From a8b687b1010f92cbc972a5c1e9dc449b1fa44c38 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 15 Oct 2020 14:37:26 +0200 Subject: [PATCH] Manual tablet test: Add a window showing the devices Task-number: QTBUG-46412 Change-Id: I9cb9bb3493728186e1e6b140308c292ca9662e55 Reviewed-by: Shawn Rutledge --- .../qtabletevent/regular_widgets/main.cpp | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/manual/qtabletevent/regular_widgets/main.cpp b/tests/manual/qtabletevent/regular_widgets/main.cpp index 3b112450b4..187d798339 100644 --- a/tests/manual/qtabletevent/regular_widgets/main.cpp +++ b/tests/manual/qtabletevent/regular_widgets/main.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include #include @@ -37,8 +39,13 @@ #include #include #include +#include +#include +#include +#include #include #include +#include #ifdef Q_OS_WIN # include @@ -296,10 +303,56 @@ void EventReportWidget::timerEvent(QTimerEvent *) 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 m_devicesDialog; }; MainWindow::MainWindow(ProximityEventFilter *proximityEventFilter) @@ -311,6 +364,8 @@ MainWindow::MainWindow(ProximityEventFilter *proximityEventFilter) 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); @@ -329,6 +384,20 @@ MainWindow::MainWindow(ProximityEventFilter *proximityEventFilter) 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);