aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickevents.cpp
diff options
context:
space:
mode:
authorJan Arve Saether <jan-arve.saether@qt.io>2016-07-20 16:42:40 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2016-07-23 06:49:54 +0000
commit7436638b51ef7b121afd5ea8135e4a3ce5913fa4 (patch)
treed34ce24c6bdc4d5a91fde55cdb149cd4e16ae7dc /src/quick/items/qquickevents.cpp
parenta5e7897dd7705a9df3a97e5de75b5b95d6a88e25 (diff)
Use Q_GLOBAL_STATIC instead of static members of QWindowPrivate
Having the members static in QWindowPrivate only gives the benefit of tidyness, but there's still the problem of initialization order and thread-safety. Q_GLOBAL_STATIC solves those issues for us. Change-Id: I8e1279959d0bb2b16fd720cb7f4e9afb6eda6355 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquickevents.cpp')
-rw-r--r--src/quick/items/qquickevents.cpp59
1 files changed, 57 insertions, 2 deletions
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp
index e4a080d2b7..80a4e6bd9a 100644
--- a/src/quick/items/qquickevents.cpp
+++ b/src/quick/items/qquickevents.cpp
@@ -441,6 +441,61 @@ Item {
\l inverted always returns false.
*/
+typedef QHash<QTouchDevice *, QQuickPointerDevice *> PointerDeviceForTouchDeviceHash;
+Q_GLOBAL_STATIC(PointerDeviceForTouchDeviceHash, g_touchDevices)
+
+Q_GLOBAL_STATIC_WITH_ARGS(QQuickPointerDevice, g_genericMouseDevice,
+ (QQuickPointerDevice::Mouse,
+ QQuickPointerDevice::GenericPointer,
+ QQuickPointerDevice::Position | QQuickPointerDevice::Scroll | QQuickPointerDevice::Hover,
+ 1, 3, QLatin1String("core pointer"), 0))
+
+typedef QHash<qint64, QQuickPointerDevice *> PointerDeviceForDeviceIdHash;
+Q_GLOBAL_STATIC(PointerDeviceForDeviceIdHash, g_tabletDevices)
+
+QQuickPointerDevice *QQuickPointerDevice::touchDevice(QTouchDevice *d)
+{
+ if (g_touchDevices->contains(d))
+ return g_touchDevices->value(d);
+
+ QQuickPointerDevice::DeviceType type = QQuickPointerDevice::TouchScreen;
+ QString name;
+ int maximumTouchPoints = 10;
+ QQuickPointerDevice::Capabilities caps = QQuickPointerDevice::Capabilities(QTouchDevice::Position);
+ if (d) {
+ QQuickPointerDevice::Capabilities caps =
+ static_cast<QQuickPointerDevice::Capabilities>(static_cast<int>(d->capabilities()) & 0x0F);
+ if (d->type() == QTouchDevice::TouchPad) {
+ type = QQuickPointerDevice::TouchPad;
+ caps |= QQuickPointerDevice::Scroll;
+ }
+ name = d->name();
+ maximumTouchPoints = d->maximumTouchPoints();
+ } else {
+ qWarning() << "QQuickWindowPrivate::touchDevice: creating touch device from nullptr device in QTouchEvent";
+ }
+
+ QQuickPointerDevice *dev = new QQuickPointerDevice(type, QQuickPointerDevice::Finger,
+ caps, maximumTouchPoints, 0, name, 0);
+ g_touchDevices->insert(d, dev);
+ return dev;
+}
+
+QQuickPointerDevice *QQuickPointerDevice::genericMouseDevice()
+{
+ return g_genericMouseDevice;
+}
+
+QQuickPointerDevice *QQuickPointerDevice::tabletDevice(qint64 id)
+{
+ auto it = g_tabletDevices->find(id);
+ if (it != g_tabletDevices->end())
+ return it.value();
+
+ // ### Figure out how to populate the tablet devices
+ return nullptr;
+}
+
QQuickEventTouchPoint::QQuickEventTouchPoint(QQuickPointerTouchEvent *parent)
: QQuickEventPoint(parent), m_rotation(0), m_pressure(0)
@@ -465,7 +520,7 @@ QQuickPointerEvent::~QQuickPointerEvent()
QQuickPointerEvent *QQuickPointerMouseEvent::reset(QEvent *event) {
auto ev = static_cast<QMouseEvent*>(event);
- m_device = QQuickWindowPrivate::genericMouseDevice;
+ m_device = QQuickPointerDevice::genericMouseDevice();
m_event = ev;
m_button = ev->button();
m_pressedButtons = ev->buttons();
@@ -490,7 +545,7 @@ QQuickPointerEvent *QQuickPointerMouseEvent::reset(QEvent *event) {
QQuickPointerEvent *QQuickPointerTouchEvent::reset(QEvent *event) {
auto ev = static_cast<QTouchEvent*>(event);
- m_device = QQuickWindowPrivate::touchDevice(ev->device());
+ m_device = QQuickPointerDevice::touchDevice(ev->device());
m_event = ev;
m_button = Qt::NoButton;
m_pressedButtons = Qt::NoButton;