From a8ffb45ac0ede0624b5f0b2cdd754a7613fe0267 Mon Sep 17 00:00:00 2001 From: laserpants Date: Wed, 30 Mar 2016 23:42:31 +0300 Subject: [PATCH] fix (hopefully) weird Toggle animation behavior --- components/toggle.cpp | 26 ++++++++++---------------- components/toggle.h | 1 - 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/components/toggle.cpp b/components/toggle.cpp index e47b2e7..2b7cbbe 100644 --- a/components/toggle.cpp +++ b/components/toggle.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include "toggle.h" #include "../lib/rippleoverlay.h" @@ -47,27 +47,29 @@ bool Thumb::eventFilter(QObject *obj, QEvent *event) const QEvent::Type type = event->type(); if (QEvent::Resize == type || QEvent::Move == type) { setGeometry(parentWidget()->rect().adjusted(8, 8, -8, -8)); + } else if (QEvent::MouseButtonRelease == type) { + return true; } return QWidget::eventFilter(obj, event); } void Thumb::mouseReleaseEvent(QMouseEvent *event) { - Q_UNUSED(event) - const bool checked = _toggle->isChecked(); _toggle->setChecked(!checked); + if (QAbstractAnimation::Running != _animation->state()) { + _animation->setEasingCurve(checked + ? QEasingCurve::OutCubic + : QEasingCurve::InCubic); + } _animation->setDirection(checked ? QAbstractAnimation::Forward : QAbstractAnimation::Backward); -// if (QAbstractAnimation::Running != _animation->state()) { -// _animation->setEasingCurve(checked -// ? QEasingCurve::OutCubic -// : QEasingCurve::InCubic); -// } _animation->start(); emit clicked(); + + QWidget::mouseReleaseEvent(event); } void Thumb::paintEvent(QPaintEvent *event) @@ -110,9 +112,6 @@ Toggle::Toggle(QWidget *parent) _thumb->installEventFilter(this); connect(_thumb, SIGNAL(clicked()), this, SLOT(addRipple())); - - connect(_thumb, SIGNAL(clicked()), this, SLOT(logCheckedStatus())); - connect(_thumb, SIGNAL(progressChanged(qreal)), this, SLOT(updateOverlayGeometry())); } @@ -120,11 +119,6 @@ Toggle::~Toggle() { } -void Toggle::logCheckedStatus() -{ - qDebug() << "checked : " << isChecked(); -} - QSize Toggle::sizeHint() const { return Qt::Horizontal == _orientation diff --git a/components/toggle.h b/components/toggle.h index dd5d319..b06d84b 100644 --- a/components/toggle.h +++ b/components/toggle.h @@ -55,7 +55,6 @@ public: protected slots: void addRipple(); void updateOverlayGeometry(); - void logCheckedStatus(); protected: bool event(QEvent *event) Q_DECL_OVERRIDE;