Fixed editing of headings. Undo debug output still enabled
3 #include <qstatusbar.h>
5 #include <qapplication.h>
7 #include <q3popupmenu.h>
9 #include <q3paintdevicemetrics.h>
11 #include <q3filedialog.h>
14 #include <QColorDialog>
16 #include <qinputdialog.h>
17 #include <q3dragobject.h>
18 #include <q3urloperator.h>
19 #include <q3networkprotocol.h>
22 #include <QResizeEvent>
23 #include <QContextMenuEvent>
26 #include <QMouseEvent>
27 #include <QDragEnterEvent>
28 #include <QTextStream>
30 #include <QActionGroup>
40 #include "editxlinkdialog.h"
42 #include "extrainfodialog.h"
44 #include "linkablemapobj.h"
45 #include "mainwindow.h"
47 #include "texteditor.h"
48 #include "warningdialog.h"
52 extern TextEditor *textEditor;
53 extern int statusbarTime;
54 extern Main *mainWindow;
55 extern QString tmpVymDir;
56 extern QString clipboardDir;
57 extern bool clipboardEmpty;
58 extern FlagRowObj *systemFlagsDefault;
59 extern FlagRowObj *standardFlagsDefault;
61 extern Q3PtrList <QAction> actionListBranches;
63 extern QAction *actionFileSave;
64 extern QAction *actionEditUndo;
65 extern QAction *actionEditRedo;
66 extern QAction *actionEditCopy;
67 extern QAction *actionEditCut;
68 extern QAction *actionEditPaste;
69 extern QAction *actionEditMoveUp;
70 extern QAction *actionEditMoveDown;
71 extern QAction *actionEditToggleScroll;
72 extern QAction *actionEditOpenURL;
73 extern QAction *actionEditOpenURLTab;
74 extern QAction *actionEditURL;
75 extern QAction *actionEditHeading2URL;
76 extern QAction *actionEditBugzilla2URL;
77 extern QAction *actionEditFATE2URL;
78 extern QAction *actionEditOpenVymLink;
79 extern QAction *actionEditVymLink;
80 extern QAction *actionEditDeleteVymLink;
81 extern QAction *actionEditToggleHideExport;
82 extern QAction *actionEditHeading;
83 extern QAction *actionEditDelete;
84 extern QAction *actionEditAddBranch;
85 extern QAction *actionEditAddBranchAbove;
86 extern QAction *actionEditAddBranchBelow;
87 extern QAction *actionEditRemoveBranchHere;
88 extern QAction *actionEditRemoveChilds;
89 extern QAction *actionEditImportAdd;
90 extern QAction *actionEditImportReplace;
91 extern QAction *actionEditSaveBranch;
92 extern QAction *actionEditSelectFirst;
93 extern QAction *actionEditSelectLast;
94 extern QAction *actionEditLoadImage;
96 extern QAction* actionFormatPickColor;
97 extern QAction* actionFormatColorBranch;
98 extern QAction* actionFormatColorSubtree;
99 extern QAction *actionFormatLinkColorHint;
100 extern QAction *actionFormatBackColor;
101 extern QAction *actionFormatLinkColor;
103 extern QActionGroup* actionGroupModModes;
104 extern QAction* actionModModeColor;
105 extern QAction* actionModModeLink;
106 extern QAction* actionModModeCopy;
108 extern QActionGroup *actionGroupFormatFrameTypes;
109 extern QAction *actionFormatFrameNone;
110 extern QAction *actionFormatFrameRectangle;
112 extern QActionGroup *actionGroupFormatLinkStyles;
113 extern QAction *actionFormatIncludeImagesVer;
114 extern QAction *actionFormatIncludeImagesHor;
115 extern QAction *actionFormatHideLinkUnselected;
116 extern QAction *actionFormatLinkStyleLine;
117 extern QAction *actionFormatLinkStyleParabel;
118 extern QAction *actionFormatLinkStylePolyLine;
119 extern QAction *actionFormatLinkStylePolyParabel;
121 extern QAction *actionViewToggleNoteEditor;
123 extern QAction *actionSettingsAutoedit;
124 extern QAction *actionSettingsAutoselectHeading;
125 extern QAction *actionSettingsAutoselectText;
126 extern QAction *actionSettingsPasteNewHeading;
127 extern QAction *actionSettingsUseFlagGroups;
129 extern QMenu* branchContextMenu;
130 extern QMenu* branchAddContextMenu;
131 extern QMenu* branchRemoveContextMenu;
132 extern QMenu* branchLinksContextMenu;
133 extern QMenu* branchXLinksContextMenuEdit;
134 extern QMenu* branchXLinksContextMenuFollow;
135 extern QMenu* floatimageContextMenu;
136 extern QMenu* saveImageFormatMenu;
137 extern QMenu* canvasContextMenu;
138 extern QMenu* lastMapsMenu;
139 extern QMenu* importMenu;
140 extern QMenu* exportMenu;
143 extern Settings settings;
144 extern ImageIO imageIO;
146 extern QString iconPath;
147 extern QDir vymBaseDir;
148 extern QDir lastImageDir;
150 int MapEditor::mapNum=0; // make instance
152 ///////////////////////////////////////////////////////////////////////
153 ///////////////////////////////////////////////////////////////////////
154 MapEditor::MapEditor(
155 QWidget* parent, bool interactive, const char* name, Qt::WFlags f) :
156 Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
158 //cout << "Constructor ME "<<this<<endl;
161 viewport()->setAcceptDrops(true);
163 mapCanvas = new Q3Canvas(width(),height());
164 mapCanvas->setAdvancePeriod(30);
165 mapCanvas->setBackgroundColor (Qt::white);
167 setCanvas (mapCanvas);
169 // Always show scroll bars (automatic would flicker sometimes)
170 setVScrollBarMode ( Q3ScrollView::AlwaysOn );
171 setHScrollBarMode ( Q3ScrollView::AlwaysOn );
173 mapCenter = new MapCenterObj(mapCanvas);
174 mapCenter->setVisibility (true);
175 mapCenter->setMapEditor (this);
176 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
177 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
181 actColor=Qt::black; setColor (actColor);
182 defLinkColor=QColor (0,0,255);
183 defXLinkColor=QColor (180,180,180);
184 linkcolorhint=DefaultColor;
185 linkstyle=StylePolyParabel;
187 // Create bitmap cursors, patform dependant
188 #if defined(Q_OS_MACX)
189 handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png") );
190 // set hot spot to tip of picker
191 pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 );
193 handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen16.png"));
194 // set hot spot to tip of picker
195 pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
207 xelection.setMapCenter (mapCenter);
210 defXLinkColor=QColor (230,230,230);
218 fileName=tr("unnamed");
221 undosTotal=settings.readNumEntry("/mapeditor/undoLevels",50);
223 // Initialize find routine
230 blockReposition=false;
231 blockSaveState=false;
235 isInteractive=interactive;
237 // Create temporary files
240 // Initially set movingCentre
243 // For testing purposes create history window
244 historyWindow = new ShowTextDialog (this);
245 historyWindow->setCaption (fileName);
247 mapCenter->reposition(); // for positioning heading
252 MapEditor::~MapEditor()
254 if (imageBuffer) delete imageBuffer;
260 //cout <<"Destructor MapEditor\n";
263 //settings.writeEntry( "/mapeditor/editmode/autoselect", );
267 QColor MapEditor::color()
272 QColor MapEditor::backgroundColor()
274 return mapCanvas->backgroundColor();
277 MapCenterObj* MapEditor::getMapCenter()
282 Q3Canvas* MapEditor::getCanvas()
287 void MapEditor::adjustCanvasSize()
289 // To adjust the canvas to map, viewport size and position, we have to
290 // do some coordinate magic...
292 // Get rectangle of (scroll-)view.
293 // We want to be in canvas coords, so
294 // we map. Important if view is zoomed...
295 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
296 visibleWidth(), visibleHeight()) );
298 // Now we need the bounding box of view AND map to calc the correct canvas size.
299 // Why? Because if the map itself is moved out of view, the view has to be enlarged
300 // to avoid jumping aroung...
301 QRect map=mapCenter->getTotalBBox();
303 // right edge - left edge
304 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
305 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
308 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
309 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
312 // move the map on canvas (in order to not move it on screen) this is neccessary
313 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
314 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
315 // to scroll to an empty area of canvas to the left.
316 // b) if topleft corner of map left of or above topleft of canvas
320 if (cw > mapCanvas->width() )
322 if (map.x()<0) dx=-map.x();
324 if (cw < mapCanvas->width() )
325 dx=-min (view.x(),map.x());
326 if (ch > mapCanvas->height() )
328 if (map.y()<0) dy=-map.y();
330 if (ch < mapCanvas->height() )
332 dy=-min (view.y(),map.y());
334 // We really have to resize now. Let's go...
335 mapCanvas->resize (cw,ch);
336 if ( (dx!=0) || (dy!=0) )
338 mapCenter->moveAllBy(dx,dy);
339 mapCenter->reposition();
340 // mapCenter->positionBBox(); // To move float
342 // scroll the view (in order to not move map on screen)
348 bool MapEditor::isRepositionBlocked()
350 return blockReposition;
353 QString MapEditor::getName (LinkableMapObj *lmo)
356 if (!lmo) return QString("Error: NULL has no name!");
358 if ((typeid(*lmo) == typeid(BranchObj) ||
359 typeid(*lmo) == typeid(MapCenterObj)))
362 s=(((BranchObj*)lmo)->getHeading());
363 if (s=="") s="unnamed";
364 return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
366 if ((typeid(*lmo) == typeid(FloatImageObj) ))
367 return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
368 return QString("Unknown type has no name!");
371 void MapEditor::makeTmpDirs()
373 // Create unique temporary directories
374 tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
375 histPath=QDir::convertSeparators (tmpMapDir+"/history");
377 d.mkdir (tmpMapDir,true);
380 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSel)
382 // tmpdir temporary directory to which data will be written
383 // prefix mapname, which will be appended to images etc.
384 // writeflags Only write flags for "real" save of map, not undo
385 // offset offset of bbox of whole map in canvas.
386 // Needed for XML export
402 ls="StylePolyParabel";
406 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
408 if (linkcolorhint==HeadingColor)
409 colhint=attribut("linkColorHint","HeadingColor");
411 QString mapAttr=attribut("version",__VYM_VERSION);
413 mapAttr+= attribut("author",mapCenter->getAuthor()) +
414 attribut("comment",mapCenter->getComment()) +
415 attribut("date",mapCenter->getDate()) +
416 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
417 attribut("linkStyle", ls ) +
418 attribut("linkColor", defLinkColor.name() ) +
419 attribut("defXLinkColor", defXLinkColor.name() ) +
420 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
422 s+=beginElement("vymmap",mapAttr);
425 // Find the used flags while traversing the tree
426 standardFlagsDefault->resetUsedCounter();
428 // Reset the counters before saving
429 FloatImageObj (mapCanvas).resetSaveCounter();
431 // Build xml recursivly
433 // Save complete map, if saveSel not set
434 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
437 if ( typeid(*saveSel) == typeid(BranchObj) )
439 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
440 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
442 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
444 else if (selection && typeid(*selection)==typeid(BranchObj))
445 // Save selected branch is saved from mainwindow //FIXME maybe use "subtree" above?
446 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
449 // Save local settings
450 s+=settings.getXMLData (destPath);
453 if (selection && !saveSel )
454 s+=valueElement("select",selection->getSelectString());
457 s+=endElement("vymmap");
460 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
464 void MapEditor::saveStateComplete(const QString &comment)
466 // Save complete map, Undo will replace whole map
467 saveState (CompleteMap,
474 void MapEditor::saveStatePart(LinkableMapObj *undoSel, const QString &comment)
476 // save the selected part of the map, Undo will replace part of map
477 saveState (PartOfMap,
484 void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment)
486 // selection does not change during action,
487 // so just save commands for undo and redo
488 // and use current selection
489 saveState (UndoCommand,
496 void MapEditor::saveStateX(LinkableMapObj *unsel, const QString &uc, const QString &comment)
498 // TODO Is this still needed?
499 saveState (UndoCommand,
501 NULL, "FIXME-redoCom", //FIXME
506 void MapEditor::saveStateComData(LinkableMapObj *unSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel)
508 saveState (UndoCommand,
510 NULL, "FIXME-redoCom", //FIXME
515 void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom, LinkableMapObj *redoSel, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
519 if (blockSaveState) return;
521 /* TODO remove after testing
523 cout << "ME::saveState() begin"<<endl;
524 historyWindow->append (comment);
528 int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
529 int curStep=undoSet.readNumEntry ("/history/curStep",0);
530 // Find out current undo directory
531 if (undosAvail<undosTotal) undosAvail++;
533 if (curStep>undosTotal) curStep=1;
536 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
537 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
539 // Create bakMapDir if not available
542 makeSubDirs (bakMapDir);
544 // Save current selection
545 QString redoSelection="";
547 redoSelection=redoSel->getSelectString();
549 // Save the object, which should be undone
550 QString undoSelection="";
552 undoSelection=undoSel->getSelectString();
554 // Save depending on how much needs to be saved
558 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel);
560 QString undoCommand="";
561 if (savemode==UndoCommand)
565 else if (savemode==PartOfMap && undoSel)
567 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
570 undoCommand="undoMap (\""+bakMapPath+"\")";
572 if (!backupXML.isEmpty())
573 // Write XML Data to disk
574 saveStringToDisk (QString(bakMapPath),backupXML);
576 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
577 undoSet.setEntry ("/history/curStep",QString::number(curStep));
578 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
579 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
580 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
581 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
582 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
583 undoSet.writeSettings(histPath);
585 /* TODO remove after testing
587 //cout << " into="<< histPath.toStdString()<<endl;
588 cout << " undosTotal="<<undosTotal<<
589 ", undosAvail="<<undosAvail<<
590 ", curStep="<<curStep<<endl;
591 cout << " ---------------------------"<<endl;
592 cout << " comment="<<comment.toStdString()<<endl;
593 cout << " undoCom="<<undoCommand.toStdString()<<endl;
594 cout << " undoSel="<<undoSelection.toStdString()<<endl;
595 cout << " redoCom="<<redoCom.toStdString()<<endl;
596 cout << " redoSel="<<redoSelection.toStdString()<<endl;
597 cout << " ---------------------------"<<endl;
600 void MapEditor::parseAtom(const QString &atom)
607 // Split string s into command and parameters
608 api.parseCommand (atom);
609 QString com=api.command();
612 if (com=="moveBranchUp")
614 else if (com=="moveBranchDown")
616 else if (com=="move")
618 if (api.checkParamCount(2) && selection )
628 else if (com=="delete")
630 if (api.checkParamCount(1) && selection )
632 s=api.parString(ok,0);
635 if (select (s)) deleteSelection();
639 else if (com=="linkBranchToPos")
641 if (selection && typeid(*selection) == typeid(BranchObj) )
643 if (api.checkParamCount(4))
645 s=api.parString(ok,0);
646 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
649 if (typeid(*dst) == typeid(BranchObj) )
651 // Get number in parent
654 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
655 } else if (typeid(*dst) == typeid(MapCenterObj) )
657 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
658 // Get coordinates of mainbranch
663 if (ok) ((BranchObj*)selection)->move (x,y);
669 } else if (com=="setHeading")
671 if (api.checkParamCount(1))
673 s=api.parString (ok,0);
677 } else if (com=="setURL")
679 if (api.checkParamCount(1))
681 s=api.parString (ok,0);
682 if (ok) setURLInt(s);
684 } else if (com=="setVymLink")
686 if (api.checkParamCount(1))
688 s=api.parString (ok,0);
689 if (ok) setVymLinkInt(s);
692 else if (com=="setFlag")
694 if (selection && typeid(*selection) == typeid(BranchObj) )
696 if (api.checkParamCount(1) )
698 s=api.parString(ok,0);
699 if (ok) ((BranchObj*)selection)->activateStandardFlag(s);
703 else if (com=="unsetFlag")
705 if (selection && typeid(*selection) == typeid(BranchObj) )
707 if (api.checkParamCount(1) )
709 s=api.parString(ok,0);
710 if (ok) ((BranchObj*)selection)->deactivateStandardFlag(s);
714 // Internal commands, used for undo etc.
715 else if (com==QString("undoMap"))
717 if (api.checkParamCount(1))
718 undoXML("",api.parString (ok,0));
719 } else if (com==QString("undoPart"))
721 if (api.checkParamCount(2))
723 s=api.parString (ok,0); // undo selection
724 t=api.parString (ok,1); // backup dir
727 } else if (com=="select")
728 if (api.checkParamCount(1))
730 s=api.parString(ok,0);
735 api.setError ("Unknown command in: "+atom);
736 cout << "ME::parse api should have error now...\n";
742 // TODO Error handling
743 qWarning("MapEditor::parseAtom: Error!");
744 qWarning(api.errorDesc());
748 void MapEditor::toggleHistoryWindow()
750 if (historyWindow->isVisible())
751 historyWindow->hide();
753 historyWindow->show();
757 bool MapEditor::isDefault()
762 bool MapEditor::isUnsaved()
767 bool MapEditor::hasChanged()
772 void MapEditor::setChanged()
777 actionEditUndo->setEnabled (true);
778 actionFileSave->setEnabled (true);
782 void MapEditor::closeMap()
784 // Unselect before disabling the toolbar actions
785 if (selection) selection->unselect();
793 void MapEditor::setFilePath(QString fname)
795 setFilePath (fname,fname);
798 void MapEditor::setFilePath(QString fname, QString destname)
800 if (fname.isEmpty() || fname=="")
807 filePath=fname; // becomes absolute path
808 fileName=fname; // gets stripped of path
809 destPath=destname; // needed for vymlinks
811 // If fname is not an absolute path, complete it
812 filePath=QDir(fname).absPath();
813 fileDir=filePath.left (1+filePath.findRev ("/"));
815 // Set short name, too. Search from behind:
816 int i=fileName.findRev("/");
817 if (i>=0) fileName=fileName.remove (0,i+1);
819 // Forget the .vym (or .xml) for name of map
820 mapName=fileName.left(fileName.findRev(".",-1,true) );
822 // Adjust history window
823 historyWindow->setCaption (fileName);
827 QString MapEditor::getFilePath()
832 QString MapEditor::getFileName()
837 QString MapEditor::getMapName()
842 QString MapEditor::getDestPath()
847 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
849 ErrorCode err=success;
853 if (selection) selection->unselect();
856 mapCenter->setMapEditor(this);
857 // (map state is set later at end of load...)
860 saveStatePart(selection,"Load map");
864 mapBuilderHandler handler;
867 // I am paranoid: file should exist anyway
868 // according to check in mainwindow.
871 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
872 tr("Couldn't open map " +fname)+".");
876 blockReposition=true;
877 QXmlInputSource source( file);
878 QXmlSimpleReader reader;
879 reader.setContentHandler( &handler );
880 reader.setErrorHandler( &handler );
881 handler.setMapEditor( this );
882 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
883 handler.setInputFile (file.name());
884 handler.setLoadMode (lmode);
886 bool ok = reader.parse( source );
887 blockReposition=false;
888 blockSaveState=false;
892 mapCenter->reposition();
902 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
903 tr( handler.errorProtocol() ) );
905 // Still return "success": the map maybe at least
906 // partially read by the parser
913 int MapEditor::save (const SaveMode &savemode)
917 // The SaveMode UndoCommand is not supported here
918 if (savemode==UndoCommand) return 1;
920 // Create mapName and fileDir
921 makeSubDirs (fileDir);
925 fname=mapName+".xml";
927 // use name given by user, even if he chooses .doc
932 if (savemode==CompleteMap || selection==NULL)
933 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
935 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
937 if (!saveStringToDisk(fileDir+fname,saveFile))
944 actionFileSave->setEnabled(false);
950 void MapEditor::setZipped (bool z)
955 bool MapEditor::saveZipped ()
960 void MapEditor::print()
964 printer = new QPrinter;
965 printer->setColorMode (QPrinter::Color);
966 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
969 QRect totalBBox=mapCenter->getTotalBBox();
971 // Try to set orientation automagically
972 // Note: Interpretation of generated postscript is amibiguous, if
973 // there are problems with landscape mode, see
974 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
976 if (totalBBox.width()>totalBBox.height())
977 // recommend landscape
978 printer->setOrientation (QPrinter::Landscape);
980 // recommend portrait
981 printer->setOrientation (QPrinter::Portrait);
983 if ( printer->setup(this) )
984 // returns false, if printing is canceled
986 QPainter pp(printer);
988 // Don't print the visualisation of selection
989 LinkableMapObj *oldselection=NULL;
992 oldselection=selection;
993 selection->unselect();
996 // Handle sizes of map and paper:
998 // setWindow defines which part of the canvas will be transformed
999 // setViewport defines area on paper in device coordinates (dpi)
1000 // e.g. (0,50,700,700) is upper part on A4
1001 // see also /usr/lib/qt3/doc/html/coordsys.html
1003 Q3PaintDeviceMetrics metrics (printer);
1005 double paperAspect = (double)metrics.width() / (double)metrics.height();
1006 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
1008 QRect mapRect=totalBBox;
1009 Q3CanvasRectangle *frame=NULL;
1010 Q3CanvasText *footerFN=NULL;
1011 Q3CanvasText *footerDate=NULL;
1012 if (printFrame || printFooter)
1017 // Print frame around map
1018 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
1019 totalBBox.width()+20, totalBBox.height()+20);
1020 frame=new Q3CanvasRectangle (mapRect,mapCanvas);
1021 frame->setBrush (QColor(Qt::white));
1022 frame->setPen (QColor(Qt::black));
1026 /* TODO remove after testing
1027 QCanvasLine *l=new QCanvasLine (mapCanvas);
1028 l->setPoints (0,0,mapRect.width(),mapRect.height());
1029 l->setPen (QPen(QColor(black), 1));
1036 // Print footer below map
1038 font.setPointSize(10);
1039 footerFN=new Q3CanvasText (mapCanvas);
1040 footerFN->setText ("VYM - " + fileName);
1041 footerFN->setFont(font);
1042 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1043 footerFN->setZ(Z_TEXT);
1045 footerDate=new Q3CanvasText (mapCanvas);
1046 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1047 footerDate->setFont(font);
1048 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1049 footerDate->setZ(Z_TEXT);
1052 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1055 pp.setWindow (mapRect);
1058 if (mapAspect>=paperAspect)
1060 // Fit horizontally to paper width
1061 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1064 // Fit vertically to paper height
1065 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1068 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1070 // Delete Frame and footer
1074 delete (footerDate);
1076 if (frame) delete (frame);
1078 // Restore selection
1081 selection=oldselection;
1082 selection->select();
1085 // Save settings in vymrc
1086 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1090 QPixmap MapEditor::getPixmap()
1092 QRect mapRect=mapCenter->getTotalBBox();
1093 QPixmap pix (mapRect.size());
1096 // Don't print the visualisation of selection
1097 LinkableMapObj *oldselection=NULL;
1100 oldselection=selection;
1101 selection->unselect();
1104 pp.setWindow (mapRect);
1106 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1109 // Restore selection
1112 selection=oldselection;
1113 selection->select();
1119 void MapEditor::setHideTmpMode (HideTmpMode mode)
1122 mapCenter->setHideTmp (hidemode);
1123 mapCenter->reposition();
1128 HideTmpMode MapEditor::getHideTmpMode()
1133 void MapEditor::exportImage(QString fn)
1135 setExportMode (true);
1136 QPixmap pix (getPixmap());
1137 pix.save(fn, "PNG");
1138 setExportMode (false);
1141 void MapEditor::setExportMode (bool b)
1143 // should be called before and after exports
1144 // depending on the settings
1145 if (b && settings.value("/export/useHideExport","yes")=="yes")
1146 setHideTmpMode (HideExport);
1148 setHideTmpMode (HideNone);
1151 void MapEditor::exportImage(QString fn, QString format)
1153 setExportMode (true);
1154 QPixmap pix (getPixmap());
1155 pix.save(fn, format);
1156 setExportMode (false);
1159 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1163 ex.setMapCenter(mapCenter);
1164 if (ex.setConfigFile(cf))
1166 setExportMode (true);
1167 ex.exportPresentation();
1168 setExportMode (false);
1174 void MapEditor::exportXML(const QString &dir)
1176 // Hide stuff during export, if settings want this
1177 setExportMode (true);
1179 // Create subdirectories
1182 // write to directory
1183 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1186 file.setName ( dir + "/"+mapName+".xml");
1187 if ( !file.open( QIODevice::WriteOnly ) )
1189 // This should neverever happen
1190 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1194 // Write it finally, and write in UTF8, no matter what
1195 QTextStream ts( &file );
1196 ts.setEncoding (QTextStream::UnicodeUTF8);
1200 // Now write image, too
1201 exportImage (dir+"/images/"+mapName+".png");
1203 setExportMode (false);
1206 void MapEditor::clear()
1210 selection->unselect();
1217 void MapEditor::copy()
1221 // write to directory
1222 QString clipfile="part";
1223 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1226 file.setName ( clipboardDir + "/"+clipfile+".xml");
1227 if ( !file.open( QIODevice::WriteOnly ) )
1229 // This should neverever happen
1230 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1234 // Write it finally, and write in UTF8, no matter what
1235 QTextStream ts( &file );
1236 ts.setEncoding (QTextStream::UnicodeUTF8);
1240 clipboardEmpty=false;
1245 void MapEditor::redo()
1247 blockSaveState=true;
1249 // Restore variables
1250 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1251 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1252 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1253 if (redosAvail>0) redosAvail--;
1254 if (undosAvail<undosTotal) undosAvail++;
1256 if (curStep>undosTotal) curStep=1;
1257 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1258 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1259 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1260 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1261 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1263 // Find out current undo directory
1264 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1266 /* TODO remove testing
1268 cout << "ME::redo() begin\n";
1269 cout << " undosAvail="<<undosAvail<<endl;
1270 cout << " redosAvail="<<redosAvail<<endl;
1271 cout << " curStep="<<curStep<<endl;
1272 cout << " ---------------------------"<<endl;
1273 cout << " comment="<<comment.toStdString()<<endl;
1274 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1275 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1276 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1277 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1278 cout << " ---------------------------"<<endl<<endl;
1280 // select object before redo
1281 // FIXME better give up if no selection there...
1282 if (!redoSelection.isEmpty())
1283 select (redoSelection);
1286 parseAtom (redoCommand);
1287 mapCenter->reposition();
1289 //if (!redoSelection.isEmpty())
1290 // select (redoSelection);
1292 blockSaveState=false;
1293 /* TODO remove testing
1295 cout << "ME::redo() end\n";
1296 cout << " undosAvail="<<undosAvail<<endl;
1297 cout << " redosAvail="<<redosAvail<<endl;
1298 cout << " curStep="<<curStep<<endl;
1299 cout << " ---------------------------"<<endl<<endl;
1302 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1303 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1304 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1305 undoSet.writeSettings(histPath);
1310 void MapEditor::undo()
1312 blockSaveState=true;
1314 // Restore variables
1315 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1316 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1317 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1318 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1319 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1320 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1321 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1322 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1324 // Find out current undo directory
1325 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1327 // select object before undo
1328 if (!undoSelection.isEmpty())
1329 select (undoSelection);
1333 cout << "ME::undo() begin\n";
1334 cout << " undosAvail="<<undosAvail<<endl;
1335 cout << " redosAvail="<<redosAvail<<endl;
1336 cout << " curStep="<<curStep<<endl;
1337 cout << " ---------------------------"<<endl;
1338 cout << " comment="<<comment.toStdString()<<endl;
1339 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1340 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1341 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1342 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1343 cout << " ---------------------------"<<endl<<endl;
1344 parseAtom (undoCommand);
1345 mapCenter->reposition();
1347 //if (!redoSelection.isEmpty())
1348 // select (redoSelection);
1353 // Undo not longer available now
1354 actionEditUndo->setEnabled (false);
1356 curStep--; if (curStep<1) curStep=undosTotal;
1360 blockSaveState=false;
1361 /* TODO remove testing
1363 cout << "ME::undo() end\n";
1364 cout << " undosAvail="<<undosAvail<<endl;
1365 cout << " redosAvail="<<redosAvail<<endl;
1366 cout << " curStep="<<curStep<<endl;
1367 cout << " ---------------------------"<<endl<<endl;
1369 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1370 undoSet.setEntry ("/history/redosAvail",QString::number(undosAvail));
1371 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1372 undoSet.writeSettings(histPath);
1377 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1379 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1381 QFile file (bakMapPath);
1385 // We need to parse saved XML data
1386 mapBuilderHandler handler;
1387 QXmlInputSource source( file);
1388 QXmlSimpleReader reader;
1389 reader.setContentHandler( &handler );
1390 reader.setErrorHandler( &handler );
1391 handler.setMapEditor( this );
1392 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1393 if (undoSel.isEmpty())
1397 handler.setLoadMode (NewMap);
1401 handler.setLoadMode (ImportReplace);
1403 blockReposition=true;
1404 bool ok = reader.parse( source );
1405 blockReposition=false;
1408 // This should never ever happen
1409 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1410 tr( handler.errorProtocol() )+" in "+bakMapDir );
1414 QMessageBox::critical( 0, tr( "Critical Error" ),
1415 tr("Temporary directory %1 used for undo is gone. \n"
1416 "I will create a new one, but at the moment no undo is available.\n"
1417 "Maybe you want to reload your original data.\n\n"
1418 "Sorry for any inconveniences.").arg(bakMapDir) );
1423 void MapEditor::pasteNoSave()
1425 load (clipboardDir+"/part.xml",ImportAdd);
1428 void MapEditor::cutNoSave()
1434 void MapEditor::paste()
1436 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1437 typeid(*selection) == typeid(MapCenterObj)))
1439 saveStatePart(selection,QString("Paste to %1").arg( getName(selection)));
1441 mapCenter->reposition();
1446 void MapEditor::cut()
1448 saveStatePart(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
1451 mapCenter->reposition();
1455 void MapEditor::move(const int &x, const int &y)
1457 // TODO no saveState, because this is only internal at undo so far
1458 if (selection) selection->move(x,y);
1459 if (typeid(*selection) == typeid(FloatImageObj))
1460 ((FloatImageObj*)selection)->setRelPos();
1463 void MapEditor::moveBranchUp()
1467 if (typeid(*selection) == typeid(BranchObj) )
1469 bo=(BranchObj*)selection;
1470 if (!bo->canMoveBranchUp()) return;
1471 par=(BranchObj*)(bo->getParObj());
1472 selection->unselect();
1473 selection=par->moveBranchUp (bo);
1474 selection->select();
1475 saveStateX(bo,"moveBranchDown ()",QString("Move up %1").arg(getName(bo)));
1476 mapCenter->reposition();
1477 ensureSelectionVisible();
1481 void MapEditor::moveBranchDown()
1485 if (typeid(*selection) == typeid(BranchObj) )
1487 bo=(BranchObj*)selection;
1488 if (!bo->canMoveBranchDown()) return;
1489 par=(BranchObj*)(bo->getParObj());
1490 selection->unselect();
1491 selection=par->moveBranchDown(bo);
1492 selection->select();
1493 saveStateX(bo,"moveBranchUp ()",QString("Move down %1").arg(getName(bo)));
1494 mapCenter->reposition();
1495 ensureSelectionVisible();
1499 QString MapEditor::getHeading(bool &ok, QPoint &p)
1502 (typeid(*selection) == typeid(BranchObj) ||
1503 typeid(*selection) == typeid(MapCenterObj) ) )
1506 ensureSelectionVisible();
1507 p = ((BranchObj*)selection)->getAbsPos();
1508 p.setX (p.x() - contentsX());
1509 p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2);
1510 return ((BranchObj*)selection)->getHeading();
1516 void MapEditor::setHeading(const QString &s)
1519 (typeid(*selection) == typeid(BranchObj) ||
1520 typeid(*selection) == typeid(MapCenterObj) ) )
1522 editingBO=(BranchObj*)selection;
1523 saveStateConstSelection(
1524 "setHeading (\""+editingBO->getHeading()+"\")",
1525 "setHeading (\""+s+"\")",
1526 QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) );
1527 editingBO->setHeading(s );
1529 mapCenter->reposition();
1531 ensureSelectionVisible();
1535 void MapEditor::setURLInt (const QString &s)
1537 // Internal function, no saveState needed
1539 (typeid(*selection) == typeid(BranchObj) ||
1540 typeid(*selection) == typeid(MapCenterObj) ) )
1542 ((BranchObj*)selection)->setURL(s);
1543 mapCenter->reposition();
1545 ensureSelectionVisible();
1549 void MapEditor::setHeadingInt(const QString &s)
1552 (typeid(*selection) == typeid(BranchObj) ||
1553 typeid(*selection) == typeid(MapCenterObj) ) )
1555 ((BranchObj*)selection)->setHeading(s);
1556 mapCenter->reposition();
1558 ensureSelectionVisible();
1562 void MapEditor::setVymLinkInt (const QString &s)
1564 // Internal function, no saveState needed
1566 (typeid(*selection) == typeid(BranchObj) ||
1567 typeid(*selection) == typeid(MapCenterObj) ) )
1569 ((BranchObj*)selection)->setVymLink(s);
1570 mapCenter->reposition();
1572 ensureSelectionVisible();
1576 void MapEditor::addNewBranch(int pos)
1579 (typeid(*selection) == typeid(BranchObj) ||
1580 typeid(*selection) == typeid(MapCenterObj) ) )
1582 BranchObj* bo1 = (BranchObj*) selection;
1584 bool wasScrolled=false;
1585 BranchObj *newbo=NULL;
1588 // save scroll state. If scrolled, automatically select
1589 // new branch in order to tmp unscroll parent...
1590 wasScrolled=bo1->isScrolled();
1591 newbo=bo1->addBranch();
1594 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1598 // add above selection
1599 newbo=parbo->insertBranch(bo1->getNum());
1601 // add below selection
1602 newbo=parbo->insertBranch(bo1->getNum()+1);
1604 // This should not happen...
1605 // ...but it happens if CTRL-A is pressed on MCO,
1609 saveStateX(selection,QString ("delete (\"%1\")").arg(newbo->getSelectString()),QString("Add new branch to %1").arg(getName(bo1))); //TODO undoCommand
1611 LinkableMapObj *oldselection=selection;
1613 mapCenter->reposition();
1617 if (actionSettingsAutoedit->isOn() ||
1618 actionSettingsAutoselectHeading->isOn() )
1620 selection->unselect();
1622 selection->select();
1623 if (actionSettingsPasteNewHeading->isOn() )
1625 BranchObj *bo2= (BranchObj*)selection;
1626 bo2->setHeading("");
1628 if (actionSettingsAutoedit->isOn() )
1629 mainWindow->editHeading();
1630 if (!actionSettingsAutoselectHeading->isOn()
1633 selection->unselect();
1634 selection=oldselection;
1635 selection->select();
1642 void MapEditor::addNewBranchHere()
1645 (typeid(*selection) == typeid(BranchObj) ) )
1647 BranchObj* bo1 = (BranchObj*) selection;
1648 saveStatePart(selection, QString("Add new branch here").arg(getName(bo1)));
1650 bool wasScrolled=false;
1651 BranchObj *newbo=NULL;
1652 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1655 // add below selection
1656 newbo=parbo->insertBranch(bo1->getNum()+1);
1659 LinkableMapObj *oldselection=selection;
1660 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1662 mapCenter->reposition();
1664 if (actionSettingsAutoedit->isOn() ||
1665 actionSettingsAutoselectHeading->isOn() )
1667 selection->unselect();
1669 selection->select();
1670 if (actionSettingsPasteNewHeading->isOn() )
1672 BranchObj *bo2= (BranchObj*)selection;
1673 bo2->setHeading("");
1675 if (actionSettingsAutoedit->isOn() )
1676 mainWindow->editHeading();
1677 if (!actionSettingsAutoselectHeading->isOn()
1680 selection->unselect();
1681 selection=oldselection;
1682 selection->select();
1688 void MapEditor::deleteSelection()
1690 if (selection && typeid(*selection) ==typeid(BranchObj) )
1692 BranchObj* bo=(BranchObj*)selection;
1693 BranchObj* par=(BranchObj*)(bo->getParObj());
1695 if (selection->getDepth()>1)
1696 // Normal branch, save parent with childs
1697 saveStatePart(par,QString("Delete %1").arg(getName(bo)));
1698 // naveState (UndoCom, par, QString("insertBranchAt (%1)", bo, "", QString ("Delete %1").arg(getName(bo))));
1700 // Mainbranch, save whole map
1701 // TODO Better would be to insert mainbranch again at pos
1702 // But undoCommand is missing right now
1703 saveStateComplete(QString("Delete %1").arg(getName(bo)));
1705 par->removeBranch(bo);
1707 selection->select();
1708 ensureSelectionVisible();
1709 mapCenter->reposition();
1712 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1714 FloatImageObj* fio=(FloatImageObj*)selection;
1715 BranchObj* par=(BranchObj*)(fio->getParObj());
1716 saveStatePart(par, QString("Delete %1").arg(getName(fio)));
1719 par->removeFloatImage(fio);
1721 selection->select();
1722 ensureSelectionVisible();
1723 mapCenter->reposition();
1728 LinkableMapObj* MapEditor::getSelection()
1733 void MapEditor::unselect()
1737 selectionLast=selection;
1738 selection->unselect();
1743 void MapEditor::reselect()
1747 selection=selectionLast;
1748 selection->select();
1753 bool MapEditor::select (const QString &s)
1755 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1757 // Finally select the found object
1760 if (selection) unselect();
1762 selection->select();
1764 ensureSelectionVisible();
1770 QString MapEditor::getSelectString()
1772 if (selection) return selection->getSelectString();
1776 void MapEditor::selectInt (LinkableMapObj *lmo)
1778 if (lmo && selection != lmo)
1780 // select the MapObj
1781 if (selection) selection->unselect();
1783 selection->select();
1790 void MapEditor::selectNextBranchInt()
1792 // Increase number of branch
1795 QString s=selection->getSelectString();
1801 part=s.section(",",-1);
1803 num=part.right(part.length() - 3);
1805 s=s.left (s.length() -num.length());
1808 num=QString ("%1").arg(num.toUInt()+1);
1812 // Try to select this one
1813 if (select (s)) return;
1815 // We have no direct successor,
1816 // try to increase the parental number in order to
1817 // find a successor with same depth
1819 int d=selection->getDepth();
1824 while (!found && d>0)
1826 s=s.section (",",0,d-1);
1827 // replace substring of current depth in s with "1"
1828 part=s.section(",",-1);
1830 num=part.right(part.length() - 3);
1834 // increase number of parent
1835 num=QString ("%1").arg(num.toUInt()+1);
1836 s=s.section (",",0,d-2) + ","+ typ+num;
1839 // Special case, look at orientation
1840 if (selection->getOrientation()==OrientRightOfCenter)
1841 num=QString ("%1").arg(num.toUInt()+1);
1843 num=QString ("%1").arg(num.toUInt()-1);
1848 // pad to oldDepth, select the first branch for each depth
1849 for (i=d;i<oldDepth;i++)
1854 if ( ((BranchObj*)selection)->countBranches()>0)
1862 // try to select the freshly built string
1870 void MapEditor::selectPrevBranchInt()
1872 // Decrease number of branch
1875 QString s=selection->getSelectString();
1881 part=s.section(",",-1);
1883 num=part.right(part.length() - 3);
1885 s=s.left (s.length() -num.length());
1888 num=QString ("%1").arg(num.toUInt()-1);
1892 // Try to select this one
1893 if (select (s)) return;
1895 // We have no direct precessor,
1896 // try to decrease the parental number in order to
1897 // find a precessor with same depth
1899 int d=selection->getDepth();
1904 while (!found && d>0)
1906 s=s.section (",",0,d-1);
1907 // replace substring of current depth in s with "1"
1908 part=s.section(",",-1);
1910 num=part.right(part.length() - 3);
1914 // decrease number of parent
1915 num=QString ("%1").arg(num.toUInt()-1);
1916 s=s.section (",",0,d-2) + ","+ typ+num;
1919 // Special case, look at orientation
1920 if (selection->getOrientation()==OrientRightOfCenter)
1921 num=QString ("%1").arg(num.toUInt()-1);
1923 num=QString ("%1").arg(num.toUInt()+1);
1928 // pad to oldDepth, select the last branch for each depth
1929 for (i=d;i<oldDepth;i++)
1933 if ( ((BranchObj*)selection)->countBranches()>0)
1934 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1941 // try to select the freshly built string
1949 void MapEditor::selectUpperBranch()
1953 if (typeid(*selection) == typeid(BranchObj))
1955 if (selection->getOrientation()==OrientRightOfCenter)
1956 selectPrevBranchInt();
1958 if (selection->getDepth()==1)
1959 selectNextBranchInt();
1961 selectPrevBranchInt();
1966 void MapEditor::selectLowerBranch()
1970 if (typeid(*selection) == typeid(BranchObj))
1972 if (selection->getOrientation()==OrientRightOfCenter)
1973 selectNextBranchInt();
1975 if (selection->getDepth()==1)
1976 selectPrevBranchInt();
1978 selectNextBranchInt();
1984 void MapEditor::selectLeftBranch()
1990 if (typeid(*selection) == typeid(MapCenterObj))
1992 par= (BranchObj*) selection;
1993 bo=par->getLastSelectedBranch();
1996 // Workaround for reselecting on left and right side
1997 if (bo->getOrientation()==OrientRightOfCenter)
1999 bo=par->getLastBranch();
2005 selection->select();
2007 ensureSelectionVisible();
2012 par=(BranchObj*)(selection->getParObj());
2013 if (selection->getOrientation()==OrientRightOfCenter)
2015 if (typeid(*selection) == typeid(BranchObj) ||
2016 typeid(*selection) == typeid(FloatImageObj))
2018 selection->unselect();
2020 selection->select();
2022 ensureSelectionVisible();
2026 if (typeid(*selection) == typeid(BranchObj) )
2028 bo=((BranchObj*)selection)->getLastSelectedBranch();
2031 selection->unselect();
2033 selection->select();
2035 ensureSelectionVisible();
2043 void MapEditor::selectRightBranch()
2050 if (typeid(*selection) == typeid(MapCenterObj))
2052 par= (BranchObj*) selection;
2053 bo=par->getLastSelectedBranch();
2056 // Workaround for reselecting on left and right side
2057 if (bo->getOrientation()==OrientLeftOfCenter)
2058 bo=par->getFirstBranch();
2063 selection->select();
2064 ensureSelectionVisible();
2069 par=(BranchObj*)(selection->getParObj());
2070 if (selection->getOrientation()==OrientLeftOfCenter)
2072 if (typeid(*selection) == typeid(BranchObj) ||
2073 typeid(*selection) == typeid(FloatImageObj))
2075 selection->unselect();
2077 selection->select();
2079 ensureSelectionVisible();
2083 if (typeid(*selection) == typeid(BranchObj) )
2085 bo=((BranchObj*)selection)->getLastSelectedBranch();
2088 selection->unselect();
2090 selection->select();
2092 ensureSelectionVisible();
2100 void MapEditor::selectFirstBranch()
2106 if (typeid(*selection) == typeid(BranchObj))
2108 bo1= (BranchObj*) selection;
2109 par=(BranchObj*)(bo1->getParObj());
2110 bo2=par->getFirstBranch();
2114 selection->select();
2115 ensureSelectionVisible();
2122 void MapEditor::selectLastBranch()
2128 if (typeid(*selection) == typeid(BranchObj))
2130 bo1= (BranchObj*) selection;
2131 par=(BranchObj*)(bo1->getParObj());
2132 bo2=par->getLastBranch();
2136 selection->select();
2137 ensureSelectionVisible();
2144 void MapEditor::setColor(QColor c)
2149 void MapEditor::selectBackgroundColor()
2151 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2152 if ( !col.isValid() ) return;
2153 setBackgroundColor( col );
2155 saveStateComplete(QString("Set background color of map to %1").arg(col.name()));
2158 void MapEditor::setBackgroundColor(QColor c)
2160 mapCanvas->setBackgroundColor (c);
2163 QColor MapEditor::pickColor()
2167 if (typeid(*selection) == typeid(BranchObj) ||
2168 typeid(*selection) == typeid(MapCenterObj))
2170 BranchObj *bo=(BranchObj*)selection;
2171 actColor=bo->getColor();
2177 void MapEditor::colorItem()
2181 if (typeid(*selection) == typeid(BranchObj) ||
2182 typeid(*selection) == typeid(MapCenterObj))
2184 BranchObj *bo=(BranchObj*)selection;
2185 saveStatePart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2186 bo->setColor(actColor); // color branch
2191 void MapEditor::colorBranch()
2195 if (typeid(*selection) == typeid(BranchObj) ||
2196 typeid(*selection) == typeid(MapCenterObj))
2198 BranchObj *bo=(BranchObj*)selection;
2199 saveStatePart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2200 bo->setColorChilds(actColor); // color links, color childs
2206 void MapEditor::toggleStandardFlag(QString f)
2210 if (typeid(*selection) == typeid(BranchObj) ||
2211 typeid(*selection) == typeid(MapCenterObj))
2213 BranchObj *bo=(BranchObj*)selection;
2215 if (bo->isSetStandardFlag(f))
2225 saveStateConstSelection(QString("%1 (\"%2\")").arg(u).arg(f),
2226 QString("%1 (\"%2\")").arg(r).arg(f),
2227 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2228 bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn());
2234 void MapEditor::setViewCenter()
2236 // transform to CanvasView Coord:
2237 QPoint p=worldMatrix().map(movingCenter);
2238 center ( p.x(), p.y());
2242 BranchObj* MapEditor::findText (QString s, bool cs)
2244 QTextDocument::FindFlags flags=0;
2245 if (cs) flags=QTextDocument::FindCaseSensitively;
2248 { // Nothing found or new find process
2250 // nothing found, start again
2252 itFind=mapCenter->first();
2254 bool searching=true;
2255 bool foundNote=false;
2256 while (searching && !EOFind)
2260 // Searching in Note
2261 if (itFind->getNote().contains(s,cs))
2263 if (selection!=itFind)
2265 if (selection) ((BranchObj*)selection)->unselect();
2267 selection->select();
2269 ensureSelectionVisible();
2271 if (textEditor->findText(s,flags))
2277 // Searching in Heading
2278 if (searching && itFind->getHeading().contains (s,cs) )
2280 if (selection) ((BranchObj*)selection)->unselect();
2282 selection->select();
2284 ensureSelectionVisible();
2290 itFind=itFind->next();
2291 if (!itFind) EOFind=true;
2297 return (BranchObj*)selection;
2302 void MapEditor::findReset()
2303 { // Necessary if text to find changes during a find process
2308 void MapEditor::editURL()
2310 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2311 typeid(*selection) == typeid(MapCenterObj)) )
2314 BranchObj *bo=(BranchObj*)selection;
2315 QString text = QInputDialog::getText(
2316 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2317 bo->getURL(), &ok, this );
2320 // user entered something and pressed OK
2321 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2328 QString MapEditor::getURL()
2330 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2331 typeid(*selection) == typeid(MapCenterObj)) )
2332 return ((BranchObj*)selection)->getURL();
2337 QStringList MapEditor::getURLs()
2340 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2341 typeid(*selection) == typeid(MapCenterObj)) )
2343 BranchObj *bo=(BranchObj*)selection;
2347 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2355 void MapEditor::editHeading2URL()
2357 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2358 typeid(*selection) == typeid(MapCenterObj)) )
2360 BranchObj *bo=(BranchObj*)selection;
2361 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2362 bo->setURL (bo->getHeading());
2367 void MapEditor::editBugzilla2URL()
2369 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2370 typeid(*selection) == typeid(MapCenterObj)) )
2372 BranchObj *bo=(BranchObj*)selection;
2373 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2374 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo)));
2380 void MapEditor::editFATE2URL()
2382 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2383 typeid(*selection) == typeid(MapCenterObj)) )
2385 BranchObj *bo=(BranchObj*)selection;
2386 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2387 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2393 void MapEditor::editVymLink()
2395 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2396 typeid(*selection) == typeid(MapCenterObj)) )
2398 BranchObj *bo=(BranchObj*)selection;
2399 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map"));
2400 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2401 fd->setCaption(__VYM " - " +tr("Link to another map"));
2402 if (! bo->getVymLink().isEmpty() )
2403 fd->setSelection( bo->getVymLink() );
2407 if ( fd->exec() == QDialog::Accepted )
2409 saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2410 bo->setVymLink (fd->selectedFile() );
2412 mapCenter->reposition();
2419 void MapEditor::deleteVymLink()
2421 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2422 typeid(*selection) == typeid(MapCenterObj)) )
2424 BranchObj *bo=(BranchObj*)selection;
2425 saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2426 bo->setVymLink ("" );
2428 mapCenter->reposition();
2434 void MapEditor::toggleHideExport()
2436 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2437 typeid(*selection) == typeid(MapCenterObj)) ||
2438 (typeid(*selection)==typeid(FloatImageObj))
2441 OrnamentedObj *oo=(OrnamentedObj*)selection;
2443 if (oo->hideInExport())
2445 oo->setHideInExport(false);
2450 oo->setHideInExport(true);
2453 saveStateComplete(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2454 actionEditToggleHideExport->setOn (oo->hideInExport());
2456 mapCenter->reposition();
2462 QString MapEditor::getVymLink()
2464 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2465 typeid(*selection) == typeid(MapCenterObj)) )
2467 return ((BranchObj*)selection)->getVymLink();
2473 QStringList MapEditor::getVymLinks()
2476 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2477 typeid(*selection) == typeid(MapCenterObj)) )
2479 BranchObj *bo=(BranchObj*)selection;
2483 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2491 void MapEditor::removeBranchKeepChilds()
2493 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2495 BranchObj* bo=(BranchObj*)selection;
2496 BranchObj* par=(BranchObj*)(bo->getParObj());
2497 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2498 if (bo->getDepth()==1)
2499 saveStateComplete(s);
2501 saveStatePart(selection->getParObj(),s); // TODO undoCommand
2502 QString sel=selection->getSelectString();
2504 par->removeBranchHere(bo);
2505 mapCenter->reposition();
2510 void MapEditor::removeChilds()
2512 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2514 saveStatePart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
2515 ((BranchObj*)selection)->removeChilds();
2516 mapCenter->reposition();
2520 void MapEditor::editMapInfo()
2522 ExtraInfoDialog dia;
2523 dia.setMapName (getFileName() );
2524 dia.setAuthor (mapCenter->getAuthor() );
2525 dia.setComment(mapCenter->getComment() );
2530 Q3CanvasItemList l=canvas()->allItems();
2531 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2533 stats+=QString ("%1 items on canvas\n").arg (i,6);
2540 bo=mapCenter->first();
2543 if (!bo->getNote().isEmpty() ) n++;
2544 f+= bo->countFloatImages();
2546 xl+=bo->countXLinks();
2549 stats+=QString ("%1 branches\n").arg (b-1,6);
2550 stats+=QString ("%1 xLinks \n").arg (xl,6);
2551 stats+=QString ("%1 notes\n").arg (n,6);
2552 stats+=QString ("%1 images\n").arg (f,6);
2553 dia.setStats (stats);
2555 // Finally show dialog
2556 if (dia.exec() == QDialog::Accepted)
2558 saveStateComplete("Edit info about map"); //TODO undoCommand
2559 mapCenter->setAuthor (dia.getAuthor() );
2560 mapCenter->setComment (dia.getComment() );
2564 void MapEditor::updateActions()
2567 if (getLinkColorHint()==HeadingColor)
2568 actionFormatLinkColorHint->setOn(true);
2570 actionFormatLinkColorHint->setOn(false);
2575 actionFormatLinkStyleLine->setOn(true);
2578 actionFormatLinkStyleParabel->setOn(true);
2581 actionFormatLinkStylePolyLine->setOn(true);
2583 case StylePolyParabel:
2584 actionFormatLinkStylePolyParabel->setOn(true);
2590 QPixmap pix( 16, 16 );
2591 pix.fill( mapCanvas->backgroundColor() );
2592 actionFormatBackColor->setIconSet( pix );
2593 pix.fill( defLinkColor );
2594 actionFormatLinkColor->setIconSet( pix );
2596 actionFileSave->setEnabled( mapUnsaved );
2597 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
2598 actionEditUndo->setEnabled( true);
2600 actionEditUndo->setEnabled( false);
2602 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
2603 actionEditRedo->setEnabled( true);
2605 actionEditRedo->setEnabled( false);
2609 if ( (typeid(*selection) == typeid(BranchObj)) ||
2610 (typeid(*selection) == typeid(MapCenterObj)) )
2612 BranchObj *bo=(BranchObj*)selection;
2613 // Take care of links
2614 if (bo->countXLinks()==0)
2616 branchXLinksContextMenuEdit->clear();
2617 branchXLinksContextMenuFollow->clear();
2622 branchXLinksContextMenuEdit->clear();
2623 branchXLinksContextMenuFollow->clear();
2624 for (int i=0; i<=bo->countXLinks();i++)
2626 bot=bo->XLinkTargetAt(i);
2629 s=bot->getHeading();
2632 branchXLinksContextMenuFollow->addAction (s);
2633 branchXLinksContextMenuEdit->addAction (s);
2638 standardFlagsDefault->setEnabled (true);
2640 actionEditToggleScroll->setEnabled (true);
2641 if ( bo->isScrolled() )
2642 actionEditToggleScroll->setOn(true);
2644 actionEditToggleScroll->setOn(false);
2646 if ( bo->getURL().isEmpty() )
2648 actionEditOpenURL->setEnabled (false);
2649 actionEditOpenURLTab->setEnabled (false);
2653 actionEditOpenURL->setEnabled (true);
2654 actionEditOpenURLTab->setEnabled (true);
2656 if ( bo->getVymLink().isEmpty() )
2658 actionEditOpenVymLink->setEnabled (false);
2659 actionEditDeleteVymLink->setEnabled (false);
2662 actionEditOpenVymLink->setEnabled (true);
2663 actionEditDeleteVymLink->setEnabled (true);
2666 if (bo->canMoveBranchUp())
2667 actionEditMoveUp->setEnabled (true);
2669 actionEditMoveUp->setEnabled (false);
2670 if (bo->canMoveBranchDown())
2671 actionEditMoveDown->setEnabled (true);
2673 actionEditMoveDown->setEnabled (false);
2676 actionEditToggleHideExport->setEnabled (true);
2677 actionEditToggleHideExport->setOn (bo->hideInExport() );
2679 actionEditCopy->setEnabled (true);
2680 actionEditCut->setEnabled (true);
2681 if (!clipboardEmpty)
2682 actionEditPaste->setEnabled (true);
2684 actionEditPaste->setEnabled (false);
2685 for (a=actionListBranches.first();a;a=actionListBranches.next())
2686 a->setEnabled(true);
2687 actionEditDelete->setEnabled (true);
2688 switch (selection->getFrameType())
2691 actionFormatFrameNone->setOn(true);
2694 actionFormatFrameRectangle->setOn(true);
2699 actionFormatIncludeImagesVer->setOn
2700 ( ((BranchObj*)selection)->getIncludeImagesVer());
2701 actionFormatIncludeImagesHor->setOn
2702 ( ((BranchObj*)selection)->getIncludeImagesHor());
2703 actionFormatHideLinkUnselected->setOn
2704 (selection->getHideLinkUnselected());
2706 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2708 FloatObj *fo=(FloatImageObj*)selection;
2709 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2711 actionEditOpenURL->setEnabled (false);
2712 actionEditOpenVymLink->setEnabled (false);
2713 actionEditDeleteVymLink->setEnabled (false);
2714 actionEditToggleHideExport->setEnabled (true);
2715 actionEditToggleHideExport->setOn (fo->hideInExport() );
2718 actionEditCopy->setEnabled (true);
2719 actionEditCut->setEnabled (true);
2720 actionEditPaste->setEnabled (false);
2721 for (a=actionListBranches.first();a;a=actionListBranches.next())
2722 a->setEnabled(false);
2723 actionEditDelete->setEnabled (true);
2724 actionFormatHideLinkUnselected->setOn
2725 ( selection->getHideLinkUnselected());
2726 actionEditMoveUp->setEnabled (false);
2727 actionEditMoveDown->setEnabled (false);
2732 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2734 actionEditCopy->setEnabled (false);
2735 actionEditCut->setEnabled (false);
2736 actionEditPaste->setEnabled (false);
2737 for (a=actionListBranches.first();a;a=actionListBranches.next())
2738 a->setEnabled(false);
2740 actionEditToggleScroll->setEnabled (false);
2741 actionEditOpenURL->setEnabled (false);
2742 actionEditOpenVymLink->setEnabled (false);
2743 actionEditDeleteVymLink->setEnabled (false);
2744 actionEditHeading2URL->setEnabled (false);
2745 actionEditDelete->setEnabled (false);
2746 actionEditMoveUp->setEnabled (false);
2747 actionEditMoveDown->setEnabled (false);
2748 actionEditToggleHideExport->setEnabled (false);
2752 void MapEditor::updateNoteFlag()
2755 if ( (typeid(*selection) == typeid(BranchObj)) ||
2756 (typeid(*selection) == typeid(MapCenterObj)) )
2757 ((BranchObj*)selection)->updateNoteFlag();
2760 void MapEditor::setLinkStyle (LinkStyle ls)
2764 saveStateComplete("Set link style"); // TODO undoCommand
2766 bo=mapCenter->first();
2770 bo->setLinkStyle(bo->getDefLinkStyle());
2773 mapCenter->reposition();
2776 LinkStyle MapEditor::getLinkStyle ()
2781 void MapEditor::setLinkColor(QColor c)
2787 void MapEditor::setLinkColorHint()
2789 // called from setLinkColorHint(lch) or at end of parse
2791 bo=mapCenter->first();
2799 void MapEditor::setLinkColorHint(LinkColorHint lch)
2805 void MapEditor::toggleLinkColorHint()
2807 if (linkcolorhint==HeadingColor)
2808 linkcolorhint=DefaultColor;
2810 linkcolorhint=HeadingColor;
2812 bo=mapCenter->first();
2820 LinkColorHint MapEditor::getLinkColorHint()
2822 return linkcolorhint;
2825 QColor MapEditor::getDefLinkColor()
2827 return defLinkColor;
2830 void MapEditor::setDefXLinkColor(QColor col)
2835 QColor MapEditor::getDefXLinkColor()
2837 return defXLinkColor;
2840 void MapEditor::setDefXLinkWidth (int w)
2845 int MapEditor::getDefXLinkWidth()
2847 return defXLinkWidth;
2850 void MapEditor::selectLinkColor()
2852 QColor col = QColorDialog::getColor( defLinkColor, this );
2853 if ( !col.isValid() ) return;
2854 setLinkColor( col );
2855 saveStateComplete(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2859 void MapEditor::toggleScroll()
2861 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2863 BranchObj *bo=((BranchObj*)selection);
2864 if (bo->countBranches()==0) return;
2865 if (bo->getDepth()==0) return;
2867 if (bo->isScrolled())
2871 saveStatePart(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2878 void MapEditor::unScrollAll()
2881 bo=mapCenter->first();
2884 if (bo->isScrolled()) bo->toggleScroll();
2889 void MapEditor::loadFloatImage ()
2892 (typeid(*selection) == typeid(BranchObj)) ||
2893 (typeid(*selection) == typeid(MapCenterObj)) )
2895 BranchObj *bo=((BranchObj*)selection);
2897 Q3FileDialog *fd=new Q3FileDialog( this);
2898 fd->setMode (Q3FileDialog::ExistingFiles);
2899 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2900 ImagePreview *p =new ImagePreview (fd);
2901 fd->setContentsPreviewEnabled( TRUE );
2902 fd->setContentsPreview( p, p );
2903 fd->setPreviewMode( Q3FileDialog::Contents );
2904 fd->setCaption(__VYM " - " +tr("Load image"));
2905 fd->setDir (lastImageDir);
2909 if ( fd->exec() == QDialog::Accepted )
2911 saveStatePart(selection, QString("Add floatimage to %1").arg(getName(selection)));
2912 // FIXME in QT4 use: lastImageDir=fd->directory();
2913 lastImageDir=QDir (fd->dirPath());
2914 QStringList flist = fd->selectedFiles();
2915 QStringList::Iterator it = flist.begin();
2916 while( it != flist.end() )
2919 bo->addFloatImage();
2920 // TODO check if load was successful
2921 bo->getLastFloatImage()->load(*it);
2922 bo->getLastFloatImage()->setOriginalFilename(fn);
2926 mapCenter->reposition();
2935 void MapEditor::saveFloatImage ()
2938 (typeid(*selection) == typeid(FloatImageObj)) )
2940 FloatImageObj *fio=((FloatImageObj*)selection);
2941 QFileDialog *fd=new QFileDialog( this);
2942 fd->setFilters (imageIO.getFilters());
2943 fd->setCaption(__VYM " - " +tr("Save image"));
2944 fd->setFileMode( QFileDialog::AnyFile );
2945 fd->setDirectory (lastImageDir);
2946 // fd->setSelection (fio->getOriginalFilename());
2950 if ( fd->exec() == QDialog::Accepted )
2952 if (QFile (fd->selectedFile()).exists() )
2954 QMessageBox mb( __VYM,
2955 tr("The file %1 exists already.\n"
2956 "Do you want to overwrite it?").arg(fd->selectedFile()),
2957 QMessageBox::Warning,
2958 QMessageBox::Yes | QMessageBox::Default,
2959 QMessageBox::Cancel | QMessageBox::Escape,
2960 QMessageBox::QMessageBox::NoButton );
2962 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2963 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2966 case QMessageBox::Yes:
2969 case QMessageBox::Cancel:
2975 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
2980 void MapEditor::setFrame(const FrameType &t)
2983 (typeid(*selection) == typeid(BranchObj)) ||
2984 (typeid(*selection) == typeid(MapCenterObj)) )
2986 selection->setFrameType (t);
2987 mapCenter->reposition();
2988 selection->updateLink();
2992 void MapEditor::setIncludeImagesVer(bool b)
2995 (typeid(*selection) == typeid(BranchObj)) ||
2996 (typeid(*selection) == typeid(MapCenterObj)) )
2997 ((BranchObj*)selection)->setIncludeImagesVer(b);
2998 mapCenter->reposition();
3001 void MapEditor::setIncludeImagesHor(bool b)
3004 (typeid(*selection) == typeid(BranchObj)) ||
3005 (typeid(*selection) == typeid(MapCenterObj)) )
3006 ((BranchObj*)selection)->setIncludeImagesHor(b);
3007 mapCenter->reposition();
3010 void MapEditor::setHideLinkUnselected (bool b)
3013 (typeid(*selection) == typeid(BranchObj)) ||
3014 (typeid(*selection) == typeid(MapCenterObj)) ||
3015 (typeid(*selection) == typeid(FloatImageObj)) )
3016 selection->setHideLinkUnselected(b);
3019 void MapEditor::importDirInt(BranchObj *dst, QDir d)
3022 (typeid(*selection) == typeid(BranchObj)) ||
3023 (typeid(*selection) == typeid(MapCenterObj)) )
3027 // Traverse directories
3028 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
3029 QFileInfoList list = d.entryInfoList();
3032 for (int i = 0; i < list.size(); ++i)
3035 if (fi.fileName() != "." && fi.fileName() != ".." )
3038 bo=dst->getLastBranch();
3039 bo->setHeading (fi.fileName() );
3040 bo->setColor (QColor("blue"));
3042 if ( !d.cd(fi.fileName()) )
3043 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3046 // Recursively add subdirs
3047 importDirInt (bo,d);
3053 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3054 list = d.entryInfoList();
3056 for (int i = 0; i < list.size(); ++i)
3060 bo=dst->getLastBranch();
3061 bo->setHeading (fi.fileName() );
3062 bo->setColor (QColor("black"));
3063 if (fi.fileName().right(4) == ".vym" )
3064 bo->setVymLink (fi.filePath());
3069 void MapEditor::importDir()
3072 (typeid(*selection) == typeid(BranchObj)) ||
3073 (typeid(*selection) == typeid(MapCenterObj)) )
3075 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
3076 fd->setMode (Q3FileDialog::DirectoryOnly);
3077 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3078 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
3082 if ( fd->exec() == QDialog::Accepted )
3084 BranchObj *bo=((BranchObj*)selection);
3085 importDirInt (bo,QDir(fd->selectedFile()) );
3086 mapCenter->reposition();
3093 void MapEditor::followXLink(int i)
3096 (typeid(*selection) == typeid(BranchObj)) ||
3097 (typeid(*selection) == typeid(MapCenterObj)) )
3099 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3102 selection->unselect();
3104 selection->select();
3105 ensureSelectionVisible();
3110 void MapEditor::editXLink(int i)
3112 qDebug ("ko."); //FIXME Huh?
3114 (typeid(*selection) == typeid(BranchObj)) ||
3115 (typeid(*selection) == typeid(MapCenterObj)) )
3117 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3120 EditXLinkDialog dia;
3122 dia.setSelection(selection);
3123 if (dia.exec() == QDialog::Accepted)
3125 if (dia.useSettingsGlobal() )
3127 setDefXLinkColor (xlo->getColor() );
3128 setDefXLinkWidth (xlo->getWidth() );
3130 if (dia.deleteXLink())
3131 ((BranchObj*)selection)->deleteXLinkAt(i);
3132 saveStateComplete("Edit xLink"); //TODO undoCommand
3138 void MapEditor::testFunction()
3140 cout << "MapEditor::testFunction() called\n";
3144 QString text = QInputDialog::getText(
3146 tr("QInputDialog::getText()"),
3147 tr("User name:"), QLineEdit::Normal,
3148 QDir::home().dirName(), &ok, Qt::FramelessWindowHint);
3151 QDialog *d =new QDialog(NULL);
3152 QLineEdit *le=new QLineEdit (d);
3153 // d->setModal (true);
3154 d->setWindowFlags (Qt::FramelessWindowHint);
3156 le->setText ("Foo");
3158 connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
3160 qWarning( le->text());
3167 dia.setCancelButton (true);
3168 dia.setText("This is a longer \nWarning");
3169 dia.setCaption("Warning: Flux problem");
3170 dia.setShowAgainName("/warnings/mapeditor");
3171 dia.setWindowFlags (Qt::FramelessWindowHint);
3172 if (dia.exec()==QDialog::Accepted)
3173 cout << "accepted!\n";
3175 cout << "canceled!\n";
3179 /* Hide hidden stuff temporary, maybe add this as regular function somewhere
3180 if (hidemode==HideNone)
3182 setHideTmpMode (HideExport);
3183 mapCenter->calcBBoxSizeWithChilds();
3184 QRect totalBBox=mapCenter->getTotalBBox();
3185 QRect mapRect=totalBBox;
3186 QCanvasRectangle *frame=NULL;
3188 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3190 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3191 totalBBox.width(), totalBBox.height());
3192 frame=new QCanvasRectangle (mapRect,mapCanvas);
3193 frame->setBrush (QColor(white));
3194 frame->setPen (QColor(black));
3200 setHideTmpMode (HideNone);
3202 cout <<" hidemode="<<hidemode<<endl;
3206 void MapEditor::ensureSelectionVisible()
3210 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3212 if (selection->getOrientation() == OrientLeftOfCenter)
3213 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3215 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3216 ensureVisible (p.x(), p.y() );
3221 void MapEditor::updateViewCenter()
3223 // Update movingCenter, so that we can zoom comfortably later
3224 QRect rc = QRect( contentsX(), contentsY(),
3225 visibleWidth(), visibleHeight() );
3226 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3227 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3228 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3231 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3233 // Lineedits are already closed by preceding
3234 // mouseEvent, we don't need to close here.
3236 QPoint p = inverseWorldMatrix().map(e->pos());
3237 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3240 { // MapObj was found
3241 if (selection != lmo)
3243 // select the MapObj
3244 if (selection) selection->unselect();
3246 selection->select();
3252 if (typeid(*selection)==typeid(BranchObj) ||
3253 typeid(*selection)==typeid(MapCenterObj) )
3255 // Context Menu on branch or mapcenter
3257 branchContextMenu->popup(e->globalPos() );
3259 if (typeid(*selection)==typeid(FloatImageObj))
3261 // Context Menu on floatimage
3263 floatimageContextMenu->popup(e->globalPos() );
3267 { // No MapObj found, we are on the Canvas itself
3268 // Context Menu on Canvas
3270 canvasContextMenu->popup(e->globalPos() );
3275 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3277 // Ignore right clicks, these will go to context menus
3278 if (e->button() == Qt::RightButton )
3284 QPoint p = inverseWorldMatrix().map(e->pos());
3285 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3289 //Take care of clickdesystem flags _or_ modifier modes
3291 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3292 typeid(*lmo)==typeid(MapCenterObj) ))
3294 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3295 if (!foname.isEmpty())
3297 // systemFlag clicked
3301 if (e->state() & Qt::ControlModifier)
3302 mainWindow->editOpenURLTab();
3304 mainWindow->editOpenURL();
3306 else if (foname=="vymLink")
3308 mainWindow->editOpenVymLink();
3309 // tabWidget may change, better return now
3310 // before segfaulting...
3311 } else if (foname=="note")
3312 mainWindow->windowToggleNoteEditor();
3313 else if (foname=="hideInExport")
3318 // No system flag clicked, take care of modmodes
3320 // Special case: CTRL is pressed
3321 if (e->state() & Qt::ControlModifier)
3323 if (actionModModeColor->isOn())
3326 setCursor (pickColorCursor);
3329 if (actionModModeLink->isOn())
3331 BranchObj *bo_begin=NULL;
3333 bo_begin=(BranchObj*)(lmo);
3336 ((typeid(*selection) == typeid(BranchObj)) ||
3337 (typeid(*selection) == typeid(MapCenterObj))) )
3338 bo_begin=(BranchObj*)selection;
3342 linkingObj_src=bo_begin;
3343 tmpXLink=new XLinkObj (mapCanvas);
3344 tmpXLink->setBegin (bo_begin);
3345 tmpXLink->setEnd (p);
3346 tmpXLink->setColor(defXLinkColor);
3347 tmpXLink->setWidth(defXLinkWidth);
3348 tmpXLink->updateXLink();
3349 tmpXLink->setVisibility (true);
3357 // Left Button Move Branches
3358 if (e->button() == Qt::LeftButton )
3360 movingObj_start.setX( p.x() - selection->x() );
3361 movingObj_start.setY( p.y() - selection->y() );
3362 movingObj_orgPos.setX (lmo->x() );
3363 movingObj_orgPos.setY (lmo->y() );
3365 // If modMode==copy, then we want to "move" the _new_ object around
3366 // then we need the offset from p to the _old_ selection, because of tmp
3367 if (actionModModeCopy->isOn() &&
3368 e->state() & Qt::ControlModifier)
3370 if (typeid(*selection)==typeid(BranchObj) )
3373 mapCenter->addBranch ((BranchObj*)selection);
3375 selection=mapCenter->getLastBranch();
3376 selection->select();
3377 mapCenter->reposition();
3380 movingObj=selection;
3382 // Middle Button Toggle Scroll
3383 // (On Mac OS X this won't work, but we still have
3384 // a button in the toolbar)
3385 if (e->button() == Qt::MidButton )
3389 { // No MapObj found, we are on the Canvas itself
3390 // Left Button move Pos of CanvasView
3391 if (e->button() == Qt::LeftButton )
3393 movingObj=NULL; // move Content not Obj
3394 movingObj_start=e->globalPos();
3395 movingCont_start=QPoint (contentsX(), contentsY() );
3396 movingVec=QPoint(0,0);
3397 setCursor(handOpenCursor);
3402 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3404 QPoint p = inverseWorldMatrix().map(e->pos());
3406 // Move the selected MapObj
3407 if ( selection && movingObj)
3409 // To avoid jumping of the CanvasView, only
3410 // ensureSelectionVisible, if not tmp linked
3411 if (!selection->hasParObjTmp())
3412 ensureSelectionVisible ();
3414 // Now move the selection, but add relative position
3415 // (movingObj_start) where selection was chosen with
3416 // mousepointer. (This avoids flickering resp. jumping
3417 // of selection back to absPos)
3419 LinkableMapObj *lmosel;
3420 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3422 // Check if we could link
3423 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3426 if (typeid(*selection) == typeid(FloatImageObj))
3428 FloatObj *fo=(FloatObj*)selection;
3429 saveStateConstSelection(
3430 "move "+qpointToString(movingObj_orgPos),fo->getSelectString() ,
3431 QString("Move %1").arg(getName(selection)));
3432 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3436 // Relink float to new mapcenter or branch, if shift is pressed
3437 // Only relink, if selection really has a new parent
3438 if ( (e->state() & Qt::ShiftModifier) && lmo &&
3439 ( (typeid(*lmo)==typeid(BranchObj)) ||
3440 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3441 ( lmo != fo->getParObj())
3444 if (typeid(*fo) == typeid(FloatImageObj))
3447 saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3448 FloatImageObj *fio=(FloatImageObj*)(fo);
3449 ((BranchObj*)(lmo))->addFloatImage (fio);
3451 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3452 fio=((BranchObj*)(lmo))->getLastFloatImage();
3455 selection=(LinkableMapObj*)(fio);
3456 selection->select();
3457 movingObj=(MapObj*)(fio);
3460 } else // selection != a FloatObj
3462 if (lmosel->getDepth()==0)
3464 if (e->state() == Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3465 // If mapCenter is moved, move all the rest by default, too.
3466 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3468 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3471 if (lmosel->getDepth()==1)
3473 // depth==1, mainbranch
3474 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3478 if (lmosel->getOrientation() == OrientLeftOfCenter)
3479 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3480 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3481 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3483 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3485 // reposition subbranch
3486 lmosel->reposition();
3487 //ensureSelectionVisible();
3489 if (lmo && (lmo!=selection) &&
3490 (typeid(*lmo) == typeid(BranchObj) ||
3491 (typeid(*lmo) == typeid(MapCenterObj) )
3494 if (e->state() & Qt::ControlModifier)
3496 // Special case: CTRL to link below lmo
3497 lmosel->setParObjTmp (lmo,p,+1);
3499 else if (e->state() & Qt::ShiftModifier)
3500 lmosel->setParObjTmp (lmo,p,-1);
3502 lmosel->setParObjTmp (lmo,p,0);
3505 lmosel->unsetParObjTmp();
3509 } // no FloatImageObj
3513 } // selection && moving_obj
3515 // Draw a link from one branch to another
3518 tmpXLink->setEnd (p);
3519 tmpXLink->updateXLink();
3523 if (!movingObj && !pickingColor &&!drawingLink)
3525 QPoint p=e->globalPos();
3526 movingVec.setX(-p.x() + movingObj_start.x() );
3527 movingVec.setY(-p.y() + movingObj_start.y() );
3528 setContentsPos( movingCont_start.x() + movingVec.x(),
3529 movingCont_start.y() + movingVec.y());
3536 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3538 LinkableMapObj *dst;
3539 // Have we been picking color?
3543 setCursor (Qt::ArrowCursor);
3544 // Check if we are over another branch
3545 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3546 if (dst && selection)
3548 if (e->state() & Qt::ShiftModifier)
3550 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3551 ((BranchObj*)selection)->setLinkColor ();
3555 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3556 ((BranchObj*)selection)->setLinkColor ();
3562 // Have we been drawing a link?
3566 // Check if we are over another branch
3567 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3568 if (dst && selection)
3570 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3571 tmpXLink->updateXLink();
3572 tmpXLink->activate();
3573 saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3582 // Have we been moving something?
3583 if ( selection && movingObj )
3585 // Moved FloatObj? Maybe we need to reposition
3586 if(typeid(*selection)==typeid (FloatImageObj))
3588 selection->getParObj()->requestReposition();
3589 mapCenter->reposition();
3592 // Check if we are over another branch, but ignore
3593 // any found LMOs, which are FloatObjs
3594 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3595 ((LinkableMapObj*)selection) );
3597 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3600 // Now check, if we have been moving a branch
3601 if (typeid(*selection) == typeid(BranchObj) )
3603 // save the position in case we link to mapcenter
3604 QPoint savePos=QPoint (selection->x(),selection->y() );
3606 // Reset the temporary drawn link to the original one
3607 ((LinkableMapObj*)selection)->unsetParObjTmp();
3613 BranchObj* bs=((BranchObj*)selection);
3614 QString undoCom="linkBranchToPos (\""+
3615 (bs->getParObj())->getSelectString()+
3617 QString("%1").arg(bs->getNum())+
3619 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3621 // TODO we also could check, if dest and src are on same branch,
3622 // then it would be sufficient to saveState of this branch
3624 // Modifiers allow to insert above/below dst
3625 if (e->state() & Qt::ShiftModifier)
3627 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3629 if (e->state() & Qt::ControlModifier)
3631 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3634 bs->moveBranchTo ((BranchObj*)(dst),-1);
3635 if (dst->getDepth()==0)
3638 saveStateConstSelection (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) );
3640 if (selection->getDepth()==1)
3641 // If we have moved mainbranch only save endposition
3642 saveStateConstSelection("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos)));
3644 // Draw the original link, before selection was moved around
3645 mapCenter->reposition();
3647 // Finally resize canvas, if needed
3652 // maybe we moved View: set old cursor
3653 setCursor (Qt::ArrowCursor);
3657 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3659 if (e->button() == Qt::LeftButton )
3661 QPoint p = inverseWorldMatrix().map(e->pos());
3662 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3663 if (lmo) { // MapObj was found
3664 // First select the MapObj than edit heading
3665 if (selection) selection->unselect();
3667 selection->select();
3668 mainWindow->editHeading();
3673 void MapEditor::resizeEvent (QResizeEvent* e)
3675 Q3CanvasView::resizeEvent( e );
3679 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3682 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3683 // cerr << event->format(i) << endl;
3686 (typeid(*selection) == typeid(BranchObj)) ||
3687 (typeid(*selection) == typeid(MapCenterObj))) {
3689 // If QImageDrag can decode mime type
3690 if (Q3ImageDrag::canDecode(event)) {
3695 // If image are dragged from firefox
3696 if (event->provides("application/x-moz-file-promise-url") &&
3697 event->provides("application/x-moz-nativeimage")) {
3698 event->accept(true);
3702 // If QUriDrag can decode mime type
3703 if (Q3UriDrag::canDecode(event)) {
3708 // If Uri are dragged from firefox
3709 if (event->provides("_NETSCAPE_URL")){
3714 // If QTextDrag can decode mime type
3715 if (Q3TextDrag::canDecode(event)) {
3724 bool isUnicode16(const QByteArray &d)
3726 // TODO: make more precise check for unicode 16.
3727 // Guess unicode16 if any of second bytes are zero
3728 unsigned int length = max(0,d.size()-2)/2;
3729 for (unsigned int i = 0; i<length ; i++)
3730 if (d.at(i*2+1)==0) return true;
3734 void MapEditor::contentsDropEvent(QDropEvent *event)
3737 (typeid(*selection) == typeid(BranchObj)) ||
3738 (typeid(*selection) == typeid(MapCenterObj)))
3743 if (event->provides("image/png"))
3746 if (Q3ImageDrag::decode(event, pix))
3754 } else if (event->provides("application/x-moz-file-promise-url") &&
3755 event->provides("application/x-moz-nativeimage"))
3757 // Contains url to the img src in unicode16
3758 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3759 QString url = QString((const QChar*)d.data(),d.size()/2);
3763 } else if (event->provides ("text/uri-list"))
3764 { // Uris provided e.g. by konqueror
3765 Q3UriDrag::decode (event,uris);
3766 } else if (event->provides ("_NETSCAPE_URL"))
3767 { // Uris provided by Mozilla
3768 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3771 } else if (event->provides("text/html")) {
3773 // Handels text mime types
3774 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3775 QByteArray d = event->encodedData("text/html");
3778 text = QString((const QChar*)d.data(),d.size()/2);
3782 textEditor->setText(text);
3786 } else if (event->provides("text/plain")) {
3787 QByteArray d = event->encodedData("text/plain");
3790 text = QString((const QChar*)d.data(),d.size()/2);
3794 textEditor->setText(text);
3806 for (const char* u=uris.first(); u; u=uris.next())
3808 bo=((BranchObj*)selection)->addBranch();
3811 s=Q3UriDrag::uriToLocalFile(u);
3814 QString file = QDir::convertSeparators(s);
3815 heading = QFileInfo(file).baseName();
3817 if (file.endsWith(".vym", false))
3818 bo->setVymLink(file);
3827 if (!heading.isEmpty())
3828 bo->setHeading(heading);
3838 //FIXME saveState has to be called earlier for each of the drops...
3839 saveStateComplete("Drop Event"); //TODO undo Command
3840 mapCenter->reposition();
3847 void MapEditor::addFloatImage(const QPixmap &img)
3850 (typeid(*selection) == typeid(BranchObj)) ||
3851 (typeid(*selection) == typeid(MapCenterObj)) )
3853 BranchObj *bo=((BranchObj*)selection);
3854 saveStatePart(selection,QString("Add floatimage to %1").arg(getName(bo)));
3855 //QString fn=fd->selectedFile();
3856 //lastImageDir=fn.left(fn.findRev ("/"));
3857 bo->addFloatImage();
3858 // FIXME check if load was successful
3859 bo->getLastFloatImage()->load(img);
3860 //bo->getLastFloatImage()->setOriginalFilename(fn);
3861 mapCenter->reposition();
3868 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
3870 if (!imageBuffer) imageBuffer = new QBuffer();
3871 if (!imageBuffer->isOpen()) {
3872 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3874 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3878 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3880 if (nop->state()==Q3NetworkProtocol::StDone) {
3881 QPixmap img(imageBuffer->buffer());
3886 imageBuffer->close();
3888 imageBuffer->close();
3895 void MapEditor::fetchImage(const QString &url)
3898 urlOperator->stop();
3899 disconnect(urlOperator);
3903 urlOperator = new Q3UrlOperator(url);
3904 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
3905 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
3907 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
3908 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));