3193 const QWidget *w)
const
3195 Q_D(
const QMacStyle);
3196 QMacCGContext cg(p);
3198 qCWarning(lcMacStyle) <<
"drawPrimitive:" << pe <<
"invalid (nullptr) graphics context";
3200 QWindow *window = w && w->window() ? w->window()->windowHandle() :
nullptr;
3201 d->resolveCurrentNSView(window);
3203 case PE_IndicatorArrowUp:
3204 case PE_IndicatorArrowDown:
3205 case PE_IndicatorArrowRight:
3206 case PE_IndicatorArrowLeft: {
3208 p->setRenderHint(QPainter::Antialiasing);
3209 const int xOffset = 1;
3210 qreal halfSize = 0.5 * qMin(opt->rect.width(), opt->rect.height());
3211 const qreal penWidth = qMax(halfSize / 3.0, 1.25);
3212#if QT_CONFIG(toolbutton)
3213 if (
const QToolButton *tb = qobject_cast<
const QToolButton *>(w)) {
3215 if (tb->arrowType() != Qt::NoArrow
3216 || tb->popupMode() == QToolButton::MenuButtonPopup)
3217 halfSize -= penWidth;
3221 QTransform transform;
3222 transform.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2);
3226 case PE_IndicatorArrowDown:
3228 case PE_IndicatorArrowUp:
3229 transform.rotate(180);
3231 case PE_IndicatorArrowLeft:
3232 transform.rotate(90);
3234 case PE_IndicatorArrowRight:
3235 transform.rotate(-90);
3238 p->setTransform(transform);
3240 path.moveTo(-halfSize, -halfSize * 0.5);
3241 path.lineTo(0.0, halfSize * 0.5);
3242 path.lineTo(halfSize, -halfSize * 0.5);
3244 const QPen arrowPen(opt->palette.text(), penWidth,
3245 Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
3246 p->strokePath(path, arrowPen);
3249#if QT_CONFIG(tabbar)
3250 case PE_FrameTabBarBase:
3251 if (
const QStyleOptionTabBarBase *tbb
3252 = qstyleoption_cast<
const QStyleOptionTabBarBase *>(opt)) {
3253 if (tbb->documentMode) {
3255 drawTabBase(p, tbb, w);
3259#if QT_CONFIG(tabwidget)
3260 QRegion region(tbb->rect);
3261 region -= tbb->tabBarRect.adjusted(3, 0, -3, 0);
3263 p->setClipRegion(region);
3264 QStyleOptionTabWidgetFrame twf;
3265 twf.QStyleOption::operator=(*tbb);
3266 twf.shape = tbb->shape;
3267 switch (QMacStylePrivate::tabDirection(twf.shape)) {
3268 case QMacStylePrivate::North:
3269 twf.rect = twf.rect.adjusted(0, 0, 0, 10);
3271 case QMacStylePrivate::South:
3272 twf.rect = twf.rect.adjusted(0, -10, 0, 0);
3274 case QMacStylePrivate::West:
3275 twf.rect = twf.rect.adjusted(0, 0, 10, 0);
3277 case QMacStylePrivate::East:
3278 twf.rect = twf.rect.adjusted(0, -10, 0, 0);
3281 proxy()->drawPrimitive(PE_FrameTabWidget, &twf, p, w);
3287 case PE_PanelTipLabel:
3288 p->fillRect(opt->rect, opt->palette.brush(QPalette::ToolTipBase));
3290 case PE_FrameGroupBox:
3291 if (
const auto *groupBox = qstyleoption_cast<
const QStyleOptionFrame *>(opt))
3292 if (groupBox->features & QStyleOptionFrame::Flat) {
3293 QCommonStyle::drawPrimitive(pe, groupBox, p, w);
3296#if QT_CONFIG(tabwidget)
3298 case PE_FrameTabWidget:
3301 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Box, QStyleHelper::SizeLarge);
3302 auto *box =
static_cast<NSBox *>(d->cocoaControl(cw));
3316 auto adjustedRect = opt->rect;
3317 bool needTranslation =
false;
3319 if (!qt_apple_runningWithLiquidGlass() && !
isDarkMode()) {
3332 adjustedRect.adjust(0, 0, 6, 6);
3333 needTranslation =
true;
3335 d->drawNSViewInRect(box, adjustedRect, p, ^(CGContextRef ctx,
const CGRect &rect) {
3336#if QT_CONFIG(tabwidget)
3337 if (qobject_cast<QTabWidget *>(opt->styleObject))
3338 clipTabBarFrame(opt,
this, ctx);
3340 CGContextTranslateCTM(ctx, 0, rect.origin.y + rect.size.height);
3341 CGContextScaleCTM(ctx, 1, -1);
3342 if ([box isMemberOfClass:QDarkNSBox.
class]) {
3343 [box drawRect:rect];
3345 if (needTranslation)
3346 CGContextTranslateCTM(ctx, -3.0, 5.0);
3347 [box displayRectIgnoringOpacity:box.bounds inContext:NSGraphicsContext.currentContext];
3352 case PE_IndicatorToolBarSeparator: {
3354 if (opt->state & State_Horizontal) {
3355 int xpoint = opt->rect.center().x();
3356 path.moveTo(xpoint + 0.5, opt->rect.top() + 1);
3357 path.lineTo(xpoint + 0.5, opt->rect.bottom());
3359 int ypoint = opt->rect.center().y();
3360 path.moveTo(opt->rect.left() + 2 , ypoint + 0.5);
3361 path.lineTo(opt->rect.right() + 1, ypoint + 0.5);
3363 QPainterPathStroker theStroker;
3364 theStroker.setCapStyle(Qt::FlatCap);
3365 theStroker.setDashPattern(QVector<qreal>() << 1 << 2);
3366 path = theStroker.createStroke(path);
3367 const auto dark =
isDarkMode() ? opt->palette.dark().color().darker()
3368 : QColor(0, 0, 0, 119);
3369 p->fillPath(path, dark);
3372 case PE_FrameWindow:
3373 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
3374 if (qobject_cast<
const QMdiSubWindow*>(w)) {
3376 p->setPen(QPen(frame->palette.dark().color(), frame->lineWidth));
3377 p->setBrush(frame->palette.window());
3378 p->drawRect(frame->rect);
3383 case PE_IndicatorDockWidgetResizeHandle: {
3386 if (opt->state & State_Horizontal) {
3387 p->setPen(QColor(160, 160, 160));
3388 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3390 p->setPen(QColor(145, 145, 145));
3391 p->drawLine(opt->rect.topRight(), opt->rect.bottomRight());
3395 case PE_IndicatorToolBarHandle: {
3398 int x = opt->rect.x() + 6;
3399 int y = opt->rect.y() + 7;
3400 static const int RectHeight = 2;
3401 if (opt->state & State_Horizontal) {
3402 while (y < opt->rect.height() - RectHeight - 5) {
3404 path.addEllipse(x, y, RectHeight, RectHeight);
3408 while (x < opt->rect.width() - RectHeight - 5) {
3410 path.addEllipse(x, y, RectHeight, RectHeight);
3414 p->setPen(Qt::NoPen);
3415 QColor dark = opt->palette.dark().color().darker();
3416 dark.setAlphaF(0.50);
3417 p->fillPath(path, dark);
3422 case PE_IndicatorHeaderArrow:
3423 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
3425 if (header->sortIndicator != QStyleOptionHeader::None)
3426 proxy()->drawPrimitive(
3427 (header->sortIndicator == QStyleOptionHeader::SortDown) ?
3428 PE_IndicatorArrowUp : PE_IndicatorArrowDown, header, p, w);
3431 case PE_IndicatorMenuCheckMark: {
3435 if (opt->state & State_On)
3436 pc = opt->palette.highlightedText().color();
3438 pc = opt->palette.text().color();
3440 QCFType<CGColorRef> checkmarkColor = CGColorCreateGenericRGB(
static_cast<CGFloat>(pc.redF()),
3441 static_cast<CGFloat>(pc.greenF()),
3442 static_cast<CGFloat>(pc.blueF()),
3443 static_cast<CGFloat>(pc.alphaF()));
3449 const CTFontUIFontType fontType = (opt->state & State_Mini) ? kCTFontUIFontMiniSystem :
3450 (opt->state & State_Small) ? kCTFontUIFontSmallSystem :
3451 kCTFontUIFontMenuItemMark;
3455 const CGFloat fontSize = fontType == kCTFontUIFontMenuItemMark ? opt->fontMetrics.height() : 0.0;
3456 QCFType<CTFontRef> checkmarkFont = CTFontCreateUIFontForLanguage(fontType, fontSize, NULL);
3458 CGContextSaveGState(cg);
3459 CGContextSetShouldSmoothFonts(cg, NO);
3462 const CGFloat vOffset = (opt->state & State_Mini) ? 0.0 :
3463 (opt->state & State_Small) ? 1.0 :
3466 CGContextTranslateCTM(cg, 0, opt->rect.bottom());
3467 CGContextScaleCTM(cg, 1, -1);
3469 CGContextTranslateCTM(cg, opt->rect.x(), vOffset);
3473 static const CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName };
3474 static const int numValues =
sizeof(keys) /
sizeof(keys[0]);
3475 const CFTypeRef values[] = { (CFTypeRef)checkmarkFont, (CFTypeRef)checkmarkColor };
3476 static_assert((
sizeof(values) /
sizeof(values[0])) == numValues);
3477 QCFType<CFDictionaryRef> attributes = CFDictionaryCreate(kCFAllocatorDefault, (
const void **)keys, (
const void **)values,
3478 numValues, NULL, NULL);
3480 QCFType<CFAttributedStringRef> checkmarkString = CFAttributedStringCreate(kCFAllocatorDefault, (CFStringRef)@
"\u2713", attributes);
3481 QCFType<CTLineRef> line = CTLineCreateWithAttributedString(checkmarkString);
3483 CTLineDraw((CTLineRef)line, cg);
3486 CGContextRestoreGState(cg);
3488 case PE_IndicatorItemViewItemCheck:
3489 case PE_IndicatorRadioButton:
3490 case PE_IndicatorCheckBox: {
3491 const bool isEnabled = opt->state & State_Enabled;
3492 const bool isPressed = opt->state & State_Sunken;
3493 const bool isRadioButton = (pe == PE_IndicatorRadioButton);
3494 const auto ct = isRadioButton ? QMacStylePrivate::Button_RadioButton : QMacStylePrivate::Button_CheckBox;
3495 const auto cs = d->effectiveAquaSizeConstrain(opt, w);
3496 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
3497 auto *tb =
static_cast<NSButton *>(d->cocoaControl(cw));
3498 tb.enabled = isEnabled;
3499 tb.state = (opt->state & State_NoChange) ? NSControlStateValueMixed :
3500 (opt->state & State_On) ? NSControlStateValueOn : NSControlStateValueOff;
3501 [tb highlight:isPressed];
3502 const auto vOffset = [=] {
3504 if (cs == QStyleHelper::SizeMini)
3505 return ct == QMacStylePrivate::Button_CheckBox ? -0.5 : 0.5;
3507 return cs == QStyleHelper::SizeSmall ? 0.5 : 0.0;
3509 d->drawNSViewInRect(tb, opt->rect, p, ^(CGContextRef ctx,
const CGRect &rect) {
3510 CGContextTranslateCTM(ctx, 0, vOffset);
3511 [tb.cell drawInteriorWithFrame:rect inView:tb];
3514 case PE_FrameFocusRect:
3517 case PE_IndicatorBranch: {
3518 if (!(opt->state & State_Children))
3522 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Button_Disclosure, QStyleHelper::SizeLarge);
3523 NSButtonCell *triangleCell =
static_cast<NSButtonCell *>(d->cocoaCell(cw));
3524 [triangleCell setState:(opt->state & State_Open) ? NSControlStateValueOn : NSControlStateValueOff];
3525 bool viewHasFocus = (w && w->hasFocus()) || (opt->state & State_HasFocus);
3526 [triangleCell setBackgroundStyle:((opt->state & State_Selected) && viewHasFocus) ? NSBackgroundStyleEmphasized : NSBackgroundStyleNormal];
3527 [triangleCell setUserInterfaceLayoutDirection:qt_macLayoutDirectionFromQt(opt->direction)];
3529 d->setupNSGraphicsContext(cg, NO);
3532 CGRect rect = CGRectMake(qtRect.x() + 1, qtRect.y(), qtRect.width(), qtRect.height());
3533 CGContextTranslateCTM(cg, rect.origin.x, rect.origin.y + rect.size.height);
3534 CGContextScaleCTM(cg, 1, -1);
3535 CGContextTranslateCTM(cg, -rect.origin.x, -rect.origin.y);
3537 [triangleCell drawBezelWithFrame:NSRectFromCGRect(rect) inView:[triangleCell controlView]];
3539 d->restoreNSGraphicsContext(cg);
3543 QPen oldPen = p->pen();
3544 p->setPen(opt->palette.base().color().darker(140));
3545 p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
3546 p->setPen(opt->palette.base().color().darker(180));
3547 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3551 case PE_FrameLineEdit:
3552 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
3553 if (frame->state & State_Sunken) {
3554 const bool isEnabled = opt->state & State_Enabled;
3555 const bool isReadOnly = opt->state & State_ReadOnly;
3556 const bool isRounded = frame->features & QStyleOptionFrame::Rounded;
3557 const auto cs = d->effectiveAquaSizeConstrain(opt, w, CT_LineEdit);
3558 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::TextField, cs);
3559 auto *tf =
static_cast<NSTextField *>(d->cocoaControl(cw));
3560 tf.enabled = isEnabled;
3561 tf.editable = !isReadOnly;
3563 static_cast<NSTextFieldCell *>(tf.cell).bezelStyle = isRounded ? NSTextFieldRoundedBezel : NSTextFieldSquareBezel;
3564 tf.frame = opt->rect.toCGRect();
3565 d->drawNSViewInRect(tf, opt->rect, p, ^(CGContextRef,
const CGRect &rect) {
3566 if (!isDarkMode()) {
3571 CGContextRef cgContext = NSGraphicsContext.currentContext.CGContext;
3575 if (cgContext ?
bool(CGBitmapContextGetColorSpace(cgContext)) :
false) {
3576 tf.drawsBackground = YES;
3577 const QColor bgColor = frame->palette.brush(QPalette::Base).color();
3578 tf.backgroundColor = [NSColor colorWithSRGBRed:bgColor.redF()
3579 green:bgColor.greenF()
3580 blue:bgColor.blueF()
3581 alpha:bgColor.alphaF()];
3582 if (bgColor.alpha() != 255) {
3589 CGRect fixedRect = rect;
3590 if (qt_apple_runningWithLiquidGlass()) {
3595 fixedRect = CGRectInset(rect, 1., 1.);
3597 [tf.cell drawWithFrame:fixedRect inView:tf];
3600 QCommonStyle::drawPrimitive(pe, opt, p, w);
3604 case PE_PanelLineEdit:
3606 const QStyleOptionFrame *panel = qstyleoption_cast<
const QStyleOptionFrame *>(opt);
3607 if (
isDarkMode() || (panel && panel->lineWidth <= 0)) {
3613 QCommonStyle::drawPrimitive(pe, opt, p, w);
3618 drawPrimitive(PE_FrameLineEdit, opt, p, w);
3624#if QT_CONFIG(lineedit)
3625 if ((opt->state & State_HasFocus) && !qobject_cast<
const QLineEdit*>(w)) {
3626 int vmargin = pixelMetric(QStyle::PM_FocusFrameVMargin);
3627 int hmargin = pixelMetric(QStyle::PM_FocusFrameHMargin);
3628 QStyleOptionFrame focusFrame = *panel;
3629 focusFrame.rect = panel->rect.adjusted(-hmargin, -vmargin, hmargin, vmargin);
3630 drawControl(CE_FocusFrame, &focusFrame, p, w);
3636 case PE_PanelScrollAreaCorner: {
3637 const QBrush brush(opt->palette.brush(QPalette::Base));
3638 p->fillRect(opt->rect, brush);
3639 p->setPen(QPen(QColor(217, 217, 217)));
3640 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3641 p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
3643 case PE_FrameStatusBarItem:
3645#if QT_CONFIG(tabbar)
3646 case PE_IndicatorTabClose: {
3648 QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget());
3649 const QWidget *closeBtn = w;
3653 tabBar = qobject_cast<QTabBar *>(
const_cast<QWidget*>(w));
3654 closeBtn =
decltype(closeBtn)(property(
"_q_styleSheetRealCloseButton").value<
void *>());
3657 const bool documentMode = tabBar->documentMode();
3658 const QTabBarPrivate *tabBarPrivate =
static_cast<QTabBarPrivate *>(QObjectPrivate::get(tabBar));
3659 const int hoveredTabIndex = tabBarPrivate->hoveredTabIndex();
3660 if (!documentMode ||
3661 (hoveredTabIndex != -1 && ((closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) ||
3662 (closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide))))) {
3663 const bool hover = (opt->state & State_MouseOver);
3664 const bool selected = (opt->state & State_Selected);
3665 const bool pressed = (opt->state & State_Sunken);
3666 drawTabCloseButton(p, hover, selected, pressed, documentMode);
3671 case PE_PanelStatusBar: {
3672 p->fillRect(opt->rect, opt->palette.window());
3675 if (w ? qt_macWindowMainWindow(w->window()) : (opt->state & QStyle::State_Active))
3676 p->setPen(titlebarSeparatorLineActive);
3678 p->setPen(titlebarSeparatorLineInactive);
3679 p->drawLine(opt->rect.left(), opt->rect.top(), opt->rect.right(), opt->rect.top());
3683 case PE_PanelMenu: {
3685 p->fillRect(opt->rect, Qt::transparent);
3686 p->setPen(Qt::transparent);
3687 p->setBrush(opt->palette.window());
3688 p->setRenderHint(QPainter::Antialiasing,
true);
3689 const QPainterPath path = d->windowPanelPath(opt->rect);
3695 QCommonStyle::drawPrimitive(pe, opt, p, w);
3736 const QWidget *w)
const
3738 Q_D(
const QMacStyle);
3739 const QMacAutoReleasePool pool;
3740 QMacCGContext cg(p);
3742 qCWarning(lcMacStyle) <<
"drawControl:" << ce <<
"invalid (nullptr) graphics context";
3744 QWindow *window = w && w->window() ? w->window()->windowHandle() :
nullptr;
3745 d->resolveCurrentNSView(window);
3747 case CE_HeaderSection:
3748 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
3749 State flags = header->state;
3750 QRect ir = header->rect;
3754 bool noVerticalHeader =
true;
3755#if QT_CONFIG(tableview)
3757 if (
const QTableView *table = qobject_cast<
const QTableView *>(w->parentWidget()))
3758 noVerticalHeader = !table->verticalHeader()->isVisible();
3761 const bool drawLeftBorder = header->orientation == Qt::Vertical
3762 || header->position == QStyleOptionHeader::OnlyOneSection
3763 || (header->position == QStyleOptionHeader::Beginning && noVerticalHeader);
3766 const bool pressed = (flags & State_Sunken) && !(flags & State_On);
3767 p->fillRect(ir, pressed ? header->palette.dark() : header->palette.button());
3768 p->setPen(QPen(header->palette.dark(), 1.0));
3769 if (header->orientation == Qt::Horizontal)
3778 case CE_ToolButtonLabel:
3779 if (
const QStyleOptionToolButton *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
3780 QStyleOptionToolButton myTb = *tb;
3781 myTb.state &= ~State_AutoRaise;
3782#if QT_CONFIG(accessibility)
3783 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) {
3784 QRect cr = tb->rect;
3787 bool needText =
false;
3789 bool down = tb->state & (State_Sunken | State_On);
3791 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, w);
3792 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, tb, w);
3798 if (!(tb->features & QStyleOptionToolButton::Arrow)) {
3799 Qt::ToolButtonStyle tbstyle = tb->toolButtonStyle;
3800 if (tb->icon.isNull() && !tb->text.isEmpty())
3801 tbstyle = Qt::ToolButtonTextOnly;
3804 case Qt::ToolButtonTextOnly: {
3806 alignment = Qt::AlignCenter;
3808 case Qt::ToolButtonIconOnly:
3809 case Qt::ToolButtonTextBesideIcon:
3810 case Qt::ToolButtonTextUnderIcon: {
3812 QIcon::Mode iconMode = (tb->state & State_Enabled) ? QIcon::Normal
3814 QIcon::State iconState = (tb->state & State_On) ? QIcon::On
3816 QPixmap pixmap = tb->icon.pixmap(tb->rect.size().boundedTo(tb->iconSize), p->device()->devicePixelRatio(),
3817 iconMode, iconState);
3820 if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) {
3822 QSizeF size = pixmap.deviceIndependentSize();
3823 if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
3824 pr.setHeight(size.height() + 6);
3825 cr.adjust(0, pr.bottom(), 0, -3);
3826 alignment |= Qt::AlignCenter;
3828 pr.setWidth(size.width() + 8);
3829 cr.adjust(pr.right(), 0, 0, 0);
3830 alignment |= Qt::AlignLeft | Qt::AlignVCenter;
3833 if (opt->state & State_Sunken) {
3834 pr.translate(shiftX, shiftY);
3835 pixmap = darkenPixmap(pixmap);
3837 proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pixmap);
3845 QPalette pal = tb->palette;
3846 QPalette::ColorRole role = QPalette::NoRole;
3847 if (!proxy()->styleHint(SH_UnderlineShortcut, tb, w))
3848 alignment |= Qt::TextHideMnemonic;
3850 cr.translate(shiftX, shiftY);
3851 if (tbstyle == Qt::ToolButtonTextOnly
3852 || (tbstyle != Qt::ToolButtonTextOnly && !down)) {
3853 QPen pen = p->pen();
3854 QColor light = down || isDarkMode() ? Qt::black : Qt::white;
3855 light.setAlphaF(0.375f);
3857 p->drawText(cr.adjusted(0, 1, 0, 1), alignment, tb->text);
3859 if (down && tbstyle == Qt::ToolButtonTextOnly) {
3860 pal = QApplication::palette(
"QMenu");
3861 pal.setCurrentColorGroup(tb->palette.currentColorGroup());
3862 role = QPalette::HighlightedText;
3865 proxy()->drawItemText(p, cr, alignment, pal,
3866 tb->state & State_Enabled, tb->text, role);
3869 QCommonStyle::drawControl(ce, &myTb, p, w);
3874 QCommonStyle::drawControl(ce, &myTb, p, w);
3878 case CE_ToolBoxTabShape:
3879 QCommonStyle::drawControl(ce, opt, p, w);
3881 case CE_PushButtonBevel:
3882 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
3883 if (!(btn->state & (State_Raised | State_Sunken | State_On)))
3886 if (btn->features & QStyleOptionButton::CommandLinkButton) {
3887 QCommonStyle::drawControl(ce, opt, p, w);
3891 const bool hasFocus = btn->state & State_HasFocus;
3892 const bool isActive = btn->state & State_Active;
3896 if ((btn->features & QStyleOptionButton::AutoDefaultButton)
3897 && isActive && hasFocus)
3898 d->autoDefaultButton = btn->styleObject;
3899 else if (d->autoDefaultButton == btn->styleObject)
3900 d->autoDefaultButton =
nullptr;
3902 const bool isEnabled = btn->state & State_Enabled;
3903 const bool isPressed = btn->state & State_Sunken;
3904 const bool isHighlighted = isActive &&
3905 ((btn->state & State_On)
3906 || (btn->features & QStyleOptionButton::DefaultButton)
3907 || (btn->features & QStyleOptionButton::AutoDefaultButton
3908 && d->autoDefaultButton == btn->styleObject));
3909 const bool hasMenu = btn->features & QStyleOptionButton::HasMenu;
3910 const auto ct = cocoaControlType(btn, w);
3911 const auto cs = d->effectiveAquaSizeConstrain(btn, w);
3912 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
3913 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
3917 const QRectF frameRect = cw.adjustedControlFrame(btn->rect);
3918 pb.frame = frameRect.toCGRect();
3920 pb.enabled = isEnabled;
3925 [pb highlight:isPressed];
3928 if (cw.type == QMacStylePrivate::Button_SquareButton) {
3929 pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff;
3933 pb.keyEquivalent = isHighlighted ? @
"\r" : @
"";
3936 d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
3937 [pb.cell drawBezelWithFrame:r inView:pb.superview];
3941 if (hasMenu && cw.type == QMacStylePrivate::Button_SquareButton) {
3944 const int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w);
3945 const auto ir = frameRect.toRect();
3946 int arrowYOffset = 0;
3951 arrowYOffset -= ir.top();
3952 if (cw.second == QStyleHelper::SizeSmall)
3956 const auto ar = visualRect(btn->direction, ir, QRect(ir.right() - mbi - 6, ir.height() / 2 - arrowYOffset, mbi, mbi));
3958 QStyleOption arrowOpt = *opt;
3960 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, w);
3964 case CE_PushButtonLabel:
3965 if (
const QStyleOptionButton *b = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
3966 QStyleOptionButton btn(*b);
3971 const bool isEnabled = btn.state & State_Enabled;
3972 const bool hasMenu = btn.features & QStyleOptionButton::HasMenu;
3973 const bool hasIcon = !btn.icon.isNull();
3974 const bool hasText = !btn.text.isEmpty();
3975 const bool isActive = btn.state & State_Active;
3976 const bool isPressed = btn.state & State_Sunken;
3977 const bool isDefault = (btn.features & QStyleOptionButton::DefaultButton && !d->autoDefaultButton)
3978 || d->autoDefaultButton == btn.styleObject;
3982 const QRect oldRect = btn.rect;
3984 btn.rect = w->rect();
3985 const auto ct = cocoaControlType(&btn, w);
3988 if (!hasMenu && ct != QMacStylePrivate::Button_SquareButton) {
3989 if (isPressed || (isActive && isEnabled && ((btn.state & State_On) || isDefault)))
3990 btn.palette.setColor(QPalette::ButtonText, Qt::white);
3994 if (!isDefault && !(btn.state & State_On)) {
3997 btn.palette.setColor(QPalette::ButtonText, Qt::black);
4001 if ((!hasIcon && !hasMenu) || (hasIcon && !hasText)) {
4002 QCommonStyle::drawControl(ce, &btn, p, w);
4004 QRect freeContentRect = btn.rect;
4005 QRect textRect = itemTextRect(
4006 btn.fontMetrics, freeContentRect, Qt::AlignCenter, isEnabled, btn.text);
4008 if (ct == QMacStylePrivate::Button_SquareButton)
4009 textRect.moveTo(w ? 8 : 11, textRect.top());
4011 textRect.moveTo(w ? (15 - pushButtonBevelRectOffsets[d->effectiveAquaSizeConstrain(b, w)])
4012 : 11, textRect.top());
4016 int contentW = textRect.width();
4018 contentW += proxy()->pixelMetric(PM_MenuButtonIndicator) + 4;
4019 QIcon::Mode mode = isEnabled ? QIcon::Normal : QIcon::Disabled;
4020 if (mode == QIcon::Normal && btn.state & State_HasFocus)
4021 mode = QIcon::Active;
4023 QIcon::State state = QIcon::Off;
4024 if (btn.state & State_On)
4026 QPixmap pixmap = btn.icon.pixmap(btn.iconSize, p->device()->devicePixelRatio(), mode, state);
4027 QSizeF pixmapSize = pixmap.deviceIndependentSize();
4028 contentW += pixmapSize.width() + QMacStylePrivate::PushButtonContentPadding;
4029 int iconLeftOffset = freeContentRect.x() + (freeContentRect.width() - contentW) / 2;
4030 int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmapSize.height()) / 2;
4031 QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmapSize.width(), pixmapSize.height());
4032 QRect visualIconDestRect = visualRect(btn.direction, freeContentRect, iconDestRect);
4033 proxy()->drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap);
4034 int newOffset = iconDestRect.x() + iconDestRect.width()
4035 + QMacStylePrivate::PushButtonContentPadding - textRect.x();
4036 textRect.adjust(newOffset, 0, newOffset, 0);
4040 textRect = visualRect(btn.direction, freeContentRect, textRect);
4041 proxy()->drawItemText(p, textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, btn.palette,
4042 isEnabled, btn.text, QPalette::ButtonText);
4047#if QT_CONFIG(combobox)
4048 case CE_ComboBoxLabel:
4049 if (
const auto *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
4050 auto comboCopy = *cb;
4051 comboCopy.direction = Qt::LeftToRight;
4053 QCommonStyle::drawControl(CE_ComboBoxLabel, &comboCopy, p, w);
4057#if QT_CONFIG(tabbar)
4058 case CE_TabBarTabShape:
4059 if (
const auto *tabOpt = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
4060 if (tabOpt->documentMode) {
4062 bool isUnified =
false;
4064 QRect tabRect = tabOpt->rect;
4065 QPoint windowTabStart = w->mapTo(w->window(), tabRect.topLeft());
4066 isUnified = isInMacUnifiedToolbarArea(w->window()->windowHandle(), windowTabStart.y());
4069 const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, opt, w);
4070 drawTabShape(p, tabOpt, isUnified, tabOverlap);
4099 const bool isActive = tabOpt->state & State_Active;
4100 const bool isEnabled = tabOpt->state & State_Enabled;
4101 const bool isPressed = tabOpt->state & State_Sunken;
4102 const bool isSelected = tabOpt->state & State_Selected;
4103 const auto tabDirection = QMacStylePrivate::tabDirection(tabOpt->shape);
4104 const bool verticalTabs = tabDirection == QMacStylePrivate::East
4105 || tabDirection == QMacStylePrivate::West;
4107 QStyleOptionTab::TabPosition tp = tabOpt->position;
4108 QStyleOptionTab::SelectedPosition sp = tabOpt->selectedPosition;
4109 if (tabOpt->direction == Qt::RightToLeft && !verticalTabs) {
4110 if (tp == QStyleOptionTab::Beginning)
4111 tp = QStyleOptionTab::End;
4112 else if (tp == QStyleOptionTab::End)
4113 tp = QStyleOptionTab::Beginning;
4115 if (sp == QStyleOptionTab::NextIsSelected)
4116 sp = QStyleOptionTab::PreviousIsSelected;
4117 else if (sp == QStyleOptionTab::PreviousIsSelected)
4118 sp = QStyleOptionTab::NextIsSelected;
4127 const auto cs = d->effectiveAquaSizeConstrain(opt, w);
4129 const bool needsInactiveHack = !isActive && isSelected;
4130 const auto ct = !needsInactiveHack && (isSelected || tp == QStyleOptionTab::OnlyOneTab) ?
4131 QMacStylePrivate::Button_PushButton :
4132 QMacStylePrivate::Button_PopupButton;
4133 const bool isPopupButton = ct == QMacStylePrivate::Button_PopupButton;
4134 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
4135 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
4138 if (tabDirection == QMacStylePrivate::East)
4140 const auto outerAdjust = isPopupButton ? 1 : 4;
4141 const auto innerAdjust = isPopupButton ? 20 : 10;
4142 QRectF frameRect = tabOpt->rect;
4144 frameRect = QRectF(frameRect.y(), frameRect.x(), frameRect.height(), frameRect.width());
4146 frameRect = frameRect.translated(0, vOffset);
4148 case QStyleOptionTab::Beginning:
4150 if (!isSelected && tabDirection == QMacStylePrivate::West)
4151 frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0);
4153 frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0);
4158 frameRect = frameRect.adjusted(0, 0, 1, 0);
4161 case QStyleOptionTab::Middle:
4162 frameRect = frameRect.adjusted(-innerAdjust, 0, innerAdjust, 0);
4167 frameRect = frameRect.adjusted(-1, 0, 1, 0);
4170 case QStyleOptionTab::Moving:
4171 case QStyleOptionTab::End:
4173 if (isSelected || tabDirection == QMacStylePrivate::West)
4174 frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0);
4176 frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0);
4180 frameRect = frameRect.adjusted(-1, 0, 0, 0);
4183 case QStyleOptionTab::OnlyOneTab:
4184 frameRect = frameRect.adjusted(-outerAdjust, 0, outerAdjust, 0);
4187 pb.frame = frameRect.toCGRect();
4189 if (!isPopupButton) {
4193 pb.buttonType = NSButtonTypePushOnPushOff;
4196 pb.enabled = isEnabled;
4197 [pb highlight:isPressed];
4199 pb.state = (isActive && isSelected) ? NSControlStateValueOn : NSControlStateValueOff;
4201 const auto drawBezelBlock = ^(CGContextRef ctx,
const CGRect &r) {
4202 CGContextClipToRect(ctx, opt->rect.toCGRect());
4203 if (!isSelected || needsInactiveHack) {
4205 if (!verticalTabs && tp == QStyleOptionTab::End) {
4206 CGContextTranslateCTM(ctx, opt->rect.right(), 0);
4207 CGContextScaleCTM(ctx, -1, 1);
4208 CGContextTranslateCTM(ctx, -frameRect.left(), 0);
4209 }
else if (tabDirection == QMacStylePrivate::West && tp == QStyleOptionTab::Beginning) {
4210 CGContextTranslateCTM(ctx, 0, opt->rect.top());
4211 CGContextScaleCTM(ctx, 1, -1);
4212 CGContextTranslateCTM(ctx, 0, -frameRect.right());
4213 }
else if (tabDirection == QMacStylePrivate::East && tp == QStyleOptionTab::End) {
4214 CGContextTranslateCTM(ctx, 0, opt->rect.bottom());
4215 CGContextScaleCTM(ctx, 1, -1);
4216 CGContextTranslateCTM(ctx, 0, -frameRect.left());
4222 if (tabDirection == QMacStylePrivate::West) {
4223 CGContextTranslateCTM(ctx, 0, frameRect.right());
4224 CGContextRotateCTM(ctx, -M_PI_2);
4225 CGContextTranslateCTM(ctx, -frameRect.left(), 0);
4226 }
else if (tabDirection == QMacStylePrivate::East) {
4227 CGContextTranslateCTM(ctx, opt->rect.right(), 0);
4228 CGContextRotateCTM(ctx, M_PI_2);
4233 NSPopUpArrowPosition oldPosition = NSPopUpArrowAtCenter;
4234 NSPopUpButtonCell *pbCell = nil;
4236 if (isPopupButton) {
4240 pbCell =
static_cast<NSPopUpButtonCell *>(pb.cell);
4241 oldPosition = pbCell.arrowPosition;
4242 pbCell.arrowPosition = NSPopUpNoArrow;
4243 if (pb.state == NSControlStateValueOff) {
4245 rAdjusted.origin.x -= 3;
4246 rAdjusted.size.width += 6;
4247 if (tp == QStyleOptionTab::End)
4248 rAdjusted.origin.x -= 2;
4251 if (qt_apple_runningWithLiquidGlass()) {
4260 const CGFloat deltaW = 20.0;
4261 rAdjusted = CGContextGetClipBoundingBox(ctx);
4262 if (tp == QStyleOptionTab::Beginning) {
4267 rAdjusted.size.width += deltaW;
4269 if (tabDirection == QMacStylePrivate::West && isSelected && isActive) {
4273 rAdjusted.origin.x -= deltaW;
4275 }
else if (tp == QStyleOptionTab::Middle) {
4277 rAdjusted.origin.x -= deltaW;
4278 rAdjusted.size.width += deltaW * 2;
4279 }
else if (tp == QStyleOptionTab::End) {
4280 if (isSelected && isActive && tabDirection != QMacStylePrivate::West)
4281 rAdjusted.origin.x -= deltaW;
4282 rAdjusted.size.width += deltaW;
4286 [pb.cell drawBezelWithFrame:rAdjusted inView:pb.superview];
4289 pbCell.arrowPosition = oldPosition;
4292 if (needsInactiveHack) {
4294 const qreal pixelRatio = p->device()->devicePixelRatio();
4295 QImage tabPixmap(opt->rect.size() * pixelRatio, QImage::Format_ARGB32_Premultiplied);
4296 tabPixmap.setDevicePixelRatio(pixelRatio);
4297 tabPixmap.fill(Qt::transparent);
4298 QPainter tabPainter(&tabPixmap);
4299 d->drawNSViewInRect(pb, frameRect, &tabPainter, ^(CGContextRef ctx,
const CGRect &r) {
4300 CGContextTranslateCTM(ctx, -opt->rect.left(), -opt->rect.top());
4301 drawBezelBlock(ctx, r);
4306 const qreal inactiveGray = 0.898;
4307 const int inactiveGray8 = qRound(inactiveGray * 255.0);
4308 const QRgb inactiveGrayRGB = qRgb(inactiveGray8, inactiveGray8, inactiveGray8);
4309 for (
int l = 0; l < tabPixmap.height(); ++l) {
4310 auto *line =
reinterpret_cast<QRgb*>(tabPixmap.scanLine(l));
4311 for (
int i = 0; i < tabPixmap.width(); ++i) {
4312 if (qAlpha(line[i]) == 255) {
4313 line[i] = inactiveGrayRGB;
4314 }
else if (qAlpha(line[i]) > 128) {
4315 const int g = qRound(inactiveGray * qRed(line[i]));
4316 line[i] = qRgba(g, g, g, qAlpha(line[i]));
4322 p->drawImage(opt->rect, tabPixmap);
4324 d->drawNSViewInRect(pb, frameRect, p, drawBezelBlock);
4327 if (!isSelected && sp != QStyleOptionTab::NextIsSelected
4328 && tp != QStyleOptionTab::End
4329 && tp != QStyleOptionTab::OnlyOneTab) {
4330 static const QPen separatorPen(Qt::black, 1.0);
4332 p->setOpacity(isEnabled ? 0.105 : 0.06);
4333 p->setPen(separatorPen);
4334 if (tabDirection == QMacStylePrivate::West) {
4335 p->drawLine(QLineF(opt->rect.left() + 1.5, opt->rect.bottom(),
4336 opt->rect.right() - 0.5, opt->rect.bottom()));
4337 }
else if (tabDirection == QMacStylePrivate::East) {
4338 p->drawLine(QLineF(opt->rect.left(), opt->rect.bottom(),
4339 opt->rect.right() - 0.5, opt->rect.bottom()));
4341 p->drawLine(QLineF(opt->rect.right(), opt->rect.top() + 1.0,
4342 opt->rect.right(), opt->rect.bottom() - 0.5));
4348 case CE_TabBarTabLabel:
4349 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
4350 QStyleOptionTab myTab = *tab;
4351 const auto foregroundRole = w ? w->foregroundRole() : QPalette::WindowText;
4352 const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape);
4353 const bool verticalTabs = tabDirection == QMacStylePrivate::East
4354 || tabDirection == QMacStylePrivate::West;
4360 const bool nonDefaultFont = p->font() != qt_app_fonts_hash()->value(
"QComboMenuItem");
4362 if (!myTab.documentMode && (myTab.state & State_Selected) && (myTab.state & State_Active))
4363 if (
const auto *tabBar = qobject_cast<
const QTabBar *>(w))
4364 if (!tabBar->tabTextColor(tabBar->currentIndex()).isValid())
4365 myTab.palette.setColor(foregroundRole, Qt::white);
4367 if (myTab.documentMode && isDarkMode()) {
4368 if (
const auto *tabBar = qobject_cast<
const QTabBar *>(w)) {
4369 if (!tabBar->tabTextColor(myTab.tabIndex).isValid()) {
4370 bool active = (myTab.state & State_Selected) && (myTab.state & State_Active);
4371 myTab.palette.setColor(foregroundRole, active ? Qt::white : Qt::gray);
4376 int heightOffset = 0;
4379 }
else if (nonDefaultFont) {
4380 if (p->fontMetrics().height() == myTab.rect.height())
4383 myTab.rect.setHeight(myTab.rect.height() + heightOffset);
4385 QCommonStyle::drawControl(ce, &myTab, p, w);
4389#if QT_CONFIG(dockwidget)
4390 case CE_DockWidgetTitle:
4391 if (
const auto *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(opt)) {
4392 const bool isVertical = dwOpt->verticalTitleBar;
4393 const auto effectiveRect = isVertical ? opt->rect.transposed() : opt->rect;
4396 p->translate(effectiveRect.left(), effectiveRect.top() + effectiveRect.width());
4398 p->translate(-effectiveRect.left(), -effectiveRect.top());
4402 p->fillRect(effectiveRect, opt->palette.window());
4405 p->setPen(opt->palette.dark().color());
4406 p->drawLine(effectiveRect.bottomLeft(), effectiveRect.bottomRight());
4408 if (!dwOpt->title.isEmpty()) {
4409 auto titleRect = proxy()->subElementRect(SE_DockWidgetTitleBarText, opt, w);
4411 titleRect = QRect(effectiveRect.left() + opt->rect.bottom() - titleRect.bottom(),
4412 effectiveRect.top() + titleRect.left() - opt->rect.left(),
4416 const auto text = p->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
4417 proxy()->drawItemText(p, titleRect, Qt::AlignCenter | Qt::TextHideMnemonic, dwOpt->palette,
4418 dwOpt->state & State_Enabled, text, QPalette::WindowText);
4424 case CE_FocusFrame: {
4425 const auto *ff = qobject_cast<
const QFocusFrame *>(w);
4426 const auto *ffw = ff ? ff->widget() :
nullptr;
4427 const auto ct = [=] {
4429 if (qobject_cast<
const QCheckBox*>(ffw))
4430 return QMacStylePrivate::Button_CheckBox;
4431 if (qobject_cast<
const QRadioButton*>(ffw))
4432 return QMacStylePrivate::Button_RadioButton;
4433 if (qobject_cast<
const QLineEdit*>(ffw) || qobject_cast<
const QTextEdit*>(ffw))
4434 return QMacStylePrivate::TextField;
4435 if (
const auto *pb = qobject_cast<
const QPushButton *>(ffw)) {
4437 auto sizePolicy = QStyleHelper::widgetSizePolicy(ffw, opt);
4438 if (sizePolicy == QStyleHelper::SizeDefault)
4439 sizePolicy = QStyleHelper::SizeLarge;
4441 || (pb->rect().height() != pushButtonDefaultHeight[sizePolicy])) {
4442 return QMacStylePrivate::Button_SquareButton;
4444 if (pb->menu() !=
nullptr)
4445 return QMacStylePrivate::Button_PullDown;
4446 return QMacStylePrivate::Button_PushButton;
4450 return QMacStylePrivate::Box;
4452 auto cs = QStyleHelper::widgetSizePolicy(ffw, opt);
4453 if (cs == QStyleHelper::SizeDefault)
4454 cs = QStyleHelper::SizeLarge;
4455 const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, w);
4456 const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, opt, w);
4457 d->drawFocusRing(p, opt->rect, hMargin, vMargin, QMacStylePrivate::CocoaControl(ct, cs));
4459 case CE_MenuEmptyArea:
4461 if (qobject_cast<
const QAbstractItemView *>(w))
4462 proxy()->drawPrimitive(PE_PanelMenu, opt, p, w);
4466 case CE_MenuHMargin:
4467 case CE_MenuVMargin:
4468 case CE_MenuTearoff:
4469 case CE_MenuScroller:
4470 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
4471 const bool active = mi->state & State_Selected;
4473 p->fillRect(mi->rect, mi->palette.highlight());
4475 const QStyleHelper::WidgetSizePolicy widgetSize = d->aquaSizeConstrain(opt, w);
4477 if (ce == CE_MenuTearoff) {
4478 p->setPen(QPen(mi->palette.dark().color(), 1, Qt::DashLine));
4479 p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2 - 1,
4480 mi->rect.x() + mi->rect.width() - 4,
4481 mi->rect.y() + mi->rect.height() / 2 - 1);
4482 p->setPen(QPen(mi->palette.light().color(), 1, Qt::DashLine));
4483 p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2,
4484 mi->rect.x() + mi->rect.width() - 4,
4485 mi->rect.y() + mi->rect.height() / 2);
4486 }
else if (ce == CE_MenuScroller) {
4487 const QSize scrollerSize = QSize(10, 8);
4488 const int scrollerVOffset = 5;
4489 const int left = mi->rect.x() + (mi->rect.width() - scrollerSize.width()) / 2;
4490 const int right = left + scrollerSize.width();
4493 if (opt->state & State_DownArrow) {
4494 bottom = mi->rect.y() + scrollerVOffset;
4495 top = bottom + scrollerSize.height();
4497 bottom = mi->rect.bottom() - scrollerVOffset;
4498 top = bottom - scrollerSize.height();
4501 p->setRenderHint(QPainter::Antialiasing);
4503 path.moveTo(left, bottom);
4504 path.lineTo(right, bottom);
4505 path.lineTo((left + right) / 2, top);
4506 p->fillPath(path, opt->palette.buttonText());
4508 }
else if (ce != CE_MenuItem) {
4512 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
4513 CGColorRef separatorColor = [NSColor quaternaryLabelColor].CGColor;
4514 const QRect separatorRect = QRect(mi->rect.left(), mi->rect.center().y(), mi->rect.width(), 2);
4515 p->fillRect(separatorRect, qt_mac_toQColor(separatorColor));
4519 const int maxpmw = mi->maxIconWidth;
4520 const bool enabled = mi->state & State_Enabled;
4522 int xpos = mi->rect.x() + 18;
4523 int checkcol = maxpmw;
4525 p->setPen(mi->palette.text().color());
4527 p->setPen(mi->palette.highlightedText().color());
4529 p->setPen(mi->palette.buttonText().color());
4532 QStyleOption checkmarkOpt;
4533 checkmarkOpt.initFrom(w);
4538 checkmarkOpt.rect = QRect(xp, mi->rect.y() - checkmarkOpt.fontMetrics.descent(), mw, mh);
4540 checkmarkOpt.state.setFlag(State_On, active);
4541 checkmarkOpt.state.setFlag(State_Enabled, enabled);
4542 if (widgetSize == QStyleHelper::SizeMini)
4543 checkmarkOpt.state |= State_Mini;
4544 else if (widgetSize == QStyleHelper::SizeSmall)
4545 checkmarkOpt.state |= State_Small;
4548 checkmarkOpt.palette.setColor(QPalette::HighlightedText, p->pen().color());
4549 checkmarkOpt.palette.setColor(QPalette::Text, p->pen().color());
4551 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &checkmarkOpt, p, w);
4553 if (!mi->icon.isNull()) {
4554 QIcon::Mode mode = (mi->state & State_Enabled) ? QIcon::Normal
4557 int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize);
4558 QSize iconSize(smallIconSize, smallIconSize);
4559#if QT_CONFIG(combobox)
4560 if (
const QComboBox *comboBox = qobject_cast<
const QComboBox *>(w)) {
4561 iconSize = comboBox->iconSize();
4564 QPixmap pixmap = mi->icon.pixmap(iconSize, p->device()->devicePixelRatio(), mode);
4565 QRect cr(xpos, mi->rect.y(), checkcol, mi->rect.height());
4566 QSize size = pixmap.deviceIndependentSize().toSize();
4567 QRect pmr(QPoint(0, 0), size);
4568 pmr.moveCenter(cr.center());
4569 p->drawPixmap(pmr.topLeft(), pixmap);
4570 xpos += size.width() + 6;
4573 QString s = mi->text;
4574 const auto text_flags = Qt::AlignVCenter | Qt::TextHideMnemonic
4575 | Qt::TextSingleLine | Qt::AlignAbsolute;
4576 int yPos = mi->rect.y();
4577 if (widgetSize == QStyleHelper::SizeMini)
4580 const bool isSubMenu = mi->menuItemType == QStyleOptionMenuItem::SubMenu;
4581 const int tabwidth = isSubMenu ? 9 : mi->reservedShortcutWidth;
4583 QString rightMarginText;
4585 rightMarginText = QStringLiteral(
"\u25b6\ufe0e");
4588 const int tabIndex = s.indexOf(QLatin1Char(
'\t'));
4589 if (tabIndex >= 0) {
4591 rightMarginText = s.mid(tabIndex + 1);
4592 s = s.left(tabIndex);
4596 if (!rightMarginText.isEmpty()) {
4597 p->setFont(qt_app_fonts_hash()->value(
"QMenuItem", p->font()));
4600 p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags | Qt::AlignRight, rightMarginText);
4604 const QKeySequence seq = QKeySequence::fromString(rightMarginText, QKeySequence::NativeText);
4605 if (seq.count() == 1) {
4607 const int maxKeyWidth = p->fontMetrics().maxWidth();
4608 const QChar key = rightMarginText.at(rightMarginText.length() - 1);
4609 const QString modifiers = rightMarginText.left(rightMarginText.size() - 1);
4610 p->drawText(xp + tabwidth - maxKeyWidth, yPos, maxKeyWidth, mi->rect.height(), text_flags, key);
4612 p->drawText(xp, yPos, tabwidth - maxKeyWidth, mi->rect.height(),
4613 text_flags | Qt::AlignRight | Qt::TextDontClip, modifiers);
4615 p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags, rightMarginText);
4622 QFont myFont = mi->font;
4628 myFont.setPointSizeF(QFontInfo(mi->font).pointSizeF());
4633 const auto *fontEngine = QFontPrivate::get(myFont)->engineForScript(QChar::Script_Common);
4634 Q_ASSERT(fontEngine);
4635 if (fontEngine->type() == QFontEngine::Multi) {
4636 fontEngine =
static_cast<
const QFontEngineMulti *>(fontEngine)->engine(0);
4637 Q_ASSERT(fontEngine);
4639 if (fontEngine->type() == QFontEngine::Mac) {
4640 NSFont *f = (NSFont *)(CTFontRef)fontEngine->handle();
4643 const auto pc = p->pen().color();
4644 NSColor *c = [NSColor colorWithSRGBRed:pc.redF()
4649 s = qt_mac_removeMnemonics(s);
4651 QMacCGContext cgCtx(p);
4652 d->setupNSGraphicsContext(cgCtx, YES);
4658 [s.toNSString() drawAtPoint:CGPointMake(xpos, yPos)
4659 withAttributes:@{ NSFontAttributeName:f, NSForegroundColorAttributeName:c,
4660 NSObliquenessAttributeName: [NSNumber numberWithDouble: myFont.italic() ? 0.3 : 0.0],
4661 NSUnderlineStyleAttributeName: [NSNumber numberWithInt: myFont.underline() ? NSUnderlineStyleSingle
4662 : NSUnderlineStyleNone],
4663 NSStrikethroughStyleAttributeName: [NSNumber numberWithInt: myFont.strikeOut() ? NSUnderlineStyleSingle
4664 : NSUnderlineStyleNone]}];
4666 d->restoreNSGraphicsContext(cgCtx);
4669 p->drawText(xpos, yPos, mi->rect.width() - xm - tabwidth + 1,
4670 mi->rect.height(), text_flags, s);
4676 case CE_MenuBarItem:
4677 case CE_MenuBarEmptyArea:
4678 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
4679 const bool selected = (opt->state & State_Selected) && (opt->state & State_Enabled) && (opt->state & State_Sunken);
4680 const QBrush bg = selected ? mi->palette.highlight() : mi->palette.window();
4681 p->fillRect(mi->rect, bg);
4683 if (ce != CE_MenuBarItem)
4686 if (!mi->icon.isNull()) {
4687 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
4688 drawItemPixmap(p, mi->rect,
4689 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip
4690 | Qt::TextSingleLine,
4691 mi->icon.pixmap(QSize(iconExtent, iconExtent), p->device()->devicePixelRatio(),
4692 (mi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled));
4694 drawItemText(p, mi->rect,
4695 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip
4696 | Qt::TextSingleLine,
4697 mi->palette, mi->state & State_Enabled,
4698 mi->text, selected ? QPalette::HighlightedText : QPalette::ButtonText);
4702 case CE_ProgressBarLabel:
4703 case CE_ProgressBarGroove:
4706 case CE_ProgressBarContents:
4707 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
4708 const bool isIndeterminate = (pb->minimum == 0 && pb->maximum == 0);
4709 const bool vertical = !(pb->state & QStyle::State_Horizontal);
4710 const bool inverted = pb->invertedAppearance;
4711 bool reverse = (!vertical && (pb->direction == Qt::RightToLeft));
4714 QRect rect = pb->rect;
4716 const auto aquaSize = d->effectiveAquaSizeConstrain(opt, w);
4717 const QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject));
4718 if (isIndeterminate) {
4726 if (!animation && opt->styleObject) {
4727 auto *animation =
new QProgressStyleAnimation(d->animateSpeed(QMacStylePrivate::AquaProgressBar), opt->styleObject);
4729 animation->setFrameRate(QStyleAnimation::FifteenFps);
4730 d->startAnimation(animation);
4733 if (qt_apple_runningWithLiquidGlass()) {
4734 d->drawProgressBar(p, pb);
4737 rect = rect.transposed();
4738 d->setupNSGraphicsContext(cg, NO);
4739 d->setupVerticalInvertedXform(cg, reverse, vertical, rect.toCGRect());
4741 =
static_cast<QIndeterminateProgressIndicator *>(
4742 d->cocoaControl({ QMacStylePrivate::ProgressIndicator_Indeterminate, aquaSize }))) {
4743 [ipi startAnimation];
4744 [ipi drawWithFrame:rect.toCGRect() inView:d->backingStoreNSView];
4746 d->restoreNSGraphicsContext(cg);
4750 d->stopAnimation(opt->styleObject);
4752 =
static_cast<QIndeterminateProgressIndicator *>(
4753 d->cocoaControl({ QMacStylePrivate::ProgressIndicator_Indeterminate, aquaSize })))
4754 [ipi stopAnimation];
4756 if (qt_apple_runningWithLiquidGlass()) {
4757 d->drawProgressBar(p, pb);
4760 rect = rect.transposed();
4761 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::ProgressIndicator_Determinate, aquaSize);
4762 auto *pi =
static_cast<NSProgressIndicator *>(d->cocoaControl(cw));
4763 d->drawNSViewInRect(pi, rect, p, ^(CGContextRef ctx,
const CGRect &cgrect) {
4764 d->setupVerticalInvertedXform(ctx, reverse, vertical, cgrect);
4765 pi.minValue = pb->minimum;
4766 pi.maxValue = pb->maximum;
4767 pi.doubleValue = pb->progress;
4768 [pi drawRect:cgrect]; });
4775#ifndef QT_NO_MDIAREA
4776 if (!w || !qobject_cast<QMdiSubWindow *>(w->parentWidget()))
4780 if (w->testAttribute(Qt::WA_MacOpaqueSizeGrip))
4781 p->fillRect(opt->rect, opt->palette.window());
4783 QPen lineColor = QColor(82, 82, 82, 192);
4784 lineColor.setWidth(1);
4786 p->setRenderHint(QPainter::Antialiasing);
4787 p->setPen(lineColor);
4788 const Qt::LayoutDirection layoutDirection = w ? w->layoutDirection() : qApp->layoutDirection();
4789 const int NumLines = 3;
4790 for (
int l = 0; l < NumLines; ++l) {
4791 const int offset = (l * 4 + 3);
4793 if (layoutDirection == Qt::LeftToRight) {
4794 start = QPoint(opt->rect.width() - offset, opt->rect.height() - 1);
4795 end = QPoint(opt->rect.width() - 1, opt->rect.height() - offset);
4797 start = QPoint(offset, opt->rect.height() - 1);
4798 end = QPoint(1, opt->rect.height() - offset);
4800 p->drawLine(start, end);
4806 if (opt->rect.width() > 1 && opt->rect.height() > 1) {
4807 const bool isVertical = !(opt->state & QStyle::State_Horizontal);
4809 const auto ct = isVertical ? QMacStylePrivate::SplitView_Horizontal : QMacStylePrivate::SplitView_Vertical;
4810 const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
4811 auto *sv =
static_cast<NSSplitView *>(d->cocoaControl(cw));
4812 sv.frame = opt->rect.toCGRect();
4813 d->drawNSViewInRect(sv, opt->rect, p, ^(CGContextRef,
const CGRect &rect) {
4814 [sv drawDividerInRect:rect];
4817 QPen oldPen = p->pen();
4818 p->setPen(opt->palette.dark().color());
4819 if (opt->state & QStyle::State_Horizontal)
4820 p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
4822 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
4827 if (
const QStyleOptionRubberBand *rubber = qstyleoption_cast<
const QStyleOptionRubberBand *>(opt)) {
4828 QColor fillColor(opt->palette.color(QPalette::Disabled, QPalette::Highlight));
4829 if (!rubber->opaque) {
4832 strokeColor.setHsvF(0, 0, 0.86, 1.0);
4833 fillColor.setHsvF(0, 0, 0.53, 0.25);
4834 if (opt->rect.width() * opt->rect.height() <= 3) {
4835 p->fillRect(opt->rect, strokeColor);
4837 QPen oldPen = p->pen();
4838 QBrush oldBrush = p->brush();
4839 QPen pen(strokeColor);
4841 p->setBrush(fillColor);
4842 QRect adjusted = opt->rect.adjusted(1, 1, -1, -1);
4843 if (adjusted.isValid())
4844 p->drawRect(adjusted);
4846 p->setBrush(oldBrush);
4849 p->fillRect(opt->rect, fillColor);
4853#ifndef QT_NO_TOOLBAR
4855 const QStyleOptionToolBar *toolBar = qstyleoption_cast<
const QStyleOptionToolBar *>(opt);
4857 const QColor separatorColor = darkMode ? darkModeSeparatorLine : opt->palette.dark().color();
4864#if QT_CONFIG(mainwindow)
4865 if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) {
4866 if (toolBar && toolBar->toolBarArea == Qt::TopToolBarArea && mainWindow->unifiedTitleAndToolBarOnMac()) {
4869 p->setCompositionMode(QPainter::CompositionMode_Source);
4870 p->fillRect(opt->rect, Qt::transparent);
4877 const QPoint windowToolbarEnd = w->mapTo(w->window(), opt->rect.bottomLeft());
4878 const bool isEndOfUnifiedArea = !isInMacUnifiedToolbarArea(w->window()->windowHandle(), windowToolbarEnd.y() + 1);
4879 if (isEndOfUnifiedArea) {
4880 const int margin = qt_mac_aqua_get_metric(SeparatorSize);
4881 const auto separatorRect = QRect(opt->rect.left(), opt->rect.bottom(), opt->rect.width(), margin);
4882 p->fillRect(separatorRect, separatorColor);
4890 p->fillRect(opt->rect, opt->palette.window());
4893 p->setPen(separatorColor);
4894 QRect toolbarRect = darkMode ? opt->rect.adjusted(0, 0, 0, 1) : opt->rect;
4895 if (opt->state & State_Horizontal) {
4896 p->drawLine(toolbarRect.topLeft(), toolbarRect.topRight());
4897 p->drawLine(toolbarRect.bottomLeft(), toolbarRect.bottomRight());
4899 p->drawLine(toolbarRect.topLeft(), toolbarRect.bottomLeft());
4900 p->drawLine(toolbarRect.topRight(), toolbarRect.bottomRight());
4908 QCommonStyle::drawControl(ce, opt, p, w);
4923 const QWidget *widget)
const
4925 Q_D(
const QMacStyle);
4927 const int controlSize = getControlSize(opt, widget);
4930#if QT_CONFIG(itemviews)
4931 case SE_ItemViewItemText:
4932 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
4933 int fw = proxy()->pixelMetric(PM_FocusFrameHMargin, opt, widget);
4935 rect = QCommonStyle::subElementRect(sr, opt, widget);
4936 if (vopt->features & QStyleOptionViewItem::HasDecoration)
4937 rect.adjust(-fw, 0, 0, 0);
4941 case SE_ToolBoxTabContents:
4942 rect = QCommonStyle::subElementRect(sr, opt, widget);
4944 case SE_PushButtonBevel:
4945 case SE_PushButtonContents:
4946 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
4955 const auto ct = cocoaControlType(btn, widget);
4956 const auto cs = d->effectiveAquaSizeConstrain(btn, widget);
4957 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
4958 auto frameRect = cw.adjustedControlFrame(btn->rect);
4959 if (sr == SE_PushButtonContents) {
4960 frameRect -= cw.titleMargins();
4961 }
else if (cw.type != QMacStylePrivate::Button_SquareButton) {
4962 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
4963 frameRect = QRectF::fromCGRect([pb alignmentRectForFrame:frameRect.toCGRect()]);
4964 if (cw.type == QMacStylePrivate::Button_PushButton)
4965 frameRect -= pushButtonShadowMargins[cw.size];
4966 else if (cw.type == QMacStylePrivate::Button_PullDown)
4967 frameRect -= pullDownButtonShadowMargins[cw.size];
4969 rect = frameRect.toRect();
4972 case SE_HeaderLabel: {
4973 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
4974 rect.setRect(opt->rect.x() + margin, opt->rect.y(),
4975 opt->rect.width() - margin * 2, opt->rect.height() - 2);
4976 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
4978 if (header->sortIndicator != QStyleOptionHeader::None) {
4979 if (opt->state & State_Horizontal)
4985 rect = visualRect(opt->direction, opt->rect, rect);
4988 case SE_HeaderArrow: {
4989 int h = opt->rect.height();
4990 int w = opt->rect.width();
4991 int x = opt->rect.x();
4992 int y = opt->rect.y();
4993 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
4995 if (opt->state & State_Horizontal) {
5002 rect = visualRect(opt->direction, opt->rect, rect);
5005 case SE_ProgressBarGroove:
5009 case SE_ProgressBarLabel:
5011 case SE_ProgressBarContents:
5014 case SE_TreeViewDisclosureItem: {
5020#if QT_CONFIG(tabwidget)
5021 case SE_TabWidgetLeftCorner:
5022 if (
const QStyleOptionTabWidgetFrame *twf
5023 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5024 switch (twf->shape) {
5025 case QTabBar::RoundedNorth:
5026 case QTabBar::TriangularNorth:
5027 rect = QRect(QPoint(0, 0), twf->leftCornerWidgetSize);
5029 case QTabBar::RoundedSouth:
5030 case QTabBar::TriangularSouth:
5031 rect = QRect(QPoint(0, twf->rect.height() - twf->leftCornerWidgetSize.height()),
5032 twf->leftCornerWidgetSize);
5037 rect = visualRect(twf->direction, twf->rect, rect);
5040 case SE_TabWidgetRightCorner:
5041 if (
const QStyleOptionTabWidgetFrame *twf
5042 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5043 switch (twf->shape) {
5044 case QTabBar::RoundedNorth:
5045 case QTabBar::TriangularNorth:
5046 rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(), 0),
5047 twf->rightCornerWidgetSize);
5049 case QTabBar::RoundedSouth:
5050 case QTabBar::TriangularSouth:
5051 rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(),
5052 twf->rect.height() - twf->rightCornerWidgetSize.height()),
5053 twf->rightCornerWidgetSize);
5058 rect = visualRect(twf->direction, twf->rect, rect);
5061 case SE_TabWidgetTabContents:
5062 rect = QCommonStyle::subElementRect(sr, opt, widget);
5063 if (
const auto *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5064 if (twf->lineWidth != 0) {
5065 switch (QMacStylePrivate::tabDirection(twf->shape)) {
5066 case QMacStylePrivate::North:
5067 rect.adjust(+1, +14, -1, -1);
5069 case QMacStylePrivate::South:
5070 rect.adjust(+1, +1, -1, -14);
5072 case QMacStylePrivate::West:
5073 rect.adjust(+14, +1, -1, -1);
5075 case QMacStylePrivate::East:
5076 rect.adjust(+1, +1, -14, -1);
5081 case SE_TabBarTabText:
5082 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
5083 QRect dummyIconRect;
5084 d->tabLayout(tab, widget, &rect, &dummyIconRect);
5087 case SE_TabBarTabLeftButton:
5088 case SE_TabBarTabRightButton:
5089 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
5090 bool selected = tab->state & State_Selected;
5091 int verticalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget);
5092 int horizontalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget);
5095 bool verticalTabs = tab->shape == QTabBar::RoundedEast
5096 || tab->shape == QTabBar::RoundedWest
5097 || tab->shape == QTabBar::TriangularEast
5098 || tab->shape == QTabBar::TriangularWest;
5100 QRect tr = tab->rect;
5101 if (tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::TriangularSouth)
5102 verticalShift = -verticalShift;
5104 qSwap(horizontalShift, verticalShift);
5105 horizontalShift *= -1;
5106 verticalShift *= -1;
5108 if (tab->shape == QTabBar::RoundedWest || tab->shape == QTabBar::TriangularWest)
5109 horizontalShift = -horizontalShift;
5111 tr.adjust(0, 0, horizontalShift, verticalShift);
5114 tr.setBottom(tr.bottom() - verticalShift);
5115 tr.setRight(tr.right() - horizontalShift);
5118 QSize size = (sr == SE_TabBarTabLeftButton) ? tab->leftButtonSize : tab->rightButtonSize;
5119 int w = size.width();
5120 int h = size.height();
5121 int midHeight =
static_cast<
int>(qCeil(
float(tr.height() - h) / 2));
5122 int midWidth = ((tr.width() - w) / 2);
5124 bool atTheTop =
true;
5125 switch (tab->shape) {
5126 case QTabBar::RoundedWest:
5127 case QTabBar::TriangularWest:
5128 atTheTop = (sr == SE_TabBarTabLeftButton);
5130 case QTabBar::RoundedEast:
5131 case QTabBar::TriangularEast:
5132 atTheTop = (sr == SE_TabBarTabRightButton);
5135 if (sr == SE_TabBarTabLeftButton)
5136 rect = QRect(tab->rect.x() + hpadding, midHeight, w, h);
5138 rect = QRect(tab->rect.right() - w - hpadding, midHeight, w, h);
5139 rect = visualRect(tab->direction, tab->rect, rect);
5143 rect = QRect(midWidth, tr.y() + tab->rect.height() - hpadding - h, w, h);
5145 rect = QRect(midWidth, tr.y() + hpadding, w, h);
5150 case SE_LineEditContents:
5151 rect = QCommonStyle::subElementRect(sr, opt, widget);
5152#if QT_CONFIG(combobox)
5153 if (widget && qobject_cast<
const QComboBox*>(widget->parentWidget()))
5154 rect.adjust(-1, -2, 0, 0);
5157 rect.adjust(-1, -1, 0, +1);
5159 case SE_CheckBoxLayoutItem:
5161 if (controlSize == QStyleHelper::SizeLarge) {
5162 setLayoutItemMargins(+2, +3, -9, -4, &rect, opt->direction);
5163 }
else if (controlSize == QStyleHelper::SizeSmall) {
5164 setLayoutItemMargins(+1, +5, 0 , -6, &rect, opt->direction);
5166 setLayoutItemMargins(0, +7, 0 , -6, &rect, opt->direction);
5169 case SE_ComboBoxLayoutItem:
5170#ifndef QT_NO_TOOLBAR
5171 if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
5180 if (controlSize == QStyleHelper::SizeLarge) {
5181 rect.adjust(+3, +2, -3, -4);
5182 }
else if (controlSize == QStyleHelper::SizeSmall) {
5183 setLayoutItemMargins(+2, +1, -3, -4, &rect, opt->direction);
5185 setLayoutItemMargins(+1, 0, -2, 0, &rect, opt->direction);
5189 case SE_LabelLayoutItem:
5191 setLayoutItemMargins(+1, 0 , 0, 0 , &rect, opt->direction);
5193 case SE_ProgressBarLayoutItem: {
5195 int bottom =
SIZE(3, 8, 8);
5196 if (opt->state & State_Horizontal) {
5197 rect.adjust(0, +1, 0, -bottom);
5199 setLayoutItemMargins(+1, 0, -bottom, 0, &rect, opt->direction);
5203 case SE_PushButtonLayoutItem:
5204 if (
const QStyleOptionButton *buttonOpt
5205 = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
5206 if ((buttonOpt->features & QStyleOptionButton::Flat))
5208 if ((buttonOpt->features & QStyleOptionButton::CommandLinkButton)) {
5210 if (controlSize == QStyleHelper::SizeLarge)
5211 rect.adjust(+6, +4, -6, -8);
5212 else if (controlSize == QStyleHelper::SizeSmall)
5213 rect.adjust(+5, +4, -5, -6);
5215 rect.adjust(+1, 0, -1, -2);
5220 if (controlSize == QStyleHelper::SizeLarge) {
5221 rect.adjust(0, +4, 0, -8);
5222 }
else if (controlSize == QStyleHelper::SizeSmall) {
5223 rect.adjust(0, +4, 0, -6);
5225 rect.adjust(0, 0, 0, -2);
5228 case SE_RadioButtonLayoutItem:
5230 if (controlSize == QStyleHelper::SizeLarge) {
5231 setLayoutItemMargins(+2, +2 ,
5232 0, -4 , &rect, opt->direction);
5233 }
else if (controlSize == QStyleHelper::SizeSmall) {
5234 rect.adjust(0, +6, 0 , -5);
5236 rect.adjust(0, +6, 0 , -7);
5239 case SE_SliderLayoutItem:
5240 if (
const QStyleOptionSlider *sliderOpt
5241 = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5243 if (sliderOpt->tickPosition == QSlider::NoTicks) {
5244 int above =
SIZE(3, 0, 2);
5245 int below =
SIZE(4, 3, 0);
5246 if (sliderOpt->orientation == Qt::Horizontal) {
5247 rect.adjust(0, +above, 0, -below);
5249 rect.adjust(+above, 0, -below, 0);
5251 }
else if (sliderOpt->tickPosition == QSlider::TicksAbove) {
5252 int below =
SIZE(3, 2, 0);
5253 if (sliderOpt->orientation == Qt::Horizontal) {
5254 rect.setHeight(rect.height() - below);
5256 rect.setWidth(rect.width() - below);
5258 }
else if (sliderOpt->tickPosition == QSlider::TicksBelow) {
5259 int above =
SIZE(3, 2, 0);
5260 if (sliderOpt->orientation == Qt::Horizontal) {
5261 rect.setTop(rect.top() + above);
5263 rect.setLeft(rect.left() + above);
5268 case SE_FrameLayoutItem:
5270 if (
const QFrame *frame = qobject_cast<
const QFrame *>(widget)) {
5272 switch (frame->frameStyle() & QFrame::Shape_Mask) {
5274 rect.adjust(0, +1, 0, -1);
5277 rect.adjust(+1, 0, -1, 0);
5284 case SE_GroupBoxLayoutItem:
5286 if (
const QStyleOptionGroupBox *groupBoxOpt =
5287 qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
5289
5290
5291
5292
5293 if (groupBoxOpt->subControls & (QStyle::SC_GroupBoxCheckBox
5294 | QStyle::SC_GroupBoxLabel)) {
5296 if (groupBoxOpt->subControls & QStyle::SC_GroupBoxCheckBox) {
5297 delta =
SIZE(8, 4, 4);
5299 delta =
SIZE(15, 12, 12);
5301 rect.setTop(rect.top() + delta);
5304 rect.setBottom(rect.bottom() - 1);
5306#if QT_CONFIG(tabwidget)
5307 case SE_TabWidgetLayoutItem:
5308 if (
const QStyleOptionTabWidgetFrame *tabWidgetOpt =
5309 qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5311
5312
5313
5314
5315 rect = tabWidgetOpt->rect;
5316 if (tabWidgetOpt->shape == QTabBar::RoundedNorth)
5317 rect.setTop(rect.top() + SIZE(6 , 3 , 2 ));
5321#if QT_CONFIG(dockwidget)
5322 case SE_DockWidgetCloseButton:
5323 case SE_DockWidgetFloatButton:
5324 case SE_DockWidgetTitleBarText:
5325 case SE_DockWidgetIcon: {
5326 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
5327 int buttonMargin = proxy()->pixelMetric(PM_DockWidgetTitleBarButtonMargin, opt, widget);
5328 QRect srect = opt->rect;
5330 const QStyleOptionDockWidget *dwOpt
5331 = qstyleoption_cast<
const QStyleOptionDockWidget*>(opt);
5332 bool canClose = dwOpt == 0 ?
true : dwOpt->closable;
5333 bool canFloat = dwOpt == 0 ?
false : dwOpt->floatable;
5335 const bool verticalTitleBar = dwOpt->verticalTitleBar;
5339 if (verticalTitleBar)
5340 srect = srect.transposed();
5343 int right = srect.right();
5344 int left = srect.left();
5348 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton,
5349 opt, widget).actualSize(QSize(iconSize, iconSize));
5350 sz += QSize(buttonMargin, buttonMargin);
5351 if (verticalTitleBar)
5352 sz = sz.transposed();
5353 closeRect = QRect(left,
5354 srect.center().y() - sz.height()/2,
5355 sz.width(), sz.height());
5356 left = closeRect.right() + 1;
5358 if (sr == SE_DockWidgetCloseButton) {
5365 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarNormalButton,
5366 opt, widget).actualSize(QSize(iconSize, iconSize));
5367 sz += QSize(buttonMargin, buttonMargin);
5368 if (verticalTitleBar)
5369 sz = sz.transposed();
5370 floatRect = QRect(left,
5371 srect.center().y() - sz.height()/2,
5372 sz.width(), sz.height());
5373 left = floatRect.right() + 1;
5375 if (sr == SE_DockWidgetFloatButton) {
5381 if (
const QDockWidget *dw = qobject_cast<
const QDockWidget*>(widget)) {
5383 if (dw->isFloating())
5384 icon = dw->windowIcon();
5386 && icon.cacheKey() != QApplication::windowIcon().cacheKey()) {
5387 QSize sz = icon.actualSize(QSize(rect.height(), rect.height()));
5388 if (verticalTitleBar)
5389 sz = sz.transposed();
5390 iconRect = QRect(right - sz.width(), srect.center().y() - sz.height()/2,
5391 sz.width(), sz.height());
5392 right = iconRect.left() - 1;
5395 if (sr == SE_DockWidgetIcon) {
5400 QRect textRect = QRect(left, srect.top(),
5401 right - left, srect.height());
5402 if (sr == SE_DockWidgetTitleBarText) {
5408 if (verticalTitleBar) {
5409 rect = QRect(srect.left() + rect.top() - srect.top(),
5410 srect.top() + srect.right() - rect.right(),
5411 rect.height(), rect.width());
5413 rect = visualRect(opt->direction, srect, rect);
5419 rect = QCommonStyle::subElementRect(sr, opt, widget);
5452 const QWidget *widget)
const
5454 Q_D(
const QMacStyle);
5455 QMacCGContext cg(p);
5457 qCWarning(lcMacStyle) <<
"drawComplexControl:" << cc <<
"invalid (nullptr) graphics context";
5458 QWindow *window = widget && widget->window() ? widget->window()->windowHandle() :
nullptr;
5459 d->resolveCurrentNSView(window);
5462 if (
const QStyleOptionSlider *sb = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5465 const bool drawTrack = sb->subControls & SC_ScrollBarGroove;
5466 const bool drawKnob = sb->subControls & SC_ScrollBarSlider && sb->minimum != sb->maximum;
5467 if (!drawTrack && !drawKnob)
5470 const bool isHorizontal = sb->orientation == Qt::Horizontal;
5472 if (opt && opt->styleObject && !QMacStylePrivate::scrollBars.contains(opt->styleObject))
5473 QMacStylePrivate::scrollBars.append(QPointer<QObject>(opt->styleObject));
5475 static const CGFloat knobWidths[] = { 7.0, 5.0, 5.0 };
5476 static const CGFloat expandedKnobWidths[] = { 11.0, 9.0, 9.0 };
5477 const auto cocoaSize = d->effectiveAquaSizeConstrain(opt, widget);
5478 const CGFloat maxExpandScale = expandedKnobWidths[cocoaSize] / knobWidths[cocoaSize];
5480 const QStyle *realStyle = widget ? widget->style() : proxy();
5481 const bool isTransient = realStyle->styleHint(SH_ScrollBar_Transient, opt, widget);
5483 d->stopAnimation(opt->styleObject);
5484 bool wasActive =
false;
5485 CGFloat opacity = 0.0;
5486 CGFloat expandScale = 1.0;
5487 CGFloat expandOffset = 0.0;
5488 bool shouldExpand =
false;
5490 if (QObject *styleObject = opt->styleObject) {
5491 const int oldPos = styleObject->property(
"_q_stylepos").toInt();
5492 const int oldMin = styleObject->property(
"_q_stylemin").toInt();
5493 const int oldMax = styleObject->property(
"_q_stylemax").toInt();
5494 const QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
5495 const QStyle::State oldState =
static_cast<QStyle::State>(styleObject->property(
"_q_stylestate").value<QStyle::State::Int>());
5496 const uint oldActiveControls = styleObject->property(
"_q_stylecontrols").toUInt();
5500 const bool transient = isTransient && !opt->activeSubControls && !(sb->state & State_On);
5503 oldPos != sb->sliderPosition ||
5504 oldMin != sb->minimum ||
5505 oldMax != sb->maximum ||
5506 oldRect != sb->rect ||
5507 oldState != sb->state ||
5508 oldActiveControls != sb->activeSubControls) {
5514 styleObject->setProperty(
"_q_stylepos", sb->sliderPosition);
5515 styleObject->setProperty(
"_q_stylemin", sb->minimum);
5516 styleObject->setProperty(
"_q_stylemax", sb->maximum);
5517 styleObject->setProperty(
"_q_stylerect", sb->rect);
5518 styleObject->setProperty(
"_q_stylestate",
static_cast<QStyle::State::Int>(sb->state));
5519 styleObject->setProperty(
"_q_stylecontrols",
static_cast<uint>(sb->activeSubControls));
5521 QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
5524 anim =
new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Deactivating, styleObject);
5525 d->startAnimation(anim);
5526 }
else if (anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5529 anim->setCurrentTime(0);
5531 }
else if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5532 d->stopAnimation(styleObject);
5536 QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
5537 if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5540 if (oldActiveControls)
5541 anim->setActive(
true);
5543 wasActive = anim->wasActive();
5544 opacity = anim->currentValue();
5547 shouldExpand = isTransient && (opt->activeSubControls || wasActive);
5549 if (!anim && !oldActiveControls) {
5551 anim =
new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Activating, styleObject);
5552 d->startAnimation(anim);
5554 if (anim && anim->mode() == QScrollbarStyleAnimation::Activating) {
5555 expandScale = 1.0 + (maxExpandScale - 1.0) * anim->currentValue();
5556 expandOffset = 5.5 * (1.0 - anim->currentValue());
5559 expandScale = maxExpandScale;
5565 d->setupNSGraphicsContext(cg, NO );
5567 const auto controlType = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical;
5568 const auto cw = QMacStylePrivate::CocoaControl(controlType, cocoaSize);
5569 NSScroller *scroller =
static_cast<NSScroller *>(d->cocoaControl(cw));
5571 const QColor bgColor = QStyleHelper::backgroundColor(opt->palette, widget);
5572 const bool hasDarkBg = bgColor.red() < 128 && bgColor.green() < 128 && bgColor.blue() < 128;
5576 scroller.knobStyle = hasDarkBg? NSScrollerKnobStyleLight : NSScrollerKnobStyleDark;
5578 scroller.knobStyle = NSScrollerKnobStyleDefault;
5581 scroller.scrollerStyle = isTransient ? NSScrollerStyleOverlay : NSScrollerStyleLegacy;
5583 if (!setupScroller(scroller, sb))
5587 CGContextBeginTransparencyLayerWithRect(cg, scroller.frame,
nullptr);
5588 CGContextSetAlpha(cg, opacity);
5593 if (!isTransient || opt->activeSubControls || wasActive) {
5594 CGRect trackRect = scroller.bounds;
5596 trackRect.origin.y += expandOffset;
5598 trackRect.origin.x += expandOffset;
5599 [scroller drawKnobSlotInRect:trackRect highlight:NO];
5609 const CGFloat scrollerWidth = [NSScroller scrollerWidthForControlSize:scroller.controlSize scrollerStyle:scroller.scrollerStyle];
5610 const CGFloat knobWidth = knobWidths[cocoaSize] * expandScale;
5612 const CGRect scrollerKnobRect = CGRectInset([scroller rectForPart:NSScrollerKnob], 1, 1);
5613 const CGFloat knobLength = isHorizontal ? scrollerKnobRect.size.width : scrollerKnobRect.size.height;
5614 const CGFloat knobPos = isHorizontal ? scrollerKnobRect.origin.x : scrollerKnobRect.origin.y;
5615 const CGFloat knobOffset = qRound((scrollerWidth + expandOffset - knobWidth) / 2.0);
5616 const CGFloat knobRadius = knobWidth / 2.0;
5619 knobRect = CGRectMake(knobPos, knobOffset, knobLength, knobWidth);
5621 knobRect = CGRectMake(knobOffset, knobPos, knobWidth, knobLength);
5622 QCFType<CGPathRef> knobPath = CGPathCreateWithRoundedRect(knobRect, knobRadius, knobRadius,
nullptr);
5623 CGContextAddPath(cg, knobPath);
5624 CGContextSetAlpha(cg, 0.5);
5625 CGColorRef knobColor = hasDarkBg ? NSColor.whiteColor.CGColor : NSColor.blackColor.CGColor;
5626 CGContextSetFillColorWithColor(cg, knobColor);
5627 CGContextFillPath(cg);
5629 [scroller drawKnob];
5631 if (!isTransient && opt->activeSubControls) {
5636 CGContextSetBlendMode(cg, kCGBlendModePlusDarker);
5637 [scroller drawKnob];
5643 CGContextEndTransparencyLayer(cg);
5645 d->restoreNSGraphicsContext(cg);
5649 if (
const QStyleOptionSlider *sl = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5650 const bool isHorizontal = sl->orientation == Qt::Horizontal;
5651 const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical;
5652 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
5653 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5654 auto *slider =
static_cast<NSSlider *>(d->cocoaControl(cw));
5655 if (!setupSlider(slider, sl))
5658 const bool hasTicks = sl->tickPosition != QSlider::NoTicks;
5659 const bool hasDoubleTicks = sl->tickPosition == QSlider::TicksBothSides;
5660 const bool drawKnob = sl->subControls & SC_SliderHandle;
5661 const bool drawBar = sl->subControls & SC_SliderGroove;
5662 const bool drawTicks = sl->subControls & SC_SliderTickmarks;
5663 const bool isPressed = qt_apple_runningWithLiquidGlass() ?
false : sl->state & State_Sunken;
5667 const CGRect knobRect = [slider.cell knobRectFlipped:slider.isFlipped];
5668 pressPoint.x = CGRectGetMidX(knobRect);
5669 pressPoint.y = CGRectGetMidY(knobRect);
5684 [slider.cell startTrackingAt:pressPoint inView:slider];
5685 [slider.cell startTrackingAt:pressPoint inView:slider];
5688 d->drawNSViewInRect(slider, opt->rect, p, ^(CGContextRef ctx,
const CGRect &rect) {
5691 const bool verticalFlip = !isHorizontal && !sl->upsideDown;
5694 if (sl->upsideDown) {
5695 CGContextTranslateCTM(ctx, rect.size.width, rect.origin.y);
5696 CGContextScaleCTM(ctx, -1, 1);
5698 CGContextTranslateCTM(ctx, 0, rect.origin.y);
5700 }
else if (verticalFlip) {
5701 CGContextTranslateCTM(ctx, rect.origin.x, rect.size.height);
5702 CGContextScaleCTM(ctx, 1, -1);
5705 if (hasDoubleTicks) {
5708 CGContextTranslateCTM(ctx, 0, 4);
5710 CGContextTranslateCTM(ctx, 1, 0);
5717 const bool drawAllParts = drawKnob && drawBar && (!hasTicks || drawTicks);
5718 if (drawAllParts && !hasDoubleTicks && (!verticalFlip || drawTicks)) {
5722 if (verticalFlip && drawTicks) {
5725 slider.intValue = slider.maxValue - slider.intValue + slider.minValue;
5727 [slider drawRect:CGRectZero];
5731 NSSliderCell *cell = slider.cell;
5733 const int numberOfTickMarks = slider.numberOfTickMarks;
5736 slider.numberOfTickMarks = 0;
5738 const CGRect barRect = [cell barRectFlipped:slider.isFlipped];
5740 if (!isHorizontal && !sl->upsideDown && (hasDoubleTicks || !hasTicks)) {
5748 [cell drawBarInside:barRect flipped:
true];
5750 [cell drawBarInside:barRect flipped:!verticalFlip];
5754 slider.numberOfTickMarks = numberOfTickMarks;
5757 if (hasTicks && drawTicks) {
5758 if (!drawBar && hasDoubleTicks)
5759 slider.numberOfTickMarks = numberOfTickMarks;
5761 if (qt_apple_runningWithLiquidGlass())
5762 drawTickMarks(ctx, slider, sl);
5764 [cell drawTickMarks];
5766 if (hasDoubleTicks) {
5768 CGAffineTransform tickMarksFlip;
5769 const CGRect tickMarkRect = [cell rectOfTickMarkAtIndex:0];
5771 tickMarksFlip = CGAffineTransformMakeTranslation(0, rect.size.height - tickMarkRect.size.height - 3);
5772 tickMarksFlip = CGAffineTransformScale(tickMarksFlip, 1, -1);
5774 tickMarksFlip = CGAffineTransformMakeTranslation(rect.size.width - tickMarkRect.size.width / 2, 0);
5775 tickMarksFlip = CGAffineTransformScale(tickMarksFlip, -1, 1);
5777 CGContextConcatCTM(ctx, tickMarksFlip);
5778 [cell drawTickMarks];
5779 CGContextConcatCTM(ctx, CGAffineTransformInvert(tickMarksFlip));
5786 slider.numberOfTickMarks = 0;
5787 if (qt_apple_runningWithLiquidGlass())
5788 drawSliderKnob(ctx, slider);
5798 [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO];
5799 [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO];
5803#if QT_CONFIG(spinbox)
5805 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
5806 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
5807 const auto lineEditRect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget);
5808 QStyleOptionFrame frame;
5809 static_cast<QStyleOption &>(frame) = *opt;
5810 frame.rect = lineEditRect;
5811 frame.state |= State_Sunken;
5812 frame.lineWidth = 1;
5813 frame.midLineWidth = 0;
5814 frame.features = QStyleOptionFrame::None;
5815 frame.frameShape = QFrame::Box;
5816 drawPrimitive(PE_FrameLineEdit, &frame, p, widget);
5818 if (sb->subControls & (SC_SpinBoxUp | SC_SpinBoxDown)) {
5819 const QRect updown = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget)
5820 | proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
5823 d->setupNSGraphicsContext(cg, NO);
5825 const auto aquaSize = d->effectiveAquaSizeConstrain(opt, widget);
5826 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize);
5827 NSStepperCell *cell =
static_cast<NSStepperCell *>(d->cocoaCell(cw));
5828 const auto controlSize = cell.controlSize;
5829 if (qt_apple_runningWithLiquidGlass())
5830 cell.controlSize = NSControlSizeMini;
5831 cell.enabled = (sb->state & State_Enabled);
5833 const CGRect newRect = [cell drawingRectForBounds:updown.toCGRect()];
5835 const bool upPressed = sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken);
5836 const bool downPressed = sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken);
5837 const CGFloat x = CGRectGetMidX(newRect);
5838 const CGFloat y = upPressed ? -3 : 3;
5839 const CGPoint pressPoint = CGPointMake(x, y);
5842 if (upPressed || downPressed)
5843 [cell startTrackingAt:pressPoint inView:d->backingStoreNSView];
5845 [cell drawWithFrame:newRect inView:d->backingStoreNSView];
5847 if (upPressed || downPressed)
5848 [cell stopTracking:pressPoint at:pressPoint inView:d->backingStoreNSView mouseIsUp:NO];
5850 d->restoreNSGraphicsContext(cg);
5851 if (qt_apple_runningWithLiquidGlass())
5852 cell.controlSize = controlSize;
5857#if QT_CONFIG(combobox)
5859 if (
const auto *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
5860 const bool isEnabled = combo->state & State_Enabled;
5861 const bool isPressed = combo->state & State_Sunken;
5863 const auto ct = cocoaControlType(combo, widget);
5864 const auto cs = d->effectiveAquaSizeConstrain(combo, widget);
5865 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5866 auto *cc =
static_cast<NSControl *>(d->cocoaControl(cw));
5867 cc.enabled = isEnabled;
5868 QRectF frameRect = cw.adjustedControlFrame(combo->rect);
5869 if (cw.type == QMacStylePrivate::Button_PopupButton) {
5871 auto *pb =
static_cast<NSPopUpButton *>(cc);
5873 if (cw.size == QStyleHelper::SizeSmall) {
5874 frameRect = frameRect.translated(0, 1);
5875 }
else if (cw.size == QStyleHelper::SizeMini) {
5877 frameRect = frameRect.translated(2, -0.5);
5879 pb.frame = frameRect.toCGRect();
5880 [pb highlight:isPressed];
5881 d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
5882 [pb.cell drawBezelWithFrame:r inView:pb.superview];
5884 }
else if (cw.type == QMacStylePrivate::ComboBox) {
5886 auto *cb =
static_cast<NSComboBox *>(cc);
5887 const auto frameRect = cw.adjustedControlFrame(combo->rect);
5888 cb.frame = frameRect.toCGRect();
5891 if (NSButtonCell *cell =
static_cast<NSButtonCell *>([cc.cell qt_valueForPrivateKey:@
"_buttonCell"])) {
5892 cell.highlighted = isPressed;
5897 d->drawNSViewInRect(cb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
5899 [cb.cell drawWithFrame:r inView:cb];
5903 if (combo->state & State_HasFocus) {
5905 const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, combo, widget);
5906 const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, combo, widget);
5908 if (cw.type == QMacStylePrivate::Button_PopupButton) {
5909 if (qt_apple_runningWithLiquidGlass())
5910 focusRect = QRectF::fromCGRect(qt_alignmentRectForFrame(cc.frame, cw.size, cw.type));
5912 focusRect = QRectF::fromCGRect([cc alignmentRectForFrame:cc.frame]);
5913 focusRect -= pullDownButtonShadowMargins[cw.size];
5914 if (cw.size == QStyleHelper::SizeSmall)
5915 focusRect = focusRect.translated(0, 1);
5916 else if (cw.size == QStyleHelper::SizeMini)
5917 focusRect = focusRect.translated(2, -1);
5918 }
else if (cw.type == QMacStylePrivate::ComboBox) {
5919 focusRect = frameRect - comboBoxFocusRingMargins[cw.size];
5921 d->drawFocusRing(p, focusRect, hMargin, vMargin, cw);
5927 if (
const auto *titlebar = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
5928 const bool isActive = (titlebar->state & State_Active)
5929 && (titlebar->titleBarState & State_Active);
5931 p->fillRect(opt->rect, Qt::transparent);
5932 p->setRenderHint(QPainter::Antialiasing);
5933 p->setClipRect(opt->rect, Qt::IntersectClip);
5937 const auto outerFrameRect = QRectF(opt->rect.adjusted(0, 0, 0, opt->rect.height()));
5938 QPainterPath outerFramePath = d->windowPanelPath(outerFrameRect);
5939 p->fillPath(outerFramePath, opt->palette.dark());
5941 const auto frameAdjust = 1.0 / p->device()->devicePixelRatio();
5942 const auto innerFrameRect = outerFrameRect.adjusted(frameAdjust, frameAdjust, -frameAdjust, 0);
5943 QPainterPath innerFramePath = d->windowPanelPath(innerFrameRect);
5944 p->fillPath(innerFramePath, opt->palette.button());
5946 if (titlebar->subControls & (SC_TitleBarCloseButton
5947 | SC_TitleBarMaxButton
5948 | SC_TitleBarMinButton
5949 | SC_TitleBarNormalButton)) {
5950 const bool isHovered = (titlebar->state & State_MouseOver);
5951 static const SubControl buttons[] = {
5952 SC_TitleBarCloseButton, SC_TitleBarMinButton, SC_TitleBarMaxButton
5954 for (
const auto sc : buttons) {
5955 const auto ct = d->windowButtonCocoaControl(sc);
5956 const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
5957 auto *wb =
static_cast<NSButton *>(d->cocoaControl(cw));
5958 wb.enabled = (sc & titlebar->subControls) && isActive;
5959 [wb highlight:(titlebar->state & State_Sunken) && (sc & titlebar->activeSubControls)];
5960 Q_UNUSED(isHovered);
5962 const auto buttonRect = proxy()->subControlRect(CC_TitleBar, titlebar, sc, widget);
5963 d->drawNSViewInRect(wb, buttonRect, p, ^(CGContextRef,
const CGRect &rect) {
5964 auto *wbCell =
static_cast<NSButtonCell *>(wb.cell);
5965 [wbCell drawWithFrame:rect inView:wb];
5970 if (titlebar->subControls & SC_TitleBarLabel) {
5971 const auto tr = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarLabel, widget);
5972 if (!titlebar->icon.isNull()) {
5973 const auto iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
5974 const auto iconSize = QSize(iconExtent, iconExtent);
5975 const auto iconPos = tr.x() - titlebar->icon.actualSize(iconSize).width() - qRound(titleBarIconTitleSpacing);
5977 if (iconPos < tr.right() - titleBarIconTitleSpacing)
5978 p->drawPixmap(iconPos, tr.y(), titlebar->icon.pixmap(iconSize, QIcon::Normal));
5981 if (!titlebar->text.isEmpty())
5982 drawItemText(p, tr, Qt::AlignCenter, opt->palette, isActive, titlebar->text, QPalette::Text);
5987 if (
const QStyleOptionGroupBox *gb
5988 = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
5990 QStyleOptionGroupBox groupBox(*gb);
5991 const bool flat = groupBox.features & QStyleOptionFrame::Flat;
5993 groupBox.state |= QStyle::State_Mini;
5995 groupBox.subControls = groupBox.subControls & ~SC_GroupBoxFrame;
5997 const bool didSetFont = widget && widget->testAttribute(Qt::WA_SetFont);
5998 const bool didModifySubControls = !didSetFont && QApplication::desktopSettingsAware();
5999 if (didModifySubControls)
6000 groupBox.subControls = groupBox.subControls & ~SC_GroupBoxLabel;
6001 QCommonStyle::drawComplexControl(cc, &groupBox, p, widget);
6002 if (didModifySubControls) {
6003 const QRect rect = proxy()->subControlRect(CC_GroupBox, &groupBox, SC_GroupBoxLabel, widget);
6004 const bool rtl = groupBox.direction == Qt::RightToLeft;
6005 const int alignment = Qt::TextHideMnemonic | (rtl ? Qt::AlignRight : Qt::AlignLeft);
6006 const QFont savedFont = p->font();
6007 if (!flat && d->smallSystemFont)
6008 p->setFont(*d->smallSystemFont);
6009 proxy()->drawItemText(p, rect, alignment, groupBox.palette, groupBox.state & State_Enabled, groupBox.text, QPalette::WindowText);
6011 p->setFont(savedFont);
6016 if (
const QStyleOptionToolButton *tb
6017 = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
6018#if QT_CONFIG(accessibility)
6019 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) {
6020 if (tb->subControls & SC_ToolButtonMenu) {
6021 QStyleOption arrowOpt = *tb;
6022 arrowOpt.rect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget);
6023 arrowOpt.rect.setY(arrowOpt.rect.y() + arrowOpt.rect.height() / 2);
6024 arrowOpt.rect.setHeight(arrowOpt.rect.height() / 2);
6025 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
6026 }
else if ((tb->features & QStyleOptionToolButton::HasMenu)
6027 && (tb->toolButtonStyle != Qt::ToolButtonTextOnly && !tb->icon.isNull())) {
6028 d->drawToolbarButtonArrow(tb, p);
6030 if (tb->state & State_On) {
6031 NSView *view = window ? (NSView *)window->winId() : nil;
6034 isKey = [view.window isKeyWindow];
6036 QBrush brush(brushForToolButton(isKey));
6038 path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4);
6039 p->setRenderHint(QPainter::Antialiasing);
6040 p->fillPath(path, brush);
6042 proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget);
6046 auto bflags = tb->state;
6047 if (tb->subControls & SC_ToolButton)
6048 bflags |= State_Sunken;
6049 auto mflags = tb->state;
6050 if (tb->subControls & SC_ToolButtonMenu)
6051 mflags |= State_Sunken;
6053 if (tb->subControls & SC_ToolButton) {
6054 if (bflags & (State_Sunken | State_On | State_Raised)) {
6055 const bool isEnabled = tb->state & State_Enabled;
6056 const bool isPressed = tb->state & State_Sunken;
6057 const bool isHighlighted = (tb->state & State_Active) && (tb->state & State_On);
6058 const auto ct = QMacStylePrivate::Button_PushButton;
6059 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6060 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6061 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
6062 pb.bezelStyle = NSBezelStyleShadowlessSquare;
6063 pb.frame = opt->rect.toCGRect();
6064 pb.buttonType = NSButtonTypePushOnPushOff;
6065 pb.enabled = isEnabled;
6066 [pb highlight:isPressed];
6067 pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff;
6068 const auto buttonRect = proxy()->subControlRect(cc, tb, SC_ToolButton, widget);
6069 d->drawNSViewInRect(pb, buttonRect, p, ^(CGContextRef,
const CGRect &rect) {
6070 [pb.cell drawBezelWithFrame:rect inView:pb];
6075 if (tb->subControls & SC_ToolButtonMenu) {
6076 const auto menuRect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget);
6077 QStyleOption arrowOpt = *tb;
6082 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
6083 }
else if (tb->features & QStyleOptionToolButton::HasMenu) {
6084 d->drawToolbarButtonArrow(tb, p);
6086 QRect buttonRect = proxy()->subControlRect(CC_ToolButton, tb, SC_ToolButton, widget);
6087 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
6088 QStyleOptionToolButton label = *tb;
6089 label.rect = buttonRect.adjusted(fw, fw, -fw, -fw);
6090 proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget);
6096 if (
const QStyleOptionSlider *dial = qstyleoption_cast<
const QStyleOptionSlider *>(opt))
6097 QStyleHelper::drawDial(dial, p);
6101 QCommonStyle::drawComplexControl(cc, opt, p, widget);
6193 const QWidget *widget)
const
6195 Q_D(
const QMacStyle);
6199 if (
const QStyleOptionSlider *sb = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6200 const bool isHorizontal = sb->orientation == Qt::Horizontal;
6201 const bool isReverseHorizontal = isHorizontal && (sb->direction == Qt::RightToLeft);
6203 NSScrollerPart part = NSScrollerNoPart;
6204 if (sc == SC_ScrollBarSlider) {
6205 part = NSScrollerKnob;
6206 }
else if (sc == SC_ScrollBarGroove) {
6207 part = NSScrollerKnobSlot;
6208 }
else if (sc == SC_ScrollBarSubPage || sc == SC_ScrollBarAddPage) {
6209 if ((!isReverseHorizontal && sc == SC_ScrollBarSubPage)
6210 || (isReverseHorizontal && sc == SC_ScrollBarAddPage))
6211 part = NSScrollerDecrementPage;
6213 part = NSScrollerIncrementPage;
6217 if (part != NSScrollerNoPart) {
6218 const auto ct = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical;
6219 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6220 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6221 auto *scroller =
static_cast<NSScroller *>(d->cocoaControl(cw));
6222 if (setupScroller(scroller, sb))
6223 ret = QRectF::fromCGRect([scroller rectForPart:part]).toRect();
6228 if (
const QStyleOptionSlider *sl = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6229 const bool hasTicks = sl->tickPosition != QSlider::NoTicks;
6230 const bool isHorizontal = sl->orientation == Qt::Horizontal;
6231 const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical;
6232 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6233 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6234 auto *slider =
static_cast<NSSlider *>(d->cocoaControl(cw));
6235 if (!setupSlider(slider, sl))
6238 NSSliderCell *cell = slider.cell;
6239 if (sc == SC_SliderHandle) {
6240 ret = QRectF::fromCGRect([cell knobRectFlipped:slider.isFlipped]).toRect();
6242 ret.setTop(sl->rect.top());
6243 ret.setBottom(sl->rect.bottom());
6245 ret.setLeft(sl->rect.left());
6246 ret.setRight(sl->rect.right());
6248 }
else if (sc == SC_SliderGroove) {
6249 ret = QRectF::fromCGRect([cell barRectFlipped:slider.isFlipped]).toRect();
6250 }
else if (hasTicks && sc == SC_SliderTickmarks) {
6251 const auto tickMarkRect = QRectF::fromCGRect([cell rectOfTickMarkAtIndex:0]);
6253 ret = QRect(sl->rect.left(), tickMarkRect.top(), sl->rect.width(), tickMarkRect.height());
6255 ret = QRect(tickMarkRect.left(), sl->rect.top(), tickMarkRect.width(), sl->rect.height());
6260 if (sl->upsideDown) {
6261 ret = QRect(sl->rect.right() - ret.right(), sl->rect.top(), ret.width(), sl->rect.height());
6263 ret.setTop(sl->rect.top());
6264 ret.setBottom(sl->rect.bottom());
6267 if (!sl->upsideDown) {
6268 ret = QRect(sl->rect.left(), sl->rect.bottom() - ret.bottom(), sl->rect.width(), ret.height());
6270 ret.setLeft(sl->rect.left());
6271 ret.setRight(sl->rect.right());
6277 if (
const auto *titlebar = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
6283 if (sc == SC_TitleBarLabel) {
6284 qreal labelWidth = titlebar->fontMetrics.horizontalAdvance(titlebar->text) + 1;
6285 qreal labelHeight = titlebar->fontMetrics.height();
6287 const auto lastButtonRect = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarMaxButton, widget);
6288 qreal controlsSpacing = lastButtonRect.right() + titleBarButtonSpacing;
6289 if (!titlebar->icon.isNull()) {
6290 const auto iconSize = proxy()->pixelMetric(PM_SmallIconSize);
6291 const auto actualIconSize = titlebar->icon.actualSize(QSize(iconSize, iconSize)).width();
6292 controlsSpacing += actualIconSize + titleBarIconTitleSpacing;
6295 const qreal labelPos = qMax(controlsSpacing, (opt->rect.width() - labelWidth) / 2.0);
6296 labelWidth = qMin(labelWidth, opt->rect.width() - (labelPos + titleBarTitleRightMargin));
6297 ret = QRect(labelPos, (opt->rect.height() - labelHeight) / 2,
6298 labelWidth, labelHeight);
6300 const auto currentButton = d->windowButtonCocoaControl(sc);
6301 if (currentButton == QMacStylePrivate::NoControl)
6304 QPointF buttonPos = titlebar->rect.topLeft() + QPointF(titleBarButtonSpacing, 0);
6306 for (
int ct = QMacStylePrivate::Button_WindowClose; ct <= currentButton; ct++) {
6307 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::CocoaControlType(ct),
6308 QStyleHelper::SizeLarge);
6309 auto *wb =
static_cast<NSButton *>(d->cocoaControl(cw));
6310 if (ct == currentButton)
6311 buttonSize = QSizeF::fromCGSize(wb.frame.size);
6313 buttonPos.rx() += wb.frame.size.width + titleBarButtonSpacing;
6316 const auto vOffset = (opt->rect.height() - buttonSize.height()) / 2.0;
6317 ret = QRectF(buttonPos, buttonSize).translated(0, vOffset).toRect();
6322 if (
const QStyleOptionComboBox *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
6323 const auto ct = cocoaControlType(combo, widget);
6324 const auto cs = d->effectiveAquaSizeConstrain(combo, widget);
6325 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6326 const auto editRect = QMacStylePrivate::comboboxEditBounds(cw.adjustedControlFrame(combo->rect), cw);
6329 case SC_ComboBoxEditField:{
6330 ret = editRect.toAlignedRect();
6332 case SC_ComboBoxArrow:{
6333 ret = editRect.toAlignedRect();
6334 ret.setX(ret.x() + ret.width());
6335 ret.setWidth(combo->rect.right() - ret.right());
6337 case SC_ComboBoxListBoxPopup:{
6338 if (combo->editable) {
6339 const CGRect inner = QMacStylePrivate::comboboxInnerBounds(combo->rect.toCGRect(), cw);
6340 const int comboTop = combo->rect.top();
6341 ret = QRect(qRound(inner.origin.x),
6343 qRound(inner.origin.x - combo->rect.left() + inner.size.width),
6344 editRect.bottom() - comboTop + 2);
6346 ret = QRect(combo->rect.x() + 4 - 11,
6347 combo->rect.y() + 1,
6348 editRect.width() + 10 + 11,
6358 if (
const QStyleOptionGroupBox *groupBox = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
6359 bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
6360 const bool flat = groupBox->features & QStyleOptionFrame::Flat;
6361 bool hasNoText = !checkable && groupBox->text.isEmpty();
6363 case SC_GroupBoxLabel:
6364 case SC_GroupBoxCheckBox: {
6366 const bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
6367 const bool fontIsSet = (widget && widget->testAttribute(Qt::WA_SetFont))
6368 || !QApplication::desktopSettingsAware();
6369 const int margin = flat || hasNoText ? 0 : 9;
6370 ret = groupBox->rect.adjusted(margin, 0, -margin, 0);
6372 const QFontMetricsF fm = flat || fontIsSet || !d->smallSystemFont
6373 ? QFontMetricsF(groupBox->fontMetrics)
6374 : QFontMetricsF(*d->smallSystemFont);
6375 const QSizeF s = fm.size(Qt::AlignHCenter | Qt::AlignVCenter, qt_mac_removeMnemonics(groupBox->text), 0,
nullptr);
6376 const int tw = qCeil(s.width());
6377 const int h = qCeil(fm.height());
6380 QRect labelRect = alignedRect(groupBox->direction, groupBox->textAlignment,
6382 if (flat && checkable)
6383 labelRect.moveLeft(labelRect.left() + 4);
6384 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt, widget);
6385 bool rtl = groupBox->direction == Qt::RightToLeft;
6386 if (sc == SC_GroupBoxLabel) {
6388 int newSum = indicatorWidth + 1;
6389 int newLeft = labelRect.left() + (rtl ? -newSum : newSum);
6390 labelRect.moveLeft(newLeft);
6392 labelRect.moveTop(labelRect.top() + 3);
6394 labelRect.moveTop(labelRect.top() + 4);
6396 int newLeft = labelRect.left() - (rtl ? 3 : -3);
6397 labelRect.moveLeft(newLeft);
6398 labelRect.moveTop(labelRect.top() + 3);
6400 int newLeft = labelRect.left() - (rtl ? 3 : 2);
6401 labelRect.moveLeft(newLeft);
6402 labelRect.moveTop(labelRect.top() + 4);
6407 if (sc == SC_GroupBoxCheckBox) {
6408 int left = rtl ? labelRect.right() - indicatorWidth : labelRect.left() - 1;
6409 int top = flat ? ret.top() + 1 : ret.top() + 5;
6410 ret.setRect(left, top,
6411 indicatorWidth, proxy()->pixelMetric(PM_IndicatorHeight, opt, widget));
6415 case SC_GroupBoxContents:
6416 case SC_GroupBoxFrame: {
6417 QFontMetrics fm = groupBox->fontMetrics;
6420 if (widget && !widget->testAttribute(Qt::WA_SetFont)
6421 && QApplication::desktopSettingsAware())
6422 fm = QFontMetrics(qt_app_fonts_hash()->value(
"QSmallFont", QFont()));
6427 yOffset = -qCeil(QFontMetricsF(fm).height());
6428 ret = opt->rect.adjusted(0, qCeil(QFontMetricsF(fm).height()) + yOffset, 0, 0);
6429 if (sc == SC_GroupBoxContents) {
6431 ret.adjust(3, -5, -3, -4);
6433 ret.adjust(3, 3, -3, -4);
6438 ret = QCommonStyle::subControlRect(cc, groupBox, sc, widget);
6443#if QT_CONFIG(spinbox)
6445 if (
const QStyleOptionSpinBox *spin = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
6446 QStyleHelper::WidgetSizePolicy aquaSize = d->effectiveAquaSizeConstrain(spin, widget);
6447 const auto fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin, widget);
6451 case QStyleHelper::SizeLarge:
6455 case QStyleHelper::SizeSmall:
6459 case QStyleHelper::SizeMini:
6469 case SC_SpinBoxDown: {
6470 if (spin->buttonSymbols == QAbstractSpinBox::NoButtons)
6474 const int x = spin->rect.width() - spinner_w;
6475 ret.setRect(x + spin->rect.x(), y + spin->rect.y(), spinner_w, spin->rect.height() - y * 2);
6478 case QStyleHelper::SizeLarge:
6481 case QStyleHelper::SizeSmall:
6482 hackTranslateX = -2;
6484 case QStyleHelper::SizeMini:
6485 hackTranslateX = -1;
6491 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize);
6492 NSStepperCell *cell =
static_cast<NSStepperCell *>(d->cocoaCell(cw));
6493 const CGRect outRect = [cell drawingRectForBounds:ret.toCGRect()];
6494 ret = QRectF::fromCGRect(outRect).toRect();
6498 ret.setHeight(ret.height() / 2);
6500 case SC_SpinBoxDown:
6501 ret.setY(ret.y() + ret.height() / 2);
6507 ret.translate(hackTranslateX, 0);
6508 ret = visualRect(spin->direction, spin->rect, ret);
6511 case SC_SpinBoxEditField:
6512 ret = spin->rect.adjusted(fw, fw, -fw, -fw);
6513 if (spin->buttonSymbols != QAbstractSpinBox::NoButtons) {
6514 ret.setWidth(spin->rect.width() - spinBoxSep - spinner_w);
6515 ret = visualRect(spin->direction, spin->rect, ret);
6519 ret = QCommonStyle::subControlRect(cc, spin, sc, widget);
6526 ret = QCommonStyle::subControlRect(cc, opt, sc, widget);
6527 if (sc == SC_ToolButtonMenu) {
6528#if QT_CONFIG(accessibility)
6529 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar))
6530 ret.adjust(-toolButtonArrowMargin, 0, 0, 0);
6532 ret.adjust(-1, 0, 0, 0);
6536 ret = QCommonStyle::subControlRect(cc, opt, sc, widget);
6543 const QSize &csz,
const QWidget *widget)
const
6545 Q_D(
const QMacStyle);
6547 bool useAquaGuideline =
true;
6550#if QT_CONFIG(spinbox)
6552 if (
const QStyleOptionSpinBox *vopt = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
6553 const bool hasButtons = (vopt->buttonSymbols != QAbstractSpinBox::NoButtons);
6554 const int buttonWidth = hasButtons ? proxy()->subControlRect(CC_SpinBox, vopt, SC_SpinBoxUp, widget).width() : 0;
6555 sz += QSize(buttonWidth, 0);
6559 case QStyle::CT_TabWidget:
6562 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6594#if QT_CONFIG(tabwidget)
6595 if (
const QStyleOptionTabWidgetFrame *twf
6596 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
6598 const int overlap = pixelMetric(PM_TabBarBaseOverlap, opt, widget);
6599 const int gapBetweenTabbarAndStackWidget = 2 + 14 - overlap;
6601 const auto tabDirection = QMacStylePrivate::tabDirection(twf->shape);
6602 if (tabDirection == QMacStylePrivate::North
6603 || tabDirection == QMacStylePrivate::South) {
6604 extra = QSize(2, gapBetweenTabbarAndStackWidget + 1);
6606 extra = QSize(gapBetweenTabbarAndStackWidget + 1, 2);
6612#if QT_CONFIG(tabbar)
6613 case QStyle::CT_TabBarTab:
6614 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
6615 const bool differentFont = (widget && widget->testAttribute(Qt::WA_SetFont))
6616 || !QApplication::desktopSettingsAware();
6617 const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape);
6618 const bool verticalTabs = tabDirection == QMacStylePrivate::East
6619 || tabDirection == QMacStylePrivate::West;
6621 sz = sz.transposed();
6623 int defaultTabHeight;
6624 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6626 case QStyleHelper::SizeLarge:
6627 if (tab->documentMode)
6628 defaultTabHeight = 24;
6630 defaultTabHeight = 21;
6632 if (qt_apple_runningWithLiquidGlass() && !tab->documentMode) {
6640 defaultTabHeight = 23;
6643 case QStyleHelper::SizeSmall:
6644 defaultTabHeight = 18;
6646 case QStyleHelper::SizeMini:
6647 defaultTabHeight = 16;
6653 const bool widthSet = !differentFont && tab->icon.isNull();
6655 const auto textSize = opt->fontMetrics.size(Qt::TextShowMnemonic, tab->text);
6656 sz.rwidth() = textSize.width();
6657 sz.rheight() = qMax(defaultTabHeight, textSize.height());
6659 sz.rheight() = qMax(defaultTabHeight, sz.height());
6661 sz.rwidth() += proxy()->pixelMetric(PM_TabBarTabHSpace, tab, widget);
6664 sz = sz.transposed();
6666 int maxWidgetHeight = qMax(tab->leftButtonSize.height(), tab->rightButtonSize.height());
6667 int maxWidgetWidth = qMax(tab->leftButtonSize.width(), tab->rightButtonSize.width());
6669 int widgetWidth = 0;
6670 int widgetHeight = 0;
6672 if (tab->leftButtonSize.isValid()) {
6674 widgetWidth += tab->leftButtonSize.width();
6675 widgetHeight += tab->leftButtonSize.height();
6677 if (tab->rightButtonSize.isValid()) {
6679 widgetWidth += tab->rightButtonSize.width();
6680 widgetHeight += tab->rightButtonSize.height();
6684 sz.setWidth(qMax(sz.width(), maxWidgetWidth));
6685 sz.setHeight(sz.height() + widgetHeight + padding);
6688 sz.setWidth(sz.width() + widgetWidth + padding);
6689 sz.setHeight(qMax(sz.height(), maxWidgetHeight));
6694 case QStyle::CT_PushButton: {
6695 bool isFlat =
false;
6696 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
6697 if (btn->features & QStyleOptionButton::CommandLinkButton)
6698 return QCommonStyle::sizeFromContents(ct, opt, sz, widget);
6699 isFlat = btn->features & QStyleOptionButton::Flat;
6706 const auto controlSize = d->effectiveAquaSizeConstrain(opt, widget, CT_PushButton, sz, &macsz);
6708 if (macsz.width() != -1)
6709 sz.setWidth(macsz.width());
6711 sz.rwidth() += QMacStylePrivate::PushButtonLeftOffset + QMacStylePrivate::PushButtonRightOffset + 12;
6713 if (controlSize != QStyleHelper::SizeMini)
6716 if (controlSize == QStyleHelper::SizeLarge) {
6719 if (sz.height() > 16)
6720 sz.rheight() += pushButtonDefaultHeight[QStyleHelper::SizeLarge] - 16;
6722 sz.setHeight(pushButtonDefaultHeight[QStyleHelper::SizeLarge]);
6724 if (!isFlat && !qt_apple_runningWithLiquidGlass())
6726 if (controlSize == QStyleHelper::SizeMini)
6729 sz.setHeight(pushButtonDefaultHeight[QStyleHelper::SizeSmall]);
6735 case QStyle::CT_MenuItem:
6736 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
6737 int maxpmw = mi->maxIconWidth;
6738#if QT_CONFIG(combobox)
6739 const QComboBox *comboBox = qobject_cast<
const QComboBox *>(widget);
6743 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
6747 h = mi->fontMetrics.height() + 2;
6748 if (!mi->icon.isNull()) {
6749#if QT_CONFIG(combobox)
6751 const QSize &iconSize = comboBox->iconSize();
6752 h = qMax(h, iconSize.height() + 4);
6753 maxpmw = qMax(maxpmw, iconSize.width());
6757 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
6758 h = qMax(h, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() + 4);
6762 if (mi->text.contains(QLatin1Char(
'\t')))
6764 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
6770#if QT_CONFIG(combobox)
6771 if (comboBox && comboBox->isVisible()) {
6772 QStyleOptionComboBox cmb;
6773 cmb.initFrom(comboBox);
6774 cmb.editable =
false;
6775 cmb.subControls = QStyle::SC_ComboBoxEditField;
6776 cmb.activeSubControls = QStyle::SC_None;
6777 w = qMax(w, subControlRect(QStyle::CC_ComboBox, &cmb,
6778 QStyle::SC_ComboBoxEditField,
6788 case CT_MenuBarItem:
6795 if (
const auto *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt))
6796 if (tb->features & QStyleOptionToolButton::Menu)
6800 if (
const auto *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
6801 const auto controlSize = d->effectiveAquaSizeConstrain(opt, widget);
6802 if (!cb->editable) {
6805 sz.rwidth() += QMacStylePrivate::PushButtonLeftOffset + QMacStylePrivate::PushButtonRightOffset + 24;
6807 if (controlSize != QStyleHelper::SizeMini)
6811 if (controlSize == QStyleHelper::SizeLarge && sz.height() > 16)
6812 sz.rheight() += popupButtonDefaultHeight[QStyleHelper::SizeLarge] - 16;
6820 if (controlSize == QStyleHelper::SizeMini)
6823 sz.setHeight(pushButtonDefaultHeight[controlSize]);
6829 if (proxy() ==
this) {
6832 QStyleHintReturnMask menuMask;
6833 QStyleOption myOption = *opt;
6834 myOption.rect.setSize(sz);
6835 if (proxy()->styleHint(SH_Menu_Mask, &myOption, widget, &menuMask))
6836 sz = menuMask.region.boundingRect().size();
6839 case CT_HeaderSection:{
6840 const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt);
6841 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6842 if (header->text.contains(QLatin1Char(
'\n')))
6843 useAquaGuideline =
false;
6847 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6848 const int minimumSize = 24;
6849 if (slider->orientation == Qt::Horizontal)
6850 sz = sz.expandedTo(QSize(minimumSize, sz.height()));
6852 sz = sz.expandedTo(QSize(sz.width(), minimumSize));
6855#if QT_CONFIG(itemviews)
6856 case CT_ItemViewItem:
6857 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
6858 sz = QCommonStyle::sizeFromContents(ct, vopt, csz, widget);
6859 sz.setHeight(sz.height() + 2);
6865 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6868 if (useAquaGuideline && ct != CT_PushButton) {
6871 if (d->aquaSizeConstrain(opt, widget, ct, sz, &macsz) != QStyleHelper::SizeDefault) {
6872 if (macsz.width() != -1)
6873 sz.setWidth(macsz.width());
6874 if (macsz.height() != -1)
6875 sz.setHeight(macsz.height());
6881 if (
const QStyleOptionComboBox *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)){
6882 if (combo->editable) {
6883 const auto widgetSize = d->aquaSizeConstrain(opt, widget);
6884 QMacStylePrivate::CocoaControl cw;
6885 cw.type = combo->editable ? QMacStylePrivate::ComboBox : QMacStylePrivate::Button_PopupButton;
6886 cw.size = widgetSize;
6887 const CGRect diffRect = QMacStylePrivate::comboboxInnerBounds(CGRectZero, cw);
6888 sz.rwidth() -= qRound(diffRect.size.width);
6889 sz.rheight() -= qRound(diffRect.size.height);