experiment with focus animation
This commit is contained in:
parent
37b4c3c531
commit
a9d0d1cc1e
|
@ -134,6 +134,13 @@ void FlatButton::paintEvent(QPaintEvent *event)
|
|||
|
||||
painter.drawControl(QStyle::CE_PushButtonLabel, option);
|
||||
|
||||
//if (hasFocus() && !underMouse()) {
|
||||
// QPen pen;
|
||||
// pen.setWidth(4);
|
||||
// painter.setPen(pen);
|
||||
// painter.drawRect(rect());
|
||||
//}
|
||||
|
||||
#ifdef DEBUG_LAYOUT
|
||||
QPainter debug(this);
|
||||
QPen pen;
|
||||
|
|
|
@ -10,7 +10,8 @@ FlatButtonDelegate::FlatButtonDelegate(FlatButton *parent)
|
|||
: QStateMachine(parent),
|
||||
button(parent),
|
||||
_normalState(new QState(this)),
|
||||
_focusedState(new QState(this)),
|
||||
_hoveredState(new QState(this)),
|
||||
_focusedState2(new QState(this)),
|
||||
_pressedState(new QState(this))
|
||||
{
|
||||
setInitialState(_normalState);
|
||||
|
@ -23,7 +24,7 @@ FlatButtonDelegate::FlatButtonDelegate(FlatButton *parent)
|
|||
//
|
||||
|
||||
transition = new QEventTransition(button, QEvent::Enter);
|
||||
transition->setTargetState(_focusedState);
|
||||
transition->setTargetState(_hoveredState);
|
||||
|
||||
animation = new QPropertyAnimation(this, "backgroundOpacity");
|
||||
animation->setDuration(140);
|
||||
|
@ -32,13 +33,33 @@ FlatButtonDelegate::FlatButtonDelegate(FlatButton *parent)
|
|||
|
||||
//
|
||||
|
||||
//transition = new QEventTransition(button, QEvent::FocusIn);
|
||||
//transition->setTargetState(_focusedState2);
|
||||
|
||||
////animation = new QPropertyAnimation(this, "backgroundOpacity");
|
||||
////animation->setDuration(140);
|
||||
////transition->addAnimation(animation);
|
||||
//_normalState->addTransition(transition);
|
||||
|
||||
//
|
||||
|
||||
transition = new QEventTransition(button, QEvent::Leave);
|
||||
transition->setTargetState(_normalState);
|
||||
|
||||
animation = new QPropertyAnimation(this, "backgroundOpacity");
|
||||
animation->setDuration(140);
|
||||
transition->addAnimation(animation);
|
||||
_focusedState->addTransition(transition);
|
||||
_focusedState2->addTransition(transition);
|
||||
|
||||
//
|
||||
|
||||
transition = new QEventTransition(button, QEvent::Leave);
|
||||
transition->setTargetState(_normalState);
|
||||
|
||||
animation = new QPropertyAnimation(this, "backgroundOpacity");
|
||||
animation->setDuration(140);
|
||||
transition->addAnimation(animation);
|
||||
_hoveredState->addTransition(transition);
|
||||
|
||||
//
|
||||
|
||||
|
@ -48,12 +69,12 @@ FlatButtonDelegate::FlatButtonDelegate(FlatButton *parent)
|
|||
animation = new QPropertyAnimation(this, "backgroundOpacity");
|
||||
animation->setDuration(140);
|
||||
transition->addAnimation(animation);
|
||||
_focusedState->addTransition(transition);
|
||||
_hoveredState->addTransition(transition);
|
||||
|
||||
//
|
||||
|
||||
transition = new QEventTransition(button, QEvent::MouseButtonRelease);
|
||||
transition->setTargetState(_focusedState);
|
||||
transition->setTargetState(_focusedState2);
|
||||
|
||||
animation = new QPropertyAnimation(this, "backgroundOpacity");
|
||||
animation->setDuration(500);
|
||||
|
@ -99,8 +120,11 @@ void FlatButtonDelegate::assignProperties()
|
|||
_normalState->assignProperty(this, "backgroundOpacity", 0);
|
||||
_normalState->assignProperty(this, "backgroundColor", textColor);
|
||||
|
||||
_focusedState->assignProperty(this, "backgroundOpacity", 0.15);
|
||||
_focusedState->assignProperty(this, "backgroundColor", textColor);
|
||||
_hoveredState->assignProperty(this, "backgroundOpacity", 0.15);
|
||||
_hoveredState->assignProperty(this, "backgroundColor", textColor);
|
||||
|
||||
_focusedState2->assignProperty(this, "backgroundOpacity", 0.15);
|
||||
_focusedState2->assignProperty(this, "backgroundColor", textColor);
|
||||
|
||||
_pressedState->assignProperty(this, "backgroundOpacity", 0.15);
|
||||
_pressedState->assignProperty(this, "backgroundColor", textColor);
|
||||
|
|
|
@ -30,7 +30,8 @@ private:
|
|||
|
||||
FlatButton *const button;
|
||||
QState *const _normalState;
|
||||
QState *const _focusedState;
|
||||
QState *const _hoveredState;
|
||||
QState *const _focusedState2;
|
||||
QState *const _pressedState;
|
||||
qreal _backgroundOpacity;
|
||||
QColor _backgroundColor;
|
||||
|
|
|
@ -89,6 +89,8 @@ RaisedButton::RaisedButton(QWidget *parent)
|
|||
Q_D(RaisedButton);
|
||||
|
||||
d->init();
|
||||
|
||||
setMinimumHeight(42);
|
||||
}
|
||||
|
||||
RaisedButton::~RaisedButton()
|
||||
|
|
Loading…
Reference in New Issue