本文整理汇总了C++中QPainter::setTransform方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::setTransform方法的具体用法?C++ QPainter::setTransform怎么用?C++ QPainter::setTransform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::setTransform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: orientationChanged
void PaintedWindow::orientationChanged(Qt::ScreenOrientation newOrientation)
{
if (contentOrientation() == newOrientation)
return;
if (m_animation->state() == QAbstractAnimation::Running) {
m_nextTargetOrientation = newOrientation;
return;
}
QRect rect(0, 0, width(), height());
m_prevImage = QImage(width(), height(), QImage::Format_ARGB32_Premultiplied);
m_nextImage = QImage(width(), height(), QImage::Format_ARGB32_Premultiplied);
m_prevImage.fill(0);
m_nextImage.fill(0);
QPainter p;
p.begin(&m_prevImage);
p.setTransform(screen()->transformBetween(contentOrientation(), screen()->orientation(), rect));
paint(&p, screen()->mapBetween(contentOrientation(), screen()->orientation(), rect));
p.end();
p.begin(&m_nextImage);
p.setTransform(screen()->transformBetween(newOrientation, screen()->orientation(), rect));
paint(&p, screen()->mapBetween(newOrientation, screen()->orientation(), rect));
p.end();
m_deltaRotation = screen()->angleBetween(newOrientation, contentOrientation());
if (m_deltaRotation > 180)
m_deltaRotation = 180 - m_deltaRotation;
m_targetOrientation = newOrientation;
m_animation->start();
}
示例2: drawTexture
void TextureMapperQt::drawTexture(const BitmapTexture& texture, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity, const BitmapTexture* maskTexture)
{
const BitmapTextureQt& textureQt = static_cast<const BitmapTextureQt&>(texture);
QPainter* painter = m_painter;
QPixmap pixmap = textureQt.m_pixmap;
if (m_currentSurface)
painter = &m_currentSurface->m_painter;
if (maskTexture && maskTexture->isValid()) {
const BitmapTextureQt* mask = static_cast<const BitmapTextureQt*>(maskTexture);
QPixmap intermediatePixmap(pixmap.size());
intermediatePixmap.fill(Qt::transparent);
QPainter maskPainter(&intermediatePixmap);
maskPainter.setCompositionMode(QPainter::CompositionMode_Source);
maskPainter.drawPixmap(0, 0, pixmap);
maskPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
maskPainter.drawPixmap(QRect(0, 0, pixmap.width(), pixmap.height()), mask->m_pixmap, mask->sourceRect());
maskPainter.end();
pixmap = intermediatePixmap;
}
const qreal prevOpacity = painter->opacity();
const QTransform prevTransform = painter->transform();
painter->setOpacity(opacity);
painter->setTransform(matrix, true);
painter->drawPixmap(targetRect, pixmap, FloatRect(textureQt.sourceRect()));
painter->setTransform(prevTransform);
painter->setOpacity(prevOpacity);
}
示例3: paint
void KWCopyShape::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext)
{
Q_ASSERT(m_original);
//paint all child shapes
KoShapeContainer* container = dynamic_cast<KoShapeContainer*>(m_original);
if (container) {
QList<KoShape*> sortedObjects = container->shapes();
sortedObjects.append(m_original);
qSort(sortedObjects.begin(), sortedObjects.end(), KoShape::compareShapeZIndex);
// Do the following to revert the absolute transformation of the
// container that is re-applied in shape->absoluteTransformation()
// later on. The transformation matrix of the container has already
// been applied once before this function is called.
QTransform baseMatrix = container->absoluteTransformation(&converter).inverted() * painter.transform();
KWPage copypage = m_pageManager->page(this);
Q_ASSERT(copypage.isValid());
foreach(KoShape *shape, sortedObjects) {
painter.save();
if (shape != m_original) {
painter.setTransform(shape->absoluteTransformation(&converter) * baseMatrix);
}
KoTextShapeData *data = qobject_cast<KoTextShapeData*>(shape->userData());
if (data == 0) {
shape->paint(painter, converter, paintcontext);
}
else {
// Since the rootArea is shared between the copyShape and the originalShape we need to
// temporary switch the used KoTextPage to be sure the proper page-numbers are displayed.
KWPage originalpage = m_pageManager->page(shape);
Q_ASSERT(originalpage.isValid());
KoTextLayoutRootArea *area = data->rootArea();
bool wasBlockChanges = false;
if (area) {
// We need to block documentChanged() signals emitted cause for example page-variables
// may change there content to result in us marking root-areas dirty for relayout else
// we could end in an infinite relayout ping-pong.
wasBlockChanges = area->documentLayout()->changesBlocked();
area->documentLayout()->setBlockChanges(true);
area->setPage(new KWPage(copypage));
}
shape->paint(painter, converter, paintcontext);
if (area) {
area->setPage(new KWPage(originalpage));
area->documentLayout()->setBlockChanges(wasBlockChanges);
}
}
painter.restore();
if (shape->stroke()) {
painter.save();
painter.setTransform(shape->absoluteTransformation(&converter) * baseMatrix);
shape->stroke()->paint(shape, painter, converter);
painter.restore();
}
}
} else {
示例4: drawDecorations
void KisCanvasWidgetBase::drawDecorations(QPainter & gc, const QRect &updateWidgetRect) const
{
gc.save();
if (!m_d->canvas) {
dbgFile<<"canvas doesn't exist, in canvas widget base!";
}
// Setup the painter to take care of the offset; all that the
// classes that do painting need to keep track of is resolution
gc.setRenderHint(QPainter::Antialiasing);
gc.setRenderHint(QPainter::TextAntialiasing);
// This option does not do anything anymore with Qt4.6, so don't reenable it since it seems to break display
// http://www.archivum.info/[email protected]/2010-01/00481/Re:-(Qt-interest)-Is-QPainter::HighQualityAntialiasing-render-hint-broken-in-Qt-4.6.html
// gc.setRenderHint(QPainter::HighQualityAntialiasing);
gc.setRenderHint(QPainter::SmoothPixmapTransform);
gc.save();
gc.setClipRect(updateWidgetRect);
QTransform transform = m_d->coordinatesConverter->flakeToWidgetTransform();
gc.setTransform(transform);
// Paint the shapes (other than the layers)
m_d->canvas->globalShapeManager()->paint(gc, *m_d->viewConverter, false);
// draw green selection outlines around text shapes that are edited, so the user sees where they end
gc.save();
QTransform worldTransform = gc.worldTransform();
gc.setPen( Qt::green );
Q_FOREACH (KoShape *shape, canvas()->shapeManager()->selection()->selectedShapes()) {
if (shape->shapeId() == "ArtisticText" || shape->shapeId() == "TextShapeID") {
gc.setWorldTransform(shape->absoluteTransformation(m_d->viewConverter) * worldTransform);
KoShape::applyConversion(gc, *m_d->viewConverter);
gc.drawRect(QRectF(QPointF(), shape->size()));
}
}
gc.restore();
// Draw text shape over canvas while editing it, that's needs to show the text selection correctly
QString toolId = KoToolManager::instance()->activeToolId();
if (toolId == "ArtisticTextTool" || toolId == "TextTool") {
gc.save();
gc.setPen(Qt::NoPen);
gc.setBrush(Qt::NoBrush);
Q_FOREACH (KoShape *shape, canvas()->shapeManager()->selection()->selectedShapes()) {
if (shape->shapeId() == "ArtisticText" || shape->shapeId() == "TextShapeID") {
KoShapePaintingContext paintContext(canvas(), false);
gc.save();
gc.setTransform(shape->absoluteTransformation(m_d->viewConverter) * gc.transform());
canvas()->shapeManager()->paintShape(shape, gc, *m_d->viewConverter, paintContext);
gc.restore();
}
}
gc.restore();
}
示例5: beginClip
void TextureMapperQt::beginClip(const TransformationMatrix& matrix, const FloatRect& rect)
{
QPainter* painter = currentPainter();
painter->save();
QTransform prevTransform = painter->transform();
painter->setTransform(matrix, false);
painter->setClipRect(rect);
painter->setTransform(prevTransform, false);
}
示例6: paint
void KoCreatePathTool::paint(QPainter &painter, const KoViewConverter &converter)
{
Q_D(KoCreatePathTool);
if (pathStarted()) {
KoShapeStroke *stroke(createStroke());
if (stroke) {
d->shape->setStroke(stroke);
}
painter.save();
paintPath(*(d->shape), painter, converter);
painter.restore();
painter.save();
painter.setTransform(d->shape->absoluteTransformation(&converter) * painter.transform());
KoShape::applyConversion(painter, converter);
painter.setPen(QPen(Qt::blue, 0));
painter.setBrush(Qt::white); //TODO make configurable
const bool firstPoint = (d->firstPoint == d->activePoint);
if (d->pointIsDragged || firstPoint) {
const bool onlyPaintActivePoints = false;
KoPathPoint::PointTypes paintFlags = KoPathPoint::ControlPoint2;
if (d->activePoint->activeControlPoint1())
paintFlags |= KoPathPoint::ControlPoint1;
d->activePoint->paint(painter, d->handleRadius, paintFlags, onlyPaintActivePoints);
}
// check if we have to color the first point
if (d->mouseOverFirstPoint)
painter.setBrush(Qt::red); //TODO make configurable
else
painter.setBrush(Qt::white); //TODO make configurable
d->firstPoint->paint(painter, d->handleRadius, KoPathPoint::Node);
painter.restore();
}
if (d->hoveredPoint) {
painter.save();
painter.setTransform(d->hoveredPoint->parent()->absoluteTransformation(&converter), true);
KoShape::applyConversion(painter, converter);
painter.setPen(QPen(Qt::blue, 0));
painter.setBrush(Qt::white); //TODO make configurable
d->hoveredPoint->paint(painter, d->handleRadius, KoPathPoint::Node);
painter.restore();
}
painter.save();
KoShape::applyConversion(painter, converter);
canvas()->snapGuide()->paint(painter, converter);
painter.restore();
}
示例7: drawUsingPainter
void PerspectivePixmap::drawUsingPainter(QPainter &painter)
{
if (!mPixMap.isNull()) {
qreal opOld = painter.opacity();
QTransform transOld = painter.transform();
QTransform trans = painter.transform();
trans.scale(1, -1);
painter.setTransform(trans);
painter.setOpacity(0.8);
painter.drawPixmap(-mXOffset / mScale, -mYOffset / mScale,
mPixMap.width() / mScale, mPixMap.height() / mScale, mPixMap);
painter.setOpacity(opOld);
painter.setTransform(transOld);
}
}
示例8: paintText
void PaintMethods::paintText(const DebugDrawing::Text& element, QPainter& painter)
{
QFont font("Arial", element.fontSize, QFont::Normal);
pen.setColor(QColor(element.penColor.r, element.penColor.g, element.penColor.b, element.penColor.a));
painter.setPen(pen);
painter.setFont(font);
QTransform trans(painter.transform());
QTransform newTrans;
newTrans.translate(trans.dx(), trans.dy());
newTrans.scale(std::abs(trans.m11()), std::abs(trans.m22()));
painter.setTransform(newTrans);
painter.drawText(QPoint(element.x * (int)sgn(trans.m11()), element.y * (int)sgn(trans.m22())), QObject::tr((const char*)(&element + 1)));
painter.setTransform(trans);
}
示例9: profiler
void
Panner::drawItems(QPainter *painter, int numItems,
QGraphicsItem *items[],
const QStyleOptionGraphicsItem options[])
{
Profiler profiler("Panner::drawItems");
if (m_cache.size() != viewport()->size()) {
QGraphicsScene *s = scene();
if (!s) return;
PannerScene *ps = static_cast<PannerScene *>(s);
m_cache = QPixmap(viewport()->size());
m_cache.fill(Qt::transparent);
QPainter cachePainter;
cachePainter.begin(&m_cache);
cachePainter.setTransform(viewportTransform());
ps->drawItems(&cachePainter, numItems, items, options);
cachePainter.end();
}
painter->save();
painter->setTransform(QTransform());
painter->drawPixmap(0, 0, m_cache);
painter->restore();
}
示例10: render
void QQuickShapeSoftwareRenderNode::render(const RenderState *state)
{
if (m_sp.isEmpty())
return;
QSGRendererInterface *rif = m_item->window()->rendererInterface();
QPainter *p = static_cast<QPainter *>(rif->getResource(m_item->window(), QSGRendererInterface::PainterResource));
Q_ASSERT(p);
const QRegion *clipRegion = state->clipRegion();
if (clipRegion && !clipRegion->isEmpty())
p->setClipRegion(*clipRegion, Qt::ReplaceClip); // must be done before setTransform
p->setTransform(matrix()->toTransform());
p->setOpacity(inheritedOpacity());
for (const ShapePathRenderData &d : qAsConst(m_sp)) {
if (d.hidden) {
continue;
}
// QTransform oldTransform = p->transform();
// p->setTransform(d.transform, true);
// p->setOpacity(inheritedOpacity() * d.opacity);
p->setPen(d.strokeWidth >= 0.0f && d.pen.color() != Qt::transparent ? d.pen : Qt::NoPen);
p->setBrush(d.brush.color() != Qt::transparent ? d.brush : Qt::NoBrush);
p->drawPath(d.path);
// p->setTransform(oldTransform);
}
}
示例11: rotarplayer
void girarder::rotarplayer(tam grados)
{
QPixmap sourceImage(*player->pixmap());
QPixmap rotatePixmap(sourceImage.size());
rotatePixmap.fill(Qt::transparent);
QTransform transform;
transform.translate(sourceImage.size().width() / 2, sourceImage.size().height() / 2);
transform.rotate(grados);
transform.translate(-sourceImage.size().width() / 2, -sourceImage.size().height() / 2);
QPainter p;
p.begin(&rotatePixmap);
p.setTransform(transform);
p.drawPixmap(0, 0, sourceImage);
p.end();
rotatePixmap.save(":/temp.png");
player->setPixmap(rotatePixmap);
player->giro = player->giro + grados;
}
示例12: paint
void KarbonCalligraphyTool::paint(QPainter &painter, const KoViewConverter &converter)
{
if (m_selectedPath) {
painter.save();
painter.setRenderHints(QPainter::Antialiasing, false);
painter.setPen(Qt::red); // TODO make configurable
QRectF rect = m_selectedPath->boundingRect();
QPointF p1 = converter.documentToView(rect.topLeft());
QPointF p2 = converter.documentToView(rect.bottomRight());
painter.drawRect(QRectF(p1, p2));
painter.restore();
}
if (!m_shape) {
return;
}
painter.save();
painter.setTransform(m_shape->absoluteTransformation(&converter) *
painter.transform());
KoShapePaintingContext paintContext; //FIXME
m_shape->paint(painter, converter, paintContext);
painter.restore();
}
示例13: textureSize
void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity)
{
m_context->markLayerComposited();
blitMultisampleFramebufferAndRestoreContext();
if (textureMapper->accelerationMode() == TextureMapper::OpenGLMode) {
TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper);
TextureMapperGL::Flags flags = TextureMapperGL::ShouldFlipTexture | (m_context->m_attrs.alpha ? TextureMapperGL::ShouldBlend : 0);
IntSize textureSize(m_context->m_currentWidth, m_context->m_currentHeight);
texmapGL->drawTexture(m_context->m_texture, flags, textureSize, targetRect, matrix, opacity);
return;
}
// Alternatively read pixels to a memory buffer.
GraphicsContext* context = textureMapper->graphicsContext();
QPainter* painter = context->platformContext();
painter->save();
painter->setTransform(matrix);
painter->setOpacity(opacity);
const int height = m_context->m_currentHeight;
const int width = m_context->m_currentWidth;
painter->beginNativePainting();
makeCurrentIfNeeded();
glBindFramebuffer(GL_FRAMEBUFFER, m_context->m_fbo);
QImage offscreenImage = qt_gl_read_framebuffer(QSize(width, height), true, true);
glBindFramebuffer(GL_FRAMEBUFFER, m_context->m_state.boundFBO);
painter->endNativePainting();
painter->drawImage(targetRect, offscreenImage);
painter->restore();
}
示例14: paintOrigin
void PaintMethods::paintOrigin(const DebugDrawing::Origin& element, QPainter& painter, const QTransform& baseTrans)
{
QTransform trans(baseTrans);
trans.translate(qreal(element.x), qreal(element.y));
trans.rotateRadians(qreal(element.angle));
painter.setTransform(trans);
}
示例15: paint
void MarkerMapObject::paint(QPainter &painter, QRect view, int scale) {
// Save the painter state for this paint session
// so that it can be restored after without influencing other objects
painter.save(); {
// Translate, scale, and rotate...
QTransform t;
t.scale(1.0/scale, 1.0/scale);
t.translate(x - view.x()*scale, view.height()*scale - y + view.y()*scale);
painter.setTransform(t);
for(int index = 0; index < transformationCount; index++) {
long arrowLength = 1000*scale;
long ballSize = 20*scale;
Vector2D a = transformation[index].trans();
Vector2D b = (transformation[index] * Trafo2D::trans(0, arrowLength)).trans();
painter.setPen(transformationColors[index]);
QPen pen = painter.pen();
pen.setWidth(2*scale);
painter.setPen(pen);
painter.drawLine(a.x(), -a.y(), b.x(), -b.y());
painter.setBrush(QBrush(transformationColors[index]));
painter.drawEllipse(a.x()-ballSize/2, -(a.y()+ballSize/2), ballSize, ballSize);
}
} painter.restore();
}