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);
541 cout << "ME::mouse pressed\n";
542 cout << " lmo="<<lmo<<endl;
543 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
545 // Select the clicked object
547 // FIXME VM better let "find" return an index instead of lmo...
548 // Get index of clicked LMO
549 TreeItem *ti=lmo->getTreeItem();
551 cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
552 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
554 //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
557 // Left Button Move Branches
558 if (e->button() == Qt::LeftButton )
560 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
561 //movingObj_start.setY( p.y() - selection->y() );
562 movingObj_start.setX( p.x() - lmo->x() );
563 movingObj_start.setY( p.y() - lmo->y() );
564 movingObj_orgPos.setX (lmo->x() );
565 movingObj_orgPos.setY (lmo->y() );
567 movingObj_orgRelPos=lmo->getRelPos();
569 // If modMode==copy, then we want to "move" the _new_ object around
570 // then we need the offset from p to the _old_ selection, because of tmp
571 if (mainWindow->getModMode()==Main::ModModeCopy &&
572 e->state() & Qt::ControlModifier)
574 BranchObj *bo=model->getSelectedBranch();
578 bo->addBranch (model->getSelectedBranch());
580 model->select(bo->getLastBranch());
585 movingObj=model->getSelectedLMO();
587 // Middle Button Toggle Scroll
588 // (On Mac OS X this won't work, but we still have
589 // a button in the toolbar)
590 if (e->button() == Qt::MidButton )
591 model->toggleScroll();
592 model->updateActions();
593 // FIXME needed? xelection.update();
595 { // No MapObj found, we are on the scene itself
596 // Left Button move Pos of sceneView
597 if (e->button() == Qt::LeftButton )
599 movingObj=NULL; // move Content not Obj
600 movingObj_start=e->globalPos();
601 movingCont_start=QPointF (
602 horizontalScrollBar()->value(),
603 verticalScrollBar()->value());
604 movingVec=QPointF(0,0);
605 setCursor(HandOpenCursor);
610 void MapEditor::mouseMoveEvent(QMouseEvent* e)
612 QPointF p = mapToScene(e->pos());
613 LinkableMapObj *lmosel=model->getSelectedLMO();
615 // Move the selected MapObj
616 if ( lmosel && movingObj)
618 // reset cursor if we are moving and don't copy
619 if (mainWindow->getModMode()!=Main::ModModeCopy)
620 setCursor (Qt::ArrowCursor);
622 // To avoid jumping of the sceneView, only
623 // ensureSelectionVisible, if not tmp linked
624 if (!lmosel->hasParObjTmp())
625 model->ensureSelectionVisible ();
627 // Now move the selection, but add relative position
628 // (movingObj_start) where selection was chosen with
629 // mousepointer. (This avoids flickering resp. jumping
630 // of selection back to absPos)
632 // Check if we could link
633 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
636 FloatObj *fio=model->getSelectedFloatImage();
639 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
641 fio->updateLink(); //no need for reposition, if we update link here
642 model->updateSelection(); // position has changed
644 // Relink float to new mapcenter or branch, if shift is pressed
645 // Only relink, if selection really has a new parent
646 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
647 ( (typeid(*lmo)==typeid(BranchObj)) ||
648 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
649 ( lmo != fio->getParObj())
652 if (typeid(*fio) == typeid(FloatImageObj) &&
653 ( (typeid(*lmo)==typeid(BranchObj) ||
654 typeid(*lmo)==typeid(MapCenterObj)) ))
657 // Also save the move which was done so far
658 QString pold=qpointfToString(movingObj_orgRelPos);
659 QString pnow=qpointfToString(fio->getRelPos());
665 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
666 fio->getParObj()->requestReposition();
669 model->linkFloatImageTo (model->getSelectString(lmo));
671 //movingObj_orgRelPos=lmosel->getRelPos();
677 { // selection != a FloatObj
678 if (lmosel->getDepth()==0)
681 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
682 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
684 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
685 model->updateRelPositions();
688 if (lmosel->getDepth()==1)
691 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
695 // Move ordinary branch
696 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
697 // Add width of bbox here, otherwise alignRelTo will cause jumping around
698 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
699 p.y()-movingObj_start.y() +lmosel->getTopPad() );
701 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
705 // Maybe we can relink temporary?
706 if (lmo && (lmo!=lmosel) && model->getSelectedBranch() &&
707 (typeid(*lmo)==typeid(BranchObj) ||
708 typeid(*lmo)==typeid(MapCenterObj)) )
711 if (e->modifiers()==Qt::ControlModifier)
713 // Special case: CTRL to link below lmo
714 lmosel->setParObjTmp (lmo,p,+1);
716 else if (e->modifiers()==Qt::ShiftModifier)
717 lmosel->setParObjTmp (lmo,p,-1);
719 lmosel->setParObjTmp (lmo,p,0);
722 lmosel->unsetParObjTmp();
724 // reposition subbranch
725 lmosel->reposition();
728 QItemSelection sel=model->getSelectionModel()->selection();
729 updateSelection(sel,sel); // position has changed
731 } // no FloatImageObj
735 } // selection && moving_obj
737 // Draw a link from one branch to another
740 tmpXLink->setEnd (p);
741 tmpXLink->updateXLink();
745 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
747 QPointF p=e->globalPos();
748 movingVec.setX(-p.x() + movingObj_start.x() );
749 movingVec.setY(-p.y() + movingObj_start.y() );
750 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
751 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
756 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
758 QPointF p = mapToScene(e->pos());
760 LinkableMapObj *lmosel=model->getSelectedLMO();
761 // Have we been picking color?
765 setCursor (Qt::ArrowCursor);
766 // Check if we are over another branch
767 dst=model->findMapObj(p, NULL);
770 if (e->state() & Qt::ShiftModifier)
771 model->colorBranch (((BranchObj*)dst)->getColor());
773 model->colorSubtree (((BranchObj*)dst)->getColor());
778 // Have we been drawing a link?
782 // Check if we are over another branch
783 dst=model->findMapObj(p, NULL);
786 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
787 tmpXLink->updateXLink();
788 tmpXLink->activate(); //FIXME savestate missing
789 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
798 // Have we been moving something?
799 if ( lmosel && movingObj )
801 FloatImageObj *fo=model->getSelectedFloatImage();
804 // Moved FloatObj. Maybe we need to reposition
805 QString pold=qpointfToString(movingObj_orgRelPos);
806 QString pnow=qpointfToString(fo->getRelPos());
812 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
814 fo->getParObj()->requestReposition();
818 // Check if we are over another branch, but ignore
819 // any found LMOs, which are FloatObjs
820 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
822 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
825 BranchObj *bo=model->getSelectedBranch();
826 if (bo && bo->getDepth()==0)
828 if (movingObj_orgPos != bo->getAbsPos())
830 QString pold=qpointfToString(movingObj_orgPos);
831 QString pnow=qpointfToString(bo->getAbsPos());
837 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bo)).arg(pnow));
841 if (model->selectionType() == TreeItem::Branch )
842 { // A branch was moved
844 // save the position in case we link to mapcenter
845 QPointF savePos=QPointF (lmosel->getAbsPos() );
847 // Reset the temporary drawn link to the original one
848 lmosel->unsetParObjTmp();
850 // For Redo we may need to save original selection
851 QString preSelStr=model->getSelectString(lmosel);
856 // We have a destination, relink to that
858 BranchObj* bsel=model->getSelectedBranch();
859 BranchObj* bdst=(BranchObj*)dst;
861 QString preParStr=model->getSelectString (bsel->getParObj());
862 QString preNum=QString::number (bsel->getNum(),10);
863 QString preDstParStr;
865 if (e->state() & Qt::ShiftModifier && dst->getParObj())
867 preDstParStr=model->getSelectString (dst->getParObj());
868 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
870 if (e->state() & Qt::ControlModifier && dst->getParObj())
873 preDstParStr=model->getSelectString (dst->getParObj());
874 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
877 preDstParStr=model->getSelectString(dst);
878 bsel->linkTo (bdst,-1);
879 if (dst->getDepth()==0) bsel->move (savePos);
881 QString postSelStr=model->getSelectString(lmosel);
882 QString postNum=QString::number (bsel->getNum(),10);
884 QString undoCom="linkTo (\""+
885 preParStr+ "\"," + preNum +"," +
886 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
888 QString redoCom="linkTo (\""+
889 preDstParStr + "\"," + postNum + "," +
890 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
895 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
897 model->reposition(); // not necessary if we undo temporary move below
900 // No destination, undo temporary move
902 if (lmosel->getDepth()==1)
904 // The select string might be different _after_ moving around.
905 // Therefor reposition and then use string of old selection, too
908 QPointF rp(lmosel->getRelPos());
909 if (rp != movingObj_orgRelPos)
911 QString ps=qpointfToString(rp);
913 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
914 preSelStr, "moveRel "+ps,
915 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
919 // Draw the original link, before selection was moved around
920 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
922 lmosel->setRelPos(); // calc relPos first for starting point
923 QPointF dst=bo->getParObj()->getChildPos();
924 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
926 model->startAnimation(
930 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
936 model->updateSelection();
937 // Finally resize scene, if needed
941 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
942 model->updateActions();
944 // maybe we moved View: set old cursor
945 setCursor (Qt::ArrowCursor);
949 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
951 if (model->isSelectionBlocked() )
957 if (e->button() == Qt::LeftButton )
959 QPointF p = mapToScene(e->pos());
960 LinkableMapObj *lmo=model->findMapObj(p, NULL);
961 if (lmo) { // MapObj was found
962 // First select the MapObj than edit heading
969 void MapEditor::resizeEvent (QResizeEvent* e)
971 QGraphicsView::resizeEvent( e );
974 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
976 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
977 // cerr << event->format(i) << endl;
979 if (event->mimeData()->hasImage())
980 event->acceptProposedAction();
982 if (event->mimeData()->hasUrls())
983 event->acceptProposedAction();
986 void MapEditor::dragMoveEvent(QDragMoveEvent *)
990 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
995 void MapEditor::dropEvent(QDropEvent *event)
997 BranchObj *sel=model->getSelectedBranch();
1001 foreach (QString format,event->mimeData()->formats())
1002 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1006 if (event->mimeData()->hasImage())
1008 QVariant imageData = event->mimeData()->imageData();
1009 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1011 if (event->mimeData()->hasUrls())
1012 uris=event->mimeData()->urls();
1020 for (int i=0; i<uris.count();i++)
1022 // Workaround to avoid adding empty branches
1023 if (!uris.at(i).toString().isEmpty())
1025 bo=sel->addBranch();
1028 s=uris.at(i).toLocalFile();
1031 QString file = QDir::fromNativeSeparators(s);
1032 heading = QFileInfo(file).baseName();
1034 if (file.endsWith(".vym", false))
1035 bo->setVymLink(file);
1037 bo->setURL(uris.at(i).toString());
1040 bo->setURL(uris.at(i).toString());
1043 if (!heading.isEmpty())
1044 bo->setHeading(heading);
1046 bo->setHeading(uris.at(i).toString());
1050 model->reposition();
1053 event->acceptProposedAction();
1056 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1058 // Reduce rectangles
1059 while (newsel.indexes().count() < selboxList.count() )
1060 delete selboxList.takeFirst();
1062 // Add additonal rectangles
1063 QGraphicsRectItem *sb;
1064 while (newsel.indexes().count() > selboxList.count() )
1066 sb = mapScene->addRect(
1068 QPen(selectionColor),
1070 sb->setZValue(Z_SELBOX);
1072 selboxList.append (sb);
1075 // Reposition rectangles
1081 LinkableMapObj *lmo;
1082 foreach (sb,selboxList)
1084 index=newsel.indexes().at(i);
1085 ti= static_cast<TreeItem*>(index.internalPointer());
1087 bbox=lmo->getBBox();
1090 bbox.width(), bbox.height());
1091 sb->setPen (selectionColor);
1092 sb->setBrush (selectionColor);
1097 void MapEditor::updateCurrent (const QModelIndex &,const QModelIndex &) //FIXME not used?
1102 cout << "ME::updateCurrent\n";
1104 TreeItem *item = static_cast<TreeItem*>(newsel.internalPointer());
1105 LinkableMapObj *lmo=item->getLMO();
1106 cout << " lmo="<<lmo<<endl;
1107 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
1112 void MapEditor::setSelectionColor (QColor col)
1115 QItemSelection sel=model->getSelectionModel()->selection();
1116 updateSelection(sel,sel);
1119 QColor MapEditor::getSelectionColor ()
1121 return selectionColor;