| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | #include "qquicklineextruder_p.h" |
| 4 | #include <QRandomGenerator> |
| 5 | #include <cmath> |
| 6 | |
| 7 | /*! |
| 8 | \qmltype LineShape |
| 9 | \nativetype QQuickLineExtruder |
| 10 | \inqmlmodule QtQuick.Particles |
| 11 | \inherits ParticleExtruder |
| 12 | \brief Represents a line for affectors and emitters. |
| 13 | \ingroup qtquick-particles |
| 14 | |
| 15 | */ |
| 16 | |
| 17 | /*! |
| 18 | \qmlproperty bool QtQuick.Particles::LineShape::mirrored |
| 19 | |
| 20 | By default, the line goes from (0,0) to (width, height) of the item that |
| 21 | this shape is being applied to. |
| 22 | |
| 23 | If mirrored is set to true, this will be mirrored along the y axis. |
| 24 | The line will then go from (0,height) to (width, 0). |
| 25 | */ |
| 26 | |
| 27 | QQuickLineExtruder::QQuickLineExtruder(QObject *parent) : |
| 28 | QQuickParticleExtruder(parent), m_mirrored(false) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | QPointF QQuickLineExtruder::extrude(const QRectF &r) |
| 33 | { |
| 34 | qreal x,y; |
| 35 | if (!r.height()){ |
| 36 | x = r.width() * QRandomGenerator::global()->generateDouble(); |
| 37 | y = 0; |
| 38 | }else{ |
| 39 | y = r.height() * QRandomGenerator::global()->generateDouble(); |
| 40 | if (!r.width()){ |
| 41 | x = 0; |
| 42 | }else{ |
| 43 | x = r.width()/r.height() * y; |
| 44 | if (m_mirrored) |
| 45 | x = r.width() - x; |
| 46 | } |
| 47 | } |
| 48 | return QPointF(x,y); |
| 49 | } |
| 50 | |
| 51 | #include "moc_qquicklineextruder_p.cpp" |
| 52 |
