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("Separator.qml")), uri, 2, 0, "Separator");
97 qmlRegisterType(componentUrl(QStringLiteral("PageRow.qml")), uri, 2, 0, "PageRow");
98
99 qmlRegisterType(componentUrl(QStringLiteral("OverlaySheet.qml")), uri, 2, 0, "OverlaySheet");
100 qmlRegisterType(componentUrl(QStringLiteral("Page.qml")), uri, 2, 0, "Page");
101 qmlRegisterType(componentUrl(QStringLiteral("ScrollablePage.qml")), uri, 2, 0, "ScrollablePage");
102 qmlRegisterType(componentUrl(QStringLiteral("SwipeListItem.qml")), uri, 2, 0, "SwipeListItem");
103
104 // 2.1
105 qmlRegisterType(componentUrl(QStringLiteral("AbstractApplicationItem.qml")), uri, 2, 1, "AbstractApplicationItem");
106 qmlRegisterType(componentUrl(QStringLiteral("ApplicationItem.qml")), uri, 2, 1, "ApplicationItem");
107
108 // 2.3
109 qmlRegisterType(componentUrl(QStringLiteral("FormLayout.qml")), uri, 2, 3, "FormLayout");
110
111 // 2.4
112 qmlRegisterType(componentUrl(QStringLiteral("AbstractCard.qml")), uri, 2, 4, "AbstractCard");
113 qmlRegisterType(componentUrl(QStringLiteral("Card.qml")), uri, 2, 4, "Card");
114 qmlRegisterType(componentUrl(QStringLiteral("CardsListView.qml")), uri, 2, 4, "CardsListView");
115 qmlRegisterType(componentUrl(QStringLiteral("CardsLayout.qml")), uri, 2, 4, "CardsLayout");
116 qmlRegisterType(componentUrl(QStringLiteral("InlineMessage.qml")), uri, 2, 4, "InlineMessage");
117
118 // 2.5
119 qmlRegisterType(componentUrl(QStringLiteral("ListItemDragHandle.qml")), uri, 2, 5, "ListItemDragHandle");
120 qmlRegisterType(componentUrl(QStringLiteral("ActionToolBar.qml")), uri, 2, 5, "ActionToolBar");
121
122 // 2.6
123 qmlRegisterType(componentUrl(QStringLiteral("AboutPage.qml")), uri, 2, 6, "AboutPage");
124 qmlRegisterType(componentUrl(QStringLiteral("LinkButton.qml")), uri, 2, 6, "LinkButton");
125 qmlRegisterType(componentUrl(QStringLiteral("UrlButton.qml")), uri, 2, 6, "UrlButton");
126
127 // 2.7
128 qmlRegisterType(componentUrl(QStringLiteral("ActionTextField.qml")), uri, 2, 7, "ActionTextField");
129
130 // 2.8
131 qmlRegisterType(componentUrl(QStringLiteral("SearchField.qml")), uri, 2, 8, "SearchField");
132 qmlRegisterType(componentUrl(QStringLiteral("PasswordField.qml")), uri, 2, 8, "PasswordField");
133
134 // 2.10
135 qmlRegisterType(componentUrl(QStringLiteral("ListSectionHeader.qml")), uri, 2, 10, "ListSectionHeader");
136
137 // 2.11
138 qmlRegisterType(componentUrl(QStringLiteral("PagePoolAction.qml")), uri, 2, 11, "PagePoolAction");
139
140 // 2.12
141 qmlRegisterType(componentUrl(QStringLiteral("ShadowedImage.qml")), uri, 2, 12, "ShadowedImage");
142 qmlRegisterType(componentUrl(QStringLiteral("PlaceholderMessage.qml")), uri, 2, 12, "PlaceholderMessage");
143
144 // 2.14
145 qmlRegisterType(componentUrl(QStringLiteral("FlexColumn.qml")), uri, 2, 14, "FlexColumn");
146
147 // 2.19
148 qmlRegisterType(componentUrl(QStringLiteral("AboutItem.qml")), uri, 2, 19, "AboutItem");
149 qmlRegisterType(componentUrl(QStringLiteral("NavigationTabBar.qml")), uri, 2, 19, "NavigationTabBar");
150 qmlRegisterType(componentUrl(QStringLiteral("NavigationTabButton.qml")), uri, 2, 19, "NavigationTabButton");
151 qmlRegisterType(componentUrl(QStringLiteral("Dialog.qml")), uri, 2, 19, "Dialog");
152 qmlRegisterType(componentUrl(QStringLiteral("MenuDialog.qml")), uri, 2, 19, "MenuDialog");
153 qmlRegisterType(componentUrl(QStringLiteral("PromptDialog.qml")), uri, 2, 19, "PromptDialog");
154 qmlRegisterType(componentUrl(QStringLiteral("Chip.qml")), uri, 2, 19, "Chip");
155 qmlRegisterType(componentUrl(QStringLiteral("LoadingPlaceholder.qml")), uri, 2, 19, "LoadingPlaceholder");
156
157 // 2.20
158 qmlRegisterType(componentUrl(QStringLiteral("SelectableLabel.qml")), uri, 2, 20, "SelectableLabel");
159 qmlRegisterType(componentUrl(QStringLiteral("InlineViewHeader.qml")), uri, 2, 20, "InlineViewHeader");
160 qmlRegisterType(componentUrl(QStringLiteral("ContextualHelpButton.qml")), uri, 2, 20, "ContextualHelpButton");
161}
162
163void KirigamiPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
164{
165 Q_UNUSED(uri);
166 connect(this, &KirigamiPlugin::languageChangeEvent, engine, &QQmlEngine::retranslate);
167}
168
169#ifdef KIRIGAMI_BUILD_TYPE_STATIC
170KirigamiPlugin &KirigamiPlugin::getInstance()
171{
172 static KirigamiPlugin instance;
173 return instance;
174}
175
176void KirigamiPlugin::registerTypes(QQmlEngine *engine)
177{
178 if (engine) {
179 engine->addImportPath(QLatin1String(":/"));
180 } else {
181 qCWarning(KirigamiLog)
182 << "Registering Kirigami on a null QQmlEngine instance - you likely want to pass a valid engine, or you will want to manually add the "
183 "qrc root path :/ to your import paths list so the engine is able to load the plugin";
184 }
185}
186#endif
187
188#include "kirigamiplugin.moc"
189#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 May 3 2024 11:49:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.