mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Remove halo animation
This commit is contained in:
parent
40722b7af7
commit
193490bd9e
3 changed files with 0 additions and 140 deletions
|
@ -4,7 +4,6 @@
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QSequentialAnimationGroup>
|
|
||||||
#include <QStateMachine>
|
#include <QStateMachine>
|
||||||
|
|
||||||
#include "RippleOverlay.h"
|
#include "RippleOverlay.h"
|
||||||
|
@ -18,9 +17,6 @@ class FlatButtonStateMachine : public QStateMachine
|
||||||
|
|
||||||
Q_PROPERTY(qreal overlayOpacity WRITE setOverlayOpacity READ overlayOpacity)
|
Q_PROPERTY(qreal overlayOpacity WRITE setOverlayOpacity READ overlayOpacity)
|
||||||
Q_PROPERTY(qreal checkedOverlayProgress WRITE setCheckedOverlayProgress READ checkedOverlayProgress)
|
Q_PROPERTY(qreal checkedOverlayProgress WRITE setCheckedOverlayProgress READ checkedOverlayProgress)
|
||||||
Q_PROPERTY(qreal haloOpacity WRITE setHaloOpacity READ haloOpacity)
|
|
||||||
Q_PROPERTY(qreal haloSize WRITE setHaloSize READ haloSize)
|
|
||||||
Q_PROPERTY(qreal haloScaleFactor WRITE setHaloScaleFactor READ haloScaleFactor)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FlatButtonStateMachine(FlatButton *parent);
|
explicit FlatButtonStateMachine(FlatButton *parent);
|
||||||
|
@ -28,15 +24,9 @@ public:
|
||||||
|
|
||||||
void setOverlayOpacity(qreal opacity);
|
void setOverlayOpacity(qreal opacity);
|
||||||
void setCheckedOverlayProgress(qreal opacity);
|
void setCheckedOverlayProgress(qreal opacity);
|
||||||
void setHaloOpacity(qreal opacity);
|
|
||||||
void setHaloSize(qreal size);
|
|
||||||
void setHaloScaleFactor(qreal factor);
|
|
||||||
|
|
||||||
inline qreal overlayOpacity() const;
|
inline qreal overlayOpacity() const;
|
||||||
inline qreal checkedOverlayProgress() const;
|
inline qreal checkedOverlayProgress() const;
|
||||||
inline qreal haloOpacity() const;
|
|
||||||
inline qreal haloSize() const;
|
|
||||||
inline qreal haloScaleFactor() const;
|
|
||||||
|
|
||||||
void startAnimations();
|
void startAnimations();
|
||||||
void setupProperties();
|
void setupProperties();
|
||||||
|
@ -68,13 +58,8 @@ private:
|
||||||
QState *const hovered_focused_state_;
|
QState *const hovered_focused_state_;
|
||||||
QState *const pressed_state_;
|
QState *const pressed_state_;
|
||||||
|
|
||||||
QSequentialAnimationGroup *const halo_animation_;
|
|
||||||
|
|
||||||
qreal overlay_opacity_;
|
qreal overlay_opacity_;
|
||||||
qreal checked_overlay_progress_;
|
qreal checked_overlay_progress_;
|
||||||
qreal halo_opacity_;
|
|
||||||
qreal halo_size_;
|
|
||||||
qreal halo_scale_factor_;
|
|
||||||
|
|
||||||
bool was_checked_;
|
bool was_checked_;
|
||||||
};
|
};
|
||||||
|
@ -89,21 +74,6 @@ inline qreal FlatButtonStateMachine::checkedOverlayProgress() const
|
||||||
return checked_overlay_progress_;
|
return checked_overlay_progress_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline qreal FlatButtonStateMachine::haloOpacity() const
|
|
||||||
{
|
|
||||||
return halo_opacity_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline qreal FlatButtonStateMachine::haloSize() const
|
|
||||||
{
|
|
||||||
return halo_size_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline qreal FlatButtonStateMachine::haloScaleFactor() const
|
|
||||||
{
|
|
||||||
return halo_scale_factor_;
|
|
||||||
}
|
|
||||||
|
|
||||||
class FlatButton : public QPushButton
|
class FlatButton : public QPushButton
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -133,7 +103,6 @@ public:
|
||||||
void setFixedRippleRadius(qreal radius);
|
void setFixedRippleRadius(qreal radius);
|
||||||
void setFontSize(qreal size);
|
void setFontSize(qreal size);
|
||||||
void setForegroundColor(const QColor &color);
|
void setForegroundColor(const QColor &color);
|
||||||
void setHaloVisible(bool visible);
|
|
||||||
void setHasFixedRippleRadius(bool value);
|
void setHasFixedRippleRadius(bool value);
|
||||||
void setIconPlacement(ui::ButtonIconPlacement placement);
|
void setIconPlacement(ui::ButtonIconPlacement placement);
|
||||||
void setOverlayColor(const QColor &color);
|
void setOverlayColor(const QColor &color);
|
||||||
|
@ -151,7 +120,6 @@ public:
|
||||||
qreal cornerRadius() const;
|
qreal cornerRadius() const;
|
||||||
qreal baseOpacity() const;
|
qreal baseOpacity() const;
|
||||||
|
|
||||||
bool isHaloVisible() const;
|
|
||||||
bool hasFixedRippleRadius() const;
|
bool hasFixedRippleRadius() const;
|
||||||
|
|
||||||
ui::Role role() const;
|
ui::Role role() const;
|
||||||
|
@ -175,7 +143,6 @@ protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
virtual void paintBackground(QPainter *painter);
|
virtual void paintBackground(QPainter *painter);
|
||||||
virtual void paintHalo(QPainter *painter);
|
|
||||||
virtual void paintForeground(QPainter *painter);
|
virtual void paintForeground(QPainter *painter);
|
||||||
virtual void updateClipPath();
|
virtual void updateClipPath();
|
||||||
|
|
||||||
|
@ -204,7 +171,6 @@ private:
|
||||||
qreal font_size_;
|
qreal font_size_;
|
||||||
|
|
||||||
bool use_fixed_ripple_radius_;
|
bool use_fixed_ripple_radius_;
|
||||||
bool halo_visible_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // UI_FLAT_BUTTON_H
|
#endif // UI_FLAT_BUTTON_H
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
|
|
||||||
#include <QBitmap>
|
|
||||||
#include <QEventTransition>
|
#include <QEventTransition>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QSequentialAnimationGroup>
|
|
||||||
#include <QSignalTransition>
|
#include <QSignalTransition>
|
||||||
|
|
||||||
#include "FlatButton.h"
|
#include "FlatButton.h"
|
||||||
|
@ -29,7 +25,6 @@ void FlatButton::init()
|
||||||
base_opacity_ = 0.13;
|
base_opacity_ = 0.13;
|
||||||
font_size_ = 10; // 10.5;
|
font_size_ = 10; // 10.5;
|
||||||
use_fixed_ripple_radius_ = false;
|
use_fixed_ripple_radius_ = false;
|
||||||
halo_visible_ = false;
|
|
||||||
|
|
||||||
setStyle(&ThemeManager::instance());
|
setStyle(&ThemeManager::instance());
|
||||||
setAttribute(Qt::WA_Hover);
|
setAttribute(Qt::WA_Hover);
|
||||||
|
@ -80,7 +75,6 @@ void FlatButton::applyPreset(ui::ButtonPreset preset)
|
||||||
case ui::CheckablePreset:
|
case ui::CheckablePreset:
|
||||||
setOverlayStyle(ui::NoOverlay);
|
setOverlayStyle(ui::NoOverlay);
|
||||||
setCheckable(true);
|
setCheckable(true);
|
||||||
setHaloVisible(false);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -205,17 +199,6 @@ qreal FlatButton::fontSize() const
|
||||||
return font_size_;
|
return font_size_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatButton::setHaloVisible(bool visible)
|
|
||||||
{
|
|
||||||
halo_visible_ = visible;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FlatButton::isHaloVisible() const
|
|
||||||
{
|
|
||||||
return halo_visible_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FlatButton::setOverlayStyle(ui::OverlayStyle style)
|
void FlatButton::setOverlayStyle(ui::OverlayStyle style)
|
||||||
{
|
{
|
||||||
overlay_style_ = style;
|
overlay_style_ = style;
|
||||||
|
@ -391,7 +374,6 @@ void FlatButton::paintEvent(QPaintEvent *event)
|
||||||
}
|
}
|
||||||
|
|
||||||
paintBackground(&painter);
|
paintBackground(&painter);
|
||||||
paintHalo(&painter);
|
|
||||||
|
|
||||||
painter.setOpacity(1);
|
painter.setOpacity(1);
|
||||||
painter.setClipping(false);
|
painter.setClipping(false);
|
||||||
|
@ -451,27 +433,6 @@ void FlatButton::paintBackground(QPainter *painter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatButton::paintHalo(QPainter *painter)
|
|
||||||
{
|
|
||||||
if (!halo_visible_)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const qreal opacity = state_machine_->haloOpacity();
|
|
||||||
const qreal s = state_machine_->haloScaleFactor() * state_machine_->haloSize();
|
|
||||||
const qreal radius = static_cast<qreal>(width()) * s;
|
|
||||||
|
|
||||||
if (isEnabled() && opacity > 0) {
|
|
||||||
QBrush brush;
|
|
||||||
brush.setStyle(Qt::SolidPattern);
|
|
||||||
brush.setColor(foregroundColor());
|
|
||||||
painter->setOpacity(opacity);
|
|
||||||
painter->setBrush(brush);
|
|
||||||
painter->setPen(Qt::NoPen);
|
|
||||||
const QPointF center = rect().center();
|
|
||||||
painter->drawEllipse(center, radius, radius);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define COLOR_INTERPOLATE(CH) (1 - progress) * source.CH() + progress *dest.CH()
|
#define COLOR_INTERPOLATE(CH) (1 - progress) * source.CH() + progress *dest.CH()
|
||||||
|
|
||||||
void FlatButton::paintForeground(QPainter *painter)
|
void FlatButton::paintForeground(QPainter *painter)
|
||||||
|
@ -548,12 +509,8 @@ FlatButtonStateMachine::FlatButtonStateMachine(FlatButton *parent)
|
||||||
, hovered_state_(new QState(config_state_))
|
, hovered_state_(new QState(config_state_))
|
||||||
, hovered_focused_state_(new QState(config_state_))
|
, hovered_focused_state_(new QState(config_state_))
|
||||||
, pressed_state_(new QState(config_state_))
|
, pressed_state_(new QState(config_state_))
|
||||||
, halo_animation_(new QSequentialAnimationGroup(this))
|
|
||||||
, overlay_opacity_(0)
|
, overlay_opacity_(0)
|
||||||
, checked_overlay_progress_(parent->isChecked() ? 1 : 0)
|
, checked_overlay_progress_(parent->isChecked() ? 1 : 0)
|
||||||
, halo_opacity_(0)
|
|
||||||
, halo_size_(0.8)
|
|
||||||
, halo_scale_factor_(1)
|
|
||||||
, was_checked_(false)
|
, was_checked_(false)
|
||||||
{
|
{
|
||||||
Q_ASSERT(parent);
|
Q_ASSERT(parent);
|
||||||
|
@ -596,33 +553,6 @@ FlatButtonStateMachine::FlatButtonStateMachine(FlatButton *parent)
|
||||||
addTransition(this, SIGNAL(buttonPressed()), hovered_state_, pressed_state_);
|
addTransition(this, SIGNAL(buttonPressed()), hovered_state_, pressed_state_);
|
||||||
addTransition(button_, QEvent::Leave, pressed_state_, neutral_focused_state_);
|
addTransition(button_, QEvent::Leave, pressed_state_, neutral_focused_state_);
|
||||||
addTransition(button_, QEvent::FocusOut, pressed_state_, hovered_state_);
|
addTransition(button_, QEvent::FocusOut, pressed_state_, hovered_state_);
|
||||||
|
|
||||||
neutral_state_->assignProperty(this, "haloSize", 0);
|
|
||||||
neutral_focused_state_->assignProperty(this, "haloSize", 0.7);
|
|
||||||
hovered_state_->assignProperty(this, "haloSize", 0);
|
|
||||||
pressed_state_->assignProperty(this, "haloSize", 4);
|
|
||||||
hovered_focused_state_->assignProperty(this, "haloSize", 0.7);
|
|
||||||
|
|
||||||
QPropertyAnimation *grow = new QPropertyAnimation(this);
|
|
||||||
QPropertyAnimation *shrink = new QPropertyAnimation(this);
|
|
||||||
|
|
||||||
grow->setTargetObject(this);
|
|
||||||
grow->setPropertyName("haloScaleFactor");
|
|
||||||
grow->setStartValue(0.56);
|
|
||||||
grow->setEndValue(0.63);
|
|
||||||
grow->setEasingCurve(QEasingCurve::InOutSine);
|
|
||||||
grow->setDuration(840);
|
|
||||||
|
|
||||||
shrink->setTargetObject(this);
|
|
||||||
shrink->setPropertyName("haloScaleFactor");
|
|
||||||
shrink->setStartValue(0.63);
|
|
||||||
shrink->setEndValue(0.56);
|
|
||||||
shrink->setEasingCurve(QEasingCurve::InOutSine);
|
|
||||||
shrink->setDuration(840);
|
|
||||||
|
|
||||||
halo_animation_->addAnimation(grow);
|
|
||||||
halo_animation_->addAnimation(shrink);
|
|
||||||
halo_animation_->setLoopCount(-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FlatButtonStateMachine::~FlatButtonStateMachine()
|
FlatButtonStateMachine::~FlatButtonStateMachine()
|
||||||
|
@ -641,27 +571,8 @@ void FlatButtonStateMachine::setCheckedOverlayProgress(qreal opacity)
|
||||||
button_->update();
|
button_->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatButtonStateMachine::setHaloOpacity(qreal opacity)
|
|
||||||
{
|
|
||||||
halo_opacity_ = opacity;
|
|
||||||
button_->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FlatButtonStateMachine::setHaloSize(qreal size)
|
|
||||||
{
|
|
||||||
halo_size_ = size;
|
|
||||||
button_->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FlatButtonStateMachine::setHaloScaleFactor(qreal factor)
|
|
||||||
{
|
|
||||||
halo_scale_factor_ = factor;
|
|
||||||
button_->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FlatButtonStateMachine::startAnimations()
|
void FlatButtonStateMachine::startAnimations()
|
||||||
{
|
{
|
||||||
halo_animation_->start();
|
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,15 +589,10 @@ void FlatButtonStateMachine::setupProperties()
|
||||||
const qreal baseOpacity = button_->baseOpacity();
|
const qreal baseOpacity = button_->baseOpacity();
|
||||||
|
|
||||||
neutral_state_->assignProperty(this, "overlayOpacity", 0);
|
neutral_state_->assignProperty(this, "overlayOpacity", 0);
|
||||||
neutral_state_->assignProperty(this, "haloOpacity", 0);
|
|
||||||
neutral_focused_state_->assignProperty(this, "overlayOpacity", 0);
|
neutral_focused_state_->assignProperty(this, "overlayOpacity", 0);
|
||||||
neutral_focused_state_->assignProperty(this, "haloOpacity", baseOpacity);
|
|
||||||
hovered_state_->assignProperty(this, "overlayOpacity", baseOpacity);
|
hovered_state_->assignProperty(this, "overlayOpacity", baseOpacity);
|
||||||
hovered_state_->assignProperty(this, "haloOpacity", 0);
|
|
||||||
hovered_focused_state_->assignProperty(this, "overlayOpacity", baseOpacity);
|
hovered_focused_state_->assignProperty(this, "overlayOpacity", baseOpacity);
|
||||||
hovered_focused_state_->assignProperty(this, "haloOpacity", baseOpacity);
|
|
||||||
pressed_state_->assignProperty(this, "overlayOpacity", baseOpacity);
|
pressed_state_->assignProperty(this, "overlayOpacity", baseOpacity);
|
||||||
pressed_state_->assignProperty(this, "haloOpacity", 0);
|
|
||||||
checked_state_->assignProperty(this, "checkedOverlayProgress", 1);
|
checked_state_->assignProperty(this, "checkedOverlayProgress", 1);
|
||||||
unchecked_state_->assignProperty(this, "checkedOverlayProgress", 0);
|
unchecked_state_->assignProperty(this, "checkedOverlayProgress", 0);
|
||||||
|
|
||||||
|
@ -748,14 +654,5 @@ void FlatButtonStateMachine::addTransition(QAbstractTransition *transition,
|
||||||
animation->setDuration(150);
|
animation->setDuration(150);
|
||||||
transition->addAnimation(animation);
|
transition->addAnimation(animation);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(this, "haloOpacity", this);
|
|
||||||
animation->setDuration(170);
|
|
||||||
transition->addAnimation(animation);
|
|
||||||
|
|
||||||
animation = new QPropertyAnimation(this, "haloSize", this);
|
|
||||||
animation->setDuration(350);
|
|
||||||
animation->setEasingCurve(QEasingCurve::OutCubic);
|
|
||||||
transition->addAnimation(animation);
|
|
||||||
|
|
||||||
fromState->addTransition(transition);
|
fromState->addTransition(transition);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
#include <QEventTransition>
|
#include <QEventTransition>
|
||||||
#include <QGraphicsDropShadowEffect>
|
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QState>
|
|
||||||
#include <QStateMachine>
|
|
||||||
|
|
||||||
#include "RaisedButton.h"
|
#include "RaisedButton.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue