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{
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
56void 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;
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
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
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
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}
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
Progress bar widget.
void CalculatePosition(void)
MythUIProgressBar(MythUIType *parent, const QString &name)
void SetUsed(int value)
void SetStart(int value)
void SetTotal(int value)
void Set(int start, int total, int used)
bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings) override
Parse the xml definition of this widget setting the state of the object accordingly.
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.
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
void SetVisible(bool visible) override
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
A widget for rendering primitive shapes and lines.
Definition: mythuishape.h:22
void SetCropRect(int x, int y, int width, int height)
Definition: mythuishape.cpp:31
The base class on which all widgets and screens are based.
Definition: mythuitype.h:86
virtual void SetVisible(bool visible)
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
void SetRedraw(void)
Definition: mythuitype.cpp:313
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
bool m_visible
Definition: mythuitype.h:263
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
void DependChanged(bool isDefault)
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuitype.cpp:73
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.
static QString getFirstText(QDomElement &element)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
static eu8 clamp(eu8 value, eu8 low, eu8 high)
Definition: pxsup2dast.c:206