MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
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 
14 
16  : MythUIType(parent, name),
17  m_layout(LayoutHorizontal), m_effect(EffectReveal),
18  m_total(0), m_start(0),
19  m_current(0)
20 {
21 }
22 
24 {
25  m_total = m_start = m_current = 0;
28 }
29 
31  const QString &filename, QDomElement &element, bool showWarnings)
32 {
33  if (element.tagName() == "layout")
34  {
35  QString layout = getFirstText(element).toLower();
36 
37  if (layout == "vertical")
39  else
41  }
42  else if (element.tagName() == "style")
43  {
44  QString effect = getFirstText(element).toLower();
45 
46  if (effect == "slide")
48  else
50  }
51  else
52  {
53  return MythUIType::ParseElement(filename, element, showWarnings);
54  }
55 
56  return true;
57 }
58 
60 {
61  m_start = value;
63 }
64 
66 {
67  if (value < m_start)
68  value = m_start;
69 
70  if (value > m_total)
71  value = m_total;
72 
73  m_current = value;
75 }
76 
78 {
79  m_total = value;
81 }
82 
84 {
85  MythUIType *progressType = GetChild("progressimage");
86 
87  if (!progressType)
88  {
89  LOG(VB_GENERAL, LOG_ERR, "Progress image doesn't exist");
90  return;
91  }
92 
93  progressType->SetVisible(false);
94 
95  int total = m_total - m_start;
96  int current = m_current - m_start;
97  float percentage = 0.0;
98 
99  if (total <= 0 || current <= 0 || current > total)
100  return;
101 
102  percentage = (float)current / (float)total;
103  progressType->SetVisible(true);
104 
105  QRect fillArea = progressType->GetArea();
106 
107  int height = fillArea.height();
108  int width = fillArea.width();
109  int x = fillArea.x();
110  int y = fillArea.y();
111 
112  switch (m_effect)
113  {
114  case EffectReveal :
115 
116  if (m_layout == LayoutHorizontal)
117  {
118  width = (int)((float)fillArea.width() * percentage);
119  }
120  else
121  {
122  height = (int)((float)fillArea.height() * percentage);
123  }
124 
125  break;
126  case EffectSlide :
127 
128  if (m_layout == LayoutHorizontal)
129  {
130  int newwidth = (int)((float)fillArea.width() * percentage);
131  x = width - newwidth;
132  width = newwidth;
133  }
134  else
135  {
136  int newheight = (int)((float)fillArea.height() * percentage);
137  y = height - newheight;
138  height = newheight;
139  }
140 
141  break;
142  case EffectAnimate :
143  // Not implemented yet
144  break;
145  }
146 
147  MythUIImage *progressImage = dynamic_cast<MythUIImage *>(progressType);
148  MythUIShape *progressShape = dynamic_cast<MythUIShape *>(progressType);
149 
150  if (width <= 0)
151  width = 1;
152 
153  if (height <= 0)
154  height = 1;
155 
156  if (progressImage)
157  progressImage->SetCropRect(x, y, width, height);
158  else if (progressShape)
159  progressShape->SetCropRect(x, y, width, height);
160 
161  SetRedraw();
162 }
163 
165 {
167 }
168 
170 {
171  MythUIProgressBar *progressbar = dynamic_cast<MythUIProgressBar *>(base);
172 
173  if (!progressbar)
174  return;
175 
176  m_layout = progressbar->m_layout;
177  m_effect = progressbar->m_effect;
178 
179  m_total = progressbar->m_total;
180  m_start = progressbar->m_start;
181  m_current = progressbar->m_current;
182 
183  MythUIType::CopyFrom(base);
184 }
185 
187 {
188  MythUIProgressBar *progressbar = new MythUIProgressBar(parent, objectName());
189  progressbar->CopyFrom(this);
190 }