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::DialogButtonBox:
78 case QQStyleKitReader::Frame:
79 case QQStyleKitReader::TabBar:
80 case QQStyleKitReader::ToolBar: {
81 static QList<QQStyleKitExtendableControlType> t =
82 { QQStyleKitReader::Pane, QQStyleKitReader::Control };
84 case QQStyleKitReader::GroupBox: {
85 static QList<QQStyleKitExtendableControlType> t =
86 { QQStyleKitReader::Frame, QQStyleKitReader::Pane, QQStyleKitReader::Control };
89 case QQStyleKitReader::TextField:
90 case QQStyleKitReader::TextArea: {
91 static QList<QQStyleKitExtendableControlType> t =
92 { QQStyleKitReader::TextInput, QQStyleKitReader::Control };
95 static QList<QQStyleKitExtendableControlType> t =
96 { QQStyleKitReader::Control };
106 Q_ASSERT(state != QQSK::StateFlag::Unspecified);
107 if (state == s_cachedState)
110 s_cachedState = state;
113
114
115
116
117 s_cachedStateList.clear();
118 if (state.testFlag(QQSK::StateFlag::Pressed))
119 s_cachedStateList.append(QQSK::StateFlag::Pressed);
120 if (state.testFlag(QQSK::StateFlag::Hovered))
121 s_cachedStateList.append(QQSK::StateFlag::Hovered);
122 if (state.testFlag(QQSK::StateFlag::Highlighted))
123 s_cachedStateList.append(QQSK::StateFlag::Highlighted);
124 if (state.testFlag(QQSK::StateFlag::Focused))
125 s_cachedStateList.append(QQSK::StateFlag::Focused);
126 if (state.testFlag(QQSK::StateFlag::Checked))
127 s_cachedStateList.append(QQSK::StateFlag::Checked);
128 if (state.testFlag(QQSK::StateFlag::Vertical))
129 s_cachedStateList.append(QQSK::StateFlag::Vertical);
130 if (state.testFlag(QQSK::StateFlag::Disabled))
131 s_cachedStateList.append(QQSK::StateFlag::Disabled);
135 QQStyleKitReader *styleReader,
140
141
142
143 if (!styleReader->m_effectiveVariations.contains(variation))
144 styleReader->m_effectiveVariations.append(variation);
147
148
149
150 if (!variation->m_usageContext.contains(styleOrTheme))
151 variation->m_usageContext.append(styleOrTheme);
155 QQStyleKitReader *styleReader,
157 const AttachedVariationList &attachedVariations)
159 const QQStyleKitExtendableControlType styleReaderType = styleReader->controlType();
160 const auto styleReaderBaseType = baseTypesForType(styleReaderType);
162 static PropertyPathIds ids;
163 if (ids.property.property() == QQSK::Property::NoProperty) {
165
166
167 ids.property = styleReader->propertyPathId(QQSK::Property::Variations, PropertyPathId::Flag::ExcludeSubtype);
168 ids.alternative = styleReader->propertyPathId(QQSK::Property::NoProperty, PropertyPathId::Flag::ExcludeSubtype);
173 for (
const QQStyleKitVariationAttached *attached : attachedVariations) {
174 const auto parentType = attached->controlType();
175 const auto parentBaseTypes = baseTypesForType(parentType);
178
179
180
181 const QVariant typeVariationsVariant = readPropertyInRelevantControls(styleOrTheme, ids, parentType, parentBaseTypes);
182 if (!typeVariationsVariant.isValid())
185 const auto typeVariations = *qvariant_cast<QList<QQStyleKitVariation *> *>(typeVariationsVariant);
187 for (QQStyleKitVariation *variation : typeVariations) {
189
190
193
197 if (variation->getControl(styleReaderType)) {
198 addVariationToReader(styleReader, styleOrTheme, variation);
200 for (
int type : styleReaderBaseType) {
201 if (variation->getControl(type))
202 addVariationToReader(styleReader, styleOrTheme, variation);
210 QQStyleKitReader *styleReader,
212 const AttachedVariationList &attachedVariations)
215
216
217
218
219 const QQStyleKitExtendableControlType styleReaderType = styleReader->controlType();
220 const auto styleReaderBaseTypes = baseTypesForType(styleReaderType);
222 for (
const QQStyleKitVariationAttached *attached : attachedVariations) {
223 for (
const QString &instanceVariationName : attached->variations()) {
224 for (QQStyleKitVariation *variation : styleOrTheme->m_styleVariations) {
225 if (variation->name() != instanceVariationName)
229
230
231
232 if (variation->getControl(styleReaderType)) {
233 addVariationToReader(styleReader, styleOrTheme, variation);
235 for (
int baseType : styleReaderBaseTypes) {
236 if (variation->getControl(baseType))
237 addVariationToReader(styleReader, styleOrTheme, variation);
246 QQStyleKitReader *styleReader, QQStyleKitStyle *style)
249
250
251
252
253
254
255 Q_ASSERT(styleReader->m_effectiveVariationsDirty);
256 styleReader->m_effectiveVariationsDirty =
false;
257 styleReader->m_effectiveVariations.clear();
259 if (!style->m_hasVariations)
263
264
265 AttachedVariationList attachedVariations;
266 for (QObject *current = styleReader; current; current = current->parent()) {
267 if (
const QObject *attachedObject = qmlAttachedPropertiesObject<QQStyleKitVariation>(current,
false)) {
269 attachedVariations.append(attached);
273 if (attachedVariations.isEmpty())
276 for (QQStyleKitStyle *current = style; current; current = current->fallbackStyle()) {
278 addInstanceVariationsToReader(styleReader, theme, attachedVariations);
279 addTypeVariationsToReader(styleReader, theme, attachedVariations);
281 addInstanceVariationsToReader(styleReader, current, attachedVariations);
282 addTypeVariationsToReader(styleReader, current, attachedVariations);
289 const T *storageProvider, QQSK::State state)
292
293
294
295
296
297
298
299
300
301 Q_ASSERT(qlonglong(state) <= qlonglong(QQSK::StateFlag::MAX_STATE));
303 const PropertyStorageId propertyKey = main.storageId(state);
306 QQStyleKitDebug::trace(main, storageProvider, state, propertyKey);
308 const QVariant propertyValue = storageProvider->readStyleProperty(propertyKey);
309 if (propertyValue.isValid()) {
311 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, propertyValue);
312 return propertyValue;
315 const PropertyStorageId altPropertyKey = alternative.storageId(state);
318 QQStyleKitDebug::trace(alternative, storageProvider, state, altPropertyKey);
320 const QVariant altValue = storageProvider->readStyleProperty(altPropertyKey);
321 if (altValue.isValid()) {
323 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, altValue);
330template <
class INDICES_CONTAINER>
334 int startIndex,
int recursionLevel)
336 for (
int i = startIndex; i < s_cachedStateList.length(); ++i) {
338
339
340
341
342
343
344
345 stateListIndices[recursionLevel] = i;
346 const QQSK::StateFlag stateFlag = s_cachedStateList[i];
349
350 if (!control->m_writtenStates.testFlag(stateFlag))
354
356 const QQSK::State statesAffectingProperty = controls->m_writtenPropertyPaths[main.pathId()];
357 if (!statesAffectingProperty.testFlag(stateFlag)) {
358 if (alternative.property() == QQSK::Property::NoProperty) {
361 const QQSK::State statesAffectingAlternative = controls->m_writtenPropertyPaths[alternative.pathId()];
362 if (!statesAffectingAlternative.testFlag(stateFlag))
367 if (recursionLevel < s_cachedStateList.length() - 1) {
369 const QVariant value = readPropertyInControlForStates(
370 main, alternative, control, stateListIndices, i + 1, recursionLevel + 1);
376 QQSK::State storageState = QQSK::StateFlag::Unspecified;
377 for (
int j = 0; j <= recursionLevel; ++j)
378 storageState.setFlag(s_cachedStateList[stateListIndices[j]]);
379 const QVariant value = readPropertyInStorageForState(main, alternative, control, storageState);
391
392
393
394
395 QVarLengthArray<
int, 10> stateListIndices(s_cachedStateList.length());
397 if (ids.subTypeProperty.property() != QQSK::Property::NoProperty) {
398 if (s_cachedState != QQSK::StateFlag::Normal) {
399 QVariant value = readPropertyInControlForStates(
400 ids.subTypeProperty, ids.subTypeAlternative, control, stateListIndices, 0, 0);
405 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal)) {
406 const QVariant value = readPropertyInStorageForState(
407 ids.subTypeProperty, ids.subTypeAlternative, control, QQSK::StateFlag::Normal);
413 if (s_cachedState != QQSK::StateFlag::Normal) {
414 const QVariant value = readPropertyInControlForStates(
415 ids.property, ids.alternative, control, stateListIndices, 0, 0);
421
422
423
424 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal))
425 return readPropertyInStorageForState(ids.property, ids.alternative, control, QQSK::StateFlag::Normal);
432 const QQStyleKitExtendableControlType exactType,
433 const QList<QQStyleKitExtendableControlType> baseTypes)
439
441 const auto writtenProperties = controls->m_writtenPropertyPaths;
442 if (writtenProperties.contains(ids.property.pathId()))
444 const bool hasAlternative = ids.alternative.property() != QQSK::Property::NoProperty;
445 if (hasAlternative && writtenProperties.contains(ids.alternative.pathId()))
447 if (ids.subTypeProperty.property() == QQSK::Property::NoProperty)
449 if (writtenProperties.contains(ids.subTypeProperty.pathId()))
451 if (hasAlternative && writtenProperties.contains(ids.subTypeAlternative.pathId()))
457 const QVariant value = readPropertyInControl(ids, control);
462 for (
const int type : baseTypes) {
463 if (
const QQStyleKitControl *control = controls->getControl(type)) {
464 const QVariant value = readPropertyInControl(ids, control);
474 const QList<QPointer<QQStyleKitVariation>> &variations,
476 const PropertyPathIds &ids,
477 const QQStyleKitExtendableControlType exactType,
478 const QList<QQStyleKitExtendableControlType> baseTypes)
480 bool foundAtLeastOneVariation =
false;
481 for (
const QPointer<QQStyleKitVariation> &variation : variations) {
484 if (!variation->m_usageContext.contains(styleOrTheme)) {
485 if (foundAtLeastOneVariation) {
487
488
489
493
496 foundAtLeastOneVariation =
true;
497 const QVariant value = readPropertyInRelevantControls(variation, ids, exactType, baseTypes);
505 QQStyleKitStyle *style,
const PropertyPathIds &ids, QQStyleKitReader *styleReader)
508
509
510 style->syncFromQPalette(styleReader->effectivePalette());
513
514
515 cacheReaderState(styleReader->controlState());
517 if (styleReader->m_effectiveVariationsDirty)
518 rebuildVariationsForReader(styleReader, style);
520 const QQStyleKitExtendableControlType exactType = styleReader->controlType();
521 const QList<QQStyleKitExtendableControlType> baseTypes = baseTypesForType(exactType);
526 value = readPropertyInVariations(styleReader->m_effectiveVariations, style->theme(), ids, exactType, baseTypes);
530 value = readPropertyInRelevantControls(style->theme(), ids, exactType, baseTypes);
534 value = readPropertyInVariations(styleReader->m_effectiveVariations, style, ids, exactType, baseTypes);
538 value = readPropertyInRelevantControls(style, ids, exactType, baseTypes);
542 if (
auto *fallbackStyle = style->fallbackStyle()) {
544
545 value = readPropertyInStyle(fallbackStyle, ids, styleReader);
554 if (!value.isValid())
563 const QQSK::Property property,
564 const QQSK::Property alternative)
567 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
568 const QQSK::Subclass subclass = controlProperties->subclass();
570 if (subclass != QQSK::Subclass::QQStyleKitReader) {
572
573
574
575
576
577
578
579 Q_ASSERT(subclass == QQSK::Subclass::QQStyleKitState);
582 const PropertyPathId propertyPathId = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
583 const PropertyStorageId key = propertyPathId.storageId(controlState->nestedState());
584 return control->readStyleProperty(key);
587 QQStyleKitStyle *style = controlProperties->style();
588 if (!style || !style->loaded()) {
590
591
592
597 QQStyleKitReader *styleReader = controlProperties->asQQStyleKitReader();
599 if (s_isReadingProperty) {
600 if (!s_styleWarningsIssued) {
601 s_styleWarningsIssued =
true;
602 qmlWarning(styleReader) <<
"The style property '" << property <<
"' was read "
603 <<
"before finishing the read of another style property. "
604 <<
"This is likely to cause a style glitch.";
607 QScopedValueRollback rollback(s_isReadingProperty,
true);
610 ids.property = group->propertyPathId(property, PropertyPathId::Flag::ExcludeSubtype);
611 ids.alternative = group->propertyPathId(alternative, PropertyPathId::Flag::ExcludeSubtype);
612 const bool insideSubType = pathFlags &
613 (QQSK::PropertyPathFlag::DelegateSubtype1 | QQSK::PropertyPathFlag::DelegateSubtype2);
616 ids.subTypeProperty = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
617 ids.subTypeAlternative = group->propertyPathId(alternative, PropertyPathId::Flag::IncludeSubtype);
623 if (!pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
625
626
627
628
630 const QVariant value = readPropertyInStorageForState(
631 ids.subTypeProperty, ids.subTypeAlternative, styleReader, QQSK::StateFlag::Normal);
635 const QVariant value = readPropertyInStorageForState(
636 ids.property, ids.alternative, styleReader, QQSK::StateFlag::Normal);
641 return readPropertyInStyle(style, ids, styleReader);
646 const QQSK::Property property,
647 const QVariant &value)
653 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
654 const QQSK::Subclass subclass = controlProperties->subclass();
655 const PropertyPathId propertyPathId = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
657 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
658 qmlWarning(controlProperties) <<
"Properties inside 'global' are read-only!";
662 if (subclass == QQSK::Subclass::QQStyleKitReader) {
664 QQStyleKitReader *reader = controlProperties->asQQStyleKitReader();
665 const PropertyStorageId key = propertyPathId.storageId(QQSK::StateFlag::Normal);
666 const QVariant currentValue = reader->readStyleProperty(key);
667 const bool valueChanged = currentValue != value;
669 reader->writeStyleProperty(key, value);
670 QQStyleKitDebug::notifyPropertyWrite(group, property, reader, QQSK::StateFlag::Normal, key, value);
675 if (subclass == QQSK::Subclass::QQStyleKitState) {
679 const QQSK::State nestedState = controlState->nestedState();
680 const PropertyStorageId key = propertyPathId.storageId(nestedState);
681 const QVariant currentValue = control->readStyleProperty(key);
682 const bool valueChanged = currentValue != value;
685
686
687 control->m_writtenStates |= nestedState;
689
690
691
693 const QQSK::State alreadyWrittenStates = controls->m_writtenPropertyPaths[propertyPathId.pathId()];
694 controls->m_writtenPropertyPaths[propertyPathId.pathId()] = alreadyWrittenStates | nestedState;
696 control->writeStyleProperty(key, value);
697 QQStyleKitDebug::notifyPropertyWrite(group, property, control, nestedState, key, value);
708 const QQSK::Property property)
712 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
713 const PropertyPathId propertyPathId = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
714 const QQSK::Subclass subclass = controlProperties->subclass();
716 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global))
719 if (subclass == QQSK::Subclass::QQStyleKitReader) {
720 const PropertyStorageId key = propertyPathId.storageId(QQSK::StateFlag::Normal);
721 return controlProperties->asQQStyleKitReader()->readStyleProperty(key).isValid();
724 if (subclass == QQSK::Subclass::QQStyleKitState) {
727 const PropertyStorageId key = propertyPathId.storageId(controlState->nestedState());
728 return control->readStyleProperty(key).isValid();
737#include "moc_qqstylekitpropertyresolver_p.cpp"
QQStyleKitControl * control() const
QQStyleKitControlProperties * controlProperties() const
Combined button and popup list for selecting options.