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::FlatButton:
46 case QQStyleKitReader::ToolButton:
47 case QQStyleKitReader::TabButton:
48 case QQStyleKitReader::RadioButton:
49 case QQStyleKitReader::CheckBox:
50 case QQStyleKitReader::SwitchControl: {
51 static QList<QQStyleKitExtendableControlType> t =
52 { QQStyleKitReader::AbstractButton, QQStyleKitReader::Control };
54 case QQStyleKitReader::Menu:
55 case QQStyleKitReader::Dialog: {
56 static QList<QQStyleKitExtendableControlType> t =
57 { QQStyleKitReader::Popup, QQStyleKitReader::Control };
59 case QQStyleKitReader::Page:
60 case QQStyleKitReader::Frame:
61 case QQStyleKitReader::TabBar:
62 case QQStyleKitReader::ToolBar: {
63 static QList<QQStyleKitExtendableControlType> t =
64 { QQStyleKitReader::Pane, QQStyleKitReader::Control };
66 case QQStyleKitReader::GroupBox: {
67 static QList<QQStyleKitExtendableControlType> t =
68 { QQStyleKitReader::Frame, QQStyleKitReader::Pane, QQStyleKitReader::Control };
71 case QQStyleKitReader::TextField:
72 case QQStyleKitReader::TextArea: {
73 static QList<QQStyleKitExtendableControlType> t =
74 { QQStyleKitReader::TextInput, QQStyleKitReader::Control };
77 static QList<QQStyleKitExtendableControlType> t =
78 { QQStyleKitReader::Control };
88 Q_ASSERT(state != QQSK::StateFlag::Unspecified);
89 if (state == s_cachedState)
92 s_cachedState = state;
95
96
97
98
99 s_cachedStateList.clear();
100 if (state.testFlag(QQSK::StateFlag::Pressed))
101 s_cachedStateList.append(QQSK::StateFlag::Pressed);
102 if (state.testFlag(QQSK::StateFlag::Hovered))
103 s_cachedStateList.append(QQSK::StateFlag::Hovered);
104 if (state.testFlag(QQSK::StateFlag::Highlighted))
105 s_cachedStateList.append(QQSK::StateFlag::Highlighted);
106 if (state.testFlag(QQSK::StateFlag::Focused))
107 s_cachedStateList.append(QQSK::StateFlag::Focused);
108 if (state.testFlag(QQSK::StateFlag::Checked))
109 s_cachedStateList.append(QQSK::StateFlag::Checked);
110 if (state.testFlag(QQSK::StateFlag::Vertical))
111 s_cachedStateList.append(QQSK::StateFlag::Vertical);
112 if (state.testFlag(QQSK::StateFlag::Disabled))
113 s_cachedStateList.append(QQSK::StateFlag::Disabled);
118 const QQStyleKitExtendableControlType parentType,
121 static PropertyPathIds ids;
122 if (ids.property.property() == QQSK::Property::NoProperty) {
124
125
126 ids.property = styleReader->propertyPathId(QQSK::Property::Variations, PropertyPathId::Flag::ExcludeSubtype);
127 ids.alternative = styleReader->propertyPathId(QQSK::Property::NoProperty, PropertyPathId::Flag::ExcludeSubtype);
132 const auto parentBaseTypes = baseTypesForType(parentType);
133 const QVariant inStyleVariationsVar = readPropertyInStyle(ids, parentType, parentBaseTypes, style);
134 if (!inStyleVariationsVar.isValid())
138
139
140 const QQStyleKitExtendableControlType styleReaderType = styleReader->controlType();
141 const auto styleReaderBaseType = baseTypesForType(styleReaderType);
143 const auto inStyleVariations = *qvariant_cast<QList<QQStyleKitVariation *> *>(inStyleVariationsVar);
144 for (
auto *variation : inStyleVariations) {
150
151
152
153
154
155
156
157
158
159 if (variation->getControl(styleReaderType)) {
160 styleReader->m_effectiveInStyleVariations.append(variation);
162 for (
int type : styleReaderBaseType) {
163 if (variation->getControl(type)) {
164 styleReader->m_effectiveInStyleVariations.append(variation);
174 const QVarLengthArray<
const QQStyleKitControls *, 6> &stylesAndThemes)
177
178
179
180
181 const QQStyleKitExtendableControlType styleReaderType = styleReader->controlType();
182 const auto styleReaderBaseTypes = baseTypesForType(styleReaderType);
184 for (
const QString &attachedVariationName : inAppVariationNames) {
185 for (
const QQStyleKitControls *styleOrTheme : stylesAndThemes) {
186 const QList<QQStyleKitVariation *> variationsInStyleOrTheme = styleOrTheme->variations();
187 for (QQStyleKitVariation *variationInStyleOrTheme : variationsInStyleOrTheme) {
188 if (variationInStyleOrTheme->name() != attachedVariationName)
191
192
193
194 if (variationInStyleOrTheme->getControl(styleReaderType)) {
195 styleReader->m_effectiveInAppVariations.append(variationInStyleOrTheme);
197 for (
int baseType : styleReaderBaseTypes) {
198 if (variationInStyleOrTheme->getControl(baseType)) {
199 styleReader->m_effectiveInAppVariations.append(variationInStyleOrTheme);
213
214
215
216
217
218
219 Q_ASSERT(styleReader->m_effectiveVariationsDirty);
220 styleReader->m_effectiveVariationsDirty =
false;
221 styleReader->m_effectiveInAppVariations.clear();
222 styleReader->m_effectiveInStyleVariations.clear();
226 if (!hasTypeVariations && !hasInstanceVariations) {
228
229
234
235
236 QVarLengthArray<
const QQStyleKitControls *, 6> stylesAndThemes;
238 while (styleOrFallbackStyle) {
239 if (
const auto *theme = styleOrFallbackStyle
->theme())
240 stylesAndThemes.append(theme);
241 stylesAndThemes.append(styleOrFallbackStyle);
245 QObject *parentObj = styleReader;
247 QObject *attachedObject = qmlAttachedPropertiesObject<
QQStyleKitVariation>(parentObj,
false);
248 if (attachedObject) {
250 if (hasInstanceVariations)
251 addInstanceVariationsToReader(styleReader, variationAtt->variations(), stylesAndThemes);
252 if (hasTypeVariations)
253 addTypeVariationsToReader(styleReader, variationAtt->controlType(), style);
256 parentObj = parentObj->parent();
263 const T *storageProvider, QQSK::State state)
266
267
268
269
270
271
272
273
274
275 Q_ASSERT(qlonglong(state) <= qlonglong(QQSK::StateFlag::MAX_STATE));
277 const PropertyStorageId propertyKey = main.storageId(state);
280 QQStyleKitDebug::trace(main, storageProvider, state, propertyKey);
282 const QVariant propertyValue = storageProvider->readStyleProperty(propertyKey);
283 if (propertyValue.isValid()) {
285 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, propertyValue);
286 return propertyValue;
289 const PropertyStorageId altPropertyKey = alternative.storageId(state);
292 QQStyleKitDebug::trace(alternative, storageProvider, state, altPropertyKey);
294 const QVariant altValue = storageProvider->readStyleProperty(altPropertyKey);
295 if (altValue.isValid()) {
297 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, altValue);
304template <
class INDICES_CONTAINER>
308 int startIndex,
int recursionLevel)
310 for (
int i = startIndex; i < s_cachedStateList.length(); ++i) {
312
313
314
315
316
317
318
319 stateListIndices[recursionLevel] = i;
320 const QQSK::StateFlag stateFlag = s_cachedStateList[i];
323
324 if (!control->m_writtenStates.testFlag(stateFlag))
328
330 const QQSK::State statesAffectingProperty = controls->m_writtenPropertyPaths[main.pathId()];
331 if (!statesAffectingProperty.testFlag(stateFlag)) {
332 if (alternative.property() == QQSK::Property::NoProperty) {
335 const QQSK::State statesAffectingAlternative = controls->m_writtenPropertyPaths[alternative.pathId()];
336 if (!statesAffectingAlternative.testFlag(stateFlag))
341 if (recursionLevel < s_cachedStateList.length() - 1) {
343 const QVariant value = readPropertyInControlForStates(
344 main, alternative, control, stateListIndices, i + 1, recursionLevel + 1);
350 QQSK::State storageState = QQSK::StateFlag::Unspecified;
351 for (
int j = 0; j <= recursionLevel; ++j)
352 storageState.setFlag(s_cachedStateList[stateListIndices[j]]);
353 const QVariant value = readPropertyInStorageForState(main, alternative, control, storageState);
365
366
367
368
369 QVarLengthArray<
int, 10> stateListIndices(s_cachedStateList.length());
371 if (ids.subTypeProperty.property() != QQSK::Property::NoProperty) {
372 if (s_cachedState != QQSK::StateFlag::Normal) {
373 QVariant value = readPropertyInControlForStates(
374 ids.subTypeProperty, ids.subTypeAlternative, control, stateListIndices, 0, 0);
379 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal)) {
380 const QVariant value = readPropertyInStorageForState(
381 ids.subTypeProperty, ids.subTypeAlternative, control, QQSK::StateFlag::Normal);
387 if (s_cachedState != QQSK::StateFlag::Normal) {
388 const QVariant value = readPropertyInControlForStates(
389 ids.property, ids.alternative, control, stateListIndices, 0, 0);
395
396
397
398 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal))
399 return readPropertyInStorageForState(ids.property, ids.alternative, control, QQSK::StateFlag::Normal);
406 const QQStyleKitExtendableControlType exactType,
407 const QList<QQStyleKitExtendableControlType> baseTypes)
413
415 const auto writtenProperties = controls->m_writtenPropertyPaths;
416 if (writtenProperties.contains(ids.property.pathId()))
418 const bool hasAlternative = ids.alternative.property() != QQSK::Property::NoProperty;
419 if (hasAlternative && writtenProperties.contains(ids.alternative.pathId()))
421 if (ids.subTypeProperty.property() == QQSK::Property::NoProperty)
423 if (writtenProperties.contains(ids.subTypeProperty.pathId()))
425 if (hasAlternative && writtenProperties.contains(ids.subTypeAlternative.pathId()))
431 const QVariant value = readPropertyInControl(ids, control);
436 for (
const int type : baseTypes) {
437 if (
const QQStyleKitControl *control = controls->getControl(type)) {
438 const QVariant value = readPropertyInControl(ids, control);
448 const PropertyPathIds &ids,
449 const QQStyleKitExtendableControlType exactType,
450 const QList<QQStyleKitExtendableControlType> baseTypes,
456 value = readPropertyInRelevantControls(style->theme(), ids, exactType, baseTypes);
459 value = readPropertyInRelevantControls(style, ids, exactType, baseTypes);
465
466 fallbackStyle->syncFromQPalette(style->effectivePalette());
467 value = readPropertyInStyle(ids, exactType, baseTypes, fallbackStyle);
476 if (!value.isValid())
487
488
489 style->syncFromQPalette(styleReader->effectivePalette());
492
493
494 cacheReaderState(styleReader->controlState());
496 if (styleReader->m_effectiveVariationsDirty)
497 rebuildVariationsForReader(styleReader, style);
499 const QQStyleKitExtendableControlType exactType = styleReader->controlType();
500 const QList<QQStyleKitExtendableControlType> baseTypes = baseTypesForType(exactType);
505 for (
const QPointer<QQStyleKitVariation> &variation : std::as_const(styleReader->m_effectiveInAppVariations)) {
508 value = readPropertyInRelevantControls(variation, ids, exactType, baseTypes);
515 for (
const QPointer<QQStyleKitVariation> &variation : std::as_const(styleReader->m_effectiveInStyleVariations)) {
518 value = readPropertyInRelevantControls(variation, ids, exactType, baseTypes);
525 value = readPropertyInStyle(ids, exactType, baseTypes, style);
530 if (!value.isValid())
539 const QQSK::Property property,
540 const QQSK::Property alternative)
543 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
544 const QQSK::Subclass subclass = controlProperties->subclass();
546 if (subclass == QQSK::Subclass::QQStyleKitState) {
548
549
550
551
552
553
554
555
556
559 const PropertyPathId propertyPathId = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
560 const PropertyStorageId key = propertyPathId.storageId(controlState->nestedState());
561 return control->readStyleProperty(key);
566 if (!s_styleWarningsIssued) {
567 s_styleWarningsIssued =
true;
568 qmlWarning(group) <<
"style properties cannot be read: No StyleKit style has been set!";
578 if (subclass == QQSK::Subclass::QQStyleKitReader) {
582 if (s_isReadingProperty) {
583 if (!s_styleWarningsIssued) {
584 s_styleWarningsIssued =
true;
585 qmlWarning(styleReader) <<
"The style property '" << property <<
"' was read "
586 <<
"before finishing the read of another style property. "
587 <<
"This is likely to cause a style glitch.";
590 QScopedValueRollback rollback(s_isReadingProperty,
true);
593 ids.property = group->propertyPathId(property, PropertyPathId::Flag::ExcludeSubtype);
594 ids.alternative = group->propertyPathId(alternative, PropertyPathId::Flag::ExcludeSubtype);
595 const bool insideSubType = pathFlags &
596 (QQSK::PropertyPathFlag::DelegateSubtype1 | QQSK::PropertyPathFlag::DelegateSubtype2);
599 ids.subTypeProperty = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
600 ids.subTypeAlternative = group->propertyPathId(alternative, PropertyPathId::Flag::IncludeSubtype);
606 if (!pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
608
609
610
611
613 const QVariant value = readPropertyInStorageForState(
614 ids.subTypeProperty, ids.subTypeAlternative, styleReader, QQSK::StateFlag::Normal);
618 const QVariant value = readPropertyInStorageForState(
619 ids.property, ids.alternative, styleReader, QQSK::StateFlag::Normal);
624 return readProperty(ids, styleReader, style);
633 const QQSK::Property property,
634 const QVariant &value)
640 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
641 const QQSK::Subclass subclass = controlProperties->subclass();
642 const PropertyPathId propertyPathId = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
644 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
645 qmlWarning(controlProperties) <<
"Properties inside 'global' are read-only!";
649 if (subclass == QQSK::Subclass::QQStyleKitReader) {
652 const PropertyStorageId key = propertyPathId.storageId(QQSK::StateFlag::Normal);
653 const QVariant currentValue = reader->readStyleProperty(key);
654 const bool valueChanged = currentValue != value;
656 reader->writeStyleProperty(key, value);
657 QQStyleKitDebug::notifyPropertyWrite(group, property, reader, QQSK::StateFlag::Normal, key, value);
662 if (subclass == QQSK::Subclass::QQStyleKitState) {
666 const QQSK::State nestedState = controlState->nestedState();
667 const PropertyStorageId key = propertyPathId.storageId(nestedState);
668 const QVariant currentValue = control->readStyleProperty(key);
669 const bool valueChanged = currentValue != value;
672
673
674 control->m_writtenStates |= nestedState;
676
677
678
680 const QQSK::State alreadyWrittenStates = controls->m_writtenPropertyPaths[propertyPathId.pathId()];
681 controls->m_writtenPropertyPaths[propertyPathId.pathId()] = alreadyWrittenStates | nestedState;
683 control->writeStyleProperty(key, value);
684 QQStyleKitDebug::notifyPropertyWrite(group, property, control, nestedState, key, value);
695 const QQSK::Property property)
699 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
700 const PropertyPathId propertyPathId = group->propertyPathId(property, PropertyPathId::Flag::IncludeSubtype);
701 const QQSK::Subclass subclass = controlProperties->subclass();
703 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global))
706 if (subclass == QQSK::Subclass::QQStyleKitReader) {
707 const PropertyStorageId key = propertyPathId.storageId(QQSK::StateFlag::Normal);
711 if (subclass == QQSK::Subclass::QQStyleKitState) {
714 const PropertyStorageId key = propertyPathId.storageId(controlState->nestedState());
715 return control->readStyleProperty(key).isValid();
724#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.