📄 qcommonstyle.cpp
字号:
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 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); 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, ir.height() - 20, mbi, ir.height() - 4); drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget); } } break; case CE_PushButtonLabel: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { QRect ir = btn->rect; uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic; if (!styleHint(SH_UnderlineShortcut, btn, widget)) tf |= Qt::TextHideMnemonic; if (btn->state & (State_On | State_Sunken)) ir.translate(pixelMetric(PM_ButtonShiftHorizontal, opt, widget), pixelMetric(PM_ButtonShiftVertical, opt, widget)); if (!btn->icon.isNull()) { QIcon::Mode mode = btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; if (mode == QIcon::Normal && btn->state & State_HasFocus) mode = QIcon::Active; QIcon::State state = QIcon::Off; if (btn->state & State_On) state = QIcon::On; QPixmap pixmap = btn->icon.pixmap(btn->iconSize, mode, state); int pixw = pixmap.width(); int pixh = pixmap.height(); //Center the icon if there is no text QPoint point; if (btn->text.isEmpty()) { point = QPoint(ir.x() + ir.width() / 2 - pixw / 2, ir.y() + ir.height() / 2 - pixh / 2); } else { point = QPoint(ir.x() + 2, ir.y() + ir.height() / 2 - pixh / 2); } if (btn->direction == Qt::RightToLeft) point.rx() += pixw; if ((btn->state & (State_On | State_Sunken)) && btn->direction == Qt::RightToLeft) point.rx() -= pixelMetric(PM_ButtonShiftHorizontal, opt, widget) * 2; p->drawPixmap(visualPos(btn->direction, btn->rect, point), pixmap); if (btn->direction == Qt::RightToLeft) ir.translate(-4, 0); else ir.translate(pixw + 4, 0); ir.setWidth(ir.width() - (pixw + 4)); // left-align text if there is if (!btn->text.isEmpty()) tf |= Qt::AlignLeft; } else { tf |= Qt::AlignHCenter; } drawItemText(p, ir, tf, btn->palette, (btn->state & State_Enabled), btn->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::Foreground); } } 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); 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::Background)); 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 && ((pb->progress - pb->minimum) * 2 >= (pb->maximum - pb->minimum))) { textRole = QPalette::HighlightedText; } 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; // 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.left(), rect.top(), rect.height(), rect.width()); // flip width and height m.translate(rect.height(), 0.0); m.rotate(90); } 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 fw = 2; int w = rect.width() - 2 * fw; if (pb->minimum == 0 && pb->maximum == 0) { // draw busy indicator int x = (pb->progress - pb->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() + 1, x, rect.height() - fw);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -