⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtransform.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        QTransform result;        if (axis == Qt::YAxis) {            result.affine._m11 = cosa;            result.m_13 = -sina * inv_dist_to_plane;        } else {            result.affine._m22 = cosa;            result.m_23 = -sina * inv_dist_to_plane;        }        m_dirty = TxProject;        *this = result * *this;    }    return *this;}/*!    \fn bool QTransform::operator==(const QTransform &matrix) const    Returns true if this matrix is equal to the given \a matrix,    otherwise returns false.*/bool QTransform::operator==(const QTransform &o) const{#define qFZ qFuzzyCompare    return qFZ(affine._m11, o.affine._m11) &&  qFZ(affine._m12, o.affine._m12) &&  qFZ(m_13, o.m_13)        && qFZ(affine._m21, o.affine._m21) &&  qFZ(affine._m22, o.affine._m22) &&  qFZ(m_23, o.m_23)        && qFZ(affine._dx, o.affine._dx) &&  qFZ(affine._dy, o.affine._dy) &&  qFZ(m_33, o.m_33);#undef qFZ}/*!    \fn bool QTransform::operator!=(const QTransform &matrix) const    Returns true if this matrix is not equal to the given \a matrix,    otherwise returns false.*/bool QTransform::operator!=(const QTransform &o) const{    return !operator==(o);}/*!    \fn QTransform & QTransform::operator*=(const QTransform &matrix)    \overload    Returns the result of multiplying this matrix by the given \a    matrix.*/QTransform & QTransform::operator*=(const QTransform &o){    qreal m11 = affine._m11*o.affine._m11 + affine._m12*o.affine._m21 + m_13*o.affine._dx;    qreal m12 = affine._m11*o.affine._m12 + affine._m12*o.affine._m22 + m_13*o.affine._dy;    qreal m13 = affine._m11*o.m_13 + affine._m12*o.m_23 + m_13*o.m_33;    qreal m21 = affine._m21*o.affine._m11 + affine._m22*o.affine._m21 + m_23*o.affine._dx;    qreal m22 = affine._m21*o.affine._m12 + affine._m22*o.affine._m22 + m_23*o.affine._dy;    qreal m23 = affine._m21*o.m_13 + affine._m22*o.m_23 + m_23*o.m_33;    qreal m31 = affine._dx*o.affine._m11 + affine._dy*o.affine._m21 + m_33*o.affine._dx;    qreal m32 = affine._dx*o.affine._m12 + affine._dy*o.affine._m22 + m_33*o.affine._dy;    qreal m33 = affine._dx*o.m_13 + affine._dy*o.m_23 + m_33*o.m_33;    affine._m11 = m11/m33; affine._m12 = m12/m33; m_13 = m13/m33;    affine._m21 = m21/m33; affine._m22 = m22/m33; m_23 = m23/m33;    affine._dx = m31/m33; affine._dy = m32/m33; m_33 = 1.0;    m_dirty = m_dirty | m_type | o.m_dirty | o.m_type;    return *this;}/*!    \fn QTransform QTransform::operator*(const QTransform &matrix) const    Returns the result of multiplying this matrix by the given \a    matrix.    Note that matrix multiplication is not commutative, i.e. a*b !=    b*a.*/QTransform QTransform::operator*(const QTransform &m) const{    QTransform result = *this;    result *= m;    return result;}/*!    \fn QTransform & QTransform::operator*=(qreal scalar)    \overload    Returns the result of performing an element-wise multiplication of this    matrix with the given \a scalar.*//*!    \fn QTransform & QTransform::operator/=(qreal scalar)    \overload    Returns the result of performing an element-wise division of this    matrix by the given \a scalar.*//*!    \fn QTransform & QTransform::operator+=(qreal scalar)    \overload    Returns the matrix obtained by adding the given \a scalar to each    element of this matrix.*//*!    \fn QTransform & QTransform::operator-=(qreal scalar)    \overload    Returns the matrix obtained by subtracting the given \a scalar from each    element of this matrix.*//*!    Assigns the given \a matrix's values to this matrix.*/QTransform & QTransform::operator=(const QTransform &matrix){    affine._m11 = matrix.affine._m11;    affine._m12 = matrix.affine._m12;    m_13 = matrix.m_13;    affine._m21 = matrix.affine._m21;    affine._m22 = matrix.affine._m22;    m_23 = matrix.m_23;    affine._dx = matrix.affine._dx;    affine._dy = matrix.affine._dy;    m_33 = matrix.m_33;    m_type = matrix.m_type;    m_dirty = matrix.m_dirty;    return *this;}/*!    Resets the matrix to an identity matrix, i.e. all elements are set    to zero, except \c m11 and \c m22 (specifying the scale) which are    set to 1.    \sa QTransform(), isIdentity(), {QTransform#Basic Matrix    Operations}{Basic Matrix Operations}*/void QTransform::reset(){    affine._m11 = affine._m22 = m_33 = 1.0;    affine._m12 = m_13 = affine._m21 = m_23 = affine._dx = affine._dy = 0;    m_type = TxNone;    m_dirty = TxNone;}#ifndef QT_NO_DATASTREAM/*!    \fn QDataStream &operator<<(QDataStream &stream, const QTransform &matrix)    \since 4.3    \relates QTransform    Writes the given \a matrix to the given \a stream and returns a    reference to the stream.    \sa {Format of the QDataStream Operators}*/QDataStream & operator<<(QDataStream &s, const QTransform &m){    s << double(m.m11())      << double(m.m12())      << double(m.m13())      << double(m.m21())      << double(m.m22())      << double(m.m23())      << double(m.m31())      << double(m.m32())      << double(m.m33());    return s;}/*!    \fn QDataStream &operator>>(QDataStream &stream, QTransform &matrix)    \since 4.3    \relates QTransform    Reads the given \a matrix from the given \a stream and returns a    reference to the stream.    \sa {Format of the QDataStream Operators}*/QDataStream & operator>>(QDataStream &s, QTransform &t){     double m11, m12, m13,         m21, m22, m23,         m31, m32, m33;     s >> m11;     s >> m12;     s >> m13;     s >> m21;     s >> m22;     s >> m23;     s >> m31;     s >> m32;     s >> m33;     t.setMatrix(m11, m12, m13,                 m21, m22, m23,                 m31, m32, m33);     return s;}#endif // QT_NO_DATASTREAM#ifndef QT_NO_DEBUG_STREAMQDebug operator<<(QDebug dbg, const QTransform &m){    dbg.nospace() << "QTransform("                  << "11="  << m.m11()                  << " 12=" << m.m12()                  << " 13=" << m.m13()                  << " 21=" << m.m21()                  << " 22=" << m.m22()                  << " 23=" << m.m23()                  << " 31=" << m.m31()                  << " 32=" << m.m32()                  << " 33=" << m.m33()                  << ")";    return dbg.space();}#endif/*!    \fn QPoint operator*(const QPoint &point, const QTransform &matrix)    \relates QTransform    This is the same as \a{matrix}.map(\a{point}).    \sa QTransform::map()*/QPoint QTransform::map(const QPoint &p) const{    qreal fx = p.x();    qreal fy = p.y();    qreal x = affine._m11 * fx + affine._m21 * fy + affine._dx;    qreal y = affine._m12 * fx + affine._m22 * fy + affine._dy;    if (isAffine()) {        return QPoint(qRound(x), qRound(y));    } else {        qreal w = m_13 * fx + m_23 * fy + m_33;        return QPoint(qRound(x/w), qRound(y/w));    }}/*!    \fn QPointF operator*(const QPointF &point, const QTransform &matrix)    \relates QTransform    Same as \a{matrix}.map(\a{point}).    \sa QTransform::map()*//*!    \overload    Creates and returns a QPointF object that is a copy of the given point,    \a p, mapped into the coordinate system defined by this matrix.*/QPointF QTransform::map(const QPointF &p) const{    qreal fx = p.x();    qreal fy = p.y();    qreal x = affine._m11 * fx + affine._m21 * fy + affine._dx;    qreal y = affine._m12 * fx + affine._m22 * fy + affine._dy;    if (isAffine()) {        return QPointF(x, y);    } else {        qreal w = m_13 * fx + m_23 * fy + m_33;        return QPointF(x/w, y/w);    }}/*!    \fn QPoint QTransform::map(const QPoint &point) const    \overload    Creates and returns a QPoint object that is a copy of the given \a    point, mapped into the coordinate system defined by this    matrix. Note that the transformed coordinates are rounded to the    nearest integer.*//*!    \fn QLineF operator*(const QLineF &line, const QTransform &matrix)    \relates QTransform    This is the same as \a{matrix}.map(\a{line}).    \sa QTransform::map()*//*!    \fn QLine operator*(const QLine &line, const QTransform &matrix)    \relates QTransform    This is the same as \a{matrix}.map(\a{line}).    \sa QTransform::map()*//*!    \overload    Creates and returns a QLineF object that is a copy of the given line,    \a l, mapped into the coordinate system defined by this matrix.*/QLine QTransform::map(const QLine &l) const{    return QLine(map(l.p1()), map(l.p2()));}/*!    \overload    \fn QLineF QTransform::map(const QLineF &line) const        Creates and returns a QLine object that is a copy of the given \a    line, mapped into the coordinate system defined by this matrix.    Note that the transformed coordinates are rounded to the nearest    integer.*/QLineF QTransform::map(const QLineF &l) const{    return QLineF(map(l.p1()), map(l.p2()));}/*!    \fn QPolygonF operator *(const QPolygonF &polygon, const QTransform &matrix)    \since 4.3    \relates QTransform    This is the same as \a{matrix}.map(\a{polygon}).    \sa QTransform::map()*//*!    \fn QPolygon operator*(const QPolygon &polygon, const QTransform &matrix)    \relates QTransform    This is the same as \a{matrix}.map(\a{polygon}).    \sa QTransform::map()*//*!    \fn QPolygonF QTransform::map(const QPolygonF &polygon) const    \overload    Creates and returns a QPolygonF object that is a copy of the given    \a polygon, mapped into the coordinate system defined by this    matrix.*/QPolygonF QTransform::map(const QPolygonF &a) const{    int size = a.size();    int i;    QPolygonF p(size);    const QPointF *da = a.constData();    QPointF *dp = p.data();    qreal fx, fy;    for(i = 0; i < size; ++i) {        MAPDOUBLE(da[i].xp, da[i].yp, dp[i].xp, dp[i].yp);    }    return p;}/*!    \fn QPolygon QTransform::map(const QPolygon &polygon) const    \overload    Creates and returns a QPolygon object that is a copy of the given    \a polygon, mapped into the coordinate system defined by this    matrix. Note that the transformed coordinates are rounded to the    nearest integer.*/QPolygon QTransform::map(const QPolygon &a) const{    int size = a.size();    int i;    QPolygon p(size);    const QPoint *da = a.constData();    QPoint *dp = p.data();    int fx, fy;    for(i = 0; i < size; ++i) {        MAPINT(da[i].xp, da[i].yp, dp[i].xp, dp[i].yp);    }    return p;}/*!    \fn QRegion operator*(const QRegion &region, const QTransform &matrix)    \relates QTransform    This is the same as \a{matrix}.map(\a{region}).    \sa QTransform::map()*//*!    \fn QRegion QTransform::map(const QRegion &region) 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 QTransform::map(const QRegion &r) const{    if (isAffine() && !isScaling() && !isRotating()) { // translate or identity        if (!isTranslating()) // Identity            return r;        QRegion copy(r);        copy.translate(qRound(affine._dx), qRound(affine._dy));        return copy;    }    QPainterPath p;    p.addRegion(r);    p = map(p);    return p.toFillPolygon(QTransform()).toPolygon();}/*!    \fn QPainterPath operator *(const QPainterPath &path, const QTransform &matrix)    \since 4.3    \relates QTransform    This is the same as \a{matrix}.map(\a{path}).    \sa QTransform::map()*//*!    \overload    Creates and returns a QPainterPath object that is a copy of the    given \a path, mapped into the coordinate system defined by this    matrix.*/QPainterPath QTransform::map(const QPainterPath &path) const{    if (path.isEmpty())        return QPainterPath();    QPainterPath copy = path;    // Translate or identity    if (isAffine() && !isScaling() && !isRotating()) {        // Translate        if (isTranslating()) {            copy.detach();            for (int i=0; i<path.elementCount(); ++i) {                QPainterPath::Element &e = copy.d_ptr->elements[i];                e.x += affine._dx;                e.y += affine._dy;            }        }    // Full xform    } else {        copy.detach();        qreal fx, fy;        for (int i=0; i<path.elementCount(); ++i) {            QPainterPath::Element &e = copy.d_ptr->elements[i];            MAPDOUBLE(e.x, e.y, e.x, e.y);        }    }    return copy;}/*!    \fn QPolygon QTransform::mapToPolygon(const QRect &rectangle) const    Creates and returns a QPolygon representation of the given \a    rectangle, mapped into the coordinate system defined by this    matrix.    The rectangle's coordinates are transformed using the following    formulas:    \code        x' = m11*x + m21*y + dx        y' = m22*y + m12*x + dy        if (is not affine) {            w' = m13*x + m23*y + m33            x' /= w'            y' /= w'        }    \endcode    Polygons and rectangles behave slightly differently when    transformed (due to integer rounding), so    \c{matrix.map(QPolygon(rectangle))} is not always the same as    \c{matrix.mapToPolygon(rectangle)}.    \sa mapRect(), {QTransform#Basic Matrix Operations}{Basic Matrix    Operations}*/QPolygon QTransform::mapToPolygon(const QRect &rect) const{    QPolygon a(4);    qreal x[4], y[4];    if (isAffine() && !isRotating()) {        x[0] = affine._m11*rect.x() + affine._dx;        y[0] = affine._m22*rect.y() + affine._dy;        qreal w = affine._m11*rect.width();        qreal h = affine._m22*rect.height();        if (w < 0) {            w = -w;            x[0] -= w;        }        if (h < 0) {            h = -h;            y[0] -= h;        }        x[1] = x[0]+w;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -