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