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