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 LinkableMapObj *undoSel;
595 saveState (UndoCommand,undoSel,c);
598 void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom)
602 // Save what is selected now
604 undoSelection=undoSel->getSelectString();
608 // Save depending on how much needs to be saved
609 if (savemode==UndoCommand)
614 else if (savemode==PartOfMap && undoSel)
616 undoCommand="undoPart (\""+undoSelection+"\")";
617 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
620 undoCommand="undoMap ()";
621 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
624 cout << "ME::saveState()\n";
625 cout << " undoCom="<<undoCommand<<endl;
629 void MapEditor::parseAtom(const QString &atom)
636 // Split string s into command and parameters
637 api.parseCommand (atom);
638 QString com=api.command();
641 if (com==QString("moveBranchUp"))
643 else if (com=="moveBranchDown")
645 else if (com=="move")
647 if (api.checkParamCount(2) &&
658 else if (com=="linkBranchToPos")
660 if (selection && typeid(*selection) == typeid(BranchObj) )
662 if (api.checkParamCount(4))
664 s=api.parString(ok,0);
665 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
668 if (typeid(*dst) == typeid(BranchObj) )
669 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
670 if (typeid(*dst) == typeid(MapCenterObj) )
672 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
677 if (ok) ((BranchObj*)(selection))->move (x,y);
683 } else if (com=="setHeading")
685 if (api.checkParamCount(1))
687 s=api.parString (ok,0);
688 if (ok) setHeading (s);
691 // Internal commands, used for undo etc.
692 else if (com==QString("undoMap"))
694 else if (com==QString("undoPart"))
696 if (api.checkParamCount(1))
698 s=api.parString (ok,0);
701 } else if (com=="select")
702 if (api.checkParamCount(1))
704 s=api.parString(ok,0);
708 api.setError ("Unknown command in: "+atom);
713 cout << "MapEditor::parseAtom: Error!\n";
714 cout << " "<<api.errorDesc()<<endl;
719 void MapEditor::finishedLineEditNoSave()
721 // This is called by finishedLineEdit or any MapEditor method,
722 // which wants to assure, that lineedits finish, before e.g. a branch is
725 // After calling LineEdit and using the clipboard, the
726 // focus is not any longer on the main widget, we
727 // have to restore it using parentWidget()->setFocus()
731 editingBO->setHeading(lineedit->text() );
733 lineedit->releaseKeyboard();
735 parentWidget()->setFocus();
736 mapCenter->reposition();
738 ensureSelectionVisible();
743 bool MapEditor::isDefault()
748 bool MapEditor::isUnsaved()
753 bool MapEditor::hasChanged()
758 void MapEditor::setChanged()
763 actionEditUndo->setEnabled (true);
764 actionFileSave->setEnabled (true);
768 void MapEditor::closeMap()
770 // Finish open lineEdits
771 if (lineedit) finishedLineEditNoSave();
773 // Unselect before disabling the toolbar actions
774 if (selection) selection->unselect();
782 void MapEditor::setFilePath(QString fname)
784 setFilePath (fname,fname);
787 void MapEditor::setFilePath(QString fname, QString destname)
796 filePath=fname; // becomes absolute path
797 fileName=fname; // gets stripped of path
798 destPath=destname; // needed for vymlinks
800 // If fname is not an absolute path, complete it
801 filePath=QDir(fname).absPath();
802 fileDir=filePath.left (1+filePath.findRev ("/"));
804 // Set short name, too. Search from behind:
805 int i=fileName.findRev("/");
806 if (i>=0) fileName=fileName.remove (0,i+1);
808 // Forget the .vym (or .xml) for name of map
809 mapName=fileName.left(fileName.findRev(".",-1,true) );
813 QString MapEditor::getFilePath()
818 QString MapEditor::getFileName()
823 QString MapEditor::getMapName()
828 QString MapEditor::getDestPath()
833 int MapEditor::load (QString &fname, const LoadMode &lmode)
835 // Finish open lineEdits
836 if (lineedit) finishedLineEditNoSave();
842 if (selection) selection->unselect();
845 mapCenter->setMapEditor(this);
846 // (map state is set later at end of load...)
849 saveState(selection);
853 mapBuilderHandler handler;
856 // I am paranoid: file should exist anyway
857 // according to check in mainwindow.
860 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
861 tr("Couldn't open map " +fname)+".");
865 blockreposition=true;
866 QXmlInputSource source( file);
867 QXmlSimpleReader reader;
868 reader.setContentHandler( &handler );
869 reader.setErrorHandler( &handler );
870 handler.setMapEditor( this );
871 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
872 handler.setLoadMode (lmode);
873 bool ok = reader.parse( source );
874 blockreposition=false;
878 mapCenter->reposition();
888 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
889 tr( handler.errorProtocol() ) );
891 // Still return "success": the map maybe at least
892 // partially read by the parser
899 int MapEditor::save (const SaveMode &savemode)
901 // Finish open lineEdits
902 if (lineedit) finishedLineEditNoSave();
906 // The SaveMode UndoCommand is not supported here
907 if (savemode==UndoCommand) return 1;
909 // Create mapName and fileDir
910 makeSubDirs (fileDir);
914 fname=mapName+".xml";
916 // use name given by user, even if he chooses .doc
920 // Check if fname is writeable
921 QFile file( fileDir+fname);
922 if (!file.open( IO_WriteOnly ) )
924 QMessageBox::critical( 0, tr( "Critical Save Error" ),
925 tr("Couldn't write to ") +fileDir+fname);
931 if (savemode==CompleteMap || selection==NULL)
932 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
934 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
936 file.setName ( fileDir + fname);
937 if ( !file.open( IO_WriteOnly ) )
939 // This should neverever happen
940 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
944 // Write it finally, and write in UTF8, no matter what
945 QTextStream ts( &file );
946 ts.setEncoding (QTextStream::UnicodeUTF8);
954 actionFileSave->setEnabled(false);
960 void MapEditor::setZipped (bool z)
965 bool MapEditor::saveZipped ()
970 void MapEditor::print()
972 // Finish open lineEdits
973 if (lineedit) finishedLineEditNoSave();
977 printer = new QPrinter;
978 printer->setColorMode (QPrinter::Color);
979 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
982 QRect totalBBox=mapCenter->getTotalBBox();
984 // Try to set orientation automagically
985 // Note: Interpretation of generated postscript is amibiguous, if
986 // there are problems with landscape mode, see
987 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
989 if (totalBBox.width()>totalBBox.height())
990 // recommend landscape
991 printer->setOrientation (QPrinter::Landscape);
993 // recommend portrait
994 printer->setOrientation (QPrinter::Portrait);
996 if ( printer->setup(this) )
997 // returns false, if printing is canceled
999 QPainter pp(printer);
1001 // Don't print the visualisation of selection
1002 LinkableMapObj *oldselection=NULL;
1005 oldselection=selection;
1006 selection->unselect();
1009 // Handle sizes of map and paper:
1011 // setWindow defines which part of the canvas will be transformed
1012 // setViewport defines area on paper in device coordinates (dpi)
1013 // e.g. (0,50,700,700) is upper part on A4
1014 // see also /usr/lib/qt3/doc/html/coordsys.html
1016 QPaintDeviceMetrics metrics (printer);
1018 double paperAspect = (double)metrics.width() / (double)metrics.height();
1019 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1021 QRect mapRect=totalBBox;
1022 QCanvasRectangle *frame=NULL;
1023 QCanvasText *footerFN=NULL;
1024 QCanvasText *footerDate=NULL;
1025 if (printFrame || printFooter)
1030 // Print frame around map
1031 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1032 totalBBox.width()+20, totalBBox.height()+20);
1033 frame=new QCanvasRectangle (mapRect,mapCanvas);
1034 frame->setBrush (QColor(white));
1035 frame->setPen (QColor(black));
1040 QCanvasLine *l=new QCanvasLine (mapCanvas);
1041 l->setPoints (0,0,mapRect.width(),mapRect.height());
1042 l->setPen (QPen(QColor(black), 1));
1049 // Print footer below map
1051 font.setPointSize(10);
1052 footerFN=new QCanvasText (mapCanvas);
1053 footerFN->setText ("VYM - " + fileName);
1054 footerFN->setFont(font);
1055 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1056 footerFN->setZ(Z_TEXT);
1058 footerDate=new QCanvasText (mapCanvas);
1059 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1060 footerDate->setFont(font);
1061 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1062 footerDate->setZ(Z_TEXT);
1065 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1068 pp.setWindow (mapRect);
1071 if (mapAspect>=paperAspect)
1073 // Fit horizontally to paper width
1074 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1077 // Fit vertically to paper height
1078 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1081 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1083 // Delete Frame and footer
1087 delete (footerDate);
1089 if (frame) delete (frame);
1091 // Restore selection
1094 selection=oldselection;
1095 selection->select();
1098 // Save settings in vymrc
1099 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1103 QPixmap MapEditor::getPixmap()
1105 QRect mapRect=mapCenter->getTotalBBox();
1106 QPixmap pix (mapRect.size());
1109 // Don't print the visualisation of selection
1110 LinkableMapObj *oldselection=NULL;
1113 oldselection=selection;
1114 selection->unselect();
1117 pp.setWindow (mapRect);
1119 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1122 // Restore selection
1125 selection=oldselection;
1126 selection->select();
1132 void MapEditor::exportImage(QString fn)
1134 // Finish open lineEdits
1135 if (lineedit) finishedLineEditNoSave();
1137 QPixmap pix (getPixmap());
1138 pix.save(fn, "PNG");
1141 void MapEditor::exportImage(QString fn, int item)
1143 // Finish open lineEdits
1144 if (lineedit) finishedLineEditNoSave();
1146 QPixmap pix (getPixmap());
1147 pix.save(fn, exportImageFormatMenu->text(item) );
1150 void MapEditor::exportASCII()
1152 // FIXME still experimental
1154 ex.setMapCenter(mapCenter);
1156 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
1157 fd->addFilter ("TXT (*.txt)");
1158 fd->setCaption("VYM - Export (ASCII) (still experimental)");
1159 fd->setMode( QFileDialog::AnyFile );
1162 if ( fd->exec() == QDialog::Accepted )
1164 if (QFile (fd->selectedFile()).exists() )
1166 QMessageBox mb( "VYM",
1167 tr("The file ") + fd->selectedFile() +
1168 tr(" exists already. Do you want to overwrite it?"),
1169 QMessageBox::Warning,
1170 QMessageBox::Yes | QMessageBox::Default,
1171 QMessageBox::Cancel | QMessageBox::Escape,
1172 QMessageBox::NoButton );
1174 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1175 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1179 case QMessageBox::Yes:
1182 case QMessageBox::Cancel:
1183 // return, do nothing
1188 ex.setPath (fd->selectedFile() );
1194 void MapEditor::exportXML(const QString &dir)
1196 // Create subdirectories
1199 // write to directory
1200 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1203 file.setName ( dir + "/"+mapName+".xml");
1204 if ( !file.open( IO_WriteOnly ) )
1206 // This should neverever happen
1207 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1211 // Write it finally, and write in UTF8, no matter what
1212 QTextStream ts( &file );
1213 ts.setEncoding (QTextStream::UnicodeUTF8);
1217 // Now write image, too
1218 exportImage (dir+"/images/"+mapName+".png");
1221 void MapEditor::clear()
1225 selection->unselect();
1232 void MapEditor::copy()
1234 // Finish open lineEdits
1235 if (lineedit) finishedLineEditNoSave();
1239 if (typeid(*selection) == typeid(BranchObj) )
1243 clipboardME->clear();
1244 clipboardME->getMapCenter()->addBranch();
1245 to=clipboardME->getMapCenter()->getLastBranch();
1248 from=(BranchObj*)(selection);
1251 // keep position relative to parent
1252 to->move2RelPos ( from->getRelPos());
1254 // select data in clipboard
1255 clipboardME->select ("bo:0");
1257 // repositioning makes testing nicer,
1258 // but is not needed usually:
1259 if (clipboardME->isVisible())
1261 clipboardME->getMapCenter()->reposition();
1264 clipboardME->hide();
1267 if (typeid(*selection) == typeid(FloatImageObj) )
1270 FloatImageObj* from;
1271 clipboardME->clear();
1272 clipboardME->getMapCenter()->addFloatImage();
1273 to=clipboardME->getMapCenter()->getLastFloatImage();
1276 from=(FloatImageObj*)(selection);
1279 // select data in clipboard
1280 clipboardME->select ("fi:0");
1282 // repositioning makes testing nicer,
1283 // but is not needed usually:
1284 if (clipboardME->isVisible())
1286 clipboardME->getMapCenter()->reposition();
1289 clipboardME->hide();
1295 void MapEditor::undo()
1297 // Finish open lineEdits
1298 if (lineedit) finishedLineEditNoSave();
1300 // select object before undo
1301 if (!undoSelection.isEmpty())
1302 select (undoSelection);
1304 parseAtom (undoCommand);
1305 mapCenter->reposition();
1307 // Undo not longer available now
1308 actionEditUndo->setEnabled (false);
1313 void MapEditor::undoXML(const QString &undoSel)
1316 d.setPath(bakMapDir);
1319 // We need to parse saved XML data
1320 mapBuilderHandler handler;
1321 QXmlInputSource source;
1322 source.setData(backupXML);
1323 QXmlSimpleReader reader;
1324 reader.setContentHandler( &handler );
1325 reader.setErrorHandler( &handler );
1326 handler.setMapEditor( this );
1327 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1328 if (undoSel.isEmpty())
1331 handler.setLoadMode (NewMap);
1335 handler.setLoadMode (ImportReplace);
1337 blockreposition=true;
1338 bool ok = reader.parse( source );
1339 blockreposition=false;
1342 // This should never ever happen
1343 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1344 tr( handler.errorProtocol() )+" in "+backupXML );
1348 QMessageBox::critical( 0, tr( "Critical Error" ),
1349 "Temporary directory " +bakMapDir +
1350 tr (" used for undo is gone. \n"
1351 "I will create a new one, but at the moment no undo is available.\n"
1352 "Maybe you want to reload your original data.\n\n"
1353 "Sorry for any inconveniences.") );
1358 LinkableMapObj* MapEditor::pasteNoSave()
1360 // Finish open lineEdits
1361 if (lineedit) finishedLineEditNoSave();
1363 LinkableMapObj *fromLMO=clipboardME->getSelection();
1364 LinkableMapObj *returnLMO=NULL;
1366 if (selection && fromLMO)
1368 if (typeid(*fromLMO) == typeid(BranchObj) )
1370 if (typeid(*selection) == typeid(MapCenterObj))
1372 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1373 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1375 if (typeid(*selection) == typeid(BranchObj))
1376 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1379 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1380 (typeid(*selection) == typeid (BranchObj) ||
1381 typeid(*selection)==typeid(MapCenterObj)) )
1382 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1388 void MapEditor::cutNoSave()
1390 // Finish open lineEdits
1391 if (lineedit) finishedLineEditNoSave();
1395 if (selection != NULL) {
1396 if (typeid(*selection) == typeid(BranchObj) )
1398 bo=(BranchObj*)(selection);
1399 par=(BranchObj*)(bo->getParObj());
1402 par->removeBranch(bo);
1404 selection->select();
1406 if (typeid(*selection) == typeid(FloatImageObj) )
1408 FloatImageObj* fio=(FloatImageObj*)(selection);
1409 par=(BranchObj*)(fio->getParObj());
1412 par->removeFloatImage(fio);
1414 selection->select();
1419 void MapEditor::paste()
1421 saveState(selection);
1423 mapCenter->reposition();
1427 void MapEditor::cut()
1429 saveState(selection->getParObj());
1432 mapCenter->reposition();
1436 void MapEditor::move(const int &x, const int &y)
1438 // FIXME no saveState, because this is only internal at undo so far
1439 if (selection) selection->move(x,y);
1440 if (typeid(*selection) == typeid(FloatImageObj))
1441 ((FloatImageObj*)(selection))->setRelPos();
1444 void MapEditor::moveBranchUp()
1446 // Finish open lineEdits
1447 if (lineedit) finishedLineEditNoSave();
1451 if (typeid(*selection) == typeid(BranchObj) )
1453 saveState("moveBranchDown ()");
1454 bo=(BranchObj*)(selection);
1455 par=(BranchObj*)(bo->getParObj());
1456 selection->unselect();
1457 selection=par->moveBranchUp (bo);
1458 selection->select();
1459 mapCenter->reposition();
1460 ensureSelectionVisible();
1464 void MapEditor::moveBranchDown()
1466 // Finish open lineEdits
1467 if (lineedit) finishedLineEditNoSave();
1471 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) ) )
1493 saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")");
1495 ensureSelectionVisible();
1496 editingBO=(BranchObj*)(selection);
1497 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1498 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1499 QString s=editingBO->getHeading();
1500 lineedit->setText(s);
1501 lineedit->setCursorPosition(1);
1502 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1503 lineedit->selectAll();
1506 lineedit->grabKeyboard();
1507 lineedit->setFocus();
1511 void MapEditor::setHeading(const QString &s)
1513 // Internal function, no saveState needed
1515 (typeid(*selection) == typeid(BranchObj) ||
1516 typeid(*selection) == typeid(MapCenterObj) ) )
1518 ((BranchObj*)(selection))->setHeading(s);
1519 mapCenter->reposition();
1521 ensureSelectionVisible();
1525 void MapEditor::addNewBranch(int pos)
1527 // Finish open lineEdits
1528 if (lineedit) finishedLineEditNoSave();
1531 (typeid(*selection) == typeid(BranchObj) ||
1532 typeid(*selection) == typeid(MapCenterObj) ) )
1534 saveState(selection);
1536 BranchObj* bo1 = (BranchObj*) (selection);
1537 bool wasScrolled=false;
1538 BranchObj *newbo=NULL;
1541 // save scroll state. If scrolled, automatically select
1542 // new branch in order to tmp unscroll parent...
1543 wasScrolled=bo1->isScrolled();
1544 newbo=bo1->addBranch();
1547 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1551 // add above selection
1552 newbo=parbo->insertBranch(bo1->getNum());
1554 // add below selection
1555 newbo=parbo->insertBranch(bo1->getNum()+1);
1557 // This should not happen...
1562 LinkableMapObj *oldselection=selection;
1564 mapCenter->reposition();
1566 if (actionSettingsAutoedit->isOn() ||
1567 actionSettingsAutoselectHeading->isOn() )
1569 selection->unselect();
1571 selection->select();
1572 if (actionSettingsPasteNewHeading->isOn() )
1574 BranchObj *bo2= (BranchObj*)(selection);
1575 bo2->setHeading("");
1577 if (actionSettingsAutoedit->isOn() )
1579 if (!actionSettingsAutoselectHeading->isOn()
1582 selection->unselect();
1583 selection=oldselection;
1584 selection->select();
1591 void MapEditor::addNewBranchHere()
1593 // Finish open lineEdits
1594 if (lineedit) finishedLineEditNoSave();
1597 (typeid(*selection) == typeid(BranchObj) ) )
1599 saveState(selection);
1601 BranchObj* bo1 = (BranchObj*) (selection);
1602 bool wasScrolled=false;
1603 BranchObj *newbo=NULL;
1604 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1607 // add below selection
1608 newbo=parbo->insertBranch(bo1->getNum()+1);
1611 LinkableMapObj *oldselection=selection;
1612 ((BranchObj*)(selection))->moveBranchTo (newbo,-1);
1614 mapCenter->reposition();
1616 if (actionSettingsAutoedit->isOn() ||
1617 actionSettingsAutoselectHeading->isOn() )
1619 selection->unselect();
1621 selection->select();
1622 if (actionSettingsPasteNewHeading->isOn() )
1624 BranchObj *bo2= (BranchObj*)(selection);
1625 bo2->setHeading("");
1627 if (actionSettingsAutoedit->isOn() )
1629 if (!actionSettingsAutoselectHeading->isOn()
1632 selection->unselect();
1633 selection=oldselection;
1634 selection->select();
1640 void MapEditor::deleteSelection()
1642 // Finish open lineEdits
1643 if (lineedit) finishedLineEditNoSave();
1645 if (selection && typeid(*selection) ==typeid(BranchObj) )
1647 saveState(selection->getParObj());
1648 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1649 BranchObj* par=(BranchObj*)(bo->getParObj());
1652 par->removeBranch(bo);
1654 selection->select();
1655 ensureSelectionVisible();
1656 mapCenter->reposition();
1659 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1661 saveState(selection->getParObj());
1662 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1663 BranchObj* par=(BranchObj*)(fio->getParObj());
1666 par->removeFloatImage(fio);
1668 selection->select();
1669 ensureSelectionVisible();
1670 mapCenter->reposition();
1675 LinkableMapObj* MapEditor::getSelection()
1680 bool MapEditor::select (const QString &s)
1682 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1684 // Finally select the found object
1687 if (selection) unselect();
1689 selection->select();
1691 ensureSelectionVisible();
1697 void MapEditor::unselect()
1701 selectionLast=selection;
1702 selection->unselect();
1707 void MapEditor::reselect()
1711 selection=selectionLast;
1712 selection->select();
1717 void MapEditor::selectNextBranch()
1719 // Increase number of branch
1722 QString s=selection->getSelectString();
1728 part=s.section(",",-1);
1730 num=part.right(part.length() - 3);
1732 s=s.left (s.length() -num.length());
1735 num=QString ("%1").arg(num.toUInt()+1);
1739 // Try to select this one
1740 if (select (s)) return;
1742 // We have no direct successor,
1743 // try to increase the parental number in order to
1744 // find a successor with same depth
1746 int d=selection->getDepth();
1751 while (!found && d>0)
1753 s=s.section (",",0,d-1);
1754 // replace substring of current depth in s with "1"
1755 part=s.section(",",-1);
1757 num=part.right(part.length() - 3);
1761 // increase number of parent
1762 num=QString ("%1").arg(num.toUInt()+1);
1763 s=s.section (",",0,d-2) + ","+ typ+num;
1766 // Special case, look at orientation
1767 if (selection->getOrientation()==OrientRightOfCenter)
1768 num=QString ("%1").arg(num.toUInt()+1);
1770 num=QString ("%1").arg(num.toUInt()-1);
1775 // pad to oldDepth, select the first branch for each depth
1776 for (i=d;i<oldDepth;i++)
1781 if ( ((BranchObj*)(selection))->countBranches()>0)
1789 // try to select the freshly built string
1797 void MapEditor::selectPrevBranch()
1799 // Decrease number of branch
1802 QString s=selection->getSelectString();
1808 part=s.section(",",-1);
1810 num=part.right(part.length() - 3);
1812 s=s.left (s.length() -num.length());
1815 num=QString ("%1").arg(num.toUInt()-1);
1819 // Try to select this one
1820 if (select (s)) return;
1822 // We have no direct precessor,
1823 // try to decrease the parental number in order to
1824 // find a precessor with same depth
1826 int d=selection->getDepth();
1831 while (!found && d>0)
1833 s=s.section (",",0,d-1);
1834 // replace substring of current depth in s with "1"
1835 part=s.section(",",-1);
1837 num=part.right(part.length() - 3);
1841 // decrease number of parent
1842 num=QString ("%1").arg(num.toUInt()-1);
1843 s=s.section (",",0,d-2) + ","+ typ+num;
1846 // Special case, look at orientation
1847 if (selection->getOrientation()==OrientRightOfCenter)
1848 num=QString ("%1").arg(num.toUInt()-1);
1850 num=QString ("%1").arg(num.toUInt()+1);
1855 // pad to oldDepth, select the last branch for each depth
1856 for (i=d;i<oldDepth;i++)
1860 if ( ((BranchObj*)(selection))->countBranches()>0)
1861 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1868 // try to select the freshly built string
1876 void MapEditor::selectUpperBranch()
1878 // Finish open lineEdits
1879 if (lineedit) finishedLineEditNoSave();
1883 if (typeid(*selection) == typeid(BranchObj))
1885 if (selection->getOrientation()==OrientRightOfCenter)
1888 if (selection->getDepth()==1)
1896 void MapEditor::selectLowerBranch()
1898 // Finish open lineEdits
1899 if (lineedit) finishedLineEditNoSave();
1903 if (typeid(*selection) == typeid(BranchObj))
1905 if (selection->getOrientation()==OrientRightOfCenter)
1908 if (selection->getDepth()==1)
1917 void MapEditor::selectLeftBranch()
1919 // Finish open lineEdits
1920 if (lineedit) finishedLineEditNoSave();
1926 if (typeid(*selection) == typeid(MapCenterObj))
1928 par= (BranchObj*) (selection);
1929 bo=par->getLastSelectedBranch();
1932 // Workaround for reselecting on left and right side
1933 if (bo->getOrientation()==OrientRightOfCenter)
1935 bo=par->getLastBranch();
1941 selection->select();
1943 ensureSelectionVisible();
1948 par=(BranchObj*)(selection->getParObj());
1949 if (selection->getOrientation()==OrientRightOfCenter)
1951 if (typeid(*selection) == typeid(BranchObj) ||
1952 typeid(*selection) == typeid(FloatImageObj))
1954 selection->unselect();
1956 selection->select();
1958 ensureSelectionVisible();
1962 if (typeid(*selection) == typeid(BranchObj) )
1964 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1967 selection->unselect();
1969 selection->select();
1971 ensureSelectionVisible();
1979 void MapEditor::selectRightBranch()
1981 // Finish open lineEdits
1982 if (lineedit) finishedLineEditNoSave();
1989 if (typeid(*selection) == typeid(MapCenterObj))
1991 par= (BranchObj*) (selection);
1992 bo=par->getLastSelectedBranch();
1995 // Workaround for relecting on left and right side
1996 if (bo->getOrientation()==OrientLeftOfCenter)
1997 bo=par->getFirstBranch();
2002 selection->select();
2003 ensureSelectionVisible();
2008 par=(BranchObj*)(selection->getParObj());
2009 if (selection->getOrientation()==OrientLeftOfCenter)
2011 if (typeid(*selection) == typeid(BranchObj) ||
2012 typeid(*selection) == typeid(FloatImageObj))
2014 selection->unselect();
2016 selection->select();
2018 ensureSelectionVisible();
2022 if (typeid(*selection) == typeid(BranchObj) )
2024 bo=((BranchObj*)(selection))->getLastSelectedBranch();
2027 selection->unselect();
2029 selection->select();
2031 ensureSelectionVisible();
2039 void MapEditor::selectFirstBranch()
2041 // Finish open lineEdits
2042 if (lineedit) finishedLineEditNoSave();
2048 if (typeid(*selection) == typeid(BranchObj))
2050 bo1= (BranchObj*) (selection);
2051 par=(BranchObj*)(bo1->getParObj());
2052 bo2=par->getFirstBranch();
2056 selection->select();
2057 ensureSelectionVisible();
2064 void MapEditor::selectLastBranch()
2066 // Finish open lineEdits
2067 if (lineedit) finishedLineEditNoSave();
2073 if (typeid(*selection) == typeid(BranchObj))
2075 bo1= (BranchObj*) (selection);
2076 par=(BranchObj*)(bo1->getParObj());
2077 bo2=par->getLastBranch();
2081 selection->select();
2082 ensureSelectionVisible();
2089 void MapEditor::setColor(QColor c)
2094 void MapEditor::selectBackgroundColor()
2096 // Finish open lineEdits
2097 if (lineedit) finishedLineEditNoSave();
2099 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2100 if ( !col.isValid() ) return;
2101 setBackgroundColor( col );
2105 void MapEditor::setBackgroundColor(QColor c)
2107 mapCanvas->setBackgroundColor (c);
2110 QColor MapEditor::pickColor()
2114 if (typeid(*selection) == typeid(BranchObj) ||
2115 typeid(*selection) == typeid(MapCenterObj))
2117 BranchObj *bo=(BranchObj*)(selection);
2118 actColor=bo->getColor();
2124 void MapEditor::colorItem()
2128 if (typeid(*selection) == typeid(BranchObj) ||
2129 typeid(*selection) == typeid(MapCenterObj))
2131 saveState(selection);
2132 BranchObj *bo=(BranchObj*)(selection);
2133 bo->setColor(actColor, false); // color links, color childs
2138 void MapEditor::colorBranch()
2142 if (typeid(*selection) == typeid(BranchObj) ||
2143 typeid(*selection) == typeid(MapCenterObj))
2145 saveState(selection);
2146 BranchObj *bo=(BranchObj*)(selection);
2147 bo->setColor(actColor, true); // color links, color childs
2153 void MapEditor::toggleStandardFlag(QString f)
2157 saveState(selection);
2158 ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2162 void MapEditor::setViewCenter()
2164 // transform to CanvasView Coord:
2165 QPoint p=worldMatrix().map(movingCenter);
2166 center ( p.x(), p.y());
2170 BranchObj* MapEditor::findText (QString s, bool cs)
2173 { // Nothing found or new find process
2175 // nothing found, start again
2177 itFind=mapCenter->first();
2179 bool searching=true;
2180 bool foundNote=false;
2181 while (searching && !EOFind)
2185 // Searching in Note
2186 if (itFind->getNote().contains(s,cs))
2188 if (selection!=itFind)
2190 if (selection) ((BranchObj*)(selection))->unselect();
2192 selection->select();
2194 ensureSelectionVisible();
2196 if (textEditor->findText(s,cs))
2202 // Searching in Heading
2203 if (searching && itFind->getHeading().contains (s,cs) )
2205 if (selection) ((BranchObj*)(selection))->unselect();
2207 selection->select();
2209 ensureSelectionVisible();
2215 itFind=itFind->next();
2216 if (!itFind) EOFind=true;
2222 return (BranchObj*)(selection);
2227 void MapEditor::findReset()
2228 { // Necessary if text to find changes during a find process
2233 void MapEditor::openURL()
2237 if (typeid(*selection) == typeid(BranchObj) ||
2238 typeid(*selection) == typeid(MapCenterObj))
2240 QString url=((BranchObj*)(selection))->getURL();
2242 QProcess *proc = new QProcess( this );
2244 #if !defined(Q_OS_MACX)
2245 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2247 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2248 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2251 proc->addArgument( url);
2253 if ( !proc->start() )
2255 if (mainWindow->settingsURL() )
2261 void MapEditor::editURL()
2263 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2264 typeid(*selection) == typeid(MapCenterObj)) )
2267 QString text = QInputDialog::getText(
2268 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2269 ((BranchObj*)(selection))->getURL(), &ok, this );
2272 // user entered something and pressed OK
2273 ((BranchObj*)(selection))->setURL (text);
2275 saveState(); //FIXME undoCommand
2280 void MapEditor::editHeading2URL()
2282 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2283 typeid(*selection) == typeid(MapCenterObj)) )
2285 BranchObj *b=(BranchObj*)(selection);
2286 b->setURL (b->getHeading());
2288 saveState(); //FIXME undoCommand
2292 void MapEditor::editBugzilla2URL()
2294 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2295 typeid(*selection) == typeid(MapCenterObj)) )
2297 BranchObj *b=(BranchObj*)(selection);
2298 b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
2300 saveState(); //FIXME undoCommand
2304 void MapEditor::editVymLink()
2306 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2307 typeid(*selection) == typeid(MapCenterObj)) )
2309 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2310 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2311 fd->setCaption(tr("VYM - Link to another map"));
2312 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2313 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2317 if ( fd->exec() == QDialog::Accepted )
2318 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2320 mapCenter->reposition();
2323 saveState(); //FIXME undoCommand
2327 void MapEditor::deleteVymLink()
2329 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2330 typeid(*selection) == typeid(MapCenterObj)) )
2332 ((BranchObj*)(selection))->setVymLink ("" );
2334 mapCenter->reposition();
2337 saveState(); //FIXME undoCommand
2341 QString MapEditor::getVymLink()
2343 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2344 typeid(*selection) == typeid(MapCenterObj)) )
2346 return ((BranchObj*)(selection))->getVymLink();
2352 void MapEditor::removeBranchHere()
2354 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2356 saveState(selection->getParObj());
2357 QString sel=selection->getSelectString();
2358 BranchObj* bo=(BranchObj*)(selection);
2359 BranchObj* par=(BranchObj*)(bo->getParObj());
2361 par->removeBranchHere(bo);
2362 mapCenter->reposition();
2367 void MapEditor::removeChilds()
2369 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2371 saveState(selection->getParObj());
2372 ((BranchObj*)(selection))->removeChilds();
2373 mapCenter->reposition();
2377 void MapEditor::editMapInfo()
2379 ExtraInfoDialog dia;
2380 dia.setMapName (getFileName() );
2381 dia.setAuthor (mapCenter->getAuthor() );
2382 dia.setComment(mapCenter->getComment() );
2387 QCanvasItemList l=canvas()->allItems();
2388 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2390 stats+=QString ("%1 items on canvas\n").arg (i,6);
2397 bo=mapCenter->first();
2400 if (!bo->getNote().isEmpty() ) n++;
2401 f+= bo->countFloatImages();
2403 xl+=bo->countXLinks();
2406 stats+=QString ("%1 branches\n").arg (b-1,6);
2407 stats+=QString ("%1 xLinks \n").arg (xl,6);
2408 stats+=QString ("%1 notes\n").arg (n,6);
2409 stats+=QString ("%1 images\n").arg (f,6);
2410 dia.setStats (stats);
2412 // Finally show dialog
2413 if (dia.exec() == QDialog::Accepted)
2415 mapCenter->setAuthor (dia.getAuthor() );
2416 mapCenter->setComment (dia.getComment() );
2417 saveState(); //FIXME undoCommand
2421 void MapEditor::updateActions()
2424 if (getLinkColorHint()==HeadingColor)
2425 actionFormatLinkColorHint->setOn(true);
2427 actionFormatLinkColorHint->setOn(false);
2432 actionFormatLinkStyleLine->setOn(true);
2435 actionFormatLinkStyleParabel->setOn(true);
2438 actionFormatLinkStylePolyLine->setOn(true);
2440 case StylePolyParabel:
2441 actionFormatLinkStylePolyParabel->setOn(true);
2447 QPixmap pix( 16, 16 );
2448 pix.fill( mapCanvas->backgroundColor() );
2449 actionFormatBackColor->setIconSet( pix );
2450 pix.fill( defLinkColor );
2451 actionFormatLinkColor->setIconSet( pix );
2453 actionEditUndo->setEnabled( mapChanged );
2454 actionFileSave->setEnabled( mapUnsaved );
2458 if ( (typeid(*selection) == typeid(BranchObj)) ||
2459 (typeid(*selection) == typeid(MapCenterObj)) )
2461 BranchObj *bo=(BranchObj*)(selection);
2462 // Take care of links
2463 if (bo->countXLinks()==0)
2465 branchLinksContextMenu->clear();
2466 branchLinksContextMenu->insertItem ("No xLink available");
2467 branchLinksContextMenuDup->clear();
2468 branchLinksContextMenuDup->insertItem ("No xLink available");
2474 branchLinksContextMenu->clear();
2475 branchLinksContextMenuDup->clear();
2476 for (int i=0; i<=bo->countXLinks();i++)
2478 bot=bo->XLinkTargetAt(i);
2481 s=bot->getHeading();
2484 branchLinksContextMenu->insertItem (s);
2485 branchLinksContextMenuDup->insertItem (s);
2490 standardFlagsDefault->setEnabled (true);
2492 if ( bo->getURL().isEmpty() )
2493 actionEditOpenURL->setEnabled (false);
2495 actionEditOpenURL->setEnabled (true);
2497 if ( bo->getVymLink().isEmpty() )
2499 actionEditOpenVymLink->setEnabled (false);
2500 actionEditDeleteVymLink->setEnabled (false);
2503 actionEditOpenVymLink->setEnabled (true);
2504 actionEditDeleteVymLink->setEnabled (true);
2507 actionEditCopy->setEnabled (true);
2508 actionEditCut->setEnabled (true);
2509 if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
2510 actionEditPaste->setEnabled (true);
2512 actionEditPaste->setEnabled (false);
2513 for (a=actionListBranches.first();a;a=actionListBranches.next())
2514 a->setEnabled(true);
2515 actionEditDelete->setEnabled (true);
2516 actionEditToggleFloatExport->setEnabled (false);
2517 switch (selection->getFrameType())
2520 actionFormatFrameNone->setOn(true);
2523 actionFormatFrameRectangle->setOn(true);
2529 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2531 standardFlagsDefault->setEnabled (false);
2533 actionEditOpenURL->setEnabled (false);
2534 actionEditOpenVymLink->setEnabled (false);
2535 actionEditDeleteVymLink->setEnabled (false);
2537 actionEditCopy->setEnabled (true);
2538 actionEditCut->setEnabled (true);
2539 actionEditPaste->setEnabled (false); //FIXME
2540 for (a=actionListBranches.first();a;a=actionListBranches.next())
2541 a->setEnabled(false);
2542 actionEditDelete->setEnabled (true);
2543 actionEditToggleFloatExport->setOn
2544 ( ((FloatImageObj*)(selection))->getFloatExport() );
2549 standardFlagsDefault->setEnabled (false);
2551 actionEditCopy->setEnabled (false);
2552 actionEditCut->setEnabled (false);
2553 actionEditPaste->setEnabled (false);
2554 for (a=actionListBranches.first();a;a=actionListBranches.next())
2555 a->setEnabled(false);
2557 actionEditOpenURL->setEnabled (false);
2558 actionEditOpenVymLink->setEnabled (false);
2559 actionEditDeleteVymLink->setEnabled (false);
2560 actionEditHeading2URL->setEnabled (false);
2561 actionEditDelete->setEnabled (false);
2562 actionEditToggleFloatExport->setEnabled (false);
2566 void MapEditor::setLinkStyle (LinkStyle ls)
2572 bo=mapCenter->first();
2576 bo->setLinkStyle(bo->getDefLinkStyle());
2579 mapCenter->reposition();
2582 LinkStyle MapEditor::getLinkStyle ()
2587 void MapEditor::setLinkColor(QColor c)
2593 void MapEditor::setLinkColorHint()
2595 // called from setLinkColorHint(lch) or at end of parse
2597 bo=mapCenter->first();
2605 void MapEditor::setLinkColorHint(LinkColorHint lch)
2611 void MapEditor::toggleLinkColorHint()
2613 if (linkcolorhint==HeadingColor)
2614 linkcolorhint=DefaultColor;
2616 linkcolorhint=HeadingColor;
2618 bo=mapCenter->first();
2626 LinkColorHint MapEditor::getLinkColorHint()
2628 return linkcolorhint;
2631 QColor MapEditor::getDefLinkColor()
2633 return defLinkColor;
2636 void MapEditor::setDefXLinkColor(QColor col)
2641 QColor MapEditor::getDefXLinkColor()
2643 return defXLinkColor;
2646 void MapEditor::setDefXLinkWidth (int w)
2651 int MapEditor::getDefXLinkWidth()
2653 return defXLinkWidth;
2656 void MapEditor::selectLinkColor()
2658 // Finish open lineEdits
2659 if (lineedit) finishedLineEditNoSave();
2661 QColor col = QColorDialog::getColor( defLinkColor, this );
2662 if ( !col.isValid() ) return;
2663 setLinkColor( col );
2664 saveState(); //FIXME undoCommand
2668 void MapEditor::toggleScroll()
2670 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2672 BranchObj *bo=((BranchObj*)(selection));
2673 if (bo->countBranches()==0) return;
2674 if (bo->getDepth()==0) return;
2675 saveState(selection);
2682 void MapEditor::unScrollAll()
2685 bo=mapCenter->first();
2688 if (bo->isScrolled()) bo->toggleScroll();
2693 void MapEditor::loadFloatImage ()
2696 (typeid(*selection) == typeid(BranchObj)) ||
2697 (typeid(*selection) == typeid(MapCenterObj)) )
2699 BranchObj *bo=((BranchObj*)(selection));
2701 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2702 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2703 ImagePreview *p =new ImagePreview (fd);
2704 fd->setContentsPreviewEnabled( TRUE );
2705 fd->setContentsPreview( p, p );
2706 fd->setPreviewMode( QFileDialog::Contents );
2707 fd->setCaption(tr("vym - Load image"));
2708 fd->setDir (lastImageDir);
2712 if ( fd->exec() == QDialog::Accepted )
2714 saveState(selection);
2715 QString fn=fd->selectedFile();
2716 lastImageDir=fn.left(fn.findRev ("/"));
2717 bo->addFloatImage();
2718 // FIXME check if load was successful
2719 bo->getLastFloatImage()->load(fn);
2720 bo->getLastFloatImage()->setOriginalFilename(fn);
2721 mapCenter->reposition();
2728 void MapEditor::saveFloatImage (int item)
2731 (typeid(*selection) == typeid(FloatImageObj)) )
2733 FloatImageObj *fio=((FloatImageObj*)(selection));
2734 const char* fmt = saveImageFormatMenu->text(item);
2736 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2737 fd->addFilter ("PNG (*.png)");
2738 fd->addFilter ("BMP (*.bmp)");
2739 fd->addFilter ("XBM (*.xbm)");
2740 fd->addFilter ("JPG (*.jpg)");
2741 fd->addFilter ("XPM (*.xpm)");
2742 fd->addFilter ("GIF (*.gif)");
2743 fd->addFilter ("PNM (*.pnm)");
2744 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2745 fd->setCaption(tr("vym - Save image as ") + fmt);
2746 fd->setMode( QFileDialog::AnyFile );
2747 fd->setSelection (fio->getOriginalFilename());
2751 if ( fd->exec() == QDialog::Accepted )
2753 if (QFile (fd->selectedFile()).exists() )
2755 QMessageBox mb( "VYM",
2756 tr("The file ") + fd->selectedFile() +
2757 tr(" exists already. "
2758 "Do you want to overwrite it?"),
2759 QMessageBox::Warning,
2760 QMessageBox::Yes | QMessageBox::Default,
2761 QMessageBox::Cancel | QMessageBox::Escape,
2762 QMessageBox::QMessageBox::NoButton );
2764 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2765 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2768 case QMessageBox::Yes:
2771 case QMessageBox::Cancel:
2777 fio->save (fd->selectedFile(),fmt);
2782 void MapEditor::toggleFloatExport()
2785 (typeid(*selection) == typeid(FloatImageObj))||
2786 (typeid(*selection) == typeid(FloatObj)) )
2788 FloatImageObj *fio=((FloatImageObj*)(selection));
2789 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2793 void MapEditor::setFrame(const FrameType &t)
2796 (typeid(*selection) == typeid(BranchObj)) ||
2797 (typeid(*selection) == typeid(MapCenterObj)) )
2799 selection->setFrameType (t);
2800 mapCenter->reposition();
2801 selection->updateLink();
2805 void MapEditor::importDir(BranchObj *dst, QDir d)
2808 (typeid(*selection) == typeid(BranchObj)) ||
2809 (typeid(*selection) == typeid(MapCenterObj)) )
2813 // Traverse directories
2814 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2815 const QFileInfoList *dirlist = d.entryInfoList();
2816 QFileInfoListIterator itdir( *dirlist );
2819 while ( (fi = itdir.current()) != 0 )
2821 if (fi->fileName() != "." && fi->fileName() != ".." )
2824 bo=dst->getLastBranch();
2825 bo->setHeading (fi->fileName() );
2826 bo->setColor (QColor("blue"),false);
2828 if ( !d.cd(fi->fileName()) )
2829 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2832 // Recursively add subdirs
2840 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2841 const QFileInfoList *filelist = d.entryInfoList();
2842 QFileInfoListIterator itfile( *filelist );
2844 while ( (fi = itfile.current()) != 0 )
2847 bo=dst->getLastBranch();
2848 bo->setHeading (fi->fileName() );
2849 bo->setColor (QColor("black"),false);
2850 if (fi->fileName().right(4) == ".vym" )
2851 bo->setVymLink (fi->filePath());
2858 void MapEditor::importDir()
2861 (typeid(*selection) == typeid(BranchObj)) ||
2862 (typeid(*selection) == typeid(MapCenterObj)) )
2864 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2865 fd->setMode (QFileDialog::DirectoryOnly);
2866 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2867 fd->setCaption(tr("VYM - Choose directory structur to import"));
2871 if ( fd->exec() == QDialog::Accepted )
2873 BranchObj *bo=((BranchObj*)(selection));
2874 importDir (bo,QDir(fd->selectedFile()) );
2875 mapCenter->reposition();
2882 void MapEditor::followXLink(int i)
2885 (typeid(*selection) == typeid(BranchObj)) ||
2886 (typeid(*selection) == typeid(MapCenterObj)) )
2888 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2891 selection->unselect();
2893 selection->select();
2894 ensureSelectionVisible();
2899 void MapEditor::editXLink(int i)
2902 (typeid(*selection) == typeid(BranchObj)) ||
2903 (typeid(*selection) == typeid(MapCenterObj)) )
2905 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2908 EditXLinkDialog dia;
2910 dia.setSelection(selection);
2911 if (dia.exec() == QDialog::Accepted)
2913 if (dia.useSettingsGlobal() )
2915 setDefXLinkColor (xlo->getColor() );
2916 setDefXLinkWidth (xlo->getWidth() );
2918 if (dia.deleteXLink())
2919 ((BranchObj*)(selection))->deleteXLinkAt(i);
2920 saveState(); //FIXME undoCommand
2926 void MapEditor::testFunction()
2928 cout << "MapEditor::testFunction() called\n";
2930 (typeid(*selection) == typeid(BranchObj)) )
2932 QString s=((BranchObj*)(selection))->getHeading();
2937 void MapEditor::ensureSelectionVisible()
2941 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2943 if (selection->getOrientation() == OrientLeftOfCenter)
2944 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2946 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2947 ensureVisible (p.x(), p.y() );
2952 void MapEditor::updateViewCenter()
2954 // Update movingCenter, so that we can zoom comfortably later
2955 QRect rc = QRect( contentsX(), contentsY(),
2956 visibleWidth(), visibleHeight() );
2957 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2958 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2959 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2962 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2964 // Lineedits are already closed by preceding
2965 // mouseEvent, we don't need to close here.
2967 QPoint p = inverseWorldMatrix().map(e->pos());
2968 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2971 { // MapObj was found
2972 if (selection != lmo)
2974 // select the MapObj
2975 if (selection) selection->unselect();
2977 selection->select();
2983 if (typeid(*selection)==typeid(BranchObj) ||
2984 typeid(*selection)==typeid(MapCenterObj) )
2986 // Context Menu on branch or mapcenter
2988 branchContextMenu->popup(e->globalPos() );
2990 if (typeid(*selection)==typeid(FloatImageObj))
2992 // Context Menu on floatimage
2994 floatimageContextMenu->popup(e->globalPos() );
2998 { // No MapObj found, we are on the Canvas itself
2999 // Context Menu on Canvas
3001 canvasContextMenu->popup(e->globalPos() );
3005 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3007 // Finish open lineEdits
3008 if (lineedit) finishedLineEditNoSave();
3010 QPoint p = inverseWorldMatrix().map(e->pos());
3011 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3013 // Special case: CTRL is pressed
3014 if (e->state() & QMouseEvent::ControlButton)
3016 if (actionModModeColor->isOn())
3018 if (e->state() & QMouseEvent::ControlButton)
3021 setCursor (pickColorCursor);
3025 if (actionModModeLink->isOn())
3027 BranchObj *bo_begin=NULL;
3029 bo_begin=(BranchObj*)(lmo);
3032 ((typeid(*selection) == typeid(BranchObj)) ||
3033 (typeid(*selection) == typeid(MapCenterObj))) )
3034 bo_begin=(BranchObj*)(selection);
3038 linkingObj_src=bo_begin;
3039 tmpXLink=new XLinkObj (mapCanvas);
3040 tmpXLink->setBegin (bo_begin);
3041 tmpXLink->setEnd (p);
3042 tmpXLink->setColor(defXLinkColor);
3043 tmpXLink->setWidth(defXLinkWidth);
3044 tmpXLink->updateXLink();
3045 tmpXLink->setVisibility (true);
3052 { // MapObj was found
3053 if (selection != lmo)
3055 // select the MapObj
3056 if (selection) selection->unselect();
3058 selection->select();
3063 // Check, if systemFlag clicked
3064 if (typeid(*selection)==typeid(BranchObj) ||
3065 typeid(*selection)==typeid(MapCenterObj) )
3067 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
3068 if (!foname.isEmpty())
3070 // Do not move, if systemFlag clicked
3074 if (foname=="vymLink")
3076 mainWindow->editOpenVymLink();
3077 // tabWidget may change, better return now
3078 // before segfaulting...
3082 mainWindow->windowToggleNoteEditor();
3086 // Left Button Move Branches
3087 if (e->button() == QMouseEvent::LeftButton )
3089 movingObj_start.setX( p.x() - selection->x() );
3090 movingObj_start.setY( p.y() - selection->y() );
3091 movingObj_orgPos.setX (lmo->x() );
3092 movingObj_orgPos.setY (lmo->y() );
3094 // If modMode==copy, then we want to "move" the _new_ object around
3095 // then we need the offset from p to the _old_ selection, because of tmp
3096 if (actionModModeCopy->isOn() &&
3097 e->state() & QMouseEvent::ControlButton)
3099 if (typeid(*selection)==typeid(BranchObj) )
3102 mapCenter->addBranch ((BranchObj*)(selection));
3104 selection=mapCenter->getLastBranch();
3105 selection->select();
3106 mapCenter->reposition();
3109 movingObj=selection;
3111 // Middle Button Toggle Scroll
3112 // (On Mac OS X this won't work, but we still have
3113 // a button in the toolbar)
3114 if (e->button() == QMouseEvent::MidButton )
3118 { // No MapObj found, we are on the Canvas itself
3119 // Left Button move Pos of CanvasView
3120 if (e->button() == QMouseEvent::LeftButton )
3122 movingObj=NULL; // move Content not Obj
3123 movingObj_start=e->globalPos();
3124 movingCont_start=QPoint (contentsX(), contentsY() );
3125 movingVec=QPoint(0,0);
3126 setCursor(handOpenCursor);
3131 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3133 QPoint p = inverseWorldMatrix().map(e->pos());
3135 // Move the selected MapObj
3136 if ( selection && movingObj)
3138 ensureVisible (p.x(),p.y());
3140 // Now move the selection, but add relative position
3141 // (movingObj_start) where selection was chosen with
3142 // mousepointer. (This avoids flickering resp. jumping
3143 // of selection back to absPos)
3145 LinkableMapObj *lmosel;
3146 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3148 // Check if we could link
3149 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3152 if (typeid(*selection) == typeid(FloatImageObj))
3154 saveState("move "+qpointToString(movingObj_orgPos));
3155 FloatObj *fo=(FloatObj*)(selection);
3156 if (fo->getLinkStyle()==StyleUndef)
3158 fo->setLinkStyle(fo->getDefLinkStyle());
3159 fo->setLinkColor(fo->getParObj()->getLinkColor());
3161 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3165 // Relink float to new mapcenter or branch, if shift is pressed
3166 // Only relink, if selection really has a new parent
3167 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3168 ( (typeid(*lmo)==typeid(BranchObj)) ||
3169 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3170 ( lmo != fo->getParObj())
3173 if (typeid(*fo) == typeid(FloatImageObj))
3176 FloatImageObj *fio=(FloatImageObj*)(fo);
3177 ((BranchObj*)(lmo))->addFloatImage (fio);
3179 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3180 fio=((BranchObj*)(lmo))->getLastFloatImage();
3183 selection=(LinkableMapObj*)(fio);
3184 selection->select();
3185 movingObj=(MapObj*)(fio);
3186 // setLinkStyle calls updateLink, only set it once
3187 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3188 fio->setLinkStyle (fio->getDefLinkStyle());
3190 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3192 } else // selection != a FloatObj
3194 if (lmosel->getDepth()==0)
3196 if (e->state() == (LeftButton | !ShiftButton))
3197 // If mapCenter is moved, move all the rest by default, too.
3198 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3200 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3203 if (lmosel->getDepth()==1)
3205 // depth==1, mainbranch
3206 saveState("move "+qpointToString(movingObj_orgPos));
3207 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3211 if (lmosel->getOrientation() == OrientLeftOfCenter)
3212 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3213 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3214 p.y()-movingObj_start.y() );
3216 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3218 // reposition subbranch
3219 lmosel->reposition();
3220 //ensureSelectionVisible();
3222 if (lmo && (lmo!=selection) &&
3223 (typeid(*lmo) == typeid(BranchObj) ||
3224 (typeid(*lmo) == typeid(MapCenterObj) )
3227 if (e->state() & QMouseEvent::ControlButton)
3229 // Special case: CTRL to link below lmo
3230 lmosel->setParObjTmp (lmo,p,+1);
3232 else if (e->state() & QMouseEvent::ShiftButton)
3233 lmosel->setParObjTmp (lmo,p,-1);
3235 lmosel->setParObjTmp (lmo,p,0);
3238 lmosel->unsetParObjTmp();
3240 if (lmo &&(lmo==selection))
3241 // Could link to myself (happens sometimes...)
3242 lmosel->unsetParObjTmp();
3244 // no Obj under selection, go back to original Parent
3245 lmosel->unsetParObjTmp();
3250 } // no FloatImageObj
3254 } // selection && moving_obj
3256 // Draw a link from one branch to another
3259 tmpXLink->setEnd (p);
3260 tmpXLink->updateXLink();
3264 if (!movingObj && !pickingColor &&!drawingLink)
3266 QPoint p=e->globalPos();
3267 movingVec.setX(-p.x() + movingObj_start.x() );
3268 movingVec.setY(-p.y() + movingObj_start.y() );
3269 setContentsPos( movingCont_start.x() + movingVec.x(),
3270 movingCont_start.y() + movingVec.y());
3277 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3279 LinkableMapObj *dst;
3280 // Have we been picking color?
3284 setCursor (ArrowCursor);
3285 // Check if we are over another branch
3286 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3287 if (dst && selection)
3289 if (e->state() & QMouseEvent::ShiftButton)
3291 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3292 ((BranchObj*)(selection))->setLinkColor ();
3296 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3297 ((BranchObj*)(selection))->setLinkColor ();
3303 // Have we been drawing a link?
3307 // Check if we are over another branch
3308 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3309 if (dst && selection)
3311 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3312 tmpXLink->updateXLink();
3313 tmpXLink->activate();
3314 saveState(); //FIXME undoCommand
3323 // Have we been moving something?
3324 if ( selection && movingObj )
3326 // Check if we are over another branch, but ignore
3327 // any found LMOs, which are FloatObjs
3328 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3329 ((LinkableMapObj*)(selection)) );
3332 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3337 // Now check, if we have been moving a branch
3338 if (typeid(*selection) == typeid(BranchObj) )
3340 // save the position in case we link to mapcenter
3341 QPoint savePos=QPoint (selection->x(),selection->y() );
3343 // Reset the temporary drawn link to the original one
3344 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3350 BranchObj* bs=((BranchObj*)(selection));
3351 saveState ("linkBranchToPos (\""+
3352 (bs->getParObj())->getSelectString()+
3354 QString("%1").arg(bs->getNum())+
3356 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3358 // TODO we also could check, if dest and src are on same branch,
3359 // then it would be sufficient to saveState of this branch
3361 // Modifiers allow to insert above/below dst
3362 if (e->state() & QMouseEvent::ShiftButton)
3364 bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum());
3366 if (e->state() & QMouseEvent::ControlButton)
3368 bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum()+1);
3371 bs->moveBranchTo ((BranchObj*)(dst),-1);
3372 if (dst->getDepth()==0)
3376 // Draw the original link, before selection was moved around
3377 mapCenter->reposition();
3379 // Finally resize canvas, if needed
3384 // maybe we moved View: set old cursor
3385 setCursor (ArrowCursor);
3389 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3391 // Finish open lineEdits
3392 if (lineedit) finishedLineEditNoSave();
3394 if (e->button() == QMouseEvent::LeftButton )
3396 QPoint p = inverseWorldMatrix().map(e->pos());
3397 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3398 if (lmo) { // MapObj was found
3399 // First select the MapObj than edit heading
3400 if (selection) selection->unselect();
3402 selection->select();
3403 saveState(selection);
3409 void MapEditor::resizeEvent (QResizeEvent* e)
3411 QCanvasView::resizeEvent( e );
3414 if (!fileName.isEmpty()) s=fileName;
3418 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3421 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3422 // cerr << event->format(i) << endl;
3425 (typeid(*selection) == typeid(BranchObj)) ||
3426 (typeid(*selection) == typeid(MapCenterObj))) {
3428 // If QImageDrag can decode mime type
3429 if (QImageDrag::canDecode(event)) {
3434 // If image are dragged from firefox
3435 if (event->provides("application/x-moz-file-promise-url") &&
3436 event->provides("application/x-moz-nativeimage")) {
3437 event->accept(true);
3441 // If QUriDrag can decode mime type
3442 if (QUriDrag::canDecode(event)) {
3447 // If Uri are dragged from firefox
3448 if (event->provides("_NETSCAPE_URL")){
3453 // If QTextDrag can decode mime type
3454 if (QTextDrag::canDecode(event)) {
3463 bool isUnicode16(const QByteArray &d)
3465 // FIXME: make more precise check for unicode 16.
3466 // Guess unicode16 if any of second bytes are zero
3467 unsigned int length = max(0,d.size()-2)/2;
3468 for (unsigned int i = 0; i<length ; i++)
3469 if (d.at(i*2+1)==0) return true;
3473 void MapEditor::contentsDropEvent(QDropEvent *event)
3476 (typeid(*selection) == typeid(BranchObj)) ||
3477 (typeid(*selection) == typeid(MapCenterObj)))
3482 if (event->provides("image/png"))
3485 if (QImageDrag::decode(event, pix))
3493 } else if (event->provides("application/x-moz-file-promise-url") &&
3494 event->provides("application/x-moz-nativeimage"))
3496 // Contains url to the img src in unicode16
3497 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3498 QString url = QString((const QChar*)d.data(),d.size()/2);
3502 } else if (event->provides ("text/uri-list"))
3503 { // Uris provided e.g. by konqueror
3504 QUriDrag::decode (event,uris);
3505 } else if (event->provides ("_NETSCAPE_URL"))
3506 { // Uris provided by Mozilla
3507 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3510 } else if (event->provides("text/html")) {
3512 // Handels text mime types
3513 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3514 QByteArray d = event->encodedData("text/html");
3517 text = QString((const QChar*)d.data(),d.size()/2);
3521 textEditor->setText(text);
3525 } else if (event->provides("text/plain")) {
3526 QByteArray d = event->encodedData("text/plain");
3529 text = QString((const QChar*)d.data(),d.size()/2);
3533 textEditor->setText(text);
3545 for (const char* u=uris.first(); u; u=uris.next())
3547 bo=((BranchObj*)(selection))->addBranch();
3550 s=QUriDrag::uriToLocalFile(u);
3552 QString file = QDir::convertSeparators(s);
3553 heading = QFileInfo(file).baseName();
3555 if (file.endsWith(".vym", false))
3556 bo->setVymLink(file);
3565 bo->setHeading(heading);
3575 saveState(); //FIXME undo Command
3576 mapCenter->reposition();
3583 void MapEditor::addFloatImage(const QPixmap &img)
3586 (typeid(*selection) == typeid(BranchObj)) ||
3587 (typeid(*selection) == typeid(MapCenterObj)) )
3589 BranchObj *bo=((BranchObj*)(selection));
3590 saveState(selection);
3591 //QString fn=fd->selectedFile();
3592 //lastImageDir=fn.left(fn.findRev ("/"));
3593 bo->addFloatImage();
3594 // FIXME check if load was successful
3595 bo->getLastFloatImage()->load(img);
3596 //bo->getLastFloatImage()->setOriginalFilename(fn);
3597 mapCenter->reposition();
3604 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3606 if (!imageBuffer) imageBuffer = new QBuffer();
3607 if (!imageBuffer->isOpen()) {
3608 imageBuffer->open(IO_WriteOnly | IO_Append);
3610 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3614 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3616 if (nop->state()==QNetworkProtocol::StDone) {
3617 QPixmap img(imageBuffer->buffer());
3622 imageBuffer->close();
3624 imageBuffer->close();
3631 void MapEditor::fetchImage(const QString &url)
3634 urlOperator->stop();
3635 disconnect(urlOperator);
3639 urlOperator = new QUrlOperator(url);
3640 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3641 this, SLOT(imageDataFinished(QNetworkOperation*)));
3643 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3644 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));