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>
27 #include "texteditor.h"
28 #include "linkablemapobj.h"
31 #include "mainwindow.h"
32 #include "extrainfodialog.h"
33 #include "editxlinkdialog.h"
36 #include "icons/flag-note.xpm"
37 #include "icons/flag-url.xpm"
38 #include "icons/flag-vymlink.xpm"
39 #include "icons/flag-scrolled-right.xpm"
40 #include "icons/flag-tmpUnscrolled-right.xpm"
41 #include "icons/flag-questionmark.xpm"
42 #include "icons/flag-exclamationmark.xpm"
43 #include "icons/flag-hook-green.xpm"
44 #include "icons/flag-cross-red.xpm"
45 #include "icons/flag-stopsign.xpm"
46 #include "icons/flag-smiley-good.xpm"
47 #include "icons/flag-smiley-sad.xpm"
48 #include "icons/flag-clock.xpm"
49 #include "icons/flag-lamp.xpm"
50 #include "icons/flag-arrow-up.xpm"
51 #include "icons/flag-arrow-down.xpm"
52 #include "icons/flag-thumb-up.xpm"
53 #include "icons/flag-thumb-down.xpm"
54 #include "icons/flag-heart.xpm"
55 #include "icons/flag-flash.xpm"
56 #include "icons/flag-lifebelt.xpm"
58 extern TextEditor *textEditor;
59 extern int statusbarTime;
60 extern Main *mainWindow;
61 extern FlagRowObj *systemFlagsDefault;
62 extern FlagRowObj *standardFlagsDefault;
63 extern MapEditor *clipboardME;
65 extern QPtrList <QAction> actionListBranches;
67 extern QAction *actionFileSave;
68 extern QAction *actionEditUndo;
69 extern QAction *actionEditCopy;
70 extern QAction *actionEditCut;
71 extern QAction *actionEditPaste;
72 extern QAction *actionEditMoveUp;
73 extern QAction *actionEditMoveDown;
74 extern QAction *actionEditToggleScroll;
75 extern QAction *actionEditOpenURL;
76 extern QAction *actionEditURL;
77 extern QAction *actionEditHeading2URL;
78 extern QAction *actionEditBugzilla2URL;
79 extern QAction *actionEditOpenVymLink;
80 extern QAction *actionEditVymLink;
81 extern QAction *actionEditDeleteVymLink;
82 extern QAction *actionEditHeading;
83 extern QAction *actionEditDelete;
84 extern QAction *actionEditAddBranch;
85 extern QAction *actionEditAddBranchAbove;
86 extern QAction *actionEditAddBranchBelow;
87 extern QAction *actionEditRemoveBranchHere;
88 extern QAction *actionEditRemoveChilds;
89 extern QAction *actionEditImportAdd;
90 extern QAction *actionEditImportReplace;
91 extern QAction *actionEditSaveBranch;
92 extern QAction *actionEditSelectFirst;
93 extern QAction *actionEditSelectLast;
94 extern QAction *actionEditLoadImage;
95 extern QAction *actionEditToggleFloatExport;
97 extern QAction* actionFormatPickColor;
98 extern QAction* actionFormatColorBranch;
99 extern QAction* actionFormatColorSubtree;
100 extern QAction *actionFormatLinkColorHint;
101 extern QAction *actionFormatBackColor;
102 extern QAction *actionFormatLinkColor;
104 extern QActionGroup* actionGroupModModes;
105 extern QAction* actionModModeColor;
106 extern QAction* actionModModeLink;
107 extern QAction* actionModModeCopy;
109 extern QActionGroup *actionGroupFormatFrameTypes;
110 extern QAction *actionFormatFrameNone;
111 extern QAction *actionFormatFrameRectangle;
113 extern QActionGroup *actionGroupFormatLinkStyles;
114 extern QAction *actionFormatLinkStyleLine;
115 extern QAction *actionFormatLinkStyleParabel;
116 extern QAction *actionFormatLinkStylePolyLine;
117 extern QAction *actionFormatLinkStylePolyParabel;
119 extern QAction *actionViewToggleNoteEditor;
121 extern QAction *actionSettingsAutoedit;
122 extern QAction *actionSettingsAutoselectHeading;
123 extern QAction *actionSettingsAutoselectText;
124 extern QAction *actionSettingsPasteNewHeading;
125 extern QAction *actionSettingsUseFlagGroups;
127 extern QPopupMenu *branchContextMenu;
128 extern QPopupMenu *branchLinksContextMenu;
129 extern QPopupMenu *branchLinksContextMenuDup;
130 extern QPopupMenu *floatimageContextMenu;
131 extern QPopupMenu *saveImageFormatMenu;
132 extern QPopupMenu *exportImageFormatMenu;
133 extern QPopupMenu *canvasContextMenu;
135 extern Settings settings;
138 ///////////////////////////////////////////////////////////////////////
139 ///////////////////////////////////////////////////////////////////////
140 MapEditor::MapEditor(
141 QWidget* parent, bool interactive, const char* name, WFlags f) :
142 QCanvasView(parent,name,f)
144 //cout << "Constructor ME "<<this<<endl;
146 mapCanvas = new QCanvas(1000,800);
147 mapCanvas->setAdvancePeriod(30);
149 setCanvas (mapCanvas);
151 setVScrollBarMode ( QScrollView::AlwaysOn );
152 setHScrollBarMode ( QScrollView::AlwaysOn );
154 // Now create the _global_ system flags _once_:
155 // (Later all OrnamentedObj copy from this
156 // and set their own canvas)
157 if (!systemFlagsDefault)
159 systemFlagsDefault = new FlagRowObj (mapCanvas);
160 systemFlagsDefault->setVisibility (false);
161 systemFlagsDefault->setName ("systemFlagsDef");
163 FlagObj *fo = new FlagObj (mapCanvas);
164 fo->load(QPixmap(flag_note_xpm));
166 fo->setToolTip(tr("Note","Systemflag"));
167 systemFlagsDefault->addFlag (fo); // makes deep copy
169 fo->load(QPixmap(flag_url_xpm));
171 fo->setToolTip(tr("WWW Document (external)","Systemflag"));
172 systemFlagsDefault->addFlag (fo);
174 fo->load(QPixmap(flag_vymlink_xpm));
175 fo->setName("vymLink");
176 fo->setToolTip(tr("Link to another vym map","Systemflag"));
177 systemFlagsDefault->addFlag (fo);
179 fo->load(QPixmap(flag_scrolled_right_xpm));
180 fo->setName("scrolledright");
181 fo->setToolTip(tr("subtree is scrolled","Systemflag"));
182 systemFlagsDefault->addFlag (fo);
184 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
185 fo->setName("tmpUnscrolledright");
186 fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
187 systemFlagsDefault->addFlag (fo);
190 if (!standardFlagsDefault)
192 standardFlagsDefault = new FlagRowObj (mapCanvas);
193 standardFlagsDefault->setVisibility (false);
194 standardFlagsDefault->setName ("standardFlagsDef");
196 FlagObj *fo = new FlagObj (mapCanvas);
197 fo->load(QPixmap(flag_exclamationmark_xpm));
198 fo->setName ("exclamationmark");
199 fo->setGroup("standard-mark");
200 fo->setToolTip(tr("Take care!","Standardflag"));
201 standardFlagsDefault->addFlag (fo); // makes deep copy
203 fo->load(QPixmap(flag_questionmark_xpm));
204 fo->setName("questionmark");
205 fo->setGroup("standard-mark");
206 fo->setToolTip(tr("Really?","Standardflag"));
207 standardFlagsDefault->addFlag (fo);
209 fo->load(QPixmap(flag_hook_green_xpm));
210 fo->setName("hook-green");
211 fo->setGroup("standard-hook");
212 fo->setToolTip(tr("ok!","Standardflag"));
213 standardFlagsDefault->addFlag (fo);
215 fo->load(QPixmap(flag_cross_red_xpm));
216 fo->setName("cross-red");
217 fo->setGroup("standard-hook");
218 fo->setToolTip(tr("Not ok!","Standardflag"));
219 standardFlagsDefault->addFlag (fo);
221 fo->load(QPixmap(flag_stopsign_xpm));
222 fo->setName("stopsign");
223 fo->setToolTip(tr("This won't work!","Standardflag"));
224 standardFlagsDefault->addFlag (fo);
226 fo->load(QPixmap(flag_smiley_good_xpm));
227 fo->setName("smiley-good");
228 fo->setGroup("standard-smiley");
229 fo->setToolTip(tr("Good","Standardflag"));
230 standardFlagsDefault->addFlag (fo);
232 fo->load(QPixmap(flag_smiley_sad_xpm));
233 fo->setName("smiley-sad");
234 fo->setGroup("standard-smiley");
235 fo->setToolTip(tr("Bad","Standardflag"));
236 standardFlagsDefault->addFlag (fo);
238 fo->load(QPixmap(flag_clock_xpm));
239 fo->setName("clock");
240 fo->setToolTip(tr("Time critical","Standardflag"));
241 standardFlagsDefault->addFlag (fo);
243 fo->load(QPixmap(flag_lamp_xpm));
245 fo->setToolTip(tr("Idea!","Standardflag"));
246 standardFlagsDefault->addFlag (fo);
248 fo->load(QPixmap(flag_arrow_up_xpm));
249 fo->setName("arrow-up");
250 fo->setGroup("standard-arrow");
251 fo->setToolTip(tr("Important","Standardflag"));
252 standardFlagsDefault->addFlag (fo);
254 fo->load(QPixmap(flag_arrow_down_xpm));
255 fo->setName("arrow-down");
256 fo->setGroup("standard-arrow");
257 fo->setToolTip(tr("Unimportant","Standardflag"));
258 standardFlagsDefault->addFlag (fo);
260 fo->load(QPixmap(flag_thumb_up_xpm));
261 fo->setName("thumb-up");
262 fo->setGroup("standard-thumb");
263 fo->setToolTip(tr("I like this","Standardflag"));
264 standardFlagsDefault->addFlag (fo);
266 fo->load(QPixmap(flag_thumb_down_xpm));
267 fo->setName("thumb-down");
268 fo->setGroup("standard-thumb");
269 fo->setToolTip(tr("I like this","Standardflag"));
270 fo->setToolTip(tr("I do not like this","Standardflag"));
271 standardFlagsDefault->addFlag (fo);
273 fo->load(QPixmap(flag_heart_xpm));
274 fo->setName("heart");
275 fo->setToolTip(tr("I just love... ","Standardflag"));
276 standardFlagsDefault->addFlag (fo);
278 fo->load(QPixmap(flag_flash_xpm));
279 fo->setName("flash");
280 fo->setToolTip(tr("Dangerous","Standardflag"));
281 standardFlagsDefault->addFlag (fo);
283 fo->load(QPixmap(flag_lifebelt_xpm));
284 fo->setName("lifebelt");
285 fo->setToolTip(tr("This will help","Standardflag"));
286 standardFlagsDefault->addFlag (fo);
291 mapCenter = new MapCenterObj(mapCanvas);
292 mapCenter->setVisibility (true);
293 mapCenter->setMapEditor (this);
294 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
298 lineedit = new QLineEdit(this, "lineedit" );
299 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
302 actColor=black; setColor (actColor);
303 defLinkColor=QColor (0,0,255);
304 defXLinkColor=QColor (180,180,180);
305 linkcolorhint=DefaultColor;
306 linkstyle=StylePolyParabel;
307 mapCanvas->setBackgroundColor (white);
309 // Create bitmap cursors, patform dependant
310 #if defined(Q_OS_MACX)
311 #include "icons/cursorhandopen16.xpm"
312 #include "icons/cursorcolorpicker16.xpm"
313 QBitmap cb( 16, 16, chandopen, TRUE );
314 QBitmap cm( 16, 16, chandopenmask, TRUE );
315 handOpenCursor=QCursor ( cb, cm );
316 // set hot spot to tip of picker
317 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
319 #include "icons/cursorhandopen.xpm"
320 #include "icons/cursorcolorpicker.xpm"
322 QBitmap cb( 32, 32, chandopen, TRUE );
323 QBitmap cm( 32, 32, chandopenmask, TRUE );
324 handOpenCursor=QCursor ( cb, cm );
325 // set hot spot to tip of picker
326 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
339 defXLinkColor=QColor (230,230,230);
350 // Initialize find routine
357 blockreposition=false;
358 isInteractive=interactive;
360 // Create temporary files
363 // Initially set movingCentre
366 mapCenter->reposition(); // for positioning heading
369 MapEditor::~MapEditor()
371 //cout <<"Destructor MapEditor\n";
372 if (isInteractive) delTmpDirs();
375 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
379 QColor MapEditor::color()
384 QColor MapEditor::backgroundColor()
386 return mapCanvas->backgroundColor();
389 MapCenterObj* MapEditor::getMapCenter()
394 QCanvas* MapEditor::getCanvas()
399 void MapEditor::adjustCanvasSize()
401 // To adjust the canvas to map, viewport size and position, we have to
402 // do some coordinate magic...
404 // Get rectangle of (scroll-)view.
405 // We want to be in canvas coords, so
406 // we map. Important if view is zoomed...
407 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
408 visibleWidth(), visibleHeight()) );
410 // Now we need the bounding box of view AND map to calc the correct canvas size.
411 // Why? Because if the map itself is moved out of view, the view has to be enlarged
412 // to avoid jumping aroung...
413 QRect map=mapCenter->getTotalBBox();
415 // right edge - left edge
416 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
417 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
420 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
421 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
424 // move the map on canvas (in order to not move it on screen) this is neccessary
425 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
426 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
427 // to scroll to an empty area of canvas to the left.
428 // b) if topleft corner of map left of or above topleft of canvas
432 if (cw > mapCanvas->width() )
434 if (map.x()<0) dx=-map.x();
436 if (cw < mapCanvas->width() )
437 dx=-min (view.x(),map.x());
438 if (ch > mapCanvas->height() )
440 if (map.y()<0) dy=-map.y();
442 if (ch < mapCanvas->height() )
444 dy=-min (view.y(),map.y());
446 // We really have to resize now. Let's go...
447 mapCanvas->resize (cw,ch);
448 if ( (dx!=0) || (dy!=0) )
450 mapCenter->moveAllBy(dx,dy);
451 mapCenter->reposition();
453 // scroll the view (in order to not move map on screen)
459 bool MapEditor::blockReposition()
461 return blockreposition;
464 void MapEditor::makeTmpDirs()
466 // Create unique temporary directories
467 char tmpdir[]="/tmp/vym-XXXXXX";
468 bakMapDir=mkdtemp(tmpdir);
469 makeSubDirs(bakMapDir);
470 // FIXME set permissions and maybe use QT method for portability
473 void MapEditor::delTmpDirs()
475 //FIXME delete tmp directory, better use QT methods here:
476 system ( "rm -rf "+ bakMapDir );
480 void MapEditor::makeSubDirs(const QString &s)
488 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
490 // tmpdir temporary directory to which data will be writte
491 // prefix mapname, which will be appended to images etc.
492 // writeflags Only write flags for "real" save of map, not undo
493 // offset offset of bbox of whole map in canvas.
494 // Needed for XML export
495 // completeMap if false, only vympart will be written, without
512 ls="StylePolyParabel";
516 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
518 if (linkcolorhint==HeadingColor)
519 colhint=attribut("linkColorHint","HeadingColor");
521 QString mapAttr=attribut("version",__VYM_VERSION__);
523 mapAttr+= attribut("author",mapCenter->getAuthor()) +
524 attribut("comment",mapCenter->getComment()) +
525 attribut("date",mapCenter->getDate()) +
526 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
527 attribut("linkStyle", ls ) +
528 attribut("linkColor", defLinkColor.name() ) +
529 attribut("defXLinkColor", defXLinkColor.name() ) +
530 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
532 s+=beginElement("vymmap",mapAttr);
535 // Find the used flags while traversing the tree
536 standardFlagsDefault->resetUsedCounter();
538 // Build xml recursivly
540 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
543 if ( typeid(*saveSelection) == typeid(BranchObj) )
544 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
546 if (selection && typeid(*selection)==typeid(BranchObj))
547 // This is used if selected branch is saved from mainwindow
548 s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
551 // Save local settings
552 s+=settings.getXMLData (destPath);
555 if (selection && !saveSelection)
556 s+=valueElement("select",selection->getSelectString());
559 s+=endElement("vymmap");
562 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
566 void MapEditor::saveState()
568 saveState (CompleteMap,NULL,"");
571 void MapEditor::saveState(LinkableMapObj *undoSel)
573 saveState (PartOfMap,undoSel,"");
576 void MapEditor::saveState(const QString & c)
578 saveState (UndoCommand,NULL,c);
581 void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom)
583 if (savemode==UndoCommand)
588 else if (savemode==PartOfMap && undoSel)
590 undoCommand="undoPart (\""+undoSel->getSelectString()+"\")";
591 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
594 undoCommand="undoMap ()";
595 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
598 cout << "ME::saveState()\n";
599 cout << " undoCom="<<undoCommand<<endl;
603 void MapEditor::parseAtom(const QString &s)
607 api.parseCommand (s,c,p);
610 cout <<"ME::parseAtom s="<<s<<endl;
611 cout <<"ME::parseAtom c="<<c<<endl;
612 cout <<"ME::parseAtom p="<<p<<endl;
616 if (c==QString("moveBranchUp"))
618 else if (c=="moveBranchDown")
620 else if (c=="setHeading")
622 // Internal commands, used for undo etc.
623 else if (c==QString("undoMap"))
625 else if (c==QString("undoPart"))
627 else if (c=="select")
631 cout << "MapEditor::parseAtom: Error!\n";
632 cout << " Command unknown: \""<<c<<"\""<<endl;
633 cout << " Used in atom: \""<<s<<"\""<<endl;
638 void MapEditor::finishedLineEditNoSave()
640 // This is called by finishedLineEdit or any MapEditor method,
641 // which wants to assure, that lineedits finish, before e.g. a branch is
644 // After calling LineEdit and using the clipboard, the
645 // focus is not any longer on the main widget, we
646 // have to restore it using parentWidget()->setFocus()
650 editingBO->setHeading(lineedit->text() );
652 lineedit->releaseKeyboard();
654 parentWidget()->setFocus();
655 mapCenter->reposition();
657 ensureSelectionVisible();
662 bool MapEditor::isDefault()
667 bool MapEditor::isUnsaved()
672 bool MapEditor::hasChanged()
677 void MapEditor::setChanged()
682 actionEditUndo->setEnabled (true);
683 actionFileSave->setEnabled (true);
687 void MapEditor::closeMap()
689 // Finish open lineEdits
690 if (lineedit) finishedLineEditNoSave();
692 // Unselect before disabling the toolbar actions
693 if (selection) selection->unselect();
701 void MapEditor::setFilePath(QString fname)
703 setFilePath (fname,fname);
706 void MapEditor::setFilePath(QString fname, QString destname)
715 filePath=fname; // becomes absolute path
716 fileName=fname; // gets stripped of path
717 destPath=destname; // needed for vymlinks
719 // If fname is not an absolute path, complete it
720 filePath=QDir(fname).absPath();
721 fileDir=filePath.left (1+filePath.findRev ("/"));
723 // Set short name, too. Search from behind:
724 int i=fileName.findRev("/");
725 if (i>=0) fileName=fileName.remove (0,i+1);
727 // Forget the .vym (or .xml) for name of map
728 mapName=fileName.left(fileName.findRev(".",-1,true) );
732 QString MapEditor::getFilePath()
737 QString MapEditor::getFileName()
742 QString MapEditor::getMapName()
747 QString MapEditor::getDestPath()
752 int MapEditor::load (QString &fname, const LoadMode &lmode)
754 // Finish open lineEdits
755 if (lineedit) finishedLineEditNoSave();
761 if (selection) selection->unselect();
764 mapCenter->setMapEditor(this);
765 // (map state is set later at end of load...)
769 saveState(selection);
773 mapBuilderHandler handler;
776 // I am paranoid: file should exist anyway
777 // according to check in mainwindow.
780 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
781 tr("Couldn't open map " +fname)+".");
785 blockreposition=true;
786 QXmlInputSource source( file);
787 QXmlSimpleReader reader;
788 reader.setContentHandler( &handler );
789 reader.setErrorHandler( &handler );
790 handler.setMapEditor( this );
791 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
792 handler.setLoadMode (lmode);
793 bool ok = reader.parse( source );
794 blockreposition=false;
798 mapCenter->reposition();
808 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
809 tr( handler.errorProtocol() ) );
811 // Still return "success": the map maybe at least
812 // partially read by the parser
819 int MapEditor::save (const SaveMode &savemode)
821 // Finish open lineEdits
822 if (lineedit) finishedLineEditNoSave();
826 // The SaveMode UndoCommand is not supported here
827 if (savemode==UndoCommand) return 1;
829 // Create mapName and fileDir
830 makeSubDirs (fileDir);
834 fname=mapName+".xml";
836 // use name given by user, even if he chooses .doc
840 // Check if fname is writeable
841 QFile file( fileDir+fname);
842 if (!file.open( IO_WriteOnly ) )
844 QMessageBox::critical( 0, tr( "Critical Save Error" ),
845 tr("Couldn't write to ") +fileDir+fname);
851 if (savemode==CompleteMap || selection==NULL)
852 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
854 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
856 file.setName ( fileDir + fname);
857 if ( !file.open( IO_WriteOnly ) )
859 // This should neverever happen
860 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
864 // Write it finally, and write in UTF8, no matter what
865 QTextStream ts( &file );
866 ts.setEncoding (QTextStream::UnicodeUTF8);
874 actionFileSave->setEnabled(false);
880 void MapEditor::setZipped (bool z)
885 bool MapEditor::saveZipped ()
890 void MapEditor::print()
892 // Finish open lineEdits
893 if (lineedit) finishedLineEditNoSave();
897 printer = new QPrinter;
898 printer->setColorMode (QPrinter::Color);
901 QRect totalBBox=mapCenter->getTotalBBox();
903 // Try to set orientation automagically
904 // Note: Interpretation of generated postscript is amibiguous, if
905 // there are problems with landscape mode, see
906 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
908 if (totalBBox.width()>totalBBox.height())
909 // recommend landscape
910 printer->setOrientation (QPrinter::Landscape);
912 // recommend portrait
913 printer->setOrientation (QPrinter::Portrait);
915 if ( printer->setup(this) )
916 // returns false, if printing is canceled
918 QPainter pp(printer);
920 // Don't print the visualisation of selection
921 LinkableMapObj *oldselection=NULL;
924 oldselection=selection;
925 selection->unselect();
928 // Handle sizes of map and paper:
930 // setWindow defines which part of the canvas will be transformed
931 // setViewport defines area on paper in device coordinates (dpi)
932 // e.g. (0,50,700,700) is upper part on A4
933 // see also /usr/lib/qt3/doc/html/coordsys.html
935 QPaintDeviceMetrics metrics (printer);
937 double paperAspect = (double)metrics.width() / (double)metrics.height();
938 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
940 QRect mapRect=totalBBox;
941 QCanvasRectangle *frame=NULL;
942 QCanvasText *footerFN=NULL;
943 QCanvasText *footerDate=NULL;
944 if (printFrame || printFooter)
949 // Print frame around map
950 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
951 totalBBox.width()+20, totalBBox.height()+20);
952 frame=new QCanvasRectangle (mapRect,mapCanvas);
953 frame->setBrush (QColor(white));
954 frame->setPen (QColor(black));
959 QCanvasLine *l=new QCanvasLine (mapCanvas);
960 l->setPoints (0,0,mapRect.width(),mapRect.height());
961 l->setPen (QPen(QColor(black), 1));
968 // Print footer below map
970 font.setPointSize(10);
971 footerFN=new QCanvasText (mapCanvas);
972 footerFN->setText ("VYM - " + fileName);
973 footerFN->setFont(font);
974 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
975 footerFN->setZ(Z_TEXT);
977 footerDate=new QCanvasText (mapCanvas);
978 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
979 footerDate->setFont(font);
980 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
981 footerDate->setZ(Z_TEXT);
984 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
987 pp.setWindow (mapRect);
990 if (mapAspect>=paperAspect)
992 // Fit horizontally to paper width
993 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
996 // Fit vertically to paper height
997 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1000 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1002 // Delete Frame and footer
1006 delete (footerDate);
1008 if (frame) delete (frame);
1010 // Restore selection
1013 selection=oldselection;
1014 selection->select();
1019 QPixmap MapEditor::getPixmap()
1021 QRect mapRect=mapCenter->getTotalBBox();
1022 QPixmap pix (mapRect.size());
1025 // Don't print the visualisation of selection
1026 LinkableMapObj *oldselection=NULL;
1029 oldselection=selection;
1030 selection->unselect();
1033 pp.setWindow (mapRect);
1035 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1038 // Restore selection
1041 selection=oldselection;
1042 selection->select();
1048 void MapEditor::exportImage(QString fn)
1050 // Finish open lineEdits
1051 if (lineedit) finishedLineEditNoSave();
1053 QPixmap pix (getPixmap());
1054 pix.save(fn, "PNG");
1057 void MapEditor::exportImage(QString fn, int item)
1059 // Finish open lineEdits
1060 if (lineedit) finishedLineEditNoSave();
1062 QPixmap pix (getPixmap());
1063 pix.save(fn, exportImageFormatMenu->text(item) );
1066 void MapEditor::exportASCII()
1068 // FIXME still experimental
1069 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
1070 fd->addFilter ("TXT (*.txt)");
1071 fd->setCaption("VYM - Export (ASCII) (still experimental)");
1072 fd->setMode( QFileDialog::AnyFile );
1075 if ( fd->exec() == QDialog::Accepted )
1077 if (QFile (fd->selectedFile()).exists() )
1079 QMessageBox mb( "VYM",
1080 tr("The file ") + fd->selectedFile() +
1081 tr(" exists already. Do you want to overwrite it?"),
1082 QMessageBox::Warning,
1083 QMessageBox::Yes | QMessageBox::Default,
1084 QMessageBox::Cancel | QMessageBox::Escape,
1085 QMessageBox::NoButton );
1087 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1088 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1092 case QMessageBox::Yes:
1094 if (!ex.setOutputDir ("out"))
1096 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1100 case QMessageBox::Cancel:
1107 ex.setPath (fd->selectedFile() );
1108 ex.setMapCenter(mapCenter);
1114 void MapEditor::exportXML(const QString &dir)
1116 // Create subdirectories
1119 // write to directory
1120 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1123 file.setName ( dir + "/"+mapName+".xml");
1124 if ( !file.open( IO_WriteOnly ) )
1126 // This should neverever happen
1127 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1131 // Write it finally, and write in UTF8, no matter what
1132 QTextStream ts( &file );
1133 ts.setEncoding (QTextStream::UnicodeUTF8);
1137 // Now write image, too
1138 exportImage (dir+"/images/"+mapName+".png");
1141 void MapEditor::clear()
1145 selection->unselect();
1152 void MapEditor::copy()
1154 // Finish open lineEdits
1155 if (lineedit) finishedLineEditNoSave();
1159 if (typeid(*selection) == typeid(BranchObj) )
1163 clipboardME->clear();
1164 clipboardME->getMapCenter()->addBranch();
1165 to=clipboardME->getMapCenter()->getLastBranch();
1168 from=(BranchObj*)(selection);
1171 // keep position relative to parent
1172 to->move2RelPos ( from->getRelPos());
1174 // select data in clipboard
1175 clipboardME->select ("bo:0");
1177 // repositioning makes testing nicer,
1178 // but is not needed usually:
1179 if (clipboardME->isVisible())
1181 clipboardME->getMapCenter()->reposition();
1184 clipboardME->hide();
1187 if (typeid(*selection) == typeid(FloatImageObj) )
1190 FloatImageObj* from;
1191 clipboardME->clear();
1192 clipboardME->getMapCenter()->addFloatImage();
1193 to=clipboardME->getMapCenter()->getLastFloatImage();
1196 from=(FloatImageObj*)(selection);
1199 // select data in clipboard
1200 clipboardME->select ("fi:0");
1202 // repositioning makes testing nicer,
1203 // but is not needed usually:
1204 if (clipboardME->isVisible())
1206 clipboardME->getMapCenter()->reposition();
1209 clipboardME->hide();
1215 void MapEditor::undo()
1217 // Finish open lineEdits
1218 if (lineedit) finishedLineEditNoSave();
1223 selection->unselect();
1227 parseAtom (undoCommand);
1228 mapCenter->reposition();
1230 // Undo not longer available now
1231 actionEditUndo->setEnabled (false);
1236 void MapEditor::undoXML(const QString &undoSel)
1239 d.setPath(bakMapDir);
1242 // We need to parse saved XML data
1243 mapBuilderHandler handler;
1244 QXmlInputSource source;
1245 source.setData(backupXML);
1246 QXmlSimpleReader reader;
1247 reader.setContentHandler( &handler );
1248 reader.setErrorHandler( &handler );
1249 handler.setMapEditor( this );
1250 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1251 if (undoSel.isEmpty())
1254 handler.setLoadMode (NewMap);
1258 handler.setLoadMode (ImportReplace);
1260 blockreposition=true;
1261 bool ok = reader.parse( source );
1262 blockreposition=false;
1265 // This should never ever happen
1266 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1267 tr( handler.errorProtocol() )+" in "+backupXML );
1271 QMessageBox::critical( 0, tr( "Critical Error" ),
1272 "Temporary directory " +bakMapDir +
1273 tr (" used for undo is gone. \n"
1274 "I will create a new one, but at the moment no undo is available.\n"
1275 "Maybe you want to reload your original data.\n\n"
1276 "Sorry for any inconveniences.") );
1281 LinkableMapObj* MapEditor::pasteNoSave()
1283 // Finish open lineEdits
1284 if (lineedit) finishedLineEditNoSave();
1286 LinkableMapObj *fromLMO=clipboardME->getSelection();
1287 LinkableMapObj *returnLMO=NULL;
1289 if (selection && fromLMO)
1292 if (typeid(*fromLMO) == typeid(BranchObj) )
1294 if (typeid(*selection) == typeid(MapCenterObj))
1296 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1297 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1299 if (typeid(*selection) == typeid(BranchObj))
1300 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1303 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1304 (typeid(*selection) == typeid (BranchObj) ||
1305 typeid(*selection)==typeid(MapCenterObj)) )
1306 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1312 void MapEditor::cutNoSave()
1314 // Finish open lineEdits
1315 if (lineedit) finishedLineEditNoSave();
1319 if (selection != NULL) {
1320 if (typeid(*selection) == typeid(BranchObj) )
1322 bo=(BranchObj*)(selection);
1323 par=(BranchObj*)(bo->getParObj());
1326 par->removeBranch(bo);
1328 selection->select();
1330 if (typeid(*selection) == typeid(FloatImageObj) )
1332 FloatImageObj* fio=(FloatImageObj*)(selection);
1333 par=(BranchObj*)(fio->getParObj());
1336 par->removeFloatImage(fio);
1338 selection->select();
1343 void MapEditor::paste()
1346 saveState(selection);
1348 mapCenter->reposition();
1352 void MapEditor::cut()
1355 saveState(selection->getParObj());
1358 mapCenter->reposition();
1362 void MapEditor::moveBranchUp()
1364 // Finish open lineEdits
1365 if (lineedit) finishedLineEditNoSave();
1369 if (typeid(*selection) == typeid(BranchObj) )
1372 saveState("moveBranchDown ()");
1373 bo=(BranchObj*)(selection);
1374 par=(BranchObj*)(bo->getParObj());
1375 selection->unselect();
1376 selection=par->moveBranchUp (bo);
1377 selection->select();
1378 mapCenter->reposition();
1379 ensureSelectionVisible();
1383 void MapEditor::moveBranchDown()
1385 // Finish open lineEdits
1386 if (lineedit) finishedLineEditNoSave();
1390 if (typeid(*selection) == typeid(BranchObj) )
1393 saveState("moveBranchUp ()");
1394 bo=(BranchObj*)(selection);
1395 par=(BranchObj*)(bo->getParObj());
1396 selection->unselect();
1397 selection=par->moveBranchDown(bo);
1398 selection->select();
1399 mapCenter->reposition();
1400 ensureSelectionVisible();
1404 void MapEditor::editHeading()
1406 // Finish open lineEdits
1407 if (lineedit) finishedLineEditNoSave();
1410 (typeid(*selection) == typeid(BranchObj) ||
1411 typeid(*selection) == typeid(MapCenterObj) ) )
1414 saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")");
1416 ensureSelectionVisible();
1417 editingBO=(BranchObj*)(selection);
1418 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1419 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1420 QString s=editingBO->getHeading();
1421 lineedit->setText(s);
1422 lineedit->setCursorPosition(1);
1423 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1424 lineedit->selectAll();
1427 lineedit->grabKeyboard();
1428 lineedit->setFocus();
1432 void MapEditor::setHeading(const QString &s)
1434 // Internal function, no saveState needed
1436 (typeid(*selection) == typeid(BranchObj) ||
1437 typeid(*selection) == typeid(MapCenterObj) ) )
1439 ((BranchObj*)(selection))->setHeading(s);
1440 mapCenter->reposition();
1442 ensureSelectionVisible();
1446 void MapEditor::addNewBranch(int pos)
1448 // Finish open lineEdits
1449 if (lineedit) finishedLineEditNoSave();
1452 (typeid(*selection) == typeid(BranchObj) ||
1453 typeid(*selection) == typeid(MapCenterObj) ) )
1456 saveState(selection);
1458 BranchObj* bo1 = (BranchObj*) (selection);
1459 bool wasScrolled=false;
1460 BranchObj *newbo=NULL;
1463 // save scroll state. If scrolled, automatically select
1464 // new branch in order to tmp unscroll parent...
1465 wasScrolled=bo1->isScrolled();
1466 newbo=bo1->addBranch();
1469 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1473 // add above selection
1474 newbo=parbo->insertBranch(bo1->getNum());
1476 // add below selection
1477 newbo=parbo->insertBranch(bo1->getNum()+1);
1479 // This should not happen...
1484 LinkableMapObj *oldselection=selection;
1486 mapCenter->reposition();
1488 if (actionSettingsAutoedit->isOn() ||
1489 actionSettingsAutoselectHeading->isOn() )
1491 selection->unselect();
1493 selection->select();
1494 if (actionSettingsPasteNewHeading->isOn() )
1496 BranchObj *bo2= (BranchObj*)(selection);
1497 bo2->setHeading("");
1499 if (actionSettingsAutoedit->isOn() )
1501 if (!actionSettingsAutoselectHeading->isOn()
1504 selection->unselect();
1505 selection=oldselection;
1506 selection->select();
1513 void MapEditor::addNewBranchHere()
1515 // Finish open lineEdits
1516 if (lineedit) finishedLineEditNoSave();
1519 (typeid(*selection) == typeid(BranchObj) ) )
1522 saveState(selection);
1524 BranchObj* bo1 = (BranchObj*) (selection);
1525 bool wasScrolled=false;
1526 BranchObj *newbo=NULL;
1527 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1530 // add below selection
1531 newbo=parbo->insertBranch(bo1->getNum()+1);
1534 LinkableMapObj *oldselection=selection;
1535 ((BranchObj*)(selection))->moveBranchTo (newbo,-1);
1537 mapCenter->reposition();
1539 if (actionSettingsAutoedit->isOn() ||
1540 actionSettingsAutoselectHeading->isOn() )
1542 selection->unselect();
1544 selection->select();
1545 if (actionSettingsPasteNewHeading->isOn() )
1547 BranchObj *bo2= (BranchObj*)(selection);
1548 bo2->setHeading("");
1550 if (actionSettingsAutoedit->isOn() )
1552 if (!actionSettingsAutoselectHeading->isOn()
1555 selection->unselect();
1556 selection=oldselection;
1557 selection->select();
1563 void MapEditor::deleteSelection()
1565 // Finish open lineEdits
1566 if (lineedit) finishedLineEditNoSave();
1568 if (selection && typeid(*selection) ==typeid(BranchObj) )
1571 saveState(selection->getParObj());
1572 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1573 BranchObj* par=(BranchObj*)(bo->getParObj());
1576 par->removeBranch(bo);
1578 selection->select();
1579 ensureSelectionVisible();
1580 mapCenter->reposition();
1583 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1586 saveState(selection->getParObj());
1587 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1588 BranchObj* par=(BranchObj*)(fio->getParObj());
1591 par->removeFloatImage(fio);
1593 selection->select();
1594 ensureSelectionVisible();
1595 mapCenter->reposition();
1600 LinkableMapObj* MapEditor::getSelection()
1605 bool MapEditor::select (const QString &s)
1607 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1609 // Finally select the found object
1612 if (selection) unselect();
1614 selection->select();
1616 ensureSelectionVisible();
1622 void MapEditor::unselect()
1626 selectionLast=selection;
1627 selection->unselect();
1632 void MapEditor::reselect()
1636 selection=selectionLast;
1637 selection->select();
1642 void MapEditor::selectNextBranch()
1644 // Increase number of branch
1647 QString s=selection->getSelectString();
1653 part=s.section(",",-1);
1655 num=part.right(part.length() - 3);
1657 s=s.left (s.length() -num.length());
1660 num=QString ("%1").arg(num.toUInt()+1);
1664 // Try to select this one
1665 if (select (s)) return;
1667 // We have no direct successor,
1668 // try to increase the parental number in order to
1669 // find a successor with same depth
1671 int d=selection->getDepth();
1676 while (!found && d>0)
1678 s=s.section (",",0,d-1);
1679 // replace substring of current depth in s with "1"
1680 part=s.section(",",-1);
1682 num=part.right(part.length() - 3);
1686 // increase number of parent
1687 num=QString ("%1").arg(num.toUInt()+1);
1688 s=s.section (",",0,d-2) + ","+ typ+num;
1691 // Special case, look at orientation
1692 if (selection->getOrientation()==OrientRightOfCenter)
1693 num=QString ("%1").arg(num.toUInt()+1);
1695 num=QString ("%1").arg(num.toUInt()-1);
1700 // pad to oldDepth, select the first branch for each depth
1701 for (i=d;i<oldDepth;i++)
1706 if ( ((BranchObj*)(selection))->countBranches()>0)
1714 // try to select the freshly built string
1722 void MapEditor::selectPrevBranch()
1724 // Decrease number of branch
1727 QString s=selection->getSelectString();
1733 part=s.section(",",-1);
1735 num=part.right(part.length() - 3);
1737 s=s.left (s.length() -num.length());
1740 num=QString ("%1").arg(num.toUInt()-1);
1744 // Try to select this one
1745 if (select (s)) return;
1747 // We have no direct precessor,
1748 // try to decrease the parental number in order to
1749 // find a precessor with same depth
1751 int d=selection->getDepth();
1756 while (!found && d>0)
1758 s=s.section (",",0,d-1);
1759 // replace substring of current depth in s with "1"
1760 part=s.section(",",-1);
1762 num=part.right(part.length() - 3);
1766 // decrease number of parent
1767 num=QString ("%1").arg(num.toUInt()-1);
1768 s=s.section (",",0,d-2) + ","+ typ+num;
1771 // Special case, look at orientation
1772 if (selection->getOrientation()==OrientRightOfCenter)
1773 num=QString ("%1").arg(num.toUInt()-1);
1775 num=QString ("%1").arg(num.toUInt()+1);
1780 // pad to oldDepth, select the last branch for each depth
1781 for (i=d;i<oldDepth;i++)
1785 if ( ((BranchObj*)(selection))->countBranches()>0)
1786 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1793 // try to select the freshly built string
1801 void MapEditor::selectUpperBranch()
1803 // Finish open lineEdits
1804 if (lineedit) finishedLineEditNoSave();
1808 if (typeid(*selection) == typeid(BranchObj))
1810 if (selection->getOrientation()==OrientRightOfCenter)
1813 if (selection->getDepth()==1)
1821 void MapEditor::selectLowerBranch()
1823 // Finish open lineEdits
1824 if (lineedit) finishedLineEditNoSave();
1828 if (typeid(*selection) == typeid(BranchObj))
1830 if (selection->getOrientation()==OrientRightOfCenter)
1833 if (selection->getDepth()==1)
1842 void MapEditor::selectLeftBranch()
1844 // Finish open lineEdits
1845 if (lineedit) finishedLineEditNoSave();
1851 if (typeid(*selection) == typeid(MapCenterObj))
1853 par= (BranchObj*) (selection);
1854 bo=par->getLastSelectedBranch();
1857 // Workaround for reselecting on left and right side
1858 if (bo->getOrientation()==OrientRightOfCenter)
1860 bo=par->getLastBranch();
1866 selection->select();
1868 ensureSelectionVisible();
1873 par=(BranchObj*)(selection->getParObj());
1874 if (selection->getOrientation()==OrientRightOfCenter)
1876 if (typeid(*selection) == typeid(BranchObj) ||
1877 typeid(*selection) == typeid(FloatImageObj))
1879 selection->unselect();
1881 selection->select();
1883 ensureSelectionVisible();
1887 if (typeid(*selection) == typeid(BranchObj) )
1889 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1892 selection->unselect();
1894 selection->select();
1896 ensureSelectionVisible();
1904 void MapEditor::selectRightBranch()
1906 // Finish open lineEdits
1907 if (lineedit) finishedLineEditNoSave();
1914 if (typeid(*selection) == typeid(MapCenterObj))
1916 par= (BranchObj*) (selection);
1917 bo=par->getLastSelectedBranch();
1920 // Workaround for relecting on left and right side
1921 if (bo->getOrientation()==OrientLeftOfCenter)
1922 bo=par->getFirstBranch();
1927 selection->select();
1928 ensureSelectionVisible();
1933 par=(BranchObj*)(selection->getParObj());
1934 if (selection->getOrientation()==OrientLeftOfCenter)
1936 if (typeid(*selection) == typeid(BranchObj) ||
1937 typeid(*selection) == typeid(FloatImageObj))
1939 selection->unselect();
1941 selection->select();
1943 ensureSelectionVisible();
1947 if (typeid(*selection) == typeid(BranchObj) )
1949 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1952 selection->unselect();
1954 selection->select();
1956 ensureSelectionVisible();
1964 void MapEditor::selectFirstBranch()
1966 // Finish open lineEdits
1967 if (lineedit) finishedLineEditNoSave();
1973 if (typeid(*selection) == typeid(BranchObj))
1975 bo1= (BranchObj*) (selection);
1976 par=(BranchObj*)(bo1->getParObj());
1977 bo2=par->getFirstBranch();
1981 selection->select();
1982 ensureSelectionVisible();
1989 void MapEditor::selectLastBranch()
1991 // Finish open lineEdits
1992 if (lineedit) finishedLineEditNoSave();
1998 if (typeid(*selection) == typeid(BranchObj))
2000 bo1= (BranchObj*) (selection);
2001 par=(BranchObj*)(bo1->getParObj());
2002 bo2=par->getLastBranch();
2006 selection->select();
2007 ensureSelectionVisible();
2014 void MapEditor::setColor(QColor c)
2019 void MapEditor::selectBackgroundColor()
2021 // Finish open lineEdits
2022 if (lineedit) finishedLineEditNoSave();
2024 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2025 if ( !col.isValid() ) return;
2026 setBackgroundColor( col );
2030 void MapEditor::setBackgroundColor(QColor c)
2032 mapCanvas->setBackgroundColor (c);
2035 QColor MapEditor::pickColor()
2039 if (typeid(*selection) == typeid(BranchObj) ||
2040 typeid(*selection) == typeid(MapCenterObj))
2042 BranchObj *bo=(BranchObj*)(selection);
2043 actColor=bo->getColor();
2049 void MapEditor::colorItem()
2053 if (typeid(*selection) == typeid(BranchObj) ||
2054 typeid(*selection) == typeid(MapCenterObj))
2057 saveState(selection);
2058 BranchObj *bo=(BranchObj*)(selection);
2059 bo->setColor(actColor, false); // color links, color childs
2064 void MapEditor::colorBranch()
2068 if (typeid(*selection) == typeid(BranchObj) ||
2069 typeid(*selection) == typeid(MapCenterObj))
2072 saveState(selection);
2073 BranchObj *bo=(BranchObj*)(selection);
2074 bo->setColor(actColor, true); // color links, color childs
2080 void MapEditor::toggleStandardFlag(QString f)
2085 saveState(selection);
2086 ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2090 void MapEditor::setViewCenter()
2092 // transform to CanvasView Coord:
2093 QPoint p=worldMatrix().map(movingCenter);
2094 center ( p.x(), p.y());
2098 BranchObj* MapEditor::findText (QString s, bool cs)
2101 { // Nothing found or new find process
2103 // nothing found, start again
2105 itFind=mapCenter->first();
2107 bool searching=true;
2108 bool foundNote=false;
2109 while (searching && !EOFind)
2113 // Searching in Note
2114 if (itFind->getNote().contains(s,cs))
2116 if (selection!=itFind)
2118 if (selection) ((BranchObj*)(selection))->unselect();
2120 selection->select();
2122 ensureSelectionVisible();
2124 if (textEditor->findText(s,cs))
2130 // Searching in Heading
2131 if (searching && itFind->getHeading().contains (s,cs) )
2133 if (selection) ((BranchObj*)(selection))->unselect();
2135 selection->select();
2137 ensureSelectionVisible();
2143 itFind=itFind->next();
2144 if (!itFind) EOFind=true;
2150 return (BranchObj*)(selection);
2155 void MapEditor::findReset()
2156 { // Necessary if text to find changes during a find process
2161 void MapEditor::openURL()
2165 if (typeid(*selection) == typeid(BranchObj) ||
2166 typeid(*selection) == typeid(MapCenterObj))
2168 QString url=((BranchObj*)(selection))->getURL();
2170 QProcess *proc = new QProcess( this );
2172 #if !defined(Q_OS_MACX)
2173 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2175 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2176 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2179 proc->addArgument( url);
2181 if ( !proc->start() )
2183 if (mainWindow->settingsURL() )
2189 void MapEditor::editURL()
2191 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2192 typeid(*selection) == typeid(MapCenterObj)) )
2195 QString text = QInputDialog::getText(
2196 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2197 ((BranchObj*)(selection))->getURL(), &ok, this );
2200 // user entered something and pressed OK
2201 ((BranchObj*)(selection))->setURL (text);
2208 void MapEditor::editHeading2URL()
2210 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2211 typeid(*selection) == typeid(MapCenterObj)) )
2213 BranchObj *b=(BranchObj*)(selection);
2214 b->setURL (b->getHeading());
2220 void MapEditor::editBugzilla2URL()
2222 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2223 typeid(*selection) == typeid(MapCenterObj)) )
2225 BranchObj *b=(BranchObj*)(selection);
2226 b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
2232 void MapEditor::editVymLink()
2234 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2235 typeid(*selection) == typeid(MapCenterObj)) )
2237 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2238 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2239 fd->setCaption(tr("VYM - Link to another map"));
2240 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2241 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2245 if ( fd->exec() == QDialog::Accepted )
2246 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2248 mapCenter->reposition();
2255 void MapEditor::deleteVymLink()
2257 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2258 typeid(*selection) == typeid(MapCenterObj)) )
2260 ((BranchObj*)(selection))->setVymLink ("" );
2262 mapCenter->reposition();
2269 QString MapEditor::getVymLink()
2271 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2272 typeid(*selection) == typeid(MapCenterObj)) )
2274 return ((BranchObj*)(selection))->getVymLink();
2280 void MapEditor::removeBranchHere()
2282 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2285 saveState(selection->getParObj());
2286 QString sel=selection->getSelectString();
2287 BranchObj* bo=(BranchObj*)(selection);
2288 BranchObj* par=(BranchObj*)(bo->getParObj());
2290 par->removeBranchHere(bo);
2291 mapCenter->reposition();
2296 void MapEditor::removeChilds()
2298 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2301 saveState(selection->getParObj());
2302 ((BranchObj*)(selection))->removeChilds();
2303 mapCenter->reposition();
2307 void MapEditor::editMapInfo()
2309 ExtraInfoDialog dia;
2310 dia.setMapName (getFileName() );
2311 dia.setAuthor (mapCenter->getAuthor() );
2312 dia.setComment(mapCenter->getComment() );
2317 QCanvasItemList l=canvas()->allItems();
2318 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2320 stats+=QString ("%1 items on canvas\n").arg (i,6);
2327 bo=mapCenter->first();
2330 if (!bo->getNote().isEmpty() ) n++;
2331 f+= bo->countFloatImages();
2333 xl+=bo->countXLinks();
2336 stats+=QString ("%1 branches\n").arg (b-1,6);
2337 stats+=QString ("%1 xLinks \n").arg (xl,6);
2338 stats+=QString ("%1 notes\n").arg (n,6);
2339 stats+=QString ("%1 images\n").arg (f,6);
2340 dia.setStats (stats);
2342 // Finally show dialog
2343 if (dia.exec() == QDialog::Accepted)
2345 mapCenter->setAuthor (dia.getAuthor() );
2346 mapCenter->setComment (dia.getComment() );
2351 void MapEditor::updateActions()
2354 if (getLinkColorHint()==HeadingColor)
2355 actionFormatLinkColorHint->setOn(true);
2357 actionFormatLinkColorHint->setOn(false);
2362 actionFormatLinkStyleLine->setOn(true);
2365 actionFormatLinkStyleParabel->setOn(true);
2368 actionFormatLinkStylePolyLine->setOn(true);
2370 case StylePolyParabel:
2371 actionFormatLinkStylePolyParabel->setOn(true);
2377 QPixmap pix( 16, 16 );
2378 pix.fill( mapCanvas->backgroundColor() );
2379 actionFormatBackColor->setIconSet( pix );
2380 pix.fill( defLinkColor );
2381 actionFormatLinkColor->setIconSet( pix );
2383 actionEditUndo->setEnabled( mapChanged );
2384 actionFileSave->setEnabled( mapUnsaved );
2388 if ( (typeid(*selection) == typeid(BranchObj)) ||
2389 (typeid(*selection) == typeid(MapCenterObj)) )
2391 BranchObj *bo=(BranchObj*)(selection);
2392 // Take care of links
2393 if (bo->countXLinks()==0)
2395 branchLinksContextMenu->clear();
2396 branchLinksContextMenu->insertItem ("No link available");
2397 branchLinksContextMenuDup->clear();
2398 branchLinksContextMenuDup->insertItem ("No link available");
2404 branchLinksContextMenu->clear();
2405 branchLinksContextMenuDup->clear();
2406 for (int i=0; i<=bo->countXLinks();i++)
2408 bot=bo->XLinkTargetAt(i);
2411 s=bot->getHeading();
2414 branchLinksContextMenu->insertItem (s);
2415 branchLinksContextMenuDup->insertItem (s);
2420 standardFlagsDefault->setEnabled (true);
2422 if ( bo->getURL().isEmpty() )
2423 actionEditOpenURL->setEnabled (false);
2425 actionEditOpenURL->setEnabled (true);
2427 if ( bo->getVymLink().isEmpty() )
2429 actionEditOpenVymLink->setEnabled (false);
2430 actionEditDeleteVymLink->setEnabled (false);
2433 actionEditOpenVymLink->setEnabled (true);
2434 actionEditDeleteVymLink->setEnabled (true);
2437 actionEditCopy->setEnabled (true);
2438 actionEditCut->setEnabled (true);
2439 if (clipboardME->getMapCenter()->countBranches()>0)
2440 actionEditPaste->setEnabled (true);
2442 actionEditPaste->setEnabled (false);
2443 for (a=actionListBranches.first();a;a=actionListBranches.next())
2444 a->setEnabled(true);
2445 actionEditDelete->setEnabled (true);
2446 actionEditToggleFloatExport->setEnabled (false);
2447 switch (selection->getFrameType())
2450 actionFormatFrameNone->setOn(true);
2453 actionFormatFrameRectangle->setOn(true);
2459 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2461 standardFlagsDefault->setEnabled (false);
2463 actionEditOpenURL->setEnabled (false);
2464 actionEditOpenVymLink->setEnabled (false);
2465 actionEditDeleteVymLink->setEnabled (false);
2467 actionEditCopy->setEnabled (true);
2468 actionEditCut->setEnabled (true);
2469 actionEditPaste->setEnabled (false); //FIXME
2470 for (a=actionListBranches.first();a;a=actionListBranches.next())
2471 a->setEnabled(false);
2472 actionEditDelete->setEnabled (true);
2473 actionEditToggleFloatExport->setOn
2474 ( ((FloatImageObj*)(selection))->getFloatExport() );
2479 standardFlagsDefault->setEnabled (false);
2481 actionEditCopy->setEnabled (false);
2482 actionEditCut->setEnabled (false);
2483 actionEditPaste->setEnabled (false);
2484 for (a=actionListBranches.first();a;a=actionListBranches.next())
2485 a->setEnabled(false);
2487 actionEditOpenURL->setEnabled (false);
2488 actionEditOpenVymLink->setEnabled (false);
2489 actionEditDeleteVymLink->setEnabled (false);
2490 actionEditHeading2URL->setEnabled (false);
2491 actionEditDelete->setEnabled (false);
2492 actionEditToggleFloatExport->setEnabled (false);
2496 void MapEditor::setLinkStyle (LinkStyle ls)
2503 bo=mapCenter->first();
2507 bo->setLinkStyle(bo->getDefLinkStyle());
2510 mapCenter->reposition();
2513 LinkStyle MapEditor::getLinkStyle ()
2518 void MapEditor::setLinkColor(QColor c)
2524 void MapEditor::setLinkColorHint()
2526 // called from setLinkColorHint(lch) or at end of parse
2528 bo=mapCenter->first();
2536 void MapEditor::setLinkColorHint(LinkColorHint lch)
2542 void MapEditor::toggleLinkColorHint()
2544 if (linkcolorhint==HeadingColor)
2545 linkcolorhint=DefaultColor;
2547 linkcolorhint=HeadingColor;
2549 bo=mapCenter->first();
2557 LinkColorHint MapEditor::getLinkColorHint()
2559 return linkcolorhint;
2562 QColor MapEditor::getDefLinkColor()
2564 return defLinkColor;
2567 void MapEditor::setDefXLinkColor(QColor col)
2572 QColor MapEditor::getDefXLinkColor()
2574 return defXLinkColor;
2577 void MapEditor::setDefXLinkWidth (int w)
2582 int MapEditor::getDefXLinkWidth()
2584 return defXLinkWidth;
2587 void MapEditor::selectLinkColor()
2589 // Finish open lineEdits
2590 if (lineedit) finishedLineEditNoSave();
2592 QColor col = QColorDialog::getColor( defLinkColor, this );
2593 if ( !col.isValid() ) return;
2594 setLinkColor( col );
2598 void MapEditor::toggleScroll()
2600 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2602 BranchObj *bo=((BranchObj*)(selection));
2603 if (bo->countBranches()==0) return;
2604 if (bo->getDepth()==0) return;
2606 saveState(selection);
2613 void MapEditor::unScrollAll()
2616 bo=mapCenter->first();
2619 if (bo->isScrolled()) bo->toggleScroll();
2624 void MapEditor::loadFloatImage ()
2627 (typeid(*selection) == typeid(BranchObj)) ||
2628 (typeid(*selection) == typeid(MapCenterObj)) )
2630 BranchObj *bo=((BranchObj*)(selection));
2632 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2633 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2634 ImagePreview *p =new ImagePreview (fd);
2635 fd->setContentsPreviewEnabled( TRUE );
2636 fd->setContentsPreview( p, p );
2637 fd->setPreviewMode( QFileDialog::Contents );
2638 fd->setCaption(tr("vym - Load image"));
2639 fd->setDir (lastImageDir);
2643 if ( fd->exec() == QDialog::Accepted )
2646 saveState(selection);
2647 QString fn=fd->selectedFile();
2648 lastImageDir=fn.left(fn.findRev ("/"));
2649 bo->addFloatImage();
2650 // FIXME check if load was successful
2651 bo->getLastFloatImage()->load(fn);
2652 bo->getLastFloatImage()->setOriginalFilename(fn);
2653 mapCenter->reposition();
2660 void MapEditor::saveFloatImage (int item)
2663 (typeid(*selection) == typeid(FloatImageObj)) )
2665 FloatImageObj *fio=((FloatImageObj*)(selection));
2666 const char* fmt = saveImageFormatMenu->text(item);
2668 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2669 fd->addFilter ("PNG (*.png)");
2670 fd->addFilter ("BMP (*.bmp)");
2671 fd->addFilter ("XBM (*.xbm)");
2672 fd->addFilter ("JPG (*.jpg)");
2673 fd->addFilter ("XPM (*.xpm)");
2674 fd->addFilter ("GIF (*.gif)");
2675 fd->addFilter ("PNM (*.pnm)");
2676 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2677 fd->setCaption(tr("vym - Save image as ") + fmt);
2678 fd->setMode( QFileDialog::AnyFile );
2679 fd->setSelection (fio->getOriginalFilename());
2683 if ( fd->exec() == QDialog::Accepted )
2685 if (QFile (fd->selectedFile()).exists() )
2687 QMessageBox mb( "VYM",
2688 tr("The file ") + fd->selectedFile() +
2689 tr(" exists already. "
2690 "Do you want to overwrite it?"),
2691 QMessageBox::Warning,
2692 QMessageBox::Yes | QMessageBox::Default,
2693 QMessageBox::Cancel | QMessageBox::Escape,
2694 QMessageBox::QMessageBox::NoButton );
2696 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2697 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2700 case QMessageBox::Yes:
2703 case QMessageBox::Cancel:
2709 fio->save (fd->selectedFile(),fmt);
2714 void MapEditor::toggleFloatExport()
2717 (typeid(*selection) == typeid(FloatImageObj))||
2718 (typeid(*selection) == typeid(FloatObj)) )
2720 FloatImageObj *fio=((FloatImageObj*)(selection));
2721 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2725 void MapEditor::setFrame(const FrameType &t)
2728 (typeid(*selection) == typeid(BranchObj)) ||
2729 (typeid(*selection) == typeid(MapCenterObj)) )
2731 selection->setFrameType (t);
2732 mapCenter->reposition();
2733 selection->updateLink();
2737 void MapEditor::importDir(BranchObj *dst, QDir d)
2740 (typeid(*selection) == typeid(BranchObj)) ||
2741 (typeid(*selection) == typeid(MapCenterObj)) )
2745 // Traverse directories
2746 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2747 const QFileInfoList *dirlist = d.entryInfoList();
2748 QFileInfoListIterator itdir( *dirlist );
2751 while ( (fi = itdir.current()) != 0 )
2753 if (fi->fileName() != "." && fi->fileName() != ".." )
2756 bo=dst->getLastBranch();
2757 bo->setHeading (fi->fileName() );
2758 bo->setColor (QColor("blue"),false);
2760 if ( !d.cd(fi->fileName()) )
2761 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2764 // Recursively add subdirs
2772 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2773 const QFileInfoList *filelist = d.entryInfoList();
2774 QFileInfoListIterator itfile( *filelist );
2776 while ( (fi = itfile.current()) != 0 )
2779 bo=dst->getLastBranch();
2780 bo->setHeading (fi->fileName() );
2781 bo->setColor (QColor("black"),false);
2782 if (fi->fileName().right(4) == ".vym" )
2783 bo->setVymLink (fi->filePath());
2790 void MapEditor::importDir()
2793 (typeid(*selection) == typeid(BranchObj)) ||
2794 (typeid(*selection) == typeid(MapCenterObj)) )
2796 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2797 fd->setMode (QFileDialog::DirectoryOnly);
2798 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2799 fd->setCaption(tr("VYM - Choose directory structur to import"));
2803 if ( fd->exec() == QDialog::Accepted )
2805 BranchObj *bo=((BranchObj*)(selection));
2806 importDir (bo,QDir(fd->selectedFile()) );
2807 mapCenter->reposition();
2814 void MapEditor::followXLink(int i)
2817 (typeid(*selection) == typeid(BranchObj)) ||
2818 (typeid(*selection) == typeid(MapCenterObj)) )
2820 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2823 selection->unselect();
2825 selection->select();
2826 ensureSelectionVisible();
2831 void MapEditor::editXLink(int i)
2834 (typeid(*selection) == typeid(BranchObj)) ||
2835 (typeid(*selection) == typeid(MapCenterObj)) )
2837 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2840 EditXLinkDialog dia;
2842 dia.setSelection(selection);
2843 if (dia.exec() == QDialog::Accepted)
2845 if (dia.useSettingsGlobal() )
2847 setDefXLinkColor (xlo->getColor() );
2848 setDefXLinkWidth (xlo->getWidth() );
2850 if (dia.deleteXLink())
2851 ((BranchObj*)(selection))->deleteXLinkAt(i);
2860 void MapEditor::testFunction()
2862 cout << "MapEditor::testFunction() called\n";
2864 (typeid(*selection) == typeid(BranchObj)) )
2866 QString s=((BranchObj*)(selection))->getHeading();
2871 void MapEditor::ensureSelectionVisible()
2875 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2877 if (selection->getOrientation() == OrientLeftOfCenter)
2878 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2880 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2881 ensureVisible (p.x(), p.y() );
2886 void MapEditor::updateViewCenter()
2888 // Update movingCenter, so that we can zoom comfortably later
2889 QRect rc = QRect( contentsX(), contentsY(),
2890 visibleWidth(), visibleHeight() );
2891 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2892 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2893 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2896 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2898 // Lineedits are already closed by preceding
2899 // mouseEvent, we don't need to close here.
2901 QPoint p = inverseWorldMatrix().map(e->pos());
2902 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2905 { // MapObj was found
2906 if (selection != lmo)
2908 // select the MapObj
2909 if (selection) selection->unselect();
2911 selection->select();
2917 if (typeid(*selection)==typeid(BranchObj) ||
2918 typeid(*selection)==typeid(MapCenterObj) )
2920 // Context Menu on branch or mapcenter
2922 branchContextMenu->popup(e->globalPos() );
2924 if (typeid(*selection)==typeid(FloatImageObj))
2926 // Context Menu on floatimage
2928 floatimageContextMenu->popup(e->globalPos() );
2932 { // No MapObj found, we are on the Canvas itself
2933 // Context Menu on Canvas
2935 canvasContextMenu->popup(e->globalPos() );
2939 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2941 // Finish open lineEdits
2942 if (lineedit) finishedLineEditNoSave();
2944 QPoint p = inverseWorldMatrix().map(e->pos());
2945 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2947 // Special case: CTRL is pressed
2948 if (e->state() & QMouseEvent::ControlButton)
2950 if (actionModModeColor->isOn())
2952 if (e->state() & QMouseEvent::ControlButton)
2955 setCursor (pickColorCursor);
2959 if (actionModModeLink->isOn())
2961 BranchObj *bo_begin=NULL;
2963 bo_begin=(BranchObj*)(lmo);
2966 ((typeid(*selection) == typeid(BranchObj)) ||
2967 (typeid(*selection) == typeid(MapCenterObj))) )
2968 bo_begin=(BranchObj*)(selection);
2972 linkingObj_src=bo_begin;
2973 tmpXLink=new XLinkObj (mapCanvas);
2974 tmpXLink->setBegin (bo_begin);
2975 tmpXLink->setEnd (p);
2976 tmpXLink->setColor(defXLinkColor);
2977 tmpXLink->setWidth(defXLinkWidth);
2978 tmpXLink->updateXLink();
2979 tmpXLink->setVisibility (true);
2986 { // MapObj was found
2987 if (selection != lmo)
2989 // select the MapObj
2990 if (selection) selection->unselect();
2992 selection->select();
2998 // Check, if systemFlag clicked
2999 if (typeid(*selection)==typeid(BranchObj) ||
3000 typeid(*selection)==typeid(MapCenterObj) )
3002 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
3003 if (!foname.isEmpty())
3005 // Do not move, if systemFlag clicked
3009 if (foname=="vymLink")
3011 mainWindow->editOpenVymLink();
3012 // tabWidget may change, better return now
3013 // before segfaulting...
3017 mainWindow->windowToggleNoteEditor();
3021 // Left Button Move Branches
3022 if (e->button() == QMouseEvent::LeftButton )
3024 // If modMode==copy, then we want to "move" the _new_ object around
3025 // then we need the offset from p to the _old_ selection, because of tmp
3026 if (actionModModeCopy->isOn() &&
3027 e->state() & QMouseEvent::ControlButton)
3029 if (typeid(*selection)==typeid(BranchObj) )
3032 movingObj_start.setX( p.x() - selection->x() );
3033 movingObj_start.setY( p.y() - selection->y() );
3034 mapCenter->addBranch ((BranchObj*)(selection));
3036 selection=mapCenter->getLastBranch();
3037 selection->select();
3038 mapCenter->reposition();
3042 movingObj_start.setX( p.x() - selection->x() );
3043 movingObj_start.setY( p.y() - selection->y() );
3046 movingObj=selection;
3048 // Middle Button Toggle Scroll
3049 // (On Mac OS X this won't work, but we still have
3050 // a button in the toolbar)
3051 if (e->button() == QMouseEvent::MidButton )
3055 { // No MapObj found, we are on the Canvas itself
3056 // Left Button move Pos of CanvasView
3057 if (e->button() == QMouseEvent::LeftButton )
3059 movingObj=NULL; // move Content not Obj
3060 movingObj_start=e->globalPos();
3061 movingCont_start=QPoint (contentsX(), contentsY() );
3062 movingVec=QPoint(0,0);
3063 setCursor(handOpenCursor);
3068 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3070 QPoint p = inverseWorldMatrix().map(e->pos());
3072 // Move the selected MapObj
3073 if ( selection && movingObj)
3075 ensureVisible (p.x(),p.y());
3077 // Now move the selection, but add relative position
3078 // (movingObj_start) where selection was chosen with
3079 // mousepointer. (This avoids flickering resp. jumping
3080 // of selection back to absPos)
3082 LinkableMapObj *lmosel;
3083 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3085 // Check if we could link
3086 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3089 if (typeid(*selection) == typeid(FloatImageObj))
3093 FloatObj *fo=(FloatObj*)(selection);
3094 if (fo->getLinkStyle()==StyleUndef)
3096 fo->setLinkStyle(fo->getDefLinkStyle());
3097 fo->setLinkColor(fo->getParObj()->getLinkColor());
3099 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3103 // Relink float to new mapcenter or branch, if shift is pressed
3104 // Only relink, if selection really has a new parent
3105 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3106 ( (typeid(*lmo)==typeid(BranchObj)) ||
3107 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3108 ( lmo != fo->getParObj())
3111 if (typeid(*fo) == typeid(FloatImageObj))
3113 FloatImageObj *fio=(FloatImageObj*)(fo);
3114 ((BranchObj*)(lmo))->addFloatImage (fio);
3116 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3117 fio=((BranchObj*)(lmo))->getLastFloatImage();
3120 selection=(LinkableMapObj*)(fio);
3121 selection->select();
3122 movingObj=(MapObj*)(fio);
3123 // setLinkStyle calls updateLink, only set it once
3124 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3125 fio->setLinkStyle (fio->getDefLinkStyle());
3128 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3130 } else // selection != a FloatObj
3132 if (lmosel->getDepth()==0)
3134 if (e->state() == (LeftButton | !ShiftButton))
3135 // If mapCenter is moved, move all the rest by default, too.
3136 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3138 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3141 if (lmosel->getDepth()==1)
3143 // depth==1, mainbranch
3146 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3150 if (lmosel->getOrientation() == OrientLeftOfCenter)
3151 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3152 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3153 p.y()-movingObj_start.y() );
3155 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3157 // reposition subbranch
3158 lmosel->reposition();
3159 //ensureSelectionVisible();
3161 if (lmo && (lmo!=selection) &&
3162 (typeid(*lmo) == typeid(BranchObj) ||
3163 (typeid(*lmo) == typeid(MapCenterObj) )
3166 if (e->state() & QMouseEvent::ControlButton)
3168 // Special case: CTRL to link below lmo
3169 lmosel->setParObjTmp (lmo,p,+1);
3171 else if (e->state() & QMouseEvent::ShiftButton)
3172 lmosel->setParObjTmp (lmo,p,-1);
3174 lmosel->setParObjTmp (lmo,p,0);
3177 lmosel->unsetParObjTmp();
3179 if (lmo &&(lmo==selection))
3180 // Could link to myself (happens sometimes...)
3181 lmosel->unsetParObjTmp();
3183 // no Obj under selection, go back to original Parent
3184 lmosel->unsetParObjTmp();
3189 } // no FloatImageObj
3193 } // selection && moving_obj
3195 // Draw a link from one branch to another
3198 tmpXLink->setEnd (p);
3199 tmpXLink->updateXLink();
3203 if (!movingObj && !pickingColor &&!drawingLink)
3205 QPoint p=e->globalPos();
3206 movingVec.setX(-p.x() + movingObj_start.x() );
3207 movingVec.setY(-p.y() + movingObj_start.y() );
3208 setContentsPos( movingCont_start.x() + movingVec.x(),
3209 movingCont_start.y() + movingVec.y());
3216 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3218 LinkableMapObj *dst;
3219 // Have we been picking color?
3223 setCursor (ArrowCursor);
3224 // Check if we are over another branch
3225 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3226 if (dst && selection)
3228 if (e->state() & QMouseEvent::ShiftButton)
3230 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3231 ((BranchObj*)(selection))->setLinkColor ();
3235 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3236 ((BranchObj*)(selection))->setLinkColor ();
3242 // Have we been drawing a link?
3246 // Check if we are over another branch
3247 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3248 if (dst && selection)
3250 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3251 tmpXLink->updateXLink();
3252 tmpXLink->activate();
3263 // Have we been moving something?
3264 if ( selection && movingObj )
3266 // Check if we are over another branch, but ignore
3267 // any found LMOs, which are FloatObjs
3268 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3269 ((LinkableMapObj*)(selection)) );
3272 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3277 // Now check, if we have been moving a branch
3278 if (typeid(*selection) == typeid(BranchObj) )
3280 // save the position in case we link to mapcenter
3281 QPoint savePos=QPoint (selection->x(),selection->y() );
3283 // Reset the temporary drawn link to the original one
3284 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3292 // remove the current selection, if we have no destination
3293 selection->unselect();
3294 ((BranchObj*)(selection->getParObj()))->removeBranch ((BranchObj*)(selection));
3297 selection=selectionLast;
3299 selection->select();
3306 // TODO we also could check, if dest and src are on same branch,
3307 // then it would be sufficient to saveState of this branch
3309 // Modifiers allow to insert above/below dst
3310 if (e->state() & QMouseEvent::ShiftButton)
3312 ((BranchObj*)(selection))->moveBranchTo
3315 ((BranchObj*)(dst))->getNum()
3317 //if (selection) selection->select();
3319 if (e->state() & QMouseEvent::ControlButton)
3321 ((BranchObj*)(selection))->moveBranchTo
3324 ((BranchObj*)(dst))->getNum()+1
3326 //if (selection) selection->select();
3329 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
3330 if (dst->getDepth()==0)
3331 ((BranchObj*)(selection))->move (savePos);
3334 // Draw the original link, before selection was moved around
3335 mapCenter->reposition();
3337 // Finally resize canvas, if needed
3342 // maybe we moved View: set old cursor
3343 setCursor (ArrowCursor);
3347 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3349 // Finish open lineEdits
3350 if (lineedit) finishedLineEditNoSave();
3352 if (e->button() == QMouseEvent::LeftButton )
3354 QPoint p = inverseWorldMatrix().map(e->pos());
3355 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3356 if (lmo) { // MapObj was found
3357 // First select the MapObj than edit heading
3358 if (selection) selection->unselect();
3360 selection->select();
3362 saveState(selection);
3368 void MapEditor::resizeEvent (QResizeEvent* e)
3370 QCanvasView::resizeEvent( e );
3373 if (!fileName.isEmpty()) s=fileName;