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->setMapEditor (this);
46 model->registerEditor(this);
47 model->addMapCenter(); // FIXME create this in MapEditor until BO and MCO are independent of scene
54 // Create bitmap cursors, platform dependant
55 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
56 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
57 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
58 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
60 setFocusPolicy (Qt::StrongFocus);
72 setAcceptDrops (true);
74 model->reposition(); //FIXME really still needed?
77 // Action to embed LineEdit for heading in Scene
79 lineEdit=new QLineEdit;
81 QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit);
84 QAction *a = new QAction( tr( "Edit heading","MapEditor" ), this);
85 a->setShortcut ( Qt::Key_Return ); //Edit heading
86 //a->setShortcutContext (Qt::WindowShortcut);
88 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
89 a = new QAction( tr( "Edit heading","MapEditor" ), this);
90 a->setShortcut ( Qt::Key_Enter); //Edit heading
91 //a->setShortcutContext (Qt::WindowShortcut);
93 connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
95 // Attributes //FIXME testing only...
98 attrTable= new AttributeTable();
100 ad=attrTable->addKey (k,StringList);
104 sl <<"val 1"<<"val 2"<< "val 3";
105 ad->setValue (QVariant (sl));
107 //attrTable->addValue ("Key A","P 1");
108 //attrTable->addValue ("Key A","P 2");
109 //attrTable->addValue ("Key A","P 3");
110 //attrTable->addValue ("Key A","P 4");
112 ad=attrTable->addKey (k,FreeString);
115 //attrTable->addValue ("Key B","w1");
116 //attrTable->addValue ("Key B","w2");
118 k="C - UniqueString";
119 ad=attrTable->addKey (k,UniqueString);
122 //attrTable->addKey ("Key Prio");
123 //attrTable->addValue ("Key Prio","Prio 1");
124 //attrTable->addValue ("Key Prio","Prio 2");
128 MapEditor::~MapEditor()
130 //cout <<"Destructor MapEditor\n";
131 // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes
133 //removeDir(QDir(tmpMapDir)); // FIXME check?!?
134 model->unregisterEditor(this);
137 VymModel* MapEditor::getModel()
142 QGraphicsScene * MapEditor::getScene()
147 void MapEditor::print()
151 printer = new QPrinter;
152 printer->setColorMode (QPrinter::Color);
153 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
154 printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt());
155 printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString());
158 QRectF totalBBox=model->getTotalBBox();
160 // Try to set orientation automagically
161 // Note: Interpretation of generated postscript is amibiguous, if
162 // there are problems with landscape mode, see
163 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
165 if (totalBBox.width()>totalBBox.height())
166 // recommend landscape
167 printer->setOrientation (QPrinter::Landscape);
169 // recommend portrait
170 printer->setOrientation (QPrinter::Portrait);
172 if ( printer->setup(this) )
173 // returns false, if printing is canceled
175 QPainter pp(printer);
177 pp.setRenderHint(QPainter::Antialiasing,true);
179 // Don't print the visualisation of selection
182 QRectF mapRect=totalBBox;
183 QGraphicsRectItem *frame=NULL;
187 // Print frame around map
188 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
189 totalBBox.width()+20, totalBBox.height()+20);
190 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
196 double paperAspect = (double)printer->width() / (double)printer->height();
197 double mapAspect = (double)mapRect.width() / (double)mapRect.height();
199 if (mapAspect>=paperAspect)
201 // Fit horizontally to paper width
202 //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
203 viewBottom=(int)(printer->width()/mapAspect);
206 // Fit vertically to paper height
207 //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
208 viewBottom=printer->height();
213 // Print footer below map
215 font.setPointSize(10);
217 QRectF footerBox(0,viewBottom,printer->width(),15);
218 // FIXME fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
219 pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
223 QRectF (0,0,printer->width(),printer->height()-15),
224 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
227 // Viewport has paper dimension
228 if (frame) delete (frame);
233 // Save settings in vymrc
234 settings.writeEntry("/mainwindow/printerName",printer->printerName());
235 settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat());
236 settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName());
240 void MapEditor::setAntiAlias (bool b)
242 setRenderHint(QPainter::Antialiasing,b);
245 void MapEditor::setSmoothPixmap(bool b)
247 setRenderHint(QPainter::SmoothPixmapTransform,b);
250 void MapEditor::toggleStandardFlag(QString f)
252 BranchObj *bo=model->getSelectedBranch();
256 if (bo->isSetStandardFlag(f))
268 QString("%1 (\"%2\")").arg(u).arg(f),
270 QString("%1 (\"%2\")").arg(r).arg(f),
271 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
272 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
273 model->updateSelection();
277 void MapEditor::updateSelection()
279 // Tell selection to update geometries
280 model->updateSelection();
283 AttributeTable* MapEditor::attributeTable()
288 void MapEditor::testFunction1()
290 BranchObj *bo=model->getSelectedBranch();
291 //if (bo) model->moveAway (bo);
292 if (bo) bo->setLinkStyle (LinkableMapObj::Line);
294 /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
295 if (hidemode==HideNone)
297 setHideTmpMode (HideExport);
298 mapCenter->calcBBoxSizeWithChilds();
299 QRectF totalBBox=mapCenter->getTotalBBox();
300 QRectF mapRect=totalBBox;
301 QCanvasRectangle *frame=NULL;
303 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
305 mapRect.setRect (totalBBox.x(), totalBBox.y(),
306 totalBBox.width(), totalBBox.height());
307 frame=new QCanvasRectangle (mapRect,mapScene);
308 frame->setBrush (QColor(white));
309 frame->setPen (QColor(black));
315 setHideTmpMode (HideNone);
317 cout <<" hidemode="<<hidemode<<endl;
321 void MapEditor::testFunction2()
326 if (hidemode==HideExport)
327 setHideTmpMode (HideNone);
329 setHideTmpMode (HideExport);
333 void MapEditor::editHeading()
337 editHeadingFinished();
340 BranchObj *bo=model->getSelectedBranch();
343 model->setSelectionBlocked(true);
345 lineEdit->setText (bo->getHeading());
346 QPoint p = mapTo (this,bo->getAbsPos().toPoint() );
347 lineEdit->setGeometry(p.x(),p.y(),230,25);
348 lineEdit->selectAll();
350 lineEdit->setFocus();
351 lineEdit->grabKeyboard();
356 void MapEditor::editHeadingFinished()
358 editingHeading=false;
359 lineEdit->releaseKeyboard();
360 model->setHeading (lineEdit->text() );
361 model->setSelectionBlocked(false);
364 // Maybe reselect previous branch
365 mainWindow->editHeadingFinished (model);
369 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
371 // Lineedits are already closed by preceding
372 // mouseEvent, we don't need to close here.
374 QPointF p = mapToScene(e->pos());
375 LinkableMapObj* lmo=model->findMapObj(p, NULL);
378 { // MapObj was found
379 if (model->getSelection() != lmo)
385 if (model->getSelectedBranch() )
387 // Context Menu on branch or mapcenter
388 model->updateActions();
389 branchContextMenu->popup(e->globalPos() );
392 if (model->getSelectedFloatImage() )
394 // Context Menu on floatimage
395 model->updateActions();
396 floatimageContextMenu->popup(e->globalPos() );
400 { // No MapObj found, we are on the Canvas itself
401 // Context Menu on scene
402 model->updateActions();
404 canvasContextMenu->popup(e->globalPos() );
409 void MapEditor::keyPressEvent(QKeyEvent* e)
411 if (e->modifiers() & Qt::ControlModifier)
413 switch (mainWindow->getModMode())
415 case Main::ModModeColor:
416 setCursor (PickColorCursor);
418 case Main::ModModeCopy:
419 setCursor (CopyCursor);
421 case Main::ModModeXLink:
422 setCursor (XLinkCursor);
425 setCursor (Qt::ArrowCursor);
431 void MapEditor::keyReleaseEvent(QKeyEvent* e)
433 if (!(e->modifiers() & Qt::ControlModifier))
434 setCursor (Qt::ArrowCursor);
437 void MapEditor::mousePressEvent(QMouseEvent* e)
439 // Ignore right clicks, these will go to context menus
440 if (e->button() == Qt::RightButton )
446 //Ignore clicks while editing heading
447 if (model->isSelectionBlocked() )
453 QPointF p = mapToScene(e->pos());
454 LinkableMapObj* lmo=model->findMapObj(p, NULL);
458 //Take care of system flags _or_ modifier modes
460 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
461 typeid(*lmo)==typeid(MapCenterObj) ))
463 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
464 if (!foname.isEmpty())
466 // systemFlag clicked
467 model->selectInt (lmo);
470 if (e->state() & Qt::ControlModifier)
471 mainWindow->editOpenURLTab();
473 mainWindow->editOpenURL();
475 else if (foname=="vymLink")
477 mainWindow->editOpenVymLink();
478 // tabWidget may change, better return now
479 // before segfaulting...
480 } else if (foname=="note")
481 mainWindow->windowToggleNoteEditor();
482 else if (foname=="hideInExport")
483 model->toggleHideExport();
484 // FIXME needed? xelection.update();
488 // No system flag clicked, take care of modmodes (CTRL-Click)
489 if (e->state() & Qt::ControlModifier)
491 if (mainWindow->getModMode()==Main::ModModeColor)
494 setCursor (PickColorCursor);
497 if (mainWindow->getModMode()==Main::ModModeXLink)
499 BranchObj *bo_begin=NULL;
501 bo_begin=(BranchObj*)(lmo);
503 bo_begin=model->getSelectedBranch();
507 linkingObj_src=bo_begin;
508 tmpXLink=new XLinkObj (mapScene);
509 tmpXLink->setBegin (bo_begin);
510 tmpXLink->setEnd (p);
511 tmpXLink->setColor(model->getMapDefXLinkColor());
512 tmpXLink->setWidth(model->getMapDefXLinkWidth());
513 tmpXLink->updateXLink();
514 tmpXLink->setVisibility (true);
522 // Select the clicked object
523 model->selectInt (lmo);
525 // Left Button Move Branches
526 if (e->button() == Qt::LeftButton )
528 //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here
529 //movingObj_start.setY( p.y() - selection->y() );
530 movingObj_start.setX( p.x() - lmo->x() );
531 movingObj_start.setY( p.y() - lmo->y() );
532 movingObj_orgPos.setX (lmo->x() );
533 movingObj_orgPos.setY (lmo->y() );
535 movingObj_orgRelPos=lmo->getRelPos();
537 // If modMode==copy, then we want to "move" the _new_ object around
538 // then we need the offset from p to the _old_ selection, because of tmp
539 if (mainWindow->getModMode()==Main::ModModeCopy &&
540 e->state() & Qt::ControlModifier)
542 BranchObj *bo=model->getSelectedBranch();
546 bo->addBranch ((BranchObj*)model->getSelection());
548 model->select(bo->getLastBranch());
553 movingObj=model->getSelection();
555 // Middle Button Toggle Scroll
556 // (On Mac OS X this won't work, but we still have
557 // a button in the toolbar)
558 if (e->button() == Qt::MidButton )
559 model->toggleScroll();
560 model->updateActions();
561 // FIXME needed? xelection.update();
563 { // No MapObj found, we are on the scene itself
564 // Left Button move Pos of sceneView
565 if (e->button() == Qt::LeftButton )
567 movingObj=NULL; // move Content not Obj
568 movingObj_start=e->globalPos();
569 movingCont_start=QPointF (
570 horizontalScrollBar()->value(),
571 verticalScrollBar()->value());
572 movingVec=QPointF(0,0);
573 setCursor(HandOpenCursor);
578 void MapEditor::mouseMoveEvent(QMouseEvent* e)
580 QPointF p = mapToScene(e->pos());
581 LinkableMapObj *lmosel=model->getSelection();
583 // Move the selected MapObj
584 if ( lmosel && movingObj)
586 // reset cursor if we are moving and don't copy
587 if (mainWindow->getModMode()!=Main::ModModeCopy)
588 setCursor (Qt::ArrowCursor);
590 // To avoid jumping of the sceneView, only
591 // ensureSelectionVisible, if not tmp linked
592 if (!lmosel->hasParObjTmp())
593 model->ensureSelectionVisible ();
595 // Now move the selection, but add relative position
596 // (movingObj_start) where selection was chosen with
597 // mousepointer. (This avoids flickering resp. jumping
598 // of selection back to absPos)
600 // Check if we could link
601 LinkableMapObj* lmo=model->findMapObj(p, lmosel);
604 FloatObj *fio=model->getSelectedFloatImage();
607 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
609 fio->updateLink(); //no need for reposition, if we update link here
610 model->updateSelection();
612 // Relink float to new mapcenter or branch, if shift is pressed
613 // Only relink, if selection really has a new parent
614 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
615 ( (typeid(*lmo)==typeid(BranchObj)) ||
616 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
617 ( lmo != fio->getParObj())
620 if (typeid(*fio) == typeid(FloatImageObj) &&
621 ( (typeid(*lmo)==typeid(BranchObj) ||
622 typeid(*lmo)==typeid(MapCenterObj)) ))
625 // Also save the move which was done so far
626 QString pold=qpointfToString(movingObj_orgRelPos);
627 QString pnow=qpointfToString(fio->getRelPos());
633 QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
634 fio->getParObj()->requestReposition();
637 model->linkFloatImageTo (model->getSelectString(lmo));
639 //movingObj_orgRelPos=lmosel->getRelPos();
645 { // selection != a FloatObj
646 if (lmosel->getDepth()==0)
649 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
650 ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
652 lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
653 model->updateRelPositions();
656 if (lmosel->getDepth()==1)
659 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
663 // Move ordinary branch
664 if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter)
665 // Add width of bbox here, otherwise alignRelTo will cause jumping around
666 lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(),
667 p.y()-movingObj_start.y() +lmosel->getTopPad() );
669 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
673 // Maybe we can relink temporary?
674 if (lmo && (lmo!=lmosel) && model->getSelectedBranch() &&
675 (typeid(*lmo)==typeid(BranchObj) ||
676 typeid(*lmo)==typeid(MapCenterObj)) )
679 if (e->modifiers()==Qt::ControlModifier)
681 // Special case: CTRL to link below lmo
682 lmosel->setParObjTmp (lmo,p,+1);
684 else if (e->modifiers()==Qt::ShiftModifier)
685 lmosel->setParObjTmp (lmo,p,-1);
687 lmosel->setParObjTmp (lmo,p,0);
690 lmosel->unsetParObjTmp();
692 // reposition subbranch
693 lmosel->reposition();
696 model->updateSelection();// FIXME needed?
697 } // no FloatImageObj
701 } // selection && moving_obj
703 // Draw a link from one branch to another
706 tmpXLink->setEnd (p);
707 tmpXLink->updateXLink();
711 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
713 QPointF p=e->globalPos();
714 movingVec.setX(-p.x() + movingObj_start.x() );
715 movingVec.setY(-p.y() + movingObj_start.y() );
716 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
717 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
722 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
724 QPointF p = mapToScene(e->pos());
726 LinkableMapObj *lmosel=model->getSelection();
727 // Have we been picking color?
731 setCursor (Qt::ArrowCursor);
732 // Check if we are over another branch
733 dst=model->findMapObj(p, NULL);
736 if (e->state() & Qt::ShiftModifier)
737 model->colorBranch (((BranchObj*)dst)->getColor());
739 model->colorSubtree (((BranchObj*)dst)->getColor());
744 // Have we been drawing a link?
748 // Check if we are over another branch
749 dst=model->findMapObj(p, NULL);
752 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
753 tmpXLink->updateXLink();
754 tmpXLink->activate(); //FIXME savestate missing
755 //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) );
764 // Have we been moving something?
765 if ( lmosel && movingObj )
767 FloatImageObj *fo=model->getSelectedFloatImage();
770 // Moved FloatObj. Maybe we need to reposition
771 QString pold=qpointfToString(movingObj_orgRelPos);
772 QString pnow=qpointfToString(fo->getRelPos());
778 QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
780 fo->getParObj()->requestReposition();
784 // Check if we are over another branch, but ignore
785 // any found LMOs, which are FloatObjs
786 dst=model->findMapObj(mapToScene(e->pos() ), lmosel);
788 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
791 BranchObj *bo=model->getSelectedBranch();
792 if (bo && bo->getDepth()==0)
794 if (movingObj_orgPos != bo->getAbsPos())
796 QString pold=qpointfToString(movingObj_orgPos);
797 QString pnow=qpointfToString(bo->getAbsPos());
803 QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow));
807 if (model->selectionType() == Selection::Branch )
808 { // A branch was moved
810 // save the position in case we link to mapcenter
811 QPointF savePos=QPointF (lmosel->getAbsPos() );
813 // Reset the temporary drawn link to the original one
814 lmosel->unsetParObjTmp();
816 // For Redo we may need to save original selection
817 QString preSelStr=model->getSelectString(lmosel);
822 // We have a destination, relink to that
824 BranchObj* bsel=model->getSelectedBranch();
825 BranchObj* bdst=(BranchObj*)dst;
827 QString preParStr=model->getSelectString (bsel->getParObj());
828 QString preNum=QString::number (bsel->getNum(),10);
829 QString preDstParStr;
831 if (e->state() & Qt::ShiftModifier && dst->getParObj())
833 preDstParStr=model->getSelectString (dst->getParObj());
834 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
836 if (e->state() & Qt::ControlModifier && dst->getParObj())
839 preDstParStr=model->getSelectString (dst->getParObj());
840 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
843 preDstParStr=model->getSelectString(dst);
844 bsel->linkTo (bdst,-1);
845 if (dst->getDepth()==0) bsel->move (savePos);
847 QString postSelStr=model->getSelectString(lmosel);
848 QString postNum=QString::number (bsel->getNum(),10);
850 QString undoCom="linkTo (\""+
851 preParStr+ "\"," + preNum +"," +
852 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
854 QString redoCom="linkTo (\""+
855 preDstParStr + "\"," + postNum + "," +
856 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
861 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
863 model->reposition(); // not necessary if we undo temporary move below
866 // No destination, undo temporary move
868 if (lmosel->getDepth()==1)
870 // The select string might be different _after_ moving around.
871 // Therefor reposition and then use string of old selection, too
874 QPointF rp(lmosel->getRelPos());
875 if (rp != movingObj_orgRelPos)
877 QString ps=qpointfToString(rp);
879 model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
880 preSelStr, "moveRel "+ps,
881 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
885 // Draw the original link, before selection was moved around
886 if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1)
888 lmosel->setRelPos(); // calc relPos first for starting point
889 QPointF dst=bo->getParObj()->getChildPos();
890 // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() );
892 model->startAnimation(
895 // QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() )
901 model->updateSelection();
902 // Finally resize scene, if needed
906 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
907 model->updateActions();
909 // maybe we moved View: set old cursor
910 setCursor (Qt::ArrowCursor);
914 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
916 if (model->isSelectionBlocked() )
922 if (e->button() == Qt::LeftButton )
924 QPointF p = mapToScene(e->pos());
925 LinkableMapObj *lmo=model->findMapObj(p, NULL);
926 if (lmo) { // MapObj was found
927 // First select the MapObj than edit heading
934 void MapEditor::resizeEvent (QResizeEvent* e)
936 QGraphicsView::resizeEvent( e );
939 void MapEditor::dragEnterEvent(QDragEnterEvent *event)
941 //for (unsigned int i=0;event->format(i);i++) // Debug mime type
942 // cerr << event->format(i) << endl;
944 if (event->mimeData()->hasImage())
945 event->acceptProposedAction();
947 if (event->mimeData()->hasUrls())
948 event->acceptProposedAction();
951 void MapEditor::dragMoveEvent(QDragMoveEvent *)
955 void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
960 void MapEditor::dropEvent(QDropEvent *event)
962 BranchObj *sel=model->getSelectedBranch();
966 foreach (QString format,event->mimeData()->formats())
967 cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
971 if (event->mimeData()->hasImage())
973 QVariant imageData = event->mimeData()->imageData();
974 model->addFloatImage (qvariant_cast<QPixmap>(imageData));
976 if (event->mimeData()->hasUrls())
977 uris=event->mimeData()->urls();
985 for (int i=0; i<uris.count();i++)
987 // Workaround to avoid adding empty branches
988 if (!uris.at(i).toString().isEmpty())
993 s=uris.at(i).toLocalFile();
996 QString file = QDir::fromNativeSeparators(s);
997 heading = QFileInfo(file).baseName();
999 if (file.endsWith(".vym", false))
1000 bo->setVymLink(file);
1002 bo->setURL(uris.at(i).toString());
1005 bo->setURL(uris.at(i).toString());
1008 if (!heading.isEmpty())
1009 bo->setHeading(heading);
1011 bo->setHeading(uris.at(i).toString());
1015 model->reposition();
1018 event->acceptProposedAction();
1023 bool isUnicode16(const QByteArray &d)
1025 // TODO: make more precise check for unicode 16.
1026 // Guess unicode16 if any of second bytes are zero
1027 unsigned int length = max(0,d.size()-2)/2;
1028 for (unsigned int i = 0; i<length ; i++)
1029 if (d.at(i*2+1)==0) return true;
1034 // FIXME the following are not needed...
1035 QString MapEditor::getName(const LinkableMapObj*) {return QString();}