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

📄 qpainter.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
{    Q_D(QPainter);#ifdef QT_DEBUG_DRAW    QRect rect = r.boundingRect();    if (qt_show_painter_debug_output)        printf("QPainter::setClipRegion(), size=%d, [%d,%d,%d,%d]\n",           r.rects().size(), rect.x(), rect.y(), rect.width(), rect.height());#endif    if (!isActive()) {        qWarning("QPainter::setClipRegion(); painter not active");        return;    }    if (!d->state->clipEnabled && (op == Qt::IntersectClip || op == Qt::UniteClip))        op = Qt::ReplaceClip;    d->state->clipRegion = r;    d->state->clipOperation = op;    if (op == Qt::NoClip || op == Qt::ReplaceClip)        d->state->clipInfo.clear();    d->state->clipInfo << QPainterClipInfo(r, op, d->state->worldMatrix);    d->state->clipEnabled = true;    d->state->dirtyFlags |= QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyClipEnabled;    d->updateState(d->state);}/*!    Sets the transformation matrix to \a matrix and enables transformations.    If \a combine is true, then \a matrix is combined with the current    transformation matrix; otherwise \a matrix replaces the current    transformation matrix.    If \a matrix is the identity matrix and \a combine is false, this    function calls setMatrixEnabled(false). (The identity matrix is the    matrix where QMatrix::m11() and QMatrix::m22() are 1.0 and the    rest are 0.0.)    The following functions can transform the coordinate system without using    a QMatrix:    \list    \i translate()    \i scale()    \i shear()    \i rotate()    \endlist    They operate on the painter's matrix() and are implemented like this:    \code        void QPainter::rotate(qreal angle)        {            QMatrix matrix;            matrix.rotate(angle);            setMatrix(matrix, true);        }    \endcode    Note that when using setMatrix() function you should always have    \a combine be true when you are drawing into a QPicture. Otherwise    it may not be possible to replay the picture with additional    transformations; using the translate(), scale(), etc. convenience    functions is safe.    For more information about the coordinate system, transformations    and window-viewport conversion, see \l {The Coordinate System}    documentation.    \sa matrix(), matrixEnabled(), QMatrix*/void QPainter::setMatrix(const QMatrix &matrix, bool combine){    Q_D(QPainter);#ifdef QT_DEBUG_DRAW    if (qt_show_painter_debug_output)        printf("QPainter::setMatrix(), combine=%d\n", combine);#endif   if (!isActive()) {        qWarning("QPainter::setMatrix(), painter not active ");        return;    }    if (combine)        d->state->worldMatrix = matrix * d->state->worldMatrix;                        // combines    else        d->state->worldMatrix = matrix;                                // set new matrix    if (!d->state->WxF)        setMatrixEnabled(true);    else        d->updateMatrix();}/*!    Returns the world transformation matrix.    \sa setMatrix(), {QPainter#Coordinate Transformations}{Coordinate    Transformations}, {The Coordinate System}*/const QMatrix &QPainter::matrix() const{    Q_D(const QPainter);    return d->state->worldMatrix;}/*!    Returns the matrix that transforms from logical coordinates to    device coordinates of the platform dependent paint device.    This function is \e only needed when using platform painting    commands on the platform dependent handle ( Qt::HANDLE), and the    platform does not do transformations nativly.    The QPaintEngine::PaintEngineFeature enum can be queried to    determine whether the platform performs the transformations or    not.    \sa matrix(), QPaintEngine::hasFeature(),*/const QMatrix &QPainter::deviceMatrix() const{    Q_D(const QPainter);    return d->state->matrix;}/*!    Resets any transformations that were made using translate(), scale(),    shear(), rotate(), setMatrix(), setViewport() and    setWindow().    \sa {QPainter#Coordinate Transformations}{Coordinate    Transformations}*/void QPainter::resetMatrix(){    Q_D(QPainter);#ifdef QT_DEBUG_DRAW    if (qt_show_painter_debug_output)        printf("QPainter::resetMatrix()\n");#endif    if (!isActive()) {        qWarning("QPainter::resetMatrix(), painter not active");        return;    }    d->state->wx = d->state->wy = d->state->vx = d->state->vy = 0;                        // default view origins    d->state->ww = d->state->vw = d->device->metric(QPaintDevice::PdmWidth);    d->state->wh = d->state->vh = d->device->metric(QPaintDevice::PdmHeight);    d->state->worldMatrix = QMatrix();    setMatrixEnabled(false);    setViewTransformEnabled(false);    if (d->engine)        d->engine->setDirty(QPaintEngine::DirtyTransform);}/*!    Enables transformations if \a enable is true, or disables    transformations if \a enable is false. The world transformation    matrix is not changed.    \sa matrixEnabled(), matrix(), {QPainter#Coordinate    Transformations}{Coordinate Transformations}*/void QPainter::setMatrixEnabled(bool enable){    Q_D(QPainter);#ifdef QT_DEBUG_DRAW    if (qt_show_painter_debug_output)        printf("QPainter::setMatrixEnabled(), enable=%d\n", enable);#endif    if (!isActive()) {        qWarning("QPainter::setMatrixEnabled(), painter not active");        return;    }    if (enable == d->state->WxF)        return;    d->state->WxF = enable;    d->updateMatrix();}/*!    Returns true if world transformation is enabled; otherwise returns    false.    \sa setMatrixEnabled(), matrix(), {The Coordinate System}*/bool QPainter::matrixEnabled() const{    Q_D(const QPainter);    return d->state->WxF;}/*!    Scales the coordinate system by (\a{sx}, \a{sy}).    \sa setMatrix() {QPainter#Coordinate Transformations}{Coordinate    Transformations}*/void QPainter::scale(qreal sx, qreal sy){#ifdef QT_DEBUG_DRAW    if (qt_show_painter_debug_output)        printf("QPainter::scale(), sx=%f, sy=%f\n", sx, sy);#endif    QMatrix m;    m.scale(sx, sy);    setMatrix(m, true);}/*!    Shears the coordinate system by (\a{sh}, \a{sv}).    \sa setMatrix(), {QPainter#Coordinate Transformations}{Coordinate    Transformations}*/void QPainter::shear(qreal sh, qreal sv){#ifdef QT_DEBUG_DRAW    if (qt_show_painter_debug_output)        printf("QPainter::shear(), sh=%f, sv=%f\n", sh, sv);#endif    QMatrix m;    m.shear(sv, sh);    setMatrix(m, true);}/*!    \fn void QPainter::rotate(qreal angle)    Rotates the coordinate system the given \a angle clockwise.    \sa setMatrix(), {QPainter#Coordinate Transformations}{Coordinate    Transformations}*/void QPainter::rotate(qreal a){#ifdef QT_DEBUG_DRAW    if (qt_show_painter_debug_output)        printf("QPainter::rotate(), angle=%f\n", a);#endif    QMatrix m;    m.rotate(a);    setMatrix(m, true);}/*!    Translates the coordinate system by the given \a offset; i.e. the    given \a offset is added to points.    \sa setMatrix(), {QPainter#Coordinate Transformations}{Coordinate    Transformations}*/void QPainter::translate(const QPointF &offset){    qreal dx = offset.x();    qreal dy = offset.y();#ifdef QT_DEBUG_DRAW    if (qt_show_painter_debug_output)        printf("QPainter::translate(), dx=%f, dy=%f\n", dx, dy);#endif    QMatrix m;    m.translate(dx, dy);    setMatrix(m, true);}/*!    \fn void QPainter::translate(const QPoint &offset)    \overload    Translates the coordinate system by the given \a offset.*//*!    \fn void QPainter::translate(qreal dx, qreal dy)    \overload    Translates the coordinate system by the vector (\a dx, \a dy).*//*!    \fn void QPainter::setClipPath(const QPainterPath &path, Qt::ClipOperation operation)    Enables clipping, and sets the clip path for the painter to the    given \a path, with the clip \a operation.    Note that the clip path is specified in logical (painter)    coordinates.    \sa clipPath(), clipRegion(), {QPainter#Clipping}{Clipping}*/void QPainter::setClipPath(const QPainterPath &path, Qt::ClipOperation op){#ifdef QT_DEBUG_DRAW    if (qt_show_painter_debug_output) {        QRectF b = path.boundingRect();        printf("QPainter::setClipPath(), size=%d, op=%d, bounds=[%.2f,%.2f,%.2f,%.2f]\n",               path.elementCount(), op, b.x(), b.y(), b.width(), b.height());    }#endif    if (!isActive())        return;    Q_D(QPainter);    if (!d->state->clipEnabled && (op == Qt::IntersectClip || op == Qt::UniteClip))        op = Qt::ReplaceClip;    d->state->clipPath = path;    d->state->clipOperation = op;    if (op == Qt::NoClip || op == Qt::ReplaceClip)        d->state->clipInfo.clear();    d->state->clipInfo << QPainterClipInfo(path, op, d->state->worldMatrix);    d->state->clipEnabled = true;    d->state->dirtyFlags |= QPaintEngine::DirtyClipPath | QPaintEngine::DirtyClipEnabled;    d->updateState(d->state);}/*!    Draws the outline (strokes) the path \a path with the pen specified    by \a pen    \sa fillPath(), {QPainter#Drawing}{Drawing}*/void QPainter::strokePath(const QPainterPath &path, const QPen &pen){    if (!isActive())        return;    Q_D(QPainter);    QBrush oldBrush = d->state->brush;    QPen oldPen = d->state->pen;    d->state->pen = pen;    d->state->brush = Qt::NoBrush;    d->engine->setDirty(QPaintEngine::DirtyFlags(QPaintEngine::DirtyPen | QPaintEngine::DirtyBrush));    drawPath(path);    // Reset old state    d->state->pen = oldPen;    d->state->brush = oldBrush;    d->engine->setDirty(QPaintEngine::DirtyFlags(QPaintEngine::DirtyPen | QPaintEngine::DirtyBrush));}/*!    Fills the given \a path using the given \a brush. The outline is    not drawn.    Alternatively, you can specify a QColor instead of a QBrush; the    QBrush constructor (taking a QColor argument) will automatically    create a solid pattern brush.    \sa drawPath()*/void QPainter::fillPath(const QPainterPath &path, const QBrush &brush){    if (!isActive())        return;    Q_D(QPainter);    QBrush oldBrush = d->state->brush;    QPen oldPen = d->state->pen;    d->state->pen = Qt::NoPen;    d->state->brush = brush;    d->engine->setDirty(QPaintEngine::DirtyFlags(QPaintEngine::DirtyPen | QPaintEngine::DirtyBrush));    drawPath(path);    // Reset old state    d->state->pen = oldPen;    d->state->brush = oldBrush;    d->engine->setDirty(QPaintEngine::DirtyFlags(QPaintEngine::DirtyPen | QPaintEngine::DirtyBrush));}/*!    Draws the given painter \a path using the current pen for outline    and the current brush for filling.    \table 100%    \row    \o \inlineimage qpainter-path.png    \o    \code    QPainterPath path;    path.moveTo(20, 80);    path.lineTo(20, 30);    path.cubicTo(80, 0, 50, 50, 80, 80);    QPainter painter(this);    painter.drawPath(path);    \endcode    \endtable    \sa {painting/painterpaths}{the Painte

⌨️ 快捷键说明

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