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

📄 qcommonstyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            if (!pix.isNull())                drawItemPixmap(p,mbi->rect, alignment, pix);            else                drawItemText(p, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled,                             mbi->text, QPalette::ButtonText);        }        break;    case CE_MenuBarEmptyArea:        if (widget && !widget->testAttribute(Qt::WA_NoSystemBackground))            p->eraseRect(opt->rect);        break;#endif // QT_NO_MENUBAR#ifndef QT_NO_PROGRESSBAR    case CE_ProgressBar:        if (const QStyleOptionProgressBar *pb                = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {            QStyleOptionProgressBarV2 subopt = *pb;            subopt.rect = subElementRect(SE_ProgressBarGroove, pb, widget);            drawControl(CE_ProgressBarGroove, &subopt, p, widget);            subopt.rect = subElementRect(SE_ProgressBarContents, pb, widget);            drawControl(CE_ProgressBarContents, &subopt, p, widget);            if (pb->textVisible) {                subopt.rect = subElementRect(SE_ProgressBarLabel, pb, widget);                drawControl(CE_ProgressBarLabel, &subopt, p, widget);            }        }        break;    case CE_ProgressBarGroove:        qDrawShadePanel(p, opt->rect, opt->palette, true, 1,                        &opt->palette.brush(QPalette::Window));        break;    case CE_ProgressBarLabel:        if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {            bool vertical = false;            if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) {                vertical = (pb2->orientation == Qt::Vertical);            }            if (!vertical) {                QPalette::ColorRole textRole = QPalette::NoRole;                if ((pb->textAlignment & Qt::AlignCenter) && pb->textVisible                    && ((qint64(pb->progress) - qint64(pb->minimum)) * 2 >= (qint64(pb->maximum) - qint64(pb->minimum)))) {                    textRole = QPalette::HighlightedText;                    //Draw text shadow, This will increase readability when the background of same color                    QRect shadowRect(pb->rect);                    shadowRect.translate(1,1);                    QColor shadowColor = (pb->palette.color(textRole).value() <= 128)                       ? QColor(255,255,255,160) : QColor(0,0,0,160);                    QPalette shadowPalette = pb->palette;                    shadowPalette.setColor(textRole, shadowColor);                    drawItemText(p, shadowRect, Qt::AlignCenter | Qt::TextSingleLine, shadowPalette,                                 pb->state & State_Enabled, pb->text, textRole);                }                drawItemText(p, pb->rect, Qt::AlignCenter | Qt::TextSingleLine, pb->palette,                             pb->state & State_Enabled, pb->text, textRole);            }        }        break;    case CE_ProgressBarContents:        if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {            QRect rect = pb->rect;            bool vertical = false;            bool inverted = false;            qint64 minimum = qint64(pb->minimum);            qint64 maximum = qint64(pb->maximum);            qint64 progress = qint64(pb->progress);            // Get extra style options if version 2            const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt);            if (pb2) {                vertical = (pb2->orientation == Qt::Vertical);                inverted = pb2->invertedAppearance;            }            QMatrix m;            if (vertical) {                rect = QRect(rect.y(), rect.x(), rect.height(), rect.width()); // flip width and height                m.rotate(90);                m.translate(0, -(rect.height() + rect.y()*2));            }            QPalette pal2 = pb->palette;            // Correct the highlight color if it is the same as the background            if (pal2.highlight() == pal2.background())                pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,                                                                     QPalette::Highlight));            bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);            if (inverted)                reverse = !reverse;            int w = rect.width();            if (pb->minimum == 0 && pb->maximum == 0) {                // draw busy indicator                int x = (progress - minimum) % (w * 2);                if (x > w)                    x = 2 * w - x;                x = reverse ? rect.right() - x : x + rect.x();                p->setPen(QPen(pal2.highlight().color(), 4));                p->drawLine(x, rect.y(), x, rect.height());            } else {                const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, pb, widget);                if (!unit_width)                    return;                int u;                if (unit_width > 1)                    u = ((rect.width() + unit_width) / unit_width);                else                    u = w / unit_width;                qint64 p_v = progress - minimum;                qint64 t_s = (maximum - minimum) ? (maximum - minimum) : qint64(1);                if (u > 0 && p_v >= INT_MAX / u && t_s >= u) {                    // scale down to something usable.                    p_v /= u;                    t_s /= u;                }                // nu < tnu, if last chunk is only a partial chunk                int tnu, nu;                tnu = nu = p_v * u / t_s;                if (nu * unit_width > w)                    --nu;                // Draw nu units out of a possible u of unit_width                // width, each a rectangle bordered by background                // color, all in a sunken panel with a percentage text                // display at the end.                int x = 0;                int x0 = reverse ? rect.right() - ((unit_width > 1) ? unit_width : 0)                                 : rect.x();                QStyleOptionProgressBarV2 pbBits = *pb;                pbBits.rect = rect;                pbBits.palette = pal2;                int myY = pbBits.rect.y();                int myHeight = pbBits.rect.height();                pbBits.state = State_None;                for (int i = 0; i < nu; ++i) {                    pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);                    pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();                    drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);                    x += reverse ? -unit_width : unit_width;                }                // Draw the last partial chunk to fill up the                // progress bar entirely                if (nu < tnu) {                    int pixels_left = w - (nu * unit_width);                    int offset = reverse ? x0 + x + unit_width-pixels_left : x0 + x;                    pbBits.rect.setRect(offset, myY, pixels_left, myHeight);                    pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();                    drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);                }            }        }        break;#endif // QT_NO_PROGRESSBAR    case CE_HeaderLabel:        if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {            QRect rect = header->rect;            if (!header->icon.isNull()) {                QPixmap pixmap                    = header->icon.pixmap(pixelMetric(PM_SmallIconSize), (header->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);                int pixw = pixmap.width();                QRect aligned = alignedRect(header->direction, QFlag(header->iconAlignment), pixmap.size(), rect);                QRect inter = aligned.intersected(rect);                p->drawPixmap(inter.x(), inter.y(), pixmap, inter.x() - aligned.x(), inter.y() - aligned.y(), inter.width(), inter.height());                if (header->direction == Qt::LeftToRight)                    rect.setLeft(rect.left() + pixw + 2);                else                    rect.setRight(rect.right() - pixw - 2);            }            if (header->state & QStyle::State_On) {                QFont fnt = p->font();                fnt.setBold(true);                p->setFont(fnt);            }            drawItemText(p, rect, header->textAlignment, header->palette,                         (header->state & State_Enabled), header->text, QPalette::ButtonText);        }        break;#ifndef QT_NO_TOOLBUTTON    case CE_ToolButtonLabel:        if (const QStyleOptionToolButton *toolbutton                = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {            QRect rect = toolbutton->rect;            int shiftX = 0;            int shiftY = 0;            if (toolbutton->state & (State_Sunken | State_On)) {                shiftX = pixelMetric(PM_ButtonShiftHorizontal, toolbutton, widget);                shiftY = pixelMetric(PM_ButtonShiftVertical, toolbutton, widget);            }            // Arrow type always overrules and is always shown            bool hasArrow = toolbutton->features & QStyleOptionToolButton::Arrow;            if ((!hasArrow && toolbutton->icon.isNull()) && !toolbutton->text.isEmpty()                || toolbutton->toolButtonStyle == Qt::ToolButtonTextOnly) {                int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;                if (!styleHint(SH_UnderlineShortcut, opt, widget))                    alignment |= Qt::TextHideMnemonic;                rect.translate(shiftX, shiftY);                drawItemText(p, rect, alignment, toolbutton->palette,                             opt->state & State_Enabled, toolbutton->text,                             QPalette::ButtonText);            } else {                QPixmap pm;                QSize pmSize = toolbutton->iconSize;                if (!toolbutton->icon.isNull()) {                    QIcon::State state = toolbutton->state & State_On ? QIcon::On : QIcon::Off;                    QIcon::Mode mode;                    if (!(toolbutton->state & State_Enabled))                        mode = QIcon::Disabled;                    else if ((opt->state & State_MouseOver) && (opt->state & State_AutoRaise))                        mode = QIcon::Active;                    else                        mode = QIcon::Normal;                    pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize),                                                 mode, state);                    pmSize = pm.size();                }                if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) {                    p->setFont(toolbutton->font);                    QRect pr = rect,                    tr = rect;                    int alignment = Qt::TextShowMnemonic;                    if (!styleHint(SH_UnderlineShortcut, opt, widget))                        alignment |= Qt::TextHideMnemonic;                    if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {                        pr.setHeight(pmSize.height() + 6);                        tr.adjust(0, pr.bottom(), 0, -3);                        pr.translate(shiftX, shiftY);                        if (!hasArrow) {                            drawItemPixmap(p, pr, Qt::AlignCenter, pm);                        } else {                            drawArrow(this, toolbutton, pr, p, widget);                        }                        alignment |= Qt::AlignCenter;                    } else {                        pr.setWidth(pmSize.width() + 8);                        tr.adjust(pr.right(), 0, 0, 0);                        pr.translate(shiftX, shiftY);                        if (!hasArrow) {                            drawItemPixmap(p, QStyle::visualRect(opt->direction, rect, pr), Qt::AlignCenter, pm);                        } else {                            drawArrow(this, toolbutton, pr, p, widget);                        }                        alignment |= Qt::AlignLeft | Qt::AlignVCenter;                    }                    tr.translate(shiftX, shiftY);                    drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette,                                 toolbutton->state & State_Enabled, toolbutton->text,                                 QPalette::ButtonText);                } else {                    rect.translate(shiftX, shiftY);                    if (hasArrow) {                        drawArrow(this, toolbutton, rect, p, widget);                    } else {                        drawItemPixmap(p, rect, Qt::AlignCenter, pm);                    }                }            }        }        break;#endif // QT_NO_TOOLBUTTON#ifndef QT_NO_TOOLBOX    case CE_ToolBoxTab:        if (const QStyleOptionToolBox *tb = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) {            drawControl(CE_ToolBoxTabShape, tb, p, widget);            drawControl(CE_ToolBoxTabLabel, tb, p, widget);        }        break;    case CE_ToolBoxTabShape:        if (const QStyleOptionToolBox *tb = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) {            int d = 20 + tb->rect.height() - 3;            QPolygon a(7);            if (tb->direction != Qt::RightToLeft) {                a.setPoint(0, -1, tb->rect.height() + 1);                a.setPoint(1, -1, 1);                a.setPoint(2, tb->rect.width() - d, 1);                a.setPoint(3, tb->rect.width() - 20, tb->rect.height() - 2);                a.setPoint(4, tb->rect.width() - 1, tb->rect.height() - 2);                a.setPoint(5, tb->rect.width() - 1, tb->rect.height() + 1);                a.setPoint(6, -1, tb->rect.height() + 1);            } else {                a.setPoint(0, tb->rect.width(), tb->rect.height() + 1);                a.setPoint(1, tb->rect.width(), 1);                a.setPoint(2, d - 1, 1);                a.setPoint(3, 20 - 1, tb->rect.height() - 2);                a.setPoint(4, 0, tb->rect.height() - 2);                a.setPoint(5, 0, tb->rect.height() + 1);                a.setPoint(6, tb->rect.width(), tb->rect.height() + 1);            }            p->setPen(tb->palette.mid().color().darker(150));            p->drawPolygon(a);            p->setPen(tb->palette.light().color());            if (tb->direction != Qt::RightToLeft) {                p->drawLine(0, 2, tb->rect.width() - d, 2);                p->drawLine(tb->rect.width() - d - 1, 2, tb->rect.width() - 21, tb->rect.height() - 1);

⌨️ 快捷键说明

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