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

📄 qcommonstyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        p->setBrush(opt->palette.background());        p->drawRect(opt->rect.adjusted(0, 0, -1, -1));        p->setPen(oldPen);        p->setBrush(oldBrush);        break;    }#ifndef QT_NO_TABBAR    case PE_IndicatorTabTear:        if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {            bool rtl = tab->direction == Qt::RightToLeft;            QRect rect = tab->rect;            QPainterPath path;            rect.setTop(rect.top() + ((tab->state & State_Selected) ? 1 : 3));            rect.setBottom(rect.bottom() - ((tab->state & State_Selected) ? 0 : 2));            path.moveTo(QPoint(rtl ? rect.right() : rect.left(), rect.top()));            int count = 4;            for(int jags = 1; jags <= count; ++jags, rtl = !rtl)                path.lineTo(QPoint(rtl ? rect.left() : rect.right(), rect.top() + jags * rect.height()/count));            p->setPen(QPen(tab->palette.light(), .8));            p->setBrush(tab->palette.background());            p->setRenderHint(QPainter::Antialiasing);            p->drawPath(path);        }        break;#endif // QT_NO_TABBAR#ifndef QT_NO_LINEEDIT    case PE_PanelLineEdit:        if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {            p->fillRect(panel->rect.adjusted(panel->lineWidth, panel->lineWidth, -panel->lineWidth, -panel->lineWidth),                        panel->palette.brush(QPalette::Base));            if (panel->lineWidth > 0)                drawPrimitive(PE_FrameLineEdit, panel, p, widget);        }        break;#endif // QT_NO_LINEEDIT    case PE_IndicatorColumnViewArrow: {    if (const QStyleOptionViewItem *viewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {        bool reverse = (viewOpt->direction == Qt::RightToLeft);        p->save();        QPainterPath path;        int x = viewOpt->rect.x() + 1;        int offset = (viewOpt->rect.height() / 3);        int height = (viewOpt->rect.height()) - offset * 2;        if (height % 2 == 1)            --height;        int x2 = x + height - 1;        if (reverse) {            x = viewOpt->rect.x() + viewOpt->rect.width() - 1;            x2 = x - height + 1;        }        path.moveTo(x, viewOpt->rect.y() + offset);        path.lineTo(x, viewOpt->rect.y() + offset + height);        path.lineTo(x2, viewOpt->rect.y() + offset+height/2);        path.closeSubpath();        if (viewOpt->state & QStyle::State_Selected ) {            if (viewOpt->showDecorationSelected) {                QColor color = viewOpt->palette.color(QPalette::Active, QPalette::HighlightedText);                p->setPen(color);                p->setBrush(color);            } else {                QColor color = viewOpt->palette.color(QPalette::Active, QPalette::WindowText);                p->setPen(color);                p->setBrush(color);            }        } else {            QColor color = viewOpt->palette.color(QPalette::Active, QPalette::Mid);            p->setPen(color);            p->setBrush(color);        }        p->drawPath(path);        // draw the vertical and top triangle line        if (!(viewOpt->state & QStyle::State_Selected)) {            QPainterPath lines;            lines.moveTo(x, viewOpt->rect.y() + offset);            lines.lineTo(x, viewOpt->rect.y() + offset + height);            lines.moveTo(x, viewOpt->rect.y() + offset);            lines.lineTo(x2, viewOpt->rect.y() + offset+height/2);            QColor color = viewOpt->palette.color(QPalette::Active, QPalette::Dark);            p->setPen(color);            p->drawPath(lines);        }        p->restore();    }    break; }    default:        break;    }}#ifndef QT_NO_TOOLBUTTONstatic void drawArrow(const QStyle *style, const QStyleOptionToolButton *toolbutton,                      const QRect &rect, QPainter *painter, const QWidget *widget = 0){    QStyle::PrimitiveElement pe;    switch (toolbutton->arrowType) {    case Qt::LeftArrow:        pe = QStyle::PE_IndicatorArrowLeft;        break;    case Qt::RightArrow:        pe = QStyle::PE_IndicatorArrowRight;        break;    case Qt::UpArrow:        pe = QStyle::PE_IndicatorArrowUp;        break;    case Qt::DownArrow:        pe = QStyle::PE_IndicatorArrowDown;        break;    default:        return;    }    QStyleOption arrowOpt;    arrowOpt.rect = rect;    arrowOpt.palette = toolbutton->palette;    arrowOpt.state = toolbutton->state;    style->drawPrimitive(pe, &arrowOpt, painter, widget);}#endif // QT_NO_TOOLBUTTON/*!  \reimp*/void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,                               QPainter *p, const QWidget *widget) const{    switch (element) {    case CE_PushButton:        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {            drawControl(CE_PushButtonBevel, btn, p, widget);            QStyleOptionButton subopt = *btn;            subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);            drawControl(CE_PushButtonLabel, &subopt, p, widget);            if (btn->state & State_HasFocus) {                QStyleOptionFocusRect fropt;                fropt.QStyleOption::operator=(*btn);                fropt.rect = subElementRect(SE_PushButtonFocusRect, btn, widget);                drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);            }        }        break;    case CE_PushButtonBevel:        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {            QRect br = btn->rect;            int dbi = pixelMetric(PM_ButtonDefaultIndicator, btn, widget);            if (btn->features & QStyleOptionButton::DefaultButton)                drawPrimitive(PE_FrameDefaultButton, opt, p, widget);            if (btn->features & QStyleOptionButton::AutoDefaultButton)                br.setCoords(br.left() + dbi, br.top() + dbi, br.right() - dbi, br.bottom() - dbi);            if (!(btn->features & (QStyleOptionButton::Flat | QStyleOptionButton::CommandLinkButton))                || btn->state & (State_Sunken | State_On)                || (btn->features & QStyleOptionButton::CommandLinkButton && btn->state & State_MouseOver)) {                QStyleOptionButton tmpBtn = *btn;                tmpBtn.rect = br;                drawPrimitive(PE_PanelButtonCommand, &tmpBtn, p, widget);            }            if (btn->features & QStyleOptionButton::HasMenu) {                int mbi = pixelMetric(PM_MenuButtonIndicator, btn, widget);                QRect ir = btn->rect;                QStyleOptionButton newBtn = *btn;                newBtn.rect = QRect(ir.right() - mbi + 2, ir.height()/2 - mbi/2 + 3, mbi - 6, mbi - 6);                drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget);            }        }        break; case CE_PushButtonLabel:        if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(opt)) {            QRect textRect = button->rect;            uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic;            if (!styleHint(SH_UnderlineShortcut, button, widget))                tf |= Qt::TextHideMnemonic;            if (!button->icon.isNull()) {                //Center both icon and text                QRect iconRect;                QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;                if (mode == QIcon::Normal && button->state & State_HasFocus)                    mode = QIcon::Active;                QIcon::State state = QIcon::Off;                if (button->state & State_On)                    state = QIcon::On;                QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state);                int labelWidth = pixmap.width();                int labelHeight = pixmap.height();                int iconSpacing = 4;//### 4 is currently hardcoded in QPushButton::sizeHint()                int textWidth = button->fontMetrics.boundingRect(opt->rect, tf, button->text).width();                if (!button->text.isEmpty())                    labelWidth += (textWidth + iconSpacing);                iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2,                                 textRect.y() + (textRect.height() - labelHeight) / 2,                                 pixmap.width(), pixmap.height());                iconRect = visualRect(button->direction, textRect, iconRect);                tf |= Qt::AlignLeft; //left align, we adjust the text-rect instead                if (button->direction == Qt::RightToLeft)                    textRect.setRight(iconRect.left() - iconSpacing);                else                    textRect.setLeft(iconRect.left() + iconRect.width() + iconSpacing);                if (button->state & (State_On | State_Sunken))                    iconRect.translate(pixelMetric(PM_ButtonShiftHorizontal, opt, widget),                                       pixelMetric(PM_ButtonShiftVertical, opt, widget));                p->drawPixmap(iconRect, pixmap);            } else {                tf |= Qt::AlignHCenter;            }            if (button->state & (State_On | State_Sunken))                textRect.translate(pixelMetric(PM_ButtonShiftHorizontal, opt, widget),                             pixelMetric(PM_ButtonShiftVertical, opt, widget));            if (button->features & QStyleOptionButton::HasMenu) {                int indicatorSize = pixelMetric(PM_MenuButtonIndicator, button, widget);                if (button->direction == Qt::LeftToRight)                    textRect = textRect.adjusted(0, 0, -indicatorSize, 0);                else                    textRect = textRect.adjusted(indicatorSize, 0, 0, 0);            }            drawItemText(p, textRect, tf, button->palette, (button->state & State_Enabled),                         button->text, QPalette::ButtonText);        }        break;    case CE_RadioButton:    case CE_CheckBox:        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {            bool isRadio = (element == CE_RadioButton);            QStyleOptionButton subopt = *btn;            subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator                                                 : SE_CheckBoxIndicator, btn, widget);            drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox,                          &subopt, p, widget);            subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents                                                 : SE_CheckBoxContents, btn, widget);            drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, p, widget);            if (btn->state & State_HasFocus) {                QStyleOptionFocusRect fropt;                fropt.QStyleOption::operator=(*btn);                fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect                                                    : SE_CheckBoxFocusRect, btn, widget);                drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);            }        }        break;    case CE_RadioButtonLabel:    case CE_CheckBoxLabel:        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {            uint alignment = visualAlignment(btn->direction, Qt::AlignLeft | Qt::AlignVCenter);            if (!styleHint(SH_UnderlineShortcut, btn, widget))                alignment |= Qt::TextHideMnemonic;            QPixmap pix;            QRect textRect = btn->rect;            if (!btn->icon.isNull()) {                pix = btn->icon.pixmap(btn->iconSize, btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled);                drawItemPixmap(p, btn->rect, alignment, pix);                if (btn->direction == Qt::RightToLeft)                    textRect.setRight(textRect.right() - btn->iconSize.width() - 4);                else                    textRect.setLeft(textRect.left() + btn->iconSize.width() + 4);            }            if (!btn->text.isEmpty()){                drawItemText(p, textRect, alignment | Qt::TextShowMnemonic,                    btn->palette, btn->state & State_Enabled, btn->text, QPalette::WindowText);            }        }        break;#ifndef QT_NO_MENU    case CE_MenuScroller: {        p->fillRect(opt->rect, opt->palette.background());        QStyleOption arrowOpt = *opt;        arrowOpt.state |= State_Enabled;        drawPrimitive(((opt->state & State_DownArrow) ? PE_IndicatorArrowDown : PE_IndicatorArrowUp),                    &arrowOpt, p, widget);        break; }    case CE_MenuTearoff:        if (opt->state & State_Selected)            p->fillRect(opt->rect, opt->palette.brush(QPalette::Highlight));        else            p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));        p->setPen(QPen(opt->palette.dark().color(), 1, Qt::DashLine));        p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2 - 1,                    opt->rect.x() + opt->rect.width() - 4,                    opt->rect.y() + opt->rect.height() / 2 - 1);        p->setPen(QPen(opt->palette.light().color(), 1, Qt::DashLine));        p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2,                    opt->rect.x() + opt->rect.width() - 4, opt->rect.y() + opt->rect.height() / 2);        break;#endif // QT_NO_MENU#ifndef QT_NO_MENUBAR    case CE_MenuBarItem:        if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {            uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip                            | Qt::TextSingleLine;            if (!styleHint(SH_UnderlineShortcut, mbi, widget))                alignment |= Qt::TextHideMnemonic;            QPixmap pix = mbi->icon.pixmap(pixelMetric(PM_SmallIconSize), (mbi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);

⌨️ 快捷键说明

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