MythTV  master
mythuiprogressbar.cpp
Go to the documentation of this file.
1 
2 // Own Header
3 #include "mythuiprogressbar.h"
4 
5 // QT
6 #include <QCoreApplication>
7 #include <QDomDocument>
8 
9 // MythBase
11 
12 // MythUI
13 #include "mythuishape.h"
14 #include "mythuiimage.h"
15 
17 {
18  m_total = m_start = m_current = 0;
20  emit DependChanged(false);
22 }
23 
25  const QString &filename, QDomElement &element, bool showWarnings)
26 {
27  if (element.tagName() == "layout")
28  {
29  QString layout = getFirstText(element).toLower();
30 
31  if (layout == "vertical")
33  else
35  }
36  else if (element.tagName() == "style")
37  {
38  QString effect = getFirstText(element).toLower();
39 
40  if (effect == "slide")
42  else
44  }
45  else
46  {
47  return MythUIType::ParseElement(filename, element, showWarnings);
48  }
49 
50  return true;
51 }
52 
53 void MythUIProgressBar::Set(int start, int total, int used)
54 {
55  if (used != m_current || start != m_start || total != m_total)
56  {
57  m_start = start;
58  m_total = total;
59  SetUsed(used);
60  }
61 }
62 
64 {
65  m_start = value;
67 }
68 
70 {
71  if (value < m_start)
72  value = m_start;
73 
74  if (value > m_total)
75  value = m_total;
76 
77  m_current = value;
79 }
80 
82 {
83  m_total = value;
85 }
86 
88 {
89  MythUIType *progressType = GetChild("progressimage");
90 
91  if (!progressType)
92  {
93  LOG(VB_GENERAL, LOG_ERR, "Progress image doesn't exist");
94  return;
95  }
96 
97  progressType->SetVisible(false);
98 
99  int total = m_total - m_start;
100  int current = m_current - m_start;
101  float percentage = 0.0;
102 
103  if (total <= 0 || current <= 0 || current > total)
104  return;
105 
106  percentage = (float)current / (float)total;
107  progressType->SetVisible(true);
108 
109  QRect fillArea = progressType->GetArea();
110 
111  int height = fillArea.height();
112  int width = fillArea.width();
113  int x = fillArea.x();
114  int y = fillArea.y();
115 
116  switch (m_effect)
117  {
118  case EffectReveal :
119 
120  if (m_layout == LayoutHorizontal)
121  {
122  width = (int)((float)fillArea.width() * percentage);
123  }
124  else
125  {
126  height = (int)((float)fillArea.height() * percentage);
127  }
128 
129  break;
130  case EffectSlide :
131 
132  if (m_layout == LayoutHorizontal)
133  {
134  int newwidth = (int)((float)fillArea.width() * percentage);
135  x = width - newwidth;
136  width = newwidth;
137  }
138  else
139  {
140  int newheight = (int)((float)fillArea.height() * percentage);
141  y = height - newheight;
142  height = newheight;
143  }
144 
145  break;
146  case EffectAnimate :
147  // Not implemented yet
148  break;
149  }
150 
151  auto *progressImage = dynamic_cast<MythUIImage *>(progressType);
152  auto *progressShape = dynamic_cast<MythUIShape *>(progressType);
153 
154  if (width <= 0)
155  width = 1;
156 
157  if (height <= 0)
158  height = 1;
159 
160  if (progressImage)
161  progressImage->SetCropRect(x, y, width, height);
162  else if (progressShape)
163  progressShape->SetCropRect(x, y, width, height);
164 
165  SetRedraw();
166 }
167 
169 {
171 }
172 
174 {
175  auto *progressbar = dynamic_cast<MythUIProgressBar *>(base);
176 
177  if (!progressbar)
178  return;
179 
180  m_layout = progressbar->m_layout;
181  m_effect = progressbar->m_effect;
182 
183  m_total = progressbar->m_total;
184  m_start = progressbar->m_start;
185  m_current = progressbar->m_current;
186 
187  MythUIType::CopyFrom(base);
188 }
189 
191 {
192  auto *progressbar = new MythUIProgressBar(parent, objectName());
193  progressbar->CopyFrom(this);
194 }
195 
197 {
198  if (m_firstdepend || visible != m_visible)
199  {
200  emit DependChanged(!visible);
201  m_firstdepend = false;
202  }
203  MythUIType::SetVisible(visible);
204 }
mythuiprogressbar.h
MythUIImage
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
MythUIProgressBar::m_start
int m_start
Definition: mythuiprogressbar.h:42
MythUIProgressBar::EffectReveal
@ EffectReveal
Definition: mythuiprogressbar.h:22
MythUIProgressBar::SetStart
void SetStart(int value)
Definition: mythuiprogressbar.cpp:63
MythUIProgressBar::Finalize
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
Definition: mythuiprogressbar.cpp:168
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:133
MythUIProgressBar::SetUsed
void SetUsed(int value)
Definition: mythuiprogressbar.cpp:69
MythUIProgressBar::EffectSlide
@ EffectSlide
Definition: mythuiprogressbar.h:22
MythUIType::m_visible
bool m_visible
Definition: mythuitype.h:261
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythUIProgressBar::LayoutHorizontal
@ LayoutHorizontal
Definition: mythuiprogressbar.h:21
mythuiimage.h
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:14
MythUIType::GetArea
virtual MythRect GetArea(void) const
If the object has a minimum area defined, return it, other wise return the default area.
Definition: mythuitype.cpp:884
MythUIProgressBar::m_firstdepend
bool m_firstdepend
Definition: mythuiprogressbar.h:44
MythUIShape::SetCropRect
void SetCropRect(int x, int y, int width, int height)
Definition: mythuishape.cpp:31
MythUIProgressBar::SetTotal
void SetTotal(int value)
Definition: mythuiprogressbar.cpp:81
mythlogging.h
MythUIProgressBar::ParseElement
bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings) override
Parse the xml definition of this widget setting the state of the object accordingly.
Definition: mythuiprogressbar.cpp:24
MythUIProgressBar::Reset
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuiprogressbar.cpp:16
MythUIProgressBar::Set
void Set(int start, int total, int used)
Definition: mythuiprogressbar.cpp:53
MythUIType::DependChanged
void DependChanged(bool isDefault)
MythUIProgressBar
Progress bar widget.
Definition: mythuiprogressbar.h:12
XMLParseBase::getFirstText
static QString getFirstText(QDomElement &element)
Definition: xmlparsebase.cpp:52
MythUIType::CopyFrom
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
Definition: mythuitype.cpp:1174
MythUIProgressBar::CreateCopy
void CreateCopy(MythUIType *parent) override
Copy the state of this widget to the one given, it must be of the same type.
Definition: mythuiprogressbar.cpp:190
MythUIProgressBar::m_current
int m_current
Definition: mythuiprogressbar.h:43
MythUIProgressBar::m_effect
EffectType m_effect
Definition: mythuiprogressbar.h:39
MythUIType::Reset
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuitype.cpp:72
MythUIType
The base class on which all widgets and screens are based.
Definition: mythuitype.h:85
MythUIShape
A widget for rendering primitive shapes and lines.
Definition: mythuishape.h:21
MythUIProgressBar::m_layout
LayoutType m_layout
Definition: mythuiprogressbar.h:38
MythUIProgressBar::EffectAnimate
@ EffectAnimate
Definition: mythuiprogressbar.h:22
MythUIType::SetVisible
virtual void SetVisible(bool visible)
Definition: mythuitype.cpp:1108
MythUIProgressBar::LayoutVertical
@ LayoutVertical
Definition: mythuiprogressbar.h:21
MythUIProgressBar::CalculatePosition
void CalculatePosition(void)
Definition: mythuiprogressbar.cpp:87
MythUIProgressBar::CopyFrom
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
Definition: mythuiprogressbar.cpp:173
MythUIProgressBar::m_total
int m_total
Definition: mythuiprogressbar.h:41
MythUIProgressBar::MythUIProgressBar
MythUIProgressBar(MythUIType *parent, const QString &name)
Definition: mythuiprogressbar.h:15
MythUIType::ParseElement
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.
Definition: mythuitype.cpp:1240
MythUIProgressBar::SetVisible
void SetVisible(bool visible) override
Definition: mythuiprogressbar.cpp:196
build_compdb.filename
filename
Definition: build_compdb.py:21
MythUIType::SetRedraw
void SetRedraw(void)
Definition: mythuitype.cpp:308
mythuishape.h