3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <qpopupmenu.h>
9 #include <qpaintdevicemetrics.h>
11 #include <qfiledialog.h>
14 #include <qcolordialog.h>
17 #include <qinputdialog.h>
18 #include <qdragobject.h>
19 #include <qurloperator.h>
20 #include <qnetworkprotocol.h>
31 #include "texteditor.h"
32 #include "linkablemapobj.h"
35 #include "mainwindow.h"
36 #include "extrainfodialog.h"
37 #include "editxlinkdialog.h"
40 #include "icons/flag-note.xpm"
41 #include "icons/flag-url.xpm"
42 #include "icons/flag-vymlink.xpm"
43 #include "icons/flag-scrolled-right.xpm"
44 #include "icons/flag-tmpUnscrolled-right.xpm"
45 #include "icons/flag-questionmark.xpm"
46 #include "icons/flag-exclamationmark.xpm"
47 #include "icons/flag-hook-green.xpm"
48 #include "icons/flag-cross-red.xpm"
49 #include "icons/flag-stopsign.xpm"
50 #include "icons/flag-smiley-good.xpm"
51 #include "icons/flag-smiley-sad.xpm"
52 #include "icons/flag-clock.xpm"
53 #include "icons/flag-lamp.xpm"
54 #include "icons/flag-arrow-up.xpm"
55 #include "icons/flag-arrow-down.xpm"
56 #include "icons/flag-thumb-up.xpm"
57 #include "icons/flag-thumb-down.xpm"
58 #include "icons/flag-heart.xpm"
59 #include "icons/flag-flash.xpm"
60 #include "icons/flag-lifebelt.xpm"
62 extern TextEditor *textEditor;
63 extern int statusbarTime;
64 extern Main *mainWindow;
65 extern FlagRowObj *systemFlagsDefault;
66 extern FlagRowObj *standardFlagsDefault;
67 extern MapEditor *clipboardME;
69 extern QPtrList <QAction> actionListBranches;
71 extern QAction *actionFileSave;
72 extern QAction *actionEditUndo;
73 extern QAction *actionEditCopy;
74 extern QAction *actionEditCut;
75 extern QAction *actionEditPaste;
76 extern QAction *actionEditMoveUp;
77 extern QAction *actionEditMoveDown;
78 extern QAction *actionEditToggleScroll;
79 extern QAction *actionEditOpenURL;
80 extern QAction *actionEditURL;
81 extern QAction *actionEditHeading2URL;
82 extern QAction *actionEditBugzilla2URL;
83 extern QAction *actionEditOpenVymLink;
84 extern QAction *actionEditVymLink;
85 extern QAction *actionEditDeleteVymLink;
86 extern QAction *actionEditHeading;
87 extern QAction *actionEditDelete;
88 extern QAction *actionEditAddBranch;
89 extern QAction *actionEditAddBranchAbove;
90 extern QAction *actionEditAddBranchBelow;
91 extern QAction *actionEditRemoveBranchHere;
92 extern QAction *actionEditRemoveChilds;
93 extern QAction *actionEditImportAdd;
94 extern QAction *actionEditImportReplace;
95 extern QAction *actionEditSaveBranch;
96 extern QAction *actionEditSelectFirst;
97 extern QAction *actionEditSelectLast;
98 extern QAction *actionEditLoadImage;
99 extern QAction *actionEditToggleFloatExport;
101 extern QAction* actionFormatPickColor;
102 extern QAction* actionFormatColorBranch;
103 extern QAction* actionFormatColorSubtree;
104 extern QAction *actionFormatLinkColorHint;
105 extern QAction *actionFormatBackColor;
106 extern QAction *actionFormatLinkColor;
108 extern QActionGroup* actionGroupModModes;
109 extern QAction* actionModModeColor;
110 extern QAction* actionModModeLink;
111 extern QAction* actionModModeCopy;
113 extern QActionGroup *actionGroupFormatFrameTypes;
114 extern QAction *actionFormatFrameNone;
115 extern QAction *actionFormatFrameRectangle;
117 extern QActionGroup *actionGroupFormatLinkStyles;
118 extern QAction *actionFormatLinkStyleLine;
119 extern QAction *actionFormatLinkStyleParabel;
120 extern QAction *actionFormatLinkStylePolyLine;
121 extern QAction *actionFormatLinkStylePolyParabel;
123 extern QAction *actionViewToggleNoteEditor;
125 extern QAction *actionSettingsAutoedit;
126 extern QAction *actionSettingsAutoselectHeading;
127 extern QAction *actionSettingsAutoselectText;
128 extern QAction *actionSettingsPasteNewHeading;
129 extern QAction *actionSettingsUseFlagGroups;
131 extern QPopupMenu *branchContextMenu;
132 extern QPopupMenu *branchLinksContextMenu;
133 extern QPopupMenu *branchLinksContextMenuDup;
134 extern QPopupMenu *floatimageContextMenu;
135 extern QPopupMenu *saveImageFormatMenu;
136 extern QPopupMenu *exportImageFormatMenu;
137 extern QPopupMenu *canvasContextMenu;
139 extern Settings settings;
142 ///////////////////////////////////////////////////////////////////////
143 ///////////////////////////////////////////////////////////////////////
144 MapEditor::MapEditor(
145 QWidget* parent, bool interactive, const char* name, WFlags f) :
146 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
148 //cout << "Constructor ME "<<this<<endl;
150 viewport()->setAcceptDrops(true);
152 mapCanvas = new QCanvas(1000,800);
153 mapCanvas->setAdvancePeriod(30);
155 setCanvas (mapCanvas);
157 setVScrollBarMode ( QScrollView::AlwaysOn );
158 setHScrollBarMode ( QScrollView::AlwaysOn );
160 // Now create the _global_ system flags _once_:
161 // (Later all OrnamentedObj copy from this
162 // and set their own canvas)
163 if (!systemFlagsDefault)
165 systemFlagsDefault = new FlagRowObj (mapCanvas);
166 systemFlagsDefault->setVisibility (false);
167 systemFlagsDefault->setName ("systemFlagsDef");
169 FlagObj *fo = new FlagObj (mapCanvas);
170 fo->load(QPixmap(flag_note_xpm));
172 fo->setToolTip(tr("Note","Systemflag"));
173 systemFlagsDefault->addFlag (fo); // makes deep copy
175 fo->load(QPixmap(flag_url_xpm));
177 fo->setToolTip(tr("WWW Document (external)","Systemflag"));
178 systemFlagsDefault->addFlag (fo);
180 fo->load(QPixmap(flag_vymlink_xpm));
181 fo->setName("vymLink");
182 fo->setToolTip(tr("Link to another vym map","Systemflag"));
183 systemFlagsDefault->addFlag (fo);
185 fo->load(QPixmap(flag_scrolled_right_xpm));
186 fo->setName("scrolledright");
187 fo->setToolTip(tr("subtree is scrolled","Systemflag"));
188 systemFlagsDefault->addFlag (fo);
190 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
191 fo->setName("tmpUnscrolledright");
192 fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
193 systemFlagsDefault->addFlag (fo);
196 if (!standardFlagsDefault)
198 standardFlagsDefault = new FlagRowObj (mapCanvas);
199 standardFlagsDefault->setVisibility (false);
200 standardFlagsDefault->setName ("standardFlagsDef");
202 FlagObj *fo = new FlagObj (mapCanvas);
203 fo->load(QPixmap(flag_exclamationmark_xpm));
204 fo->setName ("exclamationmark");
205 fo->setGroup("standard-mark");
206 fo->setToolTip(tr("Take care!","Standardflag"));
207 standardFlagsDefault->addFlag (fo); // makes deep copy
209 fo->load(QPixmap(flag_questionmark_xpm));
210 fo->setName("questionmark");
211 fo->setGroup("standard-mark");
212 fo->setToolTip(tr("Really?","Standardflag"));
213 standardFlagsDefault->addFlag (fo);
215 fo->load(QPixmap(flag_hook_green_xpm));
216 fo->setName("hook-green");
217 fo->setGroup("standard-hook");
218 fo->setToolTip(tr("ok!","Standardflag"));
219 standardFlagsDefault->addFlag (fo);
221 fo->load(QPixmap(flag_cross_red_xpm));
222 fo->setName("cross-red");
223 fo->setGroup("standard-hook");
224 fo->setToolTip(tr("Not ok!","Standardflag"));
225 standardFlagsDefault->addFlag (fo);
227 fo->load(QPixmap(flag_stopsign_xpm));
228 fo->setName("stopsign");
229 fo->setToolTip(tr("This won't work!","Standardflag"));
230 standardFlagsDefault->addFlag (fo);
232 fo->load(QPixmap(flag_smiley_good_xpm));
233 fo->setName("smiley-good");
234 fo->setGroup("standard-smiley");
235 fo->setToolTip(tr("Good","Standardflag"));
236 standardFlagsDefault->addFlag (fo);
238 fo->load(QPixmap(flag_smiley_sad_xpm));
239 fo->setName("smiley-sad");
240 fo->setGroup("standard-smiley");
241 fo->setToolTip(tr("Bad","Standardflag"));
242 standardFlagsDefault->addFlag (fo);
244 fo->load(QPixmap(flag_clock_xpm));
245 fo->setName("clock");
246 fo->setToolTip(tr("Time critical","Standardflag"));
247 standardFlagsDefault->addFlag (fo);
249 fo->load(QPixmap(flag_lamp_xpm));
251 fo->setToolTip(tr("Idea!","Standardflag"));
252 standardFlagsDefault->addFlag (fo);
254 fo->load(QPixmap(flag_arrow_up_xpm));
255 fo->setName("arrow-up");
256 fo->setGroup("standard-arrow");
257 fo->setToolTip(tr("Important","Standardflag"));
258 standardFlagsDefault->addFlag (fo);
260 fo->load(QPixmap(flag_arrow_down_xpm));
261 fo->setName("arrow-down");
262 fo->setGroup("standard-arrow");
263 fo->setToolTip(tr("Unimportant","Standardflag"));
264 standardFlagsDefault->addFlag (fo);
266 fo->load(QPixmap(flag_thumb_up_xpm));
267 fo->setName("thumb-up");
268 fo->setGroup("standard-thumb");
269 fo->setToolTip(tr("I like this","Standardflag"));
270 standardFlagsDefault->addFlag (fo);
272 fo->load(QPixmap(flag_thumb_down_xpm));
273 fo->setName("thumb-down");
274 fo->setGroup("standard-thumb");
275 fo->setToolTip(tr("I like this","Standardflag"));
276 fo->setToolTip(tr("I do not like this","Standardflag"));
277 standardFlagsDefault->addFlag (fo);
279 fo->load(QPixmap(flag_heart_xpm));
280 fo->setName("heart");
281 fo->setToolTip(tr("I just love... ","Standardflag"));
282 standardFlagsDefault->addFlag (fo);
284 fo->load(QPixmap(flag_flash_xpm));
285 fo->setName("flash");
286 fo->setToolTip(tr("Dangerous","Standardflag"));
287 standardFlagsDefault->addFlag (fo);
289 fo->load(QPixmap(flag_lifebelt_xpm));
290 fo->setName("lifebelt");
291 fo->setToolTip(tr("This will help","Standardflag"));
292 standardFlagsDefault->addFlag (fo);
297 mapCenter = new MapCenterObj(mapCanvas);
298 mapCenter->setVisibility (true);
299 mapCenter->setMapEditor (this);
300 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
304 lineedit = new QLineEdit(this, "lineedit" );
305 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
308 actColor=black; setColor (actColor);
309 defLinkColor=QColor (0,0,255);
310 defXLinkColor=QColor (180,180,180);
311 linkcolorhint=DefaultColor;
312 linkstyle=StylePolyParabel;
313 mapCanvas->setBackgroundColor (white);
315 // Create bitmap cursors, patform dependant
316 #if defined(Q_OS_MACX)
317 #include "icons/cursorhandopen16.xpm"
318 #include "icons/cursorcolorpicker16.xpm"
319 QBitmap cb( 16, 16, chandopen, TRUE );
320 QBitmap cm( 16, 16, chandopenmask, TRUE );
321 handOpenCursor=QCursor ( cb, cm );
322 // set hot spot to tip of picker
323 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
325 #include "icons/cursorhandopen.xpm"
326 #include "icons/cursorcolorpicker.xpm"
328 QBitmap cb( 32, 32, chandopen, TRUE );
329 QBitmap cm( 32, 32, chandopenmask, TRUE );
330 handOpenCursor=QCursor ( cb, cm );
331 // set hot spot to tip of picker
332 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
345 defXLinkColor=QColor (230,230,230);
356 // Initialize find routine
363 blockreposition=false;
364 isInteractive=interactive;
366 // Create temporary files
369 // Initially set movingCentre
372 mapCenter->reposition(); // for positioning heading
375 MapEditor::~MapEditor()
377 if (imageBuffer) delete imageBuffer;
383 //cout <<"Destructor MapEditor\n";
384 if (isInteractive) delTmpDirs();
387 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
391 QColor MapEditor::color()
396 QColor MapEditor::backgroundColor()
398 return mapCanvas->backgroundColor();
401 MapCenterObj* MapEditor::getMapCenter()
406 QCanvas* MapEditor::getCanvas()
411 void MapEditor::adjustCanvasSize()
413 // To adjust the canvas to map, viewport size and position, we have to
414 // do some coordinate magic...
416 // Get rectangle of (scroll-)view.
417 // We want to be in canvas coords, so
418 // we map. Important if view is zoomed...
419 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
420 visibleWidth(), visibleHeight()) );
422 // Now we need the bounding box of view AND map to calc the correct canvas size.
423 // Why? Because if the map itself is moved out of view, the view has to be enlarged
424 // to avoid jumping aroung...
425 QRect map=mapCenter->getTotalBBox();
427 // right edge - left edge
428 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
429 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
432 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
433 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
436 // move the map on canvas (in order to not move it on screen) this is neccessary
437 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
438 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
439 // to scroll to an empty area of canvas to the left.
440 // b) if topleft corner of map left of or above topleft of canvas
444 if (cw > mapCanvas->width() )
446 if (map.x()<0) dx=-map.x();
448 if (cw < mapCanvas->width() )
449 dx=-min (view.x(),map.x());
450 if (ch > mapCanvas->height() )
452 if (map.y()<0) dy=-map.y();
454 if (ch < mapCanvas->height() )
456 dy=-min (view.y(),map.y());
458 // We really have to resize now. Let's go...
459 mapCanvas->resize (cw,ch);
460 if ( (dx!=0) || (dy!=0) )
462 mapCenter->moveAllBy(dx,dy);
463 mapCenter->reposition();
465 // scroll the view (in order to not move map on screen)
471 bool MapEditor::blockReposition()
473 return blockreposition;
476 void MapEditor::makeTmpDirs()
478 // Create unique temporary directories
479 char tmpdir[]="/tmp/vym-XXXXXX";
480 bakMapDir=mkdtemp(tmpdir);
481 makeSubDirs(bakMapDir);
482 // FIXME set permissions and maybe use QT method for portability
485 void MapEditor::delTmpDirs()
487 //FIXME delete tmp directory, better use QT methods here:
488 system ( "rm -rf "+ bakMapDir );
492 void MapEditor::makeSubDirs(const QString &s)
500 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
502 // tmpdir temporary directory to which data will be writte
503 // prefix mapname, which will be appended to images etc.
504 // writeflags Only write flags for "real" save of map, not undo
505 // offset offset of bbox of whole map in canvas.
506 // Needed for XML export
507 // completeMap if false, only vympart will be written, without
524 ls="StylePolyParabel";
528 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
530 if (linkcolorhint==HeadingColor)
531 colhint=attribut("linkColorHint","HeadingColor");
533 QString mapAttr=attribut("version",__VYM_VERSION__);
535 mapAttr+= attribut("author",mapCenter->getAuthor()) +
536 attribut("comment",mapCenter->getComment()) +
537 attribut("date",mapCenter->getDate()) +
538 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
539 attribut("linkStyle", ls ) +
540 attribut("linkColor", defLinkColor.name() ) +
541 attribut("defXLinkColor", defXLinkColor.name() ) +
542 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
544 s+=beginElement("vymmap",mapAttr);
547 // Find the used flags while traversing the tree
548 standardFlagsDefault->resetUsedCounter();
550 // Build xml recursivly
552 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
555 if ( typeid(*saveSelection) == typeid(BranchObj) )
556 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
558 if (selection && typeid(*selection)==typeid(BranchObj))
559 // This is used if selected branch is saved from mainwindow
560 s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
563 // Save local settings
564 s+=settings.getXMLData (destPath);
567 if (selection && !saveSelection)
568 s+=valueElement("select",selection->getSelectString());
571 s+=endElement("vymmap");
574 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
578 void MapEditor::saveState()
580 saveState (CompleteMap,NULL,"");
583 void MapEditor::saveState(LinkableMapObj *undoSel)
585 saveState (PartOfMap,undoSel,"");
588 void MapEditor::saveState(const QString & c)
590 saveState (UndoCommand,NULL,c);
593 void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom)
596 if (savemode==UndoCommand)
601 else if (savemode==PartOfMap && undoSel)
603 undoCommand="undoPart (\""+undoSel->getSelectString()+"\")";
604 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
607 undoCommand="undoMap ()";
608 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
611 cout << "ME::saveState()\n";
612 cout << " undoCom="<<undoCommand<<endl;
616 void MapEditor::parseAtom(const QString &atom)
623 // Split string s into command and parameters
624 api.parseCommand (atom);
625 QString com=api.command();
628 if (com==QString("moveBranchUp"))
630 else if (com=="moveBranchDown")
632 else if (com=="move")
634 if (api.checkParamCount(2) &&
645 else if (com=="linkBranchToPos")
647 if (selection && typeid(*selection) == typeid(BranchObj) )
649 if (api.checkParamCount(4))
651 s=api.parString(ok,0);
652 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
655 if (typeid(*dst) == typeid(BranchObj) )
656 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
657 if (typeid(*dst) == typeid(MapCenterObj) )
659 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
664 if (ok) ((BranchObj*)(selection))->move (x,y);
670 } else if (com=="setHeading")
672 if (api.checkParamCount(1))
674 s=api.parString (ok,0);
675 if (ok) setHeading (s);
678 // Internal commands, used for undo etc.
679 else if (com==QString("undoMap"))
681 else if (com==QString("undoPart"))
683 if (api.checkParamCount(1))
685 s=api.parString (ok,0);
688 } else if (com=="select")
689 if (api.checkParamCount(1))
691 s=api.parString(ok,0);
695 api.setError ("Unknown command in: "+atom);
700 cout << "MapEditor::parseAtom: Error!\n";
701 cout << " "<<api.errorDesc()<<endl;
706 void MapEditor::finishedLineEditNoSave()
708 // This is called by finishedLineEdit or any MapEditor method,
709 // which wants to assure, that lineedits finish, before e.g. a branch is
712 // After calling LineEdit and using the clipboard, the
713 // focus is not any longer on the main widget, we
714 // have to restore it using parentWidget()->setFocus()
718 editingBO->setHeading(lineedit->text() );
720 lineedit->releaseKeyboard();
722 parentWidget()->setFocus();
723 mapCenter->reposition();
725 ensureSelectionVisible();
730 bool MapEditor::isDefault()
735 bool MapEditor::isUnsaved()
740 bool MapEditor::hasChanged()
745 void MapEditor::setChanged()
750 actionEditUndo->setEnabled (true);
751 actionFileSave->setEnabled (true);
755 void MapEditor::closeMap()
757 // Finish open lineEdits
758 if (lineedit) finishedLineEditNoSave();
760 // Unselect before disabling the toolbar actions
761 if (selection) selection->unselect();
769 void MapEditor::setFilePath(QString fname)
771 setFilePath (fname,fname);
774 void MapEditor::setFilePath(QString fname, QString destname)
783 filePath=fname; // becomes absolute path
784 fileName=fname; // gets stripped of path
785 destPath=destname; // needed for vymlinks
787 // If fname is not an absolute path, complete it
788 filePath=QDir(fname).absPath();
789 fileDir=filePath.left (1+filePath.findRev ("/"));
791 // Set short name, too. Search from behind:
792 int i=fileName.findRev("/");
793 if (i>=0) fileName=fileName.remove (0,i+1);
795 // Forget the .vym (or .xml) for name of map
796 mapName=fileName.left(fileName.findRev(".",-1,true) );
800 QString MapEditor::getFilePath()
805 QString MapEditor::getFileName()
810 QString MapEditor::getMapName()
815 QString MapEditor::getDestPath()
820 int MapEditor::load (QString &fname, const LoadMode &lmode)
822 // Finish open lineEdits
823 if (lineedit) finishedLineEditNoSave();
829 if (selection) selection->unselect();
832 mapCenter->setMapEditor(this);
833 // (map state is set later at end of load...)
836 saveState(selection);
840 mapBuilderHandler handler;
843 // I am paranoid: file should exist anyway
844 // according to check in mainwindow.
847 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
848 tr("Couldn't open map " +fname)+".");
852 blockreposition=true;
853 QXmlInputSource source( file);
854 QXmlSimpleReader reader;
855 reader.setContentHandler( &handler );
856 reader.setErrorHandler( &handler );
857 handler.setMapEditor( this );
858 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
859 handler.setLoadMode (lmode);
860 bool ok = reader.parse( source );
861 blockreposition=false;
865 mapCenter->reposition();
875 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
876 tr( handler.errorProtocol() ) );
878 // Still return "success": the map maybe at least
879 // partially read by the parser
886 int MapEditor::save (const SaveMode &savemode)
888 // Finish open lineEdits
889 if (lineedit) finishedLineEditNoSave();
893 // The SaveMode UndoCommand is not supported here
894 if (savemode==UndoCommand) return 1;
896 // Create mapName and fileDir
897 makeSubDirs (fileDir);
901 fname=mapName+".xml";
903 // use name given by user, even if he chooses .doc
907 // Check if fname is writeable
908 QFile file( fileDir+fname);
909 if (!file.open( IO_WriteOnly ) )
911 QMessageBox::critical( 0, tr( "Critical Save Error" ),
912 tr("Couldn't write to ") +fileDir+fname);
918 if (savemode==CompleteMap || selection==NULL)
919 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
921 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
923 file.setName ( fileDir + fname);
924 if ( !file.open( IO_WriteOnly ) )
926 // This should neverever happen
927 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
931 // Write it finally, and write in UTF8, no matter what
932 QTextStream ts( &file );
933 ts.setEncoding (QTextStream::UnicodeUTF8);
941 actionFileSave->setEnabled(false);
947 void MapEditor::setZipped (bool z)
952 bool MapEditor::saveZipped ()
957 void MapEditor::print()
959 // Finish open lineEdits
960 if (lineedit) finishedLineEditNoSave();
964 printer = new QPrinter;
965 printer->setColorMode (QPrinter::Color);
966 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
969 QRect totalBBox=mapCenter->getTotalBBox();
971 // Try to set orientation automagically
972 // Note: Interpretation of generated postscript is amibiguous, if
973 // there are problems with landscape mode, see
974 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
976 if (totalBBox.width()>totalBBox.height())
977 // recommend landscape
978 printer->setOrientation (QPrinter::Landscape);
980 // recommend portrait
981 printer->setOrientation (QPrinter::Portrait);
983 if ( printer->setup(this) )
984 // returns false, if printing is canceled
986 QPainter pp(printer);
988 // Don't print the visualisation of selection
989 LinkableMapObj *oldselection=NULL;
992 oldselection=selection;
993 selection->unselect();
996 // Handle sizes of map and paper:
998 // setWindow defines which part of the canvas will be transformed
999 // setViewport defines area on paper in device coordinates (dpi)
1000 // e.g. (0,50,700,700) is upper part on A4
1001 // see also /usr/lib/qt3/doc/html/coordsys.html
1003 QPaintDeviceMetrics metrics (printer);
1005 double paperAspect = (double)metrics.width() / (double)metrics.height();
1006 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1008 QRect mapRect=totalBBox;
1009 QCanvasRectangle *frame=NULL;
1010 QCanvasText *footerFN=NULL;
1011 QCanvasText *footerDate=NULL;
1012 if (printFrame || printFooter)
1017 // Print frame around map
1018 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1019 totalBBox.width()+20, totalBBox.height()+20);
1020 frame=new QCanvasRectangle (mapRect,mapCanvas);
1021 frame->setBrush (QColor(white));
1022 frame->setPen (QColor(black));
1027 QCanvasLine *l=new QCanvasLine (mapCanvas);
1028 l->setPoints (0,0,mapRect.width(),mapRect.height());
1029 l->setPen (QPen(QColor(black), 1));
1036 // Print footer below map
1038 font.setPointSize(10);
1039 footerFN=new QCanvasText (mapCanvas);
1040 footerFN->setText ("VYM - " + fileName);
1041 footerFN->setFont(font);
1042 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1043 footerFN->setZ(Z_TEXT);
1045 footerDate=new QCanvasText (mapCanvas);
1046 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1047 footerDate->setFont(font);
1048 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1049 footerDate->setZ(Z_TEXT);
1052 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1055 pp.setWindow (mapRect);
1058 if (mapAspect>=paperAspect)
1060 // Fit horizontally to paper width
1061 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1064 // Fit vertically to paper height
1065 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1068 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1070 // Delete Frame and footer
1074 delete (footerDate);
1076 if (frame) delete (frame);
1078 // Restore selection
1081 selection=oldselection;
1082 selection->select();
1085 // Save settings in vymrc
1086 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1090 QPixmap MapEditor::getPixmap()
1092 QRect mapRect=mapCenter->getTotalBBox();
1093 QPixmap pix (mapRect.size());
1096 // Don't print the visualisation of selection
1097 LinkableMapObj *oldselection=NULL;
1100 oldselection=selection;
1101 selection->unselect();
1104 pp.setWindow (mapRect);
1106 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1109 // Restore selection
1112 selection=oldselection;
1113 selection->select();
1119 void MapEditor::exportImage(QString fn)
1121 // Finish open lineEdits
1122 if (lineedit) finishedLineEditNoSave();
1124 QPixmap pix (getPixmap());
1125 pix.save(fn, "PNG");
1128 void MapEditor::exportImage(QString fn, int item)
1130 // Finish open lineEdits
1131 if (lineedit) finishedLineEditNoSave();
1133 QPixmap pix (getPixmap());
1134 pix.save(fn, exportImageFormatMenu->text(item) );
1137 void MapEditor::exportASCII()
1139 // FIXME still experimental
1141 ex.setMapCenter(mapCenter);
1143 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
1144 fd->addFilter ("TXT (*.txt)");
1145 fd->setCaption("VYM - Export (ASCII) (still experimental)");
1146 fd->setMode( QFileDialog::AnyFile );
1149 if ( fd->exec() == QDialog::Accepted )
1151 if (QFile (fd->selectedFile()).exists() )
1153 QMessageBox mb( "VYM",
1154 tr("The file ") + fd->selectedFile() +
1155 tr(" exists already. Do you want to overwrite it?"),
1156 QMessageBox::Warning,
1157 QMessageBox::Yes | QMessageBox::Default,
1158 QMessageBox::Cancel | QMessageBox::Escape,
1159 QMessageBox::NoButton );
1161 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1162 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1166 case QMessageBox::Yes:
1169 case QMessageBox::Cancel:
1170 // return, do nothing
1175 ex.setPath (fd->selectedFile() );
1181 void MapEditor::exportXML(const QString &dir)
1183 // Create subdirectories
1186 // write to directory
1187 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1190 file.setName ( dir + "/"+mapName+".xml");
1191 if ( !file.open( IO_WriteOnly ) )
1193 // This should neverever happen
1194 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1198 // Write it finally, and write in UTF8, no matter what
1199 QTextStream ts( &file );
1200 ts.setEncoding (QTextStream::UnicodeUTF8);
1204 // Now write image, too
1205 exportImage (dir+"/images/"+mapName+".png");
1208 void MapEditor::clear()
1212 selection->unselect();
1219 void MapEditor::copy()
1221 // Finish open lineEdits
1222 if (lineedit) finishedLineEditNoSave();
1226 if (typeid(*selection) == typeid(BranchObj) )
1230 clipboardME->clear();
1231 clipboardME->getMapCenter()->addBranch();
1232 to=clipboardME->getMapCenter()->getLastBranch();
1235 from=(BranchObj*)(selection);
1238 // keep position relative to parent
1239 to->move2RelPos ( from->getRelPos());
1241 // select data in clipboard
1242 clipboardME->select ("bo:0");
1244 // repositioning makes testing nicer,
1245 // but is not needed usually:
1246 if (clipboardME->isVisible())
1248 clipboardME->getMapCenter()->reposition();
1251 clipboardME->hide();
1254 if (typeid(*selection) == typeid(FloatImageObj) )
1257 FloatImageObj* from;
1258 clipboardME->clear();
1259 clipboardME->getMapCenter()->addFloatImage();
1260 to=clipboardME->getMapCenter()->getLastFloatImage();
1263 from=(FloatImageObj*)(selection);
1266 // select data in clipboard
1267 clipboardME->select ("fi:0");
1269 // repositioning makes testing nicer,
1270 // but is not needed usually:
1271 if (clipboardME->isVisible())
1273 clipboardME->getMapCenter()->reposition();
1276 clipboardME->hide();
1282 void MapEditor::undo()
1284 // Finish open lineEdits
1285 if (lineedit) finishedLineEditNoSave();
1287 parseAtom (undoCommand);
1288 mapCenter->reposition();
1290 // Undo not longer available now
1291 actionEditUndo->setEnabled (false);
1296 void MapEditor::undoXML(const QString &undoSel)
1299 d.setPath(bakMapDir);
1302 // We need to parse saved XML data
1303 mapBuilderHandler handler;
1304 QXmlInputSource source;
1305 source.setData(backupXML);
1306 QXmlSimpleReader reader;
1307 reader.setContentHandler( &handler );
1308 reader.setErrorHandler( &handler );
1309 handler.setMapEditor( this );
1310 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1311 if (undoSel.isEmpty())
1314 handler.setLoadMode (NewMap);
1318 handler.setLoadMode (ImportReplace);
1320 blockreposition=true;
1321 bool ok = reader.parse( source );
1322 blockreposition=false;
1325 // This should never ever happen
1326 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1327 tr( handler.errorProtocol() )+" in "+backupXML );
1331 QMessageBox::critical( 0, tr( "Critical Error" ),
1332 "Temporary directory " +bakMapDir +
1333 tr (" used for undo is gone. \n"
1334 "I will create a new one, but at the moment no undo is available.\n"
1335 "Maybe you want to reload your original data.\n\n"
1336 "Sorry for any inconveniences.") );
1341 LinkableMapObj* MapEditor::pasteNoSave()
1343 // Finish open lineEdits
1344 if (lineedit) finishedLineEditNoSave();
1346 LinkableMapObj *fromLMO=clipboardME->getSelection();
1347 LinkableMapObj *returnLMO=NULL;
1349 if (selection && fromLMO)
1351 if (typeid(*fromLMO) == typeid(BranchObj) )
1353 if (typeid(*selection) == typeid(MapCenterObj))
1355 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1356 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1358 if (typeid(*selection) == typeid(BranchObj))
1359 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1362 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1363 (typeid(*selection) == typeid (BranchObj) ||
1364 typeid(*selection)==typeid(MapCenterObj)) )
1365 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1371 void MapEditor::cutNoSave()
1373 // Finish open lineEdits
1374 if (lineedit) finishedLineEditNoSave();
1378 if (selection != NULL) {
1379 if (typeid(*selection) == typeid(BranchObj) )
1381 bo=(BranchObj*)(selection);
1382 par=(BranchObj*)(bo->getParObj());
1385 par->removeBranch(bo);
1387 selection->select();
1389 if (typeid(*selection) == typeid(FloatImageObj) )
1391 FloatImageObj* fio=(FloatImageObj*)(selection);
1392 par=(BranchObj*)(fio->getParObj());
1395 par->removeFloatImage(fio);
1397 selection->select();
1402 void MapEditor::paste()
1404 saveState(selection);
1406 mapCenter->reposition();
1410 void MapEditor::cut()
1412 saveState(selection->getParObj());
1415 mapCenter->reposition();
1419 void MapEditor::move(const int &x, const int &y)
1421 // FIXME no saveState, because this is only internal at undo so far
1422 if (selection) selection->move(x,y);
1423 if (typeid(*selection) == typeid(FloatImageObj))
1424 ((FloatImageObj*)(selection))->setRelPos();
1427 void MapEditor::moveBranchUp()
1429 // Finish open lineEdits
1430 if (lineedit) finishedLineEditNoSave();
1434 if (typeid(*selection) == typeid(BranchObj) )
1436 saveState("moveBranchDown ()");
1437 bo=(BranchObj*)(selection);
1438 par=(BranchObj*)(bo->getParObj());
1439 selection->unselect();
1440 selection=par->moveBranchUp (bo);
1441 selection->select();
1442 mapCenter->reposition();
1443 ensureSelectionVisible();
1447 void MapEditor::moveBranchDown()
1449 // Finish open lineEdits
1450 if (lineedit) finishedLineEditNoSave();
1454 if (typeid(*selection) == typeid(BranchObj) )
1456 saveState("moveBranchUp ()");
1457 bo=(BranchObj*)(selection);
1458 par=(BranchObj*)(bo->getParObj());
1459 selection->unselect();
1460 selection=par->moveBranchDown(bo);
1461 selection->select();
1462 mapCenter->reposition();
1463 ensureSelectionVisible();
1467 void MapEditor::editHeading()
1469 // Finish open lineEdits
1470 if (lineedit) finishedLineEditNoSave();
1473 (typeid(*selection) == typeid(BranchObj) ||
1474 typeid(*selection) == typeid(MapCenterObj) ) )
1476 saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")");
1478 ensureSelectionVisible();
1479 editingBO=(BranchObj*)(selection);
1480 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1481 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1482 QString s=editingBO->getHeading();
1483 lineedit->setText(s);
1484 lineedit->setCursorPosition(1);
1485 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1486 lineedit->selectAll();
1489 lineedit->grabKeyboard();
1490 lineedit->setFocus();
1494 void MapEditor::setHeading(const QString &s)
1496 // Internal function, no saveState needed
1498 (typeid(*selection) == typeid(BranchObj) ||
1499 typeid(*selection) == typeid(MapCenterObj) ) )
1501 ((BranchObj*)(selection))->setHeading(s);
1502 mapCenter->reposition();
1504 ensureSelectionVisible();
1508 void MapEditor::addNewBranch(int pos)
1510 // Finish open lineEdits
1511 if (lineedit) finishedLineEditNoSave();
1514 (typeid(*selection) == typeid(BranchObj) ||
1515 typeid(*selection) == typeid(MapCenterObj) ) )
1517 saveState(selection);
1519 BranchObj* bo1 = (BranchObj*) (selection);
1520 bool wasScrolled=false;
1521 BranchObj *newbo=NULL;
1524 // save scroll state. If scrolled, automatically select
1525 // new branch in order to tmp unscroll parent...
1526 wasScrolled=bo1->isScrolled();
1527 newbo=bo1->addBranch();
1530 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1534 // add above selection
1535 newbo=parbo->insertBranch(bo1->getNum());
1537 // add below selection
1538 newbo=parbo->insertBranch(bo1->getNum()+1);
1540 // This should not happen...
1545 LinkableMapObj *oldselection=selection;
1547 mapCenter->reposition();
1549 if (actionSettingsAutoedit->isOn() ||
1550 actionSettingsAutoselectHeading->isOn() )
1552 selection->unselect();
1554 selection->select();
1555 if (actionSettingsPasteNewHeading->isOn() )
1557 BranchObj *bo2= (BranchObj*)(selection);
1558 bo2->setHeading("");
1560 if (actionSettingsAutoedit->isOn() )
1562 if (!actionSettingsAutoselectHeading->isOn()
1565 selection->unselect();
1566 selection=oldselection;
1567 selection->select();
1574 void MapEditor::addNewBranchHere()
1576 // Finish open lineEdits
1577 if (lineedit) finishedLineEditNoSave();
1580 (typeid(*selection) == typeid(BranchObj) ) )
1582 saveState(selection);
1584 BranchObj* bo1 = (BranchObj*) (selection);
1585 bool wasScrolled=false;
1586 BranchObj *newbo=NULL;
1587 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1590 // add below selection
1591 newbo=parbo->insertBranch(bo1->getNum()+1);
1594 LinkableMapObj *oldselection=selection;
1595 ((BranchObj*)(selection))->moveBranchTo (newbo,-1);
1597 mapCenter->reposition();
1599 if (actionSettingsAutoedit->isOn() ||
1600 actionSettingsAutoselectHeading->isOn() )
1602 selection->unselect();
1604 selection->select();
1605 if (actionSettingsPasteNewHeading->isOn() )
1607 BranchObj *bo2= (BranchObj*)(selection);
1608 bo2->setHeading("");
1610 if (actionSettingsAutoedit->isOn() )
1612 if (!actionSettingsAutoselectHeading->isOn()
1615 selection->unselect();
1616 selection=oldselection;
1617 selection->select();
1623 void MapEditor::deleteSelection()
1625 // Finish open lineEdits
1626 if (lineedit) finishedLineEditNoSave();
1628 if (selection && typeid(*selection) ==typeid(BranchObj) )
1630 saveState(selection->getParObj());
1631 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1632 BranchObj* par=(BranchObj*)(bo->getParObj());
1635 par->removeBranch(bo);
1637 selection->select();
1638 ensureSelectionVisible();
1639 mapCenter->reposition();
1642 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1644 saveState(selection->getParObj());
1645 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1646 BranchObj* par=(BranchObj*)(fio->getParObj());
1649 par->removeFloatImage(fio);
1651 selection->select();
1652 ensureSelectionVisible();
1653 mapCenter->reposition();
1658 LinkableMapObj* MapEditor::getSelection()
1663 bool MapEditor::select (const QString &s)
1665 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1667 // Finally select the found object
1670 if (selection) unselect();
1672 selection->select();
1674 ensureSelectionVisible();
1680 void MapEditor::unselect()
1684 selectionLast=selection;
1685 selection->unselect();
1690 void MapEditor::reselect()
1694 selection=selectionLast;
1695 selection->select();
1700 void MapEditor::selectNextBranch()
1702 // Increase number of branch
1705 QString s=selection->getSelectString();
1711 part=s.section(",",-1);
1713 num=part.right(part.length() - 3);
1715 s=s.left (s.length() -num.length());
1718 num=QString ("%1").arg(num.toUInt()+1);
1722 // Try to select this one
1723 if (select (s)) return;
1725 // We have no direct successor,
1726 // try to increase the parental number in order to
1727 // find a successor with same depth
1729 int d=selection->getDepth();
1734 while (!found && d>0)
1736 s=s.section (",",0,d-1);
1737 // replace substring of current depth in s with "1"
1738 part=s.section(",",-1);
1740 num=part.right(part.length() - 3);
1744 // increase number of parent
1745 num=QString ("%1").arg(num.toUInt()+1);
1746 s=s.section (",",0,d-2) + ","+ typ+num;
1749 // Special case, look at orientation
1750 if (selection->getOrientation()==OrientRightOfCenter)
1751 num=QString ("%1").arg(num.toUInt()+1);
1753 num=QString ("%1").arg(num.toUInt()-1);
1758 // pad to oldDepth, select the first branch for each depth
1759 for (i=d;i<oldDepth;i++)
1764 if ( ((BranchObj*)(selection))->countBranches()>0)
1772 // try to select the freshly built string
1780 void MapEditor::selectPrevBranch()
1782 // Decrease number of branch
1785 QString s=selection->getSelectString();
1791 part=s.section(",",-1);
1793 num=part.right(part.length() - 3);
1795 s=s.left (s.length() -num.length());
1798 num=QString ("%1").arg(num.toUInt()-1);
1802 // Try to select this one
1803 if (select (s)) return;
1805 // We have no direct precessor,
1806 // try to decrease the parental number in order to
1807 // find a precessor with same depth
1809 int d=selection->getDepth();
1814 while (!found && d>0)
1816 s=s.section (",",0,d-1);
1817 // replace substring of current depth in s with "1"
1818 part=s.section(",",-1);
1820 num=part.right(part.length() - 3);
1824 // decrease number of parent
1825 num=QString ("%1").arg(num.toUInt()-1);
1826 s=s.section (",",0,d-2) + ","+ typ+num;
1829 // Special case, look at orientation
1830 if (selection->getOrientation()==OrientRightOfCenter)
1831 num=QString ("%1").arg(num.toUInt()-1);
1833 num=QString ("%1").arg(num.toUInt()+1);
1838 // pad to oldDepth, select the last branch for each depth
1839 for (i=d;i<oldDepth;i++)
1843 if ( ((BranchObj*)(selection))->countBranches()>0)
1844 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1851 // try to select the freshly built string
1859 void MapEditor::selectUpperBranch()
1861 // Finish open lineEdits
1862 if (lineedit) finishedLineEditNoSave();
1866 if (typeid(*selection) == typeid(BranchObj))
1868 if (selection->getOrientation()==OrientRightOfCenter)
1871 if (selection->getDepth()==1)
1879 void MapEditor::selectLowerBranch()
1881 // Finish open lineEdits
1882 if (lineedit) finishedLineEditNoSave();
1886 if (typeid(*selection) == typeid(BranchObj))
1888 if (selection->getOrientation()==OrientRightOfCenter)
1891 if (selection->getDepth()==1)
1900 void MapEditor::selectLeftBranch()
1902 // Finish open lineEdits
1903 if (lineedit) finishedLineEditNoSave();
1909 if (typeid(*selection) == typeid(MapCenterObj))
1911 par= (BranchObj*) (selection);
1912 bo=par->getLastSelectedBranch();
1915 // Workaround for reselecting on left and right side
1916 if (bo->getOrientation()==OrientRightOfCenter)
1918 bo=par->getLastBranch();
1924 selection->select();
1926 ensureSelectionVisible();
1931 par=(BranchObj*)(selection->getParObj());
1932 if (selection->getOrientation()==OrientRightOfCenter)
1934 if (typeid(*selection) == typeid(BranchObj) ||
1935 typeid(*selection) == typeid(FloatImageObj))
1937 selection->unselect();
1939 selection->select();
1941 ensureSelectionVisible();
1945 if (typeid(*selection) == typeid(BranchObj) )
1947 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1950 selection->unselect();
1952 selection->select();
1954 ensureSelectionVisible();
1962 void MapEditor::selectRightBranch()
1964 // Finish open lineEdits
1965 if (lineedit) finishedLineEditNoSave();
1972 if (typeid(*selection) == typeid(MapCenterObj))
1974 par= (BranchObj*) (selection);
1975 bo=par->getLastSelectedBranch();
1978 // Workaround for relecting on left and right side
1979 if (bo->getOrientation()==OrientLeftOfCenter)
1980 bo=par->getFirstBranch();
1985 selection->select();
1986 ensureSelectionVisible();
1991 par=(BranchObj*)(selection->getParObj());
1992 if (selection->getOrientation()==OrientLeftOfCenter)
1994 if (typeid(*selection) == typeid(BranchObj) ||
1995 typeid(*selection) == typeid(FloatImageObj))
1997 selection->unselect();
1999 selection->select();
2001 ensureSelectionVisible();
2005 if (typeid(*selection) == typeid(BranchObj) )
2007 bo=((BranchObj*)(selection))->getLastSelectedBranch();
2010 selection->unselect();
2012 selection->select();
2014 ensureSelectionVisible();
2022 void MapEditor::selectFirstBranch()
2024 // Finish open lineEdits
2025 if (lineedit) finishedLineEditNoSave();
2031 if (typeid(*selection) == typeid(BranchObj))
2033 bo1= (BranchObj*) (selection);
2034 par=(BranchObj*)(bo1->getParObj());
2035 bo2=par->getFirstBranch();
2039 selection->select();
2040 ensureSelectionVisible();
2047 void MapEditor::selectLastBranch()
2049 // Finish open lineEdits
2050 if (lineedit) finishedLineEditNoSave();
2056 if (typeid(*selection) == typeid(BranchObj))
2058 bo1= (BranchObj*) (selection);
2059 par=(BranchObj*)(bo1->getParObj());
2060 bo2=par->getLastBranch();
2064 selection->select();
2065 ensureSelectionVisible();
2072 void MapEditor::setColor(QColor c)
2077 void MapEditor::selectBackgroundColor()
2079 // Finish open lineEdits
2080 if (lineedit) finishedLineEditNoSave();
2082 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2083 if ( !col.isValid() ) return;
2084 setBackgroundColor( col );
2088 void MapEditor::setBackgroundColor(QColor c)
2090 mapCanvas->setBackgroundColor (c);
2093 QColor MapEditor::pickColor()
2097 if (typeid(*selection) == typeid(BranchObj) ||
2098 typeid(*selection) == typeid(MapCenterObj))
2100 BranchObj *bo=(BranchObj*)(selection);
2101 actColor=bo->getColor();
2107 void MapEditor::colorItem()
2111 if (typeid(*selection) == typeid(BranchObj) ||
2112 typeid(*selection) == typeid(MapCenterObj))
2114 saveState(selection);
2115 BranchObj *bo=(BranchObj*)(selection);
2116 bo->setColor(actColor, false); // color links, color childs
2121 void MapEditor::colorBranch()
2125 if (typeid(*selection) == typeid(BranchObj) ||
2126 typeid(*selection) == typeid(MapCenterObj))
2128 saveState(selection);
2129 BranchObj *bo=(BranchObj*)(selection);
2130 bo->setColor(actColor, true); // color links, color childs
2136 void MapEditor::toggleStandardFlag(QString f)
2140 saveState(selection);
2141 ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2145 void MapEditor::setViewCenter()
2147 // transform to CanvasView Coord:
2148 QPoint p=worldMatrix().map(movingCenter);
2149 center ( p.x(), p.y());
2153 BranchObj* MapEditor::findText (QString s, bool cs)
2156 { // Nothing found or new find process
2158 // nothing found, start again
2160 itFind=mapCenter->first();
2162 bool searching=true;
2163 bool foundNote=false;
2164 while (searching && !EOFind)
2168 // Searching in Note
2169 if (itFind->getNote().contains(s,cs))
2171 if (selection!=itFind)
2173 if (selection) ((BranchObj*)(selection))->unselect();
2175 selection->select();
2177 ensureSelectionVisible();
2179 if (textEditor->findText(s,cs))
2185 // Searching in Heading
2186 if (searching && itFind->getHeading().contains (s,cs) )
2188 if (selection) ((BranchObj*)(selection))->unselect();
2190 selection->select();
2192 ensureSelectionVisible();
2198 itFind=itFind->next();
2199 if (!itFind) EOFind=true;
2205 return (BranchObj*)(selection);
2210 void MapEditor::findReset()
2211 { // Necessary if text to find changes during a find process
2216 void MapEditor::openURL()
2220 if (typeid(*selection) == typeid(BranchObj) ||
2221 typeid(*selection) == typeid(MapCenterObj))
2223 QString url=((BranchObj*)(selection))->getURL();
2225 QProcess *proc = new QProcess( this );
2227 #if !defined(Q_OS_MACX)
2228 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2230 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2231 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2234 proc->addArgument( url);
2236 if ( !proc->start() )
2238 if (mainWindow->settingsURL() )
2244 void MapEditor::editURL()
2246 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2247 typeid(*selection) == typeid(MapCenterObj)) )
2250 QString text = QInputDialog::getText(
2251 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2252 ((BranchObj*)(selection))->getURL(), &ok, this );
2255 // user entered something and pressed OK
2256 ((BranchObj*)(selection))->setURL (text);
2258 saveState(); //FIXME undoCommand
2263 void MapEditor::editHeading2URL()
2265 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2266 typeid(*selection) == typeid(MapCenterObj)) )
2268 BranchObj *b=(BranchObj*)(selection);
2269 b->setURL (b->getHeading());
2271 saveState(); //FIXME undoCommand
2275 void MapEditor::editBugzilla2URL()
2277 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2278 typeid(*selection) == typeid(MapCenterObj)) )
2280 BranchObj *b=(BranchObj*)(selection);
2281 b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
2283 saveState(); //FIXME undoCommand
2287 void MapEditor::editVymLink()
2289 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2290 typeid(*selection) == typeid(MapCenterObj)) )
2292 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2293 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2294 fd->setCaption(tr("VYM - Link to another map"));
2295 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2296 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2300 if ( fd->exec() == QDialog::Accepted )
2301 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2303 mapCenter->reposition();
2306 saveState(); //FIXME undoCommand
2310 void MapEditor::deleteVymLink()
2312 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2313 typeid(*selection) == typeid(MapCenterObj)) )
2315 ((BranchObj*)(selection))->setVymLink ("" );
2317 mapCenter->reposition();
2320 saveState(); //FIXME undoCommand
2324 QString MapEditor::getVymLink()
2326 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2327 typeid(*selection) == typeid(MapCenterObj)) )
2329 return ((BranchObj*)(selection))->getVymLink();
2335 void MapEditor::removeBranchHere()
2337 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2339 saveState(selection->getParObj());
2340 QString sel=selection->getSelectString();
2341 BranchObj* bo=(BranchObj*)(selection);
2342 BranchObj* par=(BranchObj*)(bo->getParObj());
2344 par->removeBranchHere(bo);
2345 mapCenter->reposition();
2350 void MapEditor::removeChilds()
2352 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2354 saveState(selection->getParObj());
2355 ((BranchObj*)(selection))->removeChilds();
2356 mapCenter->reposition();
2360 void MapEditor::editMapInfo()
2362 ExtraInfoDialog dia;
2363 dia.setMapName (getFileName() );
2364 dia.setAuthor (mapCenter->getAuthor() );
2365 dia.setComment(mapCenter->getComment() );
2370 QCanvasItemList l=canvas()->allItems();
2371 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2373 stats+=QString ("%1 items on canvas\n").arg (i,6);
2380 bo=mapCenter->first();
2383 if (!bo->getNote().isEmpty() ) n++;
2384 f+= bo->countFloatImages();
2386 xl+=bo->countXLinks();
2389 stats+=QString ("%1 branches\n").arg (b-1,6);
2390 stats+=QString ("%1 xLinks \n").arg (xl,6);
2391 stats+=QString ("%1 notes\n").arg (n,6);
2392 stats+=QString ("%1 images\n").arg (f,6);
2393 dia.setStats (stats);
2395 // Finally show dialog
2396 if (dia.exec() == QDialog::Accepted)
2398 mapCenter->setAuthor (dia.getAuthor() );
2399 mapCenter->setComment (dia.getComment() );
2400 saveState(); //FIXME undoCommand
2404 void MapEditor::updateActions()
2407 if (getLinkColorHint()==HeadingColor)
2408 actionFormatLinkColorHint->setOn(true);
2410 actionFormatLinkColorHint->setOn(false);
2415 actionFormatLinkStyleLine->setOn(true);
2418 actionFormatLinkStyleParabel->setOn(true);
2421 actionFormatLinkStylePolyLine->setOn(true);
2423 case StylePolyParabel:
2424 actionFormatLinkStylePolyParabel->setOn(true);
2430 QPixmap pix( 16, 16 );
2431 pix.fill( mapCanvas->backgroundColor() );
2432 actionFormatBackColor->setIconSet( pix );
2433 pix.fill( defLinkColor );
2434 actionFormatLinkColor->setIconSet( pix );
2436 actionEditUndo->setEnabled( mapChanged );
2437 actionFileSave->setEnabled( mapUnsaved );
2441 if ( (typeid(*selection) == typeid(BranchObj)) ||
2442 (typeid(*selection) == typeid(MapCenterObj)) )
2444 BranchObj *bo=(BranchObj*)(selection);
2445 // Take care of links
2446 if (bo->countXLinks()==0)
2448 branchLinksContextMenu->clear();
2449 branchLinksContextMenu->insertItem ("No xLink available");
2450 branchLinksContextMenuDup->clear();
2451 branchLinksContextMenuDup->insertItem ("No xLink available");
2457 branchLinksContextMenu->clear();
2458 branchLinksContextMenuDup->clear();
2459 for (int i=0; i<=bo->countXLinks();i++)
2461 bot=bo->XLinkTargetAt(i);
2464 s=bot->getHeading();
2467 branchLinksContextMenu->insertItem (s);
2468 branchLinksContextMenuDup->insertItem (s);
2473 standardFlagsDefault->setEnabled (true);
2475 if ( bo->getURL().isEmpty() )
2476 actionEditOpenURL->setEnabled (false);
2478 actionEditOpenURL->setEnabled (true);
2480 if ( bo->getVymLink().isEmpty() )
2482 actionEditOpenVymLink->setEnabled (false);
2483 actionEditDeleteVymLink->setEnabled (false);
2486 actionEditOpenVymLink->setEnabled (true);
2487 actionEditDeleteVymLink->setEnabled (true);
2490 actionEditCopy->setEnabled (true);
2491 actionEditCut->setEnabled (true);
2492 if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
2493 actionEditPaste->setEnabled (true);
2495 actionEditPaste->setEnabled (false);
2496 for (a=actionListBranches.first();a;a=actionListBranches.next())
2497 a->setEnabled(true);
2498 actionEditDelete->setEnabled (true);
2499 actionEditToggleFloatExport->setEnabled (false);
2500 switch (selection->getFrameType())
2503 actionFormatFrameNone->setOn(true);
2506 actionFormatFrameRectangle->setOn(true);
2512 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2514 standardFlagsDefault->setEnabled (false);
2516 actionEditOpenURL->setEnabled (false);
2517 actionEditOpenVymLink->setEnabled (false);
2518 actionEditDeleteVymLink->setEnabled (false);
2520 actionEditCopy->setEnabled (true);
2521 actionEditCut->setEnabled (true);
2522 actionEditPaste->setEnabled (false); //FIXME
2523 for (a=actionListBranches.first();a;a=actionListBranches.next())
2524 a->setEnabled(false);
2525 actionEditDelete->setEnabled (true);
2526 actionEditToggleFloatExport->setOn
2527 ( ((FloatImageObj*)(selection))->getFloatExport() );
2532 standardFlagsDefault->setEnabled (false);
2534 actionEditCopy->setEnabled (false);
2535 actionEditCut->setEnabled (false);
2536 actionEditPaste->setEnabled (false);
2537 for (a=actionListBranches.first();a;a=actionListBranches.next())
2538 a->setEnabled(false);
2540 actionEditOpenURL->setEnabled (false);
2541 actionEditOpenVymLink->setEnabled (false);
2542 actionEditDeleteVymLink->setEnabled (false);
2543 actionEditHeading2URL->setEnabled (false);
2544 actionEditDelete->setEnabled (false);
2545 actionEditToggleFloatExport->setEnabled (false);
2549 void MapEditor::setLinkStyle (LinkStyle ls)
2555 bo=mapCenter->first();
2559 bo->setLinkStyle(bo->getDefLinkStyle());
2562 mapCenter->reposition();
2565 LinkStyle MapEditor::getLinkStyle ()
2570 void MapEditor::setLinkColor(QColor c)
2576 void MapEditor::setLinkColorHint()
2578 // called from setLinkColorHint(lch) or at end of parse
2580 bo=mapCenter->first();
2588 void MapEditor::setLinkColorHint(LinkColorHint lch)
2594 void MapEditor::toggleLinkColorHint()
2596 if (linkcolorhint==HeadingColor)
2597 linkcolorhint=DefaultColor;
2599 linkcolorhint=HeadingColor;
2601 bo=mapCenter->first();
2609 LinkColorHint MapEditor::getLinkColorHint()
2611 return linkcolorhint;
2614 QColor MapEditor::getDefLinkColor()
2616 return defLinkColor;
2619 void MapEditor::setDefXLinkColor(QColor col)
2624 QColor MapEditor::getDefXLinkColor()
2626 return defXLinkColor;
2629 void MapEditor::setDefXLinkWidth (int w)
2634 int MapEditor::getDefXLinkWidth()
2636 return defXLinkWidth;
2639 void MapEditor::selectLinkColor()
2641 // Finish open lineEdits
2642 if (lineedit) finishedLineEditNoSave();
2644 QColor col = QColorDialog::getColor( defLinkColor, this );
2645 if ( !col.isValid() ) return;
2646 setLinkColor( col );
2647 saveState(); //FIXME undoCommand
2651 void MapEditor::toggleScroll()
2653 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2655 BranchObj *bo=((BranchObj*)(selection));
2656 if (bo->countBranches()==0) return;
2657 if (bo->getDepth()==0) return;
2658 saveState(selection);
2665 void MapEditor::unScrollAll()
2668 bo=mapCenter->first();
2671 if (bo->isScrolled()) bo->toggleScroll();
2676 void MapEditor::loadFloatImage ()
2679 (typeid(*selection) == typeid(BranchObj)) ||
2680 (typeid(*selection) == typeid(MapCenterObj)) )
2682 BranchObj *bo=((BranchObj*)(selection));
2684 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2685 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2686 ImagePreview *p =new ImagePreview (fd);
2687 fd->setContentsPreviewEnabled( TRUE );
2688 fd->setContentsPreview( p, p );
2689 fd->setPreviewMode( QFileDialog::Contents );
2690 fd->setCaption(tr("vym - Load image"));
2691 fd->setDir (lastImageDir);
2695 if ( fd->exec() == QDialog::Accepted )
2697 saveState(selection);
2698 QString fn=fd->selectedFile();
2699 lastImageDir=fn.left(fn.findRev ("/"));
2700 bo->addFloatImage();
2701 // FIXME check if load was successful
2702 bo->getLastFloatImage()->load(fn);
2703 bo->getLastFloatImage()->setOriginalFilename(fn);
2704 mapCenter->reposition();
2711 void MapEditor::saveFloatImage (int item)
2714 (typeid(*selection) == typeid(FloatImageObj)) )
2716 FloatImageObj *fio=((FloatImageObj*)(selection));
2717 const char* fmt = saveImageFormatMenu->text(item);
2719 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2720 fd->addFilter ("PNG (*.png)");
2721 fd->addFilter ("BMP (*.bmp)");
2722 fd->addFilter ("XBM (*.xbm)");
2723 fd->addFilter ("JPG (*.jpg)");
2724 fd->addFilter ("XPM (*.xpm)");
2725 fd->addFilter ("GIF (*.gif)");
2726 fd->addFilter ("PNM (*.pnm)");
2727 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2728 fd->setCaption(tr("vym - Save image as ") + fmt);
2729 fd->setMode( QFileDialog::AnyFile );
2730 fd->setSelection (fio->getOriginalFilename());
2734 if ( fd->exec() == QDialog::Accepted )
2736 if (QFile (fd->selectedFile()).exists() )
2738 QMessageBox mb( "VYM",
2739 tr("The file ") + fd->selectedFile() +
2740 tr(" exists already. "
2741 "Do you want to overwrite it?"),
2742 QMessageBox::Warning,
2743 QMessageBox::Yes | QMessageBox::Default,
2744 QMessageBox::Cancel | QMessageBox::Escape,
2745 QMessageBox::QMessageBox::NoButton );
2747 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2748 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2751 case QMessageBox::Yes:
2754 case QMessageBox::Cancel:
2760 fio->save (fd->selectedFile(),fmt);
2765 void MapEditor::toggleFloatExport()
2768 (typeid(*selection) == typeid(FloatImageObj))||
2769 (typeid(*selection) == typeid(FloatObj)) )
2771 FloatImageObj *fio=((FloatImageObj*)(selection));
2772 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2776 void MapEditor::setFrame(const FrameType &t)
2779 (typeid(*selection) == typeid(BranchObj)) ||
2780 (typeid(*selection) == typeid(MapCenterObj)) )
2782 selection->setFrameType (t);
2783 mapCenter->reposition();
2784 selection->updateLink();
2788 void MapEditor::importDir(BranchObj *dst, QDir d)
2791 (typeid(*selection) == typeid(BranchObj)) ||
2792 (typeid(*selection) == typeid(MapCenterObj)) )
2796 // Traverse directories
2797 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2798 const QFileInfoList *dirlist = d.entryInfoList();
2799 QFileInfoListIterator itdir( *dirlist );
2802 while ( (fi = itdir.current()) != 0 )
2804 if (fi->fileName() != "." && fi->fileName() != ".." )
2807 bo=dst->getLastBranch();
2808 bo->setHeading (fi->fileName() );
2809 bo->setColor (QColor("blue"),false);
2811 if ( !d.cd(fi->fileName()) )
2812 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2815 // Recursively add subdirs
2823 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2824 const QFileInfoList *filelist = d.entryInfoList();
2825 QFileInfoListIterator itfile( *filelist );
2827 while ( (fi = itfile.current()) != 0 )
2830 bo=dst->getLastBranch();
2831 bo->setHeading (fi->fileName() );
2832 bo->setColor (QColor("black"),false);
2833 if (fi->fileName().right(4) == ".vym" )
2834 bo->setVymLink (fi->filePath());
2841 void MapEditor::importDir()
2844 (typeid(*selection) == typeid(BranchObj)) ||
2845 (typeid(*selection) == typeid(MapCenterObj)) )
2847 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2848 fd->setMode (QFileDialog::DirectoryOnly);
2849 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2850 fd->setCaption(tr("VYM - Choose directory structur to import"));
2854 if ( fd->exec() == QDialog::Accepted )
2856 BranchObj *bo=((BranchObj*)(selection));
2857 importDir (bo,QDir(fd->selectedFile()) );
2858 mapCenter->reposition();
2865 void MapEditor::followXLink(int i)
2868 (typeid(*selection) == typeid(BranchObj)) ||
2869 (typeid(*selection) == typeid(MapCenterObj)) )
2871 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2874 selection->unselect();
2876 selection->select();
2877 ensureSelectionVisible();
2882 void MapEditor::editXLink(int i)
2885 (typeid(*selection) == typeid(BranchObj)) ||
2886 (typeid(*selection) == typeid(MapCenterObj)) )
2888 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2891 EditXLinkDialog dia;
2893 dia.setSelection(selection);
2894 if (dia.exec() == QDialog::Accepted)
2896 if (dia.useSettingsGlobal() )
2898 setDefXLinkColor (xlo->getColor() );
2899 setDefXLinkWidth (xlo->getWidth() );
2901 if (dia.deleteXLink())
2902 ((BranchObj*)(selection))->deleteXLinkAt(i);
2903 saveState(); //FIXME undoCommand
2909 void MapEditor::testFunction()
2911 cout << "MapEditor::testFunction() called\n";
2913 (typeid(*selection) == typeid(BranchObj)) )
2915 QString s=((BranchObj*)(selection))->getHeading();
2920 void MapEditor::ensureSelectionVisible()
2924 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2926 if (selection->getOrientation() == OrientLeftOfCenter)
2927 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2929 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2930 ensureVisible (p.x(), p.y() );
2935 void MapEditor::updateViewCenter()
2937 // Update movingCenter, so that we can zoom comfortably later
2938 QRect rc = QRect( contentsX(), contentsY(),
2939 visibleWidth(), visibleHeight() );
2940 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2941 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2942 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2945 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2947 // Lineedits are already closed by preceding
2948 // mouseEvent, we don't need to close here.
2950 QPoint p = inverseWorldMatrix().map(e->pos());
2951 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2954 { // MapObj was found
2955 if (selection != lmo)
2957 // select the MapObj
2958 if (selection) selection->unselect();
2960 selection->select();
2966 if (typeid(*selection)==typeid(BranchObj) ||
2967 typeid(*selection)==typeid(MapCenterObj) )
2969 // Context Menu on branch or mapcenter
2971 branchContextMenu->popup(e->globalPos() );
2973 if (typeid(*selection)==typeid(FloatImageObj))
2975 // Context Menu on floatimage
2977 floatimageContextMenu->popup(e->globalPos() );
2981 { // No MapObj found, we are on the Canvas itself
2982 // Context Menu on Canvas
2984 canvasContextMenu->popup(e->globalPos() );
2988 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2990 // Finish open lineEdits
2991 if (lineedit) finishedLineEditNoSave();
2993 QPoint p = inverseWorldMatrix().map(e->pos());
2994 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2996 // Special case: CTRL is pressed
2997 if (e->state() & QMouseEvent::ControlButton)
2999 if (actionModModeColor->isOn())
3001 if (e->state() & QMouseEvent::ControlButton)
3004 setCursor (pickColorCursor);
3008 if (actionModModeLink->isOn())
3010 BranchObj *bo_begin=NULL;
3012 bo_begin=(BranchObj*)(lmo);
3015 ((typeid(*selection) == typeid(BranchObj)) ||
3016 (typeid(*selection) == typeid(MapCenterObj))) )
3017 bo_begin=(BranchObj*)(selection);
3021 linkingObj_src=bo_begin;
3022 tmpXLink=new XLinkObj (mapCanvas);
3023 tmpXLink->setBegin (bo_begin);
3024 tmpXLink->setEnd (p);
3025 tmpXLink->setColor(defXLinkColor);
3026 tmpXLink->setWidth(defXLinkWidth);
3027 tmpXLink->updateXLink();
3028 tmpXLink->setVisibility (true);
3035 { // MapObj was found
3036 if (selection != lmo)
3038 // select the MapObj
3039 if (selection) selection->unselect();
3041 selection->select();
3046 // Check, if systemFlag clicked
3047 if (typeid(*selection)==typeid(BranchObj) ||
3048 typeid(*selection)==typeid(MapCenterObj) )
3050 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
3051 if (!foname.isEmpty())
3053 // Do not move, if systemFlag clicked
3057 if (foname=="vymLink")
3059 mainWindow->editOpenVymLink();
3060 // tabWidget may change, better return now
3061 // before segfaulting...
3065 mainWindow->windowToggleNoteEditor();
3069 // Left Button Move Branches
3070 if (e->button() == QMouseEvent::LeftButton )
3072 movingObj_start.setX( p.x() - selection->x() );
3073 movingObj_start.setY( p.y() - selection->y() );
3074 movingObj_orgPos.setX (lmo->x() );
3075 movingObj_orgPos.setY (lmo->y() );
3077 // If modMode==copy, then we want to "move" the _new_ object around
3078 // then we need the offset from p to the _old_ selection, because of tmp
3079 if (actionModModeCopy->isOn() &&
3080 e->state() & QMouseEvent::ControlButton)
3082 if (typeid(*selection)==typeid(BranchObj) )
3085 mapCenter->addBranch ((BranchObj*)(selection));
3087 selection=mapCenter->getLastBranch();
3088 selection->select();
3089 mapCenter->reposition();
3092 movingObj=selection;
3094 // Middle Button Toggle Scroll
3095 // (On Mac OS X this won't work, but we still have
3096 // a button in the toolbar)
3097 if (e->button() == QMouseEvent::MidButton )
3101 { // No MapObj found, we are on the Canvas itself
3102 // Left Button move Pos of CanvasView
3103 if (e->button() == QMouseEvent::LeftButton )
3105 movingObj=NULL; // move Content not Obj
3106 movingObj_start=e->globalPos();
3107 movingCont_start=QPoint (contentsX(), contentsY() );
3108 movingVec=QPoint(0,0);
3109 setCursor(handOpenCursor);
3114 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3116 QPoint p = inverseWorldMatrix().map(e->pos());
3118 // Move the selected MapObj
3119 if ( selection && movingObj)
3121 ensureVisible (p.x(),p.y());
3123 // Now move the selection, but add relative position
3124 // (movingObj_start) where selection was chosen with
3125 // mousepointer. (This avoids flickering resp. jumping
3126 // of selection back to absPos)
3128 LinkableMapObj *lmosel;
3129 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3131 // Check if we could link
3132 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3135 if (typeid(*selection) == typeid(FloatImageObj))
3137 saveState("move "+qpointToString(movingObj_orgPos));
3138 FloatObj *fo=(FloatObj*)(selection);
3139 if (fo->getLinkStyle()==StyleUndef)
3141 fo->setLinkStyle(fo->getDefLinkStyle());
3142 fo->setLinkColor(fo->getParObj()->getLinkColor());
3144 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3148 // Relink float to new mapcenter or branch, if shift is pressed
3149 // Only relink, if selection really has a new parent
3150 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3151 ( (typeid(*lmo)==typeid(BranchObj)) ||
3152 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3153 ( lmo != fo->getParObj())
3156 if (typeid(*fo) == typeid(FloatImageObj))
3159 FloatImageObj *fio=(FloatImageObj*)(fo);
3160 ((BranchObj*)(lmo))->addFloatImage (fio);
3162 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3163 fio=((BranchObj*)(lmo))->getLastFloatImage();
3166 selection=(LinkableMapObj*)(fio);
3167 selection->select();
3168 movingObj=(MapObj*)(fio);
3169 // setLinkStyle calls updateLink, only set it once
3170 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3171 fio->setLinkStyle (fio->getDefLinkStyle());
3173 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3175 } else // selection != a FloatObj
3177 if (lmosel->getDepth()==0)
3179 if (e->state() == (LeftButton | !ShiftButton))
3180 // If mapCenter is moved, move all the rest by default, too.
3181 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3183 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3186 if (lmosel->getDepth()==1)
3188 // depth==1, mainbranch
3189 saveState("move "+qpointToString(movingObj_orgPos));
3190 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3194 if (lmosel->getOrientation() == OrientLeftOfCenter)
3195 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3196 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3197 p.y()-movingObj_start.y() );
3199 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3201 // reposition subbranch
3202 lmosel->reposition();
3203 //ensureSelectionVisible();
3205 if (lmo && (lmo!=selection) &&
3206 (typeid(*lmo) == typeid(BranchObj) ||
3207 (typeid(*lmo) == typeid(MapCenterObj) )
3210 if (e->state() & QMouseEvent::ControlButton)
3212 // Special case: CTRL to link below lmo
3213 lmosel->setParObjTmp (lmo,p,+1);
3215 else if (e->state() & QMouseEvent::ShiftButton)
3216 lmosel->setParObjTmp (lmo,p,-1);
3218 lmosel->setParObjTmp (lmo,p,0);
3221 lmosel->unsetParObjTmp();
3223 if (lmo &&(lmo==selection))
3224 // Could link to myself (happens sometimes...)
3225 lmosel->unsetParObjTmp();
3227 // no Obj under selection, go back to original Parent
3228 lmosel->unsetParObjTmp();
3233 } // no FloatImageObj
3237 } // selection && moving_obj
3239 // Draw a link from one branch to another
3242 tmpXLink->setEnd (p);
3243 tmpXLink->updateXLink();
3247 if (!movingObj && !pickingColor &&!drawingLink)
3249 QPoint p=e->globalPos();
3250 movingVec.setX(-p.x() + movingObj_start.x() );
3251 movingVec.setY(-p.y() + movingObj_start.y() );
3252 setContentsPos( movingCont_start.x() + movingVec.x(),
3253 movingCont_start.y() + movingVec.y());
3260 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3262 LinkableMapObj *dst;
3263 // Have we been picking color?
3267 setCursor (ArrowCursor);
3268 // Check if we are over another branch
3269 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3270 if (dst && selection)
3272 if (e->state() & QMouseEvent::ShiftButton)
3274 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3275 ((BranchObj*)(selection))->setLinkColor ();
3279 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3280 ((BranchObj*)(selection))->setLinkColor ();
3286 // Have we been drawing a link?
3290 // Check if we are over another branch
3291 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3292 if (dst && selection)
3294 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3295 tmpXLink->updateXLink();
3296 tmpXLink->activate();
3297 saveState(); //FIXME undoCommand
3306 // Have we been moving something?
3307 if ( selection && movingObj )
3309 // Check if we are over another branch, but ignore
3310 // any found LMOs, which are FloatObjs
3311 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3312 ((LinkableMapObj*)(selection)) );
3315 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3320 // Now check, if we have been moving a branch
3321 if (typeid(*selection) == typeid(BranchObj) )
3323 // save the position in case we link to mapcenter
3324 QPoint savePos=QPoint (selection->x(),selection->y() );
3326 // Reset the temporary drawn link to the original one
3327 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3333 BranchObj* bs=((BranchObj*)(selection));
3334 saveState ("linkBranchToPos (\""+
3335 (bs->getParObj())->getSelectString()+
3337 QString("%1").arg(bs->getNum())+
3339 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3341 // TODO we also could check, if dest and src are on same branch,
3342 // then it would be sufficient to saveState of this branch
3344 // Modifiers allow to insert above/below dst
3345 if (e->state() & QMouseEvent::ShiftButton)
3347 bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum());
3349 if (e->state() & QMouseEvent::ControlButton)
3351 bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum()+1);
3354 bs->moveBranchTo ((BranchObj*)(dst),-1);
3355 if (dst->getDepth()==0)
3359 // Draw the original link, before selection was moved around
3360 mapCenter->reposition();
3362 // Finally resize canvas, if needed
3367 // maybe we moved View: set old cursor
3368 setCursor (ArrowCursor);
3372 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3374 // Finish open lineEdits
3375 if (lineedit) finishedLineEditNoSave();
3377 if (e->button() == QMouseEvent::LeftButton )
3379 QPoint p = inverseWorldMatrix().map(e->pos());
3380 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3381 if (lmo) { // MapObj was found
3382 // First select the MapObj than edit heading
3383 if (selection) selection->unselect();
3385 selection->select();
3386 saveState(selection);
3392 void MapEditor::resizeEvent (QResizeEvent* e)
3394 QCanvasView::resizeEvent( e );
3397 if (!fileName.isEmpty()) s=fileName;
3401 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3404 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3405 // cerr << event->format(i) << endl;
3408 (typeid(*selection) == typeid(BranchObj)) ||
3409 (typeid(*selection) == typeid(MapCenterObj))) {
3411 // If QImageDrag can decode mime type
3412 if (QImageDrag::canDecode(event)) {
3417 // If image are dragged from firefox
3418 if (event->provides("application/x-moz-file-promise-url") &&
3419 event->provides("application/x-moz-nativeimage")) {
3420 event->accept(true);
3424 // If QUriDrag can decode mime type
3425 if (QUriDrag::canDecode(event)) {
3430 // If Uri are dragged from firefox
3431 if (event->provides("_NETSCAPE_URL")){
3436 // If QTextDrag can decode mime type
3437 if (QTextDrag::canDecode(event)) {
3446 bool isUnicode16(const QByteArray &d)
3448 // FIXME: make more precise check for unicode 16.
3449 // Guess unicode16 if any of second bytes are zero
3450 unsigned int length = max(0,d.size()-2)/2;
3451 for (unsigned int i = 0; i<length ; i++)
3452 if (d.at(i*2+1)==0) return true;
3456 void MapEditor::contentsDropEvent(QDropEvent *event)
3459 (typeid(*selection) == typeid(BranchObj)) ||
3460 (typeid(*selection) == typeid(MapCenterObj)))
3465 if (event->provides("image/png"))
3468 if (QImageDrag::decode(event, pix))
3476 } else if (event->provides("application/x-moz-file-promise-url") &&
3477 event->provides("application/x-moz-nativeimage"))
3479 // Contains url to the img src in unicode16
3480 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3481 QString url = QString((const QChar*)d.data(),d.size()/2);
3485 } else if (event->provides ("text/uri-list"))
3486 { // Uris provided e.g. by konqueror
3487 QUriDrag::decode (event,uris);
3488 } else if (event->provides ("_NETSCAPE_URL"))
3489 { // Uris provided by Mozilla
3490 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3493 } else if (event->provides("text/html")) {
3495 // Handels text mime types
3496 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3497 QByteArray d = event->encodedData("text/html");
3500 text = QString((const QChar*)d.data(),d.size()/2);
3504 textEditor->setText(text);
3508 } else if (event->provides("text/plain")) {
3509 QByteArray d = event->encodedData("text/plain");
3512 text = QString((const QChar*)d.data(),d.size()/2);
3516 textEditor->setText(text);
3528 for (const char* u=uris.first(); u; u=uris.next())
3530 bo=((BranchObj*)(selection))->addBranch();
3533 s=QUriDrag::uriToLocalFile(u);
3535 QString file = QDir::convertSeparators(s);
3536 heading = QFileInfo(file).baseName();
3538 if (file.endsWith(".vym", false))
3539 bo->setVymLink(file);
3548 bo->setHeading(heading);
3558 saveState(); //FIXME undo Command
3559 mapCenter->reposition();
3566 void MapEditor::addFloatImage(const QPixmap &img)
3569 (typeid(*selection) == typeid(BranchObj)) ||
3570 (typeid(*selection) == typeid(MapCenterObj)) )
3572 BranchObj *bo=((BranchObj*)(selection));
3573 saveState(selection);
3574 //QString fn=fd->selectedFile();
3575 //lastImageDir=fn.left(fn.findRev ("/"));
3576 bo->addFloatImage();
3577 // FIXME check if load was successful
3578 bo->getLastFloatImage()->load(img);
3579 //bo->getLastFloatImage()->setOriginalFilename(fn);
3580 mapCenter->reposition();
3587 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3589 if (!imageBuffer) imageBuffer = new QBuffer();
3590 if (!imageBuffer->isOpen()) {
3591 imageBuffer->open(IO_WriteOnly | IO_Append);
3593 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3597 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3599 if (nop->state()==QNetworkProtocol::StDone) {
3600 QPixmap img(imageBuffer->buffer());
3605 imageBuffer->close();
3607 imageBuffer->close();
3614 void MapEditor::fetchImage(const QString &url)
3617 urlOperator->stop();
3618 disconnect(urlOperator);
3622 urlOperator = new QUrlOperator(url);
3623 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3624 this, SLOT(imageDataFinished(QNetworkOperation*)));
3626 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3627 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));