summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-12-11 13:12:18 +0200
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-12-11 13:15:15 +0200
commit6cfc1dcc2969e0e522aa5777eef97e0eadc967e7 (patch)
treec4f5c9799cc7903946b2756432b9ac987360ba66
parent2a11c7f805ce1f980167af4971cde1eebe660c7a (diff)
Multiseries support for theme colors and gradients, part 2
Task-number: QTRD-2611 Change-Id: I280f3b7c22a212ed46813bd28c639d255107f9f3 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
-rw-r--r--src/datavisualization/theme/thememanager.cpp310
-rw-r--r--src/datavisualization/theme/thememanager_p.h1
-rw-r--r--src/datavisualizationqml2/datavisualizationqml2_plugin.cpp2
-rw-r--r--src/datavisualizationqml2/declarativecolor.cpp12
-rw-r--r--src/datavisualizationqml2/declarativecolor_p.h12
-rw-r--r--src/datavisualizationqml2/declarativetheme.cpp210
-rw-r--r--src/datavisualizationqml2/declarativetheme_p.h35
-rw-r--r--tests/qmldynamicdata/qml/qmldynamicdata/main.qml17
8 files changed, 355 insertions, 244 deletions
diff --git a/src/datavisualization/theme/thememanager.cpp b/src/datavisualization/theme/thememanager.cpp
index cefbb897..1f8f0ae0 100644
--- a/src/datavisualization/theme/thememanager.cpp
+++ b/src/datavisualization/theme/thememanager.cpp
@@ -21,6 +21,9 @@
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
+const float defaultBuiltInColorLevel = 0.7f; // for built-in gradient themes
+const float defaultColorLevel = 0.5f; // for built-in uniform themes
+
ThemeManager::ThemeManager(Abstract3DController *controller)
: m_theme(0),
m_controller(controller)
@@ -89,15 +92,22 @@ void ThemeManager::connectThemeSignals()
void ThemeManager::useTheme(Q3DTheme::Theme type)
{
- QColor color;
- QLinearGradient gradient;
-
- // TODO: Add predefined colors & gradients to more than one series
-
switch (type) {
case Q3DTheme::ThemeQt: {
QList<QColor> baseColors;
baseColors.append(QColor(QRgb(0x80c342)));
+ baseColors.append(QColor(QRgb(0x60c342)));
+ baseColors.append(QColor(QRgb(0x40c342)));
+ baseColors.append(QColor(QRgb(0x20c342)));
+ baseColors.append(QColor(QRgb(0x00c342)));
+
+ QList<QLinearGradient> baseGradients;
+ baseGradients.append(createGradient(baseColors.at(0), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(1), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(2), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(3), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(4), defaultColorLevel));
+
setBackgroundEnabled(true);
setGridEnabled(true);
setFont(QFont(QStringLiteral("Arial")));
@@ -116,35 +126,27 @@ void ThemeManager::useTheme(Q3DTheme::Theme type)
setHighlightLightStrength(5.0f);
setLabelBorderEnabled(true);
setColorStyle(Q3DTheme::ColorStyleUniform);
- gradient = QLinearGradient(qreal(gradientTextureWidth),
- qreal(gradientTextureHeight),
- 0.0, 0.0);
- color.setRed(0x80 * 0.7);
- color.setGreen(0xc3 * 0.7);
- color.setBlue(0x42 * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0x80c342)));
- QList<QLinearGradient> baseGradients;
- baseGradients.append(gradient);
setBaseGradients(baseGradients);
- color.setRed(0x14 * 0.7);
- color.setGreen(0xaa * 0.7);
- color.setBlue(0xff * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0x14aaff)));
- setSingleHighlightGradient(gradient);
- color.setRed(0x64 * 0.7);
- color.setGreen(0x00);
- color.setBlue(0xaa * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0x6400aa)));
- setMultiHighlightGradient(gradient);
+ setSingleHighlightGradient(createGradient(QColor(QRgb(0x14aaff)), defaultColorLevel));
+ setMultiHighlightGradient(createGradient(QColor(QRgb(0x6400aa)), defaultColorLevel));
break;
}
case Q3DTheme::ThemePrimaryColors: {
QList<QColor> baseColors;
baseColors.append(QColor(QRgb(0xffe400)));
+ baseColors.append(QColor(QRgb(0xdfd400)));
+ baseColors.append(QColor(QRgb(0xbfc400)));
+ baseColors.append(QColor(QRgb(0x9fb400)));
+ baseColors.append(QColor(QRgb(0x7fa400)));
+
+ QList<QLinearGradient> baseGradients;
+ baseGradients.append(createGradient(baseColors.at(0), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(1), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(2), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(3), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(4), defaultColorLevel));
+
setBackgroundEnabled(true);
setGridEnabled(true);
setFont(QFont(QStringLiteral("Arial")));
@@ -163,35 +165,27 @@ void ThemeManager::useTheme(Q3DTheme::Theme type)
setHighlightLightStrength(5.0f);
setLabelBorderEnabled(false);
setColorStyle(Q3DTheme::ColorStyleUniform);
- gradient = QLinearGradient(qreal(gradientTextureWidth),
- qreal(gradientTextureHeight),
- 0.0, 0.0);
- color.setRed(0xff * 0.7);
- color.setGreen(0xe4 * 0.7);
- color.setBlue(0x00);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xffe400)));
- QList<QLinearGradient> baseGradients;
- baseGradients.append(gradient);
setBaseGradients(baseGradients);
- color.setRed(0x27 * 0.7);
- color.setGreen(0xbe * 0.7);
- color.setBlue(0xee * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0x27beee)));
- setSingleHighlightGradient(gradient);
- color.setRed(0xee * 0.7);
- color.setGreen(0x14 * 0.7);
- color.setBlue(0x14 * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xee1414)));
- setMultiHighlightGradient(gradient);
+ setSingleHighlightGradient(createGradient(QColor(QRgb(0x27beee)), defaultColorLevel));
+ setMultiHighlightGradient(createGradient(QColor(QRgb(0xee1414)), defaultColorLevel));
break;
}
case Q3DTheme::ThemeDigia: {
QList<QColor> baseColors;
baseColors.append(QColor(QRgb(0xcccccc)));
+ baseColors.append(QColor(QRgb(0xbbbbbb)));
+ baseColors.append(QColor(QRgb(0xaaaaaa)));
+ baseColors.append(QColor(QRgb(0x999999)));
+ baseColors.append(QColor(QRgb(0x888888)));
+
+ QList<QLinearGradient> baseGradients;
+ baseGradients.append(createGradient(baseColors.at(0), defaultBuiltInColorLevel));
+ baseGradients.append(createGradient(baseColors.at(1), defaultBuiltInColorLevel));
+ baseGradients.append(createGradient(baseColors.at(2), defaultBuiltInColorLevel));
+ baseGradients.append(createGradient(baseColors.at(3), defaultBuiltInColorLevel));
+ baseGradients.append(createGradient(baseColors.at(4), defaultBuiltInColorLevel));
+
setBackgroundEnabled(true);
setGridEnabled(true);
setFont(QFont(QStringLiteral("Arial")));
@@ -210,35 +204,27 @@ void ThemeManager::useTheme(Q3DTheme::Theme type)
setHighlightLightStrength(5.0f);
setLabelBorderEnabled(false);
setColorStyle(Q3DTheme::ColorStyleObjectGradient);
- gradient = QLinearGradient(qreal(gradientTextureWidth),
- qreal(gradientTextureHeight),
- 0.0, 0.0);
- color.setRed(0xcc * 0.7);
- color.setGreen(0xcc * 0.7);
- color.setBlue(0xcc * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xcccccc)));
- QList<QLinearGradient> baseGradients;
- baseGradients.append(gradient);
setBaseGradients(baseGradients);
- color.setRed(0xfa * 0.7);
- color.setGreen(0x00);
- color.setBlue(0x00);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xfa0000)));
- setSingleHighlightGradient(gradient);
- color.setRed(0x55 * 0.7);
- color.setGreen(0x55 * 0.7);
- color.setBlue(0x55 * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0x555555)));
- setMultiHighlightGradient(gradient);
+ setSingleHighlightGradient(createGradient(QColor(QRgb(0xfa0000)), defaultBuiltInColorLevel));
+ setMultiHighlightGradient(createGradient(QColor(QRgb(0x555555)), defaultBuiltInColorLevel));
break;
}
case Q3DTheme::ThemeStoneMoss: {
QList<QColor> baseColors;
baseColors.append(QColor(QRgb(0xbeb32b)));
+ baseColors.append(QColor(QRgb(0xcec33b)));
+ baseColors.append(QColor(QRgb(0xded34b)));
+ baseColors.append(QColor(QRgb(0xeee35b)));
+ baseColors.append(QColor(QRgb(0xfef36b)));
+
+ QList<QLinearGradient> baseGradients;
+ baseGradients.append(createGradient(baseColors.at(0), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(1), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(2), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(3), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(4), defaultColorLevel));
+
setBackgroundEnabled(true);
setGridEnabled(true);
setFont(QFont(QStringLiteral("Arial")));
@@ -257,35 +243,27 @@ void ThemeManager::useTheme(Q3DTheme::Theme type)
setHighlightLightStrength(5.0f);
setLabelBorderEnabled(true);
setColorStyle(Q3DTheme::ColorStyleUniform);
- gradient = QLinearGradient(qreal(gradientTextureWidth),
- qreal(gradientTextureHeight),
- 0.0, 0.0);
- color.setRed(0xbe * 0.7);
- color.setGreen(0xb3 * 0.7);
- color.setBlue(0x2b * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xbeb32b)));
- QList<QLinearGradient> baseGradients;
- baseGradients.append(gradient);
setBaseGradients(baseGradients);
- color.setRed(0xfb* 0.7);
- color.setGreen(0xf6 * 0.7);
- color.setBlue(0xd6 * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xfbf6d6)));
- setSingleHighlightGradient(gradient);
- color.setRed(0x44 * 0.7);
- color.setGreen(0x2f * 0.7);
- color.setBlue(0x20 * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0x442f20)));
- setMultiHighlightGradient(gradient);
+ setSingleHighlightGradient(createGradient(QColor(QRgb(0xfbf6d6)), defaultColorLevel));
+ setMultiHighlightGradient(createGradient(QColor(QRgb(0x442f20)), defaultColorLevel));
break;
}
case Q3DTheme::ThemeArmyBlue: {
QList<QColor> baseColors;
baseColors.append(QColor(QRgb(0x495f76)));
+ baseColors.append(QColor(QRgb(0x495f86)));
+ baseColors.append(QColor(QRgb(0x495f96)));
+ baseColors.append(QColor(QRgb(0x495fa6)));
+ baseColors.append(QColor(QRgb(0x495fb6)));
+
+ QList<QLinearGradient> baseGradients;
+ baseGradients.append(createGradient(baseColors.at(0), defaultBuiltInColorLevel));
+ baseGradients.append(createGradient(baseColors.at(1), defaultBuiltInColorLevel));
+ baseGradients.append(createGradient(baseColors.at(2), defaultBuiltInColorLevel));
+ baseGradients.append(createGradient(baseColors.at(3), defaultBuiltInColorLevel));
+ baseGradients.append(createGradient(baseColors.at(4), defaultBuiltInColorLevel));
+
setBackgroundEnabled(true);
setGridEnabled(true);
setFont(QFont(QStringLiteral("Arial")));
@@ -304,35 +282,27 @@ void ThemeManager::useTheme(Q3DTheme::Theme type)
setHighlightLightStrength(5.0f);
setLabelBorderEnabled(false);
setColorStyle(Q3DTheme::ColorStyleObjectGradient);
- gradient = QLinearGradient(qreal(gradientTextureWidth),
- qreal(gradientTextureHeight),
- 0.0, 0.0);
- color.setRed(0x49 * 0.7);
- color.setGreen(0x5f * 0.7);
- color.setBlue(0x76 * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0x495f76)));
- QList<QLinearGradient> baseGradients;
- baseGradients.append(gradient);
setBaseGradients(baseGradients);
- color.setRed(0x2a * 0.7);
- color.setGreen(0xa2 * 0.7);
- color.setBlue(0xf9 * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0x2aa2f9)));
- setSingleHighlightGradient(gradient);
- color.setRed(0x10 * 0.7);
- color.setGreen(0x37 * 0.7);
- color.setBlue(0x53 * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0x103753)));
- setMultiHighlightGradient(gradient);
+ setSingleHighlightGradient(createGradient(QColor(QRgb(0x2aa2f9)), defaultBuiltInColorLevel));
+ setMultiHighlightGradient(createGradient(QColor(QRgb(0x103753)), defaultBuiltInColorLevel));
break;
}
case Q3DTheme::ThemeRetro: {
QList<QColor> baseColors;
baseColors.append(QColor(QRgb(0x533b23)));
+ baseColors.append(QColor(QRgb(0x633b23)));
+ baseColors.append(QColor(QRgb(0x733b23)));
+ baseColors.append(QColor(QRgb(0x833b23)));
+ baseColors.append(QColor(QRgb(0x933b23)));
+
+ QList<QLinearGradient> baseGradients;
+ baseGradients.append(createGradient(baseColors.at(0), defaultBuiltInColorLevel));
+ baseGradients.append(createGradient(baseColors.at(1), defaultBuiltInColorLevel));
+ baseGradients.append(createGradient(baseColors.at(2), defaultBuiltInColorLevel));
+ baseGradients.append(createGradient(baseColors.at(3), defaultBuiltInColorLevel));
+ baseGradients.append(createGradient(baseColors.at(4), defaultBuiltInColorLevel));
+
setBackgroundEnabled(true);
setGridEnabled(true);
setFont(QFont(QStringLiteral("Arial")));
@@ -351,35 +321,27 @@ void ThemeManager::useTheme(Q3DTheme::Theme type)
setHighlightLightStrength(5.0f);
setLabelBorderEnabled(false);
setColorStyle(Q3DTheme::ColorStyleObjectGradient);
- gradient = QLinearGradient(qreal(gradientTextureWidth),
- qreal(gradientTextureHeight),
- 0.0, 0.0);
- color.setRed(0x53 * 0.7);
- color.setGreen(0x3b * 0.7);
- color.setBlue(0x23 * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0x533b23)));
- QList<QLinearGradient> baseGradients;
- baseGradients.append(gradient);
setBaseGradients(baseGradients);
- color.setRed(0x8e * 0.7);
- color.setGreen(0xa3 * 0.7);
- color.setBlue(0x17 * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0x8ea317)));
- setSingleHighlightGradient(gradient);
- color.setRed(0xc2 * 0.7);
- color.setGreen(0x57 * 0.7);
- color.setBlue(0x08 * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xc25708)));
- setMultiHighlightGradient(gradient);
+ setSingleHighlightGradient(createGradient(QColor(QRgb(0x8ea317)), defaultBuiltInColorLevel));
+ setMultiHighlightGradient(createGradient(QColor(QRgb(0xc25708)), defaultBuiltInColorLevel));
break;
}
case Q3DTheme::ThemeEbony: {
QList<QColor> baseColors;
baseColors.append(QColor(QRgb(0xffffff)));
+ baseColors.append(QColor(QRgb(0xeeeeee)));
+ baseColors.append(QColor(QRgb(0xdddddd)));
+ baseColors.append(QColor(QRgb(0xcccccc)));
+ baseColors.append(QColor(QRgb(0xbbbbbb)));
+
+ QList<QLinearGradient> baseGradients;
+ baseGradients.append(createGradient(baseColors.at(0), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(1), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(2), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(3), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(4), defaultColorLevel));
+
setBackgroundEnabled(true);
setGridEnabled(true);
setFont(QFont(QStringLiteral("Arial")));
@@ -398,35 +360,27 @@ void ThemeManager::useTheme(Q3DTheme::Theme type)
setHighlightLightStrength(5.0f);
setLabelBorderEnabled(false);
setColorStyle(Q3DTheme::ColorStyleUniform);
- gradient = QLinearGradient(qreal(gradientTextureWidth),
- qreal(gradientTextureHeight),
- 0.0, 0.0);
- color.setRed(0xff * 0.7);
- color.setGreen(0xff * 0.7);
- color.setBlue(0xff * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xffffff)));
- QList<QLinearGradient> baseGradients;
- baseGradients.append(gradient);
setBaseGradients(baseGradients);
- color.setRed(0xf5 * 0.7);
- color.setGreen(0xdc * 0.7);
- color.setBlue(0x0d * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xf5dc0d)));
- setSingleHighlightGradient(gradient);
- color.setRed(0x72 * 0.7);
- color.setGreen(0x22 * 0.7);
- color.setBlue(0x22 * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xd72222)));
- setMultiHighlightGradient(gradient);
+ setSingleHighlightGradient(createGradient(QColor(QRgb(0xf5dc0d)), defaultColorLevel));
+ setMultiHighlightGradient(createGradient(QColor(QRgb(0xd72222)), defaultColorLevel));
break;
}
case Q3DTheme::ThemeIsabelle: {
QList<QColor> baseColors;
baseColors.append(QColor(QRgb(0xf9d900)));
+ baseColors.append(QColor(QRgb(0xf9d910)));
+ baseColors.append(QColor(QRgb(0xf9d920)));
+ baseColors.append(QColor(QRgb(0xf9d930)));
+ baseColors.append(QColor(QRgb(0xf9d940)));
+
+ QList<QLinearGradient> baseGradients;
+ baseGradients.append(createGradient(baseColors.at(0), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(1), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(2), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(3), defaultColorLevel));
+ baseGradients.append(createGradient(baseColors.at(4), defaultColorLevel));
+
setBackgroundEnabled(true);
setGridEnabled(true);
setFont(QFont(QStringLiteral("Arial")));
@@ -445,29 +399,9 @@ void ThemeManager::useTheme(Q3DTheme::Theme type)
setHighlightLightStrength(5.0f);
setLabelBorderEnabled(false);
setColorStyle(Q3DTheme::ColorStyleUniform);
- gradient = QLinearGradient(qreal(gradientTextureWidth),
- qreal(gradientTextureHeight),
- 0.0, 0.0);
- color.setRed(0xf9 * 0.7);
- color.setGreen(0xd9 * 0.7);
- color.setBlue(0x00);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xf9d900)));
- QList<QLinearGradient> baseGradients;
- baseGradients.append(gradient);
setBaseGradients(baseGradients);
- color.setRed(0xff * 0.7);
- color.setGreen(0xf7 * 0.7);
- color.setBlue(0xcc * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xfff7cc)));
- setSingleHighlightGradient(gradient);
- color.setRed(0xde * 0.7);
- color.setGreen(0x0a * 0.7);
- color.setBlue(0x0a * 0.7);
- gradient.setColorAt(0.0, color);
- gradient.setColorAt(1.0, QColor(QRgb(0xde0a0a)));
- setMultiHighlightGradient(gradient);
+ setSingleHighlightGradient(createGradient(QColor(QRgb(0xfff7cc)), defaultColorLevel));
+ setMultiHighlightGradient(createGradient(QColor(QRgb(0xde0a0a)), defaultColorLevel));
break;
}
default:
@@ -475,6 +409,20 @@ void ThemeManager::useTheme(Q3DTheme::Theme type)
}
}
+QLinearGradient ThemeManager::createGradient(const QColor &color, float colorLevel)
+{
+ QColor startColor;
+ QLinearGradient gradient = QLinearGradient(qreal(gradientTextureWidth),
+ qreal(gradientTextureHeight),
+ 0.0, 0.0);;
+ startColor.setRed(color.red() * colorLevel);
+ startColor.setGreen(color.green() * colorLevel);
+ startColor.setBlue(color.blue() * colorLevel);
+ gradient.setColorAt(0.0, startColor);
+ gradient.setColorAt(1.0, color);
+ return gradient;
+}
+
void ThemeManager::setBaseColors(const QList<QColor> &colors)
{
if (!m_theme->d_ptr->m_dirtyBits.baseColorDirty)
diff --git a/src/datavisualization/theme/thememanager_p.h b/src/datavisualization/theme/thememanager_p.h
index a20154df..c6e6a107 100644
--- a/src/datavisualization/theme/thememanager_p.h
+++ b/src/datavisualization/theme/thememanager_p.h
@@ -48,6 +48,7 @@ public:
protected:
void connectThemeSignals();
void useTheme(Q3DTheme::Theme type);
+ QLinearGradient createGradient(const QColor &color, float colorLevel);
void setBaseColors(const QList<QColor> &colors);
void setBackgroundColor(const QColor &color);
void setWindowColor(const QColor &color);
diff --git a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp
index ceefa91e..8dcdfbcc 100644
--- a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp
+++ b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp
@@ -73,8 +73,8 @@ void Datavis3Dqml2Plugin::registerTypes(const char *uri)
qmlRegisterType<ColorGradientStop>(uri, 1, 0, "ColorGradientStop");
qmlRegisterType<ColorGradient>(uri, 1, 0, "ColorGradient");
- qmlRegisterType<DeclarativeColor>(uri, 1, 0, "Color");
+ qmlRegisterType<DeclarativeColor>(uri, 1, 0, "ThemeColor");
qmlRegisterType<DeclarativeTheme3D>(uri, 1, 0, "Theme3D");
qmlRegisterType<DeclarativeBar3DSeries>(uri, 1, 0, "Bar3DSeries");
diff --git a/src/datavisualizationqml2/declarativecolor.cpp b/src/datavisualizationqml2/declarativecolor.cpp
index e15edd45..5c1ff8c5 100644
--- a/src/datavisualizationqml2/declarativecolor.cpp
+++ b/src/datavisualizationqml2/declarativecolor.cpp
@@ -23,7 +23,19 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
DeclarativeColor::DeclarativeColor(QObject *parent)
: QObject(parent)
{
+}
+void DeclarativeColor::setColor(const QColor &color)
+{
+ if (m_color != color) {
+ m_color = color;
+ emit colorChanged(color);
+ }
+}
+
+QColor DeclarativeColor::color() const
+{
+ return m_color;
}
QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualizationqml2/declarativecolor_p.h b/src/datavisualizationqml2/declarativecolor_p.h
index e500f794..755652b4 100644
--- a/src/datavisualizationqml2/declarativecolor_p.h
+++ b/src/datavisualizationqml2/declarativecolor_p.h
@@ -31,17 +31,25 @@
#include "datavisualizationglobal_p.h"
#include <QColor>
-#include <QQmlListProperty>
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
-class DeclarativeColor : public QObject, public QColor
+class DeclarativeColor : public QObject
{
Q_OBJECT
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
public:
DeclarativeColor(QObject *parent = 0);
+ void setColor(const QColor &color);
+ QColor color() const;
+
+signals:
+ void colorChanged(QColor color);
+
+private:
+ QColor m_color;
};
QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualizationqml2/declarativetheme.cpp b/src/datavisualizationqml2/declarativetheme.cpp
index 263fa62e..6c804397 100644
--- a/src/datavisualizationqml2/declarativetheme.cpp
+++ b/src/datavisualizationqml2/declarativetheme.cpp
@@ -22,9 +22,12 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
DeclarativeTheme3D::DeclarativeTheme3D(QObject *parent)
: Q3DTheme(parent),
+ m_colors(QList<DeclarativeColor *>()),
m_gradients(QList<ColorGradient *>()),
m_singleHLGradient(0),
- m_multiHLGradient(0)
+ m_multiHLGradient(0),
+ m_dummyGradients(false),
+ m_dummyColors(false)
{
}
@@ -34,8 +37,8 @@ DeclarativeTheme3D::~DeclarativeTheme3D()
QQmlListProperty<QObject> DeclarativeTheme3D::seriesChildren()
{
- return QQmlListProperty<QObject>(this, this, &DeclarativeTheme3D::appendSeriesChildren
- , 0, 0, 0);
+ return QQmlListProperty<QObject>(this, this, &DeclarativeTheme3D::appendSeriesChildren,
+ 0, 0, 0);
}
void DeclarativeTheme3D::appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element)
@@ -45,6 +48,44 @@ void DeclarativeTheme3D::appendSeriesChildren(QQmlListProperty<QObject> *list, Q
// Nothing to do, seriesChildren is there only to enable scoping gradient items in Theme3D item.
}
+void DeclarativeTheme3D::handleBaseColorUpdate()
+{
+ int colorCount = m_colors.size();
+ int changed = 0;
+ // Check which one changed
+ DeclarativeColor *color = qobject_cast<DeclarativeColor *>(QObject::sender());
+ for (int i = 0; i < colorCount; i++) {
+ if (color == m_colors.at(i)) {
+ changed = i;
+ break;
+ }
+ }
+ // Update the changed one from the list
+ QList<QColor> list = Q3DTheme::baseColors();
+ list[changed] = m_colors.at(changed)->color();
+ // Set the changed list
+ Q3DTheme::setBaseColors(list);
+}
+
+void DeclarativeTheme3D::handleBaseGradientUpdate()
+{
+ int gradientCount = m_gradients.size();
+ int changed = 0;
+ // Check which one changed
+ ColorGradient *gradient = qobject_cast<ColorGradient *>(QObject::sender());
+ for (int i = 0; i < gradientCount; i++) {
+ if (gradient == m_gradients.at(i)) {
+ changed = i;
+ break;
+ }
+ }
+ // Update the changed one from the list
+ QList<QLinearGradient> list = Q3DTheme::baseGradients();
+ list[changed] = convertGradient(gradient);
+ // Set the changed list
+ Q3DTheme::setBaseGradients(list);
+}
+
void DeclarativeTheme3D::handleSingleHLGradientUpdate()
{
if (m_singleHLGradient)
@@ -145,70 +186,147 @@ QLinearGradient DeclarativeTheme3D::convertGradient(ColorGradient *gradient)
return newGradient;
}
-//void DeclarativeTheme3D::addColor(const DeclarativeColor &color)
-//{
-// QList<QColor> list = Q3DTheme::baseColors();
-// list.append(color);
-// Q3DTheme::setBaseColors(list);
-//}
+ColorGradient *DeclarativeTheme3D::convertGradient(const QLinearGradient &gradient)
+{
+ ColorGradient *newGradient = new ColorGradient(this);
+ QGradientStops stops = gradient.stops();
+ ColorGradientStop *qmlstop;
+
+ // Convert stops
+ for (int i = 0; i < stops.size(); i++) {
+ qmlstop = new ColorGradientStop(newGradient);
+ qmlstop->setColor(stops.at(i).second);
+ qmlstop->setPosition(stops.at(i).first);
+ newGradient->m_stops.append(qmlstop);
+ }
+
+ return newGradient;
+}
+
+void DeclarativeTheme3D::addColor(DeclarativeColor *color)
+{
+ clearDummyColors();
+ m_colors.append(color);
+ connect(color, &DeclarativeColor::colorChanged,
+ this, &DeclarativeTheme3D::handleBaseColorUpdate);
+ QList<QColor> list = Q3DTheme::baseColors();
+ list.append(color->color());
+ Q3DTheme::setBaseColors(list);
+}
-//QList<DeclarativeColor> DeclarativeTheme3D::colorList() const
-//{
-// return Q3DTheme::baseColors();
-//}
+QList<DeclarativeColor *> DeclarativeTheme3D::colorList()
+{
+ if (m_colors.isEmpty()) {
+ // Create dummy ThemeColors from theme's gradients
+ m_dummyColors = true;
+ QList<QColor> list = Q3DTheme::baseColors();
+ foreach (QColor item, list) {
+ DeclarativeColor *color = new DeclarativeColor(this);
+ color->setColor(item);
+ m_colors.append(color);
+ connect(color, &DeclarativeColor::colorChanged,
+ this, &DeclarativeTheme3D::handleBaseColorUpdate);
+ }
+ }
+ return m_colors;
+}
+
+void DeclarativeTheme3D::clearColors()
+{
+ clearDummyColors();
+ foreach (DeclarativeColor *item, m_colors)
+ disconnect(item, 0, this, 0);
+ m_colors.clear();
+ Q3DTheme::setBaseColors(QList<QColor>());
+}
-//void DeclarativeTheme3D::clearColors()
-//{
-// Q3DTheme::setBaseColors(QList<QColor>());
-//}
+void DeclarativeTheme3D::clearDummyColors()
+{
+ if (m_dummyColors) {
+ foreach (DeclarativeColor *item, m_colors)
+ delete item;
+ m_colors.clear();
+ m_dummyColors = false;
+ }
+}
void DeclarativeTheme3D::addGradient(ColorGradient *gradient)
{
+ clearDummyGradients();
m_gradients.append(gradient);
+ connect(gradient, &ColorGradient::updated,
+ this, &DeclarativeTheme3D::handleBaseGradientUpdate);
QList<QLinearGradient> list = Q3DTheme::baseGradients();
list.append(convertGradient(gradient));
Q3DTheme::setBaseGradients(list);
}
-QList<ColorGradient *> DeclarativeTheme3D::gradientList() const
+QList<ColorGradient *> DeclarativeTheme3D::gradientList()
{
+ if (m_gradients.isEmpty()) {
+ // Create dummy ColorGradients from theme's gradients
+ m_dummyGradients = true;
+ QList<QLinearGradient> list = Q3DTheme::baseGradients();
+ foreach (QLinearGradient item, list) {
+ ColorGradient *gradient = convertGradient(item);
+ m_gradients.append(gradient);
+ connect(gradient, &ColorGradient::updated,
+ this, &DeclarativeTheme3D::handleBaseGradientUpdate);
+ }
+ }
+
return m_gradients;
}
void DeclarativeTheme3D::clearGradients()
{
+ clearDummyGradients();
+ foreach (ColorGradient *item, m_gradients)
+ disconnect(item, 0, this, 0);
m_gradients.clear();
Q3DTheme::setBaseGradients(QList<QLinearGradient>());
}
-//QQmlListProperty<DeclarativeColor> DeclarativeTheme3D::baseColors()
-//{
-// return QQmlListProperty<DeclarativeColor>(this, this,
-// &DeclarativeTheme3D::appendBaseColorsFunc,
-// &DeclarativeTheme3D::countBaseColorsFunc,
-// &DeclarativeTheme3D::atBaseColorsFunc,
-// &DeclarativeTheme3D::clearBaseColorsFunc);
-//}
-
-//void DeclarativeTheme3D::appendBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list, DeclarativeColor *color)
-//{
-// reinterpret_cast<DeclarativeTheme3D *>(list->data)->addColor(*color);
-//}
-
-//int DeclarativeTheme3D::countBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list)
-//{
-// return reinterpret_cast<DeclarativeTheme3D *>(list->data)->colorList().size();
-//}
-
-//DeclarativeColor *DeclarativeTheme3D::atBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list, int index)
-//{
-// return &(reinterpret_cast<DeclarativeTheme3D *>(list->data)->colorList()[index]);
-//}
-
-//void DeclarativeTheme3D::clearBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list)
-//{
-// reinterpret_cast<DeclarativeTheme3D *>(list->data)->clearGradients();
-//}
+void DeclarativeTheme3D::clearDummyGradients()
+{
+ if (m_dummyGradients) {
+ foreach (ColorGradient *item, m_gradients)
+ delete item;
+ m_gradients.clear();
+ m_dummyGradients = false;
+ }
+}
+
+QQmlListProperty<DeclarativeColor> DeclarativeTheme3D::baseColors()
+{
+ return QQmlListProperty<DeclarativeColor>(this, this,
+ &DeclarativeTheme3D::appendBaseColorsFunc,
+ &DeclarativeTheme3D::countBaseColorsFunc,
+ &DeclarativeTheme3D::atBaseColorsFunc,
+ &DeclarativeTheme3D::clearBaseColorsFunc);
+}
+
+void DeclarativeTheme3D::appendBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list,
+ DeclarativeColor *color)
+{
+ reinterpret_cast<DeclarativeTheme3D *>(list->data)->addColor(color);
+}
+
+int DeclarativeTheme3D::countBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list)
+{
+ return reinterpret_cast<DeclarativeTheme3D *>(list->data)->colorList().size();
+}
+
+DeclarativeColor *DeclarativeTheme3D::atBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list,
+ int index)
+{
+ return reinterpret_cast<DeclarativeTheme3D *>(list->data)->colorList().at(index);
+}
+
+void DeclarativeTheme3D::clearBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list)
+{
+ reinterpret_cast<DeclarativeTheme3D *>(list->data)->clearColors();
+}
QQmlListProperty<ColorGradient> DeclarativeTheme3D::baseGradients()
{
diff --git a/src/datavisualizationqml2/declarativetheme_p.h b/src/datavisualizationqml2/declarativetheme_p.h
index 75ab9514..79c1f5c9 100644
--- a/src/datavisualizationqml2/declarativetheme_p.h
+++ b/src/datavisualizationqml2/declarativetheme_p.h
@@ -30,8 +30,8 @@
#define DECLARATIVETHEME_P_H
#include "datavisualizationglobal_p.h"
+#include "declarativecolor_p.h"
#include "colorgradient_p.h"
-//#include "declarativecolor_p.h"
#include "q3dtheme.h"
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
@@ -40,7 +40,7 @@ class DeclarativeTheme3D : public Q3DTheme
{
Q_OBJECT
Q_PROPERTY(QQmlListProperty<QObject> seriesChildren READ seriesChildren)
-// Q_PROPERTY(QQmlListProperty<DeclarativeColor> baseColors READ baseColors)
+ Q_PROPERTY(QQmlListProperty<DeclarativeColor> baseColors READ baseColors)
Q_PROPERTY(QQmlListProperty<ColorGradient> baseGradients READ baseGradients)
Q_PROPERTY(ColorGradient *singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged)
Q_PROPERTY(ColorGradient *multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged)
@@ -53,12 +53,12 @@ public:
QQmlListProperty<QObject> seriesChildren();
static void appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element);
-// QQmlListProperty<DeclarativeColor> baseColors();
-// static void appendBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list,
-// DeclarativeColor *color);
-// static int countBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list);
-// static DeclarativeColor *atBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list, int index);
-// static void clearBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list);
+ QQmlListProperty<DeclarativeColor> baseColors();
+ static void appendBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list,
+ DeclarativeColor *color);
+ static int countBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list);
+ static DeclarativeColor *atBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list, int index);
+ static void clearBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list);
QQmlListProperty<ColorGradient> baseGradients();
static void appendBaseGradientsFunc(QQmlListProperty<ColorGradient> *list,
@@ -78,6 +78,8 @@ signals:
void multiHighlightGradientChanged(ColorGradient *gradient);
protected:
+ void handleBaseColorUpdate();
+ void handleBaseGradientUpdate();
void handleSingleHLGradientUpdate();
void handleMultiHLGradientUpdate();
@@ -88,18 +90,27 @@ protected:
};
private:
-// void addColor(const DeclarativeColor &color);
-// QList<DeclarativeColor> colorList() const;
-// void clearColors();
+ void addColor(DeclarativeColor *color);
+ QList<DeclarativeColor *> colorList();
+ void clearColors();
+ void clearDummyColors();
+
void addGradient(ColorGradient *gradient);
- QList<ColorGradient *> gradientList() const;
+ QList<ColorGradient *> gradientList();
void clearGradients();
+ void clearDummyGradients();
+
void setThemeGradient(ColorGradient *gradient, GradientType type);
QLinearGradient convertGradient(ColorGradient *gradient);
+ ColorGradient *convertGradient(const QLinearGradient &gradient);
+ QList<DeclarativeColor *> m_colors; // Not owned
QList<ColorGradient *> m_gradients; // Not owned
ColorGradient *m_singleHLGradient; // Not owned
ColorGradient *m_multiHLGradient; // Not owned
+
+ bool m_dummyGradients;
+ bool m_dummyColors;
};
QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/tests/qmldynamicdata/qml/qmldynamicdata/main.qml b/tests/qmldynamicdata/qml/qmldynamicdata/main.qml
index e8e23b75..4ed3b8ae 100644
--- a/tests/qmldynamicdata/qml/qmldynamicdata/main.qml
+++ b/tests/qmldynamicdata/qml/qmldynamicdata/main.qml
@@ -58,6 +58,16 @@ Item {
}
}
+ ThemeColor {
+ id: dynamicColor
+ ColorAnimation on color {
+ from: "red"
+ to: "yellow"
+ duration: 5000
+ loops: Animation.Infinite
+ }
+ }
+
Item {
id: dataView
anchors.bottom: parent.bottom
@@ -68,7 +78,10 @@ Item {
id: scatterGraph
width: dataView.width
height: dataView.height
- theme: Theme3D { type: Theme3D.ThemeDigia }
+ theme: Theme3D {
+ type: Theme3D.ThemeQt
+ baseColors: [dynamicColor]
+ }
shadowQuality: AbstractGraph3D.ShadowQualitySoftMedium
scene.activeCamera.yRotation: 30.0
inputHandler: null
@@ -185,7 +198,7 @@ Item {
NewButton {
id: cameraToggle
width: parent.width / 3
- text: "Animate Camera"
+ text: "Pause Camera"
anchors.left: shadowToggle.right
onClicked: {