MythTV  master
mythuiscrollbar.cpp
Go to the documentation of this file.
1 // Own Header
2 #include "mythuiscrollbar.h"
3 
4 // C++
5 #include <cmath>
6 
7 // QT
8 #include <QCoreApplication>
9 #include <QDomDocument>
10 
11 // myth
12 #include "mythlogging.h"
13 
15 {
17  m_sliderPosition = 0;
19 
21 
23 }
24 
26  const QString &filename, QDomElement &element, bool showWarnings)
27 {
28  if (element.tagName() == "layout")
29  {
30  QString layout = getFirstText(element).toLower();
31 
32  if (layout == "vertical")
34  else
36  }
37  else if (element.tagName() == "hidedelay")
38  m_hideDelay = getFirstText(element).toInt();
39  else
40  return MythUIType::ParseElement(filename, element, showWarnings);
41 
42  return true;
43 }
44 
46 {
47  if (value == m_pageStep)
48  return;
49 
50  if (value < 1)
51  value = kDefaultPageStep;
52 
53  m_pageStep = value;
55 }
56 
58 {
59  if (value - 1 == m_maximum)
60  return;
61 
62  if (value < 1)
63  value = 1;
64 
65  m_maximum = value - 1;
67 }
68 
70 {
71  if (value == m_sliderPosition)
72  return;
73 
74  if (value < 0)
75  value = 0;
76 
77  if (value > m_maximum)
78  value = m_maximum;
79 
80  m_sliderPosition = value;
82 }
83 
85 {
86  if (m_maximum > 0)
87  Show();
88  else
89  {
90  Hide();
91  return;
92  }
93 
94  MythUIType *slider = GetChild("slider");
95 
96  if (!slider)
97  {
98  LOG(VB_GENERAL, LOG_ERR, "Slider element doesn't exist");
99  return;
100  }
101 
102  float percentage = (float)m_sliderPosition / m_maximum;
103  float relativeSize = (float)m_pageStep / (m_maximum + m_pageStep);
104 
105  MythRect newSliderArea = slider->GetArea();
106  MythRect fillArea = GetArea();
107  QPoint endPos(newSliderArea.left(), newSliderArea.top());
108 
109  if (m_layout == LayoutHorizontal)
110  {
111  int width = qMax((int)lroundf(fillArea.width() * relativeSize),
112  m_sliderArea.width());
113  newSliderArea.setWidth(width);
114  endPos.setX(lroundf((fillArea.width() - width) * percentage));
115  }
116  else
117  {
118  int height = qMax((int)lroundf(fillArea.height() * relativeSize),
119  m_sliderArea.height());
120  newSliderArea.setHeight(height);
121  endPos.setY(lroundf((fillArea.height() - height) * percentage));
122  }
123 
124  slider->SetArea(newSliderArea);
125  slider->SetPosition(endPos);
126 
127  if (m_hideDelay > 0)
128  {
129  if (m_timerId)
130  killTimer(m_timerId);
131  m_timerId = startTimer(m_hideDelay);
132 
133  AdjustAlpha(1, 10, 0, 255);
134  }
135 }
136 
138 {
139  MythUIType *slider = GetChild("slider");
140  if (slider)
141  m_sliderArea = slider->GetArea();
142 
144 }
145 
147 {
148  MythUIScrollBar *scrollbar = dynamic_cast<MythUIScrollBar *>(base);
149  if (!scrollbar)
150  return;
151 
152  m_layout = scrollbar->m_layout;
153  m_sliderArea = scrollbar->m_sliderArea;
154  m_hideDelay = scrollbar->m_hideDelay;
155 
156  MythUIType::CopyFrom(base);
157 }
158 
160 {
161  MythUIScrollBar *scrollbar = new MythUIScrollBar(parent, objectName());
162  scrollbar->CopyFrom(this);
163 }
164 
165 void MythUIScrollBar::timerEvent(QTimerEvent * /*event*/)
166 {
167  if (m_timerId)
168  killTimer(m_timerId);
169  m_timerId = 0;
170  AdjustAlpha(1, -10, 0, 255);
171  connect(this, SIGNAL(FinishedFading()), this, SLOT(DoneFading()));
172 }
173 
175 {
176  disconnect(this, SIGNAL(FinishedFading()), nullptr, nullptr);
177  Hide();
178 }
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
void setHeight(const QString &sHeight)
Definition: mythrect.cpp:233
void Show(void)
void FinishedFading()
MythUIScrollBar(MythUIType *parent, const QString &name)
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
The base class on which all widgets and screens are based.
Definition: mythuitype.h:63
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
Definition: mythuitype.cpp:519
void Hide(void)
MythRect m_sliderArea
void timerEvent(QTimerEvent *) override
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
static QString getFirstText(QDomElement &element)
LayoutType m_layout
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:17
void setWidth(const QString &sWidth)
Definition: mythrect.cpp:222
const int kDefaultMaxValue
void AdjustAlpha(int mode, int alphachange, int minalpha=0, int maxalpha=255)
Definition: mythuitype.cpp:906
void CreateCopy(MythUIType *parent) override
Copy the state of this widget to the one given, it must be of the same type.
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:591
#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
Scroll bar widget.
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
const int kDefaultPageStep
void CalculatePosition(void)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:132
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings) override
Parse the xml definition of this widget setting the state of the object accordingly.
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.
void SetSliderPosition(int)