summaryrefslogtreecommitdiffstats
path: root/tests/manual/gestures
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/gestures')
-rw-r--r--tests/manual/gestures/pinch/main.cpp68
-rw-r--r--tests/manual/gestures/pinch/pinch.pro4
-rw-r--r--tests/manual/gestures/pinch/pinch.qrc5
-rw-r--r--tests/manual/gestures/pinch/pinchwidget.cpp118
-rw-r--r--tests/manual/gestures/pinch/pinchwidget.h78
-rw-r--r--tests/manual/gestures/pinch/qt-logo.pngbin0 -> 13923 bytes
-rw-r--r--tests/manual/gestures/twopanwidgets/main.cpp135
-rw-r--r--tests/manual/gestures/twopanwidgets/twopanwidgets.pro1
8 files changed, 409 insertions, 0 deletions
diff --git a/tests/manual/gestures/pinch/main.cpp b/tests/manual/gestures/pinch/main.cpp
new file mode 100644
index 0000000..0e5b928
--- /dev/null
+++ b/tests/manual/gestures/pinch/main.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** 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 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://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "pinchwidget.h"
+
+class MainWindow : public QWidget
+{
+public:
+ MainWindow();
+};
+
+MainWindow::MainWindow()
+{
+ QVBoxLayout *l = new QVBoxLayout(this);
+ QPushButton *btn = new QPushButton(QLatin1String("AcceptTouchEvents"));
+ l->addWidget(btn);
+ QImage image(":/images/qt-logo.png");
+ PinchWidget *w = new PinchWidget(image);
+ l->addWidget(w);
+ connect(btn, SIGNAL(clicked()), w, SLOT(acceptTouchEvents()));
+}
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow w;
+ w.show();
+ return app.exec();
+}
diff --git a/tests/manual/gestures/pinch/pinch.pro b/tests/manual/gestures/pinch/pinch.pro
new file mode 100644
index 0000000..d1f28cc
--- /dev/null
+++ b/tests/manual/gestures/pinch/pinch.pro
@@ -0,0 +1,4 @@
+SOURCES = main.cpp \
+ pinchwidget.cpp
+HEADERS += pinchwidget.h
+RESOURCES += pinch.qrc
diff --git a/tests/manual/gestures/pinch/pinch.qrc b/tests/manual/gestures/pinch/pinch.qrc
new file mode 100644
index 0000000..0be9ba1
--- /dev/null
+++ b/tests/manual/gestures/pinch/pinch.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/images" >
+ <file>qt-logo.png</file>
+ </qresource>
+</RCC>
diff --git a/tests/manual/gestures/pinch/pinchwidget.cpp b/tests/manual/gestures/pinch/pinchwidget.cpp
new file mode 100644
index 0000000..cc16443
--- /dev/null
+++ b/tests/manual/gestures/pinch/pinchwidget.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** 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 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://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "pinchwidget.h"
+
+#include <QPainter>
+#include <QImage>
+#include <QPixmap>
+#include <QPanGesture>
+#include <QPinchGesture>
+#include <QPushButton>
+
+PinchWidget::PinchWidget(const QImage &image, QWidget *parent)
+ : QWidget(parent)
+{
+ setMinimumSize(100,100);
+ this->image = image;
+ pan = new QPanGesture(this);
+ connect(pan, SIGNAL(triggered()), this, SLOT(onPanTriggered()));
+ connect(pan, SIGNAL(finished()), this, SLOT(onPanFinished()));
+ pinch = new QPinchGesture(this);
+ connect(pinch, SIGNAL(triggered()), this, SLOT(onPinchTriggered()));
+ connect(pinch, SIGNAL(finished()), this, SLOT(onPinchFinished()));
+}
+
+QSize PinchWidget::sizeHint() const
+{
+ return image.size()*1.5;
+}
+
+void PinchWidget::paintEvent(QPaintEvent *)
+{
+ QPainter p(this);
+ QTransform t = worldTransform * currentPanTransform * currentPinchTransform;
+ p.setTransform(t);
+ QPoint center = QPoint(width()/2, height()/2);
+ QPoint size = QPoint(image.width()/2, image.height()/2);
+ p.translate(center - size);
+ p.drawImage(QPoint(0,0), image);
+}
+
+void PinchWidget::acceptTouchEvents()
+{
+ setAttribute(Qt::WA_AcceptTouchEvents);
+ if (QWidget *w = qobject_cast<QPushButton*>(sender()))
+ w->setEnabled(false);
+}
+
+void PinchWidget::onPanTriggered()
+{
+ currentPanTransform = QTransform()
+ .translate(pan->totalOffset().width(),
+ pan->totalOffset().height());
+ update();
+}
+
+void PinchWidget::onPanFinished()
+{
+ worldTransform *= currentPanTransform;
+ currentPanTransform.reset();
+ update();
+}
+
+void PinchWidget::onPinchTriggered()
+{
+ QPoint transformCenter = worldTransform.map(QPoint(width()/2, height()/2));
+ currentPinchTransform = QTransform()
+ .translate(transformCenter.x(), transformCenter.y())
+ .scale(pinch->totalScaleFactor(), pinch->totalScaleFactor())
+ .rotate(pinch->totalRotationAngle())
+ .translate(-transformCenter.x(), -transformCenter.y());
+ update();
+}
+
+void PinchWidget::onPinchFinished()
+{
+ worldTransform *= currentPinchTransform;
+ currentPinchTransform.reset();
+ update();
+}
diff --git a/tests/manual/gestures/pinch/pinchwidget.h b/tests/manual/gestures/pinch/pinchwidget.h
new file mode 100644
index 0000000..a76e287
--- /dev/null
+++ b/tests/manual/gestures/pinch/pinchwidget.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** 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 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://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PINCHWIDGET_H
+#define PINCHWIDGET_H
+
+#include <QWidget>
+#include <QTransform>
+
+class QPanGesture;
+class QPinchGesture;
+
+class PinchWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ PinchWidget(const QImage &image, QWidget *parent = 0);
+
+private Q_SLOTS:
+ void acceptTouchEvents();
+ void onPanTriggered();
+ void onPanFinished();
+ void onPinchTriggered();
+ void onPinchFinished();
+
+private:
+ void paintEvent(QPaintEvent *);
+ QSize sizeHint() const;
+
+ QImage image;
+
+ QPanGesture *pan;
+ QPinchGesture *pinch;
+
+ QTransform worldTransform;
+ QTransform currentPanTransform;
+ QTransform currentPinchTransform;
+};
+
+#endif // PINCHWIDGET_H
diff --git a/tests/manual/gestures/pinch/qt-logo.png b/tests/manual/gestures/pinch/qt-logo.png
new file mode 100644
index 0000000..7d3e97e
--- /dev/null
+++ b/tests/manual/gestures/pinch/qt-logo.png
Binary files differ
diff --git a/tests/manual/gestures/twopanwidgets/main.cpp b/tests/manual/gestures/twopanwidgets/main.cpp
new file mode 100644
index 0000000..7750d1d
--- /dev/null
+++ b/tests/manual/gestures/twopanwidgets/main.cpp
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** 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 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://qt.nokia.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+static const char text[] =
+ "Hello world! This is just a lot of text with to make sure scrollbar appear";
+
+class TextEdit : public QTextEdit
+{
+ Q_OBJECT
+public Q_SLOTS:
+ void acceptTouch()
+ {
+ viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
+ if (QWidget *w = qobject_cast<QPushButton*>(sender()))
+ w->setEnabled(false);
+ }
+};
+
+class PlainTextEdit : public QPlainTextEdit
+{
+ Q_OBJECT
+public Q_SLOTS:
+ void acceptTouch()
+ {
+ viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
+ if (QWidget *w = qobject_cast<QPushButton*>(sender()))
+ w->setEnabled(false);
+ }
+};
+
+class MainWindow : public QMainWindow
+{
+public:
+ MainWindow();
+};
+
+MainWindow::MainWindow()
+{
+ QTabWidget *tw = new QTabWidget;
+ setCentralWidget(tw);
+ {
+ QWidget *tab = new QWidget;
+ QGridLayout *layout = new QGridLayout(tab);
+ QTextEdit *edit1 = new TextEdit;
+ QTextEdit *edit2 = new TextEdit;
+ QString text1 = QString(text).replace(' ', '\n');
+ for (int i = 0; i < 5; ++i) text1 += text1;
+ QString text2 = QString(text);
+ for (int i = 0; i < 5; ++i) text2 += text2;
+ edit1->setPlainText(text1);
+ edit2->setPlainText(text2);
+ edit2->setWordWrapMode(QTextOption::NoWrap);
+ QPushButton *btn1 = new QPushButton(QLatin1String("AcceptTouchEvents"));
+ connect(btn1, SIGNAL(clicked()), edit1, SLOT(acceptTouch()));
+ QPushButton *btn2 = new QPushButton(QLatin1String("AcceptTouchEvents"));
+ connect(btn2, SIGNAL(clicked()), edit2, SLOT(acceptTouch()));
+ layout->addWidget(btn1, 0, 0);
+ layout->addWidget(btn2, 0, 1);
+ layout->addWidget(edit1, 1, 0);
+ layout->addWidget(edit2, 1, 1);
+ tw->addTab(tab, QLatin1String("QTextEdit"));
+ }
+ {
+ QWidget *tab = new QWidget;
+ QGridLayout *layout = new QGridLayout(tab);
+ QPlainTextEdit *edit1 = new PlainTextEdit;
+ QPlainTextEdit *edit2 = new PlainTextEdit;
+ QString text1 = QString(text).replace(' ', '\n');
+ for (int i = 0; i < 5; ++i) text1 += text1;
+ QString text2 = QString(text);
+ for (int i = 0; i < 5; ++i) text2 += text2;
+ edit1->setPlainText(text1);
+ edit2->setPlainText(text2);
+ edit2->setWordWrapMode(QTextOption::NoWrap);
+ QPushButton *btn1 = new QPushButton(QLatin1String("AcceptTouchEvents"));
+ connect(btn1, SIGNAL(clicked()), edit1, SLOT(acceptTouch()));
+ QPushButton *btn2 = new QPushButton(QLatin1String("AcceptTouchEvents"));
+ connect(btn2, SIGNAL(clicked()), edit2, SLOT(acceptTouch()));
+ layout->addWidget(btn1, 0, 0);
+ layout->addWidget(btn2, 0, 1);
+ layout->addWidget(edit1, 1, 0);
+ layout->addWidget(edit2, 1, 1);
+ tw->addTab(tab, QLatin1String("QPlainTextEdit"));
+ }
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/tests/manual/gestures/twopanwidgets/twopanwidgets.pro b/tests/manual/gestures/twopanwidgets/twopanwidgets.pro
new file mode 100644
index 0000000..5254077
--- /dev/null
+++ b/tests/manual/gestures/twopanwidgets/twopanwidgets.pro
@@ -0,0 +1 @@
+SOURCES = main.cpp \ No newline at end of file