From 193490bd9e977729b832979804b9b46d3ead11c8 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Tue, 11 Apr 2017 18:45:01 +0300 Subject: [PATCH] Remove halo animation --- include/ui/FlatButton.h | 34 ------------- src/ui/FlatButton.cc | 103 ---------------------------------------- src/ui/RaisedButton.cc | 3 -- 3 files changed, 140 deletions(-) diff --git a/include/ui/FlatButton.h b/include/ui/FlatButton.h index 047890c7..be7ce09c 100644 --- a/include/ui/FlatButton.h +++ b/include/ui/FlatButton.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include "RippleOverlay.h" @@ -18,9 +17,6 @@ class FlatButtonStateMachine : public QStateMachine Q_PROPERTY(qreal overlayOpacity WRITE setOverlayOpacity READ overlayOpacity) 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: explicit FlatButtonStateMachine(FlatButton *parent); @@ -28,15 +24,9 @@ public: void setOverlayOpacity(qreal opacity); void setCheckedOverlayProgress(qreal opacity); - void setHaloOpacity(qreal opacity); - void setHaloSize(qreal size); - void setHaloScaleFactor(qreal factor); inline qreal overlayOpacity() const; inline qreal checkedOverlayProgress() const; - inline qreal haloOpacity() const; - inline qreal haloSize() const; - inline qreal haloScaleFactor() const; void startAnimations(); void setupProperties(); @@ -68,13 +58,8 @@ private: QState *const hovered_focused_state_; QState *const pressed_state_; - QSequentialAnimationGroup *const halo_animation_; - qreal overlay_opacity_; qreal checked_overlay_progress_; - qreal halo_opacity_; - qreal halo_size_; - qreal halo_scale_factor_; bool was_checked_; }; @@ -89,21 +74,6 @@ inline qreal FlatButtonStateMachine::checkedOverlayProgress() const 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 { Q_OBJECT @@ -133,7 +103,6 @@ public: void setFixedRippleRadius(qreal radius); void setFontSize(qreal size); void setForegroundColor(const QColor &color); - void setHaloVisible(bool visible); void setHasFixedRippleRadius(bool value); void setIconPlacement(ui::ButtonIconPlacement placement); void setOverlayColor(const QColor &color); @@ -151,7 +120,6 @@ public: qreal cornerRadius() const; qreal baseOpacity() const; - bool isHaloVisible() const; bool hasFixedRippleRadius() const; ui::Role role() const; @@ -175,7 +143,6 @@ protected: void paintEvent(QPaintEvent *event) override; virtual void paintBackground(QPainter *painter); - virtual void paintHalo(QPainter *painter); virtual void paintForeground(QPainter *painter); virtual void updateClipPath(); @@ -204,7 +171,6 @@ private: qreal font_size_; bool use_fixed_ripple_radius_; - bool halo_visible_; }; #endif // UI_FLAT_BUTTON_H diff --git a/src/ui/FlatButton.cc b/src/ui/FlatButton.cc index 97711de5..0a4aaa32 100644 --- a/src/ui/FlatButton.cc +++ b/src/ui/FlatButton.cc @@ -1,13 +1,9 @@ - -#include #include #include #include #include -#include #include #include -#include #include #include "FlatButton.h" @@ -29,7 +25,6 @@ void FlatButton::init() base_opacity_ = 0.13; font_size_ = 10; // 10.5; use_fixed_ripple_radius_ = false; - halo_visible_ = false; setStyle(&ThemeManager::instance()); setAttribute(Qt::WA_Hover); @@ -80,7 +75,6 @@ void FlatButton::applyPreset(ui::ButtonPreset preset) case ui::CheckablePreset: setOverlayStyle(ui::NoOverlay); setCheckable(true); - setHaloVisible(false); break; default: break; @@ -205,17 +199,6 @@ qreal FlatButton::fontSize() const 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) { overlay_style_ = style; @@ -391,7 +374,6 @@ void FlatButton::paintEvent(QPaintEvent *event) } paintBackground(&painter); - paintHalo(&painter); painter.setOpacity(1); 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(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() void FlatButton::paintForeground(QPainter *painter) @@ -548,12 +509,8 @@ FlatButtonStateMachine::FlatButtonStateMachine(FlatButton *parent) , hovered_state_(new QState(config_state_)) , hovered_focused_state_(new QState(config_state_)) , pressed_state_(new QState(config_state_)) - , halo_animation_(new QSequentialAnimationGroup(this)) , overlay_opacity_(0) , checked_overlay_progress_(parent->isChecked() ? 1 : 0) - , halo_opacity_(0) - , halo_size_(0.8) - , halo_scale_factor_(1) , was_checked_(false) { Q_ASSERT(parent); @@ -596,33 +553,6 @@ FlatButtonStateMachine::FlatButtonStateMachine(FlatButton *parent) addTransition(this, SIGNAL(buttonPressed()), hovered_state_, pressed_state_); addTransition(button_, QEvent::Leave, pressed_state_, neutral_focused_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() @@ -641,27 +571,8 @@ void FlatButtonStateMachine::setCheckedOverlayProgress(qreal opacity) 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() { - halo_animation_->start(); start(); } @@ -678,15 +589,10 @@ void FlatButtonStateMachine::setupProperties() const qreal baseOpacity = button_->baseOpacity(); neutral_state_->assignProperty(this, "overlayOpacity", 0); - neutral_state_->assignProperty(this, "haloOpacity", 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, "haloOpacity", 0); hovered_focused_state_->assignProperty(this, "overlayOpacity", baseOpacity); - hovered_focused_state_->assignProperty(this, "haloOpacity", baseOpacity); pressed_state_->assignProperty(this, "overlayOpacity", baseOpacity); - pressed_state_->assignProperty(this, "haloOpacity", 0); checked_state_->assignProperty(this, "checkedOverlayProgress", 1); unchecked_state_->assignProperty(this, "checkedOverlayProgress", 0); @@ -748,14 +654,5 @@ void FlatButtonStateMachine::addTransition(QAbstractTransition *transition, animation->setDuration(150); 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); } diff --git a/src/ui/RaisedButton.cc b/src/ui/RaisedButton.cc index 74f549c4..52d74db6 100644 --- a/src/ui/RaisedButton.cc +++ b/src/ui/RaisedButton.cc @@ -1,8 +1,5 @@ #include -#include #include -#include -#include #include "RaisedButton.h"