summaryrefslogtreecommitdiffstats
path: root/tests/manual/qtabletevent/device_information
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2014-06-06 09:43:00 +0200
committerShawn Rutledge <shawn.rutledge@digia.com>2014-07-31 12:20:34 +0200
commitda9e02eb83ea6eecf3cdb16b11241c91f5029380 (patch)
tree1d4a94c7eb8d8a1b836bbc65e5687406faeed49d /tests/manual/qtabletevent/device_information
parent6c1a12c5581ca8976d36431456ad53f04cddfd7d (diff)
QTabletEvent manual test: show buttons, pressure, eraser
- Show which button was pressed or released - Render an ellipse proportional to pressure for each point drawn - Different color for the eraser - More complete output for each event - Don't show mouse events by default, just as most tablet applications can now ignore mouse events on the drawing canvas. But for the purpose of testing interleaving of tablet and mouse events, one can give the argument --mouse when starting this program to show them too, as before. Task-number: QTBUG-39458 Change-Id: I5e03f1aa748be39d524bd6984ff5d66579787cf9 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'tests/manual/qtabletevent/device_information')
-rw-r--r--tests/manual/qtabletevent/device_information/main.cpp20
-rw-r--r--tests/manual/qtabletevent/device_information/tabletwidget.cpp34
-rw-r--r--tests/manual/qtabletevent/device_information/tabletwidget.h7
3 files changed, 50 insertions, 11 deletions
diff --git a/tests/manual/qtabletevent/device_information/main.cpp b/tests/manual/qtabletevent/device_information/main.cpp
index 54f9f5cb54..1c83023cee 100644
--- a/tests/manual/qtabletevent/device_information/main.cpp
+++ b/tests/manual/qtabletevent/device_information/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** 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.
@@ -40,11 +40,21 @@
****************************************************************************/
#include <QApplication>
+#include <QDebug>
#include "tabletwidget.h"
int main(int argc, char **argv) {
- QApplication app(argc, argv);
- TabletWidget tabletWidget;
- tabletWidget.showMaximized();
- return app.exec();
+ QApplication app(argc, argv);
+ bool mouseToo = false;
+ if (app.arguments().contains(QLatin1String("--nomouse")) || app.arguments().contains(QLatin1String("-nomouse")))
+ mouseToo = false;
+ else if (app.arguments().contains(QLatin1String("--mouse")) || app.arguments().contains(QLatin1String("-mouse")))
+ mouseToo = true;
+ if (mouseToo)
+ qDebug() << "will show mouse events coming from the tablet as well as QTabletEvents";
+ else
+ qDebug() << "will not show mouse events from the tablet; use the --mouse option to enable";
+ TabletWidget tabletWidget(mouseToo);
+ tabletWidget.showMaximized();
+ return app.exec();
}
diff --git a/tests/manual/qtabletevent/device_information/tabletwidget.cpp b/tests/manual/qtabletevent/device_information/tabletwidget.cpp
index 7b5de72e27..c2fbe76e5b 100644
--- a/tests/manual/qtabletevent/device_information/tabletwidget.cpp
+++ b/tests/manual/qtabletevent/device_information/tabletwidget.cpp
@@ -42,8 +42,11 @@
#include "tabletwidget.h"
#include <QPainter>
#include <QApplication>
+#include <QDebug>
+#include <QMetaObject>
+#include <QMetaEnum>
-TabletWidget::TabletWidget()
+TabletWidget::TabletWidget(bool mouseToo) : mMouseToo(mouseToo)
{
QPalette newPalette = palette();
newPalette.setColor(QPalette::Window, Qt::white);
@@ -76,12 +79,14 @@ bool TabletWidget::eventFilter(QObject *, QEvent *ev)
mPress = event->pressure();
mTangential = event->tangentialPressure();
mRot = event->rotation();
+ mButton = event->button();
+ mButtons = event->buttons();
if (isVisible())
update();
break;
}
case QEvent::MouseMove:
- {
+ if (mMouseToo) {
resetAttributes();
QMouseEvent *event = static_cast<QMouseEvent*>(ev);
mType = event->type();
@@ -129,7 +134,7 @@ void TabletWidget::paintEvent(QPaintEvent *)
|| mType == QEvent::TabletMove || mType == QEvent::TabletPress
|| mType == QEvent::TabletRelease) {
- eventInfo << QString("Hight res global position: %1 %2").arg(QString::number(mHiResGlobalPos.x()), QString::number(mHiResGlobalPos.y()));
+ eventInfo << QString("High res global position: %1 %2").arg(QString::number(mHiResGlobalPos.x()), QString::number(mHiResGlobalPos.y()));
QString pointerType("Pointer type: ");
switch (mPointerType) {
@@ -148,7 +153,6 @@ void TabletWidget::paintEvent(QPaintEvent *)
}
eventInfo << pointerType;
-
QString deviceString = "Device type: ";
switch (mDev) {
case QTabletEvent::NoDevice:
@@ -172,6 +176,8 @@ void TabletWidget::paintEvent(QPaintEvent *)
}
eventInfo << deviceString;
+ eventInfo << QString("Button: %1 (0x%2)").arg(buttonToString(mButton)).arg(mButton, 0, 16);
+ eventInfo << QString("Buttons currently pressed: %1 (0x%2)").arg(buttonsToString(mButtons)).arg(mButtons, 0, 16);
eventInfo << QString("Pressure: %1").arg(QString::number(mPress));
eventInfo << QString("Tangential pressure: %1").arg(QString::number(mTangential));
eventInfo << QString("Rotation: %1").arg(QString::number(mRot));
@@ -182,7 +188,25 @@ void TabletWidget::paintEvent(QPaintEvent *)
eventInfo << QString("Unique Id: %1").arg(QString::number(mUnique));
}
- painter.drawText(rect(), eventInfo.join("\n"));
+ QString text = eventInfo.join("\n");
+ painter.drawText(rect(), text);
+}
+
+const char *TabletWidget::buttonToString(Qt::MouseButton b)
+{
+ static int enumIdx = QObject::staticQtMetaObject.indexOfEnumerator("MouseButtons");
+ return QObject::staticQtMetaObject.enumerator(enumIdx).valueToKey(b);
+}
+
+QString TabletWidget::buttonsToString(Qt::MouseButtons bs)
+{
+ QStringList ret;
+ for (int i = 0; (uint)(1 << i) <= Qt::MaxMouseButton; ++i) {
+ Qt::MouseButton b = static_cast<Qt::MouseButton>(1 << i);
+ if (bs.testFlag(b))
+ ret << buttonToString(b);
+ }
+ return ret.join("|");
}
void TabletWidget::tabletEvent(QTabletEvent *event)
diff --git a/tests/manual/qtabletevent/device_information/tabletwidget.h b/tests/manual/qtabletevent/device_information/tabletwidget.h
index a60fa8d83f..8efdd63697 100644
--- a/tests/manual/qtabletevent/device_information/tabletwidget.h
+++ b/tests/manual/qtabletevent/device_information/tabletwidget.h
@@ -49,11 +49,13 @@
class TabletWidget : public QWidget
{
public:
- TabletWidget();
+ TabletWidget(bool mouseToo);
protected:
bool eventFilter(QObject *obj, QEvent *ev);
void tabletEvent(QTabletEvent *event);
void paintEvent(QPaintEvent *event);
+ const char *buttonToString(Qt::MouseButton b);
+ QString buttonsToString(Qt::MouseButtons bs);
private:
void resetAttributes() {
mType = mDev = mPointerType = mXT = mYT = mZ = 0;
@@ -66,8 +68,11 @@ private:
QPoint mPos, mGPos;
QPointF mHiResGlobalPos;
int mDev, mPointerType, mXT, mYT, mZ;
+ Qt::MouseButton mButton;
+ Qt::MouseButtons mButtons;
qreal mPress, mTangential, mRot;
qint64 mUnique;
+ bool mMouseToo;
};
#endif // TABLETWIDGET_H