3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <q3popupmenu.h>
9 #include <q3paintdevicemetrics.h>
11 #include <q3filedialog.h>
14 #include <qcolordialog.h>
16 #include <q3process.h>
17 #include <qinputdialog.h>
18 #include <q3dragobject.h>
19 #include <q3urloperator.h>
20 #include <q3networkprotocol.h>
23 #include <QResizeEvent>
24 #include <QContextMenuEvent>
27 #include <QMouseEvent>
28 #include <QDragEnterEvent>
29 #include <QTextStream>
31 #include <QActionGroup>
41 #include "editxlinkdialog.h"
43 #include "extrainfodialog.h"
45 #include "linkablemapobj.h"
46 #include "mainwindow.h"
49 #include "texteditor.h"
50 #include "warningdialog.h"
54 extern TextEditor *textEditor;
55 extern int statusbarTime;
56 extern Main *mainWindow;
57 extern QString tmpVymDir;
58 extern QString clipboardDir;
59 extern bool clipboardEmpty;
60 extern FlagRowObj *systemFlagsDefault;
61 extern FlagRowObj *standardFlagsDefault;
63 extern Q3PtrList <QAction> actionListBranches;
65 extern QAction *actionFileSave;
66 extern QAction *actionEditUndo;
67 extern QAction *actionEditCopy;
68 extern QAction *actionEditCut;
69 extern QAction *actionEditPaste;
70 extern QAction *actionEditMoveUp;
71 extern QAction *actionEditMoveDown;
72 extern QAction *actionEditToggleScroll;
73 extern QAction *actionEditOpenURL;
74 extern QAction *actionEditOpenURLTab;
75 extern QAction *actionEditURL;
76 extern QAction *actionEditHeading2URL;
77 extern QAction *actionEditBugzilla2URL;
78 extern QAction *actionEditFATE2URL;
79 extern QAction *actionEditOpenVymLink;
80 extern QAction *actionEditVymLink;
81 extern QAction *actionEditDeleteVymLink;
82 extern QAction *actionEditToggleHideExport;
83 extern QAction *actionEditHeading;
84 extern QAction *actionEditDelete;
85 extern QAction *actionEditAddBranch;
86 extern QAction *actionEditAddBranchAbove;
87 extern QAction *actionEditAddBranchBelow;
88 extern QAction *actionEditRemoveBranchHere;
89 extern QAction *actionEditRemoveChilds;
90 extern QAction *actionEditImportAdd;
91 extern QAction *actionEditImportReplace;
92 extern QAction *actionEditSaveBranch;
93 extern QAction *actionEditSelectFirst;
94 extern QAction *actionEditSelectLast;
95 extern QAction *actionEditLoadImage;
97 extern QAction* actionFormatPickColor;
98 extern QAction* actionFormatColorBranch;
99 extern QAction* actionFormatColorSubtree;
100 extern QAction *actionFormatLinkColorHint;
101 extern QAction *actionFormatBackColor;
102 extern QAction *actionFormatLinkColor;
104 extern QActionGroup* actionGroupModModes;
105 extern QAction* actionModModeColor;
106 extern QAction* actionModModeLink;
107 extern QAction* actionModModeCopy;
109 extern QActionGroup *actionGroupFormatFrameTypes;
110 extern QAction *actionFormatFrameNone;
111 extern QAction *actionFormatFrameRectangle;
113 extern QActionGroup *actionGroupFormatLinkStyles;
114 extern QAction *actionFormatIncludeImagesVer;
115 extern QAction *actionFormatIncludeImagesHor;
116 extern QAction *actionFormatHideLinkUnselected;
117 extern QAction *actionFormatLinkStyleLine;
118 extern QAction *actionFormatLinkStyleParabel;
119 extern QAction *actionFormatLinkStylePolyLine;
120 extern QAction *actionFormatLinkStylePolyParabel;
122 extern QAction *actionViewToggleNoteEditor;
124 extern QAction *actionSettingsAutoedit;
125 extern QAction *actionSettingsAutoselectHeading;
126 extern QAction *actionSettingsAutoselectText;
127 extern QAction *actionSettingsPasteNewHeading;
128 extern QAction *actionSettingsUseFlagGroups;
130 extern QMenu* branchContextMenu;
131 extern QMenu* branchAddContextMenu;
132 extern QMenu* branchRemoveContextMenu;
133 extern QMenu* branchLinksContextMenu;
134 extern QMenu* branchLinksContextMenuDup;
135 extern QMenu* floatimageContextMenu;
136 extern QMenu* saveImageFormatMenu;
137 extern QMenu* canvasContextMenu;
138 extern QMenu* lastMapsMenu;
139 extern QMenu* importMenu;
140 extern QMenu* exportMenu;
143 extern Settings settings;
144 extern ImageIO imageIO;
146 extern QString iconPath;
147 extern QDir vymBaseDir;
148 extern QDir lastImageDir;
150 int MapEditor::mapNum=0; // make instance
152 ///////////////////////////////////////////////////////////////////////
153 ///////////////////////////////////////////////////////////////////////
154 MapEditor::MapEditor(
155 QWidget* parent, bool interactive, const char* name, Qt::WFlags f) :
156 Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
158 //cout << "Constructor ME "<<this<<endl;
161 viewport()->setAcceptDrops(true);
163 mapCanvas = new Q3Canvas(1000,800);
164 mapCanvas->setAdvancePeriod(30);
165 mapCanvas->setBackgroundColor (Qt::white);
167 setCanvas (mapCanvas);
169 // Always show scroll bars (automatic would flicker sometimes)
170 setVScrollBarMode ( Q3ScrollView::AlwaysOn );
171 setHScrollBarMode ( Q3ScrollView::AlwaysOn );
173 mapCenter = new MapCenterObj(mapCanvas);
174 mapCenter->setVisibility (true);
175 mapCenter->setMapEditor (this);
176 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
177 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
181 lineedit = new QLineEdit(this, "lineedit" );
182 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEdit() ) );
185 actColor=Qt::black; setColor (actColor);
186 defLinkColor=QColor (0,0,255);
187 defXLinkColor=QColor (180,180,180);
188 linkcolorhint=DefaultColor;
189 linkstyle=StylePolyParabel;
191 // Create bitmap cursors, patform dependant
192 #if defined(Q_OS_MACX)
193 handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png") );
194 // set hot spot to tip of picker
195 pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 );
197 handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen16.png"));
198 // set hot spot to tip of picker
199 pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
212 defXLinkColor=QColor (230,230,230);
220 fileName=tr("unnamed");
223 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
227 // Initialize find routine
234 blockReposition=false;
235 blockSaveState=false;
239 isInteractive=interactive;
241 // Create temporary files
244 // Initially set movingCentre
247 // For testing purposes create history window
248 historyWindow = new ShowTextDialog (this);
249 historyWindow->setCaption (fileName);
251 mapCenter->reposition(); // for positioning heading
254 MapEditor::~MapEditor()
256 if (imageBuffer) delete imageBuffer;
262 //cout <<"Destructor MapEditor\n";
265 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
269 QColor MapEditor::color()
274 QColor MapEditor::backgroundColor()
276 return mapCanvas->backgroundColor();
279 MapCenterObj* MapEditor::getMapCenter()
284 Q3Canvas* MapEditor::getCanvas()
289 void MapEditor::adjustCanvasSize()
291 // To adjust the canvas to map, viewport size and position, we have to
292 // do some coordinate magic...
294 // Get rectangle of (scroll-)view.
295 // We want to be in canvas coords, so
296 // we map. Important if view is zoomed...
297 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
298 visibleWidth(), visibleHeight()) );
300 // Now we need the bounding box of view AND map to calc the correct canvas size.
301 // Why? Because if the map itself is moved out of view, the view has to be enlarged
302 // to avoid jumping aroung...
303 QRect map=mapCenter->getTotalBBox();
305 // right edge - left edge
306 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
307 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
310 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
311 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
314 // move the map on canvas (in order to not move it on screen) this is neccessary
315 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
316 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
317 // to scroll to an empty area of canvas to the left.
318 // b) if topleft corner of map left of or above topleft of canvas
322 if (cw > mapCanvas->width() )
324 if (map.x()<0) dx=-map.x();
326 if (cw < mapCanvas->width() )
327 dx=-min (view.x(),map.x());
328 if (ch > mapCanvas->height() )
330 if (map.y()<0) dy=-map.y();
332 if (ch < mapCanvas->height() )
334 dy=-min (view.y(),map.y());
336 // We really have to resize now. Let's go...
337 mapCanvas->resize (cw,ch);
338 if ( (dx!=0) || (dy!=0) )
340 mapCenter->moveAllBy(dx,dy);
341 mapCenter->reposition();
342 // mapCenter->positionBBox(); // To move float
344 // scroll the view (in order to not move map on screen)
350 bool MapEditor::isRepositionBlocked()
352 return blockReposition;
355 QString MapEditor::getName (LinkableMapObj *lmo)
358 if (!lmo) return QString("Error: NULL has no name!");
360 if ((typeid(*lmo) == typeid(BranchObj) ||
361 typeid(*lmo) == typeid(MapCenterObj)))
364 s=(((BranchObj*)lmo)->getHeading());
365 if (s=="") s="unnamed";
366 return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
368 if ((typeid(*lmo) == typeid(FloatImageObj) ))
369 return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
370 return QString("Unknown type has no name!");
373 void MapEditor::makeTmpDirs()
375 // Create unique temporary directories
376 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
378 d.mkdir (tmpMapDir,true);
381 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
383 // tmpdir temporary directory to which data will be written
384 // prefix mapname, which will be appended to images etc.
385 // writeflags Only write flags for "real" save of map, not undo
386 // offset offset of bbox of whole map in canvas.
387 // Needed for XML export
403 ls="StylePolyParabel";
407 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
409 if (linkcolorhint==HeadingColor)
410 colhint=attribut("linkColorHint","HeadingColor");
412 QString mapAttr=attribut("version",__VYM_VERSION);
414 mapAttr+= attribut("author",mapCenter->getAuthor()) +
415 attribut("comment",mapCenter->getComment()) +
416 attribut("date",mapCenter->getDate()) +
417 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
418 attribut("linkStyle", ls ) +
419 attribut("linkColor", defLinkColor.name() ) +
420 attribut("defXLinkColor", defXLinkColor.name() ) +
421 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
423 s+=beginElement("vymmap",mapAttr);
426 // Find the used flags while traversing the tree
427 standardFlagsDefault->resetUsedCounter();
429 // Reset the counters before saving
430 FloatImageObj (mapCanvas).resetSaveCounter();
432 // Build xml recursivly
434 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
437 if ( typeid(*saveSelection) == typeid(BranchObj) )
438 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
439 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
440 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
442 else if (selection && typeid(*selection)==typeid(BranchObj))
443 // This is used if selected branch is saved from mainwindow
444 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
447 // Save local settings
448 s+=settings.getXMLData (destPath);
451 if (selection && !saveSelection )
452 s+=valueElement("select",selection->getSelectString());
455 s+=endElement("vymmap");
458 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
462 void MapEditor::saveState(const QString &comment)
465 saveState (CompleteMap,"",NULL,"",NULL, comment);
468 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &comment)
470 // save the given part of the map
471 saveState (PartOfMap,"",undoSel,"",NULL, comment);
474 void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment)
476 // selection does not change during action,
477 // so just save commands for undo and redo
478 LinkableMapObj *unsel;
483 saveState (UndoCommand,uc,unsel,rc,unsel, comment);
486 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel, const QString &comment)
488 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL, comment);
491 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel, const QString &comment)
495 if (blockSaveState) return;
497 /* TODO remove after testing
498 cout << "ME::saveState() begin\n"<<endl;
499 cout << " undosTotal="<<undosTotal<<endl;
500 cout << " undosAvail="<<undosAvail<<endl;
501 cout << " undoNum="<<undoNum<<endl;
502 cout << " ---------------------------"<<endl;
505 historyWindow->append (comment);
509 // Find out current undo directory
510 if (undosAvail<undosTotal) undosAvail++;
512 if (undoNum>undosTotal) undoNum=1;
515 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
516 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
518 // Create bakMapDir if not available
521 makeSubDirs (bakMapDir);
523 // Save current selection
524 QString redoSelection="";
526 redoSelection=redoSel->getSelectString();
528 // Save the object, which should be undone
529 QString undoSelection="";
531 undoSelection=undoSel->getSelectString();
533 // Save depending on how much needs to be saved
534 QString undoCommand="";
535 if (savemode==UndoCommand)
540 else if (savemode==PartOfMap && undoSel)
542 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
543 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
546 undoCommand="undoMap (\""+bakMapPath+"\")";
547 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
550 if (!backupXML.isEmpty())
551 // Write XML Data to disk
552 saveStringToDisk (QString(bakMapPath),backupXML);
555 set.setEntry (QString("undoCommand"),undoCommand);
556 set.setEntry (QString("undoSelection"),undoSelection);
557 set.setEntry (QString("redoCommand"),redoCom);
558 set.setEntry (QString("redoSelection"),redoSelection);
559 set.setEntry (QString("comment"),comment);
560 set.writeSettings(QString(bakMapDir+"/commands"));
562 /* TODO remove after testing
563 cout << " into="<< bakMapDir<<endl;
564 cout << " undosAvail="<<undosAvail<<endl;
565 cout << " undoNum="<<undoNum<<endl;
566 cout << " ---------------------------"<<endl;
567 cout << " comment="<<comment<<endl;
568 cout << " ---------------------------"<<endl;
569 cout << " undoCom="<<undoCommand<<endl;
570 cout << " undoSel="<<undoSelection<<endl;
571 cout << " ---------------------------"<<endl;
572 cout << " redoCom="<<redoCom<<endl;
573 cout << " redoSel="<<redoSelection<<endl;
574 cout << " ---------------------------"<<endl<<endl;
578 void MapEditor::parseAtom(const QString &atom)
585 // Split string s into command and parameters
586 api.parseCommand (atom);
587 QString com=api.command();
590 if (com=="moveBranchUp")
592 else if (com=="moveBranchDown")
594 else if (com=="move")
596 if (api.checkParamCount(2) && selection )
606 else if (com=="linkBranchToPos")
608 if (selection && typeid(*selection) == typeid(BranchObj) )
610 if (api.checkParamCount(4))
612 s=api.parString(ok,0);
613 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
616 if (typeid(*dst) == typeid(BranchObj) )
618 // Get number in parent
621 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
622 } else if (typeid(*dst) == typeid(MapCenterObj) )
624 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
625 // Get coordinates of mainbranch
630 if (ok) ((BranchObj*)selection)->move (x,y);
636 } else if (com=="setHeading")
638 if (api.checkParamCount(1))
640 s=api.parString (ok,0);
641 if (ok) setHeading (s);
643 } else if (com=="setURL")
645 if (api.checkParamCount(1))
647 s=api.parString (ok,0);
650 } else if (com=="setVymLink")
652 if (api.checkParamCount(1))
654 s=api.parString (ok,0);
655 if (ok) setVymLink(s);
658 // Internal commands, used for undo etc.
659 else if (com==QString("undoMap"))
661 if (api.checkParamCount(1))
662 undoXML("",api.parString (ok,0));
663 } else if (com==QString("undoPart"))
665 if (api.checkParamCount(2))
667 s=api.parString (ok,0);
668 t=api.parString (ok,1);
671 } else if (com=="select")
672 if (api.checkParamCount(1))
674 s=api.parString(ok,0);
679 api.setError ("Unknown command in: "+atom);
680 cout << "ME::parse api should have error now...\n";
686 qWarning("MapEditor::parseAtom: Error!");
687 qWarning(api.errorDesc());
692 void MapEditor::finishedLineEdit()
694 // This is called by finishedLineEdit or any MapEditor method,
695 // which wants to assure, that lineedits finish, before e.g. a branch is
698 // After calling LineEdit and using the clipboard, the
699 // focus is not any longer on the main widget, we
700 // have to restore it using parentWidget()->setFocus()
704 saveState("setHeading (\""+editingBO->getHeading()+"\")",editingBO, QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(lineedit->text()) );
705 editingBO->setHeading(lineedit->text() );
707 lineedit->releaseKeyboard();
709 parentWidget()->setFocus();
710 mapCenter->reposition();
712 ensureSelectionVisible();
716 void MapEditor::toggleHistoryWindow()
718 if (historyWindow->isVisible())
719 historyWindow->hide();
721 historyWindow->show();
725 bool MapEditor::isDefault()
730 bool MapEditor::isUnsaved()
735 bool MapEditor::hasChanged()
740 void MapEditor::setChanged()
745 actionEditUndo->setEnabled (true);
746 actionFileSave->setEnabled (true);
750 void MapEditor::closeMap()
752 // Finish open lineEdits
753 if (lineedit) finishedLineEdit();
755 // Unselect before disabling the toolbar actions
756 if (selection) selection->unselect();
764 void MapEditor::setFilePath(QString fname)
766 setFilePath (fname,fname);
769 void MapEditor::setFilePath(QString fname, QString destname)
771 if (fname.isEmpty() || fname=="")
778 filePath=fname; // becomes absolute path
779 fileName=fname; // gets stripped of path
780 destPath=destname; // needed for vymlinks
782 // If fname is not an absolute path, complete it
783 filePath=QDir(fname).absPath();
784 fileDir=filePath.left (1+filePath.findRev ("/"));
786 // Set short name, too. Search from behind:
787 int i=fileName.findRev("/");
788 if (i>=0) fileName=fileName.remove (0,i+1);
790 // Forget the .vym (or .xml) for name of map
791 mapName=fileName.left(fileName.findRev(".",-1,true) );
793 // Adjust history window
794 historyWindow->setCaption (fileName);
798 QString MapEditor::getFilePath()
803 QString MapEditor::getFileName()
808 QString MapEditor::getMapName()
813 QString MapEditor::getDestPath()
818 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
820 // Finish open lineEdits
821 if (lineedit) finishedLineEdit();
823 ErrorCode err=success;
827 if (selection) selection->unselect();
830 mapCenter->setMapEditor(this);
831 // (map state is set later at end of load...)
834 saveState(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)
889 // Finish open lineEdits
890 if (lineedit) finishedLineEdit();
894 // The SaveMode UndoCommand is not supported here
895 if (savemode==UndoCommand) return 1;
897 // Create mapName and fileDir
898 makeSubDirs (fileDir);
902 fname=mapName+".xml";
904 // use name given by user, even if he chooses .doc
909 if (savemode==CompleteMap || selection==NULL)
910 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
912 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
914 if (!saveStringToDisk(fileDir+fname,saveFile))
921 actionFileSave->setEnabled(false);
927 void MapEditor::setZipped (bool z)
932 bool MapEditor::saveZipped ()
937 void MapEditor::print()
939 // Finish open lineEdits
940 if (lineedit) finishedLineEdit();
944 printer = new QPrinter;
945 printer->setColorMode (QPrinter::Color);
946 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
949 QRect totalBBox=mapCenter->getTotalBBox();
951 // Try to set orientation automagically
952 // Note: Interpretation of generated postscript is amibiguous, if
953 // there are problems with landscape mode, see
954 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
956 if (totalBBox.width()>totalBBox.height())
957 // recommend landscape
958 printer->setOrientation (QPrinter::Landscape);
960 // recommend portrait
961 printer->setOrientation (QPrinter::Portrait);
963 if ( printer->setup(this) )
964 // returns false, if printing is canceled
966 QPainter pp(printer);
968 // Don't print the visualisation of selection
969 LinkableMapObj *oldselection=NULL;
972 oldselection=selection;
973 selection->unselect();
976 // Handle sizes of map and paper:
978 // setWindow defines which part of the canvas will be transformed
979 // setViewport defines area on paper in device coordinates (dpi)
980 // e.g. (0,50,700,700) is upper part on A4
981 // see also /usr/lib/qt3/doc/html/coordsys.html
983 Q3PaintDeviceMetrics metrics (printer);
985 double paperAspect = (double)metrics.width() / (double)metrics.height();
986 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
988 QRect mapRect=totalBBox;
989 Q3CanvasRectangle *frame=NULL;
990 Q3CanvasText *footerFN=NULL;
991 Q3CanvasText *footerDate=NULL;
992 if (printFrame || printFooter)
997 // Print frame around map
998 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
999 totalBBox.width()+20, totalBBox.height()+20);
1000 frame=new Q3CanvasRectangle (mapRect,mapCanvas);
1001 frame->setBrush (QColor(Qt::white));
1002 frame->setPen (QColor(Qt::black));
1006 /* TODO remove after testing
1007 QCanvasLine *l=new QCanvasLine (mapCanvas);
1008 l->setPoints (0,0,mapRect.width(),mapRect.height());
1009 l->setPen (QPen(QColor(black), 1));
1016 // Print footer below map
1018 font.setPointSize(10);
1019 footerFN=new Q3CanvasText (mapCanvas);
1020 footerFN->setText ("VYM - " + fileName);
1021 footerFN->setFont(font);
1022 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1023 footerFN->setZ(Z_TEXT);
1025 footerDate=new Q3CanvasText (mapCanvas);
1026 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1027 footerDate->setFont(font);
1028 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1029 footerDate->setZ(Z_TEXT);
1032 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1035 pp.setWindow (mapRect);
1038 if (mapAspect>=paperAspect)
1040 // Fit horizontally to paper width
1041 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1044 // Fit vertically to paper height
1045 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1048 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1050 // Delete Frame and footer
1054 delete (footerDate);
1056 if (frame) delete (frame);
1058 // Restore selection
1061 selection=oldselection;
1062 selection->select();
1065 // Save settings in vymrc
1066 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1070 QPixmap MapEditor::getPixmap()
1072 QRect mapRect=mapCenter->getTotalBBox();
1073 QPixmap pix (mapRect.size());
1076 // Don't print the visualisation of selection
1077 LinkableMapObj *oldselection=NULL;
1080 oldselection=selection;
1081 selection->unselect();
1084 pp.setWindow (mapRect);
1086 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1089 // Restore selection
1092 selection=oldselection;
1093 selection->select();
1099 void MapEditor::setHideTmpMode (HideTmpMode mode)
1102 mapCenter->setHideTmp (hidemode);
1103 mapCenter->reposition();
1108 HideTmpMode MapEditor::getHideTmpMode()
1113 void MapEditor::exportImage(QString fn)
1115 // Finish open lineEdits
1116 if (lineedit) finishedLineEdit();
1118 setExportMode (true);
1119 QPixmap pix (getPixmap());
1120 pix.save(fn, "PNG");
1121 setExportMode (false);
1124 void MapEditor::setExportMode (bool b)
1126 // should be called before and after exports
1127 // depending on the settings
1128 if (b && settings.value("/vym/export/useHideExport","yes")=="yes")
1129 setHideTmpMode (HideExport);
1131 setHideTmpMode (HideNone);
1134 void MapEditor::exportImage(QString fn, QString format)
1136 // Finish open lineEdits
1137 if (lineedit) finishedLineEdit();
1139 setExportMode (true);
1140 QPixmap pix (getPixmap());
1141 pix.save(fn, format);
1142 setExportMode (false);
1145 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1149 ex.setMapCenter(mapCenter);
1150 if (ex.setConfigFile(cf))
1152 setExportMode (true);
1153 ex.exportPresentation();
1154 setExportMode (false);
1160 void MapEditor::exportXML(const QString &dir)
1162 // Hide stuff during export, if settings want this
1163 setExportMode (true);
1165 // Create subdirectories
1168 // write to directory
1169 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1172 file.setName ( dir + "/"+mapName+".xml");
1173 if ( !file.open( QIODevice::WriteOnly ) )
1175 // This should neverever happen
1176 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1180 // Write it finally, and write in UTF8, no matter what
1181 QTextStream ts( &file );
1182 ts.setEncoding (QTextStream::UnicodeUTF8);
1186 // Now write image, too
1187 exportImage (dir+"/images/"+mapName+".png");
1189 setExportMode (false);
1192 void MapEditor::clear()
1196 selection->unselect();
1203 void MapEditor::copy()
1205 // Finish open lineEdits
1206 if (lineedit) finishedLineEdit();
1210 // write to directory
1211 QString clipfile="part";
1212 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1215 file.setName ( clipboardDir + "/"+clipfile+".xml");
1216 if ( !file.open( QIODevice::WriteOnly ) )
1218 // This should neverever happen
1219 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1223 // Write it finally, and write in UTF8, no matter what
1224 QTextStream ts( &file );
1225 ts.setEncoding (QTextStream::UnicodeUTF8);
1229 clipboardEmpty=false;
1234 void MapEditor::redo()
1236 // Finish open lineEdits
1237 if (lineedit) finishedLineEdit();
1239 blockSaveState=true;
1241 // Find out current undo directory
1242 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1244 // Restore variables
1245 QString undoCommand;
1246 QString undoSelection;
1247 QString redoCommand;
1248 QString redoSelection;
1250 set.readSettings(QString(bakMapDir+"/commands"));
1251 undoCommand=set.readEntry ("undoCommand");
1252 undoSelection=set.readEntry ("undoSelection");
1253 redoCommand=set.readEntry ("redoCommand");
1254 redoSelection=set.readEntry ("redoSelection");
1256 // select object before redo
1257 if (!redoSelection.isEmpty())
1258 select (redoSelection);
1260 /* TODO remove testing
1261 cout << "ME::redo() begin\n";
1262 cout << " undosTotal="<<undosTotal<<endl;
1263 cout << " undosAvail="<<undosAvail<<endl;
1264 cout << " undoNum="<<undoNum<<endl;
1265 cout << " ---------------------------"<<endl;
1266 cout << " undoCom="<<undoCommand<<endl;
1267 cout << " undoSel="<<undoSelection<<endl;
1268 cout << " ---------------------------"<<endl;
1269 cout << " redoCom="<<redoCommand<<endl;
1270 cout << " redoSel="<<redoSelection<<endl;
1271 cout << " ---------------------------"<<endl;
1273 parseAtom (undoCommand);
1274 mapCenter->reposition();
1276 //if (!redoSelection.isEmpty())
1277 // select (redoSelection);
1281 // Undo not longer available now
1282 actionEditUndo->setEnabled (false);
1284 undoNum--; if (undoNum<1) undoNum=undosTotal;
1286 blockSaveState=false;
1287 /* TODO remove testing
1288 cout << "ME::redo() end\n";
1289 cout << " undosAvail="<<undosAvail<<endl;
1290 cout << " undoNum="<<undoNum<<endl;
1291 cout << " ---------------------------"<<endl<<endl;
1295 void MapEditor::undo()
1297 // Finish open lineEdits
1298 if (lineedit) finishedLineEdit();
1300 blockSaveState=true;
1302 // Find out current undo directory
1303 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1305 // Restore variables
1306 QString undoCommand;
1307 QString undoSelection;
1308 QString redoCommand;
1309 QString redoSelection;
1311 set.readSettings(QString(bakMapDir+"/commands"));
1312 undoCommand= set.readEntry ("undoCommand");
1313 undoSelection=set.readEntry ("undoSelection");
1314 redoCommand= set.readEntry ("redoCommand");
1315 redoSelection=set.readEntry ("redoSelection");
1317 // select object before undo
1318 if (!undoSelection.isEmpty())
1319 select (undoSelection);
1322 cout << "ME::undo() begin\n";
1323 cout << " undosTotal="<<undosTotal<<endl;
1324 cout << " undosAvail="<<undosAvail<<endl;
1325 cout << " undoNum="<<undoNum<<endl;
1326 cout << " ---------------------------"<<endl;
1327 cout << " undoCom="<<undoCommand<<endl;
1328 cout << " undoSel="<<undoSelection<<endl;
1329 cout << " ---------------------------"<<endl;
1330 cout << " redoCom="<<redoCommand<<endl;
1331 cout << " redoSel="<<redoSelection<<endl;
1332 cout << " ---------------------------"<<endl;
1334 parseAtom (undoCommand);
1335 mapCenter->reposition();
1337 //if (!redoSelection.isEmpty())
1338 // select (redoSelection);
1342 // Undo not longer available now
1343 actionEditUndo->setEnabled (false);
1345 undoNum--; if (undoNum<1) undoNum=undosTotal;
1347 blockSaveState=false;
1348 /* TODO remove testing
1349 cout << "ME::undo() end\n";
1350 cout << " undosAvail="<<undosAvail<<endl;
1351 cout << " undoNum="<<undoNum<<endl;
1352 cout << " ---------------------------"<<endl<<endl;
1356 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1358 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1360 QFile file (bakMapPath);
1364 // We need to parse saved XML data
1365 mapBuilderHandler handler;
1366 QXmlInputSource source( file);
1367 QXmlSimpleReader reader;
1368 reader.setContentHandler( &handler );
1369 reader.setErrorHandler( &handler );
1370 handler.setMapEditor( this );
1371 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1372 if (undoSel.isEmpty())
1376 handler.setLoadMode (NewMap);
1380 handler.setLoadMode (ImportReplace);
1382 blockReposition=true;
1383 bool ok = reader.parse( source );
1384 blockReposition=false;
1387 // This should never ever happen
1388 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1389 tr( handler.errorProtocol() )+" in "+bakMapDir );
1393 QMessageBox::critical( 0, tr( "Critical Error" ),
1394 tr("Temporary directory %1 used for undo is gone. \n"
1395 "I will create a new one, but at the moment no undo is available.\n"
1396 "Maybe you want to reload your original data.\n\n"
1397 "Sorry for any inconveniences.").arg(bakMapDir) );
1402 void MapEditor::pasteNoSave()
1404 // Finish open lineEdits
1405 if (lineedit) finishedLineEdit();
1407 load (clipboardDir+"/part.xml",ImportAdd);
1410 void MapEditor::cutNoSave()
1416 void MapEditor::paste()
1418 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1419 typeid(*selection) == typeid(MapCenterObj)))
1421 saveState(selection,QString("Paste to %1").arg( getName(selection)));
1423 mapCenter->reposition();
1428 void MapEditor::cut()
1430 saveState(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
1433 mapCenter->reposition();
1437 void MapEditor::move(const int &x, const int &y)
1439 // TODO no saveState, because this is only internal at undo so far
1440 if (selection) selection->move(x,y);
1441 if (typeid(*selection) == typeid(FloatImageObj))
1442 ((FloatImageObj*)selection)->setRelPos();
1445 void MapEditor::moveBranchUp()
1447 // Finish open lineEdits
1448 if (lineedit) finishedLineEdit();
1452 if (typeid(*selection) == typeid(BranchObj) )
1454 bo=(BranchObj*)selection;
1455 if (!bo->canMoveBranchUp()) return;
1456 par=(BranchObj*)(bo->getParObj());
1457 selection->unselect();
1458 selection=par->moveBranchUp (bo);
1459 selection->select();
1460 saveState("moveBranchDown ()",bo,QString("Move up %1").arg(getName(bo)));
1461 mapCenter->reposition();
1462 ensureSelectionVisible();
1466 void MapEditor::moveBranchDown()
1468 // Finish open lineEdits
1469 if (lineedit) finishedLineEdit();
1473 if (typeid(*selection) == typeid(BranchObj) )
1475 bo=(BranchObj*)selection;
1476 if (!bo->canMoveBranchDown()) return;
1477 par=(BranchObj*)(bo->getParObj());
1478 selection->unselect();
1479 selection=par->moveBranchDown(bo);
1480 selection->select();
1481 saveState("moveBranchUp ()",bo,QString("Move down %1").arg(getName(bo)));
1482 mapCenter->reposition();
1483 ensureSelectionVisible();
1487 void MapEditor::editHeading()
1489 // Finish open lineEdits
1490 if (lineedit) finishedLineEdit();
1493 (typeid(*selection) == typeid(BranchObj) ||
1494 typeid(*selection) == typeid(MapCenterObj) ) )
1496 editingBO=(BranchObj*)selection;
1498 ensureSelectionVisible();
1499 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1500 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1501 QString s=editingBO->getHeading();
1502 lineedit->setText(s);
1503 lineedit->setCursorPosition(1);
1504 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1505 lineedit->selectAll();
1507 lineedit->grabKeyboard();
1508 lineedit->setFocus();
1512 void MapEditor::setHeading(const QString &s)
1514 // Internal function, no saveState needed
1516 (typeid(*selection) == typeid(BranchObj) ||
1517 typeid(*selection) == typeid(MapCenterObj) ) )
1519 ((BranchObj*)selection)->setHeading(s);
1520 mapCenter->reposition();
1522 ensureSelectionVisible();
1526 void MapEditor::setURL (const QString &s)
1528 // Internal function, no saveState needed
1530 (typeid(*selection) == typeid(BranchObj) ||
1531 typeid(*selection) == typeid(MapCenterObj) ) )
1533 ((BranchObj*)selection)->setURL(s);
1534 mapCenter->reposition();
1536 ensureSelectionVisible();
1540 void MapEditor::setVymLink (const QString &s)
1542 // Internal function, no saveState needed
1544 (typeid(*selection) == typeid(BranchObj) ||
1545 typeid(*selection) == typeid(MapCenterObj) ) )
1547 ((BranchObj*)selection)->setVymLink(s);
1548 mapCenter->reposition();
1550 ensureSelectionVisible();
1554 void MapEditor::addNewBranch(int pos)
1556 // Finish open lineEdits
1557 if (lineedit) finishedLineEdit();
1560 (typeid(*selection) == typeid(BranchObj) ||
1561 typeid(*selection) == typeid(MapCenterObj) ) )
1563 BranchObj* bo1 = (BranchObj*) selection;
1564 saveState(selection, QString("Add new branch to %1").arg(getName(bo1))); //TODO undoCommand
1566 bool wasScrolled=false;
1567 BranchObj *newbo=NULL;
1570 // save scroll state. If scrolled, automatically select
1571 // new branch in order to tmp unscroll parent...
1572 wasScrolled=bo1->isScrolled();
1573 newbo=bo1->addBranch();
1576 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1580 // add above selection
1581 newbo=parbo->insertBranch(bo1->getNum());
1583 // add below selection
1584 newbo=parbo->insertBranch(bo1->getNum()+1);
1586 // This should not happen...
1591 LinkableMapObj *oldselection=selection;
1593 mapCenter->reposition();
1595 if (actionSettingsAutoedit->isOn() ||
1596 actionSettingsAutoselectHeading->isOn() )
1598 selection->unselect();
1600 selection->select();
1601 if (actionSettingsPasteNewHeading->isOn() )
1603 BranchObj *bo2= (BranchObj*)selection;
1604 bo2->setHeading("");
1606 if (actionSettingsAutoedit->isOn() )
1608 if (!actionSettingsAutoselectHeading->isOn()
1611 selection->unselect();
1612 selection=oldselection;
1613 selection->select();
1620 void MapEditor::addNewBranchHere()
1622 // Finish open lineEdits
1623 if (lineedit) finishedLineEdit();
1626 (typeid(*selection) == typeid(BranchObj) ) )
1628 BranchObj* bo1 = (BranchObj*) selection;
1629 saveState(selection, QString("Add new branch here").arg(getName(bo1)));
1631 bool wasScrolled=false;
1632 BranchObj *newbo=NULL;
1633 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1636 // add below selection
1637 newbo=parbo->insertBranch(bo1->getNum()+1);
1640 LinkableMapObj *oldselection=selection;
1641 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1643 mapCenter->reposition();
1645 if (actionSettingsAutoedit->isOn() ||
1646 actionSettingsAutoselectHeading->isOn() )
1648 selection->unselect();
1650 selection->select();
1651 if (actionSettingsPasteNewHeading->isOn() )
1653 BranchObj *bo2= (BranchObj*)selection;
1654 bo2->setHeading("");
1656 if (actionSettingsAutoedit->isOn() )
1658 if (!actionSettingsAutoselectHeading->isOn()
1661 selection->unselect();
1662 selection=oldselection;
1663 selection->select();
1669 void MapEditor::deleteSelection()
1671 // Finish open lineEdits
1672 if (lineedit) finishedLineEdit();
1674 if (selection && typeid(*selection) ==typeid(BranchObj) )
1676 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1677 BranchObj* par=(BranchObj*)(bo->getParObj());
1679 if (selection->getDepth()>1)
1680 // Normal branch, save parent with childs
1681 saveState(par,QString("Delete %1").arg(getName(bo)));
1683 // Mainbranch, save whole map
1684 // TODO Better would be to insert mainbranch again at pos
1685 // But undoCommand is missing right now
1686 saveState(QString("Delete %1").arg(getName(bo)));
1688 par->removeBranch(bo);
1690 selection->select();
1691 ensureSelectionVisible();
1692 mapCenter->reposition();
1695 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1697 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1698 BranchObj* par=(BranchObj*)(fio->getParObj());
1699 saveState(par, QString("Delete %1").arg(getName(fio)));
1702 par->removeFloatImage(fio);
1704 selection->select();
1705 ensureSelectionVisible();
1706 mapCenter->reposition();
1711 LinkableMapObj* MapEditor::getSelection()
1716 void MapEditor::unselect()
1720 selectionLast=selection;
1721 selection->unselect();
1726 void MapEditor::reselect()
1730 selection=selectionLast;
1731 selection->select();
1736 bool MapEditor::select (const QString &s)
1738 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1740 // Finally select the found object
1743 if (selection) unselect();
1745 selection->select();
1747 ensureSelectionVisible();
1753 void MapEditor::select (LinkableMapObj *lmo)
1755 if (lmo && selection != lmo)
1757 // select the MapObj
1758 if (selection) selection->unselect();
1760 selection->select();
1767 void MapEditor::selectNextBranch()
1769 // Increase number of branch
1772 QString s=selection->getSelectString();
1778 part=s.section(",",-1);
1780 num=part.right(part.length() - 3);
1782 s=s.left (s.length() -num.length());
1785 num=QString ("%1").arg(num.toUInt()+1);
1789 // Try to select this one
1790 if (select (s)) return;
1792 // We have no direct successor,
1793 // try to increase the parental number in order to
1794 // find a successor with same depth
1796 int d=selection->getDepth();
1801 while (!found && d>0)
1803 s=s.section (",",0,d-1);
1804 // replace substring of current depth in s with "1"
1805 part=s.section(",",-1);
1807 num=part.right(part.length() - 3);
1811 // increase number of parent
1812 num=QString ("%1").arg(num.toUInt()+1);
1813 s=s.section (",",0,d-2) + ","+ typ+num;
1816 // Special case, look at orientation
1817 if (selection->getOrientation()==OrientRightOfCenter)
1818 num=QString ("%1").arg(num.toUInt()+1);
1820 num=QString ("%1").arg(num.toUInt()-1);
1825 // pad to oldDepth, select the first branch for each depth
1826 for (i=d;i<oldDepth;i++)
1831 if ( ((BranchObj*)selection)->countBranches()>0)
1839 // try to select the freshly built string
1847 void MapEditor::selectPrevBranch()
1849 // Decrease number of branch
1852 QString s=selection->getSelectString();
1858 part=s.section(",",-1);
1860 num=part.right(part.length() - 3);
1862 s=s.left (s.length() -num.length());
1865 num=QString ("%1").arg(num.toUInt()-1);
1869 // Try to select this one
1870 if (select (s)) return;
1872 // We have no direct precessor,
1873 // try to decrease the parental number in order to
1874 // find a precessor with same depth
1876 int d=selection->getDepth();
1881 while (!found && d>0)
1883 s=s.section (",",0,d-1);
1884 // replace substring of current depth in s with "1"
1885 part=s.section(",",-1);
1887 num=part.right(part.length() - 3);
1891 // decrease number of parent
1892 num=QString ("%1").arg(num.toUInt()-1);
1893 s=s.section (",",0,d-2) + ","+ typ+num;
1896 // Special case, look at orientation
1897 if (selection->getOrientation()==OrientRightOfCenter)
1898 num=QString ("%1").arg(num.toUInt()-1);
1900 num=QString ("%1").arg(num.toUInt()+1);
1905 // pad to oldDepth, select the last branch for each depth
1906 for (i=d;i<oldDepth;i++)
1910 if ( ((BranchObj*)selection)->countBranches()>0)
1911 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1918 // try to select the freshly built string
1926 void MapEditor::selectUpperBranch()
1928 // Finish open lineEdits
1929 if (lineedit) finishedLineEdit();
1933 if (typeid(*selection) == typeid(BranchObj))
1935 if (selection->getOrientation()==OrientRightOfCenter)
1938 if (selection->getDepth()==1)
1946 void MapEditor::selectLowerBranch()
1948 // Finish open lineEdits
1949 if (lineedit) finishedLineEdit();
1953 if (typeid(*selection) == typeid(BranchObj))
1955 if (selection->getOrientation()==OrientRightOfCenter)
1958 if (selection->getDepth()==1)
1967 void MapEditor::selectLeftBranch()
1969 // Finish open lineEdits
1970 if (lineedit) finishedLineEdit();
1976 if (typeid(*selection) == typeid(MapCenterObj))
1978 par= (BranchObj*) selection;
1979 bo=par->getLastSelectedBranch();
1982 // Workaround for reselecting on left and right side
1983 if (bo->getOrientation()==OrientRightOfCenter)
1985 bo=par->getLastBranch();
1991 selection->select();
1993 ensureSelectionVisible();
1998 par=(BranchObj*)(selection->getParObj());
1999 if (selection->getOrientation()==OrientRightOfCenter)
2001 if (typeid(*selection) == typeid(BranchObj) ||
2002 typeid(*selection) == typeid(FloatImageObj))
2004 selection->unselect();
2006 selection->select();
2008 ensureSelectionVisible();
2012 if (typeid(*selection) == typeid(BranchObj) )
2014 bo=((BranchObj*)selection)->getLastSelectedBranch();
2017 selection->unselect();
2019 selection->select();
2021 ensureSelectionVisible();
2029 void MapEditor::selectRightBranch()
2031 // Finish open lineEdits
2032 if (lineedit) finishedLineEdit();
2039 if (typeid(*selection) == typeid(MapCenterObj))
2041 par= (BranchObj*) selection;
2042 bo=par->getLastSelectedBranch();
2045 // Workaround for relecting on left and right side
2046 if (bo->getOrientation()==OrientLeftOfCenter)
2047 bo=par->getFirstBranch();
2052 selection->select();
2053 ensureSelectionVisible();
2058 par=(BranchObj*)(selection->getParObj());
2059 if (selection->getOrientation()==OrientLeftOfCenter)
2061 if (typeid(*selection) == typeid(BranchObj) ||
2062 typeid(*selection) == typeid(FloatImageObj))
2064 selection->unselect();
2066 selection->select();
2068 ensureSelectionVisible();
2072 if (typeid(*selection) == typeid(BranchObj) )
2074 bo=((BranchObj*)selection)->getLastSelectedBranch();
2077 selection->unselect();
2079 selection->select();
2081 ensureSelectionVisible();
2089 void MapEditor::selectFirstBranch()
2091 // Finish open lineEdits
2092 if (lineedit) finishedLineEdit();
2098 if (typeid(*selection) == typeid(BranchObj))
2100 bo1= (BranchObj*) selection;
2101 par=(BranchObj*)(bo1->getParObj());
2102 bo2=par->getFirstBranch();
2106 selection->select();
2107 ensureSelectionVisible();
2114 void MapEditor::selectLastBranch()
2116 // Finish open lineEdits
2117 if (lineedit) finishedLineEdit();
2123 if (typeid(*selection) == typeid(BranchObj))
2125 bo1= (BranchObj*) selection;
2126 par=(BranchObj*)(bo1->getParObj());
2127 bo2=par->getLastBranch();
2131 selection->select();
2132 ensureSelectionVisible();
2139 void MapEditor::setColor(QColor c)
2144 void MapEditor::selectBackgroundColor()
2146 // Finish open lineEdits
2147 if (lineedit) finishedLineEdit();
2149 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2150 if ( !col.isValid() ) return;
2151 setBackgroundColor( col );
2152 saveState(QString("Set background color of map to %1").arg(col.name()));
2155 void MapEditor::setBackgroundColor(QColor c)
2157 mapCanvas->setBackgroundColor (c);
2160 QColor MapEditor::pickColor()
2164 if (typeid(*selection) == typeid(BranchObj) ||
2165 typeid(*selection) == typeid(MapCenterObj))
2167 BranchObj *bo=(BranchObj*)selection;
2168 actColor=bo->getColor();
2174 void MapEditor::colorItem()
2178 if (typeid(*selection) == typeid(BranchObj) ||
2179 typeid(*selection) == typeid(MapCenterObj))
2181 BranchObj *bo=(BranchObj*)selection;
2182 saveState(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2183 bo->setColor(actColor); // color branch
2188 void MapEditor::colorBranch()
2192 if (typeid(*selection) == typeid(BranchObj) ||
2193 typeid(*selection) == typeid(MapCenterObj))
2195 BranchObj *bo=(BranchObj*)selection;
2196 saveState(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2197 bo->setColorChilds(actColor); // color links, color childs
2203 void MapEditor::toggleStandardFlag(QString f)
2207 if (typeid(*selection) == typeid(BranchObj) ||
2208 typeid(*selection) == typeid(MapCenterObj))
2210 BranchObj *bo=(BranchObj*)selection;
2212 if (bo->isSetStandardFlag(f))
2216 saveState(selection, QString("%1 standard flag \"%2\" of %3").arg(s).arg(f).arg(getName(bo)));// TODO undoCommand
2217 bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn());
2223 void MapEditor::setViewCenter()
2225 // transform to CanvasView Coord:
2226 QPoint p=worldMatrix().map(movingCenter);
2227 center ( p.x(), p.y());
2231 BranchObj* MapEditor::findText (QString s, bool cs)
2234 { // Nothing found or new find process
2236 // nothing found, start again
2238 itFind=mapCenter->first();
2240 bool searching=true;
2241 bool foundNote=false;
2242 while (searching && !EOFind)
2246 // Searching in Note
2247 if (itFind->getNote().contains(s,cs))
2249 if (selection!=itFind)
2251 if (selection) ((BranchObj*)selection)->unselect();
2253 selection->select();
2255 ensureSelectionVisible();
2257 if (textEditor->findText(s,cs))
2263 // Searching in Heading
2264 if (searching && itFind->getHeading().contains (s,cs) )
2266 if (selection) ((BranchObj*)selection)->unselect();
2268 selection->select();
2270 ensureSelectionVisible();
2276 itFind=itFind->next();
2277 if (!itFind) EOFind=true;
2283 return (BranchObj*)selection;
2288 void MapEditor::findReset()
2289 { // Necessary if text to find changes during a find process
2294 void MapEditor::editURL()
2296 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2297 typeid(*selection) == typeid(MapCenterObj)) )
2300 BranchObj *bo=(BranchObj*)selection;
2301 QString text = QInputDialog::getText(
2302 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2303 bo->getURL(), &ok, this );
2306 // user entered something and pressed OK
2307 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2314 QString MapEditor::getURL()
2316 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2317 typeid(*selection) == typeid(MapCenterObj)) )
2318 return ((BranchObj*)selection)->getURL();
2323 void MapEditor::editHeading2URL()
2325 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2326 typeid(*selection) == typeid(MapCenterObj)) )
2328 BranchObj *bo=(BranchObj*)selection;
2329 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2330 bo->setURL (bo->getHeading());
2335 void MapEditor::editBugzilla2URL()
2337 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2338 typeid(*selection) == typeid(MapCenterObj)) )
2340 BranchObj *bo=(BranchObj*)selection;
2341 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2342 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo)));
2348 void MapEditor::editFATE2URL()
2350 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2351 typeid(*selection) == typeid(MapCenterObj)) )
2353 BranchObj *bo=(BranchObj*)selection;
2354 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2355 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2361 void MapEditor::editVymLink()
2363 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2364 typeid(*selection) == typeid(MapCenterObj)) )
2366 BranchObj *bo=(BranchObj*)selection;
2367 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map"));
2368 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2369 fd->setCaption(__VYM " - " +tr("Link to another map"));
2370 if (! bo->getVymLink().isEmpty() )
2371 fd->setSelection( bo->getVymLink() );
2375 if ( fd->exec() == QDialog::Accepted )
2377 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2378 bo->setVymLink (fd->selectedFile() );
2380 mapCenter->reposition();
2387 void MapEditor::deleteVymLink()
2389 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2390 typeid(*selection) == typeid(MapCenterObj)) )
2392 BranchObj *bo=(BranchObj*)selection;
2393 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2394 bo->setVymLink ("" );
2396 mapCenter->reposition();
2402 void MapEditor::toggleHideExport()
2404 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2405 typeid(*selection) == typeid(MapCenterObj)) ||
2406 (typeid(*selection)==typeid(FloatImageObj))
2409 OrnamentedObj *oo=(OrnamentedObj*)selection;
2411 if (oo->hideInExport())
2413 oo->setHideInExport(false);
2418 oo->setHideInExport(true);
2421 saveState(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2422 actionEditToggleHideExport->setOn (oo->hideInExport());
2424 mapCenter->reposition();
2430 QString MapEditor::getVymLink()
2432 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2433 typeid(*selection) == typeid(MapCenterObj)) )
2435 return ((BranchObj*)selection)->getVymLink();
2441 void MapEditor::removeBranchKeepChilds()
2443 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2445 BranchObj* bo=(BranchObj*)selection;
2446 BranchObj* par=(BranchObj*)(bo->getParObj());
2447 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2448 if (bo->getDepth()==1)
2451 saveState(selection->getParObj(),s); // TODO undoCommand
2452 QString sel=selection->getSelectString();
2454 par->removeBranchHere(bo);
2455 mapCenter->reposition();
2460 void MapEditor::removeChilds()
2462 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2464 saveState(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
2465 ((BranchObj*)selection)->removeChilds();
2466 mapCenter->reposition();
2470 void MapEditor::editMapInfo()
2472 ExtraInfoDialog dia;
2473 dia.setMapName (getFileName() );
2474 dia.setAuthor (mapCenter->getAuthor() );
2475 dia.setComment(mapCenter->getComment() );
2480 Q3CanvasItemList l=canvas()->allItems();
2481 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2483 stats+=QString ("%1 items on canvas\n").arg (i,6);
2490 bo=mapCenter->first();
2493 if (!bo->getNote().isEmpty() ) n++;
2494 f+= bo->countFloatImages();
2496 xl+=bo->countXLinks();
2499 stats+=QString ("%1 branches\n").arg (b-1,6);
2500 stats+=QString ("%1 xLinks \n").arg (xl,6);
2501 stats+=QString ("%1 notes\n").arg (n,6);
2502 stats+=QString ("%1 images\n").arg (f,6);
2503 dia.setStats (stats);
2505 // Finally show dialog
2506 if (dia.exec() == QDialog::Accepted)
2508 saveState("Edit info about map"); //TODO undoCommand
2509 mapCenter->setAuthor (dia.getAuthor() );
2510 mapCenter->setComment (dia.getComment() );
2514 void MapEditor::updateActions()
2516 return; //FIXME testing
2518 if (getLinkColorHint()==HeadingColor)
2519 actionFormatLinkColorHint->setOn(true);
2521 actionFormatLinkColorHint->setOn(false);
2526 actionFormatLinkStyleLine->setOn(true);
2529 actionFormatLinkStyleParabel->setOn(true);
2532 actionFormatLinkStylePolyLine->setOn(true);
2534 case StylePolyParabel:
2535 actionFormatLinkStylePolyParabel->setOn(true);
2541 QPixmap pix( 16, 16 );
2542 pix.fill( mapCanvas->backgroundColor() );
2543 actionFormatBackColor->setIconSet( pix );
2544 pix.fill( defLinkColor );
2545 actionFormatLinkColor->setIconSet( pix );
2547 actionEditUndo->setEnabled( mapChanged );
2548 actionFileSave->setEnabled( mapUnsaved );
2552 if ( (typeid(*selection) == typeid(BranchObj)) ||
2553 (typeid(*selection) == typeid(MapCenterObj)) )
2555 BranchObj *bo=(BranchObj*)selection;
2556 // Take care of links
2557 if (bo->countXLinks()==0)
2559 branchLinksContextMenu->clear();
2560 branchLinksContextMenu->insertItem ("No xLink available");
2561 branchLinksContextMenuDup->clear();
2562 branchLinksContextMenuDup->insertItem ("No xLink available");
2568 branchLinksContextMenu->clear();
2569 branchLinksContextMenuDup->clear();
2570 for (int i=0; i<=bo->countXLinks();i++)
2572 bot=bo->XLinkTargetAt(i);
2575 s=bot->getHeading();
2578 branchLinksContextMenu->insertItem (s);
2579 branchLinksContextMenuDup->insertItem (s);
2584 standardFlagsDefault->setEnabled (true);
2586 actionEditToggleScroll->setEnabled (true);
2587 if ( bo->isScrolled() )
2588 actionEditToggleScroll->setOn(true);
2590 actionEditToggleScroll->setOn(false);
2592 if ( bo->getURL().isEmpty() )
2594 actionEditOpenURL->setEnabled (false);
2595 actionEditOpenURLTab->setEnabled (false);
2599 actionEditOpenURL->setEnabled (true);
2600 actionEditOpenURLTab->setEnabled (true);
2602 if ( bo->getVymLink().isEmpty() )
2604 actionEditOpenVymLink->setEnabled (false);
2605 actionEditDeleteVymLink->setEnabled (false);
2608 actionEditOpenVymLink->setEnabled (true);
2609 actionEditDeleteVymLink->setEnabled (true);
2612 if (bo->canMoveBranchUp())
2613 actionEditMoveUp->setEnabled (true);
2615 actionEditMoveUp->setEnabled (false);
2616 if (bo->canMoveBranchDown())
2617 actionEditMoveDown->setEnabled (true);
2619 actionEditMoveDown->setEnabled (false);
2622 actionEditToggleHideExport->setEnabled (true);
2623 actionEditToggleHideExport->setOn (bo->hideInExport() );
2625 actionEditCopy->setEnabled (true);
2626 actionEditCut->setEnabled (true);
2627 if (!clipboardEmpty)
2628 actionEditPaste->setEnabled (true);
2630 actionEditPaste->setEnabled (false);
2631 for (a=actionListBranches.first();a;a=actionListBranches.next())
2632 a->setEnabled(true);
2633 actionEditDelete->setEnabled (true);
2634 switch (selection->getFrameType())
2637 actionFormatFrameNone->setOn(true);
2640 actionFormatFrameRectangle->setOn(true);
2645 actionFormatIncludeImagesVer->setOn
2646 ( ((BranchObj*)selection)->getIncludeImagesVer());
2647 actionFormatIncludeImagesHor->setOn
2648 ( ((BranchObj*)selection)->getIncludeImagesHor());
2649 actionFormatHideLinkUnselected->setOn
2650 (selection->getHideLinkUnselected());
2652 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2654 FloatObj *fo=(FloatImageObj*)selection;
2655 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2657 actionEditOpenURL->setEnabled (false);
2658 actionEditOpenVymLink->setEnabled (false);
2659 actionEditDeleteVymLink->setEnabled (false);
2660 actionEditToggleHideExport->setEnabled (true);
2661 actionEditToggleHideExport->setOn (fo->hideInExport() );
2664 actionEditCopy->setEnabled (true);
2665 actionEditCut->setEnabled (true);
2666 actionEditPaste->setEnabled (false);
2667 for (a=actionListBranches.first();a;a=actionListBranches.next())
2668 a->setEnabled(false);
2669 actionEditDelete->setEnabled (true);
2670 actionFormatHideLinkUnselected->setOn
2671 ( selection->getHideLinkUnselected());
2672 actionEditMoveUp->setEnabled (false);
2673 actionEditMoveDown->setEnabled (false);
2678 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2680 actionEditCopy->setEnabled (false);
2681 actionEditCut->setEnabled (false);
2682 actionEditPaste->setEnabled (false);
2683 for (a=actionListBranches.first();a;a=actionListBranches.next())
2684 a->setEnabled(false);
2686 actionEditToggleScroll->setEnabled (false);
2687 actionEditOpenURL->setEnabled (false);
2688 actionEditOpenVymLink->setEnabled (false);
2689 actionEditDeleteVymLink->setEnabled (false);
2690 actionEditHeading2URL->setEnabled (false);
2691 actionEditDelete->setEnabled (false);
2692 actionEditMoveUp->setEnabled (false);
2693 actionEditMoveDown->setEnabled (false);
2694 actionEditToggleHideExport->setEnabled (false);
2698 void MapEditor::updateNoteFlag()
2701 if ( (typeid(*selection) == typeid(BranchObj)) ||
2702 (typeid(*selection) == typeid(MapCenterObj)) )
2703 ((BranchObj*)selection)->updateNoteFlag();
2706 void MapEditor::setLinkStyle (LinkStyle ls)
2710 saveState("Set link style"); // TODO undoCommand
2712 bo=mapCenter->first();
2716 bo->setLinkStyle(bo->getDefLinkStyle());
2719 mapCenter->reposition();
2722 LinkStyle MapEditor::getLinkStyle ()
2727 void MapEditor::setLinkColor(QColor c)
2733 void MapEditor::setLinkColorHint()
2735 // called from setLinkColorHint(lch) or at end of parse
2737 bo=mapCenter->first();
2745 void MapEditor::setLinkColorHint(LinkColorHint lch)
2751 void MapEditor::toggleLinkColorHint()
2753 if (linkcolorhint==HeadingColor)
2754 linkcolorhint=DefaultColor;
2756 linkcolorhint=HeadingColor;
2758 bo=mapCenter->first();
2766 LinkColorHint MapEditor::getLinkColorHint()
2768 return linkcolorhint;
2771 QColor MapEditor::getDefLinkColor()
2773 return defLinkColor;
2776 void MapEditor::setDefXLinkColor(QColor col)
2781 QColor MapEditor::getDefXLinkColor()
2783 return defXLinkColor;
2786 void MapEditor::setDefXLinkWidth (int w)
2791 int MapEditor::getDefXLinkWidth()
2793 return defXLinkWidth;
2796 void MapEditor::selectLinkColor()
2798 // Finish open lineEdits
2799 if (lineedit) finishedLineEdit();
2801 QColor col = QColorDialog::getColor( defLinkColor, this );
2802 if ( !col.isValid() ) return;
2803 setLinkColor( col );
2804 saveState(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2808 void MapEditor::toggleScroll()
2810 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2812 BranchObj *bo=((BranchObj*)selection);
2813 if (bo->countBranches()==0) return;
2814 if (bo->getDepth()==0) return;
2816 if (bo->isScrolled())
2820 saveState(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2827 void MapEditor::unScrollAll()
2830 bo=mapCenter->first();
2833 if (bo->isScrolled()) bo->toggleScroll();
2838 void MapEditor::loadFloatImage ()
2841 (typeid(*selection) == typeid(BranchObj)) ||
2842 (typeid(*selection) == typeid(MapCenterObj)) )
2844 BranchObj *bo=((BranchObj*)selection);
2846 Q3FileDialog *fd=new Q3FileDialog( this);
2847 fd->setMode (Q3FileDialog::ExistingFiles);
2848 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2849 ImagePreview *p =new ImagePreview (fd);
2850 fd->setContentsPreviewEnabled( TRUE );
2851 fd->setContentsPreview( p, p );
2852 fd->setPreviewMode( Q3FileDialog::Contents );
2853 fd->setCaption(__VYM " - " +tr("Load image"));
2854 fd->setDir (lastImageDir);
2858 if ( fd->exec() == QDialog::Accepted )
2860 saveState(selection, QString("Add floatimage to %1").arg(getName(selection)));
2861 // FIXME in QT4 use: lastImageDir=fd->directory();
2862 lastImageDir=QDir (fd->dirPath());
2863 QStringList flist = fd->selectedFiles();
2864 QStringList::Iterator it = flist.begin();
2865 while( it != flist.end() )
2868 bo->addFloatImage();
2869 // TODO check if load was successful
2870 bo->getLastFloatImage()->load(*it);
2871 bo->getLastFloatImage()->setOriginalFilename(fn);
2875 mapCenter->reposition();
2884 void MapEditor::saveFloatImage (int item)
2887 (typeid(*selection) == typeid(FloatImageObj)) )
2889 FloatImageObj *fio=((FloatImageObj*)selection);
2890 const char* fmt = saveImageFormatMenu->text(item);
2892 Q3FileDialog *fd=new Q3FileDialog( this, tr("vym - save image as") + fmt);
2893 fd->addFilter ("PNG (*.png)");
2894 fd->addFilter ("BMP (*.bmp)");
2895 fd->addFilter ("XBM (*.xbm)");
2896 fd->addFilter ("JPG (*.jpg)");
2897 fd->addFilter ("XPM (*.xpm)");
2898 fd->addFilter ("GIF (*.gif)");
2899 fd->addFilter ("PNM (*.pnm)");
2900 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2901 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2902 fd->setMode( Q3FileDialog::AnyFile );
2903 fd->setSelection (fio->getOriginalFilename());
2907 if ( fd->exec() == QDialog::Accepted )
2909 if (QFile (fd->selectedFile()).exists() )
2911 QMessageBox mb( __VYM,
2912 tr("The file %1 exists already.\n"
2913 "Do you want to overwrite it?").arg(fd->selectedFile()),
2914 QMessageBox::Warning,
2915 QMessageBox::Yes | QMessageBox::Default,
2916 QMessageBox::Cancel | QMessageBox::Escape,
2917 QMessageBox::QMessageBox::NoButton );
2919 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2920 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2923 case QMessageBox::Yes:
2926 case QMessageBox::Cancel:
2932 fio->save (fd->selectedFile(),fmt);
2937 void MapEditor::setFrame(const FrameType &t)
2940 (typeid(*selection) == typeid(BranchObj)) ||
2941 (typeid(*selection) == typeid(MapCenterObj)) )
2943 selection->setFrameType (t);
2944 mapCenter->reposition();
2945 selection->updateLink();
2949 void MapEditor::setIncludeImagesVer(bool b)
2952 (typeid(*selection) == typeid(BranchObj)) ||
2953 (typeid(*selection) == typeid(MapCenterObj)) )
2954 ((BranchObj*)selection)->setIncludeImagesVer(b);
2955 mapCenter->reposition();
2958 void MapEditor::setIncludeImagesHor(bool b)
2961 (typeid(*selection) == typeid(BranchObj)) ||
2962 (typeid(*selection) == typeid(MapCenterObj)) )
2963 ((BranchObj*)selection)->setIncludeImagesHor(b);
2964 mapCenter->reposition();
2967 void MapEditor::setHideLinkUnselected (bool b)
2970 (typeid(*selection) == typeid(BranchObj)) ||
2971 (typeid(*selection) == typeid(MapCenterObj)) ||
2972 (typeid(*selection) == typeid(FloatImageObj)) )
2973 selection->setHideLinkUnselected(b);
2976 void MapEditor::importDir(BranchObj *dst, QDir d)
2979 (typeid(*selection) == typeid(BranchObj)) ||
2980 (typeid(*selection) == typeid(MapCenterObj)) )
2984 // Traverse directories
2985 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2986 QFileInfoList list = d.entryInfoList();
2989 for (int i = 0; i < list.size(); ++i)
2992 if (fi.fileName() != "." && fi.fileName() != ".." )
2995 bo=dst->getLastBranch();
2996 bo->setHeading (fi.fileName() );
2997 bo->setColor (QColor("blue"));
2999 if ( !d.cd(fi.fileName()) )
3000 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3003 // Recursively add subdirs
3010 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3011 list = d.entryInfoList();
3013 for (int i = 0; i < list.size(); ++i)
3017 bo=dst->getLastBranch();
3018 bo->setHeading (fi.fileName() );
3019 bo->setColor (QColor("black"));
3020 if (fi.fileName().right(4) == ".vym" )
3021 bo->setVymLink (fi.filePath());
3026 void MapEditor::importDir()
3029 (typeid(*selection) == typeid(BranchObj)) ||
3030 (typeid(*selection) == typeid(MapCenterObj)) )
3032 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
3033 fd->setMode (Q3FileDialog::DirectoryOnly);
3034 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3035 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
3039 if ( fd->exec() == QDialog::Accepted )
3041 BranchObj *bo=((BranchObj*)selection);
3042 importDir (bo,QDir(fd->selectedFile()) );
3043 mapCenter->reposition();
3050 void MapEditor::followXLink(int i)
3053 (typeid(*selection) == typeid(BranchObj)) ||
3054 (typeid(*selection) == typeid(MapCenterObj)) )
3056 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3059 selection->unselect();
3061 selection->select();
3062 ensureSelectionVisible();
3067 void MapEditor::editXLink(int i)
3070 (typeid(*selection) == typeid(BranchObj)) ||
3071 (typeid(*selection) == typeid(MapCenterObj)) )
3073 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3076 EditXLinkDialog dia;
3078 dia.setSelection(selection);
3079 if (dia.exec() == QDialog::Accepted)
3081 if (dia.useSettingsGlobal() )
3083 setDefXLinkColor (xlo->getColor() );
3084 setDefXLinkWidth (xlo->getWidth() );
3086 if (dia.deleteXLink())
3087 ((BranchObj*)selection)->deleteXLinkAt(i);
3088 saveState("Edit xLink"); //TODO undoCommand
3094 void MapEditor::testFunction()
3096 cout << "MapEditor::testFunction() called\n";
3098 mapCenter->positionBBox();
3102 dia.setCancelButton (true);
3103 dia.setText("This is a longer \nWarning");
3104 dia.setCaption("Warning: Flux problem");
3105 dia.setShowAgainName("/vym/warnings/mapeditor");
3106 if (dia.exec()==QDialog::Accepted)
3107 cout << "accepted!\n";
3109 cout << "canceled!\n";
3112 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
3113 Q3Process *proc = new Q3Process( this );
3114 proc->addArgument(ub);
3116 if ( !proc->start() )
3118 QMessageBox::warning(0,
3120 tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
3125 if (hidemode==HideNone)
3127 setHideTmpMode (HideExport);
3128 mapCenter->calcBBoxSizeWithChilds();
3129 QRect totalBBox=mapCenter->getTotalBBox();
3130 QRect mapRect=totalBBox;
3131 QCanvasRectangle *frame=NULL;
3133 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3135 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3136 totalBBox.width(), totalBBox.height());
3137 frame=new QCanvasRectangle (mapRect,mapCanvas);
3138 frame->setBrush (QColor(white));
3139 frame->setPen (QColor(black));
3145 setHideTmpMode (HideNone);
3147 cout <<" hidemode="<<hidemode<<endl;
3151 void MapEditor::ensureSelectionVisible()
3155 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3157 if (selection->getOrientation() == OrientLeftOfCenter)
3158 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3160 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3161 ensureVisible (p.x(), p.y() );
3166 void MapEditor::updateViewCenter()
3168 // Update movingCenter, so that we can zoom comfortably later
3169 QRect rc = QRect( contentsX(), contentsY(),
3170 visibleWidth(), visibleHeight() );
3171 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3172 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3173 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3176 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3178 // Lineedits are already closed by preceding
3179 // mouseEvent, we don't need to close here.
3181 QPoint p = inverseWorldMatrix().map(e->pos());
3182 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3185 { // MapObj was found
3186 if (selection != lmo)
3188 // select the MapObj
3189 if (selection) selection->unselect();
3191 selection->select();
3197 if (typeid(*selection)==typeid(BranchObj) ||
3198 typeid(*selection)==typeid(MapCenterObj) )
3200 // Context Menu on branch or mapcenter
3202 branchContextMenu->popup(e->globalPos() );
3204 if (typeid(*selection)==typeid(FloatImageObj))
3206 // Context Menu on floatimage
3208 floatimageContextMenu->popup(e->globalPos() );
3212 { // No MapObj found, we are on the Canvas itself
3213 // Context Menu on Canvas
3215 canvasContextMenu->popup(e->globalPos() );
3220 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3222 // Ignore right clicks, these will go to context menus
3223 if (e->button() == Qt::RightButton )
3229 // Finish open lineEdits
3230 if (lineedit) finishedLineEdit();
3232 QPoint p = inverseWorldMatrix().map(e->pos());
3233 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3237 //Take care of clickdesystem flags _or_ modifier modes
3239 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3240 typeid(*lmo)==typeid(MapCenterObj) ))
3242 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3243 if (!foname.isEmpty())
3245 // systemFlag clicked
3249 if (e->state() & Qt::ControlModifier)
3250 mainWindow->editOpenURLTab();
3252 mainWindow->editOpenURL();
3254 else if (foname=="vymLink")
3256 mainWindow->editOpenVymLink();
3257 // tabWidget may change, better return now
3258 // before segfaulting...
3259 } else if (foname=="note")
3260 mainWindow->windowToggleNoteEditor();
3261 else if (foname=="hideInExport")
3266 // No system flag clicked, take care of modmodes
3268 // Special case: CTRL is pressed
3269 if (e->state() & Qt::ControlModifier)
3271 if (actionModModeColor->isOn())
3274 setCursor (pickColorCursor);
3277 if (actionModModeLink->isOn())
3279 BranchObj *bo_begin=NULL;
3281 bo_begin=(BranchObj*)(lmo);
3284 ((typeid(*selection) == typeid(BranchObj)) ||
3285 (typeid(*selection) == typeid(MapCenterObj))) )
3286 bo_begin=(BranchObj*)selection;
3290 linkingObj_src=bo_begin;
3291 tmpXLink=new XLinkObj (mapCanvas);
3292 tmpXLink->setBegin (bo_begin);
3293 tmpXLink->setEnd (p);
3294 tmpXLink->setColor(defXLinkColor);
3295 tmpXLink->setWidth(defXLinkWidth);
3296 tmpXLink->updateXLink();
3297 tmpXLink->setVisibility (true);
3305 // Left Button Move Branches
3306 if (e->button() == Qt::LeftButton )
3308 movingObj_start.setX( p.x() - selection->x() );
3309 movingObj_start.setY( p.y() - selection->y() );
3310 movingObj_orgPos.setX (lmo->x() );
3311 movingObj_orgPos.setY (lmo->y() );
3313 // If modMode==copy, then we want to "move" the _new_ object around
3314 // then we need the offset from p to the _old_ selection, because of tmp
3315 if (actionModModeCopy->isOn() &&
3316 e->state() & Qt::ControlModifier)
3318 if (typeid(*selection)==typeid(BranchObj) )
3321 mapCenter->addBranch ((BranchObj*)selection);
3323 selection=mapCenter->getLastBranch();
3324 selection->select();
3325 mapCenter->reposition();
3328 movingObj=selection;
3330 // Middle Button Toggle Scroll
3331 // (On Mac OS X this won't work, but we still have
3332 // a button in the toolbar)
3333 if (e->button() == Qt::MidButton )
3337 { // No MapObj found, we are on the Canvas itself
3338 // Left Button move Pos of CanvasView
3339 if (e->button() == Qt::LeftButton )
3341 movingObj=NULL; // move Content not Obj
3342 movingObj_start=e->globalPos();
3343 movingCont_start=QPoint (contentsX(), contentsY() );
3344 movingVec=QPoint(0,0);
3345 setCursor(handOpenCursor);
3350 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3352 QPoint p = inverseWorldMatrix().map(e->pos());
3354 // Move the selected MapObj
3355 if ( selection && movingObj)
3357 // To avoid jumping of the CanvasView, only
3358 // ensureSelectionVisible, if not tmp linked
3359 if (!selection->hasParObjTmp())
3360 ensureSelectionVisible ();
3362 // Now move the selection, but add relative position
3363 // (movingObj_start) where selection was chosen with
3364 // mousepointer. (This avoids flickering resp. jumping
3365 // of selection back to absPos)
3367 LinkableMapObj *lmosel;
3368 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3370 // Check if we could link
3371 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3374 if (typeid(*selection) == typeid(FloatImageObj))
3376 FloatObj *fo=(FloatObj*)selection;
3378 "move "+qpointToString(movingObj_orgPos),fo->getSelectString() ,
3379 QString("Move %1").arg(getName(selection)));
3380 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3384 // Relink float to new mapcenter or branch, if shift is pressed
3385 // Only relink, if selection really has a new parent
3386 if ( (e->state() & Qt::ShiftModifier) && lmo &&
3387 ( (typeid(*lmo)==typeid(BranchObj)) ||
3388 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3389 ( lmo != fo->getParObj())
3392 if (typeid(*fo) == typeid(FloatImageObj))
3394 saveState(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3395 FloatImageObj *fio=(FloatImageObj*)(fo);
3396 ((BranchObj*)(lmo))->addFloatImage (fio);
3398 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3399 fio=((BranchObj*)(lmo))->getLastFloatImage();
3402 selection=(LinkableMapObj*)(fio);
3403 selection->select();
3404 movingObj=(MapObj*)(fio);
3407 } else // selection != a FloatObj
3409 if (lmosel->getDepth()==0)
3411 if (e->state() == Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3412 // If mapCenter is moved, move all the rest by default, too.
3413 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3415 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3418 if (lmosel->getDepth()==1)
3420 // depth==1, mainbranch
3421 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3425 if (lmosel->getOrientation() == OrientLeftOfCenter)
3426 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3427 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3428 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3430 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3432 // reposition subbranch
3433 lmosel->reposition();
3434 //ensureSelectionVisible();
3436 if (lmo && (lmo!=selection) &&
3437 (typeid(*lmo) == typeid(BranchObj) ||
3438 (typeid(*lmo) == typeid(MapCenterObj) )
3441 if (e->state() & Qt::ControlModifier)
3443 // Special case: CTRL to link below lmo
3444 lmosel->setParObjTmp (lmo,p,+1);
3446 else if (e->state() & Qt::ShiftModifier)
3447 lmosel->setParObjTmp (lmo,p,-1);
3449 lmosel->setParObjTmp (lmo,p,0);
3452 lmosel->unsetParObjTmp();
3456 } // no FloatImageObj
3460 } // selection && moving_obj
3462 // Draw a link from one branch to another
3465 tmpXLink->setEnd (p);
3466 tmpXLink->updateXLink();
3470 if (!movingObj && !pickingColor &&!drawingLink)
3472 QPoint p=e->globalPos();
3473 movingVec.setX(-p.x() + movingObj_start.x() );
3474 movingVec.setY(-p.y() + movingObj_start.y() );
3475 setContentsPos( movingCont_start.x() + movingVec.x(),
3476 movingCont_start.y() + movingVec.y());
3483 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3485 LinkableMapObj *dst;
3486 // Have we been picking color?
3490 setCursor (Qt::ArrowCursor);
3491 // Check if we are over another branch
3492 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3493 if (dst && selection)
3495 if (e->state() & Qt::ShiftModifier)
3497 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3498 ((BranchObj*)selection)->setLinkColor ();
3502 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3503 ((BranchObj*)selection)->setLinkColor ();
3509 // Have we been drawing a link?
3513 // Check if we are over another branch
3514 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3515 if (dst && selection)
3517 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3518 tmpXLink->updateXLink();
3519 tmpXLink->activate();
3520 saveState(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3529 // Have we been moving something?
3530 if ( selection && movingObj )
3532 // Moved FloatObj? Maybe we need to reposition
3533 if(typeid(*selection)==typeid (FloatImageObj))
3535 selection->getParObj()->requestReposition();
3536 mapCenter->reposition();
3539 // Check if we are over another branch, but ignore
3540 // any found LMOs, which are FloatObjs
3541 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3542 ((LinkableMapObj*)selection) );
3544 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3547 // Now check, if we have been moving a branch
3548 if (typeid(*selection) == typeid(BranchObj) )
3550 // save the position in case we link to mapcenter
3551 QPoint savePos=QPoint (selection->x(),selection->y() );
3553 // Reset the temporary drawn link to the original one
3554 ((LinkableMapObj*)selection)->unsetParObjTmp();
3560 BranchObj* bs=((BranchObj*)selection);
3561 QString undoCom="linkBranchToPos (\""+
3562 (bs->getParObj())->getSelectString()+
3564 QString("%1").arg(bs->getNum())+
3566 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3568 // TODO we also could check, if dest and src are on same branch,
3569 // then it would be sufficient to saveState of this branch
3571 // Modifiers allow to insert above/below dst
3572 if (e->state() & Qt::ShiftModifier)
3574 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3576 if (e->state() & Qt::ControlModifier)
3578 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3581 bs->moveBranchTo ((BranchObj*)(dst),-1);
3582 if (dst->getDepth()==0)
3585 saveState (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) );
3587 if (selection->getDepth()==1)
3588 // If we have moved mainbranch only save endposition
3589 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos)));
3591 // Draw the original link, before selection was moved around
3592 mapCenter->reposition();
3594 // Finally resize canvas, if needed
3599 // maybe we moved View: set old cursor
3600 setCursor (Qt::ArrowCursor);
3604 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3606 // Finish open lineEdits
3607 if (lineedit) finishedLineEdit();
3609 if (e->button() == Qt::LeftButton )
3611 QPoint p = inverseWorldMatrix().map(e->pos());
3612 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3613 if (lmo) { // MapObj was found
3614 // First select the MapObj than edit heading
3615 if (selection) selection->unselect();
3617 selection->select();
3623 void MapEditor::resizeEvent (QResizeEvent* e)
3625 Q3CanvasView::resizeEvent( e );
3629 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3632 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3633 // cerr << event->format(i) << endl;
3636 (typeid(*selection) == typeid(BranchObj)) ||
3637 (typeid(*selection) == typeid(MapCenterObj))) {
3639 // If QImageDrag can decode mime type
3640 if (Q3ImageDrag::canDecode(event)) {
3645 // If image are dragged from firefox
3646 if (event->provides("application/x-moz-file-promise-url") &&
3647 event->provides("application/x-moz-nativeimage")) {
3648 event->accept(true);
3652 // If QUriDrag can decode mime type
3653 if (Q3UriDrag::canDecode(event)) {
3658 // If Uri are dragged from firefox
3659 if (event->provides("_NETSCAPE_URL")){
3664 // If QTextDrag can decode mime type
3665 if (Q3TextDrag::canDecode(event)) {
3674 bool isUnicode16(const QByteArray &d)
3676 // TODO: make more precise check for unicode 16.
3677 // Guess unicode16 if any of second bytes are zero
3678 unsigned int length = max(0,d.size()-2)/2;
3679 for (unsigned int i = 0; i<length ; i++)
3680 if (d.at(i*2+1)==0) return true;
3684 void MapEditor::contentsDropEvent(QDropEvent *event)
3687 (typeid(*selection) == typeid(BranchObj)) ||
3688 (typeid(*selection) == typeid(MapCenterObj)))
3693 if (event->provides("image/png"))
3696 if (Q3ImageDrag::decode(event, pix))
3704 } else if (event->provides("application/x-moz-file-promise-url") &&
3705 event->provides("application/x-moz-nativeimage"))
3707 // Contains url to the img src in unicode16
3708 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3709 QString url = QString((const QChar*)d.data(),d.size()/2);
3713 } else if (event->provides ("text/uri-list"))
3714 { // Uris provided e.g. by konqueror
3715 Q3UriDrag::decode (event,uris);
3716 } else if (event->provides ("_NETSCAPE_URL"))
3717 { // Uris provided by Mozilla
3718 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3721 } else if (event->provides("text/html")) {
3723 // Handels text mime types
3724 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3725 QByteArray d = event->encodedData("text/html");
3728 text = QString((const QChar*)d.data(),d.size()/2);
3732 textEditor->setText(text);
3736 } else if (event->provides("text/plain")) {
3737 QByteArray d = event->encodedData("text/plain");
3740 text = QString((const QChar*)d.data(),d.size()/2);
3744 textEditor->setText(text);
3756 for (const char* u=uris.first(); u; u=uris.next())
3758 bo=((BranchObj*)selection)->addBranch();
3761 s=Q3UriDrag::uriToLocalFile(u);
3764 QString file = QDir::convertSeparators(s);
3765 heading = QFileInfo(file).baseName();
3767 if (file.endsWith(".vym", false))
3768 bo->setVymLink(file);
3777 if (!heading.isEmpty())
3778 bo->setHeading(heading);
3788 //FIXME saveState has to be called earlier for each of the drops...
3789 saveState("Drop Event"); //TODO undo Command
3790 mapCenter->reposition();
3797 void MapEditor::addFloatImage(const QPixmap &img)
3800 (typeid(*selection) == typeid(BranchObj)) ||
3801 (typeid(*selection) == typeid(MapCenterObj)) )
3803 BranchObj *bo=((BranchObj*)selection);
3804 saveState(selection,QString("Add floatimage to %1").arg(getName(bo)));
3805 //QString fn=fd->selectedFile();
3806 //lastImageDir=fn.left(fn.findRev ("/"));
3807 bo->addFloatImage();
3808 // FIXME check if load was successful
3809 bo->getLastFloatImage()->load(img);
3810 //bo->getLastFloatImage()->setOriginalFilename(fn);
3811 mapCenter->reposition();
3818 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
3820 if (!imageBuffer) imageBuffer = new QBuffer();
3821 if (!imageBuffer->isOpen()) {
3822 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3824 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3828 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3830 if (nop->state()==Q3NetworkProtocol::StDone) {
3831 QPixmap img(imageBuffer->buffer());
3836 imageBuffer->close();
3838 imageBuffer->close();
3845 void MapEditor::fetchImage(const QString &url)
3848 urlOperator->stop();
3849 disconnect(urlOperator);
3853 urlOperator = new Q3UrlOperator(url);
3854 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
3855 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
3857 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
3858 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));