Debian Codegraph @

src/GUI/GettingStartedTipsController.hxx

raw symbols SCIP
1 #ifndef GETTINGSTARTEDTIPSCONTROLLER_HXX
2 #define GETTINGSTARTEDTIPSCONTROLLER_HXX
3
4 #include <QObject>
5 #include <QVector>
6 #include <QQuickItem>
7 #include <QPointer>
8
9 // forward decls
10 class GettingStartedTip;
11
12 /**
13 * @brief Manage presentation of getting started tips on a screen/page
14 */
15 class GettingStartedTipsController : public QObject
16 {
17 Q_OBJECT
18
19 Q_PROPERTY(QString scopeId READ scopeId WRITE setScopeId NOTIFY scopeIdChanged)
20
21 Q_PROPERTY(GettingStartedTip* tip READ tip NOTIFY tipChanged)
22
23 Q_PROPERTY(int count READ count NOTIFY countChanged)
24 Q_PROPERTY(int index READ index WRITE setIndex NOTIFY indexChanged)
25
26 Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
27
28 Q_PROPERTY(QPointF tipPositionInVisualArea READ tipPositionInVisualArea NOTIFY tipPositionInVisualAreaChanged)
29 Q_PROPERTY(bool tipPositionValid READ tipPositionValid NOTIFY tipPositionInVisualAreaChanged)
30
31 Q_PROPERTY(QRectF tipGeometry READ tipGeometry NOTIFY tipGeometryChanged)
32 Q_PROPERTY(int activeTipHeight READ activeTipHeight WRITE setActiveTipHeight NOTIFY activeTipHeightChanged)
33 Q_PROPERTY(QRectF contentGeometry READ contentGeometry NOTIFY tipChanged)
34
35 Q_PROPERTY(QQuickItem* visualArea READ visualArea WRITE setVisualArea NOTIFY visualAreaChanged)
36
37 public:
38 explicit GettingStartedTipsController(QObject *parent = nullptr);
39 ~GettingStartedTipsController();
40
41 int count() const;
42
43 int index() const;
44
45 GettingStartedTip* tip() const;
46
47 QString scopeId() const
48 {
49 return _scopeId;
50 }
51
52 bool isActive() const;
53
54 QPointF tipPositionInVisualArea() const;
55
56 QQuickItem* visualArea() const
57 {
58 return _visualArea;
59 }
60
61 QRectF tipGeometry() const;
62
63 bool tipPositionValid() const;
64
65 int activeTipHeight() const;
66
67 /**
68 * @brief contentGeometry - based on the active tip, return the box
69 * (relative to the total tipGeometry) which content should occupy.
70 * This allows for offseting due to the arrow position, and also specifies
71 * the width for computing wrapped text height
72 *
73 * The actual height is the maximum height; the computed value should be
74 * set by activeTipHeight
75 */
76 QRectF contentGeometry() const;
77
78 public slots:
79
80 void close();
81
82 void setIndex(int index);
83
84 void setScopeId(QString scopeId);
85
86 void setVisualArea(QQuickItem* visualArea);
87
88 void setActiveTipHeight(int activeTipHeight);
89
90 /**
91 * @brief showOneShotTip - show a single tip on its own, if it has not
92 * previously been shown before.
93 *
94 * This is used for pieces of UI which are not always present; the first
95 * time the UI is displayed to the user, we can show a tip describing it.
96 * Once the user closes the tip, it will not reappear.
97 *
98 * The tip will be activated if the controller is currently inactive.
99 * If the controller was alreayd active, the tip will be shown, and when
100 * closed, the other tips will be shown. If the one-shot tip is part of
101 * the currently active list, this actually does nothing, to avoid showing
102 * the same tip twice
103 */
104 void showOneShotTip(GettingStartedTip* tip);
105
106 void tipsWereReset();
107 signals:
108
109 void countChanged(int count);
110 void indexChanged(int index);
111 void tipChanged();
112 void scopeChanged(QObject* scope);
113 void scopeIdChanged(QString scopeId);
114 void activeChanged();
115 void tipGeometryChanged();
116
117 void tipPositionInVisualAreaChanged();
118
119 void visualAreaChanged(QQuickItem* visualArea);
120
121 void activeTipHeightChanged(int activeTipHeight);
122
123 private:
124 friend class GettingStartedTip;
125
126 bool shouldShowScope() const;
127
128 void currentTipUpdated();
129
130 bool addTip(GettingStartedTip* t);
131 void removeTip(GettingStartedTip* t);
132
133 void onOneShotDestroyed();
134 private:
135
136 class ItemPositionObserver;
137
138 bool _scopeActive = false;
139 int _index = 0;
140 QString _scopeId;
141 ItemPositionObserver* _positionObserver = nullptr;
142 ItemPositionObserver* _viewAreaObserver = nullptr;
143
144 QPointer<GettingStartedTip> _oneShotTip;
145 QVector<GettingStartedTip*> _tips;
146 QQuickItem* _visualArea = nullptr;
147 int _activeTipHeight = 0;
148 };
149
150 #endif // GETTINGSTARTEDTIPSCONTROLLER_HXX