summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qapplication.cpp
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-06-24 10:34:31 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-06-24 10:34:31 (GMT)
commitd3ce585a235e6a92b8a662c06f8686da977daa49 (patch)
tree92532e67293b2fde9ba44867ff4ffb1e966efaa3 /src/gui/kernel/qapplication.cpp
parentd8b81cad37e9477e609bbbedf0e666163bbbd813 (diff)
downloadQt-d3ce585a235e6a92b8a662c06f8686da977daa49.zip
Qt-d3ce585a235e6a92b8a662c06f8686da977daa49.tar.gz
Qt-d3ce585a235e6a92b8a662c06f8686da977daa49.tar.bz2
Add QTouchEvent::DeviceType and deviceType()
This enum indicates what kind of device generated the touch event (TouchScreen or TouchPad). We use this information to control how touch events are sent, specifically we restrict touch events to a single widget/QGraphicsItem on touch-pads, since there is no direct relationship between the physical touch location on the pad and the on- using the touch-pad).
Diffstat (limited to 'src/gui/kernel/qapplication.cpp')
-rw-r--r--src/gui/kernel/qapplication.cpp48
1 files changed, 32 insertions, 16 deletions
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp
index 9a22fd5..0b01b73 100644
--- a/src/gui/kernel/qapplication.cpp
+++ b/src/gui/kernel/qapplication.cpp
@@ -5296,6 +5296,7 @@ int QApplicationPrivate::findClosestTouchPointId(const QPointF &screenPos)
}
void QApplicationPrivate::translateRawTouchEvent(QWidget *window,
+ QTouchEvent::DeviceType deviceType,
const QList<QTouchEvent::TouchPoint> &touchPoints)
{
QApplicationPrivate *d = self;
@@ -5312,21 +5313,33 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window,
switch (touchPoint.state()) {
case Qt::TouchPointPressed:
{
- // determine which widget this event will go to
- if (!window)
- window = q->topLevelAt(touchPoint.screenPos().toPoint());
- if (!window)
- continue;
- widget = window->childAt(window->mapFromGlobal(touchPoint.screenPos().toPoint()));
- if (!widget)
- widget = window;
+ if (deviceType == QTouchEvent::TouchPad) {
+ // on touch-pads, send all touch points to the same widget
+ widget = d->widgetForTouchPointId.isEmpty()
+ ? 0
+ : d->widgetForTouchPointId.constBegin().value();
+ }
+
+ if (!widget) {
+ // determine which widget this event will go to
+ if (!window)
+ window = q->topLevelAt(touchPoint.screenPos().toPoint());
+ if (!window)
+ continue;
+ widget = window->childAt(window->mapFromGlobal(touchPoint.screenPos().toPoint()));
+ if (!widget)
+ widget = window;
+ }
- int closestTouchPointId = d->findClosestTouchPointId(touchPoint.screenPos());
- QWidget *closestWidget = d->widgetForTouchPointId.value(closestTouchPointId);
- if (closestWidget
- && (widget->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget))) {
- widget = closestWidget;
+ if (deviceType == QTouchEvent::TouchScreen) {
+ int closestTouchPointId = d->findClosestTouchPointId(touchPoint.screenPos());
+ QWidget *closestWidget = d->widgetForTouchPointId.value(closestTouchPointId);
+ if (closestWidget
+ && (widget->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget))) {
+ widget = closestWidget;
+ }
}
+
d->widgetForTouchPointId[touchPoint.id()] = widget;
touchPoint.setStartScreenPos(touchPoint.screenPos());
touchPoint.setLastScreenPos(touchPoint.screenPos());
@@ -5356,6 +5369,7 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window,
widget = d->widgetForTouchPointId.value(touchPoint.id());
if (!widget)
continue;
+
Q_ASSERT(d->appCurrentTouchPoints.contains(touchPoint.id()));
QTouchEvent::TouchPoint previousTouchPoint = d->appCurrentTouchPoints.value(touchPoint.id());
touchPoint.setStartScreenPos(previousTouchPoint.startScreenPos());
@@ -5408,6 +5422,7 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window,
}
QTouchEvent touchEvent(eventType,
+ deviceType,
q->keyboardModifiers(),
it.value().first,
it.value().second);
@@ -5433,10 +5448,11 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window,
}
}
-Q_GUI_EXPORT void qt_translateRawTouchEvent(const QList<QTouchEvent::TouchPoint> &touchPoints,
- QWidget *window)
+Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget *window,
+ QTouchEvent::DeviceType deviceType,
+ const QList<QTouchEvent::TouchPoint> &touchPoints)
{
- QApplicationPrivate::translateRawTouchEvent(window, touchPoints);
+ QApplicationPrivate::translateRawTouchEvent(window, deviceType, touchPoints);
}
QT_END_NAMESPACE