aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-04-15 22:25:51 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-04-15 20:29:43 +0000
commitfda12ac53971f4e7b267a08a69d11031614c8ed4 (patch)
treeeb8ba38702b5c6b0530e9f70467ecde0114a72aa
parent2f5e385effd0c12ab085e13d5a6e27cf5f7bee37 (diff)
Add missing QQuickButton::pressed() & released() signals
Change-Id: I5942457258e1c666a0d67dbc5a9a5611d4ed5967 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
-rw-r--r--src/controls/qquickbutton.cpp28
-rw-r--r--src/controls/qquickbutton_p.h2
-rw-r--r--tests/auto/controls/data/tst_button.qml58
3 files changed, 70 insertions, 18 deletions
diff --git a/src/controls/qquickbutton.cpp b/src/controls/qquickbutton.cpp
index 805af923..64d7057e 100644
--- a/src/controls/qquickbutton.cpp
+++ b/src/controls/qquickbutton.cpp
@@ -50,6 +50,24 @@ QT_BEGIN_NAMESPACE
TODO
*/
+/*!
+ \qmlsignal QtQuickControls2::Button::pressed()
+
+ TODO
+*/
+
+/*!
+ \qmlsignal QtQuickControls2::Button::released()
+
+ TODO
+*/
+
+/*!
+ \qmlsignal QtQuickControls2::Button::clicked()
+
+ TODO
+*/
+
QQuickButtonPrivate::QQuickButtonPrivate() :
pressed(false), label(Q_NULLPTR)
{
@@ -100,12 +118,16 @@ bool QQuickButton::isPressed() const
return d->pressed;
}
-void QQuickButton::setPressed(bool pressed)
+void QQuickButton::setPressed(bool isPressed)
{
Q_D(QQuickButton);
- if (d->pressed != pressed) {
- d->pressed = pressed;
+ if (d->pressed != isPressed) {
+ d->pressed = isPressed;
emit pressedChanged();
+ if (isPressed)
+ emit pressed();
+ else
+ emit released();
}
}
diff --git a/src/controls/qquickbutton_p.h b/src/controls/qquickbutton_p.h
index 4b30b4d3..ecd4b3d4 100644
--- a/src/controls/qquickbutton_p.h
+++ b/src/controls/qquickbutton_p.h
@@ -74,6 +74,8 @@ public:
void setLabel(QQuickItem *label);
Q_SIGNALS:
+ void pressed();
+ void released();
void clicked();
void textChanged();
void pressedChanged();
diff --git a/tests/auto/controls/data/tst_button.qml b/tests/auto/controls/data/tst_button.qml
index a3d5d35b..c721518d 100644
--- a/tests/auto/controls/data/tst_button.qml
+++ b/tests/auto/controls/data/tst_button.qml
@@ -51,11 +51,16 @@ TestCase {
name: "Button"
SignalSpy {
- id: pressedSpy
+ id: pressedChangedSpy
signalName: "pressedChanged"
}
SignalSpy {
+ id: releasedSpy
+ signalName: "released"
+ }
+
+ SignalSpy {
id: clickedSpy
signalName: "clicked"
}
@@ -66,16 +71,20 @@ TestCase {
}
function init() {
- verify(!pressedSpy.target)
+ verify(!pressedChangedSpy.target)
+ verify(!releasedSpy.target)
verify(!clickedSpy.target)
- compare(pressedSpy.count, 0)
+ compare(pressedChangedSpy.count, 0)
+ compare(releasedSpy.count, 0)
compare(clickedSpy.count, 0)
}
function cleanup() {
- pressedSpy.target = null
+ pressedChangedSpy.target = null
+ releasedSpy.target = null
clickedSpy.target = null
- pressedSpy.clear()
+ pressedChangedSpy.clear()
+ releasedSpy.clear()
clickedSpy.clear()
}
@@ -101,47 +110,66 @@ TestCase {
function test_mouse() {
var control = button.createObject(testCase)
- pressedSpy.target = control
+ pressedChangedSpy.target = control
+ releasedSpy.target = control
clickedSpy.target = control
- verify(pressedSpy.valid)
+ verify(pressedChangedSpy.valid)
+ verify(releasedSpy.valid)
verify(clickedSpy.valid)
// check
mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton)
- compare(pressedSpy.count, 1)
+ compare(pressedChangedSpy.count, 1)
+ compare(releasedSpy.count, 0)
+ compare(clickedSpy.count, 0)
compare(control.pressed, true)
+
mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton)
+ compare(pressedChangedSpy.count, 2)
+ compare(releasedSpy.count, 1)
compare(clickedSpy.count, 1)
- compare(pressedSpy.count, 2)
compare(control.pressed, false)
// uncheck
mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton)
- compare(pressedSpy.count, 3)
+ compare(pressedChangedSpy.count, 3)
+ compare(releasedSpy.count, 1)
+ compare(clickedSpy.count, 1)
compare(control.pressed, true)
+
mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton)
+ compare(pressedChangedSpy.count, 4)
+ compare(releasedSpy.count, 2)
compare(clickedSpy.count, 2)
- compare(pressedSpy.count, 4)
compare(control.pressed, false)
// release outside
mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton)
- compare(pressedSpy.count, 5)
+ compare(pressedChangedSpy.count, 5)
+ compare(releasedSpy.count, 2)
+ compare(clickedSpy.count, 2)
compare(control.pressed, true)
+
mouseMove(control, control.width * 2, control.height * 2, 0, Qt.LeftButton)
compare(control.pressed, false)
+
mouseRelease(control, control.width * 2, control.height * 2, Qt.LeftButton)
+ compare(pressedChangedSpy.count, 6)
+ compare(releasedSpy.count, 3)
compare(clickedSpy.count, 2)
- compare(pressedSpy.count, 6)
compare(control.pressed, false)
// right button
mousePress(control, control.width / 2, control.height / 2, Qt.RightButton)
- compare(pressedSpy.count, 6)
+ compare(pressedChangedSpy.count, 6)
+ compare(releasedSpy.count, 3)
+ compare(clickedSpy.count, 2)
compare(control.pressed, false)
+
mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton)
+ compare(pressedChangedSpy.count, 6)
+ compare(releasedSpy.count, 3)
compare(clickedSpy.count, 2)
- compare(pressedSpy.count, 6)
compare(control.pressed, false)
control.destroy()