Fixed problem with images included in branches. Added missing adaptormodel.* files
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"
21 class VymModel : public TreeModel {
23 Q_CLASSINFO("D-Bus Interface", "org.insilmaril.vym.VymModel-h")
26 ////////////////////////////////////////////
27 // General housekeeping
28 ////////////////////////////////////////////
30 QString version; //!< version string saved in vym file
40 void makeTmpDirectories(); //!< create temporary directories e.g. for history
42 MapEditor* getMapEditor(); // FIXME-2 still necessary?
44 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
46 void updateActions(); //!< Update buttons in mainwindow
49 ////////////////////////////////////////////
51 ////////////////////////////////////////////
54 bool zipped; // should map be zipped
55 static int mapNum; // unique number for model used in save/undo
56 FileType fileType; // type of file, e.g. vym, freemind...
57 QString fileName; // short name of file (for tab)
58 QString filePath; // path to file which will be saved
59 QString fileDir; // dir where file is saved
60 QString destPath; // path to .vym file (needed for vymlinks)
61 QString mapName; // fileName without ".vym"
63 QString tmpMapDir; // tmp directory with undo history
65 QTimer *autosaveTimer;
66 QTimer *fileChangedTimer;
67 QDateTime fileChangedTime;
70 /*! This function saves all information of the map to disc.
71 saveToDir also calls the functions for all BranchObj and other objects in the map.
72 The structure of the map itself is returned as QString and passed back to Main,
73 where saveToDir is called initially
75 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel);
77 /*! Save all data in tree*/
78 QString saveTreeToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
81 /*! \brief Sets filepath, filename and mapname
83 If the filepath is "/home/tux/map.xml", then the filename will be set
84 to map.xml. The destname is needed for vymLinks, pointing to another map.
85 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
89 /*! \brief Set File path
91 The destname is needed to construct the references between maps
93 void setFilePath (QString filepath,QString destname);
94 void setFilePath (QString); //!< Overloaded for convenience
95 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
96 QString getFileName (); //!< e.g. "map.xml"
97 QString getMapName (); //!< e.g. "map"
98 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
102 The data is read from file. Depending on LoadMode the current
103 selection gets replaced by data or the data is appended.
105 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
108 /*! \brief Save the map to file */
109 ErrorCode save(const SaveMode &);
112 void addMapReplaceInt(const QString & undoSel, const QString & path);
113 void addMapInsertInt (const QString & path, int pos);
115 ImageItem* loadFloatImageInt (BranchItem *dst,QString);
116 void saveFloatImageInt (ImageItem*, const QString &, const QString &);
118 void loadFloatImage ();
119 void saveFloatImage ();
122 void importDirInt(BranchObj *,QDir);
123 void importDirInt(const QString&);
131 ////////////////////////////////////////////
132 // history (undo/redo)
133 ////////////////////////////////////////////
135 bool mapDefault; //!< Flag if map is untouched
136 bool mapChanged; //!< Flag if undo is possible
137 bool mapUnsaved; //!< Flag if map should be saved
139 QString histPath; //!< Path to history file
140 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
141 int stepsTotal; //!< total number of steps (undos+redos)
142 int curStep; //!< Current step in history (ring buffer)
143 int curClipboard; //!< number of history step, which is the current clipboard
144 int redosAvail; //!< Available number of redo steps
145 int undosAvail; //!< Available number of undo steps
146 bool blockReposition; //!< block while load or undo
147 bool blockSaveState; //!< block while load or undo
149 bool isDefault(); //!< true, if map is still the empty default map
150 void makeDefault(); //!< Reset changelog, declare this as default map
151 bool hasChanged() ; //!< true, if something has changed and is not saved yet
152 void setChanged(); //!< called from TextEditor via LinkableMapObj
154 /*! \brief Get name of object
156 Returns heading of a branch or name of an object for use in comment
159 QString getObjectName(LinkableMapObj*);
160 QString getObjectName(TreeItem*);
162 void redo(); //!< Redo last action
163 bool isRedoAvailable(); //!< True, if redo is available
164 void undo(); //!< Undo last action
165 bool isUndoAvailable(); //!< True, if undo is available
166 void gotoHistoryStep (int); //!< Goto a specifig step in history
169 QString getHistoryPath(); //!< Path to directory containing the history
171 /*! \brief Save the current changes in map
173 Two commands and selections are saved:
175 - undocommand and undoselection to undo the change
176 - redocommand and redoselection to redo the action after an undo
178 Additionally a comment is logged.
182 const SaveMode& savemode,
183 const QString &undoSelection,
184 const QString &undoCommand,
185 const QString &redoSelection,
186 const QString &redoCommand,
187 const QString &comment,
188 TreeItem *saveSelection);
189 /*! Overloaded for convenience */
190 void saveStateChangingPart(
191 TreeItem *undoSelection,
192 TreeItem* redoSelection,
193 const QString &redoCommand,
194 const QString &comment);
195 /*! Overloaded for convenience */
196 void saveStateRemovingPart(
197 TreeItem *redoSelection,
198 const QString &comment);
199 /*! Overloaded for convenience */
201 TreeItem *undoSelection,
202 const QString &undoCommand,
203 TreeItem *redoSelection,
204 const QString &redoCommand,
205 const QString &comment);
206 /*! Overloaded for convenience */
208 const QString &undoSelection,
209 const QString &undoCommand,
210 const QString &redoSelection,
211 const QString &redoCommand,
212 const QString &comment) ;
214 const QString &undoCommand,
215 const QString &redoCommand,
216 const QString &comment) ;
219 ////////////////////////////////////////////
221 ////////////////////////////////////////////
223 QGraphicsScene *mapScene;
225 void setScene(QGraphicsScene *s);
226 QGraphicsScene *getScene();
228 TreeItem* findBySelectString (QString s);
229 TreeItem* findID (const QString &s); // find MapObj by previously set ID
232 ////////////////////////////////////////////
234 ////////////////////////////////////////////
236 void setVersion(const QString &);
237 void setAuthor (const QString &);
238 QString getAuthor ();
239 void setComment (const QString &);
240 QString getComment ();
245 void setHeading(const QString &); //!< Set heading of item
246 QString getHeading (); //!< Get heading of item
249 BranchItem* findCurrent; // next object in find process
250 BranchItem* findPrevious; // next object in find process
251 bool EOFind; // true, if search failed
253 BranchItem* findText(QString,bool); // Find object
254 void findReset(); // Reset Search
256 void setURL(const QString &url);
257 QString getURL(); // returns URL of selection or ""
258 QStringList getURLs(); // returns URLs of subtree
261 void setFrameType(const FrameObj::FrameType &);
262 void setFrameType(const QString &);
263 void setFramePenColor (const QColor &);
264 void setFrameBrushColor (const QColor &);
265 void setFramePadding (const int &);
266 void setFrameBorderWidth (const int &);
267 void setIncludeImagesVer(bool);
268 void setIncludeImagesHor(bool);
269 void setHideLinkUnselected (bool);
271 /*! Should object be hidden in exports (clouded)? */
272 void setHideExport(bool);
274 /*! Should object be hidden in exports (clouded)? */
275 void toggleHideExport();
277 void copy(); //!< Copy to clipboard
279 void pasteNoSave(const int &n); //!< paste clipboard to branch
281 void paste(); //!< Paste clipboard to branch and backup
282 void cut(); //!< Cut to clipboard (and copy)
284 void moveUp(); //!< Move branch up
285 void moveDown(); //!< Move branch down
286 void sortChildren(); //!< Sort children lexically
288 // The create methods are used to quickly parse a XML file
289 BranchItem* createMapCenter(); //!< Create MapCenter
290 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
291 ImageItem* createImage(BranchItem *dst); //!< Create image
293 /*! \brief Add new mapcenter
295 Disclaimer: Still experimental, not fully supported yet.
297 BranchItem* addMapCenter();
299 BranchItem* addMapCenter(QPointF absPos);
301 /*! \brief Add new branch
303 Depending on num the new branch is created
305 -3 above selection as child of selections parent
306 -2 as child of selection
307 -1 below selection as child of selections parent
308 0..n insert at a specific position in selections parent
309 (needed for free relinking)
313 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
317 Depending on num the new branch is created
319 0 as child of selection
322 BranchItem* addNewBranch(int pos=0);
323 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
324 /*! \brief Relink a branch to a new destination dst
325 Relinks branch to dst at branch position pos. There is no saveState
326 here, as for example moveUp or moving in MapEditor have
327 different needs to call saveState
328 Returns true if relinking was successful.
330 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
331 bool relinkImage (ImageItem* image, BranchItem* dst);
333 void deleteSelection(); //!< Delete selection
334 void deleteKeepChildren(); //!< remove branch, but keep children
335 void deleteChildren(); //!< keep branch, but remove children
338 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
339 bool scrollBranch(BranchItem *);
340 bool unscrollBranch(BranchItem *);
343 void unscrollChildren();
344 void emitExpandAll();
349 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
350 void addFloatImage(const QPixmap &img);
352 void colorBranch(QColor);
353 void colorSubtree(QColor);
354 QColor getCurrentHeadingColor();
357 void editURL(); // edit URL
358 void editLocalURL(); // edit URL to local file
359 void editHeading2URL(); // copy heading to URL
360 void editBugzilla2URL(); // create URL to Bugzilla
361 void editFATE2URL(); // create URL to FATE
362 void editVymLink(); // edit link to another map
363 void setVymLink (const QString &); // Set vymLink for selection
364 void deleteVymLink(); // delete link to another map
365 QString getVymLink(); // return path to map
366 QStringList getVymLinks(); // return paths in subtree
367 void followXLink (int);
368 void editXLink (int);
373 ////////////////////////////////////////////
375 ////////////////////////////////////////////
378 /* \brief Process one command and its parameters */
379 void parseAtom (const QString &atom);
381 /* \brief Runs the script */
382 void runScript (QString script);
387 ////////////////////////////////////////////
389 ////////////////////////////////////////////
391 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
394 /*! Set or unset temporary hiding of objects during export */
395 void setExportMode (bool);
398 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
401 /*! Export as XTML to directory */
402 void exportXML(QString dir="", bool askForName=true);
404 /*! Export as ASCII text to file */
405 void exportASCII (QString fname="",bool askForName=true);
407 /*! Export as XHTML to directory */
408 void exportXHTML(const QString& dir="", bool askForName=true);
410 /*! Export as OpenOfficeOrg presentation */
411 void exportOOPresentation(const QString &,const QString &);
414 ////////////////////////////////////////////
416 ////////////////////////////////////////////
418 void registerEditor (QWidget *);
419 void unregisterEditor (QWidget *);
422 QPointF contextPos; //!< local position during context menu
424 void setContextPos (QPointF); //!< local position during context menu
425 void unsetContextPos (); //!< forget local position after context menu
427 void updateNoteFlag(); //!< Signal origination in TextEditor
428 void updateRelPositions();
430 void reposition(); //!< Call reposition for all MCOs
431 void setHideTmpMode (TreeItem::HideTmpMode mode);
433 //FIXME-5 QPolygonF shape(BranchObj *bo); //!< Returns arbitrary shape of subtree
434 //FIXME-5 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
436 void emitNoteHasChanged (TreeItem *ti);
437 void emitDataHasChanged (TreeItem *ti);
440 void noteHasChanged (QModelIndex ix);
441 void newChildObject(QModelIndex ix);
444 MapEditor *mapEditor;
446 QColor defLinkColor; // default color for links
447 QColor defXLinkColor; // default color for xlinks
448 int defXLinkWidth; // default width for xlinks
449 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
450 LinkableMapObj::Style linkstyle; // default style for links
453 void setMapLinkStyle (const QString &); // Set style of link
454 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
455 void setMapDefLinkColor(QColor); // default color of links
456 void setMapLinkColorHintInt(); // color of links
457 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
458 void toggleMapLinkColorHint(); // after changing linkStyles
459 void selectMapBackgroundImage();
460 void setMapBackgroundImage(const QString &);
461 void selectMapBackgroundColor();
462 void setMapBackgroundColor(QColor);
463 QColor getMapBackgroundColor();
466 LinkableMapObj::ColorHint getMapLinkColorHint();
467 QColor getMapDefLinkColor();
468 void setMapDefXLinkColor(QColor);
469 QColor getMapDefXLinkColor();
470 void setMapDefXLinkWidth (int);
471 int getMapDefXLinkWidth();
473 /*! Move absolutly to (x,y). */
474 void move (const double &x, const double &y);
476 /*! Move relativly to (x,y). */
477 void moveRel (const double &x, const double &y);
479 ////////////////////////////////////////////
480 // Animation **experimental**
481 ////////////////////////////////////////////
483 QTimer *animationTimer;
486 uint animationInterval;
487 int timerId; // animation timer
488 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
491 void animate(); //!< Called by timer to animate stuff
493 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
494 void stopAnimation(MapObj *mo);
496 ////////////////////////////////////////////
498 ////////////////////////////////////////////
500 /*! \brief Networking states
502 In Network modus we want to switch of saveState, autosave, ...
505 Offline, //!< Offline
506 Client, //!< I am the client and connected to server
507 Server //!< I am the server
511 // Network connections **Experimental**
512 NetState netstate; // offline, client, server
513 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
514 QList <QTcpSocket*> clientList; // List of connected clients
515 quint16 sendCounter; // Increased with every sent command
517 QTcpSocket *clientSocket; // socket of this client
518 QString server; // server address of this client
519 int port; // server port of this client
524 void sendSelection();
528 void connectToServer();
532 void sendData(const QString &s);
534 void displayNetworkError (QAbstractSocket::SocketError);
536 ////////////////////////////////////////////
538 ////////////////////////////////////////////
541 AdaptorModel *adaptorModel; //FIXME-3
546 ////////////////////////////////////////////
548 ////////////////////////////////////////////
550 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
553 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
554 QItemSelectionModel* getSelectionModel();
556 void setSelectionBlocked(bool);
557 bool isSelectionBlocked();
559 bool select (); //! select by using common QItemSelectionModel
560 bool select (const QString &); //! Select by string
561 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
562 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
563 bool select (const QModelIndex &index); //! Select by ModelIndex
567 void emitShowSelection(); //!< Show selection in all views
569 void showSelection();
571 // void selectInt(LinkableMapObj*); //FIXME-4
574 void selectNextBranchInt(); // Increment number of branch
575 void selectPrevBranchInt(); //! Select the branch which would be above in vymmap view
576 void selectAboveBranchInt(); //! Select the branch which would be above current selection in TreeView
577 void selectBelowBranchInt(); // Increment number of branch
579 void selectUpperBranch();
580 void selectLowerBranch();
581 void selectLeftBranch();
582 void selectRightBranch();
583 void selectFirstBranch();
584 void selectLastBranch();
585 void selectLastSelectedBranch();
589 TreeItem::Type selectionType();
590 LinkableMapObj* getSelectedLMO();
591 BranchObj* getSelectedBranchObj(); // FIXME-3 replace by item...
592 BranchItem* getSelectedBranchItem();
593 TreeItem* getSelectedItem();
594 QModelIndex getSelectedIndex();
595 ImageItem* getSelectedImageItem();
596 QString getSelectString ();
597 QString getSelectString (LinkableMapObj *lmo);
598 QString getSelectString (TreeItem *item);
602 void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
605 void updateSelection (const QItemSelection &newSel, const QItemSelection &delSel);
608 void emitSelectionChanged(const QItemSelection &oldsel);
609 void emitSelectionChanged();
610 void selectMapLinkColor();
611 void selectMapSelectionColor();
613 void setSelectionColorInt(QColor);
614 QItemSelectionModel *selModel;
615 QString lastSelectString;
616 bool selectionBlocked; //! Used to block changes of selection while editing a heading
619 void setSelectionColor(QColor);
620 QColor getSelectionColor();