void BitmapImage::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect) { QPixmap* framePixmap = nativeImageForCurrentFrame(); if (!framePixmap) // If it's too early we won't have an image yet. return; QPixmap pixmap = *framePixmap; QRect tr = QRectF(tileRect).toRect(); if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height()) { pixmap = pixmap.copy(tr); } if (patternTransform.isIdentity()) { ctxt->save(); ctxt->setCompositeOperation(op); QPainter* p = ctxt->platformContext(); p->setBrushOrigin(phase); p->drawTiledPixmap(destRect, pixmap); ctxt->restore(); } else { QBrush b(pixmap); b.setMatrix(patternTransform); ctxt->save(); ctxt->setCompositeOperation(op); QPainter* p = ctxt->platformContext(); p->setBrushOrigin(phase); p->fillRect(destRect, b); ctxt->restore(); } }
void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const TransformationMatrix& patternTransform, const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect) { QPixmap* framePixmap = nativeImageForCurrentFrame(); if (!framePixmap) // If it's too early we won't have an image yet. return; QPixmap pixmap = *framePixmap; QRect tr = QRectF(tileRect).toRect(); if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height()) pixmap = pixmap.copy(tr); QBrush b(pixmap); b.setTransform(patternTransform); ctxt->save(); ctxt->setCompositeOperation(op); QPainter* p = ctxt->platformContext(); if (!pixmap.hasAlpha() && p->compositionMode() == QPainter::CompositionMode_SourceOver) p->setCompositionMode(QPainter::CompositionMode_Source); p->setBrushOrigin(phase); p->fillRect(destRect, b); ctxt->restore(); if (imageObserver()) imageObserver()->didDraw(this); }
/* static */ void AbstractAreaBase::paintBackgroundAttributes( QPainter& painter, const QRect& rect, const KChart::BackgroundAttributes& attributes ) { if ( !attributes.isVisible() ) return; /* first draw the brush (may contain a pixmap)*/ if ( Qt::NoBrush != attributes.brush().style() ) { KChart::PainterSaver painterSaver( &painter ); painter.setPen( Qt::NoPen ); const QPointF newTopLeft( painter.deviceMatrix().map( rect.topLeft() ) ); painter.setBrushOrigin( newTopLeft ); painter.setBrush( attributes.brush() ); painter.drawRect( rect.adjusted( 0, 0, -1, -1 ) ); } /* next draw the backPixmap over the brush */ if ( !attributes.pixmap().isNull() && attributes.pixmapMode() != BackgroundAttributes::BackgroundPixmapModeNone ) { QPointF ol = rect.topLeft(); if ( BackgroundAttributes::BackgroundPixmapModeCentered == attributes.pixmapMode() ) { ol.setX( rect.center().x() - attributes.pixmap().width() / 2 ); ol.setY( rect.center().y() - attributes.pixmap().height()/ 2 ); painter.drawPixmap( ol, attributes.pixmap() ); } else { QMatrix m; qreal zW = (qreal)rect.width() / (qreal)attributes.pixmap().width(); qreal zH = (qreal)rect.height() / (qreal)attributes.pixmap().height(); switch ( attributes.pixmapMode() ) { case BackgroundAttributes::BackgroundPixmapModeScaled: { qreal z; z = qMin( zW, zH ); m.scale( z, z ); } break; case BackgroundAttributes::BackgroundPixmapModeStretched: m.scale( zW, zH ); break; default: ; // Cannot happen, previously checked } QPixmap pm = attributes.pixmap().transformed( m ); ol.setX( rect.center().x() - pm.width() / 2 ); ol.setY( rect.center().y() - pm.height()/ 2 ); painter.drawPixmap( ol, pm ); } } }
void PlayField::mouseMoveEvent(QMouseEvent *e) { lastMouseXPos_ = e->x(); lastMouseYPos_ = e->y(); if (!dragInProgress_) return highlight(); int old_x = dragX_, old_y = dragY_; dragX_ = lastMouseXPos_ - mousePosX_; dragY_ = lastMouseYPos_ - mousePosY_; { int x = pixel2x(dragX_ + size_/2); int y = pixel2y(dragY_ + size_/2); if (x >= 0 && x < levelMap_->width() && y >= 0 && y < levelMap_->height() && pathFinder_.canDragTo(x, y)) { x = x2pixel(x); y = y2pixel(y); if (dragX_ >= x - size_/4 && dragX_ < x + size_/4 && dragY_ >= y - size_/4 && dragY_ < y + size_/4) { dragX_ = x; dragY_ = y; } } } if (dragX_ == old_x && dragY_ == old_y) return; QRect rect(dragX_, dragY_, size_, size_); dragXpm_= QPixmap(size_, size_); QPainter paint; paint.begin(&dragXpm_); paint.setBackground(palette().color(backgroundRole())); paint.setBrushOrigin(- dragX_, - dragY_); paint.translate((double) (- dragX_), (double) (- dragY_)); paintPainter(paint, rect); paint.end(); dragImage_ = dragXpm_.toImage(); for (int yy=0; yy<size_; yy++) { for (int xx=0; xx<size_; xx++) { QRgb rgb1 = imageData_->objectImg().pixel(xx, yy); int r1 = qRed(rgb1); int g1 = qGreen(rgb1); int b1 = qBlue(rgb1); if (r1 != g1 || r1 != b1 || r1 == 255) { QRgb rgb2 = dragImage_.pixel(xx, yy); int r2 = qRed(rgb2); int g2 = qGreen(rgb2); int b2 = qBlue(rgb2); r2 = (int) (0.75 * r1 + 0.25 * r2 + 0.5); g2 = (int) (0.75 * g1 + 0.25 * g2 + 0.5); b2 = (int) (0.75 * b1 + 0.25 * b2 + 0.5); dragImage_.setPixel(xx, yy, qRgb(r2, g2, b2)); } } } paint.begin(this); // the following line is a workaround for a bug in Qt 2.0.1 // (and possibly earlier versions) paint.setBrushOrigin(0, 0); dragXpm_ = QPixmap::fromImage(dragImage_, Qt::OrderedDither|Qt::OrderedAlphaDither| Qt::ColorOnly|Qt::AvoidDither); paint.drawPixmap(dragX_, dragY_, dragXpm_); { int dx = dragX_ - old_x; int dy = dragY_ - old_y; int y2 = old_y; if (dy > 0) { paintPainterClip(paint, old_x, old_y, size_, dy); // NOTE: clipping is now activated in the QPainter paint y2 += dy; } else if (dy < 0) { paintPainterClip(paint, old_x, old_y+size_+dy, size_, -dy); // NOTE: clipping is now activated in the QPainter paint dy = -dy; } if (dx > 0) { paintPainterClip(paint, old_x, y2, dx, size_-dy); // NOTE: clipping is now activated in the QPainter paint } else if (dx < 0) { paintPainterClip(paint, old_x+size_+dx, y2, -dx, size_-dy); // NOTE: clipping is now activated in the QPainter paint } } paint.end(); }