Added ability to override background and ripple colors in CallButton.
This commit is contained in:
parent
011d0ba692
commit
07359392c2
2 changed files with 28 additions and 2 deletions
|
|
@ -126,7 +126,12 @@ void CallButton::paintEvent(QPaintEvent *e) {
|
|||
p.drawEllipse(outerRect);
|
||||
}
|
||||
|
||||
if (paintFrom) {
|
||||
if (_bgOverride) {
|
||||
const auto &s = _stFrom->bgSize;
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(*_bgOverride);
|
||||
p.drawEllipse(QRect(_stFrom->bgPosition, QSize(s, s)));
|
||||
} else if (paintFrom) {
|
||||
p.drawPixmap(bgPosition, _bgFrom);
|
||||
} else if (paintTo) {
|
||||
p.drawPixmap(bgPosition, _bgTo);
|
||||
|
|
@ -137,7 +142,9 @@ void CallButton::paintEvent(QPaintEvent *e) {
|
|||
|
||||
auto rippleColorInterpolated = QColor();
|
||||
auto rippleColorOverride = &rippleColorInterpolated;
|
||||
if (paintFrom) {
|
||||
if (_rippleOverride) {
|
||||
rippleColorOverride = &(*_rippleOverride);
|
||||
} else if (paintFrom) {
|
||||
rippleColorOverride = nullptr;
|
||||
} else if (paintTo) {
|
||||
rippleColorOverride = &_stTo->button.ripple.color->c;
|
||||
|
|
@ -202,6 +209,16 @@ void CallButton::onStateChanged(State was, StateChangeSource source) {
|
|||
}
|
||||
}
|
||||
|
||||
void CallButton::setColorOverrides(rpl::producer<CallButtonColors> &&colors) {
|
||||
std::move(
|
||||
colors
|
||||
) | rpl::start_with_next([=](const CallButtonColors &c) {
|
||||
_bgOverride = c.bg;
|
||||
_rippleOverride = c.ripple;
|
||||
update();
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
QPoint CallButton::prepareRippleStartPosition() const {
|
||||
return mapFromGlobal(QCursor::pos()) - _stFrom->button.rippleAreaPosition;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@ namespace Ui {
|
|||
|
||||
class FlatLabel;
|
||||
|
||||
struct CallButtonColors {
|
||||
std::optional<QColor> bg;
|
||||
std::optional<QColor> ripple;
|
||||
};
|
||||
|
||||
class CallButton final : public RippleButton {
|
||||
public:
|
||||
CallButton(
|
||||
|
|
@ -24,6 +29,7 @@ public:
|
|||
void setProgress(float64 progress);
|
||||
void setOuterValue(float64 value);
|
||||
void setText(rpl::producer<QString> text);
|
||||
void setColorOverrides(rpl::producer<CallButtonColors> &&colors);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
|
@ -43,6 +49,9 @@ private:
|
|||
|
||||
object_ptr<FlatLabel> _label = { nullptr };
|
||||
|
||||
std::optional<QColor> _bgOverride;
|
||||
std::optional<QColor> _rippleOverride;
|
||||
|
||||
QImage _bgMask, _bg;
|
||||
QPixmap _bgFrom, _bgTo;
|
||||
QImage _iconMixedMask, _iconFrom, _iconTo, _iconMixed;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue