3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <qpopupmenu.h>
9 #include <qpaintdevicemetrics.h>
11 #include <qfiledialog.h>
14 #include <qcolordialog.h>
17 #include <qinputdialog.h>
26 #include "texteditor.h"
27 #include "linkablemapobj.h"
30 #include "mainwindow.h"
31 #include "extrainfodialog.h"
34 #include "icons/flag-note.xpm"
35 #include "icons/flag-url.xpm"
36 #include "icons/flag-vymlink.xpm"
37 #include "icons/flag-scrolled-right.xpm"
38 #include "icons/flag-tmpUnscrolled-right.xpm"
39 #include "icons/flag-questionmark.xpm"
40 #include "icons/flag-exclamationmark.xpm"
41 #include "icons/flag-hook-green.xpm"
42 #include "icons/flag-cross-red.xpm"
43 #include "icons/flag-stopsign.xpm"
44 #include "icons/flag-smiley-good.xpm"
45 #include "icons/flag-smiley-sad.xpm"
46 #include "icons/flag-clock.xpm"
47 #include "icons/flag-lamp.xpm"
48 #include "icons/flag-arrow-up.xpm"
49 #include "icons/flag-arrow-down.xpm"
50 #include "icons/flag-thumb-up.xpm"
51 #include "icons/flag-thumb-down.xpm"
52 #include "icons/flag-heart.xpm"
53 #include "icons/flag-flash.xpm"
54 #include "icons/flag-lifebelt.xpm"
56 extern TextEditor *textEditor;
57 extern int statusbarTime;
58 extern Main *mainWindow;
59 extern FlagRowObj *systemFlagsDefault;
60 extern FlagRowObj *standardFlagsDefault;
61 extern MapEditor *clipboardME;
63 extern QAction *actionFileSave;
64 extern QAction *actionEditUndo;
65 extern QAction *actionEditCopy;
66 extern QAction *actionEditCut;
67 extern QAction *actionEditPaste;
68 extern QAction *actionEditMoveUp;
69 extern QAction *actionEditMoveDown;
70 extern QAction *actionEditToggleScroll;
71 extern QAction *actionEditOpenURL;
72 extern QAction *actionEditURL;
73 extern QAction *actionEditHeading2URL;
74 extern QAction *actionEditBugzilla2URL;
75 extern QAction *actionEditOpenVymLink;
76 extern QAction *actionEditVymLink;
77 extern QAction *actionEditDeleteVymLink;
78 extern QAction *actionEditHeading;
79 extern QAction *actionEditDelete;
80 extern QAction *actionEditAddBranch;
81 extern QAction *actionEditAddBranchAbove;
82 extern QAction *actionEditAddBranchBelow;
83 extern QAction *actionEditImportAdd;
84 extern QAction *actionEditImportReplace;
85 extern QAction *actionEditSaveBranch;
86 extern QAction *actionEditSelectFirst;
87 extern QAction *actionEditSelectLast;
88 extern QAction *actionEditLoadImage;
89 extern QAction *actionEditToggleFloatExport;
91 extern QAction* actionFormatPickColor;
92 extern QAction* actionFormatColorBranch;
93 extern QAction* actionFormatColorSubtree;
94 extern QAction *actionFormatLinkColorHint;
95 extern QAction *actionFormatBackColor;
96 extern QAction *actionFormatLinkColor;
98 extern QActionGroup *actionGroupFormatFrameTypes;
99 extern QAction *actionFormatFrameNone;
100 extern QAction *actionFormatFrameRectangle;
102 extern QActionGroup *actionGroupFormatLinkStyles;
103 extern QAction *actionFormatLinkStyleLine;
104 extern QAction *actionFormatLinkStyleParabel;
105 extern QAction *actionFormatLinkStylePolyLine;
106 extern QAction *actionFormatLinkStylePolyParabel;
108 extern QAction *actionViewToggleNoteEditor;
110 extern QAction *actionSettingsAutoedit;
111 extern QAction *actionSettingsAutoselectHeading;
112 extern QAction *actionSettingsAutoselectText;
113 extern QAction *actionSettingsPasteNewHeading;
115 extern QPopupMenu *branchContextMenu;
116 extern QPopupMenu *floatimageContextMenu;
117 extern QPopupMenu *saveImageFormatMenu;
118 extern QPopupMenu *exportImageFormatMenu;
119 extern QPopupMenu *canvasContextMenu;
121 extern Settings settings;
124 ///////////////////////////////////////////////////////////////////////
125 ///////////////////////////////////////////////////////////////////////
126 MapEditor::MapEditor(
127 QWidget* parent, bool interactive, const char* name, WFlags f) :
128 QCanvasView(parent,name,f)
130 //cout << "Constructor ME "<<this<<endl;
132 mapCanvas = new QCanvas(1000,800);
133 mapCanvas->setAdvancePeriod(30);
135 setCanvas (mapCanvas);
137 setVScrollBarMode ( QScrollView::AlwaysOn );
138 setHScrollBarMode ( QScrollView::AlwaysOn );
140 // Now create the _global_ system flags _once_:
141 // (Later all OrnamentedObj copy from this
142 // and set their own canvas)
143 if (!systemFlagsDefault)
145 systemFlagsDefault = new FlagRowObj (mapCanvas);
146 systemFlagsDefault->setVisibility (false);
147 systemFlagsDefault->setName ("systemFlagsDef");
149 FlagObj *fo = new FlagObj (mapCanvas);
150 fo->load(QPixmap(flag_note_xpm));
152 fo->setToolTip(tr("Note"));
153 systemFlagsDefault->addFlag (fo); // makes deep copy
155 fo->load(QPixmap(flag_url_xpm));
157 fo->setToolTip(tr("WWW Document (external)"));
158 systemFlagsDefault->addFlag (fo);
160 fo->load(QPixmap(flag_vymlink_xpm));
161 fo->setName("vymLink");
162 fo->setToolTip(tr("Link to another vym map"));
163 systemFlagsDefault->addFlag (fo);
165 fo->load(QPixmap(flag_scrolled_right_xpm));
166 fo->setName("scrolledright");
167 fo->setToolTip(tr("subtree is scrolled"));
168 systemFlagsDefault->addFlag (fo);
170 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
171 fo->setName("tmpUnscrolledright");
172 fo->setToolTip(tr("subtree is temporary scrolled"));
173 systemFlagsDefault->addFlag (fo);
176 if (!standardFlagsDefault)
178 standardFlagsDefault = new FlagRowObj (mapCanvas);
179 standardFlagsDefault->setVisibility (false);
180 standardFlagsDefault->setName ("standardFlagsDef");
182 FlagObj *fo = new FlagObj (mapCanvas);
183 fo->load(QPixmap(flag_exclamationmark_xpm));
184 fo->setName("exclamationmark");
185 fo->setToolTip(tr("Take care!"));
186 standardFlagsDefault->addFlag (fo); // makes deep copy
188 fo->load(QPixmap(flag_questionmark_xpm));
189 fo->setName("questionmark");
190 fo->setToolTip(tr("Really?"));
191 standardFlagsDefault->addFlag (fo);
193 fo->load(QPixmap(flag_hook_green_xpm));
194 fo->setName("hook-green");
195 fo->setToolTip(tr("ok!"));
196 standardFlagsDefault->addFlag (fo);
198 fo->load(QPixmap(flag_cross_red_xpm));
199 fo->setName("cross-red");
200 fo->setToolTip(tr("Not ok!"));
201 standardFlagsDefault->addFlag (fo);
203 fo->load(QPixmap(flag_stopsign_xpm));
204 fo->setName("stopsign");
205 fo->setToolTip(tr("This won't work!"));
206 standardFlagsDefault->addFlag (fo);
208 fo->load(QPixmap(flag_smiley_good_xpm));
209 fo->setName("smiley-good");
210 fo->setToolTip(tr("Good"));
211 standardFlagsDefault->addFlag (fo);
213 fo->load(QPixmap(flag_smiley_sad_xpm));
214 fo->setName("smiley-sad");
215 fo->setToolTip(tr("Bad"));
216 standardFlagsDefault->addFlag (fo);
218 fo->load(QPixmap(flag_clock_xpm));
219 fo->setName("clock");
220 fo->setToolTip(tr("Time critical"));
221 standardFlagsDefault->addFlag (fo);
223 fo->load(QPixmap(flag_lamp_xpm));
225 fo->setToolTip(tr("Idea!"));
226 standardFlagsDefault->addFlag (fo);
228 fo->load(QPixmap(flag_arrow_up_xpm));
229 fo->setName("arrow-up");
230 fo->setToolTip(tr("Important"));
231 standardFlagsDefault->addFlag (fo);
233 fo->load(QPixmap(flag_arrow_down_xpm));
234 fo->setName("arrow-down");
235 fo->setToolTip(tr("Unimportant"));
236 standardFlagsDefault->addFlag (fo);
238 fo->load(QPixmap(flag_thumb_up_xpm));
239 fo->setName("thumb-up");
240 fo->setToolTip(tr("I like this"));
241 standardFlagsDefault->addFlag (fo);
243 fo->load(QPixmap(flag_thumb_down_xpm));
244 fo->setName("thumb-down");
245 fo->setToolTip(tr("I do not like this"));
246 standardFlagsDefault->addFlag (fo);
248 fo->load(QPixmap(flag_heart_xpm));
249 fo->setName("heart");
250 fo->setToolTip(tr("I just love... "));
251 standardFlagsDefault->addFlag (fo);
253 fo->load(QPixmap(flag_flash_xpm));
254 fo->setName("flash");
255 fo->setToolTip(tr("Dangerous"));
256 standardFlagsDefault->addFlag (fo);
258 fo->load(QPixmap(flag_lifebelt_xpm));
259 fo->setName("lifebelt");
260 fo->setToolTip(tr("This will help"));
261 standardFlagsDefault->addFlag (fo);
266 mapCenter = new MapCenterObj(mapCanvas);
267 mapCenter->setVisibility (true);
268 mapCenter->setMapEditor (this);
269 mapCenter->setHeading (tr("New Map"));
273 lineedit = new QLineEdit(this, "lineedit" );
274 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
277 actColor=black; setColor (actColor);
278 deflinkcolor=QColor (0,0,255);
279 linkcolorhint=DefaultColor;
280 linkstyle=StylePolyParabel;
281 mapCanvas->setBackgroundColor (white);
283 // Create bitmap cursors, patform dependant
284 #if defined(Q_OS_MACX)
285 #include "icons/cursorhandopen16.xpm"
286 #include "icons/cursorcolorpicker16.xpm"
287 QBitmap cb( 16, 16, chandopen, TRUE );
288 QBitmap cm( 16, 16, chandopenmask, TRUE );
289 handOpenCursor=QCursor ( cb, cm );
290 // set hot spot to tip of picker
291 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
293 #include "icons/cursorhandopen.xpm"
294 #include "icons/cursorcolorpicker.xpm"
296 QBitmap cb( 32, 32, chandopen, TRUE );
297 QBitmap cm( 32, 32, chandopenmask, TRUE );
298 handOpenCursor=QCursor ( cb, cm );
299 // set hot spot to tip of picker
300 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
303 modifierMode=pickColorMode;
304 modifierMode=linkObjectsMode; // FIXME testing
323 // Initialize find routine
330 blockreposition=false;
331 isInteractive=interactive;
333 // Create temporary files
336 // Initially set movingCentre
339 mapCenter->reposition(); // for positioning heading
342 MapEditor::~MapEditor()
344 //cout <<"Destructor MapEditor\n";
345 if (isInteractive) delTmpDirs();
348 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
352 QColor MapEditor::color()
357 QColor MapEditor::backgroundColor()
359 return mapCanvas->backgroundColor();
362 MapCenterObj* MapEditor::getMapCenter()
367 QCanvas* MapEditor::getCanvas()
372 void MapEditor::adjustCanvasSize()
374 // To adjust the canvas to map, viewport size and position, we have to
375 // do some coordinate magic...
377 // Get rectangle of (scroll-)view.
378 // We want to be in canvas coords, so
379 // we map. Important if view is zoomed...
380 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
381 visibleWidth(), visibleHeight()) );
383 // Now we need the bounding box of view AND map to calc the correct canvas size.
384 // Why? Because if the map itself is moved out of view, the view has to be enlarged
385 // to avoid jumping aroung...
386 QRect map=mapCenter->getTotalBBox();
388 // right edge - left edge
389 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
390 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
393 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
394 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
397 // move the map on canvas (in order to not move it on screen) this is neccessary
398 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
399 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
400 // to scroll to an empty area of canvas to the left.
401 // b) if topleft corner of map left of or above topleft of canvas
405 if (cw > mapCanvas->width() )
407 if (map.x()<0) dx=-map.x();
409 if (cw < mapCanvas->width() )
410 dx=-min (view.x(),map.x());
411 if (ch > mapCanvas->height() )
413 if (map.y()<0) dy=-map.y();
415 if (ch < mapCanvas->height() )
417 dy=-min (view.y(),map.y());
419 // We really have to resize now. Let's go...
420 mapCanvas->resize (cw,ch);
421 if ( (dx!=0) || (dy!=0) )
423 mapCenter->moveAllBy(dx,dy);
424 mapCenter->reposition();
426 // scroll the view (in order to not move map on screen)
432 bool MapEditor::blockReposition()
434 return blockreposition;
437 void MapEditor::makeTmpDirs()
439 // Create unique temporary directories
440 char tmpdir[]="/tmp/vym-XXXXXX";
441 bakMapDir=mkdtemp(tmpdir);
442 makeSubDirs(bakMapDir);
443 // FIXME set permissions
444 // and maybe use QT method for portability
447 void MapEditor::delTmpDirs()
449 //FIXME delete tmp directory, better use QT methods here:
450 system ( "rm -rf "+ bakMapDir );
454 void MapEditor::makeSubDirs(const QString &s)
462 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, SaveMode savemode)
464 // tmpdir temporary directory to which data will be writte
465 // prefix mapname, which will be appended to images etc.
466 // writeflags Only write flags for "real" save of map, not undo
467 // offset offset of bbox of whole map in canvas.
468 // Needed for XML export
469 // completeMap if false, only vympart will be written, without
486 ls="StylePolyParabel";
490 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
492 if (linkcolorhint==HeadingColor)
493 colhint=attribut("linkColorHint","HeadingColor");
495 QString mapAttr=attribut("version",__VYM_VERSION__);
496 if (savemode==CompleteMap)
497 mapAttr+= attribut("author",mapCenter->getAuthor()) +
498 attribut("comment",mapCenter->getComment()) +
499 attribut("date",mapCenter->getDate()) +
500 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
501 attribut("linkStyle", ls ) +
502 attribut("linkColor", deflinkcolor.name() ) +
504 s+=beginElement("vymmap",mapAttr);
507 // Find the used flags while traversing the tree
508 standardFlagsDefault->resetUsedCounter();
510 // Build xml recursivly
511 if (savemode==CompleteMap)
512 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
515 if ( undoSelection &&
516 typeid(*undoSelection) == typeid(BranchObj) )
517 s+=((BranchObj*)(undoSelection))->saveToDir(tmpdir,prefix,offset);
520 // Save local settings
521 s+=settings.getXMLData (destPath);
525 s+=valueElement("select",selection->getSelectString());
528 s+=endElement("vymmap");
531 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
536 void MapEditor::saveState()
538 saveState (CompleteMap,NULL);
541 void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part)
543 // all binary data is saved in bakMapDir (created in Constructor)
544 // the xml data itself is kept in memory in backupXML
546 // For faster write/read of data, a part of the map can be
547 // written. Then the undoSelection will mark, which part of the
548 // map should be replaced if an undo is wanted later.
550 if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) )
552 // Writing a vympart only is useful for BranchObj
554 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
558 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap);
562 void MapEditor::finishedLineEditNoSave()
564 // This is called by finishedLineEdit or any MapEditor method,
565 // which wants to assure, that lineedits finish, before e.g. a branch is
568 // After calling LineEdit and using the clipboard, the
569 // focus is not any longer on the main widget, we
570 // have to restore it using parentWidget()->setFocus()
574 editingBO->setHeading(lineedit->text() );
576 lineedit->releaseKeyboard();
578 parentWidget()->setFocus();
579 mapCenter->reposition();
581 ensureSelectionVisible();
586 bool MapEditor::isDefault()
591 bool MapEditor::isUnsaved()
596 bool MapEditor::hasChanged()
601 void MapEditor::setChanged()
606 actionEditUndo->setEnabled (true);
607 actionFileSave->setEnabled (true);
611 void MapEditor::closeMap()
613 // Finish open lineEdits
614 if (lineedit) finishedLineEditNoSave();
616 // Unselect before disabling the toolbar actions
617 if (selection) selection->unselect();
625 void MapEditor::setFilePath(QString fname)
627 setFilePath (fname,fname);
630 void MapEditor::setFilePath(QString fname, QString destname)
636 // If fname is not an absolute path, complete it
637 filePath=QDir(fname).absPath();
638 fileDir=filePath.left (1+filePath.findRev ("/"));
640 // Set short name, too. Search from behind:
641 int i=fileName.findRev("/");
642 if (i>=0) fileName=fileName.remove (0,i+1);
644 // Forget the .vym (or .xml) for name of map
645 mapName=fileName.left(fileName.findRev(".",-1,true) );
648 QString MapEditor::getFilePath()
653 QString MapEditor::getFileName()
658 QString MapEditor::getMapName()
663 QString MapEditor::getDestPath()
668 int MapEditor::load (QString &fname, const LoadMode &lmode)
670 // Finish open lineEdits
671 if (lineedit) finishedLineEditNoSave();
677 if (selection) selection->unselect();
680 mapCenter->setMapEditor(this);
681 // (map state is set later at end of load...)
685 saveState(PartOfMap,selection);
689 mapBuilderHandler handler;
692 // I am paranoid: file should exist anyway
693 // according to check in mainwindow.
696 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
697 tr("Couldn't open map " +fname)+".");
701 blockreposition=true;
702 QXmlInputSource source( file);
703 QXmlSimpleReader reader;
704 reader.setContentHandler( &handler );
705 reader.setErrorHandler( &handler );
706 handler.setMapEditor( this );
707 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
708 handler.setLoadMode (lmode);
709 bool ok = reader.parse( source );
710 blockreposition=false;
714 mapCenter->reposition();
724 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
725 tr( handler.errorProtocol() ) );
727 // Still return "success": the map maybe at least
728 // partially read by the parser
735 int MapEditor::save (const SaveMode &savemode)
737 // Finish open lineEdits
738 if (lineedit) finishedLineEditNoSave();
742 // Create mapName and fileDir
743 makeSubDirs (fileDir);
747 fname=mapName+".xml";
749 // use name given by user, even if he chooses .doc
753 // Check if fname is writeable
754 QFile file( fileDir+fname);
755 if (!file.open( IO_WriteOnly ) )
757 QMessageBox::critical( 0, tr( "Critical Save Error" ),
758 tr("Couldn't write to ") +fileDir+fname);
764 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),savemode);
766 file.setName ( fileDir + fname);
767 if ( !file.open( IO_WriteOnly ) )
769 // This should neverever happen
770 QMessageBox::critical(0, tr("Critcal save error"),"MapEditor::save() Couldn't open "+file.name());
774 // Write it finally, and write in UTF8, no matter what
775 QTextStream ts( &file );
776 ts.setEncoding (QTextStream::UnicodeUTF8);
784 actionFileSave->setEnabled(false);
790 void MapEditor::setZipped (bool z)
795 bool MapEditor::saveZipped ()
800 void MapEditor::print()
802 // Finish open lineEdits
803 if (lineedit) finishedLineEditNoSave();
807 printer = new QPrinter;
808 printer->setColorMode (QPrinter::Color);
811 QRect totalBBox=mapCenter->getTotalBBox();
813 // Try to set orientation automagically
814 // Note: Interpretation of generated postscript is amibiguous, if
815 // there are problems with landscape mode, see
816 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
818 if (totalBBox.width()>totalBBox.height())
819 // recommend landscape
820 printer->setOrientation (QPrinter::Landscape);
822 // recommend portrait
823 printer->setOrientation (QPrinter::Portrait);
825 if ( printer->setup(this) )
826 // returns false, if printing is canceled
828 QPainter pp(printer);
830 // Don't print the visualisation of selection
831 LinkableMapObj *oldselection=NULL;
834 oldselection=selection;
835 selection->unselect();
838 // Handle sizes of map and paper:
840 // setWindow defines which part of the canvas will be transformed
841 // setViewport defines area on paper in device coordinates (dpi)
842 // e.g. (0,50,700,700) is upper part on A4
843 // see also /usr/lib/qt3/doc/html/coordsys.html
845 QPaintDeviceMetrics metrics (printer);
847 double paperAspect = (double)metrics.width() / (double)metrics.height();
848 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
850 QRect mapRect=mapCenter->getTotalBBox();
851 QCanvasRectangle *frame=NULL;
852 QCanvasText *footerFN=NULL;
853 QCanvasText *footerDate=NULL;
854 if (printFrame || printFooter)
859 // Print frame around map
860 mapRect.setRect (mapRect.x()-10, mapRect.y()-10,
861 mapRect.width()+20, mapRect.height()+20);
862 frame=new QCanvasRectangle (mapRect,mapCanvas);
863 frame->setBrush (QColor(white));
864 frame->setPen (QColor(black));
870 // Print footer below map
872 font.setPointSize(10);
873 footerFN=new QCanvasText (mapCanvas);
874 footerFN->setText ("VYM - " + fileName);
875 footerFN->setFont(font);
876 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
877 footerFN->setZ(Z_TEXT);
879 footerDate=new QCanvasText (mapCanvas);
880 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
881 footerDate->setFont(font);
882 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
883 footerDate->setZ(Z_TEXT);
885 mapRect.setRect (mapRect.x(), mapRect.y(),
886 mapRect.width(), mapRect.height()+20);
888 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height());
891 pp.setWindow (mapRect);
894 if (mapAspect>=paperAspect)
896 // Fit horizontally to paper width
897 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
900 // Fit vertically to paper height
901 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
904 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
906 // Delete Frame and footer
912 if (frame) delete (frame);
917 selection=oldselection;
923 QPixmap MapEditor::getPixmap()
925 QRect mapRect=mapCenter->getTotalBBox();
926 QPixmap pix (mapRect.size());
929 // Don't print the visualisation of selection
930 LinkableMapObj *oldselection=NULL;
933 oldselection=selection;
934 selection->unselect();
937 pp.setWindow (mapRect);
939 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
945 selection=oldselection;
952 void MapEditor::exportImage(QString fn)
954 // Finish open lineEdits
955 if (lineedit) finishedLineEditNoSave();
957 QPixmap pix (getPixmap());
961 void MapEditor::exportImage(QString fn, int item)
963 // Finish open lineEdits
964 if (lineedit) finishedLineEditNoSave();
966 QPixmap pix (getPixmap());
967 pix.save(fn, exportImageFormatMenu->text(item) );
970 void MapEditor::exportASCII()
972 // FIXME still experimental
973 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
974 fd->addFilter ("TXT (*.txt)");
975 fd->setCaption("VYM - Export (ASCII) (still experimental)");
976 fd->setMode( QFileDialog::AnyFile );
979 if ( fd->exec() == QDialog::Accepted )
981 if (QFile (fd->selectedFile()).exists() )
983 QMessageBox mb( "VYM",
984 tr("The file ") + fd->selectedFile() +
985 tr(" exists already. Do you want to overwrite it?"),
986 QMessageBox::Warning,
987 QMessageBox::Yes | QMessageBox::Default,
988 QMessageBox::Cancel | QMessageBox::Escape,
989 QMessageBox::NoButton );
991 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
992 mb.setButtonText( QMessageBox::No, tr("Cancel"));
996 case QMessageBox::Yes:
998 if (!ex.setOutputDir ("out"))
1000 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1004 case QMessageBox::Cancel:
1011 ex.setPath (fd->selectedFile() );
1012 ex.setMapCenter(mapCenter);
1018 void MapEditor::exportXML(const QString &dir)
1020 // Create subdirectories
1023 // write to directory
1024 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,CompleteMap);
1027 file.setName ( dir + "/"+mapName+".xml");
1028 if ( !file.open( IO_WriteOnly ) )
1030 // This should neverever happen
1031 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1035 // Write it finally, and write in UTF8, no matter what
1036 QTextStream ts( &file );
1037 ts.setEncoding (QTextStream::UnicodeUTF8);
1041 // Now write image, too
1042 exportImage (dir+"/images/"+mapName+".png");
1045 void MapEditor::clear()
1049 selection->unselect();
1056 void MapEditor::undo()
1059 d.setPath(bakMapDir);
1062 // Finish open lineEdits
1063 if (lineedit) finishedLineEditNoSave();
1067 selection->unselect();
1071 mapBuilderHandler handler;
1072 QXmlInputSource source;
1073 source.setData(backupXML);
1074 QXmlSimpleReader reader;
1075 reader.setContentHandler( &handler );
1076 reader.setErrorHandler( &handler );
1077 handler.setMapEditor( this );
1078 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1081 selection=undoSelection;
1082 selection->select();
1083 handler.setLoadMode (ImportReplace);
1088 handler.setLoadMode (NewMap);
1090 blockreposition=true;
1091 bool ok = reader.parse( source );
1092 blockreposition=false;
1094 mapCenter->reposition();
1098 // This should never ever happen
1099 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1100 tr( handler.errorProtocol() )+" in "+backupXML );
1102 // Undo not longer available now
1103 actionEditUndo->setEnabled (false);
1104 undoSelection=false;
1109 QMessageBox::critical( 0, tr( "Critical Error" ),
1110 "Temporary directory " +bakMapDir +
1111 tr (" used for undo is gone. \n"
1112 "I will create a new one, but at the moment no undo is available.\n"
1113 "Maybe you want to reload your original data.\n\n"
1114 "Sorry for any inconveniences.") );
1119 void MapEditor::copy()
1121 // Finish open lineEdits
1122 if (lineedit) finishedLineEditNoSave();
1126 if (typeid(*selection) == typeid(BranchObj) )
1130 clipboardME->clear();
1131 clipboardME->getMapCenter()->addBranch();
1132 to=clipboardME->getMapCenter()->getLastBranch();
1135 from=(BranchObj*)(selection);
1138 // keep position relative to parent
1139 to->move2RelPos ( from->getRelPos());
1141 // select data in clipboard
1142 clipboardME->select ("bo:0");
1144 // repositioning makes testing nicer,
1145 // but is not needed usually:
1146 if (clipboardME->isVisible())
1148 clipboardME->getMapCenter()->reposition();
1151 clipboardME->hide();
1154 if (typeid(*selection) == typeid(FloatImageObj) )
1157 FloatImageObj* from;
1158 clipboardME->clear();
1159 clipboardME->getMapCenter()->addFloatImage();
1160 to=clipboardME->getMapCenter()->getLastFloatImage();
1163 from=(FloatImageObj*)(selection);
1166 // select data in clipboard
1167 clipboardME->select ("fi:0");
1169 // repositioning makes testing nicer,
1170 // but is not needed usually:
1171 if (clipboardME->isVisible())
1173 clipboardME->getMapCenter()->reposition();
1176 clipboardME->hide();
1182 LinkableMapObj* MapEditor::pasteNoSave()
1184 // Finish open lineEdits
1185 if (lineedit) finishedLineEditNoSave();
1187 LinkableMapObj *fromLMO=clipboardME->getSelection();
1188 LinkableMapObj *returnLMO=NULL;
1190 if (selection && fromLMO)
1193 if (typeid(*fromLMO) == typeid(BranchObj) )
1195 if (typeid(*selection) == typeid(MapCenterObj))
1197 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1198 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1200 if (typeid(*selection) == typeid(BranchObj))
1201 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1204 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1205 (typeid(*selection) == typeid (BranchObj) ||
1206 typeid(*selection)==typeid(MapCenterObj)) )
1207 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1213 void MapEditor::cutNoSave()
1215 // Finish open lineEdits
1216 if (lineedit) finishedLineEditNoSave();
1220 if (selection != NULL) {
1221 if (typeid(*selection) == typeid(BranchObj) )
1223 bo=(BranchObj*)(selection);
1224 par=(BranchObj*)(bo->getParObj());
1227 par->removeBranch(bo);
1229 selection->select();
1231 if (typeid(*selection) == typeid(FloatImageObj) )
1233 FloatImageObj* fio=(FloatImageObj*)(selection);
1234 par=(BranchObj*)(fio->getParObj());
1237 par->removeFloatImage(fio);
1239 selection->select();
1244 void MapEditor::paste()
1247 saveState(PartOfMap,selection);
1249 mapCenter->reposition();
1253 void MapEditor::cut()
1256 saveState(PartOfMap,selection->getParObj());
1259 mapCenter->reposition();
1263 void MapEditor::moveBranchUp()
1265 // Finish open lineEdits
1266 if (lineedit) finishedLineEditNoSave();
1270 if (typeid(*selection) == typeid(BranchObj) )
1273 saveState(PartOfMap,selection->getParObj());
1274 bo=(BranchObj*)(selection);
1275 par=(BranchObj*)(bo->getParObj());
1276 selection->unselect();
1277 selection=par->moveBranchUp (bo);
1278 selection->select();
1279 mapCenter->reposition();
1280 ensureSelectionVisible();
1284 void MapEditor::moveBranchDown()
1286 // Finish open lineEdits
1287 if (lineedit) finishedLineEditNoSave();
1291 if (typeid(*selection) == typeid(BranchObj) )
1294 saveState(PartOfMap,selection->getParObj());
1295 bo=(BranchObj*)(selection);
1296 par=(BranchObj*)(bo->getParObj());
1297 selection->unselect();
1298 selection=par->moveBranchDown(bo);
1299 selection->select();
1300 mapCenter->reposition();
1301 ensureSelectionVisible();
1305 void MapEditor::editHeading()
1307 // Finish open lineEdits
1308 if (lineedit) finishedLineEditNoSave();
1311 (typeid(*selection) == typeid(BranchObj) ||
1312 typeid(*selection) == typeid(MapCenterObj) ) )
1315 saveState(PartOfMap,selection);
1317 ensureSelectionVisible();
1318 BranchObj *bo=(BranchObj*)(selection);
1319 editingBO=(BranchObj*)(selection);
1320 QPoint p = worldMatrix().map(QPoint (bo->x(),bo->y()));
1321 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1322 QString s=bo->getHeading();
1323 lineedit->setText(s);
1324 lineedit->setCursorPosition(1);
1325 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1326 lineedit->selectAll();
1329 lineedit->grabKeyboard();
1330 lineedit->setFocus();
1335 void MapEditor::addNewBranch(int pos)
1337 // Finish open lineEdits
1338 if (lineedit) finishedLineEditNoSave();
1341 (typeid(*selection) == typeid(BranchObj) ||
1342 typeid(*selection) == typeid(MapCenterObj) ) )
1345 saveState(PartOfMap,selection);
1347 BranchObj* bo1 = (BranchObj*) (selection);
1348 bool wasScrolled=false;
1349 BranchObj *newbo=NULL;
1352 // save scroll state. If scrolled, automatically select
1353 // new branch in order to tmp unscroll parent...
1354 wasScrolled=bo1->isScrolled();
1355 newbo=bo1->addBranch();
1358 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1362 // add above selection
1363 newbo=parbo->insertBranch(bo1->getNum());
1365 // add below selection
1366 newbo=parbo->insertBranch(bo1->getNum()+1);
1368 // This should not happen...
1373 LinkableMapObj *oldselection=selection;
1375 mapCenter->reposition();
1377 if (actionSettingsAutoedit->isOn() ||
1378 actionSettingsAutoselectHeading->isOn() )
1380 selection->unselect();
1382 selection->select();
1383 if (actionSettingsPasteNewHeading->isOn() )
1385 BranchObj *bo2= (BranchObj*)(selection);
1386 bo2->setHeading("");
1388 if (actionSettingsAutoedit->isOn() )
1390 if (!actionSettingsAutoselectHeading->isOn()
1393 selection->unselect();
1394 selection=oldselection;
1395 selection->select();
1401 void MapEditor::deleteSelection()
1403 // Finish open lineEdits
1404 if (lineedit) finishedLineEditNoSave();
1406 if (selection && typeid(*selection) ==typeid(BranchObj) )
1409 saveState(PartOfMap,selection->getParObj());
1410 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1411 BranchObj* par=(BranchObj*)(bo->getParObj());
1414 par->removeBranch(bo);
1416 selection->select();
1417 ensureSelectionVisible();
1418 mapCenter->reposition();
1421 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1424 saveState(PartOfMap,selection->getParObj());
1425 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1426 BranchObj* par=(BranchObj*)(fio->getParObj());
1429 par->removeFloatImage(fio);
1431 selection->select();
1432 ensureSelectionVisible();
1433 mapCenter->reposition();
1438 LinkableMapObj* MapEditor::getSelection()
1443 LinkableMapObj* MapEditor::findObj (QString s)
1445 LinkableMapObj *lmo=mapCenter;
1449 while (!s.isEmpty() )
1451 part=s.section(",",0,0);
1453 num=part.right(part.length() - 3);
1460 lmo=mapCenter->getBranchNum (num.toUInt());
1463 lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt());
1466 lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
1469 if (s.contains(","))
1470 s=s.right(s.length() - part.length() -1 );
1477 bool MapEditor::select (const QString &s)
1479 LinkableMapObj *lmo=findObj(s);
1481 // Finally select the found object
1484 if (selection) selection->unselect();
1486 selection->select();
1488 ensureSelectionVisible();
1494 void MapEditor::unselect()
1498 selectionLast=selection;
1499 selection->unselect();
1504 void MapEditor::reselect()
1508 selection=selectionLast;
1509 selection->select();
1514 void MapEditor::selectNextBranch()
1516 // Increase number of branch
1519 QString s=selection->getSelectString();
1525 part=s.section(",",-1);
1527 num=part.right(part.length() - 3);
1529 s=s.left (s.length() -num.length());
1532 num=QString ("%1").arg(num.toUInt()+1);
1536 // Try to select this one
1537 if (select (s)) return;
1539 // We have no direct successor,
1540 // try to increase the parental number in order to
1541 // find a successor with same depth
1543 int d=selection->getDepth();
1548 while (!found && d>0)
1550 s=s.section (",",0,d-1);
1551 // replace substring of current depth in s with "1"
1552 part=s.section(",",-1);
1554 num=part.right(part.length() - 3);
1558 // increase number of parent
1559 num=QString ("%1").arg(num.toUInt()+1);
1560 s=s.section (",",0,d-2) + ","+ typ+num;
1563 // Special case, look at orientation
1564 if (selection->getOrientation()==OrientRightOfCenter)
1565 num=QString ("%1").arg(num.toUInt()+1);
1567 num=QString ("%1").arg(num.toUInt()-1);
1572 // pad to oldDepth, select the first branch for each depth
1573 for (i=d;i<oldDepth;i++)
1578 if ( ((BranchObj*)(selection))->countBranches()>0)
1586 // try to select the freshly built string
1594 void MapEditor::selectPrevBranch()
1596 // Decrease number of branch
1599 QString s=selection->getSelectString();
1605 part=s.section(",",-1);
1607 num=part.right(part.length() - 3);
1609 s=s.left (s.length() -num.length());
1612 num=QString ("%1").arg(num.toUInt()-1);
1616 // Try to select this one
1617 if (select (s)) return;
1619 // We have no direct precessor,
1620 // try to decrease the parental number in order to
1621 // find a precessor with same depth
1623 int d=selection->getDepth();
1628 while (!found && d>0)
1630 s=s.section (",",0,d-1);
1631 // replace substring of current depth in s with "1"
1632 part=s.section(",",-1);
1634 num=part.right(part.length() - 3);
1638 // decrease number of parent
1639 num=QString ("%1").arg(num.toUInt()-1);
1640 s=s.section (",",0,d-2) + ","+ typ+num;
1643 // Special case, look at orientation
1644 if (selection->getOrientation()==OrientRightOfCenter)
1645 num=QString ("%1").arg(num.toUInt()-1);
1647 num=QString ("%1").arg(num.toUInt()+1);
1652 // pad to oldDepth, select the last branch for each depth
1653 for (i=d;i<oldDepth;i++)
1657 if ( ((BranchObj*)(selection))->countBranches()>0)
1658 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1665 // try to select the freshly built string
1673 void MapEditor::selectUpperBranch()
1675 // Finish open lineEdits
1676 if (lineedit) finishedLineEditNoSave();
1680 if (typeid(*selection) == typeid(BranchObj))
1682 if (selection->getOrientation()==OrientRightOfCenter)
1685 if (selection->getDepth()==1)
1693 void MapEditor::selectLowerBranch()
1695 // Finish open lineEdits
1696 if (lineedit) finishedLineEditNoSave();
1700 if (typeid(*selection) == typeid(BranchObj))
1702 if (selection->getOrientation()==OrientRightOfCenter)
1705 if (selection->getDepth()==1)
1714 void MapEditor::selectLeftBranch()
1716 // Finish open lineEdits
1717 if (lineedit) finishedLineEditNoSave();
1723 if (typeid(*selection) == typeid(MapCenterObj))
1725 par= (BranchObj*) (selection);
1726 bo=par->getLastSelectedBranch();
1729 // Workaround for reselecting on left and right side
1730 if (bo->getOrientation()==OrientRightOfCenter)
1732 bo=par->getLastBranch();
1738 selection->select();
1740 ensureSelectionVisible();
1745 par=(BranchObj*)(selection->getParObj());
1746 if (selection->getOrientation()==OrientRightOfCenter)
1748 if (typeid(*selection) == typeid(BranchObj) ||
1749 typeid(*selection) == typeid(FloatImageObj))
1751 selection->unselect();
1753 selection->select();
1755 ensureSelectionVisible();
1759 if (typeid(*selection) == typeid(BranchObj) )
1761 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1764 selection->unselect();
1766 selection->select();
1768 ensureSelectionVisible();
1776 void MapEditor::selectRightBranch()
1778 // Finish open lineEdits
1779 if (lineedit) finishedLineEditNoSave();
1786 if (typeid(*selection) == typeid(MapCenterObj))
1788 par= (BranchObj*) (selection);
1789 bo=par->getLastSelectedBranch();
1792 // Workaround for relecting on left and right side
1793 if (bo->getOrientation()==OrientLeftOfCenter)
1794 bo=par->getFirstBranch();
1799 selection->select();
1800 ensureSelectionVisible();
1805 par=(BranchObj*)(selection->getParObj());
1806 if (selection->getOrientation()==OrientLeftOfCenter)
1808 if (typeid(*selection) == typeid(BranchObj) ||
1809 typeid(*selection) == typeid(FloatImageObj))
1811 selection->unselect();
1813 selection->select();
1815 ensureSelectionVisible();
1819 if (typeid(*selection) == typeid(BranchObj) )
1821 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1824 selection->unselect();
1826 selection->select();
1828 ensureSelectionVisible();
1836 void MapEditor::selectFirstBranch()
1838 // Finish open lineEdits
1839 if (lineedit) finishedLineEditNoSave();
1845 if (typeid(*selection) == typeid(BranchObj))
1847 bo1= (BranchObj*) (selection);
1848 par=(BranchObj*)(bo1->getParObj());
1849 bo2=par->getFirstBranch();
1853 selection->select();
1854 ensureSelectionVisible();
1861 void MapEditor::selectLastBranch()
1863 // Finish open lineEdits
1864 if (lineedit) finishedLineEditNoSave();
1870 if (typeid(*selection) == typeid(BranchObj))
1872 bo1= (BranchObj*) (selection);
1873 par=(BranchObj*)(bo1->getParObj());
1874 bo2=par->getLastBranch();
1878 selection->select();
1879 ensureSelectionVisible();
1886 void MapEditor::setColor(QColor c)
1891 void MapEditor::selectBackgroundColor()
1893 // Finish open lineEdits
1894 if (lineedit) finishedLineEditNoSave();
1896 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
1897 if ( !col.isValid() ) return;
1898 setBackgroundColor( col );
1902 void MapEditor::setBackgroundColor(QColor c)
1904 mapCanvas->setBackgroundColor (c);
1907 QColor MapEditor::pickColor()
1911 if (typeid(*selection) == typeid(BranchObj) ||
1912 typeid(*selection) == typeid(MapCenterObj))
1914 BranchObj *bo=(BranchObj*)(selection);
1915 actColor=bo->getColor();
1921 void MapEditor::colorItem()
1925 if (typeid(*selection) == typeid(BranchObj) ||
1926 typeid(*selection) == typeid(MapCenterObj))
1929 saveState(PartOfMap,selection);
1930 BranchObj *bo=(BranchObj*)(selection);
1931 bo->setColor(actColor, false); // color links, color childs
1936 void MapEditor::colorBranch()
1940 if (typeid(*selection) == typeid(BranchObj) ||
1941 typeid(*selection) == typeid(MapCenterObj))
1944 saveState(PartOfMap,selection);
1945 BranchObj *bo=(BranchObj*)(selection);
1946 bo->setColor(actColor, true); // color links, color childs
1952 void MapEditor::toggleStandardFlag(QString f)
1957 saveState(PartOfMap,selection);
1958 ((BranchObj*)(selection))->toggleStandardFlag (f);
1962 void MapEditor::setViewCenter()
1964 // transform to CanvasView Coord:
1965 QPoint p=worldMatrix().map(movingCenter);
1966 center ( p.x(), p.y());
1970 BranchObj* MapEditor::findText (QString s, bool cs)
1973 { // Nothing found or new find process
1975 // nothing found, start again
1977 itFind=mapCenter->first();
1979 bool searching=true;
1980 bool foundNote=false;
1981 while (searching && !EOFind)
1985 // Searching in Note
1986 if (itFind->getNote().contains(s,cs))
1988 if (selection!=itFind)
1990 if (selection) ((BranchObj*)(selection))->unselect();
1992 selection->select();
1994 ensureSelectionVisible();
1996 if (textEditor->findText(s,cs))
2002 // Searching in Heading
2003 if (searching && itFind->getHeading().contains (s,cs) )
2005 if (selection) ((BranchObj*)(selection))->unselect();
2007 selection->select();
2009 ensureSelectionVisible();
2015 itFind=itFind->next();
2016 if (!itFind) EOFind=true;
2022 return (BranchObj*)(selection);
2027 void MapEditor::findReset()
2028 { // Necessary if text to find changes during a find process
2033 void MapEditor::openURL()
2037 if (typeid(*selection) == typeid(BranchObj) ||
2038 typeid(*selection) == typeid(MapCenterObj))
2040 QString url=((BranchObj*)(selection))->getURL();
2042 QProcess *proc = new QProcess( this );
2044 #if !defined(Q_OS_MACX)
2045 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2047 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2048 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2051 proc->addArgument( url);
2053 if ( !proc->start() )
2055 if (mainWindow->settingsURL() )
2061 void MapEditor::editURL()
2063 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2064 typeid(*selection) == typeid(MapCenterObj)) )
2067 QString text = QInputDialog::getText(
2068 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2069 ((BranchObj*)(selection))->getURL(), &ok, this );
2072 // user entered something and pressed OK
2073 ((BranchObj*)(selection))->setURL (text);
2080 void MapEditor::editHeading2URL()
2082 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2083 typeid(*selection) == typeid(MapCenterObj)) )
2085 BranchObj *b=(BranchObj*)(selection);
2086 b->setURL (b->getHeading());
2092 void MapEditor::editBugzilla2URL()
2094 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2095 typeid(*selection) == typeid(MapCenterObj)) )
2097 BranchObj *b=(BranchObj*)(selection);
2098 b->setURL ("http://bugzilla.suse.de/show_bug.cgi?id="+b->getHeading());
2104 void MapEditor::editVymLink()
2106 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2107 typeid(*selection) == typeid(MapCenterObj)) )
2109 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2110 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2111 fd->setCaption(tr("VYM - Link to another map"));
2112 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2113 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2117 if ( fd->exec() == QDialog::Accepted )
2118 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2120 mapCenter->reposition();
2127 void MapEditor::deleteVymLink()
2129 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2130 typeid(*selection) == typeid(MapCenterObj)) )
2132 ((BranchObj*)(selection))->setVymLink ("" );
2134 mapCenter->reposition();
2141 QString MapEditor::getVymLink()
2143 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2144 typeid(*selection) == typeid(MapCenterObj)) )
2146 return ((BranchObj*)(selection))->getVymLink();
2152 void MapEditor::editMapInfo()
2154 ExtraInfoDialog dia;
2155 dia.setMapName (getFileName() );
2156 dia.setAuthor (mapCenter->getAuthor() );
2157 dia.setComment(mapCenter->getComment() );
2162 QCanvasItemList l=canvas()->allItems();
2163 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2165 stats+=QString ("%1 items on canvas\n").arg (i,6);
2171 bo=mapCenter->first();
2174 if (!bo->getNote().isEmpty() ) n++;
2175 f+= bo->countFloatImages();
2179 stats+=QString ("%1 branches\n").arg (b-1,6);
2180 stats+=QString ("%1 notes\n").arg (n,6);
2181 stats+=QString ("%1 images\n").arg (f,6);
2182 dia.setStats (stats);
2184 // Finally show dialog
2185 if (dia.exec() == QDialog::Accepted)
2187 mapCenter->setAuthor (dia.getAuthor() );
2188 mapCenter->setComment (dia.getComment() );
2193 void MapEditor::updateActions()
2195 if (getLinkColorHint()==HeadingColor)
2196 actionFormatLinkColorHint->setOn(true);
2198 actionFormatLinkColorHint->setOn(false);
2203 actionFormatLinkStyleLine->setOn(true);
2206 actionFormatLinkStyleParabel->setOn(true);
2209 actionFormatLinkStylePolyLine->setOn(true);
2211 case StylePolyParabel:
2212 actionFormatLinkStylePolyParabel->setOn(true);
2218 QPixmap pix( 16, 16 );
2219 pix.fill( mapCanvas->backgroundColor() );
2220 actionFormatBackColor->setIconSet( pix );
2221 pix.fill( deflinkcolor );
2222 actionFormatLinkColor->setIconSet( pix );
2224 actionEditUndo->setEnabled( mapChanged );
2225 actionFileSave->setEnabled( mapUnsaved );
2229 if ( (typeid(*selection) == typeid(BranchObj)) ||
2230 (typeid(*selection) == typeid(MapCenterObj)) )
2232 standardFlagsDefault->setEnabled (true);
2234 if ( ((BranchObj*)(selection))->getURL().isEmpty() )
2235 actionEditOpenURL->setEnabled (false);
2237 actionEditOpenURL->setEnabled (true);
2238 actionEditURL->setEnabled (true);
2239 actionEditHeading2URL->setEnabled (true);
2240 actionEditBugzilla2URL->setEnabled (true);
2242 if ( ((BranchObj*)(selection))->getVymLink().isEmpty() )
2244 actionEditOpenVymLink->setEnabled (false);
2245 actionEditDeleteVymLink->setEnabled (false);
2248 actionEditOpenVymLink->setEnabled (true);
2249 actionEditDeleteVymLink->setEnabled (true);
2251 actionEditVymLink->setEnabled (true);
2253 actionEditCopy->setEnabled (true);
2254 actionEditCut->setEnabled (true);
2255 actionEditPaste->setEnabled (true);
2256 actionEditMoveUp->setEnabled (true);
2257 actionEditMoveDown->setEnabled (true);
2258 actionEditToggleScroll->setEnabled (true);
2259 actionEditHeading->setEnabled (true);
2260 actionEditDelete->setEnabled (true);
2261 actionEditAddBranch->setEnabled (true);
2262 actionEditAddBranchAbove->setEnabled (true);
2263 actionEditAddBranchBelow->setEnabled (true);
2264 actionEditImportAdd->setEnabled (true);
2265 actionEditImportReplace->setEnabled (true);
2266 actionEditSaveBranch->setEnabled (true);
2267 actionEditSelectFirst->setEnabled (true);
2268 actionEditSelectLast->setEnabled (true);
2269 actionEditToggleFloatExport->setEnabled (false);
2270 actionFormatPickColor->setEnabled (true);
2271 actionFormatColorBranch->setEnabled (true);
2272 actionFormatColorSubtree->setEnabled (true);
2273 switch (selection->getFrameType())
2276 actionFormatFrameNone->setOn(true);
2279 actionFormatFrameRectangle->setOn(true);
2285 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2287 standardFlagsDefault->setEnabled (false);
2289 actionEditOpenURL->setEnabled (false);
2290 actionEditURL->setEnabled (false);
2291 actionEditHeading2URL->setEnabled (false);
2292 actionEditBugzilla2URL->setEnabled (false);
2293 actionEditOpenVymLink->setEnabled (false);
2294 actionEditVymLink->setEnabled (false);
2295 actionEditDeleteVymLink->setEnabled (false);
2297 actionEditCopy->setEnabled (true);
2298 actionEditCut->setEnabled (true);
2299 actionEditPaste->setEnabled (false); //FIXME
2300 actionEditMoveUp->setEnabled (false);
2301 actionEditMoveDown->setEnabled (false);
2302 actionEditToggleScroll->setEnabled (false);
2303 actionEditHeading->setEnabled (false);
2304 actionEditDelete->setEnabled (true);
2305 actionEditAddBranch->setEnabled (false);
2306 actionEditAddBranchAbove->setEnabled (false);
2307 actionEditAddBranchBelow->setEnabled (false);
2308 actionEditImportAdd->setEnabled (false);
2309 actionEditSaveBranch->setEnabled (false);
2310 actionEditImportReplace->setEnabled (false);
2311 actionEditSelectFirst->setEnabled (false);
2312 actionEditSelectLast->setEnabled (false);
2313 actionEditToggleFloatExport->setOn
2314 ( ((FloatImageObj*)(selection))->getFloatExport() );
2315 actionFormatPickColor->setEnabled (false);
2316 actionFormatColorBranch->setEnabled (false);
2317 actionFormatColorSubtree->setEnabled (false);
2322 standardFlagsDefault->setEnabled (false);
2324 actionEditCopy->setEnabled (false);
2325 actionEditCut->setEnabled (false);
2326 actionEditPaste->setEnabled (false);
2327 actionEditMoveUp->setEnabled (false);
2328 actionEditMoveDown->setEnabled (false);
2329 actionEditToggleScroll->setEnabled (false);
2330 actionEditOpenURL->setEnabled (false);
2331 actionEditURL->setEnabled (false);
2332 actionEditOpenVymLink->setEnabled (false);
2333 actionEditVymLink->setEnabled (false);
2334 actionEditDeleteVymLink->setEnabled (false);
2335 actionEditHeading2URL->setEnabled (false);
2336 actionEditBugzilla2URL->setEnabled (false);
2337 actionEditHeading->setEnabled (false);
2338 actionEditDelete->setEnabled (false);
2339 actionEditAddBranch->setEnabled (false);
2340 actionEditAddBranchAbove->setEnabled (false);
2341 actionEditAddBranchBelow->setEnabled (false);
2342 actionEditSaveBranch->setEnabled (false);
2343 actionEditImportReplace->setEnabled (false);
2344 actionEditSelectFirst->setEnabled (false);
2345 actionEditSelectLast->setEnabled (false);
2346 actionEditToggleFloatExport->setEnabled (false);
2347 actionFormatPickColor->setEnabled (false);
2348 actionFormatColorBranch->setEnabled (false);
2349 actionFormatColorSubtree->setEnabled (false);
2353 void MapEditor::setLinkStyle (LinkStyle ls)
2358 bo=mapCenter->first();
2362 bo->setLinkStyle(bo->getDefLinkStyle());
2369 LinkStyle MapEditor::getLinkStyle ()
2374 void MapEditor::setLinkColor(QColor c)
2380 void MapEditor::setLinkColorHint()
2382 // called from setLinkColorHint(lch) or at end of parse
2384 bo=mapCenter->first();
2392 void MapEditor::setLinkColorHint(LinkColorHint lch)
2398 void MapEditor::toggleLinkColorHint()
2400 if (linkcolorhint==HeadingColor)
2401 linkcolorhint=DefaultColor;
2403 linkcolorhint=HeadingColor;
2405 bo=mapCenter->first();
2413 LinkColorHint MapEditor::getLinkColorHint()
2415 return linkcolorhint;
2418 QColor MapEditor::getDefLinkColor()
2420 return deflinkcolor;
2423 void MapEditor::selectLinkColor()
2425 // Finish open lineEdits
2426 if (lineedit) finishedLineEditNoSave();
2428 QColor col = QColorDialog::getColor( deflinkcolor, this );
2429 if ( !col.isValid() ) return;
2430 setLinkColor( col );
2434 void MapEditor::toggleScroll()
2436 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2438 BranchObj *bo=((BranchObj*)(selection));
2439 if (bo->countBranches()==0) return;
2440 if (bo->getDepth()==0) return;
2442 saveState(PartOfMap,selection);
2449 void MapEditor::unScrollAll()
2452 bo=mapCenter->first();
2455 if (bo->isScrolled()) bo->toggleScroll();
2460 void MapEditor::loadFloatImage ()
2463 (typeid(*selection) == typeid(BranchObj)) ||
2464 (typeid(*selection) == typeid(MapCenterObj)) )
2466 BranchObj *bo=((BranchObj*)(selection));
2468 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2469 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2470 ImagePreview *p =new ImagePreview (fd);
2471 fd->setContentsPreviewEnabled( TRUE );
2472 fd->setContentsPreview( p, p );
2473 fd->setPreviewMode( QFileDialog::Contents );
2474 fd->setCaption(tr("vym - Load image"));
2475 fd->setDir (lastImageDir);
2479 if ( fd->exec() == QDialog::Accepted )
2482 saveState(PartOfMap,selection);
2483 QString fn=fd->selectedFile();
2484 lastImageDir=fn.left(fn.findRev ("/"));
2485 bo->addFloatImage();
2486 // FIXME check if load was successful
2487 bo->getLastFloatImage()->load(fn);
2488 bo->getLastFloatImage()->setOriginalFilename(fn);
2489 mapCenter->reposition();
2496 void MapEditor::saveFloatImage (int item)
2499 (typeid(*selection) == typeid(FloatImageObj)) )
2501 FloatImageObj *fio=((FloatImageObj*)(selection));
2502 const char* fmt = saveImageFormatMenu->text(item);
2504 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2505 fd->addFilter ("PNG (*.png)");
2506 fd->addFilter ("BMP (*.bmp)");
2507 fd->addFilter ("XBM (*.xbm)");
2508 fd->addFilter ("JPG (*.jpg)");
2509 fd->addFilter ("XPM (*.xpm)");
2510 fd->addFilter ("GIF (*.gif)");
2511 fd->addFilter ("PNM (*.pnm)");
2512 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2513 fd->setCaption(tr("vym - Save image as ") + fmt);
2514 fd->setMode( QFileDialog::AnyFile );
2515 fd->setSelection (fio->getOriginalFilename());
2519 if ( fd->exec() == QDialog::Accepted )
2521 if (QFile (fd->selectedFile()).exists() )
2523 QMessageBox mb( "VYM",
2524 tr("The file ") + fd->selectedFile() +
2525 tr(" exists already. "
2526 "Do you want to overwrite it?"),
2527 QMessageBox::Warning,
2528 QMessageBox::Yes | QMessageBox::Default,
2529 QMessageBox::Cancel | QMessageBox::Escape,
2530 QMessageBox::QMessageBox::NoButton );
2532 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2533 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2536 case QMessageBox::Yes:
2539 case QMessageBox::Cancel:
2545 fio->save (fd->selectedFile(),fmt);
2550 void MapEditor::toggleFloatExport()
2553 (typeid(*selection) == typeid(FloatImageObj))||
2554 (typeid(*selection) == typeid(FloatObj)) )
2556 FloatImageObj *fio=((FloatImageObj*)(selection));
2557 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2561 void MapEditor::setFrame(const FrameType &t)
2564 (typeid(*selection) == typeid(BranchObj)) ||
2565 (typeid(*selection) == typeid(MapCenterObj)) )
2567 selection->setFrameType (t);
2568 mapCenter->reposition();
2569 selection->updateLink();
2573 void MapEditor::importDir(BranchObj *dst, QDir d)
2576 (typeid(*selection) == typeid(BranchObj)) ||
2577 (typeid(*selection) == typeid(MapCenterObj)) )
2581 // Traverse directories
2582 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2583 const QFileInfoList *dirlist = d.entryInfoList();
2584 QFileInfoListIterator itdir( *dirlist );
2587 while ( (fi = itdir.current()) != 0 )
2589 if (fi->fileName() != "." && fi->fileName() != ".." )
2592 bo=dst->getLastBranch();
2593 bo->setHeading (fi->fileName() );
2594 bo->setColor (QColor("blue"),false);
2596 if ( !d.cd(fi->fileName()) )
2597 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2607 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2608 const QFileInfoList *filelist = d.entryInfoList();
2609 QFileInfoListIterator itfile( *filelist );
2611 while ( (fi = itfile.current()) != 0 )
2614 bo=dst->getLastBranch();
2615 bo->setHeading (fi->fileName() );
2616 bo->setColor (QColor("black"),false);
2622 void MapEditor::importDir()
2625 (typeid(*selection) == typeid(BranchObj)) ||
2626 (typeid(*selection) == typeid(MapCenterObj)) )
2628 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2629 fd->setMode (QFileDialog::DirectoryOnly);
2630 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2631 fd->setCaption(tr("VYM - Choose directory structur to import"));
2635 if ( fd->exec() == QDialog::Accepted )
2637 BranchObj *bo=((BranchObj*)(selection));
2638 importDir (bo,QDir(fd->selectedFile()) );
2639 mapCenter->reposition();
2646 void MapEditor::testFunction()
2648 cout << "MapEditor::testFunction() called\n";
2649 if (modifierMode==pickColorMode)
2650 modifierMode=linkObjectsMode;
2652 modifierMode=pickColorMode;
2655 void MapEditor::ensureSelectionVisible()
2657 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2659 if (selection->getOrientation() == OrientLeftOfCenter)
2660 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2662 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2663 ensureVisible (p.x(), p.y() );
2667 void MapEditor::updateViewCenter()
2669 // Update movingCenter, so that we can zoom comfortably later
2670 QRect rc = QRect( contentsX(), contentsY(),
2671 visibleWidth(), visibleHeight() );
2672 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2673 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2674 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2677 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2679 // Lineedits are already closed by preceding
2680 // mouseEvent, we don't need to close here.
2682 QPoint p = inverseWorldMatrix().map(e->pos());
2683 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2686 { // MapObj was found
2687 if (selection != lmo)
2689 // select the MapObj
2690 if (selection) selection->unselect();
2692 selection->select();
2698 if (typeid(*selection)==typeid(BranchObj) ||
2699 typeid(*selection)==typeid(MapCenterObj) )
2701 // Context Menu on branch or mapcenter
2703 branchContextMenu->popup(e->globalPos() );
2705 if (typeid(*selection)==typeid(FloatImageObj))
2707 // Context Menu on floatimage
2709 floatimageContextMenu->popup(e->globalPos() );
2713 { // No MapObj found, we are on the Canvas itself
2714 // Context Menu on Canvas
2716 canvasContextMenu->popup(e->globalPos() );
2720 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2722 // Finish open lineEdits
2723 if (lineedit) finishedLineEditNoSave();
2725 QPoint p = inverseWorldMatrix().map(e->pos());
2726 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2728 // Special case: CTRL is pressed
2729 if (e->state() & QMouseEvent::ControlButton)
2731 if (modifierMode==pickColorMode)
2733 if (e->state() & QMouseEvent::ControlButton)
2736 setCursor (pickColorCursor);
2740 if (modifierMode==linkObjectsMode)
2743 (typeid(*lmo) == typeid(BranchObj)) ||
2744 (typeid(*lmo) == typeid(MapCenterObj)) )
2747 linkingObj_src=selection;
2748 tmpLink=new LinkObj (mapCanvas);
2749 tmpLink->setBegin ( ((BranchObj*)(lmo)) );
2750 tmpLink->setEnd (p);
2751 tmpLink->updateLink();
2752 tmpLink->setVisibility (true);
2759 { // MapObj was found
2760 if (selection != lmo)
2762 // select the MapObj
2763 if (selection) selection->unselect();
2765 selection->select();
2770 // Check, if systemFlag clicked
2771 if (typeid(*selection)==typeid(BranchObj) ||
2772 typeid(*selection)==typeid(MapCenterObj) )
2774 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
2775 if (!foname.isEmpty())
2777 // Do not move, if systemFlag clicked
2781 if (foname=="vymLink")
2783 mainWindow->editOpenVymLink();
2784 // tabWidget may change, better return now
2785 // before segfaulting...
2789 mainWindow->windowToggleNoteEditor();
2793 // Left Button Move Branches
2794 if (e->button() == QMouseEvent::LeftButton )
2796 movingObj=selection;
2797 movingObj_start.setX( p.x() - selection->x() );
2798 movingObj_start.setY( p.y() - selection->y() );
2800 // Middle Button Toggle Scroll
2801 // (On Mac OS X this won't work, but we still have
2802 // a button in the toolbar)
2803 if (e->button() == QMouseEvent::MidButton )
2809 { // No MapObj found, we are on the Canvas itself
2810 // Left Button move Pos of CanvasView
2811 if (e->button() == QMouseEvent::LeftButton )
2813 movingObj=NULL; // move Content not Obj
2814 movingObj_start=e->globalPos();
2815 movingCont_start=QPoint (contentsX(), contentsY() );
2816 movingVec=QPoint(0,0);
2817 setCursor(handOpenCursor);
2822 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
2824 QPoint p = inverseWorldMatrix().map(e->pos());
2826 // Move the selected MapObj
2827 if ( selection && movingObj)
2830 // Now move the selection, but add relative position
2831 // (movingObj_start) where selection was chosen with
2832 // mousepointer. (This avoids flickering resp. jumping
2833 // of selection back to absPos)
2835 LinkableMapObj *lmosel;
2836 lmosel = dynamic_cast <LinkableMapObj*> (selection);
2838 // Check if we could link
2839 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
2842 if (typeid(*selection) == typeid(FloatImageObj))
2846 FloatObj *fo=(FloatObj*)(selection);
2847 if (fo->getLinkStyle()==StyleUndef)
2849 fo->setLinkStyle(fo->getDefLinkStyle());
2850 fo->setLinkColor(fo->getParObj()->getLinkColor());
2852 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2856 // Relink float to new mapcenter or branch, if shift is pressed
2857 // Only relink, if selection really has a new parent
2858 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
2859 ( (typeid(*lmo)==typeid(BranchObj)) ||
2860 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
2861 ( lmo != fo->getParObj())
2864 if (typeid(*fo) == typeid(FloatImageObj))
2866 FloatImageObj *fio=(FloatImageObj*)(fo);
2867 ((BranchObj*)(lmo))->addFloatImage (fio);
2869 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2870 fio=((BranchObj*)(lmo))->getLastFloatImage();
2873 selection=(LinkableMapObj*)(fio);
2874 selection->select();
2875 movingObj=(MapObj*)(fio);
2876 // setLinkStyle calls updateLink, only set it once
2877 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
2878 fio->setLinkStyle (fio->getDefLinkStyle());
2881 // TODO if (typeid(*selection) == typeid(FloatTextObj))
2883 } else // selection != a FloatObj
2885 if (lmosel->getDepth()==0)
2887 if (e->state() == (LeftButton | !ShiftButton))
2888 // If mapCenter is moved, move all the rest by default, too.
2889 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2891 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2894 if (lmosel->getDepth()==1)
2896 // depth==1, mainbranch
2898 saveState(PartOfMap,lmosel);
2899 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2903 if (lmosel->getOrientation() == OrientLeftOfCenter)
2904 // Add width of bbox here, otherwise alignRelTo will cause jumping around
2905 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
2906 p.y()-movingObj_start.y() );
2908 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2910 // reposition subbranch
2911 lmosel->reposition();
2912 ensureSelectionVisible();
2914 if (lmo && (lmo!=selection) &&
2915 (typeid(*lmo) == typeid(BranchObj) ||
2916 (typeid(*lmo) == typeid(MapCenterObj) )
2919 if (e->state() & QMouseEvent::ControlButton)
2921 // Special case: CTRL to link below lmo
2922 lmosel->setParObjTmp (lmo,p,+1);
2924 else if (e->state() & QMouseEvent::ShiftButton)
2925 lmosel->setParObjTmp (lmo,p,-1);
2927 lmosel->setParObjTmp (lmo,p,0);
2930 if (lmo &&(lmo==selection))
2931 // Could link to myself (happens sometimes...)
2932 lmosel->unsetParObjTmp();
2934 // no Obj under selection, go back to original Parent
2935 lmosel->unsetParObjTmp();
2939 } // no FloatImageObj
2943 } // selection && moving_obj
2945 // Draw a link from one branch to another
2948 tmpLink->setEnd (p);
2949 tmpLink->updateLink();
2953 if (!movingObj && !pickingColor &&!drawingLink)
2955 QPoint p=e->globalPos();
2956 movingVec.setX(-p.x() + movingObj_start.x() );
2957 movingVec.setY(-p.y() + movingObj_start.y() );
2958 setContentsPos( movingCont_start.x() + movingVec.x(),
2959 movingCont_start.y() + movingVec.y());
2966 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
2968 LinkableMapObj *dst;
2969 // Have we been picking color?
2973 setCursor (ArrowCursor);
2974 // Check if we are over another branch
2975 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
2976 if (dst && selection)
2978 if (e->state() & QMouseEvent::ShiftButton)
2980 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
2981 ((BranchObj*)(selection))->setLinkColor ();
2985 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
2986 ((BranchObj*)(selection))->setLinkColor ();
2992 // Have we been drawing a link?
2996 // Check if we are over another branch
2997 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
2998 if (dst && selection)
3000 tmpLink->setEnd ( ((BranchObj*)(dst)) );
3001 tmpLink->updateLink();
3002 tmpLink->activate();
3012 // Have we been moving something?
3013 if ( selection && movingObj )
3015 // Check if we are over another branch, but ignore
3016 // any found LMOs, which are FloatObjs
3017 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3018 ((LinkableMapObj*)(selection)) );
3021 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3026 // Now check, if we have been moving a branch
3027 if (typeid(*selection) == typeid(BranchObj) )
3029 // save the position in case we link to mapcenter
3030 QPoint savePos=QPoint (selection->x(),selection->y() );
3032 // Reset the temporary drawn link to the original one
3033 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3039 // TODO we also could check, if dest and src are on same branch,
3040 // then it would be sufficient to saveState of this branch
3042 // Modifiers allow to insert above/below dst
3043 if (e->state() & QMouseEvent::ShiftButton)
3045 ((BranchObj*)(selection))->moveBranchTo
3048 ((BranchObj*)(dst))->getNum()
3050 //if (selection) selection->select();
3052 if (e->state() & QMouseEvent::ControlButton)
3054 ((BranchObj*)(selection))->moveBranchTo
3057 ((BranchObj*)(dst))->getNum()+1
3059 //if (selection) selection->select();
3062 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
3063 if (dst->getDepth()==0)
3064 ((BranchObj*)(selection))->move (savePos);
3067 // Draw the original link, before selection was moved around
3068 mapCenter->reposition();
3070 // Finally resize canvas, if needed
3075 // maybe we moved View: set old cursor
3076 setCursor (ArrowCursor);
3080 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3082 // Finish open lineEdits
3083 if (lineedit) finishedLineEditNoSave();
3085 if (e->button() == QMouseEvent::LeftButton )
3087 QPoint p = inverseWorldMatrix().map(e->pos());
3088 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3089 if (lmo) { // MapObj was found
3090 // First select the MapObj than edit heading
3091 if (selection) selection->unselect();
3093 selection->select();
3095 saveState(PartOfMap,selection);
3101 void MapEditor::resizeEvent (QResizeEvent* e)
3103 QCanvasView::resizeEvent( e );
3106 if (!fileName.isEmpty()) s=fileName;