void dumpPartPictures(const QHash<QString, QPicture> &partPictures) { foreach (const QString &partKey, partPictures.keys()) { QPicture partPicture = partPictures.value(partKey); qDebug() << partKey << partPicture.boundingRect(); QImage image(partPicture.boundingRect().size(), QImage::Format_ARGB32); image.fill(Qt::transparent); QPainter p(&image); partPicture.play(&p); image.save(partKey + QString::fromLatin1(".png")); } }
bool QPicturePaintEngine::begin(QPaintDevice *pd) { Q_D(QPicturePaintEngine); #ifdef QT_PICTURE_DEBUG qDebug() << "QPicturePaintEngine::begin()"; #endif Q_ASSERT(pd); QPicture *pic = static_cast<QPicture *>(pd); d->pdev = pd; d->pic_d = pic->d_func(); Q_ASSERT(d->pic_d); d->s.setDevice(&d->pic_d->pictb); d->s.setVersion(d->pic_d->formatMajor); d->pic_d->pictb.open(QIODevice::WriteOnly | QIODevice::Truncate); d->s.writeRawData(qt_mfhdr_tag, 4); d->s << (quint16) 0 << (quint16) d->pic_d->formatMajor << (quint16) d->pic_d->formatMinor; d->s << (quint8) QPicturePrivate::PdcBegin << (quint8) sizeof(qint32); d->pic_d->brect = QRect(); if (d->pic_d->formatMajor >= 4) { QRect r = pic->boundingRect(); d->s << (qint32) r.left() << (qint32) r.top() << (qint32) r.width() << (qint32) r.height(); } d->pic_d->trecs = 0; d->s << (quint32)d->pic_d->trecs; // total number of records d->pic_d->formatOk = false; setActive(true); return true; }
void PictureRenderer::render(QPainter *painter, const QRectF &bounds) { QRect br = picture.boundingRect(); QTransform worldTransform = painter->worldTransform(); painter->translate(bounds.topLeft()); painter->scale(bounds.width()/br.width(), bounds.height()/br.height()); painter->drawPicture(br.topLeft(), picture); painter->setWorldTransform(worldTransform); }
void operator()( int ) { QPicture pic = cache.svgAsPicture( svgPath, size, QColor( 255, 0, 0 ), QColor( 0, 255, 0 ), 1, 1, true ); QSize imageSize = pic.boundingRect().size(); QImage image( imageSize, QImage::Format_ARGB32_Premultiplied ); image.fill( 0 ); // transparent background QPainter p( &image ); p.drawPicture( 0, 0, pic ); }
void BaseDrawingWidget::commitDrawing(QPicture drawingPictureData) { getDrawingData()->registerAction(drawingPictureData); getDrawingData()->setModified(true); // update the stage getDrawingData()->update(drawingPictureData.boundingRect().adjusted(-drawingPen.width()-5, -drawingPen.width()-5, drawingPen.width()+5, drawingPen.width()+5)); }
QPixmap QS60StylePrivate::part(QS60StyleEnums::SkinParts part, const QSize &size, QPainter *painter, QS60StylePrivate::SkinElementFlags flags) { Q_UNUSED(painter); const QString partKey = QS60Style::partKeys().at(part); const QPicture partPicture = QS60StyleModeSpecifics::m_partPictures.value(partKey); QSize partSize(partPicture.boundingRect().size()); if (flags & (SF_PointEast | SF_PointWest)) { const int temp = partSize.width(); partSize.setWidth(partSize.height()); partSize.setHeight(temp); } const qreal scaleX = size.width() / (qreal)partSize.width(); const qreal scaleY = size.height() / (qreal)partSize.height(); QImage partImage(size, QImage::Format_ARGB32); partImage.fill(Qt::transparent); QPainter resultPainter(&partImage); QTransform t; if (flags & SF_PointEast) t.translate(size.width(), 0); else if (flags & SF_PointSouth) t.translate(size.width(), size.height()); else if (flags & SF_PointWest) t.translate(0, size.height()); t.scale(scaleX, scaleY); if (flags & SF_PointEast) t.rotate(90); else if (flags & SF_PointSouth) t.rotate(180); else if (flags & SF_PointWest) t.rotate(270); resultPainter.setTransform(t, true); const_cast<QPicture *>(&partPicture)->play(&resultPainter); resultPainter.end(); QPixmap result = QPixmap::fromImage(partImage); if (flags & SF_StateDisabled) { QStyleOption opt; QPalette *themePalette = QS60StylePrivate::themePalette(); if (themePalette) opt.palette = *themePalette; result = QApplication::style()->generatedIconPixmap(QIcon::Disabled, result, &opt); } return result; }
void KoPictureClipart::drawQPicture(QPicture& clipart, QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh) { kdDebug(30003) << "Drawing KoPictureClipart " << this << endl; kdDebug(30003) << " x=" << x << " y=" << y << " width=" << width << " height=" << height << endl; kdDebug(30003) << " sx=" << sx << " sy=" << sy << " sw=" << sw << " sh=" << sh << endl; painter.save(); // Thanks to Harri, Qt3 makes it much easier than Qt2 ;) QRect br = clipart.boundingRect(); kdDebug(30003) << " Bounding rect. " << br << endl; painter.translate(x,y); // Translating must be done before scaling! if ( br.width() && br.height() ) painter.scale(double(width)/double(br.width()),double(height)/double(br.height())); else kdWarning(30003) << "Null bounding rectangle: " << br.width() << " x " << br.height() << endl; painter.drawPicture(0,0,clipart); painter.restore(); }
void DrawingData::registerAction(QPicture actions) { QRect boundingRect = actions.boundingRect().adjusted(-2,-2,2,2); // fix negative / too large coordinates if(boundingRect.x() < 0) boundingRect.setX(0); if(boundingRect.y() < 0) boundingRect.setY(0); if(boundingRect.x() > width()) boundingRect.setX(width()); if(boundingRect.y() > height()) boundingRect.setY(height()); // backup the area to be painted, to be used for undo'ing later QPixmap areaToChange = QPixmap::fromImage(stage.copy(boundingRect)); // set the properties of this drawing step for undo/redo currentAction->setActions(actions); currentAction->setPrevPixmap(areaToChange, boundingRect); // add to the undo stack undoStack.push(currentAction); currentAction = new DrawingAction(this); }