Initial import.
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"
34 #include "icons/flag-note.xpm"
35 #include "icons/flag-url.xpm"
36 #include "icons/flag-vymlink.xpm"
37 #include "icons/flag-scrolled-right.xpm"
38 #include "icons/flag-tmpUnscrolled-right.xpm"
39 #include "icons/flag-questionmark.xpm"
40 #include "icons/flag-exclamationmark.xpm"
41 #include "icons/flag-hook-green.xpm"
42 #include "icons/flag-cross-red.xpm"
43 #include "icons/flag-stopsign.xpm"
44 #include "icons/flag-smiley-good.xpm"
45 #include "icons/flag-smiley-sad.xpm"
46 #include "icons/flag-clock.xpm"
47 #include "icons/flag-lamp.xpm"
48 #include "icons/flag-arrow-up.xpm"
49 #include "icons/flag-arrow-down.xpm"
50 #include "icons/flag-thumb-up.xpm"
51 #include "icons/flag-thumb-down.xpm"
52 #include "icons/flag-heart.xpm"
53 #include "icons/flag-flash.xpm"
54 #include "icons/flag-lifebelt.xpm"
56 extern TextEditor *textEditor;
57 extern int statusbarTime;
58 extern Main *mainWindow;
59 extern FlagRowObj *systemFlagsDefault;
60 extern FlagRowObj *standardFlagsDefault;
61 extern MapEditor *clipboardME;
63 extern QAction *actionFileSave;
64 extern QAction *actionEditUndo;
65 extern QAction *actionEditCopy;
66 extern QAction *actionEditCut;
67 extern QAction *actionEditPaste;
68 extern QAction *actionEditMoveUp;
69 extern QAction *actionEditMoveDown;
70 extern QAction *actionEditToggleScroll;
71 extern QAction *actionEditOpenURL;
72 extern QAction *actionEditURL;
73 extern QAction *actionEditHeading2URL;
74 extern QAction *actionEditBugzilla2URL;
75 extern QAction *actionEditOpenVymLink;
76 extern QAction *actionEditVymLink;
77 extern QAction *actionEditDeleteVymLink;
78 extern QAction *actionEditHeading;
79 extern QAction *actionEditDelete;
80 extern QAction *actionEditAddBranch;
81 extern QAction *actionEditAddBranchAbove;
82 extern QAction *actionEditAddBranchBelow;
83 extern QAction *actionEditImportAdd;
84 extern QAction *actionEditImportReplace;
85 extern QAction *actionEditSaveBranch;
86 extern QAction *actionEditSelectFirst;
87 extern QAction *actionEditSelectLast;
88 extern QAction *actionEditLoadImage;
89 extern QAction *actionEditToggleFloatExport;
91 extern QAction* actionFormatPickColor;
92 extern QAction* actionFormatColorBranch;
93 extern QAction* actionFormatColorSubtree;
94 extern QAction *actionFormatLinkColorHint;
95 extern QAction *actionFormatBackColor;
96 extern QAction *actionFormatLinkColor;
98 extern QActionGroup *actionGroupFormatFrameTypes;
99 extern QAction *actionFormatFrameNone;
100 extern QAction *actionFormatFrameRectangle;
102 extern QActionGroup *actionGroupFormatLinkStyles;
103 extern QAction *actionFormatLinkStyleLine;
104 extern QAction *actionFormatLinkStyleParabel;
105 extern QAction *actionFormatLinkStylePolyLine;
106 extern QAction *actionFormatLinkStylePolyParabel;
108 extern QAction *actionViewToggleNoteEditor;
110 extern QAction *actionSettingsAutoedit;
111 extern QAction *actionSettingsAutoselectHeading;
112 extern QAction *actionSettingsAutoselectText;
113 extern QAction *actionSettingsPasteNewHeading;
115 extern QPopupMenu *branchContextMenu;
116 extern QPopupMenu *floatimageContextMenu;
117 extern QPopupMenu *saveImageFormatMenu;
118 extern QPopupMenu *exportImageFormatMenu;
119 extern QPopupMenu *canvasContextMenu;
121 extern Settings settings;
124 ///////////////////////////////////////////////////////////////////////
125 ///////////////////////////////////////////////////////////////////////
126 MapEditor::MapEditor(
127 QWidget* parent, bool interactive, const char* name, WFlags f) :
128 QCanvasView(parent,name,f)
130 //cout << "Constructor ME "<<this<<endl;
132 mapCanvas = new QCanvas(1000,800);
133 mapCanvas->setAdvancePeriod(30);
135 setCanvas (mapCanvas);
137 setVScrollBarMode ( QScrollView::AlwaysOn );
138 setHScrollBarMode ( QScrollView::AlwaysOn );
140 // Now create the _global_ system flags _once_:
141 // (Later all OrnamentedObj copy from this
142 // and set their own canvas)
143 if (!systemFlagsDefault)
145 systemFlagsDefault = new FlagRowObj (mapCanvas);
146 systemFlagsDefault->setVisibility (false);
147 systemFlagsDefault->setName ("systemFlagsDef");
149 FlagObj *fo = new FlagObj (mapCanvas);
150 fo->load(QPixmap(flag_note_xpm));
152 fo->setToolTip(tr("Note"));
153 systemFlagsDefault->addFlag (fo); // makes deep copy
155 fo->load(QPixmap(flag_url_xpm));
157 fo->setToolTip(tr("WWW Document (external)"));
158 systemFlagsDefault->addFlag (fo);
160 fo->load(QPixmap(flag_vymlink_xpm));
161 fo->setName("vymLink");
162 fo->setToolTip(tr("Link to another vym map"));
163 systemFlagsDefault->addFlag (fo);
165 fo->load(QPixmap(flag_scrolled_right_xpm));
166 fo->setName("scrolledright");
167 fo->setToolTip(tr("subtree is scrolled"));
168 systemFlagsDefault->addFlag (fo);
170 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
171 fo->setName("tmpUnscrolledright");
172 fo->setToolTip(tr("subtree is temporary scrolled"));
173 systemFlagsDefault->addFlag (fo);
176 if (!standardFlagsDefault)
178 standardFlagsDefault = new FlagRowObj (mapCanvas);
179 standardFlagsDefault->setVisibility (false);
180 standardFlagsDefault->setName ("standardFlagsDef");
182 FlagObj *fo = new FlagObj (mapCanvas);
183 fo->load(QPixmap(flag_exclamationmark_xpm));
184 fo->setName("exclamationmark");
185 fo->setToolTip(tr("Take care!"));
186 standardFlagsDefault->addFlag (fo); // makes deep copy
188 fo->load(QPixmap(flag_questionmark_xpm));
189 fo->setName("questionmark");
190 fo->setToolTip(tr("Really?"));
191 standardFlagsDefault->addFlag (fo);
193 fo->load(QPixmap(flag_hook_green_xpm));
194 fo->setName("hook-green");
195 fo->setToolTip(tr("ok!"));
196 standardFlagsDefault->addFlag (fo);
198 fo->load(QPixmap(flag_cross_red_xpm));
199 fo->setName("cross-red");
200 fo->setToolTip(tr("Not ok!"));
201 standardFlagsDefault->addFlag (fo);
203 fo->load(QPixmap(flag_stopsign_xpm));
204 fo->setName("stopsign");
205 fo->setToolTip(tr("This won't work!"));
206 standardFlagsDefault->addFlag (fo);
208 fo->load(QPixmap(flag_smiley_good_xpm));
209 fo->setName("smiley-good");
210 fo->setToolTip(tr("Good"));
211 standardFlagsDefault->addFlag (fo);
213 fo->load(QPixmap(flag_smiley_sad_xpm));
214 fo->setName("smiley-sad");
215 fo->setToolTip(tr("Bad"));
216 standardFlagsDefault->addFlag (fo);
218 fo->load(QPixmap(flag_clock_xpm));
219 fo->setName("clock");
220 fo->setToolTip(tr("Time critical"));
221 standardFlagsDefault->addFlag (fo);
223 fo->load(QPixmap(flag_lamp_xpm));
225 fo->setToolTip(tr("Idea!"));
226 standardFlagsDefault->addFlag (fo);
228 fo->load(QPixmap(flag_arrow_up_xpm));
229 fo->setName("arrow-up");
230 fo->setToolTip(tr("Important"));
231 standardFlagsDefault->addFlag (fo);
233 fo->load(QPixmap(flag_arrow_down_xpm));
234 fo->setName("arrow-down");
235 fo->setToolTip(tr("Unimportant"));
236 standardFlagsDefault->addFlag (fo);
238 fo->load(QPixmap(flag_thumb_up_xpm));
239 fo->setName("thumb-up");
240 fo->setToolTip(tr("I like this"));
241 standardFlagsDefault->addFlag (fo);
243 fo->load(QPixmap(flag_thumb_down_xpm));
244 fo->setName("thumb-down");
245 fo->setToolTip(tr("I do not like this"));
246 standardFlagsDefault->addFlag (fo);
248 fo->load(QPixmap(flag_heart_xpm));
249 fo->setName("heart");
250 fo->setToolTip(tr("I just love... "));
251 standardFlagsDefault->addFlag (fo);
253 fo->load(QPixmap(flag_flash_xpm));
254 fo->setName("flash");
255 fo->setToolTip(tr("Dangerous"));
256 standardFlagsDefault->addFlag (fo);
258 fo->load(QPixmap(flag_lifebelt_xpm));
259 fo->setName("lifebelt");
260 fo->setToolTip(tr("This will help"));
261 standardFlagsDefault->addFlag (fo);
266 mapCenter = new MapCenterObj(mapCanvas);
267 mapCenter->setVisibility (true);
268 mapCenter->setMapEditor (this);
269 mapCenter->setHeading (tr("New Map"));
273 lineedit = new QLineEdit(this, "lineedit" );
274 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
277 actColor=black; setColor (actColor);
278 deflinkcolor=QColor (0,0,255);
279 linkcolorhint=DefaultColor;
280 linkstyle=StylePolyParabel;
281 mapCanvas->setBackgroundColor (white);
283 // Create bitmap cursors, patform dependant
284 #if defined(Q_OS_MACX)
285 #include "icons/cursorhandopen16.xpm"
286 #include "icons/cursorcolorpicker16.xpm"
287 QBitmap cb( 16, 16, chandopen, TRUE );
288 QBitmap cm( 16, 16, chandopenmask, TRUE );
289 handOpenCursor=QCursor ( cb, cm );
290 // set hot spot to tip of picker
291 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
293 #include "icons/cursorhandopen.xpm"
294 #include "icons/cursorcolorpicker.xpm"
296 QBitmap cb( 32, 32, chandopen, TRUE );
297 QBitmap cm( 32, 32, chandopenmask, TRUE );
298 handOpenCursor=QCursor ( cb, cm );
299 // set hot spot to tip of picker
300 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
321 // Initialize find routine
328 blockreposition=false;
329 isInteractive=interactive;
331 // Create temporary files
334 // Initially set movingCentre
337 mapCenter->reposition(); // for positioning heading
340 MapEditor::~MapEditor()
342 //cout <<"Destructor MapEditor\n";
343 if (isInteractive) delTmpDirs();
346 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
350 QColor MapEditor::color()
355 QColor MapEditor::backgroundColor()
357 return mapCanvas->backgroundColor();
360 MapCenterObj* MapEditor::getMapCenter()
365 QCanvas* MapEditor::getCanvas()
370 void MapEditor::adjustCanvasSize()
372 // To adjust the canvas to map, viewport size and position, we have to
373 // do some coordinate magic...
375 // Get rectangle of (scroll-)view.
376 // We want to be in canvas coords, so
377 // we map. Important if view is zoomed...
378 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
379 visibleWidth(), visibleHeight()) );
381 // Now we need the bounding box of view AND map to calc the correct canvas size.
382 // Why? Because if the map itself is moved out of view, the view has to be enlarged
383 // to avoid jumping aroung...
384 QRect map=mapCenter->getTotalBBox();
386 // right edge - left edge
387 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
388 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
391 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
392 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
395 // move the map on canvas (in order to not move it on screen) this is neccessary
396 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
397 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
398 // to scroll to an empty area of canvas to the left.
399 // b) if topleft corner of map left of or above topleft of canvas
403 if (cw > mapCanvas->width() )
405 if (map.x()<0) dx=-map.x();
407 if (cw < mapCanvas->width() )
408 dx=-min (view.x(),map.x());
409 if (ch > mapCanvas->height() )
411 if (map.y()<0) dy=-map.y();
413 if (ch < mapCanvas->height() )
415 dy=-min (view.y(),map.y());
417 // We really have to resize now. Let's go...
418 mapCanvas->resize (cw,ch);
419 if ( (dx!=0) || (dy!=0) )
421 mapCenter->moveAllBy(dx,dy);
422 mapCenter->reposition();
424 // scroll the view (in order to not move map on screen)
430 bool MapEditor::blockReposition()
432 return blockreposition;
435 void MapEditor::makeTmpDirs()
437 // Create unique temporary directories
438 char tmpdir[]="/tmp/vym-XXXXXX";
439 bakMapDir=mkdtemp(tmpdir);
440 makeSubDirs(bakMapDir);
441 // FIXME set permissions
442 // and maybe use QT method for portability
445 void MapEditor::delTmpDirs()
447 //FIXME delete tmp directory, better use QT methods here:
448 system ( "rm -rf "+ bakMapDir );
452 void MapEditor::makeSubDirs(const QString &s)
460 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, SaveMode savemode)
462 // tmpdir temporary directory to which data will be writte
463 // prefix mapname, which will be appended to images etc.
464 // writeflags Only write flags for "real" save of map, not undo
465 // offset offset of bbox of whole map in canvas.
466 // Needed for XML export
467 // completeMap if false, only vympart will be written, without
484 ls="StylePolyParabel";
488 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
490 if (linkcolorhint==HeadingColor)
491 colhint=attribut("linkColorHint","HeadingColor");
493 QString mapAttr=attribut("version",__VYM_VERSION__);
494 if (savemode==CompleteMap)
495 mapAttr+= attribut("author",mapCenter->getAuthor()) +
496 attribut("comment",mapCenter->getComment()) +
497 attribut("date",mapCenter->getDate()) +
498 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
499 attribut("linkStyle", ls ) +
500 attribut("linkColor", deflinkcolor.name() ) +
502 s+=beginElement("vymmap",mapAttr);
505 // Find the used flags while traversing the tree
506 standardFlagsDefault->resetUsedCounter();
508 // Build xml recursivly
509 if (savemode==CompleteMap)
510 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
513 if ( undoSelection &&
514 typeid(*undoSelection) == typeid(BranchObj) )
515 s+=((BranchObj*)(undoSelection))->saveToDir(tmpdir,prefix,offset);
518 // Save local settings
519 s+=settings.getXMLData (destPath);
523 s+=valueElement("select",selection->getSelectString());
526 s+=endElement("vymmap");
529 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
534 void MapEditor::saveState()
536 saveState (CompleteMap,NULL);
539 void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part)
541 // all binary data is saved in bakMapDir (created in Constructor)
542 // the xml data itself is kept in memory in backupXML
544 // For faster write/read of data, a part of the map can be
545 // written. Then the undoSelection will mark, which part of the
546 // map should be replaced if an undo is wanted later.
548 if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) )
550 // Writing a vympart only is useful for BranchObj
552 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
556 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap);
560 void MapEditor::finishedLineEditNoSave()
562 // This is called by finishedLineEdit or any MapEditor method,
563 // which wants to assure, that lineedits finish, before e.g. a branch is
566 // After calling LineEdit and using the clipboard, the
567 // focus is not any longer on the main widget, we
568 // have to restore it using parentWidget()->setFocus()
572 editingBO->setHeading(lineedit->text() );
574 lineedit->releaseKeyboard();
576 parentWidget()->setFocus();
577 mapCenter->reposition();
579 ensureSelectionVisible();
584 bool MapEditor::isDefault()
589 bool MapEditor::isUnsaved()
594 bool MapEditor::hasChanged()
599 void MapEditor::setChanged()
604 actionEditUndo->setEnabled (true);
605 actionFileSave->setEnabled (true);
609 void MapEditor::closeMap()
611 // Finish open lineEdits
612 if (lineedit) finishedLineEditNoSave();
614 // Unselect before disabling the toolbar actions
615 if (selection) selection->unselect();
623 void MapEditor::setFilePath(QString fname)
625 setFilePath (fname,fname);
628 void MapEditor::setFilePath(QString fname, QString destname)
634 // If fname is not an absolute path, complete it
635 filePath=QDir(fname).absPath();
636 fileDir=filePath.left (1+filePath.findRev ("/"));
638 // Set short name, too. Search from behind:
639 int i=fileName.findRev("/");
640 if (i>=0) fileName=fileName.remove (0,i+1);
642 // Forget the .vym (or .xml) for name of map
643 mapName=fileName.left(fileName.findRev(".",-1,true) );
646 QString MapEditor::getFilePath()
651 QString MapEditor::getFileName()
656 QString MapEditor::getMapName()
661 QString MapEditor::getDestPath()
666 int MapEditor::load (QString &fname, const LoadMode &lmode)
668 // Finish open lineEdits
669 if (lineedit) finishedLineEditNoSave();
675 if (selection) selection->unselect();
678 mapCenter->setMapEditor(this);
679 // (map state is set later at end of load...)
683 saveState(PartOfMap,selection);
687 mapBuilderHandler handler;
690 // I am paranoid: file should exist anyway
691 // according to check in mainwindow.
694 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
695 tr("Couldn't open map " +fname)+".");
699 blockreposition=true;
700 QXmlInputSource source( file);
701 QXmlSimpleReader reader;
702 reader.setContentHandler( &handler );
703 reader.setErrorHandler( &handler );
704 handler.setMapEditor( this );
705 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
706 handler.setLoadMode (lmode);
707 bool ok = reader.parse( source );
708 blockreposition=false;
712 mapCenter->reposition();
722 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
723 tr( handler.errorProtocol() ) );
725 // Still return "success": the map maybe at least
726 // partially read by the parser
733 int MapEditor::save (const SaveMode &savemode)
735 // Finish open lineEdits
736 if (lineedit) finishedLineEditNoSave();
740 // Create mapName and fileDir
741 makeSubDirs (fileDir);
745 fname=mapName+".xml";
747 // use name given by user, even if he chooses .doc
751 // Check if fname is writeable
752 QFile file( fileDir+fname);
753 if (!file.open( IO_WriteOnly ) )
755 QMessageBox::critical( 0, tr( "Critical Save Error" ),
756 tr("Couldn't write to ") +fileDir+fname);
762 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),savemode);
764 file.setName ( fileDir + fname);
765 if ( !file.open( IO_WriteOnly ) )
767 // This should neverever happen
768 QMessageBox::critical(0, tr("Critcal save error"),"MapEditor::save() Couldn't open "+file.name());
772 // Write it finally, and write in UTF8, no matter what
773 QTextStream ts( &file );
774 ts.setEncoding (QTextStream::UnicodeUTF8);
782 actionFileSave->setEnabled(false);
788 void MapEditor::setZipped (bool z)
793 bool MapEditor::saveZipped ()
798 void MapEditor::print()
800 // Finish open lineEdits
801 if (lineedit) finishedLineEditNoSave();
805 printer = new QPrinter;
806 printer->setColorMode (QPrinter::Color);
809 QRect totalBBox=mapCenter->getTotalBBox();
811 // Try to set orientation automagically
812 // Note: Interpretation of generated postscript is amibiguous, if
813 // there are problems with landscape mode, see
814 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
816 if (totalBBox.width()>totalBBox.height())
817 // recommend landscape
818 printer->setOrientation (QPrinter::Landscape);
820 // recommend portrait
821 printer->setOrientation (QPrinter::Portrait);
823 if ( printer->setup(this) )
824 // returns false, if printing is canceled
826 QPainter pp(printer);
828 // Don't print the visualisation of selection
829 LinkableMapObj *oldselection=NULL;
832 oldselection=selection;
833 selection->unselect();
836 // Handle sizes of map and paper:
838 // setWindow defines which part of the canvas will be transformed
839 // setViewport defines area on paper in device coordinates (dpi)
840 // e.g. (0,50,700,700) is upper part on A4
841 // see also /usr/lib/qt3/doc/html/coordsys.html
843 QPaintDeviceMetrics metrics (printer);
845 double paperAspect = (double)metrics.width() / (double)metrics.height();
846 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
848 QRect mapRect=mapCenter->getTotalBBox();
849 QCanvasRectangle *frame=NULL;
850 QCanvasText *footerFN=NULL;
851 QCanvasText *footerDate=NULL;
852 if (printFrame || printFooter)
857 // Print frame around map
858 mapRect.setRect (mapRect.x()-10, mapRect.y()-10,
859 mapRect.width()+20, mapRect.height()+20);
860 frame=new QCanvasRectangle (mapRect,mapCanvas);
861 frame->setBrush (QColor(white));
862 frame->setPen (QColor(black));
868 // Print footer below map
870 font.setPointSize(10);
871 footerFN=new QCanvasText (mapCanvas);
872 footerFN->setText ("VYM - " + fileName);
873 footerFN->setFont(font);
874 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
875 footerFN->setZ(Z_TEXT);
877 footerDate=new QCanvasText (mapCanvas);
878 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
879 footerDate->setFont(font);
880 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
881 footerDate->setZ(Z_TEXT);
883 mapRect.setRect (mapRect.x(), mapRect.y(),
884 mapRect.width(), mapRect.height()+20);
886 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height());
889 pp.setWindow (mapRect);
892 if (mapAspect>=paperAspect)
894 // Fit horizontally to paper width
895 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
898 // Fit vertically to paper height
899 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
902 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
904 // Delete Frame and footer
910 if (frame) delete (frame);
915 selection=oldselection;
921 QPixmap MapEditor::getPixmap()
923 QRect mapRect=mapCenter->getTotalBBox();
924 QPixmap pix (mapRect.size());
927 // Don't print the visualisation of selection
928 LinkableMapObj *oldselection=NULL;
931 oldselection=selection;
932 selection->unselect();
935 pp.setWindow (mapRect);
937 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
943 selection=oldselection;
950 void MapEditor::exportImage(QString fn)
952 // Finish open lineEdits
953 if (lineedit) finishedLineEditNoSave();
955 QPixmap pix (getPixmap());
959 void MapEditor::exportImage(QString fn, int item)
961 // Finish open lineEdits
962 if (lineedit) finishedLineEditNoSave();
964 QPixmap pix (getPixmap());
965 pix.save(fn, exportImageFormatMenu->text(item) );
968 void MapEditor::exportASCII()
970 // FIXME still experimental
971 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
972 fd->addFilter ("TXT (*.txt)");
973 fd->setCaption("VYM - Export (ASCII) (still experimental)");
974 fd->setMode( QFileDialog::AnyFile );
977 if ( fd->exec() == QDialog::Accepted )
979 if (QFile (fd->selectedFile()).exists() )
981 QMessageBox mb( "VYM",
982 tr("The file ") + fd->selectedFile() +
983 tr(" exists already. Do you want to overwrite it?"),
984 QMessageBox::Warning,
985 QMessageBox::Yes | QMessageBox::Default,
986 QMessageBox::Cancel | QMessageBox::Escape,
987 QMessageBox::NoButton );
989 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
990 mb.setButtonText( QMessageBox::No, tr("Cancel"));
994 case QMessageBox::Yes:
996 if (!ex.setOutputDir ("out"))
998 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1002 case QMessageBox::Cancel:
1009 ex.setPath (fd->selectedFile() );
1010 ex.setMapCenter(mapCenter);
1016 void MapEditor::exportXML(const QString &dir)
1018 // Create subdirectories
1021 // write to directory
1022 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,CompleteMap);
1025 file.setName ( dir + "/"+mapName+".xml");
1026 if ( !file.open( IO_WriteOnly ) )
1028 // This should neverever happen
1029 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1033 // Write it finally, and write in UTF8, no matter what
1034 QTextStream ts( &file );
1035 ts.setEncoding (QTextStream::UnicodeUTF8);
1039 // Now write image, too
1040 exportImage (dir+"/images/"+mapName+".png");
1043 void MapEditor::clear()
1047 selection->unselect();
1054 void MapEditor::undo()
1057 d.setPath(bakMapDir);
1060 // Finish open lineEdits
1061 if (lineedit) finishedLineEditNoSave();
1065 selection->unselect();
1069 mapBuilderHandler handler;
1070 QXmlInputSource source;
1071 source.setData(backupXML);
1072 QXmlSimpleReader reader;
1073 reader.setContentHandler( &handler );
1074 reader.setErrorHandler( &handler );
1075 handler.setMapEditor( this );
1076 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1079 selection=undoSelection;
1080 selection->select();
1081 handler.setLoadMode (ImportReplace);
1086 handler.setLoadMode (NewMap);
1088 blockreposition=true;
1089 bool ok = reader.parse( source );
1090 blockreposition=false;
1092 mapCenter->reposition();
1096 // This should never ever happen
1097 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1098 tr( handler.errorProtocol() )+" in "+backupXML );
1100 // Undo not longer available now
1101 actionEditUndo->setEnabled (false);
1102 undoSelection=false;
1107 QMessageBox::critical( 0, tr( "Critical Error" ),
1108 "Temporary directory " +bakMapDir +
1109 tr (" used for undo is gone. \n"
1110 "I will create a new one, but at the moment no undo is available.\n"
1111 "Maybe you want to reload your original data.\n\n"
1112 "Sorry for any inconveniences.") );
1117 void MapEditor::copy()
1119 // Finish open lineEdits
1120 if (lineedit) finishedLineEditNoSave();
1124 if (typeid(*selection) == typeid(BranchObj) )
1128 clipboardME->clear();
1129 clipboardME->getMapCenter()->addBranch();
1130 to=clipboardME->getMapCenter()->getLastBranch();
1133 from=(BranchObj*)(selection);
1136 // keep position relative to parent
1137 to->move2RelPos ( from->getRelPos());
1139 // select data in clipboard
1140 clipboardME->select ("bo:0");
1142 // repositioning makes testing nicer,
1143 // but is not needed usually:
1144 if (clipboardME->isVisible())
1146 clipboardME->getMapCenter()->reposition();
1149 clipboardME->hide();
1152 if (typeid(*selection) == typeid(FloatImageObj) )
1155 FloatImageObj* from;
1156 clipboardME->clear();
1157 clipboardME->getMapCenter()->addFloatImage();
1158 to=clipboardME->getMapCenter()->getLastFloatImage();
1161 from=(FloatImageObj*)(selection);
1164 // select data in clipboard
1165 clipboardME->select ("fi:0");
1167 // repositioning makes testing nicer,
1168 // but is not needed usually:
1169 if (clipboardME->isVisible())
1171 clipboardME->getMapCenter()->reposition();
1174 clipboardME->hide();
1180 LinkableMapObj* MapEditor::pasteNoSave()
1182 return pasteAtNoSave (-1);
1185 LinkableMapObj* MapEditor::pasteAtNoSave(int pos)
1187 // Finish open lineEdits
1188 if (lineedit) finishedLineEditNoSave();
1190 LinkableMapObj *fromLMO=clipboardME->getSelection();
1191 LinkableMapObj *returnLMO=NULL;
1193 if (selection && fromLMO)
1196 if (typeid(*fromLMO) == typeid(BranchObj) )
1198 if (typeid(*selection) == typeid(MapCenterObj))
1200 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1201 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1203 if (typeid(*selection) == typeid(BranchObj))
1205 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1208 BranchObj *par=(BranchObj*)(selection->getParObj());
1209 if (par) returnLMO=par->insertBranch((BranchObj*)(fromLMO),pos );
1213 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1214 (typeid(*selection) == typeid (BranchObj) ||
1215 typeid(*selection)==typeid(MapCenterObj)) )
1216 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1222 void MapEditor::cutNoSave()
1224 // Finish open lineEdits
1225 if (lineedit) finishedLineEditNoSave();
1229 if (selection != NULL) {
1230 if (typeid(*selection) == typeid(BranchObj) )
1232 bo=(BranchObj*)(selection);
1233 par=(BranchObj*)(bo->getParObj());
1236 par->removeBranch(bo);
1238 selection->select();
1240 if (typeid(*selection) == typeid(FloatImageObj) )
1242 FloatImageObj* fio=(FloatImageObj*)(selection);
1243 par=(BranchObj*)(fio->getParObj());
1246 par->removeFloatImage(fio);
1248 selection->select();
1253 void MapEditor::paste()
1256 saveState(PartOfMap,selection);
1258 mapCenter->reposition();
1262 void MapEditor::cut()
1265 saveState(PartOfMap,selection->getParObj());
1268 mapCenter->reposition();
1272 void MapEditor::moveBranchUp()
1274 // Finish open lineEdits
1275 if (lineedit) finishedLineEditNoSave();
1279 if (typeid(*selection) == typeid(BranchObj) )
1282 saveState(PartOfMap,selection->getParObj());
1283 bo=(BranchObj*)(selection);
1284 par=(BranchObj*)(bo->getParObj());
1285 selection->unselect();
1286 selection=par->moveBranchUp (bo);
1287 selection->select();
1288 mapCenter->reposition();
1289 ensureSelectionVisible();
1293 void MapEditor::moveBranchDown()
1295 // Finish open lineEdits
1296 if (lineedit) finishedLineEditNoSave();
1300 if (typeid(*selection) == typeid(BranchObj) )
1303 saveState(PartOfMap,selection->getParObj());
1304 bo=(BranchObj*)(selection);
1305 par=(BranchObj*)(bo->getParObj());
1306 selection->unselect();
1307 selection=par->moveBranchDown(bo);
1308 selection->select();
1309 mapCenter->reposition();
1310 ensureSelectionVisible();
1314 void MapEditor::editHeading()
1316 // Finish open lineEdits
1317 if (lineedit) finishedLineEditNoSave();
1320 (typeid(*selection) == typeid(BranchObj) ||
1321 typeid(*selection) == typeid(MapCenterObj) ) )
1324 saveState(PartOfMap,selection);
1326 ensureSelectionVisible();
1327 BranchObj *bo=(BranchObj*)(selection);
1328 editingBO=(BranchObj*)(selection);
1329 QPoint p = worldMatrix().map(QPoint (bo->x(),bo->y()));
1330 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1331 QString s=bo->getHeading();
1332 lineedit->setText(s);
1333 lineedit->setCursorPosition(1);
1334 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1335 lineedit->selectAll();
1338 lineedit->grabKeyboard();
1339 lineedit->setFocus();
1344 void MapEditor::addNewBranch(int pos)
1346 // Finish open lineEdits
1347 if (lineedit) finishedLineEditNoSave();
1350 (typeid(*selection) == typeid(BranchObj) ||
1351 typeid(*selection) == typeid(MapCenterObj) ) )
1354 saveState(PartOfMap,selection);
1356 BranchObj* bo1 = (BranchObj*) (selection);
1357 bool wasScrolled=false;
1358 BranchObj *newbo=NULL;
1361 // save scroll state. If scrolled, automatically select
1362 // new branch in order to tmp unscroll parent...
1363 wasScrolled=bo1->isScrolled();
1364 newbo=bo1->addBranch();
1367 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1371 // add above selection
1372 newbo=parbo->insertBranch(bo1->getNum());
1374 // add below selection
1375 newbo=parbo->insertBranch(bo1->getNum()+1);
1377 // This should not happen...
1382 LinkableMapObj *oldselection=selection;
1384 mapCenter->reposition();
1386 if (actionSettingsAutoedit->isOn() ||
1387 actionSettingsAutoselectHeading->isOn() )
1389 selection->unselect();
1391 selection->select();
1392 if (actionSettingsPasteNewHeading->isOn() )
1394 BranchObj *bo2= (BranchObj*)(selection);
1395 bo2->setHeading("");
1397 if (actionSettingsAutoedit->isOn() )
1399 if (!actionSettingsAutoselectHeading->isOn()
1402 selection->unselect();
1403 selection=oldselection;
1404 selection->select();
1410 void MapEditor::deleteSelection()
1412 // Finish open lineEdits
1413 if (lineedit) finishedLineEditNoSave();
1415 if (selection && typeid(*selection) ==typeid(BranchObj) )
1418 saveState(PartOfMap,selection->getParObj());
1419 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1420 BranchObj* par=(BranchObj*)(bo->getParObj());
1423 par->removeBranch(bo);
1425 selection->select();
1426 ensureSelectionVisible();
1427 mapCenter->reposition();
1430 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1433 saveState(PartOfMap,selection->getParObj());
1434 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1435 BranchObj* par=(BranchObj*)(fio->getParObj());
1438 par->removeFloatImage(fio);
1440 selection->select();
1441 ensureSelectionVisible();
1442 mapCenter->reposition();
1447 LinkableMapObj* MapEditor::getSelection()
1452 bool MapEditor::select (QString s)
1454 LinkableMapObj *lmo=mapCenter;
1458 while (!s.isEmpty() )
1460 part=s.section(",",0,0);
1462 num=part.right(part.length() - 3);
1469 lmo=mapCenter->getBranchNum (num.toUInt());
1472 lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt());
1475 lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
1481 if (s.contains(","))
1482 s=s.right(s.length() - part.length() -1 );
1487 // Finally select the found object
1490 if (selection) selection->unselect();
1492 selection->select();
1494 ensureSelectionVisible();
1502 void MapEditor::unselect()
1506 selectionLast=selection;
1507 selection->unselect();
1512 void MapEditor::reselect()
1516 selection=selectionLast;
1517 selection->select();
1522 void MapEditor::selectNextBranch()
1524 // Increase number of branch
1527 QString s=selection->getSelectString();
1533 part=s.section(",",-1);
1535 num=part.right(part.length() - 3);
1537 s=s.left (s.length() -num.length());
1540 num=QString ("%1").arg(num.toUInt()+1);
1544 // Try to select this one
1545 if (select (s)) return;
1547 // We have no direct successor,
1548 // try to increase the parental number in order to
1549 // find a successor with same depth
1551 int d=selection->getDepth();
1556 while (!found && d>0)
1558 s=s.section (",",0,d-1);
1559 // replace substring of current depth in s with "1"
1560 part=s.section(",",-1);
1562 num=part.right(part.length() - 3);
1566 // increase number of parent
1567 num=QString ("%1").arg(num.toUInt()+1);
1568 s=s.section (",",0,d-2) + ","+ typ+num;
1571 // Special case, look at orientation
1572 if (selection->getOrientation()==OrientRightOfCenter)
1573 num=QString ("%1").arg(num.toUInt()+1);
1575 num=QString ("%1").arg(num.toUInt()-1);
1580 // pad to oldDepth, select the first branch for each depth
1581 for (i=d;i<oldDepth;i++)
1586 if ( ((BranchObj*)(selection))->countBranches()>0)
1594 // try to select the freshly built string
1602 void MapEditor::selectPrevBranch()
1604 // Decrease number of branch
1607 QString s=selection->getSelectString();
1613 part=s.section(",",-1);
1615 num=part.right(part.length() - 3);
1617 s=s.left (s.length() -num.length());
1620 num=QString ("%1").arg(num.toUInt()-1);
1624 // Try to select this one
1625 if (select (s)) return;
1627 // We have no direct precessor,
1628 // try to decrease the parental number in order to
1629 // find a precessor with same depth
1631 int d=selection->getDepth();
1636 while (!found && d>0)
1638 s=s.section (",",0,d-1);
1639 // replace substring of current depth in s with "1"
1640 part=s.section(",",-1);
1642 num=part.right(part.length() - 3);
1646 // decrease number of parent
1647 num=QString ("%1").arg(num.toUInt()-1);
1648 s=s.section (",",0,d-2) + ","+ typ+num;
1651 // Special case, look at orientation
1652 if (selection->getOrientation()==OrientRightOfCenter)
1653 num=QString ("%1").arg(num.toUInt()-1);
1655 num=QString ("%1").arg(num.toUInt()+1);
1660 // pad to oldDepth, select the last branch for each depth
1661 for (i=d;i<oldDepth;i++)
1665 if ( ((BranchObj*)(selection))->countBranches()>0)
1666 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1673 // try to select the freshly built string
1681 void MapEditor::selectUpperBranch()
1683 // Finish open lineEdits
1684 if (lineedit) finishedLineEditNoSave();
1688 if (typeid(*selection) == typeid(BranchObj))
1690 if (selection->getOrientation()==OrientRightOfCenter)
1693 if (selection->getDepth()==1)
1701 void MapEditor::selectLowerBranch()
1703 // Finish open lineEdits
1704 if (lineedit) finishedLineEditNoSave();
1708 if (typeid(*selection) == typeid(BranchObj))
1710 if (selection->getOrientation()==OrientRightOfCenter)
1713 if (selection->getDepth()==1)
1722 void MapEditor::selectLeftBranch()
1724 // Finish open lineEdits
1725 if (lineedit) finishedLineEditNoSave();
1731 if (typeid(*selection) == typeid(MapCenterObj))
1733 par= (BranchObj*) (selection);
1734 bo=par->getLastSelectedBranch();
1737 // Workaround for reselecting on left and right side
1738 if (bo->getOrientation()==OrientRightOfCenter)
1740 bo=par->getLastBranch();
1746 selection->select();
1748 ensureSelectionVisible();
1753 par=(BranchObj*)(selection->getParObj());
1754 if (selection->getOrientation()==OrientRightOfCenter)
1756 if (typeid(*selection) == typeid(BranchObj) ||
1757 typeid(*selection) == typeid(FloatImageObj))
1759 selection->unselect();
1761 selection->select();
1763 ensureSelectionVisible();
1767 if (typeid(*selection) == typeid(BranchObj) )
1769 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1772 selection->unselect();
1774 selection->select();
1776 ensureSelectionVisible();
1784 void MapEditor::selectRightBranch()
1786 // Finish open lineEdits
1787 if (lineedit) finishedLineEditNoSave();
1794 if (typeid(*selection) == typeid(MapCenterObj))
1796 par= (BranchObj*) (selection);
1797 bo=par->getLastSelectedBranch();
1800 // Workaround for relecting on left and right side
1801 if (bo->getOrientation()==OrientLeftOfCenter)
1802 bo=par->getFirstBranch();
1807 selection->select();
1808 ensureSelectionVisible();
1813 par=(BranchObj*)(selection->getParObj());
1814 if (selection->getOrientation()==OrientLeftOfCenter)
1816 if (typeid(*selection) == typeid(BranchObj) ||
1817 typeid(*selection) == typeid(FloatImageObj))
1819 selection->unselect();
1821 selection->select();
1823 ensureSelectionVisible();
1827 if (typeid(*selection) == typeid(BranchObj) )
1829 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1832 selection->unselect();
1834 selection->select();
1836 ensureSelectionVisible();
1844 void MapEditor::selectFirstBranch()
1846 // Finish open lineEdits
1847 if (lineedit) finishedLineEditNoSave();
1853 if (typeid(*selection) == typeid(BranchObj))
1855 bo1= (BranchObj*) (selection);
1856 par=(BranchObj*)(bo1->getParObj());
1857 bo2=par->getFirstBranch();
1861 selection->select();
1862 ensureSelectionVisible();
1869 void MapEditor::selectLastBranch()
1871 // Finish open lineEdits
1872 if (lineedit) finishedLineEditNoSave();
1878 if (typeid(*selection) == typeid(BranchObj))
1880 bo1= (BranchObj*) (selection);
1881 par=(BranchObj*)(bo1->getParObj());
1882 bo2=par->getLastBranch();
1886 selection->select();
1887 ensureSelectionVisible();
1894 void MapEditor::setColor(QColor c)
1899 void MapEditor::selectBackgroundColor()
1901 // Finish open lineEdits
1902 if (lineedit) finishedLineEditNoSave();
1904 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
1905 if ( !col.isValid() ) return;
1906 setBackgroundColor( col );
1910 void MapEditor::setBackgroundColor(QColor c)
1912 mapCanvas->setBackgroundColor (c);
1915 QColor MapEditor::pickColor()
1919 if (typeid(*selection) == typeid(BranchObj) ||
1920 typeid(*selection) == typeid(MapCenterObj))
1922 BranchObj *bo=(BranchObj*)(selection);
1923 actColor=bo->getColor();
1929 void MapEditor::colorItem()
1933 if (typeid(*selection) == typeid(BranchObj) ||
1934 typeid(*selection) == typeid(MapCenterObj))
1937 saveState(PartOfMap,selection);
1938 BranchObj *bo=(BranchObj*)(selection);
1939 bo->setColor(actColor, false); // color links, color childs
1944 void MapEditor::colorBranch()
1948 if (typeid(*selection) == typeid(BranchObj) ||
1949 typeid(*selection) == typeid(MapCenterObj))
1952 saveState(PartOfMap,selection);
1953 BranchObj *bo=(BranchObj*)(selection);
1954 bo->setColor(actColor, true); // color links, color childs
1960 void MapEditor::toggleStandardFlag(QString f)
1965 saveState(PartOfMap,selection);
1966 ((BranchObj*)(selection))->toggleStandardFlag (f);
1970 void MapEditor::setViewCenter()
1972 // transform to CanvasView Coord:
1973 QPoint p=worldMatrix().map(movingCenter);
1974 center ( p.x(), p.y());
1978 BranchObj* MapEditor::findText (QString s, bool cs)
1981 { // Nothing found or new find process
1983 // nothing found, start again
1985 itFind=mapCenter->first();
1987 bool searching=true;
1988 bool foundNote=false;
1989 while (searching && !EOFind)
1993 // Searching in Note
1994 if (itFind->getNote().contains(s,cs))
1996 if (selection!=itFind)
1998 if (selection) ((BranchObj*)(selection))->unselect();
2000 selection->select();
2002 ensureSelectionVisible();
2004 if (textEditor->findText(s,cs))
2010 // Searching in Heading
2011 if (searching && itFind->getHeading().contains (s,cs) )
2013 if (selection) ((BranchObj*)(selection))->unselect();
2015 selection->select();
2017 ensureSelectionVisible();
2023 itFind=itFind->next();
2024 if (!itFind) EOFind=true;
2030 return (BranchObj*)(selection);
2035 void MapEditor::findReset()
2036 { // Necessary if text to find changes during a find process
2041 void MapEditor::openURL()
2045 if (typeid(*selection) == typeid(BranchObj) ||
2046 typeid(*selection) == typeid(MapCenterObj))
2048 QString url=((BranchObj*)(selection))->getURL();
2050 QProcess *proc = new QProcess( this );
2052 #if !defined(Q_OS_MACX)
2053 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2055 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2056 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2059 proc->addArgument( url);
2061 if ( !proc->start() )
2063 if (mainWindow->settingsURL() )
2069 void MapEditor::editURL()
2071 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2072 typeid(*selection) == typeid(MapCenterObj)) )
2075 QString text = QInputDialog::getText(
2076 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2077 ((BranchObj*)(selection))->getURL(), &ok, this );
2080 // user entered something and pressed OK
2081 ((BranchObj*)(selection))->setURL (text);
2088 void MapEditor::editHeading2URL()
2090 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2091 typeid(*selection) == typeid(MapCenterObj)) )
2093 BranchObj *b=(BranchObj*)(selection);
2094 b->setURL (b->getHeading());
2100 void MapEditor::editBugzilla2URL()
2102 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2103 typeid(*selection) == typeid(MapCenterObj)) )
2105 BranchObj *b=(BranchObj*)(selection);
2106 b->setURL ("http://bugzilla.suse.de/show_bug.cgi?id="+b->getHeading());
2112 void MapEditor::editVymLink()
2114 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2115 typeid(*selection) == typeid(MapCenterObj)) )
2117 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2118 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2119 fd->setCaption(tr("VYM - Link to another map"));
2120 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2121 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2125 if ( fd->exec() == QDialog::Accepted )
2126 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2128 mapCenter->reposition();
2135 void MapEditor::deleteVymLink()
2137 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2138 typeid(*selection) == typeid(MapCenterObj)) )
2140 ((BranchObj*)(selection))->setVymLink ("" );
2142 mapCenter->reposition();
2149 QString MapEditor::getVymLink()
2151 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2152 typeid(*selection) == typeid(MapCenterObj)) )
2154 return ((BranchObj*)(selection))->getVymLink();
2160 void MapEditor::editMapInfo()
2162 ExtraInfoDialog dia;
2163 dia.setMapName (getFileName() );
2164 dia.setAuthor (mapCenter->getAuthor() );
2165 dia.setComment(mapCenter->getComment() );
2170 QCanvasItemList l=canvas()->allItems();
2171 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2173 stats+=QString ("%1 items on canvas\n").arg (i,6);
2179 bo=mapCenter->first();
2182 if (!bo->getNote().isEmpty() ) n++;
2183 f+= bo->countFloatImages();
2187 stats+=QString ("%1 branches\n").arg (b-1,6);
2188 stats+=QString ("%1 notes\n").arg (n,6);
2189 stats+=QString ("%1 images\n").arg (f,6);
2190 dia.setStats (stats);
2192 // Finally show dialog
2193 if (dia.exec() == QDialog::Accepted)
2195 mapCenter->setAuthor (dia.getAuthor() );
2196 mapCenter->setComment (dia.getComment() );
2201 void MapEditor::updateActions()
2203 if (getLinkColorHint()==HeadingColor)
2204 actionFormatLinkColorHint->setOn(true);
2206 actionFormatLinkColorHint->setOn(false);
2211 actionFormatLinkStyleLine->setOn(true);
2214 actionFormatLinkStyleParabel->setOn(true);
2217 actionFormatLinkStylePolyLine->setOn(true);
2219 case StylePolyParabel:
2220 actionFormatLinkStylePolyParabel->setOn(true);
2226 QPixmap pix( 16, 16 );
2227 pix.fill( mapCanvas->backgroundColor() );
2228 actionFormatBackColor->setIconSet( pix );
2229 pix.fill( deflinkcolor );
2230 actionFormatLinkColor->setIconSet( pix );
2232 actionEditUndo->setEnabled( mapChanged );
2233 actionFileSave->setEnabled( mapUnsaved );
2237 if ( (typeid(*selection) == typeid(BranchObj)) ||
2238 (typeid(*selection) == typeid(MapCenterObj)) )
2240 standardFlagsDefault->setEnabled (true);
2242 if ( ((BranchObj*)(selection))->getURL().isEmpty() )
2243 actionEditOpenURL->setEnabled (false);
2245 actionEditOpenURL->setEnabled (true);
2246 actionEditURL->setEnabled (true);
2247 actionEditHeading2URL->setEnabled (true);
2248 actionEditBugzilla2URL->setEnabled (true);
2250 if ( ((BranchObj*)(selection))->getVymLink().isEmpty() )
2252 actionEditOpenVymLink->setEnabled (false);
2253 actionEditDeleteVymLink->setEnabled (false);
2256 actionEditOpenVymLink->setEnabled (true);
2257 actionEditDeleteVymLink->setEnabled (true);
2259 actionEditVymLink->setEnabled (true);
2261 actionEditCopy->setEnabled (true);
2262 actionEditCut->setEnabled (true);
2263 actionEditPaste->setEnabled (true);
2264 actionEditMoveUp->setEnabled (true);
2265 actionEditMoveDown->setEnabled (true);
2266 actionEditToggleScroll->setEnabled (true);
2267 actionEditHeading->setEnabled (true);
2268 actionEditDelete->setEnabled (true);
2269 actionEditAddBranch->setEnabled (true);
2270 actionEditAddBranchAbove->setEnabled (true);
2271 actionEditAddBranchBelow->setEnabled (true);
2272 actionEditImportAdd->setEnabled (true);
2273 actionEditImportReplace->setEnabled (true);
2274 actionEditSaveBranch->setEnabled (true);
2275 actionEditSelectFirst->setEnabled (true);
2276 actionEditSelectLast->setEnabled (true);
2277 actionEditToggleFloatExport->setEnabled (false);
2278 actionFormatPickColor->setEnabled (true);
2279 actionFormatColorBranch->setEnabled (true);
2280 actionFormatColorSubtree->setEnabled (true);
2281 switch (selection->getFrameType())
2284 actionFormatFrameNone->setOn(true);
2287 actionFormatFrameRectangle->setOn(true);
2293 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2295 standardFlagsDefault->setEnabled (false);
2297 actionEditOpenURL->setEnabled (false);
2298 actionEditURL->setEnabled (false);
2299 actionEditHeading2URL->setEnabled (false);
2300 actionEditBugzilla2URL->setEnabled (false);
2301 actionEditOpenVymLink->setEnabled (false);
2302 actionEditVymLink->setEnabled (false);
2303 actionEditDeleteVymLink->setEnabled (false);
2305 actionEditCopy->setEnabled (true);
2306 actionEditCut->setEnabled (true);
2307 actionEditPaste->setEnabled (false); //FIXME
2308 actionEditMoveUp->setEnabled (false);
2309 actionEditMoveDown->setEnabled (false);
2310 actionEditToggleScroll->setEnabled (false);
2311 actionEditHeading->setEnabled (false);
2312 actionEditDelete->setEnabled (true);
2313 actionEditAddBranch->setEnabled (false);
2314 actionEditAddBranchAbove->setEnabled (false);
2315 actionEditAddBranchBelow->setEnabled (false);
2316 actionEditImportAdd->setEnabled (false);
2317 actionEditSaveBranch->setEnabled (false);
2318 actionEditImportReplace->setEnabled (false);
2319 actionEditSelectFirst->setEnabled (false);
2320 actionEditSelectLast->setEnabled (false);
2321 actionEditToggleFloatExport->setOn
2322 ( ((FloatImageObj*)(selection))->getFloatExport() );
2323 actionFormatPickColor->setEnabled (false);
2324 actionFormatColorBranch->setEnabled (false);
2325 actionFormatColorSubtree->setEnabled (false);
2330 standardFlagsDefault->setEnabled (false);
2332 actionEditCopy->setEnabled (false);
2333 actionEditCut->setEnabled (false);
2334 actionEditPaste->setEnabled (false);
2335 actionEditMoveUp->setEnabled (false);
2336 actionEditMoveDown->setEnabled (false);
2337 actionEditToggleScroll->setEnabled (false);
2338 actionEditOpenURL->setEnabled (false);
2339 actionEditURL->setEnabled (false);
2340 actionEditOpenVymLink->setEnabled (false);
2341 actionEditVymLink->setEnabled (false);
2342 actionEditDeleteVymLink->setEnabled (false);
2343 actionEditHeading2URL->setEnabled (false);
2344 actionEditBugzilla2URL->setEnabled (false);
2345 actionEditHeading->setEnabled (false);
2346 actionEditDelete->setEnabled (false);
2347 actionEditAddBranch->setEnabled (false);
2348 actionEditAddBranchAbove->setEnabled (false);
2349 actionEditAddBranchBelow->setEnabled (false);
2350 actionEditSaveBranch->setEnabled (false);
2351 actionEditImportReplace->setEnabled (false);
2352 actionEditSelectFirst->setEnabled (false);
2353 actionEditSelectLast->setEnabled (false);
2354 actionEditToggleFloatExport->setEnabled (false);
2355 actionFormatPickColor->setEnabled (false);
2356 actionFormatColorBranch->setEnabled (false);
2357 actionFormatColorSubtree->setEnabled (false);
2361 void MapEditor::setLinkStyle (LinkStyle ls)
2366 bo=mapCenter->first();
2370 bo->setLinkStyle(bo->getDefLinkStyle());
2377 LinkStyle MapEditor::getLinkStyle ()
2382 void MapEditor::setLinkColor(QColor c)
2388 void MapEditor::setLinkColorHint()
2390 // called from setLinkColorHint(lch) or at end of parse
2392 bo=mapCenter->first();
2400 void MapEditor::setLinkColorHint(LinkColorHint lch)
2406 void MapEditor::toggleLinkColorHint()
2408 if (linkcolorhint==HeadingColor)
2409 linkcolorhint=DefaultColor;
2411 linkcolorhint=HeadingColor;
2413 bo=mapCenter->first();
2421 LinkColorHint MapEditor::getLinkColorHint()
2423 return linkcolorhint;
2426 QColor MapEditor::getDefLinkColor()
2428 return deflinkcolor;
2431 void MapEditor::selectLinkColor()
2433 // Finish open lineEdits
2434 if (lineedit) finishedLineEditNoSave();
2436 QColor col = QColorDialog::getColor( deflinkcolor, this );
2437 if ( !col.isValid() ) return;
2438 setLinkColor( col );
2442 void MapEditor::toggleScroll()
2444 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2446 BranchObj *bo=((BranchObj*)(selection));
2447 if (bo->countBranches()==0) return;
2448 if (bo->getDepth()==0) return;
2450 saveState(PartOfMap,selection);
2457 void MapEditor::unScrollAll()
2460 bo=mapCenter->first();
2463 if (bo->isScrolled()) bo->toggleScroll();
2468 void MapEditor::loadFloatImage ()
2471 (typeid(*selection) == typeid(BranchObj)) ||
2472 (typeid(*selection) == typeid(MapCenterObj)) )
2474 BranchObj *bo=((BranchObj*)(selection));
2476 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2477 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2478 ImagePreview *p =new ImagePreview (fd);
2479 fd->setContentsPreviewEnabled( TRUE );
2480 fd->setContentsPreview( p, p );
2481 fd->setPreviewMode( QFileDialog::Contents );
2482 fd->setCaption(tr("vym - Load image"));
2483 fd->setDir (lastImageDir);
2487 if ( fd->exec() == QDialog::Accepted )
2490 saveState(PartOfMap,selection);
2491 QString fn=fd->selectedFile();
2492 lastImageDir=fn.left(fn.findRev ("/"));
2493 bo->addFloatImage();
2494 // FIXME check if load was successful
2495 bo->getLastFloatImage()->load(fn);
2496 bo->getLastFloatImage()->setOriginalFilename(fn);
2497 mapCenter->reposition();
2504 void MapEditor::saveFloatImage (int item)
2507 (typeid(*selection) == typeid(FloatImageObj)) )
2509 FloatImageObj *fio=((FloatImageObj*)(selection));
2510 const char* fmt = saveImageFormatMenu->text(item);
2512 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2513 fd->addFilter ("PNG (*.png)");
2514 fd->addFilter ("BMP (*.bmp)");
2515 fd->addFilter ("XBM (*.xbm)");
2516 fd->addFilter ("JPG (*.jpg)");
2517 fd->addFilter ("XPM (*.xpm)");
2518 fd->addFilter ("GIF (*.gif)");
2519 fd->addFilter ("PNM (*.pnm)");
2520 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2521 fd->setCaption(tr("vym - Save image as ") + fmt);
2522 fd->setMode( QFileDialog::AnyFile );
2523 fd->setSelection (fio->getOriginalFilename());
2527 if ( fd->exec() == QDialog::Accepted )
2529 if (QFile (fd->selectedFile()).exists() )
2531 QMessageBox mb( "VYM",
2532 tr("The file ") + fd->selectedFile() +
2533 tr(" exists already. "
2534 "Do you want to overwrite it?"),
2535 QMessageBox::Warning,
2536 QMessageBox::Yes | QMessageBox::Default,
2537 QMessageBox::Cancel | QMessageBox::Escape,
2538 QMessageBox::QMessageBox::NoButton );
2540 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2541 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2544 case QMessageBox::Yes:
2547 case QMessageBox::Cancel:
2553 fio->save (fd->selectedFile(),fmt);
2558 void MapEditor::toggleFloatExport()
2561 (typeid(*selection) == typeid(FloatImageObj))||
2562 (typeid(*selection) == typeid(FloatObj)) )
2564 FloatImageObj *fio=((FloatImageObj*)(selection));
2565 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2569 void MapEditor::setFrame(const FrameType &t)
2572 (typeid(*selection) == typeid(BranchObj)) ||
2573 (typeid(*selection) == typeid(MapCenterObj)) )
2575 selection->setFrameType (t);
2576 mapCenter->reposition();
2577 selection->updateLink();
2581 void MapEditor::importDir(BranchObj *dst, QDir d)
2584 (typeid(*selection) == typeid(BranchObj)) ||
2585 (typeid(*selection) == typeid(MapCenterObj)) )
2589 // Traverse directories
2590 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2591 const QFileInfoList *dirlist = d.entryInfoList();
2592 QFileInfoListIterator itdir( *dirlist );
2595 while ( (fi = itdir.current()) != 0 )
2597 if (fi->fileName() != "." && fi->fileName() != ".." )
2600 bo=dst->getLastBranch();
2601 bo->setHeading (fi->fileName() );
2602 bo->setColor (QColor("blue"),false);
2604 if ( !d.cd(fi->fileName()) )
2605 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2615 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2616 const QFileInfoList *filelist = d.entryInfoList();
2617 QFileInfoListIterator itfile( *filelist );
2619 while ( (fi = itfile.current()) != 0 )
2622 bo=dst->getLastBranch();
2623 bo->setHeading (fi->fileName() );
2624 bo->setColor (QColor("black"),false);
2630 void MapEditor::importDir()
2633 (typeid(*selection) == typeid(BranchObj)) ||
2634 (typeid(*selection) == typeid(MapCenterObj)) )
2636 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2637 fd->setMode (QFileDialog::DirectoryOnly);
2638 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2639 fd->setCaption(tr("VYM - Choose directory structur to import"));
2643 if ( fd->exec() == QDialog::Accepted )
2645 BranchObj *bo=((BranchObj*)(selection));
2646 importDir (bo,QDir(fd->selectedFile()) );
2647 mapCenter->reposition();
2654 void MapEditor::testFunction()
2656 cout << "MapEditor::testFunction() called\n";
2659 void MapEditor::ensureSelectionVisible()
2661 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2663 if (selection->getOrientation() == OrientLeftOfCenter)
2664 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2666 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2667 ensureVisible (p.x(), p.y() );
2671 void MapEditor::updateViewCenter()
2673 // Update movingCenter, so that we can zoom comfortably later
2674 QRect rc = QRect( contentsX(), contentsY(),
2675 visibleWidth(), visibleHeight() );
2676 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2677 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2678 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2681 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2683 // Lineedits are already closed by preceding
2684 // mouseEvent, we don't need to close here.
2686 QPoint p = inverseWorldMatrix().map(e->pos());
2687 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2690 { // MapObj was found
2691 if (selection != lmo)
2693 // select the MapObj
2694 if (selection) selection->unselect();
2696 selection->select();
2702 if (typeid(*selection)==typeid(BranchObj) ||
2703 typeid(*selection)==typeid(MapCenterObj) )
2705 // Context Menu on branch or mapcenter
2707 branchContextMenu->popup(e->globalPos() );
2709 if (typeid(*selection)==typeid(FloatImageObj))
2711 // Context Menu on floatimage
2713 floatimageContextMenu->popup(e->globalPos() );
2717 { // No MapObj found, we are on the Canvas itself
2718 // Context Menu on Canvas
2720 canvasContextMenu->popup(e->globalPos() );
2724 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2726 // Finish open lineEdits
2727 if (lineedit) finishedLineEditNoSave();
2729 QPoint p = inverseWorldMatrix().map(e->pos());
2730 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2732 // Special case: CTRL is pressed, don't select anything
2733 if (e->state() & QMouseEvent::ControlButton)
2736 setCursor (pickColorCursor);
2741 { // MapObj was found
2742 if (selection != lmo)
2744 // select the MapObj
2745 if (selection) selection->unselect();
2747 selection->select();
2752 // Check, if systemFlag clicked
2753 if (typeid(*selection)==typeid(BranchObj) ||
2754 typeid(*selection)==typeid(MapCenterObj) )
2756 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
2757 if (!foname.isEmpty())
2759 // Do not move, if systemFlag clicked
2763 if (foname=="vymLink")
2765 mainWindow->editOpenVymLink();
2766 // tabWidget may change, better return now
2767 // before segfaulting...
2771 mainWindow->windowToggleNoteEditor();
2775 // Left Button Move Branches
2776 if (e->button() == QMouseEvent::LeftButton )
2778 movingObj=selection;
2779 movingObj_start.setX( p.x() - selection->x() );
2780 movingObj_start.setY( p.y() - selection->y() );
2782 // Middle Button Toggle Scroll
2783 // (On Mac OS X this won't work, but we still have
2784 // a button in the toolbar)
2785 if (e->button() == QMouseEvent::MidButton )
2791 { // No MapObj found, we are on the Canvas itself
2792 // Left Button move Pos of CanvasView
2793 if (e->button() == QMouseEvent::LeftButton )
2795 movingObj=NULL; // move Content not Obj
2796 movingObj_start=e->globalPos();
2797 movingCont_start=QPoint (contentsX(), contentsY() );
2798 movingVec=QPoint(0,0);
2799 setCursor(handOpenCursor);
2804 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
2806 // Move the selected MapObj
2807 if ( selection && movingObj)
2809 QPoint p = inverseWorldMatrix().map(e->pos());
2811 // Now move the selection, but add relative position (movingObj_start)
2813 // was chosen with mousepointer. (This avoids flickering resp. jumping
2814 // of selection back to absPos)
2816 LinkableMapObj *lmosel;
2817 lmosel = dynamic_cast <LinkableMapObj*> (selection);
2819 // Check if we could link
2820 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
2823 if (typeid(*selection) == typeid(FloatImageObj))
2827 FloatObj *fo=(FloatObj*)(selection);
2828 if (fo->getLinkStyle()==StyleUndef)
2830 fo->setLinkStyle(fo->getDefLinkStyle());
2831 fo->setLinkColor(fo->getParObj()->getLinkColor());
2833 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2837 // Relink float to new mapcenter or branch, if shift is pressed
2838 // Only relink, if selection really has a new parent
2839 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
2840 ( (typeid(*lmo)==typeid(BranchObj)) ||
2841 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
2842 ( lmo != fo->getParObj())
2845 if (typeid(*fo) == typeid(FloatImageObj))
2847 FloatImageObj *fio=(FloatImageObj*)(fo);
2848 ((BranchObj*)(lmo))->addFloatImage (fio);
2850 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2851 fio=((BranchObj*)(lmo))->getLastFloatImage();
2854 selection=(LinkableMapObj*)(fio);
2855 selection->select();
2856 movingObj=(MapObj*)(fio);
2857 // setLinkStyle calls updateLink, only set it once
2858 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
2859 fio->setLinkStyle (fio->getDefLinkStyle());
2862 // TODO if (typeid(*selection) == typeid(FloatTextObj))
2864 } else // selection != a FloatObj
2866 if (lmosel->getDepth()==0)
2868 if (e->state() == (LeftButton | !ShiftButton))
2869 // If mapCenter is moved, move all the rest by default, too.
2870 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2872 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2875 if (lmosel->getDepth()==1)
2877 // depth==1, mainbranch
2879 saveState(PartOfMap,lmosel);
2880 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2884 if (lmosel->getOrientation() == OrientLeftOfCenter)
2885 // Add width of bbox here, otherwise alignRelTo will cause jumping around
2886 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
2887 p.y()-movingObj_start.y() );
2889 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2891 // reposition subbranch
2892 lmosel->reposition();
2893 ensureSelectionVisible();
2895 if (lmo && (lmo!=selection) &&
2896 (typeid(*lmo) == typeid(BranchObj) ||
2897 (typeid(*lmo) == typeid(MapCenterObj) )
2900 if (e->state() & QMouseEvent::ControlButton)
2902 // Special case: CTRL to link below lmo
2903 lmosel->setParObjTmp (lmo,p,+1);
2905 else if (e->state() & QMouseEvent::ShiftButton)
2906 lmosel->setParObjTmp (lmo,p,-1);
2908 lmosel->setParObjTmp (lmo,p,0);
2911 if (lmo &&(lmo==selection))
2912 // Could link to myself (happens sometimes...)
2913 lmosel->unsetParObjTmp();
2915 // no Obj under selection, go back to original Parent
2916 lmosel->unsetParObjTmp();
2920 } // no FloatImageObj
2924 } // selection && moving_obj
2927 if (!movingObj && !pickingColor)
2929 QPoint p=e->globalPos();
2930 movingVec.setX(-p.x() + movingObj_start.x() );
2931 movingVec.setY(-p.y() + movingObj_start.y() );
2932 setContentsPos( movingCont_start.x() + movingVec.x(),
2933 movingCont_start.y() + movingVec.y());
2940 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
2942 LinkableMapObj *dst;
2943 // Have we been picking color?
2947 setCursor (ArrowCursor);
2948 // Check if we are over another branch
2949 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
2950 if (dst && selection)
2952 if (e->state() & QMouseEvent::ShiftButton)
2954 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
2955 ((BranchObj*)(selection))->setLinkColor ();
2959 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
2960 ((BranchObj*)(selection))->setLinkColor ();
2965 // Have we been moving something?
2966 if ( selection && movingObj )
2968 // Check if we are over another branch, but ignore
2969 // any found LMOs, which are FloatObjs
2970 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
2971 ((LinkableMapObj*)(selection)) );
2974 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
2979 // Now check, if we have been moving a branch
2980 if (typeid(*selection) == typeid(BranchObj) )
2982 // save the position in case we link to mapcenter
2983 QPoint savePos=QPoint (selection->x(),selection->y() );
2985 // Reset the temporary drawn link to the original one
2986 ((LinkableMapObj*)(selection))->unsetParObjTmp();
2992 // TODO we also could check, if dest and src are on same branch,
2993 // then it would be sufficient to saveState of this branch
2995 // FIXME better introduce BO::move to speed up and keep IDs
2996 copy(); // copy selection to clipboard
2997 cutNoSave(); // remove selection here
2999 selection->unselect();
3001 // Modifiers allow to insert above/below dst
3002 if (e->state() & QMouseEvent::ShiftButton)
3004 selection=pasteAtNoSave (((BranchObj*)(dst))->getNum());
3005 if (selection) selection->select();
3007 else if (e->state() & QMouseEvent::ControlButton)
3009 selection=pasteAtNoSave (((BranchObj*)(dst))->getNum()+1);
3010 if (selection) selection->select();
3014 selection=pasteNoSave();
3015 selection->select();
3016 if (dst->getDepth()==0)
3017 ((BranchObj*)(selection))->move (savePos);
3020 // Draw the original link, before selection was moved around
3021 mapCenter->reposition();
3023 // Finally resize canvas, if needed
3028 { // maybe we moved View: set old cursor
3029 setCursor (ArrowCursor);
3033 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3035 // Finish open lineEdits
3036 if (lineedit) finishedLineEditNoSave();
3038 if (e->button() == QMouseEvent::LeftButton )
3040 QPoint p = inverseWorldMatrix().map(e->pos());
3041 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3042 if (lmo) { // MapObj was found
3043 // First select the MapObj than edit heading
3044 if (selection) selection->unselect();
3046 selection->select();
3048 saveState(PartOfMap,selection);
3054 void MapEditor::resizeEvent (QResizeEvent* e)
3056 QCanvasView::resizeEvent( e );
3059 if (!fileName.isEmpty()) s=fileName;