diff --git a/components/flatbutton.cpp b/components/flatbutton.cpp index 0724c76..36f059e 100644 --- a/components/flatbutton.cpp +++ b/components/flatbutton.cpp @@ -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; diff --git a/components/flatbutton_internal.cpp b/components/flatbutton_internal.cpp index c9a9ed4..05365a3 100644 --- a/components/flatbutton_internal.cpp +++ b/components/flatbutton_internal.cpp @@ -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); diff --git a/components/flatbutton_internal.h b/components/flatbutton_internal.h index ec74478..12cbdac 100644 --- a/components/flatbutton_internal.h +++ b/components/flatbutton_internal.h @@ -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; diff --git a/components/raisedbutton.cpp b/components/raisedbutton.cpp index b28929b..79f49a5 100644 --- a/components/raisedbutton.cpp +++ b/components/raisedbutton.cpp @@ -89,6 +89,8 @@ RaisedButton::RaisedButton(QWidget *parent) Q_D(RaisedButton); d->init(); + + setMinimumHeight(42); } RaisedButton::~RaisedButton()