diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-08-05 12:29:14 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-08-06 09:56:42 (GMT) |
commit | d90f1e4ff7a077daf59f5f035cf6744fe732f843 (patch) | |
tree | 457cb28948a76144215ee97a32cea3e7781bb3a4 /src/gui | |
parent | 5e7c47537f0f9599959388670ebd8fe910d9c0f1 (diff) | |
download | Qt-d90f1e4ff7a077daf59f5f035cf6744fe732f843.zip Qt-d90f1e4ff7a077daf59f5f035cf6744fe732f843.tar.gz Qt-d90f1e4ff7a077daf59f5f035cf6744fe732f843.tar.bz2 |
Rearranged the gesture code a bit for future native gestures on Windows.
Moved the code that subscribes to native gestures on Windows to a private
function in QWidget which will check which gestures the widget is subscribed to
and enable native gestures as requested.
Reviewed-by: trustme
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qapplication_p.h | 14 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_win.cpp | 2 | ||||
-rw-r--r-- | src/gui/kernel/qstandardgestures.cpp | 22 | ||||
-rw-r--r-- | src/gui/kernel/qwidget.cpp | 2 | ||||
-rw-r--r-- | src/gui/kernel/qwidget_p.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qwidget_win.cpp | 50 | ||||
-rw-r--r-- | src/gui/widgets/qabstractscrollarea.cpp | 32 | ||||
-rw-r--r-- | src/gui/widgets/qabstractscrollarea.h | 1 | ||||
-rw-r--r-- | src/gui/widgets/qabstractscrollarea_p.h | 1 |
9 files changed, 80 insertions, 45 deletions
diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index 595f220..700d1ab 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -234,6 +234,8 @@ typedef struct tagGESTUREINFO # define GC_PAN_WITH_SINGLE_FINGER_VERTICALLY 0x00000002 # define GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY 0x00000004 +# define GC_ZOOM 0x00000001 + typedef struct tagGESTURECONFIG { DWORD dwID; @@ -247,11 +249,12 @@ typedef struct tagGESTURECONFIG class QPanGesture; class QPinchGesture; -struct StandardGestures +struct QStandardGestures { QPanGesture *pan; QPinchGesture *pinch; - StandardGestures() : pan(0), pinch(0) { } + + QStandardGestures() : pan(0), pinch(0) { } }; @@ -513,6 +516,9 @@ public: QTouchEvent::DeviceType deviceType, const QList<QTouchEvent::TouchPoint> &touchPoints); + typedef QMap<QWidget*, QStandardGestures> WidgetStandardGesturesMap; + WidgetStandardGesturesMap widgetGestures; + #if defined(Q_WS_WIN) static PtrRegisterTouchWindow RegisterTouchWindow; static PtrGetTouchInputInfo GetTouchInputInfo; @@ -522,10 +528,6 @@ public: QList<QTouchEvent::TouchPoint> appAllTouchPoints; bool translateTouchEvent(const MSG &msg); - typedef QMap<QWidget*, StandardGestures> WidgetStandardGesturesMap; - WidgetStandardGesturesMap widgetGestures; - ulong lastGestureId; - PtrGetGestureInfo GetGestureInfo; PtrGetGestureExtraArgs GetGestureExtraArgs; PtrCloseGestureInfoHandle CloseGestureInfoHandle; diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index 2bded5c..3177cc1 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -815,8 +815,6 @@ void qt_init(QApplicationPrivate *priv, int) ptrSetProcessDPIAware(); #endif - priv->lastGestureId = 0; - priv->GetGestureInfo = (PtrGetGestureInfo)QLibrary::resolve(QLatin1String("user32"), "GetGestureInfo"); diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index 4753416..2a5e7e8 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -46,11 +46,13 @@ #include <qscrollbar.h> #include <private/qapplication_p.h> #include <private/qevent_p.h> +#include <private/qwidget_p.h> QT_BEGIN_NAMESPACE #ifdef Q_WS_WIN QApplicationPrivate* getQApplicationPrivateInternal(); +QWidgetPrivate *qt_widget_private(QWidget *widget); #endif /*! @@ -71,32 +73,38 @@ QApplicationPrivate* getQApplicationPrivateInternal(); QPanGesture::QPanGesture(QWidget *parent) : QGesture(*new QPanGesturePrivate, parent) { -#ifdef Q_WS_WIN if (parent) { QApplicationPrivate *qAppPriv = getQApplicationPrivateInternal(); qAppPriv->widgetGestures[parent].pan = this; - } +#ifdef Q_WS_WIN + qt_widget_private(parent)->winSetupGestures(); #endif + } } /*! \internal */ bool QPanGesture::event(QEvent *event) { -#ifdef Q_WS_WIN - QApplicationPrivate* getQApplicationPrivateInternal(); switch (event->type()) { case QEvent::ParentAboutToChange: - if (QWidget *w = qobject_cast<QWidget*>(parent())) + if (QWidget *w = qobject_cast<QWidget*>(parent())) { getQApplicationPrivateInternal()->widgetGestures[w].pan = 0; +#ifdef Q_WS_WIN + qt_widget_private(w)->winSetupGestures(); +#endif + } break; case QEvent::ParentChange: - if (QWidget *w = qobject_cast<QWidget*>(parent())) + if (QWidget *w = qobject_cast<QWidget*>(parent())) { getQApplicationPrivateInternal()->widgetGestures[w].pan = this; +#ifdef Q_WS_WIN + qt_widget_private(w)->winSetupGestures(); +#endif + } break; default: break; } -#endif #if defined(Q_OS_MAC) && !defined(QT_MAC_USE_COCOA) Q_D(QPanGesture); diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index a827967..50343fc 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11114,8 +11114,6 @@ Q_GUI_EXPORT QWidgetPrivate *qt_widget_private(QWidget *widget) } - - #ifndef QT_NO_GRAPHICSVIEW /*! \since 4.5 diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 998181e..ac145b7 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -558,6 +558,7 @@ public: #endif void grabMouseWhileInWindow(); void registerTouchWindow(); + void winSetupGestures(); #elif defined(Q_WS_MAC) // <--------------------------------------------------------- MAC // This is new stuff uint needWindowChange : 1; diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp index b11b661..ce853d2 100644 --- a/src/gui/kernel/qwidget_win.cpp +++ b/src/gui/kernel/qwidget_win.cpp @@ -56,6 +56,10 @@ #include "private/qbackingstore_p.h" #include "private/qwindowsurface_raster_p.h" +#include "qscrollbar.h" +#include "qabstractscrollarea.h" +#include <private/qabstractscrollarea_p.h> + #include <qdebug.h> #include <private/qapplication_p.h> @@ -2049,6 +2053,52 @@ void QWidgetPrivate::registerTouchWindow() QApplicationPrivate::RegisterTouchWindow(q->effectiveWinId(), 0); } +void QWidgetPrivate::winSetupGestures() +{ + Q_Q(QWidget); + QApplicationPrivate *qAppPriv = getQApplicationPrivateInternal(); + bool needh = false; + bool needv = false; + bool singleFingerPanEnabled = false; + QStandardGestures gestures = qAppPriv->widgetGestures[q]; + WId winid = 0; + + if (QAbstractScrollArea *asa = qobject_cast<QAbstractScrollArea*>(q)) { + winid = asa->viewport()->winId(); + QScrollBar *hbar = asa->horizontalScrollBar(); + QScrollBar *vbar = asa->verticalScrollBar(); + Qt::ScrollBarPolicy hbarpolicy = asa->horizontalScrollBarPolicy(); + Qt::ScrollBarPolicy vbarpolicy = asa->verticalScrollBarPolicy(); + needh = (hbarpolicy == Qt::ScrollBarAlwaysOn + || (hbarpolicy == Qt::ScrollBarAsNeeded && hbar->minimum() < hbar->maximum())); + needv = (vbarpolicy == Qt::ScrollBarAlwaysOn + || (vbarpolicy == Qt::ScrollBarAsNeeded && vbar->minimum() < vbar->maximum())); + singleFingerPanEnabled = asa->d_func()->singleFingerPanEnabled; + } + if (qAppPriv->SetGestureConfig) { + GESTURECONFIG gc[2]; + gc[0].dwID = GID_PAN; + if (gestures.pan || needh || needv) { + gc[0].dwWant = GC_PAN; + gc[0].dwBlock = 0; + if (needv && singleFingerPanEnabled) + gc[0].dwWant |= GC_PAN_WITH_SINGLE_FINGER_VERTICALLY; + if (needh && singleFingerPanEnabled) + gc[0].dwWant |= GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY; + } else { + gc[0].dwWant = 0; + gc[0].dwBlock = GC_PAN; + } + + gc[1].dwID = GID_ZOOM; + if (gestures.pinch) { + gc[1].dwWant = GC_ZOOM; + gc[1].dwBlock = 0; + } + qAppPriv->SetGestureConfig(winid, 0, sizeof(gc)/sizeof(gc[0]), gc, sizeof(gc[0])); + } +} + QT_END_NAMESPACE #ifdef Q_WS_WINCE diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp index dd92e17..e803afc 100644 --- a/src/gui/widgets/qabstractscrollarea.cpp +++ b/src/gui/widgets/qabstractscrollarea.cpp @@ -296,32 +296,6 @@ void QAbstractScrollAreaPrivate::init() layoutChildren(); } -void QAbstractScrollAreaPrivate::setupGestures() -{ -#ifdef Q_OS_WIN - if (!viewport) - return; - QApplicationPrivate* getQApplicationPrivateInternal(); - QApplicationPrivate *qAppPriv = getQApplicationPrivateInternal(); - bool needh = (hbarpolicy == Qt::ScrollBarAlwaysOn - || (hbarpolicy == Qt::ScrollBarAsNeeded && hbar->minimum() < hbar->maximum())); - - bool needv = (vbarpolicy == Qt::ScrollBarAlwaysOn - || (vbarpolicy == Qt::ScrollBarAsNeeded && vbar->minimum() < vbar->maximum())); - if (qAppPriv->SetGestureConfig && (needh || needv)) { - GESTURECONFIG gc[1]; - gc[0].dwID = GID_PAN; - gc[0].dwWant = GC_PAN; - gc[0].dwBlock = 0; - if (needv && singleFingerPanEnabled) - gc[0].dwWant |= GC_PAN_WITH_SINGLE_FINGER_VERTICALLY; - if (needh && singleFingerPanEnabled) - gc[0].dwWant |= GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY; - qAppPriv->SetGestureConfig(viewport->winId(), 0, 1, gc, sizeof(gc)); - } -#endif // Q_OS_WIN -} - void QAbstractScrollAreaPrivate::layoutChildren() { Q_Q(QAbstractScrollArea); @@ -1267,7 +1241,11 @@ void QAbstractScrollAreaPrivate::_q_vslide(int y) void QAbstractScrollAreaPrivate::_q_showOrHideScrollBars() { layoutChildren(); - setupGestures(); +#ifdef Q_OS_WIN + // Need to re-subscribe to gestures as the content changes to make sure we + // enable/disable panning when needed. + winSetupGestures(); +#endif // Q_OS_WIN } QPoint QAbstractScrollAreaPrivate::contentsOffset() const diff --git a/src/gui/widgets/qabstractscrollarea.h b/src/gui/widgets/qabstractscrollarea.h index 3ec41d1..c7441c1 100644 --- a/src/gui/widgets/qabstractscrollarea.h +++ b/src/gui/widgets/qabstractscrollarea.h @@ -130,6 +130,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_showOrHideScrollBars()) friend class QStyleSheetStyle; + friend class QWidgetPrivate; }; #endif // QT_NO_SCROLLAREA diff --git a/src/gui/widgets/qabstractscrollarea_p.h b/src/gui/widgets/qabstractscrollarea_p.h index aef8ac5..9a6b923 100644 --- a/src/gui/widgets/qabstractscrollarea_p.h +++ b/src/gui/widgets/qabstractscrollarea_p.h @@ -103,7 +103,6 @@ public: #ifdef Q_WS_WIN bool singleFingerPanEnabled; #endif - void setupGestures(); }; class QAbstractScrollAreaFilter : public QObject |