From 81d204e2a5118b2d81862fa9d9a45e5522396a45 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 4 Jan 2017 14:31:23 +0100 Subject: Add X axis rotation property to PathArc It is a standard feature of elliptical arc. While perhaps deemed too advanced for PathView purposes, rendering the path using PathItem must offer the ability to specify a non-zero X axis rotation for the ellipses of which the arc is a section of. Change-Id: I53f01713b7e0e97c40f22d75d46f75a140830683 Reviewed-by: Andy Nichols --- src/quick/doc/images/declarative-arcrotation.png | Bin 0 -> 4315 bytes src/quick/doc/snippets/qml/path/arcrotation.qml | 52 +++++++++++++++++++++++ src/quick/items/qquickitemsmodule.cpp | 1 + src/quick/util/qquickpath.cpp | 38 ++++++++++++++++- src/quick/util/qquickpath_p.h | 8 +++- 5 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 src/quick/doc/images/declarative-arcrotation.png create mode 100644 src/quick/doc/snippets/qml/path/arcrotation.qml (limited to 'src/quick') diff --git a/src/quick/doc/images/declarative-arcrotation.png b/src/quick/doc/images/declarative-arcrotation.png new file mode 100644 index 0000000000..03f009bc12 Binary files /dev/null and b/src/quick/doc/images/declarative-arcrotation.png differ diff --git a/src/quick/doc/snippets/qml/path/arcrotation.qml b/src/quick/doc/snippets/qml/path/arcrotation.qml new file mode 100644 index 0000000000..c73d67ff17 --- /dev/null +++ b/src/quick/doc/snippets/qml/path/arcrotation.qml @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +//![0] +Path { + startX: 50; startY: 100 + + PathArc { + x: 150; y: 100 + radiusX: 50; radiusY: 20 + xAxisRotation: 45 + } +} +//![0] diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index b0d7f7f8a3..9c70daab1f 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -373,6 +373,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType(uri, 2, 9, "MouseArea"); #if QT_CONFIG(quick_path) + qmlRegisterType(uri, 2, 9, "PathArc"); qmlRegisterType(uri, 2, 9, "PathMove"); qmlRegisterType(uri, 2, 9, "PathItem"); qmlRegisterType(uri, 2, 9, "PathGradientStop"); diff --git a/src/quick/util/qquickpath.cpp b/src/quick/util/qquickpath.cpp index a6fa21d696..228056fdb5 100644 --- a/src/quick/util/qquickpath.cpp +++ b/src/quick/util/qquickpath.cpp @@ -1799,6 +1799,42 @@ void QQuickPathArc::setDirection(ArcDirection direction) emit changed(); } +/*! + \qmlproperty real QtQuick::PathArc::xAxisRotation + + Defines the rotation of the arc, in degrees. The default value is 0. + + An arc is a section of circles or ellipses. Given the radius and the start + and end points, there are two ellipses that connect the points. This + property defines the rotation of the X axis of these ellipses. + + \note The value is only useful when the x and y radius differ, meaning the + arc is a section of ellipses. + + The following QML demonstrates how different radius values can be used to change + the shape of the arc: + \table + \row + \li \image declarative-arcrotation.png + \li \snippet qml/path/arcrotation.qml 0 + \endtable +*/ + +qreal QQuickPathArc::xAxisRotation() const +{ + return _xAxisRotation; +} + +void QQuickPathArc::setXAxisRotation(qreal rotation) +{ + if (_xAxisRotation == rotation) + return; + + _xAxisRotation = rotation; + emit xAxisRotationChanged(); + emit changed(); +} + void QQuickPathArc::addToPath(QPainterPath &path, const QQuickPathData &data) { const QPointF &startPoint = path.currentPosition(); @@ -1806,7 +1842,7 @@ void QQuickPathArc::addToPath(QPainterPath &path, const QQuickPathData &data) QQuickSvgParser::pathArc(path, _radiusX, _radiusY, - 0, //xAxisRotation + _xAxisRotation, _useLargeArc, _direction == Clockwise ? 1 : 0, endPoint.x(), diff --git a/src/quick/util/qquickpath_p.h b/src/quick/util/qquickpath_p.h index 283283f377..4bcefb032e 100644 --- a/src/quick/util/qquickpath_p.h +++ b/src/quick/util/qquickpath_p.h @@ -290,10 +290,11 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPathArc : public QQuickCurve Q_PROPERTY(qreal radiusY READ radiusY WRITE setRadiusY NOTIFY radiusYChanged) Q_PROPERTY(bool useLargeArc READ useLargeArc WRITE setUseLargeArc NOTIFY useLargeArcChanged) Q_PROPERTY(ArcDirection direction READ direction WRITE setDirection NOTIFY directionChanged) + Q_PROPERTY(qreal xAxisRotation READ xAxisRotation WRITE setXAxisRotation NOTIFY xAxisRotationChanged REVISION 2) public: QQuickPathArc(QObject *parent=0) - : QQuickCurve(parent), _radiusX(0), _radiusY(0), _useLargeArc(false), _direction(Clockwise) {} + : QQuickCurve(parent), _radiusX(0), _radiusY(0), _useLargeArc(false), _direction(Clockwise), _xAxisRotation(0) {} enum ArcDirection { Clockwise, Counterclockwise }; Q_ENUM(ArcDirection) @@ -310,6 +311,9 @@ public: ArcDirection direction() const; void setDirection(ArcDirection direction); + qreal xAxisRotation() const; + void setXAxisRotation(qreal rotation); + void addToPath(QPainterPath &path, const QQuickPathData &) override; Q_SIGNALS: @@ -317,12 +321,14 @@ Q_SIGNALS: void radiusYChanged(); void useLargeArcChanged(); void directionChanged(); + Q_REVISION(2) void xAxisRotationChanged(); private: qreal _radiusX; qreal _radiusY; bool _useLargeArc; ArcDirection _direction; + qreal _xAxisRotation; }; class Q_QUICK_PRIVATE_EXPORT QQuickPathSvg : public QQuickCurve -- cgit v1.2.3