Added MediaSlider color overrides structure for customizable styling.

This commit is contained in:
23rd
2025-11-10 23:38:19 +03:00
committed by John Preston
parent 5b94095c78
commit 45d42c8c31
4 changed files with 49 additions and 18 deletions
@@ -261,11 +261,13 @@ void MenuVolumeItem::updateSliderColor(float64 value) {
Ui::ColorFromSerialized(0x24CD80),
Ui::ColorFromSerialized(0x3BBCEC),
} };
_slider->setActiveFgOverride((value < 0.25)
? anim::color(colors[0], colors[1], value / 0.25)
: (value < 0.5)
? anim::color(colors[1], colors[2], (value - 0.25) / 0.25)
: anim::color(colors[2], colors[3], (value - 0.5) / 0.5));
_slider->setColorOverrides({
.activeFg = (value < 0.25)
? anim::color(colors[0], colors[1], value / 0.25)
: (value < 0.5)
? anim::color(colors[1], colors[2], (value - 0.25) / 0.25)
: anim::color(colors[2], colors[3], (value - 0.5) / 0.5),
});
}
not_null<QAction*> MenuVolumeItem::action() const {
@@ -144,7 +144,9 @@ void PaidReactionSlider(
const auto update = [=](int count) {
if (activeFgOverride) {
slider->setActiveFgOverride(activeFgOverride(count));
slider->setColorOverrides({
.activeFg = activeFgOverride(count),
});
}
};
@@ -271,8 +271,8 @@ void MediaSlider::addDivider(float64 atValue, const QSize &size) {
_dividers.push_back(Divider{ atValue, size });
}
void MediaSlider::setActiveFgOverride(std::optional<QColor> color) {
_activeFgOverride = color;
void MediaSlider::setColorOverrides(ColorOverrides overrides) {
_overrides = std::move(overrides);
update();
}
@@ -324,12 +324,14 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
const auto end = from + length;
const auto activeFg = disabled
? _st.activeFgDisabled
: _activeFgOverride
? QBrush(*_activeFgOverride)
: _overrides.activeFg
? QBrush(*_overrides.activeFg)
: anim::brush(_st.activeFg, _st.activeFgOver, over);
const auto receivedTillFg = _st.receivedTillFg;
const auto inactiveFg = disabled
? _st.inactiveFgDisabled
: _overrides.inactiveFg
? QBrush(*_overrides.inactiveFg)
: anim::brush(_st.inactiveFg, _st.inactiveFgOver, over);
const auto borderFg = _st.borderFg;
if (mid > from) {
@@ -350,8 +352,14 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
till - from - borderWidth);
p.setClipRect(fromClipRect);
if (borderWidth > 0) {
p.setPen(QPen(borderFg, borderWidth));
p.setBrush(horizontal ? borderFg : inactiveFg);
const auto borderPen = _overrides.activeBorder
? QPen(*_overrides.activeBorder, borderWidth)
: QPen(borderFg, borderWidth);
const auto bgBrush = _overrides.activeBg
? QBrush(*_overrides.activeBg)
: (horizontal ? borderFg : inactiveFg);
p.setPen(borderPen);
p.setBrush(bgBrush);
} else {
p.setPen(Qt::NoPen);
p.setBrush(horizontal ? activeFg : inactiveFg);
@@ -390,7 +398,10 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
end - begin - borderWidth);
p.setClipRect(endClipRect);
if (borderWidth > 0) {
p.setPen(QPen(borderFg, borderWidth));
const auto endBorderPen = _overrides.inactiveBorder
? QPen(*_overrides.inactiveBorder, borderWidth)
: QPen(borderFg, borderWidth);
p.setPen(endBorderPen);
} else {
p.setPen(Qt::NoPen);
}
@@ -450,12 +461,18 @@ void MediaSlider::paintEvent(QPaintEvent *e) {
((1. - markerSizeRatio) * size) / 2.);
if (remove * 2 < size) {
p.setClipRect(rect());
const auto seekFg = _overrides.seekFg
? QBrush(*_overrides.seekFg)
: activeFg;
if (borderWidth > 0) {
p.setPen(QPen(borderFg, borderWidth));
p.setBrush(activeFg);
const auto seekBorderPen = _overrides.seekBorder
? QPen(*_overrides.seekBorder, borderWidth)
: QPen(borderFg, borderWidth);
p.setPen(seekBorderPen);
p.setBrush(seekFg);
} else {
p.setPen(Qt::NoPen);
p.setBrush(activeFg);
p.setBrush(seekFg);
}
const auto xshift = horizontal
? std::max(
@@ -147,6 +147,16 @@ private:
class MediaSlider : public ContinuousSlider {
public:
struct ColorOverrides {
std::optional<QColor> activeFg;
std::optional<QColor> activeBg;
std::optional<QColor> activeBorder;
std::optional<QColor> seekFg;
std::optional<QColor> seekBorder;
std::optional<QColor> inactiveFg;
std::optional<QColor> inactiveBorder;
};
MediaSlider(QWidget *parent, const style::MediaSlider &st);
void setAlwaysDisplayMarker(bool alwaysDisplayMarker) {
@@ -226,7 +236,7 @@ public:
});
}
void setActiveFgOverride(std::optional<QColor> color);
void setColorOverrides(ColorOverrides overrides);
void addDivider(float64 atValue, const QSize &size);
protected:
@@ -246,7 +256,7 @@ private:
bool _paintDisabled = false;
std::vector<Divider> _dividers;
std::optional<QColor> _activeFgOverride;
ColorOverrides _overrides;
};