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);
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::setScrollBarPosTarget (const QRectF &rect)
187 // Code copied from Qt sources
191 qreal width = viewport()->width();
192 qreal height = viewport()->height();
193 QRectF viewRect = matrix().mapRect(rect);
195 qreal left = horizontalScrollBar()->value();
196 qreal right = left + width;
197 qreal top = verticalScrollBar()->value();
198 qreal bottom = top + height;
200 if (viewRect.left() <= left + xmargin) {
201 // need to scroll from the left
202 // if (!d->leftIndent)
203 scrollBarPosTarget.setX(int(viewRect.left() - xmargin - 0.5));
205 if (viewRect.right() >= right - xmargin) {
206 // need to scroll from the right
207 // if (!d->leftIndent)
208 scrollBarPosTarget.setX(int(viewRect.right() - width + xmargin + 0.5));
210 if (viewRect.top() <= top + ymargin) {
211 // need to scroll from the top
212 // if (!d->topIndent)
213 scrollBarPosTarget.setY(int(viewRect.top() - ymargin - 0.5));
215 if (viewRect.bottom() >= bottom - ymargin) {
216 // need to scroll from the bottom
217 // if (!d->topIndent)
218 scrollBarPosTarget.setY(int(viewRect.bottom() - height + ymargin + 0.5));
221 if (scrollBarPosAnimation.state()==QtAbstractAnimation::Running)
222 scrollBarPosAnimation.stop();
223 scrollBarPosAnimation.setTargetObject (this);
224 scrollBarPosAnimation.setPropertyName ("scrollBarPos");
225 scrollBarPosAnimation.setDuration(1000);
226 scrollBarPosAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
227 scrollBarPosAnimation.setStartValue(
228 QPointF (horizontalScrollBar()->value() ,
229 verticalScrollBar()->value() ) );
230 scrollBarPosAnimation.setEndValue(scrollBarPosTarget);
231 scrollBarPosAnimation.start();
234 QPointF MapEditor::getScrollBarPosTarget()
236 return scrollBarPosTarget;
240 void MapEditor::setScrollBarPos(const QPointF &p)
243 horizontalScrollBar()->setValue(int(p.x()));
244 verticalScrollBar()->setValue(int(p.y()));
247 QPointF MapEditor::getScrollBarPos()
252 void MapEditor::setZoomFactorTarget (const qreal &zft)
254 zoomFactorTarget=zft;
255 if (zoomAnimation.state()==QtAbstractAnimation::Running)
256 zoomAnimation.stop();
257 //zoomAnimation=QtPropertyAnimation(this, "zoomFactor");
258 zoomAnimation.setTargetObject (this);
259 zoomAnimation.setPropertyName ("zoomFactor");
260 zoomAnimation.setDuration(1000);
261 zoomAnimation.setEasingCurve ( QtEasingCurve::OutQuint);
262 zoomAnimation.setStartValue(zoomFactor);
263 zoomAnimation.setEndValue(zft);
264 zoomAnimation.start();
267 qreal MapEditor::getZoomFactorTarget()
269 return zoomFactorTarget;
273 void MapEditor::setZoomFactor(const qreal &zf)
276 setMatrix (QMatrix(zf, 0, 0, zf, 0, 0),false );
279 qreal MapEditor::getZoomFactor()
284 void MapEditor::print()
288 printer = new QPrinter;
289 printer->setColorMode (QPrinter::Color);
290 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
291 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
292 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
295 QRectF totalBBox=model->getTotalBBox();
297 // Try to set orientation automagically
298 // Note: Interpretation of generated postscript is amibiguous, if
299 // there are problems with landscape mode, see
300 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
302 if (totalBBox.width()>totalBBox.height())
303 // recommend landscape
304 printer->setOrientation (QPrinter::Landscape);
306 // recommend portrait
307 printer->setOrientation (QPrinter::Portrait);
309 if ( printer->setup(this) )
310 // returns false, if printing is canceled
312 QPainter pp(printer);
314 pp.setRenderHint(QPainter::Antialiasing,true);
316 // Don't print the visualisation of selection
319 QRectF mapRect=totalBBox;
320 QGraphicsRectItem *frame=NULL;
324 // Print frame around map
325 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
326 totalBBox.width()+20, totalBBox.height()+20);
327 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
333 double paperAspect = (double)printer->width() / (double)printer->height();
334 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
336 if (mapAspect>=paperAspect)
338 // Fit horizontally to paper width
339 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
340 viewBottom=(int)(printer->width()/mapAspect);
343 // Fit vertically to paper height
344 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
345 viewBottom=printer->height();
350 // Print footer below map
352 font.setPointSize(10);
354 QRectF footerBox(0,viewBottom,printer->width(),15);
355 // FIXME-3 fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
356 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
360 QRectF (0,0,printer->width(),printer->height()-15),
361 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
364 // Viewport has paper dimension
365 if (frame) delete (frame);
370 // Save settings in vymrc
371 settings.writeEntry("/mainwindow/printerName",printer->printerName());
372 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
373 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
377 void MapEditor::setAntiAlias (bool b)
379 setRenderHint(QPainter::Antialiasing,b);
382 void MapEditor::setSmoothPixmap(bool b)
384 setRenderHint(QPainter::SmoothPixmapTransform,b);
387 TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
389 // Start with mapcenter, no images allowed at rootItem
391 BranchItem *bi=model->getRootItem()->getFirstBranch();
392 TreeItem *found=NULL;
395 found=bi->findMapItem (p, exclude);
396 if (found) return found;
398 bi=model->getRootItem()->getBranchNum(i);
403 AttributeTable* MapEditor::attributeTable()
408 void MapEditor::testFunction1()
411 // Code copied from Qt sources
412 QRectF rect=model->getSelectedBranchObj()->getBBox();
416 qreal width = viewport()->width();
417 qreal height = viewport()->height();
418 QRectF viewRect = matrix().mapRect(rect);
420 qreal left = horizontalScrollBar()->value();
421 qreal right = left + width;
422 qreal top = verticalScrollBar()->value();
423 qreal bottom = top + height;
425 if (viewRect.left() <= left + xmargin) {
426 // need to scroll from the left
427 // if (!d->leftIndent)
428 horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
430 if (viewRect.right() >= right - xmargin) {
431 // need to scroll from the right
432 // if (!d->leftIndent)
433 horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
435 if (viewRect.top() <= top + ymargin) {
436 // need to scroll from the top
437 // if (!d->topIndent)
438 verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
440 if (viewRect.bottom() >= bottom - ymargin) {
441 // need to scroll from the bottom
442 // if (!d->topIndent)
443 verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
445 cout << "test1: hor="<<horizontalScrollBar()->value()<<endl;
446 cout << "test1: ver="<<verticalScrollBar()->value()<<endl;
449 QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
450 animation->setDuration(5000);
451 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
452 animation->setEasingCurve ( QtEasingCurve::OutQuint);
453 animation->setStartValue(sceneRect() );
454 animation->setEndValue(QRectF(50, 50, 1000, 1000));
459 QDialog *dia= new QDialog (this);
460 dia->setGeometry (50,50,10,10);
465 QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
466 animation->setDuration(1000);
467 //animation->setEasingCurve ( QtEasingCurve::OutElastic);
468 animation->setEasingCurve ( QtEasingCurve::OutQuint);
469 animation->setStartValue(QRect(50, 50, 10, 10));
470 animation->setEndValue(QRect(250, 250, 100, 100));
475 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
476 if (hidemode==HideNone)
478 setHideTmpMode (HideExport);
479 mapCenter->calcBBoxSizeWithChilds();
480 QRectF totalBBox=mapCenter->getTotalBBox();
481 QRectF mapRect=totalBBox;
482 QCanvasRectangle *frame=NULL;
484 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
486 mapRect.setRect (totalBBox.x(), totalBBox.y(),
487 totalBBox.width(), totalBBox.height());
488 frame=new QCanvasRectangle (mapRect,mapScene);
489 frame->setBrush (QColor(white));
490 frame->setPen (QColor(black));
496 setHideTmpMode (HideNone);
498 cout <<" hidemode="<<hidemode<<endl;
501 void MapEditor::testFunction2()
506 if (hidemode==HideExport)
507 setHideTmpMode (HideNone);
509 setHideTmpMode (HideExport);
513 void MapEditor::cursorUp()
515 model->selectUpperBranch();
518 void MapEditor::cursorDown()
521 model->selectLowerBranch();
524 void MapEditor::cursorLeft()
526 model->selectLeftBranch();
529 void MapEditor::cursorRight()
531 model->selectRightBranch();
534 void MapEditor::cursorFirst()
536 model->selectFirstBranch();
539 void MapEditor::cursorLast()
541 model->selectLastBranch();
545 void MapEditor::editHeading()
549 editHeadingFinished();
552 BranchObj *bo=model->getSelectedBranchObj();
553 BranchItem *bi=model->getSelectedBranchItem();
556 model->setSelectionBlocked(true);
558 lineEdit->setText (bi->getHeading());
559 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
560 lineEdit->setGeometry(p.x(),p.y(),230,25);
561 lineEdit->selectAll();
563 lineEdit->setFocus();
564 lineEdit->grabKeyboard();
569 void MapEditor::editHeadingFinished()
571 editingHeading=false;
572 lineEdit->releaseKeyboard();
573 model->setHeading (lineEdit->text() );
574 model->setSelectionBlocked(false);
577 // Maybe reselect previous branch
578 mainWindow->editHeadingFinished (model);
582 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
584 // Lineedits are already closed by preceding
585 // mouseEvent, we don't need to close here.
587 QPointF p = mapToScene(e->pos());
588 TreeItem *ti=findMapItem (p, NULL);
589 LinkableMapObj* lmo=NULL;
590 if (ti) lmo=ti->getLMO(); //FIXME-2 get rid of lmo...
593 { // MapObj was found
594 if (model->getSelectedLMO() != lmo)
600 if (model->getSelectedBranchObj() )
602 // Context Menu on branch or mapcenter
603 //FIXME-3 model->updateActions(); needed?
604 branchContextMenu->popup(e->globalPos() );
607 if (model->getSelectedFloatImage() )
609 // Context Menu on floatimage
610 // model->updateActions(); FIXME-3 needed?
611 floatimageContextMenu->popup(e->globalPos() );
615 { // No MapObj found, we are on the Canvas itself
616 // Context Menu on scene
617 // model->updateActions(); FIXME-3 needed?
619 // Open context menu synchronously to position new mapcenter
620 model->setContextPos (p);
621 canvasContextMenu->exec(e->globalPos() );
622 model->unsetContextPos ();
627 void MapEditor::keyPressEvent(QKeyEvent* e)
629 if (e->modifiers() & Qt::ControlModifier)
631 switch (mainWindow->getModMode())
633 case Main::ModModeColor:
634 setCursor (PickColorCursor);
636 case Main::ModModeCopy:
637 setCursor (CopyCursor);
639 case Main::ModModeXLink:
640 setCursor (XLinkCursor);
643 setCursor (Qt::ArrowCursor);
649 void MapEditor::keyReleaseEvent(QKeyEvent* e)
651 if (!(e->modifiers() & Qt::ControlModifier))
652 setCursor (Qt::ArrowCursor);
655 void MapEditor::mousePressEvent(QMouseEvent* e)
657 // Ignore right clicks, these will go to context menus
658 if (e->button() == Qt::RightButton )
664 //Ignore clicks while editing heading
665 if (model->isSelectionBlocked() )
671 QPointF p = mapToScene(e->pos());
672 TreeItem *ti=findMapItem (p, NULL);
673 LinkableMapObj* lmo=NULL;
674 if (ti) lmo=ti->getLMO(); //FIXME-2 get rid of lmo...
678 //Take care of system flags _or_ modifier modes
680 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
681 typeid(*lmo)==typeid(MapCenterObj) ))
683 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
684 if (!foname.isEmpty())
686 // systemFlag clicked
687 model->select (lmo); // FIXME-3 was selectInt
690 if (e->state() & Qt::ControlModifier)
691 mainWindow->editOpenURLTab();
693 mainWindow->editOpenURL();
695 else if (foname=="vymLink")
697 mainWindow->editOpenVymLink();
698 // tabWidget may change, better return now
699 // before segfaulting...
700 } else if (foname=="note")
701 mainWindow->windowToggleNoteEditor();
702 else if (foname=="hideInExport")
703 model->toggleHideExport();
704 // FIXME-3 needed? xelection.update();
708 // No system flag clicked, take care of modmodes (CTRL-Click)
709 if (e->state() & Qt::ControlModifier)
711 if (mainWindow->getModMode()==Main::ModModeColor)
714 setCursor (PickColorCursor);
717 if (mainWindow->getModMode()==Main::ModModeXLink)
719 BranchObj *bo_begin=NULL;
721 bo_begin=(BranchObj*)(lmo);
723 bo_begin=model->getSelectedBranchObj();
727 linkingObj_src=bo_begin;
728 tmpXLink=new XLinkObj (mapScene);
729 tmpXLink->setBegin (bo_begin);
730 tmpXLink->setEnd (p);
731 tmpXLink->setColor(model->getMapDefXLinkColor());
732 tmpXLink->setWidth(model->getMapDefXLinkWidth());
733 tmpXLink->updateXLink();
734 tmpXLink->setVisibility (true);
743 cout << "ME::mouse pressed\n";
744 cout << " lmo="<<lmo<<endl;
745 cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
747 // Select the clicked object
749 // FIXME-2 VM better let "find" return an index instead of lmo...
750 // Get index of clicked LMO
751 TreeItem *ti=lmo->getTreeItem();
753 cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
754 cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
756 //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
759 // Left Button Move Branches
760 if (e->button() == Qt::LeftButton )
762 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
763 //movingObj_start.setY( p.y() - selection->y() );
764 movingObj_start.setX( p.x() - lmo->x() );
765 movingObj_start.setY( p.y() - lmo->y() );
766 movingObj_orgPos.setX (lmo->x() );
767 movingObj_orgPos.setY (lmo->y() );
769 movingObj_orgRelPos=lmo->getRelPos();
771 // If modMode==copy, then we want to "move" the _new_ object around
772 // then we need the offset from p to the _old_ selection, because of tmp
773 if (mainWindow->getModMode()==Main::ModModeCopy &&
774 e->state() & Qt::ControlModifier)
776 BranchItem *bi=model->getSelectedBranchItem();
780 //FIXME-2 TreeItem::addBranch (BranchItem still missing)
781 //bi->addBranch (model->getSelectedBranchItem());
783 model->select(bi->getLastBranch());
788 movingObj=model->getSelectedLMO();
790 // Middle Button Toggle Scroll
791 // (On Mac OS X this won't work, but we still have
792 // a button in the toolbar)
793 if (e->button() == Qt::MidButton )
794 model->toggleScroll();
795 // model->updateActions(); FIXME-3 needed?
796 // FIXME-3 needed? xelection.update();
798 { // No MapObj found, we are on the scene itself
799 // Left Button move Pos of sceneView
800 if (e->button() == Qt::LeftButton )
802 movingObj=NULL; // move Content not Obj
803 movingObj_start=e->globalPos();
804 movingCont_start=QPointF (
805 horizontalScrollBar()->value(),
806 verticalScrollBar()->value());
807 movingVec=QPointF(0,0);
808 setCursor(HandOpenCursor);
813 void MapEditor::mouseMoveEvent(QMouseEvent* e)
815 QPointF p = mapToScene(e->pos());
816 TreeItem *seli=model->getSelectedItem();
817 LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel
819 lmosel=seli->getLMO();
821 // Move the selected MapObj
822 if ( lmosel && movingObj)
824 // reset cursor if we are moving and don't copy
825 if (mainWindow->getModMode()!=Main::ModModeCopy)
826 setCursor (Qt::ArrowCursor);
828 // To avoid jumping of the sceneView, only
829 // show selection, if not tmp linked
830 if (!lmosel->hasParObjTmp())
831 model->emitShowSelection();
833 // Now move the selection, but add relative position
834 // (movingObj_start) where selection was chosen with
835 // mousepointer. (This avoids flickering resp. jumping
836 // of selection back to absPos)
838 // Check if we could link
839 TreeItem *dsti=findMapItem (p, seli);
840 LinkableMapObj* dst=NULL;
841 if (dsti) dst=dsti->getLMO(); //FIXME-2 get rid of lmo...
844 FloatObj *fio=model->getSelectedFloatImage();
847 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
849 fio->updateLink(); //no need for reposition, if we update link here
850 model->updateSelection(); // position has changed
852 // Relink float to new mapcenter or branch, if shift is pressed
853 // Only relink, if selection really has a new parent
854 if ( (e->modifiers()==Qt::ShiftModifier) && dst &&
855 ( (typeid(*dst)==typeid(BranchObj)) ||
856 (typeid(*dst)==typeid(MapCenterObj)) ) &&
857 ( dst != fio->getParObj())
860 if (typeid(*fio) == typeid(FloatImageObj) &&
861 ( (typeid(*dst)==typeid(BranchObj) ||
862 typeid(*dst)==typeid(MapCenterObj)) ))
865 // Also save the move which was done so far
866 QString pold=qpointfToString(movingObj_orgRelPos);
867 QString pnow=qpointfToString(fio->getRelPos());
869 fio->getTreeItem(), // FIXME-3
873 QString("Move %1 to relative position %2").arg(model->getObjectName(fio)).arg(pnow));
874 fio->getParObj()->requestReposition();
877 model->linkFloatImageTo (model->getSelectString(dst));
879 //movingObj_orgRelPos=lmosel->getRelPos();
885 { // selection != a FloatObj
886 if (seli->depth()==0) //FIXME-1 also moved mapcenters could be linked, but not working here...
889 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
890 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
892 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
893 model->updateRelPositions();
896 if (seli->depth()==1)
899 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
903 // Move ordinary branch
904 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
905 // Add width of bbox here, otherwise alignRelTo will cause jumping around
906 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
907 p.y()-movingObj_start.y() +lmosel->getTopPad() );
909 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
913 // Maybe we can relink temporary?
914 if (dsti && (dst!=lmosel) && seli->isBranchLikeType() && dsti->isBranchLikeType() )
916 if (e->modifiers()==Qt::ControlModifier)
918 // Special case: CTRL to link below dst
919 lmosel->setParObjTmp (dst,p,+1);
921 else if (e->modifiers()==Qt::ShiftModifier)
922 lmosel->setParObjTmp (dst,p,-1);
924 lmosel->setParObjTmp (dst,p,0);
927 lmosel->unsetParObjTmp();
929 // reposition subbranch
930 lmosel->reposition();
933 QItemSelection sel=model->getSelectionModel()->selection();
934 updateSelection(sel,sel); // position has changed
936 } // no FloatImageObj
940 } // selection && moving_obj
942 // Draw a link from one branch to another
945 tmpXLink->setEnd (p);
946 tmpXLink->updateXLink();
950 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
952 QPointF p=e->globalPos();
953 movingVec.setX(-p.x() + movingObj_start.x() );
954 movingVec.setY(-p.y() + movingObj_start.y() );
955 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
956 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
961 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
963 QPointF p = mapToScene(e->pos());
964 TreeItem *seli=model->getSelectedItem();
966 TreeItem *dsti=findMapItem(p, seli);
967 LinkableMapObj* dst=NULL;
968 if (dsti) dst=dsti->getLMO(); //FIXME-2 get rid of dst...
971 // Have we been picking color?
975 setCursor (Qt::ArrowCursor);
976 // Check if we are over another branch
979 if (e->state() & Qt::ShiftModifier)
980 model->colorBranch (((BranchObj*)dst)->getColor());
982 model->colorSubtree (((BranchObj*)dst)->getColor());
987 // Have we been drawing a link?
991 // Check if we are over another branch
992 if (dsti && seli && dsti->isBranchLikeType() )
994 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
995 tmpXLink->updateXLink();
996 tmpXLink->activate(); //FIXME-2 savestate missing
997 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );
1006 // Have we been moving something?
1007 if ( seli && movingObj )
1014 FloatImageObj *fo=model->getSelectedFloatImage();
1017 // Moved FloatObj. Maybe we need to reposition
1018 QString pold=qpointfToString(movingObj_orgRelPos);
1019 QString pnow=qpointfToString(fo->getRelPos());
1021 fo->getTreeItem(), // FIXME-3
1023 fo->getTreeItem(), // FIXME-3
1025 QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
1027 fo->getParObj()->requestReposition();
1028 model->reposition();
1031 // Check if we are over another branch, but ignore
1032 // any found LMOs, which are FloatObjs
1034 if (dsti && (!dsti->isBranchLikeType() ))
1040 BranchItem *bi=model->getSelectedBranchItem();
1041 if (bi && bi->depth()==0)
1043 if (movingObj_orgPos != bi->getBranchObj()->getAbsPos()) // FIXME-3 check getBO here...
1045 QString pold=qpointfToString(movingObj_orgPos);
1046 QString pnow=qpointfToString(bi->getBranchObj()->getAbsPos()); // FIXME-3 check getBO here...
1053 QString("Move mapcenter %1 to position %2").arg(model->getObjectName(bi)).arg(pnow));
1057 if (seli->getType() == TreeItem::Branch )
1058 { // A branch was moved
1059 LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel
1060 lmosel=seli->getLMO();
1062 // save the position in case we link to mapcenter
1063 QPointF savePos=QPointF (lmosel->getAbsPos() );
1065 // Reset the temporary drawn link to the original one
1066 lmosel->unsetParObjTmp();
1068 // For Redo we may need to save original selection
1069 QString preSelStr=model->getSelectString(lmosel);
1072 if (dsti && dsti->isBranchLikeType() )
1074 // We have a destination, relink to that
1076 BranchObj* bsel=model->getSelectedBranchObj();
1078 QString preParStr=model->getSelectString (bsel->getParObj());
1079 QString preNum=QString::number (seli->num(),10);
1080 QString preDstParStr;
1083 if (e->state() & Qt::ShiftModifier && dst->getParObj())
1085 preDstParStr=model->getSelectString (dst->getParObj());
1086 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
1088 if (e->state() & Qt::ControlModifier && dst->getParObj())
1091 preDstParStr=model->getSelectString (dst->getParObj());
1092 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num()+1);
1095 preDstParStr=model->getSelectString(dst);
1096 relinked=model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
1097 if (dsti->depth()==0) bsel->move (savePos);
1101 QString postSelStr=model->getSelectString(lmosel);
1102 QString postNum=QString::number (seli->num(),10);
1104 QString undoCom="linkTo (\""+
1105 preParStr+ "\"," + preNum +"," +
1106 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
1108 QString redoCom="linkTo (\""+
1109 preDstParStr + "\"," + postNum + "," +
1110 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
1115 QString("Relink %1 to %2").arg(model->getObjectName(bsel)).arg(model->getObjectName(dst)) );
1120 // No destination, undo temporary move
1122 if (seli->depth()==1)
1124 // The select string might be different _after_ moving around.
1125 // Therefor reposition and then use string of old selection, too
1126 model->reposition();
1128 QPointF rp(lmosel->getRelPos());
1129 if (rp != movingObj_orgRelPos)
1131 QString ps=qpointfToString(rp);
1133 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
1134 preSelStr, "moveRel "+ps,
1135 QString("Move %1 to relative position %2").arg(model->getObjectName(lmosel)).arg(ps));
1139 // Draw the original link, before selection was moved around
1140 if (settings.value("/animation/use",false).toBool() && seli->depth()>1)
1142 lmosel->setRelPos(); // calc relPos first for starting point
1143 QPointF dst=bi->getBranchObj()->getParObj()->getChildPos(); // FIXME-3 check getBO here...
1144 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
1146 model->startAnimation(
1148 lmosel->getRelPos(),
1150 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
1153 model->reposition();
1156 model->updateSelection(); //FIXME-3 needed? at least not after pos of selection has changed...
1157 // Finally resize scene, if needed
1161 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
1162 // model->updateActions(); FIXME-3 neeeded?
1164 // maybe we moved View: set old cursor
1165 setCursor (Qt::ArrowCursor);
1169 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
1171 if (model->isSelectionBlocked() )
1177 if (e->button() == Qt::LeftButton )
1179 QPointF p = mapToScene(e->pos());
1180 TreeItem *ti=findMapItem (p, NULL);
1181 if (ti) { // MapObj was found
1182 // First select the MapObj than edit heading
1189 void MapEditor::resizeEvent (QResizeEvent* e)
1191 QGraphicsView::resizeEvent( e );
1194 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
1196 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
1197 // cerr << event->format(i) << endl;
1199 if (event->mimeData()->hasImage())
1200 event->acceptProposedAction();
1202 if (event->mimeData()->hasUrls())
1203 event->acceptProposedAction();
1206 void MapEditor::dragMoveEvent(QDragMoveEvent *)
1210 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
1215 void MapEditor::dropEvent(QDropEvent *event)
1217 BranchItem *selbi=model->getSelectedBranchItem();
1221 foreach (QString format,event->mimeData()->formats())
1222 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1226 if (event->mimeData()->hasImage())
1228 QVariant imageData = event->mimeData()->imageData();
1229 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
1231 if (event->mimeData()->hasUrls())
1232 uris=event->mimeData()->urls();
1240 for (int i=0; i<uris.count();i++)
1242 // Workaround to avoid adding empty branches
1243 if (!uris.at(i).toString().isEmpty())
1245 bi=model->createBranch();
1249 s=uris.at(i).toLocalFile();
1252 QString file = QDir::fromNativeSeparators(s);
1253 heading = QFileInfo(file).baseName();
1255 if (file.endsWith(".vym", false))
1256 bi->setVymLink(file);
1258 bi->setURL(uris.at(i).toString());
1261 bo->setURL(uris.at(i).toString());
1265 if (!heading.isEmpty())
1266 bi->setHeading(heading);
1268 bi->setHeading(uris.at(i).toString());
1273 model->reposition();
1276 event->acceptProposedAction();
1279 void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &)
1281 // Reduce rectangles
1282 while (newsel.indexes().count() < selboxList.count() )
1283 delete selboxList.takeFirst();
1285 // Add additonal rectangles
1286 QGraphicsRectItem *sb;
1287 while (newsel.indexes().count() > selboxList.count() )
1289 sb = mapScene->addRect(
1291 QPen(selectionColor),
1293 sb->setZValue(Z_SELBOX);
1295 selboxList.append (sb);
1298 // Reposition rectangles
1304 LinkableMapObj *lmo;
1305 foreach (sb,selboxList)
1307 index=newsel.indexes().at(i);
1308 ti= static_cast<TreeItem*>(index.internalPointer());
1310 bbox=lmo->getBBox();
1313 bbox.width(), bbox.height());
1314 sb->setPen (selectionColor);
1315 sb->setBrush (selectionColor);
1320 void MapEditor::updateData (const QModelIndex &sel)
1322 TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
1325 cout << "ME::updateData\n";
1327 cout << " ti="<<ti<<endl;
1328 cout << " h="<<ti->getHeading().toStdString()<<endl;
1331 if (ti->isBranchLikeType())
1333 BranchObj *bo=(BranchObj*)ti->getLMO();
1339 void MapEditor::setSelectionColor (QColor col)
1342 QItemSelection sel=model->getSelectionModel()->selection();
1343 updateSelection(sel,sel);
1347 QColor MapEditor::getSelectionColor ()
1349 return selectionColor;