| 1 | // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 2 | // SPDX-FileCopyrightText: 2025 Harald Sitter <sitter@kde.org> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include <QObject> |
| 7 | #include <QtQmlIntegration> |
| 8 | |
| 9 | #include "klocalizedqmlcontext.h" |
| 10 | |
| 11 | class QJSEngine; |
| 12 | |
| 13 | /*! |
| 14 | \internal |
| 15 | Assistive class to expose KLocalizedQmlContext as a QML singleton. |
| 16 | This works around the fact that singleton construction prefers constructors over |
| 17 | create() functions. We do however need to use the create() because we aren't |
| 18 | really a singleton, but an engine-wide-singleton and need to excavate our actual |
| 19 | context object from the engine. |
| 20 | */ |
| 21 | class LocalizedContext : public QObject |
| 22 | { |
| 23 | Q_OBJECT |
| 24 | QML_SINGLETON |
| 25 | QML_FOREIGN(KLocalizedQmlContext) |
| 26 | QML_NAMED_ELEMENT(KI18n) |
| 27 | public: |
| 28 | static KLocalizedQmlContext *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine); |
| 29 | LocalizedContext() = delete; // use the create() function |
| 30 | }; |
| 31 | |