diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-04-13 14:03:54 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-04-15 05:32:39 +0000 |
commit | 8ed4c6caf5fd464adf3c41192a97e47b48acb713 (patch) | |
tree | 61fcde6e5c8b850d499accd4b5d70e660f1b00eb /src | |
parent | ed9720ffc6b462889e2f501824e9656a6ffde313 (diff) |
Add QQuickMaterialStyle::variantToRgba()
Extracted from setAccent() and setPrimary()
Change-Id: I2dff1d0f605cc210f6b86b5aa1a1f5ff284b20af
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/controls/material/qquickmaterialstyle.cpp | 73 | ||||
-rw-r--r-- | src/imports/controls/material/qquickmaterialstyle_p.h | 1 |
2 files changed, 32 insertions, 42 deletions
diff --git a/src/imports/controls/material/qquickmaterialstyle.cpp b/src/imports/controls/material/qquickmaterialstyle.cpp index c5670445..95dd0ba1 100644 --- a/src/imports/controls/material/qquickmaterialstyle.cpp +++ b/src/imports/controls/material/qquickmaterialstyle.cpp @@ -498,27 +498,8 @@ void QQuickMaterialStyle::setPrimary(const QVariant &var) { QRgb primary = 0; bool custom = false; - if (var.type() == QVariant::Int) { - int val = var.toInt(); - if (val > BlueGrey) { - qmlInfo(parent()) << "unknown Material.primary value: " << val; - return; - } - primary = val; - } else { - int val = QMetaEnum::fromType<Color>().keyToValue(var.toByteArray()); - if (val != -1) { - primary = val; - } else { - QColor color(var.toString()); - if (!color.isValid()) { - qmlInfo(parent()) << "unknown Material.primary value: " << var.toString(); - return; - } - custom = true; - primary = color.rgba(); - } - } + if (!variantToRgba(var, "primary", &primary, &custom)) + return; m_explicitPrimary = true; if (m_primary == primary) @@ -572,27 +553,8 @@ void QQuickMaterialStyle::setAccent(const QVariant &var) { QRgb accent = 0; bool custom = false; - if (var.type() == QVariant::Int) { - int val = var.toInt(); - if (val > BlueGrey) { - qmlInfo(parent()) << "unknown Material.accent value: " << val; - return; - } - accent = val; - } else { - int val = QMetaEnum::fromType<Color>().keyToValue(var.toByteArray()); - if (val != -1) { - accent = val; - } else { - QColor color(var.toString()); - if (!color.isValid()) { - qmlInfo(parent()) << "unknown Material.accent value: " << var.toString(); - return; - } - custom = true; - accent = color.rgba(); - } - } + if (!variantToRgba(var, "accent", &accent, &custom)) + return; m_explicitAccent = true; if (m_accent == accent) @@ -1019,4 +981,31 @@ void QQuickMaterialStyle::init() QQuickStyleAttached::init(); // TODO: lazy init? } +bool QQuickMaterialStyle::variantToRgba(const QVariant &var, const char *name, QRgb *rgba, bool *custom) const +{ + *custom = false; + if (var.type() == QVariant::Int) { + int val = var.toInt(); + if (val > BlueGrey) { + qmlInfo(parent()) << "unknown Material." << name << " value: " << val; + return false; + } + *rgba = val; + } else { + int val = QMetaEnum::fromType<Color>().keyToValue(var.toByteArray()); + if (val != -1) { + *rgba = val; + } else { + QColor color(var.toString()); + if (!color.isValid()) { + qmlInfo(parent()) << "unknown Material." << name << " value: " << var.toString(); + return false; + } + *custom = true; + *rgba = color.rgba(); + } + } + return true; +} + QT_END_NAMESPACE diff --git a/src/imports/controls/material/qquickmaterialstyle_p.h b/src/imports/controls/material/qquickmaterialstyle_p.h index 9cdf5bda..23e5750d 100644 --- a/src/imports/controls/material/qquickmaterialstyle_p.h +++ b/src/imports/controls/material/qquickmaterialstyle_p.h @@ -228,6 +228,7 @@ protected: private: void init(); + bool variantToRgba(const QVariant &var, const char *name, QRgb *rgba, bool *custom) const; bool m_explicitTheme; bool m_explicitPrimary; |