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::FlatButton:
55 case QQStyleKitReader::ToolButton:
56 case QQStyleKitReader::TabButton:
57 case QQStyleKitReader::RadioButton:
58 case QQStyleKitReader::RoundButton:
59 case QQStyleKitReader::CheckBox:
60 case QQStyleKitReader::SwitchControl: {
61 static QList<QQStyleKitExtendableControlType> t =
62 { QQStyleKitReader::AbstractButton, QQStyleKitReader::Control };
64 case QQStyleKitReader::CheckDelegate:
65 case QQStyleKitReader::RadioDelegate:
66 case QQStyleKitReader::SwipeDelegate:
67 case QQStyleKitReader::SwitchDelegate: {
68 static QList<QQStyleKitExtendableControlType> t =
69 { QQStyleKitReader::ItemDelegate, QQStyleKitReader::Control };
71 case QQStyleKitReader::Menu:
72 case QQStyleKitReader::Dialog: {
73 static QList<QQStyleKitExtendableControlType> t =
74 { QQStyleKitReader::Popup, QQStyleKitReader::Control };
76 case QQStyleKitReader::Page:
77 case QQStyleKitReader::Frame:
78 case QQStyleKitReader::TabBar:
79 case QQStyleKitReader::ToolBar: {
80 static QList<QQStyleKitExtendableControlType> t =
81 { QQStyleKitReader::Pane, QQStyleKitReader::Control };
83 case QQStyleKitReader::GroupBox: {
84 static QList<QQStyleKitExtendableControlType> t =
85 { QQStyleKitReader::Frame, QQStyleKitReader::Pane, QQStyleKitReader::Control };
88 case QQStyleKitReader::TextField:
89 case QQStyleKitReader::TextArea: {
90 static QList<QQStyleKitExtendableControlType> t =
91 { QQStyleKitReader::TextInput, QQStyleKitReader::Control };
94 static QList<QQStyleKitExtendableControlType> t =
95 { QQStyleKitReader::Control };
105 Q_ASSERT(state != QQSK::StateFlag::Unspecified);
106 if (state == s_cachedState)
109 s_cachedState = state;
112
113
114
115
116 s_cachedStateList.clear();
117 if (state.testFlag(QQSK::StateFlag::Pressed))
118 s_cachedStateList.append(QQSK::StateFlag::Pressed);
119 if (state.testFlag(QQSK::StateFlag::Hovered))
120 s_cachedStateList.append(QQSK::StateFlag::Hovered);
121 if (state.testFlag(QQSK::StateFlag::Highlighted))
122 s_cachedStateList.append(QQSK::StateFlag::Highlighted);
123 if (state.testFlag(QQSK::StateFlag::Focused))
124 s_cachedStateList.append(QQSK::StateFlag::Focused);
125 if (state.testFlag(QQSK::StateFlag::Checked))
126 s_cachedStateList.append(QQSK::StateFlag::Checked);
127 if (state.testFlag(QQSK::StateFlag::Vertical))
128 s_cachedStateList.append(QQSK::StateFlag::Vertical);
129 if (state.testFlag(QQSK::StateFlag::Disabled))
130 s_cachedStateList.append(QQSK::StateFlag::Disabled);
134 QQStyleKitReader *styleReader,
139
140
141
142 if (!styleReader->m_effectiveVariations.contains(variation))
143 styleReader->m_effectiveVariations.append(variation);
146
147
148
149 if (!variation->m_usageContext.contains(styleOrTheme))
150 variation->m_usageContext.append(styleOrTheme);
154 QQStyleKitReader *styleReader,
156 const AttachedVariationList &attachedVariations)
158 const QQStyleKitExtendableControlType styleReaderType = styleReader->controlType();
159 const auto styleReaderBaseType = baseTypesForType(styleReaderType);
161 static PropertyPathIds ids;
162 if (ids.property.property() == QQSK::Property::NoProperty) {
164
165
166 ids.property = styleReader->propertyPathId(QQSK::Property::Variations, PropertyPathId::Flag::ExcludeSubtype);
167 ids.alternative = styleReader->propertyPathId(QQSK::Property::NoProperty, PropertyPathId::Flag::ExcludeSubtype);
172 for (
const QQStyleKitVariationAttached *attached : attachedVariations) {
173 const auto parentType = attached->controlType();
174 const auto parentBaseTypes = baseTypesForType(parentType);
177
178
179
180 const QVariant typeVariationsVariant = readPropertyInRelevantControls(styleOrTheme, ids, parentType, parentBaseTypes);
181 if (!typeVariationsVariant.isValid())
184 const auto typeVariations = *qvariant_cast<QList<QQStyleKitVariation *> *>(typeVariationsVariant);
186 for (QQStyleKitVariation *variation : typeVariations) {
188
189
192
196 if (variation->getControl(styleReaderType)) {
197 addVariationToReader(styleReader, styleOrTheme, variation);
199 for (
int type : styleReaderBaseType) {
200 if (variation->getControl(type))
201 addVariationToReader(styleReader, styleOrTheme, variation);
209 QQStyleKitReader *styleReader,
211 const AttachedVariationList &attachedVariations)
214
215
216
217
218 const QQStyleKitExtendableControlType styleReaderType = styleReader->controlType();
219 const auto styleReaderBaseTypes = baseTypesForType(styleReaderType);
221 for (
const QQStyleKitVariationAttached *attached : attachedVariations) {
222 for (
const QString &instanceVariationName : attached->variations()) {
223 for (QQStyleKitVariation *variation : styleOrTheme->m_styleVariations) {
224 if (variation->name() != instanceVariationName)
228
229
230
231 if (variation->getControl(styleReaderType)) {
232 addVariationToReader(styleReader, styleOrTheme, variation);
234 for (
int baseType : styleReaderBaseTypes) {
235 if (variation->getControl(baseType))
236 addVariationToReader(styleReader, styleOrTheme, variation);
245 QQStyleKitReader *styleReader, QQStyleKitStyle *style)
248
249
250
251
252
253
254 Q_ASSERT(styleReader->m_effectiveVariationsDirty);
255 styleReader->m_effectiveVariationsDirty =
false;
256 styleReader->m_effectiveVariations.clear();
258 if (!style->m_hasVariations)
262
263
264 AttachedVariationList attachedVariations;
265 for (QObject *current = styleReader; current; current = current->parent()) {
266 if (
const QObject *attachedObject = qmlAttachedPropertiesObject<QQStyleKitVariation>(current,
false)) {
268 attachedVariations.append(attached);
272 if (attachedVariations.isEmpty())
275 for (QQStyleKitStyle *current = style; current; current = current->fallbackStyle()) {
277 addInstanceVariationsToReader(styleReader, theme, attachedVariations);
278 addTypeVariationsToReader(styleReader, theme, attachedVariations);
280 addInstanceVariationsToReader(styleReader, current, attachedVariations);
281 addTypeVariationsToReader(styleReader, current, attachedVariations);
288 const T *storageProvider, QQSK::State state)
291
292
293
294
295
296
297
298
299
300 Q_ASSERT(qlonglong(state) <= qlonglong(QQSK::StateFlag::MAX_STATE));
302 const PropertyStorageId propertyKey = main.storageId(state);
305 QQStyleKitDebug::trace(main, storageProvider, state, propertyKey);
307 const QVariant propertyValue = storageProvider->readStyleProperty(propertyKey);
308 if (propertyValue.isValid()) {
310 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, propertyValue);
311 return propertyValue;
314 const PropertyStorageId altPropertyKey = alternative.storageId(state);
317 QQStyleKitDebug::trace(alternative, storageProvider, state, altPropertyKey);
319 const QVariant altValue = storageProvider->readStyleProperty(altPropertyKey);
320 if (altValue.isValid()) {
322 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, altValue);
329template <
class INDICES_CONTAINER>
333 int startIndex,
int recursionLevel)
335 for (
int i = startIndex; i < s_cachedStateList.length(); ++i) {
337
338
339
340
341
342
343
344 stateListIndices[recursionLevel] = i;
345 const QQSK::StateFlag stateFlag = s_cachedStateList[i];
348
349 if (!control->m_writtenStates.testFlag(stateFlag))
353
355 const QQSK::State statesAffectingProperty = controls->m_writtenPropertyPaths[main.pathId()];
356 if (!statesAffectingProperty.testFlag(stateFlag)) {
357 if (alternative.property() == QQSK::Property::NoProperty) {
360 const QQSK::State statesAffectingAlternative = controls->m_writtenPropertyPaths[alternative.pathId()];
361 if (!statesAffectingAlternative.testFlag(stateFlag))
366 if (recursionLevel < s_cachedStateList.length() - 1) {
368 const QVariant value = readPropertyInControlForStates(
369 main, alternative, control, stateListIndices, i + 1, recursionLevel + 1);
375 QQSK::State storageState = QQSK::StateFlag::Unspecified;
376 for (
int j = 0; j <= recursionLevel; ++j)
377 storageState.setFlag(s_cachedStateList[stateListIndices[j]]);
378 const QVariant value = readPropertyInStorageForState(main, alternative, control, storageState);
390
391
392
393
394 QVarLengthArray<
int, 10> stateListIndices(s_cachedStateList.length());
396 if (ids.subTypeProperty.property() != QQSK::Property::NoProperty) {
397 if (s_cachedState != QQSK::StateFlag::Normal) {
398 QVariant value = readPropertyInControlForStates(
399 ids.subTypeProperty, ids.subTypeAlternative, control, stateListIndices, 0, 0);
404 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal)) {
405 const QVariant value = readPropertyInStorageForState(
406 ids.subTypeProperty, ids.subTypeAlternative, control, QQSK::StateFlag::Normal);
412 if (s_cachedState != QQSK::StateFlag::Normal) {
413 const QVariant value = readPropertyInControlForStates(
414 ids.property, ids.alternative, control, stateListIndices, 0, 0);
420
421
422
423 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal))
424 return readPropertyInStorageForState(ids.property, ids.alternative, control, QQSK::StateFlag::Normal);
431 const QQStyleKitExtendableControlType exactType,
432 const QList<QQStyleKitExtendableControlType> baseTypes)
438
440 const auto writtenProperties = controls->m_writtenPropertyPaths;
441 if (writtenProperties.contains(ids.property.pathId()))
443 const bool hasAlternative = ids.alternative.property() != QQSK::Property::NoProperty;
444 if (hasAlternative && writtenProperties.contains(ids.alternative.pathId()))
446 if (ids.subTypeProperty.property() == QQSK::Property::NoProperty)
448 if (writtenProperties.contains(ids.subTypeProperty.pathId()))
450 if (hasAlternative && writtenProperties.contains(ids.subTypeAlternative.pathId()))
456 const QVariant value = readPropertyInControl(ids, control);
461 for (
const int type : baseTypes) {
462 if (
const QQStyleKitControl *control = controls->getControl(type)) {
463 const QVariant value = readPropertyInControl(ids, control);
473 const QList<QPointer<QQStyleKitVariation>> &variations,
475 const PropertyPathIds &ids,
476 const QQStyleKitExtendableControlType exactType,
477 const QList<QQStyleKitExtendableControlType> baseTypes)
479 bool foundAtLeastOneVariation =
false;
480 for (
const QPointer<QQStyleKitVariation> &variation : variations) {
483 if (!variation->m_usageContext.contains(styleOrTheme)) {
484 if (foundAtLeastOneVariation) {
486
487
488
492
495 foundAtLeastOneVariation =
true;
496 const QVariant value = readPropertyInRelevantControls(variation, ids, exactType, baseTypes);
504 QQStyleKitStyle *style,
const PropertyPathIds &ids, QQStyleKitReader *styleReader)
507
508
509 style->syncFromQPalette(styleReader->effectivePalette());
512
513
514 cacheReaderState(styleReader->controlState());
516 if (styleReader->m_effectiveVariationsDirty)
517 rebuildVariationsForReader(styleReader, style);
519 const QQStyleKitExtendableControlType exactType = styleReader->controlType();
520 const QList<QQStyleKitExtendableControlType> baseTypes = baseTypesForType(exactType);
525 value = readPropertyInVariations(styleReader->m_effectiveVariations, style->theme(), ids, exactType, baseTypes);
529 value = readPropertyInRelevantControls(style->theme(), ids, exactType, baseTypes);
533 value = readPropertyInVariations(styleReader->m_effectiveVariations, style, ids, exactType, baseTypes);
537 value = readPropertyInRelevantControls(style, ids, exactType, baseTypes);
541 if (
auto *fallbackStyle = style->fallbackStyle()) {
543
544 value = readPropertyInStyle(fallbackStyle, ids, styleReader);
553 if (!value.isValid())
562 const QQSK::Property property,
563 const QQSK::Property alternative)
566 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
567 const QQSK::Subclass subclass = controlProperties->subclass();
569 if (subclass != QQSK::Subclass::QQStyleKitReader) {
571
572
573
574
575
576
577
578 Q_ASSERT(subclass == QQSK::Subclass::QQStyleKitState);
581 const PropertyPathId propertyPathId = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
582 const PropertyStorageId key = propertyPathId.storageId(controlState->nestedState());
583 return control->readStyleProperty(key);
586 QQStyleKitStyle *style = controlProperties->style();
587 if (!style || !style->loaded()) {
589
590
591
596 QQStyleKitReader *styleReader = controlProperties->asQQStyleKitReader();
598 if (s_isReadingProperty) {
599 if (!s_styleWarningsIssued) {
600 s_styleWarningsIssued =
true;
601 qmlWarning(styleReader) <<
"The style property '" << property <<
"' was read "
602 <<
"before finishing the read of another style property. "
603 <<
"This is likely to cause a style glitch.";
606 QScopedValueRollback rollback(s_isReadingProperty,
true);
609 ids.property = group->propertyPathId(property, PropertyPathId::Flag::ExcludeSubtype);
610 ids.alternative = group->propertyPathId(alternative, PropertyPathId::Flag::ExcludeSubtype);
611 const bool insideSubType = pathFlags &
612 (QQSK::PropertyPathFlag::DelegateSubtype1 | QQSK::PropertyPathFlag::DelegateSubtype2);
615 ids.subTypeProperty = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
616 ids.subTypeAlternative = group->propertyPathId(alternative, PropertyPathId::Flag::IncludeSubtype);
622 if (!pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
624
625
626
627
629 const QVariant value = readPropertyInStorageForState(
630 ids.subTypeProperty, ids.subTypeAlternative, styleReader, QQSK::StateFlag::Normal);
634 const QVariant value = readPropertyInStorageForState(
635 ids.property, ids.alternative, styleReader, QQSK::StateFlag::Normal);
640 return readPropertyInStyle(style, ids, styleReader);
645 const QQSK::Property property,
646 const QVariant &value)
652 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
653 const QQSK::Subclass subclass = controlProperties->subclass();
654 const PropertyPathId propertyPathId = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
656 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
657 qmlWarning(controlProperties) <<
"Properties inside 'global' are read-only!";
661 if (subclass == QQSK::Subclass::QQStyleKitReader) {
663 QQStyleKitReader *reader = controlProperties->asQQStyleKitReader();
664 const PropertyStorageId key = propertyPathId.storageId(QQSK::StateFlag::Normal);
665 const QVariant currentValue = reader->readStyleProperty(key);
666 const bool valueChanged = currentValue != value;
668 reader->writeStyleProperty(key, value);
669 QQStyleKitDebug::notifyPropertyWrite(group, property, reader, QQSK::StateFlag::Normal, key, value);
674 if (subclass == QQSK::Subclass::QQStyleKitState) {
678 const QQSK::State nestedState = controlState->nestedState();
679 const PropertyStorageId key = propertyPathId.storageId(nestedState);
680 const QVariant currentValue = control->readStyleProperty(key);
681 const bool valueChanged = currentValue != value;
684
685
686 control->m_writtenStates |= nestedState;
688
689
690
692 const QQSK::State alreadyWrittenStates = controls->m_writtenPropertyPaths[propertyPathId.pathId()];
693 controls->m_writtenPropertyPaths[propertyPathId.pathId()] = alreadyWrittenStates | nestedState;
695 control->writeStyleProperty(key, value);
696 QQStyleKitDebug::notifyPropertyWrite(group, property, control, nestedState, key, value);
707 const QQSK::Property property)
711 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
712 const PropertyPathId propertyPathId = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
713 const QQSK::Subclass subclass = controlProperties->subclass();
715 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global))
718 if (subclass == QQSK::Subclass::QQStyleKitReader) {
719 const PropertyStorageId key = propertyPathId.storageId(QQSK::StateFlag::Normal);
720 return controlProperties->asQQStyleKitReader()->readStyleProperty(key).isValid();
723 if (subclass == QQSK::Subclass::QQStyleKitState) {
726 const PropertyStorageId key = propertyPathId.storageId(controlState->nestedState());
727 return control->readStyleProperty(key).isValid();
736#include "moc_qqstylekitpropertyresolver_p.cpp"
QQStyleKitControl * control() const
QQStyleKitControlProperties * controlProperties() const
Combined button and popup list for selecting options.