50 #include "private/qapplication_p.h" |
50 #include "private/qapplication_p.h" |
51 #include "private/qwidget_p.h" |
51 #include "private/qwidget_p.h" |
52 |
52 |
53 QT_BEGIN_NAMESPACE |
53 QT_BEGIN_NAMESPACE |
54 |
54 |
|
55 #if !defined(QT_NO_NATIVE_GESTURES) |
|
56 |
55 QWinNativePanGestureRecognizer::QWinNativePanGestureRecognizer() |
57 QWinNativePanGestureRecognizer::QWinNativePanGestureRecognizer() |
56 { |
58 { |
57 } |
59 } |
58 |
60 |
59 QGesture* QWinNativePanGestureRecognizer::createGesture(QObject *target) const |
61 QGesture *QWinNativePanGestureRecognizer::create(QObject *target) |
60 { |
62 { |
61 if (!target) |
63 if (!target) |
62 return new QPanGesture; // a special case |
64 return new QPanGesture; // a special case |
63 if (qobject_cast<QGraphicsObject*>(target)) |
|
64 return 0; |
|
65 if (!target->isWidgetType()) |
65 if (!target->isWidgetType()) |
66 return 0; |
66 return 0; |
|
67 if (qobject_cast<QGraphicsObject *>(target)) |
|
68 return 0; |
67 |
69 |
68 QWidget *q = static_cast<QWidget*>(target); |
70 QWidget *q = static_cast<QWidget *>(target); |
69 QWidgetPrivate *d = q->d_func(); |
71 QWidgetPrivate *d = q->d_func(); |
70 d->nativeGesturePanEnabled = true; |
72 d->nativeGesturePanEnabled = true; |
71 d->winSetupGestures(); |
73 d->winSetupGestures(); |
72 |
74 |
73 return new QPanGesture; |
75 return new QPanGesture; |
74 } |
76 } |
75 |
77 |
76 QGestureRecognizer::Result QWinNativePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) |
78 QGestureRecognizer::Result QWinNativePanGestureRecognizer::recognize(QGesture *state, |
|
79 QObject *, |
|
80 QEvent *event) |
77 { |
81 { |
78 QPanGesture *q = static_cast<QPanGesture*>(state); |
82 QPanGesture *q = static_cast<QPanGesture*>(state); |
79 QPanGesturePrivate *d = q->d_func(); |
83 QPanGesturePrivate *d = q->d_func(); |
80 |
84 |
81 QGestureRecognizer::Result result = QGestureRecognizer::Ignore; |
85 QGestureRecognizer::Result result = QGestureRecognizer::Ignore; |
83 QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event); |
87 QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event); |
84 switch(ev->gestureType) { |
88 switch(ev->gestureType) { |
85 case QNativeGestureEvent::GestureBegin: |
89 case QNativeGestureEvent::GestureBegin: |
86 break; |
90 break; |
87 case QNativeGestureEvent::Pan: |
91 case QNativeGestureEvent::Pan: |
88 result = QGestureRecognizer::GestureTriggered; |
92 result = QGestureRecognizer::TriggerGesture; |
89 event->accept(); |
93 event->accept(); |
90 break; |
94 break; |
91 case QNativeGestureEvent::GestureEnd: |
95 case QNativeGestureEvent::GestureEnd: |
92 if (q->state() == Qt::NoGesture) |
96 if (q->state() == Qt::NoGesture) |
93 return QGestureRecognizer::Ignore; // some other gesture has ended |
97 return QGestureRecognizer::Ignore; // some other gesture has ended |
94 result = QGestureRecognizer::GestureFinished; |
98 result = QGestureRecognizer::FinishGesture; |
95 break; |
99 break; |
96 default: |
100 default: |
97 return QGestureRecognizer::Ignore; |
101 return QGestureRecognizer::Ignore; |
98 } |
102 } |
99 if (q->state() == Qt::NoGesture) { |
103 if (q->state() == Qt::NoGesture) { |
100 d->lastOffset = d->totalOffset = d->offset = QPointF(); |
104 d->lastOffset = d->offset = QPointF(); |
|
105 d->startPosition = ev->position; |
101 } else { |
106 } else { |
102 d->lastOffset = d->offset; |
107 d->lastOffset = d->offset; |
103 d->offset = QPointF(ev->position.x() - d->lastPosition.x(), |
108 d->offset = QPointF(ev->position.x() - d->startPosition.x(), |
104 ev->position.y() - d->lastPosition.y()); |
109 ev->position.y() - d->startPosition.y()); |
105 d->totalOffset += d->offset; |
|
106 } |
110 } |
107 d->lastPosition = ev->position; |
|
108 } |
111 } |
109 return result; |
112 return result; |
110 } |
113 } |
111 |
114 |
112 void QWinNativePanGestureRecognizer::reset(QGesture *state) |
115 void QWinNativePanGestureRecognizer::reset(QGesture *state) |
113 { |
116 { |
114 QPanGesture *pan = static_cast<QPanGesture*>(state); |
117 QPanGesture *pan = static_cast<QPanGesture*>(state); |
115 QPanGesturePrivate *d = pan->d_func(); |
118 QPanGesturePrivate *d = pan->d_func(); |
116 |
119 |
117 d->totalOffset = d->lastOffset = d->offset = QPointF(); |
120 d->lastOffset = d->offset = QPointF(); |
118 d->lastPosition = QPoint(); |
121 d->startPosition = QPoint(); |
119 d->acceleration = 0; |
122 d->acceleration = 0; |
120 |
123 |
121 QGestureRecognizer::reset(state); |
124 QGestureRecognizer::reset(state); |
122 } |
125 } |
123 |
126 |
|
127 #endif // QT_NO_NATIVE_GESTURES |
|
128 |
124 QT_END_NAMESPACE |
129 QT_END_NAMESPACE |