3 #include <q3dragobject.h>
4 #include <q3urloperator.h>
5 #include <q3networkprotocol.h>
6 #include <q3paintdevicemetrics.h>
7 #include <q3filedialog.h>
16 #include "editxlinkdialog.h"
18 #include "extrainfodialog.h"
20 #include "linkablemapobj.h"
21 #include "mainwindow.h"
23 #include "texteditor.h"
24 #include "warningdialog.h"
28 extern TextEditor *textEditor;
29 extern int statusbarTime;
30 extern Main *mainWindow;
31 extern QString tmpVymDir;
32 extern QString clipboardDir;
33 extern bool clipboardEmpty;
34 extern FlagRowObj *standardFlagsDefault;
36 extern QMenu* branchContextMenu;
37 extern QMenu* branchAddContextMenu;
38 extern QMenu* branchRemoveContextMenu;
39 extern QMenu* branchLinksContextMenu;
40 extern QMenu* branchXLinksContextMenuEdit;
41 extern QMenu* branchXLinksContextMenuFollow;
42 extern QMenu* floatimageContextMenu;
43 extern QMenu* saveImageFormatMenu;
44 extern QMenu* canvasContextMenu;
45 extern QMenu* lastMapsMenu;
46 extern QMenu* importMenu;
47 extern QMenu* exportMenu;
50 extern Settings settings;
51 extern ImageIO imageIO;
53 extern QString iconPath;
54 extern QDir vymBaseDir;
55 extern QDir lastImageDir;
57 int MapEditor::mapNum=0; // make instance
59 ///////////////////////////////////////////////////////////////////////
60 ///////////////////////////////////////////////////////////////////////
62 QWidget* parent, const char* name, Qt::WFlags f) :
63 Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
65 //cout << "Constructor ME "<<this<<endl;
68 viewport()->setAcceptDrops(true);
70 mapCanvas = new Q3Canvas(width(),height());
71 mapCanvas->setAdvancePeriod(30);
72 mapCanvas->setBackgroundColor (Qt::white);
74 setCanvas (mapCanvas);
76 // Always show scroll bars (automatic would flicker sometimes)
77 setVScrollBarMode ( Q3ScrollView::AlwaysOn );
78 setHScrollBarMode ( Q3ScrollView::AlwaysOn );
80 mapCenter = new MapCenterObj(mapCanvas);
81 mapCenter->setVisibility (true);
82 mapCenter->setMapEditor (this);
83 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
84 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
88 actColor=Qt::black; setColor (actColor);
89 defLinkColor=QColor (0,0,255);
90 defXLinkColor=QColor (180,180,180);
91 linkcolorhint=DefaultColor;
92 linkstyle=StylePolyParabel;
94 // Create bitmap cursors, platform dependant
95 #if defined(Q_OS_MACX)
96 handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png"),1,1 );
97 pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 );
99 handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1);
100 pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
112 xelection.setMapCenter (mapCenter);
115 defXLinkColor=QColor (230,230,230);
123 fileName=tr("unnamed");
126 stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",50);
127 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
129 // Initialize find routine
136 blockReposition=false;
137 blockSaveState=false;
141 // Create temporary files
144 // Initially set movingCentre
147 mapCenter->reposition(); // for positioning heading
149 // Initialize history window;
150 historyWindow.setME(this);
151 historyWindow.setStepsTotal(stepsTotal);
152 historyWindow.update (undoSet);
155 MapEditor::~MapEditor()
157 if (imageBuffer) delete imageBuffer;
163 //cout <<"Destructor MapEditor\n";
166 QColor MapEditor::getColor()
171 QColor MapEditor::getBackgroundColor()
173 return mapCanvas->backgroundColor();
176 MapCenterObj* MapEditor::getMapCenter()
181 Q3Canvas* MapEditor::getCanvas()
186 void MapEditor::adjustCanvasSize()
188 // To adjust the canvas to map, viewport size and position, we have to
189 // do some coordinate magic...
191 // Get rectangle of (scroll-)view.
192 // We want to be in canvas coords, so
193 // we map. Important if view is zoomed...
194 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
195 visibleWidth(), visibleHeight()) );
197 // Now we need the bounding box of view AND map to calc the correct canvas size.
198 // Why? Because if the map itself is moved out of view, the view has to be enlarged
199 // to avoid jumping aroung...
200 QRect map=mapCenter->getTotalBBox();
202 // right edge - left edge
203 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
204 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
207 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
208 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
211 // move the map on canvas (in order to not move it on screen) this is neccessary
212 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
213 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
214 // to scroll to an empty area of canvas to the left.
215 // b) if topleft corner of map left of or above topleft of canvas
219 if (cw > mapCanvas->width() )
221 if (map.x()<0) dx=-map.x();
223 if (cw < mapCanvas->width() )
224 dx=-min (view.x(),map.x());
225 if (ch > mapCanvas->height() )
227 if (map.y()<0) dy=-map.y();
229 if (ch < mapCanvas->height() )
231 dy=-min (view.y(),map.y());
233 // We really have to resize now. Let's go...
234 mapCanvas->resize (cw,ch);
235 if ( (dx!=0) || (dy!=0) )
237 mapCenter->moveAllBy(dx,dy);
238 mapCenter->reposition();
239 // mapCenter->positionBBox(); // To move float
241 // scroll the view (in order to not move map on screen)
247 bool MapEditor::isRepositionBlocked()
249 return blockReposition;
252 QString MapEditor::getName (LinkableMapObj *lmo)
255 if (!lmo) return QString("Error: NULL has no name!");
257 if ((typeid(*lmo) == typeid(BranchObj) ||
258 typeid(*lmo) == typeid(MapCenterObj)))
261 s=(((BranchObj*)lmo)->getHeading());
262 if (s=="") s="unnamed";
263 return QString("branch (%1)").arg(s);
264 //return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
266 if ((typeid(*lmo) == typeid(FloatImageObj) ))
267 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
268 //return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
269 return QString("Unknown type has no name!");
272 void MapEditor::makeTmpDirs()
274 // Create unique temporary directories
275 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
276 histPath=QDir::convertSeparators (tmpMapDir+"/history");
281 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSel)
283 // tmpdir temporary directory to which data will be written
284 // prefix mapname, which will be appended to images etc.
285 // writeflags Only write flags for "real" save of map, not undo
286 // offset offset of bbox of whole map in canvas.
287 // Needed for XML export
303 ls="StylePolyParabel";
307 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
309 if (linkcolorhint==HeadingColor)
310 colhint=attribut("linkColorHint","HeadingColor");
312 QString mapAttr=attribut("version",__VYM_VERSION);
314 mapAttr+= attribut("author",mapCenter->getAuthor()) +
315 attribut("comment",mapCenter->getComment()) +
316 attribut("date",mapCenter->getDate()) +
317 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
318 attribut("linkStyle", ls ) +
319 attribut("linkColor", defLinkColor.name() ) +
320 attribut("defXLinkColor", defXLinkColor.name() ) +
321 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
323 s+=beginElement("vymmap",mapAttr);
326 // Find the used flags while traversing the tree
327 standardFlagsDefault->resetUsedCounter();
329 // Reset the counters before saving
330 FloatImageObj (mapCanvas).resetSaveCounter();
332 // Build xml recursivly
334 // Save complete map, if saveSel not set
335 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
338 if ( typeid(*saveSel) == typeid(BranchObj) )
340 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
341 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
343 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
345 else if (selection && typeid(*selection)==typeid(BranchObj))
346 // Save selected branch is saved from mainwindow //FIXME maybe use "subtree" above?
347 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
350 // Save local settings
351 s+=settings.getXMLData (destPath);
354 if (selection && !saveSel )
355 s+=valueElement("select",selection->getSelectString());
358 s+=endElement("vymmap");
361 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
365 void MapEditor::saveStateComplete(const QString &comment)
367 // Save complete map, Undo will replace whole map
368 saveState (CompleteMap,
375 void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, const QString &comment)
377 // save the selected part of the map, Undo will replace part of map
378 QString undoSelection="";
379 if (undoSel) undoSelection=undoSel->getSelectString();
381 saveState (PartOfMap,
388 void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
392 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
395 QString undoSelection=redoSel->getParObj()->getSelectString();
396 QString redoSelection=redoSel->getSelectString();
397 if (typeid(*redoSel) == typeid(BranchObj) && redoSel->getDepth()>1 )
399 // save the selected branch of the map, Undo will insert part of map
400 saveState (PartOfMap,
401 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
402 redoSelection, "delete ()",
405 } else if (typeid(*redoSel) == typeid(BranchObj) )
407 // save the selected mainbranch of the map, Undo will insert part of map
408 saveState (PartOfMap,
409 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
410 // undoSelection, QString("addMapInsert (\"PATH\",%1,%2)").arg(((BranchObj*)redoSel)->getNum())
411 // .arg(((BranchObj*)redoSel)->x()).arg(((BranchObj*)redoSel)->y()),
412 redoSelection, "delete ()",
419 void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment)
421 // selection does not change during action,
422 // so just save commands for undo and redo
423 // and use current selection
426 if (selection) sel=selection->getSelectString();
428 saveState (UndoCommand,
435 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
437 // "Normal" savestate: save commands, selections and comment
438 // so just save commands for undo and redo
439 // and use current selection
441 QString redoSelection="";
442 if (redoSel) redoSelection=redoSel->getSelectString();
443 QString undoSelection="";
444 if (undoSel) undoSelection=undoSel->getSelectString();
446 saveState (UndoCommand,
453 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
455 // "Normal" savestate: save commands, selections and comment
456 // so just save commands for undo and redo
457 // and use current selection
458 saveState (UndoCommand,
466 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
470 if (blockSaveState) return;
472 /* TODO remove after testing
474 cout << "ME::saveState() "<<endl;
478 int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
479 int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
480 int curStep=undoSet.readNumEntry ("/history/curStep",0);
481 // Find out current undo directory
482 if (undosAvail<stepsTotal) undosAvail++;
484 if (curStep>stepsTotal) curStep=1;
487 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
488 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
489 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
491 // Create bakMapDir if not available
494 makeSubDirs (bakMapDir);
496 // Save depending on how much needs to be saved
500 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel);
502 QString undoCommand="";
503 if (savemode==UndoCommand)
507 else if (savemode==PartOfMap )
510 undoCommand.replace ("PATH",bakMapPath);
513 undoCommand="undoMap (\""+bakMapPath+"\")";
515 if (!backupXML.isEmpty())
516 // Write XML Data to disk
517 saveStringToDisk (QString(bakMapPath),backupXML);
519 // We would have to save all actions in a tree, to keep track of
520 // possible redos after a action. Possible, but we are too lazy: forget about redos.
523 // Write the current state to disk
524 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
525 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
526 undoSet.setEntry ("/history/curStep",QString::number(curStep));
527 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
528 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
529 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
530 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
531 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
532 undoSet.writeSettings(histPath);
534 /* TODO remove after testing
536 //cout << " into="<< histPath.toStdString()<<endl;
537 cout << " stepsTotal="<<stepsTotal<<
538 ", undosAvail="<<undosAvail<<
539 ", redosAvail="<<redosAvail<<
540 ", curStep="<<curStep<<endl;
541 cout << " ---------------------------"<<endl;
542 cout << " comment="<<comment.toStdString()<<endl;
543 cout << " undoCom="<<undoCommand.toStdString()<<endl;
544 cout << " undoSel="<<undoSelection.toStdString()<<endl;
545 cout << " redoCom="<<redoCom.toStdString()<<endl;
546 cout << " redoSel="<<redoSelection.toStdString()<<endl;
547 cout << " ---------------------------"<<endl;
549 historyWindow.update (undoSet);
552 void MapEditor::parseAtom(const QString &atom)
559 // Split string s into command and parameters
560 api.parseInput (atom);
561 QString com=api.command();
564 if (com=="addBranch")
568 api.setError (Aborted,"Nothing selected");
569 } else if ( (typeid(*selection) != typeid(BranchObj) &&
570 typeid(*selection) != typeid(MapCenterObj)) )
572 api.setError (Aborted,"Type of selection is not a branch");
577 if (api.checkParamCount(pl))
579 if (api.paramCount()==0)
580 addNewBranchInt (-2);
584 if (ok ) addNewBranchInt (y);
588 } else if (com=="addBranchBefore")
592 api.setError (Aborted,"Nothing selected");
593 } else if ( (typeid(*selection) != typeid(BranchObj) &&
594 typeid(*selection) != typeid(MapCenterObj)) )
596 api.setError (Aborted,"Type of selection is not a branch");
599 if (api.paramCount()==0)
601 addNewBranchBefore ();
604 } else if (com==QString("addMapReplace"))
608 api.setError (Aborted,"Nothing selected");
609 } else if ( (typeid(*selection) != typeid(BranchObj) &&
610 typeid(*selection) != typeid(MapCenterObj)) )
612 api.setError (Aborted,"Type of selection is not a branch");
613 } else if (api.checkParamCount(2))
615 s=api.parString (ok,0); // selection
616 t=api.parString (ok,1); // path to map
617 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
618 addMapReplaceInt(s,t);
620 } else if (com==QString("addMapInsert"))
624 api.setError (Aborted,"Nothing selected");
625 } else if ( (typeid(*selection) != typeid(BranchObj) &&
626 typeid(*selection) != typeid(MapCenterObj)) )
628 api.setError (Aborted,"Type of selection is not a branch");
631 if (api.checkParamCount(2))
633 t=api.parString (ok,0); // path to map
634 y=api.parInt(ok,1); // position
635 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
636 addMapInsertInt(t,y);
639 } else if (com=="delete")
643 api.setError (Aborted,"Nothing selected");
644 } else if ( (typeid(*selection) != typeid(BranchObj) &&
645 typeid(*selection) != typeid(MapCenterObj)) )
647 api.setError (Aborted,"Type of selection is not a branch");
648 } else if (api.checkParamCount(0))
652 } else if (com=="deleteKeepChilds")
656 api.setError (Aborted,"Nothing selected");
657 } else if ( (typeid(*selection) != typeid(BranchObj) &&
658 typeid(*selection) != typeid(MapCenterObj)) )
660 api.setError (Aborted,"Type of selection is not a branch");
661 } else if (api.checkParamCount(0))
663 removeBranchKeepChilds();
665 } else if (com=="linkBranchToPos")
669 api.setError (Aborted,"Nothing selected");
670 } else if ( (typeid(*selection) != typeid(BranchObj) &&
671 typeid(*selection) != typeid(MapCenterObj)) )
673 api.setError (Aborted,"Type of selection is not a branch");
674 } else if (api.checkParamCount(4))
676 // 0 selectstring of parent
677 // 1 num in parent (for branches)
678 // 2,3 x,y of mainbranch or mapcenter
679 s=api.parString(ok,0);
680 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
683 if (typeid(*dst) == typeid(BranchObj) )
685 // Get number in parent
688 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
689 } else if (typeid(*dst) == typeid(MapCenterObj) )
691 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
692 // Get coordinates of mainbranch
697 if (ok) ((BranchObj*)selection)->move (x,y);
702 } else if (com=="moveBranchUp")
706 api.setError (Aborted,"Nothing selected");
707 } else if ( (typeid(*selection) != typeid(BranchObj) &&
708 typeid(*selection) != typeid(MapCenterObj)) )
710 api.setError (Aborted,"Type of selection is not a branch");
711 } else if (api.checkParamCount(0))
715 } else if (com=="moveBranchDown")
719 api.setError (Aborted,"Nothing selected");
720 } else if ( (typeid(*selection) != typeid(BranchObj) &&
721 typeid(*selection) != typeid(MapCenterObj)) )
723 api.setError (Aborted,"Type of selection is not a branch");
724 } else if (api.checkParamCount(0))
728 } else if (com=="move")
732 api.setError (Aborted,"Nothing selected");
733 } else if ( typeid(*selection) != typeid(BranchObj) &&
734 typeid(*selection) != typeid(MapCenterObj) &&
735 typeid(*selection) != typeid(FloatImageObj) )
737 api.setError (Aborted,"Type of selection is not a branch or floatimage");
738 } else if (api.checkParamCount(2))
748 else if (com=="moveRel")
752 api.setError (Aborted,"Nothing selected");
753 } else if ( typeid(*selection) != typeid(BranchObj) &&
754 typeid(*selection) != typeid(MapCenterObj) &&
755 typeid(*selection) != typeid(FloatImageObj) )
757 api.setError (Aborted,"Type of selection is not a branch or floatimage");
758 } else if (api.checkParamCount(2))
764 if (ok) moveRel (x,y);
767 } else if (com=="setHeading")
771 api.setError (Aborted,"Nothing selected");
772 } else if ( (typeid(*selection) != typeid(BranchObj) &&
773 typeid(*selection) != typeid(MapCenterObj)) )
775 api.setError (Aborted,"Type of selection is not a branch");
776 } else if (api.checkParamCount(1))
778 s=api.parString (ok,0);
782 } else if (com=="setURL")
786 api.setError (Aborted,"Nothing selected");
787 } else if ( (typeid(*selection) != typeid(BranchObj) &&
788 typeid(*selection) != typeid(MapCenterObj)) )
790 api.setError (Aborted,"Type of selection is not a branch");
791 } else if (api.checkParamCount(1))
793 s=api.parString (ok,0);
794 if (ok) setURLInt(s);
796 } else if (com=="setVymLink")
800 api.setError (Aborted,"Nothing selected");
801 } else if ( (typeid(*selection) != typeid(BranchObj) &&
802 typeid(*selection) != typeid(MapCenterObj)) )
804 api.setError (Aborted,"Type of selection is not a branch");
805 } else if (api.checkParamCount(1))
807 s=api.parString (ok,0);
808 if (ok) setVymLinkInt(s);
811 else if (com=="setHideExport")
815 api.setError (Aborted,"Nothing selected");
816 } else if ( typeid(*selection) != typeid(BranchObj) &&
817 typeid(*selection) != typeid(MapCenterObj) &&
818 typeid(*selection) != typeid(FloatImageObj) )
820 api.setError (Aborted,"Type of selection is not a branch or floatimage");
821 } else if (api.checkParamCount(2))
823 s=api.parString(ok,0);
826 BranchObj* bo=(BranchObj*)selection;
827 bo->activateStandardFlag(s);
828 bo->updateFlagsToolbar();
832 else if (com=="setFlag")
836 api.setError (Aborted,"Nothing selected");
837 } else if ( (typeid(*selection) != typeid(BranchObj) &&
838 typeid(*selection) != typeid(MapCenterObj)) )
840 api.setError (Aborted,"Type of selection is not a branch");
841 } else if (api.checkParamCount(1))
843 s=api.parString(ok,0);
846 BranchObj* bo=(BranchObj*)selection;
847 bo->activateStandardFlag(s);
848 bo->updateFlagsToolbar();
852 else if (com=="unsetFlag")
856 api.setError (Aborted,"Nothing selected");
857 } else if ( (typeid(*selection) != typeid(BranchObj) &&
858 typeid(*selection) != typeid(MapCenterObj)) )
860 api.setError (Aborted,"Type of selection is not a branch");
861 } else if (api.checkParamCount(1))
863 s=api.parString(ok,0);
866 BranchObj* bo=(BranchObj*)selection;
867 bo->deactivateStandardFlag(s);
868 bo->updateFlagsToolbar();
872 } else if (com==QString("undoMap"))
874 if (api.checkParamCount(1))
875 addMapReplaceInt("",api.parString (ok,0));
876 } else if (com=="select")
878 if (api.checkParamCount(1))
880 s=api.parString(ok,0);
886 api.setError (Aborted,"Unknown command");
890 if (api.errorLevel()==NoError)
894 // TODO Error handling
895 qWarning("MapEditor::parseAtom: Error!");
896 qWarning(api.errorMessage());
900 void MapEditor::toggleHistoryWindow()
902 if (historyWindow.isVisible())
903 historyWindow.hide();
905 historyWindow.show();
909 bool MapEditor::isDefault()
914 bool MapEditor::isUnsaved()
919 bool MapEditor::hasChanged()
924 void MapEditor::setChanged()
932 void MapEditor::closeMap()
934 // Unselect before disabling the toolbar actions
935 if (selection) selection->unselect();
943 void MapEditor::setFilePath(QString fname)
945 setFilePath (fname,fname);
948 void MapEditor::setFilePath(QString fname, QString destname)
950 if (fname.isEmpty() || fname=="")
957 filePath=fname; // becomes absolute path
958 fileName=fname; // gets stripped of path
959 destPath=destname; // needed for vymlinks
961 // If fname is not an absolute path, complete it
962 filePath=QDir(fname).absPath();
963 fileDir=filePath.left (1+filePath.findRev ("/"));
965 // Set short name, too. Search from behind:
966 int i=fileName.findRev("/");
967 if (i>=0) fileName=fileName.remove (0,i+1);
969 // Forget the .vym (or .xml) for name of map
970 mapName=fileName.left(fileName.findRev(".",-1,true) );
972 // Adjust history window
973 historyWindow.setCaption (__VYM " - " +tr("History for ")+fileName);
977 QString MapEditor::getFilePath()
982 QString MapEditor::getFileName()
987 QString MapEditor::getMapName()
992 QString MapEditor::getDestPath()
997 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
999 ErrorCode err=success;
1003 if (selection) selection->unselect();
1006 mapCenter->setMapEditor(this);
1007 // (map state is set later at end of load...)
1010 saveStateChangingPart(selection,"Load map");
1014 mapBuilderHandler handler;
1015 QFile file( fname );
1017 // I am paranoid: file should exist anyway
1018 // according to check in mainwindow.
1019 if (!file.exists() )
1021 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1022 tr("Couldn't open map " +fname)+".");
1026 blockReposition=true;
1027 QXmlInputSource source( file);
1028 QXmlSimpleReader reader;
1029 reader.setContentHandler( &handler );
1030 reader.setErrorHandler( &handler );
1031 handler.setMapEditor( this );
1032 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
1033 handler.setInputFile (file.name());
1034 handler.setLoadMode (lmode);
1035 blockSaveState=true;
1036 bool ok = reader.parse( source );
1037 blockReposition=false;
1038 blockSaveState=false;
1042 mapCenter->reposition();
1052 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
1053 tr( handler.errorProtocol() ) );
1055 // Still return "success": the map maybe at least
1056 // partially read by the parser
1063 int MapEditor::save (const SaveMode &savemode)
1067 // The SaveMode UndoCommand is not supported here
1068 if (savemode==UndoCommand) return 1;
1070 // Create mapName and fileDir
1071 makeSubDirs (fileDir);
1075 fname=mapName+".xml";
1077 // use name given by user, even if he chooses .doc
1082 if (savemode==CompleteMap || selection==NULL)
1083 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
1085 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
1087 if (!saveStringToDisk(fileDir+fname,saveFile))
1100 void MapEditor::setZipped (bool z)
1105 bool MapEditor::saveZipped ()
1110 void MapEditor::print()
1114 printer = new QPrinter;
1115 printer->setColorMode (QPrinter::Color);
1116 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
1119 QRect totalBBox=mapCenter->getTotalBBox();
1121 // Try to set orientation automagically
1122 // Note: Interpretation of generated postscript is amibiguous, if
1123 // there are problems with landscape mode, see
1124 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
1126 if (totalBBox.width()>totalBBox.height())
1127 // recommend landscape
1128 printer->setOrientation (QPrinter::Landscape);
1130 // recommend portrait
1131 printer->setOrientation (QPrinter::Portrait);
1133 if ( printer->setup(this) )
1134 // returns false, if printing is canceled
1136 QPainter pp(printer);
1138 // Don't print the visualisation of selection
1139 LinkableMapObj *oldselection=NULL;
1142 oldselection=selection;
1143 selection->unselect();
1146 // Handle sizes of map and paper:
1148 // setWindow defines which part of the canvas will be transformed
1149 // setViewport defines area on paper in device coordinates (dpi)
1150 // e.g. (0,50,700,700) is upper part on A4
1151 // see also /usr/lib/qt3/doc/html/coordsys.html
1153 Q3PaintDeviceMetrics metrics (printer);
1155 double paperAspect = (double)metrics.width() / (double)metrics.height();
1156 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1158 QRect mapRect=totalBBox;
1159 Q3CanvasRectangle *frame=NULL;
1160 Q3CanvasText *footerFN=NULL;
1161 Q3CanvasText *footerDate=NULL;
1162 if (printFrame || printFooter)
1167 // Print frame around map
1168 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1169 totalBBox.width()+20, totalBBox.height()+20);
1170 frame=new Q3CanvasRectangle (mapRect,mapCanvas);
1171 frame->setBrush (QColor(Qt::white));
1172 frame->setPen (QColor(Qt::black));
1176 /* TODO remove after testing
1177 QCanvasLine *l=new QCanvasLine (mapCanvas);
1178 l->setPoints (0,0,mapRect.width(),mapRect.height());
1179 l->setPen (QPen(QColor(black), 1));
1186 // Print footer below map
1188 font.setPointSize(10);
1189 footerFN=new Q3CanvasText (mapCanvas);
1190 footerFN->setText ("VYM - " + fileName);
1191 footerFN->setFont(font);
1192 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1193 footerFN->setZ(Z_TEXT);
1195 footerDate=new Q3CanvasText (mapCanvas);
1196 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1197 footerDate->setFont(font);
1198 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1199 footerDate->setZ(Z_TEXT);
1202 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1205 pp.setWindow (mapRect);
1208 if (mapAspect>=paperAspect)
1210 // Fit horizontally to paper width
1211 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1214 // Fit vertically to paper height
1215 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1218 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1220 // Delete Frame and footer
1224 delete (footerDate);
1226 if (frame) delete (frame);
1228 // Restore selection
1231 selection=oldselection;
1232 selection->select();
1235 // Save settings in vymrc
1236 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1240 QPixmap MapEditor::getPixmap()
1242 QRect mapRect=mapCenter->getTotalBBox();
1243 QPixmap pix (mapRect.size());
1246 // Don't print the visualisation of selection
1247 LinkableMapObj *oldselection=NULL;
1250 oldselection=selection;
1251 selection->unselect();
1254 pp.setWindow (mapRect);
1256 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1259 // Restore selection
1262 selection=oldselection;
1263 selection->select();
1269 void MapEditor::setHideTmpMode (HideTmpMode mode)
1272 mapCenter->setHideTmp (hidemode);
1273 mapCenter->reposition();
1278 HideTmpMode MapEditor::getHideTmpMode()
1283 void MapEditor::exportImage(QString fn)
1285 setExportMode (true);
1286 QPixmap pix (getPixmap());
1287 pix.save(fn, "PNG");
1288 setExportMode (false);
1291 void MapEditor::setExportMode (bool b)
1293 // should be called before and after exports
1294 // depending on the settings
1295 if (b && settings.value("/export/useHideExport","yes")=="yes")
1296 setHideTmpMode (HideExport);
1298 setHideTmpMode (HideNone);
1301 void MapEditor::exportImage(QString fn, QString format)
1303 setExportMode (true);
1304 QPixmap pix (getPixmap());
1305 pix.save(fn, format);
1306 setExportMode (false);
1309 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1313 ex.setMapCenter(mapCenter);
1314 if (ex.setConfigFile(cf))
1316 setExportMode (true);
1317 ex.exportPresentation();
1318 setExportMode (false);
1324 void MapEditor::exportXML(const QString &dir)
1326 // Hide stuff during export, if settings want this
1327 setExportMode (true);
1329 // Create subdirectories
1332 // write to directory
1333 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1336 file.setName ( dir + "/"+mapName+".xml");
1337 if ( !file.open( QIODevice::WriteOnly ) )
1339 // This should neverever happen
1340 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1344 // Write it finally, and write in UTF8, no matter what
1345 QTextStream ts( &file );
1346 ts.setEncoding (QTextStream::UnicodeUTF8);
1350 // Now write image, too
1351 exportImage (dir+"/images/"+mapName+".png");
1353 setExportMode (false);
1356 void MapEditor::clear()
1360 selection->unselect();
1367 void MapEditor::copy()
1371 // write to directory
1372 QString clipfile="part";
1373 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1376 file.setName ( clipboardDir + "/"+clipfile+".xml");
1377 if ( !file.open( QIODevice::WriteOnly ) )
1379 // This should neverever happen
1380 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1384 // Write it finally, and write in UTF8, no matter what
1385 QTextStream ts( &file );
1386 ts.setEncoding (QTextStream::UnicodeUTF8);
1390 clipboardEmpty=false;
1395 void MapEditor::redo()
1397 blockSaveState=true;
1399 // Restore variables
1400 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1401 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1402 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1403 // Can we undo at all?
1404 if (redosAvail<1) return;
1407 if (undosAvail<stepsTotal) undosAvail++;
1409 if (curStep>stepsTotal) curStep=1;
1410 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1411 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1412 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1413 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1414 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1416 // Find out current undo directory
1417 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1419 /* TODO remove testing
1421 cout << "ME::redo() begin\n";
1422 cout << " undosAvail="<<undosAvail<<endl;
1423 cout << " redosAvail="<<redosAvail<<endl;
1424 cout << " curStep="<<curStep<<endl;
1425 cout << " ---------------------------"<<endl;
1426 cout << " comment="<<comment.toStdString()<<endl;
1427 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1428 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1429 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1430 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1431 cout << " ---------------------------"<<endl<<endl;
1433 // select object before redo
1434 // FIXME better give up if no selection there...
1435 if (!redoSelection.isEmpty())
1436 select (redoSelection);
1439 parseAtom (redoCommand);
1440 mapCenter->reposition();
1442 blockSaveState=false;
1444 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1445 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1446 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1447 undoSet.writeSettings(histPath);
1449 historyWindow.update (undoSet);
1452 /* TODO remove testing
1454 cout << "ME::redo() end\n";
1455 cout << " undosAvail="<<undosAvail<<endl;
1456 cout << " redosAvail="<<redosAvail<<endl;
1457 cout << " curStep="<<curStep<<endl;
1458 cout << " ---------------------------"<<endl<<endl;
1463 bool MapEditor::isRedoAvailable()
1465 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1471 void MapEditor::undo()
1473 blockSaveState=true;
1475 // Restore variables
1476 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1477 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1478 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1480 // Can we undo at all?
1481 if (undosAvail<1) return;
1483 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1484 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1485 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1486 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1487 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1489 // Find out current undo directory
1490 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1492 // select object before undo
1493 if (!undoSelection.isEmpty())
1494 select (undoSelection);
1498 cout << "ME::undo() begin\n";
1499 cout << " undosAvail="<<undosAvail<<endl;
1500 cout << " redosAvail="<<redosAvail<<endl;
1501 cout << " curStep="<<curStep<<endl;
1502 cout << " ---------------------------"<<endl;
1503 cout << " comment="<<comment.toStdString()<<endl;
1504 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1505 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1506 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1507 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1508 cout << " ---------------------------"<<endl<<endl;
1509 parseAtom (undoCommand);
1510 mapCenter->reposition();
1514 if (curStep<1) curStep=stepsTotal;
1518 blockSaveState=false;
1519 /* TODO remove testing
1521 cout << "ME::undo() end\n";
1522 cout << " undosAvail="<<undosAvail<<endl;
1523 cout << " redosAvail="<<redosAvail<<endl;
1524 cout << " curStep="<<curStep<<endl;
1525 cout << " ---------------------------"<<endl<<endl;
1527 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1528 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1529 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1530 undoSet.writeSettings(histPath);
1532 historyWindow.update (undoSet);
1536 bool MapEditor::isUndoAvailable()
1538 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1544 void MapEditor::gotoStep (int i)
1546 // Restore variables
1547 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1548 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1550 cout << "ME::goto "<<i<<endl;
1552 if (i<0) i=undosAvail+redosAvail;
1554 // Clicking above current step makes us undo things
1557 for (int j=0; j<undosAvail-i; j++) undo();
1560 // Clicking below current step makes us redo things
1562 for (int j=undosAvail; j<i; j++) redo();
1564 // And ignore clicking the current row ;-)
1567 void MapEditor::addMapReplaceInt(const QString &undoSel, const QString &path)
1569 QString pathDir=path.left(path.findRev("/"));
1575 // We need to parse saved XML data
1576 mapBuilderHandler handler;
1577 QXmlInputSource source( file);
1578 QXmlSimpleReader reader;
1579 reader.setContentHandler( &handler );
1580 reader.setErrorHandler( &handler );
1581 handler.setMapEditor( this );
1582 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1583 if (undoSel.isEmpty())
1587 handler.setLoadMode (NewMap);
1591 handler.setLoadMode (ImportReplace);
1593 blockReposition=true;
1594 bool ok = reader.parse( source );
1595 blockReposition=false;
1598 // This should never ever happen
1599 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1600 handler.errorProtocol());
1603 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1606 void MapEditor::addMapInsertInt (const QString &path, int pos)
1608 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1609 typeid(*selection) == typeid(MapCenterObj)))
1611 QString pathDir=path.left(path.findRev("/"));
1617 // We need to parse saved XML data
1618 mapBuilderHandler handler;
1619 QXmlInputSource source( file);
1620 QXmlSimpleReader reader;
1621 reader.setContentHandler( &handler );
1622 reader.setErrorHandler( &handler );
1623 handler.setMapEditor( this );
1624 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1625 handler.setLoadMode (ImportAdd);
1626 blockReposition=true;
1627 bool ok = reader.parse( source );
1628 blockReposition=false;
1631 // This should never ever happen
1632 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1633 handler.errorProtocol());
1635 if (selection!=mapCenter)
1636 ((BranchObj*)selection)->getLastBranch()->moveBranchTo ((BranchObj*)(selection),pos);
1638 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1642 void MapEditor::pasteNoSave()
1644 load (clipboardDir+"/part.xml",ImportAdd);
1647 void MapEditor::cutNoSave()
1653 void MapEditor::paste()
1655 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1656 typeid(*selection) == typeid(MapCenterObj)))
1658 saveStateChangingPart(selection,QString("Paste to %1").arg( getName(selection)));
1660 mapCenter->reposition();
1665 void MapEditor::cut()
1667 saveStateChangingPart(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
1670 mapCenter->reposition();
1674 void MapEditor::move(const int &x, const int &y)
1678 QString ps=qpointToString (selection->getAbsPos());
1679 QString s=selection->getSelectString();
1682 s, "move "+qpointToString (QPoint (x,y)),
1683 QString("Move %1 to %2").arg(getName(selection)).arg(ps));
1684 selection->move(x,y);
1685 mapCenter->reposition();
1691 void MapEditor::moveRel (const int &x, const int &y)
1693 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1694 typeid(*selection) == typeid(MapCenterObj) ||
1695 typeid(*selection) == typeid (FloatImageObj)))
1697 QString ps=qpointToString (selection->getRelPos());
1698 QString s=selection->getSelectString();
1701 s, "moveRel "+qpointToString (QPoint (x,y)),
1702 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps));
1703 ((OrnamentedObj*)selection)->move2RelPos (x,y);
1704 mapCenter->reposition();
1709 void MapEditor::moveBranchUp()
1713 if (typeid(*selection) == typeid(BranchObj) )
1715 bo=(BranchObj*)selection;
1716 if (!bo->canMoveBranchUp()) return;
1717 par=(BranchObj*)(bo->getParObj());
1718 selection->unselect();
1719 bo=par->moveBranchUp (bo); // bo will be the one below selection
1720 selection->select();
1721 saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1722 mapCenter->reposition();
1723 ensureSelectionVisible();
1727 void MapEditor::moveBranchDown()
1731 if (typeid(*selection) == typeid(BranchObj) )
1733 bo=(BranchObj*)selection;
1734 if (!bo->canMoveBranchDown()) return;
1735 par=(BranchObj*)(bo->getParObj());
1736 selection->unselect();
1737 bo=par->moveBranchDown(bo); // bo will be the one above selection
1738 selection->select();
1739 saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1740 mapCenter->reposition();
1741 ensureSelectionVisible();
1745 QString MapEditor::getHeading(bool &ok, QPoint &p)
1748 (typeid(*selection) == typeid(BranchObj) ||
1749 typeid(*selection) == typeid(MapCenterObj) ) )
1752 ensureSelectionVisible();
1753 p = ((BranchObj*)selection)->getAbsPos();
1754 p.setX (p.x() - contentsX());
1755 p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2);
1756 return ((BranchObj*)selection)->getHeading();
1762 void MapEditor::setHeading(const QString &s)
1765 (typeid(*selection) == typeid(BranchObj) ||
1766 typeid(*selection) == typeid(MapCenterObj) ) )
1768 editingBO=(BranchObj*)selection;
1769 saveStateConstSelection(
1770 "setHeading (\""+editingBO->getHeading()+"\")",
1771 "setHeading (\""+s+"\")",
1772 QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) );
1773 editingBO->setHeading(s );
1775 mapCenter->reposition();
1777 ensureSelectionVisible();
1781 void MapEditor::setURLInt (const QString &s)
1783 // Internal function, no saveState needed
1785 (typeid(*selection) == typeid(BranchObj) ||
1786 typeid(*selection) == typeid(MapCenterObj) ) )
1788 ((BranchObj*)selection)->setURL(s);
1789 mapCenter->reposition();
1791 ensureSelectionVisible();
1795 void MapEditor::setHeadingInt(const QString &s)
1798 (typeid(*selection) == typeid(BranchObj) ||
1799 typeid(*selection) == typeid(MapCenterObj) ) )
1801 ((BranchObj*)selection)->setHeading(s);
1802 mapCenter->reposition();
1804 ensureSelectionVisible();
1808 void MapEditor::setVymLinkInt (const QString &s)
1810 // Internal function, no saveState needed
1812 (typeid(*selection) == typeid(BranchObj) ||
1813 typeid(*selection) == typeid(MapCenterObj) ) )
1815 ((BranchObj*)selection)->setVymLink(s);
1816 mapCenter->reposition();
1818 ensureSelectionVisible();
1822 BranchObj* MapEditor::addNewBranchInt(int num)
1824 // Depending on pos:
1825 // -3 insert in childs of parent above selection
1826 // -2 add branch to selection
1827 // -1 insert in childs of parent below selection
1828 // 0..n insert in childs of parent at pos
1829 BranchObj *newbo=NULL;
1831 (typeid(*selection) == typeid(BranchObj) ||
1832 typeid(*selection) == typeid(MapCenterObj) ) )
1834 BranchObj* bo = (BranchObj*) selection;
1837 // save scroll state. If scrolled, automatically select
1838 // new branch in order to tmp unscroll parent...
1839 return bo->addBranch();
1844 bo=(BranchObj*)bo->getParObj();
1848 bo=(BranchObj*)bo->getParObj();
1851 newbo=bo->insertBranch(num);
1856 BranchObj* MapEditor::addNewBranch(int pos)
1858 // Different meaning than num in addNewBranchInt!
1862 BranchObj *bo = (BranchObj*) selection;
1863 BranchObj *newbo=NULL;
1866 (typeid(*selection) == typeid(BranchObj) ||
1867 typeid(*selection) == typeid(MapCenterObj) ) )
1869 newbo=addNewBranchInt (pos-2);
1873 saveStateConstSelection (
1874 //QString ("delete (\"%1\")").arg(newbo->getSelectString()),
1876 QString ("addBranch (%1)").arg(pos-2),
1877 QString ("Add new branch to %1").arg(getName(bo))); //TODO undoCommand
1879 mapCenter->reposition();
1887 BranchObj* MapEditor::addNewBranchBefore()
1889 BranchObj *newbo=NULL;
1891 (typeid(*selection) == typeid(BranchObj) ) )
1892 // We accept no MapCenterObj here, so we _have_ a parent
1894 BranchObj* bo = (BranchObj*) selection;
1895 QPoint p=bo->getRelPos();
1898 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1900 // add below selection
1901 newbo=parbo->insertBranch(bo->getNum()+1);
1904 newbo->move2RelPos (p);
1906 // Move selection to new branch
1907 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1909 saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()",
1910 QString ("Add branch before %1").arg(getName(bo)));
1912 mapCenter->reposition();
1919 void MapEditor::deleteSelection()
1921 if (selection && typeid(*selection) ==typeid(BranchObj) )
1923 BranchObj* bo=(BranchObj*)selection;
1924 BranchObj* par=(BranchObj*)(bo->getParObj());
1926 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
1928 par->removeBranch(bo);
1930 selection->select();
1931 ensureSelectionVisible();
1932 mapCenter->reposition();
1935 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1937 FloatImageObj* fio=(FloatImageObj*)selection;
1938 BranchObj* par=(BranchObj*)(fio->getParObj());
1939 saveStateChangingPart(par, QString("Delete %1").arg(getName(fio)));
1942 par->removeFloatImage(fio);
1944 selection->select();
1945 ensureSelectionVisible();
1946 mapCenter->reposition();
1951 LinkableMapObj* MapEditor::getSelection()
1956 void MapEditor::unselect()
1960 selectionLast=selection;
1961 selection->unselect();
1966 void MapEditor::reselect()
1970 selection=selectionLast;
1971 selection->select();
1976 bool MapEditor::select (const QString &s)
1978 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1980 // Finally select the found object
1983 if (selection) unselect();
1985 selection->select();
1987 ensureSelectionVisible();
1993 QString MapEditor::getSelectString()
1995 if (selection) return selection->getSelectString();
1999 void MapEditor::selectInt (LinkableMapObj *lmo)
2001 if (lmo && selection != lmo)
2003 // select the MapObj
2004 if (selection) selection->unselect();
2006 selection->select();
2012 void MapEditor::selectNextBranchInt()
2014 // Increase number of branch
2017 QString s=selection->getSelectString();
2023 part=s.section(",",-1);
2025 num=part.right(part.length() - 3);
2027 s=s.left (s.length() -num.length());
2030 num=QString ("%1").arg(num.toUInt()+1);
2034 // Try to select this one
2035 if (select (s)) return;
2037 // We have no direct successor,
2038 // try to increase the parental number in order to
2039 // find a successor with same depth
2041 int d=selection->getDepth();
2046 while (!found && d>0)
2048 s=s.section (",",0,d-1);
2049 // replace substring of current depth in s with "1"
2050 part=s.section(",",-1);
2052 num=part.right(part.length() - 3);
2056 // increase number of parent
2057 num=QString ("%1").arg(num.toUInt()+1);
2058 s=s.section (",",0,d-2) + ","+ typ+num;
2061 // Special case, look at orientation
2062 if (selection->getOrientation()==OrientRightOfCenter)
2063 num=QString ("%1").arg(num.toUInt()+1);
2065 num=QString ("%1").arg(num.toUInt()-1);
2070 // pad to oldDepth, select the first branch for each depth
2071 for (i=d;i<oldDepth;i++)
2076 if ( ((BranchObj*)selection)->countBranches()>0)
2084 // try to select the freshly built string
2092 void MapEditor::selectPrevBranchInt()
2094 // Decrease number of branch
2097 QString s=selection->getSelectString();
2103 part=s.section(",",-1);
2105 num=part.right(part.length() - 3);
2107 s=s.left (s.length() -num.length());
2110 num=QString ("%1").arg(num.toUInt()-1);
2114 // Try to select this one
2115 if (select (s)) return;
2117 // We have no direct precessor,
2118 // try to decrease the parental number in order to
2119 // find a precessor with same depth
2121 int d=selection->getDepth();
2126 while (!found && d>0)
2128 s=s.section (",",0,d-1);
2129 // replace substring of current depth in s with "1"
2130 part=s.section(",",-1);
2132 num=part.right(part.length() - 3);
2136 // decrease number of parent
2137 num=QString ("%1").arg(num.toUInt()-1);
2138 s=s.section (",",0,d-2) + ","+ typ+num;
2141 // Special case, look at orientation
2142 if (selection->getOrientation()==OrientRightOfCenter)
2143 num=QString ("%1").arg(num.toUInt()-1);
2145 num=QString ("%1").arg(num.toUInt()+1);
2150 // pad to oldDepth, select the last branch for each depth
2151 for (i=d;i<oldDepth;i++)
2155 if ( ((BranchObj*)selection)->countBranches()>0)
2156 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
2163 // try to select the freshly built string
2171 void MapEditor::selectUpperBranch()
2175 if (typeid(*selection) == typeid(BranchObj))
2177 if (selection->getOrientation()==OrientRightOfCenter)
2178 selectPrevBranchInt();
2180 if (selection->getDepth()==1)
2181 selectNextBranchInt();
2183 selectPrevBranchInt();
2188 void MapEditor::selectLowerBranch()
2192 if (typeid(*selection) == typeid(BranchObj))
2194 if (selection->getOrientation()==OrientRightOfCenter)
2195 selectNextBranchInt();
2197 if (selection->getDepth()==1)
2198 selectPrevBranchInt();
2200 selectNextBranchInt();
2206 void MapEditor::selectLeftBranch()
2212 if (typeid(*selection) == typeid(MapCenterObj))
2214 par= (BranchObj*) selection;
2215 bo=par->getLastSelectedBranch();
2218 // Workaround for reselecting on left and right side
2219 if (bo->getOrientation()==OrientRightOfCenter)
2221 bo=par->getLastBranch();
2227 selection->select();
2229 ensureSelectionVisible();
2234 par=(BranchObj*)(selection->getParObj());
2235 if (selection->getOrientation()==OrientRightOfCenter)
2237 if (typeid(*selection) == typeid(BranchObj) ||
2238 typeid(*selection) == typeid(FloatImageObj))
2240 selection->unselect();
2242 selection->select();
2244 ensureSelectionVisible();
2248 if (typeid(*selection) == typeid(BranchObj) )
2250 bo=((BranchObj*)selection)->getLastSelectedBranch();
2253 selection->unselect();
2255 selection->select();
2257 ensureSelectionVisible();
2265 void MapEditor::selectRightBranch()
2272 if (typeid(*selection) == typeid(MapCenterObj))
2274 par= (BranchObj*) selection;
2275 bo=par->getLastSelectedBranch();
2278 // Workaround for reselecting on left and right side
2279 if (bo->getOrientation()==OrientLeftOfCenter)
2280 bo=par->getFirstBranch();
2285 selection->select();
2286 ensureSelectionVisible();
2291 par=(BranchObj*)(selection->getParObj());
2292 if (selection->getOrientation()==OrientLeftOfCenter)
2294 if (typeid(*selection) == typeid(BranchObj) ||
2295 typeid(*selection) == typeid(FloatImageObj))
2297 selection->unselect();
2299 selection->select();
2301 ensureSelectionVisible();
2305 if (typeid(*selection) == typeid(BranchObj) )
2307 bo=((BranchObj*)selection)->getLastSelectedBranch();
2310 selection->unselect();
2312 selection->select();
2314 ensureSelectionVisible();
2322 void MapEditor::selectFirstBranch()
2328 if (typeid(*selection) == typeid(BranchObj))
2330 bo1= (BranchObj*) selection;
2331 par=(BranchObj*)(bo1->getParObj());
2332 bo2=par->getFirstBranch();
2336 selection->select();
2337 ensureSelectionVisible();
2344 void MapEditor::selectLastBranch()
2350 if (typeid(*selection) == typeid(BranchObj))
2352 bo1= (BranchObj*) selection;
2353 par=(BranchObj*)(bo1->getParObj());
2354 bo2=par->getLastBranch();
2358 selection->select();
2359 ensureSelectionVisible();
2366 void MapEditor::setColor(QColor c)
2371 void MapEditor::selectBackgroundColor()
2373 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2374 if ( !col.isValid() ) return;
2375 setBackgroundColor( col );
2377 saveStateComplete(QString("Set background color of map to %1").arg(col.name()));
2380 void MapEditor::setBackgroundColor(QColor c)
2382 mapCanvas->setBackgroundColor (c);
2385 QColor MapEditor::pickColor()
2389 if (typeid(*selection) == typeid(BranchObj) ||
2390 typeid(*selection) == typeid(MapCenterObj))
2392 BranchObj *bo=(BranchObj*)selection;
2393 actColor=bo->getColor();
2399 void MapEditor::colorItem()
2403 if (typeid(*selection) == typeid(BranchObj) ||
2404 typeid(*selection) == typeid(MapCenterObj))
2406 BranchObj *bo=(BranchObj*)selection;
2407 saveStateChangingPart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2408 bo->setColor(actColor); // color branch
2413 void MapEditor::colorBranch()
2417 if (typeid(*selection) == typeid(BranchObj) ||
2418 typeid(*selection) == typeid(MapCenterObj))
2420 BranchObj *bo=(BranchObj*)selection;
2421 saveStateChangingPart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2422 bo->setColorChilds(actColor); // color links, color childs
2428 void MapEditor::toggleStandardFlag(QString f)
2432 if (typeid(*selection) == typeid(BranchObj) ||
2433 typeid(*selection) == typeid(MapCenterObj))
2435 BranchObj *bo=(BranchObj*)selection;
2437 if (bo->isSetStandardFlag(f))
2447 saveStateConstSelection(QString("%1 (\"%2\")").arg(u).arg(f),
2448 QString("%1 (\"%2\")").arg(r).arg(f),
2449 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2450 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
2456 void MapEditor::setViewCenter()
2458 // transform to CanvasView Coord:
2459 QPoint p=worldMatrix().map(movingCenter);
2460 center ( p.x(), p.y());
2464 BranchObj* MapEditor::findText (QString s, bool cs)
2466 QTextDocument::FindFlags flags=0;
2467 if (cs) flags=QTextDocument::FindCaseSensitively;
2470 { // Nothing found or new find process
2472 // nothing found, start again
2474 itFind=mapCenter->first();
2476 bool searching=true;
2477 bool foundNote=false;
2478 while (searching && !EOFind)
2482 // Searching in Note
2483 if (itFind->getNote().contains(s,cs))
2485 if (selection!=itFind)
2487 if (selection) ((BranchObj*)selection)->unselect();
2489 selection->select();
2491 ensureSelectionVisible();
2493 if (textEditor->findText(s,flags))
2499 // Searching in Heading
2500 if (searching && itFind->getHeading().contains (s,cs) )
2502 if (selection) ((BranchObj*)selection)->unselect();
2504 selection->select();
2506 ensureSelectionVisible();
2512 itFind=itFind->next();
2513 if (!itFind) EOFind=true;
2519 return (BranchObj*)selection;
2524 void MapEditor::findReset()
2525 { // Necessary if text to find changes during a find process
2530 void MapEditor::editURL()
2532 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2533 typeid(*selection) == typeid(MapCenterObj)) )
2536 BranchObj *bo=(BranchObj*)selection;
2537 QString text = QInputDialog::getText(
2538 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2539 bo->getURL(), &ok, this );
2542 // user entered something and pressed OK
2543 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2550 QString MapEditor::getURL()
2552 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2553 typeid(*selection) == typeid(MapCenterObj)) )
2554 return ((BranchObj*)selection)->getURL();
2559 QStringList MapEditor::getURLs()
2562 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2563 typeid(*selection) == typeid(MapCenterObj)) )
2565 BranchObj *bo=(BranchObj*)selection;
2569 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2577 void MapEditor::editHeading2URL()
2579 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2580 typeid(*selection) == typeid(MapCenterObj)) )
2582 BranchObj *bo=(BranchObj*)selection;
2583 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2584 bo->setURL (bo->getHeading());
2589 void MapEditor::editBugzilla2URL()
2591 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2592 typeid(*selection) == typeid(MapCenterObj)) )
2594 BranchObj *bo=(BranchObj*)selection;
2595 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2596 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo)));
2602 void MapEditor::editFATE2URL()
2604 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2605 typeid(*selection) == typeid(MapCenterObj)) )
2607 BranchObj *bo=(BranchObj*)selection;
2608 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2609 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2615 void MapEditor::editVymLink()
2617 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2618 typeid(*selection) == typeid(MapCenterObj)) )
2620 BranchObj *bo=(BranchObj*)selection;
2621 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map"));
2622 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2623 fd->setCaption(__VYM " - " +tr("Link to another map"));
2624 if (! bo->getVymLink().isEmpty() )
2625 fd->setSelection( bo->getVymLink() );
2629 if ( fd->exec() == QDialog::Accepted )
2631 saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2632 bo->setVymLink (fd->selectedFile() );
2634 mapCenter->reposition();
2641 void MapEditor::deleteVymLink()
2643 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2644 typeid(*selection) == typeid(MapCenterObj)) )
2646 BranchObj *bo=(BranchObj*)selection;
2647 saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2648 bo->setVymLink ("" );
2650 mapCenter->reposition();
2656 void MapEditor::toggleHideExport()
2658 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2659 typeid(*selection) == typeid(MapCenterObj)) ||
2660 (typeid(*selection)==typeid(FloatImageObj))
2663 OrnamentedObj *oo=(OrnamentedObj*)selection;
2665 if (oo->hideInExport())
2667 oo->setHideInExport(false);
2672 oo->setHideInExport(true);
2675 saveStateComplete(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2677 mapCenter->reposition();
2683 QString MapEditor::getVymLink()
2685 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2686 typeid(*selection) == typeid(MapCenterObj)) )
2688 return ((BranchObj*)selection)->getVymLink();
2694 QStringList MapEditor::getVymLinks()
2697 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2698 typeid(*selection) == typeid(MapCenterObj)) )
2700 BranchObj *bo=(BranchObj*)selection;
2704 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2712 void MapEditor::removeBranchKeepChilds()
2714 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2716 BranchObj* bo=(BranchObj*)selection;
2717 BranchObj* par=(BranchObj*)(bo->getParObj());
2718 QPoint p=bo->getRelPos();
2719 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2720 if (bo->getDepth()==1)
2721 saveStateComplete(s);
2723 saveStateChangingPart(selection->getParObj(),s); // TODO undoCommand
2725 QString sel=selection->getSelectString();
2727 par->removeBranchHere(bo);
2728 mapCenter->reposition();
2730 ((BranchObj*)selection)->move2RelPos (p);
2731 mapCenter->reposition();
2736 void MapEditor::removeChilds()
2738 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2741 saveStateChangingPart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
2742 ((BranchObj*)selection)->removeChilds();
2743 mapCenter->reposition();
2747 void MapEditor::editMapInfo()
2749 ExtraInfoDialog dia;
2750 dia.setMapName (getFileName() );
2751 dia.setAuthor (mapCenter->getAuthor() );
2752 dia.setComment(mapCenter->getComment() );
2757 Q3CanvasItemList l=canvas()->allItems();
2758 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2760 stats+=QString ("%1 items on canvas\n").arg (i,6);
2767 bo=mapCenter->first();
2770 if (!bo->getNote().isEmpty() ) n++;
2771 f+= bo->countFloatImages();
2773 xl+=bo->countXLinks();
2776 stats+=QString ("%1 branches\n").arg (b-1,6);
2777 stats+=QString ("%1 xLinks \n").arg (xl,6);
2778 stats+=QString ("%1 notes\n").arg (n,6);
2779 stats+=QString ("%1 images\n").arg (f,6);
2780 dia.setStats (stats);
2782 // Finally show dialog
2783 if (dia.exec() == QDialog::Accepted)
2785 saveStateComplete("Edit info about map"); //TODO undoCommand
2786 mapCenter->setAuthor (dia.getAuthor() );
2787 mapCenter->setComment (dia.getComment() );
2791 void MapEditor::updateActions()
2793 mainWindow->updateActions();
2794 // FIXME maybe don't update if blockReposition is set
2797 void MapEditor::updateNoteFlag()
2800 if ( (typeid(*selection) == typeid(BranchObj)) ||
2801 (typeid(*selection) == typeid(MapCenterObj)) )
2802 ((BranchObj*)selection)->updateNoteFlag();
2805 void MapEditor::setLinkStyle (LinkStyle ls)
2809 saveStateComplete("Set link style"); // TODO undoCommand
2811 bo=mapCenter->first();
2815 bo->setLinkStyle(bo->getDefLinkStyle());
2818 mapCenter->reposition();
2821 LinkStyle MapEditor::getLinkStyle ()
2826 void MapEditor::setLinkColor(QColor c)
2832 void MapEditor::setLinkColorHint()
2834 // called from setLinkColorHint(lch) or at end of parse
2836 bo=mapCenter->first();
2844 void MapEditor::setLinkColorHint(LinkColorHint lch)
2850 void MapEditor::toggleLinkColorHint()
2852 if (linkcolorhint==HeadingColor)
2853 linkcolorhint=DefaultColor;
2855 linkcolorhint=HeadingColor;
2857 bo=mapCenter->first();
2865 LinkColorHint MapEditor::getLinkColorHint()
2867 return linkcolorhint;
2870 QColor MapEditor::getDefLinkColor()
2872 return defLinkColor;
2875 void MapEditor::setDefXLinkColor(QColor col)
2880 QColor MapEditor::getDefXLinkColor()
2882 return defXLinkColor;
2885 void MapEditor::setDefXLinkWidth (int w)
2890 int MapEditor::getDefXLinkWidth()
2892 return defXLinkWidth;
2895 void MapEditor::selectLinkColor()
2897 QColor col = QColorDialog::getColor( defLinkColor, this );
2898 if ( !col.isValid() ) return;
2899 setLinkColor( col );
2900 saveStateComplete(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2904 void MapEditor::toggleScroll()
2906 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2908 BranchObj *bo=((BranchObj*)selection);
2909 if (bo->countBranches()==0) return;
2910 if (bo->getDepth()==0) return;
2912 if (bo->isScrolled())
2916 saveStateChangingPart(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2923 void MapEditor::unScrollAll()
2926 bo=mapCenter->first();
2929 if (bo->isScrolled()) bo->toggleScroll();
2934 void MapEditor::loadFloatImage ()
2937 (typeid(*selection) == typeid(BranchObj)) ||
2938 (typeid(*selection) == typeid(MapCenterObj)) )
2940 BranchObj *bo=((BranchObj*)selection);
2942 Q3FileDialog *fd=new Q3FileDialog( this);
2943 fd->setMode (Q3FileDialog::ExistingFiles);
2944 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2945 ImagePreview *p =new ImagePreview (fd);
2946 fd->setContentsPreviewEnabled( TRUE );
2947 fd->setContentsPreview( p, p );
2948 fd->setPreviewMode( Q3FileDialog::Contents );
2949 fd->setCaption(__VYM " - " +tr("Load image"));
2950 fd->setDir (lastImageDir);
2954 if ( fd->exec() == QDialog::Accepted )
2956 saveStateChangingPart(selection, QString("Add floatimage to %1").arg(getName(selection)));
2957 // FIXME in QT4 use: lastImageDir=fd->directory();
2958 lastImageDir=QDir (fd->dirPath());
2959 QStringList flist = fd->selectedFiles();
2960 QStringList::Iterator it = flist.begin();
2961 while( it != flist.end() )
2964 bo->addFloatImage();
2965 // TODO check if load was successful
2966 bo->getLastFloatImage()->load(*it);
2967 bo->getLastFloatImage()->setOriginalFilename(fn);
2971 mapCenter->reposition();
2980 void MapEditor::saveFloatImage ()
2983 (typeid(*selection) == typeid(FloatImageObj)) )
2985 FloatImageObj *fio=((FloatImageObj*)selection);
2986 QFileDialog *fd=new QFileDialog( this);
2987 fd->setFilters (imageIO.getFilters());
2988 fd->setCaption(__VYM " - " +tr("Save image"));
2989 fd->setFileMode( QFileDialog::AnyFile );
2990 fd->setDirectory (lastImageDir);
2991 // fd->setSelection (fio->getOriginalFilename());
2995 if ( fd->exec() == QDialog::Accepted )
2997 if (QFile (fd->selectedFile()).exists() )
2999 QMessageBox mb( __VYM,
3000 tr("The file %1 exists already.\n"
3001 "Do you want to overwrite it?").arg(fd->selectedFile()),
3002 QMessageBox::Warning,
3003 QMessageBox::Yes | QMessageBox::Default,
3004 QMessageBox::Cancel | QMessageBox::Escape,
3005 QMessageBox::QMessageBox::NoButton );
3007 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
3008 mb.setButtonText( QMessageBox::No, tr("Cancel"));
3011 case QMessageBox::Yes:
3014 case QMessageBox::Cancel:
3021 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
3027 void MapEditor::setFrame(const FrameType &t)
3030 (typeid(*selection) == typeid(BranchObj)) ||
3031 (typeid(*selection) == typeid(MapCenterObj)) )
3033 selection->setFrameType (t);
3034 mapCenter->reposition();
3035 selection->updateLink();
3039 void MapEditor::setIncludeImagesVer(bool b)
3042 (typeid(*selection) == typeid(BranchObj)) ||
3043 (typeid(*selection) == typeid(MapCenterObj)) )
3044 ((BranchObj*)selection)->setIncludeImagesVer(b);
3045 mapCenter->reposition();
3048 void MapEditor::setIncludeImagesHor(bool b)
3051 (typeid(*selection) == typeid(BranchObj)) ||
3052 (typeid(*selection) == typeid(MapCenterObj)) )
3053 ((BranchObj*)selection)->setIncludeImagesHor(b);
3054 mapCenter->reposition();
3057 void MapEditor::setHideLinkUnselected (bool b)
3060 (typeid(*selection) == typeid(BranchObj)) ||
3061 (typeid(*selection) == typeid(MapCenterObj)) ||
3062 (typeid(*selection) == typeid(FloatImageObj)) )
3063 selection->setHideLinkUnselected(b);
3066 void MapEditor::importDirInt(BranchObj *dst, QDir d)
3069 (typeid(*selection) == typeid(BranchObj)) ||
3070 (typeid(*selection) == typeid(MapCenterObj)) )
3074 // Traverse directories
3075 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3076 QFileInfoList list = d.entryInfoList();
3079 for (int i = 0; i < list.size(); ++i)
3082 if (fi.fileName() != "." && fi.fileName() != ".." )
3085 bo=dst->getLastBranch();
3086 bo->setHeading (fi.fileName() );
3087 bo->setColor (QColor("blue"));
3089 if ( !d.cd(fi.fileName()) )
3090 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3093 // Recursively add subdirs
3094 importDirInt (bo,d);
3100 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3101 list = d.entryInfoList();
3103 for (int i = 0; i < list.size(); ++i)
3107 bo=dst->getLastBranch();
3108 bo->setHeading (fi.fileName() );
3109 bo->setColor (QColor("black"));
3110 if (fi.fileName().right(4) == ".vym" )
3111 bo->setVymLink (fi.filePath());
3116 void MapEditor::importDir()
3119 (typeid(*selection) == typeid(BranchObj)) ||
3120 (typeid(*selection) == typeid(MapCenterObj)) )
3122 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
3123 fd->setMode (Q3FileDialog::DirectoryOnly);
3124 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3125 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
3129 if ( fd->exec() == QDialog::Accepted )
3131 BranchObj *bo=((BranchObj*)selection);
3132 importDirInt (bo,QDir(fd->selectedFile()) );
3133 mapCenter->reposition();
3140 void MapEditor::followXLink(int i)
3143 (typeid(*selection) == typeid(BranchObj)) ||
3144 (typeid(*selection) == typeid(MapCenterObj)) )
3146 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3149 selection->unselect();
3151 selection->select();
3152 ensureSelectionVisible();
3157 void MapEditor::editXLink(int i)
3160 (typeid(*selection) == typeid(BranchObj)) ||
3161 (typeid(*selection) == typeid(MapCenterObj)) )
3163 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3166 EditXLinkDialog dia;
3168 dia.setSelection(selection);
3169 if (dia.exec() == QDialog::Accepted)
3171 if (dia.useSettingsGlobal() )
3173 setDefXLinkColor (xlo->getColor() );
3174 setDefXLinkWidth (xlo->getWidth() );
3176 if (dia.deleteXLink())
3177 ((BranchObj*)selection)->deleteXLinkAt(i);
3178 saveStateComplete("Edit xLink"); //TODO undoCommand
3184 void MapEditor::testFunction()
3186 cout << "MapEditor::testFunction() called\n";
3189 (typeid(*selection) == typeid(BranchObj)) ||
3190 (typeid(*selection) == typeid(MapCenterObj)) )
3192 BranchObj* bo=(BranchObj*)selection;
3193 cout << bo->getHeading().ascii() <<" is scrolled: "<<bo->isScrolled()<<endl;
3198 dia.showCancelButton (true);
3199 dia.setText("This is a longer \nWarning");
3201 dia.setCaption("Warning: Flux problem");
3202 dia.setShowAgainName("/warnings/mapeditor");
3204 if (dia.exec()==QDialog::Accepted)
3205 cout << "accepted!\n";
3207 cout << "canceled!\n";
3210 /* Hide hidden stuff temporary, maybe add this as regular function somewhere
3211 if (hidemode==HideNone)
3213 setHideTmpMode (HideExport);
3214 mapCenter->calcBBoxSizeWithChilds();
3215 QRect totalBBox=mapCenter->getTotalBBox();
3216 QRect mapRect=totalBBox;
3217 QCanvasRectangle *frame=NULL;
3219 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3221 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3222 totalBBox.width(), totalBBox.height());
3223 frame=new QCanvasRectangle (mapRect,mapCanvas);
3224 frame->setBrush (QColor(white));
3225 frame->setPen (QColor(black));
3231 setHideTmpMode (HideNone);
3233 cout <<" hidemode="<<hidemode<<endl;
3237 void MapEditor::ensureSelectionVisible()
3241 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3243 if (selection->getOrientation() == OrientLeftOfCenter)
3244 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3246 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3247 ensureVisible (p.x(), p.y() );
3252 void MapEditor::updateViewCenter()
3254 // Update movingCenter, so that we can zoom comfortably later
3255 QRect rc = QRect( contentsX(), contentsY(),
3256 visibleWidth(), visibleHeight() );
3257 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3258 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3259 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3262 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3264 // Lineedits are already closed by preceding
3265 // mouseEvent, we don't need to close here.
3267 QPoint p = inverseWorldMatrix().map(e->pos());
3268 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3271 { // MapObj was found
3272 if (selection != lmo)
3274 // select the MapObj
3275 if (selection) selection->unselect();
3277 selection->select();
3283 if (typeid(*selection)==typeid(BranchObj) ||
3284 typeid(*selection)==typeid(MapCenterObj) )
3286 // Context Menu on branch or mapcenter
3288 branchContextMenu->popup(e->globalPos() );
3290 if (typeid(*selection)==typeid(FloatImageObj))
3292 // Context Menu on floatimage
3294 floatimageContextMenu->popup(e->globalPos() );
3298 { // No MapObj found, we are on the Canvas itself
3299 // Context Menu on Canvas
3301 canvasContextMenu->popup(e->globalPos() );
3306 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3308 // Ignore right clicks, these will go to context menus
3309 if (e->button() == Qt::RightButton )
3315 QPoint p = inverseWorldMatrix().map(e->pos());
3316 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3320 //Take care of clickdesystem flags _or_ modifier modes
3322 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3323 typeid(*lmo)==typeid(MapCenterObj) ))
3325 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3326 if (!foname.isEmpty())
3328 // systemFlag clicked
3332 if (e->state() & Qt::ControlModifier)
3333 mainWindow->editOpenURLTab();
3335 mainWindow->editOpenURL();
3337 else if (foname=="vymLink")
3339 mainWindow->editOpenVymLink();
3340 // tabWidget may change, better return now
3341 // before segfaulting...
3342 } else if (foname=="note")
3343 mainWindow->windowToggleNoteEditor();
3344 else if (foname=="hideInExport")
3349 // No system flag clicked, take care of modmodes
3351 // Special case: CTRL is pressed
3352 if (e->state() & Qt::ControlModifier)
3354 if (mainWindow->getModMode()==ModModeColor)
3357 setCursor (pickColorCursor);
3360 if (mainWindow->getModMode()==ModModeXLink)
3362 BranchObj *bo_begin=NULL;
3364 bo_begin=(BranchObj*)(lmo);
3367 ((typeid(*selection) == typeid(BranchObj)) ||
3368 (typeid(*selection) == typeid(MapCenterObj))) )
3369 bo_begin=(BranchObj*)selection;
3373 linkingObj_src=bo_begin;
3374 tmpXLink=new XLinkObj (mapCanvas);
3375 tmpXLink->setBegin (bo_begin);
3376 tmpXLink->setEnd (p);
3377 tmpXLink->setColor(defXLinkColor);
3378 tmpXLink->setWidth(defXLinkWidth);
3379 tmpXLink->updateXLink();
3380 tmpXLink->setVisibility (true);
3388 // Left Button Move Branches
3389 if (e->button() == Qt::LeftButton )
3391 movingObj_start.setX( p.x() - selection->x() );
3392 movingObj_start.setY( p.y() - selection->y() );
3393 movingObj_orgPos.setX (lmo->x() );
3394 movingObj_orgPos.setY (lmo->y() );
3395 movingObj_orgRelPos=lmo->getRelPos();
3397 // If modMode==copy, then we want to "move" the _new_ object around
3398 // then we need the offset from p to the _old_ selection, because of tmp
3399 if (mainWindow->getModMode()==ModModeCopy &&
3400 e->state() & Qt::ControlModifier)
3402 if (typeid(*selection)==typeid(BranchObj) )
3405 mapCenter->addBranch ((BranchObj*)selection);
3407 selection=mapCenter->getLastBranch();
3408 selection->select();
3409 mapCenter->reposition();
3412 movingObj=selection;
3414 // Middle Button Toggle Scroll
3415 // (On Mac OS X this won't work, but we still have
3416 // a button in the toolbar)
3417 if (e->button() == Qt::MidButton )
3421 { // No MapObj found, we are on the Canvas itself
3422 // Left Button move Pos of CanvasView
3423 if (e->button() == Qt::LeftButton )
3425 movingObj=NULL; // move Content not Obj
3426 movingObj_start=e->globalPos();
3427 movingCont_start=QPoint (contentsX(), contentsY() );
3428 movingVec=QPoint(0,0);
3429 setCursor(handOpenCursor);
3434 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3436 QPoint p = inverseWorldMatrix().map(e->pos());
3438 // Move the selected MapObj
3439 if ( selection && movingObj)
3441 // To avoid jumping of the CanvasView, only
3442 // ensureSelectionVisible, if not tmp linked
3443 if (!selection->hasParObjTmp())
3444 ensureSelectionVisible ();
3446 // Now move the selection, but add relative position
3447 // (movingObj_start) where selection was chosen with
3448 // mousepointer. (This avoids flickering resp. jumping
3449 // of selection back to absPos)
3451 LinkableMapObj *lmosel;
3452 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3454 // Check if we could link
3455 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3458 if (typeid(*selection) == typeid(FloatImageObj))
3460 FloatObj *fo=(FloatObj*)selection;
3461 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3465 // Relink float to new mapcenter or branch, if shift is pressed
3466 // Only relink, if selection really has a new parent
3467 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
3468 ( (typeid(*lmo)==typeid(BranchObj)) ||
3469 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3470 ( lmo != fo->getParObj())
3473 if (typeid(*fo) == typeid(FloatImageObj))
3476 saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3477 FloatImageObj *fio=(FloatImageObj*)(fo);
3478 ((BranchObj*)(lmo))->addFloatImage (fio);
3480 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3481 fio=((BranchObj*)(lmo))->getLastFloatImage();
3484 selection=(LinkableMapObj*)(fio);
3485 selection->select();
3486 movingObj=(MapObj*)(fio);
3490 { // selection != a FloatObj
3491 if (lmosel->getDepth()==0)
3494 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3495 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3497 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3498 mapCenter->updateRelPositions();
3501 if (lmosel->getDepth()==1)
3504 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3505 lmosel->setRelPos();
3508 // Move ordinary branch
3509 if (lmosel->getOrientation() == OrientLeftOfCenter)
3510 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3511 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3512 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3514 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3516 // reposition subbranch
3517 lmosel->reposition();
3519 if (lmo && (lmo!=selection) &&
3520 (typeid(*lmo) == typeid(BranchObj) ||
3521 (typeid(*lmo) == typeid(MapCenterObj) )
3524 if (e->modifiers()==Qt::ControlModifier)
3526 // Special case: CTRL to link below lmo
3527 lmosel->setParObjTmp (lmo,p,+1);
3529 else if (e->modifiers()==Qt::ShiftModifier)
3530 lmosel->setParObjTmp (lmo,p,-1);
3532 lmosel->setParObjTmp (lmo,p,0);
3535 lmosel->unsetParObjTmp();
3539 } // no FloatImageObj
3543 } // selection && moving_obj
3545 // Draw a link from one branch to another
3548 tmpXLink->setEnd (p);
3549 tmpXLink->updateXLink();
3553 if (!movingObj && !pickingColor &&!drawingLink)
3555 QPoint p=e->globalPos();
3556 movingVec.setX(-p.x() + movingObj_start.x() );
3557 movingVec.setY(-p.y() + movingObj_start.y() );
3558 setContentsPos( movingCont_start.x() + movingVec.x(),
3559 movingCont_start.y() + movingVec.y());
3566 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3568 LinkableMapObj *dst;
3569 // Have we been picking color?
3573 setCursor (Qt::ArrowCursor);
3574 // Check if we are over another branch
3575 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3576 if (dst && selection)
3578 if (e->state() & Qt::ShiftModifier)
3580 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3581 ((BranchObj*)selection)->setLinkColor ();
3585 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3586 ((BranchObj*)selection)->setLinkColor ();
3592 // Have we been drawing a link?
3596 // Check if we are over another branch
3597 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3598 if (dst && selection)
3600 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3601 tmpXLink->updateXLink();
3602 tmpXLink->activate();
3603 saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3612 // Have we been moving something?
3613 if ( selection && movingObj )
3615 if(typeid(*selection)==typeid (FloatImageObj))
3617 // Moved FloatObj. Maybe we need to reposition
3618 FloatImageObj *fo=(FloatImageObj*)selection;
3619 QString pold=qpointToString(movingObj_orgRelPos);
3620 QString pnow=qpointToString(fo->getRelPos());
3621 saveStateConstSelection(
3624 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow));
3626 // FIXME Why calling parObj here?
3627 selection->getParObj()->requestReposition();
3628 mapCenter->reposition();
3631 // Check if we are over another branch, but ignore
3632 // any found LMOs, which are FloatObjs
3633 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3634 ((LinkableMapObj*)selection) );
3636 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3639 if (typeid(*selection) == typeid(MapCenterObj) )
3640 { // The MapCenter was moved
3641 cout << "FIXME missing savestate...\n";
3644 if (typeid(*selection) == typeid(BranchObj) )
3645 { // A branch was moved
3647 // save the position in case we link to mapcenter
3648 QPoint savePos=QPoint (selection->x(),selection->y() );
3650 // Reset the temporary drawn link to the original one
3651 ((LinkableMapObj*)selection)->unsetParObjTmp();
3653 // For Redo we may need to save original selection
3654 QString preSelStr=selection->getSelectString();
3659 BranchObj* bsel=(BranchObj*)selection;
3660 BranchObj* bdst=(BranchObj*)dst;
3662 QString preParStr=(bsel->getParObj())->getSelectString();
3663 QString preNum=QString::number (bsel->getNum(),10);
3664 QString preDstParStr;
3666 if (e->state() & Qt::ShiftModifier && dst->getParObj())
3668 preDstParStr=dst->getParObj()->getSelectString();
3669 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
3671 if (e->state() & Qt::ControlModifier && dst->getParObj())
3674 preDstParStr=dst->getParObj()->getSelectString();
3675 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
3678 preDstParStr=dst->getSelectString();
3679 bsel->moveBranchTo (bdst,-1);
3680 if (dst->getDepth()==0) bsel->move (savePos);
3682 QString postSelStr=selection->getSelectString();
3683 QString postNum=QString::number (bsel->getNum(),10);
3685 QString undoCom="linkBranchToPos (\""+
3686 preParStr+ "\"," + preNum +"," +
3687 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
3689 QString redoCom="linkBranchToPos (\""+
3690 preDstParStr + "\"," + postNum + "," +
3691 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
3696 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
3698 if (selection->getDepth()==1)
3700 // The select string might be different _after_ moving around.
3701 // Therefor reposition and then use string of old selection, too
3702 mapCenter->reposition();
3704 QString ps=qpointToString ( ((BranchObj*)selection)->getRelPos() );
3706 selection->getSelectString(), "moveRel "+qpointToString(movingObj_orgRelPos),
3707 preSelStr, "moveRel "+ps,
3708 QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps));
3711 // Draw the original link, before selection was moved around
3712 mapCenter->reposition();
3714 // Finally resize canvas, if needed
3719 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
3722 // maybe we moved View: set old cursor
3723 setCursor (Qt::ArrowCursor);
3727 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3729 if (e->button() == Qt::LeftButton )
3731 QPoint p = inverseWorldMatrix().map(e->pos());
3732 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3733 if (lmo) { // MapObj was found
3734 // First select the MapObj than edit heading
3735 if (selection) selection->unselect();
3737 selection->select();
3738 mainWindow->editHeading();
3743 void MapEditor::resizeEvent (QResizeEvent* e)
3745 Q3CanvasView::resizeEvent( e );
3749 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3752 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3753 // cerr << event->format(i) << endl;
3756 (typeid(*selection) == typeid(BranchObj)) ||
3757 (typeid(*selection) == typeid(MapCenterObj))) {
3759 // If QImageDrag can decode mime type
3760 if (Q3ImageDrag::canDecode(event)) {
3765 // If image are dragged from firefox
3766 if (event->provides("application/x-moz-file-promise-url") &&
3767 event->provides("application/x-moz-nativeimage")) {
3768 event->accept(true);
3772 // If QUriDrag can decode mime type
3773 if (Q3UriDrag::canDecode(event)) {
3778 // If Uri are dragged from firefox
3779 if (event->provides("_NETSCAPE_URL")){
3784 // If QTextDrag can decode mime type
3785 if (Q3TextDrag::canDecode(event)) {
3794 bool isUnicode16(const QByteArray &d)
3796 // TODO: make more precise check for unicode 16.
3797 // Guess unicode16 if any of second bytes are zero
3798 unsigned int length = max(0,d.size()-2)/2;
3799 for (unsigned int i = 0; i<length ; i++)
3800 if (d.at(i*2+1)==0) return true;
3804 void MapEditor::contentsDropEvent(QDropEvent *event)
3807 (typeid(*selection) == typeid(BranchObj)) ||
3808 (typeid(*selection) == typeid(MapCenterObj)))
3813 if (event->provides("image/png"))
3816 if (Q3ImageDrag::decode(event, pix))
3824 } else if (event->provides("application/x-moz-file-promise-url") &&
3825 event->provides("application/x-moz-nativeimage"))
3827 // Contains url to the img src in unicode16
3828 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3829 QString url = QString((const QChar*)d.data(),d.size()/2);
3833 } else if (event->provides ("text/uri-list"))
3834 { // Uris provided e.g. by konqueror
3835 Q3UriDrag::decode (event,uris);
3836 } else if (event->provides ("_NETSCAPE_URL"))
3837 { // Uris provided by Mozilla
3838 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3841 } else if (event->provides("text/html")) {
3843 // Handels text mime types
3844 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3845 QByteArray d = event->encodedData("text/html");
3848 text = QString((const QChar*)d.data(),d.size()/2);
3852 textEditor->setText(text);
3856 } else if (event->provides("text/plain")) {
3857 QByteArray d = event->encodedData("text/plain");
3860 text = QString((const QChar*)d.data(),d.size()/2);
3864 textEditor->setText(text);
3876 for (const char* u=uris.first(); u; u=uris.next())
3878 bo=((BranchObj*)selection)->addBranch();
3881 s=Q3UriDrag::uriToLocalFile(u);
3884 QString file = QDir::convertSeparators(s);
3885 heading = QFileInfo(file).baseName();
3887 if (file.endsWith(".vym", false))
3888 bo->setVymLink(file);
3897 if (!heading.isEmpty())
3898 bo->setHeading(heading);
3908 //FIXME saveState has to be called earlier for each of the drops...
3909 saveStateComplete("Drop Event"); //TODO undo Command
3910 mapCenter->reposition();
3917 void MapEditor::addFloatImage(const QPixmap &img)
3920 (typeid(*selection) == typeid(BranchObj)) ||
3921 (typeid(*selection) == typeid(MapCenterObj)) )
3923 BranchObj *bo=((BranchObj*)selection);
3924 saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
3925 //QString fn=fd->selectedFile();
3926 //lastImageDir=fn.left(fn.findRev ("/"));
3927 bo->addFloatImage();
3928 // FIXME check if load was successful
3929 bo->getLastFloatImage()->load(img);
3930 //bo->getLastFloatImage()->setOriginalFilename(fn);
3931 mapCenter->reposition();
3938 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
3940 if (!imageBuffer) imageBuffer = new QBuffer();
3941 if (!imageBuffer->isOpen()) {
3942 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3944 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3948 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3950 if (nop->state()==Q3NetworkProtocol::StDone) {
3951 QPixmap img(imageBuffer->buffer());
3956 imageBuffer->close();
3958 imageBuffer->close();
3965 void MapEditor::fetchImage(const QString &url)
3968 urlOperator->stop();
3969 disconnect(urlOperator);
3973 urlOperator = new Q3UrlOperator(url);
3974 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
3975 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
3977 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
3978 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));