More documentation, fixed small bug where links of unselected objects where visible again
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 *actionEditURL;
63 extern QAction *actionEditHeading2URL;
64 extern QAction *actionEditBugzilla2URL;
65 extern QAction *actionEditFATE2URL;
66 extern QAction *actionEditOpenVymLink;
67 extern QAction *actionEditVymLink;
68 extern QAction *actionEditDeleteVymLink;
69 extern QAction *actionEditToggleHideExport;
70 extern QAction *actionEditHeading;
71 extern QAction *actionEditDelete;
72 extern QAction *actionEditAddBranch;
73 extern QAction *actionEditAddBranchAbove;
74 extern QAction *actionEditAddBranchBelow;
75 extern QAction *actionEditRemoveBranchHere;
76 extern QAction *actionEditRemoveChilds;
77 extern QAction *actionEditImportAdd;
78 extern QAction *actionEditImportReplace;
79 extern QAction *actionEditSaveBranch;
80 extern QAction *actionEditSelectFirst;
81 extern QAction *actionEditSelectLast;
82 extern QAction *actionEditLoadImage;
84 extern QAction* actionFormatPickColor;
85 extern QAction* actionFormatColorBranch;
86 extern QAction* actionFormatColorSubtree;
87 extern QAction *actionFormatLinkColorHint;
88 extern QAction *actionFormatBackColor;
89 extern QAction *actionFormatLinkColor;
91 extern QActionGroup* actionGroupModModes;
92 extern QAction* actionModModeColor;
93 extern QAction* actionModModeLink;
94 extern QAction* actionModModeCopy;
96 extern QActionGroup *actionGroupFormatFrameTypes;
97 extern QAction *actionFormatFrameNone;
98 extern QAction *actionFormatFrameRectangle;
100 extern QActionGroup *actionGroupFormatLinkStyles;
101 extern QAction *actionFormatIncludeImagesVer;
102 extern QAction *actionFormatIncludeImagesHor;
103 extern QAction *actionFormatHideLinkUnselected;
104 extern QAction *actionFormatLinkStyleLine;
105 extern QAction *actionFormatLinkStyleParabel;
106 extern QAction *actionFormatLinkStylePolyLine;
107 extern QAction *actionFormatLinkStylePolyParabel;
109 extern QAction *actionViewToggleNoteEditor;
111 extern QAction *actionSettingsAutoedit;
112 extern QAction *actionSettingsAutoselectHeading;
113 extern QAction *actionSettingsAutoselectText;
114 extern QAction *actionSettingsPasteNewHeading;
115 extern QAction *actionSettingsUseFlagGroups;
117 extern QPopupMenu *branchContextMenu;
118 extern QPopupMenu *branchLinksContextMenu;
119 extern QPopupMenu *branchLinksContextMenuDup;
120 extern QPopupMenu *floatimageContextMenu;
121 extern QPopupMenu *saveImageFormatMenu;
122 extern QPopupMenu *exportImageFormatMenu;
123 extern QPopupMenu *canvasContextMenu;
125 extern Settings settings;
127 int MapEditor::mapNum=0; // make instance
129 ///////////////////////////////////////////////////////////////////////
130 ///////////////////////////////////////////////////////////////////////
131 MapEditor::MapEditor(
132 QWidget* parent, bool interactive, const char* name, WFlags f) :
133 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
135 //cout << "Constructor ME "<<this<<endl;
138 viewport()->setAcceptDrops(true);
140 mapCanvas = new QCanvas(1000,800);
141 mapCanvas->setAdvancePeriod(30);
142 mapCanvas->setBackgroundColor (white);
144 setCanvas (mapCanvas);
146 // Always show scroll bars (automatic would flicker sometimes)
147 setVScrollBarMode ( QScrollView::AlwaysOn );
148 setHScrollBarMode ( QScrollView::AlwaysOn );
150 mapCenter = new MapCenterObj(mapCanvas);
151 mapCenter->setVisibility (true);
152 mapCenter->setMapEditor (this);
153 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
154 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
158 lineedit = new QLineEdit(this, "lineedit" );
159 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
162 actColor=black; setColor (actColor);
163 defLinkColor=QColor (0,0,255);
164 defXLinkColor=QColor (180,180,180);
165 linkcolorhint=DefaultColor;
166 linkstyle=StylePolyParabel;
168 // Create bitmap cursors, patform dependant
169 #if defined(Q_OS_MACX)
170 #include "icons/cursorhandopen16.xpm"
171 #include "icons/cursorcolorpicker16.xpm"
172 QBitmap cb( 16, 16, chandopen, TRUE );
173 QBitmap cm( 16, 16, chandopenmask, TRUE );
174 handOpenCursor=QCursor ( cb, cm );
175 // set hot spot to tip of picker
176 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
178 #include "icons/cursorhandopen.xpm"
179 #include "icons/cursorcolorpicker.xpm"
181 QBitmap cb( 32, 32, chandopen, TRUE );
182 QBitmap cm( 32, 32, chandopenmask, TRUE );
183 handOpenCursor=QCursor ( cb, cm );
184 // set hot spot to tip of picker
185 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
198 defXLinkColor=QColor (230,230,230);
209 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
213 // Initialize find routine
220 blockReposition=false;
221 blockSaveState=false;
225 isInteractive=interactive;
227 // Create temporary files
230 // Initially set movingCentre
233 mapCenter->reposition(); // for positioning heading
236 MapEditor::~MapEditor()
238 if (imageBuffer) delete imageBuffer;
244 //cout <<"Destructor MapEditor\n";
247 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
251 QColor MapEditor::color()
256 QColor MapEditor::backgroundColor()
258 return mapCanvas->backgroundColor();
261 MapCenterObj* MapEditor::getMapCenter()
266 QCanvas* MapEditor::getCanvas()
271 void MapEditor::adjustCanvasSize()
273 // To adjust the canvas to map, viewport size and position, we have to
274 // do some coordinate magic...
276 // Get rectangle of (scroll-)view.
277 // We want to be in canvas coords, so
278 // we map. Important if view is zoomed...
279 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
280 visibleWidth(), visibleHeight()) );
282 // Now we need the bounding box of view AND map to calc the correct canvas size.
283 // Why? Because if the map itself is moved out of view, the view has to be enlarged
284 // to avoid jumping aroung...
285 QRect map=mapCenter->getTotalBBox();
287 // right edge - left edge
288 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
289 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
292 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
293 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
296 // move the map on canvas (in order to not move it on screen) this is neccessary
297 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
298 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
299 // to scroll to an empty area of canvas to the left.
300 // b) if topleft corner of map left of or above topleft of canvas
304 if (cw > mapCanvas->width() )
306 if (map.x()<0) dx=-map.x();
308 if (cw < mapCanvas->width() )
309 dx=-min (view.x(),map.x());
310 if (ch > mapCanvas->height() )
312 if (map.y()<0) dy=-map.y();
314 if (ch < mapCanvas->height() )
316 dy=-min (view.y(),map.y());
318 // We really have to resize now. Let's go...
319 mapCanvas->resize (cw,ch);
320 if ( (dx!=0) || (dy!=0) )
322 mapCenter->moveAllBy(dx,dy);
323 mapCenter->reposition();
325 // scroll the view (in order to not move map on screen)
331 bool MapEditor::isRepositionBlocked()
333 return blockReposition;
336 void MapEditor::makeTmpDirs()
338 // Create unique temporary directories
339 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
341 d.mkdir (tmpMapDir,true);
344 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
346 // tmpdir temporary directory to which data will be written
347 // prefix mapname, which will be appended to images etc.
348 // writeflags Only write flags for "real" save of map, not undo
349 // offset offset of bbox of whole map in canvas.
350 // Needed for XML export
366 ls="StylePolyParabel";
370 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
372 if (linkcolorhint==HeadingColor)
373 colhint=attribut("linkColorHint","HeadingColor");
375 QString mapAttr=attribut("version",__VYM_VERSION);
377 mapAttr+= attribut("author",mapCenter->getAuthor()) +
378 attribut("comment",mapCenter->getComment()) +
379 attribut("date",mapCenter->getDate()) +
380 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
381 attribut("linkStyle", ls ) +
382 attribut("linkColor", defLinkColor.name() ) +
383 attribut("defXLinkColor", defXLinkColor.name() ) +
384 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
386 s+=beginElement("vymmap",mapAttr);
389 // Find the used flags while traversing the tree
390 standardFlagsDefault->resetUsedCounter();
392 // Reset the counters before saving
393 FloatImageObj (mapCanvas).resetSaveCounter();
395 // Build xml recursivly
397 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
400 if ( typeid(*saveSelection) == typeid(BranchObj) )
401 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
402 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
403 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
405 else if (selection && typeid(*selection)==typeid(BranchObj))
406 // This is used if selected branch is saved from mainwindow
407 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
410 // Save local settings
411 s+=settings.getXMLData (destPath);
414 if (selection && !saveSelection )
415 s+=valueElement("select",selection->getSelectString());
418 s+=endElement("vymmap");
421 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
425 void MapEditor::saveState()
428 saveState (CompleteMap,"",NULL,"",NULL);
431 void MapEditor::saveState(LinkableMapObj *undoSel)
433 // save the given part of the map
434 saveState (PartOfMap,"",undoSel,"",NULL);
437 void MapEditor::saveState(const QString &uc, const QString &rc)
439 // selection does not change during action,
440 // so just save commands for undo and redo
441 LinkableMapObj *unsel;
446 saveState (UndoCommand,uc,unsel,rc,unsel);
449 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel)
451 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL);
454 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel)
458 if (blockSaveState) return;
460 /* TODO remove after testing
461 cout << "ME::saveState() begin\n"<<endl;
462 cout << " undosTotal="<<undosTotal<<endl;
463 cout << " undosAvail="<<undosAvail<<endl;
464 cout << " undoNum="<<undoNum<<endl;
465 cout << " ---------------------------"<<endl;
469 // Find out current undo directory
470 if (undosAvail<undosTotal) undosAvail++;
472 if (undoNum>undosTotal) undoNum=1;
475 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
476 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
478 // Create bakMapDir if not available
481 makeSubDirs (bakMapDir);
483 // Save current selection
484 QString redoSelection="";
486 redoSelection=redoSel->getSelectString();
488 // Save the object, which should be undone
489 QString undoSelection="";
491 undoSelection=undoSel->getSelectString();
493 // Save depending on how much needs to be saved
494 QString undoCommand="";
495 if (savemode==UndoCommand)
500 else if (savemode==PartOfMap && undoSel)
502 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
503 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
506 undoCommand="undoMap (\""+bakMapPath+"\")";
507 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
510 if (!backupXML.isEmpty())
511 // Write XML Data to disk
512 saveStringToDisk (QString(bakMapPath),backupXML);
515 set.setEntry (QString("undoCommand"),undoCommand);
516 set.setEntry (QString("undoSelection"),undoSelection);
517 set.setEntry (QString("redoCommand"),redoCom);
518 set.setEntry (QString("redoSelection"),redoSelection);
519 set.writeSettings(QString(bakMapDir+"/commands"));
521 /* TODO remove after testing
522 cout << " into="<< bakMapDir<<endl;
523 cout << " undosAvail="<<undosAvail<<endl;
524 cout << " undoNum="<<undoNum<<endl;
525 cout << " ---------------------------"<<endl;
526 cout << " undoCom="<<undoCommand<<endl;
527 cout << " undoSel="<<undoSelection<<endl;
528 cout << " ---------------------------"<<endl;
529 cout << " redoCom="<<redoCom<<endl;
530 cout << " redoSel="<<redoSelection<<endl;
531 cout << " ---------------------------"<<endl<<endl;
535 void MapEditor::parseAtom(const QString &atom)
542 // Split string s into command and parameters
543 api.parseCommand (atom);
544 QString com=api.command();
547 if (com=="moveBranchUp")
549 else if (com=="moveBranchDown")
551 else if (com=="move")
553 if (api.checkParamCount(2) && selection )
563 else if (com=="linkBranchToPos")
565 if (selection && typeid(*selection) == typeid(BranchObj) )
567 if (api.checkParamCount(4))
569 s=api.parString(ok,0);
570 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
573 if (typeid(*dst) == typeid(BranchObj) )
575 // Get number in parent
578 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
579 } else if (typeid(*dst) == typeid(MapCenterObj) )
581 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
582 // Get coordinates of mainbranch
587 if (ok) ((BranchObj*)selection)->move (x,y);
593 } else if (com=="setHeading")
595 if (api.checkParamCount(1))
597 s=api.parString (ok,0);
598 if (ok) setHeading (s);
600 } else if (com=="setURL")
602 if (api.checkParamCount(1))
604 s=api.parString (ok,0);
607 } else if (com=="setVymLink")
609 if (api.checkParamCount(1))
611 s=api.parString (ok,0);
612 if (ok) setVymLink(s);
615 // Internal commands, used for undo etc.
616 else if (com==QString("undoMap"))
618 if (api.checkParamCount(1))
619 undoXML("",api.parString (ok,0));
620 } else if (com==QString("undoPart"))
622 if (api.checkParamCount(2))
624 s=api.parString (ok,0);
625 t=api.parString (ok,1);
628 } else if (com=="select")
629 if (api.checkParamCount(1))
631 s=api.parString(ok,0);
636 api.setError ("Unknown command in: "+atom);
637 cout << "ME::parse api should have error now...\n";
643 cout << "MapEditor::parseAtom: Error!\n";
644 cout << " "<<api.errorDesc()<<endl;
649 void MapEditor::finishedLineEditNoSave()
651 // This is called by finishedLineEdit or any MapEditor method,
652 // which wants to assure, that lineedits finish, before e.g. a branch is
655 // After calling LineEdit and using the clipboard, the
656 // focus is not any longer on the main widget, we
657 // have to restore it using parentWidget()->setFocus()
661 editingBO->setHeading(lineedit->text() );
663 lineedit->releaseKeyboard();
665 parentWidget()->setFocus();
666 mapCenter->reposition();
668 ensureSelectionVisible();
673 bool MapEditor::isDefault()
678 bool MapEditor::isUnsaved()
683 bool MapEditor::hasChanged()
688 void MapEditor::setChanged()
693 actionEditUndo->setEnabled (true);
694 actionFileSave->setEnabled (true);
698 void MapEditor::closeMap()
700 // Finish open lineEdits
701 if (lineedit) finishedLineEditNoSave();
703 // Unselect before disabling the toolbar actions
704 if (selection) selection->unselect();
712 void MapEditor::setFilePath(QString fname)
714 setFilePath (fname,fname);
717 void MapEditor::setFilePath(QString fname, QString destname)
719 if (fname.isEmpty() || fname=="")
726 filePath=fname; // becomes absolute path
727 fileName=fname; // gets stripped of path
728 destPath=destname; // needed for vymlinks
730 // If fname is not an absolute path, complete it
731 filePath=QDir(fname).absPath();
732 fileDir=filePath.left (1+filePath.findRev ("/"));
734 // Set short name, too. Search from behind:
735 int i=fileName.findRev("/");
736 if (i>=0) fileName=fileName.remove (0,i+1);
738 // Forget the .vym (or .xml) for name of map
739 mapName=fileName.left(fileName.findRev(".",-1,true) );
743 QString MapEditor::getFilePath()
748 QString MapEditor::getFileName()
753 QString MapEditor::getMapName()
758 QString MapEditor::getDestPath()
763 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
765 // Finish open lineEdits
766 if (lineedit) finishedLineEditNoSave();
768 ErrorCode err=success;
772 if (selection) selection->unselect();
775 mapCenter->setMapEditor(this);
776 // (map state is set later at end of load...)
779 saveState(selection);
783 mapBuilderHandler handler;
786 // I am paranoid: file should exist anyway
787 // according to check in mainwindow.
790 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
791 tr("Couldn't open map " +fname)+".");
795 blockReposition=true;
796 QXmlInputSource source( file);
797 QXmlSimpleReader reader;
798 reader.setContentHandler( &handler );
799 reader.setErrorHandler( &handler );
800 handler.setMapEditor( this );
801 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
802 handler.setInputFile (file.name());
803 handler.setLoadMode (lmode);
805 bool ok = reader.parse( source );
806 blockReposition=false;
807 blockSaveState=false;
811 mapCenter->reposition();
821 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
822 tr( handler.errorProtocol() ) );
824 // Still return "success": the map maybe at least
825 // partially read by the parser
832 int MapEditor::save (const SaveMode &savemode)
834 // Finish open lineEdits
835 if (lineedit) finishedLineEditNoSave();
839 // The SaveMode UndoCommand is not supported here
840 if (savemode==UndoCommand) return 1;
842 // Create mapName and fileDir
843 makeSubDirs (fileDir);
847 fname=mapName+".xml";
849 // use name given by user, even if he chooses .doc
854 if (savemode==CompleteMap || selection==NULL)
855 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
857 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
859 if (!saveStringToDisk(fileDir+fname,saveFile))
866 actionFileSave->setEnabled(false);
872 void MapEditor::setZipped (bool z)
877 bool MapEditor::saveZipped ()
882 void MapEditor::print()
884 // Finish open lineEdits
885 if (lineedit) finishedLineEditNoSave();
889 printer = new QPrinter;
890 printer->setColorMode (QPrinter::Color);
891 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
894 QRect totalBBox=mapCenter->getTotalBBox();
896 // Try to set orientation automagically
897 // Note: Interpretation of generated postscript is amibiguous, if
898 // there are problems with landscape mode, see
899 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
901 if (totalBBox.width()>totalBBox.height())
902 // recommend landscape
903 printer->setOrientation (QPrinter::Landscape);
905 // recommend portrait
906 printer->setOrientation (QPrinter::Portrait);
908 if ( printer->setup(this) )
909 // returns false, if printing is canceled
911 QPainter pp(printer);
913 // Don't print the visualisation of selection
914 LinkableMapObj *oldselection=NULL;
917 oldselection=selection;
918 selection->unselect();
921 // Handle sizes of map and paper:
923 // setWindow defines which part of the canvas will be transformed
924 // setViewport defines area on paper in device coordinates (dpi)
925 // e.g. (0,50,700,700) is upper part on A4
926 // see also /usr/lib/qt3/doc/html/coordsys.html
928 QPaintDeviceMetrics metrics (printer);
930 double paperAspect = (double)metrics.width() / (double)metrics.height();
931 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
933 QRect mapRect=totalBBox;
934 QCanvasRectangle *frame=NULL;
935 QCanvasText *footerFN=NULL;
936 QCanvasText *footerDate=NULL;
937 if (printFrame || printFooter)
942 // Print frame around map
943 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
944 totalBBox.width()+20, totalBBox.height()+20);
945 frame=new QCanvasRectangle (mapRect,mapCanvas);
946 frame->setBrush (QColor(white));
947 frame->setPen (QColor(black));
951 /* TODO remove after testing
952 QCanvasLine *l=new QCanvasLine (mapCanvas);
953 l->setPoints (0,0,mapRect.width(),mapRect.height());
954 l->setPen (QPen(QColor(black), 1));
961 // Print footer below map
963 font.setPointSize(10);
964 footerFN=new QCanvasText (mapCanvas);
965 footerFN->setText ("VYM - " + fileName);
966 footerFN->setFont(font);
967 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
968 footerFN->setZ(Z_TEXT);
970 footerDate=new QCanvasText (mapCanvas);
971 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
972 footerDate->setFont(font);
973 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
974 footerDate->setZ(Z_TEXT);
977 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
980 pp.setWindow (mapRect);
983 if (mapAspect>=paperAspect)
985 // Fit horizontally to paper width
986 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
989 // Fit vertically to paper height
990 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
993 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
995 // Delete Frame and footer
1001 if (frame) delete (frame);
1003 // Restore selection
1006 selection=oldselection;
1007 selection->select();
1010 // Save settings in vymrc
1011 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1015 QPixmap MapEditor::getPixmap()
1017 QRect mapRect=mapCenter->getTotalBBox();
1018 QPixmap pix (mapRect.size());
1021 // Don't print the visualisation of selection
1022 LinkableMapObj *oldselection=NULL;
1025 oldselection=selection;
1026 selection->unselect();
1029 pp.setWindow (mapRect);
1031 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1034 // Restore selection
1037 selection=oldselection;
1038 selection->select();
1044 void MapEditor::setHideTmpMode (HideTmpMode mode)
1047 mapCenter->setHideTmp (hidemode);
1048 mapCenter->reposition();
1053 HideTmpMode MapEditor::getHideTmpMode()
1058 void MapEditor::exportImage(QString fn)
1060 // Finish open lineEdits
1061 if (lineedit) finishedLineEditNoSave();
1063 setExportMode (true);
1064 QPixmap pix (getPixmap());
1065 pix.save(fn, "PNG");
1066 setExportMode (false);
1069 void MapEditor::setExportMode (bool b)
1071 // should be called before and after exports
1072 // depending on the settings
1073 if (b && settings.readEntry("/vym/export/useHideExport","yes"))
1074 setHideTmpMode (HideExport);
1076 setHideTmpMode (HideNone);
1079 void MapEditor::exportImage(QString fn, int item)
1081 // Finish open lineEdits
1082 if (lineedit) finishedLineEditNoSave();
1084 setExportMode (true);
1085 QPixmap pix (getPixmap());
1086 pix.save(fn, exportImageFormatMenu->text(item) );
1087 setExportMode (false);
1090 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1094 ex.setMapCenter(mapCenter);
1095 if (ex.setConfigFile(cf))
1097 setExportMode (true);
1098 ex.exportPresentation();
1099 setExportMode (false);
1105 void MapEditor::exportXML(const QString &dir)
1107 // Hide stuff during export, if settings want this
1108 setExportMode (true);
1110 // Create subdirectories
1113 // write to directory
1114 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1117 file.setName ( dir + "/"+mapName+".xml");
1118 if ( !file.open( IO_WriteOnly ) )
1120 // This should neverever happen
1121 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1125 // Write it finally, and write in UTF8, no matter what
1126 QTextStream ts( &file );
1127 ts.setEncoding (QTextStream::UnicodeUTF8);
1131 // Now write image, too
1132 exportImage (dir+"/images/"+mapName+".png");
1134 setExportMode (false);
1137 void MapEditor::clear()
1141 selection->unselect();
1148 void MapEditor::copy()
1150 // Finish open lineEdits
1151 if (lineedit) finishedLineEditNoSave();
1155 // write to directory
1156 QString clipfile="part";
1157 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1160 file.setName ( clipboardDir + "/"+clipfile+".xml");
1161 if ( !file.open( IO_WriteOnly ) )
1163 // This should neverever happen
1164 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1168 // Write it finally, and write in UTF8, no matter what
1169 QTextStream ts( &file );
1170 ts.setEncoding (QTextStream::UnicodeUTF8);
1174 clipboardEmpty=false;
1179 void MapEditor::redo()
1181 // Finish open lineEdits
1182 if (lineedit) finishedLineEditNoSave();
1184 blockSaveState=true;
1186 // Find out current undo directory
1187 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1189 // Restore variables
1190 QString undoCommand;
1191 QString undoSelection;
1192 QString redoCommand;
1193 QString redoSelection;
1195 set.readSettings(QString(bakMapDir+"/commands"));
1196 undoCommand=set.readEntry ("undoCommand");
1197 undoSelection=set.readEntry ("undoSelection");
1198 redoCommand=set.readEntry ("redoCommand");
1199 redoSelection=set.readEntry ("redoSelection");
1201 // select object before redo
1202 if (!redoSelection.isEmpty())
1203 select (redoSelection);
1205 /* TODO remove testing
1206 cout << "ME::redo() begin\n";
1207 cout << " undosTotal="<<undosTotal<<endl;
1208 cout << " undosAvail="<<undosAvail<<endl;
1209 cout << " undoNum="<<undoNum<<endl;
1210 cout << " ---------------------------"<<endl;
1211 cout << " undoCom="<<undoCommand<<endl;
1212 cout << " undoSel="<<undoSelection<<endl;
1213 cout << " ---------------------------"<<endl;
1214 cout << " redoCom="<<redoCommand<<endl;
1215 cout << " redoSel="<<redoSelection<<endl;
1216 cout << " ---------------------------"<<endl;
1218 parseAtom (undoCommand);
1219 mapCenter->reposition();
1221 //if (!redoSelection.isEmpty())
1222 // select (redoSelection);
1226 // Undo not longer available now
1227 actionEditUndo->setEnabled (false);
1229 undoNum--; if (undoNum<1) undoNum=undosTotal;
1231 blockSaveState=false;
1232 /* TODO remove testing
1233 cout << "ME::redo() end\n";
1234 cout << " undosAvail="<<undosAvail<<endl;
1235 cout << " undoNum="<<undoNum<<endl;
1236 cout << " ---------------------------"<<endl<<endl;
1240 void MapEditor::undo()
1242 // Finish open lineEdits
1243 if (lineedit) finishedLineEditNoSave();
1245 blockSaveState=true;
1247 // Find out current undo directory
1248 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1250 // Restore variables
1251 QString undoCommand;
1252 QString undoSelection;
1253 QString redoCommand;
1254 QString redoSelection;
1256 set.readSettings(QString(bakMapDir+"/commands"));
1257 undoCommand= set.readEntry ("undoCommand");
1258 undoSelection=set.readEntry ("undoSelection");
1259 redoCommand= set.readEntry ("redoCommand");
1260 redoSelection=set.readEntry ("redoSelection");
1262 // select object before undo
1263 if (!undoSelection.isEmpty())
1264 select (undoSelection);
1267 cout << "ME::undo() begin\n";
1268 cout << " undosTotal="<<undosTotal<<endl;
1269 cout << " undosAvail="<<undosAvail<<endl;
1270 cout << " undoNum="<<undoNum<<endl;
1271 cout << " ---------------------------"<<endl;
1272 cout << " undoCom="<<undoCommand<<endl;
1273 cout << " undoSel="<<undoSelection<<endl;
1274 cout << " ---------------------------"<<endl;
1275 cout << " redoCom="<<redoCommand<<endl;
1276 cout << " redoSel="<<redoSelection<<endl;
1277 cout << " ---------------------------"<<endl;
1279 parseAtom (undoCommand);
1280 mapCenter->reposition();
1282 //if (!redoSelection.isEmpty())
1283 // select (redoSelection);
1287 // Undo not longer available now
1288 actionEditUndo->setEnabled (false);
1290 undoNum--; if (undoNum<1) undoNum=undosTotal;
1292 blockSaveState=false;
1293 /* TODO remove testing
1294 cout << "ME::undo() end\n";
1295 cout << " undosAvail="<<undosAvail<<endl;
1296 cout << " undoNum="<<undoNum<<endl;
1297 cout << " ---------------------------"<<endl<<endl;
1301 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1303 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1305 QFile file (bakMapPath);
1309 // We need to parse saved XML data
1310 mapBuilderHandler handler;
1311 QXmlInputSource source( file);
1312 QXmlSimpleReader reader;
1313 reader.setContentHandler( &handler );
1314 reader.setErrorHandler( &handler );
1315 handler.setMapEditor( this );
1316 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1317 if (undoSel.isEmpty())
1321 handler.setLoadMode (NewMap);
1325 handler.setLoadMode (ImportReplace);
1327 blockReposition=true;
1328 bool ok = reader.parse( source );
1329 blockReposition=false;
1332 // This should never ever happen
1333 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1334 tr( handler.errorProtocol() )+" in "+bakMapDir );
1338 QMessageBox::critical( 0, tr( "Critical Error" ),
1339 tr("Temporary directory %1 used for undo is gone. \n"
1340 "I will create a new one, but at the moment no undo is available.\n"
1341 "Maybe you want to reload your original data.\n\n"
1342 "Sorry for any inconveniences.").arg(bakMapDir) );
1347 void MapEditor::pasteNoSave()
1349 // Finish open lineEdits
1350 if (lineedit) finishedLineEditNoSave();
1352 load (clipboardDir+"/part.xml",ImportAdd);
1355 void MapEditor::cutNoSave()
1361 void MapEditor::paste()
1363 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1364 typeid(*selection) == typeid(MapCenterObj)))
1366 saveState(selection);
1368 mapCenter->reposition();
1373 void MapEditor::cut()
1375 saveState(selection->getParObj());
1378 mapCenter->reposition();
1382 void MapEditor::move(const int &x, const int &y)
1384 // TODO no saveState, because this is only internal at undo so far
1385 if (selection) selection->move(x,y);
1386 if (typeid(*selection) == typeid(FloatImageObj))
1387 ((FloatImageObj*)selection)->setRelPos();
1390 void MapEditor::moveBranchUp()
1392 // Finish open lineEdits
1393 if (lineedit) finishedLineEditNoSave();
1397 if (typeid(*selection) == typeid(BranchObj) )
1399 bo=(BranchObj*)selection;
1400 par=(BranchObj*)(bo->getParObj());
1401 selection->unselect();
1402 selection=par->moveBranchUp (bo);
1403 selection->select();
1404 saveState("moveBranchDown ()",bo);
1405 mapCenter->reposition();
1406 ensureSelectionVisible();
1410 void MapEditor::moveBranchDown()
1412 // Finish open lineEdits
1413 if (lineedit) finishedLineEditNoSave();
1417 if (typeid(*selection) == typeid(BranchObj) )
1419 bo=(BranchObj*)selection;
1420 par=(BranchObj*)(bo->getParObj());
1421 selection->unselect();
1422 selection=par->moveBranchDown(bo);
1423 selection->select();
1424 saveState("moveBranchUp ()",bo);
1425 mapCenter->reposition();
1426 ensureSelectionVisible();
1430 void MapEditor::editHeading()
1432 // Finish open lineEdits
1433 if (lineedit) finishedLineEditNoSave();
1436 (typeid(*selection) == typeid(BranchObj) ||
1437 typeid(*selection) == typeid(MapCenterObj) ) )
1439 editingBO=(BranchObj*)selection;
1440 saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
1442 ensureSelectionVisible();
1443 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1444 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1445 QString s=editingBO->getHeading();
1446 lineedit->setText(s);
1447 lineedit->setCursorPosition(1);
1448 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1449 lineedit->selectAll();
1451 lineedit->grabKeyboard();
1452 lineedit->setFocus();
1456 void MapEditor::setHeading(const QString &s)
1458 // Internal function, no saveState needed
1460 (typeid(*selection) == typeid(BranchObj) ||
1461 typeid(*selection) == typeid(MapCenterObj) ) )
1463 ((BranchObj*)selection)->setHeading(s);
1464 mapCenter->reposition();
1466 ensureSelectionVisible();
1470 void MapEditor::setURL (const QString &s)
1472 // Internal function, no saveState needed
1474 (typeid(*selection) == typeid(BranchObj) ||
1475 typeid(*selection) == typeid(MapCenterObj) ) )
1477 ((BranchObj*)selection)->setURL(s);
1478 mapCenter->reposition();
1480 ensureSelectionVisible();
1484 void MapEditor::setVymLink (const QString &s)
1486 // Internal function, no saveState needed
1488 (typeid(*selection) == typeid(BranchObj) ||
1489 typeid(*selection) == typeid(MapCenterObj) ) )
1491 ((BranchObj*)selection)->setVymLink(s);
1492 mapCenter->reposition();
1494 ensureSelectionVisible();
1498 void MapEditor::addNewBranch(int pos)
1500 // Finish open lineEdits
1501 if (lineedit) finishedLineEditNoSave();
1504 (typeid(*selection) == typeid(BranchObj) ||
1505 typeid(*selection) == typeid(MapCenterObj) ) )
1507 saveState(selection); //TODO undoCommand
1509 BranchObj* bo1 = (BranchObj*) selection;
1510 bool wasScrolled=false;
1511 BranchObj *newbo=NULL;
1514 // save scroll state. If scrolled, automatically select
1515 // new branch in order to tmp unscroll parent...
1516 wasScrolled=bo1->isScrolled();
1517 newbo=bo1->addBranch();
1520 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1524 // add above selection
1525 newbo=parbo->insertBranch(bo1->getNum());
1527 // add below selection
1528 newbo=parbo->insertBranch(bo1->getNum()+1);
1530 // This should not happen...
1535 LinkableMapObj *oldselection=selection;
1537 mapCenter->reposition();
1539 if (actionSettingsAutoedit->isOn() ||
1540 actionSettingsAutoselectHeading->isOn() )
1542 selection->unselect();
1544 selection->select();
1545 if (actionSettingsPasteNewHeading->isOn() )
1547 BranchObj *bo2= (BranchObj*)selection;
1548 bo2->setHeading("");
1550 if (actionSettingsAutoedit->isOn() )
1552 if (!actionSettingsAutoselectHeading->isOn()
1555 selection->unselect();
1556 selection=oldselection;
1557 selection->select();
1564 void MapEditor::addNewBranchHere()
1566 // Finish open lineEdits
1567 if (lineedit) finishedLineEditNoSave();
1570 (typeid(*selection) == typeid(BranchObj) ) )
1572 saveState(selection);
1574 BranchObj* bo1 = (BranchObj*) selection;
1575 bool wasScrolled=false;
1576 BranchObj *newbo=NULL;
1577 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1580 // add below selection
1581 newbo=parbo->insertBranch(bo1->getNum()+1);
1584 LinkableMapObj *oldselection=selection;
1585 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1587 mapCenter->reposition();
1589 if (actionSettingsAutoedit->isOn() ||
1590 actionSettingsAutoselectHeading->isOn() )
1592 selection->unselect();
1594 selection->select();
1595 if (actionSettingsPasteNewHeading->isOn() )
1597 BranchObj *bo2= (BranchObj*)selection;
1598 bo2->setHeading("");
1600 if (actionSettingsAutoedit->isOn() )
1602 if (!actionSettingsAutoselectHeading->isOn()
1605 selection->unselect();
1606 selection=oldselection;
1607 selection->select();
1613 void MapEditor::deleteSelection()
1615 // Finish open lineEdits
1616 if (lineedit) finishedLineEditNoSave();
1618 if (selection && typeid(*selection) ==typeid(BranchObj) )
1620 if (selection->getDepth()>1)
1621 // Normal branch, save parent with childs
1622 saveState(selection->getParObj());
1624 // Mainbranch, save whole map
1625 // TODO Better would be to insert mainbranch again at pos
1626 // But undoCommand is missing right now
1628 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1629 BranchObj* par=(BranchObj*)(bo->getParObj());
1632 par->removeBranch(bo);
1634 selection->select();
1635 ensureSelectionVisible();
1636 mapCenter->reposition();
1639 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1641 saveState(selection->getParObj());
1642 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1643 BranchObj* par=(BranchObj*)(fio->getParObj());
1646 par->removeFloatImage(fio);
1648 selection->select();
1649 ensureSelectionVisible();
1650 mapCenter->reposition();
1655 LinkableMapObj* MapEditor::getSelection()
1660 bool MapEditor::select (const QString &s)
1662 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1664 // Finally select the found object
1667 if (selection) unselect();
1669 selection->select();
1671 ensureSelectionVisible();
1677 void MapEditor::unselect()
1681 selectionLast=selection;
1682 selection->unselect();
1687 void MapEditor::reselect()
1691 selection=selectionLast;
1692 selection->select();
1697 void MapEditor::selectNextBranch()
1699 // Increase number of branch
1702 QString s=selection->getSelectString();
1708 part=s.section(",",-1);
1710 num=part.right(part.length() - 3);
1712 s=s.left (s.length() -num.length());
1715 num=QString ("%1").arg(num.toUInt()+1);
1719 // Try to select this one
1720 if (select (s)) return;
1722 // We have no direct successor,
1723 // try to increase the parental number in order to
1724 // find a successor with same depth
1726 int d=selection->getDepth();
1731 while (!found && d>0)
1733 s=s.section (",",0,d-1);
1734 // replace substring of current depth in s with "1"
1735 part=s.section(",",-1);
1737 num=part.right(part.length() - 3);
1741 // increase number of parent
1742 num=QString ("%1").arg(num.toUInt()+1);
1743 s=s.section (",",0,d-2) + ","+ typ+num;
1746 // Special case, look at orientation
1747 if (selection->getOrientation()==OrientRightOfCenter)
1748 num=QString ("%1").arg(num.toUInt()+1);
1750 num=QString ("%1").arg(num.toUInt()-1);
1755 // pad to oldDepth, select the first branch for each depth
1756 for (i=d;i<oldDepth;i++)
1761 if ( ((BranchObj*)selection)->countBranches()>0)
1769 // try to select the freshly built string
1777 void MapEditor::selectPrevBranch()
1779 // Decrease number of branch
1782 QString s=selection->getSelectString();
1788 part=s.section(",",-1);
1790 num=part.right(part.length() - 3);
1792 s=s.left (s.length() -num.length());
1795 num=QString ("%1").arg(num.toUInt()-1);
1799 // Try to select this one
1800 if (select (s)) return;
1802 // We have no direct precessor,
1803 // try to decrease the parental number in order to
1804 // find a precessor with same depth
1806 int d=selection->getDepth();
1811 while (!found && d>0)
1813 s=s.section (",",0,d-1);
1814 // replace substring of current depth in s with "1"
1815 part=s.section(",",-1);
1817 num=part.right(part.length() - 3);
1821 // decrease number of parent
1822 num=QString ("%1").arg(num.toUInt()-1);
1823 s=s.section (",",0,d-2) + ","+ typ+num;
1826 // Special case, look at orientation
1827 if (selection->getOrientation()==OrientRightOfCenter)
1828 num=QString ("%1").arg(num.toUInt()-1);
1830 num=QString ("%1").arg(num.toUInt()+1);
1835 // pad to oldDepth, select the last branch for each depth
1836 for (i=d;i<oldDepth;i++)
1840 if ( ((BranchObj*)selection)->countBranches()>0)
1841 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1848 // try to select the freshly built string
1856 void MapEditor::selectUpperBranch()
1858 // Finish open lineEdits
1859 if (lineedit) finishedLineEditNoSave();
1863 if (typeid(*selection) == typeid(BranchObj))
1865 if (selection->getOrientation()==OrientRightOfCenter)
1868 if (selection->getDepth()==1)
1876 void MapEditor::selectLowerBranch()
1878 // Finish open lineEdits
1879 if (lineedit) finishedLineEditNoSave();
1883 if (typeid(*selection) == typeid(BranchObj))
1885 if (selection->getOrientation()==OrientRightOfCenter)
1888 if (selection->getDepth()==1)
1897 void MapEditor::selectLeftBranch()
1899 // Finish open lineEdits
1900 if (lineedit) finishedLineEditNoSave();
1906 if (typeid(*selection) == typeid(MapCenterObj))
1908 par= (BranchObj*) selection;
1909 bo=par->getLastSelectedBranch();
1912 // Workaround for reselecting on left and right side
1913 if (bo->getOrientation()==OrientRightOfCenter)
1915 bo=par->getLastBranch();
1921 selection->select();
1923 ensureSelectionVisible();
1928 par=(BranchObj*)(selection->getParObj());
1929 if (selection->getOrientation()==OrientRightOfCenter)
1931 if (typeid(*selection) == typeid(BranchObj) ||
1932 typeid(*selection) == typeid(FloatImageObj))
1934 selection->unselect();
1936 selection->select();
1938 ensureSelectionVisible();
1942 if (typeid(*selection) == typeid(BranchObj) )
1944 bo=((BranchObj*)selection)->getLastSelectedBranch();
1947 selection->unselect();
1949 selection->select();
1951 ensureSelectionVisible();
1959 void MapEditor::selectRightBranch()
1961 // Finish open lineEdits
1962 if (lineedit) finishedLineEditNoSave();
1969 if (typeid(*selection) == typeid(MapCenterObj))
1971 par= (BranchObj*) selection;
1972 bo=par->getLastSelectedBranch();
1975 // Workaround for relecting on left and right side
1976 if (bo->getOrientation()==OrientLeftOfCenter)
1977 bo=par->getFirstBranch();
1982 selection->select();
1983 ensureSelectionVisible();
1988 par=(BranchObj*)(selection->getParObj());
1989 if (selection->getOrientation()==OrientLeftOfCenter)
1991 if (typeid(*selection) == typeid(BranchObj) ||
1992 typeid(*selection) == typeid(FloatImageObj))
1994 selection->unselect();
1996 selection->select();
1998 ensureSelectionVisible();
2002 if (typeid(*selection) == typeid(BranchObj) )
2004 bo=((BranchObj*)selection)->getLastSelectedBranch();
2007 selection->unselect();
2009 selection->select();
2011 ensureSelectionVisible();
2019 void MapEditor::selectFirstBranch()
2021 // Finish open lineEdits
2022 if (lineedit) finishedLineEditNoSave();
2028 if (typeid(*selection) == typeid(BranchObj))
2030 bo1= (BranchObj*) selection;
2031 par=(BranchObj*)(bo1->getParObj());
2032 bo2=par->getFirstBranch();
2036 selection->select();
2037 ensureSelectionVisible();
2044 void MapEditor::selectLastBranch()
2046 // Finish open lineEdits
2047 if (lineedit) finishedLineEditNoSave();
2053 if (typeid(*selection) == typeid(BranchObj))
2055 bo1= (BranchObj*) selection;
2056 par=(BranchObj*)(bo1->getParObj());
2057 bo2=par->getLastBranch();
2061 selection->select();
2062 ensureSelectionVisible();
2069 void MapEditor::setColor(QColor c)
2074 void MapEditor::selectBackgroundColor()
2076 // Finish open lineEdits
2077 if (lineedit) finishedLineEditNoSave();
2079 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2080 if ( !col.isValid() ) return;
2081 setBackgroundColor( col );
2085 void MapEditor::setBackgroundColor(QColor c)
2087 mapCanvas->setBackgroundColor (c);
2090 QColor MapEditor::pickColor()
2094 if (typeid(*selection) == typeid(BranchObj) ||
2095 typeid(*selection) == typeid(MapCenterObj))
2097 BranchObj *bo=(BranchObj*)selection;
2098 actColor=bo->getColor();
2104 void MapEditor::colorItem()
2108 if (typeid(*selection) == typeid(BranchObj) ||
2109 typeid(*selection) == typeid(MapCenterObj))
2111 saveState(selection); //TODO undoCommand
2112 BranchObj *bo=(BranchObj*)selection;
2113 bo->setColor(actColor); // color branch
2118 void MapEditor::colorBranch()
2122 if (typeid(*selection) == typeid(BranchObj) ||
2123 typeid(*selection) == typeid(MapCenterObj))
2125 saveState(selection); //TODO undoCommand
2126 BranchObj *bo=(BranchObj*)selection;
2127 bo->setColorChilds(actColor); // color links, color childs
2133 void MapEditor::toggleStandardFlag(QString f)
2137 saveState(selection);// TODO undoCommand
2138 ((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2143 void MapEditor::setViewCenter()
2145 // transform to CanvasView Coord:
2146 QPoint p=worldMatrix().map(movingCenter);
2147 center ( p.x(), p.y());
2151 BranchObj* MapEditor::findText (QString s, bool cs)
2154 { // Nothing found or new find process
2156 // nothing found, start again
2158 itFind=mapCenter->first();
2160 bool searching=true;
2161 bool foundNote=false;
2162 while (searching && !EOFind)
2166 // Searching in Note
2167 if (itFind->getNote().contains(s,cs))
2169 if (selection!=itFind)
2171 if (selection) ((BranchObj*)selection)->unselect();
2173 selection->select();
2175 ensureSelectionVisible();
2177 if (textEditor->findText(s,cs))
2183 // Searching in Heading
2184 if (searching && itFind->getHeading().contains (s,cs) )
2186 if (selection) ((BranchObj*)selection)->unselect();
2188 selection->select();
2190 ensureSelectionVisible();
2196 itFind=itFind->next();
2197 if (!itFind) EOFind=true;
2203 return (BranchObj*)selection;
2208 void MapEditor::findReset()
2209 { // Necessary if text to find changes during a find process
2214 void MapEditor::openURL()
2218 if (typeid(*selection) == typeid(BranchObj) ||
2219 typeid(*selection) == typeid(MapCenterObj))
2221 QString url=((BranchObj*)selection)->getURL();
2223 QProcess *proc = new QProcess( this );
2225 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL" ));
2226 proc->addArgument( url);
2228 if ( !proc->start() )
2230 if (mainWindow->settingsURL() )
2236 void MapEditor::editURL()
2238 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2239 typeid(*selection) == typeid(MapCenterObj)) )
2242 BranchObj *bo=(BranchObj*)selection;
2243 QString text = QInputDialog::getText(
2244 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2245 bo->getURL(), &ok, this );
2248 // user entered something and pressed OK
2249 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2256 void MapEditor::editHeading2URL()
2258 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2259 typeid(*selection) == typeid(MapCenterObj)) )
2261 BranchObj *bo=(BranchObj*)selection;
2262 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2263 bo->setURL (bo->getHeading());
2268 void MapEditor::editBugzilla2URL()
2270 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2271 typeid(*selection) == typeid(MapCenterObj)) )
2273 BranchObj *bo=(BranchObj*)selection;
2274 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2275 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2281 void MapEditor::editFATE2URL()
2283 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2284 typeid(*selection) == typeid(MapCenterObj)) )
2286 BranchObj *bo=(BranchObj*)selection;
2287 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2288 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2294 void MapEditor::editVymLink()
2296 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2297 typeid(*selection) == typeid(MapCenterObj)) )
2299 BranchObj *bo=(BranchObj*)selection;
2300 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
2301 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2302 fd->setCaption(__VYM " - " +tr("Link to another map"));
2303 if (! bo->getVymLink().isEmpty() )
2304 fd->setSelection( bo->getVymLink() );
2308 if ( fd->exec() == QDialog::Accepted )
2310 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2311 bo->setVymLink (fd->selectedFile() );
2313 mapCenter->reposition();
2320 void MapEditor::deleteVymLink()
2322 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2323 typeid(*selection) == typeid(MapCenterObj)) )
2325 BranchObj *bo=(BranchObj*)selection;
2326 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2327 bo->setVymLink ("" );
2329 mapCenter->reposition();
2335 void MapEditor::setHideExport()
2337 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2338 typeid(*selection) == typeid(MapCenterObj)) ||
2339 (typeid(*selection)==typeid(FloatImageObj))
2342 saveState(); //TODO undoCommand
2343 OrnamentedObj *oo=(OrnamentedObj*)selection;
2344 oo->setHideInExport(actionEditToggleHideExport->isOn());
2346 mapCenter->reposition();
2352 void MapEditor::toggleHideExport()
2354 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2355 typeid(*selection) == typeid(MapCenterObj)) ||
2356 (typeid(*selection)==typeid(FloatImageObj))
2359 saveState(); //TODO undoCommand
2360 OrnamentedObj *oo=(OrnamentedObj*)selection;
2361 if (oo->hideInExport())
2362 oo->setHideInExport(false);
2364 oo->setHideInExport(true);
2365 actionEditToggleHideExport->setOn (oo->hideInExport());
2367 mapCenter->reposition();
2373 QString MapEditor::getVymLink()
2375 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2376 typeid(*selection) == typeid(MapCenterObj)) )
2378 return ((BranchObj*)selection)->getVymLink();
2384 void MapEditor::removeBranchHere()
2386 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2388 BranchObj* bo=(BranchObj*)selection;
2389 BranchObj* par=(BranchObj*)(bo->getParObj());
2390 if (bo->getDepth()==1)
2393 saveState(selection->getParObj()); // TODO undoCommand
2394 QString sel=selection->getSelectString();
2396 par->removeBranchHere(bo);
2397 mapCenter->reposition();
2402 void MapEditor::removeChilds()
2404 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2406 saveState(selection->getParObj());
2407 ((BranchObj*)selection)->removeChilds();
2408 mapCenter->reposition();
2412 void MapEditor::editMapInfo()
2414 ExtraInfoDialog dia;
2415 dia.setMapName (getFileName() );
2416 dia.setAuthor (mapCenter->getAuthor() );
2417 dia.setComment(mapCenter->getComment() );
2422 QCanvasItemList l=canvas()->allItems();
2423 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2425 stats+=QString ("%1 items on canvas\n").arg (i,6);
2432 bo=mapCenter->first();
2435 if (!bo->getNote().isEmpty() ) n++;
2436 f+= bo->countFloatImages();
2438 xl+=bo->countXLinks();
2441 stats+=QString ("%1 branches\n").arg (b-1,6);
2442 stats+=QString ("%1 xLinks \n").arg (xl,6);
2443 stats+=QString ("%1 notes\n").arg (n,6);
2444 stats+=QString ("%1 images\n").arg (f,6);
2445 dia.setStats (stats);
2447 // Finally show dialog
2448 if (dia.exec() == QDialog::Accepted)
2450 saveState(); //TODO undoCommand
2451 mapCenter->setAuthor (dia.getAuthor() );
2452 mapCenter->setComment (dia.getComment() );
2456 void MapEditor::updateActions()
2459 if (getLinkColorHint()==HeadingColor)
2460 actionFormatLinkColorHint->setOn(true);
2462 actionFormatLinkColorHint->setOn(false);
2467 actionFormatLinkStyleLine->setOn(true);
2470 actionFormatLinkStyleParabel->setOn(true);
2473 actionFormatLinkStylePolyLine->setOn(true);
2475 case StylePolyParabel:
2476 actionFormatLinkStylePolyParabel->setOn(true);
2482 QPixmap pix( 16, 16 );
2483 pix.fill( mapCanvas->backgroundColor() );
2484 actionFormatBackColor->setIconSet( pix );
2485 pix.fill( defLinkColor );
2486 actionFormatLinkColor->setIconSet( pix );
2488 actionEditUndo->setEnabled( mapChanged );
2489 actionFileSave->setEnabled( mapUnsaved );
2493 if ( (typeid(*selection) == typeid(BranchObj)) ||
2494 (typeid(*selection) == typeid(MapCenterObj)) )
2496 BranchObj *bo=(BranchObj*)selection;
2497 // Take care of links
2498 if (bo->countXLinks()==0)
2500 branchLinksContextMenu->clear();
2501 branchLinksContextMenu->insertItem ("No xLink available");
2502 branchLinksContextMenuDup->clear();
2503 branchLinksContextMenuDup->insertItem ("No xLink available");
2509 branchLinksContextMenu->clear();
2510 branchLinksContextMenuDup->clear();
2511 for (int i=0; i<=bo->countXLinks();i++)
2513 bot=bo->XLinkTargetAt(i);
2516 s=bot->getHeading();
2519 branchLinksContextMenu->insertItem (s);
2520 branchLinksContextMenuDup->insertItem (s);
2525 standardFlagsDefault->setEnabled (true);
2527 actionEditToggleScroll->setEnabled (true);
2528 if ( bo->isScrolled() )
2529 actionEditToggleScroll->setOn(true);
2531 actionEditToggleScroll->setOn(false);
2533 if ( bo->getURL().isEmpty() )
2534 actionEditOpenURL->setEnabled (false);
2536 actionEditOpenURL->setEnabled (true);
2538 if ( bo->getVymLink().isEmpty() )
2540 actionEditOpenVymLink->setEnabled (false);
2541 actionEditDeleteVymLink->setEnabled (false);
2544 actionEditOpenVymLink->setEnabled (true);
2545 actionEditDeleteVymLink->setEnabled (true);
2547 actionEditToggleHideExport->setEnabled (true);
2548 actionEditToggleHideExport->setOn (bo->hideInExport() );
2550 actionEditCopy->setEnabled (true);
2551 actionEditCut->setEnabled (true);
2552 if (!clipboardEmpty)
2553 actionEditPaste->setEnabled (true);
2555 actionEditPaste->setEnabled (false);
2556 for (a=actionListBranches.first();a;a=actionListBranches.next())
2557 a->setEnabled(true);
2558 actionEditDelete->setEnabled (true);
2559 switch (selection->getFrameType())
2562 actionFormatFrameNone->setOn(true);
2565 actionFormatFrameRectangle->setOn(true);
2570 actionFormatIncludeImagesVer->setOn
2571 ( ((BranchObj*)selection)->getIncludeImagesVer());
2572 actionFormatIncludeImagesHor->setOn
2573 ( ((BranchObj*)selection)->getIncludeImagesHor());
2574 actionFormatHideLinkUnselected->setOn
2575 (selection->getHideLinkUnselected());
2577 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2579 FloatObj *fo=(FloatImageObj*)selection;
2580 standardFlagsDefault->setEnabled (false);
2582 actionEditOpenURL->setEnabled (false);
2583 actionEditOpenVymLink->setEnabled (false);
2584 actionEditDeleteVymLink->setEnabled (false);
2585 actionEditToggleHideExport->setEnabled (true);
2586 actionEditToggleHideExport->setOn (fo->hideInExport() );
2589 actionEditCopy->setEnabled (true);
2590 actionEditCut->setEnabled (true);
2591 actionEditPaste->setEnabled (false);
2592 for (a=actionListBranches.first();a;a=actionListBranches.next())
2593 a->setEnabled(false);
2594 actionEditDelete->setEnabled (true);
2595 actionFormatHideLinkUnselected->setOn
2596 ( selection->getHideLinkUnselected());
2601 standardFlagsDefault->setEnabled (false);
2603 actionEditCopy->setEnabled (false);
2604 actionEditCut->setEnabled (false);
2605 actionEditPaste->setEnabled (false);
2606 for (a=actionListBranches.first();a;a=actionListBranches.next())
2607 a->setEnabled(false);
2609 actionEditToggleScroll->setEnabled (true);
2610 actionEditOpenURL->setEnabled (false);
2611 actionEditOpenVymLink->setEnabled (false);
2612 actionEditDeleteVymLink->setEnabled (false);
2613 actionEditHeading2URL->setEnabled (false);
2614 actionEditDelete->setEnabled (false);
2618 void MapEditor::updateNoteFlag()
2621 if ( (typeid(*selection) == typeid(BranchObj)) ||
2622 (typeid(*selection) == typeid(MapCenterObj)) )
2623 ((BranchObj*)selection)->updateNoteFlag();
2626 void MapEditor::setLinkStyle (LinkStyle ls)
2630 saveState(); // TODO undoCommand
2632 bo=mapCenter->first();
2636 bo->setLinkStyle(bo->getDefLinkStyle());
2639 mapCenter->reposition();
2642 LinkStyle MapEditor::getLinkStyle ()
2647 void MapEditor::setLinkColor(QColor c)
2653 void MapEditor::setLinkColorHint()
2655 // called from setLinkColorHint(lch) or at end of parse
2657 bo=mapCenter->first();
2665 void MapEditor::setLinkColorHint(LinkColorHint lch)
2671 void MapEditor::toggleLinkColorHint()
2673 if (linkcolorhint==HeadingColor)
2674 linkcolorhint=DefaultColor;
2676 linkcolorhint=HeadingColor;
2678 bo=mapCenter->first();
2686 LinkColorHint MapEditor::getLinkColorHint()
2688 return linkcolorhint;
2691 QColor MapEditor::getDefLinkColor()
2693 return defLinkColor;
2696 void MapEditor::setDefXLinkColor(QColor col)
2701 QColor MapEditor::getDefXLinkColor()
2703 return defXLinkColor;
2706 void MapEditor::setDefXLinkWidth (int w)
2711 int MapEditor::getDefXLinkWidth()
2713 return defXLinkWidth;
2716 void MapEditor::selectLinkColor()
2718 // Finish open lineEdits
2719 if (lineedit) finishedLineEditNoSave();
2721 QColor col = QColorDialog::getColor( defLinkColor, this );
2722 if ( !col.isValid() ) return;
2723 setLinkColor( col );
2724 saveState(); //TODO undoCommand
2728 void MapEditor::toggleScroll()
2730 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2732 BranchObj *bo=((BranchObj*)selection);
2733 if (bo->countBranches()==0) return;
2734 if (bo->getDepth()==0) return;
2735 saveState(selection);
2742 void MapEditor::unScrollAll()
2745 bo=mapCenter->first();
2748 if (bo->isScrolled()) bo->toggleScroll();
2753 void MapEditor::loadFloatImage ()
2756 (typeid(*selection) == typeid(BranchObj)) ||
2757 (typeid(*selection) == typeid(MapCenterObj)) )
2759 BranchObj *bo=((BranchObj*)selection);
2761 QFileDialog *fd=new QFileDialog( this);
2762 fd->setMode (QFileDialog::ExistingFiles);
2763 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2764 ImagePreview *p =new ImagePreview (fd);
2765 fd->setContentsPreviewEnabled( TRUE );
2766 fd->setContentsPreview( p, p );
2767 fd->setPreviewMode( QFileDialog::Contents );
2768 fd->setCaption(__VYM " - " +tr("Load image"));
2769 fd->setDir (lastImageDir);
2773 if ( fd->exec() == QDialog::Accepted )
2775 saveState(selection);
2776 lastImageDir=fn.left(fn.findRev ("/"));
2777 QStringList flist = fd->selectedFiles();
2778 QStringList::Iterator it = flist.begin();
2779 while( it != flist.end() )
2782 bo->addFloatImage();
2783 // TODO check if load was successful
2784 bo->getLastFloatImage()->load(*it);
2785 bo->getLastFloatImage()->setOriginalFilename(fn);
2789 mapCenter->reposition();
2798 void MapEditor::saveFloatImage (int item)
2801 (typeid(*selection) == typeid(FloatImageObj)) )
2803 FloatImageObj *fio=((FloatImageObj*)selection);
2804 const char* fmt = saveImageFormatMenu->text(item);
2806 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2807 fd->addFilter ("PNG (*.png)");
2808 fd->addFilter ("BMP (*.bmp)");
2809 fd->addFilter ("XBM (*.xbm)");
2810 fd->addFilter ("JPG (*.jpg)");
2811 fd->addFilter ("XPM (*.xpm)");
2812 fd->addFilter ("GIF (*.gif)");
2813 fd->addFilter ("PNM (*.pnm)");
2814 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2815 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2816 fd->setMode( QFileDialog::AnyFile );
2817 fd->setSelection (fio->getOriginalFilename());
2821 if ( fd->exec() == QDialog::Accepted )
2823 if (QFile (fd->selectedFile()).exists() )
2825 QMessageBox mb( __VYM,
2826 tr("The file %1 exists already.\n"
2827 "Do you want to overwrite it?").arg(fd->selectedFile()),
2828 QMessageBox::Warning,
2829 QMessageBox::Yes | QMessageBox::Default,
2830 QMessageBox::Cancel | QMessageBox::Escape,
2831 QMessageBox::QMessageBox::NoButton );
2833 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2834 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2837 case QMessageBox::Yes:
2840 case QMessageBox::Cancel:
2846 fio->save (fd->selectedFile(),fmt);
2851 void MapEditor::setFrame(const FrameType &t)
2854 (typeid(*selection) == typeid(BranchObj)) ||
2855 (typeid(*selection) == typeid(MapCenterObj)) )
2857 selection->setFrameType (t);
2858 mapCenter->reposition();
2859 selection->updateLink();
2863 void MapEditor::setIncludeImagesVer(bool b)
2866 (typeid(*selection) == typeid(BranchObj)) ||
2867 (typeid(*selection) == typeid(MapCenterObj)) )
2868 ((BranchObj*)selection)->setIncludeImagesVer(b);
2869 mapCenter->reposition();
2872 void MapEditor::setIncludeImagesHor(bool b)
2875 (typeid(*selection) == typeid(BranchObj)) ||
2876 (typeid(*selection) == typeid(MapCenterObj)) )
2877 ((BranchObj*)selection)->setIncludeImagesHor(b);
2878 mapCenter->reposition();
2881 void MapEditor::setHideLinkUnselected (bool b)
2884 (typeid(*selection) == typeid(BranchObj)) ||
2885 (typeid(*selection) == typeid(MapCenterObj)) ||
2886 (typeid(*selection) == typeid(FloatImageObj)) )
2887 selection->setHideLinkUnselected(b);
2890 void MapEditor::importDir(BranchObj *dst, QDir d)
2893 (typeid(*selection) == typeid(BranchObj)) ||
2894 (typeid(*selection) == typeid(MapCenterObj)) )
2898 // Traverse directories
2899 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2900 const QFileInfoList *dirlist = d.entryInfoList();
2901 QFileInfoListIterator itdir( *dirlist );
2904 while ( (fi = itdir.current()) != 0 )
2906 if (fi->fileName() != "." && fi->fileName() != ".." )
2909 bo=dst->getLastBranch();
2910 bo->setHeading (fi->fileName() );
2911 bo->setColor (QColor("blue"));
2913 if ( !d.cd(fi->fileName()) )
2914 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2917 // Recursively add subdirs
2925 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2926 const QFileInfoList *filelist = d.entryInfoList();
2927 QFileInfoListIterator itfile( *filelist );
2929 while ( (fi = itfile.current()) != 0 )
2932 bo=dst->getLastBranch();
2933 bo->setHeading (fi->fileName() );
2934 bo->setColor (QColor("black"));
2935 if (fi->fileName().right(4) == ".vym" )
2936 bo->setVymLink (fi->filePath());
2943 void MapEditor::importDir()
2946 (typeid(*selection) == typeid(BranchObj)) ||
2947 (typeid(*selection) == typeid(MapCenterObj)) )
2949 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
2950 fd->setMode (QFileDialog::DirectoryOnly);
2951 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2952 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
2956 if ( fd->exec() == QDialog::Accepted )
2958 BranchObj *bo=((BranchObj*)selection);
2959 importDir (bo,QDir(fd->selectedFile()) );
2960 mapCenter->reposition();
2967 void MapEditor::followXLink(int i)
2970 (typeid(*selection) == typeid(BranchObj)) ||
2971 (typeid(*selection) == typeid(MapCenterObj)) )
2973 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
2976 selection->unselect();
2978 selection->select();
2979 ensureSelectionVisible();
2984 void MapEditor::editXLink(int i)
2987 (typeid(*selection) == typeid(BranchObj)) ||
2988 (typeid(*selection) == typeid(MapCenterObj)) )
2990 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
2993 EditXLinkDialog dia;
2995 dia.setSelection(selection);
2996 if (dia.exec() == QDialog::Accepted)
2998 if (dia.useSettingsGlobal() )
3000 setDefXLinkColor (xlo->getColor() );
3001 setDefXLinkWidth (xlo->getWidth() );
3003 if (dia.deleteXLink())
3004 ((BranchObj*)selection)->deleteXLinkAt(i);
3005 saveState(); //TODO undoCommand
3011 void MapEditor::testFunction()
3013 cout << "MapEditor::testFunction() called\n";
3015 if (hidemode==HideNone)
3017 setHideTmpMode (HideExport);
3018 mapCenter->calcBBoxSizeWithChilds();
3019 QRect totalBBox=mapCenter->getTotalBBox();
3020 QRect mapRect=totalBBox;
3021 QCanvasRectangle *frame=NULL;
3023 cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
3025 mapRect.setRect (totalBBox.x(), totalBBox.y(),
3026 totalBBox.width(), totalBBox.height());
3027 frame=new QCanvasRectangle (mapRect,mapCanvas);
3028 frame->setBrush (QColor(white));
3029 frame->setPen (QColor(black));
3035 setHideTmpMode (HideNone);
3037 cout <<" hidemode="<<hidemode<<endl;
3040 void MapEditor::ensureSelectionVisible()
3044 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
3046 if (selection->getOrientation() == OrientLeftOfCenter)
3047 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
3049 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
3050 ensureVisible (p.x(), p.y() );
3055 void MapEditor::updateViewCenter()
3057 // Update movingCenter, so that we can zoom comfortably later
3058 QRect rc = QRect( contentsX(), contentsY(),
3059 visibleWidth(), visibleHeight() );
3060 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
3061 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
3062 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
3065 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3067 // Lineedits are already closed by preceding
3068 // mouseEvent, we don't need to close here.
3070 QPoint p = inverseWorldMatrix().map(e->pos());
3071 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3074 { // MapObj was found
3075 if (selection != lmo)
3077 // select the MapObj
3078 if (selection) selection->unselect();
3080 selection->select();
3086 if (typeid(*selection)==typeid(BranchObj) ||
3087 typeid(*selection)==typeid(MapCenterObj) )
3089 // Context Menu on branch or mapcenter
3091 branchContextMenu->popup(e->globalPos() );
3093 if (typeid(*selection)==typeid(FloatImageObj))
3095 // Context Menu on floatimage
3097 floatimageContextMenu->popup(e->globalPos() );
3101 { // No MapObj found, we are on the Canvas itself
3102 // Context Menu on Canvas
3104 canvasContextMenu->popup(e->globalPos() );
3108 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3110 // Finish open lineEdits
3111 if (lineedit) finishedLineEditNoSave();
3113 QPoint p = inverseWorldMatrix().map(e->pos());
3114 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3116 // Special case: CTRL is pressed
3117 if (e->state() & QMouseEvent::ControlButton)
3119 if (actionModModeColor->isOn())
3121 if (e->state() & QMouseEvent::ControlButton)
3124 setCursor (pickColorCursor);
3128 if (actionModModeLink->isOn())
3130 BranchObj *bo_begin=NULL;
3132 bo_begin=(BranchObj*)(lmo);
3135 ((typeid(*selection) == typeid(BranchObj)) ||
3136 (typeid(*selection) == typeid(MapCenterObj))) )
3137 bo_begin=(BranchObj*)selection;
3141 linkingObj_src=bo_begin;
3142 tmpXLink=new XLinkObj (mapCanvas);
3143 tmpXLink->setBegin (bo_begin);
3144 tmpXLink->setEnd (p);
3145 tmpXLink->setColor(defXLinkColor);
3146 tmpXLink->setWidth(defXLinkWidth);
3147 tmpXLink->updateXLink();
3148 tmpXLink->setVisibility (true);
3155 { // MapObj was found
3156 if (selection != lmo)
3158 // select the MapObj
3159 if (selection) selection->unselect();
3161 selection->select();
3166 // Check, if systemFlag clicked
3167 if (typeid(*selection)==typeid(BranchObj) ||
3168 typeid(*selection)==typeid(MapCenterObj) )
3170 QString foname=((BranchObj*)selection)->getSystemFlagName(p);
3171 if (!foname.isEmpty())
3173 // Do not move, if systemFlag clicked
3176 else if (foname=="vymLink")
3178 mainWindow->editOpenVymLink();
3179 // tabWidget may change, better return now
3180 // before segfaulting...
3182 } else if (foname=="note")
3183 mainWindow->windowToggleNoteEditor();
3184 else if (foname=="hideInExport")
3189 // Left Button Move Branches
3190 if (e->button() == QMouseEvent::LeftButton )
3192 movingObj_start.setX( p.x() - selection->x() );
3193 movingObj_start.setY( p.y() - selection->y() );
3194 movingObj_orgPos.setX (lmo->x() );
3195 movingObj_orgPos.setY (lmo->y() );
3197 // If modMode==copy, then we want to "move" the _new_ object around
3198 // then we need the offset from p to the _old_ selection, because of tmp
3199 if (actionModModeCopy->isOn() &&
3200 e->state() & QMouseEvent::ControlButton)
3202 if (typeid(*selection)==typeid(BranchObj) )
3205 mapCenter->addBranch ((BranchObj*)selection);
3207 selection=mapCenter->getLastBranch();
3208 selection->select();
3209 mapCenter->reposition();
3212 movingObj=selection;
3214 // Middle Button Toggle Scroll
3215 // (On Mac OS X this won't work, but we still have
3216 // a button in the toolbar)
3217 if (e->button() == QMouseEvent::MidButton )
3221 { // No MapObj found, we are on the Canvas itself
3222 // Left Button move Pos of CanvasView
3223 if (e->button() == QMouseEvent::LeftButton )
3225 movingObj=NULL; // move Content not Obj
3226 movingObj_start=e->globalPos();
3227 movingCont_start=QPoint (contentsX(), contentsY() );
3228 movingVec=QPoint(0,0);
3229 setCursor(handOpenCursor);
3234 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3236 QPoint p = inverseWorldMatrix().map(e->pos());
3238 // Move the selected MapObj
3239 if ( selection && movingObj)
3241 // To avoid jumping of the CanvasView, only
3242 // ensureSelectionVisible, if not tmp linked
3243 if (!selection->hasParObjTmp())
3244 ensureSelectionVisible ();
3246 // Now move the selection, but add relative position
3247 // (movingObj_start) where selection was chosen with
3248 // mousepointer. (This avoids flickering resp. jumping
3249 // of selection back to absPos)
3251 LinkableMapObj *lmosel;
3252 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3254 // Check if we could link
3255 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3258 if (typeid(*selection) == typeid(FloatImageObj))
3260 FloatObj *fo=(FloatObj*)selection;
3261 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3262 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3266 // Relink float to new mapcenter or branch, if shift is pressed
3267 // Only relink, if selection really has a new parent
3268 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3269 ( (typeid(*lmo)==typeid(BranchObj)) ||
3270 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3271 ( lmo != fo->getParObj())
3274 if (typeid(*fo) == typeid(FloatImageObj))
3277 FloatImageObj *fio=(FloatImageObj*)(fo);
3278 ((BranchObj*)(lmo))->addFloatImage (fio);
3280 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3281 fio=((BranchObj*)(lmo))->getLastFloatImage();
3284 selection=(LinkableMapObj*)(fio);
3285 selection->select();
3286 movingObj=(MapObj*)(fio);
3289 } else // selection != a FloatObj
3291 if (lmosel->getDepth()==0)
3293 if (e->state() == (LeftButton | !ShiftButton))
3294 // If mapCenter is moved, move all the rest by default, too.
3295 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3297 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3300 if (lmosel->getDepth()==1)
3302 // depth==1, mainbranch
3303 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3307 if (lmosel->getOrientation() == OrientLeftOfCenter)
3308 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3309 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3310 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3312 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3314 // reposition subbranch
3315 lmosel->reposition();
3316 //ensureSelectionVisible();
3318 if (lmo && (lmo!=selection) &&
3319 (typeid(*lmo) == typeid(BranchObj) ||
3320 (typeid(*lmo) == typeid(MapCenterObj) )
3323 if (e->state() & QMouseEvent::ControlButton)
3325 // Special case: CTRL to link below lmo
3326 lmosel->setParObjTmp (lmo,p,+1);
3328 else if (e->state() & QMouseEvent::ShiftButton)
3329 lmosel->setParObjTmp (lmo,p,-1);
3331 lmosel->setParObjTmp (lmo,p,0);
3334 lmosel->unsetParObjTmp();
3335 /* FIXME not needed anymore?
3336 if (lmo &&(lmo==selection))
3337 // Could link to myself (happens sometimes...)
3338 lmosel->unsetParObjTmp();
3340 // no Obj under selection, go back to original Parent
3341 lmosel->unsetParObjTmp();
3346 } // no FloatImageObj
3350 } // selection && moving_obj
3352 // Draw a link from one branch to another
3355 tmpXLink->setEnd (p);
3356 tmpXLink->updateXLink();
3360 if (!movingObj && !pickingColor &&!drawingLink)
3362 QPoint p=e->globalPos();
3363 movingVec.setX(-p.x() + movingObj_start.x() );
3364 movingVec.setY(-p.y() + movingObj_start.y() );
3365 setContentsPos( movingCont_start.x() + movingVec.x(),
3366 movingCont_start.y() + movingVec.y());
3373 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3375 LinkableMapObj *dst;
3376 // Have we been picking color?
3380 setCursor (ArrowCursor);
3381 // Check if we are over another branch
3382 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3383 if (dst && selection)
3385 if (e->state() & QMouseEvent::ShiftButton)
3387 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3388 ((BranchObj*)selection)->setLinkColor ();
3392 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3393 ((BranchObj*)selection)->setLinkColor ();
3399 // Have we been drawing a link?
3403 // Check if we are over another branch
3404 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3405 if (dst && selection)
3407 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3408 tmpXLink->updateXLink();
3409 tmpXLink->activate();
3410 saveState(); //TODO undoCommand
3419 // Have we been moving something?
3420 if ( selection && movingObj )
3422 // Moved FloatObj? Maybe we need to reposition
3423 if(typeid(*selection)==typeid (FloatImageObj))
3425 selection->getParObj()->requestReposition();
3426 mapCenter->reposition();
3429 // Check if we are over another branch, but ignore
3430 // any found LMOs, which are FloatObjs
3431 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3432 ((LinkableMapObj*)selection) );
3435 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3438 // Now check, if we have been moving a branch
3439 if (typeid(*selection) == typeid(BranchObj) )
3441 // save the position in case we link to mapcenter
3442 QPoint savePos=QPoint (selection->x(),selection->y() );
3444 // Reset the temporary drawn link to the original one
3445 ((LinkableMapObj*)selection)->unsetParObjTmp();
3451 BranchObj* bs=((BranchObj*)selection);
3452 QString undoCom="linkBranchToPos (\""+
3453 (bs->getParObj())->getSelectString()+
3455 QString("%1").arg(bs->getNum())+
3457 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3459 // TODO we also could check, if dest and src are on same branch,
3460 // then it would be sufficient to saveState of this branch
3462 // Modifiers allow to insert above/below dst
3463 if (e->state() & QMouseEvent::ShiftButton)
3465 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3467 if (e->state() & QMouseEvent::ControlButton)
3469 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3472 bs->moveBranchTo ((BranchObj*)(dst),-1);
3473 if (dst->getDepth()==0)
3476 saveState (undoCom,bs->getSelectString() );
3478 if (selection->getDepth()==1)
3479 // If we have moved mainbranch only save endposition
3480 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString() );
3482 // Draw the original link, before selection was moved around
3483 mapCenter->reposition();
3485 // Finally resize canvas, if needed
3490 // maybe we moved View: set old cursor
3491 setCursor (ArrowCursor);
3495 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3497 // Finish open lineEdits
3498 if (lineedit) finishedLineEditNoSave();
3500 if (e->button() == QMouseEvent::LeftButton )
3502 QPoint p = inverseWorldMatrix().map(e->pos());
3503 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3504 if (lmo) { // MapObj was found
3505 // First select the MapObj than edit heading
3506 if (selection) selection->unselect();
3508 selection->select();
3509 saveState(selection);
3515 void MapEditor::resizeEvent (QResizeEvent* e)
3517 QCanvasView::resizeEvent( e );
3521 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3524 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3525 // cerr << event->format(i) << endl;
3528 (typeid(*selection) == typeid(BranchObj)) ||
3529 (typeid(*selection) == typeid(MapCenterObj))) {
3531 // If QImageDrag can decode mime type
3532 if (QImageDrag::canDecode(event)) {
3537 // If image are dragged from firefox
3538 if (event->provides("application/x-moz-file-promise-url") &&
3539 event->provides("application/x-moz-nativeimage")) {
3540 event->accept(true);
3544 // If QUriDrag can decode mime type
3545 if (QUriDrag::canDecode(event)) {
3550 // If Uri are dragged from firefox
3551 if (event->provides("_NETSCAPE_URL")){
3556 // If QTextDrag can decode mime type
3557 if (QTextDrag::canDecode(event)) {
3566 bool isUnicode16(const QByteArray &d)
3568 // TODO: make more precise check for unicode 16.
3569 // Guess unicode16 if any of second bytes are zero
3570 unsigned int length = max(0,d.size()-2)/2;
3571 for (unsigned int i = 0; i<length ; i++)
3572 if (d.at(i*2+1)==0) return true;
3576 void MapEditor::contentsDropEvent(QDropEvent *event)
3579 (typeid(*selection) == typeid(BranchObj)) ||
3580 (typeid(*selection) == typeid(MapCenterObj)))
3585 if (event->provides("image/png"))
3588 if (QImageDrag::decode(event, pix))
3596 } else if (event->provides("application/x-moz-file-promise-url") &&
3597 event->provides("application/x-moz-nativeimage"))
3599 // Contains url to the img src in unicode16
3600 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3601 QString url = QString((const QChar*)d.data(),d.size()/2);
3605 } else if (event->provides ("text/uri-list"))
3606 { // Uris provided e.g. by konqueror
3607 QUriDrag::decode (event,uris);
3608 } else if (event->provides ("_NETSCAPE_URL"))
3609 { // Uris provided by Mozilla
3610 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3613 } else if (event->provides("text/html")) {
3615 // Handels text mime types
3616 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3617 QByteArray d = event->encodedData("text/html");
3620 text = QString((const QChar*)d.data(),d.size()/2);
3624 textEditor->setText(text);
3628 } else if (event->provides("text/plain")) {
3629 QByteArray d = event->encodedData("text/plain");
3632 text = QString((const QChar*)d.data(),d.size()/2);
3636 textEditor->setText(text);
3648 for (const char* u=uris.first(); u; u=uris.next())
3650 bo=((BranchObj*)selection)->addBranch();
3653 s=QUriDrag::uriToLocalFile(u);
3655 QString file = QDir::convertSeparators(s);
3656 heading = QFileInfo(file).baseName();
3658 if (file.endsWith(".vym", false))
3659 bo->setVymLink(file);
3668 bo->setHeading(heading);
3678 saveState(); //TODO undo Command
3679 mapCenter->reposition();
3686 void MapEditor::addFloatImage(const QPixmap &img)
3689 (typeid(*selection) == typeid(BranchObj)) ||
3690 (typeid(*selection) == typeid(MapCenterObj)) )
3692 BranchObj *bo=((BranchObj*)selection);
3693 saveState(selection);
3694 //QString fn=fd->selectedFile();
3695 //lastImageDir=fn.left(fn.findRev ("/"));
3696 bo->addFloatImage();
3697 // FIXME check if load was successful
3698 bo->getLastFloatImage()->load(img);
3699 //bo->getLastFloatImage()->setOriginalFilename(fn);
3700 mapCenter->reposition();
3707 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3709 if (!imageBuffer) imageBuffer = new QBuffer();
3710 if (!imageBuffer->isOpen()) {
3711 imageBuffer->open(IO_WriteOnly | IO_Append);
3713 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3717 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3719 if (nop->state()==QNetworkProtocol::StDone) {
3720 QPixmap img(imageBuffer->buffer());
3725 imageBuffer->close();
3727 imageBuffer->close();
3734 void MapEditor::fetchImage(const QString &url)
3737 urlOperator->stop();
3738 disconnect(urlOperator);
3742 urlOperator = new QUrlOperator(url);
3743 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3744 this, SLOT(imageDataFinished(QNetworkOperation*)));
3746 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3747 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));