aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/controls/material/qquickmaterialstyle.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-01-25 11:02:44 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-01-25 11:03:53 +0100
commit5ada1525e03116326a480fb05611904d3484c296 (patch)
treef23822e6b0482012065b9586d95cb8ab5d70c4bf /src/imports/controls/material/qquickmaterialstyle.cpp
parentf4f5e857447d42738b1b60b5c4184f39df2f1593 (diff)
parent4f1fb09ed70c69e73f2e19f28f4299f4cfbc90dc (diff)
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts: .gitignore src/templates/qquickcombobox_p.h src/templates/qquickmenu_p.h src/templates/qquickmenu_p_p.h src/templates/qquickoverlay_p.h src/templates/qquickpopup.cpp src/templates/qquickpopup_p.h src/templates/qquickstackview_p.cpp Change-Id: I89c7d518697beec0b81ef3a12205286a4f3ccf89
Diffstat (limited to 'src/imports/controls/material/qquickmaterialstyle.cpp')
-rw-r--r--src/imports/controls/material/qquickmaterialstyle.cpp125
1 files changed, 105 insertions, 20 deletions
diff --git a/src/imports/controls/material/qquickmaterialstyle.cpp b/src/imports/controls/material/qquickmaterialstyle.cpp
index 04e96480..71b48a2b 100644
--- a/src/imports/controls/material/qquickmaterialstyle.cpp
+++ b/src/imports/controls/material/qquickmaterialstyle.cpp
@@ -43,21 +43,6 @@
QT_BEGIN_NAMESPACE
-/*!
- \qmltype Material
- \inherits QtObject
- \instantiates QQuickMaterialStyleAttached
- \inqmlmodule QtQuick.Controls.Material
- \ingroup utilities
- \brief A style interface.
-
- TODO
-*/
-
-/*!
- \qmlattachedproperty color QtQuickControls2::Material::textColorPrimaray
-*/
-
static const QRgb colors[][14] = {
// Red
{
@@ -385,8 +370,10 @@ static const QRgb colors[][14] = {
};
static QQuickMaterialStyle::Theme defaultTheme = QQuickMaterialStyle::Light;
-static uint defaultAccent = QQuickMaterialStyle::Teal;
-static bool defaultCustom = false;
+static uint defaultPrimary = QQuickMaterialStyle::Indigo;
+static uint defaultAccent = QQuickMaterialStyle::Pink;
+static bool defaultPrimaryCustom = false;
+static bool defaultAccentCustom = false;
static const QRgb backgroundColorLight = 0xFFFAFAFA;
static const QRgb backgroundColorDark = 0xFF303030;
static const QRgb dialogColorLight = 0xFFFFFFFF;
@@ -420,9 +407,12 @@ static const QRgb checkBoxUncheckedRippleColorDark = 0x20FFFFFF;
QQuickMaterialStyle::QQuickMaterialStyle(QObject *parent) : QQuickStyle(parent),
m_explicitTheme(false),
+ m_explicitPrimary(false),
m_explicitAccent(false),
- m_customAccent(defaultCustom),
+ m_customPrimary(defaultPrimaryCustom),
+ m_customAccent(defaultAccentCustom),
m_theme(defaultTheme),
+ m_primary(defaultPrimary),
m_accent(defaultAccent)
{
init();
@@ -478,6 +468,76 @@ void QQuickMaterialStyle::resetTheme()
}
}
+QVariant QQuickMaterialStyle::primary() const
+{
+ return primaryColor();
+}
+
+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();
+ }
+ }
+
+ m_explicitPrimary = true;
+ if (m_primary != primary) {
+ m_customPrimary = custom;
+ m_primary = primary;
+ propagatePrimary();
+ emit primaryChanged();
+ emit paletteChanged();
+ }
+}
+
+void QQuickMaterialStyle::inheritPrimary(uint primary, bool custom)
+{
+ if (!m_explicitPrimary && m_primary != primary) {
+ m_customPrimary = custom;
+ m_primary = primary;
+ propagatePrimary();
+ emit primaryChanged();
+ }
+}
+
+void QQuickMaterialStyle::propagatePrimary()
+{
+ foreach (QQuickStyle *child, childStyles()) {
+ QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(child);
+ if (material)
+ material->inheritPrimary(m_primary, m_customPrimary);
+ }
+}
+
+void QQuickMaterialStyle::resetPrimary()
+{
+ if (m_explicitPrimary) {
+ m_customPrimary = false;
+ m_explicitPrimary = false;
+ QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(parentStyle());
+ inheritPrimary(material ? material->m_primary : defaultPrimary, true);
+ }
+}
+
QVariant QQuickMaterialStyle::accent() const
{
return accentColor();
@@ -549,6 +609,15 @@ void QQuickMaterialStyle::resetAccent()
}
}
+QColor QQuickMaterialStyle::primaryColor() const
+{
+ if (m_customPrimary)
+ return QColor::fromRgba(m_primary);
+ if (m_primary > BlueGrey)
+ return QColor();
+ return colors[m_primary][Shade500];
+}
+
QColor QQuickMaterialStyle::accentColor() const
{
if (m_customAccent)
@@ -820,6 +889,7 @@ void QQuickMaterialStyle::parentStyleChange(QQuickStyle *newParent, QQuickStyle
Q_UNUSED(oldParent);
QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(newParent);
if (material) {
+ inheritPrimary(material->m_primary, material->m_customPrimary);
inheritAccent(material->m_accent, material->m_customAccent);
inheritTheme(material->theme());
}
@@ -846,15 +916,30 @@ void QQuickMaterialStyle::init()
else if (!value.isEmpty())
qWarning().nospace().noquote() << settings->fileName() << ": unknown Material theme value: " << value;
+ value = settings->value(QStringLiteral("Primary")).toByteArray();
+ Color primary = toEnumValue<Color>(value, &ok);
+ if (ok) {
+ defaultPrimaryCustom = m_customPrimary = false;
+ defaultPrimary = m_primary = primary;
+ } else {
+ QColor color(value.constData());
+ if (color.isValid()) {
+ defaultPrimaryCustom = m_customPrimary = true;
+ defaultPrimary = m_primary = color.rgba();
+ } else if (!value.isEmpty()) {
+ qWarning().nospace().noquote() << settings->fileName() << ": unknown Material primary value: " << value;
+ }
+ }
+
value = settings->value(QStringLiteral("Accent")).toByteArray();
Color accent = toEnumValue<Color>(value, &ok);
if (ok) {
- defaultCustom = m_customAccent = false;
+ defaultAccentCustom = m_customAccent = false;
defaultAccent = m_accent = accent;
} else {
QColor color(value.constData());
if (color.isValid()) {
- defaultCustom = m_customAccent = true;
+ defaultAccentCustom = m_customAccent = true;
defaultAccent = m_accent = color.rgba();
} else if (!value.isEmpty()) {
qWarning().nospace().noquote() << settings->fileName() << ": unknown Material accent value: " << value;