adjust RaisedButton colors
This commit is contained in:
parent
18fdf9c03c
commit
37b4c3c531
|
@ -34,15 +34,14 @@ void FlatButtonPrivate::init()
|
|||
q->setPalette(palette);
|
||||
}
|
||||
|
||||
void FlatButtonPrivate::setTextColor(const QString &themeColor)
|
||||
void FlatButtonPrivate::setPaletteColor(QPalette::ColorGroup group, QPalette::ColorRole role, const QString &themeColor)
|
||||
{
|
||||
Q_Q(FlatButton);
|
||||
|
||||
QPalette palette(q->palette());
|
||||
Style &style = Style::instance();
|
||||
|
||||
palette.setColor(QPalette::Active, QPalette::ButtonText,
|
||||
style.themeColor(themeColor));
|
||||
palette.setColor(group, role, style.themeColor(themeColor));
|
||||
|
||||
q->setPalette(palette);
|
||||
}
|
||||
|
@ -76,18 +75,16 @@ void FlatButton::setRole(Material::Role role)
|
|||
switch (role)
|
||||
{
|
||||
case Material::Primary:
|
||||
d->setTextColor("primary1");
|
||||
d->delegate->assignProperties();
|
||||
d->setPaletteColor(QPalette::Active, QPalette::ButtonText, "primary1");
|
||||
break;
|
||||
case Material::Secondary:
|
||||
d->setTextColor("accent1");
|
||||
d->delegate->assignProperties();
|
||||
d->setPaletteColor(QPalette::Active, QPalette::ButtonText, "accent1");
|
||||
break;
|
||||
default:
|
||||
d->setTextColor("text");
|
||||
d->delegate->assignProperties();
|
||||
d->setPaletteColor(QPalette::Active, QPalette::ButtonText, "text");
|
||||
break;
|
||||
}
|
||||
d->delegate->assignProperties();
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ public:
|
|||
explicit FlatButton(const QString &text, QWidget *parent = 0);
|
||||
~FlatButton();
|
||||
|
||||
void setRole(Material::Role role);
|
||||
virtual void setRole(Material::Role role);
|
||||
|
||||
protected:
|
||||
FlatButton(FlatButtonPrivate &d, QWidget *parent = 0);
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#ifndef FLATBUTTON_P_H
|
||||
#define FLATBUTTON_P_H
|
||||
|
||||
#include "flatbutton.h"
|
||||
#include <QPalette>
|
||||
#include "lib/rippleoverlay.h"
|
||||
#include "lib/theme.h"
|
||||
#include "lib/style.h"
|
||||
#include "flatbutton_internal.h"
|
||||
|
||||
class FlatButton;
|
||||
|
||||
class FlatButtonPrivate
|
||||
{
|
||||
Q_DISABLE_COPY(FlatButtonPrivate)
|
||||
|
@ -19,7 +21,7 @@ public:
|
|||
{}
|
||||
|
||||
void init();
|
||||
void setTextColor(const QString &themeColor);
|
||||
void setPaletteColor(QPalette::ColorGroup group, QPalette::ColorRole role, const QString &themeColor);
|
||||
|
||||
FlatButton *const q_ptr;
|
||||
RippleOverlay *ripple;
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
#include "raisedbutton.h"
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QEventTransition>
|
||||
#include <QSignalTransition>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QPainter>
|
||||
#include <QStylePainter>
|
||||
#include <QStyleOption>
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
#include "raisedbutton_p.h"
|
||||
|
||||
void RaisedButtonPrivate::init()
|
||||
|
@ -14,7 +17,7 @@ void RaisedButtonPrivate::init()
|
|||
QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
|
||||
effect->setBlurRadius(7);
|
||||
effect->setOffset(QPointF(0, 0));
|
||||
effect->setColor(QColor(0, 0, 0, 100));
|
||||
effect->setColor(QColor(0, 0, 0, 60));
|
||||
q->setGraphicsEffect(effect);
|
||||
|
||||
QState *normalState = new QState;
|
||||
|
@ -48,6 +51,20 @@ void RaisedButtonPrivate::init()
|
|||
|
||||
//
|
||||
|
||||
transition = new QEventTransition(q, QEvent::MouseButtonDblClick);
|
||||
transition->setTargetState(pressedState);
|
||||
|
||||
animation = new QPropertyAnimation(effect, "offset");
|
||||
animation->setDuration(100);
|
||||
transition->addAnimation(animation);
|
||||
animation = new QPropertyAnimation(effect, "blurRadius");
|
||||
animation->setDuration(100);
|
||||
transition->addAnimation(animation);
|
||||
|
||||
normalState->addTransition(transition);
|
||||
|
||||
//
|
||||
|
||||
transition = new QEventTransition(q, QEvent::MouseButtonRelease);
|
||||
transition->setTargetState(normalState);
|
||||
|
||||
|
@ -63,10 +80,6 @@ void RaisedButtonPrivate::init()
|
|||
//
|
||||
|
||||
machine.setInitialState(normalState);
|
||||
|
||||
QObject::connect(effect, SIGNAL(blurRadiusChanged(qreal)), q, SLOT(update()));
|
||||
QObject::connect(effect, SIGNAL(offsetChanged(QPointF)), q, SLOT(update()));
|
||||
|
||||
machine.start();
|
||||
}
|
||||
|
||||
|
@ -82,17 +95,44 @@ RaisedButton::~RaisedButton()
|
|||
{
|
||||
}
|
||||
|
||||
void RaisedButton::setRole(Material::Role role)
|
||||
{
|
||||
Q_D(FlatButton);
|
||||
|
||||
d->role = role;
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case Material::Primary:
|
||||
d->setPaletteColor(QPalette::Active, QPalette::Background, "primary1");
|
||||
d->setPaletteColor(QPalette::Active, QPalette::ButtonText, "alternateText");
|
||||
break;
|
||||
case Material::Secondary:
|
||||
d->setPaletteColor(QPalette::Active, QPalette::Background, "accent1");
|
||||
d->setPaletteColor(QPalette::Active, QPalette::ButtonText, "alternateText");
|
||||
break;
|
||||
default:
|
||||
d->setPaletteColor(QPalette::Active, QPalette::Background, "canvas");
|
||||
d->setPaletteColor(QPalette::Active, QPalette::ButtonText, "text");
|
||||
break;
|
||||
}
|
||||
d->delegate->assignProperties();
|
||||
update();
|
||||
}
|
||||
|
||||
void RaisedButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
Q_D(RaisedButton);
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QBrush brush;
|
||||
brush.setStyle(Qt::SolidPattern);
|
||||
brush.setColor(Qt::white);
|
||||
brush.setColor(palette().color(QPalette::Active, QPalette::Background));
|
||||
painter.setBrush(brush);
|
||||
painter.setPen(Qt::NoPen);
|
||||
|
||||
|
@ -105,6 +145,4 @@ void RaisedButton::paintEvent(QPaintEvent *event)
|
|||
option.features |= QStyleOptionButton::Flat;
|
||||
|
||||
style.drawControl(QStyle::CE_PushButtonLabel, option);
|
||||
|
||||
//FlatButton::paintEvent(event);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ public:
|
|||
explicit RaisedButton(QWidget *parent = 0);
|
||||
~RaisedButton();
|
||||
|
||||
void setRole(Material::Role role) Q_DECL_OVERRIDE;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
|
|
|
@ -10,10 +10,10 @@ ExampleList::ExampleList(QWidget *parent)
|
|||
|
||||
widget->setLayout(layout);
|
||||
|
||||
QSizePolicy policy;
|
||||
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
||||
policy.setVerticalPolicy(QSizePolicy::Maximum);
|
||||
widget->setSizePolicy(policy);
|
||||
//QSizePolicy policy;
|
||||
//policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
||||
//policy.setVerticalPolicy(QSizePolicy::Maximum);
|
||||
//widget->setSizePolicy(policy);
|
||||
|
||||
setWidget(widget);
|
||||
setWidgetResizable(true);
|
||||
|
|
|
@ -15,7 +15,7 @@ FlatButtonExamples::FlatButtonExamples(QWidget *parent)
|
|||
flatButton->setText("Press me!");
|
||||
flatButton->setMinimumSize(200, 42);
|
||||
|
||||
// flatButton->setRole(Material::Secondary);
|
||||
flatButton->setRole(Material::Primary);
|
||||
// flatButton->setDisabled(true);
|
||||
|
||||
ExampleView *view = new ExampleView;
|
||||
|
|
|
@ -23,7 +23,7 @@ Frame::Frame(QWidget *parent)
|
|||
_layout->setStretch(0, 1);
|
||||
_layout->setStretch(1, 1);
|
||||
|
||||
setMinimumHeight(300);
|
||||
//setMinimumHeight(300);
|
||||
}
|
||||
|
||||
Frame::~Frame()
|
||||
|
|
|
@ -9,23 +9,42 @@ RaisedButtonExamples::RaisedButtonExamples(QWidget *parent)
|
|||
{
|
||||
QLayout *layout = widget()->layout();
|
||||
|
||||
{
|
||||
RaisedButton *raisedButton = new RaisedButton;
|
||||
raisedButton->setText("Press me!");
|
||||
raisedButton->setMinimumSize(200, 42);
|
||||
RaisedButton *raisedButton = new RaisedButton;
|
||||
raisedButton->setRole(Material::Primary);
|
||||
raisedButton->setText("Press me!");
|
||||
|
||||
ExampleView *view = new ExampleView;
|
||||
view->setWidget(raisedButton);
|
||||
//raisedButton->setFixedSize(400, 50);
|
||||
|
||||
Frame *frame = new Frame;
|
||||
frame->setCodeSnippet(
|
||||
"RaisedButton *raisedButton = new RaisedButton;\n"
|
||||
"raisedButton->setText(\"Press me!\");"
|
||||
);
|
||||
frame->setWidget(view);
|
||||
layout->addWidget(raisedButton);
|
||||
//layout->setAlignment(raisedButton, Qt::AlignHCenter);
|
||||
|
||||
layout->addWidget(frame);
|
||||
}
|
||||
|
||||
QPushButton *pb = new QPushButton;
|
||||
pb->setText("Press me!");
|
||||
|
||||
layout->addWidget(pb);
|
||||
|
||||
//QLayout *layout = widget()->layout();
|
||||
|
||||
//{
|
||||
// RaisedButton *raisedButton = new RaisedButton;
|
||||
// raisedButton->setText("Press me!");
|
||||
// raisedButton->setMinimumSize(200, 42);
|
||||
|
||||
// raisedButton->setRole(Material::Primary);
|
||||
|
||||
// ExampleView *view = new ExampleView;
|
||||
// view->setWidget(raisedButton);
|
||||
|
||||
// Frame *frame = new Frame;
|
||||
// frame->setCodeSnippet(
|
||||
// "RaisedButton *raisedButton = new RaisedButton;\n"
|
||||
// "raisedButton->setText(\"Press me!\");"
|
||||
// );
|
||||
// frame->setWidget(view);
|
||||
|
||||
// layout->addWidget(frame);
|
||||
//}
|
||||
}
|
||||
|
||||
RaisedButtonExamples::~RaisedButtonExamples()
|
||||
|
|
Loading…
Reference in New Issue