aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/gestures
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit885735d011472bcfbb96e688d9e64553d7fe9d4b (patch)
tree734963625eba643bf11bc4870a4c407809a6400a /src/imports/gestures
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'src/imports/gestures')
-rw-r--r--src/imports/gestures/gestures.pro26
-rw-r--r--src/imports/gestures/plugin.cpp73
-rw-r--r--src/imports/gestures/qdeclarativegesturearea.cpp282
-rw-r--r--src/imports/gestures/qdeclarativegesturearea_p.h104
-rw-r--r--src/imports/gestures/qmldir1
5 files changed, 486 insertions, 0 deletions
diff --git a/src/imports/gestures/gestures.pro b/src/imports/gestures/gestures.pro
new file mode 100644
index 0000000000..ad872bae3f
--- /dev/null
+++ b/src/imports/gestures/gestures.pro
@@ -0,0 +1,26 @@
+TARGET = qmlgesturesplugin
+TARGETPATH = Qt/labs/gestures
+include(../qimportbase.pri)
+
+QT += declarative
+
+SOURCES += qdeclarativegesturearea.cpp plugin.cpp
+HEADERS += qdeclarativegesturearea_p.h
+
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/$$TARGETPATH
+target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+qmldir.files += $$PWD/qmldir
+qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+symbian:{
+ TARGET.UID3 = 0x2002131F
+
+ isEmpty(DESTDIR):importFiles.files = qmlgesturesplugin$${QT_LIBINFIX}.dll qmldir
+ else:importFiles.files = $$DESTDIR/qmlgesturesplugin$${QT_LIBINFIX}.dll qmldir
+ importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH
+
+ DEPLOYMENT = importFiles
+}
+
+INSTALLS += target qmldir
diff --git a/src/imports/gestures/plugin.cpp b/src/imports/gestures/plugin.cpp
new file mode 100644
index 0000000000..9ebfb9bd70
--- /dev/null
+++ b/src/imports/gestures/plugin.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtDeclarative/qdeclarativeextensionplugin.h>
+#include <QtDeclarative/qdeclarative.h>
+
+#include "qdeclarativegesturearea_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class GestureAreaQmlPlugin : public QDeclarativeExtensionPlugin
+{
+ Q_OBJECT
+public:
+ virtual void registerTypes(const char *uri)
+ {
+ Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.gestures"));
+#ifndef QT_NO_GESTURES
+ qmlRegisterCustomType<QDeclarativeGestureArea>(uri,1,0, "GestureArea", new QDeclarativeGestureAreaParser);
+
+ qmlRegisterUncreatableType<QGesture>(uri, 1, 0, "Gesture", QLatin1String("Do not create objects of this type."));
+ qmlRegisterUncreatableType<QPanGesture>(uri, 1, 0, "PanGesture", QLatin1String("Do not create objects of this type."));
+ qmlRegisterUncreatableType<QTapGesture>(uri, 1, 0, "TapGesture", QLatin1String("Do not create objects of this type."));
+ qmlRegisterUncreatableType<QTapAndHoldGesture>(uri, 1, 0, "TapAndHoldGesture", QLatin1String("Do not create objects of this type."));
+ qmlRegisterUncreatableType<QPinchGesture>(uri, 1, 0, "PinchGesture", QLatin1String("Do not create objects of this type."));
+ qmlRegisterUncreatableType<QSwipeGesture>(uri, 1, 0, "SwipeGesture", QLatin1String("Do not create objects of this type."));
+#endif
+ }
+};
+
+QT_END_NAMESPACE
+
+#include "plugin.moc"
+
+Q_EXPORT_PLUGIN2(qmlgesturesplugin, QT_PREPEND_NAMESPACE(GestureAreaQmlPlugin));
diff --git a/src/imports/gestures/qdeclarativegesturearea.cpp b/src/imports/gestures/qdeclarativegesturearea.cpp
new file mode 100644
index 0000000000..aae6a010f1
--- /dev/null
+++ b/src/imports/gestures/qdeclarativegesturearea.cpp
@@ -0,0 +1,282 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativegesturearea_p.h"
+
+#include <qdeclarativeexpression.h>
+#include <qdeclarativecontext.h>
+#include <qdeclarativeinfo.h>
+
+#include <private/qdeclarativeproperty_p.h>
+#include <private/qdeclarativeitem_p.h>
+
+#include <QtCore/qdebug.h>
+#include <QtCore/qstringlist.h>
+
+#include <QtGui/qevent.h>
+
+#include <private/qobject_p.h>
+
+#ifndef QT_NO_GESTURES
+
+QT_BEGIN_NAMESPACE
+
+class QDeclarativeGestureAreaPrivate : public QDeclarativeItemPrivate
+{
+ Q_DECLARE_PUBLIC(QDeclarativeGestureArea)
+public:
+ QDeclarativeGestureAreaPrivate() : componentcomplete(false), gesture(0) {}
+
+ typedef QMap<Qt::GestureType,QDeclarativeExpression*> Bindings;
+ Bindings bindings;
+
+ bool componentcomplete;
+
+ QByteArray data;
+
+ QGesture *gesture;
+
+ bool gestureEvent(QGestureEvent *event);
+};
+
+/*!
+ \qmlclass GestureArea QDeclarativeGestureArea
+ \ingroup qml-basic-interaction-elements
+
+ \brief The GestureArea item enables simple gesture handling.
+ \inherits Item
+
+ A GestureArea is like a MouseArea, but it has signals for gesture events.
+
+ \warning Elements in the Qt.labs module are not guaranteed to remain compatible
+ in future versions.
+
+ \warning GestureArea is an experimental element whose development has
+ been discontinued. PinchArea is available in QtQuick 1.1 and handles
+ two finger gesture input.
+
+ \note This element is only functional on devices with touch input.
+
+ \qml
+ import Qt.labs.gestures 1.0
+
+ GestureArea {
+ anchors.fill: parent
+ // onPan: ... gesture.acceleration ...
+ // onPinch: ... gesture.rotationAngle ...
+ // onSwipe: ...
+ // onTapAndHold: ...
+ // onTap: ...
+ // onGesture: ...
+ }
+ \endqml
+
+ Each signal has a \e gesture parameter that has the
+ properties of the gesture.
+
+ \table
+ \header \o Signal \o Type \o Property \o Description
+ \row \o onTap \o point \o position \o the position of the tap
+ \row \o onTapAndHold \o point \o position \o the position of the tap
+ \row \o onPan \o real \o acceleration \o the acceleration of the pan
+ \row \o onPan \o point \o delta \o the offset from the previous input position to the current input
+ \row \o onPan \o point \o offset \o the total offset from the first input position to the current input position
+ \row \o onPan \o point \o lastOffset \o the previous value of offset
+ \row \o onPinch \o point \o centerPoint \o the midpoint between the two input points
+ \row \o onPinch \o point \o lastCenterPoint \o the previous value of centerPoint
+ \row \o onPinch \o point \o startCenterPoint \o the first value of centerPoint
+ \row \o onPinch \o real \o rotationAngle \o the angle covered by the gesture motion
+ \row \o onPinch \o real \o lastRotationAngle \o the previous value of rotationAngle
+ \row \o onPinch \o real \o totalRotationAngle \o the complete angle covered by the gesture
+ \row \o onPinch \o real \o scaleFactor \o the change in distance between the two input points
+ \row \o onPinch \o real \o lastScaleFactor \o the previous value of scaleFactor
+ \row \o onPinch \o real \o totalScaleFactor \o the complete scale factor of the gesture
+ \row \o onSwipe \o real \o swipeAngle \o the angle of the swipe
+ \endtable
+
+ Custom gestures, handled by onGesture, will have custom properties.
+
+ GestureArea is an invisible item: it is never painted.
+
+ \sa MouseArea
+*/
+
+/*!
+ \internal
+ \class QDeclarativeGestureArea
+ \brief The QDeclarativeGestureArea class provides simple gesture handling.
+
+*/
+QDeclarativeGestureArea::QDeclarativeGestureArea(QDeclarativeItem *parent) :
+ QDeclarativeItem(*(new QDeclarativeGestureAreaPrivate), parent)
+{
+ setAcceptedMouseButtons(Qt::LeftButton);
+ setAcceptTouchEvents(true);
+}
+
+QDeclarativeGestureArea::~QDeclarativeGestureArea()
+{
+}
+
+QByteArray
+QDeclarativeGestureAreaParser::compile(const QList<QDeclarativeCustomParserProperty> &props)
+{
+ QByteArray rv;
+ QDataStream ds(&rv, QIODevice::WriteOnly);
+
+ for(int ii = 0; ii < props.count(); ++ii)
+ {
+ QString propName = QString::fromUtf8(props.at(ii).name());
+ Qt::GestureType type;
+
+ if (propName == QLatin1String("onTap")) {
+ type = Qt::TapGesture;
+ } else if (propName == QLatin1String("onTapAndHold")) {
+ type = Qt::TapAndHoldGesture;
+ } else if (propName == QLatin1String("onPan")) {
+ type = Qt::PanGesture;
+ } else if (propName == QLatin1String("onPinch")) {
+ type = Qt::PinchGesture;
+ } else if (propName == QLatin1String("onSwipe")) {
+ type = Qt::SwipeGesture;
+ } else if (propName == QLatin1String("onGesture")) {
+ type = Qt::CustomGesture;
+ } else {
+ error(props.at(ii), QDeclarativeGestureArea::tr("Cannot assign to non-existent property \"%1\"").arg(propName));
+ return QByteArray();
+ }
+
+ QList<QVariant> values = props.at(ii).assignedValues();
+
+ for (int i = 0; i < values.count(); ++i) {
+ const QVariant &value = values.at(i);
+
+ if (value.userType() == qMetaTypeId<QDeclarativeCustomParserNode>()) {
+ error(props.at(ii), QDeclarativeGestureArea::tr("GestureArea: nested objects not allowed"));
+ return QByteArray();
+ } else if (value.userType() == qMetaTypeId<QDeclarativeCustomParserProperty>()) {
+ error(props.at(ii), QDeclarativeGestureArea::tr("GestureArea: syntax error"));
+ return QByteArray();
+ } else {
+ QDeclarativeParser::Variant v = qvariant_cast<QDeclarativeParser::Variant>(value);
+ if (v.isScript()) {
+ ds << propName;
+ ds << int(type);
+ ds << v.asScript();
+ } else {
+ error(props.at(ii), QDeclarativeGestureArea::tr("GestureArea: script expected"));
+ return QByteArray();
+ }
+ }
+ }
+ }
+
+ return rv;
+}
+
+void QDeclarativeGestureAreaParser::setCustomData(QObject *object,
+ const QByteArray &data)
+{
+ QDeclarativeGestureArea *ga = static_cast<QDeclarativeGestureArea*>(object);
+ ga->d_func()->data = data;
+}
+
+
+void QDeclarativeGestureArea::connectSignals()
+{
+ Q_D(QDeclarativeGestureArea);
+ if (!d->componentcomplete)
+ return;
+
+ QDataStream ds(d->data);
+ while (!ds.atEnd()) {
+ QString propName;
+ ds >> propName;
+ int gesturetype;
+ ds >> gesturetype;
+ QString script;
+ ds >> script;
+ QDeclarativeExpression *exp = new QDeclarativeExpression(qmlContext(this), this, script);
+ d->bindings.insert(Qt::GestureType(gesturetype),exp);
+ grabGesture(Qt::GestureType(gesturetype));
+ }
+}
+
+void QDeclarativeGestureArea::componentComplete()
+{
+ QDeclarativeItem::componentComplete();
+ Q_D(QDeclarativeGestureArea);
+ d->componentcomplete=true;
+ connectSignals();
+}
+
+QGesture *QDeclarativeGestureArea::gesture() const
+{
+ Q_D(const QDeclarativeGestureArea);
+ return d->gesture;
+}
+
+bool QDeclarativeGestureArea::sceneEvent(QEvent *event)
+{
+ Q_D(QDeclarativeGestureArea);
+ if (event->type() == QEvent::Gesture)
+ return d->gestureEvent(static_cast<QGestureEvent*>(event));
+ return QDeclarativeItem::sceneEvent(event);
+}
+
+bool QDeclarativeGestureAreaPrivate::gestureEvent(QGestureEvent *event)
+{
+ bool accept = true;
+ for (Bindings::Iterator it = bindings.begin(); it != bindings.end(); ++it) {
+ if ((gesture = event->gesture(it.key()))) {
+ QDeclarativeExpression *expr = it.value();
+ expr->evaluate();
+ if (expr->hasError())
+ qmlInfo(q_func()) << expr->error();
+ event->setAccepted(true); // XXX only if value returns true?
+ }
+ }
+ return accept;
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_GESTURES
diff --git a/src/imports/gestures/qdeclarativegesturearea_p.h b/src/imports/gestures/qdeclarativegesturearea_p.h
new file mode 100644
index 0000000000..01306045bb
--- /dev/null
+++ b/src/imports/gestures/qdeclarativegesturearea_p.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVEGESTUREAREA_H
+#define QDECLARATIVEGESTUREAREA_H
+
+#include <qdeclarativeitem.h>
+#include <qdeclarativescriptstring.h>
+#include <private/qdeclarativecustomparser_p.h>
+
+#include <QtCore/qobject.h>
+#include <QtCore/qstring.h>
+#include <QtGui/qgesture.h>
+
+#ifndef QT_NO_GESTURES
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QDeclarativeBoundSignal;
+class QDeclarativeContext;
+class QDeclarativeGestureAreaPrivate;
+class QDeclarativeGestureArea : public QDeclarativeItem
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QGesture *gesture READ gesture)
+
+public:
+ QDeclarativeGestureArea(QDeclarativeItem *parent=0);
+ ~QDeclarativeGestureArea();
+
+ QGesture *gesture() const;
+
+protected:
+ bool sceneEvent(QEvent *event);
+
+private:
+ void connectSignals();
+ void componentComplete();
+ friend class QDeclarativeGestureAreaParser;
+
+ Q_DISABLE_COPY(QDeclarativeGestureArea)
+ Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeGestureArea)
+};
+
+class QDeclarativeGestureAreaParser : public QDeclarativeCustomParser
+{
+public:
+ virtual QByteArray compile(const QList<QDeclarativeCustomParserProperty> &);
+ virtual void setCustomData(QObject *, const QByteArray &);
+};
+
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QDeclarativeGestureArea)
+
+QT_END_HEADER
+
+#endif // QT_NO_GESTURES
+
+#endif
diff --git a/src/imports/gestures/qmldir b/src/imports/gestures/qmldir
new file mode 100644
index 0000000000..2a31920a40
--- /dev/null
+++ b/src/imports/gestures/qmldir
@@ -0,0 +1 @@
+plugin qmlgesturesplugin