From d0349e17acc4b0bc2b4a100d2dc786525f36837f Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Mon, 5 Mar 2018 10:18:35 +0100 Subject: tst_QGuiApplication check WindowActivate capability instead of platform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-66849 Change-Id: I31dfe6d38435b043eb21d2de02d44551649444c9 Reviewed-by: Tor Arne Vestbø --- tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 4f27aeb899..b5a69d920a 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -35,9 +35,12 @@ #include #include #include +#include #include #include +#include + #if defined(Q_OS_QNX) #include #endif @@ -203,8 +206,8 @@ void tst_QGuiApplication::focusObject() int argc = 0; QGuiApplication app(argc, 0); - if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("Wayland: This fails. Figure out why."); + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); QObject obj1, obj2, obj3; const QRect screenGeometry = QGuiApplication::primaryScreen()->availableVirtualGeometry(); @@ -374,8 +377,8 @@ void tst_QGuiApplication::changeFocusWindow() int argc = 0; QGuiApplication app(argc, 0); - if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("Wayland: This fails. Figure out why."); + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); const QRect screenGeometry = QGuiApplication::primaryScreen()->availableVirtualGeometry(); -- cgit v1.2.3 From 17b65edad11987f67b97aa9171be426dbfa8a668 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Mon, 5 Mar 2018 10:33:59 +0100 Subject: tst_QInputMethod check WindowActivation capability instead of platform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-66849 Change-Id: I72a8751f1fc0df7ff5a371c854cb975b3cee8fd2 Reviewed-by: Tor Arne Vestbø --- tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp b/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp index 509f8bd45f..15c905f943 100644 --- a/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp +++ b/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp @@ -186,8 +186,8 @@ void tst_qinputmethod::cursorRectangle() { QCOMPARE(qApp->inputMethod()->cursorRectangle(), QRectF()); - if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("Wayland: This fails. Figure out why."); + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); DummyWindow window; window.show(); @@ -284,8 +284,8 @@ void tst_qinputmethod::inputDirection() void tst_qinputmethod::inputMethodAccepted() { - if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("Wayland: This fails. Figure out why."); + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); if (!QGuiApplication::platformName().compare(QLatin1String("minimal"), Qt::CaseInsensitive) || !QGuiApplication::platformName().compare(QLatin1String("offscreen"), Qt::CaseInsensitive)) { -- cgit v1.2.3 From 951e204b29bf42459e8cfdf42eadec5fa250226b Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Mon, 5 Mar 2018 11:24:55 +0100 Subject: Skip failing tests in tst_QPixmap on Wayland Task-number: QTBUG-66846 Change-Id: I61bd3e59e51fd1d988a30b6454a6a90650a3069b Reviewed-by: Eirik Aavitsland --- tests/auto/gui/image/qpixmap/tst_qpixmap.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index e3bda6c2df..de6713596d 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -527,8 +527,16 @@ void tst_QPixmap::fill_transparent() QVERIFY(pixmap.hasAlphaChannel()); } +static bool isPlatformWayland() +{ + return QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive); +} + void tst_QPixmap::mask() { + if (isPlatformWayland()) + QSKIP("Wayland: This fails. See QTBUG-66983."); + QPixmap pm(100, 100); QBitmap bm(100, 100); @@ -770,6 +778,9 @@ void tst_QPixmap::convertFromImageNoDetach() void tst_QPixmap::convertFromImageNoDetach2() { + if (isPlatformWayland()) + QSKIP("Wayland: This fails. See QTBUG-66984."); + QPixmap randomPixmap(10, 10); if (randomPixmap.handle()->classId() != QPlatformPixmap::RasterClass) QSKIP("Test only valid for raster pixmaps"); @@ -1444,6 +1455,9 @@ void tst_QPixmap::fromImageReaderAnimatedGif() void tst_QPixmap::task_246446() { + if (isPlatformWayland()) + QSKIP("Wayland: This fails. See QTBUG-66985."); + // This crashed without the bugfix in 246446 QPixmap pm(10, 10); pm.fill(Qt::transparent); // force 32-bit depth -- cgit v1.2.3 From 3ae03c3585df7247f5699eeaa70e1bedf47f6d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 9 Mar 2018 12:03:01 +0100 Subject: testlib: Silence all Qt logging in selftests Otherwise random debug messages from Qt might mess up the expected vs actual results. The setting of QT_LOGGING_RULES in initTestcase has been removed, as the selftest overrides that for each invocation of a subtests, via the processEnvironment() function. Task-number: QTQAINFRA-1631 Change-Id: I855d31274f8261f8b125df23409353f7101be0e4 Reviewed-by: Friedemann Kleint --- tests/auto/testlib/selftests/generate_expected_output.py | 2 +- tests/auto/testlib/selftests/tst_selftests.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/testlib/selftests/generate_expected_output.py b/tests/auto/testlib/selftests/generate_expected_output.py index 6c14d75ea6..aa11ca4fe7 100755 --- a/tests/auto/testlib/selftests/generate_expected_output.py +++ b/tests/auto/testlib/selftests/generate_expected_output.py @@ -257,7 +257,7 @@ def main(name, *args): # Avoid interference from any qtlogging.ini files, e.g. in # /etc/xdg/QtProject/, (must match tst_selftests.cpp's # processEnvironment()'s value): - QT_LOGGING_RULES = '*.debug=true;qt.qpa.screen=false') + QT_LOGGING_RULES = '*.debug=true;qt.*=false') herePath = os.getcwd() cleaner = Cleaner(herePath, name) diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 93d5daa160..63e5721e7e 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -404,7 +404,6 @@ tst_Selftests::tst_Selftests() void tst_Selftests::initTestCase() { QVERIFY2(tempDir.isValid(), qPrintable(tempDir.errorString())); - qputenv("QT_LOGGING_RULES", QByteArrayLiteral("*.debug=false")); // Silence any debug output //Detect the location of the sub programs QString subProgram = QLatin1String("float/float"); #if defined(Q_OS_WIN) @@ -644,7 +643,7 @@ static QProcessEnvironment processEnvironment() // Avoid interference from any qtlogging.ini files, e.g. in /etc/xdg/QtProject/: result.insert(QStringLiteral("QT_LOGGING_RULES"), // Must match generate_expected_output.py's main()'s value: - QStringLiteral("*.debug=true;qt.qpa.screen=false")); + QStringLiteral("*.debug=true;qt.*=false")); } return result; } -- cgit v1.2.3 From 54190595efe55bdbb647c69fa7b0a43d3f84dd68 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 28 Jul 2017 13:25:50 +0200 Subject: Make sure QDir::absoluteFilePath("/dir") includes a drive on MS QDir::isAbsolutePath(name) thinks any path starting with a slash is absolute; however, to return a valid absolute path, we need to put a drive prefix onto such a name. So use QFileSystemEntry::isAbsolute() for that check (it believes in the need for a drive, or UNC prefix) and handle the absolute-but-for-drive case when it arises. Add a regression test and make related changes to existing tests. Task-number: QTBUG-50839 Change-Id: Id5d2b2586bb1423fa2d9375a298a4bb5241cffe0 Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qdir/tst_qdir.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 9d47bb2884..734b26cd65 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -1384,16 +1384,22 @@ void tst_QDir::absoluteFilePath_data() QTest::addColumn("fileName"); QTest::addColumn("expectedFilePath"); - QTest::newRow("0") << "/etc" << "/passwd" << "/passwd"; - QTest::newRow("1") << "/etc" << "passwd" << "/etc/passwd"; - QTest::newRow("2") << "/" << "passwd" << "/passwd"; - QTest::newRow("3") << "relative" << "path" << QDir::currentPath() + "/relative/path"; - QTest::newRow("4") << "" << "" << QDir::currentPath(); #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) - QTest::newRow("5") << "//machine" << "share" << "//machine/share"; + QTest::newRow("UNC") << "//machine" << "share" << "//machine/share"; + QTest::newRow("Drive") << "c:/side/town" << "/my/way/home" << "c:/my/way/home"; +#define DRIVE "Q:" +#else +#define DRIVE #endif + QTest::newRow("0") << DRIVE "/etc" << "/passwd" << DRIVE "/passwd"; + QTest::newRow("1") << DRIVE "/etc" << "passwd" << DRIVE "/etc/passwd"; + QTest::newRow("2") << DRIVE "/" << "passwd" << DRIVE "/passwd"; + QTest::newRow("3") << "relative" << "path" << QDir::currentPath() + "/relative/path"; + QTest::newRow("4") << "" << "" << QDir::currentPath(); + QTest::newRow("resource") << ":/prefix" << "foo.bar" << ":/prefix/foo.bar"; +#undef DRIVE } void tst_QDir::absoluteFilePath() -- cgit v1.2.3 From 0e37558b6edd0cbdfa2a3bc8d67d9170c7917d7f Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Mon, 5 Mar 2018 10:44:03 +0100 Subject: Don't skip tests in tst_QTouchEvent on Wayland They seem to be running just fine Task-number: QTBUG-66849 Change-Id: Ia48d47c0fff173eb1d6eba38bdba752a91bd2b56 Reviewed-by: Shawn Rutledge --- .../auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'tests') diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp index 706c66ef14..d16d95500b 100644 --- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp +++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp @@ -317,9 +317,6 @@ void tst_QTouchEvent::touchDisabledByDefault() void tst_QTouchEvent::touchEventAcceptedByDefault() { - if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("Wayland: This fails. Figure out why."); - // QWidget { // enabling touch events should automatically accept touch events @@ -606,9 +603,6 @@ QPointF normalized(const QPointF &pos, const QRectF &rect) void tst_QTouchEvent::basicRawEventTranslation() { - if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("Wayland: This fails. Figure out why."); - tst_QTouchEventWidget touchWidget; touchWidget.setWindowTitle(QTest::currentTestFunction()); touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); @@ -733,9 +727,6 @@ void tst_QTouchEvent::basicRawEventTranslation() void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() { - if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("Wayland: This fails. Figure out why."); - tst_QTouchEventWidget touchWidget; touchWidget.setWindowTitle(QTest::currentTestFunction()); touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); @@ -962,9 +953,6 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() { - if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("Wayland: This fails. Figure out why."); - tst_QTouchEventWidget touchWidget; touchWidget.setWindowTitle(QTest::currentTestFunction()); touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); @@ -1191,9 +1179,6 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() void tst_QTouchEvent::basicRawEventTranslationOfIds() { - if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("Wayland: This fails. Figure out why."); - tst_QTouchEventWidget touchWidget; touchWidget.setWindowTitle(QTest::currentTestFunction()); touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); @@ -1311,9 +1296,6 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds() void tst_QTouchEvent::deleteInEventHandler() { - if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("Wayland: This fails. Figure out why."); - // QWidget { QWidget window; @@ -1463,9 +1445,6 @@ void tst_QTouchEvent::deleteInEventHandler() void tst_QTouchEvent::deleteInRawEventTranslation() { - if (!QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) - QSKIP("Wayland: This fails. Figure out why."); - tst_QTouchEventWidget touchWidget; touchWidget.setWindowTitle(QTest::currentTestFunction()); touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); -- cgit v1.2.3 From c0272f98df87afde411e14358f65caa79991a9be Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 8 Mar 2018 15:56:10 +0100 Subject: Expand Config to Configuration in method names Commit f55c73ede28d4455f555a28e401407326ac9b954 added various backendConfig methods; API review for 5.11 pointed out that Config should not be abbreviated. Change-Id: I3b294b44a030b2a6e4cdd034fa27583c228dfe42 Reviewed-by: Timur Pocheptsov --- tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index f77afd2364..1332b369e7 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -4016,12 +4016,12 @@ void tst_QSslSocket::signatureAlgorithm() SslServer server; server.protocol = serverProtocol; server.config.setCiphers({QSslCipher("ECDHE-RSA-AES256-SHA")}); - server.config.setBackendConfigOption(QByteArrayLiteral("SignatureAlgorithms"), serverSigAlgPairs.join(':')); + server.config.setBackendConfigurationOption(QByteArrayLiteral("SignatureAlgorithms"), serverSigAlgPairs.join(':')); QVERIFY(server.listen()); QSslConfiguration clientConfig = QSslConfiguration::defaultConfiguration(); clientConfig.setProtocol(clientProtocol); - clientConfig.setBackendConfigOption(QByteArrayLiteral("SignatureAlgorithms"), clientSigAlgPairs.join(':')); + clientConfig.setBackendConfigurationOption(QByteArrayLiteral("SignatureAlgorithms"), clientSigAlgPairs.join(':')); QSslSocket client; client.setSslConfiguration(clientConfig); socket = &client; -- cgit v1.2.3 From 39d2a11a86669aa975860b7a074d338d4da0d7fc Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 14 Mar 2018 10:16:00 +0100 Subject: Item views: Fix 5.11 API review findings Rename getter QHeaderView::firstSectionMovable() to QHeaderView::isFirstSectionMovable(), turn into a property and fix \since. Change-Id: Ica2ca43d22f3fd78ff63178ba75014807fc9b823 Reviewed-by: David Faure --- tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 812ca4b223..74a2f7f2b6 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -544,11 +544,11 @@ void tst_QHeaderView::movable() view->setSectionsMovable(true); QCOMPARE(view->sectionsMovable(), true); - QCOMPARE(view->firstSectionMovable(), true); + QCOMPARE(view->isFirstSectionMovable(), true); view->setFirstSectionMovable(false); - QCOMPARE(view->firstSectionMovable(), false); + QCOMPARE(view->isFirstSectionMovable(), false); view->setFirstSectionMovable(true); - QCOMPARE(view->firstSectionMovable(), true); + QCOMPARE(view->isFirstSectionMovable(), true); } void tst_QHeaderView::clickable() -- cgit v1.2.3 From 00304eac7b1ddd22b971da78aa84c86fe2919359 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 14 Mar 2018 12:52:10 +0100 Subject: Revert "Set sharedPainter correctly for QGraphicsEffect" This reverts commit 7257862fb2edfab0219d6cd45c83677049404f7d. It has been reported that this patch causes widgets with certain effects become invisible. Task-number: QTBUG-60231 Task-number: QTBUG-66803 Task-number: QTBUG-66387 Change-Id: I9c3c4cf2f17ac639d1aee5489b665aa1e165af16 Reviewed-by: Friedemann Kleint --- .../effects/qgraphicseffect/tst_qgraphicseffect.cpp | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp index dfe5baba71..a1cb729849 100644 --- a/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp @@ -52,7 +52,6 @@ private slots: void boundingRect2(); void draw(); void opacity(); - void nestedOpaqueOpacity(); void grayscale(); void colorize(); void drawPixmapItem(); @@ -408,26 +407,6 @@ void tst_QGraphicsEffect::opacity() QCOMPARE(effect->m_opacity, qreal(0.5)); } -void tst_QGraphicsEffect::nestedOpaqueOpacity() -{ - // QTBUG-60231: Nesting widgets with a QGraphicsEffect on a toplevel with - // QGraphicsOpacityEffect caused crashes due to constructing several - // QPainter instances on a device in the fast path for - // QGraphicsOpacityEffect::opacity=1 - QWidget topLevel; - topLevel.setWindowTitle(QTest::currentTestFunction()); - topLevel.resize(320, 200); - QGraphicsOpacityEffect *opacityEffect = new QGraphicsOpacityEffect; - opacityEffect->setOpacity(1); - topLevel.setGraphicsEffect(opacityEffect); - QWidget *child = new QWidget(&topLevel); - child->resize(topLevel.size() / 2); - QGraphicsDropShadowEffect *childEffect = new QGraphicsDropShadowEffect; - child->setGraphicsEffect(childEffect); - topLevel.show(); - QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); -} - void tst_QGraphicsEffect::grayscale() { if (qApp->desktop()->depth() < 24) -- cgit v1.2.3 From ed245f3e70661a1e02467393918feef4b5af8197 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 12 Mar 2018 17:09:18 +0100 Subject: Manual tablet test: Draw crosshairs when tablet pen is close Crosshairs provide better visual feedback for coordinate conversions. Change-Id: I20f67733d7a5e6b1455507a39a8b9535202a92c4 Reviewed-by: Shawn Rutledge --- tests/manual/qtabletevent/regular_widgets/main.cpp | 60 ++++++++++++++++------ 1 file changed, 44 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/manual/qtabletevent/regular_widgets/main.cpp b/tests/manual/qtabletevent/regular_widgets/main.cpp index caf8c70c6f..c0366dea63 100644 --- a/tests/manual/qtabletevent/regular_widgets/main.cpp +++ b/tests/manual/qtabletevent/regular_widgets/main.cpp @@ -61,23 +61,38 @@ struct TabletPoint class ProximityEventFilter : public QObject { + Q_OBJECT public: explicit ProximityEventFilter(QObject *parent) : QObject(parent) { } - bool eventFilter(QObject *, QEvent *event) override - { - switch (event->type()) { - case QEvent::TabletEnterProximity: - case QEvent::TabletLeaveProximity: - qDebug() << event; - break; - default: - break; - } - return false; - } + 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 @@ -111,6 +126,7 @@ private: Qt::MouseButton m_lastButton = Qt::NoButton; QVector m_points; QVector m_touchPoints; + QPointF m_tabletPos; int m_tabletMoveCount = 0; int m_paintEventCount = 0; }; @@ -169,6 +185,13 @@ void EventReportWidget::paintEvent(QPaintEvent *) } } } + + // 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()); @@ -181,20 +204,21 @@ void EventReportWidget::tabletEvent(QTabletEvent *event) { QWidget::tabletEvent(event); bool isMove = false; + m_tabletPos = event->posF(); switch (event->type()) { case QEvent::TabletMove: - m_points.push_back(TabletPoint(event->pos(), TabletMove, m_lastButton, event->pointerType(), event->pressure(), event->rotation())); + 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(event->pos(), TabletButtonPress, event->button(), event->pointerType(), event->rotation())); + 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(event->pos(), TabletButtonRelease, event->button(), event->pointerType(), event->rotation())); + m_points.push_back(TabletPoint(m_tabletPos, TabletButtonRelease, event->button(), event->pointerType(), event->rotation())); update(); break; default: @@ -253,10 +277,14 @@ void EventReportWidget::timerEvent(QTimerEvent *) int main(int argc, char *argv[]) { QApplication app(argc, argv); - app.installEventFilter(new ProximityEventFilter(&app)); + + 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); -- cgit v1.2.3