From 065a2c63046c552c12ec6a42e737dd2a889d9c28 Mon Sep 17 00:00:00 2001 From: laserpants Date: Sun, 12 Jun 2016 17:40:56 +0300 Subject: [PATCH] style FAB and Raised Button for disabled mode --- components/fab.cpp | 3 ++- components/raisedbutton.cpp | 24 +++++++++++++++++++++++- components/raisedbutton.h | 5 +++++ components/raisedbutton_p.h | 1 + lib/theme.cpp | 2 ++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/components/fab.cpp b/components/fab.cpp index daa6592..d2da878 100644 --- a/components/fab.cpp +++ b/components/fab.cpp @@ -193,7 +193,8 @@ void FloatingActionButton::paintEvent(QPaintEvent *event) QBrush brush; brush.setStyle(Qt::SolidPattern); brush.setColor(isEnabled() - ? backgroundColor() : palette().color(QPalette::Disabled, QPalette::Background)); + ? backgroundColor() + : disabledTextColor()); painter.setBrush(brush); painter.setPen(Qt::NoPen); diff --git a/components/raisedbutton.cpp b/components/raisedbutton.cpp index 717d311..be571ca 100644 --- a/components/raisedbutton.cpp +++ b/components/raisedbutton.cpp @@ -109,6 +109,25 @@ RaisedButton::~RaisedButton() { } +void RaisedButton::setDisabledBackgroundColor(const QColor &color) +{ + Q_D(RaisedButton); + + d->disabledBackgroundColor = color; + setUseThemeColors(false); +} + +QColor RaisedButton::disabledBackgroundColor() const +{ + Q_D(const RaisedButton); + + if (d->useThemeColors || !d->disabledBackgroundColor.isValid()) { + return Style::instance().themeColor("disabled3"); + } else { + return d->disabledBackgroundColor; + } +} + RaisedButton::RaisedButton(RaisedButtonPrivate &d, QWidget *parent) : FlatButton(d, parent) { @@ -122,8 +141,10 @@ bool RaisedButton::event(QEvent *event) if (QEvent::EnabledChange == event->type()) { if (isEnabled()) { d->machine.start(); + d->effect->setEnabled(true); } else { d->machine.stop(); + d->effect->setEnabled(false); } } return FlatButton::event(event); @@ -145,7 +166,8 @@ void RaisedButton::paintEvent(QPaintEvent *event) QBrush brush; brush.setStyle(Qt::SolidPattern); brush.setColor(isEnabled() - ? backgroundColor() : palette().color(QPalette::Disabled, QPalette::Background)); + ? backgroundColor() + : disabledBackgroundColor()); painter.setBrush(brush); painter.setPen(Qt::NoPen); painter.drawRoundedRect(rect(), cr, cr); diff --git a/components/raisedbutton.h b/components/raisedbutton.h index d62dcbe..5950a24 100644 --- a/components/raisedbutton.h +++ b/components/raisedbutton.h @@ -9,10 +9,15 @@ class RaisedButton : public FlatButton { Q_OBJECT + Q_PROPERTY(QColor disabledBackgroundColor WRITE setDisabledBackgroundColor READ disabledBackgroundColor) + public: explicit RaisedButton(QWidget *parent = 0); ~RaisedButton(); + void setDisabledBackgroundColor(const QColor &color); + QColor disabledBackgroundColor() const; + protected: RaisedButton(RaisedButtonPrivate &d, QWidget *parent = 0); diff --git a/components/raisedbutton_p.h b/components/raisedbutton_p.h index fb321f1..cd65dd1 100644 --- a/components/raisedbutton_p.h +++ b/components/raisedbutton_p.h @@ -20,6 +20,7 @@ public: QState *normalState; QState *pressedState; QGraphicsDropShadowEffect *effect; + QColor disabledBackgroundColor; }; #endif // RAISEDBUTTON_P_H diff --git a/lib/theme.cpp b/lib/theme.cpp index 4fd071d..d1d3a18 100644 --- a/lib/theme.cpp +++ b/lib/theme.cpp @@ -24,6 +24,8 @@ Theme::Theme(QObject *parent) setColor("canvas", Material::white); setColor("border", Material::grey300); setColor("disabled", Material::minBlack); + setColor("disabled2", Material::faintBlack); + setColor("disabled3", Material::grey300); } Theme::~Theme()