Logo Search packages:      
Sourcecode: qt4-x11 version File versions

void QPainter::drawPixmap ( const QRectF target,
const QPixmap pixmap,
const QRectF source 
) [inherited]

Draws the rectangular portion source of the given pixmap into the given target in the paint device.

Note:
The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.
100% doc/src/snippets/code/src_gui_painting_qpainter.cpp 16

If pixmap is a QBitmap it is drawn with the bits that are "set" using the pens color. If backgroundMode is Qt::OpaqueMode, the "unset" bits are drawn using the color of the background brush; if backgroundMode is Qt::TransparentMode, the "unset" bits are transparent. Drawing bitmaps with gradient or texture colors is not supported.

See also:
drawImage()

Definition at line 4536 of file qpainter.cpp.

References QPainter::brush(), QBrush::d, QPainter::drawRect(), QPainter::fillRect(), QRectF::height(), QPixmap::height(), QPainter::isActive(), QPixmap::isNull(), QPixmap::isQBitmap(), QPainter::renderHints(), QPainter::restore(), QPainter::save(), QPainter::scale(), QPainter::setBackgroundMode(), QPainter::setBrush(), QPainter::setBrushOrigin(), QPainter::setPen(), QPainter::setRenderHint(), QPainter::translate(), QPixmap::width(), QRectF::width(), QRectF::x(), and QRectF::y().

Referenced by MainWindow::createColorToolButtonIcon(), Q3CanvasSprite::draw(), MainWindow::drawBackground(), Q3Canvas::drawBackground(), QWindowsStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QWindowsVistaStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QMotifStyle::drawControl(), QWindowsStyle::drawControl(), QWindowsXPStyle::drawControl(), QCommonStyle::drawControl(), QItemDelegate::drawDecoration(), QStyle::drawItemPixmap(), QPainter::drawPixmap(), QWindowsVistaStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QGLWidget::event(), QPicture::exec(), Q3ListBoxPixmap::paint(), Q3TableItem::paint(), LayoutItem::paint(), ImageItem::paint(), Q3ListViewItem::paintCell(), QCommandLinkButton::paintEvent(), QWizard::paintEvent(), MandelbrotWidget::paintEvent(), MyClass::paintEvent(), Q3ComboBox::paintEvent(), QGraphicsView::paintEvent(), Q3IconViewItem::paintItem(), QGraphicsWidget::paintWindowFrame(), QWidget::render(), QGraphicsView::scrollContentsBy(), QPlastiqueStyle::standardIconImplementation(), QWindowsStyle::standardIconImplementation(), QCleanlooksStyle::standardIconImplementation(), QCleanlooksStyle::standardPixmap(), QWindowsStyle::standardPixmap(), and QPlastiqueStyle::standardPixmap().

{
#if defined QT_DEBUG_DRAW
    if (qt_show_painter_debug_output)
        printf("QPainter::drawPixmap(), target=[%.2f,%.2f,%.2f,%.2f], pix=[%d,%d], source=[%.2f,%.2f,%.2f,%.2f]\n",
               r.x(), r.y(), r.width(), r.height(),
               pm.width(), pm.height(),
               sr.x(), sr.y(), sr.width(), sr.height());
#endif

    Q_D(QPainter);
    if (!isActive() || pm.isNull())
        return;
    if (!qt_painter_thread_test(d->device->devType(), "drawPixmap()"))
        return;

    qreal x = r.x();
    qreal y = r.y();
    qreal w = r.width();
    qreal h = r.height();
    qreal sx = sr.x();
    qreal sy = sr.y();
    qreal sw = sr.width();
    qreal sh = sr.height();

    // Sanity-check clipping
    if (sw <= 0)
        sw = pm.width() - sx;

    if (sh <= 0)
        sh = pm.height() - sy;

    if (w < 0)
        w = sw;
    if (h < 0)
        h = sh;

    if (sx < 0) {
        qreal w_ratio = sx * w/sw;
        x -= w_ratio;
        w += w_ratio;
        sw += sx;
        sx = 0;
    }

    if (sy < 0) {
        qreal h_ratio = sy * h/sh;
        y -= h_ratio;
        h += h_ratio;
        sh += sy;
        sy = 0;
    }

    if (sw + sx > pm.width()) {
        qreal delta = sw - (pm.width() - sx);
        qreal w_ratio = delta * w/sw;
        sw -= delta;
        w -= w_ratio;
    }

    if (sh + sy > pm.height()) {
        qreal delta = sh - (pm.height() - sy);
        qreal h_ratio = delta * h/sh;
        sh -= delta;
        h -= h_ratio;
    }

    if (w == 0 || h == 0 || sw <= 0 || sh <= 0)
        return;

    // Emulate opaque background for bitmaps
    if (d->state->bgMode == Qt::OpaqueMode && pm.isQBitmap()) {
        fillRect(QRectF(x, y, w, h), d->state->bgBrush.color());
    }

    d->updateState(d->state);

    if ((d->state->txop > QTransform::TxTranslate
         && !d->engine->hasFeature(QPaintEngine::PixmapTransform))
        || (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform))
        || (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))
        || ((sw != w || sh != h) && !d->engine->hasFeature(QPaintEngine::PixmapTransform)))
    {
        save();
        // If there is no scaling or transformation involved we have to make sure we use the
        // antialiased and not the aliased coordinate system by rounding the coordinates.
        if (d->state->txop <= QTransform::TxTranslate && sw == w && sh == h) {
            x = qRound(x + d->state->matrix.dx()) - d->state->matrix.dx();
            y = qRound(y + d->state->matrix.dy()) - d->state->matrix.dy();
            sx = qRound(sx);
            sy = qRound(sy);
            sw = qRound(sw);
            sh = qRound(sh);
        }
        translate(x, y);
        scale(w / sw, h / sh);
        setBackgroundMode(Qt::TransparentMode);
        setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform);
        QBrush brush(d->state->pen.color(), pm);
        brush.d->sourceRect = QRectF(sx, sy, sw, sh).toAlignedRect();
        setBrush(brush);
        setPen(Qt::NoPen);
        setBrushOrigin(QPointF(-sx, -sy));

        drawRect(QRectF(0, 0, sw, sh));
        restore();
    } else {
        if (!d->engine->hasFeature(QPaintEngine::PixmapTransform)) {
            x += d->state->matrix.dx();
            y += d->state->matrix.dy();
        }
        d->engine->drawPixmap(QRectF(x, y, w, h), pm, QRectF(sx, sy, sw, sh));
    }
}


Generated by  Doxygen 1.6.0   Back to index