4 #include <QGraphicsView>
11 #include "ornamentedobj.h"
12 #include "selection.h"
19 /*! \brief Main widget in vym to display and edit a map */
21 class MapEditor : public QGraphicsView, public XMLObj {
25 /*! \brief State of the mapeditor
27 While a heading is edited, the state has to change, so
28 that e.g. no other object might get selected. This is done
29 in Main by calling setStateEditHeading
32 Idle, //!< Idle, waiting for user event
33 EditHeading //!< Editing heading (dont't select another branch now)
35 /*! \brief Networking states
37 In Network modus we want to switch of saveState, autosave, ...
41 Client, //!< I am the client and connected to server
42 Server //!< I am the server
44 MapEditor(QWidget* parent=0);
47 QGraphicsScene * getScene();
48 State getState(); //!< Return State of MapEditor
49 void setStateEditHeading (bool); //!< If set to true, State will change to EditHeading
50 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
51 bool isSaveStateBlocked(); //!< block while undo/redo or while running scripts
52 void setSaveStateBlocked(bool); //!< block saving the undo/redo state
53 bool isSelectBlocked(); //!< true, if no change of selection is possible, e.g. while editing the heading of abranch
56 /*! \brief Get name of object
58 Returns heading of a branch or name of an object for use in comment
61 QString getName(const LinkableMapObj*); // Get e.g. heading or filename
62 void makeTmpDirs(); // create temporary directories
64 /*! This function saves all information of the map to disc.
65 saveToDir also calls the functions for all BranchObj and other objects in the map.
66 The structure of the map itself is returned as QString and passed back to Main,
67 where saveToDir is called initially
69 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
71 /*! \brief Get directory, where current step in history is save
73 saveState creates a directory for each step in history. This function returns the
74 path of the current directory
76 QString getHistoryDir();
78 /*! \brief Save the current changes in map
80 Two commands and selections are saved:
82 - undocommand and undoselection to undo the change
83 - redocommand and redoselection to redo the action after an undo
85 Additionally a comment is logged.
89 const SaveMode& savemode,
90 const QString &undoSelection,
91 const QString &undoCommand,
92 const QString &redoSelection,
93 const QString &redoCommand,
94 const QString &comment,
95 LinkableMapObj *saveSelection);
96 /*! Overloaded for convenience */
97 void saveStateChangingPart(
98 LinkableMapObj *undoSelection,
99 LinkableMapObj* redoSelection,
100 const QString &redoCommand,
101 const QString &comment);
102 /*! Overloaded for convenience */
103 void saveStateRemovingPart(
104 LinkableMapObj *redoSelection,
105 const QString &comment);
106 /*! Overloaded for convenience */
108 LinkableMapObj *undoSelection,
109 const QString &undoCommand,
110 LinkableMapObj *redoSelection,
111 const QString &redoCommand,
112 const QString &comment);
113 /*! Overloaded for convenience */
115 const QString &undoSelection,
116 const QString &undoCommand,
117 const QString &redoSelection,
118 const QString &redoCommand,
119 const QString &comment) ;
121 const QString &undoCommand,
122 const QString &redoCommand,
123 const QString &comment) ;
127 /* \brief Process one command and its parameters */
128 void parseAtom (const QString &atom);
130 /* \brief Runs the script */
131 void runScript (QString script);
133 void addFloatImageInt(const QPixmap &img);
136 bool isDefault(); //!< true, if map is still the empty default map
137 bool hasChanged(); //!< true, if something has changed and is not saved yet
138 void setChanged(); //!< called from TextEditor via LinkableMapObj
139 void closeMap(); //!< Closes the map
141 /*! \brief Sets filepath, filename and mapname
143 If the filepath is "/home/tux/map.xml", then the filename will be set
144 to map.xml. The destname is needed for vymLinks, pointing to another map.
145 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
148 /*! \brief Set File path
150 The destname is needed to construct the references between maps
152 void setFilePath (QString filepath,QString destname);
153 void setFilePath (QString); //!< Overloaded for convenience
154 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
155 QString getFileName (); //!< e.g. "map.xml"
156 QString getMapName (); //!< e.g. "map"
157 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
161 The data is read from file. Depending on LoadMode the current
162 selection gets replaced by data or the data is appended.
164 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
166 /*! \brief Save the map to file */
167 ErrorCode save(const SaveMode &);
168 /* FIXME no needed any longer
169 void setZipped(bool); //!< Set or unset compression of map with zip save map zipped
170 bool saveZipped(); //!< True, if file will be saved zipped
172 void print(); //!< Print the map
173 void setAntiAlias (bool); //!< Set or unset antialiasing
174 void setSmoothPixmap(bool); //!< Set or unset smoothing of pixmaps
177 void setHideTmpMode (HideTmpMode); // temporary hide stuff
178 HideTmpMode getHideTmpMode(); // temporary hide stuff
180 /*! Set or unset temporary hiding of objects during export */
181 void setExportMode (bool);
183 /*! Export as ASCII text to file */
184 void exportASCII (QString fname="",bool askForName=true);
187 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
189 /*! Export as OpenOfficeOrg presentation */
190 void exportOOPresentation(const QString &,const QString &);
192 /*! Export as XHTML to directory */
193 void exportXHTML(const QString& dir="", bool askForName=true);
195 /*! Export as XTML to directory */
196 void exportXML(QString dir="", bool askForName=true);
198 void clear(); //!< Clear map
199 void copy(); //!< Copy to clipboard
200 void redo(); //!< Redo last action
201 bool isRedoAvailable(); //!< True, if redo is available
202 void undo(); //!< Undo last action
203 bool isUndoAvailable(); //!< True, if undo is available
204 void gotoHistoryStep (int); //!< Goto a specifig step in history
206 void addMapReplaceInt(const QString & undoSel, const QString & path);
207 bool addMapInsertInt (const QString & path);
208 bool addMapInsertInt (const QString & path, int pos);
209 void pasteNoSave(const int &n); //!< paste clipboard to branch
211 void paste(); //!< Paste clipboard to branch and backup
212 void cut(); //!< Cut to clipboard (and copy)
213 /*! \brief Move absolutly
215 Move absolutly to (x,y).
217 void move (const double &x, const double &y);
218 /*! \brief Move relativly
220 Move relativly to (x,y).
222 void moveRel (const double &x, const double &y);
223 void moveBranchUp(); //!< Move branch up
224 void moveBranchDown(); //!< Move branch down
225 void sortChildren(); //!< Sort children lexically
227 void linkTo(const QString &);
229 QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
230 void setHeading(const QString &); //!< Set heading of branch
232 void setHeadingInt(const QString &);
233 void setVymLinkInt(const QString &); // Set vymLink for selection
234 /*! \brief Add new mapcenter
236 Disclaimer: Still experimental, not fully supported.
239 BranchObj* addMapCenter();
241 /*! \brief Add new branch
243 Depending on num the new branch is created
245 -3 above selection as child of selections parent
246 -2 as child of selection
247 -1 below selection as child of selections parent
248 0..n insert at a specific position in selections parent
249 (needed for free relinking)
252 BranchObj* addNewBranchInt(int); // pos allows to add above/below selection
256 Depending on num the new branch is created
258 0 as child of selection
261 BranchObj* addNewBranch(int pos);
262 BranchObj* addNewBranchBefore(); //!< Insert branch between selection and its parent
263 void deleteSelection(); //!< Delete selection
264 LinkableMapObj* getSelection(); //!< Returns selection
265 BranchObj* getSelectedBranch(); // returns selected branch or NULL
266 FloatImageObj* getSelectedFloatImage(); // returns selected branch or NULL
267 void unselect(); // before changing current noteedit
268 void reselect(); // after changing current noteedit
269 bool select(const QString &); // Select by string
270 bool select(LinkableMapObj *lmo); // Select by pointer
271 QString getSelectString();
273 void selectInt(LinkableMapObj*);
274 void selectNextBranchInt(); // Increment number of branch
275 void selectPrevBranchInt(); // Decrement number of branch
277 void selectUpperBranch();
278 void selectLowerBranch();
279 void selectLeftBranch();
280 void selectRightBranch();
281 void selectFirstBranch();
282 void selectLastBranch();
283 void selectMapBackgroundImage();
284 void setMapBackgroundImage(const QString &);
285 void selectMapBackgroundColor();
286 void setMapBackgroundColor(QColor);
287 QColor getMapBackgroundColor();
288 QColor getCurrentHeadingColor();
289 void colorBranch(QColor);
290 void colorSubtree(QColor);
291 void toggleStandardFlag(QString);
292 BranchObj* findText(QString,bool); // Find object
293 void findReset(); // Reset Find
294 void setURL(const QString &); // set URL
295 void editURL(); // edit URL
296 void editLocalURL(); // edit URL to local file
297 QString getURL(); // returns URL of selection or ""
298 QStringList getURLs(); // returns URLs of subtree
299 void editHeading2URL(); // copy heading to URL
300 void editBugzilla2URL(); // create URL to Bugzilla
301 void editFATE2URL(); // create URL to FATE
302 void editVymLink(); // edit link to another map
303 void deleteVymLink(); // delete link to another map
304 QString getVymLink(); // return path to map
305 QStringList getVymLinks(); // return paths in subtree
306 void setHideExport(bool); // toggle the export flag
307 void toggleHideExport(); // toggle the export flag
308 void deleteKeepChilds(); // remove but keep childs
309 void deleteChilds(); // remove childs
310 void editMapInfo(); // dialog to enter author, ...
311 void ensureSelectionVisible();
312 void updateSelection(); // update geometry of selection
313 void updateActions(); // update e.g. format buttons
314 void updateNoteFlag(); // when TextEditor changes
315 void setMapAuthor (const QString &);
316 void setMapComment(const QString &);
317 void setMapLinkStyle (const QString &); // Set style of link
318 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
319 void setMapDefLinkColor(QColor); // default color of links
320 void setMapLinkColorHintInt(); // color of links
321 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
322 LinkableMapObj::ColorHint getMapLinkColorHint();
323 QColor getMapDefLinkColor();
324 void setMapDefXLinkColor(QColor);
325 QColor getMapDefXLinkColor();
326 void setMapDefXLinkWidth (int);
327 int getMapDefXLinkWidth();
328 void toggleMapLinkColorHint(); // after changing linkStyles
329 void selectMapLinkColor();
330 void selectMapSelectionColor();
332 void setSelectionColorInt(QColor);
334 void setSelectionColor(QColor);
335 QColor getSelectionColor();
336 bool scrollBranch(BranchObj*);
337 bool unscrollBranch(BranchObj*);
339 void unscrollChilds();
341 FloatImageObj* loadFloatImageInt (QString);
343 void loadFloatImage ();
345 void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
347 void saveFloatImage ();
348 void setFrameType(const FrameObj::FrameType &);
349 void setFrameType(const QString &);
350 void setFramePenColor (const QColor &);
351 void setFrameBrushColor (const QColor &);
352 void setFramePadding (const int &);
353 void setFrameBorderWidth (const int &);
354 void setIncludeImagesVer(bool);
355 void setIncludeImagesHor(bool);
356 void setHideLinkUnselected (bool);
357 bool getHideLinkUnselected ();
359 void importDirInt(BranchObj *,QDir);
360 void importDirInt(const QString&);
363 void followXLink (int);
364 void editXLink (int);
365 AttributeTable* attributeTable();
366 void testFunction1(); // just testing new stuff
367 void testFunction2(); // just testing new stuff
368 // set /mainwindo/showTestMenu=true...
371 virtual void contextMenuEvent ( QContextMenuEvent *e );
372 virtual void keyPressEvent(QKeyEvent*);
373 virtual void keyReleaseEvent(QKeyEvent*);
374 virtual void mousePressEvent(QMouseEvent*);
375 virtual void mouseMoveEvent(QMouseEvent*);
376 virtual void mouseReleaseEvent(QMouseEvent*);
377 virtual void mouseDoubleClickEvent(QMouseEvent*);
378 virtual void resizeEvent( QResizeEvent * );
380 void dragEnterEvent (QDragEnterEvent *);
381 void dragMoveEvent (QDragMoveEvent *);
382 void dragLeaveEvent (QDragLeaveEvent *);
383 void dropEvent (QDropEvent *);
387 void sendSelection();
391 void connectToServer();
395 void sendData(const QString &s);
397 void displayNetworkError (QAbstractSocket::SocketError);
403 State state; // State of MapEditor
404 QGraphicsScene *mapScene;
405 VymModel *model; // Vym Map, includding several mapCenters
406 QTimer *autosaveTimer;
407 QTimer *fileChangedTimer;
408 QDateTime fileChangedTime;
410 bool adjustCanvasRequested; // collect requests until end of user event
411 BranchObj *editingBO; // entering Text into BO
413 QColor defLinkColor; // default color for links
414 QColor defXLinkColor; // default color for xlinks
415 int defXLinkWidth; // default width for xlinks
416 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
417 LinkableMapObj::Style linkstyle; // default style for links
419 QCursor HandOpenCursor; // cursor while moving canvas view
420 QCursor PickColorCursor; // cursor while picking color
421 QCursor CopyCursor; // cursor while picking color
422 QCursor XLinkCursor; // cursor while picking color
424 bool drawingLink; // true while creating a link
425 bool copyingObj; // true while creating a link
430 QString latestSelection; // select string of latest added object
432 MapObj* movingObj; // moving a MapObj
433 MapObj* linkingObj_src; // part of a link
434 QPointF movingObj_orgPos; // org. pos of mouse before move
435 QPointF movingObj_orgRelPos; // org. relative pos of mouse before move
436 QPointF movingObj_start; // rel. pos of mouse to absPos
437 QPointF movingCont_start; // inital pos of moving Content or
438 QPointF movingVec; // how far has Content moved
440 QPointF contextMenuPos; // position where context event was triggered
442 QPrinter* printer; // Printing
444 bool mapDefault; // Flag if map is untouched
445 bool mapChanged; // Flag if undo is possible
446 bool mapUnsaved; // Flag if map should be saved
448 Parser parser; // Parser stuff for scripting
450 AttributeTable *attrTable;
452 bool printFrame; // Print frame around map
453 bool printFooter; // Print footer below map
455 bool zipped; // should map be zipped
456 static int mapNum; // unique number for Editor
457 FileType fileType; // type of file, e.g. vym, freemind...
458 QString fileName; // short name of file (for tab)
459 QString filePath; // path to file which will be saved
460 QString fileDir; // dir where file is saved
461 QString destPath; // path to .vym file (needed for vymlinks)
462 QString mapName; // fileName without ".vym"
464 QString tmpMapDir; // tmp directory with undo history
465 QString histPath; // Path to history file
466 SimpleSettings undoSet; // undo/redo commands, saved in histPath
467 int stepsTotal; // total number of steps (undos+redos)
468 int curStep; // Current step in history (ring buffer)
469 int curClipboard; // number of history step, which is the current clipboard
470 int redosAvail; // Available number of redo steps
471 int undosAvail; // Available number of undo steps
472 bool blockReposition; // block while load or undo
473 bool blockSaveState; // block while load or undo
475 BranchObj* itFind; // next object in find process
476 bool EOFind; // true, if search failed
478 QPoint exportOffset; // set before export, used in save
479 HideTmpMode hidemode; // true while exporting to hide some stuff
481 // Network connections **Experimental**
482 NetState netstate; // offline, client, server
483 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
484 QList <QTcpSocket*> clientList; // List of connected clients
485 quint16 sendCounter; // Increased with every sent command
487 QTcpSocket *clientSocket; // socket of this client
488 QString server; // server address of this client
489 int port; // server port of this client
490 void displayClientError(QAbstractSocket::SocketError socketError);