summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-08-04 22:30:28 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-08-04 22:30:28 (GMT)
commit40db84c97769141f3f2351de1b2d5c64904fe5c2 (patch)
treef674a92a37a130e1ce0bfd7080019fe3b36e9c1b /examples
parent897014a47b41dcf2b9d91549be9b96890d5291c7 (diff)
parent2843c97f5310f4636c933ced56570ab7db2b707e (diff)
downloadQt-40db84c97769141f3f2351de1b2d5c64904fe5c2.zip
Qt-40db84c97769141f3f2351de1b2d5c64904fe5c2.tar.gz
Qt-40db84c97769141f3f2351de1b2d5c64904fe5c2.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Diffstat (limited to 'examples')
-rw-r--r--examples/gestures/imageviewer/imageviewer.pro11
-rw-r--r--examples/gestures/imageviewer/imagewidget.cpp39
-rw-r--r--examples/gestures/imageviewer/imagewidget.h4
-rw-r--r--examples/gestures/imageviewer/tapandholdgesture.cpp138
-rw-r--r--examples/gestures/imageviewer/tapandholdgesture.h73
5 files changed, 237 insertions, 28 deletions
diff --git a/examples/gestures/imageviewer/imageviewer.pro b/examples/gestures/imageviewer/imageviewer.pro
index 4c35dce..efbca00 100644
--- a/examples/gestures/imageviewer/imageviewer.pro
+++ b/examples/gestures/imageviewer/imageviewer.pro
@@ -1,12 +1,11 @@
-######################################################################
-# Automatically generated by qmake (2.01a) Thu Sep 11 17:18:17 2008
-######################################################################
-
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
-HEADERS += imagewidget.h
-SOURCES += imagewidget.cpp main.cpp
+HEADERS += imagewidget.h \
+ tapandholdgesture.h
+SOURCES += imagewidget.cpp \
+ tapandholdgesture.cpp \
+ main.cpp
diff --git a/examples/gestures/imageviewer/imagewidget.cpp b/examples/gestures/imageviewer/imagewidget.cpp
index 717bb09..99889ed 100644
--- a/examples/gestures/imageviewer/imagewidget.cpp
+++ b/examples/gestures/imageviewer/imagewidget.cpp
@@ -65,7 +65,7 @@ ImageWidget::ImageWidget(QWidget *parent)
panGesture = new QPanGesture(this);
connect(panGesture, SIGNAL(triggered()), this, SLOT(gestureTriggered()));
- tapAndHoldGesture = new QTapAndHoldGesture(this);
+ tapAndHoldGesture = new TapAndHoldGesture(this);
connect(tapAndHoldGesture, SIGNAL(triggered()), this, SLOT(gestureTriggered()));
}
@@ -100,7 +100,7 @@ void ImageWidget::paintEvent(QPaintEvent*)
p.setPen(QPen(Qt::gray, 2));
p.drawEllipse(touchFeedback.position, 5, 5);
if (touchFeedback.doubleTapped) {
- p.setPen(QPen(Qt::gray, 2, Qt::DotLine));
+ p.setPen(QPen(Qt::darkGray, 2, Qt::DotLine));
p.drawEllipse(touchFeedback.position, 15, 15);
} else if (touchFeedback.tapAndHoldState != 0) {
QPoint pts[8] = {
@@ -159,40 +159,37 @@ void ImageWidget::gestureTriggered()
touchFeedback.tapped = false;
touchFeedback.doubleTapped = false;
- QGesture *g = qobject_cast<QGesture*>(sender());
if (sender() == panGesture) {
+ QPanGesture *pg = qobject_cast<QPanGesture*>(sender());
if (zoomedIn) {
- // usual panning
#ifndef QT_NO_CURSOR
- if (g->state() == Qt::GestureStarted)
- setCursor(Qt::SizeAllCursor);
- else
- setCursor(Qt::ArrowCursor);
+ switch (pg->state()) {
+ case Qt::GestureStarted:
+ case Qt::GestureUpdated:
+ setCursor(Qt::SizeAllCursor);
+ break;
+ default:
+ setCursor(Qt::ArrowCursor);
+ }
#endif
- const int dx = g->pos().x() - g->lastPos().x();
- const int dy = g->pos().y() - g->lastPos().y();
- horizontalOffset += dx;
- verticalOffset += dy;
+ horizontalOffset += pg->lastOffset().width();
+ verticalOffset += pg->lastOffset().height();
update();
} else {
// only slide gesture should be accepted
- const QPanGesture *pg = static_cast<const QPanGesture*>(g);
- if (g->state() == Qt::GestureFinished) {
+ if (pg->state() == Qt::GestureFinished) {
touchFeedback.sliding = false;
zoomed = rotated = false;
- if (pg->totalOffset().width() > 0) {
- qDebug() << "slide right";
+ if (pg->totalOffset().width() > 0)
goNextImage();
- } else {
- qDebug() << "slide left";
+ else
goPrevImage();
- }
updateImage();
}
}
feedbackFadeOutTimer.start(500, this);
} else if (sender() == tapAndHoldGesture) {
- if (g->state() == Qt::GestureFinished) {
+ if (tapAndHoldGesture->state() == Qt::GestureFinished) {
qDebug() << "tap and hold detected";
touchFeedback.reset();
update();
@@ -201,7 +198,7 @@ void ImageWidget::gestureTriggered()
menu.addAction("Action 1");
menu.addAction("Action 2");
menu.addAction("Action 3");
- menu.exec(mapToGlobal(g->pos()));
+ menu.exec(mapToGlobal(tapAndHoldGesture->pos()));
}
feedbackFadeOutTimer.start(500, this);
}
diff --git a/examples/gestures/imageviewer/imagewidget.h b/examples/gestures/imageviewer/imagewidget.h
index e12634d..d8d5f8d 100644
--- a/examples/gestures/imageviewer/imagewidget.h
+++ b/examples/gestures/imageviewer/imagewidget.h
@@ -48,6 +48,8 @@
#include <QtGui>
+#include "tapandholdgesture.h"
+
class ImageWidget : public QWidget
{
Q_OBJECT
@@ -79,7 +81,7 @@ private:
void goToImage(int index);
QPanGesture *panGesture;
- QTapAndHoldGesture *tapAndHoldGesture;
+ TapAndHoldGesture *tapAndHoldGesture;
QString path;
QStringList files;
diff --git a/examples/gestures/imageviewer/tapandholdgesture.cpp b/examples/gestures/imageviewer/tapandholdgesture.cpp
new file mode 100644
index 0000000..ff5284e
--- /dev/null
+++ b/examples/gestures/imageviewer/tapandholdgesture.cpp
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples 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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tapandholdgesture.h"
+
+#include <QtGui/qevent.h>
+
+/*!
+ \class TapAndHoldGesture
+ \since 4.6
+
+ \brief The TapAndHoldGesture class represents a Tap-and-Hold gesture,
+ providing additional information.
+*/
+
+const int TapAndHoldGesture::iterationCount = 40;
+const int TapAndHoldGesture::iterationTimeout = 50;
+
+/*!
+ Creates a new Tap and Hold gesture handler object and marks it as a child
+ of \a parent.
+
+ On some platforms like Windows there is a system-wide tap and hold gesture
+ that cannot be overriden, hence the gesture might never trigger and default
+ context menu will be shown instead.
+*/
+TapAndHoldGesture::TapAndHoldGesture(QWidget *parent)
+ : QGesture(parent), iteration(0)
+{
+}
+
+/*! \internal */
+bool TapAndHoldGesture::filterEvent(QEvent *event)
+{
+ if (!event->spontaneous())
+ return false;
+ const QTouchEvent *ev = static_cast<const QTouchEvent*>(event);
+ switch (event->type()) {
+ case QEvent::TouchBegin: {
+ if (timer.isActive())
+ timer.stop();
+ timer.start(TapAndHoldGesture::iterationTimeout, this);
+ const QPoint p = ev->touchPoints().at(0).pos().toPoint();
+ position = p;
+ break;
+ }
+ case QEvent::TouchUpdate:
+ if (ev->touchPoints().size() == 1) {
+ const QPoint startPos = ev->touchPoints().at(0).startPos().toPoint();
+ const QPoint pos = ev->touchPoints().at(0).pos().toPoint();
+ if ((startPos - pos).manhattanLength() > 15)
+ reset();
+ } else {
+ reset();
+ }
+ break;
+ case QEvent::TouchEnd:
+ reset();
+ break;
+ default:
+ break;
+ }
+ return false;
+}
+
+/*! \internal */
+void TapAndHoldGesture::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() != timer.timerId())
+ return;
+ if (iteration == TapAndHoldGesture::iterationCount) {
+ timer.stop();
+ setState(Qt::GestureFinished);
+ emit triggered();
+ } else {
+ setState(Qt::GestureStarted);
+ emit triggered();
+ }
+ ++iteration;
+}
+
+/*! \internal */
+void TapAndHoldGesture::reset()
+{
+ if (state() != Qt::NoGesture)
+ emit cancelled();
+ setState(Qt::NoGesture);
+ timer.stop();
+ iteration = 0;
+}
+
+/*!
+ \property TapAndHoldGesture::pos
+
+ \brief The position of the gesture.
+*/
+QPoint TapAndHoldGesture::pos() const
+{
+ return position;
+}
diff --git a/examples/gestures/imageviewer/tapandholdgesture.h b/examples/gestures/imageviewer/tapandholdgesture.h
new file mode 100644
index 0000000..e0d50b5
--- /dev/null
+++ b/examples/gestures/imageviewer/tapandholdgesture.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples 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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TAPANDHOLDGESTURE_H
+#define TAPANDHOLDGESTURE_H
+
+#include <QtCore/QBasicTimer>
+#include <QtGui/QGesture>
+#include <QtGui/QWidget>
+
+class TapAndHoldGesture : public QGesture
+{
+ Q_OBJECT
+ Q_PROPERTY(QPoint pos READ pos)
+
+public:
+ TapAndHoldGesture(QWidget *parent);
+
+ bool filterEvent(QEvent *event);
+ void reset();
+
+ QPoint pos() const;
+
+protected:
+ void timerEvent(QTimerEvent *event);
+
+private:
+ QBasicTimer timer;
+ int iteration;
+ QPoint position;
+ static const int iterationCount;
+ static const int iterationTimeout;
+};
+
+#endif // TAPANDHOLDGESTURE_H