/*! \fn QRegion QMatrix::map(const QRegion ®ion) const \overload Creates and returns a QRegion object that is a copy of the given \a region, mapped into the coordinate system defined by this matrix. Calling this method can be rather expensive if rotations or shearing are used. */ QRegion QMatrix::map(const QRegion &r) const { if (_m11 == 1.0 && _m22 == 1.0 && _m12 == 0.0 && _m21 == 0.0) { // translate or identity if (_dx == 0.0 && _dy == 0.0) // Identity return r; QRegion copy(r); copy.translate(qRound(_dx), qRound(_dy)); return copy; } QPainterPath p = map(qt_regionToPath(r)); return p.toFillPolygon().toPolygon(); }
QT_END_NAMESPACE #endif void tst_QRegion::regionToPath() { #ifdef QT_BUILD_INTERNAL QFETCH(QPainterPath, path); for (int i = 0; i < 360; i += 10) { QTransform transform; transform.scale(5, 5); transform.rotate(i); QPainterPath mapped = transform.map(path); QRegion region(mapped.toFillPolygon().toPolygon()); QPainterPath a; a.addRegion(region); QPainterPath b = qt_regionToPath(region); QRect r = a.boundingRect().toAlignedRect(); QImage ia(r.size(), QImage::Format_RGB32); ia.fill(0xffffffff); QImage ib = ia; QPainter p(&ia); p.translate(-r.x(), -r.y()); p.fillPath(a, Qt::red); p.end(); p.begin(&ib); p.translate(-r.x(), -r.y()); p.fillPath(b, Qt::red); p.end(); QCOMPARE(ia, ib); QCOMPARE(a.boundingRect(), b.boundingRect()); } #endif }