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 linkcolorhint=DefaultColor;
288 linkstyle=StylePolyParabel;
289 mapCanvas->setBackgroundColor (white);
291 // Create bitmap cursors, patform dependant
292 #if defined(Q_OS_MACX)
293 #include "icons/cursorhandopen16.xpm"
294 #include "icons/cursorcolorpicker16.xpm"
295 QBitmap cb( 16, 16, chandopen, TRUE );
296 QBitmap cm( 16, 16, chandopenmask, TRUE );
297 handOpenCursor=QCursor ( cb, cm );
298 // set hot spot to tip of picker
299 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
301 #include "icons/cursorhandopen.xpm"
302 #include "icons/cursorcolorpicker.xpm"
304 QBitmap cb( 32, 32, chandopen, TRUE );
305 QBitmap cm( 32, 32, chandopenmask, TRUE );
306 handOpenCursor=QCursor ( cb, cm );
307 // set hot spot to tip of picker
308 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
330 // Initialize find routine
337 blockreposition=false;
338 isInteractive=interactive;
340 // Create temporary files
343 // Initially set movingCentre
346 mapCenter->reposition(); // for positioning heading
349 MapEditor::~MapEditor()
351 //cout <<"Destructor MapEditor\n";
352 if (isInteractive) delTmpDirs();
355 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
359 QColor MapEditor::color()
364 QColor MapEditor::backgroundColor()
366 return mapCanvas->backgroundColor();
369 MapCenterObj* MapEditor::getMapCenter()
374 QCanvas* MapEditor::getCanvas()
379 void MapEditor::adjustCanvasSize()
381 // To adjust the canvas to map, viewport size and position, we have to
382 // do some coordinate magic...
384 // Get rectangle of (scroll-)view.
385 // We want to be in canvas coords, so
386 // we map. Important if view is zoomed...
387 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
388 visibleWidth(), visibleHeight()) );
390 // Now we need the bounding box of view AND map to calc the correct canvas size.
391 // Why? Because if the map itself is moved out of view, the view has to be enlarged
392 // to avoid jumping aroung...
393 QRect map=mapCenter->getTotalBBox();
395 // right edge - left edge
396 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
397 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
400 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
401 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
404 // move the map on canvas (in order to not move it on screen) this is neccessary
405 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
406 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
407 // to scroll to an empty area of canvas to the left.
408 // b) if topleft corner of map left of or above topleft of canvas
412 if (cw > mapCanvas->width() )
414 if (map.x()<0) dx=-map.x();
416 if (cw < mapCanvas->width() )
417 dx=-min (view.x(),map.x());
418 if (ch > mapCanvas->height() )
420 if (map.y()<0) dy=-map.y();
422 if (ch < mapCanvas->height() )
424 dy=-min (view.y(),map.y());
426 // We really have to resize now. Let's go...
427 mapCanvas->resize (cw,ch);
428 if ( (dx!=0) || (dy!=0) )
430 mapCenter->moveAllBy(dx,dy);
431 mapCenter->reposition();
433 // scroll the view (in order to not move map on screen)
439 bool MapEditor::blockReposition()
441 return blockreposition;
444 void MapEditor::makeTmpDirs()
446 // Create unique temporary directories
447 char tmpdir[]="/tmp/vym-XXXXXX";
448 bakMapDir=mkdtemp(tmpdir);
449 makeSubDirs(bakMapDir);
450 // FIXME set permissions
451 // and maybe use QT method for portability
454 void MapEditor::delTmpDirs()
456 //FIXME delete tmp directory, better use QT methods here:
457 system ( "rm -rf "+ bakMapDir );
461 void MapEditor::makeSubDirs(const QString &s)
469 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, SaveMode savemode)
471 // tmpdir temporary directory to which data will be writte
472 // prefix mapname, which will be appended to images etc.
473 // writeflags Only write flags for "real" save of map, not undo
474 // offset offset of bbox of whole map in canvas.
475 // Needed for XML export
476 // completeMap if false, only vympart will be written, without
493 ls="StylePolyParabel";
497 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
499 if (linkcolorhint==HeadingColor)
500 colhint=attribut("linkColorHint","HeadingColor");
502 QString mapAttr=attribut("version",__VYM_VERSION__);
503 if (savemode==CompleteMap)
504 mapAttr+= attribut("author",mapCenter->getAuthor()) +
505 attribut("comment",mapCenter->getComment()) +
506 attribut("date",mapCenter->getDate()) +
507 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
508 attribut("linkStyle", ls ) +
509 attribut("linkColor", deflinkcolor.name() ) +
511 s+=beginElement("vymmap",mapAttr);
514 // Find the used flags while traversing the tree
515 standardFlagsDefault->resetUsedCounter();
517 // Build xml recursivly
518 if (savemode==CompleteMap)
519 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
522 if ( undoSelection &&
523 typeid(*undoSelection) == typeid(BranchObj) )
524 s+=((BranchObj*)(undoSelection))->saveToDir(tmpdir,prefix,offset);
526 if (selection && typeid(*selection)==typeid(BranchObj))
527 s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
530 // Save local settings
531 s+=settings.getXMLData (destPath);
535 s+=valueElement("select",selection->getSelectString());
538 s+=endElement("vymmap");
541 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
546 void MapEditor::saveState()
548 saveState (CompleteMap,NULL);
551 void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part)
553 // all binary data is saved in bakMapDir (created in Constructor)
554 // the xml data itself is kept in memory in backupXML
556 // For faster write/read of data, a part of the map can be
557 // written. Then the undoSelection will mark the part of the
558 // map which should be replaced if an undo is wanted later.
560 if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) )
562 // Writing a vympart only is useful for BranchObj
564 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
568 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap);
572 void MapEditor::finishedLineEditNoSave()
574 // This is called by finishedLineEdit or any MapEditor method,
575 // which wants to assure, that lineedits finish, before e.g. a branch is
578 // After calling LineEdit and using the clipboard, the
579 // focus is not any longer on the main widget, we
580 // have to restore it using parentWidget()->setFocus()
584 editingBO->setHeading(lineedit->text() );
586 lineedit->releaseKeyboard();
588 parentWidget()->setFocus();
589 mapCenter->reposition();
591 ensureSelectionVisible();
596 bool MapEditor::isDefault()
601 bool MapEditor::isUnsaved()
606 bool MapEditor::hasChanged()
611 void MapEditor::setChanged()
616 actionEditUndo->setEnabled (true);
617 actionFileSave->setEnabled (true);
621 void MapEditor::closeMap()
623 // Finish open lineEdits
624 if (lineedit) finishedLineEditNoSave();
626 // Unselect before disabling the toolbar actions
627 if (selection) selection->unselect();
635 void MapEditor::setFilePath(QString fname)
637 setFilePath (fname,fname);
640 void MapEditor::setFilePath(QString fname, QString destname)
646 // If fname is not an absolute path, complete it
647 filePath=QDir(fname).absPath();
648 fileDir=filePath.left (1+filePath.findRev ("/"));
650 // Set short name, too. Search from behind:
651 int i=fileName.findRev("/");
652 if (i>=0) fileName=fileName.remove (0,i+1);
654 // Forget the .vym (or .xml) for name of map
655 mapName=fileName.left(fileName.findRev(".",-1,true) );
658 QString MapEditor::getFilePath()
663 QString MapEditor::getFileName()
668 QString MapEditor::getMapName()
673 QString MapEditor::getDestPath()
678 int MapEditor::load (QString &fname, const LoadMode &lmode)
680 // Finish open lineEdits
681 if (lineedit) finishedLineEditNoSave();
687 if (selection) selection->unselect();
690 mapCenter->setMapEditor(this);
691 // (map state is set later at end of load...)
695 saveState(PartOfMap,selection);
699 mapBuilderHandler handler;
702 // I am paranoid: file should exist anyway
703 // according to check in mainwindow.
706 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
707 tr("Couldn't open map " +fname)+".");
711 blockreposition=true;
712 QXmlInputSource source( file);
713 QXmlSimpleReader reader;
714 reader.setContentHandler( &handler );
715 reader.setErrorHandler( &handler );
716 handler.setMapEditor( this );
717 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
718 handler.setLoadMode (lmode);
719 bool ok = reader.parse( source );
720 blockreposition=false;
724 mapCenter->reposition();
734 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
735 tr( handler.errorProtocol() ) );
737 // Still return "success": the map maybe at least
738 // partially read by the parser
745 int MapEditor::save (const SaveMode &savemode)
747 // Finish open lineEdits
748 if (lineedit) finishedLineEditNoSave();
752 // Create mapName and fileDir
753 makeSubDirs (fileDir);
757 fname=mapName+".xml";
759 // use name given by user, even if he chooses .doc
763 // Check if fname is writeable
764 QFile file( fileDir+fname);
765 if (!file.open( IO_WriteOnly ) )
767 QMessageBox::critical( 0, tr( "Critical Save Error" ),
768 tr("Couldn't write to ") +fileDir+fname);
774 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),savemode);
776 file.setName ( fileDir + fname);
777 if ( !file.open( IO_WriteOnly ) )
779 // This should neverever happen
780 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
784 // Write it finally, and write in UTF8, no matter what
785 QTextStream ts( &file );
786 ts.setEncoding (QTextStream::UnicodeUTF8);
794 actionFileSave->setEnabled(false);
800 void MapEditor::setZipped (bool z)
805 bool MapEditor::saveZipped ()
810 void MapEditor::print()
812 // Finish open lineEdits
813 if (lineedit) finishedLineEditNoSave();
817 printer = new QPrinter;
818 printer->setColorMode (QPrinter::Color);
821 QRect totalBBox=mapCenter->getTotalBBox();
823 // Try to set orientation automagically
824 // Note: Interpretation of generated postscript is amibiguous, if
825 // there are problems with landscape mode, see
826 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
828 if (totalBBox.width()>totalBBox.height())
829 // recommend landscape
830 printer->setOrientation (QPrinter::Landscape);
832 // recommend portrait
833 printer->setOrientation (QPrinter::Portrait);
835 if ( printer->setup(this) )
836 // returns false, if printing is canceled
838 QPainter pp(printer);
840 // Don't print the visualisation of selection
841 LinkableMapObj *oldselection=NULL;
844 oldselection=selection;
845 selection->unselect();
848 // Handle sizes of map and paper:
850 // setWindow defines which part of the canvas will be transformed
851 // setViewport defines area on paper in device coordinates (dpi)
852 // e.g. (0,50,700,700) is upper part on A4
853 // see also /usr/lib/qt3/doc/html/coordsys.html
855 QPaintDeviceMetrics metrics (printer);
857 double paperAspect = (double)metrics.width() / (double)metrics.height();
858 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
860 QRect mapRect=mapCenter->getTotalBBox();
861 QCanvasRectangle *frame=NULL;
862 QCanvasText *footerFN=NULL;
863 QCanvasText *footerDate=NULL;
864 if (printFrame || printFooter)
869 // Print frame around map
870 mapRect.setRect (mapRect.x()-10, mapRect.y()-10,
871 mapRect.width()+20, mapRect.height()+20);
872 frame=new QCanvasRectangle (mapRect,mapCanvas);
873 frame->setBrush (QColor(white));
874 frame->setPen (QColor(black));
880 // Print footer below map
882 font.setPointSize(10);
883 footerFN=new QCanvasText (mapCanvas);
884 footerFN->setText ("VYM - " + fileName);
885 footerFN->setFont(font);
886 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
887 footerFN->setZ(Z_TEXT);
889 footerDate=new QCanvasText (mapCanvas);
890 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
891 footerDate->setFont(font);
892 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
893 footerDate->setZ(Z_TEXT);
895 mapRect.setRect (mapRect.x(), mapRect.y(),
896 mapRect.width(), mapRect.height()+20);
898 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height());
901 pp.setWindow (mapRect);
904 if (mapAspect>=paperAspect)
906 // Fit horizontally to paper width
907 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
910 // Fit vertically to paper height
911 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
914 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
916 // Delete Frame and footer
922 if (frame) delete (frame);
927 selection=oldselection;
933 QPixmap MapEditor::getPixmap()
935 QRect mapRect=mapCenter->getTotalBBox();
936 QPixmap pix (mapRect.size());
939 // Don't print the visualisation of selection
940 LinkableMapObj *oldselection=NULL;
943 oldselection=selection;
944 selection->unselect();
947 pp.setWindow (mapRect);
949 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
955 selection=oldselection;
962 void MapEditor::exportImage(QString fn)
964 // Finish open lineEdits
965 if (lineedit) finishedLineEditNoSave();
967 QPixmap pix (getPixmap());
971 void MapEditor::exportImage(QString fn, int item)
973 // Finish open lineEdits
974 if (lineedit) finishedLineEditNoSave();
976 QPixmap pix (getPixmap());
977 pix.save(fn, exportImageFormatMenu->text(item) );
980 void MapEditor::exportASCII()
982 // FIXME still experimental
983 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
984 fd->addFilter ("TXT (*.txt)");
985 fd->setCaption("VYM - Export (ASCII) (still experimental)");
986 fd->setMode( QFileDialog::AnyFile );
989 if ( fd->exec() == QDialog::Accepted )
991 if (QFile (fd->selectedFile()).exists() )
993 QMessageBox mb( "VYM",
994 tr("The file ") + fd->selectedFile() +
995 tr(" exists already. Do you want to overwrite it?"),
996 QMessageBox::Warning,
997 QMessageBox::Yes | QMessageBox::Default,
998 QMessageBox::Cancel | QMessageBox::Escape,
999 QMessageBox::NoButton );
1001 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1002 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1006 case QMessageBox::Yes:
1008 if (!ex.setOutputDir ("out"))
1010 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1014 case QMessageBox::Cancel:
1021 ex.setPath (fd->selectedFile() );
1022 ex.setMapCenter(mapCenter);
1028 void MapEditor::exportXML(const QString &dir)
1030 // Create subdirectories
1033 // write to directory
1034 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,CompleteMap);
1037 file.setName ( dir + "/"+mapName+".xml");
1038 if ( !file.open( IO_WriteOnly ) )
1040 // This should neverever happen
1041 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1045 // Write it finally, and write in UTF8, no matter what
1046 QTextStream ts( &file );
1047 ts.setEncoding (QTextStream::UnicodeUTF8);
1051 // Now write image, too
1052 exportImage (dir+"/images/"+mapName+".png");
1055 void MapEditor::clear()
1059 selection->unselect();
1066 void MapEditor::undo()
1069 d.setPath(bakMapDir);
1072 // Finish open lineEdits
1073 if (lineedit) finishedLineEditNoSave();
1077 selection->unselect();
1081 mapBuilderHandler handler;
1082 QXmlInputSource source;
1083 source.setData(backupXML);
1084 QXmlSimpleReader reader;
1085 reader.setContentHandler( &handler );
1086 reader.setErrorHandler( &handler );
1087 handler.setMapEditor( this );
1088 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1091 selection=undoSelection;
1092 selection->select();
1093 handler.setLoadMode (ImportReplace);
1098 handler.setLoadMode (NewMap);
1100 blockreposition=true;
1101 bool ok = reader.parse( source );
1102 blockreposition=false;
1104 mapCenter->reposition();
1108 // This should never ever happen
1109 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1110 tr( handler.errorProtocol() )+" in "+backupXML );
1112 // Undo not longer available now
1113 actionEditUndo->setEnabled (false);
1114 undoSelection=false;
1119 QMessageBox::critical( 0, tr( "Critical Error" ),
1120 "Temporary directory " +bakMapDir +
1121 tr (" used for undo is gone. \n"
1122 "I will create a new one, but at the moment no undo is available.\n"
1123 "Maybe you want to reload your original data.\n\n"
1124 "Sorry for any inconveniences.") );
1129 void MapEditor::copy()
1131 // Finish open lineEdits
1132 if (lineedit) finishedLineEditNoSave();
1136 if (typeid(*selection) == typeid(BranchObj) )
1140 clipboardME->clear();
1141 clipboardME->getMapCenter()->addBranch();
1142 to=clipboardME->getMapCenter()->getLastBranch();
1145 from=(BranchObj*)(selection);
1148 // keep position relative to parent
1149 to->move2RelPos ( from->getRelPos());
1151 // select data in clipboard
1152 clipboardME->select ("bo:0");
1154 // repositioning makes testing nicer,
1155 // but is not needed usually:
1156 if (clipboardME->isVisible())
1158 clipboardME->getMapCenter()->reposition();
1161 clipboardME->hide();
1164 if (typeid(*selection) == typeid(FloatImageObj) )
1167 FloatImageObj* from;
1168 clipboardME->clear();
1169 clipboardME->getMapCenter()->addFloatImage();
1170 to=clipboardME->getMapCenter()->getLastFloatImage();
1173 from=(FloatImageObj*)(selection);
1176 // select data in clipboard
1177 clipboardME->select ("fi:0");
1179 // repositioning makes testing nicer,
1180 // but is not needed usually:
1181 if (clipboardME->isVisible())
1183 clipboardME->getMapCenter()->reposition();
1186 clipboardME->hide();
1192 LinkableMapObj* MapEditor::pasteNoSave()
1194 // Finish open lineEdits
1195 if (lineedit) finishedLineEditNoSave();
1197 LinkableMapObj *fromLMO=clipboardME->getSelection();
1198 LinkableMapObj *returnLMO=NULL;
1200 if (selection && fromLMO)
1203 if (typeid(*fromLMO) == typeid(BranchObj) )
1205 if (typeid(*selection) == typeid(MapCenterObj))
1207 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1208 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1210 if (typeid(*selection) == typeid(BranchObj))
1211 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1214 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1215 (typeid(*selection) == typeid (BranchObj) ||
1216 typeid(*selection)==typeid(MapCenterObj)) )
1217 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1223 void MapEditor::cutNoSave()
1225 // Finish open lineEdits
1226 if (lineedit) finishedLineEditNoSave();
1230 if (selection != NULL) {
1231 if (typeid(*selection) == typeid(BranchObj) )
1233 bo=(BranchObj*)(selection);
1234 par=(BranchObj*)(bo->getParObj());
1237 par->removeBranch(bo);
1239 selection->select();
1241 if (typeid(*selection) == typeid(FloatImageObj) )
1243 FloatImageObj* fio=(FloatImageObj*)(selection);
1244 par=(BranchObj*)(fio->getParObj());
1247 par->removeFloatImage(fio);
1249 selection->select();
1254 void MapEditor::paste()
1257 saveState(PartOfMap,selection);
1259 mapCenter->reposition();
1263 void MapEditor::cut()
1266 saveState(PartOfMap,selection->getParObj());
1269 mapCenter->reposition();
1273 void MapEditor::moveBranchUp()
1275 // Finish open lineEdits
1276 if (lineedit) finishedLineEditNoSave();
1280 if (typeid(*selection) == typeid(BranchObj) )
1283 saveState(PartOfMap,selection->getParObj());
1284 bo=(BranchObj*)(selection);
1285 par=(BranchObj*)(bo->getParObj());
1286 selection->unselect();
1287 selection=par->moveBranchUp (bo);
1288 selection->select();
1289 mapCenter->reposition();
1290 ensureSelectionVisible();
1294 void MapEditor::moveBranchDown()
1296 // Finish open lineEdits
1297 if (lineedit) finishedLineEditNoSave();
1301 if (typeid(*selection) == typeid(BranchObj) )
1304 saveState(PartOfMap,selection->getParObj());
1305 bo=(BranchObj*)(selection);
1306 par=(BranchObj*)(bo->getParObj());
1307 selection->unselect();
1308 selection=par->moveBranchDown(bo);
1309 selection->select();
1310 mapCenter->reposition();
1311 ensureSelectionVisible();
1315 void MapEditor::editHeading()
1317 // Finish open lineEdits
1318 if (lineedit) finishedLineEditNoSave();
1321 (typeid(*selection) == typeid(BranchObj) ||
1322 typeid(*selection) == typeid(MapCenterObj) ) )
1325 saveState(PartOfMap,selection);
1327 ensureSelectionVisible();
1328 editingBO=(BranchObj*)(selection);
1329 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1330 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1331 QString s=editingBO->getHeading();
1332 lineedit->setText(s);
1333 lineedit->setCursorPosition(1);
1334 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1335 lineedit->selectAll();
1338 lineedit->grabKeyboard();
1339 lineedit->setFocus();
1344 void MapEditor::addNewBranch(int pos)
1346 // Finish open lineEdits
1347 if (lineedit) finishedLineEditNoSave();
1350 (typeid(*selection) == typeid(BranchObj) ||
1351 typeid(*selection) == typeid(MapCenterObj) ) )
1354 saveState(PartOfMap,selection);
1356 BranchObj* bo1 = (BranchObj*) (selection);
1357 bool wasScrolled=false;
1358 BranchObj *newbo=NULL;
1361 // save scroll state. If scrolled, automatically select
1362 // new branch in order to tmp unscroll parent...
1363 wasScrolled=bo1->isScrolled();
1364 newbo=bo1->addBranch();
1367 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1371 // add above selection
1372 newbo=parbo->insertBranch(bo1->getNum());
1374 // add below selection
1375 newbo=parbo->insertBranch(bo1->getNum()+1);
1377 // This should not happen...
1382 LinkableMapObj *oldselection=selection;
1384 mapCenter->reposition();
1386 if (actionSettingsAutoedit->isOn() ||
1387 actionSettingsAutoselectHeading->isOn() )
1389 selection->unselect();
1391 selection->select();
1392 if (actionSettingsPasteNewHeading->isOn() )
1394 BranchObj *bo2= (BranchObj*)(selection);
1395 bo2->setHeading("");
1397 if (actionSettingsAutoedit->isOn() )
1399 if (!actionSettingsAutoselectHeading->isOn()
1402 selection->unselect();
1403 selection=oldselection;
1404 selection->select();
1410 void MapEditor::deleteSelection()
1412 // Finish open lineEdits
1413 if (lineedit) finishedLineEditNoSave();
1415 if (selection && typeid(*selection) ==typeid(BranchObj) )
1418 saveState(PartOfMap,selection->getParObj());
1419 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1420 BranchObj* par=(BranchObj*)(bo->getParObj());
1423 par->removeBranch(bo);
1425 selection->select();
1426 ensureSelectionVisible();
1427 mapCenter->reposition();
1430 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1433 saveState(PartOfMap,selection->getParObj());
1434 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1435 BranchObj* par=(BranchObj*)(fio->getParObj());
1438 par->removeFloatImage(fio);
1440 selection->select();
1441 ensureSelectionVisible();
1442 mapCenter->reposition();
1447 LinkableMapObj* MapEditor::getSelection()
1452 bool MapEditor::select (const QString &s)
1454 LinkableMapObj *lmo=mapCenter->findObj(s);
1456 // Finally select the found object
1459 if (selection) selection->unselect();
1461 selection->select();
1463 ensureSelectionVisible();
1469 void MapEditor::unselect()
1473 selectionLast=selection;
1474 selection->unselect();
1479 void MapEditor::reselect()
1483 selection=selectionLast;
1484 selection->select();
1489 void MapEditor::selectNextBranch()
1491 // Increase number of branch
1494 QString s=selection->getSelectString();
1500 part=s.section(",",-1);
1502 num=part.right(part.length() - 3);
1504 s=s.left (s.length() -num.length());
1507 num=QString ("%1").arg(num.toUInt()+1);
1511 // Try to select this one
1512 if (select (s)) return;
1514 // We have no direct successor,
1515 // try to increase the parental number in order to
1516 // find a successor with same depth
1518 int d=selection->getDepth();
1523 while (!found && d>0)
1525 s=s.section (",",0,d-1);
1526 // replace substring of current depth in s with "1"
1527 part=s.section(",",-1);
1529 num=part.right(part.length() - 3);
1533 // increase number of parent
1534 num=QString ("%1").arg(num.toUInt()+1);
1535 s=s.section (",",0,d-2) + ","+ typ+num;
1538 // Special case, look at orientation
1539 if (selection->getOrientation()==OrientRightOfCenter)
1540 num=QString ("%1").arg(num.toUInt()+1);
1542 num=QString ("%1").arg(num.toUInt()-1);
1547 // pad to oldDepth, select the first branch for each depth
1548 for (i=d;i<oldDepth;i++)
1553 if ( ((BranchObj*)(selection))->countBranches()>0)
1561 // try to select the freshly built string
1569 void MapEditor::selectPrevBranch()
1571 // Decrease number of branch
1574 QString s=selection->getSelectString();
1580 part=s.section(",",-1);
1582 num=part.right(part.length() - 3);
1584 s=s.left (s.length() -num.length());
1587 num=QString ("%1").arg(num.toUInt()-1);
1591 // Try to select this one
1592 if (select (s)) return;
1594 // We have no direct precessor,
1595 // try to decrease the parental number in order to
1596 // find a precessor with same depth
1598 int d=selection->getDepth();
1603 while (!found && d>0)
1605 s=s.section (",",0,d-1);
1606 // replace substring of current depth in s with "1"
1607 part=s.section(",",-1);
1609 num=part.right(part.length() - 3);
1613 // decrease number of parent
1614 num=QString ("%1").arg(num.toUInt()-1);
1615 s=s.section (",",0,d-2) + ","+ typ+num;
1618 // Special case, look at orientation
1619 if (selection->getOrientation()==OrientRightOfCenter)
1620 num=QString ("%1").arg(num.toUInt()-1);
1622 num=QString ("%1").arg(num.toUInt()+1);
1627 // pad to oldDepth, select the last branch for each depth
1628 for (i=d;i<oldDepth;i++)
1632 if ( ((BranchObj*)(selection))->countBranches()>0)
1633 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1640 // try to select the freshly built string
1648 void MapEditor::selectUpperBranch()
1650 // Finish open lineEdits
1651 if (lineedit) finishedLineEditNoSave();
1655 if (typeid(*selection) == typeid(BranchObj))
1657 if (selection->getOrientation()==OrientRightOfCenter)
1660 if (selection->getDepth()==1)
1668 void MapEditor::selectLowerBranch()
1670 // Finish open lineEdits
1671 if (lineedit) finishedLineEditNoSave();
1675 if (typeid(*selection) == typeid(BranchObj))
1677 if (selection->getOrientation()==OrientRightOfCenter)
1680 if (selection->getDepth()==1)
1689 void MapEditor::selectLeftBranch()
1691 // Finish open lineEdits
1692 if (lineedit) finishedLineEditNoSave();
1698 if (typeid(*selection) == typeid(MapCenterObj))
1700 par= (BranchObj*) (selection);
1701 bo=par->getLastSelectedBranch();
1704 // Workaround for reselecting on left and right side
1705 if (bo->getOrientation()==OrientRightOfCenter)
1707 bo=par->getLastBranch();
1713 selection->select();
1715 ensureSelectionVisible();
1720 par=(BranchObj*)(selection->getParObj());
1721 if (selection->getOrientation()==OrientRightOfCenter)
1723 if (typeid(*selection) == typeid(BranchObj) ||
1724 typeid(*selection) == typeid(FloatImageObj))
1726 selection->unselect();
1728 selection->select();
1730 ensureSelectionVisible();
1734 if (typeid(*selection) == typeid(BranchObj) )
1736 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1739 selection->unselect();
1741 selection->select();
1743 ensureSelectionVisible();
1751 void MapEditor::selectRightBranch()
1753 // Finish open lineEdits
1754 if (lineedit) finishedLineEditNoSave();
1761 if (typeid(*selection) == typeid(MapCenterObj))
1763 par= (BranchObj*) (selection);
1764 bo=par->getLastSelectedBranch();
1767 // Workaround for relecting on left and right side
1768 if (bo->getOrientation()==OrientLeftOfCenter)
1769 bo=par->getFirstBranch();
1774 selection->select();
1775 ensureSelectionVisible();
1780 par=(BranchObj*)(selection->getParObj());
1781 if (selection->getOrientation()==OrientLeftOfCenter)
1783 if (typeid(*selection) == typeid(BranchObj) ||
1784 typeid(*selection) == typeid(FloatImageObj))
1786 selection->unselect();
1788 selection->select();
1790 ensureSelectionVisible();
1794 if (typeid(*selection) == typeid(BranchObj) )
1796 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1799 selection->unselect();
1801 selection->select();
1803 ensureSelectionVisible();
1811 void MapEditor::selectFirstBranch()
1813 // Finish open lineEdits
1814 if (lineedit) finishedLineEditNoSave();
1820 if (typeid(*selection) == typeid(BranchObj))
1822 bo1= (BranchObj*) (selection);
1823 par=(BranchObj*)(bo1->getParObj());
1824 bo2=par->getFirstBranch();
1828 selection->select();
1829 ensureSelectionVisible();
1836 void MapEditor::selectLastBranch()
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->getLastBranch();
1853 selection->select();
1854 ensureSelectionVisible();
1861 void MapEditor::setColor(QColor c)
1866 void MapEditor::selectBackgroundColor()
1868 // Finish open lineEdits
1869 if (lineedit) finishedLineEditNoSave();
1871 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
1872 if ( !col.isValid() ) return;
1873 setBackgroundColor( col );
1877 void MapEditor::setBackgroundColor(QColor c)
1879 mapCanvas->setBackgroundColor (c);
1882 QColor MapEditor::pickColor()
1886 if (typeid(*selection) == typeid(BranchObj) ||
1887 typeid(*selection) == typeid(MapCenterObj))
1889 BranchObj *bo=(BranchObj*)(selection);
1890 actColor=bo->getColor();
1896 void MapEditor::colorItem()
1900 if (typeid(*selection) == typeid(BranchObj) ||
1901 typeid(*selection) == typeid(MapCenterObj))
1904 saveState(PartOfMap,selection);
1905 BranchObj *bo=(BranchObj*)(selection);
1906 bo->setColor(actColor, false); // color links, color childs
1911 void MapEditor::colorBranch()
1915 if (typeid(*selection) == typeid(BranchObj) ||
1916 typeid(*selection) == typeid(MapCenterObj))
1919 saveState(PartOfMap,selection);
1920 BranchObj *bo=(BranchObj*)(selection);
1921 bo->setColor(actColor, true); // color links, color childs
1927 void MapEditor::toggleStandardFlag(QString f)
1932 saveState(PartOfMap,selection);
1933 ((BranchObj*)(selection))->toggleStandardFlag (f);
1937 void MapEditor::setViewCenter()
1939 // transform to CanvasView Coord:
1940 QPoint p=worldMatrix().map(movingCenter);
1941 center ( p.x(), p.y());
1945 BranchObj* MapEditor::findText (QString s, bool cs)
1948 { // Nothing found or new find process
1950 // nothing found, start again
1952 itFind=mapCenter->first();
1954 bool searching=true;
1955 bool foundNote=false;
1956 while (searching && !EOFind)
1960 // Searching in Note
1961 if (itFind->getNote().contains(s,cs))
1963 if (selection!=itFind)
1965 if (selection) ((BranchObj*)(selection))->unselect();
1967 selection->select();
1969 ensureSelectionVisible();
1971 if (textEditor->findText(s,cs))
1977 // Searching in Heading
1978 if (searching && itFind->getHeading().contains (s,cs) )
1980 if (selection) ((BranchObj*)(selection))->unselect();
1982 selection->select();
1984 ensureSelectionVisible();
1990 itFind=itFind->next();
1991 if (!itFind) EOFind=true;
1997 return (BranchObj*)(selection);
2002 void MapEditor::findReset()
2003 { // Necessary if text to find changes during a find process
2008 void MapEditor::openURL()
2012 if (typeid(*selection) == typeid(BranchObj) ||
2013 typeid(*selection) == typeid(MapCenterObj))
2015 QString url=((BranchObj*)(selection))->getURL();
2017 QProcess *proc = new QProcess( this );
2019 #if !defined(Q_OS_MACX)
2020 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2022 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2023 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2026 proc->addArgument( url);
2028 if ( !proc->start() )
2030 if (mainWindow->settingsURL() )
2036 void MapEditor::editURL()
2038 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2039 typeid(*selection) == typeid(MapCenterObj)) )
2042 QString text = QInputDialog::getText(
2043 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2044 ((BranchObj*)(selection))->getURL(), &ok, this );
2047 // user entered something and pressed OK
2048 ((BranchObj*)(selection))->setURL (text);
2055 void MapEditor::editHeading2URL()
2057 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2058 typeid(*selection) == typeid(MapCenterObj)) )
2060 BranchObj *b=(BranchObj*)(selection);
2061 b->setURL (b->getHeading());
2067 void MapEditor::editBugzilla2URL()
2069 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2070 typeid(*selection) == typeid(MapCenterObj)) )
2072 BranchObj *b=(BranchObj*)(selection);
2073 b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
2079 void MapEditor::editVymLink()
2081 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2082 typeid(*selection) == typeid(MapCenterObj)) )
2084 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2085 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2086 fd->setCaption(tr("VYM - Link to another map"));
2087 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2088 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2092 if ( fd->exec() == QDialog::Accepted )
2093 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2095 mapCenter->reposition();
2102 void MapEditor::deleteVymLink()
2104 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2105 typeid(*selection) == typeid(MapCenterObj)) )
2107 ((BranchObj*)(selection))->setVymLink ("" );
2109 mapCenter->reposition();
2116 QString MapEditor::getVymLink()
2118 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2119 typeid(*selection) == typeid(MapCenterObj)) )
2121 return ((BranchObj*)(selection))->getVymLink();
2127 void MapEditor::editMapInfo()
2129 ExtraInfoDialog dia;
2130 dia.setMapName (getFileName() );
2131 dia.setAuthor (mapCenter->getAuthor() );
2132 dia.setComment(mapCenter->getComment() );
2137 QCanvasItemList l=canvas()->allItems();
2138 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2140 stats+=QString ("%1 items on canvas\n").arg (i,6);
2146 bo=mapCenter->first();
2149 if (!bo->getNote().isEmpty() ) n++;
2150 f+= bo->countFloatImages();
2154 stats+=QString ("%1 branches\n").arg (b-1,6);
2155 stats+=QString ("%1 notes\n").arg (n,6);
2156 stats+=QString ("%1 images\n").arg (f,6);
2157 dia.setStats (stats);
2159 // Finally show dialog
2160 if (dia.exec() == QDialog::Accepted)
2162 mapCenter->setAuthor (dia.getAuthor() );
2163 mapCenter->setComment (dia.getComment() );
2168 void MapEditor::updateActions()
2170 if (getLinkColorHint()==HeadingColor)
2171 actionFormatLinkColorHint->setOn(true);
2173 actionFormatLinkColorHint->setOn(false);
2178 actionFormatLinkStyleLine->setOn(true);
2181 actionFormatLinkStyleParabel->setOn(true);
2184 actionFormatLinkStylePolyLine->setOn(true);
2186 case StylePolyParabel:
2187 actionFormatLinkStylePolyParabel->setOn(true);
2193 QPixmap pix( 16, 16 );
2194 pix.fill( mapCanvas->backgroundColor() );
2195 actionFormatBackColor->setIconSet( pix );
2196 pix.fill( deflinkcolor );
2197 actionFormatLinkColor->setIconSet( pix );
2199 actionEditUndo->setEnabled( mapChanged );
2200 actionFileSave->setEnabled( mapUnsaved );
2204 if ( (typeid(*selection) == typeid(BranchObj)) ||
2205 (typeid(*selection) == typeid(MapCenterObj)) )
2207 BranchObj *bo=(BranchObj*)(selection);
2208 // Take care of links
2209 if (bo->countXLinks()==0)
2211 branchLinksContextMenu->clear();
2212 branchLinksContextMenu->insertItem ("No link available");
2213 branchLinksContextMenuDup->clear();
2214 branchLinksContextMenuDup->insertItem ("No link available");
2220 branchLinksContextMenu->clear();
2221 branchLinksContextMenuDup->clear();
2222 for (int i=0; i<=bo->countXLinks();i++)
2224 bot=bo->XLinkTargetAt(i);
2227 s=bot->getHeading();
2230 branchLinksContextMenu->insertItem (s);
2231 branchLinksContextMenuDup->insertItem (s);
2236 standardFlagsDefault->setEnabled (true);
2238 if ( bo->getURL().isEmpty() )
2239 actionEditOpenURL->setEnabled (false);
2241 actionEditOpenURL->setEnabled (true);
2242 actionEditURL->setEnabled (true);
2243 actionEditHeading2URL->setEnabled (true);
2244 actionEditBugzilla2URL->setEnabled (true);
2246 if ( bo->getVymLink().isEmpty() )
2248 actionEditOpenVymLink->setEnabled (false);
2249 actionEditDeleteVymLink->setEnabled (false);
2252 actionEditOpenVymLink->setEnabled (true);
2253 actionEditDeleteVymLink->setEnabled (true);
2255 actionEditVymLink->setEnabled (true);
2257 actionEditCopy->setEnabled (true);
2258 actionEditCut->setEnabled (true);
2259 actionEditPaste->setEnabled (true);
2260 actionEditMoveUp->setEnabled (true);
2261 actionEditMoveDown->setEnabled (true);
2262 actionEditToggleScroll->setEnabled (true);
2263 actionEditHeading->setEnabled (true);
2264 actionEditDelete->setEnabled (true);
2265 actionEditAddBranch->setEnabled (true);
2266 actionEditAddBranchAbove->setEnabled (true);
2267 actionEditAddBranchBelow->setEnabled (true);
2268 actionEditImportAdd->setEnabled (true);
2269 actionEditImportReplace->setEnabled (true);
2270 actionEditSaveBranch->setEnabled (true);
2271 actionEditSelectFirst->setEnabled (true);
2272 actionEditSelectLast->setEnabled (true);
2273 actionEditToggleFloatExport->setEnabled (false);
2274 actionFormatPickColor->setEnabled (true);
2275 actionFormatColorBranch->setEnabled (true);
2276 actionFormatColorSubtree->setEnabled (true);
2277 switch (selection->getFrameType())
2280 actionFormatFrameNone->setOn(true);
2283 actionFormatFrameRectangle->setOn(true);
2289 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2291 standardFlagsDefault->setEnabled (false);
2293 actionEditOpenURL->setEnabled (false);
2294 actionEditURL->setEnabled (false);
2295 actionEditHeading2URL->setEnabled (false);
2296 actionEditBugzilla2URL->setEnabled (false);
2297 actionEditOpenVymLink->setEnabled (false);
2298 actionEditVymLink->setEnabled (false);
2299 actionEditDeleteVymLink->setEnabled (false);
2301 actionEditCopy->setEnabled (true);
2302 actionEditCut->setEnabled (true);
2303 actionEditPaste->setEnabled (false); //FIXME
2304 actionEditMoveUp->setEnabled (false);
2305 actionEditMoveDown->setEnabled (false);
2306 actionEditToggleScroll->setEnabled (false);
2307 actionEditHeading->setEnabled (false);
2308 actionEditDelete->setEnabled (true);
2309 actionEditAddBranch->setEnabled (false);
2310 actionEditAddBranchAbove->setEnabled (false);
2311 actionEditAddBranchBelow->setEnabled (false);
2312 actionEditImportAdd->setEnabled (false);
2313 actionEditSaveBranch->setEnabled (false);
2314 actionEditImportReplace->setEnabled (false);
2315 actionEditSelectFirst->setEnabled (false);
2316 actionEditSelectLast->setEnabled (false);
2317 actionEditToggleFloatExport->setOn
2318 ( ((FloatImageObj*)(selection))->getFloatExport() );
2319 actionFormatPickColor->setEnabled (false);
2320 actionFormatColorBranch->setEnabled (false);
2321 actionFormatColorSubtree->setEnabled (false);
2326 standardFlagsDefault->setEnabled (false);
2328 actionEditCopy->setEnabled (false);
2329 actionEditCut->setEnabled (false);
2330 actionEditPaste->setEnabled (false);
2331 actionEditMoveUp->setEnabled (false);
2332 actionEditMoveDown->setEnabled (false);
2333 actionEditToggleScroll->setEnabled (false);
2334 actionEditOpenURL->setEnabled (false);
2335 actionEditURL->setEnabled (false);
2336 actionEditOpenVymLink->setEnabled (false);
2337 actionEditVymLink->setEnabled (false);
2338 actionEditDeleteVymLink->setEnabled (false);
2339 actionEditHeading2URL->setEnabled (false);
2340 actionEditBugzilla2URL->setEnabled (false);
2341 actionEditHeading->setEnabled (false);
2342 actionEditDelete->setEnabled (false);
2343 actionEditAddBranch->setEnabled (false);
2344 actionEditAddBranchAbove->setEnabled (false);
2345 actionEditAddBranchBelow->setEnabled (false);
2346 actionEditSaveBranch->setEnabled (false);
2347 actionEditImportReplace->setEnabled (false);
2348 actionEditSelectFirst->setEnabled (false);
2349 actionEditSelectLast->setEnabled (false);
2350 actionEditToggleFloatExport->setEnabled (false);
2351 actionFormatPickColor->setEnabled (false);
2352 actionFormatColorBranch->setEnabled (false);
2353 actionFormatColorSubtree->setEnabled (false);
2357 void MapEditor::setLinkStyle (LinkStyle ls)
2362 bo=mapCenter->first();
2366 bo->setLinkStyle(bo->getDefLinkStyle());
2373 LinkStyle MapEditor::getLinkStyle ()
2378 void MapEditor::setLinkColor(QColor c)
2384 void MapEditor::setLinkColorHint()
2386 // called from setLinkColorHint(lch) or at end of parse
2388 bo=mapCenter->first();
2396 void MapEditor::setLinkColorHint(LinkColorHint lch)
2402 void MapEditor::toggleLinkColorHint()
2404 if (linkcolorhint==HeadingColor)
2405 linkcolorhint=DefaultColor;
2407 linkcolorhint=HeadingColor;
2409 bo=mapCenter->first();
2417 LinkColorHint MapEditor::getLinkColorHint()
2419 return linkcolorhint;
2422 QColor MapEditor::getDefLinkColor()
2424 return deflinkcolor;
2427 void MapEditor::selectLinkColor()
2429 // Finish open lineEdits
2430 if (lineedit) finishedLineEditNoSave();
2432 QColor col = QColorDialog::getColor( deflinkcolor, this );
2433 if ( !col.isValid() ) return;
2434 setLinkColor( col );
2438 void MapEditor::toggleScroll()
2440 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2442 BranchObj *bo=((BranchObj*)(selection));
2443 if (bo->countBranches()==0) return;
2444 if (bo->getDepth()==0) return;
2446 saveState(PartOfMap,selection);
2453 void MapEditor::unScrollAll()
2456 bo=mapCenter->first();
2459 if (bo->isScrolled()) bo->toggleScroll();
2464 void MapEditor::loadFloatImage ()
2467 (typeid(*selection) == typeid(BranchObj)) ||
2468 (typeid(*selection) == typeid(MapCenterObj)) )
2470 BranchObj *bo=((BranchObj*)(selection));
2472 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2473 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2474 ImagePreview *p =new ImagePreview (fd);
2475 fd->setContentsPreviewEnabled( TRUE );
2476 fd->setContentsPreview( p, p );
2477 fd->setPreviewMode( QFileDialog::Contents );
2478 fd->setCaption(tr("vym - Load image"));
2479 fd->setDir (lastImageDir);
2483 if ( fd->exec() == QDialog::Accepted )
2486 saveState(PartOfMap,selection);
2487 QString fn=fd->selectedFile();
2488 lastImageDir=fn.left(fn.findRev ("/"));
2489 bo->addFloatImage();
2490 // FIXME check if load was successful
2491 bo->getLastFloatImage()->load(fn);
2492 bo->getLastFloatImage()->setOriginalFilename(fn);
2493 mapCenter->reposition();
2500 void MapEditor::saveFloatImage (int item)
2503 (typeid(*selection) == typeid(FloatImageObj)) )
2505 FloatImageObj *fio=((FloatImageObj*)(selection));
2506 const char* fmt = saveImageFormatMenu->text(item);
2508 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2509 fd->addFilter ("PNG (*.png)");
2510 fd->addFilter ("BMP (*.bmp)");
2511 fd->addFilter ("XBM (*.xbm)");
2512 fd->addFilter ("JPG (*.jpg)");
2513 fd->addFilter ("XPM (*.xpm)");
2514 fd->addFilter ("GIF (*.gif)");
2515 fd->addFilter ("PNM (*.pnm)");
2516 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2517 fd->setCaption(tr("vym - Save image as ") + fmt);
2518 fd->setMode( QFileDialog::AnyFile );
2519 fd->setSelection (fio->getOriginalFilename());
2523 if ( fd->exec() == QDialog::Accepted )
2525 if (QFile (fd->selectedFile()).exists() )
2527 QMessageBox mb( "VYM",
2528 tr("The file ") + fd->selectedFile() +
2529 tr(" exists already. "
2530 "Do you want to overwrite it?"),
2531 QMessageBox::Warning,
2532 QMessageBox::Yes | QMessageBox::Default,
2533 QMessageBox::Cancel | QMessageBox::Escape,
2534 QMessageBox::QMessageBox::NoButton );
2536 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2537 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2540 case QMessageBox::Yes:
2543 case QMessageBox::Cancel:
2549 fio->save (fd->selectedFile(),fmt);
2554 void MapEditor::toggleFloatExport()
2557 (typeid(*selection) == typeid(FloatImageObj))||
2558 (typeid(*selection) == typeid(FloatObj)) )
2560 FloatImageObj *fio=((FloatImageObj*)(selection));
2561 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2565 void MapEditor::setFrame(const FrameType &t)
2568 (typeid(*selection) == typeid(BranchObj)) ||
2569 (typeid(*selection) == typeid(MapCenterObj)) )
2571 selection->setFrameType (t);
2572 mapCenter->reposition();
2573 selection->updateLink();
2577 void MapEditor::importDir(BranchObj *dst, QDir d)
2580 (typeid(*selection) == typeid(BranchObj)) ||
2581 (typeid(*selection) == typeid(MapCenterObj)) )
2585 // Traverse directories
2586 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2587 const QFileInfoList *dirlist = d.entryInfoList();
2588 QFileInfoListIterator itdir( *dirlist );
2591 while ( (fi = itdir.current()) != 0 )
2593 if (fi->fileName() != "." && fi->fileName() != ".." )
2596 bo=dst->getLastBranch();
2597 bo->setHeading (fi->fileName() );
2598 bo->setColor (QColor("blue"),false);
2600 if ( !d.cd(fi->fileName()) )
2601 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2611 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2612 const QFileInfoList *filelist = d.entryInfoList();
2613 QFileInfoListIterator itfile( *filelist );
2615 while ( (fi = itfile.current()) != 0 )
2618 bo=dst->getLastBranch();
2619 bo->setHeading (fi->fileName() );
2620 bo->setColor (QColor("black"),false);
2626 void MapEditor::importDir()
2629 (typeid(*selection) == typeid(BranchObj)) ||
2630 (typeid(*selection) == typeid(MapCenterObj)) )
2632 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2633 fd->setMode (QFileDialog::DirectoryOnly);
2634 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2635 fd->setCaption(tr("VYM - Choose directory structur to import"));
2639 if ( fd->exec() == QDialog::Accepted )
2641 BranchObj *bo=((BranchObj*)(selection));
2642 importDir (bo,QDir(fd->selectedFile()) );
2643 mapCenter->reposition();
2650 void MapEditor::followXLink(int i)
2652 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2655 selection->unselect();
2657 selection->select();
2658 ensureSelectionVisible();
2662 void MapEditor::editXLink(int i)
2664 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2667 EditXLinkDialog dia;
2668 if (dia.exec() == QDialog::Accepted)
2670 if (dia.deleteXLink())
2671 ((BranchObj*)(selection))->deleteXLinkAt(i);
2677 void MapEditor::testFunction()
2679 cout << "MapEditor::testFunction() called\n";
2680 //cout <<((BranchObj*)(selection))->getSelectString()<<endl;
2681 QString tmpdir,prefix;
2682 cout << saveToDir(tmpdir,prefix,true,QPoint(0,0),CompleteMap)<<endl;
2685 void MapEditor::ensureSelectionVisible()
2687 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2689 if (selection->getOrientation() == OrientLeftOfCenter)
2690 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2692 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2693 ensureVisible (p.x(), p.y() );
2697 void MapEditor::updateViewCenter()
2699 // Update movingCenter, so that we can zoom comfortably later
2700 QRect rc = QRect( contentsX(), contentsY(),
2701 visibleWidth(), visibleHeight() );
2702 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2703 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2704 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2707 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2709 // Lineedits are already closed by preceding
2710 // mouseEvent, we don't need to close here.
2712 QPoint p = inverseWorldMatrix().map(e->pos());
2713 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2716 { // MapObj was found
2717 if (selection != lmo)
2719 // select the MapObj
2720 if (selection) selection->unselect();
2722 selection->select();
2728 if (typeid(*selection)==typeid(BranchObj) ||
2729 typeid(*selection)==typeid(MapCenterObj) )
2731 // Context Menu on branch or mapcenter
2733 branchContextMenu->popup(e->globalPos() );
2735 if (typeid(*selection)==typeid(FloatImageObj))
2737 // Context Menu on floatimage
2739 floatimageContextMenu->popup(e->globalPos() );
2743 { // No MapObj found, we are on the Canvas itself
2744 // Context Menu on Canvas
2746 canvasContextMenu->popup(e->globalPos() );
2750 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2752 // Finish open lineEdits
2753 if (lineedit) finishedLineEditNoSave();
2755 QPoint p = inverseWorldMatrix().map(e->pos());
2756 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2758 // Special case: CTRL is pressed
2759 if (e->state() & QMouseEvent::ControlButton)
2761 if (actionModModeColor->isOn())
2763 if (e->state() & QMouseEvent::ControlButton)
2766 setCursor (pickColorCursor);
2770 if (actionModModeLink->isOn())
2772 BranchObj *bo_begin=NULL;
2774 bo_begin=(BranchObj*)(lmo);
2777 ((typeid(*selection) == typeid(BranchObj)) ||
2778 (typeid(*selection) == typeid(MapCenterObj))) )
2779 bo_begin=(BranchObj*)(selection);
2783 linkingObj_src=bo_begin;
2784 tmpXLink=new XLinkObj (mapCanvas);
2785 tmpXLink->setBegin (bo_begin);
2786 tmpXLink->setEnd (p);
2787 tmpXLink->updateXLink();
2788 tmpXLink->setVisibility (true);
2795 { // MapObj was found
2796 if (selection != lmo)
2798 // select the MapObj
2799 if (selection) selection->unselect();
2801 selection->select();
2807 // Check, if systemFlag clicked
2808 if (typeid(*selection)==typeid(BranchObj) ||
2809 typeid(*selection)==typeid(MapCenterObj) )
2811 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
2812 if (!foname.isEmpty())
2814 // Do not move, if systemFlag clicked
2818 if (foname=="vymLink")
2820 mainWindow->editOpenVymLink();
2821 // tabWidget may change, better return now
2822 // before segfaulting...
2826 mainWindow->windowToggleNoteEditor();
2830 // Left Button Move Branches
2831 if (e->button() == QMouseEvent::LeftButton )
2833 // If modMode==copy, then we want to "move" the _new_ object around
2834 // then we need the offset from p to the _old_ selection, because of tmp
2835 if (actionModModeCopy->isOn() &&
2836 e->state() & QMouseEvent::ControlButton)
2838 if (typeid(*selection)==typeid(BranchObj) )
2841 movingObj_start.setX( p.x() - selection->x() );
2842 movingObj_start.setY( p.y() - selection->y() );
2843 mapCenter->addBranch ((BranchObj*)(selection));
2845 selection=mapCenter->getLastBranch();
2846 selection->select();
2847 selection->setParObjTmp ((BranchObj*)(selection),p,1);
2848 selection->updateLink();
2852 movingObj_start.setX( p.x() - selection->x() );
2853 movingObj_start.setY( p.y() - selection->y() );
2856 movingObj=selection;
2858 // Middle Button Toggle Scroll
2859 // (On Mac OS X this won't work, but we still have
2860 // a button in the toolbar)
2861 if (e->button() == QMouseEvent::MidButton )
2865 { // No MapObj found, we are on the Canvas itself
2866 // Left Button move Pos of CanvasView
2867 if (e->button() == QMouseEvent::LeftButton )
2869 movingObj=NULL; // move Content not Obj
2870 movingObj_start=e->globalPos();
2871 movingCont_start=QPoint (contentsX(), contentsY() );
2872 movingVec=QPoint(0,0);
2873 setCursor(handOpenCursor);
2878 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
2880 QPoint p = inverseWorldMatrix().map(e->pos());
2882 // Move the selected MapObj
2883 if ( selection && movingObj)
2885 ensureVisible (p.x(),p.y());
2887 // Now move the selection, but add relative position
2888 // (movingObj_start) where selection was chosen with
2889 // mousepointer. (This avoids flickering resp. jumping
2890 // of selection back to absPos)
2892 LinkableMapObj *lmosel;
2893 lmosel = dynamic_cast <LinkableMapObj*> (selection);
2895 // Check if we could link
2896 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
2899 if (typeid(*selection) == typeid(FloatImageObj))
2903 FloatObj *fo=(FloatObj*)(selection);
2904 if (fo->getLinkStyle()==StyleUndef)
2906 fo->setLinkStyle(fo->getDefLinkStyle());
2907 fo->setLinkColor(fo->getParObj()->getLinkColor());
2909 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2913 // Relink float to new mapcenter or branch, if shift is pressed
2914 // Only relink, if selection really has a new parent
2915 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
2916 ( (typeid(*lmo)==typeid(BranchObj)) ||
2917 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
2918 ( lmo != fo->getParObj())
2921 if (typeid(*fo) == typeid(FloatImageObj))
2923 FloatImageObj *fio=(FloatImageObj*)(fo);
2924 ((BranchObj*)(lmo))->addFloatImage (fio);
2926 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2927 fio=((BranchObj*)(lmo))->getLastFloatImage();
2930 selection=(LinkableMapObj*)(fio);
2931 selection->select();
2932 movingObj=(MapObj*)(fio);
2933 // setLinkStyle calls updateLink, only set it once
2934 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
2935 fio->setLinkStyle (fio->getDefLinkStyle());
2938 // TODO if (typeid(*selection) == typeid(FloatTextObj))
2940 } else // selection != a FloatObj
2942 if (lmosel->getDepth()==0)
2944 if (e->state() == (LeftButton | !ShiftButton))
2945 // If mapCenter is moved, move all the rest by default, too.
2946 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2948 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2951 if (lmosel->getDepth()==1)
2953 // depth==1, mainbranch
2955 saveState(PartOfMap,lmosel);
2956 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2960 if (lmosel->getOrientation() == OrientLeftOfCenter)
2961 // Add width of bbox here, otherwise alignRelTo will cause jumping around
2962 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
2963 p.y()-movingObj_start.y() );
2965 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2967 // reposition subbranch
2968 lmosel->reposition();
2969 //ensureSelectionVisible();
2971 if (lmo && (lmo!=selection) &&
2972 (typeid(*lmo) == typeid(BranchObj) ||
2973 (typeid(*lmo) == typeid(MapCenterObj) )
2976 if (e->state() & QMouseEvent::ControlButton)
2978 // Special case: CTRL to link below lmo
2979 lmosel->setParObjTmp (lmo,p,+1);
2981 else if (e->state() & QMouseEvent::ShiftButton)
2982 lmosel->setParObjTmp (lmo,p,-1);
2984 lmosel->setParObjTmp (lmo,p,0);
2987 lmosel->unsetParObjTmp();
2989 if (lmo &&(lmo==selection))
2990 // Could link to myself (happens sometimes...)
2991 lmosel->unsetParObjTmp();
2993 // no Obj under selection, go back to original Parent
2994 lmosel->unsetParObjTmp();
2999 } // no FloatImageObj
3003 } // selection && moving_obj
3005 // Draw a link from one branch to another
3008 tmpXLink->setEnd (p);
3009 tmpXLink->updateXLink();
3013 if (!movingObj && !pickingColor &&!drawingLink)
3015 QPoint p=e->globalPos();
3016 movingVec.setX(-p.x() + movingObj_start.x() );
3017 movingVec.setY(-p.y() + movingObj_start.y() );
3018 setContentsPos( movingCont_start.x() + movingVec.x(),
3019 movingCont_start.y() + movingVec.y());
3026 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3028 LinkableMapObj *dst;
3029 // Have we been picking color?
3033 setCursor (ArrowCursor);
3034 // Check if we are over another branch
3035 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3036 if (dst && selection)
3038 if (e->state() & QMouseEvent::ShiftButton)
3040 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3041 ((BranchObj*)(selection))->setLinkColor ();
3045 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3046 ((BranchObj*)(selection))->setLinkColor ();
3052 // Have we been drawing a link?
3056 // Check if we are over another branch
3057 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3058 if (dst && selection)
3060 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3061 tmpXLink->updateXLink();
3062 tmpXLink->activate();
3073 // Have we been moving something?
3074 if ( selection && movingObj )
3076 // Check if we are over another branch, but ignore
3077 // any found LMOs, which are FloatObjs
3078 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3079 ((LinkableMapObj*)(selection)) );
3082 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3087 // Now check, if we have been moving a branch
3088 if (typeid(*selection) == typeid(BranchObj) )
3090 // save the position in case we link to mapcenter
3091 QPoint savePos=QPoint (selection->x(),selection->y() );
3093 // Reset the temporary drawn link to the original one
3094 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3102 // remove the current selection, if we have no destination
3103 selection->unselect();
3104 ((BranchObj*)(selection->getParObj()))->removeBranch ((BranchObj*)(selection));
3107 selection=selectionLast;
3109 selection->select();
3116 // TODO we also could check, if dest and src are on same branch,
3117 // then it would be sufficient to saveState of this branch
3119 // Modifiers allow to insert above/below dst
3120 if (e->state() & QMouseEvent::ShiftButton)
3122 ((BranchObj*)(selection))->moveBranchTo
3125 ((BranchObj*)(dst))->getNum()
3127 //if (selection) selection->select();
3129 if (e->state() & QMouseEvent::ControlButton)
3131 ((BranchObj*)(selection))->moveBranchTo
3134 ((BranchObj*)(dst))->getNum()+1
3136 //if (selection) selection->select();
3139 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
3140 if (dst->getDepth()==0)
3141 ((BranchObj*)(selection))->move (savePos);
3144 // Draw the original link, before selection was moved around
3145 mapCenter->reposition();
3147 // Finally resize canvas, if needed
3152 // maybe we moved View: set old cursor
3153 setCursor (ArrowCursor);
3157 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3159 // Finish open lineEdits
3160 if (lineedit) finishedLineEditNoSave();
3162 if (e->button() == QMouseEvent::LeftButton )
3164 QPoint p = inverseWorldMatrix().map(e->pos());
3165 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3166 if (lmo) { // MapObj was found
3167 // First select the MapObj than edit heading
3168 if (selection) selection->unselect();
3170 selection->select();
3172 saveState(PartOfMap,selection);
3178 void MapEditor::resizeEvent (QResizeEvent* e)
3180 QCanvasView::resizeEvent( e );
3183 if (!fileName.isEmpty()) s=fileName;