mapeditor.cpp
author insilmaril
Fri, 02 Oct 2009 13:24:55 +0000
changeset 802 f076fdec767d
parent 800 959bd133cd1a
child 804 14f2b1b15242
permissions -rw-r--r--
More fixes for using proxy
insilmaril@0
     1
#include "mapeditor.h"
insilmaril@0
     2
insilmaril@0
     3
#include <iostream>
insilmaril@95
     4
#include <cstdlib>
insilmaril@0
     5
#include <typeinfo>
insilmaril@0
     6
insilmaril@720
     7
#include <QObject>
insilmaril@720
     8
insilmaril@750
     9
#include "branchitem.h"
insilmaril@792
    10
#include "geometry.h"
insilmaril@175
    11
#include "mainwindow.h"
insilmaril@175
    12
#include "misc.h"
insilmaril@314
    13
#include "warningdialog.h"
insilmaril@790
    14
#include "xlinkitem.h"
insilmaril@0
    15
insilmaril@0
    16
insilmaril@0
    17
extern int statusbarTime;
insilmaril@0
    18
extern Main *mainWindow;
insilmaril@164
    19
extern QString tmpVymDir;
insilmaril@166
    20
extern QString clipboardDir;
insilmaril@491
    21
extern QString clipboardFile;
insilmaril@166
    22
extern bool clipboardEmpty;
insilmaril@473
    23
extern bool debug;
insilmaril@0
    24
insilmaril@366
    25
extern QMenu* branchContextMenu;
insilmaril@366
    26
extern QMenu* branchAddContextMenu;
insilmaril@366
    27
extern QMenu* branchRemoveContextMenu;
insilmaril@366
    28
extern QMenu* branchLinksContextMenu;
insilmaril@366
    29
extern QMenu* branchXLinksContextMenuEdit;
insilmaril@366
    30
extern QMenu* branchXLinksContextMenuFollow;
insilmaril@366
    31
extern QMenu* floatimageContextMenu;
insilmaril@366
    32
extern QMenu* canvasContextMenu;
insilmaril@366
    33
insilmaril@0
    34
extern Settings settings;
insilmaril@269
    35
extern QString iconPath;
insilmaril@0
    36
insilmaril@0
    37
///////////////////////////////////////////////////////////////////////
insilmaril@0
    38
///////////////////////////////////////////////////////////////////////
insilmaril@720
    39
MapEditor::MapEditor( VymModel *vm) 
insilmaril@0
    40
{
insilmaril@0
    41
	//cout << "Constructor ME "<<this<<endl;
insilmaril@720
    42
	mapScene= new QGraphicsScene(NULL);
insilmaril@408
    43
	mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
insilmaril@408
    44
insilmaril@767
    45
	zoomFactor=zoomFactorTarget=1;
insilmaril@767
    46
insilmaril@720
    47
	model=vm;
insilmaril@645
    48
	model->setScene (mapScene);
insilmaril@720
    49
	model->registerEditor(this);
insilmaril@727
    50
	model->makeDefault();	// No changes in model so far
insilmaril@408
    51
insilmaril@408
    52
    setScene (mapScene);
insilmaril@0
    53
insilmaril@0
    54
    printer=NULL;
insilmaril@0
    55
insilmaril@366
    56
	// Create bitmap cursors, platform dependant
insilmaril@404
    57
	HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);		
insilmaril@404
    58
	PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); 
insilmaril@404
    59
	CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 ); 
insilmaril@404
    60
	XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 ); 
insilmaril@398
    61
insilmaril@769
    62
	//setFocusPolicy (Qt::StrongFocus);	//FIXME-3
insilmaril@0
    63
insilmaril@0
    64
	pickingColor=false;
insilmaril@91
    65
	drawingLink=false;
insilmaril@93
    66
	copyingObj=false;
insilmaril@798
    67
	objectMoved=false;
insilmaril@0
    68
insilmaril@0
    69
    editingBO=NULL;
insilmaril@0
    70
    movingObj=NULL;
insilmaril@0
    71
insilmaril@0
    72
	printFrame=true;
insilmaril@0
    73
	printFooter=true;
insilmaril@0
    74
insilmaril@417
    75
	setAcceptDrops (true);	
insilmaril@0
    76
insilmaril@746
    77
	//model->reposition();	//FIXME-3 really still needed?
insilmaril@381
    78
insilmaril@531
    79
insilmaril@769
    80
	// Shortcuts and actions
insilmaril@769
    81
	QAction *a;
insilmaril@769
    82
    a = new QAction("Select upper branch", this);
insilmaril@769
    83
	a->setShortcut (Qt::Key_Up );
insilmaril@769
    84
	a->setShortcutContext (Qt::WidgetShortcut);
insilmaril@769
    85
	addAction (a);
insilmaril@769
    86
    connect( a, SIGNAL( triggered() ), this, SLOT( cursorUp() ) );
insilmaril@769
    87
insilmaril@769
    88
    a = new QAction( "Select lower branch",this);
insilmaril@769
    89
	a->setShortcut ( Qt::Key_Down );
insilmaril@769
    90
	a->setShortcutContext (Qt::WidgetShortcut);
insilmaril@769
    91
	addAction (a);
insilmaril@769
    92
    connect( a, SIGNAL( triggered() ), this, SLOT( cursorDown() ) );
insilmaril@769
    93
insilmaril@769
    94
    a = new QAction( "Select left branch", this);
insilmaril@769
    95
	a->setShortcut (Qt::Key_Left );
insilmaril@769
    96
//	a->setShortcutContext (Qt::WindowShortcut);
insilmaril@769
    97
	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
insilmaril@769
    98
	addAction (a);
insilmaril@769
    99
    connect( a, SIGNAL( triggered() ), this, SLOT( cursorLeft() ) );
insilmaril@769
   100
insilmaril@769
   101
    a = new QAction( "Select child branch", this);
insilmaril@769
   102
	a->setShortcut (Qt::Key_Right);
insilmaril@769
   103
	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
insilmaril@769
   104
	addAction (a);
insilmaril@769
   105
    connect( a, SIGNAL( triggered() ), this, SLOT( cursorRight() ) );
insilmaril@769
   106
insilmaril@769
   107
    a = new QAction(  "Select first branch", this);
insilmaril@769
   108
	a->setShortcut (Qt::Key_Home );
insilmaril@769
   109
	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
insilmaril@769
   110
	addAction (a);
insilmaril@769
   111
    connect( a, SIGNAL( triggered() ), this, SLOT( cursorFirst() ) );
insilmaril@769
   112
insilmaril@769
   113
    a = new QAction( "Select last branch",this);
insilmaril@769
   114
	a->setShortcut ( Qt::Key_End );
insilmaril@769
   115
	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
insilmaril@769
   116
	addAction (a);
insilmaril@769
   117
    connect( a, SIGNAL( triggered() ), this, SLOT( cursorLast() ) );
insilmaril@769
   118
insilmaril@720
   119
	// Action to embed LineEdit for heading in Scene
insilmaril@720
   120
	editingHeading=false;
insilmaril@720
   121
	lineEdit=new QLineEdit;
insilmaril@720
   122
	lineEdit->hide();
insilmaril@720
   123
	QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
insilmaril@772
   124
	pw->setZValue (Z_LINEEDIT);
insilmaril@676
   125
insilmaril@769
   126
	a = new QAction( tr( "Edit heading","MapEditor" ), this);
insilmaril@720
   127
	a->setShortcut ( Qt::Key_Return );					//Edit heading
insilmaril@720
   128
	addAction (a);
insilmaril@720
   129
    connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
insilmaril@720
   130
	a = new QAction( tr( "Edit heading","MapEditor" ), this);
insilmaril@720
   131
	a->setShortcut ( Qt::Key_Enter);					//Edit heading
insilmaril@720
   132
	addAction (a);
insilmaril@720
   133
    connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
insilmaril@628
   134
insilmaril@728
   135
	// Selections
insilmaril@728
   136
	selectionColor =QColor (255,255,0);
insilmaril@728
   137
	
insilmaril@728
   138
insilmaril@746
   139
	// Attributes	//FIXME-2 testing only...
insilmaril@638
   140
	QString k;
insilmaril@638
   141
	AttributeDef *ad;
insilmaril@628
   142
	attrTable= new AttributeTable();
insilmaril@638
   143
	k="A - StringList";
insilmaril@638
   144
	ad=attrTable->addKey (k,StringList);
insilmaril@638
   145
	if (ad)
insilmaril@638
   146
	{
insilmaril@638
   147
		QStringList sl;
insilmaril@638
   148
		sl <<"val 1"<<"val 2"<< "val 3";
insilmaril@638
   149
		ad->setValue (QVariant (sl));
insilmaril@638
   150
	}
insilmaril@638
   151
	//attrTable->addValue ("Key A","P 1");
insilmaril@638
   152
	//attrTable->addValue ("Key A","P 2");
insilmaril@638
   153
	//attrTable->addValue ("Key A","P 3");
insilmaril@638
   154
	//attrTable->addValue ("Key A","P 4");
insilmaril@638
   155
	k="B - FreeString";
insilmaril@638
   156
	ad=attrTable->addKey (k,FreeString);
insilmaril@638
   157
	if (ad)
insilmaril@638
   158
	{
insilmaril@638
   159
		//attrTable->addValue ("Key B","w1");
insilmaril@638
   160
		//attrTable->addValue ("Key B","w2");
insilmaril@638
   161
	}
insilmaril@638
   162
	k="C - UniqueString";
insilmaril@638
   163
	ad=attrTable->addKey (k,UniqueString);
insilmaril@638
   164
	if (ad)
insilmaril@638
   165
	{
insilmaril@638
   166
	//attrTable->addKey ("Key Prio");
insilmaril@638
   167
	//attrTable->addValue ("Key Prio","Prio 1");
insilmaril@638
   168
	//attrTable->addValue ("Key Prio","Prio 2");
insilmaril@638
   169
	}
insilmaril@0
   170
}
insilmaril@0
   171
insilmaril@0
   172
MapEditor::~MapEditor()
insilmaril@0
   173
{
insilmaril@746
   174
	//cout <<"Destructor MapEditor for "<<model->getMapName().toStdString()<<endl;
insilmaril@720
   175
	model->unregisterEditor(this);
insilmaril@0
   176
}
insilmaril@0
   177
insilmaril@645
   178
VymModel* MapEditor::getModel()
insilmaril@0
   179
{
insilmaril@645
   180
    return model;
insilmaril@0
   181
}
insilmaril@0
   182
insilmaril@408
   183
QGraphicsScene * MapEditor::getScene()
insilmaril@0
   184
{
insilmaril@408
   185
    return mapScene;
insilmaril@0
   186
}
insilmaril@0
   187
insilmaril@802
   188
void MapEditor::scrollTo (const QModelIndex &index)	
insilmaril@772
   189
{
insilmaril@772
   190
	if (index.isValid())
insilmaril@772
   191
	{
insilmaril@776
   192
		LinkableMapObj* lmo=NULL;
insilmaril@776
   193
		TreeItem *ti= static_cast<TreeItem*>(index.internalPointer());
insilmaril@776
   194
		if (ti->getType()==TreeItem::Image ||ti->isBranchLikeType() )
insilmaril@779
   195
			lmo=((MapItem*)ti)->getLMO();
insilmaril@798
   196
		if (lmo) 
insilmaril@798
   197
		{
insilmaril@798
   198
			QRectF r=lmo->getBBox();
insilmaril@802
   199
			if (debug) cout << "ME::scrollTo "<<ti->getHeadingStd()<<" bbox="<<r<<endl;
insilmaril@802
   200
			setScrollBarPosTarget (r);
insilmaril@798
   201
		}	
insilmaril@772
   202
	}
insilmaril@772
   203
}
insilmaril@772
   204
insilmaril@767
   205
void MapEditor::setScrollBarPosTarget (const QRectF &rect)
insilmaril@767
   206
{
insilmaril@767
   207
	// Code copied from Qt sources
insilmaril@767
   208
	int xmargin=50;
insilmaril@767
   209
	int ymargin=50;
insilmaril@767
   210
insilmaril@767
   211
    qreal width = viewport()->width();
insilmaril@767
   212
    qreal height = viewport()->height();
insilmaril@767
   213
    QRectF viewRect = matrix().mapRect(rect);
insilmaril@767
   214
insilmaril@767
   215
    qreal left = horizontalScrollBar()->value();
insilmaril@767
   216
    qreal right = left + width;
insilmaril@767
   217
    qreal top = verticalScrollBar()->value();
insilmaril@767
   218
    qreal bottom = top + height;
insilmaril@767
   219
insilmaril@802
   220
	scrollBarPosTarget=getScrollBarPos();
insilmaril@802
   221
insilmaril@767
   222
    if (viewRect.left() <= left + xmargin) {
insilmaril@767
   223
        // need to scroll from the left
insilmaril@767
   224
  //      if (!d->leftIndent)
insilmaril@767
   225
            scrollBarPosTarget.setX(int(viewRect.left() - xmargin - 0.5));
insilmaril@767
   226
    }
insilmaril@767
   227
    if (viewRect.right() >= right - xmargin) {
insilmaril@767
   228
        // need to scroll from the right
insilmaril@767
   229
//        if (!d->leftIndent)
insilmaril@767
   230
            scrollBarPosTarget.setX(int(viewRect.right() - width + xmargin + 0.5));
insilmaril@767
   231
    }
insilmaril@767
   232
    if (viewRect.top() <= top + ymargin) {
insilmaril@767
   233
        // need to scroll from the top
insilmaril@767
   234
   //     if (!d->topIndent)
insilmaril@767
   235
            scrollBarPosTarget.setY(int(viewRect.top() - ymargin - 0.5));
insilmaril@767
   236
    }
insilmaril@767
   237
    if (viewRect.bottom() >= bottom - ymargin) {
insilmaril@767
   238
        // need to scroll from the bottom
insilmaril@767
   239
//        if (!d->topIndent)
insilmaril@767
   240
            scrollBarPosTarget.setY(int(viewRect.bottom() - height + ymargin + 0.5));
insilmaril@767
   241
    }
insilmaril@767
   242
insilmaril@802
   243
	if (scrollBarPosTarget==getScrollBarPos()) return;
insilmaril@802
   244
insilmaril@767
   245
	if (scrollBarPosAnimation.state()==QtAbstractAnimation::Running)
insilmaril@767
   246
		scrollBarPosAnimation.stop();
insilmaril@802
   247
	
insilmaril@802
   248
	if (settings.value ("/animation/use/",true).toBool() )
insilmaril@802
   249
	{
insilmaril@802
   250
		scrollBarPosAnimation.setTargetObject (this);
insilmaril@802
   251
		scrollBarPosAnimation.setPropertyName ("scrollBarPos");
insilmaril@802
   252
		scrollBarPosAnimation.setDuration(1000);
insilmaril@802
   253
		scrollBarPosAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
insilmaril@802
   254
		scrollBarPosAnimation.setStartValue(
insilmaril@802
   255
			QPointF (horizontalScrollBar()->value() ,
insilmaril@802
   256
					 verticalScrollBar()->value() ) );
insilmaril@802
   257
		scrollBarPosAnimation.setEndValue(scrollBarPosTarget);
insilmaril@802
   258
		scrollBarPosAnimation.start();
insilmaril@802
   259
	} else
insilmaril@802
   260
		setScrollBarPos (scrollBarPosTarget);
insilmaril@767
   261
}
insilmaril@767
   262
insilmaril@767
   263
QPointF MapEditor::getScrollBarPosTarget()
insilmaril@767
   264
{
insilmaril@767
   265
    return scrollBarPosTarget;
insilmaril@767
   266
}
insilmaril@767
   267
insilmaril@767
   268
insilmaril@767
   269
void MapEditor::setScrollBarPos(const QPointF &p)
insilmaril@767
   270
{
insilmaril@767
   271
    scrollBarPos=p;
insilmaril@767
   272
	horizontalScrollBar()->setValue(int(p.x()));
insilmaril@767
   273
	verticalScrollBar()->setValue(int(p.y()));
insilmaril@767
   274
}
insilmaril@767
   275
insilmaril@767
   276
QPointF MapEditor::getScrollBarPos()
insilmaril@767
   277
{
insilmaril@802
   278
	return QPointF (horizontalScrollBar()->value(),verticalScrollBar()->value());
insilmaril@802
   279
    //return scrollBarPos;
insilmaril@767
   280
}
insilmaril@767
   281
insilmaril@767
   282
void MapEditor::setZoomFactorTarget (const qreal &zft)
insilmaril@767
   283
{
insilmaril@767
   284
	zoomFactorTarget=zft;
insilmaril@767
   285
	if (zoomAnimation.state()==QtAbstractAnimation::Running)
insilmaril@767
   286
		zoomAnimation.stop();
insilmaril@802
   287
	if (settings.value ("/animation/use/",true).toBool() )
insilmaril@802
   288
	{
insilmaril@802
   289
		//zoomAnimation=QtPropertyAnimation(this, "zoomFactor");
insilmaril@802
   290
		zoomAnimation.setTargetObject (this);
insilmaril@802
   291
		zoomAnimation.setPropertyName ("zoomFactor");
insilmaril@802
   292
		zoomAnimation.setDuration(1000);
insilmaril@802
   293
		zoomAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
insilmaril@802
   294
		zoomAnimation.setStartValue(zoomFactor);
insilmaril@802
   295
		zoomAnimation.setEndValue(zft);
insilmaril@802
   296
		zoomAnimation.start();
insilmaril@802
   297
	} else
insilmaril@802
   298
		setZoomFactor (zft);
insilmaril@767
   299
}
insilmaril@767
   300
insilmaril@767
   301
qreal MapEditor::getZoomFactorTarget()
insilmaril@767
   302
{
insilmaril@767
   303
    return zoomFactorTarget;
insilmaril@767
   304
}
insilmaril@767
   305
insilmaril@767
   306
insilmaril@767
   307
void MapEditor::setZoomFactor(const qreal &zf)
insilmaril@767
   308
{
insilmaril@767
   309
    zoomFactor=zf;
insilmaril@767
   310
	setMatrix (QMatrix(zf, 0, 0, zf, 0, 0),false );
insilmaril@767
   311
}
insilmaril@767
   312
insilmaril@767
   313
qreal MapEditor::getZoomFactor()
insilmaril@767
   314
{
insilmaril@767
   315
    return zoomFactor;
insilmaril@767
   316
}
insilmaril@767
   317
insilmaril@0
   318
void MapEditor::print()
insilmaril@0
   319
{
insilmaril@0
   320
	if ( !printer ) 
insilmaril@0
   321
	{
insilmaril@0
   322
		printer = new QPrinter;
insilmaril@0
   323
		printer->setColorMode (QPrinter::Color);
insilmaril@366
   324
		printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
insilmaril@412
   325
		printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
insilmaril@412
   326
		printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
insilmaril@0
   327
	}
insilmaril@0
   328
insilmaril@782
   329
	QRectF totalBBox=getTotalBBox();
insilmaril@0
   330
insilmaril@0
   331
	// Try to set orientation automagically
insilmaril@0
   332
	// Note: Interpretation of generated postscript is amibiguous, if 
insilmaril@0
   333
	// there are problems with landscape mode, see
insilmaril@0
   334
	// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
insilmaril@0
   335
insilmaril@0
   336
	if (totalBBox.width()>totalBBox.height())
insilmaril@0
   337
		// recommend landscape
insilmaril@0
   338
		printer->setOrientation (QPrinter::Landscape);
insilmaril@0
   339
	else	
insilmaril@0
   340
		// recommend portrait
insilmaril@0
   341
		printer->setOrientation (QPrinter::Portrait);
insilmaril@0
   342
insilmaril@0
   343
	if ( printer->setup(this) ) 
insilmaril@0
   344
	// returns false, if printing is canceled
insilmaril@0
   345
	{
insilmaril@0
   346
		QPainter pp(printer);
insilmaril@0
   347
insilmaril@412
   348
		pp.setRenderHint(QPainter::Antialiasing,true);
insilmaril@412
   349
insilmaril@0
   350
		// Don't print the visualisation of selection
insilmaril@720
   351
		model->unselect();
insilmaril@0
   352
insilmaril@408
   353
		QRectF mapRect=totalBBox;
insilmaril@411
   354
		QGraphicsRectItem *frame=NULL;
insilmaril@412
   355
insilmaril@417
   356
		if (printFrame) 
insilmaril@0
   357
		{
insilmaril@417
   358
			// Print frame around map
insilmaril@417
   359
			mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
insilmaril@417
   360
				totalBBox.width()+20, totalBBox.height()+20);
insilmaril@417
   361
			frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
insilmaril@417
   362
			frame->setZValue(0);
insilmaril@417
   363
			frame->show();    
insilmaril@417
   364
		}		
insilmaril@417
   365
insilmaril@417
   366
insilmaril@412
   367
		double paperAspect = (double)printer->width()   / (double)printer->height();
insilmaril@412
   368
		double   mapAspect = (double)mapRect.width() / (double)mapRect.height();
insilmaril@417
   369
		int viewBottom;
insilmaril@0
   370
		if (mapAspect>=paperAspect)
insilmaril@0
   371
		{
insilmaril@0
   372
			// Fit horizontally to paper width
insilmaril@417
   373
			//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );	
insilmaril@417
   374
			viewBottom=(int)(printer->width()/mapAspect);	
insilmaril@0
   375
		}	else
insilmaril@0
   376
		{
insilmaril@0
   377
			// Fit vertically to paper height
insilmaril@417
   378
			//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());	
insilmaril@417
   379
			viewBottom=printer->height();	
insilmaril@0
   380
		}	
insilmaril@417
   381
		
insilmaril@417
   382
		if (printFooter) 
insilmaril@417
   383
		{
insilmaril@417
   384
			// Print footer below map
insilmaril@417
   385
			QFont font;		
insilmaril@417
   386
			font.setPointSize(10);
insilmaril@417
   387
			pp.setFont (font);
insilmaril@417
   388
			QRectF footerBox(0,viewBottom,printer->width(),15);
insilmaril@746
   389
			// FIXME-3 fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
insilmaril@417
   390
			pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
insilmaril@417
   391
		}
insilmaril@412
   392
		mapScene->render (
insilmaril@412
   393
			&pp, 
insilmaril@412
   394
			QRectF (0,0,printer->width(),printer->height()-15),
insilmaril@412
   395
			QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
insilmaril@412
   396
		);
insilmaril@412
   397
		
insilmaril@412
   398
		// Viewport has paper dimension
insilmaril@412
   399
		if (frame)  delete (frame);
insilmaril@0
   400
insilmaril@0
   401
		// Restore selection
insilmaril@720
   402
		model->reselect();
insilmaril@119
   403
insilmaril@119
   404
		// Save settings in vymrc
insilmaril@366
   405
		settings.writeEntry("/mainwindow/printerName",printer->printerName());
insilmaril@412
   406
		settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
insilmaril@412
   407
		settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
insilmaril@0
   408
	}
insilmaril@0
   409
}
insilmaril@0
   410
insilmaril@782
   411
QRectF MapEditor::getTotalBBox()	//FIXME-2 needed e.g. for image export
insilmaril@782
   412
{
insilmaril@782
   413
	QRectF r;
insilmaril@782
   414
/*
insilmaril@782
   415
	for (int i=0;i<rootItem->branchCount(); i++)
insilmaril@782
   416
		r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
insilmaril@782
   417
*/ 
insilmaril@782
   418
	return r;	
insilmaril@782
   419
}
insilmaril@782
   420
insilmaril@782
   421
insilmaril@782
   422
QPixmap MapEditor::getPixmap()
insilmaril@782
   423
{
insilmaril@782
   424
	QRectF mapRect=getTotalBBox();
insilmaril@782
   425
	QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
insilmaril@782
   426
	QPainter pp (&pix);
insilmaril@782
   427
	
insilmaril@782
   428
	pp.setRenderHints(renderHints());
insilmaril@782
   429
insilmaril@782
   430
	// Don't print the visualisation of selection
insilmaril@782
   431
	model->unselect();
insilmaril@782
   432
insilmaril@782
   433
	mapScene->render (	&pp, 
insilmaril@782
   434
		QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
insilmaril@782
   435
		QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
insilmaril@782
   436
insilmaril@782
   437
	// Restore selection
insilmaril@782
   438
	model->reselect();
insilmaril@782
   439
	
insilmaril@782
   440
	return pix;
insilmaril@782
   441
}
insilmaril@782
   442
insilmaril@782
   443
insilmaril@408
   444
void MapEditor::setAntiAlias (bool b)
insilmaril@408
   445
{
insilmaril@408
   446
	setRenderHint(QPainter::Antialiasing,b);
insilmaril@408
   447
}
insilmaril@408
   448
insilmaril@408
   449
void MapEditor::setSmoothPixmap(bool b)
insilmaril@408
   450
{
insilmaril@408
   451
	setRenderHint(QPainter::SmoothPixmapTransform,b);
insilmaril@408
   452
}
insilmaril@408
   453
insilmaril@754
   454
TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
insilmaril@754
   455
{
insilmaril@754
   456
	// Start with mapcenter, no images allowed at rootItem
insilmaril@754
   457
	int i=0;
insilmaril@754
   458
	BranchItem *bi=model->getRootItem()->getFirstBranch();
insilmaril@754
   459
	TreeItem *found=NULL;
insilmaril@754
   460
	while (bi)
insilmaril@754
   461
	{
insilmaril@754
   462
		found=bi->findMapItem (p, exclude);
insilmaril@754
   463
		if (found) return found;
insilmaril@754
   464
		i++;
insilmaril@754
   465
		bi=model->getRootItem()->getBranchNum(i);
insilmaril@754
   466
	}
insilmaril@754
   467
	return NULL;
insilmaril@754
   468
}
insilmaril@754
   469
insilmaril@628
   470
AttributeTable* MapEditor::attributeTable()
insilmaril@628
   471
{
insilmaril@628
   472
	return attrTable;
insilmaril@628
   473
}
insilmaril@628
   474
insilmaril@527
   475
void MapEditor::testFunction1()
insilmaril@0
   476
{
insilmaril@795
   477
	cout << "ME::test1  selected TI="<<model->getSelectedItem()<<endl;
insilmaril@798
   478
insilmaril@798
   479
	BranchObj *bo=model->getSelectedBranchObj();
insilmaril@798
   480
	if (bo)
insilmaril@798
   481
	{
insilmaril@798
   482
		bo->moveBy (100,100);
insilmaril@798
   483
		model->reposition();
insilmaril@798
   484
	}
insilmaril@798
   485
insilmaril@788
   486
	/*
insilmaril@767
   487
	// Code copied from Qt sources
insilmaril@767
   488
	QRectF rect=model->getSelectedBranchObj()->getBBox();
insilmaril@767
   489
	int xmargin=50;
insilmaril@767
   490
	int ymargin=50;
insilmaril@741
   491
insilmaril@767
   492
    qreal width = viewport()->width();
insilmaril@767
   493
    qreal height = viewport()->height();
insilmaril@767
   494
    QRectF viewRect = matrix().mapRect(rect);
insilmaril@741
   495
insilmaril@767
   496
    qreal left = horizontalScrollBar()->value();
insilmaril@767
   497
    qreal right = left + width;
insilmaril@767
   498
    qreal top = verticalScrollBar()->value();
insilmaril@767
   499
    qreal bottom = top + height;
insilmaril@723
   500
insilmaril@767
   501
    if (viewRect.left() <= left + xmargin) {
insilmaril@767
   502
        // need to scroll from the left
insilmaril@767
   503
  //      if (!d->leftIndent)
insilmaril@767
   504
            horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
insilmaril@767
   505
    }
insilmaril@767
   506
    if (viewRect.right() >= right - xmargin) {
insilmaril@767
   507
        // need to scroll from the right
insilmaril@767
   508
//        if (!d->leftIndent)
insilmaril@767
   509
            horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
insilmaril@767
   510
    }
insilmaril@767
   511
    if (viewRect.top() <= top + ymargin) {
insilmaril@767
   512
        // need to scroll from the top
insilmaril@767
   513
   //     if (!d->topIndent)
insilmaril@767
   514
            verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
insilmaril@767
   515
    }
insilmaril@767
   516
    if (viewRect.bottom() >= bottom - ymargin) {
insilmaril@767
   517
        // need to scroll from the bottom
insilmaril@767
   518
//        if (!d->topIndent)
insilmaril@767
   519
            verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
insilmaril@767
   520
    }
insilmaril@767
   521
	cout << "test1:  hor="<<horizontalScrollBar()->value()<<endl;
insilmaril@767
   522
	cout << "test1:  ver="<<verticalScrollBar()->value()<<endl;
insilmaril@767
   523
}
insilmaril@788
   524
insilmaril@788
   525
*/
insilmaril@741
   526
/*
insilmaril@767
   527
	 QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
insilmaril@767
   528
	 animation->setDuration(5000);
insilmaril@767
   529
	 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
insilmaril@767
   530
	 animation->setEasingCurve ( QtEasingCurve::OutQuint);
insilmaril@767
   531
	 animation->setStartValue(sceneRect() );
insilmaril@767
   532
	 animation->setEndValue(QRectF(50, 50, 1000, 1000));
insilmaril@740
   533
insilmaril@767
   534
	 animation->start();
insilmaril@767
   535
*/	 
insilmaril@767
   536
/*
insilmaril@767
   537
	QDialog *dia= new QDialog (this);
insilmaril@767
   538
	dia->setGeometry (50,50,10,10);
insilmaril@723
   539
insilmaril@767
   540
     dia->show();
insilmaril@767
   541
     dia ->raise();
insilmaril@767
   542
insilmaril@767
   543
	 QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
insilmaril@767
   544
	 animation->setDuration(1000);
insilmaril@767
   545
	 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
insilmaril@767
   546
	 animation->setEasingCurve ( QtEasingCurve::OutQuint);
insilmaril@767
   547
	 animation->setStartValue(QRect(50, 50, 10, 10));
insilmaril@767
   548
	 animation->setEndValue(QRect(250, 250, 100, 100));
insilmaril@767
   549
insilmaril@767
   550
	 animation->start();
insilmaril@767
   551
 */
insilmaril@723
   552
insilmaril@791
   553
/* FIXME-4 Hide hidden stuff temporary, maybe add this as regular function somewhere
insilmaril@260
   554
	if (hidemode==HideNone)
insilmaril@185
   555
	{
insilmaril@260
   556
		setHideTmpMode (HideExport);
insilmaril@260
   557
		mapCenter->calcBBoxSizeWithChilds();
insilmaril@408
   558
		QRectF totalBBox=mapCenter->getTotalBBox();
insilmaril@408
   559
		QRectF mapRect=totalBBox;
insilmaril@260
   560
		QCanvasRectangle *frame=NULL;
insilmaril@260
   561
insilmaril@260
   562
		cout << "  map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
insilmaril@260
   563
	
insilmaril@260
   564
		mapRect.setRect (totalBBox.x(), totalBBox.y(), 
insilmaril@260
   565
			totalBBox.width(), totalBBox.height());
insilmaril@408
   566
		frame=new QCanvasRectangle (mapRect,mapScene);
insilmaril@260
   567
		frame->setBrush (QColor(white));
insilmaril@260
   568
		frame->setPen (QColor(black));
insilmaril@408
   569
		frame->setZValue(0);
insilmaril@260
   570
		frame->show();    
insilmaril@260
   571
	}	
insilmaril@260
   572
	else	
insilmaril@260
   573
	{
insilmaril@260
   574
		setHideTmpMode (HideNone);
insilmaril@260
   575
	}	
insilmaril@260
   576
	cout <<"  hidemode="<<hidemode<<endl;
insilmaril@301
   577
	*/
insilmaril@645
   578
insilmaril@691
   579
/*
insilmaril@628
   580
	// Toggle hidemode
insilmaril@628
   581
	if (hidemode==HideExport)
insilmaril@628
   582
		setHideTmpMode (HideNone);
insilmaril@628
   583
	else	
insilmaril@628
   584
		setHideTmpMode (HideExport);
insilmaril@691
   585
*/		
insilmaril@792
   586
insilmaril@792
   587
}
insilmaril@792
   588
	
insilmaril@792
   589
void MapEditor::testFunction2()
insilmaril@792
   590
{
insilmaril@792
   591
	// Create list with all bounding polygons
insilmaril@794
   592
	QList <LinkableMapObj*> mapobjects;
insilmaril@792
   593
	QList <ConvexPolygon> polys; 
insilmaril@793
   594
	ConvexPolygon p;
insilmaril@792
   595
	QList <Vector> vectors;
insilmaril@792
   596
	QList <Vector> orgpos;
insilmaril@793
   597
	QStringList headings;	//FIXME-3 testing only
insilmaril@793
   598
	Vector v;
insilmaril@792
   599
	BranchItem *bi;
insilmaril@793
   600
	BranchItem *bi2;
insilmaril@792
   601
	BranchObj *bo;
insilmaril@794
   602
insilmaril@794
   603
	// Outer loop: Iterate until we no more changes in orientation 
insilmaril@794
   604
	bool orientationChanged=true;
insilmaril@794
   605
	while (orientationChanged)
insilmaril@792
   606
	{
insilmaril@794
   607
		BranchItem *ri=model->getRootItem();
insilmaril@794
   608
		for (int i=0;i<ri->branchCount();++i)
insilmaril@792
   609
		{
insilmaril@794
   610
			bi=ri->getBranchNum (i);
insilmaril@794
   611
			bo=(BranchObj*)bi->getLMO();
insilmaril@793
   612
			if (bo)
insilmaril@793
   613
			{
insilmaril@793
   614
				mapobjects.append (bo);
insilmaril@793
   615
				p=bo->getBoundingPolygon();
insilmaril@793
   616
				p.calcCentroid();
insilmaril@793
   617
				polys.append(p);
insilmaril@793
   618
				vectors.append (QPointF(0,0));
insilmaril@793
   619
				orgpos.append (p.at(0));
insilmaril@794
   620
				headings.append (bi->getHeading());
insilmaril@794
   621
			}
insilmaril@794
   622
			for (int j=0;j<bi->branchCount();++j)
insilmaril@792
   623
			{
insilmaril@794
   624
				bi2=bi->getBranchNum (j);
insilmaril@794
   625
				bo=(BranchObj*)bi2->getLMO();
insilmaril@794
   626
				if (bo)
insilmaril@792
   627
				{
insilmaril@794
   628
					mapobjects.append (bo);
insilmaril@794
   629
					p=bo->getBoundingPolygon();
insilmaril@794
   630
					p.calcCentroid();
insilmaril@794
   631
					polys.append(p);
insilmaril@794
   632
					vectors.append (QPointF(0,0));
insilmaril@794
   633
					orgpos.append (p.at(0));
insilmaril@794
   634
					headings.append (bi2->getHeading());
insilmaril@794
   635
				}	
insilmaril@792
   636
			}
insilmaril@792
   637
		}
insilmaril@794
   638
insilmaril@794
   639
		// Iterate moving bounding polygons until we have no more collisions
insilmaril@794
   640
		int collisions=1;
insilmaril@794
   641
		while (collisions>0)
insilmaril@793
   642
		{
insilmaril@794
   643
			collisions=0;
insilmaril@794
   644
			for (int i=0; i<polys.size()-1; ++i)
insilmaril@794
   645
			{
insilmaril@794
   646
				for (int j=i+1; j<polys.size();++j)
insilmaril@794
   647
				{
insilmaril@794
   648
					if (polygonCollision (polys.at(i),polys.at(j), QPointF(0,0)).intersect )
insilmaril@794
   649
					{
insilmaril@794
   650
						collisions++;
insilmaril@794
   651
						//cout << "Collision: "<<headings[i].toStdString()<<" - "<<headings[j].toStdString()<<endl;
insilmaril@794
   652
						v=polys.at(j).centroid()-polys.at(i).centroid();
insilmaril@794
   653
						// Move also away if centroids are identical
insilmaril@794
   654
						if (v.isNull()) 
insilmaril@794
   655
						{
insilmaril@794
   656
							//cout << "v==0="<<polys[i].centroid()<<polys[j].centroid()<<" "<<v<<endl;
insilmaril@794
   657
							v.setX (rand()%200 -100);
insilmaril@794
   658
							v.setY (rand()%200 -100);
insilmaril@794
   659
							//cout << v;
insilmaril@794
   660
						}
insilmaril@794
   661
						v.normalize();
insilmaril@794
   662
						v.scale (2);
insilmaril@794
   663
						//cout <<  "  v="<<v<<endl;
insilmaril@794
   664
						vectors[j]=v;
insilmaril@794
   665
						vectors[i]=v;
insilmaril@794
   666
						vectors[i].invert();
insilmaril@794
   667
					}  
insilmaril@794
   668
				}
insilmaril@794
   669
			}
insilmaril@794
   670
			for (int i=0;i<vectors.size();i++)
insilmaril@794
   671
			{
insilmaril@794
   672
				//cout << " v="<<vectors[i]<<" "<<headings[i].toStdString()<<endl;
insilmaril@794
   673
				polys[i].translate (vectors[i]);
insilmaril@794
   674
			}
insilmaril@794
   675
			cout << "Collisions: "<<collisions<<endl;
insilmaril@794
   676
			//collisions=0;
insilmaril@794
   677
		}	
insilmaril@792
   678
insilmaril@794
   679
		// Finally move the real objects and update 
insilmaril@794
   680
		QList <LinkableMapObj::Orientation> orients;
insilmaril@794
   681
		for (int i=0;i<polys.size();i++)
insilmaril@794
   682
		{
insilmaril@794
   683
			Vector v=polys[i].at(0)-orgpos[i];
insilmaril@794
   684
			orients.append (mapobjects[i]->getOrientation());
insilmaril@794
   685
			mapobjects[i]->moveBy(v.x(),v.y() );
insilmaril@798
   686
			mapobjects[i]->setRelPos();
insilmaril@794
   687
		}	
insilmaril@794
   688
		model->reposition();	
insilmaril@794
   689
		orientationChanged=false;
insilmaril@794
   690
		for (int i=0;i<polys.size();i++)
insilmaril@794
   691
			if (orients[i]!=mapobjects[i]->getOrientation())
insilmaril@794
   692
			{
insilmaril@794
   693
				orientationChanged=true;
insilmaril@794
   694
				break;
insilmaril@794
   695
			}
insilmaril@794
   696
		cout << "Final: orientChanged="<<orientationChanged<<endl;
insilmaril@794
   697
		break;
insilmaril@794
   698
		//orientationChanged=false;
insilmaril@794
   699
	} // loop if orientation has changed
insilmaril@798
   700
insilmaril@798
   701
	model->emitSelectionChanged();
insilmaril@105
   702
}
insilmaril@105
   703
insilmaril@787
   704
BranchItem* MapEditor::getBranchDirectAbove (BranchItem *bi)
insilmaril@787
   705
{
insilmaril@787
   706
	if (bi)
insilmaril@787
   707
	{
insilmaril@787
   708
		int i=bi->num();
insilmaril@787
   709
		if (i>0) return bi->parent()->getBranchNum(i-1);
insilmaril@787
   710
	}
insilmaril@787
   711
	return NULL;
insilmaril@787
   712
}
insilmaril@787
   713
insilmaril@787
   714
BranchItem* MapEditor::getBranchAbove (BranchItem *selbi)
insilmaril@787
   715
{
insilmaril@787
   716
	if (selbi)
insilmaril@787
   717
	{
insilmaril@787
   718
		int dz=selbi->depth();	// original depth
insilmaril@787
   719
		bool invert=false;
insilmaril@787
   720
		if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
insilmaril@787
   721
			invert=true;
insilmaril@787
   722
insilmaril@787
   723
		BranchItem *bi;
insilmaril@787
   724
insilmaril@787
   725
		// Look for branch with same parent but directly above
insilmaril@787
   726
		if (dz==1 && invert)
insilmaril@787
   727
			bi=getBranchDirectBelow(selbi);
insilmaril@787
   728
		else
insilmaril@787
   729
			bi=getBranchDirectAbove (selbi);
insilmaril@787
   730
insilmaril@787
   731
		if (bi) 
insilmaril@787
   732
			// direct predecessor
insilmaril@787
   733
			return bi;
insilmaril@787
   734
insilmaril@787
   735
		// Go towards center and look for predecessor
insilmaril@787
   736
		while (selbi->depth()>0)
insilmaril@787
   737
		{
insilmaril@787
   738
			selbi=(BranchItem*)(selbi->parent());
insilmaril@787
   739
			if (selbi->depth()==1 && invert)
insilmaril@787
   740
				bi=getBranchDirectBelow (selbi);
insilmaril@787
   741
			else
insilmaril@787
   742
				bi=getBranchDirectAbove (selbi);
insilmaril@787
   743
			if (bi)
insilmaril@787
   744
			{
insilmaril@787
   745
				// turn 
insilmaril@787
   746
				selbi=bi;
insilmaril@787
   747
				while (selbi->depth()<dz)
insilmaril@787
   748
				{
insilmaril@787
   749
					// try to get back to original depth dz
insilmaril@787
   750
					bi=selbi->getLastBranch();
insilmaril@787
   751
					if (!bi) 
insilmaril@787
   752
					{
insilmaril@787
   753
						return selbi;
insilmaril@787
   754
					}
insilmaril@787
   755
					selbi=bi;
insilmaril@787
   756
				}
insilmaril@787
   757
				return selbi;
insilmaril@787
   758
			}
insilmaril@787
   759
		}
insilmaril@787
   760
	}
insilmaril@787
   761
	return NULL;
insilmaril@787
   762
}
insilmaril@787
   763
insilmaril@787
   764
BranchItem* MapEditor::getBranchDirectBelow(BranchItem *bi)
insilmaril@787
   765
{
insilmaril@787
   766
	if (bi)
insilmaril@787
   767
	{
insilmaril@787
   768
		int i=bi->num();
insilmaril@787
   769
		if (i+1<bi->parent()->branchCount()) return bi->parent()->getBranchNum(i+1);
insilmaril@787
   770
	}
insilmaril@787
   771
	return NULL;
insilmaril@787
   772
}
insilmaril@787
   773
insilmaril@787
   774
BranchItem* MapEditor::getBranchBelow (BranchItem *selbi)
insilmaril@787
   775
{
insilmaril@787
   776
	if (selbi)
insilmaril@787
   777
	{
insilmaril@787
   778
		BranchItem *bi;
insilmaril@787
   779
		int dz=selbi->depth();	// original depth
insilmaril@787
   780
		bool invert=false;
insilmaril@787
   781
		if (selbi->getLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
insilmaril@787
   782
			invert=true;
insilmaril@787
   783
insilmaril@787
   784
insilmaril@787
   785
		// Look for branch with same parent but directly below
insilmaril@787
   786
		if (dz==1 && invert)
insilmaril@787
   787
			bi=getBranchDirectAbove (selbi);
insilmaril@787
   788
		else
insilmaril@787
   789
			bi=getBranchDirectBelow (selbi);
insilmaril@787
   790
		if (bi) 
insilmaril@787
   791
			// direct successor
insilmaril@787
   792
			return bi;
insilmaril@787
   793
insilmaril@787
   794
insilmaril@787
   795
		// Go towards center and look for neighbour
insilmaril@787
   796
		while (selbi->depth()>0)
insilmaril@787
   797
		{
insilmaril@787
   798
			selbi=(BranchItem*)(selbi->parent());
insilmaril@787
   799
			if (selbi->depth()==1 && invert)
insilmaril@787
   800
				bi=getBranchDirectAbove (selbi);
insilmaril@787
   801
			else
insilmaril@787
   802
				bi=getBranchDirectBelow (selbi);
insilmaril@787
   803
			if (bi)
insilmaril@787
   804
			{
insilmaril@787
   805
				// turn 
insilmaril@787
   806
				selbi=bi;
insilmaril@787
   807
				while (selbi->depth()<dz)
insilmaril@787
   808
				{
insilmaril@787
   809
					// try to get back to original depth dz
insilmaril@787
   810
					bi=selbi->getFirstBranch();
insilmaril@787
   811
					if (!bi) 
insilmaril@787
   812
					{
insilmaril@787
   813
						return selbi;
insilmaril@787
   814
					}
insilmaril@787
   815
					selbi=bi;
insilmaril@787
   816
				}
insilmaril@787
   817
				return selbi;
insilmaril@787
   818
			}
insilmaril@787
   819
		}
insilmaril@787
   820
	}
insilmaril@787
   821
	return NULL;
insilmaril@787
   822
}
insilmaril@787
   823
insilmaril@787
   824
BranchItem* MapEditor::getLeftBranch (BranchItem *bi)
insilmaril@787
   825
{
insilmaril@787
   826
	if (bi)
insilmaril@787
   827
	{
insilmaril@787
   828
		if (bi->depth()==0)
insilmaril@787
   829
			// Special case: use alternative selection index
insilmaril@787
   830
			return bi->getLastSelectedBranchAlt();	
insilmaril@787
   831
		if (bi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter)	
insilmaril@787
   832
			// right of center
insilmaril@787
   833
			return (BranchItem*)(bi->parent());
insilmaril@787
   834
		else
insilmaril@787
   835
			// left of center
insilmaril@787
   836
			if (bi->getType()== TreeItem::Branch )
insilmaril@787
   837
				return bi->getLastSelectedBranch();
insilmaril@787
   838
	}
insilmaril@787
   839
	return NULL;
insilmaril@787
   840
}
insilmaril@787
   841
insilmaril@787
   842
BranchItem* MapEditor::getRightBranch(BranchItem *bi)
insilmaril@787
   843
{
insilmaril@787
   844
	if (bi)
insilmaril@787
   845
	{
insilmaril@787
   846
		if (bi->depth()==0) return bi->getLastSelectedBranch();	
insilmaril@787
   847
		if (bi->getBranchObj()->getOrientation()==LinkableMapObj::LeftOfCenter)	
insilmaril@787
   848
			// left of center
insilmaril@787
   849
			return (BranchItem*)(bi->parent());
insilmaril@787
   850
		else
insilmaril@787
   851
			// right of center
insilmaril@787
   852
			if (bi->getType()== TreeItem::Branch )
insilmaril@787
   853
				return (BranchItem*)bi->getLastSelectedBranch();
insilmaril@787
   854
	}
insilmaril@787
   855
	return NULL;
insilmaril@787
   856
}
insilmaril@787
   857
insilmaril@787
   858
insilmaril@787
   859
insilmaril@769
   860
void MapEditor::cursorUp()
insilmaril@769
   861
{
insilmaril@787
   862
	BranchItem *bi=model->getSelectedBranch();
insilmaril@787
   863
	if (bi) model->select (getBranchAbove(bi));
insilmaril@769
   864
}
insilmaril@769
   865
insilmaril@769
   866
void MapEditor::cursorDown()	
insilmaril@769
   867
insilmaril@769
   868
{
insilmaril@787
   869
	BranchItem *bi=model->getSelectedBranch();
insilmaril@787
   870
	if (bi) model->select (getBranchBelow(bi));
insilmaril@769
   871
}
insilmaril@769
   872
insilmaril@769
   873
void MapEditor::cursorLeft()
insilmaril@769
   874
{
insilmaril@787
   875
	BranchItem *bi=getLeftBranch (model->getSelectedBranch());
insilmaril@787
   876
	if (bi) model->select (bi);
insilmaril@769
   877
}
insilmaril@769
   878
insilmaril@769
   879
void MapEditor::cursorRight()	
insilmaril@769
   880
{
insilmaril@787
   881
	BranchItem *bi=getRightBranch (model->getSelectedBranch());
insilmaril@787
   882
	if (bi) model->select (bi);
insilmaril@769
   883
}
insilmaril@769
   884
insilmaril@769
   885
void MapEditor::cursorFirst()	
insilmaril@769
   886
{
insilmaril@769
   887
	model->selectFirstBranch();
insilmaril@769
   888
}
insilmaril@769
   889
insilmaril@769
   890
void MapEditor::cursorLast()	
insilmaril@769
   891
{
insilmaril@769
   892
	model->selectLastBranch();
insilmaril@769
   893
}
insilmaril@769
   894
insilmaril@769
   895
insilmaril@720
   896
void MapEditor::editHeading()
insilmaril@720
   897
{
insilmaril@720
   898
	if (editingHeading)
insilmaril@720
   899
	{
insilmaril@720
   900
		editHeadingFinished();
insilmaril@720
   901
		return;
insilmaril@720
   902
	}
insilmaril@753
   903
	BranchObj *bo=model->getSelectedBranchObj();
insilmaril@787
   904
	BranchItem *bi=model->getSelectedBranch();
insilmaril@773
   905
	if (bo)	
insilmaril@720
   906
	{
insilmaril@720
   907
		model->setSelectionBlocked(true);
insilmaril@720
   908
insilmaril@753
   909
		lineEdit->setText (bi->getHeading());
insilmaril@720
   910
		QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
insilmaril@720
   911
		lineEdit->setGeometry(p.x(),p.y(),230,25);
insilmaril@720
   912
		lineEdit->selectAll();
insilmaril@720
   913
		lineEdit->show();
insilmaril@720
   914
		lineEdit->setFocus();
insilmaril@720
   915
		lineEdit->grabKeyboard();
insilmaril@720
   916
		editingHeading=true;
insilmaril@720
   917
	}
insilmaril@720
   918
insilmaril@720
   919
}
insilmaril@720
   920
void MapEditor::editHeadingFinished()
insilmaril@720
   921
{
insilmaril@720
   922
	editingHeading=false;
insilmaril@720
   923
	lineEdit->releaseKeyboard();
insilmaril@720
   924
	model->setHeading (lineEdit->text() );
insilmaril@720
   925
	model->setSelectionBlocked(false);
insilmaril@720
   926
	lineEdit->hide();
insilmaril@720
   927
insilmaril@720
   928
	// Maybe reselect previous branch 
insilmaril@720
   929
	mainWindow->editHeadingFinished (model);
insilmaril@720
   930
}
insilmaril@720
   931
insilmaril@720
   932
insilmaril@408
   933
void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
insilmaril@0
   934
{
insilmaril@0
   935
	// Lineedits are already closed by preceding
insilmaril@0
   936
	// mouseEvent, we don't need to close here.
insilmaril@0
   937
insilmaril@408
   938
    QPointF p = mapToScene(e->pos());
insilmaril@754
   939
    TreeItem *ti=findMapItem (p, NULL);
insilmaril@754
   940
    LinkableMapObj* lmo=NULL;
insilmaril@779
   941
	if (ti) lmo=((MapItem*)ti)->getLMO();
insilmaril@0
   942
	
insilmaril@0
   943
    if (lmo) 
insilmaril@0
   944
	{	// MapObj was found
insilmaril@735
   945
		if (model->getSelectedLMO() != lmo)
insilmaril@0
   946
		{
insilmaril@0
   947
			// select the MapObj
insilmaril@720
   948
			model->select(lmo);
insilmaril@0
   949
		}
insilmaril@0
   950
		// Context Menu 
insilmaril@753
   951
		if (model->getSelectedBranchObj() ) 
insilmaril@0
   952
		{
insilmaril@424
   953
			// Context Menu on branch or mapcenter
insilmaril@424
   954
			branchContextMenu->popup(e->globalPos() );
insilmaril@424
   955
		} else
insilmaril@424
   956
		{
insilmaril@787
   957
			if (model->getSelectedImage() )
insilmaril@0
   958
			{
insilmaril@0
   959
				// Context Menu on floatimage
insilmaril@0
   960
				floatimageContextMenu->popup(e->globalPos() );
insilmaril@0
   961
			}	
insilmaril@0
   962
		}	
insilmaril@0
   963
	} else 
insilmaril@0
   964
	{ // No MapObj found, we are on the Canvas itself
insilmaril@408
   965
		// Context Menu on scene
insilmaril@723
   966
		
insilmaril@723
   967
		// Open context menu synchronously to position new mapcenter
insilmaril@723
   968
		model->setContextPos (p);
insilmaril@723
   969
		canvasContextMenu->exec(e->globalPos() );
insilmaril@723
   970
		model->unsetContextPos ();
insilmaril@0
   971
    } 
insilmaril@329
   972
	e->accept();
insilmaril@0
   973
}
insilmaril@0
   974
insilmaril@398
   975
void MapEditor::keyPressEvent(QKeyEvent* e)
insilmaril@398
   976
{
insilmaril@411
   977
	if (e->modifiers() & Qt::ControlModifier)
insilmaril@398
   978
	{
insilmaril@398
   979
		switch (mainWindow->getModMode())
insilmaril@398
   980
		{
insilmaril@473
   981
			case Main::ModModeColor: 
insilmaril@398
   982
				setCursor (PickColorCursor);
insilmaril@398
   983
				break;
insilmaril@473
   984
			case Main::ModModeCopy: 
insilmaril@398
   985
				setCursor (CopyCursor);
insilmaril@398
   986
				break;
insilmaril@473
   987
			case Main::ModModeXLink: 
insilmaril@398
   988
				setCursor (XLinkCursor);
insilmaril@398
   989
				break;
insilmaril@398
   990
			default :
insilmaril@398
   991
				setCursor (Qt::ArrowCursor);
insilmaril@398
   992
				break;
insilmaril@398
   993
		} 
insilmaril@398
   994
	}	
insilmaril@398
   995
}
insilmaril@398
   996
insilmaril@398
   997
void MapEditor::keyReleaseEvent(QKeyEvent* e)
insilmaril@398
   998
{
insilmaril@411
   999
	if (!(e->modifiers() & Qt::ControlModifier))
insilmaril@398
  1000
		setCursor (Qt::ArrowCursor);
insilmaril@398
  1001
}
insilmaril@398
  1002
insilmaril@408
  1003
void MapEditor::mousePressEvent(QMouseEvent* e)
insilmaril@0
  1004
{
insilmaril@329
  1005
	// Ignore right clicks, these will go to context menus
insilmaril@366
  1006
	if (e->button() == Qt::RightButton )
insilmaril@329
  1007
	{
insilmaril@329
  1008
		e->ignore();
insilmaril@329
  1009
		return;
insilmaril@329
  1010
	}
insilmaril@329
  1011
insilmaril@491
  1012
	//Ignore clicks while editing heading
insilmaril@720
  1013
	if (model->isSelectionBlocked() ) 
insilmaril@491
  1014
	{
insilmaril@491
  1015
		e->ignore();
insilmaril@491
  1016
		return;
insilmaril@491
  1017
	}
insilmaril@491
  1018
insilmaril@408
  1019
    QPointF p = mapToScene(e->pos());
insilmaril@754
  1020
    TreeItem *ti=findMapItem (p, NULL);
insilmaril@754
  1021
    LinkableMapObj* lmo=NULL;
insilmaril@779
  1022
	if (ti) lmo=((MapItem*)ti)->getLMO();
insilmaril@0
  1023
	
insilmaril@790
  1024
	
insilmaril@329
  1025
	e->accept();
insilmaril@329
  1026
insilmaril@442
  1027
	//Take care of  system flags _or_ modifier modes
insilmaril@267
  1028
	//
insilmaril@773
  1029
	if (lmo && ti->isBranchLikeType() )
insilmaril@267
  1030
	{
insilmaril@267
  1031
		QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
insilmaril@267
  1032
		if (!foname.isEmpty())
insilmaril@267
  1033
		{
insilmaril@267
  1034
			// systemFlag clicked
insilmaril@798
  1035
			model->select (lmo);	
insilmaril@798
  1036
			if (foname=="system-url") 
insilmaril@267
  1037
			{
insilmaril@366
  1038
				if (e->state() & Qt::ControlModifier)
insilmaril@267
  1039
					mainWindow->editOpenURLTab();
insilmaril@267
  1040
				else	
insilmaril@267
  1041
					mainWindow->editOpenURL();
insilmaril@267
  1042
			}	
insilmaril@780
  1043
			else if (foname=="system-vymLink")
insilmaril@267
  1044
			{
insilmaril@267
  1045
				mainWindow->editOpenVymLink();
insilmaril@267
  1046
				// tabWidget may change, better return now
insilmaril@267
  1047
				// before segfaulting...
insilmaril@267
  1048
			} else if (foname=="note")
insilmaril@267
  1049
				mainWindow->windowToggleNoteEditor();
insilmaril@267
  1050
			else if (foname=="hideInExport")		
insilmaril@720
  1051
				model->toggleHideExport();
insilmaril@746
  1052
			// FIXME-3 needed? xelection.update();	
insilmaril@267
  1053
			return;	
insilmaril@267
  1054
		} 
insilmaril@720
  1055
	}	
insilmaril@442
  1056
	// No system flag clicked, take care of modmodes (CTRL-Click)
insilmaril@366
  1057
	if (e->state() & Qt::ControlModifier)
insilmaril@0
  1058
	{
insilmaril@473
  1059
		if (mainWindow->getModMode()==Main::ModModeColor)
insilmaril@83
  1060
		{
insilmaril@83
  1061
				pickingColor=true;
insilmaril@398
  1062
				setCursor (PickColorCursor);
insilmaril@83
  1063
				return;
insilmaril@83
  1064
		} 
insilmaril@473
  1065
		if (mainWindow->getModMode()==Main::ModModeXLink)
insilmaril@83
  1066
		{	
insilmaril@790
  1067
			BranchItem *bi_begin=model->getSelectedBranch();
insilmaril@790
  1068
			if (bi_begin)	
insilmaril@83
  1069
			{
insilmaril@83
  1070
				drawingLink=true;
insilmaril@790
  1071
				tmpXLink=model->createXLink(bi_begin,true);
insilmaril@720
  1072
				tmpXLink->setColor(model->getMapDefXLinkColor());
insilmaril@720
  1073
				tmpXLink->setWidth(model->getMapDefXLinkWidth());
insilmaril@790
  1074
				tmpXLink->setEnd   (p);
insilmaril@95
  1075
				tmpXLink->updateXLink();
insilmaril@83
  1076
				return;
insilmaril@89
  1077
			} 
insilmaril@267
  1078
		}
insilmaril@442
  1079
	}	// End of modmodes
insilmaril@442
  1080
insilmaril@0
  1081
    if (lmo) 
insilmaril@267
  1082
	{	
insilmaril@738
  1083
	/*
insilmaril@729
  1084
		cout << "ME::mouse pressed\n";
insilmaril@729
  1085
		cout << "  lmo="<<lmo<<endl;
insilmaril@776
  1086
		cout << "   ti="<<ti->getHeadingStd()<<endl;
insilmaril@738
  1087
	*/
insilmaril@442
  1088
		// Select the clicked object
insilmaril@729
  1089
insilmaril@776
  1090
		// Get clicked LMO
insilmaril@738
  1091
		model->select (ti);
insilmaril@442
  1092
insilmaril@0
  1093
		// Left Button	    Move Branches
insilmaril@366
  1094
		if (e->button() == Qt::LeftButton )
insilmaril@0
  1095
		{
insilmaril@424
  1096
			movingObj_start.setX( p.x() - lmo->x() );	
insilmaril@424
  1097
			movingObj_start.setY( p.y() - lmo->y() );	
insilmaril@129
  1098
			movingObj_orgPos.setX (lmo->x() );
insilmaril@129
  1099
			movingObj_orgPos.setY (lmo->y() );
insilmaril@720
  1100
			lmo->setRelPos();
insilmaril@366
  1101
			movingObj_orgRelPos=lmo->getRelPos();
insilmaril@129
  1102
insilmaril@93
  1103
			// If modMode==copy, then we want to "move" the _new_ object around
insilmaril@93
  1104
			// then we need the offset from p to the _old_ selection, because of tmp
insilmaril@473
  1105
			if (mainWindow->getModMode()==Main::ModModeCopy &&
insilmaril@366
  1106
				e->state() & Qt::ControlModifier)
insilmaril@93
  1107
			{
insilmaril@787
  1108
				BranchItem *bi=model->getSelectedBranch();
insilmaril@750
  1109
				if (bi)
insilmaril@93
  1110
				{
insilmaril@93
  1111
					copyingObj=true;
insilmaril@750
  1112
					//FIXME-2   TreeItem::addBranch (BranchItem still missing) 
insilmaril@787
  1113
					//bi->addBranch (model->getSelectedBranch());
insilmaril@720
  1114
					model->unselect();
insilmaril@750
  1115
					model->select(bi->getLastBranch());
insilmaril@645
  1116
					model->reposition();
insilmaril@93
  1117
				}
insilmaril@421
  1118
			} 
insilmaril@421
  1119
insilmaril@735
  1120
			movingObj=model->getSelectedLMO();	
insilmaril@0
  1121
		} else
insilmaril@0
  1122
			// Middle Button    Toggle Scroll
insilmaril@0
  1123
			// (On Mac OS X this won't work, but we still have 
insilmaril@0
  1124
			// a button in the toolbar)
insilmaril@366
  1125
			if (e->button() == Qt::MidButton )
insilmaril@720
  1126
				model->toggleScroll();
insilmaril@746
  1127
		// model->updateActions(); FIXME-3 needed?
insilmaril@746
  1128
		// FIXME-3 needed? xelection.update();
insilmaril@0
  1129
	} else 
insilmaril@408
  1130
	{ // No MapObj found, we are on the scene itself
insilmaril@408
  1131
		// Left Button	    move Pos of sceneView
insilmaril@366
  1132
		if (e->button() == Qt::LeftButton )
insilmaril@0
  1133
		{
insilmaril@0
  1134
			movingObj=NULL;	// move Content not Obj
insilmaril@0
  1135
			movingObj_start=e->globalPos();
insilmaril@408
  1136
			movingCont_start=QPointF (
insilmaril@408
  1137
				horizontalScrollBar()->value(),
insilmaril@408
  1138
				verticalScrollBar()->value());
insilmaril@408
  1139
			movingVec=QPointF(0,0);
insilmaril@398
  1140
			setCursor(HandOpenCursor);
insilmaril@0
  1141
		} 
insilmaril@0
  1142
    } 
insilmaril@0
  1143
}
insilmaril@0
  1144
insilmaril@408
  1145
void MapEditor::mouseMoveEvent(QMouseEvent* e)
insilmaril@0
  1146
{
insilmaril@408
  1147
    QPointF p = mapToScene(e->pos());
insilmaril@754
  1148
	TreeItem *seli=model->getSelectedItem();
insilmaril@777
  1149
	LinkableMapObj* lmosel=NULL;	
insilmaril@776
  1150
	if (seli && (seli->isBranchLikeType() ||seli->getType()==TreeItem::Image))
insilmaril@779
  1151
		lmosel=((MapItem*)seli)->getLMO();
insilmaril@83
  1152
insilmaril@0
  1153
    // Move the selected MapObj
insilmaril@424
  1154
    if ( lmosel && movingObj) 
insilmaril@0
  1155
    {	
insilmaril@798
  1156
		objectMoved=true;
insilmaril@421
  1157
		// reset cursor if we are moving and don't copy
insilmaril@473
  1158
		if (mainWindow->getModMode()!=Main::ModModeCopy)
insilmaril@421
  1159
			setCursor (Qt::ArrowCursor);
insilmaril@421
  1160
insilmaril@408
  1161
		// To avoid jumping of the sceneView, only 
insilmaril@763
  1162
		// show selection, if not tmp linked
insilmaril@798
  1163
		/* FIXME-2 if (!lmosel->hasParObjTmp())
insilmaril@763
  1164
			model->emitShowSelection();
insilmaril@798
  1165
			*/
insilmaril@0
  1166
		
insilmaril@83
  1167
		// Now move the selection, but add relative position 
insilmaril@83
  1168
		// (movingObj_start) where selection was chosen with 
insilmaril@83
  1169
		// mousepointer. (This avoids flickering resp. jumping 
insilmaril@0
  1170
		// of selection back to absPos)
insilmaril@0
  1171
		
insilmaril@0
  1172
		// Check if we could link 
insilmaril@777
  1173
		TreeItem *ti=findMapItem (p, seli);
insilmaril@777
  1174
		BranchItem *dsti=NULL;
insilmaril@754
  1175
		LinkableMapObj* dst=NULL;
insilmaril@777
  1176
		if (ti && ti!=seli && ti->isBranchLikeType())
insilmaril@777
  1177
		{
insilmaril@777
  1178
			dsti=(BranchItem*)ti;
insilmaril@777
  1179
			dst=dsti->getLMO(); 
insilmaril@777
  1180
		} else
insilmaril@772
  1181
			dsti=NULL;
insilmaril@0
  1182
		
insilmaril@0
  1183
insilmaril@777
  1184
		if (lmosel && seli->getType()==TreeItem::Image)	
insilmaril@0
  1185
		{
insilmaril@776
  1186
			FloatObj *fio=(FloatImageObj*)lmosel;
insilmaril@424
  1187
			fio->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
insilmaril@424
  1188
			fio->setRelPos();
insilmaril@779
  1189
			fio->updateLinkGeometry(); //no need for reposition, if we update link here
insilmaril@775
  1190
			model->emitSelectionChanged();	// position has changed
insilmaril@0
  1191
insilmaril@0
  1192
			// Relink float to new mapcenter or branch, if shift is pressed	
insilmaril@0
  1193
			// Only relink, if selection really has a new parent
insilmaril@777
  1194
			if ( e->modifiers()==Qt::ShiftModifier && dsti &&  dsti != seli->parent()  )
insilmaril@0
  1195
			{
insilmaril@773
  1196
				// Also save the move which was done so far
insilmaril@792
  1197
				QString pold=qpointFToString(movingObj_orgRelPos);
insilmaril@792
  1198
				QString pnow=qpointFToString(fio->getRelPos());
insilmaril@773
  1199
				model->saveState(
insilmaril@777
  1200
					seli,
insilmaril@773
  1201
					"moveRel "+pold,
insilmaril@777
  1202
					seli,
insilmaril@773
  1203
					"moveRel "+pnow,
insilmaril@773
  1204
					QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
insilmaril@773
  1205
				fio->getParObj()->requestReposition();
insilmaril@773
  1206
				model->reposition();
insilmaril@420
  1207
insilmaril@777
  1208
				model->relinkImage ((ImageItem*) seli,dsti);
insilmaril@777
  1209
				model->select (seli);
insilmaril@777
  1210
				//movingObj=lmosel;	//FIXME-3
insilmaril@773
  1211
				//movingObj_orgRelPos=lmosel->getRelPos();	
insilmaril@420
  1212
insilmaril@773
  1213
				model->reposition();
insilmaril@0
  1214
			}
insilmaril@388
  1215
		} else	
insilmaril@388
  1216
		{	// selection != a FloatObj
insilmaril@798
  1217
			if (seli->depth()==0)		
insilmaril@0
  1218
			{
insilmaril@796
  1219
				lmosel->move   (p-movingObj_start);		
insilmaril@388
  1220
				if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier) 
insilmaril@796
  1221
				{
insilmaril@796
  1222
					QPointF v;
insilmaril@796
  1223
					v=lmosel->getAbsPos();
insilmaril@796
  1224
					for (int i=0; i<seli->branchCount(); ++i)
insilmaril@796
  1225
					{
insilmaril@796
  1226
						seli->getBranchObjNum(i)->setRelPos();
insilmaril@796
  1227
						seli->getBranchObjNum(i)->setOrientation();
insilmaril@796
  1228
					}
insilmaril@796
  1229
				}	
insilmaril@0
  1230
			} else
insilmaril@0
  1231
			{	
insilmaril@755
  1232
				if (seli->depth()==1)
insilmaril@0
  1233
				{
insilmaril@388
  1234
					// Move mainbranch
insilmaril@796
  1235
					lmosel->move(p-movingObj_start);		
insilmaril@388
  1236
					lmosel->setRelPos();
insilmaril@0
  1237
				} else
insilmaril@0
  1238
				{
insilmaril@388
  1239
					// Move ordinary branch
insilmaril@473
  1240
					if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
insilmaril@0
  1241
						// Add width of bbox here, otherwise alignRelTo will cause jumping around
insilmaril@720
  1242
						lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(), 
insilmaril@175
  1243
							p.y()-movingObj_start.y() +lmosel->getTopPad() );		
insilmaril@0
  1244
					else	
insilmaril@175
  1245
						lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
insilmaril@720
  1246
					lmosel->setRelPos();	
insilmaril@0
  1247
				} 
insilmaril@0
  1248
insilmaril@794
  1249
			} // depth>0
insilmaril@431
  1250
				// Maybe we can relink temporary?
insilmaril@796
  1251
				if (dsti)	// FIXME-1 check if dsti is ancestor of myself!
insilmaril@0
  1252
				{
insilmaril@388
  1253
					if (e->modifiers()==Qt::ControlModifier)
insilmaril@0
  1254
					{
insilmaril@754
  1255
						// Special case: CTRL to link below dst
insilmaril@754
  1256
						lmosel->setParObjTmp (dst,p,+1);
insilmaril@0
  1257
					}
insilmaril@388
  1258
					else if (e->modifiers()==Qt::ShiftModifier)
insilmaril@754
  1259
						lmosel->setParObjTmp (dst,p,-1);
insilmaril@0
  1260
					else
insilmaril@754
  1261
						lmosel->setParObjTmp (dst,p,0);
insilmaril@0
  1262
				} else	
insilmaril@0
  1263
				{
insilmaril@93
  1264
					lmosel->unsetParObjTmp();
insilmaril@0
  1265
				}		
insilmaril@428
  1266
				// reposition subbranch
insilmaril@428
  1267
				lmosel->reposition();	
insilmaril@0
  1268
insilmaril@732
  1269
			QItemSelection sel=model->getSelectionModel()->selection();
insilmaril@735
  1270
			updateSelection(sel,sel);	// position has changed
insilmaril@732
  1271
insilmaril@0
  1272
		} // no FloatImageObj
insilmaril@0
  1273
insilmaril@408
  1274
		scene()->update();
insilmaril@0
  1275
		return;
insilmaril@0
  1276
	} // selection && moving_obj
insilmaril@0
  1277
		
insilmaril@83
  1278
	// Draw a link from one branch to another
insilmaril@83
  1279
	if (drawingLink)
insilmaril@83
  1280
	{
insilmaril@95
  1281
		 tmpXLink->setEnd (p);
insilmaril@95
  1282
		 tmpXLink->updateXLink();
insilmaril@83
  1283
	}	 
insilmaril@83
  1284
	
insilmaril@408
  1285
    // Move sceneView 
insilmaril@411
  1286
    if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton ) 
insilmaril@0
  1287
	{
insilmaril@408
  1288
		QPointF p=e->globalPos();
insilmaril@0
  1289
		movingVec.setX(-p.x() + movingObj_start.x() );
insilmaril@0
  1290
		movingVec.setY(-p.y() + movingObj_start.y() );
insilmaril@408
  1291
		horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
insilmaril@408
  1292
		verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
insilmaril@0
  1293
    }
insilmaril@0
  1294
}
insilmaril@0
  1295
insilmaril@0
  1296
insilmaril@408
  1297
void MapEditor::mouseReleaseEvent(QMouseEvent* e)
insilmaril@0
  1298
{
insilmaril@408
  1299
    QPointF p = mapToScene(e->pos());
insilmaril@754
  1300
	TreeItem *seli=model->getSelectedItem();
insilmaril@754
  1301
insilmaril@772
  1302
	TreeItem *dsti=NULL;
insilmaril@772
  1303
	if (seli) dsti=findMapItem(p, seli);
insilmaril@755
  1304
	LinkableMapObj* dst=NULL;
insilmaril@772
  1305
	if (dsti && dsti->isBranchLikeType ()) 
insilmaril@779
  1306
		dst=((MapItem*)dsti)->getLMO();	
insilmaril@772
  1307
	else
insilmaril@772
  1308
		dsti=NULL;
insilmaril@754
  1309
insilmaril@754
  1310
insilmaril@0
  1311
	// Have we been picking color?
insilmaril@0
  1312
	if (pickingColor)
insilmaril@0
  1313
	{
insilmaril@0
  1314
		pickingColor=false;
insilmaril@366
  1315
		setCursor (Qt::ArrowCursor);
insilmaril@0
  1316
		// Check if we are over another branch
insilmaril@772
  1317
		if (dst) 
insilmaril@0
  1318
		{	
insilmaril@366
  1319
			if (e->state() & Qt::ShiftModifier)
insilmaril@720
  1320
				model->colorBranch (((BranchObj*)dst)->getColor());
insilmaril@0
  1321
			else	
insilmaril@720
  1322
				model->colorSubtree (((BranchObj*)dst)->getColor());
insilmaril@0
  1323
		} 
insilmaril@0
  1324
		return;
insilmaril@0
  1325
	}
insilmaril@83
  1326
insilmaril@83
  1327
	// Have we been drawing a link?
insilmaril@491
  1328
	if (drawingLink)	
insilmaril@83
  1329
	{
insilmaril@83
  1330
		drawingLink=false;
insilmaril@83
  1331
		// Check if we are over another branch
insilmaril@772
  1332
		if (dsti)
insilmaril@83
  1333
		{	
insilmaril@790
  1334
			tmpXLink->setEnd ( ((BranchItem*)dsti) );
insilmaril@95
  1335
			tmpXLink->updateXLink();
insilmaril@790
  1336
			tmpXLink->activate(); 
insilmaril@794
  1337
			model->saveState(
insilmaril@794
  1338
				tmpXLink,QString("delete ()"),
insilmaril@794
  1339
				dsti,QString("addXLink (\"%1\",\"%2\")").arg(model->getSelectString(tmpXLink->getBegin())).arg(model->getSelectString(dsti)),
insilmaril@794
  1340
				QString("Add xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(dsti)) 
insilmaril@794
  1341
			);	
insilmaril@83
  1342
		} else
insilmaril@83
  1343
		{
insilmaril@790
  1344
			model->deleteItem(tmpXLink);
insilmaril@95
  1345
			tmpXLink=NULL;
insilmaril@83
  1346
		}
insilmaril@83
  1347
		return;
insilmaril@83
  1348
	}
insilmaril@83
  1349
	
insilmaril@0
  1350
    // Have we been moving something?
insilmaril@754
  1351
    if ( seli && movingObj ) 
insilmaril@0
  1352
    {	
insilmaril@776
  1353
		if (seli->getType()==TreeItem::Image)
insilmaril@175
  1354
		{
insilmaril@779
  1355
			FloatImageObj *fio=(FloatImageObj*)( ((MapItem*)seli)->getLMO());
insilmaril@776
  1356
			if(fio)
insilmaril@776
  1357
			{
insilmaril@776
  1358
				// Moved FloatObj. Maybe we need to reposition
insilmaril@792
  1359
				QString pold=qpointFToString(movingObj_orgRelPos);
insilmaril@792
  1360
				QString pnow=qpointFToString(fio->getRelPos());
insilmaril@776
  1361
				model->saveState(
insilmaril@776
  1362
					seli,
insilmaril@776
  1363
					"moveRel "+pold,
insilmaril@776
  1364
					seli,
insilmaril@776
  1365
					"moveRel "+pnow,
insilmaril@776
  1366
					QString("Move %1 to relative position %2").arg(model->getObjectName(seli)).arg(pnow));
insilmaril@424
  1367
insilmaril@785
  1368
				cout << "ME::release mouse\n";
insilmaril@776
  1369
				fio->getParObj()->requestReposition();
insilmaril@776
  1370
				model->reposition();
insilmaril@776
  1371
			}	
insilmaril@776
  1372
		}
insilmaril@175
  1373
insilmaril@787
  1374
		BranchItem *bi=model->getSelectedBranch();
insilmaril@753
  1375
		if (bi && bi->depth()==0)
insilmaril@497
  1376
		{	
insilmaril@753
  1377
            if (movingObj_orgPos != bi->getBranchObj()->getAbsPos())	// FIXME-3 check getBO here...
insilmaril@625
  1378
            {
insilmaril@792
  1379
                QString pold=qpointFToString(movingObj_orgPos);
insilmaril@792
  1380
                QString pnow=qpointFToString(bi->getBranchObj()->getAbsPos());		// FIXME-3 check getBO here...
insilmaril@753
  1381
insilmaril@720
  1382
                model->saveState(
insilmaril@753
  1383
                    bi,
insilmaril@625
  1384
                    "move "+pold,
insilmaril@753
  1385
                    bi,
insilmaril@625
  1386
                    "move "+pnow,
insilmaril@753
  1387
                    QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
insilmaril@625
  1388
            }
insilmaril@388
  1389
		}
insilmaril@645
  1390
	
insilmaril@773
  1391
		if (seli->isBranchLikeType() ) //(seli->getType() == TreeItem::Branch )
insilmaril@388
  1392
		{	// A branch was moved
insilmaril@777
  1393
			LinkableMapObj* lmosel=NULL;		
insilmaril@779
  1394
			lmosel=((MapItem*)seli)->getLMO();
insilmaril@760
  1395
				
insilmaril@0
  1396
			// save the position in case we link to mapcenter
insilmaril@424
  1397
			QPointF savePos=QPointF (lmosel->getAbsPos()  );
insilmaril@0
  1398
insilmaril@0
  1399
			// Reset the temporary drawn link to the original one
insilmaril@424
  1400
			lmosel->unsetParObjTmp();
insilmaril@0
  1401
insilmaril@366
  1402
			// For Redo we may need to save original selection
insilmaril@773
  1403
			QString preSelStr=model->getSelectString(seli);
insilmaril@93
  1404
insilmaril@94
  1405
			copyingObj=false;	
insilmaril@798
  1406
			if (dsti && objectMoved)
insilmaril@93
  1407
			{
insilmaril@691
  1408
				// We have a destination, relink to that
insilmaril@691
  1409
insilmaril@753
  1410
				BranchObj* bsel=model->getSelectedBranchObj();
insilmaril@366
  1411
insilmaril@684
  1412
				QString preParStr=model->getSelectString (bsel->getParObj());
insilmaril@755
  1413
				QString preNum=QString::number (seli->num(),10);
insilmaril@366
  1414
				QString preDstParStr;
insilmaril@767
  1415
				bool relinked;
insilmaril@366
  1416
insilmaril@366
  1417
				if (e->state() & Qt::ShiftModifier && dst->getParObj())
insilmaril@366
  1418
				{	// Link above dst
insilmaril@684
  1419
					preDstParStr=model->getSelectString (dst->getParObj());
insilmaril@767
  1420
					relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
insilmaril@366
  1421
				} else 
insilmaril@366
  1422
				if (e->state() & Qt::ControlModifier && dst->getParObj())
insilmaril@366
  1423
				{
insilmaril@366
  1424
					// Link below dst
insilmaril@684
  1425
					preDstParStr=model->getSelectString (dst->getParObj());
insilmaril@767
  1426
					relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()+1);
insilmaril@366
  1427
				} else	
insilmaril@366
  1428
				{	// Append to dst
insilmaril@684
  1429
					preDstParStr=model->getSelectString(dst);
insilmaril@767
  1430
					relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
insilmaril@755
  1431
					if (dsti->depth()==0) bsel->move (savePos);
insilmaril@366
  1432
				} 
insilmaril@767
  1433
				if (relinked)
insilmaril@767
  1434
				{
insilmaril@767
  1435
					QString postSelStr=model->getSelectString(lmosel);
insilmaril@767
  1436
					QString postNum=QString::number (seli->num(),10);
insilmaril@366
  1437
insilmaril@776
  1438
					QString undoCom="relinkTo (\""+ 
insilmaril@767
  1439
						preParStr+ "\"," + preNum  +"," + 
insilmaril@767
  1440
						QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
insilmaril@366
  1441
insilmaril@776
  1442
					QString redoCom="relinkTo (\""+ 
insilmaril@767
  1443
						preDstParStr + "\"," + postNum + "," +
insilmaril@767
  1444
						QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
insilmaril@366
  1445
insilmaril@767
  1446
					model->saveState (
insilmaril@767
  1447
						postSelStr,undoCom,
insilmaril@767
  1448
						preSelStr, redoCom,
insilmaril@767
  1449
						QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
insilmaril@691
  1450
insilmaril@767
  1451
				}
insilmaril@163
  1452
			} else
insilmaril@691
  1453
			{
insilmaril@691
  1454
				// No destination, undo  temporary move
insilmaril@691
  1455
insilmaril@755
  1456
				if (seli->depth()==1)
insilmaril@366
  1457
				{
insilmaril@366
  1458
					// The select string might be different _after_ moving around.
insilmaril@366
  1459
					// Therefor reposition and then use string of old selection, too
insilmaril@645
  1460
					model->reposition();
insilmaril@366
  1461
insilmaril@625
  1462
                    QPointF rp(lmosel->getRelPos());
insilmaril@625
  1463
                    if (rp != movingObj_orgRelPos)
insilmaril@625
  1464
                    {
insilmaril@792
  1465
                        QString ps=qpointFToString(rp);
insilmaril@720
  1466
                        model->saveState(
insilmaril@792
  1467
                            model->getSelectString(lmosel), "moveRel "+qpointFToString(movingObj_orgRelPos), 
insilmaril@625
  1468
                            preSelStr, "moveRel "+ps, 
insilmaril@726
  1469
                            QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
insilmaril@625
  1470
                    }
insilmaril@366
  1471
				}
insilmaril@691
  1472
insilmaril@691
  1473
				// Draw the original link, before selection was moved around
insilmaril@755
  1474
				if (settings.value("/animation/use",false).toBool() && seli->depth()>1) 
insilmaril@691
  1475
				{
insilmaril@720
  1476
					lmosel->setRelPos();	// calc relPos first for starting point
insilmaril@720
  1477
					
insilmaril@691
  1478
					model->startAnimation(
insilmaril@723
  1479
						(BranchObj*)lmosel,
insilmaril@691
  1480
						lmosel->getRelPos(),
insilmaril@720
  1481
						movingObj_orgRelPos
insilmaril@691
  1482
					);	
insilmaril@691
  1483
				} else	
insilmaril@691
  1484
					model->reposition();
insilmaril@691
  1485
			}
insilmaril@0
  1486
		}
insilmaril@775
  1487
		model->emitSelectionChanged();  //FIXME-3 needed? at least not after pos of selection has changed...
insilmaril@408
  1488
		// Finally resize scene, if needed
insilmaril@408
  1489
		scene()->update();
insilmaril@0
  1490
		movingObj=NULL;		
insilmaril@798
  1491
		objectMoved=false;
insilmaril@366
  1492
insilmaril@0
  1493
	} else 
insilmaril@83
  1494
		// maybe we moved View: set old cursor
insilmaril@366
  1495
		setCursor (Qt::ArrowCursor);
insilmaril@83
  1496
    
insilmaril@0
  1497
}
insilmaril@0
  1498
insilmaril@408
  1499
void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
insilmaril@0
  1500
{
insilmaril@802
  1501
	if (debug) 
insilmaril@802
  1502
	{
insilmaril@802
  1503
		cout << "ME p="<<mapToScene (e->pos())<<"  scrollBarPos="<<getScrollBarPos();
insilmaril@802
  1504
		cout << "  min="<<QPointF(horizontalScrollBar()->minimum(),verticalScrollBar()->minimum());
insilmaril@802
  1505
		cout << endl;
insilmaril@802
  1506
	}
insilmaril@798
  1507
insilmaril@798
  1508
insilmaril@720
  1509
	if (model->isSelectionBlocked() ) 
insilmaril@491
  1510
	{
insilmaril@491
  1511
		e->ignore();
insilmaril@491
  1512
		return;
insilmaril@491
  1513
	}
insilmaril@491
  1514
insilmaril@366
  1515
	if (e->button() == Qt::LeftButton )
insilmaril@0
  1516
	{
insilmaril@408
  1517
		QPointF p = mapToScene(e->pos());
insilmaril@754
  1518
		TreeItem *ti=findMapItem (p, NULL);
insilmaril@754
  1519
		if (ti) {	// MapObj was found
insilmaril@0
  1520
			// First select the MapObj than edit heading
insilmaril@754
  1521
			model->select (ti);
insilmaril@720
  1522
			editHeading();
insilmaril@0
  1523
		}
insilmaril@0
  1524
	}
insilmaril@0
  1525
}
insilmaril@0
  1526
insilmaril@0
  1527
void MapEditor::resizeEvent (QResizeEvent* e)
insilmaril@0
  1528
{
insilmaril@408
  1529
	QGraphicsView::resizeEvent( e );
insilmaril@0
  1530
}
insilmaril@0
  1531
insilmaril@412
  1532
void MapEditor::dragEnterEvent(QDragEnterEvent *event)
insilmaril@119
  1533
{
insilmaril@417
  1534
	//for (unsigned int i=0;event->format(i);i++) // Debug mime type
insilmaril@417
  1535
	//	cerr << event->format(i) << endl;
insilmaril@417
  1536
insilmaril@417
  1537
	if (event->mimeData()->hasImage())
insilmaril@417
  1538
		event->acceptProposedAction();
insilmaril@417
  1539
	else	
insilmaril@417
  1540
		if (event->mimeData()->hasUrls())
insilmaril@417
  1541
			event->acceptProposedAction();
insilmaril@417
  1542
}
insilmaril@417
  1543
insilmaril@531
  1544
void MapEditor::dragMoveEvent(QDragMoveEvent *)
insilmaril@417
  1545
{
insilmaril@417
  1546
}
insilmaril@417
  1547
insilmaril@417
  1548
void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
insilmaril@417
  1549
{
insilmaril@417
  1550
	event->accept();
insilmaril@119
  1551
}
insilmaril@129
  1552
insilmaril@412
  1553
void MapEditor::dropEvent(QDropEvent *event)
insilmaril@129
  1554
{
insilmaril@787
  1555
	BranchItem *selbi=model->getSelectedBranch();
insilmaril@753
  1556
	if (selbi)
insilmaril@128
  1557
	{
insilmaril@505
  1558
		if (debug)
insilmaril@505
  1559
			foreach (QString format,event->mimeData()->formats()) 
insilmaril@658
  1560
				cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
insilmaril@497
  1561
insilmaril@497
  1562
insilmaril@417
  1563
		QList <QUrl> uris;
insilmaril@417
  1564
		if (event->mimeData()->hasImage()) 
insilmaril@128
  1565
		{
insilmaril@417
  1566
			 QVariant imageData = event->mimeData()->imageData();
insilmaril@720
  1567
			 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
insilmaril@417
  1568
		} else
insilmaril@417
  1569
		if (event->mimeData()->hasUrls())
insilmaril@417
  1570
			uris=event->mimeData()->urls();
insilmaril@417
  1571
insilmaril@417
  1572
		if (uris.count()>0)
insilmaril@128
  1573
		{
insilmaril@417
  1574
			QStringList files;
insilmaril@417
  1575
			QString s;
insilmaril@417
  1576
			QString heading;
insilmaril@753
  1577
			BranchItem *bi;
insilmaril@428
  1578
			for (int i=0; i<uris.count();i++)
insilmaril@408
  1579
			{
insilmaril@428
  1580
				// Workaround to avoid adding empty branches
insilmaril@428
  1581
				if (!uris.at(i).toString().isEmpty())
insilmaril@417
  1582
				{
insilmaril@775
  1583
					bi=model->addNewBranch();
insilmaril@753
  1584
					if (bi)
insilmaril@417
  1585
					{
insilmaril@753
  1586
						   /* FIXME-2 
insilmaril@428
  1587
						s=uris.at(i).toLocalFile();
insilmaril@428
  1588
						if (!s.isEmpty()) 
insilmaril@428
  1589
						{
insilmaril@625
  1590
						   QString file = QDir::fromNativeSeparators(s);
insilmaril@428
  1591
						   heading = QFileInfo(file).baseName();
insilmaril@428
  1592
						   files.append(file);
insilmaril@428
  1593
						   if (file.endsWith(".vym", false))
insilmaril@753
  1594
							   bi->setVymLink(file);
insilmaril@428
  1595
						   else
insilmaril@753
  1596
							   bi->setURL(uris.at(i).toString());
insilmaril@428
  1597
					   } else 
insilmaril@428
  1598
					   {
insilmaril@428
  1599
						   bo->setURL(uris.at(i).toString());
insilmaril@428
  1600
					   }
insilmaril@753
  1601
							 */  
insilmaril@428
  1602
insilmaril@428
  1603
					   if (!heading.isEmpty())
insilmaril@753
  1604
						   bi->setHeading(heading);
insilmaril@428
  1605
					   else
insilmaril@753
  1606
						   bi->setHeading(uris.at(i).toString());
insilmaril@753
  1607
						   
insilmaril@428
  1608
					}
insilmaril@417
  1609
				}
insilmaril@417
  1610
			}
insilmaril@645
  1611
			model->reposition();
insilmaril@417
  1612
		}
insilmaril@417
  1613
	}	
insilmaril@417
  1614
	event->acceptProposedAction();
insilmaril@417
  1615
}
insilmaril@417
  1616
insilmaril@776
  1617
void MapEditor::updateSelection(QItemSelection newsel,QItemSelection oldsel)
insilmaril@728
  1618
{
insilmaril@779
  1619
	// Note: Here we are prepared for multiple selections, though this 
insilmaril@779
  1620
	// is not yet implemented elsewhere
insilmaril@779
  1621
insilmaril@776
  1622
	// Here in MapEditor we can only select Branches and Images
insilmaril@786
  1623
	QList <TreeItem*> treeItemsNew;
insilmaril@786
  1624
	QList <TreeItem*> treeItemsOld;
insilmaril@786
  1625
insilmaril@796
  1626
	bool do_reposition=false;
insilmaril@796
  1627
insilmaril@776
  1628
	QModelIndex ix;
insilmaril@776
  1629
	foreach (ix,newsel.indexes() )
insilmaril@776
  1630
	{
insilmaril@776
  1631
		TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
insilmaril@787
  1632
		if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image )
insilmaril@786
  1633
			if (!treeItemsNew.contains(ti)) treeItemsNew.append (ti);
insilmaril@786
  1634
	}
insilmaril@786
  1635
	foreach (ix,oldsel.indexes() )
insilmaril@786
  1636
	{
insilmaril@786
  1637
		TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
insilmaril@787
  1638
		if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image )
insilmaril@786
  1639
			if (!treeItemsOld.contains(ti)) treeItemsOld.append (ti);
insilmaril@776
  1640
	}
insilmaril@776
  1641
insilmaril@779
  1642
	// Trim list of selection rectangles 
insilmaril@786
  1643
	while (treeItemsNew.count() < selboxList.count() )
insilmaril@776
  1644
		delete selboxList.takeFirst();
insilmaril@776
  1645
insilmaril@775
  1646
	// Take care to tmp scroll/unscroll
insilmaril@775
  1647
	if (!oldsel.isEmpty())
insilmaril@775
  1648
	{
insilmaril@775
  1649
		QModelIndex ix=oldsel.indexes().first(); 
insilmaril@775
  1650
		if (ix.isValid() )
insilmaril@775
  1651
		{
insilmaril@775
  1652
			TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
insilmaril@779
  1653
			if (ti)
insilmaril@775
  1654
			{
insilmaril@779
  1655
				if (ti->isBranchLikeType() )
insilmaril@779
  1656
				{
insilmaril@779
  1657
					// reset tmp scrolled branches
insilmaril@779
  1658
					BranchItem *bi=(BranchItem*)ti;
insilmaril@796
  1659
					if (bi->resetTmpUnscroll() )
insilmaril@796
  1660
						do_reposition=true;
insilmaril@779
  1661
				}
insilmaril@779
  1662
				if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image)
insilmaril@779
  1663
					// Hide link if not needed
insilmaril@779
  1664
					((MapItem*)ti)->getLMO()->updateVisibility();
insilmaril@775
  1665
			}
insilmaril@775
  1666
		}
insilmaril@775
  1667
	}
insilmaril@775
  1668
insilmaril@786
  1669
	if (!treeItemsNew.isEmpty())
insilmaril@775
  1670
	{
insilmaril@775
  1671
		QModelIndex ix=newsel.indexes().first(); 
insilmaril@775
  1672
		if (ix.isValid() )
insilmaril@775
  1673
		{
insilmaril@775
  1674
			// Temporary unscroll if necessary
insilmaril@775
  1675
			TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
insilmaril@775
  1676
			if (ti->isBranchLikeType() )
insilmaril@775
  1677
			{
insilmaril@775
  1678
				BranchItem *bi=(BranchItem*)ti;
insilmaril@775
  1679
				if (bi->hasScrolledParent(bi) )
insilmaril@796
  1680
				{
insilmaril@796
  1681
					if (bi->parentBranch()->tmpUnscroll() )
insilmaril@796
  1682
						do_reposition=true;
insilmaril@796
  1683
				}	
insilmaril@775
  1684
			}
insilmaril@779
  1685
			if (ti->isBranchLikeType() || ti->getType()==TreeItem::Image)
insilmaril@779
  1686
				// Show link if needed
insilmaril@779
  1687
				((MapItem*)ti)->getLMO()->updateVisibility();
insilmaril@775
  1688
		}
insilmaril@775
  1689
	}
insilmaril@798
  1690
	// FIXME-3 cout << "ME::updateSel  doRepos="<<do_reposition<<endl;
insilmaril@796
  1691
	if (do_reposition) model->reposition();
insilmaril@775
  1692
insilmaril@731
  1693
	// Reduce rectangles
insilmaril@786
  1694
	while (treeItemsNew.count() < selboxList.count() )
insilmaril@731
  1695
		delete selboxList.takeFirst();
insilmaril@731
  1696
insilmaril@731
  1697
	// Add additonal rectangles
insilmaril@731
  1698
	QGraphicsRectItem *sb;
insilmaril@786
  1699
	while (treeItemsNew.count() > selboxList.count() )
insilmaril@728
  1700
	{
insilmaril@731
  1701
		sb = mapScene->addRect(
insilmaril@731
  1702
			QRectF(0,0,0,0), 
insilmaril@731
  1703
			QPen(selectionColor),
insilmaril@731
  1704
			selectionColor);
insilmaril@731
  1705
		sb->setZValue(Z_SELBOX);
insilmaril@731
  1706
		sb->show();
insilmaril@731
  1707
		selboxList.append (sb);
insilmaril@728
  1708
	}
insilmaril@731
  1709
insilmaril@786
  1710
insilmaril@731
  1711
	// Reposition rectangles
insilmaril@731
  1712
	QRectF bbox;
insilmaril@732
  1713
	QModelIndex index;
insilmaril@732
  1714
insilmaril@732
  1715
	LinkableMapObj *lmo;
insilmaril@786
  1716
	for (int i=0; i<treeItemsNew.count();++i)
insilmaril@731
  1717
	{
insilmaril@786
  1718
		lmo=((MapItem*)treeItemsNew.at(i) )->getLMO();
insilmaril@731
  1719
		bbox=lmo->getBBox();
insilmaril@786
  1720
		sb=selboxList.at(i);
insilmaril@731
  1721
		sb->setRect (
insilmaril@731
  1722
			bbox.x(),bbox.y(), 
insilmaril@731
  1723
			bbox.width(), bbox.height());
insilmaril@731
  1724
		sb->setPen (selectionColor);	
insilmaril@731
  1725
		sb->setBrush (selectionColor);	
insilmaril@731
  1726
		i++;
insilmaril@731
  1727
	}
insilmaril@775
  1728
insilmaril@775
  1729
	scene()->update();
insilmaril@729
  1730
}
insilmaril@728
  1731
insilmaril@753
  1732
void MapEditor::updateData (const QModelIndex &sel)
insilmaril@729
  1733
{
insilmaril@753
  1734
	TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
insilmaril@732
  1735
insilmaril@746
  1736
/* testing
insilmaril@753
  1737
	cout << "ME::updateData\n";
insilmaril@732
  1738
insilmaril@753
  1739
	cout << "  ti="<<ti<<endl;
insilmaril@753
  1740
	cout << "  h="<<ti->getHeading().toStdString()<<endl;
insilmaril@729
  1741
	*/
insilmaril@753
  1742
	
insilmaril@753
  1743
	if (ti->isBranchLikeType())
insilmaril@753
  1744
	{
insilmaril@785
  1745
	//	cout << "  ->updating...\n";
insilmaril@779
  1746
		BranchObj *bo=(BranchObj*) ( ((MapItem*)ti)->getLMO());
insilmaril@767
  1747
		bo->updateData();
insilmaril@753
  1748
	}
insilmaril@726
  1749
}
insilmaril@412
  1750
insilmaril@728
  1751
void MapEditor::setSelectionColor (QColor col)
insilmaril@728
  1752
{
insilmaril@728
  1753
	selectionColor=col;
insilmaril@732
  1754
	QItemSelection sel=model->getSelectionModel()->selection();
insilmaril@732
  1755
	updateSelection(sel,sel);
insilmaril@728
  1756
}
insilmaril@728
  1757
insilmaril@753
  1758
insilmaril@728
  1759
QColor MapEditor::getSelectionColor ()
insilmaril@728
  1760
{
insilmaril@728
  1761
	return selectionColor;
insilmaril@728
  1762
}
insilmaril@728
  1763
insilmaril@728
  1764