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;
90 extern QAction *actionEditNoLink;
92 extern QAction* actionFormatPickColor;
93 extern QAction* actionFormatColorBranch;
94 extern QAction* actionFormatColorSubtree;
95 extern QAction *actionFormatLinkColorHint;
96 extern QAction *actionFormatBackColor;
97 extern QAction *actionFormatLinkColor;
99 extern QActionGroup* actionGroupModModes;
100 extern QAction* actionModModeColor;
101 extern QAction* actionModModeLink;
103 extern QActionGroup *actionGroupFormatFrameTypes;
104 extern QAction *actionFormatFrameNone;
105 extern QAction *actionFormatFrameRectangle;
107 extern QActionGroup *actionGroupFormatLinkStyles;
108 extern QAction *actionFormatLinkStyleLine;
109 extern QAction *actionFormatLinkStyleParabel;
110 extern QAction *actionFormatLinkStylePolyLine;
111 extern QAction *actionFormatLinkStylePolyParabel;
113 extern QAction *actionViewToggleNoteEditor;
115 extern QAction *actionSettingsAutoedit;
116 extern QAction *actionSettingsAutoselectHeading;
117 extern QAction *actionSettingsAutoselectText;
118 extern QAction *actionSettingsPasteNewHeading;
120 extern QPopupMenu *branchContextMenu;
121 extern QPopupMenu *branchLinksContextMenu;
122 extern QPopupMenu *floatimageContextMenu;
123 extern QPopupMenu *saveImageFormatMenu;
124 extern QPopupMenu *exportImageFormatMenu;
125 extern QPopupMenu *canvasContextMenu;
127 extern Settings settings;
130 ///////////////////////////////////////////////////////////////////////
131 ///////////////////////////////////////////////////////////////////////
132 MapEditor::MapEditor(
133 QWidget* parent, bool interactive, const char* name, WFlags f) :
134 QCanvasView(parent,name,f)
136 //cout << "Constructor ME "<<this<<endl;
138 mapCanvas = new QCanvas(1000,800);
139 mapCanvas->setAdvancePeriod(30);
141 setCanvas (mapCanvas);
143 setVScrollBarMode ( QScrollView::AlwaysOn );
144 setHScrollBarMode ( QScrollView::AlwaysOn );
146 // Now create the _global_ system flags _once_:
147 // (Later all OrnamentedObj copy from this
148 // and set their own canvas)
149 if (!systemFlagsDefault)
151 systemFlagsDefault = new FlagRowObj (mapCanvas);
152 systemFlagsDefault->setVisibility (false);
153 systemFlagsDefault->setName ("systemFlagsDef");
155 FlagObj *fo = new FlagObj (mapCanvas);
156 fo->load(QPixmap(flag_note_xpm));
158 fo->setToolTip(tr("Note"));
159 systemFlagsDefault->addFlag (fo); // makes deep copy
161 fo->load(QPixmap(flag_url_xpm));
163 fo->setToolTip(tr("WWW Document (external)"));
164 systemFlagsDefault->addFlag (fo);
166 fo->load(QPixmap(flag_vymlink_xpm));
167 fo->setName("vymLink");
168 fo->setToolTip(tr("Link to another vym map"));
169 systemFlagsDefault->addFlag (fo);
171 fo->load(QPixmap(flag_scrolled_right_xpm));
172 fo->setName("scrolledright");
173 fo->setToolTip(tr("subtree is scrolled"));
174 systemFlagsDefault->addFlag (fo);
176 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
177 fo->setName("tmpUnscrolledright");
178 fo->setToolTip(tr("subtree is temporary scrolled"));
179 systemFlagsDefault->addFlag (fo);
182 if (!standardFlagsDefault)
184 standardFlagsDefault = new FlagRowObj (mapCanvas);
185 standardFlagsDefault->setVisibility (false);
186 standardFlagsDefault->setName ("standardFlagsDef");
188 FlagObj *fo = new FlagObj (mapCanvas);
189 fo->load(QPixmap(flag_exclamationmark_xpm));
190 fo->setName("exclamationmark");
191 fo->setToolTip(tr("Take care!"));
192 standardFlagsDefault->addFlag (fo); // makes deep copy
194 fo->load(QPixmap(flag_questionmark_xpm));
195 fo->setName("questionmark");
196 fo->setToolTip(tr("Really?"));
197 standardFlagsDefault->addFlag (fo);
199 fo->load(QPixmap(flag_hook_green_xpm));
200 fo->setName("hook-green");
201 fo->setToolTip(tr("ok!"));
202 standardFlagsDefault->addFlag (fo);
204 fo->load(QPixmap(flag_cross_red_xpm));
205 fo->setName("cross-red");
206 fo->setToolTip(tr("Not ok!"));
207 standardFlagsDefault->addFlag (fo);
209 fo->load(QPixmap(flag_stopsign_xpm));
210 fo->setName("stopsign");
211 fo->setToolTip(tr("This won't work!"));
212 standardFlagsDefault->addFlag (fo);
214 fo->load(QPixmap(flag_smiley_good_xpm));
215 fo->setName("smiley-good");
216 fo->setToolTip(tr("Good"));
217 standardFlagsDefault->addFlag (fo);
219 fo->load(QPixmap(flag_smiley_sad_xpm));
220 fo->setName("smiley-sad");
221 fo->setToolTip(tr("Bad"));
222 standardFlagsDefault->addFlag (fo);
224 fo->load(QPixmap(flag_clock_xpm));
225 fo->setName("clock");
226 fo->setToolTip(tr("Time critical"));
227 standardFlagsDefault->addFlag (fo);
229 fo->load(QPixmap(flag_lamp_xpm));
231 fo->setToolTip(tr("Idea!"));
232 standardFlagsDefault->addFlag (fo);
234 fo->load(QPixmap(flag_arrow_up_xpm));
235 fo->setName("arrow-up");
236 fo->setToolTip(tr("Important"));
237 standardFlagsDefault->addFlag (fo);
239 fo->load(QPixmap(flag_arrow_down_xpm));
240 fo->setName("arrow-down");
241 fo->setToolTip(tr("Unimportant"));
242 standardFlagsDefault->addFlag (fo);
244 fo->load(QPixmap(flag_thumb_up_xpm));
245 fo->setName("thumb-up");
246 fo->setToolTip(tr("I like this"));
247 standardFlagsDefault->addFlag (fo);
249 fo->load(QPixmap(flag_thumb_down_xpm));
250 fo->setName("thumb-down");
251 fo->setToolTip(tr("I do not like this"));
252 standardFlagsDefault->addFlag (fo);
254 fo->load(QPixmap(flag_heart_xpm));
255 fo->setName("heart");
256 fo->setToolTip(tr("I just love... "));
257 standardFlagsDefault->addFlag (fo);
259 fo->load(QPixmap(flag_flash_xpm));
260 fo->setName("flash");
261 fo->setToolTip(tr("Dangerous"));
262 standardFlagsDefault->addFlag (fo);
264 fo->load(QPixmap(flag_lifebelt_xpm));
265 fo->setName("lifebelt");
266 fo->setToolTip(tr("This will help"));
267 standardFlagsDefault->addFlag (fo);
272 mapCenter = new MapCenterObj(mapCanvas);
273 mapCenter->setVisibility (true);
274 mapCenter->setMapEditor (this);
275 mapCenter->setHeading (tr("New Map"));
279 lineedit = new QLineEdit(this, "lineedit" );
280 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
283 actColor=black; setColor (actColor);
284 deflinkcolor=QColor (0,0,255);
285 linkcolorhint=DefaultColor;
286 linkstyle=StylePolyParabel;
287 mapCanvas->setBackgroundColor (white);
289 // Create bitmap cursors, patform dependant
290 #if defined(Q_OS_MACX)
291 #include "icons/cursorhandopen16.xpm"
292 #include "icons/cursorcolorpicker16.xpm"
293 QBitmap cb( 16, 16, chandopen, TRUE );
294 QBitmap cm( 16, 16, chandopenmask, TRUE );
295 handOpenCursor=QCursor ( cb, cm );
296 // set hot spot to tip of picker
297 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
299 #include "icons/cursorhandopen.xpm"
300 #include "icons/cursorcolorpicker.xpm"
302 QBitmap cb( 32, 32, chandopen, TRUE );
303 QBitmap cm( 32, 32, chandopenmask, TRUE );
304 handOpenCursor=QCursor ( cb, cm );
305 // set hot spot to tip of picker
306 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
326 // Initialize find routine
333 blockreposition=false;
334 isInteractive=interactive;
336 // Create temporary files
339 // Initially set movingCentre
342 mapCenter->reposition(); // for positioning heading
345 MapEditor::~MapEditor()
347 //cout <<"Destructor MapEditor\n";
348 if (isInteractive) delTmpDirs();
351 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
355 QColor MapEditor::color()
360 QColor MapEditor::backgroundColor()
362 return mapCanvas->backgroundColor();
365 MapCenterObj* MapEditor::getMapCenter()
370 QCanvas* MapEditor::getCanvas()
375 void MapEditor::adjustCanvasSize()
377 // To adjust the canvas to map, viewport size and position, we have to
378 // do some coordinate magic...
380 // Get rectangle of (scroll-)view.
381 // We want to be in canvas coords, so
382 // we map. Important if view is zoomed...
383 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
384 visibleWidth(), visibleHeight()) );
386 // Now we need the bounding box of view AND map to calc the correct canvas size.
387 // Why? Because if the map itself is moved out of view, the view has to be enlarged
388 // to avoid jumping aroung...
389 QRect map=mapCenter->getTotalBBox();
391 // right edge - left edge
392 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
393 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
396 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
397 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
400 // move the map on canvas (in order to not move it on screen) this is neccessary
401 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
402 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
403 // to scroll to an empty area of canvas to the left.
404 // b) if topleft corner of map left of or above topleft of canvas
408 if (cw > mapCanvas->width() )
410 if (map.x()<0) dx=-map.x();
412 if (cw < mapCanvas->width() )
413 dx=-min (view.x(),map.x());
414 if (ch > mapCanvas->height() )
416 if (map.y()<0) dy=-map.y();
418 if (ch < mapCanvas->height() )
420 dy=-min (view.y(),map.y());
422 // We really have to resize now. Let's go...
423 mapCanvas->resize (cw,ch);
424 if ( (dx!=0) || (dy!=0) )
426 mapCenter->moveAllBy(dx,dy);
427 mapCenter->reposition();
429 // scroll the view (in order to not move map on screen)
435 bool MapEditor::blockReposition()
437 return blockreposition;
440 void MapEditor::makeTmpDirs()
442 // Create unique temporary directories
443 char tmpdir[]="/tmp/vym-XXXXXX";
444 bakMapDir=mkdtemp(tmpdir);
445 makeSubDirs(bakMapDir);
446 // FIXME set permissions
447 // and maybe use QT method for portability
450 void MapEditor::delTmpDirs()
452 //FIXME delete tmp directory, better use QT methods here:
453 system ( "rm -rf "+ bakMapDir );
457 void MapEditor::makeSubDirs(const QString &s)
465 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, SaveMode savemode)
467 // tmpdir temporary directory to which data will be writte
468 // prefix mapname, which will be appended to images etc.
469 // writeflags Only write flags for "real" save of map, not undo
470 // offset offset of bbox of whole map in canvas.
471 // Needed for XML export
472 // completeMap if false, only vympart will be written, without
489 ls="StylePolyParabel";
493 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
495 if (linkcolorhint==HeadingColor)
496 colhint=attribut("linkColorHint","HeadingColor");
498 QString mapAttr=attribut("version",__VYM_VERSION__);
499 if (savemode==CompleteMap)
500 mapAttr+= attribut("author",mapCenter->getAuthor()) +
501 attribut("comment",mapCenter->getComment()) +
502 attribut("date",mapCenter->getDate()) +
503 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
504 attribut("linkStyle", ls ) +
505 attribut("linkColor", deflinkcolor.name() ) +
507 s+=beginElement("vymmap",mapAttr);
510 // Find the used flags while traversing the tree
511 standardFlagsDefault->resetUsedCounter();
513 // Build xml recursivly
514 if (savemode==CompleteMap)
515 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
518 if ( undoSelection &&
519 typeid(*undoSelection) == typeid(BranchObj) )
520 s+=((BranchObj*)(undoSelection))->saveToDir(tmpdir,prefix,offset);
523 // Save local settings
524 s+=settings.getXMLData (destPath);
528 s+=valueElement("select",selection->getSelectString());
531 s+=endElement("vymmap");
534 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
539 void MapEditor::saveState()
541 saveState (CompleteMap,NULL);
544 void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part)
546 // all binary data is saved in bakMapDir (created in Constructor)
547 // the xml data itself is kept in memory in backupXML
549 // For faster write/read of data, a part of the map can be
550 // written. Then the undoSelection will mark, which part of the
551 // map should be replaced if an undo is wanted later.
553 if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) )
555 // Writing a vympart only is useful for BranchObj
557 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
561 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap);
565 void MapEditor::finishedLineEditNoSave()
567 // This is called by finishedLineEdit or any MapEditor method,
568 // which wants to assure, that lineedits finish, before e.g. a branch is
571 // After calling LineEdit and using the clipboard, the
572 // focus is not any longer on the main widget, we
573 // have to restore it using parentWidget()->setFocus()
577 editingBO->setHeading(lineedit->text() );
579 lineedit->releaseKeyboard();
581 parentWidget()->setFocus();
582 mapCenter->reposition();
584 ensureSelectionVisible();
589 bool MapEditor::isDefault()
594 bool MapEditor::isUnsaved()
599 bool MapEditor::hasChanged()
604 void MapEditor::setChanged()
609 actionEditUndo->setEnabled (true);
610 actionFileSave->setEnabled (true);
614 void MapEditor::closeMap()
616 // Finish open lineEdits
617 if (lineedit) finishedLineEditNoSave();
619 // Unselect before disabling the toolbar actions
620 if (selection) selection->unselect();
628 void MapEditor::setFilePath(QString fname)
630 setFilePath (fname,fname);
633 void MapEditor::setFilePath(QString fname, QString destname)
639 // If fname is not an absolute path, complete it
640 filePath=QDir(fname).absPath();
641 fileDir=filePath.left (1+filePath.findRev ("/"));
643 // Set short name, too. Search from behind:
644 int i=fileName.findRev("/");
645 if (i>=0) fileName=fileName.remove (0,i+1);
647 // Forget the .vym (or .xml) for name of map
648 mapName=fileName.left(fileName.findRev(".",-1,true) );
651 QString MapEditor::getFilePath()
656 QString MapEditor::getFileName()
661 QString MapEditor::getMapName()
666 QString MapEditor::getDestPath()
671 int MapEditor::load (QString &fname, const LoadMode &lmode)
673 // Finish open lineEdits
674 if (lineedit) finishedLineEditNoSave();
680 if (selection) selection->unselect();
683 mapCenter->setMapEditor(this);
684 // (map state is set later at end of load...)
688 saveState(PartOfMap,selection);
692 mapBuilderHandler handler;
695 // I am paranoid: file should exist anyway
696 // according to check in mainwindow.
699 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
700 tr("Couldn't open map " +fname)+".");
704 blockreposition=true;
705 QXmlInputSource source( file);
706 QXmlSimpleReader reader;
707 reader.setContentHandler( &handler );
708 reader.setErrorHandler( &handler );
709 handler.setMapEditor( this );
710 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
711 handler.setLoadMode (lmode);
712 bool ok = reader.parse( source );
713 blockreposition=false;
717 mapCenter->reposition();
727 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
728 tr( handler.errorProtocol() ) );
730 // Still return "success": the map maybe at least
731 // partially read by the parser
738 int MapEditor::save (const SaveMode &savemode)
740 // Finish open lineEdits
741 if (lineedit) finishedLineEditNoSave();
745 // Create mapName and fileDir
746 makeSubDirs (fileDir);
750 fname=mapName+".xml";
752 // use name given by user, even if he chooses .doc
756 // Check if fname is writeable
757 QFile file( fileDir+fname);
758 if (!file.open( IO_WriteOnly ) )
760 QMessageBox::critical( 0, tr( "Critical Save Error" ),
761 tr("Couldn't write to ") +fileDir+fname);
767 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),savemode);
769 file.setName ( fileDir + fname);
770 if ( !file.open( IO_WriteOnly ) )
772 // This should neverever happen
773 QMessageBox::critical(0, tr("Critcal save error"),"MapEditor::save() Couldn't open "+file.name());
777 // Write it finally, and write in UTF8, no matter what
778 QTextStream ts( &file );
779 ts.setEncoding (QTextStream::UnicodeUTF8);
787 actionFileSave->setEnabled(false);
793 void MapEditor::setZipped (bool z)
798 bool MapEditor::saveZipped ()
803 void MapEditor::print()
805 // Finish open lineEdits
806 if (lineedit) finishedLineEditNoSave();
810 printer = new QPrinter;
811 printer->setColorMode (QPrinter::Color);
814 QRect totalBBox=mapCenter->getTotalBBox();
816 // Try to set orientation automagically
817 // Note: Interpretation of generated postscript is amibiguous, if
818 // there are problems with landscape mode, see
819 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
821 if (totalBBox.width()>totalBBox.height())
822 // recommend landscape
823 printer->setOrientation (QPrinter::Landscape);
825 // recommend portrait
826 printer->setOrientation (QPrinter::Portrait);
828 if ( printer->setup(this) )
829 // returns false, if printing is canceled
831 QPainter pp(printer);
833 // Don't print the visualisation of selection
834 LinkableMapObj *oldselection=NULL;
837 oldselection=selection;
838 selection->unselect();
841 // Handle sizes of map and paper:
843 // setWindow defines which part of the canvas will be transformed
844 // setViewport defines area on paper in device coordinates (dpi)
845 // e.g. (0,50,700,700) is upper part on A4
846 // see also /usr/lib/qt3/doc/html/coordsys.html
848 QPaintDeviceMetrics metrics (printer);
850 double paperAspect = (double)metrics.width() / (double)metrics.height();
851 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
853 QRect mapRect=mapCenter->getTotalBBox();
854 QCanvasRectangle *frame=NULL;
855 QCanvasText *footerFN=NULL;
856 QCanvasText *footerDate=NULL;
857 if (printFrame || printFooter)
862 // Print frame around map
863 mapRect.setRect (mapRect.x()-10, mapRect.y()-10,
864 mapRect.width()+20, mapRect.height()+20);
865 frame=new QCanvasRectangle (mapRect,mapCanvas);
866 frame->setBrush (QColor(white));
867 frame->setPen (QColor(black));
873 // Print footer below map
875 font.setPointSize(10);
876 footerFN=new QCanvasText (mapCanvas);
877 footerFN->setText ("VYM - " + fileName);
878 footerFN->setFont(font);
879 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
880 footerFN->setZ(Z_TEXT);
882 footerDate=new QCanvasText (mapCanvas);
883 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
884 footerDate->setFont(font);
885 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
886 footerDate->setZ(Z_TEXT);
888 mapRect.setRect (mapRect.x(), mapRect.y(),
889 mapRect.width(), mapRect.height()+20);
891 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height());
894 pp.setWindow (mapRect);
897 if (mapAspect>=paperAspect)
899 // Fit horizontally to paper width
900 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
903 // Fit vertically to paper height
904 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
907 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
909 // Delete Frame and footer
915 if (frame) delete (frame);
920 selection=oldselection;
926 QPixmap MapEditor::getPixmap()
928 QRect mapRect=mapCenter->getTotalBBox();
929 QPixmap pix (mapRect.size());
932 // Don't print the visualisation of selection
933 LinkableMapObj *oldselection=NULL;
936 oldselection=selection;
937 selection->unselect();
940 pp.setWindow (mapRect);
942 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
948 selection=oldselection;
955 void MapEditor::exportImage(QString fn)
957 // Finish open lineEdits
958 if (lineedit) finishedLineEditNoSave();
960 QPixmap pix (getPixmap());
964 void MapEditor::exportImage(QString fn, int item)
966 // Finish open lineEdits
967 if (lineedit) finishedLineEditNoSave();
969 QPixmap pix (getPixmap());
970 pix.save(fn, exportImageFormatMenu->text(item) );
973 void MapEditor::exportASCII()
975 // FIXME still experimental
976 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
977 fd->addFilter ("TXT (*.txt)");
978 fd->setCaption("VYM - Export (ASCII) (still experimental)");
979 fd->setMode( QFileDialog::AnyFile );
982 if ( fd->exec() == QDialog::Accepted )
984 if (QFile (fd->selectedFile()).exists() )
986 QMessageBox mb( "VYM",
987 tr("The file ") + fd->selectedFile() +
988 tr(" exists already. Do you want to overwrite it?"),
989 QMessageBox::Warning,
990 QMessageBox::Yes | QMessageBox::Default,
991 QMessageBox::Cancel | QMessageBox::Escape,
992 QMessageBox::NoButton );
994 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
995 mb.setButtonText( QMessageBox::No, tr("Cancel"));
999 case QMessageBox::Yes:
1001 if (!ex.setOutputDir ("out"))
1003 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1007 case QMessageBox::Cancel:
1014 ex.setPath (fd->selectedFile() );
1015 ex.setMapCenter(mapCenter);
1021 void MapEditor::exportXML(const QString &dir)
1023 // Create subdirectories
1026 // write to directory
1027 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,CompleteMap);
1030 file.setName ( dir + "/"+mapName+".xml");
1031 if ( !file.open( IO_WriteOnly ) )
1033 // This should neverever happen
1034 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1038 // Write it finally, and write in UTF8, no matter what
1039 QTextStream ts( &file );
1040 ts.setEncoding (QTextStream::UnicodeUTF8);
1044 // Now write image, too
1045 exportImage (dir+"/images/"+mapName+".png");
1048 void MapEditor::clear()
1052 selection->unselect();
1059 void MapEditor::undo()
1062 d.setPath(bakMapDir);
1065 // Finish open lineEdits
1066 if (lineedit) finishedLineEditNoSave();
1070 selection->unselect();
1074 mapBuilderHandler handler;
1075 QXmlInputSource source;
1076 source.setData(backupXML);
1077 QXmlSimpleReader reader;
1078 reader.setContentHandler( &handler );
1079 reader.setErrorHandler( &handler );
1080 handler.setMapEditor( this );
1081 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1084 selection=undoSelection;
1085 selection->select();
1086 handler.setLoadMode (ImportReplace);
1091 handler.setLoadMode (NewMap);
1093 blockreposition=true;
1094 bool ok = reader.parse( source );
1095 blockreposition=false;
1097 mapCenter->reposition();
1101 // This should never ever happen
1102 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1103 tr( handler.errorProtocol() )+" in "+backupXML );
1105 // Undo not longer available now
1106 actionEditUndo->setEnabled (false);
1107 undoSelection=false;
1112 QMessageBox::critical( 0, tr( "Critical Error" ),
1113 "Temporary directory " +bakMapDir +
1114 tr (" used for undo is gone. \n"
1115 "I will create a new one, but at the moment no undo is available.\n"
1116 "Maybe you want to reload your original data.\n\n"
1117 "Sorry for any inconveniences.") );
1122 void MapEditor::copy()
1124 // Finish open lineEdits
1125 if (lineedit) finishedLineEditNoSave();
1129 if (typeid(*selection) == typeid(BranchObj) )
1133 clipboardME->clear();
1134 clipboardME->getMapCenter()->addBranch();
1135 to=clipboardME->getMapCenter()->getLastBranch();
1138 from=(BranchObj*)(selection);
1141 // keep position relative to parent
1142 to->move2RelPos ( from->getRelPos());
1144 // select data in clipboard
1145 clipboardME->select ("bo:0");
1147 // repositioning makes testing nicer,
1148 // but is not needed usually:
1149 if (clipboardME->isVisible())
1151 clipboardME->getMapCenter()->reposition();
1154 clipboardME->hide();
1157 if (typeid(*selection) == typeid(FloatImageObj) )
1160 FloatImageObj* from;
1161 clipboardME->clear();
1162 clipboardME->getMapCenter()->addFloatImage();
1163 to=clipboardME->getMapCenter()->getLastFloatImage();
1166 from=(FloatImageObj*)(selection);
1169 // select data in clipboard
1170 clipboardME->select ("fi:0");
1172 // repositioning makes testing nicer,
1173 // but is not needed usually:
1174 if (clipboardME->isVisible())
1176 clipboardME->getMapCenter()->reposition();
1179 clipboardME->hide();
1185 LinkableMapObj* MapEditor::pasteNoSave()
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))
1204 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1207 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1208 (typeid(*selection) == typeid (BranchObj) ||
1209 typeid(*selection)==typeid(MapCenterObj)) )
1210 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1216 void MapEditor::cutNoSave()
1218 // Finish open lineEdits
1219 if (lineedit) finishedLineEditNoSave();
1223 if (selection != NULL) {
1224 if (typeid(*selection) == typeid(BranchObj) )
1226 bo=(BranchObj*)(selection);
1227 par=(BranchObj*)(bo->getParObj());
1230 par->removeBranch(bo);
1232 selection->select();
1234 if (typeid(*selection) == typeid(FloatImageObj) )
1236 FloatImageObj* fio=(FloatImageObj*)(selection);
1237 par=(BranchObj*)(fio->getParObj());
1240 par->removeFloatImage(fio);
1242 selection->select();
1247 void MapEditor::paste()
1250 saveState(PartOfMap,selection);
1252 mapCenter->reposition();
1256 void MapEditor::cut()
1259 saveState(PartOfMap,selection->getParObj());
1262 mapCenter->reposition();
1266 void MapEditor::moveBranchUp()
1268 // Finish open lineEdits
1269 if (lineedit) finishedLineEditNoSave();
1273 if (typeid(*selection) == typeid(BranchObj) )
1276 saveState(PartOfMap,selection->getParObj());
1277 bo=(BranchObj*)(selection);
1278 par=(BranchObj*)(bo->getParObj());
1279 selection->unselect();
1280 selection=par->moveBranchUp (bo);
1281 selection->select();
1282 mapCenter->reposition();
1283 ensureSelectionVisible();
1287 void MapEditor::moveBranchDown()
1289 // Finish open lineEdits
1290 if (lineedit) finishedLineEditNoSave();
1294 if (typeid(*selection) == typeid(BranchObj) )
1297 saveState(PartOfMap,selection->getParObj());
1298 bo=(BranchObj*)(selection);
1299 par=(BranchObj*)(bo->getParObj());
1300 selection->unselect();
1301 selection=par->moveBranchDown(bo);
1302 selection->select();
1303 mapCenter->reposition();
1304 ensureSelectionVisible();
1308 void MapEditor::editHeading()
1310 // Finish open lineEdits
1311 if (lineedit) finishedLineEditNoSave();
1314 (typeid(*selection) == typeid(BranchObj) ||
1315 typeid(*selection) == typeid(MapCenterObj) ) )
1318 saveState(PartOfMap,selection);
1320 ensureSelectionVisible();
1321 BranchObj *bo=(BranchObj*)(selection);
1322 editingBO=(BranchObj*)(selection);
1323 QPoint p = worldMatrix().map(QPoint (bo->x(),bo->y()));
1324 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1325 QString s=bo->getHeading();
1326 lineedit->setText(s);
1327 lineedit->setCursorPosition(1);
1328 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1329 lineedit->selectAll();
1332 lineedit->grabKeyboard();
1333 lineedit->setFocus();
1338 void MapEditor::addNewBranch(int pos)
1340 // Finish open lineEdits
1341 if (lineedit) finishedLineEditNoSave();
1344 (typeid(*selection) == typeid(BranchObj) ||
1345 typeid(*selection) == typeid(MapCenterObj) ) )
1348 saveState(PartOfMap,selection);
1350 BranchObj* bo1 = (BranchObj*) (selection);
1351 bool wasScrolled=false;
1352 BranchObj *newbo=NULL;
1355 // save scroll state. If scrolled, automatically select
1356 // new branch in order to tmp unscroll parent...
1357 wasScrolled=bo1->isScrolled();
1358 newbo=bo1->addBranch();
1361 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1365 // add above selection
1366 newbo=parbo->insertBranch(bo1->getNum());
1368 // add below selection
1369 newbo=parbo->insertBranch(bo1->getNum()+1);
1371 // This should not happen...
1376 LinkableMapObj *oldselection=selection;
1378 mapCenter->reposition();
1380 if (actionSettingsAutoedit->isOn() ||
1381 actionSettingsAutoselectHeading->isOn() )
1383 selection->unselect();
1385 selection->select();
1386 if (actionSettingsPasteNewHeading->isOn() )
1388 BranchObj *bo2= (BranchObj*)(selection);
1389 bo2->setHeading("");
1391 if (actionSettingsAutoedit->isOn() )
1393 if (!actionSettingsAutoselectHeading->isOn()
1396 selection->unselect();
1397 selection=oldselection;
1398 selection->select();
1404 void MapEditor::deleteSelection()
1406 // Finish open lineEdits
1407 if (lineedit) finishedLineEditNoSave();
1409 if (selection && typeid(*selection) ==typeid(BranchObj) )
1412 saveState(PartOfMap,selection->getParObj());
1413 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1414 BranchObj* par=(BranchObj*)(bo->getParObj());
1417 par->removeBranch(bo);
1419 selection->select();
1420 ensureSelectionVisible();
1421 mapCenter->reposition();
1424 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1427 saveState(PartOfMap,selection->getParObj());
1428 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1429 BranchObj* par=(BranchObj*)(fio->getParObj());
1432 par->removeFloatImage(fio);
1434 selection->select();
1435 ensureSelectionVisible();
1436 mapCenter->reposition();
1441 LinkableMapObj* MapEditor::getSelection()
1446 LinkableMapObj* MapEditor::findObj (QString s)
1448 LinkableMapObj *lmo=mapCenter;
1452 while (!s.isEmpty() )
1454 part=s.section(",",0,0);
1456 num=part.right(part.length() - 3);
1463 lmo=mapCenter->getBranchNum (num.toUInt());
1466 lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt());
1469 lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
1472 if (s.contains(","))
1473 s=s.right(s.length() - part.length() -1 );
1480 bool MapEditor::select (const QString &s)
1482 LinkableMapObj *lmo=findObj(s);
1484 // Finally select the found object
1487 if (selection) selection->unselect();
1489 selection->select();
1491 ensureSelectionVisible();
1497 void MapEditor::unselect()
1501 selectionLast=selection;
1502 selection->unselect();
1507 void MapEditor::reselect()
1511 selection=selectionLast;
1512 selection->select();
1517 void MapEditor::selectNextBranch()
1519 // Increase number of branch
1522 QString s=selection->getSelectString();
1528 part=s.section(",",-1);
1530 num=part.right(part.length() - 3);
1532 s=s.left (s.length() -num.length());
1535 num=QString ("%1").arg(num.toUInt()+1);
1539 // Try to select this one
1540 if (select (s)) return;
1542 // We have no direct successor,
1543 // try to increase the parental number in order to
1544 // find a successor with same depth
1546 int d=selection->getDepth();
1551 while (!found && d>0)
1553 s=s.section (",",0,d-1);
1554 // replace substring of current depth in s with "1"
1555 part=s.section(",",-1);
1557 num=part.right(part.length() - 3);
1561 // increase number of parent
1562 num=QString ("%1").arg(num.toUInt()+1);
1563 s=s.section (",",0,d-2) + ","+ typ+num;
1566 // Special case, look at orientation
1567 if (selection->getOrientation()==OrientRightOfCenter)
1568 num=QString ("%1").arg(num.toUInt()+1);
1570 num=QString ("%1").arg(num.toUInt()-1);
1575 // pad to oldDepth, select the first branch for each depth
1576 for (i=d;i<oldDepth;i++)
1581 if ( ((BranchObj*)(selection))->countBranches()>0)
1589 // try to select the freshly built string
1597 void MapEditor::selectPrevBranch()
1599 // Decrease number of branch
1602 QString s=selection->getSelectString();
1608 part=s.section(",",-1);
1610 num=part.right(part.length() - 3);
1612 s=s.left (s.length() -num.length());
1615 num=QString ("%1").arg(num.toUInt()-1);
1619 // Try to select this one
1620 if (select (s)) return;
1622 // We have no direct precessor,
1623 // try to decrease the parental number in order to
1624 // find a precessor with same depth
1626 int d=selection->getDepth();
1631 while (!found && d>0)
1633 s=s.section (",",0,d-1);
1634 // replace substring of current depth in s with "1"
1635 part=s.section(",",-1);
1637 num=part.right(part.length() - 3);
1641 // decrease number of parent
1642 num=QString ("%1").arg(num.toUInt()-1);
1643 s=s.section (",",0,d-2) + ","+ typ+num;
1646 // Special case, look at orientation
1647 if (selection->getOrientation()==OrientRightOfCenter)
1648 num=QString ("%1").arg(num.toUInt()-1);
1650 num=QString ("%1").arg(num.toUInt()+1);
1655 // pad to oldDepth, select the last branch for each depth
1656 for (i=d;i<oldDepth;i++)
1660 if ( ((BranchObj*)(selection))->countBranches()>0)
1661 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1668 // try to select the freshly built string
1676 void MapEditor::selectUpperBranch()
1678 // Finish open lineEdits
1679 if (lineedit) finishedLineEditNoSave();
1683 if (typeid(*selection) == typeid(BranchObj))
1685 if (selection->getOrientation()==OrientRightOfCenter)
1688 if (selection->getDepth()==1)
1696 void MapEditor::selectLowerBranch()
1698 // Finish open lineEdits
1699 if (lineedit) finishedLineEditNoSave();
1703 if (typeid(*selection) == typeid(BranchObj))
1705 if (selection->getOrientation()==OrientRightOfCenter)
1708 if (selection->getDepth()==1)
1717 void MapEditor::selectLeftBranch()
1719 // Finish open lineEdits
1720 if (lineedit) finishedLineEditNoSave();
1726 if (typeid(*selection) == typeid(MapCenterObj))
1728 par= (BranchObj*) (selection);
1729 bo=par->getLastSelectedBranch();
1732 // Workaround for reselecting on left and right side
1733 if (bo->getOrientation()==OrientRightOfCenter)
1735 bo=par->getLastBranch();
1741 selection->select();
1743 ensureSelectionVisible();
1748 par=(BranchObj*)(selection->getParObj());
1749 if (selection->getOrientation()==OrientRightOfCenter)
1751 if (typeid(*selection) == typeid(BranchObj) ||
1752 typeid(*selection) == typeid(FloatImageObj))
1754 selection->unselect();
1756 selection->select();
1758 ensureSelectionVisible();
1762 if (typeid(*selection) == typeid(BranchObj) )
1764 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1767 selection->unselect();
1769 selection->select();
1771 ensureSelectionVisible();
1779 void MapEditor::selectRightBranch()
1781 // Finish open lineEdits
1782 if (lineedit) finishedLineEditNoSave();
1789 if (typeid(*selection) == typeid(MapCenterObj))
1791 par= (BranchObj*) (selection);
1792 bo=par->getLastSelectedBranch();
1795 // Workaround for relecting on left and right side
1796 if (bo->getOrientation()==OrientLeftOfCenter)
1797 bo=par->getFirstBranch();
1802 selection->select();
1803 ensureSelectionVisible();
1808 par=(BranchObj*)(selection->getParObj());
1809 if (selection->getOrientation()==OrientLeftOfCenter)
1811 if (typeid(*selection) == typeid(BranchObj) ||
1812 typeid(*selection) == typeid(FloatImageObj))
1814 selection->unselect();
1816 selection->select();
1818 ensureSelectionVisible();
1822 if (typeid(*selection) == typeid(BranchObj) )
1824 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1827 selection->unselect();
1829 selection->select();
1831 ensureSelectionVisible();
1839 void MapEditor::selectFirstBranch()
1841 // Finish open lineEdits
1842 if (lineedit) finishedLineEditNoSave();
1848 if (typeid(*selection) == typeid(BranchObj))
1850 bo1= (BranchObj*) (selection);
1851 par=(BranchObj*)(bo1->getParObj());
1852 bo2=par->getFirstBranch();
1856 selection->select();
1857 ensureSelectionVisible();
1864 void MapEditor::selectLastBranch()
1866 // Finish open lineEdits
1867 if (lineedit) finishedLineEditNoSave();
1873 if (typeid(*selection) == typeid(BranchObj))
1875 bo1= (BranchObj*) (selection);
1876 par=(BranchObj*)(bo1->getParObj());
1877 bo2=par->getLastBranch();
1881 selection->select();
1882 ensureSelectionVisible();
1889 void MapEditor::setColor(QColor c)
1894 void MapEditor::selectBackgroundColor()
1896 // Finish open lineEdits
1897 if (lineedit) finishedLineEditNoSave();
1899 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
1900 if ( !col.isValid() ) return;
1901 setBackgroundColor( col );
1905 void MapEditor::setBackgroundColor(QColor c)
1907 mapCanvas->setBackgroundColor (c);
1910 QColor MapEditor::pickColor()
1914 if (typeid(*selection) == typeid(BranchObj) ||
1915 typeid(*selection) == typeid(MapCenterObj))
1917 BranchObj *bo=(BranchObj*)(selection);
1918 actColor=bo->getColor();
1924 void MapEditor::colorItem()
1928 if (typeid(*selection) == typeid(BranchObj) ||
1929 typeid(*selection) == typeid(MapCenterObj))
1932 saveState(PartOfMap,selection);
1933 BranchObj *bo=(BranchObj*)(selection);
1934 bo->setColor(actColor, false); // color links, color childs
1939 void MapEditor::colorBranch()
1943 if (typeid(*selection) == typeid(BranchObj) ||
1944 typeid(*selection) == typeid(MapCenterObj))
1947 saveState(PartOfMap,selection);
1948 BranchObj *bo=(BranchObj*)(selection);
1949 bo->setColor(actColor, true); // color links, color childs
1955 void MapEditor::toggleStandardFlag(QString f)
1960 saveState(PartOfMap,selection);
1961 ((BranchObj*)(selection))->toggleStandardFlag (f);
1965 void MapEditor::setViewCenter()
1967 // transform to CanvasView Coord:
1968 QPoint p=worldMatrix().map(movingCenter);
1969 center ( p.x(), p.y());
1973 BranchObj* MapEditor::findText (QString s, bool cs)
1976 { // Nothing found or new find process
1978 // nothing found, start again
1980 itFind=mapCenter->first();
1982 bool searching=true;
1983 bool foundNote=false;
1984 while (searching && !EOFind)
1988 // Searching in Note
1989 if (itFind->getNote().contains(s,cs))
1991 if (selection!=itFind)
1993 if (selection) ((BranchObj*)(selection))->unselect();
1995 selection->select();
1997 ensureSelectionVisible();
1999 if (textEditor->findText(s,cs))
2005 // Searching in Heading
2006 if (searching && itFind->getHeading().contains (s,cs) )
2008 if (selection) ((BranchObj*)(selection))->unselect();
2010 selection->select();
2012 ensureSelectionVisible();
2018 itFind=itFind->next();
2019 if (!itFind) EOFind=true;
2025 return (BranchObj*)(selection);
2030 void MapEditor::findReset()
2031 { // Necessary if text to find changes during a find process
2036 void MapEditor::openURL()
2040 if (typeid(*selection) == typeid(BranchObj) ||
2041 typeid(*selection) == typeid(MapCenterObj))
2043 QString url=((BranchObj*)(selection))->getURL();
2045 QProcess *proc = new QProcess( this );
2047 #if !defined(Q_OS_MACX)
2048 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2050 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2051 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2054 proc->addArgument( url);
2056 if ( !proc->start() )
2058 if (mainWindow->settingsURL() )
2064 void MapEditor::editURL()
2066 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2067 typeid(*selection) == typeid(MapCenterObj)) )
2070 QString text = QInputDialog::getText(
2071 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2072 ((BranchObj*)(selection))->getURL(), &ok, this );
2075 // user entered something and pressed OK
2076 ((BranchObj*)(selection))->setURL (text);
2083 void MapEditor::editHeading2URL()
2085 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2086 typeid(*selection) == typeid(MapCenterObj)) )
2088 BranchObj *b=(BranchObj*)(selection);
2089 b->setURL (b->getHeading());
2095 void MapEditor::editBugzilla2URL()
2097 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2098 typeid(*selection) == typeid(MapCenterObj)) )
2100 BranchObj *b=(BranchObj*)(selection);
2101 b->setURL ("http://bugzilla.suse.de/show_bug.cgi?id="+b->getHeading());
2107 void MapEditor::editVymLink()
2109 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2110 typeid(*selection) == typeid(MapCenterObj)) )
2112 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2113 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2114 fd->setCaption(tr("VYM - Link to another map"));
2115 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2116 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2120 if ( fd->exec() == QDialog::Accepted )
2121 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2123 mapCenter->reposition();
2130 void MapEditor::deleteVymLink()
2132 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2133 typeid(*selection) == typeid(MapCenterObj)) )
2135 ((BranchObj*)(selection))->setVymLink ("" );
2137 mapCenter->reposition();
2144 QString MapEditor::getVymLink()
2146 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2147 typeid(*selection) == typeid(MapCenterObj)) )
2149 return ((BranchObj*)(selection))->getVymLink();
2155 void MapEditor::editMapInfo()
2157 ExtraInfoDialog dia;
2158 dia.setMapName (getFileName() );
2159 dia.setAuthor (mapCenter->getAuthor() );
2160 dia.setComment(mapCenter->getComment() );
2165 QCanvasItemList l=canvas()->allItems();
2166 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2168 stats+=QString ("%1 items on canvas\n").arg (i,6);
2174 bo=mapCenter->first();
2177 if (!bo->getNote().isEmpty() ) n++;
2178 f+= bo->countFloatImages();
2182 stats+=QString ("%1 branches\n").arg (b-1,6);
2183 stats+=QString ("%1 notes\n").arg (n,6);
2184 stats+=QString ("%1 images\n").arg (f,6);
2185 dia.setStats (stats);
2187 // Finally show dialog
2188 if (dia.exec() == QDialog::Accepted)
2190 mapCenter->setAuthor (dia.getAuthor() );
2191 mapCenter->setComment (dia.getComment() );
2196 void MapEditor::updateActions()
2198 if (getLinkColorHint()==HeadingColor)
2199 actionFormatLinkColorHint->setOn(true);
2201 actionFormatLinkColorHint->setOn(false);
2206 actionFormatLinkStyleLine->setOn(true);
2209 actionFormatLinkStyleParabel->setOn(true);
2212 actionFormatLinkStylePolyLine->setOn(true);
2214 case StylePolyParabel:
2215 actionFormatLinkStylePolyParabel->setOn(true);
2221 QPixmap pix( 16, 16 );
2222 pix.fill( mapCanvas->backgroundColor() );
2223 actionFormatBackColor->setIconSet( pix );
2224 pix.fill( deflinkcolor );
2225 actionFormatLinkColor->setIconSet( pix );
2227 actionEditUndo->setEnabled( mapChanged );
2228 actionFileSave->setEnabled( mapUnsaved );
2232 if ( (typeid(*selection) == typeid(BranchObj)) ||
2233 (typeid(*selection) == typeid(MapCenterObj)) )
2235 BranchObj *bo=(BranchObj*)(selection);
2236 // Take care of links
2237 if (bo->countLinks()==0)
2239 branchLinksContextMenu->clear();
2240 branchLinksContextMenu->insertItem ("No link available");
2246 branchLinksContextMenu->clear();
2247 for (int i=0; i<=bo->countLinks();i++)
2249 bot=bo->linkTargetAt(i);
2252 s=bot->getHeading();
2255 branchLinksContextMenu->insertItem (s);
2260 standardFlagsDefault->setEnabled (true);
2262 if ( bo->getURL().isEmpty() )
2263 actionEditOpenURL->setEnabled (false);
2265 actionEditOpenURL->setEnabled (true);
2266 actionEditURL->setEnabled (true);
2267 actionEditHeading2URL->setEnabled (true);
2268 actionEditBugzilla2URL->setEnabled (true);
2270 if ( bo->getVymLink().isEmpty() )
2272 actionEditOpenVymLink->setEnabled (false);
2273 actionEditDeleteVymLink->setEnabled (false);
2276 actionEditOpenVymLink->setEnabled (true);
2277 actionEditDeleteVymLink->setEnabled (true);
2279 actionEditVymLink->setEnabled (true);
2281 actionEditCopy->setEnabled (true);
2282 actionEditCut->setEnabled (true);
2283 actionEditPaste->setEnabled (true);
2284 actionEditMoveUp->setEnabled (true);
2285 actionEditMoveDown->setEnabled (true);
2286 actionEditToggleScroll->setEnabled (true);
2287 actionEditHeading->setEnabled (true);
2288 actionEditDelete->setEnabled (true);
2289 actionEditAddBranch->setEnabled (true);
2290 actionEditAddBranchAbove->setEnabled (true);
2291 actionEditAddBranchBelow->setEnabled (true);
2292 actionEditImportAdd->setEnabled (true);
2293 actionEditImportReplace->setEnabled (true);
2294 actionEditSaveBranch->setEnabled (true);
2295 actionEditSelectFirst->setEnabled (true);
2296 actionEditSelectLast->setEnabled (true);
2297 actionEditToggleFloatExport->setEnabled (false);
2298 actionFormatPickColor->setEnabled (true);
2299 actionFormatColorBranch->setEnabled (true);
2300 actionFormatColorSubtree->setEnabled (true);
2301 switch (selection->getFrameType())
2304 actionFormatFrameNone->setOn(true);
2307 actionFormatFrameRectangle->setOn(true);
2313 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2315 standardFlagsDefault->setEnabled (false);
2317 actionEditOpenURL->setEnabled (false);
2318 actionEditURL->setEnabled (false);
2319 actionEditHeading2URL->setEnabled (false);
2320 actionEditBugzilla2URL->setEnabled (false);
2321 actionEditOpenVymLink->setEnabled (false);
2322 actionEditVymLink->setEnabled (false);
2323 actionEditDeleteVymLink->setEnabled (false);
2325 actionEditCopy->setEnabled (true);
2326 actionEditCut->setEnabled (true);
2327 actionEditPaste->setEnabled (false); //FIXME
2328 actionEditMoveUp->setEnabled (false);
2329 actionEditMoveDown->setEnabled (false);
2330 actionEditToggleScroll->setEnabled (false);
2331 actionEditHeading->setEnabled (false);
2332 actionEditDelete->setEnabled (true);
2333 actionEditAddBranch->setEnabled (false);
2334 actionEditAddBranchAbove->setEnabled (false);
2335 actionEditAddBranchBelow->setEnabled (false);
2336 actionEditImportAdd->setEnabled (false);
2337 actionEditSaveBranch->setEnabled (false);
2338 actionEditImportReplace->setEnabled (false);
2339 actionEditSelectFirst->setEnabled (false);
2340 actionEditSelectLast->setEnabled (false);
2341 actionEditToggleFloatExport->setOn
2342 ( ((FloatImageObj*)(selection))->getFloatExport() );
2343 actionFormatPickColor->setEnabled (false);
2344 actionFormatColorBranch->setEnabled (false);
2345 actionFormatColorSubtree->setEnabled (false);
2350 standardFlagsDefault->setEnabled (false);
2352 actionEditCopy->setEnabled (false);
2353 actionEditCut->setEnabled (false);
2354 actionEditPaste->setEnabled (false);
2355 actionEditMoveUp->setEnabled (false);
2356 actionEditMoveDown->setEnabled (false);
2357 actionEditToggleScroll->setEnabled (false);
2358 actionEditOpenURL->setEnabled (false);
2359 actionEditURL->setEnabled (false);
2360 actionEditOpenVymLink->setEnabled (false);
2361 actionEditVymLink->setEnabled (false);
2362 actionEditDeleteVymLink->setEnabled (false);
2363 actionEditHeading2URL->setEnabled (false);
2364 actionEditBugzilla2URL->setEnabled (false);
2365 actionEditHeading->setEnabled (false);
2366 actionEditDelete->setEnabled (false);
2367 actionEditAddBranch->setEnabled (false);
2368 actionEditAddBranchAbove->setEnabled (false);
2369 actionEditAddBranchBelow->setEnabled (false);
2370 actionEditSaveBranch->setEnabled (false);
2371 actionEditImportReplace->setEnabled (false);
2372 actionEditSelectFirst->setEnabled (false);
2373 actionEditSelectLast->setEnabled (false);
2374 actionEditToggleFloatExport->setEnabled (false);
2375 actionFormatPickColor->setEnabled (false);
2376 actionFormatColorBranch->setEnabled (false);
2377 actionFormatColorSubtree->setEnabled (false);
2381 void MapEditor::setLinkStyle (LinkStyle ls)
2386 bo=mapCenter->first();
2390 bo->setLinkStyle(bo->getDefLinkStyle());
2397 LinkStyle MapEditor::getLinkStyle ()
2402 void MapEditor::setLinkColor(QColor c)
2408 void MapEditor::setLinkColorHint()
2410 // called from setLinkColorHint(lch) or at end of parse
2412 bo=mapCenter->first();
2420 void MapEditor::setLinkColorHint(LinkColorHint lch)
2426 void MapEditor::toggleLinkColorHint()
2428 if (linkcolorhint==HeadingColor)
2429 linkcolorhint=DefaultColor;
2431 linkcolorhint=HeadingColor;
2433 bo=mapCenter->first();
2441 LinkColorHint MapEditor::getLinkColorHint()
2443 return linkcolorhint;
2446 QColor MapEditor::getDefLinkColor()
2448 return deflinkcolor;
2451 void MapEditor::selectLinkColor()
2453 // Finish open lineEdits
2454 if (lineedit) finishedLineEditNoSave();
2456 QColor col = QColorDialog::getColor( deflinkcolor, this );
2457 if ( !col.isValid() ) return;
2458 setLinkColor( col );
2462 void MapEditor::toggleScroll()
2464 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2466 BranchObj *bo=((BranchObj*)(selection));
2467 if (bo->countBranches()==0) return;
2468 if (bo->getDepth()==0) return;
2470 saveState(PartOfMap,selection);
2477 void MapEditor::unScrollAll()
2480 bo=mapCenter->first();
2483 if (bo->isScrolled()) bo->toggleScroll();
2488 void MapEditor::loadFloatImage ()
2491 (typeid(*selection) == typeid(BranchObj)) ||
2492 (typeid(*selection) == typeid(MapCenterObj)) )
2494 BranchObj *bo=((BranchObj*)(selection));
2496 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2497 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2498 ImagePreview *p =new ImagePreview (fd);
2499 fd->setContentsPreviewEnabled( TRUE );
2500 fd->setContentsPreview( p, p );
2501 fd->setPreviewMode( QFileDialog::Contents );
2502 fd->setCaption(tr("vym - Load image"));
2503 fd->setDir (lastImageDir);
2507 if ( fd->exec() == QDialog::Accepted )
2510 saveState(PartOfMap,selection);
2511 QString fn=fd->selectedFile();
2512 lastImageDir=fn.left(fn.findRev ("/"));
2513 bo->addFloatImage();
2514 // FIXME check if load was successful
2515 bo->getLastFloatImage()->load(fn);
2516 bo->getLastFloatImage()->setOriginalFilename(fn);
2517 mapCenter->reposition();
2524 void MapEditor::saveFloatImage (int item)
2527 (typeid(*selection) == typeid(FloatImageObj)) )
2529 FloatImageObj *fio=((FloatImageObj*)(selection));
2530 const char* fmt = saveImageFormatMenu->text(item);
2532 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2533 fd->addFilter ("PNG (*.png)");
2534 fd->addFilter ("BMP (*.bmp)");
2535 fd->addFilter ("XBM (*.xbm)");
2536 fd->addFilter ("JPG (*.jpg)");
2537 fd->addFilter ("XPM (*.xpm)");
2538 fd->addFilter ("GIF (*.gif)");
2539 fd->addFilter ("PNM (*.pnm)");
2540 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2541 fd->setCaption(tr("vym - Save image as ") + fmt);
2542 fd->setMode( QFileDialog::AnyFile );
2543 fd->setSelection (fio->getOriginalFilename());
2547 if ( fd->exec() == QDialog::Accepted )
2549 if (QFile (fd->selectedFile()).exists() )
2551 QMessageBox mb( "VYM",
2552 tr("The file ") + fd->selectedFile() +
2553 tr(" exists already. "
2554 "Do you want to overwrite it?"),
2555 QMessageBox::Warning,
2556 QMessageBox::Yes | QMessageBox::Default,
2557 QMessageBox::Cancel | QMessageBox::Escape,
2558 QMessageBox::QMessageBox::NoButton );
2560 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2561 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2564 case QMessageBox::Yes:
2567 case QMessageBox::Cancel:
2573 fio->save (fd->selectedFile(),fmt);
2578 void MapEditor::toggleFloatExport()
2581 (typeid(*selection) == typeid(FloatImageObj))||
2582 (typeid(*selection) == typeid(FloatObj)) )
2584 FloatImageObj *fio=((FloatImageObj*)(selection));
2585 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2589 void MapEditor::setFrame(const FrameType &t)
2592 (typeid(*selection) == typeid(BranchObj)) ||
2593 (typeid(*selection) == typeid(MapCenterObj)) )
2595 selection->setFrameType (t);
2596 mapCenter->reposition();
2597 selection->updateLink();
2601 void MapEditor::importDir(BranchObj *dst, QDir d)
2604 (typeid(*selection) == typeid(BranchObj)) ||
2605 (typeid(*selection) == typeid(MapCenterObj)) )
2609 // Traverse directories
2610 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2611 const QFileInfoList *dirlist = d.entryInfoList();
2612 QFileInfoListIterator itdir( *dirlist );
2615 while ( (fi = itdir.current()) != 0 )
2617 if (fi->fileName() != "." && fi->fileName() != ".." )
2620 bo=dst->getLastBranch();
2621 bo->setHeading (fi->fileName() );
2622 bo->setColor (QColor("blue"),false);
2624 if ( !d.cd(fi->fileName()) )
2625 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2635 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2636 const QFileInfoList *filelist = d.entryInfoList();
2637 QFileInfoListIterator itfile( *filelist );
2639 while ( (fi = itfile.current()) != 0 )
2642 bo=dst->getLastBranch();
2643 bo->setHeading (fi->fileName() );
2644 bo->setColor (QColor("black"),false);
2650 void MapEditor::importDir()
2653 (typeid(*selection) == typeid(BranchObj)) ||
2654 (typeid(*selection) == typeid(MapCenterObj)) )
2656 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2657 fd->setMode (QFileDialog::DirectoryOnly);
2658 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2659 fd->setCaption(tr("VYM - Choose directory structur to import"));
2663 if ( fd->exec() == QDialog::Accepted )
2665 BranchObj *bo=((BranchObj*)(selection));
2666 importDir (bo,QDir(fd->selectedFile()) );
2667 mapCenter->reposition();
2674 void MapEditor::followLink(int i)
2676 cout << "ME::followLink "<<i<<endl;
2677 BranchObj *bo=((BranchObj*)(selection))->linkTargetAt(i);
2680 cout << "follow to "<<bo->getHeading()<<endl;
2681 selection->unselect();
2683 selection->select();
2684 ensureSelectionVisible();
2688 void MapEditor::testFunction()
2690 cout << "MapEditor::testFunction() called\n";
2691 branchLinksContextMenu->setEnabled (false);
2694 void MapEditor::ensureSelectionVisible()
2696 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2698 if (selection->getOrientation() == OrientLeftOfCenter)
2699 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2701 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2702 ensureVisible (p.x(), p.y() );
2706 void MapEditor::updateViewCenter()
2708 // Update movingCenter, so that we can zoom comfortably later
2709 QRect rc = QRect( contentsX(), contentsY(),
2710 visibleWidth(), visibleHeight() );
2711 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2712 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2713 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2716 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2718 // Lineedits are already closed by preceding
2719 // mouseEvent, we don't need to close here.
2721 QPoint p = inverseWorldMatrix().map(e->pos());
2722 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2725 { // MapObj was found
2726 if (selection != lmo)
2728 // select the MapObj
2729 if (selection) selection->unselect();
2731 selection->select();
2737 if (typeid(*selection)==typeid(BranchObj) ||
2738 typeid(*selection)==typeid(MapCenterObj) )
2740 // Context Menu on branch or mapcenter
2742 branchContextMenu->popup(e->globalPos() );
2744 if (typeid(*selection)==typeid(FloatImageObj))
2746 // Context Menu on floatimage
2748 floatimageContextMenu->popup(e->globalPos() );
2752 { // No MapObj found, we are on the Canvas itself
2753 // Context Menu on Canvas
2755 canvasContextMenu->popup(e->globalPos() );
2759 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2761 // Finish open lineEdits
2762 if (lineedit) finishedLineEditNoSave();
2764 QPoint p = inverseWorldMatrix().map(e->pos());
2765 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2767 // Special case: CTRL is pressed
2768 if (e->state() & QMouseEvent::ControlButton)
2770 if (actionModModeColor->isOn())
2772 if (e->state() & QMouseEvent::ControlButton)
2775 setCursor (pickColorCursor);
2779 if (actionModModeLink->isOn())
2782 ((typeid(*selection) == typeid(BranchObj)) ||
2783 (typeid(*selection) == typeid(MapCenterObj))) )
2786 linkingObj_src=selection;
2787 tmpLink=new LinkObj (mapCanvas);
2788 tmpLink->setBegin ( ((BranchObj*)(selection)) );
2789 tmpLink->setEnd (p);
2790 tmpLink->updateLink();
2791 tmpLink->setVisibility (true);
2798 { // MapObj was found
2799 if (selection != lmo)
2801 // select the MapObj
2802 if (selection) selection->unselect();
2804 selection->select();
2809 // Check, if systemFlag clicked
2810 if (typeid(*selection)==typeid(BranchObj) ||
2811 typeid(*selection)==typeid(MapCenterObj) )
2813 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
2814 if (!foname.isEmpty())
2816 // Do not move, if systemFlag clicked
2820 if (foname=="vymLink")
2822 mainWindow->editOpenVymLink();
2823 // tabWidget may change, better return now
2824 // before segfaulting...
2828 mainWindow->windowToggleNoteEditor();
2832 // Left Button Move Branches
2833 if (e->button() == QMouseEvent::LeftButton )
2835 movingObj=selection;
2836 movingObj_start.setX( p.x() - selection->x() );
2837 movingObj_start.setY( p.y() - selection->y() );
2839 // Middle Button Toggle Scroll
2840 // (On Mac OS X this won't work, but we still have
2841 // a button in the toolbar)
2842 if (e->button() == QMouseEvent::MidButton )
2848 { // No MapObj found, we are on the Canvas itself
2849 // Left Button move Pos of CanvasView
2850 if (e->button() == QMouseEvent::LeftButton )
2852 movingObj=NULL; // move Content not Obj
2853 movingObj_start=e->globalPos();
2854 movingCont_start=QPoint (contentsX(), contentsY() );
2855 movingVec=QPoint(0,0);
2856 setCursor(handOpenCursor);
2861 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
2863 QPoint p = inverseWorldMatrix().map(e->pos());
2865 // Move the selected MapObj
2866 if ( selection && movingObj)
2868 ensureVisible (p.x(),p.y());
2870 // Now move the selection, but add relative position
2871 // (movingObj_start) where selection was chosen with
2872 // mousepointer. (This avoids flickering resp. jumping
2873 // of selection back to absPos)
2875 LinkableMapObj *lmosel;
2876 lmosel = dynamic_cast <LinkableMapObj*> (selection);
2878 // Check if we could link
2879 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
2882 if (typeid(*selection) == typeid(FloatImageObj))
2886 FloatObj *fo=(FloatObj*)(selection);
2887 if (fo->getLinkStyle()==StyleUndef)
2889 fo->setLinkStyle(fo->getDefLinkStyle());
2890 fo->setLinkColor(fo->getParObj()->getLinkColor());
2892 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2896 // Relink float to new mapcenter or branch, if shift is pressed
2897 // Only relink, if selection really has a new parent
2898 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
2899 ( (typeid(*lmo)==typeid(BranchObj)) ||
2900 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
2901 ( lmo != fo->getParObj())
2904 if (typeid(*fo) == typeid(FloatImageObj))
2906 FloatImageObj *fio=(FloatImageObj*)(fo);
2907 ((BranchObj*)(lmo))->addFloatImage (fio);
2909 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2910 fio=((BranchObj*)(lmo))->getLastFloatImage();
2913 selection=(LinkableMapObj*)(fio);
2914 selection->select();
2915 movingObj=(MapObj*)(fio);
2916 // setLinkStyle calls updateLink, only set it once
2917 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
2918 fio->setLinkStyle (fio->getDefLinkStyle());
2921 // TODO if (typeid(*selection) == typeid(FloatTextObj))
2923 } else // selection != a FloatObj
2925 if (lmosel->getDepth()==0)
2927 if (e->state() == (LeftButton | !ShiftButton))
2928 // If mapCenter is moved, move all the rest by default, too.
2929 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2931 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2934 if (lmosel->getDepth()==1)
2936 // depth==1, mainbranch
2938 saveState(PartOfMap,lmosel);
2939 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2943 if (lmosel->getOrientation() == OrientLeftOfCenter)
2944 // Add width of bbox here, otherwise alignRelTo will cause jumping around
2945 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
2946 p.y()-movingObj_start.y() );
2948 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2950 // reposition subbranch
2951 lmosel->reposition();
2952 //ensureSelectionVisible();
2954 if (lmo && (lmo!=selection) &&
2955 (typeid(*lmo) == typeid(BranchObj) ||
2956 (typeid(*lmo) == typeid(MapCenterObj) )
2959 if (e->state() & QMouseEvent::ControlButton)
2961 // Special case: CTRL to link below lmo
2962 lmosel->setParObjTmp (lmo,p,+1);
2964 else if (e->state() & QMouseEvent::ShiftButton)
2965 lmosel->setParObjTmp (lmo,p,-1);
2967 lmosel->setParObjTmp (lmo,p,0);
2970 if (lmo &&(lmo==selection))
2971 // Could link to myself (happens sometimes...)
2972 lmosel->unsetParObjTmp();
2974 // no Obj under selection, go back to original Parent
2975 lmosel->unsetParObjTmp();
2979 } // no FloatImageObj
2983 } // selection && moving_obj
2985 // Draw a link from one branch to another
2988 tmpLink->setEnd (p);
2989 tmpLink->updateLink();
2993 if (!movingObj && !pickingColor &&!drawingLink)
2995 QPoint p=e->globalPos();
2996 movingVec.setX(-p.x() + movingObj_start.x() );
2997 movingVec.setY(-p.y() + movingObj_start.y() );
2998 setContentsPos( movingCont_start.x() + movingVec.x(),
2999 movingCont_start.y() + movingVec.y());
3006 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3008 LinkableMapObj *dst;
3009 // Have we been picking color?
3013 setCursor (ArrowCursor);
3014 // Check if we are over another branch
3015 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3016 if (dst && selection)
3018 if (e->state() & QMouseEvent::ShiftButton)
3020 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3021 ((BranchObj*)(selection))->setLinkColor ();
3025 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3026 ((BranchObj*)(selection))->setLinkColor ();
3032 // Have we been drawing a link?
3036 // Check if we are over another branch
3037 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3038 if (dst && selection)
3040 tmpLink->setEnd ( ((BranchObj*)(dst)) );
3041 tmpLink->updateLink();
3042 tmpLink->activate();
3052 // Have we been moving something?
3053 if ( selection && movingObj )
3055 // Check if we are over another branch, but ignore
3056 // any found LMOs, which are FloatObjs
3057 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3058 ((LinkableMapObj*)(selection)) );
3061 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3066 // Now check, if we have been moving a branch
3067 if (typeid(*selection) == typeid(BranchObj) )
3069 // save the position in case we link to mapcenter
3070 QPoint savePos=QPoint (selection->x(),selection->y() );
3072 // Reset the temporary drawn link to the original one
3073 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3079 // TODO we also could check, if dest and src are on same branch,
3080 // then it would be sufficient to saveState of this branch
3082 // Modifiers allow to insert above/below dst
3083 if (e->state() & QMouseEvent::ShiftButton)
3085 ((BranchObj*)(selection))->moveBranchTo
3088 ((BranchObj*)(dst))->getNum()
3090 //if (selection) selection->select();
3092 if (e->state() & QMouseEvent::ControlButton)
3094 ((BranchObj*)(selection))->moveBranchTo
3097 ((BranchObj*)(dst))->getNum()+1
3099 //if (selection) selection->select();
3102 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
3103 if (dst->getDepth()==0)
3104 ((BranchObj*)(selection))->move (savePos);
3107 // Draw the original link, before selection was moved around
3108 mapCenter->reposition();
3110 // Finally resize canvas, if needed
3115 // maybe we moved View: set old cursor
3116 setCursor (ArrowCursor);
3120 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3122 // Finish open lineEdits
3123 if (lineedit) finishedLineEditNoSave();
3125 if (e->button() == QMouseEvent::LeftButton )
3127 QPoint p = inverseWorldMatrix().map(e->pos());
3128 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3129 if (lmo) { // MapObj was found
3130 // First select the MapObj than edit heading
3131 if (selection) selection->unselect();
3133 selection->select();
3135 saveState(PartOfMap,selection);
3141 void MapEditor::resizeEvent (QResizeEvent* e)
3143 QCanvasView::resizeEvent( e );
3146 if (!fileName.isEmpty()) s=fileName;