** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
-** This file is part of the QtDeclarative module of the Qt Toolkit.
+** This file is part of the QtQml module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
****************************************************************************/
#include "qquickmultipointtoucharea_p.h"
-#include <QtQuick/qquickcanvas.h>
+#include <QtQuick/qquickwindow.h>
+#include <private/qsgadaptationlayer_p.h>
+#include <private/qquickitem_p.h>
#include <QEvent>
#include <QMouseEvent>
#include <math.h>
QT_BEGIN_NAMESPACE
+DEFINE_BOOL_CONFIG_OPTION(qmlVisualTouchDebugging, QML_VISUAL_TOUCH_DEBUGGING)
+
/*!
\qmlclass TouchPoint QQuickTouchPoint
\inqmlmodule QtQuick 2
- \ingroup qml-event-elements
- \brief The TouchPoint element describes a touch point in a MultiPointTouchArea.
+ \ingroup qtquick-input-events
+ \brief Describes a touch point in a MultiPointTouchArea
- The TouchPoint element contains information about a touch point, such as the current
+ The TouchPoint type contains information about a touch point, such as the current
position, pressure, and area.
*/
/*!
\qmlproperty real QtQuick2::TouchPoint::pressure
+ \qmlproperty vector2d QtQuick2::TouchPoint::velocity
\qmlproperty rectangle QtQuick2::TouchPoint::area
These properties hold additional information about the current state of the touch point.
\list
- \i \c pressure is a value in the range of 0.0 to 1.0.
- \i \c area is a rectangle covering the area of the touch point, centered on the current position of the touch point.
+ \li \c pressure is a value in the range of 0.0 to 1.0.
+ \li \c velocity is a vector with magnitude reported in pixels per second.
+ \li \c area is a rectangle covering the area of the touch point, centered on the current position of the touch point.
\endlist
+
+ Not all touch devices support velocity. If velocity is not supported, it will be reported
+ as 0,0.
*/
void QQuickTouchPoint::setPressure(qreal pressure)
{
emit pressureChanged();
}
+void QQuickTouchPoint::setVelocity(const QVector2D &velocity)
+{
+ if (_velocity == velocity)
+ return;
+ _velocity = velocity;
+ emit velocityChanged();
+}
+
void QQuickTouchPoint::setArea(const QRectF &area)
{
if (_area == area)
/*!
\qmlclass MultiPointTouchArea QQuickMultiPointTouchArea
\inqmlmodule QtQuick 2
- \brief The MultiPointTouchArea item enables handling of multiple touch points.
\inherits Item
+ \ingroup qtquick-input
+ \brief Enables handling of multiple touch points
+
A MultiPointTouchArea is an invisible item that is used to track multiple touch points.
MultiPointTouchArea can be used in two ways:
\list
- \o setting \c touchPoints to provide touch point objects with properties that can be bound to
- \o using the onTouchUpdated or onTouchPointsPressed, onTouchPointsUpdated and onTouchPointsReleased handlers
+ \li setting \c touchPoints to provide touch point objects with properties that can be bound to
+ \li using the onTouchUpdated or onPressed, onUpdated and onReleased handlers
\endlist
- While a MultiPointTouchArea \i can take exclusive ownership of certain touch points, it is also possible to have
+ While a MultiPointTouchArea \e can take exclusive ownership of certain touch points, it is also possible to have
multiple MultiPointTouchAreas active at the same time, each operating on a different set of touch points.
\sa TouchPoint
/*!
\qmlsignal QtQuick2::MultiPointTouchArea::onCanceled(list<TouchPoint> touchPoints)
- This handler is called when new touch events have been canceled because another element stole the touch event handling.
+ This handler is called when new touch events have been canceled because another item stole the touch event handling.
This signal is for advanced use: it is useful when there is more than one MultiPointTouchArea
that is handling input, or when there is a MultiPointTouchArea inside a \l Flickable. In the latter
This handler is called when the global drag threshold has been reached.
This function is typically used when a MultiPointTouchAreas has been nested in a Flickable or another MultiPointTouchArea.
- Wnen the threshold has been reached, and the handler called, you can determine whether or not the touch
+ When the threshold has been reached, and the handler called, you can determine whether or not the touch
area should grab the current touch points. By default they will not be grabbed; to grab them call \c gesture.grab(). If the
gesture is not grabbed, the nesting Flickable, for example, would also have an opportunity to grab.
In the following example, we have two small rectangles that follow our touch points.
- \snippet doc/src/snippets/declarative/multipointtoucharea/multipointtoucharea.qml 0
+ \snippet qml/multipointtoucharea/multipointtoucharea.qml 0
By default this property holds an empty list.
{
setAcceptedMouseButtons(Qt::LeftButton);
setFiltersChildMouseEvents(true);
+ if (qmlVisualTouchDebugging()) {
+ setFlag(QQuickItem::ItemHasContents);
+ }
}
QQuickMultiPointTouchArea::~QQuickMultiPointTouchArea()
case QEvent::TouchUpdate:
case QEvent::TouchEnd: {
//if e.g. a parent Flickable has the mouse grab, don't process the touch events
- QQuickCanvas *c = canvas();
+ QQuickWindow *c = window();
QQuickItem *grabber = c ? c->mouseGrabberItem() : 0;
if (grabber && grabber != this && grabber->keepMouseGrab() && grabber->isEnabled()) {
QQuickItem *item = this;
}
updateTouchData(event);
if (event->type() == QEvent::TouchEnd) {
- //TODO: move to canvas
+ //TODO: move to window
_stealMouse = false;
setKeepMouseGrab(false);
- QQuickCanvas *c = canvas();
- if (c && c->mouseGrabberItem() == this)
- ungrabMouse();
setKeepTouchGrab(false);
ungrabTouchPoints();
}
grabMouse();
setKeepMouseGrab(true);
- grabTouchPoints(_touchPoints.keys());
+ grabTouchPoints(_touchPoints.keys().toVector());
setKeepTouchGrab(true);
}
}
}
- if (ended) {
+ if (ended)
emit released(_releasedTouchPoints);
- emit touchPointsReleased(_releasedTouchPoints);
- }
- if (moved) {
+ if (moved)
emit updated(_movedTouchPoints);
- emit touchPointsUpdated(_movedTouchPoints);
- }
- if (started) {
+ if (started)
emit pressed(_pressedTouchPoints);
- emit touchPointsPressed(_pressedTouchPoints);
- }
if (ended || moved || started) emit touchUpdated(_touchPoints.values());
}
}
dtp->setX(p->pos().x());
dtp->setY(p->pos().y());
dtp->setPressure(p->pressure());
+ dtp->setVelocity(p->velocity());
dtp->setArea(p->rect());
dtp->setStartX(p->startPos().x());
dtp->setStartY(p->startPos().y());
QQuickItem::mouseReleaseEvent(event);
return;
}
- QQuickCanvas *c = canvas();
+ QQuickWindow *c = window();
if (c && c->mouseGrabberItem() == this)
ungrabMouse();
setKeepMouseGrab(false);
void QQuickMultiPointTouchArea::ungrab()
{
if (_touchPoints.count()) {
- QQuickCanvas *c = canvas();
+ QQuickWindow *c = window();
if (c && c->mouseGrabberItem() == this) {
_stealMouse = false;
setKeepMouseGrab(false);
foreach (QObject *obj, _touchPoints)
static_cast<QQuickTouchPoint*>(obj)->setPressed(false);
emit canceled(_touchPoints.values());
- emit touchPointsCanceled(_touchPoints.values());
clearTouchLists();
foreach (QObject *obj, _touchPoints) {
QQuickTouchPoint *dtp = static_cast<QQuickTouchPoint*>(obj);
bool QQuickMultiPointTouchArea::sendMouseEvent(QMouseEvent *event)
{
- QRectF myRect = mapRectToScene(QRectF(0, 0, width(), height()));
+ QPointF localPos = mapFromScene(event->windowPos());
- QQuickCanvas *c = canvas();
+ QQuickWindow *c = window();
QQuickItem *grabber = c ? c->mouseGrabberItem() : 0;
bool stealThisEvent = _stealMouse;
- if ((stealThisEvent || myRect.contains(event->windowPos())) && (!grabber || !grabber->keepMouseGrab())) {
- QMouseEvent mouseEvent(event->type(), mapFromScene(event->windowPos()), event->windowPos(), event->screenPos(),
+ if ((stealThisEvent || contains(localPos)) && (!grabber || !grabber->keepMouseGrab())) {
+ QMouseEvent mouseEvent(event->type(), localPos, event->windowPos(), event->screenPos(),
event->button(), event->buttons(), event->modifiers());
mouseEvent.setAccepted(false);
//TODO: verify this behavior
_stealMouse = false;
setKeepMouseGrab(false);
- QQuickCanvas *c = canvas();
- if (c && c->mouseGrabberItem() == this)
- ungrabMouse();
setKeepTouchGrab(false);
ungrabTouchPoints();
}
bool QQuickMultiPointTouchArea::shouldFilter(QEvent *event)
{
- QQuickCanvas *c = canvas();
+ QQuickWindow *c = window();
QQuickItem *grabber = c ? c->mouseGrabberItem() : 0;
bool disabledItem = grabber && !grabber->isEnabled();
bool stealThisEvent = _stealMouse;
- bool contains = false;
+ bool containsPoint = false;
if (!stealThisEvent) {
switch (event->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseMove:
case QEvent::MouseButtonRelease: {
QMouseEvent *me = static_cast<QMouseEvent*>(event);
- QRectF myRect = mapRectToScene(QRectF(0, 0, width(), height()));
- contains = myRect.contains(me->windowPos());
+ containsPoint = contains(mapFromScene(me->windowPos()));
}
break;
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd: {
QTouchEvent *te = static_cast<QTouchEvent*>(event);
- QRectF myRect = mapRectToScene(QRectF(0, 0, width(), height()));
foreach (const QTouchEvent::TouchPoint &point, te->touchPoints()) {
- if (myRect.contains(point.scenePos())) {
- contains = true;
+ if (contains(mapFromScene(point.scenePos()))) {
+ containsPoint = true;
break;
}
}
break;
}
}
- if ((stealThisEvent || contains) && (!grabber || !grabber->keepMouseGrab() || disabledItem)) {
+ if ((stealThisEvent || containsPoint) && (!grabber || !grabber->keepMouseGrab() || disabledItem)) {
return true;
}
ungrab();
return false;
}
+QSGNode *QQuickMultiPointTouchArea::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
+{
+ Q_UNUSED(data);
+
+ if (!qmlVisualTouchDebugging())
+ return 0;
+
+ QSGRectangleNode *rectangle = static_cast<QSGRectangleNode *>(oldNode);
+ if (!rectangle) rectangle = QQuickItemPrivate::get(this)->sceneGraphContext()->createRectangleNode();
+
+ rectangle->setRect(QRectF(0, 0, width(), height()));
+ rectangle->setColor(QColor(255, 0, 0, 50));
+ rectangle->update();
+ return rectangle;
+}
+
QT_END_NAMESPACE