fix (hopefully) weird Toggle animation behavior
This commit is contained in:
parent
414b799bc1
commit
a8ffb45ac0
|
@ -2,7 +2,7 @@
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QDebug>
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include "toggle.h"
|
#include "toggle.h"
|
||||||
#include "../lib/rippleoverlay.h"
|
#include "../lib/rippleoverlay.h"
|
||||||
|
@ -47,27 +47,29 @@ bool Thumb::eventFilter(QObject *obj, QEvent *event)
|
||||||
const QEvent::Type type = event->type();
|
const QEvent::Type type = event->type();
|
||||||
if (QEvent::Resize == type || QEvent::Move == type) {
|
if (QEvent::Resize == type || QEvent::Move == type) {
|
||||||
setGeometry(parentWidget()->rect().adjusted(8, 8, -8, -8));
|
setGeometry(parentWidget()->rect().adjusted(8, 8, -8, -8));
|
||||||
|
} else if (QEvent::MouseButtonRelease == type) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return QWidget::eventFilter(obj, event);
|
return QWidget::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thumb::mouseReleaseEvent(QMouseEvent *event)
|
void Thumb::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
|
||||||
|
|
||||||
const bool checked = _toggle->isChecked();
|
const bool checked = _toggle->isChecked();
|
||||||
_toggle->setChecked(!checked);
|
_toggle->setChecked(!checked);
|
||||||
|
if (QAbstractAnimation::Running != _animation->state()) {
|
||||||
|
_animation->setEasingCurve(checked
|
||||||
|
? QEasingCurve::OutCubic
|
||||||
|
: QEasingCurve::InCubic);
|
||||||
|
}
|
||||||
_animation->setDirection(checked
|
_animation->setDirection(checked
|
||||||
? QAbstractAnimation::Forward
|
? QAbstractAnimation::Forward
|
||||||
: QAbstractAnimation::Backward);
|
: QAbstractAnimation::Backward);
|
||||||
// if (QAbstractAnimation::Running != _animation->state()) {
|
|
||||||
// _animation->setEasingCurve(checked
|
|
||||||
// ? QEasingCurve::OutCubic
|
|
||||||
// : QEasingCurve::InCubic);
|
|
||||||
// }
|
|
||||||
_animation->start();
|
_animation->start();
|
||||||
|
|
||||||
emit clicked();
|
emit clicked();
|
||||||
|
|
||||||
|
QWidget::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thumb::paintEvent(QPaintEvent *event)
|
void Thumb::paintEvent(QPaintEvent *event)
|
||||||
|
@ -110,9 +112,6 @@ Toggle::Toggle(QWidget *parent)
|
||||||
_thumb->installEventFilter(this);
|
_thumb->installEventFilter(this);
|
||||||
|
|
||||||
connect(_thumb, SIGNAL(clicked()), this, SLOT(addRipple()));
|
connect(_thumb, SIGNAL(clicked()), this, SLOT(addRipple()));
|
||||||
|
|
||||||
connect(_thumb, SIGNAL(clicked()), this, SLOT(logCheckedStatus()));
|
|
||||||
|
|
||||||
connect(_thumb, SIGNAL(progressChanged(qreal)), this, SLOT(updateOverlayGeometry()));
|
connect(_thumb, SIGNAL(progressChanged(qreal)), this, SLOT(updateOverlayGeometry()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,11 +119,6 @@ Toggle::~Toggle()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Toggle::logCheckedStatus()
|
|
||||||
{
|
|
||||||
qDebug() << "checked : " << isChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize Toggle::sizeHint() const
|
QSize Toggle::sizeHint() const
|
||||||
{
|
{
|
||||||
return Qt::Horizontal == _orientation
|
return Qt::Horizontal == _orientation
|
||||||
|
|
|
@ -55,7 +55,6 @@ public:
|
||||||
protected slots:
|
protected slots:
|
||||||
void addRipple();
|
void addRipple();
|
||||||
void updateOverlayGeometry();
|
void updateOverlayGeometry();
|
||||||
void logCheckedStatus();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent *event) Q_DECL_OVERRIDE;
|
bool event(QEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
Loading…
Reference in New Issue