8#include <QtCore/qdebug.h>
10#include <QtCore/qsettings.h>
12#include <QtQml/qqmlinfo.h>
13#include <QtQuickControls2/private/qquickstyle_p.h>
19static const QRgb colors[][14] = {
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
436 if (theme == QQuickMaterialStyle::System)
437 theme = QQuickStylePrivate::isDarkSystemTheme() ? QQuickMaterialStyle::Dark : QQuickMaterialStyle::Light;
441QQuickMaterialStyle::QQuickMaterialStyle(QObject *parent) : QQuickAttachedPropertyPropagator(parent),
442 m_customPrimary(globalPrimaryCustom),
443 m_customAccent(globalAccentCustom),
444 m_customForeground(globalForegroundCustom),
445 m_customBackground(globalBackgroundCustom),
446 m_hasForeground(hasGlobalForeground),
447 m_hasBackground(hasGlobalBackground),
448 m_systemTheme(globalTheme == System),
449 m_theme(effectiveTheme(globalTheme)),
450 m_primary(globalPrimary),
451 m_accent(globalAccent),
452 m_foreground(globalForeground),
453 m_background(globalBackground)
455 QQuickAttachedPropertyPropagator::initialize();
458QQuickMaterialStyle *QQuickMaterialStyle::qmlAttachedProperties(QObject *object)
460 return new QQuickMaterialStyle(object);
463QQuickMaterialStyle::Theme QQuickMaterialStyle::theme()
const
468void QQuickMaterialStyle::setTheme(Theme theme)
470 m_explicitTheme =
true;
476 const bool systemThemeChanged = (m_systemTheme != (theme == System));
478 if ((m_theme == effectiveTheme(theme)) && !systemThemeChanged)
481 m_theme = effectiveTheme(theme);
482 m_systemTheme = (theme == System);
483 if (systemThemeChanged) {
485 QQuickMaterialTheme::registerSystemStyle(
this);
487 QQuickMaterialTheme::unregisterSystemStyle(
this);
494 if (!m_customBackground)
496 if (!m_customForeground)
500void QQuickMaterialStyle::inheritTheme(Theme theme)
502 const bool systemThemeChanged = (m_systemTheme != (theme == System));
503 const bool themeChanged = systemThemeChanged || (m_theme != effectiveTheme(theme));
504 if (m_explicitTheme || !themeChanged)
507 m_theme = effectiveTheme(theme);
508 m_systemTheme = (theme == System);
514 if (!m_customBackground)
516 if (!m_customForeground)
520void QQuickMaterialStyle::propagateTheme()
522 const auto styles = attachedChildren();
523 for (QQuickAttachedPropertyPropagator *child : styles) {
524 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(child);
529 material->inheritTheme(m_systemTheme ? System : m_theme);
533void QQuickMaterialStyle::resetTheme()
535 if (!m_explicitTheme)
538 m_explicitTheme =
false;
539 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(attachedParent());
540 inheritTheme(material ? material->theme() : globalTheme);
543void QQuickMaterialStyle::themeChange()
546 emit themeOrAccentChanged();
547 emit primaryHighlightedTextColor();
548 emit dialogColorChanged();
549 emit tooltipColorChanged();
550 emit toolBarColorChanged();
551 emit toolTextColorChanged();
554QVariant QQuickMaterialStyle::primary()
const
556 return primaryColor();
559void QQuickMaterialStyle::setPrimary(
const QVariant &var)
563 if (!variantToRgba(var,
"primary", &primary, &custom))
566 m_explicitPrimary =
true;
567 if (m_primary == primary)
570 m_customPrimary = custom;
576void QQuickMaterialStyle::inheritPrimary(uint primary,
bool custom)
578 if (m_explicitPrimary || m_primary == primary)
581 m_customPrimary = custom;
587void QQuickMaterialStyle::propagatePrimary()
589 const auto styles = attachedChildren();
590 for (QQuickAttachedPropertyPropagator *child : styles) {
591 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(child);
593 material->inheritPrimary(m_primary, m_customPrimary);
597void QQuickMaterialStyle::resetPrimary()
599 if (!m_explicitPrimary)
602 m_customPrimary =
false;
603 m_explicitPrimary =
false;
604 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(attachedParent());
606 inheritPrimary(material->m_primary, material->m_customPrimary);
608 inheritPrimary(globalPrimary,
false);
611void QQuickMaterialStyle::primaryChange()
613 emit primaryChanged();
614 emit toolBarColorChanged();
615 emit toolTextColorChanged();
618QVariant QQuickMaterialStyle::accent()
const
620 return accentColor();
623void QQuickMaterialStyle::setAccent(
const QVariant &var)
627 if (!variantToRgba(var,
"accent", &accent, &custom))
630 m_explicitAccent =
true;
631 if (m_accent == accent)
634 m_customAccent = custom;
640void QQuickMaterialStyle::inheritAccent(uint accent,
bool custom)
642 if (m_explicitAccent || m_accent == accent)
645 m_customAccent = custom;
651void QQuickMaterialStyle::propagateAccent()
653 const auto styles = attachedChildren();
654 for (QQuickAttachedPropertyPropagator *child : styles) {
655 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(child);
657 material->inheritAccent(m_accent, m_customAccent);
661void QQuickMaterialStyle::resetAccent()
663 if (!m_explicitAccent)
666 m_customAccent =
false;
667 m_explicitAccent =
false;
668 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(attachedParent());
670 inheritAccent(material->m_accent, material->m_customAccent);
672 inheritAccent(globalAccent,
false);
675void QQuickMaterialStyle::accentChange()
677 emit accentChanged();
678 emit themeOrAccentChanged();
681QVariant QQuickMaterialStyle::foreground()
const
683 if (!m_hasForeground) {
684 if (!m_customBackground && m_background == m_primary) {
685 return toolTextColor();
687 return QColor::fromRgba(m_theme == Light ? primaryTextColorLight : primaryTextColorDark);
689 if (m_customForeground)
690 return QColor::fromRgba(m_foreground);
691 if (m_foreground > BlueGrey)
693 return QColor::fromRgba(colors[m_foreground][Shade500]);
696void QQuickMaterialStyle::setForeground(
const QVariant &var)
700 if (!variantToRgba(var,
"foreground", &foreground, &custom))
705 if (!hasGlobalForeground) {
706 const QRgb themeDefault = (m_theme == Light ? primaryTextColorLight : primaryTextColorDark);
707 if (foreground == themeDefault) {
713 m_hasForeground =
true;
714 m_explicitForeground =
true;
715 if (m_foreground == foreground)
718 m_customForeground = custom;
719 m_foreground = foreground;
720 propagateForeground();
724void QQuickMaterialStyle::inheritForeground(uint foreground,
bool custom,
bool has)
726 if (m_explicitForeground || m_foreground == foreground)
729 m_hasForeground = has;
730 m_customForeground = custom;
731 m_foreground = foreground;
732 propagateForeground();
736void QQuickMaterialStyle::propagateForeground()
738 const auto styles = attachedChildren();
739 for (QQuickAttachedPropertyPropagator *child : styles) {
740 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(child);
742 material->inheritForeground(m_foreground, m_customForeground, m_hasForeground);
746void QQuickMaterialStyle::resetForeground()
748 if (!m_explicitForeground)
751 m_hasForeground =
false;
752 m_customForeground =
false;
753 m_explicitForeground =
false;
754 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(attachedParent());
755 inheritForeground(material ? material->m_foreground : globalForeground,
true, material ? material->m_hasForeground :
false);
758void QQuickMaterialStyle::foregroundChange()
760 emit foregroundChanged();
761 emit primaryHighlightedTextColorChanged();
764QVariant QQuickMaterialStyle::background()
const
766 return backgroundColor();
769void QQuickMaterialStyle::setBackground(
const QVariant &var)
773 if (!variantToRgba(var,
"background", &background, &custom))
778 if (!hasGlobalBackground) {
779 const QRgb themeDefault = (m_theme == Light ? backgroundColorLight : backgroundColorDark);
780 if (background == themeDefault) {
789 if (custom && background == primaryColor().rgb()) {
790 background = m_primary;
794 m_hasBackground =
true;
795 m_explicitBackground =
true;
796 if (m_background == background)
799 m_customBackground = custom;
800 m_background = background;
801 propagateBackground();
805 if (!m_customBackground && m_background == m_primary)
809void QQuickMaterialStyle::inheritBackground(uint background,
bool custom,
bool has)
811 if (m_explicitBackground || m_background == background)
814 m_hasBackground = has;
815 m_customBackground = custom;
816 m_background = background;
817 propagateBackground();
819 if (!m_customBackground && m_background == m_primary)
823void QQuickMaterialStyle::propagateBackground()
825 const auto styles = attachedChildren();
826 for (QQuickAttachedPropertyPropagator *child : styles) {
827 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(child);
829 material->inheritBackground(m_background, m_customBackground, m_hasBackground);
833void QQuickMaterialStyle::resetBackground()
835 if (!m_explicitBackground)
838 m_hasBackground =
false;
839 m_customBackground =
false;
840 m_explicitBackground =
false;
841 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(attachedParent());
842 inheritBackground(material ? material->m_background : globalBackground,
true, material ? material->m_hasBackground :
false);
845void QQuickMaterialStyle::backgroundChange()
847 emit backgroundChanged();
848 emit dialogColorChanged();
849 emit tooltipColorChanged();
850 emit toolBarColorChanged();
853int QQuickMaterialStyle::elevation()
const
858void QQuickMaterialStyle::setElevation(
int elevation)
860 if (m_elevation == elevation)
863 m_elevation = elevation;
867void QQuickMaterialStyle::resetElevation()
872void QQuickMaterialStyle::elevationChange()
874 emit elevationChanged();
877QQuickMaterialStyle::RoundedScale QQuickMaterialStyle::roundedScale()
const
879 return m_roundedScale;
882void QQuickMaterialStyle::setRoundedScale(RoundedScale roundedScale)
884 if (m_roundedScale == roundedScale)
887 m_roundedScale = roundedScale;
888 emit roundedScaleChanged();
891void QQuickMaterialStyle::resetRoundedScale()
893 setRoundedScale(RoundedScale::NotRounded);
896QQuickMaterialStyle::ContainerStyle QQuickMaterialStyle::containerStyle()
const
898 return m_containerStyle;
901void QQuickMaterialStyle::setContainerStyle(ContainerStyle containerStyle)
903 if (m_containerStyle == containerStyle)
906 m_containerStyle = containerStyle;
907 emit containerStyleChanged();
910void QQuickMaterialStyle::resetContainerStyle()
912 setContainerStyle(ContainerStyle::Filled);
915QColor QQuickMaterialStyle::primaryColor()
const
918 return QColor::fromRgba(m_primary);
919 if (m_primary > BlueGrey)
921 return colors[m_primary][Shade500];
924QColor QQuickMaterialStyle::accentColor(Shade shade)
const
927 return shade == themeShade() ? QColor::fromRgba(m_accent)
928 :
this->shade(QColor::fromRgba(m_accent), shade);
929 if (m_accent > BlueGrey)
931 return colors[m_accent][shade];
934QColor QQuickMaterialStyle::accentColor()
const
936 return accentColor(themeShade());
939QColor QQuickMaterialStyle::backgroundColor(Shade shade)
const
941 if (!m_hasBackground)
942 return QColor::fromRgba(m_theme == Light ? backgroundColorLight : backgroundColorDark);
945 if (m_customBackground || (m_customPrimary && m_background == m_primary))
946 return shade == themeShade() ? QColor::fromRgba(m_background)
947 :
this->shade(QColor::fromRgba(m_background), shade);
948 if (m_background > BlueGrey)
950 return colors[m_background][shade];
953QColor QQuickMaterialStyle::backgroundColor()
const
955 return backgroundColor(themeShade());
958QColor QQuickMaterialStyle::primaryTextColor()
const
960 return QColor::fromRgba(m_theme == Light ? primaryTextColorLight : primaryTextColorDark);
963QColor QQuickMaterialStyle::primaryHighlightedTextColor()
const
965 if (m_explicitForeground)
966 return primaryTextColor();
967 return QColor::fromRgba(primaryTextColorDark);
970QColor QQuickMaterialStyle::secondaryTextColor()
const
972 return QColor::fromRgba(m_theme == Light ? secondaryTextColorLight : secondaryTextColorDark);
975QColor QQuickMaterialStyle::hintTextColor()
const
977 return QColor::fromRgba(m_theme == Light ? hintTextColorLight : hintTextColorDark);
980QColor QQuickMaterialStyle::textSelectionColor()
const
982 QColor color = accentColor();
983 color.setAlphaF(0.4f);
987QColor QQuickMaterialStyle::dropShadowColor()
const
989 return QColor::fromRgba(0x40000000);
992QColor QQuickMaterialStyle::dividerColor()
const
994 return QColor::fromRgba(m_theme == Light ? dividerColorLight : dividerColorDark);
997QColor QQuickMaterialStyle::iconColor()
const
999 return QColor::fromRgba(m_theme == Light ? iconColorLight : iconColorDark);
1002QColor QQuickMaterialStyle::iconDisabledColor()
const
1004 return QColor::fromRgba(m_theme == Light ? iconDisabledColorLight : iconDisabledColorDark);
1007QColor QQuickMaterialStyle::buttonColor(Theme theme,
const QVariant &background,
const QVariant &accent,
1008 bool enabled,
bool flat,
bool highlighted,
bool checked)
const
1010 if (!enabled && !flat) {
1011 return QColor::fromRgba(m_theme == Light
1012 ? raisedButtonDisabledColorLight : raisedButtonDisabledColorDark);
1018 Shade shade = themeShade();
1020 Q_UNUSED(background);
1023 QColor color = Qt::transparent;
1025 if (m_explicitBackground) {
1026 color = backgroundColor(shade);
1027 }
else if (highlighted) {
1028 if (m_theme == Light) {
1029 color = accentColor(shade);
1031 color = color.lighter();
1034 color = accentColor(checked ? Shade100 : shade);
1039 color.setAlphaF(0.25);
1042 color = QColor::fromRgba(m_theme == Light ? raisedButtonColorLight
1043 : raisedButtonColorDark);
1049QColor QQuickMaterialStyle::frameColor()
const
1051 return QColor::fromRgba(m_theme == Light ? frameColorLight : frameColorDark);
1054QColor QQuickMaterialStyle::rippleColor()
const
1056 return QColor::fromRgba(m_theme == Light ? rippleColorLight : rippleColorDark);
1059QColor QQuickMaterialStyle::highlightedRippleColor()
const
1061 QColor pressColor = accentColor();
1062 pressColor.setAlpha(m_theme == Light ? 30 : 50);
1066QColor QQuickMaterialStyle::switchUncheckedTrackColor()
const
1068 return QColor::fromRgba(m_theme == Light ? switchUncheckedTrackColorLight : switchUncheckedTrackColorDark);
1071QColor QQuickMaterialStyle::switchCheckedTrackColor()
const
1073 return accentColor(m_theme == Light ? themeShade() : Shade100);
1076QColor QQuickMaterialStyle::switchDisabledUncheckedTrackColor()
const
1078 return QColor::fromRgba(m_theme == Light
1079 ? switchDisabledUncheckedTrackColorLight : switchDisabledUncheckedTrackColorDark);
1082QColor QQuickMaterialStyle::switchDisabledCheckedTrackColor()
const
1084 return QColor::fromRgba(m_theme == Light
1085 ? switchDisabledCheckedTrackColorLight : switchDisabledCheckedTrackColorDark);
1088QColor QQuickMaterialStyle::switchDisabledUncheckedTrackBorderColor()
const
1090 return QColor::fromRgba(m_theme == Light
1091 ? switchDisabledUncheckedTrackBorderColorLight : switchDisabledUncheckedTrackBorderColorDark);
1094QColor QQuickMaterialStyle::switchUncheckedHandleColor()
const
1096 return m_theme == Light ? color(Grey, Shade600) : color(Grey, Shade400);
1099QColor QQuickMaterialStyle::switchUncheckedHoveredHandleColor()
const
1101 const QColor color = switchUncheckedHandleColor();
1102 return m_theme == Light ? color.darker(140) : color.lighter(120);
1105QColor QQuickMaterialStyle::switchCheckedHandleColor()
const
1107 return m_theme == Light ? QColor::fromRgb(0xFFFFFF) : accentColor(Shade800);
1110QColor QQuickMaterialStyle::switchDisabledUncheckedHandleColor()
const
1112 if (m_theme == Light)
1113 return QColor::fromRgba(0x611C1B1F);
1115 QColor darkHandleColor = color(Grey, Shade800);
1116 darkHandleColor.setAlphaF(0.38f);
1117 return darkHandleColor;
1120QColor QQuickMaterialStyle::switchDisabledCheckedHandleColor()
const
1122 return QColor::fromRgb(m_theme == Light ? 0xFFFBFE : 0x1C1B1F);
1125QColor QQuickMaterialStyle::switchDisabledCheckedIconColor()
const
1127 return QColor::fromRgba(m_theme == Light ? 0x611C1B1F : 0x61E6E1E5);
1130QColor QQuickMaterialStyle::switchDisabledUncheckedIconColor()
const
1132 return QColor::fromRgba(m_theme == Light
1133 ? switchDisabledUncheckedIconColorLight : switchDisabledUncheckedIconColorDark);
1136QColor QQuickMaterialStyle::scrollBarColor()
const
1138 return QColor::fromRgba(m_theme == Light ? 0x40000000 : 0x40FFFFFF);
1141QColor QQuickMaterialStyle::scrollBarHoveredColor()
const
1143 return QColor::fromRgba(m_theme == Light ? 0x60000000 : 0x60FFFFFF);
1146QColor QQuickMaterialStyle::scrollBarPressedColor()
const
1148 return QColor::fromRgba(m_theme == Light ? 0x80000000 : 0x80FFFFFF);
1151QColor QQuickMaterialStyle::dialogColor()
const
1153 if (m_hasBackground)
1154 return backgroundColor();
1155 return QColor::fromRgba(m_theme == Light ? dialogColorLight : dialogColorDark);
1158QColor QQuickMaterialStyle::backgroundDimColor()
const
1160 return QColor::fromRgba(m_theme == Light ? 0x99303030 : 0x99fafafa);
1163QColor QQuickMaterialStyle::listHighlightColor()
const
1165 return QColor::fromRgba(m_theme == Light ? 0x1e000000 : 0x1effffff);
1168QColor QQuickMaterialStyle::tooltipColor()
const
1170 if (m_explicitBackground)
1171 return backgroundColor();
1172 return color(Grey, Shade700);
1175QColor QQuickMaterialStyle::toolBarColor()
const
1177 if (m_explicitBackground)
1178 return backgroundColor();
1179 return primaryColor();
1182QColor QQuickMaterialStyle::toolTextColor()
const
1184 if (m_hasForeground || m_customPrimary)
1185 return primaryTextColor();
1187 switch (m_primary) {
1198 return QColor::fromRgba(primaryTextColorDark);
1209 return QColor::fromRgba(primaryTextColorLight);
1215 return primaryTextColor();
1218QColor QQuickMaterialStyle::spinBoxDisabledIconColor()
const
1220 return QColor::fromRgba(m_theme == Light ? spinBoxDisabledIconColorLight : spinBoxDisabledIconColorDark);
1223QColor QQuickMaterialStyle::sliderDisabledColor()
const
1225 return QColor::fromRgba(m_theme == Light ? sliderDisabledColorLight : sliderDisabledColorDark);
1228QColor QQuickMaterialStyle::textFieldFilledContainerColor()
const
1230 return QColor::fromRgba(m_theme == Light ? textFieldFilledContainerColorLight : textFieldFilledContainerColorDark);
1233QColor QQuickMaterialStyle::color(QQuickMaterialStyle::Color color, QQuickMaterialStyle::Shade shade)
const
1235 int count =
sizeof(colors) /
sizeof(colors[0]);
1236 if (color < 0 || color >= count)
1239 count =
sizeof(colors[0]) /
sizeof(colors[0][0]);
1240 if (shade < 0 || shade >= count)
1243 return colors[color][shade];
1248 QColor hsl = color.toHsl();
1249 hsl.setHslF(hsl.hueF(), hsl.saturationF(),
1250 std::clamp(hsl.lightnessF() + amount, qreal(0.0), qreal(1.0)), color.alphaF());
1251 return hsl.convertTo(color.spec());
1256 QColor hsl = color.toHsl();
1257 hsl.setHslF(hsl.hueF(), hsl.saturationF(),
1258 std::clamp(hsl.lightnessF() - amount, qreal(0.0), qreal(1.0)), color.alphaF());
1259 return hsl.convertTo(color.spec());
1262QQuickMaterialStyle::Shade QQuickMaterialStyle::themeShade()
const
1264 return m_theme == Light ? Shade500 : Shade200;
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1294QColor QQuickMaterialStyle::shade(
const QColor &color, Shade shade)
const
1298 return lighterShade(color, m_theme == Light ? 0.52 : 0.26);
1300 return lighterShade(color, m_theme == Light ? 0.37 : 0.11);
1302 return m_theme == Light ? lighterShade(color, 0.26) : color;
1304 return m_theme == Light ? lighterShade(color, 0.12) : darkerShade(color, 0.14);
1306 return m_theme == Light ? lighterShade(color, 0.06) : darkerShade(color, 0.20);
1308 return m_theme == Light ? color : darkerShade(color, 0.26);
1310 return darkerShade(color, m_theme == Light ? 0.06 : 0.32);
1312 return darkerShade(color, m_theme == Light ? 0.12 : 0.38);
1314 return darkerShade(color, m_theme == Light ? 0.18 : 0.44);
1316 return darkerShade(color, m_theme == Light ? 0.24 : 0.50);
1318 return lighterShade(color, m_theme == Light ? 0.54 : 0.28);
1320 return lighterShade(color, m_theme == Light ? 0.37 : 0.11);
1322 return m_theme == Light ? lighterShade(color, 0.06) : darkerShade(color, 0.20);
1324 return darkerShade(color, m_theme == Light ? 0.12 : 0.38);
1326 Q_UNREACHABLE_RETURN(QColor());
1330int QQuickMaterialStyle::touchTarget()
const
1333 return globalVariant == Dense ? 44 : 48;
1336int QQuickMaterialStyle::buttonVerticalPadding()
const
1338 return globalVariant == Dense ? 10 : 14;
1342int QQuickMaterialStyle::buttonLeftPadding(
bool flat,
bool hasIcon)
const
1344 static const int noIconPadding = globalVariant == Dense ? 12 : 24;
1345 static const int iconPadding = globalVariant == Dense ? 8 : 16;
1346 static const int flatPadding = globalVariant == Dense ? 6 : 12;
1347 return !flat ? (!hasIcon ? noIconPadding : iconPadding) : flatPadding;
1350int QQuickMaterialStyle::buttonRightPadding(
bool flat,
bool hasIcon,
bool hasText)
const
1352 static const int noTextPadding = globalVariant == Dense ? 8 : 16;
1353 static const int textPadding = globalVariant == Dense ? 12 : 24;
1354 static const int flatNoIconPadding = globalVariant == Dense ? 6 : 12;
1355 static const int flatNoTextPadding = globalVariant == Dense ? 6 : 12;
1356 static const int flatTextPadding = globalVariant == Dense ? 8 : 16;
1358 ? (!hasText ? noTextPadding : textPadding)
1359 : (!hasIcon ? flatNoIconPadding : (!hasText ? flatNoTextPadding : flatTextPadding));
1362int QQuickMaterialStyle::buttonHeight()
const
1365 return globalVariant == Dense ? 32 : 40;
1368int QQuickMaterialStyle::delegateHeight()
const
1371 return globalVariant == Dense ? 40 : 48;
1374int QQuickMaterialStyle::dialogButtonBoxHeight()
const
1376 return globalVariant == Dense ? 48 : 52;
1379int QQuickMaterialStyle::dialogTitleFontPixelSize()
const
1381 return globalVariant == Dense ? 16 : 24;
1385QQuickMaterialStyle::RoundedScale QQuickMaterialStyle::dialogRoundedScale()
const
1387 return globalVariant == Dense
1388 ? QQuickMaterialStyle::RoundedScale::LargeScale
1389 : QQuickMaterialStyle::RoundedScale::ExtraLargeScale;
1392int QQuickMaterialStyle::frameVerticalPadding()
const
1394 return globalVariant == Dense ? 8 : 12;
1397int QQuickMaterialStyle::menuItemHeight()
const
1400 return globalVariant == Dense ? 32 : 48;
1403int QQuickMaterialStyle::menuItemVerticalPadding()
const
1405 return globalVariant == Dense ? 8 : 12;
1408int QQuickMaterialStyle::switchIndicatorWidth()
const
1410 return globalVariant == Dense ? 40 : 52;
1413int QQuickMaterialStyle::switchIndicatorHeight()
const
1415 return globalVariant == Dense ? 22 : 32;
1418int QQuickMaterialStyle::switchNormalHandleHeight()
const
1420 return globalVariant == Dense ? 10 : 16;
1423int QQuickMaterialStyle::switchCheckedHandleHeight()
const
1425 return globalVariant == Dense ? 16 : 24;
1428int QQuickMaterialStyle::switchLargestHandleHeight()
const
1430 return globalVariant == Dense ? 18 : 28;
1433int QQuickMaterialStyle::switchDelegateVerticalPadding()
const
1437 return globalVariant == Dense ? 4 : 8;
1440int QQuickMaterialStyle::textFieldHeight()
const
1444 return globalVariant == Dense ? 44 : 56;
1446int QQuickMaterialStyle::textFieldHorizontalPadding()
const
1448 return globalVariant == Dense ? 12 : 16;
1450int QQuickMaterialStyle::textFieldVerticalPadding()
const
1452 return globalVariant == Dense ? 4 : 8;
1455int QQuickMaterialStyle::tooltipHeight()
const
1458 return globalVariant == Dense ? 22 : 32;
1461QQuickMaterialStyle::Variant QQuickMaterialStyle::variant()
1463 return globalVariant;
1466template <
typename Enum>
1469 QMetaEnum enumeration = QMetaEnum::fromType<Enum>();
1470 return static_cast<Enum>(enumeration.keyToValue(value, ok));
1475 QByteArray value = qgetenv(env);
1476#if QT_CONFIG(settings)
1477 if (value.isNull() && !settings.isNull())
1478 value = settings->value(name).toByteArray();
1483void QQuickMaterialStyle::initGlobals()
1485 QSharedPointer<QSettings> settings = QQuickStylePrivate::settings(QStringLiteral(
"Material"));
1488 QByteArray themeValue = resolveSetting(
"QT_QUICK_CONTROLS_MATERIAL_THEME", settings, QStringLiteral(
"Theme"));
1489 Theme themeEnum = toEnumValue<Theme>(themeValue, &ok);
1491 globalTheme = themeEnum;
1492 else if (!themeValue.isEmpty())
1493 qWarning().nospace().noquote() <<
"Material: unknown theme value: " << themeValue;
1495 QByteArray variantValue = resolveSetting(
"QT_QUICK_CONTROLS_MATERIAL_VARIANT", settings, QStringLiteral(
"Variant"));
1496 Variant variantEnum = toEnumValue<Variant>(variantValue, &ok);
1498 globalVariant = variantEnum;
1499 else if (!variantValue.isEmpty())
1500 qWarning().nospace().noquote() <<
"Material: unknown variant value: " << variantValue;
1502 QByteArray primaryValue = resolveSetting(
"QT_QUICK_CONTROLS_MATERIAL_PRIMARY", settings, QStringLiteral(
"Primary"));
1503 Color primaryEnum = toEnumValue<Color>(primaryValue, &ok);
1505 globalPrimaryCustom =
false;
1506 globalPrimary = primaryEnum;
1508 QColor color = QColor::fromString(primaryValue);
1509 if (color.isValid()) {
1510 globalPrimaryCustom =
true;
1511 globalPrimary = color.rgba();
1512 }
else if (!primaryValue.isEmpty()) {
1513 qWarning().nospace().noquote() <<
"Material: unknown primary value: " << primaryValue;
1517 QByteArray accentValue = resolveSetting(
"QT_QUICK_CONTROLS_MATERIAL_ACCENT", settings, QStringLiteral(
"Accent"));
1518 Color accentEnum = toEnumValue<Color>(accentValue, &ok);
1520 globalAccentCustom =
false;
1521 globalAccent = accentEnum;
1522 }
else if (!accentValue.isEmpty()) {
1523 QColor color = QColor::fromString(accentValue);
1524 if (color.isValid()) {
1525 globalAccentCustom =
true;
1526 globalAccent = color.rgba();
1528 qWarning().nospace().noquote() <<
"Material: unknown accent value: " << accentValue;
1532 QByteArray foregroundValue = resolveSetting(
"QT_QUICK_CONTROLS_MATERIAL_FOREGROUND", settings, QStringLiteral(
"Foreground"));
1533 Color foregroundEnum = toEnumValue<Color>(foregroundValue, &ok);
1535 globalForegroundCustom =
false;
1536 globalForeground = foregroundEnum;
1537 hasGlobalForeground =
true;
1538 }
else if (!foregroundValue.isEmpty()) {
1539 QColor color = QColor::fromString(foregroundValue);
1540 if (color.isValid()) {
1541 globalForegroundCustom =
true;
1542 globalForeground = color.rgba();
1543 hasGlobalForeground =
true;
1545 qWarning().nospace().noquote() <<
"Material: unknown foreground value: " << foregroundValue;
1549 QByteArray backgroundValue = resolveSetting(
"QT_QUICK_CONTROLS_MATERIAL_BACKGROUND", settings, QStringLiteral(
"Background"));
1550 Color backgroundEnum = toEnumValue<Color>(backgroundValue, &ok);
1552 globalBackgroundCustom =
false;
1553 globalBackground = backgroundEnum;
1554 hasGlobalBackground =
true;
1555 }
else if (!backgroundValue.isEmpty()) {
1556 QColor color = QColor::fromString(backgroundValue);
1557 if (color.isValid()) {
1558 globalBackgroundCustom =
true;
1559 globalBackground = color.rgba();
1560 hasGlobalBackground =
true;
1562 qWarning().nospace().noquote() <<
"Material: unknown background value: " << backgroundValue;
1567void QQuickMaterialStyle::attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent)
1569 Q_UNUSED(oldParent);
1570 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(newParent);
1572 inheritPrimary(material->m_primary, material->m_customPrimary);
1573 inheritAccent(material->m_accent, material->m_customAccent);
1574 inheritForeground(material->m_foreground, material->m_customForeground, material->m_hasForeground);
1575 inheritBackground(material->m_background, material->m_customBackground, material->m_hasBackground);
1576 inheritTheme(material->theme());
1580bool QQuickMaterialStyle::variantToRgba(
const QVariant &var,
const char *name, QRgb *rgba,
bool *custom)
const
1583 if (var.metaType().id() == QMetaType::Int) {
1584 int val = var.toInt();
1585 if (val > BlueGrey) {
1586 qmlWarning(parent()) <<
"unknown Material." << name <<
" value: " << val;
1591 int val = QMetaEnum::fromType<Color>().keyToValue(var.toByteArray());
1595 QColor color = QColor::fromString(var.toString());
1596 if (!color.isValid()) {
1597 qmlWarning(parent()) <<
"unknown Material." << name <<
" value: " << var.toString();
1601 *rgba = color.rgba();
1609#include "moc_qquickmaterialstyle_p.cpp"
static const QRgb raisedButtonColorLight
static const QRgb spinBoxDisabledIconColorLight
static const QRgb textFieldFilledContainerColorDark
static bool globalBackgroundCustom
static QQuickMaterialStyle::Theme effectiveTheme(QQuickMaterialStyle::Theme theme)
static const QRgb rippleColorLight
static const QRgb dividerColorLight
static const QRgb switchDisabledUncheckedTrackBorderColorLight
static const QRgb frameColorLight
static QByteArray resolveSetting(const QByteArray &env, const QSharedPointer< QSettings > &settings, const QString &name)
static const QRgb switchDisabledCheckedTrackColorLight
static Enum toEnumValue(const QByteArray &value, bool *ok)
static const QRgb spinBoxDisabledIconColorDark
static const QRgb sliderDisabledColorDark
static const QRgb primaryTextColorLight
static const QRgb raisedButtonColorDark
static const QRgb iconColorDark
static const QRgb switchDisabledUncheckedIconColorLight
static QColor darkerShade(const QColor &color, qreal amount)
static const QRgb textFieldFilledContainerColorLight
static const QRgb rippleColorDark
static const QRgb switchDisabledCheckedTrackColorDark
static const QRgb switchDisabledUncheckedIconColorDark
static bool globalForegroundCustom
static const QRgb dialogColorDark
static QQuickMaterialStyle::Variant globalVariant
static const QRgb sliderDisabledColorLight
static const QRgb backgroundColorLight
static const QRgb secondaryTextColorLight
static const QRgb switchDisabledUncheckedTrackColorLight
static const QRgb iconColorLight
static const QRgb secondaryTextColorDark
static uint globalBackground
static const QRgb switchDisabledUncheckedTrackColorDark
static const QRgb hintTextColorDark
static const QRgb raisedButtonDisabledColorDark
static const QRgb iconDisabledColorLight
static bool globalPrimaryCustom
static bool hasGlobalBackground
static bool globalAccentCustom
static QColor lighterShade(const QColor &color, qreal amount)
static const QRgb dividerColorDark
static const QRgb switchUncheckedTrackColorLight
static const QRgb dialogColorLight
static const QRgb hintTextColorLight
static uint globalPrimary
static const QRgb iconDisabledColorDark
static const QRgb raisedButtonDisabledColorLight
static const QRgb switchUncheckedTrackColorDark
static bool hasGlobalForeground
static const QRgb backgroundColorDark
static QQuickMaterialStyle::Theme globalTheme
static uint globalForeground
static const QRgb switchDisabledUncheckedTrackBorderColorDark
static const QRgb primaryTextColorDark
static const QRgb frameColorDark