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 cout << "ME::mouse pressed\n";
542 cout << " lmo="<<lmo<<endl;
543 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
544 // Select the clicked object
546 // FIXME VM better let "find" return an index instead of lmo...
547 // Get index of clicked LMO
548 TreeItem *ti=lmo->getTreeItem();
549 cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
550 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
551 //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
552 QModelIndex ix=model->index(ti);
553 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
555 if (selModel->hasSelection() )
557 QModelIndex ixsel=selModel->selectedIndexes().first();
558 TreeItem *tisel= static_cast<TreeItem*>(ixsel.internalPointer());
560 cout << " ti="<<ti<<" tisel="<<tisel<<endl;
561 if (ti!=tisel) int i=1/0;
564 cout <<"MapEditor::mousePressed No selection!!!\n";
568 // Left Button Move Branches
569 if (e->button() == Qt::LeftButton )
571 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
572 //movingObj_start.setY( p.y() - selection->y() );
573 movingObj_start.setX( p.x() - lmo->x() );
574 movingObj_start.setY( p.y() - lmo->y() );
575 movingObj_orgPos.setX (lmo->x() );
576 movingObj_orgPos.setY (lmo->y() );
578 movingObj_orgRelPos=lmo->getRelPos();
580 // If modMode==copy, then we want to "move" the _new_ object around
581 // then we need the offset from p to the _old_ selection, because of tmp
582 if (mainWindow->getModMode()==Main::ModModeCopy &&
583 e->state() & Qt::ControlModifier)
585 BranchObj *bo=model->getSelectedBranch();
589 bo->addBranch ((BranchObj*)model->getSelection());
591 model->select(bo->getLastBranch());
596 movingObj=model->getSelection();
598 // Middle Button Toggle Scroll
599 // (On Mac OS X this won't work, but we still have
600 // a button in the toolbar)
601 if (e->button() == Qt::MidButton )
602 model->toggleScroll();
603 model->updateActions();
604 // FIXME needed? xelection.update();
606 { // No MapObj found, we are on the scene itself
607 // Left Button move Pos of sceneView
608 if (e->button() == Qt::LeftButton )
610 movingObj=NULL; // move Content not Obj
611 movingObj_start=e->globalPos();
612 movingCont_start=QPointF (
613 horizontalScrollBar()->value(),
614 verticalScrollBar()->value());
615 movingVec=QPointF(0,0);
616 setCursor(HandOpenCursor);
621 void MapEditor::mouseMoveEvent(QMouseEvent* e)
623 QPointF p = mapToScene(e->pos());
624 LinkableMapObj *lmosel=model->getSelection();
626 // Move the selected MapObj
627 if ( lmosel && movingObj)
629 // reset cursor if we are moving and don't copy
630 if (mainWindow->getModMode()!=Main::ModModeCopy)
631 setCursor (Qt::ArrowCursor);
633 // To avoid jumping of the sceneView, only
634 // ensureSelectionVisible, if not tmp linked
635 if (!lmosel->hasParObjTmp())
636 model->ensureSelectionVisible ();
638 // Now move the selection, but add relative position
639 // (movingObj_start) where selection was chosen with
640 // mousepointer. (This avoids flickering resp. jumping
641 // of selection back to absPos)
643 // Check if we could link
644 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
647 FloatObj *fio=model->getSelectedFloatImage();
650 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
652 fio->updateLink(); //no need for reposition, if we update link here
653 model->updateSelection();
655 // Relink float to new mapcenter or branch, if shift is pressed
656 // Only relink, if selection really has a new parent
657 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
658 ( (typeid(*lmo)==typeid(BranchObj)) ||
659 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
660 ( lmo != fio->getParObj())
663 if (typeid(*fio) == typeid(FloatImageObj) &&
664 ( (typeid(*lmo)==typeid(BranchObj) ||
665 typeid(*lmo)==typeid(MapCenterObj)) ))
668 // Also save the move which was done so far
669 QString pold=qpointfToString(movingObj_orgRelPos);
670 QString pnow=qpointfToString(fio->getRelPos());
676 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
677 fio->getParObj()->requestReposition();
680 model->linkFloatImageTo (model->getSelectString(lmo));
682 //movingObj_orgRelPos=lmosel->getRelPos();
688 { // selection != a FloatObj
689 if (lmosel->getDepth()==0)
692 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
693 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
695 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
696 model->updateRelPositions();
699 if (lmosel->getDepth()==1)
702 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
706 // Move ordinary branch
707 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
708 // Add width of bbox here, otherwise alignRelTo will cause jumping around
709 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
710 p.y()-movingObj_start.y() +lmosel->getTopPad() );
712 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
716 // Maybe we can relink temporary?
717 if (lmo && (lmo!=lmosel) && model->getSelectedBranch() &&
718 (typeid(*lmo)==typeid(BranchObj) ||
719 typeid(*lmo)==typeid(MapCenterObj)) )
722 if (e->modifiers()==Qt::ControlModifier)
724 // Special case: CTRL to link below lmo
725 lmosel->setParObjTmp (lmo,p,+1);
727 else if (e->modifiers()==Qt::ShiftModifier)
728 lmosel->setParObjTmp (lmo,p,-1);
730 lmosel->setParObjTmp (lmo,p,0);
733 lmosel->unsetParObjTmp();
735 // reposition subbranch
736 lmosel->reposition();
739 //model->updateSelection();// FIXME needed?
740 //updateSelectionGeometry();
741 updateSelection(selModel->selection(), selModel->selection() );
742 } // no FloatImageObj
746 } // selection && moving_obj
748 // Draw a link from one branch to another
751 tmpXLink->setEnd (p);
752 tmpXLink->updateXLink();
756 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
758 QPointF p=e->globalPos();
759 movingVec.setX(-p.x() + movingObj_start.x() );
760 movingVec.setY(-p.y() + movingObj_start.y() );
761 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
762 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
767 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
769 QPointF p = mapToScene(e->pos());
771 LinkableMapObj *lmosel=model->getSelection();
772 // Have we been picking color?
776 setCursor (Qt::ArrowCursor);
777 // Check if we are over another branch
778 dst=model->findMapObj(p, NULL);
781 if (e->state() & Qt::ShiftModifier)
782 model->colorBranch (((BranchObj*)dst)->getColor());
784 model->colorSubtree (((BranchObj*)dst)->getColor());
789 // Have we been drawing a link?
793 // Check if we are over another branch
794 dst=model->findMapObj(p, NULL);
797 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
798 tmpXLink->updateXLink();
799 tmpXLink->activate(); //FIXME savestate missing
800 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
809 // Have we been moving something?
810 if ( lmosel && movingObj )
812 FloatImageObj *fo=model->getSelectedFloatImage();
815 // Moved FloatObj. Maybe we need to reposition
816 QString pold=qpointfToString(movingObj_orgRelPos);
817 QString pnow=qpointfToString(fo->getRelPos());
823 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
825 fo->getParObj()->requestReposition();
829 // Check if we are over another branch, but ignore
830 // any found LMOs, which are FloatObjs
831 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
833 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
836 BranchObj *bo=model->getSelectedBranch();
837 if (bo && bo->getDepth()==0)
839 if (movingObj_orgPos != bo->getAbsPos())
841 QString pold=qpointfToString(movingObj_orgPos);
842 QString pnow=qpointfToString(bo->getAbsPos());
848 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bo)).arg(pnow));
852 if (model->selectionType() == Selection::Branch )
853 { // A branch was moved
855 // save the position in case we link to mapcenter
856 QPointF savePos=QPointF (lmosel->getAbsPos() );
858 // Reset the temporary drawn link to the original one
859 lmosel->unsetParObjTmp();
861 // For Redo we may need to save original selection
862 QString preSelStr=model->getSelectString(lmosel);
867 // We have a destination, relink to that
869 BranchObj* bsel=model->getSelectedBranch();
870 BranchObj* bdst=(BranchObj*)dst;
872 QString preParStr=model->getSelectString (bsel->getParObj());
873 QString preNum=QString::number (bsel->getNum(),10);
874 QString preDstParStr;
876 if (e->state() & Qt::ShiftModifier && dst->getParObj())
878 preDstParStr=model->getSelectString (dst->getParObj());
879 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
881 if (e->state() & Qt::ControlModifier && dst->getParObj())
884 preDstParStr=model->getSelectString (dst->getParObj());
885 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
888 preDstParStr=model->getSelectString(dst);
889 bsel->linkTo (bdst,-1);
890 if (dst->getDepth()==0) bsel->move (savePos);
892 QString postSelStr=model->getSelectString(lmosel);
893 QString postNum=QString::number (bsel->getNum(),10);
895 QString undoCom="linkTo (\""+
896 preParStr+ "\"," + preNum +"," +
897 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
899 QString redoCom="linkTo (\""+
900 preDstParStr + "\"," + postNum + "," +
901 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
906 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
908 model->reposition(); // not necessary if we undo temporary move below
911 // No destination, undo temporary move
913 if (lmosel->getDepth()==1)
915 // The select string might be different _after_ moving around.
916 // Therefor reposition and then use string of old selection, too
919 QPointF rp(lmosel->getRelPos());
920 if (rp != movingObj_orgRelPos)
922 QString ps=qpointfToString(rp);
924 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
925 preSelStr, "moveRel "+ps,
926 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
930 // Draw the original link, before selection was moved around
931 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
933 lmosel->setRelPos(); // calc relPos first for starting point
934 QPointF dst=bo->getParObj()->getChildPos();
935 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
937 model->startAnimation(
941 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
947 model->updateSelection();
948 // Finally resize scene, if needed
952 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
953 model->updateActions();
955 // maybe we moved View: set old cursor
956 setCursor (Qt::ArrowCursor);
960 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
962 if (model->isSelectionBlocked() )
968 if (e->button() == Qt::LeftButton )
970 QPointF p = mapToScene(e->pos());
971 LinkableMapObj *lmo=model->findMapObj(p, NULL);
972 if (lmo) { // MapObj was found
973 // First select the MapObj than edit heading
980 void MapEditor::resizeEvent (QResizeEvent* e)
982 QGraphicsView::resizeEvent( e );
985 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
987 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
988 // cerr << event->format(i) << endl;
990 if (event->mimeData()->hasImage())
991 event->acceptProposedAction();
993 if (event->mimeData()->hasUrls())
994 event->acceptProposedAction();
997 void MapEditor::dragMoveEvent(QDragMoveEvent *)
1001 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
1006 void MapEditor::dropEvent(QDropEvent *event)
1008 BranchObj *sel=model->getSelectedBranch();
1012 foreach (QString format,event->mimeData()->formats())
1013 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1017 if (event->mimeData()->hasImage())
1019 QVariant imageData = event->mimeData()->imageData();
1020 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1022 if (event->mimeData()->hasUrls())
1023 uris=event->mimeData()->urls();
1031 for (int i=0; i<uris.count();i++)
1033 // Workaround to avoid adding empty branches
1034 if (!uris.at(i).toString().isEmpty())
1036 bo=sel->addBranch();
1039 s=uris.at(i).toLocalFile();
1042 QString file = QDir::fromNativeSeparators(s);
1043 heading = QFileInfo(file).baseName();
1045 if (file.endsWith(".vym", false))
1046 bo->setVymLink(file);
1048 bo->setURL(uris.at(i).toString());
1051 bo->setURL(uris.at(i).toString());
1054 if (!heading.isEmpty())
1055 bo->setHeading(heading);
1057 bo->setHeading(uris.at(i).toString());
1061 model->reposition();
1064 event->acceptProposedAction();
1067 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1069 cout << "ME::updateSelection\n";
1072 if (newsel.isEmpty() )
1074 cout << " newsel=empty!\n";
1077 QModelIndex index=newsel.indexes().first(); // TODO no multiselections yet
1079 TreeItem *ti= static_cast<TreeItem*>(index.internalPointer());
1080 LinkableMapObj *lmo=ti->getLMO();
1081 cout << " newsel.count="<<newsel.indexes().count()<<" lmo="<<lmo<<endl;
1082 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
1083 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
1086 // Reduce rectangles
1087 while (newsel.indexes().count() < selboxList.count() )
1088 delete selboxList.takeFirst();
1090 // Add additonal rectangles
1091 QGraphicsRectItem *sb;
1092 while (newsel.indexes().count() > selboxList.count() )
1094 sb = mapScene->addRect(
1096 QPen(selectionColor),
1098 sb->setZValue(Z_SELBOX);
1100 selboxList.append (sb);
1103 // Reposition rectangles
1106 foreach (sb,selboxList)
1108 index=newsel.indexes().at(i);
1109 ti= static_cast<TreeItem*>(index.internalPointer());
1111 bbox=lmo->getBBox();
1114 bbox.width(), bbox.height());
1115 sb->setPen (selectionColor);
1116 sb->setBrush (selectionColor);
1121 void MapEditor::updateCurrent (const QModelIndex &newsel,const QModelIndex &)
1123 cout << "ME::updateCurrent\n";
1127 TreeItem *item = static_cast<TreeItem*>(newsel.internalPointer());
1128 LinkableMapObj *lmo=item->getLMO();
1129 cout << " lmo="<<lmo<<endl;
1130 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
1135 void MapEditor::updateSelectionGeometry() // FIXME VM only called from VM::animate...
1137 cout << "ME::updateSelectionGeometry\n";
1139 // Tell selection to update geometries
1140 updateSelection(selModel->selection(), selModel->selection() );
1141 //model->updateSelection();
1145 void MapEditor::setSelectionColor (QColor col)
1148 updateSelectionGeometry();
1151 QColor MapEditor::getSelectionColor ()
1153 return selectionColor;