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()
285 //BranchObj *bo=model->getSelectedBranch();
286 //if (bo) model->moveAway (bo);
287 //if (bo) bo->setLinkStyle (LinkableMapObj::Line);
290 // Displacement and animation of all non-mainbranches
297 if (bo->getDepth() >0 && !bo->hasScrolledParent(bo) )
299 p=QPointF (qrand() %600-300, qrand () %600-300);
302 model->startAnimation (bo,p, q);
309 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
310 if (hidemode==HideNone)
312 setHideTmpMode (HideExport);
313 mapCenter->calcBBoxSizeWithChilds();
314 QRectF totalBBox=mapCenter->getTotalBBox();
315 QRectF mapRect=totalBBox;
316 QCanvasRectangle *frame=NULL;
318 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
320 mapRect.setRect (totalBBox.x(), totalBBox.y(),
321 totalBBox.width(), totalBBox.height());
322 frame=new QCanvasRectangle (mapRect,mapScene);
323 frame->setBrush (QColor(white));
324 frame->setPen (QColor(black));
330 setHideTmpMode (HideNone);
332 cout <<" hidemode="<<hidemode<<endl;
336 void MapEditor::testFunction2()
341 if (hidemode==HideExport)
342 setHideTmpMode (HideNone);
344 setHideTmpMode (HideExport);
348 void MapEditor::editHeading()
352 editHeadingFinished();
355 BranchObj *bo=model->getSelectedBranch();
358 model->setSelectionBlocked(true);
360 lineEdit->setText (bo->getHeading());
361 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
362 lineEdit->setGeometry(p.x(),p.y(),230,25);
363 lineEdit->selectAll();
365 lineEdit->setFocus();
366 lineEdit->grabKeyboard();
371 void MapEditor::editHeadingFinished()
373 editingHeading=false;
374 lineEdit->releaseKeyboard();
375 model->setHeading (lineEdit->text() );
376 model->setSelectionBlocked(false);
379 // Maybe reselect previous branch
380 mainWindow->editHeadingFinished (model);
384 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
386 // Lineedits are already closed by preceding
387 // mouseEvent, we don't need to close here.
389 QPointF p = mapToScene(e->pos());
390 LinkableMapObj* lmo=model->findMapObj(p, NULL);
393 { // MapObj was found
394 if (model->getSelectedLMO() != lmo)
400 if (model->getSelectedBranch() )
402 // Context Menu on branch or mapcenter
403 model->updateActions();
404 branchContextMenu->popup(e->globalPos() );
407 if (model->getSelectedFloatImage() )
409 // Context Menu on floatimage
410 model->updateActions();
411 floatimageContextMenu->popup(e->globalPos() );
415 { // No MapObj found, we are on the Canvas itself
416 // Context Menu on scene
417 model->updateActions();
419 // Open context menu synchronously to position new mapcenter
420 model->setContextPos (p);
421 canvasContextMenu->exec(e->globalPos() );
422 model->unsetContextPos ();
427 void MapEditor::keyPressEvent(QKeyEvent* e)
429 if (e->modifiers() & Qt::ControlModifier)
431 switch (mainWindow->getModMode())
433 case Main::ModModeColor:
434 setCursor (PickColorCursor);
436 case Main::ModModeCopy:
437 setCursor (CopyCursor);
439 case Main::ModModeXLink:
440 setCursor (XLinkCursor);
443 setCursor (Qt::ArrowCursor);
449 void MapEditor::keyReleaseEvent(QKeyEvent* e)
451 if (!(e->modifiers() & Qt::ControlModifier))
452 setCursor (Qt::ArrowCursor);
455 void MapEditor::mousePressEvent(QMouseEvent* e)
457 // Ignore right clicks, these will go to context menus
458 if (e->button() == Qt::RightButton )
464 //Ignore clicks while editing heading
465 if (model->isSelectionBlocked() )
471 QPointF p = mapToScene(e->pos());
472 LinkableMapObj* lmo=model->findMapObj(p, NULL);
476 //Take care of system flags _or_ modifier modes
478 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
479 typeid(*lmo)==typeid(MapCenterObj) ))
481 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
482 if (!foname.isEmpty())
484 // systemFlag clicked
485 model->selectInt (lmo);
488 if (e->state() & Qt::ControlModifier)
489 mainWindow->editOpenURLTab();
491 mainWindow->editOpenURL();
493 else if (foname=="vymLink")
495 mainWindow->editOpenVymLink();
496 // tabWidget may change, better return now
497 // before segfaulting...
498 } else if (foname=="note")
499 mainWindow->windowToggleNoteEditor();
500 else if (foname=="hideInExport")
501 model->toggleHideExport();
502 // FIXME needed? xelection.update();
506 // No system flag clicked, take care of modmodes (CTRL-Click)
507 if (e->state() & Qt::ControlModifier)
509 if (mainWindow->getModMode()==Main::ModModeColor)
512 setCursor (PickColorCursor);
515 if (mainWindow->getModMode()==Main::ModModeXLink)
517 BranchObj *bo_begin=NULL;
519 bo_begin=(BranchObj*)(lmo);
521 bo_begin=model->getSelectedBranch();
525 linkingObj_src=bo_begin;
526 tmpXLink=new XLinkObj (mapScene);
527 tmpXLink->setBegin (bo_begin);
528 tmpXLink->setEnd (p);
529 tmpXLink->setColor(model->getMapDefXLinkColor());
530 tmpXLink->setWidth(model->getMapDefXLinkWidth());
531 tmpXLink->updateXLink();
532 tmpXLink->setVisibility (true);
540 cout << "ME::mouse pressed\n";
541 cout << " lmo="<<lmo<<endl;
542 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
543 // Select the clicked object
545 // FIXME VM better let "find" return an index instead of lmo...
546 // Get index of clicked LMO
547 TreeItem *ti=lmo->getTreeItem();
548 cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
549 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
550 //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
551 QModelIndex ix=model->index(ti);
552 model->getSelectionModel()->select (ix,QItemSelectionModel::ClearAndSelect );
554 // Left Button Move Branches
555 if (e->button() == Qt::LeftButton )
557 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
558 //movingObj_start.setY( p.y() - selection->y() );
559 movingObj_start.setX( p.x() - lmo->x() );
560 movingObj_start.setY( p.y() - lmo->y() );
561 movingObj_orgPos.setX (lmo->x() );
562 movingObj_orgPos.setY (lmo->y() );
564 movingObj_orgRelPos=lmo->getRelPos();
566 // If modMode==copy, then we want to "move" the _new_ object around
567 // then we need the offset from p to the _old_ selection, because of tmp
568 if (mainWindow->getModMode()==Main::ModModeCopy &&
569 e->state() & Qt::ControlModifier)
571 BranchObj *bo=model->getSelectedBranch();
575 bo->addBranch (model->getSelectedBranch());
577 model->select(bo->getLastBranch());
582 movingObj=model->getSelectedLMO();
584 // Middle Button Toggle Scroll
585 // (On Mac OS X this won't work, but we still have
586 // a button in the toolbar)
587 if (e->button() == Qt::MidButton )
588 model->toggleScroll();
589 model->updateActions();
590 // FIXME needed? xelection.update();
592 { // No MapObj found, we are on the scene itself
593 // Left Button move Pos of sceneView
594 if (e->button() == Qt::LeftButton )
596 movingObj=NULL; // move Content not Obj
597 movingObj_start=e->globalPos();
598 movingCont_start=QPointF (
599 horizontalScrollBar()->value(),
600 verticalScrollBar()->value());
601 movingVec=QPointF(0,0);
602 setCursor(HandOpenCursor);
607 void MapEditor::mouseMoveEvent(QMouseEvent* e)
609 QPointF p = mapToScene(e->pos());
610 LinkableMapObj *lmosel=model->getSelectedLMO();
612 // Move the selected MapObj
613 if ( lmosel && movingObj)
615 // reset cursor if we are moving and don't copy
616 if (mainWindow->getModMode()!=Main::ModModeCopy)
617 setCursor (Qt::ArrowCursor);
619 // To avoid jumping of the sceneView, only
620 // ensureSelectionVisible, if not tmp linked
621 if (!lmosel->hasParObjTmp())
622 model->ensureSelectionVisible ();
624 // Now move the selection, but add relative position
625 // (movingObj_start) where selection was chosen with
626 // mousepointer. (This avoids flickering resp. jumping
627 // of selection back to absPos)
629 // Check if we could link
630 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
633 FloatObj *fio=model->getSelectedFloatImage();
636 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
638 fio->updateLink(); //no need for reposition, if we update link here
639 model->updateSelection(); // position has changed
641 // Relink float to new mapcenter or branch, if shift is pressed
642 // Only relink, if selection really has a new parent
643 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
644 ( (typeid(*lmo)==typeid(BranchObj)) ||
645 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
646 ( lmo != fio->getParObj())
649 if (typeid(*fio) == typeid(FloatImageObj) &&
650 ( (typeid(*lmo)==typeid(BranchObj) ||
651 typeid(*lmo)==typeid(MapCenterObj)) ))
654 // Also save the move which was done so far
655 QString pold=qpointfToString(movingObj_orgRelPos);
656 QString pnow=qpointfToString(fio->getRelPos());
662 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
663 fio->getParObj()->requestReposition();
666 model->linkFloatImageTo (model->getSelectString(lmo));
668 //movingObj_orgRelPos=lmosel->getRelPos();
674 { // selection != a FloatObj
675 if (lmosel->getDepth()==0)
678 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
679 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
681 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
682 model->updateRelPositions();
685 if (lmosel->getDepth()==1)
688 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
692 // Move ordinary branch
693 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
694 // Add width of bbox here, otherwise alignRelTo will cause jumping around
695 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
696 p.y()-movingObj_start.y() +lmosel->getTopPad() );
698 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
702 // Maybe we can relink temporary?
703 if (lmo && (lmo!=lmosel) && model->getSelectedBranch() &&
704 (typeid(*lmo)==typeid(BranchObj) ||
705 typeid(*lmo)==typeid(MapCenterObj)) )
708 if (e->modifiers()==Qt::ControlModifier)
710 // Special case: CTRL to link below lmo
711 lmosel->setParObjTmp (lmo,p,+1);
713 else if (e->modifiers()==Qt::ShiftModifier)
714 lmosel->setParObjTmp (lmo,p,-1);
716 lmosel->setParObjTmp (lmo,p,0);
719 lmosel->unsetParObjTmp();
721 // reposition subbranch
722 lmosel->reposition();
725 QItemSelection sel=model->getSelectionModel()->selection();
726 updateSelection(sel,sel); // position has changed
728 } // no FloatImageObj
732 } // selection && moving_obj
734 // Draw a link from one branch to another
737 tmpXLink->setEnd (p);
738 tmpXLink->updateXLink();
742 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
744 QPointF p=e->globalPos();
745 movingVec.setX(-p.x() + movingObj_start.x() );
746 movingVec.setY(-p.y() + movingObj_start.y() );
747 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
748 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
753 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
755 QPointF p = mapToScene(e->pos());
757 LinkableMapObj *lmosel=model->getSelectedLMO();
758 // Have we been picking color?
762 setCursor (Qt::ArrowCursor);
763 // Check if we are over another branch
764 dst=model->findMapObj(p, NULL);
767 if (e->state() & Qt::ShiftModifier)
768 model->colorBranch (((BranchObj*)dst)->getColor());
770 model->colorSubtree (((BranchObj*)dst)->getColor());
775 // Have we been drawing a link?
779 // Check if we are over another branch
780 dst=model->findMapObj(p, NULL);
783 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
784 tmpXLink->updateXLink();
785 tmpXLink->activate(); //FIXME savestate missing
786 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
795 // Have we been moving something?
796 if ( lmosel && movingObj )
798 FloatImageObj *fo=model->getSelectedFloatImage();
801 // Moved FloatObj. Maybe we need to reposition
802 QString pold=qpointfToString(movingObj_orgRelPos);
803 QString pnow=qpointfToString(fo->getRelPos());
809 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
811 fo->getParObj()->requestReposition();
815 // Check if we are over another branch, but ignore
816 // any found LMOs, which are FloatObjs
817 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
819 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
822 BranchObj *bo=model->getSelectedBranch();
823 if (bo && bo->getDepth()==0)
825 if (movingObj_orgPos != bo->getAbsPos())
827 QString pold=qpointfToString(movingObj_orgPos);
828 QString pnow=qpointfToString(bo->getAbsPos());
834 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bo)).arg(pnow));
838 if (model->selectionType() == Selection::Branch )
839 { // A branch was moved
841 // save the position in case we link to mapcenter
842 QPointF savePos=QPointF (lmosel->getAbsPos() );
844 // Reset the temporary drawn link to the original one
845 lmosel->unsetParObjTmp();
847 // For Redo we may need to save original selection
848 QString preSelStr=model->getSelectString(lmosel);
853 // We have a destination, relink to that
855 BranchObj* bsel=model->getSelectedBranch();
856 BranchObj* bdst=(BranchObj*)dst;
858 QString preParStr=model->getSelectString (bsel->getParObj());
859 QString preNum=QString::number (bsel->getNum(),10);
860 QString preDstParStr;
862 if (e->state() & Qt::ShiftModifier && dst->getParObj())
864 preDstParStr=model->getSelectString (dst->getParObj());
865 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
867 if (e->state() & Qt::ControlModifier && dst->getParObj())
870 preDstParStr=model->getSelectString (dst->getParObj());
871 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
874 preDstParStr=model->getSelectString(dst);
875 bsel->linkTo (bdst,-1);
876 if (dst->getDepth()==0) bsel->move (savePos);
878 QString postSelStr=model->getSelectString(lmosel);
879 QString postNum=QString::number (bsel->getNum(),10);
881 QString undoCom="linkTo (\""+
882 preParStr+ "\"," + preNum +"," +
883 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
885 QString redoCom="linkTo (\""+
886 preDstParStr + "\"," + postNum + "," +
887 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
892 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
894 model->reposition(); // not necessary if we undo temporary move below
897 // No destination, undo temporary move
899 if (lmosel->getDepth()==1)
901 // The select string might be different _after_ moving around.
902 // Therefor reposition and then use string of old selection, too
905 QPointF rp(lmosel->getRelPos());
906 if (rp != movingObj_orgRelPos)
908 QString ps=qpointfToString(rp);
910 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
911 preSelStr, "moveRel "+ps,
912 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
916 // Draw the original link, before selection was moved around
917 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
919 lmosel->setRelPos(); // calc relPos first for starting point
920 QPointF dst=bo->getParObj()->getChildPos();
921 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
923 model->startAnimation(
927 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
933 model->updateSelection();
934 // Finally resize scene, if needed
938 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
939 model->updateActions();
941 // maybe we moved View: set old cursor
942 setCursor (Qt::ArrowCursor);
946 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
948 if (model->isSelectionBlocked() )
954 if (e->button() == Qt::LeftButton )
956 QPointF p = mapToScene(e->pos());
957 LinkableMapObj *lmo=model->findMapObj(p, NULL);
958 if (lmo) { // MapObj was found
959 // First select the MapObj than edit heading
966 void MapEditor::resizeEvent (QResizeEvent* e)
968 QGraphicsView::resizeEvent( e );
971 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
973 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
974 // cerr << event->format(i) << endl;
976 if (event->mimeData()->hasImage())
977 event->acceptProposedAction();
979 if (event->mimeData()->hasUrls())
980 event->acceptProposedAction();
983 void MapEditor::dragMoveEvent(QDragMoveEvent *)
987 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
992 void MapEditor::dropEvent(QDropEvent *event)
994 BranchObj *sel=model->getSelectedBranch();
998 foreach (QString format,event->mimeData()->formats())
999 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1003 if (event->mimeData()->hasImage())
1005 QVariant imageData = event->mimeData()->imageData();
1006 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1008 if (event->mimeData()->hasUrls())
1009 uris=event->mimeData()->urls();
1017 for (int i=0; i<uris.count();i++)
1019 // Workaround to avoid adding empty branches
1020 if (!uris.at(i).toString().isEmpty())
1022 bo=sel->addBranch();
1025 s=uris.at(i).toLocalFile();
1028 QString file = QDir::fromNativeSeparators(s);
1029 heading = QFileInfo(file).baseName();
1031 if (file.endsWith(".vym", false))
1032 bo->setVymLink(file);
1034 bo->setURL(uris.at(i).toString());
1037 bo->setURL(uris.at(i).toString());
1040 if (!heading.isEmpty())
1041 bo->setHeading(heading);
1043 bo->setHeading(uris.at(i).toString());
1047 model->reposition();
1050 event->acceptProposedAction();
1053 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1055 // Reduce rectangles
1056 while (newsel.indexes().count() < selboxList.count() )
1057 delete selboxList.takeFirst();
1059 // Add additonal rectangles
1060 QGraphicsRectItem *sb;
1061 while (newsel.indexes().count() > selboxList.count() )
1063 sb = mapScene->addRect(
1065 QPen(selectionColor),
1067 sb->setZValue(Z_SELBOX);
1069 selboxList.append (sb);
1072 // Reposition rectangles
1078 LinkableMapObj *lmo;
1079 foreach (sb,selboxList)
1081 index=newsel.indexes().at(i);
1082 ti= static_cast<TreeItem*>(index.internalPointer());
1084 cout << " ME::updateSelection of "<<((BranchObj*)lmo)->getHeading().toStdString()<<"\n";
1085 bbox=lmo->getBBox();
1088 bbox.width(), bbox.height());
1089 sb->setPen (selectionColor);
1090 sb->setBrush (selectionColor);
1095 void MapEditor::updateCurrent (const QModelIndex &,const QModelIndex &) //FIXME not used?
1100 cout << "ME::updateCurrent\n";
1102 TreeItem *item = static_cast<TreeItem*>(newsel.internalPointer());
1103 LinkableMapObj *lmo=item->getLMO();
1104 cout << " lmo="<<lmo<<endl;
1105 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
1110 void MapEditor::setSelectionColor (QColor col)
1113 QItemSelection sel=model->getSelectionModel()->selection();
1114 updateSelection(sel,sel);
1117 QColor MapEditor::getSelectionColor ()
1119 return selectionColor;