aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-11-29 12:29:13 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2016-11-29 15:19:39 +0000
commit948932c9c6ae535647e69962aad2add516802b9c (patch)
tree4e33edad68ee62a41943c58dcea61969cedb0dda
parent3f2cb85ac10b000a33781e5fa61b607f7effde07 (diff)
Add Dial::moved() signal
[ChangeLog][Controls][Dial] Added a moved() signal that is emitted whenever the dial is interactively moved by the user by using either touch, mouse, or keys. Task-number: QTBUG-57203 Change-Id: I4b4224309f11bdcafd5c7b88414d80ebe2616238 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quicktemplates2/qquickdial.cpp17
-rw-r--r--src/quicktemplates2/qquickdial_p.h1
-rw-r--r--tests/auto/controls/data/tst_dial.qml42
3 files changed, 55 insertions, 5 deletions
diff --git a/src/quicktemplates2/qquickdial.cpp b/src/quicktemplates2/qquickdial.cpp
index 9475cff7..2932f4ce 100644
--- a/src/quicktemplates2/qquickdial.cpp
+++ b/src/quicktemplates2/qquickdial.cpp
@@ -77,6 +77,14 @@ QT_BEGIN_NAMESPACE
\sa {Customizing Dial}, {Input Controls}
*/
+/*!
+ \since QtQuick.Controls 2.2
+ \qmlsignal QtQuick.Controls::Dial::moved()
+
+ This signal is emitted when the dial has been interactively moved
+ by the user by using either touch, mouse, or keys.
+*/
+
static const qreal startAngleRadians = (M_PI * 2.0) * (4.0 / 6.0);
static const qreal startAngle = -140;
static const qreal endAngleRadians = (M_PI * 2.0) * (5.0 / 6.0);
@@ -535,6 +543,7 @@ void QQuickDial::setHandle(QQuickItem *handle)
void QQuickDial::keyPressEvent(QKeyEvent *event)
{
Q_D(QQuickDial);
+ const qreal oldValue = d->value;
switch (event->key()) {
case Qt::Key_Left:
case Qt::Key_Down:
@@ -569,6 +578,8 @@ void QQuickDial::keyPressEvent(QKeyEvent *event)
QQuickControl::keyPressEvent(event);
break;
}
+ if (!qFuzzyCompare(d->value, oldValue))
+ emit moved();
}
void QQuickDial::keyReleaseEvent(QKeyEvent *event)
@@ -599,6 +610,7 @@ void QQuickDial::mouseMoveEvent(QMouseEvent *event)
}
}
if (keepMouseGrab()) {
+ const qreal oldPos = d->position;
qreal pos = d->positionAt(event->pos());
if (d->snapMode == SnapAlways)
pos = d->snapPosition(pos);
@@ -608,6 +620,8 @@ void QQuickDial::mouseMoveEvent(QMouseEvent *event)
setValue(d->valueAt(pos));
else
d->setPosition(pos);
+ if (!qFuzzyCompare(pos, oldPos))
+ emit moved();
}
}
}
@@ -618,12 +632,15 @@ void QQuickDial::mouseReleaseEvent(QMouseEvent *event)
QQuickControl::mouseReleaseEvent(event);
if (keepMouseGrab()) {
+ const qreal oldPos = d->position;
qreal pos = d->positionAt(event->pos());
if (d->snapMode != NoSnap)
pos = d->snapPosition(pos);
if (d->wrap || (!d->wrap && !d->isLargeChange(event->pos(), pos)))
setValue(d->valueAt(pos));
+ if (!qFuzzyCompare(pos, oldPos))
+ emit moved();
setKeepMouseGrab(false);
}
diff --git a/src/quicktemplates2/qquickdial_p.h b/src/quicktemplates2/qquickdial_p.h
index 17a44b7a..cd45ad0e 100644
--- a/src/quicktemplates2/qquickdial_p.h
+++ b/src/quicktemplates2/qquickdial_p.h
@@ -129,6 +129,7 @@ Q_SIGNALS:
void pressedChanged();
Q_REVISION(2) void liveChanged();
void handleChanged();
+ Q_REVISION(2) void moved();
protected:
void keyPressEvent(QKeyEvent *event) override;
diff --git a/tests/auto/controls/data/tst_dial.qml b/tests/auto/controls/data/tst_dial.qml
index 6dd65593..06037523 100644
--- a/tests/auto/controls/data/tst_dial.qml
+++ b/tests/auto/controls/data/tst_dial.qml
@@ -55,6 +55,11 @@ TestCase {
Dial {}
}
+ Component {
+ id: signalSpy
+ SignalSpy {}
+ }
+
property var dial: null
function init() {
@@ -189,6 +194,9 @@ TestCase {
valueSpy.target = dial;
verify(valueSpy.valid);
+ var moveSpy = signalSpy.createObject(testCase, {target: dial, signalName: "moved"});
+ verify(moveSpy.valid);
+
var minimumExpectedValueCount = data.live ? 2 : 1;
// drag to the left
@@ -196,24 +204,32 @@ TestCase {
fuzzyCompare(dial.value, data.leftValue, 0.1);
verify(valueSpy.count >= minimumExpectedValueCount);
valueSpy.clear();
+ verify(moveSpy.count > 0);
+ moveSpy.clear();
// drag to the top
mouseDrag(dial, dial.width / 2, dial.height / 2, 0, -dial.height / 2, Qt.LeftButton);
fuzzyCompare(dial.value, data.topValue, 0.1);
verify(valueSpy.count >= minimumExpectedValueCount);
valueSpy.clear();
+ verify(moveSpy.count > 0);
+ moveSpy.clear();
// drag to the right
mouseDrag(dial, dial.width / 2, dial.height / 2, dial.width / 2, 0, Qt.LeftButton);
fuzzyCompare(dial.value, data.rightValue, 0.1);
verify(valueSpy.count >= minimumExpectedValueCount);
valueSpy.clear();
+ verify(moveSpy.count > 0);
+ moveSpy.clear();
// drag to the bottom (* 0.6 to ensure we don't go over to the minimum position)
mouseDrag(dial, dial.width / 2, dial.height / 2, 10, dial.height / 2, Qt.LeftButton);
fuzzyCompare(dial.value, data.bottomValue, 0.1);
verify(valueSpy.count >= minimumExpectedValueCount);
valueSpy.clear();
+ verify(moveSpy.count > 0);
+ moveSpy.clear();
}
function test_nonWrapping() {
@@ -271,10 +287,15 @@ TestCase {
var focusScope = focusTest.createObject(testCase);
verify(focusScope);
+ var moveCount = 0;
+
// Tests that we've accepted events that we're interested in.
parentEventSpy.target = focusScope;
parentEventSpy.signalName = "receivedKeyPress";
+ var moveSpy = signalSpy.createObject(testCase, {target: dial, signalName: "moved"});
+ verify(moveSpy.valid);
+
dial.parent = focusScope;
compare(dial.activeFocusOnTab, true);
compare(dial.value, 0);
@@ -285,44 +306,55 @@ TestCase {
keyClick(Qt.Key_Left);
compare(parentEventSpy.count, 0);
+ compare(moveSpy.count, moveCount);
compare(dial.value, 0);
-
+ var oldValue = 0.0;
var keyPairs = [[Qt.Key_Left, Qt.Key_Right], [Qt.Key_Down, Qt.Key_Up]];
for (var keyPairIndex = 0; keyPairIndex < 2; ++keyPairIndex) {
for (var i = 1; i <= 10; ++i) {
+ oldValue = dial.value;
keyClick(keyPairs[keyPairIndex][1]);
compare(parentEventSpy.count, 0);
+ if (oldValue !== dial.value)
+ compare(moveSpy.count, ++moveCount);
compare(dial.value, dial.stepSize * i);
}
compare(dial.value, dial.to);
for (i = 10; i > 0; --i) {
+ oldValue = dial.value;
keyClick(keyPairs[keyPairIndex][0]);
compare(parentEventSpy.count, 0);
+ if (oldValue !== dial.value)
+ compare(moveSpy.count, ++moveCount);
compare(dial.value, dial.stepSize * (i - 1));
}
}
+ dial.value = 0.5;
+
+ keyClick(Qt.Key_Home);
+ compare(parentEventSpy.count, 0);
+ compare(moveSpy.count, ++moveCount);
compare(dial.value, dial.from);
keyClick(Qt.Key_Home);
compare(parentEventSpy.count, 0);
+ compare(moveSpy.count, moveCount);
compare(dial.value, dial.from);
keyClick(Qt.Key_End);
compare(parentEventSpy.count, 0);
+ compare(moveSpy.count, ++moveCount);
compare(dial.value, dial.to);
keyClick(Qt.Key_End);
compare(parentEventSpy.count, 0);
+ compare(moveSpy.count, moveCount);
compare(dial.value, dial.to);
- keyClick(Qt.Key_Home);
- compare(parentEventSpy.count, 0);
- compare(dial.value, dial.from);
-
focusScope.destroy();
}