fix raised button focus halo animation
This commit is contained in:
parent
921bc2aff4
commit
7a70648dda
|
@ -123,7 +123,7 @@ 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 int hs = d->delegate->focusHaloSize();
|
const int hs = (width()/2)*d->delegate->focusHaloSize();
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
|
@ -15,7 +15,7 @@ FlatButtonDelegate::FlatButtonDelegate(FlatButton *parent)
|
||||||
_hoveredState(new QState(this)),
|
_hoveredState(new QState(this)),
|
||||||
_hoveredFocusedState(new QState(this)),
|
_hoveredFocusedState(new QState(this)),
|
||||||
_pressedState(new QState(this)),
|
_pressedState(new QState(this)),
|
||||||
_focusHaloSize(85)
|
_focusHaloSize(0.8)
|
||||||
{
|
{
|
||||||
setInitialState(_normalState);
|
setInitialState(_normalState);
|
||||||
|
|
||||||
|
@ -37,15 +37,15 @@ FlatButtonDelegate::FlatButtonDelegate(FlatButton *parent)
|
||||||
|
|
||||||
grow->setTargetObject(this);
|
grow->setTargetObject(this);
|
||||||
grow->setPropertyName("focusHaloSize");
|
grow->setPropertyName("focusHaloSize");
|
||||||
grow->setStartValue(85);
|
grow->setStartValue(0.8);
|
||||||
grow->setEndValue(100);
|
grow->setEndValue(0.9);
|
||||||
grow->setEasingCurve(QEasingCurve::InOutSine);
|
grow->setEasingCurve(QEasingCurve::InOutSine);
|
||||||
grow->setDuration(840);
|
grow->setDuration(840);
|
||||||
|
|
||||||
shrink->setTargetObject(this);
|
shrink->setTargetObject(this);
|
||||||
shrink->setPropertyName("focusHaloSize");
|
shrink->setPropertyName("focusHaloSize");
|
||||||
shrink->setStartValue(100);
|
shrink->setStartValue(0.9);
|
||||||
shrink->setEndValue(85);
|
shrink->setEndValue(0.8);
|
||||||
shrink->setEasingCurve(QEasingCurve::InOutSine);
|
shrink->setEasingCurve(QEasingCurve::InOutSine);
|
||||||
shrink->setDuration(840);
|
shrink->setDuration(840);
|
||||||
|
|
||||||
|
@ -94,13 +94,13 @@ qreal FlatButtonDelegate::focusHaloOpacity() const
|
||||||
return _focusHaloOpacity;
|
return _focusHaloOpacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatButtonDelegate::setFocusHaloSize(int size)
|
void FlatButtonDelegate::setFocusHaloSize(qreal size)
|
||||||
{
|
{
|
||||||
_focusHaloSize = size;
|
_focusHaloSize = size;
|
||||||
button->update();
|
button->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
int FlatButtonDelegate::focusHaloSize() const
|
qreal FlatButtonDelegate::focusHaloSize() const
|
||||||
{
|
{
|
||||||
return _focusHaloSize;
|
return _focusHaloSize;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ void FlatButtonDelegate::assignProperties()
|
||||||
|
|
||||||
_normalFocusedState->assignProperty(this, "backgroundOpacity", 0);
|
_normalFocusedState->assignProperty(this, "backgroundOpacity", 0);
|
||||||
_normalFocusedState->assignProperty(this, "backgroundColor", textColor);
|
_normalFocusedState->assignProperty(this, "backgroundColor", textColor);
|
||||||
_normalFocusedState->assignProperty(this, "focusHaloOpacity", 0.12);
|
_normalFocusedState->assignProperty(this, "focusHaloOpacity", 0.15);
|
||||||
|
|
||||||
_hoveredState->assignProperty(this, "backgroundOpacity", 0.15);
|
_hoveredState->assignProperty(this, "backgroundOpacity", 0.15);
|
||||||
_hoveredState->assignProperty(this, "backgroundColor", textColor);
|
_hoveredState->assignProperty(this, "backgroundColor", textColor);
|
||||||
|
@ -124,7 +124,7 @@ void FlatButtonDelegate::assignProperties()
|
||||||
|
|
||||||
_hoveredFocusedState->assignProperty(this, "backgroundOpacity", 0.15);
|
_hoveredFocusedState->assignProperty(this, "backgroundOpacity", 0.15);
|
||||||
_hoveredFocusedState->assignProperty(this, "backgroundColor", textColor);
|
_hoveredFocusedState->assignProperty(this, "backgroundColor", textColor);
|
||||||
_normalFocusedState->assignProperty(this, "focusHaloOpacity", 0.12);
|
_normalFocusedState->assignProperty(this, "focusHaloOpacity", 0.15);
|
||||||
|
|
||||||
_pressedState->assignProperty(this, "backgroundOpacity", 0.15);
|
_pressedState->assignProperty(this, "backgroundOpacity", 0.15);
|
||||||
_pressedState->assignProperty(this, "backgroundColor", textColor);
|
_pressedState->assignProperty(this, "backgroundColor", textColor);
|
||||||
|
|
|
@ -14,7 +14,7 @@ class FlatButtonDelegate : public QStateMachine
|
||||||
Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor)
|
Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor)
|
||||||
Q_PROPERTY(qreal backgroundOpacity WRITE setBackgroundOpacity READ backgroundOpacity)
|
Q_PROPERTY(qreal backgroundOpacity WRITE setBackgroundOpacity READ backgroundOpacity)
|
||||||
Q_PROPERTY(qreal focusHaloOpacity WRITE setFocusHaloOpacity READ focusHaloOpacity)
|
Q_PROPERTY(qreal focusHaloOpacity WRITE setFocusHaloOpacity READ focusHaloOpacity)
|
||||||
Q_PROPERTY(int focusHaloSize WRITE setFocusHaloSize READ focusHaloSize)
|
Q_PROPERTY(qreal focusHaloSize WRITE setFocusHaloSize READ focusHaloSize)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FlatButtonDelegate(FlatButton *parent);
|
FlatButtonDelegate(FlatButton *parent);
|
||||||
|
@ -29,8 +29,8 @@ public:
|
||||||
void setFocusHaloOpacity(qreal opacity);
|
void setFocusHaloOpacity(qreal opacity);
|
||||||
qreal focusHaloOpacity() const;
|
qreal focusHaloOpacity() const;
|
||||||
|
|
||||||
void setFocusHaloSize(int size);
|
void setFocusHaloSize(qreal size);
|
||||||
int focusHaloSize() const;
|
qreal focusHaloSize() const;
|
||||||
|
|
||||||
void assignProperties();
|
void assignProperties();
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ private:
|
||||||
QState *const _pressedState;
|
QState *const _pressedState;
|
||||||
qreal _backgroundOpacity;
|
qreal _backgroundOpacity;
|
||||||
qreal _focusHaloOpacity;
|
qreal _focusHaloOpacity;
|
||||||
int _focusHaloSize;
|
qreal _focusHaloSize;
|
||||||
QColor _backgroundColor;
|
QColor _backgroundColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -131,21 +131,31 @@ void RaisedButton::paintEvent(QPaintEvent *event)
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
|
painter.save();
|
||||||
|
|
||||||
QBrush brush;
|
QBrush brush;
|
||||||
brush.setStyle(Qt::SolidPattern);
|
brush.setStyle(Qt::SolidPattern);
|
||||||
brush.setColor(palette().color(QPalette::Active, QPalette::Background));
|
brush.setColor(palette().color(QPalette::Active, QPalette::Background));
|
||||||
painter.setBrush(brush);
|
painter.setBrush(brush);
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
|
|
||||||
painter.drawRoundedRect(rect(), 3, 3);
|
painter.drawRoundedRect(rect(), 3, 3);
|
||||||
|
|
||||||
FlatButton::paintEvent(event);
|
const int hs = (width()/2)*d->delegate->focusHaloSize();
|
||||||
|
const qreal haloOpacity = d->delegate->focusHaloOpacity();
|
||||||
|
|
||||||
//QStylePainter style(this);
|
brush.setColor(palette().color(QPalette::Active, QPalette::ButtonText));
|
||||||
|
painter.setBrush(brush);
|
||||||
|
painter.setOpacity(haloOpacity);
|
||||||
|
painter.setPen(Qt::NoPen);
|
||||||
|
painter.drawEllipse(rect().center(), hs, hs);
|
||||||
|
|
||||||
//QStyleOptionButton option;
|
painter.restore();
|
||||||
//initStyleOption(&option);
|
|
||||||
//option.features |= QStyleOptionButton::Flat;
|
|
||||||
|
|
||||||
//style.drawControl(QStyle::CE_PushButtonLabel, option);
|
QStylePainter style(this);
|
||||||
|
|
||||||
|
QStyleOptionButton option;
|
||||||
|
initStyleOption(&option);
|
||||||
|
option.features |= QStyleOptionButton::Flat;
|
||||||
|
|
||||||
|
style.drawControl(QStyle::CE_PushButtonLabel, option);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue