12#include <QtQuickTemplates2/private/qquickcontrol_p.h>
13#include <QtCore/QScopedValueRollback>
23 QQStyleKitExtendableControlType exactType)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
49 case QQStyleKitReader::ApplicationWindow: {
50 static QList<QQStyleKitExtendableControlType> t =
51 { QQStyleKitReader::ApplicationWindow };
53 case QQStyleKitReader::Button:
54 case QQStyleKitReader::DelayButton:
55 case QQStyleKitReader::FlatButton:
56 case QQStyleKitReader::ToolButton:
57 case QQStyleKitReader::TabButton:
58 case QQStyleKitReader::RadioButton:
59 case QQStyleKitReader::RoundButton:
60 case QQStyleKitReader::CheckBox:
61 case QQStyleKitReader::SwitchControl: {
62 static QList<QQStyleKitExtendableControlType> t =
63 { QQStyleKitReader::AbstractButton, QQStyleKitReader::Control };
65 case QQStyleKitReader::CheckDelegate:
66 case QQStyleKitReader::RadioDelegate:
67 case QQStyleKitReader::SwipeDelegate:
68 case QQStyleKitReader::SwitchDelegate:
69 case QQStyleKitReader::TableViewDelegate:
70 case QQStyleKitReader::TreeViewDelegate: {
71 static QList<QQStyleKitExtendableControlType> t =
72 { QQStyleKitReader::ItemDelegate, QQStyleKitReader::Control };
74 case QQStyleKitReader::HorizontalHeaderViewDelegate:
75 case QQStyleKitReader::VerticalHeaderViewDelegate: {
76 static QList<QQStyleKitExtendableControlType> t =
77 { QQStyleKitReader::TableViewDelegate, QQStyleKitReader::ItemDelegate, QQStyleKitReader::Control };
80 case QQStyleKitReader::Dialog:
81 case QQStyleKitReader::Drawer:
82 case QQStyleKitReader::Menu:
83 case QQStyleKitReader::ToolTip: {
84 static QList<QQStyleKitExtendableControlType> t =
85 { QQStyleKitReader::Popup, QQStyleKitReader::Control };
87 case QQStyleKitReader::Page:
88 case QQStyleKitReader::DialogButtonBox:
89 case QQStyleKitReader::Frame:
90 case QQStyleKitReader::TabBar:
91 case QQStyleKitReader::ToolBar: {
92 static QList<QQStyleKitExtendableControlType> t =
93 { QQStyleKitReader::Pane, QQStyleKitReader::Control };
95 case QQStyleKitReader::GroupBox: {
96 static QList<QQStyleKitExtendableControlType> t =
97 { QQStyleKitReader::Frame, QQStyleKitReader::Pane, QQStyleKitReader::Control };
100 case QQStyleKitReader::TextField:
101 case QQStyleKitReader::TextArea: {
102 static QList<QQStyleKitExtendableControlType> t =
103 { QQStyleKitReader::TextInput, QQStyleKitReader::Control };
106 static QList<QQStyleKitExtendableControlType> t =
107 { QQStyleKitReader::Control };
117 Q_ASSERT(state != QQSK::StateFlag::Unspecified);
118 if (state == s_cachedState)
121 s_cachedState = state;
124
125
126
127
128 s_cachedStateList.clear();
129 if (state.testFlag(QQSK::StateFlag::Pressed))
130 s_cachedStateList.append(QQSK::StateFlag::Pressed);
131 if (state.testFlag(QQSK::StateFlag::Hovered))
132 s_cachedStateList.append(QQSK::StateFlag::Hovered);
133 if (state.testFlag(QQSK::StateFlag::Highlighted))
134 s_cachedStateList.append(QQSK::StateFlag::Highlighted);
135 if (state.testFlag(QQSK::StateFlag::Focused))
136 s_cachedStateList.append(QQSK::StateFlag::Focused);
137 if (state.testFlag(QQSK::StateFlag::Checked))
138 s_cachedStateList.append(QQSK::StateFlag::Checked);
139 if (state.testFlag(QQSK::StateFlag::Vertical))
140 s_cachedStateList.append(QQSK::StateFlag::Vertical);
141 if (state.testFlag(QQSK::StateFlag::Disabled))
142 s_cachedStateList.append(QQSK::StateFlag::Disabled);
146 QQStyleKitReader *styleReader,
151
152
153
154 if (!styleReader->m_effectiveVariations.contains(variation))
155 styleReader->m_effectiveVariations.append(variation);
158
159
160
161 if (!variation->m_usageContext.contains(styleOrTheme))
162 variation->m_usageContext.append(styleOrTheme);
166 QQStyleKitReader *styleReader,
168 const AttachedVariationList &attachedVariations)
170 const QQStyleKitExtendableControlType styleReaderType = styleReader->controlType();
171 const auto styleReaderBaseType = baseTypesForType(styleReaderType);
173 static PropertyPathIds ids;
174 if (ids.property.property() == QQSK::Property::NoProperty) {
176
177
178 ids.property = QQStyleKitPropertyPath(styleReader, QQSK::Property::Variations, QQStyleKitPropertyPath::Flag::ExcludeSubtype);
179 ids.alternative = QQStyleKitPropertyPath(styleReader, QQSK::Property::NoProperty, QQStyleKitPropertyPath::Flag::ExcludeSubtype);
184 for (
const QQStyleKitVariationAttached *attached : attachedVariations) {
185 const auto parentType = attached->controlType();
186 const auto parentBaseTypes = baseTypesForType(parentType);
189
190
191
192 const QVariant typeVariationsVariant = readPropertyInRelevantControls(styleOrTheme, ids, parentType, parentBaseTypes);
193 if (!typeVariationsVariant.isValid())
196 const auto typeVariations = *qvariant_cast<QList<QQStyleKitVariation *> *>(typeVariationsVariant);
198 for (QQStyleKitVariation *variation : typeVariations) {
200
201
204
208 if (variation->getControlStyle(styleReaderType)) {
209 addVariationToReader(styleReader, styleOrTheme, variation);
211 for (
int type : styleReaderBaseType) {
212 if (variation->getControlStyle(type))
213 addVariationToReader(styleReader, styleOrTheme, variation);
221 QQStyleKitReader *styleReader,
223 const AttachedVariationList &attachedVariations)
226
227
228
229
230 const QQStyleKitExtendableControlType styleReaderType = styleReader->controlType();
231 const auto styleReaderBaseTypes = baseTypesForType(styleReaderType);
233 for (
const QQStyleKitVariationAttached *attached : attachedVariations) {
234 for (
const QString &instanceVariationName : attached->variations()) {
235 for (QQStyleKitVariation *variation : styleOrTheme->m_styleVariations) {
236 if (variation->name() != instanceVariationName)
240
241
242
243 if (variation->getControlStyle(styleReaderType)) {
244 addVariationToReader(styleReader, styleOrTheme, variation);
246 for (
int baseType : styleReaderBaseTypes) {
247 if (variation->getControlStyle(baseType))
248 addVariationToReader(styleReader, styleOrTheme, variation);
257 QQStyleKitReader *styleReader, QQStyleKitStyle *style)
260
261
262
263
264
265
266 Q_ASSERT(styleReader->m_effectiveVariationsDirty);
267 styleReader->m_effectiveVariationsDirty =
false;
268 styleReader->m_effectiveVariations.clear();
270 if (!style->m_hasVariations)
274
275
276 AttachedVariationList attachedVariations;
277 for (QObject *current = styleReader; current; current = current->parent()) {
278 if (
const QObject *attachedObject = qmlAttachedPropertiesObject<QQStyleKitVariation>(current,
false)) {
280 attachedVariations.append(attached);
284 if (attachedVariations.isEmpty())
287 for (QQStyleKitStyle *current = style; current; current = current->fallbackStyle()) {
289 addInstanceVariationsToReader(styleReader, theme, attachedVariations);
290 addTypeVariationsToReader(styleReader, theme, attachedVariations);
292 addInstanceVariationsToReader(styleReader, current, attachedVariations);
293 addTypeVariationsToReader(styleReader, current, attachedVariations);
300 const T *storageProvider, QQSK::State state)
303
304
305
306
307
308
309
310
311
312 Q_ASSERT(qlonglong(state) <= qlonglong(QQSK::StateFlag::MAX_STATE));
314 const PropertyStorageId propertyKey = main.createStorageId(state);
317 QQStyleKitDebug::trace(main, storageProvider, state, propertyKey);
319 const QVariant propertyValue = storageProvider->readStyleProperty(propertyKey);
320 if (propertyValue.isValid()) {
322 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, propertyValue);
323 return propertyValue;
326 const PropertyStorageId altPropertyKey = alternative.createStorageId(state);
329 QQStyleKitDebug::trace(alternative, storageProvider, state, altPropertyKey);
331 const QVariant altValue = storageProvider->readStyleProperty(altPropertyKey);
332 if (altValue.isValid()) {
334 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, altValue);
341template <
class INDICES_CONTAINER>
345 int startIndex,
int recursionLevel)
347 for (
int i = startIndex; i < s_cachedStateList.length(); ++i) {
349
350
351
352
353
354
355
356 stateListIndices[recursionLevel] = i;
357 const QQSK::StateFlag stateFlag = s_cachedStateList[i];
360
361 if (!control->m_writtenStates.testFlag(stateFlag))
365
367 const QQSK::State statesAffectingProperty = controls->m_writtenPropertyPaths[main.pathId()];
368 if (!statesAffectingProperty.testFlag(stateFlag)) {
369 if (alternative.property() == QQSK::Property::NoProperty) {
372 const QQSK::State statesAffectingAlternative = controls->m_writtenPropertyPaths[alternative.pathId()];
373 if (!statesAffectingAlternative.testFlag(stateFlag))
378 if (recursionLevel < s_cachedStateList.length() - 1) {
380 const QVariant value = readPropertyInControlForStates(
381 main, alternative, control, stateListIndices, i + 1, recursionLevel + 1);
387 QQSK::State storageState = QQSK::StateFlag::Unspecified;
388 for (
int j = 0; j <= recursionLevel; ++j)
389 storageState.setFlag(s_cachedStateList[stateListIndices[j]]);
390 const QVariant value = readPropertyInStorageForState(main, alternative, control, storageState);
402
403
404
405
406 QVarLengthArray<
int, 10> stateListIndices(s_cachedStateList.length());
408 if (ids.subTypeProperty.property() != QQSK::Property::NoProperty) {
409 if (s_cachedState != QQSK::StateFlag::Normal) {
410 QVariant value = readPropertyInControlForStates(
411 ids.subTypeProperty, ids.subTypeAlternative, control, stateListIndices, 0, 0);
416 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal)) {
417 const QVariant value = readPropertyInStorageForState(
418 ids.subTypeProperty, ids.subTypeAlternative, control, QQSK::StateFlag::Normal);
424 if (s_cachedState != QQSK::StateFlag::Normal) {
425 const QVariant value = readPropertyInControlForStates(
426 ids.property, ids.alternative, control, stateListIndices, 0, 0);
432
433
434
435 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal))
436 return readPropertyInStorageForState(ids.property, ids.alternative, control, QQSK::StateFlag::Normal);
443 const QQStyleKitExtendableControlType exactType,
444 const QList<QQStyleKitExtendableControlType> baseTypes)
450
452 const auto writtenProperties = controls->m_writtenPropertyPaths;
453 if (writtenProperties.contains(ids.property.pathId()))
455 const bool hasAlternative = ids.alternative.property() != QQSK::Property::NoProperty;
456 if (hasAlternative && writtenProperties.contains(ids.alternative.pathId()))
458 if (ids.subTypeProperty.property() == QQSK::Property::NoProperty)
460 if (writtenProperties.contains(ids.subTypeProperty.pathId()))
462 if (hasAlternative && writtenProperties.contains(ids.subTypeAlternative.pathId()))
468 const QVariant value = readPropertyInControl(ids, control);
473 for (
const int type : baseTypes) {
474 if (
const QQStyleKitControl *control = controls->getControlStyle(type)) {
475 const QVariant value = readPropertyInControl(ids, control);
485 const QList<QPointer<QQStyleKitVariation>> &variations,
487 const PropertyPathIds &ids,
488 const QQStyleKitExtendableControlType exactType,
489 const QList<QQStyleKitExtendableControlType> baseTypes)
491 bool foundAtLeastOneVariation =
false;
492 for (
const QPointer<QQStyleKitVariation> &variation : variations) {
495 if (!variation->m_usageContext.contains(styleOrTheme)) {
496 if (foundAtLeastOneVariation) {
498
499
500
504
507 foundAtLeastOneVariation =
true;
508 const QVariant value = readPropertyInRelevantControls(variation, ids, exactType, baseTypes);
516 QQStyleKitStyle *style,
const PropertyPathIds &ids, QQStyleKitReader *styleReader)
519
520
521 style->syncFromQPalette(styleReader->effectivePalette());
524
525
526 cacheReaderState(styleReader->controlState());
528 if (styleReader->m_effectiveVariationsDirty)
529 rebuildVariationsForReader(styleReader, style);
531 const QQStyleKitExtendableControlType exactType = styleReader->controlType();
532 const QList<QQStyleKitExtendableControlType> baseTypes = baseTypesForType(exactType);
537 value = readPropertyInVariations(styleReader->m_effectiveVariations, style->theme(), ids, exactType, baseTypes);
541 value = readPropertyInRelevantControls(style->theme(), ids, exactType, baseTypes);
545 value = readPropertyInVariations(styleReader->m_effectiveVariations, style, ids, exactType, baseTypes);
549 value = readPropertyInRelevantControls(style, ids, exactType, baseTypes);
553 if (
auto *fallbackStyle = style->fallbackStyle()) {
555
556 value = readPropertyInStyle(fallbackStyle, ids, styleReader);
565 if (!value.isValid())
574 const QQSK::Property property,
575 const QQSK::Property alternative)
578 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
579 const QQSK::Subclass subclass = controlProperties->subclass();
581 if (subclass != QQSK::Subclass::QQStyleKitReader) {
583
584
585
586
587
588
589
590 Q_ASSERT(subclass == QQSK::Subclass::QQStyleKitState);
593 const PropertyStorageId key =
QQStyleKitPropertyPath(group, property).createStorageId(controlState->nestedState());
594 return control->readStyleProperty(key);
597 QQStyleKitStyle *style = controlProperties->style();
598 if (!style || !style->loaded()) {
600
601
602
607 QQStyleKitReader *styleReader = controlProperties->asQQStyleKitReader();
609 if (s_isReadingProperty) {
610 if (!s_styleWarningsIssued) {
611 s_styleWarningsIssued =
true;
612 qmlWarning(styleReader) <<
"The style property '" << property <<
"' was read "
613 <<
"before finishing the read of another style property. "
614 <<
"This is likely to cause a style glitch.";
617 QScopedValueRollback rollback(s_isReadingProperty,
true);
620 ids.property = QQStyleKitPropertyPath(group, property, QQStyleKitPropertyPath::Flag::ExcludeSubtype);
621 ids.alternative = QQStyleKitPropertyPath(group, alternative, QQStyleKitPropertyPath::Flag::ExcludeSubtype);
622 const bool insideSubType = pathFlags &
623 (QQSK::PropertyPathFlag::DelegateSubtype1 | QQSK::PropertyPathFlag::DelegateSubtype2);
633 if (!pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
635
636
637
638
640 const QVariant value = readPropertyInStorageForState(
641 ids.subTypeProperty, ids.subTypeAlternative, styleReader, QQSK::StateFlag::Normal);
645 const QVariant value = readPropertyInStorageForState(
646 ids.property, ids.alternative, styleReader, QQSK::StateFlag::Normal);
651 return readPropertyInStyle(style, ids, styleReader);
656 const QQSK::Property property,
657 const QVariant &value)
663 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
664 const QQSK::Subclass subclass = controlProperties->subclass();
667 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
668 qmlWarning(controlProperties) <<
"Properties inside 'global' are read-only!";
672 if (subclass == QQSK::Subclass::QQStyleKitReader) {
674 QQStyleKitReader *reader = controlProperties->asQQStyleKitReader();
675 const PropertyStorageId key = propertyPath.createStorageId(QQSK::StateFlag::Normal);
676 const QVariant currentValue = reader->readStyleProperty(key);
677 const bool valueChanged = currentValue != value;
679 reader->writeStyleProperty(key, value);
680 QQStyleKitDebug::notifyPropertyWrite(group, property, reader, QQSK::StateFlag::Normal, key, value);
685 if (subclass == QQSK::Subclass::QQStyleKitState) {
689 const QQSK::State nestedState = controlState->nestedState();
690 const PropertyStorageId key = propertyPath.createStorageId(nestedState);
691 const QVariant currentValue = control->readStyleProperty(key);
692 const bool valueChanged = currentValue != value;
695
696
697 control->m_writtenStates |= nestedState;
699
700
701
703 const QQSK::State alreadyWrittenStates = controls->m_writtenPropertyPaths[propertyPath.pathId()];
704 controls->m_writtenPropertyPaths[propertyPath.pathId()] = alreadyWrittenStates | nestedState;
706 control->writeStyleProperty(key, value);
707 QQStyleKitDebug::notifyPropertyWrite(group, property, control, nestedState, key, value);
718 const QQSK::Property property)
722 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
724 const QQSK::Subclass subclass = controlProperties->subclass();
726 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global))
729 if (subclass == QQSK::Subclass::QQStyleKitReader) {
730 const PropertyStorageId key = propertyPath.createStorageId(QQSK::StateFlag::Normal);
731 return controlProperties->asQQStyleKitReader()->readStyleProperty(key).isValid();
734 if (subclass == QQSK::Subclass::QQStyleKitState) {
737 const PropertyStorageId key = propertyPath.createStorageId(controlState->nestedState());
738 return control->readStyleProperty(key).isValid();
747#include "moc_qqstylekitpropertyresolver_p.cpp"
QQStyleKitControl * control() const
QQStyleKitControlProperties * controlProperties() const
Combined button and popup list for selecting options.