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>
18 #include <qdragobject.h>
19 #include <qurloperator.h>
20 #include <qnetworkprotocol.h>
30 #include "texteditor.h"
31 #include "linkablemapobj.h"
34 #include "mainwindow.h"
35 #include "extrainfodialog.h"
36 #include "editxlinkdialog.h"
39 #include "icons/flag-note.xpm"
40 #include "icons/flag-url.xpm"
41 #include "icons/flag-vymlink.xpm"
42 #include "icons/flag-scrolled-right.xpm"
43 #include "icons/flag-tmpUnscrolled-right.xpm"
44 #include "icons/flag-questionmark.xpm"
45 #include "icons/flag-exclamationmark.xpm"
46 #include "icons/flag-hook-green.xpm"
47 #include "icons/flag-cross-red.xpm"
48 #include "icons/flag-stopsign.xpm"
49 #include "icons/flag-smiley-good.xpm"
50 #include "icons/flag-smiley-sad.xpm"
51 #include "icons/flag-clock.xpm"
52 #include "icons/flag-lamp.xpm"
53 #include "icons/flag-arrow-up.xpm"
54 #include "icons/flag-arrow-down.xpm"
55 #include "icons/flag-thumb-up.xpm"
56 #include "icons/flag-thumb-down.xpm"
57 #include "icons/flag-heart.xpm"
58 #include "icons/flag-flash.xpm"
59 #include "icons/flag-lifebelt.xpm"
61 extern TextEditor *textEditor;
62 extern int statusbarTime;
63 extern Main *mainWindow;
64 extern FlagRowObj *systemFlagsDefault;
65 extern FlagRowObj *standardFlagsDefault;
66 extern MapEditor *clipboardME;
68 extern QPtrList <QAction> actionListBranches;
70 extern QAction *actionFileSave;
71 extern QAction *actionEditUndo;
72 extern QAction *actionEditCopy;
73 extern QAction *actionEditCut;
74 extern QAction *actionEditPaste;
75 extern QAction *actionEditMoveUp;
76 extern QAction *actionEditMoveDown;
77 extern QAction *actionEditToggleScroll;
78 extern QAction *actionEditOpenURL;
79 extern QAction *actionEditURL;
80 extern QAction *actionEditHeading2URL;
81 extern QAction *actionEditBugzilla2URL;
82 extern QAction *actionEditOpenVymLink;
83 extern QAction *actionEditVymLink;
84 extern QAction *actionEditDeleteVymLink;
85 extern QAction *actionEditHeading;
86 extern QAction *actionEditDelete;
87 extern QAction *actionEditAddBranch;
88 extern QAction *actionEditAddBranchAbove;
89 extern QAction *actionEditAddBranchBelow;
90 extern QAction *actionEditRemoveBranchHere;
91 extern QAction *actionEditRemoveChilds;
92 extern QAction *actionEditImportAdd;
93 extern QAction *actionEditImportReplace;
94 extern QAction *actionEditSaveBranch;
95 extern QAction *actionEditSelectFirst;
96 extern QAction *actionEditSelectLast;
97 extern QAction *actionEditLoadImage;
98 extern QAction *actionEditToggleFloatExport;
100 extern QAction* actionFormatPickColor;
101 extern QAction* actionFormatColorBranch;
102 extern QAction* actionFormatColorSubtree;
103 extern QAction *actionFormatLinkColorHint;
104 extern QAction *actionFormatBackColor;
105 extern QAction *actionFormatLinkColor;
107 extern QActionGroup* actionGroupModModes;
108 extern QAction* actionModModeColor;
109 extern QAction* actionModModeLink;
110 extern QAction* actionModModeCopy;
112 extern QActionGroup *actionGroupFormatFrameTypes;
113 extern QAction *actionFormatFrameNone;
114 extern QAction *actionFormatFrameRectangle;
116 extern QActionGroup *actionGroupFormatLinkStyles;
117 extern QAction *actionFormatLinkStyleLine;
118 extern QAction *actionFormatLinkStyleParabel;
119 extern QAction *actionFormatLinkStylePolyLine;
120 extern QAction *actionFormatLinkStylePolyParabel;
122 extern QAction *actionViewToggleNoteEditor;
124 extern QAction *actionSettingsAutoedit;
125 extern QAction *actionSettingsAutoselectHeading;
126 extern QAction *actionSettingsAutoselectText;
127 extern QAction *actionSettingsPasteNewHeading;
128 extern QAction *actionSettingsUseFlagGroups;
130 extern QPopupMenu *branchContextMenu;
131 extern QPopupMenu *branchLinksContextMenu;
132 extern QPopupMenu *branchLinksContextMenuDup;
133 extern QPopupMenu *floatimageContextMenu;
134 extern QPopupMenu *saveImageFormatMenu;
135 extern QPopupMenu *exportImageFormatMenu;
136 extern QPopupMenu *canvasContextMenu;
138 extern Settings settings;
141 ///////////////////////////////////////////////////////////////////////
142 ///////////////////////////////////////////////////////////////////////
143 MapEditor::MapEditor(
144 QWidget* parent, bool interactive, const char* name, WFlags f) :
145 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
147 //cout << "Constructor ME "<<this<<endl;
149 viewport()->setAcceptDrops(true);
151 mapCanvas = new QCanvas(1000,800);
152 mapCanvas->setAdvancePeriod(30);
154 setCanvas (mapCanvas);
156 setVScrollBarMode ( QScrollView::AlwaysOn );
157 setHScrollBarMode ( QScrollView::AlwaysOn );
159 // Now create the _global_ system flags _once_:
160 // (Later all OrnamentedObj copy from this
161 // and set their own canvas)
162 if (!systemFlagsDefault)
164 systemFlagsDefault = new FlagRowObj (mapCanvas);
165 systemFlagsDefault->setVisibility (false);
166 systemFlagsDefault->setName ("systemFlagsDef");
168 FlagObj *fo = new FlagObj (mapCanvas);
169 fo->load(QPixmap(flag_note_xpm));
171 fo->setToolTip(tr("Note","Systemflag"));
172 systemFlagsDefault->addFlag (fo); // makes deep copy
174 fo->load(QPixmap(flag_url_xpm));
176 fo->setToolTip(tr("WWW Document (external)","Systemflag"));
177 systemFlagsDefault->addFlag (fo);
179 fo->load(QPixmap(flag_vymlink_xpm));
180 fo->setName("vymLink");
181 fo->setToolTip(tr("Link to another vym map","Systemflag"));
182 systemFlagsDefault->addFlag (fo);
184 fo->load(QPixmap(flag_scrolled_right_xpm));
185 fo->setName("scrolledright");
186 fo->setToolTip(tr("subtree is scrolled","Systemflag"));
187 systemFlagsDefault->addFlag (fo);
189 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
190 fo->setName("tmpUnscrolledright");
191 fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
192 systemFlagsDefault->addFlag (fo);
195 if (!standardFlagsDefault)
197 standardFlagsDefault = new FlagRowObj (mapCanvas);
198 standardFlagsDefault->setVisibility (false);
199 standardFlagsDefault->setName ("standardFlagsDef");
201 FlagObj *fo = new FlagObj (mapCanvas);
202 fo->load(QPixmap(flag_exclamationmark_xpm));
203 fo->setName ("exclamationmark");
204 fo->setGroup("standard-mark");
205 fo->setToolTip(tr("Take care!","Standardflag"));
206 standardFlagsDefault->addFlag (fo); // makes deep copy
208 fo->load(QPixmap(flag_questionmark_xpm));
209 fo->setName("questionmark");
210 fo->setGroup("standard-mark");
211 fo->setToolTip(tr("Really?","Standardflag"));
212 standardFlagsDefault->addFlag (fo);
214 fo->load(QPixmap(flag_hook_green_xpm));
215 fo->setName("hook-green");
216 fo->setGroup("standard-hook");
217 fo->setToolTip(tr("ok!","Standardflag"));
218 standardFlagsDefault->addFlag (fo);
220 fo->load(QPixmap(flag_cross_red_xpm));
221 fo->setName("cross-red");
222 fo->setGroup("standard-hook");
223 fo->setToolTip(tr("Not ok!","Standardflag"));
224 standardFlagsDefault->addFlag (fo);
226 fo->load(QPixmap(flag_stopsign_xpm));
227 fo->setName("stopsign");
228 fo->setToolTip(tr("This won't work!","Standardflag"));
229 standardFlagsDefault->addFlag (fo);
231 fo->load(QPixmap(flag_smiley_good_xpm));
232 fo->setName("smiley-good");
233 fo->setGroup("standard-smiley");
234 fo->setToolTip(tr("Good","Standardflag"));
235 standardFlagsDefault->addFlag (fo);
237 fo->load(QPixmap(flag_smiley_sad_xpm));
238 fo->setName("smiley-sad");
239 fo->setGroup("standard-smiley");
240 fo->setToolTip(tr("Bad","Standardflag"));
241 standardFlagsDefault->addFlag (fo);
243 fo->load(QPixmap(flag_clock_xpm));
244 fo->setName("clock");
245 fo->setToolTip(tr("Time critical","Standardflag"));
246 standardFlagsDefault->addFlag (fo);
248 fo->load(QPixmap(flag_lamp_xpm));
250 fo->setToolTip(tr("Idea!","Standardflag"));
251 standardFlagsDefault->addFlag (fo);
253 fo->load(QPixmap(flag_arrow_up_xpm));
254 fo->setName("arrow-up");
255 fo->setGroup("standard-arrow");
256 fo->setToolTip(tr("Important","Standardflag"));
257 standardFlagsDefault->addFlag (fo);
259 fo->load(QPixmap(flag_arrow_down_xpm));
260 fo->setName("arrow-down");
261 fo->setGroup("standard-arrow");
262 fo->setToolTip(tr("Unimportant","Standardflag"));
263 standardFlagsDefault->addFlag (fo);
265 fo->load(QPixmap(flag_thumb_up_xpm));
266 fo->setName("thumb-up");
267 fo->setGroup("standard-thumb");
268 fo->setToolTip(tr("I like this","Standardflag"));
269 standardFlagsDefault->addFlag (fo);
271 fo->load(QPixmap(flag_thumb_down_xpm));
272 fo->setName("thumb-down");
273 fo->setGroup("standard-thumb");
274 fo->setToolTip(tr("I like this","Standardflag"));
275 fo->setToolTip(tr("I do not like this","Standardflag"));
276 standardFlagsDefault->addFlag (fo);
278 fo->load(QPixmap(flag_heart_xpm));
279 fo->setName("heart");
280 fo->setToolTip(tr("I just love... ","Standardflag"));
281 standardFlagsDefault->addFlag (fo);
283 fo->load(QPixmap(flag_flash_xpm));
284 fo->setName("flash");
285 fo->setToolTip(tr("Dangerous","Standardflag"));
286 standardFlagsDefault->addFlag (fo);
288 fo->load(QPixmap(flag_lifebelt_xpm));
289 fo->setName("lifebelt");
290 fo->setToolTip(tr("This will help","Standardflag"));
291 standardFlagsDefault->addFlag (fo);
296 mapCenter = new MapCenterObj(mapCanvas);
297 mapCenter->setVisibility (true);
298 mapCenter->setMapEditor (this);
299 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
303 lineedit = new QLineEdit(this, "lineedit" );
304 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
307 actColor=black; setColor (actColor);
308 defLinkColor=QColor (0,0,255);
309 defXLinkColor=QColor (180,180,180);
310 linkcolorhint=DefaultColor;
311 linkstyle=StylePolyParabel;
312 mapCanvas->setBackgroundColor (white);
314 // Create bitmap cursors, patform dependant
315 #if defined(Q_OS_MACX)
316 #include "icons/cursorhandopen16.xpm"
317 #include "icons/cursorcolorpicker16.xpm"
318 QBitmap cb( 16, 16, chandopen, TRUE );
319 QBitmap cm( 16, 16, chandopenmask, TRUE );
320 handOpenCursor=QCursor ( cb, cm );
321 // set hot spot to tip of picker
322 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
324 #include "icons/cursorhandopen.xpm"
325 #include "icons/cursorcolorpicker.xpm"
327 QBitmap cb( 32, 32, chandopen, TRUE );
328 QBitmap cm( 32, 32, chandopenmask, TRUE );
329 handOpenCursor=QCursor ( cb, cm );
330 // set hot spot to tip of picker
331 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
344 defXLinkColor=QColor (230,230,230);
355 // Initialize find routine
362 blockreposition=false;
363 isInteractive=interactive;
365 // Create temporary files
368 // Initially set movingCentre
371 mapCenter->reposition(); // for positioning heading
374 MapEditor::~MapEditor()
376 if (imageBuffer) delete imageBuffer;
382 //cout <<"Destructor MapEditor\n";
383 if (isInteractive) delTmpDirs();
386 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
390 QColor MapEditor::color()
395 QColor MapEditor::backgroundColor()
397 return mapCanvas->backgroundColor();
400 MapCenterObj* MapEditor::getMapCenter()
405 QCanvas* MapEditor::getCanvas()
410 void MapEditor::adjustCanvasSize()
412 // To adjust the canvas to map, viewport size and position, we have to
413 // do some coordinate magic...
415 // Get rectangle of (scroll-)view.
416 // We want to be in canvas coords, so
417 // we map. Important if view is zoomed...
418 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
419 visibleWidth(), visibleHeight()) );
421 // Now we need the bounding box of view AND map to calc the correct canvas size.
422 // Why? Because if the map itself is moved out of view, the view has to be enlarged
423 // to avoid jumping aroung...
424 QRect map=mapCenter->getTotalBBox();
426 // right edge - left edge
427 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
428 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
431 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
432 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
435 // move the map on canvas (in order to not move it on screen) this is neccessary
436 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
437 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
438 // to scroll to an empty area of canvas to the left.
439 // b) if topleft corner of map left of or above topleft of canvas
443 if (cw > mapCanvas->width() )
445 if (map.x()<0) dx=-map.x();
447 if (cw < mapCanvas->width() )
448 dx=-min (view.x(),map.x());
449 if (ch > mapCanvas->height() )
451 if (map.y()<0) dy=-map.y();
453 if (ch < mapCanvas->height() )
455 dy=-min (view.y(),map.y());
457 // We really have to resize now. Let's go...
458 mapCanvas->resize (cw,ch);
459 if ( (dx!=0) || (dy!=0) )
461 mapCenter->moveAllBy(dx,dy);
462 mapCenter->reposition();
464 // scroll the view (in order to not move map on screen)
470 bool MapEditor::blockReposition()
472 return blockreposition;
475 void MapEditor::makeTmpDirs()
477 // Create unique temporary directories
478 char tmpdir[]="/tmp/vym-XXXXXX";
479 bakMapDir=mkdtemp(tmpdir);
480 makeSubDirs(bakMapDir);
481 // FIXME set permissions and maybe use QT method for portability
484 void MapEditor::delTmpDirs()
486 //FIXME delete tmp directory, better use QT methods here:
487 system ( "rm -rf "+ bakMapDir );
491 void MapEditor::makeSubDirs(const QString &s)
499 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
501 // tmpdir temporary directory to which data will be writte
502 // prefix mapname, which will be appended to images etc.
503 // writeflags Only write flags for "real" save of map, not undo
504 // offset offset of bbox of whole map in canvas.
505 // Needed for XML export
506 // completeMap if false, only vympart will be written, without
523 ls="StylePolyParabel";
527 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
529 if (linkcolorhint==HeadingColor)
530 colhint=attribut("linkColorHint","HeadingColor");
532 QString mapAttr=attribut("version",__VYM_VERSION__);
534 mapAttr+= attribut("author",mapCenter->getAuthor()) +
535 attribut("comment",mapCenter->getComment()) +
536 attribut("date",mapCenter->getDate()) +
537 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
538 attribut("linkStyle", ls ) +
539 attribut("linkColor", defLinkColor.name() ) +
540 attribut("defXLinkColor", defXLinkColor.name() ) +
541 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
543 s+=beginElement("vymmap",mapAttr);
546 // Find the used flags while traversing the tree
547 standardFlagsDefault->resetUsedCounter();
549 // Build xml recursivly
551 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
554 if ( typeid(*saveSelection) == typeid(BranchObj) )
555 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
557 if (selection && typeid(*selection)==typeid(BranchObj))
558 // This is used if selected branch is saved from mainwindow
559 s+=((BranchObj*)(selection))->saveToDir(tmpdir,prefix,offset);
562 // Save local settings
563 s+=settings.getXMLData (destPath);
566 if (selection && !saveSelection)
567 s+=valueElement("select",selection->getSelectString());
570 s+=endElement("vymmap");
573 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
577 void MapEditor::saveState()
579 saveState (CompleteMap,NULL,"");
582 void MapEditor::saveState(LinkableMapObj *undoSel)
584 saveState (PartOfMap,undoSel,"");
587 void MapEditor::saveState(const QString & c)
589 saveState (UndoCommand,NULL,c);
592 void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom)
594 if (savemode==UndoCommand)
599 else if (savemode==PartOfMap && undoSel)
601 undoCommand="undoPart (\""+undoSel->getSelectString()+"\")";
602 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
605 undoCommand="undoMap ()";
606 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
609 cout << "ME::saveState()\n";
610 cout << " undoCom="<<undoCommand<<endl;
614 void MapEditor::parseAtom(const QString &s)
618 api.parseCommand (s,c,p);
621 cout <<"ME::parseAtom s="<<s<<endl;
622 cout <<"ME::parseAtom c="<<c<<endl;
623 cout <<"ME::parseAtom p="<<p<<endl;
627 if (c==QString("moveBranchUp"))
629 else if (c=="moveBranchDown")
631 else if (c=="setHeading")
633 // Internal commands, used for undo etc.
634 else if (c==QString("undoMap"))
636 else if (c==QString("undoPart"))
638 else if (c=="select")
642 cout << "MapEditor::parseAtom: Error!\n";
643 cout << " Command unknown: \""<<c<<"\""<<endl;
644 cout << " Used in atom: \""<<s<<"\""<<endl;
649 void MapEditor::finishedLineEditNoSave()
651 // This is called by finishedLineEdit or any MapEditor method,
652 // which wants to assure, that lineedits finish, before e.g. a branch is
655 // After calling LineEdit and using the clipboard, the
656 // focus is not any longer on the main widget, we
657 // have to restore it using parentWidget()->setFocus()
661 editingBO->setHeading(lineedit->text() );
663 lineedit->releaseKeyboard();
665 parentWidget()->setFocus();
666 mapCenter->reposition();
668 ensureSelectionVisible();
673 bool MapEditor::isDefault()
678 bool MapEditor::isUnsaved()
683 bool MapEditor::hasChanged()
688 void MapEditor::setChanged()
693 actionEditUndo->setEnabled (true);
694 actionFileSave->setEnabled (true);
698 void MapEditor::closeMap()
700 // Finish open lineEdits
701 if (lineedit) finishedLineEditNoSave();
703 // Unselect before disabling the toolbar actions
704 if (selection) selection->unselect();
712 void MapEditor::setFilePath(QString fname)
714 setFilePath (fname,fname);
717 void MapEditor::setFilePath(QString fname, QString destname)
726 filePath=fname; // becomes absolute path
727 fileName=fname; // gets stripped of path
728 destPath=destname; // needed for vymlinks
730 // If fname is not an absolute path, complete it
731 filePath=QDir(fname).absPath();
732 fileDir=filePath.left (1+filePath.findRev ("/"));
734 // Set short name, too. Search from behind:
735 int i=fileName.findRev("/");
736 if (i>=0) fileName=fileName.remove (0,i+1);
738 // Forget the .vym (or .xml) for name of map
739 mapName=fileName.left(fileName.findRev(".",-1,true) );
743 QString MapEditor::getFilePath()
748 QString MapEditor::getFileName()
753 QString MapEditor::getMapName()
758 QString MapEditor::getDestPath()
763 int MapEditor::load (QString &fname, const LoadMode &lmode)
765 // Finish open lineEdits
766 if (lineedit) finishedLineEditNoSave();
772 if (selection) selection->unselect();
775 mapCenter->setMapEditor(this);
776 // (map state is set later at end of load...)
780 saveState(selection);
784 mapBuilderHandler handler;
787 // I am paranoid: file should exist anyway
788 // according to check in mainwindow.
791 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
792 tr("Couldn't open map " +fname)+".");
796 blockreposition=true;
797 QXmlInputSource source( file);
798 QXmlSimpleReader reader;
799 reader.setContentHandler( &handler );
800 reader.setErrorHandler( &handler );
801 handler.setMapEditor( this );
802 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
803 handler.setLoadMode (lmode);
804 bool ok = reader.parse( source );
805 blockreposition=false;
809 mapCenter->reposition();
819 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
820 tr( handler.errorProtocol() ) );
822 // Still return "success": the map maybe at least
823 // partially read by the parser
830 int MapEditor::save (const SaveMode &savemode)
832 // Finish open lineEdits
833 if (lineedit) finishedLineEditNoSave();
837 // The SaveMode UndoCommand is not supported here
838 if (savemode==UndoCommand) return 1;
840 // Create mapName and fileDir
841 makeSubDirs (fileDir);
845 fname=mapName+".xml";
847 // use name given by user, even if he chooses .doc
851 // Check if fname is writeable
852 QFile file( fileDir+fname);
853 if (!file.open( IO_WriteOnly ) )
855 QMessageBox::critical( 0, tr( "Critical Save Error" ),
856 tr("Couldn't write to ") +fileDir+fname);
862 if (savemode==CompleteMap || selection==NULL)
863 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
865 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
867 file.setName ( fileDir + fname);
868 if ( !file.open( IO_WriteOnly ) )
870 // This should neverever happen
871 QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name());
875 // Write it finally, and write in UTF8, no matter what
876 QTextStream ts( &file );
877 ts.setEncoding (QTextStream::UnicodeUTF8);
885 actionFileSave->setEnabled(false);
891 void MapEditor::setZipped (bool z)
896 bool MapEditor::saveZipped ()
901 void MapEditor::print()
903 // Finish open lineEdits
904 if (lineedit) finishedLineEditNoSave();
908 printer = new QPrinter;
909 printer->setColorMode (QPrinter::Color);
910 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
913 QRect totalBBox=mapCenter->getTotalBBox();
915 // Try to set orientation automagically
916 // Note: Interpretation of generated postscript is amibiguous, if
917 // there are problems with landscape mode, see
918 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
920 if (totalBBox.width()>totalBBox.height())
921 // recommend landscape
922 printer->setOrientation (QPrinter::Landscape);
924 // recommend portrait
925 printer->setOrientation (QPrinter::Portrait);
927 if ( printer->setup(this) )
928 // returns false, if printing is canceled
930 QPainter pp(printer);
932 // Don't print the visualisation of selection
933 LinkableMapObj *oldselection=NULL;
936 oldselection=selection;
937 selection->unselect();
940 // Handle sizes of map and paper:
942 // setWindow defines which part of the canvas will be transformed
943 // setViewport defines area on paper in device coordinates (dpi)
944 // e.g. (0,50,700,700) is upper part on A4
945 // see also /usr/lib/qt3/doc/html/coordsys.html
947 QPaintDeviceMetrics metrics (printer);
949 double paperAspect = (double)metrics.width() / (double)metrics.height();
950 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
952 QRect mapRect=totalBBox;
953 QCanvasRectangle *frame=NULL;
954 QCanvasText *footerFN=NULL;
955 QCanvasText *footerDate=NULL;
956 if (printFrame || printFooter)
961 // Print frame around map
962 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
963 totalBBox.width()+20, totalBBox.height()+20);
964 frame=new QCanvasRectangle (mapRect,mapCanvas);
965 frame->setBrush (QColor(white));
966 frame->setPen (QColor(black));
971 QCanvasLine *l=new QCanvasLine (mapCanvas);
972 l->setPoints (0,0,mapRect.width(),mapRect.height());
973 l->setPen (QPen(QColor(black), 1));
980 // Print footer below map
982 font.setPointSize(10);
983 footerFN=new QCanvasText (mapCanvas);
984 footerFN->setText ("VYM - " + fileName);
985 footerFN->setFont(font);
986 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
987 footerFN->setZ(Z_TEXT);
989 footerDate=new QCanvasText (mapCanvas);
990 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
991 footerDate->setFont(font);
992 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
993 footerDate->setZ(Z_TEXT);
996 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
999 pp.setWindow (mapRect);
1002 if (mapAspect>=paperAspect)
1004 // Fit horizontally to paper width
1005 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1008 // Fit vertically to paper height
1009 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1012 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1014 // Delete Frame and footer
1018 delete (footerDate);
1020 if (frame) delete (frame);
1022 // Restore selection
1025 selection=oldselection;
1026 selection->select();
1029 // Save settings in vymrc
1030 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1034 QPixmap MapEditor::getPixmap()
1036 QRect mapRect=mapCenter->getTotalBBox();
1037 QPixmap pix (mapRect.size());
1040 // Don't print the visualisation of selection
1041 LinkableMapObj *oldselection=NULL;
1044 oldselection=selection;
1045 selection->unselect();
1048 pp.setWindow (mapRect);
1050 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1053 // Restore selection
1056 selection=oldselection;
1057 selection->select();
1063 void MapEditor::exportImage(QString fn)
1065 // Finish open lineEdits
1066 if (lineedit) finishedLineEditNoSave();
1068 QPixmap pix (getPixmap());
1069 pix.save(fn, "PNG");
1072 void MapEditor::exportImage(QString fn, int item)
1074 // Finish open lineEdits
1075 if (lineedit) finishedLineEditNoSave();
1077 QPixmap pix (getPixmap());
1078 pix.save(fn, exportImageFormatMenu->text(item) );
1081 void MapEditor::exportASCII()
1083 // FIXME still experimental
1084 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
1085 fd->addFilter ("TXT (*.txt)");
1086 fd->setCaption("VYM - Export (ASCII) (still experimental)");
1087 fd->setMode( QFileDialog::AnyFile );
1090 if ( fd->exec() == QDialog::Accepted )
1092 if (QFile (fd->selectedFile()).exists() )
1094 QMessageBox mb( "VYM",
1095 tr("The file ") + fd->selectedFile() +
1096 tr(" exists already. Do you want to overwrite it?"),
1097 QMessageBox::Warning,
1098 QMessageBox::Yes | QMessageBox::Default,
1099 QMessageBox::Cancel | QMessageBox::Escape,
1100 QMessageBox::NoButton );
1102 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1103 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1107 case QMessageBox::Yes:
1109 if (!ex.setOutputDir ("out"))
1111 QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out");
1115 case QMessageBox::Cancel:
1122 ex.setPath (fd->selectedFile() );
1123 ex.setMapCenter(mapCenter);
1129 void MapEditor::exportXML(const QString &dir)
1131 // Create subdirectories
1134 // write to directory
1135 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1138 file.setName ( dir + "/"+mapName+".xml");
1139 if ( !file.open( IO_WriteOnly ) )
1141 // This should neverever happen
1142 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+file.name());
1146 // Write it finally, and write in UTF8, no matter what
1147 QTextStream ts( &file );
1148 ts.setEncoding (QTextStream::UnicodeUTF8);
1152 // Now write image, too
1153 exportImage (dir+"/images/"+mapName+".png");
1156 void MapEditor::clear()
1160 selection->unselect();
1167 void MapEditor::copy()
1169 // Finish open lineEdits
1170 if (lineedit) finishedLineEditNoSave();
1174 if (typeid(*selection) == typeid(BranchObj) )
1178 clipboardME->clear();
1179 clipboardME->getMapCenter()->addBranch();
1180 to=clipboardME->getMapCenter()->getLastBranch();
1183 from=(BranchObj*)(selection);
1186 // keep position relative to parent
1187 to->move2RelPos ( from->getRelPos());
1189 // select data in clipboard
1190 clipboardME->select ("bo:0");
1192 // repositioning makes testing nicer,
1193 // but is not needed usually:
1194 if (clipboardME->isVisible())
1196 clipboardME->getMapCenter()->reposition();
1199 clipboardME->hide();
1202 if (typeid(*selection) == typeid(FloatImageObj) )
1205 FloatImageObj* from;
1206 clipboardME->clear();
1207 clipboardME->getMapCenter()->addFloatImage();
1208 to=clipboardME->getMapCenter()->getLastFloatImage();
1211 from=(FloatImageObj*)(selection);
1214 // select data in clipboard
1215 clipboardME->select ("fi:0");
1217 // repositioning makes testing nicer,
1218 // but is not needed usually:
1219 if (clipboardME->isVisible())
1221 clipboardME->getMapCenter()->reposition();
1224 clipboardME->hide();
1230 void MapEditor::undo()
1232 // Finish open lineEdits
1233 if (lineedit) finishedLineEditNoSave();
1238 selection->unselect();
1242 parseAtom (undoCommand);
1243 mapCenter->reposition();
1245 // Undo not longer available now
1246 actionEditUndo->setEnabled (false);
1251 void MapEditor::undoXML(const QString &undoSel)
1254 d.setPath(bakMapDir);
1257 // We need to parse saved XML data
1258 mapBuilderHandler handler;
1259 QXmlInputSource source;
1260 source.setData(backupXML);
1261 QXmlSimpleReader reader;
1262 reader.setContentHandler( &handler );
1263 reader.setErrorHandler( &handler );
1264 handler.setMapEditor( this );
1265 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1266 if (undoSel.isEmpty())
1269 handler.setLoadMode (NewMap);
1273 handler.setLoadMode (ImportReplace);
1275 blockreposition=true;
1276 bool ok = reader.parse( source );
1277 blockreposition=false;
1280 // This should never ever happen
1281 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1282 tr( handler.errorProtocol() )+" in "+backupXML );
1286 QMessageBox::critical( 0, tr( "Critical Error" ),
1287 "Temporary directory " +bakMapDir +
1288 tr (" used for undo is gone. \n"
1289 "I will create a new one, but at the moment no undo is available.\n"
1290 "Maybe you want to reload your original data.\n\n"
1291 "Sorry for any inconveniences.") );
1296 LinkableMapObj* MapEditor::pasteNoSave()
1298 // Finish open lineEdits
1299 if (lineedit) finishedLineEditNoSave();
1301 LinkableMapObj *fromLMO=clipboardME->getSelection();
1302 LinkableMapObj *returnLMO=NULL;
1304 if (selection && fromLMO)
1306 if (typeid(*fromLMO) == typeid(BranchObj) )
1308 if (typeid(*selection) == typeid(MapCenterObj))
1310 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1311 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1313 if (typeid(*selection) == typeid(BranchObj))
1314 returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) );
1317 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1318 (typeid(*selection) == typeid (BranchObj) ||
1319 typeid(*selection)==typeid(MapCenterObj)) )
1320 returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO));
1326 void MapEditor::cutNoSave()
1328 // Finish open lineEdits
1329 if (lineedit) finishedLineEditNoSave();
1333 if (selection != NULL) {
1334 if (typeid(*selection) == typeid(BranchObj) )
1336 bo=(BranchObj*)(selection);
1337 par=(BranchObj*)(bo->getParObj());
1340 par->removeBranch(bo);
1342 selection->select();
1344 if (typeid(*selection) == typeid(FloatImageObj) )
1346 FloatImageObj* fio=(FloatImageObj*)(selection);
1347 par=(BranchObj*)(fio->getParObj());
1350 par->removeFloatImage(fio);
1352 selection->select();
1357 void MapEditor::paste()
1360 saveState(selection);
1362 mapCenter->reposition();
1366 void MapEditor::cut()
1369 saveState(selection->getParObj());
1372 mapCenter->reposition();
1376 void MapEditor::moveBranchUp()
1378 // Finish open lineEdits
1379 if (lineedit) finishedLineEditNoSave();
1383 if (typeid(*selection) == typeid(BranchObj) )
1386 saveState("moveBranchDown ()");
1387 bo=(BranchObj*)(selection);
1388 par=(BranchObj*)(bo->getParObj());
1389 selection->unselect();
1390 selection=par->moveBranchUp (bo);
1391 selection->select();
1392 mapCenter->reposition();
1393 ensureSelectionVisible();
1397 void MapEditor::moveBranchDown()
1399 // Finish open lineEdits
1400 if (lineedit) finishedLineEditNoSave();
1404 if (typeid(*selection) == typeid(BranchObj) )
1407 saveState("moveBranchUp ()");
1408 bo=(BranchObj*)(selection);
1409 par=(BranchObj*)(bo->getParObj());
1410 selection->unselect();
1411 selection=par->moveBranchDown(bo);
1412 selection->select();
1413 mapCenter->reposition();
1414 ensureSelectionVisible();
1418 void MapEditor::editHeading()
1420 // Finish open lineEdits
1421 if (lineedit) finishedLineEditNoSave();
1424 (typeid(*selection) == typeid(BranchObj) ||
1425 typeid(*selection) == typeid(MapCenterObj) ) )
1428 saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")");
1430 ensureSelectionVisible();
1431 editingBO=(BranchObj*)(selection);
1432 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1433 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1434 QString s=editingBO->getHeading();
1435 lineedit->setText(s);
1436 lineedit->setCursorPosition(1);
1437 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1438 lineedit->selectAll();
1441 lineedit->grabKeyboard();
1442 lineedit->setFocus();
1446 void MapEditor::setHeading(const QString &s)
1448 // Internal function, no saveState needed
1450 (typeid(*selection) == typeid(BranchObj) ||
1451 typeid(*selection) == typeid(MapCenterObj) ) )
1453 ((BranchObj*)(selection))->setHeading(s);
1454 mapCenter->reposition();
1456 ensureSelectionVisible();
1460 void MapEditor::addNewBranch(int pos)
1462 // Finish open lineEdits
1463 if (lineedit) finishedLineEditNoSave();
1466 (typeid(*selection) == typeid(BranchObj) ||
1467 typeid(*selection) == typeid(MapCenterObj) ) )
1470 saveState(selection);
1472 BranchObj* bo1 = (BranchObj*) (selection);
1473 bool wasScrolled=false;
1474 BranchObj *newbo=NULL;
1477 // save scroll state. If scrolled, automatically select
1478 // new branch in order to tmp unscroll parent...
1479 wasScrolled=bo1->isScrolled();
1480 newbo=bo1->addBranch();
1483 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1487 // add above selection
1488 newbo=parbo->insertBranch(bo1->getNum());
1490 // add below selection
1491 newbo=parbo->insertBranch(bo1->getNum()+1);
1493 // This should not happen...
1498 LinkableMapObj *oldselection=selection;
1500 mapCenter->reposition();
1502 if (actionSettingsAutoedit->isOn() ||
1503 actionSettingsAutoselectHeading->isOn() )
1505 selection->unselect();
1507 selection->select();
1508 if (actionSettingsPasteNewHeading->isOn() )
1510 BranchObj *bo2= (BranchObj*)(selection);
1511 bo2->setHeading("");
1513 if (actionSettingsAutoedit->isOn() )
1515 if (!actionSettingsAutoselectHeading->isOn()
1518 selection->unselect();
1519 selection=oldselection;
1520 selection->select();
1527 void MapEditor::addNewBranchHere()
1529 // Finish open lineEdits
1530 if (lineedit) finishedLineEditNoSave();
1533 (typeid(*selection) == typeid(BranchObj) ) )
1536 saveState(selection);
1538 BranchObj* bo1 = (BranchObj*) (selection);
1539 bool wasScrolled=false;
1540 BranchObj *newbo=NULL;
1541 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1544 // add below selection
1545 newbo=parbo->insertBranch(bo1->getNum()+1);
1548 LinkableMapObj *oldselection=selection;
1549 ((BranchObj*)(selection))->moveBranchTo (newbo,-1);
1551 mapCenter->reposition();
1553 if (actionSettingsAutoedit->isOn() ||
1554 actionSettingsAutoselectHeading->isOn() )
1556 selection->unselect();
1558 selection->select();
1559 if (actionSettingsPasteNewHeading->isOn() )
1561 BranchObj *bo2= (BranchObj*)(selection);
1562 bo2->setHeading("");
1564 if (actionSettingsAutoedit->isOn() )
1566 if (!actionSettingsAutoselectHeading->isOn()
1569 selection->unselect();
1570 selection=oldselection;
1571 selection->select();
1577 void MapEditor::deleteSelection()
1579 // Finish open lineEdits
1580 if (lineedit) finishedLineEditNoSave();
1582 if (selection && typeid(*selection) ==typeid(BranchObj) )
1585 saveState(selection->getParObj());
1586 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1587 BranchObj* par=(BranchObj*)(bo->getParObj());
1590 par->removeBranch(bo);
1592 selection->select();
1593 ensureSelectionVisible();
1594 mapCenter->reposition();
1597 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1600 saveState(selection->getParObj());
1601 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1602 BranchObj* par=(BranchObj*)(fio->getParObj());
1605 par->removeFloatImage(fio);
1607 selection->select();
1608 ensureSelectionVisible();
1609 mapCenter->reposition();
1614 LinkableMapObj* MapEditor::getSelection()
1619 bool MapEditor::select (const QString &s)
1621 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1623 // Finally select the found object
1626 if (selection) unselect();
1628 selection->select();
1630 ensureSelectionVisible();
1636 void MapEditor::unselect()
1640 selectionLast=selection;
1641 selection->unselect();
1646 void MapEditor::reselect()
1650 selection=selectionLast;
1651 selection->select();
1656 void MapEditor::selectNextBranch()
1658 // Increase number of branch
1661 QString s=selection->getSelectString();
1667 part=s.section(",",-1);
1669 num=part.right(part.length() - 3);
1671 s=s.left (s.length() -num.length());
1674 num=QString ("%1").arg(num.toUInt()+1);
1678 // Try to select this one
1679 if (select (s)) return;
1681 // We have no direct successor,
1682 // try to increase the parental number in order to
1683 // find a successor with same depth
1685 int d=selection->getDepth();
1690 while (!found && d>0)
1692 s=s.section (",",0,d-1);
1693 // replace substring of current depth in s with "1"
1694 part=s.section(",",-1);
1696 num=part.right(part.length() - 3);
1700 // increase number of parent
1701 num=QString ("%1").arg(num.toUInt()+1);
1702 s=s.section (",",0,d-2) + ","+ typ+num;
1705 // Special case, look at orientation
1706 if (selection->getOrientation()==OrientRightOfCenter)
1707 num=QString ("%1").arg(num.toUInt()+1);
1709 num=QString ("%1").arg(num.toUInt()-1);
1714 // pad to oldDepth, select the first branch for each depth
1715 for (i=d;i<oldDepth;i++)
1720 if ( ((BranchObj*)(selection))->countBranches()>0)
1728 // try to select the freshly built string
1736 void MapEditor::selectPrevBranch()
1738 // Decrease number of branch
1741 QString s=selection->getSelectString();
1747 part=s.section(",",-1);
1749 num=part.right(part.length() - 3);
1751 s=s.left (s.length() -num.length());
1754 num=QString ("%1").arg(num.toUInt()-1);
1758 // Try to select this one
1759 if (select (s)) return;
1761 // We have no direct precessor,
1762 // try to decrease the parental number in order to
1763 // find a precessor with same depth
1765 int d=selection->getDepth();
1770 while (!found && d>0)
1772 s=s.section (",",0,d-1);
1773 // replace substring of current depth in s with "1"
1774 part=s.section(",",-1);
1776 num=part.right(part.length() - 3);
1780 // decrease number of parent
1781 num=QString ("%1").arg(num.toUInt()-1);
1782 s=s.section (",",0,d-2) + ","+ typ+num;
1785 // Special case, look at orientation
1786 if (selection->getOrientation()==OrientRightOfCenter)
1787 num=QString ("%1").arg(num.toUInt()-1);
1789 num=QString ("%1").arg(num.toUInt()+1);
1794 // pad to oldDepth, select the last branch for each depth
1795 for (i=d;i<oldDepth;i++)
1799 if ( ((BranchObj*)(selection))->countBranches()>0)
1800 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)(selection))->countBranches()-1 );
1807 // try to select the freshly built string
1815 void MapEditor::selectUpperBranch()
1817 // Finish open lineEdits
1818 if (lineedit) finishedLineEditNoSave();
1822 if (typeid(*selection) == typeid(BranchObj))
1824 if (selection->getOrientation()==OrientRightOfCenter)
1827 if (selection->getDepth()==1)
1835 void MapEditor::selectLowerBranch()
1837 // Finish open lineEdits
1838 if (lineedit) finishedLineEditNoSave();
1842 if (typeid(*selection) == typeid(BranchObj))
1844 if (selection->getOrientation()==OrientRightOfCenter)
1847 if (selection->getDepth()==1)
1856 void MapEditor::selectLeftBranch()
1858 // Finish open lineEdits
1859 if (lineedit) finishedLineEditNoSave();
1865 if (typeid(*selection) == typeid(MapCenterObj))
1867 par= (BranchObj*) (selection);
1868 bo=par->getLastSelectedBranch();
1871 // Workaround for reselecting on left and right side
1872 if (bo->getOrientation()==OrientRightOfCenter)
1874 bo=par->getLastBranch();
1880 selection->select();
1882 ensureSelectionVisible();
1887 par=(BranchObj*)(selection->getParObj());
1888 if (selection->getOrientation()==OrientRightOfCenter)
1890 if (typeid(*selection) == typeid(BranchObj) ||
1891 typeid(*selection) == typeid(FloatImageObj))
1893 selection->unselect();
1895 selection->select();
1897 ensureSelectionVisible();
1901 if (typeid(*selection) == typeid(BranchObj) )
1903 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1906 selection->unselect();
1908 selection->select();
1910 ensureSelectionVisible();
1918 void MapEditor::selectRightBranch()
1920 // Finish open lineEdits
1921 if (lineedit) finishedLineEditNoSave();
1928 if (typeid(*selection) == typeid(MapCenterObj))
1930 par= (BranchObj*) (selection);
1931 bo=par->getLastSelectedBranch();
1934 // Workaround for relecting on left and right side
1935 if (bo->getOrientation()==OrientLeftOfCenter)
1936 bo=par->getFirstBranch();
1941 selection->select();
1942 ensureSelectionVisible();
1947 par=(BranchObj*)(selection->getParObj());
1948 if (selection->getOrientation()==OrientLeftOfCenter)
1950 if (typeid(*selection) == typeid(BranchObj) ||
1951 typeid(*selection) == typeid(FloatImageObj))
1953 selection->unselect();
1955 selection->select();
1957 ensureSelectionVisible();
1961 if (typeid(*selection) == typeid(BranchObj) )
1963 bo=((BranchObj*)(selection))->getLastSelectedBranch();
1966 selection->unselect();
1968 selection->select();
1970 ensureSelectionVisible();
1978 void MapEditor::selectFirstBranch()
1980 // Finish open lineEdits
1981 if (lineedit) finishedLineEditNoSave();
1987 if (typeid(*selection) == typeid(BranchObj))
1989 bo1= (BranchObj*) (selection);
1990 par=(BranchObj*)(bo1->getParObj());
1991 bo2=par->getFirstBranch();
1995 selection->select();
1996 ensureSelectionVisible();
2003 void MapEditor::selectLastBranch()
2005 // Finish open lineEdits
2006 if (lineedit) finishedLineEditNoSave();
2012 if (typeid(*selection) == typeid(BranchObj))
2014 bo1= (BranchObj*) (selection);
2015 par=(BranchObj*)(bo1->getParObj());
2016 bo2=par->getLastBranch();
2020 selection->select();
2021 ensureSelectionVisible();
2028 void MapEditor::setColor(QColor c)
2033 void MapEditor::selectBackgroundColor()
2035 // Finish open lineEdits
2036 if (lineedit) finishedLineEditNoSave();
2038 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2039 if ( !col.isValid() ) return;
2040 setBackgroundColor( col );
2044 void MapEditor::setBackgroundColor(QColor c)
2046 mapCanvas->setBackgroundColor (c);
2049 QColor MapEditor::pickColor()
2053 if (typeid(*selection) == typeid(BranchObj) ||
2054 typeid(*selection) == typeid(MapCenterObj))
2056 BranchObj *bo=(BranchObj*)(selection);
2057 actColor=bo->getColor();
2063 void MapEditor::colorItem()
2067 if (typeid(*selection) == typeid(BranchObj) ||
2068 typeid(*selection) == typeid(MapCenterObj))
2071 saveState(selection);
2072 BranchObj *bo=(BranchObj*)(selection);
2073 bo->setColor(actColor, false); // color links, color childs
2078 void MapEditor::colorBranch()
2082 if (typeid(*selection) == typeid(BranchObj) ||
2083 typeid(*selection) == typeid(MapCenterObj))
2086 saveState(selection);
2087 BranchObj *bo=(BranchObj*)(selection);
2088 bo->setColor(actColor, true); // color links, color childs
2094 void MapEditor::toggleStandardFlag(QString f)
2099 saveState(selection);
2100 ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2104 void MapEditor::setViewCenter()
2106 // transform to CanvasView Coord:
2107 QPoint p=worldMatrix().map(movingCenter);
2108 center ( p.x(), p.y());
2112 BranchObj* MapEditor::findText (QString s, bool cs)
2115 { // Nothing found or new find process
2117 // nothing found, start again
2119 itFind=mapCenter->first();
2121 bool searching=true;
2122 bool foundNote=false;
2123 while (searching && !EOFind)
2127 // Searching in Note
2128 if (itFind->getNote().contains(s,cs))
2130 if (selection!=itFind)
2132 if (selection) ((BranchObj*)(selection))->unselect();
2134 selection->select();
2136 ensureSelectionVisible();
2138 if (textEditor->findText(s,cs))
2144 // Searching in Heading
2145 if (searching && itFind->getHeading().contains (s,cs) )
2147 if (selection) ((BranchObj*)(selection))->unselect();
2149 selection->select();
2151 ensureSelectionVisible();
2157 itFind=itFind->next();
2158 if (!itFind) EOFind=true;
2164 return (BranchObj*)(selection);
2169 void MapEditor::findReset()
2170 { // Necessary if text to find changes during a find process
2175 void MapEditor::openURL()
2179 if (typeid(*selection) == typeid(BranchObj) ||
2180 typeid(*selection) == typeid(MapCenterObj))
2182 QString url=((BranchObj*)(selection))->getURL();
2184 QProcess *proc = new QProcess( this );
2186 #if !defined(Q_OS_MACX)
2187 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" ));
2189 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL",
2190 "/Applications/Safari.app/Contents/MacOS/Safari" ));
2193 proc->addArgument( url);
2195 if ( !proc->start() )
2197 if (mainWindow->settingsURL() )
2203 void MapEditor::editURL()
2205 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2206 typeid(*selection) == typeid(MapCenterObj)) )
2209 QString text = QInputDialog::getText(
2210 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2211 ((BranchObj*)(selection))->getURL(), &ok, this );
2214 // user entered something and pressed OK
2215 ((BranchObj*)(selection))->setURL (text);
2222 void MapEditor::editHeading2URL()
2224 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2225 typeid(*selection) == typeid(MapCenterObj)) )
2227 BranchObj *b=(BranchObj*)(selection);
2228 b->setURL (b->getHeading());
2234 void MapEditor::editBugzilla2URL()
2236 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2237 typeid(*selection) == typeid(MapCenterObj)) )
2239 BranchObj *b=(BranchObj*)(selection);
2240 b->setURL ("https://bugzilla.novell.com/show_bug.cgi?id="+b->getHeading());
2246 void MapEditor::editVymLink()
2248 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2249 typeid(*selection) == typeid(MapCenterObj)) )
2251 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2252 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2253 fd->setCaption(tr("VYM - Link to another map"));
2254 if (! ((BranchObj*)(selection))->getVymLink().isEmpty() )
2255 fd->setSelection( ((BranchObj*)(selection))->getVymLink() );
2259 if ( fd->exec() == QDialog::Accepted )
2260 ((BranchObj*)(selection))->setVymLink (fd->selectedFile() );
2262 mapCenter->reposition();
2269 void MapEditor::deleteVymLink()
2271 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2272 typeid(*selection) == typeid(MapCenterObj)) )
2274 ((BranchObj*)(selection))->setVymLink ("" );
2276 mapCenter->reposition();
2283 QString MapEditor::getVymLink()
2285 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2286 typeid(*selection) == typeid(MapCenterObj)) )
2288 return ((BranchObj*)(selection))->getVymLink();
2294 void MapEditor::removeBranchHere()
2296 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2299 saveState(selection->getParObj());
2300 QString sel=selection->getSelectString();
2301 BranchObj* bo=(BranchObj*)(selection);
2302 BranchObj* par=(BranchObj*)(bo->getParObj());
2304 par->removeBranchHere(bo);
2305 mapCenter->reposition();
2310 void MapEditor::removeChilds()
2312 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2315 saveState(selection->getParObj());
2316 ((BranchObj*)(selection))->removeChilds();
2317 mapCenter->reposition();
2321 void MapEditor::editMapInfo()
2323 ExtraInfoDialog dia;
2324 dia.setMapName (getFileName() );
2325 dia.setAuthor (mapCenter->getAuthor() );
2326 dia.setComment(mapCenter->getComment() );
2331 QCanvasItemList l=canvas()->allItems();
2332 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2334 stats+=QString ("%1 items on canvas\n").arg (i,6);
2341 bo=mapCenter->first();
2344 if (!bo->getNote().isEmpty() ) n++;
2345 f+= bo->countFloatImages();
2347 xl+=bo->countXLinks();
2350 stats+=QString ("%1 branches\n").arg (b-1,6);
2351 stats+=QString ("%1 xLinks \n").arg (xl,6);
2352 stats+=QString ("%1 notes\n").arg (n,6);
2353 stats+=QString ("%1 images\n").arg (f,6);
2354 dia.setStats (stats);
2356 // Finally show dialog
2357 if (dia.exec() == QDialog::Accepted)
2359 mapCenter->setAuthor (dia.getAuthor() );
2360 mapCenter->setComment (dia.getComment() );
2365 void MapEditor::updateActions()
2368 if (getLinkColorHint()==HeadingColor)
2369 actionFormatLinkColorHint->setOn(true);
2371 actionFormatLinkColorHint->setOn(false);
2376 actionFormatLinkStyleLine->setOn(true);
2379 actionFormatLinkStyleParabel->setOn(true);
2382 actionFormatLinkStylePolyLine->setOn(true);
2384 case StylePolyParabel:
2385 actionFormatLinkStylePolyParabel->setOn(true);
2391 QPixmap pix( 16, 16 );
2392 pix.fill( mapCanvas->backgroundColor() );
2393 actionFormatBackColor->setIconSet( pix );
2394 pix.fill( defLinkColor );
2395 actionFormatLinkColor->setIconSet( pix );
2397 actionEditUndo->setEnabled( mapChanged );
2398 actionFileSave->setEnabled( mapUnsaved );
2402 if ( (typeid(*selection) == typeid(BranchObj)) ||
2403 (typeid(*selection) == typeid(MapCenterObj)) )
2405 BranchObj *bo=(BranchObj*)(selection);
2406 // Take care of links
2407 if (bo->countXLinks()==0)
2409 branchLinksContextMenu->clear();
2410 branchLinksContextMenu->insertItem ("No link available");
2411 branchLinksContextMenuDup->clear();
2412 branchLinksContextMenuDup->insertItem ("No link available");
2418 branchLinksContextMenu->clear();
2419 branchLinksContextMenuDup->clear();
2420 for (int i=0; i<=bo->countXLinks();i++)
2422 bot=bo->XLinkTargetAt(i);
2425 s=bot->getHeading();
2428 branchLinksContextMenu->insertItem (s);
2429 branchLinksContextMenuDup->insertItem (s);
2434 standardFlagsDefault->setEnabled (true);
2436 if ( bo->getURL().isEmpty() )
2437 actionEditOpenURL->setEnabled (false);
2439 actionEditOpenURL->setEnabled (true);
2441 if ( bo->getVymLink().isEmpty() )
2443 actionEditOpenVymLink->setEnabled (false);
2444 actionEditDeleteVymLink->setEnabled (false);
2447 actionEditOpenVymLink->setEnabled (true);
2448 actionEditDeleteVymLink->setEnabled (true);
2451 actionEditCopy->setEnabled (true);
2452 actionEditCut->setEnabled (true);
2453 if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
2454 actionEditPaste->setEnabled (true);
2456 actionEditPaste->setEnabled (false);
2457 for (a=actionListBranches.first();a;a=actionListBranches.next())
2458 a->setEnabled(true);
2459 actionEditDelete->setEnabled (true);
2460 actionEditToggleFloatExport->setEnabled (false);
2461 switch (selection->getFrameType())
2464 actionFormatFrameNone->setOn(true);
2467 actionFormatFrameRectangle->setOn(true);
2473 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2475 standardFlagsDefault->setEnabled (false);
2477 actionEditOpenURL->setEnabled (false);
2478 actionEditOpenVymLink->setEnabled (false);
2479 actionEditDeleteVymLink->setEnabled (false);
2481 actionEditCopy->setEnabled (true);
2482 actionEditCut->setEnabled (true);
2483 actionEditPaste->setEnabled (false); //FIXME
2484 for (a=actionListBranches.first();a;a=actionListBranches.next())
2485 a->setEnabled(false);
2486 actionEditDelete->setEnabled (true);
2487 actionEditToggleFloatExport->setOn
2488 ( ((FloatImageObj*)(selection))->getFloatExport() );
2493 standardFlagsDefault->setEnabled (false);
2495 actionEditCopy->setEnabled (false);
2496 actionEditCut->setEnabled (false);
2497 actionEditPaste->setEnabled (false);
2498 for (a=actionListBranches.first();a;a=actionListBranches.next())
2499 a->setEnabled(false);
2501 actionEditOpenURL->setEnabled (false);
2502 actionEditOpenVymLink->setEnabled (false);
2503 actionEditDeleteVymLink->setEnabled (false);
2504 actionEditHeading2URL->setEnabled (false);
2505 actionEditDelete->setEnabled (false);
2506 actionEditToggleFloatExport->setEnabled (false);
2510 void MapEditor::setLinkStyle (LinkStyle ls)
2517 bo=mapCenter->first();
2521 bo->setLinkStyle(bo->getDefLinkStyle());
2524 mapCenter->reposition();
2527 LinkStyle MapEditor::getLinkStyle ()
2532 void MapEditor::setLinkColor(QColor c)
2538 void MapEditor::setLinkColorHint()
2540 // called from setLinkColorHint(lch) or at end of parse
2542 bo=mapCenter->first();
2550 void MapEditor::setLinkColorHint(LinkColorHint lch)
2556 void MapEditor::toggleLinkColorHint()
2558 if (linkcolorhint==HeadingColor)
2559 linkcolorhint=DefaultColor;
2561 linkcolorhint=HeadingColor;
2563 bo=mapCenter->first();
2571 LinkColorHint MapEditor::getLinkColorHint()
2573 return linkcolorhint;
2576 QColor MapEditor::getDefLinkColor()
2578 return defLinkColor;
2581 void MapEditor::setDefXLinkColor(QColor col)
2586 QColor MapEditor::getDefXLinkColor()
2588 return defXLinkColor;
2591 void MapEditor::setDefXLinkWidth (int w)
2596 int MapEditor::getDefXLinkWidth()
2598 return defXLinkWidth;
2601 void MapEditor::selectLinkColor()
2603 // Finish open lineEdits
2604 if (lineedit) finishedLineEditNoSave();
2606 QColor col = QColorDialog::getColor( defLinkColor, this );
2607 if ( !col.isValid() ) return;
2608 setLinkColor( col );
2612 void MapEditor::toggleScroll()
2614 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2616 BranchObj *bo=((BranchObj*)(selection));
2617 if (bo->countBranches()==0) return;
2618 if (bo->getDepth()==0) return;
2620 saveState(selection);
2627 void MapEditor::unScrollAll()
2630 bo=mapCenter->first();
2633 if (bo->isScrolled()) bo->toggleScroll();
2638 void MapEditor::loadFloatImage ()
2641 (typeid(*selection) == typeid(BranchObj)) ||
2642 (typeid(*selection) == typeid(MapCenterObj)) )
2644 BranchObj *bo=((BranchObj*)(selection));
2646 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
2647 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2648 ImagePreview *p =new ImagePreview (fd);
2649 fd->setContentsPreviewEnabled( TRUE );
2650 fd->setContentsPreview( p, p );
2651 fd->setPreviewMode( QFileDialog::Contents );
2652 fd->setCaption(tr("vym - Load image"));
2653 fd->setDir (lastImageDir);
2657 if ( fd->exec() == QDialog::Accepted )
2660 saveState(selection);
2661 QString fn=fd->selectedFile();
2662 lastImageDir=fn.left(fn.findRev ("/"));
2663 bo->addFloatImage();
2664 // FIXME check if load was successful
2665 bo->getLastFloatImage()->load(fn);
2666 bo->getLastFloatImage()->setOriginalFilename(fn);
2667 mapCenter->reposition();
2674 void MapEditor::saveFloatImage (int item)
2677 (typeid(*selection) == typeid(FloatImageObj)) )
2679 FloatImageObj *fio=((FloatImageObj*)(selection));
2680 const char* fmt = saveImageFormatMenu->text(item);
2682 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2683 fd->addFilter ("PNG (*.png)");
2684 fd->addFilter ("BMP (*.bmp)");
2685 fd->addFilter ("XBM (*.xbm)");
2686 fd->addFilter ("JPG (*.jpg)");
2687 fd->addFilter ("XPM (*.xpm)");
2688 fd->addFilter ("GIF (*.gif)");
2689 fd->addFilter ("PNM (*.pnm)");
2690 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2691 fd->setCaption(tr("vym - Save image as ") + fmt);
2692 fd->setMode( QFileDialog::AnyFile );
2693 fd->setSelection (fio->getOriginalFilename());
2697 if ( fd->exec() == QDialog::Accepted )
2699 if (QFile (fd->selectedFile()).exists() )
2701 QMessageBox mb( "VYM",
2702 tr("The file ") + fd->selectedFile() +
2703 tr(" exists already. "
2704 "Do you want to overwrite it?"),
2705 QMessageBox::Warning,
2706 QMessageBox::Yes | QMessageBox::Default,
2707 QMessageBox::Cancel | QMessageBox::Escape,
2708 QMessageBox::QMessageBox::NoButton );
2710 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2711 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2714 case QMessageBox::Yes:
2717 case QMessageBox::Cancel:
2723 fio->save (fd->selectedFile(),fmt);
2728 void MapEditor::toggleFloatExport()
2731 (typeid(*selection) == typeid(FloatImageObj))||
2732 (typeid(*selection) == typeid(FloatObj)) )
2734 FloatImageObj *fio=((FloatImageObj*)(selection));
2735 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2739 void MapEditor::setFrame(const FrameType &t)
2742 (typeid(*selection) == typeid(BranchObj)) ||
2743 (typeid(*selection) == typeid(MapCenterObj)) )
2745 selection->setFrameType (t);
2746 mapCenter->reposition();
2747 selection->updateLink();
2751 void MapEditor::importDir(BranchObj *dst, QDir d)
2754 (typeid(*selection) == typeid(BranchObj)) ||
2755 (typeid(*selection) == typeid(MapCenterObj)) )
2759 // Traverse directories
2760 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2761 const QFileInfoList *dirlist = d.entryInfoList();
2762 QFileInfoListIterator itdir( *dirlist );
2765 while ( (fi = itdir.current()) != 0 )
2767 if (fi->fileName() != "." && fi->fileName() != ".." )
2770 bo=dst->getLastBranch();
2771 bo->setHeading (fi->fileName() );
2772 bo->setColor (QColor("blue"),false);
2774 if ( !d.cd(fi->fileName()) )
2775 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory"));
2778 // Recursively add subdirs
2786 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2787 const QFileInfoList *filelist = d.entryInfoList();
2788 QFileInfoListIterator itfile( *filelist );
2790 while ( (fi = itfile.current()) != 0 )
2793 bo=dst->getLastBranch();
2794 bo->setHeading (fi->fileName() );
2795 bo->setColor (QColor("black"),false);
2796 if (fi->fileName().right(4) == ".vym" )
2797 bo->setVymLink (fi->filePath());
2804 void MapEditor::importDir()
2807 (typeid(*selection) == typeid(BranchObj)) ||
2808 (typeid(*selection) == typeid(MapCenterObj)) )
2810 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
2811 fd->setMode (QFileDialog::DirectoryOnly);
2812 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2813 fd->setCaption(tr("VYM - Choose directory structur to import"));
2817 if ( fd->exec() == QDialog::Accepted )
2819 BranchObj *bo=((BranchObj*)(selection));
2820 importDir (bo,QDir(fd->selectedFile()) );
2821 mapCenter->reposition();
2828 void MapEditor::followXLink(int i)
2831 (typeid(*selection) == typeid(BranchObj)) ||
2832 (typeid(*selection) == typeid(MapCenterObj)) )
2834 BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i);
2837 selection->unselect();
2839 selection->select();
2840 ensureSelectionVisible();
2845 void MapEditor::editXLink(int i)
2848 (typeid(*selection) == typeid(BranchObj)) ||
2849 (typeid(*selection) == typeid(MapCenterObj)) )
2851 XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i);
2854 EditXLinkDialog dia;
2856 dia.setSelection(selection);
2857 if (dia.exec() == QDialog::Accepted)
2859 if (dia.useSettingsGlobal() )
2861 setDefXLinkColor (xlo->getColor() );
2862 setDefXLinkWidth (xlo->getWidth() );
2864 if (dia.deleteXLink())
2865 ((BranchObj*)(selection))->deleteXLinkAt(i);
2874 void MapEditor::testFunction()
2876 cout << "MapEditor::testFunction() called\n";
2878 (typeid(*selection) == typeid(BranchObj)) )
2880 QString s=((BranchObj*)(selection))->getHeading();
2885 void MapEditor::ensureSelectionVisible()
2889 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2891 if (selection->getOrientation() == OrientLeftOfCenter)
2892 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2894 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2895 ensureVisible (p.x(), p.y() );
2900 void MapEditor::updateViewCenter()
2902 // Update movingCenter, so that we can zoom comfortably later
2903 QRect rc = QRect( contentsX(), contentsY(),
2904 visibleWidth(), visibleHeight() );
2905 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2906 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2907 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2910 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
2912 // Lineedits are already closed by preceding
2913 // mouseEvent, we don't need to close here.
2915 QPoint p = inverseWorldMatrix().map(e->pos());
2916 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2919 { // MapObj was found
2920 if (selection != lmo)
2922 // select the MapObj
2923 if (selection) selection->unselect();
2925 selection->select();
2931 if (typeid(*selection)==typeid(BranchObj) ||
2932 typeid(*selection)==typeid(MapCenterObj) )
2934 // Context Menu on branch or mapcenter
2936 branchContextMenu->popup(e->globalPos() );
2938 if (typeid(*selection)==typeid(FloatImageObj))
2940 // Context Menu on floatimage
2942 floatimageContextMenu->popup(e->globalPos() );
2946 { // No MapObj found, we are on the Canvas itself
2947 // Context Menu on Canvas
2949 canvasContextMenu->popup(e->globalPos() );
2953 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
2955 // Finish open lineEdits
2956 if (lineedit) finishedLineEditNoSave();
2958 QPoint p = inverseWorldMatrix().map(e->pos());
2959 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
2961 // Special case: CTRL is pressed
2962 if (e->state() & QMouseEvent::ControlButton)
2964 if (actionModModeColor->isOn())
2966 if (e->state() & QMouseEvent::ControlButton)
2969 setCursor (pickColorCursor);
2973 if (actionModModeLink->isOn())
2975 BranchObj *bo_begin=NULL;
2977 bo_begin=(BranchObj*)(lmo);
2980 ((typeid(*selection) == typeid(BranchObj)) ||
2981 (typeid(*selection) == typeid(MapCenterObj))) )
2982 bo_begin=(BranchObj*)(selection);
2986 linkingObj_src=bo_begin;
2987 tmpXLink=new XLinkObj (mapCanvas);
2988 tmpXLink->setBegin (bo_begin);
2989 tmpXLink->setEnd (p);
2990 tmpXLink->setColor(defXLinkColor);
2991 tmpXLink->setWidth(defXLinkWidth);
2992 tmpXLink->updateXLink();
2993 tmpXLink->setVisibility (true);
3000 { // MapObj was found
3001 if (selection != lmo)
3003 // select the MapObj
3004 if (selection) selection->unselect();
3006 selection->select();
3012 // Check, if systemFlag clicked
3013 if (typeid(*selection)==typeid(BranchObj) ||
3014 typeid(*selection)==typeid(MapCenterObj) )
3016 QString foname=((BranchObj*)(selection))->getSystemFlagName(p);
3017 if (!foname.isEmpty())
3019 // Do not move, if systemFlag clicked
3023 if (foname=="vymLink")
3025 mainWindow->editOpenVymLink();
3026 // tabWidget may change, better return now
3027 // before segfaulting...
3031 mainWindow->windowToggleNoteEditor();
3035 // Left Button Move Branches
3036 if (e->button() == QMouseEvent::LeftButton )
3038 // If modMode==copy, then we want to "move" the _new_ object around
3039 // then we need the offset from p to the _old_ selection, because of tmp
3040 if (actionModModeCopy->isOn() &&
3041 e->state() & QMouseEvent::ControlButton)
3043 if (typeid(*selection)==typeid(BranchObj) )
3046 movingObj_start.setX( p.x() - selection->x() );
3047 movingObj_start.setY( p.y() - selection->y() );
3048 mapCenter->addBranch ((BranchObj*)(selection));
3050 selection=mapCenter->getLastBranch();
3051 selection->select();
3052 mapCenter->reposition();
3056 movingObj_start.setX( p.x() - selection->x() );
3057 movingObj_start.setY( p.y() - selection->y() );
3060 movingObj=selection;
3062 // Middle Button Toggle Scroll
3063 // (On Mac OS X this won't work, but we still have
3064 // a button in the toolbar)
3065 if (e->button() == QMouseEvent::MidButton )
3069 { // No MapObj found, we are on the Canvas itself
3070 // Left Button move Pos of CanvasView
3071 if (e->button() == QMouseEvent::LeftButton )
3073 movingObj=NULL; // move Content not Obj
3074 movingObj_start=e->globalPos();
3075 movingCont_start=QPoint (contentsX(), contentsY() );
3076 movingVec=QPoint(0,0);
3077 setCursor(handOpenCursor);
3082 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3084 QPoint p = inverseWorldMatrix().map(e->pos());
3086 // Move the selected MapObj
3087 if ( selection && movingObj)
3089 ensureVisible (p.x(),p.y());
3091 // Now move the selection, but add relative position
3092 // (movingObj_start) where selection was chosen with
3093 // mousepointer. (This avoids flickering resp. jumping
3094 // of selection back to absPos)
3096 LinkableMapObj *lmosel;
3097 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3099 // Check if we could link
3100 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3103 if (typeid(*selection) == typeid(FloatImageObj))
3107 FloatObj *fo=(FloatObj*)(selection);
3108 if (fo->getLinkStyle()==StyleUndef)
3110 fo->setLinkStyle(fo->getDefLinkStyle());
3111 fo->setLinkColor(fo->getParObj()->getLinkColor());
3113 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3117 // Relink float to new mapcenter or branch, if shift is pressed
3118 // Only relink, if selection really has a new parent
3119 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3120 ( (typeid(*lmo)==typeid(BranchObj)) ||
3121 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3122 ( lmo != fo->getParObj())
3125 if (typeid(*fo) == typeid(FloatImageObj))
3127 FloatImageObj *fio=(FloatImageObj*)(fo);
3128 ((BranchObj*)(lmo))->addFloatImage (fio);
3130 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3131 fio=((BranchObj*)(lmo))->getLastFloatImage();
3134 selection=(LinkableMapObj*)(fio);
3135 selection->select();
3136 movingObj=(MapObj*)(fio);
3137 // setLinkStyle calls updateLink, only set it once
3138 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3139 fio->setLinkStyle (fio->getDefLinkStyle());
3142 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3144 } else // selection != a FloatObj
3146 if (lmosel->getDepth()==0)
3148 if (e->state() == (LeftButton | !ShiftButton))
3149 // If mapCenter is moved, move all the rest by default, too.
3150 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3152 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3155 if (lmosel->getDepth()==1)
3157 // depth==1, mainbranch
3160 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3164 if (lmosel->getOrientation() == OrientLeftOfCenter)
3165 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3166 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3167 p.y()-movingObj_start.y() );
3169 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3171 // reposition subbranch
3172 lmosel->reposition();
3173 //ensureSelectionVisible();
3175 if (lmo && (lmo!=selection) &&
3176 (typeid(*lmo) == typeid(BranchObj) ||
3177 (typeid(*lmo) == typeid(MapCenterObj) )
3180 if (e->state() & QMouseEvent::ControlButton)
3182 // Special case: CTRL to link below lmo
3183 lmosel->setParObjTmp (lmo,p,+1);
3185 else if (e->state() & QMouseEvent::ShiftButton)
3186 lmosel->setParObjTmp (lmo,p,-1);
3188 lmosel->setParObjTmp (lmo,p,0);
3191 lmosel->unsetParObjTmp();
3193 if (lmo &&(lmo==selection))
3194 // Could link to myself (happens sometimes...)
3195 lmosel->unsetParObjTmp();
3197 // no Obj under selection, go back to original Parent
3198 lmosel->unsetParObjTmp();
3203 } // no FloatImageObj
3207 } // selection && moving_obj
3209 // Draw a link from one branch to another
3212 tmpXLink->setEnd (p);
3213 tmpXLink->updateXLink();
3217 if (!movingObj && !pickingColor &&!drawingLink)
3219 QPoint p=e->globalPos();
3220 movingVec.setX(-p.x() + movingObj_start.x() );
3221 movingVec.setY(-p.y() + movingObj_start.y() );
3222 setContentsPos( movingCont_start.x() + movingVec.x(),
3223 movingCont_start.y() + movingVec.y());
3230 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3232 LinkableMapObj *dst;
3233 // Have we been picking color?
3237 setCursor (ArrowCursor);
3238 // Check if we are over another branch
3239 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3240 if (dst && selection)
3242 if (e->state() & QMouseEvent::ShiftButton)
3244 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false);
3245 ((BranchObj*)(selection))->setLinkColor ();
3249 ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true);
3250 ((BranchObj*)(selection))->setLinkColor ();
3256 // Have we been drawing a link?
3260 // Check if we are over another branch
3261 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3262 if (dst && selection)
3264 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3265 tmpXLink->updateXLink();
3266 tmpXLink->activate();
3277 // Have we been moving something?
3278 if ( selection && movingObj )
3280 // Check if we are over another branch, but ignore
3281 // any found LMOs, which are FloatObjs
3282 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3283 ((LinkableMapObj*)(selection)) );
3286 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3291 // Now check, if we have been moving a branch
3292 if (typeid(*selection) == typeid(BranchObj) )
3294 // save the position in case we link to mapcenter
3295 QPoint savePos=QPoint (selection->x(),selection->y() );
3297 // Reset the temporary drawn link to the original one
3298 ((LinkableMapObj*)(selection))->unsetParObjTmp();
3306 // remove the current selection, if we have no destination
3307 selection->unselect();
3308 ((BranchObj*)(selection->getParObj()))->removeBranch ((BranchObj*)(selection));
3311 selection=selectionLast;
3313 selection->select();
3320 // TODO we also could check, if dest and src are on same branch,
3321 // then it would be sufficient to saveState of this branch
3323 // Modifiers allow to insert above/below dst
3324 if (e->state() & QMouseEvent::ShiftButton)
3326 ((BranchObj*)(selection))->moveBranchTo
3329 ((BranchObj*)(dst))->getNum()
3331 //if (selection) selection->select();
3333 if (e->state() & QMouseEvent::ControlButton)
3335 ((BranchObj*)(selection))->moveBranchTo
3338 ((BranchObj*)(dst))->getNum()+1
3340 //if (selection) selection->select();
3343 ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
3344 if (dst->getDepth()==0)
3345 ((BranchObj*)(selection))->move (savePos);
3348 // Draw the original link, before selection was moved around
3349 mapCenter->reposition();
3351 // Finally resize canvas, if needed
3356 // maybe we moved View: set old cursor
3357 setCursor (ArrowCursor);
3361 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3363 // Finish open lineEdits
3364 if (lineedit) finishedLineEditNoSave();
3366 if (e->button() == QMouseEvent::LeftButton )
3368 QPoint p = inverseWorldMatrix().map(e->pos());
3369 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3370 if (lmo) { // MapObj was found
3371 // First select the MapObj than edit heading
3372 if (selection) selection->unselect();
3374 selection->select();
3376 saveState(selection);
3382 void MapEditor::resizeEvent (QResizeEvent* e)
3384 QCanvasView::resizeEvent( e );
3387 if (!fileName.isEmpty()) s=fileName;
3392 MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3395 (typeid(*selection) == typeid(BranchObj)) ||
3396 (typeid(*selection) == typeid(MapCenterObj))) {
3398 // If QImageDrag can decode mime type
3399 if (QImageDrag::canDecode(event)) {
3404 // If image are drag from firefox
3405 if (event->provides("application/x-moz-file-promise-url") &&
3406 event->provides("application/x-moz-nativeimage")) {
3407 event->accept(true);
3416 MapEditor::contentsDropEvent(QDropEvent *event)
3419 if (event->provides("image/png")) {
3421 if (QImageDrag::decode(event, pix)) {
3427 } else if (event->provides("application/x-moz-file-promise-url") &&
3428 event->provides("application/x-moz-nativeimage")) {
3430 // Contains url to the img src in UTF-16
3431 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3432 QString url = QString((const QChar*)d.data(),d.size()/2);
3439 MapEditor::addFloatImage(const QPixmap &img)
3442 (typeid(*selection) == typeid(BranchObj)) ||
3443 (typeid(*selection) == typeid(MapCenterObj)) )
3445 BranchObj *bo=((BranchObj*)(selection));
3447 saveState(selection);
3448 //QString fn=fd->selectedFile();
3449 //lastImageDir=fn.left(fn.findRev ("/"));
3450 bo->addFloatImage();
3451 // FIXME check if load was successful
3452 bo->getLastFloatImage()->load(img);
3453 //bo->getLastFloatImage()->setOriginalFilename(fn);
3454 mapCenter->reposition();
3462 MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3464 if (!imageBuffer) imageBuffer = new QBuffer();
3465 if (!imageBuffer->isOpen()) {
3466 imageBuffer->open(IO_WriteOnly | IO_Append);
3468 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3473 MapEditor::imageDataFinished(QNetworkOperation *nop)
3475 imageBuffer->close();
3476 if (nop->state()==QNetworkProtocol::StDone) {
3477 QPixmap img(imageBuffer->buffer());
3486 MapEditor::fetchImage(const QString &url)
3489 urlOperator->stop();
3490 disconnect(urlOperator);
3494 urlOperator = new QUrlOperator(url);
3495 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3496 this, SLOT(imageDataFinished(QNetworkOperation*)));
3498 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3499 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));