diff options
author | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-12-02 08:43:02 +0200 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-12-02 09:01:25 +0200 |
commit | 94235c2e633845951ce6c947965789bb3f8ee7c4 (patch) | |
tree | 60f902b9defe670736dff4bf33d13ef5bfb57804 /src/datavisualization/theme | |
parent | 91c9f6791af049b873b7c60a88aa226eaec70c18 (diff) |
Theme documented
Task-number: QTRD-2633
Change-Id: Ib274ec236f50145df8fd4c2d83f62d4a9154687a
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavisualization/theme')
-rw-r--r-- | src/datavisualization/theme/q3dtheme.cpp | 590 | ||||
-rw-r--r-- | src/datavisualization/theme/q3dtheme.h | 63 | ||||
-rw-r--r-- | src/datavisualization/theme/q3dtheme_p.h | 17 | ||||
-rw-r--r-- | src/datavisualization/theme/thememanager.cpp | 52 | ||||
-rw-r--r-- | src/datavisualization/theme/thememanager_p.h | 4 |
5 files changed, 620 insertions, 106 deletions
diff --git a/src/datavisualization/theme/q3dtheme.cpp b/src/datavisualization/theme/q3dtheme.cpp index 21c21c98..1d7aac5e 100644 --- a/src/datavisualization/theme/q3dtheme.cpp +++ b/src/datavisualization/theme/q3dtheme.cpp @@ -20,19 +20,384 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE +/*! + * \class Q3DTheme + * \inmodule QtDataVisualization + * \brief Q3DTheme class provides a visual style for graphs. + * \since Qt Data Visualization 1.0 + * + * Q3DTheme is used to specify visual properties that affect the whole graph. There are several + * built-in themes that can be used directly, or be modified freely. User can also create a theme + * from scratch using \c ThemeUserDefined. Creating a theme using the default constructor + * produces a new user-defined theme. + * + * \section1 Properties controlled by theme + * \table + * \header + * \li Property + * \li Effect + * \li Default in ThemeUserDefined + * \row + * \li ambientLightStrength + * \li The strength of the ambient light in the graph. This affects how evenly and brightly the + * colors are shown throughout the graph regardless of light position. + * \li 0.25 + * \row + * \li backgroundColor + * \li Color of the graph background. + * \li Qt::black + * \row + * \li backgroundEnabled + * \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 + * \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 QLinearGradient(). Essentially fully black. + * \row + * \li colorStyle + * \li The color style of the objects in the graph. See ColorStyle for detailed description of + * the styles. This can be overridden by setting the colorStyle explicitly in series. + * \li ColorStyleUniform + * \row + * \li \l font + * \li The font to be used for labels. + * \li QFont() + * \row + * \li gridEnabled + * \li Is the grid on the background drawn or not. This affects all grid lines. + * \li true + * \row + * \li gridLineColor + * \li The color for the grid lines. + * \li Qt::white + * \row + * \li highlightLightStrength + * \li The specular light strength for highlighted objects. + * \li 7.5 + * \row + * \li labelBackgroundColor + * \li The color of the label background. This property has no effect if labelBackgroundEnabled + * is \c false. + * \li Qt::gray + * \row + * \li labelBackgroundEnabled + * \li Are the labels to be drawn with a background using labelBackgroundColor (including alpha), + * or with a fully transparent background. Labels with background are drawn to equal sizes + * per axis based on the longest label, and the text is centered in it. Labels without + * background are drawn as is and are left/right aligned based on their position in the + * graph. + * \li true + * \row + * \li labelBorderEnabled + * \li Are the labels to be drawn with a border or not. This property affects only labels with + * a background. + * \li true + * \row + * \li labelTextColor + * \li The color for the font used in labels. + * \li Qt::white + * \row + * \li lightColor + * \li The color of the specular light. Doesn't affect ambient light. \note Not yet supported + * in technology preview. + * \li Qt::white + * \row + * \li lightStrength + * \li The strength of the specular light in the graph. This affects the light specified in + * Q3DScene. + * \li 5.0 + * \row + * \li multiHighlightColor + * \li The color to be used for highlighted objects, if \l{Q3DBars::selectionMode}{selectionMode} + * of the graph has \c QDataVis::SelectionRow or \c QDataVis::SelectionColumn flag set. + * \li Qt::blue + * \row + * \li multiHighlightGradient + * \li The gradient to be used for highlighted objects, if \l{Q3DBars::selectionMode}{selectionMode} + * of the graph has \c QDataVis::SelectionRow or \c QDataVis::SelectionColumn flag set. + * \li QLinearGradient(). Essentially fully black. + * \row + * \li singleHighlightColor + * \li The color to be used for a highlighted object, if \l{Q3DBars::selectionMode}{selectionMode} + * of the graph has \c QDataVis::SelectionItem flag set. + * \li Qt::red + * \row + * \li singleHighlightGradient + * \li The gradient to be used for a highlighted object, if \l{Q3DBars::selectionMode}{selectionMode} + * of the graph has \c QDataVis::SelectionItem flag set. + * \li QLinearGradient(). Essentially fully black. + * \row + * \li windowColor + * \li The color of the window the graph is drawn into. + * \li Qt::black + * \endtable + * + * \section1 Usage examples + * + * Creating a built-in theme without any modifications: + * + * \snippet doc_src_q3dtheme.cpp 0 + * + * Creating a built-in theme and modifying some properties: + * + * \snippet doc_src_q3dtheme.cpp 1 + * + * Creating a user-defined theme: + * + * \snippet doc_src_q3dtheme.cpp 2 + * + * Creating a built-in theme and modifying some properties after it has been set: + * + * \snippet doc_src_q3dtheme.cpp 3 + * + */ + +/*! + * \enum Q3DTheme::ColorStyle + * + * Color styles. + * + * \value ColorStyleUniform + * Objects are rendered in a single color. The color used is specified in baseColor, + * singleHighlightColor and multiHighlightColor properties. + * \value ColorStyleObjectGradient + * Objects are colored using a full gradient for each object regardless of object height. The + * gradient used is specified in baseGradient, singleHighlightGradient and + * multiHighlightGradient properties. + * \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. The gradient used is specified in baseGradient, + * singleHighlightGradient and multiHighlightGradient properties. + */ + +/*! + * \enum Q3DTheme::Theme + * + * Built-in themes. + * + * \value ThemeQt + * A light theme with green as the base color. + * \value ThemePrimaryColors + * A light theme with yellow as the base color. + * \value ThemeDigia + * A light theme with gray as the base color. + * \value ThemeStoneMoss + * A medium dark theme with yellow as the base color. + * \value ThemeArmyBlue + * A medium light theme with blue as the base color. + * \value ThemeRetro + * A medium light theme with brown as the base color. + * \value ThemeEbony + * A dark theme with white as the base color. + * \value ThemeIsabelle + * A dark theme with yellow as the base color. + * \value ThemeUserDefined + * A user-defined theme. See \l {Properties controlled by theme} for theme defaults. + */ + +/*! + * \qmltype Theme3D + * \inqmlmodule QtDataVisualization + * \since QtDataVisualization 1.0 + * \ingroup datavisualization_qml + * \instantiates Q3DTheme + * \brief A visual style for graphs. + * + * This type is used to specify visual properties that affect the whole graph. There are several + * built-in themes that can be used directly, or be modified freely. User can also create a theme + * from scratch using \c Theme3D.ThemeUserDefined. + * + * For a more complete description, see Q3DTheme. + * + * \section1 Usage examples + * + * Using a built-in theme without any modifications: + * + * \snippet doc_src_q3dtheme.cpp 4 + * + * Using a built-in theme and modifying some properties: + * + * \snippet doc_src_q3dtheme.cpp 5 + * + * Using a user-defined theme: + * + * \snippet doc_src_q3dtheme.cpp 6 + */ + +/*! + * \qmlproperty Color Theme3D::baseColor + * + * Color to be used for all the objects in the graph. Has no immediate effect if colorStyle is not + * \c Theme3D.ColorStyleUniform. + */ + +/*! + * \qmlproperty Color Theme3D::backgroundColor + * + * Color for the graph background. + */ + +/*! + * \qmlproperty Color Theme3D::windowColor + * + * Color for the application window. + */ + +/*! + * \qmlproperty Color Theme3D::labelTextColor + * + * Color for the font used for labels. + */ + +/*! + * \qmlproperty Color Theme3D::labelBackgroundColor + * + * Color for the label backgrounds. Has no effect if labelBackgroundEnabled is \c false. + */ + +/*! + * \qmlproperty Color Theme3D::gridLineColor + * + * Color for the grid lines. + */ + +/*! + * \qmlproperty Color Theme3D::singleHighlightColor + * + * Highlight color for a highlighted object. Used if \l{AbstractGraph3D::selectionMode}{selectionMode} + * has \c AbstractGraph3D.SelectionItem flag set. + */ + +/*! + * \qmlproperty Color Theme3D::multiHighlightColor + * + * Highlight color for highlighted objects. Used if \l{AbstractGraph3D::selectionMode}{selectionMode} + * has \c AbstractGraph3D.SelectionRow or \c AbstractGraph3D.SelectionColumn flag set. + */ + +/*! + * \qmlproperty Color Theme3D::lightColor + * + * Color for the specular light defined in Scene3D. + * + * \warning Not supported in technology preview. + */ + +/*! + * \qmlproperty ColorGradient Theme3D::baseGradient + * + * Base gradient to be used for all the objects in the graph. Has no immediate effect if colorStyle + * is \c Theme3D.ColorStyleUniform. + */ + +/*! + * \qmlproperty ColorGradient Theme3D::singleHighlightGradient + * + * Highlight gradient for a highlighted object. Used if \l{AbstractGraph3D::selectionMode}{selectionMode} + * has \c AbstractGraph3D.SelectionItem flag set. + */ + +/*! + * \qmlproperty ColorGradient Theme3D::multiHighlightGradient + * + * Highlight gradient for highlighted objects. Used if \l{AbstractGraph3D::selectionMode}{selectionMode} + * has \c AbstractGraph3D.SelectionRow or \c AbstractGraph3D.SelectionColumn flag set. + */ + +/*! + * \qmlproperty float Theme3D::lightStrength + * + * Specular light strength for the whole graph. Value must be between 0.0 and 1.0. + */ + +/*! + * \qmlproperty float Theme3D::ambientLightStrength + * + * Ambient light strength for the whole graph. Value must be between 0.0 and 1.0. + */ + +/*! + * \qmlproperty float Theme3D::highlightLightStrength + * + * Specular light strength for highlighted objects. Value must be between 0.0 and 1.0. + */ + +/*! + * \qmlproperty bool Theme3D::labelBorderEnabled + * + * Set label borders enabled or disabled. Has no effect if labelBackgroundEnabled is \c false. + */ + +/*! + * \qmlproperty Font Theme3D::font + * + * Set \a font to be used for labels. + */ + +/*! + * \qmlproperty bool Theme3D::backgroundEnabled + * + * Set background enabled or disabled. + */ + +/*! + * \qmlproperty bool Theme3D::gridEnabled + * + * Set grid lines enabled or disabled. + */ + +/*! + * \qmlproperty bool Theme3D::labelBackgroundEnabled + * + * Set label backgrounds enabled or disabled. + */ + +/*! + * \qmlproperty Theme3D.ColorStyle Theme3D::colorStyle + * + * The \a style of the graph colors. One of \c Theme3D.ColorStyle. + */ + +/*! + * \qmlproperty Theme3D.Theme Theme3D::type + * + * The type of the theme. If no type is set, the type is \c Theme3D.ThemeUserDefined. + */ + +/*! + * Constructs a new theme of type ThemeUserDefined. An optional \a parent parameter + * can be given and is then passed to QObject constructor. + */ Q3DTheme::Q3DTheme(QObject *parent) : QObject(parent), - d_ptr(new Q3DThemePrivate(this, QDataVis::ThemeUserDefined)) + d_ptr(new Q3DThemePrivate(this, ThemeUserDefined)) { } -Q3DTheme::Q3DTheme(QDataVis::Theme themeType, QObject *parent) +/*! + * Constructs a new theme with \a themeType, which can be one of the built-in themes from + * \l Theme. An optional \a parent parameter can be given and is then passed to QObject + * constructor. + */ +Q3DTheme::Q3DTheme(Theme themeType, QObject *parent) : QObject(parent), d_ptr(new Q3DThemePrivate(this, themeType)) { } -Q3DTheme::Q3DTheme(Q3DThemePrivate *d, QDataVis::Theme themeType, +/*! + * \internal + */ +Q3DTheme::Q3DTheme(Q3DThemePrivate *d, Theme themeType, QObject *parent) : QObject(parent), d_ptr(d) @@ -40,13 +405,21 @@ Q3DTheme::Q3DTheme(Q3DThemePrivate *d, QDataVis::Theme themeType, d_ptr->m_themeId = themeType; } +/*! + * Destroys the theme. + */ 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 + * + * Color to be used for all the objects in the graph. Has no immediate effect if colorStyle is not + * ColorStyleUniform. + */ void Q3DTheme::setBaseColor(const QColor &color) { if (d_ptr->m_baseColor != color) { @@ -61,13 +434,18 @@ QColor Q3DTheme::baseColor() const return d_ptr->m_baseColor; } +/*! + * \property Q3DTheme::backgroundColor + * + * Color for the graph background. + */ void Q3DTheme::setBackgroundColor(const QColor &color) { if (d_ptr->m_backgroundColor != color) { d_ptr->m_dirtyBits.backgroundColorDirty = true; d_ptr->m_backgroundColor = color; emit backgroundColorChanged(color); - emit needRender(); + emit d_ptr->needRender(); } } @@ -76,13 +454,18 @@ QColor Q3DTheme::backgroundColor() const return d_ptr->m_backgroundColor; } +/*! + * \property Q3DTheme::windowColor + * + * Color for the application window. + */ void Q3DTheme::setWindowColor(const QColor &color) { if (d_ptr->m_windowColor != color) { d_ptr->m_dirtyBits.windowColorDirty = true; d_ptr->m_windowColor = color; emit windowColorChanged(color); - emit needRender(); + emit d_ptr->needRender(); } } @@ -91,43 +474,58 @@ QColor Q3DTheme::windowColor() const return d_ptr->m_windowColor; } -void Q3DTheme::setTextColor(const QColor &color) +/*! + * \property Q3DTheme::labelTextColor + * + * Color for the font used for labels. + */ +void Q3DTheme::setLabelTextColor(const QColor &color) { if (d_ptr->m_textColor != color) { - d_ptr->m_dirtyBits.textColorDirty = true; + d_ptr->m_dirtyBits.labelTextColorDirty = true; d_ptr->m_textColor = color; - emit textColorChanged(color); - emit needRender(); + emit labelTextColorChanged(color); + emit d_ptr->needRender(); } } -QColor Q3DTheme::textColor() const +QColor Q3DTheme::labelTextColor() const { return d_ptr->m_textColor; } -void Q3DTheme::setTextBackgroundColor(const QColor &color) +/*! + * \property Q3DTheme::labelBackgroundColor + * + * Color for the label backgrounds. Has no effect if labelBackgroundEnabled is \c false. + */ +void Q3DTheme::setLabelBackgroundColor(const QColor &color) { if (d_ptr->m_textBackgroundColor != color) { - d_ptr->m_dirtyBits.textBackgroundColorDirty = true; + d_ptr->m_dirtyBits.labelBackgroundColorDirty = true; d_ptr->m_textBackgroundColor = color; - emit textBackgroundColorChanged(color); - emit needRender(); + emit labelBackgroundColorChanged(color); + emit d_ptr->needRender(); } } -QColor Q3DTheme::textBackgroundColor() const +QColor Q3DTheme::labelBackgroundColor() const { return d_ptr->m_textBackgroundColor; } +/*! + * \property Q3DTheme::gridLineColor + * + * Color for the grid lines. + */ void Q3DTheme::setGridLineColor(const QColor &color) { if (d_ptr->m_gridLineColor != color) { d_ptr->m_dirtyBits.gridLineColorDirty = true; d_ptr->m_gridLineColor = color; emit gridLineColorChanged(color); - emit needRender(); + emit d_ptr->needRender(); } } @@ -136,6 +534,12 @@ QColor Q3DTheme::gridLineColor() const return d_ptr->m_gridLineColor; } +/*! + * \property Q3DTheme::singleHighlightColor + * + * Highlight color for a highlighted object. Used if \l{Q3DBars::selectionMode}{selectionMode} has + * \c QDataVis::SelectionItem flag set. + */ void Q3DTheme::setSingleHighlightColor(const QColor &color) { if (d_ptr->m_singleHighlightColor != color) { @@ -150,6 +554,12 @@ QColor Q3DTheme::singleHighlightColor() const return d_ptr->m_singleHighlightColor; } +/*! + * \property Q3DTheme::multiHighlightColor + * + * Highlight color for highlighted objects. Used if \l{Q3DBars::selectionMode}{selectionMode} has + * \c QDataVis::SelectionRow or \c QDataVis::SelectionColumn flag set. + */ void Q3DTheme::setMultiHighlightColor(const QColor &color) { if (d_ptr->m_multiHighlightColor != color) { @@ -164,13 +574,20 @@ QColor Q3DTheme::multiHighlightColor() const return d_ptr->m_multiHighlightColor; } +/*! + * \property Q3DTheme::lightColor + * + * Color for the specular light defined in Q3DScene. + * + * \warning Not supported in technology preview. + */ void Q3DTheme::setLightColor(const QColor &color) { if (d_ptr->m_lightColor != color) { d_ptr->m_dirtyBits.lightColorDirty = true; d_ptr->m_lightColor = color; emit lightColorChanged(color); - emit needRender(); + emit d_ptr->needRender(); } } @@ -180,6 +597,12 @@ QColor Q3DTheme::lightColor() const } // TODO: Surfacegradients as a list, containing one for each series? +/*! + * \property Q3DTheme::baseGradient + * + * Base gradient to be used for all the objects in the graph. Has no immediate effect if colorStyle + * is ColorStyleUniform. + */ void Q3DTheme::setBaseGradient(const QLinearGradient &gradient) { if (d_ptr->m_baseGradient != gradient) { @@ -194,6 +617,12 @@ QLinearGradient Q3DTheme::baseGradient() const return d_ptr->m_baseGradient; } +/*! + * \property Q3DTheme::singleHighlightGradient + * + * Highlight gradient for a highlighted object. Used if \l{Q3DBars::selectionMode}{selectionMode} + * has \c QDataVis::SelectionItem flag set. + */ void Q3DTheme::setSingleHighlightGradient(const QLinearGradient &gradient) { if (d_ptr->m_singleHighlightGradient != gradient) { @@ -208,6 +637,12 @@ QLinearGradient Q3DTheme::singleHighlightGradient() const return d_ptr->m_singleHighlightGradient; } +/*! + * \property Q3DTheme::multiHighlightGradient + * + * Highlight gradient for highlighted objects. Used if \l{Q3DBars::selectionMode}{selectionMode} + * has \c QDataVis::SelectionRow or \c QDataVis::SelectionColumn flag set. + */ void Q3DTheme::setMultiHighlightGradient(const QLinearGradient &gradient) { if (d_ptr->m_multiHighlightGradient != gradient) { @@ -222,13 +657,20 @@ QLinearGradient Q3DTheme::multiHighlightGradient() const return d_ptr->m_multiHighlightGradient; } +/*! + * \property Q3DTheme::lightStrength + * + * Specular light strength for the whole graph. Value must be 0.0f and 10.0f. + */ void Q3DTheme::setLightStrength(float strength) { - if (d_ptr->m_lightStrength != strength) { + if (strength < 0.0f || strength > 10.0f) { + qWarning("Invalid value. Valid range for lightStrength is between 0.0f and 10.0f"); + } else if (d_ptr->m_lightStrength != strength) { d_ptr->m_dirtyBits.lightStrengthDirty = true; d_ptr->m_lightStrength = strength; emit lightStrengthChanged(strength); - emit needRender(); + emit d_ptr->needRender(); } } @@ -237,13 +679,20 @@ float Q3DTheme::lightStrength() const return d_ptr->m_lightStrength; } +/*! + * \property Q3DTheme::ambientLightStrength + * + * Ambient light strength for the whole graph. Value must be between 0.0f and 1.0f. + */ void Q3DTheme::setAmbientLightStrength(float strength) { - if (d_ptr->m_ambientLightStrength != strength) { + if (strength < 0.0f || strength > 1.0f) { + qWarning("Invalid value. Valid range for ambientLightStrength is between 0.0f and 1.0f"); + } else if (d_ptr->m_ambientLightStrength != strength) { d_ptr->m_dirtyBits.ambientLightStrengthDirty = true; d_ptr->m_ambientLightStrength = strength; emit ambientLightStrengthChanged(strength); - emit needRender(); + emit d_ptr->needRender(); } } @@ -252,13 +701,20 @@ float Q3DTheme::ambientLightStrength() const return d_ptr->m_ambientLightStrength; } +/*! + * \property Q3DTheme::highlightLightStrength + * + * Specular light strength for highlighted objects. Value must be between 0.0f and 10.0f. + */ void Q3DTheme::setHighlightLightStrength(float strength) { - if (d_ptr->m_highlightLightStrength != strength) { + if (strength < 0.0f || strength > 10.0f) { + qWarning("Invalid value. Valid range for highlightLightStrength is between 0.0f and 10.0f"); + } else if (d_ptr->m_highlightLightStrength != strength) { d_ptr->m_dirtyBits.highlightLightStrengthDirty = true; d_ptr->m_highlightLightStrength = strength; emit highlightLightStrengthChanged(strength); - emit needRender(); + emit d_ptr->needRender(); } } @@ -267,13 +723,18 @@ float Q3DTheme::highlightLightStrength() const return d_ptr->m_highlightLightStrength; } +/*! + * \property Q3DTheme::labelBorderEnabled + * + * Set label borders enabled or disabled. Has no effect if labelBackgroundEnabled is \c false. + */ void Q3DTheme::setLabelBorderEnabled(bool enabled) { if (d_ptr->m_labelBorders != enabled) { d_ptr->m_dirtyBits.labelBorderEnabledDirty = true; d_ptr->m_labelBorders = enabled; emit labelBorderEnabledChanged(enabled); - emit needRender(); + emit d_ptr->needRender(); } } @@ -282,13 +743,18 @@ bool Q3DTheme::isLabelBorderEnabled() const return d_ptr->m_labelBorders; } +/*! + * \property Q3DTheme::font + * + * Set \a font to be used for labels. + */ void Q3DTheme::setFont(const QFont &font) { if (d_ptr->m_font != font) { d_ptr->m_dirtyBits.fontDirty = true; d_ptr->m_font = font; emit fontChanged(font); - emit needRender(); + emit d_ptr->needRender(); } } @@ -297,13 +763,18 @@ QFont Q3DTheme::font() const return d_ptr->m_font; } +/*! + * \property Q3DTheme::backgroundEnabled + * + * Set background enabled or disabled. + */ void Q3DTheme::setBackgroundEnabled(bool enabled) { if (d_ptr->m_backgoundEnabled != enabled) { d_ptr->m_dirtyBits.backgroundEnabledDirty = true; d_ptr->m_backgoundEnabled = enabled; emit backgroundEnabledChanged(enabled); - emit needRender(); + emit d_ptr->needRender(); } } @@ -312,13 +783,18 @@ bool Q3DTheme::isBackgroundEnabled() const return d_ptr->m_backgoundEnabled; } +/*! + * \property Q3DTheme::gridEnabled + * + * Set grid lines enabled or disabled. + */ void Q3DTheme::setGridEnabled(bool enabled) { if (d_ptr->m_gridEnabled != enabled) { d_ptr->m_dirtyBits.gridEnabledDirty = true; d_ptr->m_gridEnabled = enabled; emit gridEnabledChanged(enabled); - emit needRender(); + emit d_ptr->needRender(); } } @@ -327,13 +803,18 @@ bool Q3DTheme::isGridEnabled() const return d_ptr->m_gridEnabled; } +/*! + * \property Q3DTheme::labelBackgroundEnabled + * + * Set label backgrounds enabled or disabled. + */ void Q3DTheme::setLabelBackgroundEnabled(bool enabled) { if (d_ptr->m_labelBackground != enabled) { d_ptr->m_dirtyBits.labelBackgroundEnabledDirty = true; d_ptr->m_labelBackground = enabled; emit labelBackgroundEnabledChanged(enabled); - emit needRender(); + emit d_ptr->needRender(); } } @@ -342,7 +823,12 @@ bool Q3DTheme::isLabelBackgroundEnabled() const return d_ptr->m_labelBackground; } -void Q3DTheme::setColorStyle(QDataVis::ColorStyle style) +/*! + * \property Q3DTheme::colorStyle + * + * The \a style of the graph colors. One of ColorStyle. + */ +void Q3DTheme::setColorStyle(ColorStyle style) { if (d_ptr->m_colorStyle != style) { d_ptr->m_dirtyBits.colorStyleDirty = true; @@ -351,12 +837,18 @@ void Q3DTheme::setColorStyle(QDataVis::ColorStyle style) } } -QDataVis::ColorStyle Q3DTheme::colorStyle() const +Q3DTheme::ColorStyle Q3DTheme::colorStyle() const { return d_ptr->m_colorStyle; } -void Q3DTheme::setType(QDataVis::Theme themeType) +/*! + * \property Q3DTheme::type + * + * The type of the theme. Type is automatically set when constructing a theme. User should not + * need to use this when using C++ API. + */ +void Q3DTheme::setType(Theme themeType) { if (d_ptr->m_themeId != themeType) { d_ptr->m_dirtyBits.themeIdDirty = true; @@ -365,14 +857,14 @@ void Q3DTheme::setType(QDataVis::Theme themeType) } } -QDataVis::Theme Q3DTheme::type() const +Q3DTheme::Theme Q3DTheme::type() const { return d_ptr->m_themeId; } // Q3DThemePrivate -Q3DThemePrivate::Q3DThemePrivate(Q3DTheme *q, QDataVis::Theme theme_id) +Q3DThemePrivate::Q3DThemePrivate(Q3DTheme *q, Q3DTheme::Theme theme_id) : QObject(0), m_themeId(theme_id), m_baseColor(Qt::white), @@ -393,11 +885,11 @@ Q3DThemePrivate::Q3DThemePrivate(Q3DTheme *q, QDataVis::Theme theme_id) m_multiHighlightGradient(QLinearGradient(qreal(gradientTextureWidth), qreal(gradientTextureHeight), 0.0, 0.0)), - m_lightStrength(0.5f), + m_lightStrength(5.0f), m_ambientLightStrength(0.25f), - m_highlightLightStrength(0.75f), + m_highlightLightStrength(7.5f), m_labelBorders(true), - m_colorStyle(QDataVis::ColorStyleUniform), + m_colorStyle(Q3DTheme::ColorStyleUniform), m_font(QFont()), m_backgoundEnabled(true), m_gridEnabled(true), @@ -422,16 +914,16 @@ void Q3DThemePrivate::resetDirtyBits() m_dirtyBits.gridEnabledDirty = true; m_dirtyBits.gridLineColorDirty = true; m_dirtyBits.highlightLightStrengthDirty = true; + m_dirtyBits.labelBackgroundColorDirty = true; m_dirtyBits.labelBackgroundEnabledDirty = true; m_dirtyBits.labelBorderEnabledDirty = true; + m_dirtyBits.labelTextColorDirty = true; m_dirtyBits.lightColorDirty = true; m_dirtyBits.lightStrengthDirty = true; m_dirtyBits.multiHighlightColorDirty = true; m_dirtyBits.multiHighlightGradientDirty = true; m_dirtyBits.singleHighlightColorDirty = true; m_dirtyBits.singleHighlightGradientDirty = true; - m_dirtyBits.textBackgroundColorDirty = true; - m_dirtyBits.textColorDirty = true; m_dirtyBits.themeIdDirty = true; m_dirtyBits.windowColorDirty = true; } @@ -489,6 +981,11 @@ bool Q3DThemePrivate::sync(Q3DThemePrivate &other) m_dirtyBits.highlightLightStrengthDirty = false; changed = true; } + if (m_dirtyBits.labelBackgroundColorDirty) { + other.q_ptr->setLabelBackgroundColor(m_textBackgroundColor); + m_dirtyBits.labelBackgroundColorDirty = false; + changed = true; + } if (m_dirtyBits.labelBackgroundEnabledDirty) { other.q_ptr->setLabelBackgroundEnabled(m_labelBackground); m_dirtyBits.labelBackgroundEnabledDirty = false; @@ -499,6 +996,11 @@ bool Q3DThemePrivate::sync(Q3DThemePrivate &other) m_dirtyBits.labelBorderEnabledDirty = false; changed = true; } + if (m_dirtyBits.labelTextColorDirty) { + other.q_ptr->setLabelTextColor(m_textColor); + m_dirtyBits.labelTextColorDirty = false; + changed = true; + } if (m_dirtyBits.lightColorDirty) { other.q_ptr->setLightColor(m_lightColor); m_dirtyBits.lightColorDirty = false; @@ -529,16 +1031,6 @@ bool Q3DThemePrivate::sync(Q3DThemePrivate &other) m_dirtyBits.singleHighlightGradientDirty = false; changed = true; } - if (m_dirtyBits.textBackgroundColorDirty) { - other.q_ptr->setTextBackgroundColor(m_textBackgroundColor); - m_dirtyBits.textBackgroundColorDirty = false; - changed = true; - } - if (m_dirtyBits.textColorDirty) { - other.q_ptr->setTextColor(m_textColor); - m_dirtyBits.textColorDirty = false; - changed = true; - } if (m_dirtyBits.themeIdDirty) { other.m_themeId = m_themeId; // Set directly to avoid a call to ThemeManager's useTheme() m_dirtyBits.themeIdDirty = false; diff --git a/src/datavisualization/theme/q3dtheme.h b/src/datavisualization/theme/q3dtheme.h index ea6e0a4b..c3262b91 100644 --- a/src/datavisualization/theme/q3dtheme.h +++ b/src/datavisualization/theme/q3dtheme.h @@ -31,12 +31,14 @@ class Q3DThemePrivate; class QT_DATAVISUALIZATION_EXPORT Q3DTheme : public QObject { Q_OBJECT - Q_PROPERTY(QtDataVisualization::QDataVis::Theme type READ type WRITE setType NOTIFY typeChanged) + 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(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) Q_PROPERTY(QColor windowColor READ windowColor WRITE setWindowColor NOTIFY windowColorChanged) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged) - Q_PROPERTY(QColor textBackgroundColor READ textBackgroundColor WRITE setTextBackgroundColor NOTIFY textBackgroundColorChanged) + Q_PROPERTY(QColor labelTextColor READ labelTextColor WRITE setLabelTextColor NOTIFY labelTextColorChanged) + Q_PROPERTY(QColor labelBackgroundColor READ labelBackgroundColor WRITE setLabelBackgroundColor NOTIFY labelBackgroundColorChanged) Q_PROPERTY(QColor gridLineColor READ gridLineColor WRITE setGridLineColor NOTIFY gridLineColorChanged) Q_PROPERTY(QColor singleHighlightColor READ singleHighlightColor WRITE setSingleHighlightColor NOTIFY singleHighlightColorChanged) Q_PROPERTY(QColor multiHighlightColor READ multiHighlightColor WRITE setMultiHighlightColor NOTIFY multiHighlightColorChanged) @@ -52,16 +54,35 @@ class QT_DATAVISUALIZATION_EXPORT Q3DTheme : public QObject Q_PROPERTY(bool backgroundEnabled READ isBackgroundEnabled WRITE setBackgroundEnabled NOTIFY backgroundEnabledChanged) Q_PROPERTY(bool gridEnabled READ isGridEnabled WRITE setGridEnabled NOTIFY gridEnabledChanged) Q_PROPERTY(bool labelBackgroundEnabled READ isLabelBackgroundEnabled WRITE setLabelBackgroundEnabled NOTIFY labelBackgroundEnabledChanged) - Q_PROPERTY(QtDataVisualization::QDataVis::ColorStyle colorStyle READ colorStyle WRITE setColorStyle NOTIFY colorStyleChanged) - // TODO: Add everything that we need + Q_PROPERTY(ColorStyle colorStyle READ colorStyle WRITE setColorStyle NOTIFY colorStyleChanged) + // TODO: Add everything we need (specularIntensity, lightDegradation, shaders?) + +public: + enum ColorStyle { + ColorStyleUniform = 0, + ColorStyleObjectGradient, + ColorStyleRangeGradient + }; + + enum Theme { + ThemeQt, + ThemePrimaryColors, + ThemeDigia, + ThemeStoneMoss, + ThemeArmyBlue, + ThemeRetro, + ThemeEbony, + ThemeIsabelle, + ThemeUserDefined + }; public: explicit Q3DTheme(QObject *parent = 0); - explicit Q3DTheme(QDataVis::Theme themeType, QObject *parent = 0); + explicit Q3DTheme(Theme themeType, QObject *parent = 0); virtual ~Q3DTheme(); - void setType(QDataVis::Theme themeType); - QDataVis::Theme type() const; + void setType(Theme themeType); + Theme type() const; void setBaseColor(const QColor &color); QColor baseColor() const; @@ -72,11 +93,11 @@ public: void setWindowColor(const QColor &color); QColor windowColor() const; - void setTextColor(const QColor &color); - QColor textColor() const; + void setLabelTextColor(const QColor &color); + QColor labelTextColor() const; - void setTextBackgroundColor(const QColor &color); - QColor textBackgroundColor() const; + void setLabelBackgroundColor(const QColor &color); + QColor labelBackgroundColor() const; void setGridLineColor(const QColor &color); QColor gridLineColor() const; @@ -123,16 +144,16 @@ public: void setLabelBackgroundEnabled(bool enabled); bool isLabelBackgroundEnabled() const; - void setColorStyle(QDataVis::ColorStyle style); - QDataVis::ColorStyle colorStyle() const; + void setColorStyle(ColorStyle style); + ColorStyle colorStyle() const; signals: - void typeChanged(QDataVis::Theme themeType); + void typeChanged(Theme themeType); void baseColorChanged(QColor color); void backgroundColorChanged(QColor color); void windowColorChanged(QColor color); - void textColorChanged(QColor color); - void textBackgroundColorChanged(QColor color); + void labelTextColorChanged(QColor color); + void labelBackgroundColorChanged(QColor color); void gridLineColorChanged(QColor color); void singleHighlightColorChanged(QColor color); void multiHighlightColorChanged(QColor color); @@ -148,14 +169,10 @@ signals: void backgroundEnabledChanged(bool enabled); void gridEnabledChanged(bool enabled); void labelBackgroundEnabledChanged(bool enabled); - void colorStyleChanged(QDataVis::ColorStyle style); - - void needRender(); + void colorStyleChanged(ColorStyle style); protected: - explicit Q3DTheme(Q3DThemePrivate *d, - QDataVis::Theme themeType, - QObject *parent = 0); + explicit Q3DTheme(Q3DThemePrivate *d, Theme themeType, QObject *parent = 0); QScopedPointer<Q3DThemePrivate> d_ptr; friend class ThemeManager; diff --git a/src/datavisualization/theme/q3dtheme_p.h b/src/datavisualization/theme/q3dtheme_p.h index 9107095c..1d2032fb 100644 --- a/src/datavisualization/theme/q3dtheme_p.h +++ b/src/datavisualization/theme/q3dtheme_p.h @@ -38,8 +38,8 @@ struct Q3DThemeDirtyBitField { bool baseColorDirty : 1; bool backgroundColorDirty : 1; bool windowColorDirty : 1; - bool textColorDirty : 1; - bool textBackgroundColorDirty : 1; + bool labelTextColorDirty : 1; + bool labelBackgroundColorDirty : 1; bool gridLineColorDirty : 1; bool singleHighlightColorDirty : 1; bool multiHighlightColorDirty : 1; @@ -62,8 +62,8 @@ struct Q3DThemeDirtyBitField { : baseColorDirty(false), backgroundColorDirty(false), windowColorDirty(false), - textColorDirty(false), - textBackgroundColorDirty(false), + labelTextColorDirty(false), + labelBackgroundColorDirty(false), gridLineColorDirty(false), singleHighlightColorDirty(false), multiHighlightColorDirty(false), @@ -90,15 +90,18 @@ class Q3DThemePrivate : public QObject Q_OBJECT public: Q3DThemePrivate(Q3DTheme *q, - QDataVis::Theme theme_id = QDataVis::ThemeUserDefined); + Q3DTheme::Theme theme_id = Q3DTheme::ThemeUserDefined); virtual ~Q3DThemePrivate(); void resetDirtyBits(); bool sync(Q3DThemePrivate &other); +signals: + void needRender(); + public: - QDataVis::Theme m_themeId; + Q3DTheme::Theme m_themeId; Q3DThemeDirtyBitField m_dirtyBits; @@ -118,7 +121,7 @@ public: float m_ambientLightStrength; float m_highlightLightStrength; bool m_labelBorders; - QDataVis::ColorStyle m_colorStyle; + Q3DTheme::ColorStyle m_colorStyle; QFont m_font; bool m_backgoundEnabled; bool m_gridEnabled; diff --git a/src/datavisualization/theme/thememanager.cpp b/src/datavisualization/theme/thememanager.cpp index d552287b..644cedc9 100644 --- a/src/datavisualization/theme/thememanager.cpp +++ b/src/datavisualization/theme/thememanager.cpp @@ -39,15 +39,16 @@ void ThemeManager::setTheme(Q3DTheme *theme) if (m_theme.data() != theme) { // Disconnect old theme signal connections if (m_theme) { + disconnect(m_theme->d_ptr.data(), 0, m_controller, 0); disconnect(m_theme.data(), 0, m_controller, 0); disconnect(m_theme.data(), 0, this, 0); } m_theme.reset(theme); - QDataVis::Theme type = m_theme->type(); + Q3DTheme::Theme type = m_theme->type(); - if (type != QDataVis::ThemeUserDefined) { + if (type != Q3DTheme::ThemeUserDefined) { useTheme(type); // Reset all bits to dirty for sync m_theme->d_ptr->resetDirtyBits(); @@ -81,18 +82,19 @@ void ThemeManager::connectThemeSignals() connect(m_theme.data(), &Q3DTheme::multiHighlightGradientChanged, m_controller, &Abstract3DController::setMultiHighlightGradient); - connect(m_theme.data(), &Q3DTheme::needRender, m_controller, &Abstract3DController::needRender); + connect(m_theme->d_ptr.data(), &Q3DThemePrivate::needRender, + m_controller, &Abstract3DController::needRender); connect(m_theme.data(), &Q3DTheme::typeChanged, this, &ThemeManager::useTheme); } -void ThemeManager::useTheme(QDataVis::Theme type) +void ThemeManager::useTheme(Q3DTheme::Theme type) { QColor color; QLinearGradient gradient; switch (type) { - case QDataVis::ThemeQt: { + case Q3DTheme::ThemeQt: { setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); @@ -110,7 +112,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) setAmbientLightStrength(0.5f); setHighlightLightStrength(5.0f); setLabelBorderEnabled(true); - setColorStyle(QDataVis::ColorStyleUniform); + setColorStyle(Q3DTheme::ColorStyleUniform); gradient = QLinearGradient(qreal(gradientTextureWidth), qreal(gradientTextureHeight), 0.0, 0.0); @@ -135,7 +137,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) break; } - case QDataVis::ThemePrimaryColors: { + case Q3DTheme::ThemePrimaryColors: { setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); @@ -153,7 +155,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) setAmbientLightStrength(0.5f); setHighlightLightStrength(5.0f); setLabelBorderEnabled(false); - setColorStyle(QDataVis::ColorStyleUniform); + setColorStyle(Q3DTheme::ColorStyleUniform); gradient = QLinearGradient(qreal(gradientTextureWidth), qreal(gradientTextureHeight), 0.0, 0.0); @@ -178,7 +180,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) break; } - case QDataVis::ThemeDigia: { + case Q3DTheme::ThemeDigia: { setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); @@ -196,7 +198,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) setAmbientLightStrength(0.5f); setHighlightLightStrength(5.0f); setLabelBorderEnabled(false); - setColorStyle(QDataVis::ColorStyleObjectGradient); + setColorStyle(Q3DTheme::ColorStyleObjectGradient); gradient = QLinearGradient(qreal(gradientTextureWidth), qreal(gradientTextureHeight), 0.0, 0.0); @@ -221,7 +223,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) break; } - case QDataVis::ThemeStoneMoss: { + case Q3DTheme::ThemeStoneMoss: { setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); @@ -239,7 +241,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) setAmbientLightStrength(0.5f); setHighlightLightStrength(5.0f); setLabelBorderEnabled(true); - setColorStyle(QDataVis::ColorStyleUniform); + setColorStyle(Q3DTheme::ColorStyleUniform); gradient = QLinearGradient(qreal(gradientTextureWidth), qreal(gradientTextureHeight), 0.0, 0.0); @@ -264,7 +266,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) break; } - case QDataVis::ThemeArmyBlue: { + case Q3DTheme::ThemeArmyBlue: { setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); @@ -282,7 +284,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) setAmbientLightStrength(0.5f); setHighlightLightStrength(5.0f); setLabelBorderEnabled(false); - setColorStyle(QDataVis::ColorStyleObjectGradient); + setColorStyle(Q3DTheme::ColorStyleObjectGradient); gradient = QLinearGradient(qreal(gradientTextureWidth), qreal(gradientTextureHeight), 0.0, 0.0); @@ -307,7 +309,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) break; } - case QDataVis::ThemeRetro: { + case Q3DTheme::ThemeRetro: { setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); @@ -325,7 +327,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) setAmbientLightStrength(0.5f); setHighlightLightStrength(5.0f); setLabelBorderEnabled(false); - setColorStyle(QDataVis::ColorStyleObjectGradient); + setColorStyle(Q3DTheme::ColorStyleObjectGradient); gradient = QLinearGradient(qreal(gradientTextureWidth), qreal(gradientTextureHeight), 0.0, 0.0); @@ -350,7 +352,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) break; } - case QDataVis::ThemeEbony: { + case Q3DTheme::ThemeEbony: { setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); @@ -368,7 +370,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) setAmbientLightStrength(0.5f); setHighlightLightStrength(5.0f); setLabelBorderEnabled(false); - setColorStyle(QDataVis::ColorStyleUniform); + setColorStyle(Q3DTheme::ColorStyleUniform); gradient = QLinearGradient(qreal(gradientTextureWidth), qreal(gradientTextureHeight), 0.0, 0.0); @@ -393,7 +395,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) break; } - case QDataVis::ThemeIsabelle: { + case Q3DTheme::ThemeIsabelle: { setBackgroundEnabled(true); setGridEnabled(true); setFont(QFont(QStringLiteral("Arial"))); @@ -411,7 +413,7 @@ void ThemeManager::useTheme(QDataVis::Theme type) setAmbientLightStrength(0.5f); setHighlightLightStrength(5.0f); setLabelBorderEnabled(false); - setColorStyle(QDataVis::ColorStyleUniform); + setColorStyle(Q3DTheme::ColorStyleUniform); gradient = QLinearGradient(qreal(gradientTextureWidth), qreal(gradientTextureHeight), 0.0, 0.0); @@ -460,14 +462,14 @@ void ThemeManager::setWindowColor(const QColor &color) void ThemeManager::setTextColor(const QColor &color) { - if (!m_theme->d_ptr->m_dirtyBits.textColorDirty) - m_theme->setTextColor(color); + if (!m_theme->d_ptr->m_dirtyBits.labelTextColorDirty) + m_theme->setLabelTextColor(color); } void ThemeManager::setTextBackgroundColor(const QColor &color) { - if (!m_theme->d_ptr->m_dirtyBits.textBackgroundColorDirty) - m_theme->setTextBackgroundColor(color); + if (!m_theme->d_ptr->m_dirtyBits.labelBackgroundColorDirty) + m_theme->setLabelBackgroundColor(color); } void ThemeManager::setGridLineColor(const QColor &color) @@ -560,7 +562,7 @@ void ThemeManager::setLabelBackgroundEnabled(bool enabled) m_theme->setLabelBackgroundEnabled(enabled); } -void ThemeManager::setColorStyle(QDataVis::ColorStyle style) +void ThemeManager::setColorStyle(Q3DTheme::ColorStyle style) { if (!m_theme->d_ptr->m_dirtyBits.colorStyleDirty) m_theme->setColorStyle(style); diff --git a/src/datavisualization/theme/thememanager_p.h b/src/datavisualization/theme/thememanager_p.h index 33277105..4a394a4a 100644 --- a/src/datavisualization/theme/thememanager_p.h +++ b/src/datavisualization/theme/thememanager_p.h @@ -47,7 +47,7 @@ public: protected: void connectThemeSignals(); - void useTheme(QDataVis::Theme type); + void useTheme(Q3DTheme::Theme type); void setBaseColor(const QColor &color); void setBackgroundColor(const QColor &color); void setWindowColor(const QColor &color); @@ -68,7 +68,7 @@ protected: void setBackgroundEnabled(bool enabled); void setGridEnabled(bool enabled); void setLabelBackgroundEnabled(bool enabled); - void setColorStyle(QDataVis::ColorStyle style); + void setColorStyle(Q3DTheme::ColorStyle style); private: QScopedPointer<Q3DTheme> m_theme; |