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>
31 #include "texteditor.h"
32 #include "linkablemapobj.h"
35 #include "mainwindow.h"
36 #include "extrainfodialog.h"
37 #include "editxlinkdialog.h"
40 #include "icons/flag-note.xpm"
41 #include "icons/flag-url.xpm"
42 #include "icons/flag-vymlink.xpm"
43 #include "icons/flag-scrolled-right.xpm"
44 #include "icons/flag-tmpUnscrolled-right.xpm"
45 #include "icons/flag-questionmark.xpm"
46 #include "icons/flag-exclamationmark.xpm"
47 #include "icons/flag-hook-green.xpm"
48 #include "icons/flag-cross-red.xpm"
49 #include "icons/flag-stopsign.xpm"
50 #include "icons/flag-smiley-good.xpm"
51 #include "icons/flag-smiley-sad.xpm"
52 #include "icons/flag-clock.xpm"
53 #include "icons/flag-lamp.xpm"
54 #include "icons/flag-arrow-up.xpm"
55 #include "icons/flag-arrow-down.xpm"
56 #include "icons/flag-thumb-up.xpm"
57 #include "icons/flag-thumb-down.xpm"
58 #include "icons/flag-heart.xpm"
59 #include "icons/flag-flash.xpm"
60 #include "icons/flag-lifebelt.xpm"
62 extern TextEditor *textEditor;
63 extern int statusbarTime;
64 extern Main *mainWindow;
65 extern QString tmpVymDir;
66 extern FlagRowObj *systemFlagsDefault;
67 extern FlagRowObj *standardFlagsDefault;
68 extern MapEditor *clipboardME;
70 extern QPtrList <QAction> actionListBranches;
72 extern QAction *actionFileSave;
73 extern QAction *actionEditUndo;
74 extern QAction *actionEditCopy;
75 extern QAction *actionEditCut;
76 extern QAction *actionEditPaste;
77 extern QAction *actionEditMoveUp;
78 extern QAction *actionEditMoveDown;
79 extern QAction *actionEditToggleScroll;
80 extern QAction *actionEditOpenURL;
81 extern QAction *actionEditURL;
82 extern QAction *actionEditHeading2URL;
83 extern QAction *actionEditBugzilla2URL;
84 extern QAction *actionEditOpenVymLink;
85 extern QAction *actionEditVymLink;
86 extern QAction *actionEditDeleteVymLink;
87 extern QAction *actionEditHeading;
88 extern QAction *actionEditDelete;
89 extern QAction *actionEditAddBranch;
90 extern QAction *actionEditAddBranchAbove;
91 extern QAction *actionEditAddBranchBelow;
92 extern QAction *actionEditRemoveBranchHere;
93 extern QAction *actionEditRemoveChilds;
94 extern QAction *actionEditImportAdd;
95 extern QAction *actionEditImportReplace;
96 extern QAction *actionEditSaveBranch;
97 extern QAction *actionEditSelectFirst;
98 extern QAction *actionEditSelectLast;
99 extern QAction *actionEditLoadImage;
100 extern QAction *actionEditToggleFloatExport;
102 extern QAction* actionFormatPickColor;
103 extern QAction* actionFormatColorBranch;
104 extern QAction* actionFormatColorSubtree;
105 extern QAction *actionFormatLinkColorHint;
106 extern QAction *actionFormatBackColor;
107 extern QAction *actionFormatLinkColor;
109 extern QActionGroup* actionGroupModModes;
110 extern QAction* actionModModeColor;
111 extern QAction* actionModModeLink;
112 extern QAction* actionModModeCopy;
114 extern QActionGroup *actionGroupFormatFrameTypes;
115 extern QAction *actionFormatFrameNone;
116 extern QAction *actionFormatFrameRectangle;
118 extern QActionGroup *actionGroupFormatLinkStyles;
119 extern QAction *actionFormatHideLinkUnselected;
120 extern QAction *actionFormatLinkStyleLine;
121 extern QAction *actionFormatLinkStyleParabel;
122 extern QAction *actionFormatLinkStylePolyLine;
123 extern QAction *actionFormatLinkStylePolyParabel;
125 extern QAction *actionViewToggleNoteEditor;
127 extern QAction *actionSettingsAutoedit;
128 extern QAction *actionSettingsAutoselectHeading;
129 extern QAction *actionSettingsAutoselectText;
130 extern QAction *actionSettingsPasteNewHeading;
131 extern QAction *actionSettingsUseFlagGroups;
133 extern QPopupMenu *branchContextMenu;
134 extern QPopupMenu *branchLinksContextMenu;
135 extern QPopupMenu *branchLinksContextMenuDup;
136 extern QPopupMenu *floatimageContextMenu;
137 extern QPopupMenu *saveImageFormatMenu;
138 extern QPopupMenu *exportImageFormatMenu;
139 extern QPopupMenu *canvasContextMenu;
141 extern Settings settings;
143 int MapEditor::mapNum=0; // make instance
145 ///////////////////////////////////////////////////////////////////////
146 ///////////////////////////////////////////////////////////////////////
147 MapEditor::MapEditor(
148 QWidget* parent, bool interactive, const char* name, WFlags f) :
149 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
151 //cout << "Constructor ME "<<this<<endl;
154 viewport()->setAcceptDrops(true);
156 mapCanvas = new QCanvas(1000,800);
157 mapCanvas->setAdvancePeriod(30);
159 setCanvas (mapCanvas);
161 // Always show scroll bars (automatic would flicker sometimes)
162 setVScrollBarMode ( QScrollView::AlwaysOn );
163 setHScrollBarMode ( QScrollView::AlwaysOn );
165 // Now create the _global_ system flags _once_:
166 // (Later all OrnamentedObj copy from this
167 // and set their own canvas)
168 if (!systemFlagsDefault)
170 systemFlagsDefault = new FlagRowObj (mapCanvas);
171 systemFlagsDefault->setVisibility (false);
172 systemFlagsDefault->setName ("systemFlagsDef");
174 FlagObj *fo = new FlagObj (mapCanvas);
175 fo->load(QPixmap(flag_note_xpm));
177 fo->setToolTip(tr("Note","Systemflag"));
178 systemFlagsDefault->addFlag (fo); // makes deep copy
180 fo->load(QPixmap(flag_url_xpm));
182 fo->setToolTip(tr("WWW Document (external)","Systemflag"));
183 systemFlagsDefault->addFlag (fo);
185 fo->load(QPixmap(flag_vymlink_xpm));
186 fo->setName("vymLink");
187 fo->setToolTip(tr("Link to another vym map","Systemflag"));
188 systemFlagsDefault->addFlag (fo);
190 fo->load(QPixmap(flag_scrolled_right_xpm));
191 fo->setName("scrolledright");
192 fo->setToolTip(tr("subtree is scrolled","Systemflag"));
193 systemFlagsDefault->addFlag (fo);
195 fo->load(QPixmap(flag_tmpUnscrolled_right_xpm));
196 fo->setName("tmpUnscrolledright");
197 fo->setToolTip(tr("subtree is temporary scrolled","Systemflag"));
198 systemFlagsDefault->addFlag (fo);
201 if (!standardFlagsDefault)
203 standardFlagsDefault = new FlagRowObj (mapCanvas);
204 standardFlagsDefault->setVisibility (false);
205 standardFlagsDefault->setName ("standardFlagsDef");
207 FlagObj *fo = new FlagObj (mapCanvas);
208 fo->load(QPixmap(flag_exclamationmark_xpm));
209 fo->setName ("exclamationmark");
210 fo->setGroup("standard-mark");
211 fo->setToolTip(tr("Take care!","Standardflag"));
212 standardFlagsDefault->addFlag (fo); // makes deep copy
214 fo->load(QPixmap(flag_questionmark_xpm));
215 fo->setName("questionmark");
216 fo->setGroup("standard-mark");
217 fo->setToolTip(tr("Really?","Standardflag"));
218 standardFlagsDefault->addFlag (fo);
220 fo->load(QPixmap(flag_hook_green_xpm));
221 fo->setName("hook-green");
222 fo->setGroup("standard-hook");
223 fo->setToolTip(tr("ok!","Standardflag"));
224 standardFlagsDefault->addFlag (fo);
226 fo->load(QPixmap(flag_cross_red_xpm));
227 fo->setName("cross-red");
228 fo->setGroup("standard-hook");
229 fo->setToolTip(tr("Not ok!","Standardflag"));
230 standardFlagsDefault->addFlag (fo);
232 fo->load(QPixmap(flag_stopsign_xpm));
233 fo->setName("stopsign");
234 fo->setToolTip(tr("This won't work!","Standardflag"));
235 standardFlagsDefault->addFlag (fo);
237 fo->load(QPixmap(flag_smiley_good_xpm));
238 fo->setName("smiley-good");
239 fo->setGroup("standard-smiley");
240 fo->setToolTip(tr("Good","Standardflag"));
241 standardFlagsDefault->addFlag (fo);
243 fo->load(QPixmap(flag_smiley_sad_xpm));
244 fo->setName("smiley-sad");
245 fo->setGroup("standard-smiley");
246 fo->setToolTip(tr("Bad","Standardflag"));
247 standardFlagsDefault->addFlag (fo);
249 fo->load(QPixmap(flag_clock_xpm));
250 fo->setName("clock");
251 fo->setToolTip(tr("Time critical","Standardflag"));
252 standardFlagsDefault->addFlag (fo);
254 fo->load(QPixmap(flag_lamp_xpm));
256 fo->setToolTip(tr("Idea!","Standardflag"));
257 standardFlagsDefault->addFlag (fo);
259 fo->load(QPixmap(flag_arrow_up_xpm));
260 fo->setName("arrow-up");
261 fo->setGroup("standard-arrow");
262 fo->setToolTip(tr("Important","Standardflag"));
263 standardFlagsDefault->addFlag (fo);
265 fo->load(QPixmap(flag_arrow_down_xpm));
266 fo->setName("arrow-down");
267 fo->setGroup("standard-arrow");
268 fo->setToolTip(tr("Unimportant","Standardflag"));
269 standardFlagsDefault->addFlag (fo);
271 fo->load(QPixmap(flag_thumb_up_xpm));
272 fo->setName("thumb-up");
273 fo->setGroup("standard-thumb");
274 fo->setToolTip(tr("I like this","Standardflag"));
275 standardFlagsDefault->addFlag (fo);
277 fo->load(QPixmap(flag_thumb_down_xpm));
278 fo->setName("thumb-down");
279 fo->setGroup("standard-thumb");
280 fo->setToolTip(tr("I like this","Standardflag"));
281 fo->setToolTip(tr("I do not like this","Standardflag"));
282 standardFlagsDefault->addFlag (fo);
284 fo->load(QPixmap(flag_heart_xpm));
285 fo->setName("heart");
286 fo->setToolTip(tr("I just love... ","Standardflag"));
287 standardFlagsDefault->addFlag (fo);
289 fo->load(QPixmap(flag_flash_xpm));
290 fo->setName("flash");
291 fo->setToolTip(tr("Dangerous","Standardflag"));
292 standardFlagsDefault->addFlag (fo);
294 fo->load(QPixmap(flag_lifebelt_xpm));
295 fo->setName("lifebelt");
296 fo->setToolTip(tr("This will help","Standardflag"));
297 standardFlagsDefault->addFlag (fo);
302 mapCenter = new MapCenterObj(mapCanvas);
303 mapCenter->setVisibility (true);
304 mapCenter->setMapEditor (this);
305 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
309 lineedit = new QLineEdit(this, "lineedit" );
310 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
313 actColor=black; setColor (actColor);
314 defLinkColor=QColor (0,0,255);
315 defXLinkColor=QColor (180,180,180);
316 linkcolorhint=DefaultColor;
317 linkstyle=StylePolyParabel;
318 mapCanvas->setBackgroundColor (white);
320 // Create bitmap cursors, patform dependant
321 #if defined(Q_OS_MACX)
322 #include "icons/cursorhandopen16.xpm"
323 #include "icons/cursorcolorpicker16.xpm"
324 QBitmap cb( 16, 16, chandopen, TRUE );
325 QBitmap cm( 16, 16, chandopenmask, TRUE );
326 handOpenCursor=QCursor ( cb, cm );
327 // set hot spot to tip of picker
328 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
330 #include "icons/cursorhandopen.xpm"
331 #include "icons/cursorcolorpicker.xpm"
333 QBitmap cb( 32, 32, chandopen, TRUE );
334 QBitmap cm( 32, 32, chandopenmask, TRUE );
335 handOpenCursor=QCursor ( cb, cm );
336 // set hot spot to tip of picker
337 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
350 defXLinkColor=QColor (230,230,230);
361 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
365 // Initialize find routine
372 blockReposition=false;
373 blockSaveState=false;
374 isInteractive=interactive;
376 // Create temporary files
379 // Initially set movingCentre
382 mapCenter->reposition(); // for positioning heading
385 MapEditor::~MapEditor()
387 if (imageBuffer) delete imageBuffer;
393 //cout <<"Destructor MapEditor\n";
396 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
400 QColor MapEditor::color()
405 QColor MapEditor::backgroundColor()
407 return mapCanvas->backgroundColor();
410 MapCenterObj* MapEditor::getMapCenter()
415 QCanvas* MapEditor::getCanvas()
420 void MapEditor::adjustCanvasSize()
422 // To adjust the canvas to map, viewport size and position, we have to
423 // do some coordinate magic...
425 // Get rectangle of (scroll-)view.
426 // We want to be in canvas coords, so
427 // we map. Important if view is zoomed...
428 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
429 visibleWidth(), visibleHeight()) );
431 // Now we need the bounding box of view AND map to calc the correct canvas size.
432 // Why? Because if the map itself is moved out of view, the view has to be enlarged
433 // to avoid jumping aroung...
434 QRect map=mapCenter->getTotalBBox();
436 // right edge - left edge
437 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
438 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
441 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
442 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
445 // move the map on canvas (in order to not move it on screen) this is neccessary
446 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
447 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
448 // to scroll to an empty area of canvas to the left.
449 // b) if topleft corner of map left of or above topleft of canvas
453 if (cw > mapCanvas->width() )
455 if (map.x()<0) dx=-map.x();
457 if (cw < mapCanvas->width() )
458 dx=-min (view.x(),map.x());
459 if (ch > mapCanvas->height() )
461 if (map.y()<0) dy=-map.y();
463 if (ch < mapCanvas->height() )
465 dy=-min (view.y(),map.y());
467 // We really have to resize now. Let's go...
468 mapCanvas->resize (cw,ch);
469 if ( (dx!=0) || (dy!=0) )
471 mapCenter->moveAllBy(dx,dy);
472 mapCenter->reposition();
474 // scroll the view (in order to not move map on screen)
480 bool MapEditor::isRepositionBlocked()
482 return blockReposition;
485 void MapEditor::makeTmpDirs()
487 // Create unique temporary directories
488 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
490 d.mkdir (tmpMapDir,true);
493 void MapEditor::delTmpDirs()
495 removeDir (QDir(tmpMapDir));
499 void MapEditor::makeSubDirs(const QString &s)
508 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
510 // tmpdir temporary directory to which data will be written
511 // prefix mapname, which will be appended to images etc.
512 // writeflags Only write flags for "real" save of map, not undo
513 // offset offset of bbox of whole map in canvas.
514 // Needed for XML export
515 // completeMap if false, only vympart will be written, without
532 ls="StylePolyParabel";
536 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
538 if (linkcolorhint==HeadingColor)
539 colhint=attribut("linkColorHint","HeadingColor");
541 QString mapAttr=attribut("version",__VYM_VERSION__);
543 mapAttr+= attribut("author",mapCenter->getAuthor()) +
544 attribut("comment",mapCenter->getComment()) +
545 attribut("date",mapCenter->getDate()) +
546 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
547 attribut("linkStyle", ls ) +
548 attribut("linkColor", defLinkColor.name() ) +
549 attribut("defXLinkColor", defXLinkColor.name() ) +
550 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
552 s+=beginElement("vymmap",mapAttr);
555 // Find the used flags while traversing the tree
556 standardFlagsDefault->resetUsedCounter();
558 // Build xml recursivly
560 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
563 if ( typeid(*saveSelection) == typeid(BranchObj) )
564 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
566 if (selection && typeid(*selection)==typeid(BranchObj))
567 // This is used if selected branch is saved from mainwindow
568 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
571 // Save local settings
572 s+=settings.getXMLData (destPath);
575 if (selection && !saveSelection )
576 s+=valueElement("select",selection->getSelectString());
579 s+=endElement("vymmap");
582 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
586 void MapEditor::saveState()
589 saveState (CompleteMap,"",NULL,"",NULL);
592 void MapEditor::saveState(LinkableMapObj *undoSel)
594 // save the given part of the map
595 saveState (PartOfMap,"",undoSel,"",NULL);
598 void MapEditor::saveState(const QString &uc, const QString &rc)
600 // selection does not change during action,
601 // so just save commands for undo and redo
602 LinkableMapObj *unsel;
607 saveState (UndoCommand,uc,unsel,rc,unsel);
610 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel)
612 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL);
615 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel)
619 if (blockSaveState) return;
621 /* TODO remove after testing
622 cout << "ME::saveState() begin\n"<<endl;
623 cout << " undosTotal="<<undosTotal<<endl;
624 cout << " undosAvail="<<undosAvail<<endl;
625 cout << " undoNum="<<undoNum<<endl;
626 cout << " ---------------------------"<<endl;
630 // Find out current undo directory
631 if (undosAvail<undosTotal) undosAvail++;
633 if (undoNum>undosTotal) undoNum=1;
636 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
637 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
639 // Create bakMapDir if not available
642 makeSubDirs (bakMapDir);
644 // Save current selection
645 QString redoSelection="";
647 redoSelection=redoSel->getSelectString();
649 // Save the object, which should be undone
650 QString undoSelection="";
652 undoSelection=undoSel->getSelectString();
654 // Save depending on how much needs to be saved
655 QString undoCommand="";
656 if (savemode==UndoCommand)
661 else if (savemode==PartOfMap && undoSel)
663 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
664 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
667 undoCommand="undoMap (\""+bakMapPath+"\")";
668 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
671 if (!backupXML.isEmpty())
672 // Write XML Data to disk
673 saveStringToDisk (QString(bakMapPath),backupXML);
676 set.setEntry (QString("undoCommand"),undoCommand);
677 set.setEntry (QString("undoSelection"),undoSelection);
678 set.setEntry (QString("redoCommand"),redoCom);
679 set.setEntry (QString("redoSelection"),redoSelection);
680 set.writeSettings(QString(bakMapDir+"/commands"));
682 /* TODO remove after testing
683 cout << " into="<< bakMapDir<<endl;
684 cout << " undosAvail="<<undosAvail<<endl;
685 cout << " undoNum="<<undoNum<<endl;
686 cout << " ---------------------------"<<endl;
687 cout << " undoCom="<<undoCommand<<endl;
688 cout << " undoSel="<<undoSelection<<endl;
689 cout << " ---------------------------"<<endl;
690 cout << " redoCom="<<redoCom<<endl;
691 cout << " redoSel="<<redoSelection<<endl;
692 cout << " ---------------------------"<<endl<<endl;
696 void MapEditor::parseAtom(const QString &atom)
703 // Split string s into command and parameters
704 api.parseCommand (atom);
705 QString com=api.command();
708 if (com=="moveBranchUp")
710 else if (com=="moveBranchDown")
712 else if (com=="move")
714 if (api.checkParamCount(2) && selection )
724 else if (com=="linkBranchToPos")
726 if (selection && typeid(*selection) == typeid(BranchObj) )
728 if (api.checkParamCount(4))
730 s=api.parString(ok,0);
731 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
734 if (typeid(*dst) == typeid(BranchObj) )
736 // Get number in parent
739 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
740 } else if (typeid(*dst) == typeid(MapCenterObj) )
742 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
743 // Get coordinates of mainbranch
748 if (ok) ((BranchObj*)selection)->move (x,y);
754 } else if (com=="setHeading")
756 if (api.checkParamCount(1))
758 s=api.parString (ok,0);
759 if (ok) setHeading (s);
761 } else if (com=="setURL")
763 if (api.checkParamCount(1))
765 s=api.parString (ok,0);
768 } else if (com=="setVymLink")
770 if (api.checkParamCount(1))
772 s=api.parString (ok,0);
773 if (ok) setVymLink(s);
776 // Internal commands, used for undo etc.
777 else if (com==QString("undoMap"))
779 if (api.checkParamCount(1))
780 undoXML("",api.parString (ok,0));
781 } else if (com==QString("undoPart"))
783 if (api.checkParamCount(2))
785 s=api.parString (ok,0);
786 t=api.parString (ok,1);
789 } else if (com=="select")
790 if (api.checkParamCount(1))
792 s=api.parString(ok,0);
797 api.setError ("Unknown command in: "+atom);
798 cout << "ME::parse api should have error now...\n";
804 cout << "MapEditor::parseAtom: Error!\n";
805 cout << " "<<api.errorDesc()<<endl;
810 void MapEditor::finishedLineEditNoSave()
812 // This is called by finishedLineEdit or any MapEditor method,
813 // which wants to assure, that lineedits finish, before e.g. a branch is
816 // After calling LineEdit and using the clipboard, the
817 // focus is not any longer on the main widget, we
818 // have to restore it using parentWidget()->setFocus()
822 editingBO->setHeading(lineedit->text() );
824 lineedit->releaseKeyboard();
826 parentWidget()->setFocus();
827 mapCenter->reposition();
829 ensureSelectionVisible();
834 bool MapEditor::isDefault()
839 bool MapEditor::isUnsaved()
844 bool MapEditor::hasChanged()
849 void MapEditor::setChanged()
854 actionEditUndo->setEnabled (true);
855 actionFileSave->setEnabled (true);
859 void MapEditor::closeMap()
861 // Finish open lineEdits
862 if (lineedit) finishedLineEditNoSave();
864 // Unselect before disabling the toolbar actions
865 if (selection) selection->unselect();
873 void MapEditor::setFilePath(QString fname)
875 setFilePath (fname,fname);
878 void MapEditor::setFilePath(QString fname, QString destname)
887 filePath=fname; // becomes absolute path
888 fileName=fname; // gets stripped of path
889 destPath=destname; // needed for vymlinks
891 // If fname is not an absolute path, complete it
892 filePath=QDir(fname).absPath();
893 fileDir=filePath.left (1+filePath.findRev ("/"));
895 // Set short name, too. Search from behind:
896 int i=fileName.findRev("/");
897 if (i>=0) fileName=fileName.remove (0,i+1);
899 // Forget the .vym (or .xml) for name of map
900 mapName=fileName.left(fileName.findRev(".",-1,true) );
904 QString MapEditor::getFilePath()
909 QString MapEditor::getFileName()
914 QString MapEditor::getMapName()
919 QString MapEditor::getDestPath()
924 int MapEditor::load (QString &fname, const LoadMode &lmode)
926 // Finish open lineEdits
927 if (lineedit) finishedLineEditNoSave();
933 if (selection) selection->unselect();
936 mapCenter->setMapEditor(this);
937 // (map state is set later at end of load...)
940 saveState(selection);
944 mapBuilderHandler handler;
947 // I am paranoid: file should exist anyway
948 // according to check in mainwindow.
951 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
952 tr("Couldn't open map " +fname)+".");
956 blockReposition=true;
957 QXmlInputSource source( file);
958 QXmlSimpleReader reader;
959 reader.setContentHandler( &handler );
960 reader.setErrorHandler( &handler );
961 handler.setMapEditor( this );
962 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
963 handler.setLoadMode (lmode);
965 bool ok = reader.parse( source );
966 blockReposition=false;
967 blockSaveState=false;
971 mapCenter->reposition();
981 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
982 tr( handler.errorProtocol() ) );
984 // Still return "success": the map maybe at least
985 // partially read by the parser
992 int MapEditor::save (const SaveMode &savemode)
994 // Finish open lineEdits
995 if (lineedit) finishedLineEditNoSave();
999 // The SaveMode UndoCommand is not supported here
1000 if (savemode==UndoCommand) return 1;
1002 // Create mapName and fileDir
1003 makeSubDirs (fileDir);
1007 fname=mapName+".xml";
1009 // use name given by user, even if he chooses .doc
1014 if (savemode==CompleteMap || selection==NULL)
1015 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
1017 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
1019 if (!saveStringToDisk(fileDir+fname,saveFile))
1026 actionFileSave->setEnabled(false);
1032 void MapEditor::setZipped (bool z)
1037 bool MapEditor::saveZipped ()
1042 void MapEditor::print()
1044 // Finish open lineEdits
1045 if (lineedit) finishedLineEditNoSave();
1049 printer = new QPrinter;
1050 printer->setColorMode (QPrinter::Color);
1051 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
1054 QRect totalBBox=mapCenter->getTotalBBox();
1056 // Try to set orientation automagically
1057 // Note: Interpretation of generated postscript is amibiguous, if
1058 // there are problems with landscape mode, see
1059 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1061 if (totalBBox.width()>totalBBox.height())
1062 // recommend landscape
1063 printer->setOrientation (QPrinter::Landscape);
1065 // recommend portrait
1066 printer->setOrientation (QPrinter::Portrait);
1068 if ( printer->setup(this) )
1069 // returns false, if printing is canceled
1071 QPainter pp(printer);
1073 // Don't print the visualisation of selection
1074 LinkableMapObj *oldselection=NULL;
1077 oldselection=selection;
1078 selection->unselect();
1081 // Handle sizes of map and paper:
1083 // setWindow defines which part of the canvas will be transformed
1084 // setViewport defines area on paper in device coordinates (dpi)
1085 // e.g. (0,50,700,700) is upper part on A4
1086 // see also /usr/lib/qt3/doc/html/coordsys.html
1088 QPaintDeviceMetrics metrics (printer);
1090 double paperAspect = (double)metrics.width() / (double)metrics.height();
1091 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1093 QRect mapRect=totalBBox;
1094 QCanvasRectangle *frame=NULL;
1095 QCanvasText *footerFN=NULL;
1096 QCanvasText *footerDate=NULL;
1097 if (printFrame || printFooter)
1102 // Print frame around map
1103 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1104 totalBBox.width()+20, totalBBox.height()+20);
1105 frame=new QCanvasRectangle (mapRect,mapCanvas);
1106 frame->setBrush (QColor(white));
1107 frame->setPen (QColor(black));
1111 /* TODO remove after testing
1112 QCanvasLine *l=new QCanvasLine (mapCanvas);
1113 l->setPoints (0,0,mapRect.width(),mapRect.height());
1114 l->setPen (QPen(QColor(black), 1));
1121 // Print footer below map
1123 font.setPointSize(10);
1124 footerFN=new QCanvasText (mapCanvas);
1125 footerFN->setText ("VYM - " + fileName);
1126 footerFN->setFont(font);
1127 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1128 footerFN->setZ(Z_TEXT);
1130 footerDate=new QCanvasText (mapCanvas);
1131 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1132 footerDate->setFont(font);
1133 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1134 footerDate->setZ(Z_TEXT);
1137 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1140 pp.setWindow (mapRect);
1143 if (mapAspect>=paperAspect)
1145 // Fit horizontally to paper width
1146 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1149 // Fit vertically to paper height
1150 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1153 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1155 // Delete Frame and footer
1159 delete (footerDate);
1161 if (frame) delete (frame);
1163 // Restore selection
1166 selection=oldselection;
1167 selection->select();
1170 // Save settings in vymrc
1171 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1175 QPixmap MapEditor::getPixmap()
1177 QRect mapRect=mapCenter->getTotalBBox();
1178 QPixmap pix (mapRect.size());
1181 // Don't print the visualisation of selection
1182 LinkableMapObj *oldselection=NULL;
1185 oldselection=selection;
1186 selection->unselect();
1189 pp.setWindow (mapRect);
1191 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1194 // Restore selection
1197 selection=oldselection;
1198 selection->select();
1204 void MapEditor::exportImage(QString fn)
1206 // Finish open lineEdits
1207 if (lineedit) finishedLineEditNoSave();
1209 QPixmap pix (getPixmap());
1210 pix.save(fn, "PNG");
1213 void MapEditor::exportImage(QString fn, int item)
1215 // Finish open lineEdits
1216 if (lineedit) finishedLineEditNoSave();
1218 QPixmap pix (getPixmap());
1219 pix.save(fn, exportImageFormatMenu->text(item) );
1222 void MapEditor::exportASCII()
1224 // TODO still experimental
1226 ex.setMapCenter(mapCenter);
1228 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)"));
1229 fd->addFilter ("TXT (*.txt)");
1230 fd->setCaption("VYM - Export (ASCII) (still experimental)");
1231 fd->setMode( QFileDialog::AnyFile );
1234 if ( fd->exec() == QDialog::Accepted )
1236 if (QFile (fd->selectedFile()).exists() )
1238 QMessageBox mb( "VYM",
1239 tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
1240 QMessageBox::Warning,
1241 QMessageBox::Yes | QMessageBox::Default,
1242 QMessageBox::Cancel | QMessageBox::Escape,
1243 QMessageBox::NoButton );
1245 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1246 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1250 case QMessageBox::Yes:
1253 case QMessageBox::Cancel:
1254 // return, do nothing
1259 ex.setPath (fd->selectedFile() );
1264 void MapEditor::exportLaTeX()
1266 // TODO still experimental
1267 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (LaTex)"));
1268 fd->addFilter ("TEX (*.tex)");
1269 fd->setCaption("VYM - Export (LaTex) (still experimental)");
1270 fd->setMode( QFileDialog::AnyFile );
1273 if ( fd->exec() == QDialog::Accepted )
1275 if (QFile (fd->selectedFile()).exists() )
1277 QMessageBox mb( "VYM",
1278 tr("The file ") + fd->selectedFile() +
1279 tr(" exists already. Do you want to overwrite it?"),
1280 QMessageBox::Warning,
1281 QMessageBox::Yes | QMessageBox::Default,
1282 QMessageBox::Cancel | QMessageBox::Escape,
1283 QMessageBox::NoButton );
1285 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1286 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1290 case QMessageBox::Yes:
1293 case QMessageBox::Cancel:
1300 ex.setPath (fd->selectedFile() );
1301 ex.setMapCenter(mapCenter);
1306 void MapEditor::exportOOPresentation()
1308 // TODO still experimental
1310 QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (Open Office 1.3.x Presentation)"));
1311 fd->addFilter ("Open Office 1.3.x presentation (*.sxi)");
1312 fd->setCaption("VYM - Export (Open Office 1.3.x presentation) (still experimental)");
1313 fd->setMode( QFileDialog::AnyFile );
1316 if ( fd->exec() == QDialog::Accepted )
1318 if (QFile (fd->selectedFile()).exists() )
1320 QMessageBox mb( "VYM",
1321 tr("The file ") + fd->selectedFile() +
1322 tr(" exists already. Do you want to overwrite it?"),
1323 QMessageBox::Warning,
1324 QMessageBox::Yes | QMessageBox::Default,
1325 QMessageBox::Cancel | QMessageBox::Escape,
1326 QMessageBox::NoButton );
1328 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
1329 mb.setButtonText( QMessageBox::No, tr("Cancel"));
1333 case QMessageBox::Yes:
1336 case QMessageBox::Cancel:
1344 //ex.setPath (fd->selectedFile() );
1345 ex.setMapCenter(mapCenter);
1346 ex.exportOOPresentation();
1352 void MapEditor::exportXML(const QString &dir)
1354 // Create subdirectories
1357 // write to directory
1358 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1361 file.setName ( dir + "/"+mapName+".xml");
1362 if ( !file.open( IO_WriteOnly ) )
1364 // This should neverever happen
1365 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1369 // Write it finally, and write in UTF8, no matter what
1370 QTextStream ts( &file );
1371 ts.setEncoding (QTextStream::UnicodeUTF8);
1375 // Now write image, too
1376 exportImage (dir+"/images/"+mapName+".png");
1379 void MapEditor::clear()
1383 selection->unselect();
1390 void MapEditor::copy()
1392 // Finish open lineEdits
1393 if (lineedit) finishedLineEditNoSave();
1397 if (typeid(*selection) == typeid(BranchObj) )
1401 clipboardME->clear();
1402 clipboardME->getMapCenter()->addBranch();
1403 to=clipboardME->getMapCenter()->getLastBranch();
1406 from=(BranchObj*)selection;
1409 // keep position relative to parent
1410 to->move2RelPos ( from->getRelPos());
1412 // select data in clipboard
1413 clipboardME->select ("bo:0");
1415 // repositioning makes testing nicer,
1416 // but is not needed usually:
1417 if (clipboardME->isVisible())
1418 clipboardME->getMapCenter()->reposition();
1420 clipboardME->hide();
1423 if (typeid(*selection) == typeid(FloatImageObj) )
1426 FloatImageObj* from;
1427 clipboardME->clear();
1428 clipboardME->getMapCenter()->addFloatImage();
1429 to=clipboardME->getMapCenter()->getLastFloatImage();
1432 from=(FloatImageObj*)selection;
1435 // select data in clipboard
1436 clipboardME->select ("fi:0");
1438 // repositioning makes testing nicer,
1439 // but is not needed usually:
1440 if (clipboardME->isVisible())
1441 clipboardME->getMapCenter()->reposition();
1443 clipboardME->hide();
1449 void MapEditor::redo()
1451 // Finish open lineEdits
1452 if (lineedit) finishedLineEditNoSave();
1454 blockSaveState=true;
1456 // Find out current undo directory
1457 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1459 // Restore variables
1460 QString undoCommand;
1461 QString undoSelection;
1462 QString redoCommand;
1463 QString redoSelection;
1465 set.readSettings(QString(bakMapDir+"/commands"));
1466 undoCommand=set.readEntry ("undoCommand");
1467 undoSelection=set.readEntry ("undoSelection");
1468 redoCommand=set.readEntry ("redoCommand");
1469 redoSelection=set.readEntry ("redoSelection");
1471 // select object before redo
1472 if (!redoSelection.isEmpty())
1473 select (redoSelection);
1475 /* TODO remove testing
1476 cout << "ME::redo() begin\n";
1477 cout << " undosTotal="<<undosTotal<<endl;
1478 cout << " undosAvail="<<undosAvail<<endl;
1479 cout << " undoNum="<<undoNum<<endl;
1480 cout << " ---------------------------"<<endl;
1481 cout << " undoCom="<<undoCommand<<endl;
1482 cout << " undoSel="<<undoSelection<<endl;
1483 cout << " ---------------------------"<<endl;
1484 cout << " redoCom="<<redoCommand<<endl;
1485 cout << " redoSel="<<redoSelection<<endl;
1486 cout << " ---------------------------"<<endl;
1488 parseAtom (undoCommand);
1489 mapCenter->reposition();
1491 //if (!redoSelection.isEmpty())
1492 // select (redoSelection);
1496 // Undo not longer available now
1497 actionEditUndo->setEnabled (false);
1499 undoNum--; if (undoNum<1) undoNum=undosTotal;
1501 blockSaveState=false;
1502 /* TODO remove testing
1503 cout << "ME::redo() end\n";
1504 cout << " undosAvail="<<undosAvail<<endl;
1505 cout << " undoNum="<<undoNum<<endl;
1506 cout << " ---------------------------"<<endl<<endl;
1510 void MapEditor::undo()
1512 // Finish open lineEdits
1513 if (lineedit) finishedLineEditNoSave();
1515 blockSaveState=true;
1517 // Find out current undo directory
1518 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1520 // Restore variables
1521 QString undoCommand;
1522 QString undoSelection;
1523 QString redoCommand;
1524 QString redoSelection;
1526 set.readSettings(QString(bakMapDir+"/commands"));
1527 undoCommand= set.readEntry ("undoCommand");
1528 undoSelection=set.readEntry ("undoSelection");
1529 redoCommand= set.readEntry ("redoCommand");
1530 redoSelection=set.readEntry ("redoSelection");
1532 // select object before undo
1533 if (!undoSelection.isEmpty())
1534 select (undoSelection);
1537 cout << "ME::undo() begin\n";
1538 cout << " undosTotal="<<undosTotal<<endl;
1539 cout << " undosAvail="<<undosAvail<<endl;
1540 cout << " undoNum="<<undoNum<<endl;
1541 cout << " ---------------------------"<<endl;
1542 cout << " undoCom="<<undoCommand<<endl;
1543 cout << " undoSel="<<undoSelection<<endl;
1544 cout << " ---------------------------"<<endl;
1545 cout << " redoCom="<<redoCommand<<endl;
1546 cout << " redoSel="<<redoSelection<<endl;
1547 cout << " ---------------------------"<<endl;
1549 parseAtom (undoCommand);
1550 mapCenter->reposition();
1552 //if (!redoSelection.isEmpty())
1553 // select (redoSelection);
1557 // Undo not longer available now
1558 actionEditUndo->setEnabled (false);
1560 undoNum--; if (undoNum<1) undoNum=undosTotal;
1562 blockSaveState=false;
1563 /* TODO remove testing
1564 cout << "ME::undo() end\n";
1565 cout << " undosAvail="<<undosAvail<<endl;
1566 cout << " undoNum="<<undoNum<<endl;
1567 cout << " ---------------------------"<<endl<<endl;
1571 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1573 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1575 QFile file (bakMapPath);
1579 // We need to parse saved XML data
1580 mapBuilderHandler handler;
1581 QXmlInputSource source( file);
1582 QXmlSimpleReader reader;
1583 reader.setContentHandler( &handler );
1584 reader.setErrorHandler( &handler );
1585 handler.setMapEditor( this );
1586 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1587 if (undoSel.isEmpty())
1591 handler.setLoadMode (NewMap);
1595 handler.setLoadMode (ImportReplace);
1597 blockReposition=true;
1598 bool ok = reader.parse( source );
1599 blockReposition=false;
1602 // This should never ever happen
1603 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1604 tr( handler.errorProtocol() )+" in "+bakMapDir );
1608 QMessageBox::critical( 0, tr( "Critical Error" ),
1609 tr("Temporary directory %1 used for undo is gone. \n"
1610 "I will create a new one, but at the moment no undo is available.\n"
1611 "Maybe you want to reload your original data.\n\n"
1612 "Sorry for any inconveniences.").arg(bakMapDir) );
1617 LinkableMapObj* MapEditor::pasteNoSave()
1619 // Finish open lineEdits
1620 if (lineedit) finishedLineEditNoSave();
1622 LinkableMapObj *fromLMO=clipboardME->getSelection();
1623 LinkableMapObj *returnLMO=NULL;
1625 if (selection && fromLMO)
1627 if (typeid(*fromLMO) == typeid(BranchObj) )
1629 if (typeid(*selection) == typeid(MapCenterObj))
1631 returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) );
1632 ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) );
1634 if (typeid(*selection) == typeid(BranchObj))
1635 returnLMO=((BranchObj*)selection)->addBranch((BranchObj*)(fromLMO) );
1638 if (typeid(*fromLMO) == typeid(FloatImageObj) &&
1639 (typeid(*selection) == typeid (BranchObj) ||
1640 typeid(*selection)==typeid(MapCenterObj)) )
1641 returnLMO=((BranchObj*) selection)->addFloatImage ((FloatImageObj*)(fromLMO));
1647 void MapEditor::cutNoSave()
1649 // Finish open lineEdits
1650 if (lineedit) finishedLineEditNoSave();
1654 if (selection != NULL) {
1655 if (typeid(*selection) == typeid(BranchObj) )
1657 bo=(BranchObj*)selection;
1658 par=(BranchObj*)(bo->getParObj());
1661 par->removeBranch(bo);
1663 selection->select();
1665 if (typeid(*selection) == typeid(FloatImageObj) )
1667 FloatImageObj* fio=(FloatImageObj*)selection;
1668 par=(BranchObj*)(fio->getParObj());
1671 par->removeFloatImage(fio);
1673 selection->select();
1678 void MapEditor::paste()
1680 saveState(selection);
1682 mapCenter->reposition();
1686 void MapEditor::cut()
1688 saveState(selection->getParObj());
1691 mapCenter->reposition();
1695 void MapEditor::move(const int &x, const int &y)
1697 // TODO no saveState, because this is only internal at undo so far
1698 if (selection) selection->move(x,y);
1699 if (typeid(*selection) == typeid(FloatImageObj))
1700 ((FloatImageObj*)selection)->setRelPos();
1703 void MapEditor::moveBranchUp()
1705 // Finish open lineEdits
1706 if (lineedit) finishedLineEditNoSave();
1710 if (typeid(*selection) == typeid(BranchObj) )
1712 bo=(BranchObj*)selection;
1713 par=(BranchObj*)(bo->getParObj());
1714 selection->unselect();
1715 selection=par->moveBranchUp (bo);
1716 selection->select();
1717 saveState("moveBranchDown ()",bo);
1718 mapCenter->reposition();
1719 ensureSelectionVisible();
1723 void MapEditor::moveBranchDown()
1725 // Finish open lineEdits
1726 if (lineedit) finishedLineEditNoSave();
1730 if (typeid(*selection) == typeid(BranchObj) )
1732 bo=(BranchObj*)selection;
1733 par=(BranchObj*)(bo->getParObj());
1734 selection->unselect();
1735 selection=par->moveBranchDown(bo);
1736 selection->select();
1737 saveState("moveBranchUp ()",bo);
1738 mapCenter->reposition();
1739 ensureSelectionVisible();
1743 void MapEditor::editHeading()
1745 // Finish open lineEdits
1746 if (lineedit) finishedLineEditNoSave();
1749 (typeid(*selection) == typeid(BranchObj) ||
1750 typeid(*selection) == typeid(MapCenterObj) ) )
1752 editingBO=(BranchObj*)selection;
1753 saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
1755 ensureSelectionVisible();
1756 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1757 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1758 QString s=editingBO->getHeading();
1759 lineedit->setText(s);
1760 lineedit->setCursorPosition(1);
1761 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1762 lineedit->selectAll();
1764 lineedit->grabKeyboard();
1765 lineedit->setFocus();
1769 void MapEditor::setHeading(const QString &s)
1771 // Internal function, no saveState needed
1773 (typeid(*selection) == typeid(BranchObj) ||
1774 typeid(*selection) == typeid(MapCenterObj) ) )
1776 ((BranchObj*)selection)->setHeading(s);
1777 mapCenter->reposition();
1779 ensureSelectionVisible();
1783 void MapEditor::setURL (const QString &s)
1785 // Internal function, no saveState needed
1787 (typeid(*selection) == typeid(BranchObj) ||
1788 typeid(*selection) == typeid(MapCenterObj) ) )
1790 ((BranchObj*)selection)->setURL(s);
1791 mapCenter->reposition();
1793 ensureSelectionVisible();
1797 void MapEditor::setVymLink (const QString &s)
1799 // Internal function, no saveState needed
1801 (typeid(*selection) == typeid(BranchObj) ||
1802 typeid(*selection) == typeid(MapCenterObj) ) )
1804 ((BranchObj*)selection)->setVymLink(s);
1805 mapCenter->reposition();
1807 ensureSelectionVisible();
1811 void MapEditor::addNewBranch(int pos)
1813 // Finish open lineEdits
1814 if (lineedit) finishedLineEditNoSave();
1817 (typeid(*selection) == typeid(BranchObj) ||
1818 typeid(*selection) == typeid(MapCenterObj) ) )
1820 saveState(selection); //TODO undoCommand
1822 BranchObj* bo1 = (BranchObj*) selection;
1823 bool wasScrolled=false;
1824 BranchObj *newbo=NULL;
1827 // save scroll state. If scrolled, automatically select
1828 // new branch in order to tmp unscroll parent...
1829 wasScrolled=bo1->isScrolled();
1830 newbo=bo1->addBranch();
1833 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1837 // add above selection
1838 newbo=parbo->insertBranch(bo1->getNum());
1840 // add below selection
1841 newbo=parbo->insertBranch(bo1->getNum()+1);
1843 // This should not happen...
1848 LinkableMapObj *oldselection=selection;
1850 mapCenter->reposition();
1852 if (actionSettingsAutoedit->isOn() ||
1853 actionSettingsAutoselectHeading->isOn() )
1855 selection->unselect();
1857 selection->select();
1858 if (actionSettingsPasteNewHeading->isOn() )
1860 BranchObj *bo2= (BranchObj*)selection;
1861 bo2->setHeading("");
1863 if (actionSettingsAutoedit->isOn() )
1865 if (!actionSettingsAutoselectHeading->isOn()
1868 selection->unselect();
1869 selection=oldselection;
1870 selection->select();
1877 void MapEditor::addNewBranchHere()
1879 // Finish open lineEdits
1880 if (lineedit) finishedLineEditNoSave();
1883 (typeid(*selection) == typeid(BranchObj) ) )
1885 saveState(selection);
1887 BranchObj* bo1 = (BranchObj*) selection;
1888 bool wasScrolled=false;
1889 BranchObj *newbo=NULL;
1890 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1893 // add below selection
1894 newbo=parbo->insertBranch(bo1->getNum()+1);
1897 LinkableMapObj *oldselection=selection;
1898 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1900 mapCenter->reposition();
1902 if (actionSettingsAutoedit->isOn() ||
1903 actionSettingsAutoselectHeading->isOn() )
1905 selection->unselect();
1907 selection->select();
1908 if (actionSettingsPasteNewHeading->isOn() )
1910 BranchObj *bo2= (BranchObj*)selection;
1911 bo2->setHeading("");
1913 if (actionSettingsAutoedit->isOn() )
1915 if (!actionSettingsAutoselectHeading->isOn()
1918 selection->unselect();
1919 selection=oldselection;
1920 selection->select();
1926 void MapEditor::deleteSelection()
1928 // Finish open lineEdits
1929 if (lineedit) finishedLineEditNoSave();
1931 if (selection && typeid(*selection) ==typeid(BranchObj) )
1933 if (selection->getDepth()>1)
1934 // Normal branch, save parent with childs
1935 saveState(selection->getParObj());
1937 // Mainbranch, save whole map
1938 // TODO Better would be to insert mainbranch again at pos
1939 // But undoCommand is missing right now
1941 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1942 BranchObj* par=(BranchObj*)(bo->getParObj());
1945 par->removeBranch(bo);
1947 selection->select();
1948 ensureSelectionVisible();
1949 mapCenter->reposition();
1952 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1954 saveState(selection->getParObj());
1955 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1956 BranchObj* par=(BranchObj*)(fio->getParObj());
1959 par->removeFloatImage(fio);
1961 selection->select();
1962 ensureSelectionVisible();
1963 mapCenter->reposition();
1968 LinkableMapObj* MapEditor::getSelection()
1973 bool MapEditor::select (const QString &s)
1975 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1977 // Finally select the found object
1980 if (selection) unselect();
1982 selection->select();
1984 ensureSelectionVisible();
1990 void MapEditor::unselect()
1994 selectionLast=selection;
1995 selection->unselect();
2000 void MapEditor::reselect()
2004 selection=selectionLast;
2005 selection->select();
2010 void MapEditor::selectNextBranch()
2012 // Increase number of branch
2015 QString s=selection->getSelectString();
2021 part=s.section(",",-1);
2023 num=part.right(part.length() - 3);
2025 s=s.left (s.length() -num.length());
2028 num=QString ("%1").arg(num.toUInt()+1);
2032 // Try to select this one
2033 if (select (s)) return;
2035 // We have no direct successor,
2036 // try to increase the parental number in order to
2037 // find a successor with same depth
2039 int d=selection->getDepth();
2044 while (!found && d>0)
2046 s=s.section (",",0,d-1);
2047 // replace substring of current depth in s with "1"
2048 part=s.section(",",-1);
2050 num=part.right(part.length() - 3);
2054 // increase number of parent
2055 num=QString ("%1").arg(num.toUInt()+1);
2056 s=s.section (",",0,d-2) + ","+ typ+num;
2059 // Special case, look at orientation
2060 if (selection->getOrientation()==OrientRightOfCenter)
2061 num=QString ("%1").arg(num.toUInt()+1);
2063 num=QString ("%1").arg(num.toUInt()-1);
2068 // pad to oldDepth, select the first branch for each depth
2069 for (i=d;i<oldDepth;i++)
2074 if ( ((BranchObj*)selection)->countBranches()>0)
2082 // try to select the freshly built string
2090 void MapEditor::selectPrevBranch()
2092 // Decrease number of branch
2095 QString s=selection->getSelectString();
2101 part=s.section(",",-1);
2103 num=part.right(part.length() - 3);
2105 s=s.left (s.length() -num.length());
2108 num=QString ("%1").arg(num.toUInt()-1);
2112 // Try to select this one
2113 if (select (s)) return;
2115 // We have no direct precessor,
2116 // try to decrease the parental number in order to
2117 // find a precessor with same depth
2119 int d=selection->getDepth();
2124 while (!found && d>0)
2126 s=s.section (",",0,d-1);
2127 // replace substring of current depth in s with "1"
2128 part=s.section(",",-1);
2130 num=part.right(part.length() - 3);
2134 // decrease number of parent
2135 num=QString ("%1").arg(num.toUInt()-1);
2136 s=s.section (",",0,d-2) + ","+ typ+num;
2139 // Special case, look at orientation
2140 if (selection->getOrientation()==OrientRightOfCenter)
2141 num=QString ("%1").arg(num.toUInt()-1);
2143 num=QString ("%1").arg(num.toUInt()+1);
2148 // pad to oldDepth, select the last branch for each depth
2149 for (i=d;i<oldDepth;i++)
2153 if ( ((BranchObj*)selection)->countBranches()>0)
2154 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
2161 // try to select the freshly built string
2169 void MapEditor::selectUpperBranch()
2171 // Finish open lineEdits
2172 if (lineedit) finishedLineEditNoSave();
2176 if (typeid(*selection) == typeid(BranchObj))
2178 if (selection->getOrientation()==OrientRightOfCenter)
2181 if (selection->getDepth()==1)
2189 void MapEditor::selectLowerBranch()
2191 // Finish open lineEdits
2192 if (lineedit) finishedLineEditNoSave();
2196 if (typeid(*selection) == typeid(BranchObj))
2198 if (selection->getOrientation()==OrientRightOfCenter)
2201 if (selection->getDepth()==1)
2210 void MapEditor::selectLeftBranch()
2212 // Finish open lineEdits
2213 if (lineedit) finishedLineEditNoSave();
2219 if (typeid(*selection) == typeid(MapCenterObj))
2221 par= (BranchObj*) selection;
2222 bo=par->getLastSelectedBranch();
2225 // Workaround for reselecting on left and right side
2226 if (bo->getOrientation()==OrientRightOfCenter)
2228 bo=par->getLastBranch();
2234 selection->select();
2236 ensureSelectionVisible();
2241 par=(BranchObj*)(selection->getParObj());
2242 if (selection->getOrientation()==OrientRightOfCenter)
2244 if (typeid(*selection) == typeid(BranchObj) ||
2245 typeid(*selection) == typeid(FloatImageObj))
2247 selection->unselect();
2249 selection->select();
2251 ensureSelectionVisible();
2255 if (typeid(*selection) == typeid(BranchObj) )
2257 bo=((BranchObj*)selection)->getLastSelectedBranch();
2260 selection->unselect();
2262 selection->select();
2264 ensureSelectionVisible();
2272 void MapEditor::selectRightBranch()
2274 // Finish open lineEdits
2275 if (lineedit) finishedLineEditNoSave();
2282 if (typeid(*selection) == typeid(MapCenterObj))
2284 par= (BranchObj*) selection;
2285 bo=par->getLastSelectedBranch();
2288 // Workaround for relecting on left and right side
2289 if (bo->getOrientation()==OrientLeftOfCenter)
2290 bo=par->getFirstBranch();
2295 selection->select();
2296 ensureSelectionVisible();
2301 par=(BranchObj*)(selection->getParObj());
2302 if (selection->getOrientation()==OrientLeftOfCenter)
2304 if (typeid(*selection) == typeid(BranchObj) ||
2305 typeid(*selection) == typeid(FloatImageObj))
2307 selection->unselect();
2309 selection->select();
2311 ensureSelectionVisible();
2315 if (typeid(*selection) == typeid(BranchObj) )
2317 bo=((BranchObj*)selection)->getLastSelectedBranch();
2320 selection->unselect();
2322 selection->select();
2324 ensureSelectionVisible();
2332 void MapEditor::selectFirstBranch()
2334 // Finish open lineEdits
2335 if (lineedit) finishedLineEditNoSave();
2341 if (typeid(*selection) == typeid(BranchObj))
2343 bo1= (BranchObj*) selection;
2344 par=(BranchObj*)(bo1->getParObj());
2345 bo2=par->getFirstBranch();
2349 selection->select();
2350 ensureSelectionVisible();
2357 void MapEditor::selectLastBranch()
2359 // Finish open lineEdits
2360 if (lineedit) finishedLineEditNoSave();
2366 if (typeid(*selection) == typeid(BranchObj))
2368 bo1= (BranchObj*) selection;
2369 par=(BranchObj*)(bo1->getParObj());
2370 bo2=par->getLastBranch();
2374 selection->select();
2375 ensureSelectionVisible();
2382 void MapEditor::setColor(QColor c)
2387 void MapEditor::selectBackgroundColor()
2389 // Finish open lineEdits
2390 if (lineedit) finishedLineEditNoSave();
2392 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2393 if ( !col.isValid() ) return;
2394 setBackgroundColor( col );
2398 void MapEditor::setBackgroundColor(QColor c)
2400 mapCanvas->setBackgroundColor (c);
2403 QColor MapEditor::pickColor()
2407 if (typeid(*selection) == typeid(BranchObj) ||
2408 typeid(*selection) == typeid(MapCenterObj))
2410 BranchObj *bo=(BranchObj*)selection;
2411 actColor=bo->getColor();
2417 void MapEditor::colorItem()
2421 if (typeid(*selection) == typeid(BranchObj) ||
2422 typeid(*selection) == typeid(MapCenterObj))
2424 saveState(selection); //TODO undoCommand
2425 BranchObj *bo=(BranchObj*)selection;
2426 bo->setColor(actColor, false); // color links, color childs
2431 void MapEditor::colorBranch()
2435 if (typeid(*selection) == typeid(BranchObj) ||
2436 typeid(*selection) == typeid(MapCenterObj))
2438 saveState(selection);
2439 BranchObj *bo=(BranchObj*)selection;
2440 bo->setColor(actColor, true); // color links, color childs
2446 void MapEditor::toggleStandardFlag(QString f)
2450 saveState(selection);// TODO undoCommand
2451 ((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2455 void MapEditor::setViewCenter()
2457 // transform to CanvasView Coord:
2458 QPoint p=worldMatrix().map(movingCenter);
2459 center ( p.x(), p.y());
2463 BranchObj* MapEditor::findText (QString s, bool cs)
2466 { // Nothing found or new find process
2468 // nothing found, start again
2470 itFind=mapCenter->first();
2472 bool searching=true;
2473 bool foundNote=false;
2474 while (searching && !EOFind)
2478 // Searching in Note
2479 if (itFind->getNote().contains(s,cs))
2481 if (selection!=itFind)
2483 if (selection) ((BranchObj*)selection)->unselect();
2485 selection->select();
2487 ensureSelectionVisible();
2489 if (textEditor->findText(s,cs))
2495 // Searching in Heading
2496 if (searching && itFind->getHeading().contains (s,cs) )
2498 if (selection) ((BranchObj*)selection)->unselect();
2500 selection->select();
2502 ensureSelectionVisible();
2508 itFind=itFind->next();
2509 if (!itFind) EOFind=true;
2515 return (BranchObj*)selection;
2520 void MapEditor::findReset()
2521 { // Necessary if text to find changes during a find process
2526 void MapEditor::openURL()
2530 if (typeid(*selection) == typeid(BranchObj) ||
2531 typeid(*selection) == typeid(MapCenterObj))
2533 QString url=((BranchObj*)selection)->getURL();
2535 QProcess *proc = new QProcess( this );
2537 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL" ));
2538 proc->addArgument( url);
2540 if ( !proc->start() )
2542 if (mainWindow->settingsURL() )
2548 void MapEditor::editURL()
2550 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2551 typeid(*selection) == typeid(MapCenterObj)) )
2554 BranchObj *bo=(BranchObj*)selection;
2555 QString text = QInputDialog::getText(
2556 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2557 bo->getURL(), &ok, this );
2560 // user entered something and pressed OK
2561 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2568 void MapEditor::editHeading2URL()
2570 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2571 typeid(*selection) == typeid(MapCenterObj)) )
2573 BranchObj *bo=(BranchObj*)selection;
2574 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2575 bo->setURL (bo->getHeading());
2580 void MapEditor::editBugzilla2URL()
2582 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2583 typeid(*selection) == typeid(MapCenterObj)) )
2585 BranchObj *bo=(BranchObj*)selection;
2586 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2587 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2593 void MapEditor::editVymLink()
2595 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2596 typeid(*selection) == typeid(MapCenterObj)) )
2598 BranchObj *bo=(BranchObj*)selection;
2599 QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map"));
2600 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2601 fd->setCaption(tr("VYM - Link to another map"));
2602 if (! bo->getVymLink().isEmpty() )
2603 fd->setSelection( bo->getVymLink() );
2607 if ( fd->exec() == QDialog::Accepted )
2609 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2610 bo->setVymLink (fd->selectedFile() );
2612 mapCenter->reposition();
2619 void MapEditor::deleteVymLink()
2621 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2622 typeid(*selection) == typeid(MapCenterObj)) )
2624 BranchObj *bo=(BranchObj*)selection;
2625 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2626 bo->setVymLink ("" );
2628 mapCenter->reposition();
2634 QString MapEditor::getVymLink()
2636 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2637 typeid(*selection) == typeid(MapCenterObj)) )
2639 return ((BranchObj*)selection)->getVymLink();
2645 void MapEditor::removeBranchHere()
2647 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2649 BranchObj* bo=(BranchObj*)selection;
2650 BranchObj* par=(BranchObj*)(bo->getParObj());
2651 if (bo->getDepth()==1)
2654 saveState(selection->getParObj()); // TODO undoCommand
2655 QString sel=selection->getSelectString();
2657 par->removeBranchHere(bo);
2658 mapCenter->reposition();
2663 void MapEditor::removeChilds()
2665 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2667 saveState(selection->getParObj());
2668 ((BranchObj*)selection)->removeChilds();
2669 mapCenter->reposition();
2673 void MapEditor::editMapInfo()
2675 ExtraInfoDialog dia;
2676 dia.setMapName (getFileName() );
2677 dia.setAuthor (mapCenter->getAuthor() );
2678 dia.setComment(mapCenter->getComment() );
2683 QCanvasItemList l=canvas()->allItems();
2684 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2686 stats+=QString ("%1 items on canvas\n").arg (i,6);
2693 bo=mapCenter->first();
2696 if (!bo->getNote().isEmpty() ) n++;
2697 f+= bo->countFloatImages();
2699 xl+=bo->countXLinks();
2702 stats+=QString ("%1 branches\n").arg (b-1,6);
2703 stats+=QString ("%1 xLinks \n").arg (xl,6);
2704 stats+=QString ("%1 notes\n").arg (n,6);
2705 stats+=QString ("%1 images\n").arg (f,6);
2706 dia.setStats (stats);
2708 // Finally show dialog
2709 if (dia.exec() == QDialog::Accepted)
2711 saveState(); //TODO undoCommand
2712 mapCenter->setAuthor (dia.getAuthor() );
2713 mapCenter->setComment (dia.getComment() );
2717 void MapEditor::updateActions()
2720 if (getLinkColorHint()==HeadingColor)
2721 actionFormatLinkColorHint->setOn(true);
2723 actionFormatLinkColorHint->setOn(false);
2728 actionFormatLinkStyleLine->setOn(true);
2731 actionFormatLinkStyleParabel->setOn(true);
2734 actionFormatLinkStylePolyLine->setOn(true);
2736 case StylePolyParabel:
2737 actionFormatLinkStylePolyParabel->setOn(true);
2743 QPixmap pix( 16, 16 );
2744 pix.fill( mapCanvas->backgroundColor() );
2745 actionFormatBackColor->setIconSet( pix );
2746 pix.fill( defLinkColor );
2747 actionFormatLinkColor->setIconSet( pix );
2749 actionEditUndo->setEnabled( mapChanged );
2750 actionFileSave->setEnabled( mapUnsaved );
2754 if ( (typeid(*selection) == typeid(BranchObj)) ||
2755 (typeid(*selection) == typeid(MapCenterObj)) )
2757 BranchObj *bo=(BranchObj*)selection;
2758 // Take care of links
2759 if (bo->countXLinks()==0)
2761 branchLinksContextMenu->clear();
2762 branchLinksContextMenu->insertItem ("No xLink available");
2763 branchLinksContextMenuDup->clear();
2764 branchLinksContextMenuDup->insertItem ("No xLink available");
2770 branchLinksContextMenu->clear();
2771 branchLinksContextMenuDup->clear();
2772 for (int i=0; i<=bo->countXLinks();i++)
2774 bot=bo->XLinkTargetAt(i);
2777 s=bot->getHeading();
2780 branchLinksContextMenu->insertItem (s);
2781 branchLinksContextMenuDup->insertItem (s);
2786 standardFlagsDefault->setEnabled (true);
2788 if ( bo->getURL().isEmpty() )
2789 actionEditOpenURL->setEnabled (false);
2791 actionEditOpenURL->setEnabled (true);
2793 if ( bo->getVymLink().isEmpty() )
2795 actionEditOpenVymLink->setEnabled (false);
2796 actionEditDeleteVymLink->setEnabled (false);
2799 actionEditOpenVymLink->setEnabled (true);
2800 actionEditDeleteVymLink->setEnabled (true);
2803 actionEditCopy->setEnabled (true);
2804 actionEditCut->setEnabled (true);
2805 if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0)
2806 actionEditPaste->setEnabled (true);
2808 actionEditPaste->setEnabled (false);
2809 for (a=actionListBranches.first();a;a=actionListBranches.next())
2810 a->setEnabled(true);
2811 actionEditDelete->setEnabled (true);
2812 actionEditToggleFloatExport->setEnabled (false);
2813 switch (selection->getFrameType())
2816 actionFormatFrameNone->setOn(true);
2819 actionFormatFrameRectangle->setOn(true);
2824 actionFormatHideLinkUnselected->setOn
2825 ( selection->getHideLinkUnselected());
2827 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2829 standardFlagsDefault->setEnabled (false);
2831 actionEditOpenURL->setEnabled (false);
2832 actionEditOpenVymLink->setEnabled (false);
2833 actionEditDeleteVymLink->setEnabled (false);
2835 actionEditCopy->setEnabled (true);
2836 actionEditCut->setEnabled (true);
2837 actionEditPaste->setEnabled (false); //FIXME
2838 for (a=actionListBranches.first();a;a=actionListBranches.next())
2839 a->setEnabled(false);
2840 actionEditDelete->setEnabled (true);
2841 actionEditToggleFloatExport->setOn
2842 ( ((FloatImageObj*)selection)->getFloatExport() );
2843 actionFormatHideLinkUnselected->setOn
2844 ( selection->getHideLinkUnselected());
2849 standardFlagsDefault->setEnabled (false);
2851 actionEditCopy->setEnabled (false);
2852 actionEditCut->setEnabled (false);
2853 actionEditPaste->setEnabled (false);
2854 for (a=actionListBranches.first();a;a=actionListBranches.next())
2855 a->setEnabled(false);
2857 actionEditOpenURL->setEnabled (false);
2858 actionEditOpenVymLink->setEnabled (false);
2859 actionEditDeleteVymLink->setEnabled (false);
2860 actionEditHeading2URL->setEnabled (false);
2861 actionEditDelete->setEnabled (false);
2862 actionEditToggleFloatExport->setEnabled (false);
2866 void MapEditor::updateNoteFlag()
2869 if ( (typeid(*selection) == typeid(BranchObj)) ||
2870 (typeid(*selection) == typeid(MapCenterObj)) )
2871 ((BranchObj*)selection)->updateNoteFlag();
2874 void MapEditor::setLinkStyle (LinkStyle ls)
2878 saveState(); // TODO undoCommand
2880 bo=mapCenter->first();
2884 bo->setLinkStyle(bo->getDefLinkStyle());
2887 mapCenter->reposition();
2890 LinkStyle MapEditor::getLinkStyle ()
2895 void MapEditor::setLinkColor(QColor c)
2901 void MapEditor::setLinkColorHint()
2903 // called from setLinkColorHint(lch) or at end of parse
2905 bo=mapCenter->first();
2913 void MapEditor::setLinkColorHint(LinkColorHint lch)
2919 void MapEditor::toggleLinkColorHint()
2921 if (linkcolorhint==HeadingColor)
2922 linkcolorhint=DefaultColor;
2924 linkcolorhint=HeadingColor;
2926 bo=mapCenter->first();
2934 LinkColorHint MapEditor::getLinkColorHint()
2936 return linkcolorhint;
2939 QColor MapEditor::getDefLinkColor()
2941 return defLinkColor;
2944 void MapEditor::setDefXLinkColor(QColor col)
2949 QColor MapEditor::getDefXLinkColor()
2951 return defXLinkColor;
2954 void MapEditor::setDefXLinkWidth (int w)
2959 int MapEditor::getDefXLinkWidth()
2961 return defXLinkWidth;
2964 void MapEditor::selectLinkColor()
2966 // Finish open lineEdits
2967 if (lineedit) finishedLineEditNoSave();
2969 QColor col = QColorDialog::getColor( defLinkColor, this );
2970 if ( !col.isValid() ) return;
2971 setLinkColor( col );
2972 saveState(); //TODO undoCommand
2976 void MapEditor::toggleScroll()
2978 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2980 BranchObj *bo=((BranchObj*)selection);
2981 if (bo->countBranches()==0) return;
2982 if (bo->getDepth()==0) return;
2983 saveState(selection);
2990 void MapEditor::unScrollAll()
2993 bo=mapCenter->first();
2996 if (bo->isScrolled()) bo->toggleScroll();
3001 void MapEditor::loadFloatImage ()
3004 (typeid(*selection) == typeid(BranchObj)) ||
3005 (typeid(*selection) == typeid(MapCenterObj)) )
3007 BranchObj *bo=((BranchObj*)selection);
3009 QFileDialog *fd=new QFileDialog( this,tr("vym - load image"));
3010 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3011 ImagePreview *p =new ImagePreview (fd);
3012 fd->setContentsPreviewEnabled( TRUE );
3013 fd->setContentsPreview( p, p );
3014 fd->setPreviewMode( QFileDialog::Contents );
3015 fd->setCaption(tr("vym - Load image"));
3016 fd->setDir (lastImageDir);
3020 if ( fd->exec() == QDialog::Accepted )
3022 saveState(selection);
3023 QString fn=fd->selectedFile();
3024 lastImageDir=fn.left(fn.findRev ("/"));
3025 bo->addFloatImage();
3026 // TODO check if load was successful
3027 bo->getLastFloatImage()->load(fn);
3028 bo->getLastFloatImage()->setOriginalFilename(fn);
3029 mapCenter->reposition();
3036 void MapEditor::saveFloatImage (int item)
3039 (typeid(*selection) == typeid(FloatImageObj)) )
3041 FloatImageObj *fio=((FloatImageObj*)selection);
3042 const char* fmt = saveImageFormatMenu->text(item);
3044 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
3045 fd->addFilter ("PNG (*.png)");
3046 fd->addFilter ("BMP (*.bmp)");
3047 fd->addFilter ("XBM (*.xbm)");
3048 fd->addFilter ("JPG (*.jpg)");
3049 fd->addFilter ("XPM (*.xpm)");
3050 fd->addFilter ("GIF (*.gif)");
3051 fd->addFilter ("PNM (*.pnm)");
3052 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3053 fd->setCaption(tr("vym - Save image as %1").arg(fmt));
3054 fd->setMode( QFileDialog::AnyFile );
3055 fd->setSelection (fio->getOriginalFilename());
3059 if ( fd->exec() == QDialog::Accepted )
3061 if (QFile (fd->selectedFile()).exists() )
3063 QMessageBox mb( "VYM",
3064 tr("The file %1 exists already.\n"
3065 "Do you want to overwrite it?").arg(fd->selectedFile()),
3066 QMessageBox::Warning,
3067 QMessageBox::Yes | QMessageBox::Default,
3068 QMessageBox::Cancel | QMessageBox::Escape,
3069 QMessageBox::QMessageBox::NoButton );
3071 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3072 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3075 case QMessageBox::Yes:
3078 case QMessageBox::Cancel:
3084 fio->save (fd->selectedFile(),fmt);
3089 void MapEditor::toggleFloatExport()
3092 (typeid(*selection) == typeid(FloatImageObj))||
3093 (typeid(*selection) == typeid(FloatObj)) )
3095 FloatImageObj *fio=((FloatImageObj*)selection);
3096 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
3100 void MapEditor::setFrame(const FrameType &t)
3103 (typeid(*selection) == typeid(BranchObj)) ||
3104 (typeid(*selection) == typeid(MapCenterObj)) )
3106 selection->setFrameType (t);
3107 mapCenter->reposition();
3108 selection->updateLink();
3112 void MapEditor::setHideLinkUnselected (bool b)
3115 (typeid(*selection) == typeid(BranchObj)) ||
3116 (typeid(*selection) == typeid(MapCenterObj)) ||
3117 (typeid(*selection) == typeid(FloatImageObj)) )
3118 selection->setHideLinkUnselected(b);
3121 void MapEditor::importDir(BranchObj *dst, QDir d)
3124 (typeid(*selection) == typeid(BranchObj)) ||
3125 (typeid(*selection) == typeid(MapCenterObj)) )
3129 // Traverse directories
3130 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3131 const QFileInfoList *dirlist = d.entryInfoList();
3132 QFileInfoListIterator itdir( *dirlist );
3135 while ( (fi = itdir.current()) != 0 )
3137 if (fi->fileName() != "." && fi->fileName() != ".." )
3140 bo=dst->getLastBranch();
3141 bo->setHeading (fi->fileName() );
3142 bo->setColor (QColor("blue"),false);
3144 if ( !d.cd(fi->fileName()) )
3145 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
3148 // Recursively add subdirs
3156 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3157 const QFileInfoList *filelist = d.entryInfoList();
3158 QFileInfoListIterator itfile( *filelist );
3160 while ( (fi = itfile.current()) != 0 )
3163 bo=dst->getLastBranch();
3164 bo->setHeading (fi->fileName() );
3165 bo->setColor (QColor("black"),false);
3166 if (fi->fileName().right(4) == ".vym" )
3167 bo->setVymLink (fi->filePath());
3174 void MapEditor::importDir()
3177 (typeid(*selection) == typeid(BranchObj)) ||
3178 (typeid(*selection) == typeid(MapCenterObj)) )
3180 QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import"));
3181 fd->setMode (QFileDialog::DirectoryOnly);
3182 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3183 fd->setCaption(tr("VYM - Choose directory structur to import"));
3187 if ( fd->exec() == QDialog::Accepted )
3189 BranchObj *bo=((BranchObj*)selection);
3190 importDir (bo,QDir(fd->selectedFile()) );
3191 mapCenter->reposition();
3198 void MapEditor::followXLink(int i)
3201 (typeid(*selection) == typeid(BranchObj)) ||
3202 (typeid(*selection) == typeid(MapCenterObj)) )
3204 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3207 selection->unselect();
3209 selection->select();
3210 ensureSelectionVisible();
3215 void MapEditor::editXLink(int i)
3218 (typeid(*selection) == typeid(BranchObj)) ||
3219 (typeid(*selection) == typeid(MapCenterObj)) )
3221 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3224 EditXLinkDialog dia;
3226 dia.setSelection(selection);
3227 if (dia.exec() == QDialog::Accepted)
3229 if (dia.useSettingsGlobal() )
3231 setDefXLinkColor (xlo->getColor() );
3232 setDefXLinkWidth (xlo->getWidth() );
3234 if (dia.deleteXLink())
3235 ((BranchObj*)selection)->deleteXLinkAt(i);
3236 saveState(); //TODO undoCommand
3242 void MapEditor::testFunction()
3244 cout << "MapEditor::testFunction() called\n";
3249 void MapEditor::ensureSelectionVisible()
3253 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3255 if (selection->getOrientation() == OrientLeftOfCenter)
3256 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3258 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3259 ensureVisible (p.x(), p.y() );
3264 void MapEditor::updateViewCenter()
3266 // Update movingCenter, so that we can zoom comfortably later
3267 QRect rc = QRect( contentsX(), contentsY(),
3268 visibleWidth(), visibleHeight() );
3269 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3270 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3271 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3274 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3276 // Lineedits are already closed by preceding
3277 // mouseEvent, we don't need to close here.
3279 QPoint p = inverseWorldMatrix().map(e->pos());
3280 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3283 { // MapObj was found
3284 if (selection != lmo)
3286 // select the MapObj
3287 if (selection) selection->unselect();
3289 selection->select();
3295 if (typeid(*selection)==typeid(BranchObj) ||
3296 typeid(*selection)==typeid(MapCenterObj) )
3298 // Context Menu on branch or mapcenter
3300 branchContextMenu->popup(e->globalPos() );
3302 if (typeid(*selection)==typeid(FloatImageObj))
3304 // Context Menu on floatimage
3306 floatimageContextMenu->popup(e->globalPos() );
3310 { // No MapObj found, we are on the Canvas itself
3311 // Context Menu on Canvas
3313 canvasContextMenu->popup(e->globalPos() );
3317 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3319 // Finish open lineEdits
3320 if (lineedit) finishedLineEditNoSave();
3322 QPoint p = inverseWorldMatrix().map(e->pos());
3323 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3325 // Special case: CTRL is pressed
3326 if (e->state() & QMouseEvent::ControlButton)
3328 if (actionModModeColor->isOn())
3330 if (e->state() & QMouseEvent::ControlButton)
3333 setCursor (pickColorCursor);
3337 if (actionModModeLink->isOn())
3339 BranchObj *bo_begin=NULL;
3341 bo_begin=(BranchObj*)(lmo);
3344 ((typeid(*selection) == typeid(BranchObj)) ||
3345 (typeid(*selection) == typeid(MapCenterObj))) )
3346 bo_begin=(BranchObj*)selection;
3350 linkingObj_src=bo_begin;
3351 tmpXLink=new XLinkObj (mapCanvas);
3352 tmpXLink->setBegin (bo_begin);
3353 tmpXLink->setEnd (p);
3354 tmpXLink->setColor(defXLinkColor);
3355 tmpXLink->setWidth(defXLinkWidth);
3356 tmpXLink->updateXLink();
3357 tmpXLink->setVisibility (true);
3364 { // MapObj was found
3365 if (selection != lmo)
3367 // select the MapObj
3368 if (selection) selection->unselect();
3370 selection->select();
3375 // Check, if systemFlag clicked
3376 if (typeid(*selection)==typeid(BranchObj) ||
3377 typeid(*selection)==typeid(MapCenterObj) )
3379 QString foname=((BranchObj*)selection)->getSystemFlagName(p);
3380 if (!foname.isEmpty())
3382 // Do not move, if systemFlag clicked
3386 if (foname=="vymLink")
3388 mainWindow->editOpenVymLink();
3389 // tabWidget may change, better return now
3390 // before segfaulting...
3394 mainWindow->windowToggleNoteEditor();
3398 // Left Button Move Branches
3399 if (e->button() == QMouseEvent::LeftButton )
3401 movingObj_start.setX( p.x() - selection->x() );
3402 movingObj_start.setY( p.y() - selection->y() );
3403 movingObj_orgPos.setX (lmo->x() );
3404 movingObj_orgPos.setY (lmo->y() );
3406 // If modMode==copy, then we want to "move" the _new_ object around
3407 // then we need the offset from p to the _old_ selection, because of tmp
3408 if (actionModModeCopy->isOn() &&
3409 e->state() & QMouseEvent::ControlButton)
3411 if (typeid(*selection)==typeid(BranchObj) )
3414 mapCenter->addBranch ((BranchObj*)selection);
3416 selection=mapCenter->getLastBranch();
3417 selection->select();
3418 mapCenter->reposition();
3421 movingObj=selection;
3423 // Middle Button Toggle Scroll
3424 // (On Mac OS X this won't work, but we still have
3425 // a button in the toolbar)
3426 if (e->button() == QMouseEvent::MidButton )
3430 { // No MapObj found, we are on the Canvas itself
3431 // Left Button move Pos of CanvasView
3432 if (e->button() == QMouseEvent::LeftButton )
3434 movingObj=NULL; // move Content not Obj
3435 movingObj_start=e->globalPos();
3436 movingCont_start=QPoint (contentsX(), contentsY() );
3437 movingVec=QPoint(0,0);
3438 setCursor(handOpenCursor);
3443 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3445 QPoint p = inverseWorldMatrix().map(e->pos());
3447 // Move the selected MapObj
3448 if ( selection && movingObj)
3450 // To avoid jumping of the CanvasView, only
3451 // ensureSelectionVisible, if not tmp linked
3452 if (!selection->hasParObjTmp())
3453 ensureSelectionVisible ();
3455 // Now move the selection, but add relative position
3456 // (movingObj_start) where selection was chosen with
3457 // mousepointer. (This avoids flickering resp. jumping
3458 // of selection back to absPos)
3460 LinkableMapObj *lmosel;
3461 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3463 // Check if we could link
3464 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3467 if (typeid(*selection) == typeid(FloatImageObj))
3469 FloatObj *fo=(FloatObj*)selection;
3470 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3471 if (fo->getLinkStyle()==StyleUndef)
3473 fo->setLinkStyle(fo->getDefLinkStyle());
3474 fo->setLinkColor(fo->getParObj()->getLinkColor());
3476 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3480 // Relink float to new mapcenter or branch, if shift is pressed
3481 // Only relink, if selection really has a new parent
3482 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3483 ( (typeid(*lmo)==typeid(BranchObj)) ||
3484 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3485 ( lmo != fo->getParObj())
3488 if (typeid(*fo) == typeid(FloatImageObj))
3491 FloatImageObj *fio=(FloatImageObj*)(fo);
3492 ((BranchObj*)(lmo))->addFloatImage (fio);
3494 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3495 fio=((BranchObj*)(lmo))->getLastFloatImage();
3498 selection=(LinkableMapObj*)(fio);
3499 selection->select();
3500 movingObj=(MapObj*)(fio);
3501 // setLinkStyle calls updateLink, only set it once
3502 if (fio->getLinkStyle()!=fio->getDefLinkStyle() )
3503 fio->setLinkStyle (fio->getDefLinkStyle());
3505 // TODO if (typeid(*selection) == typeid(FloatTextObj))
3507 } else // selection != a FloatObj
3509 if (lmosel->getDepth()==0)
3511 if (e->state() == (LeftButton | !ShiftButton))
3512 // If mapCenter is moved, move all the rest by default, too.
3513 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3515 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3518 if (lmosel->getDepth()==1)
3520 // depth==1, mainbranch
3521 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3525 if (lmosel->getOrientation() == OrientLeftOfCenter)
3526 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3527 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3528 p.y()-movingObj_start.y() );
3530 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3532 // reposition subbranch
3533 lmosel->reposition();
3534 //ensureSelectionVisible();
3536 if (lmo && (lmo!=selection) &&
3537 (typeid(*lmo) == typeid(BranchObj) ||
3538 (typeid(*lmo) == typeid(MapCenterObj) )
3541 if (e->state() & QMouseEvent::ControlButton)
3543 // Special case: CTRL to link below lmo
3544 lmosel->setParObjTmp (lmo,p,+1);
3546 else if (e->state() & QMouseEvent::ShiftButton)
3547 lmosel->setParObjTmp (lmo,p,-1);
3549 lmosel->setParObjTmp (lmo,p,0);
3552 lmosel->unsetParObjTmp();
3554 if (lmo &&(lmo==selection))
3555 // Could link to myself (happens sometimes...)
3556 lmosel->unsetParObjTmp();
3558 // no Obj under selection, go back to original Parent
3559 lmosel->unsetParObjTmp();
3564 } // no FloatImageObj
3568 } // selection && moving_obj
3570 // Draw a link from one branch to another
3573 tmpXLink->setEnd (p);
3574 tmpXLink->updateXLink();
3578 if (!movingObj && !pickingColor &&!drawingLink)
3580 QPoint p=e->globalPos();
3581 movingVec.setX(-p.x() + movingObj_start.x() );
3582 movingVec.setY(-p.y() + movingObj_start.y() );
3583 setContentsPos( movingCont_start.x() + movingVec.x(),
3584 movingCont_start.y() + movingVec.y());
3591 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3593 LinkableMapObj *dst;
3594 // Have we been picking color?
3598 setCursor (ArrowCursor);
3599 // Check if we are over another branch
3600 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3601 if (dst && selection)
3603 if (e->state() & QMouseEvent::ShiftButton)
3605 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor(),false);
3606 ((BranchObj*)selection)->setLinkColor ();
3610 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor(),true);
3611 ((BranchObj*)selection)->setLinkColor ();
3617 // Have we been drawing a link?
3621 // Check if we are over another branch
3622 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3623 if (dst && selection)
3625 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3626 tmpXLink->updateXLink();
3627 tmpXLink->activate();
3628 saveState(); //TODO undoCommand
3637 // Have we been moving something?
3638 if ( selection && movingObj )
3640 // Check if we are over another branch, but ignore
3641 // any found LMOs, which are FloatObjs
3642 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3643 ((LinkableMapObj*)selection) );
3646 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3649 // Now check, if we have been moving a branch
3650 if (typeid(*selection) == typeid(BranchObj) )
3652 // save the position in case we link to mapcenter
3653 QPoint savePos=QPoint (selection->x(),selection->y() );
3655 // Reset the temporary drawn link to the original one
3656 ((LinkableMapObj*)selection)->unsetParObjTmp();
3662 BranchObj* bs=((BranchObj*)selection);
3663 QString undoCom="linkBranchToPos (\""+
3664 (bs->getParObj())->getSelectString()+
3666 QString("%1").arg(bs->getNum())+
3668 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3670 // TODO we also could check, if dest and src are on same branch,
3671 // then it would be sufficient to saveState of this branch
3673 // Modifiers allow to insert above/below dst
3674 if (e->state() & QMouseEvent::ShiftButton)
3676 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3678 if (e->state() & QMouseEvent::ControlButton)
3680 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3683 bs->moveBranchTo ((BranchObj*)(dst),-1);
3684 if (dst->getDepth()==0)
3687 saveState (undoCom,bs->getSelectString() );
3689 if (selection->getDepth()==1)
3690 // If we have moved mainbranch only save endposition
3691 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString() );
3693 // Draw the original link, before selection was moved around
3694 mapCenter->reposition();
3696 // Finally resize canvas, if needed
3701 // maybe we moved View: set old cursor
3702 setCursor (ArrowCursor);
3706 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3708 // Finish open lineEdits
3709 if (lineedit) finishedLineEditNoSave();
3711 if (e->button() == QMouseEvent::LeftButton )
3713 QPoint p = inverseWorldMatrix().map(e->pos());
3714 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3715 if (lmo) { // MapObj was found
3716 // First select the MapObj than edit heading
3717 if (selection) selection->unselect();
3719 selection->select();
3720 saveState(selection);
3726 void MapEditor::resizeEvent (QResizeEvent* e)
3728 QCanvasView::resizeEvent( e );
3731 if (!fileName.isEmpty()) s=fileName;
3735 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3738 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3739 // cerr << event->format(i) << endl;
3742 (typeid(*selection) == typeid(BranchObj)) ||
3743 (typeid(*selection) == typeid(MapCenterObj))) {
3745 // If QImageDrag can decode mime type
3746 if (QImageDrag::canDecode(event)) {
3751 // If image are dragged from firefox
3752 if (event->provides("application/x-moz-file-promise-url") &&
3753 event->provides("application/x-moz-nativeimage")) {
3754 event->accept(true);
3758 // If QUriDrag can decode mime type
3759 if (QUriDrag::canDecode(event)) {
3764 // If Uri are dragged from firefox
3765 if (event->provides("_NETSCAPE_URL")){
3770 // If QTextDrag can decode mime type
3771 if (QTextDrag::canDecode(event)) {
3780 bool isUnicode16(const QByteArray &d)
3782 // TODO: make more precise check for unicode 16.
3783 // Guess unicode16 if any of second bytes are zero
3784 unsigned int length = max(0,d.size()-2)/2;
3785 for (unsigned int i = 0; i<length ; i++)
3786 if (d.at(i*2+1)==0) return true;
3790 void MapEditor::contentsDropEvent(QDropEvent *event)
3793 (typeid(*selection) == typeid(BranchObj)) ||
3794 (typeid(*selection) == typeid(MapCenterObj)))
3799 if (event->provides("image/png"))
3802 if (QImageDrag::decode(event, pix))
3810 } else if (event->provides("application/x-moz-file-promise-url") &&
3811 event->provides("application/x-moz-nativeimage"))
3813 // Contains url to the img src in unicode16
3814 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3815 QString url = QString((const QChar*)d.data(),d.size()/2);
3819 } else if (event->provides ("text/uri-list"))
3820 { // Uris provided e.g. by konqueror
3821 QUriDrag::decode (event,uris);
3822 } else if (event->provides ("_NETSCAPE_URL"))
3823 { // Uris provided by Mozilla
3824 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3827 } else if (event->provides("text/html")) {
3829 // Handels text mime types
3830 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3831 QByteArray d = event->encodedData("text/html");
3834 text = QString((const QChar*)d.data(),d.size()/2);
3838 textEditor->setText(text);
3842 } else if (event->provides("text/plain")) {
3843 QByteArray d = event->encodedData("text/plain");
3846 text = QString((const QChar*)d.data(),d.size()/2);
3850 textEditor->setText(text);
3862 for (const char* u=uris.first(); u; u=uris.next())
3864 bo=((BranchObj*)selection)->addBranch();
3867 s=QUriDrag::uriToLocalFile(u);
3869 QString file = QDir::convertSeparators(s);
3870 heading = QFileInfo(file).baseName();
3872 if (file.endsWith(".vym", false))
3873 bo->setVymLink(file);
3882 bo->setHeading(heading);
3892 saveState(); //TODO undo Command
3893 mapCenter->reposition();
3900 void MapEditor::addFloatImage(const QPixmap &img)
3903 (typeid(*selection) == typeid(BranchObj)) ||
3904 (typeid(*selection) == typeid(MapCenterObj)) )
3906 BranchObj *bo=((BranchObj*)selection);
3907 saveState(selection);
3908 //QString fn=fd->selectedFile();
3909 //lastImageDir=fn.left(fn.findRev ("/"));
3910 bo->addFloatImage();
3911 // FIXME check if load was successful
3912 bo->getLastFloatImage()->load(img);
3913 //bo->getLastFloatImage()->setOriginalFilename(fn);
3914 mapCenter->reposition();
3921 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3923 if (!imageBuffer) imageBuffer = new QBuffer();
3924 if (!imageBuffer->isOpen()) {
3925 imageBuffer->open(IO_WriteOnly | IO_Append);
3927 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3931 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3933 if (nop->state()==QNetworkProtocol::StDone) {
3934 QPixmap img(imageBuffer->buffer());
3939 imageBuffer->close();
3941 imageBuffer->close();
3948 void MapEditor::fetchImage(const QString &url)
3951 urlOperator->stop();
3952 disconnect(urlOperator);
3956 urlOperator = new QUrlOperator(url);
3957 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3958 this, SLOT(imageDataFinished(QNetworkOperation*)));
3960 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3961 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));