fix weird toggle behavior

This commit is contained in:
laserpants 2016-06-05 16:28:01 +03:00
parent ead266b05a
commit 6bfbc342b0
4 changed files with 6 additions and 23 deletions

View File

@ -41,7 +41,7 @@ void TogglePrivate::init()
//
transition = new QSignalTransition(thumb, SIGNAL(clicked(bool)));
transition = new QSignalTransition(q, SIGNAL(toggled(bool)));
transition->setTargetState(onState);
offState->addTransition(transition);
@ -66,7 +66,7 @@ void TogglePrivate::init()
//
transition = new QSignalTransition(thumb, SIGNAL(clicked(bool)));
transition = new QSignalTransition(q, SIGNAL(toggled(bool)));
transition->setTargetState(offState);
onState->addTransition(transition);
@ -110,7 +110,7 @@ void TogglePrivate::init()
machine.start();
QObject::connect(thumb, SIGNAL(clicked(bool)), q, SLOT(addRipple(bool)));
QObject::connect(q, SIGNAL(toggled(bool)), q, SLOT(addRipple()));
}
Toggle::Toggle(QWidget *parent)
@ -161,7 +161,7 @@ void Toggle::updateOverlayGeometry()
}
}
void Toggle::addRipple(bool checked)
void Toggle::addRipple()
{
Q_D(Toggle);
@ -176,7 +176,7 @@ void Toggle::addRipple(bool checked)
}
Ripple *ripple = new Ripple(QPoint(10+t, 20+t));
ripple->setColor(Style::instance().themeColor(checked
ripple->setColor(Style::instance().themeColor(isChecked()
? "primary2"
: "accent3"));
ripple->setRadiusEndValue(w);

View File

@ -21,7 +21,7 @@ public:
void updateOverlayGeometry();
protected slots:
void addRipple(bool checked);
void addRipple();
protected:
bool event(QEvent *event) Q_DECL_OVERRIDE;

View File

@ -47,8 +47,6 @@ bool ToggleThumb::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::MouseButtonPress == type) {
return true;
}
return QWidget::eventFilter(obj, event);
}
@ -80,17 +78,6 @@ void ToggleThumb::paintEvent(QPaintEvent *event)
}
}
void ToggleThumb::mouseReleaseEvent(QMouseEvent *event)
{
if (_toggle->isEnabled()) {
const bool newChecked = !_toggle->isChecked();
_toggle->setChecked(newChecked);
qDebug() << "checked : " << newChecked;
emit clicked(newChecked);
}
QWidget::mouseReleaseEvent(event);
}
ToggleTrack::ToggleTrack(Toggle *parent)
: QWidget(parent),
_toggle(parent)

View File

@ -32,13 +32,9 @@ public:
return _thumbColor;
}
signals:
void clicked(bool);
protected:
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(ToggleThumb)