3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <qpopupmenu.h>
9 #include <qpaintdevicemetrics.h>
11 #include <qfiledialog.h>
14 #include <qcolordialog.h>
17 #include <qinputdialog.h>
18 #include <qdragobject.h>
19 #include <qurloperator.h>
20 #include <qnetworkprotocol.h>
30 #include "editxlinkdialog.h"
32 #include "extrainfodialog.h"
34 #include "linkablemapobj.h"
35 #include "mainwindow.h"
38 #include "texteditor.h"
39 #include "warningdialog.h"
43 extern TextEditor *textEditor;
44 extern int statusbarTime;
45 extern Main *mainWindow;
46 extern QString tmpVymDir;
47 extern QString clipboardDir;
48 extern bool clipboardEmpty;
49 extern FlagRowObj *systemFlagsDefault;
50 extern FlagRowObj *standardFlagsDefault;
52 extern QPtrList <QAction> actionListBranches;
54 extern QAction *actionFileSave;
55 extern QAction *actionEditUndo;
56 extern QAction *actionEditCopy;
57 extern QAction *actionEditCut;
58 extern QAction *actionEditPaste;
59 extern QAction *actionEditMoveUp;
60 extern QAction *actionEditMoveDown;
61 extern QAction *actionEditToggleScroll;
62 extern QAction *actionEditOpenURL;
63 extern QAction *actionEditOpenURLTab;
64 extern QAction *actionEditURL;
65 extern QAction *actionEditHeading2URL;
66 extern QAction *actionEditBugzilla2URL;
67 extern QAction *actionEditFATE2URL;
68 extern QAction *actionEditOpenVymLink;
69 extern QAction *actionEditVymLink;
70 extern QAction *actionEditDeleteVymLink;
71 extern QAction *actionEditToggleHideExport;
72 extern QAction *actionEditHeading;
73 extern QAction *actionEditDelete;
74 extern QAction *actionEditAddBranch;
75 extern QAction *actionEditAddBranchAbove;
76 extern QAction *actionEditAddBranchBelow;
77 extern QAction *actionEditRemoveBranchHere;
78 extern QAction *actionEditRemoveChilds;
79 extern QAction *actionEditImportAdd;
80 extern QAction *actionEditImportReplace;
81 extern QAction *actionEditSaveBranch;
82 extern QAction *actionEditSelectFirst;
83 extern QAction *actionEditSelectLast;
84 extern QAction *actionEditLoadImage;
86 extern QAction* actionFormatPickColor;
87 extern QAction* actionFormatColorBranch;
88 extern QAction* actionFormatColorSubtree;
89 extern QAction *actionFormatLinkColorHint;
90 extern QAction *actionFormatBackColor;
91 extern QAction *actionFormatLinkColor;
93 extern QActionGroup* actionGroupModModes;
94 extern QAction* actionModModeColor;
95 extern QAction* actionModModeLink;
96 extern QAction* actionModModeCopy;
98 extern QActionGroup *actionGroupFormatFrameTypes;
99 extern QAction *actionFormatFrameNone;
100 extern QAction *actionFormatFrameRectangle;
102 extern QActionGroup *actionGroupFormatLinkStyles;
103 extern QAction *actionFormatIncludeImagesVer;
104 extern QAction *actionFormatIncludeImagesHor;
105 extern QAction *actionFormatHideLinkUnselected;
106 extern QAction *actionFormatLinkStyleLine;
107 extern QAction *actionFormatLinkStyleParabel;
108 extern QAction *actionFormatLinkStylePolyLine;
109 extern QAction *actionFormatLinkStylePolyParabel;
111 extern QAction *actionViewToggleNoteEditor;
113 extern QAction *actionSettingsAutoedit;
114 extern QAction *actionSettingsAutoselectHeading;
115 extern QAction *actionSettingsAutoselectText;
116 extern QAction *actionSettingsPasteNewHeading;
117 extern QAction *actionSettingsUseFlagGroups;
119 extern QPopupMenu *branchContextMenu;
120 extern QPopupMenu *branchLinksContextMenu;
121 extern QPopupMenu *branchLinksContextMenuDup;
122 extern QPopupMenu *floatimageContextMenu;
123 extern QPopupMenu *saveImageFormatMenu;
124 extern QPopupMenu *exportImageFormatMenu;
125 extern QPopupMenu *canvasContextMenu;
127 extern Settings settings;
129 extern QString iconPath;
130 extern QDir vymBaseDir;
132 int MapEditor::mapNum=0; // make instance
134 ///////////////////////////////////////////////////////////////////////
135 ///////////////////////////////////////////////////////////////////////
136 MapEditor::MapEditor(
137 QWidget* parent, bool interactive, const char* name, WFlags f) :
138 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
140 //cout << "Constructor ME "<<this<<endl;
143 viewport()->setAcceptDrops(true);
145 mapCanvas = new QCanvas(1000,800);
146 mapCanvas->setAdvancePeriod(30);
147 mapCanvas->setBackgroundColor (white);
149 setCanvas (mapCanvas);
151 // Always show scroll bars (automatic would flicker sometimes)
152 setVScrollBarMode ( QScrollView::AlwaysOn );
153 setHScrollBarMode ( QScrollView::AlwaysOn );
155 mapCenter = new MapCenterObj(mapCanvas);
156 mapCenter->setVisibility (true);
157 mapCenter->setMapEditor (this);
158 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
159 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
163 lineedit = new QLineEdit(this, "lineedit" );
164 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEdit() ) );
167 actColor=black; setColor (actColor);
168 defLinkColor=QColor (0,0,255);
169 defXLinkColor=QColor (180,180,180);
170 linkcolorhint=DefaultColor;
171 linkstyle=StylePolyParabel;
173 // Create bitmap cursors, patform dependant
174 #if defined(Q_OS_MACX)
175 handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png") );
176 // set hot spot to tip of picker
177 pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 );
179 handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen16.png"));
180 // set hot spot to tip of picker
181 pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
194 defXLinkColor=QColor (230,230,230);
202 fileName=tr("unnamed");
205 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
209 // Initialize find routine
216 blockReposition=false;
217 blockSaveState=false;
221 isInteractive=interactive;
223 // Create temporary files
226 // Initially set movingCentre
229 // For testing purposes create history window
230 historyWindow = new ShowTextDialog (this);
231 historyWindow->setCaption (fileName);
233 mapCenter->reposition(); // for positioning heading
236 MapEditor::~MapEditor()
238 if (imageBuffer) delete imageBuffer;
244 //cout <<"Destructor MapEditor\n";
247 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
251 QColor MapEditor::color()
256 QColor MapEditor::backgroundColor()
258 return mapCanvas->backgroundColor();
261 MapCenterObj* MapEditor::getMapCenter()
266 QCanvas* MapEditor::getCanvas()
271 void MapEditor::adjustCanvasSize()
273 // To adjust the canvas to map, viewport size and position, we have to
274 // do some coordinate magic...
276 // Get rectangle of (scroll-)view.
277 // We want to be in canvas coords, so
278 // we map. Important if view is zoomed...
279 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
280 visibleWidth(), visibleHeight()) );
282 // Now we need the bounding box of view AND map to calc the correct canvas size.
283 // Why? Because if the map itself is moved out of view, the view has to be enlarged
284 // to avoid jumping aroung...
285 QRect map=mapCenter->getTotalBBox();
287 // right edge - left edge
288 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
289 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
292 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
293 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
296 // move the map on canvas (in order to not move it on screen) this is neccessary
297 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
298 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
299 // to scroll to an empty area of canvas to the left.
300 // b) if topleft corner of map left of or above topleft of canvas
304 if (cw > mapCanvas->width() )
306 if (map.x()<0) dx=-map.x();
308 if (cw < mapCanvas->width() )
309 dx=-min (view.x(),map.x());
310 if (ch > mapCanvas->height() )
312 if (map.y()<0) dy=-map.y();
314 if (ch < mapCanvas->height() )
316 dy=-min (view.y(),map.y());
318 // We really have to resize now. Let's go...
319 mapCanvas->resize (cw,ch);
320 if ( (dx!=0) || (dy!=0) )
322 mapCenter->moveAllBy(dx,dy);
323 mapCenter->reposition();
325 // scroll the view (in order to not move map on screen)
331 bool MapEditor::isRepositionBlocked()
333 return blockReposition;
336 QString MapEditor::getName (LinkableMapObj *lmo)
339 if (!lmo) return QString("Error: NULL has no name!");
341 if ((typeid(*lmo) == typeid(BranchObj) ||
342 typeid(*lmo) == typeid(MapCenterObj)))
345 s=(((BranchObj*)lmo)->getHeading());
346 if (s=="") s="unnamed";
347 return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
349 if ((typeid(*lmo) == typeid(FloatImageObj) ))
350 return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
351 return QString("Unknown type has no name!");
354 void MapEditor::makeTmpDirs()
356 // Create unique temporary directories
357 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
359 d.mkdir (tmpMapDir,true);
362 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
364 // tmpdir temporary directory to which data will be written
365 // prefix mapname, which will be appended to images etc.
366 // writeflags Only write flags for "real" save of map, not undo
367 // offset offset of bbox of whole map in canvas.
368 // Needed for XML export
384 ls="StylePolyParabel";
388 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
390 if (linkcolorhint==HeadingColor)
391 colhint=attribut("linkColorHint","HeadingColor");
393 QString mapAttr=attribut("version",__VYM_VERSION);
395 mapAttr+= attribut("author",mapCenter->getAuthor()) +
396 attribut("comment",mapCenter->getComment()) +
397 attribut("date",mapCenter->getDate()) +
398 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
399 attribut("linkStyle", ls ) +
400 attribut("linkColor", defLinkColor.name() ) +
401 attribut("defXLinkColor", defXLinkColor.name() ) +
402 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
404 s+=beginElement("vymmap",mapAttr);
407 // Find the used flags while traversing the tree
408 standardFlagsDefault->resetUsedCounter();
410 // Reset the counters before saving
411 FloatImageObj (mapCanvas).resetSaveCounter();
413 // Build xml recursivly
415 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
418 if ( typeid(*saveSelection) == typeid(BranchObj) )
419 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
420 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
421 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
423 else if (selection && typeid(*selection)==typeid(BranchObj))
424 // This is used if selected branch is saved from mainwindow
425 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
428 // Save local settings
429 s+=settings.getXMLData (destPath);
432 if (selection && !saveSelection )
433 s+=valueElement("select",selection->getSelectString());
436 s+=endElement("vymmap");
439 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
443 void MapEditor::saveState(const QString &comment)
446 saveState (CompleteMap,"",NULL,"",NULL, comment);
449 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &comment)
451 // save the given part of the map
452 saveState (PartOfMap,"",undoSel,"",NULL, comment);
455 void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment)
457 // selection does not change during action,
458 // so just save commands for undo and redo
459 LinkableMapObj *unsel;
464 saveState (UndoCommand,uc,unsel,rc,unsel, comment);
467 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel, const QString &comment)
469 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL, comment);
472 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel, const QString &comment)
476 if (blockSaveState) return;
478 /* TODO remove after testing
479 cout << "ME::saveState() begin\n"<<endl;
480 cout << " undosTotal="<<undosTotal<<endl;
481 cout << " undosAvail="<<undosAvail<<endl;
482 cout << " undoNum="<<undoNum<<endl;
483 cout << " ---------------------------"<<endl;
486 historyWindow->append (comment);
490 // Find out current undo directory
491 if (undosAvail<undosTotal) undosAvail++;
493 if (undoNum>undosTotal) undoNum=1;
496 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
497 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
499 // Create bakMapDir if not available
502 makeSubDirs (bakMapDir);
504 // Save current selection
505 QString redoSelection="";
507 redoSelection=redoSel->getSelectString();
509 // Save the object, which should be undone
510 QString undoSelection="";
512 undoSelection=undoSel->getSelectString();
514 // Save depending on how much needs to be saved
515 QString undoCommand="";
516 if (savemode==UndoCommand)
521 else if (savemode==PartOfMap && undoSel)
523 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
524 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
527 undoCommand="undoMap (\""+bakMapPath+"\")";
528 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
531 if (!backupXML.isEmpty())
532 // Write XML Data to disk
533 saveStringToDisk (QString(bakMapPath),backupXML);
536 set.setEntry (QString("undoCommand"),undoCommand);
537 set.setEntry (QString("undoSelection"),undoSelection);
538 set.setEntry (QString("redoCommand"),redoCom);
539 set.setEntry (QString("redoSelection"),redoSelection);
540 set.setEntry (QString("comment"),comment);
541 set.writeSettings(QString(bakMapDir+"/commands"));
543 /* TODO remove after testing
544 cout << " into="<< bakMapDir<<endl;
545 cout << " undosAvail="<<undosAvail<<endl;
546 cout << " undoNum="<<undoNum<<endl;
547 cout << " ---------------------------"<<endl;
548 cout << " comment="<<comment<<endl;
549 cout << " ---------------------------"<<endl;
550 cout << " undoCom="<<undoCommand<<endl;
551 cout << " undoSel="<<undoSelection<<endl;
552 cout << " ---------------------------"<<endl;
553 cout << " redoCom="<<redoCom<<endl;
554 cout << " redoSel="<<redoSelection<<endl;
555 cout << " ---------------------------"<<endl<<endl;
559 void MapEditor::parseAtom(const QString &atom)
566 // Split string s into command and parameters
567 api.parseCommand (atom);
568 QString com=api.command();
571 if (com=="moveBranchUp")
573 else if (com=="moveBranchDown")
575 else if (com=="move")
577 if (api.checkParamCount(2) && selection )
587 else if (com=="linkBranchToPos")
589 if (selection && typeid(*selection) == typeid(BranchObj) )
591 if (api.checkParamCount(4))
593 s=api.parString(ok,0);
594 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
597 if (typeid(*dst) == typeid(BranchObj) )
599 // Get number in parent
602 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
603 } else if (typeid(*dst) == typeid(MapCenterObj) )
605 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
606 // Get coordinates of mainbranch
611 if (ok) ((BranchObj*)selection)->move (x,y);
617 } else if (com=="setHeading")
619 if (api.checkParamCount(1))
621 s=api.parString (ok,0);
622 if (ok) setHeading (s);
624 } else if (com=="setURL")
626 if (api.checkParamCount(1))
628 s=api.parString (ok,0);
631 } else if (com=="setVymLink")
633 if (api.checkParamCount(1))
635 s=api.parString (ok,0);
636 if (ok) setVymLink(s);
639 // Internal commands, used for undo etc.
640 else if (com==QString("undoMap"))
642 if (api.checkParamCount(1))
643 undoXML("",api.parString (ok,0));
644 } else if (com==QString("undoPart"))
646 if (api.checkParamCount(2))
648 s=api.parString (ok,0);
649 t=api.parString (ok,1);
652 } else if (com=="select")
653 if (api.checkParamCount(1))
655 s=api.parString(ok,0);
660 api.setError ("Unknown command in: "+atom);
661 cout << "ME::parse api should have error now...\n";
667 cout << "MapEditor::parseAtom: Error!\n";
668 cout << " "<<api.errorDesc()<<endl;
673 void MapEditor::finishedLineEdit()
675 // This is called by finishedLineEdit or any MapEditor method,
676 // which wants to assure, that lineedits finish, before e.g. a branch is
679 // After calling LineEdit and using the clipboard, the
680 // focus is not any longer on the main widget, we
681 // have to restore it using parentWidget()->setFocus()
685 saveState("setHeading (\""+editingBO->getHeading()+"\")",editingBO, QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(lineedit->text()) );
686 editingBO->setHeading(lineedit->text() );
688 lineedit->releaseKeyboard();
690 parentWidget()->setFocus();
691 mapCenter->reposition();
693 ensureSelectionVisible();
697 void MapEditor::toggleHistoryWindow()
699 if (historyWindow->isVisible())
700 historyWindow->hide();
702 historyWindow->show();
706 bool MapEditor::isDefault()
711 bool MapEditor::isUnsaved()
716 bool MapEditor::hasChanged()
721 void MapEditor::setChanged()
726 actionEditUndo->setEnabled (true);
727 actionFileSave->setEnabled (true);
731 void MapEditor::closeMap()
733 // Finish open lineEdits
734 if (lineedit) finishedLineEdit();
736 // Unselect before disabling the toolbar actions
737 if (selection) selection->unselect();
745 void MapEditor::setFilePath(QString fname)
747 setFilePath (fname,fname);
750 void MapEditor::setFilePath(QString fname, QString destname)
752 if (fname.isEmpty() || fname=="")
759 filePath=fname; // becomes absolute path
760 fileName=fname; // gets stripped of path
761 destPath=destname; // needed for vymlinks
763 // If fname is not an absolute path, complete it
764 filePath=QDir(fname).absPath();
765 fileDir=filePath.left (1+filePath.findRev ("/"));
767 // Set short name, too. Search from behind:
768 int i=fileName.findRev("/");
769 if (i>=0) fileName=fileName.remove (0,i+1);
771 // Forget the .vym (or .xml) for name of map
772 mapName=fileName.left(fileName.findRev(".",-1,true) );
774 // Adjust history window
775 historyWindow->setCaption (fileName);
779 QString MapEditor::getFilePath()
784 QString MapEditor::getFileName()
789 QString MapEditor::getMapName()
794 QString MapEditor::getDestPath()
799 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
801 // Finish open lineEdits
802 if (lineedit) finishedLineEdit();
804 ErrorCode err=success;
808 if (selection) selection->unselect();
811 mapCenter->setMapEditor(this);
812 // (map state is set later at end of load...)
815 saveState(selection,"Load map");
819 mapBuilderHandler handler;
822 // I am paranoid: file should exist anyway
823 // according to check in mainwindow.
826 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
827 tr("Couldn't open map " +fname)+".");
831 blockReposition=true;
832 QXmlInputSource source( file);
833 QXmlSimpleReader reader;
834 reader.setContentHandler( &handler );
835 reader.setErrorHandler( &handler );
836 handler.setMapEditor( this );
837 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
838 handler.setInputFile (file.name());
839 handler.setLoadMode (lmode);
841 bool ok = reader.parse( source );
842 blockReposition=false;
843 blockSaveState=false;
847 mapCenter->reposition();
857 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
858 tr( handler.errorProtocol() ) );
860 // Still return "success": the map maybe at least
861 // partially read by the parser
868 int MapEditor::save (const SaveMode &savemode)
870 // Finish open lineEdits
871 if (lineedit) finishedLineEdit();
875 // The SaveMode UndoCommand is not supported here
876 if (savemode==UndoCommand) return 1;
878 // Create mapName and fileDir
879 makeSubDirs (fileDir);
883 fname=mapName+".xml";
885 // use name given by user, even if he chooses .doc
890 if (savemode==CompleteMap || selection==NULL)
891 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
893 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
895 if (!saveStringToDisk(fileDir+fname,saveFile))
902 actionFileSave->setEnabled(false);
908 void MapEditor::setZipped (bool z)
913 bool MapEditor::saveZipped ()
918 void MapEditor::print()
920 // Finish open lineEdits
921 if (lineedit) finishedLineEdit();
925 printer = new QPrinter;
926 printer->setColorMode (QPrinter::Color);
927 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
930 QRect totalBBox=mapCenter->getTotalBBox();
932 // Try to set orientation automagically
933 // Note: Interpretation of generated postscript is amibiguous, if
934 // there are problems with landscape mode, see
935 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
937 if (totalBBox.width()>totalBBox.height())
938 // recommend landscape
939 printer->setOrientation (QPrinter::Landscape);
941 // recommend portrait
942 printer->setOrientation (QPrinter::Portrait);
944 if ( printer->setup(this) )
945 // returns false, if printing is canceled
947 QPainter pp(printer);
949 // Don't print the visualisation of selection
950 LinkableMapObj *oldselection=NULL;
953 oldselection=selection;
954 selection->unselect();
957 // Handle sizes of map and paper:
959 // setWindow defines which part of the canvas will be transformed
960 // setViewport defines area on paper in device coordinates (dpi)
961 // e.g. (0,50,700,700) is upper part on A4
962 // see also /usr/lib/qt3/doc/html/coordsys.html
964 QPaintDeviceMetrics metrics (printer);
966 double paperAspect = (double)metrics.width() / (double)metrics.height();
967 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
969 QRect mapRect=totalBBox;
970 QCanvasRectangle *frame=NULL;
971 QCanvasText *footerFN=NULL;
972 QCanvasText *footerDate=NULL;
973 if (printFrame || printFooter)
978 // Print frame around map
979 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
980 totalBBox.width()+20, totalBBox.height()+20);
981 frame=new QCanvasRectangle (mapRect,mapCanvas);
982 frame->setBrush (QColor(white));
983 frame->setPen (QColor(black));
987 /* TODO remove after testing
988 QCanvasLine *l=new QCanvasLine (mapCanvas);
989 l->setPoints (0,0,mapRect.width(),mapRect.height());
990 l->setPen (QPen(QColor(black), 1));
997 // Print footer below map
999 font.setPointSize(10);
1000 footerFN=new QCanvasText (mapCanvas);
1001 footerFN->setText ("VYM - " + fileName);
1002 footerFN->setFont(font);
1003 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1004 footerFN->setZ(Z_TEXT);
1006 footerDate=new QCanvasText (mapCanvas);
1007 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1008 footerDate->setFont(font);
1009 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1010 footerDate->setZ(Z_TEXT);
1013 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1016 pp.setWindow (mapRect);
1019 if (mapAspect>=paperAspect)
1021 // Fit horizontally to paper width
1022 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1025 // Fit vertically to paper height
1026 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1029 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1031 // Delete Frame and footer
1035 delete (footerDate);
1037 if (frame) delete (frame);
1039 // Restore selection
1042 selection=oldselection;
1043 selection->select();
1046 // Save settings in vymrc
1047 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1051 QPixmap MapEditor::getPixmap()
1053 QRect mapRect=mapCenter->getTotalBBox();
1054 QPixmap pix (mapRect.size());
1057 // Don't print the visualisation of selection
1058 LinkableMapObj *oldselection=NULL;
1061 oldselection=selection;
1062 selection->unselect();
1065 pp.setWindow (mapRect);
1067 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1070 // Restore selection
1073 selection=oldselection;
1074 selection->select();
1080 void MapEditor::setHideTmpMode (HideTmpMode mode)
1083 mapCenter->setHideTmp (hidemode);
1084 mapCenter->reposition();
1089 HideTmpMode MapEditor::getHideTmpMode()
1094 void MapEditor::exportImage(QString fn)
1096 // Finish open lineEdits
1097 if (lineedit) finishedLineEdit();
1099 setExportMode (true);
1100 QPixmap pix (getPixmap());
1101 pix.save(fn, "PNG");
1102 setExportMode (false);
1105 void MapEditor::setExportMode (bool b)
1107 // should be called before and after exports
1108 // depending on the settings
1109 if (b && settings.readEntry("/vym/export/useHideExport","yes"))
1110 setHideTmpMode (HideExport);
1112 setHideTmpMode (HideNone);
1115 void MapEditor::exportImage(QString fn, int item)
1117 // Finish open lineEdits
1118 if (lineedit) finishedLineEdit();
1120 setExportMode (true);
1121 QPixmap pix (getPixmap());
1122 pix.save(fn, exportImageFormatMenu->text(item) );
1123 setExportMode (false);
1126 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1130 ex.setMapCenter(mapCenter);
1131 if (ex.setConfigFile(cf))
1133 setExportMode (true);
1134 ex.exportPresentation();
1135 setExportMode (false);
1141 void MapEditor::exportXML(const QString &dir)
1143 // Hide stuff during export, if settings want this
1144 setExportMode (true);
1146 // Create subdirectories
1149 // write to directory
1150 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1153 file.setName ( dir + "/"+mapName+".xml");
1154 if ( !file.open( IO_WriteOnly ) )
1156 // This should neverever happen
1157 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1161 // Write it finally, and write in UTF8, no matter what
1162 QTextStream ts( &file );
1163 ts.setEncoding (QTextStream::UnicodeUTF8);
1167 // Now write image, too
1168 exportImage (dir+"/images/"+mapName+".png");
1170 setExportMode (false);
1173 void MapEditor::clear()
1177 selection->unselect();
1184 void MapEditor::copy()
1186 // Finish open lineEdits
1187 if (lineedit) finishedLineEdit();
1191 // write to directory
1192 QString clipfile="part";
1193 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1196 file.setName ( clipboardDir + "/"+clipfile+".xml");
1197 if ( !file.open( IO_WriteOnly ) )
1199 // This should neverever happen
1200 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1204 // Write it finally, and write in UTF8, no matter what
1205 QTextStream ts( &file );
1206 ts.setEncoding (QTextStream::UnicodeUTF8);
1210 clipboardEmpty=false;
1215 void MapEditor::redo()
1217 // Finish open lineEdits
1218 if (lineedit) finishedLineEdit();
1220 blockSaveState=true;
1222 // Find out current undo directory
1223 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1225 // Restore variables
1226 QString undoCommand;
1227 QString undoSelection;
1228 QString redoCommand;
1229 QString redoSelection;
1231 set.readSettings(QString(bakMapDir+"/commands"));
1232 undoCommand=set.readEntry ("undoCommand");
1233 undoSelection=set.readEntry ("undoSelection");
1234 redoCommand=set.readEntry ("redoCommand");
1235 redoSelection=set.readEntry ("redoSelection");
1237 // select object before redo
1238 if (!redoSelection.isEmpty())
1239 select (redoSelection);
1241 /* TODO remove testing
1242 cout << "ME::redo() begin\n";
1243 cout << " undosTotal="<<undosTotal<<endl;
1244 cout << " undosAvail="<<undosAvail<<endl;
1245 cout << " undoNum="<<undoNum<<endl;
1246 cout << " ---------------------------"<<endl;
1247 cout << " undoCom="<<undoCommand<<endl;
1248 cout << " undoSel="<<undoSelection<<endl;
1249 cout << " ---------------------------"<<endl;
1250 cout << " redoCom="<<redoCommand<<endl;
1251 cout << " redoSel="<<redoSelection<<endl;
1252 cout << " ---------------------------"<<endl;
1254 parseAtom (undoCommand);
1255 mapCenter->reposition();
1257 //if (!redoSelection.isEmpty())
1258 // select (redoSelection);
1262 // Undo not longer available now
1263 actionEditUndo->setEnabled (false);
1265 undoNum--; if (undoNum<1) undoNum=undosTotal;
1267 blockSaveState=false;
1268 /* TODO remove testing
1269 cout << "ME::redo() end\n";
1270 cout << " undosAvail="<<undosAvail<<endl;
1271 cout << " undoNum="<<undoNum<<endl;
1272 cout << " ---------------------------"<<endl<<endl;
1276 void MapEditor::undo()
1278 // Finish open lineEdits
1279 if (lineedit) finishedLineEdit();
1281 blockSaveState=true;
1283 // Find out current undo directory
1284 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1286 // Restore variables
1287 QString undoCommand;
1288 QString undoSelection;
1289 QString redoCommand;
1290 QString redoSelection;
1292 set.readSettings(QString(bakMapDir+"/commands"));
1293 undoCommand= set.readEntry ("undoCommand");
1294 undoSelection=set.readEntry ("undoSelection");
1295 redoCommand= set.readEntry ("redoCommand");
1296 redoSelection=set.readEntry ("redoSelection");
1298 // select object before undo
1299 if (!undoSelection.isEmpty())
1300 select (undoSelection);
1303 cout << "ME::undo() begin\n";
1304 cout << " undosTotal="<<undosTotal<<endl;
1305 cout << " undosAvail="<<undosAvail<<endl;
1306 cout << " undoNum="<<undoNum<<endl;
1307 cout << " ---------------------------"<<endl;
1308 cout << " undoCom="<<undoCommand<<endl;
1309 cout << " undoSel="<<undoSelection<<endl;
1310 cout << " ---------------------------"<<endl;
1311 cout << " redoCom="<<redoCommand<<endl;
1312 cout << " redoSel="<<redoSelection<<endl;
1313 cout << " ---------------------------"<<endl;
1315 parseAtom (undoCommand);
1316 mapCenter->reposition();
1318 //if (!redoSelection.isEmpty())
1319 // select (redoSelection);
1323 // Undo not longer available now
1324 actionEditUndo->setEnabled (false);
1326 undoNum--; if (undoNum<1) undoNum=undosTotal;
1328 blockSaveState=false;
1329 /* TODO remove testing
1330 cout << "ME::undo() end\n";
1331 cout << " undosAvail="<<undosAvail<<endl;
1332 cout << " undoNum="<<undoNum<<endl;
1333 cout << " ---------------------------"<<endl<<endl;
1337 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1339 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1341 QFile file (bakMapPath);
1345 // We need to parse saved XML data
1346 mapBuilderHandler handler;
1347 QXmlInputSource source( file);
1348 QXmlSimpleReader reader;
1349 reader.setContentHandler( &handler );
1350 reader.setErrorHandler( &handler );
1351 handler.setMapEditor( this );
1352 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1353 if (undoSel.isEmpty())
1357 handler.setLoadMode (NewMap);
1361 handler.setLoadMode (ImportReplace);
1363 blockReposition=true;
1364 bool ok = reader.parse( source );
1365 blockReposition=false;
1368 // This should never ever happen
1369 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1370 tr( handler.errorProtocol() )+" in "+bakMapDir );
1374 QMessageBox::critical( 0, tr( "Critical Error" ),
1375 tr("Temporary directory %1 used for undo is gone. \n"
1376 "I will create a new one, but at the moment no undo is available.\n"
1377 "Maybe you want to reload your original data.\n\n"
1378 "Sorry for any inconveniences.").arg(bakMapDir) );
1383 void MapEditor::pasteNoSave()
1385 // Finish open lineEdits
1386 if (lineedit) finishedLineEdit();
1388 load (clipboardDir+"/part.xml",ImportAdd);
1391 void MapEditor::cutNoSave()
1397 void MapEditor::paste()
1399 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1400 typeid(*selection) == typeid(MapCenterObj)))
1402 saveState(selection,QString("Paste to %1").arg( getName(selection)));
1404 mapCenter->reposition();
1409 void MapEditor::cut()
1411 saveState(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
1414 mapCenter->reposition();
1418 void MapEditor::move(const int &x, const int &y)
1420 // TODO no saveState, because this is only internal at undo so far
1421 if (selection) selection->move(x,y);
1422 if (typeid(*selection) == typeid(FloatImageObj))
1423 ((FloatImageObj*)selection)->setRelPos();
1426 void MapEditor::moveBranchUp()
1428 // Finish open lineEdits
1429 if (lineedit) finishedLineEdit();
1433 if (typeid(*selection) == typeid(BranchObj) )
1435 bo=(BranchObj*)selection;
1436 if (!bo->canMoveBranchUp()) return;
1437 par=(BranchObj*)(bo->getParObj());
1438 selection->unselect();
1439 selection=par->moveBranchUp (bo);
1440 selection->select();
1441 saveState("moveBranchDown ()",bo,QString("Move up %1").arg(getName(bo)));
1442 mapCenter->reposition();
1443 ensureSelectionVisible();
1447 void MapEditor::moveBranchDown()
1449 // Finish open lineEdits
1450 if (lineedit) finishedLineEdit();
1454 if (typeid(*selection) == typeid(BranchObj) )
1456 bo=(BranchObj*)selection;
1457 if (!bo->canMoveBranchDown()) return;
1458 par=(BranchObj*)(bo->getParObj());
1459 selection->unselect();
1460 selection=par->moveBranchDown(bo);
1461 selection->select();
1462 saveState("moveBranchUp ()",bo,QString("Move down %1").arg(getName(bo)));
1463 mapCenter->reposition();
1464 ensureSelectionVisible();
1468 void MapEditor::editHeading()
1470 // Finish open lineEdits
1471 if (lineedit) finishedLineEdit();
1474 (typeid(*selection) == typeid(BranchObj) ||
1475 typeid(*selection) == typeid(MapCenterObj) ) )
1477 editingBO=(BranchObj*)selection;
1479 ensureSelectionVisible();
1480 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1481 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1482 QString s=editingBO->getHeading();
1483 lineedit->setText(s);
1484 lineedit->setCursorPosition(1);
1485 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1486 lineedit->selectAll();
1488 lineedit->grabKeyboard();
1489 lineedit->setFocus();
1493 void MapEditor::setHeading(const QString &s)
1495 // Internal function, no saveState needed
1497 (typeid(*selection) == typeid(BranchObj) ||
1498 typeid(*selection) == typeid(MapCenterObj) ) )
1500 ((BranchObj*)selection)->setHeading(s);
1501 mapCenter->reposition();
1503 ensureSelectionVisible();
1507 void MapEditor::setURL (const QString &s)
1509 // Internal function, no saveState needed
1511 (typeid(*selection) == typeid(BranchObj) ||
1512 typeid(*selection) == typeid(MapCenterObj) ) )
1514 ((BranchObj*)selection)->setURL(s);
1515 mapCenter->reposition();
1517 ensureSelectionVisible();
1521 void MapEditor::setVymLink (const QString &s)
1523 // Internal function, no saveState needed
1525 (typeid(*selection) == typeid(BranchObj) ||
1526 typeid(*selection) == typeid(MapCenterObj) ) )
1528 ((BranchObj*)selection)->setVymLink(s);
1529 mapCenter->reposition();
1531 ensureSelectionVisible();
1535 void MapEditor::addNewBranch(int pos)
1537 // Finish open lineEdits
1538 if (lineedit) finishedLineEdit();
1541 (typeid(*selection) == typeid(BranchObj) ||
1542 typeid(*selection) == typeid(MapCenterObj) ) )
1544 BranchObj* bo1 = (BranchObj*) selection;
1545 saveState(selection, QString("Add new branch to %1").arg(getName(bo1))); //TODO undoCommand
1547 bool wasScrolled=false;
1548 BranchObj *newbo=NULL;
1551 // save scroll state. If scrolled, automatically select
1552 // new branch in order to tmp unscroll parent...
1553 wasScrolled=bo1->isScrolled();
1554 newbo=bo1->addBranch();
1557 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1561 // add above selection
1562 newbo=parbo->insertBranch(bo1->getNum());
1564 // add below selection
1565 newbo=parbo->insertBranch(bo1->getNum()+1);
1567 // This should not happen...
1572 LinkableMapObj *oldselection=selection;
1574 mapCenter->reposition();
1576 if (actionSettingsAutoedit->isOn() ||
1577 actionSettingsAutoselectHeading->isOn() )
1579 selection->unselect();
1581 selection->select();
1582 if (actionSettingsPasteNewHeading->isOn() )
1584 BranchObj *bo2= (BranchObj*)selection;
1585 bo2->setHeading("");
1587 if (actionSettingsAutoedit->isOn() )
1589 if (!actionSettingsAutoselectHeading->isOn()
1592 selection->unselect();
1593 selection=oldselection;
1594 selection->select();
1601 void MapEditor::addNewBranchHere()
1603 // Finish open lineEdits
1604 if (lineedit) finishedLineEdit();
1607 (typeid(*selection) == typeid(BranchObj) ) )
1609 BranchObj* bo1 = (BranchObj*) selection;
1610 saveState(selection, QString("Add new branch here").arg(getName(bo1)));
1612 bool wasScrolled=false;
1613 BranchObj *newbo=NULL;
1614 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1617 // add below selection
1618 newbo=parbo->insertBranch(bo1->getNum()+1);
1621 LinkableMapObj *oldselection=selection;
1622 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1624 mapCenter->reposition();
1626 if (actionSettingsAutoedit->isOn() ||
1627 actionSettingsAutoselectHeading->isOn() )
1629 selection->unselect();
1631 selection->select();
1632 if (actionSettingsPasteNewHeading->isOn() )
1634 BranchObj *bo2= (BranchObj*)selection;
1635 bo2->setHeading("");
1637 if (actionSettingsAutoedit->isOn() )
1639 if (!actionSettingsAutoselectHeading->isOn()
1642 selection->unselect();
1643 selection=oldselection;
1644 selection->select();
1650 void MapEditor::deleteSelection()
1652 // Finish open lineEdits
1653 if (lineedit) finishedLineEdit();
1655 if (selection && typeid(*selection) ==typeid(BranchObj) )
1657 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1658 BranchObj* par=(BranchObj*)(bo->getParObj());
1660 if (selection->getDepth()>1)
1661 // Normal branch, save parent with childs
1662 saveState(par,QString("Delete %1").arg(getName(bo)));
1664 // Mainbranch, save whole map
1665 // TODO Better would be to insert mainbranch again at pos
1666 // But undoCommand is missing right now
1667 saveState(QString("Delete %1").arg(getName(bo)));
1669 par->removeBranch(bo);
1671 selection->select();
1672 ensureSelectionVisible();
1673 mapCenter->reposition();
1676 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1678 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1679 BranchObj* par=(BranchObj*)(fio->getParObj());
1680 saveState(par, QString("Delete %1").arg(getName(fio)));
1683 par->removeFloatImage(fio);
1685 selection->select();
1686 ensureSelectionVisible();
1687 mapCenter->reposition();
1692 LinkableMapObj* MapEditor::getSelection()
1697 void MapEditor::unselect()
1701 selectionLast=selection;
1702 selection->unselect();
1707 void MapEditor::reselect()
1711 selection=selectionLast;
1712 selection->select();
1717 bool MapEditor::select (const QString &s)
1719 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1721 // Finally select the found object
1724 if (selection) unselect();
1726 selection->select();
1728 ensureSelectionVisible();
1734 void MapEditor::select (LinkableMapObj *lmo)
1736 if (lmo && selection != lmo)
1738 // select the MapObj
1739 if (selection) selection->unselect();
1741 selection->select();
1748 void MapEditor::selectNextBranch()
1750 // Increase number of branch
1753 QString s=selection->getSelectString();
1759 part=s.section(",",-1);
1761 num=part.right(part.length() - 3);
1763 s=s.left (s.length() -num.length());
1766 num=QString ("%1").arg(num.toUInt()+1);
1770 // Try to select this one
1771 if (select (s)) return;
1773 // We have no direct successor,
1774 // try to increase the parental number in order to
1775 // find a successor with same depth
1777 int d=selection->getDepth();
1782 while (!found && d>0)
1784 s=s.section (",",0,d-1);
1785 // replace substring of current depth in s with "1"
1786 part=s.section(",",-1);
1788 num=part.right(part.length() - 3);
1792 // increase number of parent
1793 num=QString ("%1").arg(num.toUInt()+1);
1794 s=s.section (",",0,d-2) + ","+ typ+num;
1797 // Special case, look at orientation
1798 if (selection->getOrientation()==OrientRightOfCenter)
1799 num=QString ("%1").arg(num.toUInt()+1);
1801 num=QString ("%1").arg(num.toUInt()-1);
1806 // pad to oldDepth, select the first branch for each depth
1807 for (i=d;i<oldDepth;i++)
1812 if ( ((BranchObj*)selection)->countBranches()>0)
1820 // try to select the freshly built string
1828 void MapEditor::selectPrevBranch()
1830 // Decrease number of branch
1833 QString s=selection->getSelectString();
1839 part=s.section(",",-1);
1841 num=part.right(part.length() - 3);
1843 s=s.left (s.length() -num.length());
1846 num=QString ("%1").arg(num.toUInt()-1);
1850 // Try to select this one
1851 if (select (s)) return;
1853 // We have no direct precessor,
1854 // try to decrease the parental number in order to
1855 // find a precessor with same depth
1857 int d=selection->getDepth();
1862 while (!found && d>0)
1864 s=s.section (",",0,d-1);
1865 // replace substring of current depth in s with "1"
1866 part=s.section(",",-1);
1868 num=part.right(part.length() - 3);
1872 // decrease number of parent
1873 num=QString ("%1").arg(num.toUInt()-1);
1874 s=s.section (",",0,d-2) + ","+ typ+num;
1877 // Special case, look at orientation
1878 if (selection->getOrientation()==OrientRightOfCenter)
1879 num=QString ("%1").arg(num.toUInt()-1);
1881 num=QString ("%1").arg(num.toUInt()+1);
1886 // pad to oldDepth, select the last branch for each depth
1887 for (i=d;i<oldDepth;i++)
1891 if ( ((BranchObj*)selection)->countBranches()>0)
1892 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1899 // try to select the freshly built string
1907 void MapEditor::selectUpperBranch()
1909 // Finish open lineEdits
1910 if (lineedit) finishedLineEdit();
1914 if (typeid(*selection) == typeid(BranchObj))
1916 if (selection->getOrientation()==OrientRightOfCenter)
1919 if (selection->getDepth()==1)
1927 void MapEditor::selectLowerBranch()
1929 // Finish open lineEdits
1930 if (lineedit) finishedLineEdit();
1934 if (typeid(*selection) == typeid(BranchObj))
1936 if (selection->getOrientation()==OrientRightOfCenter)
1939 if (selection->getDepth()==1)
1948 void MapEditor::selectLeftBranch()
1950 // Finish open lineEdits
1951 if (lineedit) finishedLineEdit();
1957 if (typeid(*selection) == typeid(MapCenterObj))
1959 par= (BranchObj*) selection;
1960 bo=par->getLastSelectedBranch();
1963 // Workaround for reselecting on left and right side
1964 if (bo->getOrientation()==OrientRightOfCenter)
1966 bo=par->getLastBranch();
1972 selection->select();
1974 ensureSelectionVisible();
1979 par=(BranchObj*)(selection->getParObj());
1980 if (selection->getOrientation()==OrientRightOfCenter)
1982 if (typeid(*selection) == typeid(BranchObj) ||
1983 typeid(*selection) == typeid(FloatImageObj))
1985 selection->unselect();
1987 selection->select();
1989 ensureSelectionVisible();
1993 if (typeid(*selection) == typeid(BranchObj) )
1995 bo=((BranchObj*)selection)->getLastSelectedBranch();
1998 selection->unselect();
2000 selection->select();
2002 ensureSelectionVisible();
2010 void MapEditor::selectRightBranch()
2012 // Finish open lineEdits
2013 if (lineedit) finishedLineEdit();
2020 if (typeid(*selection) == typeid(MapCenterObj))
2022 par= (BranchObj*) selection;
2023 bo=par->getLastSelectedBranch();
2026 // Workaround for relecting on left and right side
2027 if (bo->getOrientation()==OrientLeftOfCenter)
2028 bo=par->getFirstBranch();
2033 selection->select();
2034 ensureSelectionVisible();
2039 par=(BranchObj*)(selection->getParObj());
2040 if (selection->getOrientation()==OrientLeftOfCenter)
2042 if (typeid(*selection) == typeid(BranchObj) ||
2043 typeid(*selection) == typeid(FloatImageObj))
2045 selection->unselect();
2047 selection->select();
2049 ensureSelectionVisible();
2053 if (typeid(*selection) == typeid(BranchObj) )
2055 bo=((BranchObj*)selection)->getLastSelectedBranch();
2058 selection->unselect();
2060 selection->select();
2062 ensureSelectionVisible();
2070 void MapEditor::selectFirstBranch()
2072 // Finish open lineEdits
2073 if (lineedit) finishedLineEdit();
2079 if (typeid(*selection) == typeid(BranchObj))
2081 bo1= (BranchObj*) selection;
2082 par=(BranchObj*)(bo1->getParObj());
2083 bo2=par->getFirstBranch();
2087 selection->select();
2088 ensureSelectionVisible();
2095 void MapEditor::selectLastBranch()
2097 // Finish open lineEdits
2098 if (lineedit) finishedLineEdit();
2104 if (typeid(*selection) == typeid(BranchObj))
2106 bo1= (BranchObj*) selection;
2107 par=(BranchObj*)(bo1->getParObj());
2108 bo2=par->getLastBranch();
2112 selection->select();
2113 ensureSelectionVisible();
2120 void MapEditor::setColor(QColor c)
2125 void MapEditor::selectBackgroundColor()
2127 // Finish open lineEdits
2128 if (lineedit) finishedLineEdit();
2130 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2131 if ( !col.isValid() ) return;
2132 setBackgroundColor( col );
2133 saveState(QString("Set background color of map to %1").arg(col.name()));
2136 void MapEditor::setBackgroundColor(QColor c)
2138 mapCanvas->setBackgroundColor (c);
2141 QColor MapEditor::pickColor()
2145 if (typeid(*selection) == typeid(BranchObj) ||
2146 typeid(*selection) == typeid(MapCenterObj))
2148 BranchObj *bo=(BranchObj*)selection;
2149 actColor=bo->getColor();
2155 void MapEditor::colorItem()
2159 if (typeid(*selection) == typeid(BranchObj) ||
2160 typeid(*selection) == typeid(MapCenterObj))
2162 BranchObj *bo=(BranchObj*)selection;
2163 saveState(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2164 bo->setColor(actColor); // color branch
2169 void MapEditor::colorBranch()
2173 if (typeid(*selection) == typeid(BranchObj) ||
2174 typeid(*selection) == typeid(MapCenterObj))
2176 BranchObj *bo=(BranchObj*)selection;
2177 saveState(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2178 bo->setColorChilds(actColor); // color links, color childs
2184 void MapEditor::toggleStandardFlag(QString f)
2188 BranchObj *bo=(BranchObj*)selection;
2190 if (bo->isSetStandardFlag(f))
2194 saveState(selection, QString("%1 standard flag \"%2\" of %3").arg(s).arg(f).arg(getName(bo)));// TODO undoCommand
2195 bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn());
2200 void MapEditor::setViewCenter()
2202 // transform to CanvasView Coord:
2203 QPoint p=worldMatrix().map(movingCenter);
2204 center ( p.x(), p.y());
2208 BranchObj* MapEditor::findText (QString s, bool cs)
2211 { // Nothing found or new find process
2213 // nothing found, start again
2215 itFind=mapCenter->first();
2217 bool searching=true;
2218 bool foundNote=false;
2219 while (searching && !EOFind)
2223 // Searching in Note
2224 if (itFind->getNote().contains(s,cs))
2226 if (selection!=itFind)
2228 if (selection) ((BranchObj*)selection)->unselect();
2230 selection->select();
2232 ensureSelectionVisible();
2234 if (textEditor->findText(s,cs))
2240 // Searching in Heading
2241 if (searching && itFind->getHeading().contains (s,cs) )
2243 if (selection) ((BranchObj*)selection)->unselect();
2245 selection->select();
2247 ensureSelectionVisible();
2253 itFind=itFind->next();
2254 if (!itFind) EOFind=true;
2260 return (BranchObj*)selection;
2265 void MapEditor::findReset()
2266 { // Necessary if text to find changes during a find process
2271 void MapEditor::editURL()
2273 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2274 typeid(*selection) == typeid(MapCenterObj)) )
2277 BranchObj *bo=(BranchObj*)selection;
2278 QString text = QInputDialog::getText(
2279 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2280 bo->getURL(), &ok, this );
2283 // user entered something and pressed OK
2284 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2291 QString MapEditor::getURL()
2293 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2294 typeid(*selection) == typeid(MapCenterObj)) )
2295 return ((BranchObj*)selection)->getURL();
2300 void MapEditor::editHeading2URL()
2302 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2303 typeid(*selection) == typeid(MapCenterObj)) )
2305 BranchObj *bo=(BranchObj*)selection;
2306 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2307 bo->setURL (bo->getHeading());
2312 void MapEditor::editBugzilla2URL()
2314 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2315 typeid(*selection) == typeid(MapCenterObj)) )
2317 BranchObj *bo=(BranchObj*)selection;
2318 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2319 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Bugzilla").arg(getName(bo)));
2325 void MapEditor::editFATE2URL()
2327 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2328 typeid(*selection) == typeid(MapCenterObj)) )
2330 BranchObj *bo=(BranchObj*)selection;
2331 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2332 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2338 void MapEditor::editVymLink()
2340 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2341 typeid(*selection) == typeid(MapCenterObj)) )
2343 BranchObj *bo=(BranchObj*)selection;
2344 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
2345 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2346 fd->setCaption(__VYM " - " +tr("Link to another map"));
2347 if (! bo->getVymLink().isEmpty() )
2348 fd->setSelection( bo->getVymLink() );
2352 if ( fd->exec() == QDialog::Accepted )
2354 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2355 bo->setVymLink (fd->selectedFile() );
2357 mapCenter->reposition();
2364 void MapEditor::deleteVymLink()
2366 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2367 typeid(*selection) == typeid(MapCenterObj)) )
2369 BranchObj *bo=(BranchObj*)selection;
2370 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2371 bo->setVymLink ("" );
2373 mapCenter->reposition();
2379 void MapEditor::toggleHideExport()
2381 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2382 typeid(*selection) == typeid(MapCenterObj)) ||
2383 (typeid(*selection)==typeid(FloatImageObj))
2386 OrnamentedObj *oo=(OrnamentedObj*)selection;
2388 if (oo->hideInExport())
2390 oo->setHideInExport(false);
2395 oo->setHideInExport(true);
2398 saveState(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2399 actionEditToggleHideExport->setOn (oo->hideInExport());
2401 mapCenter->reposition();
2407 QString MapEditor::getVymLink()
2409 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2410 typeid(*selection) == typeid(MapCenterObj)) )
2412 return ((BranchObj*)selection)->getVymLink();
2418 void MapEditor::removeBranchKeepChilds()
2420 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2422 BranchObj* bo=(BranchObj*)selection;
2423 BranchObj* par=(BranchObj*)(bo->getParObj());
2424 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2425 if (bo->getDepth()==1)
2428 saveState(selection->getParObj(),s); // TODO undoCommand
2429 QString sel=selection->getSelectString();
2431 par->removeBranchHere(bo);
2432 mapCenter->reposition();
2437 void MapEditor::removeChilds()
2439 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2441 saveState(selection->getParObj(), QString("Remove childs of branch").arg(getName(selection)));
2442 ((BranchObj*)selection)->removeChilds();
2443 mapCenter->reposition();
2447 void MapEditor::editMapInfo()
2449 ExtraInfoDialog dia;
2450 dia.setMapName (getFileName() );
2451 dia.setAuthor (mapCenter->getAuthor() );
2452 dia.setComment(mapCenter->getComment() );
2457 QCanvasItemList l=canvas()->allItems();
2458 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2460 stats+=QString ("%1 items on canvas\n").arg (i,6);
2467 bo=mapCenter->first();
2470 if (!bo->getNote().isEmpty() ) n++;
2471 f+= bo->countFloatImages();
2473 xl+=bo->countXLinks();
2476 stats+=QString ("%1 branches\n").arg (b-1,6);
2477 stats+=QString ("%1 xLinks \n").arg (xl,6);
2478 stats+=QString ("%1 notes\n").arg (n,6);
2479 stats+=QString ("%1 images\n").arg (f,6);
2480 dia.setStats (stats);
2482 // Finally show dialog
2483 if (dia.exec() == QDialog::Accepted)
2485 saveState("Edit info about map"); //TODO undoCommand
2486 mapCenter->setAuthor (dia.getAuthor() );
2487 mapCenter->setComment (dia.getComment() );
2491 void MapEditor::updateActions()
2494 if (getLinkColorHint()==HeadingColor)
2495 actionFormatLinkColorHint->setOn(true);
2497 actionFormatLinkColorHint->setOn(false);
2502 actionFormatLinkStyleLine->setOn(true);
2505 actionFormatLinkStyleParabel->setOn(true);
2508 actionFormatLinkStylePolyLine->setOn(true);
2510 case StylePolyParabel:
2511 actionFormatLinkStylePolyParabel->setOn(true);
2517 QPixmap pix( 16, 16 );
2518 pix.fill( mapCanvas->backgroundColor() );
2519 actionFormatBackColor->setIconSet( pix );
2520 pix.fill( defLinkColor );
2521 actionFormatLinkColor->setIconSet( pix );
2523 actionEditUndo->setEnabled( mapChanged );
2524 actionFileSave->setEnabled( mapUnsaved );
2528 if ( (typeid(*selection) == typeid(BranchObj)) ||
2529 (typeid(*selection) == typeid(MapCenterObj)) )
2531 BranchObj *bo=(BranchObj*)selection;
2532 // Take care of links
2533 if (bo->countXLinks()==0)
2535 branchLinksContextMenu->clear();
2536 branchLinksContextMenu->insertItem ("No xLink available");
2537 branchLinksContextMenuDup->clear();
2538 branchLinksContextMenuDup->insertItem ("No xLink available");
2544 branchLinksContextMenu->clear();
2545 branchLinksContextMenuDup->clear();
2546 for (int i=0; i<=bo->countXLinks();i++)
2548 bot=bo->XLinkTargetAt(i);
2551 s=bot->getHeading();
2554 branchLinksContextMenu->insertItem (s);
2555 branchLinksContextMenuDup->insertItem (s);
2560 standardFlagsDefault->setEnabled (true);
2562 actionEditToggleScroll->setEnabled (true);
2563 if ( bo->isScrolled() )
2564 actionEditToggleScroll->setOn(true);
2566 actionEditToggleScroll->setOn(false);
2568 if ( bo->getURL().isEmpty() )
2570 actionEditOpenURL->setEnabled (false);
2571 actionEditOpenURLTab->setEnabled (false);
2575 actionEditOpenURL->setEnabled (true);
2576 actionEditOpenURLTab->setEnabled (true);
2578 if ( bo->getVymLink().isEmpty() )
2580 actionEditOpenVymLink->setEnabled (false);
2581 actionEditDeleteVymLink->setEnabled (false);
2584 actionEditOpenVymLink->setEnabled (true);
2585 actionEditDeleteVymLink->setEnabled (true);
2588 if (bo->canMoveBranchUp())
2589 actionEditMoveUp->setEnabled (true);
2591 actionEditMoveUp->setEnabled (false);
2592 if (bo->canMoveBranchDown())
2593 actionEditMoveDown->setEnabled (true);
2595 actionEditMoveDown->setEnabled (false);
2598 actionEditToggleHideExport->setEnabled (true);
2599 actionEditToggleHideExport->setOn (bo->hideInExport() );
2601 actionEditCopy->setEnabled (true);
2602 actionEditCut->setEnabled (true);
2603 if (!clipboardEmpty)
2604 actionEditPaste->setEnabled (true);
2606 actionEditPaste->setEnabled (false);
2607 for (a=actionListBranches.first();a;a=actionListBranches.next())
2608 a->setEnabled(true);
2609 actionEditDelete->setEnabled (true);
2610 switch (selection->getFrameType())
2613 actionFormatFrameNone->setOn(true);
2616 actionFormatFrameRectangle->setOn(true);
2621 actionFormatIncludeImagesVer->setOn
2622 ( ((BranchObj*)selection)->getIncludeImagesVer());
2623 actionFormatIncludeImagesHor->setOn
2624 ( ((BranchObj*)selection)->getIncludeImagesHor());
2625 actionFormatHideLinkUnselected->setOn
2626 (selection->getHideLinkUnselected());
2628 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2630 FloatObj *fo=(FloatImageObj*)selection;
2631 standardFlagsDefault->setEnabled (false);
2633 actionEditOpenURL->setEnabled (false);
2634 actionEditOpenVymLink->setEnabled (false);
2635 actionEditDeleteVymLink->setEnabled (false);
2636 actionEditToggleHideExport->setEnabled (true);
2637 actionEditToggleHideExport->setOn (fo->hideInExport() );
2640 actionEditCopy->setEnabled (true);
2641 actionEditCut->setEnabled (true);
2642 actionEditPaste->setEnabled (false);
2643 for (a=actionListBranches.first();a;a=actionListBranches.next())
2644 a->setEnabled(false);
2645 actionEditDelete->setEnabled (true);
2646 actionFormatHideLinkUnselected->setOn
2647 ( selection->getHideLinkUnselected());
2648 actionEditMoveUp->setEnabled (false);
2649 actionEditMoveDown->setEnabled (false);
2654 standardFlagsDefault->setEnabled (false);
2656 actionEditCopy->setEnabled (false);
2657 actionEditCut->setEnabled (false);
2658 actionEditPaste->setEnabled (false);
2659 for (a=actionListBranches.first();a;a=actionListBranches.next())
2660 a->setEnabled(false);
2662 actionEditToggleScroll->setEnabled (false);
2663 actionEditOpenURL->setEnabled (false);
2664 actionEditOpenVymLink->setEnabled (false);
2665 actionEditDeleteVymLink->setEnabled (false);
2666 actionEditHeading2URL->setEnabled (false);
2667 actionEditDelete->setEnabled (false);
2668 actionEditMoveUp->setEnabled (false);
2669 actionEditMoveDown->setEnabled (false);
2670 actionEditToggleHideExport->setEnabled (false);
2674 void MapEditor::updateNoteFlag()
2677 if ( (typeid(*selection) == typeid(BranchObj)) ||
2678 (typeid(*selection) == typeid(MapCenterObj)) )
2679 ((BranchObj*)selection)->updateNoteFlag();
2682 void MapEditor::setLinkStyle (LinkStyle ls)
2686 saveState("Set link style"); // TODO undoCommand
2688 bo=mapCenter->first();
2692 bo->setLinkStyle(bo->getDefLinkStyle());
2695 mapCenter->reposition();
2698 LinkStyle MapEditor::getLinkStyle ()
2703 void MapEditor::setLinkColor(QColor c)
2709 void MapEditor::setLinkColorHint()
2711 // called from setLinkColorHint(lch) or at end of parse
2713 bo=mapCenter->first();
2721 void MapEditor::setLinkColorHint(LinkColorHint lch)
2727 void MapEditor::toggleLinkColorHint()
2729 if (linkcolorhint==HeadingColor)
2730 linkcolorhint=DefaultColor;
2732 linkcolorhint=HeadingColor;
2734 bo=mapCenter->first();
2742 LinkColorHint MapEditor::getLinkColorHint()
2744 return linkcolorhint;
2747 QColor MapEditor::getDefLinkColor()
2749 return defLinkColor;
2752 void MapEditor::setDefXLinkColor(QColor col)
2757 QColor MapEditor::getDefXLinkColor()
2759 return defXLinkColor;
2762 void MapEditor::setDefXLinkWidth (int w)
2767 int MapEditor::getDefXLinkWidth()
2769 return defXLinkWidth;
2772 void MapEditor::selectLinkColor()
2774 // Finish open lineEdits
2775 if (lineedit) finishedLineEdit();
2777 QColor col = QColorDialog::getColor( defLinkColor, this );
2778 if ( !col.isValid() ) return;
2779 setLinkColor( col );
2780 saveState(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2784 void MapEditor::toggleScroll()
2786 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2788 BranchObj *bo=((BranchObj*)selection);
2789 if (bo->countBranches()==0) return;
2790 if (bo->getDepth()==0) return;
2792 if (bo->isScrolled())
2796 saveState(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2803 void MapEditor::unScrollAll()
2806 bo=mapCenter->first();
2809 if (bo->isScrolled()) bo->toggleScroll();
2814 void MapEditor::loadFloatImage ()
2817 (typeid(*selection) == typeid(BranchObj)) ||
2818 (typeid(*selection) == typeid(MapCenterObj)) )
2820 BranchObj *bo=((BranchObj*)selection);
2822 QFileDialog *fd=new QFileDialog( this);
2823 fd->setMode (QFileDialog::ExistingFiles);
2824 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2825 ImagePreview *p =new ImagePreview (fd);
2826 fd->setContentsPreviewEnabled( TRUE );
2827 fd->setContentsPreview( p, p );
2828 fd->setPreviewMode( QFileDialog::Contents );
2829 fd->setCaption(__VYM " - " +tr("Load image"));
2830 fd->setDir (lastImageDir);
2834 if ( fd->exec() == QDialog::Accepted )
2836 saveState(selection, QString("Add floatimage to %1").arg(getName(selection)));
2837 lastImageDir=fn.left(fn.findRev ("/"));
2838 QStringList flist = fd->selectedFiles();
2839 QStringList::Iterator it = flist.begin();
2840 while( it != flist.end() )
2843 bo->addFloatImage();
2844 // TODO check if load was successful
2845 bo->getLastFloatImage()->load(*it);
2846 bo->getLastFloatImage()->setOriginalFilename(fn);
2850 mapCenter->reposition();
2859 void MapEditor::saveFloatImage (int item)
2862 (typeid(*selection) == typeid(FloatImageObj)) )
2864 FloatImageObj *fio=((FloatImageObj*)selection);
2865 const char* fmt = saveImageFormatMenu->text(item);
2867 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2868 fd->addFilter ("PNG (*.png)");
2869 fd->addFilter ("BMP (*.bmp)");
2870 fd->addFilter ("XBM (*.xbm)");
2871 fd->addFilter ("JPG (*.jpg)");
2872 fd->addFilter ("XPM (*.xpm)");
2873 fd->addFilter ("GIF (*.gif)");
2874 fd->addFilter ("PNM (*.pnm)");
2875 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2876 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2877 fd->setMode( QFileDialog::AnyFile );
2878 fd->setSelection (fio->getOriginalFilename());
2882 if ( fd->exec() == QDialog::Accepted )
2884 if (QFile (fd->selectedFile()).exists() )
2886 QMessageBox mb( __VYM,
2887 tr("The file %1 exists already.\n"
2888 "Do you want to overwrite it?").arg(fd->selectedFile()),
2889 QMessageBox::Warning,
2890 QMessageBox::Yes | QMessageBox::Default,
2891 QMessageBox::Cancel | QMessageBox::Escape,
2892 QMessageBox::QMessageBox::NoButton );
2894 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2895 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2898 case QMessageBox::Yes:
2901 case QMessageBox::Cancel:
2907 fio->save (fd->selectedFile(),fmt);
2912 void MapEditor::setFrame(const FrameType &t)
2915 (typeid(*selection) == typeid(BranchObj)) ||
2916 (typeid(*selection) == typeid(MapCenterObj)) )
2918 selection->setFrameType (t);
2919 mapCenter->reposition();
2920 selection->updateLink();
2924 void MapEditor::setIncludeImagesVer(bool b)
2927 (typeid(*selection) == typeid(BranchObj)) ||
2928 (typeid(*selection) == typeid(MapCenterObj)) )
2929 ((BranchObj*)selection)->setIncludeImagesVer(b);
2930 mapCenter->reposition();
2933 void MapEditor::setIncludeImagesHor(bool b)
2936 (typeid(*selection) == typeid(BranchObj)) ||
2937 (typeid(*selection) == typeid(MapCenterObj)) )
2938 ((BranchObj*)selection)->setIncludeImagesHor(b);
2939 mapCenter->reposition();
2942 void MapEditor::setHideLinkUnselected (bool b)
2945 (typeid(*selection) == typeid(BranchObj)) ||
2946 (typeid(*selection) == typeid(MapCenterObj)) ||
2947 (typeid(*selection) == typeid(FloatImageObj)) )
2948 selection->setHideLinkUnselected(b);
2951 void MapEditor::importDir(BranchObj *dst, QDir d)
2954 (typeid(*selection) == typeid(BranchObj)) ||
2955 (typeid(*selection) == typeid(MapCenterObj)) )
2959 // Traverse directories
2960 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2961 const QFileInfoList *dirlist = d.entryInfoList();
2962 QFileInfoListIterator itdir( *dirlist );
2965 while ( (fi = itdir.current()) != 0 )
2967 if (fi->fileName() != "." && fi->fileName() != ".." )
2970 bo=dst->getLastBranch();
2971 bo->setHeading (fi->fileName() );
2972 bo->setColor (QColor("blue"));
2974 if ( !d.cd(fi->fileName()) )
2975 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2978 // Recursively add subdirs
2986 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2987 const QFileInfoList *filelist = d.entryInfoList();
2988 QFileInfoListIterator itfile( *filelist );
2990 while ( (fi = itfile.current()) != 0 )
2993 bo=dst->getLastBranch();
2994 bo->setHeading (fi->fileName() );
2995 bo->setColor (QColor("black"));
2996 if (fi->fileName().right(4) == ".vym" )
2997 bo->setVymLink (fi->filePath());
3004 void MapEditor::importDir()
3007 (typeid(*selection) == typeid(BranchObj)) ||
3008 (typeid(*selection) == typeid(MapCenterObj)) )
3010 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
3011 fd->setMode (QFileDialog::DirectoryOnly);
3012 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3013 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
3017 if ( fd->exec() == QDialog::Accepted )
3019 BranchObj *bo=((BranchObj*)selection);
3020 importDir (bo,QDir(fd->selectedFile()) );
3021 mapCenter->reposition();
3028 void MapEditor::followXLink(int i)
3031 (typeid(*selection) == typeid(BranchObj)) ||
3032 (typeid(*selection) == typeid(MapCenterObj)) )
3034 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3037 selection->unselect();
3039 selection->select();
3040 ensureSelectionVisible();
3045 void MapEditor::editXLink(int i)
3048 (typeid(*selection) == typeid(BranchObj)) ||
3049 (typeid(*selection) == typeid(MapCenterObj)) )
3051 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3054 EditXLinkDialog dia;
3056 dia.setSelection(selection);
3057 if (dia.exec() == QDialog::Accepted)
3059 if (dia.useSettingsGlobal() )
3061 setDefXLinkColor (xlo->getColor() );
3062 setDefXLinkWidth (xlo->getWidth() );
3064 if (dia.deleteXLink())
3065 ((BranchObj*)selection)->deleteXLinkAt(i);
3066 saveState("Edit xLink"); //TODO undoCommand
3072 void MapEditor::testFunction()
3074 cout << "MapEditor::testFunction() called\n";
3077 dia.setCancelButton (true);
3078 dia.setText("This is a longer \nWarning");
3079 dia.setCaption("Warning: Flux problem");
3080 dia.setShowAgainName("/vym/warnings/mapeditor");
3081 if (dia.exec()==QDialog::Accepted)
3082 cout << "accepted!\n";
3084 cout << "canceled!\n";
3087 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
3088 QProcess *proc = new QProcess( this );
3089 proc->addArgument(ub);
3091 if ( !proc->start() )
3093 QMessageBox::warning(0,
3095 tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
3100 if (hidemode==HideNone)
3102 setHideTmpMode (HideExport);
3103 mapCenter->calcBBoxSizeWithChilds();
3104 QRect totalBBox=mapCenter->getTotalBBox();
3105 QRect mapRect=totalBBox;
3106 QCanvasRectangle *frame=NULL;
3108 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3110 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3111 totalBBox.width(), totalBBox.height());
3112 frame=new QCanvasRectangle (mapRect,mapCanvas);
3113 frame->setBrush (QColor(white));
3114 frame->setPen (QColor(black));
3120 setHideTmpMode (HideNone);
3122 cout <<" hidemode="<<hidemode<<endl;
3126 void MapEditor::ensureSelectionVisible()
3130 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3132 if (selection->getOrientation() == OrientLeftOfCenter)
3133 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3135 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3136 ensureVisible (p.x(), p.y() );
3141 void MapEditor::updateViewCenter()
3143 // Update movingCenter, so that we can zoom comfortably later
3144 QRect rc = QRect( contentsX(), contentsY(),
3145 visibleWidth(), visibleHeight() );
3146 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3147 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3148 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3151 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3153 // Lineedits are already closed by preceding
3154 // mouseEvent, we don't need to close here.
3156 QPoint p = inverseWorldMatrix().map(e->pos());
3157 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3160 { // MapObj was found
3161 if (selection != lmo)
3163 // select the MapObj
3164 if (selection) selection->unselect();
3166 selection->select();
3172 if (typeid(*selection)==typeid(BranchObj) ||
3173 typeid(*selection)==typeid(MapCenterObj) )
3175 // Context Menu on branch or mapcenter
3177 branchContextMenu->popup(e->globalPos() );
3179 if (typeid(*selection)==typeid(FloatImageObj))
3181 // Context Menu on floatimage
3183 floatimageContextMenu->popup(e->globalPos() );
3187 { // No MapObj found, we are on the Canvas itself
3188 // Context Menu on Canvas
3190 canvasContextMenu->popup(e->globalPos() );
3195 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3197 // Ignore right clicks, these will go to context menus
3198 if (e->button() == QMouseEvent::RightButton )
3204 // Finish open lineEdits
3205 if (lineedit) finishedLineEdit();
3207 QPoint p = inverseWorldMatrix().map(e->pos());
3208 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3212 //Take care of clickdesystem flags _or_ modifier modes
3214 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3215 typeid(*lmo)==typeid(MapCenterObj) ))
3217 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3218 if (!foname.isEmpty())
3220 // systemFlag clicked
3224 if (e->state() & QMouseEvent::ControlButton)
3225 mainWindow->editOpenURLTab();
3227 mainWindow->editOpenURL();
3229 else if (foname=="vymLink")
3231 mainWindow->editOpenVymLink();
3232 // tabWidget may change, better return now
3233 // before segfaulting...
3234 } else if (foname=="note")
3235 mainWindow->windowToggleNoteEditor();
3236 else if (foname=="hideInExport")
3241 // No system flag clicked, take care of modmodes
3243 // Special case: CTRL is pressed
3244 if (e->state() & QMouseEvent::ControlButton)
3246 if (actionModModeColor->isOn())
3249 setCursor (pickColorCursor);
3252 if (actionModModeLink->isOn())
3254 BranchObj *bo_begin=NULL;
3256 bo_begin=(BranchObj*)(lmo);
3259 ((typeid(*selection) == typeid(BranchObj)) ||
3260 (typeid(*selection) == typeid(MapCenterObj))) )
3261 bo_begin=(BranchObj*)selection;
3265 linkingObj_src=bo_begin;
3266 tmpXLink=new XLinkObj (mapCanvas);
3267 tmpXLink->setBegin (bo_begin);
3268 tmpXLink->setEnd (p);
3269 tmpXLink->setColor(defXLinkColor);
3270 tmpXLink->setWidth(defXLinkWidth);
3271 tmpXLink->updateXLink();
3272 tmpXLink->setVisibility (true);
3280 // Left Button Move Branches
3281 if (e->button() == QMouseEvent::LeftButton )
3283 movingObj_start.setX( p.x() - selection->x() );
3284 movingObj_start.setY( p.y() - selection->y() );
3285 movingObj_orgPos.setX (lmo->x() );
3286 movingObj_orgPos.setY (lmo->y() );
3288 // If modMode==copy, then we want to "move" the _new_ object around
3289 // then we need the offset from p to the _old_ selection, because of tmp
3290 if (actionModModeCopy->isOn() &&
3291 e->state() & QMouseEvent::ControlButton)
3293 if (typeid(*selection)==typeid(BranchObj) )
3296 mapCenter->addBranch ((BranchObj*)selection);
3298 selection=mapCenter->getLastBranch();
3299 selection->select();
3300 mapCenter->reposition();
3303 movingObj=selection;
3305 // Middle Button Toggle Scroll
3306 // (On Mac OS X this won't work, but we still have
3307 // a button in the toolbar)
3308 if (e->button() == QMouseEvent::MidButton )
3312 { // No MapObj found, we are on the Canvas itself
3313 // Left Button move Pos of CanvasView
3314 if (e->button() == QMouseEvent::LeftButton )
3316 movingObj=NULL; // move Content not Obj
3317 movingObj_start=e->globalPos();
3318 movingCont_start=QPoint (contentsX(), contentsY() );
3319 movingVec=QPoint(0,0);
3320 setCursor(handOpenCursor);
3325 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3327 QPoint p = inverseWorldMatrix().map(e->pos());
3329 // Move the selected MapObj
3330 if ( selection && movingObj)
3332 // To avoid jumping of the CanvasView, only
3333 // ensureSelectionVisible, if not tmp linked
3334 if (!selection->hasParObjTmp())
3335 ensureSelectionVisible ();
3337 // Now move the selection, but add relative position
3338 // (movingObj_start) where selection was chosen with
3339 // mousepointer. (This avoids flickering resp. jumping
3340 // of selection back to absPos)
3342 LinkableMapObj *lmosel;
3343 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3345 // Check if we could link
3346 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3349 if (typeid(*selection) == typeid(FloatImageObj))
3351 FloatObj *fo=(FloatObj*)selection;
3353 "move "+qpointToString(movingObj_orgPos),fo->getSelectString() ,
3354 QString("Move %1").arg(getName(selection)));
3355 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3359 // Relink float to new mapcenter or branch, if shift is pressed
3360 // Only relink, if selection really has a new parent
3361 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3362 ( (typeid(*lmo)==typeid(BranchObj)) ||
3363 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3364 ( lmo != fo->getParObj())
3367 if (typeid(*fo) == typeid(FloatImageObj))
3369 saveState(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3370 FloatImageObj *fio=(FloatImageObj*)(fo);
3371 ((BranchObj*)(lmo))->addFloatImage (fio);
3373 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3374 fio=((BranchObj*)(lmo))->getLastFloatImage();
3377 selection=(LinkableMapObj*)(fio);
3378 selection->select();
3379 movingObj=(MapObj*)(fio);
3382 } else // selection != a FloatObj
3384 if (lmosel->getDepth()==0)
3386 if (e->state() == (LeftButton | !ShiftButton))
3387 // If mapCenter is moved, move all the rest by default, too.
3388 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3390 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3393 if (lmosel->getDepth()==1)
3395 // depth==1, mainbranch
3396 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3400 if (lmosel->getOrientation() == OrientLeftOfCenter)
3401 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3402 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3403 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3405 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3407 // reposition subbranch
3408 lmosel->reposition();
3409 //ensureSelectionVisible();
3411 if (lmo && (lmo!=selection) &&
3412 (typeid(*lmo) == typeid(BranchObj) ||
3413 (typeid(*lmo) == typeid(MapCenterObj) )
3416 if (e->state() & QMouseEvent::ControlButton)
3418 // Special case: CTRL to link below lmo
3419 lmosel->setParObjTmp (lmo,p,+1);
3421 else if (e->state() & QMouseEvent::ShiftButton)
3422 lmosel->setParObjTmp (lmo,p,-1);
3424 lmosel->setParObjTmp (lmo,p,0);
3427 lmosel->unsetParObjTmp();
3428 /* FIXME not needed anymore?
3429 if (lmo &&(lmo==selection))
3430 // Could link to myself (happens sometimes...)
3431 lmosel->unsetParObjTmp();
3433 // no Obj under selection, go back to original Parent
3434 lmosel->unsetParObjTmp();
3439 } // no FloatImageObj
3443 } // selection && moving_obj
3445 // Draw a link from one branch to another
3448 tmpXLink->setEnd (p);
3449 tmpXLink->updateXLink();
3453 if (!movingObj && !pickingColor &&!drawingLink)
3455 QPoint p=e->globalPos();
3456 movingVec.setX(-p.x() + movingObj_start.x() );
3457 movingVec.setY(-p.y() + movingObj_start.y() );
3458 setContentsPos( movingCont_start.x() + movingVec.x(),
3459 movingCont_start.y() + movingVec.y());
3466 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3468 LinkableMapObj *dst;
3469 // Have we been picking color?
3473 setCursor (ArrowCursor);
3474 // Check if we are over another branch
3475 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3476 if (dst && selection)
3478 if (e->state() & QMouseEvent::ShiftButton)
3480 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3481 ((BranchObj*)selection)->setLinkColor ();
3485 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3486 ((BranchObj*)selection)->setLinkColor ();
3492 // Have we been drawing a link?
3496 // Check if we are over another branch
3497 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3498 if (dst && selection)
3500 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3501 tmpXLink->updateXLink();
3502 tmpXLink->activate();
3503 saveState(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3512 // Have we been moving something?
3513 if ( selection && movingObj )
3515 // Moved FloatObj? Maybe we need to reposition
3516 if(typeid(*selection)==typeid (FloatImageObj))
3518 selection->getParObj()->requestReposition();
3519 mapCenter->reposition();
3522 // Check if we are over another branch, but ignore
3523 // any found LMOs, which are FloatObjs
3524 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3525 ((LinkableMapObj*)selection) );
3528 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3531 // Now check, if we have been moving a branch
3532 if (typeid(*selection) == typeid(BranchObj) )
3534 // save the position in case we link to mapcenter
3535 QPoint savePos=QPoint (selection->x(),selection->y() );
3537 // Reset the temporary drawn link to the original one
3538 ((LinkableMapObj*)selection)->unsetParObjTmp();
3544 BranchObj* bs=((BranchObj*)selection);
3545 QString undoCom="linkBranchToPos (\""+
3546 (bs->getParObj())->getSelectString()+
3548 QString("%1").arg(bs->getNum())+
3550 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3552 // TODO we also could check, if dest and src are on same branch,
3553 // then it would be sufficient to saveState of this branch
3555 // Modifiers allow to insert above/below dst
3556 if (e->state() & QMouseEvent::ShiftButton)
3558 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3560 if (e->state() & QMouseEvent::ControlButton)
3562 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3565 bs->moveBranchTo ((BranchObj*)(dst),-1);
3566 if (dst->getDepth()==0)
3569 saveState (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) );
3571 if (selection->getDepth()==1)
3572 // If we have moved mainbranch only save endposition
3573 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos)));
3575 // Draw the original link, before selection was moved around
3576 mapCenter->reposition();
3578 // Finally resize canvas, if needed
3583 // maybe we moved View: set old cursor
3584 setCursor (ArrowCursor);
3588 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3590 // Finish open lineEdits
3591 if (lineedit) finishedLineEdit();
3593 if (e->button() == QMouseEvent::LeftButton )
3595 QPoint p = inverseWorldMatrix().map(e->pos());
3596 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3597 if (lmo) { // MapObj was found
3598 // First select the MapObj than edit heading
3599 if (selection) selection->unselect();
3601 selection->select();
3607 void MapEditor::resizeEvent (QResizeEvent* e)
3609 QCanvasView::resizeEvent( e );
3613 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3616 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3617 // cerr << event->format(i) << endl;
3620 (typeid(*selection) == typeid(BranchObj)) ||
3621 (typeid(*selection) == typeid(MapCenterObj))) {
3623 // If QImageDrag can decode mime type
3624 if (QImageDrag::canDecode(event)) {
3629 // If image are dragged from firefox
3630 if (event->provides("application/x-moz-file-promise-url") &&
3631 event->provides("application/x-moz-nativeimage")) {
3632 event->accept(true);
3636 // If QUriDrag can decode mime type
3637 if (QUriDrag::canDecode(event)) {
3642 // If Uri are dragged from firefox
3643 if (event->provides("_NETSCAPE_URL")){
3648 // If QTextDrag can decode mime type
3649 if (QTextDrag::canDecode(event)) {
3658 bool isUnicode16(const QByteArray &d)
3660 // TODO: make more precise check for unicode 16.
3661 // Guess unicode16 if any of second bytes are zero
3662 unsigned int length = max(0,d.size()-2)/2;
3663 for (unsigned int i = 0; i<length ; i++)
3664 if (d.at(i*2+1)==0) return true;
3668 void MapEditor::contentsDropEvent(QDropEvent *event)
3671 (typeid(*selection) == typeid(BranchObj)) ||
3672 (typeid(*selection) == typeid(MapCenterObj)))
3677 if (event->provides("image/png"))
3680 if (QImageDrag::decode(event, pix))
3688 } else if (event->provides("application/x-moz-file-promise-url") &&
3689 event->provides("application/x-moz-nativeimage"))
3691 // Contains url to the img src in unicode16
3692 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3693 QString url = QString((const QChar*)d.data(),d.size()/2);
3697 } else if (event->provides ("text/uri-list"))
3698 { // Uris provided e.g. by konqueror
3699 QUriDrag::decode (event,uris);
3700 } else if (event->provides ("_NETSCAPE_URL"))
3701 { // Uris provided by Mozilla
3702 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3705 } else if (event->provides("text/html")) {
3707 // Handels text mime types
3708 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3709 QByteArray d = event->encodedData("text/html");
3712 text = QString((const QChar*)d.data(),d.size()/2);
3716 textEditor->setText(text);
3720 } else if (event->provides("text/plain")) {
3721 QByteArray d = event->encodedData("text/plain");
3724 text = QString((const QChar*)d.data(),d.size()/2);
3728 textEditor->setText(text);
3740 for (const char* u=uris.first(); u; u=uris.next())
3742 bo=((BranchObj*)selection)->addBranch();
3745 s=QUriDrag::uriToLocalFile(u);
3747 QString file = QDir::convertSeparators(s);
3748 heading = QFileInfo(file).baseName();
3750 if (file.endsWith(".vym", false))
3751 bo->setVymLink(file);
3760 bo->setHeading(heading);
3770 //FIXME saveState has to be called earlier for each of the drops...
3771 saveState("Drop Event"); //TODO undo Command
3772 mapCenter->reposition();
3779 void MapEditor::addFloatImage(const QPixmap &img)
3782 (typeid(*selection) == typeid(BranchObj)) ||
3783 (typeid(*selection) == typeid(MapCenterObj)) )
3785 BranchObj *bo=((BranchObj*)selection);
3786 saveState(selection,QString("Add floatimage to %1").arg(getName(bo)));
3787 //QString fn=fd->selectedFile();
3788 //lastImageDir=fn.left(fn.findRev ("/"));
3789 bo->addFloatImage();
3790 // FIXME check if load was successful
3791 bo->getLastFloatImage()->load(img);
3792 //bo->getLastFloatImage()->setOriginalFilename(fn);
3793 mapCenter->reposition();
3800 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3802 if (!imageBuffer) imageBuffer = new QBuffer();
3803 if (!imageBuffer->isOpen()) {
3804 imageBuffer->open(IO_WriteOnly | IO_Append);
3806 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3810 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3812 if (nop->state()==QNetworkProtocol::StDone) {
3813 QPixmap img(imageBuffer->buffer());
3818 imageBuffer->close();
3820 imageBuffer->close();
3827 void MapEditor::fetchImage(const QString &url)
3830 urlOperator->stop();
3831 disconnect(urlOperator);
3835 urlOperator = new QUrlOperator(url);
3836 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3837 this, SLOT(imageDataFinished(QNetworkOperation*)));
3839 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3840 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));