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(1000,800);
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("/vym/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( "/vym/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.readEntry("/vym/mainwindow/printerName",printer->printerName()));
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("/vym/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("/vym/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->grabKeyboard();
1511 lineedit->setFocus();
1515 void MapEditor::setHeading(const QString &s)
1517 // Internal function, no saveState needed
1519 (typeid(*selection) == typeid(BranchObj) ||
1520 typeid(*selection) == typeid(MapCenterObj) ) )
1522 ((BranchObj*)selection)->setHeading(s);
1523 mapCenter->reposition();
1525 ensureSelectionVisible();
1529 void MapEditor::setURL (const QString &s)
1531 // Internal function, no saveState needed
1533 (typeid(*selection) == typeid(BranchObj) ||
1534 typeid(*selection) == typeid(MapCenterObj) ) )
1536 ((BranchObj*)selection)->setURL(s);
1537 mapCenter->reposition();
1539 ensureSelectionVisible();
1543 void MapEditor::setVymLink (const QString &s)
1545 // Internal function, no saveState needed
1547 (typeid(*selection) == typeid(BranchObj) ||
1548 typeid(*selection) == typeid(MapCenterObj) ) )
1550 ((BranchObj*)selection)->setVymLink(s);
1551 mapCenter->reposition();
1553 ensureSelectionVisible();
1557 void MapEditor::addNewBranch(int pos)
1559 // Finish open lineEdits
1560 if (lineedit) finishedLineEdit();
1563 (typeid(*selection) == typeid(BranchObj) ||
1564 typeid(*selection) == typeid(MapCenterObj) ) )
1566 BranchObj* bo1 = (BranchObj*) selection;
1567 saveState(selection, QString("Add new branch to %1").arg(getName(bo1))); //TODO undoCommand
1569 bool wasScrolled=false;
1570 BranchObj *newbo=NULL;
1573 // save scroll state. If scrolled, automatically select
1574 // new branch in order to tmp unscroll parent...
1575 wasScrolled=bo1->isScrolled();
1576 newbo=bo1->addBranch();
1579 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1583 // add above selection
1584 newbo=parbo->insertBranch(bo1->getNum());
1586 // add below selection
1587 newbo=parbo->insertBranch(bo1->getNum()+1);
1589 // This should not happen...
1594 LinkableMapObj *oldselection=selection;
1596 mapCenter->reposition();
1598 if (actionSettingsAutoedit->isOn() ||
1599 actionSettingsAutoselectHeading->isOn() )
1601 selection->unselect();
1603 selection->select();
1604 if (actionSettingsPasteNewHeading->isOn() )
1606 BranchObj *bo2= (BranchObj*)selection;
1607 bo2->setHeading("");
1609 if (actionSettingsAutoedit->isOn() )
1611 if (!actionSettingsAutoselectHeading->isOn()
1614 selection->unselect();
1615 selection=oldselection;
1616 selection->select();
1623 void MapEditor::addNewBranchHere()
1625 // Finish open lineEdits
1626 if (lineedit) finishedLineEdit();
1629 (typeid(*selection) == typeid(BranchObj) ) )
1631 BranchObj* bo1 = (BranchObj*) selection;
1632 saveState(selection, QString("Add new branch here").arg(getName(bo1)));
1634 bool wasScrolled=false;
1635 BranchObj *newbo=NULL;
1636 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1639 // add below selection
1640 newbo=parbo->insertBranch(bo1->getNum()+1);
1643 LinkableMapObj *oldselection=selection;
1644 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1646 mapCenter->reposition();
1648 if (actionSettingsAutoedit->isOn() ||
1649 actionSettingsAutoselectHeading->isOn() )
1651 selection->unselect();
1653 selection->select();
1654 if (actionSettingsPasteNewHeading->isOn() )
1656 BranchObj *bo2= (BranchObj*)selection;
1657 bo2->setHeading("");
1659 if (actionSettingsAutoedit->isOn() )
1661 if (!actionSettingsAutoselectHeading->isOn()
1664 selection->unselect();
1665 selection=oldselection;
1666 selection->select();
1672 void MapEditor::deleteSelection()
1674 // Finish open lineEdits
1675 if (lineedit) finishedLineEdit();
1677 if (selection && typeid(*selection) ==typeid(BranchObj) )
1679 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1680 BranchObj* par=(BranchObj*)(bo->getParObj());
1682 if (selection->getDepth()>1)
1683 // Normal branch, save parent with childs
1684 saveState(par,QString("Delete %1").arg(getName(bo)));
1686 // Mainbranch, save whole map
1687 // TODO Better would be to insert mainbranch again at pos
1688 // But undoCommand is missing right now
1689 saveState(QString("Delete %1").arg(getName(bo)));
1691 par->removeBranch(bo);
1693 selection->select();
1694 ensureSelectionVisible();
1695 mapCenter->reposition();
1698 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1700 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1701 BranchObj* par=(BranchObj*)(fio->getParObj());
1702 saveState(par, QString("Delete %1").arg(getName(fio)));
1705 par->removeFloatImage(fio);
1707 selection->select();
1708 ensureSelectionVisible();
1709 mapCenter->reposition();
1714 LinkableMapObj* MapEditor::getSelection()
1719 void MapEditor::unselect()
1723 selectionLast=selection;
1724 selection->unselect();
1729 void MapEditor::reselect()
1733 selection=selectionLast;
1734 selection->select();
1739 bool MapEditor::select (const QString &s)
1741 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1743 // Finally select the found object
1746 if (selection) unselect();
1748 selection->select();
1750 ensureSelectionVisible();
1756 void MapEditor::select (LinkableMapObj *lmo)
1758 if (lmo && selection != lmo)
1760 // select the MapObj
1761 if (selection) selection->unselect();
1763 selection->select();
1770 void MapEditor::selectNextBranch()
1772 // Increase number of branch
1775 QString s=selection->getSelectString();
1781 part=s.section(",",-1);
1783 num=part.right(part.length() - 3);
1785 s=s.left (s.length() -num.length());
1788 num=QString ("%1").arg(num.toUInt()+1);
1792 // Try to select this one
1793 if (select (s)) return;
1795 // We have no direct successor,
1796 // try to increase the parental number in order to
1797 // find a successor with same depth
1799 int d=selection->getDepth();
1804 while (!found && d>0)
1806 s=s.section (",",0,d-1);
1807 // replace substring of current depth in s with "1"
1808 part=s.section(",",-1);
1810 num=part.right(part.length() - 3);
1814 // increase number of parent
1815 num=QString ("%1").arg(num.toUInt()+1);
1816 s=s.section (",",0,d-2) + ","+ typ+num;
1819 // Special case, look at orientation
1820 if (selection->getOrientation()==OrientRightOfCenter)
1821 num=QString ("%1").arg(num.toUInt()+1);
1823 num=QString ("%1").arg(num.toUInt()-1);
1828 // pad to oldDepth, select the first branch for each depth
1829 for (i=d;i<oldDepth;i++)
1834 if ( ((BranchObj*)selection)->countBranches()>0)
1842 // try to select the freshly built string
1850 void MapEditor::selectPrevBranch()
1852 // Decrease number of branch
1855 QString s=selection->getSelectString();
1861 part=s.section(",",-1);
1863 num=part.right(part.length() - 3);
1865 s=s.left (s.length() -num.length());
1868 num=QString ("%1").arg(num.toUInt()-1);
1872 // Try to select this one
1873 if (select (s)) return;
1875 // We have no direct precessor,
1876 // try to decrease the parental number in order to
1877 // find a precessor with same depth
1879 int d=selection->getDepth();
1884 while (!found && d>0)
1886 s=s.section (",",0,d-1);
1887 // replace substring of current depth in s with "1"
1888 part=s.section(",",-1);
1890 num=part.right(part.length() - 3);
1894 // decrease number of parent
1895 num=QString ("%1").arg(num.toUInt()-1);
1896 s=s.section (",",0,d-2) + ","+ typ+num;
1899 // Special case, look at orientation
1900 if (selection->getOrientation()==OrientRightOfCenter)
1901 num=QString ("%1").arg(num.toUInt()-1);
1903 num=QString ("%1").arg(num.toUInt()+1);
1908 // pad to oldDepth, select the last branch for each depth
1909 for (i=d;i<oldDepth;i++)
1913 if ( ((BranchObj*)selection)->countBranches()>0)
1914 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1921 // try to select the freshly built string
1929 void MapEditor::selectUpperBranch()
1931 // Finish open lineEdits
1932 if (lineedit) finishedLineEdit();
1936 if (typeid(*selection) == typeid(BranchObj))
1938 if (selection->getOrientation()==OrientRightOfCenter)
1941 if (selection->getDepth()==1)
1949 void MapEditor::selectLowerBranch()
1951 // Finish open lineEdits
1952 if (lineedit) finishedLineEdit();
1956 if (typeid(*selection) == typeid(BranchObj))
1958 if (selection->getOrientation()==OrientRightOfCenter)
1961 if (selection->getDepth()==1)
1970 void MapEditor::selectLeftBranch()
1972 // Finish open lineEdits
1973 if (lineedit) finishedLineEdit();
1979 if (typeid(*selection) == typeid(MapCenterObj))
1981 par= (BranchObj*) selection;
1982 bo=par->getLastSelectedBranch();
1985 // Workaround for reselecting on left and right side
1986 if (bo->getOrientation()==OrientRightOfCenter)
1988 bo=par->getLastBranch();
1994 selection->select();
1996 ensureSelectionVisible();
2001 par=(BranchObj*)(selection->getParObj());
2002 if (selection->getOrientation()==OrientRightOfCenter)
2004 if (typeid(*selection) == typeid(BranchObj) ||
2005 typeid(*selection) == typeid(FloatImageObj))
2007 selection->unselect();
2009 selection->select();
2011 ensureSelectionVisible();
2015 if (typeid(*selection) == typeid(BranchObj) )
2017 bo=((BranchObj*)selection)->getLastSelectedBranch();
2020 selection->unselect();
2022 selection->select();
2024 ensureSelectionVisible();
2032 void MapEditor::selectRightBranch()
2034 // Finish open lineEdits
2035 if (lineedit) finishedLineEdit();
2042 if (typeid(*selection) == typeid(MapCenterObj))
2044 par= (BranchObj*) selection;
2045 bo=par->getLastSelectedBranch();
2048 // Workaround for relecting on left and right side
2049 if (bo->getOrientation()==OrientLeftOfCenter)
2050 bo=par->getFirstBranch();
2055 selection->select();
2056 ensureSelectionVisible();
2061 par=(BranchObj*)(selection->getParObj());
2062 if (selection->getOrientation()==OrientLeftOfCenter)
2064 if (typeid(*selection) == typeid(BranchObj) ||
2065 typeid(*selection) == typeid(FloatImageObj))
2067 selection->unselect();
2069 selection->select();
2071 ensureSelectionVisible();
2075 if (typeid(*selection) == typeid(BranchObj) )
2077 bo=((BranchObj*)selection)->getLastSelectedBranch();
2080 selection->unselect();
2082 selection->select();
2084 ensureSelectionVisible();
2092 void MapEditor::selectFirstBranch()
2094 // Finish open lineEdits
2095 if (lineedit) finishedLineEdit();
2101 if (typeid(*selection) == typeid(BranchObj))
2103 bo1= (BranchObj*) selection;
2104 par=(BranchObj*)(bo1->getParObj());
2105 bo2=par->getFirstBranch();
2109 selection->select();
2110 ensureSelectionVisible();
2117 void MapEditor::selectLastBranch()
2119 // Finish open lineEdits
2120 if (lineedit) finishedLineEdit();
2126 if (typeid(*selection) == typeid(BranchObj))
2128 bo1= (BranchObj*) selection;
2129 par=(BranchObj*)(bo1->getParObj());
2130 bo2=par->getLastBranch();
2134 selection->select();
2135 ensureSelectionVisible();
2142 void MapEditor::setColor(QColor c)
2147 void MapEditor::selectBackgroundColor()
2149 // Finish open lineEdits
2150 if (lineedit) finishedLineEdit();
2152 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2153 if ( !col.isValid() ) return;
2154 setBackgroundColor( col );
2155 saveState(QString("Set background color of map to %1").arg(col.name()));
2158 void MapEditor::setBackgroundColor(QColor c)
2160 mapCanvas->setBackgroundColor (c);
2163 QColor MapEditor::pickColor()
2167 if (typeid(*selection) == typeid(BranchObj) ||
2168 typeid(*selection) == typeid(MapCenterObj))
2170 BranchObj *bo=(BranchObj*)selection;
2171 actColor=bo->getColor();
2177 void MapEditor::colorItem()
2181 if (typeid(*selection) == typeid(BranchObj) ||
2182 typeid(*selection) == typeid(MapCenterObj))
2184 BranchObj *bo=(BranchObj*)selection;
2185 saveState(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2186 bo->setColor(actColor); // color branch
2191 void MapEditor::colorBranch()
2195 if (typeid(*selection) == typeid(BranchObj) ||
2196 typeid(*selection) == typeid(MapCenterObj))
2198 BranchObj *bo=(BranchObj*)selection;
2199 saveState(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2200 bo->setColorChilds(actColor); // color links, color childs
2206 void MapEditor::toggleStandardFlag(QString f)
2210 if (typeid(*selection) == typeid(BranchObj) ||
2211 typeid(*selection) == typeid(MapCenterObj))
2213 BranchObj *bo=(BranchObj*)selection;
2215 if (bo->isSetStandardFlag(f))
2219 saveState(selection, QString("%1 standard flag \"%2\" of %3").arg(s).arg(f).arg(getName(bo)));// TODO undoCommand
2220 bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn());
2226 void MapEditor::setViewCenter()
2228 // transform to CanvasView Coord:
2229 QPoint p=worldMatrix().map(movingCenter);
2230 center ( p.x(), p.y());
2234 BranchObj* MapEditor::findText (QString s, bool cs)
2236 QTextDocument::FindFlags flags=0;
2237 if (cs) flags=QTextDocument::QTextDocument::FindCaseSensitively;
2240 { // Nothing found or new find process
2242 // nothing found, start again
2244 itFind=mapCenter->first();
2246 bool searching=true;
2247 bool foundNote=false;
2248 while (searching && !EOFind)
2252 // Searching in Note
2253 if (itFind->getNote().contains(s,cs))
2255 if (selection!=itFind)
2257 if (selection) ((BranchObj*)selection)->unselect();
2259 selection->select();
2261 ensureSelectionVisible();
2263 if (textEditor->findText(s,flags))
2269 // Searching in Heading
2270 if (searching && itFind->getHeading().contains (s,cs) )
2272 if (selection) ((BranchObj*)selection)->unselect();
2274 selection->select();
2276 ensureSelectionVisible();
2282 itFind=itFind->next();
2283 if (!itFind) EOFind=true;
2289 return (BranchObj*)selection;
2294 void MapEditor::findReset()
2295 { // Necessary if text to find changes during a find process
2300 void MapEditor::editURL()
2302 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2303 typeid(*selection) == typeid(MapCenterObj)) )
2306 BranchObj *bo=(BranchObj*)selection;
2307 QString text = QInputDialog::getText(
2308 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2309 bo->getURL(), &ok, this );
2312 // user entered something and pressed OK
2313 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2320 QString MapEditor::getURL()
2322 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2323 typeid(*selection) == typeid(MapCenterObj)) )
2324 return ((BranchObj*)selection)->getURL();
2329 void MapEditor::editHeading2URL()
2331 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2332 typeid(*selection) == typeid(MapCenterObj)) )
2334 BranchObj *bo=(BranchObj*)selection;
2335 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2336 bo->setURL (bo->getHeading());
2341 void MapEditor::editBugzilla2URL()
2343 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2344 typeid(*selection) == typeid(MapCenterObj)) )
2346 BranchObj *bo=(BranchObj*)selection;
2347 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2348 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo)));
2354 void MapEditor::editFATE2URL()
2356 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2357 typeid(*selection) == typeid(MapCenterObj)) )
2359 BranchObj *bo=(BranchObj*)selection;
2360 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2361 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2367 void MapEditor::editVymLink()
2369 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2370 typeid(*selection) == typeid(MapCenterObj)) )
2372 BranchObj *bo=(BranchObj*)selection;
2373 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map"));
2374 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2375 fd->setCaption(__VYM " - " +tr("Link to another map"));
2376 if (! bo->getVymLink().isEmpty() )
2377 fd->setSelection( bo->getVymLink() );
2381 if ( fd->exec() == QDialog::Accepted )
2383 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2384 bo->setVymLink (fd->selectedFile() );
2386 mapCenter->reposition();
2393 void MapEditor::deleteVymLink()
2395 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2396 typeid(*selection) == typeid(MapCenterObj)) )
2398 BranchObj *bo=(BranchObj*)selection;
2399 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2400 bo->setVymLink ("" );
2402 mapCenter->reposition();
2408 void MapEditor::toggleHideExport()
2410 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2411 typeid(*selection) == typeid(MapCenterObj)) ||
2412 (typeid(*selection)==typeid(FloatImageObj))
2415 OrnamentedObj *oo=(OrnamentedObj*)selection;
2417 if (oo->hideInExport())
2419 oo->setHideInExport(false);
2424 oo->setHideInExport(true);
2427 saveState(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2428 actionEditToggleHideExport->setOn (oo->hideInExport());
2430 mapCenter->reposition();
2436 QString MapEditor::getVymLink()
2438 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2439 typeid(*selection) == typeid(MapCenterObj)) )
2441 return ((BranchObj*)selection)->getVymLink();
2447 void MapEditor::removeBranchKeepChilds()
2449 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2451 BranchObj* bo=(BranchObj*)selection;
2452 BranchObj* par=(BranchObj*)(bo->getParObj());
2453 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2454 if (bo->getDepth()==1)
2457 saveState(selection->getParObj(),s); // TODO undoCommand
2458 QString sel=selection->getSelectString();
2460 par->removeBranchHere(bo);
2461 mapCenter->reposition();
2466 void MapEditor::removeChilds()
2468 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2470 saveState(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
2471 ((BranchObj*)selection)->removeChilds();
2472 mapCenter->reposition();
2476 void MapEditor::editMapInfo()
2478 ExtraInfoDialog dia;
2479 dia.setMapName (getFileName() );
2480 dia.setAuthor (mapCenter->getAuthor() );
2481 dia.setComment(mapCenter->getComment() );
2486 Q3CanvasItemList l=canvas()->allItems();
2487 for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2489 stats+=QString ("%1 items on canvas\n").arg (i,6);
2496 bo=mapCenter->first();
2499 if (!bo->getNote().isEmpty() ) n++;
2500 f+= bo->countFloatImages();
2502 xl+=bo->countXLinks();
2505 stats+=QString ("%1 branches\n").arg (b-1,6);
2506 stats+=QString ("%1 xLinks \n").arg (xl,6);
2507 stats+=QString ("%1 notes\n").arg (n,6);
2508 stats+=QString ("%1 images\n").arg (f,6);
2509 dia.setStats (stats);
2511 // Finally show dialog
2512 if (dia.exec() == QDialog::Accepted)
2514 saveState("Edit info about map"); //TODO undoCommand
2515 mapCenter->setAuthor (dia.getAuthor() );
2516 mapCenter->setComment (dia.getComment() );
2520 void MapEditor::updateActions()
2523 if (getLinkColorHint()==HeadingColor)
2524 actionFormatLinkColorHint->setOn(true);
2526 actionFormatLinkColorHint->setOn(false);
2531 actionFormatLinkStyleLine->setOn(true);
2534 actionFormatLinkStyleParabel->setOn(true);
2537 actionFormatLinkStylePolyLine->setOn(true);
2539 case StylePolyParabel:
2540 actionFormatLinkStylePolyParabel->setOn(true);
2546 QPixmap pix( 16, 16 );
2547 pix.fill( mapCanvas->backgroundColor() );
2548 actionFormatBackColor->setIconSet( pix );
2549 pix.fill( defLinkColor );
2550 actionFormatLinkColor->setIconSet( pix );
2552 actionEditUndo->setEnabled( mapChanged );
2553 actionFileSave->setEnabled( mapUnsaved );
2557 if ( (typeid(*selection) == typeid(BranchObj)) ||
2558 (typeid(*selection) == typeid(MapCenterObj)) )
2560 BranchObj *bo=(BranchObj*)selection;
2561 // Take care of links
2562 if (bo->countXLinks()==0)
2564 branchLinksContextMenuEdit->clear();
2565 branchLinksContextMenuFollow->clear();
2570 branchLinksContextMenuEdit->clear();
2571 branchLinksContextMenuFollow->clear();
2572 for (int i=0; i<=bo->countXLinks();i++)
2574 bot=bo->XLinkTargetAt(i);
2577 s=bot->getHeading();
2580 branchLinksContextMenuFollow->addAction (s);
2581 branchLinksContextMenuEdit->addAction (s);
2586 standardFlagsDefault->setEnabled (true);
2588 actionEditToggleScroll->setEnabled (true);
2589 if ( bo->isScrolled() )
2590 actionEditToggleScroll->setOn(true);
2592 actionEditToggleScroll->setOn(false);
2594 if ( bo->getURL().isEmpty() )
2596 actionEditOpenURL->setEnabled (false);
2597 actionEditOpenURLTab->setEnabled (false);
2601 actionEditOpenURL->setEnabled (true);
2602 actionEditOpenURLTab->setEnabled (true);
2604 if ( bo->getVymLink().isEmpty() )
2606 actionEditOpenVymLink->setEnabled (false);
2607 actionEditDeleteVymLink->setEnabled (false);
2610 actionEditOpenVymLink->setEnabled (true);
2611 actionEditDeleteVymLink->setEnabled (true);
2614 if (bo->canMoveBranchUp())
2615 actionEditMoveUp->setEnabled (true);
2617 actionEditMoveUp->setEnabled (false);
2618 if (bo->canMoveBranchDown())
2619 actionEditMoveDown->setEnabled (true);
2621 actionEditMoveDown->setEnabled (false);
2624 actionEditToggleHideExport->setEnabled (true);
2625 actionEditToggleHideExport->setOn (bo->hideInExport() );
2627 actionEditCopy->setEnabled (true);
2628 actionEditCut->setEnabled (true);
2629 if (!clipboardEmpty)
2630 actionEditPaste->setEnabled (true);
2632 actionEditPaste->setEnabled (false);
2633 for (a=actionListBranches.first();a;a=actionListBranches.next())
2634 a->setEnabled(true);
2635 actionEditDelete->setEnabled (true);
2636 switch (selection->getFrameType())
2639 actionFormatFrameNone->setOn(true);
2642 actionFormatFrameRectangle->setOn(true);
2647 actionFormatIncludeImagesVer->setOn
2648 ( ((BranchObj*)selection)->getIncludeImagesVer());
2649 actionFormatIncludeImagesHor->setOn
2650 ( ((BranchObj*)selection)->getIncludeImagesHor());
2651 actionFormatHideLinkUnselected->setOn
2652 (selection->getHideLinkUnselected());
2654 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2656 FloatObj *fo=(FloatImageObj*)selection;
2657 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2659 actionEditOpenURL->setEnabled (false);
2660 actionEditOpenVymLink->setEnabled (false);
2661 actionEditDeleteVymLink->setEnabled (false);
2662 actionEditToggleHideExport->setEnabled (true);
2663 actionEditToggleHideExport->setOn (fo->hideInExport() );
2666 actionEditCopy->setEnabled (true);
2667 actionEditCut->setEnabled (true);
2668 actionEditPaste->setEnabled (false);
2669 for (a=actionListBranches.first();a;a=actionListBranches.next())
2670 a->setEnabled(false);
2671 actionEditDelete->setEnabled (true);
2672 actionFormatHideLinkUnselected->setOn
2673 ( selection->getHideLinkUnselected());
2674 actionEditMoveUp->setEnabled (false);
2675 actionEditMoveDown->setEnabled (false);
2680 //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false);
2682 actionEditCopy->setEnabled (false);
2683 actionEditCut->setEnabled (false);
2684 actionEditPaste->setEnabled (false);
2685 for (a=actionListBranches.first();a;a=actionListBranches.next())
2686 a->setEnabled(false);
2688 actionEditToggleScroll->setEnabled (false);
2689 actionEditOpenURL->setEnabled (false);
2690 actionEditOpenVymLink->setEnabled (false);
2691 actionEditDeleteVymLink->setEnabled (false);
2692 actionEditHeading2URL->setEnabled (false);
2693 actionEditDelete->setEnabled (false);
2694 actionEditMoveUp->setEnabled (false);
2695 actionEditMoveDown->setEnabled (false);
2696 actionEditToggleHideExport->setEnabled (false);
2700 void MapEditor::updateNoteFlag()
2703 if ( (typeid(*selection) == typeid(BranchObj)) ||
2704 (typeid(*selection) == typeid(MapCenterObj)) )
2705 ((BranchObj*)selection)->updateNoteFlag();
2708 void MapEditor::setLinkStyle (LinkStyle ls)
2712 saveState("Set link style"); // TODO undoCommand
2714 bo=mapCenter->first();
2718 bo->setLinkStyle(bo->getDefLinkStyle());
2721 mapCenter->reposition();
2724 LinkStyle MapEditor::getLinkStyle ()
2729 void MapEditor::setLinkColor(QColor c)
2735 void MapEditor::setLinkColorHint()
2737 // called from setLinkColorHint(lch) or at end of parse
2739 bo=mapCenter->first();
2747 void MapEditor::setLinkColorHint(LinkColorHint lch)
2753 void MapEditor::toggleLinkColorHint()
2755 if (linkcolorhint==HeadingColor)
2756 linkcolorhint=DefaultColor;
2758 linkcolorhint=HeadingColor;
2760 bo=mapCenter->first();
2768 LinkColorHint MapEditor::getLinkColorHint()
2770 return linkcolorhint;
2773 QColor MapEditor::getDefLinkColor()
2775 return defLinkColor;
2778 void MapEditor::setDefXLinkColor(QColor col)
2783 QColor MapEditor::getDefXLinkColor()
2785 return defXLinkColor;
2788 void MapEditor::setDefXLinkWidth (int w)
2793 int MapEditor::getDefXLinkWidth()
2795 return defXLinkWidth;
2798 void MapEditor::selectLinkColor()
2800 // Finish open lineEdits
2801 if (lineedit) finishedLineEdit();
2803 QColor col = QColorDialog::getColor( defLinkColor, this );
2804 if ( !col.isValid() ) return;
2805 setLinkColor( col );
2806 saveState(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2810 void MapEditor::toggleScroll()
2812 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2814 BranchObj *bo=((BranchObj*)selection);
2815 if (bo->countBranches()==0) return;
2816 if (bo->getDepth()==0) return;
2818 if (bo->isScrolled())
2822 saveState(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2829 void MapEditor::unScrollAll()
2832 bo=mapCenter->first();
2835 if (bo->isScrolled()) bo->toggleScroll();
2840 void MapEditor::loadFloatImage ()
2843 (typeid(*selection) == typeid(BranchObj)) ||
2844 (typeid(*selection) == typeid(MapCenterObj)) )
2846 BranchObj *bo=((BranchObj*)selection);
2848 Q3FileDialog *fd=new Q3FileDialog( this);
2849 fd->setMode (Q3FileDialog::ExistingFiles);
2850 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2851 ImagePreview *p =new ImagePreview (fd);
2852 fd->setContentsPreviewEnabled( TRUE );
2853 fd->setContentsPreview( p, p );
2854 fd->setPreviewMode( Q3FileDialog::Contents );
2855 fd->setCaption(__VYM " - " +tr("Load image"));
2856 fd->setDir (lastImageDir);
2860 if ( fd->exec() == QDialog::Accepted )
2862 saveState(selection, QString("Add floatimage to %1").arg(getName(selection)));
2863 // FIXME in QT4 use: lastImageDir=fd->directory();
2864 lastImageDir=QDir (fd->dirPath());
2865 QStringList flist = fd->selectedFiles();
2866 QStringList::Iterator it = flist.begin();
2867 while( it != flist.end() )
2870 bo->addFloatImage();
2871 // TODO check if load was successful
2872 bo->getLastFloatImage()->load(*it);
2873 bo->getLastFloatImage()->setOriginalFilename(fn);
2877 mapCenter->reposition();
2886 void MapEditor::saveFloatImage (int item)
2889 (typeid(*selection) == typeid(FloatImageObj)) )
2891 FloatImageObj *fio=((FloatImageObj*)selection);
2892 const char* fmt = saveImageFormatMenu->text(item);
2894 Q3FileDialog *fd=new Q3FileDialog( this, tr("vym - save image as") + fmt);
2895 fd->addFilter ("PNG (*.png)");
2896 fd->addFilter ("BMP (*.bmp)");
2897 fd->addFilter ("XBM (*.xbm)");
2898 fd->addFilter ("JPG (*.jpg)");
2899 fd->addFilter ("XPM (*.xpm)");
2900 fd->addFilter ("GIF (*.gif)");
2901 fd->addFilter ("PNM (*.pnm)");
2902 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2903 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2904 fd->setMode( Q3FileDialog::AnyFile );
2905 fd->setSelection (fio->getOriginalFilename());
2909 if ( fd->exec() == QDialog::Accepted )
2911 if (QFile (fd->selectedFile()).exists() )
2913 QMessageBox mb( __VYM,
2914 tr("The file %1 exists already.\n"
2915 "Do you want to overwrite it?").arg(fd->selectedFile()),
2916 QMessageBox::Warning,
2917 QMessageBox::Yes | QMessageBox::Default,
2918 QMessageBox::Cancel | QMessageBox::Escape,
2919 QMessageBox::QMessageBox::NoButton );
2921 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2922 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2925 case QMessageBox::Yes:
2928 case QMessageBox::Cancel:
2934 fio->save (fd->selectedFile(),fmt);
2939 void MapEditor::setFrame(const FrameType &t)
2942 (typeid(*selection) == typeid(BranchObj)) ||
2943 (typeid(*selection) == typeid(MapCenterObj)) )
2945 selection->setFrameType (t);
2946 mapCenter->reposition();
2947 selection->updateLink();
2951 void MapEditor::setIncludeImagesVer(bool b)
2954 (typeid(*selection) == typeid(BranchObj)) ||
2955 (typeid(*selection) == typeid(MapCenterObj)) )
2956 ((BranchObj*)selection)->setIncludeImagesVer(b);
2957 mapCenter->reposition();
2960 void MapEditor::setIncludeImagesHor(bool b)
2963 (typeid(*selection) == typeid(BranchObj)) ||
2964 (typeid(*selection) == typeid(MapCenterObj)) )
2965 ((BranchObj*)selection)->setIncludeImagesHor(b);
2966 mapCenter->reposition();
2969 void MapEditor::setHideLinkUnselected (bool b)
2972 (typeid(*selection) == typeid(BranchObj)) ||
2973 (typeid(*selection) == typeid(MapCenterObj)) ||
2974 (typeid(*selection) == typeid(FloatImageObj)) )
2975 selection->setHideLinkUnselected(b);
2978 void MapEditor::importDir(BranchObj *dst, QDir d)
2981 (typeid(*selection) == typeid(BranchObj)) ||
2982 (typeid(*selection) == typeid(MapCenterObj)) )
2986 // Traverse directories
2987 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2988 QFileInfoList list = d.entryInfoList();
2991 for (int i = 0; i < list.size(); ++i)
2994 if (fi.fileName() != "." && fi.fileName() != ".." )
2997 bo=dst->getLastBranch();
2998 bo->setHeading (fi.fileName() );
2999 bo->setColor (QColor("blue"));
3001 if ( !d.cd(fi.fileName()) )
3002 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
3005 // Recursively add subdirs
3012 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
3013 list = d.entryInfoList();
3015 for (int i = 0; i < list.size(); ++i)
3019 bo=dst->getLastBranch();
3020 bo->setHeading (fi.fileName() );
3021 bo->setColor (QColor("black"));
3022 if (fi.fileName().right(4) == ".vym" )
3023 bo->setVymLink (fi.filePath());
3028 void MapEditor::importDir()
3031 (typeid(*selection) == typeid(BranchObj)) ||
3032 (typeid(*selection) == typeid(MapCenterObj)) )
3034 Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
3035 fd->setMode (Q3FileDialog::DirectoryOnly);
3036 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3037 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
3041 if ( fd->exec() == QDialog::Accepted )
3043 BranchObj *bo=((BranchObj*)selection);
3044 importDir (bo,QDir(fd->selectedFile()) );
3045 mapCenter->reposition();
3052 void MapEditor::followXLink(int i)
3055 (typeid(*selection) == typeid(BranchObj)) ||
3056 (typeid(*selection) == typeid(MapCenterObj)) )
3058 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3061 selection->unselect();
3063 selection->select();
3064 ensureSelectionVisible();
3069 void MapEditor::editXLink(int i)
3073 (typeid(*selection) == typeid(BranchObj)) ||
3074 (typeid(*selection) == typeid(MapCenterObj)) )
3076 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3079 EditXLinkDialog dia;
3081 dia.setSelection(selection);
3082 if (dia.exec() == QDialog::Accepted)
3084 if (dia.useSettingsGlobal() )
3086 setDefXLinkColor (xlo->getColor() );
3087 setDefXLinkWidth (xlo->getWidth() );
3089 if (dia.deleteXLink())
3090 ((BranchObj*)selection)->deleteXLinkAt(i);
3091 saveState("Edit xLink"); //TODO undoCommand
3097 void MapEditor::testFunction()
3099 cout << "MapEditor::testFunction() called\n";
3101 mapCenter->positionBBox();
3105 dia.setCancelButton (true);
3106 dia.setText("This is a longer \nWarning");
3107 dia.setCaption("Warning: Flux problem");
3108 dia.setShowAgainName("/vym/warnings/mapeditor");
3109 if (dia.exec()==QDialog::Accepted)
3110 cout << "accepted!\n";
3112 cout << "canceled!\n";
3115 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
3117 QProcess *proc= new QProcess (this);
3119 if (!proc->waitForStarted());
3121 QMessageBox::warning(0,
3123 tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
3127 /* Hide hidden stuff temporary, maybe add this as regular function somewhere
3128 if (hidemode==HideNone)
3130 setHideTmpMode (HideExport);
3131 mapCenter->calcBBoxSizeWithChilds();
3132 QRect totalBBox=mapCenter->getTotalBBox();
3133 QRect mapRect=totalBBox;
3134 QCanvasRectangle *frame=NULL;
3136 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3138 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3139 totalBBox.width(), totalBBox.height());
3140 frame=new QCanvasRectangle (mapRect,mapCanvas);
3141 frame->setBrush (QColor(white));
3142 frame->setPen (QColor(black));
3148 setHideTmpMode (HideNone);
3150 cout <<" hidemode="<<hidemode<<endl;
3154 void MapEditor::ensureSelectionVisible()
3158 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3160 if (selection->getOrientation() == OrientLeftOfCenter)
3161 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3163 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3164 ensureVisible (p.x(), p.y() );
3169 void MapEditor::updateViewCenter()
3171 // Update movingCenter, so that we can zoom comfortably later
3172 QRect rc = QRect( contentsX(), contentsY(),
3173 visibleWidth(), visibleHeight() );
3174 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3175 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3176 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3179 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3181 // Lineedits are already closed by preceding
3182 // mouseEvent, we don't need to close here.
3184 QPoint p = inverseWorldMatrix().map(e->pos());
3185 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3188 { // MapObj was found
3189 if (selection != lmo)
3191 // select the MapObj
3192 if (selection) selection->unselect();
3194 selection->select();
3200 if (typeid(*selection)==typeid(BranchObj) ||
3201 typeid(*selection)==typeid(MapCenterObj) )
3203 // Context Menu on branch or mapcenter
3205 branchContextMenu->popup(e->globalPos() );
3207 if (typeid(*selection)==typeid(FloatImageObj))
3209 // Context Menu on floatimage
3211 floatimageContextMenu->popup(e->globalPos() );
3215 { // No MapObj found, we are on the Canvas itself
3216 // Context Menu on Canvas
3218 canvasContextMenu->popup(e->globalPos() );
3223 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3225 // Ignore right clicks, these will go to context menus
3226 if (e->button() == Qt::RightButton )
3232 // Finish open lineEdits
3233 if (lineedit) finishedLineEdit();
3235 QPoint p = inverseWorldMatrix().map(e->pos());
3236 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3240 //Take care of clickdesystem flags _or_ modifier modes
3242 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3243 typeid(*lmo)==typeid(MapCenterObj) ))
3245 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3246 if (!foname.isEmpty())
3248 // systemFlag clicked
3252 if (e->state() & Qt::ControlModifier)
3253 mainWindow->editOpenURLTab();
3255 mainWindow->editOpenURL();
3257 else if (foname=="vymLink")
3259 mainWindow->editOpenVymLink();
3260 // tabWidget may change, better return now
3261 // before segfaulting...
3262 } else if (foname=="note")
3263 mainWindow->windowToggleNoteEditor();
3264 else if (foname=="hideInExport")
3269 // No system flag clicked, take care of modmodes
3271 // Special case: CTRL is pressed
3272 if (e->state() & Qt::ControlModifier)
3274 if (actionModModeColor->isOn())
3277 setCursor (pickColorCursor);
3280 if (actionModModeLink->isOn())
3282 BranchObj *bo_begin=NULL;
3284 bo_begin=(BranchObj*)(lmo);
3287 ((typeid(*selection) == typeid(BranchObj)) ||
3288 (typeid(*selection) == typeid(MapCenterObj))) )
3289 bo_begin=(BranchObj*)selection;
3293 linkingObj_src=bo_begin;
3294 tmpXLink=new XLinkObj (mapCanvas);
3295 tmpXLink->setBegin (bo_begin);
3296 tmpXLink->setEnd (p);
3297 tmpXLink->setColor(defXLinkColor);
3298 tmpXLink->setWidth(defXLinkWidth);
3299 tmpXLink->updateXLink();
3300 tmpXLink->setVisibility (true);
3308 // Left Button Move Branches
3309 if (e->button() == Qt::LeftButton )
3311 movingObj_start.setX( p.x() - selection->x() );
3312 movingObj_start.setY( p.y() - selection->y() );
3313 movingObj_orgPos.setX (lmo->x() );
3314 movingObj_orgPos.setY (lmo->y() );
3316 // If modMode==copy, then we want to "move" the _new_ object around
3317 // then we need the offset from p to the _old_ selection, because of tmp
3318 if (actionModModeCopy->isOn() &&
3319 e->state() & Qt::ControlModifier)
3321 if (typeid(*selection)==typeid(BranchObj) )
3324 mapCenter->addBranch ((BranchObj*)selection);
3326 selection=mapCenter->getLastBranch();
3327 selection->select();
3328 mapCenter->reposition();
3331 movingObj=selection;
3333 // Middle Button Toggle Scroll
3334 // (On Mac OS X this won't work, but we still have
3335 // a button in the toolbar)
3336 if (e->button() == Qt::MidButton )
3340 { // No MapObj found, we are on the Canvas itself
3341 // Left Button move Pos of CanvasView
3342 if (e->button() == Qt::LeftButton )
3344 movingObj=NULL; // move Content not Obj
3345 movingObj_start=e->globalPos();
3346 movingCont_start=QPoint (contentsX(), contentsY() );
3347 movingVec=QPoint(0,0);
3348 setCursor(handOpenCursor);
3353 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3355 QPoint p = inverseWorldMatrix().map(e->pos());
3357 // Move the selected MapObj
3358 if ( selection && movingObj)
3360 // To avoid jumping of the CanvasView, only
3361 // ensureSelectionVisible, if not tmp linked
3362 if (!selection->hasParObjTmp())
3363 ensureSelectionVisible ();
3365 // Now move the selection, but add relative position
3366 // (movingObj_start) where selection was chosen with
3367 // mousepointer. (This avoids flickering resp. jumping
3368 // of selection back to absPos)
3370 LinkableMapObj *lmosel;
3371 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3373 // Check if we could link
3374 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3377 if (typeid(*selection) == typeid(FloatImageObj))
3379 FloatObj *fo=(FloatObj*)selection;
3381 "move "+qpointToString(movingObj_orgPos),fo->getSelectString() ,
3382 QString("Move %1").arg(getName(selection)));
3383 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3387 // Relink float to new mapcenter or branch, if shift is pressed
3388 // Only relink, if selection really has a new parent
3389 if ( (e->state() & Qt::ShiftModifier) && lmo &&
3390 ( (typeid(*lmo)==typeid(BranchObj)) ||
3391 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3392 ( lmo != fo->getParObj())
3395 if (typeid(*fo) == typeid(FloatImageObj))
3397 saveState(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3398 FloatImageObj *fio=(FloatImageObj*)(fo);
3399 ((BranchObj*)(lmo))->addFloatImage (fio);
3401 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3402 fio=((BranchObj*)(lmo))->getLastFloatImage();
3405 selection=(LinkableMapObj*)(fio);
3406 selection->select();
3407 movingObj=(MapObj*)(fio);
3410 } else // selection != a FloatObj
3412 if (lmosel->getDepth()==0)
3414 if (e->state() == Qt::LeftButton && e->modifiers()==Qt::ShiftModifier)
3415 // If mapCenter is moved, move all the rest by default, too.
3416 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3418 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3421 if (lmosel->getDepth()==1)
3423 // depth==1, mainbranch
3424 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3428 if (lmosel->getOrientation() == OrientLeftOfCenter)
3429 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3430 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3431 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3433 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3435 // reposition subbranch
3436 lmosel->reposition();
3437 //ensureSelectionVisible();
3439 if (lmo && (lmo!=selection) &&
3440 (typeid(*lmo) == typeid(BranchObj) ||
3441 (typeid(*lmo) == typeid(MapCenterObj) )
3444 if (e->state() & Qt::ControlModifier)
3446 // Special case: CTRL to link below lmo
3447 lmosel->setParObjTmp (lmo,p,+1);
3449 else if (e->state() & Qt::ShiftModifier)
3450 lmosel->setParObjTmp (lmo,p,-1);
3452 lmosel->setParObjTmp (lmo,p,0);
3455 lmosel->unsetParObjTmp();
3459 } // no FloatImageObj
3463 } // selection && moving_obj
3465 // Draw a link from one branch to another
3468 tmpXLink->setEnd (p);
3469 tmpXLink->updateXLink();
3473 if (!movingObj && !pickingColor &&!drawingLink)
3475 QPoint p=e->globalPos();
3476 movingVec.setX(-p.x() + movingObj_start.x() );
3477 movingVec.setY(-p.y() + movingObj_start.y() );
3478 setContentsPos( movingCont_start.x() + movingVec.x(),
3479 movingCont_start.y() + movingVec.y());
3486 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3488 LinkableMapObj *dst;
3489 // Have we been picking color?
3493 setCursor (Qt::ArrowCursor);
3494 // Check if we are over another branch
3495 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3496 if (dst && selection)
3498 if (e->state() & Qt::ShiftModifier)
3500 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3501 ((BranchObj*)selection)->setLinkColor ();
3505 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3506 ((BranchObj*)selection)->setLinkColor ();
3512 // Have we been drawing a link?
3516 // Check if we are over another branch
3517 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3518 if (dst && selection)
3520 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3521 tmpXLink->updateXLink();
3522 tmpXLink->activate();
3523 saveState(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3532 // Have we been moving something?
3533 if ( selection && movingObj )
3535 // Moved FloatObj? Maybe we need to reposition
3536 if(typeid(*selection)==typeid (FloatImageObj))
3538 selection->getParObj()->requestReposition();
3539 mapCenter->reposition();
3542 // Check if we are over another branch, but ignore
3543 // any found LMOs, which are FloatObjs
3544 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3545 ((LinkableMapObj*)selection) );
3547 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3550 // Now check, if we have been moving a branch
3551 if (typeid(*selection) == typeid(BranchObj) )
3553 // save the position in case we link to mapcenter
3554 QPoint savePos=QPoint (selection->x(),selection->y() );
3556 // Reset the temporary drawn link to the original one
3557 ((LinkableMapObj*)selection)->unsetParObjTmp();
3563 BranchObj* bs=((BranchObj*)selection);
3564 QString undoCom="linkBranchToPos (\""+
3565 (bs->getParObj())->getSelectString()+
3567 QString("%1").arg(bs->getNum())+
3569 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3571 // TODO we also could check, if dest and src are on same branch,
3572 // then it would be sufficient to saveState of this branch
3574 // Modifiers allow to insert above/below dst
3575 if (e->state() & Qt::ShiftModifier)
3577 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3579 if (e->state() & Qt::ControlModifier)
3581 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3584 bs->moveBranchTo ((BranchObj*)(dst),-1);
3585 if (dst->getDepth()==0)
3588 saveState (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) );
3590 if (selection->getDepth()==1)
3591 // If we have moved mainbranch only save endposition
3592 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos)));
3594 // Draw the original link, before selection was moved around
3595 mapCenter->reposition();
3597 // Finally resize canvas, if needed
3602 // maybe we moved View: set old cursor
3603 setCursor (Qt::ArrowCursor);
3607 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3609 // Finish open lineEdits
3610 if (lineedit) finishedLineEdit();
3612 if (e->button() == Qt::LeftButton )
3614 QPoint p = inverseWorldMatrix().map(e->pos());
3615 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3616 if (lmo) { // MapObj was found
3617 // First select the MapObj than edit heading
3618 if (selection) selection->unselect();
3620 selection->select();
3626 void MapEditor::resizeEvent (QResizeEvent* e)
3628 Q3CanvasView::resizeEvent( e );
3632 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3635 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3636 // cerr << event->format(i) << endl;
3639 (typeid(*selection) == typeid(BranchObj)) ||
3640 (typeid(*selection) == typeid(MapCenterObj))) {
3642 // If QImageDrag can decode mime type
3643 if (Q3ImageDrag::canDecode(event)) {
3648 // If image are dragged from firefox
3649 if (event->provides("application/x-moz-file-promise-url") &&
3650 event->provides("application/x-moz-nativeimage")) {
3651 event->accept(true);
3655 // If QUriDrag can decode mime type
3656 if (Q3UriDrag::canDecode(event)) {
3661 // If Uri are dragged from firefox
3662 if (event->provides("_NETSCAPE_URL")){
3667 // If QTextDrag can decode mime type
3668 if (Q3TextDrag::canDecode(event)) {
3677 bool isUnicode16(const QByteArray &d)
3679 // TODO: make more precise check for unicode 16.
3680 // Guess unicode16 if any of second bytes are zero
3681 unsigned int length = max(0,d.size()-2)/2;
3682 for (unsigned int i = 0; i<length ; i++)
3683 if (d.at(i*2+1)==0) return true;
3687 void MapEditor::contentsDropEvent(QDropEvent *event)
3690 (typeid(*selection) == typeid(BranchObj)) ||
3691 (typeid(*selection) == typeid(MapCenterObj)))
3696 if (event->provides("image/png"))
3699 if (Q3ImageDrag::decode(event, pix))
3707 } else if (event->provides("application/x-moz-file-promise-url") &&
3708 event->provides("application/x-moz-nativeimage"))
3710 // Contains url to the img src in unicode16
3711 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3712 QString url = QString((const QChar*)d.data(),d.size()/2);
3716 } else if (event->provides ("text/uri-list"))
3717 { // Uris provided e.g. by konqueror
3718 Q3UriDrag::decode (event,uris);
3719 } else if (event->provides ("_NETSCAPE_URL"))
3720 { // Uris provided by Mozilla
3721 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3724 } else if (event->provides("text/html")) {
3726 // Handels text mime types
3727 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3728 QByteArray d = event->encodedData("text/html");
3731 text = QString((const QChar*)d.data(),d.size()/2);
3735 textEditor->setText(text);
3739 } else if (event->provides("text/plain")) {
3740 QByteArray d = event->encodedData("text/plain");
3743 text = QString((const QChar*)d.data(),d.size()/2);
3747 textEditor->setText(text);
3759 for (const char* u=uris.first(); u; u=uris.next())
3761 bo=((BranchObj*)selection)->addBranch();
3764 s=Q3UriDrag::uriToLocalFile(u);
3767 QString file = QDir::convertSeparators(s);
3768 heading = QFileInfo(file).baseName();
3770 if (file.endsWith(".vym", false))
3771 bo->setVymLink(file);
3780 if (!heading.isEmpty())
3781 bo->setHeading(heading);
3791 //FIXME saveState has to be called earlier for each of the drops...
3792 saveState("Drop Event"); //TODO undo Command
3793 mapCenter->reposition();
3800 void MapEditor::addFloatImage(const QPixmap &img)
3803 (typeid(*selection) == typeid(BranchObj)) ||
3804 (typeid(*selection) == typeid(MapCenterObj)) )
3806 BranchObj *bo=((BranchObj*)selection);
3807 saveState(selection,QString("Add floatimage to %1").arg(getName(bo)));
3808 //QString fn=fd->selectedFile();
3809 //lastImageDir=fn.left(fn.findRev ("/"));
3810 bo->addFloatImage();
3811 // FIXME check if load was successful
3812 bo->getLastFloatImage()->load(img);
3813 //bo->getLastFloatImage()->setOriginalFilename(fn);
3814 mapCenter->reposition();
3821 void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/)
3823 if (!imageBuffer) imageBuffer = new QBuffer();
3824 if (!imageBuffer->isOpen()) {
3825 imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append);
3827 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3831 void MapEditor::imageDataFinished(Q3NetworkOperation *nop)
3833 if (nop->state()==Q3NetworkProtocol::StDone) {
3834 QPixmap img(imageBuffer->buffer());
3839 imageBuffer->close();
3841 imageBuffer->close();
3848 void MapEditor::fetchImage(const QString &url)
3851 urlOperator->stop();
3852 disconnect(urlOperator);
3856 urlOperator = new Q3UrlOperator(url);
3857 connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)),
3858 this, SLOT(imageDataFinished(Q3NetworkOperation*)));
3860 connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)),
3861 this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));