diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2016-02-12 08:18:28 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2016-02-12 09:12:57 +0100 |
commit | 2c83f2bf3366466db4dc0e3bee89e877fefe0260 (patch) | |
tree | 9c1f26ce26f80d2583803f471a9ff14dc8fb192c | |
parent | 7c7be5195df2b26db58c4e730e304787d7980228 (diff) | |
parent | 00292bca971fbe7023a28c3ccd10947a34ea88f8 (diff) |
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts:
src/templates/qquickabstractbutton.cpp
Change-Id: Icfd472451a150524dded704b4be5d286da21a6da
-rw-r--r-- | src/imports/controls/material/TabBar.qml | 8 | ||||
-rw-r--r-- | src/imports/controls/material/TabButton.qml | 5 | ||||
-rw-r--r-- | src/imports/controls/material/qquickmaterialtheme.cpp | 14 | ||||
-rw-r--r-- | src/imports/controls/material/qtlabsmaterialstyleplugin.cpp | 10 | ||||
-rw-r--r-- | src/imports/controls/plugins.qmltypes | 1 | ||||
-rw-r--r-- | src/imports/controls/universal/qquickuniversaltheme.cpp | 13 | ||||
-rw-r--r-- | src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp | 10 | ||||
-rw-r--r-- | src/imports/templates/plugins.qmltypes | 1 | ||||
-rw-r--r-- | src/templates/qquickabstractbutton.cpp | 50 | ||||
-rw-r--r-- | src/templates/qquickabstractbutton_p.h | 1 | ||||
-rw-r--r-- | src/templates/qquickabstractbutton_p_p.h | 6 | ||||
-rw-r--r-- | src/templates/qquickrangeslider.cpp | 42 | ||||
-rw-r--r-- | src/templates/qquickslider.cpp | 16 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_rangeslider.qml | 99 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_slider.qml | 32 |
15 files changed, 259 insertions, 49 deletions
diff --git a/src/imports/controls/material/TabBar.qml b/src/imports/controls/material/TabBar.qml index 4aaef818..dbc62512 100644 --- a/src/imports/controls/material/TabBar.qml +++ b/src/imports/controls/material/TabBar.qml @@ -41,15 +41,17 @@ import Qt.labs.controls.material 1.0 T.TabBar { id: control - implicitWidth: Math.max(26, contentItem.implicitWidth + leftPadding + rightPadding) - implicitHeight: Math.max(26, contentItem.implicitHeight + topPadding + bottomPadding) + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentItem.implicitWidth + leftPadding + rightPadding) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentItem.implicitHeight + topPadding + bottomPadding) spacing: 1 //! [contentItem] contentItem: ListView { implicitWidth: contentWidth - implicitHeight: contentHeight + implicitHeight: 48 model: control.contentModel currentIndex: control.currentIndex diff --git a/src/imports/controls/material/TabButton.qml b/src/imports/controls/material/TabButton.qml index 5b7510b4..496513dd 100644 --- a/src/imports/controls/material/TabButton.qml +++ b/src/imports/controls/material/TabButton.qml @@ -47,7 +47,7 @@ T.TabButton { contentItem.contentHeight + topPadding + bottomPadding) baselineOffset: contentItem.y + contentItem.baselineOffset - padding: 6 + padding: 12 //! [contentItem] contentItem: Text { @@ -62,8 +62,7 @@ T.TabButton { //! [background] background: Item { - height: parent.height - 1 - implicitHeight: 26 + implicitHeight: 48 } //! [background] } diff --git a/src/imports/controls/material/qquickmaterialtheme.cpp b/src/imports/controls/material/qquickmaterialtheme.cpp index 75ca1b8f..4124735a 100644 --- a/src/imports/controls/material/qquickmaterialtheme.cpp +++ b/src/imports/controls/material/qquickmaterialtheme.cpp @@ -43,8 +43,18 @@ QT_BEGIN_NAMESPACE QQuickMaterialTheme::QQuickMaterialTheme(QPlatformTheme *theme) : QQuickProxyTheme(theme) { - systemFont = QFont(QStringLiteral("Roboto")); - tabButtonFont = QFont(QStringLiteral("Roboto"), 10); + QFont font; + font.setFamily(QStringLiteral("Roboto")); + if (!font.exactMatch()) + font.setFamily(QStringLiteral("Noto")); + + if (font.exactMatch()) { + systemFont.setFamily(font.family()); + tabButtonFont.setFamily(font.family()); + } + + tabButtonFont.setPixelSize(14); + tabButtonFont.setCapitalization(QFont::AllUppercase); } QQuickMaterialTheme::~QQuickMaterialTheme() diff --git a/src/imports/controls/material/qtlabsmaterialstyleplugin.cpp b/src/imports/controls/material/qtlabsmaterialstyleplugin.cpp index 6370f78d..e4b44890 100644 --- a/src/imports/controls/material/qtlabsmaterialstyleplugin.cpp +++ b/src/imports/controls/material/qtlabsmaterialstyleplugin.cpp @@ -94,12 +94,10 @@ void QtLabsMaterialStylePlugin::initializeEngine(QQmlEngine *engine, const char QQuickStyleSelector selector; if (selector.style() == QLatin1String("material")) { - if (QFont(QStringLiteral("Roboto")).exactMatch()) { - QPlatformTheme *old = QGuiApplicationPrivate::platform_theme; - if (old) { - QQuickProxyTheme *theme = new QQuickMaterialTheme(old); - QGuiApplicationPrivate::platform_theme = theme; - } + QPlatformTheme *old = QGuiApplicationPrivate::platform_theme; + if (old) { + QQuickProxyTheme *theme = new QQuickMaterialTheme(old); + QGuiApplicationPrivate::platform_theme = theme; } } diff --git a/src/imports/controls/plugins.qmltypes b/src/imports/controls/plugins.qmltypes index 73f905f2..91553625 100644 --- a/src/imports/controls/plugins.qmltypes +++ b/src/imports/controls/plugins.qmltypes @@ -32,6 +32,7 @@ Module { Signal { name: "released" } Signal { name: "canceled" } Signal { name: "clicked" } + Signal { name: "pressAndHold" } Signal { name: "doubleClicked" } Method { name: "toggle" } } diff --git a/src/imports/controls/universal/qquickuniversaltheme.cpp b/src/imports/controls/universal/qquickuniversaltheme.cpp index e3899d53..290faa5d 100644 --- a/src/imports/controls/universal/qquickuniversaltheme.cpp +++ b/src/imports/controls/universal/qquickuniversaltheme.cpp @@ -43,11 +43,18 @@ QT_BEGIN_NAMESPACE QQuickUniversalTheme::QQuickUniversalTheme(QPlatformTheme *theme) : QQuickProxyTheme(theme) { - systemFont = QFont(QStringLiteral("Segoe UI")); + const QFont font(QStringLiteral("Segoe UI")); + if (font.exactMatch()) { + systemFont.setFamily(font.family()); + groupBoxTitleFont.setFamily(font.family()); + tabButtonFont.setFamily(font.family()); + } + systemFont.setPixelSize(15); - groupBoxTitleFont = systemFont; + + groupBoxTitleFont.setPixelSize(15); groupBoxTitleFont.setWeight(QFont::DemiBold); - tabButtonFont = QFont(QStringLiteral("Segoe UI")); + tabButtonFont.setPixelSize(24); tabButtonFont.setWeight(QFont::Light); } diff --git a/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp b/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp index 6d9d8c8a..51a71ea1 100644 --- a/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp +++ b/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp @@ -93,12 +93,10 @@ void QtLabsUniversalStylePlugin::initializeEngine(QQmlEngine *engine, const char { QQuickStyleSelector selector; if (selector.style() == QLatin1String("universal")) { - if (QFont(QStringLiteral("Segoe UI")).exactMatch()) { - QPlatformTheme *old = QGuiApplicationPrivate::platform_theme; - if (old) { - QQuickProxyTheme *theme = new QQuickUniversalTheme(old); - QGuiApplicationPrivate::platform_theme = theme; - } + QPlatformTheme *old = QGuiApplicationPrivate::platform_theme; + if (old) { + QQuickProxyTheme *theme = new QQuickUniversalTheme(old); + QGuiApplicationPrivate::platform_theme = theme; } } diff --git a/src/imports/templates/plugins.qmltypes b/src/imports/templates/plugins.qmltypes index 792d4e95..1879dc6c 100644 --- a/src/imports/templates/plugins.qmltypes +++ b/src/imports/templates/plugins.qmltypes @@ -26,6 +26,7 @@ Module { Signal { name: "released" } Signal { name: "canceled" } Signal { name: "clicked" } + Signal { name: "pressAndHold" } Signal { name: "doubleClicked" } Method { name: "toggle" } } diff --git a/src/templates/qquickabstractbutton.cpp b/src/templates/qquickabstractbutton.cpp index 9f1667fe..aed7ed5d 100644 --- a/src/templates/qquickabstractbutton.cpp +++ b/src/templates/qquickabstractbutton.cpp @@ -38,6 +38,7 @@ #include "qquickabstractbutton_p_p.h" #include "qquickbuttongroup_p.h" +#include <QtGui/qstylehints.h> #include <QtGui/qguiapplication.h> #include <QtQuick/private/qquickevents_p_p.h> #include <QtQml/qqmllist.h> @@ -93,15 +94,44 @@ static const int AUTO_REPEAT_INTERVAL = 100; */ /*! + \qmlsignal Qt.labs.controls::AbstractButton::pressAndHold() + + This signal is emitted when the button is interactively perssed and held down by the user. +*/ + +/*! \qmlsignal Qt.labs.controls::AbstractButton::doubleClicked() This signal is emitted when the button is interactively double clicked by the user. */ QQuickAbstractButtonPrivate::QQuickAbstractButtonPrivate() : - pressed(false), checked(false), checkable(false), highlighted(false), autoExclusive(false), autoRepeat(false), - delayTimer(0), repeatTimer(0), repeatButton(Qt::NoButton), indicator(nullptr), group(nullptr) + pressed(false), checked(false), checkable(false), highlighted(false), autoExclusive(false), autoRepeat(false), wasHeld(false), + holdTimer(0), delayTimer(0), repeatTimer(0), repeatButton(Qt::NoButton), indicator(nullptr), group(nullptr) +{ +} + +bool QQuickAbstractButtonPrivate::isPressAndHoldConnected() { + Q_Q(QQuickAbstractButton); + IS_SIGNAL_CONNECTED(q, QQuickAbstractButton, pressAndHold, ()); +} + +void QQuickAbstractButtonPrivate::startPressAndHold() +{ + Q_Q(QQuickAbstractButton); + wasHeld = false; + if (isPressAndHoldConnected()) + holdTimer = q->startTimer(QGuiApplication::styleHints()->mousePressAndHoldInterval()); +} + +void QQuickAbstractButtonPrivate::stopPressAndHold() +{ + Q_Q(QQuickAbstractButton); + if (holdTimer > 0) { + q->killTimer(holdTimer); + holdTimer = 0; + } } void QQuickAbstractButtonPrivate::startRepeatDelay() @@ -460,6 +490,8 @@ void QQuickAbstractButton::mousePressEvent(QMouseEvent *event) if (d->autoRepeat) { d->startRepeatDelay(); d->repeatButton = event->button(); + } else { + d->startPressAndHold(); } } @@ -471,6 +503,8 @@ void QQuickAbstractButton::mouseMoveEvent(QMouseEvent *event) if (d->autoRepeat) d->stopPressRepeat(); + else if (!d->pressed) + d->stopPressAndHold(); } void QQuickAbstractButton::mouseReleaseEvent(QMouseEvent *event) @@ -482,7 +516,8 @@ void QQuickAbstractButton::mouseReleaseEvent(QMouseEvent *event) if (wasPressed) { emit released(); - emit clicked(); + if (!d->wasHeld) + emit clicked(); } else { emit canceled(); } @@ -492,6 +527,8 @@ void QQuickAbstractButton::mouseReleaseEvent(QMouseEvent *event) if (d->autoRepeat) d->stopPressRepeat(); + else + d->stopPressAndHold(); } void QQuickAbstractButton::mouseDoubleClickEvent(QMouseEvent *event) @@ -507,6 +544,7 @@ void QQuickAbstractButton::mouseUngrabEvent() if (d->pressed) { setPressed(false); d->stopPressRepeat(); + d->stopPressAndHold(); emit canceled(); } } @@ -515,7 +553,11 @@ void QQuickAbstractButton::timerEvent(QTimerEvent *event) { Q_D(QQuickAbstractButton); QQuickControl::timerEvent(event); - if (event->timerId() == d->delayTimer) { + if (event->timerId() == d->holdTimer) { + d->stopPressAndHold(); + d->wasHeld = true; + emit pressAndHold(); + } else if (event->timerId() == d->delayTimer) { d->startPressRepeat(); } else if (event->timerId() == d->repeatTimer) { emit released(); diff --git a/src/templates/qquickabstractbutton_p.h b/src/templates/qquickabstractbutton_p.h index 7ff98f66..9469e706 100644 --- a/src/templates/qquickabstractbutton_p.h +++ b/src/templates/qquickabstractbutton_p.h @@ -102,6 +102,7 @@ Q_SIGNALS: void released(); void canceled(); void clicked(); + void pressAndHold(); void doubleClicked(); void textChanged(); void pressedChanged(); diff --git a/src/templates/qquickabstractbutton_p_p.h b/src/templates/qquickabstractbutton_p_p.h index be53946a..409fd52e 100644 --- a/src/templates/qquickabstractbutton_p_p.h +++ b/src/templates/qquickabstractbutton_p_p.h @@ -67,6 +67,10 @@ public: return button->d_func(); } + bool isPressAndHoldConnected(); + void startPressAndHold(); + void stopPressAndHold(); + void startRepeatDelay(); void startPressRepeat(); void stopPressRepeat(); @@ -81,6 +85,8 @@ public: bool highlighted; bool autoExclusive; bool autoRepeat; + bool wasHeld; + int holdTimer; int delayTimer; int repeatTimer; QPointF pressPoint; diff --git a/src/templates/qquickrangeslider.cpp b/src/templates/qquickrangeslider.cpp index 0dec63cb..11069757 100644 --- a/src/templates/qquickrangeslider.cpp +++ b/src/templates/qquickrangeslider.cpp @@ -323,10 +323,15 @@ static qreal valueAt(const QQuickRangeSlider *slider, qreal position) static qreal snapPosition(const QQuickRangeSlider *slider, qreal position) { - const qreal stepSize = slider->stepSize(); - if (qFuzzyIsNull(stepSize)) + const qreal range = slider->from() + (slider->to() - slider->from()); + if (qFuzzyIsNull(range)) return position; - return qRound(position / stepSize) * stepSize; + + const qreal effectiveStep = slider->stepSize() / range; + if (qFuzzyIsNull(effectiveStep)) + return position; + + return qRound(position / effectiveStep) * effectiveStep; } static qreal positionAt(const QQuickRangeSlider *slider, QQuickItem *handle, const QPoint &point) @@ -756,6 +761,31 @@ void QQuickRangeSlider::mousePressEvent(QMouseEvent *event) } else if (secondHit) { hitNode = d->second; otherNode = d->first; + } else { + // find the nearest + const qreal firstDistance = QLineF(firstHandle->boundingRect().center(), + mapToItem(firstHandle, event->pos())).length(); + const qreal secondDistance = QLineF(secondHandle->boundingRect().center(), + mapToItem(secondHandle, event->pos())).length(); + + if (qFuzzyCompare(firstDistance, secondDistance)) { + // same distance => choose the one that can be moved towards the press position + const bool inverted = d->from > d->to; + const qreal pos = positionAt(this, firstHandle, event->pos()); + if ((!inverted && pos < d->first->position()) || (inverted && pos > d->first->position())) { + hitNode = d->first; + otherNode = d->second; + } else { + hitNode = d->second; + otherNode = d->first; + } + } else if (firstDistance < secondDistance) { + hitNode = d->first; + otherNode = d->second; + } else { + hitNode = d->second; + otherNode = d->first; + } } if (hitNode) { @@ -803,7 +833,11 @@ void QQuickRangeSlider::mouseReleaseEvent(QMouseEvent *event) qreal pos = positionAt(this, pressedNode->handle(), event->pos()); if (d->snapMode != NoSnap) pos = snapPosition(this, pos); - pressedNode->setValue(valueAt(this, pos)); + qreal val = valueAt(this, pos); + if (!qFuzzyCompare(val, pressedNode->value())) + pressedNode->setValue(val); + else if (d->snapMode != NoSnap) + QQuickRangeSliderNodePrivate::get(pressedNode)->setPosition(pos); setKeepMouseGrab(false); pressedNode->setPressed(false); } diff --git a/src/templates/qquickslider.cpp b/src/templates/qquickslider.cpp index ae7d3508..e6163e0c 100644 --- a/src/templates/qquickslider.cpp +++ b/src/templates/qquickslider.cpp @@ -110,9 +110,15 @@ qreal QQuickSliderPrivate::valueAt(qreal position) const qreal QQuickSliderPrivate::snapPosition(qreal position) const { - if (qFuzzyIsNull(stepSize)) + const qreal range = from + (to - from); + if (qFuzzyIsNull(range)) return position; - return qRound(position / stepSize) * stepSize; + + const qreal effectiveStep = stepSize / range; + if (qFuzzyIsNull(effectiveStep)) + return position; + + return qRound(position / effectiveStep) * effectiveStep; } qreal QQuickSliderPrivate::positionAt(const QPoint &point) const @@ -531,7 +537,11 @@ void QQuickSlider::mouseReleaseEvent(QMouseEvent *event) qreal pos = d->positionAt(event->pos()); if (d->snapMode != NoSnap) pos = d->snapPosition(pos); - setValue(d->valueAt(pos)); + qreal val = d->valueAt(pos); + if (!qFuzzyCompare(val, d->value)) + setValue(val); + else if (d->snapMode != NoSnap) + d->setPosition(pos); setKeepMouseGrab(false); } setPressed(false); diff --git a/tests/auto/controls/data/tst_rangeslider.qml b/tests/auto/controls/data/tst_rangeslider.qml index 2a77d205..97104856 100644 --- a/tests/auto/controls/data/tst_rangeslider.qml +++ b/tests/auto/controls/data/tst_rangeslider.qml @@ -309,18 +309,18 @@ TestCase { secondPressedSpy.target = control.second verify(secondPressedSpy.valid) - mousePress(control, control.width * 0.5, control.height * 0.5, Qt.LeftButton) - compare(firstPressedSpy.count, 0) + mousePress(control, control.width * 0.25, control.height * 0.75, Qt.LeftButton) + compare(firstPressedSpy.count, 1) compare(secondPressedSpy.count, 0) - compare(control.first.pressed, false) + compare(control.first.pressed, true) compare(control.first.value, 0.0) compare(control.first.position, 0.0) compare(control.second.pressed, false) compare(control.second.value, 1.0) compare(control.second.position, 1.0) - mouseRelease(control, control.width * 0.5, control.height * 0.5, Qt.LeftButton) - compare(firstPressedSpy.count, 0) + mouseRelease(control, control.width * 0.25, control.height * 0.75, Qt.LeftButton) + compare(firstPressedSpy.count, 2) compare(secondPressedSpy.count, 0) compare(control.first.pressed, false) compare(control.first.value, 0.0) @@ -329,9 +329,19 @@ TestCase { compare(control.second.value, 1.0) compare(control.second.position, 1.0) - mousePress(control, 0, 0, Qt.LeftButton) - compare(firstPressedSpy.count, 0) - compare(secondPressedSpy.count, 0) + mousePress(control, control.width * 0.75, control.height * 0.25, Qt.LeftButton) + compare(firstPressedSpy.count, 2) + compare(secondPressedSpy.count, 1) + compare(control.first.pressed, false) + compare(control.first.value, 0.0) + compare(control.first.position, 0.0) + compare(control.second.pressed, true) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + + mouseRelease(control, control.width * 0.75, control.height * 0.25, Qt.LeftButton) + compare(firstPressedSpy.count, 2) + compare(secondPressedSpy.count, 2) compare(control.first.pressed, false) compare(control.first.value, 0.0) compare(control.first.position, 0.0) @@ -339,9 +349,19 @@ TestCase { compare(control.second.value, 1.0) compare(control.second.position, 1.0) - mouseRelease(control, 0, 0, Qt.LeftButton) - compare(firstPressedSpy.count, 0) - compare(secondPressedSpy.count, 0) + mousePress(control, 0, control.height, Qt.LeftButton) + compare(firstPressedSpy.count, 3) + compare(secondPressedSpy.count, 2) + compare(control.first.pressed, true) + compare(control.first.value, 0.0) + compare(control.first.position, 0.0) + compare(control.second.pressed, false) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + + mouseRelease(control, 0, control.height, Qt.LeftButton) + compare(firstPressedSpy.count, 4) + compare(secondPressedSpy.count, 2) compare(control.first.pressed, false) compare(control.first.value, 0.0) compare(control.first.position, 0.0) @@ -350,8 +370,8 @@ TestCase { compare(control.second.position, 1.0) mousePress(control, control.first.handle.x, control.first.handle.y, Qt.LeftButton) - compare(firstPressedSpy.count, 1) - compare(secondPressedSpy.count, 0) + compare(firstPressedSpy.count, 5) + compare(secondPressedSpy.count, 2) compare(control.first.pressed, true) compare(control.first.value, 0.0) compare(control.first.position, 0.0) @@ -363,8 +383,8 @@ TestCase { var toX = horizontal ? control.width * 0.5 : control.first.handle.x var toY = horizontal ? control.first.handle.y : control.height * 0.5 mouseMove(control, toX, toY, Qt.LeftButton) - compare(firstPressedSpy.count, 1) - compare(secondPressedSpy.count, 0) + compare(firstPressedSpy.count, 5) + compare(secondPressedSpy.count, 2) compare(control.first.pressed, true) compare(control.first.value, 0.0) compare(control.first.position, 0.5) @@ -374,6 +394,18 @@ TestCase { compare(control.second.position, 1.0) compare(control.second.visualPosition, horizontal ? 1.0 : 0.0) + mouseRelease(control, toX, toY, Qt.LeftButton) + compare(firstPressedSpy.count, 6) + compare(secondPressedSpy.count, 2) + compare(control.first.pressed, false) + compare(control.first.value, 0.5) + compare(control.first.position, 0.5) + compare(control.first.visualPosition, 0.5) + compare(control.second.pressed, false) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + compare(control.second.visualPosition, horizontal ? 1.0 : 0.0) + control.destroy() } @@ -586,4 +618,41 @@ TestCase { control.destroy() } + + function test_snapMode_data() { + return [ + { tag: "NoSnap", snapMode: Slider.NoSnap, values: [0, 0, 0.25], positions: [0, 0.1, 0.1] }, + { tag: "SnapAlways", snapMode: Slider.SnapAlways, values: [0, 0, 0.2], positions: [0, 0.1, 0.1] }, + { tag: "SnapOnRelease", snapMode: Slider.SnapOnRelease, values: [0, 0, 0.2], positions: [0, 0.1, 0.1] } + ] + } + + function test_snapMode(data) { + var control = sliderComponent.createObject(testCase, {snapMode: data.snapMode, from: 0, to: 2, stepSize: 0.2}) + verify(control) + + control.first.value = 0 + control.second.value = 2 + + function sliderCompare(left, right) { + return Math.abs(left - right) < 0.05 + } + + mousePress(control, control.first.handle.x, control.first.handle.y) + compare(control.first.pressed, true) + compare(control.first.value, data.values[0]) + compare(control.first.position, data.positions[0]) + + mouseMove(control, control.leftPadding + 0.15 * (control.availableWidth + control.first.handle.width / 2)) + compare(control.first.pressed, true) + verify(sliderCompare(control.first.value, data.values[1])) + verify(sliderCompare(control.first.position, data.positions[1])) + + mouseRelease(control, control.leftPadding + 0.15 * (control.availableWidth + control.first.handle.width / 2)) + compare(control.first.pressed, false) + verify(sliderCompare(control.first.value, data.values[2])) + verify(sliderCompare(control.first.position, data.positions[2])) + + control.destroy() + } } diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml index 5957442f..53e2fb8f 100644 --- a/tests/auto/controls/data/tst_slider.qml +++ b/tests/auto/controls/data/tst_slider.qml @@ -439,4 +439,36 @@ TestCase { control.destroy() } + + function test_snapMode_data() { + return [ + { tag: "NoSnap", snapMode: Slider.NoSnap, values: [0, 0, 0.25], positions: [0, 0.1, 0.1] }, + { tag: "SnapAlways", snapMode: Slider.SnapAlways, values: [0, 0, 0.2], positions: [0, 0.1, 0.1] }, + { tag: "SnapOnRelease", snapMode: Slider.SnapOnRelease, values: [0, 0, 0.2], positions: [0, 0.1, 0.1] } + ] + } + + function test_snapMode(data) { + var control = slider.createObject(testCase, {snapMode: data.snapMode, from: 0, to: 2, stepSize: 0.2}) + verify(control) + + function sliderCompare(left, right) { + return Math.abs(left - right) < 0.05 + } + + mousePress(control, control.leftPadding) + compare(control.value, data.values[0]) + compare(control.position, data.positions[0]) + + mouseMove(control, control.leftPadding + 0.15 * (control.availableWidth + control.handle.width / 2)) + + verify(sliderCompare(control.value, data.values[1])) + verify(sliderCompare(control.position, data.positions[1])) + + mouseRelease(control, control.leftPadding + 0.15 * (control.availableWidth + control.handle.width / 2)) + verify(sliderCompare(control.value, data.values[2])) + verify(sliderCompare(control.position, data.positions[2])) + + control.destroy() + } } |