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;
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));
43 zoomFactor=zoomFactorTarget=1;
46 model->setScene (mapScene);
47 model->registerEditor(this);
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); //FIXME-3
72 setAcceptDrops (true);
74 //model->reposition(); //FIXME-3 really still needed?
77 // Shortcuts and actions
79 a = new QAction("Select upper branch", this);
80 a->setShortcut (Qt::Key_Up );
81 a->setShortcutContext (Qt::WidgetShortcut);
83 connect( a, SIGNAL( triggered() ), this, SLOT( cursorUp() ) );
85 a = new QAction( "Select lower branch",this);
86 a->setShortcut ( Qt::Key_Down );
87 a->setShortcutContext (Qt::WidgetShortcut);
89 connect( a, SIGNAL( triggered() ), this, SLOT( cursorDown() ) );
91 a = new QAction( "Select left branch", this);
92 a->setShortcut (Qt::Key_Left );
93 // a->setShortcutContext (Qt::WindowShortcut);
94 a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
96 connect( a, SIGNAL( triggered() ), this, SLOT( cursorLeft() ) );
98 a = new QAction( "Select child branch", this);
99 a->setShortcut (Qt::Key_Right);
100 a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
102 connect( a, SIGNAL( triggered() ), this, SLOT( cursorRight() ) );
104 a = new QAction( "Select first branch", this);
105 a->setShortcut (Qt::Key_Home );
106 a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
108 connect( a, SIGNAL( triggered() ), this, SLOT( cursorFirst() ) );
110 a = new QAction( "Select last branch",this);
111 a->setShortcut ( Qt::Key_End );
112 a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
114 connect( a, SIGNAL( triggered() ), this, SLOT( cursorLast() ) );
116 // Action to embed LineEdit for heading in Scene
117 editingHeading=false;
118 lineEdit=new QLineEdit;
120 QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
121 pw->setZValue (Z_LINEEDIT);
123 a = new QAction( tr( "Edit heading","MapEditor" ), this);
124 a->setShortcut ( Qt::Key_Return ); //Edit heading
126 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
127 a = new QAction( tr( "Edit heading","MapEditor" ), this);
128 a->setShortcut ( Qt::Key_Enter); //Edit heading
130 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
133 selectionColor =QColor (255,255,0);
136 // Attributes //FIXME-2 testing only...
139 attrTable= new AttributeTable();
141 ad=attrTable->addKey (k,StringList);
145 sl <<"val 1"<<"val 2"<< "val 3";
146 ad->setValue (QVariant (sl));
148 //attrTable->addValue ("Key A","P 1");
149 //attrTable->addValue ("Key A","P 2");
150 //attrTable->addValue ("Key A","P 3");
151 //attrTable->addValue ("Key A","P 4");
153 ad=attrTable->addKey (k,FreeString);
156 //attrTable->addValue ("Key B","w1");
157 //attrTable->addValue ("Key B","w2");
159 k="C - UniqueString";
160 ad=attrTable->addKey (k,UniqueString);
163 //attrTable->addKey ("Key Prio");
164 //attrTable->addValue ("Key Prio","Prio 1");
165 //attrTable->addValue ("Key Prio","Prio 2");
169 MapEditor::~MapEditor()
171 //cout <<"Destructor MapEditor for "<<model->getMapName().toStdString()<<endl;
172 model->unregisterEditor(this);
175 VymModel* MapEditor::getModel()
180 QGraphicsScene * MapEditor::getScene()
185 void MapEditor::scrollTo (const QModelIndex &index)
189 LinkableMapObj* lmo=(static_cast<TreeItem*>(index.internalPointer()))->getLMO();
190 if (lmo) setScrollBarPosTarget (lmo->getBBox() );
194 void MapEditor::setScrollBarPosTarget (const QRectF &rect)
196 // Code copied from Qt sources
200 qreal width = viewport()->width();
201 qreal height = viewport()->height();
202 QRectF viewRect = matrix().mapRect(rect);
204 qreal left = horizontalScrollBar()->value();
205 qreal right = left + width;
206 qreal top = verticalScrollBar()->value();
207 qreal bottom = top + height;
209 if (viewRect.left() <= left + xmargin) {
210 // need to scroll from the left
211 // if (!d->leftIndent)
212 scrollBarPosTarget.setX(int(viewRect.left() - xmargin - 0.5));
214 if (viewRect.right() >= right - xmargin) {
215 // need to scroll from the right
216 // if (!d->leftIndent)
217 scrollBarPosTarget.setX(int(viewRect.right() - width + xmargin + 0.5));
219 if (viewRect.top() <= top + ymargin) {
220 // need to scroll from the top
221 // if (!d->topIndent)
222 scrollBarPosTarget.setY(int(viewRect.top() - ymargin - 0.5));
224 if (viewRect.bottom() >= bottom - ymargin) {
225 // need to scroll from the bottom
226 // if (!d->topIndent)
227 scrollBarPosTarget.setY(int(viewRect.bottom() - height + ymargin + 0.5));
230 if (scrollBarPosAnimation.state()==QtAbstractAnimation::Running)
231 scrollBarPosAnimation.stop();
232 scrollBarPosAnimation.setTargetObject (this);
233 scrollBarPosAnimation.setPropertyName ("scrollBarPos");
234 scrollBarPosAnimation.setDuration(1000);
235 scrollBarPosAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
236 scrollBarPosAnimation.setStartValue(
237 QPointF (horizontalScrollBar()->value() ,
238 verticalScrollBar()->value() ) );
239 scrollBarPosAnimation.setEndValue(scrollBarPosTarget);
240 scrollBarPosAnimation.start();
243 QPointF MapEditor::getScrollBarPosTarget()
245 return scrollBarPosTarget;
249 void MapEditor::setScrollBarPos(const QPointF &p)
252 horizontalScrollBar()->setValue(int(p.x()));
253 verticalScrollBar()->setValue(int(p.y()));
256 QPointF MapEditor::getScrollBarPos()
261 void MapEditor::setZoomFactorTarget (const qreal &zft)
263 zoomFactorTarget=zft;
264 if (zoomAnimation.state()==QtAbstractAnimation::Running)
265 zoomAnimation.stop();
266 //zoomAnimation=QtPropertyAnimation(this, "zoomFactor");
267 zoomAnimation.setTargetObject (this);
268 zoomAnimation.setPropertyName ("zoomFactor");
269 zoomAnimation.setDuration(1000);
270 zoomAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
271 zoomAnimation.setStartValue(zoomFactor);
272 zoomAnimation.setEndValue(zft);
273 zoomAnimation.start();
276 qreal MapEditor::getZoomFactorTarget()
278 return zoomFactorTarget;
282 void MapEditor::setZoomFactor(const qreal &zf)
285 setMatrix (QMatrix(zf, 0, 0, zf, 0, 0),false );
288 qreal MapEditor::getZoomFactor()
293 void MapEditor::print()
297 printer = new QPrinter;
298 printer->setColorMode (QPrinter::Color);
299 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
300 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
301 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
304 QRectF totalBBox=model->getTotalBBox();
306 // Try to set orientation automagically
307 // Note: Interpretation of generated postscript is amibiguous, if
308 // there are problems with landscape mode, see
309 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
311 if (totalBBox.width()>totalBBox.height())
312 // recommend landscape
313 printer->setOrientation (QPrinter::Landscape);
315 // recommend portrait
316 printer->setOrientation (QPrinter::Portrait);
318 if ( printer->setup(this) )
319 // returns false, if printing is canceled
321 QPainter pp(printer);
323 pp.setRenderHint(QPainter::Antialiasing,true);
325 // Don't print the visualisation of selection
328 QRectF mapRect=totalBBox;
329 QGraphicsRectItem *frame=NULL;
333 // Print frame around map
334 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
335 totalBBox.width()+20, totalBBox.height()+20);
336 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
342 double paperAspect = (double)printer->width() / (double)printer->height();
343 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
345 if (mapAspect>=paperAspect)
347 // Fit horizontally to paper width
348 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
349 viewBottom=(int)(printer->width()/mapAspect);
352 // Fit vertically to paper height
353 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
354 viewBottom=printer->height();
359 // Print footer below map
361 font.setPointSize(10);
363 QRectF footerBox(0,viewBottom,printer->width(),15);
364 // FIXME-3 fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
365 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
369 QRectF (0,0,printer->width(),printer->height()-15),
370 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
373 // Viewport has paper dimension
374 if (frame) delete (frame);
379 // Save settings in vymrc
380 settings.writeEntry("/mainwindow/printerName",printer->printerName());
381 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
382 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
386 void MapEditor::setAntiAlias (bool b)
388 setRenderHint(QPainter::Antialiasing,b);
391 void MapEditor::setSmoothPixmap(bool b)
393 setRenderHint(QPainter::SmoothPixmapTransform,b);
396 TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
398 // Start with mapcenter, no images allowed at rootItem
400 BranchItem *bi=model->getRootItem()->getFirstBranch();
401 TreeItem *found=NULL;
404 found=bi->findMapItem (p, exclude);
405 if (found) return found;
407 bi=model->getRootItem()->getBranchNum(i);
412 AttributeTable* MapEditor::attributeTable()
417 void MapEditor::testFunction1()
420 // Code copied from Qt sources
421 QRectF rect=model->getSelectedBranchObj()->getBBox();
425 qreal width = viewport()->width();
426 qreal height = viewport()->height();
427 QRectF viewRect = matrix().mapRect(rect);
429 qreal left = horizontalScrollBar()->value();
430 qreal right = left + width;
431 qreal top = verticalScrollBar()->value();
432 qreal bottom = top + height;
434 if (viewRect.left() <= left + xmargin) {
435 // need to scroll from the left
436 // if (!d->leftIndent)
437 horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
439 if (viewRect.right() >= right - xmargin) {
440 // need to scroll from the right
441 // if (!d->leftIndent)
442 horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
444 if (viewRect.top() <= top + ymargin) {
445 // need to scroll from the top
446 // if (!d->topIndent)
447 verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
449 if (viewRect.bottom() >= bottom - ymargin) {
450 // need to scroll from the bottom
451 // if (!d->topIndent)
452 verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
454 cout << "test1: hor="<<horizontalScrollBar()->value()<<endl;
455 cout << "test1: ver="<<verticalScrollBar()->value()<<endl;
458 QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
459 animation->setDuration(5000);
460 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
461 animation->setEasingCurve ( QtEasingCurve::OutQuint);
462 animation->setStartValue(sceneRect() );
463 animation->setEndValue(QRectF(50, 50, 1000, 1000));
468 QDialog *dia= new QDialog (this);
469 dia->setGeometry (50,50,10,10);
474 QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
475 animation->setDuration(1000);
476 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
477 animation->setEasingCurve ( QtEasingCurve::OutQuint);
478 animation->setStartValue(QRect(50, 50, 10, 10));
479 animation->setEndValue(QRect(250, 250, 100, 100));
484 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
485 if (hidemode==HideNone)
487 setHideTmpMode (HideExport);
488 mapCenter->calcBBoxSizeWithChilds();
489 QRectF totalBBox=mapCenter->getTotalBBox();
490 QRectF mapRect=totalBBox;
491 QCanvasRectangle *frame=NULL;
493 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
495 mapRect.setRect (totalBBox.x(), totalBBox.y(),
496 totalBBox.width(), totalBBox.height());
497 frame=new QCanvasRectangle (mapRect,mapScene);
498 frame->setBrush (QColor(white));
499 frame->setPen (QColor(black));
505 setHideTmpMode (HideNone);
507 cout <<" hidemode="<<hidemode<<endl;
510 void MapEditor::testFunction2()
515 if (hidemode==HideExport)
516 setHideTmpMode (HideNone);
518 setHideTmpMode (HideExport);
522 void MapEditor::cursorUp()
524 model->selectUpperBranch();
527 void MapEditor::cursorDown()
530 model->selectLowerBranch();
533 void MapEditor::cursorLeft()
535 model->selectLeftBranch();
538 void MapEditor::cursorRight()
540 model->selectRightBranch();
543 void MapEditor::cursorFirst()
545 model->selectFirstBranch();
548 void MapEditor::cursorLast()
550 model->selectLastBranch();
554 void MapEditor::editHeading()
558 editHeadingFinished();
561 BranchObj *bo=model->getSelectedBranchObj();
562 BranchItem *bi=model->getSelectedBranchItem();
565 model->setSelectionBlocked(true);
567 lineEdit->setText (bi->getHeading());
568 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
569 lineEdit->setGeometry(p.x(),p.y(),230,25);
570 lineEdit->selectAll();
572 lineEdit->setFocus();
573 lineEdit->grabKeyboard();
578 void MapEditor::editHeadingFinished()
580 editingHeading=false;
581 lineEdit->releaseKeyboard();
582 model->setHeading (lineEdit->text() );
583 model->setSelectionBlocked(false);
586 // Maybe reselect previous branch
587 mainWindow->editHeadingFinished (model);
591 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
593 // Lineedits are already closed by preceding
594 // mouseEvent, we don't need to close here.
596 QPointF p = mapToScene(e->pos());
597 TreeItem *ti=findMapItem (p, NULL);
598 LinkableMapObj* lmo=NULL;
599 if (ti) lmo=ti->getLMO(); //FIXME-2 get rid of lmo...
602 { // MapObj was found
603 if (model->getSelectedLMO() != lmo)
609 if (model->getSelectedBranchObj() )
611 // Context Menu on branch or mapcenter
612 //FIXME-3 model->updateActions(); needed?
613 branchContextMenu->popup(e->globalPos() );
616 if (model->getSelectedFloatImage() )
618 // Context Menu on floatimage
619 // model->updateActions(); FIXME-3 needed?
620 floatimageContextMenu->popup(e->globalPos() );
624 { // No MapObj found, we are on the Canvas itself
625 // Context Menu on scene
626 // model->updateActions(); FIXME-3 needed?
628 // Open context menu synchronously to position new mapcenter
629 model->setContextPos (p);
630 canvasContextMenu->exec(e->globalPos() );
631 model->unsetContextPos ();
636 void MapEditor::keyPressEvent(QKeyEvent* e)
638 if (e->modifiers() & Qt::ControlModifier)
640 switch (mainWindow->getModMode())
642 case Main::ModModeColor:
643 setCursor (PickColorCursor);
645 case Main::ModModeCopy:
646 setCursor (CopyCursor);
648 case Main::ModModeXLink:
649 setCursor (XLinkCursor);
652 setCursor (Qt::ArrowCursor);
658 void MapEditor::keyReleaseEvent(QKeyEvent* e)
660 if (!(e->modifiers() & Qt::ControlModifier))
661 setCursor (Qt::ArrowCursor);
664 void MapEditor::mousePressEvent(QMouseEvent* e)
666 // Ignore right clicks, these will go to context menus
667 if (e->button() == Qt::RightButton )
673 //Ignore clicks while editing heading
674 if (model->isSelectionBlocked() )
680 QPointF p = mapToScene(e->pos());
681 TreeItem *ti=findMapItem (p, NULL);
682 LinkableMapObj* lmo=NULL;
683 if (ti) lmo=ti->getLMO(); //FIXME-2 get rid of lmo...
687 //Take care of system flags _or_ modifier modes
689 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
690 typeid(*lmo)==typeid(MapCenterObj) ))
692 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
693 if (!foname.isEmpty())
695 // systemFlag clicked
696 model->select (lmo); // FIXME-3 was selectInt
699 if (e->state() & Qt::ControlModifier)
700 mainWindow->editOpenURLTab();
702 mainWindow->editOpenURL();
704 else if (foname=="vymLink")
706 mainWindow->editOpenVymLink();
707 // tabWidget may change, better return now
708 // before segfaulting...
709 } else if (foname=="note")
710 mainWindow->windowToggleNoteEditor();
711 else if (foname=="hideInExport")
712 model->toggleHideExport();
713 // FIXME-3 needed? xelection.update();
717 // No system flag clicked, take care of modmodes (CTRL-Click)
718 if (e->state() & Qt::ControlModifier)
720 if (mainWindow->getModMode()==Main::ModModeColor)
723 setCursor (PickColorCursor);
726 if (mainWindow->getModMode()==Main::ModModeXLink)
728 BranchObj *bo_begin=NULL;
730 bo_begin=(BranchObj*)(lmo);
732 bo_begin=model->getSelectedBranchObj();
736 linkingObj_src=bo_begin;
737 tmpXLink=new XLinkObj (mapScene);
738 tmpXLink->setBegin (bo_begin);
739 tmpXLink->setEnd (p);
740 tmpXLink->setColor(model->getMapDefXLinkColor());
741 tmpXLink->setWidth(model->getMapDefXLinkWidth());
742 tmpXLink->updateXLink();
743 tmpXLink->setVisibility (true);
752 cout << "ME::mouse pressed\n";
753 cout << " lmo="<<lmo<<endl;
754 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
756 // Select the clicked object
758 // FIXME-2 VM better let "find" return an index instead of lmo...
759 // Get index of clicked LMO
760 TreeItem *ti=lmo->getTreeItem();
762 cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
763 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
765 //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
768 // Left Button Move Branches
769 if (e->button() == Qt::LeftButton )
771 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
772 //movingObj_start.setY( p.y() - selection->y() );
773 movingObj_start.setX( p.x() - lmo->x() );
774 movingObj_start.setY( p.y() - lmo->y() );
775 movingObj_orgPos.setX (lmo->x() );
776 movingObj_orgPos.setY (lmo->y() );
778 movingObj_orgRelPos=lmo->getRelPos();
780 // If modMode==copy, then we want to "move" the _new_ object around
781 // then we need the offset from p to the _old_ selection, because of tmp
782 if (mainWindow->getModMode()==Main::ModModeCopy &&
783 e->state() & Qt::ControlModifier)
785 BranchItem *bi=model->getSelectedBranchItem();
789 //FIXME-2 TreeItem::addBranch (BranchItem still missing)
790 //bi->addBranch (model->getSelectedBranchItem());
792 model->select(bi->getLastBranch());
797 movingObj=model->getSelectedLMO();
799 // Middle Button Toggle Scroll
800 // (On Mac OS X this won't work, but we still have
801 // a button in the toolbar)
802 if (e->button() == Qt::MidButton )
803 model->toggleScroll();
804 // model->updateActions(); FIXME-3 needed?
805 // FIXME-3 needed? xelection.update();
807 { // No MapObj found, we are on the scene itself
808 // Left Button move Pos of sceneView
809 if (e->button() == Qt::LeftButton )
811 movingObj=NULL; // move Content not Obj
812 movingObj_start=e->globalPos();
813 movingCont_start=QPointF (
814 horizontalScrollBar()->value(),
815 verticalScrollBar()->value());
816 movingVec=QPointF(0,0);
817 setCursor(HandOpenCursor);
822 void MapEditor::mouseMoveEvent(QMouseEvent* e)
824 QPointF p = mapToScene(e->pos());
825 TreeItem *seli=model->getSelectedItem();
826 LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel
828 lmosel=seli->getLMO();
830 // Move the selected MapObj
831 if ( lmosel && movingObj)
833 // reset cursor if we are moving and don't copy
834 if (mainWindow->getModMode()!=Main::ModModeCopy)
835 setCursor (Qt::ArrowCursor);
837 // To avoid jumping of the sceneView, only
838 // show selection, if not tmp linked
839 if (!lmosel->hasParObjTmp())
840 model->emitShowSelection();
842 // Now move the selection, but add relative position
843 // (movingObj_start) where selection was chosen with
844 // mousepointer. (This avoids flickering resp. jumping
845 // of selection back to absPos)
847 // Check if we could link
848 TreeItem *dsti=findMapItem (p, seli);
849 LinkableMapObj* dst=NULL;
850 if (dsti && dsti!=seli && dsti->isBranchLikeType())
851 dst=dsti->getLMO(); //FIXME-2 get rid of lmo...
856 FloatObj *fio=model->getSelectedFloatImage();
859 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
861 fio->updateLink(); //no need for reposition, if we update link here
862 model->updateSelection(); // position has changed
864 // Relink float to new mapcenter or branch, if shift is pressed
865 // Only relink, if selection really has a new parent
866 if ( (e->modifiers()==Qt::ShiftModifier) && dst && ( dst != fio->getParObj())
869 if (typeid(*fio) == typeid(FloatImageObj) )
872 // Also save the move which was done so far
873 QString pold=qpointfToString(movingObj_orgRelPos);
874 QString pnow=qpointfToString(fio->getRelPos());
876 fio->getTreeItem(), // FIXME-3
880 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
881 fio->getParObj()->requestReposition();
884 model->linkFloatImageTo (model->getSelectString(dst));
886 //movingObj_orgRelPos=lmosel->getRelPos();
892 { // selection != a FloatObj
893 if (seli->depth()==0) //FIXME-1 also moved mapcenters could be linked, but not working here...
896 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
897 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
899 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
900 model->updateRelPositions();
903 if (seli->depth()==1)
906 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
910 // Move ordinary branch
911 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
912 // Add width of bbox here, otherwise alignRelTo will cause jumping around
913 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
914 p.y()-movingObj_start.y() +lmosel->getTopPad() );
916 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
920 // Maybe we can relink temporary?
923 if (e->modifiers()==Qt::ControlModifier)
925 // Special case: CTRL to link below dst
926 lmosel->setParObjTmp (dst,p,+1);
928 else if (e->modifiers()==Qt::ShiftModifier)
929 lmosel->setParObjTmp (dst,p,-1);
931 lmosel->setParObjTmp (dst,p,0);
934 lmosel->unsetParObjTmp();
936 // reposition subbranch
937 lmosel->reposition();
940 QItemSelection sel=model->getSelectionModel()->selection();
941 updateSelection(sel,sel); // position has changed
943 } // no FloatImageObj
947 } // selection && moving_obj
949 // Draw a link from one branch to another
952 tmpXLink->setEnd (p);
953 tmpXLink->updateXLink();
957 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
959 QPointF p=e->globalPos();
960 movingVec.setX(-p.x() + movingObj_start.x() );
961 movingVec.setY(-p.y() + movingObj_start.y() );
962 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
963 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
968 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
970 QPointF p = mapToScene(e->pos());
971 TreeItem *seli=model->getSelectedItem();
974 if (seli) dsti=findMapItem(p, seli);
975 LinkableMapObj* dst=NULL;
976 if (dsti && dsti->isBranchLikeType ())
977 dst=dsti->getLMO(); //FIXME-2 get rid of dst...
982 // Have we been picking color?
986 setCursor (Qt::ArrowCursor);
987 // Check if we are over another branch
990 if (e->state() & Qt::ShiftModifier)
991 model->colorBranch (((BranchObj*)dst)->getColor());
993 model->colorSubtree (((BranchObj*)dst)->getColor());
998 // Have we been drawing a link?
1002 // Check if we are over another branch
1005 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
1006 tmpXLink->updateXLink();
1007 tmpXLink->activate(); //FIXME-2 savestate missing
1008 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
1017 // Have we been moving something?
1018 if ( seli && movingObj )
1020 FloatImageObj *fo=model->getSelectedFloatImage();
1023 // Moved FloatObj. Maybe we need to reposition
1024 QString pold=qpointfToString(movingObj_orgRelPos);
1025 QString pnow=qpointfToString(fo->getRelPos());
1027 fo->getTreeItem(), // FIXME-3
1029 fo->getTreeItem(), // FIXME-3
1031 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
1033 fo->getParObj()->requestReposition();
1034 model->reposition();
1037 BranchItem *bi=model->getSelectedBranchItem();
1038 if (bi && bi->depth()==0)
1040 if (movingObj_orgPos != bi->getBranchObj()->getAbsPos()) // FIXME-3 check getBO here...
1042 QString pold=qpointfToString(movingObj_orgPos);
1043 QString pnow=qpointfToString(bi->getBranchObj()->getAbsPos()); // FIXME-3 check getBO here...
1050 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
1054 if (seli->getType() == TreeItem::Branch )
1055 { // A branch was moved
1056 LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel
1057 lmosel=seli->getLMO();
1059 // save the position in case we link to mapcenter
1060 QPointF savePos=QPointF (lmosel->getAbsPos() );
1062 // Reset the temporary drawn link to the original one
1063 lmosel->unsetParObjTmp();
1065 // For Redo we may need to save original selection
1066 QString preSelStr=model->getSelectString(lmosel);
1071 // We have a destination, relink to that
1073 BranchObj* bsel=model->getSelectedBranchObj();
1075 QString preParStr=model->getSelectString (bsel->getParObj());
1076 QString preNum=QString::number (seli->num(),10);
1077 QString preDstParStr;
1080 if (e->state() & Qt::ShiftModifier && dst->getParObj())
1082 preDstParStr=model->getSelectString (dst->getParObj());
1083 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
1085 if (e->state() & Qt::ControlModifier && dst->getParObj())
1088 preDstParStr=model->getSelectString (dst->getParObj());
1089 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()+1);
1092 preDstParStr=model->getSelectString(dst);
1093 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
1094 if (dsti->depth()==0) bsel->move (savePos);
1098 QString postSelStr=model->getSelectString(lmosel);
1099 QString postNum=QString::number (seli->num(),10);
1101 QString undoCom="linkTo (\""+
1102 preParStr+ "\"," + preNum +"," +
1103 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
1105 QString redoCom="linkTo (\""+
1106 preDstParStr + "\"," + postNum + "," +
1107 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
1112 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
1117 // No destination, undo temporary move
1119 if (seli->depth()==1)
1121 // The select string might be different _after_ moving around.
1122 // Therefor reposition and then use string of old selection, too
1123 model->reposition();
1125 QPointF rp(lmosel->getRelPos());
1126 if (rp != movingObj_orgRelPos)
1128 QString ps=qpointfToString(rp);
1130 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
1131 preSelStr, "moveRel "+ps,
1132 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
1136 // Draw the original link, before selection was moved around
1137 if (settings.value("/animation/use",false).toBool() && seli->depth()>1)
1139 lmosel->setRelPos(); // calc relPos first for starting point
1140 QPointF dst=bi->getBranchObj()->getParObj()->getChildPos(); // FIXME-3 check getBO here...
1141 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
1143 model->startAnimation(
1145 lmosel->getRelPos(),
1147 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
1150 model->reposition();
1153 model->updateSelection(); //FIXME-3 needed? at least not after pos of selection has changed...
1154 // Finally resize scene, if needed
1158 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
1159 // model->updateActions(); FIXME-3 neeeded?
1161 // maybe we moved View: set old cursor
1162 setCursor (Qt::ArrowCursor);
1166 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
1168 if (model->isSelectionBlocked() )
1174 if (e->button() == Qt::LeftButton )
1176 QPointF p = mapToScene(e->pos());
1177 TreeItem *ti=findMapItem (p, NULL);
1178 if (ti) { // MapObj was found
1179 // First select the MapObj than edit heading
1186 void MapEditor::resizeEvent (QResizeEvent* e)
1188 QGraphicsView::resizeEvent( e );
1191 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
1193 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
1194 // cerr << event->format(i) << endl;
1196 if (event->mimeData()->hasImage())
1197 event->acceptProposedAction();
1199 if (event->mimeData()->hasUrls())
1200 event->acceptProposedAction();
1203 void MapEditor::dragMoveEvent(QDragMoveEvent *)
1207 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
1212 void MapEditor::dropEvent(QDropEvent *event)
1214 BranchItem *selbi=model->getSelectedBranchItem();
1218 foreach (QString format,event->mimeData()->formats())
1219 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1223 if (event->mimeData()->hasImage())
1225 QVariant imageData = event->mimeData()->imageData();
1226 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1228 if (event->mimeData()->hasUrls())
1229 uris=event->mimeData()->urls();
1237 for (int i=0; i<uris.count();i++)
1239 // Workaround to avoid adding empty branches
1240 if (!uris.at(i).toString().isEmpty())
1242 bi=model->createBranch();
1246 s=uris.at(i).toLocalFile();
1249 QString file = QDir::fromNativeSeparators(s);
1250 heading = QFileInfo(file).baseName();
1252 if (file.endsWith(".vym", false))
1253 bi->setVymLink(file);
1255 bi->setURL(uris.at(i).toString());
1258 bo->setURL(uris.at(i).toString());
1262 if (!heading.isEmpty())
1263 bi->setHeading(heading);
1265 bi->setHeading(uris.at(i).toString());
1270 model->reposition();
1273 event->acceptProposedAction();
1276 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1278 // Reduce rectangles
1279 while (newsel.indexes().count() < selboxList.count() )
1280 delete selboxList.takeFirst();
1282 // Add additonal rectangles
1283 QGraphicsRectItem *sb;
1284 while (newsel.indexes().count() > selboxList.count() )
1286 sb = mapScene->addRect(
1288 QPen(selectionColor),
1290 sb->setZValue(Z_SELBOX);
1292 selboxList.append (sb);
1295 // Reposition rectangles
1301 LinkableMapObj *lmo;
1302 foreach (sb,selboxList)
1304 index=newsel.indexes().at(i);
1305 ti= static_cast<TreeItem*>(index.internalPointer());
1307 bbox=lmo->getBBox();
1310 bbox.width(), bbox.height());
1311 sb->setPen (selectionColor);
1312 sb->setBrush (selectionColor);
1317 void MapEditor::updateData (const QModelIndex &sel)
1319 TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
1322 cout << "ME::updateData\n";
1324 cout << " ti="<<ti<<endl;
1325 cout << " h="<<ti->getHeading().toStdString()<<endl;
1328 if (ti->isBranchLikeType())
1330 BranchObj *bo=(BranchObj*)ti->getLMO();
1336 void MapEditor::setSelectionColor (QColor col)
1339 QItemSelection sel=model->getSelectionModel()->selection();
1340 updateSelection(sel,sel);
1344 QColor MapEditor::getSelectionColor ()
1346 return selectionColor;