diff --git a/src/quick/items/qquickpincharea.cpp b/src/quick/items/qquickpincharea.cpp index 0e47b61319794534ff0670d13dd40a92fe8cd1d5..dc586dcaea6e65eb57700ed59461d577e1459f4e 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 4fc77d7f9c309eecfc0c95054479607dbad75154..60c2dc742e241bcd9e79f23fa979a47b6936149a 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) };