4 #include <QGraphicsScene>
8 #include "mapcenterobj.h"
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 FloatImageObj* loadFloatImageInt (QString);
111 void saveFloatImageInt (FloatImageObj*, 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(const LinkableMapObj*);
155 QString getObjectName(const 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
253 void linkFloatImageTo(const QString &);
255 void setFrameType(const FrameObj::FrameType &);
256 void setFrameType(const QString &);
257 void setFramePenColor (const QColor &);
258 void setFrameBrushColor (const QColor &);
259 void setFramePadding (const int &);
260 void setFrameBorderWidth (const int &);
261 void setIncludeImagesVer(bool);
262 void setIncludeImagesHor(bool);
263 void setHideLinkUnselected (bool);
265 /*! Should object be hidden in exports (clouded)? */
266 void setHideExport(bool);
268 /*! Should object be hidden in exports (clouded)? */
269 void toggleHideExport();
271 void copy(); //!< Copy to clipboard
273 void pasteNoSave(const int &n); //!< paste clipboard to branch
275 void paste(); //!< Paste clipboard to branch and backup
276 void cut(); //!< Cut to clipboard (and copy)
278 void moveUp(); //!< Move branch up
279 void moveDown(); //!< Move branch down
280 void sortChildren(); //!< Sort children lexically
282 // The create methods are used to quickly parse a XML file
283 BranchItem* createMapCenter(); //!< Create and select MapCenter // FIXME-3 maybe join this also with createBranch
284 BranchItem* createBranch(); //!< Create and select Branch
285 TreeItem* createImage(); //!< Create and select image
287 /*! \brief Add new mapcenter
289 Disclaimer: Still experimental, not fully supported yet.
291 BranchItem* addMapCenter();
293 BranchItem* addMapCenter(QPointF absPos);
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)
307 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
311 Depending on num the new branch is created
313 0 as child of selection
316 BranchItem* addNewBranch(int pos);
317 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
318 /*! \brief Relink a branch to a new destination dst
319 Relinks branch to dst at branch position pos. There is no saveState
320 here, as for example moveUp or moving in MapEditor have
321 different needs to call saveState
322 Returns true if relinking was successful.
324 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
326 void deleteSelection(); //!< Delete selection
327 void deleteKeepChildren(); //!< remove branch, but keep children
328 void deleteChildren(); //!< keep branch, but remove children
331 bool scrollBranch(BranchItem *);
332 bool unscrollBranch(BranchItem *);
335 void unscrollChildren();
336 void emitExpandAll();
341 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
342 void addFloatImage(const QPixmap &img);
344 void colorBranch(QColor);
345 void colorSubtree(QColor);
346 QColor getCurrentHeadingColor();
349 void editURL(); // edit URL
350 void editLocalURL(); // edit URL to local file
351 void editHeading2URL(); // copy heading to URL
352 void editBugzilla2URL(); // create URL to Bugzilla
353 void editFATE2URL(); // create URL to FATE
354 void editVymLink(); // edit link to another map
355 void setVymLink (const QString &); // Set vymLink for selection
356 void deleteVymLink(); // delete link to another map
357 QString getVymLink(); // return path to map
358 QStringList getVymLinks(); // return paths in subtree
359 void followXLink (int);
360 void editXLink (int);
365 ////////////////////////////////////////////
367 ////////////////////////////////////////////
370 /* \brief Process one command and its parameters */
371 void parseAtom (const QString &atom);
373 /* \brief Runs the script */
374 void runScript (QString script);
379 ////////////////////////////////////////////
381 ////////////////////////////////////////////
383 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
386 /*! Set or unset temporary hiding of objects during export */
387 void setExportMode (bool);
390 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
393 /*! Export as XTML to directory */
394 void exportXML(QString dir="", bool askForName=true);
396 /*! Export as ASCII text to file */
397 void exportASCII (QString fname="",bool askForName=true);
399 /*! Export as XHTML to directory */
400 void exportXHTML(const QString& dir="", bool askForName=true);
402 /*! Export as OpenOfficeOrg presentation */
403 void exportOOPresentation(const QString &,const QString &);
406 ////////////////////////////////////////////
408 ////////////////////////////////////////////
410 void registerEditor (QWidget *);
411 void unregisterEditor (QWidget *);
414 QPointF contextPos; //!< local position during context menu
416 void setContextPos (QPointF); //!< local position during context menu
417 void unsetContextPos (); //!< forget local position after context menu
419 void updateNoteFlag(); //!< Signal origination in TextEditor
420 void updateRelPositions();
422 QRectF getTotalBBox();
423 void reposition(); //!< Call reposition for all MCOs
424 void setHideTmpMode (TreeItem::HideTmpMode mode);
426 //FIXME-5 QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree
427 //FIXME-5 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
429 void emitNoteHasChanged (TreeItem *ti);
430 void emitDataHasChanged (TreeItem *ti);
433 void noteHasChanged (QModelIndex ix);
434 void newChildObject(QModelIndex ix);
437 MapEditor *mapEditor;
439 QColor defLinkColor; // default color for links
440 QColor defXLinkColor; // default color for xlinks
441 int defXLinkWidth; // default width for xlinks
442 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
443 LinkableMapObj::Style linkstyle; // default style for links
449 void setMapLinkStyle (const QString &); // Set style of link
450 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
451 void setMapDefLinkColor(QColor); // default color of links
452 void setMapLinkColorHintInt(); // color of links
453 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
454 void toggleMapLinkColorHint(); // after changing linkStyles
455 void selectMapBackgroundImage();
456 void setMapBackgroundImage(const QString &);
457 void selectMapBackgroundColor();
458 void setMapBackgroundColor(QColor);
459 QColor getMapBackgroundColor();
462 LinkableMapObj::ColorHint getMapLinkColorHint();
463 QColor getMapDefLinkColor();
464 void setMapDefXLinkColor(QColor);
465 QColor getMapDefXLinkColor();
466 void setMapDefXLinkWidth (int);
467 int getMapDefXLinkWidth();
469 /*! Move absolutly to (x,y). */
470 void move (const double &x, const double &y);
472 /*! Move relativly to (x,y). */
473 void moveRel (const double &x, const double &y);
475 ////////////////////////////////////////////
476 // Animation **experimental**
477 ////////////////////////////////////////////
479 QTimer *animationTimer;
482 uint animationInterval;
483 int timerId; // animation timer
484 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
487 void animate(); //!< Called by timer to animate stuff
489 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
490 void stopAnimation(MapObj *mo);
492 ////////////////////////////////////////////
494 ////////////////////////////////////////////
496 /*! \brief Networking states
498 In Network modus we want to switch of saveState, autosave, ...
501 Offline, //!< Offline
502 Client, //!< I am the client and connected to server
503 Server //!< I am the server
507 // Network connections **Experimental**
508 NetState netstate; // offline, client, server
509 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
510 QList <QTcpSocket*> clientList; // List of connected clients
511 quint16 sendCounter; // Increased with every sent command
513 QTcpSocket *clientSocket; // socket of this client
514 QString server; // server address of this client
515 int port; // server port of this client
520 void sendSelection();
524 void connectToServer();
528 void sendData(const QString &s);
530 void displayNetworkError (QAbstractSocket::SocketError);
533 void displayClientError(QAbstractSocket::SocketError socketError);
536 ////////////////////////////////////////////
538 ////////////////////////////////////////////
540 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
543 void selectionChanged(const QItemSelection &, const QItemSelection &);
546 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
547 QItemSelectionModel* getSelectionModel();
549 void setSelectionBlocked(bool);
550 bool isSelectionBlocked();
552 bool select (); //! select by using common QItemSelectionModel
553 bool select (const QString &); //! Select by string
554 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
555 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
556 bool select (const QModelIndex &index); //! Select by ModelIndex
560 void emitShowSelection(); //!< Show selection in all views
562 void showSelection();
564 // void selectInt(LinkableMapObj*); //FIXME-4
567 void selectNextBranchInt(); // Increment number of branch
568 void selectPrevBranchInt(); //! Select the branch which would be above in vymmap view
569 void selectAboveBranchInt(); //! Select the branch which would be above current selection in TreeView
570 void selectBelowBranchInt(); // Increment number of branch
572 void selectUpperBranch();
573 void selectLowerBranch();
574 void selectLeftBranch();
575 void selectRightBranch();
576 void selectFirstBranch();
577 void selectLastBranch();
578 void selectLastSelectedBranch();
582 TreeItem::Type selectionType();
583 LinkableMapObj* getSelectedLMO();
584 BranchObj* getSelectedBranchObj(); // FIXME-2 replace by item...
585 BranchItem* getSelectedBranchItem();
586 TreeItem* getSelectedItem();
587 QModelIndex getSelectedIndex();
588 FloatImageObj* getSelectedFloatImage();
589 QString getSelectString ();
590 QString getSelectString (LinkableMapObj *lmo);
591 QString getSelectString (TreeItem *item);
596 void changeSelection (const QItemSelection &newSel, const QItemSelection &delSel);
600 void updateSelection(const QItemSelection &oldsel);
601 void updateSelection();
602 void selectMapLinkColor();
603 void selectMapSelectionColor();
605 void setSelectionColorInt(QColor);
606 QItemSelectionModel *selModel;
607 QString lastSelectString;
608 bool selectionBlocked; //! Used to block changes of selection while editing a heading
611 void setSelectionColor(QColor);
612 QColor getSelectionColor();