MythTV master
mythuistatetype.cpp
Go to the documentation of this file.
1// Own header
2#include "mythuistatetype.h"
3#include "mythuibuttonlist.h"
4
5// Qt headers
6#include <QDomDocument>
7
8// MythUI headers
9#include "mythimage.h"
10#include "mythuiimage.h"
11#include "mythuigroup.h"
12#include "mythuitext.h"
13#include "mythpainter.h"
14#include "mythmainwindow.h"
15
16MythUIStateType::MythUIStateType(MythUIType *parent, const QString &name)
17 : MythUIComposite(parent, name)
18{
19 emit DependChanged(false);
20}
21
22bool MythUIStateType::AddImage(const QString &name, MythImage *image)
23{
24 QString key = name.toLower();
25
26 if (m_objectsByName.contains(key) || !image)
27 return false;
28
29 // Uses name, not key which is lower case otherwise we break
30 // inheritance
31 auto *imType = new MythUIImage(this, name);
32 imType->SetImage(image);
33
34 return AddObject(key, imType);
35}
36
37bool MythUIStateType::AddObject(const QString &name, MythUIType *object)
38{
39 QString key = name.toLower();
40
41 if (m_objectsByName.contains(key) || !object)
42 return false;
43
44 object->SetVisible(false);
45 m_objectsByName[key] = object;
46
47 MythRect objectArea = object->GetArea();
48 objectArea.CalculateArea(m_parentArea);
49
50 ExpandArea(objectArea);
51
52 return true;
53}
54
56{
57 if (m_objectsByState.contains((int)type) || !image)
58 return false;
59
60 QString name = QString("stateimage%1").arg(type);
61
62 auto *imType = new MythUIImage(this, name);
63 imType->SetImage(image);
64
65 return AddObject(type, imType);
66}
67
69{
70 if (m_objectsByState.contains((int)type) || !object)
71 return false;
72
73 object->SetVisible(false);
74 m_objectsByState[(int)type] = object;
75
76 MythRect objectArea = object->GetArea();
77 objectArea.CalculateArea(m_parentArea);
78
79 ExpandArea(objectArea);
80
81 return true;
82}
83
84bool MythUIStateType::DisplayState(const QString &name)
85{
86 if (name.isEmpty())
87 return false;
88
90
91 QMap<QString, MythUIType *>::Iterator i = m_objectsByName.find(name.toLower());
92
93 if (i != m_objectsByName.end())
94 m_currentState = i.value();
95 else
96 m_currentState = nullptr;
97
98 if (m_currentState != old)
99 {
101 {
104
105 if (old)
106 old->SetVisible(false);
107
108 if (m_currentState)
110 }
111 }
113
114 return (m_currentState != nullptr);
115}
116
118{
120
121 QMap<int, MythUIType *>::Iterator i = m_objectsByState.find((int)type);
122
123 if (i != m_objectsByState.end())
124 m_currentState = i.value();
125 else
126 m_currentState = nullptr;
127
128 if (m_currentState != old)
129 {
131 {
134
135 if (old)
136 old->SetVisible(false);
137
138 if (m_currentState)
140 }
141 }
143
144 return (m_currentState != nullptr);
145}
146
148{
149 QString lcname = name.toLower();
150
151 if (m_objectsByName.contains(lcname))
152 return m_objectsByName[lcname];
153
154 return nullptr;
155}
156
158{
159 if (m_objectsByState.contains(state))
160 return m_objectsByState[state];
161
162 return nullptr;
163}
164
169{
170 if (m_objectsByName.isEmpty() && m_objectsByState.isEmpty())
171 return;
172
173 QMap<QString, MythUIType *>::Iterator i;
174
175 for (i = m_objectsByName.begin(); i != m_objectsByName.end(); ++i)
176 {
177 DeleteChild(i.value());
178 }
179
180 QMap<int, MythUIType *>::Iterator j;
181
182 for (j = m_objectsByState.begin(); j != m_objectsByState.end(); ++j)
183 {
184 DeleteChild(j.value());
185 }
186
187 m_objectsByName.clear();
188 m_objectsByState.clear();
189
190 m_currentState = nullptr;
191 SetRedraw();
192}
193
198{
199 if (!DisplayState("default") && !DisplayState("active"))
200 {
201 if (!DisplayState(None))
202 {
203 if (m_currentState)
205
206 m_currentState = nullptr;
207 }
208 }
209
211}
212
214 const QString &filename, QDomElement &element, bool showWarnings)
215{
216 QMap<QString, QString> dependsMap;
217 if (element.tagName() == "showempty")
218 {
219 m_showEmpty = parseBool(element);
220 }
221 else if (element.tagName() == "state")
222 {
223 QString name = element.attribute("name", "");
224 QString type = element.attribute("type", "");
225
226 QString statename;
227
228 if (!type.isEmpty())
229 statename = type;
230 else
231 statename = name;
232
233 element.setAttribute("name", statename);
234
235 MythUIGroup *uitype = dynamic_cast<MythUIGroup *>
236 (ParseUIType(filename, element, "group", this, nullptr, showWarnings, dependsMap));
237
238 if (!type.isEmpty())
239 {
240 StateType stype = None;
241
242 if (type == "off")
243 stype = Off;
244 else if (type == "half")
245 stype = Half;
246 else if (type == "full")
247 stype = Full;
248
249 if (uitype && !m_objectsByState.contains((int)stype))
250 AddObject(stype, uitype);
251 }
252 else if (!name.isEmpty())
253 {
254 if (uitype && !m_objectsByName.contains(name))
255 AddObject(name, uitype);
256 }
257 }
258 else
259 {
260 return MythUIType::ParseElement(filename, element, showWarnings);
261 }
262
263 return true;
264}
265
267{
268 auto *st = dynamic_cast<MythUIStateType *>(base);
269
270 if (!st)
271 return;
272
273 m_showEmpty = st->m_showEmpty;
274
276
277 QMap<QString, MythUIType *>::iterator i;
278
279 for (i = st->m_objectsByName.begin(); i != st->m_objectsByName.end(); ++i)
280 {
281 MythUIType *other = i.value();
282 const QString& key = i.key();
283
284 MythUIType *newtype = GetChild(other->objectName());
285 AddObject(key, newtype);
286 newtype->SetVisible(false);
287 }
288
289 QMap<int, MythUIType *>::iterator j;
290
291 for (j = st->m_objectsByState.begin(); j != st->m_objectsByState.end(); ++j)
292 {
293 MythUIType *other = j.value();
294 int key = j.key();
295
296 MythUIType *newtype = GetChild(other->objectName());
297 AddObject((StateType)key, newtype);
298 newtype->SetVisible(false);
299 }
300}
301
303{
304 auto *st = new MythUIStateType(parent, objectName());
305 st->CopyFrom(this);
306}
307
309{
310 if (!DisplayState("default"))
312}
313
314void MythUIStateType::EnsureStateLoaded(const QString &name)
315{
316 if (name.isEmpty())
317 return;
318
319 QMap<QString, MythUIType *>::Iterator i = m_objectsByName.find(name);
320
321 if (i != m_objectsByName.end())
322 i.value()->LoadNow();
323}
324
326{
327 QMap<int, MythUIType *>::Iterator i = m_objectsByState.find((int)type);
328
329 if (i != m_objectsByState.end())
330 i.value()->LoadNow();
331}
332
334{
335 if (!m_deferload)
337}
338
340{
341 if (m_parent)
342 {
343 if (objectName().startsWith("buttonlist button"))
344 {
345 if (auto * list = dynamic_cast<MythUIButtonList *>(m_parent); list)
346 m_parentArea = list->GetButtonArea();
347 }
348 else
349 {
351 }
352 }
353 else
354 {
356 }
357
358 m_area.Reset();
360
361 if (recurse)
362 {
363 for (auto * child : std::as_const(m_childrenList))
364 child->RecalculateArea(recurse);
365 }
366}
367
369{
370 if (m_currentState == nullptr || !m_currentState->IsVisible())
371 {
372 emit DependChanged(true);
373 return;
374 }
375 QList<MythUIType *> *children = m_currentState->GetAllChildren();
376 for (auto *child : std::as_const(*children))
377 {
378 if (child->IsVisible())
379 {
380 emit DependChanged(false);
381 return;
382 }
383 }
384 emit DependChanged(true);
385}
386
388{
389 if (m_objectsByName.isEmpty() && m_objectsByState.isEmpty())
390 return;
391
392 QMap<QString, MythUIType *>::Iterator i;
393
394 for (i = m_objectsByName.begin(); i != m_objectsByName.end(); ++i)
395 {
396 MythUIType *type = i.value();
397
398 auto *textType = dynamic_cast<MythUIText *> (type);
399 if (textType)
400 textType->SetTextFromMap(infoMap);
401
402 auto *group = dynamic_cast<MythUIComposite *> (type);
403 if (group)
404 group->SetTextFromMap(infoMap);
405 }
406
407 QMap<int, MythUIType *>::Iterator j;
408
409 for (j = m_objectsByState.begin(); j != m_objectsByState.end(); ++j)
410 {
411 MythUIType *type = j.value();
412
413 auto *textType = dynamic_cast<MythUIText *> (type);
414 if (textType)
415 textType->SetTextFromMap(infoMap);
416
417 auto *group = dynamic_cast<MythUIComposite *> (type);
418 if (group)
419 group->SetTextFromMap(infoMap);
420 }
421}
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:18
void Reset(void)
Definition: mythrect.cpp:59
void CalculateArea(QRect parentArea)
Definition: mythrect.cpp:64
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
virtual void SetTextFromMap(const InfoMap &infoMap)
Create a group of widgets.
Definition: mythuigroup.h:12
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
This widget is used for grouping other widgets for display when a particular named state is called.
void SetTextFromMap(const InfoMap &infoMap) override
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings) override
Parse the xml definition of this widget setting the state of the object accordingly.
void LoadNow(void) override
Cause images in this and child widgets to be loaded.
MythUIStateType(MythUIType *parent, const QString &name)
void RecalculateArea(bool recurse=true) override
void EnsureStateLoaded(const QString &name)
MythUIType * GetState(const QString &name)
MythUIType * m_currentState
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
MythRect m_parentArea
bool AddImage(const QString &name, MythImage *image)
QMap< QString, MythUIType * > m_objectsByName
bool DisplayState(const QString &name)
QMap< int, MythUIType * > m_objectsByState
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
virtual void AdjustDependence(void)
void CreateCopy(MythUIType *parent) override
Copy the state of this widget to the one given, it must be of the same type.
bool AddObject(const QString &name, MythUIType *object)
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
void SetTextFromMap(const InfoMap &map)
Definition: mythuitext.cpp:138
The base class on which all widgets and screens are based.
Definition: mythuitype.h:97
QList< MythUIType * > * GetAllChildren(void)
Return a list of all child widgets.
Definition: mythuitype.cpp:188
bool IsVisible(bool recurse=false) const
Definition: mythuitype.cpp:889
virtual void SetVisible(bool visible)
virtual void LoadNow(void)
Cause images in this and child widgets to be loaded.
void ExpandArea(QRect rect)
Definition: mythuitype.cpp:855
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
void SetRedraw(void)
Definition: mythuitype.cpp:299
MythUIType * m_parent
Definition: mythuitype.h:308
virtual MythRect GetFullArea(void) const
Definition: mythuitype.cpp:879
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
void DeleteChild(const QString &name)
Delete a named child of this UIType.
Definition: mythuitype.cpp:145
void DependChanged(bool isDefault)
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuitype.cpp:71
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.
QList< MythUIType * > m_childrenList
Definition: mythuitype.h:266
MythRect m_area
Definition: mythuitype.h:288
bool m_deferload
Definition: mythuitype.h:317
static MythUIType * ParseUIType(const QString &filename, QDomElement &element, const QString &type, MythUIType *parent, MythScreenType *screen, bool showWarnings, QMap< QString, QString > &parentDependsMap)
static bool parseBool(const QString &text)
MythMainWindow * GetMythMainWindow(void)
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15