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 selModel=vm->getSelectionModel();
94 selectionColor =QColor (255,255,0);
97 // Attributes //FIXME 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\n";
133 // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes
135 //removeDir(QDir(tmpMapDir)); // FIXME check?!?
136 model->unregisterEditor(this);
139 VymModel* MapEditor::getModel()
144 QGraphicsScene * MapEditor::getScene()
149 void MapEditor::print()
153 printer = new QPrinter;
154 printer->setColorMode (QPrinter::Color);
155 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
156 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
157 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
160 QRectF totalBBox=model->getTotalBBox();
162 // Try to set orientation automagically
163 // Note: Interpretation of generated postscript is amibiguous, if
164 // there are problems with landscape mode, see
165 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
167 if (totalBBox.width()>totalBBox.height())
168 // recommend landscape
169 printer->setOrientation (QPrinter::Landscape);
171 // recommend portrait
172 printer->setOrientation (QPrinter::Portrait);
174 if ( printer->setup(this) )
175 // returns false, if printing is canceled
177 QPainter pp(printer);
179 pp.setRenderHint(QPainter::Antialiasing,true);
181 // Don't print the visualisation of selection
184 QRectF mapRect=totalBBox;
185 QGraphicsRectItem *frame=NULL;
189 // Print frame around map
190 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
191 totalBBox.width()+20, totalBBox.height()+20);
192 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
198 double paperAspect = (double)printer->width() / (double)printer->height();
199 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
201 if (mapAspect>=paperAspect)
203 // Fit horizontally to paper width
204 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
205 viewBottom=(int)(printer->width()/mapAspect);
208 // Fit vertically to paper height
209 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
210 viewBottom=printer->height();
215 // Print footer below map
217 font.setPointSize(10);
219 QRectF footerBox(0,viewBottom,printer->width(),15);
220 // FIXME fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
221 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
225 QRectF (0,0,printer->width(),printer->height()-15),
226 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
229 // Viewport has paper dimension
230 if (frame) delete (frame);
235 // Save settings in vymrc
236 settings.writeEntry("/mainwindow/printerName",printer->printerName());
237 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
238 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
242 void MapEditor::setAntiAlias (bool b)
244 setRenderHint(QPainter::Antialiasing,b);
247 void MapEditor::setSmoothPixmap(bool b)
249 setRenderHint(QPainter::SmoothPixmapTransform,b);
252 void MapEditor::toggleStandardFlag(QString f)
254 BranchObj *bo=model->getSelectedBranch();
258 if (bo->isSetStandardFlag(f))
270 QString("%1 (\"%2\")").arg(u).arg(f),
272 QString("%1 (\"%2\")").arg(r).arg(f),
273 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(model->getObjectName(bo)));
274 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
275 model->updateSelection();
279 AttributeTable* MapEditor::attributeTable()
284 void MapEditor::testFunction1()
286 //BranchObj *bo=model->getSelectedBranch();
287 //if (bo) model->moveAway (bo);
288 //if (bo) bo->setLinkStyle (LinkableMapObj::Line);
291 // Displacement and animation of all non-mainbranches
298 if (bo->getDepth() >0 && !bo->hasScrolledParent(bo) )
300 p=QPointF (qrand() %600-300, qrand () %600-300);
303 model->startAnimation (bo,p, q);
310 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
311 if (hidemode==HideNone)
313 setHideTmpMode (HideExport);
314 mapCenter->calcBBoxSizeWithChilds();
315 QRectF totalBBox=mapCenter->getTotalBBox();
316 QRectF mapRect=totalBBox;
317 QCanvasRectangle *frame=NULL;
319 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
321 mapRect.setRect (totalBBox.x(), totalBBox.y(),
322 totalBBox.width(), totalBBox.height());
323 frame=new QCanvasRectangle (mapRect,mapScene);
324 frame->setBrush (QColor(white));
325 frame->setPen (QColor(black));
331 setHideTmpMode (HideNone);
333 cout <<" hidemode="<<hidemode<<endl;
337 void MapEditor::testFunction2()
342 if (hidemode==HideExport)
343 setHideTmpMode (HideNone);
345 setHideTmpMode (HideExport);
349 void MapEditor::editHeading()
353 editHeadingFinished();
356 BranchObj *bo=model->getSelectedBranch();
359 model->setSelectionBlocked(true);
361 lineEdit->setText (bo->getHeading());
362 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
363 lineEdit->setGeometry(p.x(),p.y(),230,25);
364 lineEdit->selectAll();
366 lineEdit->setFocus();
367 lineEdit->grabKeyboard();
372 void MapEditor::editHeadingFinished()
374 editingHeading=false;
375 lineEdit->releaseKeyboard();
376 model->setHeading (lineEdit->text() );
377 model->setSelectionBlocked(false);
380 // Maybe reselect previous branch
381 mainWindow->editHeadingFinished (model);
385 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
387 // Lineedits are already closed by preceding
388 // mouseEvent, we don't need to close here.
390 QPointF p = mapToScene(e->pos());
391 LinkableMapObj* lmo=model->findMapObj(p, NULL);
394 { // MapObj was found
395 if (model->getSelection() != lmo)
401 if (model->getSelectedBranch() )
403 // Context Menu on branch or mapcenter
404 model->updateActions();
405 branchContextMenu->popup(e->globalPos() );
408 if (model->getSelectedFloatImage() )
410 // Context Menu on floatimage
411 model->updateActions();
412 floatimageContextMenu->popup(e->globalPos() );
416 { // No MapObj found, we are on the Canvas itself
417 // Context Menu on scene
418 model->updateActions();
420 // Open context menu synchronously to position new mapcenter
421 model->setContextPos (p);
422 canvasContextMenu->exec(e->globalPos() );
423 model->unsetContextPos ();
428 void MapEditor::keyPressEvent(QKeyEvent* e)
430 if (e->modifiers() & Qt::ControlModifier)
432 switch (mainWindow->getModMode())
434 case Main::ModModeColor:
435 setCursor (PickColorCursor);
437 case Main::ModModeCopy:
438 setCursor (CopyCursor);
440 case Main::ModModeXLink:
441 setCursor (XLinkCursor);
444 setCursor (Qt::ArrowCursor);
450 void MapEditor::keyReleaseEvent(QKeyEvent* e)
452 if (!(e->modifiers() & Qt::ControlModifier))
453 setCursor (Qt::ArrowCursor);
456 void MapEditor::mousePressEvent(QMouseEvent* e)
458 // Ignore right clicks, these will go to context menus
459 if (e->button() == Qt::RightButton )
465 //Ignore clicks while editing heading
466 if (model->isSelectionBlocked() )
472 QPointF p = mapToScene(e->pos());
473 LinkableMapObj* lmo=model->findMapObj(p, NULL);
477 //Take care of system flags _or_ modifier modes
479 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
480 typeid(*lmo)==typeid(MapCenterObj) ))
482 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
483 if (!foname.isEmpty())
485 // systemFlag clicked
486 model->selectInt (lmo);
489 if (e->state() & Qt::ControlModifier)
490 mainWindow->editOpenURLTab();
492 mainWindow->editOpenURL();
494 else if (foname=="vymLink")
496 mainWindow->editOpenVymLink();
497 // tabWidget may change, better return now
498 // before segfaulting...
499 } else if (foname=="note")
500 mainWindow->windowToggleNoteEditor();
501 else if (foname=="hideInExport")
502 model->toggleHideExport();
503 // FIXME needed? xelection.update();
507 // No system flag clicked, take care of modmodes (CTRL-Click)
508 if (e->state() & Qt::ControlModifier)
510 if (mainWindow->getModMode()==Main::ModModeColor)
513 setCursor (PickColorCursor);
516 if (mainWindow->getModMode()==Main::ModModeXLink)
518 BranchObj *bo_begin=NULL;
520 bo_begin=(BranchObj*)(lmo);
522 bo_begin=model->getSelectedBranch();
526 linkingObj_src=bo_begin;
527 tmpXLink=new XLinkObj (mapScene);
528 tmpXLink->setBegin (bo_begin);
529 tmpXLink->setEnd (p);
530 tmpXLink->setColor(model->getMapDefXLinkColor());
531 tmpXLink->setWidth(model->getMapDefXLinkWidth());
532 tmpXLink->updateXLink();
533 tmpXLink->setVisibility (true);
541 // Select the clicked object
542 model->selectInt (lmo);
544 // Left Button Move Branches
545 if (e->button() == Qt::LeftButton )
547 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
548 //movingObj_start.setY( p.y() - selection->y() );
549 movingObj_start.setX( p.x() - lmo->x() );
550 movingObj_start.setY( p.y() - lmo->y() );
551 movingObj_orgPos.setX (lmo->x() );
552 movingObj_orgPos.setY (lmo->y() );
554 movingObj_orgRelPos=lmo->getRelPos();
556 // If modMode==copy, then we want to "move" the _new_ object around
557 // then we need the offset from p to the _old_ selection, because of tmp
558 if (mainWindow->getModMode()==Main::ModModeCopy &&
559 e->state() & Qt::ControlModifier)
561 BranchObj *bo=model->getSelectedBranch();
565 bo->addBranch ((BranchObj*)model->getSelection());
567 model->select(bo->getLastBranch());
572 movingObj=model->getSelection();
574 // Middle Button Toggle Scroll
575 // (On Mac OS X this won't work, but we still have
576 // a button in the toolbar)
577 if (e->button() == Qt::MidButton )
578 model->toggleScroll();
579 model->updateActions();
580 // FIXME needed? xelection.update();
582 { // No MapObj found, we are on the scene itself
583 // Left Button move Pos of sceneView
584 if (e->button() == Qt::LeftButton )
586 movingObj=NULL; // move Content not Obj
587 movingObj_start=e->globalPos();
588 movingCont_start=QPointF (
589 horizontalScrollBar()->value(),
590 verticalScrollBar()->value());
591 movingVec=QPointF(0,0);
592 setCursor(HandOpenCursor);
597 void MapEditor::mouseMoveEvent(QMouseEvent* e)
599 QPointF p = mapToScene(e->pos());
600 LinkableMapObj *lmosel=model->getSelection();
602 // Move the selected MapObj
603 if ( lmosel && movingObj)
605 // reset cursor if we are moving and don't copy
606 if (mainWindow->getModMode()!=Main::ModModeCopy)
607 setCursor (Qt::ArrowCursor);
609 // To avoid jumping of the sceneView, only
610 // ensureSelectionVisible, if not tmp linked
611 if (!lmosel->hasParObjTmp())
612 model->ensureSelectionVisible ();
614 // Now move the selection, but add relative position
615 // (movingObj_start) where selection was chosen with
616 // mousepointer. (This avoids flickering resp. jumping
617 // of selection back to absPos)
619 // Check if we could link
620 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
623 FloatObj *fio=model->getSelectedFloatImage();
626 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
628 fio->updateLink(); //no need for reposition, if we update link here
629 model->updateSelection();
631 // Relink float to new mapcenter or branch, if shift is pressed
632 // Only relink, if selection really has a new parent
633 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
634 ( (typeid(*lmo)==typeid(BranchObj)) ||
635 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
636 ( lmo != fio->getParObj())
639 if (typeid(*fio) == typeid(FloatImageObj) &&
640 ( (typeid(*lmo)==typeid(BranchObj) ||
641 typeid(*lmo)==typeid(MapCenterObj)) ))
644 // Also save the move which was done so far
645 QString pold=qpointfToString(movingObj_orgRelPos);
646 QString pnow=qpointfToString(fio->getRelPos());
652 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
653 fio->getParObj()->requestReposition();
656 model->linkFloatImageTo (model->getSelectString(lmo));
658 //movingObj_orgRelPos=lmosel->getRelPos();
664 { // selection != a FloatObj
665 if (lmosel->getDepth()==0)
668 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
669 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
671 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
672 model->updateRelPositions();
675 if (lmosel->getDepth()==1)
678 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
682 // Move ordinary branch
683 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
684 // Add width of bbox here, otherwise alignRelTo will cause jumping around
685 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
686 p.y()-movingObj_start.y() +lmosel->getTopPad() );
688 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
692 // Maybe we can relink temporary?
693 if (lmo && (lmo!=lmosel) && model->getSelectedBranch() &&
694 (typeid(*lmo)==typeid(BranchObj) ||
695 typeid(*lmo)==typeid(MapCenterObj)) )
698 if (e->modifiers()==Qt::ControlModifier)
700 // Special case: CTRL to link below lmo
701 lmosel->setParObjTmp (lmo,p,+1);
703 else if (e->modifiers()==Qt::ShiftModifier)
704 lmosel->setParObjTmp (lmo,p,-1);
706 lmosel->setParObjTmp (lmo,p,0);
709 lmosel->unsetParObjTmp();
711 // reposition subbranch
712 lmosel->reposition();
715 model->updateSelection();// FIXME needed?
716 } // no FloatImageObj
720 } // selection && moving_obj
722 // Draw a link from one branch to another
725 tmpXLink->setEnd (p);
726 tmpXLink->updateXLink();
730 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
732 QPointF p=e->globalPos();
733 movingVec.setX(-p.x() + movingObj_start.x() );
734 movingVec.setY(-p.y() + movingObj_start.y() );
735 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
736 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
741 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
743 QPointF p = mapToScene(e->pos());
745 LinkableMapObj *lmosel=model->getSelection();
746 // Have we been picking color?
750 setCursor (Qt::ArrowCursor);
751 // Check if we are over another branch
752 dst=model->findMapObj(p, NULL);
755 if (e->state() & Qt::ShiftModifier)
756 model->colorBranch (((BranchObj*)dst)->getColor());
758 model->colorSubtree (((BranchObj*)dst)->getColor());
763 // Have we been drawing a link?
767 // Check if we are over another branch
768 dst=model->findMapObj(p, NULL);
771 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
772 tmpXLink->updateXLink();
773 tmpXLink->activate(); //FIXME savestate missing
774 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
783 // Have we been moving something?
784 if ( lmosel && movingObj )
786 FloatImageObj *fo=model->getSelectedFloatImage();
789 // Moved FloatObj. Maybe we need to reposition
790 QString pold=qpointfToString(movingObj_orgRelPos);
791 QString pnow=qpointfToString(fo->getRelPos());
797 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
799 fo->getParObj()->requestReposition();
803 // Check if we are over another branch, but ignore
804 // any found LMOs, which are FloatObjs
805 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
807 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
810 BranchObj *bo=model->getSelectedBranch();
811 if (bo && bo->getDepth()==0)
813 if (movingObj_orgPos != bo->getAbsPos())
815 QString pold=qpointfToString(movingObj_orgPos);
816 QString pnow=qpointfToString(bo->getAbsPos());
822 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bo)).arg(pnow));
826 if (model->selectionType() == Selection::Branch )
827 { // A branch was moved
829 // save the position in case we link to mapcenter
830 QPointF savePos=QPointF (lmosel->getAbsPos() );
832 // Reset the temporary drawn link to the original one
833 lmosel->unsetParObjTmp();
835 // For Redo we may need to save original selection
836 QString preSelStr=model->getSelectString(lmosel);
841 // We have a destination, relink to that
843 BranchObj* bsel=model->getSelectedBranch();
844 BranchObj* bdst=(BranchObj*)dst;
846 QString preParStr=model->getSelectString (bsel->getParObj());
847 QString preNum=QString::number (bsel->getNum(),10);
848 QString preDstParStr;
850 if (e->state() & Qt::ShiftModifier && dst->getParObj())
852 preDstParStr=model->getSelectString (dst->getParObj());
853 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
855 if (e->state() & Qt::ControlModifier && dst->getParObj())
858 preDstParStr=model->getSelectString (dst->getParObj());
859 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
862 preDstParStr=model->getSelectString(dst);
863 bsel->linkTo (bdst,-1);
864 if (dst->getDepth()==0) bsel->move (savePos);
866 QString postSelStr=model->getSelectString(lmosel);
867 QString postNum=QString::number (bsel->getNum(),10);
869 QString undoCom="linkTo (\""+
870 preParStr+ "\"," + preNum +"," +
871 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
873 QString redoCom="linkTo (\""+
874 preDstParStr + "\"," + postNum + "," +
875 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
880 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
882 model->reposition(); // not necessary if we undo temporary move below
885 // No destination, undo temporary move
887 if (lmosel->getDepth()==1)
889 // The select string might be different _after_ moving around.
890 // Therefor reposition and then use string of old selection, too
893 QPointF rp(lmosel->getRelPos());
894 if (rp != movingObj_orgRelPos)
896 QString ps=qpointfToString(rp);
898 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
899 preSelStr, "moveRel "+ps,
900 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
904 // Draw the original link, before selection was moved around
905 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
907 lmosel->setRelPos(); // calc relPos first for starting point
908 QPointF dst=bo->getParObj()->getChildPos();
909 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
911 model->startAnimation(
915 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
921 model->updateSelection();
922 // Finally resize scene, if needed
926 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
927 model->updateActions();
929 // maybe we moved View: set old cursor
930 setCursor (Qt::ArrowCursor);
934 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
936 if (model->isSelectionBlocked() )
942 if (e->button() == Qt::LeftButton )
944 QPointF p = mapToScene(e->pos());
945 LinkableMapObj *lmo=model->findMapObj(p, NULL);
946 if (lmo) { // MapObj was found
947 // First select the MapObj than edit heading
954 void MapEditor::resizeEvent (QResizeEvent* e)
956 QGraphicsView::resizeEvent( e );
959 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
961 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
962 // cerr << event->format(i) << endl;
964 if (event->mimeData()->hasImage())
965 event->acceptProposedAction();
967 if (event->mimeData()->hasUrls())
968 event->acceptProposedAction();
971 void MapEditor::dragMoveEvent(QDragMoveEvent *)
975 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
980 void MapEditor::dropEvent(QDropEvent *event)
982 BranchObj *sel=model->getSelectedBranch();
986 foreach (QString format,event->mimeData()->formats())
987 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
991 if (event->mimeData()->hasImage())
993 QVariant imageData = event->mimeData()->imageData();
994 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
996 if (event->mimeData()->hasUrls())
997 uris=event->mimeData()->urls();
1005 for (int i=0; i<uris.count();i++)
1007 // Workaround to avoid adding empty branches
1008 if (!uris.at(i).toString().isEmpty())
1010 bo=sel->addBranch();
1013 s=uris.at(i).toLocalFile();
1016 QString file = QDir::fromNativeSeparators(s);
1017 heading = QFileInfo(file).baseName();
1019 if (file.endsWith(".vym", false))
1020 bo->setVymLink(file);
1022 bo->setURL(uris.at(i).toString());
1025 bo->setURL(uris.at(i).toString());
1028 if (!heading.isEmpty())
1029 bo->setHeading(heading);
1031 bo->setHeading(uris.at(i).toString());
1035 model->reposition();
1038 event->acceptProposedAction();
1041 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1043 cout << "ME::updateSelection\n";
1045 QGraphicsRectItem *sb;
1047 // Check if selection is empty
1048 if (newsel.indexes().isEmpty() )
1050 if (!selboxList.isEmpty())
1051 while (!selboxList.isEmpty() )
1052 delete selboxList.takeFirst();
1056 if (selboxList.isEmpty())
1058 sb = mapScene->addRect(
1060 QPen(selectionColor),
1062 sb->setZValue(Z_SELBOX);
1064 selboxList.append (sb);
1066 sb=selboxList.first();
1068 QModelIndex index=newsel.indexes().first(); // TODO no multiselections yet
1070 TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
1071 LinkableMapObj *lmo=item->getLMO();
1073 int w=0; // FIXME what for?
1076 QRectF bbox=lmo->getBBox();
1077 selboxList.first()->setRect (
1078 bbox.x()-w,bbox.y()-w,
1079 bbox.width()+2*w, bbox.height()+2*w);
1080 selboxList.first()->setPen (selectionColor);
1081 selboxList.first()->setBrush (selectionColor);
1088 void MapEditor::updateSelectionGeometry() // FIXME VM only called from VM::animate...
1090 cout << "ME::updateSelectionGeometry\n";
1092 // Tell selection to update geometries
1093 model->updateSelection();
1097 void MapEditor::setSelectionColor (QColor col)
1100 updateSelectionGeometry();
1103 QColor MapEditor::getSelectionColor ()
1105 return selectionColor;