mapeditor.cpp
author insilmaril
Wed, 13 May 2009 08:26:27 +0000
changeset 767 6d2b32f305f9
parent 766 7a71a914afdb
child 769 a6931cd6309a
permissions -rw-r--r--
Started to use QtKinetic for Animation
     1 #include "mapeditor.h"
     2 
     3 #include <iostream>
     4 #include <cstdlib>
     5 #include <typeinfo>
     6 
     7 #include <QObject>
     8 
     9 #include "branchitem.h"
    10 #include "mainwindow.h"
    11 #include "misc.h"
    12 #include "warningdialog.h"
    13 
    14 
    15 extern int statusbarTime;
    16 extern Main *mainWindow;
    17 extern QString tmpVymDir;
    18 extern QString clipboardDir;
    19 extern QString clipboardFile;
    20 extern bool clipboardEmpty;
    21 extern bool debug;
    22 
    23 extern QMenu* branchContextMenu;
    24 extern QMenu* branchAddContextMenu;
    25 extern QMenu* branchRemoveContextMenu;
    26 extern QMenu* branchLinksContextMenu;
    27 extern QMenu* branchXLinksContextMenuEdit;
    28 extern QMenu* branchXLinksContextMenuFollow;
    29 extern QMenu* floatimageContextMenu;
    30 extern QMenu* canvasContextMenu;
    31 
    32 extern Settings settings;
    33 extern QString iconPath;
    34 
    35 ///////////////////////////////////////////////////////////////////////
    36 ///////////////////////////////////////////////////////////////////////
    37 MapEditor::MapEditor( VymModel *vm) 
    38 {
    39 	//cout << "Constructor ME "<<this<<endl;
    40 	mapScene= new QGraphicsScene(NULL);
    41 	mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
    42 
    43 	zoomFactor=zoomFactorTarget=1;
    44 
    45 	model=vm;
    46 	model->setScene (mapScene);
    47 	model->registerEditor(this);
    48 //	model->addMapCenter();	//  FIXME-3 create this in MapEditor until BO and MCO are independent of scene
    49 	model->makeDefault();	// No changes in model so far
    50 
    51     setScene (mapScene);
    52 
    53     printer=NULL;
    54 
    55 	// Create bitmap cursors, platform dependant
    56 	HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);		
    57 	PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); 
    58 	CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 ); 
    59 	XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 ); 
    60 
    61 	setFocusPolicy (Qt::StrongFocus);
    62 
    63 	pickingColor=false;
    64 	drawingLink=false;
    65 	copyingObj=false;
    66 
    67     editingBO=NULL;
    68     movingObj=NULL;
    69 
    70 	printFrame=true;
    71 	printFooter=true;
    72 
    73 	setAcceptDrops (true);	
    74 
    75 	//model->reposition();	//FIXME-3 really still needed?
    76 
    77 
    78 	// Action to embed LineEdit for heading in Scene
    79 	editingHeading=false;
    80 	lineEdit=new QLineEdit;
    81 	lineEdit->hide();
    82 	QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
    83 	pw->setZValue (100);
    84 
    85 	QAction *a = new QAction( tr( "Edit heading","MapEditor" ), this);
    86 	a->setShortcut ( Qt::Key_Return );					//Edit heading
    87 	addAction (a);
    88     connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
    89 	a = new QAction( tr( "Edit heading","MapEditor" ), this);
    90 	a->setShortcut ( Qt::Key_Enter);					//Edit heading
    91 	addAction (a);
    92     connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
    93 
    94 	// Selections
    95 	selectionColor =QColor (255,255,0);
    96 	
    97 
    98 	// Attributes	//FIXME-2 testing only...
    99 	QString k;
   100 	AttributeDef *ad;
   101 	attrTable= new AttributeTable();
   102 	k="A - StringList";
   103 	ad=attrTable->addKey (k,StringList);
   104 	if (ad)
   105 	{
   106 		QStringList sl;
   107 		sl <<"val 1"<<"val 2"<< "val 3";
   108 		ad->setValue (QVariant (sl));
   109 	}
   110 	//attrTable->addValue ("Key A","P 1");
   111 	//attrTable->addValue ("Key A","P 2");
   112 	//attrTable->addValue ("Key A","P 3");
   113 	//attrTable->addValue ("Key A","P 4");
   114 	k="B - FreeString";
   115 	ad=attrTable->addKey (k,FreeString);
   116 	if (ad)
   117 	{
   118 		//attrTable->addValue ("Key B","w1");
   119 		//attrTable->addValue ("Key B","w2");
   120 	}
   121 	k="C - UniqueString";
   122 	ad=attrTable->addKey (k,UniqueString);
   123 	if (ad)
   124 	{
   125 	//attrTable->addKey ("Key Prio");
   126 	//attrTable->addValue ("Key Prio","Prio 1");
   127 	//attrTable->addValue ("Key Prio","Prio 2");
   128 	}
   129 }
   130 
   131 MapEditor::~MapEditor()
   132 {
   133 	//cout <<"Destructor MapEditor for "<<model->getMapName().toStdString()<<endl;
   134 	// No need to remove tmp files:
   135 	// tmpMapDir is in tmpVymDir, 
   136 	// so it gets removed automagically when vym closes
   137 	
   138 	model->unregisterEditor(this);
   139 }
   140 
   141 VymModel* MapEditor::getModel()
   142 {
   143     return model;
   144 }
   145 
   146 QGraphicsScene * MapEditor::getScene()
   147 {
   148     return mapScene;
   149 }
   150 
   151 void MapEditor::setScrollBarPosTarget (const QRectF &rect)
   152 {
   153 	// Code copied from Qt sources
   154 	int xmargin=50;
   155 	int ymargin=50;
   156 
   157     qreal width = viewport()->width();
   158     qreal height = viewport()->height();
   159     QRectF viewRect = matrix().mapRect(rect);
   160 
   161     qreal left = horizontalScrollBar()->value();
   162     qreal right = left + width;
   163     qreal top = verticalScrollBar()->value();
   164     qreal bottom = top + height;
   165 
   166     if (viewRect.left() <= left + xmargin) {
   167         // need to scroll from the left
   168   //      if (!d->leftIndent)
   169             scrollBarPosTarget.setX(int(viewRect.left() - xmargin - 0.5));
   170     }
   171     if (viewRect.right() >= right - xmargin) {
   172         // need to scroll from the right
   173 //        if (!d->leftIndent)
   174             scrollBarPosTarget.setX(int(viewRect.right() - width + xmargin + 0.5));
   175     }
   176     if (viewRect.top() <= top + ymargin) {
   177         // need to scroll from the top
   178    //     if (!d->topIndent)
   179             scrollBarPosTarget.setY(int(viewRect.top() - ymargin - 0.5));
   180     }
   181     if (viewRect.bottom() >= bottom - ymargin) {
   182         // need to scroll from the bottom
   183 //        if (!d->topIndent)
   184             scrollBarPosTarget.setY(int(viewRect.bottom() - height + ymargin + 0.5));
   185     }
   186 
   187 	if (scrollBarPosAnimation.state()==QtAbstractAnimation::Running)
   188 		scrollBarPosAnimation.stop();
   189 	scrollBarPosAnimation.setTargetObject (this);
   190 	scrollBarPosAnimation.setPropertyName ("scrollBarPos");
   191 	scrollBarPosAnimation.setDuration(1000);
   192 	scrollBarPosAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
   193 	scrollBarPosAnimation.setStartValue(
   194 		QPointF (horizontalScrollBar()->value() ,
   195 		         verticalScrollBar()->value() ) );
   196 	scrollBarPosAnimation.setEndValue(scrollBarPosTarget);
   197 	scrollBarPosAnimation.start();
   198 }
   199 
   200 QPointF MapEditor::getScrollBarPosTarget()
   201 {
   202     return scrollBarPosTarget;
   203 }
   204 
   205 
   206 void MapEditor::setScrollBarPos(const QPointF &p)
   207 {
   208     scrollBarPos=p;
   209 	horizontalScrollBar()->setValue(int(p.x()));
   210 	verticalScrollBar()->setValue(int(p.y()));
   211 }
   212 
   213 QPointF MapEditor::getScrollBarPos()
   214 {
   215     return scrollBarPos;
   216 }
   217 
   218 void MapEditor::setZoomFactorTarget (const qreal &zft)
   219 {
   220 	zoomFactorTarget=zft;
   221 	if (zoomAnimation.state()==QtAbstractAnimation::Running)
   222 		zoomAnimation.stop();
   223 	//zoomAnimation=QtPropertyAnimation(this, "zoomFactor");
   224 	zoomAnimation.setTargetObject (this);
   225 	zoomAnimation.setPropertyName ("zoomFactor");
   226 	zoomAnimation.setDuration(1000);
   227 	zoomAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
   228 	zoomAnimation.setStartValue(zoomFactor);
   229 	zoomAnimation.setEndValue(zft);
   230 	zoomAnimation.start();
   231 }
   232 
   233 qreal MapEditor::getZoomFactorTarget()
   234 {
   235     return zoomFactorTarget;
   236 }
   237 
   238 
   239 void MapEditor::setZoomFactor(const qreal &zf)
   240 {
   241     zoomFactor=zf;
   242 	setMatrix (QMatrix(zf, 0, 0, zf, 0, 0),false );
   243 }
   244 
   245 qreal MapEditor::getZoomFactor()
   246 {
   247     return zoomFactor;
   248 }
   249 
   250 void MapEditor::print()
   251 {
   252 	if ( !printer ) 
   253 	{
   254 		printer = new QPrinter;
   255 		printer->setColorMode (QPrinter::Color);
   256 		printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
   257 		printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
   258 		printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
   259 	}
   260 
   261 	QRectF totalBBox=model->getTotalBBox();
   262 
   263 	// Try to set orientation automagically
   264 	// Note: Interpretation of generated postscript is amibiguous, if 
   265 	// there are problems with landscape mode, see
   266 	// http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
   267 
   268 	if (totalBBox.width()>totalBBox.height())
   269 		// recommend landscape
   270 		printer->setOrientation (QPrinter::Landscape);
   271 	else	
   272 		// recommend portrait
   273 		printer->setOrientation (QPrinter::Portrait);
   274 
   275 	if ( printer->setup(this) ) 
   276 	// returns false, if printing is canceled
   277 	{
   278 		QPainter pp(printer);
   279 
   280 		pp.setRenderHint(QPainter::Antialiasing,true);
   281 
   282 		// Don't print the visualisation of selection
   283 		model->unselect();
   284 
   285 		QRectF mapRect=totalBBox;
   286 		QGraphicsRectItem *frame=NULL;
   287 
   288 		if (printFrame) 
   289 		{
   290 			// Print frame around map
   291 			mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
   292 				totalBBox.width()+20, totalBBox.height()+20);
   293 			frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
   294 			frame->setZValue(0);
   295 			frame->show();    
   296 		}		
   297 
   298 
   299 		double paperAspect = (double)printer->width()   / (double)printer->height();
   300 		double   mapAspect = (double)mapRect.width() / (double)mapRect.height();
   301 		int viewBottom;
   302 		if (mapAspect>=paperAspect)
   303 		{
   304 			// Fit horizontally to paper width
   305 			//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );	
   306 			viewBottom=(int)(printer->width()/mapAspect);	
   307 		}	else
   308 		{
   309 			// Fit vertically to paper height
   310 			//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());	
   311 			viewBottom=printer->height();	
   312 		}	
   313 		
   314 		if (printFooter) 
   315 		{
   316 			// Print footer below map
   317 			QFont font;		
   318 			font.setPointSize(10);
   319 			pp.setFont (font);
   320 			QRectF footerBox(0,viewBottom,printer->width(),15);
   321 			// FIXME-3 fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
   322 			pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
   323 		}
   324 		mapScene->render (
   325 			&pp, 
   326 			QRectF (0,0,printer->width(),printer->height()-15),
   327 			QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
   328 		);
   329 		
   330 		// Viewport has paper dimension
   331 		if (frame)  delete (frame);
   332 
   333 		// Restore selection
   334 		model->reselect();
   335 
   336 		// Save settings in vymrc
   337 		settings.writeEntry("/mainwindow/printerName",printer->printerName());
   338 		settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
   339 		settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
   340 	}
   341 }
   342 
   343 void MapEditor::setAntiAlias (bool b)
   344 {
   345 	setRenderHint(QPainter::Antialiasing,b);
   346 }
   347 
   348 void MapEditor::setSmoothPixmap(bool b)
   349 {
   350 	setRenderHint(QPainter::SmoothPixmapTransform,b);
   351 }
   352 
   353 TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
   354 {
   355 	// Start with mapcenter, no images allowed at rootItem
   356 	int i=0;
   357 	BranchItem *bi=model->getRootItem()->getFirstBranch();
   358 	TreeItem *found=NULL;
   359 	while (bi)
   360 	{
   361 		found=bi->findMapItem (p, exclude);
   362 		if (found) return found;
   363 		i++;
   364 		bi=model->getRootItem()->getBranchNum(i);
   365 	}
   366 	return NULL;
   367 }
   368 
   369 AttributeTable* MapEditor::attributeTable()
   370 {
   371 	return attrTable;
   372 }
   373 
   374 void MapEditor::testFunction1()
   375 {
   376 	
   377 	// Code copied from Qt sources
   378 	QRectF rect=model->getSelectedBranchObj()->getBBox();
   379 	int xmargin=50;
   380 	int ymargin=50;
   381 
   382     qreal width = viewport()->width();
   383     qreal height = viewport()->height();
   384     QRectF viewRect = matrix().mapRect(rect);
   385 
   386     qreal left = horizontalScrollBar()->value();
   387     qreal right = left + width;
   388     qreal top = verticalScrollBar()->value();
   389     qreal bottom = top + height;
   390 
   391     if (viewRect.left() <= left + xmargin) {
   392         // need to scroll from the left
   393   //      if (!d->leftIndent)
   394             horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
   395     }
   396     if (viewRect.right() >= right - xmargin) {
   397         // need to scroll from the right
   398 //        if (!d->leftIndent)
   399             horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
   400     }
   401     if (viewRect.top() <= top + ymargin) {
   402         // need to scroll from the top
   403    //     if (!d->topIndent)
   404             verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
   405     }
   406     if (viewRect.bottom() >= bottom - ymargin) {
   407         // need to scroll from the bottom
   408 //        if (!d->topIndent)
   409             verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
   410     }
   411 	cout << "test1:  hor="<<horizontalScrollBar()->value()<<endl;
   412 	cout << "test1:  ver="<<verticalScrollBar()->value()<<endl;
   413 }
   414 /*
   415 	 QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
   416 	 animation->setDuration(5000);
   417 	 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
   418 	 animation->setEasingCurve ( QtEasingCurve::OutQuint);
   419 	 animation->setStartValue(sceneRect() );
   420 	 animation->setEndValue(QRectF(50, 50, 1000, 1000));
   421 
   422 	 animation->start();
   423 */	 
   424 /*
   425 	QDialog *dia= new QDialog (this);
   426 	dia->setGeometry (50,50,10,10);
   427 
   428      dia->show();
   429      dia ->raise();
   430 
   431 	 QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
   432 	 animation->setDuration(1000);
   433 	 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
   434 	 animation->setEasingCurve ( QtEasingCurve::OutQuint);
   435 	 animation->setStartValue(QRect(50, 50, 10, 10));
   436 	 animation->setEndValue(QRect(250, 250, 100, 100));
   437 
   438 	 animation->start();
   439  */
   440 
   441 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
   442 	if (hidemode==HideNone)
   443 	{
   444 		setHideTmpMode (HideExport);
   445 		mapCenter->calcBBoxSizeWithChilds();
   446 		QRectF totalBBox=mapCenter->getTotalBBox();
   447 		QRectF mapRect=totalBBox;
   448 		QCanvasRectangle *frame=NULL;
   449 
   450 		cout << "  map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
   451 	
   452 		mapRect.setRect (totalBBox.x(), totalBBox.y(), 
   453 			totalBBox.width(), totalBBox.height());
   454 		frame=new QCanvasRectangle (mapRect,mapScene);
   455 		frame->setBrush (QColor(white));
   456 		frame->setPen (QColor(black));
   457 		frame->setZValue(0);
   458 		frame->show();    
   459 	}	
   460 	else	
   461 	{
   462 		setHideTmpMode (HideNone);
   463 	}	
   464 	cout <<"  hidemode="<<hidemode<<endl;
   465 	*/
   466 	
   467 void MapEditor::testFunction2()
   468 {
   469 
   470 /*
   471 	// Toggle hidemode
   472 	if (hidemode==HideExport)
   473 		setHideTmpMode (HideNone);
   474 	else	
   475 		setHideTmpMode (HideExport);
   476 */		
   477 }
   478 
   479 void MapEditor::editHeading()
   480 {
   481 	if (editingHeading)
   482 	{
   483 		editHeadingFinished();
   484 		return;
   485 	}
   486 	BranchObj *bo=model->getSelectedBranchObj();
   487 	BranchItem *bi=model->getSelectedBranchItem();
   488 	if (bo)	//FIXME-3
   489 	{
   490 		model->setSelectionBlocked(true);
   491 
   492 		lineEdit->setText (bi->getHeading());
   493 		QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
   494 		lineEdit->setGeometry(p.x(),p.y(),230,25);
   495 		lineEdit->selectAll();
   496 		lineEdit->show();
   497 		lineEdit->setFocus();
   498 		lineEdit->grabKeyboard();
   499 		editingHeading=true;
   500 	}
   501 
   502 }
   503 void MapEditor::editHeadingFinished()
   504 {
   505 	editingHeading=false;
   506 	lineEdit->releaseKeyboard();
   507 	model->setHeading (lineEdit->text() );
   508 	model->setSelectionBlocked(false);
   509 	lineEdit->hide();
   510 
   511 	// Maybe reselect previous branch 
   512 	mainWindow->editHeadingFinished (model);
   513 }
   514 
   515 
   516 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
   517 {
   518 	// Lineedits are already closed by preceding
   519 	// mouseEvent, we don't need to close here.
   520 
   521     QPointF p = mapToScene(e->pos());
   522     TreeItem *ti=findMapItem (p, NULL);
   523     LinkableMapObj* lmo=NULL;
   524 	if (ti) lmo=ti->getLMO();	//FIXME-2 get rid of lmo...
   525 	
   526     if (lmo) 
   527 	{	// MapObj was found
   528 		if (model->getSelectedLMO() != lmo)
   529 		{
   530 			// select the MapObj
   531 			model->select(lmo);
   532 		}
   533 		// Context Menu 
   534 		if (model->getSelectedBranchObj() ) 
   535 		{
   536 			// Context Menu on branch or mapcenter
   537 			//FIXME-3 model->updateActions(); needed?
   538 			branchContextMenu->popup(e->globalPos() );
   539 		} else
   540 		{
   541 			if (model->getSelectedFloatImage() )
   542 			{
   543 				// Context Menu on floatimage
   544 				// model->updateActions(); FIXME-3 needed?
   545 				floatimageContextMenu->popup(e->globalPos() );
   546 			}	
   547 		}	
   548 	} else 
   549 	{ // No MapObj found, we are on the Canvas itself
   550 		// Context Menu on scene
   551 		// model->updateActions(); FIXME-3 needed?
   552 		
   553 		// Open context menu synchronously to position new mapcenter
   554 		model->setContextPos (p);
   555 		canvasContextMenu->exec(e->globalPos() );
   556 		model->unsetContextPos ();
   557     } 
   558 	e->accept();
   559 }
   560 
   561 void MapEditor::keyPressEvent(QKeyEvent* e)
   562 {
   563 	if (e->modifiers() & Qt::ControlModifier)
   564 	{
   565 		switch (mainWindow->getModMode())
   566 		{
   567 			case Main::ModModeColor: 
   568 				setCursor (PickColorCursor);
   569 				break;
   570 			case Main::ModModeCopy: 
   571 				setCursor (CopyCursor);
   572 				break;
   573 			case Main::ModModeXLink: 
   574 				setCursor (XLinkCursor);
   575 				break;
   576 			default :
   577 				setCursor (Qt::ArrowCursor);
   578 				break;
   579 		} 
   580 	}	
   581 }
   582 
   583 void MapEditor::keyReleaseEvent(QKeyEvent* e)
   584 {
   585 	if (!(e->modifiers() & Qt::ControlModifier))
   586 		setCursor (Qt::ArrowCursor);
   587 }
   588 
   589 void MapEditor::mousePressEvent(QMouseEvent* e)
   590 {
   591 	// Ignore right clicks, these will go to context menus
   592 	if (e->button() == Qt::RightButton )
   593 	{
   594 		e->ignore();
   595 		return;
   596 	}
   597 
   598 	//Ignore clicks while editing heading
   599 	if (model->isSelectionBlocked() ) 
   600 	{
   601 		e->ignore();
   602 		return;
   603 	}
   604 
   605     QPointF p = mapToScene(e->pos());
   606     TreeItem *ti=findMapItem (p, NULL);
   607     LinkableMapObj* lmo=NULL;
   608 	if (ti) lmo=ti->getLMO();	//FIXME-2 get rid of lmo...
   609 	
   610 	e->accept();
   611 
   612 	//Take care of  system flags _or_ modifier modes
   613 	//
   614 	if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
   615 		typeid(*lmo)==typeid(MapCenterObj) ))
   616 	{
   617 		QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
   618 		if (!foname.isEmpty())
   619 		{
   620 			// systemFlag clicked
   621 			model->select (lmo);	// FIXME-3 was selectInt
   622 			if (foname=="url") 
   623 			{
   624 				if (e->state() & Qt::ControlModifier)
   625 					mainWindow->editOpenURLTab();
   626 				else	
   627 					mainWindow->editOpenURL();
   628 			}	
   629 			else if (foname=="vymLink")
   630 			{
   631 				mainWindow->editOpenVymLink();
   632 				// tabWidget may change, better return now
   633 				// before segfaulting...
   634 			} else if (foname=="note")
   635 				mainWindow->windowToggleNoteEditor();
   636 			else if (foname=="hideInExport")		
   637 				model->toggleHideExport();
   638 			// FIXME-3 needed? xelection.update();	
   639 			return;	
   640 		} 
   641 	}	
   642 	// No system flag clicked, take care of modmodes (CTRL-Click)
   643 	if (e->state() & Qt::ControlModifier)
   644 	{
   645 		if (mainWindow->getModMode()==Main::ModModeColor)
   646 		{
   647 				pickingColor=true;
   648 				setCursor (PickColorCursor);
   649 				return;
   650 		} 
   651 		if (mainWindow->getModMode()==Main::ModModeXLink)
   652 		{	
   653 			BranchObj *bo_begin=NULL;
   654 			if (lmo)
   655 				bo_begin=(BranchObj*)(lmo);
   656 			else	
   657 				bo_begin=model->getSelectedBranchObj();
   658 			if (bo_begin)	
   659 			{
   660 				drawingLink=true;
   661 				linkingObj_src=bo_begin;
   662 				tmpXLink=new XLinkObj (mapScene);
   663 				tmpXLink->setBegin (bo_begin);
   664 				tmpXLink->setEnd   (p);
   665 				tmpXLink->setColor(model->getMapDefXLinkColor());
   666 				tmpXLink->setWidth(model->getMapDefXLinkWidth());
   667 				tmpXLink->updateXLink();
   668 				tmpXLink->setVisibility (true);
   669 				return;
   670 			} 
   671 		}
   672 	}	// End of modmodes
   673 
   674     if (lmo) 
   675 	{	
   676 	/*
   677 		cout << "ME::mouse pressed\n";
   678 		cout << "  lmo="<<lmo<<endl;
   679 		cout << "  h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
   680 	*/
   681 		// Select the clicked object
   682 
   683 		// FIXME-2 VM better let "find" return an index instead of lmo...
   684 		// Get index of clicked LMO
   685 		TreeItem *ti=lmo->getTreeItem();
   686 		/*
   687 		cout << "  lmo="<<lmo<<"    lmo(ti)="<<ti->getLMO()<<endl;
   688 		cout << "  ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
   689 		*/
   690 		//QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
   691 		model->select (ti);
   692 
   693 		// Left Button	    Move Branches
   694 		if (e->button() == Qt::LeftButton )
   695 		{
   696 			//movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here	
   697 			//movingObj_start.setY( p.y() - selection->y() );	
   698 			movingObj_start.setX( p.x() - lmo->x() );	
   699 			movingObj_start.setY( p.y() - lmo->y() );	
   700 			movingObj_orgPos.setX (lmo->x() );
   701 			movingObj_orgPos.setY (lmo->y() );
   702 			lmo->setRelPos();
   703 			movingObj_orgRelPos=lmo->getRelPos();
   704 
   705 			// If modMode==copy, then we want to "move" the _new_ object around
   706 			// then we need the offset from p to the _old_ selection, because of tmp
   707 			if (mainWindow->getModMode()==Main::ModModeCopy &&
   708 				e->state() & Qt::ControlModifier)
   709 			{
   710 				BranchItem *bi=model->getSelectedBranchItem();
   711 				if (bi)
   712 				{
   713 					copyingObj=true;
   714 					//FIXME-2   TreeItem::addBranch (BranchItem still missing) 
   715 					//bi->addBranch (model->getSelectedBranchItem());
   716 					model->unselect();
   717 					model->select(bi->getLastBranch());
   718 					model->reposition();
   719 				}
   720 			} 
   721 
   722 			movingObj=model->getSelectedLMO();	
   723 		} else
   724 			// Middle Button    Toggle Scroll
   725 			// (On Mac OS X this won't work, but we still have 
   726 			// a button in the toolbar)
   727 			if (e->button() == Qt::MidButton )
   728 				model->toggleScroll();
   729 		// model->updateActions(); FIXME-3 needed?
   730 		// FIXME-3 needed? xelection.update();
   731 	} else 
   732 	{ // No MapObj found, we are on the scene itself
   733 		// Left Button	    move Pos of sceneView
   734 		if (e->button() == Qt::LeftButton )
   735 		{
   736 			movingObj=NULL;	// move Content not Obj
   737 			movingObj_start=e->globalPos();
   738 			movingCont_start=QPointF (
   739 				horizontalScrollBar()->value(),
   740 				verticalScrollBar()->value());
   741 			movingVec=QPointF(0,0);
   742 			setCursor(HandOpenCursor);
   743 		} 
   744     } 
   745 }
   746 
   747 void MapEditor::mouseMoveEvent(QMouseEvent* e)
   748 {
   749     QPointF p = mapToScene(e->pos());
   750 	TreeItem *seli=model->getSelectedItem();
   751 	LinkableMapObj* lmosel=NULL;		//FIXME-2 get rid of lmosel
   752 	if (seli)
   753 		lmosel=seli->getLMO();
   754 
   755     // Move the selected MapObj
   756     if ( lmosel && movingObj) 
   757     {	
   758 		// reset cursor if we are moving and don't copy
   759 		if (mainWindow->getModMode()!=Main::ModModeCopy)
   760 			setCursor (Qt::ArrowCursor);
   761 
   762 		// To avoid jumping of the sceneView, only 
   763 		// show selection, if not tmp linked
   764 		if (!lmosel->hasParObjTmp())
   765 			model->emitShowSelection();
   766 		
   767 		// Now move the selection, but add relative position 
   768 		// (movingObj_start) where selection was chosen with 
   769 		// mousepointer. (This avoids flickering resp. jumping 
   770 		// of selection back to absPos)
   771 		
   772 		// Check if we could link 
   773 		TreeItem *dsti=findMapItem (p, seli);
   774 		LinkableMapObj* dst=NULL;
   775 		if (dsti) dst=dsti->getLMO();	//FIXME-2 get rid of lmo...
   776 		
   777 
   778 		FloatObj *fio=model->getSelectedFloatImage();
   779 		if (fio)
   780 		{
   781 			fio->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
   782 			fio->setRelPos();
   783 			fio->updateLink(); //no need for reposition, if we update link here
   784 			model->updateSelection();	// position has changed
   785 
   786 			// Relink float to new mapcenter or branch, if shift is pressed	
   787 			// Only relink, if selection really has a new parent
   788 			if ( (e->modifiers()==Qt::ShiftModifier) && dst &&
   789 				( (typeid(*dst)==typeid(BranchObj)) ||
   790 				  (typeid(*dst)==typeid(MapCenterObj)) ) &&
   791 				( dst != fio->getParObj())  
   792 				)
   793 			{
   794 				if (typeid(*fio) == typeid(FloatImageObj) && 
   795 				( (typeid(*dst)==typeid(BranchObj) ||
   796 				  typeid(*dst)==typeid(MapCenterObj)) ))  
   797 				{
   798 
   799 					// Also save the move which was done so far
   800 					QString pold=qpointfToString(movingObj_orgRelPos);
   801 					QString pnow=qpointfToString(fio->getRelPos());
   802 					model->saveState(
   803 						fio->getTreeItem(),  // FIXME-3 
   804 						"moveRel "+pold,
   805 						fio->getTreeItem(),
   806 						"moveRel "+pnow,
   807 						QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
   808 					fio->getParObj()->requestReposition();
   809 					model->reposition();
   810 
   811 					model->linkFloatImageTo (model->getSelectString(dst));
   812 					//movingObj=lmosel;
   813 					//movingObj_orgRelPos=lmosel->getRelPos();	
   814 
   815 					model->reposition();
   816 				}	
   817 			}
   818 		} else	
   819 		{	// selection != a FloatObj
   820 			if (seli->depth()==0)		//FIXME-1 also moved mapcenters could be linked, but not working here...
   821 			{
   822 				// Move MapCenter
   823 				if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier) 
   824 					((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
   825 				else	
   826 					lmosel->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
   827 				model->updateRelPositions();
   828 			} else
   829 			{	
   830 				if (seli->depth()==1)
   831 				{
   832 					// Move mainbranch
   833 					lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
   834 					lmosel->setRelPos();
   835 				} else
   836 				{
   837 					// Move ordinary branch
   838 					if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
   839 						// Add width of bbox here, otherwise alignRelTo will cause jumping around
   840 						lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(), 
   841 							p.y()-movingObj_start.y() +lmosel->getTopPad() );		
   842 					else	
   843 						lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
   844 					lmosel->setRelPos();	
   845 				} 
   846 
   847 				// Maybe we can relink temporary?
   848 				if (dsti && (dst!=lmosel) && seli->isBranchLikeType() && dsti->isBranchLikeType() )
   849 				{
   850 					if (e->modifiers()==Qt::ControlModifier)
   851 					{
   852 						// Special case: CTRL to link below dst
   853 						lmosel->setParObjTmp (dst,p,+1);
   854 					}
   855 					else if (e->modifiers()==Qt::ShiftModifier)
   856 						lmosel->setParObjTmp (dst,p,-1);
   857 					else
   858 						lmosel->setParObjTmp (dst,p,0);
   859 				} else	
   860 				{
   861 					lmosel->unsetParObjTmp();
   862 				}		
   863 				// reposition subbranch
   864 				lmosel->reposition();	
   865 			} // depth>0
   866 
   867 			QItemSelection sel=model->getSelectionModel()->selection();
   868 			updateSelection(sel,sel);	// position has changed
   869 
   870 		} // no FloatImageObj
   871 
   872 		scene()->update();
   873 		return;
   874 	} // selection && moving_obj
   875 		
   876 	// Draw a link from one branch to another
   877 	if (drawingLink)
   878 	{
   879 		 tmpXLink->setEnd (p);
   880 		 tmpXLink->updateXLink();
   881 	}	 
   882 	
   883     // Move sceneView 
   884     if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton ) 
   885 	{
   886 		QPointF p=e->globalPos();
   887 		movingVec.setX(-p.x() + movingObj_start.x() );
   888 		movingVec.setY(-p.y() + movingObj_start.y() );
   889 		horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
   890 		verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
   891     }
   892 }
   893 
   894 
   895 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
   896 {
   897     QPointF p = mapToScene(e->pos());
   898 	TreeItem *seli=model->getSelectedItem();
   899 
   900 	TreeItem *dsti=findMapItem(p, seli);
   901 	LinkableMapObj* dst=NULL;
   902 	if (dsti) dst=dsti->getLMO();	//FIXME-2 get rid of dst...
   903 
   904 
   905 	// Have we been picking color?
   906 	if (pickingColor)
   907 	{
   908 		pickingColor=false;
   909 		setCursor (Qt::ArrowCursor);
   910 		// Check if we are over another branch
   911 		if (dsti && seli) 
   912 		{	
   913 			if (e->state() & Qt::ShiftModifier)
   914 				model->colorBranch (((BranchObj*)dst)->getColor());
   915 			else	
   916 				model->colorSubtree (((BranchObj*)dst)->getColor());
   917 		} 
   918 		return;
   919 	}
   920 
   921 	// Have we been drawing a link?
   922 	if (drawingLink)	
   923 	{
   924 		drawingLink=false;
   925 		// Check if we are over another branch
   926 		if (dsti && seli && dsti->isBranchLikeType() ) 
   927 		{	
   928 			tmpXLink->setEnd ( ((BranchObj*)(dst)) );
   929 			tmpXLink->updateXLink();
   930 			tmpXLink->activate(); //FIXME-2 savestate missing
   931 			//model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );	
   932 		} else
   933 		{
   934 			delete(tmpXLink);
   935 			tmpXLink=NULL;
   936 		}
   937 		return;
   938 	}
   939 	
   940     // Have we been moving something?
   941     if ( seli && movingObj ) 
   942     {	
   943 		if (dsti==seli) 
   944 		{
   945 			dsti=NULL;
   946 			dst=NULL;
   947 		}
   948 		FloatImageObj *fo=model->getSelectedFloatImage();
   949 		if(fo)
   950 		{
   951 			// Moved FloatObj. Maybe we need to reposition
   952 		    QString pold=qpointfToString(movingObj_orgRelPos);
   953 		    QString pnow=qpointfToString(fo->getRelPos());
   954 			model->saveState(
   955 				fo->getTreeItem(),	// FIXME-3
   956 				"moveRel "+pold,
   957 				fo->getTreeItem(),	// FIXME-3
   958 				"moveRel "+pnow,
   959 				QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
   960 
   961 			fo->getParObj()->requestReposition();
   962 			model->reposition();
   963 		}	
   964 
   965 		// Check if we are over another branch, but ignore 
   966 		// any found LMOs, which are FloatObjs
   967 
   968 		if (dsti && (!dsti->isBranchLikeType() )) 
   969 		{
   970 			dst=NULL;
   971 			dsti=NULL;
   972 		}	
   973 		
   974 		BranchItem *bi=model->getSelectedBranchItem();
   975 		if (bi && bi->depth()==0)
   976 		{	
   977             if (movingObj_orgPos != bi->getBranchObj()->getAbsPos())	// FIXME-3 check getBO here...
   978             {
   979                 QString pold=qpointfToString(movingObj_orgPos);
   980                 QString pnow=qpointfToString(bi->getBranchObj()->getAbsPos());		// FIXME-3 check getBO here...
   981 
   982                 model->saveState(
   983                     bi,
   984                     "move "+pold,
   985                     bi,
   986                     "move "+pnow,
   987                     QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
   988             }
   989 		}
   990 	
   991 		if (seli->getType() == TreeItem::Branch )
   992 		{	// A branch was moved
   993 			LinkableMapObj* lmosel=NULL;		//FIXME-2 get rid of lmosel
   994 			lmosel=seli->getLMO();
   995 				
   996 			// save the position in case we link to mapcenter
   997 			QPointF savePos=QPointF (lmosel->getAbsPos()  );
   998 
   999 			// Reset the temporary drawn link to the original one
  1000 			lmosel->unsetParObjTmp();
  1001 
  1002 			// For Redo we may need to save original selection
  1003 			QString preSelStr=model->getSelectString(lmosel);
  1004 
  1005 			copyingObj=false;	
  1006 			if (dsti && dsti->isBranchLikeType() ) 
  1007 			{
  1008 				// We have a destination, relink to that
  1009 
  1010 				BranchObj* bsel=model->getSelectedBranchObj();
  1011 
  1012 				QString preParStr=model->getSelectString (bsel->getParObj());
  1013 				QString preNum=QString::number (seli->num(),10);
  1014 				QString preDstParStr;
  1015 				bool relinked;
  1016 
  1017 				if (e->state() & Qt::ShiftModifier && dst->getParObj())
  1018 				{	// Link above dst
  1019 					preDstParStr=model->getSelectString (dst->getParObj());
  1020 					relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
  1021 				} else 
  1022 				if (e->state() & Qt::ControlModifier && dst->getParObj())
  1023 				{
  1024 					// Link below dst
  1025 					preDstParStr=model->getSelectString (dst->getParObj());
  1026 					relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()+1);
  1027 				} else	
  1028 				{	// Append to dst
  1029 					preDstParStr=model->getSelectString(dst);
  1030 					relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
  1031 					if (dsti->depth()==0) bsel->move (savePos);
  1032 				} 
  1033 				if (relinked)
  1034 				{
  1035 					QString postSelStr=model->getSelectString(lmosel);
  1036 					QString postNum=QString::number (seli->num(),10);
  1037 
  1038 					QString undoCom="linkTo (\""+ 
  1039 						preParStr+ "\"," + preNum  +"," + 
  1040 						QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
  1041 
  1042 					QString redoCom="linkTo (\""+ 
  1043 						preDstParStr + "\"," + postNum + "," +
  1044 						QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
  1045 
  1046 					model->saveState (
  1047 						postSelStr,undoCom,
  1048 						preSelStr, redoCom,
  1049 						QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
  1050 
  1051 				}
  1052 			} else
  1053 			{
  1054 				// No destination, undo  temporary move
  1055 
  1056 				if (seli->depth()==1)
  1057 				{
  1058 					// The select string might be different _after_ moving around.
  1059 					// Therefor reposition and then use string of old selection, too
  1060 					model->reposition();
  1061 
  1062                     QPointF rp(lmosel->getRelPos());
  1063                     if (rp != movingObj_orgRelPos)
  1064                     {
  1065                         QString ps=qpointfToString(rp);
  1066                         model->saveState(
  1067                             model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos), 
  1068                             preSelStr, "moveRel "+ps, 
  1069                             QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
  1070                     }
  1071 				}
  1072 
  1073 				// Draw the original link, before selection was moved around
  1074 				if (settings.value("/animation/use",false).toBool() && seli->depth()>1) 
  1075 				{
  1076 					lmosel->setRelPos();	// calc relPos first for starting point
  1077 					QPointF dst=bi->getBranchObj()->getParObj()->getChildPos();		// FIXME-3 check getBO here...
  1078 			//		if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
  1079 					
  1080 					model->startAnimation(
  1081 						(BranchObj*)lmosel,
  1082 						lmosel->getRelPos(),
  1083 						movingObj_orgRelPos
  1084 //						QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
  1085 					);	
  1086 				} else	
  1087 					model->reposition();
  1088 			}
  1089 		}
  1090 		model->updateSelection();  //FIXME-3 needed? at least not after pos of selection has changed...
  1091 		// Finally resize scene, if needed
  1092 		scene()->update();
  1093 		movingObj=NULL;		
  1094 
  1095 		// Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
  1096 		// model->updateActions(); FIXME-3 neeeded? 
  1097 	} else 
  1098 		// maybe we moved View: set old cursor
  1099 		setCursor (Qt::ArrowCursor);
  1100     
  1101 }
  1102 
  1103 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
  1104 {
  1105 	if (model->isSelectionBlocked() ) 
  1106 	{
  1107 		e->ignore();
  1108 		return;
  1109 	}
  1110 
  1111 	if (e->button() == Qt::LeftButton )
  1112 	{
  1113 		QPointF p = mapToScene(e->pos());
  1114 		TreeItem *ti=findMapItem (p, NULL);
  1115 		if (ti) {	// MapObj was found
  1116 			// First select the MapObj than edit heading
  1117 			model->select (ti);
  1118 			editHeading();
  1119 		}
  1120 	}
  1121 }
  1122 
  1123 void MapEditor::resizeEvent (QResizeEvent* e)
  1124 {
  1125 	QGraphicsView::resizeEvent( e );
  1126 }
  1127 
  1128 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
  1129 {
  1130 	//for (unsigned int i=0;event->format(i);i++) // Debug mime type
  1131 	//	cerr << event->format(i) << endl;
  1132 
  1133 	if (event->mimeData()->hasImage())
  1134 		event->acceptProposedAction();
  1135 	else	
  1136 		if (event->mimeData()->hasUrls())
  1137 			event->acceptProposedAction();
  1138 }
  1139 
  1140 void MapEditor::dragMoveEvent(QDragMoveEvent *)
  1141 {
  1142 }
  1143 
  1144 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
  1145 {
  1146 	event->accept();
  1147 }
  1148 
  1149 void MapEditor::dropEvent(QDropEvent *event)
  1150 {
  1151 	BranchItem *selbi=model->getSelectedBranchItem();
  1152 	if (selbi)
  1153 	{
  1154 		if (debug)
  1155 			foreach (QString format,event->mimeData()->formats()) 
  1156 				cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
  1157 
  1158 
  1159 		QList <QUrl> uris;
  1160 		if (event->mimeData()->hasImage()) 
  1161 		{
  1162 			 QVariant imageData = event->mimeData()->imageData();
  1163 			 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
  1164 		} else
  1165 		if (event->mimeData()->hasUrls())
  1166 			uris=event->mimeData()->urls();
  1167 
  1168 		if (uris.count()>0)
  1169 		{
  1170 			QStringList files;
  1171 			QString s;
  1172 			QString heading;
  1173 			BranchItem *bi;
  1174 			for (int i=0; i<uris.count();i++)
  1175 			{
  1176 				// Workaround to avoid adding empty branches
  1177 				if (!uris.at(i).toString().isEmpty())
  1178 				{
  1179 					bi=model->createBranch();
  1180 					if (bi)
  1181 					{
  1182 						   /* FIXME-2 
  1183 						s=uris.at(i).toLocalFile();
  1184 						if (!s.isEmpty()) 
  1185 						{
  1186 						   QString file = QDir::fromNativeSeparators(s);
  1187 						   heading = QFileInfo(file).baseName();
  1188 						   files.append(file);
  1189 						   if (file.endsWith(".vym", false))
  1190 							   bi->setVymLink(file);
  1191 						   else
  1192 							   bi->setURL(uris.at(i).toString());
  1193 					   } else 
  1194 					   {
  1195 						   bo->setURL(uris.at(i).toString());
  1196 					   }
  1197 							 */  
  1198 
  1199 					   if (!heading.isEmpty())
  1200 						   bi->setHeading(heading);
  1201 					   else
  1202 						   bi->setHeading(uris.at(i).toString());
  1203 						   
  1204 					}
  1205 				}
  1206 			}
  1207 			model->reposition();
  1208 		}
  1209 	}	
  1210 	event->acceptProposedAction();
  1211 }
  1212 
  1213 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
  1214 {
  1215 	// Reduce rectangles
  1216 	while (newsel.indexes().count() < selboxList.count() )
  1217 		delete selboxList.takeFirst();
  1218 
  1219 	// Add additonal rectangles
  1220 	QGraphicsRectItem *sb;
  1221 	while (newsel.indexes().count() > selboxList.count() )
  1222 	{
  1223 		sb = mapScene->addRect(
  1224 			QRectF(0,0,0,0), 
  1225 			QPen(selectionColor),
  1226 			selectionColor);
  1227 		sb->setZValue(Z_SELBOX);
  1228 		sb->show();
  1229 		selboxList.append (sb);
  1230 	}
  1231 
  1232 	// Reposition rectangles
  1233 	int i=0;
  1234 	QRectF bbox;
  1235 	QModelIndex index;
  1236 
  1237 	TreeItem *ti;
  1238 	LinkableMapObj *lmo;
  1239 	foreach (sb,selboxList)
  1240 	{
  1241 		index=newsel.indexes().at(i);
  1242 		ti= static_cast<TreeItem*>(index.internalPointer());
  1243 		lmo=ti->getLMO();
  1244 		bbox=lmo->getBBox();
  1245 		sb->setRect (
  1246 			bbox.x(),bbox.y(), 
  1247 			bbox.width(), bbox.height());
  1248 		sb->setPen (selectionColor);	
  1249 		sb->setBrush (selectionColor);	
  1250 		i++;
  1251 	}
  1252 }
  1253 
  1254 void MapEditor::updateData (const QModelIndex &sel)
  1255 {
  1256 	TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
  1257 
  1258 /* testing
  1259 	cout << "ME::updateData\n";
  1260 
  1261 	cout << "  ti="<<ti<<endl;
  1262 	cout << "  h="<<ti->getHeading().toStdString()<<endl;
  1263 	*/
  1264 	
  1265 	if (ti->isBranchLikeType())
  1266 	{
  1267 		BranchObj *bo=(BranchObj*)ti->getLMO();
  1268 		bo->updateData();
  1269 	}
  1270 
  1271 }
  1272 
  1273 void MapEditor::setSelectionColor (QColor col)
  1274 {
  1275 	selectionColor=col;
  1276 	QItemSelection sel=model->getSelectionModel()->selection();
  1277 	updateSelection(sel,sel);
  1278 }
  1279 
  1280 
  1281 QColor MapEditor::getSelectionColor ()
  1282 {
  1283 	return selectionColor;
  1284 }
  1285 
  1286