1.8.52 Toolbar layout is saved now.
3 #include <qstatusbar.h>
5 #include <qapplication.h>
7 #include <q3popupmenu.h>
9 #include <q3paintdevicemetrics.h>
11 #include <q3filedialog.h>
14 #include <QColorDialog>
16 #include <qinputdialog.h>
17 #include <q3dragobject.h>
18 #include <q3urloperator.h>
19 #include <q3networkprotocol.h>
22 #include <QResizeEvent>
23 #include <QContextMenuEvent>
26 #include <QMouseEvent>
27 #include <QDragEnterEvent>
28 #include <QTextStream>
30 #include <QActionGroup>
40 #include "editxlinkdialog.h"
42 #include "extrainfodialog.h"
44 #include "linkablemapobj.h"
45 #include "mainwindow.h"
48 #include "texteditor.h"
49 #include "warningdialog.h"
53 extern TextEditor *textEditor;
54 extern int statusbarTime;
55 extern Main *mainWindow;
56 extern QString tmpVymDir;
57 extern QString clipboardDir;
58 extern bool clipboardEmpty;
59 extern FlagRowObj *systemFlagsDefault;
60 extern FlagRowObj *standardFlagsDefault;
62 extern Q3PtrList <QAction> actionListBranches;
64 extern QAction *actionFileSave;
65 extern QAction *actionEditUndo;
66 extern QAction *actionEditCopy;
67 extern QAction *actionEditCut;
68 extern QAction *actionEditPaste;
69 extern QAction *actionEditMoveUp;
70 extern QAction *actionEditMoveDown;
71 extern QAction *actionEditToggleScroll;
72 extern QAction *actionEditOpenURL;
73 extern QAction *actionEditOpenURLTab;
74 extern QAction *actionEditURL;
75 extern QAction *actionEditHeading2URL;
76 extern QAction *actionEditBugzilla2URL;
77 extern QAction *actionEditFATE2URL;
78 extern QAction *actionEditOpenVymLink;
79 extern QAction *actionEditVymLink;
80 extern QAction *actionEditDeleteVymLink;
81 extern QAction *actionEditToggleHideExport;
82 extern QAction *actionEditHeading;
83 extern QAction *actionEditDelete;
84 extern QAction *actionEditAddBranch;
85 extern QAction *actionEditAddBranchAbove;
86 extern QAction *actionEditAddBranchBelow;
87 extern QAction *actionEditRemoveBranchHere;
88 extern QAction *actionEditRemoveChilds;
89 extern QAction *actionEditImportAdd;
90 extern QAction *actionEditImportReplace;
91 extern QAction *actionEditSaveBranch;
92 extern QAction *actionEditSelectFirst;
93 extern QAction *actionEditSelectLast;
94 extern QAction *actionEditLoadImage;
96 extern QAction* actionFormatPickColor;
97 extern QAction* actionFormatColorBranch;
98 extern QAction* actionFormatColorSubtree;
99 extern QAction *actionFormatLinkColorHint;
100 extern QAction *actionFormatBackColor;
101 extern QAction *actionFormatLinkColor;
103 extern QActionGroup* actionGroupModModes;
104 extern QAction* actionModModeColor;
105 extern QAction* actionModModeLink;
106 extern QAction* actionModModeCopy;
108 extern QActionGroup *actionGroupFormatFrameTypes;
109 extern QAction *actionFormatFrameNone;
110 extern QAction *actionFormatFrameRectangle;
112 extern QActionGroup *actionGroupFormatLinkStyles;
113 extern QAction *actionFormatIncludeImagesVer;
114 extern QAction *actionFormatIncludeImagesHor;
115 extern QAction *actionFormatHideLinkUnselected;
116 extern QAction *actionFormatLinkStyleLine;
117 extern QAction *actionFormatLinkStyleParabel;
118 extern QAction *actionFormatLinkStylePolyLine;
119 extern QAction *actionFormatLinkStylePolyParabel;
121 extern QAction *actionViewToggleNoteEditor;
123 extern QAction *actionSettingsAutoedit;
124 extern QAction *actionSettingsAutoselectHeading;
125 extern QAction *actionSettingsAutoselectText;
126 extern QAction *actionSettingsPasteNewHeading;
127 extern QAction *actionSettingsUseFlagGroups;
129 extern QMenu* branchContextMenu;
130 extern QMenu* branchAddContextMenu;
131 extern QMenu* branchRemoveContextMenu;
132 extern QMenu* branchLinksContextMenuEdit;
133 extern QMenu* branchLinksContextMenuFollow;
134 extern QMenu* floatimageContextMenu;
135 extern QMenu* saveImageFormatMenu;
136 extern QMenu* canvasContextMenu;
137 extern QMenu* lastMapsMenu;
138 extern QMenu* importMenu;
139 extern QMenu* exportMenu;
142 extern Settings settings;
143 extern ImageIO imageIO;
145 extern QString iconPath;
146 extern QDir vymBaseDir;
147 extern QDir lastImageDir;
149 int MapEditor::mapNum=0; // make instance
151 ///////////////////////////////////////////////////////////////////////
152 ///////////////////////////////////////////////////////////////////////
153 MapEditor::MapEditor(
154 QWidget* parent, bool interactive, const char* name, Qt::WFlags f) :
155 Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
157 //cout << "Constructor ME "<<this<<endl;
160 viewport()->setAcceptDrops(true);
162 mapCanvas = new Q3Canvas(width(),height());
163 mapCanvas->setAdvancePeriod(30);
164 mapCanvas->setBackgroundColor (Qt::white);
166 setCanvas (mapCanvas);
168 // Always show scroll bars (automatic would flicker sometimes)
169 setVScrollBarMode ( Q3ScrollView::AlwaysOn );
170 setHScrollBarMode ( Q3ScrollView::AlwaysOn );
172 mapCenter = new MapCenterObj(mapCanvas);
173 mapCenter->setVisibility (true);
174 mapCenter->setMapEditor (this);
175 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
176 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
180 lineedit = new QLineEdit(this, "lineedit" );
181 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEdit() ) );
184 actColor=Qt::black; setColor (actColor);
185 defLinkColor=QColor (0,0,255);
186 defXLinkColor=QColor (180,180,180);
187 linkcolorhint=DefaultColor;
188 linkstyle=StylePolyParabel;
190 // Create bitmap cursors, patform dependant
191 #if defined(Q_OS_MACX)
192 handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png") );
193 // set hot spot to tip of picker
194 pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 );
196 handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen16.png"));
197 // set hot spot to tip of picker
198 pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
211 defXLinkColor=QColor (230,230,230);
219 fileName=tr("unnamed");
222 undosTotal=settings.readNumEntry("/mapeditor/undoLevels",50);
226 // Initialize find routine
233 blockReposition=false;
234 blockSaveState=false;
238 isInteractive=interactive;
240 // Create temporary files
243 // Initially set movingCentre
246 // For testing purposes create history window
247 historyWindow = new ShowTextDialog (this);
248 historyWindow->setCaption (fileName);
250 mapCenter->reposition(); // for positioning heading
253 MapEditor::~MapEditor()
255 if (imageBuffer) delete imageBuffer;
261 //cout <<"Destructor MapEditor\n";
264 //settings.writeEntry( "/mapeditor/editmode/autoselect", );
268 QColor MapEditor::color()
273 QColor MapEditor::backgroundColor()
275 return mapCanvas->backgroundColor();
278 MapCenterObj* MapEditor::getMapCenter()
283 Q3Canvas* MapEditor::getCanvas()
288 void MapEditor::adjustCanvasSize()
290 // To adjust the canvas to map, viewport size and position, we have to
291 // do some coordinate magic...
293 // Get rectangle of (scroll-)view.
294 // We want to be in canvas coords, so
295 // we map. Important if view is zoomed...
296 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
297 visibleWidth(), visibleHeight()) );
299 // Now we need the bounding box of view AND map to calc the correct canvas size.
300 // Why? Because if the map itself is moved out of view, the view has to be enlarged
301 // to avoid jumping aroung...
302 QRect map=mapCenter->getTotalBBox();
304 // right edge - left edge
305 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
306 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
309 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
310 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
313 // move the map on canvas (in order to not move it on screen) this is neccessary
314 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
315 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
316 // to scroll to an empty area of canvas to the left.
317 // b) if topleft corner of map left of or above topleft of canvas
321 if (cw > mapCanvas->width() )
323 if (map.x()<0) dx=-map.x();
325 if (cw < mapCanvas->width() )
326 dx=-min (view.x(),map.x());
327 if (ch > mapCanvas->height() )
329 if (map.y()<0) dy=-map.y();
331 if (ch < mapCanvas->height() )
333 dy=-min (view.y(),map.y());
335 // We really have to resize now. Let's go...
336 mapCanvas->resize (cw,ch);
337 if ( (dx!=0) || (dy!=0) )
339 mapCenter->moveAllBy(dx,dy);
340 mapCenter->reposition();
341 // mapCenter->positionBBox(); // To move float
343 // scroll the view (in order to not move map on screen)
349 bool MapEditor::isRepositionBlocked()
351 return blockReposition;
354 QString MapEditor::getName (LinkableMapObj *lmo)
357 if (!lmo) return QString("Error: NULL has no name!");
359 if ((typeid(*lmo) == typeid(BranchObj) ||
360 typeid(*lmo) == typeid(MapCenterObj)))
363 s=(((BranchObj*)lmo)->getHeading());
364 if (s=="") s="unnamed";
365 return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
367 if ((typeid(*lmo) == typeid(FloatImageObj) ))
368 return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
369 return QString("Unknown type has no name!");
372 void MapEditor::makeTmpDirs()
374 // Create unique temporary directories
375 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
377 d.mkdir (tmpMapDir,true);
380 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
382 // tmpdir temporary directory to which data will be written
383 // prefix mapname, which will be appended to images etc.
384 // writeflags Only write flags for "real" save of map, not undo
385 // offset offset of bbox of whole map in canvas.
386 // Needed for XML export
402 ls="StylePolyParabel";
406 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
408 if (linkcolorhint==HeadingColor)
409 colhint=attribut("linkColorHint","HeadingColor");
411 QString mapAttr=attribut("version",__VYM_VERSION);
413 mapAttr+= attribut("author",mapCenter->getAuthor()) +
414 attribut("comment",mapCenter->getComment()) +
415 attribut("date",mapCenter->getDate()) +
416 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
417 attribut("linkStyle", ls ) +
418 attribut("linkColor", defLinkColor.name() ) +
419 attribut("defXLinkColor", defXLinkColor.name() ) +
420 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
422 s+=beginElement("vymmap",mapAttr);
425 // Find the used flags while traversing the tree
426 standardFlagsDefault->resetUsedCounter();
428 // Reset the counters before saving
429 FloatImageObj (mapCanvas).resetSaveCounter();
431 // Build xml recursivly
433 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
436 if ( typeid(*saveSelection) == typeid(BranchObj) )
437 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
438 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
439 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
441 else if (selection && typeid(*selection)==typeid(BranchObj))
442 // This is used if selected branch is saved from mainwindow
443 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
446 // Save local settings
447 s+=settings.getXMLData (destPath);
450 if (selection && !saveSelection )
451 s+=valueElement("select",selection->getSelectString());
454 s+=endElement("vymmap");
457 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
461 void MapEditor::saveState(const QString &comment)
464 saveState (CompleteMap,"",NULL,"",NULL, comment);
467 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &comment)
469 // save the given part of the map
470 saveState (PartOfMap,"",undoSel,"",NULL, comment);
473 void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment)
475 // selection does not change during action,
476 // so just save commands for undo and redo
477 LinkableMapObj *unsel;
482 saveState (UndoCommand,uc,unsel,rc,unsel, comment);
485 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel, const QString &comment)
487 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL, comment);
490 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel, const QString &comment)
494 if (blockSaveState) return;
496 /* TODO remove after testing
497 cout << "ME::saveState() begin\n"<<endl;
498 cout << " undosTotal="<<undosTotal<<endl;
499 cout << " undosAvail="<<undosAvail<<endl;
500 cout << " undoNum="<<undoNum<<endl;
501 cout << " ---------------------------"<<endl;
504 historyWindow->append (comment);
508 // Find out current undo directory
509 if (undosAvail<undosTotal) undosAvail++;
511 if (undoNum>undosTotal) undoNum=1;
514 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
515 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
517 // Create bakMapDir if not available
520 makeSubDirs (bakMapDir);
522 // Save current selection
523 QString redoSelection="";
525 redoSelection=redoSel->getSelectString();
527 // Save the object, which should be undone
528 QString undoSelection="";
530 undoSelection=undoSel->getSelectString();
532 // Save depending on how much needs to be saved
533 QString undoCommand="";
534 if (savemode==UndoCommand)
539 else if (savemode==PartOfMap && undoSel)
541 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
542 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
545 undoCommand="undoMap (\""+bakMapPath+"\")";
546 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
549 if (!backupXML.isEmpty())
550 // Write XML Data to disk
551 saveStringToDisk (QString(bakMapPath),backupXML);
554 set.setEntry (QString("undoCommand"),undoCommand);
555 set.setEntry (QString("undoSelection"),undoSelection);
556 set.setEntry (QString("redoCommand"),redoCom);
557 set.setEntry (QString("redoSelection"),redoSelection);
558 set.setEntry (QString("comment"),comment);
559 set.writeSettings(QString(bakMapDir+"/commands"));
561 /* TODO remove after testing
562 cout << " into="<< bakMapDir<<endl;
563 cout << " undosAvail="<<undosAvail<<endl;
564 cout << " undoNum="<<undoNum<<endl;
565 cout << " ---------------------------"<<endl;
566 cout << " comment="<<comment<<endl;
567 cout << " ---------------------------"<<endl;
568 cout << " undoCom="<<undoCommand<<endl;
569 cout << " undoSel="<<undoSelection<<endl;
570 cout << " ---------------------------"<<endl;
571 cout << " redoCom="<<redoCom<<endl;
572 cout << " redoSel="<<redoSelection<<endl;
573 cout << " ---------------------------"<<endl<<endl;
577 void MapEditor::parseAtom(const QString &atom)
584 // Split string s into command and parameters
585 api.parseCommand (atom);
586 QString com=api.command();
589 if (com=="moveBranchUp")
591 else if (com=="moveBranchDown")
593 else if (com=="move")
595 if (api.checkParamCount(2) && selection )
605 else if (com=="linkBranchToPos")
607 if (selection && typeid(*selection) == typeid(BranchObj) )
609 if (api.checkParamCount(4))
611 s=api.parString(ok,0);
612 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
615 if (typeid(*dst) == typeid(BranchObj) )
617 // Get number in parent
620 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
621 } else if (typeid(*dst) == typeid(MapCenterObj) )
623 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
624 // Get coordinates of mainbranch
629 if (ok) ((BranchObj*)selection)->move (x,y);
635 } else if (com=="setHeading")
637 if (api.checkParamCount(1))
639 s=api.parString (ok,0);
640 if (ok) setHeading (s);
642 } else if (com=="setURL")
644 if (api.checkParamCount(1))
646 s=api.parString (ok,0);
649 } else if (com=="setVymLink")
651 if (api.checkParamCount(1))
653 s=api.parString (ok,0);
654 if (ok) setVymLink(s);
657 // Internal commands, used for undo etc.
658 else if (com==QString("undoMap"))
660 if (api.checkParamCount(1))
661 undoXML("",api.parString (ok,0));
662 } else if (com==QString("undoPart"))
664 if (api.checkParamCount(2))
666 s=api.parString (ok,0);
667 t=api.parString (ok,1);
670 } else if (com=="select")
671 if (api.checkParamCount(1))
673 s=api.parString(ok,0);
678 api.setError ("Unknown command in: "+atom);
679 cout << "ME::parse api should have error now...\n";
685 qWarning("MapEditor::parseAtom: Error!");
686 qWarning(api.errorDesc());
691 void MapEditor::finishedLineEdit()
693 // This is called by finishedLineEdit or any MapEditor method,
694 // which wants to assure, that lineedits finish, before e.g. a branch is
697 // After calling LineEdit and using the clipboard, the
698 // focus is not any longer on the main widget, we
699 // have to restore it using parentWidget()->setFocus()
703 saveState("setHeading (\""+editingBO->getHeading()+"\")",editingBO, QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(lineedit->text()) );
704 editingBO->setHeading(lineedit->text() );
706 lineedit->releaseKeyboard();
708 parentWidget()->setFocus();
709 mapCenter->reposition();
711 ensureSelectionVisible();
715 void MapEditor::toggleHistoryWindow()
717 if (historyWindow->isVisible())
718 historyWindow->hide();
720 historyWindow->show();
724 bool MapEditor::isDefault()
729 bool MapEditor::isUnsaved()
734 bool MapEditor::hasChanged()
739 void MapEditor::setChanged()
744 actionEditUndo->setEnabled (true);
745 actionFileSave->setEnabled (true);
749 void MapEditor::closeMap()
751 // Finish open lineEdits
752 if (lineedit) finishedLineEdit();
754 // Unselect before disabling the toolbar actions
755 if (selection) selection->unselect();
763 void MapEditor::setFilePath(QString fname)
765 setFilePath (fname,fname);
768 void MapEditor::setFilePath(QString fname, QString destname)
770 if (fname.isEmpty() || fname=="")
777 filePath=fname; // becomes absolute path
778 fileName=fname; // gets stripped of path
779 destPath=destname; // needed for vymlinks
781 // If fname is not an absolute path, complete it
782 filePath=QDir(fname).absPath();
783 fileDir=filePath.left (1+filePath.findRev ("/"));
785 // Set short name, too. Search from behind:
786 int i=fileName.findRev("/");
787 if (i>=0) fileName=fileName.remove (0,i+1);
789 // Forget the .vym (or .xml) for name of map
790 mapName=fileName.left(fileName.findRev(".",-1,true) );
792 // Adjust history window
793 historyWindow->setCaption (fileName);
797 QString MapEditor::getFilePath()
802 QString MapEditor::getFileName()
807 QString MapEditor::getMapName()
812 QString MapEditor::getDestPath()
817 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
819 // Finish open lineEdits
820 if (lineedit) finishedLineEdit();
822 ErrorCode err=success;
826 if (selection) selection->unselect();
829 mapCenter->setMapEditor(this);
830 // (map state is set later at end of load...)
833 saveState(selection,"Load map");
837 mapBuilderHandler handler;
840 // I am paranoid: file should exist anyway
841 // according to check in mainwindow.
844 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
845 tr("Couldn't open map " +fname)+".");
849 blockReposition=true;
850 QXmlInputSource source( file);
851 QXmlSimpleReader reader;
852 reader.setContentHandler( &handler );
853 reader.setErrorHandler( &handler );
854 handler.setMapEditor( this );
855 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
856 handler.setInputFile (file.name());
857 handler.setLoadMode (lmode);
859 bool ok = reader.parse( source );
860 blockReposition=false;
861 blockSaveState=false;
865 mapCenter->reposition();
875 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
876 tr( handler.errorProtocol() ) );
878 // Still return "success": the map maybe at least
879 // partially read by the parser
886 int MapEditor::save (const SaveMode &savemode)
888 // Finish open lineEdits
889 if (lineedit) finishedLineEdit();
893 // The SaveMode UndoCommand is not supported here
894 if (savemode==UndoCommand) return 1;
896 // Create mapName and fileDir
897 makeSubDirs (fileDir);
901 fname=mapName+".xml";
903 // use name given by user, even if he chooses .doc
908 if (savemode==CompleteMap || selection==NULL)
909 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
911 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
913 if (!saveStringToDisk(fileDir+fname,saveFile))
920 actionFileSave->setEnabled(false);
926 void MapEditor::setZipped (bool z)
931 bool MapEditor::saveZipped ()
936 void MapEditor::print()
938 // Finish open lineEdits
939 if (lineedit) finishedLineEdit();
943 printer = new QPrinter;
944 printer->setColorMode (QPrinter::Color);
945 printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
948 QRect totalBBox=mapCenter->getTotalBBox();
950 // Try to set orientation automagically
951 // Note: Interpretation of generated postscript is amibiguous, if
952 // there are problems with landscape mode, see
953 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
955 if (totalBBox.width()>totalBBox.height())
956 // recommend landscape
957 printer->setOrientation (QPrinter::Landscape);
959 // recommend portrait
960 printer->setOrientation (QPrinter::Portrait);
962 if ( printer->setup(this) )
963 // returns false, if printing is canceled
965 QPainter pp(printer);
967 // Don't print the visualisation of selection
968 LinkableMapObj *oldselection=NULL;
971 oldselection=selection;
972 selection->unselect();
975 // Handle sizes of map and paper:
977 // setWindow defines which part of the canvas will be transformed
978 // setViewport defines area on paper in device coordinates (dpi)
979 // e.g. (0,50,700,700) is upper part on A4
980 // see also /usr/lib/qt3/doc/html/coordsys.html
982 Q3PaintDeviceMetrics metrics (printer);
984 double paperAspect = (double)metrics.width() / (double)metrics.height();
985 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
987 QRect mapRect=totalBBox;
988 Q3CanvasRectangle *frame=NULL;
989 Q3CanvasText *footerFN=NULL;
990 Q3CanvasText *footerDate=NULL;
991 if (printFrame || printFooter)
996 // Print frame around map
997 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
998 totalBBox.width()+20, totalBBox.height()+20);
999 frame=new Q3CanvasRectangle (mapRect,mapCanvas);
1000 frame->setBrush (QColor(Qt::white));
1001 frame->setPen (QColor(Qt::black));
1005 /* TODO remove after testing
1006 QCanvasLine *l=new QCanvasLine (mapCanvas);
1007 l->setPoints (0,0,mapRect.width(),mapRect.height());
1008 l->setPen (QPen(QColor(black), 1));
1015 // Print footer below map
1017 font.setPointSize(10);
1018 footerFN=new Q3CanvasText (mapCanvas);
1019 footerFN->setText ("VYM - " + fileName);
1020 footerFN->setFont(font);
1021 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1022 footerFN->setZ(Z_TEXT);
1024 footerDate=new Q3CanvasText (mapCanvas);
1025 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1026 footerDate->setFont(font);
1027 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1028 footerDate->setZ(Z_TEXT);
1031 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1034 pp.setWindow (mapRect);
1037 if (mapAspect>=paperAspect)
1039 // Fit horizontally to paper width
1040 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1043 // Fit vertically to paper height
1044 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1047 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1049 // Delete Frame and footer
1053 delete (footerDate);
1055 if (frame) delete (frame);
1057 // Restore selection
1060 selection=oldselection;
1061 selection->select();
1064 // Save settings in vymrc
1065 settings.writeEntry("/mainwindow/printerName",printer->printerName());
1069 QPixmap MapEditor::getPixmap()
1071 QRect mapRect=mapCenter->getTotalBBox();
1072 QPixmap pix (mapRect.size());
1075 // Don't print the visualisation of selection
1076 LinkableMapObj *oldselection=NULL;
1079 oldselection=selection;
1080 selection->unselect();
1083 pp.setWindow (mapRect);
1085 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1088 // Restore selection
1091 selection=oldselection;
1092 selection->select();
1098 void MapEditor::setHideTmpMode (HideTmpMode mode)
1101 mapCenter->setHideTmp (hidemode);
1102 mapCenter->reposition();
1107 HideTmpMode MapEditor::getHideTmpMode()
1112 void MapEditor::exportImage(QString fn)
1114 // Finish open lineEdits
1115 if (lineedit) finishedLineEdit();
1117 setExportMode (true);
1118 QPixmap pix (getPixmap());
1119 pix.save(fn, "PNG");
1120 setExportMode (false);
1123 void MapEditor::setExportMode (bool b)
1125 // should be called before and after exports
1126 // depending on the settings
1127 if (b && settings.value("/export/useHideExport","yes")=="yes")
1128 setHideTmpMode (HideExport);
1130 setHideTmpMode (HideNone);
1133 void MapEditor::exportImage(QString fn, QString format)
1135 // Finish open lineEdits
1136 if (lineedit) finishedLineEdit();
1138 setExportMode (true);
1139 QPixmap pix (getPixmap());
1140 pix.save(fn, format);
1141 setExportMode (false);
1144 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1148 ex.setMapCenter(mapCenter);
1149 if (ex.setConfigFile(cf))
1151 setExportMode (true);
1152 ex.exportPresentation();
1153 setExportMode (false);
1159 void MapEditor::exportXML(const QString &dir)
1161 // Hide stuff during export, if settings want this
1162 setExportMode (true);
1164 // Create subdirectories
1167 // write to directory
1168 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1171 file.setName ( dir + "/"+mapName+".xml");
1172 if ( !file.open( QIODevice::WriteOnly ) )
1174 // This should neverever happen
1175 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1179 // Write it finally, and write in UTF8, no matter what
1180 QTextStream ts( &file );
1181 ts.setEncoding (QTextStream::UnicodeUTF8);
1185 // Now write image, too
1186 exportImage (dir+"/images/"+mapName+".png");
1188 setExportMode (false);
1191 void MapEditor::clear()
1195 selection->unselect();
1202 void MapEditor::copy()
1204 // Finish open lineEdits
1205 if (lineedit) finishedLineEdit();
1209 // write to directory
1210 QString clipfile="part";
1211 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1214 file.setName ( clipboardDir + "/"+clipfile+".xml");
1215 if ( !file.open( QIODevice::WriteOnly ) )
1217 // This should neverever happen
1218 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1222 // Write it finally, and write in UTF8, no matter what
1223 QTextStream ts( &file );
1224 ts.setEncoding (QTextStream::UnicodeUTF8);
1228 clipboardEmpty=false;
1233 void MapEditor::redo()
1235 // Finish open lineEdits
1236 if (lineedit) finishedLineEdit();
1238 blockSaveState=true;
1240 // Find out current undo directory
1241 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1243 // Restore variables
1244 QString undoCommand;
1245 QString undoSelection;
1246 QString redoCommand;
1247 QString redoSelection;
1249 set.readSettings(QString(bakMapDir+"/commands"));
1250 undoCommand=set.readEntry ("undoCommand");
1251 undoSelection=set.readEntry ("undoSelection");
1252 redoCommand=set.readEntry ("redoCommand");
1253 redoSelection=set.readEntry ("redoSelection");
1255 // select object before redo
1256 if (!redoSelection.isEmpty())
1257 select (redoSelection);
1259 /* TODO remove testing
1260 cout << "ME::redo() begin\n";
1261 cout << " undosTotal="<<undosTotal<<endl;
1262 cout << " undosAvail="<<undosAvail<<endl;
1263 cout << " undoNum="<<undoNum<<endl;
1264 cout << " ---------------------------"<<endl;
1265 cout << " undoCom="<<undoCommand<<endl;
1266 cout << " undoSel="<<undoSelection<<endl;
1267 cout << " ---------------------------"<<endl;
1268 cout << " redoCom="<<redoCommand<<endl;
1269 cout << " redoSel="<<redoSelection<<endl;
1270 cout << " ---------------------------"<<endl;
1272 parseAtom (undoCommand);
1273 mapCenter->reposition();
1275 //if (!redoSelection.isEmpty())
1276 // select (redoSelection);
1280 // Undo not longer available now
1281 actionEditUndo->setEnabled (false);
1283 undoNum--; if (undoNum<1) undoNum=undosTotal;
1285 blockSaveState=false;
1286 /* TODO remove testing
1287 cout << "ME::redo() end\n";
1288 cout << " undosAvail="<<undosAvail<<endl;
1289 cout << " undoNum="<<undoNum<<endl;
1290 cout << " ---------------------------"<<endl<<endl;
1294 void MapEditor::undo()
1296 // Finish open lineEdits
1297 if (lineedit) finishedLineEdit();
1299 blockSaveState=true;
1301 // Find out current undo directory
1302 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1304 // Restore variables
1305 QString undoCommand;
1306 QString undoSelection;
1307 QString redoCommand;
1308 QString redoSelection;
1310 set.readSettings(QString(bakMapDir+"/commands"));
1311 undoCommand= set.readEntry ("undoCommand");
1312 undoSelection=set.readEntry ("undoSelection");
1313 redoCommand= set.readEntry ("redoCommand");
1314 redoSelection=set.readEntry ("redoSelection");
1316 // select object before undo
1317 if (!undoSelection.isEmpty())
1318 select (undoSelection);
1321 cout << "ME::undo() begin\n";
1322 cout << " undosTotal="<<undosTotal<<endl;
1323 cout << " undosAvail="<<undosAvail<<endl;
1324 cout << " undoNum="<<undoNum<<endl;
1325 cout << " ---------------------------"<<endl;
1326 cout << " undoCom="<<undoCommand<<endl;
1327 cout << " undoSel="<<undoSelection<<endl;
1328 cout << " ---------------------------"<<endl;
1329 cout << " redoCom="<<redoCommand<<endl;
1330 cout << " redoSel="<<redoSelection<<endl;
1331 cout << " ---------------------------"<<endl;
1333 parseAtom (undoCommand);
1334 mapCenter->reposition();
1336 //if (!redoSelection.isEmpty())
1337 // select (redoSelection);
1341 // Undo not longer available now
1342 actionEditUndo->setEnabled (false);
1344 undoNum--; if (undoNum<1) undoNum=undosTotal;
1346 blockSaveState=false;
1347 /* TODO remove testing
1348 cout << "ME::undo() end\n";
1349 cout << " undosAvail="<<undosAvail<<endl;
1350 cout << " undoNum="<<undoNum<<endl;
1351 cout << " ---------------------------"<<endl<<endl;
1355 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1357 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1359 QFile file (bakMapPath);
1363 // We need to parse saved XML data
1364 mapBuilderHandler handler;
1365 QXmlInputSource source( file);
1366 QXmlSimpleReader reader;
1367 reader.setContentHandler( &handler );
1368 reader.setErrorHandler( &handler );
1369 handler.setMapEditor( this );
1370 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1371 if (undoSel.isEmpty())
1375 handler.setLoadMode (NewMap);
1379 handler.setLoadMode (ImportReplace);
1381 blockReposition=true;
1382 bool ok = reader.parse( source );
1383 blockReposition=false;
1386 // This should never ever happen
1387 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1388 tr( handler.errorProtocol() )+" in "+bakMapDir );
1392 QMessageBox::critical( 0, tr( "Critical Error" ),
1393 tr("Temporary directory %1 used for undo is gone. \n"
1394 "I will create a new one, but at the moment no undo is available.\n"
1395 "Maybe you want to reload your original data.\n\n"
1396 "Sorry for any inconveniences.").arg(bakMapDir) );
1401 void MapEditor::pasteNoSave()
1403 // Finish open lineEdits
1404 if (lineedit) finishedLineEdit();
1406 load (clipboardDir+"/part.xml",ImportAdd);
1409 void MapEditor::cutNoSave()
1415 void MapEditor::paste()
1417 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1418 typeid(*selection) == typeid(MapCenterObj)))
1420 saveState(selection,QString("Paste to %1").arg( getName(selection)));
1422 mapCenter->reposition();
1427 void MapEditor::cut()
1429 saveState(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
1432 mapCenter->reposition();
1436 void MapEditor::move(const int &x, const int &y)
1438 // TODO no saveState, because this is only internal at undo so far
1439 if (selection) selection->move(x,y);
1440 if (typeid(*selection) == typeid(FloatImageObj))
1441 ((FloatImageObj*)selection)->setRelPos();
1444 void MapEditor::moveBranchUp()
1446 // Finish open lineEdits
1447 if (lineedit) finishedLineEdit();
1451 if (typeid(*selection) == typeid(BranchObj) )
1453 bo=(BranchObj*)selection;
1454 if (!bo->canMoveBranchUp()) return;
1455 par=(BranchObj*)(bo->getParObj());
1456 selection->unselect();
1457 selection=par->moveBranchUp (bo);
1458 selection->select();
1459 saveState("moveBranchDown ()",bo,QString("Move up %1").arg(getName(bo)));
1460 mapCenter->reposition();
1461 ensureSelectionVisible();
1465 void MapEditor::moveBranchDown()
1467 // Finish open lineEdits
1468 if (lineedit) finishedLineEdit();
1472 if (typeid(*selection) == typeid(BranchObj) )
1474 bo=(BranchObj*)selection;
1475 if (!bo->canMoveBranchDown()) return;
1476 par=(BranchObj*)(bo->getParObj());
1477 selection->unselect();
1478 selection=par->moveBranchDown(bo);
1479 selection->select();
1480 saveState("moveBranchUp ()",bo,QString("Move down %1").arg(getName(bo)));
1481 mapCenter->reposition();
1482 ensureSelectionVisible();
1486 void MapEditor::editHeading()
1488 // Finish open lineEdits
1489 if (lineedit->isVisible())
1496 (typeid(*selection) == typeid(BranchObj) ||
1497 typeid(*selection) == typeid(MapCenterObj) ) )
1499 editingBO=(BranchObj*)selection;
1501 ensureSelectionVisible();
1502 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1503 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1504 QString s=editingBO->getHeading();
1505 lineedit->setText(s);
1506 lineedit->setCursorPosition(1);
1507 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1508 lineedit->selectAll();
1510 lineedit->setFocus();
1511 lineedit->grabKeyboard();
1512 cout << "le="<<lineedit<<" kgrabber="<<keyboardGrabber()<<endl;
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)
2237 QTextDocument::FindFlags flags=0;
2238 if (cs) flags=QTextDocument::QTextDocument::FindCaseSensitively;
2241 { // Nothing found or new find process
2243 // nothing found, start again
2245 itFind=mapCenter->first();
2247 bool searching=true;
2248 bool foundNote=false;
2249 while (searching && !EOFind)
2253 // Searching in Note
2254 if (itFind->getNote().contains(s,cs))
2256 if (selection!=itFind)
2258 if (selection) ((BranchObj*)selection)->unselect();
2260 selection->select();
2262 ensureSelectionVisible();
2264 if (textEditor->findText(s,flags))
2270 // Searching in Heading
2271 if (searching && itFind->getHeading().contains (s,cs) )
2273 if (selection) ((BranchObj*)selection)->unselect();
2275 selection->select();
2277 ensureSelectionVisible();
2283 itFind=itFind->next();
2284 if (!itFind) EOFind=true;
2290 return (BranchObj*)selection;
2295 void MapEditor::findReset()
2296 { // Necessary if text to find changes during a find process
2301 void MapEditor::editURL()
2303 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2304 typeid(*selection) == typeid(MapCenterObj)) )
2307 BranchObj *bo=(BranchObj*)selection;
2308 QString text = QInputDialog::getText(
2309 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2310 bo->getURL(), &ok, this );
2313 // user entered something and pressed OK
2314 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2321 QString MapEditor::getURL()
2323 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2324 typeid(*selection) == typeid(MapCenterObj)) )
2325 return ((BranchObj*)selection)->getURL();
2330 void MapEditor::editHeading2URL()
2332 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2333 typeid(*selection) == typeid(MapCenterObj)) )
2335 BranchObj *bo=(BranchObj*)selection;
2336 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2337 bo->setURL (bo->getHeading());
2342 void MapEditor::editBugzilla2URL()
2344 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2345 typeid(*selection) == typeid(MapCenterObj)) )
2347 BranchObj *bo=(BranchObj*)selection;
2348 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2349 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo)));
2355 void MapEditor::editFATE2URL()
2357 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2358 typeid(*selection) == typeid(MapCenterObj)) )
2360 BranchObj *bo=(BranchObj*)selection;
2361 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2362 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2368 void MapEditor::editVymLink()
2370 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2371 typeid(*selection) == typeid(MapCenterObj)) )
2373 BranchObj *bo=(BranchObj*)selection;
2374 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map"));
2375 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2376 fd->setCaption(__VYM " - " +tr("Link to another map"));
2377 if (! bo->getVymLink().isEmpty() )
2378 fd->setSelection( bo->getVymLink() );
2382 if ( fd->exec() == QDialog::Accepted )
2384 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2385 bo->setVymLink (fd->selectedFile() );
2387 mapCenter->reposition();
2394 void MapEditor::deleteVymLink()
2396 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2397 typeid(*selection) == typeid(MapCenterObj)) )
2399 BranchObj *bo=(BranchObj*)selection;
2400 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2401 bo->setVymLink ("" );
2403 mapCenter->reposition();
2409 void MapEditor::toggleHideExport()
2411 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2412 typeid(*selection) == typeid(MapCenterObj)) ||
2413 (typeid(*selection)==typeid(FloatImageObj))
2416 OrnamentedObj *oo=(OrnamentedObj*)selection;
2418 if (oo->hideInExport())
2420 oo->setHideInExport(false);
2425 oo->setHideInExport(true);
2428 saveState(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2429 actionEditToggleHideExport->setOn (oo->hideInExport());
2431 mapCenter->reposition();
2437 QString MapEditor::getVymLink()
2439 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2440 typeid(*selection) == typeid(MapCenterObj)) )
2442 return ((BranchObj*)selection)->getVymLink();
2448 void MapEditor::removeBranchKeepChilds()
2450 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2452 BranchObj* bo=(BranchObj*)selection;
2453 BranchObj* par=(BranchObj*)(bo->getParObj());
2454 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2455 if (bo->getDepth()==1)
2458 saveState(selection->getParObj(),s); // TODO undoCommand
2459 QString sel=selection->getSelectString();
2461 par->removeBranchHere(bo);
2462 mapCenter->reposition();
2467 void MapEditor::removeChilds()
2469 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2471 saveState(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
2472 ((BranchObj*)selection)->removeChilds();
2473 mapCenter->reposition();
2477 void MapEditor::editMapInfo()
2479 ExtraInfoDialog dia;
2480 dia.setMapName (getFileName() );
2481 dia.setAuthor (mapCenter->getAuthor() );
2482 dia.setComment(mapCenter->getComment() );
2487 Q3CanvasItemList l=canvas()->allItems();
2488 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2490 stats+=QString ("%1 items on canvas\n").arg (i,6);
2497 bo=mapCenter->first();
2500 if (!bo->getNote().isEmpty() ) n++;
2501 f+= bo->countFloatImages();
2503 xl+=bo->countXLinks();
2506 stats+=QString ("%1 branches\n").arg (b-1,6);
2507 stats+=QString ("%1 xLinks \n").arg (xl,6);
2508 stats+=QString ("%1 notes\n").arg (n,6);
2509 stats+=QString ("%1 images\n").arg (f,6);
2510 dia.setStats (stats);
2512 // Finally show dialog
2513 if (dia.exec() == QDialog::Accepted)
2515 saveState("Edit info about map"); //TODO undoCommand
2516 mapCenter->setAuthor (dia.getAuthor() );
2517 mapCenter->setComment (dia.getComment() );
2521 void MapEditor::updateActions()
2524 if (getLinkColorHint()==HeadingColor)
2525 actionFormatLinkColorHint->setOn(true);
2527 actionFormatLinkColorHint->setOn(false);
2532 actionFormatLinkStyleLine->setOn(true);
2535 actionFormatLinkStyleParabel->setOn(true);
2538 actionFormatLinkStylePolyLine->setOn(true);
2540 case StylePolyParabel:
2541 actionFormatLinkStylePolyParabel->setOn(true);
2547 QPixmap pix( 16, 16 );
2548 pix.fill( mapCanvas->backgroundColor() );
2549 actionFormatBackColor->setIconSet( pix );
2550 pix.fill( defLinkColor );
2551 actionFormatLinkColor->setIconSet( pix );
2553 actionEditUndo->setEnabled( mapChanged );
2554 actionFileSave->setEnabled( mapUnsaved );
2558 if ( (typeid(*selection) == typeid(BranchObj)) ||
2559 (typeid(*selection) == typeid(MapCenterObj)) )
2561 BranchObj *bo=(BranchObj*)selection;
2562 // Take care of links
2563 if (bo->countXLinks()==0)
2565 branchLinksContextMenuEdit->clear();
2566 branchLinksContextMenuFollow->clear();
2571 branchLinksContextMenuEdit->clear();
2572 branchLinksContextMenuFollow->clear();
2573 for (int i=0; i<=bo->countXLinks();i++)
2575 bot=bo->XLinkTargetAt(i);
2578 s=bot->getHeading();
2581 branchLinksContextMenuFollow->addAction (s);
2582 branchLinksContextMenuEdit->addAction (s);
2587 standardFlagsDefault->setEnabled (true);
2589 actionEditToggleScroll->setEnabled (true);
2590 if ( bo->isScrolled() )
2591 actionEditToggleScroll->setOn(true);
2593 actionEditToggleScroll->setOn(false);
2595 if ( bo->getURL().isEmpty() )
2597 actionEditOpenURL->setEnabled (false);
2598 actionEditOpenURLTab->setEnabled (false);
2602 actionEditOpenURL->setEnabled (true);
2603 actionEditOpenURLTab->setEnabled (true);
2605 if ( bo->getVymLink().isEmpty() )
2607 actionEditOpenVymLink->setEnabled (false);
2608 actionEditDeleteVymLink->setEnabled (false);
2611 actionEditOpenVymLink->setEnabled (true);
2612 actionEditDeleteVymLink->setEnabled (true);
2615 if (bo->canMoveBranchUp())
2616 actionEditMoveUp->setEnabled (true);
2618 actionEditMoveUp->setEnabled (false);
2619 if (bo->canMoveBranchDown())
2620 actionEditMoveDown->setEnabled (true);
2622 actionEditMoveDown->setEnabled (false);
2625 actionEditToggleHideExport->setEnabled (true);
2626 actionEditToggleHideExport->setOn (bo->hideInExport() );
2628 actionEditCopy->setEnabled (true);
2629 actionEditCut->setEnabled (true);
2630 if (!clipboardEmpty)
2631 actionEditPaste->setEnabled (true);
2633 actionEditPaste->setEnabled (false);
2634 for (a=actionListBranches.first();a;a=actionListBranches.next())
2635 a->setEnabled(true);
2636 actionEditDelete->setEnabled (true);
2637 switch (selection->getFrameType())
2640 actionFormatFrameNone->setOn(true);
2643 actionFormatFrameRectangle->setOn(true);
2648 actionFormatIncludeImagesVer->setOn
2649 ( ((BranchObj*)selection)->getIncludeImagesVer());
2650 actionFormatIncludeImagesHor->setOn
2651 ( ((BranchObj*)selection)->getIncludeImagesHor());
2652 actionFormatHideLinkUnselected->setOn
2653 (selection->getHideLinkUnselected());
2655 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2657 FloatObj *fo=(FloatImageObj*)selection;
2658 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2660 actionEditOpenURL->setEnabled (false);
2661 actionEditOpenVymLink->setEnabled (false);
2662 actionEditDeleteVymLink->setEnabled (false);
2663 actionEditToggleHideExport->setEnabled (true);
2664 actionEditToggleHideExport->setOn (fo->hideInExport() );
2667 actionEditCopy->setEnabled (true);
2668 actionEditCut->setEnabled (true);
2669 actionEditPaste->setEnabled (false);
2670 for (a=actionListBranches.first();a;a=actionListBranches.next())
2671 a->setEnabled(false);
2672 actionEditDelete->setEnabled (true);
2673 actionFormatHideLinkUnselected->setOn
2674 ( selection->getHideLinkUnselected());
2675 actionEditMoveUp->setEnabled (false);
2676 actionEditMoveDown->setEnabled (false);
2681 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2683 actionEditCopy->setEnabled (false);
2684 actionEditCut->setEnabled (false);
2685 actionEditPaste->setEnabled (false);
2686 for (a=actionListBranches.first();a;a=actionListBranches.next())
2687 a->setEnabled(false);
2689 actionEditToggleScroll->setEnabled (false);
2690 actionEditOpenURL->setEnabled (false);
2691 actionEditOpenVymLink->setEnabled (false);
2692 actionEditDeleteVymLink->setEnabled (false);
2693 actionEditHeading2URL->setEnabled (false);
2694 actionEditDelete->setEnabled (false);
2695 actionEditMoveUp->setEnabled (false);
2696 actionEditMoveDown->setEnabled (false);
2697 actionEditToggleHideExport->setEnabled (false);
2701 void MapEditor::updateNoteFlag()
2704 if ( (typeid(*selection) == typeid(BranchObj)) ||
2705 (typeid(*selection) == typeid(MapCenterObj)) )
2706 ((BranchObj*)selection)->updateNoteFlag();
2709 void MapEditor::setLinkStyle (LinkStyle ls)
2713 saveState("Set link style"); // TODO undoCommand
2715 bo=mapCenter->first();
2719 bo->setLinkStyle(bo->getDefLinkStyle());
2722 mapCenter->reposition();
2725 LinkStyle MapEditor::getLinkStyle ()
2730 void MapEditor::setLinkColor(QColor c)
2736 void MapEditor::setLinkColorHint()
2738 // called from setLinkColorHint(lch) or at end of parse
2740 bo=mapCenter->first();
2748 void MapEditor::setLinkColorHint(LinkColorHint lch)
2754 void MapEditor::toggleLinkColorHint()
2756 if (linkcolorhint==HeadingColor)
2757 linkcolorhint=DefaultColor;
2759 linkcolorhint=HeadingColor;
2761 bo=mapCenter->first();
2769 LinkColorHint MapEditor::getLinkColorHint()
2771 return linkcolorhint;
2774 QColor MapEditor::getDefLinkColor()
2776 return defLinkColor;
2779 void MapEditor::setDefXLinkColor(QColor col)
2784 QColor MapEditor::getDefXLinkColor()
2786 return defXLinkColor;
2789 void MapEditor::setDefXLinkWidth (int w)
2794 int MapEditor::getDefXLinkWidth()
2796 return defXLinkWidth;
2799 void MapEditor::selectLinkColor()
2801 // Finish open lineEdits
2802 if (lineedit) finishedLineEdit();
2804 QColor col = QColorDialog::getColor( defLinkColor, this );
2805 if ( !col.isValid() ) return;
2806 setLinkColor( col );
2807 saveState(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2811 void MapEditor::toggleScroll()
2813 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2815 BranchObj *bo=((BranchObj*)selection);
2816 if (bo->countBranches()==0) return;
2817 if (bo->getDepth()==0) return;
2819 if (bo->isScrolled())
2823 saveState(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2830 void MapEditor::unScrollAll()
2833 bo=mapCenter->first();
2836 if (bo->isScrolled()) bo->toggleScroll();
2841 void MapEditor::loadFloatImage ()
2844 (typeid(*selection) == typeid(BranchObj)) ||
2845 (typeid(*selection) == typeid(MapCenterObj)) )
2847 BranchObj *bo=((BranchObj*)selection);
2849 Q3FileDialog *fd=new Q3FileDialog( this);
2850 fd->setMode (Q3FileDialog::ExistingFiles);
2851 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2852 ImagePreview *p =new ImagePreview (fd);
2853 fd->setContentsPreviewEnabled( TRUE );
2854 fd->setContentsPreview( p, p );
2855 fd->setPreviewMode( Q3FileDialog::Contents );
2856 fd->setCaption(__VYM " - " +tr("Load image"));
2857 fd->setDir (lastImageDir);
2861 if ( fd->exec() == QDialog::Accepted )
2863 saveState(selection, QString("Add floatimage to %1").arg(getName(selection)));
2864 // FIXME in QT4 use: lastImageDir=fd->directory();
2865 lastImageDir=QDir (fd->dirPath());
2866 QStringList flist = fd->selectedFiles();
2867 QStringList::Iterator it = flist.begin();
2868 while( it != flist.end() )
2871 bo->addFloatImage();
2872 // TODO check if load was successful
2873 bo->getLastFloatImage()->load(*it);
2874 bo->getLastFloatImage()->setOriginalFilename(fn);
2878 mapCenter->reposition();
2887 void MapEditor::saveFloatImage ()
2890 (typeid(*selection) == typeid(FloatImageObj)) )
2892 FloatImageObj *fio=((FloatImageObj*)selection);
2893 QFileDialog *fd=new QFileDialog( this);
2894 fd->setFilters (imageIO.getFilters());
2895 fd->setCaption(__VYM " - " +tr("Save image"));
2896 fd->setFileMode( QFileDialog::AnyFile );
2897 fd->setDirectory (lastImageDir);
2898 // fd->setSelection (fio->getOriginalFilename());
2902 if ( fd->exec() == QDialog::Accepted )
2904 if (QFile (fd->selectedFile()).exists() )
2906 QMessageBox mb( __VYM,
2907 tr("The file %1 exists already.\n"
2908 "Do you want to overwrite it?").arg(fd->selectedFile()),
2909 QMessageBox::Warning,
2910 QMessageBox::Yes | QMessageBox::Default,
2911 QMessageBox::Cancel | QMessageBox::Escape,
2912 QMessageBox::QMessageBox::NoButton );
2914 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2915 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2918 case QMessageBox::Yes:
2921 case QMessageBox::Cancel:
2927 fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
2932 void MapEditor::setFrame(const FrameType &t)
2935 (typeid(*selection) == typeid(BranchObj)) ||
2936 (typeid(*selection) == typeid(MapCenterObj)) )
2938 selection->setFrameType (t);
2939 mapCenter->reposition();
2940 selection->updateLink();
2944 void MapEditor::setIncludeImagesVer(bool b)
2947 (typeid(*selection) == typeid(BranchObj)) ||
2948 (typeid(*selection) == typeid(MapCenterObj)) )
2949 ((BranchObj*)selection)->setIncludeImagesVer(b);
2950 mapCenter->reposition();
2953 void MapEditor::setIncludeImagesHor(bool b)
2956 (typeid(*selection) == typeid(BranchObj)) ||
2957 (typeid(*selection) == typeid(MapCenterObj)) )
2958 ((BranchObj*)selection)->setIncludeImagesHor(b);
2959 mapCenter->reposition();
2962 void MapEditor::setHideLinkUnselected (bool b)
2965 (typeid(*selection) == typeid(BranchObj)) ||
2966 (typeid(*selection) == typeid(MapCenterObj)) ||
2967 (typeid(*selection) == typeid(FloatImageObj)) )
2968 selection->setHideLinkUnselected(b);
2971 void MapEditor::importDir(BranchObj *dst, QDir d)
2974 (typeid(*selection) == typeid(BranchObj)) ||
2975 (typeid(*selection) == typeid(MapCenterObj)) )
2979 // Traverse directories
2980 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2981 QFileInfoList list = d.entryInfoList();
2984 for (int i = 0; i < list.size(); ++i)
2987 if (fi.fileName() != "." && fi.fileName() != ".." )
2990 bo=dst->getLastBranch();
2991 bo->setHeading (fi.fileName() );
2992 bo->setColor (QColor("blue"));
2994 if ( !d.cd(fi.fileName()) )
2995 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
2998 // Recursively add subdirs
3005 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3006 list = d.entryInfoList();
3008 for (int i = 0; i < list.size(); ++i)
3012 bo=dst->getLastBranch();
3013 bo->setHeading (fi.fileName() );
3014 bo->setColor (QColor("black"));
3015 if (fi.fileName().right(4) == ".vym" )
3016 bo->setVymLink (fi.filePath());
3021 void MapEditor::importDir()
3024 (typeid(*selection) == typeid(BranchObj)) ||
3025 (typeid(*selection) == typeid(MapCenterObj)) )
3027 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
3028 fd->setMode (Q3FileDialog::DirectoryOnly);
3029 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3030 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
3034 if ( fd->exec() == QDialog::Accepted )
3036 BranchObj *bo=((BranchObj*)selection);
3037 importDir (bo,QDir(fd->selectedFile()) );
3038 mapCenter->reposition();
3045 void MapEditor::followXLink(int i)
3048 (typeid(*selection) == typeid(BranchObj)) ||
3049 (typeid(*selection) == typeid(MapCenterObj)) )
3051 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3054 selection->unselect();
3056 selection->select();
3057 ensureSelectionVisible();
3062 void MapEditor::editXLink(int i)
3066 (typeid(*selection) == typeid(BranchObj)) ||
3067 (typeid(*selection) == typeid(MapCenterObj)) )
3069 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3072 EditXLinkDialog dia;
3074 dia.setSelection(selection);
3075 if (dia.exec() == QDialog::Accepted)
3077 if (dia.useSettingsGlobal() )
3079 setDefXLinkColor (xlo->getColor() );
3080 setDefXLinkWidth (xlo->getWidth() );
3082 if (dia.deleteXLink())
3083 ((BranchObj*)selection)->deleteXLinkAt(i);
3084 saveState("Edit xLink"); //TODO undoCommand
3090 void MapEditor::testFunction()
3092 cout << "MapEditor::testFunction() called\n";
3094 mapCenter->positionBBox();
3098 dia.setCancelButton (true);
3099 dia.setText("This is a longer \nWarning");
3100 dia.setCaption("Warning: Flux problem");
3101 dia.setShowAgainName("/warnings/mapeditor");
3102 if (dia.exec()==QDialog::Accepted)
3103 cout << "accepted!\n";
3105 cout << "canceled!\n";
3108 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
3110 QProcess *proc= new QProcess (this);
3112 if (!proc->waitForStarted());
3114 QMessageBox::warning(0,
3116 tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
3120 /* Hide hidden stuff temporary, maybe add this as regular function somewhere
3121 if (hidemode==HideNone)
3123 setHideTmpMode (HideExport);
3124 mapCenter->calcBBoxSizeWithChilds();
3125 QRect totalBBox=mapCenter->getTotalBBox();
3126 QRect mapRect=totalBBox;
3127 QCanvasRectangle *frame=NULL;
3129 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3131 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3132 totalBBox.width(), totalBBox.height());
3133 frame=new QCanvasRectangle (mapRect,mapCanvas);
3134 frame->setBrush (QColor(white));
3135 frame->setPen (QColor(black));
3141 setHideTmpMode (HideNone);
3143 cout <<" hidemode="<<hidemode<<endl;
3147 void MapEditor::ensureSelectionVisible()
3151 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3153 if (selection->getOrientation() == OrientLeftOfCenter)
3154 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3156 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3157 ensureVisible (p.x(), p.y() );
3162 void MapEditor::updateViewCenter()
3164 // Update movingCenter, so that we can zoom comfortably later
3165 QRect rc = QRect( contentsX(), contentsY(),
3166 visibleWidth(), visibleHeight() );
3167 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3168 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3169 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3172 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3174 // Lineedits are already closed by preceding
3175 // mouseEvent, we don't need to close here.
3177 QPoint p = inverseWorldMatrix().map(e->pos());
3178 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3181 { // MapObj was found
3182 if (selection != lmo)
3184 // select the MapObj
3185 if (selection) selection->unselect();
3187 selection->select();
3193 if (typeid(*selection)==typeid(BranchObj) ||
3194 typeid(*selection)==typeid(MapCenterObj) )
3196 // Context Menu on branch or mapcenter
3198 branchContextMenu->popup(e->globalPos() );
3200 if (typeid(*selection)==typeid(FloatImageObj))
3202 // Context Menu on floatimage
3204 floatimageContextMenu->popup(e->globalPos() );
3208 { // No MapObj found, we are on the Canvas itself
3209 // Context Menu on Canvas
3211 canvasContextMenu->popup(e->globalPos() );
3216 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3218 // Ignore right clicks, these will go to context menus
3219 if (e->button() == Qt::RightButton )
3225 // Finish open lineEdits
3226 if (lineedit) finishedLineEdit();
3228 QPoint p = inverseWorldMatrix().map(e->pos());
3229 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3233 //Take care of clickdesystem flags _or_ modifier modes
3235 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3236 typeid(*lmo)==typeid(MapCenterObj) ))
3238 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3239 if (!foname.isEmpty())
3241 // systemFlag clicked
3245 if (e->state() & Qt::ControlModifier)
3246 mainWindow->editOpenURLTab();
3248 mainWindow->editOpenURL();
3250 else if (foname=="vymLink")
3252 mainWindow->editOpenVymLink();
3253 // tabWidget may change, better return now
3254 // before segfaulting...
3255 } else if (foname=="note")
3256 mainWindow->windowToggleNoteEditor();
3257 else if (foname=="hideInExport")
3262 // No system flag clicked, take care of modmodes
3264 // Special case: CTRL is pressed
3265 if (e->state() & Qt::ControlModifier)
3267 if (actionModModeColor->isOn())
3270 setCursor (pickColorCursor);
3273 if (actionModModeLink->isOn())
3275 BranchObj *bo_begin=NULL;
3277 bo_begin=(BranchObj*)(lmo);
3280 ((typeid(*selection) == typeid(BranchObj)) ||
3281 (typeid(*selection) == typeid(MapCenterObj))) )
3282 bo_begin=(BranchObj*)selection;
3286 linkingObj_src=bo_begin;
3287 tmpXLink=new XLinkObj (mapCanvas);
3288 tmpXLink->setBegin (bo_begin);
3289 tmpXLink->setEnd (p);
3290 tmpXLink->setColor(defXLinkColor);
3291 tmpXLink->setWidth(defXLinkWidth);
3292 tmpXLink->updateXLink();
3293 tmpXLink->setVisibility (true);
3301 // Left Button Move Branches
3302 if (e->button() == Qt::LeftButton )
3304 movingObj_start.setX( p.x() - selection->x() );
3305 movingObj_start.setY( p.y() - selection->y() );
3306 movingObj_orgPos.setX (lmo->x() );
3307 movingObj_orgPos.setY (lmo->y() );
3309 // If modMode==copy, then we want to "move" the _new_ object around
3310 // then we need the offset from p to the _old_ selection, because of tmp
3311 if (actionModModeCopy->isOn() &&
3312 e->state() & Qt::ControlModifier)
3314 if (typeid(*selection)==typeid(BranchObj) )
3317 mapCenter->addBranch ((BranchObj*)selection);
3319 selection=mapCenter->getLastBranch();
3320 selection->select();
3321 mapCenter->reposition();
3324 movingObj=selection;
3326 // Middle Button Toggle Scroll
3327 // (On Mac OS X this won't work, but we still have
3328 // a button in the toolbar)
3329 if (e->button() == Qt::MidButton )
3333 { // No MapObj found, we are on the Canvas itself
3334 // Left Button move Pos of CanvasView
3335 if (e->button() == Qt::LeftButton )
3337 movingObj=NULL; // move Content not Obj
3338 movingObj_start=e->globalPos();
3339 movingCont_start=QPoint (contentsX(), contentsY() );
3340 movingVec=QPoint(0,0);
3341 setCursor(handOpenCursor);
3346 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3348 QPoint p = inverseWorldMatrix().map(e->pos());
3350 // Move the selected MapObj
3351 if ( selection && movingObj)
3353 // To avoid jumping of the CanvasView, only
3354 // ensureSelectionVisible, if not tmp linked
3355 if (!selection->hasParObjTmp())
3356 ensureSelectionVisible ();
3358 // Now move the selection, but add relative position
3359 // (movingObj_start) where selection was chosen with
3360 // mousepointer. (This avoids flickering resp. jumping
3361 // of selection back to absPos)
3363 LinkableMapObj *lmosel;
3364 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3366 // Check if we could link
3367 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3370 if (typeid(*selection) == typeid(FloatImageObj))
3372 FloatObj *fo=(FloatObj*)selection;
3374 "move "+qpointToString(movingObj_orgPos),fo->getSelectString() ,
3375 QString("Move %1").arg(getName(selection)));
3376 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3380 // Relink float to new mapcenter or branch, if shift is pressed
3381 // Only relink, if selection really has a new parent
3382 if ( (e->state() & Qt::ShiftModifier) && lmo &&
3383 ( (typeid(*lmo)==typeid(BranchObj)) ||
3384 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3385 ( lmo != fo->getParObj())
3388 if (typeid(*fo) == typeid(FloatImageObj))
3390 saveState(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3391 FloatImageObj *fio=(FloatImageObj*)(fo);
3392 ((BranchObj*)(lmo))->addFloatImage (fio);
3394 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3395 fio=((BranchObj*)(lmo))->getLastFloatImage();
3398 selection=(LinkableMapObj*)(fio);
3399 selection->select();
3400 movingObj=(MapObj*)(fio);
3403 } else // selection != a FloatObj
3405 if (lmosel->getDepth()==0)
3407 if (e->state() == Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3408 // If mapCenter is moved, move all the rest by default, too.
3409 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3411 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3414 if (lmosel->getDepth()==1)
3416 // depth==1, mainbranch
3417 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3421 if (lmosel->getOrientation() == OrientLeftOfCenter)
3422 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3423 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3424 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3426 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3428 // reposition subbranch
3429 lmosel->reposition();
3430 //ensureSelectionVisible();
3432 if (lmo && (lmo!=selection) &&
3433 (typeid(*lmo) == typeid(BranchObj) ||
3434 (typeid(*lmo) == typeid(MapCenterObj) )
3437 if (e->state() & Qt::ControlModifier)
3439 // Special case: CTRL to link below lmo
3440 lmosel->setParObjTmp (lmo,p,+1);
3442 else if (e->state() & Qt::ShiftModifier)
3443 lmosel->setParObjTmp (lmo,p,-1);
3445 lmosel->setParObjTmp (lmo,p,0);
3448 lmosel->unsetParObjTmp();
3452 } // no FloatImageObj
3456 } // selection && moving_obj
3458 // Draw a link from one branch to another
3461 tmpXLink->setEnd (p);
3462 tmpXLink->updateXLink();
3466 if (!movingObj && !pickingColor &&!drawingLink)
3468 QPoint p=e->globalPos();
3469 movingVec.setX(-p.x() + movingObj_start.x() );
3470 movingVec.setY(-p.y() + movingObj_start.y() );
3471 setContentsPos( movingCont_start.x() + movingVec.x(),
3472 movingCont_start.y() + movingVec.y());
3479 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3481 LinkableMapObj *dst;
3482 // Have we been picking color?
3486 setCursor (Qt::ArrowCursor);
3487 // Check if we are over another branch
3488 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3489 if (dst && selection)
3491 if (e->state() & Qt::ShiftModifier)
3493 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3494 ((BranchObj*)selection)->setLinkColor ();
3498 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3499 ((BranchObj*)selection)->setLinkColor ();
3505 // Have we been drawing a link?
3509 // Check if we are over another branch
3510 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3511 if (dst && selection)
3513 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3514 tmpXLink->updateXLink();
3515 tmpXLink->activate();
3516 saveState(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3525 // Have we been moving something?
3526 if ( selection && movingObj )
3528 // Moved FloatObj? Maybe we need to reposition
3529 if(typeid(*selection)==typeid (FloatImageObj))
3531 selection->getParObj()->requestReposition();
3532 mapCenter->reposition();
3535 // Check if we are over another branch, but ignore
3536 // any found LMOs, which are FloatObjs
3537 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3538 ((LinkableMapObj*)selection) );
3540 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3543 // Now check, if we have been moving a branch
3544 if (typeid(*selection) == typeid(BranchObj) )
3546 // save the position in case we link to mapcenter
3547 QPoint savePos=QPoint (selection->x(),selection->y() );
3549 // Reset the temporary drawn link to the original one
3550 ((LinkableMapObj*)selection)->unsetParObjTmp();
3556 BranchObj* bs=((BranchObj*)selection);
3557 QString undoCom="linkBranchToPos (\""+
3558 (bs->getParObj())->getSelectString()+
3560 QString("%1").arg(bs->getNum())+
3562 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3564 // TODO we also could check, if dest and src are on same branch,
3565 // then it would be sufficient to saveState of this branch
3567 // Modifiers allow to insert above/below dst
3568 if (e->state() & Qt::ShiftModifier)
3570 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3572 if (e->state() & Qt::ControlModifier)
3574 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3577 bs->moveBranchTo ((BranchObj*)(dst),-1);
3578 if (dst->getDepth()==0)
3581 saveState (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) );
3583 if (selection->getDepth()==1)
3584 // If we have moved mainbranch only save endposition
3585 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos)));
3587 // Draw the original link, before selection was moved around
3588 mapCenter->reposition();
3590 // Finally resize canvas, if needed
3595 // maybe we moved View: set old cursor
3596 setCursor (Qt::ArrowCursor);
3600 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3602 // Finish open lineEdits
3603 if (lineedit) finishedLineEdit();
3605 if (e->button() == Qt::LeftButton )
3607 QPoint p = inverseWorldMatrix().map(e->pos());
3608 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3609 if (lmo) { // MapObj was found
3610 // First select the MapObj than edit heading
3611 if (selection) selection->unselect();
3613 selection->select();
3619 void MapEditor::resizeEvent (QResizeEvent* e)
3621 Q3CanvasView::resizeEvent( e );
3625 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3628 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3629 // cerr << event->format(i) << endl;
3632 (typeid(*selection) == typeid(BranchObj)) ||
3633 (typeid(*selection) == typeid(MapCenterObj))) {
3635 // If QImageDrag can decode mime type
3636 if (Q3ImageDrag::canDecode(event)) {
3641 // If image are dragged from firefox
3642 if (event->provides("application/x-moz-file-promise-url") &&
3643 event->provides("application/x-moz-nativeimage")) {
3644 event->accept(true);
3648 // If QUriDrag can decode mime type
3649 if (Q3UriDrag::canDecode(event)) {
3654 // If Uri are dragged from firefox
3655 if (event->provides("_NETSCAPE_URL")){
3660 // If QTextDrag can decode mime type
3661 if (Q3TextDrag::canDecode(event)) {
3670 bool isUnicode16(const QByteArray &d)
3672 // TODO: make more precise check for unicode 16.
3673 // Guess unicode16 if any of second bytes are zero
3674 unsigned int length = max(0,d.size()-2)/2;
3675 for (unsigned int i = 0; i<length ; i++)
3676 if (d.at(i*2+1)==0) return true;
3680 void MapEditor::contentsDropEvent(QDropEvent *event)
3683 (typeid(*selection) == typeid(BranchObj)) ||
3684 (typeid(*selection) == typeid(MapCenterObj)))
3689 if (event->provides("image/png"))
3692 if (Q3ImageDrag::decode(event, pix))
3700 } else if (event->provides("application/x-moz-file-promise-url") &&
3701 event->provides("application/x-moz-nativeimage"))
3703 // Contains url to the img src in unicode16
3704 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3705 QString url = QString((const QChar*)d.data(),d.size()/2);
3709 } else if (event->provides ("text/uri-list"))
3710 { // Uris provided e.g. by konqueror
3711 Q3UriDrag::decode (event,uris);
3712 } else if (event->provides ("_NETSCAPE_URL"))
3713 { // Uris provided by Mozilla
3714 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3717 } else if (event->provides("text/html")) {
3719 // Handels text mime types
3720 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3721 QByteArray d = event->encodedData("text/html");
3724 text = QString((const QChar*)d.data(),d.size()/2);
3728 textEditor->setText(text);
3732 } else if (event->provides("text/plain")) {
3733 QByteArray d = event->encodedData("text/plain");
3736 text = QString((const QChar*)d.data(),d.size()/2);
3740 textEditor->setText(text);
3752 for (const char* u=uris.first(); u; u=uris.next())
3754 bo=((BranchObj*)selection)->addBranch();
3757 s=Q3UriDrag::uriToLocalFile(u);
3760 QString file = QDir::convertSeparators(s);
3761 heading = QFileInfo(file).baseName();
3763 if (file.endsWith(".vym", false))
3764 bo->setVymLink(file);
3773 if (!heading.isEmpty())
3774 bo->setHeading(heading);
3784 //FIXME saveState has to be called earlier for each of the drops...
3785 saveState("Drop Event"); //TODO undo Command
3786 mapCenter->reposition();
3793 void MapEditor::addFloatImage(const QPixmap &img)
3796 (typeid(*selection) == typeid(BranchObj)) ||
3797 (typeid(*selection) == typeid(MapCenterObj)) )
3799 BranchObj *bo=((BranchObj*)selection);
3800 saveState(selection,QString("Add floatimage to %1").arg(getName(bo)));
3801 //QString fn=fd->selectedFile();
3802 //lastImageDir=fn.left(fn.findRev ("/"));
3803 bo->addFloatImage();
3804 // FIXME check if load was successful
3805 bo->getLastFloatImage()->load(img);
3806 //bo->getLastFloatImage()->setOriginalFilename(fn);
3807 mapCenter->reposition();
3814 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
3816 if (!imageBuffer) imageBuffer = new QBuffer();
3817 if (!imageBuffer->isOpen()) {
3818 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3820 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3824 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3826 if (nop->state()==Q3NetworkProtocol::StDone) {
3827 QPixmap img(imageBuffer->buffer());
3832 imageBuffer->close();
3834 imageBuffer->close();
3841 void MapEditor::fetchImage(const QString &url)
3844 urlOperator->stop();
3845 disconnect(urlOperator);
3849 urlOperator = new Q3UrlOperator(url);
3850 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
3851 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
3853 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
3854 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));