MythTV  master
mythuiprogressbar.cpp
Go to the documentation of this file.
1 
2 // Own Header
3 #include "mythuiprogressbar.h"
4 
5 // C++
6 #include <algorithm>
7 
8 // QT
9 #include <QCoreApplication>
10 #include <QDomDocument>
11 
12 // MythBase
14 
15 // MythUI
16 #include "mythuishape.h"
17 #include "mythuiimage.h"
18 
20 {
21  m_total = m_start = m_current = 0;
23  emit DependChanged(false);
25 }
26 
28  const QString &filename, QDomElement &element, bool showWarnings)
29 {
30  if (element.tagName() == "layout")
31  {
32  QString layout = getFirstText(element).toLower();
33 
34  if (layout == "vertical")
36  else
38  }
39  else if (element.tagName() == "style")
40  {
41  QString effect = getFirstText(element).toLower();
42 
43  if (effect == "slide")
45  else
47  }
48  else
49  {
50  return MythUIType::ParseElement(filename, element, showWarnings);
51  }
52 
53  return true;
54 }
55 
56 void MythUIProgressBar::Set(int start, int total, int used)
57 {
58  if (used != m_current || start != m_start || total != m_total)
59  {
60  m_start = start;
61  m_total = total;
62  SetUsed(used);
63  }
64 }
65 
67 {
68  m_start = value;
70 }
71 
73 {
76 }
77 
79 {
80  m_total = value;
82 }
83 
85 {
86  MythUIType *progressType = GetChild("progressimage");
87 
88  if (!progressType)
89  {
90  LOG(VB_GENERAL, LOG_ERR, "Progress image doesn't exist");
91  return;
92  }
93 
94  progressType->SetVisible(false);
95 
96  int total = m_total - m_start;
97  int current = m_current - m_start;
98  float percentage = 0.0;
99 
100  if (total <= 0 || current <= 0 || current > total)
101  return;
102 
103  percentage = (float)current / (float)total;
104  progressType->SetVisible(true);
105 
106  QRect fillArea = progressType->GetArea();
107 
108  int height = fillArea.height();
109  int width = fillArea.width();
110  int x = fillArea.x();
111  int y = fillArea.y();
112 
113  switch (m_effect)
114  {
115  case EffectReveal :
116 
117  if (m_layout == LayoutHorizontal)
118  {
119  width = (int)((float)fillArea.width() * percentage);
120  }
121  else
122  {
123  height = (int)((float)fillArea.height() * percentage);
124  }
125 
126  break;
127  case EffectSlide :
128 
129  if (m_layout == LayoutHorizontal)
130  {
131  int newwidth = (int)((float)fillArea.width() * percentage);
132  x = width - newwidth;
133  width = newwidth;
134  }
135  else
136  {
137  int newheight = (int)((float)fillArea.height() * percentage);
138  y = height - newheight;
139  height = newheight;
140  }
141 
142  break;
143  case EffectAnimate :
144  // Not implemented yet
145  break;
146  }
147 
148  auto *progressImage = dynamic_cast<MythUIImage *>(progressType);
149  auto *progressShape = dynamic_cast<MythUIShape *>(progressType);
150 
151  if (width <= 0)
152  width = 1;
153 
154  if (height <= 0)
155  height = 1;
156 
157  if (progressImage)
158  progressImage->SetCropRect(x, y, width, height);
159  else if (progressShape)
160  progressShape->SetCropRect(x, y, width, height);
161 
162  SetRedraw();
163 }
164 
166 {
168 }
169 
171 {
172  auto *progressbar = dynamic_cast<MythUIProgressBar *>(base);
173 
174  if (!progressbar)
175  return;
176 
177  m_layout = progressbar->m_layout;
178  m_effect = progressbar->m_effect;
179 
180  m_total = progressbar->m_total;
181  m_start = progressbar->m_start;
182  m_current = progressbar->m_current;
183 
184  MythUIType::CopyFrom(base);
185 }
186 
188 {
189  auto *progressbar = new MythUIProgressBar(parent, objectName());
190  progressbar->CopyFrom(this);
191 }
192 
194 {
195  if (m_firstdepend || visible != m_visible)
196  {
197  emit DependChanged(!visible);
198  m_firstdepend = false;
199  }
200  MythUIType::SetVisible(visible);
201 }
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::LayoutHorizontal
@ LayoutHorizontal
Definition: mythuiprogressbar.h:21
MythUIProgressBar::SetStart
void SetStart(int value)
Definition: mythuiprogressbar.cpp:66
MythUIProgressBar::Finalize
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
Definition: mythuiprogressbar.cpp:165
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
MythUIProgressBar::SetUsed
void SetUsed(int value)
Definition: mythuiprogressbar.cpp:72
MythUIType::m_visible
bool m_visible
Definition: mythuitype.h:261
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
mythuiimage.h
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
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:885
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:78
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:27
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:19
MythUIProgressBar::Set
void Set(int start, int total, int used)
Definition: mythuiprogressbar.cpp:56
MythUIType::DependChanged
void DependChanged(bool isDefault)
MythUIProgressBar
Progress bar widget.
Definition: mythuiprogressbar.h:12
MythUIProgressBar::EffectSlide
@ EffectSlide
Definition: mythuiprogressbar.h:22
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:1171
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:187
clamp
static eu8 clamp(eu8 value, eu8 low, eu8 high)
Definition: pxsup2dast.c:204
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:73
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::LayoutVertical
@ LayoutVertical
Definition: mythuiprogressbar.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:1105
MythUIProgressBar::EffectReveal
@ EffectReveal
Definition: mythuiprogressbar.h:22
MythUIProgressBar::CalculatePosition
void CalculatePosition(void)
Definition: mythuiprogressbar.cpp:84
MythUIProgressBar::CopyFrom
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
Definition: mythuiprogressbar.cpp:170
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:1237
MythUIProgressBar::SetVisible
void SetVisible(bool visible) override
Definition: mythuiprogressbar.cpp:193
build_compdb.filename
filename
Definition: build_compdb.py:21
MythUIType::SetRedraw
void SetRedraw(void)
Definition: mythuitype.cpp:313
mythuishape.h