Exemplo n.º 1
0
void QQuickContext2DTexture::paintWithoutTiles(QQuickContext2DCommandBuffer *ccb)
{
    if (!ccb || ccb->isEmpty())
        return;

    QPaintDevice* device = beginPainting();
    if (!device) {
        endPainting();
        return;
    }

    QPainter p;
    p.begin(device);
    if (m_antialiasing)
        p.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing, true);
    else
        p.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing, false);

    if (m_smooth)
        p.setRenderHint(QPainter::SmoothPixmapTransform, true);
    else
        p.setRenderHint(QPainter::SmoothPixmapTransform, false);

    p.setCompositionMode(QPainter::CompositionMode_SourceOver);

    ccb->replay(&p, m_state, scaleFactor());
    endPainting();
    markDirtyTexture();
}
Exemplo n.º 2
0
void Context2D::setShadowColor(const QString &str)
{
    m_state.shadowColor = colorFromString(str);
    if (m_painter.device() == &m_shadowbuffer && m_state.shadowBlur>0)
        endPainting();
    m_state.flags |= DirtyShadowColor;
}
Exemplo n.º 3
0
void PHIContext2D::scheduleChange()
{
    if ( _changeTimerId==-2 ) { // ServerScript
        emit changed( endPainting() );
    }
    if ( _changeTimerId==-1 ) _changeTimerId=startTimer( 0 );
}
Exemplo n.º 4
0
void Context2D::setSize(int width, int height)
{
    endPainting();
    m_width = width;
    m_height = height;

    scheduleChange();
}
Exemplo n.º 5
0
void Context2D::timerEvent(QTimerEvent *e)
{
    if (e->timerId() == m_changeTimerId) {
        killTimer(m_changeTimerId);
        m_changeTimerId = -1;
        emit changed(endPainting());
    } else {
        QObject::timerEvent(e);
    }
}
Exemplo n.º 6
0
void Context2D::setShadowBlur(qreal b)
{
    if (m_state.shadowBlur == b)
        return;
    m_state.shadowBlur = b;
    updateShadowBuffer();
    if (m_painter.device() == &m_shadowbuffer && m_state.shadowBlur>0)
        endPainting();
    m_state.flags |= DirtyShadowBlur;
}
Exemplo n.º 7
0
void Context2D::setShadowOffsetX(qreal x)
{
    if (m_state.shadowOffsetX == x)
        return;
    m_state.shadowOffsetX = x;
    updateShadowBuffer();
    if (m_painter.device() == &m_shadowbuffer && m_state.shadowBlur>0)
        endPainting();
    m_state.flags |= DirtyShadowOffsetX;
}
Exemplo n.º 8
0
void Context2D::setSize(int width, int height)
{
    endPainting();
    QImage newi(width, height, QImage::Format_ARGB32_Premultiplied);
    newi.fill(qRgba(0,0,0,0));
    QPainter p(&newi);
    p.drawImage(0, 0, m_image);
    p.end();
    m_image = newi;
    scheduleChange();
}
Exemplo n.º 9
0
void QQuickContext2DTexture::paint(QQuickContext2DCommandBuffer *ccb)
{
    QQuickContext2D::mutex.lock();
    if (canvasDestroyed()) {
        delete ccb;
        QQuickContext2D::mutex.unlock();
        return;
    }
    QQuickContext2D::mutex.unlock();
#if QT_CONFIG(opengl)
    GLAcquireContext currentContext(m_gl, m_surface);
#endif
    if (!m_tiledCanvas) {
        paintWithoutTiles(ccb);
        delete ccb;
        return;
    }

    QRect tiledRegion = createTiles(m_canvasWindow.intersected(QRect(QPoint(0, 0), m_canvasSize)));
    if (!tiledRegion.isEmpty()) {
        QRect dirtyRect;
        for (QQuickContext2DTile* tile : qAsConst(m_tiles)) {
            if (tile->dirty()) {
                if (dirtyRect.isEmpty())
                    dirtyRect = tile->rect();
                else
                    dirtyRect |= tile->rect();
            }
        }

        if (beginPainting()) {
            QQuickContext2D::State oldState = m_state;
            for (QQuickContext2DTile* tile : qAsConst(m_tiles)) {
                if (tile->dirty()) {
                    ccb->replay(tile->createPainter(m_smooth, m_antialiasing), oldState, scaleFactor());
                    tile->drawFinished();
                    tile->markDirty(false);
                }
                compositeTile(tile);
            }
            endPainting();
            m_state = oldState;
            markDirtyTexture();
        }
    }
    delete ccb;
}
Exemplo n.º 10
0
void Context2D::fillText(const QString &text, qreal x, qreal y)
{
    beginPainting();
    m_painter.save();
    m_painter.setPen(QPen(m_state.fillStyle, m_state.lineWidth));
    m_painter.setMatrix(worldMatrix(), false);
    QFont font;
    font.setBold(true);
    m_painter.setFont(m_state.font);
    int yoffset = baseLineOffset(m_state.textBaseline, m_painter.fontMetrics());
    int xoffset = textAlignOffset(m_state.textAlign, m_painter.fontMetrics(), text);
    QTextOption opt; // Adjust baseLine etc
    m_painter.drawText(QRectF(x-xoffset, y-yoffset, QWIDGETSIZE_MAX, m_painter.fontMetrics().height()), text, opt);
    m_painter.restore();
    endPainting();
    scheduleChange();
}
Exemplo n.º 11
0
void Context2D::strokeText(const QString &text, qreal x, qreal y)
{
    beginPainting();
    m_painter.save();
    m_painter.setPen(QPen(m_state.fillStyle,0));
    m_painter.setMatrix(worldMatrix(), false);

    QPainterPath textPath;
    QFont font = m_state.font;
    font.setStyleStrategy(QFont::ForceOutline);
    m_painter.setFont(font);
    const QFontMetrics &metrics = m_painter.fontMetrics();
    int yoffset = baseLineOffset(m_state.textBaseline, metrics);
    int xoffset = textAlignOffset(m_state.textAlign, metrics, text);
    textPath.addText(x-xoffset, y-yoffset+metrics.ascent(), font, text);
    m_painter.strokePath(textPath, QPen(m_state.fillStyle, m_state.lineWidth));
    m_painter.restore();
    endPainting();
    scheduleChange();
}
Exemplo n.º 12
0
void Context2D::clear()
{
    endPainting();
    m_image.fill(qRgba(0,0,0,0));
    scheduleChange();
}
/*!
    \since 4.3
    \overload

    This function will automatically call flush() to flush the
    \a region to the display before notifying the hardware, if
    necessary, that painting operations have ended.
*/
void QDirectPainter::endPainting(const QRegion &region)
{
    endPainting();
    flush(region);
}