1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
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 http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include <QtQml/qqmlextensionplugin.h>
38#include <QtQml/private/qqmlglobal_p.h>
39
40#include <QtQuickTemplates2/private/qquickabstractbutton_p.h>
41#include <QtQuickTemplates2/private/qquickaction_p.h>
42#include <QtQuickTemplates2/private/qquickactiongroup_p.h>
43#include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
44#include <QtQuickTemplates2/private/qquickbusyindicator_p.h>
45#include <QtQuickTemplates2/private/qquickbutton_p.h>
46#include <QtQuickTemplates2/private/qquickbuttongroup_p.h>
47#include <QtQuickTemplates2/private/qquickcheckbox_p.h>
48#include <QtQuickTemplates2/private/qquickcheckdelegate_p.h>
49#include <QtQuickTemplates2/private/qquickcombobox_p.h>
50#include <QtQuickTemplates2/private/qquickcontrol_p.h>
51#include <QtQuickTemplates2/private/qquickcontainer_p.h>
52#include <QtQuickTemplates2/private/qquickdelaybutton_p.h>
53#include <QtQuickTemplates2/private/qquickdial_p.h>
54#include <QtQuickTemplates2/private/qquickdialog_p.h>
55#include <QtQuickTemplates2/private/qquickdialogbuttonbox_p.h>
56#include <QtQuickTemplates2/private/qquickdrawer_p.h>
57#include <QtQuickTemplates2/private/qquickframe_p.h>
58#include <QtQuickTemplates2/private/qquickgroupbox_p.h>
59#include <QtQuickTemplates2/private/qquickicon_p.h>
60#include <QtQuickTemplates2/private/qquickitemdelegate_p.h>
61#include <QtQuickTemplates2/private/qquicklabel_p.h>
62#include <QtQuickTemplates2/private/qquickmenu_p.h>
63#include <QtQuickTemplates2/private/qquickmenubar_p.h>
64#include <QtQuickTemplates2/private/qquickmenubaritem_p.h>
65#include <QtQuickTemplates2/private/qquickmenuitem_p.h>
66#include <QtQuickTemplates2/private/qquickmenuseparator_p.h>
67#include <QtQuickTemplates2/private/qquickoverlay_p.h>
68#include <QtQuickTemplates2/private/qquickpage_p.h>
69#include <QtQuickTemplates2/private/qquickpageindicator_p.h>
70#include <QtQuickTemplates2/private/qquickpaletteprovider_p.h>
71#include <QtQuickTemplates2/private/qquickpane_p.h>
72#include <QtQuickTemplates2/private/qquickpopup_p.h>
73#include <QtQuickTemplates2/private/qquickpopupanchors_p.h>
74#include <QtQuickTemplates2/private/qquickprogressbar_p.h>
75#include <QtQuickTemplates2/private/qquickradiobutton_p.h>
76#include <QtQuickTemplates2/private/qquickradiodelegate_p.h>
77#include <QtQuickTemplates2/private/qquickrangeslider_p.h>
78#include <QtQuickTemplates2/private/qquickroundbutton_p.h>
79#include <QtQuickTemplates2/private/qquickscrollbar_p.h>
80#include <QtQuickTemplates2/private/qquickscrollindicator_p.h>
81#include <QtQuickTemplates2/private/qquickscrollview_p.h>
82#include <QtQuickTemplates2/private/qquickshortcutcontext_p_p.h>
83#include <QtQuickTemplates2/private/qquickslider_p.h>
84#include <QtQuickTemplates2/private/qquickspinbox_p.h>
85#include <QtQuickTemplates2/private/qquicksplitview_p.h>
86#include <QtQuickTemplates2/private/qquickstackview_p.h>
87#include <QtQuickTemplates2/private/qquickswipe_p.h>
88#include <QtQuickTemplates2/private/qquickswipedelegate_p.h>
89#include <QtQuickTemplates2/private/qquickswipeview_p.h>
90#include <QtQuickTemplates2/private/qquickswitch_p.h>
91#include <QtQuickTemplates2/private/qquickswitchdelegate_p.h>
92#include <QtQuickTemplates2/private/qquicktabbar_p.h>
93#include <QtQuickTemplates2/private/qquicktabbutton_p.h>
94#include <QtQuickTemplates2/private/qquicktextarea_p.h>
95#include <QtQuickTemplates2/private/qquicktextfield_p.h>
96#include <QtQuickTemplates2/private/qquicktoolbar_p.h>
97#include <QtQuickTemplates2/private/qquicktoolbutton_p.h>
98#include <QtQuickTemplates2/private/qquicktoolseparator_p.h>
99#include <QtQuickTemplates2/private/qquicktooltip_p.h>
100#if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview)
101#include <QtQuickTemplates2/private/qquicktumbler_p.h>
102#endif
103
104#if QT_CONFIG(shortcut)
105// qtdeclarative/src/quick/util/qquickshortcut.cpp
106typedef bool (*ShortcutContextMatcher)(QObject *, Qt::ShortcutContext);
107extern ShortcutContextMatcher qt_quick_shortcut_context_matcher();
108extern void qt_quick_set_shortcut_context_matcher(ShortcutContextMatcher matcher);
109#endif
110
111QT_BEGIN_NAMESPACE
112
113static void initProviders()
114{
115 QQuickPaletteProvider::init();
116}
117
118static void cleanupProviders()
119{
120 QQuickPaletteProvider::cleanup();
121}
122
123class QtQuickTemplates2Plugin: public QQmlExtensionPlugin
124{
125 Q_OBJECT
126 Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
127
128public:
129 QtQuickTemplates2Plugin(QObject *parent = nullptr);
130 ~QtQuickTemplates2Plugin();
131
132 void registerTypes(const char *uri) override;
133
134private:
135 bool registered;
136#if QT_CONFIG(shortcut)
137 ShortcutContextMatcher originalContextMatcher;
138#endif
139};
140
141QtQuickTemplates2Plugin::QtQuickTemplates2Plugin(QObject *parent)
142 : QQmlExtensionPlugin(parent), registered(false)
143{
144#if QT_CONFIG(shortcut)
145 originalContextMatcher = qt_quick_shortcut_context_matcher();
146 qt_quick_set_shortcut_context_matcher(QQuickShortcutContext::matcher);
147#endif
148}
149
150QtQuickTemplates2Plugin::~QtQuickTemplates2Plugin()
151{
152 if (registered)
153 cleanupProviders();
154
155#if QT_CONFIG(shortcut)
156 qt_quick_set_shortcut_context_matcher(originalContextMatcher);
157#endif
158}
159
160void QtQuickTemplates2Plugin::registerTypes(const char *uri)
161{
162 registered = true;
163 initProviders();
164
165 // Register the latest version, even if there are no new types or new revisions for existing types yet.
166 // Before Qt 5.12, we would do the following:
167 //
168 // qmlRegisterModule(uri, 2, QT_VERSION_MINOR - 7); // Qt 5.7->2.0, 5.8->2.1, 5.9->2.2...
169 //
170 // However, we want to align with the rest of Qt Quick which uses Qt's minor version.
171 qmlRegisterModule(uri, 2, QT_VERSION_MINOR);
172
173 // QtQuick.Templates 2.0 (originally introduced in Qt 5.7)
174 qmlRegisterType<QQuickAbstractButton>(uri, 2, 0, "AbstractButton");
175 qmlRegisterType<QQuickApplicationWindow>(uri, 2, 0, "ApplicationWindow");
176 qmlRegisterType<QQuickApplicationWindowAttached>();
177 qmlRegisterType<QQuickBusyIndicator>(uri, 2, 0, "BusyIndicator");
178 qmlRegisterType<QQuickButton>(uri, 2, 0, "Button");
179 qmlRegisterType<QQuickButtonGroup>(uri, 2, 0, "ButtonGroup");
180 qmlRegisterType<QQuickButtonGroupAttached>();
181 qmlRegisterType<QQuickCheckBox>(uri, 2, 0, "CheckBox");
182 qmlRegisterType<QQuickCheckDelegate>(uri, 2, 0, "CheckDelegate");
183 qmlRegisterType<QQuickComboBox>(uri, 2, 0, "ComboBox");
184 qmlRegisterType<QQuickContainer>(uri, 2, 0, "Container");
185 qmlRegisterType<QQuickControl>(uri, 2, 0, "Control");
186 qmlRegisterType<QQuickDial>(uri, 2, 0, "Dial");
187 qmlRegisterType<QQuickDrawer>(uri, 2, 0, "Drawer");
188 qmlRegisterType<QQuickFrame>(uri, 2, 0, "Frame");
189 qmlRegisterType<QQuickGroupBox>(uri, 2, 0, "GroupBox");
190 qmlRegisterType<QQuickItemDelegate>(uri, 2, 0, "ItemDelegate");
191 qmlRegisterType<QQuickLabel>(uri, 2, 0, "Label");
192 qmlRegisterType<QQuickMenu>(uri, 2, 0, "Menu");
193 qmlRegisterType<QQuickMenuItem>(uri, 2, 0, "MenuItem");
194 qmlRegisterType<QQuickOverlay>();
195 qmlRegisterType<QQuickPage>(uri, 2, 0, "Page");
196 qmlRegisterType<QQuickPageIndicator>(uri, 2, 0, "PageIndicator");
197 qmlRegisterType<QQuickPane>(uri, 2, 0, "Pane");
198 qmlRegisterType<QQuickPopup>(uri, 2, 0, "Popup");
199 qmlRegisterType<QQuickProgressBar>(uri, 2, 0, "ProgressBar");
200 qmlRegisterType<QQuickRadioButton>(uri, 2, 0, "RadioButton");
201 qmlRegisterType<QQuickRadioDelegate>(uri, 2, 0, "RadioDelegate");
202 qmlRegisterType<QQuickRangeSlider>(uri, 2, 0, "RangeSlider");
203 qmlRegisterType<QQuickRangeSliderNode>();
204 qmlRegisterType<QQuickScrollBar>(uri, 2, 0, "ScrollBar");
205 qmlRegisterType<QQuickScrollBarAttached>();
206 qmlRegisterType<QQuickScrollIndicator>(uri, 2, 0, "ScrollIndicator");
207 qmlRegisterType<QQuickScrollIndicatorAttached>();
208 qmlRegisterType<QQuickSlider>(uri, 2, 0, "Slider");
209 qmlRegisterType<QQuickSpinBox>(uri, 2, 0, "SpinBox");
210 qmlRegisterType<QQuickSpinButton>();
211 qmlRegisterType<QQuickStackView>(uri, 2, 0, "StackView");
212 qmlRegisterType<QQuickStackViewAttached>();
213 qmlRegisterType<QQuickSwipe>();
214 qmlRegisterType<QQuickSwipeDelegate>(uri, 2, 0, "SwipeDelegate");
215 qmlRegisterType<QQuickSwipeView>(uri, 2, 0, "SwipeView");
216 qmlRegisterType<QQuickSwipeViewAttached>();
217 qmlRegisterType<QQuickSwitch>(uri, 2, 0, "Switch");
218 qmlRegisterType<QQuickSwitchDelegate>(uri, 2, 0, "SwitchDelegate");
219 qmlRegisterType<QQuickTabBar>(uri, 2, 0, "TabBar");
220 qmlRegisterType<QQuickTabButton>(uri, 2, 0, "TabButton");
221 qmlRegisterType<QQuickTextArea>(uri, 2, 0, "TextArea");
222 qmlRegisterType<QQuickTextAreaAttached>();
223 qmlRegisterType<QQuickTextField>(uri, 2, 0, "TextField");
224 qmlRegisterType<QQuickToolBar>(uri, 2, 0, "ToolBar");
225 qmlRegisterType<QQuickToolButton>(uri, 2, 0, "ToolButton");
226 qmlRegisterType<QQuickToolTip>(uri, 2, 0, "ToolTip");
227 qmlRegisterType<QQuickToolTipAttached>();
228#if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview)
229 qmlRegisterType<QQuickTumblerAttached>();
230 qmlRegisterType<QQuickTumbler>(uri, 2, 0, "Tumbler");
231#endif
232
233 // NOTE: register the latest revisions of all template/control base classes to
234 // make revisioned properties available to their subclasses (synced with Qt 5.7)
235 qmlRegisterRevision<QQuickItem, 7>(uri, 2, 0);
236 qmlRegisterRevision<QQuickText, 6>(uri, 2, 0);
237 qmlRegisterRevision<QQuickTextInput, 7>(uri, 2, 0);
238 qmlRegisterRevision<QQuickTextEdit, 7>(uri, 2, 0);
239 qmlRegisterRevision<QQuickWindow, 2>(uri, 2, 0);
240 qmlRegisterRevision<QWindow, 3>(uri, 2, 0);
241
242 // QtQuick.Templates 2.1 (new types and revisions in Qt 5.8)
243 qmlRegisterType<QQuickButtonGroup, 1>(uri, 2, 1, "ButtonGroup");
244 qmlRegisterType<QQuickComboBox, 1>(uri, 2, 1, "ComboBox");
245 qmlRegisterType<QQuickContainer, 1>(uri, 2, 1, "Container");
246 qmlRegisterType<QQuickDialog>(uri, 2, 1, "Dialog");
247 qmlRegisterType<QQuickDialogButtonBox>(uri, 2, 1, "DialogButtonBox");
248 qmlRegisterType<QQuickDialogButtonBoxAttached>();
249 qmlRegisterType<QQuickMenuSeparator>(uri, 2, 1, "MenuSeparator");
250 qmlRegisterType<QQuickPage, 1>(uri, 2, 1, "Page");
251 qmlRegisterType<QQuickPopup, 1>(uri, 2, 1, "Popup");
252 qmlRegisterType<QQuickRangeSlider, 1>(uri, 2, 1, "RangeSlider");
253 qmlRegisterType<QQuickRoundButton>(uri, 2, 1, "RoundButton");
254 qmlRegisterType<QQuickSlider, 1>(uri, 2, 1, "Slider");
255 qmlRegisterType<QQuickSpinBox, 1>(uri, 2, 1, "SpinBox");
256 qmlRegisterType<QQuickStackView, 1>(uri, 2, 1, "StackView");
257 qmlRegisterType<QQuickSwipeDelegate, 1>(uri, 2, 1, "SwipeDelegate");
258 qmlRegisterType<QQuickSwipeView, 1>(uri, 2, 1, "SwipeView");
259 qmlRegisterType<QQuickTextArea, 1>(uri, 2, 1, "TextArea");
260 qmlRegisterType<QQuickTextField, 1>(uri, 2, 1, "TextField");
261 qmlRegisterType<QQuickToolSeparator>(uri, 2, 1, "ToolSeparator");
262#if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview)
263 qmlRegisterType<QQuickTumbler, 1>(uri, 2, 1, "Tumbler");
264#endif
265
266 // QtQuick.Templates 2.2 (new types and revisions in Qt 5.9)
267 qmlRegisterType<QQuickAbstractButton, 2>(uri, 2, 2, "AbstractButton");
268 qmlRegisterType<QQuickComboBox, 2>(uri, 2, 2, "ComboBox");
269 qmlRegisterType<QQuickDelayButton>(uri, 2, 2, "DelayButton");
270 qmlRegisterType<QQuickDial, 2>(uri, 2, 2, "Dial");
271 qmlRegisterType<QQuickDrawer, 2>(uri, 2, 2, "Drawer");
272 qmlRegisterType<QQuickRangeSlider, 2>(uri, 2, 2, "RangeSlider");
273 qmlRegisterType<QQuickScrollBar, 2>(uri, 2, 2, "ScrollBar");
274 qmlRegisterType<QQuickScrollView>(uri, 2, 2, "ScrollView");
275 qmlRegisterType<QQuickSlider, 2>(uri, 2, 2, "Slider");
276 qmlRegisterType<QQuickSpinBox, 2>(uri, 2, 2, "SpinBox");
277 qmlRegisterType<QQuickSwipeDelegate, 2>(uri, 2, 2, "SwipeDelegate");
278 qmlRegisterType<QQuickSwipeView, 2>(uri, 2, 2, "SwipeView");
279 qmlRegisterType<QQuickTabBar, 2>(uri, 2, 2, "TabBar");
280#if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview)
281 qmlRegisterType<QQuickTumbler, 2>(uri, 2, 2, "Tumbler");
282#endif
283
284 // NOTE: register the latest revisions of all template/control base classes to
285 // make revisioned properties available to their subclasses (synced with Qt 5.9)
286 qmlRegisterRevision<QQuickText, 9>(uri, 2, 2);
287 qmlRegisterRevision<QQuickTextInput, 9>(uri, 2, 2);
288 qmlRegisterRevision<QQuickWindowQmlImpl, 2>(uri, 2, 2);
289
290 // QtQuick.Templates 2.3 (new types and revisions in Qt 5.10)
291 qmlRegisterType<QQuickAbstractButton, 3>(uri, 2, 3, "AbstractButton");
292 qmlRegisterType<QQuickAction>(uri, 2, 3, "Action");
293 qmlRegisterType<QQuickActionGroup>(uri, 2, 3, "ActionGroup");
294 qmlRegisterType<QQuickApplicationWindow, 3>(uri, 2, 3, "ApplicationWindow");
295 qmlRegisterType<QQuickButtonGroup, 3>(uri, 2, 3, "ButtonGroup");
296 qmlRegisterType<QQuickControl, 3>(uri, 2, 3, "Control");
297 qmlRegisterType<QQuickContainer, 3>(uri, 2, 3, "Container");
298 qmlRegisterType<QQuickDialog, 3>(uri, 2, 3, "Dialog");
299 qmlRegisterType<QQuickDialogButtonBox, 3>(uri, 2, 3, "DialogButtonBox");
300 qmlRegisterType<QQuickIcon>();
301 qRegisterMetaType<QQuickIcon>();
302 qmlRegisterType<QQuickLabel, 3>(uri, 2, 3, "Label");
303 qmlRegisterType<QQuickMenu, 3>(uri, 2, 3, "Menu");
304 qmlRegisterType<QQuickMenuBar>(uri, 2, 3, "MenuBar");
305 qmlRegisterType<QQuickMenuBarItem>(uri, 2, 3, "MenuBarItem");
306 qmlRegisterType<QQuickMenuItem, 3>(uri, 2, 3, "MenuItem");
307 qmlRegisterUncreatableType<QQuickOverlay>(uri, 2, 3, "Overlay", QStringLiteral("Overlay is only available as an attached property."));
308 qmlRegisterType<QQuickOverlayAttached>();
309 qmlRegisterType<QQuickPopup, 3>(uri, 2, 3, "Popup");
310 qmlRegisterType<QQuickRangeSlider, 3>(uri, 2, 3, "RangeSlider");
311 qmlRegisterType<QQuickScrollBar, 3>(uri, 2, 3, "ScrollBar");
312 qmlRegisterType<QQuickScrollIndicator, 3>(uri, 2, 3, "ScrollIndicator");
313 qmlRegisterType<QQuickSlider, 3>(uri, 2, 3, "Slider");
314 qmlRegisterType<QQuickSpinBox, 3>(uri, 2, 3, "SpinBox");
315 qmlRegisterType<QQuickTextArea, 3>(uri, 2, 3, "TextArea");
316 qmlRegisterType<QQuickTextField, 3>(uri, 2, 3, "TextField");
317
318 // NOTE: register the latest revisions of all template/control base classes to
319 // make revisioned properties available to their subclasses (synced with Qt 5.10)
320 qmlRegisterRevision<QQuickText, 10>(uri, 2, 3);
321 qmlRegisterRevision<QQuickTextEdit, 10>(uri, 2, 3);
322
323 // QtQuick.Templates 2.4 (new types and revisions in Qt 5.11)
324 qmlRegisterType<QQuickAbstractButton, 4>(uri, 2, 4, "AbstractButton");
325 qmlRegisterType<QQuickButtonGroup, 4>(uri, 2, 4, "ButtonGroup");
326 qmlRegisterType<QQuickCheckBox, 4>(uri, 2, 4, "CheckBox");
327 qmlRegisterType<QQuickCheckDelegate, 4>(uri, 2, 4, "CheckDelegate");
328 qmlRegisterType<QQuickScrollBar, 4>(uri, 2, 4, "ScrollBar");
329 qmlRegisterType<QQuickScrollIndicator, 4>(uri, 2, 4, "ScrollIndicator");
330 qmlRegisterType<QQuickSpinBox, 4>(uri, 2, 4, "SpinBox");
331
332 // QtQuick.Templates 2.5 (new types and revisions in Qt 5.12)
333 qmlRegisterType<QQuickAbstractButton, 5>(uri, 2, 5, "AbstractButton");
334 qmlRegisterType<QQuickDialogButtonBox, 5>(uri, 2, 5, "DialogButtonBox");
335 qmlRegisterType<QQuickComboBox, 5>(uri, 2, 5, "ComboBox");
336 qmlRegisterType<QQuickControl, 5>(uri, 2, 5, "Control");
337 qmlRegisterType<QQuickContainer, 5>(uri, 2, 5, "Container");
338 qmlRegisterType<QQuickDial, 5>(uri, 2, 5, "Dial");
339 qmlRegisterType<QQuickDialog, 5>(uri, 2, 5, "Dialog");
340 qmlRegisterType<QQuickGroupBox, 5>(uri, 2, 5, "GroupBox");
341 qmlRegisterType<QQuickLabel, 5>(uri, 2, 5, "Label");
342 qmlRegisterType<QQuickPage, 5>(uri, 2, 5, "Page");
343 qmlRegisterType<QQuickPopup, 5>(uri, 2, 5, "Popup");
344 qmlRegisterType<QQuickPopupAnchors>();
345 qmlRegisterType<QQuickRangeSlider, 5>(uri, 2, 5, "RangeSlider");
346 qmlRegisterType<QQuickSlider, 5>(uri, 2, 5, "Slider");
347 qmlRegisterType<QQuickSpinBox, 5>(uri, 2, 5, "SpinBox");
348 qmlRegisterType<QQuickTextArea, 5>(uri, 2, 5, "TextArea");
349 qmlRegisterType<QQuickTextField, 5>(uri, 2, 5, "TextField");
350 qmlRegisterType<QQuickToolTip, 5>(uri, 2, 5, "ToolTip");
351
352 // QtQuick.Templates 2.13 (new types and revisions in Qt 5.13)
353 qmlRegisterType<QQuickSplitView>(uri, 2, 13, "SplitView");
354 qmlRegisterType<QQuickSplitViewAttached>();
355 qmlRegisterUncreatableType<QQuickSplitHandleAttached>(uri, 2, 13, "SplitHandle",
356 QStringLiteral("SplitHandle is only available as an attached property."));
357 qmlRegisterType<QQuickSplitHandleAttached>();
358
359 // QtQuick.Templates 2.14 (new types and revisions in Qt 5.14)
360 qmlRegisterType<QQuickComboBox, 14>(uri, 2, 14, "ComboBox");
361}
362
363QT_END_NAMESPACE
364
365#include "qtquicktemplates2plugin.moc"
366