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"
22 class VymModel : public TreeModel {
24 Q_CLASSINFO("D-Bus Interface", "org.insilmaril.vym.VymModel-h")
27 ////////////////////////////////////////////
28 // General housekeeping
29 ////////////////////////////////////////////
31 QString version; //!< version string saved in vym file
41 void makeTmpDirectories(); //!< create temporary directories e.g. for history
43 MapEditor* getMapEditor(); // FIXME-2 still necessary?
45 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
47 void updateActions(); //!< Update buttons in mainwindow
50 ////////////////////////////////////////////
52 ////////////////////////////////////////////
55 bool zipped; // should map be zipped
56 static int mapNum; // unique number for model used in save/undo
57 FileType fileType; // type of file, e.g. vym, freemind...
58 QString fileName; // short name of file (for tab)
59 QString filePath; // path to file which will be saved
60 QString fileDir; // dir where file is saved
61 QString destPath; // path to .vym file (needed for vymlinks)
62 QString mapName; // fileName without ".vym"
64 QString tmpMapDir; // tmp directory with undo history
66 QTimer *autosaveTimer;
67 QTimer *fileChangedTimer;
68 QDateTime fileChangedTime;
71 /*! This function saves all information of the map to disc.
72 saveToDir also calls the functions for all BranchObj and other objects in the map.
73 The structure of the map itself is returned as QString and passed back to Main,
74 where saveToDir is called initially
76 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel);
78 /*! Save all data in tree*/
79 QString saveTreeToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
82 /*! \brief Sets filepath, filename and mapname
84 If the filepath is "/home/tux/map.xml", then the filename will be set
85 to map.xml. The destname is needed for vymLinks, pointing to another map.
86 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
90 /*! \brief Set File path
92 The destname is needed to construct the references between maps
94 void setFilePath (QString filepath,QString destname);
95 void setFilePath (QString); //!< Overloaded for convenience
96 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
97 QString getFileName (); //!< e.g. "map.xml"
98 QString getMapName (); //!< e.g. "map"
99 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
103 The data is read from file. Depending on LoadMode the current
104 selection gets replaced by data or the data is appended.
106 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
109 /*! \brief Save the map to file */
110 ErrorCode save(const SaveMode &);
113 void addMapReplaceInt(const QString & undoSel, const QString & path);
114 bool addMapInsertInt (const QString & path);
115 bool addMapInsertInt (const QString & path, int pos);
117 ImageItem* loadFloatImageInt (BranchItem *dst,QString);
118 void saveFloatImageInt (ImageItem*, const QString &, const QString &);
120 void loadFloatImage ();
121 void saveFloatImage ();
124 void importDirInt(BranchObj *,QDir);
125 void importDirInt(const QString&);
133 ////////////////////////////////////////////
134 // history (undo/redo)
135 ////////////////////////////////////////////
137 bool mapDefault; //!< Flag if map is untouched
138 bool mapChanged; //!< Flag if undo is possible
139 bool mapUnsaved; //!< Flag if map should be saved
141 QString histPath; //!< Path to history file
142 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
143 int stepsTotal; //!< total number of steps (undos+redos)
144 int curStep; //!< Current step in history (ring buffer)
145 int curClipboard; //!< number of history step, which is the current clipboard
146 int redosAvail; //!< Available number of redo steps
147 int undosAvail; //!< Available number of undo steps
148 bool blockReposition; //!< block while load or undo
149 bool blockSaveState; //!< block while load or undo
151 bool isDefault(); //!< true, if map is still the empty default map
152 void makeDefault(); //!< Reset changelog, declare this as default map
153 bool hasChanged() ; //!< true, if something has changed and is not saved yet
154 void setChanged(); //!< called from TextEditor via LinkableMapObj
156 /*! \brief Get name of object
158 Returns heading of a branch or name of an object for use in comment
161 QString getObjectName(LinkableMapObj*);
162 QString getObjectName(TreeItem*);
164 void redo(); //!< Redo last action
165 bool isRedoAvailable(); //!< True, if redo is available
166 void undo(); //!< Undo last action
167 bool isUndoAvailable(); //!< True, if undo is available
168 void gotoHistoryStep (int); //!< Goto a specifig step in history
171 QString getHistoryPath(); //!< Path to directory containing the history
173 /*! \brief Save the current changes in map
175 Two commands and selections are saved:
177 - undocommand and undoselection to undo the change
178 - redocommand and redoselection to redo the action after an undo
180 Additionally a comment is logged.
184 const SaveMode& savemode,
185 const QString &undoSelection,
186 const QString &undoCommand,
187 const QString &redoSelection,
188 const QString &redoCommand,
189 const QString &comment,
190 TreeItem *saveSelection);
191 /*! Overloaded for convenience */
192 void saveStateChangingPart(
193 TreeItem *undoSelection,
194 TreeItem* redoSelection,
195 const QString &redoCommand,
196 const QString &comment);
197 /*! Overloaded for convenience */
198 void saveStateRemovingPart(
199 TreeItem *redoSelection,
200 const QString &comment);
201 /*! Overloaded for convenience */
203 TreeItem *undoSelection,
204 const QString &undoCommand,
205 TreeItem *redoSelection,
206 const QString &redoCommand,
207 const QString &comment);
208 /*! Overloaded for convenience */
210 const QString &undoSelection,
211 const QString &undoCommand,
212 const QString &redoSelection,
213 const QString &redoCommand,
214 const QString &comment) ;
216 const QString &undoCommand,
217 const QString &redoCommand,
218 const QString &comment) ;
221 ////////////////////////////////////////////
223 ////////////////////////////////////////////
225 QGraphicsScene *mapScene;
227 void setScene(QGraphicsScene *s);
228 QGraphicsScene *getScene();
230 TreeItem* findBySelectString (QString s);
231 TreeItem* findID (const QString &s); // find MapObj by previously set ID
234 ////////////////////////////////////////////
236 ////////////////////////////////////////////
238 void setVersion(const QString &);
239 void setAuthor (const QString &);
240 QString getAuthor ();
241 void setComment (const QString &);
242 QString getComment ();
247 void setHeading(const QString &); //!< Set heading of item
248 QString getHeading (); //!< Get heading of item
251 BranchItem* findCurrent; // next object in find process
252 BranchItem* findPrevious; // next object in find process
253 bool EOFind; // true, if search failed
255 BranchItem* findText(QString,bool); // Find object
256 void findReset(); // Reset Search
258 void setURL(const QString &url);
259 QString getURL(); // returns URL of selection or ""
260 QStringList getURLs(); // returns URLs of subtree
263 void setFrameType(const FrameObj::FrameType &);
264 void setFrameType(const QString &);
265 void setFramePenColor (const QColor &);
266 void setFrameBrushColor (const QColor &);
267 void setFramePadding (const int &);
268 void setFrameBorderWidth (const int &);
269 void setIncludeImagesVer(bool);
270 void setIncludeImagesHor(bool);
271 void setHideLinkUnselected (bool);
273 /*! Should object be hidden in exports (clouded)? */
274 void setHideExport(bool);
276 /*! Should object be hidden in exports (clouded)? */
277 void toggleHideExport();
279 void copy(); //!< Copy to clipboard
281 void pasteNoSave(const int &n); //!< paste clipboard to branch
283 void paste(); //!< Paste clipboard to branch and backup
284 void cut(); //!< Cut to clipboard (and copy)
286 void moveUp(); //!< Move branch up
287 void moveDown(); //!< Move branch down
288 void sortChildren(); //!< Sort children lexically
290 // The create methods are used to quickly parse a XML file
291 BranchItem* createMapCenter(); //!< Create MapCenter
292 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
293 ImageItem* createImage(BranchItem *dst); //!< Create image
295 AttributeItem* addAttribute();
297 /*! \brief Add new mapcenter
299 Disclaimer: Still experimental, not fully supported yet.
301 BranchItem* addMapCenter();
303 BranchItem* addMapCenter(QPointF absPos);
305 /*! \brief Add new branch
307 Depending on num the new branch is created
309 -3 above selection as child of selections parent
310 -2 as child of selection
311 -1 below selection as child of selections parent
312 0..n insert at a specific position in selections parent
313 (needed for free relinking)
317 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
321 Depending on num the new branch is created
323 0 as child of selection
326 BranchItem* addNewBranch(int pos=0);
327 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
328 /*! \brief Relink a branch to a new destination dst
329 Relinks branch to dst at branch position pos. There is no saveState
330 here, as for example moveUp or moving in MapEditor have
331 different needs to call saveState
332 Returns true if relinking was successful.
334 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
335 bool relinkImage (ImageItem* image, BranchItem* dst);
337 void deleteSelection(); //!< Delete selection
338 void deleteKeepChildren(); //!< remove branch, but keep children
339 void deleteChildren(); //!< keep branch, but remove children
342 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
343 bool scrollBranch(BranchItem *);
344 bool unscrollBranch(BranchItem *);
347 void unscrollChildren();
348 void emitExpandAll();
353 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
354 void addFloatImage(const QPixmap &img);
356 void colorBranch(QColor);
357 void colorSubtree(QColor);
358 QColor getCurrentHeadingColor();
361 void editURL(); // edit URL
362 void editLocalURL(); // edit URL to local file
363 void editHeading2URL(); // copy heading to URL
364 void editBugzilla2URL(); // create URL to Bugzilla
365 void editFATE2URL(); // create URL to FATE
366 void editVymLink(); // edit link to another map
367 void setVymLink (const QString &); // Set vymLink for selection
368 void deleteVymLink(); // delete link to another map
369 QString getVymLink(); // return path to map
370 QStringList getVymLinks(); // return paths in subtree
371 void followXLink (int);
372 void editXLink (int);
377 ////////////////////////////////////////////
379 ////////////////////////////////////////////
382 /* \brief Process one command and its parameters */
383 void parseAtom (const QString &atom);
385 /* \brief Runs the script */
386 void runScript (QString script);
391 ////////////////////////////////////////////
393 ////////////////////////////////////////////
395 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
398 /*! Set or unset temporary hiding of objects during export */
399 void setExportMode (bool);
402 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
405 /*! Export as XTML to directory */
406 void exportXML(QString dir="", bool askForName=true);
408 /*! Export as ASCII text to file */
409 void exportASCII (QString fname="",bool askForName=true);
411 /*! Export as XHTML to directory */
412 void exportXHTML(const QString& dir="", bool askForName=true);
414 /*! Export as OpenOfficeOrg presentation */
415 void exportOOPresentation(const QString &,const QString &);
418 ////////////////////////////////////////////
420 ////////////////////////////////////////////
422 void registerEditor (QWidget *);
423 void unregisterEditor (QWidget *);
426 QPointF contextPos; //!< local position during context menu
428 void setContextPos (QPointF); //!< local position during context menu
429 void unsetContextPos (); //!< forget local position after context menu
431 void updateNoteFlag(); //!< Signal origination in TextEditor
432 void updateRelPositions();
434 void reposition(); //!< Call reposition for all MCOs
435 void setHideTmpMode (TreeItem::HideTmpMode mode);
437 //FIXME-5 QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree
438 //FIXME-5 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
440 void emitNoteHasChanged (TreeItem *ti);
441 void emitDataHasChanged (TreeItem *ti);
444 void noteHasChanged (QModelIndex ix);
445 void newChildObject(QModelIndex ix);
448 MapEditor *mapEditor;
450 QColor defLinkColor; // default color for links
451 QColor defXLinkColor; // default color for xlinks
452 int defXLinkWidth; // default width for xlinks
453 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
454 LinkableMapObj::Style linkstyle; // default style for links
457 void setMapLinkStyle (const QString &); // Set style of link
458 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
459 void setMapDefLinkColor(QColor); // default color of links
460 void setMapLinkColorHintInt(); // color of links
461 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
462 void toggleMapLinkColorHint(); // after changing linkStyles
463 void selectMapBackgroundImage();
464 void setMapBackgroundImage(const QString &);
465 void selectMapBackgroundColor();
466 void setMapBackgroundColor(QColor);
467 QColor getMapBackgroundColor();
470 LinkableMapObj::ColorHint getMapLinkColorHint();
471 QColor getMapDefLinkColor();
472 void setMapDefXLinkColor(QColor);
473 QColor getMapDefXLinkColor();
474 void setMapDefXLinkWidth (int);
475 int getMapDefXLinkWidth();
477 /*! Move absolutly to (x,y). */
478 void move (const double &x, const double &y);
480 /*! Move relativly to (x,y). */
481 void moveRel (const double &x, const double &y);
483 ////////////////////////////////////////////
484 // Animation **experimental**
485 ////////////////////////////////////////////
487 QTimer *animationTimer;
490 uint animationInterval;
491 int timerId; // animation timer
492 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
495 void animate(); //!< Called by timer to animate stuff
497 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
498 void stopAnimation(MapObj *mo);
500 ////////////////////////////////////////////
502 ////////////////////////////////////////////
504 /*! \brief Networking states
506 In Network modus we want to switch of saveState, autosave, ...
509 Offline, //!< Offline
510 Client, //!< I am the client and connected to server
511 Server //!< I am the server
515 // Network connections **Experimental**
516 NetState netstate; // offline, client, server
517 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
518 QList <QTcpSocket*> clientList; // List of connected clients
519 quint16 sendCounter; // Increased with every sent command
521 QTcpSocket *clientSocket; // socket of this client
522 QString server; // server address of this client
523 int port; // server port of this client
528 void sendSelection();
532 void connectToServer();
536 void sendData(const QString &s);
538 void displayNetworkError (QAbstractSocket::SocketError);
540 ////////////////////////////////////////////
542 ////////////////////////////////////////////
545 AdaptorModel *adaptorModel; //FIXME-3
550 ////////////////////////////////////////////
552 ////////////////////////////////////////////
554 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
557 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
558 QItemSelectionModel* getSelectionModel();
560 void setSelectionBlocked(bool);
561 bool isSelectionBlocked();
563 bool select (); //! select by using common QItemSelectionModel
564 bool select (const QString &); //! Select by string
565 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
566 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
567 bool select (const QModelIndex &index); //! Select by ModelIndex
571 void emitShowSelection(); //!< Show selection in all views
573 void showSelection();
575 // bool selectInt(LinkableMapObj*); //FIXME-4
578 bool selectFirstBranch();
579 bool selectLastBranch();
580 bool selectLastSelectedBranch();
584 TreeItem::Type selectionType();
585 LinkableMapObj* getSelectedLMO();
586 BranchObj* getSelectedBranchObj(); // FIXME-3 replace by item...
587 BranchItem* getSelectedBranch();
588 ImageItem* getSelectedImage();
589 AttributeItem* getSelectedAttribute();
590 TreeItem* getSelectedItem();
591 QModelIndex getSelectedIndex();
592 QString getSelectString ();
593 QString getSelectString (LinkableMapObj *lmo);
594 QString getSelectString (TreeItem *item);
598 void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
601 void updateSelection (const QItemSelection &newSel, const QItemSelection &delSel);
604 void emitSelectionChanged(const QItemSelection &oldsel);
605 void emitSelectionChanged();
606 void selectMapLinkColor();
607 void selectMapSelectionColor();
609 void setSelectionColorInt(QColor);
610 QItemSelectionModel *selModel;
611 QString lastSelectString;
612 bool selectionBlocked; //! Used to block changes of selection while editing a heading
615 void setSelectionColor(QColor);
616 QColor getSelectionColor();