aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2013-05-03 13:47:42 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-03 16:17:41 +0200
commit885f325196de48493a604c6d13e3f360e4fefba3 (patch)
tree1810c2cd87bb348f4e46e6b661ad9bc583355ed1
parent03f0c55799e671d8800ef3727f71162766e103d1 (diff)
Enable touch events on Mac for PinchArea
Enabling touch events on a window causes scroll event lag so we want to avoid avoid it as far as possible. Enable/disable on scene changes, similar to what we do with WA_AcceptTouchEvents for widgets, and in change I2e5b5e2b093cccfc5253f7228f5ec0c588c60371 for MultiPointTouchArea. Change-Id: I8cd8d172ffd93cfc4ec115917cc8662202f3b069 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
-rw-r--r--src/quick/items/qquickpincharea.cpp26
-rw-r--r--src/quick/items/qquickpincharea_p.h4
2 files changed, 30 insertions, 0 deletions
diff --git a/src/quick/items/qquickpincharea.cpp b/src/quick/items/qquickpincharea.cpp
index 0e47b61319..dc586dcaea 100644
--- a/src/quick/items/qquickpincharea.cpp
+++ b/src/quick/items/qquickpincharea.cpp
@@ -45,6 +45,7 @@
#include <QtGui/qevent.h>
#include <QtGui/qguiapplication.h>
#include <QtGui/qstylehints.h>
+#include <qpa/qplatformnativeinterface.h>
#include <float.h>
#include <math.h>
@@ -246,11 +247,15 @@ QQuickPinchAreaPrivate::~QQuickPinchAreaPrivate()
QQuickPinchArea::QQuickPinchArea(QQuickItem *parent)
: QQuickItem(*(new QQuickPinchAreaPrivate), parent)
+ , _currentWindow(0)
{
Q_D(QQuickPinchArea);
d->init();
setAcceptedMouseButtons(Qt::LeftButton);
setFiltersChildMouseEvents(true);
+#ifdef Q_OS_MAC
+ connect(this, &QQuickItem::windowChanged, this, &QQuickPinchArea::setTouchEventsEnabledForWindow);
+#endif
}
QQuickPinchArea::~QQuickPinchArea()
@@ -539,6 +544,27 @@ QQuickPinch *QQuickPinchArea::pinch()
return d->pinch;
}
+void QQuickPinchArea::setTouchEventsEnabledForWindow(QWindow *window)
+{
+#ifdef Q_OS_MAC
+ // Resolve function for enabling touch events from the (cocoa) platform plugin.
+ typedef void (*RegisterTouchWindowFunction)(QWindow *, bool);
+ RegisterTouchWindowFunction registerTouchWindow = reinterpret_cast<RegisterTouchWindowFunction>(
+ QGuiApplication::platformNativeInterface()->nativeResourceFunctionForIntegration("registertouchwindow"));
+ if (!registerTouchWindow)
+ return; // Not necessarily an error, Qt migh be using a different platform plugin.
+
+ // Disable touch on the old window, enable on the new window.
+ if (_currentWindow)
+ registerTouchWindow(_currentWindow, false);
+ if (window)
+ registerTouchWindow(window, true);
+ // Save the current window, setTouchEventsEnabledForWindow will be called
+ // with a null window on disable.
+ _currentWindow = window;
+#endif
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/items/qquickpincharea_p.h b/src/quick/items/qquickpincharea_p.h
index 4fc77d7f9c..60c2dc742e 100644
--- a/src/quick/items/qquickpincharea_p.h
+++ b/src/quick/items/qquickpincharea_p.h
@@ -283,12 +283,16 @@ protected:
const QRectF &oldGeometry);
virtual void itemChange(ItemChange change, const ItemChangeData& value);
+private slots:
+ void setTouchEventsEnabledForWindow(QWindow *window);
+
private:
void updatePinch();
void handlePress();
void handleRelease();
private:
+ QWindow *_currentWindow;
Q_DISABLE_COPY(QQuickPinchArea)
Q_DECLARE_PRIVATE(QQuickPinchArea)
};