4 #include <QGraphicsScene>
7 #include <QtDBus/QDBusAbstractAdaptor>
8 #include <QtDBus/QDBusVariant>
10 #include <QTextCursor>
12 #include "adaptormodel.h"
14 #include "imageitem.h"
15 #include "mapeditor.h"
18 #include "treemodel.h"
22 class FindResultModel;
26 class VymModel : public TreeModel {
28 Q_CLASSINFO("D-Bus Interface", "org.insilmaril.vym.VymModel-h")
31 ////////////////////////////////////////////
32 // General housekeeping
33 ////////////////////////////////////////////
35 QString version; //!< version string saved in vym file
40 static uint idLast; //! the last used unique ID
48 void makeTmpDirectories(); //!< create temporary directories e.g. for history
50 MapEditor* getMapEditor(); // FIXME-2 still necessary?
51 uint getID(); //! Return unique ID of model
53 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
55 void updateActions(); //!< Update buttons in mainwindow
58 ////////////////////////////////////////////
60 ////////////////////////////////////////////
63 bool zipped; // should map be zipped
64 static int mapNum; // unique number for model used in save/undo
65 FileType fileType; // type of file, e.g. vym, freemind...
66 QString fileName; // short name of file (for tab)
67 QString filePath; // path to file which will be saved
68 QString fileDir; // dir where file is saved
69 QString destPath; // path to .vym file (needed for vymlinks)
70 QString mapName; // fileName without ".vym"
72 QString tmpMapDir; // tmp directory with undo history
74 QTimer *autosaveTimer;
75 QTimer *fileChangedTimer;
76 QDateTime fileChangedTime;
79 /*! This function saves all information of the map to disc.
80 saveToDir also calls the functions for all BranchObj and other objects in the map.
81 The structure of the map itself is returned as QString and passed back to Main,
82 where saveToDir is called initially
84 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel);
86 /*! Save all data in tree*/
87 QString saveTreeToDir (const QString&,const QString&,const QPointF&);// Save data recursivly to tempdir
90 /*! \brief Sets filepath, filename and mapname
92 If the filepath is "/home/tux/map.xml", then the filename will be set
93 to map.xml. The destname is needed for vymLinks, pointing to another map.
94 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
98 /*! \brief Set File path
100 The destname is needed to construct the references between maps
102 void setFilePath (QString filepath,QString destname);
103 void setFilePath (QString); //!< Overloaded for convenience
104 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
105 QString getFileName (); //!< e.g. "map.xml"
106 QString getMapName (); //!< e.g. "map"
107 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
111 The data is read from file. Depending on LoadMode the current
112 selection gets replaced by data or the data is appended.
114 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
117 /*! \brief Save the map to file */
118 ErrorCode save(const SaveMode &);
121 void addMapReplaceInt(const QString & undoSel, const QString & path);
122 bool addMapInsertInt (const QString & path);
123 bool addMapInsertInt (const QString & path, int pos);
125 ImageItem* loadFloatImageInt (BranchItem *dst,QString);
126 void saveFloatImageInt (ImageItem*, const QString &, const QString &);
128 void loadFloatImage ();
129 void saveFloatImage ();
132 void importDirInt(BranchItem *,QDir);
133 void importDirInt(const QString&);
141 ////////////////////////////////////////////
142 // history (undo/redo)
143 ////////////////////////////////////////////
145 bool mapDefault; //!< Flag if map is untouched
146 bool mapChanged; //!< Flag if undo is possible
147 bool mapUnsaved; //!< Flag if map should be saved
149 QString histPath; //!< Path to history file
150 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
151 int stepsTotal; //!< total number of steps (undos+redos)
152 int curStep; //!< Current step in history (ring buffer)
153 int curClipboard; //!< number of history step, which is the current clipboard
154 int redosAvail; //!< Available number of redo steps
155 int undosAvail; //!< Available number of undo steps
156 bool blockReposition; //!< block while load or undo
157 bool blockSaveState; //!< block while load or undo
159 bool isDefault(); //!< true, if map is still the empty default map
160 void makeDefault(); //!< Reset changelog, declare this as default map
161 bool hasChanged() ; //!< true, if something has changed and is not saved yet
162 void setChanged(); //!< called from TextEditor via LinkableMapObj
164 /*! \brief Get name of object
166 Returns heading of a branch or name of an object for use in comment
169 QString getObjectName(LinkableMapObj*);
170 QString getObjectName(TreeItem*);
172 void redo(); //!< Redo last action
173 bool isRedoAvailable(); //!< True, if redo is available
174 void undo(); //!< Undo last action
175 bool isUndoAvailable(); //!< True, if undo is available
176 void gotoHistoryStep (int); //!< Goto a specifig step in history
179 QString getHistoryPath(); //!< Path to directory containing the history
181 /*! \brief Save the current changes in map
183 Two commands and selections are saved:
185 - undocommand and undoselection to undo the change
186 - redocommand and redoselection to redo the action after an undo
188 Additionally a comment is logged.
192 const SaveMode& savemode,
193 const QString &undoSelection,
194 const QString &undoCommand,
195 const QString &redoSelection,
196 const QString &redoCommand,
197 const QString &comment,
198 TreeItem *saveSelection);
199 /*! Overloaded for convenience */
200 void saveStateChangingPart(
201 TreeItem *undoSelection,
202 TreeItem* redoSelection,
203 const QString &redoCommand,
204 const QString &comment);
205 /*! Overloaded for convenience */
206 void saveStateRemovingPart(
207 TreeItem *redoSelection,
208 const QString &comment);
209 /*! Overloaded for convenience */
211 TreeItem *undoSelection,
212 const QString &undoCommand,
213 TreeItem *redoSelection,
214 const QString &redoCommand,
215 const QString &comment);
216 /*! Overloaded for convenience */
218 const QString &undoSelection,
219 const QString &undoCommand,
220 const QString &redoSelection,
221 const QString &redoCommand,
222 const QString &comment) ;
224 const QString &undoCommand,
225 const QString &redoCommand,
226 const QString &comment) ;
229 ////////////////////////////////////////////
231 ////////////////////////////////////////////
233 QGraphicsScene *mapScene;
235 void setScene(QGraphicsScene *s);
236 QGraphicsScene *getScene();
238 TreeItem* findBySelectString (QString s);
239 TreeItem* findID (const uint &i); // find MapObj by unique ID
242 ////////////////////////////////////////////
244 ////////////////////////////////////////////
246 void setVersion(const QString &);
247 QString getVersion();
248 void setAuthor (const QString &);
249 QString getAuthor ();
250 void setComment (const QString &);
251 QString getComment ();
255 void setSortFilter (const QString &);
256 QString getSortFilter ();
260 void sortFilterChanged (QString ); //!< Notify editors of new filter
263 void setHeading(const QString &); //!< Set heading of item
264 QString getHeading (); //!< Get heading of item
265 void setNote(const QString &s); //!< Set note text
266 QString getNote(); //!< Get note text
269 BranchItem* findCurrent; // next object in find process
270 BranchItem* findPrevious; // next object in find process
271 bool EOFind; // true, if search failed
274 void findDuplicateURLs(); // find duplicate URLs, testing only so far
275 void findAll (FindResultModel*, QString s, Qt::CaseSensitivity cs); // Search all objects at once, also notes
276 BranchItem* findText(QString s,Qt::CaseSensitivity cs,QTextCursor &cursor); // Find object, also in note
277 void findReset(); // Reset Search
282 void setURL(const QString &url);
283 QString getURL(); // returns URL of selection or ""
284 QStringList getURLs(bool ignoreScrolled=true); // returns URLs of subtree
287 void setFrameType(const FrameObj::FrameType &);
288 void setFrameType(const QString &);
289 void setFramePenColor (const QColor &);
290 void setFrameBrushColor (const QColor &);
291 void setFramePadding (const int &);
292 void setFrameBorderWidth (const int &);
293 void setIncludeImagesVer(bool);
294 void setIncludeImagesHor(bool);
295 void setHideLinkUnselected (bool);
297 /*! Should object be hidden in exports (clouded)? */
298 void setHideExport(bool);
300 /*! Should object be hidden in exports (clouded)? */
301 void toggleHideExport();
305 void copy(); //!< Copy to clipboard
307 void pasteNoSave(const int &n); //!< paste clipboard to branch
309 void paste(); //!< Paste clipboard to branch and backup
310 void cut(); //!< Cut to clipboard (and copy)
312 bool moveUp(BranchItem *bi); //!< Move branch up without saving state
313 void moveUp(); //!< Move branch up with saving state
314 bool moveDown(BranchItem *bi); //!< Move branch down without saving state
315 void moveDown(); //!< Move branch down
316 void detach(); //!< Detach branch and use as new mapcenter
317 void sortChildren(bool inverse=false); //!< Sort children lexically
319 // The create methods are used to quickly parse a XML file
320 BranchItem* createMapCenter(); //!< Create MapCenter
321 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
322 ImageItem* createImage(BranchItem *dst); //!< Create image
323 XLinkItem* createXLink(BranchItem *dst,bool createMO=false); //!< Create XLink starting at dst
325 AttributeItem* addAttribute();
326 AttributeItem* addAttribute(AttributeItem* );
328 /*! \brief Add new mapcenter
330 Disclaimer: Still experimental, not fully supported yet.
332 BranchItem* addMapCenter();
334 BranchItem* addMapCenter(QPointF absPos);
336 /*! \brief Add new branch
338 Depending on num the new branch is created
340 -3 above selection as child of selections parent
341 -2 as child of selection
342 -1 below selection as child of selections parent
343 0..n insert at a specific position in selections parent
344 (needed for free relinking)
348 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
352 Depending on num the new branch is created
354 0 as child of selection
357 BranchItem* addNewBranch(int pos=0);
358 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
359 /*! \brief Relink a branch to a new destination dst
360 Relinks branch to dst at branch position pos. There is no saveState
361 here, as for example moveUp or moving in MapEditor have
362 different needs to call saveState
363 Returns true if relinking was successful.
365 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
366 bool relinkImage (ImageItem* image, BranchItem* dst);
368 void deleteSelection(); //!< Delete selection
369 void deleteKeepChildren(); //!< remove branch, but keep children
370 void deleteChildren(); //!< keep branch, but remove children
372 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
373 void clearItem (TreeItem* ti); //!< Remove all children of TreeItem ti
374 bool scrollBranch(BranchItem *);
375 bool unscrollBranch(BranchItem *);
378 void unscrollChildren();
379 void emitExpandAll();
380 void emitExpandOneLevel();
381 void emitCollapseOneLevel();
384 void expandOneLevel();
385 void collapseOneLevel();
388 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
389 void addFloatImage(const QPixmap &img);
391 void colorBranch(QColor);
392 void colorSubtree(QColor);
393 QColor getCurrentHeadingColor();
396 void editURL(); // edit URL
397 void editLocalURL(); // edit URL to local file
398 void editHeading2URL(); // copy heading to URL
399 void editBugzilla2URL(); // create URL to Bugzilla
400 void getBugzillaData(); // get data from Novell Bugzilla
401 void editFATE2URL(); // create URL to FATE
402 void editVymLink(); // edit link to another map
403 void setVymLink (const QString &); // Set vymLink for selection
404 void deleteVymLink(); // delete link to another map
405 QString getVymLink(); // return path to map
406 QStringList getVymLinks(); // return paths in subtree
407 void followXLink (int);
408 void editXLink (int);
413 ////////////////////////////////////////////
415 ////////////////////////////////////////////
418 /* \brief Process one command and its parameters */
419 QVariant parseAtom (const QString &atom, bool &noError, QString &errorMsg);
421 /* \brief Runs the script */
422 QVariant runScript (const QString &script);
427 ////////////////////////////////////////////
429 ////////////////////////////////////////////
431 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
434 /*! Set or unset temporary hiding of objects during export */
435 void setExportMode (bool);
438 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
441 /*! Export as XTML to directory */
442 void exportXML(QString dir="", bool askForName=true);
444 /*! Export as A&O report text to file */
445 void exportAO (QString fname="",bool askForName=true);
447 /*! Export as ASCII text to file */
448 void exportASCII (QString fname="",bool askForName=true);
450 /*! Export as HTML to directory */
451 void exportHTML(const QString& dir="", bool useDialog=true);
452 void exportXHTML(const QString& dir="", bool askForName=true);
454 /*! Export as OpenOfficeOrg presentation */
455 void exportOOPresentation(const QString &,const QString &);
458 ////////////////////////////////////////////
460 ////////////////////////////////////////////
462 void registerEditor (QWidget *);
463 void unregisterEditor (QWidget *);
466 QPointF contextPos; //!< local position during context menu
468 void setContextPos (QPointF); //!< local position during context menu
469 void unsetContextPos (); //!< forget local position after context menu
471 void updateNoteFlag(); //!< Signal origination in TextEditor
472 void reposition(); //!< Call reposition for all MCOs
473 void setHideTmpMode (TreeItem::HideTmpMode mode);
475 void emitNoteHasChanged (TreeItem *ti);
476 void emitDataHasChanged (TreeItem *ti);
479 void noteHasChanged (QModelIndex ix);
480 void newChildObject(QModelIndex ix);
483 MapEditor *mapEditor;
485 QColor defLinkColor; // default color for links
486 QColor defXLinkColor; // default color for xlinks
487 int defXLinkWidth; // default width for xlinks
488 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
489 LinkableMapObj::Style linkstyle; // default style for links
492 void setMapLinkStyle (const QString &); // Set style of link
493 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
494 void setMapDefLinkColor(QColor); // default color of links
495 void setMapLinkColorHintInt(); // color of links
496 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
497 void toggleMapLinkColorHint(); // after changing linkStyles
498 void selectMapBackgroundImage();
499 void setMapBackgroundImage(const QString &);
500 void selectMapBackgroundColor();
501 void setMapBackgroundColor(QColor);
502 QColor getMapBackgroundColor();
505 LinkableMapObj::ColorHint getMapLinkColorHint();
506 QColor getMapDefLinkColor();
507 void setMapDefXLinkColor(QColor);
508 QColor getMapDefXLinkColor();
509 void setMapDefXLinkWidth (int);
510 int getMapDefXLinkWidth();
512 /*! Move absolutly to (x,y). */
513 void move (const double &x, const double &y);
515 /*! Move relativly to (x,y). */
516 void moveRel (const double &x, const double &y);
518 ////////////////////////////////////////////
519 // Animation **experimental**
520 ////////////////////////////////////////////
522 QTimer *animationTimer;
525 uint animationInterval;
526 int timerId; // animation timer
527 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
530 void animate(); //!< Called by timer to animate stuff
532 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
533 void stopAnimation(MapObj *mo);
535 ////////////////////////////////////////////
537 ////////////////////////////////////////////
539 /*! \brief Networking states
541 In Network modus we want to switch of saveState, autosave, ...
544 Offline, //!< Offline
545 Client, //!< I am the client and connected to server
546 Server //!< I am the server
550 // Network connections **Experimental**
551 NetState netstate; // offline, client, server
552 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
553 QList <QTcpSocket*> clientList; // List of connected clients
554 quint16 sendCounter; // Increased with every sent command
556 QTcpSocket *clientSocket; // socket of this client
557 QString server; // server address of this client
558 int port; // server port of this client
563 void sendSelection();
567 void connectToServer();
571 void sendData(const QString &s);
573 void displayNetworkError (QAbstractSocket::SocketError);
575 ////////////////////////////////////////////
577 ////////////////////////////////////////////
580 AdaptorModel *adaptorModel; //FIXME-3
585 ////////////////////////////////////////////
587 ////////////////////////////////////////////
589 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
592 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
593 QItemSelectionModel* getSelectionModel();
595 void setSelectionBlocked(bool);
596 bool isSelectionBlocked();
598 bool select (); //! select by using common QItemSelectionModel
599 bool select (const QString &); //! Select by string
600 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
601 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
602 bool select (const QModelIndex &index); //! Select by ModelIndex
606 void emitShowSelection(); //!< Show selection in all views
608 void showSelection();
611 bool selectFirstBranch();
612 bool selectLastBranch();
613 bool selectLastSelectedBranch();
617 TreeItem::Type selectionType();
618 LinkableMapObj* getSelectedLMO();
619 BranchObj* getSelectedBranchObj(); // FIXME-3 replace by item...
620 BranchItem* getSelectedBranch();
621 ImageItem* getSelectedImage();
622 AttributeItem* getSelectedAttribute();
623 TreeItem* getSelectedItem();
624 QModelIndex getSelectedIndex();
625 QString getSelectString ();
626 QString getSelectString (LinkableMapObj *lmo);
627 QString getSelectString (TreeItem *item);
631 void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
634 void emitSelectionChanged(const QItemSelection &oldsel);
635 void emitSelectionChanged();
636 void selectMapLinkColor();
637 void selectMapSelectionColor();
639 void setSelectionColorInt(QColor);
640 QItemSelectionModel *selModel;
641 QString lastSelectString;
642 bool selectionBlocked; //! Used to block changes of selection while editing a heading
645 void setSelectionColor(QColor);
646 QColor getSelectionColor();