3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <qpopupmenu.h>
9 #include <qpaintdevicemetrics.h>
11 #include <qfiledialog.h>
14 #include <qcolordialog.h>
17 #include <qinputdialog.h>
18 #include <qdragobject.h>
19 #include <qurloperator.h>
20 #include <qnetworkprotocol.h>
31 #include "texteditor.h"
32 #include "linkablemapobj.h"
35 #include "mainwindow.h"
36 #include "extrainfodialog.h"
37 #include "editxlinkdialog.h"
40 #include "icons/flag-note.xpm"
41 #include "icons/flag-url.xpm"
42 #include "icons/flag-vymlink.xpm"
43 #include "icons/flag-scrolled-right.xpm"
44 #include "icons/flag-tmpUnscrolled-right.xpm"
45 #include "icons/flag-questionmark.xpm"
46 #include "icons/flag-exclamationmark.xpm"
47 #include "icons/flag-hook-green.xpm"
48 #include "icons/flag-cross-red.xpm"
49 #include "icons/flag-stopsign.xpm"
50 #include "icons/flag-smiley-good.xpm"
51 #include "icons/flag-smiley-sad.xpm"
52 #include "icons/flag-clock.xpm"
53 #include "icons/flag-lamp.xpm"
54 #include "icons/flag-arrow-up.xpm"
55 #include "icons/flag-arrow-down.xpm"
56 #include "icons/flag-thumb-up.xpm"
57 #include "icons/flag-thumb-down.xpm"
58 #include "icons/flag-heart.xpm"
59 #include "icons/flag-flash.xpm"
60 #include "icons/flag-lifebelt.xpm"
62 extern TextEditor *textEditor;
63 extern int statusbarTime;
64 extern Main *mainWindow;
65 extern FlagRowObj *systemFlagsDefault;
66 extern FlagRowObj *standardFlagsDefault;
67 extern MapEditor *clipboardME;
69 extern QPtrList <QAction> actionListBranches;
71 extern QAction *actionFileSave;
72 extern QAction *actionEditUndo;
73 extern QAction *actionEditCopy;
74 extern QAction *actionEditCut;
75 extern QAction *actionEditPaste;
76 extern QAction *actionEditMoveUp;
77 extern QAction *actionEditMoveDown;
78 extern QAction *actionEditToggleScroll;
79 extern QAction *actionEditOpenURL;
80 extern QAction *actionEditURL;
81 extern QAction *actionEditHeading2URL;
82 extern QAction *actionEditBugzilla2URL;
83 extern QAction *actionEditOpenVymLink;
84 extern QAction *actionEditVymLink;
85 extern QAction *actionEditDeleteVymLink;
86 extern QAction *actionEditHeading;
87 extern QAction *actionEditDelete;
88 extern QAction *actionEditAddBranch;
89 extern QAction *actionEditAddBranchAbove;
90 extern QAction *actionEditAddBranchBelow;
91 extern QAction *actionEditRemoveBranchHere;
92 extern QAction *actionEditRemoveChilds;
93 extern QAction *actionEditImportAdd;
94 extern QAction *actionEditImportReplace;
95 extern QAction *actionEditSaveBranch;
96 extern QAction *actionEditSelectFirst;
97 extern QAction *actionEditSelectLast;
98 extern QAction *actionEditLoadImage;
99 extern QAction *actionEditToggleFloatExport;
101 extern QAction* actionFormatPickColor;
102 extern QAction* actionFormatColorBranch;
103 extern QAction* actionFormatColorSubtree;
104 extern QAction *actionFormatLinkColorHint;
105 extern QAction *actionFormatBackColor;
106 extern QAction *actionFormatLinkColor;
108 extern QActionGroup* actionGroupModModes;
109 extern QAction* actionModModeColor;
110 extern QAction* actionModModeLink;
111 extern QAction* actionModModeCopy;
113 extern QActionGroup *actionGroupFormatFrameTypes;
114 extern QAction *actionFormatFrameNone;
115 extern QAction *actionFormatFrameRectangle;
117 extern QActionGroup *actionGroupFormatLinkStyles;
118 extern QAction *actionFormatLinkStyleLine;
119 extern QAction *actionFormatLinkStyleParabel;
120 extern QAction *actionFormatLinkStylePolyLine;
121 extern QAction *actionFormatLinkStylePolyParabel;
123 extern QAction *actionViewToggleNoteEditor;
125 extern QAction *actionSettingsAutoedit;
126 extern QAction *actionSettingsAutoselectHeading;
127 extern QAction *actionSettingsAutoselectText;
128 extern QAction *actionSettingsPasteNewHeading;
129 extern QAction *actionSettingsUseFlagGroups;
131 extern QPopupMenu *branchContextMenu;
132 extern QPopupMenu *branchLinksContextMenu;
133 extern QPopupMenu *branchLinksContextMenuDup;
134 extern QPopupMenu *floatimageContextMenu;
135 extern QPopupMenu *saveImageFormatMenu;
136 extern QPopupMenu *exportImageFormatMenu;
137 extern QPopupMenu *canvasContextMenu;
139 extern Settings settings;
142 ///////////////////////////////////////////////////////////////////////
143 ///////////////////////////////////////////////////////////////////////
144 MapEditor::MapEditor(
145 QWidget* parent, bool interactive, const char* name, WFlags f) :
146 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
148 //cout << "Constructor ME "<<this<<endl;
150 viewport()->setAcceptDrops(true);
152 mapCanvas = new QCanvas(1000,800);
153 mapCanvas->setAdvancePeriod(30);
155 setCanvas (mapCanvas);
157 setVScrollBarMode ( QScrollView::AlwaysOn );
158 setHScrollBarMode ( QScrollView::AlwaysOn );
160 // Now create the _global_ system flags _once_:
161 // (Later all OrnamentedObj copy from this
162 // and set their own canvas)
163 if (!systemFlagsDefault)
165 systemFlagsDefault = new FlagRowObj (mapCanvas);
166 systemFlagsDefault->setVisibility (false);
167 systemFlagsDefault->setName ("systemFlagsDef");
169 FlagObj *fo = new FlagObj (mapCanvas);
170 fo->load(QPixmap(flag_note_xpm));
172 fo->setToolTip(tr("Note","Systemflag"));
173 systemFlagsDefault->addFlag (fo); // makes deep copy
175 fo->load(QPixmap(flag_url_xpm));
177 fo->setToolTip(tr("WWW Document (external)","Systemflag"));
178 systemFlagsDefault->addFlag (fo);
180 fo->load(QPixmap(flag_vymlink_xpm));
181 fo->setName("vymLink");
182 fo->setToolTip(tr("Link to another vym map","Systemflag"));
183 systemFlagsDefault->addFlag (fo);
185 fo->load(QPixmap(flag_scrolled_right_xpm));
186 fo->setName("scrolledright");
187 fo->setToolTip(tr("subtree is scrolled","Systemflag"));
188 systemFlagsDefault->addFlag (fo);
190 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
191 fo->setName("tmpUnscrolledright");
192 fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
193 systemFlagsDefault->addFlag (fo);
196 if (!standardFlagsDefault)
198 standardFlagsDefault = new FlagRowObj (mapCanvas);
199 standardFlagsDefault->setVisibility (false);
200 standardFlagsDefault->setName ("standardFlagsDef");
202 FlagObj *fo = new FlagObj (mapCanvas);
203 fo->load(QPixmap(flag_exclamationmark_xpm));
204 fo->setName ("exclamationmark");
205 fo->setGroup("standard-mark");
206 fo->setToolTip(tr("Take care!","Standardflag"));
207 standardFlagsDefault->addFlag (fo); // makes deep copy
209 fo->load(QPixmap(flag_questionmark_xpm));
210 fo->setName("questionmark");
211 fo->setGroup("standard-mark");
212 fo->setToolTip(tr("Really?","Standardflag"));
213 standardFlagsDefault->addFlag (fo);
215 fo->load(QPixmap(flag_hook_green_xpm));
216 fo->setName("hook-green");
217 fo->setGroup("standard-hook");
218 fo->setToolTip(tr("ok!","Standardflag"));
219 standardFlagsDefault->addFlag (fo);
221 fo->load(QPixmap(flag_cross_red_xpm));
222 fo->setName("cross-red");
223 fo->setGroup("standard-hook");
224 fo->setToolTip(tr("Not ok!","Standardflag"));
225 standardFlagsDefault->addFlag (fo);
227 fo->load(QPixmap(flag_stopsign_xpm));
228 fo->setName("stopsign");
229 fo->setToolTip(tr("This won't work!","Standardflag"));
230 standardFlagsDefault->addFlag (fo);
232 fo->load(QPixmap(flag_smiley_good_xpm));
233 fo->setName("smiley-good");
234 fo->setGroup("standard-smiley");
235 fo->setToolTip(tr("Good","Standardflag"));
236 standardFlagsDefault->addFlag (fo);
238 fo->load(QPixmap(flag_smiley_sad_xpm));
239 fo->setName("smiley-sad");
240 fo->setGroup("standard-smiley");
241 fo->setToolTip(tr("Bad","Standardflag"));
242 standardFlagsDefault->addFlag (fo);
244 fo->load(QPixmap(flag_clock_xpm));
245 fo->setName("clock");
246 fo->setToolTip(tr("Time critical","Standardflag"));
247 standardFlagsDefault->addFlag (fo);
249 fo->load(QPixmap(flag_lamp_xpm));
251 fo->setToolTip(tr("Idea!","Standardflag"));
252 standardFlagsDefault->addFlag (fo);
254 fo->load(QPixmap(flag_arrow_up_xpm));
255 fo->setName("arrow-up");
256 fo->setGroup("standard-arrow");
257 fo->setToolTip(tr("Important","Standardflag"));
258 standardFlagsDefault->addFlag (fo);
260 fo->load(QPixmap(flag_arrow_down_xpm));
261 fo->setName("arrow-down");
262 fo->setGroup("standard-arrow");
263 fo->setToolTip(tr("Unimportant","Standardflag"));
264 standardFlagsDefault->addFlag (fo);
266 fo->load(QPixmap(flag_thumb_up_xpm));
267 fo->setName("thumb-up");
268 fo->setGroup("standard-thumb");
269 fo->setToolTip(tr("I like this","Standardflag"));
270 standardFlagsDefault->addFlag (fo);
272 fo->load(QPixmap(flag_thumb_down_xpm));
273 fo->setName("thumb-down");
274 fo->setGroup("standard-thumb");
275 fo->setToolTip(tr("I like this","Standardflag"));
276 fo->setToolTip(tr("I do not like this","Standardflag"));
277 standardFlagsDefault->addFlag (fo);
279 fo->load(QPixmap(flag_heart_xpm));
280 fo->setName("heart");
281 fo->setToolTip(tr("I just love... ","Standardflag"));
282 standardFlagsDefault->addFlag (fo);
284 fo->load(QPixmap(flag_flash_xpm));
285 fo->setName("flash");
286 fo->setToolTip(tr("Dangerous","Standardflag"));
287 standardFlagsDefault->addFlag (fo);
289 fo->load(QPixmap(flag_lifebelt_xpm));
290 fo->setName("lifebelt");
291 fo->setToolTip(tr("This will help","Standardflag"));
292 standardFlagsDefault->addFlag (fo);
297 mapCenter = new MapCenterObj(mapCanvas);
298 mapCenter->setVisibility (true);
299 mapCenter->setMapEditor (this);
300 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
304 lineedit = new QLineEdit(this, "lineedit" );
305 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
308 actColor=black; setColor (actColor);
309 defLinkColor=QColor (0,0,255);
310 defXLinkColor=QColor (180,180,180);
311 linkcolorhint=DefaultColor;
312 linkstyle=StylePolyParabel;
313 mapCanvas->setBackgroundColor (white);
315 // Create bitmap cursors, patform dependant
316 #if defined(Q_OS_MACX)
317 #include "icons/cursorhandopen16.xpm"
318 #include "icons/cursorcolorpicker16.xpm"
319 QBitmap cb( 16, 16, chandopen, TRUE );
320 QBitmap cm( 16, 16, chandopenmask, TRUE );
321 handOpenCursor=QCursor ( cb, cm );
322 // set hot spot to tip of picker
323 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
325 #include "icons/cursorhandopen.xpm"
326 #include "icons/cursorcolorpicker.xpm"
328 QBitmap cb( 32, 32, chandopen, TRUE );
329 QBitmap cm( 32, 32, chandopenmask, TRUE );
330 handOpenCursor=QCursor ( cb, cm );
331 // set hot spot to tip of picker
332 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
345 defXLinkColor=QColor (230,230,230);
356 // Initialize find routine
363 blockreposition=false;
364 isInteractive=interactive;
366 // Create temporary files
369 // Initially set movingCentre
372 mapCenter->reposition(); // for positioning heading
375 MapEditor::~MapEditor()
377 if (imageBuffer) delete imageBuffer;
383 //cout <<"Destructor MapEditor\n";
384 if (isInteractive) delTmpDirs();
387 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
391 QColor MapEditor::color()
396 QColor MapEditor::backgroundColor()
398 return mapCanvas->backgroundColor();
401 MapCenterObj* MapEditor::getMapCenter()
406 QCanvas* MapEditor::getCanvas()
411 void MapEditor::adjustCanvasSize()
413 // To adjust the canvas to map, viewport size and position, we have to
414 // do some coordinate magic...
416 // Get rectangle of (scroll-)view.
417 // We want to be in canvas coords, so
418 // we map. Important if view is zoomed...
419 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
420 visibleWidth(), visibleHeight()) );
422 // Now we need the bounding box of view AND map to calc the correct canvas size.
423 // Why? Because if the map itself is moved out of view, the view has to be enlarged
424 // to avoid jumping aroung...
425 QRect map=mapCenter->getTotalBBox();
427 // right edge - left edge
428 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
429 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
432 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
433 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
436 // move the map on canvas (in order to not move it on screen) this is neccessary
437 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
438 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
439 // to scroll to an empty area of canvas to the left.
440 // b) if topleft corner of map left of or above topleft of canvas
444 if (cw > mapCanvas->width() )
446 if (map.x()<0) dx=-map.x();
448 if (cw < mapCanvas->width() )
449 dx=-min (view.x(),map.x());
450 if (ch > mapCanvas->height() )
452 if (map.y()<0) dy=-map.y();
454 if (ch < mapCanvas->height() )
456 dy=-min (view.y(),map.y());
458 // We really have to resize now. Let's go...
459 mapCanvas->resize (cw,ch);
460 if ( (dx!=0) || (dy!=0) )
462 mapCenter->moveAllBy(dx,dy);
463 mapCenter->reposition();
465 // scroll the view (in order to not move map on screen)
471 bool MapEditor::blockReposition()
473 return blockreposition;
476 void MapEditor::makeTmpDirs()
478 // Create unique temporary directories
479 char tmpdir[]="/tmp/vym-XXXXXX";
480 bakMapDir=mkdtemp(tmpdir);
481 makeSubDirs(bakMapDir);
482 // FIXME set permissions and maybe use QT method for portability
485 void MapEditor::delTmpDirs()
487 //FIXME delete tmp directory, better use QT methods here:
488 system ( "rm -rf "+ bakMapDir );
492 void MapEditor::makeSubDirs(const QString &s)
500 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
502 // tmpdir temporary directory to which data will be writte
503 // prefix mapname, which will be appended to images etc.
504 // writeflags Only write flags for "real" save of map, not undo
505 // offset offset of bbox of whole map in canvas.
506 // Needed for XML export
507 // completeMap if false, only vympart will be written, without
524 ls="StylePolyParabel";
528 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
530 if (linkcolorhint==HeadingColor)
531 colhint=attribut("linkColorHint","HeadingColor");
533 QString mapAttr=attribut("version",__VYM_VERSION__);
535 mapAttr+= attribut("author",mapCenter->getAuthor()) +
536 attribut("comment",mapCenter->getComment()) +
537 attribut("date",mapCenter->getDate()) +
538 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
539 attribut("linkStyle", ls ) +
540 attribut("linkColor", defLinkColor.name() ) +
541 attribut("defXLinkColor", defXLinkColor.name() ) +
542 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
544 s+=beginElement("vymmap",mapAttr);
547 // Find the used flags while traversing the tree
548 standardFlagsDefault->resetUsedCounter();
550 // Build xml recursivly
552 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
555 if ( typeid(*saveSelection) == typeid(BranchObj) )
556 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
558 if (selection && typeid(*selection)==typeid(BranchObj))
559 // This is used if selected branch is saved from mainwindow
560 s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
563 // Save local settings
564 s+=settings.getXMLData (destPath);
567 if (selection && !saveSelection)
568 s+=valueElement("select",selection->getSelectString());
571 s+=endElement("vymmap");
574 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
578 void MapEditor::saveState()
580 saveState (CompleteMap,NULL,"");
583 void MapEditor::saveState(LinkableMapObj *undoSel)
585 saveState (PartOfMap,undoSel,"");
588 void MapEditor::saveState(const QString & c)
590 saveState (UndoCommand,NULL,c);
593 void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom)
595 if (savemode==UndoCommand)
600 else if (savemode==PartOfMap && undoSel)
602 undoCommand="undoPart (\""+undoSel->getSelectString()+"\")";
603 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
606 undoCommand="undoMap ()";
607 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
610 cout << "ME::saveState()\n";
611 cout << " undoCom="<<undoCommand<<endl;
615 void MapEditor::parseAtom(const QString &atom)
622 // Split string s into command and parameters
623 api.parseCommand (atom);
624 QString com=api.command();
627 if (com==QString("moveBranchUp"))
629 else if (com=="moveBranchDown")
631 else if (com=="move")
633 if (api.checkParamCount(2) &&
644 else if (com=="linkBranchToPos")
646 if (selection && typeid(*selection) == typeid(BranchObj) )
648 if (api.checkParamCount(4))
650 s=api.parString(ok,0);
651 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
654 if (typeid(*dst) == typeid(BranchObj) )
655 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
656 if (typeid(*dst) == typeid(MapCenterObj) )
658 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
663 if (ok) ((BranchObj*)(selection))->move (x,y);
669 } else if (com=="setHeading")
671 if (api.checkParamCount(1))
673 s=api.parString (ok,0);
674 if (ok) setHeading (s);
677 // Internal commands, used for undo etc.
678 else if (com==QString("undoMap"))
680 else if (com==QString("undoPart"))
682 if (api.checkParamCount(1))
684 s=api.parString (ok,0);
687 } else if (com=="select")
688 if (api.checkParamCount(1))
690 s=api.parString(ok,0);
694 api.setError ("Unknown command in: "+atom);
699 cout << "MapEditor::parseAtom: Error!\n";
700 cout << " "<<api.errorDesc()<<endl;
705 void MapEditor::finishedLineEditNoSave()
707 // This is called by finishedLineEdit or any MapEditor method,
708 // which wants to assure, that lineedits finish, before e.g. a branch is
711 // After calling LineEdit and using the clipboard, the
712 // focus is not any longer on the main widget, we
713 // have to restore it using parentWidget()->setFocus()
717 editingBO->setHeading(lineedit->text() );
719 lineedit->releaseKeyboard();
721 parentWidget()->setFocus();
722 mapCenter->reposition();
724 ensureSelectionVisible();
729 bool MapEditor::isDefault()
734 bool MapEditor::isUnsaved()
739 bool MapEditor::hasChanged()
744 void MapEditor::setChanged()
749 actionEditUndo->setEnabled (true);
750 actionFileSave->setEnabled (true);
754 void MapEditor::closeMap()
756 // Finish open lineEdits
757 if (lineedit) finishedLineEditNoSave();
759 // Unselect before disabling the toolbar actions
760 if (selection) selection->unselect();
768 void MapEditor::setFilePath(QString fname)
770 setFilePath (fname,fname);
773 void MapEditor::setFilePath(QString fname, QString destname)
782 filePath=fname; // becomes absolute path
783 fileName=fname; // gets stripped of path
784 destPath=destname; // needed for vymlinks
786 // If fname is not an absolute path, complete it
787 filePath=QDir(fname).absPath();
788 fileDir=filePath.left (1+filePath.findRev ("/"));
790 // Set short name, too. Search from behind:
791 int i=fileName.findRev("/");
792 if (i>=0) fileName=fileName.remove (0,i+1);
794 // Forget the .vym (or .xml) for name of map
795 mapName=fileName.left(fileName.findRev(".",-1,true) );
799 QString MapEditor::getFilePath()
804 QString MapEditor::getFileName()
809 QString MapEditor::getMapName()
814 QString MapEditor::getDestPath()
819 int MapEditor::load (QString &fname, const LoadMode &lmode)
821 // Finish open lineEdits
822 if (lineedit) finishedLineEditNoSave();
828 if (selection) selection->unselect();
831 mapCenter->setMapEditor(this);
832 // (map state is set later at end of load...)
836 saveState(selection);
840 mapBuilderHandler handler;
843 // I am paranoid: file should exist anyway
844 // according to check in mainwindow.
847 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
848 tr("Couldn't open map " +fname)+".");
852 blockreposition=true;
853 QXmlInputSource source( file);
854 QXmlSimpleReader reader;
855 reader.setContentHandler( &handler );
856 reader.setErrorHandler( &handler );
857 handler.setMapEditor( this );
858 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
859 handler.setLoadMode (lmode);
860 bool ok = reader.parse( source );
861 blockreposition=false;
865 mapCenter->reposition();
875 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
876 tr( handler.errorProtocol() ) );
878 // Still return "success": the map maybe at least
879 // partially read by the parser
886 int MapEditor::save (const SaveMode &savemode)
888 // Finish open lineEdits
889 if (lineedit) finishedLineEditNoSave();
893 // The SaveMode UndoCommand is not supported here
894 if (savemode==UndoCommand) return 1;
896 // Create mapName and fileDir
897 makeSubDirs (fileDir);
901 fname=mapName+".xml";
903 // use name given by user, even if he chooses .doc
907 // Check if fname is writeable
908 QFile file( fileDir+fname);
909 if (!file.open( IO_WriteOnly ) )
911 QMessageBox::critical( 0, tr( "Critical Save Error" ),
912 tr("Couldn't write to ") +fileDir+fname);
918 if (savemode==CompleteMap || selection==NULL)
919 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
921 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
923 file.setName ( fileDir + fname);
924 if ( !file.open( IO_WriteOnly ) )
926 // This should neverever happen
927 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
931 // Write it finally, and write in UTF8, no matter what
932 QTextStream ts( &file );
933 ts.setEncoding (QTextStream::UnicodeUTF8);
941 actionFileSave->setEnabled(false);
947 void MapEditor::setZipped (bool z)
952 bool MapEditor::saveZipped ()
957 void MapEditor::print()
959 // Finish open lineEdits
960 if (lineedit) finishedLineEditNoSave();
964 printer = new QPrinter;
965 printer->setColorMode (QPrinter::Color);
966 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
969 QRect totalBBox=mapCenter->getTotalBBox();
971 // Try to set orientation automagically
972 // Note: Interpretation of generated postscript is amibiguous, if
973 // there are problems with landscape mode, see
974 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
976 if (totalBBox.width()>totalBBox.height())
977 // recommend landscape
978 printer->setOrientation (QPrinter::Landscape);
980 // recommend portrait
981 printer->setOrientation (QPrinter::Portrait);
983 if ( printer->setup(this) )
984 // returns false, if printing is canceled
986 QPainter pp(printer);
988 // Don't print the visualisation of selection
989 LinkableMapObj *oldselection=NULL;
992 oldselection=selection;
993 selection->unselect();
996 // Handle sizes of map and paper:
998 // setWindow defines which part of the canvas will be transformed
999 // setViewport defines area on paper in device coordinates (dpi)
1000 // e.g. (0,50,700,700) is upper part on A4
1001 // see also /usr/lib/qt3/doc/html/coordsys.html
1003 QPaintDeviceMetrics metrics (printer);
1005 double paperAspect = (double)metrics.width() / (double)metrics.height();
1006 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1008 QRect mapRect=totalBBox;
1009 QCanvasRectangle *frame=NULL;
1010 QCanvasText *footerFN=NULL;
1011 QCanvasText *footerDate=NULL;
1012 if (printFrame || printFooter)
1017 // Print frame around map
1018 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1019 totalBBox.width()+20, totalBBox.height()+20);
1020 frame=new QCanvasRectangle (mapRect,mapCanvas);
1021 frame->setBrush (QColor(white));
1022 frame->setPen (QColor(black));
1027 QCanvasLine *l=new QCanvasLine (mapCanvas);
1028 l->setPoints (0,0,mapRect.width(),mapRect.height());
1029 l->setPen (QPen(QColor(black), 1));
1036 // Print footer below map
1038 font.setPointSize(10);
1039 footerFN=new QCanvasText (mapCanvas);
1040 footerFN->setText ("VYM - " + fileName);
1041 footerFN->setFont(font);
1042 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1043 footerFN->setZ(Z_TEXT);
1045 footerDate=new QCanvasText (mapCanvas);
1046 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1047 footerDate->setFont(font);
1048 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1049 footerDate->setZ(Z_TEXT);
1052 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1055 pp.setWindow (mapRect);
1058 if (mapAspect>=paperAspect)
1060 // Fit horizontally to paper width
1061 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1064 // Fit vertically to paper height
1065 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1068 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1070 // Delete Frame and footer
1074 delete (footerDate);
1076 if (frame) delete (frame);
1078 // Restore selection
1081 selection=oldselection;
1082 selection->select();
1085 // Save settings in vymrc
1086 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1090 QPixmap MapEditor::getPixmap()
1092 QRect mapRect=mapCenter->getTotalBBox();
1093 QPixmap pix (mapRect.size());
1096 // Don't print the visualisation of selection
1097 LinkableMapObj *oldselection=NULL;
1100 oldselection=selection;
1101 selection->unselect();
1104 pp.setWindow (mapRect);
1106 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1109 // Restore selection
1112 selection=oldselection;
1113 selection->select();
1119 void MapEditor::exportImage(QString fn)
1121 // Finish open lineEdits
1122 if (lineedit) finishedLineEditNoSave();
1124 QPixmap pix (getPixmap());
1125 pix.save(fn, "PNG");
1128 void MapEditor::exportImage(QString fn, int item)
1130 // Finish open lineEdits
1131 if (lineedit) finishedLineEditNoSave();
1133 QPixmap pix (getPixmap());
1134 pix.save(fn, exportImageFormatMenu->text(item) );
1137 void MapEditor::exportASCII()
1139 // FIXME still experimental
1140 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
1141 fd->addFilter ("TXT (*.txt)");
1142 fd->setCaption("VYM - Export (ASCII) (still experimental)");
1143 fd->setMode( QFileDialog::AnyFile );
1146 if ( fd->exec() == QDialog::Accepted )
1148 if (QFile (fd->selectedFile()).exists() )
1150 QMessageBox mb( "VYM",
1151 tr("The file ") + fd->selectedFile() +
1152 tr(" exists already. Do you want to overwrite it?"),
1153 QMessageBox::Warning,
1154 QMessageBox::Yes | QMessageBox::Default,
1155 QMessageBox::Cancel | QMessageBox::Escape,
1156 QMessageBox::NoButton );
1158 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1159 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1163 case QMessageBox::Yes:
1165 if (!ex.setOutputDir ("out"))
1167 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1171 case QMessageBox::Cancel:
1178 ex.setPath (fd->selectedFile() );
1179 ex.setMapCenter(mapCenter);
1185 void MapEditor::exportXML(const QString &dir)
1187 // Create subdirectories
1190 // write to directory
1191 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1194 file.setName ( dir + "/"+mapName+".xml");
1195 if ( !file.open( IO_WriteOnly ) )
1197 // This should neverever happen
1198 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1202 // Write it finally, and write in UTF8, no matter what
1203 QTextStream ts( &file );
1204 ts.setEncoding (QTextStream::UnicodeUTF8);
1208 // Now write image, too
1209 exportImage (dir+"/images/"+mapName+".png");
1212 void MapEditor::clear()
1216 selection->unselect();
1223 void MapEditor::copy()
1225 // Finish open lineEdits
1226 if (lineedit) finishedLineEditNoSave();
1230 if (typeid(*selection) == typeid(BranchObj) )
1234 clipboardME->clear();
1235 clipboardME->getMapCenter()->addBranch();
1236 to=clipboardME->getMapCenter()->getLastBranch();
1239 from=(BranchObj*)(selection);
1242 // keep position relative to parent
1243 to->move2RelPos ( from->getRelPos());
1245 // select data in clipboard
1246 clipboardME->select ("bo:0");
1248 // repositioning makes testing nicer,
1249 // but is not needed usually:
1250 if (clipboardME->isVisible())
1252 clipboardME->getMapCenter()->reposition();
1255 clipboardME->hide();
1258 if (typeid(*selection) == typeid(FloatImageObj) )
1261 FloatImageObj* from;
1262 clipboardME->clear();
1263 clipboardME->getMapCenter()->addFloatImage();
1264 to=clipboardME->getMapCenter()->getLastFloatImage();
1267 from=(FloatImageObj*)(selection);
1270 // select data in clipboard
1271 clipboardME->select ("fi:0");
1273 // repositioning makes testing nicer,
1274 // but is not needed usually:
1275 if (clipboardME->isVisible())
1277 clipboardME->getMapCenter()->reposition();
1280 clipboardME->hide();
1286 void MapEditor::undo()
1288 // Finish open lineEdits
1289 if (lineedit) finishedLineEditNoSave();
1295 selection->unselect();
1300 parseAtom (undoCommand);
1301 mapCenter->reposition();
1303 // Undo not longer available now
1304 actionEditUndo->setEnabled (false);
1309 void MapEditor::undoXML(const QString &undoSel)
1312 d.setPath(bakMapDir);
1315 // We need to parse saved XML data
1316 mapBuilderHandler handler;
1317 QXmlInputSource source;
1318 source.setData(backupXML);
1319 QXmlSimpleReader reader;
1320 reader.setContentHandler( &handler );
1321 reader.setErrorHandler( &handler );
1322 handler.setMapEditor( this );
1323 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1324 if (undoSel.isEmpty())
1327 handler.setLoadMode (NewMap);
1331 handler.setLoadMode (ImportReplace);
1333 blockreposition=true;
1334 bool ok = reader.parse( source );
1335 blockreposition=false;
1338 // This should never ever happen
1339 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1340 tr( handler.errorProtocol() )+" in "+backupXML );
1344 QMessageBox::critical( 0, tr( "Critical Error" ),
1345 "Temporary directory " +bakMapDir +
1346 tr (" used for undo is gone. \n"
1347 "I will create a new one, but at the moment no undo is available.\n"
1348 "Maybe you want to reload your original data.\n\n"
1349 "Sorry for any inconveniences.") );
1354 LinkableMapObj* MapEditor::pasteNoSave()
1356 // Finish open lineEdits
1357 if (lineedit) finishedLineEditNoSave();
1359 LinkableMapObj *fromLMO=clipboardME->getSelection();
1360 LinkableMapObj *returnLMO=NULL;
1362 if (selection && fromLMO)
1364 if (typeid(*fromLMO) == typeid(BranchObj) )
1366 if (typeid(*selection) == typeid(MapCenterObj))
1368 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1369 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1371 if (typeid(*selection) == typeid(BranchObj))
1372 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1375 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1376 (typeid(*selection) == typeid (BranchObj) ||
1377 typeid(*selection)==typeid(MapCenterObj)) )
1378 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1384 void MapEditor::cutNoSave()
1386 // Finish open lineEdits
1387 if (lineedit) finishedLineEditNoSave();
1391 if (selection != NULL) {
1392 if (typeid(*selection) == typeid(BranchObj) )
1394 bo=(BranchObj*)(selection);
1395 par=(BranchObj*)(bo->getParObj());
1398 par->removeBranch(bo);
1400 selection->select();
1402 if (typeid(*selection) == typeid(FloatImageObj) )
1404 FloatImageObj* fio=(FloatImageObj*)(selection);
1405 par=(BranchObj*)(fio->getParObj());
1408 par->removeFloatImage(fio);
1410 selection->select();
1415 void MapEditor::paste()
1418 saveState(selection);
1420 mapCenter->reposition();
1424 void MapEditor::cut()
1427 saveState(selection->getParObj());
1430 mapCenter->reposition();
1434 void MapEditor::move(const int &x, const int &y)
1436 // FIXME no saveState, because this is only internal at undo so far
1437 if (selection) selection->move(x,y);
1438 if (typeid(*selection) == typeid(FloatImageObj))
1439 ((FloatImageObj*)(selection))->setRelPos();
1442 void MapEditor::moveBranchUp()
1444 // Finish open lineEdits
1445 if (lineedit) finishedLineEditNoSave();
1449 if (typeid(*selection) == typeid(BranchObj) )
1452 saveState("moveBranchDown ()");
1453 bo=(BranchObj*)(selection);
1454 par=(BranchObj*)(bo->getParObj());
1455 selection->unselect();
1456 selection=par->moveBranchUp (bo);
1457 selection->select();
1458 mapCenter->reposition();
1459 ensureSelectionVisible();
1463 void MapEditor::moveBranchDown()
1465 // Finish open lineEdits
1466 if (lineedit) finishedLineEditNoSave();
1470 if (typeid(*selection) == typeid(BranchObj) )
1473 saveState("moveBranchUp ()");
1474 bo=(BranchObj*)(selection);
1475 par=(BranchObj*)(bo->getParObj());
1476 selection->unselect();
1477 selection=par->moveBranchDown(bo);
1478 selection->select();
1479 mapCenter->reposition();
1480 ensureSelectionVisible();
1484 void MapEditor::editHeading()
1486 // Finish open lineEdits
1487 if (lineedit) finishedLineEditNoSave();
1490 (typeid(*selection) == typeid(BranchObj) ||
1491 typeid(*selection) == typeid(MapCenterObj) ) )
1494 saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")");
1496 ensureSelectionVisible();
1497 editingBO=(BranchObj*)(selection);
1498 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1499 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1500 QString s=editingBO->getHeading();
1501 lineedit->setText(s);
1502 lineedit->setCursorPosition(1);
1503 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1504 lineedit->selectAll();
1507 lineedit->grabKeyboard();
1508 lineedit->setFocus();
1512 void MapEditor::setHeading(const QString &s)
1514 // Internal function, no saveState needed
1516 (typeid(*selection) == typeid(BranchObj) ||
1517 typeid(*selection) == typeid(MapCenterObj) ) )
1519 ((BranchObj*)(selection))->setHeading(s);
1520 mapCenter->reposition();
1522 ensureSelectionVisible();
1526 void MapEditor::addNewBranch(int pos)
1528 // Finish open lineEdits
1529 if (lineedit) finishedLineEditNoSave();
1532 (typeid(*selection) == typeid(BranchObj) ||
1533 typeid(*selection) == typeid(MapCenterObj) ) )
1536 saveState(selection);
1538 BranchObj* bo1 = (BranchObj*) (selection);
1539 bool wasScrolled=false;
1540 BranchObj *newbo=NULL;
1543 // save scroll state. If scrolled, automatically select
1544 // new branch in order to tmp unscroll parent...
1545 wasScrolled=bo1->isScrolled();
1546 newbo=bo1->addBranch();
1549 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1553 // add above selection
1554 newbo=parbo->insertBranch(bo1->getNum());
1556 // add below selection
1557 newbo=parbo->insertBranch(bo1->getNum()+1);
1559 // This should not happen...
1564 LinkableMapObj *oldselection=selection;
1566 mapCenter->reposition();
1568 if (actionSettingsAutoedit->isOn() ||
1569 actionSettingsAutoselectHeading->isOn() )
1571 selection->unselect();
1573 selection->select();
1574 if (actionSettingsPasteNewHeading->isOn() )
1576 BranchObj *bo2= (BranchObj*)(selection);
1577 bo2->setHeading("");
1579 if (actionSettingsAutoedit->isOn() )
1581 if (!actionSettingsAutoselectHeading->isOn()
1584 selection->unselect();
1585 selection=oldselection;
1586 selection->select();
1593 void MapEditor::addNewBranchHere()
1595 // Finish open lineEdits
1596 if (lineedit) finishedLineEditNoSave();
1599 (typeid(*selection) == typeid(BranchObj) ) )
1602 saveState(selection);
1604 BranchObj* bo1 = (BranchObj*) (selection);
1605 bool wasScrolled=false;
1606 BranchObj *newbo=NULL;
1607 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1610 // add below selection
1611 newbo=parbo->insertBranch(bo1->getNum()+1);
1614 LinkableMapObj *oldselection=selection;
1615 ((BranchObj*)(selection))->moveBranchTo (newbo,-1);
1617 mapCenter->reposition();
1619 if (actionSettingsAutoedit->isOn() ||
1620 actionSettingsAutoselectHeading->isOn() )
1622 selection->unselect();
1624 selection->select();
1625 if (actionSettingsPasteNewHeading->isOn() )
1627 BranchObj *bo2= (BranchObj*)(selection);
1628 bo2->setHeading("");
1630 if (actionSettingsAutoedit->isOn() )
1632 if (!actionSettingsAutoselectHeading->isOn()
1635 selection->unselect();
1636 selection=oldselection;
1637 selection->select();
1643 void MapEditor::deleteSelection()
1645 // Finish open lineEdits
1646 if (lineedit) finishedLineEditNoSave();
1648 if (selection && typeid(*selection) ==typeid(BranchObj) )
1651 saveState(selection->getParObj());
1652 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1653 BranchObj* par=(BranchObj*)(bo->getParObj());
1656 par->removeBranch(bo);
1658 selection->select();
1659 ensureSelectionVisible();
1660 mapCenter->reposition();
1663 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1666 saveState(selection->getParObj());
1667 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1668 BranchObj* par=(BranchObj*)(fio->getParObj());
1671 par->removeFloatImage(fio);
1673 selection->select();
1674 ensureSelectionVisible();
1675 mapCenter->reposition();
1680 LinkableMapObj* MapEditor::getSelection()
1685 bool MapEditor::select (const QString &s)
1687 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1689 // Finally select the found object
1692 if (selection) unselect();
1694 selection->select();
1696 ensureSelectionVisible();
1702 void MapEditor::unselect()
1706 selectionLast=selection;
1707 selection->unselect();
1712 void MapEditor::reselect()
1716 selection=selectionLast;
1717 selection->select();
1722 void MapEditor::selectNextBranch()
1724 // Increase number of branch
1727 QString s=selection->getSelectString();
1733 part=s.section(",",-1);
1735 num=part.right(part.length() - 3);
1737 s=s.left (s.length() -num.length());
1740 num=QString ("%1").arg(num.toUInt()+1);
1744 // Try to select this one
1745 if (select (s)) return;
1747 // We have no direct successor,
1748 // try to increase the parental number in order to
1749 // find a successor with same depth
1751 int d=selection->getDepth();
1756 while (!found && d>0)
1758 s=s.section (",",0,d-1);
1759 // replace substring of current depth in s with "1"
1760 part=s.section(",",-1);
1762 num=part.right(part.length() - 3);
1766 // increase number of parent
1767 num=QString ("%1").arg(num.toUInt()+1);
1768 s=s.section (",",0,d-2) + ","+ typ+num;
1771 // Special case, look at orientation
1772 if (selection->getOrientation()==OrientRightOfCenter)
1773 num=QString ("%1").arg(num.toUInt()+1);
1775 num=QString ("%1").arg(num.toUInt()-1);
1780 // pad to oldDepth, select the first branch for each depth
1781 for (i=d;i<oldDepth;i++)
1786 if ( ((BranchObj*)(selection))->countBranches()>0)
1794 // try to select the freshly built string
1802 void MapEditor::selectPrevBranch()
1804 // Decrease number of branch
1807 QString s=selection->getSelectString();
1813 part=s.section(",",-1);
1815 num=part.right(part.length() - 3);
1817 s=s.left (s.length() -num.length());
1820 num=QString ("%1").arg(num.toUInt()-1);
1824 // Try to select this one
1825 if (select (s)) return;
1827 // We have no direct precessor,
1828 // try to decrease the parental number in order to
1829 // find a precessor with same depth
1831 int d=selection->getDepth();
1836 while (!found && d>0)
1838 s=s.section (",",0,d-1);
1839 // replace substring of current depth in s with "1"
1840 part=s.section(",",-1);
1842 num=part.right(part.length() - 3);
1846 // decrease number of parent
1847 num=QString ("%1").arg(num.toUInt()-1);
1848 s=s.section (",",0,d-2) + ","+ typ+num;
1851 // Special case, look at orientation
1852 if (selection->getOrientation()==OrientRightOfCenter)
1853 num=QString ("%1").arg(num.toUInt()-1);
1855 num=QString ("%1").arg(num.toUInt()+1);
1860 // pad to oldDepth, select the last branch for each depth
1861 for (i=d;i<oldDepth;i++)
1865 if ( ((BranchObj*)(selection))->countBranches()>0)
1866 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1873 // try to select the freshly built string
1881 void MapEditor::selectUpperBranch()
1883 // Finish open lineEdits
1884 if (lineedit) finishedLineEditNoSave();
1888 if (typeid(*selection) == typeid(BranchObj))
1890 if (selection->getOrientation()==OrientRightOfCenter)
1893 if (selection->getDepth()==1)
1901 void MapEditor::selectLowerBranch()
1903 // Finish open lineEdits
1904 if (lineedit) finishedLineEditNoSave();
1908 if (typeid(*selection) == typeid(BranchObj))
1910 if (selection->getOrientation()==OrientRightOfCenter)
1913 if (selection->getDepth()==1)
1922 void MapEditor::selectLeftBranch()
1924 // Finish open lineEdits
1925 if (lineedit) finishedLineEditNoSave();
1931 if (typeid(*selection) == typeid(MapCenterObj))
1933 par= (BranchObj*) (selection);
1934 bo=par->getLastSelectedBranch();
1937 // Workaround for reselecting on left and right side
1938 if (bo->getOrientation()==OrientRightOfCenter)
1940 bo=par->getLastBranch();
1946 selection->select();
1948 ensureSelectionVisible();
1953 par=(BranchObj*)(selection->getParObj());
1954 if (selection->getOrientation()==OrientRightOfCenter)
1956 if (typeid(*selection) == typeid(BranchObj) ||
1957 typeid(*selection) == typeid(FloatImageObj))
1959 selection->unselect();
1961 selection->select();
1963 ensureSelectionVisible();
1967 if (typeid(*selection) == typeid(BranchObj) )
1969 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1972 selection->unselect();
1974 selection->select();
1976 ensureSelectionVisible();
1984 void MapEditor::selectRightBranch()
1986 // Finish open lineEdits
1987 if (lineedit) finishedLineEditNoSave();
1994 if (typeid(*selection) == typeid(MapCenterObj))
1996 par= (BranchObj*) (selection);
1997 bo=par->getLastSelectedBranch();
2000 // Workaround for relecting on left and right side
2001 if (bo->getOrientation()==OrientLeftOfCenter)
2002 bo=par->getFirstBranch();
2007 selection->select();
2008 ensureSelectionVisible();
2013 par=(BranchObj*)(selection->getParObj());
2014 if (selection->getOrientation()==OrientLeftOfCenter)
2016 if (typeid(*selection) == typeid(BranchObj) ||
2017 typeid(*selection) == typeid(FloatImageObj))
2019 selection->unselect();
2021 selection->select();
2023 ensureSelectionVisible();
2027 if (typeid(*selection) == typeid(BranchObj) )
2029 bo=((BranchObj*)(selection))->getLastSelectedBranch();
2032 selection->unselect();
2034 selection->select();
2036 ensureSelectionVisible();
2044 void MapEditor::selectFirstBranch()
2046 // Finish open lineEdits
2047 if (lineedit) finishedLineEditNoSave();
2053 if (typeid(*selection) == typeid(BranchObj))
2055 bo1= (BranchObj*) (selection);
2056 par=(BranchObj*)(bo1->getParObj());
2057 bo2=par->getFirstBranch();
2061 selection->select();
2062 ensureSelectionVisible();
2069 void MapEditor::selectLastBranch()
2071 // Finish open lineEdits
2072 if (lineedit) finishedLineEditNoSave();
2078 if (typeid(*selection) == typeid(BranchObj))
2080 bo1= (BranchObj*) (selection);
2081 par=(BranchObj*)(bo1->getParObj());
2082 bo2=par->getLastBranch();
2086 selection->select();
2087 ensureSelectionVisible();
2094 void MapEditor::setColor(QColor c)
2099 void MapEditor::selectBackgroundColor()
2101 // Finish open lineEdits
2102 if (lineedit) finishedLineEditNoSave();
2104 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2105 if ( !col.isValid() ) return;
2106 setBackgroundColor( col );
2110 void MapEditor::setBackgroundColor(QColor c)
2112 mapCanvas->setBackgroundColor (c);
2115 QColor MapEditor::pickColor()
2119 if (typeid(*selection) == typeid(BranchObj) ||
2120 typeid(*selection) == typeid(MapCenterObj))
2122 BranchObj *bo=(BranchObj*)(selection);
2123 actColor=bo->getColor();
2129 void MapEditor::colorItem()
2133 if (typeid(*selection) == typeid(BranchObj) ||
2134 typeid(*selection) == typeid(MapCenterObj))
2137 saveState(selection);
2138 BranchObj *bo=(BranchObj*)(selection);
2139 bo->setColor(actColor, false); // color links, color childs
2144 void MapEditor::colorBranch()
2148 if (typeid(*selection) == typeid(BranchObj) ||
2149 typeid(*selection) == typeid(MapCenterObj))
2152 saveState(selection);
2153 BranchObj *bo=(BranchObj*)(selection);
2154 bo->setColor(actColor, true); // color links, color childs
2160 void MapEditor::toggleStandardFlag(QString f)
2165 saveState(selection);
2166 ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2170 void MapEditor::setViewCenter()
2172 // transform to CanvasView Coord:
2173 QPoint p=worldMatrix().map(movingCenter);
2174 center ( p.x(), p.y());
2178 BranchObj* MapEditor::findText (QString s, bool cs)
2181 { // Nothing found or new find process
2183 // nothing found, start again
2185 itFind=mapCenter->first();
2187 bool searching=true;
2188 bool foundNote=false;
2189 while (searching && !EOFind)
2193 // Searching in Note
2194 if (itFind->getNote().contains(s,cs))
2196 if (selection!=itFind)
2198 if (selection) ((BranchObj*)(selection))->unselect();
2200 selection->select();
2202 ensureSelectionVisible();
2204 if (textEditor->findText(s,cs))
2210 // Searching in Heading
2211 if (searching && itFind->getHeading().contains (s,cs) )
2213 if (selection) ((BranchObj*)(selection))->unselect();
2215 selection->select();
2217 ensureSelectionVisible();
2223 itFind=itFind->next();
2224 if (!itFind) EOFind=true;
2230 return (BranchObj*)(selection);
2235 void MapEditor::findReset()
2236 { // Necessary if text to find changes during a find process
2241 void MapEditor::openURL()
2245 if (typeid(*selection) == typeid(BranchObj) ||
2246 typeid(*selection) == typeid(MapCenterObj))
2248 QString url=((BranchObj*)(selection))->getURL();
2250 QProcess *proc = new QProcess( this );
2252 #if !defined(Q_OS_MACX)
2253 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2255 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2256 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2259 proc->addArgument( url);
2261 if ( !proc->start() )
2263 if (mainWindow->settingsURL() )
2269 void MapEditor::editURL()
2271 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2272 typeid(*selection) == typeid(MapCenterObj)) )
2275 QString text = QInputDialog::getText(
2276 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2277 ((BranchObj*)(selection))->getURL(), &ok, this );
2280 // user entered something and pressed OK
2281 ((BranchObj*)(selection))->setURL (text);
2288 void MapEditor::editHeading2URL()
2290 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2291 typeid(*selection) == typeid(MapCenterObj)) )
2293 BranchObj *b=(BranchObj*)(selection);
2294 b->setURL (b->getHeading());
2300 void MapEditor::editBugzilla2URL()
2302 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2303 typeid(*selection) == typeid(MapCenterObj)) )
2305 BranchObj *b=(BranchObj*)(selection);
2306 b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
2312 void MapEditor::editVymLink()
2314 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2315 typeid(*selection) == typeid(MapCenterObj)) )
2317 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2318 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2319 fd->setCaption(tr("VYM - Link to another map"));
2320 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2321 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2325 if ( fd->exec() == QDialog::Accepted )
2326 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2328 mapCenter->reposition();
2335 void MapEditor::deleteVymLink()
2337 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2338 typeid(*selection) == typeid(MapCenterObj)) )
2340 ((BranchObj*)(selection))->setVymLink ("" );
2342 mapCenter->reposition();
2349 QString MapEditor::getVymLink()
2351 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2352 typeid(*selection) == typeid(MapCenterObj)) )
2354 return ((BranchObj*)(selection))->getVymLink();
2360 void MapEditor::removeBranchHere()
2362 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2365 saveState(selection->getParObj());
2366 QString sel=selection->getSelectString();
2367 BranchObj* bo=(BranchObj*)(selection);
2368 BranchObj* par=(BranchObj*)(bo->getParObj());
2370 par->removeBranchHere(bo);
2371 mapCenter->reposition();
2376 void MapEditor::removeChilds()
2378 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2381 saveState(selection->getParObj());
2382 ((BranchObj*)(selection))->removeChilds();
2383 mapCenter->reposition();
2387 void MapEditor::editMapInfo()
2389 ExtraInfoDialog dia;
2390 dia.setMapName (getFileName() );
2391 dia.setAuthor (mapCenter->getAuthor() );
2392 dia.setComment(mapCenter->getComment() );
2397 QCanvasItemList l=canvas()->allItems();
2398 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2400 stats+=QString ("%1 items on canvas\n").arg (i,6);
2407 bo=mapCenter->first();
2410 if (!bo->getNote().isEmpty() ) n++;
2411 f+= bo->countFloatImages();
2413 xl+=bo->countXLinks();
2416 stats+=QString ("%1 branches\n").arg (b-1,6);
2417 stats+=QString ("%1 xLinks \n").arg (xl,6);
2418 stats+=QString ("%1 notes\n").arg (n,6);
2419 stats+=QString ("%1 images\n").arg (f,6);
2420 dia.setStats (stats);
2422 // Finally show dialog
2423 if (dia.exec() == QDialog::Accepted)
2425 mapCenter->setAuthor (dia.getAuthor() );
2426 mapCenter->setComment (dia.getComment() );
2431 void MapEditor::updateActions()
2434 if (getLinkColorHint()==HeadingColor)
2435 actionFormatLinkColorHint->setOn(true);
2437 actionFormatLinkColorHint->setOn(false);
2442 actionFormatLinkStyleLine->setOn(true);
2445 actionFormatLinkStyleParabel->setOn(true);
2448 actionFormatLinkStylePolyLine->setOn(true);
2450 case StylePolyParabel:
2451 actionFormatLinkStylePolyParabel->setOn(true);
2457 QPixmap pix( 16, 16 );
2458 pix.fill( mapCanvas->backgroundColor() );
2459 actionFormatBackColor->setIconSet( pix );
2460 pix.fill( defLinkColor );
2461 actionFormatLinkColor->setIconSet( pix );
2463 actionEditUndo->setEnabled( mapChanged );
2464 actionFileSave->setEnabled( mapUnsaved );
2468 if ( (typeid(*selection) == typeid(BranchObj)) ||
2469 (typeid(*selection) == typeid(MapCenterObj)) )
2471 BranchObj *bo=(BranchObj*)(selection);
2472 // Take care of links
2473 if (bo->countXLinks()==0)
2475 branchLinksContextMenu->clear();
2476 branchLinksContextMenu->insertItem ("No xLink available");
2477 branchLinksContextMenuDup->clear();
2478 branchLinksContextMenuDup->insertItem ("No xLink available");
2484 branchLinksContextMenu->clear();
2485 branchLinksContextMenuDup->clear();
2486 for (int i=0; i<=bo->countXLinks();i++)
2488 bot=bo->XLinkTargetAt(i);
2491 s=bot->getHeading();
2494 branchLinksContextMenu->insertItem (s);
2495 branchLinksContextMenuDup->insertItem (s);
2500 standardFlagsDefault->setEnabled (true);
2502 if ( bo->getURL().isEmpty() )
2503 actionEditOpenURL->setEnabled (false);
2505 actionEditOpenURL->setEnabled (true);
2507 if ( bo->getVymLink().isEmpty() )
2509 actionEditOpenVymLink->setEnabled (false);
2510 actionEditDeleteVymLink->setEnabled (false);
2513 actionEditOpenVymLink->setEnabled (true);
2514 actionEditDeleteVymLink->setEnabled (true);
2517 actionEditCopy->setEnabled (true);
2518 actionEditCut->setEnabled (true);
2519 if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
2520 actionEditPaste->setEnabled (true);
2522 actionEditPaste->setEnabled (false);
2523 for (a=actionListBranches.first();a;a=actionListBranches.next())
2524 a->setEnabled(true);
2525 actionEditDelete->setEnabled (true);
2526 actionEditToggleFloatExport->setEnabled (false);
2527 switch (selection->getFrameType())
2530 actionFormatFrameNone->setOn(true);
2533 actionFormatFrameRectangle->setOn(true);
2539 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2541 standardFlagsDefault->setEnabled (false);
2543 actionEditOpenURL->setEnabled (false);
2544 actionEditOpenVymLink->setEnabled (false);
2545 actionEditDeleteVymLink->setEnabled (false);
2547 actionEditCopy->setEnabled (true);
2548 actionEditCut->setEnabled (true);
2549 actionEditPaste->setEnabled (false); //FIXME
2550 for (a=actionListBranches.first();a;a=actionListBranches.next())
2551 a->setEnabled(false);
2552 actionEditDelete->setEnabled (true);
2553 actionEditToggleFloatExport->setOn
2554 ( ((FloatImageObj*)(selection))->getFloatExport() );
2559 standardFlagsDefault->setEnabled (false);
2561 actionEditCopy->setEnabled (false);
2562 actionEditCut->setEnabled (false);
2563 actionEditPaste->setEnabled (false);
2564 for (a=actionListBranches.first();a;a=actionListBranches.next())
2565 a->setEnabled(false);
2567 actionEditOpenURL->setEnabled (false);
2568 actionEditOpenVymLink->setEnabled (false);
2569 actionEditDeleteVymLink->setEnabled (false);
2570 actionEditHeading2URL->setEnabled (false);
2571 actionEditDelete->setEnabled (false);
2572 actionEditToggleFloatExport->setEnabled (false);
2576 void MapEditor::setLinkStyle (LinkStyle ls)
2583 bo=mapCenter->first();
2587 bo->setLinkStyle(bo->getDefLinkStyle());
2590 mapCenter->reposition();
2593 LinkStyle MapEditor::getLinkStyle ()
2598 void MapEditor::setLinkColor(QColor c)
2604 void MapEditor::setLinkColorHint()
2606 // called from setLinkColorHint(lch) or at end of parse
2608 bo=mapCenter->first();
2616 void MapEditor::setLinkColorHint(LinkColorHint lch)
2622 void MapEditor::toggleLinkColorHint()
2624 if (linkcolorhint==HeadingColor)
2625 linkcolorhint=DefaultColor;
2627 linkcolorhint=HeadingColor;
2629 bo=mapCenter->first();
2637 LinkColorHint MapEditor::getLinkColorHint()
2639 return linkcolorhint;
2642 QColor MapEditor::getDefLinkColor()
2644 return defLinkColor;
2647 void MapEditor::setDefXLinkColor(QColor col)
2652 QColor MapEditor::getDefXLinkColor()
2654 return defXLinkColor;
2657 void MapEditor::setDefXLinkWidth (int w)
2662 int MapEditor::getDefXLinkWidth()
2664 return defXLinkWidth;
2667 void MapEditor::selectLinkColor()
2669 // Finish open lineEdits
2670 if (lineedit) finishedLineEditNoSave();
2672 QColor col = QColorDialog::getColor( defLinkColor, this );
2673 if ( !col.isValid() ) return;
2674 setLinkColor( col );
2678 void MapEditor::toggleScroll()
2680 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2682 BranchObj *bo=((BranchObj*)(selection));
2683 if (bo->countBranches()==0) return;
2684 if (bo->getDepth()==0) return;
2686 saveState(selection);
2693 void MapEditor::unScrollAll()
2696 bo=mapCenter->first();
2699 if (bo->isScrolled()) bo->toggleScroll();
2704 void MapEditor::loadFloatImage ()
2707 (typeid(*selection) == typeid(BranchObj)) ||
2708 (typeid(*selection) == typeid(MapCenterObj)) )
2710 BranchObj *bo=((BranchObj*)(selection));
2712 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2713 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2714 ImagePreview *p =new ImagePreview (fd);
2715 fd->setContentsPreviewEnabled( TRUE );
2716 fd->setContentsPreview( p, p );
2717 fd->setPreviewMode( QFileDialog::Contents );
2718 fd->setCaption(tr("vym - Load image"));
2719 fd->setDir (lastImageDir);
2723 if ( fd->exec() == QDialog::Accepted )
2726 saveState(selection);
2727 QString fn=fd->selectedFile();
2728 lastImageDir=fn.left(fn.findRev ("/"));
2729 bo->addFloatImage();
2730 // FIXME check if load was successful
2731 bo->getLastFloatImage()->load(fn);
2732 bo->getLastFloatImage()->setOriginalFilename(fn);
2733 mapCenter->reposition();
2740 void MapEditor::saveFloatImage (int item)
2743 (typeid(*selection) == typeid(FloatImageObj)) )
2745 FloatImageObj *fio=((FloatImageObj*)(selection));
2746 const char* fmt = saveImageFormatMenu->text(item);
2748 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2749 fd->addFilter ("PNG (*.png)");
2750 fd->addFilter ("BMP (*.bmp)");
2751 fd->addFilter ("XBM (*.xbm)");
2752 fd->addFilter ("JPG (*.jpg)");
2753 fd->addFilter ("XPM (*.xpm)");
2754 fd->addFilter ("GIF (*.gif)");
2755 fd->addFilter ("PNM (*.pnm)");
2756 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2757 fd->setCaption(tr("vym - Save image as ") + fmt);
2758 fd->setMode( QFileDialog::AnyFile );
2759 fd->setSelection (fio->getOriginalFilename());
2763 if ( fd->exec() == QDialog::Accepted )
2765 if (QFile (fd->selectedFile()).exists() )
2767 QMessageBox mb( "VYM",
2768 tr("The file ") + fd->selectedFile() +
2769 tr(" exists already. "
2770 "Do you want to overwrite it?"),
2771 QMessageBox::Warning,
2772 QMessageBox::Yes | QMessageBox::Default,
2773 QMessageBox::Cancel | QMessageBox::Escape,
2774 QMessageBox::QMessageBox::NoButton );
2776 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2777 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2780 case QMessageBox::Yes:
2783 case QMessageBox::Cancel:
2789 fio->save (fd->selectedFile(),fmt);
2794 void MapEditor::toggleFloatExport()
2797 (typeid(*selection) == typeid(FloatImageObj))||
2798 (typeid(*selection) == typeid(FloatObj)) )
2800 FloatImageObj *fio=((FloatImageObj*)(selection));
2801 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2805 void MapEditor::setFrame(const FrameType &t)
2808 (typeid(*selection) == typeid(BranchObj)) ||
2809 (typeid(*selection) == typeid(MapCenterObj)) )
2811 selection->setFrameType (t);
2812 mapCenter->reposition();
2813 selection->updateLink();
2817 void MapEditor::importDir(BranchObj *dst, QDir d)
2820 (typeid(*selection) == typeid(BranchObj)) ||
2821 (typeid(*selection) == typeid(MapCenterObj)) )
2825 // Traverse directories
2826 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2827 const QFileInfoList *dirlist = d.entryInfoList();
2828 QFileInfoListIterator itdir( *dirlist );
2831 while ( (fi = itdir.current()) != 0 )
2833 if (fi->fileName() != "." && fi->fileName() != ".." )
2836 bo=dst->getLastBranch();
2837 bo->setHeading (fi->fileName() );
2838 bo->setColor (QColor("blue"),false);
2840 if ( !d.cd(fi->fileName()) )
2841 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2844 // Recursively add subdirs
2852 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2853 const QFileInfoList *filelist = d.entryInfoList();
2854 QFileInfoListIterator itfile( *filelist );
2856 while ( (fi = itfile.current()) != 0 )
2859 bo=dst->getLastBranch();
2860 bo->setHeading (fi->fileName() );
2861 bo->setColor (QColor("black"),false);
2862 if (fi->fileName().right(4) == ".vym" )
2863 bo->setVymLink (fi->filePath());
2870 void MapEditor::importDir()
2873 (typeid(*selection) == typeid(BranchObj)) ||
2874 (typeid(*selection) == typeid(MapCenterObj)) )
2876 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2877 fd->setMode (QFileDialog::DirectoryOnly);
2878 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2879 fd->setCaption(tr("VYM - Choose directory structur to import"));
2883 if ( fd->exec() == QDialog::Accepted )
2885 BranchObj *bo=((BranchObj*)(selection));
2886 importDir (bo,QDir(fd->selectedFile()) );
2887 mapCenter->reposition();
2894 void MapEditor::followXLink(int i)
2897 (typeid(*selection) == typeid(BranchObj)) ||
2898 (typeid(*selection) == typeid(MapCenterObj)) )
2900 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2903 selection->unselect();
2905 selection->select();
2906 ensureSelectionVisible();
2911 void MapEditor::editXLink(int i)
2914 (typeid(*selection) == typeid(BranchObj)) ||
2915 (typeid(*selection) == typeid(MapCenterObj)) )
2917 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2920 EditXLinkDialog dia;
2922 dia.setSelection(selection);
2923 if (dia.exec() == QDialog::Accepted)
2925 if (dia.useSettingsGlobal() )
2927 setDefXLinkColor (xlo->getColor() );
2928 setDefXLinkWidth (xlo->getWidth() );
2930 if (dia.deleteXLink())
2931 ((BranchObj*)(selection))->deleteXLinkAt(i);
2938 void MapEditor::testFunction()
2940 cout << "MapEditor::testFunction() called\n";
2942 (typeid(*selection) == typeid(BranchObj)) )
2944 QString s=((BranchObj*)(selection))->getHeading();
2949 void MapEditor::ensureSelectionVisible()
2953 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2955 if (selection->getOrientation() == OrientLeftOfCenter)
2956 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2958 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2959 ensureVisible (p.x(), p.y() );
2964 void MapEditor::updateViewCenter()
2966 // Update movingCenter, so that we can zoom comfortably later
2967 QRect rc = QRect( contentsX(), contentsY(),
2968 visibleWidth(), visibleHeight() );
2969 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2970 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2971 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2974 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2976 // Lineedits are already closed by preceding
2977 // mouseEvent, we don't need to close here.
2979 QPoint p = inverseWorldMatrix().map(e->pos());
2980 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2983 { // MapObj was found
2984 if (selection != lmo)
2986 // select the MapObj
2987 if (selection) selection->unselect();
2989 selection->select();
2995 if (typeid(*selection)==typeid(BranchObj) ||
2996 typeid(*selection)==typeid(MapCenterObj) )
2998 // Context Menu on branch or mapcenter
3000 branchContextMenu->popup(e->globalPos() );
3002 if (typeid(*selection)==typeid(FloatImageObj))
3004 // Context Menu on floatimage
3006 floatimageContextMenu->popup(e->globalPos() );
3010 { // No MapObj found, we are on the Canvas itself
3011 // Context Menu on Canvas
3013 canvasContextMenu->popup(e->globalPos() );
3017 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3019 // Finish open lineEdits
3020 if (lineedit) finishedLineEditNoSave();
3022 QPoint p = inverseWorldMatrix().map(e->pos());
3023 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3025 // Special case: CTRL is pressed
3026 if (e->state() & QMouseEvent::ControlButton)
3028 if (actionModModeColor->isOn())
3030 if (e->state() & QMouseEvent::ControlButton)
3033 setCursor (pickColorCursor);
3037 if (actionModModeLink->isOn())
3039 BranchObj *bo_begin=NULL;
3041 bo_begin=(BranchObj*)(lmo);
3044 ((typeid(*selection) == typeid(BranchObj)) ||
3045 (typeid(*selection) == typeid(MapCenterObj))) )
3046 bo_begin=(BranchObj*)(selection);
3050 linkingObj_src=bo_begin;
3051 tmpXLink=new XLinkObj (mapCanvas);
3052 tmpXLink->setBegin (bo_begin);
3053 tmpXLink->setEnd (p);
3054 tmpXLink->setColor(defXLinkColor);
3055 tmpXLink->setWidth(defXLinkWidth);
3056 tmpXLink->updateXLink();
3057 tmpXLink->setVisibility (true);
3064 { // MapObj was found
3065 if (selection != lmo)
3067 // select the MapObj
3068 if (selection) selection->unselect();
3070 selection->select();
3075 // Check, if systemFlag clicked
3076 if (typeid(*selection)==typeid(BranchObj) ||
3077 typeid(*selection)==typeid(MapCenterObj) )
3079 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
3080 if (!foname.isEmpty())
3082 // Do not move, if systemFlag clicked
3086 if (foname=="vymLink")
3088 mainWindow->editOpenVymLink();
3089 // tabWidget may change, better return now
3090 // before segfaulting...
3094 mainWindow->windowToggleNoteEditor();
3098 // Left Button Move Branches
3099 if (e->button() == QMouseEvent::LeftButton )
3101 movingObj_start.setX( p.x() - selection->x() );
3102 movingObj_start.setY( p.y() - selection->y() );
3103 movingObj_orgPos.setX (lmo->x() );
3104 movingObj_orgPos.setY (lmo->y() );
3106 // If modMode==copy, then we want to "move" the _new_ object around
3107 // then we need the offset from p to the _old_ selection, because of tmp
3108 if (actionModModeCopy->isOn() &&
3109 e->state() & QMouseEvent::ControlButton)
3111 if (typeid(*selection)==typeid(BranchObj) )
3114 mapCenter->addBranch ((BranchObj*)(selection));
3116 selection=mapCenter->getLastBranch();
3117 selection->select();
3118 mapCenter->reposition();
3121 movingObj=selection;
3123 // Middle Button Toggle Scroll
3124 // (On Mac OS X this won't work, but we still have
3125 // a button in the toolbar)
3126 if (e->button() == QMouseEvent::MidButton )
3130 { // No MapObj found, we are on the Canvas itself
3131 // Left Button move Pos of CanvasView
3132 if (e->button() == QMouseEvent::LeftButton )
3134 movingObj=NULL; // move Content not Obj
3135 movingObj_start=e->globalPos();
3136 movingCont_start=QPoint (contentsX(), contentsY() );
3137 movingVec=QPoint(0,0);
3138 setCursor(handOpenCursor);
3143 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3145 QPoint p = inverseWorldMatrix().map(e->pos());
3147 // Move the selected MapObj
3148 if ( selection && movingObj)
3150 ensureVisible (p.x(),p.y());
3152 // Now move the selection, but add relative position
3153 // (movingObj_start) where selection was chosen with
3154 // mousepointer. (This avoids flickering resp. jumping
3155 // of selection back to absPos)
3157 LinkableMapObj *lmosel;
3158 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3160 // Check if we could link
3161 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3164 if (typeid(*selection) == typeid(FloatImageObj))
3167 saveState("move "+qpointToString(movingObj_orgPos));
3168 FloatObj *fo=(FloatObj*)(selection);
3169 if (fo->getLinkStyle()==StyleUndef)
3171 fo->setLinkStyle(fo->getDefLinkStyle());
3172 fo->setLinkColor(fo->getParObj()->getLinkColor());
3174 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3178 // Relink float to new mapcenter or branch, if shift is pressed
3179 // Only relink, if selection really has a new parent
3180 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3181 ( (typeid(*lmo)==typeid(BranchObj)) ||
3182 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3183 ( lmo != fo->getParObj())
3186 if (typeid(*fo) == typeid(FloatImageObj))
3188 FloatImageObj *fio=(FloatImageObj*)(fo);
3189 ((BranchObj*)(lmo))->addFloatImage (fio);
3191 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3192 fio=((BranchObj*)(lmo))->getLastFloatImage();
3195 selection=(LinkableMapObj*)(fio);
3196 selection->select();
3197 movingObj=(MapObj*)(fio);
3198 // setLinkStyle calls updateLink, only set it once
3199 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3200 fio->setLinkStyle (fio->getDefLinkStyle());
3202 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3204 } else // selection != a FloatObj
3206 if (lmosel->getDepth()==0)
3208 if (e->state() == (LeftButton | !ShiftButton))
3209 // If mapCenter is moved, move all the rest by default, too.
3210 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3212 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3215 if (lmosel->getDepth()==1)
3217 // depth==1, mainbranch
3219 saveState("move "+qpointToString(movingObj_orgPos));
3220 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3224 if (lmosel->getOrientation() == OrientLeftOfCenter)
3225 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3226 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3227 p.y()-movingObj_start.y() );
3229 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3231 // reposition subbranch
3232 lmosel->reposition();
3233 //ensureSelectionVisible();
3235 if (lmo && (lmo!=selection) &&
3236 (typeid(*lmo) == typeid(BranchObj) ||
3237 (typeid(*lmo) == typeid(MapCenterObj) )
3240 if (e->state() & QMouseEvent::ControlButton)
3242 // Special case: CTRL to link below lmo
3243 lmosel->setParObjTmp (lmo,p,+1);
3245 else if (e->state() & QMouseEvent::ShiftButton)
3246 lmosel->setParObjTmp (lmo,p,-1);
3248 lmosel->setParObjTmp (lmo,p,0);
3251 lmosel->unsetParObjTmp();
3253 if (lmo &&(lmo==selection))
3254 // Could link to myself (happens sometimes...)
3255 lmosel->unsetParObjTmp();
3257 // no Obj under selection, go back to original Parent
3258 lmosel->unsetParObjTmp();
3263 } // no FloatImageObj
3267 } // selection && moving_obj
3269 // Draw a link from one branch to another
3272 tmpXLink->setEnd (p);
3273 tmpXLink->updateXLink();
3277 if (!movingObj && !pickingColor &&!drawingLink)
3279 QPoint p=e->globalPos();
3280 movingVec.setX(-p.x() + movingObj_start.x() );
3281 movingVec.setY(-p.y() + movingObj_start.y() );
3282 setContentsPos( movingCont_start.x() + movingVec.x(),
3283 movingCont_start.y() + movingVec.y());
3290 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3292 LinkableMapObj *dst;
3293 // Have we been picking color?
3297 setCursor (ArrowCursor);
3298 // Check if we are over another branch
3299 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3300 if (dst && selection)
3302 if (e->state() & QMouseEvent::ShiftButton)
3304 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3305 ((BranchObj*)(selection))->setLinkColor ();
3309 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3310 ((BranchObj*)(selection))->setLinkColor ();
3316 // Have we been drawing a link?
3320 // Check if we are over another branch
3321 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3322 if (dst && selection)
3324 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3325 tmpXLink->updateXLink();
3326 tmpXLink->activate();
3337 // Have we been moving something?
3338 if ( selection && movingObj )
3340 // Check if we are over another branch, but ignore
3341 // any found LMOs, which are FloatObjs
3342 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3343 ((LinkableMapObj*)(selection)) );
3346 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3351 // Now check, if we have been moving a branch
3352 if (typeid(*selection) == typeid(BranchObj) )
3354 // save the position in case we link to mapcenter
3355 QPoint savePos=QPoint (selection->x(),selection->y() );
3357 // Reset the temporary drawn link to the original one
3358 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3364 BranchObj* bs=((BranchObj*)(selection));
3366 saveState ("linkBranchToPos (\""+
3367 (bs->getParObj())->getSelectString()+
3369 QString("%1").arg(bs->getNum())+
3371 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3373 // TODO we also could check, if dest and src are on same branch,
3374 // then it would be sufficient to saveState of this branch
3376 // Modifiers allow to insert above/below dst
3377 if (e->state() & QMouseEvent::ShiftButton)
3379 bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum());
3381 if (e->state() & QMouseEvent::ControlButton)
3383 bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum()+1);
3386 bs->moveBranchTo ((BranchObj*)(dst),-1);
3387 if (dst->getDepth()==0)
3391 // Draw the original link, before selection was moved around
3392 mapCenter->reposition();
3394 // Finally resize canvas, if needed
3399 // maybe we moved View: set old cursor
3400 setCursor (ArrowCursor);
3404 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3406 // Finish open lineEdits
3407 if (lineedit) finishedLineEditNoSave();
3409 if (e->button() == QMouseEvent::LeftButton )
3411 QPoint p = inverseWorldMatrix().map(e->pos());
3412 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3413 if (lmo) { // MapObj was found
3414 // First select the MapObj than edit heading
3415 if (selection) selection->unselect();
3417 selection->select();
3419 saveState(selection);
3425 void MapEditor::resizeEvent (QResizeEvent* e)
3427 QCanvasView::resizeEvent( e );
3430 if (!fileName.isEmpty()) s=fileName;
3434 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3437 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3438 // cerr << event->format(i) << endl;
3441 (typeid(*selection) == typeid(BranchObj)) ||
3442 (typeid(*selection) == typeid(MapCenterObj))) {
3444 // If QImageDrag can decode mime type
3445 if (QImageDrag::canDecode(event)) {
3450 // If image are dragged from firefox
3451 if (event->provides("application/x-moz-file-promise-url") &&
3452 event->provides("application/x-moz-nativeimage")) {
3453 event->accept(true);
3457 // If QUriDrag can decode mime type
3458 if (QUriDrag::canDecode(event)) {
3463 // If Uri are dragged from firefox
3464 if (event->provides("_NETSCAPE_URL")){
3469 // If QTextDrag can decode mime type
3470 if (QTextDrag::canDecode(event)) {
3479 bool isUnicode16(const QByteArray &d)
3481 // FIXME: make more precise check for unicode 16.
3482 // Guess unicode16 if any of second bytes are zero
3483 unsigned int length = max(0,d.size()-2)/2;
3484 for (unsigned int i = 0; i<length ; i++)
3485 if (d.at(i*2+1)==0) return true;
3489 void MapEditor::contentsDropEvent(QDropEvent *event)
3492 (typeid(*selection) == typeid(BranchObj)) ||
3493 (typeid(*selection) == typeid(MapCenterObj)))
3498 if (event->provides("image/png"))
3501 if (QImageDrag::decode(event, pix))
3509 } else if (event->provides("application/x-moz-file-promise-url") &&
3510 event->provides("application/x-moz-nativeimage"))
3512 // Contains url to the img src in unicode16
3513 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3514 QString url = QString((const QChar*)d.data(),d.size()/2);
3518 } else if (event->provides ("text/uri-list"))
3519 { // Uris provided e.g. by konqueror
3520 QUriDrag::decode (event,uris);
3521 } else if (event->provides ("_NETSCAPE_URL"))
3522 { // Uris provided by Mozilla
3523 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3526 } else if (event->provides("text/html")) {
3528 // Handels text mime types
3529 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3530 QByteArray d = event->encodedData("text/html");
3533 text = QString((const QChar*)d.data(),d.size()/2);
3537 textEditor->setText(text);
3541 } else if (event->provides("text/plain")) {
3542 QByteArray d = event->encodedData("text/plain");
3545 text = QString((const QChar*)d.data(),d.size()/2);
3549 textEditor->setText(text);
3561 for (const char* u=uris.first(); u; u=uris.next())
3563 bo=((BranchObj*)(selection))->addBranch();
3566 s=QUriDrag::uriToLocalFile(u);
3568 QString file = QDir::convertSeparators(s);
3569 heading = QFileInfo(file).baseName();
3571 if (file.endsWith(".vym", false))
3572 bo->setVymLink(file);
3581 bo->setHeading(heading);
3592 mapCenter->reposition();
3599 void MapEditor::addFloatImage(const QPixmap &img)
3602 (typeid(*selection) == typeid(BranchObj)) ||
3603 (typeid(*selection) == typeid(MapCenterObj)) )
3605 BranchObj *bo=((BranchObj*)(selection));
3607 saveState(selection);
3608 //QString fn=fd->selectedFile();
3609 //lastImageDir=fn.left(fn.findRev ("/"));
3610 bo->addFloatImage();
3611 // FIXME check if load was successful
3612 bo->getLastFloatImage()->load(img);
3613 //bo->getLastFloatImage()->setOriginalFilename(fn);
3614 mapCenter->reposition();
3621 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3623 if (!imageBuffer) imageBuffer = new QBuffer();
3624 if (!imageBuffer->isOpen()) {
3625 imageBuffer->open(IO_WriteOnly | IO_Append);
3627 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3631 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3633 if (nop->state()==QNetworkProtocol::StDone) {
3634 QPixmap img(imageBuffer->buffer());
3639 imageBuffer->close();
3641 imageBuffer->close();
3648 void MapEditor::fetchImage(const QString &url)
3651 urlOperator->stop();
3652 disconnect(urlOperator);
3656 urlOperator = new QUrlOperator(url);
3657 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3658 this, SLOT(imageDataFinished(QNetworkOperation*)));
3660 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3661 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));