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 // MythDB
10 #include "mythlogging.h"
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 
54 {
55  m_start = value;
57 }
58 
60 {
61  if (value < m_start)
62  value = m_start;
63 
64  if (value > m_total)
65  value = m_total;
66 
67  m_current = value;
69 }
70 
72 {
73  m_total = value;
75 }
76 
78 {
79  MythUIType *progressType = GetChild("progressimage");
80 
81  if (!progressType)
82  {
83  LOG(VB_GENERAL, LOG_ERR, "Progress image doesn't exist");
84  return;
85  }
86 
87  progressType->SetVisible(false);
88 
89  int total = m_total - m_start;
90  int current = m_current - m_start;
91  float percentage = 0.0;
92 
93  if (total <= 0 || current <= 0 || current > total)
94  return;
95 
96  percentage = (float)current / (float)total;
97  progressType->SetVisible(true);
98 
99  QRect fillArea = progressType->GetArea();
100 
101  int height = fillArea.height();
102  int width = fillArea.width();
103  int x = fillArea.x();
104  int y = fillArea.y();
105 
106  switch (m_effect)
107  {
108  case EffectReveal :
109 
110  if (m_layout == LayoutHorizontal)
111  {
112  width = (int)((float)fillArea.width() * percentage);
113  }
114  else
115  {
116  height = (int)((float)fillArea.height() * percentage);
117  }
118 
119  break;
120  case EffectSlide :
121 
122  if (m_layout == LayoutHorizontal)
123  {
124  int newwidth = (int)((float)fillArea.width() * percentage);
125  x = width - newwidth;
126  width = newwidth;
127  }
128  else
129  {
130  int newheight = (int)((float)fillArea.height() * percentage);
131  y = height - newheight;
132  height = newheight;
133  }
134 
135  break;
136  case EffectAnimate :
137  // Not implemented yet
138  break;
139  }
140 
141  auto *progressImage = dynamic_cast<MythUIImage *>(progressType);
142  auto *progressShape = dynamic_cast<MythUIShape *>(progressType);
143 
144  if (width <= 0)
145  width = 1;
146 
147  if (height <= 0)
148  height = 1;
149 
150  if (progressImage)
151  progressImage->SetCropRect(x, y, width, height);
152  else if (progressShape)
153  progressShape->SetCropRect(x, y, width, height);
154 
155  SetRedraw();
156 }
157 
159 {
161 }
162 
164 {
165  auto *progressbar = dynamic_cast<MythUIProgressBar *>(base);
166 
167  if (!progressbar)
168  return;
169 
170  m_layout = progressbar->m_layout;
171  m_effect = progressbar->m_effect;
172 
173  m_total = progressbar->m_total;
174  m_start = progressbar->m_start;
175  m_current = progressbar->m_current;
176 
177  MythUIType::CopyFrom(base);
178 }
179 
181 {
182  auto *progressbar = new MythUIProgressBar(parent, objectName());
183  progressbar->CopyFrom(this);
184 }
185 
187 {
188  if (m_firstdepend || visible != m_visible)
189  {
190  emit DependChanged(!visible);
191  m_firstdepend = false;
192  }
193  MythUIType::SetVisible(visible);
194 }
mythuiprogressbar.h
MythUIImage
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
MythUIProgressBar::m_start
int m_start
Definition: mythuiprogressbar.h:41
MythUIProgressBar::EffectReveal
@ EffectReveal
Definition: mythuiprogressbar.h:22
MythUIProgressBar::SetStart
void SetStart(int value)
Definition: mythuiprogressbar.cpp:53
MythUIProgressBar::Finalize
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
Definition: mythuiprogressbar.cpp:158
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
MythUIProgressBar::SetUsed
void SetUsed(int value)
Definition: mythuiprogressbar.cpp:59
MythUIProgressBar::EffectSlide
@ EffectSlide
Definition: mythuiprogressbar.h:22
MythUIType::m_visible
bool m_visible
Definition: mythuitype.h:237
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
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:10
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:869
MythUIProgressBar::m_firstdepend
bool m_firstdepend
Definition: mythuiprogressbar.h:43
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:71
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
MythUIType::DependChanged
void DependChanged(bool isDefault)
MythUIProgressBar
Progress bar widget.
Definition: mythuiprogressbar.h:13
XMLParseBase::getFirstText
static QString getFirstText(QDomElement &element)
Definition: xmlparsebase.cpp:53
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:634
MythUIType::CopyFrom
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
Definition: mythuitype.cpp:1152
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:180
MythUIProgressBar::m_current
int m_current
Definition: mythuiprogressbar.h:42
MythUIProgressBar::m_effect
EffectType m_effect
Definition: mythuiprogressbar.h:38
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:69
MythUIType
The base class on which all widgets and screens are based.
Definition: mythuitype.h:64
MythUIShape
A widget for rendering primitive shapes and lines.
Definition: mythuishape.h:22
MythUIProgressBar::m_layout
LayoutType m_layout
Definition: mythuiprogressbar.h:37
MythUIProgressBar::EffectAnimate
@ EffectAnimate
Definition: mythuiprogressbar.h:22
MythUIType::SetVisible
virtual void SetVisible(bool visible)
Definition: mythuitype.cpp:1085
MythUIProgressBar::LayoutVertical
@ LayoutVertical
Definition: mythuiprogressbar.h:21
MythUIProgressBar::CalculatePosition
void CalculatePosition(void)
Definition: mythuiprogressbar.cpp:77
MythUIProgressBar::CopyFrom
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
Definition: mythuiprogressbar.cpp:163
MythUIProgressBar::m_total
int m_total
Definition: mythuiprogressbar.h:40
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:1218
MythUIProgressBar::SetVisible
void SetVisible(bool visible) override
Definition: mythuiprogressbar.cpp:186
MythUIType::SetRedraw
void SetRedraw(void)
Definition: mythuitype.cpp:293
mythuishape.h