9 #include "mainwindow.h"
11 #include "warningdialog.h"
14 extern int statusbarTime;
15 extern Main *mainWindow;
16 extern QString tmpVymDir;
17 extern QString clipboardDir;
18 extern QString clipboardFile;
19 extern bool clipboardEmpty;
21 extern FlagRowObj *standardFlagsDefault;
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;
32 extern Settings settings;
33 extern QString iconPath;
35 ///////////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////
37 MapEditor::MapEditor( VymModel *vm)
39 //cout << "Constructor ME "<<this<<endl;
40 mapScene= new QGraphicsScene(NULL);
41 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
44 model->setScene (mapScene);
45 model->registerEditor(this);
46 // model->addMapCenter(); // FIXME create this in MapEditor until BO and MCO are independent of scene
47 model->makeDefault(); // No changes in model so far
53 // Create bitmap cursors, platform dependant
54 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
55 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
56 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
57 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
59 setFocusPolicy (Qt::StrongFocus);
71 setAcceptDrops (true);
73 //model->reposition(); //FIXME really still needed?
76 // Action to embed LineEdit for heading in Scene
78 lineEdit=new QLineEdit;
80 QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
83 QAction *a = new QAction( tr( "Edit heading","MapEditor" ), this);
84 a->setShortcut ( Qt::Key_Return ); //Edit heading
86 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
87 a = new QAction( tr( "Edit heading","MapEditor" ), this);
88 a->setShortcut ( Qt::Key_Enter); //Edit heading
90 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
93 selectionColor =QColor (255,255,0);
96 // Attributes //FIXME testing only...
99 attrTable= new AttributeTable();
101 ad=attrTable->addKey (k,StringList);
105 sl <<"val 1"<<"val 2"<< "val 3";
106 ad->setValue (QVariant (sl));
108 //attrTable->addValue ("Key A","P 1");
109 //attrTable->addValue ("Key A","P 2");
110 //attrTable->addValue ("Key A","P 3");
111 //attrTable->addValue ("Key A","P 4");
113 ad=attrTable->addKey (k,FreeString);
116 //attrTable->addValue ("Key B","w1");
117 //attrTable->addValue ("Key B","w2");
119 k="C - UniqueString";
120 ad=attrTable->addKey (k,UniqueString);
123 //attrTable->addKey ("Key Prio");
124 //attrTable->addValue ("Key Prio","Prio 1");
125 //attrTable->addValue ("Key Prio","Prio 2");
129 MapEditor::~MapEditor()
131 //cout <<"Destructor MapEditor\n";
132 // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes
134 //removeDir(QDir(tmpMapDir)); // FIXME check?!?
135 model->unregisterEditor(this);
138 VymModel* MapEditor::getModel()
143 QGraphicsScene * MapEditor::getScene()
148 void MapEditor::print()
152 printer = new QPrinter;
153 printer->setColorMode (QPrinter::Color);
154 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
155 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
156 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
159 QRectF totalBBox=model->getTotalBBox();
161 // Try to set orientation automagically
162 // Note: Interpretation of generated postscript is amibiguous, if
163 // there are problems with landscape mode, see
164 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
166 if (totalBBox.width()>totalBBox.height())
167 // recommend landscape
168 printer->setOrientation (QPrinter::Landscape);
170 // recommend portrait
171 printer->setOrientation (QPrinter::Portrait);
173 if ( printer->setup(this) )
174 // returns false, if printing is canceled
176 QPainter pp(printer);
178 pp.setRenderHint(QPainter::Antialiasing,true);
180 // Don't print the visualisation of selection
183 QRectF mapRect=totalBBox;
184 QGraphicsRectItem *frame=NULL;
188 // Print frame around map
189 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
190 totalBBox.width()+20, totalBBox.height()+20);
191 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
197 double paperAspect = (double)printer->width() / (double)printer->height();
198 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
200 if (mapAspect>=paperAspect)
202 // Fit horizontally to paper width
203 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
204 viewBottom=(int)(printer->width()/mapAspect);
207 // Fit vertically to paper height
208 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
209 viewBottom=printer->height();
214 // Print footer below map
216 font.setPointSize(10);
218 QRectF footerBox(0,viewBottom,printer->width(),15);
219 // FIXME fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
220 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
224 QRectF (0,0,printer->width(),printer->height()-15),
225 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
228 // Viewport has paper dimension
229 if (frame) delete (frame);
234 // Save settings in vymrc
235 settings.writeEntry("/mainwindow/printerName",printer->printerName());
236 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
237 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
241 void MapEditor::setAntiAlias (bool b)
243 setRenderHint(QPainter::Antialiasing,b);
246 void MapEditor::setSmoothPixmap(bool b)
248 setRenderHint(QPainter::SmoothPixmapTransform,b);
251 void MapEditor::toggleStandardFlag(QString f)
253 BranchObj *bo=model->getSelectedBranch();
257 if (bo->isSetStandardFlag(f))
269 QString("%1 (\"%2\")").arg(u).arg(f),
271 QString("%1 (\"%2\")").arg(r).arg(f),
272 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(model->getObjectName(bo)));
273 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
274 model->updateSelection(); // geometry has changed
278 AttributeTable* MapEditor::attributeTable()
283 void MapEditor::testFunction1()
288 cout << "ME::testFunction1 starting to walk the map...\n";
289 while (model->next (cur,prev,d) )
290 cout << "*** " <<cur->getHeading().toStdString()<<endl;
293 //BranchObj *bo=model->getSelectedBranch();
294 //if (bo) model->moveAway (bo);
295 //if (bo) bo->setLinkStyle (LinkableMapObj::Line);
299 // Displacement and animation of all non-mainbranches
308 bo=(BranchObj*)(cur->getLMO());
310 if (cur->depth() >0 && !bo->hasScrolledParent(bo) )
312 p=QPointF (qrand() %600-300, qrand () %600-300);
315 model->startAnimation (bo,p, q);
317 model->next(cur,prev,d);
322 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
323 if (hidemode==HideNone)
325 setHideTmpMode (HideExport);
326 mapCenter->calcBBoxSizeWithChilds();
327 QRectF totalBBox=mapCenter->getTotalBBox();
328 QRectF mapRect=totalBBox;
329 QCanvasRectangle *frame=NULL;
331 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
333 mapRect.setRect (totalBBox.x(), totalBBox.y(),
334 totalBBox.width(), totalBBox.height());
335 frame=new QCanvasRectangle (mapRect,mapScene);
336 frame->setBrush (QColor(white));
337 frame->setPen (QColor(black));
343 setHideTmpMode (HideNone);
345 cout <<" hidemode="<<hidemode<<endl;
349 void MapEditor::testFunction2()
354 if (hidemode==HideExport)
355 setHideTmpMode (HideNone);
357 setHideTmpMode (HideExport);
361 void MapEditor::editHeading()
365 editHeadingFinished();
368 BranchObj *bo=model->getSelectedBranch();
371 model->setSelectionBlocked(true);
373 lineEdit->setText (bo->getHeading());
374 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
375 lineEdit->setGeometry(p.x(),p.y(),230,25);
376 lineEdit->selectAll();
378 lineEdit->setFocus();
379 lineEdit->grabKeyboard();
384 void MapEditor::editHeadingFinished()
386 editingHeading=false;
387 lineEdit->releaseKeyboard();
388 model->setHeading (lineEdit->text() );
389 model->setSelectionBlocked(false);
392 // Maybe reselect previous branch
393 mainWindow->editHeadingFinished (model);
397 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
399 // Lineedits are already closed by preceding
400 // mouseEvent, we don't need to close here.
402 QPointF p = mapToScene(e->pos());
403 LinkableMapObj* lmo=model->findMapObj(p, NULL);
406 { // MapObj was found
407 if (model->getSelectedLMO() != lmo)
413 if (model->getSelectedBranch() )
415 // Context Menu on branch or mapcenter
416 model->updateActions();
417 branchContextMenu->popup(e->globalPos() );
420 if (model->getSelectedFloatImage() )
422 // Context Menu on floatimage
423 model->updateActions();
424 floatimageContextMenu->popup(e->globalPos() );
428 { // No MapObj found, we are on the Canvas itself
429 // Context Menu on scene
430 model->updateActions();
432 // Open context menu synchronously to position new mapcenter
433 model->setContextPos (p);
434 canvasContextMenu->exec(e->globalPos() );
435 model->unsetContextPos ();
440 void MapEditor::keyPressEvent(QKeyEvent* e)
442 if (e->modifiers() & Qt::ControlModifier)
444 switch (mainWindow->getModMode())
446 case Main::ModModeColor:
447 setCursor (PickColorCursor);
449 case Main::ModModeCopy:
450 setCursor (CopyCursor);
452 case Main::ModModeXLink:
453 setCursor (XLinkCursor);
456 setCursor (Qt::ArrowCursor);
462 void MapEditor::keyReleaseEvent(QKeyEvent* e)
464 if (!(e->modifiers() & Qt::ControlModifier))
465 setCursor (Qt::ArrowCursor);
468 void MapEditor::mousePressEvent(QMouseEvent* e)
470 // Ignore right clicks, these will go to context menus
471 if (e->button() == Qt::RightButton )
477 //Ignore clicks while editing heading
478 if (model->isSelectionBlocked() )
484 QPointF p = mapToScene(e->pos());
485 LinkableMapObj* lmo=model->findMapObj(p, NULL);
489 //Take care of system flags _or_ modifier modes
491 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
492 typeid(*lmo)==typeid(MapCenterObj) ))
494 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
495 if (!foname.isEmpty())
497 // systemFlag clicked
498 model->selectInt (lmo);
501 if (e->state() & Qt::ControlModifier)
502 mainWindow->editOpenURLTab();
504 mainWindow->editOpenURL();
506 else if (foname=="vymLink")
508 mainWindow->editOpenVymLink();
509 // tabWidget may change, better return now
510 // before segfaulting...
511 } else if (foname=="note")
512 mainWindow->windowToggleNoteEditor();
513 else if (foname=="hideInExport")
514 model->toggleHideExport();
515 // FIXME needed? xelection.update();
519 // No system flag clicked, take care of modmodes (CTRL-Click)
520 if (e->state() & Qt::ControlModifier)
522 if (mainWindow->getModMode()==Main::ModModeColor)
525 setCursor (PickColorCursor);
528 if (mainWindow->getModMode()==Main::ModModeXLink)
530 BranchObj *bo_begin=NULL;
532 bo_begin=(BranchObj*)(lmo);
534 bo_begin=model->getSelectedBranch();
538 linkingObj_src=bo_begin;
539 tmpXLink=new XLinkObj (mapScene);
540 tmpXLink->setBegin (bo_begin);
541 tmpXLink->setEnd (p);
542 tmpXLink->setColor(model->getMapDefXLinkColor());
543 tmpXLink->setWidth(model->getMapDefXLinkWidth());
544 tmpXLink->updateXLink();
545 tmpXLink->setVisibility (true);
554 cout << "ME::mouse pressed\n";
555 cout << " lmo="<<lmo<<endl;
556 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
558 // Select the clicked object
560 // FIXME VM better let "find" return an index instead of lmo...
561 // Get index of clicked LMO
562 TreeItem *ti=lmo->getTreeItem();
564 cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
565 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
567 //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
570 // Left Button Move Branches
571 if (e->button() == Qt::LeftButton )
573 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
574 //movingObj_start.setY( p.y() - selection->y() );
575 movingObj_start.setX( p.x() - lmo->x() );
576 movingObj_start.setY( p.y() - lmo->y() );
577 movingObj_orgPos.setX (lmo->x() );
578 movingObj_orgPos.setY (lmo->y() );
580 movingObj_orgRelPos=lmo->getRelPos();
582 // If modMode==copy, then we want to "move" the _new_ object around
583 // then we need the offset from p to the _old_ selection, because of tmp
584 if (mainWindow->getModMode()==Main::ModModeCopy &&
585 e->state() & Qt::ControlModifier)
587 BranchObj *bo=model->getSelectedBranch();
591 bo->addBranch (model->getSelectedBranch());
593 model->select(bo->getLastBranch());
598 movingObj=model->getSelectedLMO();
600 // Middle Button Toggle Scroll
601 // (On Mac OS X this won't work, but we still have
602 // a button in the toolbar)
603 if (e->button() == Qt::MidButton )
604 model->toggleScroll();
605 model->updateActions();
606 // FIXME needed? xelection.update();
608 { // No MapObj found, we are on the scene itself
609 // Left Button move Pos of sceneView
610 if (e->button() == Qt::LeftButton )
612 movingObj=NULL; // move Content not Obj
613 movingObj_start=e->globalPos();
614 movingCont_start=QPointF (
615 horizontalScrollBar()->value(),
616 verticalScrollBar()->value());
617 movingVec=QPointF(0,0);
618 setCursor(HandOpenCursor);
623 void MapEditor::mouseMoveEvent(QMouseEvent* e)
625 QPointF p = mapToScene(e->pos());
626 LinkableMapObj *lmosel=model->getSelectedLMO();
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 // ensureSelectionVisible, if not tmp linked
637 if (!lmosel->hasParObjTmp())
638 model->ensureSelectionVisible ();
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 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
649 FloatObj *fio=model->getSelectedFloatImage();
652 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
654 fio->updateLink(); //no need for reposition, if we update link here
655 model->updateSelection(); // position has changed
657 // Relink float to new mapcenter or branch, if shift is pressed
658 // Only relink, if selection really has a new parent
659 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
660 ( (typeid(*lmo)==typeid(BranchObj)) ||
661 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
662 ( lmo != fio->getParObj())
665 if (typeid(*fio) == typeid(FloatImageObj) &&
666 ( (typeid(*lmo)==typeid(BranchObj) ||
667 typeid(*lmo)==typeid(MapCenterObj)) ))
670 // Also save the move which was done so far
671 QString pold=qpointfToString(movingObj_orgRelPos);
672 QString pnow=qpointfToString(fio->getRelPos());
678 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
679 fio->getParObj()->requestReposition();
682 model->linkFloatImageTo (model->getSelectString(lmo));
684 //movingObj_orgRelPos=lmosel->getRelPos();
690 { // selection != a FloatObj
691 if (lmosel->getDepth()==0)
694 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
695 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
697 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
698 model->updateRelPositions();
701 if (lmosel->getDepth()==1)
704 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
708 // Move ordinary branch
709 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
710 // Add width of bbox here, otherwise alignRelTo will cause jumping around
711 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
712 p.y()-movingObj_start.y() +lmosel->getTopPad() );
714 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
718 // Maybe we can relink temporary?
719 if (lmo && (lmo!=lmosel) && model->getSelectedBranch() &&
720 (typeid(*lmo)==typeid(BranchObj) ||
721 typeid(*lmo)==typeid(MapCenterObj)) )
724 if (e->modifiers()==Qt::ControlModifier)
726 // Special case: CTRL to link below lmo
727 lmosel->setParObjTmp (lmo,p,+1);
729 else if (e->modifiers()==Qt::ShiftModifier)
730 lmosel->setParObjTmp (lmo,p,-1);
732 lmosel->setParObjTmp (lmo,p,0);
735 lmosel->unsetParObjTmp();
737 // reposition subbranch
738 lmosel->reposition();
741 QItemSelection sel=model->getSelectionModel()->selection();
742 updateSelection(sel,sel); // position has changed
744 } // no FloatImageObj
748 } // selection && moving_obj
750 // Draw a link from one branch to another
753 tmpXLink->setEnd (p);
754 tmpXLink->updateXLink();
758 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
760 QPointF p=e->globalPos();
761 movingVec.setX(-p.x() + movingObj_start.x() );
762 movingVec.setY(-p.y() + movingObj_start.y() );
763 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
764 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
769 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
771 QPointF p = mapToScene(e->pos());
773 LinkableMapObj *lmosel=model->getSelectedLMO();
774 // Have we been picking color?
778 setCursor (Qt::ArrowCursor);
779 // Check if we are over another branch
780 dst=model->findMapObj(p, NULL);
783 if (e->state() & Qt::ShiftModifier)
784 model->colorBranch (((BranchObj*)dst)->getColor());
786 model->colorSubtree (((BranchObj*)dst)->getColor());
791 // Have we been drawing a link?
795 // Check if we are over another branch
796 dst=model->findMapObj(p, NULL);
799 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
800 tmpXLink->updateXLink();
801 tmpXLink->activate(); //FIXME savestate missing
802 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
811 // Have we been moving something?
812 if ( lmosel && movingObj )
814 FloatImageObj *fo=model->getSelectedFloatImage();
817 // Moved FloatObj. Maybe we need to reposition
818 QString pold=qpointfToString(movingObj_orgRelPos);
819 QString pnow=qpointfToString(fo->getRelPos());
825 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
827 fo->getParObj()->requestReposition();
831 // Check if we are over another branch, but ignore
832 // any found LMOs, which are FloatObjs
833 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
835 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
838 BranchObj *bo=model->getSelectedBranch();
839 if (bo && bo->getDepth()==0)
841 if (movingObj_orgPos != bo->getAbsPos())
843 QString pold=qpointfToString(movingObj_orgPos);
844 QString pnow=qpointfToString(bo->getAbsPos());
850 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bo)).arg(pnow));
854 if (model->selectionType() == TreeItem::Branch )
855 { // A branch was moved
857 // save the position in case we link to mapcenter
858 QPointF savePos=QPointF (lmosel->getAbsPos() );
860 // Reset the temporary drawn link to the original one
861 lmosel->unsetParObjTmp();
863 // For Redo we may need to save original selection
864 QString preSelStr=model->getSelectString(lmosel);
869 // We have a destination, relink to that
871 BranchObj* bsel=model->getSelectedBranch();
872 BranchObj* bdst=(BranchObj*)dst;
874 QString preParStr=model->getSelectString (bsel->getParObj());
875 QString preNum=QString::number (bsel->getNum(),10);
876 QString preDstParStr;
878 if (e->state() & Qt::ShiftModifier && dst->getParObj())
880 preDstParStr=model->getSelectString (dst->getParObj());
881 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
883 if (e->state() & Qt::ControlModifier && dst->getParObj())
886 preDstParStr=model->getSelectString (dst->getParObj());
887 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
890 preDstParStr=model->getSelectString(dst);
891 bsel->linkTo (bdst,-1);
892 if (dst->getDepth()==0) bsel->move (savePos);
894 QString postSelStr=model->getSelectString(lmosel);
895 QString postNum=QString::number (bsel->getNum(),10);
897 QString undoCom="linkTo (\""+
898 preParStr+ "\"," + preNum +"," +
899 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
901 QString redoCom="linkTo (\""+
902 preDstParStr + "\"," + postNum + "," +
903 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
908 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
910 model->reposition(); // not necessary if we undo temporary move below
913 // No destination, undo temporary move
915 if (lmosel->getDepth()==1)
917 // The select string might be different _after_ moving around.
918 // Therefor reposition and then use string of old selection, too
921 QPointF rp(lmosel->getRelPos());
922 if (rp != movingObj_orgRelPos)
924 QString ps=qpointfToString(rp);
926 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
927 preSelStr, "moveRel "+ps,
928 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
932 // Draw the original link, before selection was moved around
933 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
935 lmosel->setRelPos(); // calc relPos first for starting point
936 QPointF dst=bo->getParObj()->getChildPos();
937 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
939 model->startAnimation(
943 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
949 model->updateSelection();
950 // Finally resize scene, if needed
954 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
955 model->updateActions();
957 // maybe we moved View: set old cursor
958 setCursor (Qt::ArrowCursor);
962 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
964 if (model->isSelectionBlocked() )
970 if (e->button() == Qt::LeftButton )
972 QPointF p = mapToScene(e->pos());
973 LinkableMapObj *lmo=model->findMapObj(p, NULL);
974 if (lmo) { // MapObj was found
975 // First select the MapObj than edit heading
982 void MapEditor::resizeEvent (QResizeEvent* e)
984 QGraphicsView::resizeEvent( e );
987 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
989 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
990 // cerr << event->format(i) << endl;
992 if (event->mimeData()->hasImage())
993 event->acceptProposedAction();
995 if (event->mimeData()->hasUrls())
996 event->acceptProposedAction();
999 void MapEditor::dragMoveEvent(QDragMoveEvent *)
1003 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
1008 void MapEditor::dropEvent(QDropEvent *event)
1010 BranchObj *sel=model->getSelectedBranch();
1014 foreach (QString format,event->mimeData()->formats())
1015 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1019 if (event->mimeData()->hasImage())
1021 QVariant imageData = event->mimeData()->imageData();
1022 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1024 if (event->mimeData()->hasUrls())
1025 uris=event->mimeData()->urls();
1033 for (int i=0; i<uris.count();i++)
1035 // Workaround to avoid adding empty branches
1036 if (!uris.at(i).toString().isEmpty())
1038 bo=sel->addBranch();
1041 s=uris.at(i).toLocalFile();
1044 QString file = QDir::fromNativeSeparators(s);
1045 heading = QFileInfo(file).baseName();
1047 if (file.endsWith(".vym", false))
1048 bo->setVymLink(file);
1050 bo->setURL(uris.at(i).toString());
1053 bo->setURL(uris.at(i).toString());
1056 if (!heading.isEmpty())
1057 bo->setHeading(heading);
1059 bo->setHeading(uris.at(i).toString());
1063 model->reposition();
1066 event->acceptProposedAction();
1069 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1071 // Reduce rectangles
1072 while (newsel.indexes().count() < selboxList.count() )
1073 delete selboxList.takeFirst();
1075 // Add additonal rectangles
1076 QGraphicsRectItem *sb;
1077 while (newsel.indexes().count() > selboxList.count() )
1079 sb = mapScene->addRect(
1081 QPen(selectionColor),
1083 sb->setZValue(Z_SELBOX);
1085 selboxList.append (sb);
1088 // Reposition rectangles
1094 LinkableMapObj *lmo;
1095 foreach (sb,selboxList)
1097 index=newsel.indexes().at(i);
1098 ti= static_cast<TreeItem*>(index.internalPointer());
1100 bbox=lmo->getBBox();
1103 bbox.width(), bbox.height());
1104 sb->setPen (selectionColor);
1105 sb->setBrush (selectionColor);
1110 void MapEditor::updateCurrent (const QModelIndex &,const QModelIndex &) //FIXME not used?
1115 cout << "ME::updateCurrent\n";
1117 TreeItem *item = static_cast<TreeItem*>(newsel.internalPointer());
1118 LinkableMapObj *lmo=item->getLMO();
1119 cout << " lmo="<<lmo<<endl;
1120 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
1125 void MapEditor::setSelectionColor (QColor col)
1128 QItemSelection sel=model->getSelectionModel()->selection();
1129 updateSelection(sel,sel);
1132 QColor MapEditor::getSelectionColor ()
1134 return selectionColor;