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 blockSaveState=false;
365 isInteractive=interactive;
367 // Create temporary files
370 // Initially set movingCentre
373 mapCenter->reposition(); // for positioning heading
376 MapEditor::~MapEditor()
378 if (imageBuffer) delete imageBuffer;
384 //cout <<"Destructor MapEditor\n";
385 if (isInteractive) delTmpDirs();
388 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
392 QColor MapEditor::color()
397 QColor MapEditor::backgroundColor()
399 return mapCanvas->backgroundColor();
402 MapCenterObj* MapEditor::getMapCenter()
407 QCanvas* MapEditor::getCanvas()
412 void MapEditor::adjustCanvasSize()
414 // To adjust the canvas to map, viewport size and position, we have to
415 // do some coordinate magic...
417 // Get rectangle of (scroll-)view.
418 // We want to be in canvas coords, so
419 // we map. Important if view is zoomed...
420 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
421 visibleWidth(), visibleHeight()) );
423 // Now we need the bounding box of view AND map to calc the correct canvas size.
424 // Why? Because if the map itself is moved out of view, the view has to be enlarged
425 // to avoid jumping aroung...
426 QRect map=mapCenter->getTotalBBox();
428 // right edge - left edge
429 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
430 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
433 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
434 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
437 // move the map on canvas (in order to not move it on screen) this is neccessary
438 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
439 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
440 // to scroll to an empty area of canvas to the left.
441 // b) if topleft corner of map left of or above topleft of canvas
445 if (cw > mapCanvas->width() )
447 if (map.x()<0) dx=-map.x();
449 if (cw < mapCanvas->width() )
450 dx=-min (view.x(),map.x());
451 if (ch > mapCanvas->height() )
453 if (map.y()<0) dy=-map.y();
455 if (ch < mapCanvas->height() )
457 dy=-min (view.y(),map.y());
459 // We really have to resize now. Let's go...
460 mapCanvas->resize (cw,ch);
461 if ( (dx!=0) || (dy!=0) )
463 mapCenter->moveAllBy(dx,dy);
464 mapCenter->reposition();
466 // scroll the view (in order to not move map on screen)
472 bool MapEditor::isRepositionBlocked()
474 return blockReposition;
477 void MapEditor::makeTmpDirs()
479 // Create unique temporary directories
480 char tmpdir[]="/tmp/vym-XXXXXX";
481 bakMapDir=mkdtemp(tmpdir);
482 makeSubDirs(bakMapDir);
483 // FIXME set permissions and maybe use QT method for portability
486 void MapEditor::delTmpDirs()
488 //FIXME delete tmp directory, better use QT methods here:
489 system ( "rm -rf "+ bakMapDir );
493 void MapEditor::makeSubDirs(const QString &s)
501 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
503 // tmpdir temporary directory to which data will be writte
504 // prefix mapname, which will be appended to images etc.
505 // writeflags Only write flags for "real" save of map, not undo
506 // offset offset of bbox of whole map in canvas.
507 // Needed for XML export
508 // completeMap if false, only vympart will be written, without
525 ls="StylePolyParabel";
529 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
531 if (linkcolorhint==HeadingColor)
532 colhint=attribut("linkColorHint","HeadingColor");
534 QString mapAttr=attribut("version",__VYM_VERSION__);
536 mapAttr+= attribut("author",mapCenter->getAuthor()) +
537 attribut("comment",mapCenter->getComment()) +
538 attribut("date",mapCenter->getDate()) +
539 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
540 attribut("linkStyle", ls ) +
541 attribut("linkColor", defLinkColor.name() ) +
542 attribut("defXLinkColor", defXLinkColor.name() ) +
543 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
545 s+=beginElement("vymmap",mapAttr);
548 // Find the used flags while traversing the tree
549 standardFlagsDefault->resetUsedCounter();
551 // Build xml recursivly
553 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
556 if ( typeid(*saveSelection) == typeid(BranchObj) )
557 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
559 if (selection && typeid(*selection)==typeid(BranchObj))
560 // This is used if selected branch is saved from mainwindow
561 s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
564 // Save local settings
565 s+=settings.getXMLData (destPath);
568 if (selection && !saveSelection )
569 s+=valueElement("select",selection->getSelectString());
572 s+=endElement("vymmap");
575 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
579 void MapEditor::saveState()
581 saveState (CompleteMap,NULL,"","");
584 void MapEditor::saveState(LinkableMapObj *undoSel)
586 saveState (PartOfMap,undoSel,"","");
589 void MapEditor::saveState(const QString & uc, const QString &rc)
591 LinkableMapObj *undoSel;
596 saveState (UndoCommand,undoSel,uc,rc);
599 void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom, const QString &redoCom)
601 if (blockSaveState) return;
605 // Save current selection
608 redoSelection=selection->getSelectString();
612 // Save the object, which should be undone
614 undoSelection=undoSel->getSelectString();
618 // Save depending on how much needs to be saved
619 if (savemode==UndoCommand)
624 else if (savemode==PartOfMap && undoSel)
626 undoCommand="undoPart (\""+undoSelection+"\")";
627 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
630 undoCommand="undoMap ()";
631 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
635 cout << "ME::saveState()\n";
636 cout << " undoCom="<<undoCommand<<endl;
637 cout << " undoSel="<<undoSelection<<endl;
638 cout << " ---------------------------"<<endl;
639 cout << " redoCom="<<redoCommand<<endl;
640 cout << " redoSel="<<redoSelection<<endl<<endl;
644 void MapEditor::parseAtom(const QString &atom)
651 // Split string s into command and parameters
652 api.parseCommand (atom);
653 QString com=api.command();
656 if (com==QString("moveBranchUp"))
658 else if (com=="moveBranchDown")
660 else if (com=="move")
662 if (api.checkParamCount(2) && selection )
672 else if (com=="linkBranchToPos")
674 if (selection && typeid(*selection) == typeid(BranchObj) )
676 if (api.checkParamCount(4))
678 s=api.parString(ok,0);
679 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
682 if (typeid(*dst) == typeid(BranchObj) )
684 // Get number in parent
687 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),x);
688 } else if (typeid(*dst) == typeid(MapCenterObj) )
690 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
691 // Get coordinates of mainbranch
696 if (ok) ((BranchObj*)(selection))->move (x,y);
702 } else if (com=="setHeading")
704 if (api.checkParamCount(1))
706 s=api.parString (ok,0);
707 if (ok) setHeading (s);
710 // Internal commands, used for undo etc.
711 else if (com==QString("undoMap"))
713 if (api.checkParamCount(0))
715 } else if (com==QString("undoPart"))
717 if (api.checkParamCount(1))
719 s=api.parString (ok,0);
722 } else if (com=="select")
723 if (api.checkParamCount(1))
725 s=api.parString(ok,0);
729 api.setError ("Unknown command in: "+atom);
734 cout << "MapEditor::parseAtom: Error!\n";
735 cout << " "<<api.errorDesc()<<endl;
740 void MapEditor::finishedLineEditNoSave()
742 // This is called by finishedLineEdit or any MapEditor method,
743 // which wants to assure, that lineedits finish, before e.g. a branch is
746 // After calling LineEdit and using the clipboard, the
747 // focus is not any longer on the main widget, we
748 // have to restore it using parentWidget()->setFocus()
752 editingBO->setHeading(lineedit->text() );
754 lineedit->releaseKeyboard();
756 parentWidget()->setFocus();
757 mapCenter->reposition();
759 ensureSelectionVisible();
764 bool MapEditor::isDefault()
769 bool MapEditor::isUnsaved()
774 bool MapEditor::hasChanged()
779 void MapEditor::setChanged()
784 actionEditUndo->setEnabled (true);
785 actionFileSave->setEnabled (true);
789 void MapEditor::closeMap()
791 // Finish open lineEdits
792 if (lineedit) finishedLineEditNoSave();
794 // Unselect before disabling the toolbar actions
795 if (selection) selection->unselect();
803 void MapEditor::setFilePath(QString fname)
805 setFilePath (fname,fname);
808 void MapEditor::setFilePath(QString fname, QString destname)
817 filePath=fname; // becomes absolute path
818 fileName=fname; // gets stripped of path
819 destPath=destname; // needed for vymlinks
821 // If fname is not an absolute path, complete it
822 filePath=QDir(fname).absPath();
823 fileDir=filePath.left (1+filePath.findRev ("/"));
825 // Set short name, too. Search from behind:
826 int i=fileName.findRev("/");
827 if (i>=0) fileName=fileName.remove (0,i+1);
829 // Forget the .vym (or .xml) for name of map
830 mapName=fileName.left(fileName.findRev(".",-1,true) );
834 QString MapEditor::getFilePath()
839 QString MapEditor::getFileName()
844 QString MapEditor::getMapName()
849 QString MapEditor::getDestPath()
854 int MapEditor::load (QString &fname, const LoadMode &lmode)
856 // Finish open lineEdits
857 if (lineedit) finishedLineEditNoSave();
863 if (selection) selection->unselect();
866 mapCenter->setMapEditor(this);
867 // (map state is set later at end of load...)
870 saveState(selection);
874 mapBuilderHandler handler;
877 // I am paranoid: file should exist anyway
878 // according to check in mainwindow.
881 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
882 tr("Couldn't open map " +fname)+".");
886 blockReposition=true;
887 QXmlInputSource source( file);
888 QXmlSimpleReader reader;
889 reader.setContentHandler( &handler );
890 reader.setErrorHandler( &handler );
891 handler.setMapEditor( this );
892 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
893 handler.setLoadMode (lmode);
894 bool ok = reader.parse( source );
895 blockReposition=false;
899 mapCenter->reposition();
909 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
910 tr( handler.errorProtocol() ) );
912 // Still return "success": the map maybe at least
913 // partially read by the parser
920 int MapEditor::save (const SaveMode &savemode)
922 // Finish open lineEdits
923 if (lineedit) finishedLineEditNoSave();
927 // The SaveMode UndoCommand is not supported here
928 if (savemode==UndoCommand) return 1;
930 // Create mapName and fileDir
931 makeSubDirs (fileDir);
935 fname=mapName+".xml";
937 // use name given by user, even if he chooses .doc
941 // Check if fname is writeable
942 QFile file( fileDir+fname);
943 if (!file.open( IO_WriteOnly ) )
945 QMessageBox::critical( 0, tr( "Critical Save Error" ),
946 tr("Couldn't write to ") +fileDir+fname);
952 if (savemode==CompleteMap || selection==NULL)
953 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
955 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
957 file.setName ( fileDir + fname);
958 if ( !file.open( IO_WriteOnly ) )
960 // This should neverever happen
961 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
965 // Write it finally, and write in UTF8, no matter what
966 QTextStream ts( &file );
967 ts.setEncoding (QTextStream::UnicodeUTF8);
975 actionFileSave->setEnabled(false);
981 void MapEditor::setZipped (bool z)
986 bool MapEditor::saveZipped ()
991 void MapEditor::print()
993 // Finish open lineEdits
994 if (lineedit) finishedLineEditNoSave();
998 printer = new QPrinter;
999 printer->setColorMode (QPrinter::Color);
1000 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
1003 QRect totalBBox=mapCenter->getTotalBBox();
1005 // Try to set orientation automagically
1006 // Note: Interpretation of generated postscript is amibiguous, if
1007 // there are problems with landscape mode, see
1008 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1010 if (totalBBox.width()>totalBBox.height())
1011 // recommend landscape
1012 printer->setOrientation (QPrinter::Landscape);
1014 // recommend portrait
1015 printer->setOrientation (QPrinter::Portrait);
1017 if ( printer->setup(this) )
1018 // returns false, if printing is canceled
1020 QPainter pp(printer);
1022 // Don't print the visualisation of selection
1023 LinkableMapObj *oldselection=NULL;
1026 oldselection=selection;
1027 selection->unselect();
1030 // Handle sizes of map and paper:
1032 // setWindow defines which part of the canvas will be transformed
1033 // setViewport defines area on paper in device coordinates (dpi)
1034 // e.g. (0,50,700,700) is upper part on A4
1035 // see also /usr/lib/qt3/doc/html/coordsys.html
1037 QPaintDeviceMetrics metrics (printer);
1039 double paperAspect = (double)metrics.width() / (double)metrics.height();
1040 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1042 QRect mapRect=totalBBox;
1043 QCanvasRectangle *frame=NULL;
1044 QCanvasText *footerFN=NULL;
1045 QCanvasText *footerDate=NULL;
1046 if (printFrame || printFooter)
1051 // Print frame around map
1052 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1053 totalBBox.width()+20, totalBBox.height()+20);
1054 frame=new QCanvasRectangle (mapRect,mapCanvas);
1055 frame->setBrush (QColor(white));
1056 frame->setPen (QColor(black));
1061 QCanvasLine *l=new QCanvasLine (mapCanvas);
1062 l->setPoints (0,0,mapRect.width(),mapRect.height());
1063 l->setPen (QPen(QColor(black), 1));
1070 // Print footer below map
1072 font.setPointSize(10);
1073 footerFN=new QCanvasText (mapCanvas);
1074 footerFN->setText ("VYM - " + fileName);
1075 footerFN->setFont(font);
1076 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1077 footerFN->setZ(Z_TEXT);
1079 footerDate=new QCanvasText (mapCanvas);
1080 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1081 footerDate->setFont(font);
1082 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1083 footerDate->setZ(Z_TEXT);
1086 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1089 pp.setWindow (mapRect);
1092 if (mapAspect>=paperAspect)
1094 // Fit horizontally to paper width
1095 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1098 // Fit vertically to paper height
1099 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1102 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1104 // Delete Frame and footer
1108 delete (footerDate);
1110 if (frame) delete (frame);
1112 // Restore selection
1115 selection=oldselection;
1116 selection->select();
1119 // Save settings in vymrc
1120 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1124 QPixmap MapEditor::getPixmap()
1126 QRect mapRect=mapCenter->getTotalBBox();
1127 QPixmap pix (mapRect.size());
1130 // Don't print the visualisation of selection
1131 LinkableMapObj *oldselection=NULL;
1134 oldselection=selection;
1135 selection->unselect();
1138 pp.setWindow (mapRect);
1140 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1143 // Restore selection
1146 selection=oldselection;
1147 selection->select();
1153 void MapEditor::exportImage(QString fn)
1155 // Finish open lineEdits
1156 if (lineedit) finishedLineEditNoSave();
1158 QPixmap pix (getPixmap());
1159 pix.save(fn, "PNG");
1162 void MapEditor::exportImage(QString fn, int item)
1164 // Finish open lineEdits
1165 if (lineedit) finishedLineEditNoSave();
1167 QPixmap pix (getPixmap());
1168 pix.save(fn, exportImageFormatMenu->text(item) );
1171 void MapEditor::exportASCII()
1173 // FIXME still experimental
1175 ex.setMapCenter(mapCenter);
1177 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
1178 fd->addFilter ("TXT (*.txt)");
1179 fd->setCaption("VYM - Export (ASCII) (still experimental)");
1180 fd->setMode( QFileDialog::AnyFile );
1183 if ( fd->exec() == QDialog::Accepted )
1185 if (QFile (fd->selectedFile()).exists() )
1187 QMessageBox mb( "VYM",
1188 tr("The file ") + fd->selectedFile() +
1189 tr(" exists already. Do you want to overwrite it?"),
1190 QMessageBox::Warning,
1191 QMessageBox::Yes | QMessageBox::Default,
1192 QMessageBox::Cancel | QMessageBox::Escape,
1193 QMessageBox::NoButton );
1195 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1196 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1200 case QMessageBox::Yes:
1203 case QMessageBox::Cancel:
1204 // return, do nothing
1209 ex.setPath (fd->selectedFile() );
1215 void MapEditor::exportXML(const QString &dir)
1217 // Create subdirectories
1220 // write to directory
1221 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1224 file.setName ( dir + "/"+mapName+".xml");
1225 if ( !file.open( IO_WriteOnly ) )
1227 // This should neverever happen
1228 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1232 // Write it finally, and write in UTF8, no matter what
1233 QTextStream ts( &file );
1234 ts.setEncoding (QTextStream::UnicodeUTF8);
1238 // Now write image, too
1239 exportImage (dir+"/images/"+mapName+".png");
1242 void MapEditor::clear()
1246 selection->unselect();
1253 void MapEditor::copy()
1255 // Finish open lineEdits
1256 if (lineedit) finishedLineEditNoSave();
1260 if (typeid(*selection) == typeid(BranchObj) )
1264 clipboardME->clear();
1265 clipboardME->getMapCenter()->addBranch();
1266 to=clipboardME->getMapCenter()->getLastBranch();
1269 from=(BranchObj*)(selection);
1272 // keep position relative to parent
1273 to->move2RelPos ( from->getRelPos());
1275 // select data in clipboard
1276 clipboardME->select ("bo:0");
1278 // repositioning makes testing nicer,
1279 // but is not needed usually:
1280 if (clipboardME->isVisible())
1282 clipboardME->getMapCenter()->reposition();
1285 clipboardME->hide();
1288 if (typeid(*selection) == typeid(FloatImageObj) )
1291 FloatImageObj* from;
1292 clipboardME->clear();
1293 clipboardME->getMapCenter()->addFloatImage();
1294 to=clipboardME->getMapCenter()->getLastFloatImage();
1297 from=(FloatImageObj*)(selection);
1300 // select data in clipboard
1301 clipboardME->select ("fi:0");
1303 // repositioning makes testing nicer,
1304 // but is not needed usually:
1305 if (clipboardME->isVisible())
1307 clipboardME->getMapCenter()->reposition();
1310 clipboardME->hide();
1316 void MapEditor::undo()
1318 // Finish open lineEdits
1319 if (lineedit) finishedLineEditNoSave();
1321 // select object before undo
1322 if (!undoSelection.isEmpty())
1323 select (undoSelection);
1325 parseAtom (undoCommand);
1326 mapCenter->reposition();
1328 // Undo not longer available now
1329 actionEditUndo->setEnabled (false);
1332 if (!redoSelection.isEmpty())
1333 select (redoSelection);
1336 void MapEditor::undoXML(const QString &undoSel)
1339 d.setPath(bakMapDir);
1342 // We need to parse saved XML data
1343 mapBuilderHandler handler;
1344 QXmlInputSource source;
1345 source.setData(backupXML);
1346 QXmlSimpleReader reader;
1347 reader.setContentHandler( &handler );
1348 reader.setErrorHandler( &handler );
1349 handler.setMapEditor( this );
1350 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1351 if (undoSel.isEmpty())
1355 handler.setLoadMode (NewMap);
1359 handler.setLoadMode (ImportReplace);
1361 blockReposition=true;
1362 blockSaveState=true;
1363 bool ok = reader.parse( source );
1364 blockReposition=false;
1365 blockSaveState=false;
1368 // This should never ever happen
1369 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1370 tr( handler.errorProtocol() )+" in "+backupXML );
1374 QMessageBox::critical( 0, tr( "Critical Error" ),
1375 "Temporary directory " +bakMapDir +
1376 tr (" used for undo is gone. \n"
1377 "I will create a new one, but at the moment no undo is available.\n"
1378 "Maybe you want to reload your original data.\n\n"
1379 "Sorry for any inconveniences.") );
1384 LinkableMapObj* MapEditor::pasteNoSave()
1386 // Finish open lineEdits
1387 if (lineedit) finishedLineEditNoSave();
1389 LinkableMapObj *fromLMO=clipboardME->getSelection();
1390 LinkableMapObj *returnLMO=NULL;
1392 if (selection && fromLMO)
1394 if (typeid(*fromLMO) == typeid(BranchObj) )
1396 if (typeid(*selection) == typeid(MapCenterObj))
1398 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1399 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1401 if (typeid(*selection) == typeid(BranchObj))
1402 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1405 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1406 (typeid(*selection) == typeid (BranchObj) ||
1407 typeid(*selection)==typeid(MapCenterObj)) )
1408 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1414 void MapEditor::cutNoSave()
1416 // Finish open lineEdits
1417 if (lineedit) finishedLineEditNoSave();
1421 if (selection != NULL) {
1422 if (typeid(*selection) == typeid(BranchObj) )
1424 bo=(BranchObj*)(selection);
1425 par=(BranchObj*)(bo->getParObj());
1428 par->removeBranch(bo);
1430 selection->select();
1432 if (typeid(*selection) == typeid(FloatImageObj) )
1434 FloatImageObj* fio=(FloatImageObj*)(selection);
1435 par=(BranchObj*)(fio->getParObj());
1438 par->removeFloatImage(fio);
1440 selection->select();
1445 void MapEditor::paste()
1447 saveState(selection);
1449 mapCenter->reposition();
1453 void MapEditor::cut()
1455 saveState(selection->getParObj());
1458 mapCenter->reposition();
1462 void MapEditor::move(const int &x, const int &y)
1464 // FIXME no saveState, because this is only internal at undo so far
1465 if (selection) selection->move(x,y);
1466 if (typeid(*selection) == typeid(FloatImageObj))
1467 ((FloatImageObj*)(selection))->setRelPos();
1470 void MapEditor::moveBranchUp()
1472 // Finish open lineEdits
1473 if (lineedit) finishedLineEditNoSave();
1477 if (typeid(*selection) == typeid(BranchObj) )
1479 bo=(BranchObj*)(selection);
1480 par=(BranchObj*)(bo->getParObj());
1481 selection->unselect();
1482 selection=par->moveBranchUp (bo);
1483 selection->select();
1484 saveState("moveBranchDown ()",bo->getSelectString());
1485 mapCenter->reposition();
1486 ensureSelectionVisible();
1490 void MapEditor::moveBranchDown()
1492 // Finish open lineEdits
1493 if (lineedit) finishedLineEditNoSave();
1497 if (typeid(*selection) == typeid(BranchObj) )
1499 bo=(BranchObj*)(selection);
1500 par=(BranchObj*)(bo->getParObj());
1501 selection->unselect();
1502 selection=par->moveBranchDown(bo);
1503 selection->select();
1504 saveState("moveBranchUp ()",bo->getSelectString());
1505 mapCenter->reposition();
1506 ensureSelectionVisible();
1510 void MapEditor::editHeading()
1512 // Finish open lineEdits
1513 if (lineedit) finishedLineEditNoSave();
1516 (typeid(*selection) == typeid(BranchObj) ||
1517 typeid(*selection) == typeid(MapCenterObj) ) )
1519 editingBO=(BranchObj*)(selection);
1520 saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")",editingBO->getSelectString() );
1522 ensureSelectionVisible();
1523 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1524 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1525 QString s=editingBO->getHeading();
1526 lineedit->setText(s);
1527 lineedit->setCursorPosition(1);
1528 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1529 lineedit->selectAll();
1532 lineedit->grabKeyboard();
1533 lineedit->setFocus();
1537 void MapEditor::setHeading(const QString &s)
1539 // Internal function, no saveState needed
1541 (typeid(*selection) == typeid(BranchObj) ||
1542 typeid(*selection) == typeid(MapCenterObj) ) )
1544 ((BranchObj*)(selection))->setHeading(s);
1545 mapCenter->reposition();
1547 ensureSelectionVisible();
1551 void MapEditor::addNewBranch(int pos)
1553 // Finish open lineEdits
1554 if (lineedit) finishedLineEditNoSave();
1557 (typeid(*selection) == typeid(BranchObj) ||
1558 typeid(*selection) == typeid(MapCenterObj) ) )
1560 saveState(selection);
1562 BranchObj* bo1 = (BranchObj*) (selection);
1563 bool wasScrolled=false;
1564 BranchObj *newbo=NULL;
1567 // save scroll state. If scrolled, automatically select
1568 // new branch in order to tmp unscroll parent...
1569 wasScrolled=bo1->isScrolled();
1570 newbo=bo1->addBranch();
1573 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1577 // add above selection
1578 newbo=parbo->insertBranch(bo1->getNum());
1580 // add below selection
1581 newbo=parbo->insertBranch(bo1->getNum()+1);
1583 // This should not happen...
1588 LinkableMapObj *oldselection=selection;
1590 mapCenter->reposition();
1592 if (actionSettingsAutoedit->isOn() ||
1593 actionSettingsAutoselectHeading->isOn() )
1595 selection->unselect();
1597 selection->select();
1598 if (actionSettingsPasteNewHeading->isOn() )
1600 BranchObj *bo2= (BranchObj*)(selection);
1601 bo2->setHeading("");
1603 if (actionSettingsAutoedit->isOn() )
1605 if (!actionSettingsAutoselectHeading->isOn()
1608 selection->unselect();
1609 selection=oldselection;
1610 selection->select();
1617 void MapEditor::addNewBranchHere()
1619 // Finish open lineEdits
1620 if (lineedit) finishedLineEditNoSave();
1623 (typeid(*selection) == typeid(BranchObj) ) )
1625 saveState(selection);
1627 BranchObj* bo1 = (BranchObj*) (selection);
1628 bool wasScrolled=false;
1629 BranchObj *newbo=NULL;
1630 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1633 // add below selection
1634 newbo=parbo->insertBranch(bo1->getNum()+1);
1637 LinkableMapObj *oldselection=selection;
1638 ((BranchObj*)(selection))->moveBranchTo (newbo,-1);
1640 mapCenter->reposition();
1642 if (actionSettingsAutoedit->isOn() ||
1643 actionSettingsAutoselectHeading->isOn() )
1645 selection->unselect();
1647 selection->select();
1648 if (actionSettingsPasteNewHeading->isOn() )
1650 BranchObj *bo2= (BranchObj*)(selection);
1651 bo2->setHeading("");
1653 if (actionSettingsAutoedit->isOn() )
1655 if (!actionSettingsAutoselectHeading->isOn()
1658 selection->unselect();
1659 selection=oldselection;
1660 selection->select();
1666 void MapEditor::deleteSelection()
1668 // Finish open lineEdits
1669 if (lineedit) finishedLineEditNoSave();
1671 if (selection && typeid(*selection) ==typeid(BranchObj) )
1673 if (selection->getDepth()>1)
1674 // Normal branch, save parent with childs
1675 saveState(selection->getParObj());
1677 // Mainbranch, save whole map
1678 // FIXME Better would be to insert mainbranch again at pos
1679 // But undoCommand is missing right now
1681 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1682 BranchObj* par=(BranchObj*)(bo->getParObj());
1685 par->removeBranch(bo);
1687 selection->select();
1688 ensureSelectionVisible();
1689 mapCenter->reposition();
1692 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1694 saveState(selection->getParObj());
1695 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1696 BranchObj* par=(BranchObj*)(fio->getParObj());
1699 par->removeFloatImage(fio);
1701 selection->select();
1702 ensureSelectionVisible();
1703 mapCenter->reposition();
1708 LinkableMapObj* MapEditor::getSelection()
1713 bool MapEditor::select (const QString &s)
1715 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1717 // Finally select the found object
1720 if (selection) unselect();
1722 selection->select();
1724 ensureSelectionVisible();
1730 void MapEditor::unselect()
1734 selectionLast=selection;
1735 selection->unselect();
1740 void MapEditor::reselect()
1744 selection=selectionLast;
1745 selection->select();
1750 void MapEditor::selectNextBranch()
1752 // Increase number of branch
1755 QString s=selection->getSelectString();
1761 part=s.section(",",-1);
1763 num=part.right(part.length() - 3);
1765 s=s.left (s.length() -num.length());
1768 num=QString ("%1").arg(num.toUInt()+1);
1772 // Try to select this one
1773 if (select (s)) return;
1775 // We have no direct successor,
1776 // try to increase the parental number in order to
1777 // find a successor with same depth
1779 int d=selection->getDepth();
1784 while (!found && d>0)
1786 s=s.section (",",0,d-1);
1787 // replace substring of current depth in s with "1"
1788 part=s.section(",",-1);
1790 num=part.right(part.length() - 3);
1794 // increase number of parent
1795 num=QString ("%1").arg(num.toUInt()+1);
1796 s=s.section (",",0,d-2) + ","+ typ+num;
1799 // Special case, look at orientation
1800 if (selection->getOrientation()==OrientRightOfCenter)
1801 num=QString ("%1").arg(num.toUInt()+1);
1803 num=QString ("%1").arg(num.toUInt()-1);
1808 // pad to oldDepth, select the first branch for each depth
1809 for (i=d;i<oldDepth;i++)
1814 if ( ((BranchObj*)(selection))->countBranches()>0)
1822 // try to select the freshly built string
1830 void MapEditor::selectPrevBranch()
1832 // Decrease number of branch
1835 QString s=selection->getSelectString();
1841 part=s.section(",",-1);
1843 num=part.right(part.length() - 3);
1845 s=s.left (s.length() -num.length());
1848 num=QString ("%1").arg(num.toUInt()-1);
1852 // Try to select this one
1853 if (select (s)) return;
1855 // We have no direct precessor,
1856 // try to decrease the parental number in order to
1857 // find a precessor with same depth
1859 int d=selection->getDepth();
1864 while (!found && d>0)
1866 s=s.section (",",0,d-1);
1867 // replace substring of current depth in s with "1"
1868 part=s.section(",",-1);
1870 num=part.right(part.length() - 3);
1874 // decrease number of parent
1875 num=QString ("%1").arg(num.toUInt()-1);
1876 s=s.section (",",0,d-2) + ","+ typ+num;
1879 // Special case, look at orientation
1880 if (selection->getOrientation()==OrientRightOfCenter)
1881 num=QString ("%1").arg(num.toUInt()-1);
1883 num=QString ("%1").arg(num.toUInt()+1);
1888 // pad to oldDepth, select the last branch for each depth
1889 for (i=d;i<oldDepth;i++)
1893 if ( ((BranchObj*)(selection))->countBranches()>0)
1894 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1901 // try to select the freshly built string
1909 void MapEditor::selectUpperBranch()
1911 // Finish open lineEdits
1912 if (lineedit) finishedLineEditNoSave();
1916 if (typeid(*selection) == typeid(BranchObj))
1918 if (selection->getOrientation()==OrientRightOfCenter)
1921 if (selection->getDepth()==1)
1929 void MapEditor::selectLowerBranch()
1931 // Finish open lineEdits
1932 if (lineedit) finishedLineEditNoSave();
1936 if (typeid(*selection) == typeid(BranchObj))
1938 if (selection->getOrientation()==OrientRightOfCenter)
1941 if (selection->getDepth()==1)
1950 void MapEditor::selectLeftBranch()
1952 // Finish open lineEdits
1953 if (lineedit) finishedLineEditNoSave();
1959 if (typeid(*selection) == typeid(MapCenterObj))
1961 par= (BranchObj*) (selection);
1962 bo=par->getLastSelectedBranch();
1965 // Workaround for reselecting on left and right side
1966 if (bo->getOrientation()==OrientRightOfCenter)
1968 bo=par->getLastBranch();
1974 selection->select();
1976 ensureSelectionVisible();
1981 par=(BranchObj*)(selection->getParObj());
1982 if (selection->getOrientation()==OrientRightOfCenter)
1984 if (typeid(*selection) == typeid(BranchObj) ||
1985 typeid(*selection) == typeid(FloatImageObj))
1987 selection->unselect();
1989 selection->select();
1991 ensureSelectionVisible();
1995 if (typeid(*selection) == typeid(BranchObj) )
1997 bo=((BranchObj*)(selection))->getLastSelectedBranch();
2000 selection->unselect();
2002 selection->select();
2004 ensureSelectionVisible();
2012 void MapEditor::selectRightBranch()
2014 // Finish open lineEdits
2015 if (lineedit) finishedLineEditNoSave();
2022 if (typeid(*selection) == typeid(MapCenterObj))
2024 par= (BranchObj*) (selection);
2025 bo=par->getLastSelectedBranch();
2028 // Workaround for relecting on left and right side
2029 if (bo->getOrientation()==OrientLeftOfCenter)
2030 bo=par->getFirstBranch();
2035 selection->select();
2036 ensureSelectionVisible();
2041 par=(BranchObj*)(selection->getParObj());
2042 if (selection->getOrientation()==OrientLeftOfCenter)
2044 if (typeid(*selection) == typeid(BranchObj) ||
2045 typeid(*selection) == typeid(FloatImageObj))
2047 selection->unselect();
2049 selection->select();
2051 ensureSelectionVisible();
2055 if (typeid(*selection) == typeid(BranchObj) )
2057 bo=((BranchObj*)(selection))->getLastSelectedBranch();
2060 selection->unselect();
2062 selection->select();
2064 ensureSelectionVisible();
2072 void MapEditor::selectFirstBranch()
2074 // Finish open lineEdits
2075 if (lineedit) finishedLineEditNoSave();
2081 if (typeid(*selection) == typeid(BranchObj))
2083 bo1= (BranchObj*) (selection);
2084 par=(BranchObj*)(bo1->getParObj());
2085 bo2=par->getFirstBranch();
2089 selection->select();
2090 ensureSelectionVisible();
2097 void MapEditor::selectLastBranch()
2099 // Finish open lineEdits
2100 if (lineedit) finishedLineEditNoSave();
2106 if (typeid(*selection) == typeid(BranchObj))
2108 bo1= (BranchObj*) (selection);
2109 par=(BranchObj*)(bo1->getParObj());
2110 bo2=par->getLastBranch();
2114 selection->select();
2115 ensureSelectionVisible();
2122 void MapEditor::setColor(QColor c)
2127 void MapEditor::selectBackgroundColor()
2129 // Finish open lineEdits
2130 if (lineedit) finishedLineEditNoSave();
2132 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2133 if ( !col.isValid() ) return;
2134 setBackgroundColor( col );
2138 void MapEditor::setBackgroundColor(QColor c)
2140 mapCanvas->setBackgroundColor (c);
2143 QColor MapEditor::pickColor()
2147 if (typeid(*selection) == typeid(BranchObj) ||
2148 typeid(*selection) == typeid(MapCenterObj))
2150 BranchObj *bo=(BranchObj*)(selection);
2151 actColor=bo->getColor();
2157 void MapEditor::colorItem()
2161 if (typeid(*selection) == typeid(BranchObj) ||
2162 typeid(*selection) == typeid(MapCenterObj))
2164 saveState(selection);
2165 BranchObj *bo=(BranchObj*)(selection);
2166 bo->setColor(actColor, false); // color links, color childs
2171 void MapEditor::colorBranch()
2175 if (typeid(*selection) == typeid(BranchObj) ||
2176 typeid(*selection) == typeid(MapCenterObj))
2178 saveState(selection);
2179 BranchObj *bo=(BranchObj*)(selection);
2180 bo->setColor(actColor, true); // color links, color childs
2186 void MapEditor::toggleStandardFlag(QString f)
2190 saveState(selection);
2191 ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2195 void MapEditor::setViewCenter()
2197 // transform to CanvasView Coord:
2198 QPoint p=worldMatrix().map(movingCenter);
2199 center ( p.x(), p.y());
2203 BranchObj* MapEditor::findText (QString s, bool cs)
2206 { // Nothing found or new find process
2208 // nothing found, start again
2210 itFind=mapCenter->first();
2212 bool searching=true;
2213 bool foundNote=false;
2214 while (searching && !EOFind)
2218 // Searching in Note
2219 if (itFind->getNote().contains(s,cs))
2221 if (selection!=itFind)
2223 if (selection) ((BranchObj*)(selection))->unselect();
2225 selection->select();
2227 ensureSelectionVisible();
2229 if (textEditor->findText(s,cs))
2235 // Searching in Heading
2236 if (searching && itFind->getHeading().contains (s,cs) )
2238 if (selection) ((BranchObj*)(selection))->unselect();
2240 selection->select();
2242 ensureSelectionVisible();
2248 itFind=itFind->next();
2249 if (!itFind) EOFind=true;
2255 return (BranchObj*)(selection);
2260 void MapEditor::findReset()
2261 { // Necessary if text to find changes during a find process
2266 void MapEditor::openURL()
2270 if (typeid(*selection) == typeid(BranchObj) ||
2271 typeid(*selection) == typeid(MapCenterObj))
2273 QString url=((BranchObj*)(selection))->getURL();
2275 QProcess *proc = new QProcess( this );
2277 #if !defined(Q_OS_MACX)
2278 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2280 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2281 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2284 proc->addArgument( url);
2286 if ( !proc->start() )
2288 if (mainWindow->settingsURL() )
2294 void MapEditor::editURL()
2296 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2297 typeid(*selection) == typeid(MapCenterObj)) )
2300 QString text = QInputDialog::getText(
2301 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2302 ((BranchObj*)(selection))->getURL(), &ok, this );
2305 // user entered something and pressed OK
2306 ((BranchObj*)(selection))->setURL (text);
2308 saveState(); //FIXME undoCommand
2313 void MapEditor::editHeading2URL()
2315 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2316 typeid(*selection) == typeid(MapCenterObj)) )
2318 BranchObj *b=(BranchObj*)(selection);
2319 b->setURL (b->getHeading());
2321 saveState(); //FIXME undoCommand
2325 void MapEditor::editBugzilla2URL()
2327 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2328 typeid(*selection) == typeid(MapCenterObj)) )
2330 BranchObj *b=(BranchObj*)(selection);
2331 b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
2333 saveState(); //FIXME undoCommand
2337 void MapEditor::editVymLink()
2339 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2340 typeid(*selection) == typeid(MapCenterObj)) )
2342 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2343 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2344 fd->setCaption(tr("VYM - Link to another map"));
2345 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2346 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2350 if ( fd->exec() == QDialog::Accepted )
2351 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2353 mapCenter->reposition();
2356 saveState(); //FIXME undoCommand
2360 void MapEditor::deleteVymLink()
2362 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2363 typeid(*selection) == typeid(MapCenterObj)) )
2365 ((BranchObj*)(selection))->setVymLink ("" );
2367 mapCenter->reposition();
2370 saveState(); //FIXME undoCommand
2374 QString MapEditor::getVymLink()
2376 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2377 typeid(*selection) == typeid(MapCenterObj)) )
2379 return ((BranchObj*)(selection))->getVymLink();
2385 void MapEditor::removeBranchHere()
2387 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2389 BranchObj* bo=(BranchObj*)(selection);
2390 BranchObj* par=(BranchObj*)(bo->getParObj());
2391 if (bo->getDepth()==1)
2394 saveState(selection->getParObj()); // FIXME undoCommand
2395 QString sel=selection->getSelectString();
2397 par->removeBranchHere(bo);
2398 mapCenter->reposition();
2403 void MapEditor::removeChilds()
2405 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2407 saveState(selection->getParObj());
2408 ((BranchObj*)(selection))->removeChilds();
2409 mapCenter->reposition();
2413 void MapEditor::editMapInfo()
2415 ExtraInfoDialog dia;
2416 dia.setMapName (getFileName() );
2417 dia.setAuthor (mapCenter->getAuthor() );
2418 dia.setComment(mapCenter->getComment() );
2423 QCanvasItemList l=canvas()->allItems();
2424 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2426 stats+=QString ("%1 items on canvas\n").arg (i,6);
2433 bo=mapCenter->first();
2436 if (!bo->getNote().isEmpty() ) n++;
2437 f+= bo->countFloatImages();
2439 xl+=bo->countXLinks();
2442 stats+=QString ("%1 branches\n").arg (b-1,6);
2443 stats+=QString ("%1 xLinks \n").arg (xl,6);
2444 stats+=QString ("%1 notes\n").arg (n,6);
2445 stats+=QString ("%1 images\n").arg (f,6);
2446 dia.setStats (stats);
2448 // Finally show dialog
2449 if (dia.exec() == QDialog::Accepted)
2451 saveState(); //FIXME undoCommand
2452 mapCenter->setAuthor (dia.getAuthor() );
2453 mapCenter->setComment (dia.getComment() );
2457 void MapEditor::updateActions()
2460 if (getLinkColorHint()==HeadingColor)
2461 actionFormatLinkColorHint->setOn(true);
2463 actionFormatLinkColorHint->setOn(false);
2468 actionFormatLinkStyleLine->setOn(true);
2471 actionFormatLinkStyleParabel->setOn(true);
2474 actionFormatLinkStylePolyLine->setOn(true);
2476 case StylePolyParabel:
2477 actionFormatLinkStylePolyParabel->setOn(true);
2483 QPixmap pix( 16, 16 );
2484 pix.fill( mapCanvas->backgroundColor() );
2485 actionFormatBackColor->setIconSet( pix );
2486 pix.fill( defLinkColor );
2487 actionFormatLinkColor->setIconSet( pix );
2489 actionEditUndo->setEnabled( mapChanged );
2490 actionFileSave->setEnabled( mapUnsaved );
2494 if ( (typeid(*selection) == typeid(BranchObj)) ||
2495 (typeid(*selection) == typeid(MapCenterObj)) )
2497 BranchObj *bo=(BranchObj*)(selection);
2498 // Take care of links
2499 if (bo->countXLinks()==0)
2501 branchLinksContextMenu->clear();
2502 branchLinksContextMenu->insertItem ("No xLink available");
2503 branchLinksContextMenuDup->clear();
2504 branchLinksContextMenuDup->insertItem ("No xLink available");
2510 branchLinksContextMenu->clear();
2511 branchLinksContextMenuDup->clear();
2512 for (int i=0; i<=bo->countXLinks();i++)
2514 bot=bo->XLinkTargetAt(i);
2517 s=bot->getHeading();
2520 branchLinksContextMenu->insertItem (s);
2521 branchLinksContextMenuDup->insertItem (s);
2526 standardFlagsDefault->setEnabled (true);
2528 if ( bo->getURL().isEmpty() )
2529 actionEditOpenURL->setEnabled (false);
2531 actionEditOpenURL->setEnabled (true);
2533 if ( bo->getVymLink().isEmpty() )
2535 actionEditOpenVymLink->setEnabled (false);
2536 actionEditDeleteVymLink->setEnabled (false);
2539 actionEditOpenVymLink->setEnabled (true);
2540 actionEditDeleteVymLink->setEnabled (true);
2543 actionEditCopy->setEnabled (true);
2544 actionEditCut->setEnabled (true);
2545 if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
2546 actionEditPaste->setEnabled (true);
2548 actionEditPaste->setEnabled (false);
2549 for (a=actionListBranches.first();a;a=actionListBranches.next())
2550 a->setEnabled(true);
2551 actionEditDelete->setEnabled (true);
2552 actionEditToggleFloatExport->setEnabled (false);
2553 switch (selection->getFrameType())
2556 actionFormatFrameNone->setOn(true);
2559 actionFormatFrameRectangle->setOn(true);
2565 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2567 standardFlagsDefault->setEnabled (false);
2569 actionEditOpenURL->setEnabled (false);
2570 actionEditOpenVymLink->setEnabled (false);
2571 actionEditDeleteVymLink->setEnabled (false);
2573 actionEditCopy->setEnabled (true);
2574 actionEditCut->setEnabled (true);
2575 actionEditPaste->setEnabled (false); //FIXME
2576 for (a=actionListBranches.first();a;a=actionListBranches.next())
2577 a->setEnabled(false);
2578 actionEditDelete->setEnabled (true);
2579 actionEditToggleFloatExport->setOn
2580 ( ((FloatImageObj*)(selection))->getFloatExport() );
2585 standardFlagsDefault->setEnabled (false);
2587 actionEditCopy->setEnabled (false);
2588 actionEditCut->setEnabled (false);
2589 actionEditPaste->setEnabled (false);
2590 for (a=actionListBranches.first();a;a=actionListBranches.next())
2591 a->setEnabled(false);
2593 actionEditOpenURL->setEnabled (false);
2594 actionEditOpenVymLink->setEnabled (false);
2595 actionEditDeleteVymLink->setEnabled (false);
2596 actionEditHeading2URL->setEnabled (false);
2597 actionEditDelete->setEnabled (false);
2598 actionEditToggleFloatExport->setEnabled (false);
2602 void MapEditor::setLinkStyle (LinkStyle ls)
2606 saveState(); // FIXME undoCommand
2608 bo=mapCenter->first();
2612 bo->setLinkStyle(bo->getDefLinkStyle());
2615 mapCenter->reposition();
2618 LinkStyle MapEditor::getLinkStyle ()
2623 void MapEditor::setLinkColor(QColor c)
2629 void MapEditor::setLinkColorHint()
2631 // called from setLinkColorHint(lch) or at end of parse
2633 bo=mapCenter->first();
2641 void MapEditor::setLinkColorHint(LinkColorHint lch)
2647 void MapEditor::toggleLinkColorHint()
2649 if (linkcolorhint==HeadingColor)
2650 linkcolorhint=DefaultColor;
2652 linkcolorhint=HeadingColor;
2654 bo=mapCenter->first();
2662 LinkColorHint MapEditor::getLinkColorHint()
2664 return linkcolorhint;
2667 QColor MapEditor::getDefLinkColor()
2669 return defLinkColor;
2672 void MapEditor::setDefXLinkColor(QColor col)
2677 QColor MapEditor::getDefXLinkColor()
2679 return defXLinkColor;
2682 void MapEditor::setDefXLinkWidth (int w)
2687 int MapEditor::getDefXLinkWidth()
2689 return defXLinkWidth;
2692 void MapEditor::selectLinkColor()
2694 // Finish open lineEdits
2695 if (lineedit) finishedLineEditNoSave();
2697 QColor col = QColorDialog::getColor( defLinkColor, this );
2698 if ( !col.isValid() ) return;
2699 setLinkColor( col );
2700 saveState(); //FIXME undoCommand
2704 void MapEditor::toggleScroll()
2706 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2708 BranchObj *bo=((BranchObj*)(selection));
2709 if (bo->countBranches()==0) return;
2710 if (bo->getDepth()==0) return;
2711 saveState(selection);
2718 void MapEditor::unScrollAll()
2721 bo=mapCenter->first();
2724 if (bo->isScrolled()) bo->toggleScroll();
2729 void MapEditor::loadFloatImage ()
2732 (typeid(*selection) == typeid(BranchObj)) ||
2733 (typeid(*selection) == typeid(MapCenterObj)) )
2735 BranchObj *bo=((BranchObj*)(selection));
2737 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2738 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2739 ImagePreview *p =new ImagePreview (fd);
2740 fd->setContentsPreviewEnabled( TRUE );
2741 fd->setContentsPreview( p, p );
2742 fd->setPreviewMode( QFileDialog::Contents );
2743 fd->setCaption(tr("vym - Load image"));
2744 fd->setDir (lastImageDir);
2748 if ( fd->exec() == QDialog::Accepted )
2750 saveState(selection);
2751 QString fn=fd->selectedFile();
2752 lastImageDir=fn.left(fn.findRev ("/"));
2753 bo->addFloatImage();
2754 // FIXME check if load was successful
2755 bo->getLastFloatImage()->load(fn);
2756 bo->getLastFloatImage()->setOriginalFilename(fn);
2757 mapCenter->reposition();
2764 void MapEditor::saveFloatImage (int item)
2767 (typeid(*selection) == typeid(FloatImageObj)) )
2769 FloatImageObj *fio=((FloatImageObj*)(selection));
2770 const char* fmt = saveImageFormatMenu->text(item);
2772 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2773 fd->addFilter ("PNG (*.png)");
2774 fd->addFilter ("BMP (*.bmp)");
2775 fd->addFilter ("XBM (*.xbm)");
2776 fd->addFilter ("JPG (*.jpg)");
2777 fd->addFilter ("XPM (*.xpm)");
2778 fd->addFilter ("GIF (*.gif)");
2779 fd->addFilter ("PNM (*.pnm)");
2780 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2781 fd->setCaption(tr("vym - Save image as ") + fmt);
2782 fd->setMode( QFileDialog::AnyFile );
2783 fd->setSelection (fio->getOriginalFilename());
2787 if ( fd->exec() == QDialog::Accepted )
2789 if (QFile (fd->selectedFile()).exists() )
2791 QMessageBox mb( "VYM",
2792 tr("The file ") + fd->selectedFile() +
2793 tr(" exists already. "
2794 "Do you want to overwrite it?"),
2795 QMessageBox::Warning,
2796 QMessageBox::Yes | QMessageBox::Default,
2797 QMessageBox::Cancel | QMessageBox::Escape,
2798 QMessageBox::QMessageBox::NoButton );
2800 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2801 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2804 case QMessageBox::Yes:
2807 case QMessageBox::Cancel:
2813 fio->save (fd->selectedFile(),fmt);
2818 void MapEditor::toggleFloatExport()
2821 (typeid(*selection) == typeid(FloatImageObj))||
2822 (typeid(*selection) == typeid(FloatObj)) )
2824 FloatImageObj *fio=((FloatImageObj*)(selection));
2825 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2829 void MapEditor::setFrame(const FrameType &t)
2832 (typeid(*selection) == typeid(BranchObj)) ||
2833 (typeid(*selection) == typeid(MapCenterObj)) )
2835 selection->setFrameType (t);
2836 mapCenter->reposition();
2837 selection->updateLink();
2841 void MapEditor::importDir(BranchObj *dst, QDir d)
2844 (typeid(*selection) == typeid(BranchObj)) ||
2845 (typeid(*selection) == typeid(MapCenterObj)) )
2849 // Traverse directories
2850 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2851 const QFileInfoList *dirlist = d.entryInfoList();
2852 QFileInfoListIterator itdir( *dirlist );
2855 while ( (fi = itdir.current()) != 0 )
2857 if (fi->fileName() != "." && fi->fileName() != ".." )
2860 bo=dst->getLastBranch();
2861 bo->setHeading (fi->fileName() );
2862 bo->setColor (QColor("blue"),false);
2864 if ( !d.cd(fi->fileName()) )
2865 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2868 // Recursively add subdirs
2876 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2877 const QFileInfoList *filelist = d.entryInfoList();
2878 QFileInfoListIterator itfile( *filelist );
2880 while ( (fi = itfile.current()) != 0 )
2883 bo=dst->getLastBranch();
2884 bo->setHeading (fi->fileName() );
2885 bo->setColor (QColor("black"),false);
2886 if (fi->fileName().right(4) == ".vym" )
2887 bo->setVymLink (fi->filePath());
2894 void MapEditor::importDir()
2897 (typeid(*selection) == typeid(BranchObj)) ||
2898 (typeid(*selection) == typeid(MapCenterObj)) )
2900 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2901 fd->setMode (QFileDialog::DirectoryOnly);
2902 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2903 fd->setCaption(tr("VYM - Choose directory structur to import"));
2907 if ( fd->exec() == QDialog::Accepted )
2909 BranchObj *bo=((BranchObj*)(selection));
2910 importDir (bo,QDir(fd->selectedFile()) );
2911 mapCenter->reposition();
2918 void MapEditor::followXLink(int i)
2921 (typeid(*selection) == typeid(BranchObj)) ||
2922 (typeid(*selection) == typeid(MapCenterObj)) )
2924 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2927 selection->unselect();
2929 selection->select();
2930 ensureSelectionVisible();
2935 void MapEditor::editXLink(int i)
2938 (typeid(*selection) == typeid(BranchObj)) ||
2939 (typeid(*selection) == typeid(MapCenterObj)) )
2941 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2944 EditXLinkDialog dia;
2946 dia.setSelection(selection);
2947 if (dia.exec() == QDialog::Accepted)
2949 if (dia.useSettingsGlobal() )
2951 setDefXLinkColor (xlo->getColor() );
2952 setDefXLinkWidth (xlo->getWidth() );
2954 if (dia.deleteXLink())
2955 ((BranchObj*)(selection))->deleteXLinkAt(i);
2956 saveState(); //FIXME undoCommand
2962 void MapEditor::testFunction()
2964 cout << "MapEditor::testFunction() called\n";
2966 (typeid(*selection) == typeid(BranchObj)) )
2968 QString s=((BranchObj*)(selection))->getHeading();
2973 void MapEditor::ensureSelectionVisible()
2977 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2979 if (selection->getOrientation() == OrientLeftOfCenter)
2980 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2982 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2983 ensureVisible (p.x(), p.y() );
2988 void MapEditor::updateViewCenter()
2990 // Update movingCenter, so that we can zoom comfortably later
2991 QRect rc = QRect( contentsX(), contentsY(),
2992 visibleWidth(), visibleHeight() );
2993 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2994 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2995 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2998 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3000 // Lineedits are already closed by preceding
3001 // mouseEvent, we don't need to close here.
3003 QPoint p = inverseWorldMatrix().map(e->pos());
3004 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3007 { // MapObj was found
3008 if (selection != lmo)
3010 // select the MapObj
3011 if (selection) selection->unselect();
3013 selection->select();
3019 if (typeid(*selection)==typeid(BranchObj) ||
3020 typeid(*selection)==typeid(MapCenterObj) )
3022 // Context Menu on branch or mapcenter
3024 branchContextMenu->popup(e->globalPos() );
3026 if (typeid(*selection)==typeid(FloatImageObj))
3028 // Context Menu on floatimage
3030 floatimageContextMenu->popup(e->globalPos() );
3034 { // No MapObj found, we are on the Canvas itself
3035 // Context Menu on Canvas
3037 canvasContextMenu->popup(e->globalPos() );
3041 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3043 // Finish open lineEdits
3044 if (lineedit) finishedLineEditNoSave();
3046 QPoint p = inverseWorldMatrix().map(e->pos());
3047 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3049 // Special case: CTRL is pressed
3050 if (e->state() & QMouseEvent::ControlButton)
3052 if (actionModModeColor->isOn())
3054 if (e->state() & QMouseEvent::ControlButton)
3057 setCursor (pickColorCursor);
3061 if (actionModModeLink->isOn())
3063 BranchObj *bo_begin=NULL;
3065 bo_begin=(BranchObj*)(lmo);
3068 ((typeid(*selection) == typeid(BranchObj)) ||
3069 (typeid(*selection) == typeid(MapCenterObj))) )
3070 bo_begin=(BranchObj*)(selection);
3074 linkingObj_src=bo_begin;
3075 tmpXLink=new XLinkObj (mapCanvas);
3076 tmpXLink->setBegin (bo_begin);
3077 tmpXLink->setEnd (p);
3078 tmpXLink->setColor(defXLinkColor);
3079 tmpXLink->setWidth(defXLinkWidth);
3080 tmpXLink->updateXLink();
3081 tmpXLink->setVisibility (true);
3088 { // MapObj was found
3089 if (selection != lmo)
3091 // select the MapObj
3092 if (selection) selection->unselect();
3094 selection->select();
3099 // Check, if systemFlag clicked
3100 if (typeid(*selection)==typeid(BranchObj) ||
3101 typeid(*selection)==typeid(MapCenterObj) )
3103 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
3104 if (!foname.isEmpty())
3106 // Do not move, if systemFlag clicked
3110 if (foname=="vymLink")
3112 mainWindow->editOpenVymLink();
3113 // tabWidget may change, better return now
3114 // before segfaulting...
3118 mainWindow->windowToggleNoteEditor();
3122 // Left Button Move Branches
3123 if (e->button() == QMouseEvent::LeftButton )
3125 movingObj_start.setX( p.x() - selection->x() );
3126 movingObj_start.setY( p.y() - selection->y() );
3127 movingObj_orgPos.setX (lmo->x() );
3128 movingObj_orgPos.setY (lmo->y() );
3130 // If modMode==copy, then we want to "move" the _new_ object around
3131 // then we need the offset from p to the _old_ selection, because of tmp
3132 if (actionModModeCopy->isOn() &&
3133 e->state() & QMouseEvent::ControlButton)
3135 if (typeid(*selection)==typeid(BranchObj) )
3138 mapCenter->addBranch ((BranchObj*)(selection));
3140 selection=mapCenter->getLastBranch();
3141 selection->select();
3142 mapCenter->reposition();
3145 movingObj=selection;
3147 // Middle Button Toggle Scroll
3148 // (On Mac OS X this won't work, but we still have
3149 // a button in the toolbar)
3150 if (e->button() == QMouseEvent::MidButton )
3154 { // No MapObj found, we are on the Canvas itself
3155 // Left Button move Pos of CanvasView
3156 if (e->button() == QMouseEvent::LeftButton )
3158 movingObj=NULL; // move Content not Obj
3159 movingObj_start=e->globalPos();
3160 movingCont_start=QPoint (contentsX(), contentsY() );
3161 movingVec=QPoint(0,0);
3162 setCursor(handOpenCursor);
3167 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3169 QPoint p = inverseWorldMatrix().map(e->pos());
3171 // Move the selected MapObj
3172 if ( selection && movingObj)
3174 ensureVisible (p.x(),p.y());
3176 // Now move the selection, but add relative position
3177 // (movingObj_start) where selection was chosen with
3178 // mousepointer. (This avoids flickering resp. jumping
3179 // of selection back to absPos)
3181 LinkableMapObj *lmosel;
3182 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3184 // Check if we could link
3185 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3188 if (typeid(*selection) == typeid(FloatImageObj))
3190 FloatObj *fo=(FloatObj*)(selection);
3191 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3192 if (fo->getLinkStyle()==StyleUndef)
3194 fo->setLinkStyle(fo->getDefLinkStyle());
3195 fo->setLinkColor(fo->getParObj()->getLinkColor());
3197 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3201 // Relink float to new mapcenter or branch, if shift is pressed
3202 // Only relink, if selection really has a new parent
3203 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3204 ( (typeid(*lmo)==typeid(BranchObj)) ||
3205 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3206 ( lmo != fo->getParObj())
3209 if (typeid(*fo) == typeid(FloatImageObj))
3212 FloatImageObj *fio=(FloatImageObj*)(fo);
3213 ((BranchObj*)(lmo))->addFloatImage (fio);
3215 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3216 fio=((BranchObj*)(lmo))->getLastFloatImage();
3219 selection=(LinkableMapObj*)(fio);
3220 selection->select();
3221 movingObj=(MapObj*)(fio);
3222 // setLinkStyle calls updateLink, only set it once
3223 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3224 fio->setLinkStyle (fio->getDefLinkStyle());
3226 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3228 } else // selection != a FloatObj
3230 if (lmosel->getDepth()==0)
3232 if (e->state() == (LeftButton | !ShiftButton))
3233 // If mapCenter is moved, move all the rest by default, too.
3234 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3236 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3239 if (lmosel->getDepth()==1)
3241 // depth==1, mainbranch
3242 saveState("move "+qpointToString(movingObj_orgPos), lmosel->getSelectString() );
3243 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3247 if (lmosel->getOrientation() == OrientLeftOfCenter)
3248 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3249 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3250 p.y()-movingObj_start.y() );
3252 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3254 // reposition subbranch
3255 lmosel->reposition();
3256 //ensureSelectionVisible();
3258 if (lmo && (lmo!=selection) &&
3259 (typeid(*lmo) == typeid(BranchObj) ||
3260 (typeid(*lmo) == typeid(MapCenterObj) )
3263 if (e->state() & QMouseEvent::ControlButton)
3265 // Special case: CTRL to link below lmo
3266 lmosel->setParObjTmp (lmo,p,+1);
3268 else if (e->state() & QMouseEvent::ShiftButton)
3269 lmosel->setParObjTmp (lmo,p,-1);
3271 lmosel->setParObjTmp (lmo,p,0);
3274 lmosel->unsetParObjTmp();
3276 if (lmo &&(lmo==selection))
3277 // Could link to myself (happens sometimes...)
3278 lmosel->unsetParObjTmp();
3280 // no Obj under selection, go back to original Parent
3281 lmosel->unsetParObjTmp();
3286 } // no FloatImageObj
3290 } // selection && moving_obj
3292 // Draw a link from one branch to another
3295 tmpXLink->setEnd (p);
3296 tmpXLink->updateXLink();
3300 if (!movingObj && !pickingColor &&!drawingLink)
3302 QPoint p=e->globalPos();
3303 movingVec.setX(-p.x() + movingObj_start.x() );
3304 movingVec.setY(-p.y() + movingObj_start.y() );
3305 setContentsPos( movingCont_start.x() + movingVec.x(),
3306 movingCont_start.y() + movingVec.y());
3313 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3315 LinkableMapObj *dst;
3316 // Have we been picking color?
3320 setCursor (ArrowCursor);
3321 // Check if we are over another branch
3322 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3323 if (dst && selection)
3325 if (e->state() & QMouseEvent::ShiftButton)
3327 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3328 ((BranchObj*)(selection))->setLinkColor ();
3332 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3333 ((BranchObj*)(selection))->setLinkColor ();
3339 // Have we been drawing a link?
3343 // Check if we are over another branch
3344 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3345 if (dst && selection)
3347 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3348 tmpXLink->updateXLink();
3349 tmpXLink->activate();
3350 saveState(); //FIXME undoCommand
3359 // Have we been moving something?
3360 if ( selection && movingObj )
3362 // Check if we are over another branch, but ignore
3363 // any found LMOs, which are FloatObjs
3364 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3365 ((LinkableMapObj*)(selection)) );
3368 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3373 // Now check, if we have been moving a branch
3374 if (typeid(*selection) == typeid(BranchObj) )
3376 // save the position in case we link to mapcenter
3377 QPoint savePos=QPoint (selection->x(),selection->y() );
3379 // Reset the temporary drawn link to the original one
3380 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3386 BranchObj* bs=((BranchObj*)(selection));
3387 QString undoCom="linkBranchToPos (\""+
3388 (bs->getParObj())->getSelectString()+
3390 QString("%1").arg(bs->getNum())+
3392 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3394 // TODO we also could check, if dest and src are on same branch,
3395 // then it would be sufficient to saveState of this branch
3397 // Modifiers allow to insert above/below dst
3398 if (e->state() & QMouseEvent::ShiftButton)
3400 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3402 if (e->state() & QMouseEvent::ControlButton)
3404 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3407 bs->moveBranchTo ((BranchObj*)(dst),-1);
3408 if (dst->getDepth()==0)
3411 saveState (undoCom,bs->getSelectString() );
3413 // Draw the original link, before selection was moved around
3414 mapCenter->reposition();
3416 // Finally resize canvas, if needed
3421 // maybe we moved View: set old cursor
3422 setCursor (ArrowCursor);
3426 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3428 // Finish open lineEdits
3429 if (lineedit) finishedLineEditNoSave();
3431 if (e->button() == QMouseEvent::LeftButton )
3433 QPoint p = inverseWorldMatrix().map(e->pos());
3434 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3435 if (lmo) { // MapObj was found
3436 // First select the MapObj than edit heading
3437 if (selection) selection->unselect();
3439 selection->select();
3440 saveState(selection);
3446 void MapEditor::resizeEvent (QResizeEvent* e)
3448 QCanvasView::resizeEvent( e );
3451 if (!fileName.isEmpty()) s=fileName;
3455 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3458 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3459 // cerr << event->format(i) << endl;
3462 (typeid(*selection) == typeid(BranchObj)) ||
3463 (typeid(*selection) == typeid(MapCenterObj))) {
3465 // If QImageDrag can decode mime type
3466 if (QImageDrag::canDecode(event)) {
3471 // If image are dragged from firefox
3472 if (event->provides("application/x-moz-file-promise-url") &&
3473 event->provides("application/x-moz-nativeimage")) {
3474 event->accept(true);
3478 // If QUriDrag can decode mime type
3479 if (QUriDrag::canDecode(event)) {
3484 // If Uri are dragged from firefox
3485 if (event->provides("_NETSCAPE_URL")){
3490 // If QTextDrag can decode mime type
3491 if (QTextDrag::canDecode(event)) {
3500 bool isUnicode16(const QByteArray &d)
3502 // FIXME: make more precise check for unicode 16.
3503 // Guess unicode16 if any of second bytes are zero
3504 unsigned int length = max(0,d.size()-2)/2;
3505 for (unsigned int i = 0; i<length ; i++)
3506 if (d.at(i*2+1)==0) return true;
3510 void MapEditor::contentsDropEvent(QDropEvent *event)
3513 (typeid(*selection) == typeid(BranchObj)) ||
3514 (typeid(*selection) == typeid(MapCenterObj)))
3519 if (event->provides("image/png"))
3522 if (QImageDrag::decode(event, pix))
3530 } else if (event->provides("application/x-moz-file-promise-url") &&
3531 event->provides("application/x-moz-nativeimage"))
3533 // Contains url to the img src in unicode16
3534 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3535 QString url = QString((const QChar*)d.data(),d.size()/2);
3539 } else if (event->provides ("text/uri-list"))
3540 { // Uris provided e.g. by konqueror
3541 QUriDrag::decode (event,uris);
3542 } else if (event->provides ("_NETSCAPE_URL"))
3543 { // Uris provided by Mozilla
3544 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3547 } else if (event->provides("text/html")) {
3549 // Handels text mime types
3550 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3551 QByteArray d = event->encodedData("text/html");
3554 text = QString((const QChar*)d.data(),d.size()/2);
3558 textEditor->setText(text);
3562 } else if (event->provides("text/plain")) {
3563 QByteArray d = event->encodedData("text/plain");
3566 text = QString((const QChar*)d.data(),d.size()/2);
3570 textEditor->setText(text);
3582 for (const char* u=uris.first(); u; u=uris.next())
3584 bo=((BranchObj*)(selection))->addBranch();
3587 s=QUriDrag::uriToLocalFile(u);
3589 QString file = QDir::convertSeparators(s);
3590 heading = QFileInfo(file).baseName();
3592 if (file.endsWith(".vym", false))
3593 bo->setVymLink(file);
3602 bo->setHeading(heading);
3612 saveState(); //FIXME undo Command
3613 mapCenter->reposition();
3620 void MapEditor::addFloatImage(const QPixmap &img)
3623 (typeid(*selection) == typeid(BranchObj)) ||
3624 (typeid(*selection) == typeid(MapCenterObj)) )
3626 BranchObj *bo=((BranchObj*)(selection));
3627 saveState(selection);
3628 //QString fn=fd->selectedFile();
3629 //lastImageDir=fn.left(fn.findRev ("/"));
3630 bo->addFloatImage();
3631 // FIXME check if load was successful
3632 bo->getLastFloatImage()->load(img);
3633 //bo->getLastFloatImage()->setOriginalFilename(fn);
3634 mapCenter->reposition();
3641 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3643 if (!imageBuffer) imageBuffer = new QBuffer();
3644 if (!imageBuffer->isOpen()) {
3645 imageBuffer->open(IO_WriteOnly | IO_Append);
3647 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3651 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3653 if (nop->state()==QNetworkProtocol::StDone) {
3654 QPixmap img(imageBuffer->buffer());
3659 imageBuffer->close();
3661 imageBuffer->close();
3668 void MapEditor::fetchImage(const QString &url)
3671 urlOperator->stop();
3672 disconnect(urlOperator);
3676 urlOperator = new QUrlOperator(url);
3677 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3678 this, SLOT(imageDataFinished(QNetworkOperation*)));
3680 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3681 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));