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>
30 #include "texteditor.h"
31 #include "linkablemapobj.h"
34 #include "mainwindow.h"
35 #include "extrainfodialog.h"
36 #include "editxlinkdialog.h"
39 #include "icons/flag-note.xpm"
40 #include "icons/flag-url.xpm"
41 #include "icons/flag-vymlink.xpm"
42 #include "icons/flag-scrolled-right.xpm"
43 #include "icons/flag-tmpUnscrolled-right.xpm"
44 #include "icons/flag-questionmark.xpm"
45 #include "icons/flag-exclamationmark.xpm"
46 #include "icons/flag-hook-green.xpm"
47 #include "icons/flag-cross-red.xpm"
48 #include "icons/flag-stopsign.xpm"
49 #include "icons/flag-smiley-good.xpm"
50 #include "icons/flag-smiley-sad.xpm"
51 #include "icons/flag-clock.xpm"
52 #include "icons/flag-lamp.xpm"
53 #include "icons/flag-arrow-up.xpm"
54 #include "icons/flag-arrow-down.xpm"
55 #include "icons/flag-thumb-up.xpm"
56 #include "icons/flag-thumb-down.xpm"
57 #include "icons/flag-heart.xpm"
58 #include "icons/flag-flash.xpm"
59 #include "icons/flag-lifebelt.xpm"
61 extern TextEditor *textEditor;
62 extern int statusbarTime;
63 extern Main *mainWindow;
64 extern FlagRowObj *systemFlagsDefault;
65 extern FlagRowObj *standardFlagsDefault;
66 extern MapEditor *clipboardME;
68 extern QPtrList <QAction> actionListBranches;
70 extern QAction *actionFileSave;
71 extern QAction *actionEditUndo;
72 extern QAction *actionEditCopy;
73 extern QAction *actionEditCut;
74 extern QAction *actionEditPaste;
75 extern QAction *actionEditMoveUp;
76 extern QAction *actionEditMoveDown;
77 extern QAction *actionEditToggleScroll;
78 extern QAction *actionEditOpenURL;
79 extern QAction *actionEditURL;
80 extern QAction *actionEditHeading2URL;
81 extern QAction *actionEditBugzilla2URL;
82 extern QAction *actionEditOpenVymLink;
83 extern QAction *actionEditVymLink;
84 extern QAction *actionEditDeleteVymLink;
85 extern QAction *actionEditHeading;
86 extern QAction *actionEditDelete;
87 extern QAction *actionEditAddBranch;
88 extern QAction *actionEditAddBranchAbove;
89 extern QAction *actionEditAddBranchBelow;
90 extern QAction *actionEditRemoveBranchHere;
91 extern QAction *actionEditRemoveChilds;
92 extern QAction *actionEditImportAdd;
93 extern QAction *actionEditImportReplace;
94 extern QAction *actionEditSaveBranch;
95 extern QAction *actionEditSelectFirst;
96 extern QAction *actionEditSelectLast;
97 extern QAction *actionEditLoadImage;
98 extern QAction *actionEditToggleFloatExport;
100 extern QAction* actionFormatPickColor;
101 extern QAction* actionFormatColorBranch;
102 extern QAction* actionFormatColorSubtree;
103 extern QAction *actionFormatLinkColorHint;
104 extern QAction *actionFormatBackColor;
105 extern QAction *actionFormatLinkColor;
107 extern QActionGroup* actionGroupModModes;
108 extern QAction* actionModModeColor;
109 extern QAction* actionModModeLink;
110 extern QAction* actionModModeCopy;
112 extern QActionGroup *actionGroupFormatFrameTypes;
113 extern QAction *actionFormatFrameNone;
114 extern QAction *actionFormatFrameRectangle;
116 extern QActionGroup *actionGroupFormatLinkStyles;
117 extern QAction *actionFormatLinkStyleLine;
118 extern QAction *actionFormatLinkStyleParabel;
119 extern QAction *actionFormatLinkStylePolyLine;
120 extern QAction *actionFormatLinkStylePolyParabel;
122 extern QAction *actionViewToggleNoteEditor;
124 extern QAction *actionSettingsAutoedit;
125 extern QAction *actionSettingsAutoselectHeading;
126 extern QAction *actionSettingsAutoselectText;
127 extern QAction *actionSettingsPasteNewHeading;
128 extern QAction *actionSettingsUseFlagGroups;
130 extern QPopupMenu *branchContextMenu;
131 extern QPopupMenu *branchLinksContextMenu;
132 extern QPopupMenu *branchLinksContextMenuDup;
133 extern QPopupMenu *floatimageContextMenu;
134 extern QPopupMenu *saveImageFormatMenu;
135 extern QPopupMenu *exportImageFormatMenu;
136 extern QPopupMenu *canvasContextMenu;
138 extern Settings settings;
141 ///////////////////////////////////////////////////////////////////////
142 ///////////////////////////////////////////////////////////////////////
143 MapEditor::MapEditor(
144 QWidget* parent, bool interactive, const char* name, WFlags f) :
145 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
147 //cout << "Constructor ME "<<this<<endl;
149 viewport()->setAcceptDrops(true);
151 mapCanvas = new QCanvas(1000,800);
152 mapCanvas->setAdvancePeriod(30);
154 setCanvas (mapCanvas);
156 setVScrollBarMode ( QScrollView::AlwaysOn );
157 setHScrollBarMode ( QScrollView::AlwaysOn );
159 // Now create the _global_ system flags _once_:
160 // (Later all OrnamentedObj copy from this
161 // and set their own canvas)
162 if (!systemFlagsDefault)
164 systemFlagsDefault = new FlagRowObj (mapCanvas);
165 systemFlagsDefault->setVisibility (false);
166 systemFlagsDefault->setName ("systemFlagsDef");
168 FlagObj *fo = new FlagObj (mapCanvas);
169 fo->load(QPixmap(flag_note_xpm));
171 fo->setToolTip(tr("Note","Systemflag"));
172 systemFlagsDefault->addFlag (fo); // makes deep copy
174 fo->load(QPixmap(flag_url_xpm));
176 fo->setToolTip(tr("WWW Document (external)","Systemflag"));
177 systemFlagsDefault->addFlag (fo);
179 fo->load(QPixmap(flag_vymlink_xpm));
180 fo->setName("vymLink");
181 fo->setToolTip(tr("Link to another vym map","Systemflag"));
182 systemFlagsDefault->addFlag (fo);
184 fo->load(QPixmap(flag_scrolled_right_xpm));
185 fo->setName("scrolledright");
186 fo->setToolTip(tr("subtree is scrolled","Systemflag"));
187 systemFlagsDefault->addFlag (fo);
189 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
190 fo->setName("tmpUnscrolledright");
191 fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
192 systemFlagsDefault->addFlag (fo);
195 if (!standardFlagsDefault)
197 standardFlagsDefault = new FlagRowObj (mapCanvas);
198 standardFlagsDefault->setVisibility (false);
199 standardFlagsDefault->setName ("standardFlagsDef");
201 FlagObj *fo = new FlagObj (mapCanvas);
202 fo->load(QPixmap(flag_exclamationmark_xpm));
203 fo->setName ("exclamationmark");
204 fo->setGroup("standard-mark");
205 fo->setToolTip(tr("Take care!","Standardflag"));
206 standardFlagsDefault->addFlag (fo); // makes deep copy
208 fo->load(QPixmap(flag_questionmark_xpm));
209 fo->setName("questionmark");
210 fo->setGroup("standard-mark");
211 fo->setToolTip(tr("Really?","Standardflag"));
212 standardFlagsDefault->addFlag (fo);
214 fo->load(QPixmap(flag_hook_green_xpm));
215 fo->setName("hook-green");
216 fo->setGroup("standard-hook");
217 fo->setToolTip(tr("ok!","Standardflag"));
218 standardFlagsDefault->addFlag (fo);
220 fo->load(QPixmap(flag_cross_red_xpm));
221 fo->setName("cross-red");
222 fo->setGroup("standard-hook");
223 fo->setToolTip(tr("Not ok!","Standardflag"));
224 standardFlagsDefault->addFlag (fo);
226 fo->load(QPixmap(flag_stopsign_xpm));
227 fo->setName("stopsign");
228 fo->setToolTip(tr("This won't work!","Standardflag"));
229 standardFlagsDefault->addFlag (fo);
231 fo->load(QPixmap(flag_smiley_good_xpm));
232 fo->setName("smiley-good");
233 fo->setGroup("standard-smiley");
234 fo->setToolTip(tr("Good","Standardflag"));
235 standardFlagsDefault->addFlag (fo);
237 fo->load(QPixmap(flag_smiley_sad_xpm));
238 fo->setName("smiley-sad");
239 fo->setGroup("standard-smiley");
240 fo->setToolTip(tr("Bad","Standardflag"));
241 standardFlagsDefault->addFlag (fo);
243 fo->load(QPixmap(flag_clock_xpm));
244 fo->setName("clock");
245 fo->setToolTip(tr("Time critical","Standardflag"));
246 standardFlagsDefault->addFlag (fo);
248 fo->load(QPixmap(flag_lamp_xpm));
250 fo->setToolTip(tr("Idea!","Standardflag"));
251 standardFlagsDefault->addFlag (fo);
253 fo->load(QPixmap(flag_arrow_up_xpm));
254 fo->setName("arrow-up");
255 fo->setGroup("standard-arrow");
256 fo->setToolTip(tr("Important","Standardflag"));
257 standardFlagsDefault->addFlag (fo);
259 fo->load(QPixmap(flag_arrow_down_xpm));
260 fo->setName("arrow-down");
261 fo->setGroup("standard-arrow");
262 fo->setToolTip(tr("Unimportant","Standardflag"));
263 standardFlagsDefault->addFlag (fo);
265 fo->load(QPixmap(flag_thumb_up_xpm));
266 fo->setName("thumb-up");
267 fo->setGroup("standard-thumb");
268 fo->setToolTip(tr("I like this","Standardflag"));
269 standardFlagsDefault->addFlag (fo);
271 fo->load(QPixmap(flag_thumb_down_xpm));
272 fo->setName("thumb-down");
273 fo->setGroup("standard-thumb");
274 fo->setToolTip(tr("I like this","Standardflag"));
275 fo->setToolTip(tr("I do not like this","Standardflag"));
276 standardFlagsDefault->addFlag (fo);
278 fo->load(QPixmap(flag_heart_xpm));
279 fo->setName("heart");
280 fo->setToolTip(tr("I just love... ","Standardflag"));
281 standardFlagsDefault->addFlag (fo);
283 fo->load(QPixmap(flag_flash_xpm));
284 fo->setName("flash");
285 fo->setToolTip(tr("Dangerous","Standardflag"));
286 standardFlagsDefault->addFlag (fo);
288 fo->load(QPixmap(flag_lifebelt_xpm));
289 fo->setName("lifebelt");
290 fo->setToolTip(tr("This will help","Standardflag"));
291 standardFlagsDefault->addFlag (fo);
296 mapCenter = new MapCenterObj(mapCanvas);
297 mapCenter->setVisibility (true);
298 mapCenter->setMapEditor (this);
299 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
303 lineedit = new QLineEdit(this, "lineedit" );
304 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
307 actColor=black; setColor (actColor);
308 defLinkColor=QColor (0,0,255);
309 defXLinkColor=QColor (180,180,180);
310 linkcolorhint=DefaultColor;
311 linkstyle=StylePolyParabel;
312 mapCanvas->setBackgroundColor (white);
314 // Create bitmap cursors, patform dependant
315 #if defined(Q_OS_MACX)
316 #include "icons/cursorhandopen16.xpm"
317 #include "icons/cursorcolorpicker16.xpm"
318 QBitmap cb( 16, 16, chandopen, TRUE );
319 QBitmap cm( 16, 16, chandopenmask, TRUE );
320 handOpenCursor=QCursor ( cb, cm );
321 // set hot spot to tip of picker
322 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
324 #include "icons/cursorhandopen.xpm"
325 #include "icons/cursorcolorpicker.xpm"
327 QBitmap cb( 32, 32, chandopen, TRUE );
328 QBitmap cm( 32, 32, chandopenmask, TRUE );
329 handOpenCursor=QCursor ( cb, cm );
330 // set hot spot to tip of picker
331 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
344 defXLinkColor=QColor (230,230,230);
355 // Initialize find routine
362 blockreposition=false;
363 isInteractive=interactive;
365 // Create temporary files
368 // Initially set movingCentre
371 mapCenter->reposition(); // for positioning heading
374 MapEditor::~MapEditor()
376 if (imageBuffer) delete imageBuffer;
382 //cout <<"Destructor MapEditor\n";
383 if (isInteractive) delTmpDirs();
386 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
390 QColor MapEditor::color()
395 QColor MapEditor::backgroundColor()
397 return mapCanvas->backgroundColor();
400 MapCenterObj* MapEditor::getMapCenter()
405 QCanvas* MapEditor::getCanvas()
410 void MapEditor::adjustCanvasSize()
412 // To adjust the canvas to map, viewport size and position, we have to
413 // do some coordinate magic...
415 // Get rectangle of (scroll-)view.
416 // We want to be in canvas coords, so
417 // we map. Important if view is zoomed...
418 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
419 visibleWidth(), visibleHeight()) );
421 // Now we need the bounding box of view AND map to calc the correct canvas size.
422 // Why? Because if the map itself is moved out of view, the view has to be enlarged
423 // to avoid jumping aroung...
424 QRect map=mapCenter->getTotalBBox();
426 // right edge - left edge
427 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
428 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
431 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
432 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
435 // move the map on canvas (in order to not move it on screen) this is neccessary
436 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
437 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
438 // to scroll to an empty area of canvas to the left.
439 // b) if topleft corner of map left of or above topleft of canvas
443 if (cw > mapCanvas->width() )
445 if (map.x()<0) dx=-map.x();
447 if (cw < mapCanvas->width() )
448 dx=-min (view.x(),map.x());
449 if (ch > mapCanvas->height() )
451 if (map.y()<0) dy=-map.y();
453 if (ch < mapCanvas->height() )
455 dy=-min (view.y(),map.y());
457 // We really have to resize now. Let's go...
458 mapCanvas->resize (cw,ch);
459 if ( (dx!=0) || (dy!=0) )
461 mapCenter->moveAllBy(dx,dy);
462 mapCenter->reposition();
464 // scroll the view (in order to not move map on screen)
470 bool MapEditor::blockReposition()
472 return blockreposition;
475 void MapEditor::makeTmpDirs()
477 // Create unique temporary directories
478 char tmpdir[]="/tmp/vym-XXXXXX";
479 bakMapDir=mkdtemp(tmpdir);
480 makeSubDirs(bakMapDir);
481 // FIXME set permissions and maybe use QT method for portability
484 void MapEditor::delTmpDirs()
486 //FIXME delete tmp directory, better use QT methods here:
487 system ( "rm -rf "+ bakMapDir );
491 void MapEditor::makeSubDirs(const QString &s)
499 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
501 // tmpdir temporary directory to which data will be writte
502 // prefix mapname, which will be appended to images etc.
503 // writeflags Only write flags for "real" save of map, not undo
504 // offset offset of bbox of whole map in canvas.
505 // Needed for XML export
506 // completeMap if false, only vympart will be written, without
523 ls="StylePolyParabel";
527 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
529 if (linkcolorhint==HeadingColor)
530 colhint=attribut("linkColorHint","HeadingColor");
532 QString mapAttr=attribut("version",__VYM_VERSION__);
534 mapAttr+= attribut("author",mapCenter->getAuthor()) +
535 attribut("comment",mapCenter->getComment()) +
536 attribut("date",mapCenter->getDate()) +
537 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
538 attribut("linkStyle", ls ) +
539 attribut("linkColor", defLinkColor.name() ) +
540 attribut("defXLinkColor", defXLinkColor.name() ) +
541 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
543 s+=beginElement("vymmap",mapAttr);
546 // Find the used flags while traversing the tree
547 standardFlagsDefault->resetUsedCounter();
549 // Build xml recursivly
551 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
554 if ( typeid(*saveSelection) == typeid(BranchObj) )
555 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
557 if (selection && typeid(*selection)==typeid(BranchObj))
558 // This is used if selected branch is saved from mainwindow
559 s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
562 // Save local settings
563 s+=settings.getXMLData (destPath);
566 if (selection && !saveSelection)
567 s+=valueElement("select",selection->getSelectString());
570 s+=endElement("vymmap");
573 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
577 void MapEditor::saveState()
579 <<<<<<< mapeditor.cpp
580 saveState (CompleteMap,NULL,"");
582 saveState (CompleteMap,NULL,"");
585 void MapEditor::saveState(LinkableMapObj *undoSel)
587 saveState (PartOfMap,undoSel,"");
591 <<<<<<< mapeditor.cpp
592 void MapEditor::saveState(LinkableMapObj *undoSel)
594 void MapEditor::saveState(const QString & c)
597 <<<<<<< mapeditor.cpp
598 saveState (PartOfMap,undoSel,"");
601 saveState (UndoCommand,NULL,c);
605 <<<<<<< mapeditor.cpp
606 void MapEditor::saveState(const QString & c)
608 saveState (UndoCommand,NULL,c);
611 void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom)
613 if (savemode==UndoCommand)
618 else if (savemode==PartOfMap && undoSel)
620 void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom)
622 if (savemode==UndoCommand)
625 <<<<<<< mapeditor.cpp
626 undoCommand="undoPart (\""+undoSel->getSelectString()+"\")";
627 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
630 undoCommand="undoMap ()";
631 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
634 cout << "ME::saveState()\n";
635 cout << " undoCom="<<undoCommand<<endl;
639 void MapEditor::parseAtom(const QString &s)
643 api.parseCommand (s,c,p);
646 cout <<"ME::parseAtom s="<<s<<endl;
647 cout <<"ME::parseAtom c="<<c<<endl;
648 cout <<"ME::parseAtom p="<<p<<endl;
652 if (c==QString("moveBranchUp"))
654 else if (c=="moveBranchDown")
656 else if (c=="setHeading")
658 // Internal commands, used for undo etc.
659 else if (c==QString("undoMap"))
661 else if (c==QString("undoPart"))
663 else if (c=="select")
670 else if (savemode==PartOfMap && undoSel)
672 undoCommand="undoPart (\""+undoSel->getSelectString()+"\")";
673 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
676 undoCommand="undoMap ()";
677 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
680 cout << "ME::saveState()\n";
681 cout << " undoCom="<<undoCommand<<endl;
685 void MapEditor::parseAtom(const QString &s)
689 api.parseCommand (s,c,p);
692 cout <<"ME::parseAtom s="<<s<<endl;
693 cout <<"ME::parseAtom c="<<c<<endl;
694 cout <<"ME::parseAtom p="<<p<<endl;
698 if (c==QString("moveBranchUp"))
700 else if (c=="moveBranchDown")
702 else if (c=="setHeading")
704 // Internal commands, used for undo etc.
705 else if (c==QString("undoMap"))
707 else if (c==QString("undoPart"))
709 else if (c=="select")
714 cout << "MapEditor::parseAtom: Error!\n";
715 cout << " Command unknown: \""<<c<<"\""<<endl;
716 cout << " Used in atom: \""<<s<<"\""<<endl;
721 void MapEditor::finishedLineEditNoSave()
723 // This is called by finishedLineEdit or any MapEditor method,
724 // which wants to assure, that lineedits finish, before e.g. a branch is
727 // After calling LineEdit and using the clipboard, the
728 // focus is not any longer on the main widget, we
729 // have to restore it using parentWidget()->setFocus()
733 editingBO->setHeading(lineedit->text() );
735 lineedit->releaseKeyboard();
737 parentWidget()->setFocus();
738 mapCenter->reposition();
740 ensureSelectionVisible();
745 bool MapEditor::isDefault()
750 bool MapEditor::isUnsaved()
755 bool MapEditor::hasChanged()
760 void MapEditor::setChanged()
765 actionEditUndo->setEnabled (true);
766 actionFileSave->setEnabled (true);
770 void MapEditor::closeMap()
772 // Finish open lineEdits
773 if (lineedit) finishedLineEditNoSave();
775 // Unselect before disabling the toolbar actions
776 if (selection) selection->unselect();
784 void MapEditor::setFilePath(QString fname)
786 setFilePath (fname,fname);
789 void MapEditor::setFilePath(QString fname, QString destname)
798 filePath=fname; // becomes absolute path
799 fileName=fname; // gets stripped of path
800 destPath=destname; // needed for vymlinks
802 // If fname is not an absolute path, complete it
803 filePath=QDir(fname).absPath();
804 fileDir=filePath.left (1+filePath.findRev ("/"));
806 // Set short name, too. Search from behind:
807 int i=fileName.findRev("/");
808 if (i>=0) fileName=fileName.remove (0,i+1);
810 // Forget the .vym (or .xml) for name of map
811 mapName=fileName.left(fileName.findRev(".",-1,true) );
815 QString MapEditor::getFilePath()
820 QString MapEditor::getFileName()
825 QString MapEditor::getMapName()
830 QString MapEditor::getDestPath()
835 int MapEditor::load (QString &fname, const LoadMode &lmode)
837 // Finish open lineEdits
838 if (lineedit) finishedLineEditNoSave();
844 if (selection) selection->unselect();
847 mapCenter->setMapEditor(this);
848 // (map state is set later at end of load...)
852 saveState(selection);
856 mapBuilderHandler handler;
859 // I am paranoid: file should exist anyway
860 // according to check in mainwindow.
863 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
864 tr("Couldn't open map " +fname)+".");
868 blockreposition=true;
869 QXmlInputSource source( file);
870 QXmlSimpleReader reader;
871 reader.setContentHandler( &handler );
872 reader.setErrorHandler( &handler );
873 handler.setMapEditor( this );
874 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
875 handler.setLoadMode (lmode);
876 bool ok = reader.parse( source );
877 blockreposition=false;
881 mapCenter->reposition();
891 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
892 tr( handler.errorProtocol() ) );
894 // Still return "success": the map maybe at least
895 // partially read by the parser
902 int MapEditor::save (const SaveMode &savemode)
904 // Finish open lineEdits
905 if (lineedit) finishedLineEditNoSave();
909 // The SaveMode UndoCommand is not supported here
910 if (savemode==UndoCommand) return 1;
912 // Create mapName and fileDir
913 makeSubDirs (fileDir);
917 fname=mapName+".xml";
919 // use name given by user, even if he chooses .doc
923 // Check if fname is writeable
924 QFile file( fileDir+fname);
925 if (!file.open( IO_WriteOnly ) )
927 QMessageBox::critical( 0, tr( "Critical Save Error" ),
928 tr("Couldn't write to ") +fileDir+fname);
934 if (savemode==CompleteMap || selection==NULL)
935 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
937 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
939 file.setName ( fileDir + fname);
940 if ( !file.open( IO_WriteOnly ) )
942 // This should neverever happen
943 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
947 // Write it finally, and write in UTF8, no matter what
948 QTextStream ts( &file );
949 ts.setEncoding (QTextStream::UnicodeUTF8);
957 actionFileSave->setEnabled(false);
963 void MapEditor::setZipped (bool z)
968 bool MapEditor::saveZipped ()
973 void MapEditor::print()
975 // Finish open lineEdits
976 if (lineedit) finishedLineEditNoSave();
980 printer = new QPrinter;
981 printer->setColorMode (QPrinter::Color);
982 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
985 QRect totalBBox=mapCenter->getTotalBBox();
987 // Try to set orientation automagically
988 // Note: Interpretation of generated postscript is amibiguous, if
989 // there are problems with landscape mode, see
990 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
992 if (totalBBox.width()>totalBBox.height())
993 // recommend landscape
994 printer->setOrientation (QPrinter::Landscape);
996 // recommend portrait
997 printer->setOrientation (QPrinter::Portrait);
999 if ( printer->setup(this) )
1000 // returns false, if printing is canceled
1002 QPainter pp(printer);
1004 // Don't print the visualisation of selection
1005 LinkableMapObj *oldselection=NULL;
1008 oldselection=selection;
1009 selection->unselect();
1012 // Handle sizes of map and paper:
1014 // setWindow defines which part of the canvas will be transformed
1015 // setViewport defines area on paper in device coordinates (dpi)
1016 // e.g. (0,50,700,700) is upper part on A4
1017 // see also /usr/lib/qt3/doc/html/coordsys.html
1019 QPaintDeviceMetrics metrics (printer);
1021 double paperAspect = (double)metrics.width() / (double)metrics.height();
1022 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1024 QRect mapRect=totalBBox;
1025 QCanvasRectangle *frame=NULL;
1026 QCanvasText *footerFN=NULL;
1027 QCanvasText *footerDate=NULL;
1028 if (printFrame || printFooter)
1033 // Print frame around map
1034 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1035 totalBBox.width()+20, totalBBox.height()+20);
1036 frame=new QCanvasRectangle (mapRect,mapCanvas);
1037 frame->setBrush (QColor(white));
1038 frame->setPen (QColor(black));
1043 QCanvasLine *l=new QCanvasLine (mapCanvas);
1044 l->setPoints (0,0,mapRect.width(),mapRect.height());
1045 l->setPen (QPen(QColor(black), 1));
1052 // Print footer below map
1054 font.setPointSize(10);
1055 footerFN=new QCanvasText (mapCanvas);
1056 footerFN->setText ("VYM - " + fileName);
1057 footerFN->setFont(font);
1058 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1059 footerFN->setZ(Z_TEXT);
1061 footerDate=new QCanvasText (mapCanvas);
1062 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1063 footerDate->setFont(font);
1064 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1065 footerDate->setZ(Z_TEXT);
1068 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1071 pp.setWindow (mapRect);
1074 if (mapAspect>=paperAspect)
1076 // Fit horizontally to paper width
1077 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1080 // Fit vertically to paper height
1081 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1084 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1086 // Delete Frame and footer
1090 delete (footerDate);
1092 if (frame) delete (frame);
1094 // Restore selection
1097 selection=oldselection;
1098 selection->select();
1101 // Save settings in vymrc
1102 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1106 QPixmap MapEditor::getPixmap()
1108 QRect mapRect=mapCenter->getTotalBBox();
1109 QPixmap pix (mapRect.size());
1112 // Don't print the visualisation of selection
1113 LinkableMapObj *oldselection=NULL;
1116 oldselection=selection;
1117 selection->unselect();
1120 pp.setWindow (mapRect);
1122 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1125 // Restore selection
1128 selection=oldselection;
1129 selection->select();
1135 void MapEditor::exportImage(QString fn)
1137 // Finish open lineEdits
1138 if (lineedit) finishedLineEditNoSave();
1140 QPixmap pix (getPixmap());
1141 pix.save(fn, "PNG");
1144 void MapEditor::exportImage(QString fn, int item)
1146 // Finish open lineEdits
1147 if (lineedit) finishedLineEditNoSave();
1149 QPixmap pix (getPixmap());
1150 pix.save(fn, exportImageFormatMenu->text(item) );
1153 void MapEditor::exportASCII()
1155 // FIXME still experimental
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:
1181 if (!ex.setOutputDir ("out"))
1183 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1187 case QMessageBox::Cancel:
1194 ex.setPath (fd->selectedFile() );
1195 ex.setMapCenter(mapCenter);
1201 void MapEditor::exportXML(const QString &dir)
1203 // Create subdirectories
1206 // write to directory
1207 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1210 file.setName ( dir + "/"+mapName+".xml");
1211 if ( !file.open( IO_WriteOnly ) )
1213 // This should neverever happen
1214 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1218 // Write it finally, and write in UTF8, no matter what
1219 QTextStream ts( &file );
1220 ts.setEncoding (QTextStream::UnicodeUTF8);
1224 // Now write image, too
1225 exportImage (dir+"/images/"+mapName+".png");
1228 void MapEditor::clear()
1232 selection->unselect();
1239 void MapEditor::copy()
1241 // Finish open lineEdits
1242 if (lineedit) finishedLineEditNoSave();
1246 if (typeid(*selection) == typeid(BranchObj) )
1250 clipboardME->clear();
1251 clipboardME->getMapCenter()->addBranch();
1252 to=clipboardME->getMapCenter()->getLastBranch();
1255 from=(BranchObj*)(selection);
1258 // keep position relative to parent
1259 to->move2RelPos ( from->getRelPos());
1261 // select data in clipboard
1262 clipboardME->select ("bo:0");
1264 // repositioning makes testing nicer,
1265 // but is not needed usually:
1266 if (clipboardME->isVisible())
1268 clipboardME->getMapCenter()->reposition();
1271 clipboardME->hide();
1274 if (typeid(*selection) == typeid(FloatImageObj) )
1277 FloatImageObj* from;
1278 clipboardME->clear();
1279 clipboardME->getMapCenter()->addFloatImage();
1280 to=clipboardME->getMapCenter()->getLastFloatImage();
1283 from=(FloatImageObj*)(selection);
1286 // select data in clipboard
1287 clipboardME->select ("fi:0");
1289 // repositioning makes testing nicer,
1290 // but is not needed usually:
1291 if (clipboardME->isVisible())
1293 clipboardME->getMapCenter()->reposition();
1296 clipboardME->hide();
1302 void MapEditor::undo()
1304 // Finish open lineEdits
1305 if (lineedit) finishedLineEditNoSave();
1310 selection->unselect();
1314 parseAtom (undoCommand);
1315 mapCenter->reposition();
1317 // Undo not longer available now
1318 actionEditUndo->setEnabled (false);
1323 void MapEditor::undoXML(const QString &undoSel)
1326 d.setPath(bakMapDir);
1329 // We need to parse saved XML data
1330 mapBuilderHandler handler;
1331 QXmlInputSource source;
1332 source.setData(backupXML);
1333 QXmlSimpleReader reader;
1334 reader.setContentHandler( &handler );
1335 reader.setErrorHandler( &handler );
1336 handler.setMapEditor( this );
1337 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1338 if (undoSel.isEmpty())
1341 handler.setLoadMode (NewMap);
1345 handler.setLoadMode (ImportReplace);
1347 blockreposition=true;
1348 bool ok = reader.parse( source );
1349 blockreposition=false;
1352 // This should never ever happen
1353 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1354 tr( handler.errorProtocol() )+" in "+backupXML );
1358 QMessageBox::critical( 0, tr( "Critical Error" ),
1359 "Temporary directory " +bakMapDir +
1360 tr (" used for undo is gone. \n"
1361 "I will create a new one, but at the moment no undo is available.\n"
1362 "Maybe you want to reload your original data.\n\n"
1363 "Sorry for any inconveniences.") );
1368 LinkableMapObj* MapEditor::pasteNoSave()
1370 // Finish open lineEdits
1371 if (lineedit) finishedLineEditNoSave();
1373 LinkableMapObj *fromLMO=clipboardME->getSelection();
1374 LinkableMapObj *returnLMO=NULL;
1376 if (selection && fromLMO)
1378 if (typeid(*fromLMO) == typeid(BranchObj) )
1380 if (typeid(*selection) == typeid(MapCenterObj))
1382 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1383 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1385 if (typeid(*selection) == typeid(BranchObj))
1386 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1389 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1390 (typeid(*selection) == typeid (BranchObj) ||
1391 typeid(*selection)==typeid(MapCenterObj)) )
1392 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1398 void MapEditor::cutNoSave()
1400 // Finish open lineEdits
1401 if (lineedit) finishedLineEditNoSave();
1405 if (selection != NULL) {
1406 if (typeid(*selection) == typeid(BranchObj) )
1408 bo=(BranchObj*)(selection);
1409 par=(BranchObj*)(bo->getParObj());
1412 par->removeBranch(bo);
1414 selection->select();
1416 if (typeid(*selection) == typeid(FloatImageObj) )
1418 FloatImageObj* fio=(FloatImageObj*)(selection);
1419 par=(BranchObj*)(fio->getParObj());
1422 par->removeFloatImage(fio);
1424 selection->select();
1429 void MapEditor::paste()
1432 saveState(selection);
1434 mapCenter->reposition();
1438 void MapEditor::cut()
1441 saveState(selection->getParObj());
1444 mapCenter->reposition();
1448 void MapEditor::moveBranchUp()
1450 // Finish open lineEdits
1451 if (lineedit) finishedLineEditNoSave();
1455 if (typeid(*selection) == typeid(BranchObj) )
1458 saveState("moveBranchDown ()");
1459 bo=(BranchObj*)(selection);
1460 par=(BranchObj*)(bo->getParObj());
1461 selection->unselect();
1462 selection=par->moveBranchUp (bo);
1463 selection->select();
1464 mapCenter->reposition();
1465 ensureSelectionVisible();
1469 void MapEditor::moveBranchDown()
1471 // Finish open lineEdits
1472 if (lineedit) finishedLineEditNoSave();
1476 if (typeid(*selection) == typeid(BranchObj) )
1479 saveState("moveBranchUp ()");
1480 bo=(BranchObj*)(selection);
1481 par=(BranchObj*)(bo->getParObj());
1482 selection->unselect();
1483 selection=par->moveBranchDown(bo);
1484 selection->select();
1485 mapCenter->reposition();
1486 ensureSelectionVisible();
1490 void MapEditor::editHeading()
1492 // Finish open lineEdits
1493 if (lineedit) finishedLineEditNoSave();
1496 (typeid(*selection) == typeid(BranchObj) ||
1497 typeid(*selection) == typeid(MapCenterObj) ) )
1500 saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")");
1502 ensureSelectionVisible();
1503 editingBO=(BranchObj*)(selection);
1504 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1505 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1506 QString s=editingBO->getHeading();
1507 lineedit->setText(s);
1508 lineedit->setCursorPosition(1);
1509 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1510 lineedit->selectAll();
1513 lineedit->grabKeyboard();
1514 lineedit->setFocus();
1518 void MapEditor::setHeading(const QString &s)
1520 // Internal function, no saveState needed
1522 (typeid(*selection) == typeid(BranchObj) ||
1523 typeid(*selection) == typeid(MapCenterObj) ) )
1525 ((BranchObj*)(selection))->setHeading(s);
1526 mapCenter->reposition();
1528 ensureSelectionVisible();
1532 void MapEditor::addNewBranch(int pos)
1534 // Finish open lineEdits
1535 if (lineedit) finishedLineEditNoSave();
1538 (typeid(*selection) == typeid(BranchObj) ||
1539 typeid(*selection) == typeid(MapCenterObj) ) )
1542 saveState(selection);
1544 BranchObj* bo1 = (BranchObj*) (selection);
1545 bool wasScrolled=false;
1546 BranchObj *newbo=NULL;
1549 // save scroll state. If scrolled, automatically select
1550 // new branch in order to tmp unscroll parent...
1551 wasScrolled=bo1->isScrolled();
1552 newbo=bo1->addBranch();
1555 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1559 // add above selection
1560 newbo=parbo->insertBranch(bo1->getNum());
1562 // add below selection
1563 newbo=parbo->insertBranch(bo1->getNum()+1);
1565 // This should not happen...
1570 LinkableMapObj *oldselection=selection;
1572 mapCenter->reposition();
1574 if (actionSettingsAutoedit->isOn() ||
1575 actionSettingsAutoselectHeading->isOn() )
1577 selection->unselect();
1579 selection->select();
1580 if (actionSettingsPasteNewHeading->isOn() )
1582 BranchObj *bo2= (BranchObj*)(selection);
1583 bo2->setHeading("");
1585 if (actionSettingsAutoedit->isOn() )
1587 if (!actionSettingsAutoselectHeading->isOn()
1590 selection->unselect();
1591 selection=oldselection;
1592 selection->select();
1599 void MapEditor::addNewBranchHere()
1601 // Finish open lineEdits
1602 if (lineedit) finishedLineEditNoSave();
1605 (typeid(*selection) == typeid(BranchObj) ) )
1608 saveState(selection);
1610 BranchObj* bo1 = (BranchObj*) (selection);
1611 bool wasScrolled=false;
1612 BranchObj *newbo=NULL;
1613 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1616 // add below selection
1617 newbo=parbo->insertBranch(bo1->getNum()+1);
1620 LinkableMapObj *oldselection=selection;
1621 ((BranchObj*)(selection))->moveBranchTo (newbo,-1);
1623 mapCenter->reposition();
1625 if (actionSettingsAutoedit->isOn() ||
1626 actionSettingsAutoselectHeading->isOn() )
1628 selection->unselect();
1630 selection->select();
1631 if (actionSettingsPasteNewHeading->isOn() )
1633 BranchObj *bo2= (BranchObj*)(selection);
1634 bo2->setHeading("");
1636 if (actionSettingsAutoedit->isOn() )
1638 if (!actionSettingsAutoselectHeading->isOn()
1641 selection->unselect();
1642 selection=oldselection;
1643 selection->select();
1649 void MapEditor::deleteSelection()
1651 // Finish open lineEdits
1652 if (lineedit) finishedLineEditNoSave();
1654 if (selection && typeid(*selection) ==typeid(BranchObj) )
1657 saveState(selection->getParObj());
1658 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1659 BranchObj* par=(BranchObj*)(bo->getParObj());
1662 par->removeBranch(bo);
1664 selection->select();
1665 ensureSelectionVisible();
1666 mapCenter->reposition();
1669 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1672 saveState(selection->getParObj());
1673 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1674 BranchObj* par=(BranchObj*)(fio->getParObj());
1677 par->removeFloatImage(fio);
1679 selection->select();
1680 ensureSelectionVisible();
1681 mapCenter->reposition();
1686 LinkableMapObj* MapEditor::getSelection()
1691 bool MapEditor::select (const QString &s)
1693 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1695 // Finally select the found object
1698 if (selection) unselect();
1700 selection->select();
1702 ensureSelectionVisible();
1708 void MapEditor::unselect()
1712 selectionLast=selection;
1713 selection->unselect();
1718 void MapEditor::reselect()
1722 selection=selectionLast;
1723 selection->select();
1728 void MapEditor::selectNextBranch()
1730 // Increase number of branch
1733 QString s=selection->getSelectString();
1739 part=s.section(",",-1);
1741 num=part.right(part.length() - 3);
1743 s=s.left (s.length() -num.length());
1746 num=QString ("%1").arg(num.toUInt()+1);
1750 // Try to select this one
1751 if (select (s)) return;
1753 // We have no direct successor,
1754 // try to increase the parental number in order to
1755 // find a successor with same depth
1757 int d=selection->getDepth();
1762 while (!found && d>0)
1764 s=s.section (",",0,d-1);
1765 // replace substring of current depth in s with "1"
1766 part=s.section(",",-1);
1768 num=part.right(part.length() - 3);
1772 // increase number of parent
1773 num=QString ("%1").arg(num.toUInt()+1);
1774 s=s.section (",",0,d-2) + ","+ typ+num;
1777 // Special case, look at orientation
1778 if (selection->getOrientation()==OrientRightOfCenter)
1779 num=QString ("%1").arg(num.toUInt()+1);
1781 num=QString ("%1").arg(num.toUInt()-1);
1786 // pad to oldDepth, select the first branch for each depth
1787 for (i=d;i<oldDepth;i++)
1792 if ( ((BranchObj*)(selection))->countBranches()>0)
1800 // try to select the freshly built string
1808 void MapEditor::selectPrevBranch()
1810 // Decrease number of branch
1813 QString s=selection->getSelectString();
1819 part=s.section(",",-1);
1821 num=part.right(part.length() - 3);
1823 s=s.left (s.length() -num.length());
1826 num=QString ("%1").arg(num.toUInt()-1);
1830 // Try to select this one
1831 if (select (s)) return;
1833 // We have no direct precessor,
1834 // try to decrease the parental number in order to
1835 // find a precessor with same depth
1837 int d=selection->getDepth();
1842 while (!found && d>0)
1844 s=s.section (",",0,d-1);
1845 // replace substring of current depth in s with "1"
1846 part=s.section(",",-1);
1848 num=part.right(part.length() - 3);
1852 // decrease number of parent
1853 num=QString ("%1").arg(num.toUInt()-1);
1854 s=s.section (",",0,d-2) + ","+ typ+num;
1857 // Special case, look at orientation
1858 if (selection->getOrientation()==OrientRightOfCenter)
1859 num=QString ("%1").arg(num.toUInt()-1);
1861 num=QString ("%1").arg(num.toUInt()+1);
1866 // pad to oldDepth, select the last branch for each depth
1867 for (i=d;i<oldDepth;i++)
1871 if ( ((BranchObj*)(selection))->countBranches()>0)
1872 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1879 // try to select the freshly built string
1887 void MapEditor::selectUpperBranch()
1889 // Finish open lineEdits
1890 if (lineedit) finishedLineEditNoSave();
1894 if (typeid(*selection) == typeid(BranchObj))
1896 if (selection->getOrientation()==OrientRightOfCenter)
1899 if (selection->getDepth()==1)
1907 void MapEditor::selectLowerBranch()
1909 // Finish open lineEdits
1910 if (lineedit) finishedLineEditNoSave();
1914 if (typeid(*selection) == typeid(BranchObj))
1916 if (selection->getOrientation()==OrientRightOfCenter)
1919 if (selection->getDepth()==1)
1928 void MapEditor::selectLeftBranch()
1930 // Finish open lineEdits
1931 if (lineedit) finishedLineEditNoSave();
1937 if (typeid(*selection) == typeid(MapCenterObj))
1939 par= (BranchObj*) (selection);
1940 bo=par->getLastSelectedBranch();
1943 // Workaround for reselecting on left and right side
1944 if (bo->getOrientation()==OrientRightOfCenter)
1946 bo=par->getLastBranch();
1952 selection->select();
1954 ensureSelectionVisible();
1959 par=(BranchObj*)(selection->getParObj());
1960 if (selection->getOrientation()==OrientRightOfCenter)
1962 if (typeid(*selection) == typeid(BranchObj) ||
1963 typeid(*selection) == typeid(FloatImageObj))
1965 selection->unselect();
1967 selection->select();
1969 ensureSelectionVisible();
1973 if (typeid(*selection) == typeid(BranchObj) )
1975 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1978 selection->unselect();
1980 selection->select();
1982 ensureSelectionVisible();
1990 void MapEditor::selectRightBranch()
1992 // Finish open lineEdits
1993 if (lineedit) finishedLineEditNoSave();
2000 if (typeid(*selection) == typeid(MapCenterObj))
2002 par= (BranchObj*) (selection);
2003 bo=par->getLastSelectedBranch();
2006 // Workaround for relecting on left and right side
2007 if (bo->getOrientation()==OrientLeftOfCenter)
2008 bo=par->getFirstBranch();
2013 selection->select();
2014 ensureSelectionVisible();
2019 par=(BranchObj*)(selection->getParObj());
2020 if (selection->getOrientation()==OrientLeftOfCenter)
2022 if (typeid(*selection) == typeid(BranchObj) ||
2023 typeid(*selection) == typeid(FloatImageObj))
2025 selection->unselect();
2027 selection->select();
2029 ensureSelectionVisible();
2033 if (typeid(*selection) == typeid(BranchObj) )
2035 bo=((BranchObj*)(selection))->getLastSelectedBranch();
2038 selection->unselect();
2040 selection->select();
2042 ensureSelectionVisible();
2050 void MapEditor::selectFirstBranch()
2052 // Finish open lineEdits
2053 if (lineedit) finishedLineEditNoSave();
2059 if (typeid(*selection) == typeid(BranchObj))
2061 bo1= (BranchObj*) (selection);
2062 par=(BranchObj*)(bo1->getParObj());
2063 bo2=par->getFirstBranch();
2067 selection->select();
2068 ensureSelectionVisible();
2075 void MapEditor::selectLastBranch()
2077 // Finish open lineEdits
2078 if (lineedit) finishedLineEditNoSave();
2084 if (typeid(*selection) == typeid(BranchObj))
2086 bo1= (BranchObj*) (selection);
2087 par=(BranchObj*)(bo1->getParObj());
2088 bo2=par->getLastBranch();
2092 selection->select();
2093 ensureSelectionVisible();
2100 void MapEditor::setColor(QColor c)
2105 void MapEditor::selectBackgroundColor()
2107 // Finish open lineEdits
2108 if (lineedit) finishedLineEditNoSave();
2110 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2111 if ( !col.isValid() ) return;
2112 setBackgroundColor( col );
2116 void MapEditor::setBackgroundColor(QColor c)
2118 mapCanvas->setBackgroundColor (c);
2121 QColor MapEditor::pickColor()
2125 if (typeid(*selection) == typeid(BranchObj) ||
2126 typeid(*selection) == typeid(MapCenterObj))
2128 BranchObj *bo=(BranchObj*)(selection);
2129 actColor=bo->getColor();
2135 void MapEditor::colorItem()
2139 if (typeid(*selection) == typeid(BranchObj) ||
2140 typeid(*selection) == typeid(MapCenterObj))
2143 saveState(selection);
2144 BranchObj *bo=(BranchObj*)(selection);
2145 bo->setColor(actColor, false); // color links, color childs
2150 void MapEditor::colorBranch()
2154 if (typeid(*selection) == typeid(BranchObj) ||
2155 typeid(*selection) == typeid(MapCenterObj))
2158 saveState(selection);
2159 BranchObj *bo=(BranchObj*)(selection);
2160 bo->setColor(actColor, true); // color links, color childs
2166 void MapEditor::toggleStandardFlag(QString f)
2171 saveState(selection);
2172 ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2176 void MapEditor::setViewCenter()
2178 // transform to CanvasView Coord:
2179 QPoint p=worldMatrix().map(movingCenter);
2180 center ( p.x(), p.y());
2184 BranchObj* MapEditor::findText (QString s, bool cs)
2187 { // Nothing found or new find process
2189 // nothing found, start again
2191 itFind=mapCenter->first();
2193 bool searching=true;
2194 bool foundNote=false;
2195 while (searching && !EOFind)
2199 // Searching in Note
2200 if (itFind->getNote().contains(s,cs))
2202 if (selection!=itFind)
2204 if (selection) ((BranchObj*)(selection))->unselect();
2206 selection->select();
2208 ensureSelectionVisible();
2210 if (textEditor->findText(s,cs))
2216 // Searching in Heading
2217 if (searching && itFind->getHeading().contains (s,cs) )
2219 if (selection) ((BranchObj*)(selection))->unselect();
2221 selection->select();
2223 ensureSelectionVisible();
2229 itFind=itFind->next();
2230 if (!itFind) EOFind=true;
2236 return (BranchObj*)(selection);
2241 void MapEditor::findReset()
2242 { // Necessary if text to find changes during a find process
2247 void MapEditor::openURL()
2251 if (typeid(*selection) == typeid(BranchObj) ||
2252 typeid(*selection) == typeid(MapCenterObj))
2254 QString url=((BranchObj*)(selection))->getURL();
2256 QProcess *proc = new QProcess( this );
2258 #if !defined(Q_OS_MACX)
2259 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2261 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2262 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2265 proc->addArgument( url);
2267 if ( !proc->start() )
2269 if (mainWindow->settingsURL() )
2275 void MapEditor::editURL()
2277 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2278 typeid(*selection) == typeid(MapCenterObj)) )
2281 QString text = QInputDialog::getText(
2282 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2283 ((BranchObj*)(selection))->getURL(), &ok, this );
2286 // user entered something and pressed OK
2287 ((BranchObj*)(selection))->setURL (text);
2294 void MapEditor::editHeading2URL()
2296 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2297 typeid(*selection) == typeid(MapCenterObj)) )
2299 BranchObj *b=(BranchObj*)(selection);
2300 b->setURL (b->getHeading());
2306 void MapEditor::editBugzilla2URL()
2308 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2309 typeid(*selection) == typeid(MapCenterObj)) )
2311 BranchObj *b=(BranchObj*)(selection);
2312 b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
2318 void MapEditor::editVymLink()
2320 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2321 typeid(*selection) == typeid(MapCenterObj)) )
2323 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2324 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2325 fd->setCaption(tr("VYM - Link to another map"));
2326 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2327 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2331 if ( fd->exec() == QDialog::Accepted )
2332 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2334 mapCenter->reposition();
2341 void MapEditor::deleteVymLink()
2343 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2344 typeid(*selection) == typeid(MapCenterObj)) )
2346 ((BranchObj*)(selection))->setVymLink ("" );
2348 mapCenter->reposition();
2355 QString MapEditor::getVymLink()
2357 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2358 typeid(*selection) == typeid(MapCenterObj)) )
2360 return ((BranchObj*)(selection))->getVymLink();
2366 void MapEditor::removeBranchHere()
2368 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2371 saveState(selection->getParObj());
2372 QString sel=selection->getSelectString();
2373 BranchObj* bo=(BranchObj*)(selection);
2374 BranchObj* par=(BranchObj*)(bo->getParObj());
2376 par->removeBranchHere(bo);
2377 mapCenter->reposition();
2382 void MapEditor::removeChilds()
2384 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2387 saveState(selection->getParObj());
2388 ((BranchObj*)(selection))->removeChilds();
2389 mapCenter->reposition();
2393 void MapEditor::editMapInfo()
2395 ExtraInfoDialog dia;
2396 dia.setMapName (getFileName() );
2397 dia.setAuthor (mapCenter->getAuthor() );
2398 dia.setComment(mapCenter->getComment() );
2403 QCanvasItemList l=canvas()->allItems();
2404 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2406 stats+=QString ("%1 items on canvas\n").arg (i,6);
2413 bo=mapCenter->first();
2416 if (!bo->getNote().isEmpty() ) n++;
2417 f+= bo->countFloatImages();
2419 xl+=bo->countXLinks();
2422 stats+=QString ("%1 branches\n").arg (b-1,6);
2423 stats+=QString ("%1 xLinks \n").arg (xl,6);
2424 stats+=QString ("%1 notes\n").arg (n,6);
2425 stats+=QString ("%1 images\n").arg (f,6);
2426 dia.setStats (stats);
2428 // Finally show dialog
2429 if (dia.exec() == QDialog::Accepted)
2431 mapCenter->setAuthor (dia.getAuthor() );
2432 mapCenter->setComment (dia.getComment() );
2437 void MapEditor::updateActions()
2440 if (getLinkColorHint()==HeadingColor)
2441 actionFormatLinkColorHint->setOn(true);
2443 actionFormatLinkColorHint->setOn(false);
2448 actionFormatLinkStyleLine->setOn(true);
2451 actionFormatLinkStyleParabel->setOn(true);
2454 actionFormatLinkStylePolyLine->setOn(true);
2456 case StylePolyParabel:
2457 actionFormatLinkStylePolyParabel->setOn(true);
2463 QPixmap pix( 16, 16 );
2464 pix.fill( mapCanvas->backgroundColor() );
2465 actionFormatBackColor->setIconSet( pix );
2466 pix.fill( defLinkColor );
2467 actionFormatLinkColor->setIconSet( pix );
2469 actionEditUndo->setEnabled( mapChanged );
2470 actionFileSave->setEnabled( mapUnsaved );
2474 if ( (typeid(*selection) == typeid(BranchObj)) ||
2475 (typeid(*selection) == typeid(MapCenterObj)) )
2477 BranchObj *bo=(BranchObj*)(selection);
2478 // Take care of links
2479 if (bo->countXLinks()==0)
2481 branchLinksContextMenu->clear();
2482 branchLinksContextMenu->insertItem ("No link available");
2483 branchLinksContextMenuDup->clear();
2484 branchLinksContextMenuDup->insertItem ("No link available");
2490 branchLinksContextMenu->clear();
2491 branchLinksContextMenuDup->clear();
2492 for (int i=0; i<=bo->countXLinks();i++)
2494 bot=bo->XLinkTargetAt(i);
2497 s=bot->getHeading();
2500 branchLinksContextMenu->insertItem (s);
2501 branchLinksContextMenuDup->insertItem (s);
2506 standardFlagsDefault->setEnabled (true);
2508 if ( bo->getURL().isEmpty() )
2509 actionEditOpenURL->setEnabled (false);
2511 actionEditOpenURL->setEnabled (true);
2513 if ( bo->getVymLink().isEmpty() )
2515 actionEditOpenVymLink->setEnabled (false);
2516 actionEditDeleteVymLink->setEnabled (false);
2519 actionEditOpenVymLink->setEnabled (true);
2520 actionEditDeleteVymLink->setEnabled (true);
2523 actionEditCopy->setEnabled (true);
2524 actionEditCut->setEnabled (true);
2525 <<<<<<< mapeditor.cpp
2526 if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
2527 actionEditPaste->setEnabled (true);
2529 actionEditPaste->setEnabled (false);
2530 for (a=actionListBranches.first();a;a=actionListBranches.next())
2531 a->setEnabled(true);
2533 if (clipboardME->getMapCenter()->countBranches()>0)
2534 actionEditPaste->setEnabled (true);
2536 actionEditPaste->setEnabled (false);
2537 for (a=actionListBranches.first();a;a=actionListBranches.next())
2538 a->setEnabled(true);
2540 actionEditDelete->setEnabled (true);
2541 actionEditToggleFloatExport->setEnabled (false);
2542 switch (selection->getFrameType())
2545 actionFormatFrameNone->setOn(true);
2548 actionFormatFrameRectangle->setOn(true);
2554 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2556 standardFlagsDefault->setEnabled (false);
2558 actionEditOpenURL->setEnabled (false);
2559 actionEditOpenVymLink->setEnabled (false);
2560 actionEditDeleteVymLink->setEnabled (false);
2562 actionEditCopy->setEnabled (true);
2563 actionEditCut->setEnabled (true);
2564 actionEditPaste->setEnabled (false); //FIXME
2565 for (a=actionListBranches.first();a;a=actionListBranches.next())
2566 a->setEnabled(false);
2567 actionEditDelete->setEnabled (true);
2568 actionEditToggleFloatExport->setOn
2569 ( ((FloatImageObj*)(selection))->getFloatExport() );
2574 standardFlagsDefault->setEnabled (false);
2576 actionEditCopy->setEnabled (false);
2577 actionEditCut->setEnabled (false);
2578 actionEditPaste->setEnabled (false);
2579 for (a=actionListBranches.first();a;a=actionListBranches.next())
2580 a->setEnabled(false);
2582 actionEditOpenURL->setEnabled (false);
2583 actionEditOpenVymLink->setEnabled (false);
2584 actionEditDeleteVymLink->setEnabled (false);
2585 actionEditHeading2URL->setEnabled (false);
2586 actionEditDelete->setEnabled (false);
2587 actionEditToggleFloatExport->setEnabled (false);
2591 void MapEditor::setLinkStyle (LinkStyle ls)
2598 bo=mapCenter->first();
2602 bo->setLinkStyle(bo->getDefLinkStyle());
2605 mapCenter->reposition();
2608 LinkStyle MapEditor::getLinkStyle ()
2613 void MapEditor::setLinkColor(QColor c)
2619 void MapEditor::setLinkColorHint()
2621 // called from setLinkColorHint(lch) or at end of parse
2623 bo=mapCenter->first();
2631 void MapEditor::setLinkColorHint(LinkColorHint lch)
2637 void MapEditor::toggleLinkColorHint()
2639 if (linkcolorhint==HeadingColor)
2640 linkcolorhint=DefaultColor;
2642 linkcolorhint=HeadingColor;
2644 bo=mapCenter->first();
2652 LinkColorHint MapEditor::getLinkColorHint()
2654 return linkcolorhint;
2657 QColor MapEditor::getDefLinkColor()
2659 return defLinkColor;
2662 void MapEditor::setDefXLinkColor(QColor col)
2667 QColor MapEditor::getDefXLinkColor()
2669 return defXLinkColor;
2672 void MapEditor::setDefXLinkWidth (int w)
2677 int MapEditor::getDefXLinkWidth()
2679 return defXLinkWidth;
2682 void MapEditor::selectLinkColor()
2684 // Finish open lineEdits
2685 if (lineedit) finishedLineEditNoSave();
2687 QColor col = QColorDialog::getColor( defLinkColor, this );
2688 if ( !col.isValid() ) return;
2689 setLinkColor( col );
2693 void MapEditor::toggleScroll()
2695 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2697 BranchObj *bo=((BranchObj*)(selection));
2698 if (bo->countBranches()==0) return;
2699 if (bo->getDepth()==0) return;
2701 saveState(selection);
2708 void MapEditor::unScrollAll()
2711 bo=mapCenter->first();
2714 if (bo->isScrolled()) bo->toggleScroll();
2719 void MapEditor::loadFloatImage ()
2722 (typeid(*selection) == typeid(BranchObj)) ||
2723 (typeid(*selection) == typeid(MapCenterObj)) )
2725 BranchObj *bo=((BranchObj*)(selection));
2727 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2728 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2729 ImagePreview *p =new ImagePreview (fd);
2730 fd->setContentsPreviewEnabled( TRUE );
2731 fd->setContentsPreview( p, p );
2732 fd->setPreviewMode( QFileDialog::Contents );
2733 fd->setCaption(tr("vym - Load image"));
2734 fd->setDir (lastImageDir);
2738 if ( fd->exec() == QDialog::Accepted )
2741 saveState(selection);
2742 QString fn=fd->selectedFile();
2743 lastImageDir=fn.left(fn.findRev ("/"));
2744 bo->addFloatImage();
2745 // FIXME check if load was successful
2746 bo->getLastFloatImage()->load(fn);
2747 bo->getLastFloatImage()->setOriginalFilename(fn);
2748 mapCenter->reposition();
2755 void MapEditor::saveFloatImage (int item)
2758 (typeid(*selection) == typeid(FloatImageObj)) )
2760 FloatImageObj *fio=((FloatImageObj*)(selection));
2761 const char* fmt = saveImageFormatMenu->text(item);
2763 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2764 fd->addFilter ("PNG (*.png)");
2765 fd->addFilter ("BMP (*.bmp)");
2766 fd->addFilter ("XBM (*.xbm)");
2767 fd->addFilter ("JPG (*.jpg)");
2768 fd->addFilter ("XPM (*.xpm)");
2769 fd->addFilter ("GIF (*.gif)");
2770 fd->addFilter ("PNM (*.pnm)");
2771 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2772 fd->setCaption(tr("vym - Save image as ") + fmt);
2773 fd->setMode( QFileDialog::AnyFile );
2774 fd->setSelection (fio->getOriginalFilename());
2778 if ( fd->exec() == QDialog::Accepted )
2780 if (QFile (fd->selectedFile()).exists() )
2782 QMessageBox mb( "VYM",
2783 tr("The file ") + fd->selectedFile() +
2784 tr(" exists already. "
2785 "Do you want to overwrite it?"),
2786 QMessageBox::Warning,
2787 QMessageBox::Yes | QMessageBox::Default,
2788 QMessageBox::Cancel | QMessageBox::Escape,
2789 QMessageBox::QMessageBox::NoButton );
2791 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2792 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2795 case QMessageBox::Yes:
2798 case QMessageBox::Cancel:
2804 fio->save (fd->selectedFile(),fmt);
2809 void MapEditor::toggleFloatExport()
2812 (typeid(*selection) == typeid(FloatImageObj))||
2813 (typeid(*selection) == typeid(FloatObj)) )
2815 FloatImageObj *fio=((FloatImageObj*)(selection));
2816 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2820 void MapEditor::setFrame(const FrameType &t)
2823 (typeid(*selection) == typeid(BranchObj)) ||
2824 (typeid(*selection) == typeid(MapCenterObj)) )
2826 selection->setFrameType (t);
2827 mapCenter->reposition();
2828 selection->updateLink();
2832 void MapEditor::importDir(BranchObj *dst, QDir d)
2835 (typeid(*selection) == typeid(BranchObj)) ||
2836 (typeid(*selection) == typeid(MapCenterObj)) )
2840 // Traverse directories
2841 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2842 const QFileInfoList *dirlist = d.entryInfoList();
2843 QFileInfoListIterator itdir( *dirlist );
2846 while ( (fi = itdir.current()) != 0 )
2848 if (fi->fileName() != "." && fi->fileName() != ".." )
2851 bo=dst->getLastBranch();
2852 bo->setHeading (fi->fileName() );
2853 bo->setColor (QColor("blue"),false);
2855 if ( !d.cd(fi->fileName()) )
2856 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2859 // Recursively add subdirs
2867 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2868 const QFileInfoList *filelist = d.entryInfoList();
2869 QFileInfoListIterator itfile( *filelist );
2871 while ( (fi = itfile.current()) != 0 )
2874 bo=dst->getLastBranch();
2875 bo->setHeading (fi->fileName() );
2876 bo->setColor (QColor("black"),false);
2877 if (fi->fileName().right(4) == ".vym" )
2878 bo->setVymLink (fi->filePath());
2885 void MapEditor::importDir()
2888 (typeid(*selection) == typeid(BranchObj)) ||
2889 (typeid(*selection) == typeid(MapCenterObj)) )
2891 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2892 fd->setMode (QFileDialog::DirectoryOnly);
2893 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2894 fd->setCaption(tr("VYM - Choose directory structur to import"));
2898 if ( fd->exec() == QDialog::Accepted )
2900 BranchObj *bo=((BranchObj*)(selection));
2901 importDir (bo,QDir(fd->selectedFile()) );
2902 mapCenter->reposition();
2909 void MapEditor::followXLink(int i)
2912 (typeid(*selection) == typeid(BranchObj)) ||
2913 (typeid(*selection) == typeid(MapCenterObj)) )
2915 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2918 selection->unselect();
2920 selection->select();
2921 ensureSelectionVisible();
2926 void MapEditor::editXLink(int i)
2929 (typeid(*selection) == typeid(BranchObj)) ||
2930 (typeid(*selection) == typeid(MapCenterObj)) )
2932 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2935 EditXLinkDialog dia;
2937 dia.setSelection(selection);
2938 if (dia.exec() == QDialog::Accepted)
2940 if (dia.useSettingsGlobal() )
2942 setDefXLinkColor (xlo->getColor() );
2943 setDefXLinkWidth (xlo->getWidth() );
2945 if (dia.deleteXLink())
2946 ((BranchObj*)(selection))->deleteXLinkAt(i);
2955 void MapEditor::testFunction()
2957 cout << "MapEditor::testFunction() called\n";
2959 (typeid(*selection) == typeid(BranchObj)) )
2961 QString s=((BranchObj*)(selection))->getHeading();
2966 void MapEditor::ensureSelectionVisible()
2970 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2972 if (selection->getOrientation() == OrientLeftOfCenter)
2973 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2975 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2976 ensureVisible (p.x(), p.y() );
2981 void MapEditor::updateViewCenter()
2983 // Update movingCenter, so that we can zoom comfortably later
2984 QRect rc = QRect( contentsX(), contentsY(),
2985 visibleWidth(), visibleHeight() );
2986 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2987 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2988 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2991 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2993 // Lineedits are already closed by preceding
2994 // mouseEvent, we don't need to close here.
2996 QPoint p = inverseWorldMatrix().map(e->pos());
2997 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3000 { // MapObj was found
3001 if (selection != lmo)
3003 // select the MapObj
3004 if (selection) selection->unselect();
3006 selection->select();
3012 if (typeid(*selection)==typeid(BranchObj) ||
3013 typeid(*selection)==typeid(MapCenterObj) )
3015 // Context Menu on branch or mapcenter
3017 branchContextMenu->popup(e->globalPos() );
3019 if (typeid(*selection)==typeid(FloatImageObj))
3021 // Context Menu on floatimage
3023 floatimageContextMenu->popup(e->globalPos() );
3027 { // No MapObj found, we are on the Canvas itself
3028 // Context Menu on Canvas
3030 canvasContextMenu->popup(e->globalPos() );
3034 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3036 // Finish open lineEdits
3037 if (lineedit) finishedLineEditNoSave();
3039 QPoint p = inverseWorldMatrix().map(e->pos());
3040 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3042 // Special case: CTRL is pressed
3043 if (e->state() & QMouseEvent::ControlButton)
3045 if (actionModModeColor->isOn())
3047 if (e->state() & QMouseEvent::ControlButton)
3050 setCursor (pickColorCursor);
3054 if (actionModModeLink->isOn())
3056 BranchObj *bo_begin=NULL;
3058 bo_begin=(BranchObj*)(lmo);
3061 ((typeid(*selection) == typeid(BranchObj)) ||
3062 (typeid(*selection) == typeid(MapCenterObj))) )
3063 bo_begin=(BranchObj*)(selection);
3067 linkingObj_src=bo_begin;
3068 tmpXLink=new XLinkObj (mapCanvas);
3069 tmpXLink->setBegin (bo_begin);
3070 tmpXLink->setEnd (p);
3071 tmpXLink->setColor(defXLinkColor);
3072 tmpXLink->setWidth(defXLinkWidth);
3073 tmpXLink->updateXLink();
3074 tmpXLink->setVisibility (true);
3081 { // MapObj was found
3082 if (selection != lmo)
3084 // select the MapObj
3085 if (selection) selection->unselect();
3087 selection->select();
3093 // Check, if systemFlag clicked
3094 if (typeid(*selection)==typeid(BranchObj) ||
3095 typeid(*selection)==typeid(MapCenterObj) )
3097 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
3098 if (!foname.isEmpty())
3100 // Do not move, if systemFlag clicked
3104 if (foname=="vymLink")
3106 mainWindow->editOpenVymLink();
3107 // tabWidget may change, better return now
3108 // before segfaulting...
3112 mainWindow->windowToggleNoteEditor();
3116 // Left Button Move Branches
3117 if (e->button() == QMouseEvent::LeftButton )
3119 // If modMode==copy, then we want to "move" the _new_ object around
3120 // then we need the offset from p to the _old_ selection, because of tmp
3121 if (actionModModeCopy->isOn() &&
3122 e->state() & QMouseEvent::ControlButton)
3124 if (typeid(*selection)==typeid(BranchObj) )
3127 movingObj_start.setX( p.x() - selection->x() );
3128 movingObj_start.setY( p.y() - selection->y() );
3129 mapCenter->addBranch ((BranchObj*)(selection));
3131 selection=mapCenter->getLastBranch();
3132 selection->select();
3133 mapCenter->reposition();
3137 movingObj_start.setX( p.x() - selection->x() );
3138 movingObj_start.setY( p.y() - selection->y() );
3141 movingObj=selection;
3143 // Middle Button Toggle Scroll
3144 // (On Mac OS X this won't work, but we still have
3145 // a button in the toolbar)
3146 if (e->button() == QMouseEvent::MidButton )
3150 { // No MapObj found, we are on the Canvas itself
3151 // Left Button move Pos of CanvasView
3152 if (e->button() == QMouseEvent::LeftButton )
3154 movingObj=NULL; // move Content not Obj
3155 movingObj_start=e->globalPos();
3156 movingCont_start=QPoint (contentsX(), contentsY() );
3157 movingVec=QPoint(0,0);
3158 setCursor(handOpenCursor);
3163 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3165 QPoint p = inverseWorldMatrix().map(e->pos());
3167 // Move the selected MapObj
3168 if ( selection && movingObj)
3170 ensureVisible (p.x(),p.y());
3172 // Now move the selection, but add relative position
3173 // (movingObj_start) where selection was chosen with
3174 // mousepointer. (This avoids flickering resp. jumping
3175 // of selection back to absPos)
3177 LinkableMapObj *lmosel;
3178 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3180 // Check if we could link
3181 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3184 if (typeid(*selection) == typeid(FloatImageObj))
3188 FloatObj *fo=(FloatObj*)(selection);
3189 if (fo->getLinkStyle()==StyleUndef)
3191 fo->setLinkStyle(fo->getDefLinkStyle());
3192 fo->setLinkColor(fo->getParObj()->getLinkColor());
3194 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3198 // Relink float to new mapcenter or branch, if shift is pressed
3199 // Only relink, if selection really has a new parent
3200 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3201 ( (typeid(*lmo)==typeid(BranchObj)) ||
3202 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3203 ( lmo != fo->getParObj())
3206 if (typeid(*fo) == typeid(FloatImageObj))
3208 FloatImageObj *fio=(FloatImageObj*)(fo);
3209 ((BranchObj*)(lmo))->addFloatImage (fio);
3211 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3212 fio=((BranchObj*)(lmo))->getLastFloatImage();
3215 selection=(LinkableMapObj*)(fio);
3216 selection->select();
3217 movingObj=(MapObj*)(fio);
3218 // setLinkStyle calls updateLink, only set it once
3219 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3220 fio->setLinkStyle (fio->getDefLinkStyle());
3223 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3225 } else // selection != a FloatObj
3227 if (lmosel->getDepth()==0)
3229 if (e->state() == (LeftButton | !ShiftButton))
3230 // If mapCenter is moved, move all the rest by default, too.
3231 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3233 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3236 if (lmosel->getDepth()==1)
3238 // depth==1, mainbranch
3241 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3245 if (lmosel->getOrientation() == OrientLeftOfCenter)
3246 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3247 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3248 p.y()-movingObj_start.y() );
3250 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3252 // reposition subbranch
3253 lmosel->reposition();
3254 //ensureSelectionVisible();
3256 if (lmo && (lmo!=selection) &&
3257 (typeid(*lmo) == typeid(BranchObj) ||
3258 (typeid(*lmo) == typeid(MapCenterObj) )
3261 if (e->state() & QMouseEvent::ControlButton)
3263 // Special case: CTRL to link below lmo
3264 lmosel->setParObjTmp (lmo,p,+1);
3266 else if (e->state() & QMouseEvent::ShiftButton)
3267 lmosel->setParObjTmp (lmo,p,-1);
3269 lmosel->setParObjTmp (lmo,p,0);
3272 lmosel->unsetParObjTmp();
3274 if (lmo &&(lmo==selection))
3275 // Could link to myself (happens sometimes...)
3276 lmosel->unsetParObjTmp();
3278 // no Obj under selection, go back to original Parent
3279 lmosel->unsetParObjTmp();
3284 } // no FloatImageObj
3288 } // selection && moving_obj
3290 // Draw a link from one branch to another
3293 tmpXLink->setEnd (p);
3294 tmpXLink->updateXLink();
3298 if (!movingObj && !pickingColor &&!drawingLink)
3300 QPoint p=e->globalPos();
3301 movingVec.setX(-p.x() + movingObj_start.x() );
3302 movingVec.setY(-p.y() + movingObj_start.y() );
3303 setContentsPos( movingCont_start.x() + movingVec.x(),
3304 movingCont_start.y() + movingVec.y());
3311 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3313 LinkableMapObj *dst;
3314 // Have we been picking color?
3318 setCursor (ArrowCursor);
3319 // Check if we are over another branch
3320 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3321 if (dst && selection)
3323 if (e->state() & QMouseEvent::ShiftButton)
3325 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3326 ((BranchObj*)(selection))->setLinkColor ();
3330 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3331 ((BranchObj*)(selection))->setLinkColor ();
3337 // Have we been drawing a link?
3341 // Check if we are over another branch
3342 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3343 if (dst && selection)
3345 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3346 tmpXLink->updateXLink();
3347 tmpXLink->activate();
3358 // Have we been moving something?
3359 if ( selection && movingObj )
3361 // Check if we are over another branch, but ignore
3362 // any found LMOs, which are FloatObjs
3363 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3364 ((LinkableMapObj*)(selection)) );
3367 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3372 // Now check, if we have been moving a branch
3373 if (typeid(*selection) == typeid(BranchObj) )
3375 // save the position in case we link to mapcenter
3376 QPoint savePos=QPoint (selection->x(),selection->y() );
3378 // Reset the temporary drawn link to the original one
3379 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3387 // remove the current selection, if we have no destination
3388 selection->unselect();
3389 ((BranchObj*)(selection->getParObj()))->removeBranch ((BranchObj*)(selection));
3392 selection=selectionLast;
3394 selection->select();
3401 // TODO we also could check, if dest and src are on same branch,
3402 // then it would be sufficient to saveState of this branch
3404 // Modifiers allow to insert above/below dst
3405 if (e->state() & QMouseEvent::ShiftButton)
3407 ((BranchObj*)(selection))->moveBranchTo
3410 ((BranchObj*)(dst))->getNum()
3412 //if (selection) selection->select();
3414 if (e->state() & QMouseEvent::ControlButton)
3416 ((BranchObj*)(selection))->moveBranchTo
3419 ((BranchObj*)(dst))->getNum()+1
3421 //if (selection) selection->select();
3424 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
3425 if (dst->getDepth()==0)
3426 ((BranchObj*)(selection))->move (savePos);
3429 // Draw the original link, before selection was moved around
3430 mapCenter->reposition();
3432 // Finally resize canvas, if needed
3437 // maybe we moved View: set old cursor
3438 setCursor (ArrowCursor);
3442 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3444 // Finish open lineEdits
3445 if (lineedit) finishedLineEditNoSave();
3447 if (e->button() == QMouseEvent::LeftButton )
3449 QPoint p = inverseWorldMatrix().map(e->pos());
3450 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3451 if (lmo) { // MapObj was found
3452 // First select the MapObj than edit heading
3453 if (selection) selection->unselect();
3455 selection->select();
3457 saveState(selection);
3463 void MapEditor::resizeEvent (QResizeEvent* e)
3465 QCanvasView::resizeEvent( e );
3468 if (!fileName.isEmpty()) s=fileName;
3473 MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3476 (typeid(*selection) == typeid(BranchObj)) ||
3477 (typeid(*selection) == typeid(MapCenterObj))) {
3479 // If QImageDrag can decode mime type
3480 if (QImageDrag::canDecode(event)) {
3485 // If image are drag from firefox
3486 if (event->provides("application/x-moz-file-promise-url") &&
3487 event->provides("application/x-moz-nativeimage")) {
3488 event->accept(true);
3497 MapEditor::contentsDropEvent(QDropEvent *event)
3500 if (event->provides("image/png")) {
3502 if (QImageDrag::decode(event, pix)) {
3508 } else if (event->provides("application/x-moz-file-promise-url") &&
3509 event->provides("application/x-moz-nativeimage")) {
3511 // Contains url to the img src in UTF-16
3512 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3513 QString url = QString((const QChar*)d.data(),d.size()/2);
3520 MapEditor::addFloatImage(const QPixmap &img)
3523 (typeid(*selection) == typeid(BranchObj)) ||
3524 (typeid(*selection) == typeid(MapCenterObj)) )
3526 BranchObj *bo=((BranchObj*)(selection));
3528 saveState(selection);
3529 //QString fn=fd->selectedFile();
3530 //lastImageDir=fn.left(fn.findRev ("/"));
3531 bo->addFloatImage();
3532 // FIXME check if load was successful
3533 bo->getLastFloatImage()->load(img);
3534 //bo->getLastFloatImage()->setOriginalFilename(fn);
3535 mapCenter->reposition();
3543 MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3545 if (!imageBuffer) imageBuffer = new QBuffer();
3546 if (!imageBuffer->isOpen()) {
3547 imageBuffer->open(IO_WriteOnly | IO_Append);
3549 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3554 MapEditor::imageDataFinished(QNetworkOperation *nop)
3556 imageBuffer->close();
3557 if (nop->state()==QNetworkProtocol::StDone) {
3558 QPixmap img(imageBuffer->buffer());
3567 MapEditor::fetchImage(const QString &url)
3570 urlOperator->stop();
3571 disconnect(urlOperator);
3575 urlOperator = new QUrlOperator(url);
3576 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3577 this, SLOT(imageDataFinished(QNetworkOperation*)));
3579 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3580 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));