From 342f18c71f51227a062bd204037541ecae150846 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 4 Oct 2016 12:58:02 +0200 Subject: Check qgl_current_fbo_invalid before using qgl_current_fbo QSG24BitTextMaskShader::useSRGB() on macOS accesses the current context qgl_current_fbo member without first checking if it is valid. Make sure it also checks qgl_current_fbo_invalid, thus not accidentally dereferencing a dangling pointer. Change-Id: I56a77de23ee3b4b271bd848506ff26e14d7b6d15 Reviewed-by: Laszlo Agocs --- src/quick/scenegraph/qsgdefaultglyphnode_p.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp index 3eba29ba41..5ef5c79416 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp @@ -233,7 +233,8 @@ bool QSG24BitTextMaskShader::useSRGB() const // m_useSRGB is true, but if some QOGLFBO was bound check it's texture format: QOpenGLContext *ctx = QOpenGLContext::currentContext(); QOpenGLFramebufferObject *qfbo = QOpenGLContextPrivate::get(ctx)->qgl_current_fbo; - return !qfbo || qfbo->format().internalTextureFormat() == GL_SRGB8_ALPHA8_EXT; + bool fboInvalid = QOpenGLContextPrivate::get(ctx)->qgl_current_fbo_invalid; + return !qfbo || fboInvalid || qfbo->format().internalTextureFormat() == GL_SRGB8_ALPHA8_EXT; #else return m_useSRGB; #endif -- cgit v1.2.3 From 67e5fe1675b459de9a688be2509a060e8ccecc9e Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Sat, 1 Oct 2016 01:44:59 +0200 Subject: Remove superfluous warning statement in QAccessibleQuickItem::rect() The warning statement is printed whenever a successful hit test (essentialy a hover) happens on a QML item which is accessible (e.g. a Label) and also not visible. The message looks like "QQuickText QVariant(Invalid) QRect(0,0 0x0)". The information serves no real purpose though: 1) The property accessibleText is not set anywhere 2) The warning happens in a valid use case when an item is invisible, and the user mouse accidentally hovers over its position Change-Id: I8d20f7842d92c7944bb5e3b614ecd6fad500102a Reviewed-by: Frederik Gladhorn --- src/quick/accessible/qaccessiblequickitem.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/quick/accessible/qaccessiblequickitem.cpp b/src/quick/accessible/qaccessiblequickitem.cpp index 2ce914c0b6..df99d43531 100644 --- a/src/quick/accessible/qaccessiblequickitem.cpp +++ b/src/quick/accessible/qaccessiblequickitem.cpp @@ -61,10 +61,6 @@ int QAccessibleQuickItem::childCount() const QRect QAccessibleQuickItem::rect() const { const QRect r = itemScreenRect(item()); - - if (!r.isValid()) { - qWarning() << item()->metaObject()->className() << item()->property("accessibleText") << r; - } return r; } -- cgit v1.2.3 From 6d732026a518741718528052656a513761451b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Martins?= Date: Fri, 14 Oct 2016 12:05:08 +0100 Subject: Fix docs about ownership when QObject has a parent If you return a QObject with parent from a Q_INVOKABLE it *does* get QQmlEngine::JavaScriptOwnership. It just doesn't get deleted by JavaScript (until you unset it's parent). Change-Id: Id56debe06253ea1dd31dee844f5047d4ac055024 Reviewed-by: Simon Hausmann --- src/qml/doc/src/cppintegration/data.qdoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qml/doc/src/cppintegration/data.qdoc b/src/qml/doc/src/cppintegration/data.qdoc index ff30bffa83..1b75f6d14e 100644 --- a/src/qml/doc/src/cppintegration/data.qdoc +++ b/src/qml/doc/src/cppintegration/data.qdoc @@ -52,8 +52,8 @@ remain with C++ by invoking QQmlEngine::setObjectOwnership() with QQmlEngine::CppOwnership specified. Additionally, the QML engine respects the normal QObject parent ownership -semantics of Qt C++ objects, and will not ever take ownership of a QObject -instance which already has a parent. +semantics of Qt C++ objects, and will never delete a QObject instance which +has a parent. \section1 Basic Qt Data Types -- cgit v1.2.3 From 654e9e6a35682d2dbd468b82a954b55fef8b6e70 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sat, 15 Oct 2016 13:19:07 +0200 Subject: QQuickWindow: don't discard timestamps for wheel events Noticed while debugging QTBUG-56075 on XCB. QQuickFlickable did not receive timestamps for wheel events provided by XI2. This alone does not fix the flicking speed issue with high-precision trackpads, but is needed to be able to calculate the appropriate velocity. Task-number: QTBUG-56075 Change-Id: I458e6302aee72863cdc1f8e8f7d99449016905a9 Reviewed-by: Shawn Rutledge --- src/quick/items/qquickwindow.cpp | 1 + tests/auto/quick/qquickitem/tst_qquickitem.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 26d83cfdf5..7875005e2d 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -1827,6 +1827,7 @@ bool QQuickWindowPrivate::deliverWheelEvent(QQuickItem *item, QWheelEvent *event if (item->contains(p)) { QWheelEvent wheel(p, p, event->pixelDelta(), event->angleDelta(), event->delta(), event->orientation(), event->buttons(), event->modifiers(), event->phase(), event->source()); + wheel.setTimestamp(event->timestamp()); wheel.accept(); q->sendEvent(item, &wheel); if (wheel.isAccepted()) { diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp index a403b3e42b..3a9b752f6c 100644 --- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp @@ -53,7 +53,7 @@ public: TestItem(QQuickItem *parent = 0) : QQuickItem(parent), focused(false), pressCount(0), releaseCount(0) , wheelCount(0), acceptIncomingTouchEvents(true) - , touchEventReached(false) {} + , touchEventReached(false), timestamp(0) {} bool focused; int pressCount; @@ -61,6 +61,7 @@ public: int wheelCount; bool acceptIncomingTouchEvents; bool touchEventReached; + ulong timestamp; protected: virtual void focusInEvent(QFocusEvent *) { Q_ASSERT(!focused); focused = true; } virtual void focusOutEvent(QFocusEvent *) { Q_ASSERT(focused); focused = false; } @@ -70,7 +71,7 @@ protected: touchEventReached = true; event->setAccepted(acceptIncomingTouchEvents); } - virtual void wheelEvent(QWheelEvent *event) { event->accept(); ++wheelCount; } + virtual void wheelEvent(QWheelEvent *event) { event->accept(); ++wheelCount; timestamp = event->timestamp(); } }; class TestWindow: public QQuickWindow @@ -1435,12 +1436,14 @@ void tst_qquickitem::wheelEvent() item->setVisible(visible); QWheelEvent event(QPoint(100, 50), -120, Qt::NoButton, Qt::NoModifier, Qt::Vertical); + event.setTimestamp(123456UL); event.setAccepted(false); QGuiApplication::sendEvent(&window, &event); if (shouldReceiveWheelEvents) { QVERIFY(event.isAccepted()); QCOMPARE(item->wheelCount, 1); + QCOMPARE(item->timestamp, 123456UL); } else { QVERIFY(!event.isAccepted()); QCOMPARE(item->wheelCount, 0); -- cgit v1.2.3 From e858dc4701912c5c4e94a99d819d3a86a6ee92b3 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 19 Oct 2016 09:27:10 +0200 Subject: Fix TextInput::selectByMouse documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I41ef6b38e74162434c397535f9d73fff80e29c78 Reviewed-by: Topi Reiniƶ --- src/quick/items/qquicktextinput.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 072bfd3440..9e4b01a373 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -2206,8 +2206,8 @@ QString QQuickTextInput::displayText() const If true, the user can use the mouse to select text in some platform-specific way. Note that for some platforms this may - not be an appropriate interaction (eg. may conflict with how - the text needs to behave inside a Flickable. + not be an appropriate interaction (it may conflict with how + the text needs to behave inside a \l Flickable, for example). */ bool QQuickTextInput::selectByMouse() const { -- cgit v1.2.3 From 20bfb6a7d60f03c44e1ad25438ea1f78d59717ff Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 20 Oct 2016 21:57:28 +0200 Subject: tst_qquicktext: remove bogus blacklisting There's no such test as mouseSelection in tst_qquicktext. Change-Id: I09bf4c61b53acd9811e020379a29c80fce9fe48b Reviewed-by: Frederik Gladhorn --- tests/auto/quick/qquicktext/BLACKLIST | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/auto/quick/qquicktext/BLACKLIST b/tests/auto/quick/qquicktext/BLACKLIST index 0c65f1e245..2e4349a310 100644 --- a/tests/auto/quick/qquicktext/BLACKLIST +++ b/tests/auto/quick/qquicktext/BLACKLIST @@ -1,4 +1,2 @@ [dependentImplicitSizes] * -[mouseSelection] -* -- cgit v1.2.3 From bb8ae2d0a0ff9f36ffaf4ba64b03bd2160c99cd2 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 21 Oct 2016 13:58:58 +0200 Subject: tst_qquicktextedit: remove mouseDoubleClickInterval wait Since qtbase commit beef975, QTestLib avoids generating accidental double click events by adding 500ms timestamp delta on release events. Thus, now we can remove the QStyleHints::mouseDoubleClickInterval wait, which were there to prevent the aforementioned accidental double click events that can no longer happen. The default inverval is 400ms, so this saves us nearly half a second on most platforms. Change-Id: I7a670b70c012ac027dc951ebafdf5e7d53b89ce9 Reviewed-by: Friedemann Kleint --- tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 7f454aaa11..580c25b225 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -2963,9 +2963,6 @@ void tst_qquicktextedit::middleClickPaste() // Middle click pastes the selected text, assuming the platform supports it. QTest::mouseClick(&window, Qt::MiddleButton, Qt::NoModifier, p3); - // ### This is to prevent double click detection from carrying over to the next test. - QTest::qWait(QGuiApplication::styleHints()->mouseDoubleClickInterval() + 10); - if (QGuiApplication::clipboard()->supportsSelection()) QCOMPARE(textEditObject->text().mid(1, selectedText.length()), selectedText); else -- cgit v1.2.3 From 55b9c7c1bdc7ccaf3126622e72843a3c247cbaf4 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 20 Oct 2016 21:38:30 +0200 Subject: Make tst_qquicktextedit::mouseSelection() pass Since qtbase commit beef975, QTestLib avoids generating accidental double click events by adding 500ms timestamp delta on release events. The test requires a press-and-drag-and-release type of sequence with double and triple clicks. The triple-click case is handled fine with QTest::mouseDClick() + press + move + release, but the double-click case is using QTest::mouseClick() + press + move + release and relies on the accidental double-click event generation that QTestLib now deliberately prevents. I can't think of a nice way to inject the move event in the middle of a double-click sequence generated by QTest::mouseDClick(), so we just send the missing double-click event by hand. We can also remove the QStyleHints::mouseDoubleClickInterval waits, which were there to prevent the aforementioned accidental double click events that can no longer happen. This reduces the total execution time of mouseSelection() by roughly 90%. Task-number: QTBUG-50022 Change-Id: I252e87d6a49ea86a44cfa347a29eebee12fd36d1 Reviewed-by: Mitch Curtis Reviewed-by: Frederik Gladhorn --- tests/auto/quick/qquicktextedit/BLACKLIST | 2 -- tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp | 13 ++++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 tests/auto/quick/qquicktextedit/BLACKLIST diff --git a/tests/auto/quick/qquicktextedit/BLACKLIST b/tests/auto/quick/qquicktextedit/BLACKLIST deleted file mode 100644 index 492d81531a..0000000000 --- a/tests/auto/quick/qquicktextedit/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[mouseSelection] -* diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 580c25b225..d007e7c98d 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -2006,12 +2006,18 @@ void tst_qquicktextedit::mouseSelection() else if (clicks == 3) QTest::mouseDClick(&window, Qt::LeftButton, Qt::NoModifier, p1); QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p1); + if (clicks == 2) { + // QTBUG-50022: Since qtbase commit beef975, QTestLib avoids generating + // double click events by adding 500ms delta to release event timestamps. + // Send a double click event by hand to ensure the correct sequence: + // press, release, press, _dbl click_, move, release. + QMouseEvent dblClickEvent(QEvent::MouseButtonDblClick, p1, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); + QGuiApplication::sendEvent(textEditObject, &dblClickEvent); + } QTest::mouseMove(&window, p2); QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p2); QTRY_COMPARE(textEditObject->selectedText(), selectedText); - QTest::qWait(QGuiApplication::styleHints()->mouseDoubleClickInterval() + 10); - // Clicking and shift to clicking between the same points should select the same text. textEditObject->setCursorPosition(0); if (clicks > 1) @@ -2020,9 +2026,6 @@ void tst_qquicktextedit::mouseSelection() QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, p1); QTest::mouseClick(&window, Qt::LeftButton, Qt::ShiftModifier, p2); QTRY_COMPARE(textEditObject->selectedText(), selectedText); - - // ### This is to prevent double click detection from carrying over to the next test. - QTest::qWait(QGuiApplication::styleHints()->mouseDoubleClickInterval() + 10); } void tst_qquicktextedit::dragMouseSelection() -- cgit v1.2.3 From 9f6ae7fce68d1592b71be7df7ebfffade60ef737 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 21 Oct 2016 18:38:50 +0200 Subject: Fix QML Compiler crash After commit 2afb54fb51091765f79548b0b057795bc3c6eb38, Primitive::undefinedValue() uses setM() to clear out all bits. Previously that code was #ifndef'ed out for the bootstrap build, but now that we can do the correct boxing in host builds (as we know the pointer size), we can re-enable setM() in bootstrap builds and fix this crash that was a Q_UNREACHABLE() assertion. Change-Id: I49036792c06c9a17272aba65261ab8f32beb2ad8 Task-number: QTBUG-56658 Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4value_p.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index 13339129eb..5b6688f6b4 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -169,10 +169,7 @@ public: Q_ALWAYS_INLINE quint32 value() const { return _val & quint64(~quint32(0)); } Q_ALWAYS_INLINE quint32 tag() const { return _val >> 32; } -#if defined(V4_BOOTSTRAP) - Q_ALWAYS_INLINE Heap::Base *m() const { Q_UNREACHABLE(); return Q_NULLPTR; } - Q_ALWAYS_INLINE void setM(Heap::Base *b) { Q_UNUSED(b); Q_UNREACHABLE(); } -#elif defined(QV4_USE_64_BIT_VALUE_ENCODING) +#if defined(QV4_USE_64_BIT_VALUE_ENCODING) Q_ALWAYS_INLINE Heap::Base *m() const { Heap::Base *b; -- cgit v1.2.3 From ffedab7ba0ecc816ebf5d80d1414d1972e61029b Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 21 Oct 2016 10:26:18 +0200 Subject: Add a test for bitmap font rendering in Qt Quick The "fixedsys" font is available on Windows at least, so while this test may not add any value on other platforms, it won't hurt either, and this was something that regressed on Windows before. Task-number: QTBUG-56659 Change-Id: Id01dedcbdc2fe74027caf31dd0dde6729ade8c63 Reviewed-by: Eirik Aavitsland --- .../scenegraph_lancelot/data/text/text_bitmapfont.qml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/manual/scenegraph_lancelot/data/text/text_bitmapfont.qml diff --git a/tests/manual/scenegraph_lancelot/data/text/text_bitmapfont.qml b/tests/manual/scenegraph_lancelot/data/text/text_bitmapfont.qml new file mode 100644 index 0000000000..d1a289e24f --- /dev/null +++ b/tests/manual/scenegraph_lancelot/data/text/text_bitmapfont.qml @@ -0,0 +1,18 @@ +// test use of Fixedsys font on Windows + +import QtQuick 2.0 + +Item { + width: 320 + height: 480 + + Text { + anchors.fill: parent + wrapMode: Text.Wrap + font.family: "Fixedsys" + font.pixelSize: 20 + text: "Foobar" + } +} + + -- cgit v1.2.3 From c849f3a7eff55d60c4010831ec67336c5c0f2a27 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 26 Oct 2016 08:21:00 +0200 Subject: Fix documentation for dragFinished signal Change-Id: I9a38ab8ff60921e6d5ff6c2fa476b24d28781feb Reviewed-by: Venugopal Shivashankar --- src/quick/items/qquickdrag.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp index 71217ce146..d3c7adf2ba 100644 --- a/src/quick/items/qquickdrag.cpp +++ b/src/quick/items/qquickdrag.cpp @@ -701,7 +701,7 @@ void QQuickDragAttached::cancel() */ /*! - \qmlattachedsignal QtQuick::Drag::dragFinished(DropAction action) + \qmlattachedsignal QtQuick::Drag::dragFinished(DropAction dropAction) This signal is emitted when a drag finishes and the drag was started with the \l startDrag() method or started automatically using the \l dragType property. -- cgit v1.2.3 From 93d7c26653757755ae65f14d06d6df6f9ec2fc07 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sun, 16 Oct 2016 19:21:29 +0200 Subject: QQuickShortcut: allow setting a custom context matcher This allows Qt Quick Controls 2 to register a shortcut context matcher that makes shortcuts behave well with QQC2's item-based popups, which QQuickShortcut is not aware of. Task-number: QTBUG-56562 Change-Id: Ia2518fd6ac7140f60aa38c7d9af557007e9db23b Reviewed-by: Mitch Curtis Reviewed-by: Qt CI Bot --- src/quick/util/qquickshortcut.cpp | 55 ++++++++++++------- .../quick/qquickshortcut/tst_qquickshortcut.cpp | 64 ++++++++++++++++++++++ 2 files changed, 99 insertions(+), 20 deletions(-) diff --git a/src/quick/util/qquickshortcut.cpp b/src/quick/util/qquickshortcut.cpp index 9725ddd671..3e04161639 100644 --- a/src/quick/util/qquickshortcut.cpp +++ b/src/quick/util/qquickshortcut.cpp @@ -41,10 +41,9 @@ #include #include +#include #include -QT_BEGIN_NAMESPACE - /*! \qmltype Shortcut \instantiates QQuickShortcut @@ -89,6 +88,39 @@ QT_BEGIN_NAMESPACE The corresponding handler is \c onActivatedAmbiguously. */ +static bool qQuickShortcutContextMatcher(QObject *obj, Qt::ShortcutContext context) +{ + switch (context) { + case Qt::ApplicationShortcut: + return true; + case Qt::WindowShortcut: + while (obj && !obj->isWindowType()) { + obj = obj->parent(); + if (QQuickItem *item = qobject_cast(obj)) + obj = item->window(); + } + return obj && obj == QGuiApplication::focusWindow(); + default: + return false; + } +} + +typedef bool (*ContextMatcher)(QObject *, Qt::ShortcutContext); + +Q_GLOBAL_STATIC_WITH_ARGS(ContextMatcher, ctxMatcher, (qQuickShortcutContextMatcher)) + +Q_QUICK_PRIVATE_EXPORT ContextMatcher qt_quick_shortcut_context_matcher() +{ + return *ctxMatcher(); +} + +Q_QUICK_PRIVATE_EXPORT void qt_quick_set_shortcut_context_matcher(ContextMatcher matcher) +{ + *ctxMatcher() = matcher; +} + +QT_BEGIN_NAMESPACE + QQuickShortcut::QQuickShortcut(QObject *parent) : QObject(parent), m_id(0), m_enabled(true), m_completed(false), m_autorepeat(true), m_context(Qt::WindowShortcut) { @@ -278,30 +310,13 @@ bool QQuickShortcut::event(QEvent *event) return false; } -static bool qQuickShortcutContextMatcher(QObject *obj, Qt::ShortcutContext context) -{ - switch (context) { - case Qt::ApplicationShortcut: - return true; - case Qt::WindowShortcut: - while (obj && !obj->isWindowType()) { - obj = obj->parent(); - if (QQuickItem *item = qobject_cast(obj)) - obj = item->window(); - } - return obj && obj == QGuiApplication::focusWindow(); - default: - return false; - } -} - void QQuickShortcut::grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context) { ungrabShortcut(); if (m_completed && !sequence.isEmpty()) { QGuiApplicationPrivate *pApp = QGuiApplicationPrivate::instance(); - m_id = pApp->shortcutMap.addShortcut(this, sequence, context, qQuickShortcutContextMatcher); + m_id = pApp->shortcutMap.addShortcut(this, sequence, context, *ctxMatcher()); if (!m_enabled) pApp->shortcutMap.setShortcutEnabled(false, m_id, this); if (!m_autorepeat) diff --git a/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp b/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp index 35a1aa8757..2df94bb84a 100644 --- a/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp +++ b/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp @@ -43,6 +43,8 @@ private slots: void sequence(); void context_data(); void context(); + void matcher_data(); + void matcher(); }; Q_DECLARE_METATYPE(Qt::Key) @@ -344,6 +346,68 @@ void tst_QQuickShortcut::context() || inactiveWindow->property("ambiguousShortcut").toString() == ambiguousShortcut); } +typedef bool (*ShortcutContextMatcher)(QObject *, Qt::ShortcutContext); +extern ShortcutContextMatcher qt_quick_shortcut_context_matcher(); +extern void qt_quick_set_shortcut_context_matcher(ShortcutContextMatcher matcher); + +static ShortcutContextMatcher lastMatcher = nullptr; + +static bool trueMatcher(QObject *, Qt::ShortcutContext) +{ + lastMatcher = trueMatcher; + return true; +} + +static bool falseMatcher(QObject *, Qt::ShortcutContext) +{ + lastMatcher = falseMatcher; + return false; +} + +Q_DECLARE_METATYPE(ShortcutContextMatcher) + +void tst_QQuickShortcut::matcher_data() +{ + QTest::addColumn("matcher"); + QTest::addColumn("key"); + QTest::addColumn("shortcut"); + QTest::addColumn("activatedShortcut"); + + ShortcutContextMatcher tm = trueMatcher; + ShortcutContextMatcher fm = falseMatcher; + + QTest::newRow("F1") << tm << Qt::Key_F1 << shortcutMap("F1", Qt::ApplicationShortcut) << "F1"; + QTest::newRow("F2") << fm << Qt::Key_F2 << shortcutMap("F2", Qt::ApplicationShortcut) << ""; +} + +void tst_QQuickShortcut::matcher() +{ + QFETCH(ShortcutContextMatcher, matcher); + QFETCH(Qt::Key, key); + QFETCH(QVariant, shortcut); + QFETCH(QString, activatedShortcut); + + ShortcutContextMatcher defaultMatcher = qt_quick_shortcut_context_matcher(); + QVERIFY(defaultMatcher); + + qt_quick_set_shortcut_context_matcher(matcher); + QVERIFY(qt_quick_shortcut_context_matcher() == matcher); + + QQmlApplicationEngine engine(testFileUrl("shortcuts.qml")); + QQuickWindow *window = qobject_cast(engine.rootObjects().value(0)); + QVERIFY(window); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + window->setProperty("shortcuts", QVariantList() << shortcut); + QTest::keyClick(window, key); + + QVERIFY(lastMatcher == matcher); + QCOMPARE(window->property("activatedShortcut").toString(), activatedShortcut); + + qt_quick_set_shortcut_context_matcher(defaultMatcher); +} + QTEST_MAIN(tst_QQuickShortcut) #include "tst_qquickshortcut.moc" -- cgit v1.2.3