From 2d50c617039a57f2771c2d38ac57db5c42275527 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 30 Jan 2021 14:43:46 +0300 Subject: [PATCH] Added ability to set dividers to MediaSlider. --- .../ui/widgets/continuous_sliders.cpp | 31 +++++++++++++++++++ .../ui/widgets/continuous_sliders.h | 9 ++++++ 2 files changed, 40 insertions(+) diff --git a/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp b/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp index 7813d2aedb..e98a7a9917 100644 --- a/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp +++ b/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp @@ -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)); diff --git a/Telegram/SourceFiles/ui/widgets/continuous_sliders.h b/Telegram/SourceFiles/ui/widgets/continuous_sliders.h index 80c7e41948..1141b8fa90 100644 --- a/Telegram/SourceFiles/ui/widgets/continuous_sliders.h +++ b/Telegram/SourceFiles/ui/widgets/continuous_sliders.h @@ -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 _dividers; + }; } // namespace Ui