From a61c6ee6533dca6723320c3955773cc5ccbfe2fa Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 5 Nov 2013 13:57:18 +0200 Subject: Gradient support Part 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TODO: - Finish scatter - QML (maybe left until data set is sorted, though) Change-Id: I87a8117cb29f147080e0662c55b1098cb2e71689 Reviewed-by: Tomi Korpipää --- .../engine/abstract3dcontroller.cpp | 147 +++++++++++++++++- .../engine/abstract3dcontroller_p.h | 117 ++++++++++----- .../engine/abstract3drenderer.cpp | 73 ++++++++- .../engine/abstract3drenderer_p.h | 23 ++- src/datavisualization/engine/bars3drenderer.cpp | 114 ++++++++------ src/datavisualization/engine/bars3drenderer_p.h | 1 + src/datavisualization/engine/q3dbars.cpp | 167 ++++++++++++++++++--- src/datavisualization/engine/q3dbars.h | 37 ++++- src/datavisualization/engine/q3dscatter.cpp | 146 +++++++++++++++++- src/datavisualization/engine/q3dscatter.h | 31 ++++ src/datavisualization/engine/shaders/colorOnY.frag | 8 +- .../engine/shaders/colorOnY_ES2.frag | 8 +- .../engine/shaders/shadowNoTexColorOnY.frag | 8 +- .../engine/surface3dcontroller.cpp | 2 - src/datavisualization/engine/surface3drenderer.cpp | 13 +- src/datavisualization/engine/theme.cpp | 3 +- .../global/datavisualizationglobal_p.h | 24 ++- .../global/qdatavisualizationenums.h | 7 + .../global/qtdatavisualizationenums.qdoc | 15 ++ src/datavisualization/utils/shaderhelper.cpp | 17 ++- src/datavisualization/utils/shaderhelper_p.h | 4 + src/datavisualization/utils/texturehelper.cpp | 13 ++ src/datavisualization/utils/texturehelper_p.h | 2 + src/datavisualizationqml2/declarativebars.cpp | 2 +- src/datavisualizationqml2/declarativescatter.cpp | 2 +- tests/barstest/chart.cpp | 52 ++++++- tests/barstest/chart.h | 1 + tests/barstest/main.cpp | 21 ++- tests/spectrum/spectrumapp/main.cpp | 2 +- 29 files changed, 905 insertions(+), 155 deletions(-) diff --git a/src/datavisualization/engine/abstract3dcontroller.cpp b/src/datavisualization/engine/abstract3dcontroller.cpp index 8d870716..44a9e8b2 100644 --- a/src/datavisualization/engine/abstract3dcontroller.cpp +++ b/src/datavisualization/engine/abstract3dcontroller.cpp @@ -50,7 +50,8 @@ Abstract3DController::Abstract3DController(QRect boundRect, QObject *parent) : m_renderer(0), m_isDataDirty(true), m_data(0), - m_renderPending(false) + m_renderPending(false), + m_colorStyle(QDataVis::ColorStyleUniform) { m_theme.useTheme(QDataVis::ThemeQt); @@ -114,11 +115,47 @@ void Abstract3DController::synchDataToRenderer() m_changeTracker.inputStateChanged = false; } + // TODO: Renderer doesn't need to know the theme, so remove this bit entirely (QTRD-2538) if (m_changeTracker.themeChanged) { m_renderer->updateTheme(m_theme); m_changeTracker.themeChanged = false; } + if (m_changeTracker.colorStyleChanged) { + m_renderer->updateColorStyle(m_colorStyle); + m_changeTracker.colorStyleChanged = false; + } + + if (m_changeTracker.objectColorChanged) { + m_renderer->updateObjectColor(m_objectColor); + m_changeTracker.objectColorChanged = false; + } + + if (m_changeTracker.objectGradientChanged) { + m_renderer->updateObjectGradient(m_objectGradient); + m_changeTracker.objectGradientChanged = false; + } + + if (m_changeTracker.singleHighlightColorChanged) { + m_renderer->updateSingleHighlightColor(m_singleHighlightColor); + m_changeTracker.singleHighlightColorChanged = false; + } + + if (m_changeTracker.singleHighlightGradientChanged) { + m_renderer->updateSingleHighlightGradient(m_singleHighlightGradient); + m_changeTracker.singleHighlightGradientChanged = false; + } + + if (m_changeTracker.multiHighlightColorChanged) { + m_renderer->updateMultiHighlightColor(m_multiHighlightColor); + m_changeTracker.multiHighlightColorChanged = false; + } + + if (m_changeTracker.multiHighlightGradientChanged) { + m_renderer->updateMultiHighlightGradient(m_multiHighlightGradient); + m_changeTracker.multiHighlightGradientChanged = false; + } + if (m_changeTracker.fontChanged) { m_renderer->updateFont(m_font); m_changeTracker.fontChanged = false; @@ -677,18 +714,109 @@ void Abstract3DController::setZoomLevel(int zoomLevel) emitNeedRender(); } -void Abstract3DController::setObjectColor(const QColor &baseColor, bool uniform) +void Abstract3DController::setColorStyle(QDataVis::ColorStyle style) +{ + if (style != m_colorStyle) { + m_colorStyle = style; + m_changeTracker.colorStyleChanged = true; + emitNeedRender(); + emit colorStyleChanged(style); + } +} + +QDataVis::ColorStyle Abstract3DController::colorStyle() const { - m_theme.m_baseColor = baseColor; - m_theme.m_uniformColor = uniform; + return m_colorStyle; +} - m_changeTracker.themeChanged = true; - emitNeedRender(); +void Abstract3DController::setObjectColor(const QColor &color) +{ + if (color != m_objectColor) { + m_objectColor = color; + m_changeTracker.objectColorChanged = true; + emitNeedRender(); + emit objectColorChanged(color); + } } QColor Abstract3DController::objectColor() const { - return m_theme.m_baseColor; + return m_objectColor; +} + +void Abstract3DController::setObjectGradient(const QLinearGradient &gradient) +{ + if (gradient != m_objectGradient) { + m_objectGradient = gradient; + m_changeTracker.objectGradientChanged = true; + emitNeedRender(); + emit objectGradientChanged(gradient); + } +} + +QLinearGradient Abstract3DController::objectGradient() const +{ + return m_objectGradient; +} + +void Abstract3DController::setSingleHighlightColor(const QColor &color) +{ + if (color != m_singleHighlightColor) { + m_singleHighlightColor = color; + m_changeTracker.singleHighlightColorChanged = true; + emitNeedRender(); + emit singleHighlightColorChanged(color); + } +} + +QColor Abstract3DController::singleHighlightColor() const +{ + return m_singleHighlightColor; +} + +void Abstract3DController::setSingleHighlightGradient(const QLinearGradient &gradient) +{ + if (gradient != m_singleHighlightGradient) { + m_singleHighlightGradient = gradient; + m_changeTracker.singleHighlightGradientChanged = true; + emitNeedRender(); + emit singleHighlightGradientChanged(gradient); + } +} + +QLinearGradient Abstract3DController::singleHighlightGradient() const +{ + return m_singleHighlightGradient; +} + +void Abstract3DController::setMultiHighlightColor(const QColor &color) +{ + if (color != m_multiHighlightColor) { + m_multiHighlightColor = color; + m_changeTracker.multiHighlightColorChanged = true; + emitNeedRender(); + emit multiHighlightColorChanged(color); + } +} + +QColor Abstract3DController::multiHighlightColor() const +{ + return m_multiHighlightColor; +} + +void Abstract3DController::setMultiHighlightGradient(const QLinearGradient &gradient) +{ + if (gradient != m_multiHighlightGradient) { + m_multiHighlightGradient = gradient; + m_changeTracker.multiHighlightGradientChanged = true; + emitNeedRender(); + emit multiHighlightGradientChanged(gradient); + } +} + +QLinearGradient Abstract3DController::multiHighlightGradient() const +{ + return m_multiHighlightGradient; } void Abstract3DController::setTheme(QDataVis::Theme theme) @@ -696,6 +824,11 @@ void Abstract3DController::setTheme(QDataVis::Theme theme) if (theme != m_theme.theme()) { m_theme.useTheme(theme); m_changeTracker.themeChanged = true; + // TODO: set all colors/styles here (QTRD-2538) + setColorStyle(QDataVis::ColorStyleUniform); + setObjectColor(m_theme.m_baseColor); + setSingleHighlightColor(m_theme.m_highlightBarColor); + setMultiHighlightColor(m_theme.m_highlightRowColor); emit themeChanged(theme); emitNeedRender(); } diff --git a/src/datavisualization/engine/abstract3dcontroller_p.h b/src/datavisualization/engine/abstract3dcontroller_p.h index 7dc5d8bc..d68d33e2 100644 --- a/src/datavisualization/engine/abstract3dcontroller_p.h +++ b/src/datavisualization/engine/abstract3dcontroller_p.h @@ -39,6 +39,7 @@ #include "q3dbox.h" #include +#include class QFont; @@ -48,41 +49,48 @@ class CameraHelper; class Abstract3DRenderer; struct Abstract3DChangeBitField { - bool positionChanged : 1; - bool zoomLevelChanged : 1; - bool themeChanged : 1; - bool fontChanged : 1; - bool labelStyleChanged : 1; - bool boundingRectChanged : 1; - bool sizeChanged : 1; - bool shadowQualityChanged : 1; - bool selectionModeChanged : 1; - bool objFileChanged : 1; - bool gridEnabledChanged : 1; - bool backgroundEnabledChanged : 1; - bool axisXTypeChanged : 1; - bool axisYTypeChanged : 1; - bool axisZTypeChanged : 1; - bool axisXTitleChanged : 1; - bool axisYTitleChanged : 1; - bool axisZTitleChanged : 1; - bool axisXLabelsChanged : 1; - bool axisYLabelsChanged : 1; - bool axisZLabelsChanged : 1; - bool axisXRangeChanged : 1; - bool axisYRangeChanged : 1; - bool axisZRangeChanged : 1; - bool axisXSegmentCountChanged : 1; - bool axisYSegmentCountChanged : 1; - bool axisZSegmentCountChanged : 1; - bool axisXSubSegmentCountChanged : 1; - bool axisYSubSegmentCountChanged : 1; - bool axisZSubSegmentCountChanged : 1; - bool axisXLabelFormatChanged : 1; - bool axisYLabelFormatChanged : 1; - bool axisZLabelFormatChanged : 1; - bool inputStateChanged : 1; - bool inputPositionChanged : 1; + bool positionChanged : 1; + bool zoomLevelChanged : 1; + bool themeChanged : 1; + bool fontChanged : 1; + bool labelStyleChanged : 1; + bool boundingRectChanged : 1; + bool sizeChanged : 1; + bool shadowQualityChanged : 1; + bool selectionModeChanged : 1; + bool objFileChanged : 1; + bool gridEnabledChanged : 1; + bool backgroundEnabledChanged : 1; + bool axisXTypeChanged : 1; + bool axisYTypeChanged : 1; + bool axisZTypeChanged : 1; + bool axisXTitleChanged : 1; + bool axisYTitleChanged : 1; + bool axisZTitleChanged : 1; + bool axisXLabelsChanged : 1; + bool axisYLabelsChanged : 1; + bool axisZLabelsChanged : 1; + bool axisXRangeChanged : 1; + bool axisYRangeChanged : 1; + bool axisZRangeChanged : 1; + bool axisXSegmentCountChanged : 1; + bool axisYSegmentCountChanged : 1; + bool axisZSegmentCountChanged : 1; + bool axisXSubSegmentCountChanged : 1; + bool axisYSubSegmentCountChanged : 1; + bool axisZSubSegmentCountChanged : 1; + bool axisXLabelFormatChanged : 1; + bool axisYLabelFormatChanged : 1; + bool axisZLabelFormatChanged : 1; + bool inputStateChanged : 1; + bool inputPositionChanged : 1; + bool colorStyleChanged : 1; + bool objectColorChanged : 1; + bool objectGradientChanged : 1; + bool singleHighlightColorChanged : 1; + bool singleHighlightGradientChanged: 1; + bool multiHighlightColorChanged : 1; + bool multiHighlightGradientChanged : 1; Abstract3DChangeBitField() : positionChanged(true), @@ -119,7 +127,15 @@ struct Abstract3DChangeBitField { axisYLabelFormatChanged(true), axisZLabelFormatChanged(true), inputStateChanged(true), - inputPositionChanged(true) + inputPositionChanged(true), + // Items that override values from theme default to false since we default to theme + colorStyleChanged(false), + objectColorChanged(false), + objectGradientChanged(false), + singleHighlightColorChanged(false), + singleHighlightGradientChanged(false), + multiHighlightColorChanged(false), + multiHighlightGradientChanged(false) { } }; @@ -159,6 +175,13 @@ private: bool m_isGridEnabled; QString m_objFile; Q3DScene *m_scene; + QDataVis::ColorStyle m_colorStyle; + QColor m_objectColor; + QLinearGradient m_objectGradient; + QColor m_singleHighlightColor; + QLinearGradient m_singleHighlightGradient; + QColor m_multiHighlightColor; + QLinearGradient m_multiHighlightGradient; protected: QList m_inputHandlers; // List of all added input handlers @@ -243,9 +266,20 @@ public: virtual int zoomLevel(); virtual void setZoomLevel(int zoomLevel); - // Set color if you don't want to use themes. - virtual void setObjectColor(const QColor &baseColor, bool uniform = true); + virtual void setColorStyle(QDataVis::ColorStyle style); + virtual QDataVis::ColorStyle colorStyle() const; + virtual void setObjectColor(const QColor &color); virtual QColor objectColor() const; + virtual void setObjectGradient(const QLinearGradient &gradient); + virtual QLinearGradient objectGradient() const; + virtual void setSingleHighlightColor(const QColor &color); + virtual QColor singleHighlightColor() const; + virtual void setSingleHighlightGradient(const QLinearGradient &gradient); + virtual QLinearGradient singleHighlightGradient() const; + virtual void setMultiHighlightColor(const QColor &color); + virtual QColor multiHighlightColor() const; + virtual void setMultiHighlightGradient(const QLinearGradient &gradient); + virtual QLinearGradient multiHighlightGradient() const; // Set theme (bar colors, shaders, window color, background colors, light intensity and text // colors are affected) @@ -331,6 +365,13 @@ signals: void gridVisibleChanged(bool visible); void meshFileNameChanged(QString filename); void needRender(); + void colorStyleChanged(QDataVis::ColorStyle style); + void objectColorChanged(QColor color); + void objectGradientChanged(QLinearGradient gradient); + void singleHighlightColorChanged(QColor color); + void singleHighlightGradientChanged(QLinearGradient gradient); + void multiHighlightColorChanged(QColor color); + void multiHighlightGradientChanged(QLinearGradient gradient); protected: virtual Q3DAbstractAxis *createDefaultAxis(Q3DAbstractAxis::AxisOrientation orientation); diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp index 6e3d8d81..3f49b67e 100644 --- a/src/datavisualization/engine/abstract3drenderer.cpp +++ b/src/datavisualization/engine/abstract3drenderer.cpp @@ -41,6 +41,11 @@ Abstract3DRenderer::Abstract3DRenderer(Abstract3DController *controller) m_cachedSelectionMode(QDataVis::SelectionNone), m_cachedIsGridEnabled(false), m_cachedIsBackgroundEnabled(false), + m_cachedColorStyle(QDataVis::ColorStyleUniform), + m_objectGradientTexture(0), + m_singleHighlightGradientTexture(0), + m_multiHighlightGradientTexture(0), + m_textureHelper(0), m_cachedScene(new Q3DScene()), m_selectionDirty(true), m_inputState(QDataVis::InputStateNone) @@ -59,6 +64,12 @@ Abstract3DRenderer::Abstract3DRenderer(Abstract3DController *controller) Abstract3DRenderer::~Abstract3DRenderer() { + if (m_textureHelper) { + m_textureHelper->deleteTexture(&m_objectGradientTexture); + m_textureHelper->deleteTexture(&m_singleHighlightGradientTexture); + m_textureHelper->deleteTexture(&m_multiHighlightGradientTexture); + } + delete m_drawer; delete m_textureHelper; delete m_cachedScene; @@ -184,7 +195,7 @@ void Abstract3DRenderer::reInitShaders() { #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { - if (!m_cachedTheme.m_uniformColor) { + if (m_cachedColorStyle != QDataVis::ColorStyleUniform) { initShaders(QStringLiteral(":/shaders/vertexShadow"), QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY")); } else { @@ -194,7 +205,7 @@ void Abstract3DRenderer::reInitShaders() initBackgroundShaders(QStringLiteral(":/shaders/vertexShadow"), QStringLiteral(":/shaders/fragmentShadowNoTex")); } else { - if (!m_cachedTheme.m_uniformColor) { + if (m_cachedColorStyle != QDataVis::ColorStyleUniform) { initShaders(QStringLiteral(":/shaders/vertex"), QStringLiteral(":/shaders/fragmentColorOnY")); } else { @@ -205,7 +216,7 @@ void Abstract3DRenderer::reInitShaders() QStringLiteral(":/shaders/fragment")); } #else - if (!m_cachedTheme.m_uniformColor) { + if (m_cachedColorStyle != QDataVis::ColorStyleUniform) { initShaders(QStringLiteral(":/shaders/vertexES2"), QStringLiteral(":/shaders/fragmentColorOnYES2")); } else { @@ -324,6 +335,49 @@ void Abstract3DRenderer::updateAxisLabelFormat(Q3DAbstractAxis::AxisOrientation axisCacheForOrientation(orientation).setLabelFormat(format); } +void Abstract3DRenderer::updateColorStyle(QDataVis::ColorStyle style) +{ + bool changed = (m_cachedColorStyle != style); + + m_cachedColorStyle = style; + + if (changed) + reInitShaders(); +} + +void Abstract3DRenderer::updateObjectColor(const QColor &color) +{ + m_cachedObjectColor = color; +} + +void Abstract3DRenderer::updateObjectGradient(const QLinearGradient &gradient) +{ + m_cachedObjectGradient = gradient; + fixGradient(&m_cachedObjectGradient, &m_objectGradientTexture); +} + +void Abstract3DRenderer::updateSingleHighlightColor(const QColor &color) +{ + m_cachedSingleHighlightColor = color; +} + +void Abstract3DRenderer::updateSingleHighlightGradient(const QLinearGradient &gradient) +{ + m_cachedSingleHighlightGradient = gradient; + fixGradient(&m_cachedSingleHighlightGradient, &m_singleHighlightGradientTexture); +} + +void Abstract3DRenderer::updateMultiHighlightColor(const QColor &color) +{ + m_cachedMultiHighlightColor = color; +} + +void Abstract3DRenderer::updateMultiHighlightGradient(const QLinearGradient &gradient) +{ + m_cachedMultiHighlightGradient = gradient; + fixGradient(&m_cachedMultiHighlightGradient, &m_multiHighlightGradientTexture); +} + AxisRenderCache &Abstract3DRenderer::axisCacheForOrientation(Q3DAbstractAxis::AxisOrientation orientation) { switch (orientation) { @@ -377,5 +431,18 @@ void Abstract3DRenderer::lowerShadowQuality() updateShadowQuality(newQuality); } +void Abstract3DRenderer::fixGradient(QLinearGradient *gradient, GLuint *gradientTexture) +{ + // Readjust start/stop to match gradient texture size + gradient->setStart(qreal(gradientTextureWidth), qreal(gradientTextureHeight)); + gradient->setFinalStop(0.0, 0.0); + + if (*gradientTexture) { + m_textureHelper->deleteTexture(gradientTexture); + *gradientTexture = 0; + } + + *gradientTexture = m_textureHelper->createGradientTexture(*gradient); +} QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/engine/abstract3drenderer_p.h b/src/datavisualization/engine/abstract3drenderer_p.h index 70f0dc80..838eb181 100644 --- a/src/datavisualization/engine/abstract3drenderer_p.h +++ b/src/datavisualization/engine/abstract3drenderer_p.h @@ -42,9 +42,6 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE -static const QVector3D selectionSkipColor = QVector3D(255.0f, 255.0f, 255.0f); // Selection texture's background color -static const QVector3D invalidColorVector = QVector3D(-1.0f, -1.0f, -1.0f); - class TextureHelper; class Theme; class Drawer; @@ -69,6 +66,17 @@ protected: bool m_cachedIsGridEnabled; bool m_cachedIsBackgroundEnabled; + QDataVis::ColorStyle m_cachedColorStyle; + QColor m_cachedObjectColor; + QLinearGradient m_cachedObjectGradient; + GLuint m_objectGradientTexture; + QColor m_cachedSingleHighlightColor; + QLinearGradient m_cachedSingleHighlightGradient; + GLuint m_singleHighlightGradientTexture; + QColor m_cachedMultiHighlightColor; + QLinearGradient m_cachedMultiHighlightGradient; + GLuint m_multiHighlightGradientTexture; + AxisRenderCache m_axisCacheX; AxisRenderCache m_axisCacheY; AxisRenderCache m_axisCacheZ; @@ -125,6 +133,13 @@ public: virtual void updateAxisSegmentCount(Q3DAbstractAxis::AxisOrientation orientation, int count); virtual void updateAxisSubSegmentCount(Q3DAbstractAxis::AxisOrientation orientation, int count); virtual void updateAxisLabelFormat(Q3DAbstractAxis::AxisOrientation orientation, const QString &format); + virtual void updateColorStyle(QDataVis::ColorStyle style); + virtual void updateObjectColor(const QColor &color); + virtual void updateObjectGradient(const QLinearGradient &gradient); + virtual void updateSingleHighlightColor(const QColor &color); + virtual void updateSingleHighlightGradient(const QLinearGradient &gradient); + virtual void updateMultiHighlightColor(const QColor &color); + virtual void updateMultiHighlightGradient(const QLinearGradient &gradient); signals: void needRender(); // Emit this if something in renderer causes need for another render pass. @@ -143,6 +158,8 @@ protected: AxisRenderCache &axisCacheForOrientation(Q3DAbstractAxis::AxisOrientation orientation); virtual void lowerShadowQuality(); + + void fixGradient(QLinearGradient *gradient, GLuint *gradientTexture); }; QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp index 8ca943fb..e0910880 100644 --- a/src/datavisualization/engine/bars3drenderer.cpp +++ b/src/datavisualization/engine/bars3drenderer.cpp @@ -304,12 +304,22 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, // Bind bar shader m_barShader->bind(); + GLuint gradientTexture = 0; + // Set common bar shader bindings m_barShader->setUniformValue(m_barShader->lightP(), lightPos); m_barShader->setUniformValue(m_barShader->view(), viewMatrix); m_barShader->setUniformValue(m_barShader->lightS(), 0.5f); m_barShader->setUniformValue(m_barShader->ambientS(), m_cachedTheme.m_ambientStrength * 2.0f); + if (m_cachedColorStyle != QDataVis::ColorStyleUniform) { + // Round the gradient off a bit to avoid it looping over + m_barShader->setUniformValue(m_barShader->gradientMin(), gradientMargin); + if (m_cachedColorStyle == QDataVis::ColorStyleObjectGradient) + m_barShader->setUniformValue(m_barShader->gradientHeight(), 0.5f - gradientMargin); + + gradientTexture = m_objectGradientTexture; + } // Draw the selected row / column GLfloat barPosYAdjustment = -0.8f; // Positives only -> translate to -1.0 + 0.2 for row/column labels @@ -323,7 +333,6 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, QMatrix4x4 projectionViewMatrix = projectionMatrix * viewMatrix; QVector3D barHighlightColor(Utils::vectorFromColor(m_cachedTheme.m_highlightBarColor)); QVector3D rowHighlightColor(Utils::vectorFromColor(m_cachedTheme.m_highlightRowColor)); - QVector3D columnHighlightColor(Utils::vectorFromColor(m_cachedTheme.m_highlightColumnColor)); bool rowMode = m_cachedSelectionMode.testFlag(QDataVis::SelectionRow); bool itemMode = m_cachedSelectionMode.testFlag(QDataVis::SelectionItem); @@ -353,30 +362,19 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, MVPMatrix = projectionViewMatrix * modelMatrix; -#if 0 - QVector3D baseColor; - if (m_visualSelectedBarPos.x() == item->position().x() - && m_visualSelectedBarPos.y() == item->position().y()) { - baseColor = barHighlightColor; - } else if (rowMode) { - baseColor = rowHighlightColor; - } else { - baseColor = columnHighlightColor; - } - - QVector3D heightColor = Utils::vectorFromColor(m_cachedTheme.m_heightColor) * item->height(); - QVector3D barColor = baseColor + heightColor; -#else QVector3D barColor; if (itemMode && m_visualSelectedBarPos.x() == item->position().x() && m_visualSelectedBarPos.y() == item->position().y()) { - barColor = barHighlightColor; - } else if (rowMode) { - barColor = rowHighlightColor; + if (m_cachedColorStyle == QDataVis::ColorStyleUniform) + barColor = barHighlightColor; + else + gradientTexture = m_singleHighlightGradientTexture; } else { - barColor = columnHighlightColor; + if (m_cachedColorStyle == QDataVis::ColorStyleUniform) + barColor = rowHighlightColor; + else + gradientTexture = m_multiHighlightGradientTexture; } -#endif if (item->height() != 0) { // Set shader bindings @@ -384,10 +382,16 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, m_barShader->setUniformValue(m_barShader->nModel(), itModelMatrix.inverted().transposed()); m_barShader->setUniformValue(m_barShader->MVP(), MVPMatrix); - m_barShader->setUniformValue(m_barShader->color(), barColor); + if (m_cachedColorStyle == QDataVis::ColorStyleUniform) { + m_barShader->setUniformValue(m_barShader->color(), barColor); + } else if (m_cachedColorStyle == QDataVis::ColorStyleRangeGradient) { + m_barShader->setUniformValue(m_barShader->gradientHeight(), + ((qAbs(item->height()) / m_gradientFraction)) + - gradientMargin); + } // Draw the object - m_drawer->drawObject(m_barShader, m_barObj); + m_drawer->drawObject(m_barShader, m_barObj, gradientTexture); } } @@ -788,12 +792,21 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) // Bind bar shader m_barShader->bind(); + GLuint gradientTexture = 0; + // Set common bar shader bindings m_barShader->setUniformValue(m_barShader->lightP(), lightPos); m_barShader->setUniformValue(m_barShader->view(), viewMatrix); m_barShader->setUniformValue(m_barShader->ambientS(), m_cachedTheme.m_ambientStrength); + if (m_cachedColorStyle != QDataVis::ColorStyleUniform) { + // Round the gradient off a bit to avoid it looping over + m_barShader->setUniformValue(m_barShader->gradientMin(), gradientMargin); + if (m_cachedColorStyle == QDataVis::ColorStyleObjectGradient) + m_barShader->setUniformValue(m_barShader->gradientHeight(), 0.5f - gradientMargin); + gradientTexture = m_objectGradientTexture; + } // TODO: Can't call back to controller here! (QTRD-2216) if (m_selectionDirty) { @@ -814,8 +827,8 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) // Draw bars QVector3D barHighlightColor(Utils::vectorFromColor(m_cachedTheme.m_highlightBarColor)); QVector3D rowHighlightColor(Utils::vectorFromColor(m_cachedTheme.m_highlightRowColor)); - QVector3D columnHighlightColor(Utils::vectorFromColor(m_cachedTheme.m_highlightColumnColor)); - QVector3D baseColor(Utils::vectorFromColor(m_cachedTheme.m_baseColor)); + QVector3D baseColor(Utils::vectorFromColor(m_cachedObjectColor)); + QVector3D barColor = baseColor; GLfloat adjustedLightStrength = m_cachedTheme.m_lightStrength / 10.0f; GLfloat adjustedHighlightStrength = m_cachedTheme.m_highlightLightStrength / 10.0f; @@ -852,16 +865,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) MVPMatrix = projectionViewMatrix * modelMatrix; #endif -#if 0 - QVector3D heightColor = Utils::vectorFromColor(m_cachedTheme.m_heightColor) - * item.height(); - QVector3D depthColor = Utils::vectorFromColor(m_cachedTheme.m_depthColor) - * (float(row) / GLfloat(m_cachedRowCount)); - - QVector3D barColor = baseColor + heightColor + depthColor; -#else - QVector3D barColor = baseColor; -#endif + if (m_cachedColorStyle == QDataVis::ColorStyleUniform) + barColor = baseColor; + else + gradientTexture = m_objectGradientTexture; GLfloat lightStrength = m_cachedTheme.m_lightStrength; GLfloat shadowLightStrength = adjustedLightStrength; @@ -873,7 +880,11 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) switch (selectionType) { case Bars3DController::SelectionItem: { - barColor = barHighlightColor; + if (m_cachedColorStyle == QDataVis::ColorStyleUniform) + barColor = barHighlightColor; + else + gradientTexture = m_singleHighlightGradientTexture; + lightStrength = m_cachedTheme.m_highlightLightStrength; shadowLightStrength = adjustedHighlightStrength; // Insert position data into render item. We have no ownership, don't delete the previous one @@ -893,7 +904,11 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } case Bars3DController::SelectionRow: { // Current bar is on the same row as the selected bar - barColor = rowHighlightColor; + if (m_cachedColorStyle == QDataVis::ColorStyleUniform) + barColor = rowHighlightColor; + else + gradientTexture = m_multiHighlightGradientTexture; + lightStrength = m_cachedTheme.m_highlightLightStrength; shadowLightStrength = adjustedHighlightStrength; if (m_cachedIsSlicingActivated) { @@ -909,7 +924,11 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } case Bars3DController::SelectionColumn: { // Current bar is on the same column as the selected bar - barColor = columnHighlightColor; + if (m_cachedColorStyle == QDataVis::ColorStyleUniform) + barColor = rowHighlightColor; + else + gradientTexture = m_multiHighlightGradientTexture; + lightStrength = m_cachedTheme.m_highlightLightStrength; shadowLightStrength = adjustedHighlightStrength; if (m_cachedIsSlicingActivated) { @@ -938,7 +957,13 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) m_barShader->setUniformValue(m_barShader->nModel(), itModelMatrix.transposed().inverted()); m_barShader->setUniformValue(m_barShader->MVP(), MVPMatrix); - m_barShader->setUniformValue(m_barShader->color(), barColor); + if (m_cachedColorStyle == QDataVis::ColorStyleUniform) { + m_barShader->setUniformValue(m_barShader->color(), barColor); + } else if (m_cachedColorStyle == QDataVis::ColorStyleRangeGradient) { + m_barShader->setUniformValue(m_barShader->gradientHeight(), + ((qAbs(item.height()) / m_gradientFraction)) + - gradientMargin); + } #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { @@ -949,7 +974,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) m_barShader->setUniformValue(m_barShader->lightS(), shadowLightStrength); // Draw the object - m_drawer->drawObject(m_barShader, m_barObj, 0, m_depthTexture); + m_drawer->drawObject(m_barShader, m_barObj, gradientTexture, m_depthTexture); } else #endif { @@ -957,7 +982,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) m_barShader->setUniformValue(m_barShader->lightS(), lightStrength); // Draw the object - m_drawer->drawObject(m_barShader, m_barObj); + m_drawer->drawObject(m_barShader, m_barObj, gradientTexture); } } } @@ -1740,10 +1765,15 @@ void Bars3DRenderer::calculateHeightAdjustment() m_heightNormalizer = GLfloat(m_axisCacheY.max() - m_axisCacheY.min()); } - if (m_axisCacheY.max() < 0.0 || m_axisCacheY.min() > 0.0) + // Height fractions are used in gradient calculations and are therefore doubled + if (m_axisCacheY.max() < 0.0 || m_axisCacheY.min() > 0.0) { m_noZeroInRange = true; - else + m_gradientFraction = 2.0f; + } else { m_noZeroInRange = false; + GLfloat minAbs = qFabs(m_axisCacheY.min()); + m_gradientFraction = qMax(minAbs, maxAbs) / m_heightNormalizer * 2.0f; + } // Calculate translation adjustment for negative background newAdjustment = qBound(0.0f, (maxAbs / m_heightNormalizer), 1.0f) * 2.0f - 0.5f; diff --git a/src/datavisualization/engine/bars3drenderer_p.h b/src/datavisualization/engine/bars3drenderer_p.h index 3614dce3..9f77b387 100644 --- a/src/datavisualization/engine/bars3drenderer_p.h +++ b/src/datavisualization/engine/bars3drenderer_p.h @@ -87,6 +87,7 @@ private: GLfloat m_shadowQualityToShader; GLint m_shadowQualityMultiplier; GLfloat m_heightNormalizer; + GLfloat m_gradientFraction; GLfloat m_negativeBackgroundAdjustment; GLfloat m_rowWidth; GLfloat m_columnDepth; diff --git a/src/datavisualization/engine/q3dbars.cpp b/src/datavisualization/engine/q3dbars.cpp index 17a3a6ad..1eded43a 100644 --- a/src/datavisualization/engine/q3dbars.cpp +++ b/src/datavisualization/engine/q3dbars.cpp @@ -120,6 +120,20 @@ Q3DBars::Q3DBars() &Q3DBars::backgroundVisibleChanged); QObject::connect(d_ptr->m_shared, &Bars3DController::selectedBarChanged, this, &Q3DBars::selectedBarChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::colorStyleChanged, this, + &Q3DBars::colorStyleChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::objectColorChanged, this, + &Q3DBars::barColorChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::objectGradientChanged, this, + &Q3DBars::barGradientChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::singleHighlightColorChanged, this, + &Q3DBars::singleHighlightColorChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::singleHighlightGradientChanged, this, + &Q3DBars::singleHighlightGradientChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::multiHighlightColorChanged, this, + &Q3DBars::multiHighlightColorChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::multiHighlightGradientChanged, this, + &Q3DBars::multiHighlightGradientChanged); QObject::connect(d_ptr->m_shared, &Abstract3DController::needRender, this, &Q3DWindow::renderLater); } @@ -300,30 +314,6 @@ QDataVis::Theme Q3DBars::theme() const return d_ptr->m_shared->theme().theme(); } -/*! - * Set bar color using your own color. \a baseColor sets the base color of a bar. The \a uniform - * -flag is used to define if color needs to be uniform throughout bar's length, or will the colors - * be applied by height, starting with dark at the bottom. It is \c true by default. - * - * Calling this method overrides colors from theme. - * - * \sa setTheme() - * - * \preliminary - */ -void Q3DBars::setBarColor(const QColor &baseColor, bool uniform) -{ - d_ptr->m_shared->setObjectColor(baseColor, uniform); -} - -/*! - * \return bar color in use. - */ -QColor Q3DBars::barColor() const -{ - return d_ptr->m_shared->objectColor(); -} - /*! * \property Q3DBars::selectionMode * @@ -468,6 +458,135 @@ QDataVis::ShadowQuality Q3DBars::shadowQuality() const return d_ptr->m_shared->shadowQuality(); } +/*! + * \property Q3DBars::colorStyle + * + * Sets the color \a style used to render bars. + * Defaults to true. + * + * \sa barColor, barGradient + */ +void Q3DBars::setColorStyle(QDataVis::ColorStyle style) +{ + d_ptr->m_shared->setColorStyle(style); +} + +QDataVis::ColorStyle Q3DBars::colorStyle() const +{ + return d_ptr->m_shared->colorStyle(); +} + +/*! + * \property Q3DBars::barColor + * + * Set bar color to the \a color for this set. Overrides any previously set bar gradient for this + * set, as well as any bar gradient or color from the theme. + * + * \sa theme, barGradient + */ +void Q3DBars::setBarColor(const QColor &color) +{ + d_ptr->m_shared->setObjectColor(color); +} + +QColor Q3DBars::barColor() const +{ + return d_ptr->m_shared->objectColor(); +} + +/*! + * \property Q3DBars::barGradient + * + * Set bar gradient to the \a gradient for this set. Overrides any previously set bar color for this + * set, as well as any bar gradient or color from the theme. + * + * \sa theme, barColor, colorStyle + */ +void Q3DBars::setBarGradient(const QLinearGradient &gradient) +{ + d_ptr->m_shared->setObjectGradient(gradient); +} + +QLinearGradient Q3DBars::barGradient() const +{ + return d_ptr->m_shared->objectGradient(); +} + +/*! + * \property Q3DBars::singleHighlightColor + * + * Set single bar highlight color to the \a color for this set. Overrides any previously set single + * bar highlight gradient for this set, as well as any single bar highlight gradient or color from the theme. + * + * \sa theme, singleHighlightGradient + */ +void Q3DBars::setSingleHighlightColor(const QColor &color) +{ + d_ptr->m_shared->setSingleHighlightColor(color); +} + +QColor Q3DBars::singleHighlightColor() const +{ + return d_ptr->m_shared->singleHighlightColor(); +} + +/*! + * \property Q3DBars::singleHighlightGradient + * + * Set single bar highlight gradient to the \a gradient for this set. + * Overrides any previously set single bar highlight color for this + * set, as well as any single bar highlight gradient or color from the theme. + * + * \sa theme, singleHighlightColor, colorStyle + */ +void Q3DBars::setSingleHighlightGradient(const QLinearGradient &gradient) +{ + d_ptr->m_shared->setSingleHighlightGradient(gradient); +} + +QLinearGradient Q3DBars::singleHighlightGradient() const +{ + return d_ptr->m_shared->singleHighlightGradient(); +} + +/*! + * \property Q3DBars::multiHighlightColor + * + * Set multiple bar highlight (e.g. row/column highlight) color to the \a color for this set. + * Overrides any previously set multiple bar highlight gradient for this set, as well as any + * multiple bar highlight gradient or color from the theme. + * + * \sa theme, multiHighlightGradient + */ +void Q3DBars::setMultiHighlightColor(const QColor &color) +{ + d_ptr->m_shared->setMultiHighlightColor(color); +} + +QColor Q3DBars::multiHighlightColor() const +{ + return d_ptr->m_shared->multiHighlightColor(); +} + +/*! + * \property Q3DBars::multiHighlightGradient + * + * Set multiple bar highlight (e.g. row/column highlight) gradient to the \a gradient for this set. + * Overrides any previously set multiple bar highlight color for this + * set, as well as any multiple bar highlight gradient or color from the theme. + * + * \sa theme, multiHighlightColor, colorStyle + */ +void Q3DBars::setMultiHighlightGradient(const QLinearGradient &gradient) +{ + d_ptr->m_shared->setMultiHighlightGradient(gradient); +} + +QLinearGradient Q3DBars::multiHighlightGradient() const +{ + return d_ptr->m_shared->multiHighlightGradient(); +} + /*! * Sets a user-defined row \a axis. Implicitly calls addAxis() to transfer ownership of * the \a axis to this graph. diff --git a/src/datavisualization/engine/q3dbars.h b/src/datavisualization/engine/q3dbars.h index 602e1e11..96fce909 100644 --- a/src/datavisualization/engine/q3dbars.h +++ b/src/datavisualization/engine/q3dbars.h @@ -22,6 +22,7 @@ #include #include #include +#include QT_DATAVISUALIZATION_BEGIN_NAMESPACE @@ -48,11 +49,19 @@ class QT_DATAVISUALIZATION_EXPORT Q3DBars : public Q3DWindow Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) Q_PROPERTY(QPoint selectedBar READ selectedBar WRITE setSelectedBar NOTIFY selectedBarChanged) Q_PROPERTY(Q3DScene* scene READ scene) + Q_PROPERTY(QtDataVisualization::QDataVis::ColorStyle colorStyle READ colorStyle WRITE setColorStyle NOTIFY colorStyleChanged) + Q_PROPERTY(QColor barColor READ barColor WRITE setBarColor NOTIFY barColorChanged) + Q_PROPERTY(QLinearGradient barGradient READ barGradient WRITE setBarGradient NOTIFY barGradientChanged) + Q_PROPERTY(QColor singleHighlightColor READ singleHighlightColor WRITE setSingleHighlightColor NOTIFY singleHighlightColorChanged) + Q_PROPERTY(QLinearGradient singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged) + Q_PROPERTY(QColor multiHighlightColor READ multiHighlightColor WRITE setMultiHighlightColor NOTIFY multiHighlightColorChanged) + Q_PROPERTY(QLinearGradient multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged) public: explicit Q3DBars(); ~Q3DBars(); + // TODO: Move to dataset object once that is done QTRD-2121 void setBarType(QDataVis::MeshStyle style, bool smooth = false); void setTheme(QDataVis::Theme theme); @@ -67,9 +76,7 @@ public: void setBarSpacingRelative(bool relative); bool isBarSpacingRelative(); - void setBarColor(const QColor &baseColor, bool uniform = true); - QColor barColor() const; - + // TODO: Move to dataset object once that is done QTRD-2121 void setMeshFileName(const QString &objFileName); QString meshFileName() const; @@ -99,6 +106,22 @@ public: void setShadowQuality(QDataVis::ShadowQuality quality); QDataVis::ShadowQuality shadowQuality() const; + // TODO: Move to dataset object once that is done QTRD-2121 + void setColorStyle(QDataVis::ColorStyle style); + QDataVis::ColorStyle colorStyle() const; + void setBarColor(const QColor &color); + QColor barColor() const; + void setBarGradient(const QLinearGradient &gradient); + QLinearGradient barGradient() const; + void setSingleHighlightColor(const QColor &color); + QColor singleHighlightColor() const; + void setSingleHighlightGradient(const QLinearGradient &gradient); + QLinearGradient singleHighlightGradient() const; + void setMultiHighlightColor(const QColor &color); + QColor multiHighlightColor() const; + void setMultiHighlightGradient(const QLinearGradient &gradient); + QLinearGradient multiHighlightGradient() const; + void setRowAxis(Q3DCategoryAxis *axis); Q3DCategoryAxis *rowAxis() const; void setColumnAxis(Q3DCategoryAxis *axis); @@ -109,6 +132,7 @@ public: void releaseAxis(Q3DAbstractAxis *axis); QList axes() const; + // TODO: Move to dataset object once that is done QTRD-2121 void setActiveDataProxy(QBarDataProxy *proxy); QBarDataProxy *activeDataProxy() const; void addDataProxy(QBarDataProxy *proxy); @@ -128,6 +152,13 @@ signals: void gridVisibleChanged(bool visible); void backgroundVisibleChanged(bool visible); void selectedBarChanged(QPoint position); + void colorStyleChanged(QDataVis::ColorStyle style); + void barColorChanged(QColor color); + void barGradientChanged(QLinearGradient gradient); + void singleHighlightColorChanged(QColor color); + void singleHighlightGradientChanged(QLinearGradient gradient); + void multiHighlightColorChanged(QColor color); + void multiHighlightGradientChanged(QLinearGradient gradient); protected: diff --git a/src/datavisualization/engine/q3dscatter.cpp b/src/datavisualization/engine/q3dscatter.cpp index b2b9c718..0893990b 100644 --- a/src/datavisualization/engine/q3dscatter.cpp +++ b/src/datavisualization/engine/q3dscatter.cpp @@ -106,6 +106,20 @@ Q3DScatter::Q3DScatter() &Q3DScatter::backgroundVisibleChanged); QObject::connect(d_ptr->m_shared, &Scatter3DController::selectedItemIndexChanged, this, &Q3DScatter::selectedItemIndexChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::colorStyleChanged, this, + &Q3DScatter::colorStyleChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::objectColorChanged, this, + &Q3DScatter::itemColorChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::objectGradientChanged, this, + &Q3DScatter::itemGradientChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::singleHighlightColorChanged, this, + &Q3DScatter::singleHighlightColorChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::singleHighlightGradientChanged, this, + &Q3DScatter::singleHighlightGradientChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::multiHighlightColorChanged, this, + &Q3DScatter::multiHighlightColorChanged); + QObject::connect(d_ptr->m_shared, &Abstract3DController::multiHighlightGradientChanged, this, + &Q3DScatter::multiHighlightGradientChanged); QObject::connect(d_ptr->m_shared, &Abstract3DController::needRender, this, &Q3DWindow::renderLater); } @@ -236,7 +250,8 @@ QDataVis::Theme Q3DScatter::theme() const */ void Q3DScatter::setObjectColor(const QColor &baseColor, bool uniform) { - d_ptr->m_shared->setObjectColor(baseColor, uniform); + //TODO + d_ptr->m_shared->setObjectColor(baseColor); } /*! @@ -391,6 +406,135 @@ QDataVis::ShadowQuality Q3DScatter::shadowQuality() const return d_ptr->m_shared->shadowQuality(); } +/*! + * \property Q3DScatter::colorStyle + * + * Sets the color \a style used to render items. + * Defaults to true. + * + * \sa itemColor, itemGradient + */ +void Q3DScatter::setColorStyle(QDataVis::ColorStyle style) +{ + d_ptr->m_shared->setColorStyle(style); +} + +QDataVis::ColorStyle Q3DScatter::colorStyle() const +{ + return d_ptr->m_shared->colorStyle(); +} + +/*! + * \property Q3DScatter::itemColor + * + * Set item color to the \a color for this set. Overrides any previously set item gradient for this + * set, as well as any item gradient or color from the theme. + * + * \sa theme, itemGradient + */ +void Q3DScatter::setItemColor(const QColor &color) +{ + d_ptr->m_shared->setObjectColor(color); +} + +QColor Q3DScatter::itemColor() const +{ + return d_ptr->m_shared->objectColor(); +} + +/*! + * \property Q3DScatter::itemGradient + * + * Set item gradient to the \a gradient for this set. Overrides any previously set item color for this + * set, as well as any item gradient or color from the theme. + * + * \sa theme, itemColor, colorStyle + */ +void Q3DScatter::setItemGradient(const QLinearGradient &gradient) +{ + d_ptr->m_shared->setObjectGradient(gradient); +} + +QLinearGradient Q3DScatter::itemGradient() const +{ + return d_ptr->m_shared->objectGradient(); +} + +/*! + * \property Q3DScatter::singleHighlightColor + * + * Set single item highlight color to the \a color for this set. Overrides any previously set single + * item highlight gradient for this set, as well as any single item highlight gradient or color from the theme. + * + * \sa theme, singleHighlightGradient + */ +void Q3DScatter::setSingleHighlightColor(const QColor &color) +{ + d_ptr->m_shared->setSingleHighlightColor(color); +} + +QColor Q3DScatter::singleHighlightColor() const +{ + return d_ptr->m_shared->singleHighlightColor(); +} + +/*! + * \property Q3DScatter::singleHighlightGradient + * + * Set single item highlight gradient to the \a gradient for this set. + * Overrides any previously set single item highlight color for this + * set, as well as any single item highlight gradient or color from the theme. + * + * \sa theme, singleHighlightColor, colorStyle + */ +void Q3DScatter::setSingleHighlightGradient(const QLinearGradient &gradient) +{ + d_ptr->m_shared->setSingleHighlightGradient(gradient); +} + +QLinearGradient Q3DScatter::singleHighlightGradient() const +{ + return d_ptr->m_shared->singleHighlightGradient(); +} + +/*! + * \property Q3DScatter::multiHighlightColor + * + * Set multiple item highlight (e.g. row/column highlight) color to the \a color for this set. + * Overrides any previously set multiple item highlight gradient for this set, as well as any + * multiple item highlight gradient or color from the theme. + * + * \sa theme, multiHighlightGradient + */ +void Q3DScatter::setMultiHighlightColor(const QColor &color) +{ + d_ptr->m_shared->setMultiHighlightColor(color); +} + +QColor Q3DScatter::multiHighlightColor() const +{ + return d_ptr->m_shared->multiHighlightColor(); +} + +/*! + * \property Q3DScatter::multiHighlightGradient + * + * Set multiple item highlight (e.g. row/column highlight) gradient to the \a gradient for this set. + * Overrides any previously set multiple item highlight color for this + * set, as well as any multiple item highlight gradient or color from the theme. + * + * \sa theme, multiHighlightColor, colorStyle + */ +void Q3DScatter::setMultiHighlightGradient(const QLinearGradient &gradient) +{ + d_ptr->m_shared->setMultiHighlightGradient(gradient); +} + +QLinearGradient Q3DScatter::multiHighlightGradient() const +{ + return d_ptr->m_shared->multiHighlightGradient(); +} + /*! * Sets a user-defined X-axis. Implicitly calls addAxis() to transfer ownership * of the \a axis to this graph. diff --git a/src/datavisualization/engine/q3dscatter.h b/src/datavisualization/engine/q3dscatter.h index 70056a9d..2cc6bfd9 100644 --- a/src/datavisualization/engine/q3dscatter.h +++ b/src/datavisualization/engine/q3dscatter.h @@ -23,6 +23,7 @@ #include #include #include +#include QT_DATAVISUALIZATION_BEGIN_NAMESPACE @@ -45,6 +46,13 @@ class QT_DATAVISUALIZATION_EXPORT Q3DScatter : public Q3DWindow Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) Q_PROPERTY(int selectedItemIndex READ selectedItemIndex WRITE setSelectedItemIndex NOTIFY selectedItemIndexChanged) Q_PROPERTY(Q3DScene* scene READ scene) + Q_PROPERTY(QtDataVisualization::QDataVis::ColorStyle colorStyle READ colorStyle WRITE setColorStyle NOTIFY colorStyleChanged) + Q_PROPERTY(QColor itemColor READ itemColor WRITE setItemColor NOTIFY itemColorChanged) + Q_PROPERTY(QLinearGradient itemGradient READ itemGradient WRITE setItemGradient NOTIFY itemGradientChanged) + Q_PROPERTY(QColor singleHighlightColor READ singleHighlightColor WRITE setSingleHighlightColor NOTIFY singleHighlightColorChanged) + Q_PROPERTY(QLinearGradient singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged) + Q_PROPERTY(QColor multiHighlightColor READ multiHighlightColor WRITE setMultiHighlightColor NOTIFY multiHighlightColorChanged) + Q_PROPERTY(QLinearGradient multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged) public: explicit Q3DScatter(); @@ -87,6 +95,22 @@ public: void setShadowQuality(QDataVis::ShadowQuality quality); QDataVis::ShadowQuality shadowQuality() const; + // TODO: Move to dataset object once that is done QTRD-2121 + void setColorStyle(QDataVis::ColorStyle style); + QDataVis::ColorStyle colorStyle() const; + void setItemColor(const QColor &color); + QColor itemColor() const; + void setItemGradient(const QLinearGradient &gradient); + QLinearGradient itemGradient() const; + void setSingleHighlightColor(const QColor &color); + QColor singleHighlightColor() const; + void setSingleHighlightGradient(const QLinearGradient &gradient); + QLinearGradient singleHighlightGradient() const; + void setMultiHighlightColor(const QColor &color); + QColor multiHighlightColor() const; + void setMultiHighlightGradient(const QLinearGradient &gradient); + QLinearGradient multiHighlightGradient() const; + void setAxisX(Q3DValueAxis *axis); Q3DValueAxis *axisX() const; void setAxisY(Q3DValueAxis *axis); @@ -113,6 +137,13 @@ signals: void gridVisibleChanged(bool visible); void backgroundVisibleChanged(bool visible); void selectedItemIndexChanged(int index); + void colorStyleChanged(QDataVis::ColorStyle style); + void itemColorChanged(QColor color); + void itemGradientChanged(QLinearGradient gradient); + void singleHighlightColorChanged(QColor color); + void singleHighlightGradientChanged(QLinearGradient gradient); + void multiHighlightColorChanged(QColor color); + void multiHighlightGradientChanged(QLinearGradient gradient); protected: void mouseDoubleClickEvent(QMouseEvent *event); diff --git a/src/datavisualization/engine/shaders/colorOnY.frag b/src/datavisualization/engine/shaders/colorOnY.frag index 80e54a61..caea959b 100644 --- a/src/datavisualization/engine/shaders/colorOnY.frag +++ b/src/datavisualization/engine/shaders/colorOnY.frag @@ -1,9 +1,11 @@ #version 120 uniform highp vec3 lightPosition_wrld; -uniform highp vec3 color_mdl; uniform highp float lightStrength; uniform highp float ambientStrength; +uniform sampler2D textureSampler; +uniform highp float gradMin; +uniform highp float gradHeight; varying highp vec3 position_wrld; varying highp vec3 normal_cmr; @@ -12,8 +14,8 @@ varying highp vec3 lightDirection_cmr; varying highp vec2 coords_mdl; void main() { - highp float heightMod = (coords_mdl.y * 0.3) + 0.7; // Add 30% black to the bottom - highp vec3 materialDiffuseColor = heightMod * color_mdl; + highp vec2 gradientUV = vec2(0.0, gradMin + ((coords_mdl.y + 1.0) * gradHeight)); + highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); diff --git a/src/datavisualization/engine/shaders/colorOnY_ES2.frag b/src/datavisualization/engine/shaders/colorOnY_ES2.frag index aba52cfe..bb6e28c7 100644 --- a/src/datavisualization/engine/shaders/colorOnY_ES2.frag +++ b/src/datavisualization/engine/shaders/colorOnY_ES2.frag @@ -1,7 +1,9 @@ uniform highp vec3 lightPosition_wrld; -uniform highp vec3 color_mdl; uniform highp float lightStrength; uniform highp float ambientStrength; +uniform sampler2D textureSampler; +uniform highp float gradMin; +uniform highp float gradHeight; varying highp vec3 position_wrld; varying highp vec3 normal_cmr; @@ -10,8 +12,8 @@ varying highp vec3 lightDirection_cmr; varying highp vec2 coords_mdl; void main() { - highp float heightMod = (coords_mdl.y * 0.3) + 0.7; // Add 30% black to the bottom - highp vec3 materialDiffuseColor = heightMod * color_mdl; + highp vec2 gradientUV = vec2(0.0, gradMin + ((coords_mdl.y + 1.0) * gradHeight)); + highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); diff --git a/src/datavisualization/engine/shaders/shadowNoTexColorOnY.frag b/src/datavisualization/engine/shaders/shadowNoTexColorOnY.frag index 68ba2368..9882cd92 100644 --- a/src/datavisualization/engine/shaders/shadowNoTexColorOnY.frag +++ b/src/datavisualization/engine/shaders/shadowNoTexColorOnY.frag @@ -3,8 +3,10 @@ uniform highp float lightStrength; uniform highp float ambientStrength; uniform highp float shadowQuality; -uniform highp vec3 color_mdl; uniform highp sampler2DShadow shadowMap; +uniform sampler2D textureSampler; +uniform highp float gradMin; +uniform highp float gradHeight; varying highp vec4 shadowCoord; varying highp vec3 position_wrld; @@ -37,8 +39,8 @@ highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), }*/ void main() { - highp float heightMod = (coords_mdl.y * 0.3) + 0.7; // Add 30% black to the bottom - highp vec3 materialDiffuseColor = heightMod * color_mdl; + highp vec2 gradientUV = vec2(0.0, gradMin + ((coords_mdl.y + 1.0) * gradHeight)); + highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); diff --git a/src/datavisualization/engine/surface3dcontroller.cpp b/src/datavisualization/engine/surface3dcontroller.cpp index a30ecfad..9e82017a 100644 --- a/src/datavisualization/engine/surface3dcontroller.cpp +++ b/src/datavisualization/engine/surface3dcontroller.cpp @@ -184,8 +184,6 @@ void Surface3DController::setGradient(const QLinearGradient &gradient) { if (gradient != m_userDefinedGradient) { m_userDefinedGradient = gradient; - m_userDefinedGradient.setStart(2, 1024); - m_userDefinedGradient.setFinalStop(0, 0); m_changeTracker.gradientColorChanged = true; emitNeedRender(); } diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index f40bc7bd..0a33fb57 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -35,7 +35,6 @@ #include #include -#include #include @@ -1625,18 +1624,16 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) void Surface3DRenderer::updateSurfaceGradient(const QLinearGradient &gradient) { - QImage image(QSize(2, 1024), QImage::Format_RGB32); - QPainter pmp(&image); - pmp.setBrush(QBrush(gradient)); - pmp.setPen(Qt::NoPen); - pmp.drawRect(0, 0, 2, 1024); - if (m_gradientTexture) { m_textureHelper->deleteTexture(&m_gradientTexture); m_gradientTexture = 0; } - m_gradientTexture = m_textureHelper->create2DTexture(image, false, true); + QLinearGradient adjustedGradient = gradient; + adjustedGradient.setStart(qreal(gradientTextureWidth), qreal(gradientTextureHeight)); + adjustedGradient.setFinalStop(0.0, 0.0); + + m_gradientTexture = m_textureHelper->createGradientTexture(adjustedGradient); } // This one needs to be called when the data size changes diff --git a/src/datavisualization/engine/theme.cpp b/src/datavisualization/engine/theme.cpp index 387540b1..2892f500 100644 --- a/src/datavisualization/engine/theme.cpp +++ b/src/datavisualization/engine/theme.cpp @@ -37,7 +37,8 @@ Theme::Theme() m_highlightBarColor(QColor(Qt::red)), m_highlightRowColor(QColor(Qt::darkRed)), m_highlightColumnColor(QColor(Qt::darkMagenta)), - m_surfaceGradient(QLinearGradient(2, 1024, 0, 0)), + m_surfaceGradient(QLinearGradient(qreal(gradientTextureWidth), qreal(gradientTextureHeight), + 0.0, 0.0)), m_lightStrength(4.0f), m_ambientStrength(0.3f), m_highlightLightStrength(8.0f), diff --git a/src/datavisualization/global/datavisualizationglobal_p.h b/src/datavisualization/global/datavisualizationglobal_p.h index ce616ee7..cd1450f4 100644 --- a/src/datavisualization/global/datavisualizationglobal_p.h +++ b/src/datavisualization/global/datavisualizationglobal_p.h @@ -39,17 +39,25 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE // Constants used in several files // Distance from camera to origin -const GLfloat cameraDistance = 6.0f; +static const GLfloat cameraDistance = 6.0f; // Size of font to be used in label texture rendering. Doesn't affect the actual font size. -const int textureFontSize = 50; -const GLfloat defaultRatio = 1.0f / 1.6f; // default aspect ratio 16:10 -const float gridLineOffset = 0.0001f; // Offset for lifting grid lines off background +static const int textureFontSize = 50; +static const GLfloat defaultRatio = 1.0f / 1.6f; // default aspect ratio 16:10 +static const float gridLineOffset = 0.0001f; // Offset for lifting grid lines off background // Default light position. To have shadows working correctly, light should be as far as camera, or a bit further // y position is added to the minimum height (or can be thought to be that much above or below the camera) -const QVector3D defaultLightPos(0.0f, 0.5f, 0.0f); -const QVector3D zeroVector(0.0f, 0.0f, 0.0f); -const QVector3D upVector(0.0f, 1.0f, 0.0f); -const QVector3D cameraDistanceVector(0.0f, 0.0f, cameraDistance); +static const QVector3D defaultLightPos(0.0f, 0.5f, 0.0f); +static const QVector3D zeroVector(0.0f, 0.0f, 0.0f); +static const QVector3D upVector(0.0f, 1.0f, 0.0f); +static const QVector3D cameraDistanceVector(0.0f, 0.0f, cameraDistance); + +// Skip color == selection texture's background color +static const QVector3D selectionSkipColor = QVector3D(255.0f, 255.0f, 255.0f); +static const QVector3D invalidColorVector = QVector3D(-1.0f, -1.0f, -1.0f); +static const GLfloat gradientTextureHeight = 1024.0f; +static const GLfloat gradientTextureWidth = 2.0f; +// Relative margin for avoiding gradient overflow +static const GLfloat gradientMargin = 1.0f / gradientTextureHeight; QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/global/qdatavisualizationenums.h b/src/datavisualization/global/qdatavisualizationenums.h index 943b756e..fd6b28e1 100644 --- a/src/datavisualization/global/qdatavisualizationenums.h +++ b/src/datavisualization/global/qdatavisualizationenums.h @@ -34,6 +34,7 @@ class QT_DATAVISUALIZATION_EXPORT QDataVis : public QObject Q_ENUMS(ShadowQuality) Q_ENUMS(LabelStyle) Q_FLAGS(SelectionFlag SelectionFlags) + Q_ENUMS(ColorStyle) public: enum InputState { @@ -124,6 +125,12 @@ public: LabelStyleFromTheme, LabelStyleTransparent }; + + enum ColorStyle { + ColorStyleUniform = 0, + ColorStyleObjectGradient, + ColorStyleRangeGradient + }; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QDataVis::SelectionFlags) diff --git a/src/datavisualization/global/qtdatavisualizationenums.qdoc b/src/datavisualization/global/qtdatavisualizationenums.qdoc index 6449f209..94db4835 100644 --- a/src/datavisualization/global/qtdatavisualizationenums.qdoc +++ b/src/datavisualization/global/qtdatavisualizationenums.qdoc @@ -192,3 +192,18 @@ \value LabelStyleTransparent Fully transparent background, using text color from theme. */ + +/*! + \enum QtDataVisualization::QDataVis::ColorStyle + + Color styles. + + \value ColorStyleUniform + Objects are rendered in a single color. + \value ColorStyleObjectGradient + Objects are colored using a full gradient for each object regardless + of object height. + \value ColorStyleRangeGradient + Objects are colored using a portion of the full gradient determined by + the object's height and its position on the Y-axis. +*/ diff --git a/src/datavisualization/utils/shaderhelper.cpp b/src/datavisualization/utils/shaderhelper.cpp index e27103af..7eb48945 100644 --- a/src/datavisualization/utils/shaderhelper.cpp +++ b/src/datavisualization/utils/shaderhelper.cpp @@ -90,7 +90,8 @@ void ShaderHelper::initialize() m_colorUniform = m_program->uniformLocation("color_mdl"); m_textureUniform = m_program->uniformLocation("textureSampler"); m_shadowUniform = m_program->uniformLocation("shadowMap"); - + m_gradientMinUniform = m_program->uniformLocation("gradMin"); + m_gradientHeightUniform = m_program->uniformLocation("gradHeight"); m_initialized = true; } @@ -230,6 +231,20 @@ GLuint ShaderHelper::shadow() return m_shadowUniform; } +GLuint ShaderHelper::gradientMin() +{ + if (!m_initialized) + qFatal("Shader not initialized"); + return m_gradientMinUniform; +} + +GLuint ShaderHelper::gradientHeight() +{ + if (!m_initialized) + qFatal("Shader not initialized"); + return m_gradientHeightUniform; +} + GLuint ShaderHelper::posAtt() { if (!m_initialized) diff --git a/src/datavisualization/utils/shaderhelper_p.h b/src/datavisualization/utils/shaderhelper_p.h index 73e5b9ee..191b7bf6 100644 --- a/src/datavisualization/utils/shaderhelper_p.h +++ b/src/datavisualization/utils/shaderhelper_p.h @@ -71,6 +71,8 @@ class ShaderHelper GLuint color(); GLuint texture(); GLuint shadow(); + GLuint gradientMin(); + GLuint gradientHeight(); GLuint posAtt(); GLuint uvAtt(); @@ -102,6 +104,8 @@ class ShaderHelper GLuint m_shadowQualityUniform; GLuint m_textureUniform; GLuint m_shadowUniform; + GLuint m_gradientMinUniform; + GLuint m_gradientHeightUniform; GLboolean m_initialized; }; diff --git a/src/datavisualization/utils/texturehelper.cpp b/src/datavisualization/utils/texturehelper.cpp index 9e2b9811..8e556b44 100644 --- a/src/datavisualization/utils/texturehelper.cpp +++ b/src/datavisualization/utils/texturehelper.cpp @@ -20,6 +20,7 @@ #include "utils_p.h" #include +#include #include @@ -152,6 +153,18 @@ GLuint TextureHelper::createSelectionTexture(const QSize &size, GLuint &frameBuf return textureid; } +GLuint TextureHelper::createGradientTexture(const QLinearGradient &gradient) +{ + QImage image(QSize(int(gradientTextureWidth), int(gradientTextureHeight)), + QImage::Format_RGB32); + QPainter pmp(&image); + pmp.setBrush(QBrush(gradient)); + pmp.setPen(Qt::NoPen); + pmp.drawRect(0, 0, int(gradientTextureWidth), int(gradientTextureHeight)); + + return create2DTexture(image, false, true); +} + #if !defined(QT_OPENGL_ES_2) GLuint TextureHelper::createDepthTexture(const QSize &size, GLuint &frameBuffer, GLuint textureSize) { diff --git a/src/datavisualization/utils/texturehelper_p.h b/src/datavisualization/utils/texturehelper_p.h index 8371825e..b2657083 100644 --- a/src/datavisualization/utils/texturehelper_p.h +++ b/src/datavisualization/utils/texturehelper_p.h @@ -32,6 +32,7 @@ #include "datavisualizationglobal_p.h" #include #include +#include QT_DATAVISUALIZATION_BEGIN_NAMESPACE @@ -47,6 +48,7 @@ class TextureHelper : protected QOpenGLFunctions GLuint createCubeMapTexture(const QImage &image, bool useTrilinearFiltering = false); // Returns selection texture and inserts generated framebuffers to framebuffer parameters GLuint createSelectionTexture(const QSize &size, GLuint &frameBuffer, GLuint &depthBuffer); + GLuint createGradientTexture(const QLinearGradient &gradient); #if !defined(QT_OPENGL_ES_2) // Returns depth texture and inserts generated framebuffer to parameter GLuint createDepthTexture(const QSize &size, GLuint &frameBuffer, GLuint textureSize = 1); diff --git a/src/datavisualizationqml2/declarativebars.cpp b/src/datavisualizationqml2/declarativebars.cpp index 606be75f..2fecf5d1 100644 --- a/src/datavisualizationqml2/declarativebars.cpp +++ b/src/datavisualizationqml2/declarativebars.cpp @@ -80,7 +80,7 @@ QSGNode *DeclarativeBars::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData void DeclarativeBars::setBarColor(const QColor &baseColor, bool uniform) { - m_shared->setObjectColor(baseColor, uniform); + m_shared->setObjectColor(baseColor); // TODO } void DeclarativeBars::setDataProxy(QBarDataProxy *dataProxy) diff --git a/src/datavisualizationqml2/declarativescatter.cpp b/src/datavisualizationqml2/declarativescatter.cpp index d18ff208..f1de9a16 100644 --- a/src/datavisualizationqml2/declarativescatter.cpp +++ b/src/datavisualizationqml2/declarativescatter.cpp @@ -78,7 +78,7 @@ QSGNode *DeclarativeScatter::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDa void DeclarativeScatter::setObjectColor(const QColor &baseColor, bool uniform) { - m_shared->setObjectColor(baseColor, uniform); + m_shared->setObjectColor(baseColor); //TODO } QScatterDataProxy *DeclarativeScatter::dataProxy() const diff --git a/tests/barstest/chart.cpp b/tests/barstest/chart.cpp index f150345e..3c82e400 100644 --- a/tests/barstest/chart.cpp +++ b/tests/barstest/chart.cpp @@ -40,7 +40,7 @@ GraphModifier::GraphModifier(Q3DBars *barchart) m_fontSize(20), m_segments(4), m_subSegments(3), - m_minval(-15.0), + m_minval(-16.0), m_maxval(20.0), m_selectedBar(-1, -1), m_autoAdjustingAxis(new Q3DValueAxis), @@ -611,3 +611,53 @@ void GraphModifier::setMaxY(int max) m_fixedRangeAxis->setMax(max); m_maxval = max; } + + +void GraphModifier::setGradient() +{ + QLinearGradient barGradient(0, 0, 1, 100); + barGradient.setColorAt(1.0, Qt::lightGray); + barGradient.setColorAt(0.75001, Qt::lightGray); + barGradient.setColorAt(0.75, Qt::blue); + barGradient.setColorAt(0.50001, Qt::blue); + barGradient.setColorAt(0.50, Qt::red); + barGradient.setColorAt(0.25001, Qt::red); + barGradient.setColorAt(0.25, Qt::yellow); + barGradient.setColorAt(0.0, Qt::yellow); + + QLinearGradient singleHighlightGradient(0, 0, 1, 100); + singleHighlightGradient.setColorAt(1.0, Qt::white); + singleHighlightGradient.setColorAt(0.75001, Qt::white); + singleHighlightGradient.setColorAt(0.75, Qt::lightGray); + singleHighlightGradient.setColorAt(0.50001, Qt::lightGray); + singleHighlightGradient.setColorAt(0.50, Qt::gray); + singleHighlightGradient.setColorAt(0.25001, Qt::gray); + singleHighlightGradient.setColorAt(0.25, Qt::darkGray); + singleHighlightGradient.setColorAt(0.0, Qt::darkGray); + + QLinearGradient multiHighlightGradient(0, 0, 1, 100); + multiHighlightGradient.setColorAt(1.0, Qt::black); + multiHighlightGradient.setColorAt(0.75001, Qt::black); + multiHighlightGradient.setColorAt(0.75, Qt::darkBlue); + multiHighlightGradient.setColorAt(0.50001, Qt::darkBlue); + multiHighlightGradient.setColorAt(0.50, Qt::darkRed); + multiHighlightGradient.setColorAt(0.25001, Qt::darkRed); + multiHighlightGradient.setColorAt(0.25, Qt::darkYellow); + multiHighlightGradient.setColorAt(0.0, Qt::darkYellow); + + m_chart->setBarColor(Qt::green); + m_chart->setSingleHighlightColor(Qt::white); + m_chart->setMultiHighlightColor(Qt::cyan); + + m_chart->setBarGradient(barGradient); + m_chart->setSingleHighlightGradient(singleHighlightGradient); + m_chart->setMultiHighlightGradient(multiHighlightGradient); + + QDataVis::ColorStyle oldStyle = m_chart->colorStyle(); + if (oldStyle == QDataVis::ColorStyleUniform) + m_chart->setColorStyle(QDataVis::ColorStyleObjectGradient); + else if (oldStyle == QDataVis::ColorStyleObjectGradient) + m_chart->setColorStyle(QDataVis::ColorStyleRangeGradient); + if (oldStyle == QDataVis::ColorStyleRangeGradient) + m_chart->setColorStyle(QDataVis::ColorStyleUniform); +} diff --git a/tests/barstest/chart.h b/tests/barstest/chart.h index 221ccff8..995ac406 100644 --- a/tests/barstest/chart.h +++ b/tests/barstest/chart.h @@ -76,6 +76,7 @@ public: public slots: void flipViews(); + void setGradient(); void changeShadowQuality(int quality); void shadowQualityUpdatedByVisual(QDataVis::ShadowQuality shadowQuality); void handleSelectionChange(const QPoint &position); diff --git a/tests/barstest/main.cpp b/tests/barstest/main.cpp index 7d6d1380..9ed0407c 100644 --- a/tests/barstest/main.cpp +++ b/tests/barstest/main.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include int main(int argc, char **argv) { @@ -128,6 +130,20 @@ int main(int argc, char **argv) flipViewsButton->setText(QStringLiteral("Flip views")); flipViewsButton->setEnabled(true); + QLinearGradient grBtoY(0, 0, 100, 0); + grBtoY.setColorAt(1.0, Qt::black); + grBtoY.setColorAt(0.67, Qt::blue); + grBtoY.setColorAt(0.33, Qt::red); + grBtoY.setColorAt(0.0, Qt::yellow); + QPixmap pm(100, 24); + QPainter pmp(&pm); + pmp.setBrush(QBrush(grBtoY)); + pmp.setPen(Qt::NoPen); + pmp.drawRect(0, 0, 100, 24); + QPushButton *gradientBtoYPB = new QPushButton(widget); + gradientBtoYPB->setIcon(QIcon(pm)); + gradientBtoYPB->setIconSize(QSize(100, 24)); + QCheckBox *backgroundCheckBox = new QCheckBox(widget); backgroundCheckBox->setText(QStringLiteral("Show background")); backgroundCheckBox->setChecked(true); @@ -252,7 +268,8 @@ int main(int argc, char **argv) vLayout->addWidget(swapAxisButton, 0, Qt::AlignTop); vLayout->addWidget(releaseAxesButton, 0, Qt::AlignTop); vLayout->addWidget(releaseProxiesButton, 1, Qt::AlignTop); - vLayout->addWidget(flipViewsButton, 1, Qt::AlignTop); + vLayout->addWidget(flipViewsButton, 0, Qt::AlignTop); + vLayout->addWidget(gradientBtoYPB, 1, Qt::AlignTop); vLayout2->addWidget(staticCheckBox, 0, Qt::AlignTop); vLayout2->addWidget(rotationCheckBox, 0, Qt::AlignTop); @@ -349,6 +366,8 @@ int main(int argc, char **argv) QObject::connect(flipViewsButton, &QPushButton::clicked, modifier, &GraphModifier::flipViews); + QObject::connect(gradientBtoYPB, &QPushButton::clicked, modifier, + &GraphModifier::setGradient); QObject::connect(fontList, &QFontComboBox::currentFontChanged, modifier, &GraphModifier::changeFont); diff --git a/tests/spectrum/spectrumapp/main.cpp b/tests/spectrum/spectrumapp/main.cpp index 31bdb0f1..5c756753 100644 --- a/tests/spectrum/spectrumapp/main.cpp +++ b/tests/spectrum/spectrumapp/main.cpp @@ -97,7 +97,7 @@ MainApp::MainApp(Q3DBars *window) m_chart->scene()->activeCamera()->setCameraPosition(10.0f, 7.5f, 75); #endif // Set color scheme - m_chart->setBarColor(QColor(Qt::red), false); + m_chart->setBarColor(QColor(Qt::red)); // Disable selection m_chart->setSelectionMode(QDataVis::SelectionNone); QObject::connect(m_engine, &Engine::changedSpectrum, this, &MainApp::spectrumChanged); -- cgit v1.2.3