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->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()
2520 return; //FIXME testing
2522 if (getLinkColorHint()==HeadingColor)
2523 actionFormatLinkColorHint->setOn(true);
2525 actionFormatLinkColorHint->setOn(false);
2530 actionFormatLinkStyleLine->setOn(true);
2533 actionFormatLinkStyleParabel->setOn(true);
2536 actionFormatLinkStylePolyLine->setOn(true);
2538 case StylePolyParabel:
2539 actionFormatLinkStylePolyParabel->setOn(true);
2545 QPixmap pix( 16, 16 );
2546 pix.fill( mapCanvas->backgroundColor() );
2547 actionFormatBackColor->setIconSet( pix );
2548 pix.fill( defLinkColor );
2549 actionFormatLinkColor->setIconSet( pix );
2551 actionEditUndo->setEnabled( mapChanged );
2552 actionFileSave->setEnabled( mapUnsaved );
2556 if ( (typeid(*selection) == typeid(BranchObj)) ||
2557 (typeid(*selection) == typeid(MapCenterObj)) )
2559 BranchObj *bo=(BranchObj*)selection;
2560 // Take care of links
2561 if (bo->countXLinks()==0)
2563 branchLinksContextMenu->clear();
2564 branchLinksContextMenu->insertItem ("No xLink available");
2565 branchLinksContextMenuDup->clear();
2566 branchLinksContextMenuDup->insertItem ("No xLink available");
2572 branchLinksContextMenu->clear();
2573 branchLinksContextMenuDup->clear();
2574 for (int i=0; i<=bo->countXLinks();i++)
2576 bot=bo->XLinkTargetAt(i);
2579 s=bot->getHeading();
2582 branchLinksContextMenu->insertItem (s);
2583 branchLinksContextMenuDup->insertItem (s);
2588 standardFlagsDefault->setEnabled (true);
2590 actionEditToggleScroll->setEnabled (true);
2591 if ( bo->isScrolled() )
2592 actionEditToggleScroll->setOn(true);
2594 actionEditToggleScroll->setOn(false);
2596 if ( bo->getURL().isEmpty() )
2598 actionEditOpenURL->setEnabled (false);
2599 actionEditOpenURLTab->setEnabled (false);
2603 actionEditOpenURL->setEnabled (true);
2604 actionEditOpenURLTab->setEnabled (true);
2606 if ( bo->getVymLink().isEmpty() )
2608 actionEditOpenVymLink->setEnabled (false);
2609 actionEditDeleteVymLink->setEnabled (false);
2612 actionEditOpenVymLink->setEnabled (true);
2613 actionEditDeleteVymLink->setEnabled (true);
2616 if (bo->canMoveBranchUp())
2617 actionEditMoveUp->setEnabled (true);
2619 actionEditMoveUp->setEnabled (false);
2620 if (bo->canMoveBranchDown())
2621 actionEditMoveDown->setEnabled (true);
2623 actionEditMoveDown->setEnabled (false);
2626 actionEditToggleHideExport->setEnabled (true);
2627 actionEditToggleHideExport->setOn (bo->hideInExport() );
2629 actionEditCopy->setEnabled (true);
2630 actionEditCut->setEnabled (true);
2631 if (!clipboardEmpty)
2632 actionEditPaste->setEnabled (true);
2634 actionEditPaste->setEnabled (false);
2635 for (a=actionListBranches.first();a;a=actionListBranches.next())
2636 a->setEnabled(true);
2637 actionEditDelete->setEnabled (true);
2638 switch (selection->getFrameType())
2641 actionFormatFrameNone->setOn(true);
2644 actionFormatFrameRectangle->setOn(true);
2649 actionFormatIncludeImagesVer->setOn
2650 ( ((BranchObj*)selection)->getIncludeImagesVer());
2651 actionFormatIncludeImagesHor->setOn
2652 ( ((BranchObj*)selection)->getIncludeImagesHor());
2653 actionFormatHideLinkUnselected->setOn
2654 (selection->getHideLinkUnselected());
2656 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2658 FloatObj *fo=(FloatImageObj*)selection;
2659 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2661 actionEditOpenURL->setEnabled (false);
2662 actionEditOpenVymLink->setEnabled (false);
2663 actionEditDeleteVymLink->setEnabled (false);
2664 actionEditToggleHideExport->setEnabled (true);
2665 actionEditToggleHideExport->setOn (fo->hideInExport() );
2668 actionEditCopy->setEnabled (true);
2669 actionEditCut->setEnabled (true);
2670 actionEditPaste->setEnabled (false);
2671 for (a=actionListBranches.first();a;a=actionListBranches.next())
2672 a->setEnabled(false);
2673 actionEditDelete->setEnabled (true);
2674 actionFormatHideLinkUnselected->setOn
2675 ( selection->getHideLinkUnselected());
2676 actionEditMoveUp->setEnabled (false);
2677 actionEditMoveDown->setEnabled (false);
2682 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2684 actionEditCopy->setEnabled (false);
2685 actionEditCut->setEnabled (false);
2686 actionEditPaste->setEnabled (false);
2687 for (a=actionListBranches.first();a;a=actionListBranches.next())
2688 a->setEnabled(false);
2690 actionEditToggleScroll->setEnabled (false);
2691 actionEditOpenURL->setEnabled (false);
2692 actionEditOpenVymLink->setEnabled (false);
2693 actionEditDeleteVymLink->setEnabled (false);
2694 actionEditHeading2URL->setEnabled (false);
2695 actionEditDelete->setEnabled (false);
2696 actionEditMoveUp->setEnabled (false);
2697 actionEditMoveDown->setEnabled (false);
2698 actionEditToggleHideExport->setEnabled (false);
2702 void MapEditor::updateNoteFlag()
2705 if ( (typeid(*selection) == typeid(BranchObj)) ||
2706 (typeid(*selection) == typeid(MapCenterObj)) )
2707 ((BranchObj*)selection)->updateNoteFlag();
2710 void MapEditor::setLinkStyle (LinkStyle ls)
2714 saveState("Set link style"); // TODO undoCommand
2716 bo=mapCenter->first();
2720 bo->setLinkStyle(bo->getDefLinkStyle());
2723 mapCenter->reposition();
2726 LinkStyle MapEditor::getLinkStyle ()
2731 void MapEditor::setLinkColor(QColor c)
2737 void MapEditor::setLinkColorHint()
2739 // called from setLinkColorHint(lch) or at end of parse
2741 bo=mapCenter->first();
2749 void MapEditor::setLinkColorHint(LinkColorHint lch)
2755 void MapEditor::toggleLinkColorHint()
2757 if (linkcolorhint==HeadingColor)
2758 linkcolorhint=DefaultColor;
2760 linkcolorhint=HeadingColor;
2762 bo=mapCenter->first();
2770 LinkColorHint MapEditor::getLinkColorHint()
2772 return linkcolorhint;
2775 QColor MapEditor::getDefLinkColor()
2777 return defLinkColor;
2780 void MapEditor::setDefXLinkColor(QColor col)
2785 QColor MapEditor::getDefXLinkColor()
2787 return defXLinkColor;
2790 void MapEditor::setDefXLinkWidth (int w)
2795 int MapEditor::getDefXLinkWidth()
2797 return defXLinkWidth;
2800 void MapEditor::selectLinkColor()
2802 // Finish open lineEdits
2803 if (lineedit) finishedLineEdit();
2805 QColor col = QColorDialog::getColor( defLinkColor, this );
2806 if ( !col.isValid() ) return;
2807 setLinkColor( col );
2808 saveState(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2812 void MapEditor::toggleScroll()
2814 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2816 BranchObj *bo=((BranchObj*)selection);
2817 if (bo->countBranches()==0) return;
2818 if (bo->getDepth()==0) return;
2820 if (bo->isScrolled())
2824 saveState(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2831 void MapEditor::unScrollAll()
2834 bo=mapCenter->first();
2837 if (bo->isScrolled()) bo->toggleScroll();
2842 void MapEditor::loadFloatImage ()
2845 (typeid(*selection) == typeid(BranchObj)) ||
2846 (typeid(*selection) == typeid(MapCenterObj)) )
2848 BranchObj *bo=((BranchObj*)selection);
2850 Q3FileDialog *fd=new Q3FileDialog( this);
2851 fd->setMode (Q3FileDialog::ExistingFiles);
2852 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2853 ImagePreview *p =new ImagePreview (fd);
2854 fd->setContentsPreviewEnabled( TRUE );
2855 fd->setContentsPreview( p, p );
2856 fd->setPreviewMode( Q3FileDialog::Contents );
2857 fd->setCaption(__VYM " - " +tr("Load image"));
2858 fd->setDir (lastImageDir);
2862 if ( fd->exec() == QDialog::Accepted )
2864 saveState(selection, QString("Add floatimage to %1").arg(getName(selection)));
2865 // FIXME in QT4 use: lastImageDir=fd->directory();
2866 lastImageDir=QDir (fd->dirPath());
2867 QStringList flist = fd->selectedFiles();
2868 QStringList::Iterator it = flist.begin();
2869 while( it != flist.end() )
2872 bo->addFloatImage();
2873 // TODO check if load was successful
2874 bo->getLastFloatImage()->load(*it);
2875 bo->getLastFloatImage()->setOriginalFilename(fn);
2879 mapCenter->reposition();
2888 void MapEditor::saveFloatImage (int item)
2891 (typeid(*selection) == typeid(FloatImageObj)) )
2893 FloatImageObj *fio=((FloatImageObj*)selection);
2894 const char* fmt = saveImageFormatMenu->text(item);
2896 Q3FileDialog *fd=new Q3FileDialog( this, tr("vym - save image as") + fmt);
2897 fd->addFilter ("PNG (*.png)");
2898 fd->addFilter ("BMP (*.bmp)");
2899 fd->addFilter ("XBM (*.xbm)");
2900 fd->addFilter ("JPG (*.jpg)");
2901 fd->addFilter ("XPM (*.xpm)");
2902 fd->addFilter ("GIF (*.gif)");
2903 fd->addFilter ("PNM (*.pnm)");
2904 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2905 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2906 fd->setMode( Q3FileDialog::AnyFile );
2907 fd->setSelection (fio->getOriginalFilename());
2911 if ( fd->exec() == QDialog::Accepted )
2913 if (QFile (fd->selectedFile()).exists() )
2915 QMessageBox mb( __VYM,
2916 tr("The file %1 exists already.\n"
2917 "Do you want to overwrite it?").arg(fd->selectedFile()),
2918 QMessageBox::Warning,
2919 QMessageBox::Yes | QMessageBox::Default,
2920 QMessageBox::Cancel | QMessageBox::Escape,
2921 QMessageBox::QMessageBox::NoButton );
2923 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2924 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2927 case QMessageBox::Yes:
2930 case QMessageBox::Cancel:
2936 fio->save (fd->selectedFile(),fmt);
2941 void MapEditor::setFrame(const FrameType &t)
2944 (typeid(*selection) == typeid(BranchObj)) ||
2945 (typeid(*selection) == typeid(MapCenterObj)) )
2947 selection->setFrameType (t);
2948 mapCenter->reposition();
2949 selection->updateLink();
2953 void MapEditor::setIncludeImagesVer(bool b)
2956 (typeid(*selection) == typeid(BranchObj)) ||
2957 (typeid(*selection) == typeid(MapCenterObj)) )
2958 ((BranchObj*)selection)->setIncludeImagesVer(b);
2959 mapCenter->reposition();
2962 void MapEditor::setIncludeImagesHor(bool b)
2965 (typeid(*selection) == typeid(BranchObj)) ||
2966 (typeid(*selection) == typeid(MapCenterObj)) )
2967 ((BranchObj*)selection)->setIncludeImagesHor(b);
2968 mapCenter->reposition();
2971 void MapEditor::setHideLinkUnselected (bool b)
2974 (typeid(*selection) == typeid(BranchObj)) ||
2975 (typeid(*selection) == typeid(MapCenterObj)) ||
2976 (typeid(*selection) == typeid(FloatImageObj)) )
2977 selection->setHideLinkUnselected(b);
2980 void MapEditor::importDir(BranchObj *dst, QDir d)
2983 (typeid(*selection) == typeid(BranchObj)) ||
2984 (typeid(*selection) == typeid(MapCenterObj)) )
2988 // Traverse directories
2989 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2990 QFileInfoList list = d.entryInfoList();
2993 for (int i = 0; i < list.size(); ++i)
2996 if (fi.fileName() != "." && fi.fileName() != ".." )
2999 bo=dst->getLastBranch();
3000 bo->setHeading (fi.fileName() );
3001 bo->setColor (QColor("blue"));
3003 if ( !d.cd(fi.fileName()) )
3004 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3007 // Recursively add subdirs
3014 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3015 list = d.entryInfoList();
3017 for (int i = 0; i < list.size(); ++i)
3021 bo=dst->getLastBranch();
3022 bo->setHeading (fi.fileName() );
3023 bo->setColor (QColor("black"));
3024 if (fi.fileName().right(4) == ".vym" )
3025 bo->setVymLink (fi.filePath());
3030 void MapEditor::importDir()
3033 (typeid(*selection) == typeid(BranchObj)) ||
3034 (typeid(*selection) == typeid(MapCenterObj)) )
3036 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
3037 fd->setMode (Q3FileDialog::DirectoryOnly);
3038 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3039 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
3043 if ( fd->exec() == QDialog::Accepted )
3045 BranchObj *bo=((BranchObj*)selection);
3046 importDir (bo,QDir(fd->selectedFile()) );
3047 mapCenter->reposition();
3054 void MapEditor::followXLink(int i)
3057 (typeid(*selection) == typeid(BranchObj)) ||
3058 (typeid(*selection) == typeid(MapCenterObj)) )
3060 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3063 selection->unselect();
3065 selection->select();
3066 ensureSelectionVisible();
3071 void MapEditor::editXLink(int i)
3074 (typeid(*selection) == typeid(BranchObj)) ||
3075 (typeid(*selection) == typeid(MapCenterObj)) )
3077 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3080 EditXLinkDialog dia;
3082 dia.setSelection(selection);
3083 if (dia.exec() == QDialog::Accepted)
3085 if (dia.useSettingsGlobal() )
3087 setDefXLinkColor (xlo->getColor() );
3088 setDefXLinkWidth (xlo->getWidth() );
3090 if (dia.deleteXLink())
3091 ((BranchObj*)selection)->deleteXLinkAt(i);
3092 saveState("Edit xLink"); //TODO undoCommand
3098 void MapEditor::testFunction()
3100 cout << "MapEditor::testFunction() called\n";
3102 mapCenter->positionBBox();
3106 dia.setCancelButton (true);
3107 dia.setText("This is a longer \nWarning");
3108 dia.setCaption("Warning: Flux problem");
3109 dia.setShowAgainName("/vym/warnings/mapeditor");
3110 if (dia.exec()==QDialog::Accepted)
3111 cout << "accepted!\n";
3113 cout << "canceled!\n";
3116 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
3117 Q3Process *proc = new Q3Process( this );
3118 proc->addArgument(ub);
3120 if ( !proc->start() )
3122 QMessageBox::warning(0,
3124 tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
3129 if (hidemode==HideNone)
3131 setHideTmpMode (HideExport);
3132 mapCenter->calcBBoxSizeWithChilds();
3133 QRect totalBBox=mapCenter->getTotalBBox();
3134 QRect mapRect=totalBBox;
3135 QCanvasRectangle *frame=NULL;
3137 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3139 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3140 totalBBox.width(), totalBBox.height());
3141 frame=new QCanvasRectangle (mapRect,mapCanvas);
3142 frame->setBrush (QColor(white));
3143 frame->setPen (QColor(black));
3149 setHideTmpMode (HideNone);
3151 cout <<" hidemode="<<hidemode<<endl;
3155 void MapEditor::ensureSelectionVisible()
3159 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3161 if (selection->getOrientation() == OrientLeftOfCenter)
3162 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3164 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3165 ensureVisible (p.x(), p.y() );
3170 void MapEditor::updateViewCenter()
3172 // Update movingCenter, so that we can zoom comfortably later
3173 QRect rc = QRect( contentsX(), contentsY(),
3174 visibleWidth(), visibleHeight() );
3175 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3176 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3177 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3180 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3182 // Lineedits are already closed by preceding
3183 // mouseEvent, we don't need to close here.
3185 QPoint p = inverseWorldMatrix().map(e->pos());
3186 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3189 { // MapObj was found
3190 if (selection != lmo)
3192 // select the MapObj
3193 if (selection) selection->unselect();
3195 selection->select();
3201 if (typeid(*selection)==typeid(BranchObj) ||
3202 typeid(*selection)==typeid(MapCenterObj) )
3204 // Context Menu on branch or mapcenter
3206 branchContextMenu->popup(e->globalPos() );
3208 if (typeid(*selection)==typeid(FloatImageObj))
3210 // Context Menu on floatimage
3212 floatimageContextMenu->popup(e->globalPos() );
3216 { // No MapObj found, we are on the Canvas itself
3217 // Context Menu on Canvas
3219 canvasContextMenu->popup(e->globalPos() );
3224 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3226 // Ignore right clicks, these will go to context menus
3227 if (e->button() == Qt::RightButton )
3233 // Finish open lineEdits
3234 if (lineedit) finishedLineEdit();
3236 QPoint p = inverseWorldMatrix().map(e->pos());
3237 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3241 //Take care of clickdesystem flags _or_ modifier modes
3243 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3244 typeid(*lmo)==typeid(MapCenterObj) ))
3246 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3247 if (!foname.isEmpty())
3249 // systemFlag clicked
3253 if (e->state() & Qt::ControlModifier)
3254 mainWindow->editOpenURLTab();
3256 mainWindow->editOpenURL();
3258 else if (foname=="vymLink")
3260 mainWindow->editOpenVymLink();
3261 // tabWidget may change, better return now
3262 // before segfaulting...
3263 } else if (foname=="note")
3264 mainWindow->windowToggleNoteEditor();
3265 else if (foname=="hideInExport")
3270 // No system flag clicked, take care of modmodes
3272 // Special case: CTRL is pressed
3273 if (e->state() & Qt::ControlModifier)
3275 if (actionModModeColor->isOn())
3278 setCursor (pickColorCursor);
3281 if (actionModModeLink->isOn())
3283 BranchObj *bo_begin=NULL;
3285 bo_begin=(BranchObj*)(lmo);
3288 ((typeid(*selection) == typeid(BranchObj)) ||
3289 (typeid(*selection) == typeid(MapCenterObj))) )
3290 bo_begin=(BranchObj*)selection;
3294 linkingObj_src=bo_begin;
3295 tmpXLink=new XLinkObj (mapCanvas);
3296 tmpXLink->setBegin (bo_begin);
3297 tmpXLink->setEnd (p);
3298 tmpXLink->setColor(defXLinkColor);
3299 tmpXLink->setWidth(defXLinkWidth);
3300 tmpXLink->updateXLink();
3301 tmpXLink->setVisibility (true);
3309 // Left Button Move Branches
3310 if (e->button() == Qt::LeftButton )
3312 movingObj_start.setX( p.x() - selection->x() );
3313 movingObj_start.setY( p.y() - selection->y() );
3314 movingObj_orgPos.setX (lmo->x() );
3315 movingObj_orgPos.setY (lmo->y() );
3317 // If modMode==copy, then we want to "move" the _new_ object around
3318 // then we need the offset from p to the _old_ selection, because of tmp
3319 if (actionModModeCopy->isOn() &&
3320 e->state() & Qt::ControlModifier)
3322 if (typeid(*selection)==typeid(BranchObj) )
3325 mapCenter->addBranch ((BranchObj*)selection);
3327 selection=mapCenter->getLastBranch();
3328 selection->select();
3329 mapCenter->reposition();
3332 movingObj=selection;
3334 // Middle Button Toggle Scroll
3335 // (On Mac OS X this won't work, but we still have
3336 // a button in the toolbar)
3337 if (e->button() == Qt::MidButton )
3341 { // No MapObj found, we are on the Canvas itself
3342 // Left Button move Pos of CanvasView
3343 if (e->button() == Qt::LeftButton )
3345 movingObj=NULL; // move Content not Obj
3346 movingObj_start=e->globalPos();
3347 movingCont_start=QPoint (contentsX(), contentsY() );
3348 movingVec=QPoint(0,0);
3349 setCursor(handOpenCursor);
3354 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3356 QPoint p = inverseWorldMatrix().map(e->pos());
3358 // Move the selected MapObj
3359 if ( selection && movingObj)
3361 // To avoid jumping of the CanvasView, only
3362 // ensureSelectionVisible, if not tmp linked
3363 if (!selection->hasParObjTmp())
3364 ensureSelectionVisible ();
3366 // Now move the selection, but add relative position
3367 // (movingObj_start) where selection was chosen with
3368 // mousepointer. (This avoids flickering resp. jumping
3369 // of selection back to absPos)
3371 LinkableMapObj *lmosel;
3372 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3374 // Check if we could link
3375 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3378 if (typeid(*selection) == typeid(FloatImageObj))
3380 FloatObj *fo=(FloatObj*)selection;
3382 "move "+qpointToString(movingObj_orgPos),fo->getSelectString() ,
3383 QString("Move %1").arg(getName(selection)));
3384 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3388 // Relink float to new mapcenter or branch, if shift is pressed
3389 // Only relink, if selection really has a new parent
3390 if ( (e->state() & Qt::ShiftModifier) && lmo &&
3391 ( (typeid(*lmo)==typeid(BranchObj)) ||
3392 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3393 ( lmo != fo->getParObj())
3396 if (typeid(*fo) == typeid(FloatImageObj))
3398 saveState(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3399 FloatImageObj *fio=(FloatImageObj*)(fo);
3400 ((BranchObj*)(lmo))->addFloatImage (fio);
3402 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3403 fio=((BranchObj*)(lmo))->getLastFloatImage();
3406 selection=(LinkableMapObj*)(fio);
3407 selection->select();
3408 movingObj=(MapObj*)(fio);
3411 } else // selection != a FloatObj
3413 if (lmosel->getDepth()==0)
3415 if (e->state() == Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3416 // If mapCenter is moved, move all the rest by default, too.
3417 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3419 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3422 if (lmosel->getDepth()==1)
3424 // depth==1, mainbranch
3425 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3429 if (lmosel->getOrientation() == OrientLeftOfCenter)
3430 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3431 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3432 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3434 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3436 // reposition subbranch
3437 lmosel->reposition();
3438 //ensureSelectionVisible();
3440 if (lmo && (lmo!=selection) &&
3441 (typeid(*lmo) == typeid(BranchObj) ||
3442 (typeid(*lmo) == typeid(MapCenterObj) )
3445 if (e->state() & Qt::ControlModifier)
3447 // Special case: CTRL to link below lmo
3448 lmosel->setParObjTmp (lmo,p,+1);
3450 else if (e->state() & Qt::ShiftModifier)
3451 lmosel->setParObjTmp (lmo,p,-1);
3453 lmosel->setParObjTmp (lmo,p,0);
3456 lmosel->unsetParObjTmp();
3460 } // no FloatImageObj
3464 } // selection && moving_obj
3466 // Draw a link from one branch to another
3469 tmpXLink->setEnd (p);
3470 tmpXLink->updateXLink();
3474 if (!movingObj && !pickingColor &&!drawingLink)
3476 QPoint p=e->globalPos();
3477 movingVec.setX(-p.x() + movingObj_start.x() );
3478 movingVec.setY(-p.y() + movingObj_start.y() );
3479 setContentsPos( movingCont_start.x() + movingVec.x(),
3480 movingCont_start.y() + movingVec.y());
3487 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3489 LinkableMapObj *dst;
3490 // Have we been picking color?
3494 setCursor (Qt::ArrowCursor);
3495 // Check if we are over another branch
3496 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3497 if (dst && selection)
3499 if (e->state() & Qt::ShiftModifier)
3501 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3502 ((BranchObj*)selection)->setLinkColor ();
3506 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3507 ((BranchObj*)selection)->setLinkColor ();
3513 // Have we been drawing a link?
3517 // Check if we are over another branch
3518 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3519 if (dst && selection)
3521 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3522 tmpXLink->updateXLink();
3523 tmpXLink->activate();
3524 saveState(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3533 // Have we been moving something?
3534 if ( selection && movingObj )
3536 // Moved FloatObj? Maybe we need to reposition
3537 if(typeid(*selection)==typeid (FloatImageObj))
3539 selection->getParObj()->requestReposition();
3540 mapCenter->reposition();
3543 // Check if we are over another branch, but ignore
3544 // any found LMOs, which are FloatObjs
3545 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3546 ((LinkableMapObj*)selection) );
3548 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3551 // Now check, if we have been moving a branch
3552 if (typeid(*selection) == typeid(BranchObj) )
3554 // save the position in case we link to mapcenter
3555 QPoint savePos=QPoint (selection->x(),selection->y() );
3557 // Reset the temporary drawn link to the original one
3558 ((LinkableMapObj*)selection)->unsetParObjTmp();
3564 BranchObj* bs=((BranchObj*)selection);
3565 QString undoCom="linkBranchToPos (\""+
3566 (bs->getParObj())->getSelectString()+
3568 QString("%1").arg(bs->getNum())+
3570 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3572 // TODO we also could check, if dest and src are on same branch,
3573 // then it would be sufficient to saveState of this branch
3575 // Modifiers allow to insert above/below dst
3576 if (e->state() & Qt::ShiftModifier)
3578 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3580 if (e->state() & Qt::ControlModifier)
3582 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3585 bs->moveBranchTo ((BranchObj*)(dst),-1);
3586 if (dst->getDepth()==0)
3589 saveState (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) );
3591 if (selection->getDepth()==1)
3592 // If we have moved mainbranch only save endposition
3593 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos)));
3595 // Draw the original link, before selection was moved around
3596 mapCenter->reposition();
3598 // Finally resize canvas, if needed
3603 // maybe we moved View: set old cursor
3604 setCursor (Qt::ArrowCursor);
3608 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3610 // Finish open lineEdits
3611 if (lineedit) finishedLineEdit();
3613 if (e->button() == Qt::LeftButton )
3615 QPoint p = inverseWorldMatrix().map(e->pos());
3616 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3617 if (lmo) { // MapObj was found
3618 // First select the MapObj than edit heading
3619 if (selection) selection->unselect();
3621 selection->select();
3627 void MapEditor::resizeEvent (QResizeEvent* e)
3629 Q3CanvasView::resizeEvent( e );
3633 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3636 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3637 // cerr << event->format(i) << endl;
3640 (typeid(*selection) == typeid(BranchObj)) ||
3641 (typeid(*selection) == typeid(MapCenterObj))) {
3643 // If QImageDrag can decode mime type
3644 if (Q3ImageDrag::canDecode(event)) {
3649 // If image are dragged from firefox
3650 if (event->provides("application/x-moz-file-promise-url") &&
3651 event->provides("application/x-moz-nativeimage")) {
3652 event->accept(true);
3656 // If QUriDrag can decode mime type
3657 if (Q3UriDrag::canDecode(event)) {
3662 // If Uri are dragged from firefox
3663 if (event->provides("_NETSCAPE_URL")){
3668 // If QTextDrag can decode mime type
3669 if (Q3TextDrag::canDecode(event)) {
3678 bool isUnicode16(const QByteArray &d)
3680 // TODO: make more precise check for unicode 16.
3681 // Guess unicode16 if any of second bytes are zero
3682 unsigned int length = max(0,d.size()-2)/2;
3683 for (unsigned int i = 0; i<length ; i++)
3684 if (d.at(i*2+1)==0) return true;
3688 void MapEditor::contentsDropEvent(QDropEvent *event)
3691 (typeid(*selection) == typeid(BranchObj)) ||
3692 (typeid(*selection) == typeid(MapCenterObj)))
3697 if (event->provides("image/png"))
3700 if (Q3ImageDrag::decode(event, pix))
3708 } else if (event->provides("application/x-moz-file-promise-url") &&
3709 event->provides("application/x-moz-nativeimage"))
3711 // Contains url to the img src in unicode16
3712 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3713 QString url = QString((const QChar*)d.data(),d.size()/2);
3717 } else if (event->provides ("text/uri-list"))
3718 { // Uris provided e.g. by konqueror
3719 Q3UriDrag::decode (event,uris);
3720 } else if (event->provides ("_NETSCAPE_URL"))
3721 { // Uris provided by Mozilla
3722 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3725 } else if (event->provides("text/html")) {
3727 // Handels text mime types
3728 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3729 QByteArray d = event->encodedData("text/html");
3732 text = QString((const QChar*)d.data(),d.size()/2);
3736 textEditor->setText(text);
3740 } else if (event->provides("text/plain")) {
3741 QByteArray d = event->encodedData("text/plain");
3744 text = QString((const QChar*)d.data(),d.size()/2);
3748 textEditor->setText(text);
3760 for (const char* u=uris.first(); u; u=uris.next())
3762 bo=((BranchObj*)selection)->addBranch();
3765 s=Q3UriDrag::uriToLocalFile(u);
3768 QString file = QDir::convertSeparators(s);
3769 heading = QFileInfo(file).baseName();
3771 if (file.endsWith(".vym", false))
3772 bo->setVymLink(file);
3781 if (!heading.isEmpty())
3782 bo->setHeading(heading);
3792 //FIXME saveState has to be called earlier for each of the drops...
3793 saveState("Drop Event"); //TODO undo Command
3794 mapCenter->reposition();
3801 void MapEditor::addFloatImage(const QPixmap &img)
3804 (typeid(*selection) == typeid(BranchObj)) ||
3805 (typeid(*selection) == typeid(MapCenterObj)) )
3807 BranchObj *bo=((BranchObj*)selection);
3808 saveState(selection,QString("Add floatimage to %1").arg(getName(bo)));
3809 //QString fn=fd->selectedFile();
3810 //lastImageDir=fn.left(fn.findRev ("/"));
3811 bo->addFloatImage();
3812 // FIXME check if load was successful
3813 bo->getLastFloatImage()->load(img);
3814 //bo->getLastFloatImage()->setOriginalFilename(fn);
3815 mapCenter->reposition();
3822 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
3824 if (!imageBuffer) imageBuffer = new QBuffer();
3825 if (!imageBuffer->isOpen()) {
3826 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3828 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3832 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3834 if (nop->state()==Q3NetworkProtocol::StDone) {
3835 QPixmap img(imageBuffer->buffer());
3840 imageBuffer->close();
3842 imageBuffer->close();
3849 void MapEditor::fetchImage(const QString &url)
3852 urlOperator->stop();
3853 disconnect(urlOperator);
3857 urlOperator = new Q3UrlOperator(url);
3858 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
3859 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
3861 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
3862 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));