4 #include <QGraphicsScene>
8 #include "mapcenterobj.h"
11 #include "selection.h"
13 #include "treemodel.h"
15 class VymModel : public TreeModel {
18 ////////////////////////////////////////////
19 // General housekeeping
20 ////////////////////////////////////////////
22 QGraphicsScene *mapScene;
23 QList <MapCenterObj*> mapCenters;
24 QString version; //!< version string saved in vym file
34 void makeTmpDirectories(); //!< create temporary directories e.g. for history
36 MapEditor* getMapEditor(); // FIXME not necessary
38 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
40 void updateActions(); //!< Update buttons in mainwindow
43 ////////////////////////////////////////////
45 ////////////////////////////////////////////
48 bool zipped; // should map be zipped
49 static int mapNum; // unique number for model used in save/undo
50 FileType fileType; // type of file, e.g. vym, freemind...
51 QString fileName; // short name of file (for tab)
52 QString filePath; // path to file which will be saved
53 QString fileDir; // dir where file is saved
54 QString destPath; // path to .vym file (needed for vymlinks)
55 QString mapName; // fileName without ".vym"
57 QString tmpMapDir; // tmp directory with undo history
59 QTimer *autosaveTimer;
60 QTimer *fileChangedTimer;
61 QDateTime fileChangedTime;
64 /*! This function saves all information of the map to disc.
65 saveToDir also calls the functions for all BranchObj and other objects in the map.
66 The structure of the map itself is returned as QString and passed back to Main,
67 where saveToDir is called initially
69 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
71 /*! \brief Sets filepath, filename and mapname
73 If the filepath is "/home/tux/map.xml", then the filename will be set
74 to map.xml. The destname is needed for vymLinks, pointing to another map.
75 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
79 /*! \brief Set File path
81 The destname is needed to construct the references between maps
83 void setFilePath (QString filepath,QString destname);
84 void setFilePath (QString); //!< Overloaded for convenience
85 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
86 QString getFileName (); //!< e.g. "map.xml"
87 QString getMapName (); //!< e.g. "map"
88 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
92 The data is read from file. Depending on LoadMode the current
93 selection gets replaced by data or the data is appended.
95 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
98 /*! \brief Save the map to file */
99 ErrorCode save(const SaveMode &);
102 void addMapReplaceInt(const QString & undoSel, const QString & path);
103 void addMapInsertInt (const QString & path, int pos);
105 FloatImageObj* loadFloatImageInt (QString);
106 void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
108 void loadFloatImage ();
109 void saveFloatImage ();
112 void importDirInt(BranchObj *,QDir);
113 void importDirInt(const QString&);
121 ////////////////////////////////////////////
122 // history (undo/redo)
123 ////////////////////////////////////////////
125 bool mapDefault; //!< Flag if map is untouched
126 bool mapChanged; //!< Flag if undo is possible
127 bool mapUnsaved; //!< Flag if map should be saved
129 QString histPath; //!< Path to history file
130 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
131 int stepsTotal; //!< total number of steps (undos+redos)
132 int curStep; //!< Current step in history (ring buffer)
133 int curClipboard; //!< number of history step, which is the current clipboard
134 int redosAvail; //!< Available number of redo steps
135 int undosAvail; //!< Available number of undo steps
136 bool blockReposition; //!< block while load or undo
137 bool blockSaveState; //!< block while load or undo
139 bool isDefault(); //!< true, if map is still the empty default map
140 void makeDefault(); //!< Reset changelog, declare this as default map
141 bool hasChanged() ; //!< true, if something has changed and is not saved yet
142 void setChanged(); //!< called from TextEditor via LinkableMapObj
144 /*! \brief Get name of object
146 Returns heading of a branch or name of an object for use in comment
149 QString getObjectName(const LinkableMapObj*);
151 void redo(); //!< Redo last action
152 bool isRedoAvailable(); //!< True, if redo is available
153 void undo(); //!< Undo last action
154 bool isUndoAvailable(); //!< True, if undo is available
155 void gotoHistoryStep (int); //!< Goto a specifig step in history
158 QString getHistoryPath(); //!< Path to directory containing the history
160 /*! \brief Save the current changes in map
162 Two commands and selections are saved:
164 - undocommand and undoselection to undo the change
165 - redocommand and redoselection to redo the action after an undo
167 Additionally a comment is logged.
171 const SaveMode& savemode,
172 const QString &undoSelection,
173 const QString &undoCommand,
174 const QString &redoSelection,
175 const QString &redoCommand,
176 const QString &comment,
177 LinkableMapObj *saveSelection);
178 /*! Overloaded for convenience */
179 void saveStateChangingPart(
180 LinkableMapObj *undoSelection,
181 LinkableMapObj* redoSelection,
182 const QString &redoCommand,
183 const QString &comment);
184 /*! Overloaded for convenience */
185 void saveStateRemovingPart(
186 LinkableMapObj *redoSelection,
187 const QString &comment);
188 /*! Overloaded for convenience */
190 LinkableMapObj *undoSelection,
191 const QString &undoCommand,
192 LinkableMapObj *redoSelection,
193 const QString &redoCommand,
194 const QString &comment);
195 /*! Overloaded for convenience */
197 const QString &undoSelection,
198 const QString &undoCommand,
199 const QString &redoSelection,
200 const QString &redoCommand,
201 const QString &comment) ;
203 const QString &undoCommand,
204 const QString &redoCommand,
205 const QString &comment) ;
208 ////////////////////////////////////////////
210 ////////////////////////////////////////////
212 void setScene(QGraphicsScene *s);
213 QGraphicsScene *getScene();
215 LinkableMapObj* findMapObj(QPointF,LinkableMapObj*); // find MapObj
216 LinkableMapObj* findObjBySelect (const QString &s); // find MapObj by select string
217 LinkableMapObj* findID (const QString &s); // find MapObj by previously set ID
219 QString saveToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
222 ////////////////////////////////////////////
224 ////////////////////////////////////////////
226 void setVersion(const QString &);
227 void setAuthor (const QString &);
228 QString getAuthor ();
229 void setComment (const QString &);
230 QString getComment ();
235 void setHeading(const QString &); //!< Set heading of branch
236 // QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
239 TreeItem* findCurrent; // next object in find process
240 TreeItem* findPrevious; // next object in find process
241 bool EOFind; // true, if search failed
243 BranchObj* findText(QString,bool); // Find object
244 void findReset(); // Reset Search
246 void setURL(const QString &url);
247 QString getURL(); // returns URL of selection or ""
248 QStringList getURLs(); // returns URLs of subtree
250 void linkFloatImageTo(const QString &);
252 void setFrameType(const FrameObj::FrameType &);
253 void setFrameType(const QString &);
254 void setFramePenColor (const QColor &);
255 void setFrameBrushColor (const QColor &);
256 void setFramePadding (const int &);
257 void setFrameBorderWidth (const int &);
258 void setIncludeImagesVer(bool);
259 void setIncludeImagesHor(bool);
260 void setHideLinkUnselected (bool);
262 /*! Should object be hidden in exports (clouded)? */
263 void setHideExport(bool);
265 /*! Should object be hidden in exports (clouded)? */
266 void toggleHideExport();
268 void copy(); //!< Copy to clipboard
270 void pasteNoSave(const int &n); //!< paste clipboard to branch
272 void paste(); //!< Paste clipboard to branch and backup
273 void cut(); //!< Cut to clipboard (and copy)
275 void moveBranchUp(); //!< Move branch up
276 void moveBranchDown(); //!< Move branch down
277 void sortChildren(); //!< Sort children lexically
279 // The create methods are used to quickly parse a XML file
280 void createMapCenter(); //!< Create and select MapCenter
281 void createBranch(); //!< Create and select Branch
282 TreeItem* createImage(); //!< Create and select image
284 /*! \brief Add new mapcenter
286 Disclaimer: Still experimental, not fully supported yet.
288 MapCenterObj* addMapCenter();
290 MapCenterObj* addMapCenter(QPointF absPos);
292 MapCenterObj* removeMapCenter(MapCenterObj *mco);
294 /*! \brief Add new branch
296 Depending on num the new branch is created
298 -3 above selection as child of selections parent
299 -2 as child of selection
300 -1 below selection as child of selections parent
301 0..n insert at a specific position in selections parent
302 (needed for free relinking)
304 MapCenterObj* getLastMapCenter(); //!< get last added MapCenter, used for context menu
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 *);
401 QPointF contextPos; //!< local position during context menu
403 void setContextPos (QPointF); //!< local position during context menu
404 void unsetContextPos (); //!< forget local position after context menu
406 void updateNoteFlag(); //!< Signal origination in TextEditor
407 void updateRelPositions();
409 QRectF getTotalBBox();
410 void reposition(); //!< Call reposition for all MCOs
411 void setHideTmpMode (HideTmpMode mode);
413 QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree
414 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
416 //void ensureSelectionVisible(); //!< Show selection in all views
419 MapEditor *mapEditor;
421 QColor defLinkColor; // default color for links
422 QColor defXLinkColor; // default color for xlinks
423 int defXLinkWidth; // default width for xlinks
424 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
425 LinkableMapObj::Style linkstyle; // default style for links
431 void setMapLinkStyle (const QString &); // Set style of link
432 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
433 void setMapDefLinkColor(QColor); // default color of links
434 void setMapLinkColorHintInt(); // color of links
435 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
436 void toggleMapLinkColorHint(); // after changing linkStyles
437 void selectMapBackgroundImage();
438 void setMapBackgroundImage(const QString &);
439 void selectMapBackgroundColor();
440 void setMapBackgroundColor(QColor);
441 QColor getMapBackgroundColor();
444 LinkableMapObj::ColorHint getMapLinkColorHint();
445 QColor getMapDefLinkColor();
446 void setMapDefXLinkColor(QColor);
447 QColor getMapDefXLinkColor();
448 void setMapDefXLinkWidth (int);
449 int getMapDefXLinkWidth();
451 /*! Move absolutly to (x,y). */
452 void move (const double &x, const double &y);
454 /*! Move relativly to (x,y). */
455 void moveRel (const double &x, const double &y);
457 ////////////////////////////////////////////
458 // Animation **experimental**
459 ////////////////////////////////////////////
461 QTimer *animationTimer;
464 uint animationInterval;
465 int timerId; // animation timer
466 QList <MapObj*> animObjList;// list with animated objects
469 void animate(); //!< Called by timer to animate stuff
471 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
472 void stopAnimation(MapObj *mo);
474 ////////////////////////////////////////////
476 ////////////////////////////////////////////
478 /*! \brief Networking states
480 In Network modus we want to switch of saveState, autosave, ...
483 Offline, //!< Offline
484 Client, //!< I am the client and connected to server
485 Server //!< I am the server
489 // Network connections **Experimental**
490 NetState netstate; // offline, client, server
491 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
492 QList <QTcpSocket*> clientList; // List of connected clients
493 quint16 sendCounter; // Increased with every sent command
495 QTcpSocket *clientSocket; // socket of this client
496 QString server; // server address of this client
497 int port; // server port of this client
502 void sendSelection();
506 void connectToServer();
510 void sendData(const QString &s);
512 void displayNetworkError (QAbstractSocket::SocketError);
515 void displayClientError(QAbstractSocket::SocketError socketError);
518 ////////////////////////////////////////////
520 ////////////////////////////////////////////
523 QString latestSelectionString; // select string of latest added object
526 void selectionChanged(const QItemSelection &, const QItemSelection &);
529 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
530 QItemSelectionModel* getSelectionModel();
532 void setSelectionBlocked(bool);
533 bool isSelectionBlocked();
535 bool select (); // select by using common QItemSlectionModel
536 bool select (const QString &); // Select by string
537 bool select (LinkableMapObj *lmo); // Select by pointer to LMO
538 bool select (TreeItem *ti ); // Select by point to TreeItem
542 void ensureSelectionVisible(); //!< Show selection in all views
544 void selectInt(LinkableMapObj*);
547 void selectNextBranchInt(); // Increment number of branch
548 void selectPrevBranchInt(); // Decrement number of branch
550 void selectUpperBranch();
551 void selectLowerBranch();
552 void selectLeftBranch();
553 void selectRightBranch();
554 void selectFirstBranch();
555 void selectLastBranch();
556 void selectLastSelectedBranch();
560 TreeItem::Type selectionType();
561 LinkableMapObj* getSelectedLMO();
562 BranchObj* getSelectedBranch();
563 TreeItem* getSelectedBranchItem();
564 TreeItem* getSelectedItem();
565 QModelIndex getSelectedIndex();
566 FloatImageObj* getSelectedFloatImage();
567 QString getSelectString ();
568 QString getSelectString (LinkableMapObj *lmo);
570 void updateSelection(const QItemSelection &oldsel);
571 void updateSelection();
572 void selectMapLinkColor();
573 void selectMapSelectionColor();
575 void setSelectionColorInt(QColor);
576 QItemSelectionModel *selModel;
579 void setSelectionColor(QColor);
580 QColor getSelectionColor();