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

KDE's Doxygen guidelines are available online.