summaryrefslogtreecommitdiffstats
path: root/tests/manual/gestures/scrollarea
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-10-23 12:57:30 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-10-23 12:57:30 (GMT)
commit4ff3e1ca7ce8afab49e5c52a1ae0141abfc8a841 (patch)
tree592d015d93478525504f8e09154b633fa2abdae2 /tests/manual/gestures/scrollarea
parentc21d3a0094b0692f2f888b04e258229234200e3c (diff)
parent05aaab72d69a7fa9c23811c1d3ee7d91a9174e46 (diff)
downloadQt-4ff3e1ca7ce8afab49e5c52a1ae0141abfc8a841.zip
Qt-4ff3e1ca7ce8afab49e5c52a1ae0141abfc8a841.tar.gz
Qt-4ff3e1ca7ce8afab49e5c52a1ae0141abfc8a841.tar.bz2
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/qt into qscriptprogram
Conflicts: src/script/api/qscriptengine.cpp tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
Diffstat (limited to 'tests/manual/gestures/scrollarea')
-rw-r--r--tests/manual/gestures/scrollarea/main.cpp229
-rw-r--r--tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp94
-rw-r--r--tests/manual/gestures/scrollarea/mousepangesturerecognizer.h57
-rw-r--r--tests/manual/gestures/scrollarea/scrollarea.pro3
4 files changed, 383 insertions, 0 deletions
diff --git a/tests/manual/gestures/scrollarea/main.cpp b/tests/manual/gestures/scrollarea/main.cpp
new file mode 100644
index 0000000..f90f6c6
--- /dev/null
+++ b/tests/manual/gestures/scrollarea/main.cpp
@@ -0,0 +1,229 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite 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 <QtGui>
+
+#include "mousepangesturerecognizer.h"
+
+class ScrollArea : public QScrollArea
+{
+ Q_OBJECT
+public:
+ ScrollArea(QWidget *parent = 0)
+ : QScrollArea(parent), outside(false)
+ {
+ viewport()->grabGesture(Qt::PanGesture);
+ }
+
+protected:
+ bool viewportEvent(QEvent *event)
+ {
+ if (event->type() == QEvent::Gesture) {
+ gestureEvent(static_cast<QGestureEvent *>(event));
+ return true;
+ } else if (event->type() == QEvent::GestureOverride) {
+ QGestureEvent *ge = static_cast<QGestureEvent *>(event);
+ if (QPanGesture *pan = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture)))
+ if (pan->state() == Qt::GestureStarted) {
+ outside = false;
+ }
+ }
+ return QScrollArea::viewportEvent(event);
+ }
+ void gestureEvent(QGestureEvent *event)
+ {
+ QPanGesture *pan = static_cast<QPanGesture *>(event->gesture(Qt::PanGesture));
+ if (pan) {
+ switch(pan->state()) {
+ case Qt::GestureStarted: qDebug("area: Pan: started"); break;
+ case Qt::GestureFinished: qDebug("area: Pan: finished"); break;
+ case Qt::GestureCanceled: qDebug("area: Pan: canceled"); break;
+ case Qt::GestureUpdated: break;
+ default: qDebug("area: Pan: <unknown state>"); break;
+ }
+
+ if (pan->state() == Qt::GestureStarted)
+ outside = false;
+ event->ignore();
+ event->ignore(pan);
+ if (outside)
+ return;
+
+ const QPointF offset = pan->offset();
+ const QPointF totalOffset = pan->totalOffset();
+ QScrollBar *vbar = verticalScrollBar();
+ QScrollBar *hbar = horizontalScrollBar();
+
+ if ((vbar->value() == vbar->minimum() && totalOffset.y() > 10) ||
+ (vbar->value() == vbar->maximum() && totalOffset.y() < -10)) {
+ outside = true;
+ return;
+ }
+ if ((hbar->value() == hbar->minimum() && totalOffset.x() > 10) ||
+ (hbar->value() == hbar->maximum() && totalOffset.x() < -10)) {
+ outside = true;
+ return;
+ }
+ vbar->setValue(vbar->value() - offset.y());
+ hbar->setValue(hbar->value() - offset.x());
+ event->accept(pan);
+ }
+ }
+
+private:
+ bool outside;
+};
+
+class Slider : public QSlider
+{
+public:
+ Slider(Qt::Orientation orientation, QWidget *parent = 0)
+ : QSlider(orientation, parent)
+ {
+ grabGesture(Qt::PanGesture);
+ }
+protected:
+ bool event(QEvent *event)
+ {
+ if (event->type() == QEvent::Gesture) {
+ gestureEvent(static_cast<QGestureEvent *>(event));
+ return true;
+ }
+ return QSlider::event(event);
+ }
+ void gestureEvent(QGestureEvent *event)
+ {
+ QPanGesture *pan = static_cast<QPanGesture *>(event->gesture(Qt::PanGesture));
+ if (pan) {
+ switch (pan->state()) {
+ case Qt::GestureStarted: qDebug("slider: Pan: started"); break;
+ case Qt::GestureFinished: qDebug("slider: Pan: finished"); break;
+ case Qt::GestureCanceled: qDebug("slider: Pan: canceled"); break;
+ case Qt::GestureUpdated: break;
+ default: qDebug("slider: Pan: <unknown state>"); break;
+ }
+
+ if (pan->state() == Qt::GestureStarted)
+ outside = false;
+ event->ignore();
+ event->ignore(pan);
+ if (outside)
+ return;
+ const QPointF offset = pan->offset();
+ const QPointF totalOffset = pan->totalOffset();
+ if (orientation() == Qt::Horizontal) {
+ if ((value() == minimum() && totalOffset.x() < -10) ||
+ (value() == maximum() && totalOffset.x() > 10)) {
+ outside = true;
+ return;
+ }
+ if (totalOffset.y() < 40 && totalOffset.y() > -40) {
+ setValue(value() + offset.x());
+ event->accept(pan);
+ } else {
+ outside = true;
+ }
+ } else if (orientation() == Qt::Vertical) {
+ if ((value() == maximum() && totalOffset.y() < -10) ||
+ (value() == minimum() && totalOffset.y() > 10)) {
+ outside = true;
+ return;
+ }
+ if (totalOffset.x() < 40 && totalOffset.x() > -40) {
+ setValue(value() - offset.y());
+ event->accept(pan);
+ } else {
+ outside = true;
+ }
+ }
+ }
+ }
+private:
+ bool outside;
+};
+
+class MainWindow : public QMainWindow
+{
+public:
+ MainWindow()
+ {
+ rootScrollArea = new ScrollArea;
+ setCentralWidget(rootScrollArea);
+
+ QWidget *root = new QWidget;
+ root->setFixedSize(3000, 3000);
+ rootScrollArea->setWidget(root);
+
+ Slider *verticalSlider = new Slider(Qt::Vertical, root);
+ verticalSlider ->move(650, 1100);
+ Slider *horizontalSlider = new Slider(Qt::Horizontal, root);
+ horizontalSlider ->move(600, 1000);
+
+ childScrollArea = new ScrollArea(root);
+ childScrollArea->move(500, 500);
+ QWidget *w = new QWidget;
+ w->setMinimumWidth(400);
+ QVBoxLayout *l = new QVBoxLayout(w);
+ l->setMargin(20);
+ for (int i = 0; i < 100; ++i) {
+ QWidget *w = new QWidget;
+ QHBoxLayout *ll = new QHBoxLayout(w);
+ ll->addWidget(new QLabel(QString("Label %1").arg(i)));
+ ll->addWidget(new QPushButton(QString("Button %1").arg(i)));
+ l->addWidget(w);
+ }
+ childScrollArea->setWidget(w);
+ }
+private:
+ ScrollArea *rootScrollArea;
+ ScrollArea *childScrollArea;
+};
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ app.registerGestureRecognizer(new MousePanGestureRecognizer);
+ MainWindow w;
+ w.show();
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
new file mode 100644
index 0000000..5f94dbc
--- /dev/null
+++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite 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 "mousepangesturerecognizer.h"
+
+#include <QEvent>
+#include <QMouseEvent>
+#include <QGesture>
+
+MousePanGestureRecognizer::MousePanGestureRecognizer()
+{
+}
+
+QGesture* MousePanGestureRecognizer::createGesture(QObject *) const
+{
+ return new QPanGesture;
+}
+
+QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event)
+{
+ QPanGesture *g = static_cast<QPanGesture *>(state);
+ QMouseEvent *me = static_cast<QMouseEvent *>(event);
+ if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) {
+ g->setHotSpot(me->globalPos());
+ g->setProperty("lastPos", me->globalPos());
+ g->setProperty("pressed", QVariant::fromValue<bool>(true));
+ return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint;
+ } else if (event->type() == QEvent::MouseMove) {
+ if (g->property("pressed").toBool()) {
+ QPoint pos = me->globalPos();
+ QPoint lastPos = g->property("lastPos").toPoint();
+ g->setLastOffset(g->offset());
+ lastPos = pos - lastPos;
+ g->setOffset(QPointF(lastPos.x(), lastPos.y()));
+ g->setTotalOffset(g->totalOffset() + QPointF(lastPos.x(), lastPos.y()));
+ g->setProperty("lastPos", pos);
+ return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint;
+ }
+ return QGestureRecognizer::NotGesture;
+ } else if (event->type() == QEvent::MouseButtonRelease) {
+ return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint;
+ }
+ return QGestureRecognizer::Ignore;
+}
+
+void MousePanGestureRecognizer::reset(QGesture *state)
+{
+ QPanGesture *g = static_cast<QPanGesture *>(state);
+ g->setTotalOffset(QPointF());
+ g->setLastOffset(QPointF());
+ g->setOffset(QPointF());
+ g->setAcceleration(0);
+ g->setProperty("lastPos", QVariant());
+ g->setProperty("pressed", QVariant::fromValue<bool>(false));
+ QGestureRecognizer::reset(state);
+}
diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h
new file mode 100644
index 0000000..c92d477
--- /dev/null
+++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite 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 MOUSEPANGESTURERECOGNIZER_H
+#define MOUSEPANGESTURERECOGNIZER_H
+
+#include <QGestureRecognizer>
+
+class MousePanGestureRecognizer : public QGestureRecognizer
+{
+public:
+ MousePanGestureRecognizer();
+
+ QGesture* createGesture(QObject *target) const;
+ QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event);
+ void reset(QGesture *state);
+};
+
+#endif // MOUSEPANGESTURERECOGNIZER_H
diff --git a/tests/manual/gestures/scrollarea/scrollarea.pro b/tests/manual/gestures/scrollarea/scrollarea.pro
new file mode 100644
index 0000000..554810e
--- /dev/null
+++ b/tests/manual/gestures/scrollarea/scrollarea.pro
@@ -0,0 +1,3 @@
+SOURCES = main.cpp \
+ mousepangesturerecognizer.cpp
+HEADERS += mousepangesturerecognizer.h