qt 6.5.1 original

This commit is contained in:
kleuter
2023-10-29 23:33:08 +01:00
parent 71d22ab6b0
commit 85d238dfda
21202 changed files with 5499099 additions and 0 deletions

View File

@ -0,0 +1,6 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#add_subdirectory(device_information) # special case no member named 'staticQtMetaObject'
add_subdirectory(event_compression)
add_subdirectory(regular_widgets)

View File

@ -0,0 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## device_information Binary:
#####################################################################
qt_internal_add_manual_test(device_information
GUI
SOURCES
main.cpp
tabletwidget.cpp tabletwidget.h
LIBRARIES
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,6 @@
QT += widgets
SOURCES += \
main.cpp \
tabletwidget.cpp
HEADERS += \
tabletwidget.h

View File

@ -0,0 +1,22 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QApplication>
#include <QDebug>
#include "tabletwidget.h"
int main(int argc, char **argv) {
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();
}

View File

@ -0,0 +1,191 @@
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "tabletwidget.h"
#include <QPainter>
#include <QApplication>
#include <QDebug>
#include <QMetaObject>
#include <QMetaEnum>
TabletWidget::TabletWidget(bool mouseToo) : mMouseToo(mouseToo), mWheelEventCount(0), mQuitShortcut(QKeySequence::Quit, this)
{
QPalette newPalette = palette();
newPalette.setColor(QPalette::Window, Qt::white);
newPalette.setColor(QPalette::WindowText, Qt::black);
setPalette(newPalette);
qApp->installEventFilter(this);
resetAttributes();
connect(&mQuitShortcut, SIGNAL(activated()), qApp, SLOT(quit()));
}
bool TabletWidget::eventFilter(QObject *, QEvent *ev)
{
switch (ev->type()) {
case QEvent::TabletEnterProximity:
case QEvent::TabletLeaveProximity:
case QEvent::TabletMove:
case QEvent::TabletPress:
case QEvent::TabletRelease:
{
QTabletEvent *event = static_cast<QTabletEvent*>(ev);
mDev = event->pointingDevice();
if (!mDev)
qWarning() << "missing device in tablet event";
mType = event->type();
mPos = event->position();
mGPos = event->globalPosition();
mXT = event->xTilt();
mYT = event->yTilt();
mZ = event->z();
mPress = event->pressure();
mTangential = event->tangentialPressure();
mRot = event->rotation();
mButton = event->button();
mButtons = event->buttons();
mModifiers = event->modifiers();
mTimestamp = event->timestamp();
if (isVisible())
update();
break;
}
case QEvent::MouseMove:
if (mMouseToo) {
resetAttributes();
QMouseEvent *event = static_cast<QMouseEvent*>(ev);
mType = event->type();
mPos = event->pos();
mGPos = event->globalPosition();
mTimestamp = event->timestamp();
}
break;
case QEvent::Wheel:
++mWheelEventCount;
break;
default:
break;
}
return false;
}
void TabletWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QStringList eventInfo;
QString typeString("Event type: ");
switch (mType) {
case QEvent::TabletEnterProximity:
typeString += "QEvent::TabletEnterProximity";
break;
case QEvent::TabletLeaveProximity:
typeString += "QEvent::TabletLeaveProximity";
break;
case QEvent::TabletMove:
typeString += "QEvent::TabletMove";
break;
case QEvent::TabletPress:
typeString += "QEvent::TabletPress";
break;
case QEvent::TabletRelease:
typeString += "QEvent::TabletRelease";
break;
case QEvent::MouseMove:
typeString += "QEvent::MouseMove";
break;
}
eventInfo << typeString;
eventInfo << QString("Global position: %1 %2").arg(QString::number(mGPos.x()), QString::number(mGPos.y()));
eventInfo << QString("Local position: %1 %2").arg(QString::number(mPos.x()), QString::number(mPos.y()));
eventInfo << QString("Timestamp: %1").arg(QString::number(mTimestamp));
if (mType == QEvent::TabletEnterProximity || mType == QEvent::TabletLeaveProximity
|| mType == QEvent::TabletMove || mType == QEvent::TabletPress
|| mType == QEvent::TabletRelease) {
if (mDev.isNull()) {
eventInfo << QString("Device info missing");
} else {
eventInfo << QString("Seat: %1").arg(mDev->seatName());
eventInfo << QString("Name: %1").arg(mDev->name());
eventInfo << QString("Device type: %1").arg(deviceTypeToString(mDev->type()));
eventInfo << QString("Pointer type: %1").arg(pointerTypeToString(mDev->pointerType()));
eventInfo << QString("Capabilities: %1").arg(pointerCapabilitiesToString(mDev->capabilities()));
eventInfo << QString("Unique Id: %1").arg(QString::number(mDev->uniqueId().numericId(), 16));
}
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("Keyboard modifiers: %1 (0x%2)").arg(modifiersToString(mModifiers)).arg(mModifiers, 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));
eventInfo << QString("xTilt: %1").arg(QString::number(mXT));
eventInfo << QString("yTilt: %1").arg(QString::number(mYT));
eventInfo << QString("z: %1").arg(QString::number(mZ));
eventInfo << QString("Total wheel events: %1").arg(QString::number(mWheelEventCount));
}
QString text = eventInfo.join("\n");
painter.drawText(rect(), text);
}
const char *TabletWidget::deviceTypeToString(QInputDevice::DeviceType t)
{
static int enumIdx = QInputDevice::staticMetaObject.indexOfEnumerator("DeviceType");
return QPointingDevice::staticMetaObject.enumerator(enumIdx).valueToKey(int(t));
}
const char *TabletWidget::pointerTypeToString(QPointingDevice::PointerType t)
{
static int enumIdx = QPointingDevice::staticMetaObject.indexOfEnumerator("PointerType");
return QPointingDevice::staticMetaObject.enumerator(enumIdx).valueToKey(int(t));
}
QString TabletWidget::pointerCapabilitiesToString(QPointingDevice::Capabilities c)
{
static int enumIdx = QPointingDevice::staticMetaObject.indexOfEnumerator("Capabilities");
return QString::fromLatin1(QPointingDevice::staticMetaObject.enumerator(enumIdx).valueToKeys(c));
}
const char *TabletWidget::buttonToString(Qt::MouseButton b)
{
static int enumIdx = QObject::staticMetaObject.indexOfEnumerator("MouseButtons");
return QObject::staticMetaObject.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(QLatin1Char('|'));
}
QString TabletWidget::modifiersToString(Qt::KeyboardModifiers m)
{
QStringList ret;
if (m & Qt::ShiftModifier)
ret << QLatin1String("Shift");
if (m & Qt::ControlModifier)
ret << QLatin1String("Control");
if (m & Qt::AltModifier)
ret << QLatin1String("Alt");
if (m & Qt::MetaModifier)
ret << QLatin1String("Meta");
if (m & Qt::KeypadModifier)
ret << QLatin1String("Keypad");
if (m & Qt::GroupSwitchModifier)
ret << QLatin1String("GroupSwitch");
return ret.join(QLatin1Char('|'));
}
void TabletWidget::tabletEvent(QTabletEvent *event)
{
event->accept();
}

View File

@ -0,0 +1,49 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef TABLETWIDGET_H
#define TABLETWIDGET_H
#include <QWidget>
#include <QTabletEvent>
#include <QPointer>
#include <QPointingDevice>
#include <QShortcut>
// a widget showing the information of the last tablet event
class TabletWidget : public QWidget
{
public:
TabletWidget(bool mouseToo);
protected:
bool eventFilter(QObject *obj, QEvent *ev);
void tabletEvent(QTabletEvent *event);
void paintEvent(QPaintEvent *event);
const char *deviceTypeToString(QInputDevice::DeviceType t);
const char *pointerTypeToString(QPointingDevice::PointerType t);
QString pointerCapabilitiesToString(QPointingDevice::Capabilities c);
const char *buttonToString(Qt::MouseButton b);
QString buttonsToString(Qt::MouseButtons bs);
QString modifiersToString(Qt::KeyboardModifiers m);
private:
void resetAttributes() {
mDev.clear();
mType = mXT = mYT = mZ = 0;
mPress = mTangential = mRot = 0.0;
mPos = mGPos = QPoint();
}
QPointer<const QPointingDevice> mDev;
int mType;
QPointF mPos, mGPos;
int mXT, mYT, mZ;
Qt::MouseButton mButton;
Qt::MouseButtons mButtons;
Qt::KeyboardModifiers mModifiers;
qreal mPress, mTangential, mRot;
bool mMouseToo;
ulong mTimestamp;
int mWheelEventCount;
QShortcut mQuitShortcut;
};
#endif // TABLETWIDGET_H

View File

@ -0,0 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## event_compression Binary:
#####################################################################
qt_internal_add_manual_test(event_compression
SOURCES
main.cpp
mousestatwidget.cpp mousestatwidget.h
LIBRARIES
Qt::Gui
Qt::Test
Qt::Widgets
)

View File

@ -0,0 +1,5 @@
QT += widgets testlib
SOURCES += main.cpp \
mousestatwidget.cpp
HEADERS += mousestatwidget.h

View File

@ -0,0 +1,20 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "mousestatwidget.h"
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
int main(int argc, char **argv){
QApplication app(argc, argv);
QWidget main;
QVBoxLayout *layout = new QVBoxLayout(&main);
layout->addWidget(new MouseStatWidget(true));
layout->addWidget(new MouseStatWidget(false));
main.resize(800, 600);
main.show();
return app.exec();
}

View File

@ -0,0 +1,61 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "mousestatwidget.h"
#include <QTabletEvent>
#include <QPainter>
#include <QTextOption>
#include <QTest>
MouseStatWidget::MouseStatWidget(bool acceptTabletEvent):acceptTabletEvent(acceptTabletEvent),
receivedMouseEventCount(0),
receivedMouseEventCountToPaint(0),
receivedTabletEventCount(0),
receivedTabletEventCountToPaint(0)
{
startTimer(1000);
}
void MouseStatWidget::tabletEvent(QTabletEvent *event)
{
++receivedTabletEventCount;
if (acceptTabletEvent)
event->accept();
else
event->ignore();
// make sure the event loop is slow
QTest::qSleep(15);
}
void MouseStatWidget::mouseMoveEvent(QMouseEvent *)
{
++receivedMouseEventCount;
}
void MouseStatWidget::timerEvent(QTimerEvent *)
{
receivedMouseEventCountToPaint = receivedMouseEventCount;
receivedTabletEventCountToPaint = receivedTabletEventCount;
receivedMouseEventCount = 0;
receivedTabletEventCount = 0;
update();
}
void MouseStatWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(Qt::black);
painter.drawRect(rect());
QStringList text;
text << ((acceptTabletEvent) ? " - tablet events accepted - " : " - tablet events ignored - ");
text << QString("Number of tablet events received in the last second: %1").arg(QString::number(receivedTabletEventCountToPaint));
text << QString("Number of mouse events received in the last second: %1").arg(QString::number(receivedMouseEventCountToPaint));
QTextOption textOption(Qt::AlignCenter);
textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
painter.drawText(rect(),
text.join("\n"),
textOption);
}

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef MOUSESTATWIDGET_H
#define MOUSESTATWIDGET_H
#include <QWidget>
class QTabletEvent;
class QMouseEvent;
class QTimerEvent;
class QPaintEvent;
class MouseStatWidget : public QWidget
{
public:
MouseStatWidget(bool acceptTabletEvent = true);
protected:
void tabletEvent(QTabletEvent *);
void mouseMoveEvent(QMouseEvent *);
void timerEvent(QTimerEvent *);
void paintEvent(QPaintEvent *);
private:
const bool acceptTabletEvent;
int receivedMouseEventCount;
int receivedMouseEventCountToPaint;
int receivedTabletEventCount;
int receivedTabletEventCountToPaint;
};
#endif // MOUSESTATWIDGET_H

View File

@ -0,0 +1,5 @@
TEMPLATE=subdirs
SUBDIRS = device_information \
event_compression \
regular_widgets

View File

@ -0,0 +1,17 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## regular_widgets Binary:
#####################################################################
qt_internal_add_manual_test(regular_widgets
GUI
SOURCES
main.cpp
LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
Qt::Widgets
)

View File

@ -0,0 +1,387 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QAction>
#include <QApplication>
#include <QCursor>
#include <QDebug>
#include <QDialog>
#include <QDialogButtonBox>
#include <QList>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QMouseEvent>
#include <QPainter>
#include <QPainterPath>
#include <QPlainTextEdit>
#include <QPointingDevice>
#include <QPointer>
#include <QPushButton>
#include <QStatusBar>
#include <QTabletEvent>
#include <QVBoxLayout>
#ifdef Q_OS_WIN
# include <QtGui/private/qguiapplication_p.h>
# include <QtGui/qpa/qplatformintegration.h>
#endif
enum TabletPointType {
TabletButtonPress,
TabletButtonRelease,
TabletMove
};
#ifdef Q_OS_WIN
using QWindowsApplication = QNativeInterface::Private::QWindowsApplication;
static void setWinTabEnabled(bool e)
{
if (auto nativeWindowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration()))
nativeWindowsApp->setWinTabEnabled(e);
}
static bool isWinTabEnabled()
{
auto nativeWindowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration());
return nativeWindowsApp && nativeWindowsApp->isWinTabEnabled();
}
#endif // Q_OS_WIN
struct TabletPoint
{
TabletPoint(const QPointF &p = QPointF(), TabletPointType t = TabletMove, Qt::MouseButton b = Qt::LeftButton,
QPointingDevice::PointerType pt = QPointingDevice::PointerType::Unknown, qreal prs = 0, qreal rotation = 0) :
pos(p), type(t), button(b), ptype(pt), pressure(prs), angle(rotation) {}
QPointF pos;
TabletPointType type;
Qt::MouseButton button;
QPointingDevice::PointerType ptype;
qreal pressure;
qreal angle;
};
class ProximityEventFilter : public QObject
{
Q_OBJECT
public:
explicit ProximityEventFilter(QObject *parent) : QObject(parent) { }
bool eventFilter(QObject *, QEvent *event) override;
static bool tabletPenProximity() { return m_tabletPenProximity; }
signals:
void proximityChanged();
private:
static bool m_tabletPenProximity;
};
bool ProximityEventFilter::eventFilter(QObject *, QEvent *event)
{
switch (event->type()) {
case QEvent::TabletEnterProximity:
case QEvent::TabletLeaveProximity:
ProximityEventFilter::m_tabletPenProximity = event->type() == QEvent::TabletEnterProximity;
emit proximityChanged();
qDebug() << event;
break;
default:
break;
}
return false;
}
bool ProximityEventFilter::m_tabletPenProximity = false;
class EventReportWidget : public QWidget
{
Q_OBJECT
public:
EventReportWidget();
public slots:
void clearPoints() { m_points.clear(); update(); }
signals:
void stats(QString s, int timeOut = 0);
protected:
void mouseDoubleClickEvent(QMouseEvent *event) override { outputMouseEvent(event); }
void mouseMoveEvent(QMouseEvent *event) override { outputMouseEvent(event); }
void mousePressEvent(QMouseEvent *event) override { outputMouseEvent(event); }
void mouseReleaseEvent(QMouseEvent *event) override { outputMouseEvent(event); }
void tabletEvent(QTabletEvent *) override;
bool event(QEvent *event) override;
void paintEvent(QPaintEvent *) override;
void timerEvent(QTimerEvent *) override;
private:
void outputMouseEvent(QMouseEvent *event);
bool m_lastIsMouseMove = false;
bool m_lastIsTabletMove = false;
Qt::MouseButton m_lastButton = Qt::NoButton;
QList<TabletPoint> m_points;
QList<QPointF> m_touchPoints;
QPointF m_tabletPos;
int m_tabletMoveCount = 0;
int m_paintEventCount = 0;
};
EventReportWidget::EventReportWidget()
{
setAttribute(Qt::WA_AcceptTouchEvents);
startTimer(1000);
}
void EventReportWidget::paintEvent(QPaintEvent *)
{
QPainter p(this);
int lineSpacing = fontMetrics().lineSpacing();
int halfLineSpacing = lineSpacing / 2;
const QRectF geom = QRectF(QPoint(0, 0), size());
p.fillRect(geom, Qt::white);
p.drawRect(QRectF(geom.topLeft(), geom.bottomRight() - QPointF(1,1)));
p.setPen(Qt::white);
QPainterPath ellipse;
ellipse.addEllipse(0, 0, halfLineSpacing * 5, halfLineSpacing);
for (const TabletPoint &t : std::as_const(m_points)) {
if (geom.contains(t.pos)) {
QPainterPath pp;
pp.addEllipse(t.pos, halfLineSpacing, halfLineSpacing);
QRectF pointBounds(t.pos.x() - halfLineSpacing, t.pos.y() - halfLineSpacing, lineSpacing, lineSpacing);
switch (t.type) {
case TabletButtonPress:
p.fillPath(pp, Qt::darkGreen);
if (t.button != Qt::NoButton)
p.drawText(pointBounds, Qt::AlignCenter, QString::number(t.button));
break;
case TabletButtonRelease:
p.fillPath(pp, Qt::red);
if (t.button != Qt::NoButton)
p.drawText(pointBounds, Qt::AlignCenter, QString::number(t.button));
break;
case TabletMove:
if (t.pressure > 0.0) {
p.setPen(t.ptype == QPointingDevice::PointerType::Eraser ? Qt::red : Qt::black);
if (t.angle != 0.0) {
p.save();
p.translate(t.pos);
p.scale(t.pressure, t.pressure);
p.rotate(t.angle);
p.drawPath(ellipse);
p.restore();
} else {
p.drawEllipse(t.pos, t.pressure * halfLineSpacing, t.pressure * halfLineSpacing);
}
p.setPen(Qt::white);
} else {
p.fillRect(t.pos.x() - 2, t.pos.y() - 2, 4, 4, Qt::black);
}
break;
}
}
}
// Draw haircross when tablet pen is in proximity
if (ProximityEventFilter::tabletPenProximity() && geom.contains(m_tabletPos)) {
p.setPen(Qt::black);
p.drawLine(QPointF(0, m_tabletPos.y()), QPointF(geom.width(), m_tabletPos.y()));
p.drawLine(QPointF(m_tabletPos.x(), 0), QPointF(m_tabletPos.x(), geom.height()));
}
p.setPen(Qt::blue);
for (QPointF t : m_touchPoints) {
p.drawLine(t.x() - 40, t.y(), t.x() + 40, t.y());
p.drawLine(t.x(), t.y() - 40, t.x(), t.y() + 40);
}
++m_paintEventCount;
}
void EventReportWidget::tabletEvent(QTabletEvent *event)
{
QWidget::tabletEvent(event);
bool isMove = false;
m_tabletPos = event->position();
switch (event->type()) {
case QEvent::TabletMove:
m_points.push_back(TabletPoint(m_tabletPos, TabletMove, m_lastButton, event->pointerType(), event->pressure(), event->rotation()));
update();
isMove = true;
++m_tabletMoveCount;
break;
case QEvent::TabletPress:
m_points.push_back(TabletPoint(m_tabletPos, TabletButtonPress, event->button(), event->pointerType(), event->rotation()));
m_lastButton = event->button();
update();
break;
case QEvent::TabletRelease:
m_points.push_back(TabletPoint(m_tabletPos, TabletButtonRelease, event->button(), event->pointerType(), event->rotation()));
update();
break;
default:
Q_ASSERT(false);
break;
}
if (!(isMove && m_lastIsTabletMove)) {
QDebug d = qDebug();
d << event << " global position = " << event->globalPosition()
<< " cursor at " << QCursor::pos();
if (event->button() != Qt::NoButton)
d << " changed button " << event->button();
}
m_lastIsTabletMove = isMove;
}
bool EventReportWidget::event(QEvent *event)
{
switch (event->type()) {
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
event->accept();
m_touchPoints.clear();
for (const QEventPoint &p : static_cast<const QPointerEvent *>(event)->points())
m_touchPoints.append(p.position());
update();
break;
case QEvent::TouchEnd:
m_touchPoints.clear();
update();
break;
default:
return QWidget::event(event);
}
return true;
}
void EventReportWidget::outputMouseEvent(QMouseEvent *event)
{
if (event->type() == QEvent::MouseMove) {
if (m_lastIsMouseMove)
return; // only show one move to keep things readable
m_lastIsMouseMove = true;
}
qDebug() << event;
}
void EventReportWidget::timerEvent(QTimerEvent *)
{
emit stats(QString("%1 moves/sec, %2 frames/sec").arg(m_tabletMoveCount).arg(m_paintEventCount));
m_tabletMoveCount = 0;
m_paintEventCount = 0;
}
class DevicesDialog : public QDialog
{
Q_OBJECT
public:
explicit DevicesDialog(QWidget *p);
public slots:
void refresh();
private:
QPlainTextEdit *m_edit;
};
DevicesDialog::DevicesDialog(QWidget *p) : QDialog(p)
{
auto layout = new QVBoxLayout(this);
m_edit = new QPlainTextEdit(this);
m_edit->setReadOnly(true);
layout->addWidget(m_edit);
auto box = new QDialogButtonBox(QDialogButtonBox::Close, this);
connect(box, &QDialogButtonBox::rejected, this, &QDialog::reject);
auto refreshButton = box->addButton("Refresh", QDialogButtonBox::ActionRole);
connect(refreshButton, &QAbstractButton::clicked, this, &DevicesDialog::refresh);
layout->addWidget(box);
setWindowTitle("Devices");
refresh();
}
void DevicesDialog::refresh()
{
QString text;
QDebug d(&text);
d.noquote();
d.nospace();
for (auto device : QInputDevice::devices())
d << device<< "\n\n";
m_edit->setPlainText(text);
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(ProximityEventFilter *proximityEventFilter);
public slots:
void showDevices();
private:
QPointer<DevicesDialog> m_devicesDialog;
};
MainWindow::MainWindow(ProximityEventFilter *proximityEventFilter)
{
setWindowTitle(QString::fromLatin1("Tablet Test %1").arg(QT_VERSION_STR));
auto widget = new EventReportWidget;
QObject::connect(proximityEventFilter, &ProximityEventFilter::proximityChanged,
widget, QOverload<>::of(&QWidget::update));
widget->setMinimumSize(640, 480);
auto fileMenu = menuBar()->addMenu("File");
fileMenu->addAction("Clear", widget, &EventReportWidget::clearPoints);
auto showAction = fileMenu->addAction("Show Devices", this, &MainWindow::showDevices);
showAction->setShortcut(Qt::CTRL | Qt::Key_D);
QObject::connect(widget, &EventReportWidget::stats,
statusBar(), &QStatusBar::showMessage);
QAction *quitAction = fileMenu->addAction("Quit", qApp, &QCoreApplication::quit);
quitAction->setShortcut(Qt::CTRL | Qt::Key_Q);
auto settingsMenu = menuBar()->addMenu("Settings");
auto winTabAction = settingsMenu->addAction("WinTab");
winTabAction->setCheckable(true);
#ifdef Q_OS_WIN
winTabAction->setChecked(isWinTabEnabled());
connect(winTabAction, &QAction::toggled, this, setWinTabEnabled);
#else
winTabAction->setEnabled(false);
#endif
setCentralWidget(widget);
}
void MainWindow::showDevices()
{
if (m_devicesDialog.isNull()) {
m_devicesDialog = new DevicesDialog(nullptr);
m_devicesDialog->setModal(false);
m_devicesDialog->resize(500, 300);
m_devicesDialog->move(frameGeometry().topRight() + QPoint(20, 0));
m_devicesDialog->setAttribute(Qt::WA_DeleteOnClose);
}
m_devicesDialog->show();
m_devicesDialog->raise();
m_devicesDialog->refresh();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ProximityEventFilter *proximityEventFilter = new ProximityEventFilter(&app);
app.installEventFilter(proximityEventFilter);
MainWindow mainWindow(proximityEventFilter);
mainWindow.show();
return app.exec();
}
#include "main.moc"

View File

@ -0,0 +1,4 @@
TEMPLATE = app
QT += widgets gui-private core-private
SOURCES += main.cpp