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
44 case QQStyleKitReader::ApplicationWindow: {
45 static QList<QQStyleKitExtendableControlType> t =
46 { QQStyleKitReader::ApplicationWindow };
48 case QQStyleKitReader::Button:
49 case QQStyleKitReader::DelayButton:
50 case QQStyleKitReader::FlatButton:
51 case QQStyleKitReader::ToolButton:
52 case QQStyleKitReader::TabButton:
53 case QQStyleKitReader::RadioButton:
54 case QQStyleKitReader::RoundButton:
55 case QQStyleKitReader::CheckBox:
56 case QQStyleKitReader::SwitchControl: {
57 static QList<QQStyleKitExtendableControlType> t =
58 { QQStyleKitReader::AbstractButton, QQStyleKitReader::Control };
60 case QQStyleKitReader::CheckDelegate:
61 case QQStyleKitReader::RadioDelegate:
62 case QQStyleKitReader::SwipeDelegate:
63 case QQStyleKitReader::SwitchDelegate:
64 case QQStyleKitReader::TableViewDelegate:
65 case QQStyleKitReader::TreeViewDelegate: {
66 static QList<QQStyleKitExtendableControlType> t =
67 { QQStyleKitReader::ItemDelegate, QQStyleKitReader::Control };
69 case QQStyleKitReader::HeaderViewDelegate: {
70 static QList<QQStyleKitExtendableControlType> t =
71 { QQStyleKitReader::TableViewDelegate, QQStyleKitReader::ItemDelegate, QQStyleKitReader::Control };
74 case QQStyleKitReader::Dialog:
75 case QQStyleKitReader::Drawer:
76 case QQStyleKitReader::Menu:
77 case QQStyleKitReader::ToolTip: {
78 static QList<QQStyleKitExtendableControlType> t =
79 { QQStyleKitReader::Popup, QQStyleKitReader::Control };
81 case QQStyleKitReader::Page:
82 case QQStyleKitReader::Frame:
83 case QQStyleKitReader::ToolBar: {
84 static QList<QQStyleKitExtendableControlType> t =
85 { QQStyleKitReader::Pane, QQStyleKitReader::Control };
87 case QQStyleKitReader::DialogButtonBox:
88 case QQStyleKitReader::MenuBar:
89 case QQStyleKitReader::TabBar: {
90 static QList<QQStyleKitExtendableControlType> t =
91 { QQStyleKitReader::Container, QQStyleKitReader::Control };
93 case QQStyleKitReader::GroupBox: {
94 static QList<QQStyleKitExtendableControlType> t =
95 { QQStyleKitReader::Frame, QQStyleKitReader::Pane, QQStyleKitReader::Control };
98 case QQStyleKitReader::SplitView: {
99 static QList<QQStyleKitExtendableControlType> t =
100 { QQStyleKitReader::Container, QQStyleKitReader::Control };
102 case QQStyleKitReader::TextField:
103 case QQStyleKitReader::TextArea: {
104 static QList<QQStyleKitExtendableControlType> t =
105 { QQStyleKitReader::TextInput, QQStyleKitReader::Control };
108 static QList<QQStyleKitExtendableControlType> t =
109 { QQStyleKitReader::Control };
119 Q_ASSERT(state != QQSK::StateFlag::Unspecified);
120 if (state == s_cachedState)
123 s_cachedState = state;
126
127
128
129
130 s_cachedStateList.clear();
131 if (state.testFlag(QQSK::StateFlag::Pressed))
132 s_cachedStateList.append(QQSK::StateFlag::Pressed);
133 if (state.testFlag(QQSK::StateFlag::Hovered))
134 s_cachedStateList.append(QQSK::StateFlag::Hovered);
135 if (state.testFlag(QQSK::StateFlag::Highlighted))
136 s_cachedStateList.append(QQSK::StateFlag::Highlighted);
137 if (state.testFlag(QQSK::StateFlag::Focused))
138 s_cachedStateList.append(QQSK::StateFlag::Focused);
139 if (state.testFlag(QQSK::StateFlag::Checked))
140 s_cachedStateList.append(QQSK::StateFlag::Checked);
141 if (state.testFlag(QQSK::StateFlag::Vertical))
142 s_cachedStateList.append(QQSK::StateFlag::Vertical);
143 if (state.testFlag(QQSK::StateFlag::Disabled))
144 s_cachedStateList.append(QQSK::StateFlag::Disabled);
148 QQStyleKitReader *styleReader,
149 QQStyleKitStyleAndThemeBase *styleOrTheme,
153
154
155
156 if (!styleReader->m_effectiveVariations.contains(variation))
157 styleReader->m_effectiveVariations.append(variation);
160
161
162
163 if (!variation->m_usageContext.contains(styleOrTheme))
164 variation->m_usageContext.append(styleOrTheme);
168 QQStyleKitReader *styleReader,
169 QQStyleKitStyleAndThemeBase *styleOrTheme,
170 const AttachedVariationList &attachedVariations)
172 const QQStyleKitExtendableControlType styleReaderType = styleReader->controlType();
173 const auto styleReaderBaseType = baseTypesForType(styleReaderType);
176 if (ids.property.property() == QQSK::Property::NoProperty) {
178
179
180 ids.property = QQStyleKitPropertyPath(styleReader, QQSK::Property::Variations, QQStyleKitPropertyPath::Flag::ExcludeSubtype);
181 ids.alternative = QQStyleKitPropertyPath(styleReader, QQSK::Property::NoProperty, QQStyleKitPropertyPath::Flag::ExcludeSubtype);
186 for (
const QQStyleKitVariationAttached *attached : attachedVariations) {
187 const auto parentType = attached->controlType();
188 const auto parentBaseTypes = baseTypesForType(parentType);
191
192
193
194 const QVariant typeVariationsVariant = readPropertyInRelevantControls(styleOrTheme, ids, parentType, parentBaseTypes);
195 if (!typeVariationsVariant.isValid())
198 const auto typeVariations = *qvariant_cast<QList<QQStyleKitVariation *> *>(typeVariationsVariant);
200 for (QQStyleKitVariation *variation : typeVariations) {
202
203
206
210 if (variation->getControlStyle(styleReaderType)) {
211 addVariationToReader(styleReader, styleOrTheme, variation);
213 for (
int type : styleReaderBaseType) {
214 if (variation->getControlStyle(type))
215 addVariationToReader(styleReader, styleOrTheme, variation);
223 QQStyleKitReader *styleReader,
224 QQStyleKitStyleAndThemeBase *styleOrTheme,
225 const AttachedVariationList &attachedVariations)
228
229
230
231
232 const QQStyleKitExtendableControlType styleReaderType = styleReader->controlType();
233 const auto styleReaderBaseTypes = baseTypesForType(styleReaderType);
235 for (
const QQStyleKitVariationAttached *attached : attachedVariations) {
236 for (
const QString &instanceVariationName : attached->variations()) {
237 for (QQStyleKitVariation *variation : styleOrTheme->m_styleVariations) {
238 if (variation->name() != instanceVariationName)
242
243
244
245 if (variation->getControlStyle(styleReaderType)) {
246 addVariationToReader(styleReader, styleOrTheme, variation);
248 for (
int baseType : styleReaderBaseTypes) {
249 if (variation->getControlStyle(baseType))
250 addVariationToReader(styleReader, styleOrTheme, variation);
259 QQStyleKitReader *styleReader, QQStyleKitStyle *style)
262
263
264
265
266
267
268 Q_ASSERT(styleReader->m_effectiveVariationsDirty);
269 styleReader->m_effectiveVariationsDirty =
false;
270 styleReader->m_effectiveVariations.clear();
272 if (!style->m_hasVariations)
276
277
278 AttachedVariationList attachedVariations;
279 for (QObject *current = styleReader; current; current = current->parent()) {
280 if (
const QObject *attachedObject = qmlAttachedPropertiesObject<QQStyleKitVariation>(current,
false)) {
282 attachedVariations.append(attached);
286 if (attachedVariations.isEmpty())
289 for (QQStyleKitStyle *current = style; current; current = current->fallbackStyle()) {
291 addInstanceVariationsToReader(styleReader, theme, attachedVariations);
292 addTypeVariationsToReader(styleReader, theme, attachedVariations);
294 addInstanceVariationsToReader(styleReader, current, attachedVariations);
295 addTypeVariationsToReader(styleReader, current, attachedVariations);
302 const T *storageProvider, QQSK::State state)
305
306
307
308
309
310
311
312
313
314 Q_ASSERT(qlonglong(state) <= qlonglong(QQSK::StateFlag::MAX_STATE));
316 const PropertyStorageId propertyKey = main.createStorageId(state);
319 QQStyleKitDebug::trace(main, storageProvider, state, propertyKey);
321 const QVariant propertyValue = storageProvider->readStyleProperty(propertyKey);
322 if (propertyValue.isValid()) {
324 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, propertyValue);
325 return propertyValue;
328 const PropertyStorageId altPropertyKey = alternative.createStorageId(state);
331 QQStyleKitDebug::trace(alternative, storageProvider, state, altPropertyKey);
333 const QVariant altValue = storageProvider->readStyleProperty(altPropertyKey);
334 if (altValue.isValid()) {
336 QQStyleKitDebug::notifyPropertyRead(main, storageProvider, state, altValue);
343template <
class INDICES_CONTAINER>
346 const QQStyleKitControl *control, INDICES_CONTAINER &stateListIndices,
347 int startIndex,
int recursionLevel)
349 for (
int i = startIndex; i < s_cachedStateList.length(); ++i) {
351
352
353
354
355
356
357
358 stateListIndices[recursionLevel] = i;
359 const QQSK::StateFlag stateFlag = s_cachedStateList[i];
362
363 if (!control->m_writtenStates.testFlag(stateFlag))
367
368 const QQStyleKitControls *controls = control->controls();
369 const QQSK::State statesAffectingProperty = controls->m_writtenPropertyPaths[main.pathId()];
370 if (!statesAffectingProperty.testFlag(stateFlag)) {
371 if (alternative.property() == QQSK::Property::NoProperty) {
374 const QQSK::State statesAffectingAlternative = controls->m_writtenPropertyPaths[alternative.pathId()];
375 if (!statesAffectingAlternative.testFlag(stateFlag))
380 if (recursionLevel < s_cachedStateList.length() - 1) {
382 const QVariant value = readPropertyInControlForStates(
383 main, alternative, control, stateListIndices, i + 1, recursionLevel + 1);
389 QQSK::State storageState = QQSK::StateFlag::Unspecified;
390 for (
int j = 0; j <= recursionLevel; ++j)
391 storageState.setFlag(s_cachedStateList[stateListIndices[j]]);
392 const QVariant value = readPropertyInStorageForState(main, alternative, control, storageState);
404
405
406
407
408 QVarLengthArray<
int, 10> stateListIndices(s_cachedStateList.length());
410 if (ids.subTypeProperty.property() != QQSK::Property::NoProperty) {
411 if (s_cachedState != QQSK::StateFlag::Normal) {
412 QVariant value = readPropertyInControlForStates(
413 ids.subTypeProperty, ids.subTypeAlternative, control, stateListIndices, 0, 0);
418 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal)) {
419 const QVariant value = readPropertyInStorageForState(
420 ids.subTypeProperty, ids.subTypeAlternative, control, QQSK::StateFlag::Normal);
426 if (s_cachedState != QQSK::StateFlag::Normal) {
427 const QVariant value = readPropertyInControlForStates(
428 ids.property, ids.alternative, control, stateListIndices, 0, 0);
434
435
436
437 if (control->m_writtenStates.testFlag(QQSK::StateFlag::Normal))
438 return readPropertyInStorageForState(ids.property, ids.alternative, control, QQSK::StateFlag::Normal);
445 const QQStyleKitExtendableControlType exactType,
446 const QList<QQStyleKitExtendableControlType> baseTypes)
452
454 const auto writtenProperties = controls->m_writtenPropertyPaths;
455 if (writtenProperties.contains(ids.property.pathId()))
457 const bool hasAlternative = ids.alternative.property() != QQSK::Property::NoProperty;
458 if (hasAlternative && writtenProperties.contains(ids.alternative.pathId()))
460 if (ids.subTypeProperty.property() == QQSK::Property::NoProperty)
462 if (writtenProperties.contains(ids.subTypeProperty.pathId()))
464 if (hasAlternative && writtenProperties.contains(ids.subTypeAlternative.pathId()))
469 if (
const QQStyleKitControl *control = controls->getControlStyle(exactType)) {
470 const QVariant value = readPropertyInControl(ids, control);
475 for (
const int type : baseTypes) {
476 if (
const QQStyleKitControl *control = controls->getControlStyle(type)) {
477 const QVariant value = readPropertyInControl(ids, control);
487 const QList<QPointer<QQStyleKitVariation>> &variations,
488 const QQStyleKitStyleAndThemeBase *styleOrTheme,
490 const QQStyleKitExtendableControlType exactType,
491 const QList<QQStyleKitExtendableControlType> baseTypes)
493 bool foundAtLeastOneVariation =
false;
494 for (
const QPointer<QQStyleKitVariation> &variation : variations) {
497 if (!variation->m_usageContext.contains(styleOrTheme)) {
498 if (foundAtLeastOneVariation) {
500
501
502
506
509 foundAtLeastOneVariation =
true;
510 const QVariant value = readPropertyInRelevantControls(variation, ids, exactType, baseTypes);
518 QQStyleKitStyle *style,
const PropertyPathIds &ids, QQStyleKitReader *styleReader)
521
522
523 style->syncFromQPalette(styleReader->effectivePalette());
526
527
528 cacheReaderState(styleReader->controlState());
530 if (styleReader->m_effectiveVariationsDirty)
531 rebuildVariationsForReader(styleReader, style);
533 const QQStyleKitExtendableControlType exactType = styleReader->controlType();
534 const QList<QQStyleKitExtendableControlType> baseTypes = baseTypesForType(exactType);
539 value = readPropertyInVariations(styleReader->m_effectiveVariations, style->theme(), ids, exactType, baseTypes);
543 value = readPropertyInRelevantControls(style->theme(), ids, exactType, baseTypes);
547 value = readPropertyInVariations(styleReader->m_effectiveVariations, style, ids, exactType, baseTypes);
551 value = readPropertyInRelevantControls(style, ids, exactType, baseTypes);
555 if (
auto *fallbackStyle = style->fallbackStyle()) {
557
558 value = readPropertyInStyle(fallbackStyle, ids, styleReader);
567 if (!value.isValid())
576 const QQSK::Property property,
577 const QQSK::Property alternative)
580 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
581 const QQSK::Subclass subclass = controlProperties->subclass();
583 if (subclass != QQSK::Subclass::QQStyleKitReader) {
585
586
587
588
589
590
591
592 Q_ASSERT(subclass == QQSK::Subclass::QQStyleKitState);
593 const QQStyleKitControlState *controlState = controlProperties->asQQStyleKitState();
594 const QQStyleKitControl *control = controlState->control();
595 const PropertyStorageId key =
QQStyleKitPropertyPath(group, property).createStorageId(controlState->nestedState());
596 return control->readStyleProperty(key);
599 QQStyleKitStyle *style = controlProperties->style();
600 if (!style || !style->loaded()) {
602
603
604
609 QQStyleKitReader *styleReader = controlProperties->asQQStyleKitReader();
611 if (s_isReadingProperty) {
612 if (!s_styleWarningsIssued) {
613 s_styleWarningsIssued =
true;
614 qmlWarning(styleReader) <<
"The style property '" << property <<
"' was read "
615 <<
"before finishing the read of another style property. "
616 <<
"This is likely to cause a style glitch.";
619 QScopedValueRollback rollback(s_isReadingProperty,
true);
622 ids.property = QQStyleKitPropertyPath(group, property, QQStyleKitPropertyPath::Flag::ExcludeSubtype);
623 ids.alternative = QQStyleKitPropertyPath(group, alternative, QQStyleKitPropertyPath::Flag::ExcludeSubtype);
624 const bool insideSubType = pathFlags &
625 (QQSK::PropertyPathFlag::DelegateSubtype1 | QQSK::PropertyPathFlag::DelegateSubtype2);
635 if (!pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
637
638
639
640
642 const QVariant value = readPropertyInStorageForState(
643 ids.subTypeProperty, ids.subTypeAlternative, styleReader, QQSK::StateFlag::Normal);
647 const QVariant value = readPropertyInStorageForState(
648 ids.property, ids.alternative, styleReader, QQSK::StateFlag::Normal);
653 return readPropertyInStyle(style, ids, styleReader);
658 const QQSK::Property property,
659 const QVariant &value)
665 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
666 const QQSK::Subclass subclass = controlProperties->subclass();
669 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global)) {
670 qmlWarning(controlProperties) <<
"Properties inside 'global' are read-only!";
674 if (subclass == QQSK::Subclass::QQStyleKitReader) {
676 QQStyleKitReader *reader = controlProperties->asQQStyleKitReader();
677 const PropertyStorageId key = propertyPath.createStorageId(QQSK::StateFlag::Normal);
678 const QVariant currentValue = reader->readStyleProperty(key);
679 const bool valueChanged = currentValue != value;
681 reader->writeStyleProperty(key, value);
682 QQStyleKitDebug::notifyPropertyWrite(group, property, reader, QQSK::StateFlag::Normal, key, value);
687 if (subclass == QQSK::Subclass::QQStyleKitState) {
689 const QQStyleKitControlState *controlState = controlProperties->asQQStyleKitState();
690 QQStyleKitControl *control = controlState->control();
691 const QQSK::State nestedState = controlState->nestedState();
692 const PropertyStorageId key = propertyPath.createStorageId(nestedState);
693 const QVariant currentValue = control->readStyleProperty(key);
694 const bool valueChanged = currentValue != value;
697
698
699 control->m_writtenStates |= nestedState;
701
702
703
704 QQStyleKitControls *controls = control->controls();
705 const QQSK::State alreadyWrittenStates = controls->m_writtenPropertyPaths[propertyPath.pathId()];
706 controls->m_writtenPropertyPaths[propertyPath.pathId()] = alreadyWrittenStates | nestedState;
708 control->writeStyleProperty(key, value);
709 QQStyleKitDebug::notifyPropertyWrite(group, property, control, nestedState, key, value);
720 const QQSK::Property property)
724 const QQSK::PropertyPathFlags pathFlags = group->pathFlags();
726 const QQSK::Subclass subclass = controlProperties->subclass();
728 if (pathFlags.testFlag(QQSK::PropertyPathFlag::Global))
731 if (subclass == QQSK::Subclass::QQStyleKitReader) {
732 const PropertyStorageId key = propertyPath.createStorageId(QQSK::StateFlag::Normal);
733 return controlProperties->asQQStyleKitReader()->readStyleProperty(key).isValid();
736 if (subclass == QQSK::Subclass::QQStyleKitState) {
737 const QQStyleKitControlState *controlState = controlProperties->asQQStyleKitState();
738 const QQStyleKitControl *control = controlState->control();
739 const PropertyStorageId key = propertyPath.createStorageId(controlState->nestedState());
740 return control->readStyleProperty(key).isValid();
749#include "moc_qqstylekitpropertyresolver_p.cpp"
QQStyleKitControlProperties * controlProperties() const
Combined button and popup list for selecting options.