introduce corner radius property for flat button
This commit is contained in:
parent
0ec35cbd70
commit
d2002ad5e5
|
@ -75,6 +75,21 @@ void FlatButton::setRippleStyle(RippleStyle style)
|
||||||
d->rippleStyle = style;
|
d->rippleStyle = style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FlatButton::setCornerRadius(qreal radius)
|
||||||
|
{
|
||||||
|
Q_D(FlatButton);
|
||||||
|
|
||||||
|
d->cornerRadius = radius;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal FlatButton::cornerRadius() const
|
||||||
|
{
|
||||||
|
Q_D(const FlatButton);
|
||||||
|
|
||||||
|
return d->cornerRadius;
|
||||||
|
}
|
||||||
|
|
||||||
void FlatButton::setRole(Material::Role role)
|
void FlatButton::setRole(Material::Role role)
|
||||||
{
|
{
|
||||||
Q_D(FlatButton);
|
Q_D(FlatButton);
|
||||||
|
@ -129,13 +144,14 @@ void FlatButton::paintEvent(QPaintEvent *event)
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
if (isEnabled() && bgOpacity > 0) {
|
if (isEnabled() && bgOpacity > 0) {
|
||||||
|
const qreal cr = d->cornerRadius;
|
||||||
QBrush brush;
|
QBrush brush;
|
||||||
brush.setStyle(Qt::SolidPattern);
|
brush.setStyle(Qt::SolidPattern);
|
||||||
brush.setColor(d->delegate->backgroundColor());
|
brush.setColor(d->delegate->backgroundColor());
|
||||||
painter.setOpacity(bgOpacity);
|
painter.setOpacity(bgOpacity);
|
||||||
painter.setBrush(brush);
|
painter.setBrush(brush);
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
painter.drawRoundedRect(rect(), 3, 3);
|
painter.drawRoundedRect(rect(), cr, cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEnabled() && haloOpacity > 0) {
|
if (isEnabled() && haloOpacity > 0) {
|
||||||
|
|
|
@ -11,6 +11,8 @@ class FlatButton : public QPushButton
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(qreal cornerRadius WRITE setCornerRadius READ cornerRadius)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum RippleStyle {
|
enum RippleStyle {
|
||||||
CenteredRipple,
|
CenteredRipple,
|
||||||
|
@ -26,6 +28,9 @@ public:
|
||||||
|
|
||||||
void setRippleStyle(RippleStyle style);
|
void setRippleStyle(RippleStyle style);
|
||||||
|
|
||||||
|
void setCornerRadius(qreal radius);
|
||||||
|
qreal cornerRadius() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FlatButton(FlatButtonPrivate &d, QWidget *parent = 0);
|
FlatButton(FlatButtonPrivate &d, QWidget *parent = 0);
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,8 @@ public:
|
||||||
FlatButtonPrivate(FlatButton *q)
|
FlatButtonPrivate(FlatButton *q)
|
||||||
: q_ptr(q),
|
: q_ptr(q),
|
||||||
role(Material::Default),
|
role(Material::Default),
|
||||||
rippleStyle(FlatButton::PositionedRipple)
|
rippleStyle(FlatButton::PositionedRipple),
|
||||||
|
cornerRadius(3)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
@ -29,6 +30,7 @@ public:
|
||||||
FlatButtonDelegate *delegate;
|
FlatButtonDelegate *delegate;
|
||||||
Material::Role role;
|
Material::Role role;
|
||||||
FlatButton::RippleStyle rippleStyle;
|
FlatButton::RippleStyle rippleStyle;
|
||||||
|
qreal cornerRadius;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLATBUTTON_P_H
|
#endif // FLATBUTTON_P_H
|
||||||
|
|
|
@ -149,13 +149,15 @@ void RaisedButton::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
QBrush brush;
|
QBrush brush;
|
||||||
|
|
||||||
|
const qreal cr = d->cornerRadius;
|
||||||
|
|
||||||
brush.setStyle(Qt::SolidPattern);
|
brush.setStyle(Qt::SolidPattern);
|
||||||
brush.setColor(isEnabled()
|
brush.setColor(isEnabled()
|
||||||
? palette().color(QPalette::Active, QPalette::Background)
|
? palette().color(QPalette::Active, QPalette::Background)
|
||||||
: palette().color(QPalette::Disabled, QPalette::Background));
|
: palette().color(QPalette::Disabled, QPalette::Background));
|
||||||
painter.setBrush(brush);
|
painter.setBrush(brush);
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
painter.drawRoundedRect(rect(), 3, 3);
|
painter.drawRoundedRect(rect(), cr, cr);
|
||||||
|
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
const qreal hs = static_cast<qreal>(width())*d->delegate->focusHaloSize()/2;
|
const qreal hs = static_cast<qreal>(width())*d->delegate->focusHaloSize()/2;
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
#ifndef TABS_INTERNAL_H
|
||||||
|
#define TABS_INTERNAL_H
|
||||||
|
|
||||||
|
#endif // TABS_INTERNAL_H
|
|
@ -0,0 +1,4 @@
|
||||||
|
#ifndef TABS_P_H
|
||||||
|
#define TABS_P_H
|
||||||
|
|
||||||
|
#endif // TABS_P_H
|
Loading…
Reference in New Issue