3 #include <q3dragobject.h>
4 #include <q3urloperator.h>
5 #include <q3networkprotocol.h>
6 #include <q3paintdevicemetrics.h>
7 #include <q3filedialog.h>
16 #include "editxlinkdialog.h"
18 #include "extrainfodialog.h"
20 #include "linkablemapobj.h"
21 #include "mainwindow.h"
23 #include "texteditor.h"
24 #include "warningdialog.h"
28 extern TextEditor *textEditor;
29 extern int statusbarTime;
30 extern Main *mainWindow;
31 extern QString tmpVymDir;
32 extern QString clipboardDir;
33 extern bool clipboardEmpty;
34 extern FlagRowObj *standardFlagsDefault;
36 extern QMenu* branchContextMenu;
37 extern QMenu* branchAddContextMenu;
38 extern QMenu* branchRemoveContextMenu;
39 extern QMenu* branchLinksContextMenu;
40 extern QMenu* branchXLinksContextMenuEdit;
41 extern QMenu* branchXLinksContextMenuFollow;
42 extern QMenu* floatimageContextMenu;
43 extern QMenu* canvasContextMenu;
46 extern Settings settings;
47 extern ImageIO imageIO;
49 extern QString vymName;
50 extern QString vymVersion;
52 extern QString iconPath;
53 extern QDir vymBaseDir;
54 extern QDir lastImageDir;
56 int MapEditor::mapNum=0; // make instance
58 ///////////////////////////////////////////////////////////////////////
59 ///////////////////////////////////////////////////////////////////////
60 MapEditor::MapEditor( QWidget* parent) :
61 QGraphicsView(parent), urlOperator(0), imageBuffer(0)
63 //cout << "Constructor ME "<<this<<endl;
66 viewport()->setAcceptDrops(true);
68 mapScene= new QGraphicsScene(parent);
69 //mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
70 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
75 /* FIXME scrollview handles not needed in QT4?
76 // Maybe check QAbstractScrollArea...
77 // Always show scroll bars (automatic would flicker sometimes)
78 setVScrollBarMode ( QScrollView::AlwaysOn );
79 setHScrollBarMode ( QScrollView::AlwaysOn );
82 mapCenter = new MapCenterObj(mapScene);
83 mapCenter->setVisibility (true);
84 mapCenter->setMapEditor (this);
85 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
86 //mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2);
91 defLinkColor=QColor (0,0,255);
92 defXLinkColor=QColor (180,180,180);
93 linkcolorhint=DefaultColor;
94 linkstyle=StylePolyParabel;
96 // Create bitmap cursors, platform dependant
97 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
98 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
99 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
100 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
102 setFocusPolicy (Qt::StrongFocus);
113 xelection.setMapCenter (mapCenter);
116 defXLinkColor=QColor (230,230,230);
124 fileName=tr("unnamed");
127 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
128 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
130 // Initialize find routine
137 blockReposition=false;
138 blockSaveState=false;
142 // Create temporary files
145 // Initially set movingCentre
148 mapCenter->reposition(); // for positioning heading
152 MapEditor::~MapEditor()
154 if (imageBuffer) delete imageBuffer;
160 //cout <<"Destructor MapEditor\n";
163 MapCenterObj* MapEditor::getMapCenter()
168 QGraphicsScene * MapEditor::getScene()
173 void MapEditor::adjustCanvasSize()
176 /* FIXME QT4 adjustcanvassize probably not needed any longer!
178 // To adjust the scene to map, viewport size and position, we have to
179 // do some coordinate magic...
181 // Get rectangle of (scroll-)view.
182 // We want to be in scene coords, so
183 // we map. Important if view is zoomed...
184 QRectF view = inverseWorldMatrix().mapRect( QRectF( contentsX(), contentsY(),
185 visibleWidth(), visibleHeight()) );
187 // Now we need the bounding box of view AND map to calc the correct scene size.
188 // Why? Because if the map itself is moved out of view, the view has to be enlarged
189 // to avoid jumping aroung...
190 QRectF map=mapCenter->getTotalBBox();
192 // right edge - left edge
193 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
194 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
197 if ( (cw!=mapScene->width()) || (ch!=mapScene->height()) ||
198 !mapScene->onCanvas (map.topLeft()) || !mapScene->onCanvas (map.bottomRight())
201 // move the map on scene (in order to not move it on screen) this is neccessary
202 // a) if topleft corner of scene is left or above topleft corner of view and also left of
203 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
204 // to scroll to an empty area of scene to the left.
205 // b) if topleft corner of map left of or above topleft of scene
209 if (cw > mapScene->width() )
211 if (map.x()<0) dx=-map.x();
213 if (cw < mapScene->width() )
214 dx=-min (view.x(),map.x());
215 if (ch > mapScene->height() )
217 if (map.y()<0) dy=-map.y();
219 if (ch < mapScene->height() )
221 dy=-min (view.y(),map.y());
223 // We really have to resize now. Let's go...
224 // FIXME old code mapScene->resize (cw,ch);
225 mapScene->setSceneRect (QRectFF(0,0,cw,ch));
226 if ( (dx!=0) || (dy!=0) )
228 mapCenter->moveAllBy(dx,dy);
229 mapCenter->reposition();
230 // mapCenter->positionBBox(); // To move float
232 // scroll the view (in order to not move map on screen)
240 bool MapEditor::isRepositionBlocked()
242 return blockReposition;
245 QString MapEditor::getName (LinkableMapObj *lmo)
248 if (!lmo) return QString("Error: NULL has no name!");
250 if ((typeid(*lmo) == typeid(BranchObj) ||
251 typeid(*lmo) == typeid(MapCenterObj)))
254 s=(((BranchObj*)lmo)->getHeading());
255 if (s=="") s="unnamed";
256 return QString("branch (%1)").arg(s);
257 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
259 if ((typeid(*lmo) == typeid(FloatImageObj) ))
260 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
261 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
262 return QString("Unknown type has no name!");
265 void MapEditor::makeTmpDirs()
267 // Create unique temporary directories
268 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
269 histPath=QDir::convertSeparators (tmpMapDir+"/history");
274 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
276 // tmpdir temporary directory to which data will be written
277 // prefix mapname, which will be appended to images etc.
278 // writeflags Only write flags for "real" save of map, not undo
279 // offset offset of bbox of whole map in scene.
280 // Needed for XML export
296 ls="StylePolyParabel";
300 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
302 if (linkcolorhint==HeadingColor)
303 colhint=attribut("linkColorHint","HeadingColor");
305 QString mapAttr=attribut("version",vymVersion);
306 if (!saveSel || saveSel==mapCenter)
307 mapAttr+= attribut("author",mapCenter->getAuthor()) +
308 attribut("comment",mapCenter->getComment()) +
309 attribut("date",mapCenter->getDate()) +
310 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
311 attribut("linkStyle", ls ) +
312 attribut("linkColor", defLinkColor.name() ) +
313 attribut("defXLinkColor", defXLinkColor.name() ) +
314 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
316 s+=beginElement("vymmap",mapAttr);
319 // Find the used flags while traversing the tree
320 standardFlagsDefault->resetUsedCounter();
322 // Reset the counters before saving
323 // TODO constr. of FIO creates lots of objects, better do this in some other way...
324 FloatImageObj (mapScene).resetSaveCounter();
326 // Build xml recursivly
327 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
328 // Save complete map, if saveSel not set
329 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
332 if ( typeid(*saveSel) == typeid(BranchObj) )
334 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
335 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
337 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
340 // Save local settings
341 s+=settings.getXMLData (destPath);
344 if (selection && !saveSel )
345 s+=valueElement("select",selection->getSelectString());
348 s+=endElement("vymmap");
351 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
355 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
357 // save the selected part of the map, Undo will replace part of map
358 QString undoSelection="";
360 undoSelection=undoSel->getSelectString();
362 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
363 QString redoSelection="";
365 redoSelection=undoSel->getSelectString();
367 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
370 saveState (PartOfMap,
371 undoSelection, "addMapReplace (\"PATH\")",
377 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
381 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
384 QString undoSelection=redoSel->getParObj()->getSelectString();
385 QString redoSelection=redoSel->getSelectString();
386 if (typeid(*redoSel) == typeid(BranchObj) )
388 // save the selected branch of the map, Undo will insert part of map
389 saveState (PartOfMap,
390 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
391 redoSelection, "delete ()",
398 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
400 // "Normal" savestate: save commands, selections and comment
401 // so just save commands for undo and redo
402 // and use current selection
404 QString redoSelection="";
405 if (redoSel) redoSelection=redoSel->getSelectString();
406 QString undoSelection="";
407 if (undoSel) undoSelection=undoSel->getSelectString();
409 saveState (UndoCommand,
416 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
418 // "Normal" savestate: save commands, selections and comment
419 // so just save commands for undo and redo
420 // and use current selection
421 saveState (UndoCommand,
429 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
433 if (blockSaveState) return;
435 /* TODO remove after testing
437 cout << "ME::saveState() "<<endl;
439 int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
440 int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
441 int curStep=undoSet.readNumEntry ("/history/curStep",0);
442 // Find out current undo directory
443 if (undosAvail<stepsTotal) undosAvail++;
445 if (curStep>stepsTotal) curStep=1;
447 QString backupXML="";
448 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
449 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
450 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
452 // Create bakMapDir if not available
455 makeSubDirs (bakMapDir);
457 // Save depending on how much needs to be saved
459 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPointF (),saveSel);
461 QString undoCommand="";
462 if (savemode==UndoCommand)
466 else if (savemode==PartOfMap )
469 undoCommand.replace ("PATH",bakMapPath);
472 if (!backupXML.isEmpty())
473 // Write XML Data to disk
474 saveStringToDisk (QString(bakMapPath),backupXML);
476 // We would have to save all actions in a tree, to keep track of
477 // possible redos after a action. Possible, but we are too lazy: forget about redos.
480 // Write the current state to disk
481 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
482 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
483 undoSet.setEntry ("/history/curStep",QString::number(curStep));
484 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
485 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
486 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
487 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
488 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
489 undoSet.setEntry (QString("/history/version"),vymVersion);
490 undoSet.writeSettings(histPath);
492 /* TODO remove after testing
494 //cout << " into="<< histPath.toStdString()<<endl;
495 cout << " stepsTotal="<<stepsTotal<<
496 ", undosAvail="<<undosAvail<<
497 ", redosAvail="<<redosAvail<<
498 ", curStep="<<curStep<<endl;
499 cout << " ---------------------------"<<endl;
500 cout << " comment="<<comment.toStdString()<<endl;
501 cout << " undoCom="<<undoCommand.toStdString()<<endl;
502 cout << " undoSel="<<undoSelection.toStdString()<<endl;
503 cout << " redoCom="<<redoCom.toStdString()<<endl;
504 cout << " redoSel="<<redoSelection.toStdString()<<endl;
505 if (saveSel) cout << " saveSel="<<saveSel->getSelectString().ascii()<<endl;
506 cout << " ---------------------------"<<endl;
508 mainWindow->updateHistory (undoSet);
513 void MapEditor::parseAtom(const QString &atom)
520 // Split string s into command and parameters
521 api.parseInput (atom);
522 QString com=api.command();
525 if (com=="addBranch")
529 api.setError (Aborted,"Nothing selected");
530 } else if ( (typeid(*selection) != typeid(BranchObj) &&
531 typeid(*selection) != typeid(MapCenterObj)) )
533 api.setError (Aborted,"Type of selection is not a branch");
538 if (api.checkParamCount(pl))
540 if (api.paramCount()==0)
541 addNewBranchInt (-2);
545 if (ok ) addNewBranchInt (y);
549 } else if (com=="addBranchBefore")
553 api.setError (Aborted,"Nothing selected");
554 } else if ( (typeid(*selection) != typeid(BranchObj) &&
555 typeid(*selection) != typeid(MapCenterObj)) )
557 api.setError (Aborted,"Type of selection is not a branch");
560 if (api.paramCount()==0)
562 addNewBranchBefore ();
565 } else if (com==QString("addMapReplace"))
569 api.setError (Aborted,"Nothing selected");
570 } else if ( (typeid(*selection) != typeid(BranchObj) &&
571 typeid(*selection) != typeid(MapCenterObj)) )
573 api.setError (Aborted,"Type of selection is not a branch");
574 } else if (api.checkParamCount(1))
576 //s=api.parString (ok,0); // selection
577 t=api.parString (ok,0); // path to map
578 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
579 addMapReplaceInt(selection->getSelectString(),t);
581 } else if (com==QString("addMapInsert"))
585 api.setError (Aborted,"Nothing selected");
586 } else if ( (typeid(*selection) != typeid(BranchObj) &&
587 typeid(*selection) != typeid(MapCenterObj)) )
589 api.setError (Aborted,"Type of selection is not a branch");
592 if (api.checkParamCount(2))
594 t=api.parString (ok,0); // path to map
595 y=api.parInt(ok,1); // position
596 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
597 addMapInsertInt(t,y);
600 } else if (com=="colorItem")
604 api.setError (Aborted,"Nothing selected");
605 } else if ( typeid(*selection) != typeid(BranchObj) &&
606 typeid(*selection) != typeid(MapCenterObj))
608 api.setError (Aborted,"Type of selection is not a branch");
609 } else if (api.checkParamCount(1))
611 QColor c=api.parColor (ok,0);
612 if (ok) colorItem (c);
614 } else if (com=="colorBranch")
618 api.setError (Aborted,"Nothing selected");
619 } else if ( typeid(*selection) != typeid(BranchObj) &&
620 typeid(*selection) != typeid(MapCenterObj))
622 api.setError (Aborted,"Type of selection is not a branch");
623 } else if (api.checkParamCount(1))
625 QColor c=api.parColor (ok,0);
626 if (ok) colorBranch (c);
628 } else if (com=="cut")
632 api.setError (Aborted,"Nothing selected");
633 } else if ( typeid(*selection) != typeid(BranchObj) &&
634 typeid(*selection) != typeid(MapCenterObj) &&
635 typeid(*selection) != typeid(FloatImageObj) )
637 api.setError (Aborted,"Type of selection is not a branch or floatimage");
638 } else if (api.checkParamCount(0))
642 } else if (com=="delete")
646 api.setError (Aborted,"Nothing selected");
647 } else if ( (typeid(*selection) != typeid(BranchObj) &&
648 typeid(*selection) != typeid(MapCenterObj)) )
650 api.setError (Aborted,"Type of selection is not a branch");
651 } else if (api.checkParamCount(0))
655 } else if (com=="deleteKeepChilds")
659 api.setError (Aborted,"Nothing selected");
660 } else if ( (typeid(*selection) != typeid(BranchObj) &&
661 typeid(*selection) != typeid(MapCenterObj)) )
663 api.setError (Aborted,"Type of selection is not a branch");
664 } else if (api.checkParamCount(0))
668 } else if (com=="deleteChilds")
672 api.setError (Aborted,"Nothing selected");
673 } else if ( (typeid(*selection) != typeid(BranchObj) &&
674 typeid(*selection) != typeid(MapCenterObj)) )
676 api.setError (Aborted,"Type of selection is not a branch");
677 } else if (api.checkParamCount(0))
681 } else if (com=="linkBranchToPos")
685 api.setError (Aborted,"Nothing selected");
686 } else if ( (typeid(*selection) != typeid(BranchObj) &&
687 typeid(*selection) != typeid(MapCenterObj)) )
689 api.setError (Aborted,"Type of selection is not a branch");
690 } else if (api.checkParamCount(4))
692 // 0 selectstring of parent
693 // 1 num in parent (for branches)
694 // 2,3 x,y of mainbranch or mapcenter
695 s=api.parString(ok,0);
696 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
699 if (typeid(*dst) == typeid(BranchObj) )
701 // Get number in parent
704 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
705 } else if (typeid(*dst) == typeid(MapCenterObj) )
707 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
708 // Get coordinates of mainbranch
713 if (ok) ((BranchObj*)selection)->move (x,y);
718 } else if (com=="moveBranchUp")
722 api.setError (Aborted,"Nothing selected");
723 } else if ( (typeid(*selection) != typeid(BranchObj) &&
724 typeid(*selection) != typeid(MapCenterObj)) )
726 api.setError (Aborted,"Type of selection is not a branch");
727 } else if (api.checkParamCount(0))
731 } else if (com=="moveBranchDown")
735 api.setError (Aborted,"Nothing selected");
736 } else if ( (typeid(*selection) != typeid(BranchObj) &&
737 typeid(*selection) != typeid(MapCenterObj)) )
739 api.setError (Aborted,"Type of selection is not a branch");
740 } else if (api.checkParamCount(0))
744 } else if (com=="move")
748 api.setError (Aborted,"Nothing selected");
749 } else if ( typeid(*selection) != typeid(BranchObj) &&
750 typeid(*selection) != typeid(MapCenterObj) &&
751 typeid(*selection) != typeid(FloatImageObj) )
753 api.setError (Aborted,"Type of selection is not a branch or floatimage");
754 } else if (api.checkParamCount(2))
763 } else if (com=="moveRel")
767 api.setError (Aborted,"Nothing selected");
768 } else if ( typeid(*selection) != typeid(BranchObj) &&
769 typeid(*selection) != typeid(MapCenterObj) &&
770 typeid(*selection) != typeid(FloatImageObj) )
772 api.setError (Aborted,"Type of selection is not a branch or floatimage");
773 } else if (api.checkParamCount(2))
779 if (ok) moveRel (x,y);
782 } else if (com=="paste")
786 api.setError (Aborted,"Nothing selected");
787 } else if ( typeid(*selection) != typeid(BranchObj) &&
788 typeid(*selection) != typeid(MapCenterObj) )
790 api.setError (Aborted,"Type of selection is not a branch");
791 } else if (api.checkParamCount(0))
795 } else if (com=="select")
797 if (api.checkParamCount(1))
799 s=api.parString(ok,0);
802 } else if (com=="setMapAuthor")
804 if (api.checkParamCount(1))
806 s=api.parString(ok,0);
807 if (ok) setMapAuthor (s);
809 } else if (com=="setMapComment")
811 if (api.checkParamCount(1))
813 s=api.parString(ok,0);
814 if (ok) setMapComment(s);
816 } else if (com=="setMapBackgroundColor")
820 api.setError (Aborted,"Nothing selected");
821 } else if ( (typeid(*selection) != typeid(BranchObj) &&
822 typeid(*selection) != typeid(MapCenterObj)) )
824 api.setError (Aborted,"Type of selection is not a branch");
825 } else if (api.checkParamCount(1))
827 QColor c=api.parColor (ok,0);
828 if (ok) setMapBackgroundColor (c);
830 } else if (com=="setMapDefLinkColor")
834 api.setError (Aborted,"Nothing selected");
835 } else if ( (typeid(*selection) != typeid(BranchObj) &&
836 typeid(*selection) != typeid(MapCenterObj)) )
838 api.setError (Aborted,"Type of selection is not a branch");
839 } else if (api.checkParamCount(1))
841 QColor c=api.parColor (ok,0);
842 if (ok) setMapDefLinkColor (c);
844 } else if (com=="setMapLinkStyle")
846 if (api.checkParamCount(1))
848 s=api.parString (ok,0);
849 if (ok) setMapLinkStyle(s);
851 } else if (com=="setHeading")
855 api.setError (Aborted,"Nothing selected");
856 } else if ( (typeid(*selection) != typeid(BranchObj) &&
857 typeid(*selection) != typeid(MapCenterObj)) )
859 api.setError (Aborted,"Type of selection is not a branch");
860 } else if (api.checkParamCount(1))
862 s=api.parString (ok,0);
866 } else if (com=="setHideExport")
870 api.setError (Aborted,"Nothing selected");
871 } else if ( typeid(*selection) != typeid(BranchObj) &&
872 typeid(*selection) != typeid(FloatImageObj) )
874 api.setError (Aborted,"Type of selection is not a branch or floatimage");
875 } else if (api.checkParamCount(1))
878 if (ok) setHideExport (b);
880 } else if (com=="setURL")
884 api.setError (Aborted,"Nothing selected");
885 } else if ( (typeid(*selection) != typeid(BranchObj) &&
886 typeid(*selection) != typeid(MapCenterObj)) )
888 api.setError (Aborted,"Type of selection is not a branch");
889 } else if (api.checkParamCount(1))
891 s=api.parString (ok,0);
892 if (ok) setURLInt(s);
894 } else if (com=="setVymLink")
898 api.setError (Aborted,"Nothing selected");
899 } else if ( (typeid(*selection) != typeid(BranchObj) &&
900 typeid(*selection) != typeid(MapCenterObj)) )
902 api.setError (Aborted,"Type of selection is not a branch");
903 } else if (api.checkParamCount(1))
905 s=api.parString (ok,0);
906 if (ok) setVymLinkInt(s);
909 else if (com=="setFlag")
913 api.setError (Aborted,"Nothing selected");
914 } else if ( (typeid(*selection) != typeid(BranchObj) &&
915 typeid(*selection) != typeid(MapCenterObj)) )
917 api.setError (Aborted,"Type of selection is not a branch");
918 } else if (api.checkParamCount(1))
920 s=api.parString(ok,0);
923 BranchObj* bo=(BranchObj*)selection;
924 bo->activateStandardFlag(s);
925 bo->updateFlagsToolbar();
929 else if (com=="unsetFlag")
933 api.setError (Aborted,"Nothing selected");
934 } else if ( (typeid(*selection) != typeid(BranchObj) &&
935 typeid(*selection) != typeid(MapCenterObj)) )
937 api.setError (Aborted,"Type of selection is not a branch");
938 } else if (api.checkParamCount(1))
940 s=api.parString(ok,0);
943 BranchObj* bo=(BranchObj*)selection;
944 bo->deactivateStandardFlag(s);
945 bo->updateFlagsToolbar();
950 api.setError (Aborted,"Unknown command");
954 if (api.errorLevel()==NoError)
958 // TODO Error handling
959 qWarning("MapEditor::parseAtom: Error!");
960 qWarning(api.errorMessage());
965 bool MapEditor::isDefault()
970 bool MapEditor::isUnsaved()
975 bool MapEditor::hasChanged()
980 void MapEditor::setChanged()
988 void MapEditor::closeMap()
990 // Unselect before disabling the toolbar actions
991 if (selection) selection->unselect();
999 void MapEditor::setFilePath(QString fname)
1001 setFilePath (fname,fname);
1004 void MapEditor::setFilePath(QString fname, QString destname)
1006 if (fname.isEmpty() || fname=="")
1013 filePath=fname; // becomes absolute path
1014 fileName=fname; // gets stripped of path
1015 destPath=destname; // needed for vymlinks
1017 // If fname is not an absolute path, complete it
1018 filePath=QDir(fname).absPath();
1019 fileDir=filePath.left (1+filePath.findRev ("/"));
1021 // Set short name, too. Search from behind:
1022 int i=fileName.findRev("/");
1023 if (i>=0) fileName=fileName.remove (0,i+1);
1025 // Forget the .vym (or .xml) for name of map
1026 mapName=fileName.left(fileName.findRev(".",-1,true) );
1030 QString MapEditor::getFilePath()
1035 QString MapEditor::getFileName()
1040 QString MapEditor::getMapName()
1045 QString MapEditor::getDestPath()
1050 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
1052 ErrorCode err=success;
1056 if (selection) selection->unselect();
1059 mapCenter->setMapEditor(this);
1060 // (map state is set later at end of load...)
1063 if (!selection || (typeid(*selection) != typeid(BranchObj) &&
1064 typeid(*selection) != typeid (MapCenterObj)))
1066 BranchObj *bo=(BranchObj*)selection;
1067 if (lmode==ImportAdd)
1068 saveStateChangingPart(
1071 QString("addMapInsert (%1)").arg(fname),
1072 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1074 saveStateChangingPart(
1077 QString("addMapReplace(%1)").arg(fname),
1078 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1082 mapBuilderHandler handler;
1083 QFile file( fname );
1085 // I am paranoid: file should exist anyway
1086 // according to check in mainwindow.
1087 if (!file.exists() )
1089 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1090 tr("Couldn't open map " +fname)+".");
1094 blockReposition=true;
1095 QXmlInputSource source( file);
1096 QXmlSimpleReader reader;
1097 reader.setContentHandler( &handler );
1098 reader.setErrorHandler( &handler );
1099 handler.setMapEditor( this );
1100 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
1101 handler.setInputFile (file.name());
1102 handler.setLoadMode (lmode);
1103 blockSaveState=true;
1104 bool ok = reader.parse( source );
1105 blockReposition=false;
1106 blockSaveState=false;
1110 mapCenter->reposition();
1120 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1121 tr( handler.errorProtocol() ) );
1123 // Still return "success": the map maybe at least
1124 // partially read by the parser
1131 int MapEditor::save (const SaveMode &savemode)
1135 // Create mapName and fileDir
1136 makeSubDirs (fileDir);
1140 fname=mapName+".xml";
1142 // use name given by user, even if he chooses .doc
1147 if (savemode==CompleteMap || selection==NULL)
1148 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
1150 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),selection);
1152 if (!saveStringToDisk(fileDir+fname,saveFile))
1165 void MapEditor::setZipped (bool z)
1170 bool MapEditor::saveZipped ()
1175 void MapEditor::print()
1179 printer = new QPrinter;
1180 printer->setColorMode (QPrinter::Color);
1181 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1184 QRectF totalBBox=mapCenter->getTotalBBox();
1186 // Try to set orientation automagically
1187 // Note: Interpretation of generated postscript is amibiguous, if
1188 // there are problems with landscape mode, see
1189 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1191 if (totalBBox.width()>totalBBox.height())
1192 // recommend landscape
1193 printer->setOrientation (QPrinter::Landscape);
1195 // recommend portrait
1196 printer->setOrientation (QPrinter::Portrait);
1198 if ( printer->setup(this) )
1199 // returns false, if printing is canceled
1201 QPainter pp(printer);
1203 // Don't print the visualisation of selection
1204 LinkableMapObj *oldselection=NULL;
1207 oldselection=selection;
1208 selection->unselect();
1211 // Handle sizes of map and paper:
1213 // setWindow defines which part of the scene will be transformed
1214 // setViewport defines area on paper in device coordinates (dpi)
1215 // e.g. (0,50,700,700) is upper part on A4
1216 // see also /usr/lib/qt3/doc/html/coordsys.html
1218 Q3PaintDeviceMetrics metrics (printer);
1220 double paperAspect = (double)metrics.width() / (double)metrics.height();
1221 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1223 QRectF mapRect=totalBBox;
1224 QGraphicsRectItem *frame=NULL;
1225 QGraphicsTextItem *footerFN=NULL;
1226 QGraphicsTextItem *footerDate=NULL;
1227 if (printFrame || printFooter)
1232 // Print frame around map
1233 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1234 totalBBox.width()+20, totalBBox.height()+20);
1235 frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::red));
1236 frame->setZValue(0);
1239 // TODO remove after testing
1240 //QCanvasLine *l=new QCanvasLine (mapScene);
1241 //l->setPoints (0,0,mapRect.width(),mapRect.height());
1242 //l->setPen (QPen(QColor(black), 1));
1248 // Print footer below map
1250 font.setPointSize(10);
1251 footerFN=mapScene->addText ("VYM - " + fileName,font);
1252 footerFN->setPos (mapRect.x(), mapRect.y() + mapRect.height() );
1253 footerFN->setZValue (Z_TEXT);
1255 footerDate=mapScene->addText (QDate::currentDate().toString(Qt::TextDate),font);
1256 footerDate->setPos(mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1257 footerDate->setZValue(Z_TEXT);
1260 //pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1263 //pp.setWindow (mapRect);
1264 //pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1268 if (mapAspect>=paperAspect)
1270 // Fit horizontally to paper width
1271 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1274 // Fit vertically to paper height
1275 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1278 QRect viewport=rect();
1279 render (&pp, QRect(),QRect());
1281 //mapScene->render(&pp); // draw scene to printer
1284 // Delete Frame and footer
1288 delete (footerDate);
1291 // if (frame) delete (frame);
1293 // Restore selection
1296 selection=oldselection;
1297 selection->select();
1300 // Save settings in vymrc
1301 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1305 void MapEditor::setAntiAlias (bool b)
1307 setRenderHint(QPainter::Antialiasing,b);
1310 void MapEditor::setSmoothPixmap(bool b)
1312 setRenderHint(QPainter::SmoothPixmapTransform,b);
1315 QPixmap MapEditor::getPixmap()
1317 /* FIXME getPixmap not ported yet to QT4
1318 QRectF mapRect=mapCenter->getTotalBBox();
1319 QPixmap pix (mapRect.size());
1322 // Don't print the visualisation of selection
1323 LinkableMapObj *oldselection=NULL;
1326 oldselection=selection;
1327 selection->unselect();
1330 pp.setWindow (mapRect);
1332 mapScene->drawArea(mapRect, &pp); // draw scene to painter
1335 // Restore selection
1338 selection=oldselection;
1339 selection->select();
1347 void MapEditor::setHideTmpMode (HideTmpMode mode)
1350 mapCenter->setHideTmp (hidemode);
1351 mapCenter->reposition();
1356 HideTmpMode MapEditor::getHideTmpMode()
1361 void MapEditor::exportImage(QString fn)
1363 setExportMode (true);
1364 QPixmap pix (getPixmap());
1365 pix.save(fn, "PNG");
1366 setExportMode (false);
1369 void MapEditor::setExportMode (bool b)
1371 // should be called before and after exports
1372 // depending on the settings
1373 if (b && settings.value("/export/useHideExport","yes")=="yes")
1374 setHideTmpMode (HideExport);
1376 setHideTmpMode (HideNone);
1379 void MapEditor::exportImage(QString fn, QString format)
1381 setExportMode (true);
1382 QPixmap pix (getPixmap());
1383 pix.save(fn, format);
1384 setExportMode (false);
1387 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1391 ex.setMapCenter(mapCenter);
1392 if (ex.setConfigFile(cf))
1394 setExportMode (true);
1395 ex.exportPresentation();
1396 setExportMode (false);
1402 void MapEditor::exportXML(const QString &dir)
1404 // Hide stuff during export, if settings want this
1405 setExportMode (true);
1407 // Create subdirectories
1410 // write to directory
1411 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1414 file.setName ( dir + "/"+mapName+".xml");
1415 if ( !file.open( QIODevice::WriteOnly ) )
1417 // This should neverever happen
1418 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1422 // Write it finally, and write in UTF8, no matter what
1423 QTextStream ts( &file );
1424 ts.setEncoding (QTextStream::UnicodeUTF8);
1428 // Now write image, too
1429 exportImage (dir+"/images/"+mapName+".png");
1431 setExportMode (false);
1434 void MapEditor::clear()
1438 selection->unselect();
1445 void MapEditor::copy()
1449 // write to directory
1450 QString clipfile="part";
1451 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPointF(),selection);
1454 file.setName ( clipboardDir + "/"+clipfile+".xml");
1455 if ( !file.open( QIODevice::WriteOnly ) )
1457 // This should neverever happen
1458 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1462 // Write it finally, and write in UTF8, no matter what
1463 QTextStream ts( &file );
1464 ts.setEncoding (QTextStream::UnicodeUTF8);
1468 clipboardEmpty=false;
1473 void MapEditor::redo()
1475 blockSaveState=true;
1477 // Restore variables
1478 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1479 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1480 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1481 // Can we undo at all?
1482 if (redosAvail<1) return;
1485 if (undosAvail<stepsTotal) undosAvail++;
1487 if (curStep>stepsTotal) curStep=1;
1488 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1489 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1490 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1491 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1492 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1493 QString version=undoSet.readEntry ("/history/version");
1495 if (!checkVersion(version))
1496 QMessageBox::warning(0,tr("Warning"),
1497 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1500 // Find out current undo directory
1501 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1503 /* TODO remove testing
1505 cout << "ME::redo() begin\n";
1506 cout << " undosAvail="<<undosAvail<<endl;
1507 cout << " redosAvail="<<redosAvail<<endl;
1508 cout << " curStep="<<curStep<<endl;
1509 cout << " ---------------------------"<<endl;
1510 cout << " comment="<<comment.toStdString()<<endl;
1511 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1512 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1513 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1514 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1515 cout << " ---------------------------"<<endl<<endl;
1517 // select object before redo
1518 if (!redoSelection.isEmpty())
1519 select (redoSelection);
1522 parseAtom (redoCommand);
1523 mapCenter->reposition();
1525 blockSaveState=false;
1527 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1528 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1529 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1530 undoSet.writeSettings(histPath);
1532 mainWindow->updateHistory (undoSet);
1535 /* TODO remove testing
1536 cout << "ME::redo() end\n";
1537 cout << " undosAvail="<<undosAvail<<endl;
1538 cout << " redosAvail="<<redosAvail<<endl;
1539 cout << " curStep="<<curStep<<endl;
1540 cout << " ---------------------------"<<endl<<endl;
1546 bool MapEditor::isRedoAvailable()
1548 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1554 void MapEditor::undo()
1556 blockSaveState=true;
1558 // Restore variables
1559 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1560 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1561 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1563 // Can we undo at all?
1564 if (undosAvail<1) return;
1566 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1567 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1568 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1569 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1570 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1571 QString version=undoSet.readEntry ("/history/version");
1573 if (!checkVersion(version))
1574 QMessageBox::warning(0,tr("Warning"),
1575 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1577 // Find out current undo directory
1578 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1580 // select object before undo
1581 if (!undoSelection.isEmpty())
1582 select (undoSelection);
1586 cout << "ME::undo() begin\n";
1587 cout << " undosAvail="<<undosAvail<<endl;
1588 cout << " redosAvail="<<redosAvail<<endl;
1589 cout << " curStep="<<curStep<<endl;
1590 cout << " ---------------------------"<<endl;
1591 cout << " comment="<<comment.toStdString()<<endl;
1592 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1593 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1594 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1595 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1596 cout << " ---------------------------"<<endl<<endl;
1597 parseAtom (undoCommand);
1598 mapCenter->reposition();
1602 if (curStep<1) curStep=stepsTotal;
1606 blockSaveState=false;
1607 /* TODO remove testing
1608 cout << "ME::undo() end\n";
1609 cout << " undosAvail="<<undosAvail<<endl;
1610 cout << " redosAvail="<<redosAvail<<endl;
1611 cout << " curStep="<<curStep<<endl;
1612 cout << " ---------------------------"<<endl<<endl;
1615 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1616 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1617 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1618 undoSet.writeSettings(histPath);
1620 mainWindow->updateHistory (undoSet);
1624 bool MapEditor::isUndoAvailable()
1626 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1632 void MapEditor::gotoHistoryStep (int i)
1634 // Restore variables
1635 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1636 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1638 if (i<0) i=undosAvail+redosAvail;
1640 // Clicking above current step makes us undo things
1643 for (int j=0; j<undosAvail-i; j++) undo();
1646 // Clicking below current step makes us redo things
1648 for (int j=undosAvail; j<i; j++) redo();
1650 // And ignore clicking the current row ;-)
1653 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
1655 QString pathDir=path.left(path.findRev("/"));
1661 // We need to parse saved XML data
1662 mapBuilderHandler handler;
1663 QXmlInputSource source( file);
1664 QXmlSimpleReader reader;
1665 reader.setContentHandler( &handler );
1666 reader.setErrorHandler( &handler );
1667 handler.setMapEditor( this );
1668 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1669 if (undoSel.isEmpty())
1673 handler.setLoadMode (NewMap);
1677 handler.setLoadMode (ImportReplace);
1679 blockReposition=true;
1680 bool ok = reader.parse( source );
1681 blockReposition=false;
1684 // This should never ever happen
1685 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1686 handler.errorProtocol());
1689 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1692 void MapEditor::addMapInsertInt (const QString &path, int pos)
1694 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1695 typeid(*selection) == typeid(MapCenterObj)))
1697 QString pathDir=path.left(path.findRev("/"));
1703 // We need to parse saved XML data
1704 mapBuilderHandler handler;
1705 QXmlInputSource source( file);
1706 QXmlSimpleReader reader;
1707 reader.setContentHandler( &handler );
1708 reader.setErrorHandler( &handler );
1709 handler.setMapEditor( this );
1710 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1711 handler.setLoadMode (ImportAdd);
1712 blockReposition=true;
1713 bool ok = reader.parse( source );
1714 blockReposition=false;
1717 // This should never ever happen
1718 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1719 handler.errorProtocol());
1721 if (selection!=mapCenter)
1722 ((BranchObj*)selection)->getLastBranch()->moveBranchTo ((BranchObj*)(selection),pos);
1724 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1728 void MapEditor::pasteNoSave()
1730 load (clipboardDir+"/part.xml",ImportAdd);
1733 void MapEditor::cutNoSave()
1739 void MapEditor::paste()
1741 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1742 typeid(*selection) == typeid(MapCenterObj)))
1745 saveStateChangingPart(
1749 QString("Paste to %1").arg( getName(selection))
1751 mapCenter->reposition();
1756 void MapEditor::cut()
1758 saveStateChangingPart(
1759 selection->getParObj(),
1762 QString("Cut %1").arg(getName(selection))
1766 mapCenter->reposition();
1770 void MapEditor::move(const int &x, const int &y)
1774 QString ps=qpointfToString (selection->getAbsPos());
1775 QString s=selection->getSelectString();
1778 s, "move "+qpointfToString (QPointF (x,y)),
1779 QString("Move %1 to %2").arg(getName(selection)).arg(ps));
1780 selection->move(x,y);
1781 mapCenter->reposition();
1787 void MapEditor::moveRel (const int &x, const int &y)
1789 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1790 typeid(*selection) == typeid(MapCenterObj) ||
1791 typeid(*selection) == typeid (FloatImageObj)))
1793 QString ps=qpointfToString (selection->getRelPos());
1794 QString s=selection->getSelectString();
1797 s, "moveRel "+qpointfToString (QPointF (x,y)),
1798 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps));
1799 ((OrnamentedObj*)selection)->move2RelPos (x,y);
1800 mapCenter->reposition();
1805 void MapEditor::moveBranchUp()
1809 if (typeid(*selection) == typeid(BranchObj) )
1811 bo=(BranchObj*)selection;
1812 if (!bo->canMoveBranchUp()) return;
1813 par=(BranchObj*)(bo->getParObj());
1814 selection->unselect();
1815 bo=par->moveBranchUp (bo); // bo will be the one below selection
1816 selection->select();
1817 saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1818 mapCenter->reposition();
1819 ensureSelectionVisible();
1823 void MapEditor::moveBranchDown()
1827 if (typeid(*selection) == typeid(BranchObj) )
1829 bo=(BranchObj*)selection;
1830 if (!bo->canMoveBranchDown()) return;
1831 par=(BranchObj*)(bo->getParObj());
1832 selection->unselect();
1833 bo=par->moveBranchDown(bo); // bo will be the one above selection
1834 selection->select();
1835 saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1836 mapCenter->reposition();
1837 ensureSelectionVisible();
1841 QString MapEditor::getHeading(bool &ok, QPoint &p)
1844 (typeid(*selection) == typeid(BranchObj) ||
1845 typeid(*selection) == typeid(MapCenterObj) ) )
1848 ensureSelectionVisible();
1849 p=mapFromScene(selection->getAbsPos());
1850 return ((BranchObj*)selection)->getHeading();
1856 void MapEditor::setHeading(const QString &s)
1859 (typeid(*selection) == typeid(BranchObj) ||
1860 typeid(*selection) == typeid(MapCenterObj) ) )
1862 editingBO=(BranchObj*)selection;
1865 "setHeading (\""+editingBO->getHeading()+"\")",
1867 "setHeading (\""+s+"\")",
1868 QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) );
1869 editingBO->setHeading(s );
1871 mapCenter->reposition();
1873 ensureSelectionVisible();
1877 void MapEditor::setURLInt (const QString &s)
1879 // Internal function, no saveState needed
1881 (typeid(*selection) == typeid(BranchObj) ||
1882 typeid(*selection) == typeid(MapCenterObj) ) )
1884 ((BranchObj*)selection)->setURL(s);
1885 mapCenter->reposition();
1887 ensureSelectionVisible();
1891 void MapEditor::setHeadingInt(const QString &s)
1894 (typeid(*selection) == typeid(BranchObj) ||
1895 typeid(*selection) == typeid(MapCenterObj) ) )
1897 ((BranchObj*)selection)->setHeading(s);
1898 mapCenter->reposition();
1900 ensureSelectionVisible();
1904 void MapEditor::setVymLinkInt (const QString &s)
1906 // Internal function, no saveState needed
1908 (typeid(*selection) == typeid(BranchObj) ||
1909 typeid(*selection) == typeid(MapCenterObj) ) )
1911 ((BranchObj*)selection)->setVymLink(s);
1912 mapCenter->reposition();
1914 ensureSelectionVisible();
1918 BranchObj* MapEditor::addNewBranchInt(int num)
1920 // Depending on pos:
1921 // -3 insert in childs of parent above selection
1922 // -2 add branch to selection
1923 // -1 insert in childs of parent below selection
1924 // 0..n insert in childs of parent at pos
1925 BranchObj *newbo=NULL;
1927 (typeid(*selection) == typeid(BranchObj) ||
1928 typeid(*selection) == typeid(MapCenterObj) ) )
1930 BranchObj* bo = (BranchObj*) selection;
1933 // save scroll state. If scrolled, automatically select
1934 // new branch in order to tmp unscroll parent...
1935 return bo->addBranch();
1940 bo=(BranchObj*)bo->getParObj();
1944 bo=(BranchObj*)bo->getParObj();
1947 newbo=bo->insertBranch(num);
1952 BranchObj* MapEditor::addNewBranch(int pos)
1954 // Different meaning than num in addNewBranchInt!
1958 BranchObj *bo = (BranchObj*) selection;
1959 BranchObj *newbo=NULL;
1962 (typeid(*selection) == typeid(BranchObj) ||
1963 typeid(*selection) == typeid(MapCenterObj) ) )
1965 newbo=addNewBranchInt (pos-2);
1970 selection, // FIXME sholdnt newbo be deleted here???
1973 QString ("addBranch (%1)").arg(pos-2),
1974 QString ("Add new branch to %1").arg(getName(bo)));
1976 mapCenter->reposition();
1984 BranchObj* MapEditor::addNewBranchBefore()
1986 BranchObj *newbo=NULL;
1988 (typeid(*selection) == typeid(BranchObj) ) )
1989 // We accept no MapCenterObj here, so we _have_ a parent
1991 BranchObj* bo = (BranchObj*) selection;
1992 QPointF p=bo->getRelPos();
1995 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1997 // add below selection
1998 newbo=parbo->insertBranch(bo->getNum()+1);
2001 newbo->move2RelPos (p);
2003 // Move selection to new branch
2004 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
2006 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
2007 QString ("Add branch before %1").arg(getName(bo)));
2009 mapCenter->reposition();
2016 void MapEditor::deleteSelection()
2018 if (selection && typeid(*selection) ==typeid(BranchObj) )
2020 BranchObj* bo=(BranchObj*)selection;
2021 BranchObj* par=(BranchObj*)(bo->getParObj());
2023 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2025 par->removeBranch(bo);
2027 selection->select();
2028 ensureSelectionVisible();
2029 mapCenter->reposition();
2032 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
2034 FloatImageObj* fio=(FloatImageObj*)selection;
2035 BranchObj* par=(BranchObj*)(fio->getParObj());
2036 saveStateChangingPart(
2040 QString("Delete %1").arg(getName(fio))
2044 par->removeFloatImage(fio);
2046 selection->select();
2047 ensureSelectionVisible();
2048 mapCenter->reposition();
2053 LinkableMapObj* MapEditor::getSelection()
2058 void MapEditor::unselect()
2062 selectionLast=selection;
2063 selection->unselect();
2068 void MapEditor::reselect()
2072 selection=selectionLast;
2073 selection->select();
2078 bool MapEditor::select (const QString &s)
2080 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2082 // Finally select the found object
2085 if (selection) unselect();
2087 selection->select();
2089 ensureSelectionVisible();
2095 QString MapEditor::getSelectString()
2097 if (selection) return selection->getSelectString();
2101 void MapEditor::selectInt (LinkableMapObj *lmo)
2103 if (lmo && selection != lmo)
2105 // select the MapObj
2106 if (selection) selection->unselect();
2108 selection->select();
2114 void MapEditor::selectNextBranchInt()
2116 // Increase number of branch
2119 QString s=selection->getSelectString();
2125 part=s.section(",",-1);
2127 num=part.right(part.length() - 3);
2129 s=s.left (s.length() -num.length());
2132 num=QString ("%1").arg(num.toUInt()+1);
2136 // Try to select this one
2137 if (select (s)) return;
2139 // We have no direct successor,
2140 // try to increase the parental number in order to
2141 // find a successor with same depth
2143 int d=selection->getDepth();
2148 while (!found && d>0)
2150 s=s.section (",",0,d-1);
2151 // replace substring of current depth in s with "1"
2152 part=s.section(",",-1);
2154 num=part.right(part.length() - 3);
2158 // increase number of parent
2159 num=QString ("%1").arg(num.toUInt()+1);
2160 s=s.section (",",0,d-2) + ","+ typ+num;
2163 // Special case, look at orientation
2164 if (selection->getOrientation()==OrientRightOfCenter)
2165 num=QString ("%1").arg(num.toUInt()+1);
2167 num=QString ("%1").arg(num.toUInt()-1);
2172 // pad to oldDepth, select the first branch for each depth
2173 for (i=d;i<oldDepth;i++)
2178 if ( ((BranchObj*)selection)->countBranches()>0)
2186 // try to select the freshly built string
2194 void MapEditor::selectPrevBranchInt()
2196 // Decrease number of branch
2199 QString s=selection->getSelectString();
2205 part=s.section(",",-1);
2207 num=part.right(part.length() - 3);
2209 s=s.left (s.length() -num.length());
2211 int n=num.toInt()-1;
2214 num=QString ("%1").arg(n);
2217 // Try to select this one
2218 if (n>=0 && select (s)) return;
2220 // We have no direct precessor,
2221 // try to decrease the parental number in order to
2222 // find a precessor with same depth
2224 int d=selection->getDepth();
2229 while (!found && d>0)
2231 s=s.section (",",0,d-1);
2232 // replace substring of current depth in s with "1"
2233 part=s.section(",",-1);
2235 num=part.right(part.length() - 3);
2239 // decrease number of parent
2240 num=QString ("%1").arg(num.toInt()-1);
2241 s=s.section (",",0,d-2) + ","+ typ+num;
2244 // Special case, look at orientation
2245 if (selection->getOrientation()==OrientRightOfCenter)
2246 num=QString ("%1").arg(num.toInt()-1);
2248 num=QString ("%1").arg(num.toInt()+1);
2253 // pad to oldDepth, select the last branch for each depth
2254 for (i=d;i<oldDepth;i++)
2258 if ( ((BranchObj*)selection)->countBranches()>0)
2259 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
2266 // try to select the freshly built string
2274 void MapEditor::selectUpperBranch()
2278 if (typeid(*selection) == typeid(BranchObj))
2280 if (selection->getOrientation()==OrientRightOfCenter)
2281 selectPrevBranchInt();
2283 if (selection->getDepth()==1)
2284 selectNextBranchInt();
2286 selectPrevBranchInt();
2291 void MapEditor::selectLowerBranch()
2295 if (typeid(*selection) == typeid(BranchObj))
2297 if (selection->getOrientation()==OrientRightOfCenter)
2298 selectNextBranchInt();
2300 if (selection->getDepth()==1)
2301 selectPrevBranchInt();
2303 selectNextBranchInt();
2309 void MapEditor::selectLeftBranch()
2315 if (typeid(*selection) == typeid(MapCenterObj))
2317 par= (BranchObj*) selection;
2318 bo=par->getLastSelectedBranch();
2321 // Workaround for reselecting on left and right side
2322 if (bo->getOrientation()==OrientRightOfCenter)
2324 bo=par->getLastBranch();
2330 selection->select();
2332 ensureSelectionVisible();
2337 par=(BranchObj*)(selection->getParObj());
2338 if (selection->getOrientation()==OrientRightOfCenter)
2340 if (typeid(*selection) == typeid(BranchObj) ||
2341 typeid(*selection) == typeid(FloatImageObj))
2343 selection->unselect();
2345 selection->select();
2347 ensureSelectionVisible();
2351 if (typeid(*selection) == typeid(BranchObj) )
2353 bo=((BranchObj*)selection)->getLastSelectedBranch();
2356 selection->unselect();
2358 selection->select();
2360 ensureSelectionVisible();
2368 void MapEditor::selectRightBranch()
2375 if (typeid(*selection) == typeid(MapCenterObj))
2377 par= (BranchObj*) selection;
2378 bo=par->getLastSelectedBranch();
2381 // Workaround for reselecting on left and right side
2382 if (bo->getOrientation()==OrientLeftOfCenter)
2383 bo=par->getFirstBranch();
2388 selection->select();
2389 ensureSelectionVisible();
2394 par=(BranchObj*)(selection->getParObj());
2395 if (selection->getOrientation()==OrientLeftOfCenter)
2397 if (typeid(*selection) == typeid(BranchObj) ||
2398 typeid(*selection) == typeid(FloatImageObj))
2400 selection->unselect();
2402 selection->select();
2404 ensureSelectionVisible();
2408 if (typeid(*selection) == typeid(BranchObj) )
2410 bo=((BranchObj*)selection)->getLastSelectedBranch();
2413 selection->unselect();
2415 selection->select();
2417 ensureSelectionVisible();
2425 void MapEditor::selectFirstBranch()
2431 if (typeid(*selection) == typeid(BranchObj))
2433 bo1= (BranchObj*) selection;
2434 par=(BranchObj*)(bo1->getParObj());
2435 bo2=par->getFirstBranch();
2439 selection->select();
2440 ensureSelectionVisible();
2447 void MapEditor::selectLastBranch()
2453 if (typeid(*selection) == typeid(BranchObj))
2455 bo1= (BranchObj*) selection;
2456 par=(BranchObj*)(bo1->getParObj());
2457 bo2=par->getLastBranch();
2461 selection->select();
2462 ensureSelectionVisible();
2469 void MapEditor::selectMapBackgroundImage ()
2471 Q3FileDialog *fd=new Q3FileDialog( this);
2472 fd->setMode (Q3FileDialog::ExistingFile);
2473 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2474 ImagePreview *p =new ImagePreview (fd);
2475 fd->setContentsPreviewEnabled( TRUE );
2476 fd->setContentsPreview( p, p );
2477 fd->setPreviewMode( Q3FileDialog::Contents );
2478 fd->setCaption(vymName+" - " +tr("Load background image"));
2479 fd->setDir (lastImageDir);
2482 if ( fd->exec() == QDialog::Accepted )
2484 // FIXME in QT4 use: lastImageDir=fd->directory();
2485 lastImageDir=QDir (fd->dirPath());
2486 setMapBackgroundImage (fd->selectedFile());
2490 void MapEditor::setMapBackgroundImage (const QString &fn)
2492 QColor oldcol=mapScene->backgroundBrush().color();
2496 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
2498 QString ("setMapBackgroundImage (%1)").arg(col.name()),
2499 QString("Set background color of map to %1").arg(col.name()));
2501 cout << "Trying to load "<<fn.ascii()<<endl;
2503 brush.setTextureImage (QPixmap (fn));
2504 mapScene->setBackgroundBrush(brush);
2507 void MapEditor::selectMapBackgroundColor()
2509 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
2510 if ( !col.isValid() ) return;
2511 setMapBackgroundColor( col );
2515 void MapEditor::setMapBackgroundColor(QColor col)
2517 QColor oldcol=mapScene->backgroundBrush().color();
2520 QString ("setMapBackgroundColor (%1)").arg(oldcol.name()),
2522 QString ("setMapBackgroundColor (%1)").arg(col.name()),
2523 QString("Set background color of map to %1").arg(col.name()));
2524 mapScene->setBackgroundBrush(col);
2527 QColor MapEditor::getMapBackgroundColor()
2529 return mapScene->backgroundBrush().color();
2532 QColor MapEditor::getCurrentHeadingColor()
2536 if (typeid(*selection) == typeid(BranchObj) ||
2537 typeid(*selection) == typeid(MapCenterObj))
2539 BranchObj *bo=(BranchObj*)selection;
2540 return bo->getColor();
2544 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
2548 void MapEditor::colorItem(QColor c)
2552 if (typeid(*selection) == typeid(BranchObj) ||
2553 typeid(*selection) == typeid(MapCenterObj))
2555 BranchObj *bo=(BranchObj*)selection;
2558 QString ("colorItem (%1)").arg(bo->getColor().name()),
2560 QString ("colorItem (%1)").arg(c.name()),
2561 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
2563 bo->setColor(c); // color branch
2568 void MapEditor::colorBranch(QColor c)
2572 if (typeid(*selection) == typeid(BranchObj) ||
2573 typeid(*selection) == typeid(MapCenterObj))
2575 BranchObj *bo=(BranchObj*)selection;
2576 saveStateChangingPart(
2579 QString ("colorBranch (%1)").arg(c.name()),
2580 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
2582 bo->setColorChilds(c); // color links, color childs
2588 void MapEditor::toggleStandardFlag(QString f)
2592 if (typeid(*selection) == typeid(BranchObj) ||
2593 typeid(*selection) == typeid(MapCenterObj))
2595 BranchObj *bo=(BranchObj*)selection;
2597 if (bo->isSetStandardFlag(f))
2609 QString("%1 (\"%2\")").arg(u).arg(f),
2611 QString("%1 (\"%2\")").arg(r).arg(f),
2612 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2613 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
2619 void MapEditor::setViewCenter()
2621 // transform to sceneView Coord:
2622 QPointF p=matrix().map(movingCenter);
2623 //FIXME setViewCenter not ported yet to QT4 (center ist TextStream there)
2624 //center ( p.x(), p.y());
2628 BranchObj* MapEditor::findText (QString s, bool cs)
2630 QTextDocument::FindFlags flags=0;
2631 if (cs) flags=QTextDocument::FindCaseSensitively;
2634 { // Nothing found or new find process
2636 // nothing found, start again
2638 itFind=mapCenter->first();
2640 bool searching=true;
2641 bool foundNote=false;
2642 while (searching && !EOFind)
2646 // Searching in Note
2647 if (itFind->getNote().contains(s,cs))
2649 if (selection!=itFind)
2651 if (selection) ((BranchObj*)selection)->unselect();
2653 selection->select();
2655 ensureSelectionVisible();
2657 if (textEditor->findText(s,flags))
2663 // Searching in Heading
2664 if (searching && itFind->getHeading().contains (s,cs) )
2666 if (selection) ((BranchObj*)selection)->unselect();
2668 selection->select();
2670 ensureSelectionVisible();
2676 itFind=itFind->next();
2677 if (!itFind) EOFind=true;
2683 return (BranchObj*)selection;
2688 void MapEditor::findReset()
2689 { // Necessary if text to find changes during a find process
2693 void MapEditor::setURL(const QString &url)
2695 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2696 typeid(*selection) == typeid(MapCenterObj)) )
2698 BranchObj *bo=(BranchObj*)selection;
2699 QString oldurl=bo->getURL();
2703 QString ("setURL (\"%1\")").arg(oldurl),
2705 QString ("setURL (\"%1\")").arg(url),
2706 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
2712 void MapEditor::editURL()
2714 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2715 typeid(*selection) == typeid(MapCenterObj)) )
2718 BranchObj *bo=(BranchObj*)selection;
2719 QString text = QInputDialog::getText(
2720 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2721 bo->getURL(), &ok, this );
2723 // user entered something and pressed OK
2728 QString MapEditor::getURL()
2730 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2731 typeid(*selection) == typeid(MapCenterObj)) )
2732 return ((BranchObj*)selection)->getURL();
2737 QStringList MapEditor::getURLs()
2740 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2741 typeid(*selection) == typeid(MapCenterObj)) )
2743 BranchObj *bo=(BranchObj*)selection;
2747 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2755 void MapEditor::editHeading2URL()
2757 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2758 typeid(*selection) == typeid(MapCenterObj)) )
2759 setURL (((BranchObj*)selection)->getHeading());
2762 void MapEditor::editBugzilla2URL()
2764 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2765 typeid(*selection) == typeid(MapCenterObj)) )
2767 BranchObj *bo=(BranchObj*)selection;
2768 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2773 void MapEditor::editFATE2URL()
2775 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2776 typeid(*selection) == typeid(MapCenterObj)) )
2778 BranchObj *bo=(BranchObj*)selection;
2779 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2782 "setURL (\""+bo->getURL()+"\")",
2784 "setURL (\""+url+"\")",
2785 QString("Use heading of %1 as link to FATE").arg(getName(bo))
2792 void MapEditor::editVymLink()
2794 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2795 typeid(*selection) == typeid(MapCenterObj)) )
2797 BranchObj *bo=(BranchObj*)selection;
2798 QStringList filters;
2799 filters <<"VYM map (*.vym)";
2800 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
2801 fd->setFilters (filters);
2802 fd->setCaption(vymName+" - " +tr("Link to another map"));
2803 if (! bo->getVymLink().isEmpty() )
2804 fd->selectFile( bo->getVymLink() );
2808 if ( fd->exec() == QDialog::Accepted )
2812 "setVymLink (\""+bo->getVymLink()+"\")",
2814 "setVymLink (\""+fd->selectedFile()+"\")",
2815 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
2817 bo->setVymLink (fd->selectedFile() );
2819 mapCenter->reposition();
2826 void MapEditor::deleteVymLink()
2828 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2829 typeid(*selection) == typeid(MapCenterObj)) )
2831 BranchObj *bo=(BranchObj*)selection;
2834 "setVymLink (\""+bo->getVymLink()+"\")",
2836 "setVymLink (\"\")",
2837 QString("Unset vymlink of %1").arg(getName(bo))
2839 bo->setVymLink ("" );
2841 mapCenter->reposition();
2847 void MapEditor::setHideExport(bool b)
2849 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2850 typeid(*selection)==typeid(FloatImageObj)))
2852 OrnamentedObj *oo=(OrnamentedObj*)selection;
2853 oo->setHideInExport (b);
2854 QString u= b ? "false" : "true";
2855 QString r=!b ? "false" : "true";
2859 QString ("setHideExport (%1)").arg(u),
2861 QString ("setHideExport (%1)").arg(r),
2862 QString ("Set HideExport flag of %1 to %2").arg(getName(oo)).arg (r)
2865 mapCenter->reposition();
2871 void MapEditor::toggleHideExport()
2873 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2874 typeid(*selection)==typeid(FloatImageObj)))
2875 setHideExport ( !((OrnamentedObj*)selection)->hideInExport() );
2878 QString MapEditor::getVymLink()
2880 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2881 typeid(*selection) == typeid(MapCenterObj)) )
2883 return ((BranchObj*)selection)->getVymLink();
2889 QStringList MapEditor::getVymLinks()
2892 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2893 typeid(*selection) == typeid(MapCenterObj)) )
2895 BranchObj *bo=(BranchObj*)selection;
2899 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2907 void MapEditor::deleteKeepChilds()
2909 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2911 BranchObj* bo=(BranchObj*)selection;
2912 BranchObj* par=(BranchObj*)(bo->getParObj());
2913 QPointF p=bo->getRelPos();
2914 saveStateChangingPart(
2915 selection->getParObj(),
2917 "deleteKeepChilds ()",
2918 QString("Remove %1 and keep its childs").arg(getName(bo))
2921 QString sel=selection->getSelectString();
2923 par->removeBranchHere(bo);
2924 mapCenter->reposition();
2926 ((BranchObj*)selection)->move2RelPos (p);
2927 mapCenter->reposition();
2932 void MapEditor::deleteChilds()
2934 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2935 typeid(*selection)==typeid(MapCenterObj)))
2937 saveStateChangingPart(
2938 selection->getParObj(),
2941 QString( "Remove childs of branch %1").arg(getName(selection))
2943 ((BranchObj*)selection)->removeChilds();
2944 mapCenter->reposition();
2948 void MapEditor::editMapInfo()
2950 ExtraInfoDialog dia;
2951 dia.setMapName (getFileName() );
2952 dia.setAuthor (mapCenter->getAuthor() );
2953 dia.setComment(mapCenter->getComment() );
2957 stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
2964 bo=mapCenter->first();
2967 if (!bo->getNote().isEmpty() ) n++;
2968 f+= bo->countFloatImages();
2970 xl+=bo->countXLinks();
2973 stats+=QString ("%1 branches\n").arg (b-1,6);
2974 stats+=QString ("%1 xLinks \n").arg (xl,6);
2975 stats+=QString ("%1 notes\n").arg (n,6);
2976 stats+=QString ("%1 images\n").arg (f,6);
2977 dia.setStats (stats);
2979 // Finally show dialog
2980 if (dia.exec() == QDialog::Accepted)
2982 setMapAuthor (dia.getAuthor() );
2983 setMapComment (dia.getComment() );
2987 void MapEditor::updateActions()
2989 mainWindow->updateActions();
2990 // FIXME maybe don't update if blockReposition is set
2993 void MapEditor::updateNoteFlag()
2996 if ( (typeid(*selection) == typeid(BranchObj)) ||
2997 (typeid(*selection) == typeid(MapCenterObj)) )
2998 ((BranchObj*)selection)->updateNoteFlag();
3001 void MapEditor::setMapAuthor (const QString &s)
3005 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
3007 QString ("setMapAuthor (\"%1\")").arg(s),
3008 QString ("Set author of map to \"%1\"").arg(s)
3010 mapCenter->setAuthor (s);
3013 void MapEditor::setMapComment (const QString &s)
3017 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
3019 QString ("setMapComment (\"%1\")").arg(s),
3020 QString ("Set comment of map")
3022 mapCenter->setComment (s);
3025 void MapEditor::setMapLinkStyle (const QString & s)
3027 saveStateChangingPart (
3030 QString("setMapLinkStyle (\"%1\")").arg(s),
3031 QString("Set map link style (\"%1\")").arg(s)
3035 linkstyle=StyleLine;
3036 else if (s=="StyleParabel")
3037 linkstyle=StyleParabel;
3038 else if (s=="StylePolyLine")
3039 linkstyle=StylePolyLine;
3041 linkstyle=StylePolyParabel;
3044 bo=mapCenter->first();
3048 bo->setLinkStyle(bo->getDefLinkStyle());
3051 mapCenter->reposition();
3054 LinkStyle MapEditor::getMapLinkStyle ()
3059 void MapEditor::setMapDefLinkColor(QColor c)
3065 void MapEditor::setMapLinkColorHintInt()
3067 // called from setMapLinkColorHint(lch) or at end of parse
3069 bo=mapCenter->first();
3077 void MapEditor::setMapLinkColorHint(LinkColorHint lch)
3080 setMapLinkColorHintInt();
3083 void MapEditor::toggleMapLinkColorHint()
3085 if (linkcolorhint==HeadingColor)
3086 linkcolorhint=DefaultColor;
3088 linkcolorhint=HeadingColor;
3090 bo=mapCenter->first();
3098 LinkColorHint MapEditor::getMapLinkColorHint()
3100 return linkcolorhint;
3103 QColor MapEditor::getMapDefLinkColor()
3105 return defLinkColor;
3108 void MapEditor::setMapDefXLinkColor(QColor col)
3113 QColor MapEditor::getMapDefXLinkColor()
3115 return defXLinkColor;
3118 void MapEditor::setMapDefXLinkWidth (int w)
3123 int MapEditor::getMapDefXLinkWidth()
3125 return defXLinkWidth;
3128 void MapEditor::selectMapLinkColor()
3130 QColor col = QColorDialog::getColor( defLinkColor, this );
3131 if ( !col.isValid() ) return;
3134 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3136 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3137 QString("Set link color to %1").arg(col.name())
3139 setMapDefLinkColor( col );
3143 void MapEditor::toggleScroll()
3145 if (selection && (typeid(*selection) == typeid(BranchObj)) )
3147 BranchObj *bo=((BranchObj*)selection);
3148 if (bo->countBranches()==0) return;
3149 if (bo->getDepth()==0) return;
3151 if (bo->isScrolled())
3163 QString ("%1 ()").arg(u),
3165 QString ("%1 ()").arg(r),
3166 QString ("%1 %2").arg(r).arg(getName(bo))
3174 void MapEditor::unScrollAll()
3177 bo=mapCenter->first();
3180 if (bo->isScrolled()) bo->toggleScroll();
3185 void MapEditor::loadFloatImage ()
3188 (typeid(*selection) == typeid(BranchObj)) ||
3189 (typeid(*selection) == typeid(MapCenterObj)) )
3191 BranchObj *bo=((BranchObj*)selection);
3193 Q3FileDialog *fd=new Q3FileDialog( this);
3194 fd->setMode (Q3FileDialog::ExistingFiles);
3195 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3196 ImagePreview *p =new ImagePreview (fd);
3197 fd->setContentsPreviewEnabled( TRUE );
3198 fd->setContentsPreview( p, p );
3199 fd->setPreviewMode( Q3FileDialog::Contents );
3200 fd->setCaption(vymName+" - " +tr("Load image"));
3201 fd->setDir (lastImageDir);
3205 if ( fd->exec() == QDialog::Accepted )
3207 // FIXME in QT4 use: lastImageDir=fd->directory();
3208 lastImageDir=QDir (fd->dirPath());
3209 QStringList flist = fd->selectedFiles();
3210 QStringList::Iterator it = flist.begin();
3212 while( it != flist.end() )
3215 bo->addFloatImage();
3216 fio=bo->getLastFloatImage();
3218 // FIXME check if load of fio was successful
3220 (LinkableMapObj*)fio,
3223 QString ("loadFloatImage (%1)").arg(*it),
3224 QString("Add floatimage %1 to %2").arg(*it).arg(getName(selection))
3226 bo->getLastFloatImage()->setOriginalFilename(fn);
3230 mapCenter->reposition();
3239 void MapEditor::saveFloatImage ()
3242 (typeid(*selection) == typeid(FloatImageObj)) )
3244 FloatImageObj *fio=((FloatImageObj*)selection);
3245 QFileDialog *fd=new QFileDialog( this);
3246 fd->setFilters (imageIO.getFilters());
3247 fd->setCaption(vymName+" - " +tr("Save image"));
3248 fd->setFileMode( QFileDialog::AnyFile );
3249 fd->setDirectory (lastImageDir);
3250 // fd->setSelection (fio->getOriginalFilename());
3254 if ( fd->exec() == QDialog::Accepted )
3256 if (QFile (fd->selectedFile()).exists() )
3258 QMessageBox mb( vymName,
3259 tr("The file %1 exists already.\n"
3260 "Do you want to overwrite it?").arg(fd->selectedFile()),
3261 QMessageBox::Warning,
3262 QMessageBox::Yes | QMessageBox::Default,
3263 QMessageBox::Cancel | QMessageBox::Escape,
3264 QMessageBox::QMessageBox::NoButton );
3266 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3267 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3270 case QMessageBox::Yes:
3273 case QMessageBox::Cancel:
3280 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
3286 void MapEditor::setFrame(const FrameType &t)
3289 (typeid(*selection) == typeid(BranchObj)) ||
3290 (typeid(*selection) == typeid(MapCenterObj)) )
3292 selection->setFrameType (t);
3293 mapCenter->reposition();
3294 selection->updateLink();
3298 void MapEditor::setIncludeImagesVer(bool b)
3301 (typeid(*selection) == typeid(BranchObj)) ||
3302 (typeid(*selection) == typeid(MapCenterObj)) )
3303 ((BranchObj*)selection)->setIncludeImagesVer(b);
3304 mapCenter->reposition();
3307 void MapEditor::setIncludeImagesHor(bool b)
3310 (typeid(*selection) == typeid(BranchObj)) ||
3311 (typeid(*selection) == typeid(MapCenterObj)) )
3312 ((BranchObj*)selection)->setIncludeImagesHor(b);
3313 mapCenter->reposition();
3316 void MapEditor::setHideLinkUnselected (bool b)
3319 (typeid(*selection) == typeid(BranchObj)) ||
3320 (typeid(*selection) == typeid(MapCenterObj)) ||
3321 (typeid(*selection) == typeid(FloatImageObj)) )
3322 selection->setHideLinkUnselected(b);
3325 void MapEditor::importDirInt(BranchObj *dst, QDir d)
3328 (typeid(*selection) == typeid(BranchObj)) ||
3329 (typeid(*selection) == typeid(MapCenterObj)) )
3333 // Traverse directories
3334 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3335 QFileInfoList list = d.entryInfoList();
3338 for (int i = 0; i < list.size(); ++i)
3341 if (fi.fileName() != "." && fi.fileName() != ".." )
3344 bo=dst->getLastBranch();
3345 bo->setHeading (fi.fileName() );
3346 bo->setColor (QColor("blue"));
3348 if ( !d.cd(fi.fileName()) )
3349 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3352 // Recursively add subdirs
3353 importDirInt (bo,d);
3359 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3360 list = d.entryInfoList();
3362 for (int i = 0; i < list.size(); ++i)
3366 bo=dst->getLastBranch();
3367 bo->setHeading (fi.fileName() );
3368 bo->setColor (QColor("black"));
3369 if (fi.fileName().right(4) == ".vym" )
3370 bo->setVymLink (fi.filePath());
3375 void MapEditor::importDir()
3378 (typeid(*selection) == typeid(BranchObj)) ||
3379 (typeid(*selection) == typeid(MapCenterObj)) )
3381 QStringList filters;
3382 filters <<"VYM map (*.vym)";
3383 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
3384 fd->setMode (QFileDialog::DirectoryOnly);
3385 fd->setFilters (filters);
3386 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
3390 if ( fd->exec() == QDialog::Accepted )
3392 BranchObj *bo=((BranchObj*)selection);
3393 importDirInt (bo,QDir(fd->selectedFile()) );
3394 mapCenter->reposition();
3401 void MapEditor::followXLink(int i)
3404 (typeid(*selection) == typeid(BranchObj)) ||
3405 (typeid(*selection) == typeid(MapCenterObj)) )
3407 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3410 selection->unselect();
3412 selection->select();
3413 ensureSelectionVisible();
3418 void MapEditor::editXLink(int i)
3421 (typeid(*selection) == typeid(BranchObj)) ||
3422 (typeid(*selection) == typeid(MapCenterObj)) )
3424 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3427 EditXLinkDialog dia;
3429 dia.setSelection(selection);
3430 if (dia.exec() == QDialog::Accepted)
3432 if (dia.useSettingsGlobal() )
3434 setMapDefXLinkColor (xlo->getColor() );
3435 setMapDefXLinkWidth (xlo->getWidth() );
3437 if (dia.deleteXLink())
3438 ((BranchObj*)selection)->deleteXLinkAt(i);
3439 //saveStateComplete("Edit xLink"); //FIXME undoCommand
3445 void MapEditor::testFunction()
3448 dia.showCancelButton (true);
3449 dia.setText("This is a longer \nWarning");
3451 dia.setCaption("Warning: Flux problem");
3452 dia.setShowAgainName("/warnings/mapeditor");
3454 if (dia.exec()==QDialog::Accepted)
3455 cout << "accepted!\n";
3457 cout << "canceled!\n";
3460 /* Hide hidden stuff temporary, maybe add this as regular function somewhere
3461 if (hidemode==HideNone)
3463 setHideTmpMode (HideExport);
3464 mapCenter->calcBBoxSizeWithChilds();
3465 QRectF totalBBox=mapCenter->getTotalBBox();
3466 QRectF mapRect=totalBBox;
3467 QCanvasRectangle *frame=NULL;
3469 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3471 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3472 totalBBox.width(), totalBBox.height());
3473 frame=new QCanvasRectangle (mapRect,mapScene);
3474 frame->setBrush (QColor(white));
3475 frame->setPen (QColor(black));
3476 frame->setZValue(0);
3481 setHideTmpMode (HideNone);
3483 cout <<" hidemode="<<hidemode<<endl;
3487 void MapEditor::ensureSelectionVisible()
3491 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3493 if (selection->getOrientation() == OrientLeftOfCenter)
3494 p= matrix().map(QPointF (lmo->x(),lmo->y()));
3496 p= matrix().map(QPointF (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3497 ensureVisible (QRectF(p.x(), p.y(),0,0 ));
3503 void MapEditor::updateViewCenter()
3505 /* FIXME still to port to QT4 inverseworldmatrix
3506 // Update movingCenter, so that we can zoom comfortably later
3507 QRectF rc = QRectF( contentsX(), contentsY(),
3508 visibleWidth(), visibleHeight() );
3509 QRectF canvasRect = inverseWorldMatrix().mapRect(rc);
3510 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3511 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3515 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
3517 // Lineedits are already closed by preceding
3518 // mouseEvent, we don't need to close here.
3520 QPointF p = mapToScene(e->pos());
3521 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3524 { // MapObj was found
3525 if (selection != lmo)
3527 // select the MapObj
3528 if (selection) selection->unselect();
3530 selection->select();
3536 if (typeid(*selection)==typeid(BranchObj) ||
3537 typeid(*selection)==typeid(MapCenterObj) )
3539 // Context Menu on branch or mapcenter
3541 branchContextMenu->popup(e->globalPos() );
3543 if (typeid(*selection)==typeid(FloatImageObj))
3545 // Context Menu on floatimage
3547 floatimageContextMenu->popup(e->globalPos() );
3551 { // No MapObj found, we are on the Canvas itself
3552 // Context Menu on scene
3554 canvasContextMenu->popup(e->globalPos() );
3559 void MapEditor::keyPressEvent(QKeyEvent* e)
3561 if (e->modifiers() & Qt::ControlModifier)
3563 switch (mainWindow->getModMode())
3566 setCursor (PickColorCursor);
3569 setCursor (CopyCursor);
3572 setCursor (XLinkCursor);
3575 setCursor (Qt::ArrowCursor);
3581 void MapEditor::keyReleaseEvent(QKeyEvent* e)
3583 if (!(e->modifiers() & Qt::ControlModifier))
3584 setCursor (Qt::ArrowCursor);
3587 void MapEditor::mousePressEvent(QMouseEvent* e)
3589 // Ignore right clicks, these will go to context menus
3590 if (e->button() == Qt::RightButton )
3596 QPointF p = mapToScene(e->pos());
3597 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3601 //Take care of clickdesystem flags _or_ modifier modes
3603 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3604 typeid(*lmo)==typeid(MapCenterObj) ))
3606 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3607 if (!foname.isEmpty())
3609 // systemFlag clicked
3613 if (e->state() & Qt::ControlModifier)
3614 mainWindow->editOpenURLTab();
3616 mainWindow->editOpenURL();
3618 else if (foname=="vymLink")
3620 mainWindow->editOpenVymLink();
3621 // tabWidget may change, better return now
3622 // before segfaulting...
3623 } else if (foname=="note")
3624 mainWindow->windowToggleNoteEditor();
3625 else if (foname=="hideInExport")
3630 // No system flag clicked, take care of modmodes
3632 // Special case: CTRL is pressed
3633 if (e->state() & Qt::ControlModifier)
3635 if (mainWindow->getModMode()==ModModeColor)
3638 setCursor (PickColorCursor);
3641 if (mainWindow->getModMode()==ModModeXLink)
3643 BranchObj *bo_begin=NULL;
3645 bo_begin=(BranchObj*)(lmo);
3648 ((typeid(*selection) == typeid(BranchObj)) ||
3649 (typeid(*selection) == typeid(MapCenterObj))) )
3650 bo_begin=(BranchObj*)selection;
3654 linkingObj_src=bo_begin;
3655 tmpXLink=new XLinkObj (mapScene);
3656 tmpXLink->setBegin (bo_begin);
3657 tmpXLink->setEnd (p);
3658 tmpXLink->setColor(defXLinkColor);
3659 tmpXLink->setWidth(defXLinkWidth);
3660 tmpXLink->updateXLink();
3661 tmpXLink->setVisibility (true);
3669 // Left Button Move Branches
3670 if (e->button() == Qt::LeftButton )
3672 movingObj_start.setX( p.x() - selection->x() );
3673 movingObj_start.setY( p.y() - selection->y() );
3674 movingObj_orgPos.setX (lmo->x() );
3675 movingObj_orgPos.setY (lmo->y() );
3676 movingObj_orgRelPos=lmo->getRelPos();
3678 // If modMode==copy, then we want to "move" the _new_ object around
3679 // then we need the offset from p to the _old_ selection, because of tmp
3680 if (mainWindow->getModMode()==ModModeCopy &&
3681 e->state() & Qt::ControlModifier)
3683 if (typeid(*selection)==typeid(BranchObj) )
3686 mapCenter->addBranch ((BranchObj*)selection);
3688 selection=mapCenter->getLastBranch();
3689 selection->select();
3690 mapCenter->reposition();
3693 movingObj=selection;
3695 // Middle Button Toggle Scroll
3696 // (On Mac OS X this won't work, but we still have
3697 // a button in the toolbar)
3698 if (e->button() == Qt::MidButton )
3702 { // No MapObj found, we are on the scene itself
3703 // Left Button move Pos of sceneView
3704 if (e->button() == Qt::LeftButton )
3706 movingObj=NULL; // move Content not Obj
3707 movingObj_start=e->globalPos();
3708 // FIXME not ported to QT4 yet (move canvasView)
3709 //movingCont_start=QPointF (contentsX(), contentsY() );
3710 movingCont_start=QPointF (
3711 horizontalScrollBar()->value(),
3712 verticalScrollBar()->value());
3713 movingVec=QPointF(0,0);
3714 setCursor(HandOpenCursor);
3719 void MapEditor::mouseMoveEvent(QMouseEvent* e)
3721 QPointF p = mapToScene(e->pos());
3723 // Move the selected MapObj
3724 if ( selection && movingObj)
3726 // To avoid jumping of the sceneView, only
3727 // ensureSelectionVisible, if not tmp linked
3728 if (!selection->hasParObjTmp())
3729 ensureSelectionVisible ();
3731 // Now move the selection, but add relative position
3732 // (movingObj_start) where selection was chosen with
3733 // mousepointer. (This avoids flickering resp. jumping
3734 // of selection back to absPos)
3736 LinkableMapObj *lmosel;
3737 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3739 // Check if we could link
3740 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3743 if (typeid(*selection) == typeid(FloatImageObj))
3745 FloatObj *fo=(FloatObj*)selection;
3746 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3748 fo->updateLink(); //no need for reposition, if we update link here
3750 // Relink float to new mapcenter or branch, if shift is pressed
3751 // Only relink, if selection really has a new parent
3752 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
3753 ( (typeid(*lmo)==typeid(BranchObj)) ||
3754 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3755 ( lmo != fo->getParObj())
3758 if (typeid(*fo) == typeid(FloatImageObj))
3760 //FIXME undocom for relinking of floats
3762 //saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3763 FloatImageObj *fio=(FloatImageObj*)(fo);
3764 ((BranchObj*)(lmo))->addFloatImage (fio);
3766 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3767 fio=((BranchObj*)(lmo))->getLastFloatImage();
3770 selection=(LinkableMapObj*)(fio);
3771 selection->select();
3772 movingObj=(MapObj*)(fio);
3776 { // selection != a FloatObj
3777 if (lmosel->getDepth()==0)
3780 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3781 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3783 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3784 mapCenter->updateRelPositions();
3787 if (lmosel->getDepth()==1)
3790 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3791 lmosel->setRelPos();
3794 // Move ordinary branch
3795 if (lmosel->getOrientation() == OrientLeftOfCenter)
3796 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3797 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3798 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3800 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3802 // reposition subbranch
3803 lmosel->reposition();
3805 if (lmo && (lmo!=selection) &&
3806 (typeid(*lmo) == typeid(BranchObj) ||
3807 (typeid(*lmo) == typeid(MapCenterObj) )
3810 if (e->modifiers()==Qt::ControlModifier)
3812 // Special case: CTRL to link below lmo
3813 lmosel->setParObjTmp (lmo,p,+1);
3815 else if (e->modifiers()==Qt::ShiftModifier)
3816 lmosel->setParObjTmp (lmo,p,-1);
3818 lmosel->setParObjTmp (lmo,p,0);
3821 lmosel->unsetParObjTmp();
3825 } // no FloatImageObj
3829 } // selection && moving_obj
3831 // Draw a link from one branch to another
3834 tmpXLink->setEnd (p);
3835 tmpXLink->updateXLink();
3839 if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton )
3841 QPointF p=e->globalPos();
3842 movingVec.setX(-p.x() + movingObj_start.x() );
3843 movingVec.setY(-p.y() + movingObj_start.y() );
3844 // FIXME not ported to QT4 yet (move canvasView)
3845 //setContentsPos( movingCont_start.x() + movingVec.x(),
3846 //movingCont_start.y() + movingVec.y();
3847 horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
3848 verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
3853 void MapEditor::mouseReleaseEvent(QMouseEvent* e)
3855 QPointF p = mapToScene(e->pos());
3856 LinkableMapObj *dst;
3857 // Have we been picking color?
3861 setCursor (Qt::ArrowCursor);
3862 // Check if we are over another branch
3863 dst=mapCenter->findMapObj(p, NULL);
3864 if (dst && selection)
3866 if (e->state() & Qt::ShiftModifier)
3868 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3869 ((BranchObj*)selection)->setLinkColor ();
3873 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3874 ((BranchObj*)selection)->setLinkColor ();
3880 // Have we been drawing a link?
3884 // Check if we are over another branch
3885 dst=mapCenter->findMapObj(p, NULL);
3886 if (dst && selection)
3888 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3889 tmpXLink->updateXLink();
3890 tmpXLink->activate();
3891 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //FIXME undoCommand
3900 // Have we been moving something?
3901 if ( selection && movingObj )
3903 if(typeid(*selection)==typeid (FloatImageObj))
3905 // Moved FloatObj. Maybe we need to reposition
3906 FloatImageObj *fo=(FloatImageObj*)selection;
3907 QString pold=qpointfToString(movingObj_orgRelPos);
3908 QString pnow=qpointfToString(fo->getRelPos());
3914 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow));
3916 // FIXME Why calling parObj here?
3917 selection->getParObj()->requestReposition();
3918 mapCenter->reposition();
3921 // Check if we are over another branch, but ignore
3922 // any found LMOs, which are FloatObjs
3923 dst=mapCenter->findMapObj(mapToScene(e->pos() ),
3924 ((LinkableMapObj*)selection) );
3926 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3929 if (typeid(*selection) == typeid(MapCenterObj) )
3930 { // The MapCenter was moved
3931 cout << "FIXME missing savestate...\n";
3934 if (typeid(*selection) == typeid(BranchObj) )
3935 { // A branch was moved
3937 // save the position in case we link to mapcenter
3938 QPointF savePos=QPointF (selection->x(),selection->y() );
3940 // Reset the temporary drawn link to the original one
3941 ((LinkableMapObj*)selection)->unsetParObjTmp();
3943 // For Redo we may need to save original selection
3944 QString preSelStr=selection->getSelectString();
3949 BranchObj* bsel=(BranchObj*)selection;
3950 BranchObj* bdst=(BranchObj*)dst;
3952 QString preParStr=(bsel->getParObj())->getSelectString();
3953 QString preNum=QString::number (bsel->getNum(),10);
3954 QString preDstParStr;
3956 if (e->state() & Qt::ShiftModifier && dst->getParObj())
3958 preDstParStr=dst->getParObj()->getSelectString();
3959 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
3961 if (e->state() & Qt::ControlModifier && dst->getParObj())
3964 preDstParStr=dst->getParObj()->getSelectString();
3965 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
3968 preDstParStr=dst->getSelectString();
3969 bsel->moveBranchTo (bdst,-1);
3970 if (dst->getDepth()==0) bsel->move (savePos);
3972 QString postSelStr=selection->getSelectString();
3973 QString postNum=QString::number (bsel->getNum(),10);
3975 QString undoCom="linkBranchToPos (\""+
3976 preParStr+ "\"," + preNum +"," +
3977 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
3979 QString redoCom="linkBranchToPos (\""+
3980 preDstParStr + "\"," + postNum + "," +
3981 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
3986 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
3988 if (selection->getDepth()==1)
3990 // The select string might be different _after_ moving around.
3991 // Therefor reposition and then use string of old selection, too
3992 mapCenter->reposition();
3994 QString ps=qpointfToString ( ((BranchObj*)selection)->getRelPos() );
3996 selection->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
3997 preSelStr, "moveRel "+ps,
3998 QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps));
4001 // Draw the original link, before selection was moved around
4002 mapCenter->reposition();
4004 // Finally resize scene, if needed
4009 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
4012 // maybe we moved View: set old cursor
4013 setCursor (Qt::ArrowCursor);
4017 void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
4019 if (e->button() == Qt::LeftButton )
4021 QPointF p = mapToScene(e->pos());
4022 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
4023 if (lmo) { // MapObj was found
4024 // First select the MapObj than edit heading
4025 if (selection) selection->unselect();
4027 selection->select();
4028 mainWindow->editHeading();
4033 void MapEditor::resizeEvent (QResizeEvent* e)
4035 QGraphicsView::resizeEvent( e );
4039 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
4041 //FIXME not ported to QT4 yet
4043 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
4044 // cerr << event->format(i) << endl;
4047 (typeid(*selection) == typeid(BranchObj)) ||
4048 (typeid(*selection) == typeid(MapCenterObj))) {
4050 // If QImageDrag can decode mime type
4051 if (Q3ImageDrag::canDecode(event)) {
4056 // If image are dragged from firefox
4057 if (event->provides("application/x-moz-file-promise-url") &&
4058 event->provides("application/x-moz-nativeimage")) {
4059 event->accept(true);
4063 // If QUriDrag can decode mime type
4064 if (Q3UriDrag::canDecode(event)) {
4069 // If Uri are dragged from firefox
4070 if (event->provides("_NETSCAPE_URL")){
4075 // If QTextDrag can decode mime type
4076 if (Q3TextDrag::canDecode(event)) {
4085 bool isUnicode16(const QByteArray &d)
4087 // TODO: make more precise check for unicode 16.
4088 // Guess unicode16 if any of second bytes are zero
4089 unsigned int length = max(0,d.size()-2)/2;
4090 for (unsigned int i = 0; i<length ; i++)
4091 if (d.at(i*2+1)==0) return true;
4095 void MapEditor::contentsDropEvent(QDropEvent *event)
4097 //FIXME not ported to QT4 yet
4099 (typeid(*selection) == typeid(BranchObj)) ||
4100 (typeid(*selection) == typeid(MapCenterObj)))
4107 if (event->mimeData()->hasFormat("image/png"))
4109 event->acceptProposedAction();
4110 addFloatImageInt(event->mimeData()->imageData().value<QPixmap>());
4111 cout << "accepted drop\n";
4115 if (event->provides("image/png"))
4118 if (Q3ImageDrag::decode(event, pix))
4120 addFloatImageInt(pix);
4126 } else if (event->provides("application/x-moz-file-promise-url") &&
4127 event->provides("application/x-moz-nativeimage"))
4129 // Contains url to the img src in unicode16
4130 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
4131 QString url = QString((const QChar*)d.data(),d.size()/2);
4135 } else if (event->provides ("text/uri-list"))
4136 { // Uris provided e.g. by konqueror
4137 Q3UriDrag::decode (event,uris);
4138 } else if (event->provides ("_NETSCAPE_URL"))
4139 { // Uris provided by Mozilla
4140 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
4143 } else if (event->provides("text/html")) {
4145 // Handels text mime types
4146 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
4147 QByteArray d = event->encodedData("text/html");
4150 text = QString((const QChar*)d.data(),d.size()/2);
4154 textEditor->setText(text);
4158 } else if (event->provides("text/plain")) {
4159 QByteArray d = event->encodedData("text/plain");
4162 text = QString((const QChar*)d.data(),d.size()/2);
4166 textEditor->setText(text);
4173 /* FIXME not ported yet QSTRINGLIST has no next...
4180 for (const char* u=uris.first(); u; u=uris.next())
4182 bo=((BranchObj*)selection)->addBranch();
4185 s=Q3UriDrag::uriToLocalFile(u);
4188 QString file = QDir::convertSeparators(s);
4189 heading = QFileInfo(file).baseName();
4191 if (file.endsWith(".vym", false))
4192 bo->setVymLink(file);
4201 if (!heading.isEmpty())
4202 bo->setHeading(heading);
4212 //FIXME saveState has to be called earlier for each of the drops...
4213 //saveStateComplete("Drop Event"); //TODO undo Command
4214 mapCenter->reposition();
4221 void MapEditor::addFloatImageInt (const QPixmap &img)
4224 (typeid(*selection) == typeid(BranchObj)) ||
4225 (typeid(*selection) == typeid(MapCenterObj)) )
4227 BranchObj *bo=((BranchObj*)selection);
4228 //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
4229 //QString fn=fd->selectedFile();
4230 //lastImageDir=fn.left(fn.findRev ("/"));
4231 FloatImageObj *fio=bo->addFloatImage();
4233 fio->setOriginalFilename("Image added by Drag and Drop");
4234 mapCenter->reposition();
4241 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
4243 if (!imageBuffer) imageBuffer = new QBuffer();
4244 if (!imageBuffer->isOpen()) {
4245 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
4247 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
4251 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
4253 if (nop->state()==Q3NetworkProtocol::StDone) {
4254 QPixmap img(imageBuffer->buffer());
4255 addFloatImageInt (img);
4259 imageBuffer->close();
4261 imageBuffer->close();
4268 void MapEditor::fetchImage(const QString &url)
4271 urlOperator->stop();
4272 disconnect(urlOperator);
4276 urlOperator = new Q3UrlOperator(url);
4277 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
4278 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
4280 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
4281 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));