]> git.sven.stormbind.net Git - sven/vym.git/blob - src/vymmodel.h
Replace Pierre as the maintainer
[sven/vym.git] / src / vymmodel.h
1 #ifndef VYMMODEL_H
2 #define VYMMODEL_H
3
4 #include <QtNetwork>
5
6 #include <QPointF>
7 #include <QTextCursor>
8
9 #if defined(VYM_DBUS)
10 #include "adaptormodel.h"
11 #endif
12
13 #include "branchitem.h"
14 #include "file.h"
15 #include "imageitem.h"
16 #include "mapeditor.h"
17 #include "treeitem.h"
18 #include "treemodel.h"
19 #include "vymlock.h"
20 #include "vymmodelwrapper.h"
21
22 class AttributeItem;
23 class BranchItem;
24 class FindResultModel;
25 class Link;
26 class MapEditor;
27 class SlideItem;
28 class SlideModel;
29 class Task;
30 class XLinkItem;
31 class VymView;
32
33 class QGraphicsScene;
34 class QJsonObject;
35
36 typedef QMap<uint, QStringList> ItemList;
37
38 class VymModel : public TreeModel {
39     Q_OBJECT
40     Q_CLASSINFO("D-Bus Interface", "org.insilmaril.vym.VymModel-h")
41
42     ////////////////////////////////////////////
43     // General housekeeping
44     ////////////////////////////////////////////
45   private:
46     QString version; //!< version string saved in vym file
47     QString title;
48     QString author;
49     QString comment;
50     QDate date;
51
52     static uint idLast; //! the last used unique ID
53     uint modelID;
54     VymModelWrapper *wrapper;
55
56   public:
57     VymModel();
58     ~VymModel();
59     void clear();
60     void init();
61     void
62     makeTmpDirectories(); //!< create temporary directories e.g. for history
63     QString tmpDirPath(); //!< Return path to temporary directory
64
65     MapEditor *getMapEditor();
66     uint getModelID(); //! Return unique ID of model
67     VymModelWrapper *getWrapper();
68
69     void setView(VymView *); //! Set vymView for resizing editors after load
70   private:
71     VymView *vymView;
72
73   public:
74     bool isRepositionBlocked(); //!< While load or undo there is no need to
75                                 //!< update graphicsview
76     void updateActions();       //!< Update buttons in mainwindow
77
78     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
79
80     ////////////////////////////////////////////
81     // Load/save
82     ////////////////////////////////////////////
83   private:
84     bool zipped;       // should map be zipped
85     static int mapNum; // unique number for model used in save/undo
86     FileType fileType; // type of file, e.g. vym, freemind...
87     QString fileName;  // short name of file (for tab)
88                       // example.vym
89
90     QString filePath; // path to file which will be saved
91                       // /home/tux/example.vym
92
93     QString fileDir; // dir where file is saved
94                      // /home/tux/
95
96     QString destPath; // path to .vym file (needed for vymlinks)
97                       // /home/tux/example.vym
98
99     QString mapName; // fileName without ".vym"
100                      // example
101
102     QString tmpMapDirPath; // tmp directory with undo history
103
104     QTimer *autosaveTimer;
105     QTimer *fileChangedTimer;
106     QDateTime fileChangedTime;
107
108   public:
109     void resetUsedFlags(); //! Before exports or saving, reset the flags
110
111     /*! This function saves all information of the map to disc.
112     saveToDir also calls the functions for all BranchObj and other objects in
113     the map. The structure of the map itself is returned as QString and passed
114     back to Main, where saveToDir is called initially
115     */
116     QString saveToDir(const QString &tmpdir, const QString &prefix,
117                       FlagRowMaster::WriteMode flagMode, const QPointF &offset,
118                       TreeItem *saveSel);
119
120     /*! Save all data in tree*/
121     QString
122     saveTreeToDir(const QString &, const QString &, const QPointF &,
123                   QList<Link *> &tmpLinks); // Save data recursivly to tempdir
124
125     /*! \brief Sets filepath, filename and mapname
126
127      If the filepath is "/home/tux/map.xml", then the filename will be set
128      to map.xml. The destname is needed for vymLinks, pointing to another map.
129      The destname holds the real name of the file, after it has been compressed,
130      e.g. "map.vym"
131     */
132
133     /*! \brief Set File path
134
135      The destname is needed to construct the references between maps
136     */
137     void setFilePath(QString filepath, QString destname);
138     void setFilePath(QString); //!< Overloaded for convenience
139     QString getFilePath();     //!< Full path e.g. "/home/tux/map.xml"
140     QString getFileDir();      //!< e.g. "/home/tux"
141     QString getFileName();     //!< e.g. "map.xml"
142     QString getMapName();      //!< e.g. "map"
143     QString getDestPath();     //!< e.g. "/home/tux/map.vym"
144
145     bool parseVymText(const QString &s);
146
147     /*! \brief Load map
148
149     The data is read from file. Depending on LoadMode the current
150     selection gets replaced by data or the data is appended.
151     */
152     File::ErrorCode
153     loadMap(QString, //!< Path
154             const LoadMode &lmode =
155                 NewMap, //!< New map, replace or add to selection
156             const FileType &ftype = VymMap, //!< VymMap or FreeMind
157             const int &contentFilter =
158                 0x0000,  //!< For undo types of content can be filterd
159             int pos = -1 //!< Optionally tell position where to add data
160     );
161
162   public:
163     /*! \brief Save the map to file */
164     File::ErrorCode save(const SaveMode &);
165
166   public:
167     ImageItem* loadImage(BranchItem *dst = NULL, const QString &fn = "");
168     void saveImage(ImageItem *ii = NULL, QString fn = "");
169
170   private:
171     void importDirInt(BranchItem *, QDir);
172
173   public:
174     void importDir(const QString &);
175     void importDir();
176
177   private:
178     bool removeVymLock();
179
180   public:
181     bool tryVymLock();
182     bool renameMap(const QString &newPath); //! Rename map and change lockfile
183     void setReadOnly(bool b);
184     bool isReadOnly();
185
186   private:
187     VymLock vymLock; //! Handle lockfiles and related information
188     bool readonly;   //! if map is locked, it can be opened readonly
189
190   private slots:
191     void autosave();
192     void fileChanged();
193
194     ////////////////////////////////////////////
195     // history (undo/redo)
196     ////////////////////////////////////////////
197   private:
198     bool mapDefault; //!< Flag if map is untouched
199     bool mapChanged; //!< Flag if undo is possible
200     bool mapUnsaved; //!< Flag if map should be saved
201
202     QString histPath;       //!< Path to history file
203     SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
204     int stepsTotal;         //!< total number of steps (undos+redos)
205     int curStep;            //!< Current step in history (ring buffer)
206     int curClipboard;       //!< number of history step, which is the current
207                             //!< clipboard
208     int redosAvail;         //!< Available number of redo steps
209     int undosAvail;         //!< Available number of undo steps
210     bool repositionBlocked; //!< block while load or undo
211     bool saveStateBlocked;  //!< block saving current state
212   public:
213     void blockReposition();   //! Block reposition while bigger changes, e.g. an import
214     void unblockReposition(); //! Unblock reposition and do repositon
215     bool isDefault();   //!< true, if map is still the empty default map
216     void makeDefault(); //!< Reset changelog, declare this as default map
217     bool hasChanged();  //!< true, if something has changed and is not saved yet
218     void setChanged();  //!< called from TextEditor via LinkableMapObj
219
220     /*! \brief Get name of object
221
222       Returns heading of a branch or name of an object for use in comment
223       of undo/redo history
224     */
225     QString getObjectName(LinkableMapObj *);
226     QString getObjectName(TreeItem *);
227
228     void redo();            //!< Redo last action
229     bool isRedoAvailable(); //!< True, if redo is available
230     QString lastRedoSelection();
231     QString lastRedoCommand();
232     QVariant repeatLastCommand(); //!< Repeat last command on current selection
233
234     void undo();               //!< Undo last action
235     bool isUndoAvailable();    //!< True, if undo is available
236     void gotoHistoryStep(int); //!< Goto a specifig step in history
237
238     QString getHistoryPath(); //!< Path to directory containing the history
239     void resetHistory();      //!< Initialize history
240
241     /*! \brief Save the current changes in map
242
243     Two commands and selections are saved:
244
245         - undocommand and undoselection to undo the change
246         - redocommand and redoselection to redo the action after an undo
247
248     Additionally a comment is logged.
249
250     */
251     void saveState(const SaveMode &savemode, const QString &undoSelection,
252                    const QString &undoCommand, const QString &redoSelection,
253                    const QString &redoCommand, const QString &comment,
254                    TreeItem *saveSelection, QString dataXML = "");
255
256     /*! Overloaded for convenience */
257     void saveStateChangingPart(TreeItem *undoSelection, TreeItem *redoSelection,
258                                const QString &redoCommand,
259                                const QString &comment);
260
261     /*! Overloaded for convenience */
262     void saveStateRemovingPart(TreeItem *redoSelection, const QString &comment);
263
264     /*! Overloaded for convenience */
265     void saveState(TreeItem *undoSelection, const QString &undoCommand,
266                    TreeItem *redoSelection, const QString &redoCommand,
267                    const QString &comment);
268
269     /*! Overloaded for convenience */
270     void saveState(const QString &undoSelection, const QString &undoCommand,
271                    const QString &redoSelection, const QString &redoCommand,
272                    const QString &comment);
273
274     /*! Overloaded for convenience */
275     void saveState(const QString &undoCommand, const QString &redoCommand,
276                    const QString &comment);
277
278     /*! Save a change in string and merge
279     minor sequential  changes  */
280     void saveStateMinimal(TreeItem *undoSelection, const QString &undoCommand,
281                           TreeItem *redoSelection, const QString &redoCommand,
282                           const QString &comment);
283
284     /*! Save state before loading a map */
285     void saveStateBeforeLoad(LoadMode lmode, const QString &fname);
286
287     ////////////////////////////////////////////
288     // unsorted so far
289     ////////////////////////////////////////////
290   public:
291     QGraphicsScene *getScene();
292
293     TreeItem *findBySelectString(QString s);
294     TreeItem *findID(const uint &i);    // find MapObj by unique ID
295     TreeItem *findUuid(const QUuid &i); // find MapObj by unique ID
296
297     ////////////////////////////////////////////
298     // Interface
299     ////////////////////////////////////////////
300   public:
301     void setVersion(const QString &);
302     QString getVersion();
303     void setTitle(const QString &);
304     QString getTitle();
305     void setAuthor(const QString &);
306     QString getAuthor();
307     void setComment(const QString &);
308     QString getComment();
309     QString getDate();
310     int branchCount();
311     int centerCount();
312
313     void setSortFilter(const QString &);
314     QString getSortFilter();
315
316   protected:
317     QString sortFilter;
318   signals:
319     void sortFilterChanged(QString); //!< Notify editors of new filter
320
321   public:
322     void setHeading(const VymText &vt,
323                     BranchItem *bi = NULL); //!< Set heading of item
324     void setHeadingPlainText(const QString &s,
325                              BranchItem *bi = NULL); //!< Set heading of item
326     Heading getHeading();                            //!< Get heading of item
327     void updateNoteText(
328         const VymText &); //!< Signal emmited in NoteEditor via MainWindow
329     void setNote(const VymNote &vn);  //!< Set note text
330     VymNote getNote();                //!< Get note text
331     bool hasRichTextNote();           //!< Check type of vymText used
332     void loadNote(const QString &fn); //!< Load note from file
333     void saveNote(const QString &fn); //!< Save note to file
334
335   private:
336     BranchItem *findCurrent;  // next object in find process
337     BranchItem *findPrevious; // next object in find process
338     bool EOFind;              // true, if search failed
339
340   public:
341     void findDuplicateURLs();       // find duplicate URLs, testing only so far
342     bool findAll(FindResultModel *, // Search all objects at once, also notes
343                  QString s, Qt::CaseSensitivity cs = Qt::CaseInsensitive,
344                  bool searchNotes = true);
345
346   private:
347     QString findString;
348
349   public:
350     void setURL(QString url, bool updateFromCloud = true, BranchItem *bi = nullptr);
351     QString getURL(); // returns URL of selection or ""
352     QStringList getURLs(bool ignoreScrolled = true); // returns URLs of subtree
353
354     void setFrameType(const FrameObj::FrameType &);
355     void setFrameType(const QString &);
356     void toggleFrameIncludeChildren();
357     void setFrameIncludeChildren(bool);
358     void setFramePenColor(const QColor &);
359     void setFrameBrushColor(const QColor &);
360     void setFramePadding(const int &);
361     void setFrameBorderWidth(const int &);
362     void setIncludeImagesVer(bool);
363     void setIncludeImagesHor(bool);
364     void setChildrenLayout(BranchItem::LayoutHint layoutHint);
365     void setHideLinkUnselected(bool);
366
367     /*! Should object be hidden in exports (clouded)? */
368     void setHideExport(bool, TreeItem *ti = NULL);
369
370     /*! Should object be hidden in exports (clouded)? */
371     void toggleHideExport();
372
373     /*! Toggle task for branch */
374     void toggleTask();
375
376     /*! Cycle through task states */
377     bool cycleTaskStatus(bool reverse = false);
378
379     /*! Set task to sleep for number of days or until a given date*/
380     bool setTaskSleep(const QString &s);
381
382     /*! Set manual delta for priority of task */
383     void setTaskPriorityDelta(const int &n, BranchItem *bi = nullptr);
384
385     /*! Get manual delta for priority of task */
386     int getTaskPriorityDelta();
387
388     /*! count tasks in this model */
389     int taskCount();
390
391     /*! Update task priorities */
392   private slots:
393     void updateTasksAlarm(bool force = false);
394
395   private:
396     /*! Timer to check if tasks need to be awoken */
397     QTimer *taskAlarmTimer;
398
399   public:
400     BranchItem *addTimestamp();
401
402     void copy();  //!< Copy to clipboard
403     void paste(); //!< Paste clipboard to branch and backup
404     void cut();   //!< Cut to clipboard (and copy)
405
406     bool moveUp(BranchItem *bi);   //!< Move branch up without saving state
407     void moveUp();                 //!< Move branch up with saving state
408     bool moveDown(BranchItem *bi); //!< Move branch down without saving state
409     void moveDown();               //!< Move branch down
410     void moveUpDiagonally();       //!< Move branch up diagonally: Branchs becomes child of branch above
411     void moveDownDiagonally();     //!< Move branch down diagonally: Branchs becomes sibling of parent
412     void detach();                 //!< Detach branch and use as new mapcenter
413     void sortChildren(bool inverse = false); //!< Sort children lexically
414
415     // The create methods are used to quickly parse a XML file
416     BranchItem *createMapCenter();             //!< Create MapCenter
417     BranchItem *createBranch(BranchItem *dst); //!< Create Branch
418     ImageItem *createImage(BranchItem *dst);   //!< Create image
419
420   public:
421     bool createLink(
422         Link *l); //!< Create XLink, will create MO automatically if needed
423     QColor getXLinkColor();
424     int getXLinkWidth();
425     Qt::PenStyle getXLinkStyle();
426     QString getXLinkStyleBegin();
427     QString getXLinkStyleEnd();
428
429     AttributeItem *setAttribute();
430     AttributeItem *setAttribute(BranchItem *dst, AttributeItem *);
431
432     /*! \brief Add new mapcenter
433
434     Disclaimer: Still experimental, not fully supported yet.
435     */
436     BranchItem *addMapCenter(bool saveStateFlag = true);
437     BranchItem *addMapCenter(QPointF absPos);
438
439     /*! \brief Add new branch
440
441     Depending on num the new branch is created
442
443     -3 above selection as child of selections parent
444     -2 as child of selection
445     -1 below selection as child of selections parent
446     0..n        insert at a specific position in selections parent
447     (needed for free relinking)
448     */
449
450   private:
451     BranchItem *addNewBranchInt(BranchItem *dst,
452                                 int pos); // pos allows to add above/below
453                                           // selection, or as child  at pos
454   public:
455     /*! \Add new branch
456
457     // Depending on pos:
458     // -3       insert in children of parent  above selection
459     // -2       add branch to selection
460     // -1       insert in children of parent below selection
461     // 0..n     insert in children of parent at pos
462     */
463     BranchItem *addNewBranch(BranchItem *bi = NULL, int pos = -2);
464     BranchItem *
465     addNewBranchBefore(); //!< Insert branch between selection and its parent
466     /*! \brief Relink a branch to a new destination dst
467     Relinks branch to dst at branch position pos. There is no saveState
468     here, as for example moveUp or moving in MapEditor have
469     different needs to call saveState
470     Returns true if relinking was successful.
471     */
472     bool relinkBranch(BranchItem *branch, BranchItem *dst, int pos = -1,
473                       bool updateSelection = false, QPointF orgPos = QPointF());
474     bool relinkImage(ImageItem *image, BranchItem *dst);
475
476     bool relinkTo(const QString &dest, int num, QPointF pos);
477
478   private:
479     bool cleaningUpLinks; //!< True while cleaning up to avoid recursion
480   public:
481     void cleanupItems();    //!< Delete orphaned Items
482     void deleteLater(uint); //!< Delete later with new beginRemoveRow
483     void deleteSelection(); //!< Delete selection
484     void deleteKeepChildren(
485         bool saveStateFlag = true); //!< remove branch, but keep children
486   public:
487     void deleteChildren(); //!< keep branch, but remove children
488
489     TreeItem *deleteItem(
490         TreeItem *); //!< Delete item and return parent (if parent!= rootItem)
491     void deleteLink(Link *); //!< Remove Link and related LinkItems in TreeModel
492     void clearItem(TreeItem *ti); //!< Remove all children of TreeItem ti
493     bool scrollBranch(BranchItem *);
494     bool unscrollBranch(BranchItem *);
495     void toggleScroll();
496     void unscrollChildren();
497     void setScaleFactor(qreal, ImageItem *ii = nullptr);
498     void growSelectionSize();
499     void shrinkSelectionSize();
500     void resetSelectionSize();
501     void emitExpandAll();
502     void emitExpandOneLevel();
503     void emitCollapseOneLevel();
504     void emitCollapseUnselected();
505   signals:
506     void expandAll();
507     void expandOneLevel();
508     void collapseOneLevel();
509     void collapseUnselected();
510
511   public:
512     void toggleTarget();
513     ItemList getLinkedMaps();
514     ItemList getTargets();
515
516   private:
517     Flag* findFlagByName(const QString &name);
518   public:
519     void setFlagByName(const QString &name, bool useGroups = true);
520     void unsetFlagByName(const QString &name);
521     void toggleFlagByName(const QString &name, bool useGroups = true);
522     void toggleFlagByUid(const QUuid &uid, bool useGroups = true);
523     void clearFlags();
524
525     void colorBranch(QColor);
526     void colorSubtree(QColor, BranchItem *bi = NULL);
527     QColor getCurrentHeadingColor();
528
529     void note2URLs();                    // get URLs from note
530     void editHeading2URL();              // copy heading to URL
531     void getJiraData(bool subtree = true);      // get data from Jira
532
533   public slots:
534     void updateJiraData(QJsonObject);
535
536   public:
537     void setHeadingConfluencePageName(); // get page details from Confluence
538     void setVymLink(const QString &);    // Set vymLink for selection
539     void deleteVymLink();                // delete link to another map
540     QString getVymLink();                // return path to map
541     QStringList getVymLinks();           // return paths in subtree
542     void followXLink(int);
543     void editXLink();
544     void setXLinkColor(const QString &);
545     void setXLinkStyle(const QString &);
546     void setXLinkStyleBegin(const QString &);
547     void setXLinkStyleEnd(const QString &);
548     void setXLinkWidth(int);
549
550     ////////////////////////////////////////////
551     // Scripting
552     ////////////////////////////////////////////
553   public:
554     /* \brief Runs the script */
555     QVariant execute(const QString &script);
556
557     ////////////////////////////////////////////
558     // Exports
559     ////////////////////////////////////////////
560   private:
561     TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
562
563   public:
564     /*! Set or unset temporary hiding of objects during export  */
565     void setExportMode(bool);
566
567     /*! Save as image. Returns offset to upper left corner of image */
568     QPointF exportImage(QString fname = "", bool askForName = true,
569                         QString format = "PNG");
570
571     /*! Save as PDF  . Returns offset to upper left corner of image */
572     void exportPDF(QString fname = "", bool askForName = true);
573
574     /*! Save as SVG  . Returns offset to upper left corner of image */
575     QPointF exportSVG(QString fname = "", bool askForName = true);
576
577     /*! Export as XML to directory */
578     void exportXML(QString fname = "", QString dir = "", bool useDialog = true);
579
580     /*! Export as A&O report text to file */
581     void exportAO(QString fname = "", bool askForName = true);
582
583     /*! Export as ASCII text to file */
584     void exportASCII(const QString &fname = "", bool listTasks = false,
585                      bool askForName = true);
586
587     /*! Export as CSV text to file */
588     void exportCSV(const QString &fname = "", bool askForName = true);
589
590     /*! Export as Firefox bookmarks to JSON file */
591     void exportFirefoxBookmarks(const QString &fname = "", bool askForName = true);
592
593     /*! Export as HTML to directory */
594     void exportHTML(const QString &fname = "", const QString &dir = "", 
595                     bool useDialog = true);
596
597     /*! Export as HTML to Confluence*/
598     void exportConfluence(bool createPage = true, const QString &pageURL = "", 
599                     const QString &pageName = "", 
600                     bool useDialog = true);
601
602     /*! Export as OpenOfficeOrg presentation */
603     void exportImpress(const QString &, const QString &);
604
605     /*! Export agent might set export last command AFTER export
606      *  e.g. CreateConfluencePage might turn into UpdateConfluencePage */
607     void setExportLastCommand(const QString &cmd);
608     void setExportLastDescription(const QString &desc);
609     void setExportLastDestination(const QString &displayedDest);
610
611     /*! Returns if Export in recently used format is possible*/
612     bool exportLastAvailable(QString &description, QString &command,
613                              QString &dest);
614
615     /*! Export in recently used format (saved in map)*/
616     void exportLast();
617
618     /*! Export as LaTeX */
619     void exportLaTeX(const QString &fname = "", bool useDialog = true);
620
621     /*! Export as Markdown */
622     void exportMarkdown(const QString &fname = "", bool useDialog = true);
623
624     /*! Export as OrgMode input for emacs*/
625     void exportOrgMode(const QString &fname = "", bool useDialog = true);
626
627     ////////////////////////////////////////////
628     // View related
629     ////////////////////////////////////////////
630   public:
631     void registerMapEditor(QWidget *);
632
633     void setMapZoomFactor(const double &);
634     void setMapRotationAngle(const double &);
635     void setMapAnimDuration(const int &d);
636     void setMapAnimCurve(const QEasingCurve &c);
637     bool centerOnID(const QString &id);
638
639   private:
640     double zoomFactor;
641     double rotationAngle;
642     int animDuration;
643     QEasingCurve animCurve;
644
645     bool hasContextPos; //!< True, if we have a context pos
646     QPointF contextPos; //!< local position during context menu
647   public:
648     void setContextPos(QPointF); //!< local position during context menu
649     void unsetContextPos();      //!< forget local position after context menu
650
651     void reposition(); //!< Call reposition for all MCOs
652     void setHideTmpMode(TreeItem::HideTmpMode mode);
653
654     void emitNoteChanged(TreeItem *ti);
655     void emitDataChanged(TreeItem *ti);
656     void emitUpdateQueries(); //!< tell MainWindow to update find results...
657     void emitUpdateLayout();
658
659   signals:
660     void updateQueries(VymModel *m);
661     void updateLayout();
662     void noteChanged(QModelIndex ix);
663     void newChildObject(QModelIndex ix);
664
665   private:
666     MapEditor *mapEditor;
667
668     QColor defLinkColor;        // default color for links
669     QPen defXLinkPen;           // default pen for xlinks
670     QString defXLinkStyleBegin; // default style begin
671     QString defXLinkStyleEnd;
672     ;                                        // default style end
673     LinkableMapObj::ColorHint linkcolorhint; // use heading color or own color
674     LinkableMapObj::Style linkstyle;         // default style for links
675     QFont defaultFont;
676
677   public:
678     bool setMapLinkStyle(const QString &);   // Set style of link
679     LinkableMapObj::Style getMapLinkStyle(); // requested in LMO
680     void setMapDefLinkColor(QColor);         // default color of links
681     void setMapLinkColorHintInt();           // color of links
682     void setMapLinkColorHint(LinkableMapObj::ColorHint); // color of links
683     void toggleMapLinkColorHint(); // after changing linkStyles
684     void selectMapBackgroundImage();
685     void setMapBackgroundImage(const QString &);
686     void selectMapBackgroundColor();
687     void setMapBackgroundColor(QColor);
688     QColor getMapBackgroundColor();
689
690     QFont getMapDefaultFont();
691     void setMapDefaultFont(const QFont &);
692
693     LinkableMapObj::ColorHint getMapLinkColorHint();
694     QColor getMapDefLinkColor();
695     void setMapDefXLinkPen(const QPen &p);
696     QPen getMapDefXLinkPen();
697
698     void setMapDefXLinkStyleBegin(const QString &s);
699     QString getMapDefXLinkStyleBegin();
700     void setMapDefXLinkStyleEnd(const QString &s);
701     QString getMapDefXLinkStyleEnd();
702
703     /*!  Move absolutly to (x,y).  */
704     void move(const double &x, const double &y);
705
706     /*!  Move relativly to (x,y).  */
707     void moveRel(const double &x, const double &y);
708
709     ////////////////////////////////////////////
710     // Animation  **experimental**
711     ////////////////////////////////////////////
712   private:
713     QTimer *animationTimer;
714     bool animationUse;
715     uint animationTicks;
716     uint animationInterval;
717     int timerId;                 // animation timer
718     QList<MapObj *> animObjList; // list with animated objects
719
720   private slots:
721     void animate(); //!< Called by timer to animate stuff
722   public:
723     void startAnimation(BranchObj *bo, const QPointF &v);
724     void startAnimation(BranchObj *bo, const QPointF &start,
725                         const QPointF &dest);
726     void stopAnimation(MapObj *mo);
727     void stopAllAnimation();
728
729     ////////////////////////////////////////////
730     // Network related
731     ////////////////////////////////////////////
732   public:
733     /*! \brief Networking states
734
735     In Network modus we want to switch of saveState, autosave, ...
736     */
737     enum NetState {
738         Offline, //!< Offline
739         Client,  //!< I am the client and connected to server
740         Server   //!< I am the server
741     };
742
743   private:
744     // Network connections **Experimental**
745     NetState netstate;     // offline, client, server
746     QTcpServer *tcpServer; // Act as server in conference mode (experimental)
747     QList<QTcpSocket *> clientList; // List of connected clients
748     quint16 sendCounter;            // Increased with every sent command
749
750     QTcpSocket *clientSocket; // socket of this client
751     QString server;           // server address of this client
752     int port;                 // server port of this client
753
754   protected:
755     void sendSelection();
756
757   public:
758     void newServer();
759     void connectToServer();
760
761   private slots:
762     void newClient();
763     void sendData(const QString &s);
764     void readData();
765     void displayNetworkError(QAbstractSocket::SocketError);
766
767   public:
768     void downloadImage(const QUrl &url, BranchItem *bi = NULL);
769
770     ////////////////////////////////////////////
771     // Selection related
772     ////////////////////////////////////////////
773   private:
774     TreeItem *latestAddedItem; // latest added object, reset on setChanged()
775     QUuid lastToggledUuid;     // Latest toggled object 
776     QList<uint> selectionHistory;
777     int currentSelection;
778     bool keepSelectionHistory; // If set, selection doesn't change history
779
780   public slots:
781     void updateSelection(QItemSelection, QItemSelection); // update selection
782
783   public:
784     void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
785     QItemSelectionModel *getSelectionModel();
786
787     void setSelectionBlocked(bool);
788     bool isSelectionBlocked();
789
790     bool select(const QString &);          //! Select by string
791     bool selectID(const QString &);        //! select by unique ID (QUuid)
792     bool select(LinkableMapObj *lmo);      //! Select by pointer to LMO
793     bool selectToggle(TreeItem *ti);       //! Toggle select state
794     bool selectToggle(const QString &selectString); //! Overloaded function to toggle select state
795     bool select(TreeItem *ti);             //! Select by pointer to TreeItem
796     bool select(const QModelIndex &index); //! Select by ModelIndex
797     void unselectAll();
798     void unselect(QItemSelection desel);
799     bool reselect();
800     bool canSelectPrevious();
801     bool selectPrevious();
802     bool canSelectNext();
803     bool selectNext();
804     void resetSelectionHistory();
805     void appendSelectionToHistory();
806     void emitShowSelection(bool scaled = false); //!< Show selection in all views
807
808   signals:
809     void showSelection(bool scaled);
810
811   public:
812     TreeItem *lastToggledItem();
813     bool selectFirstBranch();
814     bool selectFirstChildBranch();
815     bool selectLastBranch();
816     bool selectLastChildBranch();
817     bool selectLastSelectedBranch();
818     bool selectLastImage();
819     bool selectLatestAdded();
820     bool selectParent();
821
822   public:
823     TreeItem::Type selectionType();
824     LinkableMapObj *getSelectedLMO();
825     BranchObj *getSelectedBranchObj();
826     BranchItem *getSelectedBranch();
827     QList<BranchItem *> getSelectedBranches();
828     ImageItem *getSelectedImage();
829     Task *getSelectedTask();
830     XLinkItem *getSelectedXLinkItem();
831     Link *getSelectedXLink();
832     AttributeItem *getSelectedAttribute();
833     TreeItem *getSelectedItem();
834     QList<TreeItem *> getSelectedItems();
835     QModelIndex getSelectedIndex();
836     QList<uint> getSelectedIDs();
837     QStringList getSelectedUUIDs();
838     bool isSelected(TreeItem *);
839     QString getSelectString();
840     QString getSelectString(LinkableMapObj *lmo);
841     QString getSelectString(TreeItem *item);
842     QString getSelectString(BranchItem *item);
843     QString getSelectString(const uint &i);
844     void setLatestAddedItem(TreeItem *ti);
845     TreeItem *getLatestAddedItem();
846
847   signals:
848     void selectionChanged(const QItemSelection &newsel,
849                           const QItemSelection &oldsel);
850
851   public:
852     void emitSelectionChanged(const QItemSelection &oldsel);
853     void emitSelectionChanged();
854     void selectMapLinkColor();
855     void selectMapSelectionColor();
856
857   private:
858     QItemSelectionModel *selModel;
859     QString lastSelectString;
860     bool selectionBlocked; //! Used to block changes of selection while editing
861                            //! a heading
862
863   public:
864     void setSelectionPenColor(QColor);
865     QColor getSelectionPenColor();
866     void setSelectionPenWidth(qreal);
867     qreal getSelectionPenWidth();
868     void setSelectionBrushColor(QColor);
869     QColor getSelectionBrushColor();
870
871     ////////////////////////////////////////////
872     // Iterating and selecting branches
873     ////////////////////////////////////////////
874   public:
875     bool initIterator(const QString &iname,
876                       bool deepLevelsFirst = false); //! Named iterator
877     bool nextIterator(const QString &iname);         //! Select next iterator
878   private:
879     QHash<QString, QUuid> selIterCur;
880     QHash<QString, QUuid> selIterPrev;
881     QHash<QString, QUuid> selIterStart;
882     QHash<QString, bool> selIterActive;
883
884     ////////////////////////////////////////////
885     // Slide related
886     ////////////////////////////////////////////
887   public:
888     SlideModel *getSlideModel();
889     int slideCount();
890     SlideItem *addSlide();
891     void deleteSlide(SlideItem *si);
892     void deleteSlide(int n);
893     void relinkSlide(SlideItem *si, int pos);
894     bool moveSlideDown(int n = -1);
895     bool moveSlideUp(int n = -1);
896     SlideItem *findSlideID(uint id);
897   public slots:
898     void updateSlideSelection(QItemSelection, QItemSelection);
899
900   private:
901     SlideModel *slideModel;
902     bool blockSlideSelection;
903 };
904
905 #endif