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 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
110 {
111 int width = std::max((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 = std::max((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 > 0ms)
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 auto *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
157}
158
160{
161 auto *scrollbar = new MythUIScrollBar(parent, objectName());
162 scrollbar->CopyFrom(this);
163}
164
165void MythUIScrollBar::timerEvent(QTimerEvent * /*event*/)
166{
167 if (m_timerId)
168 killTimer(m_timerId);
169 m_timerId = 0;
170 AdjustAlpha(1, -10, 0, 255);
172}
173
175{
176 disconnect(this, &MythUIType::FinishedFading, nullptr, nullptr);
177 Hide();
178}
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:86
void AdjustAlpha(int mode, int alphachange, int minalpha=0, int maxalpha=255)
Definition: mythuitype.cpp:928
virtual void SetArea(const MythRect &rect)
Definition: mythuitype.cpp:610
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:885
void SetPosition(int x, int y)
Convenience method, calls SetPosition(const MythPoint&) Override that instead to change functionality...
Definition: mythuitype.cpp:533
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
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.
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:206