1282void QMacStylePrivate::drawFocusRing(QPainter *p,
const QRectF &targetRect,
int hMargin,
int vMargin,
const CocoaControl &cw)
const
1284 QPainterPath focusRingPath;
1285 focusRingPath.setFillRule(Qt::OddEvenFill);
1287 qreal hOffset = 0.0;
1288 qreal vOffset = 0.0;
1291 case Button_SquareButton:
1292 case SegmentedControl_Middle:
1294 auto innerRect = targetRect;
1295 qreal innerRadius = 0.0;
1296 if (cw.type == Button_SquareButton)
1297 innerRect = cw.adjustedControlFrame(targetRect.adjusted(hMargin, vMargin, -hMargin, -vMargin));
1298 if (cw.type == TextField) {
1299 innerRect = innerRect.adjusted(hMargin, vMargin, -hMargin, -vMargin).adjusted(0.5, 0.5, -0.5, -0.5);
1300 if (qt_apple_runningWithLiquidGlass())
1301 innerRadius = textFieldBezelCornerRadius - 0.5;
1303 const auto outerRect = innerRect.adjusted(-focusRingWidth, -focusRingWidth, focusRingWidth, focusRingWidth);
1304 const auto outerRadius = innerRadius + focusRingWidth;
1305 if (innerRadius > 0.0)
1306 focusRingPath.addRoundedRect(innerRect, innerRadius, innerRadius);
1308 focusRingPath.addRect(innerRect);
1309 focusRingPath.addRoundedRect(outerRect, outerRadius, outerRadius);
1312 case Button_CheckBox: {
1313 const auto cbInnerRadius = (cw.size == QStyleHelper::SizeMini ? 2.0 : 3.0);
1314 const auto cbSize = cw.size == QStyleHelper::SizeLarge ? 13 :
1315 cw.size == QStyleHelper::SizeSmall ? 11 : 9;
1316 hOffset = hMargin + (cw.size == QStyleHelper::SizeLarge ? (qt_apple_runningWithLiquidGlass() ? 1.5 : 2.5) :
1317 cw.size == QStyleHelper::SizeSmall ? (qt_apple_runningWithLiquidGlass() ? 1.5 : 2.0) : 1.0);
1318 vOffset = 0.5 * qreal(targetRect.height() - cbSize);
1319 if (qt_apple_runningWithLiquidGlass()) {
1320 if (cw.size == QStyleHelper::SizeSmall)
1322 if (cw.size == QStyleHelper::SizeMini)
1325 const auto cbInnerRect = QRectF(0, 0, cbSize, cbSize);
1326 const auto cbOuterRadius = cbInnerRadius + focusRingWidth;
1327 const auto cbOuterRect = cbInnerRect.adjusted(-focusRingWidth, -focusRingWidth, focusRingWidth, focusRingWidth);
1328 focusRingPath.addRoundedRect(cbOuterRect, cbOuterRadius, cbOuterRadius);
1329 focusRingPath.addRoundedRect(cbInnerRect, cbInnerRadius, cbInnerRadius);
1332 case Button_RadioButton: {
1333 const auto rbSize = cw.size == QStyleHelper::SizeLarge ? 15 :
1334 cw.size == QStyleHelper::SizeSmall ? 13 : 9;
1335 hOffset = hMargin + (cw.size == QStyleHelper::SizeLarge ? (qt_apple_runningWithLiquidGlass() ? 0.5 : 1.5) :
1336 cw.size == QStyleHelper::SizeSmall ? (qt_apple_runningWithLiquidGlass() ? 0.5 : 1.0) : 1.0);
1337 vOffset = 0.5 * qreal(targetRect.height() - rbSize);
1338 const auto rbInnerRect = QRectF(0, 0, rbSize, rbSize);
1339 const auto rbOuterRect = rbInnerRect.adjusted(-focusRingWidth, -focusRingWidth, focusRingWidth, focusRingWidth);
1340 focusRingPath.addEllipse(rbInnerRect);
1341 focusRingPath.addEllipse(rbOuterRect);
1344 case Button_PullDown:
1345 case Button_PushButton: {
1347 auto *pb =
static_cast<NSButton *>(cocoaControl(cw));
1348 const QRectF frameRect = cw.adjustedControlFrame(targetRect.adjusted(hMargin, vMargin, -hMargin, -vMargin));
1349 pb.frame = frameRect.toCGRect();
1351 if (qt_apple_runningWithLiquidGlass())
1352 focusRect = QRectF::fromCGRect(qt_alignmentRectForFrame(pb.frame, cw.size, cw.type));
1354 focusRect = QRectF::fromCGRect([pb alignmentRectForFrame:pb.frame]);
1356 if (cw.type == QMacStylePrivate::Button_PushButton) {
1357 adjustPushButtonShadowMargins(focusRect, cw.size);
1358 if (cw.size == QStyleHelper::SizeMini)
1359 focusRect.adjust(0, 3, 0, -3);
1360 }
else if (cw.type == QMacStylePrivate::Button_PullDown) {
1361 focusRect -= pullDownButtonShadowMargins[cw.size];
1363 if (cw.size == QStyleHelper::SizeLarge)
1364 focusRect = focusRect.adjusted(0, 0, 0, -1);
1365 else if (cw.size == QStyleHelper::SizeMini)
1366 focusRect = focusRect.adjusted(0, -1, 0, 0);
1368 focusRect = focusRect.translated(0, 1);
1369 const qreal innerRadius = cw.type == Button_PushButton ? 3 : 4;
1370 const qreal outerRadius = innerRadius + focusRingWidth;
1371 hOffset = focusRect.left();
1372 vOffset = focusRect.top();
1373 const auto innerRect = focusRect.translated(-focusRect.topLeft());
1374 const auto outerRect = innerRect.adjusted(-hMargin, -vMargin, hMargin, vMargin);
1375 focusRingPath.addRoundedRect(innerRect, innerRadius, innerRadius);
1376 focusRingPath.addRoundedRect(outerRect, outerRadius, outerRadius);
1379 case Button_PopupButton:
1380 case SegmentedControl_Single: {
1381 QRectF focusRect = targetRect;
1383 if (!qt_apple_runningWithLiquidGlass())
1384 focusRect.translate(0, -1.5);
1385 const qreal innerRadius = cw.type == Button_PushButton ? 3 : 4;
1386 const qreal outerRadius = innerRadius + focusRingWidth;
1387 hOffset = focusRect.left();
1388 vOffset = focusRect.top();
1389 const auto innerRect = focusRect.translated(-focusRect.topLeft());
1390 const auto outerRect = innerRect.adjusted(-hMargin, -vMargin, hMargin, vMargin);
1391 focusRingPath.addRoundedRect(innerRect, innerRadius, innerRadius);
1392 focusRingPath.addRoundedRect(outerRect, outerRadius, outerRadius);
1396 case SegmentedControl_First:
1397 case SegmentedControl_Last: {
1398 hOffset = targetRect.left();
1399 vOffset = targetRect.top();
1400 const qreal innerRadius = 8;
1401 const qreal outerRadius = innerRadius + focusRingWidth;
1402 const auto innerRect = targetRect.translated(-targetRect.topLeft());
1403 const auto outerRect = innerRect.adjusted(-hMargin, -vMargin, hMargin, vMargin);
1405 const auto cbFocusFramePath = [](
const QRectF &rect, qreal tRadius, qreal bRadius) {
1409 const auto topLeftCorner = QRectF(rect.topLeft(), QSizeF(tRadius, tRadius));
1410 path.arcMoveTo(topLeftCorner, 180);
1411 path.arcTo(topLeftCorner, 180, -90);
1413 path.moveTo(rect.topLeft());
1415 const auto rightEdge = rect.right() - bRadius;
1416 path.arcTo(rightEdge, rect.top(), bRadius, bRadius, 90, -90);
1417 path.arcTo(rightEdge, rect.bottom() - bRadius, bRadius, bRadius, 0, -90);
1419 path.arcTo(rect.left(), rect.bottom() - tRadius, tRadius, tRadius, 270, -90);
1421 path.lineTo(rect.bottomLeft());
1422 path.closeSubpath();
1427 const auto innerPath = cbFocusFramePath(innerRect, 0, innerRadius);
1428 focusRingPath.addPath(innerPath);
1429 const auto outerPath = cbFocusFramePath(outerRect, 2 * focusRingWidth, outerRadius);
1430 focusRingPath.addPath(outerPath);
1437 auto focusRingColor = qt_mac_toQColor(NSColor.keyboardFocusIndicatorColor.CGColor);
1442 focusRingColor.setAlphaF(0.39);
1446 p->setRenderHint(QPainter::Antialiasing);
1448 if (cw.type == SegmentedControl_First) {
1451 p->translate(hOffset, vOffset);
1452 p->fillPath(focusRingPath, focusRingColor);
3228 const QWidget *w)
const
3230 Q_D(
const QMacStyle);
3231 QMacCGContext cg(p);
3233 qCWarning(lcMacStyle) <<
"drawPrimitive:" << pe <<
"invalid (nullptr) graphics context";
3235 QWindow *window = w && w->window() ? w->window()->windowHandle() :
nullptr;
3236 d->resolveCurrentNSView(window);
3238 case PE_IndicatorArrowUp:
3239 case PE_IndicatorArrowDown:
3240 case PE_IndicatorArrowRight:
3241 case PE_IndicatorArrowLeft: {
3243 p->setRenderHint(QPainter::Antialiasing);
3244 const int xOffset = 1;
3245 qreal halfSize = 0.5 * qMin(opt->rect.width(), opt->rect.height());
3246 const qreal penWidth = qMax(halfSize / 3.0, 1.25);
3247#if QT_CONFIG(toolbutton)
3248 if (
const QToolButton *tb = qobject_cast<
const QToolButton *>(w)) {
3250 if (tb->arrowType() != Qt::NoArrow
3251 || tb->popupMode() == QToolButton::MenuButtonPopup)
3252 halfSize -= penWidth;
3256 QTransform transform;
3257 transform.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2);
3261 case PE_IndicatorArrowDown:
3263 case PE_IndicatorArrowUp:
3264 transform.rotate(180);
3266 case PE_IndicatorArrowLeft:
3267 transform.rotate(90);
3269 case PE_IndicatorArrowRight:
3270 transform.rotate(-90);
3273 p->setTransform(transform);
3275 path.moveTo(-halfSize, -halfSize * 0.5);
3276 path.lineTo(0.0, halfSize * 0.5);
3277 path.lineTo(halfSize, -halfSize * 0.5);
3279 const QPen arrowPen(opt->palette.text(), penWidth,
3280 Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
3281 p->strokePath(path, arrowPen);
3284#if QT_CONFIG(tabbar)
3285 case PE_FrameTabBarBase:
3286 if (
const QStyleOptionTabBarBase *tbb
3287 = qstyleoption_cast<
const QStyleOptionTabBarBase *>(opt)) {
3288 if (tbb->documentMode) {
3290 drawTabBase(p, tbb, w);
3294#if QT_CONFIG(tabwidget)
3295 QRegion region(tbb->rect);
3296 region -= tbb->tabBarRect.adjusted(3, 0, -3, 0);
3298 p->setClipRegion(region);
3299 QStyleOptionTabWidgetFrame twf;
3300 twf.QStyleOption::operator=(*tbb);
3301 twf.shape = tbb->shape;
3302 switch (QMacStylePrivate::tabDirection(twf.shape)) {
3303 case QMacStylePrivate::North:
3304 twf.rect = twf.rect.adjusted(0, 0, 0, 10);
3306 case QMacStylePrivate::South:
3307 twf.rect = twf.rect.adjusted(0, -10, 0, 0);
3309 case QMacStylePrivate::West:
3310 twf.rect = twf.rect.adjusted(0, 0, 10, 0);
3312 case QMacStylePrivate::East:
3313 twf.rect = twf.rect.adjusted(0, -10, 0, 0);
3316 proxy()->drawPrimitive(PE_FrameTabWidget, &twf, p, w);
3322 case PE_PanelTipLabel:
3323 p->fillRect(opt->rect, opt->palette.brush(QPalette::ToolTipBase));
3325 case PE_FrameGroupBox:
3326 if (
const auto *groupBox = qstyleoption_cast<
const QStyleOptionFrame *>(opt))
3327 if (groupBox->features & QStyleOptionFrame::Flat) {
3328 QCommonStyle::drawPrimitive(pe, groupBox, p, w);
3331#if QT_CONFIG(tabwidget)
3333 case PE_FrameTabWidget:
3336 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Box, QStyleHelper::SizeLarge);
3337 auto *box =
static_cast<NSBox *>(d->cocoaControl(cw));
3351 auto adjustedRect = opt->rect;
3352 bool needTranslation =
false;
3354 if (!qt_apple_runningWithLiquidGlass() && !
isDarkMode()) {
3367 adjustedRect.adjust(0, 0, 6, 6);
3368 needTranslation =
true;
3370 d->drawNSViewInRect(box, adjustedRect, p, ^(CGContextRef ctx,
const CGRect &rect) {
3371#if QT_CONFIG(tabwidget)
3372 if (qobject_cast<QTabWidget *>(opt->styleObject))
3373 clipTabBarFrame(opt,
this, ctx);
3375 CGContextTranslateCTM(ctx, 0, rect.origin.y + rect.size.height);
3376 CGContextScaleCTM(ctx, 1, -1);
3377 if ([box isMemberOfClass:QDarkNSBox.
class]) {
3378 [box drawRect:rect];
3380 if (needTranslation)
3381 CGContextTranslateCTM(ctx, -3.0, 5.0);
3382 [box displayRectIgnoringOpacity:box.bounds inContext:NSGraphicsContext.currentContext];
3387 case PE_IndicatorToolBarSeparator: {
3389 if (opt->state & State_Horizontal) {
3390 int xpoint = opt->rect.center().x();
3391 path.moveTo(xpoint + 0.5, opt->rect.top() + 1);
3392 path.lineTo(xpoint + 0.5, opt->rect.bottom());
3394 int ypoint = opt->rect.center().y();
3395 path.moveTo(opt->rect.left() + 2 , ypoint + 0.5);
3396 path.lineTo(opt->rect.right() + 1, ypoint + 0.5);
3398 QPainterPathStroker theStroker;
3399 theStroker.setCapStyle(Qt::FlatCap);
3400 theStroker.setDashPattern(QVector<qreal>() << 1 << 2);
3401 path = theStroker.createStroke(path);
3402 const auto dark =
isDarkMode() ? opt->palette.dark().color().darker()
3403 : QColor(0, 0, 0, 119);
3404 p->fillPath(path, dark);
3407 case PE_FrameWindow:
3408 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
3409 if (qobject_cast<
const QMdiSubWindow*>(w)) {
3411 p->setPen(QPen(frame->palette.dark().color(), frame->lineWidth));
3412 p->setBrush(frame->palette.window());
3413 p->drawRect(frame->rect);
3418 case PE_IndicatorDockWidgetResizeHandle: {
3421 if (opt->state & State_Horizontal) {
3422 p->setPen(QColor(160, 160, 160));
3423 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3425 p->setPen(QColor(145, 145, 145));
3426 p->drawLine(opt->rect.topRight(), opt->rect.bottomRight());
3430 case PE_IndicatorToolBarHandle: {
3433 int x = opt->rect.x() + 6;
3434 int y = opt->rect.y() + 7;
3435 static const int RectHeight = 2;
3436 if (opt->state & State_Horizontal) {
3437 while (y < opt->rect.height() - RectHeight - 5) {
3439 path.addEllipse(x, y, RectHeight, RectHeight);
3443 while (x < opt->rect.width() - RectHeight - 5) {
3445 path.addEllipse(x, y, RectHeight, RectHeight);
3449 p->setPen(Qt::NoPen);
3450 QColor dark = opt->palette.dark().color().darker();
3451 dark.setAlphaF(0.50);
3452 p->fillPath(path, dark);
3457 case PE_IndicatorHeaderArrow:
3458 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
3460 if (header->sortIndicator != QStyleOptionHeader::None)
3461 proxy()->drawPrimitive(
3462 (header->sortIndicator == QStyleOptionHeader::SortDown) ?
3463 PE_IndicatorArrowUp : PE_IndicatorArrowDown, header, p, w);
3466 case PE_IndicatorMenuCheckMark: {
3470 if (opt->state & State_On)
3471 pc = opt->palette.highlightedText().color();
3473 pc = opt->palette.text().color();
3475 QCFType<CGColorRef> checkmarkColor = CGColorCreateGenericRGB(
static_cast<CGFloat>(pc.redF()),
3476 static_cast<CGFloat>(pc.greenF()),
3477 static_cast<CGFloat>(pc.blueF()),
3478 static_cast<CGFloat>(pc.alphaF()));
3484 const CTFontUIFontType fontType = (opt->state & State_Mini) ? kCTFontUIFontMiniSystem :
3485 (opt->state & State_Small) ? kCTFontUIFontSmallSystem :
3486 kCTFontUIFontMenuItemMark;
3490 const CGFloat fontSize = fontType == kCTFontUIFontMenuItemMark ? opt->fontMetrics.height() : 0.0;
3491 QCFType<CTFontRef> checkmarkFont = CTFontCreateUIFontForLanguage(fontType, fontSize, NULL);
3493 CGContextSaveGState(cg);
3494 CGContextSetShouldSmoothFonts(cg, NO);
3497 const CGFloat vOffset = (opt->state & State_Mini) ? 0.0 :
3498 (opt->state & State_Small) ? 1.0 :
3501 CGContextTranslateCTM(cg, 0, opt->rect.bottom());
3502 CGContextScaleCTM(cg, 1, -1);
3504 CGContextTranslateCTM(cg, opt->rect.x(), vOffset);
3508 static const CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName };
3509 static const int numValues =
sizeof(keys) /
sizeof(keys[0]);
3510 const CFTypeRef values[] = { (CFTypeRef)checkmarkFont, (CFTypeRef)checkmarkColor };
3511 static_assert((
sizeof(values) /
sizeof(values[0])) == numValues);
3512 QCFType<CFDictionaryRef> attributes = CFDictionaryCreate(kCFAllocatorDefault, (
const void **)keys, (
const void **)values,
3513 numValues, NULL, NULL);
3515 QCFType<CFAttributedStringRef> checkmarkString = CFAttributedStringCreate(kCFAllocatorDefault, (CFStringRef)@
"\u2713", attributes);
3516 QCFType<CTLineRef> line = CTLineCreateWithAttributedString(checkmarkString);
3518 CTLineDraw((CTLineRef)line, cg);
3521 CGContextRestoreGState(cg);
3523 case PE_IndicatorItemViewItemCheck:
3524 case PE_IndicatorRadioButton:
3525 case PE_IndicatorCheckBox: {
3526 const bool isEnabled = opt->state & State_Enabled;
3527 const bool isPressed = opt->state & State_Sunken;
3528 const bool isRadioButton = (pe == PE_IndicatorRadioButton);
3529 const auto ct = isRadioButton ? QMacStylePrivate::Button_RadioButton : QMacStylePrivate::Button_CheckBox;
3530 const auto cs = d->effectiveAquaSizeConstrain(opt, w);
3531 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
3532 auto *tb =
static_cast<NSButton *>(d->cocoaControl(cw));
3533 tb.enabled = isEnabled;
3534 tb.state = (opt->state & State_NoChange) ? NSControlStateValueMixed :
3535 (opt->state & State_On) ? NSControlStateValueOn : NSControlStateValueOff;
3536 [tb highlight:isPressed];
3537 const auto vOffset = [=] {
3539 if (cs == QStyleHelper::SizeMini)
3540 return ct == QMacStylePrivate::Button_CheckBox ? -0.5 : 0.5;
3542 return cs == QStyleHelper::SizeSmall ? 0.5 : 0.0;
3544 d->drawNSViewInRect(tb, opt->rect, p, ^(CGContextRef ctx,
const CGRect &rect) {
3545 CGContextTranslateCTM(ctx, rect.origin.x, rect.origin.y + vOffset);
3546 [tb.cell drawInteriorWithFrame:tb.bounds inView:tb];
3549 case PE_FrameFocusRect:
3552 case PE_IndicatorBranch: {
3553 if (!(opt->state & State_Children))
3557 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Button_Disclosure, QStyleHelper::SizeLarge);
3558 NSButtonCell *triangleCell =
static_cast<NSButtonCell *>(d->cocoaCell(cw));
3559 [triangleCell setState:(opt->state & State_Open) ? NSControlStateValueOn : NSControlStateValueOff];
3560 bool viewHasFocus = (w && w->hasFocus()) || (opt->state & State_HasFocus);
3561 [triangleCell setBackgroundStyle:((opt->state & State_Selected) && viewHasFocus) ? NSBackgroundStyleEmphasized : NSBackgroundStyleNormal];
3562 [triangleCell setUserInterfaceLayoutDirection:qt_macLayoutDirectionFromQt(opt->direction)];
3564 d->setupNSGraphicsContext(cg, NO);
3567 CGRect rect = CGRectMake(qtRect.x() + 1, qtRect.y(), qtRect.width(), qtRect.height());
3568 CGContextTranslateCTM(cg, rect.origin.x, rect.origin.y + rect.size.height);
3569 CGContextScaleCTM(cg, 1, -1);
3570 CGContextTranslateCTM(cg, -rect.origin.x, -rect.origin.y);
3572 [triangleCell drawBezelWithFrame:NSRectFromCGRect(rect) inView:[triangleCell controlView]];
3574 d->restoreNSGraphicsContext(cg);
3578 QPen oldPen = p->pen();
3579 p->setPen(opt->palette.base().color().darker(140));
3580 p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
3581 p->setPen(opt->palette.base().color().darker(180));
3582 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3586 case PE_FrameLineEdit:
3587 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
3588 if (frame->state & State_Sunken) {
3589 const bool isEnabled = opt->state & State_Enabled;
3590 const bool isReadOnly = opt->state & State_ReadOnly;
3591 const bool isRounded = frame->features & QStyleOptionFrame::Rounded;
3592 const auto cs = d->effectiveAquaSizeConstrain(opt, w, CT_LineEdit);
3593 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::TextField, cs);
3594 auto *tf =
static_cast<NSTextField *>(d->cocoaControl(cw));
3595 tf.enabled = isEnabled;
3596 tf.editable = !isReadOnly;
3597 const QColor bgColor = frame->palette.brush(QPalette::Base).color();
3598 const bool hasCustomBackground = hasCustomTextFieldBackground(frame->palette);
3600 static_cast<NSTextFieldCell *>(tf.cell).bezelStyle = isRounded ? NSTextFieldRoundedBezel : NSTextFieldSquareBezel;
3601 tf.frame = opt->rect.toCGRect();
3602 d->drawNSViewInRect(tf, opt->rect, p, ^(CGContextRef,
const CGRect &rect) {
3603 if (!isDarkMode() && !hasCustomBackground) {
3610 CGContextRef cgContext = NSGraphicsContext.currentContext.CGContext;
3614 if (cgContext ?
bool(CGBitmapContextGetColorSpace(cgContext)) :
false) {
3615 tf.drawsBackground = YES;
3616 tf.backgroundColor = [NSColor colorWithSRGBRed:bgColor.redF()
3617 green:bgColor.greenF()
3618 blue:bgColor.blueF()
3619 alpha:bgColor.alphaF()];
3620 if (bgColor.alpha() != 255) {
3627 CGRect fixedRect = rect;
3628 if (qt_apple_runningWithLiquidGlass() && tf.bezeled) {
3634 fixedRect = CGRectInset(rect, 1., 1.);
3636 [tf.cell drawWithFrame:fixedRect inView:tf];
3638 if (hasCustomBackground)
3639 drawTextFieldCustomBackground(p, opt->rect, bgColor);
3641 QCommonStyle::drawPrimitive(pe, opt, p, w);
3645 case PE_PanelLineEdit:
3647 const QStyleOptionFrame *panel = qstyleoption_cast<
const QStyleOptionFrame *>(opt);
3650 const bool hasCustomBackground = panel && hasCustomTextFieldBackground(panel->palette);
3651 if ((panel && panel->lineWidth <= 0) || (
isDarkMode() && !hasCustomBackground)) {
3657 QCommonStyle::drawPrimitive(pe, opt, p, w);
3662 drawPrimitive(PE_FrameLineEdit, opt, p, w);
3668#if QT_CONFIG(lineedit)
3669 if ((opt->state & State_HasFocus) && !qobject_cast<
const QLineEdit*>(w)) {
3670 int vmargin = pixelMetric(QStyle::PM_FocusFrameVMargin);
3671 int hmargin = pixelMetric(QStyle::PM_FocusFrameHMargin);
3672 QStyleOptionFrame focusFrame = *panel;
3673 focusFrame.rect = panel->rect.adjusted(-hmargin, -vmargin, hmargin, vmargin);
3674 drawControl(CE_FocusFrame, &focusFrame, p, w);
3680 case PE_PanelScrollAreaCorner: {
3681 const QBrush brush(opt->palette.brush(QPalette::Base));
3682 p->fillRect(opt->rect, brush);
3683 p->setPen(QPen(QColor(217, 217, 217)));
3684 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3685 p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
3687 case PE_FrameStatusBarItem:
3689#if QT_CONFIG(tabbar)
3690 case PE_IndicatorTabClose: {
3692 QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget());
3693 const QWidget *closeBtn = w;
3697 tabBar = qobject_cast<QTabBar *>(
const_cast<QWidget*>(w));
3698 closeBtn =
decltype(closeBtn)(property(
"_q_styleSheetRealCloseButton").value<
void *>());
3701 const bool documentMode = tabBar->documentMode();
3702 const QTabBarPrivate *tabBarPrivate =
static_cast<QTabBarPrivate *>(QObjectPrivate::get(tabBar));
3703 const int hoveredTabIndex = tabBarPrivate->hoveredTabIndex();
3704 if (!documentMode ||
3705 (hoveredTabIndex != -1 && ((closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) ||
3706 (closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide))))) {
3707 const bool hover = (opt->state & State_MouseOver);
3708 const bool selected = (opt->state & State_Selected);
3709 const bool pressed = (opt->state & State_Sunken);
3710 drawTabCloseButton(p, hover, selected, pressed, documentMode);
3715 case PE_PanelStatusBar: {
3716 p->fillRect(opt->rect, opt->palette.window());
3719 if (w ? qt_macWindowMainWindow(w->window()) : (opt->state & QStyle::State_Active))
3720 p->setPen(titlebarSeparatorLineActive);
3722 p->setPen(titlebarSeparatorLineInactive);
3723 p->drawLine(opt->rect.left(), opt->rect.top(), opt->rect.right(), opt->rect.top());
3727 case PE_PanelMenu: {
3729 p->fillRect(opt->rect, Qt::transparent);
3730 p->setPen(Qt::transparent);
3731 p->setBrush(opt->palette.window());
3732 p->setRenderHint(QPainter::Antialiasing,
true);
3733 const QPainterPath path = d->windowPanelPath(opt->rect);
3739 QCommonStyle::drawPrimitive(pe, opt, p, w);
3780 const QWidget *w)
const
3782 Q_D(
const QMacStyle);
3783 const QMacAutoReleasePool pool;
3784 QMacCGContext cg(p);
3786 qCWarning(lcMacStyle) <<
"drawControl:" << ce <<
"invalid (nullptr) graphics context";
3788 QWindow *window = w && w->window() ? w->window()->windowHandle() :
nullptr;
3789 d->resolveCurrentNSView(window);
3791 case CE_HeaderSection:
3792 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
3793 State flags = header->state;
3794 QRect ir = header->rect;
3798 bool noVerticalHeader =
true;
3799#if QT_CONFIG(tableview)
3801 if (
const QTableView *table = qobject_cast<
const QTableView *>(w->parentWidget()))
3802 noVerticalHeader = !table->verticalHeader()->isVisible();
3805 const bool drawLeftBorder = header->orientation == Qt::Vertical
3806 || header->position == QStyleOptionHeader::OnlyOneSection
3807 || (header->position == QStyleOptionHeader::Beginning && noVerticalHeader);
3810 const bool pressed = (flags & State_Sunken) && !(flags & State_On);
3811 p->fillRect(ir, pressed ? header->palette.dark() : header->palette.button());
3812 p->setPen(QPen(header->palette.dark(), 1.0));
3813 if (header->orientation == Qt::Horizontal)
3822 case CE_ToolButtonLabel:
3823 if (
const QStyleOptionToolButton *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
3824 QStyleOptionToolButton myTb = *tb;
3825 myTb.state &= ~State_AutoRaise;
3826#if QT_CONFIG(accessibility)
3827 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) {
3828 QRect cr = tb->rect;
3831 bool needText =
false;
3833 bool down = tb->state & (State_Sunken | State_On);
3835 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, w);
3836 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, tb, w);
3842 if (!(tb->features & QStyleOptionToolButton::Arrow)) {
3843 Qt::ToolButtonStyle tbstyle = tb->toolButtonStyle;
3844 if (tb->icon.isNull() && !tb->text.isEmpty())
3845 tbstyle = Qt::ToolButtonTextOnly;
3848 case Qt::ToolButtonTextOnly: {
3850 alignment = Qt::AlignCenter;
3852 case Qt::ToolButtonIconOnly:
3853 case Qt::ToolButtonTextBesideIcon:
3854 case Qt::ToolButtonTextUnderIcon: {
3856 QIcon::Mode iconMode = (tb->state & State_Enabled) ? QIcon::Normal
3858 QIcon::State iconState = (tb->state & State_On) ? QIcon::On
3860 QPixmap pixmap = tb->icon.pixmap(tb->rect.size().boundedTo(tb->iconSize), p->device()->devicePixelRatio(),
3861 iconMode, iconState);
3864 if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) {
3866 QSizeF size = pixmap.deviceIndependentSize();
3867 if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
3868 pr.setHeight(size.height() + 6);
3869 cr.adjust(0, pr.bottom(), 0, -3);
3870 alignment |= Qt::AlignCenter;
3872 pr.setWidth(size.width() + 8);
3873 cr.adjust(pr.right(), 0, 0, 0);
3874 alignment |= Qt::AlignLeft | Qt::AlignVCenter;
3877 if (opt->state & State_Sunken) {
3878 pr.translate(shiftX, shiftY);
3879 pixmap = darkenPixmap(pixmap);
3881 proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pixmap);
3889 QPalette pal = tb->palette;
3890 QPalette::ColorRole role = QPalette::NoRole;
3891 if (!proxy()->styleHint(SH_UnderlineShortcut, tb, w))
3892 alignment |= Qt::TextHideMnemonic;
3894 cr.translate(shiftX, shiftY);
3895 if (tbstyle == Qt::ToolButtonTextOnly
3896 || (tbstyle != Qt::ToolButtonTextOnly && !down)) {
3897 QPen pen = p->pen();
3898 QColor light = down || isDarkMode() ? Qt::black : Qt::white;
3899 light.setAlphaF(0.375f);
3901 p->drawText(cr.adjusted(0, 1, 0, 1), alignment, tb->text);
3903 if (down && tbstyle == Qt::ToolButtonTextOnly) {
3904 pal = QApplication::palette(
"QMenu");
3905 pal.setCurrentColorGroup(tb->palette.currentColorGroup());
3906 role = QPalette::HighlightedText;
3909 proxy()->drawItemText(p, cr, alignment, pal,
3910 tb->state & State_Enabled, tb->text, role);
3913 QCommonStyle::drawControl(ce, &myTb, p, w);
3918 QCommonStyle::drawControl(ce, &myTb, p, w);
3922 case CE_ToolBoxTabShape:
3923 QCommonStyle::drawControl(ce, opt, p, w);
3925 case CE_PushButtonBevel:
3926 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
3927 if (!(btn->state & (State_Raised | State_Sunken | State_On)))
3930 if (btn->features & QStyleOptionButton::CommandLinkButton) {
3931 QCommonStyle::drawControl(ce, opt, p, w);
3935 const bool hasFocus = btn->state & State_HasFocus;
3936 const bool isActive = btn->state & State_Active;
3940 if ((btn->features & QStyleOptionButton::AutoDefaultButton)
3941 && isActive && hasFocus)
3942 d->autoDefaultButton = btn->styleObject;
3943 else if (d->autoDefaultButton == btn->styleObject)
3944 d->autoDefaultButton =
nullptr;
3946 const bool isEnabled = btn->state & State_Enabled;
3947 const bool isPressed = btn->state & State_Sunken;
3948 const bool isHighlighted = isActive &&
3949 ((btn->state & State_On)
3950 || (btn->features & QStyleOptionButton::DefaultButton)
3951 || (btn->features & QStyleOptionButton::AutoDefaultButton
3952 && d->autoDefaultButton == btn->styleObject));
3953 const bool hasMenu = btn->features & QStyleOptionButton::HasMenu;
3954 const auto ct = cocoaControlType(btn, w);
3955 const auto cs = d->effectiveAquaSizeConstrain(btn, w);
3956 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
3957 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
3961 const QRectF frameRect = cw.adjustedControlFrame(btn->rect);
3962 pb.frame = frameRect.toCGRect();
3964 pb.enabled = isEnabled;
3969 [pb highlight:isPressed];
3972 if (cw.type == QMacStylePrivate::Button_SquareButton) {
3973 pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff;
3977 pb.keyEquivalent = isHighlighted ? @
"\r" : @
"";
3980 d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
3981 [pb.cell drawBezelWithFrame:r inView:pb.superview];
3985 if (hasMenu && cw.type == QMacStylePrivate::Button_SquareButton) {
3988 const int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w);
3989 const auto ir = frameRect.toRect();
3990 int arrowYOffset = 0;
3995 arrowYOffset -= ir.top();
3996 if (cw.second == QStyleHelper::SizeSmall)
4000 const auto ar = visualRect(btn->direction, ir, QRect(ir.right() - mbi - 6, ir.height() / 2 - arrowYOffset, mbi, mbi));
4002 QStyleOption arrowOpt = *opt;
4004 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, w);
4008 case CE_PushButtonLabel:
4009 if (
const QStyleOptionButton *b = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
4010 QStyleOptionButton btn(*b);
4015 const bool isEnabled = btn.state & State_Enabled;
4016 const bool hasMenu = btn.features & QStyleOptionButton::HasMenu;
4017 const bool hasIcon = !btn.icon.isNull();
4018 const bool hasText = !btn.text.isEmpty();
4019 const bool isActive = btn.state & State_Active;
4020 const bool isPressed = btn.state & State_Sunken;
4021 const bool isDefault = (btn.features & QStyleOptionButton::DefaultButton && !d->autoDefaultButton)
4022 || d->autoDefaultButton == btn.styleObject;
4026 const QRect oldRect = btn.rect;
4028 btn.rect = w->rect();
4029 const auto ct = cocoaControlType(&btn, w);
4032 if (!hasMenu && ct != QMacStylePrivate::Button_SquareButton) {
4033 if (isPressed || (isActive && isEnabled && ((btn.state & State_On) || isDefault)))
4034 btn.palette.setColor(QPalette::ButtonText, Qt::white);
4038 if (!isDefault && !(btn.state & State_On)) {
4041 btn.palette.setColor(QPalette::ButtonText, Qt::black);
4045 if ((!hasIcon && !hasMenu) || (hasIcon && !hasText)) {
4046 QCommonStyle::drawControl(ce, &btn, p, w);
4048 QRect freeContentRect = btn.rect;
4049 QRect textRect = itemTextRect(
4050 btn.fontMetrics, freeContentRect, Qt::AlignCenter, isEnabled, btn.text);
4052 if (ct == QMacStylePrivate::Button_SquareButton)
4053 textRect.moveTo(w ? 8 : 11, textRect.top());
4055 textRect.moveTo(w ? (15 - pushButtonBevelRectOffsets[d->effectiveAquaSizeConstrain(b, w)])
4056 : 11, textRect.top());
4060 int contentW = textRect.width();
4062 contentW += proxy()->pixelMetric(PM_MenuButtonIndicator) + 4;
4063 QIcon::Mode mode = isEnabled ? QIcon::Normal : QIcon::Disabled;
4064 if (mode == QIcon::Normal && btn.state & State_HasFocus)
4065 mode = QIcon::Active;
4067 QIcon::State state = QIcon::Off;
4068 if (btn.state & State_On)
4070 QPixmap pixmap = btn.icon.pixmap(btn.iconSize, p->device()->devicePixelRatio(), mode, state);
4071 QSizeF pixmapSize = pixmap.deviceIndependentSize();
4072 contentW += pixmapSize.width() + QMacStylePrivate::PushButtonContentPadding;
4073 int iconLeftOffset = freeContentRect.x() + (freeContentRect.width() - contentW) / 2;
4074 int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmapSize.height()) / 2;
4075 QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmapSize.width(), pixmapSize.height());
4076 QRect visualIconDestRect = visualRect(btn.direction, freeContentRect, iconDestRect);
4077 proxy()->drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap);
4078 int newOffset = iconDestRect.x() + iconDestRect.width()
4079 + QMacStylePrivate::PushButtonContentPadding - textRect.x();
4080 textRect.adjust(newOffset, 0, newOffset, 0);
4084 textRect = visualRect(btn.direction, freeContentRect, textRect);
4085 proxy()->drawItemText(p, textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, btn.palette,
4086 isEnabled, btn.text, QPalette::ButtonText);
4091#if QT_CONFIG(combobox)
4092 case CE_ComboBoxLabel:
4093 if (
const auto *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
4094 auto comboCopy = *cb;
4095 comboCopy.direction = Qt::LeftToRight;
4097 QCommonStyle::drawControl(CE_ComboBoxLabel, &comboCopy, p, w);
4101#if QT_CONFIG(tabbar)
4102 case CE_TabBarTabShape:
4103 if (
const auto *tabOpt = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
4104 if (tabOpt->documentMode) {
4106 bool isUnified =
false;
4108 QRect tabRect = tabOpt->rect;
4109 QPoint windowTabStart = w->mapTo(w->window(), tabRect.topLeft());
4110 isUnified = isInMacUnifiedToolbarArea(w->window(), windowTabStart.y());
4113 const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, opt, w);
4114 drawTabShape(p, tabOpt, isUnified, tabOverlap);
4143 const bool isActive = tabOpt->state & State_Active;
4144 const bool isEnabled = tabOpt->state & State_Enabled;
4145 const bool isPressed = tabOpt->state & State_Sunken;
4146 const bool isSelected = tabOpt->state & State_Selected;
4147 const auto tabDirection = QMacStylePrivate::tabDirection(tabOpt->shape);
4148 const bool verticalTabs = tabDirection == QMacStylePrivate::East
4149 || tabDirection == QMacStylePrivate::West;
4151 QStyleOptionTab::TabPosition tp = tabOpt->position;
4152 QStyleOptionTab::SelectedPosition sp = tabOpt->selectedPosition;
4153 if (tabOpt->direction == Qt::RightToLeft && !verticalTabs) {
4154 if (tp == QStyleOptionTab::Beginning)
4155 tp = QStyleOptionTab::End;
4156 else if (tp == QStyleOptionTab::End)
4157 tp = QStyleOptionTab::Beginning;
4159 if (sp == QStyleOptionTab::NextIsSelected)
4160 sp = QStyleOptionTab::PreviousIsSelected;
4161 else if (sp == QStyleOptionTab::PreviousIsSelected)
4162 sp = QStyleOptionTab::NextIsSelected;
4171 const auto cs = d->effectiveAquaSizeConstrain(opt, w);
4173 const bool needsInactiveHack = !isActive && isSelected;
4174 const auto ct = !needsInactiveHack && (isSelected || tp == QStyleOptionTab::OnlyOneTab) ?
4175 QMacStylePrivate::Button_PushButton :
4176 QMacStylePrivate::Button_PopupButton;
4177 const bool isPopupButton = ct == QMacStylePrivate::Button_PopupButton;
4178 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
4179 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
4182 if (tabDirection == QMacStylePrivate::East)
4184 const auto outerAdjust = isPopupButton ? 1 : 4;
4185 const auto innerAdjust = isPopupButton ? 20 : 10;
4186 QRectF frameRect = tabOpt->rect;
4188 frameRect = QRectF(frameRect.y(), frameRect.x(), frameRect.height(), frameRect.width());
4190 frameRect = frameRect.translated(0, vOffset);
4192 case QStyleOptionTab::Beginning:
4194 if (!isSelected && tabDirection == QMacStylePrivate::West)
4195 frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0);
4197 frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0);
4202 frameRect = frameRect.adjusted(0, 0, 1, 0);
4205 case QStyleOptionTab::Middle:
4206 frameRect = frameRect.adjusted(-innerAdjust, 0, innerAdjust, 0);
4211 frameRect = frameRect.adjusted(-1, 0, 1, 0);
4214 case QStyleOptionTab::Moving:
4215 case QStyleOptionTab::End:
4217 if (isSelected || tabDirection == QMacStylePrivate::West)
4218 frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0);
4220 frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0);
4224 frameRect = frameRect.adjusted(-1, 0, 0, 0);
4227 case QStyleOptionTab::OnlyOneTab:
4228 frameRect = frameRect.adjusted(-outerAdjust, 0, outerAdjust, 0);
4231 pb.frame = frameRect.toCGRect();
4233 if (!isPopupButton) {
4237 pb.buttonType = NSButtonTypePushOnPushOff;
4240 pb.enabled = isEnabled;
4241 [pb highlight:isPressed];
4243 pb.state = (isActive && isSelected) ? NSControlStateValueOn : NSControlStateValueOff;
4245 const auto drawBezelBlock = ^(CGContextRef ctx,
const CGRect &r) {
4246 CGContextClipToRect(ctx, opt->rect.toCGRect());
4247 if (!isSelected || needsInactiveHack) {
4249 if (!verticalTabs && tp == QStyleOptionTab::End) {
4250 CGContextTranslateCTM(ctx, opt->rect.right(), 0);
4251 CGContextScaleCTM(ctx, -1, 1);
4252 CGContextTranslateCTM(ctx, -frameRect.left(), 0);
4253 }
else if (tabDirection == QMacStylePrivate::West && tp == QStyleOptionTab::Beginning) {
4254 CGContextTranslateCTM(ctx, 0, opt->rect.top());
4255 CGContextScaleCTM(ctx, 1, -1);
4256 CGContextTranslateCTM(ctx, 0, -frameRect.right());
4257 }
else if (tabDirection == QMacStylePrivate::East && tp == QStyleOptionTab::End) {
4258 CGContextTranslateCTM(ctx, 0, opt->rect.bottom());
4259 CGContextScaleCTM(ctx, 1, -1);
4260 CGContextTranslateCTM(ctx, 0, -frameRect.left());
4266 if (tabDirection == QMacStylePrivate::West) {
4267 CGContextTranslateCTM(ctx, 0, frameRect.right());
4268 CGContextRotateCTM(ctx, -M_PI_2);
4269 CGContextTranslateCTM(ctx, -frameRect.left(), 0);
4270 }
else if (tabDirection == QMacStylePrivate::East) {
4271 CGContextTranslateCTM(ctx, opt->rect.right(), 0);
4272 CGContextRotateCTM(ctx, M_PI_2);
4277 NSPopUpArrowPosition oldPosition = NSPopUpArrowAtCenter;
4278 NSPopUpButtonCell *pbCell = nil;
4280 if (isPopupButton) {
4284 pbCell =
static_cast<NSPopUpButtonCell *>(pb.cell);
4285 oldPosition = pbCell.arrowPosition;
4286 pbCell.arrowPosition = NSPopUpNoArrow;
4287 if (pb.state == NSControlStateValueOff) {
4289 rAdjusted.origin.x -= 3;
4290 rAdjusted.size.width += 6;
4291 if (tp == QStyleOptionTab::End)
4292 rAdjusted.origin.x -= 2;
4295 if (qt_apple_runningWithLiquidGlass()) {
4304 const CGFloat deltaW = 20.0;
4305 rAdjusted = CGContextGetClipBoundingBox(ctx);
4306 if (tp == QStyleOptionTab::Beginning) {
4311 rAdjusted.size.width += deltaW;
4313 if (tabDirection == QMacStylePrivate::West && isSelected && isActive) {
4317 rAdjusted.origin.x -= deltaW;
4319 }
else if (tp == QStyleOptionTab::Middle) {
4321 rAdjusted.origin.x -= deltaW;
4322 rAdjusted.size.width += deltaW * 2;
4323 }
else if (tp == QStyleOptionTab::End) {
4324 if (isSelected && isActive && tabDirection != QMacStylePrivate::West)
4325 rAdjusted.origin.x -= deltaW;
4326 rAdjusted.size.width += deltaW;
4330 [pb.cell drawBezelWithFrame:rAdjusted inView:pb.superview];
4333 pbCell.arrowPosition = oldPosition;
4336 if (needsInactiveHack) {
4338 const qreal pixelRatio = p->device()->devicePixelRatio();
4339 QImage tabPixmap(opt->rect.size() * pixelRatio, QImage::Format_ARGB32_Premultiplied);
4340 tabPixmap.setDevicePixelRatio(pixelRatio);
4341 tabPixmap.fill(Qt::transparent);
4342 QPainter tabPainter(&tabPixmap);
4343 d->drawNSViewInRect(pb, frameRect, &tabPainter, ^(CGContextRef ctx,
const CGRect &r) {
4344 CGContextTranslateCTM(ctx, -opt->rect.left(), -opt->rect.top());
4345 drawBezelBlock(ctx, r);
4350 const qreal inactiveGray = 0.898;
4351 const int inactiveGray8 = qRound(inactiveGray * 255.0);
4352 const QRgb inactiveGrayRGB = qRgb(inactiveGray8, inactiveGray8, inactiveGray8);
4353 for (
int l = 0; l < tabPixmap.height(); ++l) {
4354 auto *line =
reinterpret_cast<QRgb*>(tabPixmap.scanLine(l));
4355 for (
int i = 0; i < tabPixmap.width(); ++i) {
4356 if (qAlpha(line[i]) == 255) {
4357 line[i] = inactiveGrayRGB;
4358 }
else if (qAlpha(line[i]) > 128) {
4359 const int g = qRound(inactiveGray * qRed(line[i]));
4360 line[i] = qRgba(g, g, g, qAlpha(line[i]));
4366 p->drawImage(opt->rect, tabPixmap);
4368 d->drawNSViewInRect(pb, frameRect, p, drawBezelBlock);
4371 if (!isSelected && sp != QStyleOptionTab::NextIsSelected
4372 && tp != QStyleOptionTab::End
4373 && tp != QStyleOptionTab::OnlyOneTab) {
4374 static const QPen separatorPen(Qt::black, 1.0);
4376 p->setOpacity(isEnabled ? 0.105 : 0.06);
4377 p->setPen(separatorPen);
4378 if (tabDirection == QMacStylePrivate::West) {
4379 p->drawLine(QLineF(opt->rect.left() + 1.5, opt->rect.bottom(),
4380 opt->rect.right() - 0.5, opt->rect.bottom()));
4381 }
else if (tabDirection == QMacStylePrivate::East) {
4382 p->drawLine(QLineF(opt->rect.left(), opt->rect.bottom(),
4383 opt->rect.right() - 0.5, opt->rect.bottom()));
4385 p->drawLine(QLineF(opt->rect.right(), opt->rect.top() + 1.0,
4386 opt->rect.right(), opt->rect.bottom() - 0.5));
4392 case CE_TabBarTabLabel:
4393 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
4394 QStyleOptionTab myTab = *tab;
4395 const auto foregroundRole = w ? w->foregroundRole() : QPalette::WindowText;
4396 const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape);
4397 const bool verticalTabs = tabDirection == QMacStylePrivate::East
4398 || tabDirection == QMacStylePrivate::West;
4404 const bool nonDefaultFont = p->font() != qt_app_fonts_hash()->value(
"QComboMenuItem");
4406 if (!myTab.documentMode && (myTab.state & State_Selected) && (myTab.state & State_Active))
4407 if (
const auto *tabBar = qobject_cast<
const QTabBar *>(w))
4408 if (!tabBar->tabTextColor(tabBar->currentIndex()).isValid())
4409 myTab.palette.setColor(foregroundRole, Qt::white);
4411 if (myTab.documentMode && isDarkMode()) {
4412 if (
const auto *tabBar = qobject_cast<
const QTabBar *>(w)) {
4413 if (!tabBar->tabTextColor(myTab.tabIndex).isValid()) {
4414 bool active = (myTab.state & State_Selected) && (myTab.state & State_Active);
4415 myTab.palette.setColor(foregroundRole, active ? Qt::white : Qt::gray);
4420 int heightOffset = 0;
4423 }
else if (nonDefaultFont) {
4424 if (p->fontMetrics().height() == myTab.rect.height())
4427 myTab.rect.setHeight(myTab.rect.height() + heightOffset);
4429 QCommonStyle::drawControl(ce, &myTab, p, w);
4433#if QT_CONFIG(dockwidget)
4434 case CE_DockWidgetTitle:
4435 if (
const auto *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(opt)) {
4436 const bool isVertical = dwOpt->verticalTitleBar;
4437 const auto effectiveRect = isVertical ? opt->rect.transposed() : opt->rect;
4440 p->translate(effectiveRect.left(), effectiveRect.top() + effectiveRect.width());
4442 p->translate(-effectiveRect.left(), -effectiveRect.top());
4446 p->fillRect(effectiveRect, opt->palette.window());
4449 p->setPen(opt->palette.dark().color());
4450 p->drawLine(effectiveRect.bottomLeft(), effectiveRect.bottomRight());
4452 if (!dwOpt->title.isEmpty()) {
4453 auto titleRect = proxy()->subElementRect(SE_DockWidgetTitleBarText, opt, w);
4455 titleRect = QRect(effectiveRect.left() + opt->rect.bottom() - titleRect.bottom(),
4456 effectiveRect.top() + titleRect.left() - opt->rect.left(),
4460 const auto text = p->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
4461 proxy()->drawItemText(p, titleRect, Qt::AlignCenter | Qt::TextHideMnemonic, dwOpt->palette,
4462 dwOpt->state & State_Enabled, text, QPalette::WindowText);
4468 case CE_FocusFrame: {
4469 const auto *ff = qobject_cast<
const QFocusFrame *>(w);
4470 const auto *ffw = ff ? ff->widget() :
nullptr;
4471 const auto ct = [=] {
4473 if (qobject_cast<
const QCheckBox*>(ffw))
4474 return QMacStylePrivate::Button_CheckBox;
4475 if (qobject_cast<
const QRadioButton*>(ffw))
4476 return QMacStylePrivate::Button_RadioButton;
4477 if (qobject_cast<
const QLineEdit*>(ffw) || qobject_cast<
const QTextEdit*>(ffw))
4478 return QMacStylePrivate::TextField;
4479 if (
const auto *pb = qobject_cast<
const QPushButton *>(ffw)) {
4481 auto sizePolicy = QStyleHelper::widgetSizePolicy(ffw, opt);
4482 if (sizePolicy == QStyleHelper::SizeDefault)
4483 sizePolicy = QStyleHelper::SizeLarge;
4485 || (pb->rect().height() != pushButtonDefaultHeight[sizePolicy])) {
4486 return QMacStylePrivate::Button_SquareButton;
4488 if (pb->menu() !=
nullptr)
4489 return QMacStylePrivate::Button_PullDown;
4490 return QMacStylePrivate::Button_PushButton;
4494 return QMacStylePrivate::Box;
4496 auto cs = QStyleHelper::widgetSizePolicy(ffw, opt);
4497 if (cs == QStyleHelper::SizeDefault)
4498 cs = QStyleHelper::SizeLarge;
4499 const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, w);
4500 const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, opt, w);
4501 d->drawFocusRing(p, opt->rect, hMargin, vMargin, QMacStylePrivate::CocoaControl(ct, cs));
4503 case CE_MenuEmptyArea:
4505 if (qobject_cast<
const QAbstractItemView *>(w))
4506 proxy()->drawPrimitive(PE_PanelMenu, opt, p, w);
4510 case CE_MenuHMargin:
4511 case CE_MenuVMargin:
4512 case CE_MenuTearoff:
4513 case CE_MenuScroller:
4514 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
4515 const bool active = mi->state & State_Selected;
4517 p->fillRect(mi->rect, mi->palette.highlight());
4519 const QStyleHelper::WidgetSizePolicy widgetSize = d->aquaSizeConstrain(opt, w);
4521 if (ce == CE_MenuTearoff) {
4522 p->setPen(QPen(mi->palette.dark().color(), 1, Qt::DashLine));
4523 p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2 - 1,
4524 mi->rect.x() + mi->rect.width() - 4,
4525 mi->rect.y() + mi->rect.height() / 2 - 1);
4526 p->setPen(QPen(mi->palette.light().color(), 1, Qt::DashLine));
4527 p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2,
4528 mi->rect.x() + mi->rect.width() - 4,
4529 mi->rect.y() + mi->rect.height() / 2);
4530 }
else if (ce == CE_MenuScroller) {
4531 const QSize scrollerSize = QSize(10, 8);
4532 const int scrollerVOffset = 5;
4533 const int left = mi->rect.x() + (mi->rect.width() - scrollerSize.width()) / 2;
4534 const int right = left + scrollerSize.width();
4537 if (opt->state & State_DownArrow) {
4538 bottom = mi->rect.y() + scrollerVOffset;
4539 top = bottom + scrollerSize.height();
4541 bottom = mi->rect.bottom() - scrollerVOffset;
4542 top = bottom - scrollerSize.height();
4545 p->setRenderHint(QPainter::Antialiasing);
4547 path.moveTo(left, bottom);
4548 path.lineTo(right, bottom);
4549 path.lineTo((left + right) / 2, top);
4550 p->fillPath(path, opt->palette.buttonText());
4552 }
else if (ce != CE_MenuItem) {
4556 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
4557 CGColorRef separatorColor = [NSColor quaternaryLabelColor].CGColor;
4558 const QRect separatorRect = QRect(mi->rect.left(), mi->rect.center().y(), mi->rect.width(), 2);
4559 p->fillRect(separatorRect, qt_mac_toQColor(separatorColor));
4563 const int maxpmw = mi->maxIconWidth;
4564 const bool enabled = mi->state & State_Enabled;
4566 int xpos = mi->rect.x() + 18;
4567 int checkcol = maxpmw;
4569 p->setPen(mi->palette.text().color());
4571 p->setPen(mi->palette.highlightedText().color());
4573 p->setPen(mi->palette.buttonText().color());
4576 QStyleOption checkmarkOpt;
4577 checkmarkOpt.initFrom(w);
4582 checkmarkOpt.rect = QRect(xp, mi->rect.y() - checkmarkOpt.fontMetrics.descent(), mw, mh);
4584 checkmarkOpt.state.setFlag(State_On, active);
4585 checkmarkOpt.state.setFlag(State_Enabled, enabled);
4586 if (widgetSize == QStyleHelper::SizeMini)
4587 checkmarkOpt.state |= State_Mini;
4588 else if (widgetSize == QStyleHelper::SizeSmall)
4589 checkmarkOpt.state |= State_Small;
4592 checkmarkOpt.palette.setColor(QPalette::HighlightedText, p->pen().color());
4593 checkmarkOpt.palette.setColor(QPalette::Text, p->pen().color());
4595 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &checkmarkOpt, p, w);
4597 if (!mi->icon.isNull()) {
4598 QIcon::Mode mode = (mi->state & State_Enabled) ? QIcon::Normal
4601 int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize);
4602 QSize iconSize(smallIconSize, smallIconSize);
4603#if QT_CONFIG(combobox)
4604 if (
const QComboBox *comboBox = qobject_cast<
const QComboBox *>(w)) {
4605 iconSize = comboBox->iconSize();
4608 QPixmap pixmap = mi->icon.pixmap(iconSize, p->device()->devicePixelRatio(), mode);
4609 QRect cr(xpos, mi->rect.y(), checkcol, mi->rect.height());
4610 QSize size = pixmap.deviceIndependentSize().toSize();
4611 QRect pmr(QPoint(0, 0), size);
4612 pmr.moveCenter(cr.center());
4613 p->drawPixmap(pmr.topLeft(), pixmap);
4614 xpos += size.width() + 6;
4617 QString s = mi->text;
4618 const auto text_flags = Qt::AlignVCenter | Qt::TextHideMnemonic
4619 | Qt::TextSingleLine | Qt::AlignAbsolute;
4620 int yPos = mi->rect.y();
4621 if (widgetSize == QStyleHelper::SizeMini)
4624 const bool isSubMenu = mi->menuItemType == QStyleOptionMenuItem::SubMenu;
4625 const int tabwidth = isSubMenu ? 9 : mi->reservedShortcutWidth;
4627 QString rightMarginText;
4629 rightMarginText = QStringLiteral(
"\u25b6\ufe0e");
4632 const int tabIndex = s.indexOf(QLatin1Char(
'\t'));
4633 if (tabIndex >= 0) {
4635 rightMarginText = s.mid(tabIndex + 1);
4636 s = s.left(tabIndex);
4640 if (!rightMarginText.isEmpty()) {
4641 p->setFont(qt_app_fonts_hash()->value(
"QMenuItem", p->font()));
4644 p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags | Qt::AlignRight, rightMarginText);
4648 const QKeySequence seq = QKeySequence::fromString(rightMarginText, QKeySequence::NativeText);
4649 if (seq.count() == 1) {
4651 const int maxKeyWidth = p->fontMetrics().maxWidth();
4652 const QChar key = rightMarginText.at(rightMarginText.length() - 1);
4653 const QString modifiers = rightMarginText.left(rightMarginText.size() - 1);
4654 p->drawText(xp + tabwidth - maxKeyWidth, yPos, maxKeyWidth, mi->rect.height(), text_flags, key);
4656 p->drawText(xp, yPos, tabwidth - maxKeyWidth, mi->rect.height(),
4657 text_flags | Qt::AlignRight | Qt::TextDontClip, modifiers);
4659 p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags, rightMarginText);
4666 QFont myFont = mi->font;
4672 myFont.setPointSizeF(QFontInfo(mi->font).pointSizeF());
4677 const auto *fontEngine = QFontPrivate::get(myFont)->engineForScript(QChar::Script_Common);
4678 Q_ASSERT(fontEngine);
4679 if (fontEngine->type() == QFontEngine::Multi) {
4680 fontEngine =
static_cast<
const QFontEngineMulti *>(fontEngine)->engine(0);
4681 Q_ASSERT(fontEngine);
4683 if (fontEngine->type() == QFontEngine::Mac) {
4684 NSFont *f = (NSFont *)(CTFontRef)fontEngine->handle();
4687 const auto pc = p->pen().color();
4688 NSColor *c = [NSColor colorWithSRGBRed:pc.redF()
4693 s = qt_mac_removeMnemonics(s);
4695 QMacCGContext cgCtx(p);
4696 d->setupNSGraphicsContext(cgCtx, YES);
4702 [s.toNSString() drawAtPoint:CGPointMake(xpos, yPos)
4703 withAttributes:@{ NSFontAttributeName:f, NSForegroundColorAttributeName:c,
4704 NSObliquenessAttributeName: [NSNumber numberWithDouble: myFont.italic() ? 0.3 : 0.0],
4705 NSUnderlineStyleAttributeName: [NSNumber numberWithInt: myFont.underline() ? NSUnderlineStyleSingle
4706 : NSUnderlineStyleNone],
4707 NSStrikethroughStyleAttributeName: [NSNumber numberWithInt: myFont.strikeOut() ? NSUnderlineStyleSingle
4708 : NSUnderlineStyleNone]}];
4710 d->restoreNSGraphicsContext(cgCtx);
4713 p->drawText(xpos, yPos, mi->rect.width() - xm - tabwidth + 1,
4714 mi->rect.height(), text_flags, s);
4720 case CE_MenuBarItem:
4721 case CE_MenuBarEmptyArea:
4722 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
4723 const bool selected = (opt->state & State_Selected) && (opt->state & State_Enabled) && (opt->state & State_Sunken);
4724 const QBrush bg = selected ? mi->palette.highlight() : mi->palette.window();
4725 p->fillRect(mi->rect, bg);
4727 if (ce != CE_MenuBarItem)
4730 if (!mi->icon.isNull()) {
4731 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
4732 drawItemPixmap(p, mi->rect,
4733 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip
4734 | Qt::TextSingleLine,
4735 mi->icon.pixmap(QSize(iconExtent, iconExtent), p->device()->devicePixelRatio(),
4736 (mi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled));
4738 drawItemText(p, mi->rect,
4739 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip
4740 | Qt::TextSingleLine,
4741 mi->palette, mi->state & State_Enabled,
4742 mi->text, selected ? QPalette::HighlightedText : QPalette::ButtonText);
4746 case CE_ProgressBarLabel:
4747 case CE_ProgressBarGroove:
4750 case CE_ProgressBarContents:
4751 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
4752 const bool isIndeterminate = (pb->minimum == 0 && pb->maximum == 0);
4753 const bool vertical = !(pb->state & QStyle::State_Horizontal);
4754 const bool inverted = pb->invertedAppearance;
4755 bool reverse = (!vertical && (pb->direction == Qt::RightToLeft));
4758 QRect rect = pb->rect;
4760 const auto aquaSize = d->effectiveAquaSizeConstrain(opt, w);
4761 const QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject));
4762 if (isIndeterminate) {
4770 if (!animation && opt->styleObject) {
4771 auto *animation =
new QProgressStyleAnimation(d->animateSpeed(QMacStylePrivate::AquaProgressBar), opt->styleObject);
4773 animation->setFrameRate(QStyleAnimation::FifteenFps);
4774 d->startAnimation(animation);
4777 if (qt_apple_runningWithLiquidGlass()) {
4778 d->drawProgressBar(p, pb);
4781 rect = rect.transposed();
4782 d->setupNSGraphicsContext(cg, NO);
4783 d->setupVerticalInvertedXform(cg, reverse, vertical, rect.toCGRect());
4785 =
static_cast<QIndeterminateProgressIndicator *>(
4786 d->cocoaControl({ QMacStylePrivate::ProgressIndicator_Indeterminate, aquaSize }))) {
4787 [ipi startAnimation];
4788 [ipi drawWithFrame:rect.toCGRect() inView:d->backingStoreNSView];
4790 d->restoreNSGraphicsContext(cg);
4794 d->stopAnimation(opt->styleObject);
4796 =
static_cast<QIndeterminateProgressIndicator *>(
4797 d->cocoaControl({ QMacStylePrivate::ProgressIndicator_Indeterminate, aquaSize })))
4798 [ipi stopAnimation];
4800 if (qt_apple_runningWithLiquidGlass()) {
4801 d->drawProgressBar(p, pb);
4804 rect = rect.transposed();
4805 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::ProgressIndicator_Determinate, aquaSize);
4806 auto *pi =
static_cast<NSProgressIndicator *>(d->cocoaControl(cw));
4807 d->drawNSViewInRect(pi, rect, p, ^(CGContextRef ctx,
const CGRect &cgrect) {
4808 d->setupVerticalInvertedXform(ctx, reverse, vertical, cgrect);
4809 pi.minValue = pb->minimum;
4810 pi.maxValue = pb->maximum;
4811 pi.doubleValue = pb->progress;
4812 [pi drawRect:cgrect]; });
4819#ifndef QT_NO_MDIAREA
4820 if (!w || !qobject_cast<QMdiSubWindow *>(w->parentWidget()))
4824 if (w->testAttribute(Qt::WA_MacOpaqueSizeGrip))
4825 p->fillRect(opt->rect, opt->palette.window());
4827 QPen lineColor = QColor(82, 82, 82, 192);
4828 lineColor.setWidth(1);
4830 p->setRenderHint(QPainter::Antialiasing);
4831 p->setPen(lineColor);
4832 const Qt::LayoutDirection layoutDirection = w ? w->layoutDirection() : qApp->layoutDirection();
4833 const int NumLines = 3;
4834 for (
int l = 0; l < NumLines; ++l) {
4835 const int offset = (l * 4 + 3);
4837 if (layoutDirection == Qt::LeftToRight) {
4838 start = QPoint(opt->rect.width() - offset, opt->rect.height() - 1);
4839 end = QPoint(opt->rect.width() - 1, opt->rect.height() - offset);
4841 start = QPoint(offset, opt->rect.height() - 1);
4842 end = QPoint(1, opt->rect.height() - offset);
4844 p->drawLine(start, end);
4850 if (opt->rect.width() > 1 && opt->rect.height() > 1) {
4851 const bool isVertical = !(opt->state & QStyle::State_Horizontal);
4853 const auto ct = isVertical ? QMacStylePrivate::SplitView_Horizontal : QMacStylePrivate::SplitView_Vertical;
4854 const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
4855 auto *sv =
static_cast<NSSplitView *>(d->cocoaControl(cw));
4856 sv.frame = opt->rect.toCGRect();
4857 d->drawNSViewInRect(sv, opt->rect, p, ^(CGContextRef,
const CGRect &rect) {
4858 [sv drawDividerInRect:rect];
4861 QPen oldPen = p->pen();
4862 p->setPen(opt->palette.dark().color());
4863 if (opt->state & QStyle::State_Horizontal)
4864 p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
4866 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
4871 if (
const QStyleOptionRubberBand *rubber = qstyleoption_cast<
const QStyleOptionRubberBand *>(opt)) {
4872 QColor fillColor(opt->palette.color(QPalette::Disabled, QPalette::Highlight));
4873 if (!rubber->opaque) {
4876 strokeColor.setHsvF(0, 0, 0.86, 1.0);
4877 fillColor.setHsvF(0, 0, 0.53, 0.25);
4878 if (opt->rect.width() * opt->rect.height() <= 3) {
4879 p->fillRect(opt->rect, strokeColor);
4881 QPen oldPen = p->pen();
4882 QBrush oldBrush = p->brush();
4883 QPen pen(strokeColor);
4885 p->setBrush(fillColor);
4886 QRect adjusted = opt->rect.adjusted(1, 1, -1, -1);
4887 if (adjusted.isValid())
4888 p->drawRect(adjusted);
4890 p->setBrush(oldBrush);
4893 p->fillRect(opt->rect, fillColor);
4897#ifndef QT_NO_TOOLBAR
4899 const QStyleOptionToolBar *toolBar = qstyleoption_cast<
const QStyleOptionToolBar *>(opt);
4901 const QColor separatorColor = darkMode ? darkModeSeparatorLine : opt->palette.dark().color();
4908#if QT_CONFIG(mainwindow)
4909 if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) {
4910 if (toolBar && toolBar->toolBarArea == Qt::TopToolBarArea && mainWindow->unifiedTitleAndToolBarOnMac()) {
4913 p->setCompositionMode(QPainter::CompositionMode_Source);
4914 p->fillRect(opt->rect, Qt::transparent);
4921 const QPoint windowToolbarEnd = w->mapTo(w->window(), opt->rect.bottomLeft());
4922 const bool isEndOfUnifiedArea = !isInMacUnifiedToolbarArea(w->window(), windowToolbarEnd.y() + 1);
4923 if (isEndOfUnifiedArea) {
4924 const int margin = qt_mac_aqua_get_metric(SeparatorSize);
4925 const auto separatorRect = QRect(opt->rect.left(), opt->rect.bottom(), opt->rect.width(), margin);
4926 p->fillRect(separatorRect, separatorColor);
4934 p->fillRect(opt->rect, opt->palette.window());
4937 p->setPen(separatorColor);
4938 QRect toolbarRect = darkMode ? opt->rect.adjusted(0, 0, 0, 1) : opt->rect;
4939 if (opt->state & State_Horizontal) {
4940 p->drawLine(toolbarRect.topLeft(), toolbarRect.topRight());
4941 p->drawLine(toolbarRect.bottomLeft(), toolbarRect.bottomRight());
4943 p->drawLine(toolbarRect.topLeft(), toolbarRect.bottomLeft());
4944 p->drawLine(toolbarRect.topRight(), toolbarRect.bottomRight());
4952 QCommonStyle::drawControl(ce, opt, p, w);
4967 const QWidget *widget)
const
4969 Q_D(
const QMacStyle);
4971 const int controlSize = getControlSize(opt, widget);
4974#if QT_CONFIG(itemviews)
4975 case SE_ItemViewItemText:
4976 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
4977 int fw = proxy()->pixelMetric(PM_FocusFrameHMargin, opt, widget);
4979 rect = QCommonStyle::subElementRect(sr, opt, widget);
4980 if (vopt->features & QStyleOptionViewItem::HasDecoration)
4981 rect.adjust(-fw, 0, 0, 0);
4985 case SE_ToolBoxTabContents:
4986 rect = QCommonStyle::subElementRect(sr, opt, widget);
4988 case SE_PushButtonBevel:
4989 case SE_PushButtonContents:
4990 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
4999 const auto ct = cocoaControlType(btn, widget);
5000 const auto cs = d->effectiveAquaSizeConstrain(btn, widget);
5001 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5002 auto frameRect = cw.adjustedControlFrame(btn->rect);
5003 if (sr == SE_PushButtonContents) {
5004 frameRect -= cw.titleMargins();
5005 }
else if (cw.type != QMacStylePrivate::Button_SquareButton) {
5006 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
5007 frameRect = QRectF::fromCGRect([pb alignmentRectForFrame:frameRect.toCGRect()]);
5008 if (cw.type == QMacStylePrivate::Button_PushButton)
5009 frameRect -= pushButtonShadowMargins[cw.size];
5010 else if (cw.type == QMacStylePrivate::Button_PullDown)
5011 frameRect -= pullDownButtonShadowMargins[cw.size];
5013 rect = frameRect.toRect();
5016 case SE_HeaderLabel: {
5017 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
5018 rect.setRect(opt->rect.x() + margin, opt->rect.y(),
5019 opt->rect.width() - margin * 2, opt->rect.height() - 2);
5020 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
5022 if (header->sortIndicator != QStyleOptionHeader::None) {
5023 if (opt->state & State_Horizontal)
5029 rect = visualRect(opt->direction, opt->rect, rect);
5032 case SE_HeaderArrow: {
5033 int h = opt->rect.height();
5034 int w = opt->rect.width();
5035 int x = opt->rect.x();
5036 int y = opt->rect.y();
5037 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
5039 if (opt->state & State_Horizontal) {
5046 rect = visualRect(opt->direction, opt->rect, rect);
5049 case SE_ProgressBarGroove:
5053 case SE_ProgressBarLabel:
5055 case SE_ProgressBarContents:
5058 case SE_TreeViewDisclosureItem: {
5064#if QT_CONFIG(tabwidget)
5065 case SE_TabWidgetLeftCorner:
5066 if (
const QStyleOptionTabWidgetFrame *twf
5067 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5068 switch (twf->shape) {
5069 case QTabBar::RoundedNorth:
5070 case QTabBar::TriangularNorth:
5071 rect = QRect(QPoint(0, 0), twf->leftCornerWidgetSize);
5073 case QTabBar::RoundedSouth:
5074 case QTabBar::TriangularSouth:
5075 rect = QRect(QPoint(0, twf->rect.height() - twf->leftCornerWidgetSize.height()),
5076 twf->leftCornerWidgetSize);
5081 rect = visualRect(twf->direction, twf->rect, rect);
5084 case SE_TabWidgetRightCorner:
5085 if (
const QStyleOptionTabWidgetFrame *twf
5086 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5087 switch (twf->shape) {
5088 case QTabBar::RoundedNorth:
5089 case QTabBar::TriangularNorth:
5090 rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(), 0),
5091 twf->rightCornerWidgetSize);
5093 case QTabBar::RoundedSouth:
5094 case QTabBar::TriangularSouth:
5095 rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(),
5096 twf->rect.height() - twf->rightCornerWidgetSize.height()),
5097 twf->rightCornerWidgetSize);
5102 rect = visualRect(twf->direction, twf->rect, rect);
5105 case SE_TabWidgetTabContents:
5106 rect = QCommonStyle::subElementRect(sr, opt, widget);
5107 if (
const auto *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5108 if (twf->lineWidth != 0) {
5109 switch (QMacStylePrivate::tabDirection(twf->shape)) {
5110 case QMacStylePrivate::North:
5111 rect.adjust(+1, +14, -1, -1);
5113 case QMacStylePrivate::South:
5114 rect.adjust(+1, +1, -1, -14);
5116 case QMacStylePrivate::West:
5117 rect.adjust(+14, +1, -1, -1);
5119 case QMacStylePrivate::East:
5120 rect.adjust(+1, +1, -14, -1);
5125 case SE_TabBarTabText:
5126 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
5127 QRect dummyIconRect;
5128 d->tabLayout(tab, widget, &rect, &dummyIconRect);
5131 case SE_TabBarTabLeftButton:
5132 case SE_TabBarTabRightButton:
5133 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
5134 bool selected = tab->state & State_Selected;
5135 int verticalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget);
5136 int horizontalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget);
5139 bool verticalTabs = tab->shape == QTabBar::RoundedEast
5140 || tab->shape == QTabBar::RoundedWest
5141 || tab->shape == QTabBar::TriangularEast
5142 || tab->shape == QTabBar::TriangularWest;
5144 QRect tr = tab->rect;
5145 if (tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::TriangularSouth)
5146 verticalShift = -verticalShift;
5148 qSwap(horizontalShift, verticalShift);
5149 horizontalShift *= -1;
5150 verticalShift *= -1;
5152 if (tab->shape == QTabBar::RoundedWest || tab->shape == QTabBar::TriangularWest)
5153 horizontalShift = -horizontalShift;
5155 tr.adjust(0, 0, horizontalShift, verticalShift);
5158 tr.setBottom(tr.bottom() - verticalShift);
5159 tr.setRight(tr.right() - horizontalShift);
5162 QSize size = (sr == SE_TabBarTabLeftButton) ? tab->leftButtonSize : tab->rightButtonSize;
5163 int w = size.width();
5164 int h = size.height();
5165 int midHeight =
static_cast<
int>(qCeil(
float(tr.height() - h) / 2));
5166 int midWidth = ((tr.width() - w) / 2);
5168 bool atTheTop =
true;
5169 switch (tab->shape) {
5170 case QTabBar::RoundedWest:
5171 case QTabBar::TriangularWest:
5172 atTheTop = (sr == SE_TabBarTabLeftButton);
5174 case QTabBar::RoundedEast:
5175 case QTabBar::TriangularEast:
5176 atTheTop = (sr == SE_TabBarTabRightButton);
5179 if (sr == SE_TabBarTabLeftButton)
5180 rect = QRect(tab->rect.x() + hpadding, midHeight, w, h);
5182 rect = QRect(tab->rect.right() - w - hpadding, midHeight, w, h);
5183 rect = visualRect(tab->direction, tab->rect, rect);
5187 rect = QRect(midWidth, tr.y() + tab->rect.height() - hpadding - h, w, h);
5189 rect = QRect(midWidth, tr.y() + hpadding, w, h);
5194 case SE_LineEditContents:
5195 rect = QCommonStyle::subElementRect(sr, opt, widget);
5196#if QT_CONFIG(combobox)
5197 if (widget && qobject_cast<
const QComboBox*>(widget->parentWidget()))
5198 rect.adjust(-1, -2, 0, 0);
5201 rect.adjust(-1, -1, 0, +1);
5203 case SE_CheckBoxLayoutItem:
5205 if (controlSize == QStyleHelper::SizeLarge) {
5206 setLayoutItemMargins(+2, +3, -9, -4, &rect, opt->direction);
5207 }
else if (controlSize == QStyleHelper::SizeSmall) {
5208 setLayoutItemMargins(+1, +5, 0 , -6, &rect, opt->direction);
5210 setLayoutItemMargins(0, +7, 0 , -6, &rect, opt->direction);
5213 case SE_ComboBoxLayoutItem:
5214#ifndef QT_NO_TOOLBAR
5215 if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
5224 if (controlSize == QStyleHelper::SizeLarge) {
5225 rect.adjust(+3, +2, -3, -4);
5226 }
else if (controlSize == QStyleHelper::SizeSmall) {
5227 setLayoutItemMargins(+2, +1, -3, -4, &rect, opt->direction);
5229 setLayoutItemMargins(+1, 0, -2, 0, &rect, opt->direction);
5233 case SE_LabelLayoutItem:
5235 setLayoutItemMargins(+1, 0 , 0, 0 , &rect, opt->direction);
5237 case SE_ProgressBarLayoutItem: {
5239 int bottom =
SIZE(3, 8, 8);
5240 if (opt->state & State_Horizontal) {
5241 rect.adjust(0, +1, 0, -bottom);
5243 setLayoutItemMargins(+1, 0, -bottom, 0, &rect, opt->direction);
5247 case SE_PushButtonLayoutItem:
5248 if (
const QStyleOptionButton *buttonOpt
5249 = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
5250 if ((buttonOpt->features & QStyleOptionButton::Flat))
5252 if ((buttonOpt->features & QStyleOptionButton::CommandLinkButton)) {
5254 if (controlSize == QStyleHelper::SizeLarge)
5255 rect.adjust(+6, +4, -6, -8);
5256 else if (controlSize == QStyleHelper::SizeSmall)
5257 rect.adjust(+5, +4, -5, -6);
5259 rect.adjust(+1, 0, -1, -2);
5264 if (controlSize == QStyleHelper::SizeLarge) {
5265 rect.adjust(0, +4, 0, -8);
5266 }
else if (controlSize == QStyleHelper::SizeSmall) {
5267 rect.adjust(0, +4, 0, -6);
5269 rect.adjust(0, 0, 0, -2);
5272 case SE_RadioButtonLayoutItem:
5274 if (controlSize == QStyleHelper::SizeLarge) {
5275 setLayoutItemMargins(+2, +2 ,
5276 0, -4 , &rect, opt->direction);
5277 }
else if (controlSize == QStyleHelper::SizeSmall) {
5278 rect.adjust(0, +6, 0 , -5);
5280 rect.adjust(0, +6, 0 , -7);
5283 case SE_SliderLayoutItem:
5284 if (
const QStyleOptionSlider *sliderOpt
5285 = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5287 if (sliderOpt->tickPosition == QSlider::NoTicks) {
5288 int above =
SIZE(3, 0, 2);
5289 int below =
SIZE(4, 3, 0);
5290 if (sliderOpt->orientation == Qt::Horizontal) {
5291 rect.adjust(0, +above, 0, -below);
5293 rect.adjust(+above, 0, -below, 0);
5295 }
else if (sliderOpt->tickPosition == QSlider::TicksAbove) {
5296 int below =
SIZE(3, 2, 0);
5297 if (sliderOpt->orientation == Qt::Horizontal) {
5298 rect.setHeight(rect.height() - below);
5300 rect.setWidth(rect.width() - below);
5302 }
else if (sliderOpt->tickPosition == QSlider::TicksBelow) {
5303 int above =
SIZE(3, 2, 0);
5304 if (sliderOpt->orientation == Qt::Horizontal) {
5305 rect.setTop(rect.top() + above);
5307 rect.setLeft(rect.left() + above);
5312 case SE_FrameLayoutItem:
5314 if (
const QFrame *frame = qobject_cast<
const QFrame *>(widget)) {
5316 switch (frame->frameStyle() & QFrame::Shape_Mask) {
5318 rect.adjust(0, +1, 0, -1);
5321 rect.adjust(+1, 0, -1, 0);
5328 case SE_GroupBoxLayoutItem:
5330 if (
const QStyleOptionGroupBox *groupBoxOpt =
5331 qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
5333
5334
5335
5336
5337 if (groupBoxOpt->subControls & (QStyle::SC_GroupBoxCheckBox
5338 | QStyle::SC_GroupBoxLabel)) {
5340 if (groupBoxOpt->subControls & QStyle::SC_GroupBoxCheckBox) {
5341 delta =
SIZE(8, 4, 4);
5343 delta =
SIZE(15, 12, 12);
5345 rect.setTop(rect.top() + delta);
5348 rect.setBottom(rect.bottom() - 1);
5350#if QT_CONFIG(tabwidget)
5351 case SE_TabWidgetLayoutItem:
5352 if (
const QStyleOptionTabWidgetFrame *tabWidgetOpt =
5353 qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5355
5356
5357
5358
5359 rect = tabWidgetOpt->rect;
5360 if (tabWidgetOpt->shape == QTabBar::RoundedNorth)
5361 rect.setTop(rect.top() + SIZE(6 , 3 , 2 ));
5365#if QT_CONFIG(dockwidget)
5366 case SE_DockWidgetCloseButton:
5367 case SE_DockWidgetFloatButton:
5368 case SE_DockWidgetTitleBarText:
5369 case SE_DockWidgetIcon: {
5370 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
5371 int buttonMargin = proxy()->pixelMetric(PM_DockWidgetTitleBarButtonMargin, opt, widget);
5372 QRect srect = opt->rect;
5374 const QStyleOptionDockWidget *dwOpt
5375 = qstyleoption_cast<
const QStyleOptionDockWidget*>(opt);
5376 bool canClose = dwOpt == 0 ?
true : dwOpt->closable;
5377 bool canFloat = dwOpt == 0 ?
false : dwOpt->floatable;
5379 const bool verticalTitleBar = dwOpt->verticalTitleBar;
5383 if (verticalTitleBar)
5384 srect = srect.transposed();
5387 int right = srect.right();
5388 int left = srect.left();
5392 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton,
5393 opt, widget).actualSize(QSize(iconSize, iconSize));
5394 sz += QSize(buttonMargin, buttonMargin);
5395 if (verticalTitleBar)
5396 sz = sz.transposed();
5397 closeRect = QRect(left,
5398 srect.center().y() - sz.height()/2,
5399 sz.width(), sz.height());
5400 left = closeRect.right() + 1;
5402 if (sr == SE_DockWidgetCloseButton) {
5409 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarNormalButton,
5410 opt, widget).actualSize(QSize(iconSize, iconSize));
5411 sz += QSize(buttonMargin, buttonMargin);
5412 if (verticalTitleBar)
5413 sz = sz.transposed();
5414 floatRect = QRect(left,
5415 srect.center().y() - sz.height()/2,
5416 sz.width(), sz.height());
5417 left = floatRect.right() + 1;
5419 if (sr == SE_DockWidgetFloatButton) {
5425 if (
const QDockWidget *dw = qobject_cast<
const QDockWidget*>(widget)) {
5427 if (dw->isFloating())
5428 icon = dw->windowIcon();
5430 && icon.cacheKey() != QApplication::windowIcon().cacheKey()) {
5431 QSize sz = icon.actualSize(QSize(rect.height(), rect.height()));
5432 if (verticalTitleBar)
5433 sz = sz.transposed();
5434 iconRect = QRect(right - sz.width(), srect.center().y() - sz.height()/2,
5435 sz.width(), sz.height());
5436 right = iconRect.left() - 1;
5439 if (sr == SE_DockWidgetIcon) {
5444 QRect textRect = QRect(left, srect.top(),
5445 right - left, srect.height());
5446 if (sr == SE_DockWidgetTitleBarText) {
5452 if (verticalTitleBar) {
5453 rect = QRect(srect.left() + rect.top() - srect.top(),
5454 srect.top() + srect.right() - rect.right(),
5455 rect.height(), rect.width());
5457 rect = visualRect(opt->direction, srect, rect);
5463 rect = QCommonStyle::subElementRect(sr, opt, widget);
5496 const QWidget *widget)
const
5498 Q_D(
const QMacStyle);
5499 QMacCGContext cg(p);
5501 qCWarning(lcMacStyle) <<
"drawComplexControl:" << cc <<
"invalid (nullptr) graphics context";
5502 QWindow *window = widget && widget->window() ? widget->window()->windowHandle() :
nullptr;
5503 d->resolveCurrentNSView(window);
5506 if (
const QStyleOptionSlider *sb = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5509 const bool drawTrack = sb->subControls & SC_ScrollBarGroove;
5510 const bool drawKnob = sb->subControls & SC_ScrollBarSlider && sb->minimum != sb->maximum;
5511 if (!drawTrack && !drawKnob)
5514 const bool isHorizontal = sb->orientation == Qt::Horizontal;
5516 if (opt && opt->styleObject && !QMacStylePrivate::scrollBars.contains(opt->styleObject))
5517 QMacStylePrivate::scrollBars.append(QPointer<QObject>(opt->styleObject));
5519 static const CGFloat knobWidths[] = { 7.0, 5.0, 5.0 };
5520 static const CGFloat expandedKnobWidths[] = { 11.0, 9.0, 9.0 };
5521 const auto cocoaSize = d->effectiveAquaSizeConstrain(opt, widget);
5522 const CGFloat maxExpandScale = expandedKnobWidths[cocoaSize] / knobWidths[cocoaSize];
5524 const QStyle *realStyle = widget ? widget->style() : proxy();
5525 const bool isTransient = realStyle->styleHint(SH_ScrollBar_Transient, opt, widget);
5527 d->stopAnimation(opt->styleObject);
5528 bool wasActive =
false;
5529 CGFloat opacity = 0.0;
5530 CGFloat expandScale = 1.0;
5531 CGFloat expandOffset = 0.0;
5532 bool shouldExpand =
false;
5534 if (QObject *styleObject = opt->styleObject) {
5535 const int oldPos = styleObject->property(
"_q_stylepos").toInt();
5536 const int oldMin = styleObject->property(
"_q_stylemin").toInt();
5537 const int oldMax = styleObject->property(
"_q_stylemax").toInt();
5538 const QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
5539 const QStyle::State oldState =
static_cast<QStyle::State>(styleObject->property(
"_q_stylestate").value<QStyle::State::Int>());
5540 const uint oldActiveControls = styleObject->property(
"_q_stylecontrols").toUInt();
5544 const bool transient = isTransient && !opt->activeSubControls && !(sb->state & State_On);
5547 oldPos != sb->sliderPosition ||
5548 oldMin != sb->minimum ||
5549 oldMax != sb->maximum ||
5550 oldRect != sb->rect ||
5551 oldState != sb->state ||
5552 oldActiveControls != sb->activeSubControls) {
5558 styleObject->setProperty(
"_q_stylepos", sb->sliderPosition);
5559 styleObject->setProperty(
"_q_stylemin", sb->minimum);
5560 styleObject->setProperty(
"_q_stylemax", sb->maximum);
5561 styleObject->setProperty(
"_q_stylerect", sb->rect);
5562 styleObject->setProperty(
"_q_stylestate",
static_cast<QStyle::State::Int>(sb->state));
5563 styleObject->setProperty(
"_q_stylecontrols",
static_cast<uint>(sb->activeSubControls));
5565 QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
5568 anim =
new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Deactivating, styleObject);
5569 d->startAnimation(anim);
5570 }
else if (anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5573 anim->setCurrentTime(0);
5575 }
else if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5576 d->stopAnimation(styleObject);
5580 QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
5581 if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5584 if (oldActiveControls)
5585 anim->setActive(
true);
5587 wasActive = anim->wasActive();
5588 opacity = anim->currentValue();
5591 shouldExpand = isTransient && (opt->activeSubControls || wasActive);
5593 if (!anim && !oldActiveControls) {
5595 anim =
new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Activating, styleObject);
5596 d->startAnimation(anim);
5598 if (anim && anim->mode() == QScrollbarStyleAnimation::Activating) {
5599 expandScale = 1.0 + (maxExpandScale - 1.0) * anim->currentValue();
5600 expandOffset = 5.5 * (1.0 - anim->currentValue());
5603 expandScale = maxExpandScale;
5609 d->setupNSGraphicsContext(cg, NO );
5611 const auto controlType = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical;
5612 const auto cw = QMacStylePrivate::CocoaControl(controlType, cocoaSize);
5613 NSScroller *scroller =
static_cast<NSScroller *>(d->cocoaControl(cw));
5615 const QColor bgColor = QStyleHelper::backgroundColor(opt->palette, widget);
5616 const bool hasDarkBg = bgColor.red() < 128 && bgColor.green() < 128 && bgColor.blue() < 128;
5620 scroller.knobStyle = hasDarkBg? NSScrollerKnobStyleLight : NSScrollerKnobStyleDark;
5622 scroller.knobStyle = NSScrollerKnobStyleDefault;
5625 scroller.scrollerStyle = isTransient ? NSScrollerStyleOverlay : NSScrollerStyleLegacy;
5627 if (!setupScroller(scroller, sb))
5631 CGContextBeginTransparencyLayerWithRect(cg, scroller.frame,
nullptr);
5632 CGContextSetAlpha(cg, opacity);
5637 if (!isTransient || opt->activeSubControls || wasActive) {
5638 CGRect trackRect = scroller.bounds;
5640 trackRect.origin.y += expandOffset;
5642 trackRect.origin.x += expandOffset;
5643 [scroller drawKnobSlotInRect:trackRect highlight:NO];
5653 const CGFloat scrollerWidth = [NSScroller scrollerWidthForControlSize:scroller.controlSize scrollerStyle:scroller.scrollerStyle];
5654 const CGFloat knobWidth = knobWidths[cocoaSize] * expandScale;
5656 const CGRect scrollerKnobRect = CGRectInset([scroller rectForPart:NSScrollerKnob], 1, 1);
5657 const CGFloat knobLength = isHorizontal ? scrollerKnobRect.size.width : scrollerKnobRect.size.height;
5658 const CGFloat knobPos = isHorizontal ? scrollerKnobRect.origin.x : scrollerKnobRect.origin.y;
5659 const CGFloat knobOffset = qRound((scrollerWidth + expandOffset - knobWidth) / 2.0);
5660 const CGFloat knobRadius = knobWidth / 2.0;
5663 knobRect = CGRectMake(knobPos, knobOffset, knobLength, knobWidth);
5665 knobRect = CGRectMake(knobOffset, knobPos, knobWidth, knobLength);
5666 QCFType<CGPathRef> knobPath = CGPathCreateWithRoundedRect(knobRect, knobRadius, knobRadius,
nullptr);
5667 CGContextAddPath(cg, knobPath);
5668 CGContextSetAlpha(cg, 0.5);
5669 CGColorRef knobColor = hasDarkBg ? NSColor.whiteColor.CGColor : NSColor.blackColor.CGColor;
5670 CGContextSetFillColorWithColor(cg, knobColor);
5671 CGContextFillPath(cg);
5673 [scroller drawKnob];
5675 if (!isTransient && opt->activeSubControls) {
5680 CGContextSetBlendMode(cg, kCGBlendModePlusDarker);
5681 [scroller drawKnob];
5687 CGContextEndTransparencyLayer(cg);
5689 d->restoreNSGraphicsContext(cg);
5693 if (
const QStyleOptionSlider *sl = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5694 const bool isHorizontal = sl->orientation == Qt::Horizontal;
5695 const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical;
5696 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
5697 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5698 auto *slider =
static_cast<NSSlider *>(d->cocoaControl(cw));
5699 if (!setupSlider(slider, sl))
5702 const bool hasTicks = sl->tickPosition != QSlider::NoTicks;
5703 const bool hasDoubleTicks = sl->tickPosition == QSlider::TicksBothSides;
5704 const bool drawKnob = sl->subControls & SC_SliderHandle;
5705 const bool drawBar = sl->subControls & SC_SliderGroove;
5706 const bool drawTicks = sl->subControls & SC_SliderTickmarks;
5707 const bool isPressed = qt_apple_runningWithLiquidGlass() ?
false : sl->state & State_Sunken;
5711 const CGRect knobRect = [slider.cell knobRectFlipped:slider.isFlipped];
5712 pressPoint.x = CGRectGetMidX(knobRect);
5713 pressPoint.y = CGRectGetMidY(knobRect);
5728 [slider.cell startTrackingAt:pressPoint inView:slider];
5729 [slider.cell startTrackingAt:pressPoint inView:slider];
5732 d->drawNSViewInRect(slider, opt->rect, p, ^(CGContextRef ctx,
const CGRect &rect) {
5735 const bool verticalFlip = !isHorizontal && !sl->upsideDown;
5738 if (sl->upsideDown) {
5739 CGContextTranslateCTM(ctx, rect.size.width, rect.origin.y);
5740 CGContextScaleCTM(ctx, -1, 1);
5742 CGContextTranslateCTM(ctx, 0, rect.origin.y);
5744 }
else if (verticalFlip) {
5745 CGContextTranslateCTM(ctx, rect.origin.x, rect.size.height);
5746 CGContextScaleCTM(ctx, 1, -1);
5749 if (hasDoubleTicks) {
5752 CGContextTranslateCTM(ctx, 0, 4);
5754 CGContextTranslateCTM(ctx, 1, 0);
5761 const bool drawAllParts = drawKnob && drawBar && (!hasTicks || drawTicks);
5762 if (drawAllParts && !hasDoubleTicks && (!verticalFlip || drawTicks)) {
5766 if (verticalFlip && drawTicks) {
5769 slider.intValue = slider.maxValue - slider.intValue + slider.minValue;
5771 [slider drawRect:CGRectZero];
5775 NSSliderCell *cell = slider.cell;
5777 const int numberOfTickMarks = slider.numberOfTickMarks;
5780 slider.numberOfTickMarks = 0;
5782 const CGRect barRect = [cell barRectFlipped:slider.isFlipped];
5784 if (!isHorizontal && !sl->upsideDown && (hasDoubleTicks || !hasTicks)) {
5792 [cell drawBarInside:barRect flipped:
true];
5794 [cell drawBarInside:barRect flipped:!verticalFlip];
5798 slider.numberOfTickMarks = numberOfTickMarks;
5801 if (hasTicks && drawTicks) {
5802 if (!drawBar && hasDoubleTicks)
5803 slider.numberOfTickMarks = numberOfTickMarks;
5805 if (qt_apple_runningWithLiquidGlass())
5806 drawTickMarks(ctx, slider, sl);
5808 [cell drawTickMarks];
5810 if (hasDoubleTicks) {
5812 CGAffineTransform tickMarksFlip;
5813 const CGRect tickMarkRect = [cell rectOfTickMarkAtIndex:0];
5815 tickMarksFlip = CGAffineTransformMakeTranslation(0, rect.size.height - tickMarkRect.size.height - 3);
5816 tickMarksFlip = CGAffineTransformScale(tickMarksFlip, 1, -1);
5818 tickMarksFlip = CGAffineTransformMakeTranslation(rect.size.width - tickMarkRect.size.width / 2, 0);
5819 tickMarksFlip = CGAffineTransformScale(tickMarksFlip, -1, 1);
5821 CGContextConcatCTM(ctx, tickMarksFlip);
5822 [cell drawTickMarks];
5823 CGContextConcatCTM(ctx, CGAffineTransformInvert(tickMarksFlip));
5830 slider.numberOfTickMarks = 0;
5831 if (qt_apple_runningWithLiquidGlass())
5832 drawSliderKnob(ctx, slider);
5842 [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO];
5843 [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO];
5847#if QT_CONFIG(spinbox)
5849 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
5850 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
5851 const auto lineEditRect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget);
5852 QStyleOptionFrame frame;
5853 static_cast<QStyleOption &>(frame) = *opt;
5854 frame.rect = lineEditRect;
5855 frame.state |= State_Sunken;
5856 frame.lineWidth = 1;
5857 frame.midLineWidth = 0;
5858 frame.features = QStyleOptionFrame::None;
5859 frame.frameShape = QFrame::Box;
5860 drawPrimitive(PE_FrameLineEdit, &frame, p, widget);
5862 if (sb->subControls & (SC_SpinBoxUp | SC_SpinBoxDown)) {
5863 const QRect updown = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget)
5864 | proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
5867 d->setupNSGraphicsContext(cg, NO);
5869 const auto aquaSize = d->effectiveAquaSizeConstrain(opt, widget);
5870 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize);
5871 NSStepperCell *cell =
static_cast<NSStepperCell *>(d->cocoaCell(cw));
5872 const auto controlSize = cell.controlSize;
5873 if (qt_apple_runningWithLiquidGlass())
5874 cell.controlSize = NSControlSizeMini;
5875 cell.enabled = (sb->state & State_Enabled);
5877 const CGRect newRect = [cell drawingRectForBounds:updown.toCGRect()];
5879 const bool upPressed = sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken);
5880 const bool downPressed = sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken);
5881 const CGFloat x = CGRectGetMidX(newRect);
5882 const CGFloat y = upPressed ? -3 : 3;
5883 const CGPoint pressPoint = CGPointMake(x, y);
5886 if (upPressed || downPressed)
5887 [cell startTrackingAt:pressPoint inView:d->backingStoreNSView];
5889 [cell drawWithFrame:newRect inView:d->backingStoreNSView];
5891 if (upPressed || downPressed)
5892 [cell stopTracking:pressPoint at:pressPoint inView:d->backingStoreNSView mouseIsUp:NO];
5894 d->restoreNSGraphicsContext(cg);
5895 if (qt_apple_runningWithLiquidGlass())
5896 cell.controlSize = controlSize;
5901#if QT_CONFIG(combobox)
5903 if (
const auto *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
5904 const bool isEnabled = combo->state & State_Enabled;
5905 const bool isPressed = combo->state & State_Sunken;
5907 const auto ct = cocoaControlType(combo, widget);
5908 const auto cs = d->effectiveAquaSizeConstrain(combo, widget);
5909 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5910 auto *cc =
static_cast<NSControl *>(d->cocoaControl(cw));
5911 cc.enabled = isEnabled;
5912 QRectF frameRect = cw.adjustedControlFrame(combo->rect);
5913 if (cw.type == QMacStylePrivate::Button_PopupButton) {
5915 auto *pb =
static_cast<NSPopUpButton *>(cc);
5917 if (cw.size == QStyleHelper::SizeSmall) {
5918 frameRect = frameRect.translated(0, 1);
5919 }
else if (cw.size == QStyleHelper::SizeMini) {
5921 frameRect = frameRect.translated(2, -0.5);
5923 pb.frame = frameRect.toCGRect();
5924 [pb highlight:isPressed];
5925 d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
5926 [pb.cell drawBezelWithFrame:r inView:pb.superview];
5928 }
else if (cw.type == QMacStylePrivate::ComboBox) {
5930 auto *cb =
static_cast<NSComboBox *>(cc);
5931 const auto frameRect = cw.adjustedControlFrame(combo->rect);
5932 cb.frame = frameRect.toCGRect();
5935 if (NSButtonCell *cell =
static_cast<NSButtonCell *>([cc.cell qt_valueForPrivateKey:@
"_buttonCell"])) {
5936 cell.highlighted = isPressed;
5941 d->drawNSViewInRect(cb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
5943 [cb.cell drawWithFrame:r inView:cb];
5947 if (combo->state & State_HasFocus) {
5949 const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, combo, widget);
5950 const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, combo, widget);
5952 if (cw.type == QMacStylePrivate::Button_PopupButton) {
5953 if (qt_apple_runningWithLiquidGlass())
5954 focusRect = QRectF::fromCGRect(qt_alignmentRectForFrame(cc.frame, cw.size, cw.type));
5956 focusRect = QRectF::fromCGRect([cc alignmentRectForFrame:cc.frame]);
5957 focusRect -= pullDownButtonShadowMargins[cw.size];
5958 if (cw.size == QStyleHelper::SizeSmall)
5959 focusRect = focusRect.translated(0, 1);
5960 else if (cw.size == QStyleHelper::SizeMini)
5961 focusRect = focusRect.translated(2, -1);
5962 }
else if (cw.type == QMacStylePrivate::ComboBox) {
5963 focusRect = frameRect - comboBoxFocusRingMargins[cw.size];
5965 d->drawFocusRing(p, focusRect, hMargin, vMargin, cw);
5971 if (
const auto *titlebar = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
5972 const bool isActive = (titlebar->state & State_Active)
5973 && (titlebar->titleBarState & State_Active);
5975 p->fillRect(opt->rect, Qt::transparent);
5976 p->setRenderHint(QPainter::Antialiasing);
5977 p->setClipRect(opt->rect, Qt::IntersectClip);
5981 const auto outerFrameRect = QRectF(opt->rect.adjusted(0, 0, 0, opt->rect.height()));
5982 QPainterPath outerFramePath = d->windowPanelPath(outerFrameRect);
5983 p->fillPath(outerFramePath, opt->palette.dark());
5985 const auto frameAdjust = 1.0 / p->device()->devicePixelRatio();
5986 const auto innerFrameRect = outerFrameRect.adjusted(frameAdjust, frameAdjust, -frameAdjust, 0);
5987 QPainterPath innerFramePath = d->windowPanelPath(innerFrameRect);
5988 p->fillPath(innerFramePath, opt->palette.button());
5990 if (titlebar->subControls & (SC_TitleBarCloseButton
5991 | SC_TitleBarMaxButton
5992 | SC_TitleBarMinButton
5993 | SC_TitleBarNormalButton)) {
5994 const bool isHovered = (titlebar->state & State_MouseOver);
5995 static const SubControl buttons[] = {
5996 SC_TitleBarCloseButton, SC_TitleBarMinButton, SC_TitleBarMaxButton
5998 for (
const auto sc : buttons) {
5999 const auto ct = d->windowButtonCocoaControl(sc);
6000 const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
6001 auto *wb =
static_cast<NSButton *>(d->cocoaControl(cw));
6002 wb.enabled = (sc & titlebar->subControls) && isActive;
6003 [wb highlight:(titlebar->state & State_Sunken) && (sc & titlebar->activeSubControls)];
6004 Q_UNUSED(isHovered);
6006 const auto buttonRect = proxy()->subControlRect(CC_TitleBar, titlebar, sc, widget);
6007 d->drawNSViewInRect(wb, buttonRect, p, ^(CGContextRef,
const CGRect &rect) {
6008 auto *wbCell =
static_cast<NSButtonCell *>(wb.cell);
6009 [wbCell drawWithFrame:rect inView:wb];
6014 if (titlebar->subControls & SC_TitleBarLabel) {
6015 const auto tr = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarLabel, widget);
6016 if (!titlebar->icon.isNull()) {
6017 const auto iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
6018 const auto iconSize = QSize(iconExtent, iconExtent);
6019 const auto iconPos = tr.x() - titlebar->icon.actualSize(iconSize).width() - qRound(titleBarIconTitleSpacing);
6021 if (iconPos < tr.right() - titleBarIconTitleSpacing)
6022 p->drawPixmap(iconPos, tr.y(), titlebar->icon.pixmap(iconSize, QIcon::Normal));
6025 if (!titlebar->text.isEmpty())
6026 drawItemText(p, tr, Qt::AlignCenter, opt->palette, isActive, titlebar->text, QPalette::Text);
6031 if (
const QStyleOptionGroupBox *gb
6032 = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
6034 QStyleOptionGroupBox groupBox(*gb);
6035 const bool flat = groupBox.features & QStyleOptionFrame::Flat;
6037 groupBox.state |= QStyle::State_Mini;
6039 groupBox.subControls = groupBox.subControls & ~SC_GroupBoxFrame;
6041 const bool didSetFont = widget && widget->testAttribute(Qt::WA_SetFont);
6042 const bool didModifySubControls = !didSetFont && QApplication::desktopSettingsAware();
6043 if (didModifySubControls)
6044 groupBox.subControls = groupBox.subControls & ~SC_GroupBoxLabel;
6045 QCommonStyle::drawComplexControl(cc, &groupBox, p, widget);
6046 if (didModifySubControls) {
6047 const QRect rect = proxy()->subControlRect(CC_GroupBox, &groupBox, SC_GroupBoxLabel, widget);
6048 const bool rtl = groupBox.direction == Qt::RightToLeft;
6049 const int alignment = Qt::TextHideMnemonic | (rtl ? Qt::AlignRight : Qt::AlignLeft);
6050 const QFont savedFont = p->font();
6051 if (!flat && d->smallSystemFont)
6052 p->setFont(*d->smallSystemFont);
6053 proxy()->drawItemText(p, rect, alignment, groupBox.palette, groupBox.state & State_Enabled, groupBox.text, QPalette::WindowText);
6055 p->setFont(savedFont);
6060 if (
const QStyleOptionToolButton *tb
6061 = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
6062#if QT_CONFIG(accessibility)
6063 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) {
6064 if (tb->subControls & SC_ToolButtonMenu) {
6065 QStyleOption arrowOpt = *tb;
6066 arrowOpt.rect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget);
6067 arrowOpt.rect.setY(arrowOpt.rect.y() + arrowOpt.rect.height() / 2);
6068 arrowOpt.rect.setHeight(arrowOpt.rect.height() / 2);
6069 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
6070 }
else if ((tb->features & QStyleOptionToolButton::HasMenu)
6071 && (tb->toolButtonStyle != Qt::ToolButtonTextOnly && !tb->icon.isNull())) {
6072 d->drawToolbarButtonArrow(tb, p);
6074 if (tb->state & State_On) {
6075 NSView *view = window ? (NSView *)window->winId() : nil;
6078 isKey = [view.window isKeyWindow];
6080 QBrush brush(brushForToolButton(isKey));
6082 path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4);
6083 p->setRenderHint(QPainter::Antialiasing);
6084 p->fillPath(path, brush);
6086 proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget);
6090 auto bflags = tb->state;
6091 if (tb->subControls & SC_ToolButton)
6092 bflags |= State_Sunken;
6093 auto mflags = tb->state;
6094 if (tb->subControls & SC_ToolButtonMenu)
6095 mflags |= State_Sunken;
6097 if (tb->subControls & SC_ToolButton) {
6098 if (bflags & (State_Sunken | State_On | State_Raised)) {
6099 const bool isEnabled = tb->state & State_Enabled;
6100 const bool isPressed = tb->state & State_Sunken;
6101 const bool isHighlighted = (tb->state & State_Active) && (tb->state & State_On);
6102 const auto ct = QMacStylePrivate::Button_PushButton;
6103 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6104 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6105 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
6106 pb.bezelStyle = NSBezelStyleShadowlessSquare;
6107 pb.frame = opt->rect.toCGRect();
6108 pb.buttonType = NSButtonTypePushOnPushOff;
6109 pb.enabled = isEnabled;
6110 [pb highlight:isPressed];
6111 pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff;
6112 const auto buttonRect = proxy()->subControlRect(cc, tb, SC_ToolButton, widget);
6113 d->drawNSViewInRect(pb, buttonRect, p, ^(CGContextRef,
const CGRect &rect) {
6114 [pb.cell drawBezelWithFrame:rect inView:pb];
6119 if (tb->subControls & SC_ToolButtonMenu) {
6120 const auto menuRect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget);
6121 QStyleOption arrowOpt = *tb;
6126 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
6127 }
else if (tb->features & QStyleOptionToolButton::HasMenu) {
6128 d->drawToolbarButtonArrow(tb, p);
6130 QRect buttonRect = proxy()->subControlRect(CC_ToolButton, tb, SC_ToolButton, widget);
6131 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
6132 QStyleOptionToolButton label = *tb;
6133 label.rect = buttonRect.adjusted(fw, fw, -fw, -fw);
6134 proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget);
6140 if (
const QStyleOptionSlider *dial = qstyleoption_cast<
const QStyleOptionSlider *>(opt))
6141 QStyleHelper::drawDial(dial, p);
6145 QCommonStyle::drawComplexControl(cc, opt, p, widget);
6237 const QWidget *widget)
const
6239 Q_D(
const QMacStyle);
6243 if (
const QStyleOptionSlider *sb = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6244 const bool isHorizontal = sb->orientation == Qt::Horizontal;
6245 const bool isReverseHorizontal = isHorizontal && (sb->direction == Qt::RightToLeft);
6247 NSScrollerPart part = NSScrollerNoPart;
6248 if (sc == SC_ScrollBarSlider) {
6249 part = NSScrollerKnob;
6250 }
else if (sc == SC_ScrollBarGroove) {
6251 part = NSScrollerKnobSlot;
6252 }
else if (sc == SC_ScrollBarSubPage || sc == SC_ScrollBarAddPage) {
6253 if ((!isReverseHorizontal && sc == SC_ScrollBarSubPage)
6254 || (isReverseHorizontal && sc == SC_ScrollBarAddPage))
6255 part = NSScrollerDecrementPage;
6257 part = NSScrollerIncrementPage;
6261 if (part != NSScrollerNoPart) {
6262 const auto ct = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical;
6263 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6264 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6265 auto *scroller =
static_cast<NSScroller *>(d->cocoaControl(cw));
6266 if (setupScroller(scroller, sb))
6267 ret = QRectF::fromCGRect([scroller rectForPart:part]).toRect();
6272 if (
const QStyleOptionSlider *sl = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6273 const bool hasTicks = sl->tickPosition != QSlider::NoTicks;
6274 const bool isHorizontal = sl->orientation == Qt::Horizontal;
6275 const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical;
6276 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6277 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6278 auto *slider =
static_cast<NSSlider *>(d->cocoaControl(cw));
6279 if (!setupSlider(slider, sl))
6282 NSSliderCell *cell = slider.cell;
6283 if (sc == SC_SliderHandle) {
6284 ret = QRectF::fromCGRect([cell knobRectFlipped:slider.isFlipped]).toRect();
6286 ret.setTop(sl->rect.top());
6287 ret.setBottom(sl->rect.bottom());
6289 ret.setLeft(sl->rect.left());
6290 ret.setRight(sl->rect.right());
6292 }
else if (sc == SC_SliderGroove) {
6293 ret = QRectF::fromCGRect([cell barRectFlipped:slider.isFlipped]).toRect();
6294 }
else if (hasTicks && sc == SC_SliderTickmarks) {
6295 const auto tickMarkRect = QRectF::fromCGRect([cell rectOfTickMarkAtIndex:0]);
6297 ret = QRect(sl->rect.left(), tickMarkRect.top(), sl->rect.width(), tickMarkRect.height());
6299 ret = QRect(tickMarkRect.left(), sl->rect.top(), tickMarkRect.width(), sl->rect.height());
6304 if (sl->upsideDown) {
6305 ret = QRect(sl->rect.right() - ret.right(), sl->rect.top(), ret.width(), sl->rect.height());
6307 ret.setTop(sl->rect.top());
6308 ret.setBottom(sl->rect.bottom());
6311 if (!sl->upsideDown) {
6312 ret = QRect(sl->rect.left(), sl->rect.bottom() - ret.bottom(), sl->rect.width(), ret.height());
6314 ret.setLeft(sl->rect.left());
6315 ret.setRight(sl->rect.right());
6321 if (
const auto *titlebar = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
6327 if (sc == SC_TitleBarLabel) {
6328 qreal labelWidth = titlebar->fontMetrics.horizontalAdvance(titlebar->text) + 1;
6329 qreal labelHeight = titlebar->fontMetrics.height();
6331 const auto lastButtonRect = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarMaxButton, widget);
6332 qreal controlsSpacing = lastButtonRect.right() + titleBarButtonSpacing;
6333 if (!titlebar->icon.isNull()) {
6334 const auto iconSize = proxy()->pixelMetric(PM_SmallIconSize);
6335 const auto actualIconSize = titlebar->icon.actualSize(QSize(iconSize, iconSize)).width();
6336 controlsSpacing += actualIconSize + titleBarIconTitleSpacing;
6339 const qreal labelPos = qMax(controlsSpacing, (opt->rect.width() - labelWidth) / 2.0);
6340 labelWidth = qMin(labelWidth, opt->rect.width() - (labelPos + titleBarTitleRightMargin));
6341 ret = QRect(labelPos, (opt->rect.height() - labelHeight) / 2,
6342 labelWidth, labelHeight);
6344 const auto currentButton = d->windowButtonCocoaControl(sc);
6345 if (currentButton == QMacStylePrivate::NoControl)
6348 QPointF buttonPos = titlebar->rect.topLeft() + QPointF(titleBarButtonSpacing, 0);
6350 for (
int ct = QMacStylePrivate::Button_WindowClose; ct <= currentButton; ct++) {
6351 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::CocoaControlType(ct),
6352 QStyleHelper::SizeLarge);
6353 auto *wb =
static_cast<NSButton *>(d->cocoaControl(cw));
6354 if (ct == currentButton)
6355 buttonSize = QSizeF::fromCGSize(wb.frame.size);
6357 buttonPos.rx() += wb.frame.size.width + titleBarButtonSpacing;
6360 const auto vOffset = (opt->rect.height() - buttonSize.height()) / 2.0;
6361 ret = QRectF(buttonPos, buttonSize).translated(0, vOffset).toRect();
6366 if (
const QStyleOptionComboBox *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
6367 const auto ct = cocoaControlType(combo, widget);
6368 const auto cs = d->effectiveAquaSizeConstrain(combo, widget);
6369 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6370 const auto editRect = QMacStylePrivate::comboboxEditBounds(cw.adjustedControlFrame(combo->rect), cw);
6373 case SC_ComboBoxEditField:{
6374 ret = editRect.toAlignedRect();
6376 case SC_ComboBoxArrow:{
6377 ret = editRect.toAlignedRect();
6378 ret.setX(ret.x() + ret.width());
6379 ret.setWidth(combo->rect.right() - ret.right());
6381 case SC_ComboBoxListBoxPopup:{
6382 if (combo->editable) {
6383 const CGRect inner = QMacStylePrivate::comboboxInnerBounds(combo->rect.toCGRect(), cw);
6384 const int comboTop = combo->rect.top();
6385 ret = QRect(qRound(inner.origin.x),
6387 qRound(inner.origin.x - combo->rect.left() + inner.size.width),
6388 editRect.bottom() - comboTop + 2);
6390 ret = QRect(combo->rect.x() + 4 - 11,
6391 combo->rect.y() + 1,
6392 editRect.width() + 10 + 11,
6402 if (
const QStyleOptionGroupBox *groupBox = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
6403 bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
6404 const bool flat = groupBox->features & QStyleOptionFrame::Flat;
6405 bool hasNoText = !checkable && groupBox->text.isEmpty();
6407 case SC_GroupBoxLabel:
6408 case SC_GroupBoxCheckBox: {
6410 const bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
6411 const bool fontIsSet = (widget && widget->testAttribute(Qt::WA_SetFont))
6412 || !QApplication::desktopSettingsAware();
6413 const int margin = flat || hasNoText ? 0 : 9;
6414 ret = groupBox->rect.adjusted(margin, 0, -margin, 0);
6416 const QFontMetricsF fm = flat || fontIsSet || !d->smallSystemFont
6417 ? QFontMetricsF(groupBox->fontMetrics)
6418 : QFontMetricsF(*d->smallSystemFont);
6419 const QSizeF s = fm.size(Qt::AlignHCenter | Qt::AlignVCenter, qt_mac_removeMnemonics(groupBox->text), 0,
nullptr);
6420 const int tw = qCeil(s.width());
6421 const int h = qCeil(fm.height());
6424 QRect labelRect = alignedRect(groupBox->direction, groupBox->textAlignment,
6426 if (flat && checkable)
6427 labelRect.moveLeft(labelRect.left() + 4);
6428 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt, widget);
6429 bool rtl = groupBox->direction == Qt::RightToLeft;
6430 if (sc == SC_GroupBoxLabel) {
6432 int newSum = indicatorWidth + 1;
6433 int newLeft = labelRect.left() + (rtl ? -newSum : newSum);
6434 labelRect.moveLeft(newLeft);
6436 labelRect.moveTop(labelRect.top() + 3);
6438 labelRect.moveTop(labelRect.top() + 4);
6440 int newLeft = labelRect.left() - (rtl ? 3 : -3);
6441 labelRect.moveLeft(newLeft);
6442 labelRect.moveTop(labelRect.top() + 3);
6444 int newLeft = labelRect.left() - (rtl ? 3 : 2);
6445 labelRect.moveLeft(newLeft);
6446 labelRect.moveTop(labelRect.top() + 4);
6451 if (sc == SC_GroupBoxCheckBox) {
6452 int left = rtl ? labelRect.right() - indicatorWidth : labelRect.left() - 1;
6453 int top = flat ? ret.top() + 1 : ret.top() + 5;
6454 ret.setRect(left, top,
6455 indicatorWidth, proxy()->pixelMetric(PM_IndicatorHeight, opt, widget));
6459 case SC_GroupBoxContents:
6460 case SC_GroupBoxFrame: {
6461 QFontMetrics fm = groupBox->fontMetrics;
6464 if (widget && !widget->testAttribute(Qt::WA_SetFont)
6465 && QApplication::desktopSettingsAware())
6466 fm = QFontMetrics(qt_app_fonts_hash()->value(
"QSmallFont", QFont()));
6471 yOffset = -qCeil(QFontMetricsF(fm).height());
6472 ret = opt->rect.adjusted(0, qCeil(QFontMetricsF(fm).height()) + yOffset, 0, 0);
6473 if (sc == SC_GroupBoxContents) {
6475 ret.adjust(3, -5, -3, -4);
6477 ret.adjust(3, 3, -3, -4);
6482 ret = QCommonStyle::subControlRect(cc, groupBox, sc, widget);
6487#if QT_CONFIG(spinbox)
6489 if (
const QStyleOptionSpinBox *spin = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
6490 QStyleHelper::WidgetSizePolicy aquaSize = d->effectiveAquaSizeConstrain(spin, widget);
6491 const auto fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin, widget);
6495 case QStyleHelper::SizeLarge:
6499 case QStyleHelper::SizeSmall:
6503 case QStyleHelper::SizeMini:
6513 case SC_SpinBoxDown: {
6514 if (spin->buttonSymbols == QAbstractSpinBox::NoButtons)
6518 const int x = spin->rect.width() - spinner_w;
6519 ret.setRect(x + spin->rect.x(), y + spin->rect.y(), spinner_w, spin->rect.height() - y * 2);
6522 case QStyleHelper::SizeLarge:
6525 case QStyleHelper::SizeSmall:
6526 hackTranslateX = -2;
6528 case QStyleHelper::SizeMini:
6529 hackTranslateX = -1;
6535 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize);
6536 NSStepperCell *cell =
static_cast<NSStepperCell *>(d->cocoaCell(cw));
6537 const CGRect outRect = [cell drawingRectForBounds:ret.toCGRect()];
6538 ret = QRectF::fromCGRect(outRect).toRect();
6542 ret.setHeight(ret.height() / 2);
6544 case SC_SpinBoxDown:
6545 ret.setY(ret.y() + ret.height() / 2);
6551 ret.translate(hackTranslateX, 0);
6552 ret = visualRect(spin->direction, spin->rect, ret);
6555 case SC_SpinBoxEditField:
6556 ret = spin->rect.adjusted(fw, fw, -fw, -fw);
6557 if (spin->buttonSymbols != QAbstractSpinBox::NoButtons) {
6558 ret.setWidth(spin->rect.width() - spinBoxSep - spinner_w);
6559 ret = visualRect(spin->direction, spin->rect, ret);
6563 ret = QCommonStyle::subControlRect(cc, spin, sc, widget);
6570 ret = QCommonStyle::subControlRect(cc, opt, sc, widget);
6571 if (sc == SC_ToolButtonMenu) {
6572#if QT_CONFIG(accessibility)
6573 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar))
6574 ret.adjust(-toolButtonArrowMargin, 0, 0, 0);
6576 ret.adjust(-1, 0, 0, 0);
6580 ret = QCommonStyle::subControlRect(cc, opt, sc, widget);
6587 const QSize &csz,
const QWidget *widget)
const
6589 Q_D(
const QMacStyle);
6591 bool useAquaGuideline =
true;
6594#if QT_CONFIG(spinbox)
6596 if (
const QStyleOptionSpinBox *vopt = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
6597 const bool hasButtons = (vopt->buttonSymbols != QAbstractSpinBox::NoButtons);
6598 const int buttonWidth = hasButtons ? proxy()->subControlRect(CC_SpinBox, vopt, SC_SpinBoxUp, widget).width() : 0;
6599 sz += QSize(buttonWidth, 0);
6603 case QStyle::CT_TabWidget:
6606 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6638#if QT_CONFIG(tabwidget)
6639 if (
const QStyleOptionTabWidgetFrame *twf
6640 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
6642 const int overlap = pixelMetric(PM_TabBarBaseOverlap, opt, widget);
6643 const int gapBetweenTabbarAndStackWidget = 2 + 14 - overlap;
6645 const auto tabDirection = QMacStylePrivate::tabDirection(twf->shape);
6646 if (tabDirection == QMacStylePrivate::North
6647 || tabDirection == QMacStylePrivate::South) {
6648 extra = QSize(2, gapBetweenTabbarAndStackWidget + 1);
6650 extra = QSize(gapBetweenTabbarAndStackWidget + 1, 2);
6656#if QT_CONFIG(tabbar)
6657 case QStyle::CT_TabBarTab:
6658 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
6659 const bool differentFont = (widget && widget->testAttribute(Qt::WA_SetFont))
6660 || !QApplication::desktopSettingsAware();
6661 const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape);
6662 const bool verticalTabs = tabDirection == QMacStylePrivate::East
6663 || tabDirection == QMacStylePrivate::West;
6665 sz = sz.transposed();
6667 int defaultTabHeight;
6668 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6670 case QStyleHelper::SizeLarge:
6671 if (tab->documentMode)
6672 defaultTabHeight = 24;
6674 defaultTabHeight = 21;
6676 if (qt_apple_runningWithLiquidGlass() && !tab->documentMode) {
6684 defaultTabHeight = 23;
6687 case QStyleHelper::SizeSmall:
6688 defaultTabHeight = 18;
6690 case QStyleHelper::SizeMini:
6691 defaultTabHeight = 16;
6697 const bool widthSet = !differentFont && tab->icon.isNull();
6699 const auto textSize = opt->fontMetrics.size(Qt::TextShowMnemonic, tab->text);
6700 sz.rwidth() = textSize.width();
6701 sz.rheight() = qMax(defaultTabHeight, textSize.height());
6703 sz.rheight() = qMax(defaultTabHeight, sz.height());
6705 sz.rwidth() += proxy()->pixelMetric(PM_TabBarTabHSpace, tab, widget);
6708 sz = sz.transposed();
6710 int maxWidgetHeight = qMax(tab->leftButtonSize.height(), tab->rightButtonSize.height());
6711 int maxWidgetWidth = qMax(tab->leftButtonSize.width(), tab->rightButtonSize.width());
6713 int widgetWidth = 0;
6714 int widgetHeight = 0;
6716 if (tab->leftButtonSize.isValid()) {
6718 widgetWidth += tab->leftButtonSize.width();
6719 widgetHeight += tab->leftButtonSize.height();
6721 if (tab->rightButtonSize.isValid()) {
6723 widgetWidth += tab->rightButtonSize.width();
6724 widgetHeight += tab->rightButtonSize.height();
6728 sz.setWidth(qMax(sz.width(), maxWidgetWidth));
6729 sz.setHeight(sz.height() + widgetHeight + padding);
6732 sz.setWidth(sz.width() + widgetWidth + padding);
6733 sz.setHeight(qMax(sz.height(), maxWidgetHeight));
6738 case QStyle::CT_PushButton: {
6739 bool isFlat =
false;
6740 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
6741 if (btn->features & QStyleOptionButton::CommandLinkButton)
6742 return QCommonStyle::sizeFromContents(ct, opt, sz, widget);
6743 isFlat = btn->features & QStyleOptionButton::Flat;
6750 const auto controlSize = d->effectiveAquaSizeConstrain(opt, widget, CT_PushButton, sz, &macsz);
6752 if (macsz.width() != -1)
6753 sz.setWidth(macsz.width());
6755 sz.rwidth() += QMacStylePrivate::PushButtonLeftOffset + QMacStylePrivate::PushButtonRightOffset + 12;
6757 if (controlSize != QStyleHelper::SizeMini)
6760 if (controlSize == QStyleHelper::SizeLarge) {
6763 if (sz.height() > 16)
6764 sz.rheight() += pushButtonDefaultHeight[QStyleHelper::SizeLarge] - 16;
6766 sz.setHeight(pushButtonDefaultHeight[QStyleHelper::SizeLarge]);
6768 if (!isFlat && !qt_apple_runningWithLiquidGlass())
6770 if (controlSize == QStyleHelper::SizeMini)
6773 sz.setHeight(pushButtonDefaultHeight[QStyleHelper::SizeSmall]);
6779 case QStyle::CT_MenuItem:
6780 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
6781 int maxpmw = mi->maxIconWidth;
6782#if QT_CONFIG(combobox)
6783 const QComboBox *comboBox = qobject_cast<
const QComboBox *>(widget);
6787 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
6791 h = mi->fontMetrics.height() + 2;
6792 if (!mi->icon.isNull()) {
6793#if QT_CONFIG(combobox)
6795 const QSize &iconSize = comboBox->iconSize();
6796 h = qMax(h, iconSize.height() + 4);
6797 maxpmw = qMax(maxpmw, iconSize.width());
6801 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
6802 h = qMax(h, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() + 4);
6806 if (mi->text.contains(QLatin1Char(
'\t')))
6808 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
6814#if QT_CONFIG(combobox)
6815 if (comboBox && comboBox->isVisible()) {
6816 QStyleOptionComboBox cmb;
6817 cmb.initFrom(comboBox);
6818 cmb.editable =
false;
6819 cmb.subControls = QStyle::SC_ComboBoxEditField;
6820 cmb.activeSubControls = QStyle::SC_None;
6821 w = qMax(w, subControlRect(QStyle::CC_ComboBox, &cmb,
6822 QStyle::SC_ComboBoxEditField,
6832 case CT_MenuBarItem:
6839 if (
const auto *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt))
6840 if (tb->features & QStyleOptionToolButton::Menu)
6844 if (
const auto *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
6845 const auto controlSize = d->effectiveAquaSizeConstrain(opt, widget);
6846 if (!cb->editable) {
6849 sz.rwidth() += QMacStylePrivate::PushButtonLeftOffset + QMacStylePrivate::PushButtonRightOffset + 24;
6851 if (controlSize != QStyleHelper::SizeMini)
6855 if (controlSize == QStyleHelper::SizeLarge && sz.height() > 16)
6856 sz.rheight() += popupButtonDefaultHeight[QStyleHelper::SizeLarge] - 16;
6864 if (controlSize == QStyleHelper::SizeMini)
6867 sz.setHeight(pushButtonDefaultHeight[controlSize]);
6873 if (proxy() ==
this) {
6876 QStyleHintReturnMask menuMask;
6877 QStyleOption myOption = *opt;
6878 myOption.rect.setSize(sz);
6879 if (proxy()->styleHint(SH_Menu_Mask, &myOption, widget, &menuMask))
6880 sz = menuMask.region.boundingRect().size();
6883 case CT_HeaderSection:{
6884 const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt);
6885 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6886 if (header->text.contains(QLatin1Char(
'\n')))
6887 useAquaGuideline =
false;
6891 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6892 const int minimumSize = 24;
6893 if (slider->orientation == Qt::Horizontal)
6894 sz = sz.expandedTo(QSize(minimumSize, sz.height()));
6896 sz = sz.expandedTo(QSize(sz.width(), minimumSize));
6899#if QT_CONFIG(itemviews)
6900 case CT_ItemViewItem:
6901 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
6902 sz = QCommonStyle::sizeFromContents(ct, vopt, csz, widget);
6903 sz.setHeight(sz.height() + 2);
6909 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6912 if (useAquaGuideline && ct != CT_PushButton) {
6915 if (d->aquaSizeConstrain(opt, widget, ct, sz, &macsz) != QStyleHelper::SizeDefault) {
6916 if (macsz.width() != -1)
6917 sz.setWidth(macsz.width());
6918 if (macsz.height() != -1)
6919 sz.setHeight(macsz.height());
6925 if (
const QStyleOptionComboBox *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)){
6926 if (combo->editable) {
6927 const auto widgetSize = d->aquaSizeConstrain(opt, widget);
6928 QMacStylePrivate::CocoaControl cw;
6929 cw.type = combo->editable ? QMacStylePrivate::ComboBox : QMacStylePrivate::Button_PopupButton;
6930 cw.size = widgetSize;
6931 const CGRect diffRect = QMacStylePrivate::comboboxInnerBounds(CGRectZero, cw);
6932 sz.rwidth() -= qRound(diffRect.size.width);
6933 sz.rheight() -= qRound(diffRect.size.height);