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>
26 #include "texteditor.h"
27 #include "linkablemapobj.h"
30 #include "mainwindow.h"
31 #include "extrainfodialog.h"
32 #include "editxlinkdialog.h"
35 #include "icons/flag-note.xpm"
36 #include "icons/flag-url.xpm"
37 #include "icons/flag-vymlink.xpm"
38 #include "icons/flag-scrolled-right.xpm"
39 #include "icons/flag-tmpUnscrolled-right.xpm"
40 #include "icons/flag-questionmark.xpm"
41 #include "icons/flag-exclamationmark.xpm"
42 #include "icons/flag-hook-green.xpm"
43 #include "icons/flag-cross-red.xpm"
44 #include "icons/flag-stopsign.xpm"
45 #include "icons/flag-smiley-good.xpm"
46 #include "icons/flag-smiley-sad.xpm"
47 #include "icons/flag-clock.xpm"
48 #include "icons/flag-lamp.xpm"
49 #include "icons/flag-arrow-up.xpm"
50 #include "icons/flag-arrow-down.xpm"
51 #include "icons/flag-thumb-up.xpm"
52 #include "icons/flag-thumb-down.xpm"
53 #include "icons/flag-heart.xpm"
54 #include "icons/flag-flash.xpm"
55 #include "icons/flag-lifebelt.xpm"
57 extern TextEditor *textEditor;
58 extern int statusbarTime;
59 extern Main *mainWindow;
60 extern FlagRowObj *systemFlagsDefault;
61 extern FlagRowObj *standardFlagsDefault;
62 extern MapEditor *clipboardME;
64 extern QPtrList <QAction> actionListBranches;
66 extern QAction *actionFileSave;
67 extern QAction *actionEditUndo;
68 extern QAction *actionEditCopy;
69 extern QAction *actionEditCut;
70 extern QAction *actionEditPaste;
71 extern QAction *actionEditMoveUp;
72 extern QAction *actionEditMoveDown;
73 extern QAction *actionEditToggleScroll;
74 extern QAction *actionEditOpenURL;
75 extern QAction *actionEditURL;
76 extern QAction *actionEditHeading2URL;
77 extern QAction *actionEditBugzilla2URL;
78 extern QAction *actionEditOpenVymLink;
79 extern QAction *actionEditVymLink;
80 extern QAction *actionEditDeleteVymLink;
81 extern QAction *actionEditHeading;
82 extern QAction *actionEditDelete;
83 extern QAction *actionEditAddBranch;
84 extern QAction *actionEditAddBranchAbove;
85 extern QAction *actionEditAddBranchBelow;
86 extern QAction *actionEditRemoveBranchHere;
87 extern QAction *actionEditRemoveChilds;
88 extern QAction *actionEditImportAdd;
89 extern QAction *actionEditImportReplace;
90 extern QAction *actionEditSaveBranch;
91 extern QAction *actionEditSelectFirst;
92 extern QAction *actionEditSelectLast;
93 extern QAction *actionEditLoadImage;
94 extern QAction *actionEditToggleFloatExport;
96 extern QAction* actionFormatPickColor;
97 extern QAction* actionFormatColorBranch;
98 extern QAction* actionFormatColorSubtree;
99 extern QAction *actionFormatLinkColorHint;
100 extern QAction *actionFormatBackColor;
101 extern QAction *actionFormatLinkColor;
103 extern QActionGroup* actionGroupModModes;
104 extern QAction* actionModModeColor;
105 extern QAction* actionModModeLink;
106 extern QAction* actionModModeCopy;
108 extern QActionGroup *actionGroupFormatFrameTypes;
109 extern QAction *actionFormatFrameNone;
110 extern QAction *actionFormatFrameRectangle;
112 extern QActionGroup *actionGroupFormatLinkStyles;
113 extern QAction *actionFormatLinkStyleLine;
114 extern QAction *actionFormatLinkStyleParabel;
115 extern QAction *actionFormatLinkStylePolyLine;
116 extern QAction *actionFormatLinkStylePolyParabel;
118 extern QAction *actionViewToggleNoteEditor;
120 extern QAction *actionSettingsAutoedit;
121 extern QAction *actionSettingsAutoselectHeading;
122 extern QAction *actionSettingsAutoselectText;
123 extern QAction *actionSettingsPasteNewHeading;
124 extern QAction *actionSettingsUseFlagGroups;
126 extern QPopupMenu *branchContextMenu;
127 extern QPopupMenu *branchLinksContextMenu;
128 extern QPopupMenu *branchLinksContextMenuDup;
129 extern QPopupMenu *floatimageContextMenu;
130 extern QPopupMenu *saveImageFormatMenu;
131 extern QPopupMenu *exportImageFormatMenu;
132 extern QPopupMenu *canvasContextMenu;
134 extern Settings settings;
137 ///////////////////////////////////////////////////////////////////////
138 ///////////////////////////////////////////////////////////////////////
139 MapEditor::MapEditor(
140 QWidget* parent, bool interactive, const char* name, WFlags f) :
141 QCanvasView(parent,name,f)
143 //cout << "Constructor ME "<<this<<endl;
145 mapCanvas = new QCanvas(1000,800);
146 mapCanvas->setAdvancePeriod(30);
148 setCanvas (mapCanvas);
150 setVScrollBarMode ( QScrollView::AlwaysOn );
151 setHScrollBarMode ( QScrollView::AlwaysOn );
153 // Now create the _global_ system flags _once_:
154 // (Later all OrnamentedObj copy from this
155 // and set their own canvas)
156 if (!systemFlagsDefault)
158 systemFlagsDefault = new FlagRowObj (mapCanvas);
159 systemFlagsDefault->setVisibility (false);
160 systemFlagsDefault->setName ("systemFlagsDef");
162 FlagObj *fo = new FlagObj (mapCanvas);
163 fo->load(QPixmap(flag_note_xpm));
165 fo->setToolTip(tr("Note","Systemflag"));
166 systemFlagsDefault->addFlag (fo); // makes deep copy
168 fo->load(QPixmap(flag_url_xpm));
170 fo->setToolTip(tr("WWW Document (external)","Systemflag"));
171 systemFlagsDefault->addFlag (fo);
173 fo->load(QPixmap(flag_vymlink_xpm));
174 fo->setName("vymLink");
175 fo->setToolTip(tr("Link to another vym map","Systemflag"));
176 systemFlagsDefault->addFlag (fo);
178 fo->load(QPixmap(flag_scrolled_right_xpm));
179 fo->setName("scrolledright");
180 fo->setToolTip(tr("subtree is scrolled","Systemflag"));
181 systemFlagsDefault->addFlag (fo);
183 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
184 fo->setName("tmpUnscrolledright");
185 fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
186 systemFlagsDefault->addFlag (fo);
189 if (!standardFlagsDefault)
191 standardFlagsDefault = new FlagRowObj (mapCanvas);
192 standardFlagsDefault->setVisibility (false);
193 standardFlagsDefault->setName ("standardFlagsDef");
195 FlagObj *fo = new FlagObj (mapCanvas);
196 fo->load(QPixmap(flag_exclamationmark_xpm));
197 fo->setName ("exclamationmark");
198 fo->setGroup("standard-mark");
199 fo->setToolTip(tr("Take care!","Standardflag"));
200 standardFlagsDefault->addFlag (fo); // makes deep copy
202 fo->load(QPixmap(flag_questionmark_xpm));
203 fo->setName("questionmark");
204 fo->setGroup("standard-mark");
205 fo->setToolTip(tr("Really?","Standardflag"));
206 standardFlagsDefault->addFlag (fo);
208 fo->load(QPixmap(flag_hook_green_xpm));
209 fo->setName("hook-green");
210 fo->setGroup("standard-hook");
211 fo->setToolTip(tr("ok!","Standardflag"));
212 standardFlagsDefault->addFlag (fo);
214 fo->load(QPixmap(flag_cross_red_xpm));
215 fo->setName("cross-red");
216 fo->setGroup("standard-hook");
217 fo->setToolTip(tr("Not ok!","Standardflag"));
218 standardFlagsDefault->addFlag (fo);
220 fo->load(QPixmap(flag_stopsign_xpm));
221 fo->setName("stopsign");
222 fo->setToolTip(tr("This won't work!","Standardflag"));
223 standardFlagsDefault->addFlag (fo);
225 fo->load(QPixmap(flag_smiley_good_xpm));
226 fo->setName("smiley-good");
227 fo->setGroup("standard-smiley");
228 fo->setToolTip(tr("Good","Standardflag"));
229 standardFlagsDefault->addFlag (fo);
231 fo->load(QPixmap(flag_smiley_sad_xpm));
232 fo->setName("smiley-sad");
233 fo->setGroup("standard-smiley");
234 fo->setToolTip(tr("Bad","Standardflag"));
235 standardFlagsDefault->addFlag (fo);
237 fo->load(QPixmap(flag_clock_xpm));
238 fo->setName("clock");
239 fo->setToolTip(tr("Time critical","Standardflag"));
240 standardFlagsDefault->addFlag (fo);
242 fo->load(QPixmap(flag_lamp_xpm));
244 fo->setToolTip(tr("Idea!","Standardflag"));
245 standardFlagsDefault->addFlag (fo);
247 fo->load(QPixmap(flag_arrow_up_xpm));
248 fo->setName("arrow-up");
249 fo->setGroup("standard-arrow");
250 fo->setToolTip(tr("Important","Standardflag"));
251 standardFlagsDefault->addFlag (fo);
253 fo->load(QPixmap(flag_arrow_down_xpm));
254 fo->setName("arrow-down");
255 fo->setGroup("standard-arrow");
256 fo->setToolTip(tr("Unimportant","Standardflag"));
257 standardFlagsDefault->addFlag (fo);
259 fo->load(QPixmap(flag_thumb_up_xpm));
260 fo->setName("thumb-up");
261 fo->setGroup("standard-thumb");
262 fo->setToolTip(tr("I like this","Standardflag"));
263 standardFlagsDefault->addFlag (fo);
265 fo->load(QPixmap(flag_thumb_down_xpm));
266 fo->setName("thumb-down");
267 fo->setGroup("standard-thumb");
268 fo->setToolTip(tr("I like this","Standardflag"));
269 fo->setToolTip(tr("I do not like this","Standardflag"));
270 standardFlagsDefault->addFlag (fo);
272 fo->load(QPixmap(flag_heart_xpm));
273 fo->setName("heart");
274 fo->setToolTip(tr("I just love... ","Standardflag"));
275 standardFlagsDefault->addFlag (fo);
277 fo->load(QPixmap(flag_flash_xpm));
278 fo->setName("flash");
279 fo->setToolTip(tr("Dangerous","Standardflag"));
280 standardFlagsDefault->addFlag (fo);
282 fo->load(QPixmap(flag_lifebelt_xpm));
283 fo->setName("lifebelt");
284 fo->setToolTip(tr("This will help","Standardflag"));
285 standardFlagsDefault->addFlag (fo);
290 mapCenter = new MapCenterObj(mapCanvas);
291 mapCenter->setVisibility (true);
292 mapCenter->setMapEditor (this);
293 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
297 lineedit = new QLineEdit(this, "lineedit" );
298 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
301 actColor=black; setColor (actColor);
302 defLinkColor=QColor (0,0,255);
303 defXLinkColor=QColor (180,180,180);
304 linkcolorhint=DefaultColor;
305 linkstyle=StylePolyParabel;
306 mapCanvas->setBackgroundColor (white);
308 // Create bitmap cursors, patform dependant
309 #if defined(Q_OS_MACX)
310 #include "icons/cursorhandopen16.xpm"
311 #include "icons/cursorcolorpicker16.xpm"
312 QBitmap cb( 16, 16, chandopen, TRUE );
313 QBitmap cm( 16, 16, chandopenmask, TRUE );
314 handOpenCursor=QCursor ( cb, cm );
315 // set hot spot to tip of picker
316 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
318 #include "icons/cursorhandopen.xpm"
319 #include "icons/cursorcolorpicker.xpm"
321 QBitmap cb( 32, 32, chandopen, TRUE );
322 QBitmap cm( 32, 32, chandopenmask, TRUE );
323 handOpenCursor=QCursor ( cb, cm );
324 // set hot spot to tip of picker
325 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
338 defXLinkColor=QColor (230,230,230);
350 // Initialize find routine
357 blockreposition=false;
358 isInteractive=interactive;
360 // Create temporary files
363 // Initially set movingCentre
366 mapCenter->reposition(); // for positioning heading
369 MapEditor::~MapEditor()
371 //cout <<"Destructor MapEditor\n";
372 if (isInteractive) delTmpDirs();
375 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
379 QColor MapEditor::color()
384 QColor MapEditor::backgroundColor()
386 return mapCanvas->backgroundColor();
389 MapCenterObj* MapEditor::getMapCenter()
394 QCanvas* MapEditor::getCanvas()
399 void MapEditor::adjustCanvasSize()
401 // To adjust the canvas to map, viewport size and position, we have to
402 // do some coordinate magic...
404 // Get rectangle of (scroll-)view.
405 // We want to be in canvas coords, so
406 // we map. Important if view is zoomed...
407 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
408 visibleWidth(), visibleHeight()) );
410 // Now we need the bounding box of view AND map to calc the correct canvas size.
411 // Why? Because if the map itself is moved out of view, the view has to be enlarged
412 // to avoid jumping aroung...
413 QRect map=mapCenter->getTotalBBox();
415 // right edge - left edge
416 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
417 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
420 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
421 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
424 // move the map on canvas (in order to not move it on screen) this is neccessary
425 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
426 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
427 // to scroll to an empty area of canvas to the left.
428 // b) if topleft corner of map left of or above topleft of canvas
432 if (cw > mapCanvas->width() )
434 if (map.x()<0) dx=-map.x();
436 if (cw < mapCanvas->width() )
437 dx=-min (view.x(),map.x());
438 if (ch > mapCanvas->height() )
440 if (map.y()<0) dy=-map.y();
442 if (ch < mapCanvas->height() )
444 dy=-min (view.y(),map.y());
446 // We really have to resize now. Let's go...
447 mapCanvas->resize (cw,ch);
448 if ( (dx!=0) || (dy!=0) )
450 mapCenter->moveAllBy(dx,dy);
451 mapCenter->reposition();
453 // scroll the view (in order to not move map on screen)
459 bool MapEditor::blockReposition()
461 return blockreposition;
464 void MapEditor::makeTmpDirs()
466 // Create unique temporary directories
467 char tmpdir[]="/tmp/vym-XXXXXX";
468 bakMapDir=mkdtemp(tmpdir);
469 makeSubDirs(bakMapDir);
470 // FIXME set permissions
471 // and maybe use QT method for portability
474 void MapEditor::delTmpDirs()
476 //FIXME delete tmp directory, better use QT methods here:
477 system ( "rm -rf "+ bakMapDir );
481 void MapEditor::makeSubDirs(const QString &s)
489 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, SaveMode savemode)
491 // tmpdir temporary directory to which data will be writte
492 // prefix mapname, which will be appended to images etc.
493 // writeflags Only write flags for "real" save of map, not undo
494 // offset offset of bbox of whole map in canvas.
495 // Needed for XML export
496 // completeMap if false, only vympart will be written, without
513 ls="StylePolyParabel";
517 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
519 if (linkcolorhint==HeadingColor)
520 colhint=attribut("linkColorHint","HeadingColor");
522 QString mapAttr=attribut("version",__VYM_VERSION__);
523 if (savemode==CompleteMap)
524 mapAttr+= attribut("author",mapCenter->getAuthor()) +
525 attribut("comment",mapCenter->getComment()) +
526 attribut("date",mapCenter->getDate()) +
527 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
528 attribut("linkStyle", ls ) +
529 attribut("linkColor", defLinkColor.name() ) +
530 attribut("defXLinkColor", defXLinkColor.name() ) +
531 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
533 s+=beginElement("vymmap",mapAttr);
536 // Find the used flags while traversing the tree
537 standardFlagsDefault->resetUsedCounter();
539 // Build xml recursivly
540 if (savemode==CompleteMap)
541 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
544 if ( undoSelection &&
545 typeid(*undoSelection) == typeid(BranchObj) )
546 s+=((BranchObj*)(undoSelection))->saveToDir(tmpdir,prefix,offset);
548 if (selection && typeid(*selection)==typeid(BranchObj))
549 s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
552 // Save local settings
553 s+=settings.getXMLData (destPath);
557 s+=valueElement("select",selection->getSelectString());
560 s+=endElement("vymmap");
563 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
567 void MapEditor::saveState()
569 saveState (CompleteMap,NULL);
572 void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part)
574 // all binary data is saved in bakMapDir (created in Constructor)
575 // the xml data itself is kept in memory in backupXML
577 // For faster write/read of data, a part of the map can be
578 // written. Then the undoSelection will mark the part of the
579 // map which should be replaced if an undo is wanted later.
581 if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) )
583 // Writing a vympart only is useful for BranchObj
585 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
589 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap);
593 void MapEditor::finishedLineEditNoSave()
595 // This is called by finishedLineEdit or any MapEditor method,
596 // which wants to assure, that lineedits finish, before e.g. a branch is
599 // After calling LineEdit and using the clipboard, the
600 // focus is not any longer on the main widget, we
601 // have to restore it using parentWidget()->setFocus()
605 editingBO->setHeading(lineedit->text() );
607 lineedit->releaseKeyboard();
609 parentWidget()->setFocus();
610 mapCenter->reposition();
612 ensureSelectionVisible();
617 bool MapEditor::isDefault()
622 bool MapEditor::isUnsaved()
627 bool MapEditor::hasChanged()
632 void MapEditor::setChanged()
637 actionEditUndo->setEnabled (true);
638 actionFileSave->setEnabled (true);
642 void MapEditor::closeMap()
644 // Finish open lineEdits
645 if (lineedit) finishedLineEditNoSave();
647 // Unselect before disabling the toolbar actions
648 if (selection) selection->unselect();
656 void MapEditor::setFilePath(QString fname)
658 setFilePath (fname,fname);
661 void MapEditor::setFilePath(QString fname, QString destname)
667 // If fname is not an absolute path, complete it
668 filePath=QDir(fname).absPath();
669 fileDir=filePath.left (1+filePath.findRev ("/"));
671 // Set short name, too. Search from behind:
672 int i=fileName.findRev("/");
673 if (i>=0) fileName=fileName.remove (0,i+1);
675 // Forget the .vym (or .xml) for name of map
676 mapName=fileName.left(fileName.findRev(".",-1,true) );
679 QString MapEditor::getFilePath()
684 QString MapEditor::getFileName()
689 QString MapEditor::getMapName()
694 QString MapEditor::getDestPath()
699 int MapEditor::load (QString &fname, const LoadMode &lmode)
701 // Finish open lineEdits
702 if (lineedit) finishedLineEditNoSave();
708 if (selection) selection->unselect();
711 mapCenter->setMapEditor(this);
712 // (map state is set later at end of load...)
716 saveState(PartOfMap,selection);
720 mapBuilderHandler handler;
723 // I am paranoid: file should exist anyway
724 // according to check in mainwindow.
727 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
728 tr("Couldn't open map " +fname)+".");
732 blockreposition=true;
733 QXmlInputSource source( file);
734 QXmlSimpleReader reader;
735 reader.setContentHandler( &handler );
736 reader.setErrorHandler( &handler );
737 handler.setMapEditor( this );
738 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
739 handler.setLoadMode (lmode);
740 bool ok = reader.parse( source );
741 blockreposition=false;
745 mapCenter->reposition();
755 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
756 tr( handler.errorProtocol() ) );
758 // Still return "success": the map maybe at least
759 // partially read by the parser
766 int MapEditor::save (const SaveMode &savemode)
768 // Finish open lineEdits
769 if (lineedit) finishedLineEditNoSave();
773 // Create mapName and fileDir
774 makeSubDirs (fileDir);
778 fname=mapName+".xml";
780 // use name given by user, even if he chooses .doc
784 // Check if fname is writeable
785 QFile file( fileDir+fname);
786 if (!file.open( IO_WriteOnly ) )
788 QMessageBox::critical( 0, tr( "Critical Save Error" ),
789 tr("Couldn't write to ") +fileDir+fname);
795 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),savemode);
797 file.setName ( fileDir + fname);
798 if ( !file.open( IO_WriteOnly ) )
800 // This should neverever happen
801 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
805 // Write it finally, and write in UTF8, no matter what
806 QTextStream ts( &file );
807 ts.setEncoding (QTextStream::UnicodeUTF8);
815 actionFileSave->setEnabled(false);
821 void MapEditor::setZipped (bool z)
826 bool MapEditor::saveZipped ()
831 void MapEditor::print()
833 // Finish open lineEdits
834 if (lineedit) finishedLineEditNoSave();
838 printer = new QPrinter;
839 printer->setColorMode (QPrinter::Color);
842 QRect totalBBox=mapCenter->getTotalBBox();
844 // Try to set orientation automagically
845 // Note: Interpretation of generated postscript is amibiguous, if
846 // there are problems with landscape mode, see
847 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
849 if (totalBBox.width()>totalBBox.height())
850 // recommend landscape
851 printer->setOrientation (QPrinter::Landscape);
853 // recommend portrait
854 printer->setOrientation (QPrinter::Portrait);
856 if ( printer->setup(this) )
857 // returns false, if printing is canceled
859 QPainter pp(printer);
861 // Don't print the visualisation of selection
862 LinkableMapObj *oldselection=NULL;
865 oldselection=selection;
866 selection->unselect();
869 // Handle sizes of map and paper:
871 // setWindow defines which part of the canvas will be transformed
872 // setViewport defines area on paper in device coordinates (dpi)
873 // e.g. (0,50,700,700) is upper part on A4
874 // see also /usr/lib/qt3/doc/html/coordsys.html
876 QPaintDeviceMetrics metrics (printer);
878 double paperAspect = (double)metrics.width() / (double)metrics.height();
879 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
881 QRect mapRect=totalBBox;
882 QCanvasRectangle *frame=NULL;
883 QCanvasText *footerFN=NULL;
884 QCanvasText *footerDate=NULL;
885 if (printFrame || printFooter)
890 // Print frame around map
891 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
892 totalBBox.width()+20, totalBBox.height()+20);
893 frame=new QCanvasRectangle (mapRect,mapCanvas);
894 frame->setBrush (QColor(white));
895 frame->setPen (QColor(black));
900 QCanvasLine *l=new QCanvasLine (mapCanvas);
901 l->setPoints (0,0,mapRect.width(),mapRect.height());
902 l->setPen (QPen(QColor(black), 1));
909 // Print footer below map
911 font.setPointSize(10);
912 footerFN=new QCanvasText (mapCanvas);
913 footerFN->setText ("VYM - " + fileName);
914 footerFN->setFont(font);
915 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
916 footerFN->setZ(Z_TEXT);
918 footerDate=new QCanvasText (mapCanvas);
919 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
920 footerDate->setFont(font);
921 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
922 footerDate->setZ(Z_TEXT);
925 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
928 pp.setWindow (mapRect);
931 if (mapAspect>=paperAspect)
933 // Fit horizontally to paper width
934 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
937 // Fit vertically to paper height
938 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
941 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
943 // Delete Frame and footer
949 if (frame) delete (frame);
954 selection=oldselection;
960 QPixmap MapEditor::getPixmap()
962 QRect mapRect=mapCenter->getTotalBBox();
963 QPixmap pix (mapRect.size());
966 // Don't print the visualisation of selection
967 LinkableMapObj *oldselection=NULL;
970 oldselection=selection;
971 selection->unselect();
974 pp.setWindow (mapRect);
976 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
982 selection=oldselection;
989 void MapEditor::exportImage(QString fn)
991 // Finish open lineEdits
992 if (lineedit) finishedLineEditNoSave();
994 QPixmap pix (getPixmap());
998 void MapEditor::exportImage(QString fn, int item)
1000 // Finish open lineEdits
1001 if (lineedit) finishedLineEditNoSave();
1003 QPixmap pix (getPixmap());
1004 pix.save(fn, exportImageFormatMenu->text(item) );
1007 void MapEditor::exportASCII()
1009 // FIXME still experimental
1010 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
1011 fd->addFilter ("TXT (*.txt)");
1012 fd->setCaption("VYM - Export (ASCII) (still experimental)");
1013 fd->setMode( QFileDialog::AnyFile );
1016 if ( fd->exec() == QDialog::Accepted )
1018 if (QFile (fd->selectedFile()).exists() )
1020 QMessageBox mb( "VYM",
1021 tr("The file ") + fd->selectedFile() +
1022 tr(" exists already. Do you want to overwrite it?"),
1023 QMessageBox::Warning,
1024 QMessageBox::Yes | QMessageBox::Default,
1025 QMessageBox::Cancel | QMessageBox::Escape,
1026 QMessageBox::NoButton );
1028 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1029 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1033 case QMessageBox::Yes:
1035 if (!ex.setOutputDir ("out"))
1037 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1041 case QMessageBox::Cancel:
1048 ex.setPath (fd->selectedFile() );
1049 ex.setMapCenter(mapCenter);
1055 void MapEditor::exportXML(const QString &dir)
1057 // Create subdirectories
1060 // write to directory
1061 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,CompleteMap);
1064 file.setName ( dir + "/"+mapName+".xml");
1065 if ( !file.open( IO_WriteOnly ) )
1067 // This should neverever happen
1068 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1072 // Write it finally, and write in UTF8, no matter what
1073 QTextStream ts( &file );
1074 ts.setEncoding (QTextStream::UnicodeUTF8);
1078 // Now write image, too
1079 exportImage (dir+"/images/"+mapName+".png");
1082 void MapEditor::clear()
1086 selection->unselect();
1093 void MapEditor::undo()
1096 d.setPath(bakMapDir);
1099 // Finish open lineEdits
1100 if (lineedit) finishedLineEditNoSave();
1104 selection->unselect();
1108 mapBuilderHandler handler;
1109 QXmlInputSource source;
1110 source.setData(backupXML);
1111 QXmlSimpleReader reader;
1112 reader.setContentHandler( &handler );
1113 reader.setErrorHandler( &handler );
1114 handler.setMapEditor( this );
1115 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1118 selection=undoSelection;
1119 selection->select();
1120 handler.setLoadMode (ImportReplace);
1125 handler.setLoadMode (NewMap);
1127 blockreposition=true;
1128 bool ok = reader.parse( source );
1129 blockreposition=false;
1131 mapCenter->reposition();
1135 // This should never ever happen
1136 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1137 tr( handler.errorProtocol() )+" in "+backupXML );
1139 // Undo not longer available now
1140 actionEditUndo->setEnabled (false);
1141 undoSelection=false;
1146 QMessageBox::critical( 0, tr( "Critical Error" ),
1147 "Temporary directory " +bakMapDir +
1148 tr (" used for undo is gone. \n"
1149 "I will create a new one, but at the moment no undo is available.\n"
1150 "Maybe you want to reload your original data.\n\n"
1151 "Sorry for any inconveniences.") );
1156 void MapEditor::copy()
1158 // Finish open lineEdits
1159 if (lineedit) finishedLineEditNoSave();
1163 if (typeid(*selection) == typeid(BranchObj) )
1167 clipboardME->clear();
1168 clipboardME->getMapCenter()->addBranch();
1169 to=clipboardME->getMapCenter()->getLastBranch();
1172 from=(BranchObj*)(selection);
1175 // keep position relative to parent
1176 to->move2RelPos ( from->getRelPos());
1178 // select data in clipboard
1179 clipboardME->select ("bo:0");
1181 // repositioning makes testing nicer,
1182 // but is not needed usually:
1183 if (clipboardME->isVisible())
1185 clipboardME->getMapCenter()->reposition();
1188 clipboardME->hide();
1191 if (typeid(*selection) == typeid(FloatImageObj) )
1194 FloatImageObj* from;
1195 clipboardME->clear();
1196 clipboardME->getMapCenter()->addFloatImage();
1197 to=clipboardME->getMapCenter()->getLastFloatImage();
1200 from=(FloatImageObj*)(selection);
1203 // select data in clipboard
1204 clipboardME->select ("fi:0");
1206 // repositioning makes testing nicer,
1207 // but is not needed usually:
1208 if (clipboardME->isVisible())
1210 clipboardME->getMapCenter()->reposition();
1213 clipboardME->hide();
1219 LinkableMapObj* MapEditor::pasteNoSave()
1221 // Finish open lineEdits
1222 if (lineedit) finishedLineEditNoSave();
1224 LinkableMapObj *fromLMO=clipboardME->getSelection();
1225 LinkableMapObj *returnLMO=NULL;
1227 if (selection && fromLMO)
1230 if (typeid(*fromLMO) == typeid(BranchObj) )
1232 if (typeid(*selection) == typeid(MapCenterObj))
1234 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1235 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1237 if (typeid(*selection) == typeid(BranchObj))
1238 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1241 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1242 (typeid(*selection) == typeid (BranchObj) ||
1243 typeid(*selection)==typeid(MapCenterObj)) )
1244 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1250 void MapEditor::cutNoSave()
1252 // Finish open lineEdits
1253 if (lineedit) finishedLineEditNoSave();
1257 if (selection != NULL) {
1258 if (typeid(*selection) == typeid(BranchObj) )
1260 bo=(BranchObj*)(selection);
1261 par=(BranchObj*)(bo->getParObj());
1264 par->removeBranch(bo);
1266 selection->select();
1268 if (typeid(*selection) == typeid(FloatImageObj) )
1270 FloatImageObj* fio=(FloatImageObj*)(selection);
1271 par=(BranchObj*)(fio->getParObj());
1274 par->removeFloatImage(fio);
1276 selection->select();
1281 void MapEditor::paste()
1284 saveState(PartOfMap,selection);
1286 mapCenter->reposition();
1290 void MapEditor::cut()
1293 saveState(PartOfMap,selection->getParObj());
1296 mapCenter->reposition();
1300 void MapEditor::moveBranchUp()
1302 // Finish open lineEdits
1303 if (lineedit) finishedLineEditNoSave();
1307 if (typeid(*selection) == typeid(BranchObj) )
1310 saveState(PartOfMap,selection->getParObj());
1311 bo=(BranchObj*)(selection);
1312 par=(BranchObj*)(bo->getParObj());
1313 selection->unselect();
1314 selection=par->moveBranchUp (bo);
1315 selection->select();
1316 mapCenter->reposition();
1317 ensureSelectionVisible();
1321 void MapEditor::moveBranchDown()
1323 // Finish open lineEdits
1324 if (lineedit) finishedLineEditNoSave();
1328 if (typeid(*selection) == typeid(BranchObj) )
1331 saveState(PartOfMap,selection->getParObj());
1332 bo=(BranchObj*)(selection);
1333 par=(BranchObj*)(bo->getParObj());
1334 selection->unselect();
1335 selection=par->moveBranchDown(bo);
1336 selection->select();
1337 mapCenter->reposition();
1338 ensureSelectionVisible();
1342 void MapEditor::editHeading()
1344 // Finish open lineEdits
1345 if (lineedit) finishedLineEditNoSave();
1348 (typeid(*selection) == typeid(BranchObj) ||
1349 typeid(*selection) == typeid(MapCenterObj) ) )
1352 saveState(PartOfMap,selection);
1354 ensureSelectionVisible();
1355 editingBO=(BranchObj*)(selection);
1356 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1357 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1358 QString s=editingBO->getHeading();
1359 lineedit->setText(s);
1360 lineedit->setCursorPosition(1);
1361 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1362 lineedit->selectAll();
1365 lineedit->grabKeyboard();
1366 lineedit->setFocus();
1370 void MapEditor::addNewBranch(int pos)
1372 // Finish open lineEdits
1373 if (lineedit) finishedLineEditNoSave();
1376 (typeid(*selection) == typeid(BranchObj) ||
1377 typeid(*selection) == typeid(MapCenterObj) ) )
1380 saveState(PartOfMap,selection);
1382 BranchObj* bo1 = (BranchObj*) (selection);
1383 bool wasScrolled=false;
1384 BranchObj *newbo=NULL;
1387 // save scroll state. If scrolled, automatically select
1388 // new branch in order to tmp unscroll parent...
1389 wasScrolled=bo1->isScrolled();
1390 newbo=bo1->addBranch();
1393 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1397 // add above selection
1398 newbo=parbo->insertBranch(bo1->getNum());
1400 // add below selection
1401 newbo=parbo->insertBranch(bo1->getNum()+1);
1403 // This should not happen...
1408 LinkableMapObj *oldselection=selection;
1410 mapCenter->reposition();
1412 if (actionSettingsAutoedit->isOn() ||
1413 actionSettingsAutoselectHeading->isOn() )
1415 selection->unselect();
1417 selection->select();
1418 if (actionSettingsPasteNewHeading->isOn() )
1420 BranchObj *bo2= (BranchObj*)(selection);
1421 bo2->setHeading("");
1423 if (actionSettingsAutoedit->isOn() )
1425 if (!actionSettingsAutoselectHeading->isOn()
1428 selection->unselect();
1429 selection=oldselection;
1430 selection->select();
1437 void MapEditor::addNewBranchHere()
1439 // Finish open lineEdits
1440 if (lineedit) finishedLineEditNoSave();
1443 (typeid(*selection) == typeid(BranchObj) ) )
1446 saveState(PartOfMap,selection);
1448 BranchObj* bo1 = (BranchObj*) (selection);
1449 bool wasScrolled=false;
1450 BranchObj *newbo=NULL;
1451 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1454 // add below selection
1455 newbo=parbo->insertBranch(bo1->getNum()+1);
1458 LinkableMapObj *oldselection=selection;
1459 ((BranchObj*)(selection))->moveBranchTo (newbo,-1);
1461 mapCenter->reposition();
1463 if (actionSettingsAutoedit->isOn() ||
1464 actionSettingsAutoselectHeading->isOn() )
1466 selection->unselect();
1468 selection->select();
1469 if (actionSettingsPasteNewHeading->isOn() )
1471 BranchObj *bo2= (BranchObj*)(selection);
1472 bo2->setHeading("");
1474 if (actionSettingsAutoedit->isOn() )
1476 if (!actionSettingsAutoselectHeading->isOn()
1479 selection->unselect();
1480 selection=oldselection;
1481 selection->select();
1487 void MapEditor::deleteSelection()
1489 // Finish open lineEdits
1490 if (lineedit) finishedLineEditNoSave();
1492 if (selection && typeid(*selection) ==typeid(BranchObj) )
1495 saveState(PartOfMap,selection->getParObj());
1496 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1497 BranchObj* par=(BranchObj*)(bo->getParObj());
1500 par->removeBranch(bo);
1502 selection->select();
1503 ensureSelectionVisible();
1504 mapCenter->reposition();
1507 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1510 saveState(PartOfMap,selection->getParObj());
1511 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1512 BranchObj* par=(BranchObj*)(fio->getParObj());
1515 par->removeFloatImage(fio);
1517 selection->select();
1518 ensureSelectionVisible();
1519 mapCenter->reposition();
1524 LinkableMapObj* MapEditor::getSelection()
1529 bool MapEditor::select (const QString &s)
1531 LinkableMapObj *lmo=mapCenter->findObj(s);
1533 // Finally select the found object
1536 if (selection) unselect();
1538 selection->select();
1540 ensureSelectionVisible();
1546 void MapEditor::unselect()
1550 selectionLast=selection;
1551 selection->unselect();
1556 void MapEditor::reselect()
1560 selection=selectionLast;
1561 selection->select();
1566 void MapEditor::selectNextBranch()
1568 // Increase number of branch
1571 QString s=selection->getSelectString();
1577 part=s.section(",",-1);
1579 num=part.right(part.length() - 3);
1581 s=s.left (s.length() -num.length());
1584 num=QString ("%1").arg(num.toUInt()+1);
1588 // Try to select this one
1589 if (select (s)) return;
1591 // We have no direct successor,
1592 // try to increase the parental number in order to
1593 // find a successor with same depth
1595 int d=selection->getDepth();
1600 while (!found && d>0)
1602 s=s.section (",",0,d-1);
1603 // replace substring of current depth in s with "1"
1604 part=s.section(",",-1);
1606 num=part.right(part.length() - 3);
1610 // increase number of parent
1611 num=QString ("%1").arg(num.toUInt()+1);
1612 s=s.section (",",0,d-2) + ","+ typ+num;
1615 // Special case, look at orientation
1616 if (selection->getOrientation()==OrientRightOfCenter)
1617 num=QString ("%1").arg(num.toUInt()+1);
1619 num=QString ("%1").arg(num.toUInt()-1);
1624 // pad to oldDepth, select the first branch for each depth
1625 for (i=d;i<oldDepth;i++)
1630 if ( ((BranchObj*)(selection))->countBranches()>0)
1638 // try to select the freshly built string
1646 void MapEditor::selectPrevBranch()
1648 // Decrease number of branch
1651 QString s=selection->getSelectString();
1657 part=s.section(",",-1);
1659 num=part.right(part.length() - 3);
1661 s=s.left (s.length() -num.length());
1664 num=QString ("%1").arg(num.toUInt()-1);
1668 // Try to select this one
1669 if (select (s)) return;
1671 // We have no direct precessor,
1672 // try to decrease the parental number in order to
1673 // find a precessor with same depth
1675 int d=selection->getDepth();
1680 while (!found && d>0)
1682 s=s.section (",",0,d-1);
1683 // replace substring of current depth in s with "1"
1684 part=s.section(",",-1);
1686 num=part.right(part.length() - 3);
1690 // decrease number of parent
1691 num=QString ("%1").arg(num.toUInt()-1);
1692 s=s.section (",",0,d-2) + ","+ typ+num;
1695 // Special case, look at orientation
1696 if (selection->getOrientation()==OrientRightOfCenter)
1697 num=QString ("%1").arg(num.toUInt()-1);
1699 num=QString ("%1").arg(num.toUInt()+1);
1704 // pad to oldDepth, select the last branch for each depth
1705 for (i=d;i<oldDepth;i++)
1709 if ( ((BranchObj*)(selection))->countBranches()>0)
1710 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1717 // try to select the freshly built string
1725 void MapEditor::selectUpperBranch()
1727 // Finish open lineEdits
1728 if (lineedit) finishedLineEditNoSave();
1732 if (typeid(*selection) == typeid(BranchObj))
1734 if (selection->getOrientation()==OrientRightOfCenter)
1737 if (selection->getDepth()==1)
1745 void MapEditor::selectLowerBranch()
1747 // Finish open lineEdits
1748 if (lineedit) finishedLineEditNoSave();
1752 if (typeid(*selection) == typeid(BranchObj))
1754 if (selection->getOrientation()==OrientRightOfCenter)
1757 if (selection->getDepth()==1)
1766 void MapEditor::selectLeftBranch()
1768 // Finish open lineEdits
1769 if (lineedit) finishedLineEditNoSave();
1775 if (typeid(*selection) == typeid(MapCenterObj))
1777 par= (BranchObj*) (selection);
1778 bo=par->getLastSelectedBranch();
1781 // Workaround for reselecting on left and right side
1782 if (bo->getOrientation()==OrientRightOfCenter)
1784 bo=par->getLastBranch();
1790 selection->select();
1792 ensureSelectionVisible();
1797 par=(BranchObj*)(selection->getParObj());
1798 if (selection->getOrientation()==OrientRightOfCenter)
1800 if (typeid(*selection) == typeid(BranchObj) ||
1801 typeid(*selection) == typeid(FloatImageObj))
1803 selection->unselect();
1805 selection->select();
1807 ensureSelectionVisible();
1811 if (typeid(*selection) == typeid(BranchObj) )
1813 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1816 selection->unselect();
1818 selection->select();
1820 ensureSelectionVisible();
1828 void MapEditor::selectRightBranch()
1830 // Finish open lineEdits
1831 if (lineedit) finishedLineEditNoSave();
1838 if (typeid(*selection) == typeid(MapCenterObj))
1840 par= (BranchObj*) (selection);
1841 bo=par->getLastSelectedBranch();
1844 // Workaround for relecting on left and right side
1845 if (bo->getOrientation()==OrientLeftOfCenter)
1846 bo=par->getFirstBranch();
1851 selection->select();
1852 ensureSelectionVisible();
1857 par=(BranchObj*)(selection->getParObj());
1858 if (selection->getOrientation()==OrientLeftOfCenter)
1860 if (typeid(*selection) == typeid(BranchObj) ||
1861 typeid(*selection) == typeid(FloatImageObj))
1863 selection->unselect();
1865 selection->select();
1867 ensureSelectionVisible();
1871 if (typeid(*selection) == typeid(BranchObj) )
1873 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1876 selection->unselect();
1878 selection->select();
1880 ensureSelectionVisible();
1888 void MapEditor::selectFirstBranch()
1890 // Finish open lineEdits
1891 if (lineedit) finishedLineEditNoSave();
1897 if (typeid(*selection) == typeid(BranchObj))
1899 bo1= (BranchObj*) (selection);
1900 par=(BranchObj*)(bo1->getParObj());
1901 bo2=par->getFirstBranch();
1905 selection->select();
1906 ensureSelectionVisible();
1913 void MapEditor::selectLastBranch()
1915 // Finish open lineEdits
1916 if (lineedit) finishedLineEditNoSave();
1922 if (typeid(*selection) == typeid(BranchObj))
1924 bo1= (BranchObj*) (selection);
1925 par=(BranchObj*)(bo1->getParObj());
1926 bo2=par->getLastBranch();
1930 selection->select();
1931 ensureSelectionVisible();
1938 void MapEditor::setColor(QColor c)
1943 void MapEditor::selectBackgroundColor()
1945 // Finish open lineEdits
1946 if (lineedit) finishedLineEditNoSave();
1948 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
1949 if ( !col.isValid() ) return;
1950 setBackgroundColor( col );
1954 void MapEditor::setBackgroundColor(QColor c)
1956 mapCanvas->setBackgroundColor (c);
1959 QColor MapEditor::pickColor()
1963 if (typeid(*selection) == typeid(BranchObj) ||
1964 typeid(*selection) == typeid(MapCenterObj))
1966 BranchObj *bo=(BranchObj*)(selection);
1967 actColor=bo->getColor();
1973 void MapEditor::colorItem()
1977 if (typeid(*selection) == typeid(BranchObj) ||
1978 typeid(*selection) == typeid(MapCenterObj))
1981 saveState(PartOfMap,selection);
1982 BranchObj *bo=(BranchObj*)(selection);
1983 bo->setColor(actColor, false); // color links, color childs
1988 void MapEditor::colorBranch()
1992 if (typeid(*selection) == typeid(BranchObj) ||
1993 typeid(*selection) == typeid(MapCenterObj))
1996 saveState(PartOfMap,selection);
1997 BranchObj *bo=(BranchObj*)(selection);
1998 bo->setColor(actColor, true); // color links, color childs
2004 void MapEditor::toggleStandardFlag(QString f)
2009 saveState(PartOfMap,selection);
2010 ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2014 void MapEditor::setViewCenter()
2016 // transform to CanvasView Coord:
2017 QPoint p=worldMatrix().map(movingCenter);
2018 center ( p.x(), p.y());
2022 BranchObj* MapEditor::findText (QString s, bool cs)
2025 { // Nothing found or new find process
2027 // nothing found, start again
2029 itFind=mapCenter->first();
2031 bool searching=true;
2032 bool foundNote=false;
2033 while (searching && !EOFind)
2037 // Searching in Note
2038 if (itFind->getNote().contains(s,cs))
2040 if (selection!=itFind)
2042 if (selection) ((BranchObj*)(selection))->unselect();
2044 selection->select();
2046 ensureSelectionVisible();
2048 if (textEditor->findText(s,cs))
2054 // Searching in Heading
2055 if (searching && itFind->getHeading().contains (s,cs) )
2057 if (selection) ((BranchObj*)(selection))->unselect();
2059 selection->select();
2061 ensureSelectionVisible();
2067 itFind=itFind->next();
2068 if (!itFind) EOFind=true;
2074 return (BranchObj*)(selection);
2079 void MapEditor::findReset()
2080 { // Necessary if text to find changes during a find process
2085 void MapEditor::openURL()
2089 if (typeid(*selection) == typeid(BranchObj) ||
2090 typeid(*selection) == typeid(MapCenterObj))
2092 QString url=((BranchObj*)(selection))->getURL();
2094 QProcess *proc = new QProcess( this );
2096 #if !defined(Q_OS_MACX)
2097 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2099 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2100 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2103 proc->addArgument( url);
2105 if ( !proc->start() )
2107 if (mainWindow->settingsURL() )
2113 void MapEditor::editURL()
2115 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2116 typeid(*selection) == typeid(MapCenterObj)) )
2119 QString text = QInputDialog::getText(
2120 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2121 ((BranchObj*)(selection))->getURL(), &ok, this );
2124 // user entered something and pressed OK
2125 ((BranchObj*)(selection))->setURL (text);
2132 void MapEditor::editHeading2URL()
2134 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2135 typeid(*selection) == typeid(MapCenterObj)) )
2137 BranchObj *b=(BranchObj*)(selection);
2138 b->setURL (b->getHeading());
2144 void MapEditor::editBugzilla2URL()
2146 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2147 typeid(*selection) == typeid(MapCenterObj)) )
2149 BranchObj *b=(BranchObj*)(selection);
2150 b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
2156 void MapEditor::editVymLink()
2158 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2159 typeid(*selection) == typeid(MapCenterObj)) )
2161 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2162 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2163 fd->setCaption(tr("VYM - Link to another map"));
2164 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2165 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2169 if ( fd->exec() == QDialog::Accepted )
2170 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2172 mapCenter->reposition();
2179 void MapEditor::deleteVymLink()
2181 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2182 typeid(*selection) == typeid(MapCenterObj)) )
2184 ((BranchObj*)(selection))->setVymLink ("" );
2186 mapCenter->reposition();
2193 QString MapEditor::getVymLink()
2195 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2196 typeid(*selection) == typeid(MapCenterObj)) )
2198 return ((BranchObj*)(selection))->getVymLink();
2204 void MapEditor::removeBranchHere()
2206 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2209 saveState(PartOfMap,selection->getParObj());
2210 QString sel=selection->getSelectString();
2211 BranchObj* bo=(BranchObj*)(selection);
2212 BranchObj* par=(BranchObj*)(bo->getParObj());
2214 par->removeBranchHere(bo);
2215 mapCenter->reposition();
2220 void MapEditor::removeChilds()
2222 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2225 saveState(PartOfMap,selection->getParObj());
2226 ((BranchObj*)(selection))->removeChilds();
2227 mapCenter->reposition();
2231 void MapEditor::editMapInfo()
2233 ExtraInfoDialog dia;
2234 dia.setMapName (getFileName() );
2235 dia.setAuthor (mapCenter->getAuthor() );
2236 dia.setComment(mapCenter->getComment() );
2241 QCanvasItemList l=canvas()->allItems();
2242 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2244 stats+=QString ("%1 items on canvas\n").arg (i,6);
2251 bo=mapCenter->first();
2254 if (!bo->getNote().isEmpty() ) n++;
2255 f+= bo->countFloatImages();
2257 xl+=bo->countXLinks();
2260 stats+=QString ("%1 branches\n").arg (b-1,6);
2261 stats+=QString ("%1 xLinks \n").arg (xl-1,6);
2262 stats+=QString ("%1 notes\n").arg (n,6);
2263 stats+=QString ("%1 images\n").arg (f,6);
2264 dia.setStats (stats);
2266 // Finally show dialog
2267 if (dia.exec() == QDialog::Accepted)
2269 mapCenter->setAuthor (dia.getAuthor() );
2270 mapCenter->setComment (dia.getComment() );
2275 void MapEditor::updateActions()
2278 if (getLinkColorHint()==HeadingColor)
2279 actionFormatLinkColorHint->setOn(true);
2281 actionFormatLinkColorHint->setOn(false);
2286 actionFormatLinkStyleLine->setOn(true);
2289 actionFormatLinkStyleParabel->setOn(true);
2292 actionFormatLinkStylePolyLine->setOn(true);
2294 case StylePolyParabel:
2295 actionFormatLinkStylePolyParabel->setOn(true);
2301 QPixmap pix( 16, 16 );
2302 pix.fill( mapCanvas->backgroundColor() );
2303 actionFormatBackColor->setIconSet( pix );
2304 pix.fill( defLinkColor );
2305 actionFormatLinkColor->setIconSet( pix );
2307 actionEditUndo->setEnabled( mapChanged );
2308 actionFileSave->setEnabled( mapUnsaved );
2312 if ( (typeid(*selection) == typeid(BranchObj)) ||
2313 (typeid(*selection) == typeid(MapCenterObj)) )
2315 BranchObj *bo=(BranchObj*)(selection);
2316 // Take care of links
2317 if (bo->countXLinks()==0)
2319 branchLinksContextMenu->clear();
2320 branchLinksContextMenu->insertItem ("No link available");
2321 branchLinksContextMenuDup->clear();
2322 branchLinksContextMenuDup->insertItem ("No link available");
2328 branchLinksContextMenu->clear();
2329 branchLinksContextMenuDup->clear();
2330 for (int i=0; i<=bo->countXLinks();i++)
2332 bot=bo->XLinkTargetAt(i);
2335 s=bot->getHeading();
2338 branchLinksContextMenu->insertItem (s);
2339 branchLinksContextMenuDup->insertItem (s);
2344 standardFlagsDefault->setEnabled (true);
2346 if ( bo->getURL().isEmpty() )
2347 actionEditOpenURL->setEnabled (false);
2349 actionEditOpenURL->setEnabled (true);
2351 if ( bo->getVymLink().isEmpty() )
2353 actionEditOpenVymLink->setEnabled (false);
2354 actionEditDeleteVymLink->setEnabled (false);
2357 actionEditOpenVymLink->setEnabled (true);
2358 actionEditDeleteVymLink->setEnabled (true);
2361 actionEditCopy->setEnabled (true);
2362 actionEditCut->setEnabled (true);
2363 if (clipboardME->getMapCenter()->countBranches()>0)
2364 actionEditPaste->setEnabled (true);
2366 actionEditPaste->setEnabled (false);
2367 for (a=actionListBranches.first();a;a=actionListBranches.next())
2368 a->setEnabled(true);
2369 actionEditDelete->setEnabled (true);
2370 actionEditToggleFloatExport->setEnabled (false);
2371 switch (selection->getFrameType())
2374 actionFormatFrameNone->setOn(true);
2377 actionFormatFrameRectangle->setOn(true);
2383 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2385 standardFlagsDefault->setEnabled (false);
2387 actionEditOpenURL->setEnabled (false);
2388 actionEditOpenVymLink->setEnabled (false);
2389 actionEditDeleteVymLink->setEnabled (false);
2391 actionEditCopy->setEnabled (true);
2392 actionEditCut->setEnabled (true);
2393 actionEditPaste->setEnabled (false); //FIXME
2394 for (a=actionListBranches.first();a;a=actionListBranches.next())
2395 a->setEnabled(false);
2396 actionEditDelete->setEnabled (true);
2397 actionEditToggleFloatExport->setOn
2398 ( ((FloatImageObj*)(selection))->getFloatExport() );
2403 standardFlagsDefault->setEnabled (false);
2405 actionEditCopy->setEnabled (false);
2406 actionEditCut->setEnabled (false);
2407 actionEditPaste->setEnabled (false);
2408 for (a=actionListBranches.first();a;a=actionListBranches.next())
2409 a->setEnabled(false);
2411 actionEditOpenURL->setEnabled (false);
2412 actionEditOpenVymLink->setEnabled (false);
2413 actionEditDeleteVymLink->setEnabled (false);
2414 actionEditHeading2URL->setEnabled (false);
2415 actionEditDelete->setEnabled (false);
2416 actionEditToggleFloatExport->setEnabled (false);
2420 void MapEditor::setLinkStyle (LinkStyle ls)
2427 bo=mapCenter->first();
2431 bo->setLinkStyle(bo->getDefLinkStyle());
2434 mapCenter->reposition();
2437 LinkStyle MapEditor::getLinkStyle ()
2442 void MapEditor::setLinkColor(QColor c)
2448 void MapEditor::setLinkColorHint()
2450 // called from setLinkColorHint(lch) or at end of parse
2452 bo=mapCenter->first();
2460 void MapEditor::setLinkColorHint(LinkColorHint lch)
2466 void MapEditor::toggleLinkColorHint()
2468 if (linkcolorhint==HeadingColor)
2469 linkcolorhint=DefaultColor;
2471 linkcolorhint=HeadingColor;
2473 bo=mapCenter->first();
2481 LinkColorHint MapEditor::getLinkColorHint()
2483 return linkcolorhint;
2486 QColor MapEditor::getDefLinkColor()
2488 return defLinkColor;
2491 void MapEditor::setDefXLinkColor(QColor col)
2496 QColor MapEditor::getDefXLinkColor()
2498 return defXLinkColor;
2501 void MapEditor::setDefXLinkWidth (int w)
2506 int MapEditor::getDefXLinkWidth()
2508 return defXLinkWidth;
2511 void MapEditor::selectLinkColor()
2513 // Finish open lineEdits
2514 if (lineedit) finishedLineEditNoSave();
2516 QColor col = QColorDialog::getColor( defLinkColor, this );
2517 if ( !col.isValid() ) return;
2518 setLinkColor( col );
2522 void MapEditor::toggleScroll()
2524 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2526 BranchObj *bo=((BranchObj*)(selection));
2527 if (bo->countBranches()==0) return;
2528 if (bo->getDepth()==0) return;
2530 saveState(PartOfMap,selection);
2537 void MapEditor::unScrollAll()
2540 bo=mapCenter->first();
2543 if (bo->isScrolled()) bo->toggleScroll();
2548 void MapEditor::loadFloatImage ()
2551 (typeid(*selection) == typeid(BranchObj)) ||
2552 (typeid(*selection) == typeid(MapCenterObj)) )
2554 BranchObj *bo=((BranchObj*)(selection));
2556 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2557 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2558 ImagePreview *p =new ImagePreview (fd);
2559 fd->setContentsPreviewEnabled( TRUE );
2560 fd->setContentsPreview( p, p );
2561 fd->setPreviewMode( QFileDialog::Contents );
2562 fd->setCaption(tr("vym - Load image"));
2563 fd->setDir (lastImageDir);
2567 if ( fd->exec() == QDialog::Accepted )
2570 saveState(PartOfMap,selection);
2571 QString fn=fd->selectedFile();
2572 lastImageDir=fn.left(fn.findRev ("/"));
2573 bo->addFloatImage();
2574 // FIXME check if load was successful
2575 bo->getLastFloatImage()->load(fn);
2576 bo->getLastFloatImage()->setOriginalFilename(fn);
2577 mapCenter->reposition();
2584 void MapEditor::saveFloatImage (int item)
2587 (typeid(*selection) == typeid(FloatImageObj)) )
2589 FloatImageObj *fio=((FloatImageObj*)(selection));
2590 const char* fmt = saveImageFormatMenu->text(item);
2592 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2593 fd->addFilter ("PNG (*.png)");
2594 fd->addFilter ("BMP (*.bmp)");
2595 fd->addFilter ("XBM (*.xbm)");
2596 fd->addFilter ("JPG (*.jpg)");
2597 fd->addFilter ("XPM (*.xpm)");
2598 fd->addFilter ("GIF (*.gif)");
2599 fd->addFilter ("PNM (*.pnm)");
2600 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2601 fd->setCaption(tr("vym - Save image as ") + fmt);
2602 fd->setMode( QFileDialog::AnyFile );
2603 fd->setSelection (fio->getOriginalFilename());
2607 if ( fd->exec() == QDialog::Accepted )
2609 if (QFile (fd->selectedFile()).exists() )
2611 QMessageBox mb( "VYM",
2612 tr("The file ") + fd->selectedFile() +
2613 tr(" exists already. "
2614 "Do you want to overwrite it?"),
2615 QMessageBox::Warning,
2616 QMessageBox::Yes | QMessageBox::Default,
2617 QMessageBox::Cancel | QMessageBox::Escape,
2618 QMessageBox::QMessageBox::NoButton );
2620 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2621 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2624 case QMessageBox::Yes:
2627 case QMessageBox::Cancel:
2633 fio->save (fd->selectedFile(),fmt);
2638 void MapEditor::toggleFloatExport()
2641 (typeid(*selection) == typeid(FloatImageObj))||
2642 (typeid(*selection) == typeid(FloatObj)) )
2644 FloatImageObj *fio=((FloatImageObj*)(selection));
2645 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2649 void MapEditor::setFrame(const FrameType &t)
2652 (typeid(*selection) == typeid(BranchObj)) ||
2653 (typeid(*selection) == typeid(MapCenterObj)) )
2655 selection->setFrameType (t);
2656 mapCenter->reposition();
2657 selection->updateLink();
2661 void MapEditor::importDir(BranchObj *dst, QDir d)
2664 (typeid(*selection) == typeid(BranchObj)) ||
2665 (typeid(*selection) == typeid(MapCenterObj)) )
2669 // Traverse directories
2670 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2671 const QFileInfoList *dirlist = d.entryInfoList();
2672 QFileInfoListIterator itdir( *dirlist );
2675 while ( (fi = itdir.current()) != 0 )
2677 if (fi->fileName() != "." && fi->fileName() != ".." )
2680 bo=dst->getLastBranch();
2681 bo->setHeading (fi->fileName() );
2682 bo->setColor (QColor("blue"),false);
2684 if ( !d.cd(fi->fileName()) )
2685 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2688 // Recursively add subdirs
2696 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2697 const QFileInfoList *filelist = d.entryInfoList();
2698 QFileInfoListIterator itfile( *filelist );
2700 while ( (fi = itfile.current()) != 0 )
2703 bo=dst->getLastBranch();
2704 bo->setHeading (fi->fileName() );
2705 bo->setColor (QColor("black"),false);
2706 if (fi->fileName().right(4) == ".vym" )
2707 bo->setVymLink (fi->filePath());
2714 void MapEditor::importDir()
2717 (typeid(*selection) == typeid(BranchObj)) ||
2718 (typeid(*selection) == typeid(MapCenterObj)) )
2720 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2721 fd->setMode (QFileDialog::DirectoryOnly);
2722 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2723 fd->setCaption(tr("VYM - Choose directory structur to import"));
2727 if ( fd->exec() == QDialog::Accepted )
2729 BranchObj *bo=((BranchObj*)(selection));
2730 importDir (bo,QDir(fd->selectedFile()) );
2731 mapCenter->reposition();
2738 void MapEditor::followXLink(int i)
2741 (typeid(*selection) == typeid(BranchObj)) ||
2742 (typeid(*selection) == typeid(MapCenterObj)) )
2744 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2747 selection->unselect();
2749 selection->select();
2750 ensureSelectionVisible();
2755 void MapEditor::editXLink(int i)
2758 (typeid(*selection) == typeid(BranchObj)) ||
2759 (typeid(*selection) == typeid(MapCenterObj)) )
2761 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2764 EditXLinkDialog dia;
2766 dia.setSelection(selection);
2767 if (dia.exec() == QDialog::Accepted)
2769 if (dia.useSettingsGlobal() )
2771 setDefXLinkColor (xlo->getColor() );
2772 setDefXLinkWidth (xlo->getWidth() );
2774 if (dia.deleteXLink())
2775 ((BranchObj*)(selection))->deleteXLinkAt(i);
2782 void MapEditor::testFunction()
2784 cout << "MapEditor::testFunction() called\n";
2787 void MapEditor::ensureSelectionVisible()
2791 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2793 if (selection->getOrientation() == OrientLeftOfCenter)
2794 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2796 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2797 ensureVisible (p.x(), p.y() );
2802 void MapEditor::updateViewCenter()
2804 // Update movingCenter, so that we can zoom comfortably later
2805 QRect rc = QRect( contentsX(), contentsY(),
2806 visibleWidth(), visibleHeight() );
2807 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2808 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2809 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2812 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2814 // Lineedits are already closed by preceding
2815 // mouseEvent, we don't need to close here.
2817 QPoint p = inverseWorldMatrix().map(e->pos());
2818 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2821 { // MapObj was found
2822 if (selection != lmo)
2824 // select the MapObj
2825 if (selection) selection->unselect();
2827 selection->select();
2833 if (typeid(*selection)==typeid(BranchObj) ||
2834 typeid(*selection)==typeid(MapCenterObj) )
2836 // Context Menu on branch or mapcenter
2838 branchContextMenu->popup(e->globalPos() );
2840 if (typeid(*selection)==typeid(FloatImageObj))
2842 // Context Menu on floatimage
2844 floatimageContextMenu->popup(e->globalPos() );
2848 { // No MapObj found, we are on the Canvas itself
2849 // Context Menu on Canvas
2851 canvasContextMenu->popup(e->globalPos() );
2855 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2857 // Finish open lineEdits
2858 if (lineedit) finishedLineEditNoSave();
2860 QPoint p = inverseWorldMatrix().map(e->pos());
2861 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2863 // Special case: CTRL is pressed
2864 if (e->state() & QMouseEvent::ControlButton)
2866 if (actionModModeColor->isOn())
2868 if (e->state() & QMouseEvent::ControlButton)
2871 setCursor (pickColorCursor);
2875 if (actionModModeLink->isOn())
2877 BranchObj *bo_begin=NULL;
2879 bo_begin=(BranchObj*)(lmo);
2882 ((typeid(*selection) == typeid(BranchObj)) ||
2883 (typeid(*selection) == typeid(MapCenterObj))) )
2884 bo_begin=(BranchObj*)(selection);
2888 linkingObj_src=bo_begin;
2889 tmpXLink=new XLinkObj (mapCanvas);
2890 tmpXLink->setBegin (bo_begin);
2891 tmpXLink->setEnd (p);
2892 tmpXLink->setColor(defXLinkColor);
2893 tmpXLink->setWidth(defXLinkWidth);
2894 tmpXLink->updateXLink();
2895 tmpXLink->setVisibility (true);
2902 { // MapObj was found
2903 if (selection != lmo)
2905 // select the MapObj
2906 if (selection) selection->unselect();
2908 selection->select();
2914 // Check, if systemFlag clicked
2915 if (typeid(*selection)==typeid(BranchObj) ||
2916 typeid(*selection)==typeid(MapCenterObj) )
2918 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
2919 if (!foname.isEmpty())
2921 // Do not move, if systemFlag clicked
2925 if (foname=="vymLink")
2927 mainWindow->editOpenVymLink();
2928 // tabWidget may change, better return now
2929 // before segfaulting...
2933 mainWindow->windowToggleNoteEditor();
2937 // Left Button Move Branches
2938 if (e->button() == QMouseEvent::LeftButton )
2940 // If modMode==copy, then we want to "move" the _new_ object around
2941 // then we need the offset from p to the _old_ selection, because of tmp
2942 if (actionModModeCopy->isOn() &&
2943 e->state() & QMouseEvent::ControlButton)
2945 if (typeid(*selection)==typeid(BranchObj) )
2948 movingObj_start.setX( p.x() - selection->x() );
2949 movingObj_start.setY( p.y() - selection->y() );
2950 mapCenter->addBranch ((BranchObj*)(selection));
2952 selection=mapCenter->getLastBranch();
2953 selection->select();
2954 selection->setParObjTmp ((BranchObj*)(selection),p,1);
2955 selection->updateLink();
2959 movingObj_start.setX( p.x() - selection->x() );
2960 movingObj_start.setY( p.y() - selection->y() );
2963 movingObj=selection;
2965 // Middle Button Toggle Scroll
2966 // (On Mac OS X this won't work, but we still have
2967 // a button in the toolbar)
2968 if (e->button() == QMouseEvent::MidButton )
2972 { // No MapObj found, we are on the Canvas itself
2973 // Left Button move Pos of CanvasView
2974 if (e->button() == QMouseEvent::LeftButton )
2976 movingObj=NULL; // move Content not Obj
2977 movingObj_start=e->globalPos();
2978 movingCont_start=QPoint (contentsX(), contentsY() );
2979 movingVec=QPoint(0,0);
2980 setCursor(handOpenCursor);
2985 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
2987 QPoint p = inverseWorldMatrix().map(e->pos());
2989 // Move the selected MapObj
2990 if ( selection && movingObj)
2992 ensureVisible (p.x(),p.y());
2994 // Now move the selection, but add relative position
2995 // (movingObj_start) where selection was chosen with
2996 // mousepointer. (This avoids flickering resp. jumping
2997 // of selection back to absPos)
2999 LinkableMapObj *lmosel;
3000 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3002 // Check if we could link
3003 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3006 if (typeid(*selection) == typeid(FloatImageObj))
3010 FloatObj *fo=(FloatObj*)(selection);
3011 if (fo->getLinkStyle()==StyleUndef)
3013 fo->setLinkStyle(fo->getDefLinkStyle());
3014 fo->setLinkColor(fo->getParObj()->getLinkColor());
3016 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3020 // Relink float to new mapcenter or branch, if shift is pressed
3021 // Only relink, if selection really has a new parent
3022 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3023 ( (typeid(*lmo)==typeid(BranchObj)) ||
3024 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3025 ( lmo != fo->getParObj())
3028 if (typeid(*fo) == typeid(FloatImageObj))
3030 FloatImageObj *fio=(FloatImageObj*)(fo);
3031 ((BranchObj*)(lmo))->addFloatImage (fio);
3033 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3034 fio=((BranchObj*)(lmo))->getLastFloatImage();
3037 selection=(LinkableMapObj*)(fio);
3038 selection->select();
3039 movingObj=(MapObj*)(fio);
3040 // setLinkStyle calls updateLink, only set it once
3041 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3042 fio->setLinkStyle (fio->getDefLinkStyle());
3045 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3047 } else // selection != a FloatObj
3049 if (lmosel->getDepth()==0)
3051 if (e->state() == (LeftButton | !ShiftButton))
3052 // If mapCenter is moved, move all the rest by default, too.
3053 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3055 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3058 if (lmosel->getDepth()==1)
3060 // depth==1, mainbranch
3062 saveState(PartOfMap,lmosel);
3063 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3067 if (lmosel->getOrientation() == OrientLeftOfCenter)
3068 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3069 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3070 p.y()-movingObj_start.y() );
3072 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3074 // reposition subbranch
3075 lmosel->reposition();
3076 //ensureSelectionVisible();
3078 if (lmo && (lmo!=selection) &&
3079 (typeid(*lmo) == typeid(BranchObj) ||
3080 (typeid(*lmo) == typeid(MapCenterObj) )
3083 if (e->state() & QMouseEvent::ControlButton)
3085 // Special case: CTRL to link below lmo
3086 lmosel->setParObjTmp (lmo,p,+1);
3088 else if (e->state() & QMouseEvent::ShiftButton)
3089 lmosel->setParObjTmp (lmo,p,-1);
3091 lmosel->setParObjTmp (lmo,p,0);
3094 lmosel->unsetParObjTmp();
3096 if (lmo &&(lmo==selection))
3097 // Could link to myself (happens sometimes...)
3098 lmosel->unsetParObjTmp();
3100 // no Obj under selection, go back to original Parent
3101 lmosel->unsetParObjTmp();
3106 } // no FloatImageObj
3110 } // selection && moving_obj
3112 // Draw a link from one branch to another
3115 tmpXLink->setEnd (p);
3116 tmpXLink->updateXLink();
3120 if (!movingObj && !pickingColor &&!drawingLink)
3122 QPoint p=e->globalPos();
3123 movingVec.setX(-p.x() + movingObj_start.x() );
3124 movingVec.setY(-p.y() + movingObj_start.y() );
3125 setContentsPos( movingCont_start.x() + movingVec.x(),
3126 movingCont_start.y() + movingVec.y());
3133 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3135 LinkableMapObj *dst;
3136 // Have we been picking color?
3140 setCursor (ArrowCursor);
3141 // Check if we are over another branch
3142 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3143 if (dst && selection)
3145 if (e->state() & QMouseEvent::ShiftButton)
3147 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3148 ((BranchObj*)(selection))->setLinkColor ();
3152 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3153 ((BranchObj*)(selection))->setLinkColor ();
3159 // Have we been drawing a link?
3163 // Check if we are over another branch
3164 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3165 if (dst && selection)
3167 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3168 tmpXLink->updateXLink();
3169 tmpXLink->activate();
3180 // Have we been moving something?
3181 if ( selection && movingObj )
3183 // Check if we are over another branch, but ignore
3184 // any found LMOs, which are FloatObjs
3185 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3186 ((LinkableMapObj*)(selection)) );
3189 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3194 // Now check, if we have been moving a branch
3195 if (typeid(*selection) == typeid(BranchObj) )
3197 // save the position in case we link to mapcenter
3198 QPoint savePos=QPoint (selection->x(),selection->y() );
3200 // Reset the temporary drawn link to the original one
3201 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3209 // remove the current selection, if we have no destination
3210 selection->unselect();
3211 ((BranchObj*)(selection->getParObj()))->removeBranch ((BranchObj*)(selection));
3214 selection=selectionLast;
3216 selection->select();
3223 // TODO we also could check, if dest and src are on same branch,
3224 // then it would be sufficient to saveState of this branch
3226 // Modifiers allow to insert above/below dst
3227 if (e->state() & QMouseEvent::ShiftButton)
3229 ((BranchObj*)(selection))->moveBranchTo
3232 ((BranchObj*)(dst))->getNum()
3234 //if (selection) selection->select();
3236 if (e->state() & QMouseEvent::ControlButton)
3238 ((BranchObj*)(selection))->moveBranchTo
3241 ((BranchObj*)(dst))->getNum()+1
3243 //if (selection) selection->select();
3246 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
3247 if (dst->getDepth()==0)
3248 ((BranchObj*)(selection))->move (savePos);
3251 // Draw the original link, before selection was moved around
3252 mapCenter->reposition();
3254 // Finally resize canvas, if needed
3259 // maybe we moved View: set old cursor
3260 setCursor (ArrowCursor);
3264 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3266 // Finish open lineEdits
3267 if (lineedit) finishedLineEditNoSave();
3269 if (e->button() == QMouseEvent::LeftButton )
3271 QPoint p = inverseWorldMatrix().map(e->pos());
3272 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3273 if (lmo) { // MapObj was found
3274 // First select the MapObj than edit heading
3275 if (selection) selection->unselect();
3277 selection->select();
3279 saveState(PartOfMap,selection);
3285 void MapEditor::resizeEvent (QResizeEvent* e)
3287 QCanvasView::resizeEvent( e );
3290 if (!fileName.isEmpty()) s=fileName;