9 #include "mainwindow.h"
11 #include "warningdialog.h"
14 extern int statusbarTime;
15 extern Main *mainWindow;
16 extern QString tmpVymDir;
17 extern QString clipboardDir;
18 extern QString clipboardFile;
19 extern bool clipboardEmpty;
21 extern FlagRowObj *standardFlagsDefault;
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));
44 model->setScene (mapScene);
45 model->registerEditor(this);
46 model->addMapCenter(); // FIXME create this in MapEditor until BO and MCO are independent of scene
53 // Create bitmap cursors, platform dependant
54 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
55 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
56 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
57 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
59 setFocusPolicy (Qt::StrongFocus);
71 setAcceptDrops (true);
73 //model->reposition(); //FIXME really still needed?
76 // Action to embed LineEdit for heading in Scene
78 lineEdit=new QLineEdit;
80 QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
83 QAction *a = new QAction( tr( "Edit heading","MapEditor" ), this);
84 a->setShortcut ( Qt::Key_Return ); //Edit heading
85 //a->setShortcutContext (Qt::WindowShortcut);
87 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
88 a = new QAction( tr( "Edit heading","MapEditor" ), this);
89 a->setShortcut ( Qt::Key_Enter); //Edit heading
90 //a->setShortcutContext (Qt::WindowShortcut);
92 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
94 // Attributes //FIXME testing only...
97 attrTable= new AttributeTable();
99 ad=attrTable->addKey (k,StringList);
103 sl <<"val 1"<<"val 2"<< "val 3";
104 ad->setValue (QVariant (sl));
106 //attrTable->addValue ("Key A","P 1");
107 //attrTable->addValue ("Key A","P 2");
108 //attrTable->addValue ("Key A","P 3");
109 //attrTable->addValue ("Key A","P 4");
111 ad=attrTable->addKey (k,FreeString);
114 //attrTable->addValue ("Key B","w1");
115 //attrTable->addValue ("Key B","w2");
117 k="C - UniqueString";
118 ad=attrTable->addKey (k,UniqueString);
121 //attrTable->addKey ("Key Prio");
122 //attrTable->addValue ("Key Prio","Prio 1");
123 //attrTable->addValue ("Key Prio","Prio 2");
127 MapEditor::~MapEditor()
129 //cout <<"Destructor MapEditor\n";
130 // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes
132 //removeDir(QDir(tmpMapDir)); // FIXME check?!?
133 model->unregisterEditor(this);
136 VymModel* MapEditor::getModel()
141 QGraphicsScene * MapEditor::getScene()
146 void MapEditor::print()
150 printer = new QPrinter;
151 printer->setColorMode (QPrinter::Color);
152 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
153 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
154 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
157 QRectF totalBBox=model->getTotalBBox();
159 // Try to set orientation automagically
160 // Note: Interpretation of generated postscript is amibiguous, if
161 // there are problems with landscape mode, see
162 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
164 if (totalBBox.width()>totalBBox.height())
165 // recommend landscape
166 printer->setOrientation (QPrinter::Landscape);
168 // recommend portrait
169 printer->setOrientation (QPrinter::Portrait);
171 if ( printer->setup(this) )
172 // returns false, if printing is canceled
174 QPainter pp(printer);
176 pp.setRenderHint(QPainter::Antialiasing,true);
178 // Don't print the visualisation of selection
181 QRectF mapRect=totalBBox;
182 QGraphicsRectItem *frame=NULL;
186 // Print frame around map
187 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
188 totalBBox.width()+20, totalBBox.height()+20);
189 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
195 double paperAspect = (double)printer->width() / (double)printer->height();
196 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
198 if (mapAspect>=paperAspect)
200 // Fit horizontally to paper width
201 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
202 viewBottom=(int)(printer->width()/mapAspect);
205 // Fit vertically to paper height
206 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
207 viewBottom=printer->height();
212 // Print footer below map
214 font.setPointSize(10);
216 QRectF footerBox(0,viewBottom,printer->width(),15);
217 // FIXME fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
218 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
222 QRectF (0,0,printer->width(),printer->height()-15),
223 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
226 // Viewport has paper dimension
227 if (frame) delete (frame);
232 // Save settings in vymrc
233 settings.writeEntry("/mainwindow/printerName",printer->printerName());
234 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
235 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
239 void MapEditor::setAntiAlias (bool b)
241 setRenderHint(QPainter::Antialiasing,b);
244 void MapEditor::setSmoothPixmap(bool b)
246 setRenderHint(QPainter::SmoothPixmapTransform,b);
249 void MapEditor::toggleStandardFlag(QString f)
251 BranchObj *bo=model->getSelectedBranch();
255 if (bo->isSetStandardFlag(f))
267 QString("%1 (\"%2\")").arg(u).arg(f),
269 QString("%1 (\"%2\")").arg(r).arg(f),
270 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
271 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
272 model->updateSelection();
276 void MapEditor::updateSelection()
278 // Tell selection to update geometries
279 model->updateSelection();
282 AttributeTable* MapEditor::attributeTable()
287 void MapEditor::testFunction1()
289 //BranchObj *bo=model->getSelectedBranch();
290 //if (bo) model->moveAway (bo);
291 //if (bo) bo->setLinkStyle (LinkableMapObj::Line);
294 // Displacement and animation of all non-mainbranches
301 if (bo->getDepth() >0 && !bo->hasScrolledParent(bo) )
303 p=QPointF (qrand() %600-300, qrand () %600-300);
306 model->startAnimation (bo,p, q);
313 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
314 if (hidemode==HideNone)
316 setHideTmpMode (HideExport);
317 mapCenter->calcBBoxSizeWithChilds();
318 QRectF totalBBox=mapCenter->getTotalBBox();
319 QRectF mapRect=totalBBox;
320 QCanvasRectangle *frame=NULL;
322 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
324 mapRect.setRect (totalBBox.x(), totalBBox.y(),
325 totalBBox.width(), totalBBox.height());
326 frame=new QCanvasRectangle (mapRect,mapScene);
327 frame->setBrush (QColor(white));
328 frame->setPen (QColor(black));
334 setHideTmpMode (HideNone);
336 cout <<" hidemode="<<hidemode<<endl;
340 void MapEditor::testFunction2()
345 if (hidemode==HideExport)
346 setHideTmpMode (HideNone);
348 setHideTmpMode (HideExport);
352 void MapEditor::editHeading()
356 editHeadingFinished();
359 BranchObj *bo=model->getSelectedBranch();
362 model->setSelectionBlocked(true);
364 lineEdit->setText (bo->getHeading());
365 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
366 lineEdit->setGeometry(p.x(),p.y(),230,25);
367 lineEdit->selectAll();
369 lineEdit->setFocus();
370 lineEdit->grabKeyboard();
375 void MapEditor::editHeadingFinished()
377 editingHeading=false;
378 lineEdit->releaseKeyboard();
379 model->setHeading (lineEdit->text() );
380 model->setSelectionBlocked(false);
383 // Maybe reselect previous branch
384 mainWindow->editHeadingFinished (model);
388 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
390 // Lineedits are already closed by preceding
391 // mouseEvent, we don't need to close here.
393 QPointF p = mapToScene(e->pos());
394 LinkableMapObj* lmo=model->findMapObj(p, NULL);
397 { // MapObj was found
398 if (model->getSelection() != lmo)
404 if (model->getSelectedBranch() )
406 // Context Menu on branch or mapcenter
407 model->updateActions();
408 branchContextMenu->popup(e->globalPos() );
411 if (model->getSelectedFloatImage() )
413 // Context Menu on floatimage
414 model->updateActions();
415 floatimageContextMenu->popup(e->globalPos() );
419 { // No MapObj found, we are on the Canvas itself
420 // Context Menu on scene
421 model->updateActions();
423 // Open context menu synchronously to position new mapcenter
424 model->setContextPos (p);
425 canvasContextMenu->exec(e->globalPos() );
426 model->unsetContextPos ();
431 void MapEditor::keyPressEvent(QKeyEvent* e)
433 if (e->modifiers() & Qt::ControlModifier)
435 switch (mainWindow->getModMode())
437 case Main::ModModeColor:
438 setCursor (PickColorCursor);
440 case Main::ModModeCopy:
441 setCursor (CopyCursor);
443 case Main::ModModeXLink:
444 setCursor (XLinkCursor);
447 setCursor (Qt::ArrowCursor);
453 void MapEditor::keyReleaseEvent(QKeyEvent* e)
455 if (!(e->modifiers() & Qt::ControlModifier))
456 setCursor (Qt::ArrowCursor);
459 void MapEditor::mousePressEvent(QMouseEvent* e)
461 // Ignore right clicks, these will go to context menus
462 if (e->button() == Qt::RightButton )
468 //Ignore clicks while editing heading
469 if (model->isSelectionBlocked() )
475 QPointF p = mapToScene(e->pos());
476 LinkableMapObj* lmo=model->findMapObj(p, NULL);
480 //Take care of system flags _or_ modifier modes
482 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
483 typeid(*lmo)==typeid(MapCenterObj) ))
485 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
486 if (!foname.isEmpty())
488 // systemFlag clicked
489 model->selectInt (lmo);
492 if (e->state() & Qt::ControlModifier)
493 mainWindow->editOpenURLTab();
495 mainWindow->editOpenURL();
497 else if (foname=="vymLink")
499 mainWindow->editOpenVymLink();
500 // tabWidget may change, better return now
501 // before segfaulting...
502 } else if (foname=="note")
503 mainWindow->windowToggleNoteEditor();
504 else if (foname=="hideInExport")
505 model->toggleHideExport();
506 // FIXME needed? xelection.update();
510 // No system flag clicked, take care of modmodes (CTRL-Click)
511 if (e->state() & Qt::ControlModifier)
513 if (mainWindow->getModMode()==Main::ModModeColor)
516 setCursor (PickColorCursor);
519 if (mainWindow->getModMode()==Main::ModModeXLink)
521 BranchObj *bo_begin=NULL;
523 bo_begin=(BranchObj*)(lmo);
525 bo_begin=model->getSelectedBranch();
529 linkingObj_src=bo_begin;
530 tmpXLink=new XLinkObj (mapScene);
531 tmpXLink->setBegin (bo_begin);
532 tmpXLink->setEnd (p);
533 tmpXLink->setColor(model->getMapDefXLinkColor());
534 tmpXLink->setWidth(model->getMapDefXLinkWidth());
535 tmpXLink->updateXLink();
536 tmpXLink->setVisibility (true);
544 // Select the clicked object
545 model->selectInt (lmo);
547 // Left Button Move Branches
548 if (e->button() == Qt::LeftButton )
550 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
551 //movingObj_start.setY( p.y() - selection->y() );
552 movingObj_start.setX( p.x() - lmo->x() );
553 movingObj_start.setY( p.y() - lmo->y() );
554 movingObj_orgPos.setX (lmo->x() );
555 movingObj_orgPos.setY (lmo->y() );
557 movingObj_orgRelPos=lmo->getRelPos();
559 // If modMode==copy, then we want to "move" the _new_ object around
560 // then we need the offset from p to the _old_ selection, because of tmp
561 if (mainWindow->getModMode()==Main::ModModeCopy &&
562 e->state() & Qt::ControlModifier)
564 BranchObj *bo=model->getSelectedBranch();
568 bo->addBranch ((BranchObj*)model->getSelection());
570 model->select(bo->getLastBranch());
575 movingObj=model->getSelection();
577 // Middle Button Toggle Scroll
578 // (On Mac OS X this won't work, but we still have
579 // a button in the toolbar)
580 if (e->button() == Qt::MidButton )
581 model->toggleScroll();
582 model->updateActions();
583 // FIXME needed? xelection.update();
585 { // No MapObj found, we are on the scene itself
586 // Left Button move Pos of sceneView
587 if (e->button() == Qt::LeftButton )
589 movingObj=NULL; // move Content not Obj
590 movingObj_start=e->globalPos();
591 movingCont_start=QPointF (
592 horizontalScrollBar()->value(),
593 verticalScrollBar()->value());
594 movingVec=QPointF(0,0);
595 setCursor(HandOpenCursor);
600 void MapEditor::mouseMoveEvent(QMouseEvent* e)
602 QPointF p = mapToScene(e->pos());
603 LinkableMapObj *lmosel=model->getSelection();
605 // Move the selected MapObj
606 if ( lmosel && movingObj)
608 // reset cursor if we are moving and don't copy
609 if (mainWindow->getModMode()!=Main::ModModeCopy)
610 setCursor (Qt::ArrowCursor);
612 // To avoid jumping of the sceneView, only
613 // ensureSelectionVisible, if not tmp linked
614 if (!lmosel->hasParObjTmp())
615 model->ensureSelectionVisible ();
617 // Now move the selection, but add relative position
618 // (movingObj_start) where selection was chosen with
619 // mousepointer. (This avoids flickering resp. jumping
620 // of selection back to absPos)
622 // Check if we could link
623 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
626 FloatObj *fio=model->getSelectedFloatImage();
629 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
631 fio->updateLink(); //no need for reposition, if we update link here
632 model->updateSelection();
634 // Relink float to new mapcenter or branch, if shift is pressed
635 // Only relink, if selection really has a new parent
636 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
637 ( (typeid(*lmo)==typeid(BranchObj)) ||
638 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
639 ( lmo != fio->getParObj())
642 if (typeid(*fio) == typeid(FloatImageObj) &&
643 ( (typeid(*lmo)==typeid(BranchObj) ||
644 typeid(*lmo)==typeid(MapCenterObj)) ))
647 // Also save the move which was done so far
648 QString pold=qpointfToString(movingObj_orgRelPos);
649 QString pnow=qpointfToString(fio->getRelPos());
655 QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
656 fio->getParObj()->requestReposition();
659 model->linkFloatImageTo (model->getSelectString(lmo));
661 //movingObj_orgRelPos=lmosel->getRelPos();
667 { // selection != a FloatObj
668 if (lmosel->getDepth()==0)
671 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
672 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
674 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
675 model->updateRelPositions();
678 if (lmosel->getDepth()==1)
681 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
685 // Move ordinary branch
686 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
687 // Add width of bbox here, otherwise alignRelTo will cause jumping around
688 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
689 p.y()-movingObj_start.y() +lmosel->getTopPad() );
691 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
695 // Maybe we can relink temporary?
696 if (lmo && (lmo!=lmosel) && model->getSelectedBranch() &&
697 (typeid(*lmo)==typeid(BranchObj) ||
698 typeid(*lmo)==typeid(MapCenterObj)) )
701 if (e->modifiers()==Qt::ControlModifier)
703 // Special case: CTRL to link below lmo
704 lmosel->setParObjTmp (lmo,p,+1);
706 else if (e->modifiers()==Qt::ShiftModifier)
707 lmosel->setParObjTmp (lmo,p,-1);
709 lmosel->setParObjTmp (lmo,p,0);
712 lmosel->unsetParObjTmp();
714 // reposition subbranch
715 lmosel->reposition();
718 model->updateSelection();// FIXME needed?
719 } // no FloatImageObj
723 } // selection && moving_obj
725 // Draw a link from one branch to another
728 tmpXLink->setEnd (p);
729 tmpXLink->updateXLink();
733 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
735 QPointF p=e->globalPos();
736 movingVec.setX(-p.x() + movingObj_start.x() );
737 movingVec.setY(-p.y() + movingObj_start.y() );
738 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
739 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
744 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
746 QPointF p = mapToScene(e->pos());
748 LinkableMapObj *lmosel=model->getSelection();
749 // Have we been picking color?
753 setCursor (Qt::ArrowCursor);
754 // Check if we are over another branch
755 dst=model->findMapObj(p, NULL);
758 if (e->state() & Qt::ShiftModifier)
759 model->colorBranch (((BranchObj*)dst)->getColor());
761 model->colorSubtree (((BranchObj*)dst)->getColor());
766 // Have we been drawing a link?
770 // Check if we are over another branch
771 dst=model->findMapObj(p, NULL);
774 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
775 tmpXLink->updateXLink();
776 tmpXLink->activate(); //FIXME savestate missing
777 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
786 // Have we been moving something?
787 if ( lmosel && movingObj )
789 FloatImageObj *fo=model->getSelectedFloatImage();
792 // Moved FloatObj. Maybe we need to reposition
793 QString pold=qpointfToString(movingObj_orgRelPos);
794 QString pnow=qpointfToString(fo->getRelPos());
800 QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
802 fo->getParObj()->requestReposition();
806 // Check if we are over another branch, but ignore
807 // any found LMOs, which are FloatObjs
808 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
810 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
813 BranchObj *bo=model->getSelectedBranch();
814 if (bo && bo->getDepth()==0)
816 if (movingObj_orgPos != bo->getAbsPos())
818 QString pold=qpointfToString(movingObj_orgPos);
819 QString pnow=qpointfToString(bo->getAbsPos());
825 QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow));
829 if (model->selectionType() == Selection::Branch )
830 { // A branch was moved
832 // save the position in case we link to mapcenter
833 QPointF savePos=QPointF (lmosel->getAbsPos() );
835 // Reset the temporary drawn link to the original one
836 lmosel->unsetParObjTmp();
838 // For Redo we may need to save original selection
839 QString preSelStr=model->getSelectString(lmosel);
844 // We have a destination, relink to that
846 BranchObj* bsel=model->getSelectedBranch();
847 BranchObj* bdst=(BranchObj*)dst;
849 QString preParStr=model->getSelectString (bsel->getParObj());
850 QString preNum=QString::number (bsel->getNum(),10);
851 QString preDstParStr;
853 if (e->state() & Qt::ShiftModifier && dst->getParObj())
855 preDstParStr=model->getSelectString (dst->getParObj());
856 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
858 if (e->state() & Qt::ControlModifier && dst->getParObj())
861 preDstParStr=model->getSelectString (dst->getParObj());
862 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
865 preDstParStr=model->getSelectString(dst);
866 bsel->linkTo (bdst,-1);
867 if (dst->getDepth()==0) bsel->move (savePos);
869 QString postSelStr=model->getSelectString(lmosel);
870 QString postNum=QString::number (bsel->getNum(),10);
872 QString undoCom="linkTo (\""+
873 preParStr+ "\"," + preNum +"," +
874 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
876 QString redoCom="linkTo (\""+
877 preDstParStr + "\"," + postNum + "," +
878 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
883 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
885 model->reposition(); // not necessary if we undo temporary move below
888 // No destination, undo temporary move
890 if (lmosel->getDepth()==1)
892 // The select string might be different _after_ moving around.
893 // Therefor reposition and then use string of old selection, too
896 QPointF rp(lmosel->getRelPos());
897 if (rp != movingObj_orgRelPos)
899 QString ps=qpointfToString(rp);
901 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
902 preSelStr, "moveRel "+ps,
903 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
907 // Draw the original link, before selection was moved around
908 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
910 lmosel->setRelPos(); // calc relPos first for starting point
911 QPointF dst=bo->getParObj()->getChildPos();
912 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
914 model->startAnimation(
918 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
924 model->updateSelection();
925 // Finally resize scene, if needed
929 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
930 model->updateActions();
932 // maybe we moved View: set old cursor
933 setCursor (Qt::ArrowCursor);
937 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
939 if (model->isSelectionBlocked() )
945 if (e->button() == Qt::LeftButton )
947 QPointF p = mapToScene(e->pos());
948 LinkableMapObj *lmo=model->findMapObj(p, NULL);
949 if (lmo) { // MapObj was found
950 // First select the MapObj than edit heading
957 void MapEditor::resizeEvent (QResizeEvent* e)
959 QGraphicsView::resizeEvent( e );
962 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
964 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
965 // cerr << event->format(i) << endl;
967 if (event->mimeData()->hasImage())
968 event->acceptProposedAction();
970 if (event->mimeData()->hasUrls())
971 event->acceptProposedAction();
974 void MapEditor::dragMoveEvent(QDragMoveEvent *)
978 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
983 void MapEditor::dropEvent(QDropEvent *event)
985 BranchObj *sel=model->getSelectedBranch();
989 foreach (QString format,event->mimeData()->formats())
990 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
994 if (event->mimeData()->hasImage())
996 QVariant imageData = event->mimeData()->imageData();
997 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
999 if (event->mimeData()->hasUrls())
1000 uris=event->mimeData()->urls();
1008 for (int i=0; i<uris.count();i++)
1010 // Workaround to avoid adding empty branches
1011 if (!uris.at(i).toString().isEmpty())
1013 bo=sel->addBranch();
1016 s=uris.at(i).toLocalFile();
1019 QString file = QDir::fromNativeSeparators(s);
1020 heading = QFileInfo(file).baseName();
1022 if (file.endsWith(".vym", false))
1023 bo->setVymLink(file);
1025 bo->setURL(uris.at(i).toString());
1028 bo->setURL(uris.at(i).toString());
1031 if (!heading.isEmpty())
1032 bo->setHeading(heading);
1034 bo->setHeading(uris.at(i).toString());
1038 model->reposition();
1041 event->acceptProposedAction();
1046 bool isUnicode16(const QByteArray &d)
1048 // TODO: make more precise check for unicode 16.
1049 // Guess unicode16 if any of second bytes are zero
1050 unsigned int length = max(0,d.size()-2)/2;
1051 for (unsigned int i = 0; i<length ; i++)
1052 if (d.at(i*2+1)==0) return true;
1057 // FIXME the following are not needed...
1058 QString MapEditor::getName(const LinkableMapObj*) {return QString();}