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 BranchItem *bi=model->getSelectedBranchItem();
259 /* FIXME-2 isSetStandardFlag needs to be ported
260 if (bi->isSetStandardFlag(f))
273 QString("%1 (\"%2\")").arg(u).arg(f),
275 QString("%1 (\"%2\")").arg(r).arg(f),
276 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(model->getObjectName(bi)));
277 // FIXME-2 bi->toggleStandardFlag (f,mainWindow->useFlagGroups());
278 model->updateSelection(); // geometry has changed
282 AttributeTable* MapEditor::attributeTable()
287 void MapEditor::testFunction1()
289 BranchItem *cur=NULL;
290 BranchItem *prev=NULL;
292 cout << "ME::testFunction1 starting to walk the map...\n";
293 while (model->next (cur,prev,d) )
294 cout << "*** " <<cur->getHeading().toStdString()<<endl;
297 //BranchObj *bo=model->getSelectedBranchObj();
298 //if (bo) model->moveAway (bo);
299 //if (bo) bo->setLinkStyle (LinkableMapObj::Line);
303 // Displacement and animation of all non-mainbranches
312 bo=(BranchObj*)(cur->getLMO());
314 if (cur->depth() >0 && !bo->hasScrolledParent(bo) )
316 p=QPointF (qrand() %600-300, qrand () %600-300);
319 model->startAnimation (bo,p, q);
321 model->next(cur,prev,d);
326 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
327 if (hidemode==HideNone)
329 setHideTmpMode (HideExport);
330 mapCenter->calcBBoxSizeWithChilds();
331 QRectF totalBBox=mapCenter->getTotalBBox();
332 QRectF mapRect=totalBBox;
333 QCanvasRectangle *frame=NULL;
335 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
337 mapRect.setRect (totalBBox.x(), totalBBox.y(),
338 totalBBox.width(), totalBBox.height());
339 frame=new QCanvasRectangle (mapRect,mapScene);
340 frame->setBrush (QColor(white));
341 frame->setPen (QColor(black));
347 setHideTmpMode (HideNone);
349 cout <<" hidemode="<<hidemode<<endl;
353 void MapEditor::testFunction2()
358 if (hidemode==HideExport)
359 setHideTmpMode (HideNone);
361 setHideTmpMode (HideExport);
365 void MapEditor::editHeading()
369 editHeadingFinished();
372 BranchObj *bo=model->getSelectedBranchObj();
373 BranchItem *bi=model->getSelectedBranchItem();
376 model->setSelectionBlocked(true);
378 lineEdit->setText (bi->getHeading());
379 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
380 lineEdit->setGeometry(p.x(),p.y(),230,25);
381 lineEdit->selectAll();
383 lineEdit->setFocus();
384 lineEdit->grabKeyboard();
389 void MapEditor::editHeadingFinished()
391 editingHeading=false;
392 lineEdit->releaseKeyboard();
393 model->setHeading (lineEdit->text() );
394 model->setSelectionBlocked(false);
397 // Maybe reselect previous branch
398 mainWindow->editHeadingFinished (model);
402 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
404 // Lineedits are already closed by preceding
405 // mouseEvent, we don't need to close here.
407 QPointF p = mapToScene(e->pos());
408 LinkableMapObj* lmo=model->findMapObj(p, NULL);
411 { // MapObj was found
412 if (model->getSelectedLMO() != lmo)
418 if (model->getSelectedBranchObj() )
420 // Context Menu on branch or mapcenter
421 //FIXME-3 model->updateActions(); needed?
422 branchContextMenu->popup(e->globalPos() );
425 if (model->getSelectedFloatImage() )
427 // Context Menu on floatimage
428 // model->updateActions(); FIXME-3 needed?
429 floatimageContextMenu->popup(e->globalPos() );
433 { // No MapObj found, we are on the Canvas itself
434 // Context Menu on scene
435 // model->updateActions(); FIXME-3 needed?
437 // Open context menu synchronously to position new mapcenter
438 model->setContextPos (p);
439 canvasContextMenu->exec(e->globalPos() );
440 model->unsetContextPos ();
445 void MapEditor::keyPressEvent(QKeyEvent* e)
447 if (e->modifiers() & Qt::ControlModifier)
449 switch (mainWindow->getModMode())
451 case Main::ModModeColor:
452 setCursor (PickColorCursor);
454 case Main::ModModeCopy:
455 setCursor (CopyCursor);
457 case Main::ModModeXLink:
458 setCursor (XLinkCursor);
461 setCursor (Qt::ArrowCursor);
467 void MapEditor::keyReleaseEvent(QKeyEvent* e)
469 if (!(e->modifiers() & Qt::ControlModifier))
470 setCursor (Qt::ArrowCursor);
473 void MapEditor::mousePressEvent(QMouseEvent* e)
475 // Ignore right clicks, these will go to context menus
476 if (e->button() == Qt::RightButton )
482 //Ignore clicks while editing heading
483 if (model->isSelectionBlocked() )
489 QPointF p = mapToScene(e->pos());
490 LinkableMapObj* lmo=model->findMapObj(p, NULL);
494 //Take care of system flags _or_ modifier modes
496 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
497 typeid(*lmo)==typeid(MapCenterObj) ))
499 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
500 if (!foname.isEmpty())
502 // systemFlag clicked
503 model->select (lmo); // FIXME-3 was selectInt
506 if (e->state() & Qt::ControlModifier)
507 mainWindow->editOpenURLTab();
509 mainWindow->editOpenURL();
511 else if (foname=="vymLink")
513 mainWindow->editOpenVymLink();
514 // tabWidget may change, better return now
515 // before segfaulting...
516 } else if (foname=="note")
517 mainWindow->windowToggleNoteEditor();
518 else if (foname=="hideInExport")
519 model->toggleHideExport();
520 // FIXME-3 needed? xelection.update();
524 // No system flag clicked, take care of modmodes (CTRL-Click)
525 if (e->state() & Qt::ControlModifier)
527 if (mainWindow->getModMode()==Main::ModModeColor)
530 setCursor (PickColorCursor);
533 if (mainWindow->getModMode()==Main::ModModeXLink)
535 BranchObj *bo_begin=NULL;
537 bo_begin=(BranchObj*)(lmo);
539 bo_begin=model->getSelectedBranchObj();
543 linkingObj_src=bo_begin;
544 tmpXLink=new XLinkObj (mapScene);
545 tmpXLink->setBegin (bo_begin);
546 tmpXLink->setEnd (p);
547 tmpXLink->setColor(model->getMapDefXLinkColor());
548 tmpXLink->setWidth(model->getMapDefXLinkWidth());
549 tmpXLink->updateXLink();
550 tmpXLink->setVisibility (true);
559 cout << "ME::mouse pressed\n";
560 cout << " lmo="<<lmo<<endl;
561 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
563 // Select the clicked object
565 // FIXME-2 VM better let "find" return an index instead of lmo...
566 // Get index of clicked LMO
567 TreeItem *ti=lmo->getTreeItem();
569 cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
570 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
572 //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
575 // Left Button Move Branches
576 if (e->button() == Qt::LeftButton )
578 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
579 //movingObj_start.setY( p.y() - selection->y() );
580 movingObj_start.setX( p.x() - lmo->x() );
581 movingObj_start.setY( p.y() - lmo->y() );
582 movingObj_orgPos.setX (lmo->x() );
583 movingObj_orgPos.setY (lmo->y() );
585 movingObj_orgRelPos=lmo->getRelPos();
587 // If modMode==copy, then we want to "move" the _new_ object around
588 // then we need the offset from p to the _old_ selection, because of tmp
589 if (mainWindow->getModMode()==Main::ModModeCopy &&
590 e->state() & Qt::ControlModifier)
592 BranchItem *bi=model->getSelectedBranchItem();
596 //FIXME-2 TreeItem::addBranch (BranchItem still missing)
597 //bi->addBranch (model->getSelectedBranchItem());
599 model->select(bi->getLastBranch());
604 movingObj=model->getSelectedLMO();
606 // Middle Button Toggle Scroll
607 // (On Mac OS X this won't work, but we still have
608 // a button in the toolbar)
609 if (e->button() == Qt::MidButton )
610 model->toggleScroll();
611 // model->updateActions(); FIXME-3 needed?
612 // FIXME-3 needed? xelection.update();
614 { // No MapObj found, we are on the scene itself
615 // Left Button move Pos of sceneView
616 if (e->button() == Qt::LeftButton )
618 movingObj=NULL; // move Content not Obj
619 movingObj_start=e->globalPos();
620 movingCont_start=QPointF (
621 horizontalScrollBar()->value(),
622 verticalScrollBar()->value());
623 movingVec=QPointF(0,0);
624 setCursor(HandOpenCursor);
629 void MapEditor::mouseMoveEvent(QMouseEvent* e)
631 QPointF p = mapToScene(e->pos());
632 LinkableMapObj *lmosel=model->getSelectedLMO();
634 // Move the selected MapObj
635 if ( lmosel && movingObj)
637 // reset cursor if we are moving and don't copy
638 if (mainWindow->getModMode()!=Main::ModModeCopy)
639 setCursor (Qt::ArrowCursor);
641 // To avoid jumping of the sceneView, only
642 // ensureSelectionVisible, if not tmp linked
643 if (!lmosel->hasParObjTmp())
644 model->ensureSelectionVisible ();
646 // Now move the selection, but add relative position
647 // (movingObj_start) where selection was chosen with
648 // mousepointer. (This avoids flickering resp. jumping
649 // of selection back to absPos)
651 // Check if we could link
652 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
655 FloatObj *fio=model->getSelectedFloatImage();
658 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
660 fio->updateLink(); //no need for reposition, if we update link here
661 model->updateSelection(); // position has changed
663 // Relink float to new mapcenter or branch, if shift is pressed
664 // Only relink, if selection really has a new parent
665 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
666 ( (typeid(*lmo)==typeid(BranchObj)) ||
667 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
668 ( lmo != fio->getParObj())
671 if (typeid(*fio) == typeid(FloatImageObj) &&
672 ( (typeid(*lmo)==typeid(BranchObj) ||
673 typeid(*lmo)==typeid(MapCenterObj)) ))
676 // Also save the move which was done so far
677 QString pold=qpointfToString(movingObj_orgRelPos);
678 QString pnow=qpointfToString(fio->getRelPos());
680 fio->getTreeItem(), // FIXME-3
684 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
685 fio->getParObj()->requestReposition();
688 model->linkFloatImageTo (model->getSelectString(lmo));
690 //movingObj_orgRelPos=lmosel->getRelPos();
696 { // selection != a FloatObj
697 if (lmosel->getDepth()==0)
700 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
701 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
703 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
704 model->updateRelPositions();
707 if (lmosel->getDepth()==1)
710 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
714 // Move ordinary branch
715 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
716 // Add width of bbox here, otherwise alignRelTo will cause jumping around
717 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
718 p.y()-movingObj_start.y() +lmosel->getTopPad() );
720 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
724 // Maybe we can relink temporary?
725 if (lmo && (lmo!=lmosel) && model->getSelectedBranchObj() &&
726 (typeid(*lmo)==typeid(BranchObj) ||
727 typeid(*lmo)==typeid(MapCenterObj)) )
730 if (e->modifiers()==Qt::ControlModifier)
732 // Special case: CTRL to link below lmo
733 lmosel->setParObjTmp (lmo,p,+1);
735 else if (e->modifiers()==Qt::ShiftModifier)
736 lmosel->setParObjTmp (lmo,p,-1);
738 lmosel->setParObjTmp (lmo,p,0);
741 lmosel->unsetParObjTmp();
743 // reposition subbranch
744 lmosel->reposition();
747 QItemSelection sel=model->getSelectionModel()->selection();
748 updateSelection(sel,sel); // position has changed
750 } // no FloatImageObj
754 } // selection && moving_obj
756 // Draw a link from one branch to another
759 tmpXLink->setEnd (p);
760 tmpXLink->updateXLink();
764 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
766 QPointF p=e->globalPos();
767 movingVec.setX(-p.x() + movingObj_start.x() );
768 movingVec.setY(-p.y() + movingObj_start.y() );
769 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
770 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
775 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
777 QPointF p = mapToScene(e->pos());
779 LinkableMapObj *lmosel=model->getSelectedLMO();
780 // Have we been picking color?
784 setCursor (Qt::ArrowCursor);
785 // Check if we are over another branch
786 dst=model->findMapObj(p, NULL);
789 if (e->state() & Qt::ShiftModifier)
790 model->colorBranch (((BranchObj*)dst)->getColor());
792 model->colorSubtree (((BranchObj*)dst)->getColor());
797 // Have we been drawing a link?
801 // Check if we are over another branch
802 dst=model->findMapObj(p, NULL);
805 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
806 tmpXLink->updateXLink();
807 tmpXLink->activate(); //FIXME-2 savestate missing
808 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
817 // Have we been moving something?
818 if ( lmosel && movingObj )
820 FloatImageObj *fo=model->getSelectedFloatImage();
823 // Moved FloatObj. Maybe we need to reposition
824 QString pold=qpointfToString(movingObj_orgRelPos);
825 QString pnow=qpointfToString(fo->getRelPos());
827 fo->getTreeItem(), // FIXME-3
829 fo->getTreeItem(), // FIXME-3
831 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
833 fo->getParObj()->requestReposition();
837 // Check if we are over another branch, but ignore
838 // any found LMOs, which are FloatObjs
839 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
841 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
844 BranchItem *bi=model->getSelectedBranchItem();
845 if (bi && bi->depth()==0)
847 if (movingObj_orgPos != bi->getBranchObj()->getAbsPos()) // FIXME-3 check getBO here...
849 QString pold=qpointfToString(movingObj_orgPos);
850 QString pnow=qpointfToString(bi->getBranchObj()->getAbsPos()); // FIXME-3 check getBO here...
857 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
861 if (model->selectionType() == TreeItem::Branch )
862 { // A branch was moved
864 // save the position in case we link to mapcenter
865 QPointF savePos=QPointF (lmosel->getAbsPos() );
867 // Reset the temporary drawn link to the original one
868 lmosel->unsetParObjTmp();
870 // For Redo we may need to save original selection
871 QString preSelStr=model->getSelectString(lmosel);
876 // We have a destination, relink to that
878 BranchObj* bsel=model->getSelectedBranchObj();
879 TreeItem * tisel=model->getSelectedItem();
880 BranchObj* bdst=(BranchObj*)dst;
881 TreeItem* tidst=dst->getTreeItem();
883 QString preParStr=model->getSelectString (bsel->getParObj());
884 QString preNum=QString::number (tisel->num(),10);
885 QString preDstParStr;
887 if (e->state() & Qt::ShiftModifier && dst->getParObj())
889 preDstParStr=model->getSelectString (dst->getParObj());
890 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), tidst->num());
892 if (e->state() & Qt::ControlModifier && dst->getParObj())
895 preDstParStr=model->getSelectString (dst->getParObj());
896 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), tidst->num()+1);
899 preDstParStr=model->getSelectString(dst);
900 bsel->linkTo (bdst,-1);
901 if (dst->getDepth()==0) bsel->move (savePos);
903 QString postSelStr=model->getSelectString(lmosel);
904 QString postNum=QString::number (tisel->num(),10);
906 QString undoCom="linkTo (\""+
907 preParStr+ "\"," + preNum +"," +
908 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
910 QString redoCom="linkTo (\""+
911 preDstParStr + "\"," + postNum + "," +
912 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
917 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
919 model->reposition(); // not necessary if we undo temporary move below
922 // No destination, undo temporary move
924 if (lmosel->getDepth()==1)
926 // The select string might be different _after_ moving around.
927 // Therefor reposition and then use string of old selection, too
930 QPointF rp(lmosel->getRelPos());
931 if (rp != movingObj_orgRelPos)
933 QString ps=qpointfToString(rp);
935 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
936 preSelStr, "moveRel "+ps,
937 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
941 // Draw the original link, before selection was moved around
942 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
944 lmosel->setRelPos(); // calc relPos first for starting point
945 QPointF dst=bi->getBranchObj()->getParObj()->getChildPos(); // FIXME-3 check getBO here...
946 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
948 model->startAnimation(
952 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
958 model->updateSelection(); //FIXME-3 needed? at least not after pos of selection has changed...
959 // Finally resize scene, if needed
963 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
964 // model->updateActions(); FIXME-3 neeeded?
966 // maybe we moved View: set old cursor
967 setCursor (Qt::ArrowCursor);
971 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
973 if (model->isSelectionBlocked() )
979 if (e->button() == Qt::LeftButton )
981 QPointF p = mapToScene(e->pos());
982 LinkableMapObj *lmo=model->findMapObj(p, NULL);
983 if (lmo) { // MapObj was found
984 // First select the MapObj than edit heading
991 void MapEditor::resizeEvent (QResizeEvent* e)
993 QGraphicsView::resizeEvent( e );
996 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
998 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
999 // cerr << event->format(i) << endl;
1001 if (event->mimeData()->hasImage())
1002 event->acceptProposedAction();
1004 if (event->mimeData()->hasUrls())
1005 event->acceptProposedAction();
1008 void MapEditor::dragMoveEvent(QDragMoveEvent *)
1012 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
1017 void MapEditor::dropEvent(QDropEvent *event)
1019 BranchItem *selbi=model->getSelectedBranchItem();
1023 foreach (QString format,event->mimeData()->formats())
1024 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1028 if (event->mimeData()->hasImage())
1030 QVariant imageData = event->mimeData()->imageData();
1031 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1033 if (event->mimeData()->hasUrls())
1034 uris=event->mimeData()->urls();
1042 for (int i=0; i<uris.count();i++)
1044 // Workaround to avoid adding empty branches
1045 if (!uris.at(i).toString().isEmpty())
1047 bi=model->createBranch();
1051 s=uris.at(i).toLocalFile();
1054 QString file = QDir::fromNativeSeparators(s);
1055 heading = QFileInfo(file).baseName();
1057 if (file.endsWith(".vym", false))
1058 bi->setVymLink(file);
1060 bi->setURL(uris.at(i).toString());
1063 bo->setURL(uris.at(i).toString());
1067 if (!heading.isEmpty())
1068 bi->setHeading(heading);
1070 bi->setHeading(uris.at(i).toString());
1075 model->reposition();
1078 event->acceptProposedAction();
1081 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1083 // Reduce rectangles
1084 while (newsel.indexes().count() < selboxList.count() )
1085 delete selboxList.takeFirst();
1087 // Add additonal rectangles
1088 QGraphicsRectItem *sb;
1089 while (newsel.indexes().count() > selboxList.count() )
1091 sb = mapScene->addRect(
1093 QPen(selectionColor),
1095 sb->setZValue(Z_SELBOX);
1097 selboxList.append (sb);
1100 // Reposition rectangles
1106 LinkableMapObj *lmo;
1107 foreach (sb,selboxList)
1109 index=newsel.indexes().at(i);
1110 ti= static_cast<TreeItem*>(index.internalPointer());
1112 bbox=lmo->getBBox();
1115 bbox.width(), bbox.height());
1116 sb->setPen (selectionColor);
1117 sb->setBrush (selectionColor);
1122 void MapEditor::updateData (const QModelIndex &sel)
1124 TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
1127 cout << "ME::updateData\n";
1129 cout << " ti="<<ti<<endl;
1130 cout << " h="<<ti->getHeading().toStdString()<<endl;
1133 if (ti->isBranchLikeType())
1135 BranchObj *bo=(BranchObj*)ti->getLMO();
1136 bo->updateHeading();
1141 void MapEditor::setSelectionColor (QColor col)
1144 QItemSelection sel=model->getSelectionModel()->selection();
1145 updateSelection(sel,sel);
1149 QColor MapEditor::getSelectionColor ()
1151 return selectionColor;