4 #include <QGraphicsScene>
7 #include <QtDBus/QDBusAbstractAdaptor>
8 #include <QtDBus/QDBusVariant>
10 #include "adaptormodel.h"
12 #include "imageitem.h"
13 #include "mapeditor.h"
16 #include "treemodel.h"
23 class VymModel : public TreeModel {
25 Q_CLASSINFO("D-Bus Interface", "org.insilmaril.vym.VymModel-h")
28 ////////////////////////////////////////////
29 // General housekeeping
30 ////////////////////////////////////////////
32 QString version; //!< version string saved in vym file
42 void makeTmpDirectories(); //!< create temporary directories e.g. for history
44 MapEditor* getMapEditor(); // FIXME-2 still necessary?
46 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
48 void updateActions(); //!< Update buttons in mainwindow
51 ////////////////////////////////////////////
53 ////////////////////////////////////////////
56 bool zipped; // should map be zipped
57 static int mapNum; // unique number for model used in save/undo
58 FileType fileType; // type of file, e.g. vym, freemind...
59 QString fileName; // short name of file (for tab)
60 QString filePath; // path to file which will be saved
61 QString fileDir; // dir where file is saved
62 QString destPath; // path to .vym file (needed for vymlinks)
63 QString mapName; // fileName without ".vym"
65 QString tmpMapDir; // tmp directory with undo history
67 QTimer *autosaveTimer;
68 QTimer *fileChangedTimer;
69 QDateTime fileChangedTime;
72 /*! This function saves all information of the map to disc.
73 saveToDir also calls the functions for all BranchObj and other objects in the map.
74 The structure of the map itself is returned as QString and passed back to Main,
75 where saveToDir is called initially
77 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel);
79 /*! Save all data in tree*/
80 QString saveTreeToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
83 /*! \brief Sets filepath, filename and mapname
85 If the filepath is "/home/tux/map.xml", then the filename will be set
86 to map.xml. The destname is needed for vymLinks, pointing to another map.
87 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
91 /*! \brief Set File path
93 The destname is needed to construct the references between maps
95 void setFilePath (QString filepath,QString destname);
96 void setFilePath (QString); //!< Overloaded for convenience
97 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
98 QString getFileName (); //!< e.g. "map.xml"
99 QString getMapName (); //!< e.g. "map"
100 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
104 The data is read from file. Depending on LoadMode the current
105 selection gets replaced by data or the data is appended.
107 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
110 /*! \brief Save the map to file */
111 ErrorCode save(const SaveMode &);
114 void addMapReplaceInt(const QString & undoSel, const QString & path);
115 bool addMapInsertInt (const QString & path);
116 bool addMapInsertInt (const QString & path, int pos);
118 ImageItem* loadFloatImageInt (BranchItem *dst,QString);
119 void saveFloatImageInt (ImageItem*, const QString &, const QString &);
121 void loadFloatImage ();
122 void saveFloatImage ();
125 void importDirInt(BranchItem *,QDir);
126 void importDirInt(const QString&);
134 ////////////////////////////////////////////
135 // history (undo/redo)
136 ////////////////////////////////////////////
138 bool mapDefault; //!< Flag if map is untouched
139 bool mapChanged; //!< Flag if undo is possible
140 bool mapUnsaved; //!< Flag if map should be saved
142 QString histPath; //!< Path to history file
143 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
144 int stepsTotal; //!< total number of steps (undos+redos)
145 int curStep; //!< Current step in history (ring buffer)
146 int curClipboard; //!< number of history step, which is the current clipboard
147 int redosAvail; //!< Available number of redo steps
148 int undosAvail; //!< Available number of undo steps
149 bool blockReposition; //!< block while load or undo
150 bool blockSaveState; //!< block while load or undo
152 bool isDefault(); //!< true, if map is still the empty default map
153 void makeDefault(); //!< Reset changelog, declare this as default map
154 bool hasChanged() ; //!< true, if something has changed and is not saved yet
155 void setChanged(); //!< called from TextEditor via LinkableMapObj
157 /*! \brief Get name of object
159 Returns heading of a branch or name of an object for use in comment
162 QString getObjectName(LinkableMapObj*);
163 QString getObjectName(TreeItem*);
165 void redo(); //!< Redo last action
166 bool isRedoAvailable(); //!< True, if redo is available
167 void undo(); //!< Undo last action
168 bool isUndoAvailable(); //!< True, if undo is available
169 void gotoHistoryStep (int); //!< Goto a specifig step in history
172 QString getHistoryPath(); //!< Path to directory containing the history
174 /*! \brief Save the current changes in map
176 Two commands and selections are saved:
178 - undocommand and undoselection to undo the change
179 - redocommand and redoselection to redo the action after an undo
181 Additionally a comment is logged.
185 const SaveMode& savemode,
186 const QString &undoSelection,
187 const QString &undoCommand,
188 const QString &redoSelection,
189 const QString &redoCommand,
190 const QString &comment,
191 TreeItem *saveSelection);
192 /*! Overloaded for convenience */
193 void saveStateChangingPart(
194 TreeItem *undoSelection,
195 TreeItem* redoSelection,
196 const QString &redoCommand,
197 const QString &comment);
198 /*! Overloaded for convenience */
199 void saveStateRemovingPart(
200 TreeItem *redoSelection,
201 const QString &comment);
202 /*! Overloaded for convenience */
204 TreeItem *undoSelection,
205 const QString &undoCommand,
206 TreeItem *redoSelection,
207 const QString &redoCommand,
208 const QString &comment);
209 /*! Overloaded for convenience */
211 const QString &undoSelection,
212 const QString &undoCommand,
213 const QString &redoSelection,
214 const QString &redoCommand,
215 const QString &comment) ;
217 const QString &undoCommand,
218 const QString &redoCommand,
219 const QString &comment) ;
222 ////////////////////////////////////////////
224 ////////////////////////////////////////////
226 QGraphicsScene *mapScene;
228 void setScene(QGraphicsScene *s);
229 QGraphicsScene *getScene();
231 TreeItem* findBySelectString (QString s);
232 TreeItem* findID (const QString &s); // find MapObj by previously set ID
235 ////////////////////////////////////////////
237 ////////////////////////////////////////////
239 void setVersion(const QString &);
240 void setAuthor (const QString &);
241 QString getAuthor ();
242 void setComment (const QString &);
243 QString getComment ();
247 void setSortFilter (const QString &);
248 QString getSortFilter ();
252 void sortFilterChanged (QString ); //!< Notify editors of new filter
255 void setHeading(const QString &); //!< Set heading of item
256 QString getHeading (); //!< Get heading of item
257 void setNote(const QString &s); //!< Set note text
258 QString getNote(); //!< Get note text
261 BranchItem* findCurrent; // next object in find process
262 BranchItem* findPrevious; // next object in find process
263 bool EOFind; // true, if search failed
266 BranchItem* findText(QString,bool); // Find object
267 void findReset(); // Reset Search
269 void setURL(const QString &url);
270 QString getURL(); // returns URL of selection or ""
271 QStringList getURLs(); // returns URLs of subtree
274 void setFrameType(const FrameObj::FrameType &);
275 void setFrameType(const QString &);
276 void setFramePenColor (const QColor &);
277 void setFrameBrushColor (const QColor &);
278 void setFramePadding (const int &);
279 void setFrameBorderWidth (const int &);
280 void setIncludeImagesVer(bool);
281 void setIncludeImagesHor(bool);
282 void setHideLinkUnselected (bool);
284 /*! Should object be hidden in exports (clouded)? */
285 void setHideExport(bool);
287 /*! Should object be hidden in exports (clouded)? */
288 void toggleHideExport();
292 void copy(); //!< Copy to clipboard
294 void pasteNoSave(const int &n); //!< paste clipboard to branch
296 void paste(); //!< Paste clipboard to branch and backup
297 void cut(); //!< Cut to clipboard (and copy)
299 bool moveUp(BranchItem *bi); //!< Move branch up without saving state
300 void moveUp(); //!< Move branch up with saving state
301 bool moveDown(BranchItem *bi); //!< Move branch down without saving state
302 void moveDown(); //!< Move branch down
303 void detach(); //!< Detach branch and use as new mapcenter
304 void sortChildren(); //!< Sort children lexically
306 // The create methods are used to quickly parse a XML file
307 BranchItem* createMapCenter(); //!< Create MapCenter
308 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
309 ImageItem* createImage(BranchItem *dst); //!< Create image
310 XLinkItem* createXLink(BranchItem *dst,bool createMO=false); //!< Create XLink starting at dst
312 AttributeItem* addAttribute();
314 /*! \brief Add new mapcenter
316 Disclaimer: Still experimental, not fully supported yet.
318 BranchItem* addMapCenter();
320 BranchItem* addMapCenter(QPointF absPos);
322 /*! \brief Add new branch
324 Depending on num the new branch is created
326 -3 above selection as child of selections parent
327 -2 as child of selection
328 -1 below selection as child of selections parent
329 0..n insert at a specific position in selections parent
330 (needed for free relinking)
334 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
338 Depending on num the new branch is created
340 0 as child of selection
343 BranchItem* addNewBranch(int pos=0);
344 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
345 /*! \brief Relink a branch to a new destination dst
346 Relinks branch to dst at branch position pos. There is no saveState
347 here, as for example moveUp or moving in MapEditor have
348 different needs to call saveState
349 Returns true if relinking was successful.
351 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
352 bool relinkImage (ImageItem* image, BranchItem* dst);
354 void deleteSelection(); //!< Delete selection
355 void deleteKeepChildren(); //!< remove branch, but keep children
356 void deleteChildren(); //!< keep branch, but remove children
358 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
359 void clearItem (TreeItem* ti); //!< Remove all children of TreeItem ti
360 bool scrollBranch(BranchItem *);
361 bool unscrollBranch(BranchItem *);
364 void unscrollChildren();
365 void emitExpandAll();
366 void emitExpandOneLevel();
367 void emitCollapseOneLevel();
370 void expandOneLevel();
371 void collapseOneLevel();
374 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
375 void addFloatImage(const QPixmap &img);
377 void colorBranch(QColor);
378 void colorSubtree(QColor);
379 QColor getCurrentHeadingColor();
382 void editURL(); // edit URL
383 void editLocalURL(); // edit URL to local file
384 void editHeading2URL(); // copy heading to URL
385 void editBugzilla2URL(); // create URL to Bugzilla
386 void editFATE2URL(); // create URL to FATE
387 void editVymLink(); // edit link to another map
388 void setVymLink (const QString &); // Set vymLink for selection
389 void deleteVymLink(); // delete link to another map
390 QString getVymLink(); // return path to map
391 QStringList getVymLinks(); // return paths in subtree
392 void followXLink (int);
393 void editXLink (int);
398 ////////////////////////////////////////////
400 ////////////////////////////////////////////
403 /* \brief Process one command and its parameters */
404 QVariant parseAtom (const QString &atom, bool &noError, QString &errorMsg);
406 /* \brief Runs the script */
407 void runScript (QString script);
412 ////////////////////////////////////////////
414 ////////////////////////////////////////////
416 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
419 /*! Set or unset temporary hiding of objects during export */
420 void setExportMode (bool);
423 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
426 /*! Export as XTML to directory */
427 void exportXML(QString dir="", bool askForName=true);
429 /*! Export as ASCII text to file */
430 void exportASCII (QString fname="",bool askForName=true);
432 /*! Export as XHTML to directory */
433 void exportXHTML(const QString& dir="", bool askForName=true);
435 /*! Export as OpenOfficeOrg presentation */
436 void exportOOPresentation(const QString &,const QString &);
439 ////////////////////////////////////////////
441 ////////////////////////////////////////////
443 void registerEditor (QWidget *);
444 void unregisterEditor (QWidget *);
447 QPointF contextPos; //!< local position during context menu
449 void setContextPos (QPointF); //!< local position during context menu
450 void unsetContextPos (); //!< forget local position after context menu
452 void updateNoteFlag(); //!< Signal origination in TextEditor
453 void reposition(); //!< Call reposition for all MCOs
454 void setHideTmpMode (TreeItem::HideTmpMode mode);
456 void emitNoteHasChanged (TreeItem *ti);
457 void emitDataHasChanged (TreeItem *ti);
460 void noteHasChanged (QModelIndex ix);
461 void newChildObject(QModelIndex ix);
464 MapEditor *mapEditor;
466 QColor defLinkColor; // default color for links
467 QColor defXLinkColor; // default color for xlinks
468 int defXLinkWidth; // default width for xlinks
469 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
470 LinkableMapObj::Style linkstyle; // default style for links
473 void setMapLinkStyle (const QString &); // Set style of link
474 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
475 void setMapDefLinkColor(QColor); // default color of links
476 void setMapLinkColorHintInt(); // color of links
477 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
478 void toggleMapLinkColorHint(); // after changing linkStyles
479 void selectMapBackgroundImage();
480 void setMapBackgroundImage(const QString &);
481 void selectMapBackgroundColor();
482 void setMapBackgroundColor(QColor);
483 QColor getMapBackgroundColor();
486 LinkableMapObj::ColorHint getMapLinkColorHint();
487 QColor getMapDefLinkColor();
488 void setMapDefXLinkColor(QColor);
489 QColor getMapDefXLinkColor();
490 void setMapDefXLinkWidth (int);
491 int getMapDefXLinkWidth();
493 /*! Move absolutly to (x,y). */
494 void move (const double &x, const double &y);
496 /*! Move relativly to (x,y). */
497 void moveRel (const double &x, const double &y);
499 ////////////////////////////////////////////
500 // Animation **experimental**
501 ////////////////////////////////////////////
503 QTimer *animationTimer;
506 uint animationInterval;
507 int timerId; // animation timer
508 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
511 void animate(); //!< Called by timer to animate stuff
513 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
514 void stopAnimation(MapObj *mo);
516 ////////////////////////////////////////////
518 ////////////////////////////////////////////
520 /*! \brief Networking states
522 In Network modus we want to switch of saveState, autosave, ...
525 Offline, //!< Offline
526 Client, //!< I am the client and connected to server
527 Server //!< I am the server
531 // Network connections **Experimental**
532 NetState netstate; // offline, client, server
533 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
534 QList <QTcpSocket*> clientList; // List of connected clients
535 quint16 sendCounter; // Increased with every sent command
537 QTcpSocket *clientSocket; // socket of this client
538 QString server; // server address of this client
539 int port; // server port of this client
544 void sendSelection();
548 void connectToServer();
552 void sendData(const QString &s);
554 void displayNetworkError (QAbstractSocket::SocketError);
556 ////////////////////////////////////////////
558 ////////////////////////////////////////////
561 AdaptorModel *adaptorModel; //FIXME-3
566 ////////////////////////////////////////////
568 ////////////////////////////////////////////
570 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
573 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
574 QItemSelectionModel* getSelectionModel();
576 void setSelectionBlocked(bool);
577 bool isSelectionBlocked();
579 bool select (); //! select by using common QItemSelectionModel
580 bool select (const QString &); //! Select by string
581 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
582 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
583 bool select (const QModelIndex &index); //! Select by ModelIndex
587 void emitShowSelection(); //!< Show selection in all views
589 void showSelection();
592 bool selectFirstBranch();
593 bool selectLastBranch();
594 bool selectLastSelectedBranch();
598 TreeItem::Type selectionType();
599 LinkableMapObj* getSelectedLMO();
600 BranchObj* getSelectedBranchObj(); // FIXME-3 replace by item...
601 BranchItem* getSelectedBranch();
602 ImageItem* getSelectedImage();
603 AttributeItem* getSelectedAttribute();
604 TreeItem* getSelectedItem();
605 QModelIndex getSelectedIndex();
606 QString getSelectString ();
607 QString getSelectString (LinkableMapObj *lmo);
608 QString getSelectString (TreeItem *item);
612 void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
615 void emitSelectionChanged(const QItemSelection &oldsel);
616 void emitSelectionChanged();
617 void selectMapLinkColor();
618 void selectMapSelectionColor();
620 void setSelectionColorInt(QColor);
621 QItemSelectionModel *selModel;
622 QString lastSelectString;
623 bool selectionBlocked; //! Used to block changes of selection while editing a heading
626 void setSelectionColor(QColor);
627 QColor getSelectionColor();