From 38a5b6212db33700804b83802ef9f0b1423b29cd Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Sun, 27 Sep 2020 11:30:43 +0200 Subject: [PATCH] qtabletevent/regular_widget manual test: Add a toggle for WinTab Task-number: QTBUG-83218 Change-Id: I179f53c051c92dbb86fbac710d4a514c4e5d3c49 Reviewed-by: Shawn Rutledge --- .../regular_widgets/CMakeLists.txt | 4 +- .../qtabletevent/regular_widgets/main.cpp | 68 +++++++++++++++---- .../regular_widgets/regular_widgets.pro | 2 +- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/tests/manual/qtabletevent/regular_widgets/CMakeLists.txt b/tests/manual/qtabletevent/regular_widgets/CMakeLists.txt index 340510fc6b4..b606fcabc26 100644 --- a/tests/manual/qtabletevent/regular_widgets/CMakeLists.txt +++ b/tests/manual/qtabletevent/regular_widgets/CMakeLists.txt @@ -4,12 +4,14 @@ ## regular_widgets Binary: ##################################################################### -qt_internal_add_manual_test(regular_widgets +qt_internal_add_executable(regular_widgets GUI SOURCES main.cpp PUBLIC_LIBRARIES + Qt::CorePrivate Qt::Gui + Qt::GuiPrivate Qt::Widgets ) diff --git a/tests/manual/qtabletevent/regular_widgets/main.cpp b/tests/manual/qtabletevent/regular_widgets/main.cpp index decfc3af741..9f20f5412f8 100644 --- a/tests/manual/qtabletevent/regular_widgets/main.cpp +++ b/tests/manual/qtabletevent/regular_widgets/main.cpp @@ -40,12 +40,33 @@ #include #include +#ifdef Q_OS_WIN +# include +# include +#endif + enum TabletPointType { TabletButtonPress, TabletButtonRelease, TabletMove }; +#ifdef Q_OS_WIN +using QWindowsApplication = QPlatformInterface::Private::QWindowsApplication; + +static void setWinTabEnabled(bool e) +{ + if (auto nativeWindowsApp = dynamic_cast(QGuiApplicationPrivate::platformIntegration())) + nativeWindowsApp->setWinTabEnabled(e); +} + +static bool isWinTabEnabled() +{ + auto nativeWindowsApp = dynamic_cast(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, @@ -275,25 +296,46 @@ void EventReportWidget::timerEvent(QTimerEvent *) m_paintEventCount = 0; } +class MainWindow : public QMainWindow +{ +public: + explicit MainWindow(ProximityEventFilter *proximityEventFilter); +}; + +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); + 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); +} + int main(int argc, char *argv[]) { QApplication app(argc, argv); ProximityEventFilter *proximityEventFilter = new ProximityEventFilter(&app); app.installEventFilter(proximityEventFilter); - QMainWindow mainWindow; - mainWindow.setWindowTitle(QString::fromLatin1("Tablet Test %1").arg(QT_VERSION_STR)); - EventReportWidget *widget = new EventReportWidget; - QObject::connect(proximityEventFilter, &ProximityEventFilter::proximityChanged, - widget, QOverload<>::of(&QWidget::update)); - widget->setMinimumSize(640, 480); - QMenu *fileMenu = mainWindow.menuBar()->addMenu("File"); - fileMenu->addAction("Clear", widget, &EventReportWidget::clearPoints); - QObject::connect(widget, &EventReportWidget::stats, - mainWindow.statusBar(), &QStatusBar::showMessage); - QAction *quitAction = fileMenu->addAction("Quit", qApp, &QCoreApplication::quit); - quitAction->setShortcut(Qt::CTRL | Qt::Key_Q); - mainWindow.setCentralWidget(widget); + MainWindow mainWindow(proximityEventFilter); mainWindow.show(); return app.exec(); } diff --git a/tests/manual/qtabletevent/regular_widgets/regular_widgets.pro b/tests/manual/qtabletevent/regular_widgets/regular_widgets.pro index 8f1f4342ee9..1428d10a04d 100644 --- a/tests/manual/qtabletevent/regular_widgets/regular_widgets.pro +++ b/tests/manual/qtabletevent/regular_widgets/regular_widgets.pro @@ -1,4 +1,4 @@ TEMPLATE = app -QT += widgets +QT += widgets gui-private core-private SOURCES += main.cpp