added modifier modes (color,link,copy). Not fully functional yet
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 );
327 // Initialize find routine
334 blockreposition=false;
335 isInteractive=interactive;
337 // Create temporary files
340 // Initially set movingCentre
343 mapCenter->reposition(); // for positioning heading
346 MapEditor::~MapEditor()
348 //cout <<"Destructor MapEditor\n";
349 if (isInteractive) delTmpDirs();
352 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
356 QColor MapEditor::color()
361 QColor MapEditor::backgroundColor()
363 return mapCanvas->backgroundColor();
366 MapCenterObj* MapEditor::getMapCenter()
371 QCanvas* MapEditor::getCanvas()
376 void MapEditor::adjustCanvasSize()
378 // To adjust the canvas to map, viewport size and position, we have to
379 // do some coordinate magic...
381 // Get rectangle of (scroll-)view.
382 // We want to be in canvas coords, so
383 // we map. Important if view is zoomed...
384 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
385 visibleWidth(), visibleHeight()) );
387 // Now we need the bounding box of view AND map to calc the correct canvas size.
388 // Why? Because if the map itself is moved out of view, the view has to be enlarged
389 // to avoid jumping aroung...
390 QRect map=mapCenter->getTotalBBox();
392 // right edge - left edge
393 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
394 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
397 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
398 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
401 // move the map on canvas (in order to not move it on screen) this is neccessary
402 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
403 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
404 // to scroll to an empty area of canvas to the left.
405 // b) if topleft corner of map left of or above topleft of canvas
409 if (cw > mapCanvas->width() )
411 if (map.x()<0) dx=-map.x();
413 if (cw < mapCanvas->width() )
414 dx=-min (view.x(),map.x());
415 if (ch > mapCanvas->height() )
417 if (map.y()<0) dy=-map.y();
419 if (ch < mapCanvas->height() )
421 dy=-min (view.y(),map.y());
423 // We really have to resize now. Let's go...
424 mapCanvas->resize (cw,ch);
425 if ( (dx!=0) || (dy!=0) )
427 mapCenter->moveAllBy(dx,dy);
428 mapCenter->reposition();
430 // scroll the view (in order to not move map on screen)
436 bool MapEditor::blockReposition()
438 return blockreposition;
441 void MapEditor::makeTmpDirs()
443 // Create unique temporary directories
444 char tmpdir[]="/tmp/vym-XXXXXX";
445 bakMapDir=mkdtemp(tmpdir);
446 makeSubDirs(bakMapDir);
447 // FIXME set permissions
448 // and maybe use QT method for portability
451 void MapEditor::delTmpDirs()
453 //FIXME delete tmp directory, better use QT methods here:
454 system ( "rm -rf "+ bakMapDir );
458 void MapEditor::makeSubDirs(const QString &s)
466 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, SaveMode savemode)
468 // tmpdir temporary directory to which data will be writte
469 // prefix mapname, which will be appended to images etc.
470 // writeflags Only write flags for "real" save of map, not undo
471 // offset offset of bbox of whole map in canvas.
472 // Needed for XML export
473 // completeMap if false, only vympart will be written, without
490 ls="StylePolyParabel";
494 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
496 if (linkcolorhint==HeadingColor)
497 colhint=attribut("linkColorHint","HeadingColor");
499 QString mapAttr=attribut("version",__VYM_VERSION__);
500 if (savemode==CompleteMap)
501 mapAttr+= attribut("author",mapCenter->getAuthor()) +
502 attribut("comment",mapCenter->getComment()) +
503 attribut("date",mapCenter->getDate()) +
504 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
505 attribut("linkStyle", ls ) +
506 attribut("linkColor", deflinkcolor.name() ) +
508 s+=beginElement("vymmap",mapAttr);
511 // Find the used flags while traversing the tree
512 standardFlagsDefault->resetUsedCounter();
514 // Build xml recursivly
515 if (savemode==CompleteMap)
516 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
519 if ( undoSelection &&
520 typeid(*undoSelection) == typeid(BranchObj) )
521 s+=((BranchObj*)(undoSelection))->saveToDir(tmpdir,prefix,offset);
524 // Save local settings
525 s+=settings.getXMLData (destPath);
529 s+=valueElement("select",selection->getSelectString());
532 s+=endElement("vymmap");
535 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
540 void MapEditor::saveState()
542 saveState (CompleteMap,NULL);
545 void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part)
547 // all binary data is saved in bakMapDir (created in Constructor)
548 // the xml data itself is kept in memory in backupXML
550 // For faster write/read of data, a part of the map can be
551 // written. Then the undoSelection will mark, which part of the
552 // map should be replaced if an undo is wanted later.
554 if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) )
556 // Writing a vympart only is useful for BranchObj
558 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
562 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap);
566 void MapEditor::finishedLineEditNoSave()
568 // This is called by finishedLineEdit or any MapEditor method,
569 // which wants to assure, that lineedits finish, before e.g. a branch is
572 // After calling LineEdit and using the clipboard, the
573 // focus is not any longer on the main widget, we
574 // have to restore it using parentWidget()->setFocus()
578 editingBO->setHeading(lineedit->text() );
580 lineedit->releaseKeyboard();
582 parentWidget()->setFocus();
583 mapCenter->reposition();
585 ensureSelectionVisible();
590 bool MapEditor::isDefault()
595 bool MapEditor::isUnsaved()
600 bool MapEditor::hasChanged()
605 void MapEditor::setChanged()
610 actionEditUndo->setEnabled (true);
611 actionFileSave->setEnabled (true);
615 void MapEditor::closeMap()
617 // Finish open lineEdits
618 if (lineedit) finishedLineEditNoSave();
620 // Unselect before disabling the toolbar actions
621 if (selection) selection->unselect();
629 void MapEditor::setFilePath(QString fname)
631 setFilePath (fname,fname);
634 void MapEditor::setFilePath(QString fname, QString destname)
640 // If fname is not an absolute path, complete it
641 filePath=QDir(fname).absPath();
642 fileDir=filePath.left (1+filePath.findRev ("/"));
644 // Set short name, too. Search from behind:
645 int i=fileName.findRev("/");
646 if (i>=0) fileName=fileName.remove (0,i+1);
648 // Forget the .vym (or .xml) for name of map
649 mapName=fileName.left(fileName.findRev(".",-1,true) );
652 QString MapEditor::getFilePath()
657 QString MapEditor::getFileName()
662 QString MapEditor::getMapName()
667 QString MapEditor::getDestPath()
672 int MapEditor::load (QString &fname, const LoadMode &lmode)
674 // Finish open lineEdits
675 if (lineedit) finishedLineEditNoSave();
681 if (selection) selection->unselect();
684 mapCenter->setMapEditor(this);
685 // (map state is set later at end of load...)
689 saveState(PartOfMap,selection);
693 mapBuilderHandler handler;
696 // I am paranoid: file should exist anyway
697 // according to check in mainwindow.
700 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
701 tr("Couldn't open map " +fname)+".");
705 blockreposition=true;
706 QXmlInputSource source( file);
707 QXmlSimpleReader reader;
708 reader.setContentHandler( &handler );
709 reader.setErrorHandler( &handler );
710 handler.setMapEditor( this );
711 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
712 handler.setLoadMode (lmode);
713 bool ok = reader.parse( source );
714 blockreposition=false;
718 mapCenter->reposition();
728 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
729 tr( handler.errorProtocol() ) );
731 // Still return "success": the map maybe at least
732 // partially read by the parser
739 int MapEditor::save (const SaveMode &savemode)
741 // Finish open lineEdits
742 if (lineedit) finishedLineEditNoSave();
746 // Create mapName and fileDir
747 makeSubDirs (fileDir);
751 fname=mapName+".xml";
753 // use name given by user, even if he chooses .doc
757 // Check if fname is writeable
758 QFile file( fileDir+fname);
759 if (!file.open( IO_WriteOnly ) )
761 QMessageBox::critical( 0, tr( "Critical Save Error" ),
762 tr("Couldn't write to ") +fileDir+fname);
768 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),savemode);
770 file.setName ( fileDir + fname);
771 if ( !file.open( IO_WriteOnly ) )
773 // This should neverever happen
774 QMessageBox::critical(0, tr("Critcal save error"),"MapEditor::save() Couldn't open "+file.name());
778 // Write it finally, and write in UTF8, no matter what
779 QTextStream ts( &file );
780 ts.setEncoding (QTextStream::UnicodeUTF8);
788 actionFileSave->setEnabled(false);
794 void MapEditor::setZipped (bool z)
799 bool MapEditor::saveZipped ()
804 void MapEditor::print()
806 // Finish open lineEdits
807 if (lineedit) finishedLineEditNoSave();
811 printer = new QPrinter;
812 printer->setColorMode (QPrinter::Color);
815 QRect totalBBox=mapCenter->getTotalBBox();
817 // Try to set orientation automagically
818 // Note: Interpretation of generated postscript is amibiguous, if
819 // there are problems with landscape mode, see
820 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
822 if (totalBBox.width()>totalBBox.height())
823 // recommend landscape
824 printer->setOrientation (QPrinter::Landscape);
826 // recommend portrait
827 printer->setOrientation (QPrinter::Portrait);
829 if ( printer->setup(this) )
830 // returns false, if printing is canceled
832 QPainter pp(printer);
834 // Don't print the visualisation of selection
835 LinkableMapObj *oldselection=NULL;
838 oldselection=selection;
839 selection->unselect();
842 // Handle sizes of map and paper:
844 // setWindow defines which part of the canvas will be transformed
845 // setViewport defines area on paper in device coordinates (dpi)
846 // e.g. (0,50,700,700) is upper part on A4
847 // see also /usr/lib/qt3/doc/html/coordsys.html
849 QPaintDeviceMetrics metrics (printer);
851 double paperAspect = (double)metrics.width() / (double)metrics.height();
852 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
854 QRect mapRect=mapCenter->getTotalBBox();
855 QCanvasRectangle *frame=NULL;
856 QCanvasText *footerFN=NULL;
857 QCanvasText *footerDate=NULL;
858 if (printFrame || printFooter)
863 // Print frame around map
864 mapRect.setRect (mapRect.x()-10, mapRect.y()-10,
865 mapRect.width()+20, mapRect.height()+20);
866 frame=new QCanvasRectangle (mapRect,mapCanvas);
867 frame->setBrush (QColor(white));
868 frame->setPen (QColor(black));
874 // Print footer below map
876 font.setPointSize(10);
877 footerFN=new QCanvasText (mapCanvas);
878 footerFN->setText ("VYM - " + fileName);
879 footerFN->setFont(font);
880 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
881 footerFN->setZ(Z_TEXT);
883 footerDate=new QCanvasText (mapCanvas);
884 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
885 footerDate->setFont(font);
886 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
887 footerDate->setZ(Z_TEXT);
889 mapRect.setRect (mapRect.x(), mapRect.y(),
890 mapRect.width(), mapRect.height()+20);
892 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height());
895 pp.setWindow (mapRect);
898 if (mapAspect>=paperAspect)
900 // Fit horizontally to paper width
901 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
904 // Fit vertically to paper height
905 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
908 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
910 // Delete Frame and footer
916 if (frame) delete (frame);
921 selection=oldselection;
927 QPixmap MapEditor::getPixmap()
929 QRect mapRect=mapCenter->getTotalBBox();
930 QPixmap pix (mapRect.size());
933 // Don't print the visualisation of selection
934 LinkableMapObj *oldselection=NULL;
937 oldselection=selection;
938 selection->unselect();
941 pp.setWindow (mapRect);
943 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
949 selection=oldselection;
956 void MapEditor::exportImage(QString fn)
958 // Finish open lineEdits
959 if (lineedit) finishedLineEditNoSave();
961 QPixmap pix (getPixmap());
965 void MapEditor::exportImage(QString fn, int item)
967 // Finish open lineEdits
968 if (lineedit) finishedLineEditNoSave();
970 QPixmap pix (getPixmap());
971 pix.save(fn, exportImageFormatMenu->text(item) );
974 void MapEditor::exportASCII()
976 // FIXME still experimental
977 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
978 fd->addFilter ("TXT (*.txt)");
979 fd->setCaption("VYM - Export (ASCII) (still experimental)");
980 fd->setMode( QFileDialog::AnyFile );
983 if ( fd->exec() == QDialog::Accepted )
985 if (QFile (fd->selectedFile()).exists() )
987 QMessageBox mb( "VYM",
988 tr("The file ") + fd->selectedFile() +
989 tr(" exists already. Do you want to overwrite it?"),
990 QMessageBox::Warning,
991 QMessageBox::Yes | QMessageBox::Default,
992 QMessageBox::Cancel | QMessageBox::Escape,
993 QMessageBox::NoButton );
995 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
996 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1000 case QMessageBox::Yes:
1002 if (!ex.setOutputDir ("out"))
1004 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1008 case QMessageBox::Cancel:
1015 ex.setPath (fd->selectedFile() );
1016 ex.setMapCenter(mapCenter);
1022 void MapEditor::exportXML(const QString &dir)
1024 // Create subdirectories
1027 // write to directory
1028 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,CompleteMap);
1031 file.setName ( dir + "/"+mapName+".xml");
1032 if ( !file.open( IO_WriteOnly ) )
1034 // This should neverever happen
1035 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1039 // Write it finally, and write in UTF8, no matter what
1040 QTextStream ts( &file );
1041 ts.setEncoding (QTextStream::UnicodeUTF8);
1045 // Now write image, too
1046 exportImage (dir+"/images/"+mapName+".png");
1049 void MapEditor::clear()
1053 selection->unselect();
1060 void MapEditor::undo()
1063 d.setPath(bakMapDir);
1066 // Finish open lineEdits
1067 if (lineedit) finishedLineEditNoSave();
1071 selection->unselect();
1075 mapBuilderHandler handler;
1076 QXmlInputSource source;
1077 source.setData(backupXML);
1078 QXmlSimpleReader reader;
1079 reader.setContentHandler( &handler );
1080 reader.setErrorHandler( &handler );
1081 handler.setMapEditor( this );
1082 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1085 selection=undoSelection;
1086 selection->select();
1087 handler.setLoadMode (ImportReplace);
1092 handler.setLoadMode (NewMap);
1094 blockreposition=true;
1095 bool ok = reader.parse( source );
1096 blockreposition=false;
1098 mapCenter->reposition();
1102 // This should never ever happen
1103 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1104 tr( handler.errorProtocol() )+" in "+backupXML );
1106 // Undo not longer available now
1107 actionEditUndo->setEnabled (false);
1108 undoSelection=false;
1113 QMessageBox::critical( 0, tr( "Critical Error" ),
1114 "Temporary directory " +bakMapDir +
1115 tr (" used for undo is gone. \n"
1116 "I will create a new one, but at the moment no undo is available.\n"
1117 "Maybe you want to reload your original data.\n\n"
1118 "Sorry for any inconveniences.") );
1123 void MapEditor::copy()
1125 // Finish open lineEdits
1126 if (lineedit) finishedLineEditNoSave();
1130 if (typeid(*selection) == typeid(BranchObj) )
1134 clipboardME->clear();
1135 clipboardME->getMapCenter()->addBranch();
1136 to=clipboardME->getMapCenter()->getLastBranch();
1139 from=(BranchObj*)(selection);
1142 // keep position relative to parent
1143 to->move2RelPos ( from->getRelPos());
1145 // select data in clipboard
1146 clipboardME->select ("bo:0");
1148 // repositioning makes testing nicer,
1149 // but is not needed usually:
1150 if (clipboardME->isVisible())
1152 clipboardME->getMapCenter()->reposition();
1155 clipboardME->hide();
1158 if (typeid(*selection) == typeid(FloatImageObj) )
1161 FloatImageObj* from;
1162 clipboardME->clear();
1163 clipboardME->getMapCenter()->addFloatImage();
1164 to=clipboardME->getMapCenter()->getLastFloatImage();
1167 from=(FloatImageObj*)(selection);
1170 // select data in clipboard
1171 clipboardME->select ("fi:0");
1173 // repositioning makes testing nicer,
1174 // but is not needed usually:
1175 if (clipboardME->isVisible())
1177 clipboardME->getMapCenter()->reposition();
1180 clipboardME->hide();
1186 LinkableMapObj* MapEditor::pasteNoSave()
1188 // Finish open lineEdits
1189 if (lineedit) finishedLineEditNoSave();
1191 LinkableMapObj *fromLMO=clipboardME->getSelection();
1192 LinkableMapObj *returnLMO=NULL;
1194 if (selection && fromLMO)
1197 if (typeid(*fromLMO) == typeid(BranchObj) )
1199 if (typeid(*selection) == typeid(MapCenterObj))
1201 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1202 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1204 if (typeid(*selection) == typeid(BranchObj))
1205 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1208 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1209 (typeid(*selection) == typeid (BranchObj) ||
1210 typeid(*selection)==typeid(MapCenterObj)) )
1211 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1217 void MapEditor::cutNoSave()
1219 // Finish open lineEdits
1220 if (lineedit) finishedLineEditNoSave();
1224 if (selection != NULL) {
1225 if (typeid(*selection) == typeid(BranchObj) )
1227 bo=(BranchObj*)(selection);
1228 par=(BranchObj*)(bo->getParObj());
1231 par->removeBranch(bo);
1233 selection->select();
1235 if (typeid(*selection) == typeid(FloatImageObj) )
1237 FloatImageObj* fio=(FloatImageObj*)(selection);
1238 par=(BranchObj*)(fio->getParObj());
1241 par->removeFloatImage(fio);
1243 selection->select();
1248 void MapEditor::paste()
1251 saveState(PartOfMap,selection);
1253 mapCenter->reposition();
1257 void MapEditor::cut()
1260 saveState(PartOfMap,selection->getParObj());
1263 mapCenter->reposition();
1267 void MapEditor::moveBranchUp()
1269 // Finish open lineEdits
1270 if (lineedit) finishedLineEditNoSave();
1274 if (typeid(*selection) == typeid(BranchObj) )
1277 saveState(PartOfMap,selection->getParObj());
1278 bo=(BranchObj*)(selection);
1279 par=(BranchObj*)(bo->getParObj());
1280 selection->unselect();
1281 selection=par->moveBranchUp (bo);
1282 selection->select();
1283 mapCenter->reposition();
1284 ensureSelectionVisible();
1288 void MapEditor::moveBranchDown()
1290 // Finish open lineEdits
1291 if (lineedit) finishedLineEditNoSave();
1295 if (typeid(*selection) == typeid(BranchObj) )
1298 saveState(PartOfMap,selection->getParObj());
1299 bo=(BranchObj*)(selection);
1300 par=(BranchObj*)(bo->getParObj());
1301 selection->unselect();
1302 selection=par->moveBranchDown(bo);
1303 selection->select();
1304 mapCenter->reposition();
1305 ensureSelectionVisible();
1309 void MapEditor::editHeading()
1311 // Finish open lineEdits
1312 if (lineedit) finishedLineEditNoSave();
1315 (typeid(*selection) == typeid(BranchObj) ||
1316 typeid(*selection) == typeid(MapCenterObj) ) )
1319 saveState(PartOfMap,selection);
1321 ensureSelectionVisible();
1322 BranchObj *bo=(BranchObj*)(selection);
1323 editingBO=(BranchObj*)(selection);
1324 QPoint p = worldMatrix().map(QPoint (bo->x(),bo->y()));
1325 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1326 QString s=bo->getHeading();
1327 lineedit->setText(s);
1328 lineedit->setCursorPosition(1);
1329 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1330 lineedit->selectAll();
1333 lineedit->grabKeyboard();
1334 lineedit->setFocus();
1339 void MapEditor::addNewBranch(int pos)
1341 // Finish open lineEdits
1342 if (lineedit) finishedLineEditNoSave();
1345 (typeid(*selection) == typeid(BranchObj) ||
1346 typeid(*selection) == typeid(MapCenterObj) ) )
1349 saveState(PartOfMap,selection);
1351 BranchObj* bo1 = (BranchObj*) (selection);
1352 bool wasScrolled=false;
1353 BranchObj *newbo=NULL;
1356 // save scroll state. If scrolled, automatically select
1357 // new branch in order to tmp unscroll parent...
1358 wasScrolled=bo1->isScrolled();
1359 newbo=bo1->addBranch();
1362 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1366 // add above selection
1367 newbo=parbo->insertBranch(bo1->getNum());
1369 // add below selection
1370 newbo=parbo->insertBranch(bo1->getNum()+1);
1372 // This should not happen...
1377 LinkableMapObj *oldselection=selection;
1379 mapCenter->reposition();
1381 if (actionSettingsAutoedit->isOn() ||
1382 actionSettingsAutoselectHeading->isOn() )
1384 selection->unselect();
1386 selection->select();
1387 if (actionSettingsPasteNewHeading->isOn() )
1389 BranchObj *bo2= (BranchObj*)(selection);
1390 bo2->setHeading("");
1392 if (actionSettingsAutoedit->isOn() )
1394 if (!actionSettingsAutoselectHeading->isOn()
1397 selection->unselect();
1398 selection=oldselection;
1399 selection->select();
1405 void MapEditor::deleteSelection()
1407 // Finish open lineEdits
1408 if (lineedit) finishedLineEditNoSave();
1410 if (selection && typeid(*selection) ==typeid(BranchObj) )
1413 saveState(PartOfMap,selection->getParObj());
1414 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1415 BranchObj* par=(BranchObj*)(bo->getParObj());
1418 par->removeBranch(bo);
1420 selection->select();
1421 ensureSelectionVisible();
1422 mapCenter->reposition();
1425 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1428 saveState(PartOfMap,selection->getParObj());
1429 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1430 BranchObj* par=(BranchObj*)(fio->getParObj());
1433 par->removeFloatImage(fio);
1435 selection->select();
1436 ensureSelectionVisible();
1437 mapCenter->reposition();
1442 LinkableMapObj* MapEditor::getSelection()
1447 LinkableMapObj* MapEditor::findObj (QString s)
1449 LinkableMapObj *lmo=mapCenter;
1453 while (!s.isEmpty() )
1455 part=s.section(",",0,0);
1457 num=part.right(part.length() - 3);
1464 lmo=mapCenter->getBranchNum (num.toUInt());
1467 lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt());
1470 lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
1473 if (s.contains(","))
1474 s=s.right(s.length() - part.length() -1 );
1481 bool MapEditor::select (const QString &s)
1483 LinkableMapObj *lmo=findObj(s);
1485 // Finally select the found object
1488 if (selection) selection->unselect();
1490 selection->select();
1492 ensureSelectionVisible();
1498 void MapEditor::unselect()
1502 selectionLast=selection;
1503 selection->unselect();
1508 void MapEditor::reselect()
1512 selection=selectionLast;
1513 selection->select();
1518 void MapEditor::selectNextBranch()
1520 // Increase number of branch
1523 QString s=selection->getSelectString();
1529 part=s.section(",",-1);
1531 num=part.right(part.length() - 3);
1533 s=s.left (s.length() -num.length());
1536 num=QString ("%1").arg(num.toUInt()+1);
1540 // Try to select this one
1541 if (select (s)) return;
1543 // We have no direct successor,
1544 // try to increase the parental number in order to
1545 // find a successor with same depth
1547 int d=selection->getDepth();
1552 while (!found && d>0)
1554 s=s.section (",",0,d-1);
1555 // replace substring of current depth in s with "1"
1556 part=s.section(",",-1);
1558 num=part.right(part.length() - 3);
1562 // increase number of parent
1563 num=QString ("%1").arg(num.toUInt()+1);
1564 s=s.section (",",0,d-2) + ","+ typ+num;
1567 // Special case, look at orientation
1568 if (selection->getOrientation()==OrientRightOfCenter)
1569 num=QString ("%1").arg(num.toUInt()+1);
1571 num=QString ("%1").arg(num.toUInt()-1);
1576 // pad to oldDepth, select the first branch for each depth
1577 for (i=d;i<oldDepth;i++)
1582 if ( ((BranchObj*)(selection))->countBranches()>0)
1590 // try to select the freshly built string
1598 void MapEditor::selectPrevBranch()
1600 // Decrease number of branch
1603 QString s=selection->getSelectString();
1609 part=s.section(",",-1);
1611 num=part.right(part.length() - 3);
1613 s=s.left (s.length() -num.length());
1616 num=QString ("%1").arg(num.toUInt()-1);
1620 // Try to select this one
1621 if (select (s)) return;
1623 // We have no direct precessor,
1624 // try to decrease the parental number in order to
1625 // find a precessor with same depth
1627 int d=selection->getDepth();
1632 while (!found && d>0)
1634 s=s.section (",",0,d-1);
1635 // replace substring of current depth in s with "1"
1636 part=s.section(",",-1);
1638 num=part.right(part.length() - 3);
1642 // decrease number of parent
1643 num=QString ("%1").arg(num.toUInt()-1);
1644 s=s.section (",",0,d-2) + ","+ typ+num;
1647 // Special case, look at orientation
1648 if (selection->getOrientation()==OrientRightOfCenter)
1649 num=QString ("%1").arg(num.toUInt()-1);
1651 num=QString ("%1").arg(num.toUInt()+1);
1656 // pad to oldDepth, select the last branch for each depth
1657 for (i=d;i<oldDepth;i++)
1661 if ( ((BranchObj*)(selection))->countBranches()>0)
1662 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1669 // try to select the freshly built string
1677 void MapEditor::selectUpperBranch()
1679 // Finish open lineEdits
1680 if (lineedit) finishedLineEditNoSave();
1684 if (typeid(*selection) == typeid(BranchObj))
1686 if (selection->getOrientation()==OrientRightOfCenter)
1689 if (selection->getDepth()==1)
1697 void MapEditor::selectLowerBranch()
1699 // Finish open lineEdits
1700 if (lineedit) finishedLineEditNoSave();
1704 if (typeid(*selection) == typeid(BranchObj))
1706 if (selection->getOrientation()==OrientRightOfCenter)
1709 if (selection->getDepth()==1)
1718 void MapEditor::selectLeftBranch()
1720 // Finish open lineEdits
1721 if (lineedit) finishedLineEditNoSave();
1727 if (typeid(*selection) == typeid(MapCenterObj))
1729 par= (BranchObj*) (selection);
1730 bo=par->getLastSelectedBranch();
1733 // Workaround for reselecting on left and right side
1734 if (bo->getOrientation()==OrientRightOfCenter)
1736 bo=par->getLastBranch();
1742 selection->select();
1744 ensureSelectionVisible();
1749 par=(BranchObj*)(selection->getParObj());
1750 if (selection->getOrientation()==OrientRightOfCenter)
1752 if (typeid(*selection) == typeid(BranchObj) ||
1753 typeid(*selection) == typeid(FloatImageObj))
1755 selection->unselect();
1757 selection->select();
1759 ensureSelectionVisible();
1763 if (typeid(*selection) == typeid(BranchObj) )
1765 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1768 selection->unselect();
1770 selection->select();
1772 ensureSelectionVisible();
1780 void MapEditor::selectRightBranch()
1782 // Finish open lineEdits
1783 if (lineedit) finishedLineEditNoSave();
1790 if (typeid(*selection) == typeid(MapCenterObj))
1792 par= (BranchObj*) (selection);
1793 bo=par->getLastSelectedBranch();
1796 // Workaround for relecting on left and right side
1797 if (bo->getOrientation()==OrientLeftOfCenter)
1798 bo=par->getFirstBranch();
1803 selection->select();
1804 ensureSelectionVisible();
1809 par=(BranchObj*)(selection->getParObj());
1810 if (selection->getOrientation()==OrientLeftOfCenter)
1812 if (typeid(*selection) == typeid(BranchObj) ||
1813 typeid(*selection) == typeid(FloatImageObj))
1815 selection->unselect();
1817 selection->select();
1819 ensureSelectionVisible();
1823 if (typeid(*selection) == typeid(BranchObj) )
1825 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1828 selection->unselect();
1830 selection->select();
1832 ensureSelectionVisible();
1840 void MapEditor::selectFirstBranch()
1842 // Finish open lineEdits
1843 if (lineedit) finishedLineEditNoSave();
1849 if (typeid(*selection) == typeid(BranchObj))
1851 bo1= (BranchObj*) (selection);
1852 par=(BranchObj*)(bo1->getParObj());
1853 bo2=par->getFirstBranch();
1857 selection->select();
1858 ensureSelectionVisible();
1865 void MapEditor::selectLastBranch()
1867 // Finish open lineEdits
1868 if (lineedit) finishedLineEditNoSave();
1874 if (typeid(*selection) == typeid(BranchObj))
1876 bo1= (BranchObj*) (selection);
1877 par=(BranchObj*)(bo1->getParObj());
1878 bo2=par->getLastBranch();
1882 selection->select();
1883 ensureSelectionVisible();
1890 void MapEditor::setColor(QColor c)
1895 void MapEditor::selectBackgroundColor()
1897 // Finish open lineEdits
1898 if (lineedit) finishedLineEditNoSave();
1900 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
1901 if ( !col.isValid() ) return;
1902 setBackgroundColor( col );
1906 void MapEditor::setBackgroundColor(QColor c)
1908 mapCanvas->setBackgroundColor (c);
1911 QColor MapEditor::pickColor()
1915 if (typeid(*selection) == typeid(BranchObj) ||
1916 typeid(*selection) == typeid(MapCenterObj))
1918 BranchObj *bo=(BranchObj*)(selection);
1919 actColor=bo->getColor();
1925 void MapEditor::colorItem()
1929 if (typeid(*selection) == typeid(BranchObj) ||
1930 typeid(*selection) == typeid(MapCenterObj))
1933 saveState(PartOfMap,selection);
1934 BranchObj *bo=(BranchObj*)(selection);
1935 bo->setColor(actColor, false); // color links, color childs
1940 void MapEditor::colorBranch()
1944 if (typeid(*selection) == typeid(BranchObj) ||
1945 typeid(*selection) == typeid(MapCenterObj))
1948 saveState(PartOfMap,selection);
1949 BranchObj *bo=(BranchObj*)(selection);
1950 bo->setColor(actColor, true); // color links, color childs
1956 void MapEditor::toggleStandardFlag(QString f)
1961 saveState(PartOfMap,selection);
1962 ((BranchObj*)(selection))->toggleStandardFlag (f);
1966 void MapEditor::setViewCenter()
1968 // transform to CanvasView Coord:
1969 QPoint p=worldMatrix().map(movingCenter);
1970 center ( p.x(), p.y());
1974 BranchObj* MapEditor::findText (QString s, bool cs)
1977 { // Nothing found or new find process
1979 // nothing found, start again
1981 itFind=mapCenter->first();
1983 bool searching=true;
1984 bool foundNote=false;
1985 while (searching && !EOFind)
1989 // Searching in Note
1990 if (itFind->getNote().contains(s,cs))
1992 if (selection!=itFind)
1994 if (selection) ((BranchObj*)(selection))->unselect();
1996 selection->select();
1998 ensureSelectionVisible();
2000 if (textEditor->findText(s,cs))
2006 // Searching in Heading
2007 if (searching && itFind->getHeading().contains (s,cs) )
2009 if (selection) ((BranchObj*)(selection))->unselect();
2011 selection->select();
2013 ensureSelectionVisible();
2019 itFind=itFind->next();
2020 if (!itFind) EOFind=true;
2026 return (BranchObj*)(selection);
2031 void MapEditor::findReset()
2032 { // Necessary if text to find changes during a find process
2037 void MapEditor::openURL()
2041 if (typeid(*selection) == typeid(BranchObj) ||
2042 typeid(*selection) == typeid(MapCenterObj))
2044 QString url=((BranchObj*)(selection))->getURL();
2046 QProcess *proc = new QProcess( this );
2048 #if !defined(Q_OS_MACX)
2049 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2051 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2052 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2055 proc->addArgument( url);
2057 if ( !proc->start() )
2059 if (mainWindow->settingsURL() )
2065 void MapEditor::editURL()
2067 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2068 typeid(*selection) == typeid(MapCenterObj)) )
2071 QString text = QInputDialog::getText(
2072 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2073 ((BranchObj*)(selection))->getURL(), &ok, this );
2076 // user entered something and pressed OK
2077 ((BranchObj*)(selection))->setURL (text);
2084 void MapEditor::editHeading2URL()
2086 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2087 typeid(*selection) == typeid(MapCenterObj)) )
2089 BranchObj *b=(BranchObj*)(selection);
2090 b->setURL (b->getHeading());
2096 void MapEditor::editBugzilla2URL()
2098 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2099 typeid(*selection) == typeid(MapCenterObj)) )
2101 BranchObj *b=(BranchObj*)(selection);
2102 b->setURL ("http://bugzilla.suse.de/show_bug.cgi?id="+b->getHeading());
2103 b->setURL ("https://bugzilla.innerweb.novell.com/show_bug.cgi?id="+b->getHeading());
2109 void MapEditor::editVymLink()
2111 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2112 typeid(*selection) == typeid(MapCenterObj)) )
2114 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2115 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2116 fd->setCaption(tr("VYM - Link to another map"));
2117 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2118 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2122 if ( fd->exec() == QDialog::Accepted )
2123 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2125 mapCenter->reposition();
2132 void MapEditor::deleteVymLink()
2134 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2135 typeid(*selection) == typeid(MapCenterObj)) )
2137 ((BranchObj*)(selection))->setVymLink ("" );
2139 mapCenter->reposition();
2146 QString MapEditor::getVymLink()
2148 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2149 typeid(*selection) == typeid(MapCenterObj)) )
2151 return ((BranchObj*)(selection))->getVymLink();
2157 void MapEditor::editMapInfo()
2159 ExtraInfoDialog dia;
2160 dia.setMapName (getFileName() );
2161 dia.setAuthor (mapCenter->getAuthor() );
2162 dia.setComment(mapCenter->getComment() );
2167 QCanvasItemList l=canvas()->allItems();
2168 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2170 stats+=QString ("%1 items on canvas\n").arg (i,6);
2176 bo=mapCenter->first();
2179 if (!bo->getNote().isEmpty() ) n++;
2180 f+= bo->countFloatImages();
2184 stats+=QString ("%1 branches\n").arg (b-1,6);
2185 stats+=QString ("%1 notes\n").arg (n,6);
2186 stats+=QString ("%1 images\n").arg (f,6);
2187 dia.setStats (stats);
2189 // Finally show dialog
2190 if (dia.exec() == QDialog::Accepted)
2192 mapCenter->setAuthor (dia.getAuthor() );
2193 mapCenter->setComment (dia.getComment() );
2198 void MapEditor::updateActions()
2200 if (getLinkColorHint()==HeadingColor)
2201 actionFormatLinkColorHint->setOn(true);
2203 actionFormatLinkColorHint->setOn(false);
2208 actionFormatLinkStyleLine->setOn(true);
2211 actionFormatLinkStyleParabel->setOn(true);
2214 actionFormatLinkStylePolyLine->setOn(true);
2216 case StylePolyParabel:
2217 actionFormatLinkStylePolyParabel->setOn(true);
2223 QPixmap pix( 16, 16 );
2224 pix.fill( mapCanvas->backgroundColor() );
2225 actionFormatBackColor->setIconSet( pix );
2226 pix.fill( deflinkcolor );
2227 actionFormatLinkColor->setIconSet( pix );
2229 actionEditUndo->setEnabled( mapChanged );
2230 actionFileSave->setEnabled( mapUnsaved );
2234 if ( (typeid(*selection) == typeid(BranchObj)) ||
2235 (typeid(*selection) == typeid(MapCenterObj)) )
2237 BranchObj *bo=(BranchObj*)(selection);
2238 // Take care of links
2239 if (bo->countLinks()==0)
2241 branchLinksContextMenu->clear();
2242 branchLinksContextMenu->insertItem ("No link available");
2248 branchLinksContextMenu->clear();
2249 for (int i=0; i<=bo->countLinks();i++)
2251 bot=bo->linkTargetAt(i);
2254 s=bot->getHeading();
2257 branchLinksContextMenu->insertItem (s);
2262 standardFlagsDefault->setEnabled (true);
2264 if ( bo->getURL().isEmpty() )
2265 actionEditOpenURL->setEnabled (false);
2267 actionEditOpenURL->setEnabled (true);
2268 actionEditURL->setEnabled (true);
2269 actionEditHeading2URL->setEnabled (true);
2270 actionEditBugzilla2URL->setEnabled (true);
2272 if ( bo->getVymLink().isEmpty() )
2274 actionEditOpenVymLink->setEnabled (false);
2275 actionEditDeleteVymLink->setEnabled (false);
2278 actionEditOpenVymLink->setEnabled (true);
2279 actionEditDeleteVymLink->setEnabled (true);
2281 actionEditVymLink->setEnabled (true);
2283 actionEditCopy->setEnabled (true);
2284 actionEditCut->setEnabled (true);
2285 actionEditPaste->setEnabled (true);
2286 actionEditMoveUp->setEnabled (true);
2287 actionEditMoveDown->setEnabled (true);
2288 actionEditToggleScroll->setEnabled (true);
2289 actionEditHeading->setEnabled (true);
2290 actionEditDelete->setEnabled (true);
2291 actionEditAddBranch->setEnabled (true);
2292 actionEditAddBranchAbove->setEnabled (true);
2293 actionEditAddBranchBelow->setEnabled (true);
2294 actionEditImportAdd->setEnabled (true);
2295 actionEditImportReplace->setEnabled (true);
2296 actionEditSaveBranch->setEnabled (true);
2297 actionEditSelectFirst->setEnabled (true);
2298 actionEditSelectLast->setEnabled (true);
2299 actionEditToggleFloatExport->setEnabled (false);
2300 actionFormatPickColor->setEnabled (true);
2301 actionFormatColorBranch->setEnabled (true);
2302 actionFormatColorSubtree->setEnabled (true);
2303 switch (selection->getFrameType())
2306 actionFormatFrameNone->setOn(true);
2309 actionFormatFrameRectangle->setOn(true);
2315 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2317 standardFlagsDefault->setEnabled (false);
2319 actionEditOpenURL->setEnabled (false);
2320 actionEditURL->setEnabled (false);
2321 actionEditHeading2URL->setEnabled (false);
2322 actionEditBugzilla2URL->setEnabled (false);
2323 actionEditOpenVymLink->setEnabled (false);
2324 actionEditVymLink->setEnabled (false);
2325 actionEditDeleteVymLink->setEnabled (false);
2327 actionEditCopy->setEnabled (true);
2328 actionEditCut->setEnabled (true);
2329 actionEditPaste->setEnabled (false); //FIXME
2330 actionEditMoveUp->setEnabled (false);
2331 actionEditMoveDown->setEnabled (false);
2332 actionEditToggleScroll->setEnabled (false);
2333 actionEditHeading->setEnabled (false);
2334 actionEditDelete->setEnabled (true);
2335 actionEditAddBranch->setEnabled (false);
2336 actionEditAddBranchAbove->setEnabled (false);
2337 actionEditAddBranchBelow->setEnabled (false);
2338 actionEditImportAdd->setEnabled (false);
2339 actionEditSaveBranch->setEnabled (false);
2340 actionEditImportReplace->setEnabled (false);
2341 actionEditSelectFirst->setEnabled (false);
2342 actionEditSelectLast->setEnabled (false);
2343 actionEditToggleFloatExport->setOn
2344 ( ((FloatImageObj*)(selection))->getFloatExport() );
2345 actionFormatPickColor->setEnabled (false);
2346 actionFormatColorBranch->setEnabled (false);
2347 actionFormatColorSubtree->setEnabled (false);
2352 standardFlagsDefault->setEnabled (false);
2354 actionEditCopy->setEnabled (false);
2355 actionEditCut->setEnabled (false);
2356 actionEditPaste->setEnabled (false);
2357 actionEditMoveUp->setEnabled (false);
2358 actionEditMoveDown->setEnabled (false);
2359 actionEditToggleScroll->setEnabled (false);
2360 actionEditOpenURL->setEnabled (false);
2361 actionEditURL->setEnabled (false);
2362 actionEditOpenVymLink->setEnabled (false);
2363 actionEditVymLink->setEnabled (false);
2364 actionEditDeleteVymLink->setEnabled (false);
2365 actionEditHeading2URL->setEnabled (false);
2366 actionEditBugzilla2URL->setEnabled (false);
2367 actionEditHeading->setEnabled (false);
2368 actionEditDelete->setEnabled (false);
2369 actionEditAddBranch->setEnabled (false);
2370 actionEditAddBranchAbove->setEnabled (false);
2371 actionEditAddBranchBelow->setEnabled (false);
2372 actionEditSaveBranch->setEnabled (false);
2373 actionEditImportReplace->setEnabled (false);
2374 actionEditSelectFirst->setEnabled (false);
2375 actionEditSelectLast->setEnabled (false);
2376 actionEditToggleFloatExport->setEnabled (false);
2377 actionFormatPickColor->setEnabled (false);
2378 actionFormatColorBranch->setEnabled (false);
2379 actionFormatColorSubtree->setEnabled (false);
2383 void MapEditor::setLinkStyle (LinkStyle ls)
2388 bo=mapCenter->first();
2392 bo->setLinkStyle(bo->getDefLinkStyle());
2399 LinkStyle MapEditor::getLinkStyle ()
2404 void MapEditor::setLinkColor(QColor c)
2410 void MapEditor::setLinkColorHint()
2412 // called from setLinkColorHint(lch) or at end of parse
2414 bo=mapCenter->first();
2422 void MapEditor::setLinkColorHint(LinkColorHint lch)
2428 void MapEditor::toggleLinkColorHint()
2430 if (linkcolorhint==HeadingColor)
2431 linkcolorhint=DefaultColor;
2433 linkcolorhint=HeadingColor;
2435 bo=mapCenter->first();
2443 LinkColorHint MapEditor::getLinkColorHint()
2445 return linkcolorhint;
2448 QColor MapEditor::getDefLinkColor()
2450 return deflinkcolor;
2453 void MapEditor::selectLinkColor()
2455 // Finish open lineEdits
2456 if (lineedit) finishedLineEditNoSave();
2458 QColor col = QColorDialog::getColor( deflinkcolor, this );
2459 if ( !col.isValid() ) return;
2460 setLinkColor( col );
2464 void MapEditor::toggleScroll()
2466 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2468 BranchObj *bo=((BranchObj*)(selection));
2469 if (bo->countBranches()==0) return;
2470 if (bo->getDepth()==0) return;
2472 saveState(PartOfMap,selection);
2479 void MapEditor::unScrollAll()
2482 bo=mapCenter->first();
2485 if (bo->isScrolled()) bo->toggleScroll();
2490 void MapEditor::loadFloatImage ()
2493 (typeid(*selection) == typeid(BranchObj)) ||
2494 (typeid(*selection) == typeid(MapCenterObj)) )
2496 BranchObj *bo=((BranchObj*)(selection));
2498 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2499 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2500 ImagePreview *p =new ImagePreview (fd);
2501 fd->setContentsPreviewEnabled( TRUE );
2502 fd->setContentsPreview( p, p );
2503 fd->setPreviewMode( QFileDialog::Contents );
2504 fd->setCaption(tr("vym - Load image"));
2505 fd->setDir (lastImageDir);
2509 if ( fd->exec() == QDialog::Accepted )
2512 saveState(PartOfMap,selection);
2513 QString fn=fd->selectedFile();
2514 lastImageDir=fn.left(fn.findRev ("/"));
2515 bo->addFloatImage();
2516 // FIXME check if load was successful
2517 bo->getLastFloatImage()->load(fn);
2518 bo->getLastFloatImage()->setOriginalFilename(fn);
2519 mapCenter->reposition();
2526 void MapEditor::saveFloatImage (int item)
2529 (typeid(*selection) == typeid(FloatImageObj)) )
2531 FloatImageObj *fio=((FloatImageObj*)(selection));
2532 const char* fmt = saveImageFormatMenu->text(item);
2534 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2535 fd->addFilter ("PNG (*.png)");
2536 fd->addFilter ("BMP (*.bmp)");
2537 fd->addFilter ("XBM (*.xbm)");
2538 fd->addFilter ("JPG (*.jpg)");
2539 fd->addFilter ("XPM (*.xpm)");
2540 fd->addFilter ("GIF (*.gif)");
2541 fd->addFilter ("PNM (*.pnm)");
2542 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2543 fd->setCaption(tr("vym - Save image as ") + fmt);
2544 fd->setMode( QFileDialog::AnyFile );
2545 fd->setSelection (fio->getOriginalFilename());
2549 if ( fd->exec() == QDialog::Accepted )
2551 if (QFile (fd->selectedFile()).exists() )
2553 QMessageBox mb( "VYM",
2554 tr("The file ") + fd->selectedFile() +
2555 tr(" exists already. "
2556 "Do you want to overwrite it?"),
2557 QMessageBox::Warning,
2558 QMessageBox::Yes | QMessageBox::Default,
2559 QMessageBox::Cancel | QMessageBox::Escape,
2560 QMessageBox::QMessageBox::NoButton );
2562 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2563 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2566 case QMessageBox::Yes:
2569 case QMessageBox::Cancel:
2575 fio->save (fd->selectedFile(),fmt);
2580 void MapEditor::toggleFloatExport()
2583 (typeid(*selection) == typeid(FloatImageObj))||
2584 (typeid(*selection) == typeid(FloatObj)) )
2586 FloatImageObj *fio=((FloatImageObj*)(selection));
2587 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2591 void MapEditor::setFrame(const FrameType &t)
2594 (typeid(*selection) == typeid(BranchObj)) ||
2595 (typeid(*selection) == typeid(MapCenterObj)) )
2597 selection->setFrameType (t);
2598 mapCenter->reposition();
2599 selection->updateLink();
2603 void MapEditor::importDir(BranchObj *dst, QDir d)
2606 (typeid(*selection) == typeid(BranchObj)) ||
2607 (typeid(*selection) == typeid(MapCenterObj)) )
2611 // Traverse directories
2612 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2613 const QFileInfoList *dirlist = d.entryInfoList();
2614 QFileInfoListIterator itdir( *dirlist );
2617 while ( (fi = itdir.current()) != 0 )
2619 if (fi->fileName() != "." && fi->fileName() != ".." )
2622 bo=dst->getLastBranch();
2623 bo->setHeading (fi->fileName() );
2624 bo->setColor (QColor("blue"),false);
2626 if ( !d.cd(fi->fileName()) )
2627 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2637 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2638 const QFileInfoList *filelist = d.entryInfoList();
2639 QFileInfoListIterator itfile( *filelist );
2641 while ( (fi = itfile.current()) != 0 )
2644 bo=dst->getLastBranch();
2645 bo->setHeading (fi->fileName() );
2646 bo->setColor (QColor("black"),false);
2652 void MapEditor::importDir()
2655 (typeid(*selection) == typeid(BranchObj)) ||
2656 (typeid(*selection) == typeid(MapCenterObj)) )
2658 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2659 fd->setMode (QFileDialog::DirectoryOnly);
2660 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2661 fd->setCaption(tr("VYM - Choose directory structur to import"));
2665 if ( fd->exec() == QDialog::Accepted )
2667 BranchObj *bo=((BranchObj*)(selection));
2668 importDir (bo,QDir(fd->selectedFile()) );
2669 mapCenter->reposition();
2676 void MapEditor::followLink(int i)
2678 BranchObj *bo=((BranchObj*)(selection))->linkTargetAt(i);
2681 selection->unselect();
2683 selection->select();
2684 ensureSelectionVisible();
2688 void MapEditor::testFunction()
2690 cout << "MapEditor::testFunction() called\n";
2693 void MapEditor::ensureSelectionVisible()
2695 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2697 if (selection->getOrientation() == OrientLeftOfCenter)
2698 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2700 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2701 ensureVisible (p.x(), p.y() );
2705 void MapEditor::updateViewCenter()
2707 // Update movingCenter, so that we can zoom comfortably later
2708 QRect rc = QRect( contentsX(), contentsY(),
2709 visibleWidth(), visibleHeight() );
2710 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2711 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2712 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2715 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2717 // Lineedits are already closed by preceding
2718 // mouseEvent, we don't need to close here.
2720 QPoint p = inverseWorldMatrix().map(e->pos());
2721 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2724 { // MapObj was found
2725 if (selection != lmo)
2727 // select the MapObj
2728 if (selection) selection->unselect();
2730 selection->select();
2736 if (typeid(*selection)==typeid(BranchObj) ||
2737 typeid(*selection)==typeid(MapCenterObj) )
2739 // Context Menu on branch or mapcenter
2741 branchContextMenu->popup(e->globalPos() );
2743 if (typeid(*selection)==typeid(FloatImageObj))
2745 // Context Menu on floatimage
2747 floatimageContextMenu->popup(e->globalPos() );
2751 { // No MapObj found, we are on the Canvas itself
2752 // Context Menu on Canvas
2754 canvasContextMenu->popup(e->globalPos() );
2758 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2760 // Finish open lineEdits
2761 if (lineedit) finishedLineEditNoSave();
2763 QPoint p = inverseWorldMatrix().map(e->pos());
2764 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2766 // Special case: CTRL is pressed
2767 if (e->state() & QMouseEvent::ControlButton)
2769 if (actionModModeColor->isOn())
2771 if (e->state() & QMouseEvent::ControlButton)
2774 setCursor (pickColorCursor);
2778 if (actionModModeLink->isOn())
2780 BranchObj *bo_begin=NULL;
2782 bo_begin=(BranchObj*)(lmo);
2785 ((typeid(*selection) == typeid(BranchObj)) ||
2786 (typeid(*selection) == typeid(MapCenterObj))) )
2787 bo_begin=(BranchObj*)(selection);
2791 linkingObj_src=bo_begin;
2792 tmpLink=new LinkObj (mapCanvas);
2793 tmpLink->setBegin (bo_begin);
2794 tmpLink->setEnd (p);
2795 tmpLink->updateLink();
2796 tmpLink->setVisibility (true);
2803 { // MapObj was found
2804 if (selection != lmo)
2806 // select the MapObj
2807 if (selection) selection->unselect();
2809 selection->select();
2814 // Check, if systemFlag clicked
2815 if (typeid(*selection)==typeid(BranchObj) ||
2816 typeid(*selection)==typeid(MapCenterObj) )
2818 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
2819 if (!foname.isEmpty())
2821 // Do not move, if systemFlag clicked
2825 if (foname=="vymLink")
2827 mainWindow->editOpenVymLink();
2828 // tabWidget may change, better return now
2829 // before segfaulting...
2833 mainWindow->windowToggleNoteEditor();
2837 // Left Button Move Branches
2838 if (e->button() == QMouseEvent::LeftButton )
2840 movingObj=selection;
2841 movingObj_start.setX( p.x() - selection->x() );
2842 movingObj_start.setY( p.y() - selection->y() );
2844 // Middle Button Toggle Scroll
2845 // (On Mac OS X this won't work, but we still have
2846 // a button in the toolbar)
2847 if (e->button() == QMouseEvent::MidButton )
2853 { // No MapObj found, we are on the Canvas itself
2854 // Left Button move Pos of CanvasView
2855 if (e->button() == QMouseEvent::LeftButton )
2857 movingObj=NULL; // move Content not Obj
2858 movingObj_start=e->globalPos();
2859 movingCont_start=QPoint (contentsX(), contentsY() );
2860 movingVec=QPoint(0,0);
2861 setCursor(handOpenCursor);
2866 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
2868 QPoint p = inverseWorldMatrix().map(e->pos());
2870 // Move the selected MapObj
2871 if ( selection && movingObj)
2873 ensureVisible (p.x(),p.y());
2875 // Now move the selection, but add relative position
2876 // (movingObj_start) where selection was chosen with
2877 // mousepointer. (This avoids flickering resp. jumping
2878 // of selection back to absPos)
2880 LinkableMapObj *lmosel;
2881 lmosel = dynamic_cast <LinkableMapObj*> (selection);
2883 // Check if we could link
2884 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
2887 if (typeid(*selection) == typeid(FloatImageObj))
2891 FloatObj *fo=(FloatObj*)(selection);
2892 if (fo->getLinkStyle()==StyleUndef)
2894 fo->setLinkStyle(fo->getDefLinkStyle());
2895 fo->setLinkColor(fo->getParObj()->getLinkColor());
2897 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2901 // Relink float to new mapcenter or branch, if shift is pressed
2902 // Only relink, if selection really has a new parent
2903 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
2904 ( (typeid(*lmo)==typeid(BranchObj)) ||
2905 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
2906 ( lmo != fo->getParObj())
2909 if (typeid(*fo) == typeid(FloatImageObj))
2911 FloatImageObj *fio=(FloatImageObj*)(fo);
2912 ((BranchObj*)(lmo))->addFloatImage (fio);
2914 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2915 fio=((BranchObj*)(lmo))->getLastFloatImage();
2918 selection=(LinkableMapObj*)(fio);
2919 selection->select();
2920 movingObj=(MapObj*)(fio);
2921 // setLinkStyle calls updateLink, only set it once
2922 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
2923 fio->setLinkStyle (fio->getDefLinkStyle());
2926 // TODO if (typeid(*selection) == typeid(FloatTextObj))
2928 } else // selection != a FloatObj
2930 if (lmosel->getDepth()==0)
2932 if (e->state() == (LeftButton | !ShiftButton))
2933 // If mapCenter is moved, move all the rest by default, too.
2934 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2936 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2939 if (lmosel->getDepth()==1)
2941 // depth==1, mainbranch
2943 saveState(PartOfMap,lmosel);
2944 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2948 if (lmosel->getOrientation() == OrientLeftOfCenter)
2949 // Add width of bbox here, otherwise alignRelTo will cause jumping around
2950 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
2951 p.y()-movingObj_start.y() );
2953 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2955 // reposition subbranch
2956 lmosel->reposition();
2957 //ensureSelectionVisible();
2959 if (lmo && (lmo!=selection) &&
2960 (typeid(*lmo) == typeid(BranchObj) ||
2961 (typeid(*lmo) == typeid(MapCenterObj) )
2964 if (e->state() & QMouseEvent::ControlButton)
2966 // Special case: CTRL to link below lmo
2967 lmosel->setParObjTmp (lmo,p,+1);
2969 else if (e->state() & QMouseEvent::ShiftButton)
2970 lmosel->setParObjTmp (lmo,p,-1);
2972 lmosel->setParObjTmp (lmo,p,0);
2975 if (lmo &&(lmo==selection))
2976 // Could link to myself (happens sometimes...)
2977 lmosel->unsetParObjTmp();
2979 // no Obj under selection, go back to original Parent
2980 lmosel->unsetParObjTmp();
2984 } // no FloatImageObj
2988 } // selection && moving_obj
2990 // Draw a link from one branch to another
2993 tmpLink->setEnd (p);
2994 tmpLink->updateLink();
2998 if (!movingObj && !pickingColor &&!drawingLink)
3000 QPoint p=e->globalPos();
3001 movingVec.setX(-p.x() + movingObj_start.x() );
3002 movingVec.setY(-p.y() + movingObj_start.y() );
3003 setContentsPos( movingCont_start.x() + movingVec.x(),
3004 movingCont_start.y() + movingVec.y());
3011 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3013 LinkableMapObj *dst;
3014 // Have we been picking color?
3018 setCursor (ArrowCursor);
3019 // Check if we are over another branch
3020 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3021 if (dst && selection)
3023 if (e->state() & QMouseEvent::ShiftButton)
3025 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3026 ((BranchObj*)(selection))->setLinkColor ();
3030 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3031 ((BranchObj*)(selection))->setLinkColor ();
3037 // Have we been drawing a link?
3041 // Check if we are over another branch
3042 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3043 if (dst && selection)
3045 tmpLink->setEnd ( ((BranchObj*)(dst)) );
3046 tmpLink->updateLink();
3047 tmpLink->activate();
3058 // Have we been moving something?
3059 if ( selection && movingObj )
3061 // Check if we are over another branch, but ignore
3062 // any found LMOs, which are FloatObjs
3063 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3064 ((LinkableMapObj*)(selection)) );
3067 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3072 // Now check, if we have been moving a branch
3073 if (typeid(*selection) == typeid(BranchObj) )
3075 // save the position in case we link to mapcenter
3076 QPoint savePos=QPoint (selection->x(),selection->y() );
3078 // Reset the temporary drawn link to the original one
3079 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3085 // TODO we also could check, if dest and src are on same branch,
3086 // then it would be sufficient to saveState of this branch
3088 // Modifiers allow to insert above/below dst
3089 if (e->state() & QMouseEvent::ShiftButton)
3091 ((BranchObj*)(selection))->moveBranchTo
3094 ((BranchObj*)(dst))->getNum()
3096 //if (selection) selection->select();
3098 if (e->state() & QMouseEvent::ControlButton)
3100 ((BranchObj*)(selection))->moveBranchTo
3103 ((BranchObj*)(dst))->getNum()+1
3105 //if (selection) selection->select();
3108 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
3109 if (dst->getDepth()==0)
3110 ((BranchObj*)(selection))->move (savePos);
3113 // Draw the original link, before selection was moved around
3114 mapCenter->reposition();
3116 // Finally resize canvas, if needed
3121 // maybe we moved View: set old cursor
3122 setCursor (ArrowCursor);
3126 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3128 // Finish open lineEdits
3129 if (lineedit) finishedLineEditNoSave();
3131 if (e->button() == QMouseEvent::LeftButton )
3133 QPoint p = inverseWorldMatrix().map(e->pos());
3134 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3135 if (lmo) { // MapObj was found
3136 // First select the MapObj than edit heading
3137 if (selection) selection->unselect();
3139 selection->select();
3141 saveState(PartOfMap,selection);
3147 void MapEditor::resizeEvent (QResizeEvent* e)
3149 QCanvasView::resizeEvent( e );
3152 if (!fileName.isEmpty()) s=fileName;