summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qtransform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/painting/qtransform.cpp')
-rw-r--r--src/gui/painting/qtransform.cpp64
1 files changed, 48 insertions, 16 deletions
diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp
index da8c428..39b3319 100644
--- a/src/gui/painting/qtransform.cpp
+++ b/src/gui/painting/qtransform.cpp
@@ -396,6 +396,9 @@ QTransform QTransform::inverted(bool *invertible) const
*/
QTransform & QTransform::translate(qreal dx, qreal dy)
{
+ if (dx == 0 && dy == 0)
+ return *this;
+
switch(type()) {
case TxNone:
affine._dx = dx;
@@ -432,7 +435,10 @@ QTransform & QTransform::translate(qreal dx, qreal dy)
QTransform QTransform::fromTranslate(qreal dx, qreal dy)
{
QTransform transform(1, 0, 0, 1, dx, dy);
- transform.m_dirty = TxTranslate;
+ if (dx == 0 && dy == 0)
+ transform.m_dirty = TxNone;
+ else
+ transform.m_dirty = TxTranslate;
return transform;
}
@@ -444,6 +450,9 @@ QTransform QTransform::fromTranslate(qreal dx, qreal dy)
*/
QTransform & QTransform::scale(qreal sx, qreal sy)
{
+ if (sx == 1 && sy == 1)
+ return *this;
+
switch(type()) {
case TxNone:
case TxTranslate:
@@ -478,7 +487,10 @@ QTransform & QTransform::scale(qreal sx, qreal sy)
QTransform QTransform::fromScale(qreal sx, qreal sy)
{
QTransform transform(sx, 0, 0, sy, 0, 0);
- transform.m_dirty = TxScale;
+ if (sx == 1 && sy == 1)
+ transform.m_dirty = TxNone;
+ else
+ transform.m_dirty = TxScale;
return transform;
}
@@ -541,6 +553,9 @@ const qreal inv_dist_to_plane = 1. / 1024.;
*/
QTransform & QTransform::rotate(qreal a, Qt::Axis axis)
{
+ if (a == 0)
+ return *this;
+
qreal sina = 0;
qreal cosa = 0;
if (a == 90. || a == -270.)
@@ -712,7 +727,15 @@ bool QTransform::operator!=(const QTransform &o) const
*/
QTransform & QTransform::operator*=(const QTransform &o)
{
- TransformationType t = qMax(type(), o.type());
+ const TransformationType otherType = o.type();
+ if (otherType == TxNone)
+ return *this;
+
+ const TransformationType thisType = type();
+ if (thisType == TxNone)
+ return operator=(o);
+
+ TransformationType t = qMax(thisType, otherType);
switch(t) {
case TxNone:
break;
@@ -1219,7 +1242,11 @@ static QPolygonF mapProjective(const QTransform &transform, const QPolygonF &pol
*/
QPolygonF QTransform::map(const QPolygonF &a) const
{
- if (type() >= QTransform::TxProject)
+ TransformationType t = type();
+ if (t <= TxTranslate)
+ return a.translated(affine._dx, affine._dy);
+
+ if (t >= QTransform::TxProject)
return mapProjective(*this, a);
int size = a.size();
@@ -1228,7 +1255,6 @@ QPolygonF QTransform::map(const QPolygonF &a) const
const QPointF *da = a.constData();
QPointF *dp = p.data();
- TransformationType t = type();
for(i = 0; i < size; ++i) {
MAP(da[i].xp, da[i].yp, dp[i].xp, dp[i].yp);
}
@@ -1246,7 +1272,11 @@ QPolygonF QTransform::map(const QPolygonF &a) const
*/
QPolygon QTransform::map(const QPolygon &a) const
{
- if (type() >= QTransform::TxProject)
+ TransformationType t = type();
+ if (t <= TxTranslate)
+ return a.translated(qRound(affine._dx), qRound(affine._dy));
+
+ if (t >= QTransform::TxProject)
return mapProjective(*this, QPolygonF(a)).toPolygon();
int size = a.size();
@@ -1255,7 +1285,6 @@ QPolygon QTransform::map(const QPolygon &a) const
const QPoint *da = a.constData();
QPoint *dp = p.data();
- TransformationType t = type();
for(i = 0; i < size; ++i) {
qreal nx = 0, ny = 0;
MAP(da[i].xp, da[i].yp, nx, ny);
@@ -1457,15 +1486,11 @@ QPainterPath QTransform::map(const QPainterPath &path) const
return mapProjective(*this, path);
QPainterPath copy = path;
- copy.detach();
if (t == TxTranslate) {
- for (int i=0; i<path.elementCount(); ++i) {
- QPainterPath::Element &e = copy.d_ptr->elements[i];
- e.x += affine._dx;
- e.y += affine._dy;
- }
+ copy.translate(affine._dx, affine._dy);
} else {
+ copy.detach();
// Full xform
for (int i=0; i<path.elementCount(); ++i) {
QPainterPath::Element &e = copy.d_ptr->elements[i];
@@ -1673,6 +1698,9 @@ void QTransform::setMatrix(qreal m11, qreal m12, qreal m13,
QRect QTransform::mapRect(const QRect &rect) const
{
TransformationType t = type();
+ if (t <= TxTranslate)
+ return rect.translated(qRound(affine._dx), qRound(affine._dy));
+
if (t <= TxScale) {
int x = qRound(affine._m11*rect.x() + affine._dx);
int y = qRound(affine._m22*rect.y() + affine._dy);
@@ -1741,6 +1769,9 @@ QRect QTransform::mapRect(const QRect &rect) const
QRectF QTransform::mapRect(const QRectF &rect) const
{
TransformationType t = type();
+ if (t <= TxTranslate)
+ return rect.translated(affine._dx, affine._dy);
+
if (t <= TxScale) {
qreal x = affine._m11*rect.x() + affine._dx;
qreal y = affine._m22*rect.y() + affine._dy;
@@ -2058,10 +2089,11 @@ QTransform::operator QVariant() const
Q_GUI_EXPORT
bool qt_scaleForTransform(const QTransform &transform, qreal *scale)
{
- if (transform.type() <= QTransform::TxTranslate) {
+ const QTransform::TransformationType type = transform.type();
+ if (type <= QTransform::TxTranslate) {
*scale = 1;
return true;
- } else if (transform.type() == QTransform::TxScale) {
+ } else if (type == QTransform::TxScale) {
const qreal xScale = qAbs(transform.m11());
const qreal yScale = qAbs(transform.m22());
*scale = qMax(xScale, yScale);
@@ -2073,7 +2105,7 @@ bool qt_scaleForTransform(const QTransform &transform, qreal *scale)
const qreal yScale = transform.m12() * transform.m12()
+ transform.m22() * transform.m22();
*scale = qSqrt(qMax(xScale, yScale));
- return transform.type() == QTransform::TxRotate && qFuzzyCompare(xScale, yScale);
+ return type == QTransform::TxRotate && qFuzzyCompare(xScale, yScale);
}
QT_END_NAMESPACE