4 #include <QGraphicsScene>
8 #include "mapcenterobj.h"
11 #include "selection.h"
12 #include "treemodel.h"
16 /*! \brief This will later be divided into Model/View
19 class VymModel : public QObject, public XMLObj {
22 ////////////////////////////////////////////
23 // General housekeeping
24 ////////////////////////////////////////////
26 QGraphicsScene *mapScene;
27 QList <MapCenterObj*> mapCenters;
28 QString version; //!< version string saved in vym file
38 void makeTmpDirectories(); //!< create temporary directories e.g. for history
40 MapEditor* getMapEditor(); // FIXME not necessary
45 TreeModel* getTreeModel();
47 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
49 void updateActions(); //!< Update buttons in mainwindow
52 ////////////////////////////////////////////
54 ////////////////////////////////////////////
57 bool zipped; // should map be zipped
58 static int mapNum; // unique number for model used in save/undo
59 FileType fileType; // type of file, e.g. vym, freemind...
60 QString fileName; // short name of file (for tab)
61 QString filePath; // path to file which will be saved
62 QString fileDir; // dir where file is saved
63 QString destPath; // path to .vym file (needed for vymlinks)
64 QString mapName; // fileName without ".vym"
66 QString tmpMapDir; // tmp directory with undo history
68 QTimer *autosaveTimer;
69 QTimer *fileChangedTimer;
70 QDateTime fileChangedTime;
73 /*! This function saves all information of the map to disc.
74 saveToDir also calls the functions for all BranchObj and other objects in the map.
75 The structure of the map itself is returned as QString and passed back to Main,
76 where saveToDir is called initially
78 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
80 /*! \brief Sets filepath, filename and mapname
82 If the filepath is "/home/tux/map.xml", then the filename will be set
83 to map.xml. The destname is needed for vymLinks, pointing to another map.
84 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
88 /*! \brief Set File path
90 The destname is needed to construct the references between maps
92 void setFilePath (QString filepath,QString destname);
93 void setFilePath (QString); //!< Overloaded for convenience
94 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
95 QString getFileName (); //!< e.g. "map.xml"
96 QString getMapName (); //!< e.g. "map"
97 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
101 The data is read from file. Depending on LoadMode the current
102 selection gets replaced by data or the data is appended.
104 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
107 /*! \brief Save the map to file */
108 ErrorCode save(const SaveMode &);
111 void addMapReplaceInt(const QString & undoSel, const QString & path);
112 void addMapInsertInt (const QString & path, int pos);
114 FloatImageObj* loadFloatImageInt (QString);
115 void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
117 void loadFloatImage ();
118 void saveFloatImage ();
121 void importDirInt(BranchObj *,QDir);
122 void importDirInt(const QString&);
130 ////////////////////////////////////////////
131 // history (undo/redo)
132 ////////////////////////////////////////////
134 bool mapDefault; //!< Flag if map is untouched
135 bool mapChanged; //!< Flag if undo is possible
136 bool mapUnsaved; //!< Flag if map should be saved
138 QString histPath; //!< Path to history file
139 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
140 int stepsTotal; //!< total number of steps (undos+redos)
141 int curStep; //!< Current step in history (ring buffer)
142 int curClipboard; //!< number of history step, which is the current clipboard
143 int redosAvail; //!< Available number of redo steps
144 int undosAvail; //!< Available number of undo steps
145 bool blockReposition; //!< block while load or undo
146 bool blockSaveState; //!< block while load or undo
148 bool isDefault(); //!< true, if map is still the empty default map
149 void makeDefault(); //!< Reset changelog, declare this as default map
150 bool hasChanged() ; //!< true, if something has changed and is not saved yet
151 void setChanged(); //!< called from TextEditor via LinkableMapObj
153 /*! \brief Get name of object
155 Returns heading of a branch or name of an object for use in comment
158 QString getObjectName(const LinkableMapObj*);
160 void redo(); //!< Redo last action
161 bool isRedoAvailable(); //!< True, if redo is available
162 void undo(); //!< Undo last action
163 bool isUndoAvailable(); //!< True, if undo is available
164 void gotoHistoryStep (int); //!< Goto a specifig step in history
167 QString getHistoryPath(); //!< Path to directory containing the history
169 /*! \brief Save the current changes in map
171 Two commands and selections are saved:
173 - undocommand and undoselection to undo the change
174 - redocommand and redoselection to redo the action after an undo
176 Additionally a comment is logged.
180 const SaveMode& savemode,
181 const QString &undoSelection,
182 const QString &undoCommand,
183 const QString &redoSelection,
184 const QString &redoCommand,
185 const QString &comment,
186 LinkableMapObj *saveSelection);
187 /*! Overloaded for convenience */
188 void saveStateChangingPart(
189 LinkableMapObj *undoSelection,
190 LinkableMapObj* redoSelection,
191 const QString &redoCommand,
192 const QString &comment);
193 /*! Overloaded for convenience */
194 void saveStateRemovingPart(
195 LinkableMapObj *redoSelection,
196 const QString &comment);
197 /*! Overloaded for convenience */
199 LinkableMapObj *undoSelection,
200 const QString &undoCommand,
201 LinkableMapObj *redoSelection,
202 const QString &redoCommand,
203 const QString &comment);
204 /*! Overloaded for convenience */
206 const QString &undoSelection,
207 const QString &undoCommand,
208 const QString &redoSelection,
209 const QString &redoCommand,
210 const QString &comment) ;
212 const QString &undoCommand,
213 const QString &redoCommand,
214 const QString &comment) ;
217 ////////////////////////////////////////////
219 ////////////////////////////////////////////
221 void setScene(QGraphicsScene *s);
222 QGraphicsScene *getScene();
225 BranchObj* next(BranchObj *bo);
227 LinkableMapObj* findMapObj(QPointF,LinkableMapObj*); // find MapObj
228 LinkableMapObj* findObjBySelect (const QString &s); // find MapObj by select string
229 LinkableMapObj* findID (const QString &s); // find MapObj by previously set ID
231 QString saveToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
234 ////////////////////////////////////////////
236 ////////////////////////////////////////////
238 void setVersion(const QString &);
239 void setAuthor (const QString &);
240 QString getAuthor ();
241 void setComment (const QString &);
242 QString getComment ();
246 void setHeading(const QString &); //!< Set heading of branch
247 // QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
249 void setHeadingInt(const QString &);
252 BranchObj* itFind; // next object in find process
253 bool EOFind; // true, if search failed
255 BranchObj* findText(QString,bool); // Find object
256 void findReset(); // Reset Search
258 void setURL(const QString &url);
259 QString getURL(); // returns URL of selection or ""
260 QStringList getURLs(); // returns URLs of subtree
262 void linkFloatImageTo(const QString &);
264 void setFrameType(const FrameObj::FrameType &);
265 void setFrameType(const QString &);
266 void setFramePenColor (const QColor &);
267 void setFrameBrushColor (const QColor &);
268 void setFramePadding (const int &);
269 void setFrameBorderWidth (const int &);
270 void setIncludeImagesVer(bool);
271 void setIncludeImagesHor(bool);
272 void setHideLinkUnselected (bool);
274 /*! Should object be hidden in exports (clouded)? */
275 void setHideExport(bool);
277 /*! Should object be hidden in exports (clouded)? */
278 void toggleHideExport();
280 void copy(); //!< Copy to clipboard
282 void pasteNoSave(const int &n); //!< paste clipboard to branch
284 void paste(); //!< Paste clipboard to branch and backup
285 void cut(); //!< Cut to clipboard (and copy)
287 void moveBranchUp(); //!< Move branch up
288 void moveBranchDown(); //!< Move branch down
289 void sortChildren(); //!< Sort children lexically
291 /*! \brief Add new mapcenter
293 Disclaimer: Still experimental, not fully supported yet.
295 MapCenterObj* addMapCenter();
297 MapCenterObj* addMapCenter(QPointF absPos);
299 MapCenterObj* removeMapCenter(MapCenterObj *mco);
301 /*! \brief Add new branch
303 Depending on num the new branch is created
305 -3 above selection as child of selections parent
306 -2 as child of selection
307 -1 below selection as child of selections parent
308 0..n insert at a specific position in selections parent
309 (needed for free relinking)
311 MapCenterObj* getLastMapCenter(); //!< get last added MapCenter, used for context menu
314 BranchObj* addNewBranchInt(int); // pos allows to add above/below selection
318 Depending on num the new branch is created
320 0 as child of selection
323 BranchObj* addNewBranch(int pos);
324 BranchObj* addNewBranchBefore(); //!< Insert branch between selection and its parent
325 void deleteSelection(); //!< Delete selection
326 void deleteKeepChildren(); //!< remove branch, but keep children
327 void deleteChildren(); //!< keep branch, but remove children
330 bool scrollBranch(BranchObj*);
331 bool unscrollBranch(BranchObj*);
334 void unscrollChildren();
336 void addFloatImage(const QPixmap &img);
338 void colorBranch(QColor);
339 void colorSubtree(QColor);
340 QColor getCurrentHeadingColor();
343 void editURL(); // edit URL
344 void editLocalURL(); // edit URL to local file
345 void editHeading2URL(); // copy heading to URL
346 void editBugzilla2URL(); // create URL to Bugzilla
347 void editFATE2URL(); // create URL to FATE
348 void editVymLink(); // edit link to another map
349 void setVymLink (const QString &); // Set vymLink for selection
350 void deleteVymLink(); // delete link to another map
351 QString getVymLink(); // return path to map
352 QStringList getVymLinks(); // return paths in subtree
353 void followXLink (int);
354 void editXLink (int);
359 ////////////////////////////////////////////
361 ////////////////////////////////////////////
364 /* \brief Process one command and its parameters */
365 void parseAtom (const QString &atom);
367 /* \brief Runs the script */
368 void runScript (QString script);
373 ////////////////////////////////////////////
375 ////////////////////////////////////////////
377 HideTmpMode hidemode; // true while exporting to hide some stuff
380 /*! Set or unset temporary hiding of objects during export */
381 void setExportMode (bool);
384 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
387 /*! Export as XTML to directory */
388 void exportXML(QString dir="", bool askForName=true);
390 /*! Export as ASCII text to file */
391 void exportASCII (QString fname="",bool askForName=true);
393 /*! Export as XHTML to directory */
394 void exportXHTML(const QString& dir="", bool askForName=true);
396 /*! Export as OpenOfficeOrg presentation */
397 void exportOOPresentation(const QString &,const QString &);
400 ////////////////////////////////////////////
402 ////////////////////////////////////////////
404 void registerEditor (QWidget *);
405 void unregisterEditor (QWidget *);
408 QPointF contextPos; //!< local position during context menu
410 void setContextPos (QPointF); //!< local position during context menu
411 void unsetContextPos (); //!< forget local position after context menu
413 void updateNoteFlag(); //!< Signal origination in TextEditor
414 void updateRelPositions();
416 QRectF getTotalBBox();
417 void reposition(); //!< Call reposition for all MCOs
418 void setHideTmpMode (HideTmpMode mode);
420 QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree
421 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
423 //void ensureSelectionVisible(); //!< Show selection in all views
426 MapEditor *mapEditor;
428 QColor defLinkColor; // default color for links
429 QColor defXLinkColor; // default color for xlinks
430 int defXLinkWidth; // default width for xlinks
431 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
432 LinkableMapObj::Style linkstyle; // default style for links
438 void setMapLinkStyle (const QString &); // Set style of link
439 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
440 void setMapDefLinkColor(QColor); // default color of links
441 void setMapLinkColorHintInt(); // color of links
442 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
443 void toggleMapLinkColorHint(); // after changing linkStyles
444 void selectMapBackgroundImage();
445 void setMapBackgroundImage(const QString &);
446 void selectMapBackgroundColor();
447 void setMapBackgroundColor(QColor);
448 QColor getMapBackgroundColor();
451 LinkableMapObj::ColorHint getMapLinkColorHint();
452 QColor getMapDefLinkColor();
453 void setMapDefXLinkColor(QColor);
454 QColor getMapDefXLinkColor();
455 void setMapDefXLinkWidth (int);
456 int getMapDefXLinkWidth();
458 /*! Move absolutly to (x,y). */
459 void move (const double &x, const double &y);
461 /*! Move relativly to (x,y). */
462 void moveRel (const double &x, const double &y);
464 ////////////////////////////////////////////
465 // Animation **experimental**
466 ////////////////////////////////////////////
468 QTimer *animationTimer;
471 uint animationInterval;
472 int timerId; // animation timer
473 QList <MapObj*> animObjList;// list with animated objects
476 void animate(); //!< Called by timer to animate stuff
478 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
479 void stopAnimation(MapObj *mo);
481 ////////////////////////////////////////////
483 ////////////////////////////////////////////
485 /*! \brief Networking states
487 In Network modus we want to switch of saveState, autosave, ...
490 Offline, //!< Offline
491 Client, //!< I am the client and connected to server
492 Server //!< I am the server
496 // Network connections **Experimental**
497 NetState netstate; // offline, client, server
498 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
499 QList <QTcpSocket*> clientList; // List of connected clients
500 quint16 sendCounter; // Increased with every sent command
502 QTcpSocket *clientSocket; // socket of this client
503 QString server; // server address of this client
504 int port; // server port of this client
509 void sendSelection();
513 void connectToServer();
517 void sendData(const QString &s);
519 void displayNetworkError (QAbstractSocket::SocketError);
522 void displayClientError(QAbstractSocket::SocketError socketError);
525 ////////////////////////////////////////////
527 ////////////////////////////////////////////
530 QString latestSelectionString; // select string of latest added object
533 void setSelectionBlocked(bool);
534 bool isSelectionBlocked();
536 bool select(const QString &); // Select by string
537 bool select(LinkableMapObj *lmo); // Select by pointer
541 void ensureSelectionVisible(); //!< Show selection in all views
543 void selectInt(LinkableMapObj*);
546 void selectNextBranchInt(); // Increment number of branch
547 void selectPrevBranchInt(); // Decrement number of branch
549 void selectUpperBranch();
550 void selectLowerBranch();
551 void selectLeftBranch();
552 void selectRightBranch();
553 void selectFirstBranch();
554 void selectLastBranch();
557 Selection::Type selectionType();
558 LinkableMapObj* getSelection();
559 BranchObj* getSelectedBranch();
560 FloatImageObj* getSelectedFloatImage();
561 QString getSelectString ();
562 QString getSelectString (LinkableMapObj *lmo);
564 void updateSelection();
565 void selectMapLinkColor();
566 void selectMapSelectionColor();
568 void setSelectionColorInt(QColor);
570 void setSelectionColor(QColor);
571 QColor getSelectionColor();