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

📄 qcommonstyle.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            } else {                const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, pb, widget);                int u;                if (unit_width > 1)                    u = (rect.width() + unit_width / 3) / unit_width;                else                    u = w / unit_width;                int p_v = pb->progress - pb->minimum;                int t_s = pb->maximum - pb->minimum ? pb->maximum - pb->minimum : 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 : fw)                                 : rect.x() + fw;                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(pbBits.rect);                    drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);                    x += reverse ? -unit_width : unit_width;                }                // Draw the last partial chunk to fill up the                // progressbar 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(pbBits.rect);                    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.intersect(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);            }            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) {                        int fh = p->fontMetrics().height();                        pr.adjust(0, 3, 0, -fh - 3);                        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, pr, Qt::AlignCenter, pm);                        } else {                            drawArrow(this, toolbutton, pr, p, widget);                        }                        alignment |= Qt::AlignLeft | Qt::AlignVCenter;                    }                    tr.translate(shiftX, shiftY);                    drawItemText(p, 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)) {            int d = 20 + tb->rect.height() - 3;            QPolygon a(7);            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);            p->setPen(tb->palette.mid().color().dark(150));            p->drawPolygon(a);            p->setPen(tb->palette.light().color());            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);            p->drawLine(tb->rect.width() - 20, tb->rect.height() - 1,                        tb->rect.width(), tb->rect.height() - 1);            p->setBrush(Qt::NoBrush);        }        break;#endif // QT_NO_TOOLBOX#ifndef QT_NO_TABBAR    case CE_TabBarTab:        if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {            drawControl(CE_TabBarTabShape, tab, p, widget);            drawControl(CE_TabBarTabLabel, tab, p, widget);        }        break;    case CE_TabBarTabShape:        if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {            p->save();            QRect rect(tab->rect);            bool selected = tab->state & State_Selected;            bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;            int tabOverlap = onlyOne ? 0 : pixelMetric(PM_TabBarTabOverlap, opt, widget);            if (!selected) {                switch (tab->shape) {                case QTabBar::TriangularNorth:                    rect.adjust(0, 0, 0, -tabOverlap);                    if(!selected)                        rect.adjust(1, 1, -1, 0);                    break;                case QTabBar::TriangularSouth:                    rect.adjust(0, tabOverlap, 0, 0);                    if(!selected)                        rect.adjust(1, 0, -1, -1);                    break;                case QTabBar::TriangularEast:                    rect.adjust(tabOverlap, 0, 0, 0);                    if(!selected)                        rect.adjust(0, 1, -1, -1);                    break;                case QTabBar::TriangularWest:                    rect.adjust(0, 0, -tabOverlap, 0);                    if(!selected)                        rect.adjust(1, 1, 0, -1);                    break;                default:                    break;                }            }            p->setPen(QPen(tab->palette.foreground(), 0));            if (selected) {                p->setBrush(tab->palette.base());            } else {                if (widget && widget->parentWidget())                    p->setBrush(widget->parentWidget()->palette().background());                else                    p->setBrush(tab->palette.background());            }            int y;            int x;            QPolygon a(10);            switch (tab->shape) {            case QTabBar::TriangularNorth:            case QTabBar::TriangularSouth: {                a.setPoint(0, 0, -1);                a.setPoint(1, 0, 0);                y = rect.height() - 2;                x = y / 3;                a.setPoint(2, x++, y - 1);                ++x;                a.setPoint(3, x++, y++);                a.setPoint(4, x, y);                int i;                int right = rect.width() - 1;                for (i = 0; i < 5; ++i)                    a.setPoint(9 - i, right - a.point(i).x(), a.point(i).y());                if (tab->shape == QTabBar::TriangularNorth)                    for (i = 0; i < 10; ++i)                        a.setPoint(i, a.point(i).x(), rect.height() - 1 - a.point(i).y());                a.translate(rect.left(), rect.top());                p->setRenderHint(QPainter::Antialiasing);                p->translate(0, 0.5);                QPainterPath path;                path.addPolygon(a);                p->drawPath(path);                break; }            case QTabBar::TriangularEast:            case QTabBar::TriangularWest: {                a.setPoint(0, -1, 0);                a.setPoint(1, 0, 0);                x = rect.width() - 2;                y = x / 3;                a.setPoint(2, x - 1, y++);                ++y;                a.setPoint(3, x++, y++);                a.setPoint(4, x, y);                int i;                int bottom = rect.height() - 1;                for (i = 0; i < 5; ++i)                    a.setPoint(9 - i, a.point(i).x(), bottom - a.point(i).y());                if (tab->shape == QTabBar::TriangularWest)                    for (i = 0; i < 10; ++i)                        a.setPoint(i, rect.width() - 1 - a.point(i).x(), a.point(i).y());                a.translate(rect.left(), rect.top());                p->setRenderHint(QPainter::Antialiasing);                p->translate(0.5, 0);                QPainterPath path;                path.addPolygon(a);                p->drawPath(path);                break; }            default:                break;            }            p->restore();        }        break;    case CE_TabBarTabLabel:        if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {            QStyleOptionTabV2 tabV2(*tab);            QRect tr = tabV2.rect;            bool verticalTabs = tabV2.shape == QTabBar::RoundedEast                                || tabV2.shape == QTabBar::RoundedWest                                || tabV2.shape == QTabBar::TriangularEast

⌨️ 快捷键说明

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