1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Quick Controls module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "plugin.h" |
41 | |
42 | #include "qquickaction_p.h" |
43 | #include "qquickexclusivegroup_p.h" |
44 | #include "qquickmenu_p.h" |
45 | #include "qquickmenubar_p.h" |
46 | #include "qquickpopupwindow_p.h" |
47 | #include "qquickstack_p.h" |
48 | #include "qquickdesktopiconprovider_p.h" |
49 | #include "qquickselectionmode_p.h" |
50 | |
51 | #include "Private/qquickcalendarmodel_p.h" |
52 | #include "Private/qquickrangeddate_p.h" |
53 | #include "Private/qquickrangemodel_p.h" |
54 | #include "Private/qquickwheelarea_p.h" |
55 | #include "Private/qquicktooltip_p.h" |
56 | #include "Private/qquickcontrolsettings_p.h" |
57 | #include "Private/qquickspinboxvalidator_p.h" |
58 | #include "Private/qquickabstractstyle_p.h" |
59 | #include "Private/qquickcontrolsprivate_p.h" |
60 | #include "Private/qquicktreemodeladaptor_p.h" |
61 | #include "Private/qquicksceneposlistener_p.h" |
62 | |
63 | #ifdef QT_WIDGETS_LIB |
64 | #include <QtQuick/qquickimageprovider.h> |
65 | #include "Private/qquickstyleitem_p.h" |
66 | #endif |
67 | |
68 | #ifndef QT_NO_TRANSLATION |
69 | #include <QtCore/qcoreapplication.h> |
70 | #include <QtCore/qlibraryinfo.h> |
71 | #include <QtCore/qlocale.h> |
72 | #endif |
73 | |
74 | QT_BEGIN_NAMESPACE |
75 | |
76 | struct QmldirStruct { |
77 | const char *type; |
78 | int major, minor; |
79 | }; |
80 | |
81 | static const QmldirStruct qmldir [] = { |
82 | { .type: "ApplicationWindow" , .major: 1, .minor: 0 }, |
83 | { .type: "Button" , .major: 1, .minor: 0 }, |
84 | { .type: "Calendar" , .major: 1, .minor: 2 }, |
85 | { .type: "CheckBox" , .major: 1, .minor: 0 }, |
86 | { .type: "ComboBox" , .major: 1, .minor: 0 }, |
87 | { .type: "GroupBox" , .major: 1, .minor: 0 }, |
88 | { .type: "Label" , .major: 1, .minor: 0 }, |
89 | { .type: "MenuBar" , .major: 1, .minor: 0 }, |
90 | { .type: "Menu" , .major: 1, .minor: 0 }, |
91 | { .type: "StackView" , .major: 1, .minor: 0 }, |
92 | { .type: "ProgressBar" , .major: 1, .minor: 0 }, |
93 | { .type: "RadioButton" , .major: 1, .minor: 0 }, |
94 | { .type: "ScrollView" , .major: 1, .minor: 0 }, |
95 | { .type: "Slider" , .major: 1, .minor: 0 }, |
96 | { .type: "SpinBox" , .major: 1, .minor: 0 }, |
97 | { .type: "SplitView" , .major: 1, .minor: 0 }, |
98 | { .type: "StackViewDelegate" , .major: 1, .minor: 0 }, |
99 | { .type: "StackViewTransition" , .major: 1, .minor: 0 }, |
100 | { .type: "StatusBar" , .major: 1, .minor: 0 }, |
101 | { .type: "Switch" , .major: 1, .minor: 1 }, |
102 | { .type: "Tab" , .major: 1, .minor: 0 }, |
103 | { .type: "TabView" , .major: 1, .minor: 0 }, |
104 | { .type: "TableView" , .major: 1, .minor: 0 }, |
105 | { .type: "TableViewColumn" , .major: 1, .minor: 0 }, |
106 | { .type: "TextArea" , .major: 1, .minor: 0 }, |
107 | { .type: "TextField" , .major: 1, .minor: 0 }, |
108 | { .type: "ToolBar" , .major: 1, .minor: 0 }, |
109 | { .type: "ToolButton" , .major: 1, .minor: 0 }, |
110 | |
111 | { .type: "BusyIndicator" , .major: 1, .minor: 1 }, |
112 | |
113 | { .type: "TextArea" , .major: 1, .minor: 3 }, |
114 | |
115 | { .type: "TreeView" , .major: 1, .minor: 4 }, |
116 | |
117 | { .type: "TextArea" , .major: 1, .minor: 5 }, |
118 | { .type: "TreeView" , .major: 1, .minor: 5 }, |
119 | |
120 | { .type: "Calendar" , .major: 1, .minor: 6 }, |
121 | { .type: "Slider" , .major: 1, .minor: 6 } |
122 | }; |
123 | |
124 | static const QmldirStruct stylesQmldir [] = { |
125 | { .type: "ApplicationWindowStyle" , .major: 1, .minor: 3 }, |
126 | { .type: "ButtonStyle" , .major: 1, .minor: 0 }, |
127 | { .type: "BusyIndicatorStyle" , .major: 1, .minor: 1 }, |
128 | { .type: "CalendarStyle" , .major: 1, .minor: 1 }, |
129 | { .type: "CheckBoxStyle" , .major: 1, .minor: 0 }, |
130 | { .type: "ComboBoxStyle" , .major: 1, .minor: 0 }, |
131 | { .type: "MenuStyle" , .major: 1, .minor: 2 }, |
132 | { .type: "MenuBarStyle" , .major: 1, .minor: 2 }, |
133 | { .type: "ProgressBarStyle" , .major: 1, .minor: 0 }, |
134 | { .type: "RadioButtonStyle" , .major: 1, .minor: 0 }, |
135 | { .type: "ScrollViewStyle" , .major: 1, .minor: 0 }, |
136 | { .type: "SliderStyle" , .major: 1, .minor: 0 }, |
137 | { .type: "SpinBoxStyle" , .major: 1, .minor: 1 }, |
138 | { .type: "SwitchStyle" , .major: 1, .minor: 1 }, |
139 | { .type: "TabViewStyle" , .major: 1, .minor: 0 }, |
140 | { .type: "TableViewStyle" , .major: 1, .minor: 0 }, |
141 | { .type: "TreeViewStyle" , .major: 1, .minor: 4 }, |
142 | { .type: "TextAreaStyle" , .major: 1, .minor: 1 }, |
143 | { .type: "TextFieldStyle" , .major: 1, .minor: 0 }, |
144 | { .type: "ToolBarStyle" , .major: 1, .minor: 0 }, |
145 | { .type: "StatusBarStyle" , .major: 1, .minor: 0 }, |
146 | { .type: "CircularGaugeStyle" , .major: 1, .minor: 0 }, |
147 | { .type: "CircularButtonStyle" , .major: 1, .minor: 0 }, |
148 | { .type: "CircularTickmarkLabelStyle" , .major: 1, .minor: 0 }, |
149 | { .type: "CommonStyleHelper" , .major: 1, .minor: 0 }, |
150 | { .type: "DelayButtonStyle" , .major: 1, .minor: 0 }, |
151 | { .type: "DialStyle" , .major: 1, .minor: 1 }, |
152 | { .type: "GaugeStyle" , .major: 1, .minor: 0 }, |
153 | { .type: "HandleStyle" , .major: 1, .minor: 0 }, |
154 | { .type: "HandleStyleHelper" , .major: 1, .minor: 0 }, |
155 | { .type: "PieMenuStyle" , .major: 1, .minor: 3 }, |
156 | { .type: "StatusIndicatorStyle" , .major: 1, .minor: 1 }, |
157 | { .type: "ToggleButtonStyle" , .major: 1, .minor: 0 }, |
158 | { .type: "TumblerStyle" , .major: 1, .minor: 2 } |
159 | }; |
160 | |
161 | QtQuickControls1Plugin::QtQuickControls1Plugin(QObject *parent) : QQmlExtensionPlugin(parent) |
162 | { |
163 | } |
164 | |
165 | void QtQuickControls1Plugin::registerTypes(const char *uri) |
166 | { |
167 | qmlRegisterType<QQuickAction1>(uri, versionMajor: 1, versionMinor: 0, qmlName: "Action" ); |
168 | qmlRegisterType<QQuickExclusiveGroup1>(uri, versionMajor: 1, versionMinor: 0, qmlName: "ExclusiveGroup" ); |
169 | qmlRegisterType<QQuickMenuItem1>(uri, versionMajor: 1, versionMinor: 0, qmlName: "MenuItem" ); |
170 | qmlRegisterUncreatableType<QQuickMenuItemType1>(uri, versionMajor: 1, versionMinor: 0, qmlName: "MenuItemType" , |
171 | reason: QLatin1String("Do not create objects of type MenuItemType" )); |
172 | qmlRegisterType<QQuickMenuSeparator1>(uri, versionMajor: 1, versionMinor: 0, qmlName: "MenuSeparator" ); |
173 | qmlRegisterUncreatableType<QQuickMenuBase1>(uri, versionMajor: 1, versionMinor: 0, qmlName: "MenuBase" , |
174 | reason: QLatin1String("Do not create objects of type MenuBase" )); |
175 | |
176 | qmlRegisterUncreatableType<QQuickStack1>(uri, versionMajor: 1, versionMinor: 0, qmlName: "Stack" , reason: QLatin1String("Do not create objects of type Stack" )); |
177 | qmlRegisterUncreatableType<QQuickSelectionMode1>(uri, versionMajor: 1, versionMinor: 1, qmlName: "SelectionMode" , reason: QLatin1String("Do not create objects of type SelectionMode" )); |
178 | |
179 | const QString filesLocation = fileLocation(); |
180 | for (int i = 0; i < int(sizeof(qmldir)/sizeof(qmldir[0])); i++) |
181 | qmlRegisterType(url: QUrl(filesLocation + "/" + qmldir[i].type + ".qml" ), uri, versionMajor: qmldir[i].major, versionMinor: qmldir[i].minor, qmlName: qmldir[i].type); |
182 | |
183 | // Register private API. Note that to use these types outside of the |
184 | // Qt Quick Controls module, both the public and private imports must be used. |
185 | const char *private_uri = "QtQuick.Controls.Private" ; |
186 | qmlRegisterType<QQuickAbstractStyle1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "AbstractStyle" ); |
187 | qmlRegisterType<QQuickCalendarModel1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "CalendarModel" ); |
188 | qmlRegisterType<QQuickPadding1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "Padding" ); |
189 | qmlRegisterType<QQuickRangedDate1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "RangedDate" ); |
190 | qmlRegisterType<QQuickRangeModel1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "RangeModel" ); |
191 | qmlRegisterType<QQuickWheelArea1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "WheelArea" ); |
192 | #if QT_CONFIG(validator) |
193 | qmlRegisterType<QQuickSpinBoxValidator1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "SpinBoxValidator" ); |
194 | #endif |
195 | qmlRegisterSingletonType<QQuickTooltip1>(uri: private_uri, versionMajor: 1, versionMinor: 0, typeName: "Tooltip" , callback: QQuickControlsPrivate1::registerTooltipModule); |
196 | qmlRegisterSingletonType<QQuickControlSettings1>(uri: private_uri, versionMajor: 1, versionMinor: 0, typeName: "Settings" , callback: QQuickControlsPrivate1::registerSettingsModule); |
197 | |
198 | qmlRegisterUncreatableType<QQuickControlsPrivate1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "Controls" , reason: QLatin1String("Controls is an abstract type." )); |
199 | qmlRegisterAnonymousType<QQuickControlsPrivate1Attached>(uri: private_uri, versionMajor: 1); |
200 | |
201 | qmlRegisterType<QQuickTreeModelAdaptor1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "TreeModelAdaptor" ); |
202 | qmlRegisterType<QQuickScenePosListener1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "ScenePosListener" ); |
203 | |
204 | qmlRegisterType<QQuickMenu1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "MenuPrivate" ); |
205 | qmlRegisterType<QQuickMenuBar1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "MenuBarPrivate" ); |
206 | qmlRegisterType<QQuickPopupWindow1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "PopupWindow" ); |
207 | |
208 | qmlRegisterUncreatableType<QAbstractItemModel>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "AbstractItemModel" , |
209 | reason: QLatin1String("AbstractItemModel is an abstract type." )); |
210 | |
211 | #ifdef QT_WIDGETS_LIB |
212 | qmlRegisterType<QQuickStyleItem1>(uri: private_uri, versionMajor: 1, versionMinor: 0, qmlName: "StyleItem" ); |
213 | #endif |
214 | |
215 | const char *styles_uri = "QtQuick.Controls.Styles" ; |
216 | const QString baseStyleLocation = filesLocation + "/Styles/Base" ; |
217 | for (int i = 0; i < int(sizeof(stylesQmldir)/sizeof(stylesQmldir[0])); i++) |
218 | qmlRegisterType(url: QUrl(baseStyleLocation + "/" + stylesQmldir[i].type + ".qml" ), uri: styles_uri, |
219 | versionMajor: stylesQmldir[i].major, versionMinor: stylesQmldir[i].minor, qmlName: stylesQmldir[i].type); |
220 | } |
221 | |
222 | void QtQuickControls1Plugin::initializeEngine(QQmlEngine *engine, const char *uri) |
223 | { |
224 | Q_UNUSED(uri); |
225 | |
226 | #ifdef QT_WIDGETS_LIB |
227 | engine->addImageProvider(id: "__tablerow" , new QQuickTableRowImageProvider1); |
228 | #endif |
229 | engine->addImageProvider(id: "desktoptheme" , new QQuickDesktopIconProvider1); |
230 | if (isLoadedFromResource()) |
231 | engine->addImportPath(QStringLiteral("qrc:/" )); |
232 | |
233 | #ifndef QT_NO_TRANSLATION |
234 | if (m_translator.load(locale: QLocale(), filename: QLatin1String("qtquickcontrols" ), |
235 | prefix: QLatin1String("_" ), directory: QLibraryInfo::location(QLibraryInfo::TranslationsPath))) |
236 | QCoreApplication::installTranslator(messageFile: &m_translator); |
237 | #endif |
238 | } |
239 | |
240 | QString QtQuickControls1Plugin::fileLocation() const |
241 | { |
242 | #ifdef Q_OS_ANDROID |
243 | return "qrc:/android_rcc_bundle/qml/QtQuick/Controls" ; |
244 | #else |
245 | # ifndef QT_STATIC |
246 | if (isLoadedFromResource()) |
247 | return "qrc:/QtQuick/Controls" ; |
248 | return baseUrl().toString(); |
249 | # else |
250 | return "qrc:/qt-project.org/imports/QtQuick/Controls" ; |
251 | # endif |
252 | #endif |
253 | } |
254 | |
255 | bool QtQuickControls1Plugin::isLoadedFromResource() const |
256 | { |
257 | #ifdef Q_OS_ANDROID |
258 | return true; |
259 | #else |
260 | # ifdef QT_STATIC |
261 | // When static it is included automatically |
262 | // for us. |
263 | return false; |
264 | # endif |
265 | # if defined(ALWAYS_LOAD_FROM_RESOURCES) |
266 | return true; |
267 | # else |
268 | // If one file is missing, it will load all the files from the resource |
269 | QFile file(baseUrl().toLocalFile() + "/ApplicationWindow.qml" ); |
270 | if (!file.exists()) |
271 | return true; |
272 | return false; |
273 | # endif |
274 | #endif |
275 | } |
276 | |
277 | QT_END_NAMESPACE |
278 | |