added modifier modes (color,link,copy). Not fully functional yet
3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <qpopupmenu.h>
9 #include <qpaintdevicemetrics.h>
11 #include <qfiledialog.h>
14 #include <qcolordialog.h>
17 #include <qinputdialog.h>
26 #include "texteditor.h"
27 #include "linkablemapobj.h"
30 #include "mainwindow.h"
31 #include "extrainfodialog.h"
34 #include "icons/flag-note.xpm"
35 #include "icons/flag-url.xpm"
36 #include "icons/flag-vymlink.xpm"
37 #include "icons/flag-scrolled-right.xpm"
38 #include "icons/flag-tmpUnscrolled-right.xpm"
39 #include "icons/flag-questionmark.xpm"
40 #include "icons/flag-exclamationmark.xpm"
41 #include "icons/flag-hook-green.xpm"
42 #include "icons/flag-cross-red.xpm"
43 #include "icons/flag-stopsign.xpm"
44 #include "icons/flag-smiley-good.xpm"
45 #include "icons/flag-smiley-sad.xpm"
46 #include "icons/flag-clock.xpm"
47 #include "icons/flag-lamp.xpm"
48 #include "icons/flag-arrow-up.xpm"
49 #include "icons/flag-arrow-down.xpm"
50 #include "icons/flag-thumb-up.xpm"
51 #include "icons/flag-thumb-down.xpm"
52 #include "icons/flag-heart.xpm"
53 #include "icons/flag-flash.xpm"
54 #include "icons/flag-lifebelt.xpm"
56 extern TextEditor *textEditor;
57 extern int statusbarTime;
58 extern Main *mainWindow;
59 extern FlagRowObj *systemFlagsDefault;
60 extern FlagRowObj *standardFlagsDefault;
61 extern MapEditor *clipboardME;
63 extern QAction *actionFileSave;
64 extern QAction *actionEditUndo;
65 extern QAction *actionEditCopy;
66 extern QAction *actionEditCut;
67 extern QAction *actionEditPaste;
68 extern QAction *actionEditMoveUp;
69 extern QAction *actionEditMoveDown;
70 extern QAction *actionEditToggleScroll;
71 extern QAction *actionEditOpenURL;
72 extern QAction *actionEditURL;
73 extern QAction *actionEditHeading2URL;
74 extern QAction *actionEditBugzilla2URL;
75 extern QAction *actionEditOpenVymLink;
76 extern QAction *actionEditVymLink;
77 extern QAction *actionEditDeleteVymLink;
78 extern QAction *actionEditHeading;
79 extern QAction *actionEditDelete;
80 extern QAction *actionEditAddBranch;
81 extern QAction *actionEditAddBranchAbove;
82 extern QAction *actionEditAddBranchBelow;
83 extern QAction *actionEditImportAdd;
84 extern QAction *actionEditImportReplace;
85 extern QAction *actionEditSaveBranch;
86 extern QAction *actionEditSelectFirst;
87 extern QAction *actionEditSelectLast;
88 extern QAction *actionEditLoadImage;
89 extern QAction *actionEditToggleFloatExport;
90 extern QAction *actionEditNoLink;
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 *floatimageContextMenu;
124 extern QPopupMenu *saveImageFormatMenu;
125 extern QPopupMenu *exportImageFormatMenu;
126 extern QPopupMenu *canvasContextMenu;
128 extern Settings settings;
131 ///////////////////////////////////////////////////////////////////////
132 ///////////////////////////////////////////////////////////////////////
133 MapEditor::MapEditor(
134 QWidget* parent, bool interactive, const char* name, WFlags f) :
135 QCanvasView(parent,name,f)
137 //cout << "Constructor ME "<<this<<endl;
139 mapCanvas = new QCanvas(1000,800);
140 mapCanvas->setAdvancePeriod(30);
142 setCanvas (mapCanvas);
144 setVScrollBarMode ( QScrollView::AlwaysOn );
145 setHScrollBarMode ( QScrollView::AlwaysOn );
147 // Now create the _global_ system flags _once_:
148 // (Later all OrnamentedObj copy from this
149 // and set their own canvas)
150 if (!systemFlagsDefault)
152 systemFlagsDefault = new FlagRowObj (mapCanvas);
153 systemFlagsDefault->setVisibility (false);
154 systemFlagsDefault->setName ("systemFlagsDef");
156 FlagObj *fo = new FlagObj (mapCanvas);
157 fo->load(QPixmap(flag_note_xpm));
159 fo->setToolTip(tr("Note","Systemflag"));
160 systemFlagsDefault->addFlag (fo); // makes deep copy
162 fo->load(QPixmap(flag_url_xpm));
164 fo->setToolTip(tr("WWW Document (external)","Systemflag"));
165 systemFlagsDefault->addFlag (fo);
167 fo->load(QPixmap(flag_vymlink_xpm));
168 fo->setName("vymLink");
169 fo->setToolTip(tr("Link to another vym map","Systemflag"));
170 systemFlagsDefault->addFlag (fo);
172 fo->load(QPixmap(flag_scrolled_right_xpm));
173 fo->setName("scrolledright");
174 fo->setToolTip(tr("subtree is scrolled","Systemflag"));
175 systemFlagsDefault->addFlag (fo);
177 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
178 fo->setName("tmpUnscrolledright");
179 fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
180 systemFlagsDefault->addFlag (fo);
183 if (!standardFlagsDefault)
185 standardFlagsDefault = new FlagRowObj (mapCanvas);
186 standardFlagsDefault->setVisibility (false);
187 standardFlagsDefault->setName ("standardFlagsDef");
189 FlagObj *fo = new FlagObj (mapCanvas);
190 fo->load(QPixmap(flag_exclamationmark_xpm));
191 fo->setName("exclamationmark");
192 fo->setToolTip(tr("Take care!","Standardflag"));
193 standardFlagsDefault->addFlag (fo); // makes deep copy
195 fo->load(QPixmap(flag_questionmark_xpm));
196 fo->setName("questionmark");
197 fo->setToolTip(tr("Really?","Standardflag"));
198 standardFlagsDefault->addFlag (fo);
200 fo->load(QPixmap(flag_hook_green_xpm));
201 fo->setName("hook-green");
202 fo->setToolTip(tr("ok!","Standardflag"));
203 standardFlagsDefault->addFlag (fo);
205 fo->load(QPixmap(flag_cross_red_xpm));
206 fo->setName("cross-red");
207 fo->setToolTip(tr("Not ok!","Standardflag"));
208 standardFlagsDefault->addFlag (fo);
210 fo->load(QPixmap(flag_stopsign_xpm));
211 fo->setName("stopsign");
212 fo->setToolTip(tr("This won't work!","Standardflag"));
213 standardFlagsDefault->addFlag (fo);
215 fo->load(QPixmap(flag_smiley_good_xpm));
216 fo->setName("smiley-good");
217 fo->setToolTip(tr("Good","Standardflag"));
218 standardFlagsDefault->addFlag (fo);
220 fo->load(QPixmap(flag_smiley_sad_xpm));
221 fo->setName("smiley-sad");
222 fo->setToolTip(tr("Bad","Standardflag"));
223 standardFlagsDefault->addFlag (fo);
225 fo->load(QPixmap(flag_clock_xpm));
226 fo->setName("clock");
227 fo->setToolTip(tr("Time critical","Standardflag"));
228 standardFlagsDefault->addFlag (fo);
230 fo->load(QPixmap(flag_lamp_xpm));
232 fo->setToolTip(tr("Idea!","Standardflag"));
233 standardFlagsDefault->addFlag (fo);
235 fo->load(QPixmap(flag_arrow_up_xpm));
236 fo->setName("arrow-up");
237 fo->setToolTip(tr("Important","Standardflag"));
238 standardFlagsDefault->addFlag (fo);
240 fo->load(QPixmap(flag_arrow_down_xpm));
241 fo->setName("arrow-down");
242 fo->setToolTip(tr("Unimportant","Standardflag"));
243 standardFlagsDefault->addFlag (fo);
245 fo->load(QPixmap(flag_thumb_up_xpm));
246 fo->setName("thumb-up");
247 fo->setToolTip(tr("I like this","Standardflag"));
248 standardFlagsDefault->addFlag (fo);
250 fo->load(QPixmap(flag_thumb_down_xpm));
251 fo->setName("thumb-down");
252 fo->setToolTip(tr("I do not like this","Standardflag"));
253 standardFlagsDefault->addFlag (fo);
255 fo->load(QPixmap(flag_heart_xpm));
256 fo->setName("heart");
257 fo->setToolTip(tr("I just love... ","Standardflag"));
258 standardFlagsDefault->addFlag (fo);
260 fo->load(QPixmap(flag_flash_xpm));
261 fo->setName("flash");
262 fo->setToolTip(tr("Dangerous","Standardflag"));
263 standardFlagsDefault->addFlag (fo);
265 fo->load(QPixmap(flag_lifebelt_xpm));
266 fo->setName("lifebelt");
267 fo->setToolTip(tr("This will help","Standardflag"));
268 standardFlagsDefault->addFlag (fo);
273 mapCenter = new MapCenterObj(mapCanvas);
274 mapCenter->setVisibility (true);
275 mapCenter->setMapEditor (this);
276 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
280 lineedit = new QLineEdit(this, "lineedit" );
281 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
284 actColor=black; setColor (actColor);
285 deflinkcolor=QColor (0,0,255);
286 linkcolorhint=DefaultColor;
287 linkstyle=StylePolyParabel;
288 mapCanvas->setBackgroundColor (white);
290 // Create bitmap cursors, patform dependant
291 #if defined(Q_OS_MACX)
292 #include "icons/cursorhandopen16.xpm"
293 #include "icons/cursorcolorpicker16.xpm"
294 QBitmap cb( 16, 16, chandopen, TRUE );
295 QBitmap cm( 16, 16, chandopenmask, TRUE );
296 handOpenCursor=QCursor ( cb, cm );
297 // set hot spot to tip of picker
298 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
300 #include "icons/cursorhandopen.xpm"
301 #include "icons/cursorcolorpicker.xpm"
303 QBitmap cb( 32, 32, chandopen, TRUE );
304 QBitmap cm( 32, 32, chandopenmask, TRUE );
305 handOpenCursor=QCursor ( cb, cm );
306 // set hot spot to tip of picker
307 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
329 // Initialize find routine
336 blockreposition=false;
337 isInteractive=interactive;
339 // Create temporary files
342 // Initially set movingCentre
345 mapCenter->reposition(); // for positioning heading
348 MapEditor::~MapEditor()
350 //cout <<"Destructor MapEditor\n";
351 if (isInteractive) delTmpDirs();
354 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
358 QColor MapEditor::color()
363 QColor MapEditor::backgroundColor()
365 return mapCanvas->backgroundColor();
368 MapCenterObj* MapEditor::getMapCenter()
373 QCanvas* MapEditor::getCanvas()
378 void MapEditor::adjustCanvasSize()
380 // To adjust the canvas to map, viewport size and position, we have to
381 // do some coordinate magic...
383 // Get rectangle of (scroll-)view.
384 // We want to be in canvas coords, so
385 // we map. Important if view is zoomed...
386 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
387 visibleWidth(), visibleHeight()) );
389 // Now we need the bounding box of view AND map to calc the correct canvas size.
390 // Why? Because if the map itself is moved out of view, the view has to be enlarged
391 // to avoid jumping aroung...
392 QRect map=mapCenter->getTotalBBox();
394 // right edge - left edge
395 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
396 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
399 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
400 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
403 // move the map on canvas (in order to not move it on screen) this is neccessary
404 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
405 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
406 // to scroll to an empty area of canvas to the left.
407 // b) if topleft corner of map left of or above topleft of canvas
411 if (cw > mapCanvas->width() )
413 if (map.x()<0) dx=-map.x();
415 if (cw < mapCanvas->width() )
416 dx=-min (view.x(),map.x());
417 if (ch > mapCanvas->height() )
419 if (map.y()<0) dy=-map.y();
421 if (ch < mapCanvas->height() )
423 dy=-min (view.y(),map.y());
425 // We really have to resize now. Let's go...
426 mapCanvas->resize (cw,ch);
427 if ( (dx!=0) || (dy!=0) )
429 mapCenter->moveAllBy(dx,dy);
430 mapCenter->reposition();
432 // scroll the view (in order to not move map on screen)
438 bool MapEditor::blockReposition()
440 return blockreposition;
443 void MapEditor::makeTmpDirs()
445 // Create unique temporary directories
446 char tmpdir[]="/tmp/vym-XXXXXX";
447 bakMapDir=mkdtemp(tmpdir);
448 makeSubDirs(bakMapDir);
449 // FIXME set permissions
450 // and maybe use QT method for portability
453 void MapEditor::delTmpDirs()
455 //FIXME delete tmp directory, better use QT methods here:
456 system ( "rm -rf "+ bakMapDir );
460 void MapEditor::makeSubDirs(const QString &s)
468 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, SaveMode savemode)
470 // tmpdir temporary directory to which data will be writte
471 // prefix mapname, which will be appended to images etc.
472 // writeflags Only write flags for "real" save of map, not undo
473 // offset offset of bbox of whole map in canvas.
474 // Needed for XML export
475 // completeMap if false, only vympart will be written, without
492 ls="StylePolyParabel";
496 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
498 if (linkcolorhint==HeadingColor)
499 colhint=attribut("linkColorHint","HeadingColor");
501 QString mapAttr=attribut("version",__VYM_VERSION__);
502 if (savemode==CompleteMap)
503 mapAttr+= attribut("author",mapCenter->getAuthor()) +
504 attribut("comment",mapCenter->getComment()) +
505 attribut("date",mapCenter->getDate()) +
506 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
507 attribut("linkStyle", ls ) +
508 attribut("linkColor", deflinkcolor.name() ) +
510 s+=beginElement("vymmap",mapAttr);
513 // Find the used flags while traversing the tree
514 standardFlagsDefault->resetUsedCounter();
516 // Build xml recursivly
517 if (savemode==CompleteMap)
518 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
521 if ( undoSelection &&
522 typeid(*undoSelection) == typeid(BranchObj) )
523 s+=((BranchObj*)(undoSelection))->saveToDir(tmpdir,prefix,offset);
526 // Save local settings
527 s+=settings.getXMLData (destPath);
531 s+=valueElement("select",selection->getSelectString());
534 s+=endElement("vymmap");
537 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
542 void MapEditor::saveState()
544 saveState (CompleteMap,NULL);
547 void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part)
549 // all binary data is saved in bakMapDir (created in Constructor)
550 // the xml data itself is kept in memory in backupXML
552 // For faster write/read of data, a part of the map can be
553 // written. Then the undoSelection will mark, which part of the
554 // map should be replaced if an undo is wanted later.
556 if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) )
558 // Writing a vympart only is useful for BranchObj
560 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
564 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap);
568 void MapEditor::finishedLineEditNoSave()
570 // This is called by finishedLineEdit or any MapEditor method,
571 // which wants to assure, that lineedits finish, before e.g. a branch is
574 // After calling LineEdit and using the clipboard, the
575 // focus is not any longer on the main widget, we
576 // have to restore it using parentWidget()->setFocus()
580 editingBO->setHeading(lineedit->text() );
582 lineedit->releaseKeyboard();
584 parentWidget()->setFocus();
585 mapCenter->reposition();
587 ensureSelectionVisible();
592 bool MapEditor::isDefault()
597 bool MapEditor::isUnsaved()
602 bool MapEditor::hasChanged()
607 void MapEditor::setChanged()
612 actionEditUndo->setEnabled (true);
613 actionFileSave->setEnabled (true);
617 void MapEditor::closeMap()
619 // Finish open lineEdits
620 if (lineedit) finishedLineEditNoSave();
622 // Unselect before disabling the toolbar actions
623 if (selection) selection->unselect();
631 void MapEditor::setFilePath(QString fname)
633 setFilePath (fname,fname);
636 void MapEditor::setFilePath(QString fname, QString destname)
642 // If fname is not an absolute path, complete it
643 filePath=QDir(fname).absPath();
644 fileDir=filePath.left (1+filePath.findRev ("/"));
646 // Set short name, too. Search from behind:
647 int i=fileName.findRev("/");
648 if (i>=0) fileName=fileName.remove (0,i+1);
650 // Forget the .vym (or .xml) for name of map
651 mapName=fileName.left(fileName.findRev(".",-1,true) );
654 QString MapEditor::getFilePath()
659 QString MapEditor::getFileName()
664 QString MapEditor::getMapName()
669 QString MapEditor::getDestPath()
674 int MapEditor::load (QString &fname, const LoadMode &lmode)
676 // Finish open lineEdits
677 if (lineedit) finishedLineEditNoSave();
683 if (selection) selection->unselect();
686 mapCenter->setMapEditor(this);
687 // (map state is set later at end of load...)
691 saveState(PartOfMap,selection);
695 mapBuilderHandler handler;
698 // I am paranoid: file should exist anyway
699 // according to check in mainwindow.
702 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
703 tr("Couldn't open map " +fname)+".");
707 blockreposition=true;
708 QXmlInputSource source( file);
709 QXmlSimpleReader reader;
710 reader.setContentHandler( &handler );
711 reader.setErrorHandler( &handler );
712 handler.setMapEditor( this );
713 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
714 handler.setLoadMode (lmode);
715 bool ok = reader.parse( source );
716 blockreposition=false;
720 mapCenter->reposition();
730 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
731 tr( handler.errorProtocol() ) );
733 // Still return "success": the map maybe at least
734 // partially read by the parser
741 int MapEditor::save (const SaveMode &savemode)
743 // Finish open lineEdits
744 if (lineedit) finishedLineEditNoSave();
748 // Create mapName and fileDir
749 makeSubDirs (fileDir);
753 fname=mapName+".xml";
755 // use name given by user, even if he chooses .doc
759 // Check if fname is writeable
760 QFile file( fileDir+fname);
761 if (!file.open( IO_WriteOnly ) )
763 QMessageBox::critical( 0, tr( "Critical Save Error" ),
764 tr("Couldn't write to ") +fileDir+fname);
770 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),savemode);
772 file.setName ( fileDir + fname);
773 if ( !file.open( IO_WriteOnly ) )
775 // This should neverever happen
776 QMessageBox::critical(0, tr("Critcal save error"),"MapEditor::save() Couldn't open "+file.name());
780 // Write it finally, and write in UTF8, no matter what
781 QTextStream ts( &file );
782 ts.setEncoding (QTextStream::UnicodeUTF8);
790 actionFileSave->setEnabled(false);
796 void MapEditor::setZipped (bool z)
801 bool MapEditor::saveZipped ()
806 void MapEditor::print()
808 // Finish open lineEdits
809 if (lineedit) finishedLineEditNoSave();
813 printer = new QPrinter;
814 printer->setColorMode (QPrinter::Color);
817 QRect totalBBox=mapCenter->getTotalBBox();
819 // Try to set orientation automagically
820 // Note: Interpretation of generated postscript is amibiguous, if
821 // there are problems with landscape mode, see
822 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
824 if (totalBBox.width()>totalBBox.height())
825 // recommend landscape
826 printer->setOrientation (QPrinter::Landscape);
828 // recommend portrait
829 printer->setOrientation (QPrinter::Portrait);
831 if ( printer->setup(this) )
832 // returns false, if printing is canceled
834 QPainter pp(printer);
836 // Don't print the visualisation of selection
837 LinkableMapObj *oldselection=NULL;
840 oldselection=selection;
841 selection->unselect();
844 // Handle sizes of map and paper:
846 // setWindow defines which part of the canvas will be transformed
847 // setViewport defines area on paper in device coordinates (dpi)
848 // e.g. (0,50,700,700) is upper part on A4
849 // see also /usr/lib/qt3/doc/html/coordsys.html
851 QPaintDeviceMetrics metrics (printer);
853 double paperAspect = (double)metrics.width() / (double)metrics.height();
854 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
856 QRect mapRect=mapCenter->getTotalBBox();
857 QCanvasRectangle *frame=NULL;
858 QCanvasText *footerFN=NULL;
859 QCanvasText *footerDate=NULL;
860 if (printFrame || printFooter)
865 // Print frame around map
866 mapRect.setRect (mapRect.x()-10, mapRect.y()-10,
867 mapRect.width()+20, mapRect.height()+20);
868 frame=new QCanvasRectangle (mapRect,mapCanvas);
869 frame->setBrush (QColor(white));
870 frame->setPen (QColor(black));
876 // Print footer below map
878 font.setPointSize(10);
879 footerFN=new QCanvasText (mapCanvas);
880 footerFN->setText ("VYM - " + fileName);
881 footerFN->setFont(font);
882 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
883 footerFN->setZ(Z_TEXT);
885 footerDate=new QCanvasText (mapCanvas);
886 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
887 footerDate->setFont(font);
888 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
889 footerDate->setZ(Z_TEXT);
891 mapRect.setRect (mapRect.x(), mapRect.y(),
892 mapRect.width(), mapRect.height()+20);
894 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height());
897 pp.setWindow (mapRect);
900 if (mapAspect>=paperAspect)
902 // Fit horizontally to paper width
903 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
906 // Fit vertically to paper height
907 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
910 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
912 // Delete Frame and footer
918 if (frame) delete (frame);
923 selection=oldselection;
929 QPixmap MapEditor::getPixmap()
931 QRect mapRect=mapCenter->getTotalBBox();
932 QPixmap pix (mapRect.size());
935 // Don't print the visualisation of selection
936 LinkableMapObj *oldselection=NULL;
939 oldselection=selection;
940 selection->unselect();
943 pp.setWindow (mapRect);
945 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
951 selection=oldselection;
958 void MapEditor::exportImage(QString fn)
960 // Finish open lineEdits
961 if (lineedit) finishedLineEditNoSave();
963 QPixmap pix (getPixmap());
967 void MapEditor::exportImage(QString fn, int item)
969 // Finish open lineEdits
970 if (lineedit) finishedLineEditNoSave();
972 QPixmap pix (getPixmap());
973 pix.save(fn, exportImageFormatMenu->text(item) );
976 void MapEditor::exportASCII()
978 // FIXME still experimental
979 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
980 fd->addFilter ("TXT (*.txt)");
981 fd->setCaption("VYM - Export (ASCII) (still experimental)");
982 fd->setMode( QFileDialog::AnyFile );
985 if ( fd->exec() == QDialog::Accepted )
987 if (QFile (fd->selectedFile()).exists() )
989 QMessageBox mb( "VYM",
990 tr("The file ") + fd->selectedFile() +
991 tr(" exists already. Do you want to overwrite it?"),
992 QMessageBox::Warning,
993 QMessageBox::Yes | QMessageBox::Default,
994 QMessageBox::Cancel | QMessageBox::Escape,
995 QMessageBox::NoButton );
997 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
998 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1002 case QMessageBox::Yes:
1004 if (!ex.setOutputDir ("out"))
1006 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1010 case QMessageBox::Cancel:
1017 ex.setPath (fd->selectedFile() );
1018 ex.setMapCenter(mapCenter);
1024 void MapEditor::exportXML(const QString &dir)
1026 // Create subdirectories
1029 // write to directory
1030 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,CompleteMap);
1033 file.setName ( dir + "/"+mapName+".xml");
1034 if ( !file.open( IO_WriteOnly ) )
1036 // This should neverever happen
1037 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1041 // Write it finally, and write in UTF8, no matter what
1042 QTextStream ts( &file );
1043 ts.setEncoding (QTextStream::UnicodeUTF8);
1047 // Now write image, too
1048 exportImage (dir+"/images/"+mapName+".png");
1051 void MapEditor::clear()
1055 selection->unselect();
1062 void MapEditor::undo()
1065 d.setPath(bakMapDir);
1068 // Finish open lineEdits
1069 if (lineedit) finishedLineEditNoSave();
1073 selection->unselect();
1077 mapBuilderHandler handler;
1078 QXmlInputSource source;
1079 source.setData(backupXML);
1080 QXmlSimpleReader reader;
1081 reader.setContentHandler( &handler );
1082 reader.setErrorHandler( &handler );
1083 handler.setMapEditor( this );
1084 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1087 selection=undoSelection;
1088 selection->select();
1089 handler.setLoadMode (ImportReplace);
1094 handler.setLoadMode (NewMap);
1096 blockreposition=true;
1097 bool ok = reader.parse( source );
1098 blockreposition=false;
1100 mapCenter->reposition();
1104 // This should never ever happen
1105 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1106 tr( handler.errorProtocol() )+" in "+backupXML );
1108 // Undo not longer available now
1109 actionEditUndo->setEnabled (false);
1110 undoSelection=false;
1115 QMessageBox::critical( 0, tr( "Critical Error" ),
1116 "Temporary directory " +bakMapDir +
1117 tr (" used for undo is gone. \n"
1118 "I will create a new one, but at the moment no undo is available.\n"
1119 "Maybe you want to reload your original data.\n\n"
1120 "Sorry for any inconveniences.") );
1125 void MapEditor::copy()
1127 // Finish open lineEdits
1128 if (lineedit) finishedLineEditNoSave();
1132 if (typeid(*selection) == typeid(BranchObj) )
1136 clipboardME->clear();
1137 clipboardME->getMapCenter()->addBranch();
1138 to=clipboardME->getMapCenter()->getLastBranch();
1141 from=(BranchObj*)(selection);
1144 // keep position relative to parent
1145 to->move2RelPos ( from->getRelPos());
1147 // select data in clipboard
1148 clipboardME->select ("bo:0");
1150 // repositioning makes testing nicer,
1151 // but is not needed usually:
1152 if (clipboardME->isVisible())
1154 clipboardME->getMapCenter()->reposition();
1157 clipboardME->hide();
1160 if (typeid(*selection) == typeid(FloatImageObj) )
1163 FloatImageObj* from;
1164 clipboardME->clear();
1165 clipboardME->getMapCenter()->addFloatImage();
1166 to=clipboardME->getMapCenter()->getLastFloatImage();
1169 from=(FloatImageObj*)(selection);
1172 // select data in clipboard
1173 clipboardME->select ("fi:0");
1175 // repositioning makes testing nicer,
1176 // but is not needed usually:
1177 if (clipboardME->isVisible())
1179 clipboardME->getMapCenter()->reposition();
1182 clipboardME->hide();
1188 LinkableMapObj* MapEditor::pasteNoSave()
1190 // Finish open lineEdits
1191 if (lineedit) finishedLineEditNoSave();
1193 LinkableMapObj *fromLMO=clipboardME->getSelection();
1194 LinkableMapObj *returnLMO=NULL;
1196 if (selection && fromLMO)
1199 if (typeid(*fromLMO) == typeid(BranchObj) )
1201 if (typeid(*selection) == typeid(MapCenterObj))
1203 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1204 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1206 if (typeid(*selection) == typeid(BranchObj))
1207 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1210 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1211 (typeid(*selection) == typeid (BranchObj) ||
1212 typeid(*selection)==typeid(MapCenterObj)) )
1213 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1219 void MapEditor::cutNoSave()
1221 // Finish open lineEdits
1222 if (lineedit) finishedLineEditNoSave();
1226 if (selection != NULL) {
1227 if (typeid(*selection) == typeid(BranchObj) )
1229 bo=(BranchObj*)(selection);
1230 par=(BranchObj*)(bo->getParObj());
1233 par->removeBranch(bo);
1235 selection->select();
1237 if (typeid(*selection) == typeid(FloatImageObj) )
1239 FloatImageObj* fio=(FloatImageObj*)(selection);
1240 par=(BranchObj*)(fio->getParObj());
1243 par->removeFloatImage(fio);
1245 selection->select();
1250 void MapEditor::paste()
1253 saveState(PartOfMap,selection);
1255 mapCenter->reposition();
1259 void MapEditor::cut()
1262 saveState(PartOfMap,selection->getParObj());
1265 mapCenter->reposition();
1269 void MapEditor::moveBranchUp()
1271 // Finish open lineEdits
1272 if (lineedit) finishedLineEditNoSave();
1276 if (typeid(*selection) == typeid(BranchObj) )
1279 saveState(PartOfMap,selection->getParObj());
1280 bo=(BranchObj*)(selection);
1281 par=(BranchObj*)(bo->getParObj());
1282 selection->unselect();
1283 selection=par->moveBranchUp (bo);
1284 selection->select();
1285 mapCenter->reposition();
1286 ensureSelectionVisible();
1290 void MapEditor::moveBranchDown()
1292 // Finish open lineEdits
1293 if (lineedit) finishedLineEditNoSave();
1297 if (typeid(*selection) == typeid(BranchObj) )
1300 saveState(PartOfMap,selection->getParObj());
1301 bo=(BranchObj*)(selection);
1302 par=(BranchObj*)(bo->getParObj());
1303 selection->unselect();
1304 selection=par->moveBranchDown(bo);
1305 selection->select();
1306 mapCenter->reposition();
1307 ensureSelectionVisible();
1311 void MapEditor::editHeading()
1313 // Finish open lineEdits
1314 if (lineedit) finishedLineEditNoSave();
1317 (typeid(*selection) == typeid(BranchObj) ||
1318 typeid(*selection) == typeid(MapCenterObj) ) )
1321 saveState(PartOfMap,selection);
1323 ensureSelectionVisible();
1324 editingBO=(BranchObj*)(selection);
1325 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1326 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1327 QString s=editingBO->getHeading();
1328 lineedit->setText(s);
1329 lineedit->setCursorPosition(1);
1330 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1331 lineedit->selectAll();
1334 lineedit->grabKeyboard();
1335 lineedit->setFocus();
1340 void MapEditor::addNewBranch(int pos)
1342 // Finish open lineEdits
1343 if (lineedit) finishedLineEditNoSave();
1346 (typeid(*selection) == typeid(BranchObj) ||
1347 typeid(*selection) == typeid(MapCenterObj) ) )
1350 saveState(PartOfMap,selection);
1352 BranchObj* bo1 = (BranchObj*) (selection);
1353 bool wasScrolled=false;
1354 BranchObj *newbo=NULL;
1357 // save scroll state. If scrolled, automatically select
1358 // new branch in order to tmp unscroll parent...
1359 wasScrolled=bo1->isScrolled();
1360 newbo=bo1->addBranch();
1363 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1367 // add above selection
1368 newbo=parbo->insertBranch(bo1->getNum());
1370 // add below selection
1371 newbo=parbo->insertBranch(bo1->getNum()+1);
1373 // This should not happen...
1378 LinkableMapObj *oldselection=selection;
1380 mapCenter->reposition();
1382 if (actionSettingsAutoedit->isOn() ||
1383 actionSettingsAutoselectHeading->isOn() )
1385 selection->unselect();
1387 selection->select();
1388 if (actionSettingsPasteNewHeading->isOn() )
1390 BranchObj *bo2= (BranchObj*)(selection);
1391 bo2->setHeading("");
1393 if (actionSettingsAutoedit->isOn() )
1395 if (!actionSettingsAutoselectHeading->isOn()
1398 selection->unselect();
1399 selection=oldselection;
1400 selection->select();
1406 void MapEditor::deleteSelection()
1408 // Finish open lineEdits
1409 if (lineedit) finishedLineEditNoSave();
1411 if (selection && typeid(*selection) ==typeid(BranchObj) )
1414 saveState(PartOfMap,selection->getParObj());
1415 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1416 BranchObj* par=(BranchObj*)(bo->getParObj());
1419 par->removeBranch(bo);
1421 selection->select();
1422 ensureSelectionVisible();
1423 mapCenter->reposition();
1426 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1429 saveState(PartOfMap,selection->getParObj());
1430 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1431 BranchObj* par=(BranchObj*)(fio->getParObj());
1434 par->removeFloatImage(fio);
1436 selection->select();
1437 ensureSelectionVisible();
1438 mapCenter->reposition();
1443 LinkableMapObj* MapEditor::getSelection()
1448 LinkableMapObj* MapEditor::findObj (QString s)
1450 LinkableMapObj *lmo=mapCenter;
1454 while (!s.isEmpty() )
1456 part=s.section(",",0,0);
1458 num=part.right(part.length() - 3);
1465 lmo=mapCenter->getBranchNum (num.toUInt());
1468 lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt());
1471 lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
1474 if (s.contains(","))
1475 s=s.right(s.length() - part.length() -1 );
1482 bool MapEditor::select (const QString &s)
1484 LinkableMapObj *lmo=findObj(s);
1486 // Finally select the found object
1489 if (selection) selection->unselect();
1491 selection->select();
1493 ensureSelectionVisible();
1499 void MapEditor::unselect()
1503 selectionLast=selection;
1504 selection->unselect();
1509 void MapEditor::reselect()
1513 selection=selectionLast;
1514 selection->select();
1519 void MapEditor::selectNextBranch()
1521 // Increase number of branch
1524 QString s=selection->getSelectString();
1530 part=s.section(",",-1);
1532 num=part.right(part.length() - 3);
1534 s=s.left (s.length() -num.length());
1537 num=QString ("%1").arg(num.toUInt()+1);
1541 // Try to select this one
1542 if (select (s)) return;
1544 // We have no direct successor,
1545 // try to increase the parental number in order to
1546 // find a successor with same depth
1548 int d=selection->getDepth();
1553 while (!found && d>0)
1555 s=s.section (",",0,d-1);
1556 // replace substring of current depth in s with "1"
1557 part=s.section(",",-1);
1559 num=part.right(part.length() - 3);
1563 // increase number of parent
1564 num=QString ("%1").arg(num.toUInt()+1);
1565 s=s.section (",",0,d-2) + ","+ typ+num;
1568 // Special case, look at orientation
1569 if (selection->getOrientation()==OrientRightOfCenter)
1570 num=QString ("%1").arg(num.toUInt()+1);
1572 num=QString ("%1").arg(num.toUInt()-1);
1577 // pad to oldDepth, select the first branch for each depth
1578 for (i=d;i<oldDepth;i++)
1583 if ( ((BranchObj*)(selection))->countBranches()>0)
1591 // try to select the freshly built string
1599 void MapEditor::selectPrevBranch()
1601 // Decrease number of branch
1604 QString s=selection->getSelectString();
1610 part=s.section(",",-1);
1612 num=part.right(part.length() - 3);
1614 s=s.left (s.length() -num.length());
1617 num=QString ("%1").arg(num.toUInt()-1);
1621 // Try to select this one
1622 if (select (s)) return;
1624 // We have no direct precessor,
1625 // try to decrease the parental number in order to
1626 // find a precessor with same depth
1628 int d=selection->getDepth();
1633 while (!found && d>0)
1635 s=s.section (",",0,d-1);
1636 // replace substring of current depth in s with "1"
1637 part=s.section(",",-1);
1639 num=part.right(part.length() - 3);
1643 // decrease number of parent
1644 num=QString ("%1").arg(num.toUInt()-1);
1645 s=s.section (",",0,d-2) + ","+ typ+num;
1648 // Special case, look at orientation
1649 if (selection->getOrientation()==OrientRightOfCenter)
1650 num=QString ("%1").arg(num.toUInt()-1);
1652 num=QString ("%1").arg(num.toUInt()+1);
1657 // pad to oldDepth, select the last branch for each depth
1658 for (i=d;i<oldDepth;i++)
1662 if ( ((BranchObj*)(selection))->countBranches()>0)
1663 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1670 // try to select the freshly built string
1678 void MapEditor::selectUpperBranch()
1680 // Finish open lineEdits
1681 if (lineedit) finishedLineEditNoSave();
1685 if (typeid(*selection) == typeid(BranchObj))
1687 if (selection->getOrientation()==OrientRightOfCenter)
1690 if (selection->getDepth()==1)
1698 void MapEditor::selectLowerBranch()
1700 // Finish open lineEdits
1701 if (lineedit) finishedLineEditNoSave();
1705 if (typeid(*selection) == typeid(BranchObj))
1707 if (selection->getOrientation()==OrientRightOfCenter)
1710 if (selection->getDepth()==1)
1719 void MapEditor::selectLeftBranch()
1721 // Finish open lineEdits
1722 if (lineedit) finishedLineEditNoSave();
1728 if (typeid(*selection) == typeid(MapCenterObj))
1730 par= (BranchObj*) (selection);
1731 bo=par->getLastSelectedBranch();
1734 // Workaround for reselecting on left and right side
1735 if (bo->getOrientation()==OrientRightOfCenter)
1737 bo=par->getLastBranch();
1743 selection->select();
1745 ensureSelectionVisible();
1750 par=(BranchObj*)(selection->getParObj());
1751 if (selection->getOrientation()==OrientRightOfCenter)
1753 if (typeid(*selection) == typeid(BranchObj) ||
1754 typeid(*selection) == typeid(FloatImageObj))
1756 selection->unselect();
1758 selection->select();
1760 ensureSelectionVisible();
1764 if (typeid(*selection) == typeid(BranchObj) )
1766 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1769 selection->unselect();
1771 selection->select();
1773 ensureSelectionVisible();
1781 void MapEditor::selectRightBranch()
1783 // Finish open lineEdits
1784 if (lineedit) finishedLineEditNoSave();
1791 if (typeid(*selection) == typeid(MapCenterObj))
1793 par= (BranchObj*) (selection);
1794 bo=par->getLastSelectedBranch();
1797 // Workaround for relecting on left and right side
1798 if (bo->getOrientation()==OrientLeftOfCenter)
1799 bo=par->getFirstBranch();
1804 selection->select();
1805 ensureSelectionVisible();
1810 par=(BranchObj*)(selection->getParObj());
1811 if (selection->getOrientation()==OrientLeftOfCenter)
1813 if (typeid(*selection) == typeid(BranchObj) ||
1814 typeid(*selection) == typeid(FloatImageObj))
1816 selection->unselect();
1818 selection->select();
1820 ensureSelectionVisible();
1824 if (typeid(*selection) == typeid(BranchObj) )
1826 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1829 selection->unselect();
1831 selection->select();
1833 ensureSelectionVisible();
1841 void MapEditor::selectFirstBranch()
1843 // Finish open lineEdits
1844 if (lineedit) finishedLineEditNoSave();
1850 if (typeid(*selection) == typeid(BranchObj))
1852 bo1= (BranchObj*) (selection);
1853 par=(BranchObj*)(bo1->getParObj());
1854 bo2=par->getFirstBranch();
1858 selection->select();
1859 ensureSelectionVisible();
1866 void MapEditor::selectLastBranch()
1868 // Finish open lineEdits
1869 if (lineedit) finishedLineEditNoSave();
1875 if (typeid(*selection) == typeid(BranchObj))
1877 bo1= (BranchObj*) (selection);
1878 par=(BranchObj*)(bo1->getParObj());
1879 bo2=par->getLastBranch();
1883 selection->select();
1884 ensureSelectionVisible();
1891 void MapEditor::setColor(QColor c)
1896 void MapEditor::selectBackgroundColor()
1898 // Finish open lineEdits
1899 if (lineedit) finishedLineEditNoSave();
1901 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
1902 if ( !col.isValid() ) return;
1903 setBackgroundColor( col );
1907 void MapEditor::setBackgroundColor(QColor c)
1909 mapCanvas->setBackgroundColor (c);
1912 QColor MapEditor::pickColor()
1916 if (typeid(*selection) == typeid(BranchObj) ||
1917 typeid(*selection) == typeid(MapCenterObj))
1919 BranchObj *bo=(BranchObj*)(selection);
1920 actColor=bo->getColor();
1926 void MapEditor::colorItem()
1930 if (typeid(*selection) == typeid(BranchObj) ||
1931 typeid(*selection) == typeid(MapCenterObj))
1934 saveState(PartOfMap,selection);
1935 BranchObj *bo=(BranchObj*)(selection);
1936 bo->setColor(actColor, false); // color links, color childs
1941 void MapEditor::colorBranch()
1945 if (typeid(*selection) == typeid(BranchObj) ||
1946 typeid(*selection) == typeid(MapCenterObj))
1949 saveState(PartOfMap,selection);
1950 BranchObj *bo=(BranchObj*)(selection);
1951 bo->setColor(actColor, true); // color links, color childs
1957 void MapEditor::toggleStandardFlag(QString f)
1962 saveState(PartOfMap,selection);
1963 ((BranchObj*)(selection))->toggleStandardFlag (f);
1967 void MapEditor::setViewCenter()
1969 // transform to CanvasView Coord:
1970 QPoint p=worldMatrix().map(movingCenter);
1971 center ( p.x(), p.y());
1975 BranchObj* MapEditor::findText (QString s, bool cs)
1978 { // Nothing found or new find process
1980 // nothing found, start again
1982 itFind=mapCenter->first();
1984 bool searching=true;
1985 bool foundNote=false;
1986 while (searching && !EOFind)
1990 // Searching in Note
1991 if (itFind->getNote().contains(s,cs))
1993 if (selection!=itFind)
1995 if (selection) ((BranchObj*)(selection))->unselect();
1997 selection->select();
1999 ensureSelectionVisible();
2001 if (textEditor->findText(s,cs))
2007 // Searching in Heading
2008 if (searching && itFind->getHeading().contains (s,cs) )
2010 if (selection) ((BranchObj*)(selection))->unselect();
2012 selection->select();
2014 ensureSelectionVisible();
2020 itFind=itFind->next();
2021 if (!itFind) EOFind=true;
2027 return (BranchObj*)(selection);
2032 void MapEditor::findReset()
2033 { // Necessary if text to find changes during a find process
2038 void MapEditor::openURL()
2042 if (typeid(*selection) == typeid(BranchObj) ||
2043 typeid(*selection) == typeid(MapCenterObj))
2045 QString url=((BranchObj*)(selection))->getURL();
2047 QProcess *proc = new QProcess( this );
2049 #if !defined(Q_OS_MACX)
2050 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2052 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2053 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2056 proc->addArgument( url);
2058 if ( !proc->start() )
2060 if (mainWindow->settingsURL() )
2066 void MapEditor::editURL()
2068 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2069 typeid(*selection) == typeid(MapCenterObj)) )
2072 QString text = QInputDialog::getText(
2073 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2074 ((BranchObj*)(selection))->getURL(), &ok, this );
2077 // user entered something and pressed OK
2078 ((BranchObj*)(selection))->setURL (text);
2085 void MapEditor::editHeading2URL()
2087 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2088 typeid(*selection) == typeid(MapCenterObj)) )
2090 BranchObj *b=(BranchObj*)(selection);
2091 b->setURL (b->getHeading());
2097 void MapEditor::editBugzilla2URL()
2099 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2100 typeid(*selection) == typeid(MapCenterObj)) )
2102 BranchObj *b=(BranchObj*)(selection);
2103 b->setURL ("http://bugzilla.suse.de/show_bug.cgi?id="+b->getHeading());
2104 b->setURL ("https://bugzilla.innerweb.novell.com/show_bug.cgi?id="+b->getHeading());
2110 void MapEditor::editVymLink()
2112 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2113 typeid(*selection) == typeid(MapCenterObj)) )
2115 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2116 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2117 fd->setCaption(tr("VYM - Link to another map"));
2118 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2119 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2123 if ( fd->exec() == QDialog::Accepted )
2124 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2126 mapCenter->reposition();
2133 void MapEditor::deleteVymLink()
2135 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2136 typeid(*selection) == typeid(MapCenterObj)) )
2138 ((BranchObj*)(selection))->setVymLink ("" );
2140 mapCenter->reposition();
2147 QString MapEditor::getVymLink()
2149 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2150 typeid(*selection) == typeid(MapCenterObj)) )
2152 return ((BranchObj*)(selection))->getVymLink();
2158 void MapEditor::editMapInfo()
2160 ExtraInfoDialog dia;
2161 dia.setMapName (getFileName() );
2162 dia.setAuthor (mapCenter->getAuthor() );
2163 dia.setComment(mapCenter->getComment() );
2168 QCanvasItemList l=canvas()->allItems();
2169 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2171 stats+=QString ("%1 items on canvas\n").arg (i,6);
2177 bo=mapCenter->first();
2180 if (!bo->getNote().isEmpty() ) n++;
2181 f+= bo->countFloatImages();
2185 stats+=QString ("%1 branches\n").arg (b-1,6);
2186 stats+=QString ("%1 notes\n").arg (n,6);
2187 stats+=QString ("%1 images\n").arg (f,6);
2188 dia.setStats (stats);
2190 // Finally show dialog
2191 if (dia.exec() == QDialog::Accepted)
2193 mapCenter->setAuthor (dia.getAuthor() );
2194 mapCenter->setComment (dia.getComment() );
2199 void MapEditor::updateActions()
2201 if (getLinkColorHint()==HeadingColor)
2202 actionFormatLinkColorHint->setOn(true);
2204 actionFormatLinkColorHint->setOn(false);
2209 actionFormatLinkStyleLine->setOn(true);
2212 actionFormatLinkStyleParabel->setOn(true);
2215 actionFormatLinkStylePolyLine->setOn(true);
2217 case StylePolyParabel:
2218 actionFormatLinkStylePolyParabel->setOn(true);
2224 QPixmap pix( 16, 16 );
2225 pix.fill( mapCanvas->backgroundColor() );
2226 actionFormatBackColor->setIconSet( pix );
2227 pix.fill( deflinkcolor );
2228 actionFormatLinkColor->setIconSet( pix );
2230 actionEditUndo->setEnabled( mapChanged );
2231 actionFileSave->setEnabled( mapUnsaved );
2235 if ( (typeid(*selection) == typeid(BranchObj)) ||
2236 (typeid(*selection) == typeid(MapCenterObj)) )
2238 BranchObj *bo=(BranchObj*)(selection);
2239 // Take care of links
2240 if (bo->countLinks()==0)
2242 branchLinksContextMenu->clear();
2243 branchLinksContextMenu->insertItem ("No link available");
2249 branchLinksContextMenu->clear();
2250 for (int i=0; i<=bo->countLinks();i++)
2252 bot=bo->linkTargetAt(i);
2255 s=bot->getHeading();
2258 branchLinksContextMenu->insertItem (s);
2263 standardFlagsDefault->setEnabled (true);
2265 if ( bo->getURL().isEmpty() )
2266 actionEditOpenURL->setEnabled (false);
2268 actionEditOpenURL->setEnabled (true);
2269 actionEditURL->setEnabled (true);
2270 actionEditHeading2URL->setEnabled (true);
2271 actionEditBugzilla2URL->setEnabled (true);
2273 if ( bo->getVymLink().isEmpty() )
2275 actionEditOpenVymLink->setEnabled (false);
2276 actionEditDeleteVymLink->setEnabled (false);
2279 actionEditOpenVymLink->setEnabled (true);
2280 actionEditDeleteVymLink->setEnabled (true);
2282 actionEditVymLink->setEnabled (true);
2284 actionEditCopy->setEnabled (true);
2285 actionEditCut->setEnabled (true);
2286 actionEditPaste->setEnabled (true);
2287 actionEditMoveUp->setEnabled (true);
2288 actionEditMoveDown->setEnabled (true);
2289 actionEditToggleScroll->setEnabled (true);
2290 actionEditHeading->setEnabled (true);
2291 actionEditDelete->setEnabled (true);
2292 actionEditAddBranch->setEnabled (true);
2293 actionEditAddBranchAbove->setEnabled (true);
2294 actionEditAddBranchBelow->setEnabled (true);
2295 actionEditImportAdd->setEnabled (true);
2296 actionEditImportReplace->setEnabled (true);
2297 actionEditSaveBranch->setEnabled (true);
2298 actionEditSelectFirst->setEnabled (true);
2299 actionEditSelectLast->setEnabled (true);
2300 actionEditToggleFloatExport->setEnabled (false);
2301 actionFormatPickColor->setEnabled (true);
2302 actionFormatColorBranch->setEnabled (true);
2303 actionFormatColorSubtree->setEnabled (true);
2304 switch (selection->getFrameType())
2307 actionFormatFrameNone->setOn(true);
2310 actionFormatFrameRectangle->setOn(true);
2316 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2318 standardFlagsDefault->setEnabled (false);
2320 actionEditOpenURL->setEnabled (false);
2321 actionEditURL->setEnabled (false);
2322 actionEditHeading2URL->setEnabled (false);
2323 actionEditBugzilla2URL->setEnabled (false);
2324 actionEditOpenVymLink->setEnabled (false);
2325 actionEditVymLink->setEnabled (false);
2326 actionEditDeleteVymLink->setEnabled (false);
2328 actionEditCopy->setEnabled (true);
2329 actionEditCut->setEnabled (true);
2330 actionEditPaste->setEnabled (false); //FIXME
2331 actionEditMoveUp->setEnabled (false);
2332 actionEditMoveDown->setEnabled (false);
2333 actionEditToggleScroll->setEnabled (false);
2334 actionEditHeading->setEnabled (false);
2335 actionEditDelete->setEnabled (true);
2336 actionEditAddBranch->setEnabled (false);
2337 actionEditAddBranchAbove->setEnabled (false);
2338 actionEditAddBranchBelow->setEnabled (false);
2339 actionEditImportAdd->setEnabled (false);
2340 actionEditSaveBranch->setEnabled (false);
2341 actionEditImportReplace->setEnabled (false);
2342 actionEditSelectFirst->setEnabled (false);
2343 actionEditSelectLast->setEnabled (false);
2344 actionEditToggleFloatExport->setOn
2345 ( ((FloatImageObj*)(selection))->getFloatExport() );
2346 actionFormatPickColor->setEnabled (false);
2347 actionFormatColorBranch->setEnabled (false);
2348 actionFormatColorSubtree->setEnabled (false);
2353 standardFlagsDefault->setEnabled (false);
2355 actionEditCopy->setEnabled (false);
2356 actionEditCut->setEnabled (false);
2357 actionEditPaste->setEnabled (false);
2358 actionEditMoveUp->setEnabled (false);
2359 actionEditMoveDown->setEnabled (false);
2360 actionEditToggleScroll->setEnabled (false);
2361 actionEditOpenURL->setEnabled (false);
2362 actionEditURL->setEnabled (false);
2363 actionEditOpenVymLink->setEnabled (false);
2364 actionEditVymLink->setEnabled (false);
2365 actionEditDeleteVymLink->setEnabled (false);
2366 actionEditHeading2URL->setEnabled (false);
2367 actionEditBugzilla2URL->setEnabled (false);
2368 actionEditHeading->setEnabled (false);
2369 actionEditDelete->setEnabled (false);
2370 actionEditAddBranch->setEnabled (false);
2371 actionEditAddBranchAbove->setEnabled (false);
2372 actionEditAddBranchBelow->setEnabled (false);
2373 actionEditSaveBranch->setEnabled (false);
2374 actionEditImportReplace->setEnabled (false);
2375 actionEditSelectFirst->setEnabled (false);
2376 actionEditSelectLast->setEnabled (false);
2377 actionEditToggleFloatExport->setEnabled (false);
2378 actionFormatPickColor->setEnabled (false);
2379 actionFormatColorBranch->setEnabled (false);
2380 actionFormatColorSubtree->setEnabled (false);
2384 void MapEditor::setLinkStyle (LinkStyle ls)
2389 bo=mapCenter->first();
2393 bo->setLinkStyle(bo->getDefLinkStyle());
2400 LinkStyle MapEditor::getLinkStyle ()
2405 void MapEditor::setLinkColor(QColor c)
2411 void MapEditor::setLinkColorHint()
2413 // called from setLinkColorHint(lch) or at end of parse
2415 bo=mapCenter->first();
2423 void MapEditor::setLinkColorHint(LinkColorHint lch)
2429 void MapEditor::toggleLinkColorHint()
2431 if (linkcolorhint==HeadingColor)
2432 linkcolorhint=DefaultColor;
2434 linkcolorhint=HeadingColor;
2436 bo=mapCenter->first();
2444 LinkColorHint MapEditor::getLinkColorHint()
2446 return linkcolorhint;
2449 QColor MapEditor::getDefLinkColor()
2451 return deflinkcolor;
2454 void MapEditor::selectLinkColor()
2456 // Finish open lineEdits
2457 if (lineedit) finishedLineEditNoSave();
2459 QColor col = QColorDialog::getColor( deflinkcolor, this );
2460 if ( !col.isValid() ) return;
2461 setLinkColor( col );
2465 void MapEditor::toggleScroll()
2467 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2469 BranchObj *bo=((BranchObj*)(selection));
2470 if (bo->countBranches()==0) return;
2471 if (bo->getDepth()==0) return;
2473 saveState(PartOfMap,selection);
2480 void MapEditor::unScrollAll()
2483 bo=mapCenter->first();
2486 if (bo->isScrolled()) bo->toggleScroll();
2491 void MapEditor::loadFloatImage ()
2494 (typeid(*selection) == typeid(BranchObj)) ||
2495 (typeid(*selection) == typeid(MapCenterObj)) )
2497 BranchObj *bo=((BranchObj*)(selection));
2499 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2500 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2501 ImagePreview *p =new ImagePreview (fd);
2502 fd->setContentsPreviewEnabled( TRUE );
2503 fd->setContentsPreview( p, p );
2504 fd->setPreviewMode( QFileDialog::Contents );
2505 fd->setCaption(tr("vym - Load image"));
2506 fd->setDir (lastImageDir);
2510 if ( fd->exec() == QDialog::Accepted )
2513 saveState(PartOfMap,selection);
2514 QString fn=fd->selectedFile();
2515 lastImageDir=fn.left(fn.findRev ("/"));
2516 bo->addFloatImage();
2517 // FIXME check if load was successful
2518 bo->getLastFloatImage()->load(fn);
2519 bo->getLastFloatImage()->setOriginalFilename(fn);
2520 mapCenter->reposition();
2527 void MapEditor::saveFloatImage (int item)
2530 (typeid(*selection) == typeid(FloatImageObj)) )
2532 FloatImageObj *fio=((FloatImageObj*)(selection));
2533 const char* fmt = saveImageFormatMenu->text(item);
2535 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2536 fd->addFilter ("PNG (*.png)");
2537 fd->addFilter ("BMP (*.bmp)");
2538 fd->addFilter ("XBM (*.xbm)");
2539 fd->addFilter ("JPG (*.jpg)");
2540 fd->addFilter ("XPM (*.xpm)");
2541 fd->addFilter ("GIF (*.gif)");
2542 fd->addFilter ("PNM (*.pnm)");
2543 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2544 fd->setCaption(tr("vym - Save image as ") + fmt);
2545 fd->setMode( QFileDialog::AnyFile );
2546 fd->setSelection (fio->getOriginalFilename());
2550 if ( fd->exec() == QDialog::Accepted )
2552 if (QFile (fd->selectedFile()).exists() )
2554 QMessageBox mb( "VYM",
2555 tr("The file ") + fd->selectedFile() +
2556 tr(" exists already. "
2557 "Do you want to overwrite it?"),
2558 QMessageBox::Warning,
2559 QMessageBox::Yes | QMessageBox::Default,
2560 QMessageBox::Cancel | QMessageBox::Escape,
2561 QMessageBox::QMessageBox::NoButton );
2563 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2564 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2567 case QMessageBox::Yes:
2570 case QMessageBox::Cancel:
2576 fio->save (fd->selectedFile(),fmt);
2581 void MapEditor::toggleFloatExport()
2584 (typeid(*selection) == typeid(FloatImageObj))||
2585 (typeid(*selection) == typeid(FloatObj)) )
2587 FloatImageObj *fio=((FloatImageObj*)(selection));
2588 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2592 void MapEditor::setFrame(const FrameType &t)
2595 (typeid(*selection) == typeid(BranchObj)) ||
2596 (typeid(*selection) == typeid(MapCenterObj)) )
2598 selection->setFrameType (t);
2599 mapCenter->reposition();
2600 selection->updateLink();
2604 void MapEditor::importDir(BranchObj *dst, QDir d)
2607 (typeid(*selection) == typeid(BranchObj)) ||
2608 (typeid(*selection) == typeid(MapCenterObj)) )
2612 // Traverse directories
2613 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2614 const QFileInfoList *dirlist = d.entryInfoList();
2615 QFileInfoListIterator itdir( *dirlist );
2618 while ( (fi = itdir.current()) != 0 )
2620 if (fi->fileName() != "." && fi->fileName() != ".." )
2623 bo=dst->getLastBranch();
2624 bo->setHeading (fi->fileName() );
2625 bo->setColor (QColor("blue"),false);
2627 if ( !d.cd(fi->fileName()) )
2628 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2638 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2639 const QFileInfoList *filelist = d.entryInfoList();
2640 QFileInfoListIterator itfile( *filelist );
2642 while ( (fi = itfile.current()) != 0 )
2645 bo=dst->getLastBranch();
2646 bo->setHeading (fi->fileName() );
2647 bo->setColor (QColor("black"),false);
2653 void MapEditor::importDir()
2656 (typeid(*selection) == typeid(BranchObj)) ||
2657 (typeid(*selection) == typeid(MapCenterObj)) )
2659 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2660 fd->setMode (QFileDialog::DirectoryOnly);
2661 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2662 fd->setCaption(tr("VYM - Choose directory structur to import"));
2666 if ( fd->exec() == QDialog::Accepted )
2668 BranchObj *bo=((BranchObj*)(selection));
2669 importDir (bo,QDir(fd->selectedFile()) );
2670 mapCenter->reposition();
2677 void MapEditor::followLink(int i)
2679 BranchObj *bo=((BranchObj*)(selection))->linkTargetAt(i);
2682 selection->unselect();
2684 selection->select();
2685 ensureSelectionVisible();
2689 void MapEditor::testFunction()
2691 cout << "MapEditor::testFunction() called\n";
2693 (typeid(*selection) == typeid(BranchObj) ||
2694 typeid(*selection) == typeid(MapCenterObj) ) )
2696 BranchObj *bo=(BranchObj*)(selection);
2697 QPoint p = worldMatrix().map(QPoint (bo->x(),bo->y()));
2698 // lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
2699 QPopupMenu *popupLinks=new QPopupMenu (this);
2700 if (bo->countLinks()==0)
2702 popupLinks->clear();
2703 popupLinks->insertItem ("No link available");
2709 popupLinks->clear();
2710 for (int i=0; i<=bo->countLinks();i++)
2712 bot=bo->linkTargetAt(i);
2715 s=bot->getHeading();
2718 popupLinks->insertItem (s);
2727 void MapEditor::ensureSelectionVisible()
2729 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2731 if (selection->getOrientation() == OrientLeftOfCenter)
2732 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2734 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2735 ensureVisible (p.x(), p.y() );
2739 void MapEditor::updateViewCenter()
2741 // Update movingCenter, so that we can zoom comfortably later
2742 QRect rc = QRect( contentsX(), contentsY(),
2743 visibleWidth(), visibleHeight() );
2744 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2745 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2746 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2749 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2751 // Lineedits are already closed by preceding
2752 // mouseEvent, we don't need to close here.
2754 QPoint p = inverseWorldMatrix().map(e->pos());
2755 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2758 { // MapObj was found
2759 if (selection != lmo)
2761 // select the MapObj
2762 if (selection) selection->unselect();
2764 selection->select();
2770 if (typeid(*selection)==typeid(BranchObj) ||
2771 typeid(*selection)==typeid(MapCenterObj) )
2773 // Context Menu on branch or mapcenter
2775 branchContextMenu->popup(e->globalPos() );
2777 if (typeid(*selection)==typeid(FloatImageObj))
2779 // Context Menu on floatimage
2781 floatimageContextMenu->popup(e->globalPos() );
2785 { // No MapObj found, we are on the Canvas itself
2786 // Context Menu on Canvas
2788 canvasContextMenu->popup(e->globalPos() );
2792 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2794 // Finish open lineEdits
2795 if (lineedit) finishedLineEditNoSave();
2797 QPoint p = inverseWorldMatrix().map(e->pos());
2798 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2800 // Special case: CTRL is pressed
2801 if (e->state() & QMouseEvent::ControlButton)
2803 if (actionModModeColor->isOn())
2805 if (e->state() & QMouseEvent::ControlButton)
2808 setCursor (pickColorCursor);
2812 if (actionModModeLink->isOn())
2814 BranchObj *bo_begin=NULL;
2816 bo_begin=(BranchObj*)(lmo);
2819 ((typeid(*selection) == typeid(BranchObj)) ||
2820 (typeid(*selection) == typeid(MapCenterObj))) )
2821 bo_begin=(BranchObj*)(selection);
2825 linkingObj_src=bo_begin;
2826 tmpLink=new LinkObj (mapCanvas);
2827 tmpLink->setBegin (bo_begin);
2828 tmpLink->setEnd (p);
2829 tmpLink->updateLink();
2830 tmpLink->setVisibility (true);
2837 { // MapObj was found
2838 if (selection != lmo)
2840 // select the MapObj
2841 if (selection) selection->unselect();
2843 selection->select();
2849 // Check, if systemFlag clicked
2850 if (typeid(*selection)==typeid(BranchObj) ||
2851 typeid(*selection)==typeid(MapCenterObj) )
2853 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
2854 if (!foname.isEmpty())
2856 // Do not move, if systemFlag clicked
2860 if (foname=="vymLink")
2862 mainWindow->editOpenVymLink();
2863 // tabWidget may change, better return now
2864 // before segfaulting...
2868 mainWindow->windowToggleNoteEditor();
2872 // Left Button Move Branches
2873 if (e->button() == QMouseEvent::LeftButton )
2875 // If modMode==copy, then we want to "move" the _new_ object around
2876 // then we need the offset from p to the _old_ selection, because of tmp
2877 if (actionModModeCopy->isOn() &&
2878 e->state() & QMouseEvent::ControlButton)
2880 if (typeid(*selection)==typeid(BranchObj) )
2883 movingObj_start.setX( p.x() - selection->x() );
2884 movingObj_start.setY( p.y() - selection->y() );
2885 mapCenter->addBranch ((BranchObj*)(selection));
2887 selection=mapCenter->getLastBranch();
2888 selection->select();
2889 selection->setParObjTmp ((BranchObj*)(selection),p,1);
2890 selection->updateLink();
2894 movingObj_start.setX( p.x() - selection->x() );
2895 movingObj_start.setY( p.y() - selection->y() );
2898 movingObj=selection;
2900 // Middle Button Toggle Scroll
2901 // (On Mac OS X this won't work, but we still have
2902 // a button in the toolbar)
2903 if (e->button() == QMouseEvent::MidButton )
2907 { // No MapObj found, we are on the Canvas itself
2908 // Left Button move Pos of CanvasView
2909 if (e->button() == QMouseEvent::LeftButton )
2911 movingObj=NULL; // move Content not Obj
2912 movingObj_start=e->globalPos();
2913 movingCont_start=QPoint (contentsX(), contentsY() );
2914 movingVec=QPoint(0,0);
2915 setCursor(handOpenCursor);
2920 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
2922 QPoint p = inverseWorldMatrix().map(e->pos());
2924 // Move the selected MapObj
2925 if ( selection && movingObj)
2927 ensureVisible (p.x(),p.y());
2929 // Now move the selection, but add relative position
2930 // (movingObj_start) where selection was chosen with
2931 // mousepointer. (This avoids flickering resp. jumping
2932 // of selection back to absPos)
2934 LinkableMapObj *lmosel;
2935 lmosel = dynamic_cast <LinkableMapObj*> (selection);
2937 // Check if we could link
2938 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
2941 if (typeid(*selection) == typeid(FloatImageObj))
2945 FloatObj *fo=(FloatObj*)(selection);
2946 if (fo->getLinkStyle()==StyleUndef)
2948 fo->setLinkStyle(fo->getDefLinkStyle());
2949 fo->setLinkColor(fo->getParObj()->getLinkColor());
2951 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2955 // Relink float to new mapcenter or branch, if shift is pressed
2956 // Only relink, if selection really has a new parent
2957 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
2958 ( (typeid(*lmo)==typeid(BranchObj)) ||
2959 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
2960 ( lmo != fo->getParObj())
2963 if (typeid(*fo) == typeid(FloatImageObj))
2965 FloatImageObj *fio=(FloatImageObj*)(fo);
2966 ((BranchObj*)(lmo))->addFloatImage (fio);
2968 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
2969 fio=((BranchObj*)(lmo))->getLastFloatImage();
2972 selection=(LinkableMapObj*)(fio);
2973 selection->select();
2974 movingObj=(MapObj*)(fio);
2975 // setLinkStyle calls updateLink, only set it once
2976 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
2977 fio->setLinkStyle (fio->getDefLinkStyle());
2980 // TODO if (typeid(*selection) == typeid(FloatTextObj))
2982 } else // selection != a FloatObj
2984 if (lmosel->getDepth()==0)
2986 if (e->state() == (LeftButton | !ShiftButton))
2987 // If mapCenter is moved, move all the rest by default, too.
2988 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2990 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
2993 if (lmosel->getDepth()==1)
2995 // depth==1, mainbranch
2997 saveState(PartOfMap,lmosel);
2998 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3002 if (lmosel->getOrientation() == OrientLeftOfCenter)
3003 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3004 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3005 p.y()-movingObj_start.y() );
3007 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3009 // reposition subbranch
3010 lmosel->reposition();
3011 //ensureSelectionVisible();
3013 if (lmo && (lmo!=selection) &&
3014 (typeid(*lmo) == typeid(BranchObj) ||
3015 (typeid(*lmo) == typeid(MapCenterObj) )
3018 if (e->state() & QMouseEvent::ControlButton)
3020 // Special case: CTRL to link below lmo
3021 lmosel->setParObjTmp (lmo,p,+1);
3023 else if (e->state() & QMouseEvent::ShiftButton)
3024 lmosel->setParObjTmp (lmo,p,-1);
3026 lmosel->setParObjTmp (lmo,p,0);
3029 lmosel->unsetParObjTmp();
3031 if (lmo &&(lmo==selection))
3032 // Could link to myself (happens sometimes...)
3033 lmosel->unsetParObjTmp();
3035 // no Obj under selection, go back to original Parent
3036 lmosel->unsetParObjTmp();
3041 } // no FloatImageObj
3045 } // selection && moving_obj
3047 // Draw a link from one branch to another
3050 tmpLink->setEnd (p);
3051 tmpLink->updateLink();
3055 if (!movingObj && !pickingColor &&!drawingLink)
3057 QPoint p=e->globalPos();
3058 movingVec.setX(-p.x() + movingObj_start.x() );
3059 movingVec.setY(-p.y() + movingObj_start.y() );
3060 setContentsPos( movingCont_start.x() + movingVec.x(),
3061 movingCont_start.y() + movingVec.y());
3068 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3070 LinkableMapObj *dst;
3071 // Have we been picking color?
3075 setCursor (ArrowCursor);
3076 // Check if we are over another branch
3077 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3078 if (dst && selection)
3080 if (e->state() & QMouseEvent::ShiftButton)
3082 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3083 ((BranchObj*)(selection))->setLinkColor ();
3087 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3088 ((BranchObj*)(selection))->setLinkColor ();
3094 // Have we been drawing a link?
3098 // Check if we are over another branch
3099 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3100 if (dst && selection)
3102 tmpLink->setEnd ( ((BranchObj*)(dst)) );
3103 tmpLink->updateLink();
3104 tmpLink->activate();
3115 // Have we been moving something?
3116 if ( selection && movingObj )
3118 // Check if we are over another branch, but ignore
3119 // any found LMOs, which are FloatObjs
3120 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3121 ((LinkableMapObj*)(selection)) );
3124 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3129 // Now check, if we have been moving a branch
3130 if (typeid(*selection) == typeid(BranchObj) )
3132 // save the position in case we link to mapcenter
3133 QPoint savePos=QPoint (selection->x(),selection->y() );
3135 // Reset the temporary drawn link to the original one
3136 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3143 // remove the current selection, if we have no destination
3144 selection->unselect();
3145 ((BranchObj*)(selection->getParObj()))->removeBranch ((BranchObj*)(selection));
3148 selection=selectionLast;
3150 selection->select();
3158 // TODO we also could check, if dest and src are on same branch,
3159 // then it would be sufficient to saveState of this branch
3161 // Modifiers allow to insert above/below dst
3162 if (e->state() & QMouseEvent::ShiftButton)
3164 ((BranchObj*)(selection))->moveBranchTo
3167 ((BranchObj*)(dst))->getNum()
3169 //if (selection) selection->select();
3171 if (e->state() & QMouseEvent::ControlButton)
3173 ((BranchObj*)(selection))->moveBranchTo
3176 ((BranchObj*)(dst))->getNum()+1
3178 //if (selection) selection->select();
3181 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
3182 if (dst->getDepth()==0)
3183 ((BranchObj*)(selection))->move (savePos);
3186 // Draw the original link, before selection was moved around
3187 mapCenter->reposition();
3189 // Finally resize canvas, if needed
3194 // maybe we moved View: set old cursor
3195 setCursor (ArrowCursor);
3199 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3201 // Finish open lineEdits
3202 if (lineedit) finishedLineEditNoSave();
3204 if (e->button() == QMouseEvent::LeftButton )
3206 QPoint p = inverseWorldMatrix().map(e->pos());
3207 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3208 if (lmo) { // MapObj was found
3209 // First select the MapObj than edit heading
3210 if (selection) selection->unselect();
3212 selection->select();
3214 saveState(PartOfMap,selection);
3220 void MapEditor::resizeEvent (QResizeEvent* e)
3222 QCanvasView::resizeEvent( e );
3225 if (!fileName.isEmpty()) s=fileName;