aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/util/qquickpath.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2019-03-24 18:53:52 +0100
committerpaolo <paolo.angelelli@qt.io>2019-05-28 10:02:45 +0200
commit1404009264e3526838c608269a45d9acf61f5e46 (patch)
treea4ec08a2bd9a57bb0fb16a4363a03840afadc771 /src/quick/util/qquickpath.cpp
parent5b96f81fa3c31ea911a08bb28275272b0770a745 (diff)
Add QQuickPathPolyline
And show our users some love. [ChangeLog][QtQuick][Path] Added QQuickPathPolyline. Change-Id: I0fb78ae3e4e7c65e81e100595dc1eb16f88a68ed Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/util/qquickpath.cpp')
-rw-r--r--src/quick/util/qquickpath.cpp108
1 files changed, 104 insertions, 4 deletions
diff --git a/src/quick/util/qquickpath.cpp b/src/quick/util/qquickpath.cpp
index a0f3749552..f0705d19bd 100644
--- a/src/quick/util/qquickpath.cpp
+++ b/src/quick/util/qquickpath.cpp
@@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE
This type is the base for all path types. It cannot
be instantiated.
- \sa Path, PathAttribute, PathPercent, PathLine, PathQuad, PathCubic, PathArc,
+ \sa Path, PathAttribute, PathPercent, PathLine, PathPolyline, PathQuad, PathCubic, PathArc,
PathAngleArc, PathCurve, PathSvg
*/
@@ -71,7 +71,7 @@ QT_BEGIN_NAMESPACE
\ingroup qtquick-animation-paths
\brief Defines a path for use by \l PathView and \l Shape.
- A Path is composed of one or more path segments - PathLine, PathQuad,
+ A Path is composed of one or more path segments - PathLine, PathPolyline, PathQuad,
PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg.
The spacing of the items along the Path can be adjusted via a
@@ -104,6 +104,12 @@ QT_BEGIN_NAMESPACE
\li Yes
\li Yes
\row
+ \li PathPolyline
+ \li Yes
+ \li Yes
+ \li Yes
+ \li Yes
+ \row
\li PathQuad
\li Yes
\li Yes
@@ -156,7 +162,7 @@ QT_BEGIN_NAMESPACE
\note Path is a non-visual type; it does not display anything on its own.
To draw a path, use \l Shape.
- \sa PathView, Shape, PathAttribute, PathPercent, PathLine, PathMove, PathQuad, PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg
+ \sa PathView, Shape, PathAttribute, PathPercent, PathLine, PathPolyline, PathMove, PathQuad, PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg
*/
QQuickPath::QQuickPath(QObject *parent)
: QObject(*(new QQuickPathPrivate), parent)
@@ -240,6 +246,7 @@ bool QQuickPath::isClosed() const
A path can contain the following path objects:
\list
\li \l PathLine - a straight line to a given position.
+ \li \l PathPolyline - a polyline specified as a list of normalized coordinates.
\li \l PathQuad - a quadratic Bezier curve to a given position with a control point.
\li \l PathCubic - a cubic Bezier curve to a given position with two control points.
\li \l PathArc - an arc to a given position with a radius.
@@ -1168,7 +1175,7 @@ void QQuickPathAttribute::setValue(qreal value)
}
\endqml
- \sa Path, PathQuad, PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg, PathMove
+ \sa Path, PathQuad, PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg, PathMove, PathPolyline
*/
/*!
@@ -2327,6 +2334,99 @@ void QQuickPathPercent::setValue(qreal value)
emit changed();
}
}
+
+/*!
+ \qmltype PathPolyline
+ \instantiates QQuickPathPolyline
+ \inqmlmodule QtQuick
+ \ingroup qtquick-animation-paths
+ \brief Defines a polyline through a list of coordinates.
+ \since QtQuick 2.14
+
+ The example below creates a triangular path consisting of four vertices
+ on the edge of the containing Shape's bounding box.
+ Through the containing shape's \l scale property, the path will be
+ rescaled together with its containing shape.
+
+ \qml
+ PathPolyline {
+ id: ppl
+ path: [ Qt.point(0.0, 0.0),
+ Qt.point(1.0, 0.0),
+ Qt.point(0.5, 1.0),
+ Qt.point(0.0, 0.0)
+ ]
+ }
+ \endqml
+
+ \sa Path, PathQuad, PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg, PathMove, PathPolyline
+*/
+
+/*!
+ \qmlproperty point QtQuick::PathPolyline::start
+
+ This read-only property contains the beginning of the polyline.
+*/
+
+/*!
+ \qmlproperty list<point> QtQuick::PathPolyline::path
+
+ This property defines the vertices of the polyline.
+*/
+
+QQuickPathPolyline::QQuickPathPolyline(QObject *parent) : QQuickCurve(parent)
+{
+}
+
+QVariantList QQuickPathPolyline::path() const
+{
+ QVariantList res;
+ for (int i = 0; i < m_path.length(); ++i) {
+ const QPointF &c = m_path.at(i);
+ res.append(QVariant::fromValue(c));
+ }
+
+ return res;
+}
+
+void QQuickPathPolyline::setPath(const QVariantList &path)
+{
+ QVector<QPointF> pathList;
+ for (int i = 0; i < path.length(); ++i) {
+ const QPointF c = path.at(i).toPointF();
+ pathList.append(c);
+ }
+
+ if (m_path != pathList) {
+ const QPointF &oldStart = start();
+ m_path = pathList;
+ const QPointF &newStart = start();
+ emit pathChanged();
+ if (oldStart != newStart)
+ emit startChanged();
+ emit changed();
+ }
+}
+
+QPointF QQuickPathPolyline::start() const
+{
+ if (m_path.size()) {
+ const QPointF &p = m_path.first();
+ return p;
+ }
+ return QPointF();
+}
+
+void QQuickPathPolyline::addToPath(QPainterPath &path, const QQuickPathData &/*data*/)
+{
+ if (m_path.size() < 2)
+ return;
+
+ path.moveTo(m_path.first());
+ for (int i = 1; i < m_path.size(); ++i)
+ path.lineTo(m_path.at(i));
+}
+
QT_END_NAMESPACE
#include "moc_qquickpath_p.cpp"