4 #include <QGraphicsScene>
12 #include "treemodel.h"
17 class VymModel : public TreeModel {
20 ////////////////////////////////////////////
21 // General housekeeping
22 ////////////////////////////////////////////
24 QGraphicsScene *mapScene;
25 QString version; //!< version string saved in vym file
35 void makeTmpDirectories(); //!< create temporary directories e.g. for history
37 MapEditor* getMapEditor(); // FIXME-2 still necessary?
39 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
41 void updateActions(); //!< Update buttons in mainwindow
44 ////////////////////////////////////////////
46 ////////////////////////////////////////////
49 bool zipped; // should map be zipped
50 static int mapNum; // unique number for model used in save/undo
51 FileType fileType; // type of file, e.g. vym, freemind...
52 QString fileName; // short name of file (for tab)
53 QString filePath; // path to file which will be saved
54 QString fileDir; // dir where file is saved
55 QString destPath; // path to .vym file (needed for vymlinks)
56 QString mapName; // fileName without ".vym"
58 QString tmpMapDir; // tmp directory with undo history
60 QTimer *autosaveTimer;
61 QTimer *fileChangedTimer;
62 QDateTime fileChangedTime;
65 /*! This function saves all information of the map to disc.
66 saveToDir also calls the functions for all BranchObj and other objects in the map.
67 The structure of the map itself is returned as QString and passed back to Main,
68 where saveToDir is called initially
70 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel);
72 /*! Save all data in tree*/
73 QString saveTreeToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
76 /*! \brief Sets filepath, filename and mapname
78 If the filepath is "/home/tux/map.xml", then the filename will be set
79 to map.xml. The destname is needed for vymLinks, pointing to another map.
80 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
84 /*! \brief Set File path
86 The destname is needed to construct the references between maps
88 void setFilePath (QString filepath,QString destname);
89 void setFilePath (QString); //!< Overloaded for convenience
90 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
91 QString getFileName (); //!< e.g. "map.xml"
92 QString getMapName (); //!< e.g. "map"
93 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
97 The data is read from file. Depending on LoadMode the current
98 selection gets replaced by data or the data is appended.
100 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
103 /*! \brief Save the map to file */
104 ErrorCode save(const SaveMode &);
107 void addMapReplaceInt(const QString & undoSel, const QString & path);
108 void addMapInsertInt (const QString & path, int pos);
110 ImageItem* loadFloatImageInt (BranchItem *dst,QString);
111 void saveFloatImageInt (ImageItem*, const QString &, const QString &);
113 void loadFloatImage ();
114 void saveFloatImage ();
117 void importDirInt(BranchObj *,QDir);
118 void importDirInt(const QString&);
126 ////////////////////////////////////////////
127 // history (undo/redo)
128 ////////////////////////////////////////////
130 bool mapDefault; //!< Flag if map is untouched
131 bool mapChanged; //!< Flag if undo is possible
132 bool mapUnsaved; //!< Flag if map should be saved
134 QString histPath; //!< Path to history file
135 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
136 int stepsTotal; //!< total number of steps (undos+redos)
137 int curStep; //!< Current step in history (ring buffer)
138 int curClipboard; //!< number of history step, which is the current clipboard
139 int redosAvail; //!< Available number of redo steps
140 int undosAvail; //!< Available number of undo steps
141 bool blockReposition; //!< block while load or undo
142 bool blockSaveState; //!< block while load or undo
144 bool isDefault(); //!< true, if map is still the empty default map
145 void makeDefault(); //!< Reset changelog, declare this as default map
146 bool hasChanged() ; //!< true, if something has changed and is not saved yet
147 void setChanged(); //!< called from TextEditor via LinkableMapObj
149 /*! \brief Get name of object
151 Returns heading of a branch or name of an object for use in comment
154 QString getObjectName(LinkableMapObj*);
155 QString getObjectName(TreeItem*);
157 void redo(); //!< Redo last action
158 bool isRedoAvailable(); //!< True, if redo is available
159 void undo(); //!< Undo last action
160 bool isUndoAvailable(); //!< True, if undo is available
161 void gotoHistoryStep (int); //!< Goto a specifig step in history
164 QString getHistoryPath(); //!< Path to directory containing the history
166 /*! \brief Save the current changes in map
168 Two commands and selections are saved:
170 - undocommand and undoselection to undo the change
171 - redocommand and redoselection to redo the action after an undo
173 Additionally a comment is logged.
177 const SaveMode& savemode,
178 const QString &undoSelection,
179 const QString &undoCommand,
180 const QString &redoSelection,
181 const QString &redoCommand,
182 const QString &comment,
183 TreeItem *saveSelection);
184 /*! Overloaded for convenience */
185 void saveStateChangingPart(
186 TreeItem *undoSelection,
187 TreeItem* redoSelection,
188 const QString &redoCommand,
189 const QString &comment);
190 /*! Overloaded for convenience */
191 void saveStateRemovingPart(
192 TreeItem *redoSelection,
193 const QString &comment);
194 /*! Overloaded for convenience */
196 TreeItem *undoSelection,
197 const QString &undoCommand,
198 TreeItem *redoSelection,
199 const QString &redoCommand,
200 const QString &comment);
201 /*! Overloaded for convenience */
203 const QString &undoSelection,
204 const QString &undoCommand,
205 const QString &redoSelection,
206 const QString &redoCommand,
207 const QString &comment) ;
209 const QString &undoCommand,
210 const QString &redoCommand,
211 const QString &comment) ;
214 ////////////////////////////////////////////
216 ////////////////////////////////////////////
218 void setScene(QGraphicsScene *s);
219 QGraphicsScene *getScene();
221 TreeItem* findBySelectString (QString s);
222 TreeItem* findID (const QString &s); // find MapObj by previously set ID
225 ////////////////////////////////////////////
227 ////////////////////////////////////////////
229 void setVersion(const QString &);
230 void setAuthor (const QString &);
231 QString getAuthor ();
232 void setComment (const QString &);
233 QString getComment ();
238 void setHeading(const QString &); //!< Set heading of branch
239 // QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
242 BranchItem* findCurrent; // next object in find process
243 BranchItem* findPrevious; // next object in find process
244 bool EOFind; // true, if search failed
246 BranchItem* findText(QString,bool); // Find object
247 void findReset(); // Reset Search
249 void setURL(const QString &url);
250 QString getURL(); // returns URL of selection or ""
251 QStringList getURLs(); // returns URLs of subtree
254 void setFrameType(const FrameObj::FrameType &);
255 void setFrameType(const QString &);
256 void setFramePenColor (const QColor &);
257 void setFrameBrushColor (const QColor &);
258 void setFramePadding (const int &);
259 void setFrameBorderWidth (const int &);
260 void setIncludeImagesVer(bool);
261 void setIncludeImagesHor(bool);
262 void setHideLinkUnselected (bool);
264 /*! Should object be hidden in exports (clouded)? */
265 void setHideExport(bool);
267 /*! Should object be hidden in exports (clouded)? */
268 void toggleHideExport();
270 void copy(); //!< Copy to clipboard
272 void pasteNoSave(const int &n); //!< paste clipboard to branch
274 void paste(); //!< Paste clipboard to branch and backup
275 void cut(); //!< Cut to clipboard (and copy)
277 void moveUp(); //!< Move branch up
278 void moveDown(); //!< Move branch down
279 void sortChildren(); //!< Sort children lexically
281 // The create methods are used to quickly parse a XML file
282 BranchItem* createMapCenter(); //!< Create MapCenter
283 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
284 ImageItem* createImage(BranchItem *dst); //!< Create image
286 /*! \brief Add new mapcenter
288 Disclaimer: Still experimental, not fully supported yet.
290 BranchItem* addMapCenter();
292 BranchItem* addMapCenter(QPointF absPos);
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)
306 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
310 Depending on num the new branch is created
312 0 as child of selection
315 BranchItem* addNewBranch(int pos=0);
316 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
317 /*! \brief Relink a branch to a new destination dst
318 Relinks branch to dst at branch position pos. There is no saveState
319 here, as for example moveUp or moving in MapEditor have
320 different needs to call saveState
321 Returns true if relinking was successful.
323 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
324 bool relinkImage (ImageItem* image, BranchItem* dst);
326 void deleteSelection(); //!< Delete selection
327 void deleteKeepChildren(); //!< remove branch, but keep children
328 void deleteChildren(); //!< keep branch, but remove children
331 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
332 bool scrollBranch(BranchItem *);
333 bool unscrollBranch(BranchItem *);
336 void unscrollChildren();
337 void emitExpandAll();
342 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
343 void addFloatImage(const QPixmap &img);
345 void colorBranch(QColor);
346 void colorSubtree(QColor);
347 QColor getCurrentHeadingColor();
350 void editURL(); // edit URL
351 void editLocalURL(); // edit URL to local file
352 void editHeading2URL(); // copy heading to URL
353 void editBugzilla2URL(); // create URL to Bugzilla
354 void editFATE2URL(); // create URL to FATE
355 void editVymLink(); // edit link to another map
356 void setVymLink (const QString &); // Set vymLink for selection
357 void deleteVymLink(); // delete link to another map
358 QString getVymLink(); // return path to map
359 QStringList getVymLinks(); // return paths in subtree
360 void followXLink (int);
361 void editXLink (int);
366 ////////////////////////////////////////////
368 ////////////////////////////////////////////
371 /* \brief Process one command and its parameters */
372 void parseAtom (const QString &atom);
374 /* \brief Runs the script */
375 void runScript (QString script);
380 ////////////////////////////////////////////
382 ////////////////////////////////////////////
384 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
387 /*! Set or unset temporary hiding of objects during export */
388 void setExportMode (bool);
391 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
394 /*! Export as XTML to directory */
395 void exportXML(QString dir="", bool askForName=true);
397 /*! Export as ASCII text to file */
398 void exportASCII (QString fname="",bool askForName=true);
400 /*! Export as XHTML to directory */
401 void exportXHTML(const QString& dir="", bool askForName=true);
403 /*! Export as OpenOfficeOrg presentation */
404 void exportOOPresentation(const QString &,const QString &);
407 ////////////////////////////////////////////
409 ////////////////////////////////////////////
411 void registerEditor (QWidget *);
412 void unregisterEditor (QWidget *);
415 QPointF contextPos; //!< local position during context menu
417 void setContextPos (QPointF); //!< local position during context menu
418 void unsetContextPos (); //!< forget local position after context menu
420 void updateNoteFlag(); //!< Signal origination in TextEditor
421 void updateRelPositions();
423 QRectF getTotalBBox();
424 void reposition(); //!< Call reposition for all MCOs
425 void setHideTmpMode (TreeItem::HideTmpMode mode);
427 //FIXME-5 QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree
428 //FIXME-5 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
430 void emitNoteHasChanged (TreeItem *ti);
431 void emitDataHasChanged (TreeItem *ti);
434 void noteHasChanged (QModelIndex ix);
435 void newChildObject(QModelIndex ix);
438 MapEditor *mapEditor;
440 QColor defLinkColor; // default color for links
441 QColor defXLinkColor; // default color for xlinks
442 int defXLinkWidth; // default width for xlinks
443 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
444 LinkableMapObj::Style linkstyle; // default style for links
450 void setMapLinkStyle (const QString &); // Set style of link
451 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
452 void setMapDefLinkColor(QColor); // default color of links
453 void setMapLinkColorHintInt(); // color of links
454 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
455 void toggleMapLinkColorHint(); // after changing linkStyles
456 void selectMapBackgroundImage();
457 void setMapBackgroundImage(const QString &);
458 void selectMapBackgroundColor();
459 void setMapBackgroundColor(QColor);
460 QColor getMapBackgroundColor();
463 LinkableMapObj::ColorHint getMapLinkColorHint();
464 QColor getMapDefLinkColor();
465 void setMapDefXLinkColor(QColor);
466 QColor getMapDefXLinkColor();
467 void setMapDefXLinkWidth (int);
468 int getMapDefXLinkWidth();
470 /*! Move absolutly to (x,y). */
471 void move (const double &x, const double &y);
473 /*! Move relativly to (x,y). */
474 void moveRel (const double &x, const double &y);
476 ////////////////////////////////////////////
477 // Animation **experimental**
478 ////////////////////////////////////////////
480 QTimer *animationTimer;
483 uint animationInterval;
484 int timerId; // animation timer
485 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
488 void animate(); //!< Called by timer to animate stuff
490 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
491 void stopAnimation(MapObj *mo);
493 ////////////////////////////////////////////
495 ////////////////////////////////////////////
497 /*! \brief Networking states
499 In Network modus we want to switch of saveState, autosave, ...
502 Offline, //!< Offline
503 Client, //!< I am the client and connected to server
504 Server //!< I am the server
508 // Network connections **Experimental**
509 NetState netstate; // offline, client, server
510 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
511 QList <QTcpSocket*> clientList; // List of connected clients
512 quint16 sendCounter; // Increased with every sent command
514 QTcpSocket *clientSocket; // socket of this client
515 QString server; // server address of this client
516 int port; // server port of this client
521 void sendSelection();
525 void connectToServer();
529 void sendData(const QString &s);
531 void displayNetworkError (QAbstractSocket::SocketError);
534 void displayClientError(QAbstractSocket::SocketError socketError);
537 ////////////////////////////////////////////
539 ////////////////////////////////////////////
541 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
544 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
545 QItemSelectionModel* getSelectionModel();
547 void setSelectionBlocked(bool);
548 bool isSelectionBlocked();
550 bool select (); //! select by using common QItemSelectionModel
551 bool select (const QString &); //! Select by string
552 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
553 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
554 bool select (const QModelIndex &index); //! Select by ModelIndex
558 void emitShowSelection(); //!< Show selection in all views
560 void showSelection();
562 // void selectInt(LinkableMapObj*); //FIXME-4
565 void selectNextBranchInt(); // Increment number of branch
566 void selectPrevBranchInt(); //! Select the branch which would be above in vymmap view
567 void selectAboveBranchInt(); //! Select the branch which would be above current selection in TreeView
568 void selectBelowBranchInt(); // Increment number of branch
570 void selectUpperBranch();
571 void selectLowerBranch();
572 void selectLeftBranch();
573 void selectRightBranch();
574 void selectFirstBranch();
575 void selectLastBranch();
576 void selectLastSelectedBranch();
580 TreeItem::Type selectionType();
581 LinkableMapObj* getSelectedLMO();
582 BranchObj* getSelectedBranchObj(); // FIXME-3 replace by item...
583 BranchItem* getSelectedBranchItem();
584 TreeItem* getSelectedItem();
585 QModelIndex getSelectedIndex();
586 ImageItem* getSelectedImageItem();
587 QString getSelectString ();
588 QString getSelectString (LinkableMapObj *lmo);
589 QString getSelectString (TreeItem *item);
593 void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
596 void updateSelection (const QItemSelection &newSel, const QItemSelection &delSel);
599 void emitSelectionChanged(const QItemSelection &oldsel);
600 void emitSelectionChanged();
601 void selectMapLinkColor();
602 void selectMapSelectionColor();
604 void setSelectionColorInt(QColor);
605 QItemSelectionModel *selModel;
606 QString lastSelectString;
607 bool selectionBlocked; //! Used to block changes of selection while editing a heading
610 void setSelectionColor(QColor);
611 QColor getSelectionColor();