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 int MapEditor::mapNum=0; // make instance
130 ///////////////////////////////////////////////////////////////////////
131 ///////////////////////////////////////////////////////////////////////
132 MapEditor::MapEditor(
133 QWidget* parent, bool interactive, const char* name, WFlags f) :
134 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
136 //cout << "Constructor ME "<<this<<endl;
139 viewport()->setAcceptDrops(true);
141 mapCanvas = new QCanvas(1000,800);
142 mapCanvas->setAdvancePeriod(30);
143 mapCanvas->setBackgroundColor (white);
145 setCanvas (mapCanvas);
147 // Always show scroll bars (automatic would flicker sometimes)
148 setVScrollBarMode ( QScrollView::AlwaysOn );
149 setHScrollBarMode ( QScrollView::AlwaysOn );
151 mapCenter = new MapCenterObj(mapCanvas);
152 mapCenter->setVisibility (true);
153 mapCenter->setMapEditor (this);
154 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
155 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
159 lineedit = new QLineEdit(this, "lineedit" );
160 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
163 actColor=black; setColor (actColor);
164 defLinkColor=QColor (0,0,255);
165 defXLinkColor=QColor (180,180,180);
166 linkcolorhint=DefaultColor;
167 linkstyle=StylePolyParabel;
169 // Create bitmap cursors, patform dependant
170 #if defined(Q_OS_MACX)
171 #include "icons/cursorhandopen16.xpm"
172 #include "icons/cursorcolorpicker16.xpm"
173 QBitmap cb( 16, 16, chandopen, TRUE );
174 QBitmap cm( 16, 16, chandopenmask, TRUE );
175 handOpenCursor=QCursor ( cb, cm );
176 // set hot spot to tip of picker
177 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
179 #include "icons/cursorhandopen.xpm"
180 #include "icons/cursorcolorpicker.xpm"
182 QBitmap cb( 32, 32, chandopen, TRUE );
183 QBitmap cm( 32, 32, chandopenmask, TRUE );
184 handOpenCursor=QCursor ( cb, cm );
185 // set hot spot to tip of picker
186 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
199 defXLinkColor=QColor (230,230,230);
210 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
214 // Initialize find routine
221 blockReposition=false;
222 blockSaveState=false;
226 isInteractive=interactive;
228 // Create temporary files
231 // Initially set movingCentre
234 mapCenter->reposition(); // for positioning heading
237 MapEditor::~MapEditor()
239 if (imageBuffer) delete imageBuffer;
245 //cout <<"Destructor MapEditor\n";
248 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
252 QColor MapEditor::color()
257 QColor MapEditor::backgroundColor()
259 return mapCanvas->backgroundColor();
262 MapCenterObj* MapEditor::getMapCenter()
267 QCanvas* MapEditor::getCanvas()
272 void MapEditor::adjustCanvasSize()
274 // To adjust the canvas to map, viewport size and position, we have to
275 // do some coordinate magic...
277 // Get rectangle of (scroll-)view.
278 // We want to be in canvas coords, so
279 // we map. Important if view is zoomed...
280 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
281 visibleWidth(), visibleHeight()) );
283 // Now we need the bounding box of view AND map to calc the correct canvas size.
284 // Why? Because if the map itself is moved out of view, the view has to be enlarged
285 // to avoid jumping aroung...
286 QRect map=mapCenter->getTotalBBox();
288 // right edge - left edge
289 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
290 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
293 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
294 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
297 // move the map on canvas (in order to not move it on screen) this is neccessary
298 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
299 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
300 // to scroll to an empty area of canvas to the left.
301 // b) if topleft corner of map left of or above topleft of canvas
305 if (cw > mapCanvas->width() )
307 if (map.x()<0) dx=-map.x();
309 if (cw < mapCanvas->width() )
310 dx=-min (view.x(),map.x());
311 if (ch > mapCanvas->height() )
313 if (map.y()<0) dy=-map.y();
315 if (ch < mapCanvas->height() )
317 dy=-min (view.y(),map.y());
319 // We really have to resize now. Let's go...
320 mapCanvas->resize (cw,ch);
321 if ( (dx!=0) || (dy!=0) )
323 mapCenter->moveAllBy(dx,dy);
324 mapCenter->reposition();
326 // scroll the view (in order to not move map on screen)
332 bool MapEditor::isRepositionBlocked()
334 return blockReposition;
337 void MapEditor::makeTmpDirs()
339 // Create unique temporary directories
340 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
342 d.mkdir (tmpMapDir,true);
345 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
347 // tmpdir temporary directory to which data will be written
348 // prefix mapname, which will be appended to images etc.
349 // writeflags Only write flags for "real" save of map, not undo
350 // offset offset of bbox of whole map in canvas.
351 // Needed for XML export
367 ls="StylePolyParabel";
371 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
373 if (linkcolorhint==HeadingColor)
374 colhint=attribut("linkColorHint","HeadingColor");
376 QString mapAttr=attribut("version",__VYM_VERSION);
378 mapAttr+= attribut("author",mapCenter->getAuthor()) +
379 attribut("comment",mapCenter->getComment()) +
380 attribut("date",mapCenter->getDate()) +
381 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
382 attribut("linkStyle", ls ) +
383 attribut("linkColor", defLinkColor.name() ) +
384 attribut("defXLinkColor", defXLinkColor.name() ) +
385 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
387 s+=beginElement("vymmap",mapAttr);
390 // Find the used flags while traversing the tree
391 standardFlagsDefault->resetUsedCounter();
393 // Reset the counters before saving
394 FloatImageObj (mapCanvas).resetSaveCounter();
396 // Build xml recursivly
398 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
401 if ( typeid(*saveSelection) == typeid(BranchObj) )
402 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
403 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
404 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
406 else if (selection && typeid(*selection)==typeid(BranchObj))
407 // This is used if selected branch is saved from mainwindow
408 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
411 // Save local settings
412 s+=settings.getXMLData (destPath);
415 if (selection && !saveSelection )
416 s+=valueElement("select",selection->getSelectString());
419 s+=endElement("vymmap");
422 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
426 void MapEditor::saveState()
429 saveState (CompleteMap,"",NULL,"",NULL);
432 void MapEditor::saveState(LinkableMapObj *undoSel)
434 // save the given part of the map
435 saveState (PartOfMap,"",undoSel,"",NULL);
438 void MapEditor::saveState(const QString &uc, const QString &rc)
440 // selection does not change during action,
441 // so just save commands for undo and redo
442 LinkableMapObj *unsel;
447 saveState (UndoCommand,uc,unsel,rc,unsel);
450 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel)
452 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL);
455 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel)
459 if (blockSaveState) return;
461 /* TODO remove after testing
462 cout << "ME::saveState() begin\n"<<endl;
463 cout << " undosTotal="<<undosTotal<<endl;
464 cout << " undosAvail="<<undosAvail<<endl;
465 cout << " undoNum="<<undoNum<<endl;
466 cout << " ---------------------------"<<endl;
470 // Find out current undo directory
471 if (undosAvail<undosTotal) undosAvail++;
473 if (undoNum>undosTotal) undoNum=1;
476 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
477 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
479 // Create bakMapDir if not available
482 makeSubDirs (bakMapDir);
484 // Save current selection
485 QString redoSelection="";
487 redoSelection=redoSel->getSelectString();
489 // Save the object, which should be undone
490 QString undoSelection="";
492 undoSelection=undoSel->getSelectString();
494 // Save depending on how much needs to be saved
495 QString undoCommand="";
496 if (savemode==UndoCommand)
501 else if (savemode==PartOfMap && undoSel)
503 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
504 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
507 undoCommand="undoMap (\""+bakMapPath+"\")";
508 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
511 if (!backupXML.isEmpty())
512 // Write XML Data to disk
513 saveStringToDisk (QString(bakMapPath),backupXML);
516 set.setEntry (QString("undoCommand"),undoCommand);
517 set.setEntry (QString("undoSelection"),undoSelection);
518 set.setEntry (QString("redoCommand"),redoCom);
519 set.setEntry (QString("redoSelection"),redoSelection);
520 set.writeSettings(QString(bakMapDir+"/commands"));
522 /* TODO remove after testing
523 cout << " into="<< bakMapDir<<endl;
524 cout << " undosAvail="<<undosAvail<<endl;
525 cout << " undoNum="<<undoNum<<endl;
526 cout << " ---------------------------"<<endl;
527 cout << " undoCom="<<undoCommand<<endl;
528 cout << " undoSel="<<undoSelection<<endl;
529 cout << " ---------------------------"<<endl;
530 cout << " redoCom="<<redoCom<<endl;
531 cout << " redoSel="<<redoSelection<<endl;
532 cout << " ---------------------------"<<endl<<endl;
536 void MapEditor::parseAtom(const QString &atom)
543 // Split string s into command and parameters
544 api.parseCommand (atom);
545 QString com=api.command();
548 if (com=="moveBranchUp")
550 else if (com=="moveBranchDown")
552 else if (com=="move")
554 if (api.checkParamCount(2) && selection )
564 else if (com=="linkBranchToPos")
566 if (selection && typeid(*selection) == typeid(BranchObj) )
568 if (api.checkParamCount(4))
570 s=api.parString(ok,0);
571 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
574 if (typeid(*dst) == typeid(BranchObj) )
576 // Get number in parent
579 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
580 } else if (typeid(*dst) == typeid(MapCenterObj) )
582 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
583 // Get coordinates of mainbranch
588 if (ok) ((BranchObj*)selection)->move (x,y);
594 } else if (com=="setHeading")
596 if (api.checkParamCount(1))
598 s=api.parString (ok,0);
599 if (ok) setHeading (s);
601 } else if (com=="setURL")
603 if (api.checkParamCount(1))
605 s=api.parString (ok,0);
608 } else if (com=="setVymLink")
610 if (api.checkParamCount(1))
612 s=api.parString (ok,0);
613 if (ok) setVymLink(s);
616 // Internal commands, used for undo etc.
617 else if (com==QString("undoMap"))
619 if (api.checkParamCount(1))
620 undoXML("",api.parString (ok,0));
621 } else if (com==QString("undoPart"))
623 if (api.checkParamCount(2))
625 s=api.parString (ok,0);
626 t=api.parString (ok,1);
629 } else if (com=="select")
630 if (api.checkParamCount(1))
632 s=api.parString(ok,0);
637 api.setError ("Unknown command in: "+atom);
638 cout << "ME::parse api should have error now...\n";
644 cout << "MapEditor::parseAtom: Error!\n";
645 cout << " "<<api.errorDesc()<<endl;
650 void MapEditor::finishedLineEditNoSave()
652 // This is called by finishedLineEdit or any MapEditor method,
653 // which wants to assure, that lineedits finish, before e.g. a branch is
656 // After calling LineEdit and using the clipboard, the
657 // focus is not any longer on the main widget, we
658 // have to restore it using parentWidget()->setFocus()
662 editingBO->setHeading(lineedit->text() );
664 lineedit->releaseKeyboard();
666 parentWidget()->setFocus();
667 mapCenter->reposition();
669 ensureSelectionVisible();
674 bool MapEditor::isDefault()
679 bool MapEditor::isUnsaved()
684 bool MapEditor::hasChanged()
689 void MapEditor::setChanged()
694 actionEditUndo->setEnabled (true);
695 actionFileSave->setEnabled (true);
699 void MapEditor::closeMap()
701 // Finish open lineEdits
702 if (lineedit) finishedLineEditNoSave();
704 // Unselect before disabling the toolbar actions
705 if (selection) selection->unselect();
713 void MapEditor::setFilePath(QString fname)
715 setFilePath (fname,fname);
718 void MapEditor::setFilePath(QString fname, QString destname)
720 if (fname.isEmpty() || fname=="")
727 filePath=fname; // becomes absolute path
728 fileName=fname; // gets stripped of path
729 destPath=destname; // needed for vymlinks
731 // If fname is not an absolute path, complete it
732 filePath=QDir(fname).absPath();
733 fileDir=filePath.left (1+filePath.findRev ("/"));
735 // Set short name, too. Search from behind:
736 int i=fileName.findRev("/");
737 if (i>=0) fileName=fileName.remove (0,i+1);
739 // Forget the .vym (or .xml) for name of map
740 mapName=fileName.left(fileName.findRev(".",-1,true) );
744 QString MapEditor::getFilePath()
749 QString MapEditor::getFileName()
754 QString MapEditor::getMapName()
759 QString MapEditor::getDestPath()
764 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
766 // Finish open lineEdits
767 if (lineedit) finishedLineEditNoSave();
769 ErrorCode err=success;
773 if (selection) selection->unselect();
776 mapCenter->setMapEditor(this);
777 // (map state is set later at end of load...)
780 saveState(selection);
784 mapBuilderHandler handler;
787 // I am paranoid: file should exist anyway
788 // according to check in mainwindow.
791 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
792 tr("Couldn't open map " +fname)+".");
796 blockReposition=true;
797 QXmlInputSource source( file);
798 QXmlSimpleReader reader;
799 reader.setContentHandler( &handler );
800 reader.setErrorHandler( &handler );
801 handler.setMapEditor( this );
802 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
803 handler.setInputFile (file.name());
804 handler.setLoadMode (lmode);
806 bool ok = reader.parse( source );
807 blockReposition=false;
808 blockSaveState=false;
812 mapCenter->reposition();
822 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
823 tr( handler.errorProtocol() ) );
825 // Still return "success": the map maybe at least
826 // partially read by the parser
833 int MapEditor::save (const SaveMode &savemode)
835 // Finish open lineEdits
836 if (lineedit) finishedLineEditNoSave();
840 // The SaveMode UndoCommand is not supported here
841 if (savemode==UndoCommand) return 1;
843 // Create mapName and fileDir
844 makeSubDirs (fileDir);
848 fname=mapName+".xml";
850 // use name given by user, even if he chooses .doc
855 if (savemode==CompleteMap || selection==NULL)
856 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
858 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
860 if (!saveStringToDisk(fileDir+fname,saveFile))
867 actionFileSave->setEnabled(false);
873 void MapEditor::setZipped (bool z)
878 bool MapEditor::saveZipped ()
883 void MapEditor::print()
885 // Finish open lineEdits
886 if (lineedit) finishedLineEditNoSave();
890 printer = new QPrinter;
891 printer->setColorMode (QPrinter::Color);
892 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
895 QRect totalBBox=mapCenter->getTotalBBox();
897 // Try to set orientation automagically
898 // Note: Interpretation of generated postscript is amibiguous, if
899 // there are problems with landscape mode, see
900 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
902 if (totalBBox.width()>totalBBox.height())
903 // recommend landscape
904 printer->setOrientation (QPrinter::Landscape);
906 // recommend portrait
907 printer->setOrientation (QPrinter::Portrait);
909 if ( printer->setup(this) )
910 // returns false, if printing is canceled
912 QPainter pp(printer);
914 // Don't print the visualisation of selection
915 LinkableMapObj *oldselection=NULL;
918 oldselection=selection;
919 selection->unselect();
922 // Handle sizes of map and paper:
924 // setWindow defines which part of the canvas will be transformed
925 // setViewport defines area on paper in device coordinates (dpi)
926 // e.g. (0,50,700,700) is upper part on A4
927 // see also /usr/lib/qt3/doc/html/coordsys.html
929 QPaintDeviceMetrics metrics (printer);
931 double paperAspect = (double)metrics.width() / (double)metrics.height();
932 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
934 QRect mapRect=totalBBox;
935 QCanvasRectangle *frame=NULL;
936 QCanvasText *footerFN=NULL;
937 QCanvasText *footerDate=NULL;
938 if (printFrame || printFooter)
943 // Print frame around map
944 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
945 totalBBox.width()+20, totalBBox.height()+20);
946 frame=new QCanvasRectangle (mapRect,mapCanvas);
947 frame->setBrush (QColor(white));
948 frame->setPen (QColor(black));
952 /* TODO remove after testing
953 QCanvasLine *l=new QCanvasLine (mapCanvas);
954 l->setPoints (0,0,mapRect.width(),mapRect.height());
955 l->setPen (QPen(QColor(black), 1));
962 // Print footer below map
964 font.setPointSize(10);
965 footerFN=new QCanvasText (mapCanvas);
966 footerFN->setText ("VYM - " + fileName);
967 footerFN->setFont(font);
968 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
969 footerFN->setZ(Z_TEXT);
971 footerDate=new QCanvasText (mapCanvas);
972 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
973 footerDate->setFont(font);
974 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
975 footerDate->setZ(Z_TEXT);
978 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
981 pp.setWindow (mapRect);
984 if (mapAspect>=paperAspect)
986 // Fit horizontally to paper width
987 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
990 // Fit vertically to paper height
991 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
994 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
996 // Delete Frame and footer
1000 delete (footerDate);
1002 if (frame) delete (frame);
1004 // Restore selection
1007 selection=oldselection;
1008 selection->select();
1011 // Save settings in vymrc
1012 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1016 QPixmap MapEditor::getPixmap()
1018 QRect mapRect=mapCenter->getTotalBBox();
1019 QPixmap pix (mapRect.size());
1022 // Don't print the visualisation of selection
1023 LinkableMapObj *oldselection=NULL;
1026 oldselection=selection;
1027 selection->unselect();
1030 pp.setWindow (mapRect);
1032 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1035 // Restore selection
1038 selection=oldselection;
1039 selection->select();
1045 void MapEditor::setHideTmpMode (HideTmpMode mode)
1048 mapCenter->setHideTmp (hidemode);
1049 mapCenter->reposition();
1054 HideTmpMode MapEditor::getHideTmpMode()
1059 void MapEditor::exportImage(QString fn)
1061 // Finish open lineEdits
1062 if (lineedit) finishedLineEditNoSave();
1064 setExportMode (true);
1065 QPixmap pix (getPixmap());
1066 pix.save(fn, "PNG");
1067 setExportMode (false);
1070 void MapEditor::setExportMode (bool b)
1072 // should be called before and after exports
1073 // depending on the settings
1074 if (b && settings.readEntry("/vym/export/useHideExport","yes"))
1075 setHideTmpMode (HideExport);
1077 setHideTmpMode (HideNone);
1080 void MapEditor::exportImage(QString fn, int item)
1082 // Finish open lineEdits
1083 if (lineedit) finishedLineEditNoSave();
1085 setExportMode (true);
1086 QPixmap pix (getPixmap());
1087 pix.save(fn, exportImageFormatMenu->text(item) );
1088 setExportMode (false);
1091 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1095 ex.setMapCenter(mapCenter);
1096 if (ex.setConfigFile(cf))
1098 setExportMode (true);
1099 ex.exportPresentation();
1100 setExportMode (false);
1106 void MapEditor::exportXML(const QString &dir)
1108 // Hide stuff during export, if settings want this
1109 setExportMode (true);
1111 // Create subdirectories
1114 // write to directory
1115 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1118 file.setName ( dir + "/"+mapName+".xml");
1119 if ( !file.open( IO_WriteOnly ) )
1121 // This should neverever happen
1122 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1126 // Write it finally, and write in UTF8, no matter what
1127 QTextStream ts( &file );
1128 ts.setEncoding (QTextStream::UnicodeUTF8);
1132 // Now write image, too
1133 exportImage (dir+"/images/"+mapName+".png");
1135 setExportMode (false);
1138 void MapEditor::clear()
1142 selection->unselect();
1149 void MapEditor::copy()
1151 // Finish open lineEdits
1152 if (lineedit) finishedLineEditNoSave();
1156 // write to directory
1157 QString clipfile="part";
1158 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1161 file.setName ( clipboardDir + "/"+clipfile+".xml");
1162 if ( !file.open( IO_WriteOnly ) )
1164 // This should neverever happen
1165 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1169 // Write it finally, and write in UTF8, no matter what
1170 QTextStream ts( &file );
1171 ts.setEncoding (QTextStream::UnicodeUTF8);
1175 clipboardEmpty=false;
1180 void MapEditor::redo()
1182 // Finish open lineEdits
1183 if (lineedit) finishedLineEditNoSave();
1185 blockSaveState=true;
1187 // Find out current undo directory
1188 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1190 // Restore variables
1191 QString undoCommand;
1192 QString undoSelection;
1193 QString redoCommand;
1194 QString redoSelection;
1196 set.readSettings(QString(bakMapDir+"/commands"));
1197 undoCommand=set.readEntry ("undoCommand");
1198 undoSelection=set.readEntry ("undoSelection");
1199 redoCommand=set.readEntry ("redoCommand");
1200 redoSelection=set.readEntry ("redoSelection");
1202 // select object before redo
1203 if (!redoSelection.isEmpty())
1204 select (redoSelection);
1206 /* TODO remove testing
1207 cout << "ME::redo() begin\n";
1208 cout << " undosTotal="<<undosTotal<<endl;
1209 cout << " undosAvail="<<undosAvail<<endl;
1210 cout << " undoNum="<<undoNum<<endl;
1211 cout << " ---------------------------"<<endl;
1212 cout << " undoCom="<<undoCommand<<endl;
1213 cout << " undoSel="<<undoSelection<<endl;
1214 cout << " ---------------------------"<<endl;
1215 cout << " redoCom="<<redoCommand<<endl;
1216 cout << " redoSel="<<redoSelection<<endl;
1217 cout << " ---------------------------"<<endl;
1219 parseAtom (undoCommand);
1220 mapCenter->reposition();
1222 //if (!redoSelection.isEmpty())
1223 // select (redoSelection);
1227 // Undo not longer available now
1228 actionEditUndo->setEnabled (false);
1230 undoNum--; if (undoNum<1) undoNum=undosTotal;
1232 blockSaveState=false;
1233 /* TODO remove testing
1234 cout << "ME::redo() end\n";
1235 cout << " undosAvail="<<undosAvail<<endl;
1236 cout << " undoNum="<<undoNum<<endl;
1237 cout << " ---------------------------"<<endl<<endl;
1241 void MapEditor::undo()
1243 // Finish open lineEdits
1244 if (lineedit) finishedLineEditNoSave();
1246 blockSaveState=true;
1248 // Find out current undo directory
1249 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1251 // Restore variables
1252 QString undoCommand;
1253 QString undoSelection;
1254 QString redoCommand;
1255 QString redoSelection;
1257 set.readSettings(QString(bakMapDir+"/commands"));
1258 undoCommand= set.readEntry ("undoCommand");
1259 undoSelection=set.readEntry ("undoSelection");
1260 redoCommand= set.readEntry ("redoCommand");
1261 redoSelection=set.readEntry ("redoSelection");
1263 // select object before undo
1264 if (!undoSelection.isEmpty())
1265 select (undoSelection);
1268 cout << "ME::undo() begin\n";
1269 cout << " undosTotal="<<undosTotal<<endl;
1270 cout << " undosAvail="<<undosAvail<<endl;
1271 cout << " undoNum="<<undoNum<<endl;
1272 cout << " ---------------------------"<<endl;
1273 cout << " undoCom="<<undoCommand<<endl;
1274 cout << " undoSel="<<undoSelection<<endl;
1275 cout << " ---------------------------"<<endl;
1276 cout << " redoCom="<<redoCommand<<endl;
1277 cout << " redoSel="<<redoSelection<<endl;
1278 cout << " ---------------------------"<<endl;
1280 parseAtom (undoCommand);
1281 mapCenter->reposition();
1283 //if (!redoSelection.isEmpty())
1284 // select (redoSelection);
1288 // Undo not longer available now
1289 actionEditUndo->setEnabled (false);
1291 undoNum--; if (undoNum<1) undoNum=undosTotal;
1293 blockSaveState=false;
1294 /* TODO remove testing
1295 cout << "ME::undo() end\n";
1296 cout << " undosAvail="<<undosAvail<<endl;
1297 cout << " undoNum="<<undoNum<<endl;
1298 cout << " ---------------------------"<<endl<<endl;
1302 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1304 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1306 QFile file (bakMapPath);
1310 // We need to parse saved XML data
1311 mapBuilderHandler handler;
1312 QXmlInputSource source( file);
1313 QXmlSimpleReader reader;
1314 reader.setContentHandler( &handler );
1315 reader.setErrorHandler( &handler );
1316 handler.setMapEditor( this );
1317 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1318 if (undoSel.isEmpty())
1322 handler.setLoadMode (NewMap);
1326 handler.setLoadMode (ImportReplace);
1328 blockReposition=true;
1329 bool ok = reader.parse( source );
1330 blockReposition=false;
1333 // This should never ever happen
1334 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1335 tr( handler.errorProtocol() )+" in "+bakMapDir );
1339 QMessageBox::critical( 0, tr( "Critical Error" ),
1340 tr("Temporary directory %1 used for undo is gone. \n"
1341 "I will create a new one, but at the moment no undo is available.\n"
1342 "Maybe you want to reload your original data.\n\n"
1343 "Sorry for any inconveniences.").arg(bakMapDir) );
1348 void MapEditor::pasteNoSave()
1350 // Finish open lineEdits
1351 if (lineedit) finishedLineEditNoSave();
1353 load (clipboardDir+"/part.xml",ImportAdd);
1356 void MapEditor::cutNoSave()
1362 void MapEditor::paste()
1364 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1365 typeid(*selection) == typeid(MapCenterObj)))
1367 saveState(selection);
1369 mapCenter->reposition();
1374 void MapEditor::cut()
1376 saveState(selection->getParObj());
1379 mapCenter->reposition();
1383 void MapEditor::move(const int &x, const int &y)
1385 // TODO no saveState, because this is only internal at undo so far
1386 if (selection) selection->move(x,y);
1387 if (typeid(*selection) == typeid(FloatImageObj))
1388 ((FloatImageObj*)selection)->setRelPos();
1391 void MapEditor::moveBranchUp()
1393 // Finish open lineEdits
1394 if (lineedit) finishedLineEditNoSave();
1398 if (typeid(*selection) == typeid(BranchObj) )
1400 bo=(BranchObj*)selection;
1401 par=(BranchObj*)(bo->getParObj());
1402 selection->unselect();
1403 selection=par->moveBranchUp (bo);
1404 selection->select();
1405 saveState("moveBranchDown ()",bo);
1406 mapCenter->reposition();
1407 ensureSelectionVisible();
1411 void MapEditor::moveBranchDown()
1413 // Finish open lineEdits
1414 if (lineedit) finishedLineEditNoSave();
1418 if (typeid(*selection) == typeid(BranchObj) )
1420 bo=(BranchObj*)selection;
1421 par=(BranchObj*)(bo->getParObj());
1422 selection->unselect();
1423 selection=par->moveBranchDown(bo);
1424 selection->select();
1425 saveState("moveBranchUp ()",bo);
1426 mapCenter->reposition();
1427 ensureSelectionVisible();
1431 void MapEditor::editHeading()
1433 // Finish open lineEdits
1434 if (lineedit) finishedLineEditNoSave();
1437 (typeid(*selection) == typeid(BranchObj) ||
1438 typeid(*selection) == typeid(MapCenterObj) ) )
1440 editingBO=(BranchObj*)selection;
1441 saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
1443 ensureSelectionVisible();
1444 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1445 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1446 QString s=editingBO->getHeading();
1447 lineedit->setText(s);
1448 lineedit->setCursorPosition(1);
1449 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1450 lineedit->selectAll();
1452 lineedit->grabKeyboard();
1453 lineedit->setFocus();
1457 void MapEditor::setHeading(const QString &s)
1459 // Internal function, no saveState needed
1461 (typeid(*selection) == typeid(BranchObj) ||
1462 typeid(*selection) == typeid(MapCenterObj) ) )
1464 ((BranchObj*)selection)->setHeading(s);
1465 mapCenter->reposition();
1467 ensureSelectionVisible();
1471 void MapEditor::setURL (const QString &s)
1473 // Internal function, no saveState needed
1475 (typeid(*selection) == typeid(BranchObj) ||
1476 typeid(*selection) == typeid(MapCenterObj) ) )
1478 ((BranchObj*)selection)->setURL(s);
1479 mapCenter->reposition();
1481 ensureSelectionVisible();
1485 void MapEditor::setVymLink (const QString &s)
1487 // Internal function, no saveState needed
1489 (typeid(*selection) == typeid(BranchObj) ||
1490 typeid(*selection) == typeid(MapCenterObj) ) )
1492 ((BranchObj*)selection)->setVymLink(s);
1493 mapCenter->reposition();
1495 ensureSelectionVisible();
1499 void MapEditor::addNewBranch(int pos)
1501 // Finish open lineEdits
1502 if (lineedit) finishedLineEditNoSave();
1505 (typeid(*selection) == typeid(BranchObj) ||
1506 typeid(*selection) == typeid(MapCenterObj) ) )
1508 saveState(selection); //TODO undoCommand
1510 BranchObj* bo1 = (BranchObj*) selection;
1511 bool wasScrolled=false;
1512 BranchObj *newbo=NULL;
1515 // save scroll state. If scrolled, automatically select
1516 // new branch in order to tmp unscroll parent...
1517 wasScrolled=bo1->isScrolled();
1518 newbo=bo1->addBranch();
1521 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1525 // add above selection
1526 newbo=parbo->insertBranch(bo1->getNum());
1528 // add below selection
1529 newbo=parbo->insertBranch(bo1->getNum()+1);
1531 // This should not happen...
1536 LinkableMapObj *oldselection=selection;
1538 mapCenter->reposition();
1540 if (actionSettingsAutoedit->isOn() ||
1541 actionSettingsAutoselectHeading->isOn() )
1543 selection->unselect();
1545 selection->select();
1546 if (actionSettingsPasteNewHeading->isOn() )
1548 BranchObj *bo2= (BranchObj*)selection;
1549 bo2->setHeading("");
1551 if (actionSettingsAutoedit->isOn() )
1553 if (!actionSettingsAutoselectHeading->isOn()
1556 selection->unselect();
1557 selection=oldselection;
1558 selection->select();
1565 void MapEditor::addNewBranchHere()
1567 // Finish open lineEdits
1568 if (lineedit) finishedLineEditNoSave();
1571 (typeid(*selection) == typeid(BranchObj) ) )
1573 saveState(selection);
1575 BranchObj* bo1 = (BranchObj*) selection;
1576 bool wasScrolled=false;
1577 BranchObj *newbo=NULL;
1578 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1581 // add below selection
1582 newbo=parbo->insertBranch(bo1->getNum()+1);
1585 LinkableMapObj *oldselection=selection;
1586 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1588 mapCenter->reposition();
1590 if (actionSettingsAutoedit->isOn() ||
1591 actionSettingsAutoselectHeading->isOn() )
1593 selection->unselect();
1595 selection->select();
1596 if (actionSettingsPasteNewHeading->isOn() )
1598 BranchObj *bo2= (BranchObj*)selection;
1599 bo2->setHeading("");
1601 if (actionSettingsAutoedit->isOn() )
1603 if (!actionSettingsAutoselectHeading->isOn()
1606 selection->unselect();
1607 selection=oldselection;
1608 selection->select();
1614 void MapEditor::deleteSelection()
1616 // Finish open lineEdits
1617 if (lineedit) finishedLineEditNoSave();
1619 if (selection && typeid(*selection) ==typeid(BranchObj) )
1621 if (selection->getDepth()>1)
1622 // Normal branch, save parent with childs
1623 saveState(selection->getParObj());
1625 // Mainbranch, save whole map
1626 // TODO Better would be to insert mainbranch again at pos
1627 // But undoCommand is missing right now
1629 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1630 BranchObj* par=(BranchObj*)(bo->getParObj());
1633 par->removeBranch(bo);
1635 selection->select();
1636 ensureSelectionVisible();
1637 mapCenter->reposition();
1640 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1642 saveState(selection->getParObj());
1643 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1644 BranchObj* par=(BranchObj*)(fio->getParObj());
1647 par->removeFloatImage(fio);
1649 selection->select();
1650 ensureSelectionVisible();
1651 mapCenter->reposition();
1656 LinkableMapObj* MapEditor::getSelection()
1661 bool MapEditor::select (const QString &s)
1663 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1665 // Finally select the found object
1668 if (selection) unselect();
1670 selection->select();
1672 ensureSelectionVisible();
1678 void MapEditor::unselect()
1682 selectionLast=selection;
1683 selection->unselect();
1688 void MapEditor::reselect()
1692 selection=selectionLast;
1693 selection->select();
1698 void MapEditor::selectNextBranch()
1700 // Increase number of branch
1703 QString s=selection->getSelectString();
1709 part=s.section(",",-1);
1711 num=part.right(part.length() - 3);
1713 s=s.left (s.length() -num.length());
1716 num=QString ("%1").arg(num.toUInt()+1);
1720 // Try to select this one
1721 if (select (s)) return;
1723 // We have no direct successor,
1724 // try to increase the parental number in order to
1725 // find a successor with same depth
1727 int d=selection->getDepth();
1732 while (!found && d>0)
1734 s=s.section (",",0,d-1);
1735 // replace substring of current depth in s with "1"
1736 part=s.section(",",-1);
1738 num=part.right(part.length() - 3);
1742 // increase number of parent
1743 num=QString ("%1").arg(num.toUInt()+1);
1744 s=s.section (",",0,d-2) + ","+ typ+num;
1747 // Special case, look at orientation
1748 if (selection->getOrientation()==OrientRightOfCenter)
1749 num=QString ("%1").arg(num.toUInt()+1);
1751 num=QString ("%1").arg(num.toUInt()-1);
1756 // pad to oldDepth, select the first branch for each depth
1757 for (i=d;i<oldDepth;i++)
1762 if ( ((BranchObj*)selection)->countBranches()>0)
1770 // try to select the freshly built string
1778 void MapEditor::selectPrevBranch()
1780 // Decrease number of branch
1783 QString s=selection->getSelectString();
1789 part=s.section(",",-1);
1791 num=part.right(part.length() - 3);
1793 s=s.left (s.length() -num.length());
1796 num=QString ("%1").arg(num.toUInt()-1);
1800 // Try to select this one
1801 if (select (s)) return;
1803 // We have no direct precessor,
1804 // try to decrease the parental number in order to
1805 // find a precessor with same depth
1807 int d=selection->getDepth();
1812 while (!found && d>0)
1814 s=s.section (",",0,d-1);
1815 // replace substring of current depth in s with "1"
1816 part=s.section(",",-1);
1818 num=part.right(part.length() - 3);
1822 // decrease number of parent
1823 num=QString ("%1").arg(num.toUInt()-1);
1824 s=s.section (",",0,d-2) + ","+ typ+num;
1827 // Special case, look at orientation
1828 if (selection->getOrientation()==OrientRightOfCenter)
1829 num=QString ("%1").arg(num.toUInt()-1);
1831 num=QString ("%1").arg(num.toUInt()+1);
1836 // pad to oldDepth, select the last branch for each depth
1837 for (i=d;i<oldDepth;i++)
1841 if ( ((BranchObj*)selection)->countBranches()>0)
1842 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1849 // try to select the freshly built string
1857 void MapEditor::selectUpperBranch()
1859 // Finish open lineEdits
1860 if (lineedit) finishedLineEditNoSave();
1864 if (typeid(*selection) == typeid(BranchObj))
1866 if (selection->getOrientation()==OrientRightOfCenter)
1869 if (selection->getDepth()==1)
1877 void MapEditor::selectLowerBranch()
1879 // Finish open lineEdits
1880 if (lineedit) finishedLineEditNoSave();
1884 if (typeid(*selection) == typeid(BranchObj))
1886 if (selection->getOrientation()==OrientRightOfCenter)
1889 if (selection->getDepth()==1)
1898 void MapEditor::selectLeftBranch()
1900 // Finish open lineEdits
1901 if (lineedit) finishedLineEditNoSave();
1907 if (typeid(*selection) == typeid(MapCenterObj))
1909 par= (BranchObj*) selection;
1910 bo=par->getLastSelectedBranch();
1913 // Workaround for reselecting on left and right side
1914 if (bo->getOrientation()==OrientRightOfCenter)
1916 bo=par->getLastBranch();
1922 selection->select();
1924 ensureSelectionVisible();
1929 par=(BranchObj*)(selection->getParObj());
1930 if (selection->getOrientation()==OrientRightOfCenter)
1932 if (typeid(*selection) == typeid(BranchObj) ||
1933 typeid(*selection) == typeid(FloatImageObj))
1935 selection->unselect();
1937 selection->select();
1939 ensureSelectionVisible();
1943 if (typeid(*selection) == typeid(BranchObj) )
1945 bo=((BranchObj*)selection)->getLastSelectedBranch();
1948 selection->unselect();
1950 selection->select();
1952 ensureSelectionVisible();
1960 void MapEditor::selectRightBranch()
1962 // Finish open lineEdits
1963 if (lineedit) finishedLineEditNoSave();
1970 if (typeid(*selection) == typeid(MapCenterObj))
1972 par= (BranchObj*) selection;
1973 bo=par->getLastSelectedBranch();
1976 // Workaround for relecting on left and right side
1977 if (bo->getOrientation()==OrientLeftOfCenter)
1978 bo=par->getFirstBranch();
1983 selection->select();
1984 ensureSelectionVisible();
1989 par=(BranchObj*)(selection->getParObj());
1990 if (selection->getOrientation()==OrientLeftOfCenter)
1992 if (typeid(*selection) == typeid(BranchObj) ||
1993 typeid(*selection) == typeid(FloatImageObj))
1995 selection->unselect();
1997 selection->select();
1999 ensureSelectionVisible();
2003 if (typeid(*selection) == typeid(BranchObj) )
2005 bo=((BranchObj*)selection)->getLastSelectedBranch();
2008 selection->unselect();
2010 selection->select();
2012 ensureSelectionVisible();
2020 void MapEditor::selectFirstBranch()
2022 // Finish open lineEdits
2023 if (lineedit) finishedLineEditNoSave();
2029 if (typeid(*selection) == typeid(BranchObj))
2031 bo1= (BranchObj*) selection;
2032 par=(BranchObj*)(bo1->getParObj());
2033 bo2=par->getFirstBranch();
2037 selection->select();
2038 ensureSelectionVisible();
2045 void MapEditor::selectLastBranch()
2047 // Finish open lineEdits
2048 if (lineedit) finishedLineEditNoSave();
2054 if (typeid(*selection) == typeid(BranchObj))
2056 bo1= (BranchObj*) selection;
2057 par=(BranchObj*)(bo1->getParObj());
2058 bo2=par->getLastBranch();
2062 selection->select();
2063 ensureSelectionVisible();
2070 void MapEditor::setColor(QColor c)
2075 void MapEditor::selectBackgroundColor()
2077 // Finish open lineEdits
2078 if (lineedit) finishedLineEditNoSave();
2080 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2081 if ( !col.isValid() ) return;
2082 setBackgroundColor( col );
2086 void MapEditor::setBackgroundColor(QColor c)
2088 mapCanvas->setBackgroundColor (c);
2091 QColor MapEditor::pickColor()
2095 if (typeid(*selection) == typeid(BranchObj) ||
2096 typeid(*selection) == typeid(MapCenterObj))
2098 BranchObj *bo=(BranchObj*)selection;
2099 actColor=bo->getColor();
2105 void MapEditor::colorItem()
2109 if (typeid(*selection) == typeid(BranchObj) ||
2110 typeid(*selection) == typeid(MapCenterObj))
2112 saveState(selection); //TODO undoCommand
2113 BranchObj *bo=(BranchObj*)selection;
2114 bo->setColor(actColor); // color branch
2119 void MapEditor::colorBranch()
2123 if (typeid(*selection) == typeid(BranchObj) ||
2124 typeid(*selection) == typeid(MapCenterObj))
2126 saveState(selection); //TODO undoCommand
2127 BranchObj *bo=(BranchObj*)selection;
2128 bo->setColorChilds(actColor); // color links, color childs
2134 void MapEditor::toggleStandardFlag(QString f)
2138 saveState(selection);// TODO undoCommand
2139 ((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2144 void MapEditor::setViewCenter()
2146 // transform to CanvasView Coord:
2147 QPoint p=worldMatrix().map(movingCenter);
2148 center ( p.x(), p.y());
2152 BranchObj* MapEditor::findText (QString s, bool cs)
2155 { // Nothing found or new find process
2157 // nothing found, start again
2159 itFind=mapCenter->first();
2161 bool searching=true;
2162 bool foundNote=false;
2163 while (searching && !EOFind)
2167 // Searching in Note
2168 if (itFind->getNote().contains(s,cs))
2170 if (selection!=itFind)
2172 if (selection) ((BranchObj*)selection)->unselect();
2174 selection->select();
2176 ensureSelectionVisible();
2178 if (textEditor->findText(s,cs))
2184 // Searching in Heading
2185 if (searching && itFind->getHeading().contains (s,cs) )
2187 if (selection) ((BranchObj*)selection)->unselect();
2189 selection->select();
2191 ensureSelectionVisible();
2197 itFind=itFind->next();
2198 if (!itFind) EOFind=true;
2204 return (BranchObj*)selection;
2209 void MapEditor::findReset()
2210 { // Necessary if text to find changes during a find process
2215 void MapEditor::editURL()
2217 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2218 typeid(*selection) == typeid(MapCenterObj)) )
2221 BranchObj *bo=(BranchObj*)selection;
2222 QString text = QInputDialog::getText(
2223 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2224 bo->getURL(), &ok, this );
2227 // user entered something and pressed OK
2228 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2235 QString MapEditor::getURL()
2237 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2238 typeid(*selection) == typeid(MapCenterObj)) )
2239 return ((BranchObj*)selection)->getURL();
2244 void MapEditor::editHeading2URL()
2246 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2247 typeid(*selection) == typeid(MapCenterObj)) )
2249 BranchObj *bo=(BranchObj*)selection;
2250 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2251 bo->setURL (bo->getHeading());
2256 void MapEditor::editBugzilla2URL()
2258 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2259 typeid(*selection) == typeid(MapCenterObj)) )
2261 BranchObj *bo=(BranchObj*)selection;
2262 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2263 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2269 void MapEditor::editFATE2URL()
2271 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2272 typeid(*selection) == typeid(MapCenterObj)) )
2274 BranchObj *bo=(BranchObj*)selection;
2275 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2276 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2282 void MapEditor::editVymLink()
2284 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2285 typeid(*selection) == typeid(MapCenterObj)) )
2287 BranchObj *bo=(BranchObj*)selection;
2288 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
2289 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2290 fd->setCaption(__VYM " - " +tr("Link to another map"));
2291 if (! bo->getVymLink().isEmpty() )
2292 fd->setSelection( bo->getVymLink() );
2296 if ( fd->exec() == QDialog::Accepted )
2298 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2299 bo->setVymLink (fd->selectedFile() );
2301 mapCenter->reposition();
2308 void MapEditor::deleteVymLink()
2310 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2311 typeid(*selection) == typeid(MapCenterObj)) )
2313 BranchObj *bo=(BranchObj*)selection;
2314 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2315 bo->setVymLink ("" );
2317 mapCenter->reposition();
2323 void MapEditor::setHideExport()
2325 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2326 typeid(*selection) == typeid(MapCenterObj)) ||
2327 (typeid(*selection)==typeid(FloatImageObj))
2330 saveState(); //TODO undoCommand
2331 OrnamentedObj *oo=(OrnamentedObj*)selection;
2332 oo->setHideInExport(actionEditToggleHideExport->isOn());
2334 mapCenter->reposition();
2340 void MapEditor::toggleHideExport()
2342 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2343 typeid(*selection) == typeid(MapCenterObj)) ||
2344 (typeid(*selection)==typeid(FloatImageObj))
2347 saveState(); //TODO undoCommand
2348 OrnamentedObj *oo=(OrnamentedObj*)selection;
2349 if (oo->hideInExport())
2350 oo->setHideInExport(false);
2352 oo->setHideInExport(true);
2353 actionEditToggleHideExport->setOn (oo->hideInExport());
2355 mapCenter->reposition();
2361 QString MapEditor::getVymLink()
2363 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2364 typeid(*selection) == typeid(MapCenterObj)) )
2366 return ((BranchObj*)selection)->getVymLink();
2372 void MapEditor::removeBranchHere()
2374 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2376 BranchObj* bo=(BranchObj*)selection;
2377 BranchObj* par=(BranchObj*)(bo->getParObj());
2378 if (bo->getDepth()==1)
2381 saveState(selection->getParObj()); // TODO undoCommand
2382 QString sel=selection->getSelectString();
2384 par->removeBranchHere(bo);
2385 mapCenter->reposition();
2390 void MapEditor::removeChilds()
2392 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2394 saveState(selection->getParObj());
2395 ((BranchObj*)selection)->removeChilds();
2396 mapCenter->reposition();
2400 void MapEditor::editMapInfo()
2402 ExtraInfoDialog dia;
2403 dia.setMapName (getFileName() );
2404 dia.setAuthor (mapCenter->getAuthor() );
2405 dia.setComment(mapCenter->getComment() );
2410 QCanvasItemList l=canvas()->allItems();
2411 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2413 stats+=QString ("%1 items on canvas\n").arg (i,6);
2420 bo=mapCenter->first();
2423 if (!bo->getNote().isEmpty() ) n++;
2424 f+= bo->countFloatImages();
2426 xl+=bo->countXLinks();
2429 stats+=QString ("%1 branches\n").arg (b-1,6);
2430 stats+=QString ("%1 xLinks \n").arg (xl,6);
2431 stats+=QString ("%1 notes\n").arg (n,6);
2432 stats+=QString ("%1 images\n").arg (f,6);
2433 dia.setStats (stats);
2435 // Finally show dialog
2436 if (dia.exec() == QDialog::Accepted)
2438 saveState(); //TODO undoCommand
2439 mapCenter->setAuthor (dia.getAuthor() );
2440 mapCenter->setComment (dia.getComment() );
2444 void MapEditor::updateActions()
2447 if (getLinkColorHint()==HeadingColor)
2448 actionFormatLinkColorHint->setOn(true);
2450 actionFormatLinkColorHint->setOn(false);
2455 actionFormatLinkStyleLine->setOn(true);
2458 actionFormatLinkStyleParabel->setOn(true);
2461 actionFormatLinkStylePolyLine->setOn(true);
2463 case StylePolyParabel:
2464 actionFormatLinkStylePolyParabel->setOn(true);
2470 QPixmap pix( 16, 16 );
2471 pix.fill( mapCanvas->backgroundColor() );
2472 actionFormatBackColor->setIconSet( pix );
2473 pix.fill( defLinkColor );
2474 actionFormatLinkColor->setIconSet( pix );
2476 actionEditUndo->setEnabled( mapChanged );
2477 actionFileSave->setEnabled( mapUnsaved );
2481 if ( (typeid(*selection) == typeid(BranchObj)) ||
2482 (typeid(*selection) == typeid(MapCenterObj)) )
2484 BranchObj *bo=(BranchObj*)selection;
2485 // Take care of links
2486 if (bo->countXLinks()==0)
2488 branchLinksContextMenu->clear();
2489 branchLinksContextMenu->insertItem ("No xLink available");
2490 branchLinksContextMenuDup->clear();
2491 branchLinksContextMenuDup->insertItem ("No xLink available");
2497 branchLinksContextMenu->clear();
2498 branchLinksContextMenuDup->clear();
2499 for (int i=0; i<=bo->countXLinks();i++)
2501 bot=bo->XLinkTargetAt(i);
2504 s=bot->getHeading();
2507 branchLinksContextMenu->insertItem (s);
2508 branchLinksContextMenuDup->insertItem (s);
2513 standardFlagsDefault->setEnabled (true);
2515 actionEditToggleScroll->setEnabled (true);
2516 if ( bo->isScrolled() )
2517 actionEditToggleScroll->setOn(true);
2519 actionEditToggleScroll->setOn(false);
2521 if ( bo->getURL().isEmpty() )
2523 actionEditOpenURL->setEnabled (false);
2524 actionEditOpenURLTab->setEnabled (false);
2528 actionEditOpenURL->setEnabled (true);
2529 actionEditOpenURLTab->setEnabled (true);
2531 if ( bo->getVymLink().isEmpty() )
2533 actionEditOpenVymLink->setEnabled (false);
2534 actionEditDeleteVymLink->setEnabled (false);
2537 actionEditOpenVymLink->setEnabled (true);
2538 actionEditDeleteVymLink->setEnabled (true);
2540 actionEditToggleHideExport->setEnabled (true);
2541 actionEditToggleHideExport->setOn (bo->hideInExport() );
2543 actionEditCopy->setEnabled (true);
2544 actionEditCut->setEnabled (true);
2545 if (!clipboardEmpty)
2546 actionEditPaste->setEnabled (true);
2548 actionEditPaste->setEnabled (false);
2549 for (a=actionListBranches.first();a;a=actionListBranches.next())
2550 a->setEnabled(true);
2551 actionEditDelete->setEnabled (true);
2552 switch (selection->getFrameType())
2555 actionFormatFrameNone->setOn(true);
2558 actionFormatFrameRectangle->setOn(true);
2563 actionFormatIncludeImagesVer->setOn
2564 ( ((BranchObj*)selection)->getIncludeImagesVer());
2565 actionFormatIncludeImagesHor->setOn
2566 ( ((BranchObj*)selection)->getIncludeImagesHor());
2567 actionFormatHideLinkUnselected->setOn
2568 (selection->getHideLinkUnselected());
2570 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2572 FloatObj *fo=(FloatImageObj*)selection;
2573 standardFlagsDefault->setEnabled (false);
2575 actionEditOpenURL->setEnabled (false);
2576 actionEditOpenVymLink->setEnabled (false);
2577 actionEditDeleteVymLink->setEnabled (false);
2578 actionEditToggleHideExport->setEnabled (true);
2579 actionEditToggleHideExport->setOn (fo->hideInExport() );
2582 actionEditCopy->setEnabled (true);
2583 actionEditCut->setEnabled (true);
2584 actionEditPaste->setEnabled (false);
2585 for (a=actionListBranches.first();a;a=actionListBranches.next())
2586 a->setEnabled(false);
2587 actionEditDelete->setEnabled (true);
2588 actionFormatHideLinkUnselected->setOn
2589 ( selection->getHideLinkUnselected());
2594 standardFlagsDefault->setEnabled (false);
2596 actionEditCopy->setEnabled (false);
2597 actionEditCut->setEnabled (false);
2598 actionEditPaste->setEnabled (false);
2599 for (a=actionListBranches.first();a;a=actionListBranches.next())
2600 a->setEnabled(false);
2602 actionEditToggleScroll->setEnabled (true);
2603 actionEditOpenURL->setEnabled (false);
2604 actionEditOpenVymLink->setEnabled (false);
2605 actionEditDeleteVymLink->setEnabled (false);
2606 actionEditHeading2URL->setEnabled (false);
2607 actionEditDelete->setEnabled (false);
2611 void MapEditor::updateNoteFlag()
2614 if ( (typeid(*selection) == typeid(BranchObj)) ||
2615 (typeid(*selection) == typeid(MapCenterObj)) )
2616 ((BranchObj*)selection)->updateNoteFlag();
2619 void MapEditor::setLinkStyle (LinkStyle ls)
2623 saveState(); // TODO undoCommand
2625 bo=mapCenter->first();
2629 bo->setLinkStyle(bo->getDefLinkStyle());
2632 mapCenter->reposition();
2635 LinkStyle MapEditor::getLinkStyle ()
2640 void MapEditor::setLinkColor(QColor c)
2646 void MapEditor::setLinkColorHint()
2648 // called from setLinkColorHint(lch) or at end of parse
2650 bo=mapCenter->first();
2658 void MapEditor::setLinkColorHint(LinkColorHint lch)
2664 void MapEditor::toggleLinkColorHint()
2666 if (linkcolorhint==HeadingColor)
2667 linkcolorhint=DefaultColor;
2669 linkcolorhint=HeadingColor;
2671 bo=mapCenter->first();
2679 LinkColorHint MapEditor::getLinkColorHint()
2681 return linkcolorhint;
2684 QColor MapEditor::getDefLinkColor()
2686 return defLinkColor;
2689 void MapEditor::setDefXLinkColor(QColor col)
2694 QColor MapEditor::getDefXLinkColor()
2696 return defXLinkColor;
2699 void MapEditor::setDefXLinkWidth (int w)
2704 int MapEditor::getDefXLinkWidth()
2706 return defXLinkWidth;
2709 void MapEditor::selectLinkColor()
2711 // Finish open lineEdits
2712 if (lineedit) finishedLineEditNoSave();
2714 QColor col = QColorDialog::getColor( defLinkColor, this );
2715 if ( !col.isValid() ) return;
2716 setLinkColor( col );
2717 saveState(); //TODO undoCommand
2721 void MapEditor::toggleScroll()
2723 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2725 BranchObj *bo=((BranchObj*)selection);
2726 if (bo->countBranches()==0) return;
2727 if (bo->getDepth()==0) return;
2728 saveState(selection);
2735 void MapEditor::unScrollAll()
2738 bo=mapCenter->first();
2741 if (bo->isScrolled()) bo->toggleScroll();
2746 void MapEditor::loadFloatImage ()
2749 (typeid(*selection) == typeid(BranchObj)) ||
2750 (typeid(*selection) == typeid(MapCenterObj)) )
2752 BranchObj *bo=((BranchObj*)selection);
2754 QFileDialog *fd=new QFileDialog( this);
2755 fd->setMode (QFileDialog::ExistingFiles);
2756 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2757 ImagePreview *p =new ImagePreview (fd);
2758 fd->setContentsPreviewEnabled( TRUE );
2759 fd->setContentsPreview( p, p );
2760 fd->setPreviewMode( QFileDialog::Contents );
2761 fd->setCaption(__VYM " - " +tr("Load image"));
2762 fd->setDir (lastImageDir);
2766 if ( fd->exec() == QDialog::Accepted )
2768 saveState(selection);
2769 lastImageDir=fn.left(fn.findRev ("/"));
2770 QStringList flist = fd->selectedFiles();
2771 QStringList::Iterator it = flist.begin();
2772 while( it != flist.end() )
2775 bo->addFloatImage();
2776 // TODO check if load was successful
2777 bo->getLastFloatImage()->load(*it);
2778 bo->getLastFloatImage()->setOriginalFilename(fn);
2782 mapCenter->reposition();
2791 void MapEditor::saveFloatImage (int item)
2794 (typeid(*selection) == typeid(FloatImageObj)) )
2796 FloatImageObj *fio=((FloatImageObj*)selection);
2797 const char* fmt = saveImageFormatMenu->text(item);
2799 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2800 fd->addFilter ("PNG (*.png)");
2801 fd->addFilter ("BMP (*.bmp)");
2802 fd->addFilter ("XBM (*.xbm)");
2803 fd->addFilter ("JPG (*.jpg)");
2804 fd->addFilter ("XPM (*.xpm)");
2805 fd->addFilter ("GIF (*.gif)");
2806 fd->addFilter ("PNM (*.pnm)");
2807 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2808 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2809 fd->setMode( QFileDialog::AnyFile );
2810 fd->setSelection (fio->getOriginalFilename());
2814 if ( fd->exec() == QDialog::Accepted )
2816 if (QFile (fd->selectedFile()).exists() )
2818 QMessageBox mb( __VYM,
2819 tr("The file %1 exists already.\n"
2820 "Do you want to overwrite it?").arg(fd->selectedFile()),
2821 QMessageBox::Warning,
2822 QMessageBox::Yes | QMessageBox::Default,
2823 QMessageBox::Cancel | QMessageBox::Escape,
2824 QMessageBox::QMessageBox::NoButton );
2826 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2827 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2830 case QMessageBox::Yes:
2833 case QMessageBox::Cancel:
2839 fio->save (fd->selectedFile(),fmt);
2844 void MapEditor::setFrame(const FrameType &t)
2847 (typeid(*selection) == typeid(BranchObj)) ||
2848 (typeid(*selection) == typeid(MapCenterObj)) )
2850 selection->setFrameType (t);
2851 mapCenter->reposition();
2852 selection->updateLink();
2856 void MapEditor::setIncludeImagesVer(bool b)
2859 (typeid(*selection) == typeid(BranchObj)) ||
2860 (typeid(*selection) == typeid(MapCenterObj)) )
2861 ((BranchObj*)selection)->setIncludeImagesVer(b);
2862 mapCenter->reposition();
2865 void MapEditor::setIncludeImagesHor(bool b)
2868 (typeid(*selection) == typeid(BranchObj)) ||
2869 (typeid(*selection) == typeid(MapCenterObj)) )
2870 ((BranchObj*)selection)->setIncludeImagesHor(b);
2871 mapCenter->reposition();
2874 void MapEditor::setHideLinkUnselected (bool b)
2877 (typeid(*selection) == typeid(BranchObj)) ||
2878 (typeid(*selection) == typeid(MapCenterObj)) ||
2879 (typeid(*selection) == typeid(FloatImageObj)) )
2880 selection->setHideLinkUnselected(b);
2883 void MapEditor::importDir(BranchObj *dst, QDir d)
2886 (typeid(*selection) == typeid(BranchObj)) ||
2887 (typeid(*selection) == typeid(MapCenterObj)) )
2891 // Traverse directories
2892 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2893 const QFileInfoList *dirlist = d.entryInfoList();
2894 QFileInfoListIterator itdir( *dirlist );
2897 while ( (fi = itdir.current()) != 0 )
2899 if (fi->fileName() != "." && fi->fileName() != ".." )
2902 bo=dst->getLastBranch();
2903 bo->setHeading (fi->fileName() );
2904 bo->setColor (QColor("blue"));
2906 if ( !d.cd(fi->fileName()) )
2907 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2910 // Recursively add subdirs
2918 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2919 const QFileInfoList *filelist = d.entryInfoList();
2920 QFileInfoListIterator itfile( *filelist );
2922 while ( (fi = itfile.current()) != 0 )
2925 bo=dst->getLastBranch();
2926 bo->setHeading (fi->fileName() );
2927 bo->setColor (QColor("black"));
2928 if (fi->fileName().right(4) == ".vym" )
2929 bo->setVymLink (fi->filePath());
2936 void MapEditor::importDir()
2939 (typeid(*selection) == typeid(BranchObj)) ||
2940 (typeid(*selection) == typeid(MapCenterObj)) )
2942 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
2943 fd->setMode (QFileDialog::DirectoryOnly);
2944 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2945 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
2949 if ( fd->exec() == QDialog::Accepted )
2951 BranchObj *bo=((BranchObj*)selection);
2952 importDir (bo,QDir(fd->selectedFile()) );
2953 mapCenter->reposition();
2960 void MapEditor::followXLink(int i)
2963 (typeid(*selection) == typeid(BranchObj)) ||
2964 (typeid(*selection) == typeid(MapCenterObj)) )
2966 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
2969 selection->unselect();
2971 selection->select();
2972 ensureSelectionVisible();
2977 void MapEditor::editXLink(int i)
2980 (typeid(*selection) == typeid(BranchObj)) ||
2981 (typeid(*selection) == typeid(MapCenterObj)) )
2983 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
2986 EditXLinkDialog dia;
2988 dia.setSelection(selection);
2989 if (dia.exec() == QDialog::Accepted)
2991 if (dia.useSettingsGlobal() )
2993 setDefXLinkColor (xlo->getColor() );
2994 setDefXLinkWidth (xlo->getWidth() );
2996 if (dia.deleteXLink())
2997 ((BranchObj*)selection)->deleteXLinkAt(i);
2998 saveState(); //TODO undoCommand
3004 void MapEditor::testFunction()
3006 cout << "MapEditor::testFunction() called\n";
3008 if (hidemode==HideNone)
3010 setHideTmpMode (HideExport);
3011 mapCenter->calcBBoxSizeWithChilds();
3012 QRect totalBBox=mapCenter->getTotalBBox();
3013 QRect mapRect=totalBBox;
3014 QCanvasRectangle *frame=NULL;
3016 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3018 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3019 totalBBox.width(), totalBBox.height());
3020 frame=new QCanvasRectangle (mapRect,mapCanvas);
3021 frame->setBrush (QColor(white));
3022 frame->setPen (QColor(black));
3028 setHideTmpMode (HideNone);
3030 cout <<" hidemode="<<hidemode<<endl;
3033 void MapEditor::ensureSelectionVisible()
3037 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3039 if (selection->getOrientation() == OrientLeftOfCenter)
3040 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3042 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3043 ensureVisible (p.x(), p.y() );
3048 void MapEditor::updateViewCenter()
3050 // Update movingCenter, so that we can zoom comfortably later
3051 QRect rc = QRect( contentsX(), contentsY(),
3052 visibleWidth(), visibleHeight() );
3053 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3054 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3055 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3058 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3060 // Lineedits are already closed by preceding
3061 // mouseEvent, we don't need to close here.
3063 QPoint p = inverseWorldMatrix().map(e->pos());
3064 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3067 { // MapObj was found
3068 if (selection != lmo)
3070 // select the MapObj
3071 if (selection) selection->unselect();
3073 selection->select();
3079 if (typeid(*selection)==typeid(BranchObj) ||
3080 typeid(*selection)==typeid(MapCenterObj) )
3082 // Context Menu on branch or mapcenter
3084 branchContextMenu->popup(e->globalPos() );
3086 if (typeid(*selection)==typeid(FloatImageObj))
3088 // Context Menu on floatimage
3090 floatimageContextMenu->popup(e->globalPos() );
3094 { // No MapObj found, we are on the Canvas itself
3095 // Context Menu on Canvas
3097 canvasContextMenu->popup(e->globalPos() );
3101 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3103 // Finish open lineEdits
3104 if (lineedit) finishedLineEditNoSave();
3106 QPoint p = inverseWorldMatrix().map(e->pos());
3107 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3109 // Special case: CTRL is pressed
3110 if (e->state() & QMouseEvent::ControlButton)
3112 if (actionModModeColor->isOn())
3114 if (e->state() & QMouseEvent::ControlButton)
3117 setCursor (pickColorCursor);
3121 if (actionModModeLink->isOn())
3123 BranchObj *bo_begin=NULL;
3125 bo_begin=(BranchObj*)(lmo);
3128 ((typeid(*selection) == typeid(BranchObj)) ||
3129 (typeid(*selection) == typeid(MapCenterObj))) )
3130 bo_begin=(BranchObj*)selection;
3134 linkingObj_src=bo_begin;
3135 tmpXLink=new XLinkObj (mapCanvas);
3136 tmpXLink->setBegin (bo_begin);
3137 tmpXLink->setEnd (p);
3138 tmpXLink->setColor(defXLinkColor);
3139 tmpXLink->setWidth(defXLinkWidth);
3140 tmpXLink->updateXLink();
3141 tmpXLink->setVisibility (true);
3148 { // MapObj was found
3149 if (selection != lmo)
3151 // select the MapObj
3152 if (selection) selection->unselect();
3154 selection->select();
3159 // Check, if systemFlag clicked
3160 if (typeid(*selection)==typeid(BranchObj) ||
3161 typeid(*selection)==typeid(MapCenterObj) )
3163 QString foname=((BranchObj*)selection)->getSystemFlagName(p);
3164 if (!foname.isEmpty())
3166 // Do not move, if systemFlag clicked
3169 if (e->state() & QMouseEvent::ControlButton)
3170 mainWindow->editOpenURLTab();
3172 mainWindow->editOpenURL();
3174 else if (foname=="vymLink")
3176 mainWindow->editOpenVymLink();
3177 // tabWidget may change, better return now
3178 // before segfaulting...
3180 } else if (foname=="note")
3181 mainWindow->windowToggleNoteEditor();
3182 else if (foname=="hideInExport")
3187 // Left Button Move Branches
3188 if (e->button() == QMouseEvent::LeftButton )
3190 movingObj_start.setX( p.x() - selection->x() );
3191 movingObj_start.setY( p.y() - selection->y() );
3192 movingObj_orgPos.setX (lmo->x() );
3193 movingObj_orgPos.setY (lmo->y() );
3195 // If modMode==copy, then we want to "move" the _new_ object around
3196 // then we need the offset from p to the _old_ selection, because of tmp
3197 if (actionModModeCopy->isOn() &&
3198 e->state() & QMouseEvent::ControlButton)
3200 if (typeid(*selection)==typeid(BranchObj) )
3203 mapCenter->addBranch ((BranchObj*)selection);
3205 selection=mapCenter->getLastBranch();
3206 selection->select();
3207 mapCenter->reposition();
3210 movingObj=selection;
3212 // Middle Button Toggle Scroll
3213 // (On Mac OS X this won't work, but we still have
3214 // a button in the toolbar)
3215 if (e->button() == QMouseEvent::MidButton )
3219 { // No MapObj found, we are on the Canvas itself
3220 // Left Button move Pos of CanvasView
3221 if (e->button() == QMouseEvent::LeftButton )
3223 movingObj=NULL; // move Content not Obj
3224 movingObj_start=e->globalPos();
3225 movingCont_start=QPoint (contentsX(), contentsY() );
3226 movingVec=QPoint(0,0);
3227 setCursor(handOpenCursor);
3232 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3234 QPoint p = inverseWorldMatrix().map(e->pos());
3236 // Move the selected MapObj
3237 if ( selection && movingObj)
3239 // To avoid jumping of the CanvasView, only
3240 // ensureSelectionVisible, if not tmp linked
3241 if (!selection->hasParObjTmp())
3242 ensureSelectionVisible ();
3244 // Now move the selection, but add relative position
3245 // (movingObj_start) where selection was chosen with
3246 // mousepointer. (This avoids flickering resp. jumping
3247 // of selection back to absPos)
3249 LinkableMapObj *lmosel;
3250 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3252 // Check if we could link
3253 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3256 if (typeid(*selection) == typeid(FloatImageObj))
3258 FloatObj *fo=(FloatObj*)selection;
3259 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3260 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3264 // Relink float to new mapcenter or branch, if shift is pressed
3265 // Only relink, if selection really has a new parent
3266 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3267 ( (typeid(*lmo)==typeid(BranchObj)) ||
3268 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3269 ( lmo != fo->getParObj())
3272 if (typeid(*fo) == typeid(FloatImageObj))
3275 FloatImageObj *fio=(FloatImageObj*)(fo);
3276 ((BranchObj*)(lmo))->addFloatImage (fio);
3278 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3279 fio=((BranchObj*)(lmo))->getLastFloatImage();
3282 selection=(LinkableMapObj*)(fio);
3283 selection->select();
3284 movingObj=(MapObj*)(fio);
3287 } else // selection != a FloatObj
3289 if (lmosel->getDepth()==0)
3291 if (e->state() == (LeftButton | !ShiftButton))
3292 // If mapCenter is moved, move all the rest by default, too.
3293 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3295 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3298 if (lmosel->getDepth()==1)
3300 // depth==1, mainbranch
3301 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3305 if (lmosel->getOrientation() == OrientLeftOfCenter)
3306 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3307 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3308 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3310 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3312 // reposition subbranch
3313 lmosel->reposition();
3314 //ensureSelectionVisible();
3316 if (lmo && (lmo!=selection) &&
3317 (typeid(*lmo) == typeid(BranchObj) ||
3318 (typeid(*lmo) == typeid(MapCenterObj) )
3321 if (e->state() & QMouseEvent::ControlButton)
3323 // Special case: CTRL to link below lmo
3324 lmosel->setParObjTmp (lmo,p,+1);
3326 else if (e->state() & QMouseEvent::ShiftButton)
3327 lmosel->setParObjTmp (lmo,p,-1);
3329 lmosel->setParObjTmp (lmo,p,0);
3332 lmosel->unsetParObjTmp();
3333 /* FIXME not needed anymore?
3334 if (lmo &&(lmo==selection))
3335 // Could link to myself (happens sometimes...)
3336 lmosel->unsetParObjTmp();
3338 // no Obj under selection, go back to original Parent
3339 lmosel->unsetParObjTmp();
3344 } // no FloatImageObj
3348 } // selection && moving_obj
3350 // Draw a link from one branch to another
3353 tmpXLink->setEnd (p);
3354 tmpXLink->updateXLink();
3358 if (!movingObj && !pickingColor &&!drawingLink)
3360 QPoint p=e->globalPos();
3361 movingVec.setX(-p.x() + movingObj_start.x() );
3362 movingVec.setY(-p.y() + movingObj_start.y() );
3363 setContentsPos( movingCont_start.x() + movingVec.x(),
3364 movingCont_start.y() + movingVec.y());
3371 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3373 LinkableMapObj *dst;
3374 // Have we been picking color?
3378 setCursor (ArrowCursor);
3379 // Check if we are over another branch
3380 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3381 if (dst && selection)
3383 if (e->state() & QMouseEvent::ShiftButton)
3385 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3386 ((BranchObj*)selection)->setLinkColor ();
3390 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3391 ((BranchObj*)selection)->setLinkColor ();
3397 // Have we been drawing a link?
3401 // Check if we are over another branch
3402 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3403 if (dst && selection)
3405 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3406 tmpXLink->updateXLink();
3407 tmpXLink->activate();
3408 saveState(); //TODO undoCommand
3417 // Have we been moving something?
3418 if ( selection && movingObj )
3420 // Moved FloatObj? Maybe we need to reposition
3421 if(typeid(*selection)==typeid (FloatImageObj))
3423 selection->getParObj()->requestReposition();
3424 mapCenter->reposition();
3427 // Check if we are over another branch, but ignore
3428 // any found LMOs, which are FloatObjs
3429 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3430 ((LinkableMapObj*)selection) );
3433 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3436 // Now check, if we have been moving a branch
3437 if (typeid(*selection) == typeid(BranchObj) )
3439 // save the position in case we link to mapcenter
3440 QPoint savePos=QPoint (selection->x(),selection->y() );
3442 // Reset the temporary drawn link to the original one
3443 ((LinkableMapObj*)selection)->unsetParObjTmp();
3449 BranchObj* bs=((BranchObj*)selection);
3450 QString undoCom="linkBranchToPos (\""+
3451 (bs->getParObj())->getSelectString()+
3453 QString("%1").arg(bs->getNum())+
3455 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3457 // TODO we also could check, if dest and src are on same branch,
3458 // then it would be sufficient to saveState of this branch
3460 // Modifiers allow to insert above/below dst
3461 if (e->state() & QMouseEvent::ShiftButton)
3463 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3465 if (e->state() & QMouseEvent::ControlButton)
3467 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3470 bs->moveBranchTo ((BranchObj*)(dst),-1);
3471 if (dst->getDepth()==0)
3474 saveState (undoCom,bs->getSelectString() );
3476 if (selection->getDepth()==1)
3477 // If we have moved mainbranch only save endposition
3478 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString() );
3480 // Draw the original link, before selection was moved around
3481 mapCenter->reposition();
3483 // Finally resize canvas, if needed
3488 // maybe we moved View: set old cursor
3489 setCursor (ArrowCursor);
3493 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3495 // Finish open lineEdits
3496 if (lineedit) finishedLineEditNoSave();
3498 if (e->button() == QMouseEvent::LeftButton )
3500 QPoint p = inverseWorldMatrix().map(e->pos());
3501 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3502 if (lmo) { // MapObj was found
3503 // First select the MapObj than edit heading
3504 if (selection) selection->unselect();
3506 selection->select();
3507 saveState(selection);
3513 void MapEditor::resizeEvent (QResizeEvent* e)
3515 QCanvasView::resizeEvent( e );
3519 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3522 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3523 // cerr << event->format(i) << endl;
3526 (typeid(*selection) == typeid(BranchObj)) ||
3527 (typeid(*selection) == typeid(MapCenterObj))) {
3529 // If QImageDrag can decode mime type
3530 if (QImageDrag::canDecode(event)) {
3535 // If image are dragged from firefox
3536 if (event->provides("application/x-moz-file-promise-url") &&
3537 event->provides("application/x-moz-nativeimage")) {
3538 event->accept(true);
3542 // If QUriDrag can decode mime type
3543 if (QUriDrag::canDecode(event)) {
3548 // If Uri are dragged from firefox
3549 if (event->provides("_NETSCAPE_URL")){
3554 // If QTextDrag can decode mime type
3555 if (QTextDrag::canDecode(event)) {
3564 bool isUnicode16(const QByteArray &d)
3566 // TODO: make more precise check for unicode 16.
3567 // Guess unicode16 if any of second bytes are zero
3568 unsigned int length = max(0,d.size()-2)/2;
3569 for (unsigned int i = 0; i<length ; i++)
3570 if (d.at(i*2+1)==0) return true;
3574 void MapEditor::contentsDropEvent(QDropEvent *event)
3577 (typeid(*selection) == typeid(BranchObj)) ||
3578 (typeid(*selection) == typeid(MapCenterObj)))
3583 if (event->provides("image/png"))
3586 if (QImageDrag::decode(event, pix))
3594 } else if (event->provides("application/x-moz-file-promise-url") &&
3595 event->provides("application/x-moz-nativeimage"))
3597 // Contains url to the img src in unicode16
3598 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3599 QString url = QString((const QChar*)d.data(),d.size()/2);
3603 } else if (event->provides ("text/uri-list"))
3604 { // Uris provided e.g. by konqueror
3605 QUriDrag::decode (event,uris);
3606 } else if (event->provides ("_NETSCAPE_URL"))
3607 { // Uris provided by Mozilla
3608 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3611 } else if (event->provides("text/html")) {
3613 // Handels text mime types
3614 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3615 QByteArray d = event->encodedData("text/html");
3618 text = QString((const QChar*)d.data(),d.size()/2);
3622 textEditor->setText(text);
3626 } else if (event->provides("text/plain")) {
3627 QByteArray d = event->encodedData("text/plain");
3630 text = QString((const QChar*)d.data(),d.size()/2);
3634 textEditor->setText(text);
3646 for (const char* u=uris.first(); u; u=uris.next())
3648 bo=((BranchObj*)selection)->addBranch();
3651 s=QUriDrag::uriToLocalFile(u);
3653 QString file = QDir::convertSeparators(s);
3654 heading = QFileInfo(file).baseName();
3656 if (file.endsWith(".vym", false))
3657 bo->setVymLink(file);
3666 bo->setHeading(heading);
3676 saveState(); //TODO undo Command
3677 mapCenter->reposition();
3684 void MapEditor::addFloatImage(const QPixmap &img)
3687 (typeid(*selection) == typeid(BranchObj)) ||
3688 (typeid(*selection) == typeid(MapCenterObj)) )
3690 BranchObj *bo=((BranchObj*)selection);
3691 saveState(selection);
3692 //QString fn=fd->selectedFile();
3693 //lastImageDir=fn.left(fn.findRev ("/"));
3694 bo->addFloatImage();
3695 // FIXME check if load was successful
3696 bo->getLastFloatImage()->load(img);
3697 //bo->getLastFloatImage()->setOriginalFilename(fn);
3698 mapCenter->reposition();
3705 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3707 if (!imageBuffer) imageBuffer = new QBuffer();
3708 if (!imageBuffer->isOpen()) {
3709 imageBuffer->open(IO_WriteOnly | IO_Append);
3711 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3715 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3717 if (nop->state()==QNetworkProtocol::StDone) {
3718 QPixmap img(imageBuffer->buffer());
3723 imageBuffer->close();
3725 imageBuffer->close();
3732 void MapEditor::fetchImage(const QString &url)
3735 urlOperator->stop();
3736 disconnect(urlOperator);
3740 urlOperator = new QUrlOperator(url);
3741 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3742 this, SLOT(imageDataFinished(QNetworkOperation*)));
3744 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3745 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));