diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-10-30 16:35:17 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-10-30 21:35:44 +0100 |
commit | 0630c82bd0fa2a4a4275437d58544ffdc8fbdb33 (patch) | |
tree | af4915b719cec955593338b9a0beb6e644e003ad /tests/manual | |
parent | 4387c5d6af49976318f7ca04c7a47b81a9cb19cc (diff) |
Add manual test for touch events.
Unlike qtouchevents, this provides a touch area which logs its
events and devices.
Task-number: QTBUG-40461
Change-Id: Iaaa3589dd692caf8c7078f5ed2ff1e8b2322a369
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/manual.pro | 1 | ||||
-rw-r--r-- | tests/manual/touch/main.cpp | 209 | ||||
-rw-r--r-- | tests/manual/touch/touch.pro | 5 |
3 files changed, 215 insertions, 0 deletions
diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index e593756a7d..fe3e624bfe 100644 --- a/tests/manual/manual.pro +++ b/tests/manual/manual.pro @@ -29,6 +29,7 @@ qtabletevent \ qtexteditlist \ qtbug-8933 \ qtouchevent \ +touch \ qwidget_zorder \ repaint \ socketengine \ diff --git a/tests/manual/touch/main.cpp b/tests/manual/touch/main.cpp new file mode 100644 index 0000000000..6b06db614c --- /dev/null +++ b/tests/manual/touch/main.cpp @@ -0,0 +1,209 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include <QLabel> +#include <QMenu> +#include <QMenuBar> +#include <QAction> +#include <QMainWindow> +#include <QSplitter> +#include <QVector> +#include <QCommandLineOption> +#include <QCommandLineParser> +#include <QPlainTextEdit> +#include <QPaintEvent> +#include <QScreen> +#include <QDebug> +#include <QTextStream> + +QDebug operator<<(QDebug debug, const QTouchDevice *d) +{ + QDebugStateSaver saver(debug); + debug.nospace(); + debug << "QTouchDevice(" << d->name() << ','; + switch (d->type()) { + case QTouchDevice::TouchScreen: + debug << "TouchScreen"; + break; + case QTouchDevice::TouchPad: + debug << "TouchPad"; + break; + } + debug << ", capabilities=" << d->capabilities() + << ", maximumTouchPoints=" << d->maximumTouchPoints() << ')'; + return debug; +} + +typedef QVector<QEvent::Type> EventTypeVector; + +class EventFilter : public QObject { + Q_OBJECT +public: + explicit EventFilter(const EventTypeVector &types, QObject *p) : QObject(p), m_types(types) {} + + bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE; + +signals: + void eventReceived(const QString &); + +private: + const EventTypeVector m_types; +}; + +bool EventFilter::eventFilter(QObject *o, QEvent *e) +{ + static int n = 0; + if (m_types.contains(e->type())) { + QString message; + QDebug(&message) << '#' << n++ << ' ' << o->objectName() << ' ' << e; + emit eventReceived(message); + } + return false; +} + +class TouchTestWidget : public QWidget { +public: + explicit TouchTestWidget(QWidget *parent = 0) : QWidget(parent) + { + setAttribute(Qt::WA_AcceptTouchEvents); + } + + bool event(QEvent *event) Q_DECL_OVERRIDE + { + switch (event->type()) { + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + event->accept(); + return true; + default: + break; + } + return QWidget::event(event); + } +}; + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow(); + QWidget *touchWidget() const { return m_touchWidget; } + +public slots: + void appendToLog(const QString &text) { m_logTextEdit->appendPlainText(text); } + void dumpTouchDevices(); + +private: + QWidget *m_touchWidget; + QPlainTextEdit *m_logTextEdit; +}; + +MainWindow::MainWindow() + : m_touchWidget(new TouchTestWidget) + , m_logTextEdit(new QPlainTextEdit) +{ + setWindowTitle(QStringLiteral("Touch Event Tester ") + QT_VERSION_STR); + + setObjectName("MainWin"); + QMenu *fileMenu = menuBar()->addMenu("File"); + QAction *da = fileMenu->addAction(QStringLiteral("Dump devices")); + da->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); + connect(da, SIGNAL(triggered()), this, SLOT(dumpTouchDevices())); + QAction *qa = fileMenu->addAction(QStringLiteral("Quit")); + qa->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q)); + connect(qa, SIGNAL(triggered()), this, SLOT(close())); + + QSplitter *mainSplitter = new QSplitter(Qt::Vertical); + + m_touchWidget->setObjectName(QStringLiteral("TouchWidget")); + const QSize screenSize = QGuiApplication::primaryScreen()->availableGeometry().size(); + m_touchWidget->setMinimumSize(screenSize / 2); + mainSplitter->addWidget(m_touchWidget); + + m_logTextEdit->setObjectName(QStringLiteral("LogTextEdit")); + m_logTextEdit->setMinimumHeight(screenSize.height() / 4); + mainSplitter->addWidget(m_logTextEdit); + setCentralWidget(mainSplitter); + + dumpTouchDevices(); +} + +void MainWindow::dumpTouchDevices() +{ + QString message; + QDebug debug(&message); + const QList<const QTouchDevice *> devices = QTouchDevice::devices(); + debug << devices.size() << "Device(s):\n"; + for (int i = 0; i < devices.size(); ++i) + debug << "Device #" << i << devices.at(i) << '\n'; + appendToLog(message); +} + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + QCommandLineParser parser; + parser.setApplicationDescription(QStringLiteral("Touch/Mouse tester")); + parser.addHelpOption(); + const QCommandLineOption mouseMoveOption(QStringLiteral("mousemove"), + QStringLiteral("Log mouse move events")); + parser.addOption(mouseMoveOption); + const QCommandLineOption globalFilterOption(QStringLiteral("global"), + QStringLiteral("Global event filter")); + parser.addOption(globalFilterOption); + parser.process(QApplication::arguments()); + + MainWindow w; + w.show(); + const QSize pos = QGuiApplication::primaryScreen()->availableGeometry().size() - w.size(); + w.move(pos.width() / 2, pos.height() / 2); + + EventTypeVector eventTypes; + eventTypes << QEvent::MouseButtonPress << QEvent::MouseButtonRelease + << QEvent::MouseButtonDblClick + << QEvent::TouchBegin << QEvent::TouchUpdate << QEvent::TouchEnd; + if (parser.isSet(mouseMoveOption)) + eventTypes << QEvent::MouseMove; + QObject *filterTarget = parser.isSet(globalFilterOption) + ? static_cast<QObject *>(&a) + : static_cast<QObject *>(w.touchWidget()); + EventFilter *filter = new EventFilter(eventTypes, filterTarget); + filterTarget->installEventFilter(filter); + QObject::connect(filter, SIGNAL(eventReceived(QString)), &w, SLOT(appendToLog(QString))); + + return a.exec(); +} + +#include "main.moc" diff --git a/tests/manual/touch/touch.pro b/tests/manual/touch/touch.pro new file mode 100644 index 0000000000..fcb3c47f43 --- /dev/null +++ b/tests/manual/touch/touch.pro @@ -0,0 +1,5 @@ +TEMPLATE = app +QT = core gui +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +CONFIG -= app_bundle +SOURCES += main.cpp |