add various Qt properties to Flat Button
This commit is contained in:
parent
da41a3d2d4
commit
0a79208ab4
|
@ -75,6 +75,13 @@ void FlatButton::setRippleStyle(Material::RippleStyle style)
|
||||||
d->rippleStyle = style;
|
d->rippleStyle = style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Material::RippleStyle FlatButton::rippleStyle() const
|
||||||
|
{
|
||||||
|
Q_D(const FlatButton);
|
||||||
|
|
||||||
|
return d->rippleStyle;
|
||||||
|
}
|
||||||
|
|
||||||
void FlatButton::setCornerRadius(qreal radius)
|
void FlatButton::setCornerRadius(qreal radius)
|
||||||
{
|
{
|
||||||
Q_D(FlatButton);
|
Q_D(FlatButton);
|
||||||
|
@ -90,6 +97,21 @@ qreal FlatButton::cornerRadius() const
|
||||||
return d->cornerRadius;
|
return d->cornerRadius;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FlatButton::setBgMode(Qt::BGMode mode)
|
||||||
|
{
|
||||||
|
Q_D(FlatButton);
|
||||||
|
|
||||||
|
d->bgMode = mode;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::BGMode FlatButton::bgMode() const
|
||||||
|
{
|
||||||
|
Q_D(const FlatButton);
|
||||||
|
|
||||||
|
return d->bgMode;
|
||||||
|
}
|
||||||
|
|
||||||
void FlatButton::setRole(Material::Role role)
|
void FlatButton::setRole(Material::Role role)
|
||||||
{
|
{
|
||||||
Q_D(FlatButton);
|
Q_D(FlatButton);
|
||||||
|
@ -112,6 +134,13 @@ void FlatButton::setRole(Material::Role role)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Material::Role FlatButton::role() const
|
||||||
|
{
|
||||||
|
Q_D(const FlatButton);
|
||||||
|
|
||||||
|
return d->role;
|
||||||
|
}
|
||||||
|
|
||||||
FlatButton::FlatButton(FlatButtonPrivate &d, QWidget *parent)
|
FlatButton::FlatButton(FlatButtonPrivate &d, QWidget *parent)
|
||||||
: QPushButton(parent),
|
: QPushButton(parent),
|
||||||
d_ptr(&d)
|
d_ptr(&d)
|
||||||
|
@ -139,12 +168,22 @@ void FlatButton::paintEvent(QPaintEvent *event)
|
||||||
const qreal bgOpacity = d->delegate->backgroundOpacity();
|
const qreal bgOpacity = d->delegate->backgroundOpacity();
|
||||||
const qreal haloOpacity = d->delegate->focusHaloOpacity();
|
const qreal haloOpacity = d->delegate->focusHaloOpacity();
|
||||||
const qreal hs = static_cast<qreal>(width())*d->delegate->focusHaloSize()/2;
|
const qreal hs = static_cast<qreal>(width())*d->delegate->focusHaloSize()/2;
|
||||||
|
const qreal cr = d->cornerRadius;
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
|
if (Qt::OpaqueMode == d->bgMode) {
|
||||||
|
QBrush brush;
|
||||||
|
brush.setStyle(Qt::SolidPattern);
|
||||||
|
brush.setColor(Qt::red);
|
||||||
|
painter.setOpacity(1);
|
||||||
|
painter.setBrush(brush);
|
||||||
|
painter.setPen(Qt::NoPen);
|
||||||
|
painter.drawRoundedRect(rect(), cr, cr);
|
||||||
|
}
|
||||||
|
|
||||||
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());
|
||||||
|
|
|
@ -11,7 +11,10 @@ class FlatButton : public QPushButton
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(Material::Role role WRITE setRole READ role)
|
||||||
|
Q_PROPERTY(Material::RippleStyle rippleStyle WRITE setRippleStyle READ rippleStyle)
|
||||||
Q_PROPERTY(qreal cornerRadius WRITE setCornerRadius READ cornerRadius)
|
Q_PROPERTY(qreal cornerRadius WRITE setCornerRadius READ cornerRadius)
|
||||||
|
Q_PROPERTY(Qt::BGMode bgMode WRITE setBgMode READ bgMode)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FlatButton(QWidget *parent = 0);
|
explicit FlatButton(QWidget *parent = 0);
|
||||||
|
@ -19,12 +22,17 @@ public:
|
||||||
~FlatButton();
|
~FlatButton();
|
||||||
|
|
||||||
virtual void setRole(Material::Role role);
|
virtual void setRole(Material::Role role);
|
||||||
|
Material::Role role() const;
|
||||||
|
|
||||||
void setRippleStyle(Material::RippleStyle style);
|
void setRippleStyle(Material::RippleStyle style);
|
||||||
|
Material::RippleStyle rippleStyle() const;
|
||||||
|
|
||||||
void setCornerRadius(qreal radius);
|
void setCornerRadius(qreal radius);
|
||||||
qreal cornerRadius() const;
|
qreal cornerRadius() const;
|
||||||
|
|
||||||
|
void setBgMode(Qt::BGMode mode);
|
||||||
|
Qt::BGMode bgMode() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FlatButton(FlatButtonPrivate &d, QWidget *parent = 0);
|
FlatButton(FlatButtonPrivate &d, QWidget *parent = 0);
|
||||||
|
|
||||||
|
|
|
@ -19,18 +19,20 @@ public:
|
||||||
: q_ptr(q),
|
: q_ptr(q),
|
||||||
role(Material::Default),
|
role(Material::Default),
|
||||||
rippleStyle(Material::PositionedRipple),
|
rippleStyle(Material::PositionedRipple),
|
||||||
cornerRadius(3)
|
cornerRadius(3),
|
||||||
|
bgMode(Qt::TransparentMode)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void setPaletteColor(QPalette::ColorGroup group, QPalette::ColorRole role, const QString &themeColor);
|
void setPaletteColor(QPalette::ColorGroup group, QPalette::ColorRole role, const QString &themeColor);
|
||||||
|
|
||||||
FlatButton *const q_ptr;
|
FlatButton *const q_ptr;
|
||||||
RippleOverlay *ripple;
|
RippleOverlay *ripple;
|
||||||
FlatButtonDelegate *delegate;
|
FlatButtonDelegate *delegate;
|
||||||
Material::Role role;
|
Material::Role role;
|
||||||
Material::RippleStyle rippleStyle;
|
Material::RippleStyle rippleStyle;
|
||||||
qreal cornerRadius;
|
qreal cornerRadius;
|
||||||
|
Qt::BGMode bgMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLATBUTTON_P_H
|
#endif // FLATBUTTON_P_H
|
||||||
|
|
Loading…
Reference in New Issue