4 #include <QGraphicsView>
6 #include "mapcenterobj.h"
10 #include "ornamentedobj.h"
11 #include "selection.h"
15 /*! \brief Main widget in vym to display and edit a map */
17 class MapEditor : public QGraphicsView, public xmlObj {
21 /*! \brief State of the mapeditor
23 While a heading is edited, the state has to change, so
24 that e.g. no other object might get selected. This is done
25 in Main by calling setStateEditHeading
28 Idle, //!< Idle, waiting for user event
29 EditHeading //!< Editing heading (dont't select another branch now)
31 MapEditor(QWidget* parent=0);
33 MapCenterObj* getMapCenter(); //!< Return center of map
34 QGraphicsScene * getScene();
35 State getState(); //!< Return State of MapEditor
36 void setStateEditHeading (bool); //!< If set to true, State will change to EditHeading
37 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
38 bool isSaveStateBlocked(); //!< block while undo/redo or while running scripts
39 void setSaveStateBlocked(bool); //!< block saving the undo/redo state
40 bool isSelectBlocked(); //!< true, if no change of selection is possible, e.g. while editing the heading of abranch
43 /*! \brief Get name of object
45 Returns heading of a branch or name of an object for use in comment
48 QString getName(const LinkableMapObj*); // Get e.g. heading or filename
49 void makeTmpDirs(); // create temporary directories
51 /*! This function saves all information of the map to disc.
52 saveToDir also calls the functions for all BranchObj and other objects in the map.
53 The structure of the map itself is returned as QString and passed back to Main,
54 where saveToDir is called initially
56 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
58 /*! \brief Get directory, where current step in history is save
60 saveState creates a directory for each step in history. This function returns the
61 path of the current directory
63 QString getHistoryDir();
65 /*! \brief Save the current changes in map
67 Two commands and selections are saved:
69 - undocommand and undoselection to undo the change
70 - redocommand and redoselection to redo the action after an undo
72 Additionally a comment is logged.
75 void saveState(const SaveMode& savemode, const QString &undoSelection, const QString &undoCommand, const QString &redoSelection, const QString &redoCommand, const QString &comment, LinkableMapObj *saveSelection);
76 /*! Overloaded for convenience */
77 void saveStateChangingPart(LinkableMapObj *undoSelection, LinkableMapObj* redoSelection, const QString &redoCommand, const QString &comment);
78 /*! Overloaded for convenience */
79 void saveStateRemovingPart(LinkableMapObj *redoSelection, const QString &comment);
80 /*! Overloaded for convenience */
81 void saveState(LinkableMapObj *undoSelection, const QString &undoCommand, LinkableMapObj *redoSelection, const QString &redoCommand, const QString &comment);
82 /*! Overloaded for convenience */
83 void saveState(const QString &undoSelection, const QString &undoCommand, const QString &redoSelection, const QString &redoCommand, const QString &comment) ;
87 /* \brief Process one command and its parameters */
88 void parseAtom (const QString &atom);
90 /* \brief Runs the script */
91 void runScript (QString script);
93 void addFloatImageInt(const QPixmap &img);
96 bool isDefault(); //!< true, if map is still the empty default map
97 bool hasChanged(); //!< true, if something has changed and is not saved yet
98 void setChanged(); //!< called from TextEditor via LinkableMapObj
99 void closeMap(); //!< Closes the map
101 /*! \brief Sets filepath, filename and mapname
103 If the filepath is "/home/tux/map.xml", then the filename will be set
104 to map.xml. The destname is needed for vymLinks, pointing to another map.
105 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
108 /*! \brief Set File path
110 The destname is needed to construct the references between maps
112 void setFilePath (QString filepath,QString destname);
113 void setFilePath (QString); //!< Overloaded for convenience
114 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
115 QString getFileName (); //!< e.g. "map.xml"
116 QString getMapName (); //!< e.g. "map"
117 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
121 The data is read from file. Depending on LoadMode the current
122 selection gets replaced by data or the data is appended.
124 ErrorCode load (QString, LoadMode ); // newmap, import/replace selection
126 /*! \brief Save the map to file */
127 int save(const SaveMode &);
128 void setZipped(bool); //!< Set or unset compression of map with zip save map zipped
129 bool saveZipped(); //!< True, if file will be saved zipped
130 void print(); //!< Print the map
131 void setAntiAlias (bool); //!< Set or unset antialiasing
132 void setSmoothPixmap(bool); //!< Set or unset smoothing of pixmaps
135 void setHideTmpMode (BranchObj::HideTmpMode); // temporary hide stuff
136 BranchObj::HideTmpMode getHideTmpMode(); // temporary hide stuff
138 void setExportMode (bool); //!< Set or unset temporary hiding of objects during export
139 void exportASCII (QString fname="",bool askForName=true); //!< Export as ASCII
142 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
143 void exportOOPresentation(const QString &,const QString &); //!< Export as OpenOfficeOrg presentation
144 void exportXHTML(const QString& dir="");//!< Export as XHTML to directory
145 void exportXML(const QString& dir=""); //!< Export as XML to directory
146 void clear(); //!< Clear map
147 void copy(); //!< Copy to clipboard
148 void redo(); //!< Redo last action
149 bool isRedoAvailable(); //!< True, if redo is available
150 void undo(); //!< Undo last action
151 bool isUndoAvailable(); //!< True, if undo is available
152 void gotoHistoryStep (int); //!< Goto a specifig step in history
154 void addMapReplaceInt(const QString & undoSel, const QString & path);
155 void addMapInsertInt (const QString & path, int pos);
156 void pasteNoSave(const int &n); //!< paste clipboard to branch
158 void paste(); //!< Paste clipboard to branch and backup
159 void cut(); //!< Cut to clipboard (and copy)
160 /*! \brief Move absolutly
162 Move absolutly to (x,y).
164 void move (const int &x, const int &y);
165 /*! \brief Move relativly
167 Move relativly to (x,y).
169 void moveRel (const int &x, const int &y);
170 void moveBranchUp(); //!< Move branch up
171 void moveBranchDown(); //!< Move branch down
173 void linkTo(const QString &);
175 QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
176 void setHeading(const QString &); //!< Set heading of branch
178 void setHeadingInt(const QString &);
179 void setVymLinkInt(const QString &); // Set vymLink for selection
180 /*! \brief Add new branch
182 Depending on num the new branch is created
184 -3 above selection as child of selections parent
185 -2 as child of selection
186 -1 below selection as child of selections parent
187 0..n insert at a specific position in selections parent
188 (needed for free relinking)
190 BranchObj* addNewBranchInt(int); // pos allows to add above/below selection
194 Depending on num the new branch is created
196 0 as child of selection
199 BranchObj* addNewBranch(int pos);
200 BranchObj* addNewBranchBefore(); //!< Insert branch between selection and its parent
201 void deleteSelection(); //!< Delete selection
202 LinkableMapObj* getSelection(); //!< Returns selection
203 BranchObj* getSelectedBranch(); // returns selected branch or NULL
204 FloatImageObj* getSelectedFloatImage(); // returns selected branch or NULL
205 void unselect(); // before changing current noteedit
206 void reselect(); // after changing current noteedit
207 bool select(const QString &); // Select by string
208 QString getSelectString();
210 void selectInt(LinkableMapObj*);
211 void selectNextBranchInt(); // Increment number of branch
212 void selectPrevBranchInt(); // Decrement number of branch
214 void selectUpperBranch();
215 void selectLowerBranch();
216 void selectLeftBranch();
217 void selectRightBranch();
218 void selectFirstBranch();
219 void selectLastBranch();
220 void selectMapBackgroundImage();
221 void setMapBackgroundImage(const QString &);
222 void selectMapBackgroundColor();
223 void setMapBackgroundColor(QColor);
224 QColor getMapBackgroundColor();
225 QColor getCurrentHeadingColor();
226 void colorBranch(QColor);
227 void colorSubtree(QColor);
228 void toggleStandardFlag(QString);
229 BranchObj* findText(QString,bool); // Find object
230 void findReset(); // Reset Find
231 void setURL(const QString &); // set the URL
232 void editURL(); // edit the URL
233 QString getURL(); // returns URL of selection or ""
234 QStringList getURLs(); // returns URLs of subtree
235 void editHeading2URL(); // copy heading to URL
236 void editBugzilla2URL(); // create URL to Bugzilla
237 void editFATE2URL(); // create URL to FATE
238 void editVymLink(); // edit link to another map
239 void deleteVymLink(); // delete link to another map
240 QString getVymLink(); // return path to map
241 QStringList getVymLinks(); // return paths in subtree
242 void setHideExport(bool); // toggle the export flag
243 void toggleHideExport(); // toggle the export flag
244 void deleteKeepChilds(); // remove but keep childs
245 void deleteChilds(); // remove childs
246 void editMapInfo(); // dialog to enter author, ...
247 void ensureSelectionVisible();
248 void updateSelection(); // update geometry of selection
249 void updateActions(); // update e.g. format buttons
250 void updateNoteFlag(); // when TextEditor changes
251 void setMapAuthor (const QString &);
252 void setMapComment(const QString &);
253 void setMapLinkStyle (const QString &); // Set style of link
254 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
255 void setMapDefLinkColor(QColor); // default color of links
256 void setMapLinkColorHintInt(); // color of links
257 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
258 LinkableMapObj::ColorHint getMapLinkColorHint();
259 QColor getMapDefLinkColor();
260 void setMapDefXLinkColor(QColor);
261 QColor getMapDefXLinkColor();
262 void setMapDefXLinkWidth (int);
263 int getMapDefXLinkWidth();
264 void toggleMapLinkColorHint(); // after changing linkStyles
265 void selectMapLinkColor();
266 void selectMapSelectionColor();
268 void setSelectionColorInt(QColor);
270 void setSelectionColor(QColor);
271 QColor getSelectionColor();
272 bool scrollBranch(BranchObj*);
273 bool unscrollBranch(BranchObj*);
275 void unscrollChilds();
277 FloatImageObj* loadFloatImageInt (QString);
279 void loadFloatImage ();
281 void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
283 void saveFloatImage ();
284 void setFrameType(const FrameObj::FrameType &);
285 void setFrameType(const QString &);
286 void setFramePenColor (const QColor &);
287 void setFrameBrushColor (const QColor &);
288 void setFramePadding (const int &);
289 void setFrameBorderWidth (const int &);
290 void setIncludeImagesVer(bool);
291 void setIncludeImagesHor(bool);
292 void setHideLinkUnselected (bool);
293 bool getHideLinkUnselected ();
295 void importDirInt(BranchObj *,QDir);
296 void importDirInt(const QString&);
299 void followXLink (int);
300 void editXLink (int);
301 void testFunction(); // just testing new stuff
302 // set /mainwindo/showTestMenu=true...
305 virtual void contextMenuEvent ( QContextMenuEvent *e );
306 virtual void keyPressEvent(QKeyEvent*);
307 virtual void keyReleaseEvent(QKeyEvent*);
308 virtual void mousePressEvent(QMouseEvent*);
309 virtual void mouseMoveEvent(QMouseEvent*);
310 virtual void mouseReleaseEvent(QMouseEvent*);
311 virtual void mouseDoubleClickEvent(QMouseEvent*);
312 virtual void resizeEvent( QResizeEvent * );
314 void dragEnterEvent (QDragEnterEvent *);
315 void dragMoveEvent (QDragMoveEvent *);
316 void dragLeaveEvent (QDragLeaveEvent *);
317 void dropEvent (QDropEvent *);
319 void timerEvent(QTimerEvent *event);
325 State state; // State of MapEditor
326 QGraphicsScene *mapScene;
327 MapCenterObj* mapCenter;
328 QTimer *autosaveTimer;
330 bool adjustCanvasRequested; // collect requests until end of user event
331 BranchObj *editingBO; // entering Text into BO
333 QColor defLinkColor; // default color for links
334 QColor defXLinkColor; // default color for xlinks
335 int defXLinkWidth; // default width for xlinks
336 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
337 LinkableMapObj::Style linkstyle; // default style for links
339 QCursor HandOpenCursor; // cursor while moving canvas view
340 QCursor PickColorCursor; // cursor while picking color
341 QCursor CopyCursor; // cursor while picking color
342 QCursor XLinkCursor; // cursor while picking color
344 bool drawingLink; // true while creating a link
345 bool copyingObj; // true while creating a link
349 MapObj* movingObj; // moving a MapObj
350 MapObj* linkingObj_src; // part of a link
351 QPointF movingObj_orgPos; // org. pos of mouse before move
352 QPointF movingObj_orgRelPos; // org. relative pos of mouse before move
353 QPointF movingObj_start; // rel. pos of mouse to absPos
354 QPointF movingCont_start; // inital pos of moving Content or
355 QPointF movingVec; // how far has Content moved
356 QPrinter* printer; // Printing
358 bool mapDefault; // Flag if map is untouched
359 bool mapChanged; // Flag if undo is possible
360 bool mapUnsaved; // Flag if map should be saved
362 Parser parser; // Parser stuff for scripting
364 bool printFrame; // Print frame around map
365 bool printFooter; // Print footer below map
367 bool zipped; // should map be zipped
368 static int mapNum; // unique number for Editor
369 QString fileName; // short name of file (for tab)
370 QString filePath; // path to file which will be saved
371 QString fileDir; // dir where file is saved
372 QString destPath; // path to .vym file (needed for vymlinks)
373 QString mapName; // fileName without ".vym"
375 QString tmpMapDir; // tmp directory with undo history
376 QString histPath; // Path to history file
377 SimpleSettings undoSet; // undo/redo commands, saved in histPath
378 int stepsTotal; // total number of steps (undos+redos)
379 int curStep; // Current step in history (ring buffer)
380 int curClipboard; // number of history step, which is the current clipboard
381 int redosAvail; // Available number of redo steps
382 int undosAvail; // Available number of undo steps
383 bool blockReposition; // block while load or undo
384 bool blockSaveState; // block while load or undo
386 BranchObj* itFind; // next object in find process
387 bool EOFind; // true, if search failed
389 QPoint exportOffset; // set before export, used in save
390 BranchObj::HideTmpMode hidemode; // true while exporting to hide some stuff
392 int timerId; // animation timer
393 QList <MapObj*> animObjList;// list with animated objects