Removed even more QT3 stuff. Drag & Drop not 100% functional at the moment
3 #include <q3filedialog.h>
12 #include "editxlinkdialog.h"
14 #include "extrainfodialog.h"
16 #include "linkablemapobj.h"
17 #include "mainwindow.h"
19 #include "texteditor.h"
20 #include "warningdialog.h"
24 extern TextEditor *textEditor;
25 extern int statusbarTime;
26 extern Main *mainWindow;
27 extern QString tmpVymDir;
28 extern QString clipboardDir;
29 extern bool clipboardEmpty;
30 extern FlagRowObj *standardFlagsDefault;
32 extern QMenu* branchContextMenu;
33 extern QMenu* branchAddContextMenu;
34 extern QMenu* branchRemoveContextMenu;
35 extern QMenu* branchLinksContextMenu;
36 extern QMenu* branchXLinksContextMenuEdit;
37 extern QMenu* branchXLinksContextMenuFollow;
38 extern QMenu* floatimageContextMenu;
39 extern QMenu* canvasContextMenu;
42 extern Settings settings;
43 extern ImageIO imageIO;
45 extern QString vymName;
46 extern QString vymVersion;
48 extern QString iconPath;
49 extern QDir vymBaseDir;
50 extern QDir lastImageDir;
52 int MapEditor::mapNum=0; // make instance
54 ///////////////////////////////////////////////////////////////////////
55 ///////////////////////////////////////////////////////////////////////
57 QWidget* parent, const char* name, Qt::WFlags f) :
58 Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
60 //cout << "Constructor ME "<<this<<endl;
63 viewport()->setAcceptDrops(true);
65 mapCanvas = new Q3Canvas(width(),height());
66 mapCanvas->setAdvancePeriod(30);
67 mapCanvas->setBackgroundColor (Qt::white);
69 setCanvas (mapCanvas);
71 // Always show scroll bars (automatic would flicker sometimes)
72 setVScrollBarMode ( Q3ScrollView::AlwaysOn );
73 setHScrollBarMode ( Q3ScrollView::AlwaysOn );
75 mapCenter = new MapCenterObj(mapCanvas);
76 mapCenter->setVisibility (true);
77 mapCenter->setMapEditor (this);
78 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
79 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
83 defLinkColor=QColor (0,0,255);
84 defXLinkColor=QColor (180,180,180);
85 linkcolorhint=DefaultColor;
86 linkstyle=StylePolyParabel;
88 // Create bitmap cursors, platform dependant
89 HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
90 PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
91 CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 );
92 XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 );
94 setFocusPolicy (Qt::StrongFocus);
105 xelection.setMapCenter (mapCenter);
108 defXLinkColor=QColor (230,230,230);
116 fileName=tr("unnamed");
119 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100);
120 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
122 // Initialize find routine
129 blockReposition=false;
130 blockSaveState=false;
134 // Create temporary files
137 // Initially set movingCentre
140 mapCenter->reposition(); // for positioning heading
144 MapEditor::~MapEditor()
146 if (imageBuffer) delete imageBuffer;
152 //cout <<"Destructor MapEditor\n";
155 MapCenterObj* MapEditor::getMapCenter()
160 Q3Canvas* MapEditor::getCanvas()
165 void MapEditor::adjustCanvasSize()
167 // To adjust the canvas to map, viewport size and position, we have to
168 // do some coordinate magic...
170 // Get rectangle of (scroll-)view.
171 // We want to be in canvas coords, so
172 // we map. Important if view is zoomed...
173 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
174 visibleWidth(), visibleHeight()) );
176 // Now we need the bounding box of view AND map to calc the correct canvas size.
177 // Why? Because if the map itself is moved out of view, the view has to be enlarged
178 // to avoid jumping aroung...
179 QRect map=mapCenter->getTotalBBox();
181 // right edge - left edge
182 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
183 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
186 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
187 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
190 // move the map on canvas (in order to not move it on screen) this is neccessary
191 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
192 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
193 // to scroll to an empty area of canvas to the left.
194 // b) if topleft corner of map left of or above topleft of canvas
198 if (cw > mapCanvas->width() )
200 if (map.x()<0) dx=-map.x();
202 if (cw < mapCanvas->width() )
203 dx=-min (view.x(),map.x());
204 if (ch > mapCanvas->height() )
206 if (map.y()<0) dy=-map.y();
208 if (ch < mapCanvas->height() )
210 dy=-min (view.y(),map.y());
212 // We really have to resize now. Let's go...
213 mapCanvas->resize (cw,ch);
214 if ( (dx!=0) || (dy!=0) )
216 mapCenter->moveAllBy(dx,dy);
217 mapCenter->reposition();
218 // mapCenter->positionBBox(); // To move float
220 // scroll the view (in order to not move map on screen)
226 bool MapEditor::isRepositionBlocked()
228 return blockReposition;
231 QString MapEditor::getName (LinkableMapObj *lmo)
234 if (!lmo) return QString("Error: NULL has no name!");
236 if ((typeid(*lmo) == typeid(BranchObj) ||
237 typeid(*lmo) == typeid(MapCenterObj)))
240 s=(((BranchObj*)lmo)->getHeading());
241 if (s=="") s="unnamed";
242 return QString("branch (%1)").arg(s);
243 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
245 if ((typeid(*lmo) == typeid(FloatImageObj) ))
246 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
247 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
248 return QString("Unknown type has no name!");
251 void MapEditor::makeTmpDirs()
253 // Create unique temporary directories
254 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
255 histPath=QDir::convertSeparators (tmpMapDir+"/history");
260 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSel)
262 // tmpdir temporary directory to which data will be written
263 // prefix mapname, which will be appended to images etc.
264 // writeflags Only write flags for "real" save of map, not undo
265 // offset offset of bbox of whole map in canvas.
266 // Needed for XML export
282 ls="StylePolyParabel";
286 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
288 if (linkcolorhint==HeadingColor)
289 colhint=attribut("linkColorHint","HeadingColor");
291 QString mapAttr=attribut("version",vymVersion);
292 if (!saveSel || saveSel==mapCenter)
293 mapAttr+= attribut("author",mapCenter->getAuthor()) +
294 attribut("comment",mapCenter->getComment()) +
295 attribut("date",mapCenter->getDate()) +
296 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
297 attribut("linkStyle", ls ) +
298 attribut("linkColor", defLinkColor.name() ) +
299 attribut("defXLinkColor", defXLinkColor.name() ) +
300 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
302 s+=beginElement("vymmap",mapAttr);
305 // Find the used flags while traversing the tree
306 standardFlagsDefault->resetUsedCounter();
308 // Reset the counters before saving
309 // TODO constr. of FIO creates lots of objects, better do this in some other way...
310 FloatImageObj (mapCanvas).resetSaveCounter();
312 // Build xml recursivly
313 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
314 // Save complete map, if saveSel not set
315 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
318 if ( typeid(*saveSel) == typeid(BranchObj) )
320 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
321 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
323 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
325 else if (selection && typeid(*selection)==typeid(BranchObj))
326 // Save selected branch is saved from mainwindow //FIXME maybe use "subtree" above?
327 // FIXME is this possible at all? BO is already above...
328 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
331 // Save local settings
332 s+=settings.getXMLData (destPath);
335 if (selection && !saveSel )
336 s+=valueElement("select",selection->getSelectString());
339 s+=endElement("vymmap");
342 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
346 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
348 // save the selected part of the map, Undo will replace part of map
349 QString undoSelection="";
351 undoSelection=undoSel->getSelectString();
353 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
354 QString redoSelection="";
356 redoSelection=undoSel->getSelectString();
358 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
361 saveState (PartOfMap,
362 undoSelection, "addMapReplace (\"PATH\")",
368 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
372 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
375 QString undoSelection=redoSel->getParObj()->getSelectString();
376 QString redoSelection=redoSel->getSelectString();
377 if (typeid(*redoSel) == typeid(BranchObj) )
379 // save the selected branch of the map, Undo will insert part of map
380 saveState (PartOfMap,
381 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
382 redoSelection, "delete ()",
389 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
391 // "Normal" savestate: save commands, selections and comment
392 // so just save commands for undo and redo
393 // and use current selection
395 QString redoSelection="";
396 if (redoSel) redoSelection=redoSel->getSelectString();
397 QString undoSelection="";
398 if (undoSel) undoSelection=undoSel->getSelectString();
400 saveState (UndoCommand,
407 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
409 // "Normal" savestate: save commands, selections and comment
410 // so just save commands for undo and redo
411 // and use current selection
412 saveState (UndoCommand,
420 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
424 if (blockSaveState) return;
426 /* TODO remove after testing
428 cout << "ME::saveState() "<<endl;
430 int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
431 int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
432 int curStep=undoSet.readNumEntry ("/history/curStep",0);
433 // Find out current undo directory
434 if (undosAvail<stepsTotal) undosAvail++;
436 if (curStep>stepsTotal) curStep=1;
438 QString backupXML="";
439 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
440 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
441 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
443 // Create bakMapDir if not available
446 makeSubDirs (bakMapDir);
448 // Save depending on how much needs to be saved
450 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel);
452 QString undoCommand="";
453 if (savemode==UndoCommand)
457 else if (savemode==PartOfMap )
460 undoCommand.replace ("PATH",bakMapPath);
463 if (!backupXML.isEmpty())
464 // Write XML Data to disk
465 saveStringToDisk (QString(bakMapPath),backupXML);
467 // We would have to save all actions in a tree, to keep track of
468 // possible redos after a action. Possible, but we are too lazy: forget about redos.
471 // Write the current state to disk
472 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
473 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
474 undoSet.setEntry ("/history/curStep",QString::number(curStep));
475 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
476 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
477 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
478 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
479 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
480 undoSet.setEntry (QString("/history/version"),vymVersion);
481 undoSet.writeSettings(histPath);
483 /* TODO remove after testing
485 //cout << " into="<< histPath.toStdString()<<endl;
486 cout << " stepsTotal="<<stepsTotal<<
487 ", undosAvail="<<undosAvail<<
488 ", redosAvail="<<redosAvail<<
489 ", curStep="<<curStep<<endl;
490 cout << " ---------------------------"<<endl;
491 cout << " comment="<<comment.toStdString()<<endl;
492 cout << " undoCom="<<undoCommand.toStdString()<<endl;
493 cout << " undoSel="<<undoSelection.toStdString()<<endl;
494 cout << " redoCom="<<redoCom.toStdString()<<endl;
495 cout << " redoSel="<<redoSelection.toStdString()<<endl;
496 if (saveSel) cout << " saveSel="<<saveSel->getSelectString().ascii()<<endl;
497 cout << " ---------------------------"<<endl;
500 mainWindow->updateHistory (undoSet);
504 void MapEditor::parseAtom(const QString &atom)
511 // Split string s into command and parameters
512 api.parseInput (atom);
513 QString com=api.command();
516 if (com=="addBranch")
520 api.setError (Aborted,"Nothing selected");
521 } else if ( (typeid(*selection) != typeid(BranchObj) &&
522 typeid(*selection) != typeid(MapCenterObj)) )
524 api.setError (Aborted,"Type of selection is not a branch");
529 if (api.checkParamCount(pl))
531 if (api.paramCount()==0)
532 addNewBranchInt (-2);
536 if (ok ) addNewBranchInt (y);
540 } else if (com=="addBranchBefore")
544 api.setError (Aborted,"Nothing selected");
545 } else if ( (typeid(*selection) != typeid(BranchObj) &&
546 typeid(*selection) != typeid(MapCenterObj)) )
548 api.setError (Aborted,"Type of selection is not a branch");
551 if (api.paramCount()==0)
553 addNewBranchBefore ();
556 } else if (com==QString("addMapReplace"))
560 api.setError (Aborted,"Nothing selected");
561 } else if ( (typeid(*selection) != typeid(BranchObj) &&
562 typeid(*selection) != typeid(MapCenterObj)) )
564 api.setError (Aborted,"Type of selection is not a branch");
565 } else if (api.checkParamCount(1))
567 //s=api.parString (ok,0); // selection
568 t=api.parString (ok,0); // path to map
569 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
570 addMapReplaceInt(selection->getSelectString(),t);
572 } else if (com==QString("addMapInsert"))
576 api.setError (Aborted,"Nothing selected");
577 } else if ( (typeid(*selection) != typeid(BranchObj) &&
578 typeid(*selection) != typeid(MapCenterObj)) )
580 api.setError (Aborted,"Type of selection is not a branch");
583 if (api.checkParamCount(2))
585 t=api.parString (ok,0); // path to map
586 y=api.parInt(ok,1); // position
587 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
588 addMapInsertInt(t,y);
591 } else if (com=="colorItem")
595 api.setError (Aborted,"Nothing selected");
596 } else if ( typeid(*selection) != typeid(BranchObj) &&
597 typeid(*selection) != typeid(MapCenterObj))
599 api.setError (Aborted,"Type of selection is not a branch");
600 } else if (api.checkParamCount(1))
602 QColor c=api.parColor (ok,0);
603 if (ok) colorItem (c);
605 } else if (com=="colorBranch")
609 api.setError (Aborted,"Nothing selected");
610 } else if ( typeid(*selection) != typeid(BranchObj) &&
611 typeid(*selection) != typeid(MapCenterObj))
613 api.setError (Aborted,"Type of selection is not a branch");
614 } else if (api.checkParamCount(1))
616 QColor c=api.parColor (ok,0);
617 if (ok) colorBranch (c);
619 } else if (com=="cut")
623 api.setError (Aborted,"Nothing selected");
624 } else if ( typeid(*selection) != typeid(BranchObj) &&
625 typeid(*selection) != typeid(MapCenterObj) &&
626 typeid(*selection) != typeid(FloatImageObj) )
628 api.setError (Aborted,"Type of selection is not a branch or floatimage");
629 } else if (api.checkParamCount(0))
633 } else if (com=="delete")
637 api.setError (Aborted,"Nothing selected");
638 } else if ( (typeid(*selection) != typeid(BranchObj) &&
639 typeid(*selection) != typeid(MapCenterObj)) )
641 api.setError (Aborted,"Type of selection is not a branch");
642 } else if (api.checkParamCount(0))
646 } else if (com=="deleteKeepChilds")
650 api.setError (Aborted,"Nothing selected");
651 } else if ( (typeid(*selection) != typeid(BranchObj) &&
652 typeid(*selection) != typeid(MapCenterObj)) )
654 api.setError (Aborted,"Type of selection is not a branch");
655 } else if (api.checkParamCount(0))
659 } else if (com=="deleteChilds")
663 api.setError (Aborted,"Nothing selected");
664 } else if ( (typeid(*selection) != typeid(BranchObj) &&
665 typeid(*selection) != typeid(MapCenterObj)) )
667 api.setError (Aborted,"Type of selection is not a branch");
668 } else if (api.checkParamCount(0))
672 } else if (com=="linkBranchToPos")
676 api.setError (Aborted,"Nothing selected");
677 } else if ( (typeid(*selection) != typeid(BranchObj) &&
678 typeid(*selection) != typeid(MapCenterObj)) )
680 api.setError (Aborted,"Type of selection is not a branch");
681 } else if (api.checkParamCount(4))
683 // 0 selectstring of parent
684 // 1 num in parent (for branches)
685 // 2,3 x,y of mainbranch or mapcenter
686 s=api.parString(ok,0);
687 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
690 if (typeid(*dst) == typeid(BranchObj) )
692 // Get number in parent
695 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
696 } else if (typeid(*dst) == typeid(MapCenterObj) )
698 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
699 // Get coordinates of mainbranch
704 if (ok) ((BranchObj*)selection)->move (x,y);
709 } else if (com=="moveBranchUp")
713 api.setError (Aborted,"Nothing selected");
714 } else if ( (typeid(*selection) != typeid(BranchObj) &&
715 typeid(*selection) != typeid(MapCenterObj)) )
717 api.setError (Aborted,"Type of selection is not a branch");
718 } else if (api.checkParamCount(0))
722 } else if (com=="moveBranchDown")
726 api.setError (Aborted,"Nothing selected");
727 } else if ( (typeid(*selection) != typeid(BranchObj) &&
728 typeid(*selection) != typeid(MapCenterObj)) )
730 api.setError (Aborted,"Type of selection is not a branch");
731 } else if (api.checkParamCount(0))
735 } else if (com=="move")
739 api.setError (Aborted,"Nothing selected");
740 } else if ( typeid(*selection) != typeid(BranchObj) &&
741 typeid(*selection) != typeid(MapCenterObj) &&
742 typeid(*selection) != typeid(FloatImageObj) )
744 api.setError (Aborted,"Type of selection is not a branch or floatimage");
745 } else if (api.checkParamCount(2))
754 } else if (com=="moveRel")
758 api.setError (Aborted,"Nothing selected");
759 } else if ( typeid(*selection) != typeid(BranchObj) &&
760 typeid(*selection) != typeid(MapCenterObj) &&
761 typeid(*selection) != typeid(FloatImageObj) )
763 api.setError (Aborted,"Type of selection is not a branch or floatimage");
764 } else if (api.checkParamCount(2))
770 if (ok) moveRel (x,y);
773 } else if (com=="paste")
777 api.setError (Aborted,"Nothing selected");
778 } else if ( typeid(*selection) != typeid(BranchObj) &&
779 typeid(*selection) != typeid(MapCenterObj) )
781 api.setError (Aborted,"Type of selection is not a branch");
782 } else if (api.checkParamCount(0))
786 } else if (com=="select")
788 if (api.checkParamCount(1))
790 s=api.parString(ok,0);
793 } else if (com=="setMapAuthor")
795 if (api.checkParamCount(1))
797 s=api.parString(ok,0);
798 if (ok) setMapAuthor (s);
800 } else if (com=="setMapComment")
802 if (api.checkParamCount(1))
804 s=api.parString(ok,0);
805 if (ok) setMapComment(s);
807 } else if (com=="setMapBackgroundColor")
811 api.setError (Aborted,"Nothing selected");
812 } else if ( (typeid(*selection) != typeid(BranchObj) &&
813 typeid(*selection) != typeid(MapCenterObj)) )
815 api.setError (Aborted,"Type of selection is not a branch");
816 } else if (api.checkParamCount(1))
818 QColor c=api.parColor (ok,0);
819 if (ok) setMapBackgroundColor (c);
821 } else if (com=="setMapDefLinkColor")
825 api.setError (Aborted,"Nothing selected");
826 } else if ( (typeid(*selection) != typeid(BranchObj) &&
827 typeid(*selection) != typeid(MapCenterObj)) )
829 api.setError (Aborted,"Type of selection is not a branch");
830 } else if (api.checkParamCount(1))
832 QColor c=api.parColor (ok,0);
833 if (ok) setMapDefLinkColor (c);
835 } else if (com=="setMapLinkStyle")
837 if (api.checkParamCount(1))
839 s=api.parString (ok,0);
840 if (ok) setMapLinkStyle(s);
842 } else if (com=="setHeading")
846 api.setError (Aborted,"Nothing selected");
847 } else if ( (typeid(*selection) != typeid(BranchObj) &&
848 typeid(*selection) != typeid(MapCenterObj)) )
850 api.setError (Aborted,"Type of selection is not a branch");
851 } else if (api.checkParamCount(1))
853 s=api.parString (ok,0);
857 } else if (com=="setHideExport")
861 api.setError (Aborted,"Nothing selected");
862 } else if ( typeid(*selection) != typeid(BranchObj) &&
863 typeid(*selection) != typeid(FloatImageObj) )
865 api.setError (Aborted,"Type of selection is not a branch or floatimage");
866 } else if (api.checkParamCount(1))
869 if (ok) setHideExport (b);
871 } else if (com=="setURL")
875 api.setError (Aborted,"Nothing selected");
876 } else if ( (typeid(*selection) != typeid(BranchObj) &&
877 typeid(*selection) != typeid(MapCenterObj)) )
879 api.setError (Aborted,"Type of selection is not a branch");
880 } else if (api.checkParamCount(1))
882 s=api.parString (ok,0);
883 if (ok) setURLInt(s);
885 } else if (com=="setVymLink")
889 api.setError (Aborted,"Nothing selected");
890 } else if ( (typeid(*selection) != typeid(BranchObj) &&
891 typeid(*selection) != typeid(MapCenterObj)) )
893 api.setError (Aborted,"Type of selection is not a branch");
894 } else if (api.checkParamCount(1))
896 s=api.parString (ok,0);
897 if (ok) setVymLinkInt(s);
900 else if (com=="setFlag")
904 api.setError (Aborted,"Nothing selected");
905 } else if ( (typeid(*selection) != typeid(BranchObj) &&
906 typeid(*selection) != typeid(MapCenterObj)) )
908 api.setError (Aborted,"Type of selection is not a branch");
909 } else if (api.checkParamCount(1))
911 s=api.parString(ok,0);
914 BranchObj* bo=(BranchObj*)selection;
915 bo->activateStandardFlag(s);
916 bo->updateFlagsToolbar();
920 else if (com=="unsetFlag")
924 api.setError (Aborted,"Nothing selected");
925 } else if ( (typeid(*selection) != typeid(BranchObj) &&
926 typeid(*selection) != typeid(MapCenterObj)) )
928 api.setError (Aborted,"Type of selection is not a branch");
929 } else if (api.checkParamCount(1))
931 s=api.parString(ok,0);
934 BranchObj* bo=(BranchObj*)selection;
935 bo->deactivateStandardFlag(s);
936 bo->updateFlagsToolbar();
941 api.setError (Aborted,"Unknown command");
945 if (api.errorLevel()==NoError)
949 // TODO Error handling
950 qWarning("MapEditor::parseAtom: Error!");
951 qWarning(api.errorMessage());
956 bool MapEditor::isDefault()
961 bool MapEditor::isUnsaved()
966 bool MapEditor::hasChanged()
971 void MapEditor::setChanged()
979 void MapEditor::closeMap()
981 // Unselect before disabling the toolbar actions
982 if (selection) selection->unselect();
990 void MapEditor::setFilePath(QString fname)
992 setFilePath (fname,fname);
995 void MapEditor::setFilePath(QString fname, QString destname)
997 if (fname.isEmpty() || fname=="")
1004 filePath=fname; // becomes absolute path
1005 fileName=fname; // gets stripped of path
1006 destPath=destname; // needed for vymlinks
1008 // If fname is not an absolute path, complete it
1009 filePath=QDir(fname).absPath();
1010 fileDir=filePath.left (1+filePath.findRev ("/"));
1012 // Set short name, too. Search from behind:
1013 int i=fileName.findRev("/");
1014 if (i>=0) fileName=fileName.remove (0,i+1);
1016 // Forget the .vym (or .xml) for name of map
1017 mapName=fileName.left(fileName.findRev(".",-1,true) );
1021 QString MapEditor::getFilePath()
1026 QString MapEditor::getFileName()
1031 QString MapEditor::getMapName()
1036 QString MapEditor::getDestPath()
1041 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
1043 ErrorCode err=success;
1047 if (selection) selection->unselect();
1050 mapCenter->setMapEditor(this);
1051 // (map state is set later at end of load...)
1054 if (!selection || (typeid(*selection) != typeid(BranchObj) &&
1055 typeid(*selection) != typeid (MapCenterObj)))
1057 BranchObj *bo=(BranchObj*)selection;
1058 if (lmode==ImportAdd)
1059 saveStateChangingPart(
1062 QString("addMapInsert (%1)").arg(fname),
1063 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1065 saveStateChangingPart(
1068 QString("addMapReplace(%1)").arg(fname),
1069 QString("Add map %1 to %2").arg(fname).arg(getName(bo)));
1073 mapBuilderHandler handler;
1074 QFile file( fname );
1076 // I am paranoid: file should exist anyway
1077 // according to check in mainwindow.
1078 if (!file.exists() )
1080 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1081 tr("Couldn't open map " +fname)+".");
1085 blockReposition=true;
1086 QXmlInputSource source( file);
1087 QXmlSimpleReader reader;
1088 reader.setContentHandler( &handler );
1089 reader.setErrorHandler( &handler );
1090 handler.setMapEditor( this );
1091 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
1092 handler.setInputFile (file.name());
1093 handler.setLoadMode (lmode);
1094 blockSaveState=true;
1095 bool ok = reader.parse( source );
1096 blockReposition=false;
1097 blockSaveState=false;
1101 mapCenter->reposition();
1111 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1112 tr( handler.errorProtocol() ) );
1114 // Still return "success": the map maybe at least
1115 // partially read by the parser
1122 int MapEditor::save (const SaveMode &savemode)
1126 // Create mapName and fileDir
1127 makeSubDirs (fileDir);
1131 fname=mapName+".xml";
1133 // use name given by user, even if he chooses .doc
1138 if (savemode==CompleteMap || selection==NULL)
1139 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
1141 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
1143 if (!saveStringToDisk(fileDir+fname,saveFile))
1156 void MapEditor::setZipped (bool z)
1161 bool MapEditor::saveZipped ()
1166 void MapEditor::print()
1170 printer = new QPrinter;
1171 printer->setColorMode (QPrinter::Color);
1172 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1175 QRect totalBBox=mapCenter->getTotalBBox();
1177 // Try to set orientation automagically
1178 // Note: Interpretation of generated postscript is amibiguous, if
1179 // there are problems with landscape mode, see
1180 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1182 if (totalBBox.width()>totalBBox.height())
1183 // recommend landscape
1184 printer->setOrientation (QPrinter::Landscape);
1186 // recommend portrait
1187 printer->setOrientation (QPrinter::Portrait);
1189 if ( printer->setup(this) )
1190 // returns false, if printing is canceled
1192 QPainter pp(printer);
1194 // Don't print the visualisation of selection
1195 LinkableMapObj *oldselection=NULL;
1198 oldselection=selection;
1199 selection->unselect();
1202 // Handle sizes of map and paper:
1204 // setWindow defines which part of the canvas will be transformed
1205 // setViewport defines area on paper in device coordinates (dpi)
1206 // e.g. (0,50,700,700) is upper part on A4
1207 // see also /usr/lib/qt3/doc/html/coordsys.html
1209 double paperAspect = (double)printer->width() / (double)printer->height();
1210 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1212 QRect mapRect=totalBBox;
1213 Q3CanvasRectangle *frame=NULL;
1214 Q3CanvasText *footerFN=NULL;
1215 Q3CanvasText *footerDate=NULL;
1216 if (printFrame || printFooter)
1221 // Print frame around map
1222 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1223 totalBBox.width()+20, totalBBox.height()+20);
1224 frame=new Q3CanvasRectangle (mapRect,mapCanvas);
1225 frame->setBrush (QColor(Qt::white));
1226 frame->setPen (QColor(Qt::black));
1230 /* TODO remove after testing
1231 QCanvasLine *l=new QCanvasLine (mapCanvas);
1232 l->setPoints (0,0,mapRect.width(),mapRect.height());
1233 l->setPen (QPen(QColor(black), 1));
1240 // Print footer below map
1242 font.setPointSize(10);
1243 footerFN=new Q3CanvasText (mapCanvas);
1244 footerFN->setText ("VYM - " + fileName);
1245 footerFN->setFont(font);
1246 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1247 footerFN->setZ(Z_TEXT);
1249 footerDate=new Q3CanvasText (mapCanvas);
1250 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1251 footerDate->setFont(font);
1252 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1253 footerDate->setZ(Z_TEXT);
1256 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1259 pp.setWindow (mapRect);
1262 if (mapAspect>=paperAspect)
1264 // Fit horizontally to paper width
1265 pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );
1268 // Fit vertically to paper height
1269 pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());
1272 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1274 // Delete Frame and footer
1278 delete (footerDate);
1280 if (frame) delete (frame);
1282 // Restore selection
1285 selection=oldselection;
1286 selection->select();
1289 // Save settings in vymrc
1290 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1294 QPixmap MapEditor::getPixmap()
1296 QRect mapRect=mapCenter->getTotalBBox();
1297 QPixmap pix (mapRect.size());
1300 // Don't print the visualisation of selection
1301 LinkableMapObj *oldselection=NULL;
1304 oldselection=selection;
1305 selection->unselect();
1308 pp.setWindow (mapRect);
1310 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1313 // Restore selection
1316 selection=oldselection;
1317 selection->select();
1323 void MapEditor::setHideTmpMode (HideTmpMode mode)
1326 mapCenter->setHideTmp (hidemode);
1327 mapCenter->reposition();
1332 HideTmpMode MapEditor::getHideTmpMode()
1337 void MapEditor::exportImage(QString fn)
1339 setExportMode (true);
1340 QPixmap pix (getPixmap());
1341 pix.save(fn, "PNG");
1342 setExportMode (false);
1345 void MapEditor::setExportMode (bool b)
1347 // should be called before and after exports
1348 // depending on the settings
1349 if (b && settings.value("/export/useHideExport","yes")=="yes")
1350 setHideTmpMode (HideExport);
1352 setHideTmpMode (HideNone);
1355 void MapEditor::exportImage(QString fn, QString format)
1357 setExportMode (true);
1358 QPixmap pix (getPixmap());
1359 pix.save(fn, format);
1360 setExportMode (false);
1363 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1367 ex.setMapCenter(mapCenter);
1368 if (ex.setConfigFile(cf))
1370 setExportMode (true);
1371 ex.exportPresentation();
1372 setExportMode (false);
1378 void MapEditor::exportXML(const QString &dir)
1380 // Hide stuff during export, if settings want this
1381 setExportMode (true);
1383 // Create subdirectories
1386 // write to directory
1387 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1390 file.setName ( dir + "/"+mapName+".xml");
1391 if ( !file.open( QIODevice::WriteOnly ) )
1393 // This should neverever happen
1394 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1398 // Write it finally, and write in UTF8, no matter what
1399 QTextStream ts( &file );
1400 ts.setEncoding (QTextStream::UnicodeUTF8);
1404 // Now write image, too
1405 exportImage (dir+"/images/"+mapName+".png");
1407 setExportMode (false);
1410 void MapEditor::clear()
1414 selection->unselect();
1421 void MapEditor::copy()
1425 // write to directory
1426 QString clipfile="part";
1427 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1430 file.setName ( clipboardDir + "/"+clipfile+".xml");
1431 if ( !file.open( QIODevice::WriteOnly ) )
1433 // This should neverever happen
1434 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1438 // Write it finally, and write in UTF8, no matter what
1439 QTextStream ts( &file );
1440 ts.setEncoding (QTextStream::UnicodeUTF8);
1444 clipboardEmpty=false;
1449 void MapEditor::redo()
1451 blockSaveState=true;
1453 // Restore variables
1454 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1455 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1456 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1457 // Can we undo at all?
1458 if (redosAvail<1) return;
1461 if (undosAvail<stepsTotal) undosAvail++;
1463 if (curStep>stepsTotal) curStep=1;
1464 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1465 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1466 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1467 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1468 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1469 QString version=undoSet.readEntry ("/history/version");
1471 if (!checkVersion(version))
1472 QMessageBox::warning(0,tr("Warning"),
1473 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1476 // Find out current undo directory
1477 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1479 /* TODO remove testing
1481 cout << "ME::redo() begin\n";
1482 cout << " undosAvail="<<undosAvail<<endl;
1483 cout << " redosAvail="<<redosAvail<<endl;
1484 cout << " curStep="<<curStep<<endl;
1485 cout << " ---------------------------"<<endl;
1486 cout << " comment="<<comment.toStdString()<<endl;
1487 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1488 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1489 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1490 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1491 cout << " ---------------------------"<<endl<<endl;
1493 // select object before redo
1494 if (!redoSelection.isEmpty())
1495 select (redoSelection);
1498 parseAtom (redoCommand);
1499 mapCenter->reposition();
1501 blockSaveState=false;
1503 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1504 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1505 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1506 undoSet.writeSettings(histPath);
1509 mainWindow->updateHistory (undoSet);
1511 /* TODO remove testing
1512 cout << "ME::redo() end\n";
1513 cout << " undosAvail="<<undosAvail<<endl;
1514 cout << " redosAvail="<<redosAvail<<endl;
1515 cout << " curStep="<<curStep<<endl;
1516 cout << " ---------------------------"<<endl<<endl;
1522 bool MapEditor::isRedoAvailable()
1524 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1530 void MapEditor::undo()
1532 blockSaveState=true;
1534 // Restore variables
1535 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1536 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1537 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1539 // Can we undo at all?
1540 if (undosAvail<1) return;
1542 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1543 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1544 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1545 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1546 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1547 QString version=undoSet.readEntry ("/history/version");
1549 if (!checkVersion(version))
1550 QMessageBox::warning(0,tr("Warning"),
1551 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1553 // Find out current undo directory
1554 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1556 // select object before undo
1557 if (!undoSelection.isEmpty())
1558 select (undoSelection);
1562 cout << "ME::undo() begin\n";
1563 cout << " undosAvail="<<undosAvail<<endl;
1564 cout << " redosAvail="<<redosAvail<<endl;
1565 cout << " curStep="<<curStep<<endl;
1566 cout << " ---------------------------"<<endl;
1567 cout << " comment="<<comment.toStdString()<<endl;
1568 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1569 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1570 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1571 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1572 cout << " ---------------------------"<<endl<<endl;
1573 parseAtom (undoCommand);
1574 mapCenter->reposition();
1578 if (curStep<1) curStep=stepsTotal;
1582 blockSaveState=false;
1583 /* TODO remove testing
1584 cout << "ME::undo() end\n";
1585 cout << " undosAvail="<<undosAvail<<endl;
1586 cout << " redosAvail="<<redosAvail<<endl;
1587 cout << " curStep="<<curStep<<endl;
1588 cout << " ---------------------------"<<endl<<endl;
1591 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1592 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1593 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1594 undoSet.writeSettings(histPath);
1596 mainWindow->updateHistory (undoSet);
1600 bool MapEditor::isUndoAvailable()
1602 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1608 void MapEditor::gotoHistoryStep (int i)
1610 // Restore variables
1611 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1612 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1614 if (i<0) i=undosAvail+redosAvail;
1616 // Clicking above current step makes us undo things
1619 for (int j=0; j<undosAvail-i; j++) undo();
1622 // Clicking below current step makes us redo things
1624 for (int j=undosAvail; j<i; j++) redo();
1626 // And ignore clicking the current row ;-)
1629 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
1631 QString pathDir=path.left(path.findRev("/"));
1637 // We need to parse saved XML data
1638 mapBuilderHandler handler;
1639 QXmlInputSource source( file);
1640 QXmlSimpleReader reader;
1641 reader.setContentHandler( &handler );
1642 reader.setErrorHandler( &handler );
1643 handler.setMapEditor( this );
1644 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1645 if (undoSel.isEmpty())
1649 handler.setLoadMode (NewMap);
1653 handler.setLoadMode (ImportReplace);
1655 blockReposition=true;
1656 bool ok = reader.parse( source );
1657 blockReposition=false;
1660 // This should never ever happen
1661 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1662 handler.errorProtocol());
1665 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1668 void MapEditor::addMapInsertInt (const QString &path, int pos)
1670 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1671 typeid(*selection) == typeid(MapCenterObj)))
1673 QString pathDir=path.left(path.findRev("/"));
1679 // We need to parse saved XML data
1680 mapBuilderHandler handler;
1681 QXmlInputSource source( file);
1682 QXmlSimpleReader reader;
1683 reader.setContentHandler( &handler );
1684 reader.setErrorHandler( &handler );
1685 handler.setMapEditor( this );
1686 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1687 handler.setLoadMode (ImportAdd);
1688 blockReposition=true;
1689 bool ok = reader.parse( source );
1690 blockReposition=false;
1693 // This should never ever happen
1694 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1695 handler.errorProtocol());
1697 if (selection!=mapCenter)
1698 ((BranchObj*)selection)->getLastBranch()->moveBranchTo ((BranchObj*)(selection),pos);
1700 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1704 void MapEditor::pasteNoSave()
1706 load (clipboardDir+"/part.xml",ImportAdd);
1709 void MapEditor::cutNoSave()
1715 void MapEditor::paste()
1717 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1718 typeid(*selection) == typeid(MapCenterObj)))
1721 saveStateChangingPart(
1725 QString("Paste to %1").arg( getName(selection))
1727 mapCenter->reposition();
1732 void MapEditor::cut()
1734 saveStateChangingPart(
1735 selection->getParObj(),
1738 QString("Cut %1").arg(getName(selection))
1742 mapCenter->reposition();
1746 void MapEditor::move(const int &x, const int &y)
1750 QString ps=qpointToString (selection->getAbsPos());
1751 QString s=selection->getSelectString();
1754 s, "move "+qpointToString (QPoint (x,y)),
1755 QString("Move %1 to %2").arg(getName(selection)).arg(ps));
1756 selection->move(x,y);
1757 mapCenter->reposition();
1763 void MapEditor::moveRel (const int &x, const int &y)
1765 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1766 typeid(*selection) == typeid(MapCenterObj) ||
1767 typeid(*selection) == typeid (FloatImageObj)))
1769 QString ps=qpointToString (selection->getRelPos());
1770 QString s=selection->getSelectString();
1773 s, "moveRel "+qpointToString (QPoint (x,y)),
1774 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps));
1775 ((OrnamentedObj*)selection)->move2RelPos (x,y);
1776 mapCenter->reposition();
1781 void MapEditor::moveBranchUp()
1785 if (typeid(*selection) == typeid(BranchObj) )
1787 bo=(BranchObj*)selection;
1788 if (!bo->canMoveBranchUp()) return;
1789 par=(BranchObj*)(bo->getParObj());
1790 selection->unselect();
1791 bo=par->moveBranchUp (bo); // bo will be the one below selection
1792 selection->select();
1793 saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1794 mapCenter->reposition();
1795 ensureSelectionVisible();
1799 void MapEditor::moveBranchDown()
1803 if (typeid(*selection) == typeid(BranchObj) )
1805 bo=(BranchObj*)selection;
1806 if (!bo->canMoveBranchDown()) return;
1807 par=(BranchObj*)(bo->getParObj());
1808 selection->unselect();
1809 bo=par->moveBranchDown(bo); // bo will be the one above selection
1810 selection->select();
1811 saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1812 mapCenter->reposition();
1813 ensureSelectionVisible();
1817 QString MapEditor::getHeading(bool &ok, QPoint &p)
1820 (typeid(*selection) == typeid(BranchObj) ||
1821 typeid(*selection) == typeid(MapCenterObj) ) )
1824 ensureSelectionVisible();
1825 p = ((BranchObj*)selection)->getAbsPos();
1826 p.setX (p.x() - contentsX());
1827 p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2);
1828 return ((BranchObj*)selection)->getHeading();
1834 void MapEditor::setHeading(const QString &s)
1837 (typeid(*selection) == typeid(BranchObj) ||
1838 typeid(*selection) == typeid(MapCenterObj) ) )
1840 editingBO=(BranchObj*)selection;
1843 "setHeading (\""+editingBO->getHeading()+"\")",
1845 "setHeading (\""+s+"\")",
1846 QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) );
1847 editingBO->setHeading(s );
1849 mapCenter->reposition();
1851 ensureSelectionVisible();
1855 void MapEditor::setURLInt (const QString &s)
1857 // Internal function, no saveState needed
1859 (typeid(*selection) == typeid(BranchObj) ||
1860 typeid(*selection) == typeid(MapCenterObj) ) )
1862 ((BranchObj*)selection)->setURL(s);
1863 mapCenter->reposition();
1865 ensureSelectionVisible();
1869 void MapEditor::setHeadingInt(const QString &s)
1872 (typeid(*selection) == typeid(BranchObj) ||
1873 typeid(*selection) == typeid(MapCenterObj) ) )
1875 ((BranchObj*)selection)->setHeading(s);
1876 mapCenter->reposition();
1878 ensureSelectionVisible();
1882 void MapEditor::setVymLinkInt (const QString &s)
1884 // Internal function, no saveState needed
1886 (typeid(*selection) == typeid(BranchObj) ||
1887 typeid(*selection) == typeid(MapCenterObj) ) )
1889 ((BranchObj*)selection)->setVymLink(s);
1890 mapCenter->reposition();
1892 ensureSelectionVisible();
1896 BranchObj* MapEditor::addNewBranchInt(int num)
1898 // Depending on pos:
1899 // -3 insert in childs of parent above selection
1900 // -2 add branch to selection
1901 // -1 insert in childs of parent below selection
1902 // 0..n insert in childs of parent at pos
1903 BranchObj *newbo=NULL;
1905 (typeid(*selection) == typeid(BranchObj) ||
1906 typeid(*selection) == typeid(MapCenterObj) ) )
1908 BranchObj* bo = (BranchObj*) selection;
1911 // save scroll state. If scrolled, automatically select
1912 // new branch in order to tmp unscroll parent...
1913 return bo->addBranch();
1918 bo=(BranchObj*)bo->getParObj();
1922 bo=(BranchObj*)bo->getParObj();
1925 newbo=bo->insertBranch(num);
1930 BranchObj* MapEditor::addNewBranch(int pos)
1932 // Different meaning than num in addNewBranchInt!
1936 BranchObj *bo = (BranchObj*) selection;
1937 BranchObj *newbo=NULL;
1940 (typeid(*selection) == typeid(BranchObj) ||
1941 typeid(*selection) == typeid(MapCenterObj) ) )
1943 newbo=addNewBranchInt (pos-2);
1948 selection, // FIXME sholdnt newbo be deleted here???
1951 QString ("addBranch (%1)").arg(pos-2),
1952 QString ("Add new branch to %1").arg(getName(bo)));
1954 mapCenter->reposition();
1962 BranchObj* MapEditor::addNewBranchBefore()
1964 BranchObj *newbo=NULL;
1966 (typeid(*selection) == typeid(BranchObj) ) )
1967 // We accept no MapCenterObj here, so we _have_ a parent
1969 BranchObj* bo = (BranchObj*) selection;
1970 QPoint p=bo->getRelPos();
1973 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1975 // add below selection
1976 newbo=parbo->insertBranch(bo->getNum()+1);
1979 newbo->move2RelPos (p);
1981 // Move selection to new branch
1982 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1984 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
1985 QString ("Add branch before %1").arg(getName(bo)));
1987 mapCenter->reposition();
1994 void MapEditor::deleteSelection()
1996 if (selection && typeid(*selection) ==typeid(BranchObj) )
1998 BranchObj* bo=(BranchObj*)selection;
1999 BranchObj* par=(BranchObj*)(bo->getParObj());
2001 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
2003 par->removeBranch(bo);
2005 selection->select();
2006 ensureSelectionVisible();
2007 mapCenter->reposition();
2010 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
2012 FloatImageObj* fio=(FloatImageObj*)selection;
2013 BranchObj* par=(BranchObj*)(fio->getParObj());
2014 saveStateChangingPart(
2018 QString("Delete %1").arg(getName(fio))
2022 par->removeFloatImage(fio);
2024 selection->select();
2025 ensureSelectionVisible();
2026 mapCenter->reposition();
2031 LinkableMapObj* MapEditor::getSelection()
2036 void MapEditor::unselect()
2040 selectionLast=selection;
2041 selection->unselect();
2046 void MapEditor::reselect()
2050 selection=selectionLast;
2051 selection->select();
2056 bool MapEditor::select (const QString &s)
2058 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
2060 // Finally select the found object
2063 if (selection) unselect();
2065 selection->select();
2067 ensureSelectionVisible();
2073 QString MapEditor::getSelectString()
2075 if (selection) return selection->getSelectString();
2079 void MapEditor::selectInt (LinkableMapObj *lmo)
2081 if (lmo && selection != lmo)
2083 // select the MapObj
2084 if (selection) selection->unselect();
2086 selection->select();
2092 void MapEditor::selectNextBranchInt()
2094 // Increase number of branch
2097 QString s=selection->getSelectString();
2103 part=s.section(",",-1);
2105 num=part.right(part.length() - 3);
2107 s=s.left (s.length() -num.length());
2110 num=QString ("%1").arg(num.toUInt()+1);
2114 // Try to select this one
2115 if (select (s)) return;
2117 // We have no direct successor,
2118 // try to increase the parental number in order to
2119 // find a successor with same depth
2121 int d=selection->getDepth();
2126 while (!found && d>0)
2128 s=s.section (",",0,d-1);
2129 // replace substring of current depth in s with "1"
2130 part=s.section(",",-1);
2132 num=part.right(part.length() - 3);
2136 // increase number of parent
2137 num=QString ("%1").arg(num.toUInt()+1);
2138 s=s.section (",",0,d-2) + ","+ typ+num;
2141 // Special case, look at orientation
2142 if (selection->getOrientation()==OrientRightOfCenter)
2143 num=QString ("%1").arg(num.toUInt()+1);
2145 num=QString ("%1").arg(num.toUInt()-1);
2150 // pad to oldDepth, select the first branch for each depth
2151 for (i=d;i<oldDepth;i++)
2156 if ( ((BranchObj*)selection)->countBranches()>0)
2164 // try to select the freshly built string
2172 void MapEditor::selectPrevBranchInt()
2174 // Decrease number of branch
2177 QString s=selection->getSelectString();
2183 part=s.section(",",-1);
2185 num=part.right(part.length() - 3);
2187 s=s.left (s.length() -num.length());
2190 num=QString ("%1").arg(num.toUInt()-1);
2194 // Try to select this one
2195 if (select (s)) return;
2197 // We have no direct precessor,
2198 // try to decrease the parental number in order to
2199 // find a precessor with same depth
2201 int d=selection->getDepth();
2206 while (!found && d>0)
2208 s=s.section (",",0,d-1);
2209 // replace substring of current depth in s with "1"
2210 part=s.section(",",-1);
2212 num=part.right(part.length() - 3);
2216 // decrease number of parent
2217 num=QString ("%1").arg(num.toUInt()-1);
2218 s=s.section (",",0,d-2) + ","+ typ+num;
2221 // Special case, look at orientation
2222 if (selection->getOrientation()==OrientRightOfCenter)
2223 num=QString ("%1").arg(num.toUInt()-1);
2225 num=QString ("%1").arg(num.toUInt()+1);
2230 // pad to oldDepth, select the last branch for each depth
2231 for (i=d;i<oldDepth;i++)
2235 if ( ((BranchObj*)selection)->countBranches()>0)
2236 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
2243 // try to select the freshly built string
2251 void MapEditor::selectUpperBranch()
2255 if (typeid(*selection) == typeid(BranchObj))
2257 if (selection->getOrientation()==OrientRightOfCenter)
2258 selectPrevBranchInt();
2260 if (selection->getDepth()==1)
2261 selectNextBranchInt();
2263 selectPrevBranchInt();
2268 void MapEditor::selectLowerBranch()
2272 if (typeid(*selection) == typeid(BranchObj))
2274 if (selection->getOrientation()==OrientRightOfCenter)
2275 selectNextBranchInt();
2277 if (selection->getDepth()==1)
2278 selectPrevBranchInt();
2280 selectNextBranchInt();
2286 void MapEditor::selectLeftBranch()
2292 if (typeid(*selection) == typeid(MapCenterObj))
2294 par= (BranchObj*) selection;
2295 bo=par->getLastSelectedBranch();
2298 // Workaround for reselecting on left and right side
2299 if (bo->getOrientation()==OrientRightOfCenter)
2301 bo=par->getLastBranch();
2307 selection->select();
2309 ensureSelectionVisible();
2314 par=(BranchObj*)(selection->getParObj());
2315 if (selection->getOrientation()==OrientRightOfCenter)
2317 if (typeid(*selection) == typeid(BranchObj) ||
2318 typeid(*selection) == typeid(FloatImageObj))
2320 selection->unselect();
2322 selection->select();
2324 ensureSelectionVisible();
2328 if (typeid(*selection) == typeid(BranchObj) )
2330 bo=((BranchObj*)selection)->getLastSelectedBranch();
2333 selection->unselect();
2335 selection->select();
2337 ensureSelectionVisible();
2345 void MapEditor::selectRightBranch()
2352 if (typeid(*selection) == typeid(MapCenterObj))
2354 par= (BranchObj*) selection;
2355 bo=par->getLastSelectedBranch();
2358 // Workaround for reselecting on left and right side
2359 if (bo->getOrientation()==OrientLeftOfCenter)
2360 bo=par->getFirstBranch();
2365 selection->select();
2366 ensureSelectionVisible();
2371 par=(BranchObj*)(selection->getParObj());
2372 if (selection->getOrientation()==OrientLeftOfCenter)
2374 if (typeid(*selection) == typeid(BranchObj) ||
2375 typeid(*selection) == typeid(FloatImageObj))
2377 selection->unselect();
2379 selection->select();
2381 ensureSelectionVisible();
2385 if (typeid(*selection) == typeid(BranchObj) )
2387 bo=((BranchObj*)selection)->getLastSelectedBranch();
2390 selection->unselect();
2392 selection->select();
2394 ensureSelectionVisible();
2402 void MapEditor::selectFirstBranch()
2408 if (typeid(*selection) == typeid(BranchObj))
2410 bo1= (BranchObj*) selection;
2411 par=(BranchObj*)(bo1->getParObj());
2412 bo2=par->getFirstBranch();
2416 selection->select();
2417 ensureSelectionVisible();
2424 void MapEditor::selectLastBranch()
2430 if (typeid(*selection) == typeid(BranchObj))
2432 bo1= (BranchObj*) selection;
2433 par=(BranchObj*)(bo1->getParObj());
2434 bo2=par->getLastBranch();
2438 selection->select();
2439 ensureSelectionVisible();
2446 void MapEditor::selectMapBackgroundColor()
2448 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2449 if ( !col.isValid() ) return;
2450 setBackgroundColor( col );
2454 void MapEditor::setMapBackgroundColor(QColor col)
2456 QColor oldcol=mapCanvas->backgroundColor();
2459 QString ("setMapBackgroundColor (%1)").arg(oldcol.name()),
2461 QString ("setMapBackgroundColor (%1)").arg(col.name()),
2462 QString("Set background color of map to %1").arg(col.name()));
2463 mapCanvas->setBackgroundColor (col);
2466 QColor MapEditor::getMapBackgroundColor()
2468 return mapCanvas->backgroundColor();
2471 QColor MapEditor::getCurrentHeadingColor()
2475 if (typeid(*selection) == typeid(BranchObj) ||
2476 typeid(*selection) == typeid(MapCenterObj))
2478 BranchObj *bo=(BranchObj*)selection;
2479 return bo->getColor();
2483 QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected"));
2487 void MapEditor::colorItem(QColor c)
2491 if (typeid(*selection) == typeid(BranchObj) ||
2492 typeid(*selection) == typeid(MapCenterObj))
2494 BranchObj *bo=(BranchObj*)selection;
2497 QString ("colorItem (%1)").arg(bo->getColor().name()),
2499 QString ("colorItem (%1)").arg(c.name()),
2500 QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
2502 bo->setColor(c); // color branch
2507 void MapEditor::colorBranch(QColor c)
2511 if (typeid(*selection) == typeid(BranchObj) ||
2512 typeid(*selection) == typeid(MapCenterObj))
2514 BranchObj *bo=(BranchObj*)selection;
2515 saveStateChangingPart(
2518 QString ("colorBranch (%1)").arg(c.name()),
2519 QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
2521 bo->setColorChilds(c); // color links, color childs
2527 void MapEditor::toggleStandardFlag(QString f)
2531 if (typeid(*selection) == typeid(BranchObj) ||
2532 typeid(*selection) == typeid(MapCenterObj))
2534 BranchObj *bo=(BranchObj*)selection;
2536 if (bo->isSetStandardFlag(f))
2548 QString("%1 (\"%2\")").arg(u).arg(f),
2550 QString("%1 (\"%2\")").arg(r).arg(f),
2551 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2552 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
2558 void MapEditor::setViewCenter()
2560 // transform to CanvasView Coord:
2561 QPoint p=worldMatrix().map(movingCenter);
2562 center ( p.x(), p.y());
2566 BranchObj* MapEditor::findText (QString s, bool cs)
2568 QTextDocument::FindFlags flags=0;
2569 if (cs) flags=QTextDocument::FindCaseSensitively;
2572 { // Nothing found or new find process
2574 // nothing found, start again
2576 itFind=mapCenter->first();
2578 bool searching=true;
2579 bool foundNote=false;
2580 while (searching && !EOFind)
2584 // Searching in Note
2585 if (itFind->getNote().contains(s,cs))
2587 if (selection!=itFind)
2589 if (selection) ((BranchObj*)selection)->unselect();
2591 selection->select();
2593 ensureSelectionVisible();
2595 if (textEditor->findText(s,flags))
2601 // Searching in Heading
2602 if (searching && itFind->getHeading().contains (s,cs) )
2604 if (selection) ((BranchObj*)selection)->unselect();
2606 selection->select();
2608 ensureSelectionVisible();
2614 itFind=itFind->next();
2615 if (!itFind) EOFind=true;
2621 return (BranchObj*)selection;
2626 void MapEditor::findReset()
2627 { // Necessary if text to find changes during a find process
2631 void MapEditor::setURL(const QString &url)
2633 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2634 typeid(*selection) == typeid(MapCenterObj)) )
2636 BranchObj *bo=(BranchObj*)selection;
2637 QString oldurl=bo->getURL();
2641 QString ("setURL (\"%1\")").arg(oldurl),
2643 QString ("setURL (\"%1\")").arg(url),
2644 QString ("set URL of %1 to %2").arg(getName(bo)).arg(url)
2650 void MapEditor::editURL()
2652 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2653 typeid(*selection) == typeid(MapCenterObj)) )
2656 BranchObj *bo=(BranchObj*)selection;
2657 QString text = QInputDialog::getText(
2658 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2659 bo->getURL(), &ok, this );
2661 // user entered something and pressed OK
2666 QString MapEditor::getURL()
2668 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2669 typeid(*selection) == typeid(MapCenterObj)) )
2670 return ((BranchObj*)selection)->getURL();
2675 QStringList MapEditor::getURLs()
2678 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2679 typeid(*selection) == typeid(MapCenterObj)) )
2681 BranchObj *bo=(BranchObj*)selection;
2685 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2693 void MapEditor::editHeading2URL()
2695 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2696 typeid(*selection) == typeid(MapCenterObj)) )
2697 setURL (((BranchObj*)selection)->getHeading());
2700 void MapEditor::editBugzilla2URL()
2702 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2703 typeid(*selection) == typeid(MapCenterObj)) )
2705 BranchObj *bo=(BranchObj*)selection;
2706 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2711 void MapEditor::editFATE2URL()
2713 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2714 typeid(*selection) == typeid(MapCenterObj)) )
2716 BranchObj *bo=(BranchObj*)selection;
2717 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2720 "setURL (\""+bo->getURL()+"\")",
2722 "setURL (\""+url+"\")",
2723 QString("Use heading of %1 as link to FATE").arg(getName(bo))
2730 void MapEditor::editVymLink()
2732 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2733 typeid(*selection) == typeid(MapCenterObj)) )
2735 BranchObj *bo=(BranchObj*)selection;
2736 QStringList filters;
2737 filters <<"VYM map (*.vym)";
2738 QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map"));
2739 fd->setFilters (filters);
2740 fd->setCaption(vymName+" - " +tr("Link to another map"));
2741 if (! bo->getVymLink().isEmpty() )
2742 fd->selectFile( bo->getVymLink() );
2746 if ( fd->exec() == QDialog::Accepted )
2750 "setVymLink (\""+bo->getVymLink()+"\")",
2752 "setVymLink (\""+fd->selectedFile()+"\")",
2753 QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())
2755 bo->setVymLink (fd->selectedFile() );
2757 mapCenter->reposition();
2764 void MapEditor::deleteVymLink()
2766 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2767 typeid(*selection) == typeid(MapCenterObj)) )
2769 BranchObj *bo=(BranchObj*)selection;
2772 "setVymLink (\""+bo->getVymLink()+"\")",
2774 "setVymLink (\"\")",
2775 QString("Unset vymlink of %1").arg(getName(bo))
2777 bo->setVymLink ("" );
2779 mapCenter->reposition();
2785 void MapEditor::setHideExport(bool b)
2787 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2788 typeid(*selection)==typeid(FloatImageObj)))
2790 OrnamentedObj *oo=(OrnamentedObj*)selection;
2791 oo->setHideInExport (b);
2792 QString u= b ? "false" : "true";
2793 QString r=!b ? "false" : "true";
2797 QString ("setHideExport (%1)").arg(u),
2799 QString ("setHideExport (%1)").arg(r),
2800 QString ("Set HideExport flag of %1 to %2").arg(getName(oo)).arg (r)
2803 mapCenter->reposition();
2809 void MapEditor::toggleHideExport()
2811 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2812 typeid(*selection)==typeid(FloatImageObj)))
2813 setHideExport ( !((OrnamentedObj*)selection)->hideInExport() );
2816 QString MapEditor::getVymLink()
2818 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2819 typeid(*selection) == typeid(MapCenterObj)) )
2821 return ((BranchObj*)selection)->getVymLink();
2827 QStringList MapEditor::getVymLinks()
2830 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2831 typeid(*selection) == typeid(MapCenterObj)) )
2833 BranchObj *bo=(BranchObj*)selection;
2837 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2845 void MapEditor::deleteKeepChilds()
2847 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2849 BranchObj* bo=(BranchObj*)selection;
2850 BranchObj* par=(BranchObj*)(bo->getParObj());
2851 QPoint p=bo->getRelPos();
2852 saveStateChangingPart(
2853 selection->getParObj(),
2855 "deleteKeepChilds ()",
2856 QString("Remove %1 and keep its childs").arg(getName(bo))
2859 QString sel=selection->getSelectString();
2861 par->removeBranchHere(bo);
2862 mapCenter->reposition();
2864 ((BranchObj*)selection)->move2RelPos (p);
2865 mapCenter->reposition();
2870 void MapEditor::deleteChilds()
2872 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2873 typeid(*selection)==typeid(MapCenterObj)))
2875 saveStateChangingPart(
2876 selection->getParObj(),
2879 QString( "Remove childs of branch %1").arg(getName(selection))
2881 ((BranchObj*)selection)->removeChilds();
2882 mapCenter->reposition();
2886 void MapEditor::editMapInfo()
2888 ExtraInfoDialog dia;
2889 dia.setMapName (getFileName() );
2890 dia.setAuthor (mapCenter->getAuthor() );
2891 dia.setComment(mapCenter->getComment() );
2896 Q3CanvasItemList l=canvas()->allItems();
2897 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2899 stats+=QString ("%1 items on canvas\n").arg (i,6);
2906 bo=mapCenter->first();
2909 if (!bo->getNote().isEmpty() ) n++;
2910 f+= bo->countFloatImages();
2912 xl+=bo->countXLinks();
2915 stats+=QString ("%1 branches\n").arg (b-1,6);
2916 stats+=QString ("%1 xLinks \n").arg (xl,6);
2917 stats+=QString ("%1 notes\n").arg (n,6);
2918 stats+=QString ("%1 images\n").arg (f,6);
2919 dia.setStats (stats);
2921 // Finally show dialog
2922 if (dia.exec() == QDialog::Accepted)
2924 setMapAuthor (dia.getAuthor() );
2925 setMapComment (dia.getComment() );
2929 void MapEditor::updateActions()
2931 mainWindow->updateActions();
2932 // FIXME maybe don't update if blockReposition is set
2935 void MapEditor::updateNoteFlag()
2938 if ( (typeid(*selection) == typeid(BranchObj)) ||
2939 (typeid(*selection) == typeid(MapCenterObj)) )
2940 ((BranchObj*)selection)->updateNoteFlag();
2943 void MapEditor::setMapAuthor (const QString &s)
2947 QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()),
2949 QString ("setMapAuthor (\"%1\")").arg(s),
2950 QString ("Set author of map to \"%1\"").arg(s)
2952 mapCenter->setAuthor (s);
2955 void MapEditor::setMapComment (const QString &s)
2959 QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()),
2961 QString ("setMapComment (\"%1\")").arg(s),
2962 QString ("Set comment of map")
2964 mapCenter->setComment (s);
2967 void MapEditor::setMapLinkStyle (const QString & s)
2969 saveStateChangingPart (
2972 QString("setMapLinkStyle (\"%1\")").arg(s),
2973 QString("Set map link style (\"%1\")").arg(s)
2977 linkstyle=StyleLine;
2978 else if (s=="StyleParabel")
2979 linkstyle=StyleParabel;
2980 else if (s=="StylePolyLine")
2981 linkstyle=StylePolyLine;
2983 linkstyle=StylePolyParabel;
2986 bo=mapCenter->first();
2990 bo->setLinkStyle(bo->getDefLinkStyle());
2993 mapCenter->reposition();
2996 LinkStyle MapEditor::getMapLinkStyle ()
3001 void MapEditor::setMapDefLinkColor(QColor c)
3007 void MapEditor::setMapLinkColorHintInt()
3009 // called from setMapLinkColorHint(lch) or at end of parse
3011 bo=mapCenter->first();
3019 void MapEditor::setMapLinkColorHint(LinkColorHint lch)
3022 setMapLinkColorHintInt();
3025 void MapEditor::toggleMapLinkColorHint()
3027 if (linkcolorhint==HeadingColor)
3028 linkcolorhint=DefaultColor;
3030 linkcolorhint=HeadingColor;
3032 bo=mapCenter->first();
3040 LinkColorHint MapEditor::getMapLinkColorHint()
3042 return linkcolorhint;
3045 QColor MapEditor::getMapDefLinkColor()
3047 return defLinkColor;
3050 void MapEditor::setMapDefXLinkColor(QColor col)
3055 QColor MapEditor::getMapDefXLinkColor()
3057 return defXLinkColor;
3060 void MapEditor::setMapDefXLinkWidth (int w)
3065 int MapEditor::getMapDefXLinkWidth()
3067 return defXLinkWidth;
3070 void MapEditor::selectMapLinkColor()
3072 QColor col = QColorDialog::getColor( defLinkColor, this );
3073 if ( !col.isValid() ) return;
3076 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3078 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3079 QString("Set link color to %1").arg(col.name())
3081 setMapDefLinkColor( col );
3085 void MapEditor::toggleScroll()
3087 if (selection && (typeid(*selection) == typeid(BranchObj)) )
3089 BranchObj *bo=((BranchObj*)selection);
3090 if (bo->countBranches()==0) return;
3091 if (bo->getDepth()==0) return;
3093 if (bo->isScrolled())
3105 QString ("%1 ()").arg(u),
3107 QString ("%1 ()").arg(r),
3108 QString ("%1 %2").arg(r).arg(getName(bo))
3116 void MapEditor::unScrollAll()
3119 bo=mapCenter->first();
3122 if (bo->isScrolled()) bo->toggleScroll();
3127 void MapEditor::loadFloatImage ()
3130 (typeid(*selection) == typeid(BranchObj)) ||
3131 (typeid(*selection) == typeid(MapCenterObj)) )
3133 BranchObj *bo=((BranchObj*)selection);
3135 Q3FileDialog *fd=new Q3FileDialog( this);
3136 fd->setMode (Q3FileDialog::ExistingFiles);
3137 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3138 ImagePreview *p =new ImagePreview (fd);
3139 fd->setContentsPreviewEnabled( TRUE );
3140 fd->setContentsPreview( p, p );
3141 fd->setPreviewMode( Q3FileDialog::Contents );
3142 fd->setCaption(vymName+" - " +tr("Load image"));
3143 fd->setDir (lastImageDir);
3147 if ( fd->exec() == QDialog::Accepted )
3149 // FIXME in QT4 use: lastImageDir=fd->directory();
3150 lastImageDir=QDir (fd->dirPath());
3151 QStringList flist = fd->selectedFiles();
3152 QStringList::Iterator it = flist.begin();
3154 while( it != flist.end() )
3157 bo->addFloatImage();
3158 fio=bo->getLastFloatImage();
3160 // FIXME check if load of fio was successful
3162 (LinkableMapObj*)fio,
3165 QString ("loadFloatImage (%1)").arg(*it),
3166 QString("Add floatimage %1 to %2").arg(*it).arg(getName(selection))
3168 bo->getLastFloatImage()->setOriginalFilename(fn);
3172 mapCenter->reposition();
3181 void MapEditor::saveFloatImage ()
3184 (typeid(*selection) == typeid(FloatImageObj)) )
3186 FloatImageObj *fio=((FloatImageObj*)selection);
3187 QFileDialog *fd=new QFileDialog( this);
3188 fd->setFilters (imageIO.getFilters());
3189 fd->setCaption(vymName+" - " +tr("Save image"));
3190 fd->setFileMode( QFileDialog::AnyFile );
3191 fd->setDirectory (lastImageDir);
3192 // fd->setSelection (fio->getOriginalFilename());
3196 if ( fd->exec() == QDialog::Accepted )
3198 if (QFile (fd->selectedFile()).exists() )
3200 QMessageBox mb( vymName,
3201 tr("The file %1 exists already.\n"
3202 "Do you want to overwrite it?").arg(fd->selectedFile()),
3203 QMessageBox::Warning,
3204 QMessageBox::Yes | QMessageBox::Default,
3205 QMessageBox::Cancel | QMessageBox::Escape,
3206 QMessageBox::QMessageBox::NoButton );
3208 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3209 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3212 case QMessageBox::Yes:
3215 case QMessageBox::Cancel:
3222 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
3228 void MapEditor::setFrame(const FrameType &t)
3231 (typeid(*selection) == typeid(BranchObj)) ||
3232 (typeid(*selection) == typeid(MapCenterObj)) )
3234 selection->setFrameType (t);
3235 mapCenter->reposition();
3236 selection->updateLink();
3240 void MapEditor::setIncludeImagesVer(bool b)
3243 (typeid(*selection) == typeid(BranchObj)) ||
3244 (typeid(*selection) == typeid(MapCenterObj)) )
3245 ((BranchObj*)selection)->setIncludeImagesVer(b);
3246 mapCenter->reposition();
3249 void MapEditor::setIncludeImagesHor(bool b)
3252 (typeid(*selection) == typeid(BranchObj)) ||
3253 (typeid(*selection) == typeid(MapCenterObj)) )
3254 ((BranchObj*)selection)->setIncludeImagesHor(b);
3255 mapCenter->reposition();
3258 void MapEditor::setHideLinkUnselected (bool b)
3261 (typeid(*selection) == typeid(BranchObj)) ||
3262 (typeid(*selection) == typeid(MapCenterObj)) ||
3263 (typeid(*selection) == typeid(FloatImageObj)) )
3264 selection->setHideLinkUnselected(b);
3267 void MapEditor::importDirInt(BranchObj *dst, QDir d)
3270 (typeid(*selection) == typeid(BranchObj)) ||
3271 (typeid(*selection) == typeid(MapCenterObj)) )
3275 // Traverse directories
3276 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3277 QFileInfoList list = d.entryInfoList();
3280 for (int i = 0; i < list.size(); ++i)
3283 if (fi.fileName() != "." && fi.fileName() != ".." )
3286 bo=dst->getLastBranch();
3287 bo->setHeading (fi.fileName() );
3288 bo->setColor (QColor("blue"));
3290 if ( !d.cd(fi.fileName()) )
3291 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3294 // Recursively add subdirs
3295 importDirInt (bo,d);
3301 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3302 list = d.entryInfoList();
3304 for (int i = 0; i < list.size(); ++i)
3308 bo=dst->getLastBranch();
3309 bo->setHeading (fi.fileName() );
3310 bo->setColor (QColor("black"));
3311 if (fi.fileName().right(4) == ".vym" )
3312 bo->setVymLink (fi.filePath());
3317 void MapEditor::importDir()
3320 (typeid(*selection) == typeid(BranchObj)) ||
3321 (typeid(*selection) == typeid(MapCenterObj)) )
3323 QStringList filters;
3324 filters <<"VYM map (*.vym)";
3325 QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import"));
3326 fd->setMode (QFileDialog::DirectoryOnly);
3327 fd->setFilters (filters);
3328 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
3332 if ( fd->exec() == QDialog::Accepted )
3334 BranchObj *bo=((BranchObj*)selection);
3335 importDirInt (bo,QDir(fd->selectedFile()) );
3336 mapCenter->reposition();
3343 void MapEditor::followXLink(int i)
3346 (typeid(*selection) == typeid(BranchObj)) ||
3347 (typeid(*selection) == typeid(MapCenterObj)) )
3349 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3352 selection->unselect();
3354 selection->select();
3355 ensureSelectionVisible();
3360 void MapEditor::editXLink(int i)
3363 (typeid(*selection) == typeid(BranchObj)) ||
3364 (typeid(*selection) == typeid(MapCenterObj)) )
3366 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3369 EditXLinkDialog dia;
3371 dia.setSelection(selection);
3372 if (dia.exec() == QDialog::Accepted)
3374 if (dia.useSettingsGlobal() )
3376 setMapDefXLinkColor (xlo->getColor() );
3377 setMapDefXLinkWidth (xlo->getWidth() );
3379 if (dia.deleteXLink())
3380 ((BranchObj*)selection)->deleteXLinkAt(i);
3381 //saveStateComplete("Edit xLink"); //FIXME undoCommand
3387 void MapEditor::testFunction()
3389 cout << "MapEditor::testFunction() called\n";
3392 (typeid(*selection) == typeid(BranchObj)) ||
3393 (typeid(*selection) == typeid(MapCenterObj)) )
3395 BranchObj* bo=(BranchObj*)selection;
3396 cout << bo->getHeading().ascii() <<" is scrolled: "<<bo->isScrolled()<<endl;
3401 dia.showCancelButton (true);
3402 dia.setText("This is a longer \nWarning");
3404 dia.setCaption("Warning: Flux problem");
3405 dia.setShowAgainName("/warnings/mapeditor");
3407 if (dia.exec()==QDialog::Accepted)
3408 cout << "accepted!\n";
3410 cout << "canceled!\n";
3413 /* Hide hidden stuff temporary, maybe add this as regular function somewhere
3414 if (hidemode==HideNone)
3416 setHideTmpMode (HideExport);
3417 mapCenter->calcBBoxSizeWithChilds();
3418 QRect totalBBox=mapCenter->getTotalBBox();
3419 QRect mapRect=totalBBox;
3420 QCanvasRectangle *frame=NULL;
3422 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3424 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3425 totalBBox.width(), totalBBox.height());
3426 frame=new QCanvasRectangle (mapRect,mapCanvas);
3427 frame->setBrush (QColor(white));
3428 frame->setPen (QColor(black));
3434 setHideTmpMode (HideNone);
3436 cout <<" hidemode="<<hidemode<<endl;
3440 void MapEditor::ensureSelectionVisible()
3444 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3446 if (selection->getOrientation() == OrientLeftOfCenter)
3447 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3449 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3450 ensureVisible (p.x(), p.y() );
3455 void MapEditor::updateViewCenter()
3457 // Update movingCenter, so that we can zoom comfortably later
3458 QRect rc = QRect( contentsX(), contentsY(),
3459 visibleWidth(), visibleHeight() );
3460 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3461 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3462 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3465 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3467 // Lineedits are already closed by preceding
3468 // mouseEvent, we don't need to close here.
3470 QPoint p = inverseWorldMatrix().map(e->pos());
3471 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3474 { // MapObj was found
3475 if (selection != lmo)
3477 // select the MapObj
3478 if (selection) selection->unselect();
3480 selection->select();
3486 if (typeid(*selection)==typeid(BranchObj) ||
3487 typeid(*selection)==typeid(MapCenterObj) )
3489 // Context Menu on branch or mapcenter
3491 branchContextMenu->popup(e->globalPos() );
3493 if (typeid(*selection)==typeid(FloatImageObj))
3495 // Context Menu on floatimage
3497 floatimageContextMenu->popup(e->globalPos() );
3501 { // No MapObj found, we are on the Canvas itself
3502 // Context Menu on Canvas
3504 canvasContextMenu->popup(e->globalPos() );
3509 void MapEditor::keyPressEvent(QKeyEvent* e)
3511 if (e->modifiers() && Qt::ControlModifier)
3513 switch (mainWindow->getModMode())
3516 setCursor (PickColorCursor);
3519 setCursor (CopyCursor);
3522 setCursor (XLinkCursor);
3525 setCursor (Qt::ArrowCursor);
3531 void MapEditor::keyReleaseEvent(QKeyEvent* e)
3533 if (!(e->modifiers() && Qt::ControlModifier))
3534 setCursor (Qt::ArrowCursor);
3537 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3539 // Ignore right clicks, these will go to context menus
3540 if (e->button() == Qt::RightButton )
3546 QPoint p = inverseWorldMatrix().map(e->pos());
3547 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3551 //Take care of clickdesystem flags _or_ modifier modes
3553 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3554 typeid(*lmo)==typeid(MapCenterObj) ))
3556 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3557 if (!foname.isEmpty())
3559 // systemFlag clicked
3563 if (e->state() & Qt::ControlModifier)
3564 mainWindow->editOpenURLTab();
3566 mainWindow->editOpenURL();
3568 else if (foname=="vymLink")
3570 mainWindow->editOpenVymLink();
3571 // tabWidget may change, better return now
3572 // before segfaulting...
3573 } else if (foname=="note")
3574 mainWindow->windowToggleNoteEditor();
3575 else if (foname=="hideInExport")
3580 // No system flag clicked, take care of modmodes
3582 // Special case: CTRL is pressed
3583 if (e->state() & Qt::ControlModifier)
3585 if (mainWindow->getModMode()==ModModeColor)
3588 setCursor (PickColorCursor);
3591 if (mainWindow->getModMode()==ModModeXLink)
3593 BranchObj *bo_begin=NULL;
3595 bo_begin=(BranchObj*)(lmo);
3598 ((typeid(*selection) == typeid(BranchObj)) ||
3599 (typeid(*selection) == typeid(MapCenterObj))) )
3600 bo_begin=(BranchObj*)selection;
3604 linkingObj_src=bo_begin;
3605 tmpXLink=new XLinkObj (mapCanvas);
3606 tmpXLink->setBegin (bo_begin);
3607 tmpXLink->setEnd (p);
3608 tmpXLink->setColor(defXLinkColor);
3609 tmpXLink->setWidth(defXLinkWidth);
3610 tmpXLink->updateXLink();
3611 tmpXLink->setVisibility (true);
3619 // Left Button Move Branches
3620 if (e->button() == Qt::LeftButton )
3622 movingObj_start.setX( p.x() - selection->x() );
3623 movingObj_start.setY( p.y() - selection->y() );
3624 movingObj_orgPos.setX (lmo->x() );
3625 movingObj_orgPos.setY (lmo->y() );
3626 movingObj_orgRelPos=lmo->getRelPos();
3628 // If modMode==copy, then we want to "move" the _new_ object around
3629 // then we need the offset from p to the _old_ selection, because of tmp
3630 if (mainWindow->getModMode()==ModModeCopy &&
3631 e->state() & Qt::ControlModifier)
3633 if (typeid(*selection)==typeid(BranchObj) )
3636 mapCenter->addBranch ((BranchObj*)selection);
3638 selection=mapCenter->getLastBranch();
3639 selection->select();
3640 mapCenter->reposition();
3643 movingObj=selection;
3645 // Middle Button Toggle Scroll
3646 // (On Mac OS X this won't work, but we still have
3647 // a button in the toolbar)
3648 if (e->button() == Qt::MidButton )
3652 { // No MapObj found, we are on the Canvas itself
3653 // Left Button move Pos of CanvasView
3654 if (e->button() == Qt::LeftButton )
3656 movingObj=NULL; // move Content not Obj
3657 movingObj_start=e->globalPos();
3658 movingCont_start=QPoint (contentsX(), contentsY() );
3659 movingVec=QPoint(0,0);
3660 setCursor(HandOpenCursor);
3665 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3667 QPoint p = inverseWorldMatrix().map(e->pos());
3669 // Move the selected MapObj
3670 if ( selection && movingObj)
3672 // To avoid jumping of the CanvasView, only
3673 // ensureSelectionVisible, if not tmp linked
3674 if (!selection->hasParObjTmp())
3675 ensureSelectionVisible ();
3677 // Now move the selection, but add relative position
3678 // (movingObj_start) where selection was chosen with
3679 // mousepointer. (This avoids flickering resp. jumping
3680 // of selection back to absPos)
3682 LinkableMapObj *lmosel;
3683 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3685 // Check if we could link
3686 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3689 if (typeid(*selection) == typeid(FloatImageObj))
3691 FloatObj *fo=(FloatObj*)selection;
3692 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3696 // Relink float to new mapcenter or branch, if shift is pressed
3697 // Only relink, if selection really has a new parent
3698 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
3699 ( (typeid(*lmo)==typeid(BranchObj)) ||
3700 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3701 ( lmo != fo->getParObj())
3704 if (typeid(*fo) == typeid(FloatImageObj))
3707 //saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3708 FloatImageObj *fio=(FloatImageObj*)(fo);
3709 ((BranchObj*)(lmo))->addFloatImage (fio);
3711 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3712 fio=((BranchObj*)(lmo))->getLastFloatImage();
3715 selection=(LinkableMapObj*)(fio);
3716 selection->select();
3717 movingObj=(MapObj*)(fio);
3721 { // selection != a FloatObj
3722 if (lmosel->getDepth()==0)
3725 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3726 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3728 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3729 mapCenter->updateRelPositions();
3732 if (lmosel->getDepth()==1)
3735 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3736 lmosel->setRelPos();
3739 // Move ordinary branch
3740 if (lmosel->getOrientation() == OrientLeftOfCenter)
3741 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3742 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3743 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3745 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3747 // reposition subbranch
3748 lmosel->reposition();
3750 if (lmo && (lmo!=selection) &&
3751 (typeid(*lmo) == typeid(BranchObj) ||
3752 (typeid(*lmo) == typeid(MapCenterObj) )
3755 if (e->modifiers()==Qt::ControlModifier)
3757 // Special case: CTRL to link below lmo
3758 lmosel->setParObjTmp (lmo,p,+1);
3760 else if (e->modifiers()==Qt::ShiftModifier)
3761 lmosel->setParObjTmp (lmo,p,-1);
3763 lmosel->setParObjTmp (lmo,p,0);
3766 lmosel->unsetParObjTmp();
3770 } // no FloatImageObj
3774 } // selection && moving_obj
3776 // Draw a link from one branch to another
3779 tmpXLink->setEnd (p);
3780 tmpXLink->updateXLink();
3784 if (!movingObj && !pickingColor &&!drawingLink)
3786 QPoint p=e->globalPos();
3787 movingVec.setX(-p.x() + movingObj_start.x() );
3788 movingVec.setY(-p.y() + movingObj_start.y() );
3789 setContentsPos( movingCont_start.x() + movingVec.x(),
3790 movingCont_start.y() + movingVec.y());
3797 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3799 LinkableMapObj *dst;
3800 // Have we been picking color?
3804 setCursor (Qt::ArrowCursor);
3805 // Check if we are over another branch
3806 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3807 if (dst && selection)
3809 if (e->state() & Qt::ShiftModifier)
3811 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3812 ((BranchObj*)selection)->setLinkColor ();
3816 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3817 ((BranchObj*)selection)->setLinkColor ();
3823 // Have we been drawing a link?
3827 // Check if we are over another branch
3828 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3829 if (dst && selection)
3831 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3832 tmpXLink->updateXLink();
3833 tmpXLink->activate();
3834 //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //FIXME undoCommand
3843 // Have we been moving something?
3844 if ( selection && movingObj )
3846 if(typeid(*selection)==typeid (FloatImageObj))
3848 // Moved FloatObj. Maybe we need to reposition
3849 FloatImageObj *fo=(FloatImageObj*)selection;
3850 QString pold=qpointToString(movingObj_orgRelPos);
3851 QString pnow=qpointToString(fo->getRelPos());
3857 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow));
3859 // FIXME Why calling parObj here?
3860 selection->getParObj()->requestReposition();
3861 mapCenter->reposition();
3864 // Check if we are over another branch, but ignore
3865 // any found LMOs, which are FloatObjs
3866 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3867 ((LinkableMapObj*)selection) );
3869 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3872 if (typeid(*selection) == typeid(MapCenterObj) )
3873 { // The MapCenter was moved
3874 cout << "FIXME missing savestate...\n";
3877 if (typeid(*selection) == typeid(BranchObj) )
3878 { // A branch was moved
3880 // save the position in case we link to mapcenter
3881 QPoint savePos=QPoint (selection->x(),selection->y() );
3883 // Reset the temporary drawn link to the original one
3884 ((LinkableMapObj*)selection)->unsetParObjTmp();
3886 // For Redo we may need to save original selection
3887 QString preSelStr=selection->getSelectString();
3892 BranchObj* bsel=(BranchObj*)selection;
3893 BranchObj* bdst=(BranchObj*)dst;
3895 QString preParStr=(bsel->getParObj())->getSelectString();
3896 QString preNum=QString::number (bsel->getNum(),10);
3897 QString preDstParStr;
3899 if (e->state() & Qt::ShiftModifier && dst->getParObj())
3901 preDstParStr=dst->getParObj()->getSelectString();
3902 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
3904 if (e->state() & Qt::ControlModifier && dst->getParObj())
3907 preDstParStr=dst->getParObj()->getSelectString();
3908 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
3911 preDstParStr=dst->getSelectString();
3912 bsel->moveBranchTo (bdst,-1);
3913 if (dst->getDepth()==0) bsel->move (savePos);
3915 QString postSelStr=selection->getSelectString();
3916 QString postNum=QString::number (bsel->getNum(),10);
3918 QString undoCom="linkBranchToPos (\""+
3919 preParStr+ "\"," + preNum +"," +
3920 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
3922 QString redoCom="linkBranchToPos (\""+
3923 preDstParStr + "\"," + postNum + "," +
3924 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
3929 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
3931 if (selection->getDepth()==1)
3933 // The select string might be different _after_ moving around.
3934 // Therefor reposition and then use string of old selection, too
3935 mapCenter->reposition();
3937 QString ps=qpointToString ( ((BranchObj*)selection)->getRelPos() );
3939 selection->getSelectString(), "moveRel "+qpointToString(movingObj_orgRelPos),
3940 preSelStr, "moveRel "+ps,
3941 QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps));
3944 // Draw the original link, before selection was moved around
3945 mapCenter->reposition();
3947 // Finally resize canvas, if needed
3952 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
3955 // maybe we moved View: set old cursor
3956 setCursor (Qt::ArrowCursor);
3960 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3962 if (e->button() == Qt::LeftButton )
3964 QPoint p = inverseWorldMatrix().map(e->pos());
3965 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3966 if (lmo) { // MapObj was found
3967 // First select the MapObj than edit heading
3968 if (selection) selection->unselect();
3970 selection->select();
3971 mainWindow->editHeading();
3976 void MapEditor::resizeEvent (QResizeEvent* e)
3978 Q3CanvasView::resizeEvent( e );
3982 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3985 (typeid(*selection) == typeid(BranchObj)) ||
3986 (typeid(*selection) == typeid(MapCenterObj)))
3988 if (event->mimeData()->hasFormat("image/png"))
3990 cout <<"found png in dragenterevent\n";
3995 if (event->mimeData()->hasFormat("text/uri-list"))
3997 cout <<"found uri-list in dragenterevent\n";
4003 // If QImageDrag can decode mime type
4004 if (Q3ImageDrag::canDecode(event))
4006 cout << "dragenterevent q3imagedrag\n";
4011 // If image are dragged from firefox
4012 if (event->mimeData()->hasFormat("application/x-moz-file-promise-url") &&
4013 event->mimeData()->hasFormat("application/x-moz-nativeimage")) {
4014 event->accept(true);
4015 cout << "dragenterevent firefox\n";
4019 // If QUriDrag can decode mime type
4020 if (Q3UriDrag::canDecode(event)) {
4022 cout << "accepted uri drag\n";
4025 // If Uri are dragged from firefox
4026 if (event->provides("_NETSCAPE_URL")){
4028 cout << "dragenterevent NETSCAPE\n";
4032 // If QTextDrag can decode mime type
4033 if (Q3TextDrag::canDecode(event)) {
4035 cout << "dragenterevent textdrag\n";
4045 /* FIXME needed in QT4? bool isUnicode16(const QByteArray &d)
4047 // TODO: make more precise check for unicode 16.
4048 // Guess unicode16 if any of second bytes are zero
4049 unsigned int length = max(0,d.size()-2)/2;
4050 for (unsigned int i = 0; i<length ; i++)
4051 if (d.at(i*2+1)==0) return true;
4056 void MapEditor::contentsDropEvent(QDropEvent *event)
4059 (typeid(*selection) == typeid(BranchObj)) ||
4060 (typeid(*selection) == typeid(MapCenterObj)))
4068 if (event->mimeData()->hasFormat("image/png"))
4070 event->acceptProposedAction();
4071 addFloatImageInt(event->mimeData()->imageData().value<QPixmap>());
4072 cout << "Drop png...\n";
4073 } else if (event->mimeData()->hasFormat("application/x-moz-file-promise-url")&&
4074 event->mimeData()->hasFormat("application/x-moz-nativeimage"))
4076 cout << "Drop Mozilla...\n";
4077 // Contains url to the img src in unicode16
4078 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
4079 QString url = QString((const QChar*)d.data(),d.size()/2);
4080 //FIXME fetchImage(url);
4081 event->acceptProposedAction();
4083 } else if (event->mimeData()->hasUrls())
4085 urls=event->mimeData()->urls();
4086 } /*else if (event->provides ("_NETSCAPE_URL"))
4087 { // Uris provided by Mozilla
4088 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
4091 } else if (event->provides("text/html")) {
4093 // Handels text mime types
4094 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
4095 QByteArray d = event->encodedData("text/html");
4098 text = QString((const QChar*)d.data(),d.size()/2);
4102 textEditor->setText(text);
4106 } else if (event->provides("text/plain")) {
4107 QByteArray d = event->encodedData("text/plain");
4110 text = QString((const QChar*)d.data(),d.size()/2);
4114 textEditor->setText(text);
4121 for (int i=0; i<urls.size(); ++i)
4123 cout << "Found URL: "<<urls.at(i).toString().ascii()<<endl;
4125 /* FIXME not ported yet QSTRINGLIST has no next...
4132 for (const char* u=uris.first(); u; u=uris.next())
4134 bo=((BranchObj*)selection)->addBranch();
4137 s=Q3UriDrag::uriToLocalFile(u);
4140 QString file = QDir::convertSeparators(s);
4141 heading = QFileInfo(file).baseName();
4143 if (file.endsWith(".vym", false))
4144 bo->setVymLink(file);
4153 if (!heading.isEmpty())
4154 bo->setHeading(heading);
4164 //FIXME saveState has to be called earlier for each of the drops...
4165 //saveStateComplete("Drop Event"); //TODO undo Command
4166 mapCenter->reposition();
4173 void MapEditor::addFloatImageInt (const QPixmap &img)
4176 (typeid(*selection) == typeid(BranchObj)) ||
4177 (typeid(*selection) == typeid(MapCenterObj)) )
4179 BranchObj *bo=((BranchObj*)selection);
4180 qWarning ("Warning: Image added by drop event: no undo/redo so far.");
4181 //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
4182 //QString fn=fd->selectedFile();
4183 //lastImageDir=fn.left(fn.findRev ("/"));
4184 FloatImageObj *fio=bo->addFloatImage();
4186 fio->setOriginalFilename("Image added by Drag and Drop");
4187 mapCenter->reposition();
4194 //void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
4195 /* FIXME not needed in QT4
4197 if (!imageBuffer) imageBuffer = new QBuffer();
4198 if (!imageBuffer->isOpen()) {
4199 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
4201 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
4205 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
4207 if (nop->state()==Q3NetworkProtocol::StDone) {
4208 QPixmap img(imageBuffer->buffer());
4209 addFloatImageInt (img);
4213 imageBuffer->close();
4215 imageBuffer->close();
4222 void MapEditor::fetchImage(const QString &url)
4225 urlOperator->stop();
4226 disconnect(urlOperator);
4230 urlOperator = new Q3UrlOperator(url);
4231 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
4232 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
4234 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
4235 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));