Removed more QT3 stuff. Drag & Drop not 100% functional at the moment
3 //#include <q3urloperator.h>
4 #include <q3paintdevicemetrics.h>
5 #include <q3filedialog.h>
14 #include "editxlinkdialog.h"
16 #include "extrainfodialog.h"
18 #include "linkablemapobj.h"
19 #include "mainwindow.h"
21 #include "texteditor.h"
22 #include "warningdialog.h"
26 extern TextEditor *textEditor;
27 extern int statusbarTime;
28 extern Main *mainWindow;
29 extern QString tmpVymDir;
30 extern QString clipboardDir;
31 extern bool clipboardEmpty;
32 extern FlagRowObj *standardFlagsDefault;
34 extern QMenu* branchContextMenu;
35 extern QMenu* branchAddContextMenu;
36 extern QMenu* branchRemoveContextMenu;
37 extern QMenu* branchLinksContextMenu;
38 extern QMenu* branchXLinksContextMenuEdit;
39 extern QMenu* branchXLinksContextMenuFollow;
40 extern QMenu* floatimageContextMenu;
41 extern QMenu* canvasContextMenu;
44 extern Settings settings;
45 extern ImageIO imageIO;
47 extern QString vymName;
48 extern QString vymVersion;
50 extern QString iconPath;
51 extern QDir vymBaseDir;
52 extern QDir lastImageDir;
54 int MapEditor::mapNum=0; // make instance
56 ///////////////////////////////////////////////////////////////////////
57 ///////////////////////////////////////////////////////////////////////
59 QWidget* parent, const char* name, Qt::WFlags f) :
60 Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
62 //cout << "Constructor ME "<<this<<endl;
65 viewport()->setAcceptDrops(true);
67 mapCanvas = new Q3Canvas(width(),height());
68 mapCanvas->setAdvancePeriod(30);
69 mapCanvas->setBackgroundColor (Qt::white);
71 setCanvas (mapCanvas);
73 // Always show scroll bars (automatic would flicker sometimes)
74 setVScrollBarMode ( Q3ScrollView::AlwaysOn );
75 setHScrollBarMode ( Q3ScrollView::AlwaysOn );
77 mapCenter = new MapCenterObj(mapCanvas);
78 mapCenter->setVisibility (true);
79 mapCenter->setMapEditor (this);
80 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
81 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
85 defLinkColor=QColor (0,0,255);
86 defXLinkColor=QColor (180,180,180);
87 linkcolorhint=DefaultColor;
88 linkstyle=StylePolyParabel;
90 // Create bitmap cursors, platform dependant
91 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
92 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
93 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
94 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
96 setFocusPolicy (Qt::StrongFocus);
107 xelection.setMapCenter (mapCenter);
110 defXLinkColor=QColor (230,230,230);
118 fileName=tr("unnamed");
121 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
122 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
124 // Initialize find routine
131 blockReposition=false;
132 blockSaveState=false;
136 // Create temporary files
139 // Initially set movingCentre
142 mapCenter->reposition(); // for positioning heading
146 MapEditor::~MapEditor()
148 if (imageBuffer) delete imageBuffer;
154 //cout <<"Destructor MapEditor\n";
157 MapCenterObj* MapEditor::getMapCenter()
162 Q3Canvas* MapEditor::getCanvas()
167 void MapEditor::adjustCanvasSize()
169 // To adjust the canvas to map, viewport size and position, we have to
170 // do some coordinate magic...
172 // Get rectangle of (scroll-)view.
173 // We want to be in canvas coords, so
174 // we map. Important if view is zoomed...
175 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
176 visibleWidth(), visibleHeight()) );
178 // Now we need the bounding box of view AND map to calc the correct canvas size.
179 // Why? Because if the map itself is moved out of view, the view has to be enlarged
180 // to avoid jumping aroung...
181 QRect map=mapCenter->getTotalBBox();
183 // right edge - left edge
184 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
185 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
188 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
189 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
192 // move the map on canvas (in order to not move it on screen) this is neccessary
193 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
194 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
195 // to scroll to an empty area of canvas to the left.
196 // b) if topleft corner of map left of or above topleft of canvas
200 if (cw > mapCanvas->width() )
202 if (map.x()<0) dx=-map.x();
204 if (cw < mapCanvas->width() )
205 dx=-min (view.x(),map.x());
206 if (ch > mapCanvas->height() )
208 if (map.y()<0) dy=-map.y();
210 if (ch < mapCanvas->height() )
212 dy=-min (view.y(),map.y());
214 // We really have to resize now. Let's go...
215 mapCanvas->resize (cw,ch);
216 if ( (dx!=0) || (dy!=0) )
218 mapCenter->moveAllBy(dx,dy);
219 mapCenter->reposition();
220 // mapCenter->positionBBox(); // To move float
222 // scroll the view (in order to not move map on screen)
228 bool MapEditor::isRepositionBlocked()
230 return blockReposition;
233 QString MapEditor::getName (LinkableMapObj *lmo)
236 if (!lmo) return QString("Error: NULL has no name!");
238 if ((typeid(*lmo) == typeid(BranchObj) ||
239 typeid(*lmo) == typeid(MapCenterObj)))
242 s=(((BranchObj*)lmo)->getHeading());
243 if (s=="") s="unnamed";
244 return QString("branch (%1)").arg(s);
245 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
247 if ((typeid(*lmo) == typeid(FloatImageObj) ))
248 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
249 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
250 return QString("Unknown type has no name!");
253 void MapEditor::makeTmpDirs()
255 // Create unique temporary directories
256 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
257 histPath=QDir::convertSeparators (tmpMapDir+"/history");
262 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSel)
264 // tmpdir temporary directory to which data will be written
265 // prefix mapname, which will be appended to images etc.
266 // writeflags Only write flags for "real" save of map, not undo
267 // offset offset of bbox of whole map in canvas.
268 // Needed for XML export
284 ls="StylePolyParabel";
288 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
290 if (linkcolorhint==HeadingColor)
291 colhint=attribut("linkColorHint","HeadingColor");
293 QString mapAttr=attribut("version",vymVersion);
294 if (!saveSel || saveSel==mapCenter)
295 mapAttr+= attribut("author",mapCenter->getAuthor()) +
296 attribut("comment",mapCenter->getComment()) +
297 attribut("date",mapCenter->getDate()) +
298 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
299 attribut("linkStyle", ls ) +
300 attribut("linkColor", defLinkColor.name() ) +
301 attribut("defXLinkColor", defXLinkColor.name() ) +
302 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
304 s+=beginElement("vymmap",mapAttr);
307 // Find the used flags while traversing the tree
308 standardFlagsDefault->resetUsedCounter();
310 // Reset the counters before saving
311 // TODO constr. of FIO creates lots of objects, better do this in some other way...
312 FloatImageObj (mapCanvas).resetSaveCounter();
314 // Build xml recursivly
315 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
316 // Save complete map, if saveSel not set
317 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
320 if ( typeid(*saveSel) == typeid(BranchObj) )
322 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
323 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
325 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
327 else if (selection && typeid(*selection)==typeid(BranchObj))
328 // Save selected branch is saved from mainwindow //FIXME maybe use "subtree" above?
329 // FIXME is this possible at all? BO is already above...
330 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
333 // Save local settings
334 s+=settings.getXMLData (destPath);
337 if (selection && !saveSel )
338 s+=valueElement("select",selection->getSelectString());
341 s+=endElement("vymmap");
344 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
348 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
350 // save the selected part of the map, Undo will replace part of map
351 QString undoSelection="";
353 undoSelection=undoSel->getSelectString();
355 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
356 QString redoSelection="";
358 redoSelection=undoSel->getSelectString();
360 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
363 saveState (PartOfMap,
364 undoSelection, "addMapReplace (\"PATH\")",
370 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
374 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
377 QString undoSelection=redoSel->getParObj()->getSelectString();
378 QString redoSelection=redoSel->getSelectString();
379 if (typeid(*redoSel) == typeid(BranchObj) )
381 // save the selected branch of the map, Undo will insert part of map
382 saveState (PartOfMap,
383 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
384 redoSelection, "delete ()",
391 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
393 // "Normal" savestate: save commands, selections and comment
394 // so just save commands for undo and redo
395 // and use current selection
397 QString redoSelection="";
398 if (redoSel) redoSelection=redoSel->getSelectString();
399 QString undoSelection="";
400 if (undoSel) undoSelection=undoSel->getSelectString();
402 saveState (UndoCommand,
409 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
411 // "Normal" savestate: save commands, selections and comment
412 // so just save commands for undo and redo
413 // and use current selection
414 saveState (UndoCommand,
422 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
426 if (blockSaveState) return;
428 /* TODO remove after testing
430 cout << "ME::saveState() "<<endl;
432 int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
433 int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
434 int curStep=undoSet.readNumEntry ("/history/curStep",0);
435 // Find out current undo directory
436 if (undosAvail<stepsTotal) undosAvail++;
438 if (curStep>stepsTotal) curStep=1;
440 QString backupXML="";
441 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
442 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
443 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
445 // Create bakMapDir if not available
448 makeSubDirs (bakMapDir);
450 // Save depending on how much needs to be saved
452 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel);
454 QString undoCommand="";
455 if (savemode==UndoCommand)
459 else if (savemode==PartOfMap )
462 undoCommand.replace ("PATH",bakMapPath);
465 if (!backupXML.isEmpty())
466 // Write XML Data to disk
467 saveStringToDisk (QString(bakMapPath),backupXML);
469 // We would have to save all actions in a tree, to keep track of
470 // possible redos after a action. Possible, but we are too lazy: forget about redos.
473 // Write the current state to disk
474 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
475 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
476 undoSet.setEntry ("/history/curStep",QString::number(curStep));
477 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
478 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
479 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
480 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
481 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
482 undoSet.setEntry (QString("/history/version"),vymVersion);
483 undoSet.writeSettings(histPath);
485 /* TODO remove after testing
487 //cout << " into="<< histPath.toStdString()<<endl;
488 cout << " stepsTotal="<<stepsTotal<<
489 ", undosAvail="<<undosAvail<<
490 ", redosAvail="<<redosAvail<<
491 ", curStep="<<curStep<<endl;
492 cout << " ---------------------------"<<endl;
493 cout << " comment="<<comment.toStdString()<<endl;
494 cout << " undoCom="<<undoCommand.toStdString()<<endl;
495 cout << " undoSel="<<undoSelection.toStdString()<<endl;
496 cout << " redoCom="<<redoCom.toStdString()<<endl;
497 cout << " redoSel="<<redoSelection.toStdString()<<endl;
498 if (saveSel) cout << " saveSel="<<saveSel->getSelectString().ascii()<<endl;
499 cout << " ---------------------------"<<endl;
501 mainWindow->updateHistory (undoSet);
506 void MapEditor::parseAtom(const QString &atom)
513 // Split string s into command and parameters
514 api.parseInput (atom);
515 QString com=api.command();
518 if (com=="addBranch")
522 api.setError (Aborted,"Nothing selected");
523 } else if ( (typeid(*selection) != typeid(BranchObj) &&
524 typeid(*selection) != typeid(MapCenterObj)) )
526 api.setError (Aborted,"Type of selection is not a branch");
531 if (api.checkParamCount(pl))
533 if (api.paramCount()==0)
534 addNewBranchInt (-2);
538 if (ok ) addNewBranchInt (y);
542 } else if (com=="addBranchBefore")
546 api.setError (Aborted,"Nothing selected");
547 } else if ( (typeid(*selection) != typeid(BranchObj) &&
548 typeid(*selection) != typeid(MapCenterObj)) )
550 api.setError (Aborted,"Type of selection is not a branch");
553 if (api.paramCount()==0)
555 addNewBranchBefore ();
558 } else if (com==QString("addMapReplace"))
562 api.setError (Aborted,"Nothing selected");
563 } else if ( (typeid(*selection) != typeid(BranchObj) &&
564 typeid(*selection) != typeid(MapCenterObj)) )
566 api.setError (Aborted,"Type of selection is not a branch");
567 } else if (api.checkParamCount(1))
569 //s=api.parString (ok,0); // selection
570 t=api.parString (ok,0); // path to map
571 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
572 addMapReplaceInt(selection->getSelectString(),t);
574 } else if (com==QString("addMapInsert"))
578 api.setError (Aborted,"Nothing selected");
579 } else if ( (typeid(*selection) != typeid(BranchObj) &&
580 typeid(*selection) != typeid(MapCenterObj)) )
582 api.setError (Aborted,"Type of selection is not a branch");
585 if (api.checkParamCount(2))
587 t=api.parString (ok,0); // path to map
588 y=api.parInt(ok,1); // position
589 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
590 addMapInsertInt(t,y);
593 } else if (com=="colorItem")
597 api.setError (Aborted,"Nothing selected");
598 } else if ( typeid(*selection) != typeid(BranchObj) &&
599 typeid(*selection) != typeid(MapCenterObj))
601 api.setError (Aborted,"Type of selection is not a branch");
602 } else if (api.checkParamCount(1))
604 QColor c=api.parColor (ok,0);
605 if (ok) colorItem (c);
607 } else if (com=="colorBranch")
611 api.setError (Aborted,"Nothing selected");
612 } else if ( typeid(*selection) != typeid(BranchObj) &&
613 typeid(*selection) != typeid(MapCenterObj))
615 api.setError (Aborted,"Type of selection is not a branch");
616 } else if (api.checkParamCount(1))
618 QColor c=api.parColor (ok,0);
619 if (ok) colorBranch (c);
621 } else if (com=="cut")
625 api.setError (Aborted,"Nothing selected");
626 } else if ( typeid(*selection) != typeid(BranchObj) &&
627 typeid(*selection) != typeid(MapCenterObj) &&
628 typeid(*selection) != typeid(FloatImageObj) )
630 api.setError (Aborted,"Type of selection is not a branch or floatimage");
631 } else if (api.checkParamCount(0))
635 } else if (com=="delete")
639 api.setError (Aborted,"Nothing selected");
640 } else if ( (typeid(*selection) != typeid(BranchObj) &&
641 typeid(*selection) != typeid(MapCenterObj)) )
643 api.setError (Aborted,"Type of selection is not a branch");
644 } else if (api.checkParamCount(0))
648 } else if (com=="deleteKeepChilds")
652 api.setError (Aborted,"Nothing selected");
653 } else if ( (typeid(*selection) != typeid(BranchObj) &&
654 typeid(*selection) != typeid(MapCenterObj)) )
656 api.setError (Aborted,"Type of selection is not a branch");
657 } else if (api.checkParamCount(0))
661 } else if (com=="deleteChilds")
665 api.setError (Aborted,"Nothing selected");
666 } else if ( (typeid(*selection) != typeid(BranchObj) &&
667 typeid(*selection) != typeid(MapCenterObj)) )
669 api.setError (Aborted,"Type of selection is not a branch");
670 } else if (api.checkParamCount(0))
674 } else if (com=="linkBranchToPos")
678 api.setError (Aborted,"Nothing selected");
679 } else if ( (typeid(*selection) != typeid(BranchObj) &&
680 typeid(*selection) != typeid(MapCenterObj)) )
682 api.setError (Aborted,"Type of selection is not a branch");
683 } else if (api.checkParamCount(4))
685 // 0 selectstring of parent
686 // 1 num in parent (for branches)
687 // 2,3 x,y of mainbranch or mapcenter
688 s=api.parString(ok,0);
689 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
692 if (typeid(*dst) == typeid(BranchObj) )
694 // Get number in parent
697 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
698 } else if (typeid(*dst) == typeid(MapCenterObj) )
700 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
701 // Get coordinates of mainbranch
706 if (ok) ((BranchObj*)selection)->move (x,y);
711 } else if (com=="moveBranchUp")
715 api.setError (Aborted,"Nothing selected");
716 } else if ( (typeid(*selection) != typeid(BranchObj) &&
717 typeid(*selection) != typeid(MapCenterObj)) )
719 api.setError (Aborted,"Type of selection is not a branch");
720 } else if (api.checkParamCount(0))
724 } else if (com=="moveBranchDown")
728 api.setError (Aborted,"Nothing selected");
729 } else if ( (typeid(*selection) != typeid(BranchObj) &&
730 typeid(*selection) != typeid(MapCenterObj)) )
732 api.setError (Aborted,"Type of selection is not a branch");
733 } else if (api.checkParamCount(0))
737 } else if (com=="move")
741 api.setError (Aborted,"Nothing selected");
742 } else if ( typeid(*selection) != typeid(BranchObj) &&
743 typeid(*selection) != typeid(MapCenterObj) &&
744 typeid(*selection) != typeid(FloatImageObj) )
746 api.setError (Aborted,"Type of selection is not a branch or floatimage");
747 } else if (api.checkParamCount(2))
756 } else if (com=="moveRel")
760 api.setError (Aborted,"Nothing selected");
761 } else if ( typeid(*selection) != typeid(BranchObj) &&
762 typeid(*selection) != typeid(MapCenterObj) &&
763 typeid(*selection) != typeid(FloatImageObj) )
765 api.setError (Aborted,"Type of selection is not a branch or floatimage");
766 } else if (api.checkParamCount(2))
772 if (ok) moveRel (x,y);
775 } else if (com=="paste")
779 api.setError (Aborted,"Nothing selected");
780 } else if ( typeid(*selection) != typeid(BranchObj) &&
781 typeid(*selection) != typeid(MapCenterObj) )
783 api.setError (Aborted,"Type of selection is not a branch");
784 } else if (api.checkParamCount(0))
788 } else if (com=="select")
790 if (api.checkParamCount(1))
792 s=api.parString(ok,0);
795 } else if (com=="setMapAuthor")
797 if (api.checkParamCount(1))
799 s=api.parString(ok,0);
800 if (ok) setMapAuthor (s);
802 } else if (com=="setMapComment")
804 if (api.checkParamCount(1))
806 s=api.parString(ok,0);
807 if (ok) setMapComment(s);
809 } else if (com=="setMapBackgroundColor")
813 api.setError (Aborted,"Nothing selected");
814 } else if ( (typeid(*selection) != typeid(BranchObj) &&
815 typeid(*selection) != typeid(MapCenterObj)) )
817 api.setError (Aborted,"Type of selection is not a branch");
818 } else if (api.checkParamCount(1))
820 QColor c=api.parColor (ok,0);
821 if (ok) setMapBackgroundColor (c);
823 } else if (com=="setMapDefLinkColor")
827 api.setError (Aborted,"Nothing selected");
828 } else if ( (typeid(*selection) != typeid(BranchObj) &&
829 typeid(*selection) != typeid(MapCenterObj)) )
831 api.setError (Aborted,"Type of selection is not a branch");
832 } else if (api.checkParamCount(1))
834 QColor c=api.parColor (ok,0);
835 if (ok) setMapDefLinkColor (c);
837 } else if (com=="setMapLinkStyle")
839 if (api.checkParamCount(1))
841 s=api.parString (ok,0);
842 if (ok) setMapLinkStyle(s);
844 } else if (com=="setHeading")
848 api.setError (Aborted,"Nothing selected");
849 } else if ( (typeid(*selection) != typeid(BranchObj) &&
850 typeid(*selection) != typeid(MapCenterObj)) )
852 api.setError (Aborted,"Type of selection is not a branch");
853 } else if (api.checkParamCount(1))
855 s=api.parString (ok,0);
859 } else if (com=="setHideExport")
863 api.setError (Aborted,"Nothing selected");
864 } else if ( typeid(*selection) != typeid(BranchObj) &&
865 typeid(*selection) != typeid(FloatImageObj) )
867 api.setError (Aborted,"Type of selection is not a branch or floatimage");
868 } else if (api.checkParamCount(1))
871 if (ok) setHideExport (b);
873 } else if (com=="setURL")
877 api.setError (Aborted,"Nothing selected");
878 } else if ( (typeid(*selection) != typeid(BranchObj) &&
879 typeid(*selection) != typeid(MapCenterObj)) )
881 api.setError (Aborted,"Type of selection is not a branch");
882 } else if (api.checkParamCount(1))
884 s=api.parString (ok,0);
885 if (ok) setURLInt(s);
887 } else if (com=="setVymLink")
891 api.setError (Aborted,"Nothing selected");
892 } else if ( (typeid(*selection) != typeid(BranchObj) &&
893 typeid(*selection) != typeid(MapCenterObj)) )
895 api.setError (Aborted,"Type of selection is not a branch");
896 } else if (api.checkParamCount(1))
898 s=api.parString (ok,0);
899 if (ok) setVymLinkInt(s);
902 else if (com=="setFlag")
906 api.setError (Aborted,"Nothing selected");
907 } else if ( (typeid(*selection) != typeid(BranchObj) &&
908 typeid(*selection) != typeid(MapCenterObj)) )
910 api.setError (Aborted,"Type of selection is not a branch");
911 } else if (api.checkParamCount(1))
913 s=api.parString(ok,0);
916 BranchObj* bo=(BranchObj*)selection;
917 bo->activateStandardFlag(s);
918 bo->updateFlagsToolbar();
922 else if (com=="unsetFlag")
926 api.setError (Aborted,"Nothing selected");
927 } else if ( (typeid(*selection) != typeid(BranchObj) &&
928 typeid(*selection) != typeid(MapCenterObj)) )
930 api.setError (Aborted,"Type of selection is not a branch");
931 } else if (api.checkParamCount(1))
933 s=api.parString(ok,0);
936 BranchObj* bo=(BranchObj*)selection;
937 bo->deactivateStandardFlag(s);
938 bo->updateFlagsToolbar();
943 api.setError (Aborted,"Unknown command");
947 if (api.errorLevel()==NoError)
951 // TODO Error handling
952 qWarning("MapEditor::parseAtom: Error!");
953 qWarning(api.errorMessage());
958 bool MapEditor::isDefault()
963 bool MapEditor::isUnsaved()
968 bool MapEditor::hasChanged()
973 void MapEditor::setChanged()
981 void MapEditor::closeMap()
983 // Unselect before disabling the toolbar actions
984 if (selection) selection->unselect();
992 void MapEditor::setFilePath(QString fname)
994 setFilePath (fname,fname);
997 void MapEditor::setFilePath(QString fname, QString destname)
999 if (fname.isEmpty() || fname=="")
1006 filePath=fname; // becomes absolute path
1007 fileName=fname; // gets stripped of path
1008 destPath=destname; // needed for vymlinks
1010 // If fname is not an absolute path, complete it
1011 filePath=QDir(fname).absPath();
1012 fileDir=filePath.left (1+filePath.findRev ("/"));
1014 // Set short name, too. Search from behind:
1015 int i=fileName.findRev("/");
1016 if (i>=0) fileName=fileName.remove (0,i+1);
1018 // Forget the .vym (or .xml) for name of map
1019 mapName=fileName.left(fileName.findRev(".",-1,true) );
1023 QString MapEditor::getFilePath()
1028 QString MapEditor::getFileName()
1033 QString MapEditor::getMapName()
1038 QString MapEditor::getDestPath()
1043 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
1045 ErrorCode err=success;
1049 if (selection) selection->unselect();
1052 mapCenter->setMapEditor(this);
1053 // (map state is set later at end of load...)
1056 if (!selection || (typeid(*selection) != typeid(BranchObj) &&
1057 typeid(*selection) != typeid (MapCenterObj)))
1059 BranchObj *bo=(BranchObj*)selection;
1060 if (lmode==ImportAdd)
1061 saveStateChangingPart(
1064 QString("addMapInsert (%1)").arg(fname),
1065 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1067 saveStateChangingPart(
1070 QString("addMapReplace(%1)").arg(fname),
1071 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1075 mapBuilderHandler handler;
1076 QFile file( fname );
1078 // I am paranoid: file should exist anyway
1079 // according to check in mainwindow.
1080 if (!file.exists() )
1082 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1083 tr("Couldn't open map " +fname)+".");
1087 blockReposition=true;
1088 QXmlInputSource source( file);
1089 QXmlSimpleReader reader;
1090 reader.setContentHandler( &handler );
1091 reader.setErrorHandler( &handler );
1092 handler.setMapEditor( this );
1093 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
1094 handler.setInputFile (file.name());
1095 handler.setLoadMode (lmode);
1096 blockSaveState=true;
1097 bool ok = reader.parse( source );
1098 blockReposition=false;
1099 blockSaveState=false;
1103 mapCenter->reposition();
1113 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1114 tr( handler.errorProtocol() ) );
1116 // Still return "success": the map maybe at least
1117 // partially read by the parser
1124 int MapEditor::save (const SaveMode &savemode)
1128 // Create mapName and fileDir
1129 makeSubDirs (fileDir);
1133 fname=mapName+".xml";
1135 // use name given by user, even if he chooses .doc
1140 if (savemode==CompleteMap || selection==NULL)
1141 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
1143 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
1145 if (!saveStringToDisk(fileDir+fname,saveFile))
1158 void MapEditor::setZipped (bool z)
1163 bool MapEditor::saveZipped ()
1168 void MapEditor::print()
1172 printer = new QPrinter;
1173 printer->setColorMode (QPrinter::Color);
1174 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1177 QRect totalBBox=mapCenter->getTotalBBox();
1179 // Try to set orientation automagically
1180 // Note: Interpretation of generated postscript is amibiguous, if
1181 // there are problems with landscape mode, see
1182 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1184 if (totalBBox.width()>totalBBox.height())
1185 // recommend landscape
1186 printer->setOrientation (QPrinter::Landscape);
1188 // recommend portrait
1189 printer->setOrientation (QPrinter::Portrait);
1191 if ( printer->setup(this) )
1192 // returns false, if printing is canceled
1194 QPainter pp(printer);
1196 // Don't print the visualisation of selection
1197 LinkableMapObj *oldselection=NULL;
1200 oldselection=selection;
1201 selection->unselect();
1204 // Handle sizes of map and paper:
1206 // setWindow defines which part of the canvas will be transformed
1207 // setViewport defines area on paper in device coordinates (dpi)
1208 // e.g. (0,50,700,700) is upper part on A4
1209 // see also /usr/lib/qt3/doc/html/coordsys.html
1211 Q3PaintDeviceMetrics metrics (printer);
1213 double paperAspect = (double)metrics.width() / (double)metrics.height();
1214 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1216 QRect mapRect=totalBBox;
1217 Q3CanvasRectangle *frame=NULL;
1218 Q3CanvasText *footerFN=NULL;
1219 Q3CanvasText *footerDate=NULL;
1220 if (printFrame || printFooter)
1225 // Print frame around map
1226 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1227 totalBBox.width()+20, totalBBox.height()+20);
1228 frame=new Q3CanvasRectangle (mapRect,mapCanvas);
1229 frame->setBrush (QColor(Qt::white));
1230 frame->setPen (QColor(Qt::black));
1234 /* TODO remove after testing
1235 QCanvasLine *l=new QCanvasLine (mapCanvas);
1236 l->setPoints (0,0,mapRect.width(),mapRect.height());
1237 l->setPen (QPen(QColor(black), 1));
1244 // Print footer below map
1246 font.setPointSize(10);
1247 footerFN=new Q3CanvasText (mapCanvas);
1248 footerFN->setText ("VYM - " + fileName);
1249 footerFN->setFont(font);
1250 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1251 footerFN->setZ(Z_TEXT);
1253 footerDate=new Q3CanvasText (mapCanvas);
1254 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1255 footerDate->setFont(font);
1256 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1257 footerDate->setZ(Z_TEXT);
1260 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1263 pp.setWindow (mapRect);
1266 if (mapAspect>=paperAspect)
1268 // Fit horizontally to paper width
1269 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1272 // Fit vertically to paper height
1273 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1276 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1278 // Delete Frame and footer
1282 delete (footerDate);
1284 if (frame) delete (frame);
1286 // Restore selection
1289 selection=oldselection;
1290 selection->select();
1293 // Save settings in vymrc
1294 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1298 QPixmap MapEditor::getPixmap()
1300 QRect mapRect=mapCenter->getTotalBBox();
1301 QPixmap pix (mapRect.size());
1304 // Don't print the visualisation of selection
1305 LinkableMapObj *oldselection=NULL;
1308 oldselection=selection;
1309 selection->unselect();
1312 pp.setWindow (mapRect);
1314 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1317 // Restore selection
1320 selection=oldselection;
1321 selection->select();
1327 void MapEditor::setHideTmpMode (HideTmpMode mode)
1330 mapCenter->setHideTmp (hidemode);
1331 mapCenter->reposition();
1336 HideTmpMode MapEditor::getHideTmpMode()
1341 void MapEditor::exportImage(QString fn)
1343 setExportMode (true);
1344 QPixmap pix (getPixmap());
1345 pix.save(fn, "PNG");
1346 setExportMode (false);
1349 void MapEditor::setExportMode (bool b)
1351 // should be called before and after exports
1352 // depending on the settings
1353 if (b && settings.value("/export/useHideExport","yes")=="yes")
1354 setHideTmpMode (HideExport);
1356 setHideTmpMode (HideNone);
1359 void MapEditor::exportImage(QString fn, QString format)
1361 setExportMode (true);
1362 QPixmap pix (getPixmap());
1363 pix.save(fn, format);
1364 setExportMode (false);
1367 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1371 ex.setMapCenter(mapCenter);
1372 if (ex.setConfigFile(cf))
1374 setExportMode (true);
1375 ex.exportPresentation();
1376 setExportMode (false);
1382 void MapEditor::exportXML(const QString &dir)
1384 // Hide stuff during export, if settings want this
1385 setExportMode (true);
1387 // Create subdirectories
1390 // write to directory
1391 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1394 file.setName ( dir + "/"+mapName+".xml");
1395 if ( !file.open( QIODevice::WriteOnly ) )
1397 // This should neverever happen
1398 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1402 // Write it finally, and write in UTF8, no matter what
1403 QTextStream ts( &file );
1404 ts.setEncoding (QTextStream::UnicodeUTF8);
1408 // Now write image, too
1409 exportImage (dir+"/images/"+mapName+".png");
1411 setExportMode (false);
1414 void MapEditor::clear()
1418 selection->unselect();
1425 void MapEditor::copy()
1429 // write to directory
1430 QString clipfile="part";
1431 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1434 file.setName ( clipboardDir + "/"+clipfile+".xml");
1435 if ( !file.open( QIODevice::WriteOnly ) )
1437 // This should neverever happen
1438 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1442 // Write it finally, and write in UTF8, no matter what
1443 QTextStream ts( &file );
1444 ts.setEncoding (QTextStream::UnicodeUTF8);
1448 clipboardEmpty=false;
1453 void MapEditor::redo()
1455 blockSaveState=true;
1457 // Restore variables
1458 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1459 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1460 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1461 // Can we undo at all?
1462 if (redosAvail<1) return;
1465 if (undosAvail<stepsTotal) undosAvail++;
1467 if (curStep>stepsTotal) curStep=1;
1468 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1469 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1470 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1471 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1472 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1473 QString version=undoSet.readEntry ("/history/version");
1475 if (!checkVersion(version))
1476 QMessageBox::warning(0,tr("Warning"),
1477 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1480 // Find out current undo directory
1481 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1483 /* TODO remove testing
1485 cout << "ME::redo() begin\n";
1486 cout << " undosAvail="<<undosAvail<<endl;
1487 cout << " redosAvail="<<redosAvail<<endl;
1488 cout << " curStep="<<curStep<<endl;
1489 cout << " ---------------------------"<<endl;
1490 cout << " comment="<<comment.toStdString()<<endl;
1491 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1492 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1493 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1494 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1495 cout << " ---------------------------"<<endl<<endl;
1497 // select object before redo
1498 if (!redoSelection.isEmpty())
1499 select (redoSelection);
1502 parseAtom (redoCommand);
1503 mapCenter->reposition();
1505 blockSaveState=false;
1507 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1508 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1509 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1510 undoSet.writeSettings(histPath);
1512 mainWindow->updateHistory (undoSet);
1515 /* TODO remove testing
1516 cout << "ME::redo() end\n";
1517 cout << " undosAvail="<<undosAvail<<endl;
1518 cout << " redosAvail="<<redosAvail<<endl;
1519 cout << " curStep="<<curStep<<endl;
1520 cout << " ---------------------------"<<endl<<endl;
1526 bool MapEditor::isRedoAvailable()
1528 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1534 void MapEditor::undo()
1536 blockSaveState=true;
1538 // Restore variables
1539 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1540 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1541 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1543 // Can we undo at all?
1544 if (undosAvail<1) return;
1546 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1547 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1548 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1549 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1550 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1551 QString version=undoSet.readEntry ("/history/version");
1553 if (!checkVersion(version))
1554 QMessageBox::warning(0,tr("Warning"),
1555 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1557 // Find out current undo directory
1558 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1560 // select object before undo
1561 if (!undoSelection.isEmpty())
1562 select (undoSelection);
1566 cout << "ME::undo() begin\n";
1567 cout << " undosAvail="<<undosAvail<<endl;
1568 cout << " redosAvail="<<redosAvail<<endl;
1569 cout << " curStep="<<curStep<<endl;
1570 cout << " ---------------------------"<<endl;
1571 cout << " comment="<<comment.toStdString()<<endl;
1572 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1573 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1574 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1575 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1576 cout << " ---------------------------"<<endl<<endl;
1577 parseAtom (undoCommand);
1578 mapCenter->reposition();
1582 if (curStep<1) curStep=stepsTotal;
1586 blockSaveState=false;
1587 /* TODO remove testing
1588 cout << "ME::undo() end\n";
1589 cout << " undosAvail="<<undosAvail<<endl;
1590 cout << " redosAvail="<<redosAvail<<endl;
1591 cout << " curStep="<<curStep<<endl;
1592 cout << " ---------------------------"<<endl<<endl;
1595 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1596 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1597 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1598 undoSet.writeSettings(histPath);
1600 mainWindow->updateHistory (undoSet);
1604 bool MapEditor::isUndoAvailable()
1606 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1612 void MapEditor::gotoHistoryStep (int i)
1614 // Restore variables
1615 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1616 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1618 if (i<0) i=undosAvail+redosAvail;
1620 // Clicking above current step makes us undo things
1623 for (int j=0; j<undosAvail-i; j++) undo();
1626 // Clicking below current step makes us redo things
1628 for (int j=undosAvail; j<i; j++) redo();
1630 // And ignore clicking the current row ;-)
1633 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
1635 QString pathDir=path.left(path.findRev("/"));
1641 // We need to parse saved XML data
1642 mapBuilderHandler handler;
1643 QXmlInputSource source( file);
1644 QXmlSimpleReader reader;
1645 reader.setContentHandler( &handler );
1646 reader.setErrorHandler( &handler );
1647 handler.setMapEditor( this );
1648 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1649 if (undoSel.isEmpty())
1653 handler.setLoadMode (NewMap);
1657 handler.setLoadMode (ImportReplace);
1659 blockReposition=true;
1660 bool ok = reader.parse( source );
1661 blockReposition=false;
1664 // This should never ever happen
1665 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1666 handler.errorProtocol());
1669 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1672 void MapEditor::addMapInsertInt (const QString &path, int pos)
1674 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1675 typeid(*selection) == typeid(MapCenterObj)))
1677 QString pathDir=path.left(path.findRev("/"));
1683 // We need to parse saved XML data
1684 mapBuilderHandler handler;
1685 QXmlInputSource source( file);
1686 QXmlSimpleReader reader;
1687 reader.setContentHandler( &handler );
1688 reader.setErrorHandler( &handler );
1689 handler.setMapEditor( this );
1690 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1691 handler.setLoadMode (ImportAdd);
1692 blockReposition=true;
1693 bool ok = reader.parse( source );
1694 blockReposition=false;
1697 // This should never ever happen
1698 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1699 handler.errorProtocol());
1701 if (selection!=mapCenter)
1702 ((BranchObj*)selection)->getLastBranch()->moveBranchTo ((BranchObj*)(selection),pos);
1704 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1708 void MapEditor::pasteNoSave()
1710 load (clipboardDir+"/part.xml",ImportAdd);
1713 void MapEditor::cutNoSave()
1719 void MapEditor::paste()
1721 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1722 typeid(*selection) == typeid(MapCenterObj)))
1725 saveStateChangingPart(
1729 QString("Paste to %1").arg( getName(selection))
1731 mapCenter->reposition();
1736 void MapEditor::cut()
1738 saveStateChangingPart(
1739 selection->getParObj(),
1742 QString("Cut %1").arg(getName(selection))
1746 mapCenter->reposition();
1750 void MapEditor::move(const int &x, const int &y)
1754 QString ps=qpointToString (selection->getAbsPos());
1755 QString s=selection->getSelectString();
1758 s, "move "+qpointToString (QPoint (x,y)),
1759 QString("Move %1 to %2").arg(getName(selection)).arg(ps));
1760 selection->move(x,y);
1761 mapCenter->reposition();
1767 void MapEditor::moveRel (const int &x, const int &y)
1769 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1770 typeid(*selection) == typeid(MapCenterObj) ||
1771 typeid(*selection) == typeid (FloatImageObj)))
1773 QString ps=qpointToString (selection->getRelPos());
1774 QString s=selection->getSelectString();
1777 s, "moveRel "+qpointToString (QPoint (x,y)),
1778 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps));
1779 ((OrnamentedObj*)selection)->move2RelPos (x,y);
1780 mapCenter->reposition();
1785 void MapEditor::moveBranchUp()
1789 if (typeid(*selection) == typeid(BranchObj) )
1791 bo=(BranchObj*)selection;
1792 if (!bo->canMoveBranchUp()) return;
1793 par=(BranchObj*)(bo->getParObj());
1794 selection->unselect();
1795 bo=par->moveBranchUp (bo); // bo will be the one below selection
1796 selection->select();
1797 saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1798 mapCenter->reposition();
1799 ensureSelectionVisible();
1803 void MapEditor::moveBranchDown()
1807 if (typeid(*selection) == typeid(BranchObj) )
1809 bo=(BranchObj*)selection;
1810 if (!bo->canMoveBranchDown()) return;
1811 par=(BranchObj*)(bo->getParObj());
1812 selection->unselect();
1813 bo=par->moveBranchDown(bo); // bo will be the one above selection
1814 selection->select();
1815 saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1816 mapCenter->reposition();
1817 ensureSelectionVisible();
1821 QString MapEditor::getHeading(bool &ok, QPoint &p)
1824 (typeid(*selection) == typeid(BranchObj) ||
1825 typeid(*selection) == typeid(MapCenterObj) ) )
1828 ensureSelectionVisible();
1829 p = ((BranchObj*)selection)->getAbsPos();
1830 p.setX (p.x() - contentsX());
1831 p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2);
1832 return ((BranchObj*)selection)->getHeading();
1838 void MapEditor::setHeading(const QString &s)
1841 (typeid(*selection) == typeid(BranchObj) ||
1842 typeid(*selection) == typeid(MapCenterObj) ) )
1844 editingBO=(BranchObj*)selection;
1847 "setHeading (\""+editingBO->getHeading()+"\")",
1849 "setHeading (\""+s+"\")",
1850 QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) );
1851 editingBO->setHeading(s );
1853 mapCenter->reposition();
1855 ensureSelectionVisible();
1859 void MapEditor::setURLInt (const QString &s)
1861 // Internal function, no saveState needed
1863 (typeid(*selection) == typeid(BranchObj) ||
1864 typeid(*selection) == typeid(MapCenterObj) ) )
1866 ((BranchObj*)selection)->setURL(s);
1867 mapCenter->reposition();
1869 ensureSelectionVisible();
1873 void MapEditor::setHeadingInt(const QString &s)
1876 (typeid(*selection) == typeid(BranchObj) ||
1877 typeid(*selection) == typeid(MapCenterObj) ) )
1879 ((BranchObj*)selection)->setHeading(s);
1880 mapCenter->reposition();
1882 ensureSelectionVisible();
1886 void MapEditor::setVymLinkInt (const QString &s)
1888 // Internal function, no saveState needed
1890 (typeid(*selection) == typeid(BranchObj) ||
1891 typeid(*selection) == typeid(MapCenterObj) ) )
1893 ((BranchObj*)selection)->setVymLink(s);
1894 mapCenter->reposition();
1896 ensureSelectionVisible();
1900 BranchObj* MapEditor::addNewBranchInt(int num)
1902 // Depending on pos:
1903 // -3 insert in childs of parent above selection
1904 // -2 add branch to selection
1905 // -1 insert in childs of parent below selection
1906 // 0..n insert in childs of parent at pos
1907 BranchObj *newbo=NULL;
1909 (typeid(*selection) == typeid(BranchObj) ||
1910 typeid(*selection) == typeid(MapCenterObj) ) )
1912 BranchObj* bo = (BranchObj*) selection;
1915 // save scroll state. If scrolled, automatically select
1916 // new branch in order to tmp unscroll parent...
1917 return bo->addBranch();
1922 bo=(BranchObj*)bo->getParObj();
1926 bo=(BranchObj*)bo->getParObj();
1929 newbo=bo->insertBranch(num);
1934 BranchObj* MapEditor::addNewBranch(int pos)
1936 // Different meaning than num in addNewBranchInt!
1940 BranchObj *bo = (BranchObj*) selection;
1941 BranchObj *newbo=NULL;
1944 (typeid(*selection) == typeid(BranchObj) ||
1945 typeid(*selection) == typeid(MapCenterObj) ) )
1947 newbo=addNewBranchInt (pos-2);
1952 selection, // FIXME sholdnt newbo be deleted here???
1955 QString ("addBranch (%1)").arg(pos-2),
1956 QString ("Add new branch to %1").arg(getName(bo)));
1958 mapCenter->reposition();
1966 BranchObj* MapEditor::addNewBranchBefore()
1968 BranchObj *newbo=NULL;
1970 (typeid(*selection) == typeid(BranchObj) ) )
1971 // We accept no MapCenterObj here, so we _have_ a parent
1973 BranchObj* bo = (BranchObj*) selection;
1974 QPoint p=bo->getRelPos();
1977 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1979 // add below selection
1980 newbo=parbo->insertBranch(bo->getNum()+1);
1983 newbo->move2RelPos (p);
1985 // Move selection to new branch
1986 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1988 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
1989 QString ("Add branch before %1").arg(getName(bo)));
1991 mapCenter->reposition();
1998 void MapEditor::deleteSelection()
2000 if (selection && typeid(*selection) ==typeid(BranchObj) )
2002 BranchObj* bo=(BranchObj*)selection;
2003 BranchObj* par=(BranchObj*)(bo->getParObj());
2005 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2007 par->removeBranch(bo);
2009 selection->select();
2010 ensureSelectionVisible();
2011 mapCenter->reposition();
2014 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
2016 FloatImageObj* fio=(FloatImageObj*)selection;
2017 BranchObj* par=(BranchObj*)(fio->getParObj());
2018 saveStateChangingPart(
2022 QString("Delete %1").arg(getName(fio))
2026 par->removeFloatImage(fio);
2028 selection->select();
2029 ensureSelectionVisible();
2030 mapCenter->reposition();
2035 LinkableMapObj* MapEditor::getSelection()
2040 void MapEditor::unselect()
2044 selectionLast=selection;
2045 selection->unselect();
2050 void MapEditor::reselect()
2054 selection=selectionLast;
2055 selection->select();
2060 bool MapEditor::select (const QString &s)
2062 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2064 // Finally select the found object
2067 if (selection) unselect();
2069 selection->select();
2071 ensureSelectionVisible();
2077 QString MapEditor::getSelectString()
2079 if (selection) return selection->getSelectString();
2083 void MapEditor::selectInt (LinkableMapObj *lmo)
2085 if (lmo && selection != lmo)
2087 // select the MapObj
2088 if (selection) selection->unselect();
2090 selection->select();
2096 void MapEditor::selectNextBranchInt()
2098 // Increase number of branch
2101 QString s=selection->getSelectString();
2107 part=s.section(",",-1);
2109 num=part.right(part.length() - 3);
2111 s=s.left (s.length() -num.length());
2114 num=QString ("%1").arg(num.toUInt()+1);
2118 // Try to select this one
2119 if (select (s)) return;
2121 // We have no direct successor,
2122 // try to increase the parental number in order to
2123 // find a successor with same depth
2125 int d=selection->getDepth();
2130 while (!found && d>0)
2132 s=s.section (",",0,d-1);
2133 // replace substring of current depth in s with "1"
2134 part=s.section(",",-1);
2136 num=part.right(part.length() - 3);
2140 // increase number of parent
2141 num=QString ("%1").arg(num.toUInt()+1);
2142 s=s.section (",",0,d-2) + ","+ typ+num;
2145 // Special case, look at orientation
2146 if (selection->getOrientation()==OrientRightOfCenter)
2147 num=QString ("%1").arg(num.toUInt()+1);
2149 num=QString ("%1").arg(num.toUInt()-1);
2154 // pad to oldDepth, select the first branch for each depth
2155 for (i=d;i<oldDepth;i++)
2160 if ( ((BranchObj*)selection)->countBranches()>0)
2168 // try to select the freshly built string
2176 void MapEditor::selectPrevBranchInt()
2178 // Decrease number of branch
2181 QString s=selection->getSelectString();
2187 part=s.section(",",-1);
2189 num=part.right(part.length() - 3);
2191 s=s.left (s.length() -num.length());
2194 num=QString ("%1").arg(num.toUInt()-1);
2198 // Try to select this one
2199 if (select (s)) return;
2201 // We have no direct precessor,
2202 // try to decrease the parental number in order to
2203 // find a precessor with same depth
2205 int d=selection->getDepth();
2210 while (!found && d>0)
2212 s=s.section (",",0,d-1);
2213 // replace substring of current depth in s with "1"
2214 part=s.section(",",-1);
2216 num=part.right(part.length() - 3);
2220 // decrease number of parent
2221 num=QString ("%1").arg(num.toUInt()-1);
2222 s=s.section (",",0,d-2) + ","+ typ+num;
2225 // Special case, look at orientation
2226 if (selection->getOrientation()==OrientRightOfCenter)
2227 num=QString ("%1").arg(num.toUInt()-1);
2229 num=QString ("%1").arg(num.toUInt()+1);
2234 // pad to oldDepth, select the last branch for each depth
2235 for (i=d;i<oldDepth;i++)
2239 if ( ((BranchObj*)selection)->countBranches()>0)
2240 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
2247 // try to select the freshly built string
2255 void MapEditor::selectUpperBranch()
2259 if (typeid(*selection) == typeid(BranchObj))
2261 if (selection->getOrientation()==OrientRightOfCenter)
2262 selectPrevBranchInt();
2264 if (selection->getDepth()==1)
2265 selectNextBranchInt();
2267 selectPrevBranchInt();
2272 void MapEditor::selectLowerBranch()
2276 if (typeid(*selection) == typeid(BranchObj))
2278 if (selection->getOrientation()==OrientRightOfCenter)
2279 selectNextBranchInt();
2281 if (selection->getDepth()==1)
2282 selectPrevBranchInt();
2284 selectNextBranchInt();
2290 void MapEditor::selectLeftBranch()
2296 if (typeid(*selection) == typeid(MapCenterObj))
2298 par= (BranchObj*) selection;
2299 bo=par->getLastSelectedBranch();
2302 // Workaround for reselecting on left and right side
2303 if (bo->getOrientation()==OrientRightOfCenter)
2305 bo=par->getLastBranch();
2311 selection->select();
2313 ensureSelectionVisible();
2318 par=(BranchObj*)(selection->getParObj());
2319 if (selection->getOrientation()==OrientRightOfCenter)
2321 if (typeid(*selection) == typeid(BranchObj) ||
2322 typeid(*selection) == typeid(FloatImageObj))
2324 selection->unselect();
2326 selection->select();
2328 ensureSelectionVisible();
2332 if (typeid(*selection) == typeid(BranchObj) )
2334 bo=((BranchObj*)selection)->getLastSelectedBranch();
2337 selection->unselect();
2339 selection->select();
2341 ensureSelectionVisible();
2349 void MapEditor::selectRightBranch()
2356 if (typeid(*selection) == typeid(MapCenterObj))
2358 par= (BranchObj*) selection;
2359 bo=par->getLastSelectedBranch();
2362 // Workaround for reselecting on left and right side
2363 if (bo->getOrientation()==OrientLeftOfCenter)
2364 bo=par->getFirstBranch();
2369 selection->select();
2370 ensureSelectionVisible();
2375 par=(BranchObj*)(selection->getParObj());
2376 if (selection->getOrientation()==OrientLeftOfCenter)
2378 if (typeid(*selection) == typeid(BranchObj) ||
2379 typeid(*selection) == typeid(FloatImageObj))
2381 selection->unselect();
2383 selection->select();
2385 ensureSelectionVisible();
2389 if (typeid(*selection) == typeid(BranchObj) )
2391 bo=((BranchObj*)selection)->getLastSelectedBranch();
2394 selection->unselect();
2396 selection->select();
2398 ensureSelectionVisible();
2406 void MapEditor::selectFirstBranch()
2412 if (typeid(*selection) == typeid(BranchObj))
2414 bo1= (BranchObj*) selection;
2415 par=(BranchObj*)(bo1->getParObj());
2416 bo2=par->getFirstBranch();
2420 selection->select();
2421 ensureSelectionVisible();
2428 void MapEditor::selectLastBranch()
2434 if (typeid(*selection) == typeid(BranchObj))
2436 bo1= (BranchObj*) selection;
2437 par=(BranchObj*)(bo1->getParObj());
2438 bo2=par->getLastBranch();
2442 selection->select();
2443 ensureSelectionVisible();
2450 void MapEditor::selectMapBackgroundColor()
2452 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2453 if ( !col.isValid() ) return;
2454 setBackgroundColor( col );
2458 void MapEditor::setMapBackgroundColor(QColor col)
2460 QColor oldcol=mapCanvas->backgroundColor();
2463 QString ("setMapBackgroundColor (%1)").arg(oldcol.name()),
2465 QString ("setMapBackgroundColor (%1)").arg(col.name()),
2466 QString("Set background color of map to %1").arg(col.name()));
2467 mapCanvas->setBackgroundColor (col);
2470 QColor MapEditor::getMapBackgroundColor()
2472 return mapCanvas->backgroundColor();
2475 QColor MapEditor::getCurrentHeadingColor()
2479 if (typeid(*selection) == typeid(BranchObj) ||
2480 typeid(*selection) == typeid(MapCenterObj))
2482 BranchObj *bo=(BranchObj*)selection;
2483 return bo->getColor();
2487 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
2491 void MapEditor::colorItem(QColor c)
2495 if (typeid(*selection) == typeid(BranchObj) ||
2496 typeid(*selection) == typeid(MapCenterObj))
2498 BranchObj *bo=(BranchObj*)selection;
2501 QString ("colorItem (%1)").arg(bo->getColor().name()),
2503 QString ("colorItem (%1)").arg(c.name()),
2504 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
2506 bo->setColor(c); // color branch
2511 void MapEditor::colorBranch(QColor c)
2515 if (typeid(*selection) == typeid(BranchObj) ||
2516 typeid(*selection) == typeid(MapCenterObj))
2518 BranchObj *bo=(BranchObj*)selection;
2519 saveStateChangingPart(
2522 QString ("colorBranch (%1)").arg(c.name()),
2523 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
2525 bo->setColorChilds(c); // color links, color childs
2531 void MapEditor::toggleStandardFlag(QString f)
2535 if (typeid(*selection) == typeid(BranchObj) ||
2536 typeid(*selection) == typeid(MapCenterObj))
2538 BranchObj *bo=(BranchObj*)selection;
2540 if (bo->isSetStandardFlag(f))
2552 QString("%1 (\"%2\")").arg(u).arg(f),
2554 QString("%1 (\"%2\")").arg(r).arg(f),
2555 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2556 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
2562 void MapEditor::setViewCenter()
2564 // transform to CanvasView Coord:
2565 QPoint p=worldMatrix().map(movingCenter);
2566 center ( p.x(), p.y());
2570 BranchObj* MapEditor::findText (QString s, bool cs)
2572 QTextDocument::FindFlags flags=0;
2573 if (cs) flags=QTextDocument::FindCaseSensitively;
2576 { // Nothing found or new find process
2578 // nothing found, start again
2580 itFind=mapCenter->first();
2582 bool searching=true;
2583 bool foundNote=false;
2584 while (searching && !EOFind)
2588 // Searching in Note
2589 if (itFind->getNote().contains(s,cs))
2591 if (selection!=itFind)
2593 if (selection) ((BranchObj*)selection)->unselect();
2595 selection->select();
2597 ensureSelectionVisible();
2599 if (textEditor->findText(s,flags))
2605 // Searching in Heading
2606 if (searching && itFind->getHeading().contains (s,cs) )
2608 if (selection) ((BranchObj*)selection)->unselect();
2610 selection->select();
2612 ensureSelectionVisible();
2618 itFind=itFind->next();
2619 if (!itFind) EOFind=true;
2625 return (BranchObj*)selection;
2630 void MapEditor::findReset()
2631 { // Necessary if text to find changes during a find process
2635 void MapEditor::setURL(const QString &url)
2637 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2638 typeid(*selection) == typeid(MapCenterObj)) )
2640 BranchObj *bo=(BranchObj*)selection;
2641 QString oldurl=bo->getURL();
2645 QString ("setURL (\"%1\")").arg(oldurl),
2647 QString ("setURL (\"%1\")").arg(url),
2648 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
2654 void MapEditor::editURL()
2656 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2657 typeid(*selection) == typeid(MapCenterObj)) )
2660 BranchObj *bo=(BranchObj*)selection;
2661 QString text = QInputDialog::getText(
2662 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2663 bo->getURL(), &ok, this );
2665 // user entered something and pressed OK
2670 QString MapEditor::getURL()
2672 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2673 typeid(*selection) == typeid(MapCenterObj)) )
2674 return ((BranchObj*)selection)->getURL();
2679 QStringList MapEditor::getURLs()
2682 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2683 typeid(*selection) == typeid(MapCenterObj)) )
2685 BranchObj *bo=(BranchObj*)selection;
2689 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2697 void MapEditor::editHeading2URL()
2699 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2700 typeid(*selection) == typeid(MapCenterObj)) )
2701 setURL (((BranchObj*)selection)->getHeading());
2704 void MapEditor::editBugzilla2URL()
2706 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2707 typeid(*selection) == typeid(MapCenterObj)) )
2709 BranchObj *bo=(BranchObj*)selection;
2710 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2715 void MapEditor::editFATE2URL()
2717 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2718 typeid(*selection) == typeid(MapCenterObj)) )
2720 BranchObj *bo=(BranchObj*)selection;
2721 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2724 "setURL (\""+bo->getURL()+"\")",
2726 "setURL (\""+url+"\")",
2727 QString("Use heading of %1 as link to FATE").arg(getName(bo))
2734 void MapEditor::editVymLink()
2736 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2737 typeid(*selection) == typeid(MapCenterObj)) )
2739 BranchObj *bo=(BranchObj*)selection;
2740 QStringList filters;
2741 filters <<"VYM map (*.vym)";
2742 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
2743 fd->setFilters (filters);
2744 fd->setCaption(vymName+" - " +tr("Link to another map"));
2745 if (! bo->getVymLink().isEmpty() )
2746 fd->selectFile( bo->getVymLink() );
2750 if ( fd->exec() == QDialog::Accepted )
2754 "setVymLink (\""+bo->getVymLink()+"\")",
2756 "setVymLink (\""+fd->selectedFile()+"\")",
2757 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
2759 bo->setVymLink (fd->selectedFile() );
2761 mapCenter->reposition();
2768 void MapEditor::deleteVymLink()
2770 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2771 typeid(*selection) == typeid(MapCenterObj)) )
2773 BranchObj *bo=(BranchObj*)selection;
2776 "setVymLink (\""+bo->getVymLink()+"\")",
2778 "setVymLink (\"\")",
2779 QString("Unset vymlink of %1").arg(getName(bo))
2781 bo->setVymLink ("" );
2783 mapCenter->reposition();
2789 void MapEditor::setHideExport(bool b)
2791 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2792 typeid(*selection)==typeid(FloatImageObj)))
2794 OrnamentedObj *oo=(OrnamentedObj*)selection;
2795 oo->setHideInExport (b);
2796 QString u= b ? "false" : "true";
2797 QString r=!b ? "false" : "true";
2801 QString ("setHideExport (%1)").arg(u),
2803 QString ("setHideExport (%1)").arg(r),
2804 QString ("Set HideExport flag of %1 to %2").arg(getName(oo)).arg (r)
2807 mapCenter->reposition();
2813 void MapEditor::toggleHideExport()
2815 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2816 typeid(*selection)==typeid(FloatImageObj)))
2817 setHideExport ( !((OrnamentedObj*)selection)->hideInExport() );
2820 QString MapEditor::getVymLink()
2822 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2823 typeid(*selection) == typeid(MapCenterObj)) )
2825 return ((BranchObj*)selection)->getVymLink();
2831 QStringList MapEditor::getVymLinks()
2834 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2835 typeid(*selection) == typeid(MapCenterObj)) )
2837 BranchObj *bo=(BranchObj*)selection;
2841 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2849 void MapEditor::deleteKeepChilds()
2851 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2853 BranchObj* bo=(BranchObj*)selection;
2854 BranchObj* par=(BranchObj*)(bo->getParObj());
2855 QPoint p=bo->getRelPos();
2856 saveStateChangingPart(
2857 selection->getParObj(),
2859 "deleteKeepChilds ()",
2860 QString("Remove %1 and keep its childs").arg(getName(bo))
2863 QString sel=selection->getSelectString();
2865 par->removeBranchHere(bo);
2866 mapCenter->reposition();
2868 ((BranchObj*)selection)->move2RelPos (p);
2869 mapCenter->reposition();
2874 void MapEditor::deleteChilds()
2876 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2877 typeid(*selection)==typeid(MapCenterObj)))
2879 saveStateChangingPart(
2880 selection->getParObj(),
2883 QString( "Remove childs of branch %1").arg(getName(selection))
2885 ((BranchObj*)selection)->removeChilds();
2886 mapCenter->reposition();
2890 void MapEditor::editMapInfo()
2892 ExtraInfoDialog dia;
2893 dia.setMapName (getFileName() );
2894 dia.setAuthor (mapCenter->getAuthor() );
2895 dia.setComment(mapCenter->getComment() );
2900 Q3CanvasItemList l=canvas()->allItems();
2901 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2903 stats+=QString ("%1 items on canvas\n").arg (i,6);
2910 bo=mapCenter->first();
2913 if (!bo->getNote().isEmpty() ) n++;
2914 f+= bo->countFloatImages();
2916 xl+=bo->countXLinks();
2919 stats+=QString ("%1 branches\n").arg (b-1,6);
2920 stats+=QString ("%1 xLinks \n").arg (xl,6);
2921 stats+=QString ("%1 notes\n").arg (n,6);
2922 stats+=QString ("%1 images\n").arg (f,6);
2923 dia.setStats (stats);
2925 // Finally show dialog
2926 if (dia.exec() == QDialog::Accepted)
2928 setMapAuthor (dia.getAuthor() );
2929 setMapComment (dia.getComment() );
2933 void MapEditor::updateActions()
2935 mainWindow->updateActions();
2936 // FIXME maybe don't update if blockReposition is set
2939 void MapEditor::updateNoteFlag()
2942 if ( (typeid(*selection) == typeid(BranchObj)) ||
2943 (typeid(*selection) == typeid(MapCenterObj)) )
2944 ((BranchObj*)selection)->updateNoteFlag();
2947 void MapEditor::setMapAuthor (const QString &s)
2951 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
2953 QString ("setMapAuthor (\"%1\")").arg(s),
2954 QString ("Set author of map to \"%1\"").arg(s)
2956 mapCenter->setAuthor (s);
2959 void MapEditor::setMapComment (const QString &s)
2963 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
2965 QString ("setMapComment (\"%1\")").arg(s),
2966 QString ("Set comment of map")
2968 mapCenter->setComment (s);
2971 void MapEditor::setMapLinkStyle (const QString & s)
2973 saveStateChangingPart (
2976 QString("setMapLinkStyle (\"%1\")").arg(s),
2977 QString("Set map link style (\"%1\")").arg(s)
2981 linkstyle=StyleLine;
2982 else if (s=="StyleParabel")
2983 linkstyle=StyleParabel;
2984 else if (s=="StylePolyLine")
2985 linkstyle=StylePolyLine;
2987 linkstyle=StylePolyParabel;
2990 bo=mapCenter->first();
2994 bo->setLinkStyle(bo->getDefLinkStyle());
2997 mapCenter->reposition();
3000 LinkStyle MapEditor::getMapLinkStyle ()
3005 void MapEditor::setMapDefLinkColor(QColor c)
3011 void MapEditor::setMapLinkColorHintInt()
3013 // called from setMapLinkColorHint(lch) or at end of parse
3015 bo=mapCenter->first();
3023 void MapEditor::setMapLinkColorHint(LinkColorHint lch)
3026 setMapLinkColorHintInt();
3029 void MapEditor::toggleMapLinkColorHint()
3031 if (linkcolorhint==HeadingColor)
3032 linkcolorhint=DefaultColor;
3034 linkcolorhint=HeadingColor;
3036 bo=mapCenter->first();
3044 LinkColorHint MapEditor::getMapLinkColorHint()
3046 return linkcolorhint;
3049 QColor MapEditor::getMapDefLinkColor()
3051 return defLinkColor;
3054 void MapEditor::setMapDefXLinkColor(QColor col)
3059 QColor MapEditor::getMapDefXLinkColor()
3061 return defXLinkColor;
3064 void MapEditor::setMapDefXLinkWidth (int w)
3069 int MapEditor::getMapDefXLinkWidth()
3071 return defXLinkWidth;
3074 void MapEditor::selectMapLinkColor()
3076 QColor col = QColorDialog::getColor( defLinkColor, this );
3077 if ( !col.isValid() ) return;
3080 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3082 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3083 QString("Set link color to %1").arg(col.name())
3085 setMapDefLinkColor( col );
3089 void MapEditor::toggleScroll()
3091 if (selection && (typeid(*selection) == typeid(BranchObj)) )
3093 BranchObj *bo=((BranchObj*)selection);
3094 if (bo->countBranches()==0) return;
3095 if (bo->getDepth()==0) return;
3097 if (bo->isScrolled())
3109 QString ("%1 ()").arg(u),
3111 QString ("%1 ()").arg(r),
3112 QString ("%1 %2").arg(r).arg(getName(bo))
3120 void MapEditor::unScrollAll()
3123 bo=mapCenter->first();
3126 if (bo->isScrolled()) bo->toggleScroll();
3131 void MapEditor::loadFloatImage ()
3134 (typeid(*selection) == typeid(BranchObj)) ||
3135 (typeid(*selection) == typeid(MapCenterObj)) )
3137 BranchObj *bo=((BranchObj*)selection);
3139 Q3FileDialog *fd=new Q3FileDialog( this);
3140 fd->setMode (Q3FileDialog::ExistingFiles);
3141 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3142 ImagePreview *p =new ImagePreview (fd);
3143 fd->setContentsPreviewEnabled( TRUE );
3144 fd->setContentsPreview( p, p );
3145 fd->setPreviewMode( Q3FileDialog::Contents );
3146 fd->setCaption(vymName+" - " +tr("Load image"));
3147 fd->setDir (lastImageDir);
3151 if ( fd->exec() == QDialog::Accepted )
3153 // FIXME in QT4 use: lastImageDir=fd->directory();
3154 lastImageDir=QDir (fd->dirPath());
3155 QStringList flist = fd->selectedFiles();
3156 QStringList::Iterator it = flist.begin();
3158 while( it != flist.end() )
3161 bo->addFloatImage();
3162 fio=bo->getLastFloatImage();
3164 // FIXME check if load of fio was successful
3166 (LinkableMapObj*)fio,
3169 QString ("loadFloatImage (%1)").arg(*it),
3170 QString("Add floatimage %1 to %2").arg(*it).arg(getName(selection))
3172 bo->getLastFloatImage()->setOriginalFilename(fn);
3176 mapCenter->reposition();
3185 void MapEditor::saveFloatImage ()
3188 (typeid(*selection) == typeid(FloatImageObj)) )
3190 FloatImageObj *fio=((FloatImageObj*)selection);
3191 QFileDialog *fd=new QFileDialog( this);
3192 fd->setFilters (imageIO.getFilters());
3193 fd->setCaption(vymName+" - " +tr("Save image"));
3194 fd->setFileMode( QFileDialog::AnyFile );
3195 fd->setDirectory (lastImageDir);
3196 // fd->setSelection (fio->getOriginalFilename());
3200 if ( fd->exec() == QDialog::Accepted )
3202 if (QFile (fd->selectedFile()).exists() )
3204 QMessageBox mb( vymName,
3205 tr("The file %1 exists already.\n"
3206 "Do you want to overwrite it?").arg(fd->selectedFile()),
3207 QMessageBox::Warning,
3208 QMessageBox::Yes | QMessageBox::Default,
3209 QMessageBox::Cancel | QMessageBox::Escape,
3210 QMessageBox::QMessageBox::NoButton );
3212 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3213 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3216 case QMessageBox::Yes:
3219 case QMessageBox::Cancel:
3226 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
3232 void MapEditor::setFrame(const FrameType &t)
3235 (typeid(*selection) == typeid(BranchObj)) ||
3236 (typeid(*selection) == typeid(MapCenterObj)) )
3238 selection->setFrameType (t);
3239 mapCenter->reposition();
3240 selection->updateLink();
3244 void MapEditor::setIncludeImagesVer(bool b)
3247 (typeid(*selection) == typeid(BranchObj)) ||
3248 (typeid(*selection) == typeid(MapCenterObj)) )
3249 ((BranchObj*)selection)->setIncludeImagesVer(b);
3250 mapCenter->reposition();
3253 void MapEditor::setIncludeImagesHor(bool b)
3256 (typeid(*selection) == typeid(BranchObj)) ||
3257 (typeid(*selection) == typeid(MapCenterObj)) )
3258 ((BranchObj*)selection)->setIncludeImagesHor(b);
3259 mapCenter->reposition();
3262 void MapEditor::setHideLinkUnselected (bool b)
3265 (typeid(*selection) == typeid(BranchObj)) ||
3266 (typeid(*selection) == typeid(MapCenterObj)) ||
3267 (typeid(*selection) == typeid(FloatImageObj)) )
3268 selection->setHideLinkUnselected(b);
3271 void MapEditor::importDirInt(BranchObj *dst, QDir d)
3274 (typeid(*selection) == typeid(BranchObj)) ||
3275 (typeid(*selection) == typeid(MapCenterObj)) )
3279 // Traverse directories
3280 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3281 QFileInfoList list = d.entryInfoList();
3284 for (int i = 0; i < list.size(); ++i)
3287 if (fi.fileName() != "." && fi.fileName() != ".." )
3290 bo=dst->getLastBranch();
3291 bo->setHeading (fi.fileName() );
3292 bo->setColor (QColor("blue"));
3294 if ( !d.cd(fi.fileName()) )
3295 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3298 // Recursively add subdirs
3299 importDirInt (bo,d);
3305 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3306 list = d.entryInfoList();
3308 for (int i = 0; i < list.size(); ++i)
3312 bo=dst->getLastBranch();
3313 bo->setHeading (fi.fileName() );
3314 bo->setColor (QColor("black"));
3315 if (fi.fileName().right(4) == ".vym" )
3316 bo->setVymLink (fi.filePath());
3321 void MapEditor::importDir()
3324 (typeid(*selection) == typeid(BranchObj)) ||
3325 (typeid(*selection) == typeid(MapCenterObj)) )
3327 QStringList filters;
3328 filters <<"VYM map (*.vym)";
3329 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
3330 fd->setMode (QFileDialog::DirectoryOnly);
3331 fd->setFilters (filters);
3332 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
3336 if ( fd->exec() == QDialog::Accepted )
3338 BranchObj *bo=((BranchObj*)selection);
3339 importDirInt (bo,QDir(fd->selectedFile()) );
3340 mapCenter->reposition();
3347 void MapEditor::followXLink(int i)
3350 (typeid(*selection) == typeid(BranchObj)) ||
3351 (typeid(*selection) == typeid(MapCenterObj)) )
3353 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3356 selection->unselect();
3358 selection->select();
3359 ensureSelectionVisible();
3364 void MapEditor::editXLink(int i)
3367 (typeid(*selection) == typeid(BranchObj)) ||
3368 (typeid(*selection) == typeid(MapCenterObj)) )
3370 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3373 EditXLinkDialog dia;
3375 dia.setSelection(selection);
3376 if (dia.exec() == QDialog::Accepted)
3378 if (dia.useSettingsGlobal() )
3380 setMapDefXLinkColor (xlo->getColor() );
3381 setMapDefXLinkWidth (xlo->getWidth() );
3383 if (dia.deleteXLink())
3384 ((BranchObj*)selection)->deleteXLinkAt(i);
3385 //saveStateComplete("Edit xLink"); //FIXME undoCommand
3391 void MapEditor::testFunction()
3393 cout << "MapEditor::testFunction() called\n";
3396 (typeid(*selection) == typeid(BranchObj)) ||
3397 (typeid(*selection) == typeid(MapCenterObj)) )
3399 BranchObj* bo=(BranchObj*)selection;
3400 cout << bo->getHeading().ascii() <<" is scrolled: "<<bo->isScrolled()<<endl;
3405 dia.showCancelButton (true);
3406 dia.setText("This is a longer \nWarning");
3408 dia.setCaption("Warning: Flux problem");
3409 dia.setShowAgainName("/warnings/mapeditor");
3411 if (dia.exec()==QDialog::Accepted)
3412 cout << "accepted!\n";
3414 cout << "canceled!\n";
3417 /* Hide hidden stuff temporary, maybe add this as regular function somewhere
3418 if (hidemode==HideNone)
3420 setHideTmpMode (HideExport);
3421 mapCenter->calcBBoxSizeWithChilds();
3422 QRect totalBBox=mapCenter->getTotalBBox();
3423 QRect mapRect=totalBBox;
3424 QCanvasRectangle *frame=NULL;
3426 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3428 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3429 totalBBox.width(), totalBBox.height());
3430 frame=new QCanvasRectangle (mapRect,mapCanvas);
3431 frame->setBrush (QColor(white));
3432 frame->setPen (QColor(black));
3438 setHideTmpMode (HideNone);
3440 cout <<" hidemode="<<hidemode<<endl;
3444 void MapEditor::ensureSelectionVisible()
3448 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3450 if (selection->getOrientation() == OrientLeftOfCenter)
3451 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3453 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3454 ensureVisible (p.x(), p.y() );
3459 void MapEditor::updateViewCenter()
3461 // Update movingCenter, so that we can zoom comfortably later
3462 QRect rc = QRect( contentsX(), contentsY(),
3463 visibleWidth(), visibleHeight() );
3464 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3465 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3466 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3469 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3471 // Lineedits are already closed by preceding
3472 // mouseEvent, we don't need to close here.
3474 QPoint p = inverseWorldMatrix().map(e->pos());
3475 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3478 { // MapObj was found
3479 if (selection != lmo)
3481 // select the MapObj
3482 if (selection) selection->unselect();
3484 selection->select();
3490 if (typeid(*selection)==typeid(BranchObj) ||
3491 typeid(*selection)==typeid(MapCenterObj) )
3493 // Context Menu on branch or mapcenter
3495 branchContextMenu->popup(e->globalPos() );
3497 if (typeid(*selection)==typeid(FloatImageObj))
3499 // Context Menu on floatimage
3501 floatimageContextMenu->popup(e->globalPos() );
3505 { // No MapObj found, we are on the Canvas itself
3506 // Context Menu on Canvas
3508 canvasContextMenu->popup(e->globalPos() );
3513 void MapEditor::keyPressEvent(QKeyEvent* e)
3515 if (e->modifiers() && Qt::ControlModifier)
3517 switch (mainWindow->getModMode())
3520 setCursor (PickColorCursor);
3523 setCursor (CopyCursor);
3526 setCursor (XLinkCursor);
3529 setCursor (Qt::ArrowCursor);
3535 void MapEditor::keyReleaseEvent(QKeyEvent* e)
3537 if (!(e->modifiers() && Qt::ControlModifier))
3538 setCursor (Qt::ArrowCursor);
3541 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3543 // Ignore right clicks, these will go to context menus
3544 if (e->button() == Qt::RightButton )
3550 QPoint p = inverseWorldMatrix().map(e->pos());
3551 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3555 //Take care of clickdesystem flags _or_ modifier modes
3557 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3558 typeid(*lmo)==typeid(MapCenterObj) ))
3560 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3561 if (!foname.isEmpty())
3563 // systemFlag clicked
3567 if (e->state() & Qt::ControlModifier)
3568 mainWindow->editOpenURLTab();
3570 mainWindow->editOpenURL();
3572 else if (foname=="vymLink")
3574 mainWindow->editOpenVymLink();
3575 // tabWidget may change, better return now
3576 // before segfaulting...
3577 } else if (foname=="note")
3578 mainWindow->windowToggleNoteEditor();
3579 else if (foname=="hideInExport")
3584 // No system flag clicked, take care of modmodes
3586 // Special case: CTRL is pressed
3587 if (e->state() & Qt::ControlModifier)
3589 if (mainWindow->getModMode()==ModModeColor)
3592 setCursor (PickColorCursor);
3595 if (mainWindow->getModMode()==ModModeXLink)
3597 BranchObj *bo_begin=NULL;
3599 bo_begin=(BranchObj*)(lmo);
3602 ((typeid(*selection) == typeid(BranchObj)) ||
3603 (typeid(*selection) == typeid(MapCenterObj))) )
3604 bo_begin=(BranchObj*)selection;
3608 linkingObj_src=bo_begin;
3609 tmpXLink=new XLinkObj (mapCanvas);
3610 tmpXLink->setBegin (bo_begin);
3611 tmpXLink->setEnd (p);
3612 tmpXLink->setColor(defXLinkColor);
3613 tmpXLink->setWidth(defXLinkWidth);
3614 tmpXLink->updateXLink();
3615 tmpXLink->setVisibility (true);
3623 // Left Button Move Branches
3624 if (e->button() == Qt::LeftButton )
3626 movingObj_start.setX( p.x() - selection->x() );
3627 movingObj_start.setY( p.y() - selection->y() );
3628 movingObj_orgPos.setX (lmo->x() );
3629 movingObj_orgPos.setY (lmo->y() );
3630 movingObj_orgRelPos=lmo->getRelPos();
3632 // If modMode==copy, then we want to "move" the _new_ object around
3633 // then we need the offset from p to the _old_ selection, because of tmp
3634 if (mainWindow->getModMode()==ModModeCopy &&
3635 e->state() & Qt::ControlModifier)
3637 if (typeid(*selection)==typeid(BranchObj) )
3640 mapCenter->addBranch ((BranchObj*)selection);
3642 selection=mapCenter->getLastBranch();
3643 selection->select();
3644 mapCenter->reposition();
3647 movingObj=selection;
3649 // Middle Button Toggle Scroll
3650 // (On Mac OS X this won't work, but we still have
3651 // a button in the toolbar)
3652 if (e->button() == Qt::MidButton )
3656 { // No MapObj found, we are on the Canvas itself
3657 // Left Button move Pos of CanvasView
3658 if (e->button() == Qt::LeftButton )
3660 movingObj=NULL; // move Content not Obj
3661 movingObj_start=e->globalPos();
3662 movingCont_start=QPoint (contentsX(), contentsY() );
3663 movingVec=QPoint(0,0);
3664 setCursor(HandOpenCursor);
3669 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3671 QPoint p = inverseWorldMatrix().map(e->pos());
3673 // Move the selected MapObj
3674 if ( selection && movingObj)
3676 // To avoid jumping of the CanvasView, only
3677 // ensureSelectionVisible, if not tmp linked
3678 if (!selection->hasParObjTmp())
3679 ensureSelectionVisible ();
3681 // Now move the selection, but add relative position
3682 // (movingObj_start) where selection was chosen with
3683 // mousepointer. (This avoids flickering resp. jumping
3684 // of selection back to absPos)
3686 LinkableMapObj *lmosel;
3687 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3689 // Check if we could link
3690 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3693 if (typeid(*selection) == typeid(FloatImageObj))
3695 FloatObj *fo=(FloatObj*)selection;
3696 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3700 // Relink float to new mapcenter or branch, if shift is pressed
3701 // Only relink, if selection really has a new parent
3702 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
3703 ( (typeid(*lmo)==typeid(BranchObj)) ||
3704 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3705 ( lmo != fo->getParObj())
3708 if (typeid(*fo) == typeid(FloatImageObj))
3711 //saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3712 FloatImageObj *fio=(FloatImageObj*)(fo);
3713 ((BranchObj*)(lmo))->addFloatImage (fio);
3715 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3716 fio=((BranchObj*)(lmo))->getLastFloatImage();
3719 selection=(LinkableMapObj*)(fio);
3720 selection->select();
3721 movingObj=(MapObj*)(fio);
3725 { // selection != a FloatObj
3726 if (lmosel->getDepth()==0)
3729 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3730 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3732 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3733 mapCenter->updateRelPositions();
3736 if (lmosel->getDepth()==1)
3739 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3740 lmosel->setRelPos();
3743 // Move ordinary branch
3744 if (lmosel->getOrientation() == OrientLeftOfCenter)
3745 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3746 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3747 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3749 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3751 // reposition subbranch
3752 lmosel->reposition();
3754 if (lmo && (lmo!=selection) &&
3755 (typeid(*lmo) == typeid(BranchObj) ||
3756 (typeid(*lmo) == typeid(MapCenterObj) )
3759 if (e->modifiers()==Qt::ControlModifier)
3761 // Special case: CTRL to link below lmo
3762 lmosel->setParObjTmp (lmo,p,+1);
3764 else if (e->modifiers()==Qt::ShiftModifier)
3765 lmosel->setParObjTmp (lmo,p,-1);
3767 lmosel->setParObjTmp (lmo,p,0);
3770 lmosel->unsetParObjTmp();
3774 } // no FloatImageObj
3778 } // selection && moving_obj
3780 // Draw a link from one branch to another
3783 tmpXLink->setEnd (p);
3784 tmpXLink->updateXLink();
3788 if (!movingObj && !pickingColor &&!drawingLink)
3790 QPoint p=e->globalPos();
3791 movingVec.setX(-p.x() + movingObj_start.x() );
3792 movingVec.setY(-p.y() + movingObj_start.y() );
3793 setContentsPos( movingCont_start.x() + movingVec.x(),
3794 movingCont_start.y() + movingVec.y());
3801 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3803 LinkableMapObj *dst;
3804 // Have we been picking color?
3808 setCursor (Qt::ArrowCursor);
3809 // Check if we are over another branch
3810 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3811 if (dst && selection)
3813 if (e->state() & Qt::ShiftModifier)
3815 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3816 ((BranchObj*)selection)->setLinkColor ();
3820 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3821 ((BranchObj*)selection)->setLinkColor ();
3827 // Have we been drawing a link?
3831 // Check if we are over another branch
3832 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3833 if (dst && selection)
3835 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3836 tmpXLink->updateXLink();
3837 tmpXLink->activate();
3838 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //FIXME undoCommand
3847 // Have we been moving something?
3848 if ( selection && movingObj )
3850 if(typeid(*selection)==typeid (FloatImageObj))
3852 // Moved FloatObj. Maybe we need to reposition
3853 FloatImageObj *fo=(FloatImageObj*)selection;
3854 QString pold=qpointToString(movingObj_orgRelPos);
3855 QString pnow=qpointToString(fo->getRelPos());
3861 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow));
3863 // FIXME Why calling parObj here?
3864 selection->getParObj()->requestReposition();
3865 mapCenter->reposition();
3868 // Check if we are over another branch, but ignore
3869 // any found LMOs, which are FloatObjs
3870 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3871 ((LinkableMapObj*)selection) );
3873 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3876 if (typeid(*selection) == typeid(MapCenterObj) )
3877 { // The MapCenter was moved
3878 cout << "FIXME missing savestate...\n";
3881 if (typeid(*selection) == typeid(BranchObj) )
3882 { // A branch was moved
3884 // save the position in case we link to mapcenter
3885 QPoint savePos=QPoint (selection->x(),selection->y() );
3887 // Reset the temporary drawn link to the original one
3888 ((LinkableMapObj*)selection)->unsetParObjTmp();
3890 // For Redo we may need to save original selection
3891 QString preSelStr=selection->getSelectString();
3896 BranchObj* bsel=(BranchObj*)selection;
3897 BranchObj* bdst=(BranchObj*)dst;
3899 QString preParStr=(bsel->getParObj())->getSelectString();
3900 QString preNum=QString::number (bsel->getNum(),10);
3901 QString preDstParStr;
3903 if (e->state() & Qt::ShiftModifier && dst->getParObj())
3905 preDstParStr=dst->getParObj()->getSelectString();
3906 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
3908 if (e->state() & Qt::ControlModifier && dst->getParObj())
3911 preDstParStr=dst->getParObj()->getSelectString();
3912 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
3915 preDstParStr=dst->getSelectString();
3916 bsel->moveBranchTo (bdst,-1);
3917 if (dst->getDepth()==0) bsel->move (savePos);
3919 QString postSelStr=selection->getSelectString();
3920 QString postNum=QString::number (bsel->getNum(),10);
3922 QString undoCom="linkBranchToPos (\""+
3923 preParStr+ "\"," + preNum +"," +
3924 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
3926 QString redoCom="linkBranchToPos (\""+
3927 preDstParStr + "\"," + postNum + "," +
3928 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
3933 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
3935 if (selection->getDepth()==1)
3937 // The select string might be different _after_ moving around.
3938 // Therefor reposition and then use string of old selection, too
3939 mapCenter->reposition();
3941 QString ps=qpointToString ( ((BranchObj*)selection)->getRelPos() );
3943 selection->getSelectString(), "moveRel "+qpointToString(movingObj_orgRelPos),
3944 preSelStr, "moveRel "+ps,
3945 QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps));
3948 // Draw the original link, before selection was moved around
3949 mapCenter->reposition();
3951 // Finally resize canvas, if needed
3956 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
3959 // maybe we moved View: set old cursor
3960 setCursor (Qt::ArrowCursor);
3964 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3966 if (e->button() == Qt::LeftButton )
3968 QPoint p = inverseWorldMatrix().map(e->pos());
3969 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3970 if (lmo) { // MapObj was found
3971 // First select the MapObj than edit heading
3972 if (selection) selection->unselect();
3974 selection->select();
3975 mainWindow->editHeading();
3980 void MapEditor::resizeEvent (QResizeEvent* e)
3982 Q3CanvasView::resizeEvent( e );
3986 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3989 (typeid(*selection) == typeid(BranchObj)) ||
3990 (typeid(*selection) == typeid(MapCenterObj)))
3992 if (event->mimeData()->hasFormat("image/png"))
3994 cout <<"found png in dragenterevent\n";
3999 if (event->mimeData()->hasFormat("text/uri-list"))
4001 cout <<"found uri-list in dragenterevent\n";
4007 // If QImageDrag can decode mime type
4008 if (Q3ImageDrag::canDecode(event))
4010 cout << "dragenterevent q3imagedrag\n";
4015 // If image are dragged from firefox
4016 if (event->mimeData()->hasFormat("application/x-moz-file-promise-url") &&
4017 event->mimeData()->hasFormat("application/x-moz-nativeimage")) {
4018 event->accept(true);
4019 cout << "dragenterevent firefox\n";
4023 // If QUriDrag can decode mime type
4024 if (Q3UriDrag::canDecode(event)) {
4026 cout << "accepted uri drag\n";
4029 // If Uri are dragged from firefox
4030 if (event->provides("_NETSCAPE_URL")){
4032 cout << "dragenterevent NETSCAPE\n";
4036 // If QTextDrag can decode mime type
4037 if (Q3TextDrag::canDecode(event)) {
4039 cout << "dragenterevent textdrag\n";
4049 /* FIXME needed in QT4? bool isUnicode16(const QByteArray &d)
4051 // TODO: make more precise check for unicode 16.
4052 // Guess unicode16 if any of second bytes are zero
4053 unsigned int length = max(0,d.size()-2)/2;
4054 for (unsigned int i = 0; i<length ; i++)
4055 if (d.at(i*2+1)==0) return true;
4060 void MapEditor::contentsDropEvent(QDropEvent *event)
4063 (typeid(*selection) == typeid(BranchObj)) ||
4064 (typeid(*selection) == typeid(MapCenterObj)))
4072 if (event->mimeData()->hasFormat("image/png"))
4074 event->acceptProposedAction();
4075 addFloatImageInt(event->mimeData()->imageData().value<QPixmap>());
4076 cout << "Drop png...\n";
4077 } else if (event->mimeData()->hasFormat("application/x-moz-file-promise-url")&&
4078 event->mimeData()->hasFormat("application/x-moz-nativeimage"))
4080 cout << "Drop Mozilla...\n";
4081 // Contains url to the img src in unicode16
4082 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
4083 QString url = QString((const QChar*)d.data(),d.size()/2);
4085 event->acceptProposedAction();
4087 } else if (event->mimeData()->hasUrls())
4089 urls=event->mimeData()->urls();
4090 } /*else if (event->provides ("_NETSCAPE_URL"))
4091 { // Uris provided by Mozilla
4092 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
4095 } else if (event->provides("text/html")) {
4097 // Handels text mime types
4098 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
4099 QByteArray d = event->encodedData("text/html");
4102 text = QString((const QChar*)d.data(),d.size()/2);
4106 textEditor->setText(text);
4110 } else if (event->provides("text/plain")) {
4111 QByteArray d = event->encodedData("text/plain");
4114 text = QString((const QChar*)d.data(),d.size()/2);
4118 textEditor->setText(text);
4125 for (int i=0; i<urls.size(); ++i)
4127 cout << "Found URL: "<<urls.at(i).toString().ascii()<<endl;
4129 /* FIXME not ported yet QSTRINGLIST has no next...
4136 for (const char* u=uris.first(); u; u=uris.next())
4138 bo=((BranchObj*)selection)->addBranch();
4141 s=Q3UriDrag::uriToLocalFile(u);
4144 QString file = QDir::convertSeparators(s);
4145 heading = QFileInfo(file).baseName();
4147 if (file.endsWith(".vym", false))
4148 bo->setVymLink(file);
4157 if (!heading.isEmpty())
4158 bo->setHeading(heading);
4168 //FIXME saveState has to be called earlier for each of the drops...
4169 //saveStateComplete("Drop Event"); //TODO undo Command
4170 mapCenter->reposition();
4177 void MapEditor::addFloatImageInt (const QPixmap &img)
4180 (typeid(*selection) == typeid(BranchObj)) ||
4181 (typeid(*selection) == typeid(MapCenterObj)) )
4183 BranchObj *bo=((BranchObj*)selection);
4184 qWarning ("Warning: Image added by drop event: no undo/redo so far.");
4185 //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
4186 //QString fn=fd->selectedFile();
4187 //lastImageDir=fn.left(fn.findRev ("/"));
4188 FloatImageObj *fio=bo->addFloatImage();
4190 fio->setOriginalFilename("Image added by Drag and Drop");
4191 mapCenter->reposition();
4198 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
4200 if (!imageBuffer) imageBuffer = new QBuffer();
4201 if (!imageBuffer->isOpen()) {
4202 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
4204 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
4208 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
4210 if (nop->state()==Q3NetworkProtocol::StDone) {
4211 QPixmap img(imageBuffer->buffer());
4212 addFloatImageInt (img);
4216 imageBuffer->close();
4218 imageBuffer->close();
4225 void MapEditor::fetchImage(const QString &url)
4228 urlOperator->stop();
4229 disconnect(urlOperator);
4233 urlOperator = new Q3UrlOperator(url);
4234 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
4235 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
4237 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
4238 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));