3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <qpopupmenu.h>
9 #include <qpaintdevicemetrics.h>
11 #include <qfiledialog.h>
14 #include <qcolordialog.h>
17 #include <qinputdialog.h>
18 #include <qdragobject.h>
19 #include <qurloperator.h>
20 #include <qnetworkprotocol.h>
30 #include "editxlinkdialog.h"
32 #include "extrainfodialog.h"
34 #include "linkablemapobj.h"
35 #include "mainwindow.h"
38 #include "texteditor.h"
39 #include "warningdialog.h"
43 extern TextEditor *textEditor;
44 extern int statusbarTime;
45 extern Main *mainWindow;
46 extern QString tmpVymDir;
47 extern QString clipboardDir;
48 extern bool clipboardEmpty;
49 extern FlagRowObj *systemFlagsDefault;
50 extern FlagRowObj *standardFlagsDefault;
52 extern QPtrList <QAction> actionListBranches;
54 extern QAction *actionFileSave;
55 extern QAction *actionEditUndo;
56 extern QAction *actionEditCopy;
57 extern QAction *actionEditCut;
58 extern QAction *actionEditPaste;
59 extern QAction *actionEditMoveUp;
60 extern QAction *actionEditMoveDown;
61 extern QAction *actionEditToggleScroll;
62 extern QAction *actionEditOpenURL;
63 extern QAction *actionEditOpenURLTab;
64 extern QAction *actionEditURL;
65 extern QAction *actionEditHeading2URL;
66 extern QAction *actionEditBugzilla2URL;
67 extern QAction *actionEditFATE2URL;
68 extern QAction *actionEditOpenVymLink;
69 extern QAction *actionEditVymLink;
70 extern QAction *actionEditDeleteVymLink;
71 extern QAction *actionEditToggleHideExport;
72 extern QAction *actionEditHeading;
73 extern QAction *actionEditDelete;
74 extern QAction *actionEditAddBranch;
75 extern QAction *actionEditAddBranchAbove;
76 extern QAction *actionEditAddBranchBelow;
77 extern QAction *actionEditRemoveBranchHere;
78 extern QAction *actionEditRemoveChilds;
79 extern QAction *actionEditImportAdd;
80 extern QAction *actionEditImportReplace;
81 extern QAction *actionEditSaveBranch;
82 extern QAction *actionEditSelectFirst;
83 extern QAction *actionEditSelectLast;
84 extern QAction *actionEditLoadImage;
86 extern QAction* actionFormatPickColor;
87 extern QAction* actionFormatColorBranch;
88 extern QAction* actionFormatColorSubtree;
89 extern QAction *actionFormatLinkColorHint;
90 extern QAction *actionFormatBackColor;
91 extern QAction *actionFormatLinkColor;
93 extern QActionGroup* actionGroupModModes;
94 extern QAction* actionModModeColor;
95 extern QAction* actionModModeLink;
96 extern QAction* actionModModeCopy;
98 extern QActionGroup *actionGroupFormatFrameTypes;
99 extern QAction *actionFormatFrameNone;
100 extern QAction *actionFormatFrameRectangle;
102 extern QActionGroup *actionGroupFormatLinkStyles;
103 extern QAction *actionFormatIncludeImagesVer;
104 extern QAction *actionFormatIncludeImagesHor;
105 extern QAction *actionFormatHideLinkUnselected;
106 extern QAction *actionFormatLinkStyleLine;
107 extern QAction *actionFormatLinkStyleParabel;
108 extern QAction *actionFormatLinkStylePolyLine;
109 extern QAction *actionFormatLinkStylePolyParabel;
111 extern QAction *actionViewToggleNoteEditor;
113 extern QAction *actionSettingsAutoedit;
114 extern QAction *actionSettingsAutoselectHeading;
115 extern QAction *actionSettingsAutoselectText;
116 extern QAction *actionSettingsPasteNewHeading;
117 extern QAction *actionSettingsUseFlagGroups;
119 extern QPopupMenu *branchContextMenu;
120 extern QPopupMenu *branchLinksContextMenu;
121 extern QPopupMenu *branchLinksContextMenuDup;
122 extern QPopupMenu *floatimageContextMenu;
123 extern QPopupMenu *saveImageFormatMenu;
124 extern QPopupMenu *exportImageFormatMenu;
125 extern QPopupMenu *canvasContextMenu;
127 extern Settings settings;
129 extern QString iconPath;
130 extern QDir vymBaseDir;
132 int MapEditor::mapNum=0; // make instance
134 ///////////////////////////////////////////////////////////////////////
135 ///////////////////////////////////////////////////////////////////////
136 MapEditor::MapEditor(
137 QWidget* parent, bool interactive, const char* name, WFlags f) :
138 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
140 //cout << "Constructor ME "<<this<<endl;
143 viewport()->setAcceptDrops(true);
145 mapCanvas = new QCanvas(1000,800);
146 mapCanvas->setAdvancePeriod(30);
147 mapCanvas->setBackgroundColor (white);
149 setCanvas (mapCanvas);
151 // Always show scroll bars (automatic would flicker sometimes)
152 setVScrollBarMode ( QScrollView::AlwaysOn );
153 setHScrollBarMode ( QScrollView::AlwaysOn );
155 mapCenter = new MapCenterObj(mapCanvas);
156 mapCenter->setVisibility (true);
157 mapCenter->setMapEditor (this);
158 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
159 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
163 lineedit = new QLineEdit(this, "lineedit" );
164 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEdit() ) );
167 actColor=black; setColor (actColor);
168 defLinkColor=QColor (0,0,255);
169 defXLinkColor=QColor (180,180,180);
170 linkcolorhint=DefaultColor;
171 linkstyle=StylePolyParabel;
173 // Create bitmap cursors, patform dependant
174 #if defined(Q_OS_MACX)
175 handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png") );
176 // set hot spot to tip of picker
177 pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 );
179 handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen16.png"));
180 // set hot spot to tip of picker
181 pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
194 defXLinkColor=QColor (230,230,230);
202 fileName=tr("unnamed");
205 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
209 // Initialize find routine
216 blockReposition=false;
217 blockSaveState=false;
221 isInteractive=interactive;
223 // Create temporary files
226 // Initially set movingCentre
229 // For testing purposes create history window
230 historyWindow = new ShowTextDialog (this);
231 historyWindow->setCaption (fileName);
233 mapCenter->reposition(); // for positioning heading
236 MapEditor::~MapEditor()
238 if (imageBuffer) delete imageBuffer;
244 //cout <<"Destructor MapEditor\n";
247 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
251 QColor MapEditor::color()
256 QColor MapEditor::backgroundColor()
258 return mapCanvas->backgroundColor();
261 MapCenterObj* MapEditor::getMapCenter()
266 QCanvas* MapEditor::getCanvas()
271 void MapEditor::adjustCanvasSize()
273 // To adjust the canvas to map, viewport size and position, we have to
274 // do some coordinate magic...
276 // Get rectangle of (scroll-)view.
277 // We want to be in canvas coords, so
278 // we map. Important if view is zoomed...
279 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
280 visibleWidth(), visibleHeight()) );
282 // Now we need the bounding box of view AND map to calc the correct canvas size.
283 // Why? Because if the map itself is moved out of view, the view has to be enlarged
284 // to avoid jumping aroung...
285 QRect map=mapCenter->getTotalBBox();
287 // right edge - left edge
288 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
289 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
292 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
293 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
296 // move the map on canvas (in order to not move it on screen) this is neccessary
297 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
298 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
299 // to scroll to an empty area of canvas to the left.
300 // b) if topleft corner of map left of or above topleft of canvas
304 if (cw > mapCanvas->width() )
306 if (map.x()<0) dx=-map.x();
308 if (cw < mapCanvas->width() )
309 dx=-min (view.x(),map.x());
310 if (ch > mapCanvas->height() )
312 if (map.y()<0) dy=-map.y();
314 if (ch < mapCanvas->height() )
316 dy=-min (view.y(),map.y());
318 // We really have to resize now. Let's go...
319 mapCanvas->resize (cw,ch);
320 if ( (dx!=0) || (dy!=0) )
322 mapCenter->moveAllBy(dx,dy);
323 mapCenter->reposition();
324 // mapCenter->positionBBox(); // To move float
326 // scroll the view (in order to not move map on screen)
332 bool MapEditor::isRepositionBlocked()
334 return blockReposition;
337 QString MapEditor::getName (LinkableMapObj *lmo)
340 if (!lmo) return QString("Error: NULL has no name!");
342 if ((typeid(*lmo) == typeid(BranchObj) ||
343 typeid(*lmo) == typeid(MapCenterObj)))
346 s=(((BranchObj*)lmo)->getHeading());
347 if (s=="") s="unnamed";
348 return QString("branch (<font color=\"#0000ff\">%1</font>)").arg(s);
350 if ((typeid(*lmo) == typeid(FloatImageObj) ))
351 return QString ("floatimage [<font color=\"#0000ff\">%1</font>]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
352 return QString("Unknown type has no name!");
355 void MapEditor::makeTmpDirs()
357 // Create unique temporary directories
358 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
360 d.mkdir (tmpMapDir,true);
363 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
365 // tmpdir temporary directory to which data will be written
366 // prefix mapname, which will be appended to images etc.
367 // writeflags Only write flags for "real" save of map, not undo
368 // offset offset of bbox of whole map in canvas.
369 // Needed for XML export
385 ls="StylePolyParabel";
389 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
391 if (linkcolorhint==HeadingColor)
392 colhint=attribut("linkColorHint","HeadingColor");
394 QString mapAttr=attribut("version",__VYM_VERSION);
396 mapAttr+= attribut("author",mapCenter->getAuthor()) +
397 attribut("comment",mapCenter->getComment()) +
398 attribut("date",mapCenter->getDate()) +
399 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
400 attribut("linkStyle", ls ) +
401 attribut("linkColor", defLinkColor.name() ) +
402 attribut("defXLinkColor", defXLinkColor.name() ) +
403 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
405 s+=beginElement("vymmap",mapAttr);
408 // Find the used flags while traversing the tree
409 standardFlagsDefault->resetUsedCounter();
411 // Reset the counters before saving
412 FloatImageObj (mapCanvas).resetSaveCounter();
414 // Build xml recursivly
416 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
419 if ( typeid(*saveSelection) == typeid(BranchObj) )
420 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
421 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
422 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
424 else if (selection && typeid(*selection)==typeid(BranchObj))
425 // This is used if selected branch is saved from mainwindow
426 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
429 // Save local settings
430 s+=settings.getXMLData (destPath);
433 if (selection && !saveSelection )
434 s+=valueElement("select",selection->getSelectString());
437 s+=endElement("vymmap");
440 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
444 void MapEditor::saveState(const QString &comment)
447 saveState (CompleteMap,"",NULL,"",NULL, comment);
450 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &comment)
452 // save the given part of the map
453 saveState (PartOfMap,"",undoSel,"",NULL, comment);
456 void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment)
458 // selection does not change during action,
459 // so just save commands for undo and redo
460 LinkableMapObj *unsel;
465 saveState (UndoCommand,uc,unsel,rc,unsel, comment);
468 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel, const QString &comment)
470 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL, comment);
473 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel, const QString &comment)
477 if (blockSaveState) return;
479 /* TODO remove after testing
480 cout << "ME::saveState() begin\n"<<endl;
481 cout << " undosTotal="<<undosTotal<<endl;
482 cout << " undosAvail="<<undosAvail<<endl;
483 cout << " undoNum="<<undoNum<<endl;
484 cout << " ---------------------------"<<endl;
487 historyWindow->append (comment);
491 // Find out current undo directory
492 if (undosAvail<undosTotal) undosAvail++;
494 if (undoNum>undosTotal) undoNum=1;
497 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
498 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
500 // Create bakMapDir if not available
503 makeSubDirs (bakMapDir);
505 // Save current selection
506 QString redoSelection="";
508 redoSelection=redoSel->getSelectString();
510 // Save the object, which should be undone
511 QString undoSelection="";
513 undoSelection=undoSel->getSelectString();
515 // Save depending on how much needs to be saved
516 QString undoCommand="";
517 if (savemode==UndoCommand)
522 else if (savemode==PartOfMap && undoSel)
524 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
525 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
528 undoCommand="undoMap (\""+bakMapPath+"\")";
529 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
532 if (!backupXML.isEmpty())
533 // Write XML Data to disk
534 saveStringToDisk (QString(bakMapPath),backupXML);
537 set.setEntry (QString("undoCommand"),undoCommand);
538 set.setEntry (QString("undoSelection"),undoSelection);
539 set.setEntry (QString("redoCommand"),redoCom);
540 set.setEntry (QString("redoSelection"),redoSelection);
541 set.setEntry (QString("comment"),comment);
542 set.writeSettings(QString(bakMapDir+"/commands"));
544 /* TODO remove after testing
545 cout << " into="<< bakMapDir<<endl;
546 cout << " undosAvail="<<undosAvail<<endl;
547 cout << " undoNum="<<undoNum<<endl;
548 cout << " ---------------------------"<<endl;
549 cout << " comment="<<comment<<endl;
550 cout << " ---------------------------"<<endl;
551 cout << " undoCom="<<undoCommand<<endl;
552 cout << " undoSel="<<undoSelection<<endl;
553 cout << " ---------------------------"<<endl;
554 cout << " redoCom="<<redoCom<<endl;
555 cout << " redoSel="<<redoSelection<<endl;
556 cout << " ---------------------------"<<endl<<endl;
560 void MapEditor::parseAtom(const QString &atom)
567 // Split string s into command and parameters
568 api.parseCommand (atom);
569 QString com=api.command();
572 if (com=="moveBranchUp")
574 else if (com=="moveBranchDown")
576 else if (com=="move")
578 if (api.checkParamCount(2) && selection )
588 else if (com=="linkBranchToPos")
590 if (selection && typeid(*selection) == typeid(BranchObj) )
592 if (api.checkParamCount(4))
594 s=api.parString(ok,0);
595 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
598 if (typeid(*dst) == typeid(BranchObj) )
600 // Get number in parent
603 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
604 } else if (typeid(*dst) == typeid(MapCenterObj) )
606 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
607 // Get coordinates of mainbranch
612 if (ok) ((BranchObj*)selection)->move (x,y);
618 } else if (com=="setHeading")
620 if (api.checkParamCount(1))
622 s=api.parString (ok,0);
623 if (ok) setHeading (s);
625 } else if (com=="setURL")
627 if (api.checkParamCount(1))
629 s=api.parString (ok,0);
632 } else if (com=="setVymLink")
634 if (api.checkParamCount(1))
636 s=api.parString (ok,0);
637 if (ok) setVymLink(s);
640 // Internal commands, used for undo etc.
641 else if (com==QString("undoMap"))
643 if (api.checkParamCount(1))
644 undoXML("",api.parString (ok,0));
645 } else if (com==QString("undoPart"))
647 if (api.checkParamCount(2))
649 s=api.parString (ok,0);
650 t=api.parString (ok,1);
653 } else if (com=="select")
654 if (api.checkParamCount(1))
656 s=api.parString(ok,0);
661 api.setError ("Unknown command in: "+atom);
662 cout << "ME::parse api should have error now...\n";
668 cout << "MapEditor::parseAtom: Error!\n";
669 cout << " "<<api.errorDesc()<<endl;
674 void MapEditor::finishedLineEdit()
676 // This is called by finishedLineEdit or any MapEditor method,
677 // which wants to assure, that lineedits finish, before e.g. a branch is
680 // After calling LineEdit and using the clipboard, the
681 // focus is not any longer on the main widget, we
682 // have to restore it using parentWidget()->setFocus()
686 saveState("setHeading (\""+editingBO->getHeading()+"\")",editingBO, QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(lineedit->text()) );
687 editingBO->setHeading(lineedit->text() );
689 lineedit->releaseKeyboard();
691 parentWidget()->setFocus();
692 mapCenter->reposition();
694 ensureSelectionVisible();
698 void MapEditor::toggleHistoryWindow()
700 if (historyWindow->isVisible())
701 historyWindow->hide();
703 historyWindow->show();
707 bool MapEditor::isDefault()
712 bool MapEditor::isUnsaved()
717 bool MapEditor::hasChanged()
722 void MapEditor::setChanged()
727 actionEditUndo->setEnabled (true);
728 actionFileSave->setEnabled (true);
732 void MapEditor::closeMap()
734 // Finish open lineEdits
735 if (lineedit) finishedLineEdit();
737 // Unselect before disabling the toolbar actions
738 if (selection) selection->unselect();
746 void MapEditor::setFilePath(QString fname)
748 setFilePath (fname,fname);
751 void MapEditor::setFilePath(QString fname, QString destname)
753 if (fname.isEmpty() || fname=="")
760 filePath=fname; // becomes absolute path
761 fileName=fname; // gets stripped of path
762 destPath=destname; // needed for vymlinks
764 // If fname is not an absolute path, complete it
765 filePath=QDir(fname).absPath();
766 fileDir=filePath.left (1+filePath.findRev ("/"));
768 // Set short name, too. Search from behind:
769 int i=fileName.findRev("/");
770 if (i>=0) fileName=fileName.remove (0,i+1);
772 // Forget the .vym (or .xml) for name of map
773 mapName=fileName.left(fileName.findRev(".",-1,true) );
775 // Adjust history window
776 historyWindow->setCaption (fileName);
780 QString MapEditor::getFilePath()
785 QString MapEditor::getFileName()
790 QString MapEditor::getMapName()
795 QString MapEditor::getDestPath()
800 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
802 // Finish open lineEdits
803 if (lineedit) finishedLineEdit();
805 ErrorCode err=success;
809 if (selection) selection->unselect();
812 mapCenter->setMapEditor(this);
813 // (map state is set later at end of load...)
816 saveState(selection,"Load map");
820 mapBuilderHandler handler;
823 // I am paranoid: file should exist anyway
824 // according to check in mainwindow.
827 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
828 tr("Couldn't open map " +fname)+".");
832 blockReposition=true;
833 QXmlInputSource source( file);
834 QXmlSimpleReader reader;
835 reader.setContentHandler( &handler );
836 reader.setErrorHandler( &handler );
837 handler.setMapEditor( this );
838 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
839 handler.setInputFile (file.name());
840 handler.setLoadMode (lmode);
842 bool ok = reader.parse( source );
843 blockReposition=false;
844 blockSaveState=false;
848 mapCenter->reposition();
858 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
859 tr( handler.errorProtocol() ) );
861 // Still return "success": the map maybe at least
862 // partially read by the parser
869 int MapEditor::save (const SaveMode &savemode)
871 // Finish open lineEdits
872 if (lineedit) finishedLineEdit();
876 // The SaveMode UndoCommand is not supported here
877 if (savemode==UndoCommand) return 1;
879 // Create mapName and fileDir
880 makeSubDirs (fileDir);
884 fname=mapName+".xml";
886 // use name given by user, even if he chooses .doc
891 if (savemode==CompleteMap || selection==NULL)
892 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
894 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
896 if (!saveStringToDisk(fileDir+fname,saveFile))
903 actionFileSave->setEnabled(false);
909 void MapEditor::setZipped (bool z)
914 bool MapEditor::saveZipped ()
919 void MapEditor::print()
921 // Finish open lineEdits
922 if (lineedit) finishedLineEdit();
926 printer = new QPrinter;
927 printer->setColorMode (QPrinter::Color);
928 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
931 QRect totalBBox=mapCenter->getTotalBBox();
933 // Try to set orientation automagically
934 // Note: Interpretation of generated postscript is amibiguous, if
935 // there are problems with landscape mode, see
936 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
938 if (totalBBox.width()>totalBBox.height())
939 // recommend landscape
940 printer->setOrientation (QPrinter::Landscape);
942 // recommend portrait
943 printer->setOrientation (QPrinter::Portrait);
945 if ( printer->setup(this) )
946 // returns false, if printing is canceled
948 QPainter pp(printer);
950 // Don't print the visualisation of selection
951 LinkableMapObj *oldselection=NULL;
954 oldselection=selection;
955 selection->unselect();
958 // Handle sizes of map and paper:
960 // setWindow defines which part of the canvas will be transformed
961 // setViewport defines area on paper in device coordinates (dpi)
962 // e.g. (0,50,700,700) is upper part on A4
963 // see also /usr/lib/qt3/doc/html/coordsys.html
965 QPaintDeviceMetrics metrics (printer);
967 double paperAspect = (double)metrics.width() / (double)metrics.height();
968 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
970 QRect mapRect=totalBBox;
971 QCanvasRectangle *frame=NULL;
972 QCanvasText *footerFN=NULL;
973 QCanvasText *footerDate=NULL;
974 if (printFrame || printFooter)
979 // Print frame around map
980 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
981 totalBBox.width()+20, totalBBox.height()+20);
982 frame=new QCanvasRectangle (mapRect,mapCanvas);
983 frame->setBrush (QColor(white));
984 frame->setPen (QColor(black));
988 /* TODO remove after testing
989 QCanvasLine *l=new QCanvasLine (mapCanvas);
990 l->setPoints (0,0,mapRect.width(),mapRect.height());
991 l->setPen (QPen(QColor(black), 1));
998 // Print footer below map
1000 font.setPointSize(10);
1001 footerFN=new QCanvasText (mapCanvas);
1002 footerFN->setText ("VYM - " + fileName);
1003 footerFN->setFont(font);
1004 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
1005 footerFN->setZ(Z_TEXT);
1007 footerDate=new QCanvasText (mapCanvas);
1008 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1009 footerDate->setFont(font);
1010 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1011 footerDate->setZ(Z_TEXT);
1014 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1017 pp.setWindow (mapRect);
1020 if (mapAspect>=paperAspect)
1022 // Fit horizontally to paper width
1023 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1026 // Fit vertically to paper height
1027 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1030 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1032 // Delete Frame and footer
1036 delete (footerDate);
1038 if (frame) delete (frame);
1040 // Restore selection
1043 selection=oldselection;
1044 selection->select();
1047 // Save settings in vymrc
1048 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1052 QPixmap MapEditor::getPixmap()
1054 QRect mapRect=mapCenter->getTotalBBox();
1055 QPixmap pix (mapRect.size());
1058 // Don't print the visualisation of selection
1059 LinkableMapObj *oldselection=NULL;
1062 oldselection=selection;
1063 selection->unselect();
1066 pp.setWindow (mapRect);
1068 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1071 // Restore selection
1074 selection=oldselection;
1075 selection->select();
1081 void MapEditor::setHideTmpMode (HideTmpMode mode)
1084 mapCenter->setHideTmp (hidemode);
1085 mapCenter->reposition();
1090 HideTmpMode MapEditor::getHideTmpMode()
1095 void MapEditor::exportImage(QString fn)
1097 // Finish open lineEdits
1098 if (lineedit) finishedLineEdit();
1100 setExportMode (true);
1101 QPixmap pix (getPixmap());
1102 pix.save(fn, "PNG");
1103 setExportMode (false);
1106 void MapEditor::setExportMode (bool b)
1108 // should be called before and after exports
1109 // depending on the settings
1110 if (b && settings.readEntry("/vym/export/useHideExport","yes"))
1111 setHideTmpMode (HideExport);
1113 setHideTmpMode (HideNone);
1116 void MapEditor::exportImage(QString fn, int item)
1118 // Finish open lineEdits
1119 if (lineedit) finishedLineEdit();
1121 setExportMode (true);
1122 QPixmap pix (getPixmap());
1123 pix.save(fn, exportImageFormatMenu->text(item) );
1124 setExportMode (false);
1127 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1131 ex.setMapCenter(mapCenter);
1132 if (ex.setConfigFile(cf))
1134 setExportMode (true);
1135 ex.exportPresentation();
1136 setExportMode (false);
1142 void MapEditor::exportXML(const QString &dir)
1144 // Hide stuff during export, if settings want this
1145 setExportMode (true);
1147 // Create subdirectories
1150 // write to directory
1151 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1154 file.setName ( dir + "/"+mapName+".xml");
1155 if ( !file.open( IO_WriteOnly ) )
1157 // This should neverever happen
1158 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1162 // Write it finally, and write in UTF8, no matter what
1163 QTextStream ts( &file );
1164 ts.setEncoding (QTextStream::UnicodeUTF8);
1168 // Now write image, too
1169 exportImage (dir+"/images/"+mapName+".png");
1171 setExportMode (false);
1174 void MapEditor::clear()
1178 selection->unselect();
1185 void MapEditor::copy()
1187 // Finish open lineEdits
1188 if (lineedit) finishedLineEdit();
1192 // write to directory
1193 QString clipfile="part";
1194 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1197 file.setName ( clipboardDir + "/"+clipfile+".xml");
1198 if ( !file.open( IO_WriteOnly ) )
1200 // This should neverever happen
1201 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1205 // Write it finally, and write in UTF8, no matter what
1206 QTextStream ts( &file );
1207 ts.setEncoding (QTextStream::UnicodeUTF8);
1211 clipboardEmpty=false;
1216 void MapEditor::redo()
1218 // Finish open lineEdits
1219 if (lineedit) finishedLineEdit();
1221 blockSaveState=true;
1223 // Find out current undo directory
1224 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1226 // Restore variables
1227 QString undoCommand;
1228 QString undoSelection;
1229 QString redoCommand;
1230 QString redoSelection;
1232 set.readSettings(QString(bakMapDir+"/commands"));
1233 undoCommand=set.readEntry ("undoCommand");
1234 undoSelection=set.readEntry ("undoSelection");
1235 redoCommand=set.readEntry ("redoCommand");
1236 redoSelection=set.readEntry ("redoSelection");
1238 // select object before redo
1239 if (!redoSelection.isEmpty())
1240 select (redoSelection);
1242 /* TODO remove testing
1243 cout << "ME::redo() begin\n";
1244 cout << " undosTotal="<<undosTotal<<endl;
1245 cout << " undosAvail="<<undosAvail<<endl;
1246 cout << " undoNum="<<undoNum<<endl;
1247 cout << " ---------------------------"<<endl;
1248 cout << " undoCom="<<undoCommand<<endl;
1249 cout << " undoSel="<<undoSelection<<endl;
1250 cout << " ---------------------------"<<endl;
1251 cout << " redoCom="<<redoCommand<<endl;
1252 cout << " redoSel="<<redoSelection<<endl;
1253 cout << " ---------------------------"<<endl;
1255 parseAtom (undoCommand);
1256 mapCenter->reposition();
1258 //if (!redoSelection.isEmpty())
1259 // select (redoSelection);
1263 // Undo not longer available now
1264 actionEditUndo->setEnabled (false);
1266 undoNum--; if (undoNum<1) undoNum=undosTotal;
1268 blockSaveState=false;
1269 /* TODO remove testing
1270 cout << "ME::redo() end\n";
1271 cout << " undosAvail="<<undosAvail<<endl;
1272 cout << " undoNum="<<undoNum<<endl;
1273 cout << " ---------------------------"<<endl<<endl;
1277 void MapEditor::undo()
1279 // Finish open lineEdits
1280 if (lineedit) finishedLineEdit();
1282 blockSaveState=true;
1284 // Find out current undo directory
1285 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1287 // Restore variables
1288 QString undoCommand;
1289 QString undoSelection;
1290 QString redoCommand;
1291 QString redoSelection;
1293 set.readSettings(QString(bakMapDir+"/commands"));
1294 undoCommand= set.readEntry ("undoCommand");
1295 undoSelection=set.readEntry ("undoSelection");
1296 redoCommand= set.readEntry ("redoCommand");
1297 redoSelection=set.readEntry ("redoSelection");
1299 // select object before undo
1300 if (!undoSelection.isEmpty())
1301 select (undoSelection);
1304 cout << "ME::undo() begin\n";
1305 cout << " undosTotal="<<undosTotal<<endl;
1306 cout << " undosAvail="<<undosAvail<<endl;
1307 cout << " undoNum="<<undoNum<<endl;
1308 cout << " ---------------------------"<<endl;
1309 cout << " undoCom="<<undoCommand<<endl;
1310 cout << " undoSel="<<undoSelection<<endl;
1311 cout << " ---------------------------"<<endl;
1312 cout << " redoCom="<<redoCommand<<endl;
1313 cout << " redoSel="<<redoSelection<<endl;
1314 cout << " ---------------------------"<<endl;
1316 parseAtom (undoCommand);
1317 mapCenter->reposition();
1319 //if (!redoSelection.isEmpty())
1320 // select (redoSelection);
1324 // Undo not longer available now
1325 actionEditUndo->setEnabled (false);
1327 undoNum--; if (undoNum<1) undoNum=undosTotal;
1329 blockSaveState=false;
1330 /* TODO remove testing
1331 cout << "ME::undo() end\n";
1332 cout << " undosAvail="<<undosAvail<<endl;
1333 cout << " undoNum="<<undoNum<<endl;
1334 cout << " ---------------------------"<<endl<<endl;
1338 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1340 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1342 QFile file (bakMapPath);
1346 // We need to parse saved XML data
1347 mapBuilderHandler handler;
1348 QXmlInputSource source( file);
1349 QXmlSimpleReader reader;
1350 reader.setContentHandler( &handler );
1351 reader.setErrorHandler( &handler );
1352 handler.setMapEditor( this );
1353 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1354 if (undoSel.isEmpty())
1358 handler.setLoadMode (NewMap);
1362 handler.setLoadMode (ImportReplace);
1364 blockReposition=true;
1365 bool ok = reader.parse( source );
1366 blockReposition=false;
1369 // This should never ever happen
1370 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1371 tr( handler.errorProtocol() )+" in "+bakMapDir );
1375 QMessageBox::critical( 0, tr( "Critical Error" ),
1376 tr("Temporary directory %1 used for undo is gone. \n"
1377 "I will create a new one, but at the moment no undo is available.\n"
1378 "Maybe you want to reload your original data.\n\n"
1379 "Sorry for any inconveniences.").arg(bakMapDir) );
1384 void MapEditor::pasteNoSave()
1386 // Finish open lineEdits
1387 if (lineedit) finishedLineEdit();
1389 load (clipboardDir+"/part.xml",ImportAdd);
1392 void MapEditor::cutNoSave()
1398 void MapEditor::paste()
1400 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1401 typeid(*selection) == typeid(MapCenterObj)))
1403 saveState(selection,QString("Paste to %1").arg( getName(selection)));
1405 mapCenter->reposition();
1410 void MapEditor::cut()
1412 saveState(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
1415 mapCenter->reposition();
1419 void MapEditor::move(const int &x, const int &y)
1421 // TODO no saveState, because this is only internal at undo so far
1422 if (selection) selection->move(x,y);
1423 if (typeid(*selection) == typeid(FloatImageObj))
1424 ((FloatImageObj*)selection)->setRelPos();
1427 void MapEditor::moveBranchUp()
1429 // Finish open lineEdits
1430 if (lineedit) finishedLineEdit();
1434 if (typeid(*selection) == typeid(BranchObj) )
1436 bo=(BranchObj*)selection;
1437 if (!bo->canMoveBranchUp()) return;
1438 par=(BranchObj*)(bo->getParObj());
1439 selection->unselect();
1440 selection=par->moveBranchUp (bo);
1441 selection->select();
1442 saveState("moveBranchDown ()",bo,QString("Move up %1").arg(getName(bo)));
1443 mapCenter->reposition();
1444 ensureSelectionVisible();
1448 void MapEditor::moveBranchDown()
1450 // Finish open lineEdits
1451 if (lineedit) finishedLineEdit();
1455 if (typeid(*selection) == typeid(BranchObj) )
1457 bo=(BranchObj*)selection;
1458 if (!bo->canMoveBranchDown()) return;
1459 par=(BranchObj*)(bo->getParObj());
1460 selection->unselect();
1461 selection=par->moveBranchDown(bo);
1462 selection->select();
1463 saveState("moveBranchUp ()",bo,QString("Move down %1").arg(getName(bo)));
1464 mapCenter->reposition();
1465 ensureSelectionVisible();
1469 void MapEditor::editHeading()
1471 // Finish open lineEdits
1472 if (lineedit) finishedLineEdit();
1475 (typeid(*selection) == typeid(BranchObj) ||
1476 typeid(*selection) == typeid(MapCenterObj) ) )
1478 editingBO=(BranchObj*)selection;
1480 ensureSelectionVisible();
1481 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1482 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1483 QString s=editingBO->getHeading();
1484 lineedit->setText(s);
1485 lineedit->setCursorPosition(1);
1486 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1487 lineedit->selectAll();
1489 lineedit->grabKeyboard();
1490 lineedit->setFocus();
1494 void MapEditor::setHeading(const QString &s)
1496 // Internal function, no saveState needed
1498 (typeid(*selection) == typeid(BranchObj) ||
1499 typeid(*selection) == typeid(MapCenterObj) ) )
1501 ((BranchObj*)selection)->setHeading(s);
1502 mapCenter->reposition();
1504 ensureSelectionVisible();
1508 void MapEditor::setURL (const QString &s)
1510 // Internal function, no saveState needed
1512 (typeid(*selection) == typeid(BranchObj) ||
1513 typeid(*selection) == typeid(MapCenterObj) ) )
1515 ((BranchObj*)selection)->setURL(s);
1516 mapCenter->reposition();
1518 ensureSelectionVisible();
1522 void MapEditor::setVymLink (const QString &s)
1524 // Internal function, no saveState needed
1526 (typeid(*selection) == typeid(BranchObj) ||
1527 typeid(*selection) == typeid(MapCenterObj) ) )
1529 ((BranchObj*)selection)->setVymLink(s);
1530 mapCenter->reposition();
1532 ensureSelectionVisible();
1536 void MapEditor::addNewBranch(int pos)
1538 // Finish open lineEdits
1539 if (lineedit) finishedLineEdit();
1542 (typeid(*selection) == typeid(BranchObj) ||
1543 typeid(*selection) == typeid(MapCenterObj) ) )
1545 BranchObj* bo1 = (BranchObj*) selection;
1546 saveState(selection, QString("Add new branch to %1").arg(getName(bo1))); //TODO undoCommand
1548 bool wasScrolled=false;
1549 BranchObj *newbo=NULL;
1552 // save scroll state. If scrolled, automatically select
1553 // new branch in order to tmp unscroll parent...
1554 wasScrolled=bo1->isScrolled();
1555 newbo=bo1->addBranch();
1558 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1562 // add above selection
1563 newbo=parbo->insertBranch(bo1->getNum());
1565 // add below selection
1566 newbo=parbo->insertBranch(bo1->getNum()+1);
1568 // This should not happen...
1573 LinkableMapObj *oldselection=selection;
1575 mapCenter->reposition();
1577 if (actionSettingsAutoedit->isOn() ||
1578 actionSettingsAutoselectHeading->isOn() )
1580 selection->unselect();
1582 selection->select();
1583 if (actionSettingsPasteNewHeading->isOn() )
1585 BranchObj *bo2= (BranchObj*)selection;
1586 bo2->setHeading("");
1588 if (actionSettingsAutoedit->isOn() )
1590 if (!actionSettingsAutoselectHeading->isOn()
1593 selection->unselect();
1594 selection=oldselection;
1595 selection->select();
1602 void MapEditor::addNewBranchHere()
1604 // Finish open lineEdits
1605 if (lineedit) finishedLineEdit();
1608 (typeid(*selection) == typeid(BranchObj) ) )
1610 BranchObj* bo1 = (BranchObj*) selection;
1611 saveState(selection, QString("Add new branch here").arg(getName(bo1)));
1613 bool wasScrolled=false;
1614 BranchObj *newbo=NULL;
1615 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1618 // add below selection
1619 newbo=parbo->insertBranch(bo1->getNum()+1);
1622 LinkableMapObj *oldselection=selection;
1623 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1625 mapCenter->reposition();
1627 if (actionSettingsAutoedit->isOn() ||
1628 actionSettingsAutoselectHeading->isOn() )
1630 selection->unselect();
1632 selection->select();
1633 if (actionSettingsPasteNewHeading->isOn() )
1635 BranchObj *bo2= (BranchObj*)selection;
1636 bo2->setHeading("");
1638 if (actionSettingsAutoedit->isOn() )
1640 if (!actionSettingsAutoselectHeading->isOn()
1643 selection->unselect();
1644 selection=oldselection;
1645 selection->select();
1651 void MapEditor::deleteSelection()
1653 // Finish open lineEdits
1654 if (lineedit) finishedLineEdit();
1656 if (selection && typeid(*selection) ==typeid(BranchObj) )
1658 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1659 BranchObj* par=(BranchObj*)(bo->getParObj());
1661 if (selection->getDepth()>1)
1662 // Normal branch, save parent with childs
1663 saveState(par,QString("Delete %1").arg(getName(bo)));
1665 // Mainbranch, save whole map
1666 // TODO Better would be to insert mainbranch again at pos
1667 // But undoCommand is missing right now
1668 saveState(QString("Delete %1").arg(getName(bo)));
1670 par->removeBranch(bo);
1672 selection->select();
1673 ensureSelectionVisible();
1674 mapCenter->reposition();
1677 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1679 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1680 BranchObj* par=(BranchObj*)(fio->getParObj());
1681 saveState(par, QString("Delete %1").arg(getName(fio)));
1684 par->removeFloatImage(fio);
1686 selection->select();
1687 ensureSelectionVisible();
1688 mapCenter->reposition();
1693 LinkableMapObj* MapEditor::getSelection()
1698 void MapEditor::unselect()
1702 selectionLast=selection;
1703 selection->unselect();
1708 void MapEditor::reselect()
1712 selection=selectionLast;
1713 selection->select();
1718 bool MapEditor::select (const QString &s)
1720 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1722 // Finally select the found object
1725 if (selection) unselect();
1727 selection->select();
1729 ensureSelectionVisible();
1735 void MapEditor::select (LinkableMapObj *lmo)
1737 if (lmo && selection != lmo)
1739 // select the MapObj
1740 if (selection) selection->unselect();
1742 selection->select();
1749 void MapEditor::selectNextBranch()
1751 // Increase number of branch
1754 QString s=selection->getSelectString();
1760 part=s.section(",",-1);
1762 num=part.right(part.length() - 3);
1764 s=s.left (s.length() -num.length());
1767 num=QString ("%1").arg(num.toUInt()+1);
1771 // Try to select this one
1772 if (select (s)) return;
1774 // We have no direct successor,
1775 // try to increase the parental number in order to
1776 // find a successor with same depth
1778 int d=selection->getDepth();
1783 while (!found && d>0)
1785 s=s.section (",",0,d-1);
1786 // replace substring of current depth in s with "1"
1787 part=s.section(",",-1);
1789 num=part.right(part.length() - 3);
1793 // increase number of parent
1794 num=QString ("%1").arg(num.toUInt()+1);
1795 s=s.section (",",0,d-2) + ","+ typ+num;
1798 // Special case, look at orientation
1799 if (selection->getOrientation()==OrientRightOfCenter)
1800 num=QString ("%1").arg(num.toUInt()+1);
1802 num=QString ("%1").arg(num.toUInt()-1);
1807 // pad to oldDepth, select the first branch for each depth
1808 for (i=d;i<oldDepth;i++)
1813 if ( ((BranchObj*)selection)->countBranches()>0)
1821 // try to select the freshly built string
1829 void MapEditor::selectPrevBranch()
1831 // Decrease number of branch
1834 QString s=selection->getSelectString();
1840 part=s.section(",",-1);
1842 num=part.right(part.length() - 3);
1844 s=s.left (s.length() -num.length());
1847 num=QString ("%1").arg(num.toUInt()-1);
1851 // Try to select this one
1852 if (select (s)) return;
1854 // We have no direct precessor,
1855 // try to decrease the parental number in order to
1856 // find a precessor with same depth
1858 int d=selection->getDepth();
1863 while (!found && d>0)
1865 s=s.section (",",0,d-1);
1866 // replace substring of current depth in s with "1"
1867 part=s.section(",",-1);
1869 num=part.right(part.length() - 3);
1873 // decrease number of parent
1874 num=QString ("%1").arg(num.toUInt()-1);
1875 s=s.section (",",0,d-2) + ","+ typ+num;
1878 // Special case, look at orientation
1879 if (selection->getOrientation()==OrientRightOfCenter)
1880 num=QString ("%1").arg(num.toUInt()-1);
1882 num=QString ("%1").arg(num.toUInt()+1);
1887 // pad to oldDepth, select the last branch for each depth
1888 for (i=d;i<oldDepth;i++)
1892 if ( ((BranchObj*)selection)->countBranches()>0)
1893 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1900 // try to select the freshly built string
1908 void MapEditor::selectUpperBranch()
1910 // Finish open lineEdits
1911 if (lineedit) finishedLineEdit();
1915 if (typeid(*selection) == typeid(BranchObj))
1917 if (selection->getOrientation()==OrientRightOfCenter)
1920 if (selection->getDepth()==1)
1928 void MapEditor::selectLowerBranch()
1930 // Finish open lineEdits
1931 if (lineedit) finishedLineEdit();
1935 if (typeid(*selection) == typeid(BranchObj))
1937 if (selection->getOrientation()==OrientRightOfCenter)
1940 if (selection->getDepth()==1)
1949 void MapEditor::selectLeftBranch()
1951 // Finish open lineEdits
1952 if (lineedit) finishedLineEdit();
1958 if (typeid(*selection) == typeid(MapCenterObj))
1960 par= (BranchObj*) selection;
1961 bo=par->getLastSelectedBranch();
1964 // Workaround for reselecting on left and right side
1965 if (bo->getOrientation()==OrientRightOfCenter)
1967 bo=par->getLastBranch();
1973 selection->select();
1975 ensureSelectionVisible();
1980 par=(BranchObj*)(selection->getParObj());
1981 if (selection->getOrientation()==OrientRightOfCenter)
1983 if (typeid(*selection) == typeid(BranchObj) ||
1984 typeid(*selection) == typeid(FloatImageObj))
1986 selection->unselect();
1988 selection->select();
1990 ensureSelectionVisible();
1994 if (typeid(*selection) == typeid(BranchObj) )
1996 bo=((BranchObj*)selection)->getLastSelectedBranch();
1999 selection->unselect();
2001 selection->select();
2003 ensureSelectionVisible();
2011 void MapEditor::selectRightBranch()
2013 // Finish open lineEdits
2014 if (lineedit) finishedLineEdit();
2021 if (typeid(*selection) == typeid(MapCenterObj))
2023 par= (BranchObj*) selection;
2024 bo=par->getLastSelectedBranch();
2027 // Workaround for relecting on left and right side
2028 if (bo->getOrientation()==OrientLeftOfCenter)
2029 bo=par->getFirstBranch();
2034 selection->select();
2035 ensureSelectionVisible();
2040 par=(BranchObj*)(selection->getParObj());
2041 if (selection->getOrientation()==OrientLeftOfCenter)
2043 if (typeid(*selection) == typeid(BranchObj) ||
2044 typeid(*selection) == typeid(FloatImageObj))
2046 selection->unselect();
2048 selection->select();
2050 ensureSelectionVisible();
2054 if (typeid(*selection) == typeid(BranchObj) )
2056 bo=((BranchObj*)selection)->getLastSelectedBranch();
2059 selection->unselect();
2061 selection->select();
2063 ensureSelectionVisible();
2071 void MapEditor::selectFirstBranch()
2073 // Finish open lineEdits
2074 if (lineedit) finishedLineEdit();
2080 if (typeid(*selection) == typeid(BranchObj))
2082 bo1= (BranchObj*) selection;
2083 par=(BranchObj*)(bo1->getParObj());
2084 bo2=par->getFirstBranch();
2088 selection->select();
2089 ensureSelectionVisible();
2096 void MapEditor::selectLastBranch()
2098 // Finish open lineEdits
2099 if (lineedit) finishedLineEdit();
2105 if (typeid(*selection) == typeid(BranchObj))
2107 bo1= (BranchObj*) selection;
2108 par=(BranchObj*)(bo1->getParObj());
2109 bo2=par->getLastBranch();
2113 selection->select();
2114 ensureSelectionVisible();
2121 void MapEditor::setColor(QColor c)
2126 void MapEditor::selectBackgroundColor()
2128 // Finish open lineEdits
2129 if (lineedit) finishedLineEdit();
2131 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2132 if ( !col.isValid() ) return;
2133 setBackgroundColor( col );
2134 saveState(QString("Set background color of map to %1").arg(col.name()));
2137 void MapEditor::setBackgroundColor(QColor c)
2139 mapCanvas->setBackgroundColor (c);
2142 QColor MapEditor::pickColor()
2146 if (typeid(*selection) == typeid(BranchObj) ||
2147 typeid(*selection) == typeid(MapCenterObj))
2149 BranchObj *bo=(BranchObj*)selection;
2150 actColor=bo->getColor();
2156 void MapEditor::colorItem()
2160 if (typeid(*selection) == typeid(BranchObj) ||
2161 typeid(*selection) == typeid(MapCenterObj))
2163 BranchObj *bo=(BranchObj*)selection;
2164 saveState(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2165 bo->setColor(actColor); // color branch
2170 void MapEditor::colorBranch()
2174 if (typeid(*selection) == typeid(BranchObj) ||
2175 typeid(*selection) == typeid(MapCenterObj))
2177 BranchObj *bo=(BranchObj*)selection;
2178 saveState(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2179 bo->setColorChilds(actColor); // color links, color childs
2185 void MapEditor::toggleStandardFlag(QString f)
2189 BranchObj *bo=(BranchObj*)selection;
2191 if (bo->isSetStandardFlag(f))
2195 saveState(selection, QString("%1 standard flag \"%2\" of %3").arg(s).arg(f).arg(getName(bo)));// TODO undoCommand
2196 bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn());
2201 void MapEditor::setViewCenter()
2203 // transform to CanvasView Coord:
2204 QPoint p=worldMatrix().map(movingCenter);
2205 center ( p.x(), p.y());
2209 BranchObj* MapEditor::findText (QString s, bool cs)
2212 { // Nothing found or new find process
2214 // nothing found, start again
2216 itFind=mapCenter->first();
2218 bool searching=true;
2219 bool foundNote=false;
2220 while (searching && !EOFind)
2224 // Searching in Note
2225 if (itFind->getNote().contains(s,cs))
2227 if (selection!=itFind)
2229 if (selection) ((BranchObj*)selection)->unselect();
2231 selection->select();
2233 ensureSelectionVisible();
2235 if (textEditor->findText(s,cs))
2241 // Searching in Heading
2242 if (searching && itFind->getHeading().contains (s,cs) )
2244 if (selection) ((BranchObj*)selection)->unselect();
2246 selection->select();
2248 ensureSelectionVisible();
2254 itFind=itFind->next();
2255 if (!itFind) EOFind=true;
2261 return (BranchObj*)selection;
2266 void MapEditor::findReset()
2267 { // Necessary if text to find changes during a find process
2272 void MapEditor::editURL()
2274 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2275 typeid(*selection) == typeid(MapCenterObj)) )
2278 BranchObj *bo=(BranchObj*)selection;
2279 QString text = QInputDialog::getText(
2280 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2281 bo->getURL(), &ok, this );
2284 // user entered something and pressed OK
2285 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2292 QString MapEditor::getURL()
2294 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2295 typeid(*selection) == typeid(MapCenterObj)) )
2296 return ((BranchObj*)selection)->getURL();
2301 void MapEditor::editHeading2URL()
2303 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2304 typeid(*selection) == typeid(MapCenterObj)) )
2306 BranchObj *bo=(BranchObj*)selection;
2307 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2308 bo->setURL (bo->getHeading());
2313 void MapEditor::editBugzilla2URL()
2315 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2316 typeid(*selection) == typeid(MapCenterObj)) )
2318 BranchObj *bo=(BranchObj*)selection;
2319 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2320 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo)));
2326 void MapEditor::editFATE2URL()
2328 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2329 typeid(*selection) == typeid(MapCenterObj)) )
2331 BranchObj *bo=(BranchObj*)selection;
2332 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2333 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2339 void MapEditor::editVymLink()
2341 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2342 typeid(*selection) == typeid(MapCenterObj)) )
2344 BranchObj *bo=(BranchObj*)selection;
2345 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
2346 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2347 fd->setCaption(__VYM " - " +tr("Link to another map"));
2348 if (! bo->getVymLink().isEmpty() )
2349 fd->setSelection( bo->getVymLink() );
2353 if ( fd->exec() == QDialog::Accepted )
2355 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2356 bo->setVymLink (fd->selectedFile() );
2358 mapCenter->reposition();
2365 void MapEditor::deleteVymLink()
2367 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2368 typeid(*selection) == typeid(MapCenterObj)) )
2370 BranchObj *bo=(BranchObj*)selection;
2371 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2372 bo->setVymLink ("" );
2374 mapCenter->reposition();
2380 void MapEditor::toggleHideExport()
2382 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2383 typeid(*selection) == typeid(MapCenterObj)) ||
2384 (typeid(*selection)==typeid(FloatImageObj))
2387 OrnamentedObj *oo=(OrnamentedObj*)selection;
2389 if (oo->hideInExport())
2391 oo->setHideInExport(false);
2396 oo->setHideInExport(true);
2399 saveState(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2400 actionEditToggleHideExport->setOn (oo->hideInExport());
2402 mapCenter->reposition();
2408 QString MapEditor::getVymLink()
2410 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2411 typeid(*selection) == typeid(MapCenterObj)) )
2413 return ((BranchObj*)selection)->getVymLink();
2419 void MapEditor::removeBranchKeepChilds()
2421 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2423 BranchObj* bo=(BranchObj*)selection;
2424 BranchObj* par=(BranchObj*)(bo->getParObj());
2425 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2426 if (bo->getDepth()==1)
2429 saveState(selection->getParObj(),s); // TODO undoCommand
2430 QString sel=selection->getSelectString();
2432 par->removeBranchHere(bo);
2433 mapCenter->reposition();
2438 void MapEditor::removeChilds()
2440 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2442 saveState(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection)));
2443 ((BranchObj*)selection)->removeChilds();
2444 mapCenter->reposition();
2448 void MapEditor::editMapInfo()
2450 ExtraInfoDialog dia;
2451 dia.setMapName (getFileName() );
2452 dia.setAuthor (mapCenter->getAuthor() );
2453 dia.setComment(mapCenter->getComment() );
2458 QCanvasItemList l=canvas()->allItems();
2459 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2461 stats+=QString ("%1 items on canvas\n").arg (i,6);
2468 bo=mapCenter->first();
2471 if (!bo->getNote().isEmpty() ) n++;
2472 f+= bo->countFloatImages();
2474 xl+=bo->countXLinks();
2477 stats+=QString ("%1 branches\n").arg (b-1,6);
2478 stats+=QString ("%1 xLinks \n").arg (xl,6);
2479 stats+=QString ("%1 notes\n").arg (n,6);
2480 stats+=QString ("%1 images\n").arg (f,6);
2481 dia.setStats (stats);
2483 // Finally show dialog
2484 if (dia.exec() == QDialog::Accepted)
2486 saveState("Edit info about map"); //TODO undoCommand
2487 mapCenter->setAuthor (dia.getAuthor() );
2488 mapCenter->setComment (dia.getComment() );
2492 void MapEditor::updateActions()
2495 if (getLinkColorHint()==HeadingColor)
2496 actionFormatLinkColorHint->setOn(true);
2498 actionFormatLinkColorHint->setOn(false);
2503 actionFormatLinkStyleLine->setOn(true);
2506 actionFormatLinkStyleParabel->setOn(true);
2509 actionFormatLinkStylePolyLine->setOn(true);
2511 case StylePolyParabel:
2512 actionFormatLinkStylePolyParabel->setOn(true);
2518 QPixmap pix( 16, 16 );
2519 pix.fill( mapCanvas->backgroundColor() );
2520 actionFormatBackColor->setIconSet( pix );
2521 pix.fill( defLinkColor );
2522 actionFormatLinkColor->setIconSet( pix );
2524 actionEditUndo->setEnabled( mapChanged );
2525 actionFileSave->setEnabled( mapUnsaved );
2529 if ( (typeid(*selection) == typeid(BranchObj)) ||
2530 (typeid(*selection) == typeid(MapCenterObj)) )
2532 BranchObj *bo=(BranchObj*)selection;
2533 // Take care of links
2534 if (bo->countXLinks()==0)
2536 branchLinksContextMenu->clear();
2537 branchLinksContextMenu->insertItem ("No xLink available");
2538 branchLinksContextMenuDup->clear();
2539 branchLinksContextMenuDup->insertItem ("No xLink available");
2545 branchLinksContextMenu->clear();
2546 branchLinksContextMenuDup->clear();
2547 for (int i=0; i<=bo->countXLinks();i++)
2549 bot=bo->XLinkTargetAt(i);
2552 s=bot->getHeading();
2555 branchLinksContextMenu->insertItem (s);
2556 branchLinksContextMenuDup->insertItem (s);
2561 standardFlagsDefault->setEnabled (true);
2563 actionEditToggleScroll->setEnabled (true);
2564 if ( bo->isScrolled() )
2565 actionEditToggleScroll->setOn(true);
2567 actionEditToggleScroll->setOn(false);
2569 if ( bo->getURL().isEmpty() )
2571 actionEditOpenURL->setEnabled (false);
2572 actionEditOpenURLTab->setEnabled (false);
2576 actionEditOpenURL->setEnabled (true);
2577 actionEditOpenURLTab->setEnabled (true);
2579 if ( bo->getVymLink().isEmpty() )
2581 actionEditOpenVymLink->setEnabled (false);
2582 actionEditDeleteVymLink->setEnabled (false);
2585 actionEditOpenVymLink->setEnabled (true);
2586 actionEditDeleteVymLink->setEnabled (true);
2589 if (bo->canMoveBranchUp())
2590 actionEditMoveUp->setEnabled (true);
2592 actionEditMoveUp->setEnabled (false);
2593 if (bo->canMoveBranchDown())
2594 actionEditMoveDown->setEnabled (true);
2596 actionEditMoveDown->setEnabled (false);
2599 actionEditToggleHideExport->setEnabled (true);
2600 actionEditToggleHideExport->setOn (bo->hideInExport() );
2602 actionEditCopy->setEnabled (true);
2603 actionEditCut->setEnabled (true);
2604 if (!clipboardEmpty)
2605 actionEditPaste->setEnabled (true);
2607 actionEditPaste->setEnabled (false);
2608 for (a=actionListBranches.first();a;a=actionListBranches.next())
2609 a->setEnabled(true);
2610 actionEditDelete->setEnabled (true);
2611 switch (selection->getFrameType())
2614 actionFormatFrameNone->setOn(true);
2617 actionFormatFrameRectangle->setOn(true);
2622 actionFormatIncludeImagesVer->setOn
2623 ( ((BranchObj*)selection)->getIncludeImagesVer());
2624 actionFormatIncludeImagesHor->setOn
2625 ( ((BranchObj*)selection)->getIncludeImagesHor());
2626 actionFormatHideLinkUnselected->setOn
2627 (selection->getHideLinkUnselected());
2629 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2631 FloatObj *fo=(FloatImageObj*)selection;
2632 standardFlagsDefault->setEnabled (false);
2634 actionEditOpenURL->setEnabled (false);
2635 actionEditOpenVymLink->setEnabled (false);
2636 actionEditDeleteVymLink->setEnabled (false);
2637 actionEditToggleHideExport->setEnabled (true);
2638 actionEditToggleHideExport->setOn (fo->hideInExport() );
2641 actionEditCopy->setEnabled (true);
2642 actionEditCut->setEnabled (true);
2643 actionEditPaste->setEnabled (false);
2644 for (a=actionListBranches.first();a;a=actionListBranches.next())
2645 a->setEnabled(false);
2646 actionEditDelete->setEnabled (true);
2647 actionFormatHideLinkUnselected->setOn
2648 ( selection->getHideLinkUnselected());
2649 actionEditMoveUp->setEnabled (false);
2650 actionEditMoveDown->setEnabled (false);
2655 standardFlagsDefault->setEnabled (false);
2657 actionEditCopy->setEnabled (false);
2658 actionEditCut->setEnabled (false);
2659 actionEditPaste->setEnabled (false);
2660 for (a=actionListBranches.first();a;a=actionListBranches.next())
2661 a->setEnabled(false);
2663 actionEditToggleScroll->setEnabled (false);
2664 actionEditOpenURL->setEnabled (false);
2665 actionEditOpenVymLink->setEnabled (false);
2666 actionEditDeleteVymLink->setEnabled (false);
2667 actionEditHeading2URL->setEnabled (false);
2668 actionEditDelete->setEnabled (false);
2669 actionEditMoveUp->setEnabled (false);
2670 actionEditMoveDown->setEnabled (false);
2671 actionEditToggleHideExport->setEnabled (false);
2675 void MapEditor::updateNoteFlag()
2678 if ( (typeid(*selection) == typeid(BranchObj)) ||
2679 (typeid(*selection) == typeid(MapCenterObj)) )
2680 ((BranchObj*)selection)->updateNoteFlag();
2683 void MapEditor::setLinkStyle (LinkStyle ls)
2687 saveState("Set link style"); // TODO undoCommand
2689 bo=mapCenter->first();
2693 bo->setLinkStyle(bo->getDefLinkStyle());
2696 mapCenter->reposition();
2699 LinkStyle MapEditor::getLinkStyle ()
2704 void MapEditor::setLinkColor(QColor c)
2710 void MapEditor::setLinkColorHint()
2712 // called from setLinkColorHint(lch) or at end of parse
2714 bo=mapCenter->first();
2722 void MapEditor::setLinkColorHint(LinkColorHint lch)
2728 void MapEditor::toggleLinkColorHint()
2730 if (linkcolorhint==HeadingColor)
2731 linkcolorhint=DefaultColor;
2733 linkcolorhint=HeadingColor;
2735 bo=mapCenter->first();
2743 LinkColorHint MapEditor::getLinkColorHint()
2745 return linkcolorhint;
2748 QColor MapEditor::getDefLinkColor()
2750 return defLinkColor;
2753 void MapEditor::setDefXLinkColor(QColor col)
2758 QColor MapEditor::getDefXLinkColor()
2760 return defXLinkColor;
2763 void MapEditor::setDefXLinkWidth (int w)
2768 int MapEditor::getDefXLinkWidth()
2770 return defXLinkWidth;
2773 void MapEditor::selectLinkColor()
2775 // Finish open lineEdits
2776 if (lineedit) finishedLineEdit();
2778 QColor col = QColorDialog::getColor( defLinkColor, this );
2779 if ( !col.isValid() ) return;
2780 setLinkColor( col );
2781 saveState(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2785 void MapEditor::toggleScroll()
2787 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2789 BranchObj *bo=((BranchObj*)selection);
2790 if (bo->countBranches()==0) return;
2791 if (bo->getDepth()==0) return;
2793 if (bo->isScrolled())
2797 saveState(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2804 void MapEditor::unScrollAll()
2807 bo=mapCenter->first();
2810 if (bo->isScrolled()) bo->toggleScroll();
2815 void MapEditor::loadFloatImage ()
2818 (typeid(*selection) == typeid(BranchObj)) ||
2819 (typeid(*selection) == typeid(MapCenterObj)) )
2821 BranchObj *bo=((BranchObj*)selection);
2823 QFileDialog *fd=new QFileDialog( this);
2824 fd->setMode (QFileDialog::ExistingFiles);
2825 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2826 ImagePreview *p =new ImagePreview (fd);
2827 fd->setContentsPreviewEnabled( TRUE );
2828 fd->setContentsPreview( p, p );
2829 fd->setPreviewMode( QFileDialog::Contents );
2830 fd->setCaption(__VYM " - " +tr("Load image"));
2831 fd->setDir (lastImageDir);
2835 if ( fd->exec() == QDialog::Accepted )
2837 saveState(selection, QString("Add floatimage to %1").arg(getName(selection)));
2838 lastImageDir=fn.left(fn.findRev ("/"));
2839 QStringList flist = fd->selectedFiles();
2840 QStringList::Iterator it = flist.begin();
2841 while( it != flist.end() )
2844 bo->addFloatImage();
2845 // TODO check if load was successful
2846 bo->getLastFloatImage()->load(*it);
2847 bo->getLastFloatImage()->setOriginalFilename(fn);
2851 mapCenter->reposition();
2860 void MapEditor::saveFloatImage (int item)
2863 (typeid(*selection) == typeid(FloatImageObj)) )
2865 FloatImageObj *fio=((FloatImageObj*)selection);
2866 const char* fmt = saveImageFormatMenu->text(item);
2868 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2869 fd->addFilter ("PNG (*.png)");
2870 fd->addFilter ("BMP (*.bmp)");
2871 fd->addFilter ("XBM (*.xbm)");
2872 fd->addFilter ("JPG (*.jpg)");
2873 fd->addFilter ("XPM (*.xpm)");
2874 fd->addFilter ("GIF (*.gif)");
2875 fd->addFilter ("PNM (*.pnm)");
2876 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2877 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2878 fd->setMode( QFileDialog::AnyFile );
2879 fd->setSelection (fio->getOriginalFilename());
2883 if ( fd->exec() == QDialog::Accepted )
2885 if (QFile (fd->selectedFile()).exists() )
2887 QMessageBox mb( __VYM,
2888 tr("The file %1 exists already.\n"
2889 "Do you want to overwrite it?").arg(fd->selectedFile()),
2890 QMessageBox::Warning,
2891 QMessageBox::Yes | QMessageBox::Default,
2892 QMessageBox::Cancel | QMessageBox::Escape,
2893 QMessageBox::QMessageBox::NoButton );
2895 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2896 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2899 case QMessageBox::Yes:
2902 case QMessageBox::Cancel:
2908 fio->save (fd->selectedFile(),fmt);
2913 void MapEditor::setFrame(const FrameType &t)
2916 (typeid(*selection) == typeid(BranchObj)) ||
2917 (typeid(*selection) == typeid(MapCenterObj)) )
2919 selection->setFrameType (t);
2920 mapCenter->reposition();
2921 selection->updateLink();
2925 void MapEditor::setIncludeImagesVer(bool b)
2928 (typeid(*selection) == typeid(BranchObj)) ||
2929 (typeid(*selection) == typeid(MapCenterObj)) )
2930 ((BranchObj*)selection)->setIncludeImagesVer(b);
2931 mapCenter->reposition();
2934 void MapEditor::setIncludeImagesHor(bool b)
2937 (typeid(*selection) == typeid(BranchObj)) ||
2938 (typeid(*selection) == typeid(MapCenterObj)) )
2939 ((BranchObj*)selection)->setIncludeImagesHor(b);
2940 mapCenter->reposition();
2943 void MapEditor::setHideLinkUnselected (bool b)
2946 (typeid(*selection) == typeid(BranchObj)) ||
2947 (typeid(*selection) == typeid(MapCenterObj)) ||
2948 (typeid(*selection) == typeid(FloatImageObj)) )
2949 selection->setHideLinkUnselected(b);
2952 void MapEditor::importDir(BranchObj *dst, QDir d)
2955 (typeid(*selection) == typeid(BranchObj)) ||
2956 (typeid(*selection) == typeid(MapCenterObj)) )
2960 // Traverse directories
2961 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2962 const QFileInfoList *dirlist = d.entryInfoList();
2963 QFileInfoListIterator itdir( *dirlist );
2966 while ( (fi = itdir.current()) != 0 )
2968 if (fi->fileName() != "." && fi->fileName() != ".." )
2971 bo=dst->getLastBranch();
2972 bo->setHeading (fi->fileName() );
2973 bo->setColor (QColor("blue"));
2975 if ( !d.cd(fi->fileName()) )
2976 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2979 // Recursively add subdirs
2987 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2988 const QFileInfoList *filelist = d.entryInfoList();
2989 QFileInfoListIterator itfile( *filelist );
2991 while ( (fi = itfile.current()) != 0 )
2994 bo=dst->getLastBranch();
2995 bo->setHeading (fi->fileName() );
2996 bo->setColor (QColor("black"));
2997 if (fi->fileName().right(4) == ".vym" )
2998 bo->setVymLink (fi->filePath());
3005 void MapEditor::importDir()
3008 (typeid(*selection) == typeid(BranchObj)) ||
3009 (typeid(*selection) == typeid(MapCenterObj)) )
3011 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
3012 fd->setMode (QFileDialog::DirectoryOnly);
3013 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
3014 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
3018 if ( fd->exec() == QDialog::Accepted )
3020 BranchObj *bo=((BranchObj*)selection);
3021 importDir (bo,QDir(fd->selectedFile()) );
3022 mapCenter->reposition();
3029 void MapEditor::followXLink(int i)
3032 (typeid(*selection) == typeid(BranchObj)) ||
3033 (typeid(*selection) == typeid(MapCenterObj)) )
3035 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3038 selection->unselect();
3040 selection->select();
3041 ensureSelectionVisible();
3046 void MapEditor::editXLink(int i)
3049 (typeid(*selection) == typeid(BranchObj)) ||
3050 (typeid(*selection) == typeid(MapCenterObj)) )
3052 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3055 EditXLinkDialog dia;
3057 dia.setSelection(selection);
3058 if (dia.exec() == QDialog::Accepted)
3060 if (dia.useSettingsGlobal() )
3062 setDefXLinkColor (xlo->getColor() );
3063 setDefXLinkWidth (xlo->getWidth() );
3065 if (dia.deleteXLink())
3066 ((BranchObj*)selection)->deleteXLinkAt(i);
3067 saveState("Edit xLink"); //TODO undoCommand
3073 void MapEditor::testFunction()
3075 cout << "MapEditor::testFunction() called\n";
3077 mapCenter->positionBBox();
3081 dia.setCancelButton (true);
3082 dia.setText("This is a longer \nWarning");
3083 dia.setCaption("Warning: Flux problem");
3084 dia.setShowAgainName("/vym/warnings/mapeditor");
3085 if (dia.exec()==QDialog::Accepted)
3086 cout << "accepted!\n";
3088 cout << "canceled!\n";
3091 QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
3092 QProcess *proc = new QProcess( this );
3093 proc->addArgument(ub);
3095 if ( !proc->start() )
3097 QMessageBox::warning(0,
3099 tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
3104 if (hidemode==HideNone)
3106 setHideTmpMode (HideExport);
3107 mapCenter->calcBBoxSizeWithChilds();
3108 QRect totalBBox=mapCenter->getTotalBBox();
3109 QRect mapRect=totalBBox;
3110 QCanvasRectangle *frame=NULL;
3112 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3114 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3115 totalBBox.width(), totalBBox.height());
3116 frame=new QCanvasRectangle (mapRect,mapCanvas);
3117 frame->setBrush (QColor(white));
3118 frame->setPen (QColor(black));
3124 setHideTmpMode (HideNone);
3126 cout <<" hidemode="<<hidemode<<endl;
3130 void MapEditor::ensureSelectionVisible()
3134 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3136 if (selection->getOrientation() == OrientLeftOfCenter)
3137 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3139 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3140 ensureVisible (p.x(), p.y() );
3145 void MapEditor::updateViewCenter()
3147 // Update movingCenter, so that we can zoom comfortably later
3148 QRect rc = QRect( contentsX(), contentsY(),
3149 visibleWidth(), visibleHeight() );
3150 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3151 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3152 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3155 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3157 // Lineedits are already closed by preceding
3158 // mouseEvent, we don't need to close here.
3160 QPoint p = inverseWorldMatrix().map(e->pos());
3161 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3164 { // MapObj was found
3165 if (selection != lmo)
3167 // select the MapObj
3168 if (selection) selection->unselect();
3170 selection->select();
3176 if (typeid(*selection)==typeid(BranchObj) ||
3177 typeid(*selection)==typeid(MapCenterObj) )
3179 // Context Menu on branch or mapcenter
3181 branchContextMenu->popup(e->globalPos() );
3183 if (typeid(*selection)==typeid(FloatImageObj))
3185 // Context Menu on floatimage
3187 floatimageContextMenu->popup(e->globalPos() );
3191 { // No MapObj found, we are on the Canvas itself
3192 // Context Menu on Canvas
3194 canvasContextMenu->popup(e->globalPos() );
3199 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3201 // Ignore right clicks, these will go to context menus
3202 if (e->button() == QMouseEvent::RightButton )
3208 // Finish open lineEdits
3209 if (lineedit) finishedLineEdit();
3211 QPoint p = inverseWorldMatrix().map(e->pos());
3212 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3216 //Take care of clickdesystem flags _or_ modifier modes
3218 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3219 typeid(*lmo)==typeid(MapCenterObj) ))
3221 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3222 if (!foname.isEmpty())
3224 // systemFlag clicked
3228 if (e->state() & QMouseEvent::ControlButton)
3229 mainWindow->editOpenURLTab();
3231 mainWindow->editOpenURL();
3233 else if (foname=="vymLink")
3235 mainWindow->editOpenVymLink();
3236 // tabWidget may change, better return now
3237 // before segfaulting...
3238 } else if (foname=="note")
3239 mainWindow->windowToggleNoteEditor();
3240 else if (foname=="hideInExport")
3245 // No system flag clicked, take care of modmodes
3247 // Special case: CTRL is pressed
3248 if (e->state() & QMouseEvent::ControlButton)
3250 if (actionModModeColor->isOn())
3253 setCursor (pickColorCursor);
3256 if (actionModModeLink->isOn())
3258 BranchObj *bo_begin=NULL;
3260 bo_begin=(BranchObj*)(lmo);
3263 ((typeid(*selection) == typeid(BranchObj)) ||
3264 (typeid(*selection) == typeid(MapCenterObj))) )
3265 bo_begin=(BranchObj*)selection;
3269 linkingObj_src=bo_begin;
3270 tmpXLink=new XLinkObj (mapCanvas);
3271 tmpXLink->setBegin (bo_begin);
3272 tmpXLink->setEnd (p);
3273 tmpXLink->setColor(defXLinkColor);
3274 tmpXLink->setWidth(defXLinkWidth);
3275 tmpXLink->updateXLink();
3276 tmpXLink->setVisibility (true);
3284 // Left Button Move Branches
3285 if (e->button() == QMouseEvent::LeftButton )
3287 movingObj_start.setX( p.x() - selection->x() );
3288 movingObj_start.setY( p.y() - selection->y() );
3289 movingObj_orgPos.setX (lmo->x() );
3290 movingObj_orgPos.setY (lmo->y() );
3292 // If modMode==copy, then we want to "move" the _new_ object around
3293 // then we need the offset from p to the _old_ selection, because of tmp
3294 if (actionModModeCopy->isOn() &&
3295 e->state() & QMouseEvent::ControlButton)
3297 if (typeid(*selection)==typeid(BranchObj) )
3300 mapCenter->addBranch ((BranchObj*)selection);
3302 selection=mapCenter->getLastBranch();
3303 selection->select();
3304 mapCenter->reposition();
3307 movingObj=selection;
3309 // Middle Button Toggle Scroll
3310 // (On Mac OS X this won't work, but we still have
3311 // a button in the toolbar)
3312 if (e->button() == QMouseEvent::MidButton )
3316 { // No MapObj found, we are on the Canvas itself
3317 // Left Button move Pos of CanvasView
3318 if (e->button() == QMouseEvent::LeftButton )
3320 movingObj=NULL; // move Content not Obj
3321 movingObj_start=e->globalPos();
3322 movingCont_start=QPoint (contentsX(), contentsY() );
3323 movingVec=QPoint(0,0);
3324 setCursor(handOpenCursor);
3329 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3331 QPoint p = inverseWorldMatrix().map(e->pos());
3333 // Move the selected MapObj
3334 if ( selection && movingObj)
3336 // To avoid jumping of the CanvasView, only
3337 // ensureSelectionVisible, if not tmp linked
3338 if (!selection->hasParObjTmp())
3339 ensureSelectionVisible ();
3341 // Now move the selection, but add relative position
3342 // (movingObj_start) where selection was chosen with
3343 // mousepointer. (This avoids flickering resp. jumping
3344 // of selection back to absPos)
3346 LinkableMapObj *lmosel;
3347 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3349 // Check if we could link
3350 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3353 if (typeid(*selection) == typeid(FloatImageObj))
3355 FloatObj *fo=(FloatObj*)selection;
3357 "move "+qpointToString(movingObj_orgPos),fo->getSelectString() ,
3358 QString("Move %1").arg(getName(selection)));
3359 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3363 // Relink float to new mapcenter or branch, if shift is pressed
3364 // Only relink, if selection really has a new parent
3365 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3366 ( (typeid(*lmo)==typeid(BranchObj)) ||
3367 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3368 ( lmo != fo->getParObj())
3371 if (typeid(*fo) == typeid(FloatImageObj))
3373 saveState(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3374 FloatImageObj *fio=(FloatImageObj*)(fo);
3375 ((BranchObj*)(lmo))->addFloatImage (fio);
3377 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3378 fio=((BranchObj*)(lmo))->getLastFloatImage();
3381 selection=(LinkableMapObj*)(fio);
3382 selection->select();
3383 movingObj=(MapObj*)(fio);
3386 } else // selection != a FloatObj
3388 if (lmosel->getDepth()==0)
3390 if (e->state() == (LeftButton | !ShiftButton))
3391 // If mapCenter is moved, move all the rest by default, too.
3392 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3394 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3397 if (lmosel->getDepth()==1)
3399 // depth==1, mainbranch
3400 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3404 if (lmosel->getOrientation() == OrientLeftOfCenter)
3405 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3406 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3407 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3409 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3411 // reposition subbranch
3412 lmosel->reposition();
3413 //ensureSelectionVisible();
3415 if (lmo && (lmo!=selection) &&
3416 (typeid(*lmo) == typeid(BranchObj) ||
3417 (typeid(*lmo) == typeid(MapCenterObj) )
3420 if (e->state() & QMouseEvent::ControlButton)
3422 // Special case: CTRL to link below lmo
3423 lmosel->setParObjTmp (lmo,p,+1);
3425 else if (e->state() & QMouseEvent::ShiftButton)
3426 lmosel->setParObjTmp (lmo,p,-1);
3428 lmosel->setParObjTmp (lmo,p,0);
3431 lmosel->unsetParObjTmp();
3435 } // no FloatImageObj
3439 } // selection && moving_obj
3441 // Draw a link from one branch to another
3444 tmpXLink->setEnd (p);
3445 tmpXLink->updateXLink();
3449 if (!movingObj && !pickingColor &&!drawingLink)
3451 QPoint p=e->globalPos();
3452 movingVec.setX(-p.x() + movingObj_start.x() );
3453 movingVec.setY(-p.y() + movingObj_start.y() );
3454 setContentsPos( movingCont_start.x() + movingVec.x(),
3455 movingCont_start.y() + movingVec.y());
3462 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3464 LinkableMapObj *dst;
3465 // Have we been picking color?
3469 setCursor (ArrowCursor);
3470 // Check if we are over another branch
3471 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3472 if (dst && selection)
3474 if (e->state() & QMouseEvent::ShiftButton)
3476 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3477 ((BranchObj*)selection)->setLinkColor ();
3481 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3482 ((BranchObj*)selection)->setLinkColor ();
3488 // Have we been drawing a link?
3492 // Check if we are over another branch
3493 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3494 if (dst && selection)
3496 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3497 tmpXLink->updateXLink();
3498 tmpXLink->activate();
3499 saveState(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3508 // Have we been moving something?
3509 if ( selection && movingObj )
3511 // Moved FloatObj? Maybe we need to reposition
3512 if(typeid(*selection)==typeid (FloatImageObj))
3514 selection->getParObj()->requestReposition();
3515 mapCenter->reposition();
3518 // Check if we are over another branch, but ignore
3519 // any found LMOs, which are FloatObjs
3520 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3521 ((LinkableMapObj*)selection) );
3523 if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj)))
3526 // Now check, if we have been moving a branch
3527 if (typeid(*selection) == typeid(BranchObj) )
3529 // save the position in case we link to mapcenter
3530 QPoint savePos=QPoint (selection->x(),selection->y() );
3532 // Reset the temporary drawn link to the original one
3533 ((LinkableMapObj*)selection)->unsetParObjTmp();
3539 BranchObj* bs=((BranchObj*)selection);
3540 QString undoCom="linkBranchToPos (\""+
3541 (bs->getParObj())->getSelectString()+
3543 QString("%1").arg(bs->getNum())+
3545 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3547 // TODO we also could check, if dest and src are on same branch,
3548 // then it would be sufficient to saveState of this branch
3550 // Modifiers allow to insert above/below dst
3551 if (e->state() & QMouseEvent::ShiftButton)
3553 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3555 if (e->state() & QMouseEvent::ControlButton)
3557 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3560 bs->moveBranchTo ((BranchObj*)(dst),-1);
3561 if (dst->getDepth()==0)
3564 saveState (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) );
3566 if (selection->getDepth()==1)
3567 // If we have moved mainbranch only save endposition
3568 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos)));
3570 // Draw the original link, before selection was moved around
3571 mapCenter->reposition();
3573 // Finally resize canvas, if needed
3578 // maybe we moved View: set old cursor
3579 setCursor (ArrowCursor);
3583 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3585 // Finish open lineEdits
3586 if (lineedit) finishedLineEdit();
3588 if (e->button() == QMouseEvent::LeftButton )
3590 QPoint p = inverseWorldMatrix().map(e->pos());
3591 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3592 if (lmo) { // MapObj was found
3593 // First select the MapObj than edit heading
3594 if (selection) selection->unselect();
3596 selection->select();
3602 void MapEditor::resizeEvent (QResizeEvent* e)
3604 QCanvasView::resizeEvent( e );
3608 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3611 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3612 // cerr << event->format(i) << endl;
3615 (typeid(*selection) == typeid(BranchObj)) ||
3616 (typeid(*selection) == typeid(MapCenterObj))) {
3618 // If QImageDrag can decode mime type
3619 if (QImageDrag::canDecode(event)) {
3624 // If image are dragged from firefox
3625 if (event->provides("application/x-moz-file-promise-url") &&
3626 event->provides("application/x-moz-nativeimage")) {
3627 event->accept(true);
3631 // If QUriDrag can decode mime type
3632 if (QUriDrag::canDecode(event)) {
3637 // If Uri are dragged from firefox
3638 if (event->provides("_NETSCAPE_URL")){
3643 // If QTextDrag can decode mime type
3644 if (QTextDrag::canDecode(event)) {
3653 bool isUnicode16(const QByteArray &d)
3655 // TODO: make more precise check for unicode 16.
3656 // Guess unicode16 if any of second bytes are zero
3657 unsigned int length = max(0,d.size()-2)/2;
3658 for (unsigned int i = 0; i<length ; i++)
3659 if (d.at(i*2+1)==0) return true;
3663 void MapEditor::contentsDropEvent(QDropEvent *event)
3666 (typeid(*selection) == typeid(BranchObj)) ||
3667 (typeid(*selection) == typeid(MapCenterObj)))
3672 if (event->provides("image/png"))
3675 if (QImageDrag::decode(event, pix))
3683 } else if (event->provides("application/x-moz-file-promise-url") &&
3684 event->provides("application/x-moz-nativeimage"))
3686 // Contains url to the img src in unicode16
3687 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3688 QString url = QString((const QChar*)d.data(),d.size()/2);
3692 } else if (event->provides ("text/uri-list"))
3693 { // Uris provided e.g. by konqueror
3694 QUriDrag::decode (event,uris);
3695 } else if (event->provides ("_NETSCAPE_URL"))
3696 { // Uris provided by Mozilla
3697 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3700 } else if (event->provides("text/html")) {
3702 // Handels text mime types
3703 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3704 QByteArray d = event->encodedData("text/html");
3707 text = QString((const QChar*)d.data(),d.size()/2);
3711 textEditor->setText(text);
3715 } else if (event->provides("text/plain")) {
3716 QByteArray d = event->encodedData("text/plain");
3719 text = QString((const QChar*)d.data(),d.size()/2);
3723 textEditor->setText(text);
3735 for (const char* u=uris.first(); u; u=uris.next())
3737 bo=((BranchObj*)selection)->addBranch();
3740 s=QUriDrag::uriToLocalFile(u);
3742 QString file = QDir::convertSeparators(s);
3743 heading = QFileInfo(file).baseName();
3745 if (file.endsWith(".vym", false))
3746 bo->setVymLink(file);
3755 bo->setHeading(heading);
3765 //FIXME saveState has to be called earlier for each of the drops...
3766 saveState("Drop Event"); //TODO undo Command
3767 mapCenter->reposition();
3774 void MapEditor::addFloatImage(const QPixmap &img)
3777 (typeid(*selection) == typeid(BranchObj)) ||
3778 (typeid(*selection) == typeid(MapCenterObj)) )
3780 BranchObj *bo=((BranchObj*)selection);
3781 saveState(selection,QString("Add floatimage to %1").arg(getName(bo)));
3782 //QString fn=fd->selectedFile();
3783 //lastImageDir=fn.left(fn.findRev ("/"));
3784 bo->addFloatImage();
3785 // FIXME check if load was successful
3786 bo->getLastFloatImage()->load(img);
3787 //bo->getLastFloatImage()->setOriginalFilename(fn);
3788 mapCenter->reposition();
3795 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3797 if (!imageBuffer) imageBuffer = new QBuffer();
3798 if (!imageBuffer->isOpen()) {
3799 imageBuffer->open(IO_WriteOnly | IO_Append);
3801 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3805 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3807 if (nop->state()==QNetworkProtocol::StDone) {
3808 QPixmap img(imageBuffer->buffer());
3813 imageBuffer->close();
3815 imageBuffer->close();
3822 void MapEditor::fetchImage(const QString &url)
3825 urlOperator->stop();
3826 disconnect(urlOperator);
3830 urlOperator = new QUrlOperator(url);
3831 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3832 this, SLOT(imageDataFinished(QNetworkOperation*)));
3834 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3835 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));