diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2012-01-06 09:37:03 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-06 01:08:22 +0100 |
commit | c13098fa6e0dcaca1022f1c50ced6cba4d5f7168 (patch) | |
tree | e08b3029c89396c6786fdde525601ecb9768b837 /src/quick/util | |
parent | 29d2d20be058f5b10dee4dd2d04b864aa155d48e (diff) |
Smooth join point for closed Paths starting and ending with PathCurve.
Change-Id: I6d416e7d794271c10c9eb19de9678b0fe45b083d
Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'src/quick/util')
-rw-r--r-- | src/quick/util/qdeclarativepath.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/quick/util/qdeclarativepath.cpp b/src/quick/util/qdeclarativepath.cpp index 4f048ba95a..f1a2a1d5f5 100644 --- a/src/quick/util/qdeclarativepath.cpp +++ b/src/quick/util/qdeclarativepath.cpp @@ -1377,8 +1377,32 @@ void QDeclarativePathCatmullRomCurve::addToPath(QPainterPath &path, const QDecla if (qobject_cast<QDeclarativePathCatmullRomCurve*>(curve)) { prev = path.currentPosition(); prevFar = previousPathPosition(path); - } else - prevFar = prev = path.currentPosition(); + } else { + prev = path.currentPosition(); + bool prevFarSet = false; + if (index == -1 && data.curves.count() > 1) { + if (qobject_cast<QDeclarativePathCatmullRomCurve*>(data.curves.at(data.curves.count()-1))) { + //TODO: profile and optimize + QPointF pos = prev; + QDeclarativePathData loopData; + loopData.endPoint = data.endPoint; + loopData.curves = data.curves; + for (int i = data.index; i < data.curves.count(); ++i) { + loopData.index = i; + pos = positionForCurve(loopData, pos); + if (i == data.curves.count()-2) + prevFar = pos; + } + if (pos == QPointF(path.elementAt(0))) { + //this is a closed path starting and ending with catmull-rom segments. + //we try to smooth the join point + prevFarSet = true; + } + } + } + if (!prevFarSet) + prevFar = prev; + } //get current point point = positionForCurve(data, path.currentPosition()); @@ -1391,8 +1415,14 @@ void QDeclarativePathCatmullRomCurve::addToPath(QPainterPath &path, const QDecla nextData.endPoint = data.endPoint; nextData.curves = data.curves; next = positionForCurve(nextData, point); - } else - next = point; + } else { + if (point == QPointF(path.elementAt(0)) && qobject_cast<QDeclarativePathCatmullRomCurve*>(data.curves.at(0))) { + //this is a closed path starting and ending with catmull-rom segments. + //we try to smooth the join point + next = QPointF(path.elementAt(3)); //the first catmull-rom point + } else + next = point; + } /* full conversion matrix (inverse bezier * catmull-rom): |