From 80d5e0acb6cf44bacee89b2eb4a89bb0bc263efd Mon Sep 17 00:00:00 2001 From: laserpants Date: Sun, 15 May 2016 09:19:45 +0300 Subject: [PATCH] adjust flat button colors according to button role --- components/flatbutton.cpp | 12 ++++++++++-- components/flatbutton_p.h | 8 ++++++++ lib/ripple.cpp | 4 ++-- lib/rippleoverlay.cpp | 9 +++++++-- lib/rippleoverlay.h | 4 ++-- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/components/flatbutton.cpp b/components/flatbutton.cpp index 4b61666..b7619dd 100644 --- a/components/flatbutton.cpp +++ b/components/flatbutton.cpp @@ -6,8 +6,8 @@ #include #include #include -#include "lib/style.h" #include "lib/rippleoverlay.h" +#include "lib/ripple.h" #include "flatbutton_p.h" @@ -64,6 +64,8 @@ void FlatButton::paintEvent(QPaintEvent *event) { Q_UNUSED(event) + Q_D(FlatButton); + QStylePainter painter(this); QStyleOptionButton option; @@ -77,6 +79,7 @@ void FlatButton::paintEvent(QPaintEvent *event) QPainter painter(this); QBrush brush; brush.setStyle(Qt::SolidPattern); + brush.setColor(d->textColor()); painter.setOpacity(0.1); painter.fillRect(rect(), brush); } @@ -95,7 +98,12 @@ void FlatButton::mousePressEvent(QMouseEvent *event) { Q_D(FlatButton); - d->ripple->addRipple(event->pos()); + Ripple *ripple = new Ripple(event->pos()); + ripple->setRadiusEndValue(100); + ripple->setOpacityStartValue(0.2); + ripple->setColor(d->textColor()); + + d->ripple->addRipple(ripple); QPushButton::mousePressEvent(event); } diff --git a/components/flatbutton_p.h b/components/flatbutton_p.h index 02cd22b..6c939bf 100644 --- a/components/flatbutton_p.h +++ b/components/flatbutton_p.h @@ -14,6 +14,7 @@ class FlatButtonPrivate public: FlatButtonPrivate(FlatButton *parent); + QColor textColor() const; void setTextColor(const QString &themeColor); FlatButton *const q_ptr; @@ -44,6 +45,13 @@ FlatButtonPrivate::FlatButtonPrivate(FlatButton *parent) parent->setPalette(palette); } +QColor FlatButtonPrivate::textColor() const +{ + Q_Q(const FlatButton); + + return q->palette().color(QPalette::Active, QPalette::ButtonText); +} + void FlatButtonPrivate::setTextColor(const QString &themeColor) { Q_Q(FlatButton); diff --git a/lib/ripple.cpp b/lib/ripple.cpp index d204d75..ab458c1 100644 --- a/lib/ripple.cpp +++ b/lib/ripple.cpp @@ -53,9 +53,9 @@ QPropertyAnimation *Ripple::animate(const QByteArray &property) { QPropertyAnimation *animation = new QPropertyAnimation; animation->setPropertyName(property); - animation->setEasingCurve(QEasingCurve::OutCubic); + animation->setEasingCurve(QEasingCurve::OutQuad); animation->setTargetObject(this); - animation->setDuration(1000); + animation->setDuration(800); _group.addAnimation(animation); return animation; } diff --git a/lib/rippleoverlay.cpp b/lib/rippleoverlay.cpp index 4a10f89..7212c43 100644 --- a/lib/rippleoverlay.cpp +++ b/lib/rippleoverlay.cpp @@ -14,11 +14,15 @@ RippleOverlay::~RippleOverlay() { } -void RippleOverlay::addRipple(const QPoint &position, const QColor &color, qreal radius) +void RippleOverlay::addRipple(const QPoint &position, qreal radius) { Ripple *ripple = new Ripple(position); ripple->setRadiusEndValue(radius); - ripple->setColor(color); + addRipple(ripple); +} + +void RippleOverlay::addRipple(Ripple *ripple) +{ ripples.push_back(ripple); connect(ripple, SIGNAL(changed()), this, SLOT(update())); connect(ripple, SIGNAL(finished()), this, SLOT(deleteRipple())); @@ -31,6 +35,7 @@ void RippleOverlay::paintEvent(QPaintEvent *event) QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(Qt::NoPen); QList::const_iterator i; for (i = ripples.begin(); i != ripples.end(); ++i) diff --git a/lib/rippleoverlay.h b/lib/rippleoverlay.h index 3b9fd97..4c262b1 100644 --- a/lib/rippleoverlay.h +++ b/lib/rippleoverlay.h @@ -13,8 +13,8 @@ public: explicit RippleOverlay(QWidget *parent = 0); ~RippleOverlay(); - void addRipple(const QPoint &position, const QColor &color = Qt::black, - qreal radius = 300); + void addRipple(const QPoint &position, qreal radius = 300); + void addRipple(Ripple *ripple); protected: void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;