diff options
author | Balazs Egedi <egedib@inf.u-szeged.hu> | 2021-08-16 14:40:27 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-02-01 16:35:03 +0000 |
commit | 89449238860b77b5a6d2339a269e0363314f3ae6 (patch) | |
tree | 015054243a8ebeefa114c8c947a549d102b5c241 /tests | |
parent | 113de3584e12aebd45a2cc1d54e63a3827bf0489 (diff) |
Port touchbrowser to Qt6
- Touchbrowser is only using QuickControls2.
- Missing resource files are added.
Change-Id: Ic8402b1d2daed8906d1244bfab2854d0d8844276
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
(cherry picked from commit 5f9b031d9b6333486198061c073161f3ff5f2d94)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/manual/quick/touchbrowser/AddressBar.qml | 24 | ||||
-rw-r--r-- | tests/manual/quick/touchbrowser/MockTouchPoint.qml | 53 | ||||
-rw-r--r-- | tests/manual/quick/touchbrowser/main.qml | 6 | ||||
-rw-r--r-- | tests/manual/quick/touchbrowser/qml.qrc | 2 | ||||
-rw-r--r-- | tests/manual/quick/touchbrowser/touchmockingapplication.cpp | 91 | ||||
-rw-r--r-- | tests/manual/quick/touchbrowser/touchmockingapplication.h | 18 | ||||
-rw-r--r-- | tests/manual/quick/touchbrowser/touchpoint.png | bin | 0 -> 1331 bytes |
7 files changed, 120 insertions, 74 deletions
diff --git a/tests/manual/quick/touchbrowser/AddressBar.qml b/tests/manual/quick/touchbrowser/AddressBar.qml index 1daae6dbf..77d887f3f 100644 --- a/tests/manual/quick/touchbrowser/AddressBar.qml +++ b/tests/manual/quick/touchbrowser/AddressBar.qml @@ -26,9 +26,8 @@ ** ****************************************************************************/ -import QtQuick 2.5 -import QtQuick.Controls 1.4 -import QtQuick.Controls.Styles 1.4 +import QtQuick +import QtQuick.Controls Rectangle { id: root @@ -59,6 +58,14 @@ Rectangle { TextField { id: addressField anchors.fill: parent + leftPadding: 30 + + background: Rectangle { + color: "transparent" + border.color: "black" + border.width: 1 + radius: root.radius + } Image { anchors.verticalCenter: addressField.verticalCenter @@ -78,17 +85,6 @@ Rectangle { visible: root.progress < 100 } - style: TextFieldStyle { - padding.left: 30 - - background: Rectangle { - color: "transparent" - border.color: "black" - border.width: 1 - radius: root.radius - } - } - onActiveFocusChanged: { if (activeFocus) selectAll(); diff --git a/tests/manual/quick/touchbrowser/MockTouchPoint.qml b/tests/manual/quick/touchbrowser/MockTouchPoint.qml new file mode 100644 index 000000000..bc24b002e --- /dev/null +++ b/tests/manual/quick/touchbrowser/MockTouchPoint.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt WebBrowser application. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick + +Item { + id: mockTouchPoint + + property bool pressed: false + property int pointId: 0 + + Image { + source: "qrc:/touchpoint.png" + x: -(width / 2) + y: -(height / 2) + opacity: mockTouchPoint.pressed ? 0.6 : 0.0 + + Behavior on opacity { + NumberAnimation { duration: 200 } + } + + Text { + text: mockTouchPoint.pointId + anchors.centerIn: parent + } + } +} diff --git a/tests/manual/quick/touchbrowser/main.qml b/tests/manual/quick/touchbrowser/main.qml index 926b3a941..1b864c057 100644 --- a/tests/manual/quick/touchbrowser/main.qml +++ b/tests/manual/quick/touchbrowser/main.qml @@ -26,9 +26,9 @@ ** ****************************************************************************/ -import QtQuick 2.5 -import QtQuick.Layouts 1.3 -import QtWebEngine 1.3 +import QtQuick +import QtQuick.Layouts +import QtWebEngine Item { function load(url) { diff --git a/tests/manual/quick/touchbrowser/qml.qrc b/tests/manual/quick/touchbrowser/qml.qrc index 45210fe36..5c384502e 100644 --- a/tests/manual/quick/touchbrowser/qml.qrc +++ b/tests/manual/quick/touchbrowser/qml.qrc @@ -2,5 +2,7 @@ <qresource prefix="/"> <file>main.qml</file> <file>AddressBar.qml</file> + <file>MockTouchPoint.qml</file> + <file>touchpoint.png</file> </qresource> </RCC> diff --git a/tests/manual/quick/touchbrowser/touchmockingapplication.cpp b/tests/manual/quick/touchbrowser/touchmockingapplication.cpp index 41b731a6a..b856365bf 100644 --- a/tests/manual/quick/touchbrowser/touchmockingapplication.cpp +++ b/tests/manual/quick/touchbrowser/touchmockingapplication.cpp @@ -29,12 +29,9 @@ #include "touchmockingapplication.h" #include <qpa/qwindowsysteminterface.h> -#include <QtCore/QEvent> -#include <QtGui/QMouseEvent> -#include <QtGui/QTouchDevice> -#include <QtGui/QTouchEvent> #include <QtQuick/QQuickItem> #include <QtQuick/QQuickView> +#include <QInputDevice> static inline bool isTouchEvent(const QEvent* event) { @@ -94,10 +91,10 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) if (event->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(event)->key() == Qt::Key_Control) { foreach (int id, m_heldTouchPoints) if (m_touchPoints.contains(id) && !QGuiApplication::mouseButtons().testFlag(Qt::MouseButton(id))) { - m_touchPoints[id].setState(Qt::TouchPointReleased); + QMutableEventPoint::from(m_touchPoints[id]).setState(QEventPoint::Released); m_heldTouchPoints.remove(id); } else - m_touchPoints[id].setState(Qt::TouchPointStationary); + QMutableEventPoint::from(m_touchPoints[id]).setState(QEventPoint::Stationary); sendTouchEvent(window, m_heldTouchPoints.isEmpty() ? QEvent::TouchEnd : QEvent::TouchUpdate, static_cast<QKeyEvent*>(event)->timestamp()); } @@ -105,19 +102,19 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) if (isMouseEvent(event)) { const QMouseEvent* const mouseEvent = static_cast<QMouseEvent*>(event); - QTouchEvent::TouchPoint touchPoint; - touchPoint.setPressure(1); + QEventPoint touchPoint; + QMutableEventPoint::from(touchPoint).setPressure(1); QEvent::Type touchType = QEvent::None; switch (mouseEvent->type()) { case QEvent::MouseButtonPress: - touchPoint.setId(mouseEvent->button()); + QMutableEventPoint::from(touchPoint).setId(mouseEvent->button()); if (m_touchPoints.contains(touchPoint.id())) { - touchPoint.setState(Qt::TouchPointMoved); + QMutableEventPoint::from(touchPoint).setState(QEventPoint::Updated); touchType = QEvent::TouchUpdate; } else { - touchPoint.setState(Qt::TouchPointPressed); + QMutableEventPoint::from(touchPoint).setState(QEventPoint::Pressed); // Check if more buttons are held down than just the event triggering one. if (mouseEvent->buttons() > mouseEvent->button()) touchType = QEvent::TouchUpdate; @@ -135,8 +132,8 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) return true; } touchType = QEvent::TouchUpdate; - touchPoint.setId(mouseEvent->buttons()); - touchPoint.setState(Qt::TouchPointMoved); + QMutableEventPoint::from(touchPoint).setId(mouseEvent->buttons()); + QMutableEventPoint::from(touchPoint).setState(QEventPoint::Updated); break; case QEvent::MouseButtonRelease: // Check if any buttons are still held down after this event. @@ -144,8 +141,8 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) touchType = QEvent::TouchUpdate; else touchType = QEvent::TouchEnd; - touchPoint.setId(mouseEvent->button()); - touchPoint.setState(Qt::TouchPointReleased); + QMutableEventPoint::from(touchPoint).setId(mouseEvent->button()); + QMutableEventPoint::from(touchPoint).setState(QEventPoint::Released); break; case QEvent::MouseButtonDblClick: // Eat double-clicks, their accompanying press event is all we need. @@ -163,7 +160,7 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) if (touchPoint.id() & Qt::RightButton) updateTouchPoint(mouseEvent, touchPoint, Qt::RightButton); - if (m_holdingControl && touchPoint.state() == Qt::TouchPointReleased) { + if (m_holdingControl && touchPoint.state() == QEventPoint::Released) { // We avoid sending the release event because the Flickable is // listening to mouse events and would start a bounce-back // animation if it received a mouse release. @@ -172,9 +169,9 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) } // Update states for all other touch-points - for (QHash<int, QTouchEvent::TouchPoint>::iterator it = m_touchPoints.begin(), end = m_touchPoints.end(); it != end; ++it) { + for (QHash<int, QEventPoint>::iterator it = m_touchPoints.begin(), end = m_touchPoints.end(); it != end; ++it) { if (!(it.value().id() & touchPoint.id())) - it.value().setState(Qt::TouchPointStationary); + QMutableEventPoint::from(it.value()).setState(QEventPoint::Stationary); } Q_ASSERT(touchType != QEvent::None); @@ -189,14 +186,14 @@ bool TouchMockingApplication::notify(QObject* target, QEvent* event) return QGuiApplication::notify(target, event); } -void TouchMockingApplication::updateTouchPoint(const QMouseEvent* mouseEvent, QTouchEvent::TouchPoint touchPoint, Qt::MouseButton mouseButton) +void TouchMockingApplication::updateTouchPoint(const QMouseEvent* mouseEvent, QEventPoint touchPoint, Qt::MouseButton mouseButton) { // Ignore inserting additional touch points if Ctrl isn't held because it produces // inconsistent touch events and results in assers in the gesture recognizers. if (!m_holdingControl && m_touchPoints.size() && !m_touchPoints.contains(mouseButton)) return; - if (m_holdingControl && touchPoint.state() == Qt::TouchPointReleased) { + if (m_holdingControl && touchPoint.state() == QEventPoint::Released) { m_heldTouchPoints.insert(mouseButton); return; } @@ -205,57 +202,59 @@ void TouchMockingApplication::updateTouchPoint(const QMouseEvent* mouseEvent, QT // but since the canvas translates touch events we actually need to pass // the screen position as the scene position to deliver the appropriate // coordinates to the target. - touchPoint.setPos(mouseEvent->localPos()); - touchPoint.setScenePos(mouseEvent->screenPos()); + QMutableEventPoint::from(touchPoint).setPosition(mouseEvent->position()); + QMutableEventPoint::from(touchPoint).setScenePosition(mouseEvent->globalPosition()); - if (touchPoint.state() == Qt::TouchPointPressed) - touchPoint.setStartScenePos(mouseEvent->screenPos()); + if (touchPoint.state() == QEventPoint::Pressed) + QMutableEventPoint::from(touchPoint).setScenePosition(mouseEvent->scenePosition()); else { - const QTouchEvent::TouchPoint& oldTouchPoint = m_touchPoints[mouseButton]; - touchPoint.setStartScenePos(oldTouchPoint.startScenePos()); - touchPoint.setLastPos(oldTouchPoint.pos()); - touchPoint.setLastScenePos(oldTouchPoint.scenePos()); + const QEventPoint& oldTouchPoint = m_touchPoints[mouseButton]; + QMutableEventPoint::from(touchPoint).setGlobalLastPosition(oldTouchPoint.globalPosition()); } // Update current touch-point. - touchPoint.setId(mouseButton); + QMutableEventPoint::from(touchPoint).setId(mouseButton); m_touchPoints.insert(mouseButton, touchPoint); } bool TouchMockingApplication::sendTouchEvent(QQuickView* window, QEvent::Type type, ulong timestamp) { - static QTouchDevice* device = 0; + static QPointingDevice* device = 0; if (!device) { - device = new QTouchDevice; - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device); + device = new QPointingDevice(QStringLiteral("MockTouchDevice"), 1, + QPointingDevice::DeviceType::TouchScreen, + QPointingDevice::PointerType::AllPointerTypes, + QInputDevice::Capability::All, 3, 3, + QString(), QPointingDeviceUniqueId(), window->rootObject()); + + QWindowSystemInterface::registerInputDevice(device); } m_pendingFakeTouchEventCount++; - const QList<QTouchEvent::TouchPoint>& currentTouchPoints = m_touchPoints.values(); - Qt::TouchPointStates touchPointStates = Qt::TouchPointState(); - foreach (const QTouchEvent::TouchPoint& touchPoint, currentTouchPoints) + const QList<QEventPoint>& currentTouchPoints = m_touchPoints.values(); + QEventPoint::States touchPointStates = QEventPoint::States(); + foreach (const QEventPoint& touchPoint, currentTouchPoints) touchPointStates |= touchPoint.state(); - QTouchEvent event(type, device, Qt::NoModifier, touchPointStates, currentTouchPoints); + QTouchEvent event(type, device, Qt::NoModifier, currentTouchPoints); event.setTimestamp(timestamp); event.setAccepted(false); QGuiApplication::notify(window, &event); - updateVisualMockTouchPoints(window,m_holdingControl ? currentTouchPoints : QList<QTouchEvent::TouchPoint>()); + updateVisualMockTouchPoints(window, m_holdingControl ? currentTouchPoints : QList<QEventPoint>()); // Get rid of touch-points that are no longer valid - foreach (const QTouchEvent::TouchPoint& touchPoint, currentTouchPoints) { - if (touchPoint.state() == Qt::TouchPointReleased) + foreach (const QEventPoint& touchPoint, currentTouchPoints) { + if (touchPoint.state() == QEventPoint::Released) m_touchPoints.remove(touchPoint.id()); } return event.isAccepted(); } -void TouchMockingApplication::updateVisualMockTouchPoints(QQuickView* window,const QList<QTouchEvent::TouchPoint>& touchPoints) +void TouchMockingApplication::updateVisualMockTouchPoints(QQuickView* window,const QList<QEventPoint>& touchPoints) { if (touchPoints.isEmpty()) { // Hide all touch indicator items. @@ -265,11 +264,11 @@ void TouchMockingApplication::updateVisualMockTouchPoints(QQuickView* window,con return; } - foreach (const QTouchEvent::TouchPoint& touchPoint, touchPoints) { + foreach (const QEventPoint& touchPoint, touchPoints) { QQuickItem* mockTouchPointItem = m_activeMockComponents.value(touchPoint.id()); if (!mockTouchPointItem) { - QQmlComponent touchMockPointComponent(window->engine(), QUrl("qrc:///qml/MockTouchPoint.qml")); + QQmlComponent touchMockPointComponent(window->engine(), QUrl("qrc:///MockTouchPoint.qml")); mockTouchPointItem = qobject_cast<QQuickItem*>(touchMockPointComponent.create()); Q_ASSERT(mockTouchPointItem); m_activeMockComponents.insert(touchPoint.id(), mockTouchPointItem); @@ -278,10 +277,10 @@ void TouchMockingApplication::updateVisualMockTouchPoints(QQuickView* window,con mockTouchPointItem->setParentItem(window->rootObject()); } - mockTouchPointItem->setX(touchPoint.pos().x()); - mockTouchPointItem->setY(touchPoint.pos().y()); + mockTouchPointItem->setX(touchPoint.position().x()); + mockTouchPointItem->setY(touchPoint.position().y()); mockTouchPointItem->setWidth(touchPoint.ellipseDiameters().width()); mockTouchPointItem->setHeight(touchPoint.ellipseDiameters().height()); - mockTouchPointItem->setProperty("pressed", QVariant(touchPoint.state() != Qt::TouchPointReleased)); + mockTouchPointItem->setProperty("pressed", QVariant(touchPoint.state() != QEventPoint::Released)); } } diff --git a/tests/manual/quick/touchbrowser/touchmockingapplication.h b/tests/manual/quick/touchbrowser/touchmockingapplication.h index cdabe871f..205cab694 100644 --- a/tests/manual/quick/touchbrowser/touchmockingapplication.h +++ b/tests/manual/quick/touchbrowser/touchmockingapplication.h @@ -29,11 +29,11 @@ #ifndef TOUCHMOCKINGAPPLICATION_H #define TOUCHMOCKINGAPPLICATION_H -#include <QtCore/QHash> -#include <QtCore/QSet> -#include <QtCore/QUrl> #include <QtGui/QGuiApplication> -#include <QtGui/QTouchEvent> +#include <QtGui/private/qeventpoint_p.h> +#include <QtGui/QEventPoint> + +#include <private/qevent_p.h> QT_BEGIN_NAMESPACE class QQuickView; @@ -50,19 +50,15 @@ public: virtual bool notify(QObject *, QEvent *) override; private: - void updateTouchPoint(const QMouseEvent *, QTouchEvent::TouchPoint, Qt::MouseButton); + void updateTouchPoint(const QMouseEvent *, QEventPoint, Qt::MouseButton); bool sendTouchEvent(QQuickView *, QEvent::Type, ulong timestamp); - void updateVisualMockTouchPoints(QQuickView *,const QList<QTouchEvent::TouchPoint> &touchPoints); + void updateVisualMockTouchPoints(QQuickView *,const QList<QEventPoint> &touchPoints); private: bool m_realTouchEventReceived; int m_pendingFakeTouchEventCount; - QPointF m_lastPos; - QPointF m_lastScreenPos; - QPointF m_startScreenPos; - - QHash<int, QTouchEvent::TouchPoint> m_touchPoints; + QHash<int, QEventPoint> m_touchPoints; QSet<int> m_heldTouchPoints; QHash<int, QQuickItem*> m_activeMockComponents; diff --git a/tests/manual/quick/touchbrowser/touchpoint.png b/tests/manual/quick/touchbrowser/touchpoint.png Binary files differnew file mode 100644 index 000000000..7649ee991 --- /dev/null +++ b/tests/manual/quick/touchbrowser/touchpoint.png |