Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqstylekitcontrols.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
8
10
11using namespace Qt::StringLiterals;
12
13QQStyleKitControls::QQStyleKitControls(QObject *parent)
14 : QObject(parent)
15{
16}
17
19{
20 return QQmlListProperty<QObject>(this, &m_data);
21}
22
24{
25 return m_data;
26}
27
28/* Lazy-create the controls that the style is actually using, when accessed
29 * them from the style/application (e.g from Style or Theme). We don't lazy
30 * create any controls while resolving style properties, as undefined controls would
31 * anyway not contain any property overrides. The properties have setters too, to
32 * allow the style/application to share custom StyleKitControls the classical
33 * way, e.g button: StyleKitControl { id: button }. */
34QQStyleKitControl* QQStyleKitControls::getControl(QQStyleKitExtendableControlType controlType) const
35{
36 if (!m_controls.contains(controlType))
37 return nullptr;
38 return m_controls[controlType];
39}
40
41
43{
44 QList<QQStyleKitVariation *> list;
45 for (auto *obj : children()) {
46 if (auto *variation = qobject_cast<QQStyleKitVariation *>(obj))
47 list.append(variation);
48 }
49 return list;
50}
51
52#define IMPLEMENT_ACCESSORS(NAME, TYPE) QQStyleKitControl
53 *QQStyleKitControls::NAME() const \
54{
55 if (!m_controls.contains(TYPE)) {
56 auto *self = const_cast<QQStyleKitControls *>(this);
57 auto *control = new QQStyleKitControl(self);
58 self->m_controls.insert(TYPE, control);
59 }
60 return m_controls[TYPE]; \
61}void
62 QQStyleKitControls::set_ ## NAME(QQStyleKitControl *control) \
63{
64 m_controls.insert(TYPE, control); \
65}
66
67
68IMPLEMENT_ACCESSORS(abstractButton, QQStyleKitReader::ControlType::AbstractButton)
69IMPLEMENT_ACCESSORS(applicationWindow, QQStyleKitReader::ControlType::ApplicationWindow)
70IMPLEMENT_ACCESSORS(control, QQStyleKitReader::ControlType::Control)
71IMPLEMENT_ACCESSORS(button, QQStyleKitReader::ControlType::Button)
72IMPLEMENT_ACCESSORS(flatButton, QQStyleKitReader::ControlType::FlatButton)
73IMPLEMENT_ACCESSORS(checkBox, QQStyleKitReader::ControlType::CheckBox)
74IMPLEMENT_ACCESSORS(comboBox, QQStyleKitReader::ControlType::ComboBox)
75IMPLEMENT_ACCESSORS(progressBar, QQStyleKitReader::ControlType::ProgressBar)
76IMPLEMENT_ACCESSORS(scrollBar, QQStyleKitReader::ControlType::ScrollBar)
77IMPLEMENT_ACCESSORS(scrollIndicator, QQStyleKitReader::ControlType::ScrollIndicator)
78IMPLEMENT_ACCESSORS(scrollView, QQStyleKitReader::ControlType::ScrollView)
79IMPLEMENT_ACCESSORS(slider, QQStyleKitReader::ControlType::Slider)
80IMPLEMENT_ACCESSORS(spinBox, QQStyleKitReader::ControlType::SpinBox)
81IMPLEMENT_ACCESSORS(switchControl, QQStyleKitReader::ControlType::SwitchControl)
82IMPLEMENT_ACCESSORS(tabBar, QQStyleKitReader::ControlType::TabBar)
83IMPLEMENT_ACCESSORS(tabButton, QQStyleKitReader::ControlType::TabButton)
84IMPLEMENT_ACCESSORS(textField, QQStyleKitReader::ControlType::TextField)
85IMPLEMENT_ACCESSORS(textInput, QQStyleKitReader::ControlType::TextInput)
86IMPLEMENT_ACCESSORS(toolBar, QQStyleKitReader::ControlType::ToolBar)
87IMPLEMENT_ACCESSORS(toolButton, QQStyleKitReader::ControlType::ToolButton)
88IMPLEMENT_ACCESSORS(toolSeparator, QQStyleKitReader::ControlType::ToolSeparator)
89IMPLEMENT_ACCESSORS(radioButton, QQStyleKitReader::ControlType::RadioButton)
90IMPLEMENT_ACCESSORS(itemDelegate, QQStyleKitReader::ControlType::ItemDelegate)
91IMPLEMENT_ACCESSORS(popup, QQStyleKitReader::ControlType::Popup)
92IMPLEMENT_ACCESSORS(pane, QQStyleKitReader::ControlType::Pane)
93IMPLEMENT_ACCESSORS(page, QQStyleKitReader::ControlType::Page)
94IMPLEMENT_ACCESSORS(frame, QQStyleKitReader::ControlType::Frame)
95IMPLEMENT_ACCESSORS(label, QQStyleKitReader::ControlType::Label)
96IMPLEMENT_ACCESSORS(groupBox, QQStyleKitReader::ControlType::GroupBox)
97IMPLEMENT_ACCESSORS(textArea, QQStyleKitReader::ControlType::TextArea)
98
99#undef IMPLEMENT_ACCESSORS
100
102{
103 for (auto *obj : children()) {
104 if (auto *customControl = qobject_cast<QQStyleKitCustomControl *>(obj)) {
105 const QQStyleKitExtendableControlType type = customControl->controlType();
106 const QQStyleKitExtendableControlType reserved
107 = QQStyleKitExtendableControlType(QQStyleKitReader::ControlType::Unspecified);
108 if (type >= reserved)
109 qmlWarning(this) << "CustomControls must use a controlType less than " << reserved;
110 if (m_controls.contains(type))
111 qmlWarning(this) << "CustomControl registered more than once: " << type;
112 m_controls.insert(type, customControl);
113 }
114 }
115}
116
117QT_END_NAMESPACE
118
119#include "moc_qqstylekitcontrols_p.cpp"
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
const QList< QObject * > children() const
QList< QQStyleKitVariation * > variations() const
QQmlListProperty< QObject > data()
Combined button and popup list for selecting options.
#define IMPLEMENT_ACCESSORS(NAME, TYPE)