Kirigami2

kirigamiplugin.cpp
1/*
2 * SPDX-FileCopyrightText: 2009 Alan Alpert <alan.alpert@nokia.com>
3 * SPDX-FileCopyrightText: 2010 Ménard Alexis <menard@kde.org>
4 * SPDX-FileCopyrightText: 2010 Marco Martin <mart@kde.org>
5 *
6 * SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8
9#include "kirigamiplugin.h"
10
11#include <QIcon>
12#if defined(Q_OS_ANDROID)
13#include <QResource>
14#endif
15#include <QQmlContext>
16#include <QQuickItem>
17
18#include "platform/styleselector.h"
19
20#ifdef KIRIGAMI_BUILD_TYPE_STATIC
21#include "loggingcategory.h"
22#include <QDebug>
23#endif
24
25// This is required for declarative registration to work on Windows.
26// This is normally generated by Qt but since we need a manually written plugin
27// file, we need to include this ourselves.
28extern void qml_register_types_org_kde_kirigami();
29Q_GHS_KEEP_REFERENCE(qml_register_types_org_kde_kirigami)
30
31// we can't do this in the plugin object directly, as that can live in a different thread
32// and event filters are only allowed in the same thread as the filtered object
33class LanguageChangeEventFilter : public QObject
34{
36public:
37 bool eventFilter(QObject *receiver, QEvent *event) override
38 {
39 if (event->type() == QEvent::LanguageChange && receiver == QCoreApplication::instance()) {
40 Q_EMIT languageChangeEvent();
41 }
42 return QObject::eventFilter(receiver, event);
43 }
44
46 void languageChangeEvent();
47};
48
49KirigamiPlugin::KirigamiPlugin(QObject *parent)
50 : QQmlExtensionPlugin(parent)
51{
52 // See above.
53 volatile auto registration = &qml_register_types_org_kde_kirigami;
54 Q_UNUSED(registration)
55
56 auto filter = new LanguageChangeEventFilter;
57 filter->moveToThread(QCoreApplication::instance()->thread());
59 connect(filter, &LanguageChangeEventFilter::languageChangeEvent, this, &KirigamiPlugin::languageChangeEvent);
60}
61
62QUrl KirigamiPlugin::componentUrl(const QString &fileName) const
63{
64 return Kirigami::Platform::StyleSelector::componentUrl(fileName);
65}
66
67void KirigamiPlugin::registerTypes(const char *uri)
68{
69#if defined(Q_OS_ANDROID)
70 QResource::registerResource(QStringLiteral("assets:/android_rcc_bundle.rcc"));
71#endif
72
73 Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.kirigami"));
74
75 Kirigami::Platform::StyleSelector::setBaseUrl(baseUrl());
76
77 if (QIcon::themeName().isEmpty() && !qEnvironmentVariableIsSet("XDG_CURRENT_DESKTOP")) {
78#if defined(Q_OS_ANDROID)
79 QIcon::setThemeSearchPaths({QStringLiteral("assets:/qml/org/kde/kirigami"), QStringLiteral(":/icons")});
80#else
81 QIcon::setThemeSearchPaths({Kirigami::Platform::StyleSelector::resolveFilePath(QStringLiteral(".")), QStringLiteral(":/icons")});
82#endif
83 QIcon::setThemeName(QStringLiteral("breeze-internal"));
84 } else {
85 QIcon::setFallbackSearchPaths(QIcon::fallbackSearchPaths() << Kirigami::Platform::StyleSelector::resolveFilePath(QStringLiteral("icons")));
86 }
87
88 qmlRegisterType(componentUrl(QStringLiteral("Action.qml")), uri, 2, 0, "Action");
89 qmlRegisterType(componentUrl(QStringLiteral("AbstractApplicationHeader.qml")), uri, 2, 0, "AbstractApplicationHeader");
90 qmlRegisterType(componentUrl(QStringLiteral("AbstractApplicationWindow.qml")), uri, 2, 0, "AbstractApplicationWindow");
91 qmlRegisterType(componentUrl(QStringLiteral("ApplicationWindow.qml")), uri, 2, 0, "ApplicationWindow");
92 qmlRegisterType(componentUrl(QStringLiteral("OverlayDrawer.qml")), uri, 2, 0, "OverlayDrawer");
93 qmlRegisterType(componentUrl(QStringLiteral("ContextDrawer.qml")), uri, 2, 0, "ContextDrawer");
94 qmlRegisterType(componentUrl(QStringLiteral("GlobalDrawer.qml")), uri, 2, 0, "GlobalDrawer");
95 qmlRegisterType(componentUrl(QStringLiteral("Heading.qml")), uri, 2, 0, "Heading");
96 qmlRegisterType(componentUrl(QStringLiteral("PageRow.qml")), uri, 2, 0, "PageRow");
97
98 qmlRegisterType(componentUrl(QStringLiteral("OverlaySheet.qml")), uri, 2, 0, "OverlaySheet");
99 qmlRegisterType(componentUrl(QStringLiteral("Page.qml")), uri, 2, 0, "Page");
100 qmlRegisterType(componentUrl(QStringLiteral("ScrollablePage.qml")), uri, 2, 0, "ScrollablePage");
101 qmlRegisterType(componentUrl(QStringLiteral("SwipeListItem.qml")), uri, 2, 0, "SwipeListItem");
102
103 // 2.1
104 qmlRegisterType(componentUrl(QStringLiteral("AbstractApplicationItem.qml")), uri, 2, 1, "AbstractApplicationItem");
105 qmlRegisterType(componentUrl(QStringLiteral("ApplicationItem.qml")), uri, 2, 1, "ApplicationItem");
106
107 // 2.4
108 qmlRegisterType(componentUrl(QStringLiteral("AbstractCard.qml")), uri, 2, 4, "AbstractCard");
109 qmlRegisterType(componentUrl(QStringLiteral("Card.qml")), uri, 2, 4, "Card");
110 qmlRegisterType(componentUrl(QStringLiteral("CardsListView.qml")), uri, 2, 4, "CardsListView");
111 qmlRegisterType(componentUrl(QStringLiteral("CardsLayout.qml")), uri, 2, 4, "CardsLayout");
112 qmlRegisterType(componentUrl(QStringLiteral("InlineMessage.qml")), uri, 2, 4, "InlineMessage");
113
114 // 2.5
115 qmlRegisterType(componentUrl(QStringLiteral("ListItemDragHandle.qml")), uri, 2, 5, "ListItemDragHandle");
116 qmlRegisterType(componentUrl(QStringLiteral("ActionToolBar.qml")), uri, 2, 5, "ActionToolBar");
117
118 // 2.6
119 qmlRegisterType(componentUrl(QStringLiteral("AboutPage.qml")), uri, 2, 6, "AboutPage");
120 qmlRegisterType(componentUrl(QStringLiteral("LinkButton.qml")), uri, 2, 6, "LinkButton");
121 qmlRegisterType(componentUrl(QStringLiteral("UrlButton.qml")), uri, 2, 6, "UrlButton");
122
123 // 2.7
124 qmlRegisterType(componentUrl(QStringLiteral("ActionTextField.qml")), uri, 2, 7, "ActionTextField");
125
126 // 2.8
127 qmlRegisterType(componentUrl(QStringLiteral("SearchField.qml")), uri, 2, 8, "SearchField");
128 qmlRegisterType(componentUrl(QStringLiteral("PasswordField.qml")), uri, 2, 8, "PasswordField");
129
130 // 2.10
131 qmlRegisterType(componentUrl(QStringLiteral("ListSectionHeader.qml")), uri, 2, 10, "ListSectionHeader");
132
133 // 2.11
134 qmlRegisterType(componentUrl(QStringLiteral("PagePoolAction.qml")), uri, 2, 11, "PagePoolAction");
135
136 // 2.12
137 qmlRegisterType(componentUrl(QStringLiteral("PlaceholderMessage.qml")), uri, 2, 12, "PlaceholderMessage");
138
139 // 2.14
140 qmlRegisterType(componentUrl(QStringLiteral("FlexColumn.qml")), uri, 2, 14, "FlexColumn");
141
142 // 2.19
143 qmlRegisterType(componentUrl(QStringLiteral("AboutItem.qml")), uri, 2, 19, "AboutItem");
144 qmlRegisterType(componentUrl(QStringLiteral("NavigationTabBar.qml")), uri, 2, 19, "NavigationTabBar");
145 qmlRegisterType(componentUrl(QStringLiteral("NavigationTabButton.qml")), uri, 2, 19, "NavigationTabButton");
146 qmlRegisterType(componentUrl(QStringLiteral("Chip.qml")), uri, 2, 19, "Chip");
147 qmlRegisterType(componentUrl(QStringLiteral("LoadingPlaceholder.qml")), uri, 2, 19, "LoadingPlaceholder");
148
149 // 2.20
150 qmlRegisterType(componentUrl(QStringLiteral("SelectableLabel.qml")), uri, 2, 20, "SelectableLabel");
151 qmlRegisterType(componentUrl(QStringLiteral("InlineViewHeader.qml")), uri, 2, 20, "InlineViewHeader");
152 qmlRegisterType(componentUrl(QStringLiteral("ContextualHelpButton.qml")), uri, 2, 20, "ContextualHelpButton");
153}
154
155void KirigamiPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
156{
157 Q_UNUSED(uri);
158 connect(this, &KirigamiPlugin::languageChangeEvent, engine, &QQmlEngine::retranslate);
159}
160
161#ifdef KIRIGAMI_BUILD_TYPE_STATIC
162KirigamiPlugin &KirigamiPlugin::getInstance()
163{
164 static KirigamiPlugin instance;
165 return instance;
166}
167
168void KirigamiPlugin::registerTypes(QQmlEngine *engine)
169{
170 if (engine) {
171 engine->addImportPath(QLatin1String(":/"));
172 } else {
173 qCWarning(KirigamiLog)
174 << "Registering Kirigami on a null QQmlEngine instance - you likely want to pass a valid engine, or you will want to manually add the "
175 "qrc root path :/ to your import paths list so the engine is able to load the plugin";
176 }
177}
178#endif
179
180#include "kirigamiplugin.moc"
181#include "moc_kirigamiplugin.cpp"
QCoreApplication * instance()
QStringList fallbackSearchPaths()
void setFallbackSearchPaths(const QStringList &paths)
void setThemeName(const QString &name)
void setThemeSearchPaths(const QStringList &paths)
QString themeName()
Q_EMITQ_EMIT
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual bool event(QEvent *e)
virtual bool eventFilter(QObject *watched, QEvent *event)
void installEventFilter(QObject *filterObj)
void addImportPath(const QString &path)
void retranslate()
bool registerResource(const QString &rccFileName, const QString &mapRoot)
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:05:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.