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::HeaderViewDelegate: {
75 static QList<QQStyleKitExtendableControlType> t =
76 { QQStyleKitReader::TableViewDelegate, QQStyleKitReader::ItemDelegate, QQStyleKitReader::Control };
79 case QQStyleKitReader::Dialog:
80 case QQStyleKitReader::Drawer:
81 case QQStyleKitReader::Menu:
82 case QQStyleKitReader::ToolTip: {
83 static QList<QQStyleKitExtendableControlType> t =
84 { QQStyleKitReader::Popup, QQStyleKitReader::Control };
86 case QQStyleKitReader::Page:
87 case QQStyleKitReader::DialogButtonBox:
88 case QQStyleKitReader::Frame:
89 case QQStyleKitReader::TabBar:
90 case QQStyleKitReader::ToolBar: {
91 static QList<QQStyleKitExtendableControlType> t =
92 { QQStyleKitReader::Pane, QQStyleKitReader::Control };
94 case QQStyleKitReader::GroupBox: {
95 static QList<QQStyleKitExtendableControlType> t =
96 { QQStyleKitReader::Frame, QQStyleKitReader::Pane, QQStyleKitReader::Control };
99 case QQStyleKitReader::TextField:
100 case QQStyleKitReader::TextArea: {
101 static QList<QQStyleKitExtendableControlType> t =
102 { QQStyleKitReader::TextInput, QQStyleKitReader::Control };
105 static QList<QQStyleKitExtendableControlType> t =
106 { QQStyleKitReader::Control };
116 Q_ASSERT(state != QQSK::StateFlag::Unspecified);
117 if (state == s_cachedState)
120 s_cachedState = state;
123
124
125
126
127 s_cachedStateList.clear();
128 if (state.testFlag(QQSK::StateFlag::Pressed))
129 s_cachedStateList.append(QQSK::StateFlag::Pressed);
130 if (state.testFlag(QQSK::StateFlag::Hovered))
131 s_cachedStateList.append(QQSK::StateFlag::Hovered);
132 if (state.testFlag(QQSK::StateFlag::Highlighted))
133 s_cachedStateList.append(QQSK::StateFlag::Highlighted);
134 if (state.testFlag(QQSK::StateFlag::Focused))
135 s_cachedStateList.append(QQSK::StateFlag::Focused);
136 if (state.testFlag(QQSK::StateFlag::Checked))
137 s_cachedStateList.append(QQSK::StateFlag::Checked);
138 if (state.testFlag(QQSK::StateFlag::Vertical))
139 s_cachedStateList.append(QQSK::StateFlag::Vertical);
140 if (state.testFlag(QQSK::StateFlag::Disabled))
141 s_cachedStateList.append(QQSK::StateFlag::Disabled);
145 QQStyleKitReader *styleReader,
150
151
152
153 if (!styleReader->m_effectiveVariations.contains(variation))
154 styleReader->m_effectiveVariations.append(variation);
157
158
159
160 if (!variation->m_usageContext.contains(styleOrTheme))
161 variation->m_usageContext.append(styleOrTheme);
165 QQStyleKitReader *styleReader,
167 const AttachedVariationList &attachedVariations)
169 const QQStyleKitExtendableControlType styleReaderType = styleReader->controlType();
170 const auto styleReaderBaseType = baseTypesForType(styleReaderType);
173 if (ids.property.property() == QQSK::Property::NoProperty) {
175
176
177 ids.property = QQStyleKitPropertyPath(styleReader, QQSK::Property::Variations, QQStyleKitPropertyPath::Flag::ExcludeSubtype);
178 ids.alternative = QQStyleKitPropertyPath(styleReader, QQSK::Property::NoProperty, QQStyleKitPropertyPath::Flag::ExcludeSubtype);
183 for (
const QQStyleKitVariationAttached *attached : attachedVariations) {
184 const auto parentType = attached->controlType();
185 const auto parentBaseTypes = baseTypesForType(parentType);
188
189
190
191 const QVariant typeVariationsVariant = readPropertyInRelevantControls(styleOrTheme, ids, parentType, parentBaseTypes);
192 if (!typeVariationsVariant.isValid())
195 const auto typeVariations = *qvariant_cast<QList<QQStyleKitVariation *> *>(typeVariationsVariant);
197 for (QQStyleKitVariation *variation : typeVariations) {
199
200
203
207 if (variation->getControlStyle(styleReaderType)) {
208 addVariationToReader(styleReader, styleOrTheme, variation);
210 for (
int type : styleReaderBaseType) {
211 if (variation->getControlStyle(type))
212 addVariationToReader(styleReader, styleOrTheme, variation);
220 QQStyleKitReader *styleReader,
222 const AttachedVariationList &attachedVariations)
225
226
227
228
229 const QQStyleKitExtendableControlType styleReaderType = styleReader->controlType();
230 const auto styleReaderBaseTypes = baseTypesForType(styleReaderType);
232 for (
const QQStyleKitVariationAttached *attached : attachedVariations) {
233 for (
const QString &instanceVariationName : attached->variations()) {
234 for (QQStyleKitVariation *variation : styleOrTheme->m_styleVariations) {
235 if (variation->name() != instanceVariationName)
239
240
241
242 if (variation->getControlStyle(styleReaderType)) {
243 addVariationToReader(styleReader, styleOrTheme, variation);
245 for (
int baseType : styleReaderBaseTypes) {
246 if (variation->getControlStyle(baseType))
247 addVariationToReader(styleReader, styleOrTheme, variation);
256 QQStyleKitReader *styleReader, QQStyleKitStyle *style)
259
260
261
262
263
264
265 Q_ASSERT(styleReader->m_effectiveVariationsDirty);
266 styleReader->m_effectiveVariationsDirty =
false;
267 styleReader->m_effectiveVariations.clear();
269 if (!style->m_hasVariations)
273
274
275 AttachedVariationList attachedVariations;
276 for (QObject *current = styleReader; current; current = current->parent()) {
277 if (
const QObject *attachedObject = qmlAttachedPropertiesObject<QQStyleKitVariation>(current,
false)) {
279 attachedVariations.append(attached);
283 if (attachedVariations.isEmpty())
286 for (QQStyleKitStyle *current = style; current; current = current->fallbackStyle()) {
288 addInstanceVariationsToReader(styleReader, theme, attachedVariations);
289 addTypeVariationsToReader(styleReader, theme, attachedVariations);
291 addInstanceVariationsToReader(styleReader, current, attachedVariations);
292 addTypeVariationsToReader(styleReader, current, attachedVariations);
299 const T *storageProvider, QQSK::State state)
302
303
304
305
306
307
308
309
310
311 Q_ASSERT(qlonglong(state) <= qlonglong(QQSK::StateFlag::MAX_STATE));
313 const PropertyStorageId propertyKey = main.createStorageId(state);
316 QQStyleKitDebug::trace(main, storageProvider, state, propertyKey);
318 const QVariant propertyValue = storageProvider->readStyleProperty(propertyKey);
319 if (propertyValue.isValid()) {
321 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, propertyValue);
322 return propertyValue;
325 const PropertyStorageId altPropertyKey = alternative.createStorageId(state);
328 QQStyleKitDebug::trace(alternative, storageProvider, state, altPropertyKey);
330 const QVariant altValue = storageProvider->readStyleProperty(altPropertyKey);
331 if (altValue.isValid()) {
333 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, altValue);
340template <
class INDICES_CONTAINER>
344 int startIndex,
int recursionLevel)
346 for (
int i = startIndex; i < s_cachedStateList.length(); ++i) {
348
349
350
351
352
353
354
355 stateListIndices[recursionLevel] = i;
356 const QQSK::StateFlag stateFlag = s_cachedStateList[i];
359
360 if (!control->m_writtenStates.testFlag(stateFlag))
364
366 const QQSK::State statesAffectingProperty = controls->m_writtenPropertyPaths[main.pathId()];
367 if (!statesAffectingProperty.testFlag(stateFlag)) {
368 if (alternative.property() == QQSK::Property::NoProperty) {
371 const QQSK::State statesAffectingAlternative = controls->m_writtenPropertyPaths[alternative.pathId()];
372 if (!statesAffectingAlternative.testFlag(stateFlag))
377 if (recursionLevel < s_cachedStateList.length() - 1) {
379 const QVariant value = readPropertyInControlForStates(
380 main, alternative, control, stateListIndices, i + 1, recursionLevel + 1);
386 QQSK::State storageState = QQSK::StateFlag::Unspecified;
387 for (
int j = 0; j <= recursionLevel; ++j)
388 storageState.setFlag(s_cachedStateList[stateListIndices[j]]);
389 const QVariant value = readPropertyInStorageForState(main, alternative, control, storageState);
401
402
403
404
405 QVarLengthArray<
int, 10> stateListIndices(s_cachedStateList.length());
407 if (ids.subTypeProperty.property() != QQSK::Property::NoProperty) {
408 if (s_cachedState != QQSK::StateFlag::Normal) {
409 QVariant value = readPropertyInControlForStates(
410 ids.subTypeProperty, ids.subTypeAlternative, control, stateListIndices, 0, 0);
415 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal)) {
416 const QVariant value = readPropertyInStorageForState(
417 ids.subTypeProperty, ids.subTypeAlternative, control, QQSK::StateFlag::Normal);
423 if (s_cachedState != QQSK::StateFlag::Normal) {
424 const QVariant value = readPropertyInControlForStates(
425 ids.property, ids.alternative, control, stateListIndices, 0, 0);
431
432
433
434 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal))
435 return readPropertyInStorageForState(ids.property, ids.alternative, control, QQSK::StateFlag::Normal);
442 const QQStyleKitExtendableControlType exactType,
443 const QList<QQStyleKitExtendableControlType> baseTypes)
449
451 const auto writtenProperties = controls->m_writtenPropertyPaths;
452 if (writtenProperties.contains(ids.property.pathId()))
454 const bool hasAlternative = ids.alternative.property() != QQSK::Property::NoProperty;
455 if (hasAlternative && writtenProperties.contains(ids.alternative.pathId()))
457 if (ids.subTypeProperty.property() == QQSK::Property::NoProperty)
459 if (writtenProperties.contains(ids.subTypeProperty.pathId()))
461 if (hasAlternative && writtenProperties.contains(ids.subTypeAlternative.pathId()))
467 const QVariant value = readPropertyInControl(ids, control);
472 for (
const int type : baseTypes) {
473 if (
const QQStyleKitControl *control = controls->getControlStyle(type)) {
474 const QVariant value = readPropertyInControl(ids, control);
484 const QList<QPointer<QQStyleKitVariation>> &variations,
487 const QQStyleKitExtendableControlType exactType,
488 const QList<QQStyleKitExtendableControlType> baseTypes)
490 bool foundAtLeastOneVariation =
false;
491 for (
const QPointer<QQStyleKitVariation> &variation : variations) {
494 if (!variation->m_usageContext.contains(styleOrTheme)) {
495 if (foundAtLeastOneVariation) {
497
498
499
503
506 foundAtLeastOneVariation =
true;
507 const QVariant value = readPropertyInRelevantControls(variation, ids, exactType, baseTypes);
515 QQStyleKitStyle *style,
const PropertyPathIds &ids, QQStyleKitReader *styleReader)
518
519
520 style->syncFromQPalette(styleReader->effectivePalette());
523
524
525 cacheReaderState(styleReader->controlState());
527 if (styleReader->m_effectiveVariationsDirty)
528 rebuildVariationsForReader(styleReader, style);
530 const QQStyleKitExtendableControlType exactType = styleReader->controlType();
531 const QList<QQStyleKitExtendableControlType> baseTypes = baseTypesForType(exactType);
536 value = readPropertyInVariations(styleReader->m_effectiveVariations, style->theme(), ids, exactType, baseTypes);
540 value = readPropertyInRelevantControls(style->theme(), ids, exactType, baseTypes);
544 value = readPropertyInVariations(styleReader->m_effectiveVariations, style, ids, exactType, baseTypes);
548 value = readPropertyInRelevantControls(style, ids, exactType, baseTypes);
552 if (
auto *fallbackStyle = style->fallbackStyle()) {
554
555 value = readPropertyInStyle(fallbackStyle, ids, styleReader);
564 if (!value.isValid())
573 const QQSK::Property property,
574 const QQSK::Property alternative)
577 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
578 const QQSK::Subclass subclass = controlProperties->subclass();
580 if (subclass != QQSK::Subclass::QQStyleKitReader) {
582
583
584
585
586
587
588
589 Q_ASSERT(subclass == QQSK::Subclass::QQStyleKitState);
592 const PropertyStorageId key =
QQStyleKitPropertyPath(group, property).createStorageId(controlState->nestedState());
593 return control->readStyleProperty(key);
596 QQStyleKitStyle *style = controlProperties->style();
597 if (!style || !style->loaded()) {
599
600
601
606 QQStyleKitReader *styleReader = controlProperties->asQQStyleKitReader();
608 if (s_isReadingProperty) {
609 if (!s_styleWarningsIssued) {
610 s_styleWarningsIssued =
true;
611 qmlWarning(styleReader) <<
"The style property '" << property <<
"' was read "
612 <<
"before finishing the read of another style property. "
613 <<
"This is likely to cause a style glitch.";
616 QScopedValueRollback rollback(s_isReadingProperty,
true);
619 ids.property = QQStyleKitPropertyPath(group, property, QQStyleKitPropertyPath::Flag::ExcludeSubtype);
620 ids.alternative = QQStyleKitPropertyPath(group, alternative, QQStyleKitPropertyPath::Flag::ExcludeSubtype);
621 const bool insideSubType = pathFlags &
622 (QQSK::PropertyPathFlag::DelegateSubtype1 | QQSK::PropertyPathFlag::DelegateSubtype2);
632 if (!pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
634
635
636
637
639 const QVariant value = readPropertyInStorageForState(
640 ids.subTypeProperty, ids.subTypeAlternative, styleReader, QQSK::StateFlag::Normal);
644 const QVariant value = readPropertyInStorageForState(
645 ids.property, ids.alternative, styleReader, QQSK::StateFlag::Normal);
650 return readPropertyInStyle(style, ids, styleReader);
655 const QQSK::Property property,
656 const QVariant &value)
662 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
663 const QQSK::Subclass subclass = controlProperties->subclass();
666 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
667 qmlWarning(controlProperties) <<
"Properties inside 'global' are read-only!";
671 if (subclass == QQSK::Subclass::QQStyleKitReader) {
673 QQStyleKitReader *reader = controlProperties->asQQStyleKitReader();
674 const PropertyStorageId key = propertyPath.createStorageId(QQSK::StateFlag::Normal);
675 const QVariant currentValue = reader->readStyleProperty(key);
676 const bool valueChanged = currentValue != value;
678 reader->writeStyleProperty(key, value);
679 QQStyleKitDebug::notifyPropertyWrite(group, property, reader, QQSK::StateFlag::Normal, key, value);
684 if (subclass == QQSK::Subclass::QQStyleKitState) {
688 const QQSK::State nestedState = controlState->nestedState();
689 const PropertyStorageId key = propertyPath.createStorageId(nestedState);
690 const QVariant currentValue = control->readStyleProperty(key);
691 const bool valueChanged = currentValue != value;
694
695
696 control->m_writtenStates |= nestedState;
698
699
700
702 const QQSK::State alreadyWrittenStates = controls->m_writtenPropertyPaths[propertyPath.pathId()];
703 controls->m_writtenPropertyPaths[propertyPath.pathId()] = alreadyWrittenStates | nestedState;
705 control->writeStyleProperty(key, value);
706 QQStyleKitDebug::notifyPropertyWrite(group, property, control, nestedState, key, value);
717 const QQSK::Property property)
721 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
723 const QQSK::Subclass subclass = controlProperties->subclass();
725 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global))
728 if (subclass == QQSK::Subclass::QQStyleKitReader) {
729 const PropertyStorageId key = propertyPath.createStorageId(QQSK::StateFlag::Normal);
730 return controlProperties->asQQStyleKitReader()->readStyleProperty(key).isValid();
733 if (subclass == QQSK::Subclass::QQStyleKitState) {
736 const PropertyStorageId key = propertyPath.createStorageId(controlState->nestedState());
737 return control->readStyleProperty(key).isValid();
746#include "moc_qqstylekitpropertyresolver_p.cpp"
QQStyleKitControl * control() const
QQStyleKitControlProperties * controlProperties() const
Combined button and popup list for selecting options.