diff options
-rw-r--r-- | examples/quick/shapes/content/item11.qml | 6 | ||||
-rw-r--r-- | examples/quick/shapes/content/item12.qml | 6 | ||||
-rw-r--r-- | examples/quick/shapes/content/item5.qml | 12 | ||||
-rw-r--r-- | src/imports/shapes/plugin.cpp | 3 | ||||
-rw-r--r-- | src/imports/shapes/plugins.qmltypes | 10 | ||||
-rw-r--r-- | src/imports/shapes/qquickshape.cpp | 166 | ||||
-rw-r--r-- | src/imports/shapes/qquickshape_p.h | 36 | ||||
-rw-r--r-- | src/imports/shapes/qquickshapegenericrenderer.cpp | 2 | ||||
-rw-r--r-- | src/imports/shapes/qquickshapenvprrenderer.cpp | 2 | ||||
-rw-r--r-- | src/imports/shapes/qquickshapesoftwarerenderer.cpp | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquickshape/data/pathitem3.qml | 12 | ||||
-rw-r--r-- | tests/auto/quick/qquickshape/data/pathitem4.qml | 6 | ||||
-rw-r--r-- | tests/auto/quick/qquickshape/tst_qquickshape.cpp | 7 | ||||
-rw-r--r-- | tests/manual/shapestest/shapestest.qml | 12 |
14 files changed, 60 insertions, 222 deletions
diff --git a/examples/quick/shapes/content/item11.qml b/examples/quick/shapes/content/item11.qml index 21687d42f1..0cfe73d5c9 100644 --- a/examples/quick/shapes/content/item11.qml +++ b/examples/quick/shapes/content/item11.qml @@ -60,10 +60,10 @@ Rectangle { anchors.centerIn: parent ShapePath { - fillGradient: ShapeLinearGradient { + fillGradient: LinearGradient { y2: shape.height - ShapeGradientStop { position: 0; color: "yellow" } - ShapeGradientStop { position: 1; color: "green" } + GradientStop { position: 0; color: "yellow" } + GradientStop { position: 1; color: "green" } } startX: 10; startY: 100 diff --git a/examples/quick/shapes/content/item12.qml b/examples/quick/shapes/content/item12.qml index d4d7816e44..8bdd1bfe50 100644 --- a/examples/quick/shapes/content/item12.qml +++ b/examples/quick/shapes/content/item12.qml @@ -65,11 +65,11 @@ Rectangle { ShapePath { strokeColor: "transparent" - fillGradient: ShapeLinearGradient { + fillGradient: LinearGradient { id: grad y1: 50; y2: 150 - ShapeGradientStop { position: 0; color: "black" } - ShapeGradientStop { position: 1; color: "red" } + GradientStop { position: 0; color: "black" } + GradientStop { position: 1; color: "red" } } startX: 10; startY: 10 diff --git a/examples/quick/shapes/content/item5.qml b/examples/quick/shapes/content/item5.qml index c9874e5ebc..5fd25093ae 100644 --- a/examples/quick/shapes/content/item5.qml +++ b/examples/quick/shapes/content/item5.qml @@ -60,14 +60,14 @@ Rectangle { 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" } } fillColor: "blue" // ignored with the gradient set strokeStyle: ShapePath.DashLine 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); diff --git a/tests/auto/quick/qquickshape/data/pathitem3.qml b/tests/auto/quick/qquickshape/data/pathitem3.qml index 3b819991e6..fccd1aa2de 100644 --- a/tests/auto/quick/qquickshape/data/pathitem3.qml +++ b/tests/auto/quick/qquickshape/data/pathitem3.qml @@ -13,14 +13,14 @@ Item { 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 ] diff --git a/tests/auto/quick/qquickshape/data/pathitem4.qml b/tests/auto/quick/qquickshape/data/pathitem4.qml index 26e7084b8d..1d769051ee 100644 --- a/tests/auto/quick/qquickshape/data/pathitem4.qml +++ b/tests/auto/quick/qquickshape/data/pathitem4.qml @@ -28,10 +28,10 @@ Item { } ShapePath { - fillGradient: ShapeLinearGradient { + fillGradient: LinearGradient { y2: 150 - ShapeGradientStop { position: 0; color: "yellow" } - ShapeGradientStop { position: 1; color: "green" } + GradientStop { position: 0; color: "yellow" } + GradientStop { position: 1; color: "green" } } startX: 10; startY: 100 diff --git a/tests/auto/quick/qquickshape/tst_qquickshape.cpp b/tests/auto/quick/qquickshape/tst_qquickshape.cpp index fecac573b7..a984c28732 100644 --- a/tests/auto/quick/qquickshape/tst_qquickshape.cpp +++ b/tests/auto/quick/qquickshape/tst_qquickshape.cpp @@ -65,9 +65,8 @@ tst_QQuickShape::tst_QQuickShape() const char *uri = "tst_qquickpathitem"; 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"); } void tst_QQuickShape::initValues() @@ -206,9 +205,9 @@ void tst_QQuickShape::changeSignals() QCOMPARE(vpChangeSpy.count(), 14); QQmlListReference stopList(lgrad, "stops"); QCOMPARE(stopList.count(), 5); - qobject_cast<QQuickShapeGradientStop *>(stopList.at(1))->setPosition(0.3); + qobject_cast<QQuickGradientStop *>(stopList.at(1))->setPosition(0.3); QCOMPARE(vpChangeSpy.count(), 15); - qobject_cast<QQuickShapeGradientStop *>(stopList.at(1))->setColor(Qt::black); + qobject_cast<QQuickGradientStop *>(stopList.at(1))->setColor(Qt::black); QCOMPARE(vpChangeSpy.count(), 16); } diff --git a/tests/manual/shapestest/shapestest.qml b/tests/manual/shapestest/shapestest.qml index bf503c12d9..df53f088ae 100644 --- a/tests/manual/shapestest/shapestest.qml +++ b/tests/manual/shapestest/shapestest.qml @@ -83,14 +83,14 @@ Rectangle { ShapePath { strokeWidth: 4 strokeColor: "red" - fillGradient: ShapeLinearGradient { + fillGradient: LinearGradient { x1: 0; y1: 0 x2: 200; y2: 100 - 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" } } fillColor: "blue" // ignored with the gradient set strokeStyle: ShapePath.DashLine |