4 #include <QGraphicsScene>
8 #include "mapcenterobj.h"
11 #include "selection.h"
15 /*! \brief This will later be divided into Model/View
18 class VymModel : public QObject, public XMLObj {
21 ////////////////////////////////////////////
22 // General housekeeping
23 ////////////////////////////////////////////
25 QGraphicsScene *mapScene;
26 QList <MapCenterObj*> mapCenters;
27 QString version; //!< version string saved in vym file
37 void makeTmpDirectories(); //!< create temporary directories e.g. for history
39 void setMapEditor(MapEditor *me); // FIXME should not be necessary in Model/View
40 MapEditor* getMapEditor(); // FIXME not necessary
42 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
44 void updateActions(); //!< Update buttons in mainwindow
47 ////////////////////////////////////////////
49 ////////////////////////////////////////////
52 bool zipped; // should map be zipped
53 static int mapNum; // unique number for model used in save/undo
54 FileType fileType; // type of file, e.g. vym, freemind...
55 QString fileName; // short name of file (for tab)
56 QString filePath; // path to file which will be saved
57 QString fileDir; // dir where file is saved
58 QString destPath; // path to .vym file (needed for vymlinks)
59 QString mapName; // fileName without ".vym"
61 QString tmpMapDir; // tmp directory with undo history
63 QTimer *autosaveTimer;
64 QTimer *fileChangedTimer;
65 QDateTime fileChangedTime;
68 /*! This function saves all information of the map to disc.
69 saveToDir also calls the functions for all BranchObj and other objects in the map.
70 The structure of the map itself is returned as QString and passed back to Main,
71 where saveToDir is called initially
73 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
75 /*! \brief Sets filepath, filename and mapname
77 If the filepath is "/home/tux/map.xml", then the filename will be set
78 to map.xml. The destname is needed for vymLinks, pointing to another map.
79 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
83 /*! \brief Set File path
85 The destname is needed to construct the references between maps
87 void setFilePath (QString filepath,QString destname);
88 void setFilePath (QString); //!< Overloaded for convenience
89 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
90 QString getFileName (); //!< e.g. "map.xml"
91 QString getMapName (); //!< e.g. "map"
92 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
96 The data is read from file. Depending on LoadMode the current
97 selection gets replaced by data or the data is appended.
99 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
102 /*! \brief Save the map to file */
103 ErrorCode save(const SaveMode &);
106 void addMapReplaceInt(const QString & undoSel, const QString & path);
107 void addMapInsertInt (const QString & path, int pos);
109 FloatImageObj* loadFloatImageInt (QString);
110 void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
112 void loadFloatImage ();
113 void saveFloatImage ();
116 void importDirInt(BranchObj *,QDir);
117 void importDirInt(const QString&);
125 ////////////////////////////////////////////
126 // history (undo/redo)
127 ////////////////////////////////////////////
129 bool mapDefault; //!< Flag if map is untouched
130 bool mapChanged; //!< Flag if undo is possible
131 bool mapUnsaved; //!< Flag if map should be saved
133 QString histPath; //!< Path to history file
134 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
135 int stepsTotal; //!< total number of steps (undos+redos)
136 int curStep; //!< Current step in history (ring buffer)
137 int curClipboard; //!< number of history step, which is the current clipboard
138 int redosAvail; //!< Available number of redo steps
139 int undosAvail; //!< Available number of undo steps
140 bool blockReposition; //!< block while load or undo
141 bool blockSaveState; //!< block while load or undo
143 bool isDefault(); //!< true, if map is still the empty default map
144 void makeDefault(); //!< Reset changelog, declare this as default map
145 bool hasChanged() ; //!< true, if something has changed and is not saved yet
146 void setChanged(); //!< called from TextEditor via LinkableMapObj
148 /*! \brief Get name of object
150 Returns heading of a branch or name of an object for use in comment
153 QString getObjectName(const LinkableMapObj*);
155 void redo(); //!< Redo last action
156 bool isRedoAvailable(); //!< True, if redo is available
157 void undo(); //!< Undo last action
158 bool isUndoAvailable(); //!< True, if undo is available
159 void gotoHistoryStep (int); //!< Goto a specifig step in history
162 QString getHistoryPath(); //!< Path to directory containing the history
164 /*! \brief Save the current changes in map
166 Two commands and selections are saved:
168 - undocommand and undoselection to undo the change
169 - redocommand and redoselection to redo the action after an undo
171 Additionally a comment is logged.
175 const SaveMode& savemode,
176 const QString &undoSelection,
177 const QString &undoCommand,
178 const QString &redoSelection,
179 const QString &redoCommand,
180 const QString &comment,
181 LinkableMapObj *saveSelection);
182 /*! Overloaded for convenience */
183 void saveStateChangingPart(
184 LinkableMapObj *undoSelection,
185 LinkableMapObj* redoSelection,
186 const QString &redoCommand,
187 const QString &comment);
188 /*! Overloaded for convenience */
189 void saveStateRemovingPart(
190 LinkableMapObj *redoSelection,
191 const QString &comment);
192 /*! Overloaded for convenience */
194 LinkableMapObj *undoSelection,
195 const QString &undoCommand,
196 LinkableMapObj *redoSelection,
197 const QString &redoCommand,
198 const QString &comment);
199 /*! Overloaded for convenience */
201 const QString &undoSelection,
202 const QString &undoCommand,
203 const QString &redoSelection,
204 const QString &redoCommand,
205 const QString &comment) ;
207 const QString &undoCommand,
208 const QString &redoCommand,
209 const QString &comment) ;
212 ////////////////////////////////////////////
214 ////////////////////////////////////////////
216 void setScene(QGraphicsScene *s);
217 QGraphicsScene *getScene();
220 BranchObj* next(BranchObj *bo);
222 LinkableMapObj* findMapObj(QPointF,LinkableMapObj*); // find MapObj
223 LinkableMapObj* findObjBySelect (const QString &s); // find MapObj by select string
224 LinkableMapObj* findID (const QString &s); // find MapObj by previously set ID
226 QString saveToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
229 ////////////////////////////////////////////
231 ////////////////////////////////////////////
233 void setVersion(const QString &);
234 void setAuthor (const QString &);
235 QString getAuthor ();
236 void setComment (const QString &);
237 QString getComment ();
241 void setHeading(const QString &); //!< Set heading of branch
242 QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
244 void setHeadingInt(const QString &);
247 BranchObj* itFind; // next object in find process
248 bool EOFind; // true, if search failed
250 BranchObj* findText(QString,bool); // Find object
251 void findReset(); // Reset Search
253 void setURL(const QString &url);
254 QString getURL(); // returns URL of selection or ""
255 QStringList getURLs(); // returns URLs of subtree
257 void linkFloatImageTo(const QString &);
259 void setFrameType(const FrameObj::FrameType &);
260 void setFrameType(const QString &);
261 void setFramePenColor (const QColor &);
262 void setFrameBrushColor (const QColor &);
263 void setFramePadding (const int &);
264 void setFrameBorderWidth (const int &);
265 void setIncludeImagesVer(bool);
266 void setIncludeImagesHor(bool);
267 void setHideLinkUnselected (bool);
269 /*! Should object be hidden in exports (clouded)? */
270 void setHideExport(bool);
272 /*! Should object be hidden in exports (clouded)? */
273 void toggleHideExport();
275 void copy(); //!< Copy to clipboard
277 void pasteNoSave(const int &n); //!< paste clipboard to branch
279 void paste(); //!< Paste clipboard to branch and backup
280 void cut(); //!< Cut to clipboard (and copy)
282 void moveBranchUp(); //!< Move branch up
283 void moveBranchDown(); //!< Move branch down
284 void sortChildren(); //!< Sort children lexically
286 /*! \brief Add new mapcenter
288 Disclaimer: Still experimental, not fully supported yet.
290 MapCenterObj* addMapCenter();
292 MapCenterObj* addMapCenter(QPointF absPos);
294 MapCenterObj* removeMapCenter(MapCenterObj *mco);
296 /*! \brief Add new branch
298 Depending on num the new branch is created
300 -3 above selection as child of selections parent
301 -2 as child of selection
302 -1 below selection as child of selections parent
303 0..n insert at a specific position in selections parent
304 (needed for free relinking)
307 BranchObj* addNewBranchInt(int); // pos allows to add above/below selection
311 Depending on num the new branch is created
313 0 as child of selection
316 BranchObj* addNewBranch(int pos);
317 BranchObj* addNewBranchBefore(); //!< Insert branch between selection and its parent
318 void deleteSelection(); //!< Delete selection
319 void deleteKeepChildren(); //!< remove branch, but keep children
320 void deleteChildren(); //!< keep branch, but remove children
323 bool scrollBranch(BranchObj*);
324 bool unscrollBranch(BranchObj*);
327 void unscrollChildren();
329 void addFloatImage(const QPixmap &img);
331 void colorBranch(QColor);
332 void colorSubtree(QColor);
333 QColor getCurrentHeadingColor();
336 void editURL(); // edit URL
337 void editLocalURL(); // edit URL to local file
338 void editHeading2URL(); // copy heading to URL
339 void editBugzilla2URL(); // create URL to Bugzilla
340 void editFATE2URL(); // create URL to FATE
341 void editVymLink(); // edit link to another map
342 void setVymLink (const QString &); // Set vymLink for selection
343 void deleteVymLink(); // delete link to another map
344 QString getVymLink(); // return path to map
345 QStringList getVymLinks(); // return paths in subtree
346 void followXLink (int);
347 void editXLink (int);
352 ////////////////////////////////////////////
354 ////////////////////////////////////////////
357 /* \brief Process one command and its parameters */
358 void parseAtom (const QString &atom);
360 /* \brief Runs the script */
361 void runScript (QString script);
366 ////////////////////////////////////////////
368 ////////////////////////////////////////////
370 HideTmpMode hidemode; // true while exporting to hide some stuff
373 /*! Set or unset temporary hiding of objects during export */
374 void setExportMode (bool);
377 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
380 /*! Export as XTML to directory */
381 void exportXML(QString dir="", bool askForName=true);
383 /*! Export as ASCII text to file */
384 void exportASCII (QString fname="",bool askForName=true);
386 /*! Export as XHTML to directory */
387 void exportXHTML(const QString& dir="", bool askForName=true);
389 /*! Export as OpenOfficeOrg presentation */
390 void exportOOPresentation(const QString &,const QString &);
393 ////////////////////////////////////////////
395 ////////////////////////////////////////////
397 void registerEditor (QWidget *);
398 void unregisterEditor (QWidget *);
399 void updateNoteFlag(); //!< Signal origination in TextEditor
400 void updateRelPositions();
402 QRectF getTotalBBox();
403 void reposition(); //!< Call reposition for all MCOs
404 void setHideTmpMode (HideTmpMode mode);
406 QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree
407 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
409 //void ensureSelectionVisible(); //!< Show selection in all views
412 MapEditor *mapEditor;
414 QColor defLinkColor; // default color for links
415 QColor defXLinkColor; // default color for xlinks
416 int defXLinkWidth; // default width for xlinks
417 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
418 LinkableMapObj::Style linkstyle; // default style for links
424 void setMapLinkStyle (const QString &); // Set style of link
425 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
426 void setMapDefLinkColor(QColor); // default color of links
427 void setMapLinkColorHintInt(); // color of links
428 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
429 void toggleMapLinkColorHint(); // after changing linkStyles
430 void selectMapBackgroundImage();
431 void setMapBackgroundImage(const QString &);
432 void selectMapBackgroundColor();
433 void setMapBackgroundColor(QColor);
434 QColor getMapBackgroundColor();
437 LinkableMapObj::ColorHint getMapLinkColorHint();
438 QColor getMapDefLinkColor();
439 void setMapDefXLinkColor(QColor);
440 QColor getMapDefXLinkColor();
441 void setMapDefXLinkWidth (int);
442 int getMapDefXLinkWidth();
444 /*! Move absolutly to (x,y). */
445 void move (const double &x, const double &y);
447 /*! Move relativly to (x,y). */
448 void moveRel (const double &x, const double &y);
450 ////////////////////////////////////////////
451 // Animation **experimental**
452 ////////////////////////////////////////////
454 QTimer *animationTimer;
457 uint animationInterval;
458 int timerId; // animation timer
459 QList <MapObj*> animObjList;// list with animated objects
462 void animate(); //!< Called by timer to animate stuff
464 void startAnimation(const QPointF &start, const QPointF &dest);
465 void stopAnimation(MapObj *mo);
467 ////////////////////////////////////////////
469 ////////////////////////////////////////////
471 /*! \brief Networking states
473 In Network modus we want to switch of saveState, autosave, ...
476 Offline, //!< Offline
477 Client, //!< I am the client and connected to server
478 Server //!< I am the server
482 // Network connections **Experimental**
483 NetState netstate; // offline, client, server
484 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
485 QList <QTcpSocket*> clientList; // List of connected clients
486 quint16 sendCounter; // Increased with every sent command
488 QTcpSocket *clientSocket; // socket of this client
489 QString server; // server address of this client
490 int port; // server port of this client
495 void sendSelection();
499 void connectToServer();
503 void sendData(const QString &s);
505 void displayNetworkError (QAbstractSocket::SocketError);
508 void displayClientError(QAbstractSocket::SocketError socketError);
511 ////////////////////////////////////////////
513 ////////////////////////////////////////////
516 QString latestSelectionString; // select string of latest added object
519 void setSelectionBlocked(bool);
520 bool isSelectionBlocked();
522 bool select(const QString &); // Select by string
523 bool select(LinkableMapObj *lmo); // Select by pointer
527 void ensureSelectionVisible(); //!< Show selection in all views
529 void selectInt(LinkableMapObj*);
532 void selectNextBranchInt(); // Increment number of branch
533 void selectPrevBranchInt(); // Decrement number of branch
535 void selectUpperBranch();
536 void selectLowerBranch();
537 void selectLeftBranch();
538 void selectRightBranch();
539 void selectFirstBranch();
540 void selectLastBranch();
543 Selection::Type selectionType();
544 LinkableMapObj* getSelection();
545 BranchObj* getSelectedBranch();
546 FloatImageObj* getSelectedFloatImage();
547 QString getSelectString ();
548 QString getSelectString (LinkableMapObj *lmo);
550 void updateSelection();
551 void selectMapLinkColor();
552 void selectMapSelectionColor();
554 void setSelectionColorInt(QColor);
556 void setSelectionColor(QColor);
557 QColor getSelectionColor();