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;
125 extern QPopupMenu *branchContextMenu;
126 extern QPopupMenu *branchLinksContextMenu;
127 extern QPopupMenu *branchLinksContextMenuDup;
128 extern QPopupMenu *floatimageContextMenu;
129 extern QPopupMenu *saveImageFormatMenu;
130 extern QPopupMenu *exportImageFormatMenu;
131 extern QPopupMenu *canvasContextMenu;
133 extern Settings settings;
136 ///////////////////////////////////////////////////////////////////////
137 ///////////////////////////////////////////////////////////////////////
138 MapEditor::MapEditor(
139 QWidget* parent, bool interactive, const char* name, WFlags f) :
140 QCanvasView(parent,name,f)
142 //cout << "Constructor ME "<<this<<endl;
144 mapCanvas = new QCanvas(1000,800);
145 mapCanvas->setAdvancePeriod(30);
147 setCanvas (mapCanvas);
149 setVScrollBarMode ( QScrollView::AlwaysOn );
150 setHScrollBarMode ( QScrollView::AlwaysOn );
152 // Now create the _global_ system flags _once_:
153 // (Later all OrnamentedObj copy from this
154 // and set their own canvas)
155 if (!systemFlagsDefault)
157 systemFlagsDefault = new FlagRowObj (mapCanvas);
158 systemFlagsDefault->setVisibility (false);
159 systemFlagsDefault->setName ("systemFlagsDef");
161 FlagObj *fo = new FlagObj (mapCanvas);
162 fo->load(QPixmap(flag_note_xpm));
164 fo->setToolTip(tr("Note","Systemflag"));
165 systemFlagsDefault->addFlag (fo); // makes deep copy
167 fo->load(QPixmap(flag_url_xpm));
169 fo->setToolTip(tr("WWW Document (external)","Systemflag"));
170 systemFlagsDefault->addFlag (fo);
172 fo->load(QPixmap(flag_vymlink_xpm));
173 fo->setName("vymLink");
174 fo->setToolTip(tr("Link to another vym map","Systemflag"));
175 systemFlagsDefault->addFlag (fo);
177 fo->load(QPixmap(flag_scrolled_right_xpm));
178 fo->setName("scrolledright");
179 fo->setToolTip(tr("subtree is scrolled","Systemflag"));
180 systemFlagsDefault->addFlag (fo);
182 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
183 fo->setName("tmpUnscrolledright");
184 fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
185 systemFlagsDefault->addFlag (fo);
188 if (!standardFlagsDefault)
190 standardFlagsDefault = new FlagRowObj (mapCanvas);
191 standardFlagsDefault->setVisibility (false);
192 standardFlagsDefault->setName ("standardFlagsDef");
194 FlagObj *fo = new FlagObj (mapCanvas);
195 fo->load(QPixmap(flag_exclamationmark_xpm));
196 fo->setName("exclamationmark");
197 fo->setToolTip(tr("Take care!","Standardflag"));
198 standardFlagsDefault->addFlag (fo); // makes deep copy
200 fo->load(QPixmap(flag_questionmark_xpm));
201 fo->setName("questionmark");
202 fo->setToolTip(tr("Really?","Standardflag"));
203 standardFlagsDefault->addFlag (fo);
205 fo->load(QPixmap(flag_hook_green_xpm));
206 fo->setName("hook-green");
207 fo->setToolTip(tr("ok!","Standardflag"));
208 standardFlagsDefault->addFlag (fo);
210 fo->load(QPixmap(flag_cross_red_xpm));
211 fo->setName("cross-red");
212 fo->setToolTip(tr("Not ok!","Standardflag"));
213 standardFlagsDefault->addFlag (fo);
215 fo->load(QPixmap(flag_stopsign_xpm));
216 fo->setName("stopsign");
217 fo->setToolTip(tr("This won't work!","Standardflag"));
218 standardFlagsDefault->addFlag (fo);
220 fo->load(QPixmap(flag_smiley_good_xpm));
221 fo->setName("smiley-good");
222 fo->setToolTip(tr("Good","Standardflag"));
223 standardFlagsDefault->addFlag (fo);
225 fo->load(QPixmap(flag_smiley_sad_xpm));
226 fo->setName("smiley-sad");
227 fo->setToolTip(tr("Bad","Standardflag"));
228 standardFlagsDefault->addFlag (fo);
230 fo->load(QPixmap(flag_clock_xpm));
231 fo->setName("clock");
232 fo->setToolTip(tr("Time critical","Standardflag"));
233 standardFlagsDefault->addFlag (fo);
235 fo->load(QPixmap(flag_lamp_xpm));
237 fo->setToolTip(tr("Idea!","Standardflag"));
238 standardFlagsDefault->addFlag (fo);
240 fo->load(QPixmap(flag_arrow_up_xpm));
241 fo->setName("arrow-up");
242 fo->setToolTip(tr("Important","Standardflag"));
243 standardFlagsDefault->addFlag (fo);
245 fo->load(QPixmap(flag_arrow_down_xpm));
246 fo->setName("arrow-down");
247 fo->setToolTip(tr("Unimportant","Standardflag"));
248 standardFlagsDefault->addFlag (fo);
250 fo->load(QPixmap(flag_thumb_up_xpm));
251 fo->setName("thumb-up");
252 fo->setToolTip(tr("I like this","Standardflag"));
253 standardFlagsDefault->addFlag (fo);
255 fo->load(QPixmap(flag_thumb_down_xpm));
256 fo->setName("thumb-down");
257 fo->setToolTip(tr("I do not like this","Standardflag"));
258 standardFlagsDefault->addFlag (fo);
260 fo->load(QPixmap(flag_heart_xpm));
261 fo->setName("heart");
262 fo->setToolTip(tr("I just love... ","Standardflag"));
263 standardFlagsDefault->addFlag (fo);
265 fo->load(QPixmap(flag_flash_xpm));
266 fo->setName("flash");
267 fo->setToolTip(tr("Dangerous","Standardflag"));
268 standardFlagsDefault->addFlag (fo);
270 fo->load(QPixmap(flag_lifebelt_xpm));
271 fo->setName("lifebelt");
272 fo->setToolTip(tr("This will help","Standardflag"));
273 standardFlagsDefault->addFlag (fo);
278 mapCenter = new MapCenterObj(mapCanvas);
279 mapCenter->setVisibility (true);
280 mapCenter->setMapEditor (this);
281 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
285 lineedit = new QLineEdit(this, "lineedit" );
286 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
289 actColor=black; setColor (actColor);
290 defLinkColor=QColor (0,0,255);
291 defXLinkColor=QColor (180,180,180);
292 linkcolorhint=DefaultColor;
293 linkstyle=StylePolyParabel;
294 mapCanvas->setBackgroundColor (white);
296 // Create bitmap cursors, patform dependant
297 #if defined(Q_OS_MACX)
298 #include "icons/cursorhandopen16.xpm"
299 #include "icons/cursorcolorpicker16.xpm"
300 QBitmap cb( 16, 16, chandopen, TRUE );
301 QBitmap cm( 16, 16, chandopenmask, TRUE );
302 handOpenCursor=QCursor ( cb, cm );
303 // set hot spot to tip of picker
304 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
306 #include "icons/cursorhandopen.xpm"
307 #include "icons/cursorcolorpicker.xpm"
309 QBitmap cb( 32, 32, chandopen, TRUE );
310 QBitmap cm( 32, 32, chandopenmask, TRUE );
311 handOpenCursor=QCursor ( cb, cm );
312 // set hot spot to tip of picker
313 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
335 // Initialize find routine
342 blockreposition=false;
343 isInteractive=interactive;
345 // Create temporary files
348 // Initially set movingCentre
351 mapCenter->reposition(); // for positioning heading
354 MapEditor::~MapEditor()
356 //cout <<"Destructor MapEditor\n";
357 if (isInteractive) delTmpDirs();
360 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
364 QColor MapEditor::color()
369 QColor MapEditor::backgroundColor()
371 return mapCanvas->backgroundColor();
374 MapCenterObj* MapEditor::getMapCenter()
379 QCanvas* MapEditor::getCanvas()
384 void MapEditor::adjustCanvasSize()
386 // To adjust the canvas to map, viewport size and position, we have to
387 // do some coordinate magic...
389 // Get rectangle of (scroll-)view.
390 // We want to be in canvas coords, so
391 // we map. Important if view is zoomed...
392 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
393 visibleWidth(), visibleHeight()) );
395 // Now we need the bounding box of view AND map to calc the correct canvas size.
396 // Why? Because if the map itself is moved out of view, the view has to be enlarged
397 // to avoid jumping aroung...
398 QRect map=mapCenter->getTotalBBox();
400 // right edge - left edge
401 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
402 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
405 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
406 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
409 // move the map on canvas (in order to not move it on screen) this is neccessary
410 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
411 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
412 // to scroll to an empty area of canvas to the left.
413 // b) if topleft corner of map left of or above topleft of canvas
417 if (cw > mapCanvas->width() )
419 if (map.x()<0) dx=-map.x();
421 if (cw < mapCanvas->width() )
422 dx=-min (view.x(),map.x());
423 if (ch > mapCanvas->height() )
425 if (map.y()<0) dy=-map.y();
427 if (ch < mapCanvas->height() )
429 dy=-min (view.y(),map.y());
431 // We really have to resize now. Let's go...
432 mapCanvas->resize (cw,ch);
433 if ( (dx!=0) || (dy!=0) )
435 mapCenter->moveAllBy(dx,dy);
436 mapCenter->reposition();
438 // scroll the view (in order to not move map on screen)
444 bool MapEditor::blockReposition()
446 return blockreposition;
449 void MapEditor::makeTmpDirs()
451 // Create unique temporary directories
452 char tmpdir[]="/tmp/vym-XXXXXX";
453 bakMapDir=mkdtemp(tmpdir);
454 makeSubDirs(bakMapDir);
455 // FIXME set permissions
456 // and maybe use QT method for portability
459 void MapEditor::delTmpDirs()
461 //FIXME delete tmp directory, better use QT methods here:
462 system ( "rm -rf "+ bakMapDir );
466 void MapEditor::makeSubDirs(const QString &s)
474 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, SaveMode savemode)
476 // tmpdir temporary directory to which data will be writte
477 // prefix mapname, which will be appended to images etc.
478 // writeflags Only write flags for "real" save of map, not undo
479 // offset offset of bbox of whole map in canvas.
480 // Needed for XML export
481 // completeMap if false, only vympart will be written, without
498 ls="StylePolyParabel";
502 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
504 if (linkcolorhint==HeadingColor)
505 colhint=attribut("linkColorHint","HeadingColor");
507 QString mapAttr=attribut("version",__VYM_VERSION__);
508 if (savemode==CompleteMap)
509 mapAttr+= attribut("author",mapCenter->getAuthor()) +
510 attribut("comment",mapCenter->getComment()) +
511 attribut("date",mapCenter->getDate()) +
512 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
513 attribut("linkStyle", ls ) +
514 attribut("linkColor", defLinkColor.name() ) +
515 attribut("xlinkColor", defXLinkColor.name() ) +
516 attribut("xlinkWidth", QString().setNum(defXLinkWidth,10) ) +
518 s+=beginElement("vymmap",mapAttr);
521 // Find the used flags while traversing the tree
522 standardFlagsDefault->resetUsedCounter();
524 // Build xml recursivly
525 if (savemode==CompleteMap)
526 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
529 if ( undoSelection &&
530 typeid(*undoSelection) == typeid(BranchObj) )
531 s+=((BranchObj*)(undoSelection))->saveToDir(tmpdir,prefix,offset);
533 if (selection && typeid(*selection)==typeid(BranchObj))
534 s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
537 // Save local settings
538 s+=settings.getXMLData (destPath);
542 s+=valueElement("select",selection->getSelectString());
545 s+=endElement("vymmap");
548 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
553 void MapEditor::saveState()
555 saveState (CompleteMap,NULL);
558 void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part)
560 // all binary data is saved in bakMapDir (created in Constructor)
561 // the xml data itself is kept in memory in backupXML
563 // For faster write/read of data, a part of the map can be
564 // written. Then the undoSelection will mark the part of the
565 // map which should be replaced if an undo is wanted later.
567 if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) )
569 // Writing a vympart only is useful for BranchObj
571 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
575 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap);
579 void MapEditor::finishedLineEditNoSave()
581 // This is called by finishedLineEdit or any MapEditor method,
582 // which wants to assure, that lineedits finish, before e.g. a branch is
585 // After calling LineEdit and using the clipboard, the
586 // focus is not any longer on the main widget, we
587 // have to restore it using parentWidget()->setFocus()
591 editingBO->setHeading(lineedit->text() );
593 lineedit->releaseKeyboard();
595 parentWidget()->setFocus();
596 mapCenter->reposition();
598 ensureSelectionVisible();
603 bool MapEditor::isDefault()
608 bool MapEditor::isUnsaved()
613 bool MapEditor::hasChanged()
618 void MapEditor::setChanged()
623 actionEditUndo->setEnabled (true);
624 actionFileSave->setEnabled (true);
628 void MapEditor::closeMap()
630 // Finish open lineEdits
631 if (lineedit) finishedLineEditNoSave();
633 // Unselect before disabling the toolbar actions
634 if (selection) selection->unselect();
642 void MapEditor::setFilePath(QString fname)
644 setFilePath (fname,fname);
647 void MapEditor::setFilePath(QString fname, QString destname)
653 // If fname is not an absolute path, complete it
654 filePath=QDir(fname).absPath();
655 fileDir=filePath.left (1+filePath.findRev ("/"));
657 // Set short name, too. Search from behind:
658 int i=fileName.findRev("/");
659 if (i>=0) fileName=fileName.remove (0,i+1);
661 // Forget the .vym (or .xml) for name of map
662 mapName=fileName.left(fileName.findRev(".",-1,true) );
665 QString MapEditor::getFilePath()
670 QString MapEditor::getFileName()
675 QString MapEditor::getMapName()
680 QString MapEditor::getDestPath()
685 int MapEditor::load (QString &fname, const LoadMode &lmode)
687 // Finish open lineEdits
688 if (lineedit) finishedLineEditNoSave();
694 if (selection) selection->unselect();
697 mapCenter->setMapEditor(this);
698 // (map state is set later at end of load...)
702 saveState(PartOfMap,selection);
706 mapBuilderHandler handler;
709 // I am paranoid: file should exist anyway
710 // according to check in mainwindow.
713 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
714 tr("Couldn't open map " +fname)+".");
718 blockreposition=true;
719 QXmlInputSource source( file);
720 QXmlSimpleReader reader;
721 reader.setContentHandler( &handler );
722 reader.setErrorHandler( &handler );
723 handler.setMapEditor( this );
724 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
725 handler.setLoadMode (lmode);
726 bool ok = reader.parse( source );
727 blockreposition=false;
731 mapCenter->reposition();
741 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
742 tr( handler.errorProtocol() ) );
744 // Still return "success": the map maybe at least
745 // partially read by the parser
752 int MapEditor::save (const SaveMode &savemode)
754 // Finish open lineEdits
755 if (lineedit) finishedLineEditNoSave();
759 // Create mapName and fileDir
760 makeSubDirs (fileDir);
764 fname=mapName+".xml";
766 // use name given by user, even if he chooses .doc
770 // Check if fname is writeable
771 QFile file( fileDir+fname);
772 if (!file.open( IO_WriteOnly ) )
774 QMessageBox::critical( 0, tr( "Critical Save Error" ),
775 tr("Couldn't write to ") +fileDir+fname);
781 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),savemode);
783 file.setName ( fileDir + fname);
784 if ( !file.open( IO_WriteOnly ) )
786 // This should neverever happen
787 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
791 // Write it finally, and write in UTF8, no matter what
792 QTextStream ts( &file );
793 ts.setEncoding (QTextStream::UnicodeUTF8);
801 actionFileSave->setEnabled(false);
807 void MapEditor::setZipped (bool z)
812 bool MapEditor::saveZipped ()
817 void MapEditor::print()
819 // Finish open lineEdits
820 if (lineedit) finishedLineEditNoSave();
824 printer = new QPrinter;
825 printer->setColorMode (QPrinter::Color);
828 QRect totalBBox=mapCenter->getTotalBBox();
830 // Try to set orientation automagically
831 // Note: Interpretation of generated postscript is amibiguous, if
832 // there are problems with landscape mode, see
833 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
835 if (totalBBox.width()>totalBBox.height())
836 // recommend landscape
837 printer->setOrientation (QPrinter::Landscape);
839 // recommend portrait
840 printer->setOrientation (QPrinter::Portrait);
842 if ( printer->setup(this) )
843 // returns false, if printing is canceled
845 QPainter pp(printer);
847 // Don't print the visualisation of selection
848 LinkableMapObj *oldselection=NULL;
851 oldselection=selection;
852 selection->unselect();
855 // Handle sizes of map and paper:
857 // setWindow defines which part of the canvas will be transformed
858 // setViewport defines area on paper in device coordinates (dpi)
859 // e.g. (0,50,700,700) is upper part on A4
860 // see also /usr/lib/qt3/doc/html/coordsys.html
862 QPaintDeviceMetrics metrics (printer);
864 double paperAspect = (double)metrics.width() / (double)metrics.height();
865 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
867 QRect mapRect=mapCenter->getTotalBBox();
868 QCanvasRectangle *frame=NULL;
869 QCanvasText *footerFN=NULL;
870 QCanvasText *footerDate=NULL;
871 if (printFrame || printFooter)
876 // Print frame around map
877 mapRect.setRect (mapRect.x()-10, mapRect.y()-10,
878 mapRect.width()+20, mapRect.height()+20);
879 frame=new QCanvasRectangle (mapRect,mapCanvas);
880 frame->setBrush (QColor(white));
881 frame->setPen (QColor(black));
887 // Print footer below map
889 font.setPointSize(10);
890 footerFN=new QCanvasText (mapCanvas);
891 footerFN->setText ("VYM - " + fileName);
892 footerFN->setFont(font);
893 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
894 footerFN->setZ(Z_TEXT);
896 footerDate=new QCanvasText (mapCanvas);
897 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
898 footerDate->setFont(font);
899 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
900 footerDate->setZ(Z_TEXT);
902 mapRect.setRect (mapRect.x(), mapRect.y(),
903 mapRect.width(), mapRect.height()+20);
905 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height());
908 pp.setWindow (mapRect);
911 if (mapAspect>=paperAspect)
913 // Fit horizontally to paper width
914 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
917 // Fit vertically to paper height
918 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
921 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
923 // Delete Frame and footer
929 if (frame) delete (frame);
934 selection=oldselection;
940 QPixmap MapEditor::getPixmap()
942 QRect mapRect=mapCenter->getTotalBBox();
943 QPixmap pix (mapRect.size());
946 // Don't print the visualisation of selection
947 LinkableMapObj *oldselection=NULL;
950 oldselection=selection;
951 selection->unselect();
954 pp.setWindow (mapRect);
956 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
962 selection=oldselection;
969 void MapEditor::exportImage(QString fn)
971 // Finish open lineEdits
972 if (lineedit) finishedLineEditNoSave();
974 QPixmap pix (getPixmap());
978 void MapEditor::exportImage(QString fn, int item)
980 // Finish open lineEdits
981 if (lineedit) finishedLineEditNoSave();
983 QPixmap pix (getPixmap());
984 pix.save(fn, exportImageFormatMenu->text(item) );
987 void MapEditor::exportASCII()
989 // FIXME still experimental
990 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
991 fd->addFilter ("TXT (*.txt)");
992 fd->setCaption("VYM - Export (ASCII) (still experimental)");
993 fd->setMode( QFileDialog::AnyFile );
996 if ( fd->exec() == QDialog::Accepted )
998 if (QFile (fd->selectedFile()).exists() )
1000 QMessageBox mb( "VYM",
1001 tr("The file ") + fd->selectedFile() +
1002 tr(" exists already. Do you want to overwrite it?"),
1003 QMessageBox::Warning,
1004 QMessageBox::Yes | QMessageBox::Default,
1005 QMessageBox::Cancel | QMessageBox::Escape,
1006 QMessageBox::NoButton );
1008 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1009 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1013 case QMessageBox::Yes:
1015 if (!ex.setOutputDir ("out"))
1017 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1021 case QMessageBox::Cancel:
1028 ex.setPath (fd->selectedFile() );
1029 ex.setMapCenter(mapCenter);
1035 void MapEditor::exportXML(const QString &dir)
1037 // Create subdirectories
1040 // write to directory
1041 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,CompleteMap);
1044 file.setName ( dir + "/"+mapName+".xml");
1045 if ( !file.open( IO_WriteOnly ) )
1047 // This should neverever happen
1048 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1052 // Write it finally, and write in UTF8, no matter what
1053 QTextStream ts( &file );
1054 ts.setEncoding (QTextStream::UnicodeUTF8);
1058 // Now write image, too
1059 exportImage (dir+"/images/"+mapName+".png");
1062 void MapEditor::clear()
1066 selection->unselect();
1073 void MapEditor::undo()
1076 d.setPath(bakMapDir);
1079 // Finish open lineEdits
1080 if (lineedit) finishedLineEditNoSave();
1084 selection->unselect();
1088 mapBuilderHandler handler;
1089 QXmlInputSource source;
1090 source.setData(backupXML);
1091 QXmlSimpleReader reader;
1092 reader.setContentHandler( &handler );
1093 reader.setErrorHandler( &handler );
1094 handler.setMapEditor( this );
1095 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1098 selection=undoSelection;
1099 selection->select();
1100 handler.setLoadMode (ImportReplace);
1105 handler.setLoadMode (NewMap);
1107 blockreposition=true;
1108 bool ok = reader.parse( source );
1109 blockreposition=false;
1111 mapCenter->reposition();
1115 // This should never ever happen
1116 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1117 tr( handler.errorProtocol() )+" in "+backupXML );
1119 // Undo not longer available now
1120 actionEditUndo->setEnabled (false);
1121 undoSelection=false;
1126 QMessageBox::critical( 0, tr( "Critical Error" ),
1127 "Temporary directory " +bakMapDir +
1128 tr (" used for undo is gone. \n"
1129 "I will create a new one, but at the moment no undo is available.\n"
1130 "Maybe you want to reload your original data.\n\n"
1131 "Sorry for any inconveniences.") );
1136 void MapEditor::copy()
1138 // Finish open lineEdits
1139 if (lineedit) finishedLineEditNoSave();
1143 if (typeid(*selection) == typeid(BranchObj) )
1147 clipboardME->clear();
1148 clipboardME->getMapCenter()->addBranch();
1149 to=clipboardME->getMapCenter()->getLastBranch();
1152 from=(BranchObj*)(selection);
1155 // keep position relative to parent
1156 to->move2RelPos ( from->getRelPos());
1158 // select data in clipboard
1159 clipboardME->select ("bo:0");
1161 // repositioning makes testing nicer,
1162 // but is not needed usually:
1163 if (clipboardME->isVisible())
1165 clipboardME->getMapCenter()->reposition();
1168 clipboardME->hide();
1171 if (typeid(*selection) == typeid(FloatImageObj) )
1174 FloatImageObj* from;
1175 clipboardME->clear();
1176 clipboardME->getMapCenter()->addFloatImage();
1177 to=clipboardME->getMapCenter()->getLastFloatImage();
1180 from=(FloatImageObj*)(selection);
1183 // select data in clipboard
1184 clipboardME->select ("fi:0");
1186 // repositioning makes testing nicer,
1187 // but is not needed usually:
1188 if (clipboardME->isVisible())
1190 clipboardME->getMapCenter()->reposition();
1193 clipboardME->hide();
1199 LinkableMapObj* MapEditor::pasteNoSave()
1201 // Finish open lineEdits
1202 if (lineedit) finishedLineEditNoSave();
1204 LinkableMapObj *fromLMO=clipboardME->getSelection();
1205 LinkableMapObj *returnLMO=NULL;
1207 if (selection && fromLMO)
1210 if (typeid(*fromLMO) == typeid(BranchObj) )
1212 if (typeid(*selection) == typeid(MapCenterObj))
1214 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1215 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1217 if (typeid(*selection) == typeid(BranchObj))
1218 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1221 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1222 (typeid(*selection) == typeid (BranchObj) ||
1223 typeid(*selection)==typeid(MapCenterObj)) )
1224 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1230 void MapEditor::cutNoSave()
1232 // Finish open lineEdits
1233 if (lineedit) finishedLineEditNoSave();
1237 if (selection != NULL) {
1238 if (typeid(*selection) == typeid(BranchObj) )
1240 bo=(BranchObj*)(selection);
1241 par=(BranchObj*)(bo->getParObj());
1244 par->removeBranch(bo);
1246 selection->select();
1248 if (typeid(*selection) == typeid(FloatImageObj) )
1250 FloatImageObj* fio=(FloatImageObj*)(selection);
1251 par=(BranchObj*)(fio->getParObj());
1254 par->removeFloatImage(fio);
1256 selection->select();
1261 void MapEditor::paste()
1264 saveState(PartOfMap,selection);
1266 mapCenter->reposition();
1270 void MapEditor::cut()
1273 saveState(PartOfMap,selection->getParObj());
1276 mapCenter->reposition();
1280 void MapEditor::moveBranchUp()
1282 // Finish open lineEdits
1283 if (lineedit) finishedLineEditNoSave();
1287 if (typeid(*selection) == typeid(BranchObj) )
1290 saveState(PartOfMap,selection->getParObj());
1291 bo=(BranchObj*)(selection);
1292 par=(BranchObj*)(bo->getParObj());
1293 selection->unselect();
1294 selection=par->moveBranchUp (bo);
1295 selection->select();
1296 mapCenter->reposition();
1297 ensureSelectionVisible();
1301 void MapEditor::moveBranchDown()
1303 // Finish open lineEdits
1304 if (lineedit) finishedLineEditNoSave();
1308 if (typeid(*selection) == typeid(BranchObj) )
1311 saveState(PartOfMap,selection->getParObj());
1312 bo=(BranchObj*)(selection);
1313 par=(BranchObj*)(bo->getParObj());
1314 selection->unselect();
1315 selection=par->moveBranchDown(bo);
1316 selection->select();
1317 mapCenter->reposition();
1318 ensureSelectionVisible();
1322 void MapEditor::editHeading()
1324 // Finish open lineEdits
1325 if (lineedit) finishedLineEditNoSave();
1328 (typeid(*selection) == typeid(BranchObj) ||
1329 typeid(*selection) == typeid(MapCenterObj) ) )
1332 saveState(PartOfMap,selection);
1334 ensureSelectionVisible();
1335 editingBO=(BranchObj*)(selection);
1336 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1337 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1338 QString s=editingBO->getHeading();
1339 lineedit->setText(s);
1340 lineedit->setCursorPosition(1);
1341 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1342 lineedit->selectAll();
1345 lineedit->grabKeyboard();
1346 lineedit->setFocus();
1350 void MapEditor::addNewBranch(int pos)
1352 // Finish open lineEdits
1353 if (lineedit) finishedLineEditNoSave();
1356 (typeid(*selection) == typeid(BranchObj) ||
1357 typeid(*selection) == typeid(MapCenterObj) ) )
1360 saveState(PartOfMap,selection);
1362 BranchObj* bo1 = (BranchObj*) (selection);
1363 bool wasScrolled=false;
1364 BranchObj *newbo=NULL;
1367 // save scroll state. If scrolled, automatically select
1368 // new branch in order to tmp unscroll parent...
1369 wasScrolled=bo1->isScrolled();
1370 newbo=bo1->addBranch();
1373 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1377 // add above selection
1378 newbo=parbo->insertBranch(bo1->getNum());
1380 // add below selection
1381 newbo=parbo->insertBranch(bo1->getNum()+1);
1383 // This should not happen...
1388 LinkableMapObj *oldselection=selection;
1390 mapCenter->reposition();
1392 if (actionSettingsAutoedit->isOn() ||
1393 actionSettingsAutoselectHeading->isOn() )
1395 selection->unselect();
1397 selection->select();
1398 if (actionSettingsPasteNewHeading->isOn() )
1400 BranchObj *bo2= (BranchObj*)(selection);
1401 bo2->setHeading("");
1403 if (actionSettingsAutoedit->isOn() )
1405 if (!actionSettingsAutoselectHeading->isOn()
1408 selection->unselect();
1409 selection=oldselection;
1410 selection->select();
1417 void MapEditor::addNewBranchHere()
1419 // Finish open lineEdits
1420 if (lineedit) finishedLineEditNoSave();
1423 (typeid(*selection) == typeid(BranchObj) ) )
1426 saveState(PartOfMap,selection);
1428 BranchObj* bo1 = (BranchObj*) (selection);
1429 bool wasScrolled=false;
1430 BranchObj *newbo=NULL;
1431 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1434 // add below selection
1435 newbo=parbo->insertBranch(bo1->getNum()+1);
1438 LinkableMapObj *oldselection=selection;
1439 ((BranchObj*)(selection))->moveBranchTo (newbo,-1);
1441 mapCenter->reposition();
1443 if (actionSettingsAutoedit->isOn() ||
1444 actionSettingsAutoselectHeading->isOn() )
1446 selection->unselect();
1448 selection->select();
1449 if (actionSettingsPasteNewHeading->isOn() )
1451 BranchObj *bo2= (BranchObj*)(selection);
1452 bo2->setHeading("");
1454 if (actionSettingsAutoedit->isOn() )
1456 if (!actionSettingsAutoselectHeading->isOn()
1459 selection->unselect();
1460 selection=oldselection;
1461 selection->select();
1467 void MapEditor::deleteSelection()
1469 // Finish open lineEdits
1470 if (lineedit) finishedLineEditNoSave();
1472 if (selection && typeid(*selection) ==typeid(BranchObj) )
1475 saveState(PartOfMap,selection->getParObj());
1476 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1477 BranchObj* par=(BranchObj*)(bo->getParObj());
1480 par->removeBranch(bo);
1482 selection->select();
1483 ensureSelectionVisible();
1484 mapCenter->reposition();
1487 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1490 saveState(PartOfMap,selection->getParObj());
1491 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1492 BranchObj* par=(BranchObj*)(fio->getParObj());
1495 par->removeFloatImage(fio);
1497 selection->select();
1498 ensureSelectionVisible();
1499 mapCenter->reposition();
1504 LinkableMapObj* MapEditor::getSelection()
1509 bool MapEditor::select (const QString &s)
1511 LinkableMapObj *lmo=mapCenter->findObj(s);
1513 // Finally select the found object
1516 if (selection) unselect();
1518 selection->select();
1520 ensureSelectionVisible();
1526 void MapEditor::unselect()
1530 selectionLast=selection;
1531 selection->unselect();
1536 void MapEditor::reselect()
1540 selection=selectionLast;
1541 selection->select();
1546 void MapEditor::selectNextBranch()
1548 // Increase number of branch
1551 QString s=selection->getSelectString();
1557 part=s.section(",",-1);
1559 num=part.right(part.length() - 3);
1561 s=s.left (s.length() -num.length());
1564 num=QString ("%1").arg(num.toUInt()+1);
1568 // Try to select this one
1569 if (select (s)) return;
1571 // We have no direct successor,
1572 // try to increase the parental number in order to
1573 // find a successor with same depth
1575 int d=selection->getDepth();
1580 while (!found && d>0)
1582 s=s.section (",",0,d-1);
1583 // replace substring of current depth in s with "1"
1584 part=s.section(",",-1);
1586 num=part.right(part.length() - 3);
1590 // increase number of parent
1591 num=QString ("%1").arg(num.toUInt()+1);
1592 s=s.section (",",0,d-2) + ","+ typ+num;
1595 // Special case, look at orientation
1596 if (selection->getOrientation()==OrientRightOfCenter)
1597 num=QString ("%1").arg(num.toUInt()+1);
1599 num=QString ("%1").arg(num.toUInt()-1);
1604 // pad to oldDepth, select the first branch for each depth
1605 for (i=d;i<oldDepth;i++)
1610 if ( ((BranchObj*)(selection))->countBranches()>0)
1618 // try to select the freshly built string
1626 void MapEditor::selectPrevBranch()
1628 // Decrease number of branch
1631 QString s=selection->getSelectString();
1637 part=s.section(",",-1);
1639 num=part.right(part.length() - 3);
1641 s=s.left (s.length() -num.length());
1644 num=QString ("%1").arg(num.toUInt()-1);
1648 // Try to select this one
1649 if (select (s)) return;
1651 // We have no direct precessor,
1652 // try to decrease the parental number in order to
1653 // find a precessor with same depth
1655 int d=selection->getDepth();
1660 while (!found && d>0)
1662 s=s.section (",",0,d-1);
1663 // replace substring of current depth in s with "1"
1664 part=s.section(",",-1);
1666 num=part.right(part.length() - 3);
1670 // decrease number of parent
1671 num=QString ("%1").arg(num.toUInt()-1);
1672 s=s.section (",",0,d-2) + ","+ typ+num;
1675 // Special case, look at orientation
1676 if (selection->getOrientation()==OrientRightOfCenter)
1677 num=QString ("%1").arg(num.toUInt()-1);
1679 num=QString ("%1").arg(num.toUInt()+1);
1684 // pad to oldDepth, select the last branch for each depth
1685 for (i=d;i<oldDepth;i++)
1689 if ( ((BranchObj*)(selection))->countBranches()>0)
1690 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1697 // try to select the freshly built string
1705 void MapEditor::selectUpperBranch()
1707 // Finish open lineEdits
1708 if (lineedit) finishedLineEditNoSave();
1712 if (typeid(*selection) == typeid(BranchObj))
1714 if (selection->getOrientation()==OrientRightOfCenter)
1717 if (selection->getDepth()==1)
1725 void MapEditor::selectLowerBranch()
1727 // Finish open lineEdits
1728 if (lineedit) finishedLineEditNoSave();
1732 if (typeid(*selection) == typeid(BranchObj))
1734 if (selection->getOrientation()==OrientRightOfCenter)
1737 if (selection->getDepth()==1)
1746 void MapEditor::selectLeftBranch()
1748 // Finish open lineEdits
1749 if (lineedit) finishedLineEditNoSave();
1755 if (typeid(*selection) == typeid(MapCenterObj))
1757 par= (BranchObj*) (selection);
1758 bo=par->getLastSelectedBranch();
1761 // Workaround for reselecting on left and right side
1762 if (bo->getOrientation()==OrientRightOfCenter)
1764 bo=par->getLastBranch();
1770 selection->select();
1772 ensureSelectionVisible();
1777 par=(BranchObj*)(selection->getParObj());
1778 if (selection->getOrientation()==OrientRightOfCenter)
1780 if (typeid(*selection) == typeid(BranchObj) ||
1781 typeid(*selection) == typeid(FloatImageObj))
1783 selection->unselect();
1785 selection->select();
1787 ensureSelectionVisible();
1791 if (typeid(*selection) == typeid(BranchObj) )
1793 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1796 selection->unselect();
1798 selection->select();
1800 ensureSelectionVisible();
1808 void MapEditor::selectRightBranch()
1810 // Finish open lineEdits
1811 if (lineedit) finishedLineEditNoSave();
1818 if (typeid(*selection) == typeid(MapCenterObj))
1820 par= (BranchObj*) (selection);
1821 bo=par->getLastSelectedBranch();
1824 // Workaround for relecting on left and right side
1825 if (bo->getOrientation()==OrientLeftOfCenter)
1826 bo=par->getFirstBranch();
1831 selection->select();
1832 ensureSelectionVisible();
1837 par=(BranchObj*)(selection->getParObj());
1838 if (selection->getOrientation()==OrientLeftOfCenter)
1840 if (typeid(*selection) == typeid(BranchObj) ||
1841 typeid(*selection) == typeid(FloatImageObj))
1843 selection->unselect();
1845 selection->select();
1847 ensureSelectionVisible();
1851 if (typeid(*selection) == typeid(BranchObj) )
1853 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1856 selection->unselect();
1858 selection->select();
1860 ensureSelectionVisible();
1868 void MapEditor::selectFirstBranch()
1870 // Finish open lineEdits
1871 if (lineedit) finishedLineEditNoSave();
1877 if (typeid(*selection) == typeid(BranchObj))
1879 bo1= (BranchObj*) (selection);
1880 par=(BranchObj*)(bo1->getParObj());
1881 bo2=par->getFirstBranch();
1885 selection->select();
1886 ensureSelectionVisible();
1893 void MapEditor::selectLastBranch()
1895 // Finish open lineEdits
1896 if (lineedit) finishedLineEditNoSave();
1902 if (typeid(*selection) == typeid(BranchObj))
1904 bo1= (BranchObj*) (selection);
1905 par=(BranchObj*)(bo1->getParObj());
1906 bo2=par->getLastBranch();
1910 selection->select();
1911 ensureSelectionVisible();
1918 void MapEditor::setColor(QColor c)
1923 void MapEditor::selectBackgroundColor()
1925 // Finish open lineEdits
1926 if (lineedit) finishedLineEditNoSave();
1928 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
1929 if ( !col.isValid() ) return;
1930 setBackgroundColor( col );
1934 void MapEditor::setBackgroundColor(QColor c)
1936 mapCanvas->setBackgroundColor (c);
1939 QColor MapEditor::pickColor()
1943 if (typeid(*selection) == typeid(BranchObj) ||
1944 typeid(*selection) == typeid(MapCenterObj))
1946 BranchObj *bo=(BranchObj*)(selection);
1947 actColor=bo->getColor();
1953 void MapEditor::colorItem()
1957 if (typeid(*selection) == typeid(BranchObj) ||
1958 typeid(*selection) == typeid(MapCenterObj))
1961 saveState(PartOfMap,selection);
1962 BranchObj *bo=(BranchObj*)(selection);
1963 bo->setColor(actColor, false); // color links, color childs
1968 void MapEditor::colorBranch()
1972 if (typeid(*selection) == typeid(BranchObj) ||
1973 typeid(*selection) == typeid(MapCenterObj))
1976 saveState(PartOfMap,selection);
1977 BranchObj *bo=(BranchObj*)(selection);
1978 bo->setColor(actColor, true); // color links, color childs
1984 void MapEditor::toggleStandardFlag(QString f)
1989 saveState(PartOfMap,selection);
1990 ((BranchObj*)(selection))->toggleStandardFlag (f);
1994 void MapEditor::setViewCenter()
1996 // transform to CanvasView Coord:
1997 QPoint p=worldMatrix().map(movingCenter);
1998 center ( p.x(), p.y());
2002 BranchObj* MapEditor::findText (QString s, bool cs)
2005 { // Nothing found or new find process
2007 // nothing found, start again
2009 itFind=mapCenter->first();
2011 bool searching=true;
2012 bool foundNote=false;
2013 while (searching && !EOFind)
2017 // Searching in Note
2018 if (itFind->getNote().contains(s,cs))
2020 if (selection!=itFind)
2022 if (selection) ((BranchObj*)(selection))->unselect();
2024 selection->select();
2026 ensureSelectionVisible();
2028 if (textEditor->findText(s,cs))
2034 // Searching in Heading
2035 if (searching && itFind->getHeading().contains (s,cs) )
2037 if (selection) ((BranchObj*)(selection))->unselect();
2039 selection->select();
2041 ensureSelectionVisible();
2047 itFind=itFind->next();
2048 if (!itFind) EOFind=true;
2054 return (BranchObj*)(selection);
2059 void MapEditor::findReset()
2060 { // Necessary if text to find changes during a find process
2065 void MapEditor::openURL()
2069 if (typeid(*selection) == typeid(BranchObj) ||
2070 typeid(*selection) == typeid(MapCenterObj))
2072 QString url=((BranchObj*)(selection))->getURL();
2074 QProcess *proc = new QProcess( this );
2076 #if !defined(Q_OS_MACX)
2077 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2079 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2080 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2083 proc->addArgument( url);
2085 if ( !proc->start() )
2087 if (mainWindow->settingsURL() )
2093 void MapEditor::editURL()
2095 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2096 typeid(*selection) == typeid(MapCenterObj)) )
2099 QString text = QInputDialog::getText(
2100 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2101 ((BranchObj*)(selection))->getURL(), &ok, this );
2104 // user entered something and pressed OK
2105 ((BranchObj*)(selection))->setURL (text);
2112 void MapEditor::editHeading2URL()
2114 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2115 typeid(*selection) == typeid(MapCenterObj)) )
2117 BranchObj *b=(BranchObj*)(selection);
2118 b->setURL (b->getHeading());
2124 void MapEditor::editBugzilla2URL()
2126 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2127 typeid(*selection) == typeid(MapCenterObj)) )
2129 BranchObj *b=(BranchObj*)(selection);
2130 b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
2136 void MapEditor::editVymLink()
2138 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2139 typeid(*selection) == typeid(MapCenterObj)) )
2141 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2142 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2143 fd->setCaption(tr("VYM - Link to another map"));
2144 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2145 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2149 if ( fd->exec() == QDialog::Accepted )
2150 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2152 mapCenter->reposition();
2159 void MapEditor::deleteVymLink()
2161 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2162 typeid(*selection) == typeid(MapCenterObj)) )
2164 ((BranchObj*)(selection))->setVymLink ("" );
2166 mapCenter->reposition();
2173 QString MapEditor::getVymLink()
2175 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2176 typeid(*selection) == typeid(MapCenterObj)) )
2178 return ((BranchObj*)(selection))->getVymLink();
2184 void MapEditor::removeBranchHere()
2186 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2189 saveState(PartOfMap,selection->getParObj());
2190 QString sel=selection->getSelectString();
2191 BranchObj* bo=(BranchObj*)(selection);
2192 BranchObj* par=(BranchObj*)(bo->getParObj());
2194 par->removeBranchHere(bo);
2195 mapCenter->reposition();
2200 void MapEditor::removeChilds()
2202 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2205 saveState(PartOfMap,selection->getParObj());
2206 ((BranchObj*)(selection))->removeChilds();
2207 mapCenter->reposition();
2211 void MapEditor::editMapInfo()
2213 ExtraInfoDialog dia;
2214 dia.setMapName (getFileName() );
2215 dia.setAuthor (mapCenter->getAuthor() );
2216 dia.setComment(mapCenter->getComment() );
2221 QCanvasItemList l=canvas()->allItems();
2222 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2224 stats+=QString ("%1 items on canvas\n").arg (i,6);
2230 bo=mapCenter->first();
2233 if (!bo->getNote().isEmpty() ) n++;
2234 f+= bo->countFloatImages();
2238 stats+=QString ("%1 branches\n").arg (b-1,6);
2239 stats+=QString ("%1 notes\n").arg (n,6);
2240 stats+=QString ("%1 images\n").arg (f,6);
2241 dia.setStats (stats);
2243 // Finally show dialog
2244 if (dia.exec() == QDialog::Accepted)
2246 mapCenter->setAuthor (dia.getAuthor() );
2247 mapCenter->setComment (dia.getComment() );
2252 void MapEditor::updateActions()
2255 if (getLinkColorHint()==HeadingColor)
2256 actionFormatLinkColorHint->setOn(true);
2258 actionFormatLinkColorHint->setOn(false);
2263 actionFormatLinkStyleLine->setOn(true);
2266 actionFormatLinkStyleParabel->setOn(true);
2269 actionFormatLinkStylePolyLine->setOn(true);
2271 case StylePolyParabel:
2272 actionFormatLinkStylePolyParabel->setOn(true);
2278 QPixmap pix( 16, 16 );
2279 pix.fill( mapCanvas->backgroundColor() );
2280 actionFormatBackColor->setIconSet( pix );
2281 pix.fill( defLinkColor );
2282 actionFormatLinkColor->setIconSet( pix );
2284 actionEditUndo->setEnabled( mapChanged );
2285 actionFileSave->setEnabled( mapUnsaved );
2289 if ( (typeid(*selection) == typeid(BranchObj)) ||
2290 (typeid(*selection) == typeid(MapCenterObj)) )
2292 BranchObj *bo=(BranchObj*)(selection);
2293 // Take care of links
2294 if (bo->countXLinks()==0)
2296 branchLinksContextMenu->clear();
2297 branchLinksContextMenu->insertItem ("No link available");
2298 branchLinksContextMenuDup->clear();
2299 branchLinksContextMenuDup->insertItem ("No link available");
2305 branchLinksContextMenu->clear();
2306 branchLinksContextMenuDup->clear();
2307 for (int i=0; i<=bo->countXLinks();i++)
2309 bot=bo->XLinkTargetAt(i);
2312 s=bot->getHeading();
2315 branchLinksContextMenu->insertItem (s);
2316 branchLinksContextMenuDup->insertItem (s);
2321 standardFlagsDefault->setEnabled (true);
2323 if ( bo->getURL().isEmpty() )
2324 actionEditOpenURL->setEnabled (false);
2326 actionEditOpenURL->setEnabled (true);
2328 if ( bo->getVymLink().isEmpty() )
2330 actionEditOpenVymLink->setEnabled (false);
2331 actionEditDeleteVymLink->setEnabled (false);
2334 actionEditOpenVymLink->setEnabled (true);
2335 actionEditDeleteVymLink->setEnabled (true);
2338 actionEditCopy->setEnabled (true);
2339 actionEditCut->setEnabled (true);
2340 actionEditPaste->setEnabled (true);
2341 for (a=actionListBranches.first();a;a=actionListBranches.next())
2342 a->setEnabled(true);
2343 actionEditDelete->setEnabled (true);
2344 actionEditToggleFloatExport->setEnabled (false);
2345 switch (selection->getFrameType())
2348 actionFormatFrameNone->setOn(true);
2351 actionFormatFrameRectangle->setOn(true);
2357 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2359 standardFlagsDefault->setEnabled (false);
2361 actionEditOpenURL->setEnabled (false);
2362 actionEditOpenVymLink->setEnabled (false);
2363 actionEditDeleteVymLink->setEnabled (false);
2365 actionEditCopy->setEnabled (true);
2366 actionEditCut->setEnabled (true);
2367 actionEditPaste->setEnabled (false); //FIXME
2368 for (a=actionListBranches.first();a;a=actionListBranches.next())
2369 a->setEnabled(false);
2370 actionEditDelete->setEnabled (true);
2371 actionEditToggleFloatExport->setOn
2372 ( ((FloatImageObj*)(selection))->getFloatExport() );
2377 standardFlagsDefault->setEnabled (false);
2379 actionEditCopy->setEnabled (false);
2380 actionEditCut->setEnabled (false);
2381 actionEditPaste->setEnabled (false);
2382 for (a=actionListBranches.first();a;a=actionListBranches.next())
2383 a->setEnabled(false);
2385 actionEditOpenURL->setEnabled (false);
2386 actionEditOpenVymLink->setEnabled (false);
2387 actionEditDeleteVymLink->setEnabled (false);
2388 actionEditHeading2URL->setEnabled (false);
2389 actionEditDelete->setEnabled (false);
2390 actionEditToggleFloatExport->setEnabled (false);
2394 void MapEditor::setLinkStyle (LinkStyle ls)
2399 bo=mapCenter->first();
2403 bo->setLinkStyle(bo->getDefLinkStyle());
2410 LinkStyle MapEditor::getLinkStyle ()
2415 void MapEditor::setLinkColor(QColor c)
2421 void MapEditor::setLinkColorHint()
2423 // called from setLinkColorHint(lch) or at end of parse
2425 bo=mapCenter->first();
2433 void MapEditor::setLinkColorHint(LinkColorHint lch)
2439 void MapEditor::toggleLinkColorHint()
2441 if (linkcolorhint==HeadingColor)
2442 linkcolorhint=DefaultColor;
2444 linkcolorhint=HeadingColor;
2446 bo=mapCenter->first();
2454 LinkColorHint MapEditor::getLinkColorHint()
2456 return linkcolorhint;
2459 QColor MapEditor::getDefLinkColor()
2461 return defLinkColor;
2464 void MapEditor::setDefXLinkColor(QColor col)
2469 QColor MapEditor::getDefXLinkColor()
2471 return defXLinkColor;
2474 void MapEditor::setDefXLinkWidth (int w)
2479 int MapEditor::getDefXLinkWidth()
2481 return defXLinkWidth;
2484 void MapEditor::selectLinkColor()
2486 // Finish open lineEdits
2487 if (lineedit) finishedLineEditNoSave();
2489 QColor col = QColorDialog::getColor( defLinkColor, this );
2490 if ( !col.isValid() ) return;
2491 setLinkColor( col );
2495 void MapEditor::toggleScroll()
2497 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2499 BranchObj *bo=((BranchObj*)(selection));
2500 if (bo->countBranches()==0) return;
2501 if (bo->getDepth()==0) return;
2503 saveState(PartOfMap,selection);
2510 void MapEditor::unScrollAll()
2513 bo=mapCenter->first();
2516 if (bo->isScrolled()) bo->toggleScroll();
2521 void MapEditor::loadFloatImage ()
2524 (typeid(*selection) == typeid(BranchObj)) ||
2525 (typeid(*selection) == typeid(MapCenterObj)) )
2527 BranchObj *bo=((BranchObj*)(selection));
2529 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2530 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2531 ImagePreview *p =new ImagePreview (fd);
2532 fd->setContentsPreviewEnabled( TRUE );
2533 fd->setContentsPreview( p, p );
2534 fd->setPreviewMode( QFileDialog::Contents );
2535 fd->setCaption(tr("vym - Load image"));
2536 fd->setDir (lastImageDir);
2540 if ( fd->exec() == QDialog::Accepted )
2543 saveState(PartOfMap,selection);
2544 QString fn=fd->selectedFile();
2545 lastImageDir=fn.left(fn.findRev ("/"));
2546 bo->addFloatImage();
2547 // FIXME check if load was successful
2548 bo->getLastFloatImage()->load(fn);
2549 bo->getLastFloatImage()->setOriginalFilename(fn);
2550 mapCenter->reposition();
2557 void MapEditor::saveFloatImage (int item)
2560 (typeid(*selection) == typeid(FloatImageObj)) )
2562 FloatImageObj *fio=((FloatImageObj*)(selection));
2563 const char* fmt = saveImageFormatMenu->text(item);
2565 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2566 fd->addFilter ("PNG (*.png)");
2567 fd->addFilter ("BMP (*.bmp)");
2568 fd->addFilter ("XBM (*.xbm)");
2569 fd->addFilter ("JPG (*.jpg)");
2570 fd->addFilter ("XPM (*.xpm)");
2571 fd->addFilter ("GIF (*.gif)");
2572 fd->addFilter ("PNM (*.pnm)");
2573 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2574 fd->setCaption(tr("vym - Save image as ") + fmt);
2575 fd->setMode( QFileDialog::AnyFile );
2576 fd->setSelection (fio->getOriginalFilename());
2580 if ( fd->exec() == QDialog::Accepted )
2582 if (QFile (fd->selectedFile()).exists() )
2584 QMessageBox mb( "VYM",
2585 tr("The file ") + fd->selectedFile() +
2586 tr(" exists already. "
2587 "Do you want to overwrite it?"),
2588 QMessageBox::Warning,
2589 QMessageBox::Yes | QMessageBox::Default,
2590 QMessageBox::Cancel | QMessageBox::Escape,
2591 QMessageBox::QMessageBox::NoButton );
2593 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2594 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2597 case QMessageBox::Yes:
2600 case QMessageBox::Cancel:
2606 fio->save (fd->selectedFile(),fmt);
2611 void MapEditor::toggleFloatExport()
2614 (typeid(*selection) == typeid(FloatImageObj))||
2615 (typeid(*selection) == typeid(FloatObj)) )
2617 FloatImageObj *fio=((FloatImageObj*)(selection));
2618 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2622 void MapEditor::setFrame(const FrameType &t)
2625 (typeid(*selection) == typeid(BranchObj)) ||
2626 (typeid(*selection) == typeid(MapCenterObj)) )
2628 selection->setFrameType (t);
2629 mapCenter->reposition();
2630 selection->updateLink();
2634 void MapEditor::importDir(BranchObj *dst, QDir d)
2637 (typeid(*selection) == typeid(BranchObj)) ||
2638 (typeid(*selection) == typeid(MapCenterObj)) )
2642 // Traverse directories
2643 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2644 const QFileInfoList *dirlist = d.entryInfoList();
2645 QFileInfoListIterator itdir( *dirlist );
2648 while ( (fi = itdir.current()) != 0 )
2650 if (fi->fileName() != "." && fi->fileName() != ".." )
2653 bo=dst->getLastBranch();
2654 bo->setHeading (fi->fileName() );
2655 bo->setColor (QColor("blue"),false);
2657 if ( !d.cd(fi->fileName()) )
2658 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2668 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2669 const QFileInfoList *filelist = d.entryInfoList();
2670 QFileInfoListIterator itfile( *filelist );
2672 while ( (fi = itfile.current()) != 0 )
2675 bo=dst->getLastBranch();
2676 bo->setHeading (fi->fileName() );
2677 bo->setColor (QColor("black"),false);
2683 void MapEditor::importDir()
2686 (typeid(*selection) == typeid(BranchObj)) ||
2687 (typeid(*selection) == typeid(MapCenterObj)) )
2689 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2690 fd->setMode (QFileDialog::DirectoryOnly);
2691 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2692 fd->setCaption(tr("VYM - Choose directory structur to import"));
2696 if ( fd->exec() == QDialog::Accepted )
2698 BranchObj *bo=((BranchObj*)(selection));
2699 importDir (bo,QDir(fd->selectedFile()) );
2700 mapCenter->reposition();
2707 void MapEditor::followXLink(int i)
2710 (typeid(*selection) == typeid(BranchObj)) ||
2711 (typeid(*selection) == typeid(MapCenterObj)) )
2713 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2716 selection->unselect();
2718 selection->select();
2719 ensureSelectionVisible();
2724 void MapEditor::editXLink(int i)
2727 (typeid(*selection) == typeid(BranchObj)) ||
2728 (typeid(*selection) == typeid(MapCenterObj)) )
2730 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2733 EditXLinkDialog dia;
2735 if (dia.exec() == QDialog::Accepted)
2737 if (dia.useSettingsGlobal() )
2739 setDefXLinkColor (xlo->getColor() );
2740 setDefXLinkWidth (xlo->getWidth() );
2742 if (dia.deleteXLink())
2743 ((BranchObj*)(selection))->deleteXLinkAt(i);
2750 void MapEditor::testFunction()
2752 cout << "MapEditor::testFunction() called\n";
2755 void MapEditor::ensureSelectionVisible()
2759 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2761 if (selection->getOrientation() == OrientLeftOfCenter)
2762 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2764 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2765 ensureVisible (p.x(), p.y() );
2770 void MapEditor::updateViewCenter()
2772 // Update movingCenter, so that we can zoom comfortably later
2773 QRect rc = QRect( contentsX(), contentsY(),
2774 visibleWidth(), visibleHeight() );
2775 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2776 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2777 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2780 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2782 // Lineedits are already closed by preceding
2783 // mouseEvent, we don't need to close here.
2785 QPoint p = inverseWorldMatrix().map(e->pos());
2786 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2789 { // MapObj was found
2790 if (selection != lmo)
2792 // select the MapObj
2793 if (selection) selection->unselect();
2795 selection->select();
2801 if (typeid(*selection)==typeid(BranchObj) ||
2802 typeid(*selection)==typeid(MapCenterObj) )
2804 // Context Menu on branch or mapcenter
2806 branchContextMenu->popup(e->globalPos() );
2808 if (typeid(*selection)==typeid(FloatImageObj))
2810 // Context Menu on floatimage
2812 floatimageContextMenu->popup(e->globalPos() );
2816 { // No MapObj found, we are on the Canvas itself
2817 // Context Menu on Canvas
2819 canvasContextMenu->popup(e->globalPos() );
2823 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2825 // Finish open lineEdits
2826 if (lineedit) finishedLineEditNoSave();
2828 QPoint p = inverseWorldMatrix().map(e->pos());
2829 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2831 // Special case: CTRL is pressed
2832 if (e->state() & QMouseEvent::ControlButton)
2834 if (actionModModeColor->isOn())
2836 if (e->state() & QMouseEvent::ControlButton)
2839 setCursor (pickColorCursor);
2843 if (actionModModeLink->isOn())
2845 BranchObj *bo_begin=NULL;
2847 bo_begin=(BranchObj*)(lmo);
2850 ((typeid(*selection) == typeid(BranchObj)) ||
2851 (typeid(*selection) == typeid(MapCenterObj))) )
2852 bo_begin=(BranchObj*)(selection);
2856 linkingObj_src=bo_begin;
2857 tmpXLink=new XLinkObj (mapCanvas);
2858 tmpXLink->setBegin (bo_begin);
2859 tmpXLink->setEnd (p);
2860 tmpXLink->setColor(defXLinkColor);
2861 tmpXLink->setWidth(defXLinkWidth);
2862 tmpXLink->updateXLink();
2863 tmpXLink->setVisibility (true);
2870 { // MapObj was found
2871 if (selection != lmo)
2873 // select the MapObj
2874 if (selection) selection->unselect();
2876 selection->select();
2882 // Check, if systemFlag clicked
2883 if (typeid(*selection)==typeid(BranchObj) ||
2884 typeid(*selection)==typeid(MapCenterObj) )
2886 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
2887 if (!foname.isEmpty())
2889 // Do not move, if systemFlag clicked
2893 if (foname=="vymLink")
2895 mainWindow->editOpenVymLink();
2896 // tabWidget may change, better return now
2897 // before segfaulting...
2901 mainWindow->windowToggleNoteEditor();
2905 // Left Button Move Branches
2906 if (e->button() == QMouseEvent::LeftButton )
2908 // If modMode==copy, then we want to "move" the _new_ object around
2909 // then we need the offset from p to the _old_ selection, because of tmp
2910 if (actionModModeCopy->isOn() &&
2911 e->state() & QMouseEvent::ControlButton)
2913 if (typeid(*selection)==typeid(BranchObj) )
2916 movingObj_start.setX( p.x() - selection->x() );
2917 movingObj_start.setY( p.y() - selection->y() );
2918 mapCenter->addBranch ((BranchObj*)(selection));
2920 selection=mapCenter->getLastBranch();
2921 selection->select();
2922 selection->setParObjTmp ((BranchObj*)(selection),p,1);
2923 selection->updateLink();
2927 movingObj_start.setX( p.x() - selection->x() );
2928 movingObj_start.setY( p.y() - selection->y() );
2931 movingObj=selection;
2933 // Middle Button Toggle Scroll
2934 // (On Mac OS X this won't work, but we still have
2935 // a button in the toolbar)
2936 if (e->button() == QMouseEvent::MidButton )
2940 { // No MapObj found, we are on the Canvas itself
2941 // Left Button move Pos of CanvasView
2942 if (e->button() == QMouseEvent::LeftButton )
2944 movingObj=NULL; // move Content not Obj
2945 movingObj_start=e->globalPos();
2946 movingCont_start=QPoint (contentsX(), contentsY() );
2947 movingVec=QPoint(0,0);
2948 setCursor(handOpenCursor);
2953 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
2955 QPoint p = inverseWorldMatrix().map(e->pos());
2957 // Move the selected MapObj
2958 if ( selection && movingObj)
2960 ensureVisible (p.x(),p.y());
2962 // Now move the selection, but add relative position
2963 // (movingObj_start) where selection was chosen with
2964 // mousepointer. (This avoids flickering resp. jumping
2965 // of selection back to absPos)
2967 LinkableMapObj *lmosel;
2968 lmosel = dynamic_cast <LinkableMapObj*> (selection);
2970 // Check if we could link
2971 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
2974 if (typeid(*selection) == typeid(FloatImageObj))
2978 FloatObj *fo=(FloatObj*)(selection);
2979 if (fo->getLinkStyle()==StyleUndef)
2981 fo->setLinkStyle(fo->getDefLinkStyle());
2982 fo->setLinkColor(fo->getParObj()->getLinkColor());
2984 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2988 // Relink float to new mapcenter or branch, if shift is pressed
2989 // Only relink, if selection really has a new parent
2990 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
2991 ( (typeid(*lmo)==typeid(BranchObj)) ||
2992 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
2993 ( lmo != fo->getParObj())
2996 if (typeid(*fo) == typeid(FloatImageObj))
2998 FloatImageObj *fio=(FloatImageObj*)(fo);
2999 ((BranchObj*)(lmo))->addFloatImage (fio);
3001 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3002 fio=((BranchObj*)(lmo))->getLastFloatImage();
3005 selection=(LinkableMapObj*)(fio);
3006 selection->select();
3007 movingObj=(MapObj*)(fio);
3008 // setLinkStyle calls updateLink, only set it once
3009 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3010 fio->setLinkStyle (fio->getDefLinkStyle());
3013 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3015 } else // selection != a FloatObj
3017 if (lmosel->getDepth()==0)
3019 if (e->state() == (LeftButton | !ShiftButton))
3020 // If mapCenter is moved, move all the rest by default, too.
3021 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3023 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3026 if (lmosel->getDepth()==1)
3028 // depth==1, mainbranch
3030 saveState(PartOfMap,lmosel);
3031 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3035 if (lmosel->getOrientation() == OrientLeftOfCenter)
3036 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3037 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3038 p.y()-movingObj_start.y() );
3040 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3042 // reposition subbranch
3043 lmosel->reposition();
3044 //ensureSelectionVisible();
3046 if (lmo && (lmo!=selection) &&
3047 (typeid(*lmo) == typeid(BranchObj) ||
3048 (typeid(*lmo) == typeid(MapCenterObj) )
3051 if (e->state() & QMouseEvent::ControlButton)
3053 // Special case: CTRL to link below lmo
3054 lmosel->setParObjTmp (lmo,p,+1);
3056 else if (e->state() & QMouseEvent::ShiftButton)
3057 lmosel->setParObjTmp (lmo,p,-1);
3059 lmosel->setParObjTmp (lmo,p,0);
3062 lmosel->unsetParObjTmp();
3064 if (lmo &&(lmo==selection))
3065 // Could link to myself (happens sometimes...)
3066 lmosel->unsetParObjTmp();
3068 // no Obj under selection, go back to original Parent
3069 lmosel->unsetParObjTmp();
3074 } // no FloatImageObj
3078 } // selection && moving_obj
3080 // Draw a link from one branch to another
3083 tmpXLink->setEnd (p);
3084 tmpXLink->updateXLink();
3088 if (!movingObj && !pickingColor &&!drawingLink)
3090 QPoint p=e->globalPos();
3091 movingVec.setX(-p.x() + movingObj_start.x() );
3092 movingVec.setY(-p.y() + movingObj_start.y() );
3093 setContentsPos( movingCont_start.x() + movingVec.x(),
3094 movingCont_start.y() + movingVec.y());
3101 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3103 LinkableMapObj *dst;
3104 // Have we been picking color?
3108 setCursor (ArrowCursor);
3109 // Check if we are over another branch
3110 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3111 if (dst && selection)
3113 if (e->state() & QMouseEvent::ShiftButton)
3115 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3116 ((BranchObj*)(selection))->setLinkColor ();
3120 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3121 ((BranchObj*)(selection))->setLinkColor ();
3127 // Have we been drawing a link?
3131 // Check if we are over another branch
3132 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3133 if (dst && selection)
3135 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3136 tmpXLink->updateXLink();
3137 tmpXLink->activate();
3148 // Have we been moving something?
3149 if ( selection && movingObj )
3151 // Check if we are over another branch, but ignore
3152 // any found LMOs, which are FloatObjs
3153 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3154 ((LinkableMapObj*)(selection)) );
3157 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3162 // Now check, if we have been moving a branch
3163 if (typeid(*selection) == typeid(BranchObj) )
3165 // save the position in case we link to mapcenter
3166 QPoint savePos=QPoint (selection->x(),selection->y() );
3168 // Reset the temporary drawn link to the original one
3169 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3177 // remove the current selection, if we have no destination
3178 selection->unselect();
3179 ((BranchObj*)(selection->getParObj()))->removeBranch ((BranchObj*)(selection));
3182 selection=selectionLast;
3184 selection->select();
3191 // TODO we also could check, if dest and src are on same branch,
3192 // then it would be sufficient to saveState of this branch
3194 // Modifiers allow to insert above/below dst
3195 if (e->state() & QMouseEvent::ShiftButton)
3197 ((BranchObj*)(selection))->moveBranchTo
3200 ((BranchObj*)(dst))->getNum()
3202 //if (selection) selection->select();
3204 if (e->state() & QMouseEvent::ControlButton)
3206 ((BranchObj*)(selection))->moveBranchTo
3209 ((BranchObj*)(dst))->getNum()+1
3211 //if (selection) selection->select();
3214 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
3215 if (dst->getDepth()==0)
3216 ((BranchObj*)(selection))->move (savePos);
3219 // Draw the original link, before selection was moved around
3220 mapCenter->reposition();
3222 // Finally resize canvas, if needed
3227 // maybe we moved View: set old cursor
3228 setCursor (ArrowCursor);
3232 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3234 // Finish open lineEdits
3235 if (lineedit) finishedLineEditNoSave();
3237 if (e->button() == QMouseEvent::LeftButton )
3239 QPoint p = inverseWorldMatrix().map(e->pos());
3240 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3241 if (lmo) { // MapObj was found
3242 // First select the MapObj than edit heading
3243 if (selection) selection->unselect();
3245 selection->select();
3247 saveState(PartOfMap,selection);
3253 void MapEditor::resizeEvent (QResizeEvent* e)
3255 QCanvasView::resizeEvent( e );
3258 if (!fileName.isEmpty()) s=fileName;