4 #include <QGraphicsScene>
8 #include "mapcenterobj.h"
11 #include "selection.h"
13 #include "treemodel.h"
17 class VymModel : public TreeModel {
20 ////////////////////////////////////////////
21 // General housekeeping
22 ////////////////////////////////////////////
24 QGraphicsScene *mapScene;
25 QList <MapCenterObj*> mapCenters;
26 QString version; //!< version string saved in vym file
36 void makeTmpDirectories(); //!< create temporary directories e.g. for history
38 MapEditor* getMapEditor(); // FIXME not necessary
40 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
42 void updateActions(); //!< Update buttons in mainwindow
45 ////////////////////////////////////////////
47 ////////////////////////////////////////////
50 bool zipped; // should map be zipped
51 static int mapNum; // unique number for model used in save/undo
52 FileType fileType; // type of file, e.g. vym, freemind...
53 QString fileName; // short name of file (for tab)
54 QString filePath; // path to file which will be saved
55 QString fileDir; // dir where file is saved
56 QString destPath; // path to .vym file (needed for vymlinks)
57 QString mapName; // fileName without ".vym"
59 QString tmpMapDir; // tmp directory with undo history
61 QTimer *autosaveTimer;
62 QTimer *fileChangedTimer;
63 QDateTime fileChangedTime;
66 /*! This function saves all information of the map to disc.
67 saveToDir also calls the functions for all BranchObj and other objects in the map.
68 The structure of the map itself is returned as QString and passed back to Main,
69 where saveToDir is called initially
71 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
73 /*! Save all data in tree*/
74 QString saveTreeToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
77 /*! \brief Sets filepath, filename and mapname
79 If the filepath is "/home/tux/map.xml", then the filename will be set
80 to map.xml. The destname is needed for vymLinks, pointing to another map.
81 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
85 /*! \brief Set File path
87 The destname is needed to construct the references between maps
89 void setFilePath (QString filepath,QString destname);
90 void setFilePath (QString); //!< Overloaded for convenience
91 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
92 QString getFileName (); //!< e.g. "map.xml"
93 QString getMapName (); //!< e.g. "map"
94 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
98 The data is read from file. Depending on LoadMode the current
99 selection gets replaced by data or the data is appended.
101 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
104 /*! \brief Save the map to file */
105 ErrorCode save(const SaveMode &);
108 void addMapReplaceInt(const QString & undoSel, const QString & path);
109 void addMapInsertInt (const QString & path, int pos);
111 FloatImageObj* loadFloatImageInt (QString);
112 void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
114 void loadFloatImage ();
115 void saveFloatImage ();
118 void importDirInt(BranchObj *,QDir);
119 void importDirInt(const QString&);
127 ////////////////////////////////////////////
128 // history (undo/redo)
129 ////////////////////////////////////////////
131 bool mapDefault; //!< Flag if map is untouched
132 bool mapChanged; //!< Flag if undo is possible
133 bool mapUnsaved; //!< Flag if map should be saved
135 QString histPath; //!< Path to history file
136 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
137 int stepsTotal; //!< total number of steps (undos+redos)
138 int curStep; //!< Current step in history (ring buffer)
139 int curClipboard; //!< number of history step, which is the current clipboard
140 int redosAvail; //!< Available number of redo steps
141 int undosAvail; //!< Available number of undo steps
142 bool blockReposition; //!< block while load or undo
143 bool blockSaveState; //!< block while load or undo
145 bool isDefault(); //!< true, if map is still the empty default map
146 void makeDefault(); //!< Reset changelog, declare this as default map
147 bool hasChanged() ; //!< true, if something has changed and is not saved yet
148 void setChanged(); //!< called from TextEditor via LinkableMapObj
150 /*! \brief Get name of object
152 Returns heading of a branch or name of an object for use in comment
155 QString getObjectName(const LinkableMapObj*);
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 LinkableMapObj *saveSelection);
184 /*! Overloaded for convenience */
185 void saveStateChangingPart(
186 LinkableMapObj *undoSelection,
187 LinkableMapObj* redoSelection,
188 const QString &redoCommand,
189 const QString &comment);
190 /*! Overloaded for convenience */
191 void saveStateRemovingPart(
192 LinkableMapObj *redoSelection,
193 const QString &comment);
194 /*! Overloaded for convenience */
196 LinkableMapObj *undoSelection,
197 const QString &undoCommand,
198 LinkableMapObj *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 LinkableMapObj* findMapObj(QPointF,LinkableMapObj*); // find MapObj
222 LinkableMapObj* findObjBySelect (const QString &s); // find MapObj by select string
223 LinkableMapObj* findID (const QString &s); // find MapObj by previously set ID
226 ////////////////////////////////////////////
228 ////////////////////////////////////////////
230 void setVersion(const QString &);
231 void setAuthor (const QString &);
232 QString getAuthor ();
233 void setComment (const QString &);
234 QString getComment ();
239 void setHeading(const QString &); //!< Set heading of branch
240 // QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
243 BranchItem* findCurrent; // next object in find process
244 BranchItem* findPrevious; // next object in find process
245 bool EOFind; // true, if search failed
247 BranchObj* findText(QString,bool); // Find object
248 void findReset(); // Reset Search
250 void setURL(const QString &url);
251 QString getURL(); // returns URL of selection or ""
252 QStringList getURLs(); // returns URLs of subtree
254 void linkFloatImageTo(const QString &);
256 void setFrameType(const FrameObj::FrameType &);
257 void setFrameType(const QString &);
258 void setFramePenColor (const QColor &);
259 void setFrameBrushColor (const QColor &);
260 void setFramePadding (const int &);
261 void setFrameBorderWidth (const int &);
262 void setIncludeImagesVer(bool);
263 void setIncludeImagesHor(bool);
264 void setHideLinkUnselected (bool);
266 /*! Should object be hidden in exports (clouded)? */
267 void setHideExport(bool);
269 /*! Should object be hidden in exports (clouded)? */
270 void toggleHideExport();
272 void copy(); //!< Copy to clipboard
274 void pasteNoSave(const int &n); //!< paste clipboard to branch
276 void paste(); //!< Paste clipboard to branch and backup
277 void cut(); //!< Cut to clipboard (and copy)
279 void moveBranchUp(); //!< Move branch up
280 void moveBranchDown(); //!< Move branch down
281 void sortChildren(); //!< Sort children lexically
283 // The create methods are used to quickly parse a XML file
284 void createMapCenter(); //!< Create and select MapCenter
285 BranchItem* createBranch(); //!< Create and select Branch
286 TreeItem* createImage(); //!< Create and select image
288 /*! \brief Add new mapcenter
290 Disclaimer: Still experimental, not fully supported yet.
292 MapCenterObj* addMapCenter();
294 MapCenterObj* addMapCenter(QPointF absPos);
296 MapCenterObj* removeMapCenter(MapCenterObj *mco);
298 /*! \brief Add new branch
300 Depending on num the new branch is created
302 -3 above selection as child of selections parent
303 -2 as child of selection
304 -1 below selection as child of selections parent
305 0..n insert at a specific position in selections parent
306 (needed for free relinking)
308 MapCenterObj* getLastMapCenter(); //!< get last added MapCenter, used for context menu
311 BranchObj* addNewBranchInt(int); // pos allows to add above/below selection
315 Depending on num the new branch is created
317 0 as child of selection
320 BranchObj* addNewBranch(int pos);
321 BranchObj* addNewBranchBefore(); //!< Insert branch between selection and its parent
322 void deleteSelection(); //!< Delete selection
323 void deleteKeepChildren(); //!< remove branch, but keep children
324 void deleteChildren(); //!< keep branch, but remove children
327 bool scrollBranch(BranchItem *);
328 bool unscrollBranch(BranchItem *);
331 void unscrollChildren();
333 void addFloatImage(const QPixmap &img);
335 void colorBranch(QColor);
336 void colorSubtree(QColor);
337 QColor getCurrentHeadingColor();
340 void editURL(); // edit URL
341 void editLocalURL(); // edit URL to local file
342 void editHeading2URL(); // copy heading to URL
343 void editBugzilla2URL(); // create URL to Bugzilla
344 void editFATE2URL(); // create URL to FATE
345 void editVymLink(); // edit link to another map
346 void setVymLink (const QString &); // Set vymLink for selection
347 void deleteVymLink(); // delete link to another map
348 QString getVymLink(); // return path to map
349 QStringList getVymLinks(); // return paths in subtree
350 void followXLink (int);
351 void editXLink (int);
356 ////////////////////////////////////////////
358 ////////////////////////////////////////////
361 /* \brief Process one command and its parameters */
362 void parseAtom (const QString &atom);
364 /* \brief Runs the script */
365 void runScript (QString script);
370 ////////////////////////////////////////////
372 ////////////////////////////////////////////
374 HideTmpMode hidemode; // true while exporting to hide some stuff
377 /*! Set or unset temporary hiding of objects during export */
378 void setExportMode (bool);
381 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
384 /*! Export as XTML to directory */
385 void exportXML(QString dir="", bool askForName=true);
387 /*! Export as ASCII text to file */
388 void exportASCII (QString fname="",bool askForName=true);
390 /*! Export as XHTML to directory */
391 void exportXHTML(const QString& dir="", bool askForName=true);
393 /*! Export as OpenOfficeOrg presentation */
394 void exportOOPresentation(const QString &,const QString &);
397 ////////////////////////////////////////////
399 ////////////////////////////////////////////
401 void registerEditor (QWidget *);
402 void unregisterEditor (QWidget *);
405 QPointF contextPos; //!< local position during context menu
407 void setContextPos (QPointF); //!< local position during context menu
408 void unsetContextPos (); //!< forget local position after context menu
410 void updateNoteFlag(); //!< Signal origination in TextEditor
411 void updateRelPositions();
413 QRectF getTotalBBox();
414 void reposition(); //!< Call reposition for all MCOs
415 void setHideTmpMode (HideTmpMode mode);
417 QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree
418 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
420 //void ensureSelectionVisible(); //!< Show selection in all views
422 void emitContentHasChanged (TreeItem *ti);
425 void contentHasChanged (QModelIndex ix);
426 void newChildObject(QModelIndex ix);
429 MapEditor *mapEditor;
431 QColor defLinkColor; // default color for links
432 QColor defXLinkColor; // default color for xlinks
433 int defXLinkWidth; // default width for xlinks
434 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
435 LinkableMapObj::Style linkstyle; // default style for links
441 void setMapLinkStyle (const QString &); // Set style of link
442 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
443 void setMapDefLinkColor(QColor); // default color of links
444 void setMapLinkColorHintInt(); // color of links
445 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
446 void toggleMapLinkColorHint(); // after changing linkStyles
447 void selectMapBackgroundImage();
448 void setMapBackgroundImage(const QString &);
449 void selectMapBackgroundColor();
450 void setMapBackgroundColor(QColor);
451 QColor getMapBackgroundColor();
454 LinkableMapObj::ColorHint getMapLinkColorHint();
455 QColor getMapDefLinkColor();
456 void setMapDefXLinkColor(QColor);
457 QColor getMapDefXLinkColor();
458 void setMapDefXLinkWidth (int);
459 int getMapDefXLinkWidth();
461 /*! Move absolutly to (x,y). */
462 void move (const double &x, const double &y);
464 /*! Move relativly to (x,y). */
465 void moveRel (const double &x, const double &y);
467 ////////////////////////////////////////////
468 // Animation **experimental**
469 ////////////////////////////////////////////
471 QTimer *animationTimer;
474 uint animationInterval;
475 int timerId; // animation timer
476 QList <MapObj*> animObjList;// list with animated objects
479 void animate(); //!< Called by timer to animate stuff
481 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
482 void stopAnimation(MapObj *mo);
484 ////////////////////////////////////////////
486 ////////////////////////////////////////////
488 /*! \brief Networking states
490 In Network modus we want to switch of saveState, autosave, ...
493 Offline, //!< Offline
494 Client, //!< I am the client and connected to server
495 Server //!< I am the server
499 // Network connections **Experimental**
500 NetState netstate; // offline, client, server
501 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
502 QList <QTcpSocket*> clientList; // List of connected clients
503 quint16 sendCounter; // Increased with every sent command
505 QTcpSocket *clientSocket; // socket of this client
506 QString server; // server address of this client
507 int port; // server port of this client
512 void sendSelection();
516 void connectToServer();
520 void sendData(const QString &s);
522 void displayNetworkError (QAbstractSocket::SocketError);
525 void displayClientError(QAbstractSocket::SocketError socketError);
528 ////////////////////////////////////////////
530 ////////////////////////////////////////////
533 QString latestSelectionString; // select string of latest added object
536 void selectionChanged(const QItemSelection &, const QItemSelection &);
539 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
540 QItemSelectionModel* getSelectionModel();
542 void setSelectionBlocked(bool);
543 bool isSelectionBlocked();
545 bool select (); // select by using common QItemSlectionModel
546 bool select (const QString &); // Select by string
547 bool select (LinkableMapObj *lmo); // Select by pointer to LMO
548 bool select (TreeItem *ti ); // Select by point to TreeItem
552 void ensureSelectionVisible(); //!< Show selection in all views
554 // void selectInt(LinkableMapObj*);
557 void selectNextBranchInt(); // Increment number of branch
558 void selectPrevBranchInt(); // Decrement number of branch
560 void selectUpperBranch();
561 void selectLowerBranch();
562 void selectLeftBranch();
563 void selectRightBranch();
564 void selectFirstBranch();
565 void selectLastBranch();
566 void selectLastSelectedBranch();
570 TreeItem::Type selectionType();
571 LinkableMapObj* getSelectedLMO();
572 BranchObj* getSelectedBranch();
573 BranchItem* getSelectedBranchItem();
574 TreeItem* getSelectedItem();
575 QModelIndex getSelectedIndex();
576 FloatImageObj* getSelectedFloatImage();
577 QString getSelectString ();
578 QString getSelectString (LinkableMapObj *lmo);
579 QString getSelectString (TreeItem *item);
584 void changeSelection (const QItemSelection &newSel, const QItemSelection &delSel);
588 void updateSelection(const QItemSelection &oldsel);
589 void updateSelection();
590 void selectMapLinkColor();
591 void selectMapSelectionColor();
593 void setSelectionColorInt(QColor);
594 QItemSelectionModel *selModel;
597 void setSelectionColor(QColor);
598 QColor getSelectionColor();