More undo/redo commands. Undo debug output still enabled
3 #include <qstatusbar.h>
5 #include <qapplication.h>
7 #include <q3popupmenu.h>
9 #include <q3paintdevicemetrics.h>
11 #include <q3filedialog.h>
14 #include <QColorDialog>
16 #include <qinputdialog.h>
17 #include <q3dragobject.h>
18 #include <q3urloperator.h>
19 #include <q3networkprotocol.h>
22 #include <QResizeEvent>
23 #include <QContextMenuEvent>
26 #include <QMouseEvent>
27 #include <QDragEnterEvent>
28 #include <QTextStream>
30 #include <QActionGroup>
40 #include "editxlinkdialog.h"
42 #include "extrainfodialog.h"
44 #include "linkablemapobj.h"
45 #include "mainwindow.h"
47 #include "texteditor.h"
48 #include "warningdialog.h"
52 extern TextEditor *textEditor;
53 extern int statusbarTime;
54 extern Main *mainWindow;
55 extern QString tmpVymDir;
56 extern QString clipboardDir;
57 extern bool clipboardEmpty;
58 extern FlagRowObj *systemFlagsDefault;
59 extern FlagRowObj *standardFlagsDefault;
61 extern Q3PtrList <QAction> actionListBranches;
63 extern QAction *actionFileSave;
64 extern QAction *actionEditUndo;
65 extern QAction *actionEditRedo;
66 extern QAction *actionEditCopy;
67 extern QAction *actionEditCut;
68 extern QAction *actionEditPaste;
69 extern QAction *actionEditMoveUp;
70 extern QAction *actionEditMoveDown;
71 extern QAction *actionEditToggleScroll;
72 extern QAction *actionEditOpenURL;
73 extern QAction *actionEditOpenURLTab;
74 extern QAction *actionEditURL;
75 extern QAction *actionEditHeading2URL;
76 extern QAction *actionEditBugzilla2URL;
77 extern QAction *actionEditFATE2URL;
78 extern QAction *actionEditOpenVymLink;
79 extern QAction *actionEditVymLink;
80 extern QAction *actionEditDeleteVymLink;
81 extern QAction *actionEditToggleHideExport;
82 extern QAction *actionEditHeading;
83 extern QAction *actionEditDelete;
84 extern QAction *actionEditAddBranch;
85 extern QAction *actionEditAddBranchAbove;
86 extern QAction *actionEditAddBranchBelow;
87 extern QAction *actionEditRemoveBranchHere;
88 extern QAction *actionEditRemoveChilds;
89 extern QAction *actionEditImportAdd;
90 extern QAction *actionEditImportReplace;
91 extern QAction *actionEditSaveBranch;
92 extern QAction *actionEditSelectFirst;
93 extern QAction *actionEditSelectLast;
94 extern QAction *actionEditLoadImage;
96 extern QAction* actionFormatPickColor;
97 extern QAction* actionFormatColorBranch;
98 extern QAction* actionFormatColorSubtree;
99 extern QAction *actionFormatLinkColorHint;
100 extern QAction *actionFormatBackColor;
101 extern QAction *actionFormatLinkColor;
103 extern QActionGroup* actionGroupModModes;
104 extern QAction* actionModModeColor;
105 extern QAction* actionModModeLink;
106 extern QAction* actionModModeCopy;
108 extern QActionGroup *actionGroupFormatFrameTypes;
109 extern QAction *actionFormatFrameNone;
110 extern QAction *actionFormatFrameRectangle;
112 extern QActionGroup *actionGroupFormatLinkStyles;
113 extern QAction *actionFormatIncludeImagesVer;
114 extern QAction *actionFormatIncludeImagesHor;
115 extern QAction *actionFormatHideLinkUnselected;
116 extern QAction *actionFormatLinkStyleLine;
117 extern QAction *actionFormatLinkStyleParabel;
118 extern QAction *actionFormatLinkStylePolyLine;
119 extern QAction *actionFormatLinkStylePolyParabel;
121 extern QAction *actionViewToggleNoteEditor;
123 extern QAction *actionSettingsAutoedit;
124 extern QAction *actionSettingsAutoselectHeading;
125 extern QAction *actionSettingsAutoselectText;
126 extern QAction *actionSettingsUseFlagGroups;
128 extern QMenu* branchContextMenu;
129 extern QMenu* branchAddContextMenu;
130 extern QMenu* branchRemoveContextMenu;
131 extern QMenu* branchLinksContextMenu;
132 extern QMenu* branchXLinksContextMenuEdit;
133 extern QMenu* branchXLinksContextMenuFollow;
134 extern QMenu* floatimageContextMenu;
135 extern QMenu* saveImageFormatMenu;
136 extern QMenu* canvasContextMenu;
137 extern QMenu* lastMapsMenu;
138 extern QMenu* importMenu;
139 extern QMenu* exportMenu;
142 extern Settings settings;
143 extern ImageIO imageIO;
145 extern QString iconPath;
146 extern QDir vymBaseDir;
147 extern QDir lastImageDir;
149 int MapEditor::mapNum=0; // make instance
151 ///////////////////////////////////////////////////////////////////////
152 ///////////////////////////////////////////////////////////////////////
153 MapEditor::MapEditor(
154 QWidget* parent, bool interactive, const char* name, Qt::WFlags f) :
155 Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
157 //cout << "Constructor ME "<<this<<endl;
160 viewport()->setAcceptDrops(true);
162 mapCanvas = new Q3Canvas(width(),height());
163 mapCanvas->setAdvancePeriod(30);
164 mapCanvas->setBackgroundColor (Qt::white);
166 setCanvas (mapCanvas);
168 // Always show scroll bars (automatic would flicker sometimes)
169 setVScrollBarMode ( Q3ScrollView::AlwaysOn );
170 setHScrollBarMode ( Q3ScrollView::AlwaysOn );
172 mapCenter = new MapCenterObj(mapCanvas);
173 mapCenter->setVisibility (true);
174 mapCenter->setMapEditor (this);
175 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
176 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
180 actColor=Qt::black; setColor (actColor);
181 defLinkColor=QColor (0,0,255);
182 defXLinkColor=QColor (180,180,180);
183 linkcolorhint=DefaultColor;
184 linkstyle=StylePolyParabel;
186 // Create bitmap cursors, platform dependant
187 #if defined(Q_OS_MACX)
188 handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png"),1,1 );
189 pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 );
191 handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
192 pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
204 xelection.setMapCenter (mapCenter);
207 defXLinkColor=QColor (230,230,230);
215 fileName=tr("unnamed");
218 undosTotal=settings.readNumEntry("/mapeditor/undoLevels",50);
220 // Initialize find routine
227 blockReposition=false;
228 blockSaveState=false;
232 isInteractive=interactive;
234 // Create temporary files
237 // Initially set movingCentre
240 // For testing purposes create history window
241 historyWindow = new ShowTextDialog (this);
242 historyWindow->setCaption (fileName);
244 mapCenter->reposition(); // for positioning heading
249 MapEditor::~MapEditor()
251 if (imageBuffer) delete imageBuffer;
257 //cout <<"Destructor MapEditor\n";
260 //settings.writeEntry( "/mapeditor/editmode/autoselect", );
264 QColor MapEditor::color()
269 QColor MapEditor::backgroundColor()
271 return mapCanvas->backgroundColor();
274 MapCenterObj* MapEditor::getMapCenter()
279 Q3Canvas* MapEditor::getCanvas()
284 void MapEditor::adjustCanvasSize()
286 // To adjust the canvas to map, viewport size and position, we have to
287 // do some coordinate magic...
289 // Get rectangle of (scroll-)view.
290 // We want to be in canvas coords, so
291 // we map. Important if view is zoomed...
292 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
293 visibleWidth(), visibleHeight()) );
295 // Now we need the bounding box of view AND map to calc the correct canvas size.
296 // Why? Because if the map itself is moved out of view, the view has to be enlarged
297 // to avoid jumping aroung...
298 QRect map=mapCenter->getTotalBBox();
300 // right edge - left edge
301 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
302 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
305 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
306 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
309 // move the map on canvas (in order to not move it on screen) this is neccessary
310 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
311 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
312 // to scroll to an empty area of canvas to the left.
313 // b) if topleft corner of map left of or above topleft of canvas
317 if (cw > mapCanvas->width() )
319 if (map.x()<0) dx=-map.x();
321 if (cw < mapCanvas->width() )
322 dx=-min (view.x(),map.x());
323 if (ch > mapCanvas->height() )
325 if (map.y()<0) dy=-map.y();
327 if (ch < mapCanvas->height() )
329 dy=-min (view.y(),map.y());
331 // We really have to resize now. Let's go...
332 mapCanvas->resize (cw,ch);
333 if ( (dx!=0) || (dy!=0) )
335 mapCenter->moveAllBy(dx,dy);
336 mapCenter->reposition();
337 // mapCenter->positionBBox(); // To move float
339 // scroll the view (in order to not move map on screen)
345 bool MapEditor::isRepositionBlocked()
347 return blockReposition;
350 QString MapEditor::getName (LinkableMapObj *lmo)
353 if (!lmo) return QString("Error: NULL has no name!");
355 if ((typeid(*lmo) == typeid(BranchObj) ||
356 typeid(*lmo) == typeid(MapCenterObj)))
359 s=(((BranchObj*)lmo)->getHeading());
360 if (s=="") s="unnamed";
361 return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
363 if ((typeid(*lmo) == typeid(FloatImageObj) ))
364 return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
365 return QString("Unknown type has no name!");
368 void MapEditor::makeTmpDirs()
370 // Create unique temporary directories
371 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
372 histPath=QDir::convertSeparators (tmpMapDir+"/history");
374 d.mkdir (tmpMapDir,true);
377 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSel)
379 // tmpdir temporary directory to which data will be written
380 // prefix mapname, which will be appended to images etc.
381 // writeflags Only write flags for "real" save of map, not undo
382 // offset offset of bbox of whole map in canvas.
383 // Needed for XML export
399 ls="StylePolyParabel";
403 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
405 if (linkcolorhint==HeadingColor)
406 colhint=attribut("linkColorHint","HeadingColor");
408 QString mapAttr=attribut("version",__VYM_VERSION);
410 mapAttr+= attribut("author",mapCenter->getAuthor()) +
411 attribut("comment",mapCenter->getComment()) +
412 attribut("date",mapCenter->getDate()) +
413 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
414 attribut("linkStyle", ls ) +
415 attribut("linkColor", defLinkColor.name() ) +
416 attribut("defXLinkColor", defXLinkColor.name() ) +
417 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
419 s+=beginElement("vymmap",mapAttr);
422 // Find the used flags while traversing the tree
423 standardFlagsDefault->resetUsedCounter();
425 // Reset the counters before saving
426 FloatImageObj (mapCanvas).resetSaveCounter();
428 // Build xml recursivly
430 // Save complete map, if saveSel not set
431 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
434 if ( typeid(*saveSel) == typeid(BranchObj) )
436 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
437 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
439 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
441 else if (selection && typeid(*selection)==typeid(BranchObj))
442 // Save selected branch is saved from mainwindow //FIXME maybe use "subtree" above?
443 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
446 // Save local settings
447 s+=settings.getXMLData (destPath);
450 if (selection && !saveSel )
451 s+=valueElement("select",selection->getSelectString());
454 s+=endElement("vymmap");
457 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
461 void MapEditor::saveStateComplete(const QString &comment)
463 // Save complete map, Undo will replace whole map
464 saveState (CompleteMap,
471 void MapEditor::saveStatePart(LinkableMapObj *undoSel, const QString &comment)
473 // save the selected part of the map, Undo will replace part of map
474 QString undoSelection="";
475 if (undoSel) undoSelection=undoSel->getSelectString();
477 saveState (PartOfMap,
484 void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment)
486 // selection does not change during action,
487 // so just save commands for undo and redo
488 // and use current selection
491 if (selection) sel=selection->getSelectString();
493 saveState (UndoCommand,
500 void MapEditor::saveStateComData(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel)
502 QString redoSelection="";
503 if (redoSel) redoSelection=redoSel->getSelectString();
504 QString undoSelection="";
505 if (undoSel) undoSelection=undoSel->getSelectString();
507 saveState (UndoCommand,
509 redoSelection, "FIXME-redoCom", //FIXME
514 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
516 // "Normal" savestate: save commands, selections and comment
517 // so just save commands for undo and redo
518 // and use current selection
520 QString redoSelection="";
521 if (redoSel) redoSelection=redoSel->getSelectString();
522 QString undoSelection="";
523 if (undoSel) undoSelection=undoSel->getSelectString();
525 saveState (UndoCommand,
532 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
534 // "Normal" savestate: save commands, selections and comment
535 // so just save commands for undo and redo
536 // and use current selection
537 saveState (UndoCommand,
545 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
549 if (blockSaveState) return;
551 /* TODO remove after testing
553 cout << "ME::saveState() begin"<<endl;
554 historyWindow->append (comment);
558 int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
559 int curStep=undoSet.readNumEntry ("/history/curStep",0);
560 // Find out current undo directory
561 if (undosAvail<undosTotal) undosAvail++;
563 if (curStep>undosTotal) curStep=1;
566 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
567 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
569 // Create bakMapDir if not available
572 makeSubDirs (bakMapDir);
574 // Save depending on how much needs to be saved
578 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel);
580 QString undoCommand="";
581 if (savemode==UndoCommand)
585 else if (savemode==PartOfMap )
587 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
590 undoCommand="undoMap (\""+bakMapPath+"\")";
592 if (!backupXML.isEmpty())
593 // Write XML Data to disk
594 saveStringToDisk (QString(bakMapPath),backupXML);
596 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
597 undoSet.setEntry ("/history/curStep",QString::number(curStep));
598 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
599 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
600 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
601 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
602 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
603 undoSet.writeSettings(histPath);
605 /* TODO remove after testing
607 //cout << " into="<< histPath.toStdString()<<endl;
608 cout << " undosTotal="<<undosTotal<<
609 ", undosAvail="<<undosAvail<<
610 ", curStep="<<curStep<<endl;
611 cout << " ---------------------------"<<endl;
612 cout << " comment="<<comment.toStdString()<<endl;
613 cout << " undoCom="<<undoCommand.toStdString()<<endl;
614 cout << " undoSel="<<undoSelection.toStdString()<<endl;
615 cout << " redoCom="<<redoCom.toStdString()<<endl;
616 cout << " redoSel="<<redoSelection.toStdString()<<endl;
617 cout << " ---------------------------"<<endl;
620 void MapEditor::parseAtom(const QString &atom)
627 // Split string s into command and parameters
628 api.parseCommand (atom);
629 QString com=api.command();
632 if (com=="moveBranchUp")
634 else if (com=="moveBranchDown")
636 else if (com=="move")
638 if (api.checkParamCount(2) && selection )
648 else if (com=="delete")
650 if (api.checkParamCount(1) && selection )
652 s=api.parString(ok,0);
653 if (ok &&select (s)) deleteSelection();
656 else if (com=="addBranch")
658 if (api.checkParamCount(1) && selection )
661 if (ok ) addNewBranchInt (y);
664 else if (com=="linkBranchToPos")
666 if (selection && typeid(*selection) == typeid(BranchObj) )
668 if (api.checkParamCount(4))
670 // 0 selectstring of parent
671 // 1 num in parent (for branches)
672 // 2,3 x,y of mainbranch or mapcenter
673 s=api.parString(ok,0);
674 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
677 if (typeid(*dst) == typeid(BranchObj) )
679 // Get number in parent
682 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
683 } else if (typeid(*dst) == typeid(MapCenterObj) )
685 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
686 // Get coordinates of mainbranch
691 if (ok) ((BranchObj*)selection)->move (x,y);
697 } else if (com=="setHeading")
699 if (api.checkParamCount(1))
701 s=api.parString (ok,0);
705 } else if (com=="setURL")
707 if (api.checkParamCount(1))
709 s=api.parString (ok,0);
710 if (ok) setURLInt(s);
712 } else if (com=="setVymLink")
714 if (api.checkParamCount(1))
716 s=api.parString (ok,0);
717 if (ok) setVymLinkInt(s);
720 else if (com=="setFlag")
722 if (selection && typeid(*selection) == typeid(BranchObj) )
724 if (api.checkParamCount(1) )
726 s=api.parString(ok,0);
729 BranchObj* bo=(BranchObj*)selection;
730 bo->activateStandardFlag(s);
731 bo->updateFlagsToolbar();
736 else if (com=="unsetFlag")
738 if (selection && typeid(*selection) == typeid(BranchObj) )
740 if (api.checkParamCount(1) )
742 s=api.parString(ok,0);
745 BranchObj* bo=(BranchObj*)selection;
746 bo->deactivateStandardFlag(s);
747 bo->updateFlagsToolbar();
752 // Internal commands, used for undo etc.
753 else if (com==QString("undoMap"))
755 if (api.checkParamCount(1))
756 undoXML("",api.parString (ok,0));
757 } else if (com==QString("undoPart"))
759 if (api.checkParamCount(2))
761 s=api.parString (ok,0); // undo selection
762 t=api.parString (ok,1); // backup dir
765 } else if (com=="select")
766 if (api.checkParamCount(1))
768 s=api.parString(ok,0);
773 api.setError ("Unknown command in: "+atom);
774 cout << "ME::parse api should have error now...\n";
780 // TODO Error handling
781 qWarning("MapEditor::parseAtom: Error!");
782 qWarning(api.errorDesc());
786 void MapEditor::toggleHistoryWindow()
788 if (historyWindow->isVisible())
789 historyWindow->hide();
791 historyWindow->show();
795 bool MapEditor::isDefault()
800 bool MapEditor::isUnsaved()
805 bool MapEditor::hasChanged()
810 void MapEditor::setChanged()
815 actionEditUndo->setEnabled (true);
816 actionFileSave->setEnabled (true);
820 void MapEditor::closeMap()
822 // Unselect before disabling the toolbar actions
823 if (selection) selection->unselect();
831 void MapEditor::setFilePath(QString fname)
833 setFilePath (fname,fname);
836 void MapEditor::setFilePath(QString fname, QString destname)
838 if (fname.isEmpty() || fname=="")
845 filePath=fname; // becomes absolute path
846 fileName=fname; // gets stripped of path
847 destPath=destname; // needed for vymlinks
849 // If fname is not an absolute path, complete it
850 filePath=QDir(fname).absPath();
851 fileDir=filePath.left (1+filePath.findRev ("/"));
853 // Set short name, too. Search from behind:
854 int i=fileName.findRev("/");
855 if (i>=0) fileName=fileName.remove (0,i+1);
857 // Forget the .vym (or .xml) for name of map
858 mapName=fileName.left(fileName.findRev(".",-1,true) );
860 // Adjust history window
861 historyWindow->setCaption (fileName);
865 QString MapEditor::getFilePath()
870 QString MapEditor::getFileName()
875 QString MapEditor::getMapName()
880 QString MapEditor::getDestPath()
885 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
887 ErrorCode err=success;
891 if (selection) selection->unselect();
894 mapCenter->setMapEditor(this);
895 // (map state is set later at end of load...)
898 saveStatePart(selection,"Load map");
902 mapBuilderHandler handler;
905 // I am paranoid: file should exist anyway
906 // according to check in mainwindow.
909 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
910 tr("Couldn't open map " +fname)+".");
914 blockReposition=true;
915 QXmlInputSource source( file);
916 QXmlSimpleReader reader;
917 reader.setContentHandler( &handler );
918 reader.setErrorHandler( &handler );
919 handler.setMapEditor( this );
920 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
921 handler.setInputFile (file.name());
922 handler.setLoadMode (lmode);
924 bool ok = reader.parse( source );
925 blockReposition=false;
926 blockSaveState=false;
930 mapCenter->reposition();
940 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
941 tr( handler.errorProtocol() ) );
943 // Still return "success": the map maybe at least
944 // partially read by the parser
951 int MapEditor::save (const SaveMode &savemode)
955 // The SaveMode UndoCommand is not supported here
956 if (savemode==UndoCommand) return 1;
958 // Create mapName and fileDir
959 makeSubDirs (fileDir);
963 fname=mapName+".xml";
965 // use name given by user, even if he chooses .doc
970 if (savemode==CompleteMap || selection==NULL)
971 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
973 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
975 if (!saveStringToDisk(fileDir+fname,saveFile))
982 actionFileSave->setEnabled(false);
988 void MapEditor::setZipped (bool z)
993 bool MapEditor::saveZipped ()
998 void MapEditor::print()
1002 printer = new QPrinter;
1003 printer->setColorMode (QPrinter::Color);
1004 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1007 QRect totalBBox=mapCenter->getTotalBBox();
1009 // Try to set orientation automagically
1010 // Note: Interpretation of generated postscript is amibiguous, if
1011 // there are problems with landscape mode, see
1012 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1014 if (totalBBox.width()>totalBBox.height())
1015 // recommend landscape
1016 printer->setOrientation (QPrinter::Landscape);
1018 // recommend portrait
1019 printer->setOrientation (QPrinter::Portrait);
1021 if ( printer->setup(this) )
1022 // returns false, if printing is canceled
1024 QPainter pp(printer);
1026 // Don't print the visualisation of selection
1027 LinkableMapObj *oldselection=NULL;
1030 oldselection=selection;
1031 selection->unselect();
1034 // Handle sizes of map and paper:
1036 // setWindow defines which part of the canvas will be transformed
1037 // setViewport defines area on paper in device coordinates (dpi)
1038 // e.g. (0,50,700,700) is upper part on A4
1039 // see also /usr/lib/qt3/doc/html/coordsys.html
1041 Q3PaintDeviceMetrics metrics (printer);
1043 double paperAspect = (double)metrics.width() / (double)metrics.height();
1044 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1046 QRect mapRect=totalBBox;
1047 Q3CanvasRectangle *frame=NULL;
1048 Q3CanvasText *footerFN=NULL;
1049 Q3CanvasText *footerDate=NULL;
1050 if (printFrame || printFooter)
1055 // Print frame around map
1056 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1057 totalBBox.width()+20, totalBBox.height()+20);
1058 frame=new Q3CanvasRectangle (mapRect,mapCanvas);
1059 frame->setBrush (QColor(Qt::white));
1060 frame->setPen (QColor(Qt::black));
1064 /* TODO remove after testing
1065 QCanvasLine *l=new QCanvasLine (mapCanvas);
1066 l->setPoints (0,0,mapRect.width(),mapRect.height());
1067 l->setPen (QPen(QColor(black), 1));
1074 // Print footer below map
1076 font.setPointSize(10);
1077 footerFN=new Q3CanvasText (mapCanvas);
1078 footerFN->setText ("VYM - " + fileName);
1079 footerFN->setFont(font);
1080 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1081 footerFN->setZ(Z_TEXT);
1083 footerDate=new Q3CanvasText (mapCanvas);
1084 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1085 footerDate->setFont(font);
1086 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1087 footerDate->setZ(Z_TEXT);
1090 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1093 pp.setWindow (mapRect);
1096 if (mapAspect>=paperAspect)
1098 // Fit horizontally to paper width
1099 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1102 // Fit vertically to paper height
1103 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1106 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1108 // Delete Frame and footer
1112 delete (footerDate);
1114 if (frame) delete (frame);
1116 // Restore selection
1119 selection=oldselection;
1120 selection->select();
1123 // Save settings in vymrc
1124 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1128 QPixmap MapEditor::getPixmap()
1130 QRect mapRect=mapCenter->getTotalBBox();
1131 QPixmap pix (mapRect.size());
1134 // Don't print the visualisation of selection
1135 LinkableMapObj *oldselection=NULL;
1138 oldselection=selection;
1139 selection->unselect();
1142 pp.setWindow (mapRect);
1144 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1147 // Restore selection
1150 selection=oldselection;
1151 selection->select();
1157 void MapEditor::setHideTmpMode (HideTmpMode mode)
1160 mapCenter->setHideTmp (hidemode);
1161 mapCenter->reposition();
1166 HideTmpMode MapEditor::getHideTmpMode()
1171 void MapEditor::exportImage(QString fn)
1173 setExportMode (true);
1174 QPixmap pix (getPixmap());
1175 pix.save(fn, "PNG");
1176 setExportMode (false);
1179 void MapEditor::setExportMode (bool b)
1181 // should be called before and after exports
1182 // depending on the settings
1183 if (b && settings.value("/export/useHideExport","yes")=="yes")
1184 setHideTmpMode (HideExport);
1186 setHideTmpMode (HideNone);
1189 void MapEditor::exportImage(QString fn, QString format)
1191 setExportMode (true);
1192 QPixmap pix (getPixmap());
1193 pix.save(fn, format);
1194 setExportMode (false);
1197 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1201 ex.setMapCenter(mapCenter);
1202 if (ex.setConfigFile(cf))
1204 setExportMode (true);
1205 ex.exportPresentation();
1206 setExportMode (false);
1212 void MapEditor::exportXML(const QString &dir)
1214 // Hide stuff during export, if settings want this
1215 setExportMode (true);
1217 // Create subdirectories
1220 // write to directory
1221 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1224 file.setName ( dir + "/"+mapName+".xml");
1225 if ( !file.open( QIODevice::WriteOnly ) )
1227 // This should neverever happen
1228 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1232 // Write it finally, and write in UTF8, no matter what
1233 QTextStream ts( &file );
1234 ts.setEncoding (QTextStream::UnicodeUTF8);
1238 // Now write image, too
1239 exportImage (dir+"/images/"+mapName+".png");
1241 setExportMode (false);
1244 void MapEditor::clear()
1248 selection->unselect();
1255 void MapEditor::copy()
1259 // write to directory
1260 QString clipfile="part";
1261 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1264 file.setName ( clipboardDir + "/"+clipfile+".xml");
1265 if ( !file.open( QIODevice::WriteOnly ) )
1267 // This should neverever happen
1268 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1272 // Write it finally, and write in UTF8, no matter what
1273 QTextStream ts( &file );
1274 ts.setEncoding (QTextStream::UnicodeUTF8);
1278 clipboardEmpty=false;
1283 void MapEditor::redo()
1285 blockSaveState=true;
1287 // Restore variables
1288 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1289 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1290 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1291 if (redosAvail>0) redosAvail--;
1292 if (undosAvail<undosTotal) undosAvail++;
1294 if (curStep>undosTotal) curStep=1;
1295 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1296 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1297 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1298 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1299 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1301 // Find out current undo directory
1302 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1304 /* TODO remove testing
1306 cout << "ME::redo() begin\n";
1307 cout << " undosAvail="<<undosAvail<<endl;
1308 cout << " redosAvail="<<redosAvail<<endl;
1309 cout << " curStep="<<curStep<<endl;
1310 cout << " ---------------------------"<<endl;
1311 cout << " comment="<<comment.toStdString()<<endl;
1312 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1313 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1314 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1315 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1316 cout << " ---------------------------"<<endl<<endl;
1318 // select object before redo
1319 // FIXME better give up if no selection there...
1320 if (!redoSelection.isEmpty())
1321 select (redoSelection);
1324 parseAtom (redoCommand);
1325 mapCenter->reposition();
1327 blockSaveState=false;
1329 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1330 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1331 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1332 undoSet.writeSettings(histPath);
1336 /* TODO remove testing
1338 cout << "ME::redo() end\n";
1339 cout << " undosAvail="<<undosAvail<<endl;
1340 cout << " redosAvail="<<redosAvail<<endl;
1341 cout << " curStep="<<curStep<<endl;
1342 cout << " ---------------------------"<<endl<<endl;
1347 void MapEditor::undo()
1349 blockSaveState=true;
1351 // Restore variables
1352 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1353 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1354 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1355 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1356 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1357 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1358 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1359 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1361 // Find out current undo directory
1362 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1364 // select object before undo
1365 if (!undoSelection.isEmpty())
1366 select (undoSelection);
1370 cout << "ME::undo() begin\n";
1371 cout << " undosAvail="<<undosAvail<<endl;
1372 cout << " redosAvail="<<redosAvail<<endl;
1373 cout << " curStep="<<curStep<<endl;
1374 cout << " ---------------------------"<<endl;
1375 cout << " comment="<<comment.toStdString()<<endl;
1376 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1377 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1378 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1379 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1380 cout << " ---------------------------"<<endl<<endl;
1381 parseAtom (undoCommand);
1382 mapCenter->reposition();
1386 if (curStep<1) curStep=undosTotal;
1390 blockSaveState=false;
1391 /* TODO remove testing
1393 cout << "ME::undo() end\n";
1394 cout << " undosAvail="<<undosAvail<<endl;
1395 cout << " redosAvail="<<redosAvail<<endl;
1396 cout << " curStep="<<curStep<<endl;
1397 cout << " ---------------------------"<<endl<<endl;
1399 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1400 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1401 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1402 undoSet.writeSettings(histPath);
1407 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1409 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1411 QFile file (bakMapPath);
1415 // We need to parse saved XML data
1416 mapBuilderHandler handler;
1417 QXmlInputSource source( file);
1418 QXmlSimpleReader reader;
1419 reader.setContentHandler( &handler );
1420 reader.setErrorHandler( &handler );
1421 handler.setMapEditor( this );
1422 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1423 if (undoSel.isEmpty())
1427 handler.setLoadMode (NewMap);
1431 handler.setLoadMode (ImportReplace);
1433 blockReposition=true;
1434 bool ok = reader.parse( source );
1435 blockReposition=false;
1438 // This should never ever happen
1439 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1440 tr( handler.errorProtocol() )+" in "+bakMapDir );
1444 QMessageBox::critical( 0, tr( "Critical Error" ),
1445 tr("Temporary directory %1 used for undo is gone. \n"
1446 "I will create a new one, but at the moment no undo is available.\n"
1447 "Maybe you want to reload your original data.\n\n"
1448 "Sorry for any inconveniences.").arg(bakMapDir) );
1453 void MapEditor::pasteNoSave()
1455 load (clipboardDir+"/part.xml",ImportAdd);
1458 void MapEditor::cutNoSave()
1464 void MapEditor::paste()
1466 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1467 typeid(*selection) == typeid(MapCenterObj)))
1469 saveStatePart(selection,QString("Paste to %1").arg( getName(selection)));
1471 mapCenter->reposition();
1476 void MapEditor::cut()
1478 saveStatePart(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
1481 mapCenter->reposition();
1485 void MapEditor::move(const int &x, const int &y)
1487 // TODO no saveState, because this is only internal at undo so far
1488 if (selection) selection->move(x,y);
1489 if (typeid(*selection) == typeid(FloatImageObj))
1490 ((FloatImageObj*)selection)->setRelPos();
1493 void MapEditor::moveBranchUp()
1497 if (typeid(*selection) == typeid(BranchObj) )
1499 bo=(BranchObj*)selection;
1500 if (!bo->canMoveBranchUp()) return;
1501 par=(BranchObj*)(bo->getParObj());
1502 selection->unselect();
1503 bo=par->moveBranchUp (bo); // bo will be the one below selection
1504 selection->select();
1505 saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1506 mapCenter->reposition();
1507 ensureSelectionVisible();
1511 void MapEditor::moveBranchDown()
1515 if (typeid(*selection) == typeid(BranchObj) )
1517 bo=(BranchObj*)selection;
1518 if (!bo->canMoveBranchDown()) return;
1519 par=(BranchObj*)(bo->getParObj());
1520 selection->unselect();
1521 bo=par->moveBranchDown(bo); // bo will be the one above selection
1522 selection->select();
1523 saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1524 mapCenter->reposition();
1525 ensureSelectionVisible();
1529 QString MapEditor::getHeading(bool &ok, QPoint &p)
1532 (typeid(*selection) == typeid(BranchObj) ||
1533 typeid(*selection) == typeid(MapCenterObj) ) )
1536 ensureSelectionVisible();
1537 p = ((BranchObj*)selection)->getAbsPos();
1538 p.setX (p.x() - contentsX());
1539 p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2);
1540 return ((BranchObj*)selection)->getHeading();
1546 void MapEditor::setHeading(const QString &s)
1549 (typeid(*selection) == typeid(BranchObj) ||
1550 typeid(*selection) == typeid(MapCenterObj) ) )
1552 editingBO=(BranchObj*)selection;
1553 saveStateConstSelection(
1554 "setHeading (\""+editingBO->getHeading()+"\")",
1555 "setHeading (\""+s+"\")",
1556 QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) );
1557 editingBO->setHeading(s );
1559 mapCenter->reposition();
1561 ensureSelectionVisible();
1565 void MapEditor::setURLInt (const QString &s)
1567 // Internal function, no saveState needed
1569 (typeid(*selection) == typeid(BranchObj) ||
1570 typeid(*selection) == typeid(MapCenterObj) ) )
1572 ((BranchObj*)selection)->setURL(s);
1573 mapCenter->reposition();
1575 ensureSelectionVisible();
1579 void MapEditor::setHeadingInt(const QString &s)
1582 (typeid(*selection) == typeid(BranchObj) ||
1583 typeid(*selection) == typeid(MapCenterObj) ) )
1585 ((BranchObj*)selection)->setHeading(s);
1586 mapCenter->reposition();
1588 ensureSelectionVisible();
1592 void MapEditor::setVymLinkInt (const QString &s)
1594 // Internal function, no saveState needed
1596 (typeid(*selection) == typeid(BranchObj) ||
1597 typeid(*selection) == typeid(MapCenterObj) ) )
1599 ((BranchObj*)selection)->setVymLink(s);
1600 mapCenter->reposition();
1602 ensureSelectionVisible();
1606 BranchObj* MapEditor::addNewBranchInt(int num)
1608 // Depending on pos:
1609 // -3 insert in childs of parent above selection
1610 // -2 add branch to selection
1611 // -1 insert in childs of parent below selection
1612 // 0..n insert in childs of parent at pos
1613 BranchObj *newbo=NULL;
1615 (typeid(*selection) == typeid(BranchObj) ||
1616 typeid(*selection) == typeid(MapCenterObj) ) )
1618 BranchObj* bo = (BranchObj*) selection;
1621 // save scroll state. If scrolled, automatically select
1622 // new branch in order to tmp unscroll parent...
1623 return bo->addBranch();
1628 bo=(BranchObj*)bo->getParObj();
1632 bo=(BranchObj*)bo->getParObj();
1635 newbo=bo->insertBranch(num);
1640 void MapEditor::addNewBranch(int pos)
1642 // Different meaning than num in addNewBranchInt!
1647 (typeid(*selection) == typeid(BranchObj) ||
1648 typeid(*selection) == typeid(MapCenterObj) ) )
1650 BranchObj *bo = (BranchObj*) selection;
1652 newbo=addNewBranchInt (pos-2);
1656 saveStateConstSelection (
1657 QString ("delete (\"%1\")").arg(newbo->getSelectString()),
1658 QString ("addBranch (%1)").arg(pos-2),
1659 QString ("Add new branch to %1").arg(getName(bo))); //TODO undoCommand
1661 LinkableMapObj *oldselection=selection;
1663 mapCenter->reposition();
1667 if (actionSettingsAutoedit->isOn() ||
1668 actionSettingsAutoselectHeading->isOn() )
1670 selection->unselect();
1672 selection->select();
1673 if (actionSettingsAutoedit->isOn() )
1674 mainWindow->editHeading();
1675 if (!actionSettingsAutoselectHeading->isOn()
1676 )//&& !wasScrolled) //FIXME wasScrolled was moved to addNewBranchInt
1678 selection->unselect();
1679 selection=oldselection;
1680 selection->select();
1688 void MapEditor::addNewBranchHere()
1691 (typeid(*selection) == typeid(BranchObj) ) )
1693 BranchObj* bo1 = (BranchObj*) selection;
1694 saveStatePart(selection, QString("Add new branch here").arg(getName(bo1)));
1696 bool wasScrolled=false;
1697 BranchObj *newbo=NULL;
1698 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1701 // add below selection
1702 newbo=parbo->insertBranch(bo1->getNum()+1);
1705 LinkableMapObj *oldselection=selection;
1706 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1708 mapCenter->reposition();
1710 if (actionSettingsAutoedit->isOn() ||
1711 actionSettingsAutoselectHeading->isOn() )
1713 selection->unselect();
1715 selection->select();
1716 if (actionSettingsAutoedit->isOn() )
1717 mainWindow->editHeading();
1718 if (!actionSettingsAutoselectHeading->isOn()
1721 selection->unselect();
1722 selection=oldselection;
1723 selection->select();
1729 void MapEditor::deleteSelection()
1731 if (selection && typeid(*selection) ==typeid(BranchObj) )
1733 BranchObj* bo=(BranchObj*)selection;
1734 BranchObj* par=(BranchObj*)(bo->getParObj());
1736 if (selection->getDepth()>1)
1737 // Normal branch, save parent with childs
1738 saveStatePart(par,QString("Delete %1").arg(getName(bo)));
1739 // naveState (UndoCom, par, QString("insertBranchAt (%1)", bo, "", QString ("Delete %1").arg(getName(bo))));
1741 // Mainbranch, save whole map
1742 // TODO Better would be to insert mainbranch again at pos
1743 // But undoCommand is missing right now
1744 saveStateComplete(QString("Delete %1").arg(getName(bo)));
1746 par->removeBranch(bo);
1748 selection->select();
1749 ensureSelectionVisible();
1750 mapCenter->reposition();
1753 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1755 FloatImageObj* fio=(FloatImageObj*)selection;
1756 BranchObj* par=(BranchObj*)(fio->getParObj());
1757 saveStatePart(par, QString("Delete %1").arg(getName(fio)));
1760 par->removeFloatImage(fio);
1762 selection->select();
1763 ensureSelectionVisible();
1764 mapCenter->reposition();
1769 LinkableMapObj* MapEditor::getSelection()
1774 void MapEditor::unselect()
1778 selectionLast=selection;
1779 selection->unselect();
1784 void MapEditor::reselect()
1788 selection=selectionLast;
1789 selection->select();
1794 bool MapEditor::select (const QString &s)
1796 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1798 // Finally select the found object
1801 if (selection) unselect();
1803 selection->select();
1805 ensureSelectionVisible();
1811 QString MapEditor::getSelectString()
1813 if (selection) return selection->getSelectString();
1817 void MapEditor::selectInt (LinkableMapObj *lmo)
1819 if (lmo && selection != lmo)
1821 // select the MapObj
1822 if (selection) selection->unselect();
1824 selection->select();
1830 void MapEditor::selectNextBranchInt()
1832 // Increase number of branch
1835 QString s=selection->getSelectString();
1841 part=s.section(",",-1);
1843 num=part.right(part.length() - 3);
1845 s=s.left (s.length() -num.length());
1848 num=QString ("%1").arg(num.toUInt()+1);
1852 // Try to select this one
1853 if (select (s)) return;
1855 // We have no direct successor,
1856 // try to increase the parental number in order to
1857 // find a successor with same depth
1859 int d=selection->getDepth();
1864 while (!found && d>0)
1866 s=s.section (",",0,d-1);
1867 // replace substring of current depth in s with "1"
1868 part=s.section(",",-1);
1870 num=part.right(part.length() - 3);
1874 // increase number of parent
1875 num=QString ("%1").arg(num.toUInt()+1);
1876 s=s.section (",",0,d-2) + ","+ typ+num;
1879 // Special case, look at orientation
1880 if (selection->getOrientation()==OrientRightOfCenter)
1881 num=QString ("%1").arg(num.toUInt()+1);
1883 num=QString ("%1").arg(num.toUInt()-1);
1888 // pad to oldDepth, select the first branch for each depth
1889 for (i=d;i<oldDepth;i++)
1894 if ( ((BranchObj*)selection)->countBranches()>0)
1902 // try to select the freshly built string
1910 void MapEditor::selectPrevBranchInt()
1912 // Decrease number of branch
1915 QString s=selection->getSelectString();
1921 part=s.section(",",-1);
1923 num=part.right(part.length() - 3);
1925 s=s.left (s.length() -num.length());
1928 num=QString ("%1").arg(num.toUInt()-1);
1932 // Try to select this one
1933 if (select (s)) return;
1935 // We have no direct precessor,
1936 // try to decrease the parental number in order to
1937 // find a precessor with same depth
1939 int d=selection->getDepth();
1944 while (!found && d>0)
1946 s=s.section (",",0,d-1);
1947 // replace substring of current depth in s with "1"
1948 part=s.section(",",-1);
1950 num=part.right(part.length() - 3);
1954 // decrease number of parent
1955 num=QString ("%1").arg(num.toUInt()-1);
1956 s=s.section (",",0,d-2) + ","+ typ+num;
1959 // Special case, look at orientation
1960 if (selection->getOrientation()==OrientRightOfCenter)
1961 num=QString ("%1").arg(num.toUInt()-1);
1963 num=QString ("%1").arg(num.toUInt()+1);
1968 // pad to oldDepth, select the last branch for each depth
1969 for (i=d;i<oldDepth;i++)
1973 if ( ((BranchObj*)selection)->countBranches()>0)
1974 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1981 // try to select the freshly built string
1989 void MapEditor::selectUpperBranch()
1993 if (typeid(*selection) == typeid(BranchObj))
1995 if (selection->getOrientation()==OrientRightOfCenter)
1996 selectPrevBranchInt();
1998 if (selection->getDepth()==1)
1999 selectNextBranchInt();
2001 selectPrevBranchInt();
2006 void MapEditor::selectLowerBranch()
2010 if (typeid(*selection) == typeid(BranchObj))
2012 if (selection->getOrientation()==OrientRightOfCenter)
2013 selectNextBranchInt();
2015 if (selection->getDepth()==1)
2016 selectPrevBranchInt();
2018 selectNextBranchInt();
2024 void MapEditor::selectLeftBranch()
2030 if (typeid(*selection) == typeid(MapCenterObj))
2032 par= (BranchObj*) selection;
2033 bo=par->getLastSelectedBranch();
2036 // Workaround for reselecting on left and right side
2037 if (bo->getOrientation()==OrientRightOfCenter)
2039 bo=par->getLastBranch();
2045 selection->select();
2047 ensureSelectionVisible();
2052 par=(BranchObj*)(selection->getParObj());
2053 if (selection->getOrientation()==OrientRightOfCenter)
2055 if (typeid(*selection) == typeid(BranchObj) ||
2056 typeid(*selection) == typeid(FloatImageObj))
2058 selection->unselect();
2060 selection->select();
2062 ensureSelectionVisible();
2066 if (typeid(*selection) == typeid(BranchObj) )
2068 bo=((BranchObj*)selection)->getLastSelectedBranch();
2071 selection->unselect();
2073 selection->select();
2075 ensureSelectionVisible();
2083 void MapEditor::selectRightBranch()
2090 if (typeid(*selection) == typeid(MapCenterObj))
2092 par= (BranchObj*) selection;
2093 bo=par->getLastSelectedBranch();
2096 // Workaround for reselecting on left and right side
2097 if (bo->getOrientation()==OrientLeftOfCenter)
2098 bo=par->getFirstBranch();
2103 selection->select();
2104 ensureSelectionVisible();
2109 par=(BranchObj*)(selection->getParObj());
2110 if (selection->getOrientation()==OrientLeftOfCenter)
2112 if (typeid(*selection) == typeid(BranchObj) ||
2113 typeid(*selection) == typeid(FloatImageObj))
2115 selection->unselect();
2117 selection->select();
2119 ensureSelectionVisible();
2123 if (typeid(*selection) == typeid(BranchObj) )
2125 bo=((BranchObj*)selection)->getLastSelectedBranch();
2128 selection->unselect();
2130 selection->select();
2132 ensureSelectionVisible();
2140 void MapEditor::selectFirstBranch()
2146 if (typeid(*selection) == typeid(BranchObj))
2148 bo1= (BranchObj*) selection;
2149 par=(BranchObj*)(bo1->getParObj());
2150 bo2=par->getFirstBranch();
2154 selection->select();
2155 ensureSelectionVisible();
2162 void MapEditor::selectLastBranch()
2168 if (typeid(*selection) == typeid(BranchObj))
2170 bo1= (BranchObj*) selection;
2171 par=(BranchObj*)(bo1->getParObj());
2172 bo2=par->getLastBranch();
2176 selection->select();
2177 ensureSelectionVisible();
2184 void MapEditor::setColor(QColor c)
2189 void MapEditor::selectBackgroundColor()
2191 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2192 if ( !col.isValid() ) return;
2193 setBackgroundColor( col );
2195 saveStateComplete(QString("Set background color of map to %1").arg(col.name()));
2198 void MapEditor::setBackgroundColor(QColor c)
2200 mapCanvas->setBackgroundColor (c);
2203 QColor MapEditor::pickColor()
2207 if (typeid(*selection) == typeid(BranchObj) ||
2208 typeid(*selection) == typeid(MapCenterObj))
2210 BranchObj *bo=(BranchObj*)selection;
2211 actColor=bo->getColor();
2217 void MapEditor::colorItem()
2221 if (typeid(*selection) == typeid(BranchObj) ||
2222 typeid(*selection) == typeid(MapCenterObj))
2224 BranchObj *bo=(BranchObj*)selection;
2225 saveStatePart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2226 bo->setColor(actColor); // color branch
2231 void MapEditor::colorBranch()
2235 if (typeid(*selection) == typeid(BranchObj) ||
2236 typeid(*selection) == typeid(MapCenterObj))
2238 BranchObj *bo=(BranchObj*)selection;
2239 saveStatePart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2240 bo->setColorChilds(actColor); // color links, color childs
2246 void MapEditor::toggleStandardFlag(QString f)
2250 if (typeid(*selection) == typeid(BranchObj) ||
2251 typeid(*selection) == typeid(MapCenterObj))
2253 BranchObj *bo=(BranchObj*)selection;
2255 if (bo->isSetStandardFlag(f))
2265 saveStateConstSelection(QString("%1 (\"%2\")").arg(u).arg(f),
2266 QString("%1 (\"%2\")").arg(r).arg(f),
2267 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2268 bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn());
2274 void MapEditor::setViewCenter()
2276 // transform to CanvasView Coord:
2277 QPoint p=worldMatrix().map(movingCenter);
2278 center ( p.x(), p.y());
2282 BranchObj* MapEditor::findText (QString s, bool cs)
2284 QTextDocument::FindFlags flags=0;
2285 if (cs) flags=QTextDocument::FindCaseSensitively;
2288 { // Nothing found or new find process
2290 // nothing found, start again
2292 itFind=mapCenter->first();
2294 bool searching=true;
2295 bool foundNote=false;
2296 while (searching && !EOFind)
2300 // Searching in Note
2301 if (itFind->getNote().contains(s,cs))
2303 if (selection!=itFind)
2305 if (selection) ((BranchObj*)selection)->unselect();
2307 selection->select();
2309 ensureSelectionVisible();
2311 if (textEditor->findText(s,flags))
2317 // Searching in Heading
2318 if (searching && itFind->getHeading().contains (s,cs) )
2320 if (selection) ((BranchObj*)selection)->unselect();
2322 selection->select();
2324 ensureSelectionVisible();
2330 itFind=itFind->next();
2331 if (!itFind) EOFind=true;
2337 return (BranchObj*)selection;
2342 void MapEditor::findReset()
2343 { // Necessary if text to find changes during a find process
2348 void MapEditor::editURL()
2350 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2351 typeid(*selection) == typeid(MapCenterObj)) )
2354 BranchObj *bo=(BranchObj*)selection;
2355 QString text = QInputDialog::getText(
2356 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2357 bo->getURL(), &ok, this );
2360 // user entered something and pressed OK
2361 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2368 QString MapEditor::getURL()
2370 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2371 typeid(*selection) == typeid(MapCenterObj)) )
2372 return ((BranchObj*)selection)->getURL();
2377 QStringList MapEditor::getURLs()
2380 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2381 typeid(*selection) == typeid(MapCenterObj)) )
2383 BranchObj *bo=(BranchObj*)selection;
2387 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2395 void MapEditor::editHeading2URL()
2397 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2398 typeid(*selection) == typeid(MapCenterObj)) )
2400 BranchObj *bo=(BranchObj*)selection;
2401 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2402 bo->setURL (bo->getHeading());
2407 void MapEditor::editBugzilla2URL()
2409 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2410 typeid(*selection) == typeid(MapCenterObj)) )
2412 BranchObj *bo=(BranchObj*)selection;
2413 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2414 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo)));
2420 void MapEditor::editFATE2URL()
2422 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2423 typeid(*selection) == typeid(MapCenterObj)) )
2425 BranchObj *bo=(BranchObj*)selection;
2426 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2427 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2433 void MapEditor::editVymLink()
2435 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2436 typeid(*selection) == typeid(MapCenterObj)) )
2438 BranchObj *bo=(BranchObj*)selection;
2439 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map"));
2440 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2441 fd->setCaption(__VYM " - " +tr("Link to another map"));
2442 if (! bo->getVymLink().isEmpty() )
2443 fd->setSelection( bo->getVymLink() );
2447 if ( fd->exec() == QDialog::Accepted )
2449 saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2450 bo->setVymLink (fd->selectedFile() );
2452 mapCenter->reposition();
2459 void MapEditor::deleteVymLink()
2461 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2462 typeid(*selection) == typeid(MapCenterObj)) )
2464 BranchObj *bo=(BranchObj*)selection;
2465 saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2466 bo->setVymLink ("" );
2468 mapCenter->reposition();
2474 void MapEditor::toggleHideExport()
2476 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2477 typeid(*selection) == typeid(MapCenterObj)) ||
2478 (typeid(*selection)==typeid(FloatImageObj))
2481 OrnamentedObj *oo=(OrnamentedObj*)selection;
2483 if (oo->hideInExport())
2485 oo->setHideInExport(false);
2490 oo->setHideInExport(true);
2493 saveStateComplete(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2494 actionEditToggleHideExport->setOn (oo->hideInExport());
2496 mapCenter->reposition();
2502 QString MapEditor::getVymLink()
2504 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2505 typeid(*selection) == typeid(MapCenterObj)) )
2507 return ((BranchObj*)selection)->getVymLink();
2513 QStringList MapEditor::getVymLinks()
2516 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2517 typeid(*selection) == typeid(MapCenterObj)) )
2519 BranchObj *bo=(BranchObj*)selection;
2523 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2531 void MapEditor::removeBranchKeepChilds()
2533 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2535 BranchObj* bo=(BranchObj*)selection;
2536 BranchObj* par=(BranchObj*)(bo->getParObj());
2537 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2538 if (bo->getDepth()==1)
2539 saveStateComplete(s);
2541 saveStatePart(selection->getParObj(),s); // TODO undoCommand
2542 QString sel=selection->getSelectString();
2544 par->removeBranchHere(bo);
2545 mapCenter->reposition();
2550 void MapEditor::removeChilds()
2552 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2554 saveStatePart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
2555 ((BranchObj*)selection)->removeChilds();
2556 mapCenter->reposition();
2560 void MapEditor::editMapInfo()
2562 ExtraInfoDialog dia;
2563 dia.setMapName (getFileName() );
2564 dia.setAuthor (mapCenter->getAuthor() );
2565 dia.setComment(mapCenter->getComment() );
2570 Q3CanvasItemList l=canvas()->allItems();
2571 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2573 stats+=QString ("%1 items on canvas\n").arg (i,6);
2580 bo=mapCenter->first();
2583 if (!bo->getNote().isEmpty() ) n++;
2584 f+= bo->countFloatImages();
2586 xl+=bo->countXLinks();
2589 stats+=QString ("%1 branches\n").arg (b-1,6);
2590 stats+=QString ("%1 xLinks \n").arg (xl,6);
2591 stats+=QString ("%1 notes\n").arg (n,6);
2592 stats+=QString ("%1 images\n").arg (f,6);
2593 dia.setStats (stats);
2595 // Finally show dialog
2596 if (dia.exec() == QDialog::Accepted)
2598 saveStateComplete("Edit info about map"); //TODO undoCommand
2599 mapCenter->setAuthor (dia.getAuthor() );
2600 mapCenter->setComment (dia.getComment() );
2604 void MapEditor::updateActions()
2607 if (getLinkColorHint()==HeadingColor)
2608 actionFormatLinkColorHint->setOn(true);
2610 actionFormatLinkColorHint->setOn(false);
2615 actionFormatLinkStyleLine->setOn(true);
2618 actionFormatLinkStyleParabel->setOn(true);
2621 actionFormatLinkStylePolyLine->setOn(true);
2623 case StylePolyParabel:
2624 actionFormatLinkStylePolyParabel->setOn(true);
2630 QPixmap pix( 16, 16 );
2631 pix.fill( mapCanvas->backgroundColor() );
2632 actionFormatBackColor->setIconSet( pix );
2633 pix.fill( defLinkColor );
2634 actionFormatLinkColor->setIconSet( pix );
2636 actionFileSave->setEnabled( mapUnsaved );
2637 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2638 actionEditUndo->setEnabled( true);
2640 actionEditUndo->setEnabled( false);
2642 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2643 actionEditRedo->setEnabled( true);
2645 actionEditRedo->setEnabled( false);
2649 if ( (typeid(*selection) == typeid(BranchObj)) ||
2650 (typeid(*selection) == typeid(MapCenterObj)) )
2652 BranchObj *bo=(BranchObj*)selection;
2653 // Take care of links
2654 if (bo->countXLinks()==0)
2656 branchXLinksContextMenuEdit->clear();
2657 branchXLinksContextMenuFollow->clear();
2662 branchXLinksContextMenuEdit->clear();
2663 branchXLinksContextMenuFollow->clear();
2664 for (int i=0; i<=bo->countXLinks();i++)
2666 bot=bo->XLinkTargetAt(i);
2669 s=bot->getHeading();
2672 branchXLinksContextMenuFollow->addAction (s);
2673 branchXLinksContextMenuEdit->addAction (s);
2678 standardFlagsDefault->setEnabled (true);
2680 actionEditToggleScroll->setEnabled (true);
2681 if ( bo->isScrolled() )
2682 actionEditToggleScroll->setOn(true);
2684 actionEditToggleScroll->setOn(false);
2686 if ( bo->getURL().isEmpty() )
2688 actionEditOpenURL->setEnabled (false);
2689 actionEditOpenURLTab->setEnabled (false);
2693 actionEditOpenURL->setEnabled (true);
2694 actionEditOpenURLTab->setEnabled (true);
2696 if ( bo->getVymLink().isEmpty() )
2698 actionEditOpenVymLink->setEnabled (false);
2699 actionEditDeleteVymLink->setEnabled (false);
2702 actionEditOpenVymLink->setEnabled (true);
2703 actionEditDeleteVymLink->setEnabled (true);
2706 if (bo->canMoveBranchUp())
2707 actionEditMoveUp->setEnabled (true);
2709 actionEditMoveUp->setEnabled (false);
2710 if (bo->canMoveBranchDown())
2711 actionEditMoveDown->setEnabled (true);
2713 actionEditMoveDown->setEnabled (false);
2716 actionEditToggleHideExport->setEnabled (true);
2717 actionEditToggleHideExport->setOn (bo->hideInExport() );
2719 actionEditCopy->setEnabled (true);
2720 actionEditCut->setEnabled (true);
2721 if (!clipboardEmpty)
2722 actionEditPaste->setEnabled (true);
2724 actionEditPaste->setEnabled (false);
2725 for (a=actionListBranches.first();a;a=actionListBranches.next())
2726 a->setEnabled(true);
2727 actionEditDelete->setEnabled (true);
2728 switch (selection->getFrameType())
2731 actionFormatFrameNone->setOn(true);
2734 actionFormatFrameRectangle->setOn(true);
2739 actionFormatIncludeImagesVer->setOn
2740 ( ((BranchObj*)selection)->getIncludeImagesVer());
2741 actionFormatIncludeImagesHor->setOn
2742 ( ((BranchObj*)selection)->getIncludeImagesHor());
2743 actionFormatHideLinkUnselected->setOn
2744 (selection->getHideLinkUnselected());
2746 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2748 FloatObj *fo=(FloatImageObj*)selection;
2749 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2751 actionEditOpenURL->setEnabled (false);
2752 actionEditOpenVymLink->setEnabled (false);
2753 actionEditDeleteVymLink->setEnabled (false);
2754 actionEditToggleHideExport->setEnabled (true);
2755 actionEditToggleHideExport->setOn (fo->hideInExport() );
2758 actionEditCopy->setEnabled (true);
2759 actionEditCut->setEnabled (true);
2760 actionEditPaste->setEnabled (false);
2761 for (a=actionListBranches.first();a;a=actionListBranches.next())
2762 a->setEnabled(false);
2763 actionEditDelete->setEnabled (true);
2764 actionFormatHideLinkUnselected->setOn
2765 ( selection->getHideLinkUnselected());
2766 actionEditMoveUp->setEnabled (false);
2767 actionEditMoveDown->setEnabled (false);
2772 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2774 actionEditCopy->setEnabled (false);
2775 actionEditCut->setEnabled (false);
2776 actionEditPaste->setEnabled (false);
2777 for (a=actionListBranches.first();a;a=actionListBranches.next())
2778 a->setEnabled(false);
2780 actionEditToggleScroll->setEnabled (false);
2781 actionEditOpenURL->setEnabled (false);
2782 actionEditOpenVymLink->setEnabled (false);
2783 actionEditDeleteVymLink->setEnabled (false);
2784 actionEditHeading2URL->setEnabled (false);
2785 actionEditDelete->setEnabled (false);
2786 actionEditMoveUp->setEnabled (false);
2787 actionEditMoveDown->setEnabled (false);
2788 actionEditToggleHideExport->setEnabled (false);
2792 void MapEditor::updateNoteFlag()
2795 if ( (typeid(*selection) == typeid(BranchObj)) ||
2796 (typeid(*selection) == typeid(MapCenterObj)) )
2797 ((BranchObj*)selection)->updateNoteFlag();
2800 void MapEditor::setLinkStyle (LinkStyle ls)
2804 saveStateComplete("Set link style"); // TODO undoCommand
2806 bo=mapCenter->first();
2810 bo->setLinkStyle(bo->getDefLinkStyle());
2813 mapCenter->reposition();
2816 LinkStyle MapEditor::getLinkStyle ()
2821 void MapEditor::setLinkColor(QColor c)
2827 void MapEditor::setLinkColorHint()
2829 // called from setLinkColorHint(lch) or at end of parse
2831 bo=mapCenter->first();
2839 void MapEditor::setLinkColorHint(LinkColorHint lch)
2845 void MapEditor::toggleLinkColorHint()
2847 if (linkcolorhint==HeadingColor)
2848 linkcolorhint=DefaultColor;
2850 linkcolorhint=HeadingColor;
2852 bo=mapCenter->first();
2860 LinkColorHint MapEditor::getLinkColorHint()
2862 return linkcolorhint;
2865 QColor MapEditor::getDefLinkColor()
2867 return defLinkColor;
2870 void MapEditor::setDefXLinkColor(QColor col)
2875 QColor MapEditor::getDefXLinkColor()
2877 return defXLinkColor;
2880 void MapEditor::setDefXLinkWidth (int w)
2885 int MapEditor::getDefXLinkWidth()
2887 return defXLinkWidth;
2890 void MapEditor::selectLinkColor()
2892 QColor col = QColorDialog::getColor( defLinkColor, this );
2893 if ( !col.isValid() ) return;
2894 setLinkColor( col );
2895 saveStateComplete(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2899 void MapEditor::toggleScroll()
2901 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2903 BranchObj *bo=((BranchObj*)selection);
2904 if (bo->countBranches()==0) return;
2905 if (bo->getDepth()==0) return;
2907 if (bo->isScrolled())
2911 saveStatePart(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2918 void MapEditor::unScrollAll()
2921 bo=mapCenter->first();
2924 if (bo->isScrolled()) bo->toggleScroll();
2929 void MapEditor::loadFloatImage ()
2932 (typeid(*selection) == typeid(BranchObj)) ||
2933 (typeid(*selection) == typeid(MapCenterObj)) )
2935 BranchObj *bo=((BranchObj*)selection);
2937 Q3FileDialog *fd=new Q3FileDialog( this);
2938 fd->setMode (Q3FileDialog::ExistingFiles);
2939 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2940 ImagePreview *p =new ImagePreview (fd);
2941 fd->setContentsPreviewEnabled( TRUE );
2942 fd->setContentsPreview( p, p );
2943 fd->setPreviewMode( Q3FileDialog::Contents );
2944 fd->setCaption(__VYM " - " +tr("Load image"));
2945 fd->setDir (lastImageDir);
2949 if ( fd->exec() == QDialog::Accepted )
2951 saveStatePart(selection, QString("Add floatimage to %1").arg(getName(selection)));
2952 // FIXME in QT4 use: lastImageDir=fd->directory();
2953 lastImageDir=QDir (fd->dirPath());
2954 QStringList flist = fd->selectedFiles();
2955 QStringList::Iterator it = flist.begin();
2956 while( it != flist.end() )
2959 bo->addFloatImage();
2960 // TODO check if load was successful
2961 bo->getLastFloatImage()->load(*it);
2962 bo->getLastFloatImage()->setOriginalFilename(fn);
2966 mapCenter->reposition();
2975 void MapEditor::saveFloatImage ()
2978 (typeid(*selection) == typeid(FloatImageObj)) )
2980 FloatImageObj *fio=((FloatImageObj*)selection);
2981 QFileDialog *fd=new QFileDialog( this);
2982 fd->setFilters (imageIO.getFilters());
2983 fd->setCaption(__VYM " - " +tr("Save image"));
2984 fd->setFileMode( QFileDialog::AnyFile );
2985 fd->setDirectory (lastImageDir);
2986 // fd->setSelection (fio->getOriginalFilename());
2990 if ( fd->exec() == QDialog::Accepted )
2992 if (QFile (fd->selectedFile()).exists() )
2994 QMessageBox mb( __VYM,
2995 tr("The file %1 exists already.\n"
2996 "Do you want to overwrite it?").arg(fd->selectedFile()),
2997 QMessageBox::Warning,
2998 QMessageBox::Yes | QMessageBox::Default,
2999 QMessageBox::Cancel | QMessageBox::Escape,
3000 QMessageBox::QMessageBox::NoButton );
3002 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3003 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3006 case QMessageBox::Yes:
3009 case QMessageBox::Cancel:
3015 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
3020 void MapEditor::setFrame(const FrameType &t)
3023 (typeid(*selection) == typeid(BranchObj)) ||
3024 (typeid(*selection) == typeid(MapCenterObj)) )
3026 selection->setFrameType (t);
3027 mapCenter->reposition();
3028 selection->updateLink();
3032 void MapEditor::setIncludeImagesVer(bool b)
3035 (typeid(*selection) == typeid(BranchObj)) ||
3036 (typeid(*selection) == typeid(MapCenterObj)) )
3037 ((BranchObj*)selection)->setIncludeImagesVer(b);
3038 mapCenter->reposition();
3041 void MapEditor::setIncludeImagesHor(bool b)
3044 (typeid(*selection) == typeid(BranchObj)) ||
3045 (typeid(*selection) == typeid(MapCenterObj)) )
3046 ((BranchObj*)selection)->setIncludeImagesHor(b);
3047 mapCenter->reposition();
3050 void MapEditor::setHideLinkUnselected (bool b)
3053 (typeid(*selection) == typeid(BranchObj)) ||
3054 (typeid(*selection) == typeid(MapCenterObj)) ||
3055 (typeid(*selection) == typeid(FloatImageObj)) )
3056 selection->setHideLinkUnselected(b);
3059 void MapEditor::importDirInt(BranchObj *dst, QDir d)
3062 (typeid(*selection) == typeid(BranchObj)) ||
3063 (typeid(*selection) == typeid(MapCenterObj)) )
3067 // Traverse directories
3068 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3069 QFileInfoList list = d.entryInfoList();
3072 for (int i = 0; i < list.size(); ++i)
3075 if (fi.fileName() != "." && fi.fileName() != ".." )
3078 bo=dst->getLastBranch();
3079 bo->setHeading (fi.fileName() );
3080 bo->setColor (QColor("blue"));
3082 if ( !d.cd(fi.fileName()) )
3083 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3086 // Recursively add subdirs
3087 importDirInt (bo,d);
3093 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3094 list = d.entryInfoList();
3096 for (int i = 0; i < list.size(); ++i)
3100 bo=dst->getLastBranch();
3101 bo->setHeading (fi.fileName() );
3102 bo->setColor (QColor("black"));
3103 if (fi.fileName().right(4) == ".vym" )
3104 bo->setVymLink (fi.filePath());
3109 void MapEditor::importDir()
3112 (typeid(*selection) == typeid(BranchObj)) ||
3113 (typeid(*selection) == typeid(MapCenterObj)) )
3115 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
3116 fd->setMode (Q3FileDialog::DirectoryOnly);
3117 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3118 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
3122 if ( fd->exec() == QDialog::Accepted )
3124 BranchObj *bo=((BranchObj*)selection);
3125 importDirInt (bo,QDir(fd->selectedFile()) );
3126 mapCenter->reposition();
3133 void MapEditor::followXLink(int i)
3136 (typeid(*selection) == typeid(BranchObj)) ||
3137 (typeid(*selection) == typeid(MapCenterObj)) )
3139 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3142 selection->unselect();
3144 selection->select();
3145 ensureSelectionVisible();
3150 void MapEditor::editXLink(int i)
3152 qDebug ("ko."); //FIXME Huh?
3154 (typeid(*selection) == typeid(BranchObj)) ||
3155 (typeid(*selection) == typeid(MapCenterObj)) )
3157 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3160 EditXLinkDialog dia;
3162 dia.setSelection(selection);
3163 if (dia.exec() == QDialog::Accepted)
3165 if (dia.useSettingsGlobal() )
3167 setDefXLinkColor (xlo->getColor() );
3168 setDefXLinkWidth (xlo->getWidth() );
3170 if (dia.deleteXLink())
3171 ((BranchObj*)selection)->deleteXLinkAt(i);
3172 saveStateComplete("Edit xLink"); //TODO undoCommand
3178 void MapEditor::testFunction()
3180 cout << "MapEditor::testFunction() called\n";
3184 QString text = QInputDialog::getText(
3186 tr("QInputDialog::getText()"),
3187 tr("User name:"), QLineEdit::Normal,
3188 QDir::home().dirName(), &ok, Qt::FramelessWindowHint);
3191 QDialog *d =new QDialog(NULL);
3192 QLineEdit *le=new QLineEdit (d);
3193 // d->setModal (true);
3194 d->setWindowFlags (Qt::FramelessWindowHint);
3196 le->setText ("Foo");
3198 connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
3200 qWarning( le->text());
3207 dia.setCancelButton (true);
3208 dia.setText("This is a longer \nWarning");
3209 dia.setCaption("Warning: Flux problem");
3210 dia.setShowAgainName("/warnings/mapeditor");
3211 dia.setWindowFlags (Qt::FramelessWindowHint);
3212 if (dia.exec()==QDialog::Accepted)
3213 cout << "accepted!\n";
3215 cout << "canceled!\n";
3219 /* Hide hidden stuff temporary, maybe add this as regular function somewhere
3220 if (hidemode==HideNone)
3222 setHideTmpMode (HideExport);
3223 mapCenter->calcBBoxSizeWithChilds();
3224 QRect totalBBox=mapCenter->getTotalBBox();
3225 QRect mapRect=totalBBox;
3226 QCanvasRectangle *frame=NULL;
3228 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3230 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3231 totalBBox.width(), totalBBox.height());
3232 frame=new QCanvasRectangle (mapRect,mapCanvas);
3233 frame->setBrush (QColor(white));
3234 frame->setPen (QColor(black));
3240 setHideTmpMode (HideNone);
3242 cout <<" hidemode="<<hidemode<<endl;
3246 void MapEditor::ensureSelectionVisible()
3250 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3252 if (selection->getOrientation() == OrientLeftOfCenter)
3253 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3255 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3256 ensureVisible (p.x(), p.y() );
3261 void MapEditor::updateViewCenter()
3263 // Update movingCenter, so that we can zoom comfortably later
3264 QRect rc = QRect( contentsX(), contentsY(),
3265 visibleWidth(), visibleHeight() );
3266 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3267 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3268 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3271 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3273 // Lineedits are already closed by preceding
3274 // mouseEvent, we don't need to close here.
3276 QPoint p = inverseWorldMatrix().map(e->pos());
3277 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3280 { // MapObj was found
3281 if (selection != lmo)
3283 // select the MapObj
3284 if (selection) selection->unselect();
3286 selection->select();
3292 if (typeid(*selection)==typeid(BranchObj) ||
3293 typeid(*selection)==typeid(MapCenterObj) )
3295 // Context Menu on branch or mapcenter
3297 branchContextMenu->popup(e->globalPos() );
3299 if (typeid(*selection)==typeid(FloatImageObj))
3301 // Context Menu on floatimage
3303 floatimageContextMenu->popup(e->globalPos() );
3307 { // No MapObj found, we are on the Canvas itself
3308 // Context Menu on Canvas
3310 canvasContextMenu->popup(e->globalPos() );
3315 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3317 // Ignore right clicks, these will go to context menus
3318 if (e->button() == Qt::RightButton )
3324 QPoint p = inverseWorldMatrix().map(e->pos());
3325 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3329 //Take care of clickdesystem flags _or_ modifier modes
3331 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3332 typeid(*lmo)==typeid(MapCenterObj) ))
3334 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3335 if (!foname.isEmpty())
3337 // systemFlag clicked
3341 if (e->state() & Qt::ControlModifier)
3342 mainWindow->editOpenURLTab();
3344 mainWindow->editOpenURL();
3346 else if (foname=="vymLink")
3348 mainWindow->editOpenVymLink();
3349 // tabWidget may change, better return now
3350 // before segfaulting...
3351 } else if (foname=="note")
3352 mainWindow->windowToggleNoteEditor();
3353 else if (foname=="hideInExport")
3358 // No system flag clicked, take care of modmodes
3360 // Special case: CTRL is pressed
3361 if (e->state() & Qt::ControlModifier)
3363 if (actionModModeColor->isOn())
3366 setCursor (pickColorCursor);
3369 if (actionModModeLink->isOn())
3371 BranchObj *bo_begin=NULL;
3373 bo_begin=(BranchObj*)(lmo);
3376 ((typeid(*selection) == typeid(BranchObj)) ||
3377 (typeid(*selection) == typeid(MapCenterObj))) )
3378 bo_begin=(BranchObj*)selection;
3382 linkingObj_src=bo_begin;
3383 tmpXLink=new XLinkObj (mapCanvas);
3384 tmpXLink->setBegin (bo_begin);
3385 tmpXLink->setEnd (p);
3386 tmpXLink->setColor(defXLinkColor);
3387 tmpXLink->setWidth(defXLinkWidth);
3388 tmpXLink->updateXLink();
3389 tmpXLink->setVisibility (true);
3397 // Left Button Move Branches
3398 if (e->button() == Qt::LeftButton )
3400 movingObj_start.setX( p.x() - selection->x() );
3401 movingObj_start.setY( p.y() - selection->y() );
3402 movingObj_orgPos.setX (lmo->x() );
3403 movingObj_orgPos.setY (lmo->y() );
3405 // If modMode==copy, then we want to "move" the _new_ object around
3406 // then we need the offset from p to the _old_ selection, because of tmp
3407 if (actionModModeCopy->isOn() &&
3408 e->state() & Qt::ControlModifier)
3410 if (typeid(*selection)==typeid(BranchObj) )
3413 mapCenter->addBranch ((BranchObj*)selection);
3415 selection=mapCenter->getLastBranch();
3416 selection->select();
3417 mapCenter->reposition();
3420 movingObj=selection;
3422 // Middle Button Toggle Scroll
3423 // (On Mac OS X this won't work, but we still have
3424 // a button in the toolbar)
3425 if (e->button() == Qt::MidButton )
3429 { // No MapObj found, we are on the Canvas itself
3430 // Left Button move Pos of CanvasView
3431 if (e->button() == Qt::LeftButton )
3433 movingObj=NULL; // move Content not Obj
3434 movingObj_start=e->globalPos();
3435 movingCont_start=QPoint (contentsX(), contentsY() );
3436 movingVec=QPoint(0,0);
3437 setCursor(handOpenCursor);
3442 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3444 QPoint p = inverseWorldMatrix().map(e->pos());
3446 // Move the selected MapObj
3447 if ( selection && movingObj)
3449 // To avoid jumping of the CanvasView, only
3450 // ensureSelectionVisible, if not tmp linked
3451 if (!selection->hasParObjTmp())
3452 ensureSelectionVisible ();
3454 // Now move the selection, but add relative position
3455 // (movingObj_start) where selection was chosen with
3456 // mousepointer. (This avoids flickering resp. jumping
3457 // of selection back to absPos)
3459 LinkableMapObj *lmosel;
3460 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3462 // Check if we could link
3463 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3466 if (typeid(*selection) == typeid(FloatImageObj))
3468 FloatObj *fo=(FloatObj*)selection;
3469 saveStateConstSelection(
3470 "move "+qpointToString(movingObj_orgPos),fo->getSelectString() ,
3471 QString("Move %1").arg(getName(selection)));
3472 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3476 // Relink float to new mapcenter or branch, if shift is pressed
3477 // Only relink, if selection really has a new parent
3478 if ( (e->state() & Qt::ShiftModifier) && lmo &&
3479 ( (typeid(*lmo)==typeid(BranchObj)) ||
3480 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3481 ( lmo != fo->getParObj())
3484 if (typeid(*fo) == typeid(FloatImageObj))
3487 saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3488 FloatImageObj *fio=(FloatImageObj*)(fo);
3489 ((BranchObj*)(lmo))->addFloatImage (fio);
3491 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3492 fio=((BranchObj*)(lmo))->getLastFloatImage();
3495 selection=(LinkableMapObj*)(fio);
3496 selection->select();
3497 movingObj=(MapObj*)(fio);
3500 } else // selection != a FloatObj
3502 if (lmosel->getDepth()==0)
3504 if (e->state() == Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3505 // If mapCenter is moved, move all the rest by default, too.
3506 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3508 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3511 if (lmosel->getDepth()==1)
3513 // depth==1, mainbranch
3514 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3518 if (lmosel->getOrientation() == OrientLeftOfCenter)
3519 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3520 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3521 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3523 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3525 // reposition subbranch
3526 lmosel->reposition();
3527 //ensureSelectionVisible();
3529 if (lmo && (lmo!=selection) &&
3530 (typeid(*lmo) == typeid(BranchObj) ||
3531 (typeid(*lmo) == typeid(MapCenterObj) )
3534 if (e->state() & Qt::ControlModifier)
3536 // Special case: CTRL to link below lmo
3537 lmosel->setParObjTmp (lmo,p,+1);
3539 else if (e->state() & Qt::ShiftModifier)
3540 lmosel->setParObjTmp (lmo,p,-1);
3542 lmosel->setParObjTmp (lmo,p,0);
3545 lmosel->unsetParObjTmp();
3549 } // no FloatImageObj
3553 } // selection && moving_obj
3555 // Draw a link from one branch to another
3558 tmpXLink->setEnd (p);
3559 tmpXLink->updateXLink();
3563 if (!movingObj && !pickingColor &&!drawingLink)
3565 QPoint p=e->globalPos();
3566 movingVec.setX(-p.x() + movingObj_start.x() );
3567 movingVec.setY(-p.y() + movingObj_start.y() );
3568 setContentsPos( movingCont_start.x() + movingVec.x(),
3569 movingCont_start.y() + movingVec.y());
3576 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3578 LinkableMapObj *dst;
3579 // Have we been picking color?
3583 setCursor (Qt::ArrowCursor);
3584 // Check if we are over another branch
3585 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3586 if (dst && selection)
3588 if (e->state() & Qt::ShiftModifier)
3590 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3591 ((BranchObj*)selection)->setLinkColor ();
3595 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3596 ((BranchObj*)selection)->setLinkColor ();
3602 // Have we been drawing a link?
3606 // Check if we are over another branch
3607 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3608 if (dst && selection)
3610 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3611 tmpXLink->updateXLink();
3612 tmpXLink->activate();
3613 saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3622 // Have we been moving something?
3623 if ( selection && movingObj )
3625 // Moved FloatObj? Maybe we need to reposition
3626 if(typeid(*selection)==typeid (FloatImageObj))
3628 selection->getParObj()->requestReposition();
3629 mapCenter->reposition();
3632 // Check if we are over another branch, but ignore
3633 // any found LMOs, which are FloatObjs
3634 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3635 ((LinkableMapObj*)selection) );
3637 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3640 // Now check, if we have been moving a branch
3641 if (typeid(*selection) == typeid(BranchObj) )
3643 // save the position in case we link to mapcenter
3644 QPoint savePos=QPoint (selection->x(),selection->y() );
3646 // Reset the temporary drawn link to the original one
3647 ((LinkableMapObj*)selection)->unsetParObjTmp();
3649 // For Redo we may need to save original selection
3650 QString orgSel=selection->getSelectString();
3655 BranchObj* bsel=(BranchObj*)selection;
3656 BranchObj* bdst=(BranchObj*)dst;
3659 QString undoCom="linkBranchToPos (\""+
3660 (bsel->getParObj())->getSelectString()+
3662 QString("%1").arg(bsel->getNum())+
3664 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3667 // Modifiers allow to insert above/below dst
3668 if (e->state() & Qt::ShiftModifier)
3670 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
3672 if (e->state() & Qt::ControlModifier)
3674 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
3677 bsel->moveBranchTo (bdst,-1);
3678 if (dst->getDepth()==0)
3679 bsel->move (savePos);
3681 QString redoCom="linkBranchToPos (\""+
3682 ((BranchObj*)(bsel->getParObj()))->getSelectString()+
3684 QString("%1").arg(bsel->getNum())+
3686 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+
3690 selection->getSelectString(),undoCom,
3692 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
3694 if (selection->getDepth()==1)
3696 // The select string might be different _after_ moving around.
3697 // Therefor reposition and then use string of old selection, too
3698 mapCenter->reposition();
3700 QString ps=qpointToString ( ((BranchObj*)selection)->getAbsPos() );
3702 selection->getSelectString(), "move "+qpointToString(movingObj_orgPos),
3704 QString("Move %1 to %2").arg(getName(selection)).arg(ps));
3707 // Draw the original link, before selection was moved around
3708 mapCenter->reposition();
3710 // Finally resize canvas, if needed
3715 // maybe we moved View: set old cursor
3716 setCursor (Qt::ArrowCursor);
3720 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3722 if (e->button() == Qt::LeftButton )
3724 QPoint p = inverseWorldMatrix().map(e->pos());
3725 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3726 if (lmo) { // MapObj was found
3727 // First select the MapObj than edit heading
3728 if (selection) selection->unselect();
3730 selection->select();
3731 mainWindow->editHeading();
3736 void MapEditor::resizeEvent (QResizeEvent* e)
3738 Q3CanvasView::resizeEvent( e );
3742 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3745 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3746 // cerr << event->format(i) << endl;
3749 (typeid(*selection) == typeid(BranchObj)) ||
3750 (typeid(*selection) == typeid(MapCenterObj))) {
3752 // If QImageDrag can decode mime type
3753 if (Q3ImageDrag::canDecode(event)) {
3758 // If image are dragged from firefox
3759 if (event->provides("application/x-moz-file-promise-url") &&
3760 event->provides("application/x-moz-nativeimage")) {
3761 event->accept(true);
3765 // If QUriDrag can decode mime type
3766 if (Q3UriDrag::canDecode(event)) {
3771 // If Uri are dragged from firefox
3772 if (event->provides("_NETSCAPE_URL")){
3777 // If QTextDrag can decode mime type
3778 if (Q3TextDrag::canDecode(event)) {
3787 bool isUnicode16(const QByteArray &d)
3789 // TODO: make more precise check for unicode 16.
3790 // Guess unicode16 if any of second bytes are zero
3791 unsigned int length = max(0,d.size()-2)/2;
3792 for (unsigned int i = 0; i<length ; i++)
3793 if (d.at(i*2+1)==0) return true;
3797 void MapEditor::contentsDropEvent(QDropEvent *event)
3800 (typeid(*selection) == typeid(BranchObj)) ||
3801 (typeid(*selection) == typeid(MapCenterObj)))
3806 if (event->provides("image/png"))
3809 if (Q3ImageDrag::decode(event, pix))
3817 } else if (event->provides("application/x-moz-file-promise-url") &&
3818 event->provides("application/x-moz-nativeimage"))
3820 // Contains url to the img src in unicode16
3821 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3822 QString url = QString((const QChar*)d.data(),d.size()/2);
3826 } else if (event->provides ("text/uri-list"))
3827 { // Uris provided e.g. by konqueror
3828 Q3UriDrag::decode (event,uris);
3829 } else if (event->provides ("_NETSCAPE_URL"))
3830 { // Uris provided by Mozilla
3831 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3834 } else if (event->provides("text/html")) {
3836 // Handels text mime types
3837 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3838 QByteArray d = event->encodedData("text/html");
3841 text = QString((const QChar*)d.data(),d.size()/2);
3845 textEditor->setText(text);
3849 } else if (event->provides("text/plain")) {
3850 QByteArray d = event->encodedData("text/plain");
3853 text = QString((const QChar*)d.data(),d.size()/2);
3857 textEditor->setText(text);
3869 for (const char* u=uris.first(); u; u=uris.next())
3871 bo=((BranchObj*)selection)->addBranch();
3874 s=Q3UriDrag::uriToLocalFile(u);
3877 QString file = QDir::convertSeparators(s);
3878 heading = QFileInfo(file).baseName();
3880 if (file.endsWith(".vym", false))
3881 bo->setVymLink(file);
3890 if (!heading.isEmpty())
3891 bo->setHeading(heading);
3901 //FIXME saveState has to be called earlier for each of the drops...
3902 saveStateComplete("Drop Event"); //TODO undo Command
3903 mapCenter->reposition();
3910 void MapEditor::addFloatImage(const QPixmap &img)
3913 (typeid(*selection) == typeid(BranchObj)) ||
3914 (typeid(*selection) == typeid(MapCenterObj)) )
3916 BranchObj *bo=((BranchObj*)selection);
3917 saveStatePart(selection,QString("Add floatimage to %1").arg(getName(bo)));
3918 //QString fn=fd->selectedFile();
3919 //lastImageDir=fn.left(fn.findRev ("/"));
3920 bo->addFloatImage();
3921 // FIXME check if load was successful
3922 bo->getLastFloatImage()->load(img);
3923 //bo->getLastFloatImage()->setOriginalFilename(fn);
3924 mapCenter->reposition();
3931 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
3933 if (!imageBuffer) imageBuffer = new QBuffer();
3934 if (!imageBuffer->isOpen()) {
3935 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3937 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3941 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3943 if (nop->state()==Q3NetworkProtocol::StDone) {
3944 QPixmap img(imageBuffer->buffer());
3949 imageBuffer->close();
3951 imageBuffer->close();
3958 void MapEditor::fetchImage(const QString &url)
3961 urlOperator->stop();
3962 disconnect(urlOperator);
3966 urlOperator = new Q3UrlOperator(url);
3967 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
3968 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
3970 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
3971 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));