diff options
Diffstat (limited to 'tests/manual/qtabletevent')
12 files changed, 262 insertions, 278 deletions
diff --git a/tests/manual/qtabletevent/CMakeLists.txt b/tests/manual/qtabletevent/CMakeLists.txt new file mode 100644 index 0000000000..df4a66c8f1 --- /dev/null +++ b/tests/manual/qtabletevent/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +#add_subdirectory(device_information) # TODO: no member named 'staticQtMetaObject' +add_subdirectory(event_compression) +add_subdirectory(regular_widgets) diff --git a/tests/manual/qtabletevent/device_information/CMakeLists.txt b/tests/manual/qtabletevent/device_information/CMakeLists.txt new file mode 100644 index 0000000000..a0583b1f93 --- /dev/null +++ b/tests/manual/qtabletevent/device_information/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +project(tablet_device_info) +cmake_minimum_required(VERSION 3.19) + +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) + +qt_add_executable(tablet_device_info + main.cpp + tabletwidget.h tabletwidget.cpp +) + +set_target_properties(tablet_device_info PROPERTIES + AUTOMOC TRUE +) + +target_link_libraries(tablet_device_info PUBLIC + Qt::Widgets +) diff --git a/tests/manual/qtabletevent/device_information/main.cpp b/tests/manual/qtabletevent/device_information/main.cpp index d1ccd28928..cb18e79eac 100644 --- a/tests/manual/qtabletevent/device_information/main.cpp +++ b/tests/manual/qtabletevent/device_information/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QApplication> #include <QDebug> diff --git a/tests/manual/qtabletevent/device_information/tabletwidget.cpp b/tests/manual/qtabletevent/device_information/tabletwidget.cpp index 14d059abc1..747c807e02 100644 --- a/tests/manual/qtabletevent/device_information/tabletwidget.cpp +++ b/tests/manual/qtabletevent/device_information/tabletwidget.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** 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$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "tabletwidget.h" #include <QPainter> @@ -54,13 +29,12 @@ bool TabletWidget::eventFilter(QObject *, QEvent *ev) case QEvent::TabletRelease: { QTabletEvent *event = static_cast<QTabletEvent*>(ev); + mDev = event->pointingDevice(); + if (!mDev) + qWarning() << "missing device in tablet event"; mType = event->type(); - mPos = event->pos(); - mGPos = event->globalPos(); - mHiResGlobalPos = event->posF(); - mDev = event->device(); - mPointerType = event->pointerType(); - mUnique = event->uniqueId(); + mPos = event->position(); + mGPos = event->globalPosition(); mXT = event->xTilt(); mYT = event->yTilt(); mZ = event->z(); @@ -81,8 +55,10 @@ bool TabletWidget::eventFilter(QObject *, QEvent *ev) QMouseEvent *event = static_cast<QMouseEvent*>(ev); mType = event->type(); mPos = event->pos(); - mGPos = event->globalPos(); + mGPos = event->globalPosition(); mTimestamp = event->timestamp(); + if (isVisible()) + update(); } break; case QEvent::Wheel: @@ -129,49 +105,16 @@ void TabletWidget::paintEvent(QPaintEvent *) if (mType == QEvent::TabletEnterProximity || mType == QEvent::TabletLeaveProximity || mType == QEvent::TabletMove || mType == QEvent::TabletPress || mType == QEvent::TabletRelease) { - - eventInfo << QString("High res global position: %1 %2").arg(QString::number(mHiResGlobalPos.x()), QString::number(mHiResGlobalPos.y())); - - QString pointerType("Pointer type: "); - switch (mPointerType) { - case QTabletEvent::UnknownPointer: - pointerType += "QTabletEvent::UnknownPointer"; - break; - case QTabletEvent::Pen: - pointerType += "QTabletEvent::Pen"; - break; - case QTabletEvent::Cursor: - pointerType += "QTabletEvent::Cursor"; - break; - case QTabletEvent::Eraser: - pointerType += "QTabletEvent::Eraser"; - break; + if (mDev.isNull()) { + eventInfo << QString("Device info missing"); + } else { + eventInfo << QString("Seat: %1").arg(mDev->seatName()); + eventInfo << QString("Name: %1").arg(mDev->name()); + eventInfo << QString("Device type: %1").arg(deviceTypeToString(mDev->type())); + eventInfo << QString("Pointer type: %1").arg(pointerTypeToString(mDev->pointerType())); + eventInfo << QString("Capabilities: %1").arg(pointerCapabilitiesToString(mDev->capabilities())); + eventInfo << QString("Unique Id: %1").arg(QString::number(mDev->uniqueId().numericId(), 16)); } - eventInfo << pointerType; - - QString deviceString = "Device type: "; - switch (mDev) { - case QTabletEvent::NoDevice: - deviceString += "QTabletEvent::NoDevice"; - break; - case QTabletEvent::Puck: - deviceString += "QTabletEvent::Puck"; - break; - case QTabletEvent::Stylus: - deviceString += "QTabletEvent::Stylus"; - break; - case QTabletEvent::Airbrush: - deviceString += "QTabletEvent::Airbrush"; - break; - case QTabletEvent::FourDMouse: - deviceString += "QTabletEvent::FourDMouse"; - break; - case QTabletEvent::RotationStylus: - deviceString += "QTabletEvent::RotationStylus"; - break; - } - eventInfo << deviceString; - eventInfo << QString("Button: %1 (0x%2)").arg(buttonToString(mButton)).arg(mButton, 0, 16); eventInfo << QString("Buttons currently pressed: %1 (0x%2)").arg(buttonsToString(mButtons)).arg(mButtons, 0, 16); eventInfo << QString("Keyboard modifiers: %1 (0x%2)").arg(modifiersToString(mModifiers)).arg(mModifiers, 0, 16); @@ -182,7 +125,6 @@ void TabletWidget::paintEvent(QPaintEvent *) eventInfo << QString("yTilt: %1").arg(QString::number(mYT)); eventInfo << QString("z: %1").arg(QString::number(mZ)); - eventInfo << QString("Unique Id: %1").arg(QString::number(mUnique)); eventInfo << QString("Total wheel events: %1").arg(QString::number(mWheelEventCount)); } @@ -191,10 +133,28 @@ void TabletWidget::paintEvent(QPaintEvent *) painter.drawText(rect(), text); } +const char *TabletWidget::deviceTypeToString(QInputDevice::DeviceType t) +{ + static int enumIdx = QInputDevice::staticMetaObject.indexOfEnumerator("DeviceType"); + return QPointingDevice::staticMetaObject.enumerator(enumIdx).valueToKey(int(t)); +} + +const char *TabletWidget::pointerTypeToString(QPointingDevice::PointerType t) +{ + static int enumIdx = QPointingDevice::staticMetaObject.indexOfEnumerator("PointerType"); + return QPointingDevice::staticMetaObject.enumerator(enumIdx).valueToKey(int(t)); +} + +QString TabletWidget::pointerCapabilitiesToString(QPointingDevice::Capabilities c) +{ + static int enumIdx = QPointingDevice::staticMetaObject.indexOfEnumerator("Capabilities"); + return QString::fromLatin1(QPointingDevice::staticMetaObject.enumerator(enumIdx).valueToKeys(c)); +} + const char *TabletWidget::buttonToString(Qt::MouseButton b) { - static int enumIdx = QObject::staticQtMetaObject.indexOfEnumerator("MouseButtons"); - return QObject::staticQtMetaObject.enumerator(enumIdx).valueToKey(b); + static int enumIdx = QObject::staticMetaObject.indexOfEnumerator("MouseButtons"); + return QObject::staticMetaObject.enumerator(enumIdx).valueToKey(b); } QString TabletWidget::buttonsToString(Qt::MouseButtons bs) diff --git a/tests/manual/qtabletevent/device_information/tabletwidget.h b/tests/manual/qtabletevent/device_information/tabletwidget.h index 404be1289f..477ae55b1b 100644 --- a/tests/manual/qtabletevent/device_information/tabletwidget.h +++ b/tests/manual/qtabletevent/device_information/tabletwidget.h @@ -1,36 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef TABLETWIDGET_H #define TABLETWIDGET_H #include <QWidget> #include <QTabletEvent> +#include <QPointer> +#include <QPointingDevice> #include <QShortcut> // a widget showing the information of the last tablet event @@ -42,26 +19,27 @@ protected: bool eventFilter(QObject *obj, QEvent *ev); void tabletEvent(QTabletEvent *event); void paintEvent(QPaintEvent *event); + const char *deviceTypeToString(QInputDevice::DeviceType t); + const char *pointerTypeToString(QPointingDevice::PointerType t); + QString pointerCapabilitiesToString(QPointingDevice::Capabilities c); const char *buttonToString(Qt::MouseButton b); QString buttonsToString(Qt::MouseButtons bs); QString modifiersToString(Qt::KeyboardModifiers m); private: void resetAttributes() { - mType = mDev = mPointerType = mXT = mYT = mZ = 0; + mDev.clear(); + mType = mXT = mYT = mZ = 0; mPress = mTangential = mRot = 0.0; mPos = mGPos = QPoint(); - mHiResGlobalPos = QPointF(); - mUnique = 0; } + QPointer<const QPointingDevice> mDev; int mType; - QPoint mPos, mGPos; - QPointF mHiResGlobalPos; - int mDev, mPointerType, mXT, mYT, mZ; + QPointF mPos, mGPos; + int mXT, mYT, mZ; Qt::MouseButton mButton; Qt::MouseButtons mButtons; Qt::KeyboardModifiers mModifiers; qreal mPress, mTangential, mRot; - qint64 mUnique; bool mMouseToo; ulong mTimestamp; int mWheelEventCount; diff --git a/tests/manual/qtabletevent/event_compression/CMakeLists.txt b/tests/manual/qtabletevent/event_compression/CMakeLists.txt new file mode 100644 index 0000000000..74fa0fb790 --- /dev/null +++ b/tests/manual/qtabletevent/event_compression/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## event_compression Binary: +##################################################################### + +qt_internal_add_manual_test(event_compression + SOURCES + main.cpp + mousestatwidget.cpp mousestatwidget.h + LIBRARIES + Qt::Gui + Qt::Test + Qt::Widgets +) diff --git a/tests/manual/qtabletevent/event_compression/main.cpp b/tests/manual/qtabletevent/event_compression/main.cpp index 10a26a976a..13edf8e704 100644 --- a/tests/manual/qtabletevent/event_compression/main.cpp +++ b/tests/manual/qtabletevent/event_compression/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "mousestatwidget.h" diff --git a/tests/manual/qtabletevent/event_compression/mousestatwidget.cpp b/tests/manual/qtabletevent/event_compression/mousestatwidget.cpp index a26c62d2e1..483ce0019d 100644 --- a/tests/manual/qtabletevent/event_compression/mousestatwidget.cpp +++ b/tests/manual/qtabletevent/event_compression/mousestatwidget.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "mousestatwidget.h" diff --git a/tests/manual/qtabletevent/event_compression/mousestatwidget.h b/tests/manual/qtabletevent/event_compression/mousestatwidget.h index 78294c2d25..f204a753a3 100644 --- a/tests/manual/qtabletevent/event_compression/mousestatwidget.h +++ b/tests/manual/qtabletevent/event_compression/mousestatwidget.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MOUSESTATWIDGET_H #define MOUSESTATWIDGET_H diff --git a/tests/manual/qtabletevent/regular_widgets/CMakeLists.txt b/tests/manual/qtabletevent/regular_widgets/CMakeLists.txt new file mode 100644 index 0000000000..d95c33df18 --- /dev/null +++ b/tests/manual/qtabletevent/regular_widgets/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## regular_widgets Binary: +##################################################################### + +qt_internal_add_manual_test(regular_widgets + GUI + SOURCES + main.cpp + LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + Qt::Widgets +) diff --git a/tests/manual/qtabletevent/regular_widgets/main.cpp b/tests/manual/qtabletevent/regular_widgets/main.cpp index 4816e2f3b9..3aee2bcdba 100644 --- a/tests/manual/qtabletevent/regular_widgets/main.cpp +++ b/tests/manual/qtabletevent/regular_widgets/main.cpp @@ -1,43 +1,31 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only +#include <QAction> #include <QApplication> +#include <QCursor> #include <QDebug> -#include <QMouseEvent> -#include <QTabletEvent> +#include <QDialog> +#include <QDialogButtonBox> +#include <QList> #include <QMainWindow> -#include <QMenuBar> #include <QMenu> -#include <QAction> -#include <QStatusBar> -#include <QVector> +#include <QMenuBar> +#include <QMouseEvent> #include <QPainter> -#include <QCursor> +#include <QPainterPath> +#include <QPlainTextEdit> +#include <QPointingDevice> +#include <QPointer> +#include <QPushButton> +#include <QStatusBar> +#include <QTabletEvent> +#include <QVBoxLayout> + +#ifdef Q_OS_WIN +# include <QtGui/private/qguiapplication_p.h> +# include <QtGui/qpa/qplatformintegration.h> +#endif enum TabletPointType { TabletButtonPress, @@ -45,16 +33,32 @@ enum TabletPointType { TabletMove }; +#ifdef Q_OS_WIN +using QWindowsApplication = QNativeInterface::Private::QWindowsApplication; + +static void setWinTabEnabled(bool e) +{ + if (auto nativeWindowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration())) + nativeWindowsApp->setWinTabEnabled(e); +} + +static bool isWinTabEnabled() +{ + auto nativeWindowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration()); + return nativeWindowsApp && nativeWindowsApp->isWinTabEnabled(); +} +#endif // Q_OS_WIN + struct TabletPoint { - TabletPoint(const QPointF &p = QPointF(), TabletPointType t = TabletMove, - Qt::MouseButton b = Qt::LeftButton, QTabletEvent::PointerType pt = QTabletEvent::UnknownPointer, qreal prs = 0, qreal rotation = 0) : + TabletPoint(const QPointF &p = QPointF(), TabletPointType t = TabletMove, Qt::MouseButton b = Qt::LeftButton, + QPointingDevice::PointerType pt = QPointingDevice::PointerType::Unknown, qreal prs = 0, qreal rotation = 0) : pos(p), type(t), button(b), ptype(pt), pressure(prs), angle(rotation) {} QPointF pos; TabletPointType type; Qt::MouseButton button; - QTabletEvent::PointerType ptype; + QPointingDevice::PointerType ptype; qreal pressure; qreal angle; }; @@ -124,8 +128,8 @@ private: bool m_lastIsMouseMove = false; bool m_lastIsTabletMove = false; Qt::MouseButton m_lastButton = Qt::NoButton; - QVector<TabletPoint> m_points; - QVector<QPointF> m_touchPoints; + QList<TabletPoint> m_points; + QList<QPointF> m_touchPoints; QPointF m_tabletPos; int m_tabletMoveCount = 0; int m_paintEventCount = 0; @@ -148,7 +152,7 @@ void EventReportWidget::paintEvent(QPaintEvent *) p.setPen(Qt::white); QPainterPath ellipse; ellipse.addEllipse(0, 0, halfLineSpacing * 5, halfLineSpacing); - for (const TabletPoint &t : qAsConst(m_points)) { + for (const TabletPoint &t : std::as_const(m_points)) { if (geom.contains(t.pos)) { QPainterPath pp; pp.addEllipse(t.pos, halfLineSpacing, halfLineSpacing); @@ -166,7 +170,7 @@ void EventReportWidget::paintEvent(QPaintEvent *) break; case TabletMove: if (t.pressure > 0.0) { - p.setPen(t.ptype == QTabletEvent::Eraser ? Qt::red : Qt::black); + p.setPen(t.ptype == QPointingDevice::PointerType::Eraser ? Qt::red : Qt::black); if (t.angle != 0.0) { p.save(); p.translate(t.pos); @@ -204,7 +208,7 @@ void EventReportWidget::tabletEvent(QTabletEvent *event) { QWidget::tabletEvent(event); bool isMove = false; - m_tabletPos = event->posF(); + m_tabletPos = event->position(); switch (event->type()) { case QEvent::TabletMove: m_points.push_back(TabletPoint(m_tabletPos, TabletMove, m_lastButton, event->pointerType(), event->pressure(), event->rotation())); @@ -228,7 +232,7 @@ void EventReportWidget::tabletEvent(QTabletEvent *event) if (!(isMove && m_lastIsTabletMove)) { QDebug d = qDebug(); - d << event << " global position = " << event->globalPos() + d << event << " global position = " << event->globalPosition() << " cursor at " << QCursor::pos(); if (event->button() != Qt::NoButton) d << " changed button " << event->button(); @@ -243,8 +247,8 @@ bool EventReportWidget::event(QEvent *event) case QEvent::TouchUpdate: event->accept(); m_touchPoints.clear(); - for (const QTouchEvent::TouchPoint &p : static_cast<const QTouchEvent *>(event)->touchPoints()) - m_touchPoints.append(p.pos()); + for (const QEventPoint &p : static_cast<const QPointerEvent *>(event)->points()) + m_touchPoints.append(p.position()); update(); break; case QEvent::TouchEnd: @@ -274,25 +278,108 @@ void EventReportWidget::timerEvent(QTimerEvent *) m_paintEventCount = 0; } -int main(int argc, char *argv[]) +class DevicesDialog : public QDialog { - QApplication app(argc, argv); + Q_OBJECT +public: + explicit DevicesDialog(QWidget *p); - ProximityEventFilter *proximityEventFilter = new ProximityEventFilter(&app); - app.installEventFilter(proximityEventFilter); - QMainWindow mainWindow; - mainWindow.setWindowTitle(QString::fromLatin1("Tablet Test %1").arg(QT_VERSION_STR)); - EventReportWidget *widget = new EventReportWidget; +public slots: + void refresh(); + +private: + QPlainTextEdit *m_edit; +}; + +DevicesDialog::DevicesDialog(QWidget *p) : QDialog(p) +{ + auto layout = new QVBoxLayout(this); + m_edit = new QPlainTextEdit(this); + m_edit->setReadOnly(true); + layout->addWidget(m_edit); + auto box = new QDialogButtonBox(QDialogButtonBox::Close, this); + connect(box, &QDialogButtonBox::rejected, this, &QDialog::reject); + auto refreshButton = box->addButton("Refresh", QDialogButtonBox::ActionRole); + connect(refreshButton, &QAbstractButton::clicked, this, &DevicesDialog::refresh); + layout->addWidget(box); + setWindowTitle("Devices"); + refresh(); +} + +void DevicesDialog::refresh() +{ + QString text; + QDebug d(&text); + d.noquote(); + d.nospace(); + for (auto device : QInputDevice::devices()) + d << device<< "\n\n"; + m_edit->setPlainText(text); +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + explicit MainWindow(ProximityEventFilter *proximityEventFilter); + +public slots: + void showDevices(); + +private: + QPointer<DevicesDialog> m_devicesDialog; +}; + +MainWindow::MainWindow(ProximityEventFilter *proximityEventFilter) +{ + setWindowTitle(QString::fromLatin1("Tablet Test %1").arg(QT_VERSION_STR)); + auto widget = new EventReportWidget; QObject::connect(proximityEventFilter, &ProximityEventFilter::proximityChanged, widget, QOverload<>::of(&QWidget::update)); widget->setMinimumSize(640, 480); - QMenu *fileMenu = mainWindow.menuBar()->addMenu("File"); + auto fileMenu = menuBar()->addMenu("File"); fileMenu->addAction("Clear", widget, &EventReportWidget::clearPoints); + auto showAction = fileMenu->addAction("Show Devices", this, &MainWindow::showDevices); + showAction->setShortcut(Qt::CTRL | Qt::Key_D); QObject::connect(widget, &EventReportWidget::stats, - mainWindow.statusBar(), &QStatusBar::showMessage); + statusBar(), &QStatusBar::showMessage); QAction *quitAction = fileMenu->addAction("Quit", qApp, &QCoreApplication::quit); - quitAction->setShortcut(Qt::CTRL + Qt::Key_Q); - mainWindow.setCentralWidget(widget); + quitAction->setShortcut(Qt::CTRL | Qt::Key_Q); + + auto settingsMenu = menuBar()->addMenu("Settings"); + auto winTabAction = settingsMenu->addAction("WinTab"); + winTabAction->setCheckable(true); +#ifdef Q_OS_WIN + winTabAction->setChecked(isWinTabEnabled()); + connect(winTabAction, &QAction::toggled, this, setWinTabEnabled); +#else + winTabAction->setEnabled(false); +#endif + + setCentralWidget(widget); +} + +void MainWindow::showDevices() +{ + if (m_devicesDialog.isNull()) { + m_devicesDialog = new DevicesDialog(nullptr); + m_devicesDialog->setModal(false); + m_devicesDialog->resize(500, 300); + m_devicesDialog->move(frameGeometry().topRight() + QPoint(20, 0)); + m_devicesDialog->setAttribute(Qt::WA_DeleteOnClose); + } + m_devicesDialog->show(); + m_devicesDialog->raise(); + m_devicesDialog->refresh(); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + ProximityEventFilter *proximityEventFilter = new ProximityEventFilter(&app); + app.installEventFilter(proximityEventFilter); + MainWindow mainWindow(proximityEventFilter); mainWindow.show(); return app.exec(); } diff --git a/tests/manual/qtabletevent/regular_widgets/regular_widgets.pro b/tests/manual/qtabletevent/regular_widgets/regular_widgets.pro index 8f1f4342ee..1428d10a04 100644 --- a/tests/manual/qtabletevent/regular_widgets/regular_widgets.pro +++ b/tests/manual/qtabletevent/regular_widgets/regular_widgets.pro @@ -1,4 +1,4 @@ TEMPLATE = app -QT += widgets +QT += widgets gui-private core-private SOURCES += main.cpp |