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-3 get rid of lmo...
687 //Take care of system flags _or_ modifier modes
689 if (lmo && ti->isBranchLikeType() )
691 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
692 if (!foname.isEmpty())
694 // systemFlag clicked
695 model->select (lmo); // FIXME-3 was selectInt
698 if (e->state() & Qt::ControlModifier)
699 mainWindow->editOpenURLTab();
701 mainWindow->editOpenURL();
703 else if (foname=="vymLink")
705 mainWindow->editOpenVymLink();
706 // tabWidget may change, better return now
707 // before segfaulting...
708 } else if (foname=="note")
709 mainWindow->windowToggleNoteEditor();
710 else if (foname=="hideInExport")
711 model->toggleHideExport();
712 // FIXME-3 needed? xelection.update();
716 // No system flag clicked, take care of modmodes (CTRL-Click)
717 if (e->state() & Qt::ControlModifier)
719 if (mainWindow->getModMode()==Main::ModModeColor)
722 setCursor (PickColorCursor);
725 if (mainWindow->getModMode()==Main::ModModeXLink)
727 BranchObj *bo_begin=NULL;
729 bo_begin=(BranchObj*)(lmo);
731 bo_begin=model->getSelectedBranchObj();
735 linkingObj_src=bo_begin;
736 tmpXLink=new XLinkObj (mapScene);
737 tmpXLink->setBegin (bo_begin);
738 tmpXLink->setEnd (p);
739 tmpXLink->setColor(model->getMapDefXLinkColor());
740 tmpXLink->setWidth(model->getMapDefXLinkWidth());
741 tmpXLink->updateXLink();
742 tmpXLink->setVisibility (true);
751 cout << "ME::mouse pressed\n";
752 cout << " lmo="<<lmo<<endl;
753 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
755 // Select the clicked object
757 // FIXME-2 VM better let "find" return an index instead of lmo...
758 // Get index of clicked LMO
759 TreeItem *ti=lmo->getTreeItem();
761 cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
762 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
764 //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
767 // Left Button Move Branches
768 if (e->button() == Qt::LeftButton )
770 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
771 //movingObj_start.setY( p.y() - selection->y() );
772 movingObj_start.setX( p.x() - lmo->x() );
773 movingObj_start.setY( p.y() - lmo->y() );
774 movingObj_orgPos.setX (lmo->x() );
775 movingObj_orgPos.setY (lmo->y() );
777 movingObj_orgRelPos=lmo->getRelPos();
779 // If modMode==copy, then we want to "move" the _new_ object around
780 // then we need the offset from p to the _old_ selection, because of tmp
781 if (mainWindow->getModMode()==Main::ModModeCopy &&
782 e->state() & Qt::ControlModifier)
784 BranchItem *bi=model->getSelectedBranchItem();
788 //FIXME-2 TreeItem::addBranch (BranchItem still missing)
789 //bi->addBranch (model->getSelectedBranchItem());
791 model->select(bi->getLastBranch());
796 movingObj=model->getSelectedLMO();
798 // Middle Button Toggle Scroll
799 // (On Mac OS X this won't work, but we still have
800 // a button in the toolbar)
801 if (e->button() == Qt::MidButton )
802 model->toggleScroll();
803 // model->updateActions(); FIXME-3 needed?
804 // FIXME-3 needed? xelection.update();
806 { // No MapObj found, we are on the scene itself
807 // Left Button move Pos of sceneView
808 if (e->button() == Qt::LeftButton )
810 movingObj=NULL; // move Content not Obj
811 movingObj_start=e->globalPos();
812 movingCont_start=QPointF (
813 horizontalScrollBar()->value(),
814 verticalScrollBar()->value());
815 movingVec=QPointF(0,0);
816 setCursor(HandOpenCursor);
821 void MapEditor::mouseMoveEvent(QMouseEvent* e)
823 QPointF p = mapToScene(e->pos());
824 TreeItem *seli=model->getSelectedItem();
825 LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel
827 lmosel=seli->getLMO();
829 // Move the selected MapObj
830 if ( lmosel && movingObj)
832 // reset cursor if we are moving and don't copy
833 if (mainWindow->getModMode()!=Main::ModModeCopy)
834 setCursor (Qt::ArrowCursor);
836 // To avoid jumping of the sceneView, only
837 // show selection, if not tmp linked
838 if (!lmosel->hasParObjTmp())
839 model->emitShowSelection();
841 // Now move the selection, but add relative position
842 // (movingObj_start) where selection was chosen with
843 // mousepointer. (This avoids flickering resp. jumping
844 // of selection back to absPos)
846 // Check if we could link
847 TreeItem *dsti=findMapItem (p, seli);
848 LinkableMapObj* dst=NULL;
849 if (dsti && dsti!=seli && dsti->isBranchLikeType())
850 dst=dsti->getLMO(); //FIXME-2 get rid of lmo...
855 FloatObj *fio=model->getSelectedFloatImage();
858 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
860 fio->updateLink(); //no need for reposition, if we update link here
861 model->updateSelection(); // position has changed
863 // Relink float to new mapcenter or branch, if shift is pressed
864 // Only relink, if selection really has a new parent
865 if ( (e->modifiers()==Qt::ShiftModifier) && dst && ( dst != fio->getParObj())
868 // Also save the move which was done so far
869 QString pold=qpointfToString(movingObj_orgRelPos);
870 QString pnow=qpointfToString(fio->getRelPos());
872 fio->getTreeItem(), // FIXME-3
876 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
877 fio->getParObj()->requestReposition();
880 model->linkFloatImageTo (model->getSelectString(dst));
882 //movingObj_orgRelPos=lmosel->getRelPos();
887 { // selection != a FloatObj
888 if (seli->depth()==0) //FIXME-1 also moved mapcenters could be linked, but not working here...
891 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
892 ((BranchObj*)lmosel)->moveBy(
893 QPointF(p.x() -movingObj_start.x(),
894 p.y()-movingObj_start.y()) );
896 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
897 model->updateRelPositions();
900 if (seli->depth()==1)
903 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
907 // Move ordinary branch
908 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
909 // Add width of bbox here, otherwise alignRelTo will cause jumping around
910 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
911 p.y()-movingObj_start.y() +lmosel->getTopPad() );
913 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
917 // Maybe we can relink temporary?
920 if (e->modifiers()==Qt::ControlModifier)
922 // Special case: CTRL to link below dst
923 lmosel->setParObjTmp (dst,p,+1);
925 else if (e->modifiers()==Qt::ShiftModifier)
926 lmosel->setParObjTmp (dst,p,-1);
928 lmosel->setParObjTmp (dst,p,0);
931 lmosel->unsetParObjTmp();
933 // reposition subbranch
934 lmosel->reposition();
937 QItemSelection sel=model->getSelectionModel()->selection();
938 updateSelection(sel,sel); // position has changed
940 } // no FloatImageObj
944 } // selection && moving_obj
946 // Draw a link from one branch to another
949 tmpXLink->setEnd (p);
950 tmpXLink->updateXLink();
954 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
956 QPointF p=e->globalPos();
957 movingVec.setX(-p.x() + movingObj_start.x() );
958 movingVec.setY(-p.y() + movingObj_start.y() );
959 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
960 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
965 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
967 QPointF p = mapToScene(e->pos());
968 TreeItem *seli=model->getSelectedItem();
971 if (seli) dsti=findMapItem(p, seli);
972 LinkableMapObj* dst=NULL;
973 if (dsti && dsti->isBranchLikeType ())
974 dst=dsti->getLMO(); //FIXME-2 get rid of dst...
979 // Have we been picking color?
983 setCursor (Qt::ArrowCursor);
984 // Check if we are over another branch
987 if (e->state() & Qt::ShiftModifier)
988 model->colorBranch (((BranchObj*)dst)->getColor());
990 model->colorSubtree (((BranchObj*)dst)->getColor());
995 // Have we been drawing a link?
999 // Check if we are over another branch
1002 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
1003 tmpXLink->updateXLink();
1004 tmpXLink->activate(); //FIXME-2 savestate missing
1005 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
1014 // Have we been moving something?
1015 if ( seli && movingObj )
1017 FloatImageObj *fo=model->getSelectedFloatImage();
1020 // Moved FloatObj. Maybe we need to reposition
1021 QString pold=qpointfToString(movingObj_orgRelPos);
1022 QString pnow=qpointfToString(fo->getRelPos());
1024 fo->getTreeItem(), // FIXME-3
1026 fo->getTreeItem(), // FIXME-3
1028 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
1030 fo->getParObj()->requestReposition();
1031 model->reposition();
1034 BranchItem *bi=model->getSelectedBranchItem();
1035 if (bi && bi->depth()==0)
1037 if (movingObj_orgPos != bi->getBranchObj()->getAbsPos()) // FIXME-3 check getBO here...
1039 QString pold=qpointfToString(movingObj_orgPos);
1040 QString pnow=qpointfToString(bi->getBranchObj()->getAbsPos()); // FIXME-3 check getBO here...
1047 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
1051 if (seli->isBranchLikeType() ) //(seli->getType() == TreeItem::Branch )
1052 { // A branch was moved
1053 LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel
1054 lmosel=seli->getLMO();
1056 // save the position in case we link to mapcenter
1057 QPointF savePos=QPointF (lmosel->getAbsPos() );
1059 // Reset the temporary drawn link to the original one
1060 lmosel->unsetParObjTmp();
1062 // For Redo we may need to save original selection
1063 QString preSelStr=model->getSelectString(seli);
1068 // We have a destination, relink to that
1070 BranchObj* bsel=model->getSelectedBranchObj();
1072 QString preParStr=model->getSelectString (bsel->getParObj());
1073 QString preNum=QString::number (seli->num(),10);
1074 QString preDstParStr;
1077 if (e->state() & Qt::ShiftModifier && dst->getParObj())
1079 preDstParStr=model->getSelectString (dst->getParObj());
1080 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
1082 if (e->state() & Qt::ControlModifier && dst->getParObj())
1085 preDstParStr=model->getSelectString (dst->getParObj());
1086 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()+1);
1089 preDstParStr=model->getSelectString(dst);
1090 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
1091 if (dsti->depth()==0) bsel->move (savePos);
1095 QString postSelStr=model->getSelectString(lmosel);
1096 QString postNum=QString::number (seli->num(),10);
1098 QString undoCom="linkTo (\""+
1099 preParStr+ "\"," + preNum +"," +
1100 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
1102 QString redoCom="linkTo (\""+
1103 preDstParStr + "\"," + postNum + "," +
1104 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
1109 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
1114 // No destination, undo temporary move
1116 if (seli->depth()==1)
1118 // The select string might be different _after_ moving around.
1119 // Therefor reposition and then use string of old selection, too
1120 model->reposition();
1122 QPointF rp(lmosel->getRelPos());
1123 if (rp != movingObj_orgRelPos)
1125 QString ps=qpointfToString(rp);
1127 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
1128 preSelStr, "moveRel "+ps,
1129 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
1133 // Draw the original link, before selection was moved around
1134 if (settings.value("/animation/use",false).toBool() && seli->depth()>1)
1136 lmosel->setRelPos(); // calc relPos first for starting point
1137 QPointF dst=bi->getBranchObj()->getParObj()->getChildPos(); // FIXME-3 check getBO here...
1138 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
1140 model->startAnimation(
1142 lmosel->getRelPos(),
1144 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
1147 model->reposition();
1150 model->updateSelection(); //FIXME-3 needed? at least not after pos of selection has changed...
1151 // Finally resize scene, if needed
1155 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
1156 // model->updateActions(); FIXME-3 neeeded?
1158 // maybe we moved View: set old cursor
1159 setCursor (Qt::ArrowCursor);
1163 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
1165 if (model->isSelectionBlocked() )
1171 if (e->button() == Qt::LeftButton )
1173 QPointF p = mapToScene(e->pos());
1174 TreeItem *ti=findMapItem (p, NULL);
1175 if (ti) { // MapObj was found
1176 // First select the MapObj than edit heading
1183 void MapEditor::resizeEvent (QResizeEvent* e)
1185 QGraphicsView::resizeEvent( e );
1188 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
1190 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
1191 // cerr << event->format(i) << endl;
1193 if (event->mimeData()->hasImage())
1194 event->acceptProposedAction();
1196 if (event->mimeData()->hasUrls())
1197 event->acceptProposedAction();
1200 void MapEditor::dragMoveEvent(QDragMoveEvent *)
1204 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
1209 void MapEditor::dropEvent(QDropEvent *event)
1211 BranchItem *selbi=model->getSelectedBranchItem();
1215 foreach (QString format,event->mimeData()->formats())
1216 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1220 if (event->mimeData()->hasImage())
1222 QVariant imageData = event->mimeData()->imageData();
1223 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1225 if (event->mimeData()->hasUrls())
1226 uris=event->mimeData()->urls();
1234 for (int i=0; i<uris.count();i++)
1236 // Workaround to avoid adding empty branches
1237 if (!uris.at(i).toString().isEmpty())
1239 bi=model->createBranch();
1243 s=uris.at(i).toLocalFile();
1246 QString file = QDir::fromNativeSeparators(s);
1247 heading = QFileInfo(file).baseName();
1249 if (file.endsWith(".vym", false))
1250 bi->setVymLink(file);
1252 bi->setURL(uris.at(i).toString());
1255 bo->setURL(uris.at(i).toString());
1259 if (!heading.isEmpty())
1260 bi->setHeading(heading);
1262 bi->setHeading(uris.at(i).toString());
1267 model->reposition();
1270 event->acceptProposedAction();
1273 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1275 // Reduce rectangles
1276 while (newsel.indexes().count() < selboxList.count() )
1277 delete selboxList.takeFirst();
1279 // Add additonal rectangles
1280 QGraphicsRectItem *sb;
1281 while (newsel.indexes().count() > selboxList.count() )
1283 sb = mapScene->addRect(
1285 QPen(selectionColor),
1287 sb->setZValue(Z_SELBOX);
1289 selboxList.append (sb);
1292 // Reposition rectangles
1298 LinkableMapObj *lmo;
1299 foreach (sb,selboxList)
1301 index=newsel.indexes().at(i);
1302 ti= static_cast<TreeItem*>(index.internalPointer());
1304 bbox=lmo->getBBox();
1307 bbox.width(), bbox.height());
1308 sb->setPen (selectionColor);
1309 sb->setBrush (selectionColor);
1314 void MapEditor::updateData (const QModelIndex &sel)
1316 TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
1319 cout << "ME::updateData\n";
1321 cout << " ti="<<ti<<endl;
1322 cout << " h="<<ti->getHeading().toStdString()<<endl;
1325 if (ti->isBranchLikeType())
1327 BranchObj *bo=(BranchObj*)ti->getLMO();
1333 void MapEditor::setSelectionColor (QColor col)
1336 QItemSelection sel=model->getSelectionModel()->selection();
1337 updateSelection(sel,sel);
1341 QColor MapEditor::getSelectionColor ()
1343 return selectionColor;