aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickpageindicator.cpp81
-rw-r--r--src/quicktemplates2/qquickpageindicator_p.h5
-rw-r--r--tests/auto/controls/data/tst_pageindicator.qml26
3 files changed, 63 insertions, 49 deletions
diff --git a/src/quicktemplates2/qquickpageindicator.cpp b/src/quicktemplates2/qquickpageindicator.cpp
index b4c9c14c..7387b019 100644
--- a/src/quicktemplates2/qquickpageindicator.cpp
+++ b/src/quicktemplates2/qquickpageindicator.cpp
@@ -98,8 +98,13 @@ public:
{
}
- QQuickItem *itemAt(const QPoint &pos) const;
- void updatePressed(bool pressed, const QPoint &pos = QPoint());
+ void handlePress(const QPointF &point) override;
+ void handleMove(const QPointF &point) override;
+ void handleRelease(const QPointF &point) override;
+ void handleUngrab() override;
+
+ QQuickItem *itemAt(const QPointF &pos) const;
+ void updatePressed(bool pressed, const QPointF &pos = QPointF());
void setContextProperty(QQuickItem *item, const QString &name, const QVariant &value);
void itemChildAdded(QQuickItem *, QQuickItem *child);
@@ -111,7 +116,39 @@ public:
QQuickItem *pressedItem;
};
-QQuickItem *QQuickPageIndicatorPrivate::itemAt(const QPoint &pos) const
+void QQuickPageIndicatorPrivate::handlePress(const QPointF &point)
+{
+ QQuickControlPrivate::handlePress(point);
+ if (interactive)
+ updatePressed(true, point);
+}
+
+void QQuickPageIndicatorPrivate::handleMove(const QPointF &point)
+{
+ QQuickControlPrivate::handleMove(point);
+ if (interactive)
+ updatePressed(true, point);
+}
+
+void QQuickPageIndicatorPrivate::handleRelease(const QPointF &point)
+{
+ Q_Q(QQuickPageIndicator);
+ QQuickControlPrivate::handleRelease(point);
+ if (interactive) {
+ if (pressedItem && contentItem)
+ q->setCurrentIndex(contentItem->childItems().indexOf(pressedItem));
+ updatePressed(false);
+ }
+}
+
+void QQuickPageIndicatorPrivate::handleUngrab()
+{
+ QQuickControlPrivate::handleUngrab();
+ if (interactive)
+ updatePressed(false);
+}
+
+QQuickItem *QQuickPageIndicatorPrivate::itemAt(const QPointF &pos) const
{
Q_Q(const QQuickPageIndicator);
if (!contentItem || !q->contains(pos))
@@ -144,7 +181,7 @@ QQuickItem *QQuickPageIndicatorPrivate::itemAt(const QPoint &pos) const
return nearest;
}
-void QQuickPageIndicatorPrivate::updatePressed(bool pressed, const QPoint &pos)
+void QQuickPageIndicatorPrivate::updatePressed(bool pressed, const QPointF &pos)
{
QQuickItem *prevItem = pressedItem;
pressedItem = pressed ? itemAt(pos) : nullptr;
@@ -298,42 +335,6 @@ void QQuickPageIndicator::contentItemChange(QQuickItem *newItem, QQuickItem *old
QQuickItemPrivate::get(newItem)->addItemChangeListener(d, QQuickItemPrivate::Children);
}
-void QQuickPageIndicator::mousePressEvent(QMouseEvent *event)
-{
- Q_D(QQuickPageIndicator);
- if (d->interactive) {
- d->updatePressed(true, event->pos());
- event->accept();
- }
-}
-
-void QQuickPageIndicator::mouseMoveEvent(QMouseEvent *event)
-{
- Q_D(QQuickPageIndicator);
- if (d->interactive) {
- d->updatePressed(true, event->pos());
- event->accept();
- }
-}
-
-void QQuickPageIndicator::mouseReleaseEvent(QMouseEvent *event)
-{
- Q_D(QQuickPageIndicator);
- if (d->interactive) {
- if (d->pressedItem)
- setCurrentIndex(d->contentItem->childItems().indexOf(d->pressedItem));
- d->updatePressed(false);
- event->accept();
- }
-}
-
-void QQuickPageIndicator::mouseUngrabEvent()
-{
- Q_D(QQuickPageIndicator);
- if (d->interactive)
- d->updatePressed(false);
-}
-
#if QT_CONFIG(accessibility)
QAccessible::Role QQuickPageIndicator::accessibleRole() const
{
diff --git a/src/quicktemplates2/qquickpageindicator_p.h b/src/quicktemplates2/qquickpageindicator_p.h
index 921fe7e8..ea20a37a 100644
--- a/src/quicktemplates2/qquickpageindicator_p.h
+++ b/src/quicktemplates2/qquickpageindicator_p.h
@@ -87,11 +87,6 @@ Q_SIGNALS:
protected:
void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override;
- void mousePressEvent(QMouseEvent *event) override;
- void mouseMoveEvent(QMouseEvent *event) override;
- void mouseReleaseEvent(QMouseEvent *event) override;
- void mouseUngrabEvent() override;
-
#if QT_CONFIG(accessibility)
QAccessible::Role accessibleRole() const override;
#endif
diff --git a/tests/auto/controls/data/tst_pageindicator.qml b/tests/auto/controls/data/tst_pageindicator.qml
index 86c0bd8b..0ceefa35 100644
--- a/tests/auto/controls/data/tst_pageindicator.qml
+++ b/tests/auto/controls/data/tst_pageindicator.qml
@@ -83,20 +83,35 @@ TestCase {
compare(control.currentIndex, 5)
}
- function test_interactive() {
+ function test_interactive_data() {
+ return [
+ { tag: "mouse", touch: false },
+ { tag: "touch", touch: true }
+ ]
+ }
+
+ function test_interactive(data) {
var control = createTemporaryObject(pageIndicator, testCase, {count: 5, spacing: 10, padding: 10})
verify(control)
verify(!control.interactive)
compare(control.currentIndex, 0)
- mouseClick(control, control.width / 2, control.height / 2, Qt.LeftButton)
+ var touch = touchEvent(control)
+
+ if (data.touch)
+ touch.press(0, control).commit().release(0, control).commit()
+ else
+ mouseClick(control, control.width / 2, control.height / 2, Qt.LeftButton)
compare(control.currentIndex, 0)
control.interactive = true
verify(control.interactive)
- mouseClick(control, control.width / 2, control.height / 2, Qt.LeftButton)
+ if (data.touch)
+ touch.press(0, control).commit().release(0, control).commit()
+ else
+ mouseClick(control, control.width / 2, control.height / 2, Qt.LeftButton)
compare(control.currentIndex, 2)
// test also clicking outside delegates => the nearest should be selected
@@ -108,7 +123,10 @@ TestCase {
compare(control.currentIndex, -1)
var pos = control.mapFromItem(child, x, y)
- mouseClick(control, pos.x, pos.y, Qt.LeftButton)
+ if (data.touch)
+ touch.press(0, control, pos.x, pos.y).commit().release(0, control, pos.x, pos.y).commit()
+ else
+ mouseClick(control, pos.x, pos.y, Qt.LeftButton)
compare(control.currentIndex, i)
}
}