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