4 #include <QGraphicsScene>
8 #include "mapcenterobj.h"
11 #include "selection.h"
13 #include "treemodel.h"
19 class VymModel : public TreeModel {
22 ////////////////////////////////////////////
23 // General housekeeping
24 ////////////////////////////////////////////
26 QGraphicsScene *mapScene;
27 QString version; //!< version string saved in vym file
37 void makeTmpDirectories(); //!< create temporary directories e.g. for history
39 MapEditor* getMapEditor(); // FIXME-2 still 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, TreeItem *saveSel);
74 /*! Save all data in tree*/
75 QString saveTreeToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
78 /*! \brief Sets filepath, filename and mapname
80 If the filepath is "/home/tux/map.xml", then the filename will be set
81 to map.xml. The destname is needed for vymLinks, pointing to another map.
82 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
86 /*! \brief Set File path
88 The destname is needed to construct the references between maps
90 void setFilePath (QString filepath,QString destname);
91 void setFilePath (QString); //!< Overloaded for convenience
92 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
93 QString getFileName (); //!< e.g. "map.xml"
94 QString getMapName (); //!< e.g. "map"
95 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
99 The data is read from file. Depending on LoadMode the current
100 selection gets replaced by data or the data is appended.
102 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
105 /*! \brief Save the map to file */
106 ErrorCode save(const SaveMode &);
109 void addMapReplaceInt(const QString & undoSel, const QString & path);
110 void addMapInsertInt (const QString & path, int pos);
112 FloatImageObj* loadFloatImageInt (QString);
113 void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
115 void loadFloatImage ();
116 void saveFloatImage ();
119 void importDirInt(BranchObj *,QDir);
120 void importDirInt(const QString&);
128 ////////////////////////////////////////////
129 // history (undo/redo)
130 ////////////////////////////////////////////
132 bool mapDefault; //!< Flag if map is untouched
133 bool mapChanged; //!< Flag if undo is possible
134 bool mapUnsaved; //!< Flag if map should be saved
136 QString histPath; //!< Path to history file
137 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
138 int stepsTotal; //!< total number of steps (undos+redos)
139 int curStep; //!< Current step in history (ring buffer)
140 int curClipboard; //!< number of history step, which is the current clipboard
141 int redosAvail; //!< Available number of redo steps
142 int undosAvail; //!< Available number of undo steps
143 bool blockReposition; //!< block while load or undo
144 bool blockSaveState; //!< block while load or undo
146 bool isDefault(); //!< true, if map is still the empty default map
147 void makeDefault(); //!< Reset changelog, declare this as default map
148 bool hasChanged() ; //!< true, if something has changed and is not saved yet
149 void setChanged(); //!< called from TextEditor via LinkableMapObj
151 /*! \brief Get name of object
153 Returns heading of a branch or name of an object for use in comment
156 QString getObjectName(const LinkableMapObj*);
157 QString getObjectName(const TreeItem*);
159 void redo(); //!< Redo last action
160 bool isRedoAvailable(); //!< True, if redo is available
161 void undo(); //!< Undo last action
162 bool isUndoAvailable(); //!< True, if undo is available
163 void gotoHistoryStep (int); //!< Goto a specifig step in history
166 QString getHistoryPath(); //!< Path to directory containing the history
168 /*! \brief Save the current changes in map
170 Two commands and selections are saved:
172 - undocommand and undoselection to undo the change
173 - redocommand and redoselection to redo the action after an undo
175 Additionally a comment is logged.
179 const SaveMode& savemode,
180 const QString &undoSelection,
181 const QString &undoCommand,
182 const QString &redoSelection,
183 const QString &redoCommand,
184 const QString &comment,
185 TreeItem *saveSelection);
186 /*! Overloaded for convenience */
187 void saveStateChangingPart(
188 TreeItem *undoSelection,
189 TreeItem* redoSelection,
190 const QString &redoCommand,
191 const QString &comment);
192 /*! Overloaded for convenience */
193 void saveStateRemovingPart(
194 TreeItem *redoSelection,
195 const QString &comment);
196 /*! Overloaded for convenience */
198 TreeItem *undoSelection,
199 const QString &undoCommand,
200 TreeItem *redoSelection,
201 const QString &redoCommand,
202 const QString &comment);
203 /*! Overloaded for convenience */
205 const QString &undoSelection,
206 const QString &undoCommand,
207 const QString &redoSelection,
208 const QString &redoCommand,
209 const QString &comment) ;
211 const QString &undoCommand,
212 const QString &redoCommand,
213 const QString &comment) ;
216 ////////////////////////////////////////////
218 ////////////////////////////////////////////
220 void setScene(QGraphicsScene *s);
221 QGraphicsScene *getScene();
223 TreeItem* findBySelectString (QString s);
224 TreeItem* findID (const QString &s); // find MapObj by previously set ID
227 ////////////////////////////////////////////
229 ////////////////////////////////////////////
231 void setVersion(const QString &);
232 void setAuthor (const QString &);
233 QString getAuthor ();
234 void setComment (const QString &);
235 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
244 BranchItem* findCurrent; // next object in find process
245 BranchItem* findPrevious; // next object in find process
246 bool EOFind; // true, if search failed
248 BranchItem* findText(QString,bool); // Find object
249 void findReset(); // Reset Search
251 void setURL(const QString &url);
252 QString getURL(); // returns URL of selection or ""
253 QStringList getURLs(); // returns URLs of subtree
255 void linkFloatImageTo(const QString &);
257 void setFrameType(const FrameObj::FrameType &);
258 void setFrameType(const QString &);
259 void setFramePenColor (const QColor &);
260 void setFrameBrushColor (const QColor &);
261 void setFramePadding (const int &);
262 void setFrameBorderWidth (const int &);
263 void setIncludeImagesVer(bool);
264 void setIncludeImagesHor(bool);
265 void setHideLinkUnselected (bool);
267 /*! Should object be hidden in exports (clouded)? */
268 void setHideExport(bool);
270 /*! Should object be hidden in exports (clouded)? */
271 void toggleHideExport();
273 void copy(); //!< Copy to clipboard
275 void pasteNoSave(const int &n); //!< paste clipboard to branch
277 void paste(); //!< Paste clipboard to branch and backup
278 void cut(); //!< Cut to clipboard (and copy)
280 void moveUp(); //!< Move branch up
281 void moveDown(); //!< Move branch down
282 void sortChildren(); //!< Sort children lexically
284 // The create methods are used to quickly parse a XML file
285 MapCenterItem* createMapCenter(); //!< Create and select MapCenter
286 BranchItem* createBranch(); //!< Create and select Branch
287 TreeItem* createImage(); //!< Create and select image
289 /*! \brief Add new mapcenter
291 Disclaimer: Still experimental, not fully supported yet.
293 MapCenterItem* addMapCenter();
295 MapCenterItem* addMapCenter(QPointF absPos);
297 /*! \brief Add new branch
299 Depending on num the new branch is created
301 -3 above selection as child of selections parent
302 -2 as child of selection
303 -1 below selection as child of selections parent
304 0..n insert at a specific position in selections parent
305 (needed for free relinking)
309 BranchItem* addNewBranchInt(int); // pos allows to add above/below selection
313 Depending on num the new branch is created
315 0 as child of selection
318 BranchItem* addNewBranch(int pos);
319 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
320 /*! \brief Relink a branch to a new destination dst
321 Relinks branch to dst at branch position pos. There is no saveState
322 here, as for example moveUp or moving in MapEditor have
323 different needs to call saveState
324 Returns true if relinking was successful.
326 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
328 void deleteSelection(); //!< Delete selection
329 void deleteKeepChildren(); //!< remove branch, but keep children
330 void deleteChildren(); //!< keep branch, but remove children
333 bool scrollBranch(BranchItem *);
334 bool unscrollBranch(BranchItem *);
337 void unscrollChildren();
338 void emitExpandAll();
343 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
344 void addFloatImage(const QPixmap &img);
346 void colorBranch(QColor);
347 void colorSubtree(QColor);
348 QColor getCurrentHeadingColor();
351 void editURL(); // edit URL
352 void editLocalURL(); // edit URL to local file
353 void editHeading2URL(); // copy heading to URL
354 void editBugzilla2URL(); // create URL to Bugzilla
355 void editFATE2URL(); // create URL to FATE
356 void editVymLink(); // edit link to another map
357 void setVymLink (const QString &); // Set vymLink for selection
358 void deleteVymLink(); // delete link to another map
359 QString getVymLink(); // return path to map
360 QStringList getVymLinks(); // return paths in subtree
361 void followXLink (int);
362 void editXLink (int);
367 ////////////////////////////////////////////
369 ////////////////////////////////////////////
372 /* \brief Process one command and its parameters */
373 void parseAtom (const QString &atom);
375 /* \brief Runs the script */
376 void runScript (QString script);
381 ////////////////////////////////////////////
383 ////////////////////////////////////////////
385 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
388 /*! Set or unset temporary hiding of objects during export */
389 void setExportMode (bool);
392 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
395 /*! Export as XTML to directory */
396 void exportXML(QString dir="", bool askForName=true);
398 /*! Export as ASCII text to file */
399 void exportASCII (QString fname="",bool askForName=true);
401 /*! Export as XHTML to directory */
402 void exportXHTML(const QString& dir="", bool askForName=true);
404 /*! Export as OpenOfficeOrg presentation */
405 void exportOOPresentation(const QString &,const QString &);
408 ////////////////////////////////////////////
410 ////////////////////////////////////////////
412 void registerEditor (QWidget *);
413 void unregisterEditor (QWidget *);
416 QPointF contextPos; //!< local position during context menu
418 void setContextPos (QPointF); //!< local position during context menu
419 void unsetContextPos (); //!< forget local position after context menu
421 void updateNoteFlag(); //!< Signal origination in TextEditor
422 void updateRelPositions();
424 QRectF getTotalBBox();
425 void reposition(); //!< Call reposition for all MCOs
426 void setHideTmpMode (TreeItem::HideTmpMode mode);
428 QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree
429 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
431 void emitNoteHasChanged (TreeItem *ti);
432 void emitDataHasChanged (TreeItem *ti);
435 void noteHasChanged (QModelIndex ix);
436 void newChildObject(QModelIndex ix);
439 MapEditor *mapEditor;
441 QColor defLinkColor; // default color for links
442 QColor defXLinkColor; // default color for xlinks
443 int defXLinkWidth; // default width for xlinks
444 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
445 LinkableMapObj::Style linkstyle; // default style for links
451 void setMapLinkStyle (const QString &); // Set style of link
452 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
453 void setMapDefLinkColor(QColor); // default color of links
454 void setMapLinkColorHintInt(); // color of links
455 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
456 void toggleMapLinkColorHint(); // after changing linkStyles
457 void selectMapBackgroundImage();
458 void setMapBackgroundImage(const QString &);
459 void selectMapBackgroundColor();
460 void setMapBackgroundColor(QColor);
461 QColor getMapBackgroundColor();
464 LinkableMapObj::ColorHint getMapLinkColorHint();
465 QColor getMapDefLinkColor();
466 void setMapDefXLinkColor(QColor);
467 QColor getMapDefXLinkColor();
468 void setMapDefXLinkWidth (int);
469 int getMapDefXLinkWidth();
471 /*! Move absolutly to (x,y). */
472 void move (const double &x, const double &y);
474 /*! Move relativly to (x,y). */
475 void moveRel (const double &x, const double &y);
477 ////////////////////////////////////////////
478 // Animation **experimental**
479 ////////////////////////////////////////////
481 QTimer *animationTimer;
484 uint animationInterval;
485 int timerId; // animation timer
486 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
489 void animate(); //!< Called by timer to animate stuff
491 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
492 void stopAnimation(MapObj *mo);
494 ////////////////////////////////////////////
496 ////////////////////////////////////////////
498 /*! \brief Networking states
500 In Network modus we want to switch of saveState, autosave, ...
503 Offline, //!< Offline
504 Client, //!< I am the client and connected to server
505 Server //!< I am the server
509 // Network connections **Experimental**
510 NetState netstate; // offline, client, server
511 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
512 QList <QTcpSocket*> clientList; // List of connected clients
513 quint16 sendCounter; // Increased with every sent command
515 QTcpSocket *clientSocket; // socket of this client
516 QString server; // server address of this client
517 int port; // server port of this client
522 void sendSelection();
526 void connectToServer();
530 void sendData(const QString &s);
532 void displayNetworkError (QAbstractSocket::SocketError);
535 void displayClientError(QAbstractSocket::SocketError socketError);
538 ////////////////////////////////////////////
540 ////////////////////////////////////////////
543 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
546 void selectionChanged(const QItemSelection &, const QItemSelection &);
549 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
550 QItemSelectionModel* getSelectionModel();
552 void setSelectionBlocked(bool);
553 bool isSelectionBlocked();
555 bool select (); // select by using common QItemSlectionModel
556 bool select (const QString &); // Select by string
557 bool select (LinkableMapObj *lmo); // Select by pointer tog LMO
558 bool select (TreeItem *ti ); // Select by point to TreeItem
562 void emitShowSelection(); //!< Show selection in all views
564 void showSelection();
566 // void selectInt(LinkableMapObj*); //FIXME-4
569 void selectNextBranchInt(); // Increment number of branch
570 void selectPrevBranchInt(); //! Select the branch which would be above in vymmap view
571 void selectAboveBranchInt(); //! Select the branch which would be above current selection in TreeView
572 void selectBelowBranchInt(); // Increment number of branch
574 void selectUpperBranch();
575 void selectLowerBranch();
576 void selectLeftBranch();
577 void selectRightBranch();
578 void selectFirstBranch();
579 void selectLastBranch();
580 void selectLastSelectedBranch();
584 TreeItem::Type selectionType();
585 LinkableMapObj* getSelectedLMO();
586 BranchObj* getSelectedBranchObj(); // FIXME-2 replace by item...
587 BranchItem* getSelectedBranchItem();
588 TreeItem* getSelectedItem();
589 QModelIndex getSelectedIndex();
590 FloatImageObj* getSelectedFloatImage();
591 QString getSelectString ();
592 QString getSelectString (LinkableMapObj *lmo);
593 QString getSelectString (TreeItem *item);
598 void changeSelection (const QItemSelection &newSel, const QItemSelection &delSel);
602 void updateSelection(const QItemSelection &oldsel);
603 void updateSelection();
604 void selectMapLinkColor();
605 void selectMapSelectionColor();
607 void setSelectionColorInt(QColor);
608 QItemSelectionModel *selModel;
611 void setSelectionColor(QColor);
612 QColor getSelectionColor();