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 MapEditor* getMapEditor(); // FIXME not necessary
41 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
43 void updateActions(); //!< Update buttons in mainwindow
46 ////////////////////////////////////////////
48 ////////////////////////////////////////////
51 bool zipped; // should map be zipped
52 static int mapNum; // unique number for model used in save/undo
53 FileType fileType; // type of file, e.g. vym, freemind...
54 QString fileName; // short name of file (for tab)
55 QString filePath; // path to file which will be saved
56 QString fileDir; // dir where file is saved
57 QString destPath; // path to .vym file (needed for vymlinks)
58 QString mapName; // fileName without ".vym"
60 QString tmpMapDir; // tmp directory with undo history
62 QTimer *autosaveTimer;
63 QTimer *fileChangedTimer;
64 QDateTime fileChangedTime;
67 /*! This function saves all information of the map to disc.
68 saveToDir also calls the functions for all BranchObj and other objects in the map.
69 The structure of the map itself is returned as QString and passed back to Main,
70 where saveToDir is called initially
72 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
74 /*! \brief Sets filepath, filename and mapname
76 If the filepath is "/home/tux/map.xml", then the filename will be set
77 to map.xml. The destname is needed for vymLinks, pointing to another map.
78 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
82 /*! \brief Set File path
84 The destname is needed to construct the references between maps
86 void setFilePath (QString filepath,QString destname);
87 void setFilePath (QString); //!< Overloaded for convenience
88 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
89 QString getFileName (); //!< e.g. "map.xml"
90 QString getMapName (); //!< e.g. "map"
91 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
95 The data is read from file. Depending on LoadMode the current
96 selection gets replaced by data or the data is appended.
98 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
101 /*! \brief Save the map to file */
102 ErrorCode save(const SaveMode &);
105 void addMapReplaceInt(const QString & undoSel, const QString & path);
106 void addMapInsertInt (const QString & path, int pos);
108 FloatImageObj* loadFloatImageInt (QString);
109 void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
111 void loadFloatImage ();
112 void saveFloatImage ();
115 void importDirInt(BranchObj *,QDir);
116 void importDirInt(const QString&);
124 ////////////////////////////////////////////
125 // history (undo/redo)
126 ////////////////////////////////////////////
128 bool mapDefault; //!< Flag if map is untouched
129 bool mapChanged; //!< Flag if undo is possible
130 bool mapUnsaved; //!< Flag if map should be saved
132 QString histPath; //!< Path to history file
133 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
134 int stepsTotal; //!< total number of steps (undos+redos)
135 int curStep; //!< Current step in history (ring buffer)
136 int curClipboard; //!< number of history step, which is the current clipboard
137 int redosAvail; //!< Available number of redo steps
138 int undosAvail; //!< Available number of undo steps
139 bool blockReposition; //!< block while load or undo
140 bool blockSaveState; //!< block while load or undo
142 bool isDefault(); //!< true, if map is still the empty default map
143 void makeDefault(); //!< Reset changelog, declare this as default map
144 bool hasChanged() ; //!< true, if something has changed and is not saved yet
145 void setChanged(); //!< called from TextEditor via LinkableMapObj
147 /*! \brief Get name of object
149 Returns heading of a branch or name of an object for use in comment
152 QString getObjectName(const LinkableMapObj*);
154 void redo(); //!< Redo last action
155 bool isRedoAvailable(); //!< True, if redo is available
156 void undo(); //!< Undo last action
157 bool isUndoAvailable(); //!< True, if undo is available
158 void gotoHistoryStep (int); //!< Goto a specifig step in history
161 QString getHistoryPath(); //!< Path to directory containing the history
163 /*! \brief Save the current changes in map
165 Two commands and selections are saved:
167 - undocommand and undoselection to undo the change
168 - redocommand and redoselection to redo the action after an undo
170 Additionally a comment is logged.
174 const SaveMode& savemode,
175 const QString &undoSelection,
176 const QString &undoCommand,
177 const QString &redoSelection,
178 const QString &redoCommand,
179 const QString &comment,
180 LinkableMapObj *saveSelection);
181 /*! Overloaded for convenience */
182 void saveStateChangingPart(
183 LinkableMapObj *undoSelection,
184 LinkableMapObj* redoSelection,
185 const QString &redoCommand,
186 const QString &comment);
187 /*! Overloaded for convenience */
188 void saveStateRemovingPart(
189 LinkableMapObj *redoSelection,
190 const QString &comment);
191 /*! Overloaded for convenience */
193 LinkableMapObj *undoSelection,
194 const QString &undoCommand,
195 LinkableMapObj *redoSelection,
196 const QString &redoCommand,
197 const QString &comment);
198 /*! Overloaded for convenience */
200 const QString &undoSelection,
201 const QString &undoCommand,
202 const QString &redoSelection,
203 const QString &redoCommand,
204 const QString &comment) ;
206 const QString &undoCommand,
207 const QString &redoCommand,
208 const QString &comment) ;
211 ////////////////////////////////////////////
213 ////////////////////////////////////////////
215 void setScene(QGraphicsScene *s);
216 QGraphicsScene *getScene();
219 BranchObj* next(BranchObj *bo);
221 LinkableMapObj* findMapObj(QPointF,LinkableMapObj*); // find MapObj
222 LinkableMapObj* findObjBySelect (const QString &s); // find MapObj by select string
223 LinkableMapObj* findID (const QString &s); // find MapObj by previously set ID
225 QString saveToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
228 ////////////////////////////////////////////
230 ////////////////////////////////////////////
232 void setVersion(const QString &);
233 void setAuthor (const QString &);
234 QString getAuthor ();
235 void setComment (const QString &);
236 QString getComment ();
240 void setHeading(const QString &); //!< Set heading of branch
241 QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
243 void setHeadingInt(const QString &);
246 BranchObj* itFind; // next object in find process
247 bool EOFind; // true, if search failed
249 BranchObj* findText(QString,bool); // Find object
250 void findReset(); // Reset Search
252 void setURL(const QString &url);
253 QString getURL(); // returns URL of selection or ""
254 QStringList getURLs(); // returns URLs of subtree
256 void linkFloatImageTo(const QString &);
258 void setFrameType(const FrameObj::FrameType &);
259 void setFrameType(const QString &);
260 void setFramePenColor (const QColor &);
261 void setFrameBrushColor (const QColor &);
262 void setFramePadding (const int &);
263 void setFrameBorderWidth (const int &);
264 void setIncludeImagesVer(bool);
265 void setIncludeImagesHor(bool);
266 void setHideLinkUnselected (bool);
268 /*! Should object be hidden in exports (clouded)? */
269 void setHideExport(bool);
271 /*! Should object be hidden in exports (clouded)? */
272 void toggleHideExport();
274 void copy(); //!< Copy to clipboard
276 void pasteNoSave(const int &n); //!< paste clipboard to branch
278 void paste(); //!< Paste clipboard to branch and backup
279 void cut(); //!< Cut to clipboard (and copy)
281 void moveBranchUp(); //!< Move branch up
282 void moveBranchDown(); //!< Move branch down
283 void sortChildren(); //!< Sort children lexically
285 /*! \brief Add new mapcenter
287 Disclaimer: Still experimental, not fully supported yet.
289 MapCenterObj* addMapCenter();
291 MapCenterObj* addMapCenter(QPointF absPos);
293 MapCenterObj* removeMapCenter(MapCenterObj *mco);
295 /*! \brief Add new branch
297 Depending on num the new branch is created
299 -3 above selection as child of selections parent
300 -2 as child of selection
301 -1 below selection as child of selections parent
302 0..n insert at a specific position in selections parent
303 (needed for free relinking)
305 MapCenterObj* getLastMapCenter(); //!< get last added MapCenter, used for context menu
308 BranchObj* addNewBranchInt(int); // pos allows to add above/below selection
312 Depending on num the new branch is created
314 0 as child of selection
317 BranchObj* addNewBranch(int pos);
318 BranchObj* addNewBranchBefore(); //!< Insert branch between selection and its parent
319 void deleteSelection(); //!< Delete selection
320 void deleteKeepChildren(); //!< remove branch, but keep children
321 void deleteChildren(); //!< keep branch, but remove children
324 bool scrollBranch(BranchObj*);
325 bool unscrollBranch(BranchObj*);
328 void unscrollChildren();
330 void addFloatImage(const QPixmap &img);
332 void colorBranch(QColor);
333 void colorSubtree(QColor);
334 QColor getCurrentHeadingColor();
337 void editURL(); // edit URL
338 void editLocalURL(); // edit URL to local file
339 void editHeading2URL(); // copy heading to URL
340 void editBugzilla2URL(); // create URL to Bugzilla
341 void editFATE2URL(); // create URL to FATE
342 void editVymLink(); // edit link to another map
343 void setVymLink (const QString &); // Set vymLink for selection
344 void deleteVymLink(); // delete link to another map
345 QString getVymLink(); // return path to map
346 QStringList getVymLinks(); // return paths in subtree
347 void followXLink (int);
348 void editXLink (int);
353 ////////////////////////////////////////////
355 ////////////////////////////////////////////
358 /* \brief Process one command and its parameters */
359 void parseAtom (const QString &atom);
361 /* \brief Runs the script */
362 void runScript (QString script);
367 ////////////////////////////////////////////
369 ////////////////////////////////////////////
371 HideTmpMode hidemode; // true while exporting to hide some stuff
374 /*! Set or unset temporary hiding of objects during export */
375 void setExportMode (bool);
378 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
381 /*! Export as XTML to directory */
382 void exportXML(QString dir="", bool askForName=true);
384 /*! Export as ASCII text to file */
385 void exportASCII (QString fname="",bool askForName=true);
387 /*! Export as XHTML to directory */
388 void exportXHTML(const QString& dir="", bool askForName=true);
390 /*! Export as OpenOfficeOrg presentation */
391 void exportOOPresentation(const QString &,const QString &);
394 ////////////////////////////////////////////
396 ////////////////////////////////////////////
398 void registerEditor (QWidget *);
399 void unregisterEditor (QWidget *);
402 QPointF contextPos; //!< local position during context menu
404 void setContextPos (QPointF); //!< local position during context menu
405 void unsetContextPos (); //!< forget local position after context menu
407 void updateNoteFlag(); //!< Signal origination in TextEditor
408 void updateRelPositions();
410 QRectF getTotalBBox();
411 void reposition(); //!< Call reposition for all MCOs
412 void setHideTmpMode (HideTmpMode mode);
414 QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree
415 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
417 //void ensureSelectionVisible(); //!< Show selection in all views
420 MapEditor *mapEditor;
422 QColor defLinkColor; // default color for links
423 QColor defXLinkColor; // default color for xlinks
424 int defXLinkWidth; // default width for xlinks
425 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
426 LinkableMapObj::Style linkstyle; // default style for links
432 void setMapLinkStyle (const QString &); // Set style of link
433 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
434 void setMapDefLinkColor(QColor); // default color of links
435 void setMapLinkColorHintInt(); // color of links
436 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
437 void toggleMapLinkColorHint(); // after changing linkStyles
438 void selectMapBackgroundImage();
439 void setMapBackgroundImage(const QString &);
440 void selectMapBackgroundColor();
441 void setMapBackgroundColor(QColor);
442 QColor getMapBackgroundColor();
445 LinkableMapObj::ColorHint getMapLinkColorHint();
446 QColor getMapDefLinkColor();
447 void setMapDefXLinkColor(QColor);
448 QColor getMapDefXLinkColor();
449 void setMapDefXLinkWidth (int);
450 int getMapDefXLinkWidth();
452 /*! Move absolutly to (x,y). */
453 void move (const double &x, const double &y);
455 /*! Move relativly to (x,y). */
456 void moveRel (const double &x, const double &y);
458 ////////////////////////////////////////////
459 // Animation **experimental**
460 ////////////////////////////////////////////
462 QTimer *animationTimer;
465 uint animationInterval;
466 int timerId; // animation timer
467 QList <MapObj*> animObjList;// list with animated objects
470 void animate(); //!< Called by timer to animate stuff
472 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
473 void stopAnimation(MapObj *mo);
475 ////////////////////////////////////////////
477 ////////////////////////////////////////////
479 /*! \brief Networking states
481 In Network modus we want to switch of saveState, autosave, ...
484 Offline, //!< Offline
485 Client, //!< I am the client and connected to server
486 Server //!< I am the server
490 // Network connections **Experimental**
491 NetState netstate; // offline, client, server
492 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
493 QList <QTcpSocket*> clientList; // List of connected clients
494 quint16 sendCounter; // Increased with every sent command
496 QTcpSocket *clientSocket; // socket of this client
497 QString server; // server address of this client
498 int port; // server port of this client
503 void sendSelection();
507 void connectToServer();
511 void sendData(const QString &s);
513 void displayNetworkError (QAbstractSocket::SocketError);
516 void displayClientError(QAbstractSocket::SocketError socketError);
519 ////////////////////////////////////////////
521 ////////////////////////////////////////////
524 QString latestSelectionString; // select string of latest added object
527 void setSelectionBlocked(bool);
528 bool isSelectionBlocked();
530 bool select(const QString &); // Select by string
531 bool select(LinkableMapObj *lmo); // Select by pointer
535 void ensureSelectionVisible(); //!< Show selection in all views
537 void selectInt(LinkableMapObj*);
540 void selectNextBranchInt(); // Increment number of branch
541 void selectPrevBranchInt(); // Decrement number of branch
543 void selectUpperBranch();
544 void selectLowerBranch();
545 void selectLeftBranch();
546 void selectRightBranch();
547 void selectFirstBranch();
548 void selectLastBranch();
551 Selection::Type selectionType();
552 LinkableMapObj* getSelection();
553 BranchObj* getSelectedBranch();
554 FloatImageObj* getSelectedFloatImage();
555 QString getSelectString ();
556 QString getSelectString (LinkableMapObj *lmo);
558 void updateSelection();
559 void selectMapLinkColor();
560 void selectMapSelectionColor();
562 void setSelectionColorInt(QColor);
564 void setSelectionColor(QColor);
565 QColor getSelectionColor();