]> git.sven.stormbind.net Git - sven/vym.git/blob - src/vymmodel.h
New upstream version 2.9.22
[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     /*! Returns if Export in recently used format is possible*/
606     bool exportLastAvailable(QString &description, QString &command,
607                              QString &dest);
608
609     /*! Export in recently used format (saved in map)*/
610     void exportLast();
611
612     /*! Export as LaTeX */
613     void exportLaTeX(const QString &fname = "", bool useDialog = true);
614
615     /*! Export as Markdown */
616     void exportMarkdown(const QString &fname = "", bool useDialog = true);
617
618     /*! Export as OrgMode input for emacs*/
619     void exportOrgMode(const QString &fname = "", bool useDialog = true);
620
621     ////////////////////////////////////////////
622     // View related
623     ////////////////////////////////////////////
624   public:
625     void registerMapEditor(QWidget *);
626
627     void setMapZoomFactor(const double &);
628     void setMapRotationAngle(const double &);
629     void setMapAnimDuration(const int &d);
630     void setMapAnimCurve(const QEasingCurve &c);
631     bool centerOnID(const QString &id);
632
633   private:
634     double zoomFactor;
635     double rotationAngle;
636     int animDuration;
637     QEasingCurve animCurve;
638
639     bool hasContextPos; //!< True, if we have a context pos
640     QPointF contextPos; //!< local position during context menu
641   public:
642     void setContextPos(QPointF); //!< local position during context menu
643     void unsetContextPos();      //!< forget local position after context menu
644
645     void reposition(); //!< Call reposition for all MCOs
646     void setHideTmpMode(TreeItem::HideTmpMode mode);
647
648     void emitNoteChanged(TreeItem *ti);
649     void emitDataChanged(TreeItem *ti);
650     void emitUpdateQueries(); //!< tell MainWindow to update find results...
651     void emitUpdateLayout();
652
653   signals:
654     void updateQueries(VymModel *m);
655     void updateLayout();
656     void noteChanged(QModelIndex ix);
657     void newChildObject(QModelIndex ix);
658
659   private:
660     MapEditor *mapEditor;
661
662     QColor defLinkColor;        // default color for links
663     QPen defXLinkPen;           // default pen for xlinks
664     QString defXLinkStyleBegin; // default style begin
665     QString defXLinkStyleEnd;
666     ;                                        // default style end
667     LinkableMapObj::ColorHint linkcolorhint; // use heading color or own color
668     LinkableMapObj::Style linkstyle;         // default style for links
669     QFont defaultFont;
670
671   public:
672     bool setMapLinkStyle(const QString &);   // Set style of link
673     LinkableMapObj::Style getMapLinkStyle(); // requested in LMO
674     void setMapDefLinkColor(QColor);         // default color of links
675     void setMapLinkColorHintInt();           // color of links
676     void setMapLinkColorHint(LinkableMapObj::ColorHint); // color of links
677     void toggleMapLinkColorHint(); // after changing linkStyles
678     void selectMapBackgroundImage();
679     void setMapBackgroundImage(const QString &);
680     void selectMapBackgroundColor();
681     void setMapBackgroundColor(QColor);
682     QColor getMapBackgroundColor();
683
684     QFont getMapDefaultFont();
685     void setMapDefaultFont(const QFont &);
686
687     LinkableMapObj::ColorHint getMapLinkColorHint();
688     QColor getMapDefLinkColor();
689     void setMapDefXLinkPen(const QPen &p);
690     QPen getMapDefXLinkPen();
691
692     void setMapDefXLinkStyleBegin(const QString &s);
693     QString getMapDefXLinkStyleBegin();
694     void setMapDefXLinkStyleEnd(const QString &s);
695     QString getMapDefXLinkStyleEnd();
696
697     /*!  Move absolutly to (x,y).  */
698     void move(const double &x, const double &y);
699
700     /*!  Move relativly to (x,y).  */
701     void moveRel(const double &x, const double &y);
702
703     ////////////////////////////////////////////
704     // Animation  **experimental**
705     ////////////////////////////////////////////
706   private:
707     QTimer *animationTimer;
708     bool animationUse;
709     uint animationTicks;
710     uint animationInterval;
711     int timerId;                 // animation timer
712     QList<MapObj *> animObjList; // list with animated objects
713
714   private slots:
715     void animate(); //!< Called by timer to animate stuff
716   public:
717     void startAnimation(BranchObj *bo, const QPointF &v);
718     void startAnimation(BranchObj *bo, const QPointF &start,
719                         const QPointF &dest);
720     void stopAnimation(MapObj *mo);
721     void stopAllAnimation();
722
723     ////////////////////////////////////////////
724     // Network related
725     ////////////////////////////////////////////
726   public:
727     /*! \brief Networking states
728
729     In Network modus we want to switch of saveState, autosave, ...
730     */
731     enum NetState {
732         Offline, //!< Offline
733         Client,  //!< I am the client and connected to server
734         Server   //!< I am the server
735     };
736
737   private:
738     // Network connections **Experimental**
739     NetState netstate;     // offline, client, server
740     QTcpServer *tcpServer; // Act as server in conference mode (experimental)
741     QList<QTcpSocket *> clientList; // List of connected clients
742     quint16 sendCounter;            // Increased with every sent command
743
744     QTcpSocket *clientSocket; // socket of this client
745     QString server;           // server address of this client
746     int port;                 // server port of this client
747
748   protected:
749     void sendSelection();
750
751   public:
752     void newServer();
753     void connectToServer();
754
755   private slots:
756     void newClient();
757     void sendData(const QString &s);
758     void readData();
759     void displayNetworkError(QAbstractSocket::SocketError);
760
761   public:
762     void downloadImage(const QUrl &url, BranchItem *bi = NULL);
763
764     ////////////////////////////////////////////
765     // Selection related
766     ////////////////////////////////////////////
767   private:
768     TreeItem *latestAddedItem; // latest added object, reset on setChanged()
769     QUuid lastToggledUuid;     // Latest toggled object 
770     QList<uint> selectionHistory;
771     int currentSelection;
772     bool keepSelectionHistory; // If set, selection doesn't change history
773
774   public slots:
775     void updateSelection(QItemSelection, QItemSelection); // update selection
776
777   public:
778     void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
779     QItemSelectionModel *getSelectionModel();
780
781     void setSelectionBlocked(bool);
782     bool isSelectionBlocked();
783
784     bool select(const QString &);          //! Select by string
785     bool selectID(const QString &);        //! select by unique ID (QUuid)
786     bool select(LinkableMapObj *lmo);      //! Select by pointer to LMO
787     bool selectToggle(TreeItem *ti);       //! Toggle select state
788     bool selectToggle(const QString &selectString); //! Overloaded function to toggle select state
789     bool select(TreeItem *ti);             //! Select by pointer to TreeItem
790     bool select(const QModelIndex &index); //! Select by ModelIndex
791     void unselectAll();
792     void unselect(QItemSelection desel);
793     bool reselect();
794     bool canSelectPrevious();
795     bool selectPrevious();
796     bool canSelectNext();
797     bool selectNext();
798     void resetSelectionHistory();
799     void appendSelectionToHistory();
800     void emitShowSelection(bool scaled = false); //!< Show selection in all views
801
802   signals:
803     void showSelection(bool scaled);
804
805   public:
806     TreeItem *lastToggledItem();
807     bool selectFirstBranch();
808     bool selectFirstChildBranch();
809     bool selectLastBranch();
810     bool selectLastChildBranch();
811     bool selectLastSelectedBranch();
812     bool selectLastImage();
813     bool selectLatestAdded();
814     bool selectParent();
815
816   public:
817     TreeItem::Type selectionType();
818     LinkableMapObj *getSelectedLMO();
819     BranchObj *getSelectedBranchObj();
820     BranchItem *getSelectedBranch();
821     QList<BranchItem *> getSelectedBranches();
822     ImageItem *getSelectedImage();
823     Task *getSelectedTask();
824     XLinkItem *getSelectedXLinkItem();
825     Link *getSelectedXLink();
826     AttributeItem *getSelectedAttribute();
827     TreeItem *getSelectedItem();
828     QList<TreeItem *> getSelectedItems();
829     QModelIndex getSelectedIndex();
830     QList<uint> getSelectedIDs();
831     QStringList getSelectedUUIDs();
832     bool isSelected(TreeItem *);
833     QString getSelectString();
834     QString getSelectString(LinkableMapObj *lmo);
835     QString getSelectString(TreeItem *item);
836     QString getSelectString(BranchItem *item);
837     QString getSelectString(const uint &i);
838     void setLatestAddedItem(TreeItem *ti);
839     TreeItem *getLatestAddedItem();
840
841   signals:
842     void selectionChanged(const QItemSelection &newsel,
843                           const QItemSelection &oldsel);
844
845   public:
846     void emitSelectionChanged(const QItemSelection &oldsel);
847     void emitSelectionChanged();
848     void selectMapLinkColor();
849     void selectMapSelectionColor();
850
851   private:
852     QItemSelectionModel *selModel;
853     QString lastSelectString;
854     bool selectionBlocked; //! Used to block changes of selection while editing
855                            //! a heading
856
857   public:
858     void setSelectionPenColor(QColor);
859     QColor getSelectionPenColor();
860     void setSelectionPenWidth(qreal);
861     qreal getSelectionPenWidth();
862     void setSelectionBrushColor(QColor);
863     QColor getSelectionBrushColor();
864
865     ////////////////////////////////////////////
866     // Iterating and selecting branches
867     ////////////////////////////////////////////
868   public:
869     bool initIterator(const QString &iname,
870                       bool deepLevelsFirst = false); //! Named iterator
871     bool nextIterator(const QString &iname);         //! Select next iterator
872   private:
873     QHash<QString, QUuid> selIterCur;
874     QHash<QString, QUuid> selIterPrev;
875     QHash<QString, QUuid> selIterStart;
876     QHash<QString, bool> selIterActive;
877
878     ////////////////////////////////////////////
879     // Slide related
880     ////////////////////////////////////////////
881   public:
882     SlideModel *getSlideModel();
883     int slideCount();
884     SlideItem *addSlide();
885     void deleteSlide(SlideItem *si);
886     void deleteSlide(int n);
887     void relinkSlide(SlideItem *si, int pos);
888     bool moveSlideDown(int n = -1);
889     bool moveSlideUp(int n = -1);
890     SlideItem *findSlideID(uint id);
891   public slots:
892     void updateSlideSelection(QItemSelection, QItemSelection);
893
894   private:
895     SlideModel *slideModel;
896     bool blockSlideSelection;
897 };
898
899 #endif