9 #include "branchitem.h"
10 #include "mainwindow.h"
12 #include "warningdialog.h"
15 extern int statusbarTime;
16 extern Main *mainWindow;
17 extern QString tmpVymDir;
18 extern QString clipboardDir;
19 extern QString clipboardFile;
20 extern bool clipboardEmpty;
22 extern FlagRowObj *standardFlagsDefault;
24 extern QMenu* branchContextMenu;
25 extern QMenu* branchAddContextMenu;
26 extern QMenu* branchRemoveContextMenu;
27 extern QMenu* branchLinksContextMenu;
28 extern QMenu* branchXLinksContextMenuEdit;
29 extern QMenu* branchXLinksContextMenuFollow;
30 extern QMenu* floatimageContextMenu;
31 extern QMenu* canvasContextMenu;
33 extern Settings settings;
34 extern QString iconPath;
36 ///////////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////////
38 MapEditor::MapEditor( VymModel *vm)
40 //cout << "Constructor ME "<<this<<endl;
41 mapScene= new QGraphicsScene(NULL);
42 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
45 model->setScene (mapScene);
46 model->registerEditor(this);
47 // model->addMapCenter(); // FIXME-3 create this in MapEditor until BO and MCO are independent of scene
48 model->makeDefault(); // No changes in model so far
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 );
60 setFocusPolicy (Qt::StrongFocus);
72 setAcceptDrops (true);
74 //model->reposition(); //FIXME-3 really still needed?
77 // Action to embed LineEdit for heading in Scene
79 lineEdit=new QLineEdit;
81 QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
84 QAction *a = new QAction( tr( "Edit heading","MapEditor" ), this);
85 a->setShortcut ( Qt::Key_Return ); //Edit heading
87 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
88 a = new QAction( tr( "Edit heading","MapEditor" ), this);
89 a->setShortcut ( Qt::Key_Enter); //Edit heading
91 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
94 selectionColor =QColor (255,255,0);
97 // Attributes //FIXME-2 testing only...
100 attrTable= new AttributeTable();
102 ad=attrTable->addKey (k,StringList);
106 sl <<"val 1"<<"val 2"<< "val 3";
107 ad->setValue (QVariant (sl));
109 //attrTable->addValue ("Key A","P 1");
110 //attrTable->addValue ("Key A","P 2");
111 //attrTable->addValue ("Key A","P 3");
112 //attrTable->addValue ("Key A","P 4");
114 ad=attrTable->addKey (k,FreeString);
117 //attrTable->addValue ("Key B","w1");
118 //attrTable->addValue ("Key B","w2");
120 k="C - UniqueString";
121 ad=attrTable->addKey (k,UniqueString);
124 //attrTable->addKey ("Key Prio");
125 //attrTable->addValue ("Key Prio","Prio 1");
126 //attrTable->addValue ("Key Prio","Prio 2");
130 MapEditor::~MapEditor()
132 //cout <<"Destructor MapEditor for "<<model->getMapName().toStdString()<<endl;
133 // No need to remove tmp files:
134 // tmpMapDir is in tmpVymDir,
135 // so it gets removed automagically when vym closes
137 model->unregisterEditor(this);
140 VymModel* MapEditor::getModel()
145 QGraphicsScene * MapEditor::getScene()
150 void MapEditor::print()
154 printer = new QPrinter;
155 printer->setColorMode (QPrinter::Color);
156 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
157 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
158 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
161 QRectF totalBBox=model->getTotalBBox();
163 // Try to set orientation automagically
164 // Note: Interpretation of generated postscript is amibiguous, if
165 // there are problems with landscape mode, see
166 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
168 if (totalBBox.width()>totalBBox.height())
169 // recommend landscape
170 printer->setOrientation (QPrinter::Landscape);
172 // recommend portrait
173 printer->setOrientation (QPrinter::Portrait);
175 if ( printer->setup(this) )
176 // returns false, if printing is canceled
178 QPainter pp(printer);
180 pp.setRenderHint(QPainter::Antialiasing,true);
182 // Don't print the visualisation of selection
185 QRectF mapRect=totalBBox;
186 QGraphicsRectItem *frame=NULL;
190 // Print frame around map
191 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
192 totalBBox.width()+20, totalBBox.height()+20);
193 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
199 double paperAspect = (double)printer->width() / (double)printer->height();
200 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
202 if (mapAspect>=paperAspect)
204 // Fit horizontally to paper width
205 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
206 viewBottom=(int)(printer->width()/mapAspect);
209 // Fit vertically to paper height
210 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
211 viewBottom=printer->height();
216 // Print footer below map
218 font.setPointSize(10);
220 QRectF footerBox(0,viewBottom,printer->width(),15);
221 // FIXME-3 fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
222 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
226 QRectF (0,0,printer->width(),printer->height()-15),
227 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
230 // Viewport has paper dimension
231 if (frame) delete (frame);
236 // Save settings in vymrc
237 settings.writeEntry("/mainwindow/printerName",printer->printerName());
238 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
239 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
243 void MapEditor::setAntiAlias (bool b)
245 setRenderHint(QPainter::Antialiasing,b);
248 void MapEditor::setSmoothPixmap(bool b)
250 setRenderHint(QPainter::SmoothPixmapTransform,b);
253 TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
255 // Start with mapcenter, no images allowed at rootItem
257 BranchItem *bi=model->getRootItem()->getFirstBranch();
258 TreeItem *found=NULL;
261 found=bi->findMapItem (p, exclude);
262 if (found) return found;
264 bi=model->getRootItem()->getBranchNum(i);
269 AttributeTable* MapEditor::attributeTable()
274 void MapEditor::testFunction1()
276 BranchItem *cur=NULL;
277 BranchItem *prev=NULL;
279 cout << "ME::testFunction1 starting to walk the map...\n";
280 while (model->next (cur,prev,d) )
281 cout << "*** " <<cur->getHeading().toStdString()<<endl;
284 //BranchObj *bo=model->getSelectedBranchObj();
285 //if (bo) model->moveAway (bo);
286 //if (bo) bo->setLinkStyle (LinkableMapObj::Line);
290 // Displacement and animation of all non-mainbranches
299 bo=(BranchObj*)(cur->getLMO());
301 if (cur->depth() >0 && !bo->hasScrolledParent(bo) )
303 p=QPointF (qrand() %600-300, qrand () %600-300);
306 model->startAnimation (bo,p, q);
308 model->next(cur,prev,d);
313 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
314 if (hidemode==HideNone)
316 setHideTmpMode (HideExport);
317 mapCenter->calcBBoxSizeWithChilds();
318 QRectF totalBBox=mapCenter->getTotalBBox();
319 QRectF mapRect=totalBBox;
320 QCanvasRectangle *frame=NULL;
322 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
324 mapRect.setRect (totalBBox.x(), totalBBox.y(),
325 totalBBox.width(), totalBBox.height());
326 frame=new QCanvasRectangle (mapRect,mapScene);
327 frame->setBrush (QColor(white));
328 frame->setPen (QColor(black));
334 setHideTmpMode (HideNone);
336 cout <<" hidemode="<<hidemode<<endl;
340 void MapEditor::testFunction2()
345 if (hidemode==HideExport)
346 setHideTmpMode (HideNone);
348 setHideTmpMode (HideExport);
352 void MapEditor::editHeading()
356 editHeadingFinished();
359 BranchObj *bo=model->getSelectedBranchObj();
360 BranchItem *bi=model->getSelectedBranchItem();
363 model->setSelectionBlocked(true);
365 lineEdit->setText (bi->getHeading());
366 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
367 lineEdit->setGeometry(p.x(),p.y(),230,25);
368 lineEdit->selectAll();
370 lineEdit->setFocus();
371 lineEdit->grabKeyboard();
376 void MapEditor::editHeadingFinished()
378 editingHeading=false;
379 lineEdit->releaseKeyboard();
380 model->setHeading (lineEdit->text() );
381 model->setSelectionBlocked(false);
384 // Maybe reselect previous branch
385 mainWindow->editHeadingFinished (model);
389 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
391 // Lineedits are already closed by preceding
392 // mouseEvent, we don't need to close here.
394 QPointF p = mapToScene(e->pos());
395 TreeItem *ti=findMapItem (p, NULL);
396 LinkableMapObj* lmo=NULL;
397 if (ti) lmo=ti->getLMO(); //FIXME-2 get rid of lmo...
400 { // MapObj was found
401 if (model->getSelectedLMO() != lmo)
407 if (model->getSelectedBranchObj() )
409 // Context Menu on branch or mapcenter
410 //FIXME-3 model->updateActions(); needed?
411 branchContextMenu->popup(e->globalPos() );
414 if (model->getSelectedFloatImage() )
416 // Context Menu on floatimage
417 // model->updateActions(); FIXME-3 needed?
418 floatimageContextMenu->popup(e->globalPos() );
422 { // No MapObj found, we are on the Canvas itself
423 // Context Menu on scene
424 // model->updateActions(); FIXME-3 needed?
426 // Open context menu synchronously to position new mapcenter
427 model->setContextPos (p);
428 canvasContextMenu->exec(e->globalPos() );
429 model->unsetContextPos ();
434 void MapEditor::keyPressEvent(QKeyEvent* e)
436 if (e->modifiers() & Qt::ControlModifier)
438 switch (mainWindow->getModMode())
440 case Main::ModModeColor:
441 setCursor (PickColorCursor);
443 case Main::ModModeCopy:
444 setCursor (CopyCursor);
446 case Main::ModModeXLink:
447 setCursor (XLinkCursor);
450 setCursor (Qt::ArrowCursor);
456 void MapEditor::keyReleaseEvent(QKeyEvent* e)
458 if (!(e->modifiers() & Qt::ControlModifier))
459 setCursor (Qt::ArrowCursor);
462 void MapEditor::mousePressEvent(QMouseEvent* e)
464 // Ignore right clicks, these will go to context menus
465 if (e->button() == Qt::RightButton )
471 //Ignore clicks while editing heading
472 if (model->isSelectionBlocked() )
478 QPointF p = mapToScene(e->pos());
479 TreeItem *ti=findMapItem (p, NULL);
480 LinkableMapObj* lmo=NULL;
481 if (ti) lmo=ti->getLMO(); //FIXME-2 get rid of lmo...
485 //Take care of system flags _or_ modifier modes
487 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
488 typeid(*lmo)==typeid(MapCenterObj) ))
490 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
491 if (!foname.isEmpty())
493 // systemFlag clicked
494 model->select (lmo); // FIXME-3 was selectInt
497 if (e->state() & Qt::ControlModifier)
498 mainWindow->editOpenURLTab();
500 mainWindow->editOpenURL();
502 else if (foname=="vymLink")
504 mainWindow->editOpenVymLink();
505 // tabWidget may change, better return now
506 // before segfaulting...
507 } else if (foname=="note")
508 mainWindow->windowToggleNoteEditor();
509 else if (foname=="hideInExport")
510 model->toggleHideExport();
511 // FIXME-3 needed? xelection.update();
515 // No system flag clicked, take care of modmodes (CTRL-Click)
516 if (e->state() & Qt::ControlModifier)
518 if (mainWindow->getModMode()==Main::ModModeColor)
521 setCursor (PickColorCursor);
524 if (mainWindow->getModMode()==Main::ModModeXLink)
526 BranchObj *bo_begin=NULL;
528 bo_begin=(BranchObj*)(lmo);
530 bo_begin=model->getSelectedBranchObj();
534 linkingObj_src=bo_begin;
535 tmpXLink=new XLinkObj (mapScene);
536 tmpXLink->setBegin (bo_begin);
537 tmpXLink->setEnd (p);
538 tmpXLink->setColor(model->getMapDefXLinkColor());
539 tmpXLink->setWidth(model->getMapDefXLinkWidth());
540 tmpXLink->updateXLink();
541 tmpXLink->setVisibility (true);
550 cout << "ME::mouse pressed\n";
551 cout << " lmo="<<lmo<<endl;
552 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
554 // Select the clicked object
556 // FIXME-2 VM better let "find" return an index instead of lmo...
557 // Get index of clicked LMO
558 TreeItem *ti=lmo->getTreeItem();
560 cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
561 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
563 //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
566 // Left Button Move Branches
567 if (e->button() == Qt::LeftButton )
569 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
570 //movingObj_start.setY( p.y() - selection->y() );
571 movingObj_start.setX( p.x() - lmo->x() );
572 movingObj_start.setY( p.y() - lmo->y() );
573 movingObj_orgPos.setX (lmo->x() );
574 movingObj_orgPos.setY (lmo->y() );
576 movingObj_orgRelPos=lmo->getRelPos();
578 // If modMode==copy, then we want to "move" the _new_ object around
579 // then we need the offset from p to the _old_ selection, because of tmp
580 if (mainWindow->getModMode()==Main::ModModeCopy &&
581 e->state() & Qt::ControlModifier)
583 BranchItem *bi=model->getSelectedBranchItem();
587 //FIXME-2 TreeItem::addBranch (BranchItem still missing)
588 //bi->addBranch (model->getSelectedBranchItem());
590 model->select(bi->getLastBranch());
595 movingObj=model->getSelectedLMO();
597 // Middle Button Toggle Scroll
598 // (On Mac OS X this won't work, but we still have
599 // a button in the toolbar)
600 if (e->button() == Qt::MidButton )
601 model->toggleScroll();
602 // model->updateActions(); FIXME-3 needed?
603 // FIXME-3 needed? xelection.update();
605 { // No MapObj found, we are on the scene itself
606 // Left Button move Pos of sceneView
607 if (e->button() == Qt::LeftButton )
609 movingObj=NULL; // move Content not Obj
610 movingObj_start=e->globalPos();
611 movingCont_start=QPointF (
612 horizontalScrollBar()->value(),
613 verticalScrollBar()->value());
614 movingVec=QPointF(0,0);
615 setCursor(HandOpenCursor);
620 void MapEditor::mouseMoveEvent(QMouseEvent* e)
622 QPointF p = mapToScene(e->pos());
623 TreeItem *seli=model->getSelectedItem();
624 LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel
626 lmosel=seli->getLMO();
628 // Move the selected MapObj
629 if ( lmosel && movingObj)
631 // reset cursor if we are moving and don't copy
632 if (mainWindow->getModMode()!=Main::ModModeCopy)
633 setCursor (Qt::ArrowCursor);
635 // To avoid jumping of the sceneView, only
636 // show selection, if not tmp linked
637 if (!lmosel->hasParObjTmp())
638 model->emitShowSelection();
640 // Now move the selection, but add relative position
641 // (movingObj_start) where selection was chosen with
642 // mousepointer. (This avoids flickering resp. jumping
643 // of selection back to absPos)
645 // Check if we could link
646 TreeItem *dsti=findMapItem (p, seli);
647 LinkableMapObj* dst=NULL;
648 if (dsti) dst=dsti->getLMO(); //FIXME-2 get rid of lmo...
651 FloatObj *fio=model->getSelectedFloatImage();
654 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
656 fio->updateLink(); //no need for reposition, if we update link here
657 model->updateSelection(); // position has changed
659 // Relink float to new mapcenter or branch, if shift is pressed
660 // Only relink, if selection really has a new parent
661 if ( (e->modifiers()==Qt::ShiftModifier) && dst &&
662 ( (typeid(*dst)==typeid(BranchObj)) ||
663 (typeid(*dst)==typeid(MapCenterObj)) ) &&
664 ( dst != fio->getParObj())
667 if (typeid(*fio) == typeid(FloatImageObj) &&
668 ( (typeid(*dst)==typeid(BranchObj) ||
669 typeid(*dst)==typeid(MapCenterObj)) ))
672 // Also save the move which was done so far
673 QString pold=qpointfToString(movingObj_orgRelPos);
674 QString pnow=qpointfToString(fio->getRelPos());
676 fio->getTreeItem(), // FIXME-3
680 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
681 fio->getParObj()->requestReposition();
684 model->linkFloatImageTo (model->getSelectString(dst));
686 //movingObj_orgRelPos=lmosel->getRelPos();
692 { // selection != a FloatObj
693 if (seli->depth()==0) //FIXME-1 also moved mapcenters could be linked, but not working here...
696 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
697 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
699 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
700 model->updateRelPositions();
703 if (seli->depth()==1)
706 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
710 // Move ordinary branch
711 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
712 // Add width of bbox here, otherwise alignRelTo will cause jumping around
713 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
714 p.y()-movingObj_start.y() +lmosel->getTopPad() );
716 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
720 // Maybe we can relink temporary?
721 if (dsti && (dst!=lmosel) && seli->isBranchLikeType() && dsti->isBranchLikeType() )
723 if (e->modifiers()==Qt::ControlModifier)
725 // Special case: CTRL to link below dst
726 lmosel->setParObjTmp (dst,p,+1);
728 else if (e->modifiers()==Qt::ShiftModifier)
729 lmosel->setParObjTmp (dst,p,-1);
731 lmosel->setParObjTmp (dst,p,0);
734 lmosel->unsetParObjTmp();
736 // reposition subbranch
737 lmosel->reposition();
740 QItemSelection sel=model->getSelectionModel()->selection();
741 updateSelection(sel,sel); // position has changed
743 } // no FloatImageObj
747 } // selection && moving_obj
749 // Draw a link from one branch to another
752 tmpXLink->setEnd (p);
753 tmpXLink->updateXLink();
757 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
759 QPointF p=e->globalPos();
760 movingVec.setX(-p.x() + movingObj_start.x() );
761 movingVec.setY(-p.y() + movingObj_start.y() );
762 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
763 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
768 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
770 QPointF p = mapToScene(e->pos());
771 TreeItem *seli=model->getSelectedItem();
773 TreeItem *dsti=findMapItem(p, seli);
774 LinkableMapObj* dst=NULL;
775 if (dsti) dst=dsti->getLMO(); //FIXME-2 get rid of dst...
778 // Have we been picking color?
782 setCursor (Qt::ArrowCursor);
783 // Check if we are over another branch
786 if (e->state() & Qt::ShiftModifier)
787 model->colorBranch (((BranchObj*)dst)->getColor());
789 model->colorSubtree (((BranchObj*)dst)->getColor());
794 // Have we been drawing a link?
798 // Check if we are over another branch
799 if (dsti && seli && dsti->isBranchLikeType() )
801 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
802 tmpXLink->updateXLink();
803 tmpXLink->activate(); //FIXME-2 savestate missing
804 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
813 // Have we been moving something?
814 if ( seli && movingObj )
821 FloatImageObj *fo=model->getSelectedFloatImage();
824 // Moved FloatObj. Maybe we need to reposition
825 QString pold=qpointfToString(movingObj_orgRelPos);
826 QString pnow=qpointfToString(fo->getRelPos());
828 fo->getTreeItem(), // FIXME-3
830 fo->getTreeItem(), // FIXME-3
832 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
834 fo->getParObj()->requestReposition();
838 // Check if we are over another branch, but ignore
839 // any found LMOs, which are FloatObjs
841 if (dsti && (!dsti->isBranchLikeType() ))
847 BranchItem *bi=model->getSelectedBranchItem();
848 if (bi && bi->depth()==0)
850 if (movingObj_orgPos != bi->getBranchObj()->getAbsPos()) // FIXME-3 check getBO here...
852 QString pold=qpointfToString(movingObj_orgPos);
853 QString pnow=qpointfToString(bi->getBranchObj()->getAbsPos()); // FIXME-3 check getBO here...
860 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
864 if (seli->getType() == TreeItem::Branch )
865 { // A branch was moved
866 LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel
867 lmosel=seli->getLMO();
869 // save the position in case we link to mapcenter
870 QPointF savePos=QPointF (lmosel->getAbsPos() );
872 // Reset the temporary drawn link to the original one
873 lmosel->unsetParObjTmp();
875 // For Redo we may need to save original selection
876 QString preSelStr=model->getSelectString(lmosel);
879 if (dsti && dsti->isBranchLikeType() )
881 // We have a destination, relink to that
883 BranchObj* bsel=model->getSelectedBranchObj();
885 QString preParStr=model->getSelectString (bsel->getParObj());
886 QString preNum=QString::number (seli->num(),10);
887 QString preDstParStr;
889 if (e->state() & Qt::ShiftModifier && dst->getParObj())
891 preDstParStr=model->getSelectString (dst->getParObj());
892 model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
894 if (e->state() & Qt::ControlModifier && dst->getParObj())
897 preDstParStr=model->getSelectString (dst->getParObj());
898 model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)seli)->num()+1);
901 preDstParStr=model->getSelectString(dst);
902 model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
903 if (dsti->depth()==0) bsel->move (savePos);
905 QString postSelStr=model->getSelectString(lmosel);
906 QString postNum=QString::number (seli->num(),10);
908 QString undoCom="linkTo (\""+
909 preParStr+ "\"," + preNum +"," +
910 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
912 QString redoCom="linkTo (\""+
913 preDstParStr + "\"," + postNum + "," +
914 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
919 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
921 model->reposition(); // not necessary if we undo temporary move below
924 // No destination, undo temporary move
926 if (seli->depth()==1)
928 // The select string might be different _after_ moving around.
929 // Therefor reposition and then use string of old selection, too
932 QPointF rp(lmosel->getRelPos());
933 if (rp != movingObj_orgRelPos)
935 QString ps=qpointfToString(rp);
937 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
938 preSelStr, "moveRel "+ps,
939 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
943 // Draw the original link, before selection was moved around
944 if (settings.value("/animation/use",false).toBool() && seli->depth()>1)
946 lmosel->setRelPos(); // calc relPos first for starting point
947 QPointF dst=bi->getBranchObj()->getParObj()->getChildPos(); // FIXME-3 check getBO here...
948 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
950 model->startAnimation(
954 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
960 model->updateSelection(); //FIXME-3 needed? at least not after pos of selection has changed...
961 // Finally resize scene, if needed
965 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
966 // model->updateActions(); FIXME-3 neeeded?
968 // maybe we moved View: set old cursor
969 setCursor (Qt::ArrowCursor);
973 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
975 if (model->isSelectionBlocked() )
981 if (e->button() == Qt::LeftButton )
983 QPointF p = mapToScene(e->pos());
984 TreeItem *ti=findMapItem (p, NULL);
985 if (ti) { // MapObj was found
986 // First select the MapObj than edit heading
993 void MapEditor::resizeEvent (QResizeEvent* e)
995 QGraphicsView::resizeEvent( e );
998 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
1000 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
1001 // cerr << event->format(i) << endl;
1003 if (event->mimeData()->hasImage())
1004 event->acceptProposedAction();
1006 if (event->mimeData()->hasUrls())
1007 event->acceptProposedAction();
1010 void MapEditor::dragMoveEvent(QDragMoveEvent *)
1014 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
1019 void MapEditor::dropEvent(QDropEvent *event)
1021 BranchItem *selbi=model->getSelectedBranchItem();
1025 foreach (QString format,event->mimeData()->formats())
1026 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1030 if (event->mimeData()->hasImage())
1032 QVariant imageData = event->mimeData()->imageData();
1033 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1035 if (event->mimeData()->hasUrls())
1036 uris=event->mimeData()->urls();
1044 for (int i=0; i<uris.count();i++)
1046 // Workaround to avoid adding empty branches
1047 if (!uris.at(i).toString().isEmpty())
1049 bi=model->createBranch();
1053 s=uris.at(i).toLocalFile();
1056 QString file = QDir::fromNativeSeparators(s);
1057 heading = QFileInfo(file).baseName();
1059 if (file.endsWith(".vym", false))
1060 bi->setVymLink(file);
1062 bi->setURL(uris.at(i).toString());
1065 bo->setURL(uris.at(i).toString());
1069 if (!heading.isEmpty())
1070 bi->setHeading(heading);
1072 bi->setHeading(uris.at(i).toString());
1077 model->reposition();
1080 event->acceptProposedAction();
1083 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1085 // Reduce rectangles
1086 while (newsel.indexes().count() < selboxList.count() )
1087 delete selboxList.takeFirst();
1089 // Add additonal rectangles
1090 QGraphicsRectItem *sb;
1091 while (newsel.indexes().count() > selboxList.count() )
1093 sb = mapScene->addRect(
1095 QPen(selectionColor),
1097 sb->setZValue(Z_SELBOX);
1099 selboxList.append (sb);
1102 // Reposition rectangles
1108 LinkableMapObj *lmo;
1109 foreach (sb,selboxList)
1111 index=newsel.indexes().at(i);
1112 ti= static_cast<TreeItem*>(index.internalPointer());
1114 bbox=lmo->getBBox();
1117 bbox.width(), bbox.height());
1118 sb->setPen (selectionColor);
1119 sb->setBrush (selectionColor);
1124 void MapEditor::updateData (const QModelIndex &sel)
1126 TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
1129 cout << "ME::updateData\n";
1131 cout << " ti="<<ti<<endl;
1132 cout << " h="<<ti->getHeading().toStdString()<<endl;
1135 if (ti->isBranchLikeType())
1137 BranchObj *bo=(BranchObj*)ti->getLMO();
1138 bo->updateHeading();
1143 void MapEditor::setSelectionColor (QColor col)
1146 QItemSelection sel=model->getSelectionModel()->selection();
1147 updateSelection(sel,sel);
1151 QColor MapEditor::getSelectionColor ()
1153 return selectionColor;