| 1 | // Copyright (C) 2020 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtQml/qqmlextensionplugin.h> |
| 5 | #include <QtQml/private/qqmlglobal_p.h> |
| 6 | #include <QtQuickTemplates2/private/qtquicktemplates2global_p.h> |
| 7 | |
| 8 | #if QT_CONFIG(shortcut) |
| 9 | #include <QtQuickTemplates2/private/qquickshortcutcontext_p_p.h> |
| 10 | |
| 11 | // qtdeclarative/src/quick/util/qquickshortcut.cpp |
| 12 | typedef bool (*ShortcutContextMatcher)(QObject *, Qt::ShortcutContext); |
| 13 | extern ShortcutContextMatcher qt_quick_shortcut_context_matcher(); |
| 14 | extern void qt_quick_set_shortcut_context_matcher(ShortcutContextMatcher matcher); |
| 15 | #endif |
| 16 | |
| 17 | QT_BEGIN_NAMESPACE |
| 18 | |
| 19 | Q_GHS_KEEP_REFERENCE(qml_register_types_QtQuick_Templates); |
| 20 | Q_GHS_KEEP_REFERENCE(QQuickTemplates_initializeModule); |
| 21 | |
| 22 | class QtQuickTemplates2Plugin : public QQmlExtensionPlugin |
| 23 | { |
| 24 | Q_OBJECT |
| 25 | Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) |
| 26 | |
| 27 | public: |
| 28 | QtQuickTemplates2Plugin(QObject *parent = nullptr); |
| 29 | ~QtQuickTemplates2Plugin(); |
| 30 | |
| 31 | void registerTypes(const char *uri) override; |
| 32 | void unregisterTypes() override; |
| 33 | |
| 34 | private: |
| 35 | #if QT_CONFIG(shortcut) |
| 36 | ShortcutContextMatcher originalContextMatcher; |
| 37 | #endif |
| 38 | }; |
| 39 | |
| 40 | QtQuickTemplates2Plugin::QtQuickTemplates2Plugin(QObject *parent) |
| 41 | : QQmlExtensionPlugin(parent) |
| 42 | { |
| 43 | volatile auto registration = &qml_register_types_QtQuick_Templates; |
| 44 | volatile auto initialization = &QQuickTemplates_initializeModule; |
| 45 | |
| 46 | Q_UNUSED(registration) |
| 47 | Q_UNUSED(initialization) |
| 48 | } |
| 49 | |
| 50 | QtQuickTemplates2Plugin::~QtQuickTemplates2Plugin() |
| 51 | { |
| 52 | // Intentionally empty: we use register/unregisterTypes() to do |
| 53 | // initialization and cleanup, as plugins are not unloaded on macOS. |
| 54 | } |
| 55 | |
| 56 | void QtQuickTemplates2Plugin::registerTypes(const char * /*uri*/) |
| 57 | { |
| 58 | #if QT_CONFIG(shortcut) |
| 59 | originalContextMatcher = qt_quick_shortcut_context_matcher(); |
| 60 | qt_quick_set_shortcut_context_matcher(matcher: QQuickShortcutContext::matcher); |
| 61 | #endif |
| 62 | } |
| 63 | |
| 64 | void QtQuickTemplates2Plugin::unregisterTypes() |
| 65 | { |
| 66 | #if QT_CONFIG(shortcut) |
| 67 | qt_quick_set_shortcut_context_matcher(matcher: originalContextMatcher); |
| 68 | #endif |
| 69 | } |
| 70 | |
| 71 | QT_END_NAMESPACE |
| 72 | |
| 73 | #include "qtquicktemplates2plugin.moc" |
| 74 |
