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_explicitForeground =
true;
714 if (m_hasForeground && m_foreground == foreground)
717 m_hasForeground =
true;
718 m_customForeground = custom;
719 m_foreground = foreground;
720 propagateForeground();
724void QQuickMaterialStyle::inheritForeground(uint foreground,
bool custom,
bool has)
726 if (m_explicitForeground || (m_hasForeground == has && 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_explicitForeground =
false;
752 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(attachedParent());
753 inheritForeground(material ? material->m_foreground : globalForeground,
754 material ? material->m_customForeground : globalForegroundCustom,
755 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_explicitBackground =
true;
795 if (m_hasBackground && m_background == background)
797 m_hasBackground =
true;
798 m_customBackground = custom;
799 m_background = background;
800 propagateBackground();
804 if (!m_customBackground && m_background == m_primary)
808void QQuickMaterialStyle::inheritBackground(uint background,
bool custom,
bool has)
810 if (m_explicitBackground || (m_hasBackground == has && m_background == background))
813 m_hasBackground = has;
814 m_customBackground = custom;
815 m_background = background;
816 propagateBackground();
818 if (!m_customBackground && m_background == m_primary)
822void QQuickMaterialStyle::propagateBackground()
824 const auto styles = attachedChildren();
825 for (QQuickAttachedPropertyPropagator *child : styles) {
826 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(child);
828 material->inheritBackground(m_background, m_customBackground, m_hasBackground);
832void QQuickMaterialStyle::resetBackground()
834 if (!m_explicitBackground)
837 m_explicitBackground =
false;
838 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(attachedParent());
839 inheritBackground(material ? material->m_background : globalBackground,
840 material ? material->m_customBackground : globalBackgroundCustom,
841 material ? material->m_hasBackground :
false);
844void QQuickMaterialStyle::backgroundChange()
846 emit backgroundChanged();
847 emit dialogColorChanged();
848 emit tooltipColorChanged();
849 emit toolBarColorChanged();
852int QQuickMaterialStyle::elevation()
const
857void QQuickMaterialStyle::setElevation(
int elevation)
859 if (m_elevation == elevation)
862 m_elevation = elevation;
866void QQuickMaterialStyle::resetElevation()
871void QQuickMaterialStyle::elevationChange()
873 emit elevationChanged();
876QQuickMaterialStyle::RoundedScale QQuickMaterialStyle::roundedScale()
const
878 return m_roundedScale;
881void QQuickMaterialStyle::setRoundedScale(RoundedScale roundedScale)
883 if (m_roundedScale == roundedScale)
886 m_roundedScale = roundedScale;
887 emit roundedScaleChanged();
890void QQuickMaterialStyle::resetRoundedScale()
892 setRoundedScale(RoundedScale::NotRounded);
895QQuickMaterialStyle::ContainerStyle QQuickMaterialStyle::containerStyle()
const
897 return m_containerStyle;
900void QQuickMaterialStyle::setContainerStyle(ContainerStyle containerStyle)
902 if (m_containerStyle == containerStyle)
905 m_containerStyle = containerStyle;
906 emit containerStyleChanged();
909void QQuickMaterialStyle::resetContainerStyle()
911 setContainerStyle(ContainerStyle::Filled);
914QColor QQuickMaterialStyle::primaryColor()
const
917 return QColor::fromRgba(m_primary);
918 if (m_primary > BlueGrey)
920 return colors[m_primary][Shade500];
923QColor QQuickMaterialStyle::accentColor(Shade shade)
const
926 return shade == themeShade() ? QColor::fromRgba(m_accent)
927 :
this->shade(QColor::fromRgba(m_accent), shade);
928 if (m_accent > BlueGrey)
930 return colors[m_accent][shade];
933QColor QQuickMaterialStyle::accentColor()
const
935 return accentColor(themeShade());
938QColor QQuickMaterialStyle::backgroundColor(Shade shade)
const
940 if (!m_hasBackground)
941 return QColor::fromRgba(m_theme == Light ? backgroundColorLight : backgroundColorDark);
944 if (m_customBackground || (m_customPrimary && m_background == m_primary))
945 return shade == themeShade() ? QColor::fromRgba(m_background)
946 :
this->shade(QColor::fromRgba(m_background), shade);
947 if (m_background > BlueGrey)
949 return colors[m_background][shade];
952QColor QQuickMaterialStyle::backgroundColor()
const
954 return backgroundColor(themeShade());
957QColor QQuickMaterialStyle::primaryTextColor()
const
959 return QColor::fromRgba(m_theme == Light ? primaryTextColorLight : primaryTextColorDark);
962QColor QQuickMaterialStyle::primaryHighlightedTextColor()
const
964 if (m_explicitForeground)
965 return primaryTextColor();
966 return QColor::fromRgba(primaryTextColorDark);
969QColor QQuickMaterialStyle::secondaryTextColor()
const
971 return QColor::fromRgba(m_theme == Light ? secondaryTextColorLight : secondaryTextColorDark);
974QColor QQuickMaterialStyle::hintTextColor()
const
976 return QColor::fromRgba(m_theme == Light ? hintTextColorLight : hintTextColorDark);
979QColor QQuickMaterialStyle::textSelectionColor()
const
981 QColor color = accentColor();
982 color.setAlphaF(0.4f);
986QColor QQuickMaterialStyle::dropShadowColor()
const
988 return QColor::fromRgba(0x40000000);
991QColor QQuickMaterialStyle::dividerColor()
const
993 return QColor::fromRgba(m_theme == Light ? dividerColorLight : dividerColorDark);
996QColor QQuickMaterialStyle::iconColor()
const
998 return QColor::fromRgba(m_theme == Light ? iconColorLight : iconColorDark);
1001QColor QQuickMaterialStyle::iconDisabledColor()
const
1003 return QColor::fromRgba(m_theme == Light ? iconDisabledColorLight : iconDisabledColorDark);
1006QColor QQuickMaterialStyle::buttonColor(Theme theme,
const QVariant &background,
const QVariant &accent,
1007 bool enabled,
bool flat,
bool highlighted,
bool checked)
const
1009 if (!enabled && !flat) {
1010 return QColor::fromRgba(m_theme == Light
1011 ? raisedButtonDisabledColorLight : raisedButtonDisabledColorDark);
1017 Shade shade = themeShade();
1019 Q_UNUSED(background);
1022 QColor color = Qt::transparent;
1024 if (m_explicitBackground) {
1025 color = backgroundColor(shade);
1026 }
else if (highlighted) {
1027 if (m_theme == Light) {
1028 color = accentColor(shade);
1030 color = color.lighter();
1033 color = accentColor(checked ? Shade100 : shade);
1038 color.setAlphaF(0.25);
1041 color = QColor::fromRgba(m_theme == Light ? raisedButtonColorLight
1042 : raisedButtonColorDark);
1048QColor QQuickMaterialStyle::frameColor()
const
1050 return QColor::fromRgba(m_theme == Light ? frameColorLight : frameColorDark);
1053QColor QQuickMaterialStyle::rippleColor()
const
1055 return QColor::fromRgba(m_theme == Light ? rippleColorLight : rippleColorDark);
1058QColor QQuickMaterialStyle::highlightedRippleColor()
const
1060 QColor pressColor = accentColor();
1061 pressColor.setAlpha(m_theme == Light ? 30 : 50);
1065QColor QQuickMaterialStyle::switchUncheckedTrackColor()
const
1067 return QColor::fromRgba(m_theme == Light ? switchUncheckedTrackColorLight : switchUncheckedTrackColorDark);
1070QColor QQuickMaterialStyle::switchCheckedTrackColor()
const
1072 return accentColor(m_theme == Light ? themeShade() : Shade100);
1075QColor QQuickMaterialStyle::switchDisabledUncheckedTrackColor()
const
1077 return QColor::fromRgba(m_theme == Light
1078 ? switchDisabledUncheckedTrackColorLight : switchDisabledUncheckedTrackColorDark);
1081QColor QQuickMaterialStyle::switchDisabledCheckedTrackColor()
const
1083 return QColor::fromRgba(m_theme == Light
1084 ? switchDisabledCheckedTrackColorLight : switchDisabledCheckedTrackColorDark);
1087QColor QQuickMaterialStyle::switchDisabledUncheckedTrackBorderColor()
const
1089 return QColor::fromRgba(m_theme == Light
1090 ? switchDisabledUncheckedTrackBorderColorLight : switchDisabledUncheckedTrackBorderColorDark);
1093QColor QQuickMaterialStyle::switchUncheckedHandleColor()
const
1095 return m_theme == Light ? color(Grey, Shade600) : color(Grey, Shade400);
1098QColor QQuickMaterialStyle::switchUncheckedHoveredHandleColor()
const
1100 const QColor color = switchUncheckedHandleColor();
1101 return m_theme == Light ? color.darker(140) : color.lighter(120);
1104QColor QQuickMaterialStyle::switchCheckedHandleColor()
const
1106 return m_theme == Light ? QColor::fromRgb(0xFFFFFF) : accentColor(Shade800);
1109QColor QQuickMaterialStyle::switchDisabledUncheckedHandleColor()
const
1111 if (m_theme == Light)
1112 return QColor::fromRgba(0x611C1B1F);
1114 QColor darkHandleColor = color(Grey, Shade800);
1115 darkHandleColor.setAlphaF(0.38f);
1116 return darkHandleColor;
1119QColor QQuickMaterialStyle::switchDisabledCheckedHandleColor()
const
1121 return QColor::fromRgb(m_theme == Light ? 0xFFFBFE : 0x1C1B1F);
1124QColor QQuickMaterialStyle::switchDisabledCheckedIconColor()
const
1126 return QColor::fromRgba(m_theme == Light ? 0x611C1B1F : 0x61E6E1E5);
1129QColor QQuickMaterialStyle::switchDisabledUncheckedIconColor()
const
1131 return QColor::fromRgba(m_theme == Light
1132 ? switchDisabledUncheckedIconColorLight : switchDisabledUncheckedIconColorDark);
1135QColor QQuickMaterialStyle::scrollBarColor()
const
1137 return QColor::fromRgba(m_theme == Light ? 0x40000000 : 0x40FFFFFF);
1140QColor QQuickMaterialStyle::scrollBarHoveredColor()
const
1142 return QColor::fromRgba(m_theme == Light ? 0x60000000 : 0x60FFFFFF);
1145QColor QQuickMaterialStyle::scrollBarPressedColor()
const
1147 return QColor::fromRgba(m_theme == Light ? 0x80000000 : 0x80FFFFFF);
1150QColor QQuickMaterialStyle::dialogColor()
const
1152 if (m_hasBackground)
1153 return backgroundColor();
1154 return QColor::fromRgba(m_theme == Light ? dialogColorLight : dialogColorDark);
1157QColor QQuickMaterialStyle::backgroundDimColor()
const
1159 return QColor::fromRgba(m_theme == Light ? 0x99303030 : 0x99fafafa);
1162QColor QQuickMaterialStyle::listHighlightColor()
const
1164 return QColor::fromRgba(m_theme == Light ? 0x1e000000 : 0x1effffff);
1167QColor QQuickMaterialStyle::tooltipColor()
const
1169 if (m_explicitBackground)
1170 return backgroundColor();
1171 return color(Grey, Shade700);
1174QColor QQuickMaterialStyle::toolBarColor()
const
1176 if (m_explicitBackground)
1177 return backgroundColor();
1178 return primaryColor();
1181QColor QQuickMaterialStyle::toolTextColor()
const
1183 if (m_hasForeground || m_customPrimary)
1184 return primaryTextColor();
1186 switch (m_primary) {
1197 return QColor::fromRgba(primaryTextColorDark);
1208 return QColor::fromRgba(primaryTextColorLight);
1214 return primaryTextColor();
1217QColor QQuickMaterialStyle::spinBoxDisabledIconColor()
const
1219 return QColor::fromRgba(m_theme == Light ? spinBoxDisabledIconColorLight : spinBoxDisabledIconColorDark);
1222QColor QQuickMaterialStyle::sliderDisabledColor()
const
1224 return QColor::fromRgba(m_theme == Light ? sliderDisabledColorLight : sliderDisabledColorDark);
1227QColor QQuickMaterialStyle::textFieldFilledContainerColor()
const
1229 return QColor::fromRgba(m_theme == Light ? textFieldFilledContainerColorLight : textFieldFilledContainerColorDark);
1232QColor QQuickMaterialStyle::color(QQuickMaterialStyle::Color color, QQuickMaterialStyle::Shade shade)
const
1234 int count =
sizeof(colors) /
sizeof(colors[0]);
1235 if (color < 0 || color >= count)
1238 count =
sizeof(colors[0]) /
sizeof(colors[0][0]);
1239 if (shade < 0 || shade >= count)
1242 return colors[color][shade];
1247 QColor hsl = color.toHsl();
1248 hsl.setHslF(hsl.hueF(), hsl.saturationF(),
1249 std::clamp(hsl.lightnessF() + amount, qreal(0.0), qreal(1.0)), color.alphaF());
1250 return hsl.convertTo(color.spec());
1255 QColor hsl = color.toHsl();
1256 hsl.setHslF(hsl.hueF(), hsl.saturationF(),
1257 std::clamp(hsl.lightnessF() - amount, qreal(0.0), qreal(1.0)), color.alphaF());
1258 return hsl.convertTo(color.spec());
1261QQuickMaterialStyle::Shade QQuickMaterialStyle::themeShade()
const
1263 return m_theme == Light ? Shade500 : Shade200;
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1293QColor QQuickMaterialStyle::shade(
const QColor &color, Shade shade)
const
1297 return lighterShade(color, m_theme == Light ? 0.52 : 0.26);
1299 return lighterShade(color, m_theme == Light ? 0.37 : 0.11);
1301 return m_theme == Light ? lighterShade(color, 0.26) : color;
1303 return m_theme == Light ? lighterShade(color, 0.12) : darkerShade(color, 0.14);
1305 return m_theme == Light ? lighterShade(color, 0.06) : darkerShade(color, 0.20);
1307 return m_theme == Light ? color : darkerShade(color, 0.26);
1309 return darkerShade(color, m_theme == Light ? 0.06 : 0.32);
1311 return darkerShade(color, m_theme == Light ? 0.12 : 0.38);
1313 return darkerShade(color, m_theme == Light ? 0.18 : 0.44);
1315 return darkerShade(color, m_theme == Light ? 0.24 : 0.50);
1317 return lighterShade(color, m_theme == Light ? 0.54 : 0.28);
1319 return lighterShade(color, m_theme == Light ? 0.37 : 0.11);
1321 return m_theme == Light ? lighterShade(color, 0.06) : darkerShade(color, 0.20);
1323 return darkerShade(color, m_theme == Light ? 0.12 : 0.38);
1325 Q_UNREACHABLE_RETURN(QColor());
1329int QQuickMaterialStyle::touchTarget()
const
1332 return globalVariant == Dense ? 44 : 48;
1335int QQuickMaterialStyle::buttonVerticalPadding()
const
1337 return globalVariant == Dense ? 10 : 14;
1341int QQuickMaterialStyle::buttonLeftPadding(
bool flat,
bool hasIcon)
const
1343 static const int noIconPadding = globalVariant == Dense ? 12 : 24;
1344 static const int iconPadding = globalVariant == Dense ? 8 : 16;
1345 static const int flatPadding = globalVariant == Dense ? 6 : 12;
1346 return !flat ? (!hasIcon ? noIconPadding : iconPadding) : flatPadding;
1349int QQuickMaterialStyle::buttonRightPadding(
bool flat,
bool hasIcon,
bool hasText)
const
1351 static const int noTextPadding = globalVariant == Dense ? 8 : 16;
1352 static const int textPadding = globalVariant == Dense ? 12 : 24;
1353 static const int flatNoIconPadding = globalVariant == Dense ? 6 : 12;
1354 static const int flatNoTextPadding = globalVariant == Dense ? 6 : 12;
1355 static const int flatTextPadding = globalVariant == Dense ? 8 : 16;
1357 ? (!hasText ? noTextPadding : textPadding)
1358 : (!hasIcon ? flatNoIconPadding : (!hasText ? flatNoTextPadding : flatTextPadding));
1361int QQuickMaterialStyle::buttonHeight()
const
1364 return globalVariant == Dense ? 32 : 40;
1367int QQuickMaterialStyle::delegateHeight()
const
1370 return globalVariant == Dense ? 40 : 48;
1373int QQuickMaterialStyle::dialogButtonBoxHeight()
const
1375 return globalVariant == Dense ? 48 : 52;
1378int QQuickMaterialStyle::dialogTitleFontPixelSize()
const
1380 return globalVariant == Dense ? 16 : 24;
1384QQuickMaterialStyle::RoundedScale QQuickMaterialStyle::dialogRoundedScale()
const
1386 return globalVariant == Dense
1387 ? QQuickMaterialStyle::RoundedScale::LargeScale
1388 : QQuickMaterialStyle::RoundedScale::ExtraLargeScale;
1391int QQuickMaterialStyle::frameVerticalPadding()
const
1393 return globalVariant == Dense ? 8 : 12;
1396int QQuickMaterialStyle::menuItemHeight()
const
1399 return globalVariant == Dense ? 32 : 48;
1402int QQuickMaterialStyle::menuItemVerticalPadding()
const
1404 return globalVariant == Dense ? 8 : 12;
1407int QQuickMaterialStyle::switchIndicatorWidth()
const
1409 return globalVariant == Dense ? 40 : 52;
1412int QQuickMaterialStyle::switchIndicatorHeight()
const
1414 return globalVariant == Dense ? 22 : 32;
1417int QQuickMaterialStyle::switchNormalHandleHeight()
const
1419 return globalVariant == Dense ? 10 : 16;
1422int QQuickMaterialStyle::switchCheckedHandleHeight()
const
1424 return globalVariant == Dense ? 16 : 24;
1427int QQuickMaterialStyle::switchLargestHandleHeight()
const
1429 return globalVariant == Dense ? 18 : 28;
1432int QQuickMaterialStyle::switchDelegateVerticalPadding()
const
1436 return globalVariant == Dense ? 4 : 8;
1439int QQuickMaterialStyle::textFieldHeight()
const
1443 return globalVariant == Dense ? 44 : 56;
1445int QQuickMaterialStyle::textFieldHorizontalPadding()
const
1447 return globalVariant == Dense ? 12 : 16;
1449int QQuickMaterialStyle::textFieldVerticalPadding()
const
1451 return globalVariant == Dense ? 4 : 8;
1454int QQuickMaterialStyle::tooltipHeight()
const
1457 return globalVariant == Dense ? 22 : 32;
1460QQuickMaterialStyle::Variant QQuickMaterialStyle::variant()
1462 return globalVariant;
1465template <
typename Enum>
1468 QMetaEnum enumeration = QMetaEnum::fromType<Enum>();
1469 return static_cast<Enum>(enumeration.keyToValue(value, ok));
1474 QByteArray value = qgetenv(env);
1475#if QT_CONFIG(settings)
1476 if (value.isNull() && !settings.isNull())
1477 value = settings->value(name).toByteArray();
1482void QQuickMaterialStyle::initGlobals()
1484 QSharedPointer<QSettings> settings = QQuickStylePrivate::settings(QStringLiteral(
"Material"));
1487 QByteArray themeValue = resolveSetting(
"QT_QUICK_CONTROLS_MATERIAL_THEME", settings, QStringLiteral(
"Theme"));
1488 Theme themeEnum = toEnumValue<Theme>(themeValue, &ok);
1490 globalTheme = themeEnum;
1491 else if (!themeValue.isEmpty())
1492 qWarning().nospace().noquote() <<
"Material: unknown theme value: " << themeValue;
1494 QByteArray variantValue = resolveSetting(
"QT_QUICK_CONTROLS_MATERIAL_VARIANT", settings, QStringLiteral(
"Variant"));
1495 Variant variantEnum = toEnumValue<Variant>(variantValue, &ok);
1497 globalVariant = variantEnum;
1498 else if (!variantValue.isEmpty())
1499 qWarning().nospace().noquote() <<
"Material: unknown variant value: " << variantValue;
1501 QByteArray primaryValue = resolveSetting(
"QT_QUICK_CONTROLS_MATERIAL_PRIMARY", settings, QStringLiteral(
"Primary"));
1502 Color primaryEnum = toEnumValue<Color>(primaryValue, &ok);
1504 globalPrimaryCustom =
false;
1505 globalPrimary = primaryEnum;
1507 QColor color = QColor::fromString(primaryValue);
1508 if (color.isValid()) {
1509 globalPrimaryCustom =
true;
1510 globalPrimary = color.rgba();
1511 }
else if (!primaryValue.isEmpty()) {
1512 qWarning().nospace().noquote() <<
"Material: unknown primary value: " << primaryValue;
1516 QByteArray accentValue = resolveSetting(
"QT_QUICK_CONTROLS_MATERIAL_ACCENT", settings, QStringLiteral(
"Accent"));
1517 Color accentEnum = toEnumValue<Color>(accentValue, &ok);
1519 globalAccentCustom =
false;
1520 globalAccent = accentEnum;
1521 }
else if (!accentValue.isEmpty()) {
1522 QColor color = QColor::fromString(accentValue);
1523 if (color.isValid()) {
1524 globalAccentCustom =
true;
1525 globalAccent = color.rgba();
1527 qWarning().nospace().noquote() <<
"Material: unknown accent value: " << accentValue;
1531 QByteArray foregroundValue = resolveSetting(
"QT_QUICK_CONTROLS_MATERIAL_FOREGROUND", settings, QStringLiteral(
"Foreground"));
1532 Color foregroundEnum = toEnumValue<Color>(foregroundValue, &ok);
1534 globalForegroundCustom =
false;
1535 globalForeground = foregroundEnum;
1536 hasGlobalForeground =
true;
1537 }
else if (!foregroundValue.isEmpty()) {
1538 QColor color = QColor::fromString(foregroundValue);
1539 if (color.isValid()) {
1540 globalForegroundCustom =
true;
1541 globalForeground = color.rgba();
1542 hasGlobalForeground =
true;
1544 qWarning().nospace().noquote() <<
"Material: unknown foreground value: " << foregroundValue;
1548 QByteArray backgroundValue = resolveSetting(
"QT_QUICK_CONTROLS_MATERIAL_BACKGROUND", settings, QStringLiteral(
"Background"));
1549 Color backgroundEnum = toEnumValue<Color>(backgroundValue, &ok);
1551 globalBackgroundCustom =
false;
1552 globalBackground = backgroundEnum;
1553 hasGlobalBackground =
true;
1554 }
else if (!backgroundValue.isEmpty()) {
1555 QColor color = QColor::fromString(backgroundValue);
1556 if (color.isValid()) {
1557 globalBackgroundCustom =
true;
1558 globalBackground = color.rgba();
1559 hasGlobalBackground =
true;
1561 qWarning().nospace().noquote() <<
"Material: unknown background value: " << backgroundValue;
1566void QQuickMaterialStyle::attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent)
1568 Q_UNUSED(oldParent);
1569 QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(newParent);
1571 inheritPrimary(material->m_primary, material->m_customPrimary);
1572 inheritAccent(material->m_accent, material->m_customAccent);
1573 inheritForeground(material->m_foreground, material->m_customForeground, material->m_hasForeground);
1574 inheritBackground(material->m_background, material->m_customBackground, material->m_hasBackground);
1575 inheritTheme(material->theme());
1579bool QQuickMaterialStyle::variantToRgba(
const QVariant &var,
const char *name, QRgb *rgba,
bool *custom)
const
1582 if (var.metaType().id() == QMetaType::Int) {
1583 int val = var.toInt();
1584 if (val > BlueGrey) {
1585 qmlWarning(parent()) <<
"unknown Material." << name <<
" value: " << val;
1590 int val = QMetaEnum::fromType<Color>().keyToValue(var.toByteArray());
1594 QColor color = QColor::fromString(var.toString());
1595 if (!color.isValid()) {
1596 qmlWarning(parent()) <<
"unknown Material." << name <<
" value: " << var.toString();
1600 *rgba = color.rgba();
1608#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