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, LoadMode ); // 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
193 void linkTo(const QString &);
195 QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
196 void setHeading(const QString &); //!< Set heading of branch
198 void setHeadingInt(const QString &);
199 void setVymLinkInt(const QString &); // Set vymLink for selection
200 /*! \brief Add new branch
202 Depending on num the new branch is created
204 -3 above selection as child of selections parent
205 -2 as child of selection
206 -1 below selection as child of selections parent
207 0..n insert at a specific position in selections parent
208 (needed for free relinking)
210 BranchObj* addNewBranchInt(int); // pos allows to add above/below selection
214 Depending on num the new branch is created
216 0 as child of selection
219 BranchObj* addNewBranch(int pos);
220 BranchObj* addNewBranchBefore(); //!< Insert branch between selection and its parent
221 void deleteSelection(); //!< Delete selection
222 LinkableMapObj* getSelection(); //!< Returns selection
223 BranchObj* getSelectedBranch(); // returns selected branch or NULL
224 FloatImageObj* getSelectedFloatImage(); // returns selected branch or NULL
225 void unselect(); // before changing current noteedit
226 void reselect(); // after changing current noteedit
227 bool select(const QString &); // Select by string
228 QString getSelectString();
230 void selectInt(LinkableMapObj*);
231 void selectNextBranchInt(); // Increment number of branch
232 void selectPrevBranchInt(); // Decrement number of branch
234 void selectUpperBranch();
235 void selectLowerBranch();
236 void selectLeftBranch();
237 void selectRightBranch();
238 void selectFirstBranch();
239 void selectLastBranch();
240 void selectMapBackgroundImage();
241 void setMapBackgroundImage(const QString &);
242 void selectMapBackgroundColor();
243 void setMapBackgroundColor(QColor);
244 QColor getMapBackgroundColor();
245 QColor getCurrentHeadingColor();
246 void colorBranch(QColor);
247 void colorSubtree(QColor);
248 void toggleStandardFlag(QString);
249 BranchObj* findText(QString,bool); // Find object
250 void findReset(); // Reset Find
251 void setURL(const QString &); // set URL
252 void editURL(); // edit URL
253 void editLocalURL(); // edit URL to local file
254 QString getURL(); // returns URL of selection or ""
255 QStringList getURLs(); // returns URLs of subtree
256 void editHeading2URL(); // copy heading to URL
257 void editBugzilla2URL(); // create URL to Bugzilla
258 void editFATE2URL(); // create URL to FATE
259 void editVymLink(); // edit link to another map
260 void deleteVymLink(); // delete link to another map
261 QString getVymLink(); // return path to map
262 QStringList getVymLinks(); // return paths in subtree
263 void setHideExport(bool); // toggle the export flag
264 void toggleHideExport(); // toggle the export flag
265 void deleteKeepChilds(); // remove but keep childs
266 void deleteChilds(); // remove childs
267 void editMapInfo(); // dialog to enter author, ...
268 void ensureSelectionVisible();
269 void updateSelection(); // update geometry of selection
270 void updateActions(); // update e.g. format buttons
271 void updateNoteFlag(); // when TextEditor changes
272 void setMapAuthor (const QString &);
273 void setMapComment(const QString &);
274 void setMapLinkStyle (const QString &); // Set style of link
275 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
276 void setMapDefLinkColor(QColor); // default color of links
277 void setMapLinkColorHintInt(); // color of links
278 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
279 LinkableMapObj::ColorHint getMapLinkColorHint();
280 QColor getMapDefLinkColor();
281 void setMapDefXLinkColor(QColor);
282 QColor getMapDefXLinkColor();
283 void setMapDefXLinkWidth (int);
284 int getMapDefXLinkWidth();
285 void toggleMapLinkColorHint(); // after changing linkStyles
286 void selectMapLinkColor();
287 void selectMapSelectionColor();
289 void setSelectionColorInt(QColor);
291 void setSelectionColor(QColor);
292 QColor getSelectionColor();
293 bool scrollBranch(BranchObj*);
294 bool unscrollBranch(BranchObj*);
296 void unscrollChilds();
298 FloatImageObj* loadFloatImageInt (QString);
300 void loadFloatImage ();
302 void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
304 void saveFloatImage ();
305 void setFrameType(const FrameObj::FrameType &);
306 void setFrameType(const QString &);
307 void setFramePenColor (const QColor &);
308 void setFrameBrushColor (const QColor &);
309 void setFramePadding (const int &);
310 void setFrameBorderWidth (const int &);
311 void setIncludeImagesVer(bool);
312 void setIncludeImagesHor(bool);
313 void setHideLinkUnselected (bool);
314 bool getHideLinkUnselected ();
316 void importDirInt(BranchObj *,QDir);
317 void importDirInt(const QString&);
320 void followXLink (int);
321 void editXLink (int);
322 void testFunction1(); // just testing new stuff
323 void testFunction2(); // just testing new stuff
324 // set /mainwindo/showTestMenu=true...
327 virtual void contextMenuEvent ( QContextMenuEvent *e );
328 virtual void keyPressEvent(QKeyEvent*);
329 virtual void keyReleaseEvent(QKeyEvent*);
330 virtual void mousePressEvent(QMouseEvent*);
331 virtual void mouseMoveEvent(QMouseEvent*);
332 virtual void mouseReleaseEvent(QMouseEvent*);
333 virtual void mouseDoubleClickEvent(QMouseEvent*);
334 virtual void resizeEvent( QResizeEvent * );
336 void dragEnterEvent (QDragEnterEvent *);
337 void dragMoveEvent (QDragMoveEvent *);
338 void dragLeaveEvent (QDragLeaveEvent *);
339 void dropEvent (QDropEvent *);
341 void timerEvent(QTimerEvent *event);
344 void sendSelection();
348 void connectToServer();
352 void sendData(const QString &s);
354 void displayNetworkError (QAbstractSocket::SocketError);
359 State state; // State of MapEditor
360 QGraphicsScene *mapScene;
361 MapCenterObj* mapCenter;
362 QTimer *autosaveTimer;
364 bool adjustCanvasRequested; // collect requests until end of user event
365 BranchObj *editingBO; // entering Text into BO
367 QColor defLinkColor; // default color for links
368 QColor defXLinkColor; // default color for xlinks
369 int defXLinkWidth; // default width for xlinks
370 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
371 LinkableMapObj::Style linkstyle; // default style for links
373 QCursor HandOpenCursor; // cursor while moving canvas view
374 QCursor PickColorCursor; // cursor while picking color
375 QCursor CopyCursor; // cursor while picking color
376 QCursor XLinkCursor; // cursor while picking color
378 bool drawingLink; // true while creating a link
379 bool copyingObj; // true while creating a link
384 QString latestSelection; // select string of latest added object
386 MapObj* movingObj; // moving a MapObj
387 MapObj* linkingObj_src; // part of a link
388 QPointF movingObj_orgPos; // org. pos of mouse before move
389 QPointF movingObj_orgRelPos; // org. relative pos of mouse before move
390 QPointF movingObj_start; // rel. pos of mouse to absPos
391 QPointF movingCont_start; // inital pos of moving Content or
392 QPointF movingVec; // how far has Content moved
393 QPrinter* printer; // Printing
395 bool mapDefault; // Flag if map is untouched
396 bool mapChanged; // Flag if undo is possible
397 bool mapUnsaved; // Flag if map should be saved
399 Parser parser; // Parser stuff for scripting
401 bool printFrame; // Print frame around map
402 bool printFooter; // Print footer below map
404 bool zipped; // should map be zipped
405 static int mapNum; // unique number for Editor
406 QString fileName; // short name of file (for tab)
407 QString filePath; // path to file which will be saved
408 QString fileDir; // dir where file is saved
409 QString destPath; // path to .vym file (needed for vymlinks)
410 QString mapName; // fileName without ".vym"
412 QString tmpMapDir; // tmp directory with undo history
413 QString histPath; // Path to history file
414 SimpleSettings undoSet; // undo/redo commands, saved in histPath
415 int stepsTotal; // total number of steps (undos+redos)
416 int curStep; // Current step in history (ring buffer)
417 int curClipboard; // number of history step, which is the current clipboard
418 int redosAvail; // Available number of redo steps
419 int undosAvail; // Available number of undo steps
420 bool blockReposition; // block while load or undo
421 bool blockSaveState; // block while load or undo
423 BranchObj* itFind; // next object in find process
424 bool EOFind; // true, if search failed
426 QPoint exportOffset; // set before export, used in save
427 BranchObj::HideTmpMode hidemode; // true while exporting to hide some stuff
429 NetState netstate; // offline, client, server
430 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
431 QList <QTcpSocket*> clientList; // List of connected clients
432 quint16 sendCounter; // Increased with every sent command
434 QTcpSocket *clientSocket; // socket of this client
435 QString server; // server address of this client
436 int port; // server port of this client
437 void displayClientError(QAbstractSocket::SocketError socketError);
440 int timerId; // animation timer
441 QList <MapObj*> animObjList;// list with animated objects