summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-05-27 15:22:31 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-05-27 15:22:31 (GMT)
commit20fa050643f72b4bc91386c5fff62cdfe3b75393 (patch)
treefe0bdefb2007b79739b5e0de01bebee08ee5c8c0 /src/gui/kernel
parent8598ffab46a500b9077d437ffc72d0e6fc843712 (diff)
downloadQt-20fa050643f72b4bc91386c5fff62cdfe3b75393.zip
Qt-20fa050643f72b4bc91386c5fff62cdfe3b75393.tar.gz
Qt-20fa050643f72b4bc91386c5fff62cdfe3b75393.tar.bz2
Make Qt::TouchPointState ORable, add Q*TouchEvent::touchPointStates()
This new function returns a bitwise OR of all the touch point states for the event. This makes it easy to see if a certain type of state is present or not without the need to loop over all touch points. QApplication and QGraphicsScene need to build this state when dispatching the touch points. This also fixes the ASSERT bug that Denis found when trying to send multiple touch presses in a touch begin event.
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qapplication_p.h8
-rw-r--r--src/gui/kernel/qapplication_win.cpp59
-rw-r--r--src/gui/kernel/qevent.cpp17
-rw-r--r--src/gui/kernel/qevent.h16
4 files changed, 69 insertions, 31 deletions
diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h
index 08020fb..34395c9 100644
--- a/src/gui/kernel/qapplication_p.h
+++ b/src/gui/kernel/qapplication_p.h
@@ -450,10 +450,10 @@ public:
void initializeMultitouch();
static QTouchEvent::TouchPoint *findClosestTouchPoint(const QList<QTouchEvent::TouchPoint *> &activeTouchPoints,
const QPointF &screenPos);
- QEvent::Type appendTouchPoint(QTouchEvent::TouchPoint *touchPoint,
- QList<QTouchEvent::TouchPoint *> *currentTouchPoints);
- QEvent::Type removeTouchPoint(QTouchEvent::TouchPoint *touchPoint,
- QList<QTouchEvent::TouchPoint *> *currentTouchPoints);
+ void appendTouchPoint(QTouchEvent::TouchPoint *touchPoint,
+ QList<QTouchEvent::TouchPoint *> *currentTouchPoints);
+ void removeTouchPoint(QTouchEvent::TouchPoint *touchPoint,
+ QList<QTouchEvent::TouchPoint *> *currentTouchPoints);
bool translateTouchEvent(const MSG &msg);
#endif
diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp
index 148988f..0fc76ae 100644
--- a/src/gui/kernel/qapplication_win.cpp
+++ b/src/gui/kernel/qapplication_win.cpp
@@ -4011,13 +4011,9 @@ QTouchEvent::TouchPoint *QApplicationPrivate::findClosestTouchPoint(const QList<
return closestTouchPoint;
}
-QEvent::Type QApplicationPrivate::appendTouchPoint(QTouchEvent::TouchPoint *touchPoint,
- QList<QTouchEvent::TouchPoint *> *currentTouchPoints)
+void QApplicationPrivate::appendTouchPoint(QTouchEvent::TouchPoint *touchPoint,
+ QList<QTouchEvent::TouchPoint *> *currentTouchPoints)
{
- QEvent::Type eventType = currentTouchPoints->isEmpty()
- ? QEvent::TouchBegin
- : QEvent::TouchUpdate;
-
// insort touch point (for the app)
int at = 0;
for (; at < appCurrentTouchPoints.count(); ++at) {
@@ -4037,12 +4033,10 @@ QEvent::Type QApplicationPrivate::appendTouchPoint(QTouchEvent::TouchPoint *touc
appCurrentTouchPoints.count(),
appAllTouchPoints.count());
}
-
- return eventType;
}
-QEvent::Type QApplicationPrivate::removeTouchPoint(QTouchEvent::TouchPoint *touchPoint,
- QList<QTouchEvent::TouchPoint *> *currentTouchPoints)
+void QApplicationPrivate::removeTouchPoint(QTouchEvent::TouchPoint *touchPoint,
+ QList<QTouchEvent::TouchPoint *> *currentTouchPoints)
{
// remove touch point from all known touch points
for (int i = qMin(appCurrentTouchPoints.count() - 1, touchPoint->id()); i >= 0; --i) {
@@ -4058,8 +4052,6 @@ QEvent::Type QApplicationPrivate::removeTouchPoint(QTouchEvent::TouchPoint *touc
break;
}
}
-
- return currentTouchPoints->isEmpty() ? QEvent::TouchEnd : QEvent::TouchUpdate;
}
bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
@@ -4072,7 +4064,8 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
QList<QTouchEvent::TouchPoint *> appActiveTouchPoints = appCurrentTouchPoints;
- QHash<QWidget *, QTouchEvent> widgetsNeedingEvents;
+ typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint *> > StatesAndTouchPoints;
+ QHash<QWidget *, StatesAndTouchPoints> widgetsNeedingEvents;
QVector<TOUCHINPUT> winTouchInputs(msg.wParam);
memset(winTouchInputs.data(), 0, sizeof(TOUCHINPUT) * winTouchInputs.count());
QApplicationPrivate::GetTouchInputInfo((HANDLE) msg.lParam, msg.wParam, winTouchInputs.data(), sizeof(TOUCHINPUT));
@@ -4096,7 +4089,6 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
QWidget *widget = 0;
bool down = touchPoint->state() != Qt::TouchPointReleased;
QPointF screenPos(qreal(touchInput.x) / qreal(100.), qreal(touchInput.y) / qreal(100.));
- QEvent::Type eventType = QEvent::None;
QList<QTouchEvent::TouchPoint *> activeTouchPoints;
if (!down && (touchInput.dwFlags & TOUCHEVENTF_DOWN)) {
@@ -4116,7 +4108,7 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
widgetForTouchPointId[touchPoint->id()] = widget;
QList<QTouchEvent::TouchPoint *> &currentTouchPoints = widgetCurrentTouchPoints[widget];
- eventType = appendTouchPoint(touchPoint, &currentTouchPoints);
+ appendTouchPoint(touchPoint, &currentTouchPoints);
// make sure new points are added to activeTouchPoints as well
appActiveTouchPoints = appCurrentTouchPoints;
activeTouchPoints = currentTouchPoints;
@@ -4131,7 +4123,7 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
QList<QTouchEvent::TouchPoint *> &currentTouchPoints = widgetCurrentTouchPoints[widget];
appActiveTouchPoints = appCurrentTouchPoints;
activeTouchPoints = currentTouchPoints;
- eventType = removeTouchPoint(touchPoint, &currentTouchPoints);
+ removeTouchPoint(touchPoint, &currentTouchPoints);
touchPoint->setState(Qt::TouchPointReleased);
touchPoint->setLastScreenPos(touchPoint->screenPos());
@@ -4141,7 +4133,6 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
widget = widgetForTouchPointId.value(touchPoint->id());
appActiveTouchPoints = appCurrentTouchPoints;
activeTouchPoints = widgetCurrentTouchPoints.value(widget);
- eventType = QEvent::TouchUpdate;
touchPoint->setState(screenPos == touchPoint->screenPos()
? Qt::TouchPointStationary
: Qt::TouchPointMoved);
@@ -4149,12 +4140,11 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
touchPoint->setScreenPos(screenPos);
// pressure should still be 1.
}
- Q_ASSERT(widget != 0 && eventType != QEvent::None);
+ Q_ASSERT(widget != 0);
- if (touchPoint->state() != Qt::TouchPointStationary) {
- widgetsNeedingEvents.insert(widget,
- QTouchEvent(eventType, q->keyboardModifiers(), activeTouchPoints));
- }
+ StatesAndTouchPoints &maskAndPoints = widgetsNeedingEvents[widget];
+ maskAndPoints.first |= touchPoint->state();
+ maskAndPoints.second = activeTouchPoints;
}
QApplicationPrivate::CloseTouchInputHandle((HANDLE) msg.lParam);
@@ -4164,14 +4154,33 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
bool returnValue = false;
qt_tabletChokeMouse = false;
- QHash<QWidget *, QTouchEvent>::ConstIterator it = widgetsNeedingEvents.constBegin();
- const QHash<QWidget *, QTouchEvent>::ConstIterator end = widgetsNeedingEvents.constEnd();
+ QHash<QWidget *, StatesAndTouchPoints>::ConstIterator it = widgetsNeedingEvents.constBegin();
+ const QHash<QWidget *, StatesAndTouchPoints>::ConstIterator end = widgetsNeedingEvents.constEnd();
for (; it != end; ++it) {
QWidget *widget = it.key();
if (!QApplicationPrivate::tryModalHelper(widget, 0))
continue;
- QTouchEvent touchEvent = it.value();
+ QEvent::Type eventType;
+ switch(it.value().first) {
+ case Qt::TouchPointPressed:
+ eventType = QEvent::TouchBegin;
+ break;
+ case Qt::TouchPointReleased:
+ eventType = QEvent::TouchEnd;
+ break;
+ case Qt::TouchPointStationary:
+ // don't send the event if nothing changed
+ continue;
+ default:
+ eventType = QEvent::TouchUpdate;
+ break;
+ }
+
+ QTouchEvent touchEvent(eventType,
+ q->keyboardModifiers(),
+ it.value().first,
+ it.value().second);
updateTouchPointsForWidget(widget, &touchEvent);
switch (touchEvent.type()) {
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 419107c..7a4c424 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -3727,8 +3727,11 @@ void QGestureEvent::accept(const QString &type)
*/
QTouchEvent::QTouchEvent(QEvent::Type type,
Qt::KeyboardModifiers modifiers,
+ Qt::TouchPointStates touchPointStates,
const QList<QTouchEvent::TouchPoint *> &touchPoints)
- : QInputEvent(type, modifiers), _touchPoints(touchPoints)
+ : QInputEvent(type, modifiers),
+ _touchPointStates(touchPointStates),
+ _touchPoints(touchPoints)
{ }
/*!
@@ -3737,6 +3740,18 @@ QTouchEvent::QTouchEvent(QEvent::Type type,
QTouchEvent::~QTouchEvent()
{ }
+/*! \fn Qt::TouchPointStates QTouchEvent::touchPointStates() const
+
+ Returns a bitwise OR of all the touch point states for this event.
+*/
+
+/*! \fn void QTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates)
+
+ \internal
+
+ Sets a bitwise OR of all the touch point states for this event.
+*/
+
/*! \fn const QList<QTouchEvent::TouchPoint *> &QTouchEvent::TouchPoints() const
Returns the list of touch points contained in the touch event.
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index 75cfb9d..0c7d101 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -800,16 +800,30 @@ public:
QTouchEvent(QEvent::Type type,
Qt::KeyboardModifiers modifiers,
+ Qt::TouchPointStates touchPointStates,
const QList<QTouchEvent::TouchPoint *> &touchPoints);
~QTouchEvent();
- inline const QList<QTouchEvent::TouchPoint *> &touchPoints() const { return _touchPoints; }
+ inline Qt::TouchPointStates touchPointStates() const
+ {
+ return _touchPointStates;
+ }
+ inline void setTouchPointStates(Qt::TouchPointStates touchPointStates)
+ {
+ _touchPointStates = touchPointStates;
+ }
+
+ inline const QList<QTouchEvent::TouchPoint *> &touchPoints() const
+ {
+ return _touchPoints;
+ }
inline void setTouchPoints(const QList<QTouchEvent::TouchPoint *> &touchPoints)
{
_touchPoints = touchPoints;
}
protected:
+ Qt::TouchPointStates _touchPointStates;
QList<QTouchEvent::TouchPoint *> _touchPoints;
};