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-3 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-3 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-2 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 for "<<model->getMapName().toStdString()<<endl;
132 // No need to remove tmp files:
133 // tmpMapDir is in tmpVymDir,
134 // so it gets removed automagically when vym closes
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-3 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(); // geometry has changed
279 AttributeTable* MapEditor::attributeTable()
284 void MapEditor::testFunction1()
289 cout << "ME::testFunction1 starting to walk the map...\n";
290 while (model->next (cur,prev,d) )
291 cout << "*** " <<cur->getHeading().toStdString()<<endl;
294 //BranchObj *bo=model->getSelectedBranch();
295 //if (bo) model->moveAway (bo);
296 //if (bo) bo->setLinkStyle (LinkableMapObj::Line);
300 // Displacement and animation of all non-mainbranches
309 bo=(BranchObj*)(cur->getLMO());
311 if (cur->depth() >0 && !bo->hasScrolledParent(bo) )
313 p=QPointF (qrand() %600-300, qrand () %600-300);
316 model->startAnimation (bo,p, q);
318 model->next(cur,prev,d);
323 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
324 if (hidemode==HideNone)
326 setHideTmpMode (HideExport);
327 mapCenter->calcBBoxSizeWithChilds();
328 QRectF totalBBox=mapCenter->getTotalBBox();
329 QRectF mapRect=totalBBox;
330 QCanvasRectangle *frame=NULL;
332 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
334 mapRect.setRect (totalBBox.x(), totalBBox.y(),
335 totalBBox.width(), totalBBox.height());
336 frame=new QCanvasRectangle (mapRect,mapScene);
337 frame->setBrush (QColor(white));
338 frame->setPen (QColor(black));
344 setHideTmpMode (HideNone);
346 cout <<" hidemode="<<hidemode<<endl;
350 void MapEditor::testFunction2()
355 if (hidemode==HideExport)
356 setHideTmpMode (HideNone);
358 setHideTmpMode (HideExport);
362 void MapEditor::editHeading()
366 editHeadingFinished();
369 BranchObj *bo=model->getSelectedBranch();
372 model->setSelectionBlocked(true);
374 lineEdit->setText (bo->getHeading());
375 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
376 lineEdit->setGeometry(p.x(),p.y(),230,25);
377 lineEdit->selectAll();
379 lineEdit->setFocus();
380 lineEdit->grabKeyboard();
385 void MapEditor::editHeadingFinished()
387 editingHeading=false;
388 lineEdit->releaseKeyboard();
389 model->setHeading (lineEdit->text() );
390 model->setSelectionBlocked(false);
393 // Maybe reselect previous branch
394 mainWindow->editHeadingFinished (model);
398 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
400 // Lineedits are already closed by preceding
401 // mouseEvent, we don't need to close here.
403 QPointF p = mapToScene(e->pos());
404 LinkableMapObj* lmo=model->findMapObj(p, NULL);
407 { // MapObj was found
408 if (model->getSelectedLMO() != lmo)
414 if (model->getSelectedBranch() )
416 // Context Menu on branch or mapcenter
417 //FIXME-3 model->updateActions(); needed?
418 branchContextMenu->popup(e->globalPos() );
421 if (model->getSelectedFloatImage() )
423 // Context Menu on floatimage
424 // model->updateActions(); FIXME-3 needed?
425 floatimageContextMenu->popup(e->globalPos() );
429 { // No MapObj found, we are on the Canvas itself
430 // Context Menu on scene
431 // model->updateActions(); FIXME-3 needed?
433 // Open context menu synchronously to position new mapcenter
434 model->setContextPos (p);
435 canvasContextMenu->exec(e->globalPos() );
436 model->unsetContextPos ();
441 void MapEditor::keyPressEvent(QKeyEvent* e)
443 if (e->modifiers() & Qt::ControlModifier)
445 switch (mainWindow->getModMode())
447 case Main::ModModeColor:
448 setCursor (PickColorCursor);
450 case Main::ModModeCopy:
451 setCursor (CopyCursor);
453 case Main::ModModeXLink:
454 setCursor (XLinkCursor);
457 setCursor (Qt::ArrowCursor);
463 void MapEditor::keyReleaseEvent(QKeyEvent* e)
465 if (!(e->modifiers() & Qt::ControlModifier))
466 setCursor (Qt::ArrowCursor);
469 void MapEditor::mousePressEvent(QMouseEvent* e)
471 // Ignore right clicks, these will go to context menus
472 if (e->button() == Qt::RightButton )
478 //Ignore clicks while editing heading
479 if (model->isSelectionBlocked() )
485 QPointF p = mapToScene(e->pos());
486 LinkableMapObj* lmo=model->findMapObj(p, NULL);
490 //Take care of system flags _or_ modifier modes
492 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
493 typeid(*lmo)==typeid(MapCenterObj) ))
495 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
496 if (!foname.isEmpty())
498 // systemFlag clicked
499 model->selectInt (lmo);
502 if (e->state() & Qt::ControlModifier)
503 mainWindow->editOpenURLTab();
505 mainWindow->editOpenURL();
507 else if (foname=="vymLink")
509 mainWindow->editOpenVymLink();
510 // tabWidget may change, better return now
511 // before segfaulting...
512 } else if (foname=="note")
513 mainWindow->windowToggleNoteEditor();
514 else if (foname=="hideInExport")
515 model->toggleHideExport();
516 // FIXME-3 needed? xelection.update();
520 // No system flag clicked, take care of modmodes (CTRL-Click)
521 if (e->state() & Qt::ControlModifier)
523 if (mainWindow->getModMode()==Main::ModModeColor)
526 setCursor (PickColorCursor);
529 if (mainWindow->getModMode()==Main::ModModeXLink)
531 BranchObj *bo_begin=NULL;
533 bo_begin=(BranchObj*)(lmo);
535 bo_begin=model->getSelectedBranch();
539 linkingObj_src=bo_begin;
540 tmpXLink=new XLinkObj (mapScene);
541 tmpXLink->setBegin (bo_begin);
542 tmpXLink->setEnd (p);
543 tmpXLink->setColor(model->getMapDefXLinkColor());
544 tmpXLink->setWidth(model->getMapDefXLinkWidth());
545 tmpXLink->updateXLink();
546 tmpXLink->setVisibility (true);
555 cout << "ME::mouse pressed\n";
556 cout << " lmo="<<lmo<<endl;
557 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
559 // Select the clicked object
561 // FIXME-2 VM better let "find" return an index instead of lmo...
562 // Get index of clicked LMO
563 TreeItem *ti=lmo->getTreeItem();
565 cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
566 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
568 //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
571 // Left Button Move Branches
572 if (e->button() == Qt::LeftButton )
574 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
575 //movingObj_start.setY( p.y() - selection->y() );
576 movingObj_start.setX( p.x() - lmo->x() );
577 movingObj_start.setY( p.y() - lmo->y() );
578 movingObj_orgPos.setX (lmo->x() );
579 movingObj_orgPos.setY (lmo->y() );
581 movingObj_orgRelPos=lmo->getRelPos();
583 // If modMode==copy, then we want to "move" the _new_ object around
584 // then we need the offset from p to the _old_ selection, because of tmp
585 if (mainWindow->getModMode()==Main::ModModeCopy &&
586 e->state() & Qt::ControlModifier)
588 BranchObj *bo=model->getSelectedBranch();
592 bo->addBranch (model->getSelectedBranch());
594 model->select(bo->getLastBranch());
599 movingObj=model->getSelectedLMO();
601 // Middle Button Toggle Scroll
602 // (On Mac OS X this won't work, but we still have
603 // a button in the toolbar)
604 if (e->button() == Qt::MidButton )
605 model->toggleScroll();
606 // model->updateActions(); FIXME-3 needed?
607 // FIXME-3 needed? xelection.update();
609 { // No MapObj found, we are on the scene itself
610 // Left Button move Pos of sceneView
611 if (e->button() == Qt::LeftButton )
613 movingObj=NULL; // move Content not Obj
614 movingObj_start=e->globalPos();
615 movingCont_start=QPointF (
616 horizontalScrollBar()->value(),
617 verticalScrollBar()->value());
618 movingVec=QPointF(0,0);
619 setCursor(HandOpenCursor);
624 void MapEditor::mouseMoveEvent(QMouseEvent* e)
626 QPointF p = mapToScene(e->pos());
627 LinkableMapObj *lmosel=model->getSelectedLMO();
629 // Move the selected MapObj
630 if ( lmosel && movingObj)
632 // reset cursor if we are moving and don't copy
633 if (mainWindow->getModMode()!=Main::ModModeCopy)
634 setCursor (Qt::ArrowCursor);
636 // To avoid jumping of the sceneView, only
637 // ensureSelectionVisible, if not tmp linked
638 if (!lmosel->hasParObjTmp())
639 model->ensureSelectionVisible ();
641 // Now move the selection, but add relative position
642 // (movingObj_start) where selection was chosen with
643 // mousepointer. (This avoids flickering resp. jumping
644 // of selection back to absPos)
646 // Check if we could link
647 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
650 FloatObj *fio=model->getSelectedFloatImage();
653 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
655 fio->updateLink(); //no need for reposition, if we update link here
656 model->updateSelection(); // position has changed
658 // Relink float to new mapcenter or branch, if shift is pressed
659 // Only relink, if selection really has a new parent
660 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
661 ( (typeid(*lmo)==typeid(BranchObj)) ||
662 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
663 ( lmo != fio->getParObj())
666 if (typeid(*fio) == typeid(FloatImageObj) &&
667 ( (typeid(*lmo)==typeid(BranchObj) ||
668 typeid(*lmo)==typeid(MapCenterObj)) ))
671 // Also save the move which was done so far
672 QString pold=qpointfToString(movingObj_orgRelPos);
673 QString pnow=qpointfToString(fio->getRelPos());
679 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
680 fio->getParObj()->requestReposition();
683 model->linkFloatImageTo (model->getSelectString(lmo));
685 //movingObj_orgRelPos=lmosel->getRelPos();
691 { // selection != a FloatObj
692 if (lmosel->getDepth()==0)
695 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
696 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
698 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
699 model->updateRelPositions();
702 if (lmosel->getDepth()==1)
705 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
709 // Move ordinary branch
710 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
711 // Add width of bbox here, otherwise alignRelTo will cause jumping around
712 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
713 p.y()-movingObj_start.y() +lmosel->getTopPad() );
715 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
719 // Maybe we can relink temporary?
720 if (lmo && (lmo!=lmosel) && model->getSelectedBranch() &&
721 (typeid(*lmo)==typeid(BranchObj) ||
722 typeid(*lmo)==typeid(MapCenterObj)) )
725 if (e->modifiers()==Qt::ControlModifier)
727 // Special case: CTRL to link below lmo
728 lmosel->setParObjTmp (lmo,p,+1);
730 else if (e->modifiers()==Qt::ShiftModifier)
731 lmosel->setParObjTmp (lmo,p,-1);
733 lmosel->setParObjTmp (lmo,p,0);
736 lmosel->unsetParObjTmp();
738 // reposition subbranch
739 lmosel->reposition();
742 QItemSelection sel=model->getSelectionModel()->selection();
743 updateSelection(sel,sel); // position has changed
745 } // no FloatImageObj
749 } // selection && moving_obj
751 // Draw a link from one branch to another
754 tmpXLink->setEnd (p);
755 tmpXLink->updateXLink();
759 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
761 QPointF p=e->globalPos();
762 movingVec.setX(-p.x() + movingObj_start.x() );
763 movingVec.setY(-p.y() + movingObj_start.y() );
764 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
765 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
770 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
772 QPointF p = mapToScene(e->pos());
774 LinkableMapObj *lmosel=model->getSelectedLMO();
775 // Have we been picking color?
779 setCursor (Qt::ArrowCursor);
780 // Check if we are over another branch
781 dst=model->findMapObj(p, NULL);
784 if (e->state() & Qt::ShiftModifier)
785 model->colorBranch (((BranchObj*)dst)->getColor());
787 model->colorSubtree (((BranchObj*)dst)->getColor());
792 // Have we been drawing a link?
796 // Check if we are over another branch
797 dst=model->findMapObj(p, NULL);
800 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
801 tmpXLink->updateXLink();
802 tmpXLink->activate(); //FIXME-2 savestate missing
803 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
812 // Have we been moving something?
813 if ( lmosel && movingObj )
815 FloatImageObj *fo=model->getSelectedFloatImage();
818 // Moved FloatObj. Maybe we need to reposition
819 QString pold=qpointfToString(movingObj_orgRelPos);
820 QString pnow=qpointfToString(fo->getRelPos());
826 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
828 fo->getParObj()->requestReposition();
832 // Check if we are over another branch, but ignore
833 // any found LMOs, which are FloatObjs
834 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
836 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
839 BranchObj *bo=model->getSelectedBranch();
840 if (bo && bo->getDepth()==0)
842 if (movingObj_orgPos != bo->getAbsPos())
844 QString pold=qpointfToString(movingObj_orgPos);
845 QString pnow=qpointfToString(bo->getAbsPos());
851 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bo)).arg(pnow));
855 if (model->selectionType() == TreeItem::Branch )
856 { // A branch was moved
858 // save the position in case we link to mapcenter
859 QPointF savePos=QPointF (lmosel->getAbsPos() );
861 // Reset the temporary drawn link to the original one
862 lmosel->unsetParObjTmp();
864 // For Redo we may need to save original selection
865 QString preSelStr=model->getSelectString(lmosel);
870 // We have a destination, relink to that
872 BranchObj* bsel=model->getSelectedBranch();
873 BranchObj* bdst=(BranchObj*)dst;
875 QString preParStr=model->getSelectString (bsel->getParObj());
876 QString preNum=QString::number (bsel->getNum(),10);
877 QString preDstParStr;
879 if (e->state() & Qt::ShiftModifier && dst->getParObj())
881 preDstParStr=model->getSelectString (dst->getParObj());
882 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
884 if (e->state() & Qt::ControlModifier && dst->getParObj())
887 preDstParStr=model->getSelectString (dst->getParObj());
888 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
891 preDstParStr=model->getSelectString(dst);
892 bsel->linkTo (bdst,-1);
893 if (dst->getDepth()==0) bsel->move (savePos);
895 QString postSelStr=model->getSelectString(lmosel);
896 QString postNum=QString::number (bsel->getNum(),10);
898 QString undoCom="linkTo (\""+
899 preParStr+ "\"," + preNum +"," +
900 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
902 QString redoCom="linkTo (\""+
903 preDstParStr + "\"," + postNum + "," +
904 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
909 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
911 model->reposition(); // not necessary if we undo temporary move below
914 // No destination, undo temporary move
916 if (lmosel->getDepth()==1)
918 // The select string might be different _after_ moving around.
919 // Therefor reposition and then use string of old selection, too
922 QPointF rp(lmosel->getRelPos());
923 if (rp != movingObj_orgRelPos)
925 QString ps=qpointfToString(rp);
927 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
928 preSelStr, "moveRel "+ps,
929 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
933 // Draw the original link, before selection was moved around
934 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
936 lmosel->setRelPos(); // calc relPos first for starting point
937 QPointF dst=bo->getParObj()->getChildPos();
938 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
940 model->startAnimation(
944 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
950 model->updateSelection(); //FIXME-3 needed? at least not after pos of selection has changed...
951 // Finally resize scene, if needed
955 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
956 // model->updateActions(); FIXME-3 neeeded?
958 // maybe we moved View: set old cursor
959 setCursor (Qt::ArrowCursor);
963 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
965 if (model->isSelectionBlocked() )
971 if (e->button() == Qt::LeftButton )
973 QPointF p = mapToScene(e->pos());
974 LinkableMapObj *lmo=model->findMapObj(p, NULL);
975 if (lmo) { // MapObj was found
976 // First select the MapObj than edit heading
983 void MapEditor::resizeEvent (QResizeEvent* e)
985 QGraphicsView::resizeEvent( e );
988 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
990 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
991 // cerr << event->format(i) << endl;
993 if (event->mimeData()->hasImage())
994 event->acceptProposedAction();
996 if (event->mimeData()->hasUrls())
997 event->acceptProposedAction();
1000 void MapEditor::dragMoveEvent(QDragMoveEvent *)
1004 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
1009 void MapEditor::dropEvent(QDropEvent *event)
1011 BranchObj *sel=model->getSelectedBranch();
1015 foreach (QString format,event->mimeData()->formats())
1016 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1020 if (event->mimeData()->hasImage())
1022 QVariant imageData = event->mimeData()->imageData();
1023 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1025 if (event->mimeData()->hasUrls())
1026 uris=event->mimeData()->urls();
1034 for (int i=0; i<uris.count();i++)
1036 // Workaround to avoid adding empty branches
1037 if (!uris.at(i).toString().isEmpty())
1039 bo=sel->addBranch();
1042 s=uris.at(i).toLocalFile();
1045 QString file = QDir::fromNativeSeparators(s);
1046 heading = QFileInfo(file).baseName();
1048 if (file.endsWith(".vym", false))
1049 bo->setVymLink(file);
1051 bo->setURL(uris.at(i).toString());
1054 bo->setURL(uris.at(i).toString());
1057 if (!heading.isEmpty())
1058 bo->setHeading(heading);
1060 bo->setHeading(uris.at(i).toString());
1064 model->reposition();
1067 event->acceptProposedAction();
1070 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1072 // Reduce rectangles
1073 while (newsel.indexes().count() < selboxList.count() )
1074 delete selboxList.takeFirst();
1076 // Add additonal rectangles
1077 QGraphicsRectItem *sb;
1078 while (newsel.indexes().count() > selboxList.count() )
1080 sb = mapScene->addRect(
1082 QPen(selectionColor),
1084 sb->setZValue(Z_SELBOX);
1086 selboxList.append (sb);
1089 // Reposition rectangles
1095 LinkableMapObj *lmo;
1096 foreach (sb,selboxList)
1098 index=newsel.indexes().at(i);
1099 ti= static_cast<TreeItem*>(index.internalPointer());
1101 bbox=lmo->getBBox();
1104 bbox.width(), bbox.height());
1105 sb->setPen (selectionColor);
1106 sb->setBrush (selectionColor);
1111 void MapEditor::updateCurrent (const QModelIndex &,const QModelIndex &) //FIXME-3 not used?
1116 cout << "ME::updateCurrent\n";
1118 TreeItem *item = static_cast<TreeItem*>(newsel.internalPointer());
1119 LinkableMapObj *lmo=item->getLMO();
1120 cout << " lmo="<<lmo<<endl;
1121 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
1126 void MapEditor::setSelectionColor (QColor col)
1129 QItemSelection sel=model->getSelectionModel()->selection();
1130 updateSelection(sel,sel);
1133 QColor MapEditor::getSelectionColor ()
1135 return selectionColor;