diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-05-31 08:38:16 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-06-16 22:06:56 +0200 |
commit | 6589f2ed0cf78c9b8a5bdffcdc458dc40a974c60 (patch) | |
tree | 61f29061a4cbaf925ef0ab7ba9fafc1db9ee4ef3 /tests/manual/qtabletevent | |
parent | 0a2e3ce85ce788b8a07380a458faf4ed3817d0c0 (diff) | |
download | qtbase-6589f2ed0cf78c9b8a5bdffcdc458dc40a974c60.tar.gz |
Introduce QInputDevice hierarchy; replace QTouchDevice
We have seen during the Qt 5 series that QMouseEvent::source() does
not provide enough information: if it is synthesized, it could have
come from any device for which mouse events are synthesized, not only
from a touchscreen. By providing in every QInputEvent as complete
information about the actual source device as possible, we will enable
very fine-tuned behavior in the object that handles each event.
Further, we would like to support multiple keyboards, pointing devices,
and named groups of devices that are known as "seats" in Wayland.
In Qt 5, QPA plugins registered each touchscreen as it was discovered.
Now we extend this pattern to all input devices. This new requirement
can be implemented gradually; for now, if a QTWSI input event is
received wtihout a device pointer, a default "core" device will be
created on-the-fly, and a warning emitted.
In Qt 5, QTouchEvent::TouchPoint::id() was forced to be unique even when
multiple devices were in use simultaneously. Now that each event
identifies the device it came from, this hack is no longer needed.
A stub of the new QPointerEvent is added; it will be developed further
in subsequent patches.
[ChangeLog][QtGui][QInputEvent] Every QInputEvent now carries a pointer
to an instance of QInputDevice, or the subclass QPointingDevice in case
of mouse, touch and tablet events. Each platform plugin is expected to
create the device instances, register them, and provide valid pointers
with all input events. If this is not done, warnings are emitted and
default devices are created as necessary. When the device has accurate
information, it provides the opportunity to fine-tune behavior depending
on device type and capabilities: for example if a QMouseEvent is
synthesized from a touchscreen, the recipient can see which touchscreen
it came from. Each device also has a seatName to distinguish users on
multi-user windowing systems. Touchpoint IDs are no longer unique on
their own, but the combination of ID and device is.
Fixes: QTBUG-46412
Fixes: QTBUG-72167
Task-number: QTBUG-69433
Task-number: QTBUG-52430
Change-Id: I933fb2b86182efa722037b7a33e404c5daf5292a
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/manual/qtabletevent')
3 files changed, 51 insertions, 55 deletions
diff --git a/tests/manual/qtabletevent/device_information/tabletwidget.cpp b/tests/manual/qtabletevent/device_information/tabletwidget.cpp index e146175109..18ea50c854 100644 --- a/tests/manual/qtabletevent/device_information/tabletwidget.cpp +++ b/tests/manual/qtabletevent/device_information/tabletwidget.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite module of the Qt Toolkit. @@ -58,8 +58,13 @@ bool TabletWidget::eventFilter(QObject *, QEvent *ev) mPos = event->pos(); mGPos = event->globalPos(); mHiResGlobalPos = event->posF(); - mDev = event->deviceType(); - mPointerType = event->pointerType(); + if (event->pointingDevice()) { + mDev = event->pointingDevice()->type(); + mPointerType = event->pointingDevice()->pointerType(); + mCaps = event->pointingDevice()->capabilities(); + } else { + qWarning() << "missing device in tablet event"; + } mUnique = event->uniqueId(); mXT = event->xTilt(); mYT = event->yTilt(); @@ -132,46 +137,9 @@ void TabletWidget::paintEvent(QPaintEvent *) 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; - } - 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("Device type: %1").arg(deviceTypeToString(mDev)); + eventInfo << QString("Pointer type: %1").arg(pointerTypeToString(mPointerType)); + eventInfo << QString("Capabilities: %1").arg(pointerCapabilitiesToString(mCaps)); 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 +150,7 @@ 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("Unique Id: %1").arg(QString::number(mUnique, 16)); eventInfo << QString("Total wheel events: %1").arg(QString::number(mWheelEventCount)); } @@ -191,10 +159,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..d05b89a74e 100644 --- a/tests/manual/qtabletevent/device_information/tabletwidget.h +++ b/tests/manual/qtabletevent/device_information/tabletwidget.h @@ -31,6 +31,7 @@ #include <QWidget> #include <QTabletEvent> +#include <QPointingDevice> #include <QShortcut> // a widget showing the information of the last tablet event @@ -42,12 +43,18 @@ 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 = QInputDevice::DeviceType::Unknown; + mPointerType = QPointingDevice::PointerType::Unknown; + mCaps = {}; + mType = mXT = mYT = mZ = 0; mPress = mTangential = mRot = 0.0; mPos = mGPos = QPoint(); mHiResGlobalPos = QPointF(); @@ -56,7 +63,10 @@ private: int mType; QPoint mPos, mGPos; QPointF mHiResGlobalPos; - int mDev, mPointerType, mXT, mYT, mZ; + QInputDevice::DeviceType mDev; + QPointingDevice::PointerType mPointerType; + QPointingDevice::Capabilities mCaps; + int mXT, mYT, mZ; Qt::MouseButton mButton; Qt::MouseButtons mButtons; Qt::KeyboardModifiers mModifiers; diff --git a/tests/manual/qtabletevent/regular_widgets/main.cpp b/tests/manual/qtabletevent/regular_widgets/main.cpp index 1d0af4559b..38b8ae816d 100644 --- a/tests/manual/qtabletevent/regular_widgets/main.cpp +++ b/tests/manual/qtabletevent/regular_widgets/main.cpp @@ -48,14 +48,14 @@ enum TabletPointType { 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; }; @@ -167,7 +167,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); @@ -205,7 +205,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())); @@ -229,7 +229,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(); @@ -245,7 +245,7 @@ bool EventReportWidget::event(QEvent *event) event->accept(); m_touchPoints.clear(); for (const QTouchEvent::TouchPoint &p : static_cast<const QTouchEvent *>(event)->touchPoints()) - m_touchPoints.append(p.pos()); + m_touchPoints.append(p.position()); update(); break; case QEvent::TouchEnd: |