diff --git a/components/flatbutton_internal.cpp b/components/flatbutton_internal.cpp index db30f11..80682bd 100644 --- a/components/flatbutton_internal.cpp +++ b/components/flatbutton_internal.cpp @@ -15,6 +15,7 @@ FlatButtonDelegate::FlatButtonDelegate(FlatButton *parent) _hoveredState(new QState(this)), _hoveredFocusedState(new QState(this)), _pressedState(new QState(this)), + _releaseState(new QState(this)), _focusHaloSize(0.8) { setInitialState(_normalState); @@ -26,7 +27,8 @@ FlatButtonDelegate::FlatButtonDelegate(FlatButton *parent) addTransition(QEvent::Leave, _hoveredFocusedState, _normalFocusedState); addTransition(QEvent::Leave, _hoveredState, _normalState); addTransition(QEvent::MouseButtonPress, _hoveredState, _pressedState); - addTransition(QEvent::MouseButtonRelease, _pressedState, _hoveredFocusedState); + addTransition(QEvent::MouseButtonRelease, _pressedState, _releaseState); + addTransition(QEvent::Leave, _releaseState, _normalFocusedState); QSequentialAnimationGroup *group = new QSequentialAnimationGroup(this); @@ -105,19 +107,26 @@ qreal FlatButtonDelegate::focusHaloSize() const void FlatButtonDelegate::updatePalette() { - QColor color; + QColor color, bg; switch (button->role()) { case Material::Primary: color = button->primaryTextColor(); + bg = button->primaryBgColor(); break; case Material::Secondary: color = button->secondaryTextColor(); + bg = button->secondaryBgColor(); break; case Material::Default: default: color = button->defaultTextColor(); + bg = button->defaultBgColor(); + } + + if (Qt::OpaqueMode == button->bgMode()) { + color = Qt::white; } QPalette palette(button->palette()); @@ -127,25 +136,29 @@ void FlatButtonDelegate::updatePalette() button->setPalette(palette); _normalState->assignProperty(this, "backgroundOpacity", 0); - _normalState->assignProperty(this, "backgroundColor", color); + _normalState->assignProperty(this, "backgroundColor", bg); _normalState->assignProperty(this, "focusHaloOpacity", 0); _normalFocusedState->assignProperty(this, "backgroundOpacity", 0); - _normalFocusedState->assignProperty(this, "backgroundColor", color); + _normalFocusedState->assignProperty(this, "backgroundColor", bg); _normalFocusedState->assignProperty(this, "focusHaloOpacity", button->peakOpacity()); _hoveredState->assignProperty(this, "backgroundOpacity", button->peakOpacity()); - _hoveredState->assignProperty(this, "backgroundColor", color); + _hoveredState->assignProperty(this, "backgroundColor", bg); _hoveredState->assignProperty(this, "focusHaloOpacity", 0); _hoveredFocusedState->assignProperty(this, "backgroundOpacity", button->peakOpacity()); - _hoveredFocusedState->assignProperty(this, "backgroundColor", color); + _hoveredFocusedState->assignProperty(this, "backgroundColor", bg); _normalFocusedState->assignProperty(this, "focusHaloOpacity", button->peakOpacity()); - _pressedState->assignProperty(this, "backgroundOpacity", button->peakOpacity()); - _pressedState->assignProperty(this, "backgroundColor", color); + _pressedState->assignProperty(this, "backgroundOpacity", 0); + _pressedState->assignProperty(this, "backgroundColor", bg); _pressedState->assignProperty(this, "focusHaloOpacity", 0); + _releaseState->assignProperty(this, "backgroundOpacity", 0); + _releaseState->assignProperty(this, "backgroundColor", bg); + _releaseState->assignProperty(this, "focusHaloOpacity", 0); + button->update(); } diff --git a/components/flatbutton_internal.h b/components/flatbutton_internal.h index db26228..5e60b90 100644 --- a/components/flatbutton_internal.h +++ b/components/flatbutton_internal.h @@ -45,6 +45,7 @@ private: QState *const _hoveredState; QState *const _hoveredFocusedState; QState *const _pressedState; + QState *const _releaseState; qreal _backgroundOpacity; qreal _focusHaloOpacity; qreal _focusHaloSize; diff --git a/examples/flatbuttonexamples.cpp b/examples/flatbuttonexamples.cpp index 89db6ca..8b2fce9 100644 --- a/examples/flatbuttonexamples.cpp +++ b/examples/flatbuttonexamples.cpp @@ -57,9 +57,31 @@ FlatButtonExamples::FlatButtonExamples(QWidget *parent) flatButton->setText("Press me!"); flatButton->setMinimumSize(200, 42); + flatButton->setRole(Material::Secondary); + flatButton->setSecondaryBgColor(QColor(0, 0, 0, 80)); +// flatButton->setDisabled(true); + + ExampleView *view = new ExampleView; + view->setWidget(flatButton); + view->setBackgroundRole(QPalette::Base); + + Frame *frame = new Frame; + frame->setCodeSnippet( + "FlatButton *flatButton = new FlatButton;\n" + "flatButton->setText(\"Press me!\");" + ); + frame->setWidget(view); + + layout->addWidget(frame); + } + { + FlatButton *flatButton = new FlatButton; + flatButton->setText("Press me!"); + flatButton->setMinimumSize(200, 42); + flatButton->setRole(Material::Primary); flatButton->setBgMode(Qt::OpaqueMode); - flatButton->setPrimaryTextColor(Qt::white); + //flatButton->setPrimaryTextColor(Qt::white); flatButton->setPeakOpacity(0.25); ExampleView *view = new ExampleView; @@ -82,7 +104,6 @@ FlatButtonExamples::FlatButtonExamples(QWidget *parent) flatButton->setRole(Material::Secondary); flatButton->setBgMode(Qt::OpaqueMode); - flatButton->setSecondaryTextColor(Qt::white); flatButton->setPeakOpacity(0.25); ExampleView *view = new ExampleView;