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

📄 qstylesheetstyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        break;    case TileMode_Repeat:        if (!bi->topEdge.isNull())            qDrawCenterTiledPixmap(p, topEdgeRect, bi->topEdge);        if (!bi->bottomEdge.isNull())            qDrawCenterTiledPixmap(p, bottomEdgeRect, bi->bottomEdge);        if (bi->middleRect.isValid()) {            if (bi->vertStretch == TileMode_Repeat) {                qDrawCenterTiledPixmap(p, pr, bi->middle);            } else if (bi->vertStretch == TileMode_Stretch) {                QPixmap scaled = bi->middle.scaled(bi->middle.width(), int(pr.height()));                qDrawCenterTiledPixmap(p, pr, scaled);            }        }        break;    case TileMode_Round:        if (!bi->topEdge.isNull()) {            int rwh = (int)pr.width()/ceil(pr.width()/bi->topEdge.width());            QPixmap scaled = bi->topEdge.scaled(rwh, bi->topEdge.height());            int blank = int(pr.width()) % rwh;            p->drawTiledPixmap(QRectF(br.x() + l + blank/2, br.y(), pr.width() - blank, t),                               scaled);        }        if (!bi->bottomEdge.isNull()) {            int rwh = (int) pr.width()/ceil(pr.width()/bi->bottomEdge.width());            QPixmap scaled = bi->bottomEdge.scaled(rwh, bi->bottomEdge.height());            int blank = int(pr.width()) % rwh;            p->drawTiledPixmap(QRectF(br.x() + l+ blank/2, br.y()+br.height()-b,                                      pr.width() - blank, b), scaled);        }        break;    default:        break;    }    QRectF leftEdgeRect(br.x(), br.y() + t, l, pr.height());    QRectF rightEdgeRect(br.x() + br.width()- r, br.y() + t, r, pr.height());    switch (bi->vertStretch) {    case TileMode_Stretch:         if (bi->leftEdgeRect.isValid())              p->drawPixmap(leftEdgeRect, pix, bi->leftEdgeRect);        if (bi->rightEdgeRect.isValid())            p->drawPixmap(rightEdgeRect, pix, bi->rightEdgeRect);        break;    case TileMode_Repeat:        if (!bi->leftEdge.isNull())            qDrawCenterTiledPixmap(p, leftEdgeRect, bi->leftEdge);        if (!bi->rightEdge.isNull())            qDrawCenterTiledPixmap(p, rightEdgeRect, bi->rightEdge);        break;    case TileMode_Round:        if (!bi->leftEdge.isNull()) {            int rwh = (int) pr.height()/ceil(pr.height()/bi->leftEdge.height());            QPixmap scaled = bi->leftEdge.scaled(bi->leftEdge.width(), rwh);            int blank = int(pr.height()) % rwh;            p->drawTiledPixmap(QRectF(br.x(), br.y() + t + blank/2, l, pr.height() - blank),                               scaled);        }        if (!bi->rightEdge.isNull()) {            int rwh = (int) pr.height()/ceil(pr.height()/bi->rightEdge.height());            QPixmap scaled = bi->rightEdge.scaled(bi->rightEdge.width(), rwh);            int blank = int(pr.height()) % rwh;            p->drawTiledPixmap(QRectF(br.x() + br.width() - r, br.y()+t+blank/2, r,                                      pr.height() - blank), scaled);        }        break;    default:        break;    }    p->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothPixmapTransform);    unsetClip(p);}QRect QRenderRule::originRect(const QRect &rect, Origin origin) const{    switch (origin) {    case Origin_Padding:        return paddingRect(rect);    case Origin_Border:        return borderRect(rect);    case Origin_Content:        return contentsRect(rect);    case Origin_Margin:    default:        return rect;    }}void QRenderRule::drawBackgroundImage(QPainter *p, const QRect &rect, QPoint off){    if (!hasBackground())        return;    const QPixmap& bgp = background()->pixmap;    if (bgp.isNull())        return;    setClip(p, borderRect(rect));    if (background()->origin != background()->clip) {        p->save();        p->setClipRect(originRect(rect, background()->clip), Qt::IntersectClip);    }    if (background()->attachment == Attachment_Fixed)        off = QPoint(0, 0);    QRect r = originRect(rect, background()->origin);    QRect aligned = QStyle::alignedRect(Qt::LeftToRight, background()->position, bgp.size(), r);    QRect inter = aligned.intersected(r);    switch (background()->repeat) {    case Repeat_Y:        p->drawTiledPixmap(inter.x(), r.y(), inter.width(), r.height(), bgp,                           inter.x() - aligned.x() + off.x(),                           bgp.height() - int(aligned.y() - r.y()) % bgp.height() + off.y());        break;    case Repeat_X:        p->drawTiledPixmap(r.x(), inter.y(), r.width(), inter.height(), bgp,                           bgp.width() - int(aligned.x() - r.x())%bgp.width() + off.x(),                           inter.y() - aligned.y() + off.y());        break;    case Repeat_XY:        p->drawTiledPixmap(r, bgp,                           QPoint(bgp.width() - int(aligned.x() - r.x())% bgp.width() + off.x(),                                  bgp.height() - int(aligned.y() - r.y())%bgp.height() + off.y()));        break;    case Repeat_None:    default:        p->drawPixmap(inter.x(), inter.y(), bgp, inter.x() - aligned.x() + off.x(),                      inter.y() - aligned.y() + off.y(), inter.width(), inter.height());        break;    }    if (background()->origin != background()->clip)        p->restore();    unsetClip(p);}void QRenderRule::getRadii(const QRect &br, QSize *tlr, QSize *trr, QSize *blr, QSize *brr) const{    Q_ASSERT(hasBorder());    const QSize *radii = border()->radii;    *tlr = radii[0].expandedTo(QSize(0, 0));    *trr = radii[1].expandedTo(QSize(0, 0));    *blr = radii[2].expandedTo(QSize(0, 0));    *brr = radii[3].expandedTo(QSize(0, 0));    if (tlr->width() + trr->width() > br.width())        *tlr = *trr = QSize(0, 0);    if (blr->width() + brr->width() > br.width())        *blr = *brr = QSize(0, 0);    if (tlr->height() + blr->height() > br.height())        *tlr = *blr = QSize(0, 0);    if (trr->height() + brr->height() > br.height())        *trr = *brr = QSize(0, 0);}void QRenderRule::drawBorder(QPainter *p, const QRect& rect){    if (!hasBorder())        return;    const QRectF br(rect);    if (border()->hasBorderImage()) {        drawBorderImage(p, rect);        return;    }    const BorderStyle *styles = border()->styles;    const int *borders = border()->borders;    const QBrush *colors = border()->colors;    QSize tlr, trr, blr, brr;    getRadii(rect, &tlr, &trr, &blr, &brr);    bool wasAntialiased = p->renderHints() & QPainter::Antialiasing;    p->setRenderHint(QPainter::Antialiasing);    // Drawn in increasing order of precendence    if (styles[BottomEdge] != BorderStyle_None) {        qreal dw1 = (blr.width() || paintsOver(BottomEdge, LeftEdge)) ? 0 : borders[LeftEdge];        qreal dw2 = (brr.width() || paintsOver(BottomEdge, RightEdge)) ? 0 : borders[RightEdge];        qreal x1 = br.x() + blr.width();        qreal y1 = br.y() + br.height() - borders[BottomEdge];        qreal x2 = br.x() + br.width() - brr.width();        qreal y2 = br.y() + br.height() ;        qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, BottomEdge, styles[BottomEdge], colors[BottomEdge]);        if (blr.width() || brr.width())            qDrawRoundedCorners(p, x1, y1, x2, y2, blr, brr, BottomEdge, styles[BottomEdge], colors[BottomEdge]);    }    if (styles[RightEdge] != BorderStyle_None) {        qreal dw1 = (trr.height() || paintsOver(RightEdge, TopEdge)) ? 0 : borders[TopEdge];        qreal dw2 = (brr.height() || paintsOver(RightEdge, BottomEdge)) ? 0 : borders[BottomEdge];        qreal x1 = br.x() + br.width() - borders[RightEdge];        qreal y1 = br.y() + trr.height();        qreal x2 = br.x() + br.width();        qreal y2 = br.y() + br.height() - brr.height();        qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, RightEdge, styles[RightEdge], colors[RightEdge]);        if (trr.height() || brr.height())            qDrawRoundedCorners(p, x1, y1, x2, y2, trr, brr, RightEdge, styles[RightEdge], colors[RightEdge]);    }    if (styles[LeftEdge] != BorderStyle_None) {        qreal dw1 = (tlr.height() || paintsOver(LeftEdge, TopEdge)) ? 0 : borders[TopEdge];        qreal dw2 = (blr.height() || paintsOver(LeftEdge, BottomEdge)) ? 0 : borders[BottomEdge];        qreal x1 = br.x();        qreal y1 = br.y() + tlr.height();        qreal x2 = br.x() + borders[LeftEdge];        qreal y2 = br.y() + br.height() - blr.height();        qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, LeftEdge, styles[LeftEdge], colors[LeftEdge]);        if (tlr.height() || blr.height())            qDrawRoundedCorners(p, x1, y1, x2, y2, tlr, blr, LeftEdge, styles[LeftEdge], colors[LeftEdge]);    }    if (styles[TopEdge] != BorderStyle_None) {        qreal dw1 = (tlr.width() || paintsOver(TopEdge, LeftEdge)) ? 0 : borders[LeftEdge];        qreal dw2 = (trr.width() || paintsOver(TopEdge, RightEdge)) ? 0 : borders[RightEdge];        qreal x1 = br.x() + tlr.width();        qreal y1 = br.y();        qreal x2 = br.left() + br.width() - trr.width();        qreal y2 = br.y() + borders[TopEdge];        qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, TopEdge, styles[TopEdge], colors[TopEdge]);        if (tlr.width() || trr.width())            qDrawRoundedCorners(p, x1, y1, x2, y2, tlr, trr, TopEdge, styles[TopEdge], colors[TopEdge]);    }    p->setRenderHint(QPainter::Antialiasing, wasAntialiased);}QPainterPath QRenderRule::borderClip(QRect r){    if (!hasBorder())        return QPainterPath();    QSize tlr, trr, blr, brr;    getRadii(r, &tlr, &trr, &blr, &brr);    if (tlr.isNull() && trr.isNull() && blr.isNull() && brr.isNull())        return QPainterPath();    const QRectF rect(r);    const int *borders = border()->borders;    QPainterPath path;    qreal curY = rect.y() + borders[TopEdge]/2.0;    path.moveTo(rect.x() + tlr.width(), curY);    path.lineTo(rect.right() - trr.width(), curY);    qreal curX = rect.right() - borders[RightEdge]/2.0;    path.arcTo(curX - 2*trr.width() + borders[RightEdge], curY,               trr.width()*2 - borders[RightEdge], trr.height()*2 - borders[TopEdge], 90, -90);    path.lineTo(curX, rect.bottom() - brr.height());    curY = rect.bottom() - borders[BottomEdge]/2.0;    path.arcTo(curX - 2*brr.width() + borders[RightEdge], curY - 2*brr.height() + borders[BottomEdge],               brr.width()*2 - borders[RightEdge], brr.height()*2 - borders[BottomEdge], 0, -90);    path.lineTo(rect.x() + blr.width(), curY);    curX = rect.left() + borders[LeftEdge]/2.0;    path.arcTo(curX, rect.bottom() - 2*blr.height() + borders[BottomEdge]/2,               blr.width()*2 - borders[LeftEdge], blr.height()*2 - borders[BottomEdge], 270, -90);    path.lineTo(curX, rect.top() + tlr.height());    path.arcTo(curX, rect.top() + borders[TopEdge]/2,               tlr.width()*2 - borders[LeftEdge], tlr.height()*2 - borders[TopEdge], 180, -90);    path.closeSubpath();    return path;}void QRenderRule::setClip(QPainter *p, const QRect &rect){    if (clipset++)        return;    clipPath = borderClip(rect);    if (!clipPath.isEmpty()) {        p->save();        p->setClipPath(clipPath);    }}void QRenderRule::unsetClip(QPainter *p){    if (--clipset)        return;    if (!clipPath.isEmpty())        p->restore();}void QRenderRule::drawBackground(QPainter *p, const QRect& rect, const QPoint& off){    setClip(p, borderRect(rect));    QBrush brush = hasBackground() ? background()->brush : QBrush();    if (brush.style() == Qt::NoBrush)        brush = defaultBackground;    if (brush.style() != Qt::NoBrush) {        Origin origin = hasBackground() ? background()->clip : Origin_Border;        // ### fix for  gradients        p->fillRect(originRect(rect, origin), brush);    }    drawBackgroundImage(p, rect, off);    unsetClip(p);}void QRenderRule::drawFrame(QPainter *p, const QRect& rect){    drawBackground(p, rect);    if (hasBorder())        drawBorder(p, borderRect(rect));}void QRenderRule::drawImage(QPainter *p, const QRect &rect){    if (!hasImage())        return;    img->icon.paint(p, rect, img->alignment);}void QRenderRule::drawRule(QPainter *p, const QRect& rect){    drawFrame(p, rect);    drawImage(p, contentsRect(rect));}// *shudder* , *horror*, *whoa* <-- what you might feel when you see the functions belowvoid QRenderRule::configurePalette(QPalette *p, QPalette::ColorRole fr, QPalette::ColorRole br){    if (bg && bg->brush.style() != Qt::NoBrush) {        if (br != QPalette::NoRole)            p->setBrush(br, bg->brush);        p->setBrush(QPalette::Window, bg->brush);    }    if (!hasPalette())        return;    if (pal->foreground.style() != Qt::NoBrush) {        if (fr != QPalette::NoRole)            p->setBrush(fr, pal->foreground);        p->setBrush(QPalette::WindowText, pal->foreground);        p->setBrush(QPalette::Text, pal->foreground);    }

⌨️ 快捷键说明

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