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 void addMapInsertInt (const QString & path, int pos);
116 ImageItem* loadFloatImageInt (BranchItem *dst,QString);
117 void saveFloatImageInt (ImageItem*, const QString &, const QString &);
119 void loadFloatImage ();
120 void saveFloatImage ();
123 void importDirInt(BranchObj *,QDir);
124 void importDirInt(const QString&);
132 ////////////////////////////////////////////
133 // history (undo/redo)
134 ////////////////////////////////////////////
136 bool mapDefault; //!< Flag if map is untouched
137 bool mapChanged; //!< Flag if undo is possible
138 bool mapUnsaved; //!< Flag if map should be saved
140 QString histPath; //!< Path to history file
141 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
142 int stepsTotal; //!< total number of steps (undos+redos)
143 int curStep; //!< Current step in history (ring buffer)
144 int curClipboard; //!< number of history step, which is the current clipboard
145 int redosAvail; //!< Available number of redo steps
146 int undosAvail; //!< Available number of undo steps
147 bool blockReposition; //!< block while load or undo
148 bool blockSaveState; //!< block while load or undo
150 bool isDefault(); //!< true, if map is still the empty default map
151 void makeDefault(); //!< Reset changelog, declare this as default map
152 bool hasChanged() ; //!< true, if something has changed and is not saved yet
153 void setChanged(); //!< called from TextEditor via LinkableMapObj
155 /*! \brief Get name of object
157 Returns heading of a branch or name of an object for use in comment
160 QString getObjectName(LinkableMapObj*);
161 QString getObjectName(TreeItem*);
163 void redo(); //!< Redo last action
164 bool isRedoAvailable(); //!< True, if redo is available
165 void undo(); //!< Undo last action
166 bool isUndoAvailable(); //!< True, if undo is available
167 void gotoHistoryStep (int); //!< Goto a specifig step in history
170 QString getHistoryPath(); //!< Path to directory containing the history
172 /*! \brief Save the current changes in map
174 Two commands and selections are saved:
176 - undocommand and undoselection to undo the change
177 - redocommand and redoselection to redo the action after an undo
179 Additionally a comment is logged.
183 const SaveMode& savemode,
184 const QString &undoSelection,
185 const QString &undoCommand,
186 const QString &redoSelection,
187 const QString &redoCommand,
188 const QString &comment,
189 TreeItem *saveSelection);
190 /*! Overloaded for convenience */
191 void saveStateChangingPart(
192 TreeItem *undoSelection,
193 TreeItem* redoSelection,
194 const QString &redoCommand,
195 const QString &comment);
196 /*! Overloaded for convenience */
197 void saveStateRemovingPart(
198 TreeItem *redoSelection,
199 const QString &comment);
200 /*! Overloaded for convenience */
202 TreeItem *undoSelection,
203 const QString &undoCommand,
204 TreeItem *redoSelection,
205 const QString &redoCommand,
206 const QString &comment);
207 /*! Overloaded for convenience */
209 const QString &undoSelection,
210 const QString &undoCommand,
211 const QString &redoSelection,
212 const QString &redoCommand,
213 const QString &comment) ;
215 const QString &undoCommand,
216 const QString &redoCommand,
217 const QString &comment) ;
220 ////////////////////////////////////////////
222 ////////////////////////////////////////////
224 QGraphicsScene *mapScene;
226 void setScene(QGraphicsScene *s);
227 QGraphicsScene *getScene();
229 TreeItem* findBySelectString (QString s);
230 TreeItem* findID (const QString &s); // find MapObj by previously set ID
233 ////////////////////////////////////////////
235 ////////////////////////////////////////////
237 void setVersion(const QString &);
238 void setAuthor (const QString &);
239 QString getAuthor ();
240 void setComment (const QString &);
241 QString getComment ();
246 void setHeading(const QString &); //!< Set heading of item
247 QString getHeading (); //!< Get heading of item
250 BranchItem* findCurrent; // next object in find process
251 BranchItem* findPrevious; // next object in find process
252 bool EOFind; // true, if search failed
254 BranchItem* findText(QString,bool); // Find object
255 void findReset(); // Reset Search
257 void setURL(const QString &url);
258 QString getURL(); // returns URL of selection or ""
259 QStringList getURLs(); // returns URLs of subtree
262 void setFrameType(const FrameObj::FrameType &);
263 void setFrameType(const QString &);
264 void setFramePenColor (const QColor &);
265 void setFrameBrushColor (const QColor &);
266 void setFramePadding (const int &);
267 void setFrameBorderWidth (const int &);
268 void setIncludeImagesVer(bool);
269 void setIncludeImagesHor(bool);
270 void setHideLinkUnselected (bool);
272 /*! Should object be hidden in exports (clouded)? */
273 void setHideExport(bool);
275 /*! Should object be hidden in exports (clouded)? */
276 void toggleHideExport();
278 void copy(); //!< Copy to clipboard
280 void pasteNoSave(const int &n); //!< paste clipboard to branch
282 void paste(); //!< Paste clipboard to branch and backup
283 void cut(); //!< Cut to clipboard (and copy)
285 void moveUp(); //!< Move branch up
286 void moveDown(); //!< Move branch down
287 void sortChildren(); //!< Sort children lexically
289 // The create methods are used to quickly parse a XML file
290 BranchItem* createMapCenter(); //!< Create MapCenter
291 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
292 ImageItem* createImage(BranchItem *dst); //!< Create image
294 AttributeItem* addAttribute();
296 /*! \brief Add new mapcenter
298 Disclaimer: Still experimental, not fully supported yet.
300 BranchItem* addMapCenter();
302 BranchItem* addMapCenter(QPointF absPos);
304 /*! \brief Add new branch
306 Depending on num the new branch is created
308 -3 above selection as child of selections parent
309 -2 as child of selection
310 -1 below selection as child of selections parent
311 0..n insert at a specific position in selections parent
312 (needed for free relinking)
316 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
320 Depending on num the new branch is created
322 0 as child of selection
325 BranchItem* addNewBranch(int pos=0);
326 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
327 /*! \brief Relink a branch to a new destination dst
328 Relinks branch to dst at branch position pos. There is no saveState
329 here, as for example moveUp or moving in MapEditor have
330 different needs to call saveState
331 Returns true if relinking was successful.
333 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
334 bool relinkImage (ImageItem* image, BranchItem* dst);
336 void deleteSelection(); //!< Delete selection
337 void deleteKeepChildren(); //!< remove branch, but keep children
338 void deleteChildren(); //!< keep branch, but remove children
341 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
342 bool scrollBranch(BranchItem *);
343 bool unscrollBranch(BranchItem *);
346 void unscrollChildren();
347 void emitExpandAll();
352 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
353 void addFloatImage(const QPixmap &img);
355 void colorBranch(QColor);
356 void colorSubtree(QColor);
357 QColor getCurrentHeadingColor();
360 void editURL(); // edit URL
361 void editLocalURL(); // edit URL to local file
362 void editHeading2URL(); // copy heading to URL
363 void editBugzilla2URL(); // create URL to Bugzilla
364 void editFATE2URL(); // create URL to FATE
365 void editVymLink(); // edit link to another map
366 void setVymLink (const QString &); // Set vymLink for selection
367 void deleteVymLink(); // delete link to another map
368 QString getVymLink(); // return path to map
369 QStringList getVymLinks(); // return paths in subtree
370 void followXLink (int);
371 void editXLink (int);
376 ////////////////////////////////////////////
378 ////////////////////////////////////////////
381 /* \brief Process one command and its parameters */
382 void parseAtom (const QString &atom);
384 /* \brief Runs the script */
385 void runScript (QString script);
390 ////////////////////////////////////////////
392 ////////////////////////////////////////////
394 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
397 /*! Set or unset temporary hiding of objects during export */
398 void setExportMode (bool);
401 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
404 /*! Export as XTML to directory */
405 void exportXML(QString dir="", bool askForName=true);
407 /*! Export as ASCII text to file */
408 void exportASCII (QString fname="",bool askForName=true);
410 /*! Export as XHTML to directory */
411 void exportXHTML(const QString& dir="", bool askForName=true);
413 /*! Export as OpenOfficeOrg presentation */
414 void exportOOPresentation(const QString &,const QString &);
417 ////////////////////////////////////////////
419 ////////////////////////////////////////////
421 void registerEditor (QWidget *);
422 void unregisterEditor (QWidget *);
425 QPointF contextPos; //!< local position during context menu
427 void setContextPos (QPointF); //!< local position during context menu
428 void unsetContextPos (); //!< forget local position after context menu
430 void updateNoteFlag(); //!< Signal origination in TextEditor
431 void updateRelPositions();
433 void reposition(); //!< Call reposition for all MCOs
434 void setHideTmpMode (TreeItem::HideTmpMode mode);
436 //FIXME-5 QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree
437 //FIXME-5 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
439 void emitNoteHasChanged (TreeItem *ti);
440 void emitDataHasChanged (TreeItem *ti);
443 void noteHasChanged (QModelIndex ix);
444 void newChildObject(QModelIndex ix);
447 MapEditor *mapEditor;
449 QColor defLinkColor; // default color for links
450 QColor defXLinkColor; // default color for xlinks
451 int defXLinkWidth; // default width for xlinks
452 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
453 LinkableMapObj::Style linkstyle; // default style for links
456 void setMapLinkStyle (const QString &); // Set style of link
457 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
458 void setMapDefLinkColor(QColor); // default color of links
459 void setMapLinkColorHintInt(); // color of links
460 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
461 void toggleMapLinkColorHint(); // after changing linkStyles
462 void selectMapBackgroundImage();
463 void setMapBackgroundImage(const QString &);
464 void selectMapBackgroundColor();
465 void setMapBackgroundColor(QColor);
466 QColor getMapBackgroundColor();
469 LinkableMapObj::ColorHint getMapLinkColorHint();
470 QColor getMapDefLinkColor();
471 void setMapDefXLinkColor(QColor);
472 QColor getMapDefXLinkColor();
473 void setMapDefXLinkWidth (int);
474 int getMapDefXLinkWidth();
476 /*! Move absolutly to (x,y). */
477 void move (const double &x, const double &y);
479 /*! Move relativly to (x,y). */
480 void moveRel (const double &x, const double &y);
482 ////////////////////////////////////////////
483 // Animation **experimental**
484 ////////////////////////////////////////////
486 QTimer *animationTimer;
489 uint animationInterval;
490 int timerId; // animation timer
491 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
494 void animate(); //!< Called by timer to animate stuff
496 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
497 void stopAnimation(MapObj *mo);
499 ////////////////////////////////////////////
501 ////////////////////////////////////////////
503 /*! \brief Networking states
505 In Network modus we want to switch of saveState, autosave, ...
508 Offline, //!< Offline
509 Client, //!< I am the client and connected to server
510 Server //!< I am the server
514 // Network connections **Experimental**
515 NetState netstate; // offline, client, server
516 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
517 QList <QTcpSocket*> clientList; // List of connected clients
518 quint16 sendCounter; // Increased with every sent command
520 QTcpSocket *clientSocket; // socket of this client
521 QString server; // server address of this client
522 int port; // server port of this client
527 void sendSelection();
531 void connectToServer();
535 void sendData(const QString &s);
537 void displayNetworkError (QAbstractSocket::SocketError);
539 ////////////////////////////////////////////
541 ////////////////////////////////////////////
544 AdaptorModel *adaptorModel; //FIXME-3
549 ////////////////////////////////////////////
551 ////////////////////////////////////////////
553 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
556 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
557 QItemSelectionModel* getSelectionModel();
559 void setSelectionBlocked(bool);
560 bool isSelectionBlocked();
562 bool select (); //! select by using common QItemSelectionModel
563 bool select (const QString &); //! Select by string
564 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
565 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
566 bool select (const QModelIndex &index); //! Select by ModelIndex
570 void emitShowSelection(); //!< Show selection in all views
572 void showSelection();
574 // void selectInt(LinkableMapObj*); //FIXME-4
577 void selectNextBranchInt(); // Increment number of branch
578 void selectPrevBranchInt(); //! Select the branch which would be above in vymmap view
579 void selectAboveBranchInt(); //! Select the branch which would be above current selection in TreeView
580 void selectBelowBranchInt(); // Increment number of branch
582 void selectUpperBranch();
583 void selectLowerBranch();
584 void selectLeftBranch();
585 void selectRightBranch();
586 void selectFirstBranch();
587 void selectLastBranch();
588 void selectLastSelectedBranch();
592 TreeItem::Type selectionType();
593 LinkableMapObj* getSelectedLMO();
594 BranchObj* getSelectedBranchObj(); // FIXME-3 replace by item...
595 BranchItem* getSelectedBranchItem();
596 TreeItem* getSelectedItem();
597 QModelIndex getSelectedIndex();
598 ImageItem* getSelectedImageItem();
599 QString getSelectString ();
600 QString getSelectString (LinkableMapObj *lmo);
601 QString getSelectString (TreeItem *item);
605 void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
608 void updateSelection (const QItemSelection &newSel, const QItemSelection &delSel);
611 void emitSelectionChanged(const QItemSelection &oldsel);
612 void emitSelectionChanged();
613 void selectMapLinkColor();
614 void selectMapSelectionColor();
616 void setSelectionColorInt(QColor);
617 QItemSelectionModel *selModel;
618 QString lastSelectString;
619 bool selectionBlocked; //! Used to block changes of selection while editing a heading
622 void setSelectionColor(QColor);
623 QColor getSelectionColor();