FlightGear next
GettingStartedTip.cxx
Go to the documentation of this file.
2
5
6static bool static_globalEnableTips = true;
7
9 QQuickItem(parent)
10{
11 _enabled = static_globalEnableTips;
12
13 setImplicitHeight(1);
14 setImplicitWidth(1);
15
16 if (_enabled) {
17 registerWithScope();
18 }
19}
20
22{
23 if (_enabled) {
24 unregisterFromScope();
25 }
26}
27
29{
30 return _controller.data();
31}
32
34{
35 if (_enabled && !_controller) {
36 registerWithScope();
37 }
38
39 QQuickItem::componentComplete();
40}
41
46
48{
49 if (_enabled == enabled)
50 return;
51
53 if (enabled) {
54 registerWithScope();
55 } else {
56 unregisterFromScope();
57 }
58
59 emit enabledChanged();
60}
61
63{
64 auto ctl = findController();
65 if (ctl) {
66 ctl->showOneShotTip(this);
67 }
68}
69
71{
72 if (_standalone == standalone)
73 return;
74
75 _standalone = standalone;
76 emit standaloneChanged(_standalone);
77
78 // re-register with our scope, which will also unregister us if
79 // necessary.
80 if (_enabled) {
81 registerWithScope();
82 }
83}
84
85void GettingStartedTip::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
86{
87 const bool isParentChanged = (change == ItemParentHasChanged);
88 if (isParentChanged && _enabled) {
89 unregisterFromScope();
90 }
91
92 QQuickItem::itemChange(change, value);
93
94 if (isParentChanged && _enabled) {
95 registerWithScope();
96 }
97}
98
99void GettingStartedTip::registerWithScope()
100{
101 if (_controller) {
102 unregisterFromScope();
103 }
104
105 if (_standalone) {
106 return; // standalone tips don't register
107 }
108
109 auto ctl = findController();
110 if (!ctl) {
111 return;
112 }
113
114 bool ok = ctl->addTip(this);
115 if (ok) {
116 _controller = ctl;
117 emit controllerChanged();
118 }
119}
120
121GettingStartedTipsController* GettingStartedTip::findController()
122{
123 QQuickItem* pr = const_cast<QQuickItem*>(parentItem());
124 if (!pr) {
125 return nullptr;
126 }
127
128 while (pr) {
129 auto sa = qobject_cast<GettingStartedScopeAttached*>(qmlAttachedPropertiesObject<GettingStartedScope>(pr, false));
130 if (sa && sa->controller()) {
131 return sa->controller();
132 }
133
134 pr = pr->parentItem();
135 }
136
137 return nullptr;
138}
139
140void GettingStartedTip::unregisterFromScope()
141{
142 if (_controller) {
143 _controller->removeTip(this);
144 _controller.clear();
145 emit controllerChanged();
146 }
147}
static bool static_globalEnableTips
GettingStartedTipsController * controller
void standaloneChanged(bool standalone)
void setStandalone(bool standalone)
void componentComplete() override
GettingStartedTip(QQuickItem *parent=nullptr)
void controllerChanged()
bool standalone
standalone tips are excluded from their scope when activated; instead they need to be activated manua...
void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) override
void setEnabled(bool enabled)
static void setGlobalTipsEnabled(bool enable)
Manage presentation of getting started tips on a screen/page.