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
40 case QQStyleKitReader::ApplicationWindow: {
41 static QList<QQStyleKitExtendableControlType> t =
42 { QQStyleKitReader::ApplicationWindow };
44 case QQStyleKitReader::Button:
45 case QQStyleKitReader::ToolButton:
46 case QQStyleKitReader::TabButton:
47 case QQStyleKitReader::RadioButton:
48 case QQStyleKitReader::CheckBox:
49 case QQStyleKitReader::SwitchControl: {
50 static QList<QQStyleKitExtendableControlType> t =
51 { QQStyleKitReader::AbstractButton, QQStyleKitReader::Control };
53 case QQStyleKitReader::Menu:
54 case QQStyleKitReader::Dialog: {
55 static QList<QQStyleKitExtendableControlType> t =
56 { QQStyleKitReader::Popup, QQStyleKitReader::Control };
58 case QQStyleKitReader::Page:
59 case QQStyleKitReader::Frame:
60 case QQStyleKitReader::TabBar:
61 case QQStyleKitReader::ToolBar: {
62 static QList<QQStyleKitExtendableControlType> t =
63 { QQStyleKitReader::Pane, QQStyleKitReader::Control };
65 case QQStyleKitReader::GroupBox: {
66 static QList<QQStyleKitExtendableControlType> t =
67 { QQStyleKitReader::Frame, QQStyleKitReader::Pane, QQStyleKitReader::Control };
70 case QQStyleKitReader::TextField:
71 case QQStyleKitReader::TextArea: {
72 static QList<QQStyleKitExtendableControlType> t =
73 { QQStyleKitReader::TextInput, QQStyleKitReader::Control };
76 static QList<QQStyleKitExtendableControlType> t =
77 { QQStyleKitReader::Control };
87 Q_ASSERT(state != QQSK::StateFlag::Unspecified);
88 if (state == s_cachedState)
91 s_cachedState = state;
94
95
96
97
98 s_cachedStateList.clear();
99 if (state.testFlag(QQSK::StateFlag::Pressed))
100 s_cachedStateList.append(QQSK::StateFlag::Pressed);
101 if (state.testFlag(QQSK::StateFlag::Hovered))
102 s_cachedStateList.append(QQSK::StateFlag::Hovered);
103 if (state.testFlag(QQSK::StateFlag::Highlighted))
104 s_cachedStateList.append(QQSK::StateFlag::Highlighted);
105 if (state.testFlag(QQSK::StateFlag::Focused))
106 s_cachedStateList.append(QQSK::StateFlag::Focused);
107 if (state.testFlag(QQSK::StateFlag::Checked))
108 s_cachedStateList.append(QQSK::StateFlag::Checked);
109 if (state.testFlag(QQSK::StateFlag::Vertical))
110 s_cachedStateList.append(QQSK::StateFlag::Vertical);
111 if (state.testFlag(QQSK::StateFlag::Disabled))
112 s_cachedStateList.append(QQSK::StateFlag::Disabled);
117 const QQStyleKitExtendableControlType parentType,
120 static PropertyPathIds ids;
121 if (ids.property.property() == QQSK::Property::NoProperty) {
123
124
125 ids.property = styleReader->propertyPathId(QQSK::Property::Variations, PropertyPathId::Flag::ExcludeSubtype);
126 ids.alternative = styleReader->propertyPathId(QQSK::Property::NoProperty, PropertyPathId::Flag::ExcludeSubtype);
131 const auto parentBaseTypes = baseTypesForType(parentType);
132 const QVariant inStyleVariationsVar = readPropertyInStyle(ids, parentType, parentBaseTypes, style);
133 if (!inStyleVariationsVar.isValid())
137
138
139 const QQStyleKitExtendableControlType styleReaderType = styleReader->type();
140 const auto styleReaderBaseType = baseTypesForType(styleReaderType);
142 const auto inStyleVariations = *qvariant_cast<QList<QQStyleKitVariation *> *>(inStyleVariationsVar);
143 for (
auto *variation : inStyleVariations) {
149
150
151
152
153
154
155
156
157
158 if (variation->getControl(styleReaderType)) {
159 styleReader->m_effectiveInStyleVariations.append(variation);
161 for (
int type : styleReaderBaseType) {
162 if (variation->getControl(type)) {
163 styleReader->m_effectiveInStyleVariations.append(variation);
173 const QVarLengthArray<
const QQStyleKitControls *, 6> &stylesAndThemes)
176
177
178
179
180 const QQStyleKitExtendableControlType styleReaderType = styleReader->type();
181 const auto styleReaderBaseTypes = baseTypesForType(styleReaderType);
183 for (
const QString &attachedVariationName : inAppVariationNames) {
184 for (
const QQStyleKitControls *styleOrTheme : stylesAndThemes) {
185 const QList<QQStyleKitVariation *> variationsInStyleOrTheme = styleOrTheme->variations();
186 for (QQStyleKitVariation *variationInStyleOrTheme : variationsInStyleOrTheme) {
187 if (variationInStyleOrTheme->name() != attachedVariationName)
190
191
192
193 if (variationInStyleOrTheme->getControl(styleReaderType)) {
194 styleReader->m_effectiveInAppVariations.append(variationInStyleOrTheme);
196 for (
int baseType : styleReaderBaseTypes) {
197 if (variationInStyleOrTheme->getControl(baseType)) {
198 styleReader->m_effectiveInAppVariations.append(variationInStyleOrTheme);
212
213
214
215
216
217
218 Q_ASSERT(styleReader->m_effectiveVariationsDirty);
219 styleReader->m_effectiveVariationsDirty =
false;
220 styleReader->m_effectiveInAppVariations.clear();
221 styleReader->m_effectiveInStyleVariations.clear();
225 if (!styleHasVariations) {
227
228
233
234
235 QVarLengthArray<
const QQStyleKitControls *, 6> stylesAndThemes;
237 while (styleOrFallbackStyle) {
238 if (
const auto *theme = styleOrFallbackStyle
->theme())
239 stylesAndThemes.append(theme);
240 stylesAndThemes.append(styleOrFallbackStyle);
244 QObject *parentObj = styleReader;
246 QObject *attachedObject = qmlAttachedPropertiesObject<
QQStyleKitControl>(parentObj,
false);
247 if (attachedObject) {
249 if (hasInstanceVariations)
250 addInstanceVariationsToReader(styleReader, controlAtt->variations(), stylesAndThemes);
251 if (styleHasVariations)
252 addTypeVariationsToReader(styleReader, controlAtt->controlType(), style);
255 parentObj = parentObj->parent();
262 const T *storageProvider, QQSK::State state)
265
266
267
268
269
270
271
272
273
274 Q_ASSERT(qlonglong(state) <= qlonglong(QQSK::StateFlag::MAX_STATE));
276 const PropertyStorageId propertyKey = main.storageId(state);
279 QQStyleKitDebug::trace(main, storageProvider, state, propertyKey);
281 const QVariant propertyValue = storageProvider->readStyleProperty(propertyKey);
282 if (propertyValue.isValid()) {
284 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, propertyValue);
285 return propertyValue;
288 const PropertyStorageId altPropertyKey = alternative.storageId(state);
291 QQStyleKitDebug::trace(alternative, storageProvider, state, altPropertyKey);
293 const QVariant altValue = storageProvider->readStyleProperty(altPropertyKey);
294 if (altValue.isValid()) {
296 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, altValue);
303template <
class INDICES_CONTAINER>
307 int startIndex,
int recursionLevel)
309 for (
int i = startIndex; i < s_cachedStateList.length(); ++i) {
311
312
313
314
315
316
317
318 stateListIndices[recursionLevel] = i;
319 const QQSK::StateFlag stateFlag = s_cachedStateList[i];
322
323 if (!control->m_writtenStates.testFlag(stateFlag))
327
329 const QQSK::State statesAffectingProperty = controls->m_writtenPropertyPaths[main.pathId()];
330 if (!statesAffectingProperty.testFlag(stateFlag)) {
331 if (alternative.property() == QQSK::Property::NoProperty) {
334 const QQSK::State statesAffectingAlternative = controls->m_writtenPropertyPaths[alternative.pathId()];
335 if (!statesAffectingAlternative.testFlag(stateFlag))
340 if (recursionLevel < s_cachedStateList.length() - 1) {
342 const QVariant value = readPropertyInControlForStates(
343 main, alternative, control, stateListIndices, i + 1, recursionLevel + 1);
349 QQSK::State storageState = QQSK::StateFlag::Unspecified;
350 for (
int j = 0; j <= recursionLevel; ++j)
351 storageState.setFlag(s_cachedStateList[stateListIndices[j]]);
352 const QVariant value = readPropertyInStorageForState(main, alternative, control, storageState);
364
365
366
367
368 QVarLengthArray<
int, 10> stateListIndices(s_cachedStateList.length());
370 if (ids.subTypeProperty.property() != QQSK::Property::NoProperty) {
371 if (s_cachedState != QQSK::StateFlag::Normal) {
372 QVariant value = readPropertyInControlForStates(
373 ids.subTypeProperty, ids.subTypeAlternative, control, stateListIndices, 0, 0);
378 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal)) {
379 const QVariant value = readPropertyInStorageForState(
380 ids.subTypeProperty, ids.subTypeAlternative, control, QQSK::StateFlag::Normal);
386 if (s_cachedState != QQSK::StateFlag::Normal) {
387 const QVariant value = readPropertyInControlForStates(
388 ids.property, ids.alternative, control, stateListIndices, 0, 0);
394
395
396
397 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal))
398 return readPropertyInStorageForState(ids.property, ids.alternative, control, QQSK::StateFlag::Normal);
405 const QQStyleKitExtendableControlType exactType,
406 const QList<QQStyleKitExtendableControlType> baseTypes)
412
414 const auto writtenProperties = controls->m_writtenPropertyPaths;
415 if (writtenProperties.contains(ids.property.pathId()))
417 const bool hasAlternative = ids.alternative.property() != QQSK::Property::NoProperty;
418 if (hasAlternative && writtenProperties.contains(ids.alternative.pathId()))
420 if (ids.subTypeProperty.property() == QQSK::Property::NoProperty)
422 if (writtenProperties.contains(ids.subTypeProperty.pathId()))
424 if (hasAlternative && writtenProperties.contains(ids.subTypeAlternative.pathId()))
430 const QVariant value = readPropertyInControl(ids, control);
435 for (
const int type : baseTypes) {
436 if (
const QQStyleKitControl *control = controls->getControl(type)) {
437 const QVariant value = readPropertyInControl(ids, control);
447 const PropertyPathIds &ids,
448 const QQStyleKitExtendableControlType exactType,
449 const QList<QQStyleKitExtendableControlType> baseTypes,
455 value = readPropertyInRelevantControls(style->theme(), ids, exactType, baseTypes);
458 value = readPropertyInRelevantControls(style, ids, exactType, baseTypes);
464
465 fallbackStyle->syncFromQPalette(style->effectivePalette());
466 value = readPropertyInStyle(ids, exactType, baseTypes, fallbackStyle);
475 if (!value.isValid())
486
487
488 style->syncFromQPalette(styleReader->effectivePalette());
491
492
493 cacheReaderState(styleReader->controlState());
495 if (styleReader->m_effectiveVariationsDirty)
496 rebuildVariationsForReader(styleReader, style);
498 const QQStyleKitExtendableControlType exactType = styleReader->type();
499 const QList<QQStyleKitExtendableControlType> baseTypes = baseTypesForType(exactType);
504 for (
const QPointer<QQStyleKitVariation> &variation : std::as_const(styleReader->m_effectiveInAppVariations)) {
507 value = readPropertyInRelevantControls(variation, ids, exactType, baseTypes);
514 for (
const QPointer<QQStyleKitVariation> &variation : std::as_const(styleReader->m_effectiveInStyleVariations)) {
517 value = readPropertyInRelevantControls(variation, ids, exactType, baseTypes);
524 value = readPropertyInStyle(ids, exactType, baseTypes, style);
529 if (!value.isValid())
538 const QQSK::Property property,
539 const QQSK::Property alternative)
542 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
543 const QQSK::Subclass subclass = controlProperties->subclass();
545 if (subclass == QQSK::Subclass::QQStyleKitState) {
547
548
549
550
551
552
553
554
555
558 const PropertyPathId propertyPathId = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
559 const PropertyStorageId key = propertyPathId.storageId(controlState->nestedState());
560 return control->readStyleProperty(key);
565 if (!s_styleWarningsIssued) {
566 s_styleWarningsIssued =
true;
567 qmlWarning(group) <<
"style properties cannot be read: No StyleKit style has been set!";
577 if (subclass == QQSK::Subclass::QQStyleKitReader) {
581 if (s_isReadingProperty) {
582 if (!s_styleWarningsIssued) {
583 s_styleWarningsIssued =
true;
584 qmlWarning(styleReader) <<
"The style property '" << property <<
"' was read "
585 <<
"before finishing the read of another style property. "
586 <<
"This is likely to cause a style glitch.";
589 QScopedValueRollback rollback(s_isReadingProperty,
true);
592 ids.property = group->propertyPathId(property, PropertyPathId::Flag::ExcludeSubtype);
593 ids.alternative = group->propertyPathId(alternative, PropertyPathId::Flag::ExcludeSubtype);
594 const bool insideSubType = pathFlags &
595 (QQSK::PropertyPathFlag::DelegateSubtype1 | QQSK::PropertyPathFlag::DelegateSubtype2);
598 ids.subTypeProperty = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
599 ids.subTypeAlternative = group->propertyPathId(alternative, PropertyPathId::Flag::IncludeSubtype);
605 if (!pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
607
608
609
610
612 const QVariant value = readPropertyInStorageForState(
613 ids.subTypeProperty, ids.subTypeAlternative, styleReader, QQSK::StateFlag::Normal);
617 const QVariant value = readPropertyInStorageForState(
618 ids.property, ids.alternative, styleReader, QQSK::StateFlag::Normal);
623 return readProperty(ids, styleReader, style);
632 const QQSK::Property property,
633 const QVariant &value)
639 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
640 const QQSK::Subclass subclass = controlProperties->subclass();
641 const PropertyPathId propertyPathId = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
643 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
644 qmlWarning(controlProperties) <<
"Properties inside 'global' are read-only!";
648 if (subclass == QQSK::Subclass::QQStyleKitReader) {
651 const PropertyStorageId key = propertyPathId.storageId(QQSK::StateFlag::Normal);
652 const QVariant currentValue = reader->readStyleProperty(key);
653 const bool valueChanged = currentValue != value;
655 reader->writeStyleProperty(key, value);
656 QQStyleKitDebug::notifyPropertyWrite(group, property, reader, QQSK::StateFlag::Normal, key, value);
661 if (subclass == QQSK::Subclass::QQStyleKitState) {
665 const QQSK::State nestedState = controlState->nestedState();
666 const PropertyStorageId key = propertyPathId.storageId(nestedState);
667 const QVariant currentValue = control->readStyleProperty(key);
668 const bool valueChanged = currentValue != value;
671
672
673 control->m_writtenStates |= nestedState;
675
676
677
679 const QQSK::State alreadyWrittenStates = controls->m_writtenPropertyPaths[propertyPathId.pathId()];
680 controls->m_writtenPropertyPaths[propertyPathId.pathId()] = alreadyWrittenStates | nestedState;
682 control->writeStyleProperty(key, value);
683 QQStyleKitDebug::notifyPropertyWrite(group, property, control, nestedState, key, value);
694 const QQSK::Property property)
698 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
699 const PropertyPathId propertyPathId = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
700 const QQSK::Subclass subclass = controlProperties->subclass();
702 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global))
705 if (subclass == QQSK::Subclass::QQStyleKitReader) {
706 const PropertyStorageId key = propertyPathId.storageId(QQSK::StateFlag::Normal);
710 if (subclass == QQSK::Subclass::QQStyleKitState) {
713 const PropertyStorageId key = propertyPathId.storageId(controlState->nestedState());
714 return control->readStyleProperty(key).isValid();
723#include "moc_qqstylekitpropertyresolver_p.cpp"
QQStyleKitStyle * style() const
QQStyleKitReader * asQQStyleKitReader() const
QQStyleKitControlState * asQQStyleKitState() const
QQStyleKitControl * control() const
QQStyleKitControlProperties * controlProperties() const
QQStyleKitStyle * fallbackStyle() const
QQStyleKitTheme * theme() const
Combined button and popup list for selecting options.