summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-06-03 12:29:24 +0200
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-06-03 12:29:24 +0200
commitb93e3a34402aadc9d313fe64e18d7373cd50612c (patch)
tree30c74be85c3ba869998ffb12cbdbf59c724ad46d
parentc8226762c4fe9ca4c98114a4bf6d88adc44bc2fb (diff)
Add support for touch point contact area
Add QTouchEvent::TouchPoint::area() and implement support for it on Windows
-rw-r--r--examples/multitouch/fingerpaint/scribblearea.cpp8
-rw-r--r--src/gui/kernel/qapplication_win.cpp7
-rw-r--r--src/gui/kernel/qevent.cpp14
-rw-r--r--src/gui/kernel/qevent.h3
-rw-r--r--src/gui/kernel/qevent_p.h1
5 files changed, 31 insertions, 2 deletions
diff --git a/examples/multitouch/fingerpaint/scribblearea.cpp b/examples/multitouch/fingerpaint/scribblearea.cpp
index a042fe7218..ffff9bb809 100644
--- a/examples/multitouch/fingerpaint/scribblearea.cpp
+++ b/examples/multitouch/fingerpaint/scribblearea.cpp
@@ -184,8 +184,12 @@ bool ScribbleArea::event(QEvent *event)
continue;
default:
{
- int diameter = int(50 * touchPoint->pressure());
- QRectF rectF(0, 0, diameter, diameter);
+ QSizeF area = touchPoint->area();
+ if (area.isEmpty()) {
+ qreal diameter = qreal(50) * touchPoint->pressure();
+ area = QSizeF(diameter, diameter);
+ }
+ QRectF rectF(QPointF(), area);
rectF.moveCenter(touchPoint->pos());
QRect rect = rectF.toRect();
diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp
index b2411b0c5e..d3bb6c295b 100644
--- a/src/gui/kernel/qapplication_win.cpp
+++ b/src/gui/kernel/qapplication_win.cpp
@@ -4029,17 +4029,23 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
// update state
bool down = touchPoint->state() != Qt::TouchPointReleased;
QPointF screenPos(qreal(touchInput.x) / qreal(100.), qreal(touchInput.y) / qreal(100.));
+ QSizeF contactArea = (touchInput.dwMask & TOUCHINPUTMASKF_CONTACTAREA)
+ ? QSizeF(qreal(touchInput.cxContact) / qreal(100.),
+ qreal(touchInput.cyContact) / qreal(100.))
+ : QSizeF();
if (!down && (touchInput.dwFlags & TOUCHEVENTF_DOWN)) {
touchPoint->setState(Qt::TouchPointPressed);
touchPoint->setScreenPos(screenPos);
touchPoint->setStartScreenPos(screenPos);
touchPoint->setLastScreenPos(screenPos);
+ touchPoint->setArea(contactArea);
touchPoint->setPressure(qreal(1.));
} else if (down && (touchInput.dwFlags & TOUCHEVENTF_UP)) {
touchPoint->setState(Qt::TouchPointReleased);
touchPoint->setLastScreenPos(touchPoint->screenPos());
touchPoint->setScreenPos(screenPos);
+ touchPoint->setArea(QSizeF());
touchPoint->setPressure(qreal(0.));
} else if (down) {
touchPoint->setState(screenPos == touchPoint->screenPos()
@@ -4047,6 +4053,7 @@ bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
: Qt::TouchPointMoved);
touchPoint->setLastScreenPos(touchPoint->screenPos());
touchPoint->setScreenPos(screenPos);
+ touchPoint->setArea(contactArea);
// pressure should still be 1.
}
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 7a4c424660..2692e82f3a 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -3900,6 +3900,20 @@ void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
}
/*!
+ Returns the area of this touch point.
+*/
+QSizeF QTouchEvent::TouchPoint::area() const
+{
+ return d->area;
+}
+
+/*! \internal */
+void QTouchEvent::TouchPoint::setArea(const QSizeF &area)
+{
+ d->area = area;
+}
+
+/*!
Returns the pressure of this touch point. The return value is in
the range 0.0 to 1.0.
*/
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index 0c7d10156a..f622126390 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -791,6 +791,9 @@ public:
QPointF lastScreenPos() const;
void setLastScreenPos(const QPointF &lastScreenPos);
+ QSizeF area() const;
+ void setArea(const QSizeF &area);
+
qreal pressure() const; // 0.0 -> 1.0
void setPressure(qreal pressure);
diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h
index dd78c3ee9b..37a0ee7e47 100644
--- a/src/gui/kernel/qevent_p.h
+++ b/src/gui/kernel/qevent_p.h
@@ -103,6 +103,7 @@ public:
QPointF pos, startPos, lastPos;
QPointF scenePos, startScenePos, lastScenePos;
QPointF screenPos, startScreenPos, lastScreenPos;
+ QSizeF area;
qreal pressure;
};