Beispiel #1
0
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();
}
Beispiel #2
0
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);
}
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 {
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();
    }
Beispiel #5
0
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);
}
Beispiel #6
0
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();
}
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);
    }
}
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);
}
Beispiel #9
0
/*!
    Draws the first \a pointCount points in the buffer \a points
*/
void QPaintEngine::drawPoints(const QPointF *points, int pointCount)
{
    QPainter *p = painter();
    if (!p)
        return;

    qreal penWidth = p->pen().widthF();
    if (penWidth == 0)
        penWidth = 1;

    bool ellipses = p->pen().capStyle() == Qt::RoundCap;

    p->save();

    QTransform transform;
    if (qt_pen_is_cosmetic(p->pen(), p->renderHints())) {
        transform = p->transform();
        p->setTransform(QTransform());
    }

    p->setBrush(p->pen().brush());
    p->setPen(Qt::NoPen);

    for (int i=0; i<pointCount; ++i) {
        QPointF pos = transform.map(points[i]);
        QRectF rect(pos.x() - penWidth / 2, pos.y() - penWidth / 2, penWidth, penWidth);

        if (ellipses)
            p->drawEllipse(rect);
        else
            p->drawRect(rect);
    }

    p->restore();
}
Beispiel #10
0
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();
}
Beispiel #11
0
void KisInfinityManager::drawDecoration(QPainter& gc, const QRectF& updateArea, const KisCoordinatesConverter *converter, KisCanvas2 *canvas)
{
    Q_UNUSED(updateArea);
    Q_UNUSED(converter);
    Q_UNUSED(canvas);

    if (!m_filteringEnabled) return;

    gc.save();
    gc.setTransform(QTransform(), false);

    KisConfig cfg;
    QColor color = cfg.canvasBorderColor();
    gc.fillPath(m_decorationPath, color.darker(115));

    QPainterPath p;

    p.moveTo(5, 2);
    p.lineTo(-3, 8);
    p.lineTo(-5, 5);
    p.lineTo( 2, 0);
    p.lineTo(-5,-5);
    p.lineTo(-3,-8);
    p.lineTo( 5,-2);
    p.arcTo(QRectF(3, -2, 4, 4), 90, -180);

    foreach (const QTransform &t, m_handleTransform) {
        gc.fillPath(t.map(p), color);
    }
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);
    }
}
Beispiel #13
0
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;

}
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();
}
Beispiel #15
0
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();
}
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);
}
Beispiel #17
0
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();
}
Beispiel #18
0
void ImageWidget::paintDrawings(QPainter& painter)
{
  painter.scale(imageView.ddScale, imageView.ddScale);
  const QTransform baseTrans = QTransform(painter.transform());
  const std::list<std::string>& drawings = imageView.console.imageViews[imageView.name];
  for(const std::string& drawing : drawings)
  {
    auto& camDrawings = imageView.upperCam ? imageView.console.upperCamImageDrawings : imageView.console.lowerCamImageDrawings;
    auto debugDrawing = camDrawings.find(drawing);
    if(debugDrawing != camDrawings.end())
    {
      PaintMethods::paintDebugDrawing(painter, debugDrawing->second, baseTrans);
      if(debugDrawing->second.timeStamp > lastDrawingsTimeStamp)
        lastDrawingsTimeStamp = debugDrawing->second.timeStamp;
    }
    auto& motinoDrawings = imageView.console.motionImageDrawings;
    debugDrawing = motinoDrawings.find(drawing);
    if(debugDrawing != motinoDrawings.end())
    {
      PaintMethods::paintDebugDrawing(painter, debugDrawing->second, baseTrans);
      if(debugDrawing->second.timeStamp > lastDrawingsTimeStamp)
        lastDrawingsTimeStamp = debugDrawing->second.timeStamp;
    }
  }
  painter.setTransform(baseTrans);
}
Beispiel #19
0
void KoCreateShapeStrategy::paint(QPainter &painter, const KoViewConverter &converter)
{
    Q_D(KoShapeRubberSelectStrategy);
    if (m_outline.isEmpty())
        KoShapeRubberSelectStrategy::paint(painter, converter);
    else {
        painter.save();
        painter.setRenderHint(QPainter::Antialiasing, false);

        QColor selectColor(Qt::blue);   // TODO make configurable
        selectColor.setAlphaF(0.5);
        QBrush sb(selectColor, Qt::SolidPattern);
        painter.setPen(QPen(sb, 0));
        painter.setBrush(sb);
        QRectF paintRect = converter.documentToView(d->selectedRect());

        qreal xscale = paintRect.width() / m_outlineBoundingRect.width();
        qreal yscale = paintRect.height() / m_outlineBoundingRect.height();
        QTransform matrix;
        matrix.translate(-m_outlineBoundingRect.left(), -m_outlineBoundingRect.top());
        matrix.scale(xscale, yscale);
        painter.translate(paintRect.left(), paintRect.top());

        if (painter.hasClipping())
            paintRect = paintRect.intersect(painter.clipRegion().boundingRect());

        painter.setTransform(matrix, true);
        painter.drawPath(m_outline);
        painter.restore();
    }
}
Beispiel #20
0
void AdvancedImageWidget::drawResized(QPainter &painter)
{
    //qDebug("AdvancedImageWidget::drawResized():called");
    if (mImage.isNull())
    {
        qDebug("AdvancedImageWidget::drawResized():image is null");

        painter.drawText(0,0, this->width(), this->height(), Qt::AlignHCenter | Qt::AlignVCenter, QString("NO ACTIVE IMAGE"));
        return;
    }

    if (mUi->rotationComboBox->currentIndex() == 0)
    {
        painter.drawImage(mOutputRect, *mImage, mInputRect);
        return;
    }

//    qDebug() << "Input"  << mInputRect;
//    qDebug() << "Output" << mOutputRect;


    Matrix33 matrix = currentTransformMatrix();
//    cout << "Transfrom Matrix:\n" << matrix << std::endl << std::flush;
    QTransform transform = Core2Qt::QTransformFromMatrix(matrix);
//    qDebug() << "QTransfrom" << transform;



    QTransform old = painter.transform();
    painter.setTransform(transform, false);

    painter.drawImage(mOutputRect.topLeft(), *mImage, mImage->rect());

#if 0
    painter.setPen(Qt::red);
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            painter.drawPoint(i * 64, j * 48);
        }
    }
#endif

    painter.setTransform(old);

}
void KoShapeManagerPaintingStrategy::paint(KoShape * shape, QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintContext)
{
    if (d->shapeManager) {
        painter.save();
        painter.setTransform(shape->absoluteTransformation(&converter) * painter.transform());
        d->shapeManager->paintShape(shape, painter, converter, paintContext);
        painter.restore();  // for the matrix
    }
}
void ConnectionTool::paint(QPainter &painter, const KoViewConverter &converter)
{
    // get the correctly sized rect for painting handles
    QRectF handleRect = handlePaintRect(QPointF());

    painter.setRenderHint(QPainter::Antialiasing, true);

    if (m_currentStrategy) {
        painter.save();
        m_currentStrategy->paint(painter, converter);
        painter.restore();
    }

    QList<KoShape*> shapes = canvas()->shapeManager()->shapes();
    for (QList<KoShape*>::const_iterator end = shapes.constBegin(); end !=  shapes.constEnd(); ++end) {
        KoShape* shape = *end;
        if (!dynamic_cast<KoConnectionShape*>(shape)) {
            // only paint connection points of textShapes not inside a tos container and other shapes
            if (shape->shapeId() == TextShape_SHAPEID && dynamic_cast<KoTosContainer*>(shape->parent())) continue;

            painter.save();
            painter.setPen(Qt::black);
            QTransform transform = shape->absoluteTransformation(0);
            KoShape::applyConversion(painter, converter);
            // Draw all the connection points of the shape
            KoConnectionPoints connectionPoints = shape->connectionPoints();
            KoConnectionPoints::const_iterator cp = connectionPoints.constBegin();
            KoConnectionPoints::const_iterator lastCp = connectionPoints.constEnd();
            for(; cp != lastCp; ++cp) {
                if (shape == findNonConnectionShapeAtPosition(transform.map(cp.value().position)) ) {
                    handleRect.moveCenter(transform.map(cp.value().position));
                    painter.setBrush(cp.key() == m_activeHandle && shape == m_currentShape ?
                                     Qt::red : Qt::white);
                    painter.drawRect(handleRect);
                }
            }
            painter.restore();
        }
    }
    // paint connection points or connection handles depending
    // on the shape the mouse is currently
    if (m_currentShape && m_editMode == EditConnection) {
        KoConnectionShape *connectionShape = dynamic_cast<KoConnectionShape*>(m_currentShape);
        if (connectionShape) {
            int radius = handleRadius()+1;
            int handleCount = connectionShape->handleCount();
            for(int i = 0; i < handleCount; ++i) {
                painter.save();
                painter.setPen(Qt::blue);
                painter.setBrush(i == m_activeHandle ? Qt::red : Qt::white);
                painter.setTransform(connectionShape->absoluteTransformation(&converter) * painter.transform());
                connectionShape->paintHandle(painter, converter, i, radius);
                painter.restore();
            }
        }
    }
}
Beispiel #23
0
 void operator()
     ( QPainter & painter
     , const DrawTransform & t
     ) const
 {
     painter.save();
     painter.setTransform( t.t, true );
     draw( t.d, painter );
     painter.restore();
 }
Beispiel #24
0
static void drawTextEx(QPainter &p, const QRectF &r, int fl,
    const QString &s, bool mirrorX = 0, bool mirrorY = 0)
{
    QTransform t = p.transform();
    qreal hw = 0.5*r.width(), hh = 0.5*r.height();
    p.setTransform(QTransform(mirrorX ? -1:1, 0, 0, mirrorY ? -1:1, r.x() + hw, r.y() + hh), 1);
    if(mirrorX)
    {
        if(fl&Qt::AlignLeft) fl &= ~Qt::AlignLeft, fl |= Qt::AlignRight;
        else if(fl&Qt::AlignRight) fl &= ~Qt::AlignRight, fl |= Qt::AlignLeft;
    }
    if(mirrorY)
    {
        if(fl&Qt::AlignTop) fl &= ~Qt::AlignTop, fl |= Qt::AlignBottom;
        else if(fl&Qt::AlignBottom) fl &= ~Qt::AlignBottom, fl |= Qt::AlignTop;
    }
    p.drawText(QRect(-hw, -hh, r.width(), r.height()), fl, s);
    p.setTransform(t);
}
Beispiel #25
0
void SignalPlot::drawSignal(QPainter &painter)
{
    /*QPainter painter;
    painter.begin(this);*/


    int beginLine = 0,
            endLine = mChannelData[0].size();

    //painter.setClipRect(clippingRect);

    /*if(!clippingRect.isNull())
    {
        int leftBorder = std::max(clippingRect.left() - this->width()+mPlotArea.width(), 0);
        int rightBorder = std::min(clippingRect.right(), this->width());
        int length = rightBorder-leftBorder;
        beginLine = floor(leftBorder/length*mChannelData[0].size());
        endLine = ceil(rightBorder/length*mChannelData[0].size());
    }*/
    QTransform matrix;
    matrix.translate(
                    this->size().width() - mPlotArea.width(),
                    0
                );
    matrix.scale(
                    (qreal)mPlotArea.width()/mChannelData[0].size(),
                    1
                );

    painter.setTransform(matrix, true);
    painter.setPen(mLinesColor);

    for(int channel=0; channel<mChannels; ++channel)
    {
        int baseY = mPlotArea.height()/mChannels/2*(channel*2+1);

        int y = mChannelData[channel](beginLine)*mAmp;

        for(int i=beginLine+1; i<endLine; ++i)
        {
            int newY = mChannelData[channel](i)*mAmp;
            painter.drawLine(i-1, baseY+y, i, baseY+newY);
            y = newY;
        }
    }

    QPen pen(mTextColor);
    pen.setWidth(3);
    painter.setPen(pen);

    int pos = mChannelData[0].internalPos();
    painter.drawLine(pos, 0, pos, mPlotArea.height());

   // painter.end();
}
Beispiel #26
0
void
PictureZoneEditor::paintOverPictureMask(QPainter& painter)
{
	painter.setRenderHint(QPainter::Antialiasing);
	painter.setTransform(imageToVirtual() * virtualToWidget(), true);
	painter.setPen(Qt::NoPen);
	painter.setBrush(QColor(mask_color));

#ifndef Q_WS_X11
	// That's how it's supposed to be.
	painter.setCompositionMode(QPainter::CompositionMode_Clear);
#else
	// QPainter::CompositionMode_Clear doesn't work for arbitrarily shaped
	// objects on X11, as well as CompositionMode_Source with a transparent
	// brush.  Fortunately, CompositionMode_DestinationOut with a non-transparent
	// brush does actually work.
	painter.setCompositionMode(QPainter::CompositionMode_DestinationOut);
#endif

	typedef PictureLayerProperty PLP;

	// First pass: ERASER1
	BOOST_FOREACH(EditableZoneSet::Zone const& zone, m_zones) {
		if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::ERASER1) {
			painter.drawPolygon(zone.spline()->toPolygon(), Qt::WindingFill);
		}
	}

	painter.setCompositionMode(QPainter::CompositionMode_SourceOver);

	// Second pass: PAINTER2
	BOOST_FOREACH (EditableZoneSet::Zone const& zone, m_zones) {
		if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::PAINTER2) {
			painter.drawPolygon(zone.spline()->toPolygon(), Qt::WindingFill);
		}
	}

#ifndef Q_WS_X11
	// That's how it's supposed to be.
	painter.setCompositionMode(QPainter::CompositionMode_Clear);
#else
	// QPainter::CompositionMode_Clear doesn't work for arbitrarily shaped
	// objects on X11, as well as CompositionMode_Source with a transparent
	// brush.  Fortunately, CompositionMode_DestinationOut with a non-transparent
	// brush does actually work.
	painter.setCompositionMode(QPainter::CompositionMode_DestinationOut);
#endif

	// Third pass: ERASER1
	BOOST_FOREACH (EditableZoneSet::Zone const& zone, m_zones) {
		if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::ERASER3) {
			painter.drawPolygon(zone.spline()->toPolygon(), Qt::WindingFill);
		}
	}
}
void PaintMethods::paintEllipse(const DebugDrawing::Ellipse& element, QPainter& painter)
{
  setBrush(element.fillStyle, element.fillColor, painter);
  setPen(element, painter);

  if(element.rotation != 0.0f)
  {
    QTransform trans(painter.transform());
    QTransform transBack(painter.transform());
    trans.translate(qreal(element.x), qreal(element.y));
    trans.rotateRadians(qreal(element.rotation));
    painter.setTransform(trans);
    painter.drawEllipse(-element.radiusX, -element.radiusY, 2 * element.radiusX, 2 * element.radiusY);
    painter.setTransform(transBack);
  }
  else
  {
    painter.drawEllipse(element.x - element.radiusX, element.y - element.radiusY, 2 * element.radiusX, 2 * element.radiusY);
  }
}
void PaintMethods::paintRectangle(const DebugDrawing::Rectangle& element, QPainter& painter)
{
  setBrush(element.fillStyle, element.fillColor, painter);
  setPen(element, painter);

  const QRect dRect(element.topLX, element.topLY, element.w, element.h);

  if(element.rotation != 0.0f)
  {
    const QPoint center = dRect.center();
    QTransform trans(painter.transform());
    QTransform transBack(painter.transform());
    trans.translate(center.x(), center.y());
    trans.rotateRadians(qreal(element.rotation));
    painter.setTransform(trans);
    painter.drawRect(element.topLX - center.x(), element.topLY - center.y(), dRect.width(), dRect.height());
    painter.setTransform(transBack);
  }
  else
  {
    painter.drawRect(dRect);
  }
}
void KoShapeShadow::Private::paintGroupShadow(KoShapeGroup *group, QPainter &painter, const KoViewConverter &converter)
{
    QList<KoShape*> shapes = group->shapes();
    foreach(KoShape *child, shapes) {
        // we paint recursively here, so we do not have to check recursively for visibility
        if (!child->isVisible())
            continue;
        painter.save();
        //apply group child's transformation
        painter.setTransform(child->absoluteTransformation(&converter), true);
        paintShadow(child, painter, converter);
        painter.restore();
    }
}
void KoShapeShadow::paint(KoShape *shape, QPainter &painter, const KoViewConverter &converter)
{
    if (! d->visible)
        return;

    // So the approach we are taking here is to draw into a buffer image the size of boundingRect
    // We offset by the shadow offset at the time we draw into the buffer
    // Then we filter the image and draw it at the position of the bounding rect on canvas

    //the boundingRect of the shape or the KoSelection boundingRect of the group
    QRectF shadowRect = shape->boundingRect();
    QRectF zoomedClipRegion = converter.documentToView(shadowRect);

    // Init the buffer image
    QImage sourceGraphic(zoomedClipRegion.size().toSize(), QImage::Format_ARGB32_Premultiplied);
    sourceGraphic.fill(qRgba(0,0,0,0));
    // Init the buffer painter
    QPainter imagePainter(&sourceGraphic);
    imagePainter.setPen(Qt::NoPen);
    imagePainter.setBrush(Qt::NoBrush);
    imagePainter.setRenderHint(QPainter::Antialiasing, painter.testRenderHint(QPainter::Antialiasing));
    // Since our imagebuffer and the canvas don't align we need to offset our drawings
    imagePainter.translate(-1.0f*converter.documentToView(shadowRect.topLeft()));

    // Handle the shadow offset
    imagePainter.translate(converter.documentToView(offset()));

    KoShapeGroup *group = dynamic_cast<KoShapeGroup*>(shape);
    if (group) {
        d->paintGroupShadow(group, imagePainter, converter);
    } else {
        //apply shape's transformation
        imagePainter.setTransform(shape->absoluteTransformation(&converter), true);

        d->paintShadow(shape, imagePainter, converter);
    }
    imagePainter.end();

    // Blur the shadow (well the entire buffer)
    d->blurShadow(sourceGraphic, converter.documentToViewX(d->blur), d->color);

    // Paint the result
    painter.save();
    // The painter is initialized for us with canvas transform 'plus' shape transform
    // we are only interested in the canvas transform so 'subtract' the shape transform part
    painter.setTransform(shape->absoluteTransformation(&converter).inverted() * painter.transform());
    painter.drawImage(zoomedClipRegion.topLeft(), sourceGraphic);
    painter.restore();
}