4 #include <QGraphicsView>
7 #include "mapcenterobj.h"
11 #include "ornamentedobj.h"
12 #include "selection.h"
16 /*! \brief Main widget in vym to display and edit a map */
18 class MapEditor : public QGraphicsView, public xmlObj {
22 /*! \brief State of the mapeditor
24 While a heading is edited, the state has to change, so
25 that e.g. no other object might get selected. This is done
26 in Main by calling setStateEditHeading
29 Idle, //!< Idle, waiting for user event
30 EditHeading //!< Editing heading (dont't select another branch now)
32 /*! \brief Networking states
34 In Network modus we want to switch of saveState, autosave, ...
38 Client, //!< I am the client and connected to server
39 Server //!< I am the server
41 MapEditor(QWidget* parent=0);
43 MapCenterObj* getMapCenter(); //!< Return center of map
44 QGraphicsScene * getScene();
45 State getState(); //!< Return State of MapEditor
46 void setStateEditHeading (bool); //!< If set to true, State will change to EditHeading
47 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
48 bool isSaveStateBlocked(); //!< block while undo/redo or while running scripts
49 void setSaveStateBlocked(bool); //!< block saving the undo/redo state
50 bool isSelectBlocked(); //!< true, if no change of selection is possible, e.g. while editing the heading of abranch
53 /*! \brief Get name of object
55 Returns heading of a branch or name of an object for use in comment
58 QString getName(const LinkableMapObj*); // Get e.g. heading or filename
59 void makeTmpDirs(); // create temporary directories
61 /*! This function saves all information of the map to disc.
62 saveToDir also calls the functions for all BranchObj and other objects in the map.
63 The structure of the map itself is returned as QString and passed back to Main,
64 where saveToDir is called initially
66 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
68 /*! \brief Get directory, where current step in history is save
70 saveState creates a directory for each step in history. This function returns the
71 path of the current directory
73 QString getHistoryDir();
75 /*! \brief Save the current changes in map
77 Two commands and selections are saved:
79 - undocommand and undoselection to undo the change
80 - redocommand and redoselection to redo the action after an undo
82 Additionally a comment is logged.
85 void saveState(const SaveMode& savemode, const QString &undoSelection, const QString &undoCommand, const QString &redoSelection, const QString &redoCommand, const QString &comment, LinkableMapObj *saveSelection);
86 /*! Overloaded for convenience */
87 void saveStateChangingPart(LinkableMapObj *undoSelection, LinkableMapObj* redoSelection, const QString &redoCommand, const QString &comment);
88 /*! Overloaded for convenience */
89 void saveStateRemovingPart(LinkableMapObj *redoSelection, const QString &comment);
90 /*! Overloaded for convenience */
91 void saveState(LinkableMapObj *undoSelection, const QString &undoCommand, LinkableMapObj *redoSelection, const QString &redoCommand, const QString &comment);
92 /*! Overloaded for convenience */
93 void saveState(const QString &undoSelection, const QString &undoCommand, const QString &redoSelection, const QString &redoCommand, const QString &comment) ;
97 /* \brief Process one command and its parameters */
98 void parseAtom (const QString &atom);
100 /* \brief Runs the script */
101 void runScript (QString script);
103 void addFloatImageInt(const QPixmap &img);
106 bool isDefault(); //!< true, if map is still the empty default map
107 bool hasChanged(); //!< true, if something has changed and is not saved yet
108 void setChanged(); //!< called from TextEditor via LinkableMapObj
109 void closeMap(); //!< Closes the map
111 /*! \brief Sets filepath, filename and mapname
113 If the filepath is "/home/tux/map.xml", then the filename will be set
114 to map.xml. The destname is needed for vymLinks, pointing to another map.
115 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
118 /*! \brief Set File path
120 The destname is needed to construct the references between maps
122 void setFilePath (QString filepath,QString destname);
123 void setFilePath (QString); //!< Overloaded for convenience
124 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
125 QString getFileName (); //!< e.g. "map.xml"
126 QString getMapName (); //!< e.g. "map"
127 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
131 The data is read from file. Depending on LoadMode the current
132 selection gets replaced by data or the data is appended.
134 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
136 /*! \brief Save the map to file */
137 int save(const SaveMode &);
138 void setZipped(bool); //!< Set or unset compression of map with zip save map zipped
139 bool saveZipped(); //!< True, if file will be saved zipped
140 void print(); //!< Print the map
141 void setAntiAlias (bool); //!< Set or unset antialiasing
142 void setSmoothPixmap(bool); //!< Set or unset smoothing of pixmaps
145 void setHideTmpMode (BranchObj::HideTmpMode); // temporary hide stuff
146 BranchObj::HideTmpMode getHideTmpMode(); // temporary hide stuff
148 /*! Set or unset temporary hiding of objects during export */
149 void setExportMode (bool);
151 /*! Export as ASCII text to file */
152 void exportASCII (QString fname="",bool askForName=true);
155 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
157 /*! Export as OpenOfficeOrg presentation */
158 void exportOOPresentation(const QString &,const QString &);
160 /*! Export as XHTML to directory */
161 void exportXHTML(const QString& dir="", bool askForName=true);
163 /*! Export as XTML to directory */
164 void exportXML(QString dir="", bool askForName=true);
166 void clear(); //!< Clear map
167 void copy(); //!< Copy to clipboard
168 void redo(); //!< Redo last action
169 bool isRedoAvailable(); //!< True, if redo is available
170 void undo(); //!< Undo last action
171 bool isUndoAvailable(); //!< True, if undo is available
172 void gotoHistoryStep (int); //!< Goto a specifig step in history
174 void addMapReplaceInt(const QString & undoSel, const QString & path);
175 void addMapInsertInt (const QString & path, int pos);
176 void pasteNoSave(const int &n); //!< paste clipboard to branch
178 void paste(); //!< Paste clipboard to branch and backup
179 void cut(); //!< Cut to clipboard (and copy)
180 /*! \brief Move absolutly
182 Move absolutly to (x,y).
184 void move (const double &x, const double &y);
185 /*! \brief Move relativly
187 Move relativly to (x,y).
189 void moveRel (const double &x, const double &y);
190 void moveBranchUp(); //!< Move branch up
191 void moveBranchDown(); //!< Move branch down
192 void sortChildren(); //!< Sort children lexically
194 void linkTo(const QString &);
196 QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
197 void setHeading(const QString &); //!< Set heading of branch
199 void setHeadingInt(const QString &);
200 void setVymLinkInt(const QString &); // Set vymLink for selection
201 /*! \brief Add new branch
203 Depending on num the new branch is created
205 -3 above selection as child of selections parent
206 -2 as child of selection
207 -1 below selection as child of selections parent
208 0..n insert at a specific position in selections parent
209 (needed for free relinking)
211 BranchObj* addNewBranchInt(int); // pos allows to add above/below selection
215 Depending on num the new branch is created
217 0 as child of selection
220 BranchObj* addNewBranch(int pos);
221 BranchObj* addNewBranchBefore(); //!< Insert branch between selection and its parent
222 void deleteSelection(); //!< Delete selection
223 LinkableMapObj* getSelection(); //!< Returns selection
224 BranchObj* getSelectedBranch(); // returns selected branch or NULL
225 FloatImageObj* getSelectedFloatImage(); // returns selected branch or NULL
226 void unselect(); // before changing current noteedit
227 void reselect(); // after changing current noteedit
228 bool select(const QString &); // Select by string
229 QString getSelectString();
231 void selectInt(LinkableMapObj*);
232 void selectNextBranchInt(); // Increment number of branch
233 void selectPrevBranchInt(); // Decrement number of branch
235 void selectUpperBranch();
236 void selectLowerBranch();
237 void selectLeftBranch();
238 void selectRightBranch();
239 void selectFirstBranch();
240 void selectLastBranch();
241 void selectMapBackgroundImage();
242 void setMapBackgroundImage(const QString &);
243 void selectMapBackgroundColor();
244 void setMapBackgroundColor(QColor);
245 QColor getMapBackgroundColor();
246 QColor getCurrentHeadingColor();
247 void colorBranch(QColor);
248 void colorSubtree(QColor);
249 void toggleStandardFlag(QString);
250 BranchObj* findText(QString,bool); // Find object
251 void findReset(); // Reset Find
252 void setURL(const QString &); // set URL
253 void editURL(); // edit URL
254 void editLocalURL(); // edit URL to local file
255 QString getURL(); // returns URL of selection or ""
256 QStringList getURLs(); // returns URLs of subtree
257 void editHeading2URL(); // copy heading to URL
258 void editBugzilla2URL(); // create URL to Bugzilla
259 void editFATE2URL(); // create URL to FATE
260 void editVymLink(); // edit link to another map
261 void deleteVymLink(); // delete link to another map
262 QString getVymLink(); // return path to map
263 QStringList getVymLinks(); // return paths in subtree
264 void setHideExport(bool); // toggle the export flag
265 void toggleHideExport(); // toggle the export flag
266 void deleteKeepChilds(); // remove but keep childs
267 void deleteChilds(); // remove childs
268 void editMapInfo(); // dialog to enter author, ...
269 void ensureSelectionVisible();
270 void updateSelection(); // update geometry of selection
271 void updateActions(); // update e.g. format buttons
272 void updateNoteFlag(); // when TextEditor changes
273 void setMapAuthor (const QString &);
274 void setMapComment(const QString &);
275 void setMapLinkStyle (const QString &); // Set style of link
276 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
277 void setMapDefLinkColor(QColor); // default color of links
278 void setMapLinkColorHintInt(); // color of links
279 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
280 LinkableMapObj::ColorHint getMapLinkColorHint();
281 QColor getMapDefLinkColor();
282 void setMapDefXLinkColor(QColor);
283 QColor getMapDefXLinkColor();
284 void setMapDefXLinkWidth (int);
285 int getMapDefXLinkWidth();
286 void toggleMapLinkColorHint(); // after changing linkStyles
287 void selectMapLinkColor();
288 void selectMapSelectionColor();
290 void setSelectionColorInt(QColor);
292 void setSelectionColor(QColor);
293 QColor getSelectionColor();
294 bool scrollBranch(BranchObj*);
295 bool unscrollBranch(BranchObj*);
297 void unscrollChilds();
299 FloatImageObj* loadFloatImageInt (QString);
301 void loadFloatImage ();
303 void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
305 void saveFloatImage ();
306 void setFrameType(const FrameObj::FrameType &);
307 void setFrameType(const QString &);
308 void setFramePenColor (const QColor &);
309 void setFrameBrushColor (const QColor &);
310 void setFramePadding (const int &);
311 void setFrameBorderWidth (const int &);
312 void setIncludeImagesVer(bool);
313 void setIncludeImagesHor(bool);
314 void setHideLinkUnselected (bool);
315 bool getHideLinkUnselected ();
317 void importDirInt(BranchObj *,QDir);
318 void importDirInt(const QString&);
321 void followXLink (int);
322 void editXLink (int);
323 void testFunction1(); // just testing new stuff
324 void testFunction2(); // just testing new stuff
325 // set /mainwindo/showTestMenu=true...
328 virtual void contextMenuEvent ( QContextMenuEvent *e );
329 virtual void keyPressEvent(QKeyEvent*);
330 virtual void keyReleaseEvent(QKeyEvent*);
331 virtual void mousePressEvent(QMouseEvent*);
332 virtual void mouseMoveEvent(QMouseEvent*);
333 virtual void mouseReleaseEvent(QMouseEvent*);
334 virtual void mouseDoubleClickEvent(QMouseEvent*);
335 virtual void resizeEvent( QResizeEvent * );
337 void dragEnterEvent (QDragEnterEvent *);
338 void dragMoveEvent (QDragMoveEvent *);
339 void dragLeaveEvent (QDragLeaveEvent *);
340 void dropEvent (QDropEvent *);
342 void timerEvent(QTimerEvent *event);
345 void sendSelection();
349 void connectToServer();
353 void sendData(const QString &s);
355 void displayNetworkError (QAbstractSocket::SocketError);
360 State state; // State of MapEditor
361 QGraphicsScene *mapScene;
362 MapCenterObj* mapCenter;
363 QTimer *autosaveTimer;
365 bool adjustCanvasRequested; // collect requests until end of user event
366 BranchObj *editingBO; // entering Text into BO
368 QColor defLinkColor; // default color for links
369 QColor defXLinkColor; // default color for xlinks
370 int defXLinkWidth; // default width for xlinks
371 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
372 LinkableMapObj::Style linkstyle; // default style for links
374 QCursor HandOpenCursor; // cursor while moving canvas view
375 QCursor PickColorCursor; // cursor while picking color
376 QCursor CopyCursor; // cursor while picking color
377 QCursor XLinkCursor; // cursor while picking color
379 bool drawingLink; // true while creating a link
380 bool copyingObj; // true while creating a link
385 QString latestSelection; // select string of latest added object
387 MapObj* movingObj; // moving a MapObj
388 MapObj* linkingObj_src; // part of a link
389 QPointF movingObj_orgPos; // org. pos of mouse before move
390 QPointF movingObj_orgRelPos; // org. relative pos of mouse before move
391 QPointF movingObj_start; // rel. pos of mouse to absPos
392 QPointF movingCont_start; // inital pos of moving Content or
393 QPointF movingVec; // how far has Content moved
394 QPrinter* printer; // Printing
396 bool mapDefault; // Flag if map is untouched
397 bool mapChanged; // Flag if undo is possible
398 bool mapUnsaved; // Flag if map should be saved
400 Parser parser; // Parser stuff for scripting
402 bool printFrame; // Print frame around map
403 bool printFooter; // Print footer below map
405 bool zipped; // should map be zipped
406 static int mapNum; // unique number for Editor
407 QString fileName; // short name of file (for tab)
408 QString filePath; // path to file which will be saved
409 QString fileDir; // dir where file is saved
410 QString destPath; // path to .vym file (needed for vymlinks)
411 QString mapName; // fileName without ".vym"
413 QString tmpMapDir; // tmp directory with undo history
414 QString histPath; // Path to history file
415 SimpleSettings undoSet; // undo/redo commands, saved in histPath
416 int stepsTotal; // total number of steps (undos+redos)
417 int curStep; // Current step in history (ring buffer)
418 int curClipboard; // number of history step, which is the current clipboard
419 int redosAvail; // Available number of redo steps
420 int undosAvail; // Available number of undo steps
421 bool blockReposition; // block while load or undo
422 bool blockSaveState; // block while load or undo
424 BranchObj* itFind; // next object in find process
425 bool EOFind; // true, if search failed
427 QPoint exportOffset; // set before export, used in save
428 BranchObj::HideTmpMode hidemode; // true while exporting to hide some stuff
430 NetState netstate; // offline, client, server
431 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
432 QList <QTcpSocket*> clientList; // List of connected clients
433 quint16 sendCounter; // Increased with every sent command
435 QTcpSocket *clientSocket; // socket of this client
436 QString server; // server address of this client
437 int port; // server port of this client
438 void displayClientError(QAbstractSocket::SocketError socketError);
441 int timerId; // animation timer
442 QList <MapObj*> animObjList;// list with animated objects