445 |
452 |
446 \since 4.5 |
453 \since 4.5 |
447 */ |
454 */ |
448 QTransform QTransform::fromTranslate(qreal dx, qreal dy) |
455 QTransform QTransform::fromTranslate(qreal dx, qreal dy) |
449 { |
456 { |
|
457 #ifndef QT_NO_DEBUG |
|
458 if (qIsNaN(dx) | qIsNaN(dy)) { |
|
459 qWarning() << "QTransform::fromTranslate with NaN called"; |
|
460 return QTransform(); |
|
461 } |
|
462 #endif |
450 QTransform transform(1, 0, 0, 0, 1, 0, dx, dy, 1, true); |
463 QTransform transform(1, 0, 0, 0, 1, 0, dx, dy, 1, true); |
451 if (dx == 0 && dy == 0) |
464 if (dx == 0 && dy == 0) |
452 transform.m_type = TxNone; |
465 transform.m_type = TxNone; |
453 else |
466 else |
454 transform.m_type = TxTranslate; |
467 transform.m_type = TxTranslate; |
499 |
518 |
500 \since 4.5 |
519 \since 4.5 |
501 */ |
520 */ |
502 QTransform QTransform::fromScale(qreal sx, qreal sy) |
521 QTransform QTransform::fromScale(qreal sx, qreal sy) |
503 { |
522 { |
|
523 #ifndef QT_NO_DEBUG |
|
524 if (qIsNaN(sx) | qIsNaN(sy)) { |
|
525 qWarning() << "QTransform::fromScale with NaN called"; |
|
526 return QTransform(); |
|
527 } |
|
528 #endif |
504 QTransform transform(sx, 0, 0, 0, sy, 0, 0, 0, 1, true); |
529 QTransform transform(sx, 0, 0, 0, sy, 0, 0, 0, 1, true); |
505 if (sx == 1. && sy == 1.) |
530 if (sx == 1. && sy == 1.) |
506 transform.m_type = TxNone; |
531 transform.m_type = TxNone; |
507 else |
532 else |
508 transform.m_type = TxScale; |
533 transform.m_type = TxScale; |
658 |
695 |
659 \sa setMatrix() |
696 \sa setMatrix() |
660 */ |
697 */ |
661 QTransform & QTransform::rotateRadians(qreal a, Qt::Axis axis) |
698 QTransform & QTransform::rotateRadians(qreal a, Qt::Axis axis) |
662 { |
699 { |
|
700 #ifndef QT_NO_DEBUG |
|
701 if (qIsNaN(a)) { |
|
702 qWarning() << "QTransform::rotateRadians with NaN called"; |
|
703 return *this; |
|
704 } |
|
705 #endif |
663 qreal sina = qSin(a); |
706 qreal sina = qSin(a); |
664 qreal cosa = qCos(a); |
707 qreal cosa = qCos(a); |
665 |
708 |
666 if (axis == Qt::ZAxis) { |
709 if (axis == Qt::ZAxis) { |
667 switch(inline_type()) { |
710 switch(inline_type()) { |
1035 #endif // QT_NO_DATASTREAM |
1078 #endif // QT_NO_DATASTREAM |
1036 |
1079 |
1037 #ifndef QT_NO_DEBUG_STREAM |
1080 #ifndef QT_NO_DEBUG_STREAM |
1038 QDebug operator<<(QDebug dbg, const QTransform &m) |
1081 QDebug operator<<(QDebug dbg, const QTransform &m) |
1039 { |
1082 { |
1040 dbg.nospace() << "QTransform(" |
1083 static const char *typeStr[] = |
1041 << "11=" << m.m11() |
1084 { |
|
1085 "TxNone", |
|
1086 "TxTranslate", |
|
1087 "TxScale", |
|
1088 "TxRotate", |
|
1089 "TxShear", |
|
1090 "TxProject" |
|
1091 }; |
|
1092 |
|
1093 dbg.nospace() << "QTransform(type=" << typeStr[m.type()] << ',' |
|
1094 << " 11=" << m.m11() |
1042 << " 12=" << m.m12() |
1095 << " 12=" << m.m12() |
1043 << " 13=" << m.m13() |
1096 << " 13=" << m.m13() |
1044 << " 21=" << m.m21() |
1097 << " 21=" << m.m21() |
1045 << " 22=" << m.m22() |
1098 << " 22=" << m.m22() |
1046 << " 23=" << m.m23() |
1099 << " 23=" << m.m23() |
1047 << " 31=" << m.m31() |
1100 << " 31=" << m.m31() |
1048 << " 32=" << m.m32() |
1101 << " 32=" << m.m32() |
1049 << " 33=" << m.m33() |
1102 << " 33=" << m.m33() |
1050 << ')'; |
1103 << ')'; |
|
1104 |
1051 return dbg.space(); |
1105 return dbg.space(); |
1052 } |
1106 } |
1053 #endif |
1107 #endif |
1054 |
1108 |
1055 /*! |
1109 /*! |
1489 if (needsLineTo) |
1543 if (needsLineTo) |
1490 path.lineTo(hb.toPoint()); |
1544 path.lineTo(hb.toPoint()); |
1491 |
1545 |
1492 return true; |
1546 return true; |
1493 } |
1547 } |
|
1548 Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale); |
1494 |
1549 |
1495 static inline bool cubicTo_clipped(QPainterPath &path, const QTransform &transform, const QPointF &a, const QPointF &b, const QPointF &c, const QPointF &d, bool needsMoveTo) |
1550 static inline bool cubicTo_clipped(QPainterPath &path, const QTransform &transform, const QPointF &a, const QPointF &b, const QPointF &c, const QPointF &d, bool needsMoveTo) |
1496 { |
1551 { |
1497 // Convert projective xformed curves to line |
1552 // Convert projective xformed curves to line |
1498 // segments so they can be transformed more accurately |
1553 // segments so they can be transformed more accurately |
1499 QPolygonF segment = QBezier::fromPoints(a, b, c, d).toPolygon(); |
1554 |
|
1555 qreal scale; |
|
1556 qt_scaleForTransform(transform, &scale); |
|
1557 |
|
1558 qreal curveThreshold = scale == 0 ? qreal(0.25) : (qreal(0.25) / scale); |
|
1559 |
|
1560 QPolygonF segment = QBezier::fromPoints(a, b, c, d).toPolygon(curveThreshold); |
1500 |
1561 |
1501 for (int i = 0; i < segment.size() - 1; ++i) |
1562 for (int i = 0; i < segment.size() - 1; ++i) |
1502 if (lineTo_clipped(path, transform, segment.at(i), segment.at(i+1), needsMoveTo)) |
1563 if (lineTo_clipped(path, transform, segment.at(i), segment.at(i+1), needsMoveTo)) |
1503 needsMoveTo = false; |
1564 needsMoveTo = false; |
1504 |
1565 |