3191 const QWidget *w)
const
3193 Q_D(
const QMacStyle);
3194 QMacCGContext cg(p);
3196 qCWarning(lcMacStyle) <<
"drawPrimitive:" << pe <<
"invalid (nullptr) graphics context";
3198 QWindow *window = w && w->window() ? w->window()->windowHandle() :
nullptr;
3199 d->resolveCurrentNSView(window);
3201 case PE_IndicatorArrowUp:
3202 case PE_IndicatorArrowDown:
3203 case PE_IndicatorArrowRight:
3204 case PE_IndicatorArrowLeft: {
3206 p->setRenderHint(QPainter::Antialiasing);
3207 const int xOffset = 1;
3208 qreal halfSize = 0.5 * qMin(opt->rect.width(), opt->rect.height());
3209 const qreal penWidth = qMax(halfSize / 3.0, 1.25);
3210#if QT_CONFIG(toolbutton)
3211 if (
const QToolButton *tb = qobject_cast<
const QToolButton *>(w)) {
3213 if (tb->arrowType() != Qt::NoArrow
3214 || tb->popupMode() == QToolButton::MenuButtonPopup)
3215 halfSize -= penWidth;
3219 QTransform transform;
3220 transform.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2);
3224 case PE_IndicatorArrowDown:
3226 case PE_IndicatorArrowUp:
3227 transform.rotate(180);
3229 case PE_IndicatorArrowLeft:
3230 transform.rotate(90);
3232 case PE_IndicatorArrowRight:
3233 transform.rotate(-90);
3236 p->setTransform(transform);
3238 path.moveTo(-halfSize, -halfSize * 0.5);
3239 path.lineTo(0.0, halfSize * 0.5);
3240 path.lineTo(halfSize, -halfSize * 0.5);
3242 const QPen arrowPen(opt->palette.text(), penWidth,
3243 Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
3244 p->strokePath(path, arrowPen);
3247#if QT_CONFIG(tabbar)
3248 case PE_FrameTabBarBase:
3249 if (
const QStyleOptionTabBarBase *tbb
3250 = qstyleoption_cast<
const QStyleOptionTabBarBase *>(opt)) {
3251 if (tbb->documentMode) {
3253 drawTabBase(p, tbb, w);
3257#if QT_CONFIG(tabwidget)
3258 QRegion region(tbb->rect);
3259 region -= tbb->tabBarRect.adjusted(3, 0, -3, 0);
3261 p->setClipRegion(region);
3262 QStyleOptionTabWidgetFrame twf;
3263 twf.QStyleOption::operator=(*tbb);
3264 twf.shape = tbb->shape;
3265 switch (QMacStylePrivate::tabDirection(twf.shape)) {
3266 case QMacStylePrivate::North:
3267 twf.rect = twf.rect.adjusted(0, 0, 0, 10);
3269 case QMacStylePrivate::South:
3270 twf.rect = twf.rect.adjusted(0, -10, 0, 0);
3272 case QMacStylePrivate::West:
3273 twf.rect = twf.rect.adjusted(0, 0, 10, 0);
3275 case QMacStylePrivate::East:
3276 twf.rect = twf.rect.adjusted(0, -10, 0, 0);
3279 proxy()->drawPrimitive(PE_FrameTabWidget, &twf, p, w);
3285 case PE_PanelTipLabel:
3286 p->fillRect(opt->rect, opt->palette.brush(QPalette::ToolTipBase));
3288 case PE_FrameGroupBox:
3289 if (
const auto *groupBox = qstyleoption_cast<
const QStyleOptionFrame *>(opt))
3290 if (groupBox->features & QStyleOptionFrame::Flat) {
3291 QCommonStyle::drawPrimitive(pe, groupBox, p, w);
3294#if QT_CONFIG(tabwidget)
3296 case PE_FrameTabWidget:
3299 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Box, QStyleHelper::SizeLarge);
3300 auto *box =
static_cast<NSBox *>(d->cocoaControl(cw));
3314 auto adjustedRect = opt->rect;
3315 bool needTranslation =
false;
3317 if (!qt_apple_runningWithLiquidGlass() && !
isDarkMode()) {
3330 adjustedRect.adjust(0, 0, 6, 6);
3331 needTranslation =
true;
3333 d->drawNSViewInRect(box, adjustedRect, p, ^(CGContextRef ctx,
const CGRect &rect) {
3334#if QT_CONFIG(tabwidget)
3335 if (qobject_cast<QTabWidget *>(opt->styleObject))
3336 clipTabBarFrame(opt,
this, ctx);
3338 CGContextTranslateCTM(ctx, 0, rect.origin.y + rect.size.height);
3339 CGContextScaleCTM(ctx, 1, -1);
3340 if ([box isMemberOfClass:QDarkNSBox.
class]) {
3341 [box drawRect:rect];
3343 if (needTranslation)
3344 CGContextTranslateCTM(ctx, -3.0, 5.0);
3345 [box displayRectIgnoringOpacity:box.bounds inContext:NSGraphicsContext.currentContext];
3350 case PE_IndicatorToolBarSeparator: {
3352 if (opt->state & State_Horizontal) {
3353 int xpoint = opt->rect.center().x();
3354 path.moveTo(xpoint + 0.5, opt->rect.top() + 1);
3355 path.lineTo(xpoint + 0.5, opt->rect.bottom());
3357 int ypoint = opt->rect.center().y();
3358 path.moveTo(opt->rect.left() + 2 , ypoint + 0.5);
3359 path.lineTo(opt->rect.right() + 1, ypoint + 0.5);
3361 QPainterPathStroker theStroker;
3362 theStroker.setCapStyle(Qt::FlatCap);
3363 theStroker.setDashPattern(QVector<qreal>() << 1 << 2);
3364 path = theStroker.createStroke(path);
3365 const auto dark =
isDarkMode() ? opt->palette.dark().color().darker()
3366 : QColor(0, 0, 0, 119);
3367 p->fillPath(path, dark);
3370 case PE_FrameWindow:
3371 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
3372 if (qobject_cast<
const QMdiSubWindow*>(w)) {
3374 p->setPen(QPen(frame->palette.dark().color(), frame->lineWidth));
3375 p->setBrush(frame->palette.window());
3376 p->drawRect(frame->rect);
3381 case PE_IndicatorDockWidgetResizeHandle: {
3384 if (opt->state & State_Horizontal) {
3385 p->setPen(QColor(160, 160, 160));
3386 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3388 p->setPen(QColor(145, 145, 145));
3389 p->drawLine(opt->rect.topRight(), opt->rect.bottomRight());
3393 case PE_IndicatorToolBarHandle: {
3396 int x = opt->rect.x() + 6;
3397 int y = opt->rect.y() + 7;
3398 static const int RectHeight = 2;
3399 if (opt->state & State_Horizontal) {
3400 while (y < opt->rect.height() - RectHeight - 5) {
3402 path.addEllipse(x, y, RectHeight, RectHeight);
3406 while (x < opt->rect.width() - RectHeight - 5) {
3408 path.addEllipse(x, y, RectHeight, RectHeight);
3412 p->setPen(Qt::NoPen);
3413 QColor dark = opt->palette.dark().color().darker();
3414 dark.setAlphaF(0.50);
3415 p->fillPath(path, dark);
3420 case PE_IndicatorHeaderArrow:
3421 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
3423 if (header->sortIndicator != QStyleOptionHeader::None)
3424 proxy()->drawPrimitive(
3425 (header->sortIndicator == QStyleOptionHeader::SortDown) ?
3426 PE_IndicatorArrowUp : PE_IndicatorArrowDown, header, p, w);
3429 case PE_IndicatorMenuCheckMark: {
3433 if (opt->state & State_On)
3434 pc = opt->palette.highlightedText().color();
3436 pc = opt->palette.text().color();
3438 QCFType<CGColorRef> checkmarkColor = CGColorCreateGenericRGB(
static_cast<CGFloat>(pc.redF()),
3439 static_cast<CGFloat>(pc.greenF()),
3440 static_cast<CGFloat>(pc.blueF()),
3441 static_cast<CGFloat>(pc.alphaF()));
3447 const CTFontUIFontType fontType = (opt->state & State_Mini) ? kCTFontUIFontMiniSystem :
3448 (opt->state & State_Small) ? kCTFontUIFontSmallSystem :
3449 kCTFontUIFontMenuItemMark;
3453 const CGFloat fontSize = fontType == kCTFontUIFontMenuItemMark ? opt->fontMetrics.height() : 0.0;
3454 QCFType<CTFontRef> checkmarkFont = CTFontCreateUIFontForLanguage(fontType, fontSize, NULL);
3456 CGContextSaveGState(cg);
3457 CGContextSetShouldSmoothFonts(cg, NO);
3460 const CGFloat vOffset = (opt->state & State_Mini) ? 0.0 :
3461 (opt->state & State_Small) ? 1.0 :
3464 CGContextTranslateCTM(cg, 0, opt->rect.bottom());
3465 CGContextScaleCTM(cg, 1, -1);
3467 CGContextTranslateCTM(cg, opt->rect.x(), vOffset);
3471 static const CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName };
3472 static const int numValues =
sizeof(keys) /
sizeof(keys[0]);
3473 const CFTypeRef values[] = { (CFTypeRef)checkmarkFont, (CFTypeRef)checkmarkColor };
3474 static_assert((
sizeof(values) /
sizeof(values[0])) == numValues);
3475 QCFType<CFDictionaryRef> attributes = CFDictionaryCreate(kCFAllocatorDefault, (
const void **)keys, (
const void **)values,
3476 numValues, NULL, NULL);
3478 QCFType<CFAttributedStringRef> checkmarkString = CFAttributedStringCreate(kCFAllocatorDefault, (CFStringRef)@
"\u2713", attributes);
3479 QCFType<CTLineRef> line = CTLineCreateWithAttributedString(checkmarkString);
3481 CTLineDraw((CTLineRef)line, cg);
3484 CGContextRestoreGState(cg);
3486 case PE_IndicatorItemViewItemCheck:
3487 case PE_IndicatorRadioButton:
3488 case PE_IndicatorCheckBox: {
3489 const bool isEnabled = opt->state & State_Enabled;
3490 const bool isPressed = opt->state & State_Sunken;
3491 const bool isRadioButton = (pe == PE_IndicatorRadioButton);
3492 const auto ct = isRadioButton ? QMacStylePrivate::Button_RadioButton : QMacStylePrivate::Button_CheckBox;
3493 const auto cs = d->effectiveAquaSizeConstrain(opt, w);
3494 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
3495 auto *tb =
static_cast<NSButton *>(d->cocoaControl(cw));
3496 tb.enabled = isEnabled;
3497 tb.state = (opt->state & State_NoChange) ? NSControlStateValueMixed :
3498 (opt->state & State_On) ? NSControlStateValueOn : NSControlStateValueOff;
3499 [tb highlight:isPressed];
3500 const auto vOffset = [=] {
3502 if (cs == QStyleHelper::SizeMini)
3503 return ct == QMacStylePrivate::Button_CheckBox ? -0.5 : 0.5;
3505 return cs == QStyleHelper::SizeSmall ? 0.5 : 0.0;
3507 d->drawNSViewInRect(tb, opt->rect, p, ^(CGContextRef ctx,
const CGRect &rect) {
3508 CGContextTranslateCTM(ctx, 0, vOffset);
3509 [tb.cell drawInteriorWithFrame:rect inView:tb];
3512 case PE_FrameFocusRect:
3515 case PE_IndicatorBranch: {
3516 if (!(opt->state & State_Children))
3520 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Button_Disclosure, QStyleHelper::SizeLarge);
3521 NSButtonCell *triangleCell =
static_cast<NSButtonCell *>(d->cocoaCell(cw));
3522 [triangleCell setState:(opt->state & State_Open) ? NSControlStateValueOn : NSControlStateValueOff];
3523 bool viewHasFocus = (w && w->hasFocus()) || (opt->state & State_HasFocus);
3524 [triangleCell setBackgroundStyle:((opt->state & State_Selected) && viewHasFocus) ? NSBackgroundStyleEmphasized : NSBackgroundStyleNormal];
3525 [triangleCell setUserInterfaceLayoutDirection:qt_macLayoutDirectionFromQt(opt->direction)];
3527 d->setupNSGraphicsContext(cg, NO);
3530 CGRect rect = CGRectMake(qtRect.x() + 1, qtRect.y(), qtRect.width(), qtRect.height());
3531 CGContextTranslateCTM(cg, rect.origin.x, rect.origin.y + rect.size.height);
3532 CGContextScaleCTM(cg, 1, -1);
3533 CGContextTranslateCTM(cg, -rect.origin.x, -rect.origin.y);
3535 [triangleCell drawBezelWithFrame:NSRectFromCGRect(rect) inView:[triangleCell controlView]];
3537 d->restoreNSGraphicsContext(cg);
3541 QPen oldPen = p->pen();
3542 p->setPen(opt->palette.base().color().darker(140));
3543 p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
3544 p->setPen(opt->palette.base().color().darker(180));
3545 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3549 case PE_FrameLineEdit:
3550 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
3551 if (frame->state & State_Sunken) {
3552 const bool isEnabled = opt->state & State_Enabled;
3553 const bool isReadOnly = opt->state & State_ReadOnly;
3554 const bool isRounded = frame->features & QStyleOptionFrame::Rounded;
3555 const auto cs = d->effectiveAquaSizeConstrain(opt, w, CT_LineEdit);
3556 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::TextField, cs);
3557 auto *tf =
static_cast<NSTextField *>(d->cocoaControl(cw));
3558 tf.enabled = isEnabled;
3559 tf.editable = !isReadOnly;
3560 const QColor bgColor = frame->palette.brush(QPalette::Base).color();
3561 bool hasCustomBackground =
false;
3562 if (qt_apple_runningWithLiquidGlass()) {
3571 NSColor *sysColor = [NSColor.textBackgroundColor colorUsingColorSpace:NSColorSpace.sRGBColorSpace];
3572 const QColor defaultColor = QColor::fromRgbF(sysColor.redComponent, sysColor.greenComponent,
3573 sysColor.blueComponent, sysColor.alphaComponent);
3574 hasCustomBackground = bgColor != defaultColor;
3577 if (hasCustomBackground) {
3581 static_cast<NSTextFieldCell *>(tf.cell).bezelStyle = isRounded ? NSTextFieldRoundedBezel : NSTextFieldSquareBezel;
3582 tf.frame = opt->rect.toCGRect();
3583 d->drawNSViewInRect(tf, opt->rect, p, ^(CGContextRef,
const CGRect &rect) {
3584 if (!isDarkMode() || hasCustomBackground) {
3591 CGContextRef cgContext = NSGraphicsContext.currentContext.CGContext;
3595 if (cgContext ?
bool(CGBitmapContextGetColorSpace(cgContext)) :
false) {
3596 tf.drawsBackground = YES;
3597 tf.backgroundColor = [NSColor colorWithSRGBRed:bgColor.redF()
3598 green:bgColor.greenF()
3599 blue:bgColor.blueF()
3600 alpha:bgColor.alphaF()];
3601 if (bgColor.alpha() != 255) {
3608 CGRect fixedRect = rect;
3609 if (qt_apple_runningWithLiquidGlass()) {
3614 fixedRect = CGRectInset(rect, 1., 1.);
3616 [tf.cell drawWithFrame:fixedRect inView:tf];
3619 QCommonStyle::drawPrimitive(pe, opt, p, w);
3623 case PE_PanelLineEdit:
3625 const QStyleOptionFrame *panel = qstyleoption_cast<
const QStyleOptionFrame *>(opt);
3626 if (
isDarkMode() || (panel && panel->lineWidth <= 0)) {
3632 QCommonStyle::drawPrimitive(pe, opt, p, w);
3637 drawPrimitive(PE_FrameLineEdit, opt, p, w);
3643#if QT_CONFIG(lineedit)
3644 if ((opt->state & State_HasFocus) && !qobject_cast<
const QLineEdit*>(w)) {
3645 int vmargin = pixelMetric(QStyle::PM_FocusFrameVMargin);
3646 int hmargin = pixelMetric(QStyle::PM_FocusFrameHMargin);
3647 QStyleOptionFrame focusFrame = *panel;
3648 focusFrame.rect = panel->rect.adjusted(-hmargin, -vmargin, hmargin, vmargin);
3649 drawControl(CE_FocusFrame, &focusFrame, p, w);
3655 case PE_PanelScrollAreaCorner: {
3656 const QBrush brush(opt->palette.brush(QPalette::Base));
3657 p->fillRect(opt->rect, brush);
3658 p->setPen(QPen(QColor(217, 217, 217)));
3659 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3660 p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
3662 case PE_FrameStatusBarItem:
3664#if QT_CONFIG(tabbar)
3665 case PE_IndicatorTabClose: {
3667 QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget());
3668 const QWidget *closeBtn = w;
3672 tabBar = qobject_cast<QTabBar *>(
const_cast<QWidget*>(w));
3673 closeBtn =
decltype(closeBtn)(property(
"_q_styleSheetRealCloseButton").value<
void *>());
3676 const bool documentMode = tabBar->documentMode();
3677 const QTabBarPrivate *tabBarPrivate =
static_cast<QTabBarPrivate *>(QObjectPrivate::get(tabBar));
3678 const int hoveredTabIndex = tabBarPrivate->hoveredTabIndex();
3679 if (!documentMode ||
3680 (hoveredTabIndex != -1 && ((closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) ||
3681 (closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide))))) {
3682 const bool hover = (opt->state & State_MouseOver);
3683 const bool selected = (opt->state & State_Selected);
3684 const bool pressed = (opt->state & State_Sunken);
3685 drawTabCloseButton(p, hover, selected, pressed, documentMode);
3690 case PE_PanelStatusBar: {
3691 p->fillRect(opt->rect, opt->palette.window());
3694 if (w ? qt_macWindowMainWindow(w->window()) : (opt->state & QStyle::State_Active))
3695 p->setPen(titlebarSeparatorLineActive);
3697 p->setPen(titlebarSeparatorLineInactive);
3698 p->drawLine(opt->rect.left(), opt->rect.top(), opt->rect.right(), opt->rect.top());
3702 case PE_PanelMenu: {
3704 p->fillRect(opt->rect, Qt::transparent);
3705 p->setPen(Qt::transparent);
3706 p->setBrush(opt->palette.window());
3707 p->setRenderHint(QPainter::Antialiasing,
true);
3708 const QPainterPath path = d->windowPanelPath(opt->rect);
3714 QCommonStyle::drawPrimitive(pe, opt, p, w);
3755 const QWidget *w)
const
3757 Q_D(
const QMacStyle);
3758 const QMacAutoReleasePool pool;
3759 QMacCGContext cg(p);
3761 qCWarning(lcMacStyle) <<
"drawControl:" << ce <<
"invalid (nullptr) graphics context";
3763 QWindow *window = w && w->window() ? w->window()->windowHandle() :
nullptr;
3764 d->resolveCurrentNSView(window);
3766 case CE_HeaderSection:
3767 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
3768 State flags = header->state;
3769 QRect ir = header->rect;
3773 bool noVerticalHeader =
true;
3774#if QT_CONFIG(tableview)
3776 if (
const QTableView *table = qobject_cast<
const QTableView *>(w->parentWidget()))
3777 noVerticalHeader = !table->verticalHeader()->isVisible();
3780 const bool drawLeftBorder = header->orientation == Qt::Vertical
3781 || header->position == QStyleOptionHeader::OnlyOneSection
3782 || (header->position == QStyleOptionHeader::Beginning && noVerticalHeader);
3785 const bool pressed = (flags & State_Sunken) && !(flags & State_On);
3786 p->fillRect(ir, pressed ? header->palette.dark() : header->palette.button());
3787 p->setPen(QPen(header->palette.dark(), 1.0));
3788 if (header->orientation == Qt::Horizontal)
3797 case CE_ToolButtonLabel:
3798 if (
const QStyleOptionToolButton *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
3799 QStyleOptionToolButton myTb = *tb;
3800 myTb.state &= ~State_AutoRaise;
3801#if QT_CONFIG(accessibility)
3802 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) {
3803 QRect cr = tb->rect;
3806 bool needText =
false;
3808 bool down = tb->state & (State_Sunken | State_On);
3810 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, w);
3811 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, tb, w);
3817 if (!(tb->features & QStyleOptionToolButton::Arrow)) {
3818 Qt::ToolButtonStyle tbstyle = tb->toolButtonStyle;
3819 if (tb->icon.isNull() && !tb->text.isEmpty())
3820 tbstyle = Qt::ToolButtonTextOnly;
3823 case Qt::ToolButtonTextOnly: {
3825 alignment = Qt::AlignCenter;
3827 case Qt::ToolButtonIconOnly:
3828 case Qt::ToolButtonTextBesideIcon:
3829 case Qt::ToolButtonTextUnderIcon: {
3831 QIcon::Mode iconMode = (tb->state & State_Enabled) ? QIcon::Normal
3833 QIcon::State iconState = (tb->state & State_On) ? QIcon::On
3835 QPixmap pixmap = tb->icon.pixmap(tb->rect.size().boundedTo(tb->iconSize), p->device()->devicePixelRatio(),
3836 iconMode, iconState);
3839 if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) {
3841 QSizeF size = pixmap.deviceIndependentSize();
3842 if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
3843 pr.setHeight(size.height() + 6);
3844 cr.adjust(0, pr.bottom(), 0, -3);
3845 alignment |= Qt::AlignCenter;
3847 pr.setWidth(size.width() + 8);
3848 cr.adjust(pr.right(), 0, 0, 0);
3849 alignment |= Qt::AlignLeft | Qt::AlignVCenter;
3852 if (opt->state & State_Sunken) {
3853 pr.translate(shiftX, shiftY);
3854 pixmap = darkenPixmap(pixmap);
3856 proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pixmap);
3864 QPalette pal = tb->palette;
3865 QPalette::ColorRole role = QPalette::NoRole;
3866 if (!proxy()->styleHint(SH_UnderlineShortcut, tb, w))
3867 alignment |= Qt::TextHideMnemonic;
3869 cr.translate(shiftX, shiftY);
3870 if (tbstyle == Qt::ToolButtonTextOnly
3871 || (tbstyle != Qt::ToolButtonTextOnly && !down)) {
3872 QPen pen = p->pen();
3873 QColor light = down || isDarkMode() ? Qt::black : Qt::white;
3874 light.setAlphaF(0.375f);
3876 p->drawText(cr.adjusted(0, 1, 0, 1), alignment, tb->text);
3878 if (down && tbstyle == Qt::ToolButtonTextOnly) {
3879 pal = QApplication::palette(
"QMenu");
3880 pal.setCurrentColorGroup(tb->palette.currentColorGroup());
3881 role = QPalette::HighlightedText;
3884 proxy()->drawItemText(p, cr, alignment, pal,
3885 tb->state & State_Enabled, tb->text, role);
3888 QCommonStyle::drawControl(ce, &myTb, p, w);
3893 QCommonStyle::drawControl(ce, &myTb, p, w);
3897 case CE_ToolBoxTabShape:
3898 QCommonStyle::drawControl(ce, opt, p, w);
3900 case CE_PushButtonBevel:
3901 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
3902 if (!(btn->state & (State_Raised | State_Sunken | State_On)))
3905 if (btn->features & QStyleOptionButton::CommandLinkButton) {
3906 QCommonStyle::drawControl(ce, opt, p, w);
3910 const bool hasFocus = btn->state & State_HasFocus;
3911 const bool isActive = btn->state & State_Active;
3915 if ((btn->features & QStyleOptionButton::AutoDefaultButton)
3916 && isActive && hasFocus)
3917 d->autoDefaultButton = btn->styleObject;
3918 else if (d->autoDefaultButton == btn->styleObject)
3919 d->autoDefaultButton =
nullptr;
3921 const bool isEnabled = btn->state & State_Enabled;
3922 const bool isPressed = btn->state & State_Sunken;
3923 const bool isHighlighted = isActive &&
3924 ((btn->state & State_On)
3925 || (btn->features & QStyleOptionButton::DefaultButton)
3926 || (btn->features & QStyleOptionButton::AutoDefaultButton
3927 && d->autoDefaultButton == btn->styleObject));
3928 const bool hasMenu = btn->features & QStyleOptionButton::HasMenu;
3929 const auto ct = cocoaControlType(btn, w);
3930 const auto cs = d->effectiveAquaSizeConstrain(btn, w);
3931 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
3932 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
3936 const QRectF frameRect = cw.adjustedControlFrame(btn->rect);
3937 pb.frame = frameRect.toCGRect();
3939 pb.enabled = isEnabled;
3944 [pb highlight:isPressed];
3947 if (cw.type == QMacStylePrivate::Button_SquareButton) {
3948 pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff;
3952 pb.keyEquivalent = isHighlighted ? @
"\r" : @
"";
3955 d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
3956 [pb.cell drawBezelWithFrame:r inView:pb.superview];
3960 if (hasMenu && cw.type == QMacStylePrivate::Button_SquareButton) {
3963 const int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w);
3964 const auto ir = frameRect.toRect();
3965 int arrowYOffset = 0;
3970 arrowYOffset -= ir.top();
3971 if (cw.second == QStyleHelper::SizeSmall)
3975 const auto ar = visualRect(btn->direction, ir, QRect(ir.right() - mbi - 6, ir.height() / 2 - arrowYOffset, mbi, mbi));
3977 QStyleOption arrowOpt = *opt;
3979 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, w);
3983 case CE_PushButtonLabel:
3984 if (
const QStyleOptionButton *b = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
3985 QStyleOptionButton btn(*b);
3990 const bool isEnabled = btn.state & State_Enabled;
3991 const bool hasMenu = btn.features & QStyleOptionButton::HasMenu;
3992 const bool hasIcon = !btn.icon.isNull();
3993 const bool hasText = !btn.text.isEmpty();
3994 const bool isActive = btn.state & State_Active;
3995 const bool isPressed = btn.state & State_Sunken;
3996 const bool isDefault = (btn.features & QStyleOptionButton::DefaultButton && !d->autoDefaultButton)
3997 || d->autoDefaultButton == btn.styleObject;
4001 const QRect oldRect = btn.rect;
4003 btn.rect = w->rect();
4004 const auto ct = cocoaControlType(&btn, w);
4007 if (!hasMenu && ct != QMacStylePrivate::Button_SquareButton) {
4008 if (isPressed || (isActive && isEnabled && ((btn.state & State_On) || isDefault)))
4009 btn.palette.setColor(QPalette::ButtonText, Qt::white);
4013 if (!isDefault && !(btn.state & State_On)) {
4016 btn.palette.setColor(QPalette::ButtonText, Qt::black);
4020 if ((!hasIcon && !hasMenu) || (hasIcon && !hasText)) {
4021 QCommonStyle::drawControl(ce, &btn, p, w);
4023 QRect freeContentRect = btn.rect;
4024 QRect textRect = itemTextRect(
4025 btn.fontMetrics, freeContentRect, Qt::AlignCenter, isEnabled, btn.text);
4027 if (ct == QMacStylePrivate::Button_SquareButton)
4028 textRect.moveTo(w ? 8 : 11, textRect.top());
4030 textRect.moveTo(w ? (15 - pushButtonBevelRectOffsets[d->effectiveAquaSizeConstrain(b, w)])
4031 : 11, textRect.top());
4035 int contentW = textRect.width();
4037 contentW += proxy()->pixelMetric(PM_MenuButtonIndicator) + 4;
4038 QIcon::Mode mode = isEnabled ? QIcon::Normal : QIcon::Disabled;
4039 if (mode == QIcon::Normal && btn.state & State_HasFocus)
4040 mode = QIcon::Active;
4042 QIcon::State state = QIcon::Off;
4043 if (btn.state & State_On)
4045 QPixmap pixmap = btn.icon.pixmap(btn.iconSize, p->device()->devicePixelRatio(), mode, state);
4046 QSizeF pixmapSize = pixmap.deviceIndependentSize();
4047 contentW += pixmapSize.width() + QMacStylePrivate::PushButtonContentPadding;
4048 int iconLeftOffset = freeContentRect.x() + (freeContentRect.width() - contentW) / 2;
4049 int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmapSize.height()) / 2;
4050 QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmapSize.width(), pixmapSize.height());
4051 QRect visualIconDestRect = visualRect(btn.direction, freeContentRect, iconDestRect);
4052 proxy()->drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap);
4053 int newOffset = iconDestRect.x() + iconDestRect.width()
4054 + QMacStylePrivate::PushButtonContentPadding - textRect.x();
4055 textRect.adjust(newOffset, 0, newOffset, 0);
4059 textRect = visualRect(btn.direction, freeContentRect, textRect);
4060 proxy()->drawItemText(p, textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, btn.palette,
4061 isEnabled, btn.text, QPalette::ButtonText);
4066#if QT_CONFIG(combobox)
4067 case CE_ComboBoxLabel:
4068 if (
const auto *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
4069 auto comboCopy = *cb;
4070 comboCopy.direction = Qt::LeftToRight;
4072 QCommonStyle::drawControl(CE_ComboBoxLabel, &comboCopy, p, w);
4076#if QT_CONFIG(tabbar)
4077 case CE_TabBarTabShape:
4078 if (
const auto *tabOpt = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
4079 if (tabOpt->documentMode) {
4081 bool isUnified =
false;
4083 QRect tabRect = tabOpt->rect;
4084 QPoint windowTabStart = w->mapTo(w->window(), tabRect.topLeft());
4085 isUnified = isInMacUnifiedToolbarArea(w->window(), windowTabStart.y());
4088 const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, opt, w);
4089 drawTabShape(p, tabOpt, isUnified, tabOverlap);
4118 const bool isActive = tabOpt->state & State_Active;
4119 const bool isEnabled = tabOpt->state & State_Enabled;
4120 const bool isPressed = tabOpt->state & State_Sunken;
4121 const bool isSelected = tabOpt->state & State_Selected;
4122 const auto tabDirection = QMacStylePrivate::tabDirection(tabOpt->shape);
4123 const bool verticalTabs = tabDirection == QMacStylePrivate::East
4124 || tabDirection == QMacStylePrivate::West;
4126 QStyleOptionTab::TabPosition tp = tabOpt->position;
4127 QStyleOptionTab::SelectedPosition sp = tabOpt->selectedPosition;
4128 if (tabOpt->direction == Qt::RightToLeft && !verticalTabs) {
4129 if (tp == QStyleOptionTab::Beginning)
4130 tp = QStyleOptionTab::End;
4131 else if (tp == QStyleOptionTab::End)
4132 tp = QStyleOptionTab::Beginning;
4134 if (sp == QStyleOptionTab::NextIsSelected)
4135 sp = QStyleOptionTab::PreviousIsSelected;
4136 else if (sp == QStyleOptionTab::PreviousIsSelected)
4137 sp = QStyleOptionTab::NextIsSelected;
4146 const auto cs = d->effectiveAquaSizeConstrain(opt, w);
4148 const bool needsInactiveHack = !isActive && isSelected;
4149 const auto ct = !needsInactiveHack && (isSelected || tp == QStyleOptionTab::OnlyOneTab) ?
4150 QMacStylePrivate::Button_PushButton :
4151 QMacStylePrivate::Button_PopupButton;
4152 const bool isPopupButton = ct == QMacStylePrivate::Button_PopupButton;
4153 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
4154 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
4157 if (tabDirection == QMacStylePrivate::East)
4159 const auto outerAdjust = isPopupButton ? 1 : 4;
4160 const auto innerAdjust = isPopupButton ? 20 : 10;
4161 QRectF frameRect = tabOpt->rect;
4163 frameRect = QRectF(frameRect.y(), frameRect.x(), frameRect.height(), frameRect.width());
4165 frameRect = frameRect.translated(0, vOffset);
4167 case QStyleOptionTab::Beginning:
4169 if (!isSelected && tabDirection == QMacStylePrivate::West)
4170 frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0);
4172 frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0);
4177 frameRect = frameRect.adjusted(0, 0, 1, 0);
4180 case QStyleOptionTab::Middle:
4181 frameRect = frameRect.adjusted(-innerAdjust, 0, innerAdjust, 0);
4186 frameRect = frameRect.adjusted(-1, 0, 1, 0);
4189 case QStyleOptionTab::Moving:
4190 case QStyleOptionTab::End:
4192 if (isSelected || tabDirection == QMacStylePrivate::West)
4193 frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0);
4195 frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0);
4199 frameRect = frameRect.adjusted(-1, 0, 0, 0);
4202 case QStyleOptionTab::OnlyOneTab:
4203 frameRect = frameRect.adjusted(-outerAdjust, 0, outerAdjust, 0);
4206 pb.frame = frameRect.toCGRect();
4208 if (!isPopupButton) {
4212 pb.buttonType = NSButtonTypePushOnPushOff;
4215 pb.enabled = isEnabled;
4216 [pb highlight:isPressed];
4218 pb.state = (isActive && isSelected) ? NSControlStateValueOn : NSControlStateValueOff;
4220 const auto drawBezelBlock = ^(CGContextRef ctx,
const CGRect &r) {
4221 CGContextClipToRect(ctx, opt->rect.toCGRect());
4222 if (!isSelected || needsInactiveHack) {
4224 if (!verticalTabs && tp == QStyleOptionTab::End) {
4225 CGContextTranslateCTM(ctx, opt->rect.right(), 0);
4226 CGContextScaleCTM(ctx, -1, 1);
4227 CGContextTranslateCTM(ctx, -frameRect.left(), 0);
4228 }
else if (tabDirection == QMacStylePrivate::West && tp == QStyleOptionTab::Beginning) {
4229 CGContextTranslateCTM(ctx, 0, opt->rect.top());
4230 CGContextScaleCTM(ctx, 1, -1);
4231 CGContextTranslateCTM(ctx, 0, -frameRect.right());
4232 }
else if (tabDirection == QMacStylePrivate::East && tp == QStyleOptionTab::End) {
4233 CGContextTranslateCTM(ctx, 0, opt->rect.bottom());
4234 CGContextScaleCTM(ctx, 1, -1);
4235 CGContextTranslateCTM(ctx, 0, -frameRect.left());
4241 if (tabDirection == QMacStylePrivate::West) {
4242 CGContextTranslateCTM(ctx, 0, frameRect.right());
4243 CGContextRotateCTM(ctx, -M_PI_2);
4244 CGContextTranslateCTM(ctx, -frameRect.left(), 0);
4245 }
else if (tabDirection == QMacStylePrivate::East) {
4246 CGContextTranslateCTM(ctx, opt->rect.right(), 0);
4247 CGContextRotateCTM(ctx, M_PI_2);
4252 NSPopUpArrowPosition oldPosition = NSPopUpArrowAtCenter;
4253 NSPopUpButtonCell *pbCell = nil;
4255 if (isPopupButton) {
4259 pbCell =
static_cast<NSPopUpButtonCell *>(pb.cell);
4260 oldPosition = pbCell.arrowPosition;
4261 pbCell.arrowPosition = NSPopUpNoArrow;
4262 if (pb.state == NSControlStateValueOff) {
4264 rAdjusted.origin.x -= 3;
4265 rAdjusted.size.width += 6;
4266 if (tp == QStyleOptionTab::End)
4267 rAdjusted.origin.x -= 2;
4270 if (qt_apple_runningWithLiquidGlass()) {
4279 const CGFloat deltaW = 20.0;
4280 rAdjusted = CGContextGetClipBoundingBox(ctx);
4281 if (tp == QStyleOptionTab::Beginning) {
4286 rAdjusted.size.width += deltaW;
4288 if (tabDirection == QMacStylePrivate::West && isSelected && isActive) {
4292 rAdjusted.origin.x -= deltaW;
4294 }
else if (tp == QStyleOptionTab::Middle) {
4296 rAdjusted.origin.x -= deltaW;
4297 rAdjusted.size.width += deltaW * 2;
4298 }
else if (tp == QStyleOptionTab::End) {
4299 if (isSelected && isActive && tabDirection != QMacStylePrivate::West)
4300 rAdjusted.origin.x -= deltaW;
4301 rAdjusted.size.width += deltaW;
4305 [pb.cell drawBezelWithFrame:rAdjusted inView:pb.superview];
4308 pbCell.arrowPosition = oldPosition;
4311 if (needsInactiveHack) {
4313 const qreal pixelRatio = p->device()->devicePixelRatio();
4314 QImage tabPixmap(opt->rect.size() * pixelRatio, QImage::Format_ARGB32_Premultiplied);
4315 tabPixmap.setDevicePixelRatio(pixelRatio);
4316 tabPixmap.fill(Qt::transparent);
4317 QPainter tabPainter(&tabPixmap);
4318 d->drawNSViewInRect(pb, frameRect, &tabPainter, ^(CGContextRef ctx,
const CGRect &r) {
4319 CGContextTranslateCTM(ctx, -opt->rect.left(), -opt->rect.top());
4320 drawBezelBlock(ctx, r);
4325 const qreal inactiveGray = 0.898;
4326 const int inactiveGray8 = qRound(inactiveGray * 255.0);
4327 const QRgb inactiveGrayRGB = qRgb(inactiveGray8, inactiveGray8, inactiveGray8);
4328 for (
int l = 0; l < tabPixmap.height(); ++l) {
4329 auto *line =
reinterpret_cast<QRgb*>(tabPixmap.scanLine(l));
4330 for (
int i = 0; i < tabPixmap.width(); ++i) {
4331 if (qAlpha(line[i]) == 255) {
4332 line[i] = inactiveGrayRGB;
4333 }
else if (qAlpha(line[i]) > 128) {
4334 const int g = qRound(inactiveGray * qRed(line[i]));
4335 line[i] = qRgba(g, g, g, qAlpha(line[i]));
4341 p->drawImage(opt->rect, tabPixmap);
4343 d->drawNSViewInRect(pb, frameRect, p, drawBezelBlock);
4346 if (!isSelected && sp != QStyleOptionTab::NextIsSelected
4347 && tp != QStyleOptionTab::End
4348 && tp != QStyleOptionTab::OnlyOneTab) {
4349 static const QPen separatorPen(Qt::black, 1.0);
4351 p->setOpacity(isEnabled ? 0.105 : 0.06);
4352 p->setPen(separatorPen);
4353 if (tabDirection == QMacStylePrivate::West) {
4354 p->drawLine(QLineF(opt->rect.left() + 1.5, opt->rect.bottom(),
4355 opt->rect.right() - 0.5, opt->rect.bottom()));
4356 }
else if (tabDirection == QMacStylePrivate::East) {
4357 p->drawLine(QLineF(opt->rect.left(), opt->rect.bottom(),
4358 opt->rect.right() - 0.5, opt->rect.bottom()));
4360 p->drawLine(QLineF(opt->rect.right(), opt->rect.top() + 1.0,
4361 opt->rect.right(), opt->rect.bottom() - 0.5));
4367 case CE_TabBarTabLabel:
4368 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
4369 QStyleOptionTab myTab = *tab;
4370 const auto foregroundRole = w ? w->foregroundRole() : QPalette::WindowText;
4371 const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape);
4372 const bool verticalTabs = tabDirection == QMacStylePrivate::East
4373 || tabDirection == QMacStylePrivate::West;
4379 const bool nonDefaultFont = p->font() != qt_app_fonts_hash()->value(
"QComboMenuItem");
4381 if (!myTab.documentMode && (myTab.state & State_Selected) && (myTab.state & State_Active))
4382 if (
const auto *tabBar = qobject_cast<
const QTabBar *>(w))
4383 if (!tabBar->tabTextColor(tabBar->currentIndex()).isValid())
4384 myTab.palette.setColor(foregroundRole, Qt::white);
4386 if (myTab.documentMode && isDarkMode()) {
4387 if (
const auto *tabBar = qobject_cast<
const QTabBar *>(w)) {
4388 if (!tabBar->tabTextColor(myTab.tabIndex).isValid()) {
4389 bool active = (myTab.state & State_Selected) && (myTab.state & State_Active);
4390 myTab.palette.setColor(foregroundRole, active ? Qt::white : Qt::gray);
4395 int heightOffset = 0;
4398 }
else if (nonDefaultFont) {
4399 if (p->fontMetrics().height() == myTab.rect.height())
4402 myTab.rect.setHeight(myTab.rect.height() + heightOffset);
4404 QCommonStyle::drawControl(ce, &myTab, p, w);
4408#if QT_CONFIG(dockwidget)
4409 case CE_DockWidgetTitle:
4410 if (
const auto *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(opt)) {
4411 const bool isVertical = dwOpt->verticalTitleBar;
4412 const auto effectiveRect = isVertical ? opt->rect.transposed() : opt->rect;
4415 p->translate(effectiveRect.left(), effectiveRect.top() + effectiveRect.width());
4417 p->translate(-effectiveRect.left(), -effectiveRect.top());
4421 p->fillRect(effectiveRect, opt->palette.window());
4424 p->setPen(opt->palette.dark().color());
4425 p->drawLine(effectiveRect.bottomLeft(), effectiveRect.bottomRight());
4427 if (!dwOpt->title.isEmpty()) {
4428 auto titleRect = proxy()->subElementRect(SE_DockWidgetTitleBarText, opt, w);
4430 titleRect = QRect(effectiveRect.left() + opt->rect.bottom() - titleRect.bottom(),
4431 effectiveRect.top() + titleRect.left() - opt->rect.left(),
4435 const auto text = p->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
4436 proxy()->drawItemText(p, titleRect, Qt::AlignCenter | Qt::TextHideMnemonic, dwOpt->palette,
4437 dwOpt->state & State_Enabled, text, QPalette::WindowText);
4443 case CE_FocusFrame: {
4444 const auto *ff = qobject_cast<
const QFocusFrame *>(w);
4445 const auto *ffw = ff ? ff->widget() :
nullptr;
4446 const auto ct = [=] {
4448 if (qobject_cast<
const QCheckBox*>(ffw))
4449 return QMacStylePrivate::Button_CheckBox;
4450 if (qobject_cast<
const QRadioButton*>(ffw))
4451 return QMacStylePrivate::Button_RadioButton;
4452 if (qobject_cast<
const QLineEdit*>(ffw) || qobject_cast<
const QTextEdit*>(ffw))
4453 return QMacStylePrivate::TextField;
4454 if (
const auto *pb = qobject_cast<
const QPushButton *>(ffw)) {
4456 auto sizePolicy = QStyleHelper::widgetSizePolicy(ffw, opt);
4457 if (sizePolicy == QStyleHelper::SizeDefault)
4458 sizePolicy = QStyleHelper::SizeLarge;
4460 || (pb->rect().height() != pushButtonDefaultHeight[sizePolicy])) {
4461 return QMacStylePrivate::Button_SquareButton;
4463 if (pb->menu() !=
nullptr)
4464 return QMacStylePrivate::Button_PullDown;
4465 return QMacStylePrivate::Button_PushButton;
4469 return QMacStylePrivate::Box;
4471 auto cs = QStyleHelper::widgetSizePolicy(ffw, opt);
4472 if (cs == QStyleHelper::SizeDefault)
4473 cs = QStyleHelper::SizeLarge;
4474 const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, w);
4475 const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, opt, w);
4476 d->drawFocusRing(p, opt->rect, hMargin, vMargin, QMacStylePrivate::CocoaControl(ct, cs));
4478 case CE_MenuEmptyArea:
4480 if (qobject_cast<
const QAbstractItemView *>(w))
4481 proxy()->drawPrimitive(PE_PanelMenu, opt, p, w);
4485 case CE_MenuHMargin:
4486 case CE_MenuVMargin:
4487 case CE_MenuTearoff:
4488 case CE_MenuScroller:
4489 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
4490 const bool active = mi->state & State_Selected;
4492 p->fillRect(mi->rect, mi->palette.highlight());
4494 const QStyleHelper::WidgetSizePolicy widgetSize = d->aquaSizeConstrain(opt, w);
4496 if (ce == CE_MenuTearoff) {
4497 p->setPen(QPen(mi->palette.dark().color(), 1, Qt::DashLine));
4498 p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2 - 1,
4499 mi->rect.x() + mi->rect.width() - 4,
4500 mi->rect.y() + mi->rect.height() / 2 - 1);
4501 p->setPen(QPen(mi->palette.light().color(), 1, Qt::DashLine));
4502 p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2,
4503 mi->rect.x() + mi->rect.width() - 4,
4504 mi->rect.y() + mi->rect.height() / 2);
4505 }
else if (ce == CE_MenuScroller) {
4506 const QSize scrollerSize = QSize(10, 8);
4507 const int scrollerVOffset = 5;
4508 const int left = mi->rect.x() + (mi->rect.width() - scrollerSize.width()) / 2;
4509 const int right = left + scrollerSize.width();
4512 if (opt->state & State_DownArrow) {
4513 bottom = mi->rect.y() + scrollerVOffset;
4514 top = bottom + scrollerSize.height();
4516 bottom = mi->rect.bottom() - scrollerVOffset;
4517 top = bottom - scrollerSize.height();
4520 p->setRenderHint(QPainter::Antialiasing);
4522 path.moveTo(left, bottom);
4523 path.lineTo(right, bottom);
4524 path.lineTo((left + right) / 2, top);
4525 p->fillPath(path, opt->palette.buttonText());
4527 }
else if (ce != CE_MenuItem) {
4531 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
4532 CGColorRef separatorColor = [NSColor quaternaryLabelColor].CGColor;
4533 const QRect separatorRect = QRect(mi->rect.left(), mi->rect.center().y(), mi->rect.width(), 2);
4534 p->fillRect(separatorRect, qt_mac_toQColor(separatorColor));
4538 const int maxpmw = mi->maxIconWidth;
4539 const bool enabled = mi->state & State_Enabled;
4541 int xpos = mi->rect.x() + 18;
4542 int checkcol = maxpmw;
4544 p->setPen(mi->palette.text().color());
4546 p->setPen(mi->palette.highlightedText().color());
4548 p->setPen(mi->palette.buttonText().color());
4551 QStyleOption checkmarkOpt;
4552 checkmarkOpt.initFrom(w);
4557 checkmarkOpt.rect = QRect(xp, mi->rect.y() - checkmarkOpt.fontMetrics.descent(), mw, mh);
4559 checkmarkOpt.state.setFlag(State_On, active);
4560 checkmarkOpt.state.setFlag(State_Enabled, enabled);
4561 if (widgetSize == QStyleHelper::SizeMini)
4562 checkmarkOpt.state |= State_Mini;
4563 else if (widgetSize == QStyleHelper::SizeSmall)
4564 checkmarkOpt.state |= State_Small;
4567 checkmarkOpt.palette.setColor(QPalette::HighlightedText, p->pen().color());
4568 checkmarkOpt.palette.setColor(QPalette::Text, p->pen().color());
4570 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &checkmarkOpt, p, w);
4572 if (!mi->icon.isNull()) {
4573 QIcon::Mode mode = (mi->state & State_Enabled) ? QIcon::Normal
4576 int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize);
4577 QSize iconSize(smallIconSize, smallIconSize);
4578#if QT_CONFIG(combobox)
4579 if (
const QComboBox *comboBox = qobject_cast<
const QComboBox *>(w)) {
4580 iconSize = comboBox->iconSize();
4583 QPixmap pixmap = mi->icon.pixmap(iconSize, p->device()->devicePixelRatio(), mode);
4584 QRect cr(xpos, mi->rect.y(), checkcol, mi->rect.height());
4585 QSize size = pixmap.deviceIndependentSize().toSize();
4586 QRect pmr(QPoint(0, 0), size);
4587 pmr.moveCenter(cr.center());
4588 p->drawPixmap(pmr.topLeft(), pixmap);
4589 xpos += size.width() + 6;
4592 QString s = mi->text;
4593 const auto text_flags = Qt::AlignVCenter | Qt::TextHideMnemonic
4594 | Qt::TextSingleLine | Qt::AlignAbsolute;
4595 int yPos = mi->rect.y();
4596 if (widgetSize == QStyleHelper::SizeMini)
4599 const bool isSubMenu = mi->menuItemType == QStyleOptionMenuItem::SubMenu;
4600 const int tabwidth = isSubMenu ? 9 : mi->reservedShortcutWidth;
4602 QString rightMarginText;
4604 rightMarginText = QStringLiteral(
"\u25b6\ufe0e");
4607 const int tabIndex = s.indexOf(QLatin1Char(
'\t'));
4608 if (tabIndex >= 0) {
4610 rightMarginText = s.mid(tabIndex + 1);
4611 s = s.left(tabIndex);
4615 if (!rightMarginText.isEmpty()) {
4616 p->setFont(qt_app_fonts_hash()->value(
"QMenuItem", p->font()));
4619 p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags | Qt::AlignRight, rightMarginText);
4623 const QKeySequence seq = QKeySequence::fromString(rightMarginText, QKeySequence::NativeText);
4624 if (seq.count() == 1) {
4626 const int maxKeyWidth = p->fontMetrics().maxWidth();
4627 const QChar key = rightMarginText.at(rightMarginText.length() - 1);
4628 const QString modifiers = rightMarginText.left(rightMarginText.size() - 1);
4629 p->drawText(xp + tabwidth - maxKeyWidth, yPos, maxKeyWidth, mi->rect.height(), text_flags, key);
4631 p->drawText(xp, yPos, tabwidth - maxKeyWidth, mi->rect.height(),
4632 text_flags | Qt::AlignRight | Qt::TextDontClip, modifiers);
4634 p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags, rightMarginText);
4641 QFont myFont = mi->font;
4647 myFont.setPointSizeF(QFontInfo(mi->font).pointSizeF());
4652 const auto *fontEngine = QFontPrivate::get(myFont)->engineForScript(QChar::Script_Common);
4653 Q_ASSERT(fontEngine);
4654 if (fontEngine->type() == QFontEngine::Multi) {
4655 fontEngine =
static_cast<
const QFontEngineMulti *>(fontEngine)->engine(0);
4656 Q_ASSERT(fontEngine);
4658 if (fontEngine->type() == QFontEngine::Mac) {
4659 NSFont *f = (NSFont *)(CTFontRef)fontEngine->handle();
4662 const auto pc = p->pen().color();
4663 NSColor *c = [NSColor colorWithSRGBRed:pc.redF()
4668 s = qt_mac_removeMnemonics(s);
4670 QMacCGContext cgCtx(p);
4671 d->setupNSGraphicsContext(cgCtx, YES);
4677 [s.toNSString() drawAtPoint:CGPointMake(xpos, yPos)
4678 withAttributes:@{ NSFontAttributeName:f, NSForegroundColorAttributeName:c,
4679 NSObliquenessAttributeName: [NSNumber numberWithDouble: myFont.italic() ? 0.3 : 0.0],
4680 NSUnderlineStyleAttributeName: [NSNumber numberWithInt: myFont.underline() ? NSUnderlineStyleSingle
4681 : NSUnderlineStyleNone],
4682 NSStrikethroughStyleAttributeName: [NSNumber numberWithInt: myFont.strikeOut() ? NSUnderlineStyleSingle
4683 : NSUnderlineStyleNone]}];
4685 d->restoreNSGraphicsContext(cgCtx);
4688 p->drawText(xpos, yPos, mi->rect.width() - xm - tabwidth + 1,
4689 mi->rect.height(), text_flags, s);
4695 case CE_MenuBarItem:
4696 case CE_MenuBarEmptyArea:
4697 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
4698 const bool selected = (opt->state & State_Selected) && (opt->state & State_Enabled) && (opt->state & State_Sunken);
4699 const QBrush bg = selected ? mi->palette.highlight() : mi->palette.window();
4700 p->fillRect(mi->rect, bg);
4702 if (ce != CE_MenuBarItem)
4705 if (!mi->icon.isNull()) {
4706 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
4707 drawItemPixmap(p, mi->rect,
4708 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip
4709 | Qt::TextSingleLine,
4710 mi->icon.pixmap(QSize(iconExtent, iconExtent), p->device()->devicePixelRatio(),
4711 (mi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled));
4713 drawItemText(p, mi->rect,
4714 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip
4715 | Qt::TextSingleLine,
4716 mi->palette, mi->state & State_Enabled,
4717 mi->text, selected ? QPalette::HighlightedText : QPalette::ButtonText);
4721 case CE_ProgressBarLabel:
4722 case CE_ProgressBarGroove:
4725 case CE_ProgressBarContents:
4726 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
4727 const bool isIndeterminate = (pb->minimum == 0 && pb->maximum == 0);
4728 const bool vertical = !(pb->state & QStyle::State_Horizontal);
4729 const bool inverted = pb->invertedAppearance;
4730 bool reverse = (!vertical && (pb->direction == Qt::RightToLeft));
4733 QRect rect = pb->rect;
4735 const auto aquaSize = d->effectiveAquaSizeConstrain(opt, w);
4736 const QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject));
4737 if (isIndeterminate) {
4745 if (!animation && opt->styleObject) {
4746 auto *animation =
new QProgressStyleAnimation(d->animateSpeed(QMacStylePrivate::AquaProgressBar), opt->styleObject);
4748 animation->setFrameRate(QStyleAnimation::FifteenFps);
4749 d->startAnimation(animation);
4752 if (qt_apple_runningWithLiquidGlass()) {
4753 d->drawProgressBar(p, pb);
4756 rect = rect.transposed();
4757 d->setupNSGraphicsContext(cg, NO);
4758 d->setupVerticalInvertedXform(cg, reverse, vertical, rect.toCGRect());
4760 =
static_cast<QIndeterminateProgressIndicator *>(
4761 d->cocoaControl({ QMacStylePrivate::ProgressIndicator_Indeterminate, aquaSize }))) {
4762 [ipi startAnimation];
4763 [ipi drawWithFrame:rect.toCGRect() inView:d->backingStoreNSView];
4765 d->restoreNSGraphicsContext(cg);
4769 d->stopAnimation(opt->styleObject);
4771 =
static_cast<QIndeterminateProgressIndicator *>(
4772 d->cocoaControl({ QMacStylePrivate::ProgressIndicator_Indeterminate, aquaSize })))
4773 [ipi stopAnimation];
4775 if (qt_apple_runningWithLiquidGlass()) {
4776 d->drawProgressBar(p, pb);
4779 rect = rect.transposed();
4780 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::ProgressIndicator_Determinate, aquaSize);
4781 auto *pi =
static_cast<NSProgressIndicator *>(d->cocoaControl(cw));
4782 d->drawNSViewInRect(pi, rect, p, ^(CGContextRef ctx,
const CGRect &cgrect) {
4783 d->setupVerticalInvertedXform(ctx, reverse, vertical, cgrect);
4784 pi.minValue = pb->minimum;
4785 pi.maxValue = pb->maximum;
4786 pi.doubleValue = pb->progress;
4787 [pi drawRect:cgrect]; });
4794#ifndef QT_NO_MDIAREA
4795 if (!w || !qobject_cast<QMdiSubWindow *>(w->parentWidget()))
4799 if (w->testAttribute(Qt::WA_MacOpaqueSizeGrip))
4800 p->fillRect(opt->rect, opt->palette.window());
4802 QPen lineColor = QColor(82, 82, 82, 192);
4803 lineColor.setWidth(1);
4805 p->setRenderHint(QPainter::Antialiasing);
4806 p->setPen(lineColor);
4807 const Qt::LayoutDirection layoutDirection = w ? w->layoutDirection() : qApp->layoutDirection();
4808 const int NumLines = 3;
4809 for (
int l = 0; l < NumLines; ++l) {
4810 const int offset = (l * 4 + 3);
4812 if (layoutDirection == Qt::LeftToRight) {
4813 start = QPoint(opt->rect.width() - offset, opt->rect.height() - 1);
4814 end = QPoint(opt->rect.width() - 1, opt->rect.height() - offset);
4816 start = QPoint(offset, opt->rect.height() - 1);
4817 end = QPoint(1, opt->rect.height() - offset);
4819 p->drawLine(start, end);
4825 if (opt->rect.width() > 1 && opt->rect.height() > 1) {
4826 const bool isVertical = !(opt->state & QStyle::State_Horizontal);
4828 const auto ct = isVertical ? QMacStylePrivate::SplitView_Horizontal : QMacStylePrivate::SplitView_Vertical;
4829 const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
4830 auto *sv =
static_cast<NSSplitView *>(d->cocoaControl(cw));
4831 sv.frame = opt->rect.toCGRect();
4832 d->drawNSViewInRect(sv, opt->rect, p, ^(CGContextRef,
const CGRect &rect) {
4833 [sv drawDividerInRect:rect];
4836 QPen oldPen = p->pen();
4837 p->setPen(opt->palette.dark().color());
4838 if (opt->state & QStyle::State_Horizontal)
4839 p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
4841 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
4846 if (
const QStyleOptionRubberBand *rubber = qstyleoption_cast<
const QStyleOptionRubberBand *>(opt)) {
4847 QColor fillColor(opt->palette.color(QPalette::Disabled, QPalette::Highlight));
4848 if (!rubber->opaque) {
4851 strokeColor.setHsvF(0, 0, 0.86, 1.0);
4852 fillColor.setHsvF(0, 0, 0.53, 0.25);
4853 if (opt->rect.width() * opt->rect.height() <= 3) {
4854 p->fillRect(opt->rect, strokeColor);
4856 QPen oldPen = p->pen();
4857 QBrush oldBrush = p->brush();
4858 QPen pen(strokeColor);
4860 p->setBrush(fillColor);
4861 QRect adjusted = opt->rect.adjusted(1, 1, -1, -1);
4862 if (adjusted.isValid())
4863 p->drawRect(adjusted);
4865 p->setBrush(oldBrush);
4868 p->fillRect(opt->rect, fillColor);
4872#ifndef QT_NO_TOOLBAR
4874 const QStyleOptionToolBar *toolBar = qstyleoption_cast<
const QStyleOptionToolBar *>(opt);
4876 const QColor separatorColor = darkMode ? darkModeSeparatorLine : opt->palette.dark().color();
4883#if QT_CONFIG(mainwindow)
4884 if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) {
4885 if (toolBar && toolBar->toolBarArea == Qt::TopToolBarArea && mainWindow->unifiedTitleAndToolBarOnMac()) {
4888 p->setCompositionMode(QPainter::CompositionMode_Source);
4889 p->fillRect(opt->rect, Qt::transparent);
4896 const QPoint windowToolbarEnd = w->mapTo(w->window(), opt->rect.bottomLeft());
4897 const bool isEndOfUnifiedArea = !isInMacUnifiedToolbarArea(w->window(), windowToolbarEnd.y() + 1);
4898 if (isEndOfUnifiedArea) {
4899 const int margin = qt_mac_aqua_get_metric(SeparatorSize);
4900 const auto separatorRect = QRect(opt->rect.left(), opt->rect.bottom(), opt->rect.width(), margin);
4901 p->fillRect(separatorRect, separatorColor);
4909 p->fillRect(opt->rect, opt->palette.window());
4912 p->setPen(separatorColor);
4913 QRect toolbarRect = darkMode ? opt->rect.adjusted(0, 0, 0, 1) : opt->rect;
4914 if (opt->state & State_Horizontal) {
4915 p->drawLine(toolbarRect.topLeft(), toolbarRect.topRight());
4916 p->drawLine(toolbarRect.bottomLeft(), toolbarRect.bottomRight());
4918 p->drawLine(toolbarRect.topLeft(), toolbarRect.bottomLeft());
4919 p->drawLine(toolbarRect.topRight(), toolbarRect.bottomRight());
4927 QCommonStyle::drawControl(ce, opt, p, w);
4942 const QWidget *widget)
const
4944 Q_D(
const QMacStyle);
4946 const int controlSize = getControlSize(opt, widget);
4949#if QT_CONFIG(itemviews)
4950 case SE_ItemViewItemText:
4951 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
4952 int fw = proxy()->pixelMetric(PM_FocusFrameHMargin, opt, widget);
4954 rect = QCommonStyle::subElementRect(sr, opt, widget);
4955 if (vopt->features & QStyleOptionViewItem::HasDecoration)
4956 rect.adjust(-fw, 0, 0, 0);
4960 case SE_ToolBoxTabContents:
4961 rect = QCommonStyle::subElementRect(sr, opt, widget);
4963 case SE_PushButtonBevel:
4964 case SE_PushButtonContents:
4965 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
4974 const auto ct = cocoaControlType(btn, widget);
4975 const auto cs = d->effectiveAquaSizeConstrain(btn, widget);
4976 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
4977 auto frameRect = cw.adjustedControlFrame(btn->rect);
4978 if (sr == SE_PushButtonContents) {
4979 frameRect -= cw.titleMargins();
4980 }
else if (cw.type != QMacStylePrivate::Button_SquareButton) {
4981 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
4982 frameRect = QRectF::fromCGRect([pb alignmentRectForFrame:frameRect.toCGRect()]);
4983 if (cw.type == QMacStylePrivate::Button_PushButton)
4984 frameRect -= pushButtonShadowMargins[cw.size];
4985 else if (cw.type == QMacStylePrivate::Button_PullDown)
4986 frameRect -= pullDownButtonShadowMargins[cw.size];
4988 rect = frameRect.toRect();
4991 case SE_HeaderLabel: {
4992 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
4993 rect.setRect(opt->rect.x() + margin, opt->rect.y(),
4994 opt->rect.width() - margin * 2, opt->rect.height() - 2);
4995 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
4997 if (header->sortIndicator != QStyleOptionHeader::None) {
4998 if (opt->state & State_Horizontal)
5004 rect = visualRect(opt->direction, opt->rect, rect);
5007 case SE_HeaderArrow: {
5008 int h = opt->rect.height();
5009 int w = opt->rect.width();
5010 int x = opt->rect.x();
5011 int y = opt->rect.y();
5012 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
5014 if (opt->state & State_Horizontal) {
5021 rect = visualRect(opt->direction, opt->rect, rect);
5024 case SE_ProgressBarGroove:
5028 case SE_ProgressBarLabel:
5030 case SE_ProgressBarContents:
5033 case SE_TreeViewDisclosureItem: {
5039#if QT_CONFIG(tabwidget)
5040 case SE_TabWidgetLeftCorner:
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(0, 0), twf->leftCornerWidgetSize);
5048 case QTabBar::RoundedSouth:
5049 case QTabBar::TriangularSouth:
5050 rect = QRect(QPoint(0, twf->rect.height() - twf->leftCornerWidgetSize.height()),
5051 twf->leftCornerWidgetSize);
5056 rect = visualRect(twf->direction, twf->rect, rect);
5059 case SE_TabWidgetRightCorner:
5060 if (
const QStyleOptionTabWidgetFrame *twf
5061 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5062 switch (twf->shape) {
5063 case QTabBar::RoundedNorth:
5064 case QTabBar::TriangularNorth:
5065 rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(), 0),
5066 twf->rightCornerWidgetSize);
5068 case QTabBar::RoundedSouth:
5069 case QTabBar::TriangularSouth:
5070 rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(),
5071 twf->rect.height() - twf->rightCornerWidgetSize.height()),
5072 twf->rightCornerWidgetSize);
5077 rect = visualRect(twf->direction, twf->rect, rect);
5080 case SE_TabWidgetTabContents:
5081 rect = QCommonStyle::subElementRect(sr, opt, widget);
5082 if (
const auto *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5083 if (twf->lineWidth != 0) {
5084 switch (QMacStylePrivate::tabDirection(twf->shape)) {
5085 case QMacStylePrivate::North:
5086 rect.adjust(+1, +14, -1, -1);
5088 case QMacStylePrivate::South:
5089 rect.adjust(+1, +1, -1, -14);
5091 case QMacStylePrivate::West:
5092 rect.adjust(+14, +1, -1, -1);
5094 case QMacStylePrivate::East:
5095 rect.adjust(+1, +1, -14, -1);
5100 case SE_TabBarTabText:
5101 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
5102 QRect dummyIconRect;
5103 d->tabLayout(tab, widget, &rect, &dummyIconRect);
5106 case SE_TabBarTabLeftButton:
5107 case SE_TabBarTabRightButton:
5108 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
5109 bool selected = tab->state & State_Selected;
5110 int verticalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget);
5111 int horizontalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget);
5114 bool verticalTabs = tab->shape == QTabBar::RoundedEast
5115 || tab->shape == QTabBar::RoundedWest
5116 || tab->shape == QTabBar::TriangularEast
5117 || tab->shape == QTabBar::TriangularWest;
5119 QRect tr = tab->rect;
5120 if (tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::TriangularSouth)
5121 verticalShift = -verticalShift;
5123 qSwap(horizontalShift, verticalShift);
5124 horizontalShift *= -1;
5125 verticalShift *= -1;
5127 if (tab->shape == QTabBar::RoundedWest || tab->shape == QTabBar::TriangularWest)
5128 horizontalShift = -horizontalShift;
5130 tr.adjust(0, 0, horizontalShift, verticalShift);
5133 tr.setBottom(tr.bottom() - verticalShift);
5134 tr.setRight(tr.right() - horizontalShift);
5137 QSize size = (sr == SE_TabBarTabLeftButton) ? tab->leftButtonSize : tab->rightButtonSize;
5138 int w = size.width();
5139 int h = size.height();
5140 int midHeight =
static_cast<
int>(qCeil(
float(tr.height() - h) / 2));
5141 int midWidth = ((tr.width() - w) / 2);
5143 bool atTheTop =
true;
5144 switch (tab->shape) {
5145 case QTabBar::RoundedWest:
5146 case QTabBar::TriangularWest:
5147 atTheTop = (sr == SE_TabBarTabLeftButton);
5149 case QTabBar::RoundedEast:
5150 case QTabBar::TriangularEast:
5151 atTheTop = (sr == SE_TabBarTabRightButton);
5154 if (sr == SE_TabBarTabLeftButton)
5155 rect = QRect(tab->rect.x() + hpadding, midHeight, w, h);
5157 rect = QRect(tab->rect.right() - w - hpadding, midHeight, w, h);
5158 rect = visualRect(tab->direction, tab->rect, rect);
5162 rect = QRect(midWidth, tr.y() + tab->rect.height() - hpadding - h, w, h);
5164 rect = QRect(midWidth, tr.y() + hpadding, w, h);
5169 case SE_LineEditContents:
5170 rect = QCommonStyle::subElementRect(sr, opt, widget);
5171#if QT_CONFIG(combobox)
5172 if (widget && qobject_cast<
const QComboBox*>(widget->parentWidget()))
5173 rect.adjust(-1, -2, 0, 0);
5176 rect.adjust(-1, -1, 0, +1);
5178 case SE_CheckBoxLayoutItem:
5180 if (controlSize == QStyleHelper::SizeLarge) {
5181 setLayoutItemMargins(+2, +3, -9, -4, &rect, opt->direction);
5182 }
else if (controlSize == QStyleHelper::SizeSmall) {
5183 setLayoutItemMargins(+1, +5, 0 , -6, &rect, opt->direction);
5185 setLayoutItemMargins(0, +7, 0 , -6, &rect, opt->direction);
5188 case SE_ComboBoxLayoutItem:
5189#ifndef QT_NO_TOOLBAR
5190 if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
5199 if (controlSize == QStyleHelper::SizeLarge) {
5200 rect.adjust(+3, +2, -3, -4);
5201 }
else if (controlSize == QStyleHelper::SizeSmall) {
5202 setLayoutItemMargins(+2, +1, -3, -4, &rect, opt->direction);
5204 setLayoutItemMargins(+1, 0, -2, 0, &rect, opt->direction);
5208 case SE_LabelLayoutItem:
5210 setLayoutItemMargins(+1, 0 , 0, 0 , &rect, opt->direction);
5212 case SE_ProgressBarLayoutItem: {
5214 int bottom =
SIZE(3, 8, 8);
5215 if (opt->state & State_Horizontal) {
5216 rect.adjust(0, +1, 0, -bottom);
5218 setLayoutItemMargins(+1, 0, -bottom, 0, &rect, opt->direction);
5222 case SE_PushButtonLayoutItem:
5223 if (
const QStyleOptionButton *buttonOpt
5224 = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
5225 if ((buttonOpt->features & QStyleOptionButton::Flat))
5227 if ((buttonOpt->features & QStyleOptionButton::CommandLinkButton)) {
5229 if (controlSize == QStyleHelper::SizeLarge)
5230 rect.adjust(+6, +4, -6, -8);
5231 else if (controlSize == QStyleHelper::SizeSmall)
5232 rect.adjust(+5, +4, -5, -6);
5234 rect.adjust(+1, 0, -1, -2);
5239 if (controlSize == QStyleHelper::SizeLarge) {
5240 rect.adjust(0, +4, 0, -8);
5241 }
else if (controlSize == QStyleHelper::SizeSmall) {
5242 rect.adjust(0, +4, 0, -6);
5244 rect.adjust(0, 0, 0, -2);
5247 case SE_RadioButtonLayoutItem:
5249 if (controlSize == QStyleHelper::SizeLarge) {
5250 setLayoutItemMargins(+2, +2 ,
5251 0, -4 , &rect, opt->direction);
5252 }
else if (controlSize == QStyleHelper::SizeSmall) {
5253 rect.adjust(0, +6, 0 , -5);
5255 rect.adjust(0, +6, 0 , -7);
5258 case SE_SliderLayoutItem:
5259 if (
const QStyleOptionSlider *sliderOpt
5260 = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5262 if (sliderOpt->tickPosition == QSlider::NoTicks) {
5263 int above =
SIZE(3, 0, 2);
5264 int below =
SIZE(4, 3, 0);
5265 if (sliderOpt->orientation == Qt::Horizontal) {
5266 rect.adjust(0, +above, 0, -below);
5268 rect.adjust(+above, 0, -below, 0);
5270 }
else if (sliderOpt->tickPosition == QSlider::TicksAbove) {
5271 int below =
SIZE(3, 2, 0);
5272 if (sliderOpt->orientation == Qt::Horizontal) {
5273 rect.setHeight(rect.height() - below);
5275 rect.setWidth(rect.width() - below);
5277 }
else if (sliderOpt->tickPosition == QSlider::TicksBelow) {
5278 int above =
SIZE(3, 2, 0);
5279 if (sliderOpt->orientation == Qt::Horizontal) {
5280 rect.setTop(rect.top() + above);
5282 rect.setLeft(rect.left() + above);
5287 case SE_FrameLayoutItem:
5289 if (
const QFrame *frame = qobject_cast<
const QFrame *>(widget)) {
5291 switch (frame->frameStyle() & QFrame::Shape_Mask) {
5293 rect.adjust(0, +1, 0, -1);
5296 rect.adjust(+1, 0, -1, 0);
5303 case SE_GroupBoxLayoutItem:
5305 if (
const QStyleOptionGroupBox *groupBoxOpt =
5306 qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
5308
5309
5310
5311
5312 if (groupBoxOpt->subControls & (QStyle::SC_GroupBoxCheckBox
5313 | QStyle::SC_GroupBoxLabel)) {
5315 if (groupBoxOpt->subControls & QStyle::SC_GroupBoxCheckBox) {
5316 delta =
SIZE(8, 4, 4);
5318 delta =
SIZE(15, 12, 12);
5320 rect.setTop(rect.top() + delta);
5323 rect.setBottom(rect.bottom() - 1);
5325#if QT_CONFIG(tabwidget)
5326 case SE_TabWidgetLayoutItem:
5327 if (
const QStyleOptionTabWidgetFrame *tabWidgetOpt =
5328 qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5330
5331
5332
5333
5334 rect = tabWidgetOpt->rect;
5335 if (tabWidgetOpt->shape == QTabBar::RoundedNorth)
5336 rect.setTop(rect.top() + SIZE(6 , 3 , 2 ));
5340#if QT_CONFIG(dockwidget)
5341 case SE_DockWidgetCloseButton:
5342 case SE_DockWidgetFloatButton:
5343 case SE_DockWidgetTitleBarText:
5344 case SE_DockWidgetIcon: {
5345 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
5346 int buttonMargin = proxy()->pixelMetric(PM_DockWidgetTitleBarButtonMargin, opt, widget);
5347 QRect srect = opt->rect;
5349 const QStyleOptionDockWidget *dwOpt
5350 = qstyleoption_cast<
const QStyleOptionDockWidget*>(opt);
5351 bool canClose = dwOpt == 0 ?
true : dwOpt->closable;
5352 bool canFloat = dwOpt == 0 ?
false : dwOpt->floatable;
5354 const bool verticalTitleBar = dwOpt->verticalTitleBar;
5358 if (verticalTitleBar)
5359 srect = srect.transposed();
5362 int right = srect.right();
5363 int left = srect.left();
5367 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton,
5368 opt, widget).actualSize(QSize(iconSize, iconSize));
5369 sz += QSize(buttonMargin, buttonMargin);
5370 if (verticalTitleBar)
5371 sz = sz.transposed();
5372 closeRect = QRect(left,
5373 srect.center().y() - sz.height()/2,
5374 sz.width(), sz.height());
5375 left = closeRect.right() + 1;
5377 if (sr == SE_DockWidgetCloseButton) {
5384 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarNormalButton,
5385 opt, widget).actualSize(QSize(iconSize, iconSize));
5386 sz += QSize(buttonMargin, buttonMargin);
5387 if (verticalTitleBar)
5388 sz = sz.transposed();
5389 floatRect = QRect(left,
5390 srect.center().y() - sz.height()/2,
5391 sz.width(), sz.height());
5392 left = floatRect.right() + 1;
5394 if (sr == SE_DockWidgetFloatButton) {
5400 if (
const QDockWidget *dw = qobject_cast<
const QDockWidget*>(widget)) {
5402 if (dw->isFloating())
5403 icon = dw->windowIcon();
5405 && icon.cacheKey() != QApplication::windowIcon().cacheKey()) {
5406 QSize sz = icon.actualSize(QSize(rect.height(), rect.height()));
5407 if (verticalTitleBar)
5408 sz = sz.transposed();
5409 iconRect = QRect(right - sz.width(), srect.center().y() - sz.height()/2,
5410 sz.width(), sz.height());
5411 right = iconRect.left() - 1;
5414 if (sr == SE_DockWidgetIcon) {
5419 QRect textRect = QRect(left, srect.top(),
5420 right - left, srect.height());
5421 if (sr == SE_DockWidgetTitleBarText) {
5427 if (verticalTitleBar) {
5428 rect = QRect(srect.left() + rect.top() - srect.top(),
5429 srect.top() + srect.right() - rect.right(),
5430 rect.height(), rect.width());
5432 rect = visualRect(opt->direction, srect, rect);
5438 rect = QCommonStyle::subElementRect(sr, opt, widget);
5471 const QWidget *widget)
const
5473 Q_D(
const QMacStyle);
5474 QMacCGContext cg(p);
5476 qCWarning(lcMacStyle) <<
"drawComplexControl:" << cc <<
"invalid (nullptr) graphics context";
5477 QWindow *window = widget && widget->window() ? widget->window()->windowHandle() :
nullptr;
5478 d->resolveCurrentNSView(window);
5481 if (
const QStyleOptionSlider *sb = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5484 const bool drawTrack = sb->subControls & SC_ScrollBarGroove;
5485 const bool drawKnob = sb->subControls & SC_ScrollBarSlider && sb->minimum != sb->maximum;
5486 if (!drawTrack && !drawKnob)
5489 const bool isHorizontal = sb->orientation == Qt::Horizontal;
5491 if (opt && opt->styleObject && !QMacStylePrivate::scrollBars.contains(opt->styleObject))
5492 QMacStylePrivate::scrollBars.append(QPointer<QObject>(opt->styleObject));
5494 static const CGFloat knobWidths[] = { 7.0, 5.0, 5.0 };
5495 static const CGFloat expandedKnobWidths[] = { 11.0, 9.0, 9.0 };
5496 const auto cocoaSize = d->effectiveAquaSizeConstrain(opt, widget);
5497 const CGFloat maxExpandScale = expandedKnobWidths[cocoaSize] / knobWidths[cocoaSize];
5499 const QStyle *realStyle = widget ? widget->style() : proxy();
5500 const bool isTransient = realStyle->styleHint(SH_ScrollBar_Transient, opt, widget);
5502 d->stopAnimation(opt->styleObject);
5503 bool wasActive =
false;
5504 CGFloat opacity = 0.0;
5505 CGFloat expandScale = 1.0;
5506 CGFloat expandOffset = 0.0;
5507 bool shouldExpand =
false;
5509 if (QObject *styleObject = opt->styleObject) {
5510 const int oldPos = styleObject->property(
"_q_stylepos").toInt();
5511 const int oldMin = styleObject->property(
"_q_stylemin").toInt();
5512 const int oldMax = styleObject->property(
"_q_stylemax").toInt();
5513 const QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
5514 const QStyle::State oldState =
static_cast<QStyle::State>(styleObject->property(
"_q_stylestate").value<QStyle::State::Int>());
5515 const uint oldActiveControls = styleObject->property(
"_q_stylecontrols").toUInt();
5519 const bool transient = isTransient && !opt->activeSubControls && !(sb->state & State_On);
5522 oldPos != sb->sliderPosition ||
5523 oldMin != sb->minimum ||
5524 oldMax != sb->maximum ||
5525 oldRect != sb->rect ||
5526 oldState != sb->state ||
5527 oldActiveControls != sb->activeSubControls) {
5533 styleObject->setProperty(
"_q_stylepos", sb->sliderPosition);
5534 styleObject->setProperty(
"_q_stylemin", sb->minimum);
5535 styleObject->setProperty(
"_q_stylemax", sb->maximum);
5536 styleObject->setProperty(
"_q_stylerect", sb->rect);
5537 styleObject->setProperty(
"_q_stylestate",
static_cast<QStyle::State::Int>(sb->state));
5538 styleObject->setProperty(
"_q_stylecontrols",
static_cast<uint>(sb->activeSubControls));
5540 QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
5543 anim =
new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Deactivating, styleObject);
5544 d->startAnimation(anim);
5545 }
else if (anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5548 anim->setCurrentTime(0);
5550 }
else if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5551 d->stopAnimation(styleObject);
5555 QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
5556 if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5559 if (oldActiveControls)
5560 anim->setActive(
true);
5562 wasActive = anim->wasActive();
5563 opacity = anim->currentValue();
5566 shouldExpand = isTransient && (opt->activeSubControls || wasActive);
5568 if (!anim && !oldActiveControls) {
5570 anim =
new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Activating, styleObject);
5571 d->startAnimation(anim);
5573 if (anim && anim->mode() == QScrollbarStyleAnimation::Activating) {
5574 expandScale = 1.0 + (maxExpandScale - 1.0) * anim->currentValue();
5575 expandOffset = 5.5 * (1.0 - anim->currentValue());
5578 expandScale = maxExpandScale;
5584 d->setupNSGraphicsContext(cg, NO );
5586 const auto controlType = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical;
5587 const auto cw = QMacStylePrivate::CocoaControl(controlType, cocoaSize);
5588 NSScroller *scroller =
static_cast<NSScroller *>(d->cocoaControl(cw));
5590 const QColor bgColor = QStyleHelper::backgroundColor(opt->palette, widget);
5591 const bool hasDarkBg = bgColor.red() < 128 && bgColor.green() < 128 && bgColor.blue() < 128;
5595 scroller.knobStyle = hasDarkBg? NSScrollerKnobStyleLight : NSScrollerKnobStyleDark;
5597 scroller.knobStyle = NSScrollerKnobStyleDefault;
5600 scroller.scrollerStyle = isTransient ? NSScrollerStyleOverlay : NSScrollerStyleLegacy;
5602 if (!setupScroller(scroller, sb))
5606 CGContextBeginTransparencyLayerWithRect(cg, scroller.frame,
nullptr);
5607 CGContextSetAlpha(cg, opacity);
5612 if (!isTransient || opt->activeSubControls || wasActive) {
5613 CGRect trackRect = scroller.bounds;
5615 trackRect.origin.y += expandOffset;
5617 trackRect.origin.x += expandOffset;
5618 [scroller drawKnobSlotInRect:trackRect highlight:NO];
5628 const CGFloat scrollerWidth = [NSScroller scrollerWidthForControlSize:scroller.controlSize scrollerStyle:scroller.scrollerStyle];
5629 const CGFloat knobWidth = knobWidths[cocoaSize] * expandScale;
5631 const CGRect scrollerKnobRect = CGRectInset([scroller rectForPart:NSScrollerKnob], 1, 1);
5632 const CGFloat knobLength = isHorizontal ? scrollerKnobRect.size.width : scrollerKnobRect.size.height;
5633 const CGFloat knobPos = isHorizontal ? scrollerKnobRect.origin.x : scrollerKnobRect.origin.y;
5634 const CGFloat knobOffset = qRound((scrollerWidth + expandOffset - knobWidth) / 2.0);
5635 const CGFloat knobRadius = knobWidth / 2.0;
5638 knobRect = CGRectMake(knobPos, knobOffset, knobLength, knobWidth);
5640 knobRect = CGRectMake(knobOffset, knobPos, knobWidth, knobLength);
5641 QCFType<CGPathRef> knobPath = CGPathCreateWithRoundedRect(knobRect, knobRadius, knobRadius,
nullptr);
5642 CGContextAddPath(cg, knobPath);
5643 CGContextSetAlpha(cg, 0.5);
5644 CGColorRef knobColor = hasDarkBg ? NSColor.whiteColor.CGColor : NSColor.blackColor.CGColor;
5645 CGContextSetFillColorWithColor(cg, knobColor);
5646 CGContextFillPath(cg);
5648 [scroller drawKnob];
5650 if (!isTransient && opt->activeSubControls) {
5655 CGContextSetBlendMode(cg, kCGBlendModePlusDarker);
5656 [scroller drawKnob];
5662 CGContextEndTransparencyLayer(cg);
5664 d->restoreNSGraphicsContext(cg);
5668 if (
const QStyleOptionSlider *sl = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5669 const bool isHorizontal = sl->orientation == Qt::Horizontal;
5670 const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical;
5671 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
5672 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5673 auto *slider =
static_cast<NSSlider *>(d->cocoaControl(cw));
5674 if (!setupSlider(slider, sl))
5677 const bool hasTicks = sl->tickPosition != QSlider::NoTicks;
5678 const bool hasDoubleTicks = sl->tickPosition == QSlider::TicksBothSides;
5679 const bool drawKnob = sl->subControls & SC_SliderHandle;
5680 const bool drawBar = sl->subControls & SC_SliderGroove;
5681 const bool drawTicks = sl->subControls & SC_SliderTickmarks;
5682 const bool isPressed = qt_apple_runningWithLiquidGlass() ?
false : sl->state & State_Sunken;
5686 const CGRect knobRect = [slider.cell knobRectFlipped:slider.isFlipped];
5687 pressPoint.x = CGRectGetMidX(knobRect);
5688 pressPoint.y = CGRectGetMidY(knobRect);
5703 [slider.cell startTrackingAt:pressPoint inView:slider];
5704 [slider.cell startTrackingAt:pressPoint inView:slider];
5707 d->drawNSViewInRect(slider, opt->rect, p, ^(CGContextRef ctx,
const CGRect &rect) {
5710 const bool verticalFlip = !isHorizontal && !sl->upsideDown;
5713 if (sl->upsideDown) {
5714 CGContextTranslateCTM(ctx, rect.size.width, rect.origin.y);
5715 CGContextScaleCTM(ctx, -1, 1);
5717 CGContextTranslateCTM(ctx, 0, rect.origin.y);
5719 }
else if (verticalFlip) {
5720 CGContextTranslateCTM(ctx, rect.origin.x, rect.size.height);
5721 CGContextScaleCTM(ctx, 1, -1);
5724 if (hasDoubleTicks) {
5727 CGContextTranslateCTM(ctx, 0, 4);
5729 CGContextTranslateCTM(ctx, 1, 0);
5736 const bool drawAllParts = drawKnob && drawBar && (!hasTicks || drawTicks);
5737 if (drawAllParts && !hasDoubleTicks && (!verticalFlip || drawTicks)) {
5741 if (verticalFlip && drawTicks) {
5744 slider.intValue = slider.maxValue - slider.intValue + slider.minValue;
5746 [slider drawRect:CGRectZero];
5750 NSSliderCell *cell = slider.cell;
5752 const int numberOfTickMarks = slider.numberOfTickMarks;
5755 slider.numberOfTickMarks = 0;
5757 const CGRect barRect = [cell barRectFlipped:slider.isFlipped];
5759 if (!isHorizontal && !sl->upsideDown && (hasDoubleTicks || !hasTicks)) {
5767 [cell drawBarInside:barRect flipped:
true];
5769 [cell drawBarInside:barRect flipped:!verticalFlip];
5773 slider.numberOfTickMarks = numberOfTickMarks;
5776 if (hasTicks && drawTicks) {
5777 if (!drawBar && hasDoubleTicks)
5778 slider.numberOfTickMarks = numberOfTickMarks;
5780 if (qt_apple_runningWithLiquidGlass())
5781 drawTickMarks(ctx, slider, sl);
5783 [cell drawTickMarks];
5785 if (hasDoubleTicks) {
5787 CGAffineTransform tickMarksFlip;
5788 const CGRect tickMarkRect = [cell rectOfTickMarkAtIndex:0];
5790 tickMarksFlip = CGAffineTransformMakeTranslation(0, rect.size.height - tickMarkRect.size.height - 3);
5791 tickMarksFlip = CGAffineTransformScale(tickMarksFlip, 1, -1);
5793 tickMarksFlip = CGAffineTransformMakeTranslation(rect.size.width - tickMarkRect.size.width / 2, 0);
5794 tickMarksFlip = CGAffineTransformScale(tickMarksFlip, -1, 1);
5796 CGContextConcatCTM(ctx, tickMarksFlip);
5797 [cell drawTickMarks];
5798 CGContextConcatCTM(ctx, CGAffineTransformInvert(tickMarksFlip));
5805 slider.numberOfTickMarks = 0;
5806 if (qt_apple_runningWithLiquidGlass())
5807 drawSliderKnob(ctx, slider);
5817 [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO];
5818 [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO];
5822#if QT_CONFIG(spinbox)
5824 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
5825 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
5826 const auto lineEditRect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget);
5827 QStyleOptionFrame frame;
5828 static_cast<QStyleOption &>(frame) = *opt;
5829 frame.rect = lineEditRect;
5830 frame.state |= State_Sunken;
5831 frame.lineWidth = 1;
5832 frame.midLineWidth = 0;
5833 frame.features = QStyleOptionFrame::None;
5834 frame.frameShape = QFrame::Box;
5835 drawPrimitive(PE_FrameLineEdit, &frame, p, widget);
5837 if (sb->subControls & (SC_SpinBoxUp | SC_SpinBoxDown)) {
5838 const QRect updown = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget)
5839 | proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
5842 d->setupNSGraphicsContext(cg, NO);
5844 const auto aquaSize = d->effectiveAquaSizeConstrain(opt, widget);
5845 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize);
5846 NSStepperCell *cell =
static_cast<NSStepperCell *>(d->cocoaCell(cw));
5847 const auto controlSize = cell.controlSize;
5848 if (qt_apple_runningWithLiquidGlass())
5849 cell.controlSize = NSControlSizeMini;
5850 cell.enabled = (sb->state & State_Enabled);
5852 const CGRect newRect = [cell drawingRectForBounds:updown.toCGRect()];
5854 const bool upPressed = sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken);
5855 const bool downPressed = sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken);
5856 const CGFloat x = CGRectGetMidX(newRect);
5857 const CGFloat y = upPressed ? -3 : 3;
5858 const CGPoint pressPoint = CGPointMake(x, y);
5861 if (upPressed || downPressed)
5862 [cell startTrackingAt:pressPoint inView:d->backingStoreNSView];
5864 [cell drawWithFrame:newRect inView:d->backingStoreNSView];
5866 if (upPressed || downPressed)
5867 [cell stopTracking:pressPoint at:pressPoint inView:d->backingStoreNSView mouseIsUp:NO];
5869 d->restoreNSGraphicsContext(cg);
5870 if (qt_apple_runningWithLiquidGlass())
5871 cell.controlSize = controlSize;
5876#if QT_CONFIG(combobox)
5878 if (
const auto *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
5879 const bool isEnabled = combo->state & State_Enabled;
5880 const bool isPressed = combo->state & State_Sunken;
5882 const auto ct = cocoaControlType(combo, widget);
5883 const auto cs = d->effectiveAquaSizeConstrain(combo, widget);
5884 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5885 auto *cc =
static_cast<NSControl *>(d->cocoaControl(cw));
5886 cc.enabled = isEnabled;
5887 QRectF frameRect = cw.adjustedControlFrame(combo->rect);
5888 if (cw.type == QMacStylePrivate::Button_PopupButton) {
5890 auto *pb =
static_cast<NSPopUpButton *>(cc);
5892 if (cw.size == QStyleHelper::SizeSmall) {
5893 frameRect = frameRect.translated(0, 1);
5894 }
else if (cw.size == QStyleHelper::SizeMini) {
5896 frameRect = frameRect.translated(2, -0.5);
5898 pb.frame = frameRect.toCGRect();
5899 [pb highlight:isPressed];
5900 d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
5901 [pb.cell drawBezelWithFrame:r inView:pb.superview];
5903 }
else if (cw.type == QMacStylePrivate::ComboBox) {
5905 auto *cb =
static_cast<NSComboBox *>(cc);
5906 const auto frameRect = cw.adjustedControlFrame(combo->rect);
5907 cb.frame = frameRect.toCGRect();
5910 if (NSButtonCell *cell =
static_cast<NSButtonCell *>([cc.cell qt_valueForPrivateKey:@
"_buttonCell"])) {
5911 cell.highlighted = isPressed;
5916 d->drawNSViewInRect(cb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
5918 [cb.cell drawWithFrame:r inView:cb];
5922 if (combo->state & State_HasFocus) {
5924 const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, combo, widget);
5925 const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, combo, widget);
5927 if (cw.type == QMacStylePrivate::Button_PopupButton) {
5928 if (qt_apple_runningWithLiquidGlass())
5929 focusRect = QRectF::fromCGRect(qt_alignmentRectForFrame(cc.frame, cw.size, cw.type));
5931 focusRect = QRectF::fromCGRect([cc alignmentRectForFrame:cc.frame]);
5932 focusRect -= pullDownButtonShadowMargins[cw.size];
5933 if (cw.size == QStyleHelper::SizeSmall)
5934 focusRect = focusRect.translated(0, 1);
5935 else if (cw.size == QStyleHelper::SizeMini)
5936 focusRect = focusRect.translated(2, -1);
5937 }
else if (cw.type == QMacStylePrivate::ComboBox) {
5938 focusRect = frameRect - comboBoxFocusRingMargins[cw.size];
5940 d->drawFocusRing(p, focusRect, hMargin, vMargin, cw);
5946 if (
const auto *titlebar = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
5947 const bool isActive = (titlebar->state & State_Active)
5948 && (titlebar->titleBarState & State_Active);
5950 p->fillRect(opt->rect, Qt::transparent);
5951 p->setRenderHint(QPainter::Antialiasing);
5952 p->setClipRect(opt->rect, Qt::IntersectClip);
5956 const auto outerFrameRect = QRectF(opt->rect.adjusted(0, 0, 0, opt->rect.height()));
5957 QPainterPath outerFramePath = d->windowPanelPath(outerFrameRect);
5958 p->fillPath(outerFramePath, opt->palette.dark());
5960 const auto frameAdjust = 1.0 / p->device()->devicePixelRatio();
5961 const auto innerFrameRect = outerFrameRect.adjusted(frameAdjust, frameAdjust, -frameAdjust, 0);
5962 QPainterPath innerFramePath = d->windowPanelPath(innerFrameRect);
5963 p->fillPath(innerFramePath, opt->palette.button());
5965 if (titlebar->subControls & (SC_TitleBarCloseButton
5966 | SC_TitleBarMaxButton
5967 | SC_TitleBarMinButton
5968 | SC_TitleBarNormalButton)) {
5969 const bool isHovered = (titlebar->state & State_MouseOver);
5970 static const SubControl buttons[] = {
5971 SC_TitleBarCloseButton, SC_TitleBarMinButton, SC_TitleBarMaxButton
5973 for (
const auto sc : buttons) {
5974 const auto ct = d->windowButtonCocoaControl(sc);
5975 const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
5976 auto *wb =
static_cast<NSButton *>(d->cocoaControl(cw));
5977 wb.enabled = (sc & titlebar->subControls) && isActive;
5978 [wb highlight:(titlebar->state & State_Sunken) && (sc & titlebar->activeSubControls)];
5979 Q_UNUSED(isHovered);
5981 const auto buttonRect = proxy()->subControlRect(CC_TitleBar, titlebar, sc, widget);
5982 d->drawNSViewInRect(wb, buttonRect, p, ^(CGContextRef,
const CGRect &rect) {
5983 auto *wbCell =
static_cast<NSButtonCell *>(wb.cell);
5984 [wbCell drawWithFrame:rect inView:wb];
5989 if (titlebar->subControls & SC_TitleBarLabel) {
5990 const auto tr = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarLabel, widget);
5991 if (!titlebar->icon.isNull()) {
5992 const auto iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
5993 const auto iconSize = QSize(iconExtent, iconExtent);
5994 const auto iconPos = tr.x() - titlebar->icon.actualSize(iconSize).width() - qRound(titleBarIconTitleSpacing);
5996 if (iconPos < tr.right() - titleBarIconTitleSpacing)
5997 p->drawPixmap(iconPos, tr.y(), titlebar->icon.pixmap(iconSize, QIcon::Normal));
6000 if (!titlebar->text.isEmpty())
6001 drawItemText(p, tr, Qt::AlignCenter, opt->palette, isActive, titlebar->text, QPalette::Text);
6006 if (
const QStyleOptionGroupBox *gb
6007 = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
6009 QStyleOptionGroupBox groupBox(*gb);
6010 const bool flat = groupBox.features & QStyleOptionFrame::Flat;
6012 groupBox.state |= QStyle::State_Mini;
6014 groupBox.subControls = groupBox.subControls & ~SC_GroupBoxFrame;
6016 const bool didSetFont = widget && widget->testAttribute(Qt::WA_SetFont);
6017 const bool didModifySubControls = !didSetFont && QApplication::desktopSettingsAware();
6018 if (didModifySubControls)
6019 groupBox.subControls = groupBox.subControls & ~SC_GroupBoxLabel;
6020 QCommonStyle::drawComplexControl(cc, &groupBox, p, widget);
6021 if (didModifySubControls) {
6022 const QRect rect = proxy()->subControlRect(CC_GroupBox, &groupBox, SC_GroupBoxLabel, widget);
6023 const bool rtl = groupBox.direction == Qt::RightToLeft;
6024 const int alignment = Qt::TextHideMnemonic | (rtl ? Qt::AlignRight : Qt::AlignLeft);
6025 const QFont savedFont = p->font();
6026 if (!flat && d->smallSystemFont)
6027 p->setFont(*d->smallSystemFont);
6028 proxy()->drawItemText(p, rect, alignment, groupBox.palette, groupBox.state & State_Enabled, groupBox.text, QPalette::WindowText);
6030 p->setFont(savedFont);
6035 if (
const QStyleOptionToolButton *tb
6036 = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
6037#if QT_CONFIG(accessibility)
6038 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) {
6039 if (tb->subControls & SC_ToolButtonMenu) {
6040 QStyleOption arrowOpt = *tb;
6041 arrowOpt.rect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget);
6042 arrowOpt.rect.setY(arrowOpt.rect.y() + arrowOpt.rect.height() / 2);
6043 arrowOpt.rect.setHeight(arrowOpt.rect.height() / 2);
6044 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
6045 }
else if ((tb->features & QStyleOptionToolButton::HasMenu)
6046 && (tb->toolButtonStyle != Qt::ToolButtonTextOnly && !tb->icon.isNull())) {
6047 d->drawToolbarButtonArrow(tb, p);
6049 if (tb->state & State_On) {
6050 NSView *view = window ? (NSView *)window->winId() : nil;
6053 isKey = [view.window isKeyWindow];
6055 QBrush brush(brushForToolButton(isKey));
6057 path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4);
6058 p->setRenderHint(QPainter::Antialiasing);
6059 p->fillPath(path, brush);
6061 proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget);
6065 auto bflags = tb->state;
6066 if (tb->subControls & SC_ToolButton)
6067 bflags |= State_Sunken;
6068 auto mflags = tb->state;
6069 if (tb->subControls & SC_ToolButtonMenu)
6070 mflags |= State_Sunken;
6072 if (tb->subControls & SC_ToolButton) {
6073 if (bflags & (State_Sunken | State_On | State_Raised)) {
6074 const bool isEnabled = tb->state & State_Enabled;
6075 const bool isPressed = tb->state & State_Sunken;
6076 const bool isHighlighted = (tb->state & State_Active) && (tb->state & State_On);
6077 const auto ct = QMacStylePrivate::Button_PushButton;
6078 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6079 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6080 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
6081 pb.bezelStyle = NSBezelStyleShadowlessSquare;
6082 pb.frame = opt->rect.toCGRect();
6083 pb.buttonType = NSButtonTypePushOnPushOff;
6084 pb.enabled = isEnabled;
6085 [pb highlight:isPressed];
6086 pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff;
6087 const auto buttonRect = proxy()->subControlRect(cc, tb, SC_ToolButton, widget);
6088 d->drawNSViewInRect(pb, buttonRect, p, ^(CGContextRef,
const CGRect &rect) {
6089 [pb.cell drawBezelWithFrame:rect inView:pb];
6094 if (tb->subControls & SC_ToolButtonMenu) {
6095 const auto menuRect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget);
6096 QStyleOption arrowOpt = *tb;
6101 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
6102 }
else if (tb->features & QStyleOptionToolButton::HasMenu) {
6103 d->drawToolbarButtonArrow(tb, p);
6105 QRect buttonRect = proxy()->subControlRect(CC_ToolButton, tb, SC_ToolButton, widget);
6106 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
6107 QStyleOptionToolButton label = *tb;
6108 label.rect = buttonRect.adjusted(fw, fw, -fw, -fw);
6109 proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget);
6115 if (
const QStyleOptionSlider *dial = qstyleoption_cast<
const QStyleOptionSlider *>(opt))
6116 QStyleHelper::drawDial(dial, p);
6120 QCommonStyle::drawComplexControl(cc, opt, p, widget);
6212 const QWidget *widget)
const
6214 Q_D(
const QMacStyle);
6218 if (
const QStyleOptionSlider *sb = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6219 const bool isHorizontal = sb->orientation == Qt::Horizontal;
6220 const bool isReverseHorizontal = isHorizontal && (sb->direction == Qt::RightToLeft);
6222 NSScrollerPart part = NSScrollerNoPart;
6223 if (sc == SC_ScrollBarSlider) {
6224 part = NSScrollerKnob;
6225 }
else if (sc == SC_ScrollBarGroove) {
6226 part = NSScrollerKnobSlot;
6227 }
else if (sc == SC_ScrollBarSubPage || sc == SC_ScrollBarAddPage) {
6228 if ((!isReverseHorizontal && sc == SC_ScrollBarSubPage)
6229 || (isReverseHorizontal && sc == SC_ScrollBarAddPage))
6230 part = NSScrollerDecrementPage;
6232 part = NSScrollerIncrementPage;
6236 if (part != NSScrollerNoPart) {
6237 const auto ct = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical;
6238 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6239 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6240 auto *scroller =
static_cast<NSScroller *>(d->cocoaControl(cw));
6241 if (setupScroller(scroller, sb))
6242 ret = QRectF::fromCGRect([scroller rectForPart:part]).toRect();
6247 if (
const QStyleOptionSlider *sl = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6248 const bool hasTicks = sl->tickPosition != QSlider::NoTicks;
6249 const bool isHorizontal = sl->orientation == Qt::Horizontal;
6250 const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical;
6251 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6252 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6253 auto *slider =
static_cast<NSSlider *>(d->cocoaControl(cw));
6254 if (!setupSlider(slider, sl))
6257 NSSliderCell *cell = slider.cell;
6258 if (sc == SC_SliderHandle) {
6259 ret = QRectF::fromCGRect([cell knobRectFlipped:slider.isFlipped]).toRect();
6261 ret.setTop(sl->rect.top());
6262 ret.setBottom(sl->rect.bottom());
6264 ret.setLeft(sl->rect.left());
6265 ret.setRight(sl->rect.right());
6267 }
else if (sc == SC_SliderGroove) {
6268 ret = QRectF::fromCGRect([cell barRectFlipped:slider.isFlipped]).toRect();
6269 }
else if (hasTicks && sc == SC_SliderTickmarks) {
6270 const auto tickMarkRect = QRectF::fromCGRect([cell rectOfTickMarkAtIndex:0]);
6272 ret = QRect(sl->rect.left(), tickMarkRect.top(), sl->rect.width(), tickMarkRect.height());
6274 ret = QRect(tickMarkRect.left(), sl->rect.top(), tickMarkRect.width(), sl->rect.height());
6279 if (sl->upsideDown) {
6280 ret = QRect(sl->rect.right() - ret.right(), sl->rect.top(), ret.width(), sl->rect.height());
6282 ret.setTop(sl->rect.top());
6283 ret.setBottom(sl->rect.bottom());
6286 if (!sl->upsideDown) {
6287 ret = QRect(sl->rect.left(), sl->rect.bottom() - ret.bottom(), sl->rect.width(), ret.height());
6289 ret.setLeft(sl->rect.left());
6290 ret.setRight(sl->rect.right());
6296 if (
const auto *titlebar = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
6302 if (sc == SC_TitleBarLabel) {
6303 qreal labelWidth = titlebar->fontMetrics.horizontalAdvance(titlebar->text) + 1;
6304 qreal labelHeight = titlebar->fontMetrics.height();
6306 const auto lastButtonRect = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarMaxButton, widget);
6307 qreal controlsSpacing = lastButtonRect.right() + titleBarButtonSpacing;
6308 if (!titlebar->icon.isNull()) {
6309 const auto iconSize = proxy()->pixelMetric(PM_SmallIconSize);
6310 const auto actualIconSize = titlebar->icon.actualSize(QSize(iconSize, iconSize)).width();
6311 controlsSpacing += actualIconSize + titleBarIconTitleSpacing;
6314 const qreal labelPos = qMax(controlsSpacing, (opt->rect.width() - labelWidth) / 2.0);
6315 labelWidth = qMin(labelWidth, opt->rect.width() - (labelPos + titleBarTitleRightMargin));
6316 ret = QRect(labelPos, (opt->rect.height() - labelHeight) / 2,
6317 labelWidth, labelHeight);
6319 const auto currentButton = d->windowButtonCocoaControl(sc);
6320 if (currentButton == QMacStylePrivate::NoControl)
6323 QPointF buttonPos = titlebar->rect.topLeft() + QPointF(titleBarButtonSpacing, 0);
6325 for (
int ct = QMacStylePrivate::Button_WindowClose; ct <= currentButton; ct++) {
6326 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::CocoaControlType(ct),
6327 QStyleHelper::SizeLarge);
6328 auto *wb =
static_cast<NSButton *>(d->cocoaControl(cw));
6329 if (ct == currentButton)
6330 buttonSize = QSizeF::fromCGSize(wb.frame.size);
6332 buttonPos.rx() += wb.frame.size.width + titleBarButtonSpacing;
6335 const auto vOffset = (opt->rect.height() - buttonSize.height()) / 2.0;
6336 ret = QRectF(buttonPos, buttonSize).translated(0, vOffset).toRect();
6341 if (
const QStyleOptionComboBox *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
6342 const auto ct = cocoaControlType(combo, widget);
6343 const auto cs = d->effectiveAquaSizeConstrain(combo, widget);
6344 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6345 const auto editRect = QMacStylePrivate::comboboxEditBounds(cw.adjustedControlFrame(combo->rect), cw);
6348 case SC_ComboBoxEditField:{
6349 ret = editRect.toAlignedRect();
6351 case SC_ComboBoxArrow:{
6352 ret = editRect.toAlignedRect();
6353 ret.setX(ret.x() + ret.width());
6354 ret.setWidth(combo->rect.right() - ret.right());
6356 case SC_ComboBoxListBoxPopup:{
6357 if (combo->editable) {
6358 const CGRect inner = QMacStylePrivate::comboboxInnerBounds(combo->rect.toCGRect(), cw);
6359 const int comboTop = combo->rect.top();
6360 ret = QRect(qRound(inner.origin.x),
6362 qRound(inner.origin.x - combo->rect.left() + inner.size.width),
6363 editRect.bottom() - comboTop + 2);
6365 ret = QRect(combo->rect.x() + 4 - 11,
6366 combo->rect.y() + 1,
6367 editRect.width() + 10 + 11,
6377 if (
const QStyleOptionGroupBox *groupBox = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
6378 bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
6379 const bool flat = groupBox->features & QStyleOptionFrame::Flat;
6380 bool hasNoText = !checkable && groupBox->text.isEmpty();
6382 case SC_GroupBoxLabel:
6383 case SC_GroupBoxCheckBox: {
6385 const bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
6386 const bool fontIsSet = (widget && widget->testAttribute(Qt::WA_SetFont))
6387 || !QApplication::desktopSettingsAware();
6388 const int margin = flat || hasNoText ? 0 : 9;
6389 ret = groupBox->rect.adjusted(margin, 0, -margin, 0);
6391 const QFontMetricsF fm = flat || fontIsSet || !d->smallSystemFont
6392 ? QFontMetricsF(groupBox->fontMetrics)
6393 : QFontMetricsF(*d->smallSystemFont);
6394 const QSizeF s = fm.size(Qt::AlignHCenter | Qt::AlignVCenter, qt_mac_removeMnemonics(groupBox->text), 0,
nullptr);
6395 const int tw = qCeil(s.width());
6396 const int h = qCeil(fm.height());
6399 QRect labelRect = alignedRect(groupBox->direction, groupBox->textAlignment,
6401 if (flat && checkable)
6402 labelRect.moveLeft(labelRect.left() + 4);
6403 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt, widget);
6404 bool rtl = groupBox->direction == Qt::RightToLeft;
6405 if (sc == SC_GroupBoxLabel) {
6407 int newSum = indicatorWidth + 1;
6408 int newLeft = labelRect.left() + (rtl ? -newSum : newSum);
6409 labelRect.moveLeft(newLeft);
6411 labelRect.moveTop(labelRect.top() + 3);
6413 labelRect.moveTop(labelRect.top() + 4);
6415 int newLeft = labelRect.left() - (rtl ? 3 : -3);
6416 labelRect.moveLeft(newLeft);
6417 labelRect.moveTop(labelRect.top() + 3);
6419 int newLeft = labelRect.left() - (rtl ? 3 : 2);
6420 labelRect.moveLeft(newLeft);
6421 labelRect.moveTop(labelRect.top() + 4);
6426 if (sc == SC_GroupBoxCheckBox) {
6427 int left = rtl ? labelRect.right() - indicatorWidth : labelRect.left() - 1;
6428 int top = flat ? ret.top() + 1 : ret.top() + 5;
6429 ret.setRect(left, top,
6430 indicatorWidth, proxy()->pixelMetric(PM_IndicatorHeight, opt, widget));
6434 case SC_GroupBoxContents:
6435 case SC_GroupBoxFrame: {
6436 QFontMetrics fm = groupBox->fontMetrics;
6439 if (widget && !widget->testAttribute(Qt::WA_SetFont)
6440 && QApplication::desktopSettingsAware())
6441 fm = QFontMetrics(qt_app_fonts_hash()->value(
"QSmallFont", QFont()));
6446 yOffset = -qCeil(QFontMetricsF(fm).height());
6447 ret = opt->rect.adjusted(0, qCeil(QFontMetricsF(fm).height()) + yOffset, 0, 0);
6448 if (sc == SC_GroupBoxContents) {
6450 ret.adjust(3, -5, -3, -4);
6452 ret.adjust(3, 3, -3, -4);
6457 ret = QCommonStyle::subControlRect(cc, groupBox, sc, widget);
6462#if QT_CONFIG(spinbox)
6464 if (
const QStyleOptionSpinBox *spin = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
6465 QStyleHelper::WidgetSizePolicy aquaSize = d->effectiveAquaSizeConstrain(spin, widget);
6466 const auto fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin, widget);
6470 case QStyleHelper::SizeLarge:
6474 case QStyleHelper::SizeSmall:
6478 case QStyleHelper::SizeMini:
6488 case SC_SpinBoxDown: {
6489 if (spin->buttonSymbols == QAbstractSpinBox::NoButtons)
6493 const int x = spin->rect.width() - spinner_w;
6494 ret.setRect(x + spin->rect.x(), y + spin->rect.y(), spinner_w, spin->rect.height() - y * 2);
6497 case QStyleHelper::SizeLarge:
6500 case QStyleHelper::SizeSmall:
6501 hackTranslateX = -2;
6503 case QStyleHelper::SizeMini:
6504 hackTranslateX = -1;
6510 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize);
6511 NSStepperCell *cell =
static_cast<NSStepperCell *>(d->cocoaCell(cw));
6512 const CGRect outRect = [cell drawingRectForBounds:ret.toCGRect()];
6513 ret = QRectF::fromCGRect(outRect).toRect();
6517 ret.setHeight(ret.height() / 2);
6519 case SC_SpinBoxDown:
6520 ret.setY(ret.y() + ret.height() / 2);
6526 ret.translate(hackTranslateX, 0);
6527 ret = visualRect(spin->direction, spin->rect, ret);
6530 case SC_SpinBoxEditField:
6531 ret = spin->rect.adjusted(fw, fw, -fw, -fw);
6532 if (spin->buttonSymbols != QAbstractSpinBox::NoButtons) {
6533 ret.setWidth(spin->rect.width() - spinBoxSep - spinner_w);
6534 ret = visualRect(spin->direction, spin->rect, ret);
6538 ret = QCommonStyle::subControlRect(cc, spin, sc, widget);
6545 ret = QCommonStyle::subControlRect(cc, opt, sc, widget);
6546 if (sc == SC_ToolButtonMenu) {
6547#if QT_CONFIG(accessibility)
6548 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar))
6549 ret.adjust(-toolButtonArrowMargin, 0, 0, 0);
6551 ret.adjust(-1, 0, 0, 0);
6555 ret = QCommonStyle::subControlRect(cc, opt, sc, widget);
6562 const QSize &csz,
const QWidget *widget)
const
6564 Q_D(
const QMacStyle);
6566 bool useAquaGuideline =
true;
6569#if QT_CONFIG(spinbox)
6571 if (
const QStyleOptionSpinBox *vopt = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
6572 const bool hasButtons = (vopt->buttonSymbols != QAbstractSpinBox::NoButtons);
6573 const int buttonWidth = hasButtons ? proxy()->subControlRect(CC_SpinBox, vopt, SC_SpinBoxUp, widget).width() : 0;
6574 sz += QSize(buttonWidth, 0);
6578 case QStyle::CT_TabWidget:
6581 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6613#if QT_CONFIG(tabwidget)
6614 if (
const QStyleOptionTabWidgetFrame *twf
6615 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
6617 const int overlap = pixelMetric(PM_TabBarBaseOverlap, opt, widget);
6618 const int gapBetweenTabbarAndStackWidget = 2 + 14 - overlap;
6620 const auto tabDirection = QMacStylePrivate::tabDirection(twf->shape);
6621 if (tabDirection == QMacStylePrivate::North
6622 || tabDirection == QMacStylePrivate::South) {
6623 extra = QSize(2, gapBetweenTabbarAndStackWidget + 1);
6625 extra = QSize(gapBetweenTabbarAndStackWidget + 1, 2);
6631#if QT_CONFIG(tabbar)
6632 case QStyle::CT_TabBarTab:
6633 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
6634 const bool differentFont = (widget && widget->testAttribute(Qt::WA_SetFont))
6635 || !QApplication::desktopSettingsAware();
6636 const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape);
6637 const bool verticalTabs = tabDirection == QMacStylePrivate::East
6638 || tabDirection == QMacStylePrivate::West;
6640 sz = sz.transposed();
6642 int defaultTabHeight;
6643 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6645 case QStyleHelper::SizeLarge:
6646 if (tab->documentMode)
6647 defaultTabHeight = 24;
6649 defaultTabHeight = 21;
6651 if (qt_apple_runningWithLiquidGlass() && !tab->documentMode) {
6659 defaultTabHeight = 23;
6662 case QStyleHelper::SizeSmall:
6663 defaultTabHeight = 18;
6665 case QStyleHelper::SizeMini:
6666 defaultTabHeight = 16;
6672 const bool widthSet = !differentFont && tab->icon.isNull();
6674 const auto textSize = opt->fontMetrics.size(Qt::TextShowMnemonic, tab->text);
6675 sz.rwidth() = textSize.width();
6676 sz.rheight() = qMax(defaultTabHeight, textSize.height());
6678 sz.rheight() = qMax(defaultTabHeight, sz.height());
6680 sz.rwidth() += proxy()->pixelMetric(PM_TabBarTabHSpace, tab, widget);
6683 sz = sz.transposed();
6685 int maxWidgetHeight = qMax(tab->leftButtonSize.height(), tab->rightButtonSize.height());
6686 int maxWidgetWidth = qMax(tab->leftButtonSize.width(), tab->rightButtonSize.width());
6688 int widgetWidth = 0;
6689 int widgetHeight = 0;
6691 if (tab->leftButtonSize.isValid()) {
6693 widgetWidth += tab->leftButtonSize.width();
6694 widgetHeight += tab->leftButtonSize.height();
6696 if (tab->rightButtonSize.isValid()) {
6698 widgetWidth += tab->rightButtonSize.width();
6699 widgetHeight += tab->rightButtonSize.height();
6703 sz.setWidth(qMax(sz.width(), maxWidgetWidth));
6704 sz.setHeight(sz.height() + widgetHeight + padding);
6707 sz.setWidth(sz.width() + widgetWidth + padding);
6708 sz.setHeight(qMax(sz.height(), maxWidgetHeight));
6713 case QStyle::CT_PushButton: {
6714 bool isFlat =
false;
6715 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
6716 if (btn->features & QStyleOptionButton::CommandLinkButton)
6717 return QCommonStyle::sizeFromContents(ct, opt, sz, widget);
6718 isFlat = btn->features & QStyleOptionButton::Flat;
6725 const auto controlSize = d->effectiveAquaSizeConstrain(opt, widget, CT_PushButton, sz, &macsz);
6727 if (macsz.width() != -1)
6728 sz.setWidth(macsz.width());
6730 sz.rwidth() += QMacStylePrivate::PushButtonLeftOffset + QMacStylePrivate::PushButtonRightOffset + 12;
6732 if (controlSize != QStyleHelper::SizeMini)
6735 if (controlSize == QStyleHelper::SizeLarge) {
6738 if (sz.height() > 16)
6739 sz.rheight() += pushButtonDefaultHeight[QStyleHelper::SizeLarge] - 16;
6741 sz.setHeight(pushButtonDefaultHeight[QStyleHelper::SizeLarge]);
6743 if (!isFlat && !qt_apple_runningWithLiquidGlass())
6745 if (controlSize == QStyleHelper::SizeMini)
6748 sz.setHeight(pushButtonDefaultHeight[QStyleHelper::SizeSmall]);
6754 case QStyle::CT_MenuItem:
6755 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
6756 int maxpmw = mi->maxIconWidth;
6757#if QT_CONFIG(combobox)
6758 const QComboBox *comboBox = qobject_cast<
const QComboBox *>(widget);
6762 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
6766 h = mi->fontMetrics.height() + 2;
6767 if (!mi->icon.isNull()) {
6768#if QT_CONFIG(combobox)
6770 const QSize &iconSize = comboBox->iconSize();
6771 h = qMax(h, iconSize.height() + 4);
6772 maxpmw = qMax(maxpmw, iconSize.width());
6776 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
6777 h = qMax(h, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() + 4);
6781 if (mi->text.contains(QLatin1Char(
'\t')))
6783 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
6789#if QT_CONFIG(combobox)
6790 if (comboBox && comboBox->isVisible()) {
6791 QStyleOptionComboBox cmb;
6792 cmb.initFrom(comboBox);
6793 cmb.editable =
false;
6794 cmb.subControls = QStyle::SC_ComboBoxEditField;
6795 cmb.activeSubControls = QStyle::SC_None;
6796 w = qMax(w, subControlRect(QStyle::CC_ComboBox, &cmb,
6797 QStyle::SC_ComboBoxEditField,
6807 case CT_MenuBarItem:
6814 if (
const auto *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt))
6815 if (tb->features & QStyleOptionToolButton::Menu)
6819 if (
const auto *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
6820 const auto controlSize = d->effectiveAquaSizeConstrain(opt, widget);
6821 if (!cb->editable) {
6824 sz.rwidth() += QMacStylePrivate::PushButtonLeftOffset + QMacStylePrivate::PushButtonRightOffset + 24;
6826 if (controlSize != QStyleHelper::SizeMini)
6830 if (controlSize == QStyleHelper::SizeLarge && sz.height() > 16)
6831 sz.rheight() += popupButtonDefaultHeight[QStyleHelper::SizeLarge] - 16;
6839 if (controlSize == QStyleHelper::SizeMini)
6842 sz.setHeight(pushButtonDefaultHeight[controlSize]);
6848 if (proxy() ==
this) {
6851 QStyleHintReturnMask menuMask;
6852 QStyleOption myOption = *opt;
6853 myOption.rect.setSize(sz);
6854 if (proxy()->styleHint(SH_Menu_Mask, &myOption, widget, &menuMask))
6855 sz = menuMask.region.boundingRect().size();
6858 case CT_HeaderSection:{
6859 const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt);
6860 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6861 if (header->text.contains(QLatin1Char(
'\n')))
6862 useAquaGuideline =
false;
6866 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6867 const int minimumSize = 24;
6868 if (slider->orientation == Qt::Horizontal)
6869 sz = sz.expandedTo(QSize(minimumSize, sz.height()));
6871 sz = sz.expandedTo(QSize(sz.width(), minimumSize));
6874#if QT_CONFIG(itemviews)
6875 case CT_ItemViewItem:
6876 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
6877 sz = QCommonStyle::sizeFromContents(ct, vopt, csz, widget);
6878 sz.setHeight(sz.height() + 2);
6884 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6887 if (useAquaGuideline && ct != CT_PushButton) {
6890 if (d->aquaSizeConstrain(opt, widget, ct, sz, &macsz) != QStyleHelper::SizeDefault) {
6891 if (macsz.width() != -1)
6892 sz.setWidth(macsz.width());
6893 if (macsz.height() != -1)
6894 sz.setHeight(macsz.height());
6900 if (
const QStyleOptionComboBox *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)){
6901 if (combo->editable) {
6902 const auto widgetSize = d->aquaSizeConstrain(opt, widget);
6903 QMacStylePrivate::CocoaControl cw;
6904 cw.type = combo->editable ? QMacStylePrivate::ComboBox : QMacStylePrivate::Button_PopupButton;
6905 cw.size = widgetSize;
6906 const CGRect diffRect = QMacStylePrivate::comboboxInnerBounds(CGRectZero, cw);
6907 sz.rwidth() -= qRound(diffRect.size.width);
6908 sz.rheight() -= qRound(diffRect.size.height);