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&,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 uint &i); // find MapObj by unique ID
235 ////////////////////////////////////////////
237 ////////////////////////////////////////////
239 void setVersion(const QString &);
240 QString getVersion();
241 void setAuthor (const QString &);
242 QString getAuthor ();
243 void setComment (const QString &);
244 QString getComment ();
248 void setSortFilter (const QString &);
249 QString getSortFilter ();
253 void sortFilterChanged (QString ); //!< Notify editors of new filter
256 void setHeading(const QString &); //!< Set heading of item
257 QString getHeading (); //!< Get heading of item
258 void setNote(const QString &s); //!< Set note text
259 QString getNote(); //!< Get note text
262 BranchItem* findCurrent; // next object in find process
263 BranchItem* findPrevious; // next object in find process
264 bool EOFind; // true, if search failed
267 void findDuplicateURLs(); // find duplicate URLs, testing only so far
268 BranchItem* findText(QString,bool); // Find object
269 void findReset(); // Reset Search
270 void emitShowFindWidget(); // Tell views to show FindWidget
274 void showFindWidget();
277 void setURL(const QString &url);
278 QString getURL(); // returns URL of selection or ""
279 QStringList getURLs(bool ignoreScrolled=true); // returns URLs of subtree
282 void setFrameType(const FrameObj::FrameType &);
283 void setFrameType(const QString &);
284 void setFramePenColor (const QColor &);
285 void setFrameBrushColor (const QColor &);
286 void setFramePadding (const int &);
287 void setFrameBorderWidth (const int &);
288 void setIncludeImagesVer(bool);
289 void setIncludeImagesHor(bool);
290 void setHideLinkUnselected (bool);
292 /*! Should object be hidden in exports (clouded)? */
293 void setHideExport(bool);
295 /*! Should object be hidden in exports (clouded)? */
296 void toggleHideExport();
300 void copy(); //!< Copy to clipboard
302 void pasteNoSave(const int &n); //!< paste clipboard to branch
304 void paste(); //!< Paste clipboard to branch and backup
305 void cut(); //!< Cut to clipboard (and copy)
307 bool moveUp(BranchItem *bi); //!< Move branch up without saving state
308 void moveUp(); //!< Move branch up with saving state
309 bool moveDown(BranchItem *bi); //!< Move branch down without saving state
310 void moveDown(); //!< Move branch down
311 void detach(); //!< Detach branch and use as new mapcenter
312 void sortChildren(bool inverse=false); //!< Sort children lexically
314 // The create methods are used to quickly parse a XML file
315 BranchItem* createMapCenter(); //!< Create MapCenter
316 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
317 ImageItem* createImage(BranchItem *dst); //!< Create image
318 XLinkItem* createXLink(BranchItem *dst,bool createMO=false); //!< Create XLink starting at dst
320 AttributeItem* addAttribute();
321 AttributeItem* addAttribute(AttributeItem* );
323 /*! \brief Add new mapcenter
325 Disclaimer: Still experimental, not fully supported yet.
327 BranchItem* addMapCenter();
329 BranchItem* addMapCenter(QPointF absPos);
331 /*! \brief Add new branch
333 Depending on num the new branch is created
335 -3 above selection as child of selections parent
336 -2 as child of selection
337 -1 below selection as child of selections parent
338 0..n insert at a specific position in selections parent
339 (needed for free relinking)
343 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
347 Depending on num the new branch is created
349 0 as child of selection
352 BranchItem* addNewBranch(int pos=0);
353 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
354 /*! \brief Relink a branch to a new destination dst
355 Relinks branch to dst at branch position pos. There is no saveState
356 here, as for example moveUp or moving in MapEditor have
357 different needs to call saveState
358 Returns true if relinking was successful.
360 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
361 bool relinkImage (ImageItem* image, BranchItem* dst);
363 void deleteSelection(); //!< Delete selection
364 void deleteKeepChildren(); //!< remove branch, but keep children
365 void deleteChildren(); //!< keep branch, but remove children
367 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
368 void clearItem (TreeItem* ti); //!< Remove all children of TreeItem ti
369 bool scrollBranch(BranchItem *);
370 bool unscrollBranch(BranchItem *);
373 void unscrollChildren();
374 void emitExpandAll();
375 void emitExpandOneLevel();
376 void emitCollapseOneLevel();
379 void expandOneLevel();
380 void collapseOneLevel();
383 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
384 void addFloatImage(const QPixmap &img);
386 void colorBranch(QColor);
387 void colorSubtree(QColor);
388 QColor getCurrentHeadingColor();
391 void editURL(); // edit URL
392 void editLocalURL(); // edit URL to local file
393 void editHeading2URL(); // copy heading to URL
394 void editBugzilla2URL(); // create URL to Bugzilla
395 void getBugzillaData(); // get data from Novell Bugzilla
396 void editFATE2URL(); // create URL to FATE
397 void editVymLink(); // edit link to another map
398 void setVymLink (const QString &); // Set vymLink for selection
399 void deleteVymLink(); // delete link to another map
400 QString getVymLink(); // return path to map
401 QStringList getVymLinks(); // return paths in subtree
402 void followXLink (int);
403 void editXLink (int);
408 ////////////////////////////////////////////
410 ////////////////////////////////////////////
413 /* \brief Process one command and its parameters */
414 QVariant parseAtom (const QString &atom, bool &noError, QString &errorMsg);
416 /* \brief Runs the script */
417 QVariant runScript (const QString &script);
422 ////////////////////////////////////////////
424 ////////////////////////////////////////////
426 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
429 /*! Set or unset temporary hiding of objects during export */
430 void setExportMode (bool);
433 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
436 /*! Export as XTML to directory */
437 void exportXML(QString dir="", bool askForName=true);
439 /*! Export as A&O report text to file */
440 void exportAO (QString fname="",bool askForName=true);
442 /*! Export as ASCII text to file */
443 void exportASCII (QString fname="",bool askForName=true);
445 /*! Export as HTML to directory */
446 void exportHTML(const QString& dir="", bool askForName=true);
447 void exportXHTML(const QString& dir="", bool askForName=true);
449 /*! Export as OpenOfficeOrg presentation */
450 void exportOOPresentation(const QString &,const QString &);
453 ////////////////////////////////////////////
455 ////////////////////////////////////////////
457 void registerEditor (QWidget *);
458 void unregisterEditor (QWidget *);
461 QPointF contextPos; //!< local position during context menu
463 void setContextPos (QPointF); //!< local position during context menu
464 void unsetContextPos (); //!< forget local position after context menu
466 void updateNoteFlag(); //!< Signal origination in TextEditor
467 void reposition(); //!< Call reposition for all MCOs
468 void setHideTmpMode (TreeItem::HideTmpMode mode);
470 void emitNoteHasChanged (TreeItem *ti);
471 void emitDataHasChanged (TreeItem *ti);
474 void noteHasChanged (QModelIndex ix);
475 void newChildObject(QModelIndex ix);
478 MapEditor *mapEditor;
480 QColor defLinkColor; // default color for links
481 QColor defXLinkColor; // default color for xlinks
482 int defXLinkWidth; // default width for xlinks
483 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
484 LinkableMapObj::Style linkstyle; // default style for links
487 void setMapLinkStyle (const QString &); // Set style of link
488 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
489 void setMapDefLinkColor(QColor); // default color of links
490 void setMapLinkColorHintInt(); // color of links
491 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
492 void toggleMapLinkColorHint(); // after changing linkStyles
493 void selectMapBackgroundImage();
494 void setMapBackgroundImage(const QString &);
495 void selectMapBackgroundColor();
496 void setMapBackgroundColor(QColor);
497 QColor getMapBackgroundColor();
500 LinkableMapObj::ColorHint getMapLinkColorHint();
501 QColor getMapDefLinkColor();
502 void setMapDefXLinkColor(QColor);
503 QColor getMapDefXLinkColor();
504 void setMapDefXLinkWidth (int);
505 int getMapDefXLinkWidth();
507 /*! Move absolutly to (x,y). */
508 void move (const double &x, const double &y);
510 /*! Move relativly to (x,y). */
511 void moveRel (const double &x, const double &y);
513 ////////////////////////////////////////////
514 // Animation **experimental**
515 ////////////////////////////////////////////
517 QTimer *animationTimer;
520 uint animationInterval;
521 int timerId; // animation timer
522 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
525 void animate(); //!< Called by timer to animate stuff
527 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
528 void stopAnimation(MapObj *mo);
530 ////////////////////////////////////////////
532 ////////////////////////////////////////////
534 /*! \brief Networking states
536 In Network modus we want to switch of saveState, autosave, ...
539 Offline, //!< Offline
540 Client, //!< I am the client and connected to server
541 Server //!< I am the server
545 // Network connections **Experimental**
546 NetState netstate; // offline, client, server
547 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
548 QList <QTcpSocket*> clientList; // List of connected clients
549 quint16 sendCounter; // Increased with every sent command
551 QTcpSocket *clientSocket; // socket of this client
552 QString server; // server address of this client
553 int port; // server port of this client
558 void sendSelection();
562 void connectToServer();
566 void sendData(const QString &s);
568 void displayNetworkError (QAbstractSocket::SocketError);
570 ////////////////////////////////////////////
572 ////////////////////////////////////////////
575 AdaptorModel *adaptorModel; //FIXME-3
580 ////////////////////////////////////////////
582 ////////////////////////////////////////////
584 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
587 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
588 QItemSelectionModel* getSelectionModel();
590 void setSelectionBlocked(bool);
591 bool isSelectionBlocked();
593 bool select (); //! select by using common QItemSelectionModel
594 bool select (const QString &); //! Select by string
595 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
596 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
597 bool select (const QModelIndex &index); //! Select by ModelIndex
601 void emitShowSelection(); //!< Show selection in all views
603 void showSelection();
606 bool selectFirstBranch();
607 bool selectLastBranch();
608 bool selectLastSelectedBranch();
612 TreeItem::Type selectionType();
613 LinkableMapObj* getSelectedLMO();
614 BranchObj* getSelectedBranchObj(); // FIXME-3 replace by item...
615 BranchItem* getSelectedBranch();
616 ImageItem* getSelectedImage();
617 AttributeItem* getSelectedAttribute();
618 TreeItem* getSelectedItem();
619 QModelIndex getSelectedIndex();
620 QString getSelectString ();
621 QString getSelectString (LinkableMapObj *lmo);
622 QString getSelectString (TreeItem *item);
626 void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
629 void emitSelectionChanged(const QItemSelection &oldsel);
630 void emitSelectionChanged();
631 void selectMapLinkColor();
632 void selectMapSelectionColor();
634 void setSelectionColorInt(QColor);
635 QItemSelectionModel *selModel;
636 QString lastSelectString;
637 bool selectionBlocked; //! Used to block changes of selection while editing a heading
640 void setSelectionColor(QColor);
641 QColor getSelectionColor();