adjust flat button colors according to button role
This commit is contained in:
parent
2601b2e39e
commit
80d5e0acb6
|
@ -6,8 +6,8 @@
|
|||
#include <QApplication>
|
||||
#include <QPalette>
|
||||
#include <QDebug>
|
||||
#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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<Ripple *>::const_iterator i;
|
||||
for (i = ripples.begin(); i != ripples.end(); ++i)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue