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 "editlinkdialog.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 LinkableMapObj* MapEditor::findObj (QString s)
1454 LinkableMapObj *lmo=mapCenter;
1458 while (!s.isEmpty() )
1460 part=s.section(",",0,0);
1462 num=part.right(part.length() - 3);
1469 lmo=mapCenter->getBranchNum (num.toUInt());
1472 lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt());
1475 lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
1478 if (s.contains(","))
1479 s=s.right(s.length() - part.length() -1 );
1486 bool MapEditor::select (const QString &s)
1488 LinkableMapObj *lmo=findObj(s);
1490 // Finally select the found object
1493 if (selection) selection->unselect();
1495 selection->select();
1497 ensureSelectionVisible();
1503 void MapEditor::unselect()
1507 selectionLast=selection;
1508 selection->unselect();
1513 void MapEditor::reselect()
1517 selection=selectionLast;
1518 selection->select();
1523 void MapEditor::selectNextBranch()
1525 // Increase number of branch
1528 QString s=selection->getSelectString();
1534 part=s.section(",",-1);
1536 num=part.right(part.length() - 3);
1538 s=s.left (s.length() -num.length());
1541 num=QString ("%1").arg(num.toUInt()+1);
1545 // Try to select this one
1546 if (select (s)) return;
1548 // We have no direct successor,
1549 // try to increase the parental number in order to
1550 // find a successor with same depth
1552 int d=selection->getDepth();
1557 while (!found && d>0)
1559 s=s.section (",",0,d-1);
1560 // replace substring of current depth in s with "1"
1561 part=s.section(",",-1);
1563 num=part.right(part.length() - 3);
1567 // increase number of parent
1568 num=QString ("%1").arg(num.toUInt()+1);
1569 s=s.section (",",0,d-2) + ","+ typ+num;
1572 // Special case, look at orientation
1573 if (selection->getOrientation()==OrientRightOfCenter)
1574 num=QString ("%1").arg(num.toUInt()+1);
1576 num=QString ("%1").arg(num.toUInt()-1);
1581 // pad to oldDepth, select the first branch for each depth
1582 for (i=d;i<oldDepth;i++)
1587 if ( ((BranchObj*)(selection))->countBranches()>0)
1595 // try to select the freshly built string
1603 void MapEditor::selectPrevBranch()
1605 // Decrease number of branch
1608 QString s=selection->getSelectString();
1614 part=s.section(",",-1);
1616 num=part.right(part.length() - 3);
1618 s=s.left (s.length() -num.length());
1621 num=QString ("%1").arg(num.toUInt()-1);
1625 // Try to select this one
1626 if (select (s)) return;
1628 // We have no direct precessor,
1629 // try to decrease the parental number in order to
1630 // find a precessor with same depth
1632 int d=selection->getDepth();
1637 while (!found && d>0)
1639 s=s.section (",",0,d-1);
1640 // replace substring of current depth in s with "1"
1641 part=s.section(",",-1);
1643 num=part.right(part.length() - 3);
1647 // decrease number of parent
1648 num=QString ("%1").arg(num.toUInt()-1);
1649 s=s.section (",",0,d-2) + ","+ typ+num;
1652 // Special case, look at orientation
1653 if (selection->getOrientation()==OrientRightOfCenter)
1654 num=QString ("%1").arg(num.toUInt()-1);
1656 num=QString ("%1").arg(num.toUInt()+1);
1661 // pad to oldDepth, select the last branch for each depth
1662 for (i=d;i<oldDepth;i++)
1666 if ( ((BranchObj*)(selection))->countBranches()>0)
1667 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1674 // try to select the freshly built string
1682 void MapEditor::selectUpperBranch()
1684 // Finish open lineEdits
1685 if (lineedit) finishedLineEditNoSave();
1689 if (typeid(*selection) == typeid(BranchObj))
1691 if (selection->getOrientation()==OrientRightOfCenter)
1694 if (selection->getDepth()==1)
1702 void MapEditor::selectLowerBranch()
1704 // Finish open lineEdits
1705 if (lineedit) finishedLineEditNoSave();
1709 if (typeid(*selection) == typeid(BranchObj))
1711 if (selection->getOrientation()==OrientRightOfCenter)
1714 if (selection->getDepth()==1)
1723 void MapEditor::selectLeftBranch()
1725 // Finish open lineEdits
1726 if (lineedit) finishedLineEditNoSave();
1732 if (typeid(*selection) == typeid(MapCenterObj))
1734 par= (BranchObj*) (selection);
1735 bo=par->getLastSelectedBranch();
1738 // Workaround for reselecting on left and right side
1739 if (bo->getOrientation()==OrientRightOfCenter)
1741 bo=par->getLastBranch();
1747 selection->select();
1749 ensureSelectionVisible();
1754 par=(BranchObj*)(selection->getParObj());
1755 if (selection->getOrientation()==OrientRightOfCenter)
1757 if (typeid(*selection) == typeid(BranchObj) ||
1758 typeid(*selection) == typeid(FloatImageObj))
1760 selection->unselect();
1762 selection->select();
1764 ensureSelectionVisible();
1768 if (typeid(*selection) == typeid(BranchObj) )
1770 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1773 selection->unselect();
1775 selection->select();
1777 ensureSelectionVisible();
1785 void MapEditor::selectRightBranch()
1787 // Finish open lineEdits
1788 if (lineedit) finishedLineEditNoSave();
1795 if (typeid(*selection) == typeid(MapCenterObj))
1797 par= (BranchObj*) (selection);
1798 bo=par->getLastSelectedBranch();
1801 // Workaround for relecting on left and right side
1802 if (bo->getOrientation()==OrientLeftOfCenter)
1803 bo=par->getFirstBranch();
1808 selection->select();
1809 ensureSelectionVisible();
1814 par=(BranchObj*)(selection->getParObj());
1815 if (selection->getOrientation()==OrientLeftOfCenter)
1817 if (typeid(*selection) == typeid(BranchObj) ||
1818 typeid(*selection) == typeid(FloatImageObj))
1820 selection->unselect();
1822 selection->select();
1824 ensureSelectionVisible();
1828 if (typeid(*selection) == typeid(BranchObj) )
1830 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1833 selection->unselect();
1835 selection->select();
1837 ensureSelectionVisible();
1845 void MapEditor::selectFirstBranch()
1847 // Finish open lineEdits
1848 if (lineedit) finishedLineEditNoSave();
1854 if (typeid(*selection) == typeid(BranchObj))
1856 bo1= (BranchObj*) (selection);
1857 par=(BranchObj*)(bo1->getParObj());
1858 bo2=par->getFirstBranch();
1862 selection->select();
1863 ensureSelectionVisible();
1870 void MapEditor::selectLastBranch()
1872 // Finish open lineEdits
1873 if (lineedit) finishedLineEditNoSave();
1879 if (typeid(*selection) == typeid(BranchObj))
1881 bo1= (BranchObj*) (selection);
1882 par=(BranchObj*)(bo1->getParObj());
1883 bo2=par->getLastBranch();
1887 selection->select();
1888 ensureSelectionVisible();
1895 void MapEditor::setColor(QColor c)
1900 void MapEditor::selectBackgroundColor()
1902 // Finish open lineEdits
1903 if (lineedit) finishedLineEditNoSave();
1905 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
1906 if ( !col.isValid() ) return;
1907 setBackgroundColor( col );
1911 void MapEditor::setBackgroundColor(QColor c)
1913 mapCanvas->setBackgroundColor (c);
1916 QColor MapEditor::pickColor()
1920 if (typeid(*selection) == typeid(BranchObj) ||
1921 typeid(*selection) == typeid(MapCenterObj))
1923 BranchObj *bo=(BranchObj*)(selection);
1924 actColor=bo->getColor();
1930 void MapEditor::colorItem()
1934 if (typeid(*selection) == typeid(BranchObj) ||
1935 typeid(*selection) == typeid(MapCenterObj))
1938 saveState(PartOfMap,selection);
1939 BranchObj *bo=(BranchObj*)(selection);
1940 bo->setColor(actColor, false); // color links, color childs
1945 void MapEditor::colorBranch()
1949 if (typeid(*selection) == typeid(BranchObj) ||
1950 typeid(*selection) == typeid(MapCenterObj))
1953 saveState(PartOfMap,selection);
1954 BranchObj *bo=(BranchObj*)(selection);
1955 bo->setColor(actColor, true); // color links, color childs
1961 void MapEditor::toggleStandardFlag(QString f)
1966 saveState(PartOfMap,selection);
1967 ((BranchObj*)(selection))->toggleStandardFlag (f);
1971 void MapEditor::setViewCenter()
1973 // transform to CanvasView Coord:
1974 QPoint p=worldMatrix().map(movingCenter);
1975 center ( p.x(), p.y());
1979 BranchObj* MapEditor::findText (QString s, bool cs)
1982 { // Nothing found or new find process
1984 // nothing found, start again
1986 itFind=mapCenter->first();
1988 bool searching=true;
1989 bool foundNote=false;
1990 while (searching && !EOFind)
1994 // Searching in Note
1995 if (itFind->getNote().contains(s,cs))
1997 if (selection!=itFind)
1999 if (selection) ((BranchObj*)(selection))->unselect();
2001 selection->select();
2003 ensureSelectionVisible();
2005 if (textEditor->findText(s,cs))
2011 // Searching in Heading
2012 if (searching && itFind->getHeading().contains (s,cs) )
2014 if (selection) ((BranchObj*)(selection))->unselect();
2016 selection->select();
2018 ensureSelectionVisible();
2024 itFind=itFind->next();
2025 if (!itFind) EOFind=true;
2031 return (BranchObj*)(selection);
2036 void MapEditor::findReset()
2037 { // Necessary if text to find changes during a find process
2042 void MapEditor::openURL()
2046 if (typeid(*selection) == typeid(BranchObj) ||
2047 typeid(*selection) == typeid(MapCenterObj))
2049 QString url=((BranchObj*)(selection))->getURL();
2051 QProcess *proc = new QProcess( this );
2053 #if !defined(Q_OS_MACX)
2054 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2056 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2057 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2060 proc->addArgument( url);
2062 if ( !proc->start() )
2064 if (mainWindow->settingsURL() )
2070 void MapEditor::editURL()
2072 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2073 typeid(*selection) == typeid(MapCenterObj)) )
2076 QString text = QInputDialog::getText(
2077 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2078 ((BranchObj*)(selection))->getURL(), &ok, this );
2081 // user entered something and pressed OK
2082 ((BranchObj*)(selection))->setURL (text);
2089 void MapEditor::editHeading2URL()
2091 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2092 typeid(*selection) == typeid(MapCenterObj)) )
2094 BranchObj *b=(BranchObj*)(selection);
2095 b->setURL (b->getHeading());
2101 void MapEditor::editBugzilla2URL()
2103 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2104 typeid(*selection) == typeid(MapCenterObj)) )
2106 BranchObj *b=(BranchObj*)(selection);
2107 b->setURL ("http://bugzilla.suse.de/show_bug.cgi?id="+b->getHeading());
2108 b->setURL ("https://bugzilla.innerweb.novell.com/show_bug.cgi?id="+b->getHeading());
2114 void MapEditor::editVymLink()
2116 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2117 typeid(*selection) == typeid(MapCenterObj)) )
2119 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2120 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2121 fd->setCaption(tr("VYM - Link to another map"));
2122 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2123 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2127 if ( fd->exec() == QDialog::Accepted )
2128 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2130 mapCenter->reposition();
2137 void MapEditor::deleteVymLink()
2139 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2140 typeid(*selection) == typeid(MapCenterObj)) )
2142 ((BranchObj*)(selection))->setVymLink ("" );
2144 mapCenter->reposition();
2151 QString MapEditor::getVymLink()
2153 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2154 typeid(*selection) == typeid(MapCenterObj)) )
2156 return ((BranchObj*)(selection))->getVymLink();
2162 void MapEditor::editMapInfo()
2164 ExtraInfoDialog dia;
2165 dia.setMapName (getFileName() );
2166 dia.setAuthor (mapCenter->getAuthor() );
2167 dia.setComment(mapCenter->getComment() );
2172 QCanvasItemList l=canvas()->allItems();
2173 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2175 stats+=QString ("%1 items on canvas\n").arg (i,6);
2181 bo=mapCenter->first();
2184 if (!bo->getNote().isEmpty() ) n++;
2185 f+= bo->countFloatImages();
2189 stats+=QString ("%1 branches\n").arg (b-1,6);
2190 stats+=QString ("%1 notes\n").arg (n,6);
2191 stats+=QString ("%1 images\n").arg (f,6);
2192 dia.setStats (stats);
2194 // Finally show dialog
2195 if (dia.exec() == QDialog::Accepted)
2197 mapCenter->setAuthor (dia.getAuthor() );
2198 mapCenter->setComment (dia.getComment() );
2203 void MapEditor::updateActions()
2205 if (getLinkColorHint()==HeadingColor)
2206 actionFormatLinkColorHint->setOn(true);
2208 actionFormatLinkColorHint->setOn(false);
2213 actionFormatLinkStyleLine->setOn(true);
2216 actionFormatLinkStyleParabel->setOn(true);
2219 actionFormatLinkStylePolyLine->setOn(true);
2221 case StylePolyParabel:
2222 actionFormatLinkStylePolyParabel->setOn(true);
2228 QPixmap pix( 16, 16 );
2229 pix.fill( mapCanvas->backgroundColor() );
2230 actionFormatBackColor->setIconSet( pix );
2231 pix.fill( deflinkcolor );
2232 actionFormatLinkColor->setIconSet( pix );
2234 actionEditUndo->setEnabled( mapChanged );
2235 actionFileSave->setEnabled( mapUnsaved );
2239 if ( (typeid(*selection) == typeid(BranchObj)) ||
2240 (typeid(*selection) == typeid(MapCenterObj)) )
2242 BranchObj *bo=(BranchObj*)(selection);
2243 // Take care of links
2244 if (bo->countLinks()==0)
2246 branchLinksContextMenu->clear();
2247 branchLinksContextMenu->insertItem ("No link available");
2248 branchLinksContextMenuDup->clear();
2249 branchLinksContextMenuDup->insertItem ("No link available");
2255 branchLinksContextMenu->clear();
2256 branchLinksContextMenuDup->clear();
2257 for (int i=0; i<=bo->countLinks();i++)
2259 bot=bo->linkTargetAt(i);
2262 s=bot->getHeading();
2265 branchLinksContextMenu->insertItem (s);
2266 branchLinksContextMenuDup->insertItem (s);
2271 standardFlagsDefault->setEnabled (true);
2273 if ( bo->getURL().isEmpty() )
2274 actionEditOpenURL->setEnabled (false);
2276 actionEditOpenURL->setEnabled (true);
2277 actionEditURL->setEnabled (true);
2278 actionEditHeading2URL->setEnabled (true);
2279 actionEditBugzilla2URL->setEnabled (true);
2281 if ( bo->getVymLink().isEmpty() )
2283 actionEditOpenVymLink->setEnabled (false);
2284 actionEditDeleteVymLink->setEnabled (false);
2287 actionEditOpenVymLink->setEnabled (true);
2288 actionEditDeleteVymLink->setEnabled (true);
2290 actionEditVymLink->setEnabled (true);
2292 actionEditCopy->setEnabled (true);
2293 actionEditCut->setEnabled (true);
2294 actionEditPaste->setEnabled (true);
2295 actionEditMoveUp->setEnabled (true);
2296 actionEditMoveDown->setEnabled (true);
2297 actionEditToggleScroll->setEnabled (true);
2298 actionEditHeading->setEnabled (true);
2299 actionEditDelete->setEnabled (true);
2300 actionEditAddBranch->setEnabled (true);
2301 actionEditAddBranchAbove->setEnabled (true);
2302 actionEditAddBranchBelow->setEnabled (true);
2303 actionEditImportAdd->setEnabled (true);
2304 actionEditImportReplace->setEnabled (true);
2305 actionEditSaveBranch->setEnabled (true);
2306 actionEditSelectFirst->setEnabled (true);
2307 actionEditSelectLast->setEnabled (true);
2308 actionEditToggleFloatExport->setEnabled (false);
2309 actionFormatPickColor->setEnabled (true);
2310 actionFormatColorBranch->setEnabled (true);
2311 actionFormatColorSubtree->setEnabled (true);
2312 switch (selection->getFrameType())
2315 actionFormatFrameNone->setOn(true);
2318 actionFormatFrameRectangle->setOn(true);
2324 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2326 standardFlagsDefault->setEnabled (false);
2328 actionEditOpenURL->setEnabled (false);
2329 actionEditURL->setEnabled (false);
2330 actionEditHeading2URL->setEnabled (false);
2331 actionEditBugzilla2URL->setEnabled (false);
2332 actionEditOpenVymLink->setEnabled (false);
2333 actionEditVymLink->setEnabled (false);
2334 actionEditDeleteVymLink->setEnabled (false);
2336 actionEditCopy->setEnabled (true);
2337 actionEditCut->setEnabled (true);
2338 actionEditPaste->setEnabled (false); //FIXME
2339 actionEditMoveUp->setEnabled (false);
2340 actionEditMoveDown->setEnabled (false);
2341 actionEditToggleScroll->setEnabled (false);
2342 actionEditHeading->setEnabled (false);
2343 actionEditDelete->setEnabled (true);
2344 actionEditAddBranch->setEnabled (false);
2345 actionEditAddBranchAbove->setEnabled (false);
2346 actionEditAddBranchBelow->setEnabled (false);
2347 actionEditImportAdd->setEnabled (false);
2348 actionEditSaveBranch->setEnabled (false);
2349 actionEditImportReplace->setEnabled (false);
2350 actionEditSelectFirst->setEnabled (false);
2351 actionEditSelectLast->setEnabled (false);
2352 actionEditToggleFloatExport->setOn
2353 ( ((FloatImageObj*)(selection))->getFloatExport() );
2354 actionFormatPickColor->setEnabled (false);
2355 actionFormatColorBranch->setEnabled (false);
2356 actionFormatColorSubtree->setEnabled (false);
2361 standardFlagsDefault->setEnabled (false);
2363 actionEditCopy->setEnabled (false);
2364 actionEditCut->setEnabled (false);
2365 actionEditPaste->setEnabled (false);
2366 actionEditMoveUp->setEnabled (false);
2367 actionEditMoveDown->setEnabled (false);
2368 actionEditToggleScroll->setEnabled (false);
2369 actionEditOpenURL->setEnabled (false);
2370 actionEditURL->setEnabled (false);
2371 actionEditOpenVymLink->setEnabled (false);
2372 actionEditVymLink->setEnabled (false);
2373 actionEditDeleteVymLink->setEnabled (false);
2374 actionEditHeading2URL->setEnabled (false);
2375 actionEditBugzilla2URL->setEnabled (false);
2376 actionEditHeading->setEnabled (false);
2377 actionEditDelete->setEnabled (false);
2378 actionEditAddBranch->setEnabled (false);
2379 actionEditAddBranchAbove->setEnabled (false);
2380 actionEditAddBranchBelow->setEnabled (false);
2381 actionEditSaveBranch->setEnabled (false);
2382 actionEditImportReplace->setEnabled (false);
2383 actionEditSelectFirst->setEnabled (false);
2384 actionEditSelectLast->setEnabled (false);
2385 actionEditToggleFloatExport->setEnabled (false);
2386 actionFormatPickColor->setEnabled (false);
2387 actionFormatColorBranch->setEnabled (false);
2388 actionFormatColorSubtree->setEnabled (false);
2392 void MapEditor::setLinkStyle (LinkStyle ls)
2397 bo=mapCenter->first();
2401 bo->setLinkStyle(bo->getDefLinkStyle());
2408 LinkStyle MapEditor::getLinkStyle ()
2413 void MapEditor::setLinkColor(QColor c)
2419 void MapEditor::setLinkColorHint()
2421 // called from setLinkColorHint(lch) or at end of parse
2423 bo=mapCenter->first();
2431 void MapEditor::setLinkColorHint(LinkColorHint lch)
2437 void MapEditor::toggleLinkColorHint()
2439 if (linkcolorhint==HeadingColor)
2440 linkcolorhint=DefaultColor;
2442 linkcolorhint=HeadingColor;
2444 bo=mapCenter->first();
2452 LinkColorHint MapEditor::getLinkColorHint()
2454 return linkcolorhint;
2457 QColor MapEditor::getDefLinkColor()
2459 return deflinkcolor;
2462 void MapEditor::selectLinkColor()
2464 // Finish open lineEdits
2465 if (lineedit) finishedLineEditNoSave();
2467 QColor col = QColorDialog::getColor( deflinkcolor, this );
2468 if ( !col.isValid() ) return;
2469 setLinkColor( col );
2473 void MapEditor::toggleScroll()
2475 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2477 BranchObj *bo=((BranchObj*)(selection));
2478 if (bo->countBranches()==0) return;
2479 if (bo->getDepth()==0) return;
2481 saveState(PartOfMap,selection);
2488 void MapEditor::unScrollAll()
2491 bo=mapCenter->first();
2494 if (bo->isScrolled()) bo->toggleScroll();
2499 void MapEditor::loadFloatImage ()
2502 (typeid(*selection) == typeid(BranchObj)) ||
2503 (typeid(*selection) == typeid(MapCenterObj)) )
2505 BranchObj *bo=((BranchObj*)(selection));
2507 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2508 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2509 ImagePreview *p =new ImagePreview (fd);
2510 fd->setContentsPreviewEnabled( TRUE );
2511 fd->setContentsPreview( p, p );
2512 fd->setPreviewMode( QFileDialog::Contents );
2513 fd->setCaption(tr("vym - Load image"));
2514 fd->setDir (lastImageDir);
2518 if ( fd->exec() == QDialog::Accepted )
2521 saveState(PartOfMap,selection);
2522 QString fn=fd->selectedFile();
2523 lastImageDir=fn.left(fn.findRev ("/"));
2524 bo->addFloatImage();
2525 // FIXME check if load was successful
2526 bo->getLastFloatImage()->load(fn);
2527 bo->getLastFloatImage()->setOriginalFilename(fn);
2528 mapCenter->reposition();
2535 void MapEditor::saveFloatImage (int item)
2538 (typeid(*selection) == typeid(FloatImageObj)) )
2540 FloatImageObj *fio=((FloatImageObj*)(selection));
2541 const char* fmt = saveImageFormatMenu->text(item);
2543 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2544 fd->addFilter ("PNG (*.png)");
2545 fd->addFilter ("BMP (*.bmp)");
2546 fd->addFilter ("XBM (*.xbm)");
2547 fd->addFilter ("JPG (*.jpg)");
2548 fd->addFilter ("XPM (*.xpm)");
2549 fd->addFilter ("GIF (*.gif)");
2550 fd->addFilter ("PNM (*.pnm)");
2551 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2552 fd->setCaption(tr("vym - Save image as ") + fmt);
2553 fd->setMode( QFileDialog::AnyFile );
2554 fd->setSelection (fio->getOriginalFilename());
2558 if ( fd->exec() == QDialog::Accepted )
2560 if (QFile (fd->selectedFile()).exists() )
2562 QMessageBox mb( "VYM",
2563 tr("The file ") + fd->selectedFile() +
2564 tr(" exists already. "
2565 "Do you want to overwrite it?"),
2566 QMessageBox::Warning,
2567 QMessageBox::Yes | QMessageBox::Default,
2568 QMessageBox::Cancel | QMessageBox::Escape,
2569 QMessageBox::QMessageBox::NoButton );
2571 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2572 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2575 case QMessageBox::Yes:
2578 case QMessageBox::Cancel:
2584 fio->save (fd->selectedFile(),fmt);
2589 void MapEditor::toggleFloatExport()
2592 (typeid(*selection) == typeid(FloatImageObj))||
2593 (typeid(*selection) == typeid(FloatObj)) )
2595 FloatImageObj *fio=((FloatImageObj*)(selection));
2596 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2600 void MapEditor::setFrame(const FrameType &t)
2603 (typeid(*selection) == typeid(BranchObj)) ||
2604 (typeid(*selection) == typeid(MapCenterObj)) )
2606 selection->setFrameType (t);
2607 mapCenter->reposition();
2608 selection->updateLink();
2612 void MapEditor::importDir(BranchObj *dst, QDir d)
2615 (typeid(*selection) == typeid(BranchObj)) ||
2616 (typeid(*selection) == typeid(MapCenterObj)) )
2620 // Traverse directories
2621 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2622 const QFileInfoList *dirlist = d.entryInfoList();
2623 QFileInfoListIterator itdir( *dirlist );
2626 while ( (fi = itdir.current()) != 0 )
2628 if (fi->fileName() != "." && fi->fileName() != ".." )
2631 bo=dst->getLastBranch();
2632 bo->setHeading (fi->fileName() );
2633 bo->setColor (QColor("blue"),false);
2635 if ( !d.cd(fi->fileName()) )
2636 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2646 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2647 const QFileInfoList *filelist = d.entryInfoList();
2648 QFileInfoListIterator itfile( *filelist );
2650 while ( (fi = itfile.current()) != 0 )
2653 bo=dst->getLastBranch();
2654 bo->setHeading (fi->fileName() );
2655 bo->setColor (QColor("black"),false);
2661 void MapEditor::importDir()
2664 (typeid(*selection) == typeid(BranchObj)) ||
2665 (typeid(*selection) == typeid(MapCenterObj)) )
2667 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2668 fd->setMode (QFileDialog::DirectoryOnly);
2669 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2670 fd->setCaption(tr("VYM - Choose directory structur to import"));
2674 if ( fd->exec() == QDialog::Accepted )
2676 BranchObj *bo=((BranchObj*)(selection));
2677 importDir (bo,QDir(fd->selectedFile()) );
2678 mapCenter->reposition();
2685 void MapEditor::followLink(int i)
2687 BranchObj *bo=((BranchObj*)(selection))->linkTargetAt(i);
2690 selection->unselect();
2692 selection->select();
2693 ensureSelectionVisible();
2697 void MapEditor::editLink(int i)
2699 BranchObj *bo=((BranchObj*)(selection))->linkTargetAt(i);
2703 if (dia.exec() == QDialog::Accepted)
2705 if (dia.deleteLink())
2706 ((BranchObj*)(selection))->deleteLinkAt(i);
2712 void MapEditor::testFunction()
2714 cout << "MapEditor::testFunction() called\n";
2716 (typeid(*selection) == typeid(BranchObj) ||
2717 typeid(*selection) == typeid(MapCenterObj) ) )
2719 BranchObj *bo=(BranchObj*)(selection);
2720 QPoint p = worldMatrix().map(QPoint (bo->x(),bo->y()));
2721 // lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
2722 QPopupMenu *popupLinks=new QPopupMenu (this);
2723 if (bo->countLinks()==0)
2725 popupLinks->clear();
2726 popupLinks->insertItem ("No link available");
2732 popupLinks->clear();
2733 for (int i=0; i<=bo->countLinks();i++)
2735 bot=bo->linkTargetAt(i);
2738 s=bot->getHeading();
2741 popupLinks->insertItem (s);
2745 popupLinks->move(p);
2751 void MapEditor::ensureSelectionVisible()
2753 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2755 if (selection->getOrientation() == OrientLeftOfCenter)
2756 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2758 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2759 ensureVisible (p.x(), p.y() );
2763 void MapEditor::updateViewCenter()
2765 // Update movingCenter, so that we can zoom comfortably later
2766 QRect rc = QRect( contentsX(), contentsY(),
2767 visibleWidth(), visibleHeight() );
2768 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2769 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2770 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2773 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2775 // Lineedits are already closed by preceding
2776 // mouseEvent, we don't need to close here.
2778 QPoint p = inverseWorldMatrix().map(e->pos());
2779 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2782 { // MapObj was found
2783 if (selection != lmo)
2785 // select the MapObj
2786 if (selection) selection->unselect();
2788 selection->select();
2794 if (typeid(*selection)==typeid(BranchObj) ||
2795 typeid(*selection)==typeid(MapCenterObj) )
2797 // Context Menu on branch or mapcenter
2799 branchContextMenu->popup(e->globalPos() );
2801 if (typeid(*selection)==typeid(FloatImageObj))
2803 // Context Menu on floatimage
2805 floatimageContextMenu->popup(e->globalPos() );
2809 { // No MapObj found, we are on the Canvas itself
2810 // Context Menu on Canvas
2812 canvasContextMenu->popup(e->globalPos() );
2816 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2818 // Finish open lineEdits
2819 if (lineedit) finishedLineEditNoSave();
2821 QPoint p = inverseWorldMatrix().map(e->pos());
2822 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2824 // Special case: CTRL is pressed
2825 if (e->state() & QMouseEvent::ControlButton)
2827 if (actionModModeColor->isOn())
2829 if (e->state() & QMouseEvent::ControlButton)
2832 setCursor (pickColorCursor);
2836 if (actionModModeLink->isOn())
2838 BranchObj *bo_begin=NULL;
2840 bo_begin=(BranchObj*)(lmo);
2843 ((typeid(*selection) == typeid(BranchObj)) ||
2844 (typeid(*selection) == typeid(MapCenterObj))) )
2845 bo_begin=(BranchObj*)(selection);
2849 linkingObj_src=bo_begin;
2850 tmpLink=new LinkObj (mapCanvas);
2851 tmpLink->setBegin (bo_begin);
2852 tmpLink->setEnd (p);
2853 tmpLink->updateLink();
2854 tmpLink->setVisibility (true);
2861 { // MapObj was found
2862 if (selection != lmo)
2864 // select the MapObj
2865 if (selection) selection->unselect();
2867 selection->select();
2873 // Check, if systemFlag clicked
2874 if (typeid(*selection)==typeid(BranchObj) ||
2875 typeid(*selection)==typeid(MapCenterObj) )
2877 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
2878 if (!foname.isEmpty())
2880 // Do not move, if systemFlag clicked
2884 if (foname=="vymLink")
2886 mainWindow->editOpenVymLink();
2887 // tabWidget may change, better return now
2888 // before segfaulting...
2892 mainWindow->windowToggleNoteEditor();
2896 // Left Button Move Branches
2897 if (e->button() == QMouseEvent::LeftButton )
2899 // If modMode==copy, then we want to "move" the _new_ object around
2900 // then we need the offset from p to the _old_ selection, because of tmp
2901 if (actionModModeCopy->isOn() &&
2902 e->state() & QMouseEvent::ControlButton)
2904 if (typeid(*selection)==typeid(BranchObj) )
2907 movingObj_start.setX( p.x() - selection->x() );
2908 movingObj_start.setY( p.y() - selection->y() );
2909 mapCenter->addBranch ((BranchObj*)(selection));
2911 selection=mapCenter->getLastBranch();
2912 selection->select();
2913 selection->setParObjTmp ((BranchObj*)(selection),p,1);
2914 selection->updateLink();
2918 movingObj_start.setX( p.x() - selection->x() );
2919 movingObj_start.setY( p.y() - selection->y() );
2922 movingObj=selection;
2924 // Middle Button Toggle Scroll
2925 // (On Mac OS X this won't work, but we still have
2926 // a button in the toolbar)
2927 if (e->button() == QMouseEvent::MidButton )
2931 { // No MapObj found, we are on the Canvas itself
2932 // Left Button move Pos of CanvasView
2933 if (e->button() == QMouseEvent::LeftButton )
2935 movingObj=NULL; // move Content not Obj
2936 movingObj_start=e->globalPos();
2937 movingCont_start=QPoint (contentsX(), contentsY() );
2938 movingVec=QPoint(0,0);
2939 setCursor(handOpenCursor);
2944 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
2946 QPoint p = inverseWorldMatrix().map(e->pos());
2948 // Move the selected MapObj
2949 if ( selection && movingObj)
2951 ensureVisible (p.x(),p.y());
2953 // Now move the selection, but add relative position
2954 // (movingObj_start) where selection was chosen with
2955 // mousepointer. (This avoids flickering resp. jumping
2956 // of selection back to absPos)
2958 LinkableMapObj *lmosel;
2959 lmosel = dynamic_cast <LinkableMapObj*> (selection);
2961 // Check if we could link
2962 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
2965 if (typeid(*selection) == typeid(FloatImageObj))
2969 FloatObj *fo=(FloatObj*)(selection);
2970 if (fo->getLinkStyle()==StyleUndef)
2972 fo->setLinkStyle(fo->getDefLinkStyle());
2973 fo->setLinkColor(fo->getParObj()->getLinkColor());
2975 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2979 // Relink float to new mapcenter or branch, if shift is pressed
2980 // Only relink, if selection really has a new parent
2981 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
2982 ( (typeid(*lmo)==typeid(BranchObj)) ||
2983 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
2984 ( lmo != fo->getParObj())
2987 if (typeid(*fo) == typeid(FloatImageObj))
2989 FloatImageObj *fio=(FloatImageObj*)(fo);
2990 ((BranchObj*)(lmo))->addFloatImage (fio);
2992 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2993 fio=((BranchObj*)(lmo))->getLastFloatImage();
2996 selection=(LinkableMapObj*)(fio);
2997 selection->select();
2998 movingObj=(MapObj*)(fio);
2999 // setLinkStyle calls updateLink, only set it once
3000 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3001 fio->setLinkStyle (fio->getDefLinkStyle());
3004 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3006 } else // selection != a FloatObj
3008 if (lmosel->getDepth()==0)
3010 if (e->state() == (LeftButton | !ShiftButton))
3011 // If mapCenter is moved, move all the rest by default, too.
3012 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3014 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3017 if (lmosel->getDepth()==1)
3019 // depth==1, mainbranch
3021 saveState(PartOfMap,lmosel);
3022 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3026 if (lmosel->getOrientation() == OrientLeftOfCenter)
3027 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3028 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3029 p.y()-movingObj_start.y() );
3031 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3033 // reposition subbranch
3034 lmosel->reposition();
3035 //ensureSelectionVisible();
3037 if (lmo && (lmo!=selection) &&
3038 (typeid(*lmo) == typeid(BranchObj) ||
3039 (typeid(*lmo) == typeid(MapCenterObj) )
3042 if (e->state() & QMouseEvent::ControlButton)
3044 // Special case: CTRL to link below lmo
3045 lmosel->setParObjTmp (lmo,p,+1);
3047 else if (e->state() & QMouseEvent::ShiftButton)
3048 lmosel->setParObjTmp (lmo,p,-1);
3050 lmosel->setParObjTmp (lmo,p,0);
3053 lmosel->unsetParObjTmp();
3055 if (lmo &&(lmo==selection))
3056 // Could link to myself (happens sometimes...)
3057 lmosel->unsetParObjTmp();
3059 // no Obj under selection, go back to original Parent
3060 lmosel->unsetParObjTmp();
3065 } // no FloatImageObj
3069 } // selection && moving_obj
3071 // Draw a link from one branch to another
3074 tmpLink->setEnd (p);
3075 tmpLink->updateLink();
3079 if (!movingObj && !pickingColor &&!drawingLink)
3081 QPoint p=e->globalPos();
3082 movingVec.setX(-p.x() + movingObj_start.x() );
3083 movingVec.setY(-p.y() + movingObj_start.y() );
3084 setContentsPos( movingCont_start.x() + movingVec.x(),
3085 movingCont_start.y() + movingVec.y());
3092 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3094 LinkableMapObj *dst;
3095 // Have we been picking color?
3099 setCursor (ArrowCursor);
3100 // Check if we are over another branch
3101 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3102 if (dst && selection)
3104 if (e->state() & QMouseEvent::ShiftButton)
3106 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3107 ((BranchObj*)(selection))->setLinkColor ();
3111 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3112 ((BranchObj*)(selection))->setLinkColor ();
3118 // Have we been drawing a link?
3122 // Check if we are over another branch
3123 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3124 if (dst && selection)
3126 tmpLink->setEnd ( ((BranchObj*)(dst)) );
3127 tmpLink->updateLink();
3128 tmpLink->activate();
3139 // Have we been moving something?
3140 if ( selection && movingObj )
3142 // Check if we are over another branch, but ignore
3143 // any found LMOs, which are FloatObjs
3144 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3145 ((LinkableMapObj*)(selection)) );
3148 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3153 // Now check, if we have been moving a branch
3154 if (typeid(*selection) == typeid(BranchObj) )
3156 // save the position in case we link to mapcenter
3157 QPoint savePos=QPoint (selection->x(),selection->y() );
3159 // Reset the temporary drawn link to the original one
3160 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3168 // remove the current selection, if we have no destination
3169 selection->unselect();
3170 ((BranchObj*)(selection->getParObj()))->removeBranch ((BranchObj*)(selection));
3173 selection=selectionLast;
3175 selection->select();
3182 // TODO we also could check, if dest and src are on same branch,
3183 // then it would be sufficient to saveState of this branch
3185 // Modifiers allow to insert above/below dst
3186 if (e->state() & QMouseEvent::ShiftButton)
3188 ((BranchObj*)(selection))->moveBranchTo
3191 ((BranchObj*)(dst))->getNum()
3193 //if (selection) selection->select();
3195 if (e->state() & QMouseEvent::ControlButton)
3197 ((BranchObj*)(selection))->moveBranchTo
3200 ((BranchObj*)(dst))->getNum()+1
3202 //if (selection) selection->select();
3205 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
3206 if (dst->getDepth()==0)
3207 ((BranchObj*)(selection))->move (savePos);
3210 // Draw the original link, before selection was moved around
3211 mapCenter->reposition();
3213 // Finally resize canvas, if needed
3218 // maybe we moved View: set old cursor
3219 setCursor (ArrowCursor);
3223 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3225 // Finish open lineEdits
3226 if (lineedit) finishedLineEditNoSave();
3228 if (e->button() == QMouseEvent::LeftButton )
3230 QPoint p = inverseWorldMatrix().map(e->pos());
3231 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3232 if (lmo) { // MapObj was found
3233 // First select the MapObj than edit heading
3234 if (selection) selection->unselect();
3236 selection->select();
3238 saveState(PartOfMap,selection);
3244 void MapEditor::resizeEvent (QResizeEvent* e)
3246 QCanvasView::resizeEvent( e );
3249 if (!fileName.isEmpty()) s=fileName;