Added ability to set dividers to MediaSlider.
This commit is contained in:
parent
2dd99a535c
commit
2d50c61703
|
@ -219,6 +219,10 @@ void MediaSlider::disablePaint(bool disabled) {
|
|||
_paintDisabled = disabled;
|
||||
}
|
||||
|
||||
void MediaSlider::addDivider(float64 atValue, const QSize &size) {
|
||||
_dividers.push_back(Divider{ atValue, size });
|
||||
}
|
||||
|
||||
void MediaSlider::paintEvent(QPaintEvent *e) {
|
||||
if (_paintDisabled) {
|
||||
return;
|
||||
|
@ -285,6 +289,33 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
|
|||
p.setBrush(horizontal ? inactiveFg : activeFg);
|
||||
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);
|
||||
if (markerSizeRatio > 0) {
|
||||
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:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
||||
private:
|
||||
struct Divider {
|
||||
const float64 atValue;
|
||||
const QSize size;
|
||||
};
|
||||
|
||||
QSize getSeekDecreaseSize() const override;
|
||||
float64 getOverDuration() const override;
|
||||
|
||||
|
@ -190,6 +197,8 @@ private:
|
|||
bool _alwaysDisplayMarker = false;
|
||||
bool _paintDisabled = false;
|
||||
|
||||
std::vector<Divider> _dividers;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Ui
|
||||
|
|
Loading…
Reference in New Issue