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 TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
284 // Start with mapcenter, no images allowed at rootItem
286 BranchItem *bi=model->getRootItem()->getFirstBranch();
287 TreeItem *found=NULL;
290 found=bi->findMapItem (p, exclude);
291 if (found) return found;
293 bi=model->getRootItem()->getBranchNum(i);
298 AttributeTable* MapEditor::attributeTable()
303 void MapEditor::testFunction1()
305 BranchItem *cur=NULL;
306 BranchItem *prev=NULL;
308 cout << "ME::testFunction1 starting to walk the map...\n";
309 while (model->next (cur,prev,d) )
310 cout << "*** " <<cur->getHeading().toStdString()<<endl;
313 //BranchObj *bo=model->getSelectedBranchObj();
314 //if (bo) model->moveAway (bo);
315 //if (bo) bo->setLinkStyle (LinkableMapObj::Line);
319 // Displacement and animation of all non-mainbranches
328 bo=(BranchObj*)(cur->getLMO());
330 if (cur->depth() >0 && !bo->hasScrolledParent(bo) )
332 p=QPointF (qrand() %600-300, qrand () %600-300);
335 model->startAnimation (bo,p, q);
337 model->next(cur,prev,d);
342 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
343 if (hidemode==HideNone)
345 setHideTmpMode (HideExport);
346 mapCenter->calcBBoxSizeWithChilds();
347 QRectF totalBBox=mapCenter->getTotalBBox();
348 QRectF mapRect=totalBBox;
349 QCanvasRectangle *frame=NULL;
351 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
353 mapRect.setRect (totalBBox.x(), totalBBox.y(),
354 totalBBox.width(), totalBBox.height());
355 frame=new QCanvasRectangle (mapRect,mapScene);
356 frame->setBrush (QColor(white));
357 frame->setPen (QColor(black));
363 setHideTmpMode (HideNone);
365 cout <<" hidemode="<<hidemode<<endl;
369 void MapEditor::testFunction2()
374 if (hidemode==HideExport)
375 setHideTmpMode (HideNone);
377 setHideTmpMode (HideExport);
381 void MapEditor::editHeading()
385 editHeadingFinished();
388 BranchObj *bo=model->getSelectedBranchObj();
389 BranchItem *bi=model->getSelectedBranchItem();
392 model->setSelectionBlocked(true);
394 lineEdit->setText (bi->getHeading());
395 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
396 lineEdit->setGeometry(p.x(),p.y(),230,25);
397 lineEdit->selectAll();
399 lineEdit->setFocus();
400 lineEdit->grabKeyboard();
405 void MapEditor::editHeadingFinished()
407 editingHeading=false;
408 lineEdit->releaseKeyboard();
409 model->setHeading (lineEdit->text() );
410 model->setSelectionBlocked(false);
413 // Maybe reselect previous branch
414 mainWindow->editHeadingFinished (model);
418 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
420 // Lineedits are already closed by preceding
421 // mouseEvent, we don't need to close here.
423 QPointF p = mapToScene(e->pos());
424 TreeItem *ti=findMapItem (p, NULL);
425 LinkableMapObj* lmo=NULL;
426 if (ti) lmo=ti->getLMO(); //FIXME-2 get rid of lmo...
429 { // MapObj was found
430 if (model->getSelectedLMO() != lmo)
436 if (model->getSelectedBranchObj() )
438 // Context Menu on branch or mapcenter
439 //FIXME-3 model->updateActions(); needed?
440 branchContextMenu->popup(e->globalPos() );
443 if (model->getSelectedFloatImage() )
445 // Context Menu on floatimage
446 // model->updateActions(); FIXME-3 needed?
447 floatimageContextMenu->popup(e->globalPos() );
451 { // No MapObj found, we are on the Canvas itself
452 // Context Menu on scene
453 // model->updateActions(); FIXME-3 needed?
455 // Open context menu synchronously to position new mapcenter
456 model->setContextPos (p);
457 canvasContextMenu->exec(e->globalPos() );
458 model->unsetContextPos ();
463 void MapEditor::keyPressEvent(QKeyEvent* e)
465 if (e->modifiers() & Qt::ControlModifier)
467 switch (mainWindow->getModMode())
469 case Main::ModModeColor:
470 setCursor (PickColorCursor);
472 case Main::ModModeCopy:
473 setCursor (CopyCursor);
475 case Main::ModModeXLink:
476 setCursor (XLinkCursor);
479 setCursor (Qt::ArrowCursor);
485 void MapEditor::keyReleaseEvent(QKeyEvent* e)
487 if (!(e->modifiers() & Qt::ControlModifier))
488 setCursor (Qt::ArrowCursor);
491 void MapEditor::mousePressEvent(QMouseEvent* e)
493 // Ignore right clicks, these will go to context menus
494 if (e->button() == Qt::RightButton )
500 //Ignore clicks while editing heading
501 if (model->isSelectionBlocked() )
507 QPointF p = mapToScene(e->pos());
508 TreeItem *ti=findMapItem (p, NULL);
509 LinkableMapObj* lmo=NULL;
510 if (ti) lmo=ti->getLMO(); //FIXME-2 get rid of lmo...
514 //Take care of system flags _or_ modifier modes
516 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
517 typeid(*lmo)==typeid(MapCenterObj) ))
519 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
520 if (!foname.isEmpty())
522 // systemFlag clicked
523 model->select (lmo); // FIXME-3 was selectInt
526 if (e->state() & Qt::ControlModifier)
527 mainWindow->editOpenURLTab();
529 mainWindow->editOpenURL();
531 else if (foname=="vymLink")
533 mainWindow->editOpenVymLink();
534 // tabWidget may change, better return now
535 // before segfaulting...
536 } else if (foname=="note")
537 mainWindow->windowToggleNoteEditor();
538 else if (foname=="hideInExport")
539 model->toggleHideExport();
540 // FIXME-3 needed? xelection.update();
544 // No system flag clicked, take care of modmodes (CTRL-Click)
545 if (e->state() & Qt::ControlModifier)
547 if (mainWindow->getModMode()==Main::ModModeColor)
550 setCursor (PickColorCursor);
553 if (mainWindow->getModMode()==Main::ModModeXLink)
555 BranchObj *bo_begin=NULL;
557 bo_begin=(BranchObj*)(lmo);
559 bo_begin=model->getSelectedBranchObj();
563 linkingObj_src=bo_begin;
564 tmpXLink=new XLinkObj (mapScene);
565 tmpXLink->setBegin (bo_begin);
566 tmpXLink->setEnd (p);
567 tmpXLink->setColor(model->getMapDefXLinkColor());
568 tmpXLink->setWidth(model->getMapDefXLinkWidth());
569 tmpXLink->updateXLink();
570 tmpXLink->setVisibility (true);
579 cout << "ME::mouse pressed\n";
580 cout << " lmo="<<lmo<<endl;
581 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
583 // Select the clicked object
585 // FIXME-2 VM better let "find" return an index instead of lmo...
586 // Get index of clicked LMO
587 TreeItem *ti=lmo->getTreeItem();
589 cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
590 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
592 //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
595 // Left Button Move Branches
596 if (e->button() == Qt::LeftButton )
598 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
599 //movingObj_start.setY( p.y() - selection->y() );
600 movingObj_start.setX( p.x() - lmo->x() );
601 movingObj_start.setY( p.y() - lmo->y() );
602 movingObj_orgPos.setX (lmo->x() );
603 movingObj_orgPos.setY (lmo->y() );
605 movingObj_orgRelPos=lmo->getRelPos();
607 // If modMode==copy, then we want to "move" the _new_ object around
608 // then we need the offset from p to the _old_ selection, because of tmp
609 if (mainWindow->getModMode()==Main::ModModeCopy &&
610 e->state() & Qt::ControlModifier)
612 BranchItem *bi=model->getSelectedBranchItem();
616 //FIXME-2 TreeItem::addBranch (BranchItem still missing)
617 //bi->addBranch (model->getSelectedBranchItem());
619 model->select(bi->getLastBranch());
624 movingObj=model->getSelectedLMO();
626 // Middle Button Toggle Scroll
627 // (On Mac OS X this won't work, but we still have
628 // a button in the toolbar)
629 if (e->button() == Qt::MidButton )
630 model->toggleScroll();
631 // model->updateActions(); FIXME-3 needed?
632 // FIXME-3 needed? xelection.update();
634 { // No MapObj found, we are on the scene itself
635 // Left Button move Pos of sceneView
636 if (e->button() == Qt::LeftButton )
638 movingObj=NULL; // move Content not Obj
639 movingObj_start=e->globalPos();
640 movingCont_start=QPointF (
641 horizontalScrollBar()->value(),
642 verticalScrollBar()->value());
643 movingVec=QPointF(0,0);
644 setCursor(HandOpenCursor);
649 void MapEditor::mouseMoveEvent(QMouseEvent* e)
651 QPointF p = mapToScene(e->pos());
652 TreeItem *seli=model->getSelectedItem();
653 LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel
655 lmosel=seli->getLMO();
657 // Move the selected MapObj
658 if ( lmosel && movingObj)
660 // reset cursor if we are moving and don't copy
661 if (mainWindow->getModMode()!=Main::ModModeCopy)
662 setCursor (Qt::ArrowCursor);
664 // To avoid jumping of the sceneView, only
665 // ensureSelectionVisible, if not tmp linked
666 if (!lmosel->hasParObjTmp())
667 model->ensureSelectionVisible ();
669 // Now move the selection, but add relative position
670 // (movingObj_start) where selection was chosen with
671 // mousepointer. (This avoids flickering resp. jumping
672 // of selection back to absPos)
674 // Check if we could link
675 TreeItem *dsti=findMapItem (p, seli);
676 LinkableMapObj* dst=NULL;
677 if (dsti) dst=dsti->getLMO(); //FIXME-2 get rid of lmo...
680 FloatObj *fio=model->getSelectedFloatImage();
683 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
685 fio->updateLink(); //no need for reposition, if we update link here
686 model->updateSelection(); // position has changed
688 // Relink float to new mapcenter or branch, if shift is pressed
689 // Only relink, if selection really has a new parent
690 if ( (e->modifiers()==Qt::ShiftModifier) && dst &&
691 ( (typeid(*dst)==typeid(BranchObj)) ||
692 (typeid(*dst)==typeid(MapCenterObj)) ) &&
693 ( dst != fio->getParObj())
696 if (typeid(*fio) == typeid(FloatImageObj) &&
697 ( (typeid(*dst)==typeid(BranchObj) ||
698 typeid(*dst)==typeid(MapCenterObj)) ))
701 // Also save the move which was done so far
702 QString pold=qpointfToString(movingObj_orgRelPos);
703 QString pnow=qpointfToString(fio->getRelPos());
705 fio->getTreeItem(), // FIXME-3
709 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
710 fio->getParObj()->requestReposition();
713 model->linkFloatImageTo (model->getSelectString(dst));
715 //movingObj_orgRelPos=lmosel->getRelPos();
721 { // selection != a FloatObj
722 if (seli->depth()==0) //FIXME-1 also moved mapcenters could be linked, but not working here...
725 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
726 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
728 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
729 model->updateRelPositions();
732 if (seli->depth()==1)
735 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
739 // Move ordinary branch
740 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
741 // Add width of bbox here, otherwise alignRelTo will cause jumping around
742 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
743 p.y()-movingObj_start.y() +lmosel->getTopPad() );
745 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
749 // Maybe we can relink temporary?
750 if (dsti && (dst!=lmosel) && seli->isBranchLikeType() && dsti->isBranchLikeType() )
752 if (e->modifiers()==Qt::ControlModifier)
754 // Special case: CTRL to link below dst
755 lmosel->setParObjTmp (dst,p,+1);
757 else if (e->modifiers()==Qt::ShiftModifier)
758 lmosel->setParObjTmp (dst,p,-1);
760 lmosel->setParObjTmp (dst,p,0);
763 lmosel->unsetParObjTmp();
765 // reposition subbranch
766 lmosel->reposition();
769 QItemSelection sel=model->getSelectionModel()->selection();
770 updateSelection(sel,sel); // position has changed
772 } // no FloatImageObj
776 } // selection && moving_obj
778 // Draw a link from one branch to another
781 tmpXLink->setEnd (p);
782 tmpXLink->updateXLink();
786 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
788 QPointF p=e->globalPos();
789 movingVec.setX(-p.x() + movingObj_start.x() );
790 movingVec.setY(-p.y() + movingObj_start.y() );
791 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
792 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
797 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
799 QPointF p = mapToScene(e->pos());
800 TreeItem *seli=model->getSelectedItem();
801 LinkableMapObj *lmosel=seli->getLMO(); // FIXME-2 get rid of lmosel
803 TreeItem *dsti=findMapItem(p, seli);
804 LinkableMapObj* dst=NULL;
805 if (dsti) dst=dsti->getLMO(); //FIXME-2 get rid of dst...
808 // Have we been picking color?
812 setCursor (Qt::ArrowCursor);
813 // Check if we are over another branch
816 if (e->state() & Qt::ShiftModifier)
817 model->colorBranch (((BranchObj*)dst)->getColor());
819 model->colorSubtree (((BranchObj*)dst)->getColor());
824 // Have we been drawing a link?
828 // Check if we are over another branch
829 if (dsti && lmosel && dsti->isBranchLikeType() )
831 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
832 tmpXLink->updateXLink();
833 tmpXLink->activate(); //FIXME-2 savestate missing
834 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
843 // Have we been moving something?
844 if ( seli && movingObj )
851 FloatImageObj *fo=model->getSelectedFloatImage();
854 // Moved FloatObj. Maybe we need to reposition
855 QString pold=qpointfToString(movingObj_orgRelPos);
856 QString pnow=qpointfToString(fo->getRelPos());
858 fo->getTreeItem(), // FIXME-3
860 fo->getTreeItem(), // FIXME-3
862 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
864 fo->getParObj()->requestReposition();
868 // Check if we are over another branch, but ignore
869 // any found LMOs, which are FloatObjs
871 if (dsti && (!dsti->isBranchLikeType() ))
877 BranchItem *bi=model->getSelectedBranchItem();
878 if (bi && bi->depth()==0)
880 if (movingObj_orgPos != bi->getBranchObj()->getAbsPos()) // FIXME-3 check getBO here...
882 QString pold=qpointfToString(movingObj_orgPos);
883 QString pnow=qpointfToString(bi->getBranchObj()->getAbsPos()); // FIXME-3 check getBO here...
890 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
894 if (seli->getType() == TreeItem::Branch )
895 { // A branch was moved
897 // save the position in case we link to mapcenter
898 QPointF savePos=QPointF (lmosel->getAbsPos() );
900 // Reset the temporary drawn link to the original one
901 lmosel->unsetParObjTmp();
903 // For Redo we may need to save original selection
904 QString preSelStr=model->getSelectString(lmosel);
907 if (dsti && dsti->isBranchLikeType() )
909 // We have a destination, relink to that
911 BranchObj* bsel=model->getSelectedBranchObj();
912 BranchObj* bdst=(BranchObj*)dst;
914 QString preParStr=model->getSelectString (bsel->getParObj());
915 QString preNum=QString::number (seli->num(),10);
916 QString preDstParStr;
918 if (e->state() & Qt::ShiftModifier && dst->getParObj())
920 preDstParStr=model->getSelectString (dst->getParObj());
921 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), seli->num()); //FIXME-2 not needed
922 model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
924 if (e->state() & Qt::ControlModifier && dst->getParObj())
927 preDstParStr=model->getSelectString (dst->getParObj());
928 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), seli->num()+1);//FIXME-2 not needed
929 model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)seli)->num()+1);
932 preDstParStr=model->getSelectString(dst);
933 bsel->linkTo (bdst,-1);//FIXME-2 not needed
934 model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
935 if (dsti->depth()==0) bsel->move (savePos);
937 QString postSelStr=model->getSelectString(lmosel);
938 QString postNum=QString::number (seli->num(),10);
940 QString undoCom="linkTo (\""+
941 preParStr+ "\"," + preNum +"," +
942 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
944 QString redoCom="linkTo (\""+
945 preDstParStr + "\"," + postNum + "," +
946 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
951 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
953 model->reposition(); // not necessary if we undo temporary move below
956 // No destination, undo temporary move
958 if (seli->depth()==1)
960 // The select string might be different _after_ moving around.
961 // Therefor reposition and then use string of old selection, too
964 QPointF rp(lmosel->getRelPos());
965 if (rp != movingObj_orgRelPos)
967 QString ps=qpointfToString(rp);
969 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
970 preSelStr, "moveRel "+ps,
971 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
975 // Draw the original link, before selection was moved around
976 if (settings.value("/animation/use",false).toBool() && seli->depth()>1)
978 lmosel->setRelPos(); // calc relPos first for starting point
979 QPointF dst=bi->getBranchObj()->getParObj()->getChildPos(); // FIXME-3 check getBO here...
980 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
982 model->startAnimation(
986 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
992 model->updateSelection(); //FIXME-3 needed? at least not after pos of selection has changed...
993 // Finally resize scene, if needed
997 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
998 // model->updateActions(); FIXME-3 neeeded?
1000 // maybe we moved View: set old cursor
1001 setCursor (Qt::ArrowCursor);
1005 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
1007 if (model->isSelectionBlocked() )
1013 if (e->button() == Qt::LeftButton )
1015 QPointF p = mapToScene(e->pos());
1016 TreeItem *ti=findMapItem (p, NULL);
1017 if (ti) { // MapObj was found
1018 // First select the MapObj than edit heading
1025 void MapEditor::resizeEvent (QResizeEvent* e)
1027 QGraphicsView::resizeEvent( e );
1030 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
1032 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
1033 // cerr << event->format(i) << endl;
1035 if (event->mimeData()->hasImage())
1036 event->acceptProposedAction();
1038 if (event->mimeData()->hasUrls())
1039 event->acceptProposedAction();
1042 void MapEditor::dragMoveEvent(QDragMoveEvent *)
1046 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
1051 void MapEditor::dropEvent(QDropEvent *event)
1053 BranchItem *selbi=model->getSelectedBranchItem();
1057 foreach (QString format,event->mimeData()->formats())
1058 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1062 if (event->mimeData()->hasImage())
1064 QVariant imageData = event->mimeData()->imageData();
1065 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1067 if (event->mimeData()->hasUrls())
1068 uris=event->mimeData()->urls();
1076 for (int i=0; i<uris.count();i++)
1078 // Workaround to avoid adding empty branches
1079 if (!uris.at(i).toString().isEmpty())
1081 bi=model->createBranch();
1085 s=uris.at(i).toLocalFile();
1088 QString file = QDir::fromNativeSeparators(s);
1089 heading = QFileInfo(file).baseName();
1091 if (file.endsWith(".vym", false))
1092 bi->setVymLink(file);
1094 bi->setURL(uris.at(i).toString());
1097 bo->setURL(uris.at(i).toString());
1101 if (!heading.isEmpty())
1102 bi->setHeading(heading);
1104 bi->setHeading(uris.at(i).toString());
1109 model->reposition();
1112 event->acceptProposedAction();
1115 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1117 // Reduce rectangles
1118 while (newsel.indexes().count() < selboxList.count() )
1119 delete selboxList.takeFirst();
1121 // Add additonal rectangles
1122 QGraphicsRectItem *sb;
1123 while (newsel.indexes().count() > selboxList.count() )
1125 sb = mapScene->addRect(
1127 QPen(selectionColor),
1129 sb->setZValue(Z_SELBOX);
1131 selboxList.append (sb);
1134 // Reposition rectangles
1140 LinkableMapObj *lmo;
1141 foreach (sb,selboxList)
1143 index=newsel.indexes().at(i);
1144 ti= static_cast<TreeItem*>(index.internalPointer());
1146 bbox=lmo->getBBox();
1149 bbox.width(), bbox.height());
1150 sb->setPen (selectionColor);
1151 sb->setBrush (selectionColor);
1156 void MapEditor::updateData (const QModelIndex &sel)
1158 TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
1161 cout << "ME::updateData\n";
1163 cout << " ti="<<ti<<endl;
1164 cout << " h="<<ti->getHeading().toStdString()<<endl;
1167 if (ti->isBranchLikeType())
1169 BranchObj *bo=(BranchObj*)ti->getLMO();
1170 bo->updateHeading();
1175 void MapEditor::setSelectionColor (QColor col)
1178 QItemSelection sel=model->getSelectionModel()->selection();
1179 updateSelection(sel,sel);
1183 QColor MapEditor::getSelectionColor ()
1185 return selectionColor;