⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphicscontextqt.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    delete layer;}void GraphicsContext::clearRect(const FloatRect& rect){    if (paintingDisabled())        return;    QPainter *p = m_data->p();    QPainter::CompositionMode currentCompositionMode = p->compositionMode();    if (p->paintEngine()->hasFeature(QPaintEngine::PorterDuff))        p->setCompositionMode(QPainter::CompositionMode_Source);    p->fillRect(rect, Qt::transparent);    if (p->paintEngine()->hasFeature(QPaintEngine::PorterDuff))        p->setCompositionMode(currentCompositionMode);}void GraphicsContext::strokeRect(const FloatRect& rect, float width){    if (paintingDisabled())        return;    QPainterPath path;    path.addRect(rect);    setStrokeThickness(width);    m_data->currentPath = path;    strokePath();}void GraphicsContext::setLineCap(LineCap lc){    if (paintingDisabled())        return;    QPainter *p = m_data->p();    QPen nPen = p->pen();    nPen.setCapStyle(toQtLineCap(lc));    p->setPen(nPen);}void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset){    QPainter* p = m_data->p();    QPen pen = p->pen();    unsigned dashLength = dashes.size();    if (dashLength) {        QVector<qreal> pattern;        unsigned count = dashLength;        if (dashLength % 2)            count *= 2;        float penWidth = narrowPrecisionToFloat(double(pen.widthF()));        for (unsigned i = 0; i < count; i++)            pattern.append(dashes[i % dashLength] / penWidth);        pen.setDashPattern(pattern);        pen.setDashOffset(dashOffset);    }    p->setPen(pen);}void GraphicsContext::setLineJoin(LineJoin lj){    if (paintingDisabled())        return;    QPainter *p = m_data->p();    QPen nPen = p->pen();    nPen.setJoinStyle(toQtLineJoin(lj));    p->setPen(nPen);}void GraphicsContext::setMiterLimit(float limit){    if (paintingDisabled())        return;    QPainter *p = m_data->p();    QPen nPen = p->pen();    nPen.setMiterLimit(limit);    p->setPen(nPen);}void GraphicsContext::setAlpha(float opacity){    if (paintingDisabled())        return;    QPainter *p = m_data->p();    p->setOpacity(opacity);}void GraphicsContext::setCompositeOperation(CompositeOperator op){    if (paintingDisabled())        return;    if (m_data->p()->paintEngine()->hasFeature(QPaintEngine::PorterDuff))        m_data->p()->setCompositionMode(toQtCompositionMode(op));}void GraphicsContext::clip(const Path& path){    if (paintingDisabled())        return;    m_data->p()->setClipPath(*path.platformPath(), Qt::IntersectClip);}void GraphicsContext::clipOut(const Path& path){    if (paintingDisabled())        return;    QPainter *p = m_data->p();    QRectF clipBounds = p->clipPath().boundingRect();    QPainterPath clippedOut = *path.platformPath();    QPainterPath newClip;    newClip.setFillRule(Qt::OddEvenFill);    newClip.addRect(clipBounds);    newClip.addPath(clippedOut);    p->setClipPath(newClip, Qt::IntersectClip);}void GraphicsContext::translate(float x, float y){    if (paintingDisabled())        return;    m_data->p()->translate(x, y);    if (!m_data->currentPath.isEmpty()) {        QTransform matrix;        m_data->currentPath = m_data->currentPath * matrix.translate(-x, -y);        m_common->state.pathTransform.translate(x, y);    }}IntPoint GraphicsContext::origin(){    if (paintingDisabled())        return IntPoint();    const QTransform &transform = m_data->p()->transform();    return IntPoint(qRound(transform.dx()), qRound(transform.dy()));}void GraphicsContext::rotate(float radians){    if (paintingDisabled())        return;    m_data->p()->rotate(180/M_PI*radians);    if (!m_data->currentPath.isEmpty()) {        QTransform matrix;        m_data->currentPath = m_data->currentPath * matrix.rotate(-180/M_PI*radians);        m_common->state.pathTransform.rotate(radians);    }}void GraphicsContext::scale(const FloatSize& s){    if (paintingDisabled())        return;    m_data->p()->scale(s.width(), s.height());    if (!m_data->currentPath.isEmpty()) {        QTransform matrix;        m_data->currentPath = m_data->currentPath * matrix.scale(1 / s.width(), 1 / s.height());        m_common->state.pathTransform.scaleNonUniform(s.width(), s.height());    }}void GraphicsContext::clipOut(const IntRect& rect){    if (paintingDisabled())        return;    QPainter *p = m_data->p();    QRectF clipBounds = p->clipPath().boundingRect();    QPainterPath newClip;    newClip.setFillRule(Qt::OddEvenFill);    newClip.addRect(clipBounds);    newClip.addRect(QRect(rect));    p->setClipPath(newClip, Qt::IntersectClip);}void GraphicsContext::clipOutEllipseInRect(const IntRect& rect){    if (paintingDisabled())        return;    QPainter *p = m_data->p();    QRectF clipBounds = p->clipPath().boundingRect();    QPainterPath newClip;    newClip.setFillRule(Qt::OddEvenFill);    newClip.addRect(clipBounds);    newClip.addEllipse(QRect(rect));    p->setClipPath(newClip, Qt::IntersectClip);}void GraphicsContext::clipToImageBuffer(const FloatRect&, const ImageBuffer*){    notImplemented();}void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect,                                              int thickness){    if (paintingDisabled())        return;    clip(rect);    QPainterPath path;    // Add outer ellipse    path.addEllipse(QRectF(rect.x(), rect.y(), rect.width(), rect.height()));    // Add inner ellipse.    path.addEllipse(QRectF(rect.x() + thickness, rect.y() + thickness,                           rect.width() - (thickness * 2), rect.height() - (thickness * 2)));    path.setFillRule(Qt::OddEvenFill);    m_data->p()->setClipPath(path, Qt::IntersectClip);}void GraphicsContext::concatCTM(const TransformationMatrix& transform){    if (paintingDisabled())        return;    m_data->p()->setWorldTransform(transform, true);    // Transformations to the context shouldn't transform the currentPath.     // We have to undo every change made to the context from the currentPath to avoid wrong drawings.    if (!m_data->currentPath.isEmpty() && transform.isInvertible()) {        QTransform matrix = transform.inverse();        m_data->currentPath = m_data->currentPath * matrix;        m_common->state.pathTransform.multiply(transform);    }}void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect){    notImplemented();}void GraphicsContext::setPlatformStrokeColor(const Color& color){    if (paintingDisabled())        return;    QPainter *p = m_data->p();    QPen newPen(p->pen());    newPen.setColor(color);    p->setPen(newPen);}void GraphicsContext::setPlatformStrokeStyle(const StrokeStyle& strokeStyle){    if (paintingDisabled())        return;    QPainter *p = m_data->p();    QPen newPen(p->pen());    newPen.setStyle(toQPenStyle(strokeStyle));    p->setPen(newPen);}void GraphicsContext::setPlatformStrokeThickness(float thickness){    if (paintingDisabled())        return;    QPainter *p = m_data->p();    QPen newPen(p->pen());    newPen.setWidthF(thickness);    p->setPen(newPen);}void GraphicsContext::setPlatformFillColor(const Color& color){    if (paintingDisabled())        return;    m_data->p()->setBrush(QBrush(color));}void GraphicsContext::setPlatformShouldAntialias(bool enable){    if (paintingDisabled())        return;    m_data->p()->setRenderHint(QPainter::Antialiasing, enable);}#ifdef Q_WS_WIN#include <windows.h>HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap){    // painting through native HDC is only supported for plugin, where mayCreateBitmap is always true    Q_ASSERT(mayCreateBitmap);    if (dstRect.isEmpty())        return 0;    // Create a bitmap DC in which to draw.    BITMAPINFO bitmapInfo;    bitmapInfo.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);    bitmapInfo.bmiHeader.biWidth         = dstRect.width();    bitmapInfo.bmiHeader.biHeight        = dstRect.height();    bitmapInfo.bmiHeader.biPlanes        = 1;    bitmapInfo.bmiHeader.biBitCount      = 32;    bitmapInfo.bmiHeader.biCompression   = BI_RGB;    bitmapInfo.bmiHeader.biSizeImage     = 0;    bitmapInfo.bmiHeader.biXPelsPerMeter = 0;    bitmapInfo.bmiHeader.biYPelsPerMeter = 0;    bitmapInfo.bmiHeader.biClrUsed       = 0;    bitmapInfo.bmiHeader.biClrImportant  = 0;    void* pixels = 0;    HBITMAP bitmap = ::CreateDIBSection(NULL, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0);    if (!bitmap)        return 0;    HDC displayDC = ::GetDC(0);    HDC bitmapDC = ::CreateCompatibleDC(displayDC);    ::ReleaseDC(0, displayDC);    ::SelectObject(bitmapDC, bitmap);    // Fill our buffer with clear if we're going to alpha blend.    if (supportAlphaBlend) {        BITMAP bmpInfo;        GetObject(bitmap, sizeof(bmpInfo), &bmpInfo);        int bufferSize = bmpInfo.bmWidthBytes * bmpInfo.bmHeight;        memset(bmpInfo.bmBits, 0, bufferSize);    }#if !PLATFORM(WIN_CE)    // Make sure we can do world transforms.    SetGraphicsMode(bitmapDC, GM_ADVANCED);    // Apply a translation to our context so that the drawing done will be at (0,0) of the bitmap.    XFORM xform;    xform.eM11 = 1.0f;    xform.eM12 = 0.0f;    xform.eM21 = 0.0f;    xform.eM22 = 1.0f;    xform.eDx = -dstRect.x();    xform.eDy = -dstRect.y();    ::SetWorldTransform(bitmapDC, &xform);#endif    return bitmapDC;}void GraphicsContext::releaseWindowsContext(HDC hdc, const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap){    // painting through native HDC is only supported for plugin, where mayCreateBitmap is always true    Q_ASSERT(mayCreateBitmap);    if (hdc) {        if (!dstRect.isEmpty()) {            HBITMAP bitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP));            BITMAP info;            GetObject(bitmap, sizeof(info), &info);            ASSERT(info.bmBitsPixel == 32);            QPixmap pixmap = QPixmap::fromWinHBITMAP(bitmap, supportAlphaBlend ? QPixmap::PremultipliedAlpha : QPixmap::NoAlpha);            m_data->p()->drawPixmap(dstRect, pixmap);            ::DeleteObject(bitmap);        }        ::DeleteDC(hdc);    }}#endifvoid GraphicsContext::setImageInterpolationQuality(InterpolationQuality){}InterpolationQuality GraphicsContext::imageInterpolationQuality() const{    return InterpolationDefault;}}// vim: ts=4 sw=4 et

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -