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#include <algorithm>
7
8// QT
9#include <QCoreApplication>
10#include <QDomDocument>
11
12// myth
14
16{
20
22
24}
25
27 const QString &filename, QDomElement &element, bool showWarnings)
28{
29 if (element.tagName() == "layout")
30 {
31 QString layout = getFirstText(element).toLower();
32
33 if (layout == "vertical")
35 else
37 }
38 else if (element.tagName() == "hidedelay")
39 {
40 m_hideDelay = std::chrono::milliseconds(getFirstText(element).toInt());
41 }
42 else
43 {
44 return MythUIType::ParseElement(filename, element, showWarnings);
45 }
46
47 return true;
48}
49
51{
52 if (value == m_pageStep)
53 return;
54
55 if (value < 1)
56 value = kDefaultPageStep;
57
58 m_pageStep = value;
60}
61
63{
64 if (value - 1 == m_maximum)
65 return;
66
67 value = std::max(value, 1);
68
69 m_maximum = value - 1;
71}
72
74{
75 if (value == m_sliderPosition)
76 return;
77
78 value = std::clamp(value, 0, m_maximum);
79
80 m_sliderPosition = value;
82}
83
85{
86 if (m_maximum > 0)
87 {
88 Show();
89 }
90 else
91 {
92 Hide();
93 return;
94 }
95
96 MythUIType *slider = GetChild("slider");
97
98 if (!slider)
99 {
100 LOG(VB_GENERAL, LOG_ERR, "Slider element doesn't exist");
101 return;
102 }
103
104 float percentage = (float)m_sliderPosition / m_maximum;
105 float relativeSize = (float)m_pageStep / (m_maximum + m_pageStep);
106
107 MythRect newSliderArea = slider->GetArea();
108 MythRect fillArea = GetArea();
109 QPoint endPos(newSliderArea.left(), newSliderArea.top());
110
112 {
113 int width = std::max((int)lroundf(fillArea.width() * relativeSize),
114 m_sliderArea.width());
115 newSliderArea.setWidth(width);
116 endPos.setX(lroundf((fillArea.width() - width) * percentage));
117 }
118 else
119 {
120 int height = std::max((int)lroundf(fillArea.height() * relativeSize),
121 m_sliderArea.height());
122 newSliderArea.setHeight(height);
123 endPos.setY(lroundf((fillArea.height() - height) * percentage));
124 }
125
126 slider->SetArea(newSliderArea);
127 slider->SetPosition(endPos);
128
129 if (m_hideDelay > 0ms)
130 {
131 if (m_timerId)
132 killTimer(m_timerId);
133 m_timerId = startTimer(m_hideDelay);
134
135 AdjustAlpha(1, 10, 0, 255);
136 }
137}
138
140{
141 MythUIType *slider = GetChild("slider");
142 if (slider)
143 m_sliderArea = slider->GetArea();
144
146}
147
149{
150 auto *scrollbar = dynamic_cast<MythUIScrollBar *>(base);
151 if (!scrollbar)
152 return;
153
154 m_layout = scrollbar->m_layout;
155 m_sliderArea = scrollbar->m_sliderArea;
156 m_hideDelay = scrollbar->m_hideDelay;
157
159}
160
162{
163 auto *scrollbar = new MythUIScrollBar(parent, objectName());
164 scrollbar->CopyFrom(this);
165}
166
167void MythUIScrollBar::timerEvent(QTimerEvent * /*event*/)
168{
169 if (m_timerId)
170 killTimer(m_timerId);
171 m_timerId = 0;
172 AdjustAlpha(1, -10, 0, 255);
174}
175
177{
178 disconnect(this, &MythUIType::FinishedFading, nullptr, nullptr);
179 Hide();
180}
181
182#include "moc_mythuiscrollbar.cpp"
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:18
void setWidth(const QString &sWidth)
Definition: mythrect.cpp:266
void setHeight(const QString &sHeight)
Definition: mythrect.cpp:277
Scroll bar widget.
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
void SetMaximum(int value)
LayoutType m_layout
void Finalize(void) override
Perform any post-xml parsing initialisation tasks.
std::chrono::milliseconds m_hideDelay
void CreateCopy(MythUIType *parent) override
Copy the state of this widget to the one given, it must be of the same type.
void timerEvent(QTimerEvent *event) override
void CalculatePosition(void)
void CopyFrom(MythUIType *base) override
Copy this widgets state from another.
void SetPageStep(int value)
void SetSliderPosition(int value)
MythRect m_sliderArea
MythUIScrollBar(MythUIType *parent, const QString &name)
bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings) override
Parse the xml definition of this widget setting the state of the object accordingly.
The base class on which all widgets and screens are based.
Definition: mythuitype.h:97
void AdjustAlpha(int mode, int alphachange, int minalpha=0, int maxalpha=255)
Definition: mythuitype.cpp:914
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:596
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
void Hide(void)
virtual MythRect GetArea(void) const
If the object has a minimum area defined, return it, other wise return the default area.
Definition: mythuitype.cpp:871
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
Definition: mythuitype.cpp:519
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
virtual void Reset(void)
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuitype.cpp:71
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 Show(void)
void FinishedFading(void)
static QString getFirstText(QDomElement &element)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
const int kDefaultMaxValue
const int kDefaultPageStep
static eu8 clamp(eu8 value, eu8 low, eu8 high)
Definition: pxsup2dast.c:204