mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-08 08:04:08 +02:00
Added ability to set dividers to MediaSlider.
This commit is contained in:
parent
2dd99a535c
commit
2d50c61703
2 changed files with 40 additions and 0 deletions
|
@ -219,6 +219,10 @@ void MediaSlider::disablePaint(bool disabled) {
|
||||||
_paintDisabled = disabled;
|
_paintDisabled = disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MediaSlider::addDivider(float64 atValue, const QSize &size) {
|
||||||
|
_dividers.push_back(Divider{ atValue, size });
|
||||||
|
}
|
||||||
|
|
||||||
void MediaSlider::paintEvent(QPaintEvent *e) {
|
void MediaSlider::paintEvent(QPaintEvent *e) {
|
||||||
if (_paintDisabled) {
|
if (_paintDisabled) {
|
||||||
return;
|
return;
|
||||||
|
@ -285,6 +289,33 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
|
||||||
p.setBrush(horizontal ? inactiveFg : activeFg);
|
p.setBrush(horizontal ? inactiveFg : activeFg);
|
||||||
p.drawRoundedRect(endRect, radius, radius);
|
p.drawRoundedRect(endRect, radius, radius);
|
||||||
}
|
}
|
||||||
|
if (!_dividers.empty()) {
|
||||||
|
p.setClipRect(rect());
|
||||||
|
for (const auto ÷r : _dividers) {
|
||||||
|
const auto dividerValue = horizontal
|
||||||
|
? divider.atValue
|
||||||
|
: (1. - divider.atValue);
|
||||||
|
const auto dividerMid = std::round(from
|
||||||
|
+ dividerValue * length);
|
||||||
|
const auto &size = divider.size;
|
||||||
|
const auto rect = horizontal
|
||||||
|
? QRect(
|
||||||
|
dividerMid - size.width() / 2,
|
||||||
|
(height() - size.height()) / 2,
|
||||||
|
size.width(),
|
||||||
|
size.height())
|
||||||
|
: QRect(
|
||||||
|
(width() - size.height()) / 2,
|
||||||
|
dividerMid - size.width() / 2,
|
||||||
|
size.height(),
|
||||||
|
size.width());
|
||||||
|
p.setBrush(((value < dividerValue) == horizontal)
|
||||||
|
? inactiveFg
|
||||||
|
: activeFg);
|
||||||
|
const auto dividerRadius = size.width() / 2.;
|
||||||
|
p.drawRoundedRect(rect, dividerRadius, dividerRadius);
|
||||||
|
}
|
||||||
|
}
|
||||||
const auto markerSizeRatio = disabled ? 0. : (_alwaysDisplayMarker ? 1. : over);
|
const auto markerSizeRatio = disabled ? 0. : (_alwaysDisplayMarker ? 1. : over);
|
||||||
if (markerSizeRatio > 0) {
|
if (markerSizeRatio > 0) {
|
||||||
const auto position = qRound(markerFrom + value * markerLength) - (horizontal ? (_st.seekSize.width() / 2) : (_st.seekSize.height() / 2));
|
const auto position = qRound(markerFrom + value * markerLength) - (horizontal ? (_st.seekSize.width() / 2) : (_st.seekSize.height() / 2));
|
||||||
|
|
|
@ -179,10 +179,17 @@ public:
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addDivider(float64 atValue, const QSize &size);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct Divider {
|
||||||
|
const float64 atValue;
|
||||||
|
const QSize size;
|
||||||
|
};
|
||||||
|
|
||||||
QSize getSeekDecreaseSize() const override;
|
QSize getSeekDecreaseSize() const override;
|
||||||
float64 getOverDuration() const override;
|
float64 getOverDuration() const override;
|
||||||
|
|
||||||
|
@ -190,6 +197,8 @@ private:
|
||||||
bool _alwaysDisplayMarker = false;
|
bool _alwaysDisplayMarker = false;
|
||||||
bool _paintDisabled = false;
|
bool _paintDisabled = false;
|
||||||
|
|
||||||
|
std::vector<Divider> _dividers;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
Loading…
Add table
Reference in a new issue