aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2017-06-06 14:54:37 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2017-06-08 10:32:18 +0000
commitf4f89858cffa1107af5139dfb1e1d7b16ca3a1a0 (patch)
tree848471b6d85eebfea8915f1da89b26286f0dbbc7 /src/imports
parent8a5837467d153c50c869625390a584b0335b77b7 (diff)
Use GradientStop and rename ShapeLinearGradient to LinearGradient
Thus application code becomes: ShapePath { ... fillGradient: LinearGradient { ... GradientStop { ... } } } which is even more clean and readable. The duplication for stops is now avoided. Change-Id: I50ae2f388e21683a37dc4787763dc71e16eef4f5 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/shapes/plugin.cpp3
-rw-r--r--src/imports/shapes/plugins.qmltypes10
-rw-r--r--src/imports/shapes/qquickshape.cpp166
-rw-r--r--src/imports/shapes/qquickshape_p.h36
-rw-r--r--src/imports/shapes/qquickshapegenericrenderer.cpp2
-rw-r--r--src/imports/shapes/qquickshapenvprrenderer.cpp2
-rw-r--r--src/imports/shapes/qquickshapesoftwarerenderer.cpp2
7 files changed, 30 insertions, 191 deletions
diff --git a/src/imports/shapes/plugin.cpp b/src/imports/shapes/plugin.cpp
index 2f2f8c74d3..ae0d02da93 100644
--- a/src/imports/shapes/plugin.cpp
+++ b/src/imports/shapes/plugin.cpp
@@ -63,9 +63,8 @@ public:
Q_ASSERT(QByteArray(uri) == QByteArray("QtQuick.Shapes"));
qmlRegisterType<QQuickShape>(uri, 1, 0, "Shape");
qmlRegisterType<QQuickShapePath>(uri, 1, 0, "ShapePath");
- qmlRegisterType<QQuickShapeGradientStop>(uri, 1, 0, "ShapeGradientStop");
qmlRegisterUncreatableType<QQuickShapeGradient>(uri, 1, 0, "ShapeGradient", QQuickShapeGradient::tr("ShapeGradient is an abstract base class"));
- qmlRegisterType<QQuickShapeLinearGradient>(uri, 1, 0, "ShapeLinearGradient");
+ qmlRegisterType<QQuickShapeLinearGradient>(uri, 1, 0, "LinearGradient");
}
};
diff --git a/src/imports/shapes/plugins.qmltypes b/src/imports/shapes/plugins.qmltypes
index 28d8dd1f12..00d0050085 100644
--- a/src/imports/shapes/plugins.qmltypes
+++ b/src/imports/shapes/plugins.qmltypes
@@ -192,14 +192,6 @@ Module {
Signal { name: "updated" }
}
Component {
- name: "QQuickShapeGradientStop"
- prototype: "QObject"
- exports: ["QtQuick.Shapes/ShapeGradientStop 1.0"]
- exportMetaObjectRevisions: [0]
- Property { name: "position"; type: "double" }
- Property { name: "color"; type: "QColor" }
- }
- Component {
name: "QQuickShape"
defaultProperty: "elements"
prototype: "QQuickItem"
@@ -232,7 +224,7 @@ Module {
name: "QQuickShapeLinearGradient"
defaultProperty: "stops"
prototype: "QQuickShapeGradient"
- exports: ["QtQuick.Shapes/ShapeLinearGradient 1.0"]
+ exports: ["QtQuick.Shapes/LinearGradient 1.0"]
exportMetaObjectRevisions: [0]
Property { name: "x1"; type: "double" }
Property { name: "y1"; type: "double" }
diff --git a/src/imports/shapes/qquickshape.cpp b/src/imports/shapes/qquickshape.cpp
index 81736fcd82..3c253eabd4 100644
--- a/src/imports/shapes/qquickshape.cpp
+++ b/src/imports/shapes/qquickshape.cpp
@@ -47,12 +47,6 @@
#include <QtGui/private/qdrawhelper_p.h>
#include <QOpenGLFunctions>
-#include <private/qv4engine_p.h>
-#include <private/qv4object_p.h>
-#include <private/qv4qobjectwrapper_p.h>
-#include <private/qv4mm_p.h>
-#include <private/qqmlengine_p.h>
-
QT_BEGIN_NAMESPACE
/*!
@@ -497,6 +491,9 @@ void QQuickShapePath::setDashPattern(const QVector<qreal> &array)
When set, ShapePath.fillColor is ignored and filling is done using one of
the ShapeGradient subtypes.
+
+ \note The Gradient type cannot be used here. Rather, prefer using one of the
+ advanced subtypes, like LinearGradient.
*/
QQuickShapeGradient *QQuickShapePath::fillGradient() const
@@ -570,14 +567,14 @@ void QQuickShapePath::resetFillGradient()
ShapePath {
strokeWidth: 4
strokeColor: "red"
- fillGradient: ShapeLinearGradient {
+ fillGradient: LinearGradient {
x1: 20; y1: 20
x2: 180; y2: 130
- ShapeGradientStop { position: 0; color: "blue" }
- ShapeGradientStop { position: 0.2; color: "green" }
- ShapeGradientStop { position: 0.4; color: "red" }
- ShapeGradientStop { position: 0.6; color: "yellow" }
- ShapeGradientStop { position: 1; color: "cyan" }
+ GradientStop { position: 0; color: "blue" }
+ GradientStop { position: 0.2; color: "green" }
+ GradientStop { position: 0.4; color: "red" }
+ GradientStop { position: 0.6; color: "yellow" }
+ GradientStop { position: 1; color: "cyan" }
}
strokeStyle: ShapePath.DashLine
dashPattern: [ 1, 4 ]
@@ -1063,148 +1060,28 @@ void QQuickShapePrivate::sync()
// ***** gradient support *****
/*!
- \qmltype ShapeGradientStop
- \instantiates QQuickShapeGradientStop
- \inqmlmodule QtQuick.Shapes
- \ingroup qtquick-paths
- \ingroup qtquick-views
- \inherits Object
- \brief Defines a color at a position in a gradient
- \since 5.10
- */
-
-QQuickShapeGradientStop::QQuickShapeGradientStop(QObject *parent)
- : QObject(parent),
- m_position(0),
- m_color(Qt::black)
-{
-}
-
-/*!
- \qmlproperty real QtQuick.Shapes::ShapeGradientStop::position
-
- The position and color properties describe the color used at a given
- position in a gradient, as represented by a gradient stop.
-
- The default value is 0.
- */
-
-qreal QQuickShapeGradientStop::position() const
-{
- return m_position;
-}
-
-void QQuickShapeGradientStop::setPosition(qreal position)
-{
- if (m_position != position) {
- m_position = position;
- if (QQuickShapeGradient *grad = qobject_cast<QQuickShapeGradient *>(parent()))
- emit grad->updated();
- }
-}
-
-/*!
- \qmlproperty real QtQuick.Shapes::ShapeGradientStop::color
-
- The position and color properties describe the color used at a given
- position in a gradient, as represented by a gradient stop.
-
- The default value is \c black.
- */
-
-QColor QQuickShapeGradientStop::color() const
-{
- return m_color;
-}
-
-void QQuickShapeGradientStop::setColor(const QColor &color)
-{
- if (m_color != color) {
- m_color = color;
- if (QQuickShapeGradient *grad = qobject_cast<QQuickShapeGradient *>(parent()))
- emit grad->updated();
- }
-}
-
-/*!
\qmltype ShapeGradient
\instantiates QQuickShapeGradient
\inqmlmodule QtQuick.Shapes
\ingroup qtquick-paths
\ingroup qtquick-views
- \inherits Object
+ \inherits Gradient
\brief Base type of Shape fill gradients
\since 5.10
- This is an abstract base class for gradients like ShapeLinearGradient and
- cannot be created directly.
+ This is an abstract base class for gradients like LinearGradient and
+ cannot be created directly. It extends \l Gradient with properties like the
+ spread mode.
*/
QQuickShapeGradient::QQuickShapeGradient(QObject *parent)
- : QObject(parent),
+ : QQuickGradient(parent),
m_spread(PadSpread)
{
}
-int QQuickShapeGradient::countStops(QQmlListProperty<QObject> *list)
-{
- QQuickShapeGradient *grad = qobject_cast<QQuickShapeGradient *>(list->object);
- Q_ASSERT(grad);
- return grad->m_stops.count();
-}
-
-QObject *QQuickShapeGradient::atStop(QQmlListProperty<QObject> *list, int index)
-{
- QQuickShapeGradient *grad = qobject_cast<QQuickShapeGradient *>(list->object);
- Q_ASSERT(grad);
- return grad->m_stops.at(index);
-}
-
-void QQuickShapeGradient::appendStop(QQmlListProperty<QObject> *list, QObject *stop)
-{
- QQuickShapeGradientStop *sstop = qobject_cast<QQuickShapeGradientStop *>(stop);
- if (!sstop) {
- qWarning("Gradient stop list only supports QQuickShapeGradientStop elements");
- return;
- }
- QQuickShapeGradient *grad = qobject_cast<QQuickShapeGradient *>(list->object);
- Q_ASSERT(grad);
- sstop->setParent(grad);
- grad->m_stops.append(sstop);
-}
-
/*!
- \qmlproperty list<Object> QtQuick.Shapes::ShapeGradient::stops
- \default
-
- The list of ShapeGradientStop objects defining the colors at given positions
- in the gradient.
- */
-
-QQmlListProperty<QObject> QQuickShapeGradient::stops()
-{
- return QQmlListProperty<QObject>(this, nullptr,
- &QQuickShapeGradient::appendStop,
- &QQuickShapeGradient::countStops,
- &QQuickShapeGradient::atStop,
- nullptr);
-}
-
-QGradientStops QQuickShapeGradient::sortedGradientStops() const
-{
- QGradientStops result;
- for (int i = 0; i < m_stops.count(); ++i) {
- QQuickShapeGradientStop *s = static_cast<QQuickShapeGradientStop *>(m_stops[i]);
- int j = 0;
- while (j < result.count() && result[j].first < s->position())
- ++j;
- result.insert(j, QGradientStop(s->position(), s->color()));
- }
- return result;
-}
-
-/*!
- \qmlproperty enumeration QtQuick.Shapes::ShapeGradient::spred
+ \qmlproperty enumeration QtQuick.Shapes::ShapeGradient::spread
Specifies how the area outside the gradient area should be filled. The
default value is ShapeGradient.PadSpread.
@@ -1231,7 +1108,7 @@ void QQuickShapeGradient::setSpread(SpreadMode mode)
}
/*!
- \qmltype ShapeLinearGradient
+ \qmltype LinearGradient
\instantiates QQuickShapeLinearGradient
\inqmlmodule QtQuick.Shapes
\ingroup qtquick-paths
@@ -1244,6 +1121,9 @@ void QQuickShapeGradient::setSpread(SpreadMode mode)
these points the gradient is either padded, reflected or repeated depending
on the spread type.
+ \note LinearGradient is not compatible with Rectangle items that only
+ support Gradient. This type is to be used with Shape.
+
\sa QLinearGradient
*/
@@ -1253,10 +1133,10 @@ QQuickShapeLinearGradient::QQuickShapeLinearGradient(QObject *parent)
}
/*!
- \qmlproperty real QtQuick.Shapes::ShapeLinearGradient::x1
- \qmlproperty real QtQuick.Shapes::ShapeLinearGradient::y1
- \qmlproperty real QtQuick.Shapes::ShapeLinearGradient::x2
- \qmlproperty real QtQuick.Shapes::ShapeLinearGradient::y2
+ \qmlproperty real QtQuick.Shapes::LinearGradient::x1
+ \qmlproperty real QtQuick.Shapes::LinearGradient::y1
+ \qmlproperty real QtQuick.Shapes::LinearGradient::x2
+ \qmlproperty real QtQuick.Shapes::LinearGradient::y2
These properties define the start and end points between which color
interpolation occurs. By default both the stard and end points are set to
diff --git a/src/imports/shapes/qquickshape_p.h b/src/imports/shapes/qquickshape_p.h
index a01c36e971..50b242e492 100644
--- a/src/imports/shapes/qquickshape_p.h
+++ b/src/imports/shapes/qquickshape_p.h
@@ -55,38 +55,16 @@
#include <private/qtquickglobal_p.h>
#include <private/qquickpath_p_p.h>
-#include <private/qv8engine_p.h>
-#include <QGradientStops>
+#include <private/qquickrectangle_p.h>
QT_BEGIN_NAMESPACE
class QQuickShapePathPrivate;
class QQuickShapePrivate;
-class QQuickShapeGradientStop : public QObject
+class QQuickShapeGradient : public QQuickGradient
{
Q_OBJECT
- Q_PROPERTY(qreal position READ position WRITE setPosition)
- Q_PROPERTY(QColor color READ color WRITE setColor)
-
-public:
- QQuickShapeGradientStop(QObject *parent = nullptr);
-
- qreal position() const;
- void setPosition(qreal position);
-
- QColor color() const;
- void setColor(const QColor &color);
-
-private:
- qreal m_position;
- QColor m_color;
-};
-
-class QQuickShapeGradient : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QQmlListProperty<QObject> stops READ stops)
Q_PROPERTY(SpreadMode spread READ spread WRITE setSpread NOTIFY spreadChanged)
Q_CLASSINFO("DefaultProperty", "stops")
@@ -100,23 +78,13 @@ public:
QQuickShapeGradient(QObject *parent = nullptr);
- QQmlListProperty<QObject> stops();
-
- QGradientStops sortedGradientStops() const;
-
SpreadMode spread() const;
void setSpread(SpreadMode mode);
signals:
- void updated();
void spreadChanged();
private:
- static int countStops(QQmlListProperty<QObject> *list);
- static QObject *atStop(QQmlListProperty<QObject> *list, int index);
- static void appendStop(QQmlListProperty<QObject> *list, QObject *stop);
-
- QVector<QObject *> m_stops;
SpreadMode m_spread;
};
diff --git a/src/imports/shapes/qquickshapegenericrenderer.cpp b/src/imports/shapes/qquickshapegenericrenderer.cpp
index ff226959eb..47203698d5 100644
--- a/src/imports/shapes/qquickshapegenericrenderer.cpp
+++ b/src/imports/shapes/qquickshapegenericrenderer.cpp
@@ -247,7 +247,7 @@ void QQuickShapeGenericRenderer::setFillGradient(int index, QQuickShapeGradient
ShapePathData &d(m_sp[index]);
d.fillGradientActive = gradient != nullptr;
if (gradient) {
- d.fillGradient.stops = gradient->sortedGradientStops();
+ d.fillGradient.stops = gradient->gradientStops(); // sorted
d.fillGradient.spread = gradient->spread();
if (QQuickShapeLinearGradient *g = qobject_cast<QQuickShapeLinearGradient *>(gradient)) {
d.fillGradient.start = QPointF(g->x1(), g->y1());
diff --git a/src/imports/shapes/qquickshapenvprrenderer.cpp b/src/imports/shapes/qquickshapenvprrenderer.cpp
index a3e9d31be5..f3f8d807ec 100644
--- a/src/imports/shapes/qquickshapenvprrenderer.cpp
+++ b/src/imports/shapes/qquickshapenvprrenderer.cpp
@@ -135,7 +135,7 @@ void QQuickShapeNvprRenderer::setFillGradient(int index, QQuickShapeGradient *gr
ShapePathGuiData &d(m_sp[index]);
d.fillGradientActive = gradient != nullptr;
if (gradient) {
- d.fillGradient.stops = gradient->sortedGradientStops();
+ d.fillGradient.stops = gradient->gradientStops(); // sorted
d.fillGradient.spread = gradient->spread();
if (QQuickShapeLinearGradient *g = qobject_cast<QQuickShapeLinearGradient *>(gradient)) {
d.fillGradient.start = QPointF(g->x1(), g->y1());
diff --git a/src/imports/shapes/qquickshapesoftwarerenderer.cpp b/src/imports/shapes/qquickshapesoftwarerenderer.cpp
index 33d80be22c..b3373106af 100644
--- a/src/imports/shapes/qquickshapesoftwarerenderer.cpp
+++ b/src/imports/shapes/qquickshapesoftwarerenderer.cpp
@@ -144,7 +144,7 @@ void QQuickShapeSoftwareRenderer::setFillGradient(int index, QQuickShapeGradient
if (QQuickShapeLinearGradient *linearGradient = qobject_cast<QQuickShapeLinearGradient *>(gradient)) {
QLinearGradient painterGradient(linearGradient->x1(), linearGradient->y1(),
linearGradient->x2(), linearGradient->y2());
- painterGradient.setStops(linearGradient->sortedGradientStops());
+ painterGradient.setStops(linearGradient->gradientStops()); // sorted
switch (gradient->spread()) {
case QQuickShapeGradient::PadSpread:
painterGradient.setSpread(QGradient::PadSpread);