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 undosTotal=settings.readNumEntry("/mapeditor/undoLevels",50);
214 // Initialize find routine
221 blockReposition=false;
222 blockSaveState=false;
226 isInteractive=interactive;
228 // Create temporary files
231 // Initially set movingCentre
234 // For testing purposes create history window
235 historyWindow = new ShowTextDialog (this);
236 historyWindow->setCaption (fileName);
238 mapCenter->reposition(); // for positioning heading
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 (<font color=\"#0000ff\">%1</font>)").arg(s);
357 if ((typeid(*lmo) == typeid(FloatImageObj) ))
358 return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
359 return QString("Unknown type has no name!");
362 void MapEditor::makeTmpDirs()
364 // Create unique temporary directories
365 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
366 histPath=QDir::convertSeparators (tmpMapDir+"/history");
368 d.mkdir (tmpMapDir,true);
371 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSel)
373 // tmpdir temporary directory to which data will be written
374 // prefix mapname, which will be appended to images etc.
375 // writeflags Only write flags for "real" save of map, not undo
376 // offset offset of bbox of whole map in canvas.
377 // Needed for XML export
393 ls="StylePolyParabel";
397 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
399 if (linkcolorhint==HeadingColor)
400 colhint=attribut("linkColorHint","HeadingColor");
402 QString mapAttr=attribut("version",__VYM_VERSION);
404 mapAttr+= attribut("author",mapCenter->getAuthor()) +
405 attribut("comment",mapCenter->getComment()) +
406 attribut("date",mapCenter->getDate()) +
407 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
408 attribut("linkStyle", ls ) +
409 attribut("linkColor", defLinkColor.name() ) +
410 attribut("defXLinkColor", defXLinkColor.name() ) +
411 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
413 s+=beginElement("vymmap",mapAttr);
416 // Find the used flags while traversing the tree
417 standardFlagsDefault->resetUsedCounter();
419 // Reset the counters before saving
420 FloatImageObj (mapCanvas).resetSaveCounter();
422 // Build xml recursivly
424 // Save complete map, if saveSel not set
425 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
428 if ( typeid(*saveSel) == typeid(BranchObj) )
430 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
431 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
433 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
435 else if (selection && typeid(*selection)==typeid(BranchObj))
436 // Save selected branch is saved from mainwindow //FIXME maybe use "subtree" above?
437 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
440 // Save local settings
441 s+=settings.getXMLData (destPath);
444 if (selection && !saveSel )
445 s+=valueElement("select",selection->getSelectString());
448 s+=endElement("vymmap");
451 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
455 void MapEditor::saveStateComplete(const QString &comment)
457 // Save complete map, Undo will replace whole map
458 saveState (CompleteMap,
465 void MapEditor::saveStatePart(LinkableMapObj *undoSel, const QString &comment)
467 // save the selected part of the map, Undo will replace part of map
468 QString undoSelection="";
469 if (undoSel) undoSelection=undoSel->getSelectString();
471 saveState (PartOfMap,
478 void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment)
480 // selection does not change during action,
481 // so just save commands for undo and redo
482 // and use current selection
485 if (selection) sel=selection->getSelectString();
487 saveState (UndoCommand,
494 void MapEditor::saveStateComData(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel)
496 QString redoSelection="";
497 if (redoSel) redoSelection=redoSel->getSelectString();
498 QString undoSelection="";
499 if (undoSel) undoSelection=undoSel->getSelectString();
501 saveState (UndoCommand,
503 redoSelection, "FIXME-redoCom", //FIXME
508 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
510 // "Normal" savestate: save commands, selections and comment
511 // so just save commands for undo and redo
512 // and use current selection
514 QString redoSelection="";
515 if (redoSel) redoSelection=redoSel->getSelectString();
516 QString undoSelection="";
517 if (undoSel) undoSelection=undoSel->getSelectString();
519 saveState (UndoCommand,
526 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
528 // "Normal" savestate: save commands, selections and comment
529 // so just save commands for undo and redo
530 // and use current selection
531 saveState (UndoCommand,
539 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
543 if (blockSaveState) return;
545 /* TODO remove after testing
547 cout << "ME::saveState() begin"<<endl;
548 historyWindow->append (comment);
552 int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
553 int curStep=undoSet.readNumEntry ("/history/curStep",0);
554 // Find out current undo directory
555 if (undosAvail<undosTotal) undosAvail++;
557 if (curStep>undosTotal) curStep=1;
560 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
561 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
563 // Create bakMapDir if not available
566 makeSubDirs (bakMapDir);
568 // Save depending on how much needs to be saved
572 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel);
574 QString undoCommand="";
575 if (savemode==UndoCommand)
579 else if (savemode==PartOfMap )
581 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
584 undoCommand="undoMap (\""+bakMapPath+"\")";
586 if (!backupXML.isEmpty())
587 // Write XML Data to disk
588 saveStringToDisk (QString(bakMapPath),backupXML);
590 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
591 undoSet.setEntry ("/history/curStep",QString::number(curStep));
592 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
593 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
594 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
595 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
596 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
597 undoSet.writeSettings(histPath);
599 /* TODO remove after testing
601 //cout << " into="<< histPath.toStdString()<<endl;
602 cout << " undosTotal="<<undosTotal<<
603 ", undosAvail="<<undosAvail<<
604 ", curStep="<<curStep<<endl;
605 cout << " ---------------------------"<<endl;
606 cout << " comment="<<comment.toStdString()<<endl;
607 cout << " undoCom="<<undoCommand.toStdString()<<endl;
608 cout << " undoSel="<<undoSelection.toStdString()<<endl;
609 cout << " redoCom="<<redoCom.toStdString()<<endl;
610 cout << " redoSel="<<redoSelection.toStdString()<<endl;
611 cout << " ---------------------------"<<endl;
614 void MapEditor::parseAtom(const QString &atom)
621 // Split string s into command and parameters
622 api.parseCommand (atom);
623 QString com=api.command();
626 if (com=="moveBranchUp")
628 else if (com=="moveBranchDown")
630 else if (com=="move")
632 if (api.checkParamCount(2) && selection )
642 else if (com=="moveRel")
644 if (api.checkParamCount(2) && selection )
650 if (ok) moveRel (x,y);
654 else if (com=="delete")
656 if (api.checkParamCount(1) && selection )
658 s=api.parString(ok,0);
659 if (ok &&select (s)) deleteSelection();
662 else if (com=="addBranch")
664 if (api.checkParamCount(1) && selection )
667 if (ok ) addNewBranchInt (y);
670 else if (com=="linkBranchToPos")
672 if (selection && typeid(*selection) == typeid(BranchObj) )
674 if (api.checkParamCount(4))
676 // 0 selectstring of parent
677 // 1 num in parent (for branches)
678 // 2,3 x,y of mainbranch or mapcenter
679 s=api.parString(ok,0);
680 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
683 if (typeid(*dst) == typeid(BranchObj) )
685 // Get number in parent
688 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
689 } else if (typeid(*dst) == typeid(MapCenterObj) )
691 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
692 // Get coordinates of mainbranch
697 if (ok) ((BranchObj*)selection)->move (x,y);
703 } else if (com=="setHeading")
705 if (api.checkParamCount(1))
707 s=api.parString (ok,0);
711 } else if (com=="setURL")
713 if (api.checkParamCount(1))
715 s=api.parString (ok,0);
716 if (ok) setURLInt(s);
718 } else if (com=="setVymLink")
720 if (api.checkParamCount(1))
722 s=api.parString (ok,0);
723 if (ok) setVymLinkInt(s);
726 else if (com=="setFlag")
728 if (selection && typeid(*selection) == typeid(BranchObj) )
730 if (api.checkParamCount(1) )
732 s=api.parString(ok,0);
735 BranchObj* bo=(BranchObj*)selection;
736 bo->activateStandardFlag(s);
737 bo->updateFlagsToolbar();
742 else if (com=="unsetFlag")
744 if (selection && typeid(*selection) == typeid(BranchObj) )
746 if (api.checkParamCount(1) )
748 s=api.parString(ok,0);
751 BranchObj* bo=(BranchObj*)selection;
752 bo->deactivateStandardFlag(s);
753 bo->updateFlagsToolbar();
758 // Internal commands, used for undo etc.
759 else if (com==QString("undoMap"))
761 if (api.checkParamCount(1))
762 undoXML("",api.parString (ok,0));
763 } else if (com==QString("undoPart"))
765 if (api.checkParamCount(2))
767 s=api.parString (ok,0); // undo selection
768 t=api.parString (ok,1); // backup dir
771 } else if (com=="select")
773 if (api.checkParamCount(1))
775 s=api.parString(ok,0);
781 api.setError ("Unknown command in: "+atom);
787 // TODO Error handling
788 qWarning("MapEditor::parseAtom: Error!");
789 qWarning(api.errorDesc());
793 void MapEditor::toggleHistoryWindow()
795 if (historyWindow->isVisible())
796 historyWindow->hide();
798 historyWindow->show();
802 bool MapEditor::isDefault()
807 bool MapEditor::isUnsaved()
812 bool MapEditor::hasChanged()
817 void MapEditor::setChanged()
822 actionEditUndo->setEnabled (true);
823 actionFileSave->setEnabled (true);
827 void MapEditor::closeMap()
829 // Unselect before disabling the toolbar actions
830 if (selection) selection->unselect();
838 void MapEditor::setFilePath(QString fname)
840 setFilePath (fname,fname);
843 void MapEditor::setFilePath(QString fname, QString destname)
845 if (fname.isEmpty() || fname=="")
852 filePath=fname; // becomes absolute path
853 fileName=fname; // gets stripped of path
854 destPath=destname; // needed for vymlinks
856 // If fname is not an absolute path, complete it
857 filePath=QDir(fname).absPath();
858 fileDir=filePath.left (1+filePath.findRev ("/"));
860 // Set short name, too. Search from behind:
861 int i=fileName.findRev("/");
862 if (i>=0) fileName=fileName.remove (0,i+1);
864 // Forget the .vym (or .xml) for name of map
865 mapName=fileName.left(fileName.findRev(".",-1,true) );
867 // Adjust history window
868 historyWindow->setCaption (fileName);
872 QString MapEditor::getFilePath()
877 QString MapEditor::getFileName()
882 QString MapEditor::getMapName()
887 QString MapEditor::getDestPath()
892 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
894 ErrorCode err=success;
898 if (selection) selection->unselect();
901 mapCenter->setMapEditor(this);
902 // (map state is set later at end of load...)
905 saveStatePart(selection,"Load map");
909 mapBuilderHandler handler;
912 // I am paranoid: file should exist anyway
913 // according to check in mainwindow.
916 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
917 tr("Couldn't open map " +fname)+".");
921 blockReposition=true;
922 QXmlInputSource source( file);
923 QXmlSimpleReader reader;
924 reader.setContentHandler( &handler );
925 reader.setErrorHandler( &handler );
926 handler.setMapEditor( this );
927 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
928 handler.setInputFile (file.name());
929 handler.setLoadMode (lmode);
931 bool ok = reader.parse( source );
932 blockReposition=false;
933 blockSaveState=false;
937 mapCenter->reposition();
947 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
948 tr( handler.errorProtocol() ) );
950 // Still return "success": the map maybe at least
951 // partially read by the parser
958 int MapEditor::save (const SaveMode &savemode)
962 // The SaveMode UndoCommand is not supported here
963 if (savemode==UndoCommand) return 1;
965 // Create mapName and fileDir
966 makeSubDirs (fileDir);
970 fname=mapName+".xml";
972 // use name given by user, even if he chooses .doc
977 if (savemode==CompleteMap || selection==NULL)
978 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
980 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
982 if (!saveStringToDisk(fileDir+fname,saveFile))
989 actionFileSave->setEnabled(false);
995 void MapEditor::setZipped (bool z)
1000 bool MapEditor::saveZipped ()
1005 void MapEditor::print()
1009 printer = new QPrinter;
1010 printer->setColorMode (QPrinter::Color);
1011 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1014 QRect totalBBox=mapCenter->getTotalBBox();
1016 // Try to set orientation automagically
1017 // Note: Interpretation of generated postscript is amibiguous, if
1018 // there are problems with landscape mode, see
1019 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1021 if (totalBBox.width()>totalBBox.height())
1022 // recommend landscape
1023 printer->setOrientation (QPrinter::Landscape);
1025 // recommend portrait
1026 printer->setOrientation (QPrinter::Portrait);
1028 if ( printer->setup(this) )
1029 // returns false, if printing is canceled
1031 QPainter pp(printer);
1033 // Don't print the visualisation of selection
1034 LinkableMapObj *oldselection=NULL;
1037 oldselection=selection;
1038 selection->unselect();
1041 // Handle sizes of map and paper:
1043 // setWindow defines which part of the canvas will be transformed
1044 // setViewport defines area on paper in device coordinates (dpi)
1045 // e.g. (0,50,700,700) is upper part on A4
1046 // see also /usr/lib/qt3/doc/html/coordsys.html
1048 Q3PaintDeviceMetrics metrics (printer);
1050 double paperAspect = (double)metrics.width() / (double)metrics.height();
1051 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1053 QRect mapRect=totalBBox;
1054 Q3CanvasRectangle *frame=NULL;
1055 Q3CanvasText *footerFN=NULL;
1056 Q3CanvasText *footerDate=NULL;
1057 if (printFrame || printFooter)
1062 // Print frame around map
1063 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1064 totalBBox.width()+20, totalBBox.height()+20);
1065 frame=new Q3CanvasRectangle (mapRect,mapCanvas);
1066 frame->setBrush (QColor(Qt::white));
1067 frame->setPen (QColor(Qt::black));
1071 /* TODO remove after testing
1072 QCanvasLine *l=new QCanvasLine (mapCanvas);
1073 l->setPoints (0,0,mapRect.width(),mapRect.height());
1074 l->setPen (QPen(QColor(black), 1));
1081 // Print footer below map
1083 font.setPointSize(10);
1084 footerFN=new Q3CanvasText (mapCanvas);
1085 footerFN->setText ("VYM - " + fileName);
1086 footerFN->setFont(font);
1087 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1088 footerFN->setZ(Z_TEXT);
1090 footerDate=new Q3CanvasText (mapCanvas);
1091 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1092 footerDate->setFont(font);
1093 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1094 footerDate->setZ(Z_TEXT);
1097 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1100 pp.setWindow (mapRect);
1103 if (mapAspect>=paperAspect)
1105 // Fit horizontally to paper width
1106 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1109 // Fit vertically to paper height
1110 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1113 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1115 // Delete Frame and footer
1119 delete (footerDate);
1121 if (frame) delete (frame);
1123 // Restore selection
1126 selection=oldselection;
1127 selection->select();
1130 // Save settings in vymrc
1131 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1135 QPixmap MapEditor::getPixmap()
1137 QRect mapRect=mapCenter->getTotalBBox();
1138 QPixmap pix (mapRect.size());
1141 // Don't print the visualisation of selection
1142 LinkableMapObj *oldselection=NULL;
1145 oldselection=selection;
1146 selection->unselect();
1149 pp.setWindow (mapRect);
1151 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1154 // Restore selection
1157 selection=oldselection;
1158 selection->select();
1164 void MapEditor::setHideTmpMode (HideTmpMode mode)
1167 mapCenter->setHideTmp (hidemode);
1168 mapCenter->reposition();
1173 HideTmpMode MapEditor::getHideTmpMode()
1178 void MapEditor::exportImage(QString fn)
1180 setExportMode (true);
1181 QPixmap pix (getPixmap());
1182 pix.save(fn, "PNG");
1183 setExportMode (false);
1186 void MapEditor::setExportMode (bool b)
1188 // should be called before and after exports
1189 // depending on the settings
1190 if (b && settings.value("/export/useHideExport","yes")=="yes")
1191 setHideTmpMode (HideExport);
1193 setHideTmpMode (HideNone);
1196 void MapEditor::exportImage(QString fn, QString format)
1198 setExportMode (true);
1199 QPixmap pix (getPixmap());
1200 pix.save(fn, format);
1201 setExportMode (false);
1204 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1208 ex.setMapCenter(mapCenter);
1209 if (ex.setConfigFile(cf))
1211 setExportMode (true);
1212 ex.exportPresentation();
1213 setExportMode (false);
1219 void MapEditor::exportXML(const QString &dir)
1221 // Hide stuff during export, if settings want this
1222 setExportMode (true);
1224 // Create subdirectories
1227 // write to directory
1228 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1231 file.setName ( dir + "/"+mapName+".xml");
1232 if ( !file.open( QIODevice::WriteOnly ) )
1234 // This should neverever happen
1235 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1239 // Write it finally, and write in UTF8, no matter what
1240 QTextStream ts( &file );
1241 ts.setEncoding (QTextStream::UnicodeUTF8);
1245 // Now write image, too
1246 exportImage (dir+"/images/"+mapName+".png");
1248 setExportMode (false);
1251 void MapEditor::clear()
1255 selection->unselect();
1262 void MapEditor::copy()
1266 // write to directory
1267 QString clipfile="part";
1268 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1271 file.setName ( clipboardDir + "/"+clipfile+".xml");
1272 if ( !file.open( QIODevice::WriteOnly ) )
1274 // This should neverever happen
1275 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1279 // Write it finally, and write in UTF8, no matter what
1280 QTextStream ts( &file );
1281 ts.setEncoding (QTextStream::UnicodeUTF8);
1285 clipboardEmpty=false;
1290 void MapEditor::redo()
1292 blockSaveState=true;
1294 // Restore variables
1295 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1296 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1297 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1298 if (redosAvail>0) redosAvail--;
1299 if (undosAvail<undosTotal) undosAvail++;
1301 if (curStep>undosTotal) curStep=1;
1302 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1303 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1304 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1305 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1306 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1308 // Find out current undo directory
1309 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1311 /* TODO remove testing
1313 cout << "ME::redo() begin\n";
1314 cout << " undosAvail="<<undosAvail<<endl;
1315 cout << " redosAvail="<<redosAvail<<endl;
1316 cout << " curStep="<<curStep<<endl;
1317 cout << " ---------------------------"<<endl;
1318 cout << " comment="<<comment.toStdString()<<endl;
1319 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1320 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1321 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1322 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1323 cout << " ---------------------------"<<endl<<endl;
1325 // select object before redo
1326 // FIXME better give up if no selection there...
1327 if (!redoSelection.isEmpty())
1328 select (redoSelection);
1331 parseAtom (redoCommand);
1332 mapCenter->reposition();
1334 blockSaveState=false;
1336 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1337 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1338 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1339 undoSet.writeSettings(histPath);
1343 /* TODO remove testing
1345 cout << "ME::redo() end\n";
1346 cout << " undosAvail="<<undosAvail<<endl;
1347 cout << " redosAvail="<<redosAvail<<endl;
1348 cout << " curStep="<<curStep<<endl;
1349 cout << " ---------------------------"<<endl<<endl;
1354 void MapEditor::undo()
1356 blockSaveState=true;
1358 // Restore variables
1359 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1360 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1361 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1362 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1363 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1364 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1365 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1366 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1368 // Find out current undo directory
1369 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1371 // select object before undo
1372 if (!undoSelection.isEmpty())
1373 select (undoSelection);
1377 cout << "ME::undo() begin\n";
1378 cout << " undosAvail="<<undosAvail<<endl;
1379 cout << " redosAvail="<<redosAvail<<endl;
1380 cout << " curStep="<<curStep<<endl;
1381 cout << " ---------------------------"<<endl;
1382 cout << " comment="<<comment.toStdString()<<endl;
1383 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1384 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1385 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1386 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1387 cout << " ---------------------------"<<endl<<endl;
1388 parseAtom (undoCommand);
1389 mapCenter->reposition();
1393 if (curStep<1) curStep=undosTotal;
1397 blockSaveState=false;
1398 /* TODO remove testing
1400 cout << "ME::undo() end\n";
1401 cout << " undosAvail="<<undosAvail<<endl;
1402 cout << " redosAvail="<<redosAvail<<endl;
1403 cout << " curStep="<<curStep<<endl;
1404 cout << " ---------------------------"<<endl<<endl;
1406 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1407 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1408 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1409 undoSet.writeSettings(histPath);
1414 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1416 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1418 QFile file (bakMapPath);
1422 // We need to parse saved XML data
1423 mapBuilderHandler handler;
1424 QXmlInputSource source( file);
1425 QXmlSimpleReader reader;
1426 reader.setContentHandler( &handler );
1427 reader.setErrorHandler( &handler );
1428 handler.setMapEditor( this );
1429 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1430 if (undoSel.isEmpty())
1434 handler.setLoadMode (NewMap);
1438 handler.setLoadMode (ImportReplace);
1440 blockReposition=true;
1441 bool ok = reader.parse( source );
1442 blockReposition=false;
1445 // This should never ever happen
1446 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1447 tr( handler.errorProtocol() )+" in "+bakMapDir );
1451 QMessageBox::critical( 0, tr( "Critical Error" ),
1452 tr("Temporary directory %1 used for undo is gone. \n"
1453 "I will create a new one, but at the moment no undo is available.\n"
1454 "Maybe you want to reload your original data.\n\n"
1455 "Sorry for any inconveniences.").arg(bakMapDir) );
1460 void MapEditor::pasteNoSave()
1462 load (clipboardDir+"/part.xml",ImportAdd);
1465 void MapEditor::cutNoSave()
1471 void MapEditor::paste()
1473 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1474 typeid(*selection) == typeid(MapCenterObj)))
1476 saveStatePart(selection,QString("Paste to %1").arg( getName(selection)));
1478 mapCenter->reposition();
1483 void MapEditor::cut()
1485 saveStatePart(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
1488 mapCenter->reposition();
1492 void MapEditor::move(const int &x, const int &y)
1496 QString ps=qpointToString (selection->getAbsPos());
1497 QString s=selection->getSelectString();
1500 s, "move "+qpointToString (QPoint (x,y)),
1501 QString("Move %1 to %2").arg(getName(selection)).arg(ps));
1502 selection->move(x,y);
1503 mapCenter->reposition();
1509 void MapEditor::moveRel (const int &x, const int &y)
1513 QString ps=qpointToString (selection->getRelPos());
1514 QString s=selection->getSelectString();
1517 s, "moveRel "+qpointToString (QPoint (x,y)),
1518 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps));
1519 selection->setRelPos (QPoint(x,y));
1520 mapCenter->reposition();
1525 void MapEditor::moveBranchUp()
1529 if (typeid(*selection) == typeid(BranchObj) )
1531 bo=(BranchObj*)selection;
1532 if (!bo->canMoveBranchUp()) return;
1533 par=(BranchObj*)(bo->getParObj());
1534 selection->unselect();
1535 bo=par->moveBranchUp (bo); // bo will be the one below selection
1536 selection->select();
1537 saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1538 mapCenter->reposition();
1539 ensureSelectionVisible();
1543 void MapEditor::moveBranchDown()
1547 if (typeid(*selection) == typeid(BranchObj) )
1549 bo=(BranchObj*)selection;
1550 if (!bo->canMoveBranchDown()) return;
1551 par=(BranchObj*)(bo->getParObj());
1552 selection->unselect();
1553 bo=par->moveBranchDown(bo); // bo will be the one above selection
1554 selection->select();
1555 saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1556 mapCenter->reposition();
1557 ensureSelectionVisible();
1561 QString MapEditor::getHeading(bool &ok, QPoint &p)
1564 (typeid(*selection) == typeid(BranchObj) ||
1565 typeid(*selection) == typeid(MapCenterObj) ) )
1568 ensureSelectionVisible();
1569 p = ((BranchObj*)selection)->getAbsPos();
1570 p.setX (p.x() - contentsX());
1571 p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2);
1572 return ((BranchObj*)selection)->getHeading();
1578 void MapEditor::setHeading(const QString &s)
1581 (typeid(*selection) == typeid(BranchObj) ||
1582 typeid(*selection) == typeid(MapCenterObj) ) )
1584 editingBO=(BranchObj*)selection;
1585 saveStateConstSelection(
1586 "setHeading (\""+editingBO->getHeading()+"\")",
1587 "setHeading (\""+s+"\")",
1588 QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) );
1589 editingBO->setHeading(s );
1591 mapCenter->reposition();
1593 ensureSelectionVisible();
1597 void MapEditor::setURLInt (const QString &s)
1599 // Internal function, no saveState needed
1601 (typeid(*selection) == typeid(BranchObj) ||
1602 typeid(*selection) == typeid(MapCenterObj) ) )
1604 ((BranchObj*)selection)->setURL(s);
1605 mapCenter->reposition();
1607 ensureSelectionVisible();
1611 void MapEditor::setHeadingInt(const QString &s)
1614 (typeid(*selection) == typeid(BranchObj) ||
1615 typeid(*selection) == typeid(MapCenterObj) ) )
1617 ((BranchObj*)selection)->setHeading(s);
1618 mapCenter->reposition();
1620 ensureSelectionVisible();
1624 void MapEditor::setVymLinkInt (const QString &s)
1626 // Internal function, no saveState needed
1628 (typeid(*selection) == typeid(BranchObj) ||
1629 typeid(*selection) == typeid(MapCenterObj) ) )
1631 ((BranchObj*)selection)->setVymLink(s);
1632 mapCenter->reposition();
1634 ensureSelectionVisible();
1638 BranchObj* MapEditor::addNewBranchInt(int num)
1640 // Depending on pos:
1641 // -3 insert in childs of parent above selection
1642 // -2 add branch to selection
1643 // -1 insert in childs of parent below selection
1644 // 0..n insert in childs of parent at pos
1645 BranchObj *newbo=NULL;
1647 (typeid(*selection) == typeid(BranchObj) ||
1648 typeid(*selection) == typeid(MapCenterObj) ) )
1650 BranchObj* bo = (BranchObj*) selection;
1653 // save scroll state. If scrolled, automatically select
1654 // new branch in order to tmp unscroll parent...
1655 return bo->addBranch();
1660 bo=(BranchObj*)bo->getParObj();
1664 bo=(BranchObj*)bo->getParObj();
1667 newbo=bo->insertBranch(num);
1672 void MapEditor::addNewBranch(int pos)
1674 // Different meaning than num in addNewBranchInt!
1679 (typeid(*selection) == typeid(BranchObj) ||
1680 typeid(*selection) == typeid(MapCenterObj) ) )
1682 BranchObj *bo = (BranchObj*) selection;
1684 newbo=addNewBranchInt (pos-2);
1688 saveStateConstSelection (
1689 QString ("delete (\"%1\")").arg(newbo->getSelectString()),
1690 QString ("addBranch (%1)").arg(pos-2),
1691 QString ("Add new branch to %1").arg(getName(bo))); //TODO undoCommand
1693 LinkableMapObj *oldselection=selection;
1695 mapCenter->reposition();
1699 if (actionSettingsAutoedit->isOn() ||
1700 actionSettingsAutoselectHeading->isOn() )
1702 selection->unselect();
1704 selection->select();
1705 if (actionSettingsAutoedit->isOn() )
1706 mainWindow->editHeading();
1707 if (!actionSettingsAutoselectHeading->isOn()
1708 )//&& !wasScrolled) //FIXME wasScrolled was moved to addNewBranchInt
1710 selection->unselect();
1711 selection=oldselection;
1712 selection->select();
1720 void MapEditor::addNewBranchHere()
1723 (typeid(*selection) == typeid(BranchObj) ) )
1725 BranchObj* bo1 = (BranchObj*) selection;
1726 saveStatePart(selection, QString("Add new branch here").arg(getName(bo1)));
1728 bool wasScrolled=false;
1729 BranchObj *newbo=NULL;
1730 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1733 // add below selection
1734 newbo=parbo->insertBranch(bo1->getNum()+1);
1737 LinkableMapObj *oldselection=selection;
1738 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1740 mapCenter->reposition();
1742 if (actionSettingsAutoedit->isOn() ||
1743 actionSettingsAutoselectHeading->isOn() )
1745 selection->unselect();
1747 selection->select();
1748 if (actionSettingsAutoedit->isOn() )
1749 mainWindow->editHeading();
1750 if (!actionSettingsAutoselectHeading->isOn()
1753 selection->unselect();
1754 selection=oldselection;
1755 selection->select();
1761 void MapEditor::deleteSelection()
1763 if (selection && typeid(*selection) ==typeid(BranchObj) )
1765 BranchObj* bo=(BranchObj*)selection;
1766 BranchObj* par=(BranchObj*)(bo->getParObj());
1768 if (selection->getDepth()>1)
1769 // Normal branch, save parent with childs
1770 saveStatePart(par,QString("Delete %1").arg(getName(bo)));
1771 // naveState (UndoCom, par, QString("insertBranchAt (%1)", bo, "", QString ("Delete %1").arg(getName(bo))));
1773 // Mainbranch, save whole map
1774 // TODO Better would be to insert mainbranch again at pos
1775 // But undoCommand is missing right now
1776 saveStateComplete(QString("Delete %1").arg(getName(bo)));
1778 par->removeBranch(bo);
1780 selection->select();
1781 ensureSelectionVisible();
1782 mapCenter->reposition();
1785 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1787 FloatImageObj* fio=(FloatImageObj*)selection;
1788 BranchObj* par=(BranchObj*)(fio->getParObj());
1789 saveStatePart(par, QString("Delete %1").arg(getName(fio)));
1792 par->removeFloatImage(fio);
1794 selection->select();
1795 ensureSelectionVisible();
1796 mapCenter->reposition();
1801 LinkableMapObj* MapEditor::getSelection()
1806 void MapEditor::unselect()
1810 selectionLast=selection;
1811 selection->unselect();
1816 void MapEditor::reselect()
1820 selection=selectionLast;
1821 selection->select();
1826 bool MapEditor::select (const QString &s)
1828 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1830 // Finally select the found object
1833 if (selection) unselect();
1835 selection->select();
1837 ensureSelectionVisible();
1843 QString MapEditor::getSelectString()
1845 if (selection) return selection->getSelectString();
1849 void MapEditor::selectInt (LinkableMapObj *lmo)
1851 if (lmo && selection != lmo)
1853 // select the MapObj
1854 if (selection) selection->unselect();
1856 selection->select();
1862 void MapEditor::selectNextBranchInt()
1864 // Increase number of branch
1867 QString s=selection->getSelectString();
1873 part=s.section(",",-1);
1875 num=part.right(part.length() - 3);
1877 s=s.left (s.length() -num.length());
1880 num=QString ("%1").arg(num.toUInt()+1);
1884 // Try to select this one
1885 if (select (s)) return;
1887 // We have no direct successor,
1888 // try to increase the parental number in order to
1889 // find a successor with same depth
1891 int d=selection->getDepth();
1896 while (!found && d>0)
1898 s=s.section (",",0,d-1);
1899 // replace substring of current depth in s with "1"
1900 part=s.section(",",-1);
1902 num=part.right(part.length() - 3);
1906 // increase number of parent
1907 num=QString ("%1").arg(num.toUInt()+1);
1908 s=s.section (",",0,d-2) + ","+ typ+num;
1911 // Special case, look at orientation
1912 if (selection->getOrientation()==OrientRightOfCenter)
1913 num=QString ("%1").arg(num.toUInt()+1);
1915 num=QString ("%1").arg(num.toUInt()-1);
1920 // pad to oldDepth, select the first branch for each depth
1921 for (i=d;i<oldDepth;i++)
1926 if ( ((BranchObj*)selection)->countBranches()>0)
1934 // try to select the freshly built string
1942 void MapEditor::selectPrevBranchInt()
1944 // Decrease number of branch
1947 QString s=selection->getSelectString();
1953 part=s.section(",",-1);
1955 num=part.right(part.length() - 3);
1957 s=s.left (s.length() -num.length());
1960 num=QString ("%1").arg(num.toUInt()-1);
1964 // Try to select this one
1965 if (select (s)) return;
1967 // We have no direct precessor,
1968 // try to decrease the parental number in order to
1969 // find a precessor with same depth
1971 int d=selection->getDepth();
1976 while (!found && d>0)
1978 s=s.section (",",0,d-1);
1979 // replace substring of current depth in s with "1"
1980 part=s.section(",",-1);
1982 num=part.right(part.length() - 3);
1986 // decrease number of parent
1987 num=QString ("%1").arg(num.toUInt()-1);
1988 s=s.section (",",0,d-2) + ","+ typ+num;
1991 // Special case, look at orientation
1992 if (selection->getOrientation()==OrientRightOfCenter)
1993 num=QString ("%1").arg(num.toUInt()-1);
1995 num=QString ("%1").arg(num.toUInt()+1);
2000 // pad to oldDepth, select the last branch for each depth
2001 for (i=d;i<oldDepth;i++)
2005 if ( ((BranchObj*)selection)->countBranches()>0)
2006 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
2013 // try to select the freshly built string
2021 void MapEditor::selectUpperBranch()
2025 if (typeid(*selection) == typeid(BranchObj))
2027 if (selection->getOrientation()==OrientRightOfCenter)
2028 selectPrevBranchInt();
2030 if (selection->getDepth()==1)
2031 selectNextBranchInt();
2033 selectPrevBranchInt();
2038 void MapEditor::selectLowerBranch()
2042 if (typeid(*selection) == typeid(BranchObj))
2044 if (selection->getOrientation()==OrientRightOfCenter)
2045 selectNextBranchInt();
2047 if (selection->getDepth()==1)
2048 selectPrevBranchInt();
2050 selectNextBranchInt();
2056 void MapEditor::selectLeftBranch()
2062 if (typeid(*selection) == typeid(MapCenterObj))
2064 par= (BranchObj*) selection;
2065 bo=par->getLastSelectedBranch();
2068 // Workaround for reselecting on left and right side
2069 if (bo->getOrientation()==OrientRightOfCenter)
2071 bo=par->getLastBranch();
2077 selection->select();
2079 ensureSelectionVisible();
2084 par=(BranchObj*)(selection->getParObj());
2085 if (selection->getOrientation()==OrientRightOfCenter)
2087 if (typeid(*selection) == typeid(BranchObj) ||
2088 typeid(*selection) == typeid(FloatImageObj))
2090 selection->unselect();
2092 selection->select();
2094 ensureSelectionVisible();
2098 if (typeid(*selection) == typeid(BranchObj) )
2100 bo=((BranchObj*)selection)->getLastSelectedBranch();
2103 selection->unselect();
2105 selection->select();
2107 ensureSelectionVisible();
2115 void MapEditor::selectRightBranch()
2122 if (typeid(*selection) == typeid(MapCenterObj))
2124 par= (BranchObj*) selection;
2125 bo=par->getLastSelectedBranch();
2128 // Workaround for reselecting on left and right side
2129 if (bo->getOrientation()==OrientLeftOfCenter)
2130 bo=par->getFirstBranch();
2135 selection->select();
2136 ensureSelectionVisible();
2141 par=(BranchObj*)(selection->getParObj());
2142 if (selection->getOrientation()==OrientLeftOfCenter)
2144 if (typeid(*selection) == typeid(BranchObj) ||
2145 typeid(*selection) == typeid(FloatImageObj))
2147 selection->unselect();
2149 selection->select();
2151 ensureSelectionVisible();
2155 if (typeid(*selection) == typeid(BranchObj) )
2157 bo=((BranchObj*)selection)->getLastSelectedBranch();
2160 selection->unselect();
2162 selection->select();
2164 ensureSelectionVisible();
2172 void MapEditor::selectFirstBranch()
2178 if (typeid(*selection) == typeid(BranchObj))
2180 bo1= (BranchObj*) selection;
2181 par=(BranchObj*)(bo1->getParObj());
2182 bo2=par->getFirstBranch();
2186 selection->select();
2187 ensureSelectionVisible();
2194 void MapEditor::selectLastBranch()
2200 if (typeid(*selection) == typeid(BranchObj))
2202 bo1= (BranchObj*) selection;
2203 par=(BranchObj*)(bo1->getParObj());
2204 bo2=par->getLastBranch();
2208 selection->select();
2209 ensureSelectionVisible();
2216 void MapEditor::setColor(QColor c)
2221 void MapEditor::selectBackgroundColor()
2223 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2224 if ( !col.isValid() ) return;
2225 setBackgroundColor( col );
2227 saveStateComplete(QString("Set background color of map to %1").arg(col.name()));
2230 void MapEditor::setBackgroundColor(QColor c)
2232 mapCanvas->setBackgroundColor (c);
2235 QColor MapEditor::pickColor()
2239 if (typeid(*selection) == typeid(BranchObj) ||
2240 typeid(*selection) == typeid(MapCenterObj))
2242 BranchObj *bo=(BranchObj*)selection;
2243 actColor=bo->getColor();
2249 void MapEditor::colorItem()
2253 if (typeid(*selection) == typeid(BranchObj) ||
2254 typeid(*selection) == typeid(MapCenterObj))
2256 BranchObj *bo=(BranchObj*)selection;
2257 saveStatePart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2258 bo->setColor(actColor); // color branch
2263 void MapEditor::colorBranch()
2267 if (typeid(*selection) == typeid(BranchObj) ||
2268 typeid(*selection) == typeid(MapCenterObj))
2270 BranchObj *bo=(BranchObj*)selection;
2271 saveStatePart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2272 bo->setColorChilds(actColor); // color links, color childs
2278 void MapEditor::toggleStandardFlag(QString f)
2282 if (typeid(*selection) == typeid(BranchObj) ||
2283 typeid(*selection) == typeid(MapCenterObj))
2285 BranchObj *bo=(BranchObj*)selection;
2287 if (bo->isSetStandardFlag(f))
2297 saveStateConstSelection(QString("%1 (\"%2\")").arg(u).arg(f),
2298 QString("%1 (\"%2\")").arg(r).arg(f),
2299 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2300 bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn());
2306 void MapEditor::setViewCenter()
2308 // transform to CanvasView Coord:
2309 QPoint p=worldMatrix().map(movingCenter);
2310 center ( p.x(), p.y());
2314 BranchObj* MapEditor::findText (QString s, bool cs)
2316 QTextDocument::FindFlags flags=0;
2317 if (cs) flags=QTextDocument::FindCaseSensitively;
2320 { // Nothing found or new find process
2322 // nothing found, start again
2324 itFind=mapCenter->first();
2326 bool searching=true;
2327 bool foundNote=false;
2328 while (searching && !EOFind)
2332 // Searching in Note
2333 if (itFind->getNote().contains(s,cs))
2335 if (selection!=itFind)
2337 if (selection) ((BranchObj*)selection)->unselect();
2339 selection->select();
2341 ensureSelectionVisible();
2343 if (textEditor->findText(s,flags))
2349 // Searching in Heading
2350 if (searching && itFind->getHeading().contains (s,cs) )
2352 if (selection) ((BranchObj*)selection)->unselect();
2354 selection->select();
2356 ensureSelectionVisible();
2362 itFind=itFind->next();
2363 if (!itFind) EOFind=true;
2369 return (BranchObj*)selection;
2374 void MapEditor::findReset()
2375 { // Necessary if text to find changes during a find process
2380 void MapEditor::editURL()
2382 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2383 typeid(*selection) == typeid(MapCenterObj)) )
2386 BranchObj *bo=(BranchObj*)selection;
2387 QString text = QInputDialog::getText(
2388 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2389 bo->getURL(), &ok, this );
2392 // user entered something and pressed OK
2393 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2400 QString MapEditor::getURL()
2402 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2403 typeid(*selection) == typeid(MapCenterObj)) )
2404 return ((BranchObj*)selection)->getURL();
2409 QStringList MapEditor::getURLs()
2412 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2413 typeid(*selection) == typeid(MapCenterObj)) )
2415 BranchObj *bo=(BranchObj*)selection;
2419 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2427 void MapEditor::editHeading2URL()
2429 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2430 typeid(*selection) == typeid(MapCenterObj)) )
2432 BranchObj *bo=(BranchObj*)selection;
2433 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2434 bo->setURL (bo->getHeading());
2439 void MapEditor::editBugzilla2URL()
2441 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2442 typeid(*selection) == typeid(MapCenterObj)) )
2444 BranchObj *bo=(BranchObj*)selection;
2445 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2446 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo)));
2452 void MapEditor::editFATE2URL()
2454 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2455 typeid(*selection) == typeid(MapCenterObj)) )
2457 BranchObj *bo=(BranchObj*)selection;
2458 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2459 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2465 void MapEditor::editVymLink()
2467 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2468 typeid(*selection) == typeid(MapCenterObj)) )
2470 BranchObj *bo=(BranchObj*)selection;
2471 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map"));
2472 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2473 fd->setCaption(__VYM " - " +tr("Link to another map"));
2474 if (! bo->getVymLink().isEmpty() )
2475 fd->setSelection( bo->getVymLink() );
2479 if ( fd->exec() == QDialog::Accepted )
2481 saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2482 bo->setVymLink (fd->selectedFile() );
2484 mapCenter->reposition();
2491 void MapEditor::deleteVymLink()
2493 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2494 typeid(*selection) == typeid(MapCenterObj)) )
2496 BranchObj *bo=(BranchObj*)selection;
2497 saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2498 bo->setVymLink ("" );
2500 mapCenter->reposition();
2506 void MapEditor::toggleHideExport()
2508 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2509 typeid(*selection) == typeid(MapCenterObj)) ||
2510 (typeid(*selection)==typeid(FloatImageObj))
2513 OrnamentedObj *oo=(OrnamentedObj*)selection;
2515 if (oo->hideInExport())
2517 oo->setHideInExport(false);
2522 oo->setHideInExport(true);
2525 saveStateComplete(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2526 actionEditToggleHideExport->setOn (oo->hideInExport());
2528 mapCenter->reposition();
2534 QString MapEditor::getVymLink()
2536 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2537 typeid(*selection) == typeid(MapCenterObj)) )
2539 return ((BranchObj*)selection)->getVymLink();
2545 QStringList MapEditor::getVymLinks()
2548 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2549 typeid(*selection) == typeid(MapCenterObj)) )
2551 BranchObj *bo=(BranchObj*)selection;
2555 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2563 void MapEditor::removeBranchKeepChilds()
2565 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2567 BranchObj* bo=(BranchObj*)selection;
2568 BranchObj* par=(BranchObj*)(bo->getParObj());
2569 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2570 if (bo->getDepth()==1)
2571 saveStateComplete(s);
2573 saveStatePart(selection->getParObj(),s); // TODO undoCommand
2574 QString sel=selection->getSelectString();
2576 par->removeBranchHere(bo);
2577 mapCenter->reposition();
2582 void MapEditor::removeChilds()
2584 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2586 saveStatePart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
2587 ((BranchObj*)selection)->removeChilds();
2588 mapCenter->reposition();
2592 void MapEditor::editMapInfo()
2594 ExtraInfoDialog dia;
2595 dia.setMapName (getFileName() );
2596 dia.setAuthor (mapCenter->getAuthor() );
2597 dia.setComment(mapCenter->getComment() );
2602 Q3CanvasItemList l=canvas()->allItems();
2603 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2605 stats+=QString ("%1 items on canvas\n").arg (i,6);
2612 bo=mapCenter->first();
2615 if (!bo->getNote().isEmpty() ) n++;
2616 f+= bo->countFloatImages();
2618 xl+=bo->countXLinks();
2621 stats+=QString ("%1 branches\n").arg (b-1,6);
2622 stats+=QString ("%1 xLinks \n").arg (xl,6);
2623 stats+=QString ("%1 notes\n").arg (n,6);
2624 stats+=QString ("%1 images\n").arg (f,6);
2625 dia.setStats (stats);
2627 // Finally show dialog
2628 if (dia.exec() == QDialog::Accepted)
2630 saveStateComplete("Edit info about map"); //TODO undoCommand
2631 mapCenter->setAuthor (dia.getAuthor() );
2632 mapCenter->setComment (dia.getComment() );
2636 void MapEditor::updateActions()
2639 if (getLinkColorHint()==HeadingColor)
2640 actionFormatLinkColorHint->setOn(true);
2642 actionFormatLinkColorHint->setOn(false);
2647 actionFormatLinkStyleLine->setOn(true);
2650 actionFormatLinkStyleParabel->setOn(true);
2653 actionFormatLinkStylePolyLine->setOn(true);
2655 case StylePolyParabel:
2656 actionFormatLinkStylePolyParabel->setOn(true);
2662 QPixmap pix( 16, 16 );
2663 pix.fill( mapCanvas->backgroundColor() );
2664 actionFormatBackColor->setIconSet( pix );
2665 pix.fill( defLinkColor );
2666 actionFormatLinkColor->setIconSet( pix );
2668 actionFileSave->setEnabled( mapUnsaved );
2669 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2670 actionEditUndo->setEnabled( true);
2672 actionEditUndo->setEnabled( false);
2674 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2675 actionEditRedo->setEnabled( true);
2677 actionEditRedo->setEnabled( false);
2681 if ( (typeid(*selection) == typeid(BranchObj)) ||
2682 (typeid(*selection) == typeid(MapCenterObj)) )
2684 BranchObj *bo=(BranchObj*)selection;
2685 // Take care of links
2686 if (bo->countXLinks()==0)
2688 branchXLinksContextMenuEdit->clear();
2689 branchXLinksContextMenuFollow->clear();
2694 branchXLinksContextMenuEdit->clear();
2695 branchXLinksContextMenuFollow->clear();
2696 for (int i=0; i<=bo->countXLinks();i++)
2698 bot=bo->XLinkTargetAt(i);
2701 s=bot->getHeading();
2704 branchXLinksContextMenuFollow->addAction (s);
2705 branchXLinksContextMenuEdit->addAction (s);
2710 standardFlagsDefault->setEnabled (true);
2712 actionEditToggleScroll->setEnabled (true);
2713 if ( bo->isScrolled() )
2714 actionEditToggleScroll->setOn(true);
2716 actionEditToggleScroll->setOn(false);
2718 if ( bo->getURL().isEmpty() )
2720 actionEditOpenURL->setEnabled (false);
2721 actionEditOpenURLTab->setEnabled (false);
2725 actionEditOpenURL->setEnabled (true);
2726 actionEditOpenURLTab->setEnabled (true);
2728 if ( bo->getVymLink().isEmpty() )
2730 actionEditOpenVymLink->setEnabled (false);
2731 actionEditDeleteVymLink->setEnabled (false);
2734 actionEditOpenVymLink->setEnabled (true);
2735 actionEditDeleteVymLink->setEnabled (true);
2738 if (bo->canMoveBranchUp())
2739 actionEditMoveUp->setEnabled (true);
2741 actionEditMoveUp->setEnabled (false);
2742 if (bo->canMoveBranchDown())
2743 actionEditMoveDown->setEnabled (true);
2745 actionEditMoveDown->setEnabled (false);
2748 actionEditToggleHideExport->setEnabled (true);
2749 actionEditToggleHideExport->setOn (bo->hideInExport() );
2751 actionEditCopy->setEnabled (true);
2752 actionEditCut->setEnabled (true);
2753 if (!clipboardEmpty)
2754 actionEditPaste->setEnabled (true);
2756 actionEditPaste->setEnabled (false);
2757 for (a=actionListBranches.first();a;a=actionListBranches.next())
2758 a->setEnabled(true);
2759 actionEditDelete->setEnabled (true);
2760 switch (selection->getFrameType())
2763 actionFormatFrameNone->setOn(true);
2766 actionFormatFrameRectangle->setOn(true);
2771 actionFormatIncludeImagesVer->setOn
2772 ( ((BranchObj*)selection)->getIncludeImagesVer());
2773 actionFormatIncludeImagesHor->setOn
2774 ( ((BranchObj*)selection)->getIncludeImagesHor());
2775 actionFormatHideLinkUnselected->setOn
2776 (selection->getHideLinkUnselected());
2778 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2780 FloatObj *fo=(FloatImageObj*)selection;
2781 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2783 actionEditOpenURL->setEnabled (false);
2784 actionEditOpenVymLink->setEnabled (false);
2785 actionEditDeleteVymLink->setEnabled (false);
2786 actionEditToggleHideExport->setEnabled (true);
2787 actionEditToggleHideExport->setOn (fo->hideInExport() );
2790 actionEditCopy->setEnabled (true);
2791 actionEditCut->setEnabled (true);
2792 actionEditPaste->setEnabled (false);
2793 for (a=actionListBranches.first();a;a=actionListBranches.next())
2794 a->setEnabled(false);
2795 actionEditDelete->setEnabled (true);
2796 actionFormatHideLinkUnselected->setOn
2797 ( selection->getHideLinkUnselected());
2798 actionEditMoveUp->setEnabled (false);
2799 actionEditMoveDown->setEnabled (false);
2804 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2806 actionEditCopy->setEnabled (false);
2807 actionEditCut->setEnabled (false);
2808 actionEditPaste->setEnabled (false);
2809 for (a=actionListBranches.first();a;a=actionListBranches.next())
2810 a->setEnabled(false);
2812 actionEditToggleScroll->setEnabled (false);
2813 actionEditOpenURL->setEnabled (false);
2814 actionEditOpenVymLink->setEnabled (false);
2815 actionEditDeleteVymLink->setEnabled (false);
2816 actionEditHeading2URL->setEnabled (false);
2817 actionEditDelete->setEnabled (false);
2818 actionEditMoveUp->setEnabled (false);
2819 actionEditMoveDown->setEnabled (false);
2820 actionEditToggleHideExport->setEnabled (false);
2824 void MapEditor::updateNoteFlag()
2827 if ( (typeid(*selection) == typeid(BranchObj)) ||
2828 (typeid(*selection) == typeid(MapCenterObj)) )
2829 ((BranchObj*)selection)->updateNoteFlag();
2832 void MapEditor::setLinkStyle (LinkStyle ls)
2836 saveStateComplete("Set link style"); // TODO undoCommand
2838 bo=mapCenter->first();
2842 bo->setLinkStyle(bo->getDefLinkStyle());
2845 mapCenter->reposition();
2848 LinkStyle MapEditor::getLinkStyle ()
2853 void MapEditor::setLinkColor(QColor c)
2859 void MapEditor::setLinkColorHint()
2861 // called from setLinkColorHint(lch) or at end of parse
2863 bo=mapCenter->first();
2871 void MapEditor::setLinkColorHint(LinkColorHint lch)
2877 void MapEditor::toggleLinkColorHint()
2879 if (linkcolorhint==HeadingColor)
2880 linkcolorhint=DefaultColor;
2882 linkcolorhint=HeadingColor;
2884 bo=mapCenter->first();
2892 LinkColorHint MapEditor::getLinkColorHint()
2894 return linkcolorhint;
2897 QColor MapEditor::getDefLinkColor()
2899 return defLinkColor;
2902 void MapEditor::setDefXLinkColor(QColor col)
2907 QColor MapEditor::getDefXLinkColor()
2909 return defXLinkColor;
2912 void MapEditor::setDefXLinkWidth (int w)
2917 int MapEditor::getDefXLinkWidth()
2919 return defXLinkWidth;
2922 void MapEditor::selectLinkColor()
2924 QColor col = QColorDialog::getColor( defLinkColor, this );
2925 if ( !col.isValid() ) return;
2926 setLinkColor( col );
2927 saveStateComplete(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2931 void MapEditor::toggleScroll()
2933 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2935 BranchObj *bo=((BranchObj*)selection);
2936 if (bo->countBranches()==0) return;
2937 if (bo->getDepth()==0) return;
2939 if (bo->isScrolled())
2943 saveStatePart(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2950 void MapEditor::unScrollAll()
2953 bo=mapCenter->first();
2956 if (bo->isScrolled()) bo->toggleScroll();
2961 void MapEditor::loadFloatImage ()
2964 (typeid(*selection) == typeid(BranchObj)) ||
2965 (typeid(*selection) == typeid(MapCenterObj)) )
2967 BranchObj *bo=((BranchObj*)selection);
2969 Q3FileDialog *fd=new Q3FileDialog( this);
2970 fd->setMode (Q3FileDialog::ExistingFiles);
2971 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2972 ImagePreview *p =new ImagePreview (fd);
2973 fd->setContentsPreviewEnabled( TRUE );
2974 fd->setContentsPreview( p, p );
2975 fd->setPreviewMode( Q3FileDialog::Contents );
2976 fd->setCaption(__VYM " - " +tr("Load image"));
2977 fd->setDir (lastImageDir);
2981 if ( fd->exec() == QDialog::Accepted )
2983 saveStatePart(selection, QString("Add floatimage to %1").arg(getName(selection)));
2984 // FIXME in QT4 use: lastImageDir=fd->directory();
2985 lastImageDir=QDir (fd->dirPath());
2986 QStringList flist = fd->selectedFiles();
2987 QStringList::Iterator it = flist.begin();
2988 while( it != flist.end() )
2991 bo->addFloatImage();
2992 // TODO check if load was successful
2993 bo->getLastFloatImage()->load(*it);
2994 bo->getLastFloatImage()->setOriginalFilename(fn);
2998 mapCenter->reposition();
3007 void MapEditor::saveFloatImage ()
3010 (typeid(*selection) == typeid(FloatImageObj)) )
3012 FloatImageObj *fio=((FloatImageObj*)selection);
3013 QFileDialog *fd=new QFileDialog( this);
3014 fd->setFilters (imageIO.getFilters());
3015 fd->setCaption(__VYM " - " +tr("Save image"));
3016 fd->setFileMode( QFileDialog::AnyFile );
3017 fd->setDirectory (lastImageDir);
3018 // fd->setSelection (fio->getOriginalFilename());
3022 if ( fd->exec() == QDialog::Accepted )
3024 if (QFile (fd->selectedFile()).exists() )
3026 QMessageBox mb( __VYM,
3027 tr("The file %1 exists already.\n"
3028 "Do you want to overwrite it?").arg(fd->selectedFile()),
3029 QMessageBox::Warning,
3030 QMessageBox::Yes | QMessageBox::Default,
3031 QMessageBox::Cancel | QMessageBox::Escape,
3032 QMessageBox::QMessageBox::NoButton );
3034 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3035 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3038 case QMessageBox::Yes:
3041 case QMessageBox::Cancel:
3047 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
3052 void MapEditor::setFrame(const FrameType &t)
3055 (typeid(*selection) == typeid(BranchObj)) ||
3056 (typeid(*selection) == typeid(MapCenterObj)) )
3058 selection->setFrameType (t);
3059 mapCenter->reposition();
3060 selection->updateLink();
3064 void MapEditor::setIncludeImagesVer(bool b)
3067 (typeid(*selection) == typeid(BranchObj)) ||
3068 (typeid(*selection) == typeid(MapCenterObj)) )
3069 ((BranchObj*)selection)->setIncludeImagesVer(b);
3070 mapCenter->reposition();
3073 void MapEditor::setIncludeImagesHor(bool b)
3076 (typeid(*selection) == typeid(BranchObj)) ||
3077 (typeid(*selection) == typeid(MapCenterObj)) )
3078 ((BranchObj*)selection)->setIncludeImagesHor(b);
3079 mapCenter->reposition();
3082 void MapEditor::setHideLinkUnselected (bool b)
3085 (typeid(*selection) == typeid(BranchObj)) ||
3086 (typeid(*selection) == typeid(MapCenterObj)) ||
3087 (typeid(*selection) == typeid(FloatImageObj)) )
3088 selection->setHideLinkUnselected(b);
3091 void MapEditor::importDirInt(BranchObj *dst, QDir d)
3094 (typeid(*selection) == typeid(BranchObj)) ||
3095 (typeid(*selection) == typeid(MapCenterObj)) )
3099 // Traverse directories
3100 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3101 QFileInfoList list = d.entryInfoList();
3104 for (int i = 0; i < list.size(); ++i)
3107 if (fi.fileName() != "." && fi.fileName() != ".." )
3110 bo=dst->getLastBranch();
3111 bo->setHeading (fi.fileName() );
3112 bo->setColor (QColor("blue"));
3114 if ( !d.cd(fi.fileName()) )
3115 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3118 // Recursively add subdirs
3119 importDirInt (bo,d);
3125 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3126 list = d.entryInfoList();
3128 for (int i = 0; i < list.size(); ++i)
3132 bo=dst->getLastBranch();
3133 bo->setHeading (fi.fileName() );
3134 bo->setColor (QColor("black"));
3135 if (fi.fileName().right(4) == ".vym" )
3136 bo->setVymLink (fi.filePath());
3141 void MapEditor::importDir()
3144 (typeid(*selection) == typeid(BranchObj)) ||
3145 (typeid(*selection) == typeid(MapCenterObj)) )
3147 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
3148 fd->setMode (Q3FileDialog::DirectoryOnly);
3149 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3150 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
3154 if ( fd->exec() == QDialog::Accepted )
3156 BranchObj *bo=((BranchObj*)selection);
3157 importDirInt (bo,QDir(fd->selectedFile()) );
3158 mapCenter->reposition();
3165 void MapEditor::followXLink(int i)
3168 (typeid(*selection) == typeid(BranchObj)) ||
3169 (typeid(*selection) == typeid(MapCenterObj)) )
3171 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3174 selection->unselect();
3176 selection->select();
3177 ensureSelectionVisible();
3182 void MapEditor::editXLink(int i)
3184 qDebug ("ko."); //FIXME Huh?
3186 (typeid(*selection) == typeid(BranchObj)) ||
3187 (typeid(*selection) == typeid(MapCenterObj)) )
3189 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3192 EditXLinkDialog dia;
3194 dia.setSelection(selection);
3195 if (dia.exec() == QDialog::Accepted)
3197 if (dia.useSettingsGlobal() )
3199 setDefXLinkColor (xlo->getColor() );
3200 setDefXLinkWidth (xlo->getWidth() );
3202 if (dia.deleteXLink())
3203 ((BranchObj*)selection)->deleteXLinkAt(i);
3204 saveStateComplete("Edit xLink"); //TODO undoCommand
3210 void MapEditor::testFunction()
3212 cout << "MapEditor::testFunction() called\n";
3216 QString text = QInputDialog::getText(
3218 tr("QInputDialog::getText()"),
3219 tr("User name:"), QLineEdit::Normal,
3220 QDir::home().dirName(), &ok, Qt::FramelessWindowHint);
3223 QDialog *d =new QDialog(NULL);
3224 QLineEdit *le=new QLineEdit (d);
3225 // d->setModal (true);
3226 d->setWindowFlags (Qt::FramelessWindowHint);
3228 le->setText ("Foo");
3230 connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
3232 qWarning( le->text());
3239 dia.setCancelButton (true);
3240 dia.setText("This is a longer \nWarning");
3241 dia.setCaption("Warning: Flux problem");
3242 dia.setShowAgainName("/warnings/mapeditor");
3243 dia.setWindowFlags (Qt::FramelessWindowHint);
3244 if (dia.exec()==QDialog::Accepted)
3245 cout << "accepted!\n";
3247 cout << "canceled!\n";
3251 /* Hide hidden stuff temporary, maybe add this as regular function somewhere
3252 if (hidemode==HideNone)
3254 setHideTmpMode (HideExport);
3255 mapCenter->calcBBoxSizeWithChilds();
3256 QRect totalBBox=mapCenter->getTotalBBox();
3257 QRect mapRect=totalBBox;
3258 QCanvasRectangle *frame=NULL;
3260 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3262 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3263 totalBBox.width(), totalBBox.height());
3264 frame=new QCanvasRectangle (mapRect,mapCanvas);
3265 frame->setBrush (QColor(white));
3266 frame->setPen (QColor(black));
3272 setHideTmpMode (HideNone);
3274 cout <<" hidemode="<<hidemode<<endl;
3278 void MapEditor::ensureSelectionVisible()
3282 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3284 if (selection->getOrientation() == OrientLeftOfCenter)
3285 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3287 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3288 ensureVisible (p.x(), p.y() );
3293 void MapEditor::updateViewCenter()
3295 // Update movingCenter, so that we can zoom comfortably later
3296 QRect rc = QRect( contentsX(), contentsY(),
3297 visibleWidth(), visibleHeight() );
3298 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3299 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3300 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3303 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3305 // Lineedits are already closed by preceding
3306 // mouseEvent, we don't need to close here.
3308 QPoint p = inverseWorldMatrix().map(e->pos());
3309 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3312 { // MapObj was found
3313 if (selection != lmo)
3315 // select the MapObj
3316 if (selection) selection->unselect();
3318 selection->select();
3324 if (typeid(*selection)==typeid(BranchObj) ||
3325 typeid(*selection)==typeid(MapCenterObj) )
3327 // Context Menu on branch or mapcenter
3329 branchContextMenu->popup(e->globalPos() );
3331 if (typeid(*selection)==typeid(FloatImageObj))
3333 // Context Menu on floatimage
3335 floatimageContextMenu->popup(e->globalPos() );
3339 { // No MapObj found, we are on the Canvas itself
3340 // Context Menu on Canvas
3342 canvasContextMenu->popup(e->globalPos() );
3347 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3349 // Ignore right clicks, these will go to context menus
3350 if (e->button() == Qt::RightButton )
3356 QPoint p = inverseWorldMatrix().map(e->pos());
3357 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3361 //Take care of clickdesystem flags _or_ modifier modes
3363 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3364 typeid(*lmo)==typeid(MapCenterObj) ))
3366 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3367 if (!foname.isEmpty())
3369 // systemFlag clicked
3373 if (e->state() & Qt::ControlModifier)
3374 mainWindow->editOpenURLTab();
3376 mainWindow->editOpenURL();
3378 else if (foname=="vymLink")
3380 mainWindow->editOpenVymLink();
3381 // tabWidget may change, better return now
3382 // before segfaulting...
3383 } else if (foname=="note")
3384 mainWindow->windowToggleNoteEditor();
3385 else if (foname=="hideInExport")
3390 // No system flag clicked, take care of modmodes
3392 // Special case: CTRL is pressed
3393 if (e->state() & Qt::ControlModifier)
3395 if (actionModModeColor->isOn())
3398 setCursor (pickColorCursor);
3401 if (actionModModeLink->isOn())
3403 BranchObj *bo_begin=NULL;
3405 bo_begin=(BranchObj*)(lmo);
3408 ((typeid(*selection) == typeid(BranchObj)) ||
3409 (typeid(*selection) == typeid(MapCenterObj))) )
3410 bo_begin=(BranchObj*)selection;
3414 linkingObj_src=bo_begin;
3415 tmpXLink=new XLinkObj (mapCanvas);
3416 tmpXLink->setBegin (bo_begin);
3417 tmpXLink->setEnd (p);
3418 tmpXLink->setColor(defXLinkColor);
3419 tmpXLink->setWidth(defXLinkWidth);
3420 tmpXLink->updateXLink();
3421 tmpXLink->setVisibility (true);
3429 // Left Button Move Branches
3430 if (e->button() == Qt::LeftButton )
3432 movingObj_start.setX( p.x() - selection->x() );
3433 movingObj_start.setY( p.y() - selection->y() );
3434 movingObj_orgPos.setX (lmo->x() );
3435 movingObj_orgPos.setY (lmo->y() );
3436 movingObj_orgRelPos=lmo->getRelPos();
3438 // If modMode==copy, then we want to "move" the _new_ object around
3439 // then we need the offset from p to the _old_ selection, because of tmp
3440 if (actionModModeCopy->isOn() &&
3441 e->state() & Qt::ControlModifier)
3443 if (typeid(*selection)==typeid(BranchObj) )
3446 mapCenter->addBranch ((BranchObj*)selection);
3448 selection=mapCenter->getLastBranch();
3449 selection->select();
3450 mapCenter->reposition();
3453 movingObj=selection;
3455 // Middle Button Toggle Scroll
3456 // (On Mac OS X this won't work, but we still have
3457 // a button in the toolbar)
3458 if (e->button() == Qt::MidButton )
3462 { // No MapObj found, we are on the Canvas itself
3463 // Left Button move Pos of CanvasView
3464 if (e->button() == Qt::LeftButton )
3466 movingObj=NULL; // move Content not Obj
3467 movingObj_start=e->globalPos();
3468 movingCont_start=QPoint (contentsX(), contentsY() );
3469 movingVec=QPoint(0,0);
3470 setCursor(handOpenCursor);
3475 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3477 QPoint p = inverseWorldMatrix().map(e->pos());
3479 // Move the selected MapObj
3480 if ( selection && movingObj)
3482 // To avoid jumping of the CanvasView, only
3483 // ensureSelectionVisible, if not tmp linked
3484 if (!selection->hasParObjTmp())
3485 ensureSelectionVisible ();
3487 // Now move the selection, but add relative position
3488 // (movingObj_start) where selection was chosen with
3489 // mousepointer. (This avoids flickering resp. jumping
3490 // of selection back to absPos)
3492 LinkableMapObj *lmosel;
3493 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3495 // Check if we could link
3496 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3499 if (typeid(*selection) == typeid(FloatImageObj))
3501 FloatObj *fo=(FloatObj*)selection;
3502 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3506 // Relink float to new mapcenter or branch, if shift is pressed
3507 // Only relink, if selection really has a new parent
3508 if ( (e->state() & Qt::ShiftModifier) && lmo &&
3509 ( (typeid(*lmo)==typeid(BranchObj)) ||
3510 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3511 ( lmo != fo->getParObj())
3514 if (typeid(*fo) == typeid(FloatImageObj))
3517 saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3518 FloatImageObj *fio=(FloatImageObj*)(fo);
3519 ((BranchObj*)(lmo))->addFloatImage (fio);
3521 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3522 fio=((BranchObj*)(lmo))->getLastFloatImage();
3525 selection=(LinkableMapObj*)(fio);
3526 selection->select();
3527 movingObj=(MapObj*)(fio);
3530 } else // selection != a FloatObj
3532 if (lmosel->getDepth()==0)
3534 if (e->state() == Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3535 // If mapCenter is moved, move all the rest by default, too.
3536 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3538 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3541 if (lmosel->getDepth()==1)
3543 // depth==1, mainbranch
3544 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3548 if (lmosel->getOrientation() == OrientLeftOfCenter)
3549 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3550 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3551 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3553 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3555 // reposition subbranch
3556 lmosel->reposition();
3557 //ensureSelectionVisible();
3559 if (lmo && (lmo!=selection) &&
3560 (typeid(*lmo) == typeid(BranchObj) ||
3561 (typeid(*lmo) == typeid(MapCenterObj) )
3564 if (e->state() & Qt::ControlModifier)
3566 // Special case: CTRL to link below lmo
3567 lmosel->setParObjTmp (lmo,p,+1);
3569 else if (e->state() & Qt::ShiftModifier)
3570 lmosel->setParObjTmp (lmo,p,-1);
3572 lmosel->setParObjTmp (lmo,p,0);
3575 lmosel->unsetParObjTmp();
3579 } // no FloatImageObj
3583 } // selection && moving_obj
3585 // Draw a link from one branch to another
3588 tmpXLink->setEnd (p);
3589 tmpXLink->updateXLink();
3593 if (!movingObj && !pickingColor &&!drawingLink)
3595 QPoint p=e->globalPos();
3596 movingVec.setX(-p.x() + movingObj_start.x() );
3597 movingVec.setY(-p.y() + movingObj_start.y() );
3598 setContentsPos( movingCont_start.x() + movingVec.x(),
3599 movingCont_start.y() + movingVec.y());
3606 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3608 LinkableMapObj *dst;
3609 // Have we been picking color?
3613 setCursor (Qt::ArrowCursor);
3614 // Check if we are over another branch
3615 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3616 if (dst && selection)
3618 if (e->state() & Qt::ShiftModifier)
3620 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3621 ((BranchObj*)selection)->setLinkColor ();
3625 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3626 ((BranchObj*)selection)->setLinkColor ();
3632 // Have we been drawing a link?
3636 // Check if we are over another branch
3637 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3638 if (dst && selection)
3640 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3641 tmpXLink->updateXLink();
3642 tmpXLink->activate();
3643 saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3652 // Have we been moving something?
3653 if ( selection && movingObj )
3655 // Moved FloatObj? Maybe we need to reposition
3656 if(typeid(*selection)==typeid (FloatImageObj))
3658 FloatImageObj *fo=(FloatImageObj*)selection;
3659 QString pold=qpointToString(movingObj_orgRelPos);
3660 QString pnow=qpointToString(fo->getRelPos());
3661 saveStateConstSelection(
3664 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow));
3666 selection->getParObj()->requestReposition();
3667 mapCenter->reposition();
3670 // Check if we are over another branch, but ignore
3671 // any found LMOs, which are FloatObjs
3672 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3673 ((LinkableMapObj*)selection) );
3675 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3678 // Now check, if we have been moving a branch
3679 if (typeid(*selection) == typeid(BranchObj) )
3681 // save the position in case we link to mapcenter
3682 QPoint savePos=QPoint (selection->x(),selection->y() );
3684 // Reset the temporary drawn link to the original one
3685 ((LinkableMapObj*)selection)->unsetParObjTmp();
3687 // For Redo we may need to save original selection
3688 QString preSelStr=selection->getSelectString();
3693 BranchObj* bsel=(BranchObj*)selection;
3694 BranchObj* bdst=(BranchObj*)dst;
3696 QString preParStr=(bsel->getParObj())->getSelectString();
3697 QString preNum=QString::number (bsel->getNum(),10);
3698 QString preDstParStr;
3700 if (e->state() & Qt::ShiftModifier && dst->getParObj())
3702 preDstParStr=dst->getParObj()->getSelectString();
3703 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
3705 if (e->state() & Qt::ControlModifier && dst->getParObj())
3708 preDstParStr=dst->getParObj()->getSelectString();
3709 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
3712 preDstParStr=dst->getSelectString();
3713 bsel->moveBranchTo (bdst,-1);
3714 if (dst->getDepth()==0) bsel->move (savePos);
3716 QString postSelStr=selection->getSelectString();
3717 QString postNum=QString::number (bsel->getNum(),10);
3719 QString undoCom="linkBranchToPos (\""+
3720 preParStr+ "\"," + preNum +"," +
3721 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
3723 QString redoCom="linkBranchToPos (\""+
3724 preDstParStr + "\"," + postNum + "," +
3725 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
3730 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
3732 if (selection->getDepth()==1)
3734 // The select string might be different _after_ moving around.
3735 // Therefor reposition and then use string of old selection, too
3736 mapCenter->reposition();
3738 QString ps=qpointToString ( ((BranchObj*)selection)->getRelPos() );
3740 selection->getSelectString(), "moveRel "+qpointToString(movingObj_orgRelPos),
3741 preSelStr, "moveRel "+ps,
3742 QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps));
3745 // Draw the original link, before selection was moved around
3746 mapCenter->reposition();
3748 // Finally resize canvas, if needed
3753 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
3756 // maybe we moved View: set old cursor
3757 setCursor (Qt::ArrowCursor);
3761 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3763 if (e->button() == Qt::LeftButton )
3765 QPoint p = inverseWorldMatrix().map(e->pos());
3766 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3767 if (lmo) { // MapObj was found
3768 // First select the MapObj than edit heading
3769 if (selection) selection->unselect();
3771 selection->select();
3772 mainWindow->editHeading();
3777 void MapEditor::resizeEvent (QResizeEvent* e)
3779 Q3CanvasView::resizeEvent( e );
3783 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3786 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3787 // cerr << event->format(i) << endl;
3790 (typeid(*selection) == typeid(BranchObj)) ||
3791 (typeid(*selection) == typeid(MapCenterObj))) {
3793 // If QImageDrag can decode mime type
3794 if (Q3ImageDrag::canDecode(event)) {
3799 // If image are dragged from firefox
3800 if (event->provides("application/x-moz-file-promise-url") &&
3801 event->provides("application/x-moz-nativeimage")) {
3802 event->accept(true);
3806 // If QUriDrag can decode mime type
3807 if (Q3UriDrag::canDecode(event)) {
3812 // If Uri are dragged from firefox
3813 if (event->provides("_NETSCAPE_URL")){
3818 // If QTextDrag can decode mime type
3819 if (Q3TextDrag::canDecode(event)) {
3828 bool isUnicode16(const QByteArray &d)
3830 // TODO: make more precise check for unicode 16.
3831 // Guess unicode16 if any of second bytes are zero
3832 unsigned int length = max(0,d.size()-2)/2;
3833 for (unsigned int i = 0; i<length ; i++)
3834 if (d.at(i*2+1)==0) return true;
3838 void MapEditor::contentsDropEvent(QDropEvent *event)
3841 (typeid(*selection) == typeid(BranchObj)) ||
3842 (typeid(*selection) == typeid(MapCenterObj)))
3847 if (event->provides("image/png"))
3850 if (Q3ImageDrag::decode(event, pix))
3858 } else if (event->provides("application/x-moz-file-promise-url") &&
3859 event->provides("application/x-moz-nativeimage"))
3861 // Contains url to the img src in unicode16
3862 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3863 QString url = QString((const QChar*)d.data(),d.size()/2);
3867 } else if (event->provides ("text/uri-list"))
3868 { // Uris provided e.g. by konqueror
3869 Q3UriDrag::decode (event,uris);
3870 } else if (event->provides ("_NETSCAPE_URL"))
3871 { // Uris provided by Mozilla
3872 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3875 } else if (event->provides("text/html")) {
3877 // Handels text mime types
3878 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3879 QByteArray d = event->encodedData("text/html");
3882 text = QString((const QChar*)d.data(),d.size()/2);
3886 textEditor->setText(text);
3890 } else if (event->provides("text/plain")) {
3891 QByteArray d = event->encodedData("text/plain");
3894 text = QString((const QChar*)d.data(),d.size()/2);
3898 textEditor->setText(text);
3910 for (const char* u=uris.first(); u; u=uris.next())
3912 bo=((BranchObj*)selection)->addBranch();
3915 s=Q3UriDrag::uriToLocalFile(u);
3918 QString file = QDir::convertSeparators(s);
3919 heading = QFileInfo(file).baseName();
3921 if (file.endsWith(".vym", false))
3922 bo->setVymLink(file);
3931 if (!heading.isEmpty())
3932 bo->setHeading(heading);
3942 //FIXME saveState has to be called earlier for each of the drops...
3943 saveStateComplete("Drop Event"); //TODO undo Command
3944 mapCenter->reposition();
3951 void MapEditor::addFloatImage(const QPixmap &img)
3954 (typeid(*selection) == typeid(BranchObj)) ||
3955 (typeid(*selection) == typeid(MapCenterObj)) )
3957 BranchObj *bo=((BranchObj*)selection);
3958 saveStatePart(selection,QString("Add floatimage to %1").arg(getName(bo)));
3959 //QString fn=fd->selectedFile();
3960 //lastImageDir=fn.left(fn.findRev ("/"));
3961 bo->addFloatImage();
3962 // FIXME check if load was successful
3963 bo->getLastFloatImage()->load(img);
3964 //bo->getLastFloatImage()->setOriginalFilename(fn);
3965 mapCenter->reposition();
3972 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
3974 if (!imageBuffer) imageBuffer = new QBuffer();
3975 if (!imageBuffer->isOpen()) {
3976 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3978 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3982 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3984 if (nop->state()==Q3NetworkProtocol::StDone) {
3985 QPixmap img(imageBuffer->buffer());
3990 imageBuffer->close();
3992 imageBuffer->close();
3999 void MapEditor::fetchImage(const QString &url)
4002 urlOperator->stop();
4003 disconnect(urlOperator);
4007 urlOperator = new Q3UrlOperator(url);
4008 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
4009 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
4011 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
4012 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));