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  MythUIImage *progressImage = dynamic_cast<MythUIImage *>(progressType);
142  MythUIShape *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  MythUIProgressBar *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  MythUIProgressBar *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 }
void SetVisible(bool visible) override
void CalculatePosition(void)
void SetRedraw(void)
Definition: mythuitype.cpp:295
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
void SetCropRect(int x, int y, int width, int height)
Crop the image using the given rectangle, useful for removing unsightly edges from imported images or...
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
The base class on which all widgets and screens are based.
Definition: mythuitype.h:63
virtual void SetVisible(bool visible)
virtual MythRect GetArea(void) const
If the object has a minimum area defined, return it, other wise return the default area.
Definition: mythuitype.cpp:863
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
void DependChanged(bool isDefault)
static QString getFirstText(QDomElement &element)
void SetCropRect(int x, int y, int width, int height)
Definition: mythuishape.cpp:31
bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings) override
Parse the xml definition of this widget setting the state of the object accordingly.
A widget for rendering primitive shapes and lines.
Definition: mythuishape.h:21
bool m_Visible
Definition: mythuitype.h:236
MythUIProgressBar(MythUIType *parent, const QString &name)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuitype.cpp:69
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
void CreateCopy(MythUIType *parent) override
Copy the state of this widget to the one given, it must be of the same type.
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
Progress bar widget.
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:132
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.