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

📄 qcommonstyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                p->drawLine(tb->rect.width() - 20, tb->rect.height() - 1,                            tb->rect.width(), tb->rect.height() - 1);            } else {                p->drawLine(tb->rect.width() - 1, 2, d - 1, 2);                p->drawLine(d, 2, 20, tb->rect.height() - 1);                p->drawLine(19, tb->rect.height() - 1,                            -1, 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_ToolBoxTabLabel:        if (const QStyleOptionToolBox *tb = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) {            bool enabled = tb->state & State_Enabled;            bool selected = tb->state & State_Selected;            QPixmap pm = tb->icon.pixmap(pixelMetric(QStyle::PM_SmallIconSize, tb, widget),                                         enabled ? QIcon::Normal : QIcon::Disabled);            QRect cr = subElementRect(QStyle::SE_ToolBoxTabContents, tb, widget);            QRect tr, ir;            int ih = 0;            if (pm.isNull()) {                tr = cr;                tr.adjust(4, 0, -8, 0);            } else {                int iw = pm.width() + 4;                ih = pm.height();                ir = QRect(cr.left() + 4, cr.top(), iw + 2, ih);                tr = QRect(ir.right(), cr.top(), cr.width() - ir.right() - 4, cr.height());            }            if (selected && styleHint(QStyle::SH_ToolBox_SelectedPageTitleBold, tb, widget)) {                QFont f(p->font());                f.setBold(true);                p->setFont(f);            }            QString txt = tb->fontMetrics.elidedText(tb->text, Qt::ElideRight, tr.width());            if (ih)                p->drawPixmap(ir.left(), (tb->rect.height() - ih) / 2, pm);            int alignment = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic;            if (!styleHint(QStyle::SH_UnderlineShortcut, tb, widget))                alignment |= Qt::TextHideMnemonic;            drawItemText(p, tr, alignment, tb->palette, enabled, txt, QPalette::ButtonText);            if (!txt.isEmpty() && opt->state & State_HasFocus) {                QStyleOptionFocusRect opt;                opt.rect = tr;                opt.palette = tb->palette;                opt.state = QStyle::State_None;                drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, widget);            }        }        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                                || tabV2.shape == QTabBar::TriangularWest;            bool selected = tabV2.state & State_Selected;            if (verticalTabs) {                p->save();                int newX, newY, newRot;                if (tabV2.shape == QTabBar::RoundedEast || tabV2.shape == QTabBar::TriangularEast) {                    newX = tr.width();                    newY = tr.y();                    newRot = 90;                } else {                    newX = 0;                    newY = tr.y() + tr.height();                    newRot = -90;                }                tr.setRect(0, 0, tr.height(), tr.width());                QTransform m;                m.translate(newX, newY);                m.rotate(newRot);                p->setTransform(m, true);            }            tr.adjust(0, 0, pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget),                            pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget));            if (selected)            {                tr.setBottom(tr.bottom() - pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab,                                                    widget));                tr.setRight(tr.right() - pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab,                                                    widget));            }            int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;            if (!styleHint(SH_UnderlineShortcut, opt, widget))                alignment |= Qt::TextHideMnemonic;            if (!tabV2.icon.isNull()) {                QSize iconSize = tabV2.iconSize;                if (!iconSize.isValid()) {                    int iconExtent = pixelMetric(PM_SmallIconSize);                    iconSize = QSize(iconExtent, iconExtent);                }                QPixmap tabIcon = tabV2.icon.pixmap(iconSize,                                                    (tabV2.state & State_Enabled) ? QIcon::Normal                                                                                  : QIcon::Disabled);                p->drawPixmap(tr.left() + 6, tr.center().y() - tabIcon.height() / 2, tabIcon);                tr.setLeft(tr.left() + iconSize.width() + 4);            }            drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text, QPalette::WindowText);            if (verticalTabs)                p->restore();            if (tabV2.state & State_HasFocus) {                const int OFFSET = 1 + pixelMetric(PM_DefaultFrameWidth);                int x1, x2;                x1 = tabV2.rect.left();                x2 = tabV2.rect.right() - 1;                QStyleOptionFocusRect fropt;                fropt.QStyleOption::operator=(*tab);                fropt.rect.setRect(x1 + 1 + OFFSET, tabV2.rect.y() + OFFSET,                                   x2 - x1 - 2*OFFSET, tabV2.rect.height() - 2*OFFSET);                drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);            }        }        break;#endif // QT_NO_TABBAR#ifndef QT_NO_SIZEGRIP    case CE_SizeGrip: {        p->save();        int x, y, w, h;        opt->rect.getRect(&x, &y, &w, &h);        int sw = qMin(h, w);        if (h > w)            p->translate(0, h - w);        else            p->translate(w - h, 0);        int sx = x;        int sy = y;        int s = sw / 3;        Qt::Corner corner;        if (const QStyleOptionSizeGrip *sgOpt = qstyleoption_cast<const QStyleOptionSizeGrip *>(opt))            corner = sgOpt->corner;        else if (opt->direction == Qt::RightToLeft)            corner = Qt::BottomLeftCorner;        else            corner = Qt::BottomRightCorner;        if (corner == Qt::BottomLeftCorner) {            sx = x + sw;            for (int i = 0; i < 4; ++i) {                p->setPen(QPen(opt->palette.light().color(), 1));                p->drawLine(x, sy - 1 , sx + 1, sw);                p->setPen(QPen(opt->palette.dark().color(), 1));                p->drawLine(x, sy, sx, sw);                p->setPen(QPen(opt->palette.dark().color(), 1));                p->drawLine(x, sy + 1, sx - 1, sw);                sx -= s;                sy += s;            }        } else if (corner == Qt::BottomRightCorner) {            for (int i = 0; i < 4; ++i) {                p->setPen(QPen(opt->palette.light().color(), 1));                p->drawLine(sx - 1, sw, sw, sy - 1);                p->setPen(QPen(opt->palette.dark().color(), 1));                p->drawLine(sx, sw, sw, sy);                p->setPen(QPen(opt->palette.dark().color(), 1));                p->drawLine(sx + 1, sw, sw, sy + 1);                sx += s;                sy += s;            }        } else if (corner == Qt::TopRightCorner) {            sy = y + sw;            for (int i = 0; i < 4; ++i) {                p->setPen(QPen(opt->palette.light().color(), 1));                p->drawLine(sx - 1, y, sw, sy + 1);                p->setPen(QPen(opt->palette.dark().color(), 1));                p->drawLine(sx, y, sw, sy);                p->setPen(QPen(opt->

⌨️ 快捷键说明

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