tweak flat button animations
This commit is contained in:
parent
364873565c
commit
c500b3c218
|
@ -15,6 +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)),
|
||||||
|
_releaseState(new QState(this)),
|
||||||
_focusHaloSize(0.8)
|
_focusHaloSize(0.8)
|
||||||
{
|
{
|
||||||
setInitialState(_normalState);
|
setInitialState(_normalState);
|
||||||
|
@ -26,7 +27,8 @@ FlatButtonDelegate::FlatButtonDelegate(FlatButton *parent)
|
||||||
addTransition(QEvent::Leave, _hoveredFocusedState, _normalFocusedState);
|
addTransition(QEvent::Leave, _hoveredFocusedState, _normalFocusedState);
|
||||||
addTransition(QEvent::Leave, _hoveredState, _normalState);
|
addTransition(QEvent::Leave, _hoveredState, _normalState);
|
||||||
addTransition(QEvent::MouseButtonPress, _hoveredState, _pressedState);
|
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);
|
QSequentialAnimationGroup *group = new QSequentialAnimationGroup(this);
|
||||||
|
|
||||||
|
@ -105,19 +107,26 @@ qreal FlatButtonDelegate::focusHaloSize() const
|
||||||
|
|
||||||
void FlatButtonDelegate::updatePalette()
|
void FlatButtonDelegate::updatePalette()
|
||||||
{
|
{
|
||||||
QColor color;
|
QColor color, bg;
|
||||||
|
|
||||||
switch (button->role())
|
switch (button->role())
|
||||||
{
|
{
|
||||||
case Material::Primary:
|
case Material::Primary:
|
||||||
color = button->primaryTextColor();
|
color = button->primaryTextColor();
|
||||||
|
bg = button->primaryBgColor();
|
||||||
break;
|
break;
|
||||||
case Material::Secondary:
|
case Material::Secondary:
|
||||||
color = button->secondaryTextColor();
|
color = button->secondaryTextColor();
|
||||||
|
bg = button->secondaryBgColor();
|
||||||
break;
|
break;
|
||||||
case Material::Default:
|
case Material::Default:
|
||||||
default:
|
default:
|
||||||
color = button->defaultTextColor();
|
color = button->defaultTextColor();
|
||||||
|
bg = button->defaultBgColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Qt::OpaqueMode == button->bgMode()) {
|
||||||
|
color = Qt::white;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPalette palette(button->palette());
|
QPalette palette(button->palette());
|
||||||
|
@ -127,25 +136,29 @@ void FlatButtonDelegate::updatePalette()
|
||||||
button->setPalette(palette);
|
button->setPalette(palette);
|
||||||
|
|
||||||
_normalState->assignProperty(this, "backgroundOpacity", 0);
|
_normalState->assignProperty(this, "backgroundOpacity", 0);
|
||||||
_normalState->assignProperty(this, "backgroundColor", color);
|
_normalState->assignProperty(this, "backgroundColor", bg);
|
||||||
_normalState->assignProperty(this, "focusHaloOpacity", 0);
|
_normalState->assignProperty(this, "focusHaloOpacity", 0);
|
||||||
|
|
||||||
_normalFocusedState->assignProperty(this, "backgroundOpacity", 0);
|
_normalFocusedState->assignProperty(this, "backgroundOpacity", 0);
|
||||||
_normalFocusedState->assignProperty(this, "backgroundColor", color);
|
_normalFocusedState->assignProperty(this, "backgroundColor", bg);
|
||||||
_normalFocusedState->assignProperty(this, "focusHaloOpacity", button->peakOpacity());
|
_normalFocusedState->assignProperty(this, "focusHaloOpacity", button->peakOpacity());
|
||||||
|
|
||||||
_hoveredState->assignProperty(this, "backgroundOpacity", button->peakOpacity());
|
_hoveredState->assignProperty(this, "backgroundOpacity", button->peakOpacity());
|
||||||
_hoveredState->assignProperty(this, "backgroundColor", color);
|
_hoveredState->assignProperty(this, "backgroundColor", bg);
|
||||||
_hoveredState->assignProperty(this, "focusHaloOpacity", 0);
|
_hoveredState->assignProperty(this, "focusHaloOpacity", 0);
|
||||||
|
|
||||||
_hoveredFocusedState->assignProperty(this, "backgroundOpacity", button->peakOpacity());
|
_hoveredFocusedState->assignProperty(this, "backgroundOpacity", button->peakOpacity());
|
||||||
_hoveredFocusedState->assignProperty(this, "backgroundColor", color);
|
_hoveredFocusedState->assignProperty(this, "backgroundColor", bg);
|
||||||
_normalFocusedState->assignProperty(this, "focusHaloOpacity", button->peakOpacity());
|
_normalFocusedState->assignProperty(this, "focusHaloOpacity", button->peakOpacity());
|
||||||
|
|
||||||
_pressedState->assignProperty(this, "backgroundOpacity", button->peakOpacity());
|
_pressedState->assignProperty(this, "backgroundOpacity", 0);
|
||||||
_pressedState->assignProperty(this, "backgroundColor", color);
|
_pressedState->assignProperty(this, "backgroundColor", bg);
|
||||||
_pressedState->assignProperty(this, "focusHaloOpacity", 0);
|
_pressedState->assignProperty(this, "focusHaloOpacity", 0);
|
||||||
|
|
||||||
|
_releaseState->assignProperty(this, "backgroundOpacity", 0);
|
||||||
|
_releaseState->assignProperty(this, "backgroundColor", bg);
|
||||||
|
_releaseState->assignProperty(this, "focusHaloOpacity", 0);
|
||||||
|
|
||||||
button->update();
|
button->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ private:
|
||||||
QState *const _hoveredState;
|
QState *const _hoveredState;
|
||||||
QState *const _hoveredFocusedState;
|
QState *const _hoveredFocusedState;
|
||||||
QState *const _pressedState;
|
QState *const _pressedState;
|
||||||
|
QState *const _releaseState;
|
||||||
qreal _backgroundOpacity;
|
qreal _backgroundOpacity;
|
||||||
qreal _focusHaloOpacity;
|
qreal _focusHaloOpacity;
|
||||||
qreal _focusHaloSize;
|
qreal _focusHaloSize;
|
||||||
|
|
|
@ -57,9 +57,31 @@ FlatButtonExamples::FlatButtonExamples(QWidget *parent)
|
||||||
flatButton->setText("Press me!");
|
flatButton->setText("Press me!");
|
||||||
flatButton->setMinimumSize(200, 42);
|
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->setRole(Material::Primary);
|
||||||
flatButton->setBgMode(Qt::OpaqueMode);
|
flatButton->setBgMode(Qt::OpaqueMode);
|
||||||
flatButton->setPrimaryTextColor(Qt::white);
|
//flatButton->setPrimaryTextColor(Qt::white);
|
||||||
flatButton->setPeakOpacity(0.25);
|
flatButton->setPeakOpacity(0.25);
|
||||||
|
|
||||||
ExampleView *view = new ExampleView;
|
ExampleView *view = new ExampleView;
|
||||||
|
@ -82,7 +104,6 @@ FlatButtonExamples::FlatButtonExamples(QWidget *parent)
|
||||||
|
|
||||||
flatButton->setRole(Material::Secondary);
|
flatButton->setRole(Material::Secondary);
|
||||||
flatButton->setBgMode(Qt::OpaqueMode);
|
flatButton->setBgMode(Qt::OpaqueMode);
|
||||||
flatButton->setSecondaryTextColor(Qt::white);
|
|
||||||
flatButton->setPeakOpacity(0.25);
|
flatButton->setPeakOpacity(0.25);
|
||||||
|
|
||||||
ExampleView *view = new ExampleView;
|
ExampleView *view = new ExampleView;
|
||||||
|
|
Loading…
Reference in New Issue