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 /*! Set or unset temporary hiding of objects during export */
139 void setExportMode (bool);
141 /*! Export as ASCII text to file */
142 void exportASCII (QString fname="",bool askForName=true);
145 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
147 /*! Export as OpenOfficeOrg presentation */
148 void exportOOPresentation(const QString &,const QString &);
150 /*! Export as XHTML to directory */
151 void exportXHTML(const QString& dir="", bool askForName=true);
153 /*! Export as XTML to directory */
154 void exportXML(const QString& dir="");
156 void clear(); //!< Clear map
157 void copy(); //!< Copy to clipboard
158 void redo(); //!< Redo last action
159 bool isRedoAvailable(); //!< True, if redo is available
160 void undo(); //!< Undo last action
161 bool isUndoAvailable(); //!< True, if undo is available
162 void gotoHistoryStep (int); //!< Goto a specifig step in history
164 void addMapReplaceInt(const QString & undoSel, const QString & path);
165 void addMapInsertInt (const QString & path, int pos);
166 void pasteNoSave(const int &n); //!< paste clipboard to branch
168 void paste(); //!< Paste clipboard to branch and backup
169 void cut(); //!< Cut to clipboard (and copy)
170 /*! \brief Move absolutly
172 Move absolutly to (x,y).
174 void move (const int &x, const int &y);
175 /*! \brief Move relativly
177 Move relativly to (x,y).
179 void moveRel (const int &x, const int &y);
180 void moveBranchUp(); //!< Move branch up
181 void moveBranchDown(); //!< Move branch down
183 void linkTo(const QString &);
185 QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
186 void setHeading(const QString &); //!< Set heading of branch
188 void setHeadingInt(const QString &);
189 void setVymLinkInt(const QString &); // Set vymLink for selection
190 /*! \brief Add new branch
192 Depending on num the new branch is created
194 -3 above selection as child of selections parent
195 -2 as child of selection
196 -1 below selection as child of selections parent
197 0..n insert at a specific position in selections parent
198 (needed for free relinking)
200 BranchObj* addNewBranchInt(int); // pos allows to add above/below selection
204 Depending on num the new branch is created
206 0 as child of selection
209 BranchObj* addNewBranch(int pos);
210 BranchObj* addNewBranchBefore(); //!< Insert branch between selection and its parent
211 void deleteSelection(); //!< Delete selection
212 LinkableMapObj* getSelection(); //!< Returns selection
213 BranchObj* getSelectedBranch(); // returns selected branch or NULL
214 FloatImageObj* getSelectedFloatImage(); // returns selected branch or NULL
215 void unselect(); // before changing current noteedit
216 void reselect(); // after changing current noteedit
217 bool select(const QString &); // Select by string
218 QString getSelectString();
220 void selectInt(LinkableMapObj*);
221 void selectNextBranchInt(); // Increment number of branch
222 void selectPrevBranchInt(); // Decrement number of branch
224 void selectUpperBranch();
225 void selectLowerBranch();
226 void selectLeftBranch();
227 void selectRightBranch();
228 void selectFirstBranch();
229 void selectLastBranch();
230 void selectMapBackgroundImage();
231 void setMapBackgroundImage(const QString &);
232 void selectMapBackgroundColor();
233 void setMapBackgroundColor(QColor);
234 QColor getMapBackgroundColor();
235 QColor getCurrentHeadingColor();
236 void colorBranch(QColor);
237 void colorSubtree(QColor);
238 void toggleStandardFlag(QString);
239 BranchObj* findText(QString,bool); // Find object
240 void findReset(); // Reset Find
241 void setURL(const QString &); // set the URL
242 void editURL(); // edit the URL
243 QString getURL(); // returns URL of selection or ""
244 QStringList getURLs(); // returns URLs of subtree
245 void editHeading2URL(); // copy heading to URL
246 void editBugzilla2URL(); // create URL to Bugzilla
247 void editFATE2URL(); // create URL to FATE
248 void editVymLink(); // edit link to another map
249 void deleteVymLink(); // delete link to another map
250 QString getVymLink(); // return path to map
251 QStringList getVymLinks(); // return paths in subtree
252 void setHideExport(bool); // toggle the export flag
253 void toggleHideExport(); // toggle the export flag
254 void deleteKeepChilds(); // remove but keep childs
255 void deleteChilds(); // remove childs
256 void editMapInfo(); // dialog to enter author, ...
257 void ensureSelectionVisible();
258 void updateSelection(); // update geometry of selection
259 void updateActions(); // update e.g. format buttons
260 void updateNoteFlag(); // when TextEditor changes
261 void setMapAuthor (const QString &);
262 void setMapComment(const QString &);
263 void setMapLinkStyle (const QString &); // Set style of link
264 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
265 void setMapDefLinkColor(QColor); // default color of links
266 void setMapLinkColorHintInt(); // color of links
267 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
268 LinkableMapObj::ColorHint getMapLinkColorHint();
269 QColor getMapDefLinkColor();
270 void setMapDefXLinkColor(QColor);
271 QColor getMapDefXLinkColor();
272 void setMapDefXLinkWidth (int);
273 int getMapDefXLinkWidth();
274 void toggleMapLinkColorHint(); // after changing linkStyles
275 void selectMapLinkColor();
276 void selectMapSelectionColor();
278 void setSelectionColorInt(QColor);
280 void setSelectionColor(QColor);
281 QColor getSelectionColor();
282 bool scrollBranch(BranchObj*);
283 bool unscrollBranch(BranchObj*);
285 void unscrollChilds();
287 FloatImageObj* loadFloatImageInt (QString);
289 void loadFloatImage ();
291 void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
293 void saveFloatImage ();
294 void setFrameType(const FrameObj::FrameType &);
295 void setFrameType(const QString &);
296 void setFramePenColor (const QColor &);
297 void setFrameBrushColor (const QColor &);
298 void setFramePadding (const int &);
299 void setFrameBorderWidth (const int &);
300 void setIncludeImagesVer(bool);
301 void setIncludeImagesHor(bool);
302 void setHideLinkUnselected (bool);
303 bool getHideLinkUnselected ();
305 void importDirInt(BranchObj *,QDir);
306 void importDirInt(const QString&);
309 void followXLink (int);
310 void editXLink (int);
311 void testFunction(); // just testing new stuff
312 // set /mainwindo/showTestMenu=true...
315 virtual void contextMenuEvent ( QContextMenuEvent *e );
316 virtual void keyPressEvent(QKeyEvent*);
317 virtual void keyReleaseEvent(QKeyEvent*);
318 virtual void mousePressEvent(QMouseEvent*);
319 virtual void mouseMoveEvent(QMouseEvent*);
320 virtual void mouseReleaseEvent(QMouseEvent*);
321 virtual void mouseDoubleClickEvent(QMouseEvent*);
322 virtual void resizeEvent( QResizeEvent * );
324 void dragEnterEvent (QDragEnterEvent *);
325 void dragMoveEvent (QDragMoveEvent *);
326 void dragLeaveEvent (QDragLeaveEvent *);
327 void dropEvent (QDropEvent *);
329 void timerEvent(QTimerEvent *event);
335 State state; // State of MapEditor
336 QGraphicsScene *mapScene;
337 MapCenterObj* mapCenter;
338 QTimer *autosaveTimer;
340 bool adjustCanvasRequested; // collect requests until end of user event
341 BranchObj *editingBO; // entering Text into BO
343 QColor defLinkColor; // default color for links
344 QColor defXLinkColor; // default color for xlinks
345 int defXLinkWidth; // default width for xlinks
346 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
347 LinkableMapObj::Style linkstyle; // default style for links
349 QCursor HandOpenCursor; // cursor while moving canvas view
350 QCursor PickColorCursor; // cursor while picking color
351 QCursor CopyCursor; // cursor while picking color
352 QCursor XLinkCursor; // cursor while picking color
354 bool drawingLink; // true while creating a link
355 bool copyingObj; // true while creating a link
359 MapObj* movingObj; // moving a MapObj
360 MapObj* linkingObj_src; // part of a link
361 QPointF movingObj_orgPos; // org. pos of mouse before move
362 QPointF movingObj_orgRelPos; // org. relative pos of mouse before move
363 QPointF movingObj_start; // rel. pos of mouse to absPos
364 QPointF movingCont_start; // inital pos of moving Content or
365 QPointF movingVec; // how far has Content moved
366 QPrinter* printer; // Printing
368 bool mapDefault; // Flag if map is untouched
369 bool mapChanged; // Flag if undo is possible
370 bool mapUnsaved; // Flag if map should be saved
372 Parser parser; // Parser stuff for scripting
374 bool printFrame; // Print frame around map
375 bool printFooter; // Print footer below map
377 bool zipped; // should map be zipped
378 static int mapNum; // unique number for Editor
379 QString fileName; // short name of file (for tab)
380 QString filePath; // path to file which will be saved
381 QString fileDir; // dir where file is saved
382 QString destPath; // path to .vym file (needed for vymlinks)
383 QString mapName; // fileName without ".vym"
385 QString tmpMapDir; // tmp directory with undo history
386 QString histPath; // Path to history file
387 SimpleSettings undoSet; // undo/redo commands, saved in histPath
388 int stepsTotal; // total number of steps (undos+redos)
389 int curStep; // Current step in history (ring buffer)
390 int curClipboard; // number of history step, which is the current clipboard
391 int redosAvail; // Available number of redo steps
392 int undosAvail; // Available number of undo steps
393 bool blockReposition; // block while load or undo
394 bool blockSaveState; // block while load or undo
396 BranchObj* itFind; // next object in find process
397 bool EOFind; // true, if search failed
399 QPoint exportOffset; // set before export, used in save
400 BranchObj::HideTmpMode hidemode; // true while exporting to hide some stuff
402 int timerId; // animation timer
403 QList <MapObj*> animObjList;// list with animated objects