undo/redo for delete BranchObj. Added calling commands in testmenu
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)
390 if (!redoSel ||typeid(*redoSel) != typeid(BranchObj) )
392 qWarning ("MapEditor::saveStateRemovingPart no undoSel given!");
396 // save the selected part of the map, Undo will insert part of map
397 QString undoSelection=redoSel->getParObj()->getSelectString();
398 QString redoSelection=redoSel->getSelectString();
400 saveState (PartOfMap,
401 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
402 redoSelection, "delete ()",
407 void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment)
409 // selection does not change during action,
410 // so just save commands for undo and redo
411 // and use current selection
414 if (selection) sel=selection->getSelectString();
416 saveState (UndoCommand,
423 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
425 // "Normal" savestate: save commands, selections and comment
426 // so just save commands for undo and redo
427 // and use current selection
429 QString redoSelection="";
430 if (redoSel) redoSelection=redoSel->getSelectString();
431 QString undoSelection="";
432 if (undoSel) undoSelection=undoSel->getSelectString();
434 saveState (UndoCommand,
441 void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
443 // "Normal" savestate: save commands, selections and comment
444 // so just save commands for undo and redo
445 // and use current selection
446 saveState (UndoCommand,
454 void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
458 if (blockSaveState) return;
460 /* TODO remove after testing
462 cout << "ME::saveState() "<<endl;
466 int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
467 int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
468 int curStep=undoSet.readNumEntry ("/history/curStep",0);
469 // Find out current undo directory
470 if (undosAvail<stepsTotal) undosAvail++;
472 if (curStep>stepsTotal) curStep=1;
475 QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
476 QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
477 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
479 // Create bakMapDir if not available
482 makeSubDirs (bakMapDir);
484 // Save depending on how much needs to be saved
488 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel);
490 QString undoCommand="";
491 if (savemode==UndoCommand)
495 else if (savemode==PartOfMap )
498 undoCommand.replace ("PATH",bakMapPath);
501 undoCommand="undoMap (\""+bakMapPath+"\")";
503 if (!backupXML.isEmpty())
504 // Write XML Data to disk
505 saveStringToDisk (QString(bakMapPath),backupXML);
507 // We would have to save all actions in a tree, to keep track of
508 // possible redos after a action. Possible, but we are too lazy: forget about redos.
511 // Write the current state to disk
512 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
513 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
514 undoSet.setEntry ("/history/curStep",QString::number(curStep));
515 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
516 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
517 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
518 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
519 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
520 undoSet.writeSettings(histPath);
522 /* TODO remove after testing
524 //cout << " into="<< histPath.toStdString()<<endl;
525 cout << " stepsTotal="<<stepsTotal<<
526 ", undosAvail="<<undosAvail<<
527 ", redosAvail="<<redosAvail<<
528 ", curStep="<<curStep<<endl;
529 cout << " ---------------------------"<<endl;
530 cout << " comment="<<comment.toStdString()<<endl;
531 cout << " undoCom="<<undoCommand.toStdString()<<endl;
532 cout << " undoSel="<<undoSelection.toStdString()<<endl;
533 cout << " redoCom="<<redoCom.toStdString()<<endl;
534 cout << " redoSel="<<redoSelection.toStdString()<<endl;
535 cout << " ---------------------------"<<endl;
537 historyWindow.update (undoSet);
540 void MapEditor::parseAtom(const QString &atom)
547 // Split string s into command and parameters
548 api.parseCommand (atom);
549 QString com=api.command();
552 if (com=="addBranch")
554 if (api.checkParamCount(1) && selection )
557 if (ok ) addNewBranchInt (y);
559 } else if (com==QString("addMapReplace"))
561 if (api.checkParamCount(2))
563 s=api.parString (ok,0); // selection
564 t=api.parString (ok,1); // path to map
565 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
568 } else if (com==QString("addMapInsert"))
570 if (api.checkParamCount(2))
572 t=api.parString (ok,0); // path to map
573 y=api.parInt(ok,1); // position
574 if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
577 } else if (com=="delete")
579 if (api.checkParamCount(0) && selection )
583 } else if (com=="linkBranchToPos")
585 if (selection && typeid(*selection) == typeid(BranchObj) )
587 if (api.checkParamCount(4))
589 // 0 selectstring of parent
590 // 1 num in parent (for branches)
591 // 2,3 x,y of mainbranch or mapcenter
592 s=api.parString(ok,0);
593 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
596 if (typeid(*dst) == typeid(BranchObj) )
598 // Get number in parent
601 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
602 } else if (typeid(*dst) == typeid(MapCenterObj) )
604 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
605 // Get coordinates of mainbranch
610 if (ok) ((BranchObj*)selection)->move (x,y);
616 } else if (com=="moveBranchUp")
618 else if (com=="moveBranchDown")
620 else if (com=="move")
622 if (api.checkParamCount(2) && selection )
632 else if (com=="moveRel")
634 if (api.checkParamCount(2) && selection )
640 if (ok) moveRel (x,y);
643 } else if (com=="setHeading")
645 if (api.checkParamCount(1))
647 s=api.parString (ok,0);
651 } else if (com=="setURL")
653 if (api.checkParamCount(1))
655 s=api.parString (ok,0);
656 if (ok) setURLInt(s);
658 } else if (com=="setVymLink")
660 if (api.checkParamCount(1))
662 s=api.parString (ok,0);
663 if (ok) setVymLinkInt(s);
666 else if (com=="setFlag")
668 if (selection && typeid(*selection) == typeid(BranchObj) )
670 if (api.checkParamCount(1) )
672 s=api.parString(ok,0);
675 BranchObj* bo=(BranchObj*)selection;
676 bo->activateStandardFlag(s);
677 bo->updateFlagsToolbar();
682 else if (com=="unsetFlag")
684 if (selection && typeid(*selection) == typeid(BranchObj) )
686 if (api.checkParamCount(1) )
688 s=api.parString(ok,0);
691 BranchObj* bo=(BranchObj*)selection;
692 bo->deactivateStandardFlag(s);
693 bo->updateFlagsToolbar();
698 } else if (com==QString("undoMap"))
700 if (api.checkParamCount(1))
701 addMapReplace("",api.parString (ok,0));
702 } else if (com=="select")
704 if (api.checkParamCount(1))
706 s=api.parString(ok,0);
712 api.setError ("Unknown command in: "+atom);
718 // TODO Error handling
719 qWarning("MapEditor::parseAtom: Error!");
720 qWarning(api.errorDesc());
724 void MapEditor::toggleHistoryWindow()
726 if (historyWindow.isVisible())
727 historyWindow.hide();
729 historyWindow.show();
733 bool MapEditor::isDefault()
738 bool MapEditor::isUnsaved()
743 bool MapEditor::hasChanged()
748 void MapEditor::setChanged()
756 void MapEditor::closeMap()
758 // Unselect before disabling the toolbar actions
759 if (selection) selection->unselect();
767 void MapEditor::setFilePath(QString fname)
769 setFilePath (fname,fname);
772 void MapEditor::setFilePath(QString fname, QString destname)
774 if (fname.isEmpty() || fname=="")
781 filePath=fname; // becomes absolute path
782 fileName=fname; // gets stripped of path
783 destPath=destname; // needed for vymlinks
785 // If fname is not an absolute path, complete it
786 filePath=QDir(fname).absPath();
787 fileDir=filePath.left (1+filePath.findRev ("/"));
789 // Set short name, too. Search from behind:
790 int i=fileName.findRev("/");
791 if (i>=0) fileName=fileName.remove (0,i+1);
793 // Forget the .vym (or .xml) for name of map
794 mapName=fileName.left(fileName.findRev(".",-1,true) );
796 // Adjust history window
797 historyWindow.setCaption (__VYM " - " +tr("History for ")+fileName);
801 QString MapEditor::getFilePath()
806 QString MapEditor::getFileName()
811 QString MapEditor::getMapName()
816 QString MapEditor::getDestPath()
821 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
823 ErrorCode err=success;
827 if (selection) selection->unselect();
830 mapCenter->setMapEditor(this);
831 // (map state is set later at end of load...)
834 saveStateChangingPart(selection,"Load map");
838 mapBuilderHandler handler;
841 // I am paranoid: file should exist anyway
842 // according to check in mainwindow.
845 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
846 tr("Couldn't open map " +fname)+".");
850 blockReposition=true;
851 QXmlInputSource source( file);
852 QXmlSimpleReader reader;
853 reader.setContentHandler( &handler );
854 reader.setErrorHandler( &handler );
855 handler.setMapEditor( this );
856 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
857 handler.setInputFile (file.name());
858 handler.setLoadMode (lmode);
860 bool ok = reader.parse( source );
861 blockReposition=false;
862 blockSaveState=false;
866 mapCenter->reposition();
876 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
877 tr( handler.errorProtocol() ) );
879 // Still return "success": the map maybe at least
880 // partially read by the parser
887 int MapEditor::save (const SaveMode &savemode)
891 // The SaveMode UndoCommand is not supported here
892 if (savemode==UndoCommand) return 1;
894 // Create mapName and fileDir
895 makeSubDirs (fileDir);
899 fname=mapName+".xml";
901 // use name given by user, even if he chooses .doc
906 if (savemode==CompleteMap || selection==NULL)
907 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
909 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
911 if (!saveStringToDisk(fileDir+fname,saveFile))
924 void MapEditor::setZipped (bool z)
929 bool MapEditor::saveZipped ()
934 void MapEditor::print()
938 printer = new QPrinter;
939 printer->setColorMode (QPrinter::Color);
940 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
943 QRect totalBBox=mapCenter->getTotalBBox();
945 // Try to set orientation automagically
946 // Note: Interpretation of generated postscript is amibiguous, if
947 // there are problems with landscape mode, see
948 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
950 if (totalBBox.width()>totalBBox.height())
951 // recommend landscape
952 printer->setOrientation (QPrinter::Landscape);
954 // recommend portrait
955 printer->setOrientation (QPrinter::Portrait);
957 if ( printer->setup(this) )
958 // returns false, if printing is canceled
960 QPainter pp(printer);
962 // Don't print the visualisation of selection
963 LinkableMapObj *oldselection=NULL;
966 oldselection=selection;
967 selection->unselect();
970 // Handle sizes of map and paper:
972 // setWindow defines which part of the canvas will be transformed
973 // setViewport defines area on paper in device coordinates (dpi)
974 // e.g. (0,50,700,700) is upper part on A4
975 // see also /usr/lib/qt3/doc/html/coordsys.html
977 Q3PaintDeviceMetrics metrics (printer);
979 double paperAspect = (double)metrics.width() / (double)metrics.height();
980 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
982 QRect mapRect=totalBBox;
983 Q3CanvasRectangle *frame=NULL;
984 Q3CanvasText *footerFN=NULL;
985 Q3CanvasText *footerDate=NULL;
986 if (printFrame || printFooter)
991 // Print frame around map
992 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
993 totalBBox.width()+20, totalBBox.height()+20);
994 frame=new Q3CanvasRectangle (mapRect,mapCanvas);
995 frame->setBrush (QColor(Qt::white));
996 frame->setPen (QColor(Qt::black));
1000 /* TODO remove after testing
1001 QCanvasLine *l=new QCanvasLine (mapCanvas);
1002 l->setPoints (0,0,mapRect.width(),mapRect.height());
1003 l->setPen (QPen(QColor(black), 1));
1010 // Print footer below map
1012 font.setPointSize(10);
1013 footerFN=new Q3CanvasText (mapCanvas);
1014 footerFN->setText ("VYM - " + fileName);
1015 footerFN->setFont(font);
1016 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1017 footerFN->setZ(Z_TEXT);
1019 footerDate=new Q3CanvasText (mapCanvas);
1020 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1021 footerDate->setFont(font);
1022 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1023 footerDate->setZ(Z_TEXT);
1026 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1029 pp.setWindow (mapRect);
1032 if (mapAspect>=paperAspect)
1034 // Fit horizontally to paper width
1035 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1038 // Fit vertically to paper height
1039 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1042 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1044 // Delete Frame and footer
1048 delete (footerDate);
1050 if (frame) delete (frame);
1052 // Restore selection
1055 selection=oldselection;
1056 selection->select();
1059 // Save settings in vymrc
1060 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1064 QPixmap MapEditor::getPixmap()
1066 QRect mapRect=mapCenter->getTotalBBox();
1067 QPixmap pix (mapRect.size());
1070 // Don't print the visualisation of selection
1071 LinkableMapObj *oldselection=NULL;
1074 oldselection=selection;
1075 selection->unselect();
1078 pp.setWindow (mapRect);
1080 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1083 // Restore selection
1086 selection=oldselection;
1087 selection->select();
1093 void MapEditor::setHideTmpMode (HideTmpMode mode)
1096 mapCenter->setHideTmp (hidemode);
1097 mapCenter->reposition();
1102 HideTmpMode MapEditor::getHideTmpMode()
1107 void MapEditor::exportImage(QString fn)
1109 setExportMode (true);
1110 QPixmap pix (getPixmap());
1111 pix.save(fn, "PNG");
1112 setExportMode (false);
1115 void MapEditor::setExportMode (bool b)
1117 // should be called before and after exports
1118 // depending on the settings
1119 if (b && settings.value("/export/useHideExport","yes")=="yes")
1120 setHideTmpMode (HideExport);
1122 setHideTmpMode (HideNone);
1125 void MapEditor::exportImage(QString fn, QString format)
1127 setExportMode (true);
1128 QPixmap pix (getPixmap());
1129 pix.save(fn, format);
1130 setExportMode (false);
1133 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1137 ex.setMapCenter(mapCenter);
1138 if (ex.setConfigFile(cf))
1140 setExportMode (true);
1141 ex.exportPresentation();
1142 setExportMode (false);
1148 void MapEditor::exportXML(const QString &dir)
1150 // Hide stuff during export, if settings want this
1151 setExportMode (true);
1153 // Create subdirectories
1156 // write to directory
1157 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1160 file.setName ( dir + "/"+mapName+".xml");
1161 if ( !file.open( QIODevice::WriteOnly ) )
1163 // This should neverever happen
1164 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1168 // Write it finally, and write in UTF8, no matter what
1169 QTextStream ts( &file );
1170 ts.setEncoding (QTextStream::UnicodeUTF8);
1174 // Now write image, too
1175 exportImage (dir+"/images/"+mapName+".png");
1177 setExportMode (false);
1180 void MapEditor::clear()
1184 selection->unselect();
1191 void MapEditor::copy()
1195 // write to directory
1196 QString clipfile="part";
1197 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1200 file.setName ( clipboardDir + "/"+clipfile+".xml");
1201 if ( !file.open( QIODevice::WriteOnly ) )
1203 // This should neverever happen
1204 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1208 // Write it finally, and write in UTF8, no matter what
1209 QTextStream ts( &file );
1210 ts.setEncoding (QTextStream::UnicodeUTF8);
1214 clipboardEmpty=false;
1219 void MapEditor::redo()
1221 blockSaveState=true;
1223 // Restore variables
1224 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1225 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1226 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1227 // Can we undo at all?
1228 if (redosAvail<1) return;
1231 if (undosAvail<stepsTotal) undosAvail++;
1233 if (curStep>stepsTotal) curStep=1;
1234 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1235 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1236 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1237 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1238 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1240 // Find out current undo directory
1241 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1243 /* TODO remove testing
1245 cout << "ME::redo() begin\n";
1246 cout << " undosAvail="<<undosAvail<<endl;
1247 cout << " redosAvail="<<redosAvail<<endl;
1248 cout << " curStep="<<curStep<<endl;
1249 cout << " ---------------------------"<<endl;
1250 cout << " comment="<<comment.toStdString()<<endl;
1251 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1252 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1253 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1254 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1255 cout << " ---------------------------"<<endl<<endl;
1257 // select object before redo
1258 // FIXME better give up if no selection there...
1259 if (!redoSelection.isEmpty())
1260 select (redoSelection);
1263 parseAtom (redoCommand);
1264 mapCenter->reposition();
1266 blockSaveState=false;
1268 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1269 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1270 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1271 undoSet.writeSettings(histPath);
1273 historyWindow.update (undoSet);
1276 /* TODO remove testing
1278 cout << "ME::redo() end\n";
1279 cout << " undosAvail="<<undosAvail<<endl;
1280 cout << " redosAvail="<<redosAvail<<endl;
1281 cout << " curStep="<<curStep<<endl;
1282 cout << " ---------------------------"<<endl<<endl;
1287 bool MapEditor::isRedoAvailable()
1289 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1295 void MapEditor::undo()
1297 blockSaveState=true;
1299 // Restore variables
1300 int curStep=undoSet.readNumEntry (QString("/history/curStep"));
1301 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1302 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1304 // Can we undo at all?
1305 if (undosAvail<1) return;
1307 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1308 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1309 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1310 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1311 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1313 // Find out current undo directory
1314 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
1316 // select object before undo
1317 if (!undoSelection.isEmpty())
1318 select (undoSelection);
1322 cout << "ME::undo() begin\n";
1323 cout << " undosAvail="<<undosAvail<<endl;
1324 cout << " redosAvail="<<redosAvail<<endl;
1325 cout << " curStep="<<curStep<<endl;
1326 cout << " ---------------------------"<<endl;
1327 cout << " comment="<<comment.toStdString()<<endl;
1328 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1329 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1330 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1331 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1332 cout << " ---------------------------"<<endl<<endl;
1333 parseAtom (undoCommand);
1334 mapCenter->reposition();
1338 if (curStep<1) curStep=stepsTotal;
1342 blockSaveState=false;
1343 /* TODO remove testing
1345 cout << "ME::undo() end\n";
1346 cout << " undosAvail="<<undosAvail<<endl;
1347 cout << " redosAvail="<<redosAvail<<endl;
1348 cout << " curStep="<<curStep<<endl;
1349 cout << " ---------------------------"<<endl<<endl;
1351 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1352 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1353 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1354 undoSet.writeSettings(histPath);
1356 historyWindow.update (undoSet);
1360 bool MapEditor::isUndoAvailable()
1362 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1368 void MapEditor::gotoStep (int i)
1370 // Restore variables
1371 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1372 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1374 cout << "ME::goto "<<i<<endl;
1376 if (i<0) i=undosAvail+redosAvail;
1378 // Clicking above current step makes us undo things
1381 for (int j=0; j<undosAvail-i; j++) undo();
1384 // Clicking below current step makes us redo things
1386 for (int j=undosAvail; j<i; j++) redo();
1388 // And ignore clicking the current row ;-)
1391 void MapEditor::addMapReplace(const QString &undoSel, const QString &path)
1393 QString pathDir=path.left(path.findRev("/"));
1399 // We need to parse saved XML data
1400 mapBuilderHandler handler;
1401 QXmlInputSource source( file);
1402 QXmlSimpleReader reader;
1403 reader.setContentHandler( &handler );
1404 reader.setErrorHandler( &handler );
1405 handler.setMapEditor( this );
1406 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1407 if (undoSel.isEmpty())
1411 handler.setLoadMode (NewMap);
1415 handler.setLoadMode (ImportReplace);
1417 blockReposition=true;
1418 bool ok = reader.parse( source );
1419 blockReposition=false;
1422 // This should never ever happen
1423 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1424 handler.errorProtocol());
1427 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1430 void MapEditor::addMapInsert(const QString &path, int pos)
1432 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1433 typeid(*selection) == typeid(MapCenterObj)))
1435 QString pathDir=path.left(path.findRev("/"));
1439 BranchObj *bo=addNewBranchInt (pos);
1443 QMessageBox::critical( 0, tr( "Critical Error" ),
1444 tr("Could insert branch at position %1\n in branch %2").arg(pos)
1445 .arg(((BranchObj*)selection)->getHeading()));
1450 selection->select();
1455 // We need to parse saved XML data
1456 mapBuilderHandler handler;
1457 QXmlInputSource source( file);
1458 QXmlSimpleReader reader;
1459 reader.setContentHandler( &handler );
1460 reader.setErrorHandler( &handler );
1461 handler.setMapEditor( this );
1462 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
1463 handler.setLoadMode (ImportReplace);
1464 blockReposition=true;
1465 bool ok = reader.parse( source );
1466 blockReposition=false;
1469 // This should never ever happen
1470 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
1471 handler.errorProtocol());
1474 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
1478 void MapEditor::pasteNoSave()
1480 load (clipboardDir+"/part.xml",ImportAdd);
1483 void MapEditor::cutNoSave()
1489 void MapEditor::paste()
1491 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1492 typeid(*selection) == typeid(MapCenterObj)))
1494 saveStateChangingPart(selection,QString("Paste to %1").arg( getName(selection)));
1496 mapCenter->reposition();
1501 void MapEditor::cut()
1503 saveStateChangingPart(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
1506 mapCenter->reposition();
1510 void MapEditor::move(const int &x, const int &y)
1514 QString ps=qpointToString (selection->getAbsPos());
1515 QString s=selection->getSelectString();
1518 s, "move "+qpointToString (QPoint (x,y)),
1519 QString("Move %1 to %2").arg(getName(selection)).arg(ps));
1520 selection->move(x,y);
1521 mapCenter->reposition();
1527 void MapEditor::moveRel (const int &x, const int &y)
1529 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1530 typeid(*selection) == typeid(MapCenterObj) ||
1531 typeid(*selection) == typeid (FloatImageObj)))
1533 QString ps=qpointToString (selection->getRelPos());
1534 QString s=selection->getSelectString();
1537 s, "moveRel "+qpointToString (QPoint (x,y)),
1538 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps));
1539 ((OrnamentedObj*)selection)->move2RelPos (x,y);
1540 mapCenter->reposition();
1545 void MapEditor::moveBranchUp()
1549 if (typeid(*selection) == typeid(BranchObj) )
1551 bo=(BranchObj*)selection;
1552 if (!bo->canMoveBranchUp()) return;
1553 par=(BranchObj*)(bo->getParObj());
1554 selection->unselect();
1555 bo=par->moveBranchUp (bo); // bo will be the one below selection
1556 selection->select();
1557 saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1558 mapCenter->reposition();
1559 ensureSelectionVisible();
1563 void MapEditor::moveBranchDown()
1567 if (typeid(*selection) == typeid(BranchObj) )
1569 bo=(BranchObj*)selection;
1570 if (!bo->canMoveBranchDown()) return;
1571 par=(BranchObj*)(bo->getParObj());
1572 selection->unselect();
1573 bo=par->moveBranchDown(bo); // bo will be the one above selection
1574 selection->select();
1575 saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1576 mapCenter->reposition();
1577 ensureSelectionVisible();
1581 QString MapEditor::getHeading(bool &ok, QPoint &p)
1584 (typeid(*selection) == typeid(BranchObj) ||
1585 typeid(*selection) == typeid(MapCenterObj) ) )
1588 ensureSelectionVisible();
1589 p = ((BranchObj*)selection)->getAbsPos();
1590 p.setX (p.x() - contentsX());
1591 p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2);
1592 return ((BranchObj*)selection)->getHeading();
1598 void MapEditor::setHeading(const QString &s)
1601 (typeid(*selection) == typeid(BranchObj) ||
1602 typeid(*selection) == typeid(MapCenterObj) ) )
1604 editingBO=(BranchObj*)selection;
1605 saveStateConstSelection(
1606 "setHeading (\""+editingBO->getHeading()+"\")",
1607 "setHeading (\""+s+"\")",
1608 QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) );
1609 editingBO->setHeading(s );
1611 mapCenter->reposition();
1613 ensureSelectionVisible();
1617 void MapEditor::setURLInt (const QString &s)
1619 // Internal function, no saveState needed
1621 (typeid(*selection) == typeid(BranchObj) ||
1622 typeid(*selection) == typeid(MapCenterObj) ) )
1624 ((BranchObj*)selection)->setURL(s);
1625 mapCenter->reposition();
1627 ensureSelectionVisible();
1631 void MapEditor::setHeadingInt(const QString &s)
1634 (typeid(*selection) == typeid(BranchObj) ||
1635 typeid(*selection) == typeid(MapCenterObj) ) )
1637 ((BranchObj*)selection)->setHeading(s);
1638 mapCenter->reposition();
1640 ensureSelectionVisible();
1644 void MapEditor::setVymLinkInt (const QString &s)
1646 // Internal function, no saveState needed
1648 (typeid(*selection) == typeid(BranchObj) ||
1649 typeid(*selection) == typeid(MapCenterObj) ) )
1651 ((BranchObj*)selection)->setVymLink(s);
1652 mapCenter->reposition();
1654 ensureSelectionVisible();
1658 BranchObj* MapEditor::addNewBranchInt(int num)
1660 // Depending on pos:
1661 // -3 insert in childs of parent above selection
1662 // -2 add branch to selection
1663 // -1 insert in childs of parent below selection
1664 // 0..n insert in childs of parent at pos
1665 BranchObj *newbo=NULL;
1667 (typeid(*selection) == typeid(BranchObj) ||
1668 typeid(*selection) == typeid(MapCenterObj) ) )
1670 BranchObj* bo = (BranchObj*) selection;
1673 // save scroll state. If scrolled, automatically select
1674 // new branch in order to tmp unscroll parent...
1675 return bo->addBranch();
1680 bo=(BranchObj*)bo->getParObj();
1684 bo=(BranchObj*)bo->getParObj();
1687 newbo=bo->insertBranch(num);
1692 void MapEditor::addNewBranch(int pos)
1694 // Different meaning than num in addNewBranchInt!
1699 (typeid(*selection) == typeid(BranchObj) ||
1700 typeid(*selection) == typeid(MapCenterObj) ) )
1702 BranchObj *bo = (BranchObj*) selection;
1704 newbo=addNewBranchInt (pos-2);
1708 saveStateConstSelection (
1709 //QString ("delete (\"%1\")").arg(newbo->getSelectString()),
1711 QString ("addBranch (%1)").arg(pos-2),
1712 QString ("Add new branch to %1").arg(getName(bo))); //TODO undoCommand
1714 LinkableMapObj *oldselection=selection;
1716 mapCenter->reposition();
1720 if (mainWindow->autoEdit() ||
1721 mainWindow->autoSelectHeading() )
1723 selection->unselect();
1725 selection->select();
1726 if (mainWindow->autoEdit() )
1727 mainWindow->editHeading();
1728 if (!mainWindow->autoSelectHeading()
1729 )//&& !wasScrolled) //FIXME wasScrolled was moved to addNewBranchInt
1731 selection->unselect();
1732 selection=oldselection;
1733 selection->select();
1741 void MapEditor::addNewBranchHere()
1744 (typeid(*selection) == typeid(BranchObj) ) )
1746 BranchObj* bo1 = (BranchObj*) selection;
1747 saveStateChangingPart(selection, QString("Add new branch here").arg(getName(bo1)));
1749 bool wasScrolled=false;
1750 BranchObj *newbo=NULL;
1751 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1754 // add below selection
1755 newbo=parbo->insertBranch(bo1->getNum()+1);
1758 LinkableMapObj *oldselection=selection;
1759 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1761 mapCenter->reposition();
1763 if (mainWindow->autoEdit() ||
1764 mainWindow->autoSelectHeading() )
1766 selection->unselect();
1768 selection->select();
1769 if (mainWindow->autoEdit() )
1770 mainWindow->editHeading();
1771 if (!mainWindow->autoSelectHeading()
1774 selection->unselect();
1775 selection=oldselection;
1776 selection->select();
1782 void MapEditor::deleteSelection()
1784 if (selection && typeid(*selection) ==typeid(BranchObj) )
1786 BranchObj* bo=(BranchObj*)selection;
1787 BranchObj* par=(BranchObj*)(bo->getParObj());
1789 if (selection->getDepth()>1)
1790 // Normal branch, save parent with childs
1791 saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
1793 // Mainbranch, save whole map
1794 // TODO Better would be to insert mainbranch again at pos But undoCommand is missing right now
1795 saveStateComplete(QString("Delete %1").arg(getName(bo)));
1797 par->removeBranch(bo);
1799 selection->select();
1800 ensureSelectionVisible();
1801 mapCenter->reposition();
1804 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1806 FloatImageObj* fio=(FloatImageObj*)selection;
1807 BranchObj* par=(BranchObj*)(fio->getParObj());
1808 saveStateChangingPart(par, QString("Delete %1").arg(getName(fio)));
1811 par->removeFloatImage(fio);
1813 selection->select();
1814 ensureSelectionVisible();
1815 mapCenter->reposition();
1820 LinkableMapObj* MapEditor::getSelection()
1825 void MapEditor::unselect()
1829 selectionLast=selection;
1830 selection->unselect();
1835 void MapEditor::reselect()
1839 selection=selectionLast;
1840 selection->select();
1845 bool MapEditor::select (const QString &s)
1847 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1849 // Finally select the found object
1852 if (selection) unselect();
1854 selection->select();
1856 ensureSelectionVisible();
1862 QString MapEditor::getSelectString()
1864 if (selection) return selection->getSelectString();
1868 void MapEditor::selectInt (LinkableMapObj *lmo)
1870 if (lmo && selection != lmo)
1872 // select the MapObj
1873 if (selection) selection->unselect();
1875 selection->select();
1881 void MapEditor::selectNextBranchInt()
1883 // Increase number of branch
1886 QString s=selection->getSelectString();
1892 part=s.section(",",-1);
1894 num=part.right(part.length() - 3);
1896 s=s.left (s.length() -num.length());
1899 num=QString ("%1").arg(num.toUInt()+1);
1903 // Try to select this one
1904 if (select (s)) return;
1906 // We have no direct successor,
1907 // try to increase the parental number in order to
1908 // find a successor with same depth
1910 int d=selection->getDepth();
1915 while (!found && d>0)
1917 s=s.section (",",0,d-1);
1918 // replace substring of current depth in s with "1"
1919 part=s.section(",",-1);
1921 num=part.right(part.length() - 3);
1925 // increase number of parent
1926 num=QString ("%1").arg(num.toUInt()+1);
1927 s=s.section (",",0,d-2) + ","+ typ+num;
1930 // Special case, look at orientation
1931 if (selection->getOrientation()==OrientRightOfCenter)
1932 num=QString ("%1").arg(num.toUInt()+1);
1934 num=QString ("%1").arg(num.toUInt()-1);
1939 // pad to oldDepth, select the first branch for each depth
1940 for (i=d;i<oldDepth;i++)
1945 if ( ((BranchObj*)selection)->countBranches()>0)
1953 // try to select the freshly built string
1961 void MapEditor::selectPrevBranchInt()
1963 // Decrease number of branch
1966 QString s=selection->getSelectString();
1972 part=s.section(",",-1);
1974 num=part.right(part.length() - 3);
1976 s=s.left (s.length() -num.length());
1979 num=QString ("%1").arg(num.toUInt()-1);
1983 // Try to select this one
1984 if (select (s)) return;
1986 // We have no direct precessor,
1987 // try to decrease the parental number in order to
1988 // find a precessor with same depth
1990 int d=selection->getDepth();
1995 while (!found && d>0)
1997 s=s.section (",",0,d-1);
1998 // replace substring of current depth in s with "1"
1999 part=s.section(",",-1);
2001 num=part.right(part.length() - 3);
2005 // decrease number of parent
2006 num=QString ("%1").arg(num.toUInt()-1);
2007 s=s.section (",",0,d-2) + ","+ typ+num;
2010 // Special case, look at orientation
2011 if (selection->getOrientation()==OrientRightOfCenter)
2012 num=QString ("%1").arg(num.toUInt()-1);
2014 num=QString ("%1").arg(num.toUInt()+1);
2019 // pad to oldDepth, select the last branch for each depth
2020 for (i=d;i<oldDepth;i++)
2024 if ( ((BranchObj*)selection)->countBranches()>0)
2025 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
2032 // try to select the freshly built string
2040 void MapEditor::selectUpperBranch()
2044 if (typeid(*selection) == typeid(BranchObj))
2046 if (selection->getOrientation()==OrientRightOfCenter)
2047 selectPrevBranchInt();
2049 if (selection->getDepth()==1)
2050 selectNextBranchInt();
2052 selectPrevBranchInt();
2057 void MapEditor::selectLowerBranch()
2061 if (typeid(*selection) == typeid(BranchObj))
2063 if (selection->getOrientation()==OrientRightOfCenter)
2064 selectNextBranchInt();
2066 if (selection->getDepth()==1)
2067 selectPrevBranchInt();
2069 selectNextBranchInt();
2075 void MapEditor::selectLeftBranch()
2081 if (typeid(*selection) == typeid(MapCenterObj))
2083 par= (BranchObj*) selection;
2084 bo=par->getLastSelectedBranch();
2087 // Workaround for reselecting on left and right side
2088 if (bo->getOrientation()==OrientRightOfCenter)
2090 bo=par->getLastBranch();
2096 selection->select();
2098 ensureSelectionVisible();
2103 par=(BranchObj*)(selection->getParObj());
2104 if (selection->getOrientation()==OrientRightOfCenter)
2106 if (typeid(*selection) == typeid(BranchObj) ||
2107 typeid(*selection) == typeid(FloatImageObj))
2109 selection->unselect();
2111 selection->select();
2113 ensureSelectionVisible();
2117 if (typeid(*selection) == typeid(BranchObj) )
2119 bo=((BranchObj*)selection)->getLastSelectedBranch();
2122 selection->unselect();
2124 selection->select();
2126 ensureSelectionVisible();
2134 void MapEditor::selectRightBranch()
2141 if (typeid(*selection) == typeid(MapCenterObj))
2143 par= (BranchObj*) selection;
2144 bo=par->getLastSelectedBranch();
2147 // Workaround for reselecting on left and right side
2148 if (bo->getOrientation()==OrientLeftOfCenter)
2149 bo=par->getFirstBranch();
2154 selection->select();
2155 ensureSelectionVisible();
2160 par=(BranchObj*)(selection->getParObj());
2161 if (selection->getOrientation()==OrientLeftOfCenter)
2163 if (typeid(*selection) == typeid(BranchObj) ||
2164 typeid(*selection) == typeid(FloatImageObj))
2166 selection->unselect();
2168 selection->select();
2170 ensureSelectionVisible();
2174 if (typeid(*selection) == typeid(BranchObj) )
2176 bo=((BranchObj*)selection)->getLastSelectedBranch();
2179 selection->unselect();
2181 selection->select();
2183 ensureSelectionVisible();
2191 void MapEditor::selectFirstBranch()
2197 if (typeid(*selection) == typeid(BranchObj))
2199 bo1= (BranchObj*) selection;
2200 par=(BranchObj*)(bo1->getParObj());
2201 bo2=par->getFirstBranch();
2205 selection->select();
2206 ensureSelectionVisible();
2213 void MapEditor::selectLastBranch()
2219 if (typeid(*selection) == typeid(BranchObj))
2221 bo1= (BranchObj*) selection;
2222 par=(BranchObj*)(bo1->getParObj());
2223 bo2=par->getLastBranch();
2227 selection->select();
2228 ensureSelectionVisible();
2235 void MapEditor::setColor(QColor c)
2240 void MapEditor::selectBackgroundColor()
2242 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2243 if ( !col.isValid() ) return;
2244 setBackgroundColor( col );
2246 saveStateComplete(QString("Set background color of map to %1").arg(col.name()));
2249 void MapEditor::setBackgroundColor(QColor c)
2251 mapCanvas->setBackgroundColor (c);
2254 QColor MapEditor::pickColor()
2258 if (typeid(*selection) == typeid(BranchObj) ||
2259 typeid(*selection) == typeid(MapCenterObj))
2261 BranchObj *bo=(BranchObj*)selection;
2262 actColor=bo->getColor();
2268 void MapEditor::colorItem()
2272 if (typeid(*selection) == typeid(BranchObj) ||
2273 typeid(*selection) == typeid(MapCenterObj))
2275 BranchObj *bo=(BranchObj*)selection;
2276 saveStateChangingPart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2277 bo->setColor(actColor); // color branch
2282 void MapEditor::colorBranch()
2286 if (typeid(*selection) == typeid(BranchObj) ||
2287 typeid(*selection) == typeid(MapCenterObj))
2289 BranchObj *bo=(BranchObj*)selection;
2290 saveStateChangingPart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2291 bo->setColorChilds(actColor); // color links, color childs
2297 void MapEditor::toggleStandardFlag(QString f)
2301 if (typeid(*selection) == typeid(BranchObj) ||
2302 typeid(*selection) == typeid(MapCenterObj))
2304 BranchObj *bo=(BranchObj*)selection;
2306 if (bo->isSetStandardFlag(f))
2316 saveStateConstSelection(QString("%1 (\"%2\")").arg(u).arg(f),
2317 QString("%1 (\"%2\")").arg(r).arg(f),
2318 QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo)));
2319 bo->toggleStandardFlag (f,mainWindow->useFlagGroups());
2325 void MapEditor::setViewCenter()
2327 // transform to CanvasView Coord:
2328 QPoint p=worldMatrix().map(movingCenter);
2329 center ( p.x(), p.y());
2333 BranchObj* MapEditor::findText (QString s, bool cs)
2335 QTextDocument::FindFlags flags=0;
2336 if (cs) flags=QTextDocument::FindCaseSensitively;
2339 { // Nothing found or new find process
2341 // nothing found, start again
2343 itFind=mapCenter->first();
2345 bool searching=true;
2346 bool foundNote=false;
2347 while (searching && !EOFind)
2351 // Searching in Note
2352 if (itFind->getNote().contains(s,cs))
2354 if (selection!=itFind)
2356 if (selection) ((BranchObj*)selection)->unselect();
2358 selection->select();
2360 ensureSelectionVisible();
2362 if (textEditor->findText(s,flags))
2368 // Searching in Heading
2369 if (searching && itFind->getHeading().contains (s,cs) )
2371 if (selection) ((BranchObj*)selection)->unselect();
2373 selection->select();
2375 ensureSelectionVisible();
2381 itFind=itFind->next();
2382 if (!itFind) EOFind=true;
2388 return (BranchObj*)selection;
2393 void MapEditor::findReset()
2394 { // Necessary if text to find changes during a find process
2399 void MapEditor::editURL()
2401 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2402 typeid(*selection) == typeid(MapCenterObj)) )
2405 BranchObj *bo=(BranchObj*)selection;
2406 QString text = QInputDialog::getText(
2407 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2408 bo->getURL(), &ok, this );
2411 // user entered something and pressed OK
2412 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2419 QString MapEditor::getURL()
2421 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2422 typeid(*selection) == typeid(MapCenterObj)) )
2423 return ((BranchObj*)selection)->getURL();
2428 QStringList MapEditor::getURLs()
2431 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2432 typeid(*selection) == typeid(MapCenterObj)) )
2434 BranchObj *bo=(BranchObj*)selection;
2438 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
2446 void MapEditor::editHeading2URL()
2448 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2449 typeid(*selection) == typeid(MapCenterObj)) )
2451 BranchObj *bo=(BranchObj*)selection;
2452 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2453 bo->setURL (bo->getHeading());
2458 void MapEditor::editBugzilla2URL()
2460 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2461 typeid(*selection) == typeid(MapCenterObj)) )
2463 BranchObj *bo=(BranchObj*)selection;
2464 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2465 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo)));
2471 void MapEditor::editFATE2URL()
2473 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2474 typeid(*selection) == typeid(MapCenterObj)) )
2476 BranchObj *bo=(BranchObj*)selection;
2477 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2478 saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2484 void MapEditor::editVymLink()
2486 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2487 typeid(*selection) == typeid(MapCenterObj)) )
2489 BranchObj *bo=(BranchObj*)selection;
2490 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map"));
2491 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2492 fd->setCaption(__VYM " - " +tr("Link to another map"));
2493 if (! bo->getVymLink().isEmpty() )
2494 fd->setSelection( bo->getVymLink() );
2498 if ( fd->exec() == QDialog::Accepted )
2500 saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2501 bo->setVymLink (fd->selectedFile() );
2503 mapCenter->reposition();
2510 void MapEditor::deleteVymLink()
2512 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2513 typeid(*selection) == typeid(MapCenterObj)) )
2515 BranchObj *bo=(BranchObj*)selection;
2516 saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2517 bo->setVymLink ("" );
2519 mapCenter->reposition();
2525 void MapEditor::toggleHideExport()
2527 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2528 typeid(*selection) == typeid(MapCenterObj)) ||
2529 (typeid(*selection)==typeid(FloatImageObj))
2532 OrnamentedObj *oo=(OrnamentedObj*)selection;
2534 if (oo->hideInExport())
2536 oo->setHideInExport(false);
2541 oo->setHideInExport(true);
2544 saveStateComplete(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2546 mapCenter->reposition();
2552 QString MapEditor::getVymLink()
2554 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2555 typeid(*selection) == typeid(MapCenterObj)) )
2557 return ((BranchObj*)selection)->getVymLink();
2563 QStringList MapEditor::getVymLinks()
2566 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2567 typeid(*selection) == typeid(MapCenterObj)) )
2569 BranchObj *bo=(BranchObj*)selection;
2573 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2581 void MapEditor::removeBranchKeepChilds()
2583 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2585 BranchObj* bo=(BranchObj*)selection;
2586 BranchObj* par=(BranchObj*)(bo->getParObj());
2587 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2588 if (bo->getDepth()==1)
2589 saveStateComplete(s);
2591 saveStateChangingPart(selection->getParObj(),s); // TODO undoCommand
2592 QString sel=selection->getSelectString();
2594 par->removeBranchHere(bo);
2595 mapCenter->reposition();
2600 void MapEditor::removeChilds()
2602 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2604 saveStateChangingPart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
2605 ((BranchObj*)selection)->removeChilds();
2606 mapCenter->reposition();
2610 void MapEditor::editMapInfo()
2612 ExtraInfoDialog dia;
2613 dia.setMapName (getFileName() );
2614 dia.setAuthor (mapCenter->getAuthor() );
2615 dia.setComment(mapCenter->getComment() );
2620 Q3CanvasItemList l=canvas()->allItems();
2621 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2623 stats+=QString ("%1 items on canvas\n").arg (i,6);
2630 bo=mapCenter->first();
2633 if (!bo->getNote().isEmpty() ) n++;
2634 f+= bo->countFloatImages();
2636 xl+=bo->countXLinks();
2639 stats+=QString ("%1 branches\n").arg (b-1,6);
2640 stats+=QString ("%1 xLinks \n").arg (xl,6);
2641 stats+=QString ("%1 notes\n").arg (n,6);
2642 stats+=QString ("%1 images\n").arg (f,6);
2643 dia.setStats (stats);
2645 // Finally show dialog
2646 if (dia.exec() == QDialog::Accepted)
2648 saveStateComplete("Edit info about map"); //TODO undoCommand
2649 mapCenter->setAuthor (dia.getAuthor() );
2650 mapCenter->setComment (dia.getComment() );
2654 void MapEditor::updateActions()
2656 mainWindow->updateActions();
2657 // FIXME maybe don't update if blockReposition is set
2660 void MapEditor::updateNoteFlag()
2663 if ( (typeid(*selection) == typeid(BranchObj)) ||
2664 (typeid(*selection) == typeid(MapCenterObj)) )
2665 ((BranchObj*)selection)->updateNoteFlag();
2668 void MapEditor::setLinkStyle (LinkStyle ls)
2672 saveStateComplete("Set link style"); // TODO undoCommand
2674 bo=mapCenter->first();
2678 bo->setLinkStyle(bo->getDefLinkStyle());
2681 mapCenter->reposition();
2684 LinkStyle MapEditor::getLinkStyle ()
2689 void MapEditor::setLinkColor(QColor c)
2695 void MapEditor::setLinkColorHint()
2697 // called from setLinkColorHint(lch) or at end of parse
2699 bo=mapCenter->first();
2707 void MapEditor::setLinkColorHint(LinkColorHint lch)
2713 void MapEditor::toggleLinkColorHint()
2715 if (linkcolorhint==HeadingColor)
2716 linkcolorhint=DefaultColor;
2718 linkcolorhint=HeadingColor;
2720 bo=mapCenter->first();
2728 LinkColorHint MapEditor::getLinkColorHint()
2730 return linkcolorhint;
2733 QColor MapEditor::getDefLinkColor()
2735 return defLinkColor;
2738 void MapEditor::setDefXLinkColor(QColor col)
2743 QColor MapEditor::getDefXLinkColor()
2745 return defXLinkColor;
2748 void MapEditor::setDefXLinkWidth (int w)
2753 int MapEditor::getDefXLinkWidth()
2755 return defXLinkWidth;
2758 void MapEditor::selectLinkColor()
2760 QColor col = QColorDialog::getColor( defLinkColor, this );
2761 if ( !col.isValid() ) return;
2762 setLinkColor( col );
2763 saveStateComplete(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2767 void MapEditor::toggleScroll()
2769 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2771 BranchObj *bo=((BranchObj*)selection);
2772 if (bo->countBranches()==0) return;
2773 if (bo->getDepth()==0) return;
2775 if (bo->isScrolled())
2779 saveStateChangingPart(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2786 void MapEditor::unScrollAll()
2789 bo=mapCenter->first();
2792 if (bo->isScrolled()) bo->toggleScroll();
2797 void MapEditor::loadFloatImage ()
2800 (typeid(*selection) == typeid(BranchObj)) ||
2801 (typeid(*selection) == typeid(MapCenterObj)) )
2803 BranchObj *bo=((BranchObj*)selection);
2805 Q3FileDialog *fd=new Q3FileDialog( this);
2806 fd->setMode (Q3FileDialog::ExistingFiles);
2807 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2808 ImagePreview *p =new ImagePreview (fd);
2809 fd->setContentsPreviewEnabled( TRUE );
2810 fd->setContentsPreview( p, p );
2811 fd->setPreviewMode( Q3FileDialog::Contents );
2812 fd->setCaption(__VYM " - " +tr("Load image"));
2813 fd->setDir (lastImageDir);
2817 if ( fd->exec() == QDialog::Accepted )
2819 saveStateChangingPart(selection, QString("Add floatimage to %1").arg(getName(selection)));
2820 // FIXME in QT4 use: lastImageDir=fd->directory();
2821 lastImageDir=QDir (fd->dirPath());
2822 QStringList flist = fd->selectedFiles();
2823 QStringList::Iterator it = flist.begin();
2824 while( it != flist.end() )
2827 bo->addFloatImage();
2828 // TODO check if load was successful
2829 bo->getLastFloatImage()->load(*it);
2830 bo->getLastFloatImage()->setOriginalFilename(fn);
2834 mapCenter->reposition();
2843 void MapEditor::saveFloatImage ()
2846 (typeid(*selection) == typeid(FloatImageObj)) )
2848 FloatImageObj *fio=((FloatImageObj*)selection);
2849 QFileDialog *fd=new QFileDialog( this);
2850 fd->setFilters (imageIO.getFilters());
2851 fd->setCaption(__VYM " - " +tr("Save image"));
2852 fd->setFileMode( QFileDialog::AnyFile );
2853 fd->setDirectory (lastImageDir);
2854 // fd->setSelection (fio->getOriginalFilename());
2858 if ( fd->exec() == QDialog::Accepted )
2860 if (QFile (fd->selectedFile()).exists() )
2862 QMessageBox mb( __VYM,
2863 tr("The file %1 exists already.\n"
2864 "Do you want to overwrite it?").arg(fd->selectedFile()),
2865 QMessageBox::Warning,
2866 QMessageBox::Yes | QMessageBox::Default,
2867 QMessageBox::Cancel | QMessageBox::Escape,
2868 QMessageBox::QMessageBox::NoButton );
2870 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2871 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2874 case QMessageBox::Yes:
2877 case QMessageBox::Cancel:
2884 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
2890 void MapEditor::setFrame(const FrameType &t)
2893 (typeid(*selection) == typeid(BranchObj)) ||
2894 (typeid(*selection) == typeid(MapCenterObj)) )
2896 selection->setFrameType (t);
2897 mapCenter->reposition();
2898 selection->updateLink();
2902 void MapEditor::setIncludeImagesVer(bool b)
2905 (typeid(*selection) == typeid(BranchObj)) ||
2906 (typeid(*selection) == typeid(MapCenterObj)) )
2907 ((BranchObj*)selection)->setIncludeImagesVer(b);
2908 mapCenter->reposition();
2911 void MapEditor::setIncludeImagesHor(bool b)
2914 (typeid(*selection) == typeid(BranchObj)) ||
2915 (typeid(*selection) == typeid(MapCenterObj)) )
2916 ((BranchObj*)selection)->setIncludeImagesHor(b);
2917 mapCenter->reposition();
2920 void MapEditor::setHideLinkUnselected (bool b)
2923 (typeid(*selection) == typeid(BranchObj)) ||
2924 (typeid(*selection) == typeid(MapCenterObj)) ||
2925 (typeid(*selection) == typeid(FloatImageObj)) )
2926 selection->setHideLinkUnselected(b);
2929 void MapEditor::importDirInt(BranchObj *dst, QDir d)
2932 (typeid(*selection) == typeid(BranchObj)) ||
2933 (typeid(*selection) == typeid(MapCenterObj)) )
2937 // Traverse directories
2938 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2939 QFileInfoList list = d.entryInfoList();
2942 for (int i = 0; i < list.size(); ++i)
2945 if (fi.fileName() != "." && fi.fileName() != ".." )
2948 bo=dst->getLastBranch();
2949 bo->setHeading (fi.fileName() );
2950 bo->setColor (QColor("blue"));
2952 if ( !d.cd(fi.fileName()) )
2953 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
2956 // Recursively add subdirs
2957 importDirInt (bo,d);
2963 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2964 list = d.entryInfoList();
2966 for (int i = 0; i < list.size(); ++i)
2970 bo=dst->getLastBranch();
2971 bo->setHeading (fi.fileName() );
2972 bo->setColor (QColor("black"));
2973 if (fi.fileName().right(4) == ".vym" )
2974 bo->setVymLink (fi.filePath());
2979 void MapEditor::importDir()
2982 (typeid(*selection) == typeid(BranchObj)) ||
2983 (typeid(*selection) == typeid(MapCenterObj)) )
2985 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
2986 fd->setMode (Q3FileDialog::DirectoryOnly);
2987 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2988 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
2992 if ( fd->exec() == QDialog::Accepted )
2994 BranchObj *bo=((BranchObj*)selection);
2995 importDirInt (bo,QDir(fd->selectedFile()) );
2996 mapCenter->reposition();
3003 void MapEditor::followXLink(int i)
3006 (typeid(*selection) == typeid(BranchObj)) ||
3007 (typeid(*selection) == typeid(MapCenterObj)) )
3009 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3012 selection->unselect();
3014 selection->select();
3015 ensureSelectionVisible();
3020 void MapEditor::editXLink(int i)
3023 (typeid(*selection) == typeid(BranchObj)) ||
3024 (typeid(*selection) == typeid(MapCenterObj)) )
3026 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3029 EditXLinkDialog dia;
3031 dia.setSelection(selection);
3032 if (dia.exec() == QDialog::Accepted)
3034 if (dia.useSettingsGlobal() )
3036 setDefXLinkColor (xlo->getColor() );
3037 setDefXLinkWidth (xlo->getWidth() );
3039 if (dia.deleteXLink())
3040 ((BranchObj*)selection)->deleteXLinkAt(i);
3041 saveStateComplete("Edit xLink"); //TODO undoCommand
3047 void MapEditor::testFunction()
3049 cout << "MapEditor::testFunction() called\n";
3052 dia.showCancelButton (true);
3053 dia.setText("This is a longer \nWarning");
3055 dia.setCaption("Warning: Flux problem");
3056 dia.setShowAgainName("/warnings/mapeditor");
3058 if (dia.exec()==QDialog::Accepted)
3059 cout << "accepted!\n";
3061 cout << "canceled!\n";
3064 /* Hide hidden stuff temporary, maybe add this as regular function somewhere
3065 if (hidemode==HideNone)
3067 setHideTmpMode (HideExport);
3068 mapCenter->calcBBoxSizeWithChilds();
3069 QRect totalBBox=mapCenter->getTotalBBox();
3070 QRect mapRect=totalBBox;
3071 QCanvasRectangle *frame=NULL;
3073 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3075 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3076 totalBBox.width(), totalBBox.height());
3077 frame=new QCanvasRectangle (mapRect,mapCanvas);
3078 frame->setBrush (QColor(white));
3079 frame->setPen (QColor(black));
3085 setHideTmpMode (HideNone);
3087 cout <<" hidemode="<<hidemode<<endl;
3091 void MapEditor::ensureSelectionVisible()
3095 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3097 if (selection->getOrientation() == OrientLeftOfCenter)
3098 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3100 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3101 ensureVisible (p.x(), p.y() );
3106 void MapEditor::updateViewCenter()
3108 // Update movingCenter, so that we can zoom comfortably later
3109 QRect rc = QRect( contentsX(), contentsY(),
3110 visibleWidth(), visibleHeight() );
3111 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3112 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3113 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3116 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3118 // Lineedits are already closed by preceding
3119 // mouseEvent, we don't need to close here.
3121 QPoint p = inverseWorldMatrix().map(e->pos());
3122 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3125 { // MapObj was found
3126 if (selection != lmo)
3128 // select the MapObj
3129 if (selection) selection->unselect();
3131 selection->select();
3137 if (typeid(*selection)==typeid(BranchObj) ||
3138 typeid(*selection)==typeid(MapCenterObj) )
3140 // Context Menu on branch or mapcenter
3142 branchContextMenu->popup(e->globalPos() );
3144 if (typeid(*selection)==typeid(FloatImageObj))
3146 // Context Menu on floatimage
3148 floatimageContextMenu->popup(e->globalPos() );
3152 { // No MapObj found, we are on the Canvas itself
3153 // Context Menu on Canvas
3155 canvasContextMenu->popup(e->globalPos() );
3160 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3162 // Ignore right clicks, these will go to context menus
3163 if (e->button() == Qt::RightButton )
3169 QPoint p = inverseWorldMatrix().map(e->pos());
3170 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3174 //Take care of clickdesystem flags _or_ modifier modes
3176 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3177 typeid(*lmo)==typeid(MapCenterObj) ))
3179 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3180 if (!foname.isEmpty())
3182 // systemFlag clicked
3186 if (e->state() & Qt::ControlModifier)
3187 mainWindow->editOpenURLTab();
3189 mainWindow->editOpenURL();
3191 else if (foname=="vymLink")
3193 mainWindow->editOpenVymLink();
3194 // tabWidget may change, better return now
3195 // before segfaulting...
3196 } else if (foname=="note")
3197 mainWindow->windowToggleNoteEditor();
3198 else if (foname=="hideInExport")
3203 // No system flag clicked, take care of modmodes
3205 // Special case: CTRL is pressed
3206 if (e->state() & Qt::ControlModifier)
3208 if (mainWindow->getModMode()==ModModeColor)
3211 setCursor (pickColorCursor);
3214 if (mainWindow->getModMode()==ModModeXLink)
3216 BranchObj *bo_begin=NULL;
3218 bo_begin=(BranchObj*)(lmo);
3221 ((typeid(*selection) == typeid(BranchObj)) ||
3222 (typeid(*selection) == typeid(MapCenterObj))) )
3223 bo_begin=(BranchObj*)selection;
3227 linkingObj_src=bo_begin;
3228 tmpXLink=new XLinkObj (mapCanvas);
3229 tmpXLink->setBegin (bo_begin);
3230 tmpXLink->setEnd (p);
3231 tmpXLink->setColor(defXLinkColor);
3232 tmpXLink->setWidth(defXLinkWidth);
3233 tmpXLink->updateXLink();
3234 tmpXLink->setVisibility (true);
3242 // Left Button Move Branches
3243 if (e->button() == Qt::LeftButton )
3245 movingObj_start.setX( p.x() - selection->x() );
3246 movingObj_start.setY( p.y() - selection->y() );
3247 movingObj_orgPos.setX (lmo->x() );
3248 movingObj_orgPos.setY (lmo->y() );
3249 movingObj_orgRelPos=lmo->getRelPos();
3251 // If modMode==copy, then we want to "move" the _new_ object around
3252 // then we need the offset from p to the _old_ selection, because of tmp
3253 if (mainWindow->getModMode()==ModModeCopy &&
3254 e->state() & Qt::ControlModifier)
3256 if (typeid(*selection)==typeid(BranchObj) )
3259 mapCenter->addBranch ((BranchObj*)selection);
3261 selection=mapCenter->getLastBranch();
3262 selection->select();
3263 mapCenter->reposition();
3266 movingObj=selection;
3268 // Middle Button Toggle Scroll
3269 // (On Mac OS X this won't work, but we still have
3270 // a button in the toolbar)
3271 if (e->button() == Qt::MidButton )
3275 { // No MapObj found, we are on the Canvas itself
3276 // Left Button move Pos of CanvasView
3277 if (e->button() == Qt::LeftButton )
3279 movingObj=NULL; // move Content not Obj
3280 movingObj_start=e->globalPos();
3281 movingCont_start=QPoint (contentsX(), contentsY() );
3282 movingVec=QPoint(0,0);
3283 setCursor(handOpenCursor);
3288 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3290 QPoint p = inverseWorldMatrix().map(e->pos());
3292 // Move the selected MapObj
3293 if ( selection && movingObj)
3295 // To avoid jumping of the CanvasView, only
3296 // ensureSelectionVisible, if not tmp linked
3297 if (!selection->hasParObjTmp())
3298 ensureSelectionVisible ();
3300 // Now move the selection, but add relative position
3301 // (movingObj_start) where selection was chosen with
3302 // mousepointer. (This avoids flickering resp. jumping
3303 // of selection back to absPos)
3305 LinkableMapObj *lmosel;
3306 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3308 // Check if we could link
3309 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3312 if (typeid(*selection) == typeid(FloatImageObj))
3314 FloatObj *fo=(FloatObj*)selection;
3315 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3319 // Relink float to new mapcenter or branch, if shift is pressed
3320 // Only relink, if selection really has a new parent
3321 if ( (e->modifiers()==Qt::ShiftModifier) && lmo &&
3322 ( (typeid(*lmo)==typeid(BranchObj)) ||
3323 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3324 ( lmo != fo->getParObj())
3327 if (typeid(*fo) == typeid(FloatImageObj))
3330 saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3331 FloatImageObj *fio=(FloatImageObj*)(fo);
3332 ((BranchObj*)(lmo))->addFloatImage (fio);
3334 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3335 fio=((BranchObj*)(lmo))->getLastFloatImage();
3338 selection=(LinkableMapObj*)(fio);
3339 selection->select();
3340 movingObj=(MapObj*)(fio);
3344 { // selection != a FloatObj
3345 if (lmosel->getDepth()==0)
3348 if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3349 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3351 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3352 mapCenter->updateRelPositions();
3355 if (lmosel->getDepth()==1)
3358 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3359 lmosel->setRelPos();
3362 // Move ordinary branch
3363 if (lmosel->getOrientation() == OrientLeftOfCenter)
3364 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3365 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3366 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3368 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3370 // reposition subbranch
3371 lmosel->reposition();
3373 if (lmo && (lmo!=selection) &&
3374 (typeid(*lmo) == typeid(BranchObj) ||
3375 (typeid(*lmo) == typeid(MapCenterObj) )
3378 if (e->modifiers()==Qt::ControlModifier)
3380 // Special case: CTRL to link below lmo
3381 lmosel->setParObjTmp (lmo,p,+1);
3383 else if (e->modifiers()==Qt::ShiftModifier)
3384 lmosel->setParObjTmp (lmo,p,-1);
3386 lmosel->setParObjTmp (lmo,p,0);
3389 lmosel->unsetParObjTmp();
3393 } // no FloatImageObj
3397 } // selection && moving_obj
3399 // Draw a link from one branch to another
3402 tmpXLink->setEnd (p);
3403 tmpXLink->updateXLink();
3407 if (!movingObj && !pickingColor &&!drawingLink)
3409 QPoint p=e->globalPos();
3410 movingVec.setX(-p.x() + movingObj_start.x() );
3411 movingVec.setY(-p.y() + movingObj_start.y() );
3412 setContentsPos( movingCont_start.x() + movingVec.x(),
3413 movingCont_start.y() + movingVec.y());
3420 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3422 LinkableMapObj *dst;
3423 // Have we been picking color?
3427 setCursor (Qt::ArrowCursor);
3428 // Check if we are over another branch
3429 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3430 if (dst && selection)
3432 if (e->state() & Qt::ShiftModifier)
3434 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3435 ((BranchObj*)selection)->setLinkColor ();
3439 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3440 ((BranchObj*)selection)->setLinkColor ();
3446 // Have we been drawing a link?
3450 // Check if we are over another branch
3451 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3452 if (dst && selection)
3454 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3455 tmpXLink->updateXLink();
3456 tmpXLink->activate();
3457 saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3466 // Have we been moving something?
3467 if ( selection && movingObj )
3469 if(typeid(*selection)==typeid (FloatImageObj))
3471 // Moved FloatObj. Maybe we need to reposition
3472 FloatImageObj *fo=(FloatImageObj*)selection;
3473 QString pold=qpointToString(movingObj_orgRelPos);
3474 QString pnow=qpointToString(fo->getRelPos());
3475 saveStateConstSelection(
3478 QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow));
3480 // FIXME Why calling parObj here?
3481 selection->getParObj()->requestReposition();
3482 mapCenter->reposition();
3485 // Check if we are over another branch, but ignore
3486 // any found LMOs, which are FloatObjs
3487 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3488 ((LinkableMapObj*)selection) );
3490 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3493 if (typeid(*selection) == typeid(MapCenterObj) )
3494 { // The MapCenter was moved
3495 cout << "FIXME missing savestate...\n";
3498 if (typeid(*selection) == typeid(BranchObj) )
3499 { // A branch was moved
3501 // save the position in case we link to mapcenter
3502 QPoint savePos=QPoint (selection->x(),selection->y() );
3504 // Reset the temporary drawn link to the original one
3505 ((LinkableMapObj*)selection)->unsetParObjTmp();
3507 // For Redo we may need to save original selection
3508 QString preSelStr=selection->getSelectString();
3513 BranchObj* bsel=(BranchObj*)selection;
3514 BranchObj* bdst=(BranchObj*)dst;
3516 QString preParStr=(bsel->getParObj())->getSelectString();
3517 QString preNum=QString::number (bsel->getNum(),10);
3518 QString preDstParStr;
3520 if (e->state() & Qt::ShiftModifier && dst->getParObj())
3522 preDstParStr=dst->getParObj()->getSelectString();
3523 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
3525 if (e->state() & Qt::ControlModifier && dst->getParObj())
3528 preDstParStr=dst->getParObj()->getSelectString();
3529 bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
3532 preDstParStr=dst->getSelectString();
3533 bsel->moveBranchTo (bdst,-1);
3534 if (dst->getDepth()==0) bsel->move (savePos);
3536 QString postSelStr=selection->getSelectString();
3537 QString postNum=QString::number (bsel->getNum(),10);
3539 QString undoCom="linkBranchToPos (\""+
3540 preParStr+ "\"," + preNum +"," +
3541 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
3543 QString redoCom="linkBranchToPos (\""+
3544 preDstParStr + "\"," + postNum + "," +
3545 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
3550 QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) );
3552 if (selection->getDepth()==1)
3554 // The select string might be different _after_ moving around.
3555 // Therefor reposition and then use string of old selection, too
3556 mapCenter->reposition();
3558 QString ps=qpointToString ( ((BranchObj*)selection)->getRelPos() );
3560 selection->getSelectString(), "moveRel "+qpointToString(movingObj_orgRelPos),
3561 preSelStr, "moveRel "+ps,
3562 QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps));
3565 // Draw the original link, before selection was moved around
3566 mapCenter->reposition();
3568 // Finally resize canvas, if needed
3573 // Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
3576 // maybe we moved View: set old cursor
3577 setCursor (Qt::ArrowCursor);
3581 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3583 if (e->button() == Qt::LeftButton )
3585 QPoint p = inverseWorldMatrix().map(e->pos());
3586 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3587 if (lmo) { // MapObj was found
3588 // First select the MapObj than edit heading
3589 if (selection) selection->unselect();
3591 selection->select();
3592 mainWindow->editHeading();
3597 void MapEditor::resizeEvent (QResizeEvent* e)
3599 Q3CanvasView::resizeEvent( e );
3603 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3606 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3607 // cerr << event->format(i) << endl;
3610 (typeid(*selection) == typeid(BranchObj)) ||
3611 (typeid(*selection) == typeid(MapCenterObj))) {
3613 // If QImageDrag can decode mime type
3614 if (Q3ImageDrag::canDecode(event)) {
3619 // If image are dragged from firefox
3620 if (event->provides("application/x-moz-file-promise-url") &&
3621 event->provides("application/x-moz-nativeimage")) {
3622 event->accept(true);
3626 // If QUriDrag can decode mime type
3627 if (Q3UriDrag::canDecode(event)) {
3632 // If Uri are dragged from firefox
3633 if (event->provides("_NETSCAPE_URL")){
3638 // If QTextDrag can decode mime type
3639 if (Q3TextDrag::canDecode(event)) {
3648 bool isUnicode16(const QByteArray &d)
3650 // TODO: make more precise check for unicode 16.
3651 // Guess unicode16 if any of second bytes are zero
3652 unsigned int length = max(0,d.size()-2)/2;
3653 for (unsigned int i = 0; i<length ; i++)
3654 if (d.at(i*2+1)==0) return true;
3658 void MapEditor::contentsDropEvent(QDropEvent *event)
3661 (typeid(*selection) == typeid(BranchObj)) ||
3662 (typeid(*selection) == typeid(MapCenterObj)))
3667 if (event->provides("image/png"))
3670 if (Q3ImageDrag::decode(event, pix))
3678 } else if (event->provides("application/x-moz-file-promise-url") &&
3679 event->provides("application/x-moz-nativeimage"))
3681 // Contains url to the img src in unicode16
3682 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3683 QString url = QString((const QChar*)d.data(),d.size()/2);
3687 } else if (event->provides ("text/uri-list"))
3688 { // Uris provided e.g. by konqueror
3689 Q3UriDrag::decode (event,uris);
3690 } else if (event->provides ("_NETSCAPE_URL"))
3691 { // Uris provided by Mozilla
3692 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3695 } else if (event->provides("text/html")) {
3697 // Handels text mime types
3698 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3699 QByteArray d = event->encodedData("text/html");
3702 text = QString((const QChar*)d.data(),d.size()/2);
3706 textEditor->setText(text);
3710 } else if (event->provides("text/plain")) {
3711 QByteArray d = event->encodedData("text/plain");
3714 text = QString((const QChar*)d.data(),d.size()/2);
3718 textEditor->setText(text);
3730 for (const char* u=uris.first(); u; u=uris.next())
3732 bo=((BranchObj*)selection)->addBranch();
3735 s=Q3UriDrag::uriToLocalFile(u);
3738 QString file = QDir::convertSeparators(s);
3739 heading = QFileInfo(file).baseName();
3741 if (file.endsWith(".vym", false))
3742 bo->setVymLink(file);
3751 if (!heading.isEmpty())
3752 bo->setHeading(heading);
3762 //FIXME saveState has to be called earlier for each of the drops...
3763 saveStateComplete("Drop Event"); //TODO undo Command
3764 mapCenter->reposition();
3771 void MapEditor::addFloatImage(const QPixmap &img)
3774 (typeid(*selection) == typeid(BranchObj)) ||
3775 (typeid(*selection) == typeid(MapCenterObj)) )
3777 BranchObj *bo=((BranchObj*)selection);
3778 saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
3779 //QString fn=fd->selectedFile();
3780 //lastImageDir=fn.left(fn.findRev ("/"));
3781 bo->addFloatImage();
3782 // FIXME check if load was successful
3783 bo->getLastFloatImage()->load(img);
3784 //bo->getLastFloatImage()->setOriginalFilename(fn);
3785 mapCenter->reposition();
3792 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
3794 if (!imageBuffer) imageBuffer = new QBuffer();
3795 if (!imageBuffer->isOpen()) {
3796 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3798 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3802 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3804 if (nop->state()==Q3NetworkProtocol::StDone) {
3805 QPixmap img(imageBuffer->buffer());
3810 imageBuffer->close();
3812 imageBuffer->close();
3819 void MapEditor::fetchImage(const QString &url)
3822 urlOperator->stop();
3823 disconnect(urlOperator);
3827 urlOperator = new Q3UrlOperator(url);
3828 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
3829 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
3831 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
3832 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));