3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <qpopupmenu.h>
9 #include <qpaintdevicemetrics.h>
11 #include <qfiledialog.h>
14 #include <qcolordialog.h>
17 #include <qinputdialog.h>
26 #include "texteditor.h"
27 #include "linkablemapobj.h"
30 #include "mainwindow.h"
31 #include "extrainfodialog.h"
32 #include "editxlinkdialog.h"
35 #include "icons/flag-note.xpm"
36 #include "icons/flag-url.xpm"
37 #include "icons/flag-vymlink.xpm"
38 #include "icons/flag-scrolled-right.xpm"
39 #include "icons/flag-tmpUnscrolled-right.xpm"
40 #include "icons/flag-questionmark.xpm"
41 #include "icons/flag-exclamationmark.xpm"
42 #include "icons/flag-hook-green.xpm"
43 #include "icons/flag-cross-red.xpm"
44 #include "icons/flag-stopsign.xpm"
45 #include "icons/flag-smiley-good.xpm"
46 #include "icons/flag-smiley-sad.xpm"
47 #include "icons/flag-clock.xpm"
48 #include "icons/flag-lamp.xpm"
49 #include "icons/flag-arrow-up.xpm"
50 #include "icons/flag-arrow-down.xpm"
51 #include "icons/flag-thumb-up.xpm"
52 #include "icons/flag-thumb-down.xpm"
53 #include "icons/flag-heart.xpm"
54 #include "icons/flag-flash.xpm"
55 #include "icons/flag-lifebelt.xpm"
57 extern TextEditor *textEditor;
58 extern int statusbarTime;
59 extern Main *mainWindow;
60 extern FlagRowObj *systemFlagsDefault;
61 extern FlagRowObj *standardFlagsDefault;
62 extern MapEditor *clipboardME;
64 extern QAction *actionFileSave;
65 extern QAction *actionEditUndo;
66 extern QAction *actionEditCopy;
67 extern QAction *actionEditCut;
68 extern QAction *actionEditPaste;
69 extern QAction *actionEditMoveUp;
70 extern QAction *actionEditMoveDown;
71 extern QAction *actionEditToggleScroll;
72 extern QAction *actionEditOpenURL;
73 extern QAction *actionEditURL;
74 extern QAction *actionEditHeading2URL;
75 extern QAction *actionEditBugzilla2URL;
76 extern QAction *actionEditOpenVymLink;
77 extern QAction *actionEditVymLink;
78 extern QAction *actionEditDeleteVymLink;
79 extern QAction *actionEditHeading;
80 extern QAction *actionEditDelete;
81 extern QAction *actionEditAddBranch;
82 extern QAction *actionEditAddBranchAbove;
83 extern QAction *actionEditAddBranchBelow;
84 extern QAction *actionEditImportAdd;
85 extern QAction *actionEditImportReplace;
86 extern QAction *actionEditSaveBranch;
87 extern QAction *actionEditSelectFirst;
88 extern QAction *actionEditSelectLast;
89 extern QAction *actionEditLoadImage;
90 extern QAction *actionEditToggleFloatExport;
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;
102 extern QAction* actionModModeCopy;
104 extern QActionGroup *actionGroupFormatFrameTypes;
105 extern QAction *actionFormatFrameNone;
106 extern QAction *actionFormatFrameRectangle;
108 extern QActionGroup *actionGroupFormatLinkStyles;
109 extern QAction *actionFormatLinkStyleLine;
110 extern QAction *actionFormatLinkStyleParabel;
111 extern QAction *actionFormatLinkStylePolyLine;
112 extern QAction *actionFormatLinkStylePolyParabel;
114 extern QAction *actionViewToggleNoteEditor;
116 extern QAction *actionSettingsAutoedit;
117 extern QAction *actionSettingsAutoselectHeading;
118 extern QAction *actionSettingsAutoselectText;
119 extern QAction *actionSettingsPasteNewHeading;
121 extern QPopupMenu *branchContextMenu;
122 extern QPopupMenu *branchLinksContextMenu;
123 extern QPopupMenu *branchLinksContextMenuDup;
124 extern QPopupMenu *floatimageContextMenu;
125 extern QPopupMenu *saveImageFormatMenu;
126 extern QPopupMenu *exportImageFormatMenu;
127 extern QPopupMenu *canvasContextMenu;
129 extern Settings settings;
132 ///////////////////////////////////////////////////////////////////////
133 ///////////////////////////////////////////////////////////////////////
134 MapEditor::MapEditor(
135 QWidget* parent, bool interactive, const char* name, WFlags f) :
136 QCanvasView(parent,name,f)
138 //cout << "Constructor ME "<<this<<endl;
140 mapCanvas = new QCanvas(1000,800);
141 mapCanvas->setAdvancePeriod(30);
143 setCanvas (mapCanvas);
145 setVScrollBarMode ( QScrollView::AlwaysOn );
146 setHScrollBarMode ( QScrollView::AlwaysOn );
148 // Now create the _global_ system flags _once_:
149 // (Later all OrnamentedObj copy from this
150 // and set their own canvas)
151 if (!systemFlagsDefault)
153 systemFlagsDefault = new FlagRowObj (mapCanvas);
154 systemFlagsDefault->setVisibility (false);
155 systemFlagsDefault->setName ("systemFlagsDef");
157 FlagObj *fo = new FlagObj (mapCanvas);
158 fo->load(QPixmap(flag_note_xpm));
160 fo->setToolTip(tr("Note","Systemflag"));
161 systemFlagsDefault->addFlag (fo); // makes deep copy
163 fo->load(QPixmap(flag_url_xpm));
165 fo->setToolTip(tr("WWW Document (external)","Systemflag"));
166 systemFlagsDefault->addFlag (fo);
168 fo->load(QPixmap(flag_vymlink_xpm));
169 fo->setName("vymLink");
170 fo->setToolTip(tr("Link to another vym map","Systemflag"));
171 systemFlagsDefault->addFlag (fo);
173 fo->load(QPixmap(flag_scrolled_right_xpm));
174 fo->setName("scrolledright");
175 fo->setToolTip(tr("subtree is scrolled","Systemflag"));
176 systemFlagsDefault->addFlag (fo);
178 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
179 fo->setName("tmpUnscrolledright");
180 fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
181 systemFlagsDefault->addFlag (fo);
184 if (!standardFlagsDefault)
186 standardFlagsDefault = new FlagRowObj (mapCanvas);
187 standardFlagsDefault->setVisibility (false);
188 standardFlagsDefault->setName ("standardFlagsDef");
190 FlagObj *fo = new FlagObj (mapCanvas);
191 fo->load(QPixmap(flag_exclamationmark_xpm));
192 fo->setName("exclamationmark");
193 fo->setToolTip(tr("Take care!","Standardflag"));
194 standardFlagsDefault->addFlag (fo); // makes deep copy
196 fo->load(QPixmap(flag_questionmark_xpm));
197 fo->setName("questionmark");
198 fo->setToolTip(tr("Really?","Standardflag"));
199 standardFlagsDefault->addFlag (fo);
201 fo->load(QPixmap(flag_hook_green_xpm));
202 fo->setName("hook-green");
203 fo->setToolTip(tr("ok!","Standardflag"));
204 standardFlagsDefault->addFlag (fo);
206 fo->load(QPixmap(flag_cross_red_xpm));
207 fo->setName("cross-red");
208 fo->setToolTip(tr("Not ok!","Standardflag"));
209 standardFlagsDefault->addFlag (fo);
211 fo->load(QPixmap(flag_stopsign_xpm));
212 fo->setName("stopsign");
213 fo->setToolTip(tr("This won't work!","Standardflag"));
214 standardFlagsDefault->addFlag (fo);
216 fo->load(QPixmap(flag_smiley_good_xpm));
217 fo->setName("smiley-good");
218 fo->setToolTip(tr("Good","Standardflag"));
219 standardFlagsDefault->addFlag (fo);
221 fo->load(QPixmap(flag_smiley_sad_xpm));
222 fo->setName("smiley-sad");
223 fo->setToolTip(tr("Bad","Standardflag"));
224 standardFlagsDefault->addFlag (fo);
226 fo->load(QPixmap(flag_clock_xpm));
227 fo->setName("clock");
228 fo->setToolTip(tr("Time critical","Standardflag"));
229 standardFlagsDefault->addFlag (fo);
231 fo->load(QPixmap(flag_lamp_xpm));
233 fo->setToolTip(tr("Idea!","Standardflag"));
234 standardFlagsDefault->addFlag (fo);
236 fo->load(QPixmap(flag_arrow_up_xpm));
237 fo->setName("arrow-up");
238 fo->setToolTip(tr("Important","Standardflag"));
239 standardFlagsDefault->addFlag (fo);
241 fo->load(QPixmap(flag_arrow_down_xpm));
242 fo->setName("arrow-down");
243 fo->setToolTip(tr("Unimportant","Standardflag"));
244 standardFlagsDefault->addFlag (fo);
246 fo->load(QPixmap(flag_thumb_up_xpm));
247 fo->setName("thumb-up");
248 fo->setToolTip(tr("I like this","Standardflag"));
249 standardFlagsDefault->addFlag (fo);
251 fo->load(QPixmap(flag_thumb_down_xpm));
252 fo->setName("thumb-down");
253 fo->setToolTip(tr("I do not like this","Standardflag"));
254 standardFlagsDefault->addFlag (fo);
256 fo->load(QPixmap(flag_heart_xpm));
257 fo->setName("heart");
258 fo->setToolTip(tr("I just love... ","Standardflag"));
259 standardFlagsDefault->addFlag (fo);
261 fo->load(QPixmap(flag_flash_xpm));
262 fo->setName("flash");
263 fo->setToolTip(tr("Dangerous","Standardflag"));
264 standardFlagsDefault->addFlag (fo);
266 fo->load(QPixmap(flag_lifebelt_xpm));
267 fo->setName("lifebelt");
268 fo->setToolTip(tr("This will help","Standardflag"));
269 standardFlagsDefault->addFlag (fo);
274 mapCenter = new MapCenterObj(mapCanvas);
275 mapCenter->setVisibility (true);
276 mapCenter->setMapEditor (this);
277 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
281 lineedit = new QLineEdit(this, "lineedit" );
282 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
285 actColor=black; setColor (actColor);
286 defLinkColor=QColor (0,0,255);
287 defXLinkColor=QColor (180,180,180);
288 linkcolorhint=DefaultColor;
289 linkstyle=StylePolyParabel;
290 mapCanvas->setBackgroundColor (white);
292 // Create bitmap cursors, patform dependant
293 #if defined(Q_OS_MACX)
294 #include "icons/cursorhandopen16.xpm"
295 #include "icons/cursorcolorpicker16.xpm"
296 QBitmap cb( 16, 16, chandopen, TRUE );
297 QBitmap cm( 16, 16, chandopenmask, TRUE );
298 handOpenCursor=QCursor ( cb, cm );
299 // set hot spot to tip of picker
300 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
302 #include "icons/cursorhandopen.xpm"
303 #include "icons/cursorcolorpicker.xpm"
305 QBitmap cb( 32, 32, chandopen, TRUE );
306 QBitmap cm( 32, 32, chandopenmask, TRUE );
307 handOpenCursor=QCursor ( cb, cm );
308 // set hot spot to tip of picker
309 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
331 // Initialize find routine
338 blockreposition=false;
339 isInteractive=interactive;
341 // Create temporary files
344 // Initially set movingCentre
347 mapCenter->reposition(); // for positioning heading
350 MapEditor::~MapEditor()
352 //cout <<"Destructor MapEditor\n";
353 if (isInteractive) delTmpDirs();
356 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
360 QColor MapEditor::color()
365 QColor MapEditor::backgroundColor()
367 return mapCanvas->backgroundColor();
370 MapCenterObj* MapEditor::getMapCenter()
375 QCanvas* MapEditor::getCanvas()
380 void MapEditor::adjustCanvasSize()
382 // To adjust the canvas to map, viewport size and position, we have to
383 // do some coordinate magic...
385 // Get rectangle of (scroll-)view.
386 // We want to be in canvas coords, so
387 // we map. Important if view is zoomed...
388 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
389 visibleWidth(), visibleHeight()) );
391 // Now we need the bounding box of view AND map to calc the correct canvas size.
392 // Why? Because if the map itself is moved out of view, the view has to be enlarged
393 // to avoid jumping aroung...
394 QRect map=mapCenter->getTotalBBox();
396 // right edge - left edge
397 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
398 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
401 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
402 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
405 // move the map on canvas (in order to not move it on screen) this is neccessary
406 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
407 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
408 // to scroll to an empty area of canvas to the left.
409 // b) if topleft corner of map left of or above topleft of canvas
413 if (cw > mapCanvas->width() )
415 if (map.x()<0) dx=-map.x();
417 if (cw < mapCanvas->width() )
418 dx=-min (view.x(),map.x());
419 if (ch > mapCanvas->height() )
421 if (map.y()<0) dy=-map.y();
423 if (ch < mapCanvas->height() )
425 dy=-min (view.y(),map.y());
427 // We really have to resize now. Let's go...
428 mapCanvas->resize (cw,ch);
429 if ( (dx!=0) || (dy!=0) )
431 mapCenter->moveAllBy(dx,dy);
432 mapCenter->reposition();
434 // scroll the view (in order to not move map on screen)
440 bool MapEditor::blockReposition()
442 return blockreposition;
445 void MapEditor::makeTmpDirs()
447 // Create unique temporary directories
448 char tmpdir[]="/tmp/vym-XXXXXX";
449 bakMapDir=mkdtemp(tmpdir);
450 makeSubDirs(bakMapDir);
451 // FIXME set permissions
452 // and maybe use QT method for portability
455 void MapEditor::delTmpDirs()
457 //FIXME delete tmp directory, better use QT methods here:
458 system ( "rm -rf "+ bakMapDir );
462 void MapEditor::makeSubDirs(const QString &s)
470 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, SaveMode savemode)
472 // tmpdir temporary directory to which data will be writte
473 // prefix mapname, which will be appended to images etc.
474 // writeflags Only write flags for "real" save of map, not undo
475 // offset offset of bbox of whole map in canvas.
476 // Needed for XML export
477 // completeMap if false, only vympart will be written, without
494 ls="StylePolyParabel";
498 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
500 if (linkcolorhint==HeadingColor)
501 colhint=attribut("linkColorHint","HeadingColor");
503 QString mapAttr=attribut("version",__VYM_VERSION__);
504 if (savemode==CompleteMap)
505 mapAttr+= attribut("author",mapCenter->getAuthor()) +
506 attribut("comment",mapCenter->getComment()) +
507 attribut("date",mapCenter->getDate()) +
508 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
509 attribut("linkStyle", ls ) +
510 attribut("linkColor", defLinkColor.name() ) +
511 attribut("xlinkColor", defXLinkColor.name() ) +
512 attribut("xlinkWidth", QString().setNum(defXLinkWidth,10) ) +
514 s+=beginElement("vymmap",mapAttr);
517 // Find the used flags while traversing the tree
518 standardFlagsDefault->resetUsedCounter();
520 // Build xml recursivly
521 if (savemode==CompleteMap)
522 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
525 if ( undoSelection &&
526 typeid(*undoSelection) == typeid(BranchObj) )
527 s+=((BranchObj*)(undoSelection))->saveToDir(tmpdir,prefix,offset);
529 if (selection && typeid(*selection)==typeid(BranchObj))
530 s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
533 // Save local settings
534 s+=settings.getXMLData (destPath);
538 s+=valueElement("select",selection->getSelectString());
541 s+=endElement("vymmap");
544 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
549 void MapEditor::saveState()
551 saveState (CompleteMap,NULL);
554 void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part)
556 // all binary data is saved in bakMapDir (created in Constructor)
557 // the xml data itself is kept in memory in backupXML
559 // For faster write/read of data, a part of the map can be
560 // written. Then the undoSelection will mark the part of the
561 // map which should be replaced if an undo is wanted later.
563 if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) )
565 // Writing a vympart only is useful for BranchObj
567 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
571 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap);
575 void MapEditor::finishedLineEditNoSave()
577 // This is called by finishedLineEdit or any MapEditor method,
578 // which wants to assure, that lineedits finish, before e.g. a branch is
581 // After calling LineEdit and using the clipboard, the
582 // focus is not any longer on the main widget, we
583 // have to restore it using parentWidget()->setFocus()
587 editingBO->setHeading(lineedit->text() );
589 lineedit->releaseKeyboard();
591 parentWidget()->setFocus();
592 mapCenter->reposition();
594 ensureSelectionVisible();
599 bool MapEditor::isDefault()
604 bool MapEditor::isUnsaved()
609 bool MapEditor::hasChanged()
614 void MapEditor::setChanged()
619 actionEditUndo->setEnabled (true);
620 actionFileSave->setEnabled (true);
624 void MapEditor::closeMap()
626 // Finish open lineEdits
627 if (lineedit) finishedLineEditNoSave();
629 // Unselect before disabling the toolbar actions
630 if (selection) selection->unselect();
638 void MapEditor::setFilePath(QString fname)
640 setFilePath (fname,fname);
643 void MapEditor::setFilePath(QString fname, QString destname)
649 // If fname is not an absolute path, complete it
650 filePath=QDir(fname).absPath();
651 fileDir=filePath.left (1+filePath.findRev ("/"));
653 // Set short name, too. Search from behind:
654 int i=fileName.findRev("/");
655 if (i>=0) fileName=fileName.remove (0,i+1);
657 // Forget the .vym (or .xml) for name of map
658 mapName=fileName.left(fileName.findRev(".",-1,true) );
661 QString MapEditor::getFilePath()
666 QString MapEditor::getFileName()
671 QString MapEditor::getMapName()
676 QString MapEditor::getDestPath()
681 int MapEditor::load (QString &fname, const LoadMode &lmode)
683 // Finish open lineEdits
684 if (lineedit) finishedLineEditNoSave();
690 if (selection) selection->unselect();
693 mapCenter->setMapEditor(this);
694 // (map state is set later at end of load...)
698 saveState(PartOfMap,selection);
702 mapBuilderHandler handler;
705 // I am paranoid: file should exist anyway
706 // according to check in mainwindow.
709 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
710 tr("Couldn't open map " +fname)+".");
714 blockreposition=true;
715 QXmlInputSource source( file);
716 QXmlSimpleReader reader;
717 reader.setContentHandler( &handler );
718 reader.setErrorHandler( &handler );
719 handler.setMapEditor( this );
720 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
721 handler.setLoadMode (lmode);
722 bool ok = reader.parse( source );
723 blockreposition=false;
727 mapCenter->reposition();
737 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
738 tr( handler.errorProtocol() ) );
740 // Still return "success": the map maybe at least
741 // partially read by the parser
748 int MapEditor::save (const SaveMode &savemode)
750 // Finish open lineEdits
751 if (lineedit) finishedLineEditNoSave();
755 // Create mapName and fileDir
756 makeSubDirs (fileDir);
760 fname=mapName+".xml";
762 // use name given by user, even if he chooses .doc
766 // Check if fname is writeable
767 QFile file( fileDir+fname);
768 if (!file.open( IO_WriteOnly ) )
770 QMessageBox::critical( 0, tr( "Critical Save Error" ),
771 tr("Couldn't write to ") +fileDir+fname);
777 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),savemode);
779 file.setName ( fileDir + fname);
780 if ( !file.open( IO_WriteOnly ) )
782 // This should neverever happen
783 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
787 // Write it finally, and write in UTF8, no matter what
788 QTextStream ts( &file );
789 ts.setEncoding (QTextStream::UnicodeUTF8);
797 actionFileSave->setEnabled(false);
803 void MapEditor::setZipped (bool z)
808 bool MapEditor::saveZipped ()
813 void MapEditor::print()
815 // Finish open lineEdits
816 if (lineedit) finishedLineEditNoSave();
820 printer = new QPrinter;
821 printer->setColorMode (QPrinter::Color);
824 QRect totalBBox=mapCenter->getTotalBBox();
826 // Try to set orientation automagically
827 // Note: Interpretation of generated postscript is amibiguous, if
828 // there are problems with landscape mode, see
829 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
831 if (totalBBox.width()>totalBBox.height())
832 // recommend landscape
833 printer->setOrientation (QPrinter::Landscape);
835 // recommend portrait
836 printer->setOrientation (QPrinter::Portrait);
838 if ( printer->setup(this) )
839 // returns false, if printing is canceled
841 QPainter pp(printer);
843 // Don't print the visualisation of selection
844 LinkableMapObj *oldselection=NULL;
847 oldselection=selection;
848 selection->unselect();
851 // Handle sizes of map and paper:
853 // setWindow defines which part of the canvas will be transformed
854 // setViewport defines area on paper in device coordinates (dpi)
855 // e.g. (0,50,700,700) is upper part on A4
856 // see also /usr/lib/qt3/doc/html/coordsys.html
858 QPaintDeviceMetrics metrics (printer);
860 double paperAspect = (double)metrics.width() / (double)metrics.height();
861 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
863 QRect mapRect=mapCenter->getTotalBBox();
864 QCanvasRectangle *frame=NULL;
865 QCanvasText *footerFN=NULL;
866 QCanvasText *footerDate=NULL;
867 if (printFrame || printFooter)
872 // Print frame around map
873 mapRect.setRect (mapRect.x()-10, mapRect.y()-10,
874 mapRect.width()+20, mapRect.height()+20);
875 frame=new QCanvasRectangle (mapRect,mapCanvas);
876 frame->setBrush (QColor(white));
877 frame->setPen (QColor(black));
883 // Print footer below map
885 font.setPointSize(10);
886 footerFN=new QCanvasText (mapCanvas);
887 footerFN->setText ("VYM - " + fileName);
888 footerFN->setFont(font);
889 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
890 footerFN->setZ(Z_TEXT);
892 footerDate=new QCanvasText (mapCanvas);
893 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
894 footerDate->setFont(font);
895 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
896 footerDate->setZ(Z_TEXT);
898 mapRect.setRect (mapRect.x(), mapRect.y(),
899 mapRect.width(), mapRect.height()+20);
901 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height());
904 pp.setWindow (mapRect);
907 if (mapAspect>=paperAspect)
909 // Fit horizontally to paper width
910 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
913 // Fit vertically to paper height
914 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
917 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
919 // Delete Frame and footer
925 if (frame) delete (frame);
930 selection=oldselection;
936 QPixmap MapEditor::getPixmap()
938 QRect mapRect=mapCenter->getTotalBBox();
939 QPixmap pix (mapRect.size());
942 // Don't print the visualisation of selection
943 LinkableMapObj *oldselection=NULL;
946 oldselection=selection;
947 selection->unselect();
950 pp.setWindow (mapRect);
952 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
958 selection=oldselection;
965 void MapEditor::exportImage(QString fn)
967 // Finish open lineEdits
968 if (lineedit) finishedLineEditNoSave();
970 QPixmap pix (getPixmap());
974 void MapEditor::exportImage(QString fn, int item)
976 // Finish open lineEdits
977 if (lineedit) finishedLineEditNoSave();
979 QPixmap pix (getPixmap());
980 pix.save(fn, exportImageFormatMenu->text(item) );
983 void MapEditor::exportASCII()
985 // FIXME still experimental
986 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
987 fd->addFilter ("TXT (*.txt)");
988 fd->setCaption("VYM - Export (ASCII) (still experimental)");
989 fd->setMode( QFileDialog::AnyFile );
992 if ( fd->exec() == QDialog::Accepted )
994 if (QFile (fd->selectedFile()).exists() )
996 QMessageBox mb( "VYM",
997 tr("The file ") + fd->selectedFile() +
998 tr(" exists already. Do you want to overwrite it?"),
999 QMessageBox::Warning,
1000 QMessageBox::Yes | QMessageBox::Default,
1001 QMessageBox::Cancel | QMessageBox::Escape,
1002 QMessageBox::NoButton );
1004 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1005 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1009 case QMessageBox::Yes:
1011 if (!ex.setOutputDir ("out"))
1013 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1017 case QMessageBox::Cancel:
1024 ex.setPath (fd->selectedFile() );
1025 ex.setMapCenter(mapCenter);
1031 void MapEditor::exportXML(const QString &dir)
1033 // Create subdirectories
1036 // write to directory
1037 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,CompleteMap);
1040 file.setName ( dir + "/"+mapName+".xml");
1041 if ( !file.open( IO_WriteOnly ) )
1043 // This should neverever happen
1044 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1048 // Write it finally, and write in UTF8, no matter what
1049 QTextStream ts( &file );
1050 ts.setEncoding (QTextStream::UnicodeUTF8);
1054 // Now write image, too
1055 exportImage (dir+"/images/"+mapName+".png");
1058 void MapEditor::clear()
1062 selection->unselect();
1069 void MapEditor::undo()
1072 d.setPath(bakMapDir);
1075 // Finish open lineEdits
1076 if (lineedit) finishedLineEditNoSave();
1080 selection->unselect();
1084 mapBuilderHandler handler;
1085 QXmlInputSource source;
1086 source.setData(backupXML);
1087 QXmlSimpleReader reader;
1088 reader.setContentHandler( &handler );
1089 reader.setErrorHandler( &handler );
1090 handler.setMapEditor( this );
1091 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1094 selection=undoSelection;
1095 selection->select();
1096 handler.setLoadMode (ImportReplace);
1101 handler.setLoadMode (NewMap);
1103 blockreposition=true;
1104 bool ok = reader.parse( source );
1105 blockreposition=false;
1107 mapCenter->reposition();
1111 // This should never ever happen
1112 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1113 tr( handler.errorProtocol() )+" in "+backupXML );
1115 // Undo not longer available now
1116 actionEditUndo->setEnabled (false);
1117 undoSelection=false;
1122 QMessageBox::critical( 0, tr( "Critical Error" ),
1123 "Temporary directory " +bakMapDir +
1124 tr (" used for undo is gone. \n"
1125 "I will create a new one, but at the moment no undo is available.\n"
1126 "Maybe you want to reload your original data.\n\n"
1127 "Sorry for any inconveniences.") );
1132 void MapEditor::copy()
1134 // Finish open lineEdits
1135 if (lineedit) finishedLineEditNoSave();
1139 if (typeid(*selection) == typeid(BranchObj) )
1143 clipboardME->clear();
1144 clipboardME->getMapCenter()->addBranch();
1145 to=clipboardME->getMapCenter()->getLastBranch();
1148 from=(BranchObj*)(selection);
1151 // keep position relative to parent
1152 to->move2RelPos ( from->getRelPos());
1154 // select data in clipboard
1155 clipboardME->select ("bo:0");
1157 // repositioning makes testing nicer,
1158 // but is not needed usually:
1159 if (clipboardME->isVisible())
1161 clipboardME->getMapCenter()->reposition();
1164 clipboardME->hide();
1167 if (typeid(*selection) == typeid(FloatImageObj) )
1170 FloatImageObj* from;
1171 clipboardME->clear();
1172 clipboardME->getMapCenter()->addFloatImage();
1173 to=clipboardME->getMapCenter()->getLastFloatImage();
1176 from=(FloatImageObj*)(selection);
1179 // select data in clipboard
1180 clipboardME->select ("fi:0");
1182 // repositioning makes testing nicer,
1183 // but is not needed usually:
1184 if (clipboardME->isVisible())
1186 clipboardME->getMapCenter()->reposition();
1189 clipboardME->hide();
1195 LinkableMapObj* MapEditor::pasteNoSave()
1197 // Finish open lineEdits
1198 if (lineedit) finishedLineEditNoSave();
1200 LinkableMapObj *fromLMO=clipboardME->getSelection();
1201 LinkableMapObj *returnLMO=NULL;
1203 if (selection && fromLMO)
1206 if (typeid(*fromLMO) == typeid(BranchObj) )
1208 if (typeid(*selection) == typeid(MapCenterObj))
1210 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1211 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1213 if (typeid(*selection) == typeid(BranchObj))
1214 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1217 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1218 (typeid(*selection) == typeid (BranchObj) ||
1219 typeid(*selection)==typeid(MapCenterObj)) )
1220 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1226 void MapEditor::cutNoSave()
1228 // Finish open lineEdits
1229 if (lineedit) finishedLineEditNoSave();
1233 if (selection != NULL) {
1234 if (typeid(*selection) == typeid(BranchObj) )
1236 bo=(BranchObj*)(selection);
1237 par=(BranchObj*)(bo->getParObj());
1240 par->removeBranch(bo);
1242 selection->select();
1244 if (typeid(*selection) == typeid(FloatImageObj) )
1246 FloatImageObj* fio=(FloatImageObj*)(selection);
1247 par=(BranchObj*)(fio->getParObj());
1250 par->removeFloatImage(fio);
1252 selection->select();
1257 void MapEditor::paste()
1260 saveState(PartOfMap,selection);
1262 mapCenter->reposition();
1266 void MapEditor::cut()
1269 saveState(PartOfMap,selection->getParObj());
1272 mapCenter->reposition();
1276 void MapEditor::moveBranchUp()
1278 // Finish open lineEdits
1279 if (lineedit) finishedLineEditNoSave();
1283 if (typeid(*selection) == typeid(BranchObj) )
1286 saveState(PartOfMap,selection->getParObj());
1287 bo=(BranchObj*)(selection);
1288 par=(BranchObj*)(bo->getParObj());
1289 selection->unselect();
1290 selection=par->moveBranchUp (bo);
1291 selection->select();
1292 mapCenter->reposition();
1293 ensureSelectionVisible();
1297 void MapEditor::moveBranchDown()
1299 // Finish open lineEdits
1300 if (lineedit) finishedLineEditNoSave();
1304 if (typeid(*selection) == typeid(BranchObj) )
1307 saveState(PartOfMap,selection->getParObj());
1308 bo=(BranchObj*)(selection);
1309 par=(BranchObj*)(bo->getParObj());
1310 selection->unselect();
1311 selection=par->moveBranchDown(bo);
1312 selection->select();
1313 mapCenter->reposition();
1314 ensureSelectionVisible();
1318 void MapEditor::editHeading()
1320 // Finish open lineEdits
1321 if (lineedit) finishedLineEditNoSave();
1324 (typeid(*selection) == typeid(BranchObj) ||
1325 typeid(*selection) == typeid(MapCenterObj) ) )
1328 saveState(PartOfMap,selection);
1330 ensureSelectionVisible();
1331 editingBO=(BranchObj*)(selection);
1332 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1333 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1334 QString s=editingBO->getHeading();
1335 lineedit->setText(s);
1336 lineedit->setCursorPosition(1);
1337 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1338 lineedit->selectAll();
1341 lineedit->grabKeyboard();
1342 lineedit->setFocus();
1347 void MapEditor::addNewBranch(int pos)
1349 // Finish open lineEdits
1350 if (lineedit) finishedLineEditNoSave();
1353 (typeid(*selection) == typeid(BranchObj) ||
1354 typeid(*selection) == typeid(MapCenterObj) ) )
1357 saveState(PartOfMap,selection);
1359 BranchObj* bo1 = (BranchObj*) (selection);
1360 bool wasScrolled=false;
1361 BranchObj *newbo=NULL;
1364 // save scroll state. If scrolled, automatically select
1365 // new branch in order to tmp unscroll parent...
1366 wasScrolled=bo1->isScrolled();
1367 newbo=bo1->addBranch();
1370 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1374 // add above selection
1375 newbo=parbo->insertBranch(bo1->getNum());
1377 // add below selection
1378 newbo=parbo->insertBranch(bo1->getNum()+1);
1380 // This should not happen...
1385 LinkableMapObj *oldselection=selection;
1387 mapCenter->reposition();
1389 if (actionSettingsAutoedit->isOn() ||
1390 actionSettingsAutoselectHeading->isOn() )
1392 selection->unselect();
1394 selection->select();
1395 if (actionSettingsPasteNewHeading->isOn() )
1397 BranchObj *bo2= (BranchObj*)(selection);
1398 bo2->setHeading("");
1400 if (actionSettingsAutoedit->isOn() )
1402 if (!actionSettingsAutoselectHeading->isOn()
1405 selection->unselect();
1406 selection=oldselection;
1407 selection->select();
1413 void MapEditor::deleteSelection()
1415 // Finish open lineEdits
1416 if (lineedit) finishedLineEditNoSave();
1418 if (selection && typeid(*selection) ==typeid(BranchObj) )
1421 saveState(PartOfMap,selection->getParObj());
1422 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1423 BranchObj* par=(BranchObj*)(bo->getParObj());
1426 par->removeBranch(bo);
1428 selection->select();
1429 ensureSelectionVisible();
1430 mapCenter->reposition();
1433 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1436 saveState(PartOfMap,selection->getParObj());
1437 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1438 BranchObj* par=(BranchObj*)(fio->getParObj());
1441 par->removeFloatImage(fio);
1443 selection->select();
1444 ensureSelectionVisible();
1445 mapCenter->reposition();
1450 LinkableMapObj* MapEditor::getSelection()
1455 bool MapEditor::select (const QString &s)
1457 LinkableMapObj *lmo=mapCenter->findObj(s);
1459 // Finally select the found object
1462 if (selection) selection->unselect();
1464 selection->select();
1466 ensureSelectionVisible();
1472 void MapEditor::unselect()
1476 selectionLast=selection;
1477 selection->unselect();
1482 void MapEditor::reselect()
1486 selection=selectionLast;
1487 selection->select();
1492 void MapEditor::selectNextBranch()
1494 // Increase number of branch
1497 QString s=selection->getSelectString();
1503 part=s.section(",",-1);
1505 num=part.right(part.length() - 3);
1507 s=s.left (s.length() -num.length());
1510 num=QString ("%1").arg(num.toUInt()+1);
1514 // Try to select this one
1515 if (select (s)) return;
1517 // We have no direct successor,
1518 // try to increase the parental number in order to
1519 // find a successor with same depth
1521 int d=selection->getDepth();
1526 while (!found && d>0)
1528 s=s.section (",",0,d-1);
1529 // replace substring of current depth in s with "1"
1530 part=s.section(",",-1);
1532 num=part.right(part.length() - 3);
1536 // increase number of parent
1537 num=QString ("%1").arg(num.toUInt()+1);
1538 s=s.section (",",0,d-2) + ","+ typ+num;
1541 // Special case, look at orientation
1542 if (selection->getOrientation()==OrientRightOfCenter)
1543 num=QString ("%1").arg(num.toUInt()+1);
1545 num=QString ("%1").arg(num.toUInt()-1);
1550 // pad to oldDepth, select the first branch for each depth
1551 for (i=d;i<oldDepth;i++)
1556 if ( ((BranchObj*)(selection))->countBranches()>0)
1564 // try to select the freshly built string
1572 void MapEditor::selectPrevBranch()
1574 // Decrease number of branch
1577 QString s=selection->getSelectString();
1583 part=s.section(",",-1);
1585 num=part.right(part.length() - 3);
1587 s=s.left (s.length() -num.length());
1590 num=QString ("%1").arg(num.toUInt()-1);
1594 // Try to select this one
1595 if (select (s)) return;
1597 // We have no direct precessor,
1598 // try to decrease the parental number in order to
1599 // find a precessor with same depth
1601 int d=selection->getDepth();
1606 while (!found && d>0)
1608 s=s.section (",",0,d-1);
1609 // replace substring of current depth in s with "1"
1610 part=s.section(",",-1);
1612 num=part.right(part.length() - 3);
1616 // decrease number of parent
1617 num=QString ("%1").arg(num.toUInt()-1);
1618 s=s.section (",",0,d-2) + ","+ typ+num;
1621 // Special case, look at orientation
1622 if (selection->getOrientation()==OrientRightOfCenter)
1623 num=QString ("%1").arg(num.toUInt()-1);
1625 num=QString ("%1").arg(num.toUInt()+1);
1630 // pad to oldDepth, select the last branch for each depth
1631 for (i=d;i<oldDepth;i++)
1635 if ( ((BranchObj*)(selection))->countBranches()>0)
1636 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1643 // try to select the freshly built string
1651 void MapEditor::selectUpperBranch()
1653 // Finish open lineEdits
1654 if (lineedit) finishedLineEditNoSave();
1658 if (typeid(*selection) == typeid(BranchObj))
1660 if (selection->getOrientation()==OrientRightOfCenter)
1663 if (selection->getDepth()==1)
1671 void MapEditor::selectLowerBranch()
1673 // Finish open lineEdits
1674 if (lineedit) finishedLineEditNoSave();
1678 if (typeid(*selection) == typeid(BranchObj))
1680 if (selection->getOrientation()==OrientRightOfCenter)
1683 if (selection->getDepth()==1)
1692 void MapEditor::selectLeftBranch()
1694 // Finish open lineEdits
1695 if (lineedit) finishedLineEditNoSave();
1701 if (typeid(*selection) == typeid(MapCenterObj))
1703 par= (BranchObj*) (selection);
1704 bo=par->getLastSelectedBranch();
1707 // Workaround for reselecting on left and right side
1708 if (bo->getOrientation()==OrientRightOfCenter)
1710 bo=par->getLastBranch();
1716 selection->select();
1718 ensureSelectionVisible();
1723 par=(BranchObj*)(selection->getParObj());
1724 if (selection->getOrientation()==OrientRightOfCenter)
1726 if (typeid(*selection) == typeid(BranchObj) ||
1727 typeid(*selection) == typeid(FloatImageObj))
1729 selection->unselect();
1731 selection->select();
1733 ensureSelectionVisible();
1737 if (typeid(*selection) == typeid(BranchObj) )
1739 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1742 selection->unselect();
1744 selection->select();
1746 ensureSelectionVisible();
1754 void MapEditor::selectRightBranch()
1756 // Finish open lineEdits
1757 if (lineedit) finishedLineEditNoSave();
1764 if (typeid(*selection) == typeid(MapCenterObj))
1766 par= (BranchObj*) (selection);
1767 bo=par->getLastSelectedBranch();
1770 // Workaround for relecting on left and right side
1771 if (bo->getOrientation()==OrientLeftOfCenter)
1772 bo=par->getFirstBranch();
1777 selection->select();
1778 ensureSelectionVisible();
1783 par=(BranchObj*)(selection->getParObj());
1784 if (selection->getOrientation()==OrientLeftOfCenter)
1786 if (typeid(*selection) == typeid(BranchObj) ||
1787 typeid(*selection) == typeid(FloatImageObj))
1789 selection->unselect();
1791 selection->select();
1793 ensureSelectionVisible();
1797 if (typeid(*selection) == typeid(BranchObj) )
1799 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1802 selection->unselect();
1804 selection->select();
1806 ensureSelectionVisible();
1814 void MapEditor::selectFirstBranch()
1816 // Finish open lineEdits
1817 if (lineedit) finishedLineEditNoSave();
1823 if (typeid(*selection) == typeid(BranchObj))
1825 bo1= (BranchObj*) (selection);
1826 par=(BranchObj*)(bo1->getParObj());
1827 bo2=par->getFirstBranch();
1831 selection->select();
1832 ensureSelectionVisible();
1839 void MapEditor::selectLastBranch()
1841 // Finish open lineEdits
1842 if (lineedit) finishedLineEditNoSave();
1848 if (typeid(*selection) == typeid(BranchObj))
1850 bo1= (BranchObj*) (selection);
1851 par=(BranchObj*)(bo1->getParObj());
1852 bo2=par->getLastBranch();
1856 selection->select();
1857 ensureSelectionVisible();
1864 void MapEditor::setColor(QColor c)
1869 void MapEditor::selectBackgroundColor()
1871 // Finish open lineEdits
1872 if (lineedit) finishedLineEditNoSave();
1874 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
1875 if ( !col.isValid() ) return;
1876 setBackgroundColor( col );
1880 void MapEditor::setBackgroundColor(QColor c)
1882 mapCanvas->setBackgroundColor (c);
1885 QColor MapEditor::pickColor()
1889 if (typeid(*selection) == typeid(BranchObj) ||
1890 typeid(*selection) == typeid(MapCenterObj))
1892 BranchObj *bo=(BranchObj*)(selection);
1893 actColor=bo->getColor();
1899 void MapEditor::colorItem()
1903 if (typeid(*selection) == typeid(BranchObj) ||
1904 typeid(*selection) == typeid(MapCenterObj))
1907 saveState(PartOfMap,selection);
1908 BranchObj *bo=(BranchObj*)(selection);
1909 bo->setColor(actColor, false); // color links, color childs
1914 void MapEditor::colorBranch()
1918 if (typeid(*selection) == typeid(BranchObj) ||
1919 typeid(*selection) == typeid(MapCenterObj))
1922 saveState(PartOfMap,selection);
1923 BranchObj *bo=(BranchObj*)(selection);
1924 bo->setColor(actColor, true); // color links, color childs
1930 void MapEditor::toggleStandardFlag(QString f)
1935 saveState(PartOfMap,selection);
1936 ((BranchObj*)(selection))->toggleStandardFlag (f);
1940 void MapEditor::setViewCenter()
1942 // transform to CanvasView Coord:
1943 QPoint p=worldMatrix().map(movingCenter);
1944 center ( p.x(), p.y());
1948 BranchObj* MapEditor::findText (QString s, bool cs)
1951 { // Nothing found or new find process
1953 // nothing found, start again
1955 itFind=mapCenter->first();
1957 bool searching=true;
1958 bool foundNote=false;
1959 while (searching && !EOFind)
1963 // Searching in Note
1964 if (itFind->getNote().contains(s,cs))
1966 if (selection!=itFind)
1968 if (selection) ((BranchObj*)(selection))->unselect();
1970 selection->select();
1972 ensureSelectionVisible();
1974 if (textEditor->findText(s,cs))
1980 // Searching in Heading
1981 if (searching && itFind->getHeading().contains (s,cs) )
1983 if (selection) ((BranchObj*)(selection))->unselect();
1985 selection->select();
1987 ensureSelectionVisible();
1993 itFind=itFind->next();
1994 if (!itFind) EOFind=true;
2000 return (BranchObj*)(selection);
2005 void MapEditor::findReset()
2006 { // Necessary if text to find changes during a find process
2011 void MapEditor::openURL()
2015 if (typeid(*selection) == typeid(BranchObj) ||
2016 typeid(*selection) == typeid(MapCenterObj))
2018 QString url=((BranchObj*)(selection))->getURL();
2020 QProcess *proc = new QProcess( this );
2022 #if !defined(Q_OS_MACX)
2023 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2025 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2026 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2029 proc->addArgument( url);
2031 if ( !proc->start() )
2033 if (mainWindow->settingsURL() )
2039 void MapEditor::editURL()
2041 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2042 typeid(*selection) == typeid(MapCenterObj)) )
2045 QString text = QInputDialog::getText(
2046 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2047 ((BranchObj*)(selection))->getURL(), &ok, this );
2050 // user entered something and pressed OK
2051 ((BranchObj*)(selection))->setURL (text);
2058 void MapEditor::editHeading2URL()
2060 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2061 typeid(*selection) == typeid(MapCenterObj)) )
2063 BranchObj *b=(BranchObj*)(selection);
2064 b->setURL (b->getHeading());
2070 void MapEditor::editBugzilla2URL()
2072 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2073 typeid(*selection) == typeid(MapCenterObj)) )
2075 BranchObj *b=(BranchObj*)(selection);
2076 b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
2082 void MapEditor::editVymLink()
2084 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2085 typeid(*selection) == typeid(MapCenterObj)) )
2087 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2088 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2089 fd->setCaption(tr("VYM - Link to another map"));
2090 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2091 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2095 if ( fd->exec() == QDialog::Accepted )
2096 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2098 mapCenter->reposition();
2105 void MapEditor::deleteVymLink()
2107 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2108 typeid(*selection) == typeid(MapCenterObj)) )
2110 ((BranchObj*)(selection))->setVymLink ("" );
2112 mapCenter->reposition();
2119 QString MapEditor::getVymLink()
2121 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2122 typeid(*selection) == typeid(MapCenterObj)) )
2124 return ((BranchObj*)(selection))->getVymLink();
2130 void MapEditor::editMapInfo()
2132 ExtraInfoDialog dia;
2133 dia.setMapName (getFileName() );
2134 dia.setAuthor (mapCenter->getAuthor() );
2135 dia.setComment(mapCenter->getComment() );
2140 QCanvasItemList l=canvas()->allItems();
2141 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2143 stats+=QString ("%1 items on canvas\n").arg (i,6);
2149 bo=mapCenter->first();
2152 if (!bo->getNote().isEmpty() ) n++;
2153 f+= bo->countFloatImages();
2157 stats+=QString ("%1 branches\n").arg (b-1,6);
2158 stats+=QString ("%1 notes\n").arg (n,6);
2159 stats+=QString ("%1 images\n").arg (f,6);
2160 dia.setStats (stats);
2162 // Finally show dialog
2163 if (dia.exec() == QDialog::Accepted)
2165 mapCenter->setAuthor (dia.getAuthor() );
2166 mapCenter->setComment (dia.getComment() );
2171 void MapEditor::updateActions()
2173 if (getLinkColorHint()==HeadingColor)
2174 actionFormatLinkColorHint->setOn(true);
2176 actionFormatLinkColorHint->setOn(false);
2181 actionFormatLinkStyleLine->setOn(true);
2184 actionFormatLinkStyleParabel->setOn(true);
2187 actionFormatLinkStylePolyLine->setOn(true);
2189 case StylePolyParabel:
2190 actionFormatLinkStylePolyParabel->setOn(true);
2196 QPixmap pix( 16, 16 );
2197 pix.fill( mapCanvas->backgroundColor() );
2198 actionFormatBackColor->setIconSet( pix );
2199 pix.fill( defLinkColor );
2200 actionFormatLinkColor->setIconSet( pix );
2202 actionEditUndo->setEnabled( mapChanged );
2203 actionFileSave->setEnabled( mapUnsaved );
2207 if ( (typeid(*selection) == typeid(BranchObj)) ||
2208 (typeid(*selection) == typeid(MapCenterObj)) )
2210 BranchObj *bo=(BranchObj*)(selection);
2211 // Take care of links
2212 if (bo->countXLinks()==0)
2214 branchLinksContextMenu->clear();
2215 branchLinksContextMenu->insertItem ("No link available");
2216 branchLinksContextMenuDup->clear();
2217 branchLinksContextMenuDup->insertItem ("No link available");
2223 branchLinksContextMenu->clear();
2224 branchLinksContextMenuDup->clear();
2225 for (int i=0; i<=bo->countXLinks();i++)
2227 bot=bo->XLinkTargetAt(i);
2230 s=bot->getHeading();
2233 branchLinksContextMenu->insertItem (s);
2234 branchLinksContextMenuDup->insertItem (s);
2239 standardFlagsDefault->setEnabled (true);
2241 if ( bo->getURL().isEmpty() )
2242 actionEditOpenURL->setEnabled (false);
2244 actionEditOpenURL->setEnabled (true);
2245 actionEditURL->setEnabled (true);
2246 actionEditHeading2URL->setEnabled (true);
2247 actionEditBugzilla2URL->setEnabled (true);
2249 if ( bo->getVymLink().isEmpty() )
2251 actionEditOpenVymLink->setEnabled (false);
2252 actionEditDeleteVymLink->setEnabled (false);
2255 actionEditOpenVymLink->setEnabled (true);
2256 actionEditDeleteVymLink->setEnabled (true);
2258 actionEditVymLink->setEnabled (true);
2260 actionEditCopy->setEnabled (true);
2261 actionEditCut->setEnabled (true);
2262 actionEditPaste->setEnabled (true);
2263 actionEditMoveUp->setEnabled (true);
2264 actionEditMoveDown->setEnabled (true);
2265 actionEditToggleScroll->setEnabled (true);
2266 actionEditHeading->setEnabled (true);
2267 actionEditDelete->setEnabled (true);
2268 actionEditAddBranch->setEnabled (true);
2269 actionEditAddBranchAbove->setEnabled (true);
2270 actionEditAddBranchBelow->setEnabled (true);
2271 actionEditImportAdd->setEnabled (true);
2272 actionEditImportReplace->setEnabled (true);
2273 actionEditSaveBranch->setEnabled (true);
2274 actionEditSelectFirst->setEnabled (true);
2275 actionEditSelectLast->setEnabled (true);
2276 actionEditToggleFloatExport->setEnabled (false);
2277 actionFormatPickColor->setEnabled (true);
2278 actionFormatColorBranch->setEnabled (true);
2279 actionFormatColorSubtree->setEnabled (true);
2280 switch (selection->getFrameType())
2283 actionFormatFrameNone->setOn(true);
2286 actionFormatFrameRectangle->setOn(true);
2292 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2294 standardFlagsDefault->setEnabled (false);
2296 actionEditOpenURL->setEnabled (false);
2297 actionEditURL->setEnabled (false);
2298 actionEditHeading2URL->setEnabled (false);
2299 actionEditBugzilla2URL->setEnabled (false);
2300 actionEditOpenVymLink->setEnabled (false);
2301 actionEditVymLink->setEnabled (false);
2302 actionEditDeleteVymLink->setEnabled (false);
2304 actionEditCopy->setEnabled (true);
2305 actionEditCut->setEnabled (true);
2306 actionEditPaste->setEnabled (false); //FIXME
2307 actionEditMoveUp->setEnabled (false);
2308 actionEditMoveDown->setEnabled (false);
2309 actionEditToggleScroll->setEnabled (false);
2310 actionEditHeading->setEnabled (false);
2311 actionEditDelete->setEnabled (true);
2312 actionEditAddBranch->setEnabled (false);
2313 actionEditAddBranchAbove->setEnabled (false);
2314 actionEditAddBranchBelow->setEnabled (false);
2315 actionEditImportAdd->setEnabled (false);
2316 actionEditSaveBranch->setEnabled (false);
2317 actionEditImportReplace->setEnabled (false);
2318 actionEditSelectFirst->setEnabled (false);
2319 actionEditSelectLast->setEnabled (false);
2320 actionEditToggleFloatExport->setOn
2321 ( ((FloatImageObj*)(selection))->getFloatExport() );
2322 actionFormatPickColor->setEnabled (false);
2323 actionFormatColorBranch->setEnabled (false);
2324 actionFormatColorSubtree->setEnabled (false);
2329 standardFlagsDefault->setEnabled (false);
2331 actionEditCopy->setEnabled (false);
2332 actionEditCut->setEnabled (false);
2333 actionEditPaste->setEnabled (false);
2334 actionEditMoveUp->setEnabled (false);
2335 actionEditMoveDown->setEnabled (false);
2336 actionEditToggleScroll->setEnabled (false);
2337 actionEditOpenURL->setEnabled (false);
2338 actionEditURL->setEnabled (false);
2339 actionEditOpenVymLink->setEnabled (false);
2340 actionEditVymLink->setEnabled (false);
2341 actionEditDeleteVymLink->setEnabled (false);
2342 actionEditHeading2URL->setEnabled (false);
2343 actionEditBugzilla2URL->setEnabled (false);
2344 actionEditHeading->setEnabled (false);
2345 actionEditDelete->setEnabled (false);
2346 actionEditAddBranch->setEnabled (false);
2347 actionEditAddBranchAbove->setEnabled (false);
2348 actionEditAddBranchBelow->setEnabled (false);
2349 actionEditSaveBranch->setEnabled (false);
2350 actionEditImportReplace->setEnabled (false);
2351 actionEditSelectFirst->setEnabled (false);
2352 actionEditSelectLast->setEnabled (false);
2353 actionEditToggleFloatExport->setEnabled (false);
2354 actionFormatPickColor->setEnabled (false);
2355 actionFormatColorBranch->setEnabled (false);
2356 actionFormatColorSubtree->setEnabled (false);
2360 void MapEditor::setLinkStyle (LinkStyle ls)
2365 bo=mapCenter->first();
2369 bo->setLinkStyle(bo->getDefLinkStyle());
2376 LinkStyle MapEditor::getLinkStyle ()
2381 void MapEditor::setLinkColor(QColor c)
2387 void MapEditor::setLinkColorHint()
2389 // called from setLinkColorHint(lch) or at end of parse
2391 bo=mapCenter->first();
2399 void MapEditor::setLinkColorHint(LinkColorHint lch)
2405 void MapEditor::toggleLinkColorHint()
2407 if (linkcolorhint==HeadingColor)
2408 linkcolorhint=DefaultColor;
2410 linkcolorhint=HeadingColor;
2412 bo=mapCenter->first();
2420 LinkColorHint MapEditor::getLinkColorHint()
2422 return linkcolorhint;
2425 QColor MapEditor::getDefLinkColor()
2427 return defLinkColor;
2430 void MapEditor::setDefXLinkColor(QColor col)
2435 QColor MapEditor::getDefXLinkColor()
2437 return defXLinkColor;
2440 void MapEditor::setDefXLinkWidth (int w)
2445 int MapEditor::getDefXLinkWidth()
2447 return defXLinkWidth;
2450 void MapEditor::selectLinkColor()
2452 // Finish open lineEdits
2453 if (lineedit) finishedLineEditNoSave();
2455 QColor col = QColorDialog::getColor( defLinkColor, this );
2456 if ( !col.isValid() ) return;
2457 setLinkColor( col );
2461 void MapEditor::toggleScroll()
2463 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2465 BranchObj *bo=((BranchObj*)(selection));
2466 if (bo->countBranches()==0) return;
2467 if (bo->getDepth()==0) return;
2469 saveState(PartOfMap,selection);
2476 void MapEditor::unScrollAll()
2479 bo=mapCenter->first();
2482 if (bo->isScrolled()) bo->toggleScroll();
2487 void MapEditor::loadFloatImage ()
2490 (typeid(*selection) == typeid(BranchObj)) ||
2491 (typeid(*selection) == typeid(MapCenterObj)) )
2493 BranchObj *bo=((BranchObj*)(selection));
2495 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2496 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2497 ImagePreview *p =new ImagePreview (fd);
2498 fd->setContentsPreviewEnabled( TRUE );
2499 fd->setContentsPreview( p, p );
2500 fd->setPreviewMode( QFileDialog::Contents );
2501 fd->setCaption(tr("vym - Load image"));
2502 fd->setDir (lastImageDir);
2506 if ( fd->exec() == QDialog::Accepted )
2509 saveState(PartOfMap,selection);
2510 QString fn=fd->selectedFile();
2511 lastImageDir=fn.left(fn.findRev ("/"));
2512 bo->addFloatImage();
2513 // FIXME check if load was successful
2514 bo->getLastFloatImage()->load(fn);
2515 bo->getLastFloatImage()->setOriginalFilename(fn);
2516 mapCenter->reposition();
2523 void MapEditor::saveFloatImage (int item)
2526 (typeid(*selection) == typeid(FloatImageObj)) )
2528 FloatImageObj *fio=((FloatImageObj*)(selection));
2529 const char* fmt = saveImageFormatMenu->text(item);
2531 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2532 fd->addFilter ("PNG (*.png)");
2533 fd->addFilter ("BMP (*.bmp)");
2534 fd->addFilter ("XBM (*.xbm)");
2535 fd->addFilter ("JPG (*.jpg)");
2536 fd->addFilter ("XPM (*.xpm)");
2537 fd->addFilter ("GIF (*.gif)");
2538 fd->addFilter ("PNM (*.pnm)");
2539 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2540 fd->setCaption(tr("vym - Save image as ") + fmt);
2541 fd->setMode( QFileDialog::AnyFile );
2542 fd->setSelection (fio->getOriginalFilename());
2546 if ( fd->exec() == QDialog::Accepted )
2548 if (QFile (fd->selectedFile()).exists() )
2550 QMessageBox mb( "VYM",
2551 tr("The file ") + fd->selectedFile() +
2552 tr(" exists already. "
2553 "Do you want to overwrite it?"),
2554 QMessageBox::Warning,
2555 QMessageBox::Yes | QMessageBox::Default,
2556 QMessageBox::Cancel | QMessageBox::Escape,
2557 QMessageBox::QMessageBox::NoButton );
2559 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2560 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2563 case QMessageBox::Yes:
2566 case QMessageBox::Cancel:
2572 fio->save (fd->selectedFile(),fmt);
2577 void MapEditor::toggleFloatExport()
2580 (typeid(*selection) == typeid(FloatImageObj))||
2581 (typeid(*selection) == typeid(FloatObj)) )
2583 FloatImageObj *fio=((FloatImageObj*)(selection));
2584 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2588 void MapEditor::setFrame(const FrameType &t)
2591 (typeid(*selection) == typeid(BranchObj)) ||
2592 (typeid(*selection) == typeid(MapCenterObj)) )
2594 selection->setFrameType (t);
2595 mapCenter->reposition();
2596 selection->updateLink();
2600 void MapEditor::importDir(BranchObj *dst, QDir d)
2603 (typeid(*selection) == typeid(BranchObj)) ||
2604 (typeid(*selection) == typeid(MapCenterObj)) )
2608 // Traverse directories
2609 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2610 const QFileInfoList *dirlist = d.entryInfoList();
2611 QFileInfoListIterator itdir( *dirlist );
2614 while ( (fi = itdir.current()) != 0 )
2616 if (fi->fileName() != "." && fi->fileName() != ".." )
2619 bo=dst->getLastBranch();
2620 bo->setHeading (fi->fileName() );
2621 bo->setColor (QColor("blue"),false);
2623 if ( !d.cd(fi->fileName()) )
2624 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2634 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2635 const QFileInfoList *filelist = d.entryInfoList();
2636 QFileInfoListIterator itfile( *filelist );
2638 while ( (fi = itfile.current()) != 0 )
2641 bo=dst->getLastBranch();
2642 bo->setHeading (fi->fileName() );
2643 bo->setColor (QColor("black"),false);
2649 void MapEditor::importDir()
2652 (typeid(*selection) == typeid(BranchObj)) ||
2653 (typeid(*selection) == typeid(MapCenterObj)) )
2655 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2656 fd->setMode (QFileDialog::DirectoryOnly);
2657 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2658 fd->setCaption(tr("VYM - Choose directory structur to import"));
2662 if ( fd->exec() == QDialog::Accepted )
2664 BranchObj *bo=((BranchObj*)(selection));
2665 importDir (bo,QDir(fd->selectedFile()) );
2666 mapCenter->reposition();
2673 void MapEditor::followXLink(int i)
2676 (typeid(*selection) == typeid(BranchObj)) ||
2677 (typeid(*selection) == typeid(MapCenterObj)) )
2679 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2682 selection->unselect();
2684 selection->select();
2685 ensureSelectionVisible();
2690 void MapEditor::editXLink(int i)
2693 (typeid(*selection) == typeid(BranchObj)) ||
2694 (typeid(*selection) == typeid(MapCenterObj)) )
2696 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2699 EditXLinkDialog dia;
2701 if (dia.exec() == QDialog::Accepted)
2703 if (dia.useSettingsGlobal() )
2705 setDefXLinkColor (xlo->getColor() );
2706 setDefXLinkWidth (xlo->getWidth() );
2708 if (dia.deleteXLink())
2709 ((BranchObj*)(selection))->deleteXLinkAt(i);
2716 void MapEditor::testFunction()
2718 cout << "MapEditor::testFunction() called\n";
2719 //cout <<((BranchObj*)(selection))->getSelectString()<<endl;
2720 QString tmpdir,prefix;
2721 cout << saveToDir(tmpdir,prefix,true,QPoint(0,0),CompleteMap)<<endl;
2724 void MapEditor::ensureSelectionVisible()
2726 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2728 if (selection->getOrientation() == OrientLeftOfCenter)
2729 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2731 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2732 ensureVisible (p.x(), p.y() );
2736 void MapEditor::updateViewCenter()
2738 // Update movingCenter, so that we can zoom comfortably later
2739 QRect rc = QRect( contentsX(), contentsY(),
2740 visibleWidth(), visibleHeight() );
2741 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2742 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2743 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2746 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2748 // Lineedits are already closed by preceding
2749 // mouseEvent, we don't need to close here.
2751 QPoint p = inverseWorldMatrix().map(e->pos());
2752 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2755 { // MapObj was found
2756 if (selection != lmo)
2758 // select the MapObj
2759 if (selection) selection->unselect();
2761 selection->select();
2767 if (typeid(*selection)==typeid(BranchObj) ||
2768 typeid(*selection)==typeid(MapCenterObj) )
2770 // Context Menu on branch or mapcenter
2772 branchContextMenu->popup(e->globalPos() );
2774 if (typeid(*selection)==typeid(FloatImageObj))
2776 // Context Menu on floatimage
2778 floatimageContextMenu->popup(e->globalPos() );
2782 { // No MapObj found, we are on the Canvas itself
2783 // Context Menu on Canvas
2785 canvasContextMenu->popup(e->globalPos() );
2789 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2791 // Finish open lineEdits
2792 if (lineedit) finishedLineEditNoSave();
2794 QPoint p = inverseWorldMatrix().map(e->pos());
2795 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2797 // Special case: CTRL is pressed
2798 if (e->state() & QMouseEvent::ControlButton)
2800 if (actionModModeColor->isOn())
2802 if (e->state() & QMouseEvent::ControlButton)
2805 setCursor (pickColorCursor);
2809 if (actionModModeLink->isOn())
2811 BranchObj *bo_begin=NULL;
2813 bo_begin=(BranchObj*)(lmo);
2816 ((typeid(*selection) == typeid(BranchObj)) ||
2817 (typeid(*selection) == typeid(MapCenterObj))) )
2818 bo_begin=(BranchObj*)(selection);
2822 linkingObj_src=bo_begin;
2823 tmpXLink=new XLinkObj (mapCanvas);
2824 tmpXLink->setBegin (bo_begin);
2825 tmpXLink->setEnd (p);
2826 tmpXLink->setColor(defXLinkColor);
2827 tmpXLink->setWidth(defXLinkWidth);
2828 tmpXLink->updateXLink();
2829 tmpXLink->setVisibility (true);
2836 { // MapObj was found
2837 if (selection != lmo)
2839 // select the MapObj
2840 if (selection) selection->unselect();
2842 selection->select();
2848 // Check, if systemFlag clicked
2849 if (typeid(*selection)==typeid(BranchObj) ||
2850 typeid(*selection)==typeid(MapCenterObj) )
2852 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
2853 if (!foname.isEmpty())
2855 // Do not move, if systemFlag clicked
2859 if (foname=="vymLink")
2861 mainWindow->editOpenVymLink();
2862 // tabWidget may change, better return now
2863 // before segfaulting...
2867 mainWindow->windowToggleNoteEditor();
2871 // Left Button Move Branches
2872 if (e->button() == QMouseEvent::LeftButton )
2874 // If modMode==copy, then we want to "move" the _new_ object around
2875 // then we need the offset from p to the _old_ selection, because of tmp
2876 if (actionModModeCopy->isOn() &&
2877 e->state() & QMouseEvent::ControlButton)
2879 if (typeid(*selection)==typeid(BranchObj) )
2882 movingObj_start.setX( p.x() - selection->x() );
2883 movingObj_start.setY( p.y() - selection->y() );
2884 mapCenter->addBranch ((BranchObj*)(selection));
2886 selection=mapCenter->getLastBranch();
2887 selection->select();
2888 selection->setParObjTmp ((BranchObj*)(selection),p,1);
2889 selection->updateLink();
2893 movingObj_start.setX( p.x() - selection->x() );
2894 movingObj_start.setY( p.y() - selection->y() );
2897 movingObj=selection;
2899 // Middle Button Toggle Scroll
2900 // (On Mac OS X this won't work, but we still have
2901 // a button in the toolbar)
2902 if (e->button() == QMouseEvent::MidButton )
2906 { // No MapObj found, we are on the Canvas itself
2907 // Left Button move Pos of CanvasView
2908 if (e->button() == QMouseEvent::LeftButton )
2910 movingObj=NULL; // move Content not Obj
2911 movingObj_start=e->globalPos();
2912 movingCont_start=QPoint (contentsX(), contentsY() );
2913 movingVec=QPoint(0,0);
2914 setCursor(handOpenCursor);
2919 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
2921 QPoint p = inverseWorldMatrix().map(e->pos());
2923 // Move the selected MapObj
2924 if ( selection && movingObj)
2926 ensureVisible (p.x(),p.y());
2928 // Now move the selection, but add relative position
2929 // (movingObj_start) where selection was chosen with
2930 // mousepointer. (This avoids flickering resp. jumping
2931 // of selection back to absPos)
2933 LinkableMapObj *lmosel;
2934 lmosel = dynamic_cast <LinkableMapObj*> (selection);
2936 // Check if we could link
2937 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
2940 if (typeid(*selection) == typeid(FloatImageObj))
2944 FloatObj *fo=(FloatObj*)(selection);
2945 if (fo->getLinkStyle()==StyleUndef)
2947 fo->setLinkStyle(fo->getDefLinkStyle());
2948 fo->setLinkColor(fo->getParObj()->getLinkColor());
2950 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2954 // Relink float to new mapcenter or branch, if shift is pressed
2955 // Only relink, if selection really has a new parent
2956 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
2957 ( (typeid(*lmo)==typeid(BranchObj)) ||
2958 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
2959 ( lmo != fo->getParObj())
2962 if (typeid(*fo) == typeid(FloatImageObj))
2964 FloatImageObj *fio=(FloatImageObj*)(fo);
2965 ((BranchObj*)(lmo))->addFloatImage (fio);
2967 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2968 fio=((BranchObj*)(lmo))->getLastFloatImage();
2971 selection=(LinkableMapObj*)(fio);
2972 selection->select();
2973 movingObj=(MapObj*)(fio);
2974 // setLinkStyle calls updateLink, only set it once
2975 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
2976 fio->setLinkStyle (fio->getDefLinkStyle());
2979 // TODO if (typeid(*selection) == typeid(FloatTextObj))
2981 } else // selection != a FloatObj
2983 if (lmosel->getDepth()==0)
2985 if (e->state() == (LeftButton | !ShiftButton))
2986 // If mapCenter is moved, move all the rest by default, too.
2987 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2989 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2992 if (lmosel->getDepth()==1)
2994 // depth==1, mainbranch
2996 saveState(PartOfMap,lmosel);
2997 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3001 if (lmosel->getOrientation() == OrientLeftOfCenter)
3002 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3003 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3004 p.y()-movingObj_start.y() );
3006 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3008 // reposition subbranch
3009 lmosel->reposition();
3010 //ensureSelectionVisible();
3012 if (lmo && (lmo!=selection) &&
3013 (typeid(*lmo) == typeid(BranchObj) ||
3014 (typeid(*lmo) == typeid(MapCenterObj) )
3017 if (e->state() & QMouseEvent::ControlButton)
3019 // Special case: CTRL to link below lmo
3020 lmosel->setParObjTmp (lmo,p,+1);
3022 else if (e->state() & QMouseEvent::ShiftButton)
3023 lmosel->setParObjTmp (lmo,p,-1);
3025 lmosel->setParObjTmp (lmo,p,0);
3028 lmosel->unsetParObjTmp();
3030 if (lmo &&(lmo==selection))
3031 // Could link to myself (happens sometimes...)
3032 lmosel->unsetParObjTmp();
3034 // no Obj under selection, go back to original Parent
3035 lmosel->unsetParObjTmp();
3040 } // no FloatImageObj
3044 } // selection && moving_obj
3046 // Draw a link from one branch to another
3049 tmpXLink->setEnd (p);
3050 tmpXLink->updateXLink();
3054 if (!movingObj && !pickingColor &&!drawingLink)
3056 QPoint p=e->globalPos();
3057 movingVec.setX(-p.x() + movingObj_start.x() );
3058 movingVec.setY(-p.y() + movingObj_start.y() );
3059 setContentsPos( movingCont_start.x() + movingVec.x(),
3060 movingCont_start.y() + movingVec.y());
3067 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3069 LinkableMapObj *dst;
3070 // Have we been picking color?
3074 setCursor (ArrowCursor);
3075 // Check if we are over another branch
3076 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3077 if (dst && selection)
3079 if (e->state() & QMouseEvent::ShiftButton)
3081 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3082 ((BranchObj*)(selection))->setLinkColor ();
3086 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3087 ((BranchObj*)(selection))->setLinkColor ();
3093 // Have we been drawing a link?
3097 // Check if we are over another branch
3098 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3099 if (dst && selection)
3101 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3102 tmpXLink->updateXLink();
3103 tmpXLink->activate();
3114 // Have we been moving something?
3115 if ( selection && movingObj )
3117 // Check if we are over another branch, but ignore
3118 // any found LMOs, which are FloatObjs
3119 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3120 ((LinkableMapObj*)(selection)) );
3123 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3128 // Now check, if we have been moving a branch
3129 if (typeid(*selection) == typeid(BranchObj) )
3131 // save the position in case we link to mapcenter
3132 QPoint savePos=QPoint (selection->x(),selection->y() );
3134 // Reset the temporary drawn link to the original one
3135 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3143 // remove the current selection, if we have no destination
3144 selection->unselect();
3145 ((BranchObj*)(selection->getParObj()))->removeBranch ((BranchObj*)(selection));
3148 selection=selectionLast;
3150 selection->select();
3157 // TODO we also could check, if dest and src are on same branch,
3158 // then it would be sufficient to saveState of this branch
3160 // Modifiers allow to insert above/below dst
3161 if (e->state() & QMouseEvent::ShiftButton)
3163 ((BranchObj*)(selection))->moveBranchTo
3166 ((BranchObj*)(dst))->getNum()
3168 //if (selection) selection->select();
3170 if (e->state() & QMouseEvent::ControlButton)
3172 ((BranchObj*)(selection))->moveBranchTo
3175 ((BranchObj*)(dst))->getNum()+1
3177 //if (selection) selection->select();
3180 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
3181 if (dst->getDepth()==0)
3182 ((BranchObj*)(selection))->move (savePos);
3185 // Draw the original link, before selection was moved around
3186 mapCenter->reposition();
3188 // Finally resize canvas, if needed
3193 // maybe we moved View: set old cursor
3194 setCursor (ArrowCursor);
3198 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3200 // Finish open lineEdits
3201 if (lineedit) finishedLineEditNoSave();
3203 if (e->button() == QMouseEvent::LeftButton )
3205 QPoint p = inverseWorldMatrix().map(e->pos());
3206 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3207 if (lmo) { // MapObj was found
3208 // First select the MapObj than edit heading
3209 if (selection) selection->unselect();
3211 selection->select();
3213 saveState(PartOfMap,selection);
3219 void MapEditor::resizeEvent (QResizeEvent* e)
3221 QCanvasView::resizeEvent( e );
3224 if (!fileName.isEmpty()) s=fileName;