3 #include <QActionGroup>
5 #include <QColorDialog>
6 #include <QContextMenuEvent>
8 #include <QDragEnterEvent>
11 #include <QInputDialog>
12 #include <QMessageBox>
13 #include <QMouseEvent>
17 #include <QResizeEvent>
18 #include <QTextStream>
21 #include <q3dragobject.h>
22 #include <q3urloperator.h>
23 #include <q3networkprotocol.h>
24 #include <q3paintdevicemetrics.h>
25 #include <q3filedialog.h>
34 #include "editxlinkdialog.h"
36 #include "extrainfodialog.h"
38 #include "linkablemapobj.h"
39 #include "mainwindow.h"
41 #include "texteditor.h"
42 #include "warningdialog.h"
46 extern TextEditor *textEditor;
47 extern int statusbarTime;
48 extern Main *mainWindow;
49 extern QString tmpVymDir;
50 extern QString clipboardDir;
51 extern bool clipboardEmpty;
52 extern FlagRowObj *systemFlagsDefault;
53 extern FlagRowObj *standardFlagsDefault;
55 extern Q3PtrList <QAction> actionListBranches;
57 extern QAction *actionFileSave;
58 extern QAction *actionEditUndo;
59 extern QAction *actionEditRedo;
60 extern QAction *actionEditCopy;
61 extern QAction *actionEditCut;
62 extern QAction *actionEditPaste;
63 extern QAction *actionEditMoveUp;
64 extern QAction *actionEditMoveDown;
65 extern QAction *actionEditToggleScroll;
66 extern QAction *actionEditOpenURL;
67 extern QAction *actionEditOpenURLTab;
68 extern QAction *actionEditURL;
69 extern QAction *actionEditHeading2URL;
70 extern QAction *actionEditBugzilla2URL;
71 extern QAction *actionEditFATE2URL;
72 extern QAction *actionEditOpenVymLink;
73 extern QAction *actionEditVymLink;
74 extern QAction *actionEditDeleteVymLink;
75 extern QAction *actionEditToggleHideExport;
76 extern QAction *actionEditHeading;
77 extern QAction *actionEditDelete;
78 extern QAction *actionEditAddBranch;
79 extern QAction *actionEditAddBranchAbove;
80 extern QAction *actionEditAddBranchBelow;
81 extern QAction *actionEditRemoveBranchHere;
82 extern QAction *actionEditRemoveChilds;
83 extern QAction *actionEditImportAdd;
84 extern QAction *actionEditImportReplace;
85 extern QAction *actionEditSaveBranch;
86 extern QAction *actionEditSelectFirst;
87 extern QAction *actionEditSelectLast;
88 extern QAction *actionEditLoadImage;
90 extern QAction* actionFormatPickColor;
91 extern QAction* actionFormatColorBranch;
92 extern QAction* actionFormatColorSubtree;
93 extern QAction *actionFormatLinkColorHint;
94 extern QAction *actionFormatBackColor;
95 extern QAction *actionFormatLinkColor;
97 extern QActionGroup* actionGroupModModes;
98 extern QAction* actionModModeColor;
99 extern QAction* actionModModeLink;
100 extern QAction* actionModModeCopy;
102 extern QActionGroup *actionGroupFormatFrameTypes;
103 extern QAction *actionFormatFrameNone;
104 extern QAction *actionFormatFrameRectangle;
106 extern QActionGroup *actionGroupFormatLinkStyles;
107 extern QAction *actionFormatIncludeImagesVer;
108 extern QAction *actionFormatIncludeImagesHor;
109 extern QAction *actionFormatHideLinkUnselected;
110 extern QAction *actionFormatLinkStyleLine;
111 extern QAction *actionFormatLinkStyleParabel;
112 extern QAction *actionFormatLinkStylePolyLine;
113 extern QAction *actionFormatLinkStylePolyParabel;
115 extern QAction *actionViewToggleNoteEditor;
117 extern QAction *actionSettingsAutoedit;
118 extern QAction *actionSettingsAutoselectHeading;
119 extern QAction *actionSettingsAutoselectText;
120 extern QAction *actionSettingsUseFlagGroups;
122 extern QMenu* branchContextMenu;
123 extern QMenu* branchAddContextMenu;
124 extern QMenu* branchRemoveContextMenu;
125 extern QMenu* branchLinksContextMenu;
126 extern QMenu* branchXLinksContextMenuEdit;
127 extern QMenu* branchXLinksContextMenuFollow;
128 extern QMenu* floatimageContextMenu;
129 extern QMenu* saveImageFormatMenu;
130 extern QMenu* canvasContextMenu;
131 extern QMenu* lastMapsMenu;
132 extern QMenu* importMenu;
133 extern QMenu* exportMenu;
136 extern Settings settings;
137 extern ImageIO imageIO;
139 extern QString iconPath;
140 extern QDir vymBaseDir;
141 extern QDir lastImageDir;
143 int MapEditor::mapNum=0; // make instance
145 ///////////////////////////////////////////////////////////////////////
146 ///////////////////////////////////////////////////////////////////////
147 MapEditor::MapEditor(
148 QWidget* parent, bool interactive, const char* name, Qt::WFlags f) :
149 Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
151 //cout << "Constructor ME "<<this<<endl;
154 viewport()->setAcceptDrops(true);
156 mapCanvas = new Q3Canvas(width(),height());
157 mapCanvas->setAdvancePeriod(30);
158 mapCanvas->setBackgroundColor (Qt::white);
160 setCanvas (mapCanvas);
162 // Always show scroll bars (automatic would flicker sometimes)
163 setVScrollBarMode ( Q3ScrollView::AlwaysOn );
164 setHScrollBarMode ( Q3ScrollView::AlwaysOn );
166 mapCenter = new MapCenterObj(mapCanvas);
167 mapCenter->setVisibility (true);
168 mapCenter->setMapEditor (this);
169 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
170 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
174 actColor=Qt::black; setColor (actColor);
175 defLinkColor=QColor (0,0,255);
176 defXLinkColor=QColor (180,180,180);
177 linkcolorhint=DefaultColor;
178 linkstyle=StylePolyParabel;
180 // Create bitmap cursors, platform dependant
181 #if defined(Q_OS_MACX)
182 handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png"),1,1 );
183 pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 );
185 handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
186 pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
198 xelection.setMapCenter (mapCenter);
201 defXLinkColor=QColor (230,230,230);
209 fileName=tr("unnamed");
212 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",5);
213 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
215 // Initialize find routine
222 blockReposition=false;
223 blockSaveState=false;
227 isInteractive=interactive; // FIXME still needed?
229 // Create temporary files
232 // Initially set movingCentre
235 mapCenter->reposition(); // for positioning heading
237 // Initialize history window;
238 historyWindow.setME(this);
239 historyWindow.setStepsTotal(stepsTotal);
240 historyWindow.update (undoSet);
243 MapEditor::~MapEditor()
245 if (imageBuffer) delete imageBuffer;
251 //cout <<"Destructor MapEditor\n";
254 //settings.writeEntry( "/mapeditor/editmode/autoselect", );
258 QColor MapEditor::color()
263 QColor MapEditor::backgroundColor()
265 return mapCanvas->backgroundColor();
268 MapCenterObj* MapEditor::getMapCenter()
273 Q3Canvas* MapEditor::getCanvas()
278 void MapEditor::adjustCanvasSize()
280 // To adjust the canvas to map, viewport size and position, we have to
281 // do some coordinate magic...
283 // Get rectangle of (scroll-)view.
284 // We want to be in canvas coords, so
285 // we map. Important if view is zoomed...
286 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
287 visibleWidth(), visibleHeight()) );
289 // Now we need the bounding box of view AND map to calc the correct canvas size.
290 // Why? Because if the map itself is moved out of view, the view has to be enlarged
291 // to avoid jumping aroung...
292 QRect map=mapCenter->getTotalBBox();
294 // right edge - left edge
295 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
296 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
299 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
300 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
303 // move the map on canvas (in order to not move it on screen) this is neccessary
304 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
305 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
306 // to scroll to an empty area of canvas to the left.
307 // b) if topleft corner of map left of or above topleft of canvas
311 if (cw > mapCanvas->width() )
313 if (map.x()<0) dx=-map.x();
315 if (cw < mapCanvas->width() )
316 dx=-min (view.x(),map.x());
317 if (ch > mapCanvas->height() )
319 if (map.y()<0) dy=-map.y();
321 if (ch < mapCanvas->height() )
323 dy=-min (view.y(),map.y());
325 // We really have to resize now. Let's go...
326 mapCanvas->resize (cw,ch);
327 if ( (dx!=0) || (dy!=0) )
329 mapCenter->moveAllBy(dx,dy);
330 mapCenter->reposition();
331 // mapCenter->positionBBox(); // To move float
333 // scroll the view (in order to not move map on screen)
339 bool MapEditor::isRepositionBlocked()
341 return blockReposition;
344 QString MapEditor::getName (LinkableMapObj *lmo)
347 if (!lmo) return QString("Error: NULL has no name!");
349 if ((typeid(*lmo) == typeid(BranchObj) ||
350 typeid(*lmo) == typeid(MapCenterObj)))
353 s=(((BranchObj*)lmo)->getHeading());
354 if (s=="") s="unnamed";
355 return QString("branch (%1)").arg(s);
356 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
358 if ((typeid(*lmo) == typeid(FloatImageObj) ))
359 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
360 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
361 return QString("Unknown type has no name!");
364 void MapEditor::makeTmpDirs()
366 // Create unique temporary directories
367 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
368 histPath=QDir::convertSeparators (tmpMapDir+"/history");
373 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSel)
375 // tmpdir temporary directory to which data will be written
376 // prefix mapname, which will be appended to images etc.
377 // writeflags Only write flags for "real" save of map, not undo
378 // offset offset of bbox of whole map in canvas.
379 // Needed for XML export
395 ls="StylePolyParabel";
399 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
401 if (linkcolorhint==HeadingColor)
402 colhint=attribut("linkColorHint","HeadingColor");
404 QString mapAttr=attribut("version",__VYM_VERSION);
406 mapAttr+= attribut("author",mapCenter->getAuthor()) +
407 attribut("comment",mapCenter->getComment()) +
408 attribut("date",mapCenter->getDate()) +
409 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
410 attribut("linkStyle", ls ) +
411 attribut("linkColor", defLinkColor.name() ) +
412 attribut("defXLinkColor", defXLinkColor.name() ) +
413 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
415 s+=beginElement("vymmap",mapAttr);
418 // Find the used flags while traversing the tree
419 standardFlagsDefault->resetUsedCounter();
421 // Reset the counters before saving
422 FloatImageObj (mapCanvas).resetSaveCounter();
424 // Build xml recursivly
426 // Save complete map, if saveSel not set
427 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
430 if ( typeid(*saveSel) == typeid(BranchObj) )
432 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
433 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
435 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
437 else if (selection && typeid(*selection)==typeid(BranchObj))
438 // Save selected branch is saved from mainwindow //FIXME maybe use "subtree" above?
439 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
442 // Save local settings
443 s+=settings.getXMLData (destPath);
446 if (selection && !saveSel )
447 s+=valueElement("select",selection->getSelectString());
450 s+=endElement("vymmap");
453 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
457 void MapEditor::saveStateComplete(const QString &comment)
459 // Save complete map, Undo will replace whole map
460 saveState (CompleteMap,
467 void MapEditor::saveStatePart(LinkableMapObj *undoSel, const QString &comment)
469 // save the selected part of the map, Undo will replace part of map
470 QString undoSelection="";
471 if (undoSel) undoSelection=undoSel->getSelectString();
473 saveState (PartOfMap,
480 void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment)
482 // selection does not change during action,
483 // so just save commands for undo and redo
484 // and use current selection
487 if (selection) sel=selection->getSelectString();
489 saveState (UndoCommand,
496 void MapEditor::saveStateComData(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel)
498 QString redoSelection="";
499 if (redoSel) redoSelection=redoSel->getSelectString();
500 QString undoSelection="";
501 if (undoSel) undoSelection=undoSel->getSelectString();
503 saveState (UndoCommand,
505 redoSelection, "FIXME-redoCom", //FIXME
510 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
512 // "Normal" savestate: save commands, selections and comment
513 // so just save commands for undo and redo
514 // and use current selection
516 QString redoSelection="";
517 if (redoSel) redoSelection=redoSel->getSelectString();
518 QString undoSelection="";
519 if (undoSel) undoSelection=undoSel->getSelectString();
521 saveState (UndoCommand,
528 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
530 // "Normal" savestate: save commands, selections and comment
531 // so just save commands for undo and redo
532 // and use current selection
533 saveState (UndoCommand,
541 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
545 if (blockSaveState) return;
547 /* TODO remove after testing
549 cout << "ME::saveState() begin"<<endl;
553 int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
554 int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
555 int curStep=undoSet.readNumEntry ("/history/curStep",0);
556 // Find out current undo directory
557 if (undosAvail<stepsTotal) undosAvail++;
559 if (curStep>stepsTotal) curStep=1;
562 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
563 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
565 // Create bakMapDir if not available
568 makeSubDirs (bakMapDir);
570 // Save depending on how much needs to be saved
574 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel);
576 QString undoCommand="";
577 if (savemode==UndoCommand)
581 else if (savemode==PartOfMap )
583 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
586 undoCommand="undoMap (\""+bakMapPath+"\")";
588 if (!backupXML.isEmpty())
589 // Write XML Data to disk
590 saveStringToDisk (QString(bakMapPath),backupXML);
592 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
593 undoSet.setEntry ("/history/curStep",QString::number(curStep));
594 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
595 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
596 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
597 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
598 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
599 undoSet.writeSettings(histPath);
601 /* TODO remove after testing
603 //cout << " into="<< histPath.toStdString()<<endl;
604 cout << " stepsTotal="<<stepsTotal<<
605 ", undosAvail="<<undosAvail<<
606 ", redosAvail="<<redosAvail<<
607 ", curStep="<<curStep<<endl;
608 cout << " ---------------------------"<<endl;
609 cout << " comment="<<comment.toStdString()<<endl;
610 cout << " undoCom="<<undoCommand.toStdString()<<endl;
611 cout << " undoSel="<<undoSelection.toStdString()<<endl;
612 cout << " redoCom="<<redoCom.toStdString()<<endl;
613 cout << " redoSel="<<redoSelection.toStdString()<<endl;
614 cout << " ---------------------------"<<endl;
616 historyWindow.update (undoSet);
619 void MapEditor::parseAtom(const QString &atom)
626 // Split string s into command and parameters
627 api.parseCommand (atom);
628 QString com=api.command();
631 if (com=="moveBranchUp")
633 else if (com=="moveBranchDown")
635 else if (com=="move")
637 if (api.checkParamCount(2) && selection )
647 else if (com=="moveRel")
649 if (api.checkParamCount(2) && selection )
655 if (ok) moveRel (x,y);
659 else if (com=="delete")
661 if (api.checkParamCount(1) && selection )
663 s=api.parString(ok,0);
664 if (ok &&select (s)) deleteSelection();
667 else if (com=="addBranch")
669 if (api.checkParamCount(1) && selection )
672 if (ok ) addNewBranchInt (y);
675 else if (com=="linkBranchToPos")
677 if (selection && typeid(*selection) == typeid(BranchObj) )
679 if (api.checkParamCount(4))
681 // 0 selectstring of parent
682 // 1 num in parent (for branches)
683 // 2,3 x,y of mainbranch or mapcenter
684 s=api.parString(ok,0);
685 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
688 if (typeid(*dst) == typeid(BranchObj) )
690 // Get number in parent
693 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
694 } else if (typeid(*dst) == typeid(MapCenterObj) )
696 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
697 // Get coordinates of mainbranch
702 if (ok) ((BranchObj*)selection)->move (x,y);
708 } else if (com=="setHeading")
710 if (api.checkParamCount(1))
712 s=api.parString (ok,0);
716 } else if (com=="setURL")
718 if (api.checkParamCount(1))
720 s=api.parString (ok,0);
721 if (ok) setURLInt(s);
723 } else if (com=="setVymLink")
725 if (api.checkParamCount(1))
727 s=api.parString (ok,0);
728 if (ok) setVymLinkInt(s);
731 else if (com=="setFlag")
733 if (selection && typeid(*selection) == typeid(BranchObj) )
735 if (api.checkParamCount(1) )
737 s=api.parString(ok,0);
740 BranchObj* bo=(BranchObj*)selection;
741 bo->activateStandardFlag(s);
742 bo->updateFlagsToolbar();
747 else if (com=="unsetFlag")
749 if (selection && typeid(*selection) == typeid(BranchObj) )
751 if (api.checkParamCount(1) )
753 s=api.parString(ok,0);
756 BranchObj* bo=(BranchObj*)selection;
757 bo->deactivateStandardFlag(s);
758 bo->updateFlagsToolbar();
763 // Internal commands, used for undo etc.
764 else if (com==QString("undoMap"))
766 if (api.checkParamCount(1))
767 undoXML("",api.parString (ok,0));
768 } else if (com==QString("undoPart"))
770 if (api.checkParamCount(2))
772 s=api.parString (ok,0); // undo selection
773 t=api.parString (ok,1); // backup dir
776 } else if (com=="select")
778 if (api.checkParamCount(1))
780 s=api.parString(ok,0);
786 api.setError ("Unknown command in: "+atom);
792 // TODO Error handling
793 qWarning("MapEditor::parseAtom: Error!");
794 qWarning(api.errorDesc());
798 void MapEditor::toggleHistoryWindow()
800 if (historyWindow.isVisible())
801 historyWindow.hide();
803 historyWindow.show();
807 bool MapEditor::isDefault()
812 bool MapEditor::isUnsaved()
817 bool MapEditor::hasChanged()
822 void MapEditor::setChanged()
827 actionEditUndo->setEnabled (true);
828 actionFileSave->setEnabled (true);
832 void MapEditor::closeMap()
834 // Unselect before disabling the toolbar actions
835 if (selection) selection->unselect();
843 void MapEditor::setFilePath(QString fname)
845 setFilePath (fname,fname);
848 void MapEditor::setFilePath(QString fname, QString destname)
850 if (fname.isEmpty() || fname=="")
857 filePath=fname; // becomes absolute path
858 fileName=fname; // gets stripped of path
859 destPath=destname; // needed for vymlinks
861 // If fname is not an absolute path, complete it
862 filePath=QDir(fname).absPath();
863 fileDir=filePath.left (1+filePath.findRev ("/"));
865 // Set short name, too. Search from behind:
866 int i=fileName.findRev("/");
867 if (i>=0) fileName=fileName.remove (0,i+1);
869 // Forget the .vym (or .xml) for name of map
870 mapName=fileName.left(fileName.findRev(".",-1,true) );
872 // Adjust history window
873 historyWindow.setCaption (__VYM " - " +tr("History for ")+fileName);
877 QString MapEditor::getFilePath()
882 QString MapEditor::getFileName()
887 QString MapEditor::getMapName()
892 QString MapEditor::getDestPath()
897 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
899 ErrorCode err=success;
903 if (selection) selection->unselect();
906 mapCenter->setMapEditor(this);
907 // (map state is set later at end of load...)
910 saveStatePart(selection,"Load map");
914 mapBuilderHandler handler;
917 // I am paranoid: file should exist anyway
918 // according to check in mainwindow.
921 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
922 tr("Couldn't open map " +fname)+".");
926 blockReposition=true;
927 QXmlInputSource source( file);
928 QXmlSimpleReader reader;
929 reader.setContentHandler( &handler );
930 reader.setErrorHandler( &handler );
931 handler.setMapEditor( this );
932 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
933 handler.setInputFile (file.name());
934 handler.setLoadMode (lmode);
936 bool ok = reader.parse( source );
937 blockReposition=false;
938 blockSaveState=false;
942 mapCenter->reposition();
952 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
953 tr( handler.errorProtocol() ) );
955 // Still return "success": the map maybe at least
956 // partially read by the parser
963 int MapEditor::save (const SaveMode &savemode)
967 // The SaveMode UndoCommand is not supported here
968 if (savemode==UndoCommand) return 1;
970 // Create mapName and fileDir
971 makeSubDirs (fileDir);
975 fname=mapName+".xml";
977 // use name given by user, even if he chooses .doc
982 if (savemode==CompleteMap || selection==NULL)
983 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
985 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
987 if (!saveStringToDisk(fileDir+fname,saveFile))
994 actionFileSave->setEnabled(false);
1000 void MapEditor::setZipped (bool z)
1005 bool MapEditor::saveZipped ()
1010 void MapEditor::print()
1014 printer = new QPrinter;
1015 printer->setColorMode (QPrinter::Color);
1016 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1019 QRect totalBBox=mapCenter->getTotalBBox();
1021 // Try to set orientation automagically
1022 // Note: Interpretation of generated postscript is amibiguous, if
1023 // there are problems with landscape mode, see
1024 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1026 if (totalBBox.width()>totalBBox.height())
1027 // recommend landscape
1028 printer->setOrientation (QPrinter::Landscape);
1030 // recommend portrait
1031 printer->setOrientation (QPrinter::Portrait);
1033 if ( printer->setup(this) )
1034 // returns false, if printing is canceled
1036 QPainter pp(printer);
1038 // Don't print the visualisation of selection
1039 LinkableMapObj *oldselection=NULL;
1042 oldselection=selection;
1043 selection->unselect();
1046 // Handle sizes of map and paper:
1048 // setWindow defines which part of the canvas will be transformed
1049 // setViewport defines area on paper in device coordinates (dpi)
1050 // e.g. (0,50,700,700) is upper part on A4
1051 // see also /usr/lib/qt3/doc/html/coordsys.html
1053 Q3PaintDeviceMetrics metrics (printer);
1055 double paperAspect = (double)metrics.width() / (double)metrics.height();
1056 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1058 QRect mapRect=totalBBox;
1059 Q3CanvasRectangle *frame=NULL;
1060 Q3CanvasText *footerFN=NULL;
1061 Q3CanvasText *footerDate=NULL;
1062 if (printFrame || printFooter)
1067 // Print frame around map
1068 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1069 totalBBox.width()+20, totalBBox.height()+20);
1070 frame=new Q3CanvasRectangle (mapRect,mapCanvas);
1071 frame->setBrush (QColor(Qt::white));
1072 frame->setPen (QColor(Qt::black));
1076 /* TODO remove after testing
1077 QCanvasLine *l=new QCanvasLine (mapCanvas);
1078 l->setPoints (0,0,mapRect.width(),mapRect.height());
1079 l->setPen (QPen(QColor(black), 1));
1086 // Print footer below map
1088 font.setPointSize(10);
1089 footerFN=new Q3CanvasText (mapCanvas);
1090 footerFN->setText ("VYM - " + fileName);
1091 footerFN->setFont(font);
1092 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1093 footerFN->setZ(Z_TEXT);
1095 footerDate=new Q3CanvasText (mapCanvas);
1096 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1097 footerDate->setFont(font);
1098 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1099 footerDate->setZ(Z_TEXT);
1102 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1105 pp.setWindow (mapRect);
1108 if (mapAspect>=paperAspect)
1110 // Fit horizontally to paper width
1111 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1114 // Fit vertically to paper height
1115 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1118 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1120 // Delete Frame and footer
1124 delete (footerDate);
1126 if (frame) delete (frame);
1128 // Restore selection
1131 selection=oldselection;
1132 selection->select();
1135 // Save settings in vymrc
1136 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1140 QPixmap MapEditor::getPixmap()
1142 QRect mapRect=mapCenter->getTotalBBox();
1143 QPixmap pix (mapRect.size());
1146 // Don't print the visualisation of selection
1147 LinkableMapObj *oldselection=NULL;
1150 oldselection=selection;
1151 selection->unselect();
1154 pp.setWindow (mapRect);
1156 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1159 // Restore selection
1162 selection=oldselection;
1163 selection->select();
1169 void MapEditor::setHideTmpMode (HideTmpMode mode)
1172 mapCenter->setHideTmp (hidemode);
1173 mapCenter->reposition();
1178 HideTmpMode MapEditor::getHideTmpMode()
1183 void MapEditor::exportImage(QString fn)
1185 setExportMode (true);
1186 QPixmap pix (getPixmap());
1187 pix.save(fn, "PNG");
1188 setExportMode (false);
1191 void MapEditor::setExportMode (bool b)
1193 // should be called before and after exports
1194 // depending on the settings
1195 if (b && settings.value("/export/useHideExport","yes")=="yes")
1196 setHideTmpMode (HideExport);
1198 setHideTmpMode (HideNone);
1201 void MapEditor::exportImage(QString fn, QString format)
1203 setExportMode (true);
1204 QPixmap pix (getPixmap());
1205 pix.save(fn, format);
1206 setExportMode (false);
1209 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1213 ex.setMapCenter(mapCenter);
1214 if (ex.setConfigFile(cf))
1216 setExportMode (true);
1217 ex.exportPresentation();
1218 setExportMode (false);
1224 void MapEditor::exportXML(const QString &dir)
1226 // Hide stuff during export, if settings want this
1227 setExportMode (true);
1229 // Create subdirectories
1232 // write to directory
1233 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1236 file.setName ( dir + "/"+mapName+".xml");
1237 if ( !file.open( QIODevice::WriteOnly ) )
1239 // This should neverever happen
1240 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1244 // Write it finally, and write in UTF8, no matter what
1245 QTextStream ts( &file );
1246 ts.setEncoding (QTextStream::UnicodeUTF8);
1250 // Now write image, too
1251 exportImage (dir+"/images/"+mapName+".png");
1253 setExportMode (false);
1256 void MapEditor::clear()
1260 selection->unselect();
1267 void MapEditor::copy()
1271 // write to directory
1272 QString clipfile="part";
1273 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1276 file.setName ( clipboardDir + "/"+clipfile+".xml");
1277 if ( !file.open( QIODevice::WriteOnly ) )
1279 // This should neverever happen
1280 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1284 // Write it finally, and write in UTF8, no matter what
1285 QTextStream ts( &file );
1286 ts.setEncoding (QTextStream::UnicodeUTF8);
1290 clipboardEmpty=false;
1295 void MapEditor::redo()
1297 blockSaveState=true;
1299 // Restore variables
1300 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1301 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1302 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1303 // Can we undo at all?
1304 if (redosAvail<1) return;
1307 if (undosAvail<stepsTotal) undosAvail++;
1309 if (curStep>stepsTotal) curStep=1;
1310 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1311 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1312 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1313 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1314 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1316 // Find out current undo directory
1317 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1319 /* TODO remove testing
1321 cout << "ME::redo() begin\n";
1322 cout << " undosAvail="<<undosAvail<<endl;
1323 cout << " redosAvail="<<redosAvail<<endl;
1324 cout << " curStep="<<curStep<<endl;
1325 cout << " ---------------------------"<<endl;
1326 cout << " comment="<<comment.toStdString()<<endl;
1327 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1328 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1329 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1330 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1331 cout << " ---------------------------"<<endl<<endl;
1333 // select object before redo
1334 // FIXME better give up if no selection there...
1335 if (!redoSelection.isEmpty())
1336 select (redoSelection);
1339 parseAtom (redoCommand);
1340 mapCenter->reposition();
1342 blockSaveState=false;
1344 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1345 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1346 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1347 undoSet.writeSettings(histPath);
1349 historyWindow.update (undoSet);
1352 /* TODO remove testing
1354 cout << "ME::redo() end\n";
1355 cout << " undosAvail="<<undosAvail<<endl;
1356 cout << " redosAvail="<<redosAvail<<endl;
1357 cout << " curStep="<<curStep<<endl;
1358 cout << " ---------------------------"<<endl<<endl;
1363 void MapEditor::undo()
1365 blockSaveState=true;
1367 // Restore variables
1368 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1369 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1370 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1372 // Can we undo at all?
1373 if (undosAvail<1) return;
1375 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1376 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1377 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1378 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1379 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1381 // Find out current undo directory
1382 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1384 // select object before undo
1385 if (!undoSelection.isEmpty())
1386 select (undoSelection);
1390 cout << "ME::undo() begin\n";
1391 cout << " undosAvail="<<undosAvail<<endl;
1392 cout << " redosAvail="<<redosAvail<<endl;
1393 cout << " curStep="<<curStep<<endl;
1394 cout << " ---------------------------"<<endl;
1395 cout << " comment="<<comment.toStdString()<<endl;
1396 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1397 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1398 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1399 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1400 cout << " ---------------------------"<<endl<<endl;
1401 parseAtom (undoCommand);
1402 mapCenter->reposition();
1406 if (curStep<1) curStep=stepsTotal;
1410 blockSaveState=false;
1411 /* TODO remove testing
1413 cout << "ME::undo() end\n";
1414 cout << " undosAvail="<<undosAvail<<endl;
1415 cout << " redosAvail="<<redosAvail<<endl;
1416 cout << " curStep="<<curStep<<endl;
1417 cout << " ---------------------------"<<endl<<endl;
1419 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1420 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1421 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1422 undoSet.writeSettings(histPath);
1424 historyWindow.update (undoSet);
1428 void MapEditor::gotoStep (int i)
1430 // Restore variables
1431 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1435 // Clicking above current steps let's us undo things
1438 for (int j=0; j<undosAvail-i; j++) undo();
1441 // Clicking below current steps let's us rendo things
1443 for (int j=undosAvail; j<i; j++) redo();
1445 // And ignore clicking the current row ;-)
1448 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1450 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1452 QFile file (bakMapPath);
1456 // We need to parse saved XML data
1457 mapBuilderHandler handler;
1458 QXmlInputSource source( file);
1459 QXmlSimpleReader reader;
1460 reader.setContentHandler( &handler );
1461 reader.setErrorHandler( &handler );
1462 handler.setMapEditor( this );
1463 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1464 if (undoSel.isEmpty())
1468 handler.setLoadMode (NewMap);
1472 handler.setLoadMode (ImportReplace);
1474 blockReposition=true;
1475 bool ok = reader.parse( source );
1476 blockReposition=false;
1479 // This should never ever happen
1480 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1481 tr( handler.errorProtocol() )+" in "+bakMapDir );
1485 QMessageBox::critical( 0, tr( "Critical Error" ),
1486 tr("Temporary directory %1 used for undo is gone. \n"
1487 "I will create a new one, but at the moment no undo is available.\n"
1488 "Maybe you want to reload your original data.\n\n"
1489 "Sorry for any inconveniences.").arg(bakMapDir) );
1494 void MapEditor::pasteNoSave()
1496 load (clipboardDir+"/part.xml",ImportAdd);
1499 void MapEditor::cutNoSave()
1505 void MapEditor::paste()
1507 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1508 typeid(*selection) == typeid(MapCenterObj)))
1510 saveStatePart(selection,QString("Paste to %1").arg( getName(selection)));
1512 mapCenter->reposition();
1517 void MapEditor::cut()
1519 saveStatePart(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
1522 mapCenter->reposition();
1526 void MapEditor::move(const int &x, const int &y)
1530 QString ps=qpointToString (selection->getAbsPos());
1531 QString s=selection->getSelectString();
1534 s, "move "+qpointToString (QPoint (x,y)),
1535 QString("Move %1 to %2").arg(getName(selection)).arg(ps));
1536 selection->move(x,y);
1537 mapCenter->reposition();
1543 void MapEditor::moveRel (const int &x, const int &y)
1547 QString ps=qpointToString (selection->getRelPos());
1548 QString s=selection->getSelectString();
1551 s, "moveRel "+qpointToString (QPoint (x,y)),
1552 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps));
1553 selection->setRelPos (QPoint(x,y));
1554 mapCenter->reposition();
1559 void MapEditor::moveBranchUp()
1563 if (typeid(*selection) == typeid(BranchObj) )
1565 bo=(BranchObj*)selection;
1566 if (!bo->canMoveBranchUp()) return;
1567 par=(BranchObj*)(bo->getParObj());
1568 selection->unselect();
1569 bo=par->moveBranchUp (bo); // bo will be the one below selection
1570 selection->select();
1571 saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1572 mapCenter->reposition();
1573 ensureSelectionVisible();
1577 void MapEditor::moveBranchDown()
1581 if (typeid(*selection) == typeid(BranchObj) )
1583 bo=(BranchObj*)selection;
1584 if (!bo->canMoveBranchDown()) return;
1585 par=(BranchObj*)(bo->getParObj());
1586 selection->unselect();
1587 bo=par->moveBranchDown(bo); // bo will be the one above selection
1588 selection->select();
1589 saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1590 mapCenter->reposition();
1591 ensureSelectionVisible();
1595 QString MapEditor::getHeading(bool &ok, QPoint &p)
1598 (typeid(*selection) == typeid(BranchObj) ||
1599 typeid(*selection) == typeid(MapCenterObj) ) )
1602 ensureSelectionVisible();
1603 p = ((BranchObj*)selection)->getAbsPos();
1604 p.setX (p.x() - contentsX());
1605 p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2);
1606 return ((BranchObj*)selection)->getHeading();
1612 void MapEditor::setHeading(const QString &s)
1615 (typeid(*selection) == typeid(BranchObj) ||
1616 typeid(*selection) == typeid(MapCenterObj) ) )
1618 editingBO=(BranchObj*)selection;
1619 saveStateConstSelection(
1620 "setHeading (\""+editingBO->getHeading()+"\")",
1621 "setHeading (\""+s+"\")",
1622 QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) );
1623 editingBO->setHeading(s );
1625 mapCenter->reposition();
1627 ensureSelectionVisible();
1631 void MapEditor::setURLInt (const QString &s)
1633 // Internal function, no saveState needed
1635 (typeid(*selection) == typeid(BranchObj) ||
1636 typeid(*selection) == typeid(MapCenterObj) ) )
1638 ((BranchObj*)selection)->setURL(s);
1639 mapCenter->reposition();
1641 ensureSelectionVisible();
1645 void MapEditor::setHeadingInt(const QString &s)
1648 (typeid(*selection) == typeid(BranchObj) ||
1649 typeid(*selection) == typeid(MapCenterObj) ) )
1651 ((BranchObj*)selection)->setHeading(s);
1652 mapCenter->reposition();
1654 ensureSelectionVisible();
1658 void MapEditor::setVymLinkInt (const QString &s)
1660 // Internal function, no saveState needed
1662 (typeid(*selection) == typeid(BranchObj) ||
1663 typeid(*selection) == typeid(MapCenterObj) ) )
1665 ((BranchObj*)selection)->setVymLink(s);
1666 mapCenter->reposition();
1668 ensureSelectionVisible();
1672 BranchObj* MapEditor::addNewBranchInt(int num)
1674 // Depending on pos:
1675 // -3 insert in childs of parent above selection
1676 // -2 add branch to selection
1677 // -1 insert in childs of parent below selection
1678 // 0..n insert in childs of parent at pos
1679 BranchObj *newbo=NULL;
1681 (typeid(*selection) == typeid(BranchObj) ||
1682 typeid(*selection) == typeid(MapCenterObj) ) )
1684 BranchObj* bo = (BranchObj*) selection;
1687 // save scroll state. If scrolled, automatically select
1688 // new branch in order to tmp unscroll parent...
1689 return bo->addBranch();
1694 bo=(BranchObj*)bo->getParObj();
1698 bo=(BranchObj*)bo->getParObj();
1701 newbo=bo->insertBranch(num);
1706 void MapEditor::addNewBranch(int pos)
1708 // Different meaning than num in addNewBranchInt!
1713 (typeid(*selection) == typeid(BranchObj) ||
1714 typeid(*selection) == typeid(MapCenterObj) ) )
1716 BranchObj *bo = (BranchObj*) selection;
1718 newbo=addNewBranchInt (pos-2);
1722 saveStateConstSelection (
1723 QString ("delete (\"%1\")").arg(newbo->getSelectString()),
1724 QString ("addBranch (%1)").arg(pos-2),
1725 QString ("Add new branch to %1").arg(getName(bo))); //TODO undoCommand
1727 LinkableMapObj *oldselection=selection;
1729 mapCenter->reposition();
1733 if (actionSettingsAutoedit->isOn() ||
1734 actionSettingsAutoselectHeading->isOn() )
1736 selection->unselect();
1738 selection->select();
1739 if (actionSettingsAutoedit->isOn() )
1740 mainWindow->editHeading();
1741 if (!actionSettingsAutoselectHeading->isOn()
1742 )//&& !wasScrolled) //FIXME wasScrolled was moved to addNewBranchInt
1744 selection->unselect();
1745 selection=oldselection;
1746 selection->select();
1754 void MapEditor::addNewBranchHere()
1757 (typeid(*selection) == typeid(BranchObj) ) )
1759 BranchObj* bo1 = (BranchObj*) selection;
1760 saveStatePart(selection, QString("Add new branch here").arg(getName(bo1)));
1762 bool wasScrolled=false;
1763 BranchObj *newbo=NULL;
1764 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1767 // add below selection
1768 newbo=parbo->insertBranch(bo1->getNum()+1);
1771 LinkableMapObj *oldselection=selection;
1772 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1774 mapCenter->reposition();
1776 if (actionSettingsAutoedit->isOn() ||
1777 actionSettingsAutoselectHeading->isOn() )
1779 selection->unselect();
1781 selection->select();
1782 if (actionSettingsAutoedit->isOn() )
1783 mainWindow->editHeading();
1784 if (!actionSettingsAutoselectHeading->isOn()
1787 selection->unselect();
1788 selection=oldselection;
1789 selection->select();
1795 void MapEditor::deleteSelection()
1797 if (selection && typeid(*selection) ==typeid(BranchObj) )
1799 BranchObj* bo=(BranchObj*)selection;
1800 BranchObj* par=(BranchObj*)(bo->getParObj());
1802 if (selection->getDepth()>1)
1803 // Normal branch, save parent with childs
1804 saveStatePart(par,QString("Delete %1").arg(getName(bo)));
1805 // naveState (UndoCom, par, QString("insertBranchAt (%1)", bo, "", QString ("Delete %1").arg(getName(bo))));
1807 // Mainbranch, save whole map
1808 // TODO Better would be to insert mainbranch again at pos
1809 // But undoCommand is missing right now
1810 saveStateComplete(QString("Delete %1").arg(getName(bo)));
1812 par->removeBranch(bo);
1814 selection->select();
1815 ensureSelectionVisible();
1816 mapCenter->reposition();
1819 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1821 FloatImageObj* fio=(FloatImageObj*)selection;
1822 BranchObj* par=(BranchObj*)(fio->getParObj());
1823 saveStatePart(par, QString("Delete %1").arg(getName(fio)));
1826 par->removeFloatImage(fio);
1828 selection->select();
1829 ensureSelectionVisible();
1830 mapCenter->reposition();
1835 LinkableMapObj* MapEditor::getSelection()
1840 void MapEditor::unselect()
1844 selectionLast=selection;
1845 selection->unselect();
1850 void MapEditor::reselect()
1854 selection=selectionLast;
1855 selection->select();
1860 bool MapEditor::select (const QString &s)
1862 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1864 // Finally select the found object
1867 if (selection) unselect();
1869 selection->select();
1871 ensureSelectionVisible();
1877 QString MapEditor::getSelectString()
1879 if (selection) return selection->getSelectString();
1883 void MapEditor::selectInt (LinkableMapObj *lmo)
1885 if (lmo && selection != lmo)
1887 // select the MapObj
1888 if (selection) selection->unselect();
1890 selection->select();
1896 void MapEditor::selectNextBranchInt()
1898 // Increase number of branch
1901 QString s=selection->getSelectString();
1907 part=s.section(",",-1);
1909 num=part.right(part.length() - 3);
1911 s=s.left (s.length() -num.length());
1914 num=QString ("%1").arg(num.toUInt()+1);
1918 // Try to select this one
1919 if (select (s)) return;
1921 // We have no direct successor,
1922 // try to increase the parental number in order to
1923 // find a successor with same depth
1925 int d=selection->getDepth();
1930 while (!found && d>0)
1932 s=s.section (",",0,d-1);
1933 // replace substring of current depth in s with "1"
1934 part=s.section(",",-1);
1936 num=part.right(part.length() - 3);
1940 // increase number of parent
1941 num=QString ("%1").arg(num.toUInt()+1);
1942 s=s.section (",",0,d-2) + ","+ typ+num;
1945 // Special case, look at orientation
1946 if (selection->getOrientation()==OrientRightOfCenter)
1947 num=QString ("%1").arg(num.toUInt()+1);
1949 num=QString ("%1").arg(num.toUInt()-1);
1954 // pad to oldDepth, select the first branch for each depth
1955 for (i=d;i<oldDepth;i++)
1960 if ( ((BranchObj*)selection)->countBranches()>0)
1968 // try to select the freshly built string
1976 void MapEditor::selectPrevBranchInt()
1978 // Decrease number of branch
1981 QString s=selection->getSelectString();
1987 part=s.section(",",-1);
1989 num=part.right(part.length() - 3);
1991 s=s.left (s.length() -num.length());
1994 num=QString ("%1").arg(num.toUInt()-1);
1998 // Try to select this one
1999 if (select (s)) return;
2001 // We have no direct precessor,
2002 // try to decrease the parental number in order to
2003 // find a precessor with same depth
2005 int d=selection->getDepth();
2010 while (!found && d>0)
2012 s=s.section (",",0,d-1);
2013 // replace substring of current depth in s with "1"
2014 part=s.section(",",-1);
2016 num=part.right(part.length() - 3);
2020 // decrease number of parent
2021 num=QString ("%1").arg(num.toUInt()-1);
2022 s=s.section (",",0,d-2) + ","+ typ+num;
2025 // Special case, look at orientation
2026 if (selection->getOrientation()==OrientRightOfCenter)
2027 num=QString ("%1").arg(num.toUInt()-1);
2029 num=QString ("%1").arg(num.toUInt()+1);
2034 // pad to oldDepth, select the last branch for each depth
2035 for (i=d;i<oldDepth;i++)
2039 if ( ((BranchObj*)selection)->countBranches()>0)
2040 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
2047 // try to select the freshly built string
2055 void MapEditor::selectUpperBranch()
2059 if (typeid(*selection) == typeid(BranchObj))
2061 if (selection->getOrientation()==OrientRightOfCenter)
2062 selectPrevBranchInt();
2064 if (selection->getDepth()==1)
2065 selectNextBranchInt();
2067 selectPrevBranchInt();
2072 void MapEditor::selectLowerBranch()
2076 if (typeid(*selection) == typeid(BranchObj))
2078 if (selection->getOrientation()==OrientRightOfCenter)
2079 selectNextBranchInt();
2081 if (selection->getDepth()==1)
2082 selectPrevBranchInt();
2084 selectNextBranchInt();
2090 void MapEditor::selectLeftBranch()
2096 if (typeid(*selection) == typeid(MapCenterObj))
2098 par= (BranchObj*) selection;
2099 bo=par->getLastSelectedBranch();
2102 // Workaround for reselecting on left and right side
2103 if (bo->getOrientation()==OrientRightOfCenter)
2105 bo=par->getLastBranch();
2111 selection->select();
2113 ensureSelectionVisible();
2118 par=(BranchObj*)(selection->getParObj());
2119 if (selection->getOrientation()==OrientRightOfCenter)
2121 if (typeid(*selection) == typeid(BranchObj) ||
2122 typeid(*selection) == typeid(FloatImageObj))
2124 selection->unselect();
2126 selection->select();
2128 ensureSelectionVisible();
2132 if (typeid(*selection) == typeid(BranchObj) )
2134 bo=((BranchObj*)selection)->getLastSelectedBranch();
2137 selection->unselect();
2139 selection->select();
2141 ensureSelectionVisible();
2149 void MapEditor::selectRightBranch()
2156 if (typeid(*selection) == typeid(MapCenterObj))
2158 par= (BranchObj*) selection;
2159 bo=par->getLastSelectedBranch();
2162 // Workaround for reselecting on left and right side
2163 if (bo->getOrientation()==OrientLeftOfCenter)
2164 bo=par->getFirstBranch();
2169 selection->select();
2170 ensureSelectionVisible();
2175 par=(BranchObj*)(selection->getParObj());
2176 if (selection->getOrientation()==OrientLeftOfCenter)
2178 if (typeid(*selection) == typeid(BranchObj) ||
2179 typeid(*selection) == typeid(FloatImageObj))
2181 selection->unselect();
2183 selection->select();
2185 ensureSelectionVisible();
2189 if (typeid(*selection) == typeid(BranchObj) )
2191 bo=((BranchObj*)selection)->getLastSelectedBranch();
2194 selection->unselect();
2196 selection->select();
2198 ensureSelectionVisible();
2206 void MapEditor::selectFirstBranch()
2212 if (typeid(*selection) == typeid(BranchObj))
2214 bo1= (BranchObj*) selection;
2215 par=(BranchObj*)(bo1->getParObj());
2216 bo2=par->getFirstBranch();
2220 selection->select();
2221 ensureSelectionVisible();
2228 void MapEditor::selectLastBranch()
2234 if (typeid(*selection) == typeid(BranchObj))
2236 bo1= (BranchObj*) selection;
2237 par=(BranchObj*)(bo1->getParObj());
2238 bo2=par->getLastBranch();
2242 selection->select();
2243 ensureSelectionVisible();
2250 void MapEditor::setColor(QColor c)
2255 void MapEditor::selectBackgroundColor()
2257 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2258 if ( !col.isValid() ) return;
2259 setBackgroundColor( col );
2261 saveStateComplete(QString("Set background color of map to %1").arg(col.name()));
2264 void MapEditor::setBackgroundColor(QColor c)
2266 mapCanvas->setBackgroundColor (c);
2269 QColor MapEditor::pickColor()
2273 if (typeid(*selection) == typeid(BranchObj) ||
2274 typeid(*selection) == typeid(MapCenterObj))
2276 BranchObj *bo=(BranchObj*)selection;
2277 actColor=bo->getColor();
2283 void MapEditor::colorItem()
2287 if (typeid(*selection) == typeid(BranchObj) ||
2288 typeid(*selection) == typeid(MapCenterObj))
2290 BranchObj *bo=(BranchObj*)selection;
2291 saveStatePart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2292 bo->setColor(actColor); // color branch
2297 void MapEditor::colorBranch()
2301 if (typeid(*selection) == typeid(BranchObj) ||
2302 typeid(*selection) == typeid(MapCenterObj))
2304 BranchObj *bo=(BranchObj*)selection;
2305 saveStatePart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2306 bo->setColorChilds(actColor); // color links, color childs
2312 void MapEditor::toggleStandardFlag(QString f)
2316 if (typeid(*selection) == typeid(BranchObj) ||
2317 typeid(*selection) == typeid(MapCenterObj))
2319 BranchObj *bo=(BranchObj*)selection;
2321 if (bo->isSetStandardFlag(f))
2331 saveStateConstSelection(QString("%1 (\"%2\")").arg(u).arg(f),
2332 QString("%1 (\"%2\")").arg(r).arg(f),
2333 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2334 bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn());
2340 void MapEditor::setViewCenter()
2342 // transform to CanvasView Coord:
2343 QPoint p=worldMatrix().map(movingCenter);
2344 center ( p.x(), p.y());
2348 BranchObj* MapEditor::findText (QString s, bool cs)
2350 QTextDocument::FindFlags flags=0;
2351 if (cs) flags=QTextDocument::FindCaseSensitively;
2354 { // Nothing found or new find process
2356 // nothing found, start again
2358 itFind=mapCenter->first();
2360 bool searching=true;
2361 bool foundNote=false;
2362 while (searching && !EOFind)
2366 // Searching in Note
2367 if (itFind->getNote().contains(s,cs))
2369 if (selection!=itFind)
2371 if (selection) ((BranchObj*)selection)->unselect();
2373 selection->select();
2375 ensureSelectionVisible();
2377 if (textEditor->findText(s,flags))
2383 // Searching in Heading
2384 if (searching && itFind->getHeading().contains (s,cs) )
2386 if (selection) ((BranchObj*)selection)->unselect();
2388 selection->select();
2390 ensureSelectionVisible();
2396 itFind=itFind->next();
2397 if (!itFind) EOFind=true;
2403 return (BranchObj*)selection;
2408 void MapEditor::findReset()
2409 { // Necessary if text to find changes during a find process
2414 void MapEditor::editURL()
2416 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2417 typeid(*selection) == typeid(MapCenterObj)) )
2420 BranchObj *bo=(BranchObj*)selection;
2421 QString text = QInputDialog::getText(
2422 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2423 bo->getURL(), &ok, this );
2426 // user entered something and pressed OK
2427 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2434 QString MapEditor::getURL()
2436 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2437 typeid(*selection) == typeid(MapCenterObj)) )
2438 return ((BranchObj*)selection)->getURL();
2443 QStringList MapEditor::getURLs()
2446 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2447 typeid(*selection) == typeid(MapCenterObj)) )
2449 BranchObj *bo=(BranchObj*)selection;
2453 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2461 void MapEditor::editHeading2URL()
2463 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2464 typeid(*selection) == typeid(MapCenterObj)) )
2466 BranchObj *bo=(BranchObj*)selection;
2467 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2468 bo->setURL (bo->getHeading());
2473 void MapEditor::editBugzilla2URL()
2475 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2476 typeid(*selection) == typeid(MapCenterObj)) )
2478 BranchObj *bo=(BranchObj*)selection;
2479 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2480 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo)));
2486 void MapEditor::editFATE2URL()
2488 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2489 typeid(*selection) == typeid(MapCenterObj)) )
2491 BranchObj *bo=(BranchObj*)selection;
2492 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2493 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2499 void MapEditor::editVymLink()
2501 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2502 typeid(*selection) == typeid(MapCenterObj)) )
2504 BranchObj *bo=(BranchObj*)selection;
2505 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map"));
2506 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2507 fd->setCaption(__VYM " - " +tr("Link to another map"));
2508 if (! bo->getVymLink().isEmpty() )
2509 fd->setSelection( bo->getVymLink() );
2513 if ( fd->exec() == QDialog::Accepted )
2515 saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2516 bo->setVymLink (fd->selectedFile() );
2518 mapCenter->reposition();
2525 void MapEditor::deleteVymLink()
2527 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2528 typeid(*selection) == typeid(MapCenterObj)) )
2530 BranchObj *bo=(BranchObj*)selection;
2531 saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2532 bo->setVymLink ("" );
2534 mapCenter->reposition();
2540 void MapEditor::toggleHideExport()
2542 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2543 typeid(*selection) == typeid(MapCenterObj)) ||
2544 (typeid(*selection)==typeid(FloatImageObj))
2547 OrnamentedObj *oo=(OrnamentedObj*)selection;
2549 if (oo->hideInExport())
2551 oo->setHideInExport(false);
2556 oo->setHideInExport(true);
2559 saveStateComplete(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2560 actionEditToggleHideExport->setOn (oo->hideInExport());
2562 mapCenter->reposition();
2568 QString MapEditor::getVymLink()
2570 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2571 typeid(*selection) == typeid(MapCenterObj)) )
2573 return ((BranchObj*)selection)->getVymLink();
2579 QStringList MapEditor::getVymLinks()
2582 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2583 typeid(*selection) == typeid(MapCenterObj)) )
2585 BranchObj *bo=(BranchObj*)selection;
2589 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2597 void MapEditor::removeBranchKeepChilds()
2599 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2601 BranchObj* bo=(BranchObj*)selection;
2602 BranchObj* par=(BranchObj*)(bo->getParObj());
2603 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2604 if (bo->getDepth()==1)
2605 saveStateComplete(s);
2607 saveStatePart(selection->getParObj(),s); // TODO undoCommand
2608 QString sel=selection->getSelectString();
2610 par->removeBranchHere(bo);
2611 mapCenter->reposition();
2616 void MapEditor::removeChilds()
2618 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2620 saveStatePart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
2621 ((BranchObj*)selection)->removeChilds();
2622 mapCenter->reposition();
2626 void MapEditor::editMapInfo()
2628 ExtraInfoDialog dia;
2629 dia.setMapName (getFileName() );
2630 dia.setAuthor (mapCenter->getAuthor() );
2631 dia.setComment(mapCenter->getComment() );
2636 Q3CanvasItemList l=canvas()->allItems();
2637 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2639 stats+=QString ("%1 items on canvas\n").arg (i,6);
2646 bo=mapCenter->first();
2649 if (!bo->getNote().isEmpty() ) n++;
2650 f+= bo->countFloatImages();
2652 xl+=bo->countXLinks();
2655 stats+=QString ("%1 branches\n").arg (b-1,6);
2656 stats+=QString ("%1 xLinks \n").arg (xl,6);
2657 stats+=QString ("%1 notes\n").arg (n,6);
2658 stats+=QString ("%1 images\n").arg (f,6);
2659 dia.setStats (stats);
2661 // Finally show dialog
2662 if (dia.exec() == QDialog::Accepted)
2664 saveStateComplete("Edit info about map"); //TODO undoCommand
2665 mapCenter->setAuthor (dia.getAuthor() );
2666 mapCenter->setComment (dia.getComment() );
2670 void MapEditor::updateActions()
2673 if (getLinkColorHint()==HeadingColor)
2674 actionFormatLinkColorHint->setOn(true);
2676 actionFormatLinkColorHint->setOn(false);
2681 actionFormatLinkStyleLine->setOn(true);
2684 actionFormatLinkStyleParabel->setOn(true);
2687 actionFormatLinkStylePolyLine->setOn(true);
2689 case StylePolyParabel:
2690 actionFormatLinkStylePolyParabel->setOn(true);
2696 QPixmap pix( 16, 16 );
2697 pix.fill( mapCanvas->backgroundColor() );
2698 actionFormatBackColor->setIconSet( pix );
2699 pix.fill( defLinkColor );
2700 actionFormatLinkColor->setIconSet( pix );
2702 actionFileSave->setEnabled( mapUnsaved );
2703 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2704 actionEditUndo->setEnabled( true);
2706 actionEditUndo->setEnabled( false);
2708 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2709 actionEditRedo->setEnabled( true);
2711 actionEditRedo->setEnabled( false);
2715 if ( (typeid(*selection) == typeid(BranchObj)) ||
2716 (typeid(*selection) == typeid(MapCenterObj)) )
2718 BranchObj *bo=(BranchObj*)selection;
2719 // Take care of links
2720 if (bo->countXLinks()==0)
2722 branchXLinksContextMenuEdit->clear();
2723 branchXLinksContextMenuFollow->clear();
2728 branchXLinksContextMenuEdit->clear();
2729 branchXLinksContextMenuFollow->clear();
2730 for (int i=0; i<=bo->countXLinks();i++)
2732 bot=bo->XLinkTargetAt(i);
2735 s=bot->getHeading();
2738 branchXLinksContextMenuFollow->addAction (s);
2739 branchXLinksContextMenuEdit->addAction (s);
2744 standardFlagsDefault->setEnabled (true);
2746 actionEditToggleScroll->setEnabled (true);
2747 if ( bo->isScrolled() )
2748 actionEditToggleScroll->setOn(true);
2750 actionEditToggleScroll->setOn(false);
2752 if ( bo->getURL().isEmpty() )
2754 actionEditOpenURL->setEnabled (false);
2755 actionEditOpenURLTab->setEnabled (false);
2759 actionEditOpenURL->setEnabled (true);
2760 actionEditOpenURLTab->setEnabled (true);
2762 if ( bo->getVymLink().isEmpty() )
2764 actionEditOpenVymLink->setEnabled (false);
2765 actionEditDeleteVymLink->setEnabled (false);
2768 actionEditOpenVymLink->setEnabled (true);
2769 actionEditDeleteVymLink->setEnabled (true);
2772 if (bo->canMoveBranchUp())
2773 actionEditMoveUp->setEnabled (true);
2775 actionEditMoveUp->setEnabled (false);
2776 if (bo->canMoveBranchDown())
2777 actionEditMoveDown->setEnabled (true);
2779 actionEditMoveDown->setEnabled (false);
2782 actionEditToggleHideExport->setEnabled (true);
2783 actionEditToggleHideExport->setOn (bo->hideInExport() );
2785 actionEditCopy->setEnabled (true);
2786 actionEditCut->setEnabled (true);
2787 if (!clipboardEmpty)
2788 actionEditPaste->setEnabled (true);
2790 actionEditPaste->setEnabled (false);
2791 for (a=actionListBranches.first();a;a=actionListBranches.next())
2792 a->setEnabled(true);
2793 actionEditDelete->setEnabled (true);
2794 switch (selection->getFrameType())
2797 actionFormatFrameNone->setOn(true);
2800 actionFormatFrameRectangle->setOn(true);
2805 actionFormatIncludeImagesVer->setOn
2806 ( ((BranchObj*)selection)->getIncludeImagesVer());
2807 actionFormatIncludeImagesHor->setOn
2808 ( ((BranchObj*)selection)->getIncludeImagesHor());
2809 actionFormatHideLinkUnselected->setOn
2810 (selection->getHideLinkUnselected());
2812 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2814 FloatObj *fo=(FloatImageObj*)selection;
2815 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2817 actionEditOpenURL->setEnabled (false);
2818 actionEditOpenVymLink->setEnabled (false);
2819 actionEditDeleteVymLink->setEnabled (false);
2820 actionEditToggleHideExport->setEnabled (true);
2821 actionEditToggleHideExport->setOn (fo->hideInExport() );
2824 actionEditCopy->setEnabled (true);
2825 actionEditCut->setEnabled (true);
2826 actionEditPaste->setEnabled (false);
2827 for (a=actionListBranches.first();a;a=actionListBranches.next())
2828 a->setEnabled(false);
2829 actionEditDelete->setEnabled (true);
2830 actionFormatHideLinkUnselected->setOn
2831 ( selection->getHideLinkUnselected());
2832 actionEditMoveUp->setEnabled (false);
2833 actionEditMoveDown->setEnabled (false);
2838 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2840 actionEditCopy->setEnabled (false);
2841 actionEditCut->setEnabled (false);
2842 actionEditPaste->setEnabled (false);
2843 for (a=actionListBranches.first();a;a=actionListBranches.next())
2844 a->setEnabled(false);
2846 actionEditToggleScroll->setEnabled (false);
2847 actionEditOpenURL->setEnabled (false);
2848 actionEditOpenVymLink->setEnabled (false);
2849 actionEditDeleteVymLink->setEnabled (false);
2850 actionEditHeading2URL->setEnabled (false);
2851 actionEditDelete->setEnabled (false);
2852 actionEditMoveUp->setEnabled (false);
2853 actionEditMoveDown->setEnabled (false);
2854 actionEditToggleHideExport->setEnabled (false);
2858 void MapEditor::updateNoteFlag()
2861 if ( (typeid(*selection) == typeid(BranchObj)) ||
2862 (typeid(*selection) == typeid(MapCenterObj)) )
2863 ((BranchObj*)selection)->updateNoteFlag();
2866 void MapEditor::setLinkStyle (LinkStyle ls)
2870 saveStateComplete("Set link style"); // TODO undoCommand
2872 bo=mapCenter->first();
2876 bo->setLinkStyle(bo->getDefLinkStyle());
2879 mapCenter->reposition();
2882 LinkStyle MapEditor::getLinkStyle ()
2887 void MapEditor::setLinkColor(QColor c)
2893 void MapEditor::setLinkColorHint()
2895 // called from setLinkColorHint(lch) or at end of parse
2897 bo=mapCenter->first();
2905 void MapEditor::setLinkColorHint(LinkColorHint lch)
2911 void MapEditor::toggleLinkColorHint()
2913 if (linkcolorhint==HeadingColor)
2914 linkcolorhint=DefaultColor;
2916 linkcolorhint=HeadingColor;
2918 bo=mapCenter->first();
2926 LinkColorHint MapEditor::getLinkColorHint()
2928 return linkcolorhint;
2931 QColor MapEditor::getDefLinkColor()
2933 return defLinkColor;
2936 void MapEditor::setDefXLinkColor(QColor col)
2941 QColor MapEditor::getDefXLinkColor()
2943 return defXLinkColor;
2946 void MapEditor::setDefXLinkWidth (int w)
2951 int MapEditor::getDefXLinkWidth()
2953 return defXLinkWidth;
2956 void MapEditor::selectLinkColor()
2958 QColor col = QColorDialog::getColor( defLinkColor, this );
2959 if ( !col.isValid() ) return;
2960 setLinkColor( col );
2961 saveStateComplete(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2965 void MapEditor::toggleScroll()
2967 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2969 BranchObj *bo=((BranchObj*)selection);
2970 if (bo->countBranches()==0) return;
2971 if (bo->getDepth()==0) return;
2973 if (bo->isScrolled())
2977 saveStatePart(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2984 void MapEditor::unScrollAll()
2987 bo=mapCenter->first();
2990 if (bo->isScrolled()) bo->toggleScroll();
2995 void MapEditor::loadFloatImage ()
2998 (typeid(*selection) == typeid(BranchObj)) ||
2999 (typeid(*selection) == typeid(MapCenterObj)) )
3001 BranchObj *bo=((BranchObj*)selection);
3003 Q3FileDialog *fd=new Q3FileDialog( this);
3004 fd->setMode (Q3FileDialog::ExistingFiles);
3005 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3006 ImagePreview *p =new ImagePreview (fd);
3007 fd->setContentsPreviewEnabled( TRUE );
3008 fd->setContentsPreview( p, p );
3009 fd->setPreviewMode( Q3FileDialog::Contents );
3010 fd->setCaption(__VYM " - " +tr("Load image"));
3011 fd->setDir (lastImageDir);
3015 if ( fd->exec() == QDialog::Accepted )
3017 saveStatePart(selection, QString("Add floatimage to %1").arg(getName(selection)));
3018 // FIXME in QT4 use: lastImageDir=fd->directory();
3019 lastImageDir=QDir (fd->dirPath());
3020 QStringList flist = fd->selectedFiles();
3021 QStringList::Iterator it = flist.begin();
3022 while( it != flist.end() )
3025 bo->addFloatImage();
3026 // TODO check if load was successful
3027 bo->getLastFloatImage()->load(*it);
3028 bo->getLastFloatImage()->setOriginalFilename(fn);
3032 mapCenter->reposition();
3041 void MapEditor::saveFloatImage ()
3044 (typeid(*selection) == typeid(FloatImageObj)) )
3046 FloatImageObj *fio=((FloatImageObj*)selection);
3047 QFileDialog *fd=new QFileDialog( this);
3048 fd->setFilters (imageIO.getFilters());
3049 fd->setCaption(__VYM " - " +tr("Save image"));
3050 fd->setFileMode( QFileDialog::AnyFile );
3051 fd->setDirectory (lastImageDir);
3052 // fd->setSelection (fio->getOriginalFilename());
3056 if ( fd->exec() == QDialog::Accepted )
3058 if (QFile (fd->selectedFile()).exists() )
3060 QMessageBox mb( __VYM,
3061 tr("The file %1 exists already.\n"
3062 "Do you want to overwrite it?").arg(fd->selectedFile()),
3063 QMessageBox::Warning,
3064 QMessageBox::Yes | QMessageBox::Default,
3065 QMessageBox::Cancel | QMessageBox::Escape,
3066 QMessageBox::QMessageBox::NoButton );
3068 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3069 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3072 case QMessageBox::Yes:
3075 case QMessageBox::Cancel:
3082 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
3088 void MapEditor::setFrame(const FrameType &t)
3091 (typeid(*selection) == typeid(BranchObj)) ||
3092 (typeid(*selection) == typeid(MapCenterObj)) )
3094 selection->setFrameType (t);
3095 mapCenter->reposition();
3096 selection->updateLink();
3100 void MapEditor::setIncludeImagesVer(bool b)
3103 (typeid(*selection) == typeid(BranchObj)) ||
3104 (typeid(*selection) == typeid(MapCenterObj)) )
3105 ((BranchObj*)selection)->setIncludeImagesVer(b);
3106 mapCenter->reposition();
3109 void MapEditor::setIncludeImagesHor(bool b)
3112 (typeid(*selection) == typeid(BranchObj)) ||
3113 (typeid(*selection) == typeid(MapCenterObj)) )
3114 ((BranchObj*)selection)->setIncludeImagesHor(b);
3115 mapCenter->reposition();
3118 void MapEditor::setHideLinkUnselected (bool b)
3121 (typeid(*selection) == typeid(BranchObj)) ||
3122 (typeid(*selection) == typeid(MapCenterObj)) ||
3123 (typeid(*selection) == typeid(FloatImageObj)) )
3124 selection->setHideLinkUnselected(b);
3127 void MapEditor::importDirInt(BranchObj *dst, QDir d)
3130 (typeid(*selection) == typeid(BranchObj)) ||
3131 (typeid(*selection) == typeid(MapCenterObj)) )
3135 // Traverse directories
3136 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3137 QFileInfoList list = d.entryInfoList();
3140 for (int i = 0; i < list.size(); ++i)
3143 if (fi.fileName() != "." && fi.fileName() != ".." )
3146 bo=dst->getLastBranch();
3147 bo->setHeading (fi.fileName() );
3148 bo->setColor (QColor("blue"));
3150 if ( !d.cd(fi.fileName()) )
3151 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3154 // Recursively add subdirs
3155 importDirInt (bo,d);
3161 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3162 list = d.entryInfoList();
3164 for (int i = 0; i < list.size(); ++i)
3168 bo=dst->getLastBranch();
3169 bo->setHeading (fi.fileName() );
3170 bo->setColor (QColor("black"));
3171 if (fi.fileName().right(4) == ".vym" )
3172 bo->setVymLink (fi.filePath());
3177 void MapEditor::importDir()
3180 (typeid(*selection) == typeid(BranchObj)) ||
3181 (typeid(*selection) == typeid(MapCenterObj)) )
3183 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
3184 fd->setMode (Q3FileDialog::DirectoryOnly);
3185 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3186 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
3190 if ( fd->exec() == QDialog::Accepted )
3192 BranchObj *bo=((BranchObj*)selection);
3193 importDirInt (bo,QDir(fd->selectedFile()) );
3194 mapCenter->reposition();
3201 void MapEditor::followXLink(int i)
3204 (typeid(*selection) == typeid(BranchObj)) ||
3205 (typeid(*selection) == typeid(MapCenterObj)) )
3207 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3210 selection->unselect();
3212 selection->select();
3213 ensureSelectionVisible();
3218 void MapEditor::editXLink(int i)
3220 qDebug ("ko."); //FIXME Huh?
3222 (typeid(*selection) == typeid(BranchObj)) ||
3223 (typeid(*selection) == typeid(MapCenterObj)) )
3225 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3228 EditXLinkDialog dia;
3230 dia.setSelection(selection);
3231 if (dia.exec() == QDialog::Accepted)
3233 if (dia.useSettingsGlobal() )
3235 setDefXLinkColor (xlo->getColor() );
3236 setDefXLinkWidth (xlo->getWidth() );
3238 if (dia.deleteXLink())
3239 ((BranchObj*)selection)->deleteXLinkAt(i);
3240 saveStateComplete("Edit xLink"); //TODO undoCommand
3246 void MapEditor::testFunction()
3248 cout << "MapEditor::testFunction() called\n";
3252 QString text = QInputDialog::getText(
3254 tr("QInputDialog::getText()"),
3255 tr("User name:"), QLineEdit::Normal,
3256 QDir::home().dirName(), &ok, Qt::FramelessWindowHint);
3259 QDialog *d =new QDialog(NULL);
3260 QLineEdit *le=new QLineEdit (d);
3261 // d->setModal (true);
3262 d->setWindowFlags (Qt::FramelessWindowHint);
3264 le->setText ("Foo");
3266 connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
3268 qWarning( le->text());
3275 dia.setCancelButton (true);
3276 dia.setText("This is a longer \nWarning");
3277 dia.setCaption("Warning: Flux problem");
3278 dia.setShowAgainName("/warnings/mapeditor");
3279 dia.setWindowFlags (Qt::FramelessWindowHint);
3280 if (dia.exec()==QDialog::Accepted)
3281 cout << "accepted!\n";
3283 cout << "canceled!\n";
3287 /* Hide hidden stuff temporary, maybe add this as regular function somewhere
3288 if (hidemode==HideNone)
3290 setHideTmpMode (HideExport);
3291 mapCenter->calcBBoxSizeWithChilds();
3292 QRect totalBBox=mapCenter->getTotalBBox();
3293 QRect mapRect=totalBBox;
3294 QCanvasRectangle *frame=NULL;
3296 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3298 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3299 totalBBox.width(), totalBBox.height());
3300 frame=new QCanvasRectangle (mapRect,mapCanvas);
3301 frame->setBrush (QColor(white));
3302 frame->setPen (QColor(black));
3308 setHideTmpMode (HideNone);
3310 cout <<" hidemode="<<hidemode<<endl;
3314 void MapEditor::ensureSelectionVisible()
3318 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3320 if (selection->getOrientation() == OrientLeftOfCenter)
3321 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3323 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3324 ensureVisible (p.x(), p.y() );
3329 void MapEditor::updateViewCenter()
3331 // Update movingCenter, so that we can zoom comfortably later
3332 QRect rc = QRect( contentsX(), contentsY(),
3333 visibleWidth(), visibleHeight() );
3334 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3335 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3336 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3339 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3341 // Lineedits are already closed by preceding
3342 // mouseEvent, we don't need to close here.
3344 QPoint p = inverseWorldMatrix().map(e->pos());
3345 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3348 { // MapObj was found
3349 if (selection != lmo)
3351 // select the MapObj
3352 if (selection) selection->unselect();
3354 selection->select();
3360 if (typeid(*selection)==typeid(BranchObj) ||
3361 typeid(*selection)==typeid(MapCenterObj) )
3363 // Context Menu on branch or mapcenter
3365 branchContextMenu->popup(e->globalPos() );
3367 if (typeid(*selection)==typeid(FloatImageObj))
3369 // Context Menu on floatimage
3371 floatimageContextMenu->popup(e->globalPos() );
3375 { // No MapObj found, we are on the Canvas itself
3376 // Context Menu on Canvas
3378 canvasContextMenu->popup(e->globalPos() );
3383 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3385 // Ignore right clicks, these will go to context menus
3386 if (e->button() == Qt::RightButton )
3392 QPoint p = inverseWorldMatrix().map(e->pos());
3393 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3397 //Take care of clickdesystem flags _or_ modifier modes
3399 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3400 typeid(*lmo)==typeid(MapCenterObj) ))
3402 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3403 if (!foname.isEmpty())
3405 // systemFlag clicked
3409 if (e->state() & Qt::ControlModifier)
3410 mainWindow->editOpenURLTab();
3412 mainWindow->editOpenURL();
3414 else if (foname=="vymLink")
3416 mainWindow->editOpenVymLink();
3417 // tabWidget may change, better return now
3418 // before segfaulting...
3419 } else if (foname=="note")
3420 mainWindow->windowToggleNoteEditor();
3421 else if (foname=="hideInExport")
3426 // No system flag clicked, take care of modmodes
3428 // Special case: CTRL is pressed
3429 if (e->state() & Qt::ControlModifier)
3431 if (actionModModeColor->isOn())
3434 setCursor (pickColorCursor);
3437 if (actionModModeLink->isOn())
3439 BranchObj *bo_begin=NULL;
3441 bo_begin=(BranchObj*)(lmo);
3444 ((typeid(*selection) == typeid(BranchObj)) ||
3445 (typeid(*selection) == typeid(MapCenterObj))) )
3446 bo_begin=(BranchObj*)selection;
3450 linkingObj_src=bo_begin;
3451 tmpXLink=new XLinkObj (mapCanvas);
3452 tmpXLink->setBegin (bo_begin);
3453 tmpXLink->setEnd (p);
3454 tmpXLink->setColor(defXLinkColor);
3455 tmpXLink->setWidth(defXLinkWidth);
3456 tmpXLink->updateXLink();
3457 tmpXLink->setVisibility (true);
3465 // Left Button Move Branches
3466 if (e->button() == Qt::LeftButton )
3468 movingObj_start.setX( p.x() - selection->x() );
3469 movingObj_start.setY( p.y() - selection->y() );
3470 movingObj_orgPos.setX (lmo->x() );
3471 movingObj_orgPos.setY (lmo->y() );
3472 movingObj_orgRelPos=lmo->getRelPos();
3474 // If modMode==copy, then we want to "move" the _new_ object around
3475 // then we need the offset from p to the _old_ selection, because of tmp
3476 if (actionModModeCopy->isOn() &&
3477 e->state() & Qt::ControlModifier)
3479 if (typeid(*selection)==typeid(BranchObj) )
3482 mapCenter->addBranch ((BranchObj*)selection);
3484 selection=mapCenter->getLastBranch();
3485 selection->select();
3486 mapCenter->reposition();
3489 movingObj=selection;
3491 // Middle Button Toggle Scroll
3492 // (On Mac OS X this won't work, but we still have
3493 // a button in the toolbar)
3494 if (e->button() == Qt::MidButton )
3498 { // No MapObj found, we are on the Canvas itself
3499 // Left Button move Pos of CanvasView
3500 if (e->button() == Qt::LeftButton )
3502 movingObj=NULL; // move Content not Obj
3503 movingObj_start=e->globalPos();
3504 movingCont_start=QPoint (contentsX(), contentsY() );
3505 movingVec=QPoint(0,0);
3506 setCursor(handOpenCursor);
3511 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3513 QPoint p = inverseWorldMatrix().map(e->pos());
3515 // Move the selected MapObj
3516 if ( selection && movingObj)
3518 // To avoid jumping of the CanvasView, only
3519 // ensureSelectionVisible, if not tmp linked
3520 if (!selection->hasParObjTmp())
3521 ensureSelectionVisible ();
3523 // Now move the selection, but add relative position
3524 // (movingObj_start) where selection was chosen with
3525 // mousepointer. (This avoids flickering resp. jumping
3526 // of selection back to absPos)
3528 LinkableMapObj *lmosel;
3529 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3531 // Check if we could link
3532 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3535 if (typeid(*selection) == typeid(FloatImageObj))
3537 FloatObj *fo=(FloatObj*)selection;
3538 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3542 // Relink float to new mapcenter or branch, if shift is pressed
3543 // Only relink, if selection really has a new parent
3544 if ( (e->state() & Qt::ShiftModifier) && lmo &&
3545 ( (typeid(*lmo)==typeid(BranchObj)) ||
3546 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3547 ( lmo != fo->getParObj())
3550 if (typeid(*fo) == typeid(FloatImageObj))
3553 saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3554 FloatImageObj *fio=(FloatImageObj*)(fo);
3555 ((BranchObj*)(lmo))->addFloatImage (fio);
3557 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3558 fio=((BranchObj*)(lmo))->getLastFloatImage();
3561 selection=(LinkableMapObj*)(fio);
3562 selection->select();
3563 movingObj=(MapObj*)(fio);
3566 } else // selection != a FloatObj
3568 if (lmosel->getDepth()==0)
3570 if (e->state() == Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3571 // If mapCenter is moved, move all the rest by default, too.
3572 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3574 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3577 if (lmosel->getDepth()==1)
3579 // depth==1, mainbranch
3580 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3584 if (lmosel->getOrientation() == OrientLeftOfCenter)
3585 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3586 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3587 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3589 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3591 // reposition subbranch
3592 lmosel->reposition();
3593 //ensureSelectionVisible();
3595 if (lmo && (lmo!=selection) &&
3596 (typeid(*lmo) == typeid(BranchObj) ||
3597 (typeid(*lmo) == typeid(MapCenterObj) )
3600 if (e->state() & Qt::ControlModifier)
3602 // Special case: CTRL to link below lmo
3603 lmosel->setParObjTmp (lmo,p,+1);
3605 else if (e->state() & Qt::ShiftModifier)
3606 lmosel->setParObjTmp (lmo,p,-1);
3608 lmosel->setParObjTmp (lmo,p,0);
3611 lmosel->unsetParObjTmp();
3615 } // no FloatImageObj
3619 } // selection && moving_obj
3621 // Draw a link from one branch to another
3624 tmpXLink->setEnd (p);
3625 tmpXLink->updateXLink();
3629 if (!movingObj && !pickingColor &&!drawingLink)
3631 QPoint p=e->globalPos();
3632 movingVec.setX(-p.x() + movingObj_start.x() );
3633 movingVec.setY(-p.y() + movingObj_start.y() );
3634 setContentsPos( movingCont_start.x() + movingVec.x(),
3635 movingCont_start.y() + movingVec.y());
3642 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3644 LinkableMapObj *dst;
3645 // Have we been picking color?
3649 setCursor (Qt::ArrowCursor);
3650 // Check if we are over another branch
3651 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3652 if (dst && selection)
3654 if (e->state() & Qt::ShiftModifier)
3656 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3657 ((BranchObj*)selection)->setLinkColor ();
3661 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3662 ((BranchObj*)selection)->setLinkColor ();
3668 // Have we been drawing a link?
3672 // Check if we are over another branch
3673 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3674 if (dst && selection)
3676 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3677 tmpXLink->updateXLink();
3678 tmpXLink->activate();
3679 saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3688 // Have we been moving something?
3689 if ( selection && movingObj )
3691 // Moved FloatObj? Maybe we need to reposition
3692 if(typeid(*selection)==typeid (FloatImageObj))
3694 FloatImageObj *fo=(FloatImageObj*)selection;
3695 QString pold=qpointToString(movingObj_orgRelPos);
3696 QString pnow=qpointToString(fo->getRelPos());
3697 saveStateConstSelection(
3700 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow));
3702 selection->getParObj()->requestReposition();
3703 mapCenter->reposition();
3706 // Check if we are over another branch, but ignore
3707 // any found LMOs, which are FloatObjs
3708 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3709 ((LinkableMapObj*)selection) );
3711 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3714 // Now check, if we have been moving a branch
3715 if (typeid(*selection) == typeid(BranchObj) )
3717 // save the position in case we link to mapcenter
3718 QPoint savePos=QPoint (selection->x(),selection->y() );
3720 // Reset the temporary drawn link to the original one
3721 ((LinkableMapObj*)selection)->unsetParObjTmp();
3723 // For Redo we may need to save original selection
3724 QString preSelStr=selection->getSelectString();
3729 BranchObj* bsel=(BranchObj*)selection;
3730 BranchObj* bdst=(BranchObj*)dst;
3732 QString preParStr=(bsel->getParObj())->getSelectString();
3733 QString preNum=QString::number (bsel->getNum(),10);
3734 QString preDstParStr;
3736 if (e->state() & Qt::ShiftModifier && dst->getParObj())
3738 preDstParStr=dst->getParObj()->getSelectString();
3739 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
3741 if (e->state() & Qt::ControlModifier && dst->getParObj())
3744 preDstParStr=dst->getParObj()->getSelectString();
3745 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
3748 preDstParStr=dst->getSelectString();
3749 bsel->moveBranchTo (bdst,-1);
3750 if (dst->getDepth()==0) bsel->move (savePos);
3752 QString postSelStr=selection->getSelectString();
3753 QString postNum=QString::number (bsel->getNum(),10);
3755 QString undoCom="linkBranchToPos (\""+
3756 preParStr+ "\"," + preNum +"," +
3757 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
3759 QString redoCom="linkBranchToPos (\""+
3760 preDstParStr + "\"," + postNum + "," +
3761 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
3766 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
3768 if (selection->getDepth()==1)
3770 // The select string might be different _after_ moving around.
3771 // Therefor reposition and then use string of old selection, too
3772 mapCenter->reposition();
3774 QString ps=qpointToString ( ((BranchObj*)selection)->getRelPos() );
3776 selection->getSelectString(), "moveRel "+qpointToString(movingObj_orgRelPos),
3777 preSelStr, "moveRel "+ps,
3778 QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps));
3781 // Draw the original link, before selection was moved around
3782 mapCenter->reposition();
3784 // Finally resize canvas, if needed
3789 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
3792 // maybe we moved View: set old cursor
3793 setCursor (Qt::ArrowCursor);
3797 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3799 if (e->button() == Qt::LeftButton )
3801 QPoint p = inverseWorldMatrix().map(e->pos());
3802 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3803 if (lmo) { // MapObj was found
3804 // First select the MapObj than edit heading
3805 if (selection) selection->unselect();
3807 selection->select();
3808 mainWindow->editHeading();
3813 void MapEditor::resizeEvent (QResizeEvent* e)
3815 Q3CanvasView::resizeEvent( e );
3819 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3822 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3823 // cerr << event->format(i) << endl;
3826 (typeid(*selection) == typeid(BranchObj)) ||
3827 (typeid(*selection) == typeid(MapCenterObj))) {
3829 // If QImageDrag can decode mime type
3830 if (Q3ImageDrag::canDecode(event)) {
3835 // If image are dragged from firefox
3836 if (event->provides("application/x-moz-file-promise-url") &&
3837 event->provides("application/x-moz-nativeimage")) {
3838 event->accept(true);
3842 // If QUriDrag can decode mime type
3843 if (Q3UriDrag::canDecode(event)) {
3848 // If Uri are dragged from firefox
3849 if (event->provides("_NETSCAPE_URL")){
3854 // If QTextDrag can decode mime type
3855 if (Q3TextDrag::canDecode(event)) {
3864 bool isUnicode16(const QByteArray &d)
3866 // TODO: make more precise check for unicode 16.
3867 // Guess unicode16 if any of second bytes are zero
3868 unsigned int length = max(0,d.size()-2)/2;
3869 for (unsigned int i = 0; i<length ; i++)
3870 if (d.at(i*2+1)==0) return true;
3874 void MapEditor::contentsDropEvent(QDropEvent *event)
3877 (typeid(*selection) == typeid(BranchObj)) ||
3878 (typeid(*selection) == typeid(MapCenterObj)))
3883 if (event->provides("image/png"))
3886 if (Q3ImageDrag::decode(event, pix))
3894 } else if (event->provides("application/x-moz-file-promise-url") &&
3895 event->provides("application/x-moz-nativeimage"))
3897 // Contains url to the img src in unicode16
3898 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3899 QString url = QString((const QChar*)d.data(),d.size()/2);
3903 } else if (event->provides ("text/uri-list"))
3904 { // Uris provided e.g. by konqueror
3905 Q3UriDrag::decode (event,uris);
3906 } else if (event->provides ("_NETSCAPE_URL"))
3907 { // Uris provided by Mozilla
3908 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3911 } else if (event->provides("text/html")) {
3913 // Handels text mime types
3914 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3915 QByteArray d = event->encodedData("text/html");
3918 text = QString((const QChar*)d.data(),d.size()/2);
3922 textEditor->setText(text);
3926 } else if (event->provides("text/plain")) {
3927 QByteArray d = event->encodedData("text/plain");
3930 text = QString((const QChar*)d.data(),d.size()/2);
3934 textEditor->setText(text);
3946 for (const char* u=uris.first(); u; u=uris.next())
3948 bo=((BranchObj*)selection)->addBranch();
3951 s=Q3UriDrag::uriToLocalFile(u);
3954 QString file = QDir::convertSeparators(s);
3955 heading = QFileInfo(file).baseName();
3957 if (file.endsWith(".vym", false))
3958 bo->setVymLink(file);
3967 if (!heading.isEmpty())
3968 bo->setHeading(heading);
3978 //FIXME saveState has to be called earlier for each of the drops...
3979 saveStateComplete("Drop Event"); //TODO undo Command
3980 mapCenter->reposition();
3987 void MapEditor::addFloatImage(const QPixmap &img)
3990 (typeid(*selection) == typeid(BranchObj)) ||
3991 (typeid(*selection) == typeid(MapCenterObj)) )
3993 BranchObj *bo=((BranchObj*)selection);
3994 saveStatePart(selection,QString("Add floatimage to %1").arg(getName(bo)));
3995 //QString fn=fd->selectedFile();
3996 //lastImageDir=fn.left(fn.findRev ("/"));
3997 bo->addFloatImage();
3998 // FIXME check if load was successful
3999 bo->getLastFloatImage()->load(img);
4000 //bo->getLastFloatImage()->setOriginalFilename(fn);
4001 mapCenter->reposition();
4008 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
4010 if (!imageBuffer) imageBuffer = new QBuffer();
4011 if (!imageBuffer->isOpen()) {
4012 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
4014 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
4018 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
4020 if (nop->state()==Q3NetworkProtocol::StDone) {
4021 QPixmap img(imageBuffer->buffer());
4026 imageBuffer->close();
4028 imageBuffer->close();
4035 void MapEditor::fetchImage(const QString &url)
4038 urlOperator->stop();
4039 disconnect(urlOperator);
4043 urlOperator = new Q3UrlOperator(url);
4044 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
4045 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
4047 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
4048 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));