9 #include "branchitem.h"
10 #include "mainwindow.h"
12 #include "warningdialog.h"
15 extern int statusbarTime;
16 extern Main *mainWindow;
17 extern QString tmpVymDir;
18 extern QString clipboardDir;
19 extern QString clipboardFile;
20 extern bool clipboardEmpty;
22 extern FlagRowObj *standardFlagsDefault;
24 extern QMenu* branchContextMenu;
25 extern QMenu* branchAddContextMenu;
26 extern QMenu* branchRemoveContextMenu;
27 extern QMenu* branchLinksContextMenu;
28 extern QMenu* branchXLinksContextMenuEdit;
29 extern QMenu* branchXLinksContextMenuFollow;
30 extern QMenu* floatimageContextMenu;
31 extern QMenu* canvasContextMenu;
33 extern Settings settings;
34 extern QString iconPath;
36 ///////////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////////
38 MapEditor::MapEditor( VymModel *vm)
40 //cout << "Constructor ME "<<this<<endl;
41 mapScene= new QGraphicsScene(NULL);
42 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
45 model->setScene (mapScene);
46 model->registerEditor(this);
47 // model->addMapCenter(); // FIXME-3 create this in MapEditor until BO and MCO are independent of scene
48 model->makeDefault(); // No changes in model so far
54 // Create bitmap cursors, platform dependant
55 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
56 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
57 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
58 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
60 setFocusPolicy (Qt::StrongFocus);
72 setAcceptDrops (true);
74 //model->reposition(); //FIXME-3 really still needed?
77 // Action to embed LineEdit for heading in Scene
79 lineEdit=new QLineEdit;
81 QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
84 QAction *a = new QAction( tr( "Edit heading","MapEditor" ), this);
85 a->setShortcut ( Qt::Key_Return ); //Edit heading
87 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
88 a = new QAction( tr( "Edit heading","MapEditor" ), this);
89 a->setShortcut ( Qt::Key_Enter); //Edit heading
91 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
94 selectionColor =QColor (255,255,0);
97 // Attributes //FIXME-2 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 for "<<model->getMapName().toStdString()<<endl;
133 // No need to remove tmp files:
134 // tmpMapDir is in tmpVymDir,
135 // so it gets removed automagically when vym closes
137 model->unregisterEditor(this);
140 VymModel* MapEditor::getModel()
145 QGraphicsScene * MapEditor::getScene()
150 void MapEditor::print()
154 printer = new QPrinter;
155 printer->setColorMode (QPrinter::Color);
156 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
157 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
158 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
161 QRectF totalBBox=model->getTotalBBox();
163 // Try to set orientation automagically
164 // Note: Interpretation of generated postscript is amibiguous, if
165 // there are problems with landscape mode, see
166 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
168 if (totalBBox.width()>totalBBox.height())
169 // recommend landscape
170 printer->setOrientation (QPrinter::Landscape);
172 // recommend portrait
173 printer->setOrientation (QPrinter::Portrait);
175 if ( printer->setup(this) )
176 // returns false, if printing is canceled
178 QPainter pp(printer);
180 pp.setRenderHint(QPainter::Antialiasing,true);
182 // Don't print the visualisation of selection
185 QRectF mapRect=totalBBox;
186 QGraphicsRectItem *frame=NULL;
190 // Print frame around map
191 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
192 totalBBox.width()+20, totalBBox.height()+20);
193 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
199 double paperAspect = (double)printer->width() / (double)printer->height();
200 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
202 if (mapAspect>=paperAspect)
204 // Fit horizontally to paper width
205 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
206 viewBottom=(int)(printer->width()/mapAspect);
209 // Fit vertically to paper height
210 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
211 viewBottom=printer->height();
216 // Print footer below map
218 font.setPointSize(10);
220 QRectF footerBox(0,viewBottom,printer->width(),15);
221 // FIXME-3 fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
222 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
226 QRectF (0,0,printer->width(),printer->height()-15),
227 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
230 // Viewport has paper dimension
231 if (frame) delete (frame);
236 // Save settings in vymrc
237 settings.writeEntry("/mainwindow/printerName",printer->printerName());
238 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
239 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
243 void MapEditor::setAntiAlias (bool b)
245 setRenderHint(QPainter::Antialiasing,b);
248 void MapEditor::setSmoothPixmap(bool b)
250 setRenderHint(QPainter::SmoothPixmapTransform,b);
253 void MapEditor::toggleStandardFlag(QString f)
255 BranchObj *bo=model->getSelectedBranch();
259 if (bo->isSetStandardFlag(f))
271 QString("%1 (\"%2\")").arg(u).arg(f),
273 QString("%1 (\"%2\")").arg(r).arg(f),
274 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(model->getObjectName(bo)));
275 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
276 model->updateSelection(); // geometry has changed
280 AttributeTable* MapEditor::attributeTable()
285 void MapEditor::testFunction1()
287 BranchItem *cur=NULL;
288 BranchItem *prev=NULL;
290 cout << "ME::testFunction1 starting to walk the map...\n";
291 while (model->next (cur,prev,d) )
292 cout << "*** " <<cur->getHeading().toStdString()<<endl;
295 //BranchObj *bo=model->getSelectedBranch();
296 //if (bo) model->moveAway (bo);
297 //if (bo) bo->setLinkStyle (LinkableMapObj::Line);
301 // Displacement and animation of all non-mainbranches
310 bo=(BranchObj*)(cur->getLMO());
312 if (cur->depth() >0 && !bo->hasScrolledParent(bo) )
314 p=QPointF (qrand() %600-300, qrand () %600-300);
317 model->startAnimation (bo,p, q);
319 model->next(cur,prev,d);
324 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
325 if (hidemode==HideNone)
327 setHideTmpMode (HideExport);
328 mapCenter->calcBBoxSizeWithChilds();
329 QRectF totalBBox=mapCenter->getTotalBBox();
330 QRectF mapRect=totalBBox;
331 QCanvasRectangle *frame=NULL;
333 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
335 mapRect.setRect (totalBBox.x(), totalBBox.y(),
336 totalBBox.width(), totalBBox.height());
337 frame=new QCanvasRectangle (mapRect,mapScene);
338 frame->setBrush (QColor(white));
339 frame->setPen (QColor(black));
345 setHideTmpMode (HideNone);
347 cout <<" hidemode="<<hidemode<<endl;
351 void MapEditor::testFunction2()
356 if (hidemode==HideExport)
357 setHideTmpMode (HideNone);
359 setHideTmpMode (HideExport);
363 void MapEditor::editHeading()
367 editHeadingFinished();
370 BranchObj *bo=model->getSelectedBranch();
373 model->setSelectionBlocked(true);
375 lineEdit->setText (bo->getHeading());
376 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
377 lineEdit->setGeometry(p.x(),p.y(),230,25);
378 lineEdit->selectAll();
380 lineEdit->setFocus();
381 lineEdit->grabKeyboard();
386 void MapEditor::editHeadingFinished()
388 editingHeading=false;
389 lineEdit->releaseKeyboard();
390 model->setHeading (lineEdit->text() );
391 model->setSelectionBlocked(false);
394 // Maybe reselect previous branch
395 mainWindow->editHeadingFinished (model);
399 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
401 // Lineedits are already closed by preceding
402 // mouseEvent, we don't need to close here.
404 QPointF p = mapToScene(e->pos());
405 LinkableMapObj* lmo=model->findMapObj(p, NULL);
408 { // MapObj was found
409 if (model->getSelectedLMO() != lmo)
415 if (model->getSelectedBranch() )
417 // Context Menu on branch or mapcenter
418 //FIXME-3 model->updateActions(); needed?
419 branchContextMenu->popup(e->globalPos() );
422 if (model->getSelectedFloatImage() )
424 // Context Menu on floatimage
425 // model->updateActions(); FIXME-3 needed?
426 floatimageContextMenu->popup(e->globalPos() );
430 { // No MapObj found, we are on the Canvas itself
431 // Context Menu on scene
432 // model->updateActions(); FIXME-3 needed?
434 // Open context menu synchronously to position new mapcenter
435 model->setContextPos (p);
436 canvasContextMenu->exec(e->globalPos() );
437 model->unsetContextPos ();
442 void MapEditor::keyPressEvent(QKeyEvent* e)
444 if (e->modifiers() & Qt::ControlModifier)
446 switch (mainWindow->getModMode())
448 case Main::ModModeColor:
449 setCursor (PickColorCursor);
451 case Main::ModModeCopy:
452 setCursor (CopyCursor);
454 case Main::ModModeXLink:
455 setCursor (XLinkCursor);
458 setCursor (Qt::ArrowCursor);
464 void MapEditor::keyReleaseEvent(QKeyEvent* e)
466 if (!(e->modifiers() & Qt::ControlModifier))
467 setCursor (Qt::ArrowCursor);
470 void MapEditor::mousePressEvent(QMouseEvent* e)
472 // Ignore right clicks, these will go to context menus
473 if (e->button() == Qt::RightButton )
479 //Ignore clicks while editing heading
480 if (model->isSelectionBlocked() )
486 QPointF p = mapToScene(e->pos());
487 LinkableMapObj* lmo=model->findMapObj(p, NULL);
491 //Take care of system flags _or_ modifier modes
493 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
494 typeid(*lmo)==typeid(MapCenterObj) ))
496 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
497 if (!foname.isEmpty())
499 // systemFlag clicked
500 model->select (lmo); // FIXME-3 was selectInt
503 if (e->state() & Qt::ControlModifier)
504 mainWindow->editOpenURLTab();
506 mainWindow->editOpenURL();
508 else if (foname=="vymLink")
510 mainWindow->editOpenVymLink();
511 // tabWidget may change, better return now
512 // before segfaulting...
513 } else if (foname=="note")
514 mainWindow->windowToggleNoteEditor();
515 else if (foname=="hideInExport")
516 model->toggleHideExport();
517 // FIXME-3 needed? xelection.update();
521 // No system flag clicked, take care of modmodes (CTRL-Click)
522 if (e->state() & Qt::ControlModifier)
524 if (mainWindow->getModMode()==Main::ModModeColor)
527 setCursor (PickColorCursor);
530 if (mainWindow->getModMode()==Main::ModModeXLink)
532 BranchObj *bo_begin=NULL;
534 bo_begin=(BranchObj*)(lmo);
536 bo_begin=model->getSelectedBranch();
540 linkingObj_src=bo_begin;
541 tmpXLink=new XLinkObj (mapScene);
542 tmpXLink->setBegin (bo_begin);
543 tmpXLink->setEnd (p);
544 tmpXLink->setColor(model->getMapDefXLinkColor());
545 tmpXLink->setWidth(model->getMapDefXLinkWidth());
546 tmpXLink->updateXLink();
547 tmpXLink->setVisibility (true);
556 cout << "ME::mouse pressed\n";
557 cout << " lmo="<<lmo<<endl;
558 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
560 // Select the clicked object
562 // FIXME-2 VM better let "find" return an index instead of lmo...
563 // Get index of clicked LMO
564 TreeItem *ti=lmo->getTreeItem();
566 cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
567 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
569 //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
572 // Left Button Move Branches
573 if (e->button() == Qt::LeftButton )
575 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
576 //movingObj_start.setY( p.y() - selection->y() );
577 movingObj_start.setX( p.x() - lmo->x() );
578 movingObj_start.setY( p.y() - lmo->y() );
579 movingObj_orgPos.setX (lmo->x() );
580 movingObj_orgPos.setY (lmo->y() );
582 movingObj_orgRelPos=lmo->getRelPos();
584 // If modMode==copy, then we want to "move" the _new_ object around
585 // then we need the offset from p to the _old_ selection, because of tmp
586 if (mainWindow->getModMode()==Main::ModModeCopy &&
587 e->state() & Qt::ControlModifier)
589 BranchItem *bi=model->getSelectedBranchItem();
593 //FIXME-2 TreeItem::addBranch (BranchItem still missing)
594 //bi->addBranch (model->getSelectedBranchItem());
596 model->select(bi->getLastBranch());
601 movingObj=model->getSelectedLMO();
603 // Middle Button Toggle Scroll
604 // (On Mac OS X this won't work, but we still have
605 // a button in the toolbar)
606 if (e->button() == Qt::MidButton )
607 model->toggleScroll();
608 // model->updateActions(); FIXME-3 needed?
609 // FIXME-3 needed? xelection.update();
611 { // No MapObj found, we are on the scene itself
612 // Left Button move Pos of sceneView
613 if (e->button() == Qt::LeftButton )
615 movingObj=NULL; // move Content not Obj
616 movingObj_start=e->globalPos();
617 movingCont_start=QPointF (
618 horizontalScrollBar()->value(),
619 verticalScrollBar()->value());
620 movingVec=QPointF(0,0);
621 setCursor(HandOpenCursor);
626 void MapEditor::mouseMoveEvent(QMouseEvent* e)
628 QPointF p = mapToScene(e->pos());
629 LinkableMapObj *lmosel=model->getSelectedLMO();
631 // Move the selected MapObj
632 if ( lmosel && movingObj)
634 // reset cursor if we are moving and don't copy
635 if (mainWindow->getModMode()!=Main::ModModeCopy)
636 setCursor (Qt::ArrowCursor);
638 // To avoid jumping of the sceneView, only
639 // ensureSelectionVisible, if not tmp linked
640 if (!lmosel->hasParObjTmp())
641 model->ensureSelectionVisible ();
643 // Now move the selection, but add relative position
644 // (movingObj_start) where selection was chosen with
645 // mousepointer. (This avoids flickering resp. jumping
646 // of selection back to absPos)
648 // Check if we could link
649 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
652 FloatObj *fio=model->getSelectedFloatImage();
655 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
657 fio->updateLink(); //no need for reposition, if we update link here
658 model->updateSelection(); // position has changed
660 // Relink float to new mapcenter or branch, if shift is pressed
661 // Only relink, if selection really has a new parent
662 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
663 ( (typeid(*lmo)==typeid(BranchObj)) ||
664 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
665 ( lmo != fio->getParObj())
668 if (typeid(*fio) == typeid(FloatImageObj) &&
669 ( (typeid(*lmo)==typeid(BranchObj) ||
670 typeid(*lmo)==typeid(MapCenterObj)) ))
673 // Also save the move which was done so far
674 QString pold=qpointfToString(movingObj_orgRelPos);
675 QString pnow=qpointfToString(fio->getRelPos());
681 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
682 fio->getParObj()->requestReposition();
685 model->linkFloatImageTo (model->getSelectString(lmo));
687 //movingObj_orgRelPos=lmosel->getRelPos();
693 { // selection != a FloatObj
694 if (lmosel->getDepth()==0)
697 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
698 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
700 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
701 model->updateRelPositions();
704 if (lmosel->getDepth()==1)
707 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
711 // Move ordinary branch
712 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
713 // Add width of bbox here, otherwise alignRelTo will cause jumping around
714 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
715 p.y()-movingObj_start.y() +lmosel->getTopPad() );
717 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
721 // Maybe we can relink temporary?
722 if (lmo && (lmo!=lmosel) && model->getSelectedBranch() &&
723 (typeid(*lmo)==typeid(BranchObj) ||
724 typeid(*lmo)==typeid(MapCenterObj)) )
727 if (e->modifiers()==Qt::ControlModifier)
729 // Special case: CTRL to link below lmo
730 lmosel->setParObjTmp (lmo,p,+1);
732 else if (e->modifiers()==Qt::ShiftModifier)
733 lmosel->setParObjTmp (lmo,p,-1);
735 lmosel->setParObjTmp (lmo,p,0);
738 lmosel->unsetParObjTmp();
740 // reposition subbranch
741 lmosel->reposition();
744 QItemSelection sel=model->getSelectionModel()->selection();
745 updateSelection(sel,sel); // position has changed
747 } // no FloatImageObj
751 } // selection && moving_obj
753 // Draw a link from one branch to another
756 tmpXLink->setEnd (p);
757 tmpXLink->updateXLink();
761 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
763 QPointF p=e->globalPos();
764 movingVec.setX(-p.x() + movingObj_start.x() );
765 movingVec.setY(-p.y() + movingObj_start.y() );
766 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
767 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
772 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
774 QPointF p = mapToScene(e->pos());
776 LinkableMapObj *lmosel=model->getSelectedLMO();
777 // Have we been picking color?
781 setCursor (Qt::ArrowCursor);
782 // Check if we are over another branch
783 dst=model->findMapObj(p, NULL);
786 if (e->state() & Qt::ShiftModifier)
787 model->colorBranch (((BranchObj*)dst)->getColor());
789 model->colorSubtree (((BranchObj*)dst)->getColor());
794 // Have we been drawing a link?
798 // Check if we are over another branch
799 dst=model->findMapObj(p, NULL);
802 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
803 tmpXLink->updateXLink();
804 tmpXLink->activate(); //FIXME-2 savestate missing
805 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
814 // Have we been moving something?
815 if ( lmosel && movingObj )
817 FloatImageObj *fo=model->getSelectedFloatImage();
820 // Moved FloatObj. Maybe we need to reposition
821 QString pold=qpointfToString(movingObj_orgRelPos);
822 QString pnow=qpointfToString(fo->getRelPos());
828 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
830 fo->getParObj()->requestReposition();
834 // Check if we are over another branch, but ignore
835 // any found LMOs, which are FloatObjs
836 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
838 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
841 BranchObj *bo=model->getSelectedBranch();
842 if (bo && bo->getDepth()==0)
844 if (movingObj_orgPos != bo->getAbsPos())
846 QString pold=qpointfToString(movingObj_orgPos);
847 QString pnow=qpointfToString(bo->getAbsPos());
853 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bo)).arg(pnow));
857 if (model->selectionType() == TreeItem::Branch )
858 { // A branch was moved
860 // save the position in case we link to mapcenter
861 QPointF savePos=QPointF (lmosel->getAbsPos() );
863 // Reset the temporary drawn link to the original one
864 lmosel->unsetParObjTmp();
866 // For Redo we may need to save original selection
867 QString preSelStr=model->getSelectString(lmosel);
872 // We have a destination, relink to that
874 BranchObj* bsel=model->getSelectedBranch();
875 TreeItem * tisel=model->getSelectedItem();
876 BranchObj* bdst=(BranchObj*)dst;
877 TreeItem* tidst=dst->getTreeItem();
879 QString preParStr=model->getSelectString (bsel->getParObj());
880 QString preNum=QString::number (tisel->num(),10);
881 QString preDstParStr;
883 if (e->state() & Qt::ShiftModifier && dst->getParObj())
885 preDstParStr=model->getSelectString (dst->getParObj());
886 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), tidst->num());
888 if (e->state() & Qt::ControlModifier && dst->getParObj())
891 preDstParStr=model->getSelectString (dst->getParObj());
892 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), tidst->num()+1);
895 preDstParStr=model->getSelectString(dst);
896 bsel->linkTo (bdst,-1);
897 if (dst->getDepth()==0) bsel->move (savePos);
899 QString postSelStr=model->getSelectString(lmosel);
900 QString postNum=QString::number (tisel->num(),10);
902 QString undoCom="linkTo (\""+
903 preParStr+ "\"," + preNum +"," +
904 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
906 QString redoCom="linkTo (\""+
907 preDstParStr + "\"," + postNum + "," +
908 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
913 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
915 model->reposition(); // not necessary if we undo temporary move below
918 // No destination, undo temporary move
920 if (lmosel->getDepth()==1)
922 // The select string might be different _after_ moving around.
923 // Therefor reposition and then use string of old selection, too
926 QPointF rp(lmosel->getRelPos());
927 if (rp != movingObj_orgRelPos)
929 QString ps=qpointfToString(rp);
931 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
932 preSelStr, "moveRel "+ps,
933 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
937 // Draw the original link, before selection was moved around
938 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
940 lmosel->setRelPos(); // calc relPos first for starting point
941 QPointF dst=bo->getParObj()->getChildPos();
942 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
944 model->startAnimation(
948 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
954 model->updateSelection(); //FIXME-3 needed? at least not after pos of selection has changed...
955 // Finally resize scene, if needed
959 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
960 // model->updateActions(); FIXME-3 neeeded?
962 // maybe we moved View: set old cursor
963 setCursor (Qt::ArrowCursor);
967 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
969 if (model->isSelectionBlocked() )
975 if (e->button() == Qt::LeftButton )
977 QPointF p = mapToScene(e->pos());
978 LinkableMapObj *lmo=model->findMapObj(p, NULL);
979 if (lmo) { // MapObj was found
980 // First select the MapObj than edit heading
987 void MapEditor::resizeEvent (QResizeEvent* e)
989 QGraphicsView::resizeEvent( e );
992 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
994 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
995 // cerr << event->format(i) << endl;
997 if (event->mimeData()->hasImage())
998 event->acceptProposedAction();
1000 if (event->mimeData()->hasUrls())
1001 event->acceptProposedAction();
1004 void MapEditor::dragMoveEvent(QDragMoveEvent *)
1008 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
1013 void MapEditor::dropEvent(QDropEvent *event)
1015 BranchObj *sel=model->getSelectedBranch();
1019 foreach (QString format,event->mimeData()->formats())
1020 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1024 if (event->mimeData()->hasImage())
1026 QVariant imageData = event->mimeData()->imageData();
1027 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1029 if (event->mimeData()->hasUrls())
1030 uris=event->mimeData()->urls();
1038 for (int i=0; i<uris.count();i++)
1040 // Workaround to avoid adding empty branches
1041 if (!uris.at(i).toString().isEmpty())
1043 bo=sel->addBranch();
1046 s=uris.at(i).toLocalFile();
1049 QString file = QDir::fromNativeSeparators(s);
1050 heading = QFileInfo(file).baseName();
1052 if (file.endsWith(".vym", false))
1053 bo->setVymLink(file);
1055 bo->setURL(uris.at(i).toString());
1058 bo->setURL(uris.at(i).toString());
1061 if (!heading.isEmpty())
1062 bo->setHeading(heading);
1064 bo->setHeading(uris.at(i).toString());
1068 model->reposition();
1071 event->acceptProposedAction();
1074 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1076 // Reduce rectangles
1077 while (newsel.indexes().count() < selboxList.count() )
1078 delete selboxList.takeFirst();
1080 // Add additonal rectangles
1081 QGraphicsRectItem *sb;
1082 while (newsel.indexes().count() > selboxList.count() )
1084 sb = mapScene->addRect(
1086 QPen(selectionColor),
1088 sb->setZValue(Z_SELBOX);
1090 selboxList.append (sb);
1093 // Reposition rectangles
1099 LinkableMapObj *lmo;
1100 foreach (sb,selboxList)
1102 index=newsel.indexes().at(i);
1103 ti= static_cast<TreeItem*>(index.internalPointer());
1105 bbox=lmo->getBBox();
1108 bbox.width(), bbox.height());
1109 sb->setPen (selectionColor);
1110 sb->setBrush (selectionColor);
1115 void MapEditor::updateCurrent (const QModelIndex &,const QModelIndex &) //FIXME-3 not used?
1120 cout << "ME::updateCurrent\n";
1122 TreeItem *item = static_cast<TreeItem*>(newsel.internalPointer());
1123 LinkableMapObj *lmo=item->getLMO();
1124 cout << " lmo="<<lmo<<endl;
1125 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
1130 void MapEditor::setSelectionColor (QColor col)
1133 QItemSelection sel=model->getSelectionModel()->selection();
1134 updateSelection(sel,sel);
1137 QColor MapEditor::getSelectionColor ()
1139 return selectionColor;