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"
42 extern TextEditor *textEditor;
43 extern int statusbarTime;
44 extern Main *mainWindow;
45 extern QString tmpVymDir;
46 extern QString clipboardDir;
47 extern bool clipboardEmpty;
48 extern FlagRowObj *systemFlagsDefault;
49 extern FlagRowObj *standardFlagsDefault;
51 extern QPtrList <QAction> actionListBranches;
53 extern QAction *actionFileSave;
54 extern QAction *actionEditUndo;
55 extern QAction *actionEditCopy;
56 extern QAction *actionEditCut;
57 extern QAction *actionEditPaste;
58 extern QAction *actionEditMoveUp;
59 extern QAction *actionEditMoveDown;
60 extern QAction *actionEditToggleScroll;
61 extern QAction *actionEditOpenURL;
62 extern QAction *actionEditOpenURLTab;
63 extern QAction *actionEditURL;
64 extern QAction *actionEditHeading2URL;
65 extern QAction *actionEditBugzilla2URL;
66 extern QAction *actionEditFATE2URL;
67 extern QAction *actionEditOpenVymLink;
68 extern QAction *actionEditVymLink;
69 extern QAction *actionEditDeleteVymLink;
70 extern QAction *actionEditToggleHideExport;
71 extern QAction *actionEditHeading;
72 extern QAction *actionEditDelete;
73 extern QAction *actionEditAddBranch;
74 extern QAction *actionEditAddBranchAbove;
75 extern QAction *actionEditAddBranchBelow;
76 extern QAction *actionEditRemoveBranchHere;
77 extern QAction *actionEditRemoveChilds;
78 extern QAction *actionEditImportAdd;
79 extern QAction *actionEditImportReplace;
80 extern QAction *actionEditSaveBranch;
81 extern QAction *actionEditSelectFirst;
82 extern QAction *actionEditSelectLast;
83 extern QAction *actionEditLoadImage;
85 extern QAction* actionFormatPickColor;
86 extern QAction* actionFormatColorBranch;
87 extern QAction* actionFormatColorSubtree;
88 extern QAction *actionFormatLinkColorHint;
89 extern QAction *actionFormatBackColor;
90 extern QAction *actionFormatLinkColor;
92 extern QActionGroup* actionGroupModModes;
93 extern QAction* actionModModeColor;
94 extern QAction* actionModModeLink;
95 extern QAction* actionModModeCopy;
97 extern QActionGroup *actionGroupFormatFrameTypes;
98 extern QAction *actionFormatFrameNone;
99 extern QAction *actionFormatFrameRectangle;
101 extern QActionGroup *actionGroupFormatLinkStyles;
102 extern QAction *actionFormatIncludeImagesVer;
103 extern QAction *actionFormatIncludeImagesHor;
104 extern QAction *actionFormatHideLinkUnselected;
105 extern QAction *actionFormatLinkStyleLine;
106 extern QAction *actionFormatLinkStyleParabel;
107 extern QAction *actionFormatLinkStylePolyLine;
108 extern QAction *actionFormatLinkStylePolyParabel;
110 extern QAction *actionViewToggleNoteEditor;
112 extern QAction *actionSettingsAutoedit;
113 extern QAction *actionSettingsAutoselectHeading;
114 extern QAction *actionSettingsAutoselectText;
115 extern QAction *actionSettingsPasteNewHeading;
116 extern QAction *actionSettingsUseFlagGroups;
118 extern QPopupMenu *branchContextMenu;
119 extern QPopupMenu *branchLinksContextMenu;
120 extern QPopupMenu *branchLinksContextMenuDup;
121 extern QPopupMenu *floatimageContextMenu;
122 extern QPopupMenu *saveImageFormatMenu;
123 extern QPopupMenu *exportImageFormatMenu;
124 extern QPopupMenu *canvasContextMenu;
126 extern Settings settings;
128 extern QString iconPath;
130 int MapEditor::mapNum=0; // make instance
132 ///////////////////////////////////////////////////////////////////////
133 ///////////////////////////////////////////////////////////////////////
134 MapEditor::MapEditor(
135 QWidget* parent, bool interactive, const char* name, WFlags f) :
136 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
138 //cout << "Constructor ME "<<this<<endl;
141 viewport()->setAcceptDrops(true);
143 mapCanvas = new QCanvas(1000,800);
144 mapCanvas->setAdvancePeriod(30);
145 mapCanvas->setBackgroundColor (white);
147 setCanvas (mapCanvas);
149 // Always show scroll bars (automatic would flicker sometimes)
150 setVScrollBarMode ( QScrollView::AlwaysOn );
151 setHScrollBarMode ( QScrollView::AlwaysOn );
153 mapCenter = new MapCenterObj(mapCanvas);
154 mapCenter->setVisibility (true);
155 mapCenter->setMapEditor (this);
156 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
157 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
161 lineedit = new QLineEdit(this, "lineedit" );
162 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEdit() ) );
165 actColor=black; setColor (actColor);
166 defLinkColor=QColor (0,0,255);
167 defXLinkColor=QColor (180,180,180);
168 linkcolorhint=DefaultColor;
169 linkstyle=StylePolyParabel;
171 // Create bitmap cursors, patform dependant
172 #if defined(Q_OS_MACX)
173 handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png") );
174 // set hot spot to tip of picker
175 pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 );
177 handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen16.png"));
178 // set hot spot to tip of picker
179 pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 );
192 defXLinkColor=QColor (230,230,230);
200 fileName=tr("unnamed");
203 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
207 // Initialize find routine
214 blockReposition=false;
215 blockSaveState=false;
219 isInteractive=interactive;
221 // Create temporary files
224 // Initially set movingCentre
227 // For testing purposes create history window
228 historyWindow = new ShowTextDialog (this);
229 historyWindow->setCaption (fileName);
231 mapCenter->reposition(); // for positioning heading
234 MapEditor::~MapEditor()
236 if (imageBuffer) delete imageBuffer;
242 //cout <<"Destructor MapEditor\n";
245 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
249 QColor MapEditor::color()
254 QColor MapEditor::backgroundColor()
256 return mapCanvas->backgroundColor();
259 MapCenterObj* MapEditor::getMapCenter()
264 QCanvas* MapEditor::getCanvas()
269 void MapEditor::adjustCanvasSize()
271 // To adjust the canvas to map, viewport size and position, we have to
272 // do some coordinate magic...
274 // Get rectangle of (scroll-)view.
275 // We want to be in canvas coords, so
276 // we map. Important if view is zoomed...
277 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
278 visibleWidth(), visibleHeight()) );
280 // Now we need the bounding box of view AND map to calc the correct canvas size.
281 // Why? Because if the map itself is moved out of view, the view has to be enlarged
282 // to avoid jumping aroung...
283 QRect map=mapCenter->getTotalBBox();
285 // right edge - left edge
286 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
287 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
290 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
291 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
294 // move the map on canvas (in order to not move it on screen) this is neccessary
295 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
296 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
297 // to scroll to an empty area of canvas to the left.
298 // b) if topleft corner of map left of or above topleft of canvas
302 if (cw > mapCanvas->width() )
304 if (map.x()<0) dx=-map.x();
306 if (cw < mapCanvas->width() )
307 dx=-min (view.x(),map.x());
308 if (ch > mapCanvas->height() )
310 if (map.y()<0) dy=-map.y();
312 if (ch < mapCanvas->height() )
314 dy=-min (view.y(),map.y());
316 // We really have to resize now. Let's go...
317 mapCanvas->resize (cw,ch);
318 if ( (dx!=0) || (dy!=0) )
320 mapCenter->moveAllBy(dx,dy);
321 mapCenter->reposition();
323 // scroll the view (in order to not move map on screen)
329 bool MapEditor::isRepositionBlocked()
331 return blockReposition;
334 QString MapEditor::getName (LinkableMapObj *lmo)
336 if (!lmo) return QString("NULL has no name!");
338 if ((typeid(*lmo) == typeid(BranchObj) ||
339 typeid(*lmo) == typeid(MapCenterObj)))
340 return QString("branch (%1)").arg(((BranchObj*)lmo)->getHeading());
341 if ((typeid(*lmo) == typeid(FloatImageObj) ))
342 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
343 return QString("Unknown type has no name!");
346 void MapEditor::makeTmpDirs()
348 // Create unique temporary directories
349 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
351 d.mkdir (tmpMapDir,true);
354 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
356 // tmpdir temporary directory to which data will be written
357 // prefix mapname, which will be appended to images etc.
358 // writeflags Only write flags for "real" save of map, not undo
359 // offset offset of bbox of whole map in canvas.
360 // Needed for XML export
376 ls="StylePolyParabel";
380 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
382 if (linkcolorhint==HeadingColor)
383 colhint=attribut("linkColorHint","HeadingColor");
385 QString mapAttr=attribut("version",__VYM_VERSION);
387 mapAttr+= attribut("author",mapCenter->getAuthor()) +
388 attribut("comment",mapCenter->getComment()) +
389 attribut("date",mapCenter->getDate()) +
390 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
391 attribut("linkStyle", ls ) +
392 attribut("linkColor", defLinkColor.name() ) +
393 attribut("defXLinkColor", defXLinkColor.name() ) +
394 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
396 s+=beginElement("vymmap",mapAttr);
399 // Find the used flags while traversing the tree
400 standardFlagsDefault->resetUsedCounter();
402 // Reset the counters before saving
403 FloatImageObj (mapCanvas).resetSaveCounter();
405 // Build xml recursivly
407 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
410 if ( typeid(*saveSelection) == typeid(BranchObj) )
411 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
412 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
413 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
415 else if (selection && typeid(*selection)==typeid(BranchObj))
416 // This is used if selected branch is saved from mainwindow
417 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
420 // Save local settings
421 s+=settings.getXMLData (destPath);
424 if (selection && !saveSelection )
425 s+=valueElement("select",selection->getSelectString());
428 s+=endElement("vymmap");
431 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
435 void MapEditor::saveState(const QString &comment)
438 saveState (CompleteMap,"",NULL,"",NULL, comment);
441 void MapEditor::saveState(LinkableMapObj *undoSel, const QString &comment)
443 // save the given part of the map
444 saveState (PartOfMap,"",undoSel,"",NULL, comment);
447 void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment)
449 // selection does not change during action,
450 // so just save commands for undo and redo
451 LinkableMapObj *unsel;
456 saveState (UndoCommand,uc,unsel,rc,unsel, comment);
459 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel, const QString &comment)
461 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL, comment);
464 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel, const QString &comment)
468 if (blockSaveState) return;
470 /* TODO remove after testing
471 cout << "ME::saveState() begin\n"<<endl;
472 cout << " undosTotal="<<undosTotal<<endl;
473 cout << " undosAvail="<<undosAvail<<endl;
474 cout << " undoNum="<<undoNum<<endl;
475 cout << " ---------------------------"<<endl;
478 historyWindow->append (comment);
482 // Find out current undo directory
483 if (undosAvail<undosTotal) undosAvail++;
485 if (undoNum>undosTotal) undoNum=1;
488 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
489 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
491 // Create bakMapDir if not available
494 makeSubDirs (bakMapDir);
496 // Save current selection
497 QString redoSelection="";
499 redoSelection=redoSel->getSelectString();
501 // Save the object, which should be undone
502 QString undoSelection="";
504 undoSelection=undoSel->getSelectString();
506 // Save depending on how much needs to be saved
507 QString undoCommand="";
508 if (savemode==UndoCommand)
513 else if (savemode==PartOfMap && undoSel)
515 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
516 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
519 undoCommand="undoMap (\""+bakMapPath+"\")";
520 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
523 if (!backupXML.isEmpty())
524 // Write XML Data to disk
525 saveStringToDisk (QString(bakMapPath),backupXML);
528 set.setEntry (QString("undoCommand"),undoCommand);
529 set.setEntry (QString("undoSelection"),undoSelection);
530 set.setEntry (QString("redoCommand"),redoCom);
531 set.setEntry (QString("redoSelection"),redoSelection);
532 set.setEntry (QString("comment"),comment);
533 set.writeSettings(QString(bakMapDir+"/commands"));
535 /* TODO remove after testing
536 cout << " into="<< bakMapDir<<endl;
537 cout << " undosAvail="<<undosAvail<<endl;
538 cout << " undoNum="<<undoNum<<endl;
539 cout << " ---------------------------"<<endl;
540 cout << " comment="<<comment<<endl;
541 cout << " ---------------------------"<<endl;
542 cout << " undoCom="<<undoCommand<<endl;
543 cout << " undoSel="<<undoSelection<<endl;
544 cout << " ---------------------------"<<endl;
545 cout << " redoCom="<<redoCom<<endl;
546 cout << " redoSel="<<redoSelection<<endl;
547 cout << " ---------------------------"<<endl<<endl;
551 void MapEditor::parseAtom(const QString &atom)
558 // Split string s into command and parameters
559 api.parseCommand (atom);
560 QString com=api.command();
563 if (com=="moveBranchUp")
565 else if (com=="moveBranchDown")
567 else if (com=="move")
569 if (api.checkParamCount(2) && selection )
579 else if (com=="linkBranchToPos")
581 if (selection && typeid(*selection) == typeid(BranchObj) )
583 if (api.checkParamCount(4))
585 s=api.parString(ok,0);
586 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
589 if (typeid(*dst) == typeid(BranchObj) )
591 // Get number in parent
594 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
595 } else if (typeid(*dst) == typeid(MapCenterObj) )
597 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
598 // Get coordinates of mainbranch
603 if (ok) ((BranchObj*)selection)->move (x,y);
609 } else if (com=="setHeading")
611 if (api.checkParamCount(1))
613 s=api.parString (ok,0);
614 if (ok) setHeading (s);
616 } else if (com=="setURL")
618 if (api.checkParamCount(1))
620 s=api.parString (ok,0);
623 } else if (com=="setVymLink")
625 if (api.checkParamCount(1))
627 s=api.parString (ok,0);
628 if (ok) setVymLink(s);
631 // Internal commands, used for undo etc.
632 else if (com==QString("undoMap"))
634 if (api.checkParamCount(1))
635 undoXML("",api.parString (ok,0));
636 } else if (com==QString("undoPart"))
638 if (api.checkParamCount(2))
640 s=api.parString (ok,0);
641 t=api.parString (ok,1);
644 } else if (com=="select")
645 if (api.checkParamCount(1))
647 s=api.parString(ok,0);
652 api.setError ("Unknown command in: "+atom);
653 cout << "ME::parse api should have error now...\n";
659 cout << "MapEditor::parseAtom: Error!\n";
660 cout << " "<<api.errorDesc()<<endl;
665 void MapEditor::finishedLineEdit()
667 // This is called by finishedLineEdit or any MapEditor method,
668 // which wants to assure, that lineedits finish, before e.g. a branch is
671 // After calling LineEdit and using the clipboard, the
672 // focus is not any longer on the main widget, we
673 // have to restore it using parentWidget()->setFocus()
677 saveState("setHeading (\""+editingBO->getHeading()+"\")",editingBO, QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(lineedit->text()) );
678 editingBO->setHeading(lineedit->text() );
680 lineedit->releaseKeyboard();
682 parentWidget()->setFocus();
683 mapCenter->reposition();
685 ensureSelectionVisible();
689 void MapEditor::toggleHistoryWindow()
691 if (historyWindow->isVisible())
692 historyWindow->hide();
694 historyWindow->show();
698 bool MapEditor::isDefault()
703 bool MapEditor::isUnsaved()
708 bool MapEditor::hasChanged()
713 void MapEditor::setChanged()
718 actionEditUndo->setEnabled (true);
719 actionFileSave->setEnabled (true);
723 void MapEditor::closeMap()
725 // Finish open lineEdits
726 if (lineedit) finishedLineEdit();
728 // Unselect before disabling the toolbar actions
729 if (selection) selection->unselect();
737 void MapEditor::setFilePath(QString fname)
739 setFilePath (fname,fname);
742 void MapEditor::setFilePath(QString fname, QString destname)
744 if (fname.isEmpty() || fname=="")
751 filePath=fname; // becomes absolute path
752 fileName=fname; // gets stripped of path
753 destPath=destname; // needed for vymlinks
755 // If fname is not an absolute path, complete it
756 filePath=QDir(fname).absPath();
757 fileDir=filePath.left (1+filePath.findRev ("/"));
759 // Set short name, too. Search from behind:
760 int i=fileName.findRev("/");
761 if (i>=0) fileName=fileName.remove (0,i+1);
763 // Forget the .vym (or .xml) for name of map
764 mapName=fileName.left(fileName.findRev(".",-1,true) );
766 // Adjust history window
767 historyWindow->setCaption (fileName);
771 QString MapEditor::getFilePath()
776 QString MapEditor::getFileName()
781 QString MapEditor::getMapName()
786 QString MapEditor::getDestPath()
791 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
793 // Finish open lineEdits
794 if (lineedit) finishedLineEdit();
796 ErrorCode err=success;
800 if (selection) selection->unselect();
803 mapCenter->setMapEditor(this);
804 // (map state is set later at end of load...)
807 saveState(selection,"Load map");
811 mapBuilderHandler handler;
814 // I am paranoid: file should exist anyway
815 // according to check in mainwindow.
818 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
819 tr("Couldn't open map " +fname)+".");
823 blockReposition=true;
824 QXmlInputSource source( file);
825 QXmlSimpleReader reader;
826 reader.setContentHandler( &handler );
827 reader.setErrorHandler( &handler );
828 handler.setMapEditor( this );
829 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
830 handler.setInputFile (file.name());
831 handler.setLoadMode (lmode);
833 bool ok = reader.parse( source );
834 blockReposition=false;
835 blockSaveState=false;
839 mapCenter->reposition();
849 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
850 tr( handler.errorProtocol() ) );
852 // Still return "success": the map maybe at least
853 // partially read by the parser
860 int MapEditor::save (const SaveMode &savemode)
862 // Finish open lineEdits
863 if (lineedit) finishedLineEdit();
867 // The SaveMode UndoCommand is not supported here
868 if (savemode==UndoCommand) return 1;
870 // Create mapName and fileDir
871 makeSubDirs (fileDir);
875 fname=mapName+".xml";
877 // use name given by user, even if he chooses .doc
882 if (savemode==CompleteMap || selection==NULL)
883 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
885 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
887 if (!saveStringToDisk(fileDir+fname,saveFile))
894 actionFileSave->setEnabled(false);
900 void MapEditor::setZipped (bool z)
905 bool MapEditor::saveZipped ()
910 void MapEditor::print()
912 // Finish open lineEdits
913 if (lineedit) finishedLineEdit();
917 printer = new QPrinter;
918 printer->setColorMode (QPrinter::Color);
919 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
922 QRect totalBBox=mapCenter->getTotalBBox();
924 // Try to set orientation automagically
925 // Note: Interpretation of generated postscript is amibiguous, if
926 // there are problems with landscape mode, see
927 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
929 if (totalBBox.width()>totalBBox.height())
930 // recommend landscape
931 printer->setOrientation (QPrinter::Landscape);
933 // recommend portrait
934 printer->setOrientation (QPrinter::Portrait);
936 if ( printer->setup(this) )
937 // returns false, if printing is canceled
939 QPainter pp(printer);
941 // Don't print the visualisation of selection
942 LinkableMapObj *oldselection=NULL;
945 oldselection=selection;
946 selection->unselect();
949 // Handle sizes of map and paper:
951 // setWindow defines which part of the canvas will be transformed
952 // setViewport defines area on paper in device coordinates (dpi)
953 // e.g. (0,50,700,700) is upper part on A4
954 // see also /usr/lib/qt3/doc/html/coordsys.html
956 QPaintDeviceMetrics metrics (printer);
958 double paperAspect = (double)metrics.width() / (double)metrics.height();
959 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
961 QRect mapRect=totalBBox;
962 QCanvasRectangle *frame=NULL;
963 QCanvasText *footerFN=NULL;
964 QCanvasText *footerDate=NULL;
965 if (printFrame || printFooter)
970 // Print frame around map
971 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
972 totalBBox.width()+20, totalBBox.height()+20);
973 frame=new QCanvasRectangle (mapRect,mapCanvas);
974 frame->setBrush (QColor(white));
975 frame->setPen (QColor(black));
979 /* TODO remove after testing
980 QCanvasLine *l=new QCanvasLine (mapCanvas);
981 l->setPoints (0,0,mapRect.width(),mapRect.height());
982 l->setPen (QPen(QColor(black), 1));
989 // Print footer below map
991 font.setPointSize(10);
992 footerFN=new QCanvasText (mapCanvas);
993 footerFN->setText ("VYM - " + fileName);
994 footerFN->setFont(font);
995 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
996 footerFN->setZ(Z_TEXT);
998 footerDate=new QCanvasText (mapCanvas);
999 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
1000 footerDate->setFont(font);
1001 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
1002 footerDate->setZ(Z_TEXT);
1005 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
1008 pp.setWindow (mapRect);
1011 if (mapAspect>=paperAspect)
1013 // Fit horizontally to paper width
1014 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
1017 // Fit vertically to paper height
1018 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
1021 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
1023 // Delete Frame and footer
1027 delete (footerDate);
1029 if (frame) delete (frame);
1031 // Restore selection
1034 selection=oldselection;
1035 selection->select();
1038 // Save settings in vymrc
1039 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1043 QPixmap MapEditor::getPixmap()
1045 QRect mapRect=mapCenter->getTotalBBox();
1046 QPixmap pix (mapRect.size());
1049 // Don't print the visualisation of selection
1050 LinkableMapObj *oldselection=NULL;
1053 oldselection=selection;
1054 selection->unselect();
1057 pp.setWindow (mapRect);
1059 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1062 // Restore selection
1065 selection=oldselection;
1066 selection->select();
1072 void MapEditor::setHideTmpMode (HideTmpMode mode)
1075 mapCenter->setHideTmp (hidemode);
1076 mapCenter->reposition();
1081 HideTmpMode MapEditor::getHideTmpMode()
1086 void MapEditor::exportImage(QString fn)
1088 // Finish open lineEdits
1089 if (lineedit) finishedLineEdit();
1091 setExportMode (true);
1092 QPixmap pix (getPixmap());
1093 pix.save(fn, "PNG");
1094 setExportMode (false);
1097 void MapEditor::setExportMode (bool b)
1099 // should be called before and after exports
1100 // depending on the settings
1101 if (b && settings.readEntry("/vym/export/useHideExport","yes"))
1102 setHideTmpMode (HideExport);
1104 setHideTmpMode (HideNone);
1107 void MapEditor::exportImage(QString fn, int item)
1109 // Finish open lineEdits
1110 if (lineedit) finishedLineEdit();
1112 setExportMode (true);
1113 QPixmap pix (getPixmap());
1114 pix.save(fn, exportImageFormatMenu->text(item) );
1115 setExportMode (false);
1118 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1122 ex.setMapCenter(mapCenter);
1123 if (ex.setConfigFile(cf))
1125 setExportMode (true);
1126 ex.exportPresentation();
1127 setExportMode (false);
1133 void MapEditor::exportXML(const QString &dir)
1135 // Hide stuff during export, if settings want this
1136 setExportMode (true);
1138 // Create subdirectories
1141 // write to directory
1142 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1145 file.setName ( dir + "/"+mapName+".xml");
1146 if ( !file.open( IO_WriteOnly ) )
1148 // This should neverever happen
1149 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1153 // Write it finally, and write in UTF8, no matter what
1154 QTextStream ts( &file );
1155 ts.setEncoding (QTextStream::UnicodeUTF8);
1159 // Now write image, too
1160 exportImage (dir+"/images/"+mapName+".png");
1162 setExportMode (false);
1165 void MapEditor::clear()
1169 selection->unselect();
1176 void MapEditor::copy()
1178 // Finish open lineEdits
1179 if (lineedit) finishedLineEdit();
1183 // write to directory
1184 QString clipfile="part";
1185 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1188 file.setName ( clipboardDir + "/"+clipfile+".xml");
1189 if ( !file.open( IO_WriteOnly ) )
1191 // This should neverever happen
1192 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1196 // Write it finally, and write in UTF8, no matter what
1197 QTextStream ts( &file );
1198 ts.setEncoding (QTextStream::UnicodeUTF8);
1202 clipboardEmpty=false;
1207 void MapEditor::redo()
1209 // Finish open lineEdits
1210 if (lineedit) finishedLineEdit();
1212 blockSaveState=true;
1214 // Find out current undo directory
1215 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1217 // Restore variables
1218 QString undoCommand;
1219 QString undoSelection;
1220 QString redoCommand;
1221 QString redoSelection;
1223 set.readSettings(QString(bakMapDir+"/commands"));
1224 undoCommand=set.readEntry ("undoCommand");
1225 undoSelection=set.readEntry ("undoSelection");
1226 redoCommand=set.readEntry ("redoCommand");
1227 redoSelection=set.readEntry ("redoSelection");
1229 // select object before redo
1230 if (!redoSelection.isEmpty())
1231 select (redoSelection);
1233 /* TODO remove testing
1234 cout << "ME::redo() begin\n";
1235 cout << " undosTotal="<<undosTotal<<endl;
1236 cout << " undosAvail="<<undosAvail<<endl;
1237 cout << " undoNum="<<undoNum<<endl;
1238 cout << " ---------------------------"<<endl;
1239 cout << " undoCom="<<undoCommand<<endl;
1240 cout << " undoSel="<<undoSelection<<endl;
1241 cout << " ---------------------------"<<endl;
1242 cout << " redoCom="<<redoCommand<<endl;
1243 cout << " redoSel="<<redoSelection<<endl;
1244 cout << " ---------------------------"<<endl;
1246 parseAtom (undoCommand);
1247 mapCenter->reposition();
1249 //if (!redoSelection.isEmpty())
1250 // select (redoSelection);
1254 // Undo not longer available now
1255 actionEditUndo->setEnabled (false);
1257 undoNum--; if (undoNum<1) undoNum=undosTotal;
1259 blockSaveState=false;
1260 /* TODO remove testing
1261 cout << "ME::redo() end\n";
1262 cout << " undosAvail="<<undosAvail<<endl;
1263 cout << " undoNum="<<undoNum<<endl;
1264 cout << " ---------------------------"<<endl<<endl;
1268 void MapEditor::undo()
1270 // Finish open lineEdits
1271 if (lineedit) finishedLineEdit();
1273 blockSaveState=true;
1275 // Find out current undo directory
1276 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1278 // Restore variables
1279 QString undoCommand;
1280 QString undoSelection;
1281 QString redoCommand;
1282 QString redoSelection;
1284 set.readSettings(QString(bakMapDir+"/commands"));
1285 undoCommand= set.readEntry ("undoCommand");
1286 undoSelection=set.readEntry ("undoSelection");
1287 redoCommand= set.readEntry ("redoCommand");
1288 redoSelection=set.readEntry ("redoSelection");
1290 // select object before undo
1291 if (!undoSelection.isEmpty())
1292 select (undoSelection);
1295 cout << "ME::undo() begin\n";
1296 cout << " undosTotal="<<undosTotal<<endl;
1297 cout << " undosAvail="<<undosAvail<<endl;
1298 cout << " undoNum="<<undoNum<<endl;
1299 cout << " ---------------------------"<<endl;
1300 cout << " undoCom="<<undoCommand<<endl;
1301 cout << " undoSel="<<undoSelection<<endl;
1302 cout << " ---------------------------"<<endl;
1303 cout << " redoCom="<<redoCommand<<endl;
1304 cout << " redoSel="<<redoSelection<<endl;
1305 cout << " ---------------------------"<<endl;
1307 parseAtom (undoCommand);
1308 mapCenter->reposition();
1310 //if (!redoSelection.isEmpty())
1311 // select (redoSelection);
1315 // Undo not longer available now
1316 actionEditUndo->setEnabled (false);
1318 undoNum--; if (undoNum<1) undoNum=undosTotal;
1320 blockSaveState=false;
1321 /* TODO remove testing
1322 cout << "ME::undo() end\n";
1323 cout << " undosAvail="<<undosAvail<<endl;
1324 cout << " undoNum="<<undoNum<<endl;
1325 cout << " ---------------------------"<<endl<<endl;
1329 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1331 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1333 QFile file (bakMapPath);
1337 // We need to parse saved XML data
1338 mapBuilderHandler handler;
1339 QXmlInputSource source( file);
1340 QXmlSimpleReader reader;
1341 reader.setContentHandler( &handler );
1342 reader.setErrorHandler( &handler );
1343 handler.setMapEditor( this );
1344 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1345 if (undoSel.isEmpty())
1349 handler.setLoadMode (NewMap);
1353 handler.setLoadMode (ImportReplace);
1355 blockReposition=true;
1356 bool ok = reader.parse( source );
1357 blockReposition=false;
1360 // This should never ever happen
1361 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1362 tr( handler.errorProtocol() )+" in "+bakMapDir );
1366 QMessageBox::critical( 0, tr( "Critical Error" ),
1367 tr("Temporary directory %1 used for undo is gone. \n"
1368 "I will create a new one, but at the moment no undo is available.\n"
1369 "Maybe you want to reload your original data.\n\n"
1370 "Sorry for any inconveniences.").arg(bakMapDir) );
1375 void MapEditor::pasteNoSave()
1377 // Finish open lineEdits
1378 if (lineedit) finishedLineEdit();
1380 load (clipboardDir+"/part.xml",ImportAdd);
1383 void MapEditor::cutNoSave()
1389 void MapEditor::paste()
1391 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1392 typeid(*selection) == typeid(MapCenterObj)))
1394 saveState(selection,QString("Paste to %1").arg( getName(selection)));
1396 mapCenter->reposition();
1401 void MapEditor::cut()
1403 saveState(selection->getParObj(),QString("Cut %1").arg(getName(selection)));
1406 mapCenter->reposition();
1410 void MapEditor::move(const int &x, const int &y)
1412 // TODO no saveState, because this is only internal at undo so far
1413 if (selection) selection->move(x,y);
1414 if (typeid(*selection) == typeid(FloatImageObj))
1415 ((FloatImageObj*)selection)->setRelPos();
1418 void MapEditor::moveBranchUp()
1420 // Finish open lineEdits
1421 if (lineedit) finishedLineEdit();
1425 if (typeid(*selection) == typeid(BranchObj) )
1427 bo=(BranchObj*)selection;
1428 par=(BranchObj*)(bo->getParObj());
1429 selection->unselect();
1430 selection=par->moveBranchUp (bo);
1431 selection->select();
1432 saveState("moveBranchDown ()",bo,QString("Move up %1").arg(getName(bo)));
1433 mapCenter->reposition();
1434 ensureSelectionVisible();
1438 void MapEditor::moveBranchDown()
1440 // Finish open lineEdits
1441 if (lineedit) finishedLineEdit();
1445 if (typeid(*selection) == typeid(BranchObj) )
1447 bo=(BranchObj*)selection;
1448 par=(BranchObj*)(bo->getParObj());
1449 selection->unselect();
1450 selection=par->moveBranchDown(bo);
1451 selection->select();
1452 saveState("moveBranchUp ()",bo,QString("Move down %1").arg(getName(bo)));
1453 mapCenter->reposition();
1454 ensureSelectionVisible();
1458 void MapEditor::editHeading()
1460 // Finish open lineEdits
1461 if (lineedit) finishedLineEdit();
1464 (typeid(*selection) == typeid(BranchObj) ||
1465 typeid(*selection) == typeid(MapCenterObj) ) )
1467 editingBO=(BranchObj*)selection;
1469 ensureSelectionVisible();
1470 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1471 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1472 QString s=editingBO->getHeading();
1473 lineedit->setText(s);
1474 lineedit->setCursorPosition(1);
1475 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1476 lineedit->selectAll();
1478 lineedit->grabKeyboard();
1479 lineedit->setFocus();
1483 void MapEditor::setHeading(const QString &s)
1485 // Internal function, no saveState needed
1487 (typeid(*selection) == typeid(BranchObj) ||
1488 typeid(*selection) == typeid(MapCenterObj) ) )
1490 ((BranchObj*)selection)->setHeading(s);
1491 mapCenter->reposition();
1493 ensureSelectionVisible();
1497 void MapEditor::setURL (const QString &s)
1499 // Internal function, no saveState needed
1501 (typeid(*selection) == typeid(BranchObj) ||
1502 typeid(*selection) == typeid(MapCenterObj) ) )
1504 ((BranchObj*)selection)->setURL(s);
1505 mapCenter->reposition();
1507 ensureSelectionVisible();
1511 void MapEditor::setVymLink (const QString &s)
1513 // Internal function, no saveState needed
1515 (typeid(*selection) == typeid(BranchObj) ||
1516 typeid(*selection) == typeid(MapCenterObj) ) )
1518 ((BranchObj*)selection)->setVymLink(s);
1519 mapCenter->reposition();
1521 ensureSelectionVisible();
1525 void MapEditor::addNewBranch(int pos)
1527 // Finish open lineEdits
1528 if (lineedit) finishedLineEdit();
1531 (typeid(*selection) == typeid(BranchObj) ||
1532 typeid(*selection) == typeid(MapCenterObj) ) )
1534 BranchObj* bo1 = (BranchObj*) selection;
1535 saveState(selection, QString("Add new branch to %1").arg(getName(bo1))); //TODO undoCommand
1537 bool wasScrolled=false;
1538 BranchObj *newbo=NULL;
1541 // save scroll state. If scrolled, automatically select
1542 // new branch in order to tmp unscroll parent...
1543 wasScrolled=bo1->isScrolled();
1544 newbo=bo1->addBranch();
1547 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1551 // add above selection
1552 newbo=parbo->insertBranch(bo1->getNum());
1554 // add below selection
1555 newbo=parbo->insertBranch(bo1->getNum()+1);
1557 // This should not happen...
1562 LinkableMapObj *oldselection=selection;
1564 mapCenter->reposition();
1566 if (actionSettingsAutoedit->isOn() ||
1567 actionSettingsAutoselectHeading->isOn() )
1569 selection->unselect();
1571 selection->select();
1572 if (actionSettingsPasteNewHeading->isOn() )
1574 BranchObj *bo2= (BranchObj*)selection;
1575 bo2->setHeading("");
1577 if (actionSettingsAutoedit->isOn() )
1579 if (!actionSettingsAutoselectHeading->isOn()
1582 selection->unselect();
1583 selection=oldselection;
1584 selection->select();
1591 void MapEditor::addNewBranchHere()
1593 // Finish open lineEdits
1594 if (lineedit) finishedLineEdit();
1597 (typeid(*selection) == typeid(BranchObj) ) )
1599 BranchObj* bo1 = (BranchObj*) selection;
1600 saveState(selection, QString("Add new branch here").arg(getName(bo1)));
1602 bool wasScrolled=false;
1603 BranchObj *newbo=NULL;
1604 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1607 // add below selection
1608 newbo=parbo->insertBranch(bo1->getNum()+1);
1611 LinkableMapObj *oldselection=selection;
1612 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1614 mapCenter->reposition();
1616 if (actionSettingsAutoedit->isOn() ||
1617 actionSettingsAutoselectHeading->isOn() )
1619 selection->unselect();
1621 selection->select();
1622 if (actionSettingsPasteNewHeading->isOn() )
1624 BranchObj *bo2= (BranchObj*)selection;
1625 bo2->setHeading("");
1627 if (actionSettingsAutoedit->isOn() )
1629 if (!actionSettingsAutoselectHeading->isOn()
1632 selection->unselect();
1633 selection=oldselection;
1634 selection->select();
1640 void MapEditor::deleteSelection()
1642 // Finish open lineEdits
1643 if (lineedit) finishedLineEdit();
1645 if (selection && typeid(*selection) ==typeid(BranchObj) )
1647 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1648 BranchObj* par=(BranchObj*)(bo->getParObj());
1650 if (selection->getDepth()>1)
1651 // Normal branch, save parent with childs
1652 saveState(par,QString("Delete %1").arg(getName(bo)));
1654 // Mainbranch, save whole map
1655 // TODO Better would be to insert mainbranch again at pos
1656 // But undoCommand is missing right now
1657 saveState(QString("Delete %1").arg(getName(bo)));
1659 par->removeBranch(bo);
1661 selection->select();
1662 ensureSelectionVisible();
1663 mapCenter->reposition();
1666 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1668 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1669 BranchObj* par=(BranchObj*)(fio->getParObj());
1670 saveState(par, QString("Delete %1").arg(getName(fio)));
1673 par->removeFloatImage(fio);
1675 selection->select();
1676 ensureSelectionVisible();
1677 mapCenter->reposition();
1682 LinkableMapObj* MapEditor::getSelection()
1687 void MapEditor::unselect()
1691 selectionLast=selection;
1692 selection->unselect();
1697 void MapEditor::reselect()
1701 selection=selectionLast;
1702 selection->select();
1707 bool MapEditor::select (const QString &s)
1709 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1711 // Finally select the found object
1714 if (selection) unselect();
1716 selection->select();
1718 ensureSelectionVisible();
1724 void MapEditor::select (LinkableMapObj *lmo)
1726 if (lmo && selection != lmo)
1728 // select the MapObj
1729 if (selection) selection->unselect();
1731 selection->select();
1738 void MapEditor::selectNextBranch()
1740 // Increase number of branch
1743 QString s=selection->getSelectString();
1749 part=s.section(",",-1);
1751 num=part.right(part.length() - 3);
1753 s=s.left (s.length() -num.length());
1756 num=QString ("%1").arg(num.toUInt()+1);
1760 // Try to select this one
1761 if (select (s)) return;
1763 // We have no direct successor,
1764 // try to increase the parental number in order to
1765 // find a successor with same depth
1767 int d=selection->getDepth();
1772 while (!found && d>0)
1774 s=s.section (",",0,d-1);
1775 // replace substring of current depth in s with "1"
1776 part=s.section(",",-1);
1778 num=part.right(part.length() - 3);
1782 // increase number of parent
1783 num=QString ("%1").arg(num.toUInt()+1);
1784 s=s.section (",",0,d-2) + ","+ typ+num;
1787 // Special case, look at orientation
1788 if (selection->getOrientation()==OrientRightOfCenter)
1789 num=QString ("%1").arg(num.toUInt()+1);
1791 num=QString ("%1").arg(num.toUInt()-1);
1796 // pad to oldDepth, select the first branch for each depth
1797 for (i=d;i<oldDepth;i++)
1802 if ( ((BranchObj*)selection)->countBranches()>0)
1810 // try to select the freshly built string
1818 void MapEditor::selectPrevBranch()
1820 // Decrease number of branch
1823 QString s=selection->getSelectString();
1829 part=s.section(",",-1);
1831 num=part.right(part.length() - 3);
1833 s=s.left (s.length() -num.length());
1836 num=QString ("%1").arg(num.toUInt()-1);
1840 // Try to select this one
1841 if (select (s)) return;
1843 // We have no direct precessor,
1844 // try to decrease the parental number in order to
1845 // find a precessor with same depth
1847 int d=selection->getDepth();
1852 while (!found && d>0)
1854 s=s.section (",",0,d-1);
1855 // replace substring of current depth in s with "1"
1856 part=s.section(",",-1);
1858 num=part.right(part.length() - 3);
1862 // decrease number of parent
1863 num=QString ("%1").arg(num.toUInt()-1);
1864 s=s.section (",",0,d-2) + ","+ typ+num;
1867 // Special case, look at orientation
1868 if (selection->getOrientation()==OrientRightOfCenter)
1869 num=QString ("%1").arg(num.toUInt()-1);
1871 num=QString ("%1").arg(num.toUInt()+1);
1876 // pad to oldDepth, select the last branch for each depth
1877 for (i=d;i<oldDepth;i++)
1881 if ( ((BranchObj*)selection)->countBranches()>0)
1882 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1889 // try to select the freshly built string
1897 void MapEditor::selectUpperBranch()
1899 // Finish open lineEdits
1900 if (lineedit) finishedLineEdit();
1904 if (typeid(*selection) == typeid(BranchObj))
1906 if (selection->getOrientation()==OrientRightOfCenter)
1909 if (selection->getDepth()==1)
1917 void MapEditor::selectLowerBranch()
1919 // Finish open lineEdits
1920 if (lineedit) finishedLineEdit();
1924 if (typeid(*selection) == typeid(BranchObj))
1926 if (selection->getOrientation()==OrientRightOfCenter)
1929 if (selection->getDepth()==1)
1938 void MapEditor::selectLeftBranch()
1940 // Finish open lineEdits
1941 if (lineedit) finishedLineEdit();
1947 if (typeid(*selection) == typeid(MapCenterObj))
1949 par= (BranchObj*) selection;
1950 bo=par->getLastSelectedBranch();
1953 // Workaround for reselecting on left and right side
1954 if (bo->getOrientation()==OrientRightOfCenter)
1956 bo=par->getLastBranch();
1962 selection->select();
1964 ensureSelectionVisible();
1969 par=(BranchObj*)(selection->getParObj());
1970 if (selection->getOrientation()==OrientRightOfCenter)
1972 if (typeid(*selection) == typeid(BranchObj) ||
1973 typeid(*selection) == typeid(FloatImageObj))
1975 selection->unselect();
1977 selection->select();
1979 ensureSelectionVisible();
1983 if (typeid(*selection) == typeid(BranchObj) )
1985 bo=((BranchObj*)selection)->getLastSelectedBranch();
1988 selection->unselect();
1990 selection->select();
1992 ensureSelectionVisible();
2000 void MapEditor::selectRightBranch()
2002 // Finish open lineEdits
2003 if (lineedit) finishedLineEdit();
2010 if (typeid(*selection) == typeid(MapCenterObj))
2012 par= (BranchObj*) selection;
2013 bo=par->getLastSelectedBranch();
2016 // Workaround for relecting on left and right side
2017 if (bo->getOrientation()==OrientLeftOfCenter)
2018 bo=par->getFirstBranch();
2023 selection->select();
2024 ensureSelectionVisible();
2029 par=(BranchObj*)(selection->getParObj());
2030 if (selection->getOrientation()==OrientLeftOfCenter)
2032 if (typeid(*selection) == typeid(BranchObj) ||
2033 typeid(*selection) == typeid(FloatImageObj))
2035 selection->unselect();
2037 selection->select();
2039 ensureSelectionVisible();
2043 if (typeid(*selection) == typeid(BranchObj) )
2045 bo=((BranchObj*)selection)->getLastSelectedBranch();
2048 selection->unselect();
2050 selection->select();
2052 ensureSelectionVisible();
2060 void MapEditor::selectFirstBranch()
2062 // Finish open lineEdits
2063 if (lineedit) finishedLineEdit();
2069 if (typeid(*selection) == typeid(BranchObj))
2071 bo1= (BranchObj*) selection;
2072 par=(BranchObj*)(bo1->getParObj());
2073 bo2=par->getFirstBranch();
2077 selection->select();
2078 ensureSelectionVisible();
2085 void MapEditor::selectLastBranch()
2087 // Finish open lineEdits
2088 if (lineedit) finishedLineEdit();
2094 if (typeid(*selection) == typeid(BranchObj))
2096 bo1= (BranchObj*) selection;
2097 par=(BranchObj*)(bo1->getParObj());
2098 bo2=par->getLastBranch();
2102 selection->select();
2103 ensureSelectionVisible();
2110 void MapEditor::setColor(QColor c)
2115 void MapEditor::selectBackgroundColor()
2117 // Finish open lineEdits
2118 if (lineedit) finishedLineEdit();
2120 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2121 if ( !col.isValid() ) return;
2122 setBackgroundColor( col );
2123 saveState(QString("Set background color of map to %1").arg(col.name()));
2126 void MapEditor::setBackgroundColor(QColor c)
2128 mapCanvas->setBackgroundColor (c);
2131 QColor MapEditor::pickColor()
2135 if (typeid(*selection) == typeid(BranchObj) ||
2136 typeid(*selection) == typeid(MapCenterObj))
2138 BranchObj *bo=(BranchObj*)selection;
2139 actColor=bo->getColor();
2145 void MapEditor::colorItem()
2149 if (typeid(*selection) == typeid(BranchObj) ||
2150 typeid(*selection) == typeid(MapCenterObj))
2152 BranchObj *bo=(BranchObj*)selection;
2153 saveState(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2154 bo->setColor(actColor); // color branch
2159 void MapEditor::colorBranch()
2163 if (typeid(*selection) == typeid(BranchObj) ||
2164 typeid(*selection) == typeid(MapCenterObj))
2166 BranchObj *bo=(BranchObj*)selection;
2167 saveState(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand
2168 bo->setColorChilds(actColor); // color links, color childs
2174 void MapEditor::toggleStandardFlag(QString f)
2178 BranchObj *bo=(BranchObj*)selection;
2180 if (bo->isSetStandardFlag(f))
2184 saveState(selection, QString("%1 standard flag \"%2\" of %3").arg(s).arg(f).arg(getName(bo)));// TODO undoCommand
2185 bo->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2190 void MapEditor::setViewCenter()
2192 // transform to CanvasView Coord:
2193 QPoint p=worldMatrix().map(movingCenter);
2194 center ( p.x(), p.y());
2198 BranchObj* MapEditor::findText (QString s, bool cs)
2201 { // Nothing found or new find process
2203 // nothing found, start again
2205 itFind=mapCenter->first();
2207 bool searching=true;
2208 bool foundNote=false;
2209 while (searching && !EOFind)
2213 // Searching in Note
2214 if (itFind->getNote().contains(s,cs))
2216 if (selection!=itFind)
2218 if (selection) ((BranchObj*)selection)->unselect();
2220 selection->select();
2222 ensureSelectionVisible();
2224 if (textEditor->findText(s,cs))
2230 // Searching in Heading
2231 if (searching && itFind->getHeading().contains (s,cs) )
2233 if (selection) ((BranchObj*)selection)->unselect();
2235 selection->select();
2237 ensureSelectionVisible();
2243 itFind=itFind->next();
2244 if (!itFind) EOFind=true;
2250 return (BranchObj*)selection;
2255 void MapEditor::findReset()
2256 { // Necessary if text to find changes during a find process
2261 void MapEditor::editURL()
2263 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2264 typeid(*selection) == typeid(MapCenterObj)) )
2267 BranchObj *bo=(BranchObj*)selection;
2268 QString text = QInputDialog::getText(
2269 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2270 bo->getURL(), &ok, this );
2273 // user entered something and pressed OK
2274 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text));
2281 QString MapEditor::getURL()
2283 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2284 typeid(*selection) == typeid(MapCenterObj)) )
2285 return ((BranchObj*)selection)->getURL();
2290 void MapEditor::editHeading2URL()
2292 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2293 typeid(*selection) == typeid(MapCenterObj)) )
2295 BranchObj *bo=(BranchObj*)selection;
2296 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo)));
2297 bo->setURL (bo->getHeading());
2302 void MapEditor::editBugzilla2URL()
2304 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2305 typeid(*selection) == typeid(MapCenterObj)) )
2307 BranchObj *bo=(BranchObj*)selection;
2308 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2309 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Bugzilla").arg(getName(bo)));
2315 void MapEditor::editFATE2URL()
2317 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2318 typeid(*selection) == typeid(MapCenterObj)) )
2320 BranchObj *bo=(BranchObj*)selection;
2321 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2322 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo)));
2328 void MapEditor::editVymLink()
2330 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2331 typeid(*selection) == typeid(MapCenterObj)) )
2333 BranchObj *bo=(BranchObj*)selection;
2334 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
2335 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2336 fd->setCaption(__VYM " - " +tr("Link to another map"));
2337 if (! bo->getVymLink().isEmpty() )
2338 fd->setSelection( bo->getVymLink() );
2342 if ( fd->exec() == QDialog::Accepted )
2344 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()));
2345 bo->setVymLink (fd->selectedFile() );
2347 mapCenter->reposition();
2354 void MapEditor::deleteVymLink()
2356 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2357 typeid(*selection) == typeid(MapCenterObj)) )
2359 BranchObj *bo=(BranchObj*)selection;
2360 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo)));
2361 bo->setVymLink ("" );
2363 mapCenter->reposition();
2369 void MapEditor::toggleHideExport()
2371 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2372 typeid(*selection) == typeid(MapCenterObj)) ||
2373 (typeid(*selection)==typeid(FloatImageObj))
2376 OrnamentedObj *oo=(OrnamentedObj*)selection;
2378 if (oo->hideInExport())
2380 oo->setHideInExport(false);
2385 oo->setHideInExport(true);
2388 saveState(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand
2389 actionEditToggleHideExport->setOn (oo->hideInExport());
2391 mapCenter->reposition();
2397 QString MapEditor::getVymLink()
2399 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2400 typeid(*selection) == typeid(MapCenterObj)) )
2402 return ((BranchObj*)selection)->getVymLink();
2408 void MapEditor::removeBranchKeepChilds()
2410 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2412 BranchObj* bo=(BranchObj*)selection;
2413 BranchObj* par=(BranchObj*)(bo->getParObj());
2414 QString s=QString("Remove %1 and keep its childs").arg(getName(bo));
2415 if (bo->getDepth()==1)
2418 saveState(selection->getParObj(),s); // TODO undoCommand
2419 QString sel=selection->getSelectString();
2421 par->removeBranchHere(bo);
2422 mapCenter->reposition();
2427 void MapEditor::removeChilds()
2429 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2431 saveState(selection->getParObj(), QString("Remove childs of branch").arg(getName(selection)));
2432 ((BranchObj*)selection)->removeChilds();
2433 mapCenter->reposition();
2437 void MapEditor::editMapInfo()
2439 ExtraInfoDialog dia;
2440 dia.setMapName (getFileName() );
2441 dia.setAuthor (mapCenter->getAuthor() );
2442 dia.setComment(mapCenter->getComment() );
2447 QCanvasItemList l=canvas()->allItems();
2448 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2450 stats+=QString ("%1 items on canvas\n").arg (i,6);
2457 bo=mapCenter->first();
2460 if (!bo->getNote().isEmpty() ) n++;
2461 f+= bo->countFloatImages();
2463 xl+=bo->countXLinks();
2466 stats+=QString ("%1 branches\n").arg (b-1,6);
2467 stats+=QString ("%1 xLinks \n").arg (xl,6);
2468 stats+=QString ("%1 notes\n").arg (n,6);
2469 stats+=QString ("%1 images\n").arg (f,6);
2470 dia.setStats (stats);
2472 // Finally show dialog
2473 if (dia.exec() == QDialog::Accepted)
2475 saveState("Edit info about map"); //TODO undoCommand
2476 mapCenter->setAuthor (dia.getAuthor() );
2477 mapCenter->setComment (dia.getComment() );
2481 void MapEditor::updateActions()
2484 if (getLinkColorHint()==HeadingColor)
2485 actionFormatLinkColorHint->setOn(true);
2487 actionFormatLinkColorHint->setOn(false);
2492 actionFormatLinkStyleLine->setOn(true);
2495 actionFormatLinkStyleParabel->setOn(true);
2498 actionFormatLinkStylePolyLine->setOn(true);
2500 case StylePolyParabel:
2501 actionFormatLinkStylePolyParabel->setOn(true);
2507 QPixmap pix( 16, 16 );
2508 pix.fill( mapCanvas->backgroundColor() );
2509 actionFormatBackColor->setIconSet( pix );
2510 pix.fill( defLinkColor );
2511 actionFormatLinkColor->setIconSet( pix );
2513 actionEditUndo->setEnabled( mapChanged );
2514 actionFileSave->setEnabled( mapUnsaved );
2518 if ( (typeid(*selection) == typeid(BranchObj)) ||
2519 (typeid(*selection) == typeid(MapCenterObj)) )
2521 BranchObj *bo=(BranchObj*)selection;
2522 // Take care of links
2523 if (bo->countXLinks()==0)
2525 branchLinksContextMenu->clear();
2526 branchLinksContextMenu->insertItem ("No xLink available");
2527 branchLinksContextMenuDup->clear();
2528 branchLinksContextMenuDup->insertItem ("No xLink available");
2534 branchLinksContextMenu->clear();
2535 branchLinksContextMenuDup->clear();
2536 for (int i=0; i<=bo->countXLinks();i++)
2538 bot=bo->XLinkTargetAt(i);
2541 s=bot->getHeading();
2544 branchLinksContextMenu->insertItem (s);
2545 branchLinksContextMenuDup->insertItem (s);
2550 standardFlagsDefault->setEnabled (true);
2552 actionEditToggleScroll->setEnabled (true);
2553 if ( bo->isScrolled() )
2554 actionEditToggleScroll->setOn(true);
2556 actionEditToggleScroll->setOn(false);
2558 if ( bo->getURL().isEmpty() )
2560 actionEditOpenURL->setEnabled (false);
2561 actionEditOpenURLTab->setEnabled (false);
2565 actionEditOpenURL->setEnabled (true);
2566 actionEditOpenURLTab->setEnabled (true);
2568 if ( bo->getVymLink().isEmpty() )
2570 actionEditOpenVymLink->setEnabled (false);
2571 actionEditDeleteVymLink->setEnabled (false);
2574 actionEditOpenVymLink->setEnabled (true);
2575 actionEditDeleteVymLink->setEnabled (true);
2577 actionEditToggleHideExport->setEnabled (true);
2578 actionEditToggleHideExport->setOn (bo->hideInExport() );
2580 actionEditCopy->setEnabled (true);
2581 actionEditCut->setEnabled (true);
2582 if (!clipboardEmpty)
2583 actionEditPaste->setEnabled (true);
2585 actionEditPaste->setEnabled (false);
2586 for (a=actionListBranches.first();a;a=actionListBranches.next())
2587 a->setEnabled(true);
2588 actionEditDelete->setEnabled (true);
2589 switch (selection->getFrameType())
2592 actionFormatFrameNone->setOn(true);
2595 actionFormatFrameRectangle->setOn(true);
2600 actionFormatIncludeImagesVer->setOn
2601 ( ((BranchObj*)selection)->getIncludeImagesVer());
2602 actionFormatIncludeImagesHor->setOn
2603 ( ((BranchObj*)selection)->getIncludeImagesHor());
2604 actionFormatHideLinkUnselected->setOn
2605 (selection->getHideLinkUnselected());
2607 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2609 FloatObj *fo=(FloatImageObj*)selection;
2610 standardFlagsDefault->setEnabled (false);
2612 actionEditOpenURL->setEnabled (false);
2613 actionEditOpenVymLink->setEnabled (false);
2614 actionEditDeleteVymLink->setEnabled (false);
2615 actionEditToggleHideExport->setEnabled (true);
2616 actionEditToggleHideExport->setOn (fo->hideInExport() );
2619 actionEditCopy->setEnabled (true);
2620 actionEditCut->setEnabled (true);
2621 actionEditPaste->setEnabled (false);
2622 for (a=actionListBranches.first();a;a=actionListBranches.next())
2623 a->setEnabled(false);
2624 actionEditDelete->setEnabled (true);
2625 actionFormatHideLinkUnselected->setOn
2626 ( selection->getHideLinkUnselected());
2631 standardFlagsDefault->setEnabled (false);
2633 actionEditCopy->setEnabled (false);
2634 actionEditCut->setEnabled (false);
2635 actionEditPaste->setEnabled (false);
2636 for (a=actionListBranches.first();a;a=actionListBranches.next())
2637 a->setEnabled(false);
2639 actionEditToggleScroll->setEnabled (true);
2640 actionEditOpenURL->setEnabled (false);
2641 actionEditOpenVymLink->setEnabled (false);
2642 actionEditDeleteVymLink->setEnabled (false);
2643 actionEditHeading2URL->setEnabled (false);
2644 actionEditDelete->setEnabled (false);
2648 void MapEditor::updateNoteFlag()
2651 if ( (typeid(*selection) == typeid(BranchObj)) ||
2652 (typeid(*selection) == typeid(MapCenterObj)) )
2653 ((BranchObj*)selection)->updateNoteFlag();
2656 void MapEditor::setLinkStyle (LinkStyle ls)
2660 saveState("Set link style"); // TODO undoCommand
2662 bo=mapCenter->first();
2666 bo->setLinkStyle(bo->getDefLinkStyle());
2669 mapCenter->reposition();
2672 LinkStyle MapEditor::getLinkStyle ()
2677 void MapEditor::setLinkColor(QColor c)
2683 void MapEditor::setLinkColorHint()
2685 // called from setLinkColorHint(lch) or at end of parse
2687 bo=mapCenter->first();
2695 void MapEditor::setLinkColorHint(LinkColorHint lch)
2701 void MapEditor::toggleLinkColorHint()
2703 if (linkcolorhint==HeadingColor)
2704 linkcolorhint=DefaultColor;
2706 linkcolorhint=HeadingColor;
2708 bo=mapCenter->first();
2716 LinkColorHint MapEditor::getLinkColorHint()
2718 return linkcolorhint;
2721 QColor MapEditor::getDefLinkColor()
2723 return defLinkColor;
2726 void MapEditor::setDefXLinkColor(QColor col)
2731 QColor MapEditor::getDefXLinkColor()
2733 return defXLinkColor;
2736 void MapEditor::setDefXLinkWidth (int w)
2741 int MapEditor::getDefXLinkWidth()
2743 return defXLinkWidth;
2746 void MapEditor::selectLinkColor()
2748 // Finish open lineEdits
2749 if (lineedit) finishedLineEdit();
2751 QColor col = QColorDialog::getColor( defLinkColor, this );
2752 if ( !col.isValid() ) return;
2753 setLinkColor( col );
2754 saveState(QString("Set link color to %1").arg(col.name())); //TODO undoCommand
2758 void MapEditor::toggleScroll()
2760 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2762 BranchObj *bo=((BranchObj*)selection);
2763 if (bo->countBranches()==0) return;
2764 if (bo->getDepth()==0) return;
2766 if (bo->isScrolled())
2770 saveState(selection, QString ("%1 %2").arg(s).arg(getName(bo)));
2777 void MapEditor::unScrollAll()
2780 bo=mapCenter->first();
2783 if (bo->isScrolled()) bo->toggleScroll();
2788 void MapEditor::loadFloatImage ()
2791 (typeid(*selection) == typeid(BranchObj)) ||
2792 (typeid(*selection) == typeid(MapCenterObj)) )
2794 BranchObj *bo=((BranchObj*)selection);
2796 QFileDialog *fd=new QFileDialog( this);
2797 fd->setMode (QFileDialog::ExistingFiles);
2798 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2799 ImagePreview *p =new ImagePreview (fd);
2800 fd->setContentsPreviewEnabled( TRUE );
2801 fd->setContentsPreview( p, p );
2802 fd->setPreviewMode( QFileDialog::Contents );
2803 fd->setCaption(__VYM " - " +tr("Load image"));
2804 fd->setDir (lastImageDir);
2808 if ( fd->exec() == QDialog::Accepted )
2810 saveState(selection, QString("Add floatimage to %1").arg(getName(selection)));
2811 lastImageDir=fn.left(fn.findRev ("/"));
2812 QStringList flist = fd->selectedFiles();
2813 QStringList::Iterator it = flist.begin();
2814 while( it != flist.end() )
2817 bo->addFloatImage();
2818 // TODO check if load was successful
2819 bo->getLastFloatImage()->load(*it);
2820 bo->getLastFloatImage()->setOriginalFilename(fn);
2824 mapCenter->reposition();
2833 void MapEditor::saveFloatImage (int item)
2836 (typeid(*selection) == typeid(FloatImageObj)) )
2838 FloatImageObj *fio=((FloatImageObj*)selection);
2839 const char* fmt = saveImageFormatMenu->text(item);
2841 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2842 fd->addFilter ("PNG (*.png)");
2843 fd->addFilter ("BMP (*.bmp)");
2844 fd->addFilter ("XBM (*.xbm)");
2845 fd->addFilter ("JPG (*.jpg)");
2846 fd->addFilter ("XPM (*.xpm)");
2847 fd->addFilter ("GIF (*.gif)");
2848 fd->addFilter ("PNM (*.pnm)");
2849 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2850 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2851 fd->setMode( QFileDialog::AnyFile );
2852 fd->setSelection (fio->getOriginalFilename());
2856 if ( fd->exec() == QDialog::Accepted )
2858 if (QFile (fd->selectedFile()).exists() )
2860 QMessageBox mb( __VYM,
2861 tr("The file %1 exists already.\n"
2862 "Do you want to overwrite it?").arg(fd->selectedFile()),
2863 QMessageBox::Warning,
2864 QMessageBox::Yes | QMessageBox::Default,
2865 QMessageBox::Cancel | QMessageBox::Escape,
2866 QMessageBox::QMessageBox::NoButton );
2868 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2869 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2872 case QMessageBox::Yes:
2875 case QMessageBox::Cancel:
2881 fio->save (fd->selectedFile(),fmt);
2886 void MapEditor::setFrame(const FrameType &t)
2889 (typeid(*selection) == typeid(BranchObj)) ||
2890 (typeid(*selection) == typeid(MapCenterObj)) )
2892 selection->setFrameType (t);
2893 mapCenter->reposition();
2894 selection->updateLink();
2898 void MapEditor::setIncludeImagesVer(bool b)
2901 (typeid(*selection) == typeid(BranchObj)) ||
2902 (typeid(*selection) == typeid(MapCenterObj)) )
2903 ((BranchObj*)selection)->setIncludeImagesVer(b);
2904 mapCenter->reposition();
2907 void MapEditor::setIncludeImagesHor(bool b)
2910 (typeid(*selection) == typeid(BranchObj)) ||
2911 (typeid(*selection) == typeid(MapCenterObj)) )
2912 ((BranchObj*)selection)->setIncludeImagesHor(b);
2913 mapCenter->reposition();
2916 void MapEditor::setHideLinkUnselected (bool b)
2919 (typeid(*selection) == typeid(BranchObj)) ||
2920 (typeid(*selection) == typeid(MapCenterObj)) ||
2921 (typeid(*selection) == typeid(FloatImageObj)) )
2922 selection->setHideLinkUnselected(b);
2925 void MapEditor::importDir(BranchObj *dst, QDir d)
2928 (typeid(*selection) == typeid(BranchObj)) ||
2929 (typeid(*selection) == typeid(MapCenterObj)) )
2933 // Traverse directories
2934 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2935 const QFileInfoList *dirlist = d.entryInfoList();
2936 QFileInfoListIterator itdir( *dirlist );
2939 while ( (fi = itdir.current()) != 0 )
2941 if (fi->fileName() != "." && fi->fileName() != ".." )
2944 bo=dst->getLastBranch();
2945 bo->setHeading (fi->fileName() );
2946 bo->setColor (QColor("blue"));
2948 if ( !d.cd(fi->fileName()) )
2949 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2952 // Recursively add subdirs
2960 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2961 const QFileInfoList *filelist = d.entryInfoList();
2962 QFileInfoListIterator itfile( *filelist );
2964 while ( (fi = itfile.current()) != 0 )
2967 bo=dst->getLastBranch();
2968 bo->setHeading (fi->fileName() );
2969 bo->setColor (QColor("black"));
2970 if (fi->fileName().right(4) == ".vym" )
2971 bo->setVymLink (fi->filePath());
2978 void MapEditor::importDir()
2981 (typeid(*selection) == typeid(BranchObj)) ||
2982 (typeid(*selection) == typeid(MapCenterObj)) )
2984 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
2985 fd->setMode (QFileDialog::DirectoryOnly);
2986 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2987 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
2991 if ( fd->exec() == QDialog::Accepted )
2993 BranchObj *bo=((BranchObj*)selection);
2994 importDir (bo,QDir(fd->selectedFile()) );
2995 mapCenter->reposition();
3002 void MapEditor::followXLink(int i)
3005 (typeid(*selection) == typeid(BranchObj)) ||
3006 (typeid(*selection) == typeid(MapCenterObj)) )
3008 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
3011 selection->unselect();
3013 selection->select();
3014 ensureSelectionVisible();
3019 void MapEditor::editXLink(int i)
3022 (typeid(*selection) == typeid(BranchObj)) ||
3023 (typeid(*selection) == typeid(MapCenterObj)) )
3025 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
3028 EditXLinkDialog dia;
3030 dia.setSelection(selection);
3031 if (dia.exec() == QDialog::Accepted)
3033 if (dia.useSettingsGlobal() )
3035 setDefXLinkColor (xlo->getColor() );
3036 setDefXLinkWidth (xlo->getWidth() );
3038 if (dia.deleteXLink())
3039 ((BranchObj*)selection)->deleteXLinkAt(i);
3040 saveState("Edit xLink"); //TODO undoCommand
3046 void MapEditor::testFunction()
3048 cout << "MapEditor::testFunction() called\n";
3050 if (hidemode==HideNone)
3052 setHideTmpMode (HideExport);
3053 mapCenter->calcBBoxSizeWithChilds();
3054 QRect totalBBox=mapCenter->getTotalBBox();
3055 QRect mapRect=totalBBox;
3056 QCanvasRectangle *frame=NULL;
3058 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3060 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3061 totalBBox.width(), totalBBox.height());
3062 frame=new QCanvasRectangle (mapRect,mapCanvas);
3063 frame->setBrush (QColor(white));
3064 frame->setPen (QColor(black));
3070 setHideTmpMode (HideNone);
3072 cout <<" hidemode="<<hidemode<<endl;
3075 void MapEditor::ensureSelectionVisible()
3079 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3081 if (selection->getOrientation() == OrientLeftOfCenter)
3082 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3084 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3085 ensureVisible (p.x(), p.y() );
3090 void MapEditor::updateViewCenter()
3092 // Update movingCenter, so that we can zoom comfortably later
3093 QRect rc = QRect( contentsX(), contentsY(),
3094 visibleWidth(), visibleHeight() );
3095 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3096 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3097 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3100 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3102 // Lineedits are already closed by preceding
3103 // mouseEvent, we don't need to close here.
3105 QPoint p = inverseWorldMatrix().map(e->pos());
3106 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3109 { // MapObj was found
3110 if (selection != lmo)
3112 // select the MapObj
3113 if (selection) selection->unselect();
3115 selection->select();
3121 if (typeid(*selection)==typeid(BranchObj) ||
3122 typeid(*selection)==typeid(MapCenterObj) )
3124 // Context Menu on branch or mapcenter
3126 branchContextMenu->popup(e->globalPos() );
3128 if (typeid(*selection)==typeid(FloatImageObj))
3130 // Context Menu on floatimage
3132 floatimageContextMenu->popup(e->globalPos() );
3136 { // No MapObj found, we are on the Canvas itself
3137 // Context Menu on Canvas
3139 canvasContextMenu->popup(e->globalPos() );
3143 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3145 // Finish open lineEdits
3146 if (lineedit) finishedLineEdit();
3148 QPoint p = inverseWorldMatrix().map(e->pos());
3149 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3151 //Take care of clickdesystem flags _or_ modifier modes
3153 if (lmo && (typeid(*lmo)==typeid(BranchObj) ||
3154 typeid(*lmo)==typeid(MapCenterObj) ))
3156 QString foname=((BranchObj*)lmo)->getSystemFlagName(p);
3157 if (!foname.isEmpty())
3159 // systemFlag clicked
3163 if (e->state() & QMouseEvent::ControlButton)
3164 mainWindow->editOpenURLTab();
3166 mainWindow->editOpenURL();
3168 else if (foname=="vymLink")
3170 mainWindow->editOpenVymLink();
3171 // tabWidget may change, better return now
3172 // before segfaulting...
3173 } else if (foname=="note")
3174 mainWindow->windowToggleNoteEditor();
3175 else if (foname=="hideInExport")
3180 // No system flag clicked, take care of modmodes
3182 // Special case: CTRL is pressed
3183 if (e->state() & QMouseEvent::ControlButton)
3185 if (actionModModeColor->isOn())
3188 setCursor (pickColorCursor);
3191 if (actionModModeLink->isOn())
3193 BranchObj *bo_begin=NULL;
3195 bo_begin=(BranchObj*)(lmo);
3198 ((typeid(*selection) == typeid(BranchObj)) ||
3199 (typeid(*selection) == typeid(MapCenterObj))) )
3200 bo_begin=(BranchObj*)selection;
3204 linkingObj_src=bo_begin;
3205 tmpXLink=new XLinkObj (mapCanvas);
3206 tmpXLink->setBegin (bo_begin);
3207 tmpXLink->setEnd (p);
3208 tmpXLink->setColor(defXLinkColor);
3209 tmpXLink->setWidth(defXLinkWidth);
3210 tmpXLink->updateXLink();
3211 tmpXLink->setVisibility (true);
3219 // Left Button Move Branches
3220 if (e->button() == QMouseEvent::LeftButton )
3222 movingObj_start.setX( p.x() - selection->x() );
3223 movingObj_start.setY( p.y() - selection->y() );
3224 movingObj_orgPos.setX (lmo->x() );
3225 movingObj_orgPos.setY (lmo->y() );
3227 // If modMode==copy, then we want to "move" the _new_ object around
3228 // then we need the offset from p to the _old_ selection, because of tmp
3229 if (actionModModeCopy->isOn() &&
3230 e->state() & QMouseEvent::ControlButton)
3232 if (typeid(*selection)==typeid(BranchObj) )
3235 mapCenter->addBranch ((BranchObj*)selection);
3237 selection=mapCenter->getLastBranch();
3238 selection->select();
3239 mapCenter->reposition();
3242 movingObj=selection;
3244 // Middle Button Toggle Scroll
3245 // (On Mac OS X this won't work, but we still have
3246 // a button in the toolbar)
3247 if (e->button() == QMouseEvent::MidButton )
3251 { // No MapObj found, we are on the Canvas itself
3252 // Left Button move Pos of CanvasView
3253 if (e->button() == QMouseEvent::LeftButton )
3255 movingObj=NULL; // move Content not Obj
3256 movingObj_start=e->globalPos();
3257 movingCont_start=QPoint (contentsX(), contentsY() );
3258 movingVec=QPoint(0,0);
3259 setCursor(handOpenCursor);
3264 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3266 QPoint p = inverseWorldMatrix().map(e->pos());
3268 // Move the selected MapObj
3269 if ( selection && movingObj)
3271 // To avoid jumping of the CanvasView, only
3272 // ensureSelectionVisible, if not tmp linked
3273 if (!selection->hasParObjTmp())
3274 ensureSelectionVisible ();
3276 // Now move the selection, but add relative position
3277 // (movingObj_start) where selection was chosen with
3278 // mousepointer. (This avoids flickering resp. jumping
3279 // of selection back to absPos)
3281 LinkableMapObj *lmosel;
3282 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3284 // Check if we could link
3285 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3288 if (typeid(*selection) == typeid(FloatImageObj))
3290 FloatObj *fo=(FloatObj*)selection;
3292 "move "+qpointToString(movingObj_orgPos),fo->getSelectString() ,
3293 QString("Move %1").arg(getName(selection)));
3294 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3298 // Relink float to new mapcenter or branch, if shift is pressed
3299 // Only relink, if selection really has a new parent
3300 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3301 ( (typeid(*lmo)==typeid(BranchObj)) ||
3302 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3303 ( lmo != fo->getParObj())
3306 if (typeid(*fo) == typeid(FloatImageObj))
3308 saveState(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
3309 FloatImageObj *fio=(FloatImageObj*)(fo);
3310 ((BranchObj*)(lmo))->addFloatImage (fio);
3312 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3313 fio=((BranchObj*)(lmo))->getLastFloatImage();
3316 selection=(LinkableMapObj*)(fio);
3317 selection->select();
3318 movingObj=(MapObj*)(fio);
3321 } else // selection != a FloatObj
3323 if (lmosel->getDepth()==0)
3325 if (e->state() == (LeftButton | !ShiftButton))
3326 // If mapCenter is moved, move all the rest by default, too.
3327 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3329 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3332 if (lmosel->getDepth()==1)
3334 // depth==1, mainbranch
3335 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3339 if (lmosel->getOrientation() == OrientLeftOfCenter)
3340 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3341 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3342 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3344 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3346 // reposition subbranch
3347 lmosel->reposition();
3348 //ensureSelectionVisible();
3350 if (lmo && (lmo!=selection) &&
3351 (typeid(*lmo) == typeid(BranchObj) ||
3352 (typeid(*lmo) == typeid(MapCenterObj) )
3355 if (e->state() & QMouseEvent::ControlButton)
3357 // Special case: CTRL to link below lmo
3358 lmosel->setParObjTmp (lmo,p,+1);
3360 else if (e->state() & QMouseEvent::ShiftButton)
3361 lmosel->setParObjTmp (lmo,p,-1);
3363 lmosel->setParObjTmp (lmo,p,0);
3366 lmosel->unsetParObjTmp();
3367 /* FIXME not needed anymore?
3368 if (lmo &&(lmo==selection))
3369 // Could link to myself (happens sometimes...)
3370 lmosel->unsetParObjTmp();
3372 // no Obj under selection, go back to original Parent
3373 lmosel->unsetParObjTmp();
3378 } // no FloatImageObj
3382 } // selection && moving_obj
3384 // Draw a link from one branch to another
3387 tmpXLink->setEnd (p);
3388 tmpXLink->updateXLink();
3392 if (!movingObj && !pickingColor &&!drawingLink)
3394 QPoint p=e->globalPos();
3395 movingVec.setX(-p.x() + movingObj_start.x() );
3396 movingVec.setY(-p.y() + movingObj_start.y() );
3397 setContentsPos( movingCont_start.x() + movingVec.x(),
3398 movingCont_start.y() + movingVec.y());
3405 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3407 LinkableMapObj *dst;
3408 // Have we been picking color?
3412 setCursor (ArrowCursor);
3413 // Check if we are over another branch
3414 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3415 if (dst && selection)
3417 if (e->state() & QMouseEvent::ShiftButton)
3419 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3420 ((BranchObj*)selection)->setLinkColor ();
3424 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3425 ((BranchObj*)selection)->setLinkColor ();
3431 // Have we been drawing a link?
3435 // Check if we are over another branch
3436 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3437 if (dst && selection)
3439 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3440 tmpXLink->updateXLink();
3441 tmpXLink->activate();
3442 saveState(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand
3451 // Have we been moving something?
3452 if ( selection && movingObj )
3454 // Moved FloatObj? Maybe we need to reposition
3455 if(typeid(*selection)==typeid (FloatImageObj))
3457 selection->getParObj()->requestReposition();
3458 mapCenter->reposition();
3461 // Check if we are over another branch, but ignore
3462 // any found LMOs, which are FloatObjs
3463 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3464 ((LinkableMapObj*)selection) );
3467 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3470 // Now check, if we have been moving a branch
3471 if (typeid(*selection) == typeid(BranchObj) )
3473 // save the position in case we link to mapcenter
3474 QPoint savePos=QPoint (selection->x(),selection->y() );
3476 // Reset the temporary drawn link to the original one
3477 ((LinkableMapObj*)selection)->unsetParObjTmp();
3483 BranchObj* bs=((BranchObj*)selection);
3484 QString undoCom="linkBranchToPos (\""+
3485 (bs->getParObj())->getSelectString()+
3487 QString("%1").arg(bs->getNum())+
3489 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3491 // TODO we also could check, if dest and src are on same branch,
3492 // then it would be sufficient to saveState of this branch
3494 // Modifiers allow to insert above/below dst
3495 if (e->state() & QMouseEvent::ShiftButton)
3497 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3499 if (e->state() & QMouseEvent::ControlButton)
3501 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3504 bs->moveBranchTo ((BranchObj*)(dst),-1);
3505 if (dst->getDepth()==0)
3508 saveState (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) );
3510 if (selection->getDepth()==1)
3511 // If we have moved mainbranch only save endposition
3512 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos)));
3514 // Draw the original link, before selection was moved around
3515 mapCenter->reposition();
3517 // Finally resize canvas, if needed
3522 // maybe we moved View: set old cursor
3523 setCursor (ArrowCursor);
3527 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3529 // Finish open lineEdits
3530 if (lineedit) finishedLineEdit();
3532 if (e->button() == QMouseEvent::LeftButton )
3534 QPoint p = inverseWorldMatrix().map(e->pos());
3535 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3536 if (lmo) { // MapObj was found
3537 // First select the MapObj than edit heading
3538 if (selection) selection->unselect();
3540 selection->select();
3546 void MapEditor::resizeEvent (QResizeEvent* e)
3548 QCanvasView::resizeEvent( e );
3552 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3555 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3556 // cerr << event->format(i) << endl;
3559 (typeid(*selection) == typeid(BranchObj)) ||
3560 (typeid(*selection) == typeid(MapCenterObj))) {
3562 // If QImageDrag can decode mime type
3563 if (QImageDrag::canDecode(event)) {
3568 // If image are dragged from firefox
3569 if (event->provides("application/x-moz-file-promise-url") &&
3570 event->provides("application/x-moz-nativeimage")) {
3571 event->accept(true);
3575 // If QUriDrag can decode mime type
3576 if (QUriDrag::canDecode(event)) {
3581 // If Uri are dragged from firefox
3582 if (event->provides("_NETSCAPE_URL")){
3587 // If QTextDrag can decode mime type
3588 if (QTextDrag::canDecode(event)) {
3597 bool isUnicode16(const QByteArray &d)
3599 // TODO: make more precise check for unicode 16.
3600 // Guess unicode16 if any of second bytes are zero
3601 unsigned int length = max(0,d.size()-2)/2;
3602 for (unsigned int i = 0; i<length ; i++)
3603 if (d.at(i*2+1)==0) return true;
3607 void MapEditor::contentsDropEvent(QDropEvent *event)
3610 (typeid(*selection) == typeid(BranchObj)) ||
3611 (typeid(*selection) == typeid(MapCenterObj)))
3616 if (event->provides("image/png"))
3619 if (QImageDrag::decode(event, pix))
3627 } else if (event->provides("application/x-moz-file-promise-url") &&
3628 event->provides("application/x-moz-nativeimage"))
3630 // Contains url to the img src in unicode16
3631 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3632 QString url = QString((const QChar*)d.data(),d.size()/2);
3636 } else if (event->provides ("text/uri-list"))
3637 { // Uris provided e.g. by konqueror
3638 QUriDrag::decode (event,uris);
3639 } else if (event->provides ("_NETSCAPE_URL"))
3640 { // Uris provided by Mozilla
3641 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3644 } else if (event->provides("text/html")) {
3646 // Handels text mime types
3647 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3648 QByteArray d = event->encodedData("text/html");
3651 text = QString((const QChar*)d.data(),d.size()/2);
3655 textEditor->setText(text);
3659 } else if (event->provides("text/plain")) {
3660 QByteArray d = event->encodedData("text/plain");
3663 text = QString((const QChar*)d.data(),d.size()/2);
3667 textEditor->setText(text);
3679 for (const char* u=uris.first(); u; u=uris.next())
3681 bo=((BranchObj*)selection)->addBranch();
3684 s=QUriDrag::uriToLocalFile(u);
3686 QString file = QDir::convertSeparators(s);
3687 heading = QFileInfo(file).baseName();
3689 if (file.endsWith(".vym", false))
3690 bo->setVymLink(file);
3699 bo->setHeading(heading);
3709 //FIXME saveState has to be called earlier for each of the drops...
3710 saveState("Drop Event"); //TODO undo Command
3711 mapCenter->reposition();
3718 void MapEditor::addFloatImage(const QPixmap &img)
3721 (typeid(*selection) == typeid(BranchObj)) ||
3722 (typeid(*selection) == typeid(MapCenterObj)) )
3724 BranchObj *bo=((BranchObj*)selection);
3725 saveState(selection,QString("Add floatimage to %1").arg(getName(bo)));
3726 //QString fn=fd->selectedFile();
3727 //lastImageDir=fn.left(fn.findRev ("/"));
3728 bo->addFloatImage();
3729 // FIXME check if load was successful
3730 bo->getLastFloatImage()->load(img);
3731 //bo->getLastFloatImage()->setOriginalFilename(fn);
3732 mapCenter->reposition();
3739 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3741 if (!imageBuffer) imageBuffer = new QBuffer();
3742 if (!imageBuffer->isOpen()) {
3743 imageBuffer->open(IO_WriteOnly | IO_Append);
3745 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3749 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3751 if (nop->state()==QNetworkProtocol::StDone) {
3752 QPixmap img(imageBuffer->buffer());
3757 imageBuffer->close();
3759 imageBuffer->close();
3766 void MapEditor::fetchImage(const QString &url)
3769 urlOperator->stop();
3770 disconnect(urlOperator);
3774 urlOperator = new QUrlOperator(url);
3775 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3776 this, SLOT(imageDataFinished(QNetworkOperation*)));
3778 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3779 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));