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* branchLinksContextMenuEdit;
134 extern QMenu* branchLinksContextMenuFollow;
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->isVisible())
1497 (typeid(*selection) == typeid(BranchObj) ||
1498 typeid(*selection) == typeid(MapCenterObj) ) )
1500 editingBO=(BranchObj*)selection;
1502 ensureSelectionVisible();
1503 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1504 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1505 QString s=editingBO->getHeading();
1506 lineedit->setText(s);
1507 lineedit->setCursorPosition(1);
1508 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1509 lineedit->selectAll();
1511 lineedit->grabKeyboard();
1512 lineedit->setFocus();
1516 void MapEditor::setHeading(const QString &s)
1518 // Internal function, no saveState needed
1520 (typeid(*selection) == typeid(BranchObj) ||
1521 typeid(*selection) == typeid(MapCenterObj) ) )
1523 ((BranchObj*)selection)->setHeading(s);
1524 mapCenter->reposition();
1526 ensureSelectionVisible();
1530 void MapEditor::setURL (const QString &s)
1532 // Internal function, no saveState needed
1534 (typeid(*selection) == typeid(BranchObj) ||
1535 typeid(*selection) == typeid(MapCenterObj) ) )
1537 ((BranchObj*)selection)->setURL(s);
1538 mapCenter->reposition();
1540 ensureSelectionVisible();
1544 void MapEditor::setVymLink (const QString &s)
1546 // Internal function, no saveState needed
1548 (typeid(*selection) == typeid(BranchObj) ||
1549 typeid(*selection) == typeid(MapCenterObj) ) )
1551 ((BranchObj*)selection)->setVymLink(s);
1552 mapCenter->reposition();
1554 ensureSelectionVisible();
1558 void MapEditor::addNewBranch(int pos)
1560 // Finish open lineEdits
1561 if (lineedit) finishedLineEdit();
1564 (typeid(*selection) == typeid(BranchObj) ||
1565 typeid(*selection) == typeid(MapCenterObj) ) )
1567 BranchObj* bo1 = (BranchObj*) selection;
1568 saveState(selection, QString("Add new branch to %1").arg(getName(bo1))); //TODO undoCommand
1570 bool wasScrolled=false;
1571 BranchObj *newbo=NULL;
1574 // save scroll state. If scrolled, automatically select
1575 // new branch in order to tmp unscroll parent...
1576 wasScrolled=bo1->isScrolled();
1577 newbo=bo1->addBranch();
1580 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1584 // add above selection
1585 newbo=parbo->insertBranch(bo1->getNum());
1587 // add below selection
1588 newbo=parbo->insertBranch(bo1->getNum()+1);
1590 // This should not happen...
1595 LinkableMapObj *oldselection=selection;
1597 mapCenter->reposition();
1599 if (actionSettingsAutoedit->isOn() ||
1600 actionSettingsAutoselectHeading->isOn() )
1602 selection->unselect();
1604 selection->select();
1605 if (actionSettingsPasteNewHeading->isOn() )
1607 BranchObj *bo2= (BranchObj*)selection;
1608 bo2->setHeading("");
1610 if (actionSettingsAutoedit->isOn() )
1612 if (!actionSettingsAutoselectHeading->isOn()
1615 selection->unselect();
1616 selection=oldselection;
1617 selection->select();
1624 void MapEditor::addNewBranchHere()
1626 // Finish open lineEdits
1627 if (lineedit) finishedLineEdit();
1630 (typeid(*selection) == typeid(BranchObj) ) )
1632 BranchObj* bo1 = (BranchObj*) selection;
1633 saveState(selection, QString("Add new branch here").arg(getName(bo1)));
1635 bool wasScrolled=false;
1636 BranchObj *newbo=NULL;
1637 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1640 // add below selection
1641 newbo=parbo->insertBranch(bo1->getNum()+1);
1644 LinkableMapObj *oldselection=selection;
1645 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1647 mapCenter->reposition();
1649 if (actionSettingsAutoedit->isOn() ||
1650 actionSettingsAutoselectHeading->isOn() )
1652 selection->unselect();
1654 selection->select();
1655 if (actionSettingsPasteNewHeading->isOn() )
1657 BranchObj *bo2= (BranchObj*)selection;
1658 bo2->setHeading("");
1660 if (actionSettingsAutoedit->isOn() )
1662 if (!actionSettingsAutoselectHeading->isOn()
1665 selection->unselect();
1666 selection=oldselection;
1667 selection->select();
1673 void MapEditor::deleteSelection()
1675 // Finish open lineEdits
1676 if (lineedit) finishedLineEdit();
1678 if (selection && typeid(*selection) ==typeid(BranchObj) )
1680 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1681 BranchObj* par=(BranchObj*)(bo->getParObj());
1683 if (selection->getDepth()>1)
1684 // Normal branch, save parent with childs
1685 saveState(par,QString("Delete %1").arg(getName(bo)));
1687 // Mainbranch, save whole map
1688 // TODO Better would be to insert mainbranch again at pos
1689 // But undoCommand is missing right now
1690 saveState(QString("Delete %1").arg(getName(bo)));
1692 par->removeBranch(bo);
1694 selection->select();
1695 ensureSelectionVisible();
1696 mapCenter->reposition();
1699 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1701 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1702 BranchObj* par=(BranchObj*)(fio->getParObj());
1703 saveState(par, QString("Delete %1").arg(getName(fio)));
1706 par->removeFloatImage(fio);
1708 selection->select();
1709 ensureSelectionVisible();
1710 mapCenter->reposition();
1715 LinkableMapObj* MapEditor::getSelection()
1720 void MapEditor::unselect()
1724 selectionLast=selection;
1725 selection->unselect();
1730 void MapEditor::reselect()
1734 selection=selectionLast;
1735 selection->select();
1740 bool MapEditor::select (const QString &s)
1742 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1744 // Finally select the found object
1747 if (selection) unselect();
1749 selection->select();
1751 ensureSelectionVisible();
1757 void MapEditor::select (LinkableMapObj *lmo)
1759 if (lmo && selection != lmo)
1761 // select the MapObj
1762 if (selection) selection->unselect();
1764 selection->select();
1771 void MapEditor::selectNextBranch()
1773 // Increase number of branch
1776 QString s=selection->getSelectString();
1782 part=s.section(",",-1);
1784 num=part.right(part.length() - 3);
1786 s=s.left (s.length() -num.length());
1789 num=QString ("%1").arg(num.toUInt()+1);
1793 // Try to select this one
1794 if (select (s)) return;
1796 // We have no direct successor,
1797 // try to increase the parental number in order to
1798 // find a successor with same depth
1800 int d=selection->getDepth();
1805 while (!found && d>0)
1807 s=s.section (",",0,d-1);
1808 // replace substring of current depth in s with "1"
1809 part=s.section(",",-1);
1811 num=part.right(part.length() - 3);
1815 // increase number of parent
1816 num=QString ("%1").arg(num.toUInt()+1);
1817 s=s.section (",",0,d-2) + ","+ typ+num;
1820 // Special case, look at orientation
1821 if (selection->getOrientation()==OrientRightOfCenter)
1822 num=QString ("%1").arg(num.toUInt()+1);
1824 num=QString ("%1").arg(num.toUInt()-1);
1829 // pad to oldDepth, select the first branch for each depth
1830 for (i=d;i<oldDepth;i++)
1835 if ( ((BranchObj*)selection)->countBranches()>0)
1843 // try to select the freshly built string
1851 void MapEditor::selectPrevBranch()
1853 // Decrease number of branch
1856 QString s=selection->getSelectString();
1862 part=s.section(",",-1);
1864 num=part.right(part.length() - 3);
1866 s=s.left (s.length() -num.length());
1869 num=QString ("%1").arg(num.toUInt()-1);
1873 // Try to select this one
1874 if (select (s)) return;
1876 // We have no direct precessor,
1877 // try to decrease the parental number in order to
1878 // find a precessor with same depth
1880 int d=selection->getDepth();
1885 while (!found && d>0)
1887 s=s.section (",",0,d-1);
1888 // replace substring of current depth in s with "1"
1889 part=s.section(",",-1);
1891 num=part.right(part.length() - 3);
1895 // decrease number of parent
1896 num=QString ("%1").arg(num.toUInt()-1);
1897 s=s.section (",",0,d-2) + ","+ typ+num;
1900 // Special case, look at orientation
1901 if (selection->getOrientation()==OrientRightOfCenter)
1902 num=QString ("%1").arg(num.toUInt()-1);
1904 num=QString ("%1").arg(num.toUInt()+1);
1909 // pad to oldDepth, select the last branch for each depth
1910 for (i=d;i<oldDepth;i++)
1914 if ( ((BranchObj*)selection)->countBranches()>0)
1915 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1922 // try to select the freshly built string
1930 void MapEditor::selectUpperBranch()
1932 // Finish open lineEdits
1933 if (lineedit) finishedLineEdit();
1937 if (typeid(*selection) == typeid(BranchObj))
1939 if (selection->getOrientation()==OrientRightOfCenter)
1942 if (selection->getDepth()==1)
1950 void MapEditor::selectLowerBranch()
1952 // Finish open lineEdits
1953 if (lineedit) finishedLineEdit();
1957 if (typeid(*selection) == typeid(BranchObj))
1959 if (selection->getOrientation()==OrientRightOfCenter)
1962 if (selection->getDepth()==1)
1971 void MapEditor::selectLeftBranch()
1973 // Finish open lineEdits
1974 if (lineedit) finishedLineEdit();
1980 if (typeid(*selection) == typeid(MapCenterObj))
1982 par= (BranchObj*) selection;
1983 bo=par->getLastSelectedBranch();
1986 // Workaround for reselecting on left and right side
1987 if (bo->getOrientation()==OrientRightOfCenter)
1989 bo=par->getLastBranch();
1995 selection->select();
1997 ensureSelectionVisible();
2002 par=(BranchObj*)(selection->getParObj());
2003 if (selection->getOrientation()==OrientRightOfCenter)
2005 if (typeid(*selection) == typeid(BranchObj) ||
2006 typeid(*selection) == typeid(FloatImageObj))
2008 selection->unselect();
2010 selection->select();
2012 ensureSelectionVisible();
2016 if (typeid(*selection) == typeid(BranchObj) )
2018 bo=((BranchObj*)selection)->getLastSelectedBranch();
2021 selection->unselect();
2023 selection->select();
2025 ensureSelectionVisible();
2033 void MapEditor::selectRightBranch()
2035 // Finish open lineEdits
2036 if (lineedit) finishedLineEdit();
2043 if (typeid(*selection) == typeid(MapCenterObj))
2045 par= (BranchObj*) selection;
2046 bo=par->getLastSelectedBranch();
2049 // Workaround for relecting on left and right side
2050 if (bo->getOrientation()==OrientLeftOfCenter)
2051 bo=par->getFirstBranch();
2056 selection->select();
2057 ensureSelectionVisible();
2062 par=(BranchObj*)(selection->getParObj());
2063 if (selection->getOrientation()==OrientLeftOfCenter)
2065 if (typeid(*selection) == typeid(BranchObj) ||
2066 typeid(*selection) == typeid(FloatImageObj))
2068 selection->unselect();
2070 selection->select();
2072 ensureSelectionVisible();
2076 if (typeid(*selection) == typeid(BranchObj) )
2078 bo=((BranchObj*)selection)->getLastSelectedBranch();
2081 selection->unselect();
2083 selection->select();
2085 ensureSelectionVisible();
2093 void MapEditor::selectFirstBranch()
2095 // Finish open lineEdits
2096 if (lineedit) finishedLineEdit();
2102 if (typeid(*selection) == typeid(BranchObj))
2104 bo1= (BranchObj*) selection;
2105 par=(BranchObj*)(bo1->getParObj());
2106 bo2=par->getFirstBranch();
2110 selection->select();
2111 ensureSelectionVisible();
2118 void MapEditor::selectLastBranch()
2120 // Finish open lineEdits
2121 if (lineedit) finishedLineEdit();
2127 if (typeid(*selection) == typeid(BranchObj))
2129 bo1= (BranchObj*) selection;
2130 par=(BranchObj*)(bo1->getParObj());
2131 bo2=par->getLastBranch();
2135 selection->select();
2136 ensureSelectionVisible();
2143 void MapEditor::setColor(QColor c)
2148 void MapEditor::selectBackgroundColor()
2150 // Finish open lineEdits
2151 if (lineedit) finishedLineEdit();
2153 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2154 if ( !col.isValid() ) return;
2155 setBackgroundColor( col );
2156 saveState(QString("Set background color of map to %1").arg(col.name()));
2159 void MapEditor::setBackgroundColor(QColor c)
2161 mapCanvas->setBackgroundColor (c);
2164 QColor MapEditor::pickColor()
2168 if (typeid(*selection) == typeid(BranchObj) ||
2169 typeid(*selection) == typeid(MapCenterObj))
2171 BranchObj *bo=(BranchObj*)selection;
2172 actColor=bo->getColor();
2178 void MapEditor::colorItem()
2182 if (typeid(*selection) == typeid(BranchObj) ||
2183 typeid(*selection) == typeid(MapCenterObj))
2185 BranchObj *bo=(BranchObj*)selection;
2186 saveState(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2187 bo->setColor(actColor); // color branch
2192 void MapEditor::colorBranch()
2196 if (typeid(*selection) == typeid(BranchObj) ||
2197 typeid(*selection) == typeid(MapCenterObj))
2199 BranchObj *bo=(BranchObj*)selection;
2200 saveState(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2201 bo->setColorChilds(actColor); // color links, color childs
2207 void MapEditor::toggleStandardFlag(QString f)
2211 if (typeid(*selection) == typeid(BranchObj) ||
2212 typeid(*selection) == typeid(MapCenterObj))
2214 BranchObj *bo=(BranchObj*)selection;
2216 if (bo->isSetStandardFlag(f))
2220 saveState(selection, QString("%1 standard flag \"%2\" of %3").arg(s).arg(f).arg(getName(bo)));// TODO undoCommand
2221 bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn());
2227 void MapEditor::setViewCenter()
2229 // transform to CanvasView Coord:
2230 QPoint p=worldMatrix().map(movingCenter);
2231 center ( p.x(), p.y());
2235 BranchObj* MapEditor::findText (QString s, bool cs)
2238 { // Nothing found or new find process
2240 // nothing found, start again
2242 itFind=mapCenter->first();
2244 bool searching=true;
2245 bool foundNote=false;
2246 while (searching && !EOFind)
2250 // Searching in Note
2251 if (itFind->getNote().contains(s,cs))
2253 if (selection!=itFind)
2255 if (selection) ((BranchObj*)selection)->unselect();
2257 selection->select();
2259 ensureSelectionVisible();
2261 if (textEditor->findText(s,cs))
2267 // Searching in Heading
2268 if (searching && itFind->getHeading().contains (s,cs) )
2270 if (selection) ((BranchObj*)selection)->unselect();
2272 selection->select();
2274 ensureSelectionVisible();
2280 itFind=itFind->next();
2281 if (!itFind) EOFind=true;
2287 return (BranchObj*)selection;
2292 void MapEditor::findReset()
2293 { // Necessary if text to find changes during a find process
2298 void MapEditor::editURL()
2300 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2301 typeid(*selection) == typeid(MapCenterObj)) )
2304 BranchObj *bo=(BranchObj*)selection;
2305 QString text = QInputDialog::getText(
2306 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2307 bo->getURL(), &ok, this );
2310 // user entered something and pressed OK
2311 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2318 QString MapEditor::getURL()
2320 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2321 typeid(*selection) == typeid(MapCenterObj)) )
2322 return ((BranchObj*)selection)->getURL();
2327 void MapEditor::editHeading2URL()
2329 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2330 typeid(*selection) == typeid(MapCenterObj)) )
2332 BranchObj *bo=(BranchObj*)selection;
2333 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2334 bo->setURL (bo->getHeading());
2339 void MapEditor::editBugzilla2URL()
2341 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2342 typeid(*selection) == typeid(MapCenterObj)) )
2344 BranchObj *bo=(BranchObj*)selection;
2345 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2346 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo)));
2352 void MapEditor::editFATE2URL()
2354 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2355 typeid(*selection) == typeid(MapCenterObj)) )
2357 BranchObj *bo=(BranchObj*)selection;
2358 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2359 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2365 void MapEditor::editVymLink()
2367 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2368 typeid(*selection) == typeid(MapCenterObj)) )
2370 BranchObj *bo=(BranchObj*)selection;
2371 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map"));
2372 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2373 fd->setCaption(__VYM " - " +tr("Link to another map"));
2374 if (! bo->getVymLink().isEmpty() )
2375 fd->setSelection( bo->getVymLink() );
2379 if ( fd->exec() == QDialog::Accepted )
2381 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2382 bo->setVymLink (fd->selectedFile() );
2384 mapCenter->reposition();
2391 void MapEditor::deleteVymLink()
2393 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2394 typeid(*selection) == typeid(MapCenterObj)) )
2396 BranchObj *bo=(BranchObj*)selection;
2397 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2398 bo->setVymLink ("" );
2400 mapCenter->reposition();
2406 void MapEditor::toggleHideExport()
2408 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2409 typeid(*selection) == typeid(MapCenterObj)) ||
2410 (typeid(*selection)==typeid(FloatImageObj))
2413 OrnamentedObj *oo=(OrnamentedObj*)selection;
2415 if (oo->hideInExport())
2417 oo->setHideInExport(false);
2422 oo->setHideInExport(true);
2425 saveState(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2426 actionEditToggleHideExport->setOn (oo->hideInExport());
2428 mapCenter->reposition();
2434 QString MapEditor::getVymLink()
2436 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2437 typeid(*selection) == typeid(MapCenterObj)) )
2439 return ((BranchObj*)selection)->getVymLink();
2445 void MapEditor::removeBranchKeepChilds()
2447 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2449 BranchObj* bo=(BranchObj*)selection;
2450 BranchObj* par=(BranchObj*)(bo->getParObj());
2451 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2452 if (bo->getDepth()==1)
2455 saveState(selection->getParObj(),s); // TODO undoCommand
2456 QString sel=selection->getSelectString();
2458 par->removeBranchHere(bo);
2459 mapCenter->reposition();
2464 void MapEditor::removeChilds()
2466 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2468 saveState(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
2469 ((BranchObj*)selection)->removeChilds();
2470 mapCenter->reposition();
2474 void MapEditor::editMapInfo()
2476 ExtraInfoDialog dia;
2477 dia.setMapName (getFileName() );
2478 dia.setAuthor (mapCenter->getAuthor() );
2479 dia.setComment(mapCenter->getComment() );
2484 Q3CanvasItemList l=canvas()->allItems();
2485 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2487 stats+=QString ("%1 items on canvas\n").arg (i,6);
2494 bo=mapCenter->first();
2497 if (!bo->getNote().isEmpty() ) n++;
2498 f+= bo->countFloatImages();
2500 xl+=bo->countXLinks();
2503 stats+=QString ("%1 branches\n").arg (b-1,6);
2504 stats+=QString ("%1 xLinks \n").arg (xl,6);
2505 stats+=QString ("%1 notes\n").arg (n,6);
2506 stats+=QString ("%1 images\n").arg (f,6);
2507 dia.setStats (stats);
2509 // Finally show dialog
2510 if (dia.exec() == QDialog::Accepted)
2512 saveState("Edit info about map"); //TODO undoCommand
2513 mapCenter->setAuthor (dia.getAuthor() );
2514 mapCenter->setComment (dia.getComment() );
2518 void MapEditor::updateActions()
2521 if (getLinkColorHint()==HeadingColor)
2522 actionFormatLinkColorHint->setOn(true);
2524 actionFormatLinkColorHint->setOn(false);
2529 actionFormatLinkStyleLine->setOn(true);
2532 actionFormatLinkStyleParabel->setOn(true);
2535 actionFormatLinkStylePolyLine->setOn(true);
2537 case StylePolyParabel:
2538 actionFormatLinkStylePolyParabel->setOn(true);
2544 QPixmap pix( 16, 16 );
2545 pix.fill( mapCanvas->backgroundColor() );
2546 actionFormatBackColor->setIconSet( pix );
2547 pix.fill( defLinkColor );
2548 actionFormatLinkColor->setIconSet( pix );
2550 actionEditUndo->setEnabled( mapChanged );
2551 actionFileSave->setEnabled( mapUnsaved );
2555 if ( (typeid(*selection) == typeid(BranchObj)) ||
2556 (typeid(*selection) == typeid(MapCenterObj)) )
2558 BranchObj *bo=(BranchObj*)selection;
2559 // Take care of links
2560 if (bo->countXLinks()==0)
2562 branchLinksContextMenuEdit->clear();
2563 branchLinksContextMenuFollow->clear();
2568 branchLinksContextMenuEdit->clear();
2569 branchLinksContextMenuFollow->clear();
2570 for (int i=0; i<=bo->countXLinks();i++)
2572 bot=bo->XLinkTargetAt(i);
2575 s=bot->getHeading();
2578 branchLinksContextMenuFollow->addAction (s);
2579 branchLinksContextMenuEdit->addAction (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)
3071 (typeid(*selection) == typeid(BranchObj)) ||
3072 (typeid(*selection) == typeid(MapCenterObj)) )
3074 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3077 EditXLinkDialog dia;
3079 dia.setSelection(selection);
3080 if (dia.exec() == QDialog::Accepted)
3082 if (dia.useSettingsGlobal() )
3084 setDefXLinkColor (xlo->getColor() );
3085 setDefXLinkWidth (xlo->getWidth() );
3087 if (dia.deleteXLink())
3088 ((BranchObj*)selection)->deleteXLinkAt(i);
3089 saveState("Edit xLink"); //TODO undoCommand
3095 void MapEditor::testFunction()
3097 cout << "MapEditor::testFunction() called\n";
3099 mapCenter->positionBBox();
3103 dia.setCancelButton (true);
3104 dia.setText("This is a longer \nWarning");
3105 dia.setCaption("Warning: Flux problem");
3106 dia.setShowAgainName("/vym/warnings/mapeditor");
3107 if (dia.exec()==QDialog::Accepted)
3108 cout << "accepted!\n";
3110 cout << "canceled!\n";
3113 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
3114 Q3Process *proc = new Q3Process( this );
3115 proc->addArgument(ub);
3117 if ( !proc->start() )
3119 QMessageBox::warning(0,
3121 tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
3126 if (hidemode==HideNone)
3128 setHideTmpMode (HideExport);
3129 mapCenter->calcBBoxSizeWithChilds();
3130 QRect totalBBox=mapCenter->getTotalBBox();
3131 QRect mapRect=totalBBox;
3132 QCanvasRectangle *frame=NULL;
3134 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3136 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3137 totalBBox.width(), totalBBox.height());
3138 frame=new QCanvasRectangle (mapRect,mapCanvas);
3139 frame->setBrush (QColor(white));
3140 frame->setPen (QColor(black));
3146 setHideTmpMode (HideNone);
3148 cout <<" hidemode="<<hidemode<<endl;
3152 void MapEditor::ensureSelectionVisible()
3156 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3158 if (selection->getOrientation() == OrientLeftOfCenter)
3159 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3161 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3162 ensureVisible (p.x(), p.y() );
3167 void MapEditor::updateViewCenter()
3169 // Update movingCenter, so that we can zoom comfortably later
3170 QRect rc = QRect( contentsX(), contentsY(),
3171 visibleWidth(), visibleHeight() );
3172 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3173 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3174 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3177 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3179 // Lineedits are already closed by preceding
3180 // mouseEvent, we don't need to close here.
3182 QPoint p = inverseWorldMatrix().map(e->pos());
3183 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3186 { // MapObj was found
3187 if (selection != lmo)
3189 // select the MapObj
3190 if (selection) selection->unselect();
3192 selection->select();
3198 if (typeid(*selection)==typeid(BranchObj) ||
3199 typeid(*selection)==typeid(MapCenterObj) )
3201 // Context Menu on branch or mapcenter
3203 branchContextMenu->popup(e->globalPos() );
3205 if (typeid(*selection)==typeid(FloatImageObj))
3207 // Context Menu on floatimage
3209 floatimageContextMenu->popup(e->globalPos() );
3213 { // No MapObj found, we are on the Canvas itself
3214 // Context Menu on Canvas
3216 canvasContextMenu->popup(e->globalPos() );
3221 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3223 // Ignore right clicks, these will go to context menus
3224 if (e->button() == Qt::RightButton )
3230 // Finish open lineEdits
3231 if (lineedit) finishedLineEdit();
3233 QPoint p = inverseWorldMatrix().map(e->pos());
3234 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3238 //Take care of clickdesystem flags _or_ modifier modes
3240 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3241 typeid(*lmo)==typeid(MapCenterObj) ))
3243 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3244 if (!foname.isEmpty())
3246 // systemFlag clicked
3250 if (e->state() & Qt::ControlModifier)
3251 mainWindow->editOpenURLTab();
3253 mainWindow->editOpenURL();
3255 else if (foname=="vymLink")
3257 mainWindow->editOpenVymLink();
3258 // tabWidget may change, better return now
3259 // before segfaulting...
3260 } else if (foname=="note")
3261 mainWindow->windowToggleNoteEditor();
3262 else if (foname=="hideInExport")
3267 // No system flag clicked, take care of modmodes
3269 // Special case: CTRL is pressed
3270 if (e->state() & Qt::ControlModifier)
3272 if (actionModModeColor->isOn())
3275 setCursor (pickColorCursor);
3278 if (actionModModeLink->isOn())
3280 BranchObj *bo_begin=NULL;
3282 bo_begin=(BranchObj*)(lmo);
3285 ((typeid(*selection) == typeid(BranchObj)) ||
3286 (typeid(*selection) == typeid(MapCenterObj))) )
3287 bo_begin=(BranchObj*)selection;
3291 linkingObj_src=bo_begin;
3292 tmpXLink=new XLinkObj (mapCanvas);
3293 tmpXLink->setBegin (bo_begin);
3294 tmpXLink->setEnd (p);
3295 tmpXLink->setColor(defXLinkColor);
3296 tmpXLink->setWidth(defXLinkWidth);
3297 tmpXLink->updateXLink();
3298 tmpXLink->setVisibility (true);
3306 // Left Button Move Branches
3307 if (e->button() == Qt::LeftButton )
3309 movingObj_start.setX( p.x() - selection->x() );
3310 movingObj_start.setY( p.y() - selection->y() );
3311 movingObj_orgPos.setX (lmo->x() );
3312 movingObj_orgPos.setY (lmo->y() );
3314 // If modMode==copy, then we want to "move" the _new_ object around
3315 // then we need the offset from p to the _old_ selection, because of tmp
3316 if (actionModModeCopy->isOn() &&
3317 e->state() & Qt::ControlModifier)
3319 if (typeid(*selection)==typeid(BranchObj) )
3322 mapCenter->addBranch ((BranchObj*)selection);
3324 selection=mapCenter->getLastBranch();
3325 selection->select();
3326 mapCenter->reposition();
3329 movingObj=selection;
3331 // Middle Button Toggle Scroll
3332 // (On Mac OS X this won't work, but we still have
3333 // a button in the toolbar)
3334 if (e->button() == Qt::MidButton )
3338 { // No MapObj found, we are on the Canvas itself
3339 // Left Button move Pos of CanvasView
3340 if (e->button() == Qt::LeftButton )
3342 movingObj=NULL; // move Content not Obj
3343 movingObj_start=e->globalPos();
3344 movingCont_start=QPoint (contentsX(), contentsY() );
3345 movingVec=QPoint(0,0);
3346 setCursor(handOpenCursor);
3351 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3353 QPoint p = inverseWorldMatrix().map(e->pos());
3355 // Move the selected MapObj
3356 if ( selection && movingObj)
3358 // To avoid jumping of the CanvasView, only
3359 // ensureSelectionVisible, if not tmp linked
3360 if (!selection->hasParObjTmp())
3361 ensureSelectionVisible ();
3363 // Now move the selection, but add relative position
3364 // (movingObj_start) where selection was chosen with
3365 // mousepointer. (This avoids flickering resp. jumping
3366 // of selection back to absPos)
3368 LinkableMapObj *lmosel;
3369 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3371 // Check if we could link
3372 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3375 if (typeid(*selection) == typeid(FloatImageObj))
3377 FloatObj *fo=(FloatObj*)selection;
3379 "move "+qpointToString(movingObj_orgPos),fo->getSelectString() ,
3380 QString("Move %1").arg(getName(selection)));
3381 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3385 // Relink float to new mapcenter or branch, if shift is pressed
3386 // Only relink, if selection really has a new parent
3387 if ( (e->state() & Qt::ShiftModifier) && lmo &&
3388 ( (typeid(*lmo)==typeid(BranchObj)) ||
3389 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3390 ( lmo != fo->getParObj())
3393 if (typeid(*fo) == typeid(FloatImageObj))
3395 saveState(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3396 FloatImageObj *fio=(FloatImageObj*)(fo);
3397 ((BranchObj*)(lmo))->addFloatImage (fio);
3399 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3400 fio=((BranchObj*)(lmo))->getLastFloatImage();
3403 selection=(LinkableMapObj*)(fio);
3404 selection->select();
3405 movingObj=(MapObj*)(fio);
3408 } else // selection != a FloatObj
3410 if (lmosel->getDepth()==0)
3412 if (e->state() == Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3413 // If mapCenter is moved, move all the rest by default, too.
3414 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3416 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3419 if (lmosel->getDepth()==1)
3421 // depth==1, mainbranch
3422 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3426 if (lmosel->getOrientation() == OrientLeftOfCenter)
3427 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3428 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3429 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3431 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3433 // reposition subbranch
3434 lmosel->reposition();
3435 //ensureSelectionVisible();
3437 if (lmo && (lmo!=selection) &&
3438 (typeid(*lmo) == typeid(BranchObj) ||
3439 (typeid(*lmo) == typeid(MapCenterObj) )
3442 if (e->state() & Qt::ControlModifier)
3444 // Special case: CTRL to link below lmo
3445 lmosel->setParObjTmp (lmo,p,+1);
3447 else if (e->state() & Qt::ShiftModifier)
3448 lmosel->setParObjTmp (lmo,p,-1);
3450 lmosel->setParObjTmp (lmo,p,0);
3453 lmosel->unsetParObjTmp();
3457 } // no FloatImageObj
3461 } // selection && moving_obj
3463 // Draw a link from one branch to another
3466 tmpXLink->setEnd (p);
3467 tmpXLink->updateXLink();
3471 if (!movingObj && !pickingColor &&!drawingLink)
3473 QPoint p=e->globalPos();
3474 movingVec.setX(-p.x() + movingObj_start.x() );
3475 movingVec.setY(-p.y() + movingObj_start.y() );
3476 setContentsPos( movingCont_start.x() + movingVec.x(),
3477 movingCont_start.y() + movingVec.y());
3484 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3486 LinkableMapObj *dst;
3487 // Have we been picking color?
3491 setCursor (Qt::ArrowCursor);
3492 // Check if we are over another branch
3493 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3494 if (dst && selection)
3496 if (e->state() & Qt::ShiftModifier)
3498 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3499 ((BranchObj*)selection)->setLinkColor ();
3503 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3504 ((BranchObj*)selection)->setLinkColor ();
3510 // Have we been drawing a link?
3514 // Check if we are over another branch
3515 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3516 if (dst && selection)
3518 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3519 tmpXLink->updateXLink();
3520 tmpXLink->activate();
3521 saveState(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3530 // Have we been moving something?
3531 if ( selection && movingObj )
3533 // Moved FloatObj? Maybe we need to reposition
3534 if(typeid(*selection)==typeid (FloatImageObj))
3536 selection->getParObj()->requestReposition();
3537 mapCenter->reposition();
3540 // Check if we are over another branch, but ignore
3541 // any found LMOs, which are FloatObjs
3542 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3543 ((LinkableMapObj*)selection) );
3545 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3548 // Now check, if we have been moving a branch
3549 if (typeid(*selection) == typeid(BranchObj) )
3551 // save the position in case we link to mapcenter
3552 QPoint savePos=QPoint (selection->x(),selection->y() );
3554 // Reset the temporary drawn link to the original one
3555 ((LinkableMapObj*)selection)->unsetParObjTmp();
3561 BranchObj* bs=((BranchObj*)selection);
3562 QString undoCom="linkBranchToPos (\""+
3563 (bs->getParObj())->getSelectString()+
3565 QString("%1").arg(bs->getNum())+
3567 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3569 // TODO we also could check, if dest and src are on same branch,
3570 // then it would be sufficient to saveState of this branch
3572 // Modifiers allow to insert above/below dst
3573 if (e->state() & Qt::ShiftModifier)
3575 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3577 if (e->state() & Qt::ControlModifier)
3579 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3582 bs->moveBranchTo ((BranchObj*)(dst),-1);
3583 if (dst->getDepth()==0)
3586 saveState (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) );
3588 if (selection->getDepth()==1)
3589 // If we have moved mainbranch only save endposition
3590 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos)));
3592 // Draw the original link, before selection was moved around
3593 mapCenter->reposition();
3595 // Finally resize canvas, if needed
3600 // maybe we moved View: set old cursor
3601 setCursor (Qt::ArrowCursor);
3605 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3607 // Finish open lineEdits
3608 if (lineedit) finishedLineEdit();
3610 if (e->button() == Qt::LeftButton )
3612 QPoint p = inverseWorldMatrix().map(e->pos());
3613 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3614 if (lmo) { // MapObj was found
3615 // First select the MapObj than edit heading
3616 if (selection) selection->unselect();
3618 selection->select();
3624 void MapEditor::resizeEvent (QResizeEvent* e)
3626 Q3CanvasView::resizeEvent( e );
3630 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3633 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3634 // cerr << event->format(i) << endl;
3637 (typeid(*selection) == typeid(BranchObj)) ||
3638 (typeid(*selection) == typeid(MapCenterObj))) {
3640 // If QImageDrag can decode mime type
3641 if (Q3ImageDrag::canDecode(event)) {
3646 // If image are dragged from firefox
3647 if (event->provides("application/x-moz-file-promise-url") &&
3648 event->provides("application/x-moz-nativeimage")) {
3649 event->accept(true);
3653 // If QUriDrag can decode mime type
3654 if (Q3UriDrag::canDecode(event)) {
3659 // If Uri are dragged from firefox
3660 if (event->provides("_NETSCAPE_URL")){
3665 // If QTextDrag can decode mime type
3666 if (Q3TextDrag::canDecode(event)) {
3675 bool isUnicode16(const QByteArray &d)
3677 // TODO: make more precise check for unicode 16.
3678 // Guess unicode16 if any of second bytes are zero
3679 unsigned int length = max(0,d.size()-2)/2;
3680 for (unsigned int i = 0; i<length ; i++)
3681 if (d.at(i*2+1)==0) return true;
3685 void MapEditor::contentsDropEvent(QDropEvent *event)
3688 (typeid(*selection) == typeid(BranchObj)) ||
3689 (typeid(*selection) == typeid(MapCenterObj)))
3694 if (event->provides("image/png"))
3697 if (Q3ImageDrag::decode(event, pix))
3705 } else if (event->provides("application/x-moz-file-promise-url") &&
3706 event->provides("application/x-moz-nativeimage"))
3708 // Contains url to the img src in unicode16
3709 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3710 QString url = QString((const QChar*)d.data(),d.size()/2);
3714 } else if (event->provides ("text/uri-list"))
3715 { // Uris provided e.g. by konqueror
3716 Q3UriDrag::decode (event,uris);
3717 } else if (event->provides ("_NETSCAPE_URL"))
3718 { // Uris provided by Mozilla
3719 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3722 } else if (event->provides("text/html")) {
3724 // Handels text mime types
3725 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3726 QByteArray d = event->encodedData("text/html");
3729 text = QString((const QChar*)d.data(),d.size()/2);
3733 textEditor->setText(text);
3737 } else if (event->provides("text/plain")) {
3738 QByteArray d = event->encodedData("text/plain");
3741 text = QString((const QChar*)d.data(),d.size()/2);
3745 textEditor->setText(text);
3757 for (const char* u=uris.first(); u; u=uris.next())
3759 bo=((BranchObj*)selection)->addBranch();
3762 s=Q3UriDrag::uriToLocalFile(u);
3765 QString file = QDir::convertSeparators(s);
3766 heading = QFileInfo(file).baseName();
3768 if (file.endsWith(".vym", false))
3769 bo->setVymLink(file);
3778 if (!heading.isEmpty())
3779 bo->setHeading(heading);
3789 //FIXME saveState has to be called earlier for each of the drops...
3790 saveState("Drop Event"); //TODO undo Command
3791 mapCenter->reposition();
3798 void MapEditor::addFloatImage(const QPixmap &img)
3801 (typeid(*selection) == typeid(BranchObj)) ||
3802 (typeid(*selection) == typeid(MapCenterObj)) )
3804 BranchObj *bo=((BranchObj*)selection);
3805 saveState(selection,QString("Add floatimage to %1").arg(getName(bo)));
3806 //QString fn=fd->selectedFile();
3807 //lastImageDir=fn.left(fn.findRev ("/"));
3808 bo->addFloatImage();
3809 // FIXME check if load was successful
3810 bo->getLastFloatImage()->load(img);
3811 //bo->getLastFloatImage()->setOriginalFilename(fn);
3812 mapCenter->reposition();
3819 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
3821 if (!imageBuffer) imageBuffer = new QBuffer();
3822 if (!imageBuffer->isOpen()) {
3823 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3825 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3829 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3831 if (nop->state()==Q3NetworkProtocol::StDone) {
3832 QPixmap img(imageBuffer->buffer());
3837 imageBuffer->close();
3839 imageBuffer->close();
3846 void MapEditor::fetchImage(const QString &url)
3849 urlOperator->stop();
3850 disconnect(urlOperator);
3854 urlOperator = new Q3UrlOperator(url);
3855 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
3856 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
3858 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
3859 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));