summaryrefslogtreecommitdiffstats
path: root/src/datavisualizationqml2
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-12-03 08:43:55 +0200
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-12-03 08:47:20 +0200
commit50bc17dfb181a8806fe6814f77a55223a51335ef (patch)
tree58bbf24baecbf7763ab11160e9ff1cc779a08b30 /src/datavisualizationqml2
parent7b621b89e40b9006bc8ffbb8595bba336fb60d42 (diff)
QML gradient support for theme
Task-number: QTRD-2664 Change-Id: I66e5890ef284ad7a28f7034c3c3d4e6ce01b0c1d Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavisualizationqml2')
-rw-r--r--src/datavisualizationqml2/colorgradient_p.h1
-rw-r--r--src/datavisualizationqml2/datavisualizationqml2.pro6
-rw-r--r--src/datavisualizationqml2/datavisualizationqml2_plugin.cpp8
-rw-r--r--src/datavisualizationqml2/datavisualizationqml2_plugin.h2
-rw-r--r--src/datavisualizationqml2/declarativesurface.cpp1
-rw-r--r--src/datavisualizationqml2/declarativetheme.cpp161
-rw-r--r--src/datavisualizationqml2/declarativetheme_p.h84
7 files changed, 257 insertions, 6 deletions
diff --git a/src/datavisualizationqml2/colorgradient_p.h b/src/datavisualizationqml2/colorgradient_p.h
index 37d3e407..d1cc0543 100644
--- a/src/datavisualizationqml2/colorgradient_p.h
+++ b/src/datavisualizationqml2/colorgradient_p.h
@@ -83,6 +83,7 @@ private:
friend class ColorGradientStop;
friend class DeclarativeSurface;
+ friend class DeclarativeTheme3D;
};
QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualizationqml2/datavisualizationqml2.pro b/src/datavisualizationqml2/datavisualizationqml2.pro
index 5a5ab476..2ae9ae1a 100644
--- a/src/datavisualizationqml2/datavisualizationqml2.pro
+++ b/src/datavisualizationqml2/datavisualizationqml2.pro
@@ -28,7 +28,8 @@ SOURCES += \
declarativesurfacerenderer.cpp \
abstractdeclarative.cpp \
colorgradient.cpp \
- declarativeseries.cpp
+ declarativeseries.cpp \
+ declarativetheme.cpp
HEADERS += \
datavisualizationqml2_plugin.h \
@@ -40,7 +41,8 @@ HEADERS += \
declarativesurfacerenderer_p.h \
abstractdeclarative_p.h \
colorgradient_p.h \
- declarativeseries_p.h
+ declarativeseries_p.h \
+ declarativetheme_p.h
OTHER_FILES = qmldir
diff --git a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp
index 1368b480..4dd095f8 100644
--- a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp
+++ b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp
@@ -40,9 +40,9 @@ void Datavis3Dqml2Plugin::registerTypes(const char *uri)
qmlRegisterUncreatableType<QSurfaceDataProxy>(uri, 1, 0, "SurfaceDataProxy",
QLatin1String("Trying to create uncreatable: SurfaceDataProxy."));
qmlRegisterUncreatableType<AbstractDeclarative>(uri, 1, 0, "AbstractGraph3D",
- QLatin1String("Trying to create uncreatable: AbstractGraph3D."));
+ QLatin1String("Trying to create uncreatable: AbstractGraph3D."));
qmlRegisterUncreatableType<Q3DScene>(uri, 1, 0, "Scene3D",
- QLatin1String("Trying to create uncreatable: Scene3D."));
+ QLatin1String("Trying to create uncreatable: Scene3D."));
qmlRegisterUncreatableType<QAbstract3DSeries>(uri, 1, 0, "Abstract3DSeries",
QLatin1String("Trying to create uncreatable: Abstract3DSeries."));
qmlRegisterUncreatableType<QBar3DSeries>(uri, 1, 0, "QBar3DSeries",
@@ -51,6 +51,8 @@ void Datavis3Dqml2Plugin::registerTypes(const char *uri)
QLatin1String("Trying to create uncreatable: QScatter3DSeries, use Scatter3DSeries instead."));
qmlRegisterUncreatableType<QSurface3DSeries>(uri, 1, 0, "QSurface3DSeries",
QLatin1String("Trying to create uncreatable: QSurface3DSeries, use Surface3DSeries instead."));
+ qmlRegisterUncreatableType<Q3DTheme>(uri, 1, 0, "Q3DTheme",
+ QLatin1String("Trying to create uncreatable: Q3DTheme, use Theme3D instead."));
qmlRegisterType<DeclarativeBars>(uri, 1, 0, "Bars3D");
qmlRegisterType<DeclarativeScatter>(uri, 1, 0, "Scatter3D");
@@ -69,7 +71,7 @@ void Datavis3Dqml2Plugin::registerTypes(const char *uri)
qmlRegisterType<ColorGradientStop>(uri, 1, 0, "ColorGradientStop");
qmlRegisterType<ColorGradient>(uri, 1, 0, "ColorGradient");
- qmlRegisterType<Q3DTheme>(uri, 1, 0, "Theme3D");
+ qmlRegisterType<DeclarativeTheme3D>(uri, 1, 0, "Theme3D");
qmlRegisterType<DeclarativeBar3DSeries>(uri, 1, 0, "Bar3DSeries");
qmlRegisterType<DeclarativeScatter3DSeries>(uri, 1, 0, "Scatter3DSeries");
diff --git a/src/datavisualizationqml2/datavisualizationqml2_plugin.h b/src/datavisualizationqml2/datavisualizationqml2_plugin.h
index b9cda29c..799f26ca 100644
--- a/src/datavisualizationqml2/datavisualizationqml2_plugin.h
+++ b/src/datavisualizationqml2/datavisualizationqml2_plugin.h
@@ -38,6 +38,7 @@
#include "qsurface3dseries.h"
#include "declarativeseries_p.h"
#include "q3dtheme.h"
+#include "declarativetheme_p.h"
#include <QQmlExtensionPlugin>
@@ -79,6 +80,7 @@ QML_DECLARE_TYPE(ColorGradientStop)
QML_DECLARE_TYPE(ColorGradient)
QML_DECLARE_TYPE(Q3DTheme)
+QML_DECLARE_TYPE(DeclarativeTheme3D)
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
diff --git a/src/datavisualizationqml2/declarativesurface.cpp b/src/datavisualizationqml2/declarativesurface.cpp
index 62288529..7d69eee8 100644
--- a/src/datavisualizationqml2/declarativesurface.cpp
+++ b/src/datavisualizationqml2/declarativesurface.cpp
@@ -151,7 +151,6 @@ void DeclarativeSurface::setGradient(ColorGradient *gradient)
ColorGradient *DeclarativeSurface::gradient() const
{
-
return m_gradient;
}
diff --git a/src/datavisualizationqml2/declarativetheme.cpp b/src/datavisualizationqml2/declarativetheme.cpp
new file mode 100644
index 00000000..f51825f3
--- /dev/null
+++ b/src/datavisualizationqml2/declarativetheme.cpp
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+#include "declarativetheme_p.h"
+
+QT_DATAVISUALIZATION_BEGIN_NAMESPACE
+
+DeclarativeTheme3D::DeclarativeTheme3D(QObject *parent)
+ : Q3DTheme(parent),
+ m_baseGradient(0),
+ m_singleHLGradient(0),
+ m_multiHLGradient(0)
+{
+}
+
+DeclarativeTheme3D::~DeclarativeTheme3D()
+{
+}
+
+void DeclarativeTheme3D::handleBaseGradientUpdate()
+{
+ if (m_baseGradient)
+ setThemeGradient(*m_baseGradient, GradientTypeBase);
+}
+
+void DeclarativeTheme3D::handleSingleHLGradientUpdate()
+{
+ if (m_singleHLGradient)
+ setThemeGradient(*m_singleHLGradient, GradientTypeSingleHL);
+}
+
+void DeclarativeTheme3D::handleMultiHLGradientUpdate()
+{
+ if (m_multiHLGradient)
+ setThemeGradient(*m_multiHLGradient, GradientTypeMultiHL);
+}
+
+void DeclarativeTheme3D::setBaseGradient(ColorGradient *gradient)
+{
+ // connect new / disconnect old
+ if (gradient != m_baseGradient) {
+ if (m_baseGradient)
+ QObject::disconnect(m_baseGradient, 0, this, 0);
+
+ m_baseGradient = gradient;
+
+ if (m_baseGradient) {
+ QObject::connect(m_baseGradient, &ColorGradient::updated, this,
+ &DeclarativeTheme3D::handleBaseGradientUpdate);
+ }
+
+ emit baseGradientChanged(m_baseGradient);
+ }
+
+ if (m_baseGradient)
+ setThemeGradient(*m_baseGradient, GradientTypeBase);
+}
+
+ColorGradient *DeclarativeTheme3D::baseGradient() const
+{
+ return m_baseGradient;
+}
+
+void DeclarativeTheme3D::setSingleHighlightGradient(ColorGradient *gradient)
+{
+ // connect new / disconnect old
+ if (gradient != m_singleHLGradient) {
+ if (m_singleHLGradient)
+ QObject::disconnect(m_singleHLGradient, 0, this, 0);
+
+ m_singleHLGradient = gradient;
+
+ if (m_singleHLGradient) {
+ QObject::connect(m_singleHLGradient, &ColorGradient::updated, this,
+ &DeclarativeTheme3D::handleSingleHLGradientUpdate);
+ }
+
+ emit singleHighlightGradientChanged(m_singleHLGradient);
+ }
+
+ if (m_singleHLGradient)
+ setThemeGradient(*m_singleHLGradient, GradientTypeSingleHL);
+}
+
+ColorGradient *DeclarativeTheme3D::singleHighlightGradient() const
+{
+ return m_singleHLGradient;
+}
+
+void DeclarativeTheme3D::setMultiHighlightGradient(ColorGradient *gradient)
+{
+ // connect new / disconnect old
+ if (gradient != m_multiHLGradient) {
+ if (m_multiHLGradient)
+ QObject::disconnect(m_multiHLGradient, 0, this, 0);
+
+ m_multiHLGradient = gradient;
+
+ if (m_multiHLGradient) {
+ QObject::connect(m_multiHLGradient, &ColorGradient::updated, this,
+ &DeclarativeTheme3D::handleMultiHLGradientUpdate);
+ }
+
+ emit multiHighlightGradientChanged(m_multiHLGradient);
+ }
+
+ if (m_multiHLGradient)
+ setThemeGradient(*m_baseGradient, GradientTypeMultiHL);
+}
+
+ColorGradient *DeclarativeTheme3D::multiHighlightGradient() const
+{
+ return m_multiHLGradient;
+}
+
+void DeclarativeTheme3D::setThemeGradient(const ColorGradient &gradient, GradientType type)
+{
+ QLinearGradient newGradient;
+ QGradientStops stops;
+ QList<ColorGradientStop *> qmlstops = gradient.m_stops;
+
+ // Get sorted gradient stops
+ for (int i = 0; i < qmlstops.size(); i++) {
+ int j = 0;
+ while (j < stops.size() && stops.at(j).first < qmlstops[i]->position())
+ j++;
+ stops.insert(j, QGradientStop(qmlstops.at(i)->position(), qmlstops.at(i)->color()));
+ }
+
+ newGradient.setStops(stops);
+ switch (type) {
+ case GradientTypeBase:
+ Q3DTheme::setBaseGradient(newGradient);
+ break;
+ case GradientTypeSingleHL:
+ Q3DTheme::setSingleHighlightGradient(newGradient);
+ break;
+ case GradientTypeMultiHL:
+ break;
+ Q3DTheme::setMultiHighlightGradient(newGradient);
+ default:
+ break;
+ }
+}
+
+QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualizationqml2/declarativetheme_p.h b/src/datavisualizationqml2/declarativetheme_p.h
new file mode 100644
index 00000000..2ada1516
--- /dev/null
+++ b/src/datavisualizationqml2/declarativetheme_p.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the QtDataVisualization API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef DECLARATIVETHEME_P_H
+#define DECLARATIVETHEME_P_H
+
+#include "datavisualizationglobal_p.h"
+#include "colorgradient_p.h"
+#include "q3dtheme.h"
+
+QT_DATAVISUALIZATION_BEGIN_NAMESPACE
+
+class DeclarativeTheme3D : public Q3DTheme
+{
+ Q_OBJECT
+ Q_PROPERTY(ColorGradient *baseGradient READ baseGradient WRITE setBaseGradient NOTIFY baseGradientChanged)
+ Q_PROPERTY(ColorGradient *singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged)
+ Q_PROPERTY(ColorGradient *multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged)
+
+public:
+ DeclarativeTheme3D(QObject *parent = 0);
+ virtual ~DeclarativeTheme3D();
+
+ void setBaseGradient(ColorGradient *gradient);
+ ColorGradient *baseGradient() const;
+
+ void setSingleHighlightGradient(ColorGradient *gradient);
+ ColorGradient *singleHighlightGradient() const;
+
+ void setMultiHighlightGradient(ColorGradient *gradient);
+ ColorGradient *multiHighlightGradient() const;
+
+signals:
+ void baseGradientChanged(ColorGradient *gradient);
+ void singleHighlightGradientChanged(ColorGradient *gradient);
+ void multiHighlightGradientChanged(ColorGradient *gradient);
+
+protected:
+ void handleBaseGradientUpdate();
+ void handleSingleHLGradientUpdate();
+ void handleMultiHLGradientUpdate();
+
+ enum GradientType {
+ GradientTypeBase = 0,
+ GradientTypeSingleHL,
+ GradientTypeMultiHL
+ };
+
+private:
+ void setThemeGradient(const ColorGradient &gradient, GradientType type);
+
+ ColorGradient *m_baseGradient; // Not owned
+ ColorGradient *m_singleHLGradient; // Not owned
+ ColorGradient *m_multiHLGradient; // Not owned
+};
+
+QT_DATAVISUALIZATION_END_NAMESPACE
+
+#endif