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 
17  : MythUIComposite(parent, name)
18 {
19  emit DependChanged(false);
20 }
21 
22 bool 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  MythUIImage *imType = new MythUIImage(this, name);
32  imType->SetImage(image);
33 
34  return AddObject(key, imType);
35 }
36 
37 bool 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  MythUIImage *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 
84 bool 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  return false;
97 
98  if (m_CurrentState != old)
99  {
101  {
104 
105  if (old)
106  old->SetVisible(false);
107 
108  if (m_CurrentState)
109  m_CurrentState->SetVisible(true);
110  }
111  }
113 
114  return (m_CurrentState != nullptr);
115 }
116 
118 {
119  MythUIType *old = m_CurrentState;
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)
139  m_CurrentState->SetVisible(true);
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)
204  m_CurrentState->SetVisible(false);
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  m_ShowEmpty = parseBool(element);
219  else if (element.tagName() == "state")
220  {
221  QString name = element.attribute("name", "");
222  QString type = element.attribute("type", "");
223 
224  QString statename;
225 
226  if (!type.isEmpty())
227  statename = type;
228  else
229  statename = name;
230 
231  element.setAttribute("name", statename);
232 
233  MythUIGroup *uitype = dynamic_cast<MythUIGroup *>
234  (ParseUIType(filename, element, "group", this, nullptr, showWarnings, dependsMap));
235 
236  if (!type.isEmpty())
237  {
238  StateType stype = None;
239 
240  if (type == "off")
241  stype = Off;
242  else if (type == "half")
243  stype = Half;
244  else if (type == "full")
245  stype = Full;
246 
247  if (uitype && !m_ObjectsByState.contains((int)stype))
248  AddObject(stype, uitype);
249  }
250  else if (!name.isEmpty())
251  {
252  if (uitype && !m_ObjectsByName.contains(name))
253  AddObject(name, uitype);
254  }
255  }
256  else
257  {
258  return MythUIType::ParseElement(filename, element, showWarnings);
259  }
260 
261  return true;
262 }
263 
265 {
266  MythUIStateType *st = dynamic_cast<MythUIStateType *>(base);
267 
268  if (!st)
269  return;
270 
271  m_ShowEmpty = st->m_ShowEmpty;
272 
273  MythUIType::CopyFrom(base);
274 
275  QMap<QString, MythUIType *>::iterator i;
276 
277  for (i = st->m_ObjectsByName.begin(); i != st->m_ObjectsByName.end(); ++i)
278  {
279  MythUIType *other = i.value();
280  const QString& key = i.key();
281 
282  MythUIType *newtype = GetChild(other->objectName());
283  AddObject(key, newtype);
284  newtype->SetVisible(false);
285  }
286 
287  QMap<int, MythUIType *>::iterator j;
288 
289  for (j = st->m_ObjectsByState.begin(); j != st->m_ObjectsByState.end(); ++j)
290  {
291  MythUIType *other = j.value();
292  int key = j.key();
293 
294  MythUIType *newtype = GetChild(other->objectName());
295  AddObject((StateType)key, newtype);
296  newtype->SetVisible(false);
297  }
298 }
299 
301 {
302  MythUIStateType *st = new MythUIStateType(parent, objectName());
303  st->CopyFrom(this);
304 }
305 
307 {
308  if (!DisplayState("default"))
310 }
311 
313 {
314  if (name.isEmpty())
315  return;
316 
317  QMap<QString, MythUIType *>::Iterator i = m_ObjectsByName.find(name);
318 
319  if (i != m_ObjectsByName.end())
320  i.value()->LoadNow();
321 }
322 
324 {
325  QMap<int, MythUIType *>::Iterator i = m_ObjectsByState.find((int)type);
326 
327  if (i != m_ObjectsByState.end())
328  i.value()->LoadNow();
329 }
330 
332 {
333  if (!m_deferload)
335 }
336 
338 {
339  if (m_Parent)
340  {
341  if (objectName().startsWith("buttonlist button"))
342  {
343  MythUIButtonList *list = static_cast<MythUIButtonList *>(m_Parent);
344  m_ParentArea = list->GetButtonArea();
345  }
346  else
348  }
349  else
351 
352  m_Area.Reset();
354 
355  if (recurse)
356  {
357  QList<MythUIType *>::iterator it;
358 
359  for (it = m_ChildrenList.begin(); it != m_ChildrenList.end(); ++it)
360  {
361  (*it)->RecalculateArea(recurse);
362  }
363  }
364 }
365 
367 {
368  if (m_CurrentState == nullptr || !m_CurrentState->IsVisible())
369  {
370  emit DependChanged(true);
371  return;
372  }
373  QList<MythUIType *> *children = m_CurrentState->GetAllChildren();
374  QList<MythUIType *>::iterator it = children->begin();
375 
376  for (; it != children->end(); ++it)
377  {
378  if ((*it)->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  MythUIText *textType = dynamic_cast<MythUIText *> (type);
399  if (textType)
400  textType->SetTextFromMap(infoMap);
401 
402  MythUIComposite *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  MythUIText *textType = dynamic_cast<MythUIText *> (type);
414  if (textType)
415  textType->SetTextFromMap(infoMap);
416 
417  MythUIComposite *group = dynamic_cast<MythUIComposite *> (type);
418  if (group)
419  group->SetTextFromMap(infoMap);
420  }
421 }
This widget is used for grouping other widgets for display when a particular named state is called.
QList< MythUIType * > * GetAllChildren(void)
Return a list of all child widgets.
Definition: mythuitype.cpp:196
void CalculateArea(const MythRect &parentArea)
Definition: mythrect.cpp:32
void SetImage(MythImage *img)
Should not be used unless absolutely necessary since it bypasses the image caching and threaded loade...
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
bool AddImage(const QString &name, MythImage *image)
void SetRedraw(void)
Definition: mythuitype.cpp:295
void DeleteChild(const QString &name)
Delete a named child of this UIType.
Definition: mythuitype.cpp:147
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
bool IsVisible(bool recurse=false) const
Definition: mythuitype.cpp:881
void SetTextFromMap(const InfoMap &map)
Definition: mythuitext.cpp:159
virtual void AdjustDependence(void)
The base class on which all widgets and screens are based.
Definition: mythuitype.h:63
void Reset(void)
Definition: mythrect.cpp:27
MythRect m_ParentArea
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
virtual void SetVisible(bool visible)
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
void DependChanged(bool isDefault)
void LoadNow(void) override
Cause images in this and child widgets to be loaded.
bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings) override
Parse the xml definition of this widget setting the state of the object accordingly.
Create a group of widgets.
Definition: mythuigroup.h:11
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:17
virtual void SetTextFromMap(const InfoMap &infoMap)
MythRect m_Area
Definition: mythuitype.h:249
void ExpandArea(const MythRect &rect)
Definition: mythuitype.cpp:847
MythUIType * GetState(const QString &name)
const char * name
Definition: ParseText.cpp:328
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
void CreateCopy(MythUIType *parent) override
Copy the state of this widget to the one given, it must be of the same type.
virtual void LoadNow(void)
Cause images in this and child widgets to be loaded.
MythMainWindow * GetMythMainWindow(void)
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuitype.cpp:69
static MythUIType * ParseUIType(const QString &filename, QDomElement &element, const QString &type, MythUIType *parent, MythScreenType *screen, bool showWarnings, QMap< QString, QString > &parentDependsMap)
virtual MythRect GetFullArea(void) const
Definition: mythuitype.cpp:871
MythRect GetButtonArea(void) const
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
void SetTextFromMap(const InfoMap &infoMap) override
bool DisplayState(const QString &name)
void EnsureStateLoaded(const QString &name)
MythUIType * m_Parent
Definition: mythuitype.h:270
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
MythUIType * m_CurrentState
void RecalculateArea(bool recurse=true) override
MythUIStateType(MythUIType *parent, const QString &name)
QMap< int, MythUIType * > m_ObjectsByState
bool m_deferload
Definition: mythuitype.h:279
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:132
static bool parseBool(const QString &text)
QList< MythUIType * > m_ChildrenList
Definition: mythuitype.h:228
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.
QMap< QString, MythUIType * > m_ObjectsByName
bool AddObject(const QString &name, MythUIType *object)