📄 qcommonstyle.cpp
字号:
|| 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()); QMatrix m; m.translate(newX, newY); m.rotate(newRot); p->setMatrix(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); } if (verticalTabs){ QPixmap pixmap(tr.size()); pixmap.fill(Qt::transparent); QPainter pixPainter(&pixmap); drawItemText(&pixPainter, pixmap.rect(), alignment, tab->palette, tab->state & State_Enabled, tab->text, QPalette::Foreground); drawItemPixmap(p,tr,alignment,pixmap); p->restore(); } else { drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text, QPalette::Foreground); } 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; if (opt->direction == Qt::RightToLeft) { 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 { 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; } } p->restore(); break; }#endif // QT_NO_SIZEGRIP#ifndef QT_NO_RUBBERBAND case CE_RubberBand: { if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) { QPixmap tiledPixmap(16, 16); QPainter pixmapPainter(&tiledPixmap); pixmapPainter.setPen(Qt::NoPen); pixmapPainter.setBrush(Qt::Dense4Pattern); pixmapPainter.setBackground(QBrush(opt->palette.base())); pixmapPainter.setBackgroundMode(Qt::OpaqueMode); pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height()); pixmapPainter.end(); // ### workaround for borked XRENDER tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage()); p->save(); QRect r = opt->rect; QStyleHintReturnMask mask; if (styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask)) p->setClipRegion(mask.region); p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap); p->setPen(opt->palette.color(QPalette::Active, QPalette::Foreground)); p->setBrush(Qt::NoBrush); p->drawRect(r.adjusted(0, 0, -1, -1)); if (rbOpt->shape == QRubberBand::Rectangle) p->drawRect(r.adjusted(3, 3, -4, -4)); p->restore(); } break; }#endif // QT_NO_RUBBERBAND#ifndef QT_NO_DOCKWIDGET case CE_DockWidgetTitle: if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) { QRect r = dwOpt->rect.adjusted(0, 0, -1, -1); if (dwOpt->movable) { p->setPen(dwOpt->palette.color(QPalette::Dark)); p->drawRect(r); } if (!dwOpt->title.isEmpty()) { const int indent = p->fontMetrics().descent(); drawItemText(p, r.adjusted(indent + 1, 1, -indent - 1, -1), Qt::AlignLeft | Qt::AlignVCenter, dwOpt->palette, dwOpt->state & State_Enabled, dwOpt->title, QPalette::Foreground); } } break;#endif // QT_NO_DOCKWIDGET case CE_Header: if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { QRegion clipRegion = p->clipRegion(); p->setClipRect(opt->rect); drawControl(CE_HeaderSection, header, p, widget); QStyleOptionHeader subopt = *header; subopt.rect = subElementRect(SE_HeaderLabel, header, widget); if (subopt.rect.isValid()) drawControl(CE_HeaderLabel, &subopt, p, widget); if (header->sortIndicator != QStyleOptionHeader::None) { subopt.rect = subElementRect(SE_HeaderArrow, opt, widget); drawPrimitive(PE_IndicatorHeaderArrow, &subopt, p, widget); } p->setClipRegion(clipRegion); } break; case CE_FocusFrame: p->fillRect(opt->rect, opt->palette.foreground()); break; case CE_HeaderSection: qDrawShadePanel(p, opt->rect, opt->palette, opt->state & State_Sunken, 1, &opt->palette.brush(QPalette::Button)); break;#ifndef QT_NO_COMBOBOX case CE_ComboBoxLabel: if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget); p->save(); p->setClipRect(editRect); if (!cb->currentIcon.isNull()) { QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode); QRect iconRect(editRect); iconRect.setWidth(cb->iconSize.width() + 4); iconRect = alignedRect(QApplication::layoutDirection(), Qt::AlignLeft | Qt::AlignVCenter, iconRect.size(), editRect); if (cb->editable) p->fillRect(iconRect, opt->palette.brush(QPalette::Base)); drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap); if (cb->direction == Qt::RightToLeft) editRect.translate(-4 - cb->iconSize.width(), 0); else editRect.translate(cb->iconSize.width() + 4, 0); } if (!cb->currentText.isEmpty() && !cb->editable) { drawItemText(p, editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, cb->palette, cb->state & State_Enabled, cb->currentText); } p->restore(); } break;#endif // QT_NO_COMBOBOX#ifndef QT_NO_TOOLBAR case CE_ToolBar: if (const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) { // Compatibility with styles that use PE_PanelToolBar QStyleOptionFrame frame; frame.QStyleOption::operator=(*toolBar); frame.lineWidth = toolBar->lineWidth; frame.midLineWidth = toolBar->midLineWidth; drawPrimitive(PE_PanelToolBar, opt, p, widget); if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) break; qDrawShadePanel(p, toolBar->rect, toolBar->palette, false, toolBar->lineWidth, &toolBar->palette.brush(QPalette::Button)); } break;#endif // QT_NO_TOOLBAR default: break; }}/*! \reimp*/QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *widget) const{ QRect r; switch (sr) { case SE_PushButtonContents: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { int dx1, dx2; dx1 = pixelMetric(PM_DefaultFrameWidth, btn, widget); if (btn->features & QStyleOptionButton::AutoDefaultButton) dx1 += pixelMetric(PM_ButtonDefaultIndicator, btn, widget); dx2 = dx1 * 2; r.setRect(opt->rect.x() + dx1, opt->rect.y() + dx1, opt->rect.width() - dx2, opt->rect.height() - dx2); r = visualRect(opt->direction, opt->rect, r); } break; case SE_PushButtonFocusRect: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { int dbw1 = 0, dbw2 = 0; if (btn->features & QStyleOptionButton::AutoDefaultButton){ dbw1 = pixelMetric(PM_ButtonDefaultIndicator, btn, widget); dbw2 = dbw1 * 2; } int dfw1 = pixelMetric(PM_DefaultFrameWidth, btn, widget) + 1, dfw2 = dfw1 * 2; r.setRect(btn->rect.x() + dfw1 + dbw1, btn->rect.y() + dfw1 + dbw1, btn->rect.width() - dfw2 - dbw2, btn->rect.height()- dfw2 - dbw2); r = visualRect(opt->direction, opt->rect, r); } break; case SE_ViewItemCheckIndicator: r = subElementRect(SE_CheckBoxIndicator, opt, widget); break; case SE_CheckBoxIndicator: { int h = pixelMetric(PM_IndicatorHeight, opt, widget); r.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - h) / 2), pixelMetric(PM_IndicatorWidth, opt, widget), h); r = visualRect(opt->direction, opt->rect, r); } break; case SE_CheckBoxContents: { // Deal with the logical first, then convert it back to screen coords. QRect ir = visualRect(opt->direction, opt->rect, subElementRect(SE_CheckBoxIndicator, opt, widget)); r.setRect(ir.right() + 6, opt->rect.y(), opt->rect.width() - ir.width() - 6, opt->rect.height()); r = visualRect(opt->direction, opt->rect, r); } break; case SE_CheckBoxFocusRect:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -