42 #include "private/qdeclarativepath_p.h" 43 #include "private/qdeclarativepath_p_p.h" 48 #include <private/qbezier_p.h> 49 #include <QtCore/qmath.h> 50 #include <QtCore/qnumeric.h> 185 qreal lastPercent = 0;
186 int search = idx - 1;
201 for (
int ii = search; ii < idx; ++ii) {
214 for (
int ii =
d->_attributePoints.count() - 1; ii >= 0; ii--) {
217 for (
int jj = ii + 1; jj <
d->_attributePoints.count(); ++jj) {
233 d->_pointCache.clear();
234 d->_attributePoints.clear();
238 for (
int ii = 0; ii <
d->_attributes.count(); ++ii)
239 first.
values[
d->_attributes.at(ii)] = 0;
240 d->_attributePoints << first;
242 d->_path.moveTo(
d->startX,
d->startY);
250 d->_attributePoints << p;
254 point.
values[attribute->name()] = attribute->
value();
255 interpolate(
d->_attributePoints.count() - 1, attribute->name(), attribute->value());
265 for (
int ii = 0; ii <
d->_attributes.count(); ++ii) {
266 if (!last.values.contains(
d->_attributes.at(ii)))
271 qreal length =
d->_path.length();
272 qreal prevpercent = 0;
273 qreal prevorigpercent = 0;
274 for (
int ii = 0; ii <
d->_attributePoints.count(); ++ii) {
278 qreal scale = (
d->_attributePoints[ii].origpercent/length - prevorigpercent) /
280 d->_attributePoints[ii].scale = scale;
282 d->_attributePoints[ii].origpercent /= length;
284 prevorigpercent =
d->_attributePoints[ii].origpercent;
285 prevpercent =
d->_attributePoints[ii].percent;
287 d->_attributePoints[ii].origpercent /= length;
288 d->_attributePoints[ii].percent =
d->_attributePoints[ii].origpercent;
292 d->closed = lastCurve &&
d->startX == lastCurve->
x() &&
d->startY == lastCurve->
y();
312 qobject_cast<QDeclarativePathAttribute *>(pathElement))
313 attrs.
insert(attribute->name());
315 d->_attributes = attrs.
toList();
338 qobject_cast<QDeclarativePathAttribute *>(pathElement))
339 attrs.
insert(attribute->name());
343 return d->_attributes;
349 for (
int i=*from; i <= lastElement; ++i) {
358 *bezLength = line.
length();
386 qreal pathLength =
d->_path.length();
387 if (pathLength <= 0 ||
qIsNaN(pathLength))
391 const int points =
qCeil(pathLength*5);
392 const int lastElement =
d->_path.elementCount() - 1;
393 d->_pointCache.resize(points+1);
398 qreal currLength = bezLength;
399 qreal epc = currLength / pathLength;
401 for (
int i = 0; i <
d->_pointCache.size(); i++) {
403 qreal prevPercent = 0;
404 qreal prevOrigPercent = 0;
405 for (
int ii = 0; ii <
d->_attributePoints.count(); ++ii) {
408 if (percent < point.percent || ii == d->_attributePoints.count() - 1) {
409 qreal elementPercent = (percent - prevPercent);
411 qreal spc = prevOrigPercent + elementPercent * point.
scale;
414 if (currElement > lastElement)
416 currBez =
nextBezier(
d->_path, &currElement, &bezLength);
417 if (bezLength == 0.0) {
418 currLength = pathLength;
422 currLength += bezLength;
423 epc = currLength / pathLength;
425 qreal realT = (pathLength * spc - (currLength - bezLength)) / bezLength;
438 if (
d->_pointCache.isEmpty()) {
440 if (
d->_pointCache.isEmpty())
443 int idx =
qRound(p*
d->_pointCache.size());
444 if (idx >=
d->_pointCache.size())
445 idx =
d->_pointCache.size() - 1;
448 return d->_pointCache.at(idx);
454 if (percent < 0 || percent > 1)
457 for (
int ii = 0; ii <
d->_attributePoints.count(); ++ii) {
460 if (point.
percent == percent) {
462 }
else if (point.
percent > percent) {
464 ii?(
d->_attributePoints.at(ii - 1).values.value(name)):0;
466 ii?(
d->_attributePoints.at(ii - 1).percent):0;
470 return lastValue + (curValue - lastValue) * (percent - lastPercent) / (curPercent - lastPercent);
621 if (_value != value) {
723 if (_controlX != x) {
725 emit controlXChanged();
741 if (_controlY != y) {
743 emit controlYChanged();
750 path.
quadTo(controlX(), controlY(), x(), y());
809 if (_control1X != x) {
811 emit control1XChanged();
823 if (_control1Y != y) {
825 emit control1YChanged();
846 if (_control2X != x) {
848 emit control2XChanged();
860 if (_control2Y != y) {
862 emit control2YChanged();
869 path.
cubicTo(control1X(), control1Y(), control2X(), control2Y(), x(), y());
965 if (_value != value) {
ElementType type
the type of element
The QPainterPath::Element class specifies the position and type of a subpath.
static QBezier nextBezier(const QPainterPath &path, int *from, qreal *bezLength)
#define QT_END_NAMESPACE
This macro expands to.
QDeclarativeParserStatus ** d
qreal length() const
Returns the length of the line.
virtual void componentComplete()
Invoked after the root component that caused this instantiation has completed construction.
QDeclarativePath(QObject *parent=0)
void interpolate(int idx, const QString &name, qreal value)
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
void setControl2Y(qreal y)
The QPointF class defines a point in the plane using floating point precision.
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
long ASN1_INTEGER_get ASN1_INTEGER * a
QPointF pointAt(qreal t) const
virtual void addToPath(QPainterPath &)
The QString class provides a Unicode character string.
QPointF pointAt(qreal) const
The QObject class is the base class of all Qt objects.
qreal length(qreal error=0.01) const
void addToPath(QPainterPath &path)
void setControlX(qreal x)
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
const T value(const Key &key) const
Returns the value associated with the key.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
The QLineF class provides a two-dimensional vector using floating point precision.
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
#define QT_BEGIN_NAMESPACE
This macro expands to.
void setControl2X(qreal x)
void createPointCache() const
QList< T > toList() const
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
The QStringList class provides a list of strings.
const_iterator insert(const T &value)
void setValue(qreal value)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
void addToPath(QPainterPath &path)
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
QDeclarativeListProperty< QDeclarativePathElement > pathElements()
void endpoint(const QString &name)
QHash< QString, qreal > values
virtual void classBegin()
Invoked after class creation, but before any properties have been set.
QPainterPath path() const
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
void setControlY(qreal y)
void setValue(qreal value)
void quadTo(const QPointF &ctrlPt, const QPointF &endPt)
Adds a quadratic Bezier curve between the current position and the given endPoint with the control po...
void setControl1X(qreal x)
void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
Adds a cubic Bezier curve between the current position and the given endPoint using the control point...
void setName(const QString &name)
int elementCount() const
Returns the number of path elements in the painter path.
void addToPath(QPainterPath &path)
qreal attributeAt(const QString &, qreal) const
Q_DECL_CONSTEXPR int qRound(qreal d)
void setControl1Y(qreal y)
QStringList attributes() const