From 56eb5442dd1e2d6233e443bab956c6bd1b7a116b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Tue, 10 Dec 2013 12:55:22 +0200 Subject: Multiseries support for theme colors and gradients, Part 1 Task-number: QTRD-2611 - declarative support for color list missing - declarative connections and fixes for count etc. Change-Id: I0ac007dcd7acb011d1a4461a56066ee41c364a75 Reviewed-by: Miikka Heikkinen --- src/datavisualization/data/qabstract3dseries.cpp | 16 +- .../engine/abstract3dcontroller.cpp | 14 +- .../engine/abstract3dcontroller_p.h | 4 +- src/datavisualization/engine/surface3drenderer.cpp | 2 +- src/datavisualization/theme/q3dtheme.cpp | 103 +++++++----- src/datavisualization/theme/q3dtheme.h | 16 +- src/datavisualization/theme/q3dtheme_p.h | 4 +- src/datavisualization/theme/thememanager.cpp | 82 +++++++--- src/datavisualization/theme/thememanager_p.h | 4 +- .../datavisualizationqml2.pro | 6 +- .../datavisualizationqml2_plugin.cpp | 1 + .../datavisualizationqml2_plugin.h | 3 + src/datavisualizationqml2/declarativecolor.cpp | 29 ++++ src/datavisualizationqml2/declarativecolor_p.h | 49 ++++++ src/datavisualizationqml2/declarativetheme.cpp | 174 +++++++++++++++------ src/datavisualizationqml2/declarativetheme_p.h | 34 +++- 16 files changed, 386 insertions(+), 155 deletions(-) create mode 100644 src/datavisualizationqml2/declarativecolor.cpp create mode 100644 src/datavisualizationqml2/declarativecolor_p.h (limited to 'src') diff --git a/src/datavisualization/data/qabstract3dseries.cpp b/src/datavisualization/data/qabstract3dseries.cpp index 46224813..6126d774 100644 --- a/src/datavisualization/data/qabstract3dseries.cpp +++ b/src/datavisualization/data/qabstract3dseries.cpp @@ -102,7 +102,7 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE * \qmlproperty Color Abstract3DSeries::baseColor * * Sets the base \c color of the series. - * See \l{Theme3D::baseColor}{Theme3D.baseColor} + * See \l{Theme3D::baseColors}{Theme3D.baseColors} * documentation for more information. * * \sa colorStyle @@ -112,7 +112,7 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE * \qmlproperty ColorGradient Abstract3DSeries::baseGradient * * Sets the base \c gradient of the series. - * See \l{Theme3D::baseGradient}{Theme3D.baseGradient} + * See \l{Theme3D::baseGradients}{Theme3D.baseGradients} * documentation for more information. * * \sa colorStyle @@ -628,19 +628,21 @@ void QAbstract3DSeriesPrivate::setMultiHighlightGradient(const QLinearGradient & void QAbstract3DSeriesPrivate::resetToTheme(const Q3DTheme &theme, int seriesIndex, bool force) { - // TODO: seriesIndex indicates which color from theme is required - Q_UNUSED(seriesIndex) - + int themeIndex = seriesIndex; if (force || !m_themeTracker.colorStyleOverride) { q_ptr->setColorStyle(theme.colorStyle()); m_themeTracker.colorStyleOverride = false; } if (force || !m_themeTracker.baseColorOverride) { - q_ptr->setBaseColor(theme.baseColor()); + if (theme.baseColors().size() <= seriesIndex) + themeIndex = seriesIndex % theme.baseColors().size(); + q_ptr->setBaseColor(theme.baseColors().at(themeIndex)); m_themeTracker.baseColorOverride = false; } if (force || !m_themeTracker.baseGradientOverride) { - q_ptr->setBaseGradient(theme.baseGradient()); + if (theme.baseGradients().size() <= seriesIndex) + themeIndex = seriesIndex % theme.baseGradients().size(); + q_ptr->setBaseGradient(theme.baseGradients().at(themeIndex)); m_themeTracker.baseGradientOverride = false; } if (force || !m_themeTracker.singleHighlightColorOverride) { diff --git a/src/datavisualization/engine/abstract3dcontroller.cpp b/src/datavisualization/engine/abstract3dcontroller.cpp index a1ad9191..09fa8510 100644 --- a/src/datavisualization/engine/abstract3dcontroller.cpp +++ b/src/datavisualization/engine/abstract3dcontroller.cpp @@ -474,26 +474,32 @@ void Abstract3DController::handleThemeColorStyleChanged(Q3DTheme::ColorStyle sty markSeriesVisualsDirty(); } -void Abstract3DController::handleThemeBaseColorChanged(const QColor &color) +void Abstract3DController::handleThemeBaseColorsChanged(const QList &colors) { + int colorIdx = 0; // Set value for series that have not explicitly set this value foreach (QAbstract3DSeries *series, m_seriesList) { if (!series->d_ptr->m_themeTracker.baseColorOverride) { - series->setBaseColor(color); + series->setBaseColor(colors.at(colorIdx)); series->d_ptr->m_themeTracker.baseColorOverride = false; } + if (++colorIdx >= colors.size()) + colorIdx = 0; } markSeriesVisualsDirty(); } -void Abstract3DController::handleThemeBaseGradientChanged(const QLinearGradient &gradient) +void Abstract3DController::handleThemeBaseGradientsChanged(const QList &gradients) { + int gradientIdx = 0; // Set value for series that have not explicitly set this value foreach (QAbstract3DSeries *series, m_seriesList) { if (!series->d_ptr->m_themeTracker.baseGradientOverride) { - series->setBaseGradient(gradient); + series->setBaseGradient(gradients.at(gradientIdx)); series->d_ptr->m_themeTracker.baseGradientOverride = false; } + if (++gradientIdx >= gradients.size()) + gradientIdx = 0; } markSeriesVisualsDirty(); } diff --git a/src/datavisualization/engine/abstract3dcontroller_p.h b/src/datavisualization/engine/abstract3dcontroller_p.h index 934aa7f5..b8ad5daa 100644 --- a/src/datavisualization/engine/abstract3dcontroller_p.h +++ b/src/datavisualization/engine/abstract3dcontroller_p.h @@ -262,8 +262,8 @@ public slots: void handlePixelRatioChanged(float ratio); void handleThemeColorStyleChanged(Q3DTheme::ColorStyle style); - void handleThemeBaseColorChanged(const QColor &color); - void handleThemeBaseGradientChanged(const QLinearGradient &gradient); + void handleThemeBaseColorsChanged(const QList &color); + void handleThemeBaseGradientsChanged(const QList &gradient); void handleThemeSingleHighlightColorChanged(const QColor &color); void handleThemeSingleHighlightGradientChanged(const QLinearGradient &gradient); void handleThemeMultiHighlightColorChanged(const QColor &color); diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index f0dd5f3e..47e3bf08 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -2179,6 +2179,7 @@ void Surface3DRenderer::updateDepthBuffer() lowerShadowQuality(); } } +#endif void Surface3DRenderer::generateUniformGradient(const QVector3D newColor) { @@ -2192,6 +2193,5 @@ void Surface3DRenderer::generateUniformGradient(const QVector3D newColor) fixGradientAndGenerateTexture(&newGradient, &m_uniformGradientTexture); } } -#endif QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/theme/q3dtheme.cpp b/src/datavisualization/theme/q3dtheme.cpp index f138dfc1..8db30ec6 100644 --- a/src/datavisualization/theme/q3dtheme.cpp +++ b/src/datavisualization/theme/q3dtheme.cpp @@ -51,16 +51,19 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE * \li Is the graph background drawn or not. * \li true * \row - * \li baseColor - * \li The color for the objects in the graph. The color in this property is used if colorStyle - * is ColorStyleUniform. This can be overridden by setting the baseColor explicitly in - * series. - * \li Qt::white + * \li baseColors + * \li List of colors for the objects in the graph. Colors are applied to series one by one. + * If there are more series than colors, the color list is reused from the start. + * The colors in this property are used if colorStyle is ColorStyleUniform. This can be + * overridden by setting the baseColor explicitly in series. + * \li Qt::black * \row - * \li baseGradient - * \li The gradient for the objects in the graph. The gradient in this property is used if - * colorStyle is ColorStyleObjectGradient or ColorStyleRangeGradient. This can be overridden - * by setting the baseGradient explicitly in series. + * \li baseGradients + * \li List of gradients for the objects in the graph. Gradients are applied to series one by + * one. If there are more series than gradients, the gradient list is reused from the start. + * The gradients in this property are used if colorStyle is ColorStyleObjectGradient or + * ColorStyleRangeGradient. This can be overridden by setting the baseGradient explicitly + * in series. * \li QLinearGradient(). Essentially fully black. * \row * \li colorStyle @@ -234,10 +237,11 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE */ /*! - * \qmlproperty Color Theme3D::baseColor + * \qmlproperty Color Theme3D::baseColors * - * Color to be used for all the objects in the graph. Has no immediate effect if colorStyle is not - * \c Theme3D.ColorStyleUniform. + * List of base colors to be used for all the objects in the graph, series by series. If there + * are more series than colors, color list wraps and starts again with the first color in the list. + * Has no immediate effect if colorStyle is not \c Theme3D.ColorStyleUniform. */ /*! @@ -293,10 +297,12 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE */ /*! - * \qmlproperty ColorGradient Theme3D::baseGradient + * \qmlproperty ColorGradient Theme3D::baseGradients * - * Base gradient to be used for all the objects in the graph. Has no immediate effect if colorStyle - * is \c Theme3D.ColorStyleUniform. + * List of base gradients to be used for all the objects in the graph, series by series. If there + * are more series than gradients, gradient list wraps and starts again with the first gradient in + * the list + * Has no immediate effect if colorStyle is \c Theme3D.ColorStyleUniform. */ /*! @@ -413,25 +419,30 @@ Q3DTheme::~Q3DTheme() } // TODO: Add needRenders if necessary after color api has been added to series (QTRD-2200/2557) -// TODO: Basecolors as a list, containing one for each series? /*! - * \property Q3DTheme::baseColor + * \property Q3DTheme::baseColors * - * Color to be used for all the objects in the graph. Has no immediate effect if colorStyle is not - * ColorStyleUniform. + * List of base colors to be used for all the objects in the graph, series by series. If there + * are more series than colors, color list wraps and starts again with the first color in the list. + * Has no immediate effect if colorStyle is not ColorStyleUniform. */ -void Q3DTheme::setBaseColor(const QColor &color) +void Q3DTheme::setBaseColors(const QList &colors) { - d_ptr->m_dirtyBits.baseColorDirty = true; - if (d_ptr->m_baseColor != color) { - d_ptr->m_baseColor = color; - emit baseColorChanged(color); + if (colors.size()) { + d_ptr->m_dirtyBits.baseColorDirty = true; + if (d_ptr->m_baseColors != colors) { + d_ptr->m_baseColors.clear(); + d_ptr->m_baseColors = colors; + emit baseColorsChanged(colors); + } + } else { + d_ptr->m_baseColors.clear(); } } -QColor Q3DTheme::baseColor() const +QList Q3DTheme::baseColors() const { - return d_ptr->m_baseColor; + return d_ptr->m_baseColors; } /*! @@ -596,25 +607,31 @@ QColor Q3DTheme::lightColor() const return d_ptr->m_lightColor; } -// TODO: Surfacegradients as a list, containing one for each series? /*! - * \property Q3DTheme::baseGradient + * \property Q3DTheme::baseGradients * - * Base gradient to be used for all the objects in the graph. Has no immediate effect if colorStyle - * is ColorStyleUniform. + * List of base gradients to be used for all the objects in the graph, series by series. If there + * are more series than gradients, gradient list wraps and starts again with the first gradient in + * the list + * Has no immediate effect if colorStyle is ColorStyleUniform. */ -void Q3DTheme::setBaseGradient(const QLinearGradient &gradient) +void Q3DTheme::setBaseGradients(const QList &gradients) { - d_ptr->m_dirtyBits.baseGradientDirty = true; - if (d_ptr->m_baseGradient != gradient) { - d_ptr->m_baseGradient = gradient; - emit baseGradientChanged(gradient); + if (gradients.size()) { + d_ptr->m_dirtyBits.baseGradientDirty = true; + if (d_ptr->m_baseGradients != gradients) { + d_ptr->m_baseGradients.clear(); + d_ptr->m_baseGradients = gradients; + emit baseGradientsChanged(gradients); + } + } else { + d_ptr->m_baseGradients.clear(); } } -QLinearGradient Q3DTheme::baseGradient() const +QList Q3DTheme::baseGradients() const { - return d_ptr->m_baseGradient; + return d_ptr->m_baseGradients; } /*! @@ -867,7 +884,6 @@ Q3DTheme::Theme Q3DTheme::type() const Q3DThemePrivate::Q3DThemePrivate(Q3DTheme *q, Q3DTheme::Theme theme_id) : QObject(0), m_themeId(theme_id), - m_baseColor(Qt::white), m_backgroundColor(Qt::black), m_windowColor(Qt::black), m_textColor(Qt::white), @@ -876,9 +892,6 @@ Q3DThemePrivate::Q3DThemePrivate(Q3DTheme *q, Q3DTheme::Theme theme_id) m_singleHighlightColor(Qt::red), m_multiHighlightColor(Qt::blue), m_lightColor(Qt::white), - m_baseGradient(QLinearGradient(qreal(gradientTextureWidth), - qreal(gradientTextureHeight), - 0.0, 0.0)), m_singleHighlightGradient(QLinearGradient(qreal(gradientTextureWidth), qreal(gradientTextureHeight), 0.0, 0.0)), @@ -896,6 +909,10 @@ Q3DThemePrivate::Q3DThemePrivate(Q3DTheme *q, Q3DTheme::Theme theme_id) m_labelBackground(true), q_ptr(q) { + m_baseColors.append(QColor(Qt::black)); + m_baseGradients.append(QLinearGradient(qreal(gradientTextureWidth), + qreal(gradientTextureHeight), + 0.0, 0.0)); } Q3DThemePrivate::~Q3DThemePrivate() @@ -947,12 +964,12 @@ bool Q3DThemePrivate::sync(Q3DThemePrivate &other) changed = true; } if (m_dirtyBits.baseColorDirty) { - other.q_ptr->setBaseColor(m_baseColor); + other.q_ptr->setBaseColors(m_baseColors); m_dirtyBits.baseColorDirty = false; changed = true; } if (m_dirtyBits.baseGradientDirty) { - other.q_ptr->setBaseGradient(m_baseGradient); + other.q_ptr->setBaseGradients(m_baseGradients); m_dirtyBits.baseGradientDirty = false; changed = true; } diff --git a/src/datavisualization/theme/q3dtheme.h b/src/datavisualization/theme/q3dtheme.h index c3262b91..44e58e5d 100644 --- a/src/datavisualization/theme/q3dtheme.h +++ b/src/datavisualization/theme/q3dtheme.h @@ -34,7 +34,7 @@ class QT_DATAVISUALIZATION_EXPORT Q3DTheme : public QObject Q_ENUMS(ColorStyle) Q_ENUMS(Theme) Q_PROPERTY(Theme type READ type WRITE setType NOTIFY typeChanged) - Q_PROPERTY(QColor baseColor READ baseColor WRITE setBaseColor NOTIFY baseColorChanged) + Q_PROPERTY(QList baseColors READ baseColors WRITE setBaseColors NOTIFY baseColorsChanged) Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) Q_PROPERTY(QColor windowColor READ windowColor WRITE setWindowColor NOTIFY windowColorChanged) Q_PROPERTY(QColor labelTextColor READ labelTextColor WRITE setLabelTextColor NOTIFY labelTextColorChanged) @@ -43,7 +43,7 @@ class QT_DATAVISUALIZATION_EXPORT Q3DTheme : public QObject Q_PROPERTY(QColor singleHighlightColor READ singleHighlightColor WRITE setSingleHighlightColor NOTIFY singleHighlightColorChanged) Q_PROPERTY(QColor multiHighlightColor READ multiHighlightColor WRITE setMultiHighlightColor NOTIFY multiHighlightColorChanged) Q_PROPERTY(QColor lightColor READ lightColor WRITE setLightColor NOTIFY lightColorChanged) // TODO: Not used yet - Q_PROPERTY(QLinearGradient baseGradient READ baseGradient WRITE setBaseGradient NOTIFY baseGradientChanged) + Q_PROPERTY(QList baseGradients READ baseGradients WRITE setBaseGradients NOTIFY baseGradientsChanged) Q_PROPERTY(QLinearGradient singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged) Q_PROPERTY(QLinearGradient multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged) Q_PROPERTY(float lightStrength READ lightStrength WRITE setLightStrength NOTIFY lightStrengthChanged) @@ -84,8 +84,8 @@ public: void setType(Theme themeType); Theme type() const; - void setBaseColor(const QColor &color); - QColor baseColor() const; + void setBaseColors(const QList &colors); + QList baseColors() const; void setBackgroundColor(const QColor &color); QColor backgroundColor() const; @@ -111,8 +111,8 @@ public: void setLightColor(const QColor &color); QColor lightColor() const; - void setBaseGradient(const QLinearGradient &gradient); - QLinearGradient baseGradient() const; + void setBaseGradients(const QList &gradients); + QList baseGradients() const; void setSingleHighlightGradient(const QLinearGradient &gradient); QLinearGradient singleHighlightGradient() const; @@ -149,7 +149,7 @@ public: signals: void typeChanged(Theme themeType); - void baseColorChanged(QColor color); + void baseColorsChanged(QList colors); void backgroundColorChanged(QColor color); void windowColorChanged(QColor color); void labelTextColorChanged(QColor color); @@ -158,7 +158,7 @@ signals: void singleHighlightColorChanged(QColor color); void multiHighlightColorChanged(QColor color); void lightColorChanged(QColor color); - void baseGradientChanged(QLinearGradient gradient); + void baseGradientsChanged(QList gradients); void singleHighlightGradientChanged(QLinearGradient gradient); void multiHighlightGradientChanged(QLinearGradient gradient); void lightStrengthChanged(float strength); diff --git a/src/datavisualization/theme/q3dtheme_p.h b/src/datavisualization/theme/q3dtheme_p.h index 1d2032fb..c9f59d99 100644 --- a/src/datavisualization/theme/q3dtheme_p.h +++ b/src/datavisualization/theme/q3dtheme_p.h @@ -105,7 +105,7 @@ public: Q3DThemeDirtyBitField m_dirtyBits; - QColor m_baseColor; + QList m_baseColors; QColor m_backgroundColor; QColor m_windowColor; QColor m_textColor; @@ -114,7 +114,7 @@ public: QColor m_singleHighlightColor; QColor m_multiHighlightColor; QColor m_lightColor; - QLinearGradient m_baseGradient; + QList m_baseGradients; QLinearGradient m_singleHighlightGradient; QLinearGradient m_multiHighlightGradient; float m_lightStrength; diff --git a/src/datavisualization/theme/thememanager.cpp b/src/datavisualization/theme/thememanager.cpp index 9ab82441..cefbb897 100644 --- a/src/datavisualization/theme/thememanager.cpp +++ b/src/datavisualization/theme/thememanager.cpp @@ -68,14 +68,14 @@ void ThemeManager::connectThemeSignals() { connect(m_theme.data(), &Q3DTheme::colorStyleChanged, m_controller, &Abstract3DController::handleThemeColorStyleChanged); - connect(m_theme.data(), &Q3DTheme::baseColorChanged, - m_controller, &Abstract3DController::handleThemeBaseColorChanged); + connect(m_theme.data(), &Q3DTheme::baseColorsChanged, + m_controller, &Abstract3DController::handleThemeBaseColorsChanged); connect(m_theme.data(), &Q3DTheme::singleHighlightColorChanged, m_controller, &Abstract3DController::handleThemeSingleHighlightColorChanged); connect(m_theme.data(), &Q3DTheme::multiHighlightColorChanged, m_controller, &Abstract3DController::handleThemeMultiHighlightColorChanged); - connect(m_theme.data(), &Q3DTheme::baseGradientChanged, - m_controller, &Abstract3DController::handleThemeBaseGradientChanged); + connect(m_theme.data(), &Q3DTheme::baseGradientsChanged, + m_controller, &Abstract3DController::handleThemeBaseGradientsChanged); connect(m_theme.data(), &Q3DTheme::singleHighlightGradientChanged, m_controller, &Abstract3DController::handleThemeSingleHighlightGradientChanged); connect(m_theme.data(), &Q3DTheme::multiHighlightGradientChanged, @@ -92,14 +92,18 @@ 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 baseColors; + baseColors.append(QColor(QRgb(0x80c342))); setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); setLabelBackgroundEnabled(true); setLightColor(Qt::white); - setBaseColor(QColor(QRgb(0x80c342))); + setBaseColors(baseColors); setBackgroundColor(QColor(QRgb(0xffffff))); setWindowColor(QColor(QRgb(0xffffff))); setTextColor(QColor(QRgb(0x35322f))); @@ -120,7 +124,9 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) color.setBlue(0x42 * 0.7); gradient.setColorAt(0.0, color); gradient.setColorAt(1.0, QColor(QRgb(0x80c342))); - setBaseGradient(gradient); + QList baseGradients; + baseGradients.append(gradient); + setBaseGradients(baseGradients); color.setRed(0x14 * 0.7); color.setGreen(0xaa * 0.7); color.setBlue(0xff * 0.7); @@ -137,12 +143,14 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) } case Q3DTheme::ThemePrimaryColors: { + QList baseColors; + baseColors.append(QColor(QRgb(0xffe400))); setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); setLabelBackgroundEnabled(true); setLightColor(Qt::white); - setBaseColor(QColor(QRgb(0xffe400))); + setBaseColors(baseColors); setBackgroundColor(QColor(QRgb(0xffffff))); setWindowColor(QColor(QRgb(0xffffff))); setTextColor(QColor(QRgb(0x000000))); @@ -163,7 +171,9 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) color.setBlue(0x00); gradient.setColorAt(0.0, color); gradient.setColorAt(1.0, QColor(QRgb(0xffe400))); - setBaseGradient(gradient); + QList baseGradients; + baseGradients.append(gradient); + setBaseGradients(baseGradients); color.setRed(0x27 * 0.7); color.setGreen(0xbe * 0.7); color.setBlue(0xee * 0.7); @@ -180,12 +190,14 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) } case Q3DTheme::ThemeDigia: { + QList baseColors; + baseColors.append(QColor(QRgb(0xcccccc))); setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); setLabelBackgroundEnabled(true); setLightColor(Qt::white); - setBaseColor(QColor(QRgb(0xcccccc))); + setBaseColors(baseColors); setBackgroundColor(QColor(QRgb(0xffffff))); setWindowColor(QColor(QRgb(0xffffff))); setTextColor(QColor(QRgb(0x000000))); @@ -206,7 +218,9 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) color.setBlue(0xcc * 0.7); gradient.setColorAt(0.0, color); gradient.setColorAt(1.0, QColor(QRgb(0xcccccc))); - setBaseGradient(gradient); + QList baseGradients; + baseGradients.append(gradient); + setBaseGradients(baseGradients); color.setRed(0xfa * 0.7); color.setGreen(0x00); color.setBlue(0x00); @@ -223,12 +237,14 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) } case Q3DTheme::ThemeStoneMoss: { + QList baseColors; + baseColors.append(QColor(QRgb(0xbeb32b))); setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); setLabelBackgroundEnabled(true); setLightColor(Qt::white); - setBaseColor(QColor(QRgb(0xbeb32b))); + setBaseColors(baseColors); setBackgroundColor(QColor(QRgb(0x4d4d4f))); setWindowColor(QColor(QRgb(0x4d4d4f))); setTextColor(QColor(QRgb(0xffffff))); @@ -249,7 +265,9 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) color.setBlue(0x2b * 0.7); gradient.setColorAt(0.0, color); gradient.setColorAt(1.0, QColor(QRgb(0xbeb32b))); - setBaseGradient(gradient); + QList baseGradients; + baseGradients.append(gradient); + setBaseGradients(baseGradients); color.setRed(0xfb* 0.7); color.setGreen(0xf6 * 0.7); color.setBlue(0xd6 * 0.7); @@ -266,12 +284,14 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) } case Q3DTheme::ThemeArmyBlue: { + QList baseColors; + baseColors.append(QColor(QRgb(0x495f76))); setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); setLabelBackgroundEnabled(true); setLightColor(Qt::white); - setBaseColor(QColor(QRgb(0x495f76))); + setBaseColors(baseColors); setBackgroundColor(QColor(QRgb(0xd5d6d7))); setWindowColor(QColor(QRgb(0xd5d6d7))); setTextColor(QColor(QRgb(0x000000))); @@ -292,7 +312,9 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) color.setBlue(0x76 * 0.7); gradient.setColorAt(0.0, color); gradient.setColorAt(1.0, QColor(QRgb(0x495f76))); - setBaseGradient(gradient); + QList baseGradients; + baseGradients.append(gradient); + setBaseGradients(baseGradients); color.setRed(0x2a * 0.7); color.setGreen(0xa2 * 0.7); color.setBlue(0xf9 * 0.7); @@ -309,12 +331,14 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) } case Q3DTheme::ThemeRetro: { + QList baseColors; + baseColors.append(QColor(QRgb(0x533b23))); setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); setLabelBackgroundEnabled(true); setLightColor(Qt::white); - setBaseColor(QColor(QRgb(0x533b23))); + setBaseColors(baseColors); setBackgroundColor(QColor(QRgb(0xe9e2ce))); setWindowColor(QColor(QRgb(0xe9e2ce))); setTextColor(QColor(QRgb(0x000000))); @@ -335,7 +359,9 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) color.setBlue(0x23 * 0.7); gradient.setColorAt(0.0, color); gradient.setColorAt(1.0, QColor(QRgb(0x533b23))); - setBaseGradient(gradient); + QList baseGradients; + baseGradients.append(gradient); + setBaseGradients(baseGradients); color.setRed(0x8e * 0.7); color.setGreen(0xa3 * 0.7); color.setBlue(0x17 * 0.7); @@ -352,12 +378,14 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) } case Q3DTheme::ThemeEbony: { + QList baseColors; + baseColors.append(QColor(QRgb(0xffffff))); setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); setLabelBackgroundEnabled(true); setLightColor(Qt::white); - setBaseColor(QColor(QRgb(0xffffff))); + setBaseColors(baseColors); setBackgroundColor(QColor(QRgb(0x000000))); setWindowColor(QColor(QRgb(0x000000))); setTextColor(QColor(QRgb(0xaeadac))); @@ -378,7 +406,9 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) color.setBlue(0xff * 0.7); gradient.setColorAt(0.0, color); gradient.setColorAt(1.0, QColor(QRgb(0xffffff))); - setBaseGradient(gradient); + QList baseGradients; + baseGradients.append(gradient); + setBaseGradients(baseGradients); color.setRed(0xf5 * 0.7); color.setGreen(0xdc * 0.7); color.setBlue(0x0d * 0.7); @@ -395,12 +425,14 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) } case Q3DTheme::ThemeIsabelle: { + QList baseColors; + baseColors.append(QColor(QRgb(0xf9d900))); setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); setLabelBackgroundEnabled(true); setLightColor(Qt::white); - setBaseColor(QColor(QRgb(0xf9d900))); + setBaseColors(baseColors); setBackgroundColor(QColor(QRgb(0x000000))); setWindowColor(QColor(QRgb(0x000000))); setTextColor(QColor(QRgb(0xaeadac))); @@ -421,7 +453,9 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) color.setBlue(0x00); gradient.setColorAt(0.0, color); gradient.setColorAt(1.0, QColor(QRgb(0xf9d900))); - setBaseGradient(gradient); + QList baseGradients; + baseGradients.append(gradient); + setBaseGradients(baseGradients); color.setRed(0xff * 0.7); color.setGreen(0xf7 * 0.7); color.setBlue(0xcc * 0.7); @@ -441,10 +475,10 @@ void ThemeManager::useTheme(Q3DTheme::Theme type) } } -void ThemeManager::setBaseColor(const QColor &color) +void ThemeManager::setBaseColors(const QList &colors) { if (!m_theme->d_ptr->m_dirtyBits.baseColorDirty) - m_theme->setBaseColor(color); + m_theme->setBaseColors(colors); } void ThemeManager::setBackgroundColor(const QColor &color) @@ -495,10 +529,10 @@ void ThemeManager::setLightColor(const QColor &color) m_theme->setLightColor(color); } -void ThemeManager::setBaseGradient(const QLinearGradient &gradient) +void ThemeManager::setBaseGradients(const QList &gradients) { if (!m_theme->d_ptr->m_dirtyBits.baseGradientDirty) - m_theme->setBaseGradient(gradient); + m_theme->setBaseGradients(gradients); } void ThemeManager::setSingleHighlightGradient(const QLinearGradient &gradient) diff --git a/src/datavisualization/theme/thememanager_p.h b/src/datavisualization/theme/thememanager_p.h index 4a394a4a..a20154df 100644 --- a/src/datavisualization/theme/thememanager_p.h +++ b/src/datavisualization/theme/thememanager_p.h @@ -48,7 +48,7 @@ public: protected: void connectThemeSignals(); void useTheme(Q3DTheme::Theme type); - void setBaseColor(const QColor &color); + void setBaseColors(const QList &colors); void setBackgroundColor(const QColor &color); void setWindowColor(const QColor &color); void setTextColor(const QColor &color); @@ -57,7 +57,7 @@ protected: void setSingleHighlightColor(const QColor &color); void setMultiHighlightColor(const QColor &color); void setLightColor(const QColor &color); - void setBaseGradient(const QLinearGradient &gradient); + void setBaseGradients(const QList &gradients); void setSingleHighlightGradient(const QLinearGradient &gradient); void setMultiHighlightGradient(const QLinearGradient &gradient); void setLightStrength(float strength); diff --git a/src/datavisualizationqml2/datavisualizationqml2.pro b/src/datavisualizationqml2/datavisualizationqml2.pro index b9785f44..938a8a5c 100644 --- a/src/datavisualizationqml2/datavisualizationqml2.pro +++ b/src/datavisualizationqml2/datavisualizationqml2.pro @@ -27,7 +27,8 @@ SOURCES += \ colorgradient.cpp \ declarativeseries.cpp \ declarativerenderer.cpp \ - declarativetheme.cpp + declarativetheme.cpp \ + declarativecolor.cpp HEADERS += \ datavisualizationqml2_plugin.h \ @@ -38,7 +39,8 @@ HEADERS += \ colorgradient_p.h \ declarativeseries_p.h \ declarativerenderer_p.h \ - declarativetheme_p.h + declarativetheme_p.h \ + declarativecolor_p.h OTHER_FILES = qmldir diff --git a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp index 2ca23643..ceefa91e 100644 --- a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp +++ b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp @@ -73,6 +73,7 @@ void Datavis3Dqml2Plugin::registerTypes(const char *uri) qmlRegisterType(uri, 1, 0, "ColorGradientStop"); qmlRegisterType(uri, 1, 0, "ColorGradient"); + qmlRegisterType(uri, 1, 0, "Color"); qmlRegisterType(uri, 1, 0, "Theme3D"); diff --git a/src/datavisualizationqml2/datavisualizationqml2_plugin.h b/src/datavisualizationqml2/datavisualizationqml2_plugin.h index 7a30d65d..25c06364 100644 --- a/src/datavisualizationqml2/datavisualizationqml2_plugin.h +++ b/src/datavisualizationqml2/datavisualizationqml2_plugin.h @@ -41,6 +41,7 @@ #include "q3dtheme.h" #include "declarativetheme_p.h" #include "qabstract3dinputhandler.h" +#include "declarativecolor_p.h" #include @@ -83,6 +84,8 @@ QML_DECLARE_TYPE(DeclarativeSurface3DSeries) QML_DECLARE_TYPE(ColorGradientStop) QML_DECLARE_TYPE(ColorGradient) +QML_DECLARE_TYPE(DeclarativeColor) + QML_DECLARE_TYPE(Q3DTheme) QML_DECLARE_TYPE(DeclarativeTheme3D) diff --git a/src/datavisualizationqml2/declarativecolor.cpp b/src/datavisualizationqml2/declarativecolor.cpp new file mode 100644 index 00000000..e15edd45 --- /dev/null +++ b/src/datavisualizationqml2/declarativecolor.cpp @@ -0,0 +1,29 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVisualization module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "declarativecolor_p.h" + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +DeclarativeColor::DeclarativeColor(QObject *parent) + : QObject(parent) +{ + +} + +QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativecolor_p.h b/src/datavisualizationqml2/declarativecolor_p.h new file mode 100644 index 00000000..e500f794 --- /dev/null +++ b/src/datavisualizationqml2/declarativecolor_p.h @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVisualization module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtDataVisualization API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef DECLARATIVECOLOR_P_H +#define DECLARATIVECOLOR_P_H + +#include "datavisualizationglobal_p.h" +#include +#include + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +class DeclarativeColor : public QObject, public QColor +{ + Q_OBJECT + +public: + DeclarativeColor(QObject *parent = 0); + +}; + +QT_DATAVISUALIZATION_END_NAMESPACE + +#endif diff --git a/src/datavisualizationqml2/declarativetheme.cpp b/src/datavisualizationqml2/declarativetheme.cpp index eb7fd2cc..263fa62e 100644 --- a/src/datavisualizationqml2/declarativetheme.cpp +++ b/src/datavisualizationqml2/declarativetheme.cpp @@ -22,7 +22,7 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE DeclarativeTheme3D::DeclarativeTheme3D(QObject *parent) : Q3DTheme(parent), - m_baseGradient(0), + m_gradients(QList()), m_singleHLGradient(0), m_multiHLGradient(0) { @@ -45,48 +45,16 @@ void DeclarativeTheme3D::appendSeriesChildren(QQmlListProperty *list, Q // Nothing to do, seriesChildren is there only to enable scoping gradient items in Theme3D item. } -void DeclarativeTheme3D::handleBaseGradientUpdate() -{ - if (m_baseGradient) - setThemeGradient(*m_baseGradient, GradientTypeBase); -} - void DeclarativeTheme3D::handleSingleHLGradientUpdate() { if (m_singleHLGradient) - setThemeGradient(*m_singleHLGradient, GradientTypeSingleHL); + setThemeGradient(m_singleHLGradient, GradientTypeSingleHL); } void DeclarativeTheme3D::handleMultiHLGradientUpdate() { if (m_multiHLGradient) - setThemeGradient(*m_multiHLGradient, GradientTypeMultiHL); -} - -void DeclarativeTheme3D::setBaseGradient(ColorGradient *gradient) -{ - // connect new / disconnect old - if (gradient != m_baseGradient) { - if (m_baseGradient) - QObject::disconnect(m_baseGradient, 0, this, 0); - - m_baseGradient = gradient; - - if (m_baseGradient) { - QObject::connect(m_baseGradient, &ColorGradient::updated, this, - &DeclarativeTheme3D::handleBaseGradientUpdate); - } - - emit baseGradientChanged(m_baseGradient); - } - - if (m_baseGradient) - setThemeGradient(*m_baseGradient, GradientTypeBase); -} - -ColorGradient *DeclarativeTheme3D::baseGradient() const -{ - return m_baseGradient; + setThemeGradient(m_multiHLGradient, GradientTypeMultiHL); } void DeclarativeTheme3D::setSingleHighlightGradient(ColorGradient *gradient) @@ -107,7 +75,7 @@ void DeclarativeTheme3D::setSingleHighlightGradient(ColorGradient *gradient) } if (m_singleHLGradient) - setThemeGradient(*m_singleHLGradient, GradientTypeSingleHL); + setThemeGradient(m_singleHLGradient, GradientTypeSingleHL); } ColorGradient *DeclarativeTheme3D::singleHighlightGradient() const @@ -133,7 +101,7 @@ void DeclarativeTheme3D::setMultiHighlightGradient(ColorGradient *gradient) } if (m_multiHLGradient) - setThemeGradient(*m_baseGradient, GradientTypeMultiHL); + setThemeGradient(m_multiHLGradient, GradientTypeMultiHL); } ColorGradient *DeclarativeTheme3D::multiHighlightGradient() const @@ -141,11 +109,28 @@ ColorGradient *DeclarativeTheme3D::multiHighlightGradient() const return m_multiHLGradient; } -void DeclarativeTheme3D::setThemeGradient(const ColorGradient &gradient, GradientType type) +void DeclarativeTheme3D::setThemeGradient(ColorGradient *gradient, GradientType type) +{ + QLinearGradient newGradient = convertGradient(gradient); + + switch (type) { + case GradientTypeSingleHL: + Q3DTheme::setSingleHighlightGradient(newGradient); + break; + case GradientTypeMultiHL: + break; + Q3DTheme::setMultiHighlightGradient(newGradient); + default: + qWarning("Incorrect usage. Type may be GradientTypeSingleHL or GradientTypeMultiHL."); + break; + } +} + +QLinearGradient DeclarativeTheme3D::convertGradient(ColorGradient *gradient) { QLinearGradient newGradient; QGradientStops stops; - QList qmlstops = gradient.m_stops; + QList qmlstops = gradient->m_stops; // Get sorted gradient stops for (int i = 0; i < qmlstops.size(); i++) { @@ -156,19 +141,104 @@ void DeclarativeTheme3D::setThemeGradient(const ColorGradient &gradient, Gradien } newGradient.setStops(stops); - switch (type) { - case GradientTypeBase: - Q3DTheme::setBaseGradient(newGradient); - break; - case GradientTypeSingleHL: - Q3DTheme::setSingleHighlightGradient(newGradient); - break; - case GradientTypeMultiHL: - break; - Q3DTheme::setMultiHighlightGradient(newGradient); - default: - break; - } + + return newGradient; +} + +//void DeclarativeTheme3D::addColor(const DeclarativeColor &color) +//{ +// QList list = Q3DTheme::baseColors(); +// list.append(color); +// Q3DTheme::setBaseColors(list); +//} + +//QList DeclarativeTheme3D::colorList() const +//{ +// return Q3DTheme::baseColors(); +//} + +//void DeclarativeTheme3D::clearColors() +//{ +// Q3DTheme::setBaseColors(QList()); +//} + +void DeclarativeTheme3D::addGradient(ColorGradient *gradient) +{ + m_gradients.append(gradient); + QList list = Q3DTheme::baseGradients(); + list.append(convertGradient(gradient)); + Q3DTheme::setBaseGradients(list); +} + +QList DeclarativeTheme3D::gradientList() const +{ + return m_gradients; +} + +void DeclarativeTheme3D::clearGradients() +{ + m_gradients.clear(); + Q3DTheme::setBaseGradients(QList()); +} + +//QQmlListProperty DeclarativeTheme3D::baseColors() +//{ +// return QQmlListProperty(this, this, +// &DeclarativeTheme3D::appendBaseColorsFunc, +// &DeclarativeTheme3D::countBaseColorsFunc, +// &DeclarativeTheme3D::atBaseColorsFunc, +// &DeclarativeTheme3D::clearBaseColorsFunc); +//} + +//void DeclarativeTheme3D::appendBaseColorsFunc(QQmlListProperty *list, DeclarativeColor *color) +//{ +// reinterpret_cast(list->data)->addColor(*color); +//} + +//int DeclarativeTheme3D::countBaseColorsFunc(QQmlListProperty *list) +//{ +// return reinterpret_cast(list->data)->colorList().size(); +//} + +//DeclarativeColor *DeclarativeTheme3D::atBaseColorsFunc(QQmlListProperty *list, int index) +//{ +// return &(reinterpret_cast(list->data)->colorList()[index]); +//} + +//void DeclarativeTheme3D::clearBaseColorsFunc(QQmlListProperty *list) +//{ +// reinterpret_cast(list->data)->clearGradients(); +//} + +QQmlListProperty DeclarativeTheme3D::baseGradients() +{ + return QQmlListProperty(this, this, + &DeclarativeTheme3D::appendBaseGradientsFunc, + &DeclarativeTheme3D::countBaseGradientsFunc, + &DeclarativeTheme3D::atBaseGradientsFunc, + &DeclarativeTheme3D::clearBaseGradientsFunc); +} + +void DeclarativeTheme3D::appendBaseGradientsFunc(QQmlListProperty *list, + ColorGradient *gradient) +{ + reinterpret_cast(list->data)->addGradient(gradient); +} + +int DeclarativeTheme3D::countBaseGradientsFunc(QQmlListProperty *list) +{ + return reinterpret_cast(list->data)->gradientList().size(); +} + +ColorGradient *DeclarativeTheme3D::atBaseGradientsFunc(QQmlListProperty *list, + int index) +{ + return reinterpret_cast(list->data)->gradientList().at(index); +} + +void DeclarativeTheme3D::clearBaseGradientsFunc(QQmlListProperty *list) +{ + reinterpret_cast(list->data)->clearGradients(); } QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativetheme_p.h b/src/datavisualizationqml2/declarativetheme_p.h index 9bbb518a..75ab9514 100644 --- a/src/datavisualizationqml2/declarativetheme_p.h +++ b/src/datavisualizationqml2/declarativetheme_p.h @@ -31,6 +31,7 @@ #include "datavisualizationglobal_p.h" #include "colorgradient_p.h" +//#include "declarativecolor_p.h" #include "q3dtheme.h" QT_DATAVISUALIZATION_BEGIN_NAMESPACE @@ -39,7 +40,8 @@ class DeclarativeTheme3D : public Q3DTheme { Q_OBJECT Q_PROPERTY(QQmlListProperty seriesChildren READ seriesChildren) - Q_PROPERTY(ColorGradient *baseGradient READ baseGradient WRITE setBaseGradient NOTIFY baseGradientChanged) +// Q_PROPERTY(QQmlListProperty baseColors READ baseColors) + Q_PROPERTY(QQmlListProperty baseGradients READ baseGradients) Q_PROPERTY(ColorGradient *singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged) Q_PROPERTY(ColorGradient *multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged) Q_CLASSINFO("DefaultProperty", "seriesChildren") @@ -51,8 +53,19 @@ public: QQmlListProperty seriesChildren(); static void appendSeriesChildren(QQmlListProperty *list, QObject *element); - void setBaseGradient(ColorGradient *gradient); - ColorGradient *baseGradient() const; +// QQmlListProperty baseColors(); +// static void appendBaseColorsFunc(QQmlListProperty *list, +// DeclarativeColor *color); +// static int countBaseColorsFunc(QQmlListProperty *list); +// static DeclarativeColor *atBaseColorsFunc(QQmlListProperty *list, int index); +// static void clearBaseColorsFunc(QQmlListProperty *list); + + QQmlListProperty baseGradients(); + static void appendBaseGradientsFunc(QQmlListProperty *list, + ColorGradient *gradient); + static int countBaseGradientsFunc(QQmlListProperty *list); + static ColorGradient *atBaseGradientsFunc(QQmlListProperty *list, int index); + static void clearBaseGradientsFunc(QQmlListProperty *list); void setSingleHighlightGradient(ColorGradient *gradient); ColorGradient *singleHighlightGradient() const; @@ -61,12 +74,10 @@ public: ColorGradient *multiHighlightGradient() const; signals: - void baseGradientChanged(ColorGradient *gradient); void singleHighlightGradientChanged(ColorGradient *gradient); void multiHighlightGradientChanged(ColorGradient *gradient); protected: - void handleBaseGradientUpdate(); void handleSingleHLGradientUpdate(); void handleMultiHLGradientUpdate(); @@ -77,9 +88,16 @@ protected: }; private: - void setThemeGradient(const ColorGradient &gradient, GradientType type); - - ColorGradient *m_baseGradient; // Not owned +// void addColor(const DeclarativeColor &color); +// QList colorList() const; +// void clearColors(); + void addGradient(ColorGradient *gradient); + QList gradientList() const; + void clearGradients(); + void setThemeGradient(ColorGradient *gradient, GradientType type); + QLinearGradient convertGradient(ColorGradient *gradient); + + QList m_gradients; // Not owned ColorGradient *m_singleHLGradient; // Not owned ColorGradient *m_multiHLGradient; // Not owned }; -- cgit v1.2.3