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;
3561 static_cast<NSTextFieldCell *>(tf.cell).bezelStyle = isRounded ? NSTextFieldRoundedBezel : NSTextFieldSquareBezel;
3562 tf.frame = opt->rect.toCGRect();
3563 d->drawNSViewInRect(tf, opt->rect, p, ^(CGContextRef,
const CGRect &rect) {
3564 if (!isDarkMode()) {
3569 CGContextRef cgContext = NSGraphicsContext.currentContext.CGContext;
3573 if (cgContext ?
bool(CGBitmapContextGetColorSpace(cgContext)) :
false) {
3574 tf.drawsBackground = YES;
3575 const QColor bgColor = frame->palette.brush(QPalette::Base).color();
3576 tf.backgroundColor = [NSColor colorWithSRGBRed:bgColor.redF()
3577 green:bgColor.greenF()
3578 blue:bgColor.blueF()
3579 alpha:bgColor.alphaF()];
3580 if (bgColor.alpha() != 255) {
3587 CGRect fixedRect = rect;
3588 if (qt_apple_runningWithLiquidGlass()) {
3593 fixedRect = CGRectInset(rect, 1., 1.);
3595 [tf.cell drawWithFrame:fixedRect inView:tf];
3598 QCommonStyle::drawPrimitive(pe, opt, p, w);
3602 case PE_PanelLineEdit:
3604 const QStyleOptionFrame *panel = qstyleoption_cast<
const QStyleOptionFrame *>(opt);
3605 if (
isDarkMode() || (panel && panel->lineWidth <= 0)) {
3611 QCommonStyle::drawPrimitive(pe, opt, p, w);
3616 drawPrimitive(PE_FrameLineEdit, opt, p, w);
3622#if QT_CONFIG(lineedit)
3623 if ((opt->state & State_HasFocus) && !qobject_cast<
const QLineEdit*>(w)) {
3624 int vmargin = pixelMetric(QStyle::PM_FocusFrameVMargin);
3625 int hmargin = pixelMetric(QStyle::PM_FocusFrameHMargin);
3626 QStyleOptionFrame focusFrame = *panel;
3627 focusFrame.rect = panel->rect.adjusted(-hmargin, -vmargin, hmargin, vmargin);
3628 drawControl(CE_FocusFrame, &focusFrame, p, w);
3634 case PE_PanelScrollAreaCorner: {
3635 const QBrush brush(opt->palette.brush(QPalette::Base));
3636 p->fillRect(opt->rect, brush);
3637 p->setPen(QPen(QColor(217, 217, 217)));
3638 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3639 p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
3641 case PE_FrameStatusBarItem:
3643#if QT_CONFIG(tabbar)
3644 case PE_IndicatorTabClose: {
3646 QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget());
3647 const QWidget *closeBtn = w;
3651 tabBar = qobject_cast<QTabBar *>(
const_cast<QWidget*>(w));
3652 closeBtn =
decltype(closeBtn)(property(
"_q_styleSheetRealCloseButton").value<
void *>());
3655 const bool documentMode = tabBar->documentMode();
3656 const QTabBarPrivate *tabBarPrivate =
static_cast<QTabBarPrivate *>(QObjectPrivate::get(tabBar));
3657 const int hoveredTabIndex = tabBarPrivate->hoveredTabIndex();
3658 if (!documentMode ||
3659 (hoveredTabIndex != -1 && ((closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) ||
3660 (closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide))))) {
3661 const bool hover = (opt->state & State_MouseOver);
3662 const bool selected = (opt->state & State_Selected);
3663 const bool pressed = (opt->state & State_Sunken);
3664 drawTabCloseButton(p, hover, selected, pressed, documentMode);
3669 case PE_PanelStatusBar: {
3670 p->fillRect(opt->rect, opt->palette.window());
3673 if (w ? qt_macWindowMainWindow(w->window()) : (opt->state & QStyle::State_Active))
3674 p->setPen(titlebarSeparatorLineActive);
3676 p->setPen(titlebarSeparatorLineInactive);
3677 p->drawLine(opt->rect.left(), opt->rect.top(), opt->rect.right(), opt->rect.top());
3681 case PE_PanelMenu: {
3683 p->fillRect(opt->rect, Qt::transparent);
3684 p->setPen(Qt::transparent);
3685 p->setBrush(opt->palette.window());
3686 p->setRenderHint(QPainter::Antialiasing,
true);
3687 const QPainterPath path = d->windowPanelPath(opt->rect);
3693 QCommonStyle::drawPrimitive(pe, opt, p, w);
3734 const QWidget *w)
const
3736 Q_D(
const QMacStyle);
3737 const QMacAutoReleasePool pool;
3738 QMacCGContext cg(p);
3740 qCWarning(lcMacStyle) <<
"drawControl:" << ce <<
"invalid (nullptr) graphics context";
3742 QWindow *window = w && w->window() ? w->window()->windowHandle() :
nullptr;
3743 d->resolveCurrentNSView(window);
3745 case CE_HeaderSection:
3746 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
3747 State flags = header->state;
3748 QRect ir = header->rect;
3752 bool noVerticalHeader =
true;
3753#if QT_CONFIG(tableview)
3755 if (
const QTableView *table = qobject_cast<
const QTableView *>(w->parentWidget()))
3756 noVerticalHeader = !table->verticalHeader()->isVisible();
3759 const bool drawLeftBorder = header->orientation == Qt::Vertical
3760 || header->position == QStyleOptionHeader::OnlyOneSection
3761 || (header->position == QStyleOptionHeader::Beginning && noVerticalHeader);
3764 const bool pressed = (flags & State_Sunken) && !(flags & State_On);
3765 p->fillRect(ir, pressed ? header->palette.dark() : header->palette.button());
3766 p->setPen(QPen(header->palette.dark(), 1.0));
3767 if (header->orientation == Qt::Horizontal)
3776 case CE_ToolButtonLabel:
3777 if (
const QStyleOptionToolButton *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
3778 QStyleOptionToolButton myTb = *tb;
3779 myTb.state &= ~State_AutoRaise;
3780#if QT_CONFIG(accessibility)
3781 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) {
3782 QRect cr = tb->rect;
3785 bool needText =
false;
3787 bool down = tb->state & (State_Sunken | State_On);
3789 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, w);
3790 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, tb, w);
3796 if (!(tb->features & QStyleOptionToolButton::Arrow)) {
3797 Qt::ToolButtonStyle tbstyle = tb->toolButtonStyle;
3798 if (tb->icon.isNull() && !tb->text.isEmpty())
3799 tbstyle = Qt::ToolButtonTextOnly;
3802 case Qt::ToolButtonTextOnly: {
3804 alignment = Qt::AlignCenter;
3806 case Qt::ToolButtonIconOnly:
3807 case Qt::ToolButtonTextBesideIcon:
3808 case Qt::ToolButtonTextUnderIcon: {
3810 QIcon::Mode iconMode = (tb->state & State_Enabled) ? QIcon::Normal
3812 QIcon::State iconState = (tb->state & State_On) ? QIcon::On
3814 QPixmap pixmap = tb->icon.pixmap(tb->rect.size().boundedTo(tb->iconSize), p->device()->devicePixelRatio(),
3815 iconMode, iconState);
3818 if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) {
3820 QSizeF size = pixmap.deviceIndependentSize();
3821 if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
3822 pr.setHeight(size.height() + 6);
3823 cr.adjust(0, pr.bottom(), 0, -3);
3824 alignment |= Qt::AlignCenter;
3826 pr.setWidth(size.width() + 8);
3827 cr.adjust(pr.right(), 0, 0, 0);
3828 alignment |= Qt::AlignLeft | Qt::AlignVCenter;
3831 if (opt->state & State_Sunken) {
3832 pr.translate(shiftX, shiftY);
3833 pixmap = darkenPixmap(pixmap);
3835 proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pixmap);
3843 QPalette pal = tb->palette;
3844 QPalette::ColorRole role = QPalette::NoRole;
3845 if (!proxy()->styleHint(SH_UnderlineShortcut, tb, w))
3846 alignment |= Qt::TextHideMnemonic;
3848 cr.translate(shiftX, shiftY);
3849 if (tbstyle == Qt::ToolButtonTextOnly
3850 || (tbstyle != Qt::ToolButtonTextOnly && !down)) {
3851 QPen pen = p->pen();
3852 QColor light = down || isDarkMode() ? Qt::black : Qt::white;
3853 light.setAlphaF(0.375f);
3855 p->drawText(cr.adjusted(0, 1, 0, 1), alignment, tb->text);
3857 if (down && tbstyle == Qt::ToolButtonTextOnly) {
3858 pal = QApplication::palette(
"QMenu");
3859 pal.setCurrentColorGroup(tb->palette.currentColorGroup());
3860 role = QPalette::HighlightedText;
3863 proxy()->drawItemText(p, cr, alignment, pal,
3864 tb->state & State_Enabled, tb->text, role);
3867 QCommonStyle::drawControl(ce, &myTb, p, w);
3872 QCommonStyle::drawControl(ce, &myTb, p, w);
3876 case CE_ToolBoxTabShape:
3877 QCommonStyle::drawControl(ce, opt, p, w);
3879 case CE_PushButtonBevel:
3880 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
3881 if (!(btn->state & (State_Raised | State_Sunken | State_On)))
3884 if (btn->features & QStyleOptionButton::CommandLinkButton) {
3885 QCommonStyle::drawControl(ce, opt, p, w);
3889 const bool hasFocus = btn->state & State_HasFocus;
3890 const bool isActive = btn->state & State_Active;
3894 if ((btn->features & QStyleOptionButton::AutoDefaultButton)
3895 && isActive && hasFocus)
3896 d->autoDefaultButton = btn->styleObject;
3897 else if (d->autoDefaultButton == btn->styleObject)
3898 d->autoDefaultButton =
nullptr;
3900 const bool isEnabled = btn->state & State_Enabled;
3901 const bool isPressed = btn->state & State_Sunken;
3902 const bool isHighlighted = isActive &&
3903 ((btn->state & State_On)
3904 || (btn->features & QStyleOptionButton::DefaultButton)
3905 || (btn->features & QStyleOptionButton::AutoDefaultButton
3906 && d->autoDefaultButton == btn->styleObject));
3907 const bool hasMenu = btn->features & QStyleOptionButton::HasMenu;
3908 const auto ct = cocoaControlType(btn, w);
3909 const auto cs = d->effectiveAquaSizeConstrain(btn, w);
3910 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
3911 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
3915 const QRectF frameRect = cw.adjustedControlFrame(btn->rect);
3916 pb.frame = frameRect.toCGRect();
3918 pb.enabled = isEnabled;
3923 [pb highlight:isPressed];
3926 if (cw.type == QMacStylePrivate::Button_SquareButton) {
3927 pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff;
3931 pb.keyEquivalent = isHighlighted ? @
"\r" : @
"";
3934 d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
3935 [pb.cell drawBezelWithFrame:r inView:pb.superview];
3939 if (hasMenu && cw.type == QMacStylePrivate::Button_SquareButton) {
3942 const int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w);
3943 const auto ir = frameRect.toRect();
3944 int arrowYOffset = 0;
3949 arrowYOffset -= ir.top();
3950 if (cw.second == QStyleHelper::SizeSmall)
3954 const auto ar = visualRect(btn->direction, ir, QRect(ir.right() - mbi - 6, ir.height() / 2 - arrowYOffset, mbi, mbi));
3956 QStyleOption arrowOpt = *opt;
3958 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, w);
3962 case CE_PushButtonLabel:
3963 if (
const QStyleOptionButton *b = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
3964 QStyleOptionButton btn(*b);
3969 const bool isEnabled = btn.state & State_Enabled;
3970 const bool hasMenu = btn.features & QStyleOptionButton::HasMenu;
3971 const bool hasIcon = !btn.icon.isNull();
3972 const bool hasText = !btn.text.isEmpty();
3973 const bool isActive = btn.state & State_Active;
3974 const bool isPressed = btn.state & State_Sunken;
3975 const bool isDefault = (btn.features & QStyleOptionButton::DefaultButton && !d->autoDefaultButton)
3976 || d->autoDefaultButton == btn.styleObject;
3980 const QRect oldRect = btn.rect;
3982 btn.rect = w->rect();
3983 const auto ct = cocoaControlType(&btn, w);
3986 if (!hasMenu && ct != QMacStylePrivate::Button_SquareButton) {
3987 if (isPressed || (isActive && isEnabled && ((btn.state & State_On) || isDefault)))
3988 btn.palette.setColor(QPalette::ButtonText, Qt::white);
3992 if (!isDefault && !(btn.state & State_On)) {
3995 btn.palette.setColor(QPalette::ButtonText, Qt::black);
3999 if ((!hasIcon && !hasMenu) || (hasIcon && !hasText)) {
4000 QCommonStyle::drawControl(ce, &btn, p, w);
4002 QRect freeContentRect = btn.rect;
4003 QRect textRect = itemTextRect(
4004 btn.fontMetrics, freeContentRect, Qt::AlignCenter, isEnabled, btn.text);
4006 if (ct == QMacStylePrivate::Button_SquareButton)
4007 textRect.moveTo(w ? 8 : 11, textRect.top());
4009 textRect.moveTo(w ? (15 - pushButtonBevelRectOffsets[d->effectiveAquaSizeConstrain(b, w)])
4010 : 11, textRect.top());
4014 int contentW = textRect.width();
4016 contentW += proxy()->pixelMetric(PM_MenuButtonIndicator) + 4;
4017 QIcon::Mode mode = isEnabled ? QIcon::Normal : QIcon::Disabled;
4018 if (mode == QIcon::Normal && btn.state & State_HasFocus)
4019 mode = QIcon::Active;
4021 QIcon::State state = QIcon::Off;
4022 if (btn.state & State_On)
4024 QPixmap pixmap = btn.icon.pixmap(btn.iconSize, p->device()->devicePixelRatio(), mode, state);
4025 QSizeF pixmapSize = pixmap.deviceIndependentSize();
4026 contentW += pixmapSize.width() + QMacStylePrivate::PushButtonContentPadding;
4027 int iconLeftOffset = freeContentRect.x() + (freeContentRect.width() - contentW) / 2;
4028 int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmapSize.height()) / 2;
4029 QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmapSize.width(), pixmapSize.height());
4030 QRect visualIconDestRect = visualRect(btn.direction, freeContentRect, iconDestRect);
4031 proxy()->drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap);
4032 int newOffset = iconDestRect.x() + iconDestRect.width()
4033 + QMacStylePrivate::PushButtonContentPadding - textRect.x();
4034 textRect.adjust(newOffset, 0, newOffset, 0);
4038 textRect = visualRect(btn.direction, freeContentRect, textRect);
4039 proxy()->drawItemText(p, textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, btn.palette,
4040 isEnabled, btn.text, QPalette::ButtonText);
4045#if QT_CONFIG(combobox)
4046 case CE_ComboBoxLabel:
4047 if (
const auto *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
4048 auto comboCopy = *cb;
4049 comboCopy.direction = Qt::LeftToRight;
4051 QCommonStyle::drawControl(CE_ComboBoxLabel, &comboCopy, p, w);
4055#if QT_CONFIG(tabbar)
4056 case CE_TabBarTabShape:
4057 if (
const auto *tabOpt = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
4058 if (tabOpt->documentMode) {
4060 bool isUnified =
false;
4062 QRect tabRect = tabOpt->rect;
4063 QPoint windowTabStart = w->mapTo(w->window(), tabRect.topLeft());
4064 isUnified = isInMacUnifiedToolbarArea(w->window(), windowTabStart.y());
4067 const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, opt, w);
4068 drawTabShape(p, tabOpt, isUnified, tabOverlap);
4097 const bool isActive = tabOpt->state & State_Active;
4098 const bool isEnabled = tabOpt->state & State_Enabled;
4099 const bool isPressed = tabOpt->state & State_Sunken;
4100 const bool isSelected = tabOpt->state & State_Selected;
4101 const auto tabDirection = QMacStylePrivate::tabDirection(tabOpt->shape);
4102 const bool verticalTabs = tabDirection == QMacStylePrivate::East
4103 || tabDirection == QMacStylePrivate::West;
4105 QStyleOptionTab::TabPosition tp = tabOpt->position;
4106 QStyleOptionTab::SelectedPosition sp = tabOpt->selectedPosition;
4107 if (tabOpt->direction == Qt::RightToLeft && !verticalTabs) {
4108 if (tp == QStyleOptionTab::Beginning)
4109 tp = QStyleOptionTab::End;
4110 else if (tp == QStyleOptionTab::End)
4111 tp = QStyleOptionTab::Beginning;
4113 if (sp == QStyleOptionTab::NextIsSelected)
4114 sp = QStyleOptionTab::PreviousIsSelected;
4115 else if (sp == QStyleOptionTab::PreviousIsSelected)
4116 sp = QStyleOptionTab::NextIsSelected;
4125 const auto cs = d->effectiveAquaSizeConstrain(opt, w);
4127 const bool needsInactiveHack = !isActive && isSelected;
4128 const auto ct = !needsInactiveHack && (isSelected || tp == QStyleOptionTab::OnlyOneTab) ?
4129 QMacStylePrivate::Button_PushButton :
4130 QMacStylePrivate::Button_PopupButton;
4131 const bool isPopupButton = ct == QMacStylePrivate::Button_PopupButton;
4132 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
4133 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
4136 if (tabDirection == QMacStylePrivate::East)
4138 const auto outerAdjust = isPopupButton ? 1 : 4;
4139 const auto innerAdjust = isPopupButton ? 20 : 10;
4140 QRectF frameRect = tabOpt->rect;
4142 frameRect = QRectF(frameRect.y(), frameRect.x(), frameRect.height(), frameRect.width());
4144 frameRect = frameRect.translated(0, vOffset);
4146 case QStyleOptionTab::Beginning:
4148 if (!isSelected && tabDirection == QMacStylePrivate::West)
4149 frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0);
4151 frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0);
4156 frameRect = frameRect.adjusted(0, 0, 1, 0);
4159 case QStyleOptionTab::Middle:
4160 frameRect = frameRect.adjusted(-innerAdjust, 0, innerAdjust, 0);
4165 frameRect = frameRect.adjusted(-1, 0, 1, 0);
4168 case QStyleOptionTab::Moving:
4169 case QStyleOptionTab::End:
4171 if (isSelected || tabDirection == QMacStylePrivate::West)
4172 frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0);
4174 frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0);
4178 frameRect = frameRect.adjusted(-1, 0, 0, 0);
4181 case QStyleOptionTab::OnlyOneTab:
4182 frameRect = frameRect.adjusted(-outerAdjust, 0, outerAdjust, 0);
4185 pb.frame = frameRect.toCGRect();
4187 if (!isPopupButton) {
4191 pb.buttonType = NSButtonTypePushOnPushOff;
4194 pb.enabled = isEnabled;
4195 [pb highlight:isPressed];
4197 pb.state = (isActive && isSelected) ? NSControlStateValueOn : NSControlStateValueOff;
4199 const auto drawBezelBlock = ^(CGContextRef ctx,
const CGRect &r) {
4200 CGContextClipToRect(ctx, opt->rect.toCGRect());
4201 if (!isSelected || needsInactiveHack) {
4203 if (!verticalTabs && tp == QStyleOptionTab::End) {
4204 CGContextTranslateCTM(ctx, opt->rect.right(), 0);
4205 CGContextScaleCTM(ctx, -1, 1);
4206 CGContextTranslateCTM(ctx, -frameRect.left(), 0);
4207 }
else if (tabDirection == QMacStylePrivate::West && tp == QStyleOptionTab::Beginning) {
4208 CGContextTranslateCTM(ctx, 0, opt->rect.top());
4209 CGContextScaleCTM(ctx, 1, -1);
4210 CGContextTranslateCTM(ctx, 0, -frameRect.right());
4211 }
else if (tabDirection == QMacStylePrivate::East && tp == QStyleOptionTab::End) {
4212 CGContextTranslateCTM(ctx, 0, opt->rect.bottom());
4213 CGContextScaleCTM(ctx, 1, -1);
4214 CGContextTranslateCTM(ctx, 0, -frameRect.left());
4220 if (tabDirection == QMacStylePrivate::West) {
4221 CGContextTranslateCTM(ctx, 0, frameRect.right());
4222 CGContextRotateCTM(ctx, -M_PI_2);
4223 CGContextTranslateCTM(ctx, -frameRect.left(), 0);
4224 }
else if (tabDirection == QMacStylePrivate::East) {
4225 CGContextTranslateCTM(ctx, opt->rect.right(), 0);
4226 CGContextRotateCTM(ctx, M_PI_2);
4231 NSPopUpArrowPosition oldPosition = NSPopUpArrowAtCenter;
4232 NSPopUpButtonCell *pbCell = nil;
4234 if (isPopupButton) {
4238 pbCell =
static_cast<NSPopUpButtonCell *>(pb.cell);
4239 oldPosition = pbCell.arrowPosition;
4240 pbCell.arrowPosition = NSPopUpNoArrow;
4241 if (pb.state == NSControlStateValueOff) {
4243 rAdjusted.origin.x -= 3;
4244 rAdjusted.size.width += 6;
4245 if (tp == QStyleOptionTab::End)
4246 rAdjusted.origin.x -= 2;
4249 if (qt_apple_runningWithLiquidGlass()) {
4258 const CGFloat deltaW = 20.0;
4259 rAdjusted = CGContextGetClipBoundingBox(ctx);
4260 if (tp == QStyleOptionTab::Beginning) {
4265 rAdjusted.size.width += deltaW;
4267 if (tabDirection == QMacStylePrivate::West && isSelected && isActive) {
4271 rAdjusted.origin.x -= deltaW;
4273 }
else if (tp == QStyleOptionTab::Middle) {
4275 rAdjusted.origin.x -= deltaW;
4276 rAdjusted.size.width += deltaW * 2;
4277 }
else if (tp == QStyleOptionTab::End) {
4278 if (isSelected && isActive && tabDirection != QMacStylePrivate::West)
4279 rAdjusted.origin.x -= deltaW;
4280 rAdjusted.size.width += deltaW;
4284 [pb.cell drawBezelWithFrame:rAdjusted inView:pb.superview];
4287 pbCell.arrowPosition = oldPosition;
4290 if (needsInactiveHack) {
4292 const qreal pixelRatio = p->device()->devicePixelRatio();
4293 QImage tabPixmap(opt->rect.size() * pixelRatio, QImage::Format_ARGB32_Premultiplied);
4294 tabPixmap.setDevicePixelRatio(pixelRatio);
4295 tabPixmap.fill(Qt::transparent);
4296 QPainter tabPainter(&tabPixmap);
4297 d->drawNSViewInRect(pb, frameRect, &tabPainter, ^(CGContextRef ctx,
const CGRect &r) {
4298 CGContextTranslateCTM(ctx, -opt->rect.left(), -opt->rect.top());
4299 drawBezelBlock(ctx, r);
4304 const qreal inactiveGray = 0.898;
4305 const int inactiveGray8 = qRound(inactiveGray * 255.0);
4306 const QRgb inactiveGrayRGB = qRgb(inactiveGray8, inactiveGray8, inactiveGray8);
4307 for (
int l = 0; l < tabPixmap.height(); ++l) {
4308 auto *line =
reinterpret_cast<QRgb*>(tabPixmap.scanLine(l));
4309 for (
int i = 0; i < tabPixmap.width(); ++i) {
4310 if (qAlpha(line[i]) == 255) {
4311 line[i] = inactiveGrayRGB;
4312 }
else if (qAlpha(line[i]) > 128) {
4313 const int g = qRound(inactiveGray * qRed(line[i]));
4314 line[i] = qRgba(g, g, g, qAlpha(line[i]));
4320 p->drawImage(opt->rect, tabPixmap);
4322 d->drawNSViewInRect(pb, frameRect, p, drawBezelBlock);
4325 if (!isSelected && sp != QStyleOptionTab::NextIsSelected
4326 && tp != QStyleOptionTab::End
4327 && tp != QStyleOptionTab::OnlyOneTab) {
4328 static const QPen separatorPen(Qt::black, 1.0);
4330 p->setOpacity(isEnabled ? 0.105 : 0.06);
4331 p->setPen(separatorPen);
4332 if (tabDirection == QMacStylePrivate::West) {
4333 p->drawLine(QLineF(opt->rect.left() + 1.5, opt->rect.bottom(),
4334 opt->rect.right() - 0.5, opt->rect.bottom()));
4335 }
else if (tabDirection == QMacStylePrivate::East) {
4336 p->drawLine(QLineF(opt->rect.left(), opt->rect.bottom(),
4337 opt->rect.right() - 0.5, opt->rect.bottom()));
4339 p->drawLine(QLineF(opt->rect.right(), opt->rect.top() + 1.0,
4340 opt->rect.right(), opt->rect.bottom() - 0.5));
4346 case CE_TabBarTabLabel:
4347 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
4348 QStyleOptionTab myTab = *tab;
4349 const auto foregroundRole = w ? w->foregroundRole() : QPalette::WindowText;
4350 const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape);
4351 const bool verticalTabs = tabDirection == QMacStylePrivate::East
4352 || tabDirection == QMacStylePrivate::West;
4358 const bool nonDefaultFont = p->font() != qt_app_fonts_hash()->value(
"QComboMenuItem");
4360 if (!myTab.documentMode && (myTab.state & State_Selected) && (myTab.state & State_Active))
4361 if (
const auto *tabBar = qobject_cast<
const QTabBar *>(w))
4362 if (!tabBar->tabTextColor(tabBar->currentIndex()).isValid())
4363 myTab.palette.setColor(foregroundRole, Qt::white);
4365 if (myTab.documentMode && isDarkMode()) {
4366 if (
const auto *tabBar = qobject_cast<
const QTabBar *>(w)) {
4367 if (!tabBar->tabTextColor(myTab.tabIndex).isValid()) {
4368 bool active = (myTab.state & State_Selected) && (myTab.state & State_Active);
4369 myTab.palette.setColor(foregroundRole, active ? Qt::white : Qt::gray);
4374 int heightOffset = 0;
4377 }
else if (nonDefaultFont) {
4378 if (p->fontMetrics().height() == myTab.rect.height())
4381 myTab.rect.setHeight(myTab.rect.height() + heightOffset);
4383 QCommonStyle::drawControl(ce, &myTab, p, w);
4387#if QT_CONFIG(dockwidget)
4388 case CE_DockWidgetTitle:
4389 if (
const auto *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(opt)) {
4390 const bool isVertical = dwOpt->verticalTitleBar;
4391 const auto effectiveRect = isVertical ? opt->rect.transposed() : opt->rect;
4394 p->translate(effectiveRect.left(), effectiveRect.top() + effectiveRect.width());
4396 p->translate(-effectiveRect.left(), -effectiveRect.top());
4400 p->fillRect(effectiveRect, opt->palette.window());
4403 p->setPen(opt->palette.dark().color());
4404 p->drawLine(effectiveRect.bottomLeft(), effectiveRect.bottomRight());
4406 if (!dwOpt->title.isEmpty()) {
4407 auto titleRect = proxy()->subElementRect(SE_DockWidgetTitleBarText, opt, w);
4409 titleRect = QRect(effectiveRect.left() + opt->rect.bottom() - titleRect.bottom(),
4410 effectiveRect.top() + titleRect.left() - opt->rect.left(),
4414 const auto text = p->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
4415 proxy()->drawItemText(p, titleRect, Qt::AlignCenter | Qt::TextHideMnemonic, dwOpt->palette,
4416 dwOpt->state & State_Enabled, text, QPalette::WindowText);
4422 case CE_FocusFrame: {
4423 const auto *ff = qobject_cast<
const QFocusFrame *>(w);
4424 const auto *ffw = ff ? ff->widget() :
nullptr;
4425 const auto ct = [=] {
4427 if (qobject_cast<
const QCheckBox*>(ffw))
4428 return QMacStylePrivate::Button_CheckBox;
4429 if (qobject_cast<
const QRadioButton*>(ffw))
4430 return QMacStylePrivate::Button_RadioButton;
4431 if (qobject_cast<
const QLineEdit*>(ffw) || qobject_cast<
const QTextEdit*>(ffw))
4432 return QMacStylePrivate::TextField;
4433 if (
const auto *pb = qobject_cast<
const QPushButton *>(ffw)) {
4435 auto sizePolicy = QStyleHelper::widgetSizePolicy(ffw, opt);
4436 if (sizePolicy == QStyleHelper::SizeDefault)
4437 sizePolicy = QStyleHelper::SizeLarge;
4439 || (pb->rect().height() != pushButtonDefaultHeight[sizePolicy])) {
4440 return QMacStylePrivate::Button_SquareButton;
4442 if (pb->menu() !=
nullptr)
4443 return QMacStylePrivate::Button_PullDown;
4444 return QMacStylePrivate::Button_PushButton;
4448 return QMacStylePrivate::Box;
4450 auto cs = QStyleHelper::widgetSizePolicy(ffw, opt);
4451 if (cs == QStyleHelper::SizeDefault)
4452 cs = QStyleHelper::SizeLarge;
4453 const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, w);
4454 const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, opt, w);
4455 d->drawFocusRing(p, opt->rect, hMargin, vMargin, QMacStylePrivate::CocoaControl(ct, cs));
4457 case CE_MenuEmptyArea:
4459 if (qobject_cast<
const QAbstractItemView *>(w))
4460 proxy()->drawPrimitive(PE_PanelMenu, opt, p, w);
4464 case CE_MenuHMargin:
4465 case CE_MenuVMargin:
4466 case CE_MenuTearoff:
4467 case CE_MenuScroller:
4468 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
4469 const bool active = mi->state & State_Selected;
4471 p->fillRect(mi->rect, mi->palette.highlight());
4473 const QStyleHelper::WidgetSizePolicy widgetSize = d->aquaSizeConstrain(opt, w);
4475 if (ce == CE_MenuTearoff) {
4476 p->setPen(QPen(mi->palette.dark().color(), 1, Qt::DashLine));
4477 p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2 - 1,
4478 mi->rect.x() + mi->rect.width() - 4,
4479 mi->rect.y() + mi->rect.height() / 2 - 1);
4480 p->setPen(QPen(mi->palette.light().color(), 1, Qt::DashLine));
4481 p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2,
4482 mi->rect.x() + mi->rect.width() - 4,
4483 mi->rect.y() + mi->rect.height() / 2);
4484 }
else if (ce == CE_MenuScroller) {
4485 const QSize scrollerSize = QSize(10, 8);
4486 const int scrollerVOffset = 5;
4487 const int left = mi->rect.x() + (mi->rect.width() - scrollerSize.width()) / 2;
4488 const int right = left + scrollerSize.width();
4491 if (opt->state & State_DownArrow) {
4492 bottom = mi->rect.y() + scrollerVOffset;
4493 top = bottom + scrollerSize.height();
4495 bottom = mi->rect.bottom() - scrollerVOffset;
4496 top = bottom - scrollerSize.height();
4499 p->setRenderHint(QPainter::Antialiasing);
4501 path.moveTo(left, bottom);
4502 path.lineTo(right, bottom);
4503 path.lineTo((left + right) / 2, top);
4504 p->fillPath(path, opt->palette.buttonText());
4506 }
else if (ce != CE_MenuItem) {
4510 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
4511 CGColorRef separatorColor = [NSColor quaternaryLabelColor].CGColor;
4512 const QRect separatorRect = QRect(mi->rect.left(), mi->rect.center().y(), mi->rect.width(), 2);
4513 p->fillRect(separatorRect, qt_mac_toQColor(separatorColor));
4517 const int maxpmw = mi->maxIconWidth;
4518 const bool enabled = mi->state & State_Enabled;
4520 int xpos = mi->rect.x() + 18;
4521 int checkcol = maxpmw;
4523 p->setPen(mi->palette.text().color());
4525 p->setPen(mi->palette.highlightedText().color());
4527 p->setPen(mi->palette.buttonText().color());
4530 QStyleOption checkmarkOpt;
4531 checkmarkOpt.initFrom(w);
4536 checkmarkOpt.rect = QRect(xp, mi->rect.y() - checkmarkOpt.fontMetrics.descent(), mw, mh);
4538 checkmarkOpt.state.setFlag(State_On, active);
4539 checkmarkOpt.state.setFlag(State_Enabled, enabled);
4540 if (widgetSize == QStyleHelper::SizeMini)
4541 checkmarkOpt.state |= State_Mini;
4542 else if (widgetSize == QStyleHelper::SizeSmall)
4543 checkmarkOpt.state |= State_Small;
4546 checkmarkOpt.palette.setColor(QPalette::HighlightedText, p->pen().color());
4547 checkmarkOpt.palette.setColor(QPalette::Text, p->pen().color());
4549 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &checkmarkOpt, p, w);
4551 if (!mi->icon.isNull()) {
4552 QIcon::Mode mode = (mi->state & State_Enabled) ? QIcon::Normal
4555 int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize);
4556 QSize iconSize(smallIconSize, smallIconSize);
4557#if QT_CONFIG(combobox)
4558 if (
const QComboBox *comboBox = qobject_cast<
const QComboBox *>(w)) {
4559 iconSize = comboBox->iconSize();
4562 QPixmap pixmap = mi->icon.pixmap(iconSize, p->device()->devicePixelRatio(), mode);
4563 QRect cr(xpos, mi->rect.y(), checkcol, mi->rect.height());
4564 QSize size = pixmap.deviceIndependentSize().toSize();
4565 QRect pmr(QPoint(0, 0), size);
4566 pmr.moveCenter(cr.center());
4567 p->drawPixmap(pmr.topLeft(), pixmap);
4568 xpos += size.width() + 6;
4571 QString s = mi->text;
4572 const auto text_flags = Qt::AlignVCenter | Qt::TextHideMnemonic
4573 | Qt::TextSingleLine | Qt::AlignAbsolute;
4574 int yPos = mi->rect.y();
4575 if (widgetSize == QStyleHelper::SizeMini)
4578 const bool isSubMenu = mi->menuItemType == QStyleOptionMenuItem::SubMenu;
4579 const int tabwidth = isSubMenu ? 9 : mi->reservedShortcutWidth;
4581 QString rightMarginText;
4583 rightMarginText = QStringLiteral(
"\u25b6\ufe0e");
4586 const int tabIndex = s.indexOf(QLatin1Char(
'\t'));
4587 if (tabIndex >= 0) {
4589 rightMarginText = s.mid(tabIndex + 1);
4590 s = s.left(tabIndex);
4594 if (!rightMarginText.isEmpty()) {
4595 p->setFont(qt_app_fonts_hash()->value(
"QMenuItem", p->font()));
4598 p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags | Qt::AlignRight, rightMarginText);
4602 const QKeySequence seq = QKeySequence::fromString(rightMarginText, QKeySequence::NativeText);
4603 if (seq.count() == 1) {
4605 const int maxKeyWidth = p->fontMetrics().maxWidth();
4606 const QChar key = rightMarginText.at(rightMarginText.length() - 1);
4607 const QString modifiers = rightMarginText.left(rightMarginText.size() - 1);
4608 p->drawText(xp + tabwidth - maxKeyWidth, yPos, maxKeyWidth, mi->rect.height(), text_flags, key);
4610 p->drawText(xp, yPos, tabwidth - maxKeyWidth, mi->rect.height(),
4611 text_flags | Qt::AlignRight | Qt::TextDontClip, modifiers);
4613 p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags, rightMarginText);
4620 QFont myFont = mi->font;
4626 myFont.setPointSizeF(QFontInfo(mi->font).pointSizeF());
4631 const auto *fontEngine = QFontPrivate::get(myFont)->engineForScript(QChar::Script_Common);
4632 Q_ASSERT(fontEngine);
4633 if (fontEngine->type() == QFontEngine::Multi) {
4634 fontEngine =
static_cast<
const QFontEngineMulti *>(fontEngine)->engine(0);
4635 Q_ASSERT(fontEngine);
4637 if (fontEngine->type() == QFontEngine::Mac) {
4638 NSFont *f = (NSFont *)(CTFontRef)fontEngine->handle();
4641 const auto pc = p->pen().color();
4642 NSColor *c = [NSColor colorWithSRGBRed:pc.redF()
4647 s = qt_mac_removeMnemonics(s);
4649 QMacCGContext cgCtx(p);
4650 d->setupNSGraphicsContext(cgCtx, YES);
4656 [s.toNSString() drawAtPoint:CGPointMake(xpos, yPos)
4657 withAttributes:@{ NSFontAttributeName:f, NSForegroundColorAttributeName:c,
4658 NSObliquenessAttributeName: [NSNumber numberWithDouble: myFont.italic() ? 0.3 : 0.0],
4659 NSUnderlineStyleAttributeName: [NSNumber numberWithInt: myFont.underline() ? NSUnderlineStyleSingle
4660 : NSUnderlineStyleNone],
4661 NSStrikethroughStyleAttributeName: [NSNumber numberWithInt: myFont.strikeOut() ? NSUnderlineStyleSingle
4662 : NSUnderlineStyleNone]}];
4664 d->restoreNSGraphicsContext(cgCtx);
4667 p->drawText(xpos, yPos, mi->rect.width() - xm - tabwidth + 1,
4668 mi->rect.height(), text_flags, s);
4674 case CE_MenuBarItem:
4675 case CE_MenuBarEmptyArea:
4676 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
4677 const bool selected = (opt->state & State_Selected) && (opt->state & State_Enabled) && (opt->state & State_Sunken);
4678 const QBrush bg = selected ? mi->palette.highlight() : mi->palette.window();
4679 p->fillRect(mi->rect, bg);
4681 if (ce != CE_MenuBarItem)
4684 if (!mi->icon.isNull()) {
4685 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
4686 drawItemPixmap(p, mi->rect,
4687 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip
4688 | Qt::TextSingleLine,
4689 mi->icon.pixmap(QSize(iconExtent, iconExtent), p->device()->devicePixelRatio(),
4690 (mi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled));
4692 drawItemText(p, mi->rect,
4693 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip
4694 | Qt::TextSingleLine,
4695 mi->palette, mi->state & State_Enabled,
4696 mi->text, selected ? QPalette::HighlightedText : QPalette::ButtonText);
4700 case CE_ProgressBarLabel:
4701 case CE_ProgressBarGroove:
4704 case CE_ProgressBarContents:
4705 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
4706 const bool isIndeterminate = (pb->minimum == 0 && pb->maximum == 0);
4707 const bool vertical = !(pb->state & QStyle::State_Horizontal);
4708 const bool inverted = pb->invertedAppearance;
4709 bool reverse = (!vertical && (pb->direction == Qt::RightToLeft));
4712 QRect rect = pb->rect;
4714 const auto aquaSize = d->effectiveAquaSizeConstrain(opt, w);
4715 const QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject));
4716 if (isIndeterminate) {
4724 if (!animation && opt->styleObject) {
4725 auto *animation =
new QProgressStyleAnimation(d->animateSpeed(QMacStylePrivate::AquaProgressBar), opt->styleObject);
4727 animation->setFrameRate(QStyleAnimation::FifteenFps);
4728 d->startAnimation(animation);
4731 if (qt_apple_runningWithLiquidGlass()) {
4732 d->drawProgressBar(p, pb);
4735 rect = rect.transposed();
4736 d->setupNSGraphicsContext(cg, NO);
4737 d->setupVerticalInvertedXform(cg, reverse, vertical, rect.toCGRect());
4739 =
static_cast<QIndeterminateProgressIndicator *>(
4740 d->cocoaControl({ QMacStylePrivate::ProgressIndicator_Indeterminate, aquaSize }))) {
4741 [ipi startAnimation];
4742 [ipi drawWithFrame:rect.toCGRect() inView:d->backingStoreNSView];
4744 d->restoreNSGraphicsContext(cg);
4748 d->stopAnimation(opt->styleObject);
4750 =
static_cast<QIndeterminateProgressIndicator *>(
4751 d->cocoaControl({ QMacStylePrivate::ProgressIndicator_Indeterminate, aquaSize })))
4752 [ipi stopAnimation];
4754 if (qt_apple_runningWithLiquidGlass()) {
4755 d->drawProgressBar(p, pb);
4758 rect = rect.transposed();
4759 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::ProgressIndicator_Determinate, aquaSize);
4760 auto *pi =
static_cast<NSProgressIndicator *>(d->cocoaControl(cw));
4761 d->drawNSViewInRect(pi, rect, p, ^(CGContextRef ctx,
const CGRect &cgrect) {
4762 d->setupVerticalInvertedXform(ctx, reverse, vertical, cgrect);
4763 pi.minValue = pb->minimum;
4764 pi.maxValue = pb->maximum;
4765 pi.doubleValue = pb->progress;
4766 [pi drawRect:cgrect]; });
4773#ifndef QT_NO_MDIAREA
4774 if (!w || !qobject_cast<QMdiSubWindow *>(w->parentWidget()))
4778 if (w->testAttribute(Qt::WA_MacOpaqueSizeGrip))
4779 p->fillRect(opt->rect, opt->palette.window());
4781 QPen lineColor = QColor(82, 82, 82, 192);
4782 lineColor.setWidth(1);
4784 p->setRenderHint(QPainter::Antialiasing);
4785 p->setPen(lineColor);
4786 const Qt::LayoutDirection layoutDirection = w ? w->layoutDirection() : qApp->layoutDirection();
4787 const int NumLines = 3;
4788 for (
int l = 0; l < NumLines; ++l) {
4789 const int offset = (l * 4 + 3);
4791 if (layoutDirection == Qt::LeftToRight) {
4792 start = QPoint(opt->rect.width() - offset, opt->rect.height() - 1);
4793 end = QPoint(opt->rect.width() - 1, opt->rect.height() - offset);
4795 start = QPoint(offset, opt->rect.height() - 1);
4796 end = QPoint(1, opt->rect.height() - offset);
4798 p->drawLine(start, end);
4804 if (opt->rect.width() > 1 && opt->rect.height() > 1) {
4805 const bool isVertical = !(opt->state & QStyle::State_Horizontal);
4807 const auto ct = isVertical ? QMacStylePrivate::SplitView_Horizontal : QMacStylePrivate::SplitView_Vertical;
4808 const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
4809 auto *sv =
static_cast<NSSplitView *>(d->cocoaControl(cw));
4810 sv.frame = opt->rect.toCGRect();
4811 d->drawNSViewInRect(sv, opt->rect, p, ^(CGContextRef,
const CGRect &rect) {
4812 [sv drawDividerInRect:rect];
4815 QPen oldPen = p->pen();
4816 p->setPen(opt->palette.dark().color());
4817 if (opt->state & QStyle::State_Horizontal)
4818 p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
4820 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
4825 if (
const QStyleOptionRubberBand *rubber = qstyleoption_cast<
const QStyleOptionRubberBand *>(opt)) {
4826 QColor fillColor(opt->palette.color(QPalette::Disabled, QPalette::Highlight));
4827 if (!rubber->opaque) {
4830 strokeColor.setHsvF(0, 0, 0.86, 1.0);
4831 fillColor.setHsvF(0, 0, 0.53, 0.25);
4832 if (opt->rect.width() * opt->rect.height() <= 3) {
4833 p->fillRect(opt->rect, strokeColor);
4835 QPen oldPen = p->pen();
4836 QBrush oldBrush = p->brush();
4837 QPen pen(strokeColor);
4839 p->setBrush(fillColor);
4840 QRect adjusted = opt->rect.adjusted(1, 1, -1, -1);
4841 if (adjusted.isValid())
4842 p->drawRect(adjusted);
4844 p->setBrush(oldBrush);
4847 p->fillRect(opt->rect, fillColor);
4851#ifndef QT_NO_TOOLBAR
4853 const QStyleOptionToolBar *toolBar = qstyleoption_cast<
const QStyleOptionToolBar *>(opt);
4855 const QColor separatorColor = darkMode ? darkModeSeparatorLine : opt->palette.dark().color();
4862#if QT_CONFIG(mainwindow)
4863 if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) {
4864 if (toolBar && toolBar->toolBarArea == Qt::TopToolBarArea && mainWindow->unifiedTitleAndToolBarOnMac()) {
4867 p->setCompositionMode(QPainter::CompositionMode_Source);
4868 p->fillRect(opt->rect, Qt::transparent);
4875 const QPoint windowToolbarEnd = w->mapTo(w->window(), opt->rect.bottomLeft());
4876 const bool isEndOfUnifiedArea = !isInMacUnifiedToolbarArea(w->window(), windowToolbarEnd.y() + 1);
4877 if (isEndOfUnifiedArea) {
4878 const int margin = qt_mac_aqua_get_metric(SeparatorSize);
4879 const auto separatorRect = QRect(opt->rect.left(), opt->rect.bottom(), opt->rect.width(), margin);
4880 p->fillRect(separatorRect, separatorColor);
4888 p->fillRect(opt->rect, opt->palette.window());
4891 p->setPen(separatorColor);
4892 QRect toolbarRect = darkMode ? opt->rect.adjusted(0, 0, 0, 1) : opt->rect;
4893 if (opt->state & State_Horizontal) {
4894 p->drawLine(toolbarRect.topLeft(), toolbarRect.topRight());
4895 p->drawLine(toolbarRect.bottomLeft(), toolbarRect.bottomRight());
4897 p->drawLine(toolbarRect.topLeft(), toolbarRect.bottomLeft());
4898 p->drawLine(toolbarRect.topRight(), toolbarRect.bottomRight());
4906 QCommonStyle::drawControl(ce, opt, p, w);
4921 const QWidget *widget)
const
4923 Q_D(
const QMacStyle);
4925 const int controlSize = getControlSize(opt, widget);
4928#if QT_CONFIG(itemviews)
4929 case SE_ItemViewItemText:
4930 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
4931 int fw = proxy()->pixelMetric(PM_FocusFrameHMargin, opt, widget);
4933 rect = QCommonStyle::subElementRect(sr, opt, widget);
4934 if (vopt->features & QStyleOptionViewItem::HasDecoration)
4935 rect.adjust(-fw, 0, 0, 0);
4939 case SE_ToolBoxTabContents:
4940 rect = QCommonStyle::subElementRect(sr, opt, widget);
4942 case SE_PushButtonBevel:
4943 case SE_PushButtonContents:
4944 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
4953 const auto ct = cocoaControlType(btn, widget);
4954 const auto cs = d->effectiveAquaSizeConstrain(btn, widget);
4955 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
4956 auto frameRect = cw.adjustedControlFrame(btn->rect);
4957 if (sr == SE_PushButtonContents) {
4958 frameRect -= cw.titleMargins();
4959 }
else if (cw.type != QMacStylePrivate::Button_SquareButton) {
4960 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
4961 frameRect = QRectF::fromCGRect([pb alignmentRectForFrame:frameRect.toCGRect()]);
4962 if (cw.type == QMacStylePrivate::Button_PushButton)
4963 frameRect -= pushButtonShadowMargins[cw.size];
4964 else if (cw.type == QMacStylePrivate::Button_PullDown)
4965 frameRect -= pullDownButtonShadowMargins[cw.size];
4967 rect = frameRect.toRect();
4970 case SE_HeaderLabel: {
4971 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
4972 rect.setRect(opt->rect.x() + margin, opt->rect.y(),
4973 opt->rect.width() - margin * 2, opt->rect.height() - 2);
4974 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
4976 if (header->sortIndicator != QStyleOptionHeader::None) {
4977 if (opt->state & State_Horizontal)
4983 rect = visualRect(opt->direction, opt->rect, rect);
4986 case SE_HeaderArrow: {
4987 int h = opt->rect.height();
4988 int w = opt->rect.width();
4989 int x = opt->rect.x();
4990 int y = opt->rect.y();
4991 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
4993 if (opt->state & State_Horizontal) {
5000 rect = visualRect(opt->direction, opt->rect, rect);
5003 case SE_ProgressBarGroove:
5007 case SE_ProgressBarLabel:
5009 case SE_ProgressBarContents:
5012 case SE_TreeViewDisclosureItem: {
5018#if QT_CONFIG(tabwidget)
5019 case SE_TabWidgetLeftCorner:
5020 if (
const QStyleOptionTabWidgetFrame *twf
5021 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5022 switch (twf->shape) {
5023 case QTabBar::RoundedNorth:
5024 case QTabBar::TriangularNorth:
5025 rect = QRect(QPoint(0, 0), twf->leftCornerWidgetSize);
5027 case QTabBar::RoundedSouth:
5028 case QTabBar::TriangularSouth:
5029 rect = QRect(QPoint(0, twf->rect.height() - twf->leftCornerWidgetSize.height()),
5030 twf->leftCornerWidgetSize);
5035 rect = visualRect(twf->direction, twf->rect, rect);
5038 case SE_TabWidgetRightCorner:
5039 if (
const QStyleOptionTabWidgetFrame *twf
5040 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5041 switch (twf->shape) {
5042 case QTabBar::RoundedNorth:
5043 case QTabBar::TriangularNorth:
5044 rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(), 0),
5045 twf->rightCornerWidgetSize);
5047 case QTabBar::RoundedSouth:
5048 case QTabBar::TriangularSouth:
5049 rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(),
5050 twf->rect.height() - twf->rightCornerWidgetSize.height()),
5051 twf->rightCornerWidgetSize);
5056 rect = visualRect(twf->direction, twf->rect, rect);
5059 case SE_TabWidgetTabContents:
5060 rect = QCommonStyle::subElementRect(sr, opt, widget);
5061 if (
const auto *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5062 if (twf->lineWidth != 0) {
5063 switch (QMacStylePrivate::tabDirection(twf->shape)) {
5064 case QMacStylePrivate::North:
5065 rect.adjust(+1, +14, -1, -1);
5067 case QMacStylePrivate::South:
5068 rect.adjust(+1, +1, -1, -14);
5070 case QMacStylePrivate::West:
5071 rect.adjust(+14, +1, -1, -1);
5073 case QMacStylePrivate::East:
5074 rect.adjust(+1, +1, -14, -1);
5079 case SE_TabBarTabText:
5080 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
5081 QRect dummyIconRect;
5082 d->tabLayout(tab, widget, &rect, &dummyIconRect);
5085 case SE_TabBarTabLeftButton:
5086 case SE_TabBarTabRightButton:
5087 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
5088 bool selected = tab->state & State_Selected;
5089 int verticalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget);
5090 int horizontalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget);
5093 bool verticalTabs = tab->shape == QTabBar::RoundedEast
5094 || tab->shape == QTabBar::RoundedWest
5095 || tab->shape == QTabBar::TriangularEast
5096 || tab->shape == QTabBar::TriangularWest;
5098 QRect tr = tab->rect;
5099 if (tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::TriangularSouth)
5100 verticalShift = -verticalShift;
5102 qSwap(horizontalShift, verticalShift);
5103 horizontalShift *= -1;
5104 verticalShift *= -1;
5106 if (tab->shape == QTabBar::RoundedWest || tab->shape == QTabBar::TriangularWest)
5107 horizontalShift = -horizontalShift;
5109 tr.adjust(0, 0, horizontalShift, verticalShift);
5112 tr.setBottom(tr.bottom() - verticalShift);
5113 tr.setRight(tr.right() - horizontalShift);
5116 QSize size = (sr == SE_TabBarTabLeftButton) ? tab->leftButtonSize : tab->rightButtonSize;
5117 int w = size.width();
5118 int h = size.height();
5119 int midHeight =
static_cast<
int>(qCeil(
float(tr.height() - h) / 2));
5120 int midWidth = ((tr.width() - w) / 2);
5122 bool atTheTop =
true;
5123 switch (tab->shape) {
5124 case QTabBar::RoundedWest:
5125 case QTabBar::TriangularWest:
5126 atTheTop = (sr == SE_TabBarTabLeftButton);
5128 case QTabBar::RoundedEast:
5129 case QTabBar::TriangularEast:
5130 atTheTop = (sr == SE_TabBarTabRightButton);
5133 if (sr == SE_TabBarTabLeftButton)
5134 rect = QRect(tab->rect.x() + hpadding, midHeight, w, h);
5136 rect = QRect(tab->rect.right() - w - hpadding, midHeight, w, h);
5137 rect = visualRect(tab->direction, tab->rect, rect);
5141 rect = QRect(midWidth, tr.y() + tab->rect.height() - hpadding - h, w, h);
5143 rect = QRect(midWidth, tr.y() + hpadding, w, h);
5148 case SE_LineEditContents:
5149 rect = QCommonStyle::subElementRect(sr, opt, widget);
5150#if QT_CONFIG(combobox)
5151 if (widget && qobject_cast<
const QComboBox*>(widget->parentWidget()))
5152 rect.adjust(-1, -2, 0, 0);
5155 rect.adjust(-1, -1, 0, +1);
5157 case SE_CheckBoxLayoutItem:
5159 if (controlSize == QStyleHelper::SizeLarge) {
5160 setLayoutItemMargins(+2, +3, -9, -4, &rect, opt->direction);
5161 }
else if (controlSize == QStyleHelper::SizeSmall) {
5162 setLayoutItemMargins(+1, +5, 0 , -6, &rect, opt->direction);
5164 setLayoutItemMargins(0, +7, 0 , -6, &rect, opt->direction);
5167 case SE_ComboBoxLayoutItem:
5168#ifndef QT_NO_TOOLBAR
5169 if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
5178 if (controlSize == QStyleHelper::SizeLarge) {
5179 rect.adjust(+3, +2, -3, -4);
5180 }
else if (controlSize == QStyleHelper::SizeSmall) {
5181 setLayoutItemMargins(+2, +1, -3, -4, &rect, opt->direction);
5183 setLayoutItemMargins(+1, 0, -2, 0, &rect, opt->direction);
5187 case SE_LabelLayoutItem:
5189 setLayoutItemMargins(+1, 0 , 0, 0 , &rect, opt->direction);
5191 case SE_ProgressBarLayoutItem: {
5193 int bottom =
SIZE(3, 8, 8);
5194 if (opt->state & State_Horizontal) {
5195 rect.adjust(0, +1, 0, -bottom);
5197 setLayoutItemMargins(+1, 0, -bottom, 0, &rect, opt->direction);
5201 case SE_PushButtonLayoutItem:
5202 if (
const QStyleOptionButton *buttonOpt
5203 = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
5204 if ((buttonOpt->features & QStyleOptionButton::Flat))
5206 if ((buttonOpt->features & QStyleOptionButton::CommandLinkButton)) {
5208 if (controlSize == QStyleHelper::SizeLarge)
5209 rect.adjust(+6, +4, -6, -8);
5210 else if (controlSize == QStyleHelper::SizeSmall)
5211 rect.adjust(+5, +4, -5, -6);
5213 rect.adjust(+1, 0, -1, -2);
5218 if (controlSize == QStyleHelper::SizeLarge) {
5219 rect.adjust(0, +4, 0, -8);
5220 }
else if (controlSize == QStyleHelper::SizeSmall) {
5221 rect.adjust(0, +4, 0, -6);
5223 rect.adjust(0, 0, 0, -2);
5226 case SE_RadioButtonLayoutItem:
5228 if (controlSize == QStyleHelper::SizeLarge) {
5229 setLayoutItemMargins(+2, +2 ,
5230 0, -4 , &rect, opt->direction);
5231 }
else if (controlSize == QStyleHelper::SizeSmall) {
5232 rect.adjust(0, +6, 0 , -5);
5234 rect.adjust(0, +6, 0 , -7);
5237 case SE_SliderLayoutItem:
5238 if (
const QStyleOptionSlider *sliderOpt
5239 = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5241 if (sliderOpt->tickPosition == QSlider::NoTicks) {
5242 int above =
SIZE(3, 0, 2);
5243 int below =
SIZE(4, 3, 0);
5244 if (sliderOpt->orientation == Qt::Horizontal) {
5245 rect.adjust(0, +above, 0, -below);
5247 rect.adjust(+above, 0, -below, 0);
5249 }
else if (sliderOpt->tickPosition == QSlider::TicksAbove) {
5250 int below =
SIZE(3, 2, 0);
5251 if (sliderOpt->orientation == Qt::Horizontal) {
5252 rect.setHeight(rect.height() - below);
5254 rect.setWidth(rect.width() - below);
5256 }
else if (sliderOpt->tickPosition == QSlider::TicksBelow) {
5257 int above =
SIZE(3, 2, 0);
5258 if (sliderOpt->orientation == Qt::Horizontal) {
5259 rect.setTop(rect.top() + above);
5261 rect.setLeft(rect.left() + above);
5266 case SE_FrameLayoutItem:
5268 if (
const QFrame *frame = qobject_cast<
const QFrame *>(widget)) {
5270 switch (frame->frameStyle() & QFrame::Shape_Mask) {
5272 rect.adjust(0, +1, 0, -1);
5275 rect.adjust(+1, 0, -1, 0);
5282 case SE_GroupBoxLayoutItem:
5284 if (
const QStyleOptionGroupBox *groupBoxOpt =
5285 qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
5287
5288
5289
5290
5291 if (groupBoxOpt->subControls & (QStyle::SC_GroupBoxCheckBox
5292 | QStyle::SC_GroupBoxLabel)) {
5294 if (groupBoxOpt->subControls & QStyle::SC_GroupBoxCheckBox) {
5295 delta =
SIZE(8, 4, 4);
5297 delta =
SIZE(15, 12, 12);
5299 rect.setTop(rect.top() + delta);
5302 rect.setBottom(rect.bottom() - 1);
5304#if QT_CONFIG(tabwidget)
5305 case SE_TabWidgetLayoutItem:
5306 if (
const QStyleOptionTabWidgetFrame *tabWidgetOpt =
5307 qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5309
5310
5311
5312
5313 rect = tabWidgetOpt->rect;
5314 if (tabWidgetOpt->shape == QTabBar::RoundedNorth)
5315 rect.setTop(rect.top() + SIZE(6 , 3 , 2 ));
5319#if QT_CONFIG(dockwidget)
5320 case SE_DockWidgetCloseButton:
5321 case SE_DockWidgetFloatButton:
5322 case SE_DockWidgetTitleBarText:
5323 case SE_DockWidgetIcon: {
5324 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
5325 int buttonMargin = proxy()->pixelMetric(PM_DockWidgetTitleBarButtonMargin, opt, widget);
5326 QRect srect = opt->rect;
5328 const QStyleOptionDockWidget *dwOpt
5329 = qstyleoption_cast<
const QStyleOptionDockWidget*>(opt);
5330 bool canClose = dwOpt == 0 ?
true : dwOpt->closable;
5331 bool canFloat = dwOpt == 0 ?
false : dwOpt->floatable;
5333 const bool verticalTitleBar = dwOpt->verticalTitleBar;
5337 if (verticalTitleBar)
5338 srect = srect.transposed();
5341 int right = srect.right();
5342 int left = srect.left();
5346 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton,
5347 opt, widget).actualSize(QSize(iconSize, iconSize));
5348 sz += QSize(buttonMargin, buttonMargin);
5349 if (verticalTitleBar)
5350 sz = sz.transposed();
5351 closeRect = QRect(left,
5352 srect.center().y() - sz.height()/2,
5353 sz.width(), sz.height());
5354 left = closeRect.right() + 1;
5356 if (sr == SE_DockWidgetCloseButton) {
5363 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarNormalButton,
5364 opt, widget).actualSize(QSize(iconSize, iconSize));
5365 sz += QSize(buttonMargin, buttonMargin);
5366 if (verticalTitleBar)
5367 sz = sz.transposed();
5368 floatRect = QRect(left,
5369 srect.center().y() - sz.height()/2,
5370 sz.width(), sz.height());
5371 left = floatRect.right() + 1;
5373 if (sr == SE_DockWidgetFloatButton) {
5379 if (
const QDockWidget *dw = qobject_cast<
const QDockWidget*>(widget)) {
5381 if (dw->isFloating())
5382 icon = dw->windowIcon();
5384 && icon.cacheKey() != QApplication::windowIcon().cacheKey()) {
5385 QSize sz = icon.actualSize(QSize(rect.height(), rect.height()));
5386 if (verticalTitleBar)
5387 sz = sz.transposed();
5388 iconRect = QRect(right - sz.width(), srect.center().y() - sz.height()/2,
5389 sz.width(), sz.height());
5390 right = iconRect.left() - 1;
5393 if (sr == SE_DockWidgetIcon) {
5398 QRect textRect = QRect(left, srect.top(),
5399 right - left, srect.height());
5400 if (sr == SE_DockWidgetTitleBarText) {
5406 if (verticalTitleBar) {
5407 rect = QRect(srect.left() + rect.top() - srect.top(),
5408 srect.top() + srect.right() - rect.right(),
5409 rect.height(), rect.width());
5411 rect = visualRect(opt->direction, srect, rect);
5417 rect = QCommonStyle::subElementRect(sr, opt, widget);
5450 const QWidget *widget)
const
5452 Q_D(
const QMacStyle);
5453 QMacCGContext cg(p);
5455 qCWarning(lcMacStyle) <<
"drawComplexControl:" << cc <<
"invalid (nullptr) graphics context";
5456 QWindow *window = widget && widget->window() ? widget->window()->windowHandle() :
nullptr;
5457 d->resolveCurrentNSView(window);
5460 if (
const QStyleOptionSlider *sb = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5463 const bool drawTrack = sb->subControls & SC_ScrollBarGroove;
5464 const bool drawKnob = sb->subControls & SC_ScrollBarSlider && sb->minimum != sb->maximum;
5465 if (!drawTrack && !drawKnob)
5468 const bool isHorizontal = sb->orientation == Qt::Horizontal;
5470 if (opt && opt->styleObject && !QMacStylePrivate::scrollBars.contains(opt->styleObject))
5471 QMacStylePrivate::scrollBars.append(QPointer<QObject>(opt->styleObject));
5473 static const CGFloat knobWidths[] = { 7.0, 5.0, 5.0 };
5474 static const CGFloat expandedKnobWidths[] = { 11.0, 9.0, 9.0 };
5475 const auto cocoaSize = d->effectiveAquaSizeConstrain(opt, widget);
5476 const CGFloat maxExpandScale = expandedKnobWidths[cocoaSize] / knobWidths[cocoaSize];
5478 const QStyle *realStyle = widget ? widget->style() : proxy();
5479 const bool isTransient = realStyle->styleHint(SH_ScrollBar_Transient, opt, widget);
5481 d->stopAnimation(opt->styleObject);
5482 bool wasActive =
false;
5483 CGFloat opacity = 0.0;
5484 CGFloat expandScale = 1.0;
5485 CGFloat expandOffset = 0.0;
5486 bool shouldExpand =
false;
5488 if (QObject *styleObject = opt->styleObject) {
5489 const int oldPos = styleObject->property(
"_q_stylepos").toInt();
5490 const int oldMin = styleObject->property(
"_q_stylemin").toInt();
5491 const int oldMax = styleObject->property(
"_q_stylemax").toInt();
5492 const QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
5493 const QStyle::State oldState =
static_cast<QStyle::State>(styleObject->property(
"_q_stylestate").value<QStyle::State::Int>());
5494 const uint oldActiveControls = styleObject->property(
"_q_stylecontrols").toUInt();
5498 const bool transient = isTransient && !opt->activeSubControls && !(sb->state & State_On);
5501 oldPos != sb->sliderPosition ||
5502 oldMin != sb->minimum ||
5503 oldMax != sb->maximum ||
5504 oldRect != sb->rect ||
5505 oldState != sb->state ||
5506 oldActiveControls != sb->activeSubControls) {
5512 styleObject->setProperty(
"_q_stylepos", sb->sliderPosition);
5513 styleObject->setProperty(
"_q_stylemin", sb->minimum);
5514 styleObject->setProperty(
"_q_stylemax", sb->maximum);
5515 styleObject->setProperty(
"_q_stylerect", sb->rect);
5516 styleObject->setProperty(
"_q_stylestate",
static_cast<QStyle::State::Int>(sb->state));
5517 styleObject->setProperty(
"_q_stylecontrols",
static_cast<uint>(sb->activeSubControls));
5519 QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
5522 anim =
new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Deactivating, styleObject);
5523 d->startAnimation(anim);
5524 }
else if (anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5527 anim->setCurrentTime(0);
5529 }
else if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5530 d->stopAnimation(styleObject);
5534 QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
5535 if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5538 if (oldActiveControls)
5539 anim->setActive(
true);
5541 wasActive = anim->wasActive();
5542 opacity = anim->currentValue();
5545 shouldExpand = isTransient && (opt->activeSubControls || wasActive);
5547 if (!anim && !oldActiveControls) {
5549 anim =
new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Activating, styleObject);
5550 d->startAnimation(anim);
5552 if (anim && anim->mode() == QScrollbarStyleAnimation::Activating) {
5553 expandScale = 1.0 + (maxExpandScale - 1.0) * anim->currentValue();
5554 expandOffset = 5.5 * (1.0 - anim->currentValue());
5557 expandScale = maxExpandScale;
5563 d->setupNSGraphicsContext(cg, NO );
5565 const auto controlType = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical;
5566 const auto cw = QMacStylePrivate::CocoaControl(controlType, cocoaSize);
5567 NSScroller *scroller =
static_cast<NSScroller *>(d->cocoaControl(cw));
5569 const QColor bgColor = QStyleHelper::backgroundColor(opt->palette, widget);
5570 const bool hasDarkBg = bgColor.red() < 128 && bgColor.green() < 128 && bgColor.blue() < 128;
5574 scroller.knobStyle = hasDarkBg? NSScrollerKnobStyleLight : NSScrollerKnobStyleDark;
5576 scroller.knobStyle = NSScrollerKnobStyleDefault;
5579 scroller.scrollerStyle = isTransient ? NSScrollerStyleOverlay : NSScrollerStyleLegacy;
5581 if (!setupScroller(scroller, sb))
5585 CGContextBeginTransparencyLayerWithRect(cg, scroller.frame,
nullptr);
5586 CGContextSetAlpha(cg, opacity);
5591 if (!isTransient || opt->activeSubControls || wasActive) {
5592 CGRect trackRect = scroller.bounds;
5594 trackRect.origin.y += expandOffset;
5596 trackRect.origin.x += expandOffset;
5597 [scroller drawKnobSlotInRect:trackRect highlight:NO];
5607 const CGFloat scrollerWidth = [NSScroller scrollerWidthForControlSize:scroller.controlSize scrollerStyle:scroller.scrollerStyle];
5608 const CGFloat knobWidth = knobWidths[cocoaSize] * expandScale;
5610 const CGRect scrollerKnobRect = CGRectInset([scroller rectForPart:NSScrollerKnob], 1, 1);
5611 const CGFloat knobLength = isHorizontal ? scrollerKnobRect.size.width : scrollerKnobRect.size.height;
5612 const CGFloat knobPos = isHorizontal ? scrollerKnobRect.origin.x : scrollerKnobRect.origin.y;
5613 const CGFloat knobOffset = qRound((scrollerWidth + expandOffset - knobWidth) / 2.0);
5614 const CGFloat knobRadius = knobWidth / 2.0;
5617 knobRect = CGRectMake(knobPos, knobOffset, knobLength, knobWidth);
5619 knobRect = CGRectMake(knobOffset, knobPos, knobWidth, knobLength);
5620 QCFType<CGPathRef> knobPath = CGPathCreateWithRoundedRect(knobRect, knobRadius, knobRadius,
nullptr);
5621 CGContextAddPath(cg, knobPath);
5622 CGContextSetAlpha(cg, 0.5);
5623 CGColorRef knobColor = hasDarkBg ? NSColor.whiteColor.CGColor : NSColor.blackColor.CGColor;
5624 CGContextSetFillColorWithColor(cg, knobColor);
5625 CGContextFillPath(cg);
5627 [scroller drawKnob];
5629 if (!isTransient && opt->activeSubControls) {
5634 CGContextSetBlendMode(cg, kCGBlendModePlusDarker);
5635 [scroller drawKnob];
5641 CGContextEndTransparencyLayer(cg);
5643 d->restoreNSGraphicsContext(cg);
5647 if (
const QStyleOptionSlider *sl = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5648 const bool isHorizontal = sl->orientation == Qt::Horizontal;
5649 const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical;
5650 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
5651 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5652 auto *slider =
static_cast<NSSlider *>(d->cocoaControl(cw));
5653 if (!setupSlider(slider, sl))
5656 const bool hasTicks = sl->tickPosition != QSlider::NoTicks;
5657 const bool hasDoubleTicks = sl->tickPosition == QSlider::TicksBothSides;
5658 const bool drawKnob = sl->subControls & SC_SliderHandle;
5659 const bool drawBar = sl->subControls & SC_SliderGroove;
5660 const bool drawTicks = sl->subControls & SC_SliderTickmarks;
5661 const bool isPressed = qt_apple_runningWithLiquidGlass() ?
false : sl->state & State_Sunken;
5665 const CGRect knobRect = [slider.cell knobRectFlipped:slider.isFlipped];
5666 pressPoint.x = CGRectGetMidX(knobRect);
5667 pressPoint.y = CGRectGetMidY(knobRect);
5682 [slider.cell startTrackingAt:pressPoint inView:slider];
5683 [slider.cell startTrackingAt:pressPoint inView:slider];
5686 d->drawNSViewInRect(slider, opt->rect, p, ^(CGContextRef ctx,
const CGRect &rect) {
5689 const bool verticalFlip = !isHorizontal && !sl->upsideDown;
5692 if (sl->upsideDown) {
5693 CGContextTranslateCTM(ctx, rect.size.width, rect.origin.y);
5694 CGContextScaleCTM(ctx, -1, 1);
5696 CGContextTranslateCTM(ctx, 0, rect.origin.y);
5698 }
else if (verticalFlip) {
5699 CGContextTranslateCTM(ctx, rect.origin.x, rect.size.height);
5700 CGContextScaleCTM(ctx, 1, -1);
5703 if (hasDoubleTicks) {
5706 CGContextTranslateCTM(ctx, 0, 4);
5708 CGContextTranslateCTM(ctx, 1, 0);
5715 const bool drawAllParts = drawKnob && drawBar && (!hasTicks || drawTicks);
5716 if (drawAllParts && !hasDoubleTicks && (!verticalFlip || drawTicks)) {
5720 if (verticalFlip && drawTicks) {
5723 slider.intValue = slider.maxValue - slider.intValue + slider.minValue;
5725 [slider drawRect:CGRectZero];
5729 NSSliderCell *cell = slider.cell;
5731 const int numberOfTickMarks = slider.numberOfTickMarks;
5734 slider.numberOfTickMarks = 0;
5736 const CGRect barRect = [cell barRectFlipped:slider.isFlipped];
5738 if (!isHorizontal && !sl->upsideDown && (hasDoubleTicks || !hasTicks)) {
5746 [cell drawBarInside:barRect flipped:
true];
5748 [cell drawBarInside:barRect flipped:!verticalFlip];
5752 slider.numberOfTickMarks = numberOfTickMarks;
5755 if (hasTicks && drawTicks) {
5756 if (!drawBar && hasDoubleTicks)
5757 slider.numberOfTickMarks = numberOfTickMarks;
5759 if (qt_apple_runningWithLiquidGlass())
5760 drawTickMarks(ctx, slider, sl);
5762 [cell drawTickMarks];
5764 if (hasDoubleTicks) {
5766 CGAffineTransform tickMarksFlip;
5767 const CGRect tickMarkRect = [cell rectOfTickMarkAtIndex:0];
5769 tickMarksFlip = CGAffineTransformMakeTranslation(0, rect.size.height - tickMarkRect.size.height - 3);
5770 tickMarksFlip = CGAffineTransformScale(tickMarksFlip, 1, -1);
5772 tickMarksFlip = CGAffineTransformMakeTranslation(rect.size.width - tickMarkRect.size.width / 2, 0);
5773 tickMarksFlip = CGAffineTransformScale(tickMarksFlip, -1, 1);
5775 CGContextConcatCTM(ctx, tickMarksFlip);
5776 [cell drawTickMarks];
5777 CGContextConcatCTM(ctx, CGAffineTransformInvert(tickMarksFlip));
5784 slider.numberOfTickMarks = 0;
5785 if (qt_apple_runningWithLiquidGlass())
5786 drawSliderKnob(ctx, slider);
5796 [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO];
5797 [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO];
5801#if QT_CONFIG(spinbox)
5803 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
5804 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
5805 const auto lineEditRect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget);
5806 QStyleOptionFrame frame;
5807 static_cast<QStyleOption &>(frame) = *opt;
5808 frame.rect = lineEditRect;
5809 frame.state |= State_Sunken;
5810 frame.lineWidth = 1;
5811 frame.midLineWidth = 0;
5812 frame.features = QStyleOptionFrame::None;
5813 frame.frameShape = QFrame::Box;
5814 drawPrimitive(PE_FrameLineEdit, &frame, p, widget);
5816 if (sb->subControls & (SC_SpinBoxUp | SC_SpinBoxDown)) {
5817 const QRect updown = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget)
5818 | proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
5821 d->setupNSGraphicsContext(cg, NO);
5823 const auto aquaSize = d->effectiveAquaSizeConstrain(opt, widget);
5824 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize);
5825 NSStepperCell *cell =
static_cast<NSStepperCell *>(d->cocoaCell(cw));
5826 const auto controlSize = cell.controlSize;
5827 if (qt_apple_runningWithLiquidGlass())
5828 cell.controlSize = NSControlSizeMini;
5829 cell.enabled = (sb->state & State_Enabled);
5831 const CGRect newRect = [cell drawingRectForBounds:updown.toCGRect()];
5833 const bool upPressed = sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken);
5834 const bool downPressed = sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken);
5835 const CGFloat x = CGRectGetMidX(newRect);
5836 const CGFloat y = upPressed ? -3 : 3;
5837 const CGPoint pressPoint = CGPointMake(x, y);
5840 if (upPressed || downPressed)
5841 [cell startTrackingAt:pressPoint inView:d->backingStoreNSView];
5843 [cell drawWithFrame:newRect inView:d->backingStoreNSView];
5845 if (upPressed || downPressed)
5846 [cell stopTracking:pressPoint at:pressPoint inView:d->backingStoreNSView mouseIsUp:NO];
5848 d->restoreNSGraphicsContext(cg);
5849 if (qt_apple_runningWithLiquidGlass())
5850 cell.controlSize = controlSize;
5855#if QT_CONFIG(combobox)
5857 if (
const auto *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
5858 const bool isEnabled = combo->state & State_Enabled;
5859 const bool isPressed = combo->state & State_Sunken;
5861 const auto ct = cocoaControlType(combo, widget);
5862 const auto cs = d->effectiveAquaSizeConstrain(combo, widget);
5863 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5864 auto *cc =
static_cast<NSControl *>(d->cocoaControl(cw));
5865 cc.enabled = isEnabled;
5866 QRectF frameRect = cw.adjustedControlFrame(combo->rect);
5867 if (cw.type == QMacStylePrivate::Button_PopupButton) {
5869 auto *pb =
static_cast<NSPopUpButton *>(cc);
5871 if (cw.size == QStyleHelper::SizeSmall) {
5872 frameRect = frameRect.translated(0, 1);
5873 }
else if (cw.size == QStyleHelper::SizeMini) {
5875 frameRect = frameRect.translated(2, -0.5);
5877 pb.frame = frameRect.toCGRect();
5878 [pb highlight:isPressed];
5879 d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
5880 [pb.cell drawBezelWithFrame:r inView:pb.superview];
5882 }
else if (cw.type == QMacStylePrivate::ComboBox) {
5884 auto *cb =
static_cast<NSComboBox *>(cc);
5885 const auto frameRect = cw.adjustedControlFrame(combo->rect);
5886 cb.frame = frameRect.toCGRect();
5889 if (NSButtonCell *cell =
static_cast<NSButtonCell *>([cc.cell qt_valueForPrivateKey:@
"_buttonCell"])) {
5890 cell.highlighted = isPressed;
5895 d->drawNSViewInRect(cb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
5897 [cb.cell drawWithFrame:r inView:cb];
5901 if (combo->state & State_HasFocus) {
5903 const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, combo, widget);
5904 const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, combo, widget);
5906 if (cw.type == QMacStylePrivate::Button_PopupButton) {
5907 if (qt_apple_runningWithLiquidGlass())
5908 focusRect = QRectF::fromCGRect(qt_alignmentRectForFrame(cc.frame, cw.size, cw.type));
5910 focusRect = QRectF::fromCGRect([cc alignmentRectForFrame:cc.frame]);
5911 focusRect -= pullDownButtonShadowMargins[cw.size];
5912 if (cw.size == QStyleHelper::SizeSmall)
5913 focusRect = focusRect.translated(0, 1);
5914 else if (cw.size == QStyleHelper::SizeMini)
5915 focusRect = focusRect.translated(2, -1);
5916 }
else if (cw.type == QMacStylePrivate::ComboBox) {
5917 focusRect = frameRect - comboBoxFocusRingMargins[cw.size];
5919 d->drawFocusRing(p, focusRect, hMargin, vMargin, cw);
5925 if (
const auto *titlebar = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
5926 const bool isActive = (titlebar->state & State_Active)
5927 && (titlebar->titleBarState & State_Active);
5929 p->fillRect(opt->rect, Qt::transparent);
5930 p->setRenderHint(QPainter::Antialiasing);
5931 p->setClipRect(opt->rect, Qt::IntersectClip);
5935 const auto outerFrameRect = QRectF(opt->rect.adjusted(0, 0, 0, opt->rect.height()));
5936 QPainterPath outerFramePath = d->windowPanelPath(outerFrameRect);
5937 p->fillPath(outerFramePath, opt->palette.dark());
5939 const auto frameAdjust = 1.0 / p->device()->devicePixelRatio();
5940 const auto innerFrameRect = outerFrameRect.adjusted(frameAdjust, frameAdjust, -frameAdjust, 0);
5941 QPainterPath innerFramePath = d->windowPanelPath(innerFrameRect);
5942 p->fillPath(innerFramePath, opt->palette.button());
5944 if (titlebar->subControls & (SC_TitleBarCloseButton
5945 | SC_TitleBarMaxButton
5946 | SC_TitleBarMinButton
5947 | SC_TitleBarNormalButton)) {
5948 const bool isHovered = (titlebar->state & State_MouseOver);
5949 static const SubControl buttons[] = {
5950 SC_TitleBarCloseButton, SC_TitleBarMinButton, SC_TitleBarMaxButton
5952 for (
const auto sc : buttons) {
5953 const auto ct = d->windowButtonCocoaControl(sc);
5954 const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
5955 auto *wb =
static_cast<NSButton *>(d->cocoaControl(cw));
5956 wb.enabled = (sc & titlebar->subControls) && isActive;
5957 [wb highlight:(titlebar->state & State_Sunken) && (sc & titlebar->activeSubControls)];
5958 Q_UNUSED(isHovered);
5960 const auto buttonRect = proxy()->subControlRect(CC_TitleBar, titlebar, sc, widget);
5961 d->drawNSViewInRect(wb, buttonRect, p, ^(CGContextRef,
const CGRect &rect) {
5962 auto *wbCell =
static_cast<NSButtonCell *>(wb.cell);
5963 [wbCell drawWithFrame:rect inView:wb];
5968 if (titlebar->subControls & SC_TitleBarLabel) {
5969 const auto tr = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarLabel, widget);
5970 if (!titlebar->icon.isNull()) {
5971 const auto iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
5972 const auto iconSize = QSize(iconExtent, iconExtent);
5973 const auto iconPos = tr.x() - titlebar->icon.actualSize(iconSize).width() - qRound(titleBarIconTitleSpacing);
5975 if (iconPos < tr.right() - titleBarIconTitleSpacing)
5976 p->drawPixmap(iconPos, tr.y(), titlebar->icon.pixmap(iconSize, QIcon::Normal));
5979 if (!titlebar->text.isEmpty())
5980 drawItemText(p, tr, Qt::AlignCenter, opt->palette, isActive, titlebar->text, QPalette::Text);
5985 if (
const QStyleOptionGroupBox *gb
5986 = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
5988 QStyleOptionGroupBox groupBox(*gb);
5989 const bool flat = groupBox.features & QStyleOptionFrame::Flat;
5991 groupBox.state |= QStyle::State_Mini;
5993 groupBox.subControls = groupBox.subControls & ~SC_GroupBoxFrame;
5995 const bool didSetFont = widget && widget->testAttribute(Qt::WA_SetFont);
5996 const bool didModifySubControls = !didSetFont && QApplication::desktopSettingsAware();
5997 if (didModifySubControls)
5998 groupBox.subControls = groupBox.subControls & ~SC_GroupBoxLabel;
5999 QCommonStyle::drawComplexControl(cc, &groupBox, p, widget);
6000 if (didModifySubControls) {
6001 const QRect rect = proxy()->subControlRect(CC_GroupBox, &groupBox, SC_GroupBoxLabel, widget);
6002 const bool rtl = groupBox.direction == Qt::RightToLeft;
6003 const int alignment = Qt::TextHideMnemonic | (rtl ? Qt::AlignRight : Qt::AlignLeft);
6004 const QFont savedFont = p->font();
6005 if (!flat && d->smallSystemFont)
6006 p->setFont(*d->smallSystemFont);
6007 proxy()->drawItemText(p, rect, alignment, groupBox.palette, groupBox.state & State_Enabled, groupBox.text, QPalette::WindowText);
6009 p->setFont(savedFont);
6014 if (
const QStyleOptionToolButton *tb
6015 = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
6016#if QT_CONFIG(accessibility)
6017 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) {
6018 if (tb->subControls & SC_ToolButtonMenu) {
6019 QStyleOption arrowOpt = *tb;
6020 arrowOpt.rect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget);
6021 arrowOpt.rect.setY(arrowOpt.rect.y() + arrowOpt.rect.height() / 2);
6022 arrowOpt.rect.setHeight(arrowOpt.rect.height() / 2);
6023 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
6024 }
else if ((tb->features & QStyleOptionToolButton::HasMenu)
6025 && (tb->toolButtonStyle != Qt::ToolButtonTextOnly && !tb->icon.isNull())) {
6026 d->drawToolbarButtonArrow(tb, p);
6028 if (tb->state & State_On) {
6029 NSView *view = window ? (NSView *)window->winId() : nil;
6032 isKey = [view.window isKeyWindow];
6034 QBrush brush(brushForToolButton(isKey));
6036 path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4);
6037 p->setRenderHint(QPainter::Antialiasing);
6038 p->fillPath(path, brush);
6040 proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget);
6044 auto bflags = tb->state;
6045 if (tb->subControls & SC_ToolButton)
6046 bflags |= State_Sunken;
6047 auto mflags = tb->state;
6048 if (tb->subControls & SC_ToolButtonMenu)
6049 mflags |= State_Sunken;
6051 if (tb->subControls & SC_ToolButton) {
6052 if (bflags & (State_Sunken | State_On | State_Raised)) {
6053 const bool isEnabled = tb->state & State_Enabled;
6054 const bool isPressed = tb->state & State_Sunken;
6055 const bool isHighlighted = (tb->state & State_Active) && (tb->state & State_On);
6056 const auto ct = QMacStylePrivate::Button_PushButton;
6057 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6058 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6059 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
6060 pb.bezelStyle = NSBezelStyleShadowlessSquare;
6061 pb.frame = opt->rect.toCGRect();
6062 pb.buttonType = NSButtonTypePushOnPushOff;
6063 pb.enabled = isEnabled;
6064 [pb highlight:isPressed];
6065 pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff;
6066 const auto buttonRect = proxy()->subControlRect(cc, tb, SC_ToolButton, widget);
6067 d->drawNSViewInRect(pb, buttonRect, p, ^(CGContextRef,
const CGRect &rect) {
6068 [pb.cell drawBezelWithFrame:rect inView:pb];
6073 if (tb->subControls & SC_ToolButtonMenu) {
6074 const auto menuRect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget);
6075 QStyleOption arrowOpt = *tb;
6080 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
6081 }
else if (tb->features & QStyleOptionToolButton::HasMenu) {
6082 d->drawToolbarButtonArrow(tb, p);
6084 QRect buttonRect = proxy()->subControlRect(CC_ToolButton, tb, SC_ToolButton, widget);
6085 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
6086 QStyleOptionToolButton label = *tb;
6087 label.rect = buttonRect.adjusted(fw, fw, -fw, -fw);
6088 proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget);
6094 if (
const QStyleOptionSlider *dial = qstyleoption_cast<
const QStyleOptionSlider *>(opt))
6095 QStyleHelper::drawDial(dial, p);
6099 QCommonStyle::drawComplexControl(cc, opt, p, widget);
6191 const QWidget *widget)
const
6193 Q_D(
const QMacStyle);
6197 if (
const QStyleOptionSlider *sb = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6198 const bool isHorizontal = sb->orientation == Qt::Horizontal;
6199 const bool isReverseHorizontal = isHorizontal && (sb->direction == Qt::RightToLeft);
6201 NSScrollerPart part = NSScrollerNoPart;
6202 if (sc == SC_ScrollBarSlider) {
6203 part = NSScrollerKnob;
6204 }
else if (sc == SC_ScrollBarGroove) {
6205 part = NSScrollerKnobSlot;
6206 }
else if (sc == SC_ScrollBarSubPage || sc == SC_ScrollBarAddPage) {
6207 if ((!isReverseHorizontal && sc == SC_ScrollBarSubPage)
6208 || (isReverseHorizontal && sc == SC_ScrollBarAddPage))
6209 part = NSScrollerDecrementPage;
6211 part = NSScrollerIncrementPage;
6215 if (part != NSScrollerNoPart) {
6216 const auto ct = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical;
6217 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6218 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6219 auto *scroller =
static_cast<NSScroller *>(d->cocoaControl(cw));
6220 if (setupScroller(scroller, sb))
6221 ret = QRectF::fromCGRect([scroller rectForPart:part]).toRect();
6226 if (
const QStyleOptionSlider *sl = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6227 const bool hasTicks = sl->tickPosition != QSlider::NoTicks;
6228 const bool isHorizontal = sl->orientation == Qt::Horizontal;
6229 const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical;
6230 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6231 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6232 auto *slider =
static_cast<NSSlider *>(d->cocoaControl(cw));
6233 if (!setupSlider(slider, sl))
6236 NSSliderCell *cell = slider.cell;
6237 if (sc == SC_SliderHandle) {
6238 ret = QRectF::fromCGRect([cell knobRectFlipped:slider.isFlipped]).toRect();
6240 ret.setTop(sl->rect.top());
6241 ret.setBottom(sl->rect.bottom());
6243 ret.setLeft(sl->rect.left());
6244 ret.setRight(sl->rect.right());
6246 }
else if (sc == SC_SliderGroove) {
6247 ret = QRectF::fromCGRect([cell barRectFlipped:slider.isFlipped]).toRect();
6248 }
else if (hasTicks && sc == SC_SliderTickmarks) {
6249 const auto tickMarkRect = QRectF::fromCGRect([cell rectOfTickMarkAtIndex:0]);
6251 ret = QRect(sl->rect.left(), tickMarkRect.top(), sl->rect.width(), tickMarkRect.height());
6253 ret = QRect(tickMarkRect.left(), sl->rect.top(), tickMarkRect.width(), sl->rect.height());
6258 if (sl->upsideDown) {
6259 ret = QRect(sl->rect.right() - ret.right(), sl->rect.top(), ret.width(), sl->rect.height());
6261 ret.setTop(sl->rect.top());
6262 ret.setBottom(sl->rect.bottom());
6265 if (!sl->upsideDown) {
6266 ret = QRect(sl->rect.left(), sl->rect.bottom() - ret.bottom(), sl->rect.width(), ret.height());
6268 ret.setLeft(sl->rect.left());
6269 ret.setRight(sl->rect.right());
6275 if (
const auto *titlebar = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
6281 if (sc == SC_TitleBarLabel) {
6282 qreal labelWidth = titlebar->fontMetrics.horizontalAdvance(titlebar->text) + 1;
6283 qreal labelHeight = titlebar->fontMetrics.height();
6285 const auto lastButtonRect = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarMaxButton, widget);
6286 qreal controlsSpacing = lastButtonRect.right() + titleBarButtonSpacing;
6287 if (!titlebar->icon.isNull()) {
6288 const auto iconSize = proxy()->pixelMetric(PM_SmallIconSize);
6289 const auto actualIconSize = titlebar->icon.actualSize(QSize(iconSize, iconSize)).width();
6290 controlsSpacing += actualIconSize + titleBarIconTitleSpacing;
6293 const qreal labelPos = qMax(controlsSpacing, (opt->rect.width() - labelWidth) / 2.0);
6294 labelWidth = qMin(labelWidth, opt->rect.width() - (labelPos + titleBarTitleRightMargin));
6295 ret = QRect(labelPos, (opt->rect.height() - labelHeight) / 2,
6296 labelWidth, labelHeight);
6298 const auto currentButton = d->windowButtonCocoaControl(sc);
6299 if (currentButton == QMacStylePrivate::NoControl)
6302 QPointF buttonPos = titlebar->rect.topLeft() + QPointF(titleBarButtonSpacing, 0);
6304 for (
int ct = QMacStylePrivate::Button_WindowClose; ct <= currentButton; ct++) {
6305 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::CocoaControlType(ct),
6306 QStyleHelper::SizeLarge);
6307 auto *wb =
static_cast<NSButton *>(d->cocoaControl(cw));
6308 if (ct == currentButton)
6309 buttonSize = QSizeF::fromCGSize(wb.frame.size);
6311 buttonPos.rx() += wb.frame.size.width + titleBarButtonSpacing;
6314 const auto vOffset = (opt->rect.height() - buttonSize.height()) / 2.0;
6315 ret = QRectF(buttonPos, buttonSize).translated(0, vOffset).toRect();
6320 if (
const QStyleOptionComboBox *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
6321 const auto ct = cocoaControlType(combo, widget);
6322 const auto cs = d->effectiveAquaSizeConstrain(combo, widget);
6323 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6324 const auto editRect = QMacStylePrivate::comboboxEditBounds(cw.adjustedControlFrame(combo->rect), cw);
6327 case SC_ComboBoxEditField:{
6328 ret = editRect.toAlignedRect();
6330 case SC_ComboBoxArrow:{
6331 ret = editRect.toAlignedRect();
6332 ret.setX(ret.x() + ret.width());
6333 ret.setWidth(combo->rect.right() - ret.right());
6335 case SC_ComboBoxListBoxPopup:{
6336 if (combo->editable) {
6337 const CGRect inner = QMacStylePrivate::comboboxInnerBounds(combo->rect.toCGRect(), cw);
6338 const int comboTop = combo->rect.top();
6339 ret = QRect(qRound(inner.origin.x),
6341 qRound(inner.origin.x - combo->rect.left() + inner.size.width),
6342 editRect.bottom() - comboTop + 2);
6344 ret = QRect(combo->rect.x() + 4 - 11,
6345 combo->rect.y() + 1,
6346 editRect.width() + 10 + 11,
6356 if (
const QStyleOptionGroupBox *groupBox = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
6357 bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
6358 const bool flat = groupBox->features & QStyleOptionFrame::Flat;
6359 bool hasNoText = !checkable && groupBox->text.isEmpty();
6361 case SC_GroupBoxLabel:
6362 case SC_GroupBoxCheckBox: {
6364 const bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
6365 const bool fontIsSet = (widget && widget->testAttribute(Qt::WA_SetFont))
6366 || !QApplication::desktopSettingsAware();
6367 const int margin = flat || hasNoText ? 0 : 9;
6368 ret = groupBox->rect.adjusted(margin, 0, -margin, 0);
6370 const QFontMetricsF fm = flat || fontIsSet || !d->smallSystemFont
6371 ? QFontMetricsF(groupBox->fontMetrics)
6372 : QFontMetricsF(*d->smallSystemFont);
6373 const QSizeF s = fm.size(Qt::AlignHCenter | Qt::AlignVCenter, qt_mac_removeMnemonics(groupBox->text), 0,
nullptr);
6374 const int tw = qCeil(s.width());
6375 const int h = qCeil(fm.height());
6378 QRect labelRect = alignedRect(groupBox->direction, groupBox->textAlignment,
6380 if (flat && checkable)
6381 labelRect.moveLeft(labelRect.left() + 4);
6382 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt, widget);
6383 bool rtl = groupBox->direction == Qt::RightToLeft;
6384 if (sc == SC_GroupBoxLabel) {
6386 int newSum = indicatorWidth + 1;
6387 int newLeft = labelRect.left() + (rtl ? -newSum : newSum);
6388 labelRect.moveLeft(newLeft);
6390 labelRect.moveTop(labelRect.top() + 3);
6392 labelRect.moveTop(labelRect.top() + 4);
6394 int newLeft = labelRect.left() - (rtl ? 3 : -3);
6395 labelRect.moveLeft(newLeft);
6396 labelRect.moveTop(labelRect.top() + 3);
6398 int newLeft = labelRect.left() - (rtl ? 3 : 2);
6399 labelRect.moveLeft(newLeft);
6400 labelRect.moveTop(labelRect.top() + 4);
6405 if (sc == SC_GroupBoxCheckBox) {
6406 int left = rtl ? labelRect.right() - indicatorWidth : labelRect.left() - 1;
6407 int top = flat ? ret.top() + 1 : ret.top() + 5;
6408 ret.setRect(left, top,
6409 indicatorWidth, proxy()->pixelMetric(PM_IndicatorHeight, opt, widget));
6413 case SC_GroupBoxContents:
6414 case SC_GroupBoxFrame: {
6415 QFontMetrics fm = groupBox->fontMetrics;
6418 if (widget && !widget->testAttribute(Qt::WA_SetFont)
6419 && QApplication::desktopSettingsAware())
6420 fm = QFontMetrics(qt_app_fonts_hash()->value(
"QSmallFont", QFont()));
6425 yOffset = -qCeil(QFontMetricsF(fm).height());
6426 ret = opt->rect.adjusted(0, qCeil(QFontMetricsF(fm).height()) + yOffset, 0, 0);
6427 if (sc == SC_GroupBoxContents) {
6429 ret.adjust(3, -5, -3, -4);
6431 ret.adjust(3, 3, -3, -4);
6436 ret = QCommonStyle::subControlRect(cc, groupBox, sc, widget);
6441#if QT_CONFIG(spinbox)
6443 if (
const QStyleOptionSpinBox *spin = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
6444 QStyleHelper::WidgetSizePolicy aquaSize = d->effectiveAquaSizeConstrain(spin, widget);
6445 const auto fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin, widget);
6449 case QStyleHelper::SizeLarge:
6453 case QStyleHelper::SizeSmall:
6457 case QStyleHelper::SizeMini:
6467 case SC_SpinBoxDown: {
6468 if (spin->buttonSymbols == QAbstractSpinBox::NoButtons)
6472 const int x = spin->rect.width() - spinner_w;
6473 ret.setRect(x + spin->rect.x(), y + spin->rect.y(), spinner_w, spin->rect.height() - y * 2);
6476 case QStyleHelper::SizeLarge:
6479 case QStyleHelper::SizeSmall:
6480 hackTranslateX = -2;
6482 case QStyleHelper::SizeMini:
6483 hackTranslateX = -1;
6489 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize);
6490 NSStepperCell *cell =
static_cast<NSStepperCell *>(d->cocoaCell(cw));
6491 const CGRect outRect = [cell drawingRectForBounds:ret.toCGRect()];
6492 ret = QRectF::fromCGRect(outRect).toRect();
6496 ret.setHeight(ret.height() / 2);
6498 case SC_SpinBoxDown:
6499 ret.setY(ret.y() + ret.height() / 2);
6505 ret.translate(hackTranslateX, 0);
6506 ret = visualRect(spin->direction, spin->rect, ret);
6509 case SC_SpinBoxEditField:
6510 ret = spin->rect.adjusted(fw, fw, -fw, -fw);
6511 if (spin->buttonSymbols != QAbstractSpinBox::NoButtons) {
6512 ret.setWidth(spin->rect.width() - spinBoxSep - spinner_w);
6513 ret = visualRect(spin->direction, spin->rect, ret);
6517 ret = QCommonStyle::subControlRect(cc, spin, sc, widget);
6524 ret = QCommonStyle::subControlRect(cc, opt, sc, widget);
6525 if (sc == SC_ToolButtonMenu) {
6526#if QT_CONFIG(accessibility)
6527 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar))
6528 ret.adjust(-toolButtonArrowMargin, 0, 0, 0);
6530 ret.adjust(-1, 0, 0, 0);
6534 ret = QCommonStyle::subControlRect(cc, opt, sc, widget);
6541 const QSize &csz,
const QWidget *widget)
const
6543 Q_D(
const QMacStyle);
6545 bool useAquaGuideline =
true;
6548#if QT_CONFIG(spinbox)
6550 if (
const QStyleOptionSpinBox *vopt = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
6551 const bool hasButtons = (vopt->buttonSymbols != QAbstractSpinBox::NoButtons);
6552 const int buttonWidth = hasButtons ? proxy()->subControlRect(CC_SpinBox, vopt, SC_SpinBoxUp, widget).width() : 0;
6553 sz += QSize(buttonWidth, 0);
6557 case QStyle::CT_TabWidget:
6560 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6592#if QT_CONFIG(tabwidget)
6593 if (
const QStyleOptionTabWidgetFrame *twf
6594 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
6596 const int overlap = pixelMetric(PM_TabBarBaseOverlap, opt, widget);
6597 const int gapBetweenTabbarAndStackWidget = 2 + 14 - overlap;
6599 const auto tabDirection = QMacStylePrivate::tabDirection(twf->shape);
6600 if (tabDirection == QMacStylePrivate::North
6601 || tabDirection == QMacStylePrivate::South) {
6602 extra = QSize(2, gapBetweenTabbarAndStackWidget + 1);
6604 extra = QSize(gapBetweenTabbarAndStackWidget + 1, 2);
6610#if QT_CONFIG(tabbar)
6611 case QStyle::CT_TabBarTab:
6612 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
6613 const bool differentFont = (widget && widget->testAttribute(Qt::WA_SetFont))
6614 || !QApplication::desktopSettingsAware();
6615 const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape);
6616 const bool verticalTabs = tabDirection == QMacStylePrivate::East
6617 || tabDirection == QMacStylePrivate::West;
6619 sz = sz.transposed();
6621 int defaultTabHeight;
6622 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6624 case QStyleHelper::SizeLarge:
6625 if (tab->documentMode)
6626 defaultTabHeight = 24;
6628 defaultTabHeight = 21;
6630 if (qt_apple_runningWithLiquidGlass() && !tab->documentMode) {
6638 defaultTabHeight = 23;
6641 case QStyleHelper::SizeSmall:
6642 defaultTabHeight = 18;
6644 case QStyleHelper::SizeMini:
6645 defaultTabHeight = 16;
6651 const bool widthSet = !differentFont && tab->icon.isNull();
6653 const auto textSize = opt->fontMetrics.size(Qt::TextShowMnemonic, tab->text);
6654 sz.rwidth() = textSize.width();
6655 sz.rheight() = qMax(defaultTabHeight, textSize.height());
6657 sz.rheight() = qMax(defaultTabHeight, sz.height());
6659 sz.rwidth() += proxy()->pixelMetric(PM_TabBarTabHSpace, tab, widget);
6662 sz = sz.transposed();
6664 int maxWidgetHeight = qMax(tab->leftButtonSize.height(), tab->rightButtonSize.height());
6665 int maxWidgetWidth = qMax(tab->leftButtonSize.width(), tab->rightButtonSize.width());
6667 int widgetWidth = 0;
6668 int widgetHeight = 0;
6670 if (tab->leftButtonSize.isValid()) {
6672 widgetWidth += tab->leftButtonSize.width();
6673 widgetHeight += tab->leftButtonSize.height();
6675 if (tab->rightButtonSize.isValid()) {
6677 widgetWidth += tab->rightButtonSize.width();
6678 widgetHeight += tab->rightButtonSize.height();
6682 sz.setWidth(qMax(sz.width(), maxWidgetWidth));
6683 sz.setHeight(sz.height() + widgetHeight + padding);
6686 sz.setWidth(sz.width() + widgetWidth + padding);
6687 sz.setHeight(qMax(sz.height(), maxWidgetHeight));
6692 case QStyle::CT_PushButton: {
6693 bool isFlat =
false;
6694 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
6695 if (btn->features & QStyleOptionButton::CommandLinkButton)
6696 return QCommonStyle::sizeFromContents(ct, opt, sz, widget);
6697 isFlat = btn->features & QStyleOptionButton::Flat;
6704 const auto controlSize = d->effectiveAquaSizeConstrain(opt, widget, CT_PushButton, sz, &macsz);
6706 if (macsz.width() != -1)
6707 sz.setWidth(macsz.width());
6709 sz.rwidth() += QMacStylePrivate::PushButtonLeftOffset + QMacStylePrivate::PushButtonRightOffset + 12;
6711 if (controlSize != QStyleHelper::SizeMini)
6714 if (controlSize == QStyleHelper::SizeLarge) {
6717 if (sz.height() > 16)
6718 sz.rheight() += pushButtonDefaultHeight[QStyleHelper::SizeLarge] - 16;
6720 sz.setHeight(pushButtonDefaultHeight[QStyleHelper::SizeLarge]);
6722 if (!isFlat && !qt_apple_runningWithLiquidGlass())
6724 if (controlSize == QStyleHelper::SizeMini)
6727 sz.setHeight(pushButtonDefaultHeight[QStyleHelper::SizeSmall]);
6733 case QStyle::CT_MenuItem:
6734 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
6735 int maxpmw = mi->maxIconWidth;
6736#if QT_CONFIG(combobox)
6737 const QComboBox *comboBox = qobject_cast<
const QComboBox *>(widget);
6741 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
6745 h = mi->fontMetrics.height() + 2;
6746 if (!mi->icon.isNull()) {
6747#if QT_CONFIG(combobox)
6749 const QSize &iconSize = comboBox->iconSize();
6750 h = qMax(h, iconSize.height() + 4);
6751 maxpmw = qMax(maxpmw, iconSize.width());
6755 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
6756 h = qMax(h, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() + 4);
6760 if (mi->text.contains(QLatin1Char(
'\t')))
6762 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
6768#if QT_CONFIG(combobox)
6769 if (comboBox && comboBox->isVisible()) {
6770 QStyleOptionComboBox cmb;
6771 cmb.initFrom(comboBox);
6772 cmb.editable =
false;
6773 cmb.subControls = QStyle::SC_ComboBoxEditField;
6774 cmb.activeSubControls = QStyle::SC_None;
6775 w = qMax(w, subControlRect(QStyle::CC_ComboBox, &cmb,
6776 QStyle::SC_ComboBoxEditField,
6786 case CT_MenuBarItem:
6793 if (
const auto *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt))
6794 if (tb->features & QStyleOptionToolButton::Menu)
6798 if (
const auto *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
6799 const auto controlSize = d->effectiveAquaSizeConstrain(opt, widget);
6800 if (!cb->editable) {
6803 sz.rwidth() += QMacStylePrivate::PushButtonLeftOffset + QMacStylePrivate::PushButtonRightOffset + 24;
6805 if (controlSize != QStyleHelper::SizeMini)
6809 if (controlSize == QStyleHelper::SizeLarge && sz.height() > 16)
6810 sz.rheight() += popupButtonDefaultHeight[QStyleHelper::SizeLarge] - 16;
6818 if (controlSize == QStyleHelper::SizeMini)
6821 sz.setHeight(pushButtonDefaultHeight[controlSize]);
6827 if (proxy() ==
this) {
6830 QStyleHintReturnMask menuMask;
6831 QStyleOption myOption = *opt;
6832 myOption.rect.setSize(sz);
6833 if (proxy()->styleHint(SH_Menu_Mask, &myOption, widget, &menuMask))
6834 sz = menuMask.region.boundingRect().size();
6837 case CT_HeaderSection:{
6838 const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt);
6839 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6840 if (header->text.contains(QLatin1Char(
'\n')))
6841 useAquaGuideline =
false;
6845 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6846 const int minimumSize = 24;
6847 if (slider->orientation == Qt::Horizontal)
6848 sz = sz.expandedTo(QSize(minimumSize, sz.height()));
6850 sz = sz.expandedTo(QSize(sz.width(), minimumSize));
6853#if QT_CONFIG(itemviews)
6854 case CT_ItemViewItem:
6855 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
6856 sz = QCommonStyle::sizeFromContents(ct, vopt, csz, widget);
6857 sz.setHeight(sz.height() + 2);
6863 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6866 if (useAquaGuideline && ct != CT_PushButton) {
6869 if (d->aquaSizeConstrain(opt, widget, ct, sz, &macsz) != QStyleHelper::SizeDefault) {
6870 if (macsz.width() != -1)
6871 sz.setWidth(macsz.width());
6872 if (macsz.height() != -1)
6873 sz.setHeight(macsz.height());
6879 if (
const QStyleOptionComboBox *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)){
6880 if (combo->editable) {
6881 const auto widgetSize = d->aquaSizeConstrain(opt, widget);
6882 QMacStylePrivate::CocoaControl cw;
6883 cw.type = combo->editable ? QMacStylePrivate::ComboBox : QMacStylePrivate::Button_PopupButton;
6884 cw.size = widgetSize;
6885 const CGRect diffRect = QMacStylePrivate::comboboxInnerBounds(CGRectZero, cw);
6886 sz.rwidth() -= qRound(diffRect.size.width);
6887 sz.rheight() -= qRound(diffRect.size.height);