1252void QMacStylePrivate::drawFocusRing(QPainter *p,
const QRectF &targetRect,
int hMargin,
int vMargin,
const CocoaControl &cw)
const
1254 const bool isBigSurOrAbove = QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSBigSur;
1256 QPainterPath focusRingPath;
1257 focusRingPath.setFillRule(Qt::OddEvenFill);
1259 qreal hOffset = 0.0;
1260 qreal vOffset = 0.0;
1263 case Button_SquareButton:
1264 case SegmentedControl_Middle:
1266 auto innerRect = targetRect;
1267 if (cw.type == Button_SquareButton)
1268 innerRect = cw.adjustedControlFrame(targetRect.adjusted(hMargin, vMargin, -hMargin, -vMargin));
1269 if (cw.type == TextField)
1270 innerRect = innerRect.adjusted(hMargin, vMargin, -hMargin, -vMargin).adjusted(0.5, 0.5, -0.5, -0.5);
1271 const auto outerRect = innerRect.adjusted(-focusRingWidth, -focusRingWidth, focusRingWidth, focusRingWidth);
1272 const auto outerRadius = focusRingWidth;
1273 focusRingPath.addRect(innerRect);
1274 focusRingPath.addRoundedRect(outerRect, outerRadius, outerRadius);
1277 case Button_CheckBox: {
1278 const auto cbInnerRadius = (cw.size == QStyleHelper::SizeMini ? 2.0 : 3.0);
1279 const auto cbSize = cw.size == QStyleHelper::SizeLarge ? 13 :
1280 cw.size == QStyleHelper::SizeSmall ? 11 : 9;
1281 hOffset = hMargin + (cw.size == QStyleHelper::SizeLarge ? (qt_apple_runningWithLiquidGlass() ? 1.5 : 2.5) :
1282 cw.size == QStyleHelper::SizeSmall ? (qt_apple_runningWithLiquidGlass() ? 1.5 : 2.0) : 1.0);
1283 vOffset = 0.5 * qreal(targetRect.height() - cbSize);
1284 if (qt_apple_runningWithLiquidGlass()) {
1285 if (cw.size == QStyleHelper::SizeSmall)
1287 if (cw.size == QStyleHelper::SizeMini)
1290 const auto cbInnerRect = QRectF(0, 0, cbSize, cbSize);
1291 const auto cbOuterRadius = cbInnerRadius + focusRingWidth;
1292 const auto cbOuterRect = cbInnerRect.adjusted(-focusRingWidth, -focusRingWidth, focusRingWidth, focusRingWidth);
1293 focusRingPath.addRoundedRect(cbOuterRect, cbOuterRadius, cbOuterRadius);
1294 focusRingPath.addRoundedRect(cbInnerRect, cbInnerRadius, cbInnerRadius);
1297 case Button_RadioButton: {
1298 const auto rbSize = cw.size == QStyleHelper::SizeLarge ? 15 :
1299 cw.size == QStyleHelper::SizeSmall ? 13 : 9;
1300 hOffset = hMargin + (cw.size == QStyleHelper::SizeLarge ? (qt_apple_runningWithLiquidGlass() ? 0.5 : 1.5) :
1301 cw.size == QStyleHelper::SizeSmall ? (qt_apple_runningWithLiquidGlass() ? 0.5 : 1.0) : 1.0);
1302 vOffset = 0.5 * qreal(targetRect.height() - rbSize);
1303 const auto rbInnerRect = QRectF(0, 0, rbSize, rbSize);
1304 const auto rbOuterRect = rbInnerRect.adjusted(-focusRingWidth, -focusRingWidth, focusRingWidth, focusRingWidth);
1305 focusRingPath.addEllipse(rbInnerRect);
1306 focusRingPath.addEllipse(rbOuterRect);
1309 case Button_PullDown:
1310 case Button_PushButton: {
1312 auto *pb =
static_cast<NSButton *>(cocoaControl(cw));
1313 const QRectF frameRect = cw.adjustedControlFrame(targetRect.adjusted(hMargin, vMargin, -hMargin, -vMargin));
1314 pb.frame = frameRect.toCGRect();
1316 if (qt_apple_runningWithLiquidGlass())
1317 focusRect = QRectF::fromCGRect(qt_alignmentRectForFrame(pb.frame, cw.size, cw.type));
1319 focusRect = QRectF::fromCGRect([pb alignmentRectForFrame:pb.frame]);
1321 if (cw.type == QMacStylePrivate::Button_PushButton) {
1322 adjustPushButtonShadowMargins(focusRect, cw.size);
1323 if (cw.size == QStyleHelper::SizeMini)
1324 focusRect.adjust(0, 3, 0, -3);
1325 }
else if (cw.type == QMacStylePrivate::Button_PullDown) {
1326 focusRect -= pullDownButtonShadowMargins[cw.size];
1328 if (cw.size == QStyleHelper::SizeLarge)
1329 focusRect = focusRect.adjusted(0, 0, 0, -1);
1330 else if (cw.size == QStyleHelper::SizeMini)
1331 focusRect = focusRect.adjusted(0, -1, 0, 0);
1333 if (isBigSurOrAbove)
1334 focusRect = focusRect.translated(0, 1);
1335 const qreal innerRadius = cw.type == Button_PushButton ? 3 : 4;
1336 const qreal outerRadius = innerRadius + focusRingWidth;
1337 hOffset = focusRect.left();
1338 vOffset = focusRect.top();
1339 const auto innerRect = focusRect.translated(-focusRect.topLeft());
1340 const auto outerRect = innerRect.adjusted(-hMargin, -vMargin, hMargin, vMargin);
1341 focusRingPath.addRoundedRect(innerRect, innerRadius, innerRadius);
1342 focusRingPath.addRoundedRect(outerRect, outerRadius, outerRadius);
1345 case Button_PopupButton:
1346 case SegmentedControl_Single: {
1347 QRectF focusRect = targetRect;
1348 if (isBigSurOrAbove) {
1349 if (!qt_apple_runningWithLiquidGlass())
1350 focusRect.translate(0, -1.5);
1351 }
else if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSCatalina) {
1352 focusRect.adjust(0, 0, 0, -1);
1354 const qreal innerRadius = cw.type == Button_PushButton ? 3 : 4;
1355 const qreal outerRadius = innerRadius + focusRingWidth;
1356 hOffset = focusRect.left();
1357 vOffset = focusRect.top();
1358 const auto innerRect = focusRect.translated(-focusRect.topLeft());
1359 const auto outerRect = innerRect.adjusted(-hMargin, -vMargin, hMargin, vMargin);
1360 focusRingPath.addRoundedRect(innerRect, innerRadius, innerRadius);
1361 focusRingPath.addRoundedRect(outerRect, outerRadius, outerRadius);
1365 case SegmentedControl_First:
1366 case SegmentedControl_Last: {
1367 hOffset = targetRect.left();
1368 vOffset = targetRect.top();
1369 const qreal innerRadius = 8;
1370 const qreal outerRadius = innerRadius + focusRingWidth;
1371 const auto innerRect = targetRect.translated(-targetRect.topLeft());
1372 const auto outerRect = innerRect.adjusted(-hMargin, -vMargin, hMargin, vMargin);
1374 const auto cbFocusFramePath = [](
const QRectF &rect, qreal tRadius, qreal bRadius) {
1378 const auto topLeftCorner = QRectF(rect.topLeft(), QSizeF(tRadius, tRadius));
1379 path.arcMoveTo(topLeftCorner, 180);
1380 path.arcTo(topLeftCorner, 180, -90);
1382 path.moveTo(rect.topLeft());
1384 const auto rightEdge = rect.right() - bRadius;
1385 path.arcTo(rightEdge, rect.top(), bRadius, bRadius, 90, -90);
1386 path.arcTo(rightEdge, rect.bottom() - bRadius, bRadius, bRadius, 0, -90);
1388 path.arcTo(rect.left(), rect.bottom() - tRadius, tRadius, tRadius, 270, -90);
1390 path.lineTo(rect.bottomLeft());
1391 path.closeSubpath();
1396 const auto innerPath = cbFocusFramePath(innerRect, 0, innerRadius);
1397 focusRingPath.addPath(innerPath);
1398 const auto outerPath = cbFocusFramePath(outerRect, 2 * focusRingWidth, outerRadius);
1399 focusRingPath.addPath(outerPath);
1406 auto focusRingColor = qt_mac_toQColor(NSColor.keyboardFocusIndicatorColor.CGColor);
1411 focusRingColor.setAlphaF(0.39);
1415 p->setRenderHint(QPainter::Antialiasing);
1417 if (cw.type == SegmentedControl_First) {
1420 p->translate(hOffset, vOffset);
1421 p->fillPath(focusRingPath, focusRingColor);
3185 const QWidget *w)
const
3187 Q_D(
const QMacStyle);
3188 QMacCGContext cg(p);
3190 qCWarning(lcMacStyle) <<
"drawPrimitive:" << pe <<
"invalid (nullptr) graphics context";
3192 QWindow *window = w && w->window() ? w->window()->windowHandle() :
nullptr;
3193 d->resolveCurrentNSView(window);
3195 case PE_IndicatorArrowUp:
3196 case PE_IndicatorArrowDown:
3197 case PE_IndicatorArrowRight:
3198 case PE_IndicatorArrowLeft: {
3200 p->setRenderHint(QPainter::Antialiasing);
3201 const int xOffset = 1;
3202 qreal halfSize = 0.5 * qMin(opt->rect.width(), opt->rect.height());
3203 const qreal penWidth = qMax(halfSize / 3.0, 1.25);
3204#if QT_CONFIG(toolbutton)
3205 if (
const QToolButton *tb = qobject_cast<
const QToolButton *>(w)) {
3207 if (tb->arrowType() != Qt::NoArrow
3208 || tb->popupMode() == QToolButton::MenuButtonPopup)
3209 halfSize -= penWidth;
3213 QTransform transform;
3214 transform.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2);
3218 case PE_IndicatorArrowDown:
3220 case PE_IndicatorArrowUp:
3221 transform.rotate(180);
3223 case PE_IndicatorArrowLeft:
3224 transform.rotate(90);
3226 case PE_IndicatorArrowRight:
3227 transform.rotate(-90);
3230 p->setTransform(transform);
3232 path.moveTo(-halfSize, -halfSize * 0.5);
3233 path.lineTo(0.0, halfSize * 0.5);
3234 path.lineTo(halfSize, -halfSize * 0.5);
3236 const QPen arrowPen(opt->palette.text(), penWidth,
3237 Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
3238 p->strokePath(path, arrowPen);
3241#if QT_CONFIG(tabbar)
3242 case PE_FrameTabBarBase:
3243 if (
const QStyleOptionTabBarBase *tbb
3244 = qstyleoption_cast<
const QStyleOptionTabBarBase *>(opt)) {
3245 if (tbb->documentMode) {
3247 drawTabBase(p, tbb, w);
3251#if QT_CONFIG(tabwidget)
3252 QRegion region(tbb->rect);
3253 region -= tbb->tabBarRect.adjusted(3, 0, -3, 0);
3255 p->setClipRegion(region);
3256 QStyleOptionTabWidgetFrame twf;
3257 twf.QStyleOption::operator=(*tbb);
3258 twf.shape = tbb->shape;
3259 switch (QMacStylePrivate::tabDirection(twf.shape)) {
3260 case QMacStylePrivate::North:
3261 twf.rect = twf.rect.adjusted(0, 0, 0, 10);
3263 case QMacStylePrivate::South:
3264 twf.rect = twf.rect.adjusted(0, -10, 0, 0);
3266 case QMacStylePrivate::West:
3267 twf.rect = twf.rect.adjusted(0, 0, 10, 0);
3269 case QMacStylePrivate::East:
3270 twf.rect = twf.rect.adjusted(0, -10, 0, 0);
3273 proxy()->drawPrimitive(PE_FrameTabWidget, &twf, p, w);
3279 case PE_PanelTipLabel:
3280 p->fillRect(opt->rect, opt->palette.brush(QPalette::ToolTipBase));
3282 case PE_FrameGroupBox:
3283 if (
const auto *groupBox = qstyleoption_cast<
const QStyleOptionFrame *>(opt))
3284 if (groupBox->features & QStyleOptionFrame::Flat) {
3285 QCommonStyle::drawPrimitive(pe, groupBox, p, w);
3288#if QT_CONFIG(tabwidget)
3290 case PE_FrameTabWidget:
3293 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Box, QStyleHelper::SizeLarge);
3294 auto *box =
static_cast<NSBox *>(d->cocoaControl(cw));
3308 auto adjustedRect = opt->rect;
3309 bool needTranslation =
false;
3311 if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSMojave
3312 && !qt_apple_runningWithLiquidGlass() && !isDarkMode()) {
3325 adjustedRect.adjust(0, 0, 6, 6);
3326 needTranslation =
true;
3328 d->drawNSViewInRect(box, adjustedRect, p, ^(CGContextRef ctx,
const CGRect &rect) {
3329#if QT_CONFIG(tabwidget)
3330 if (qobject_cast<QTabWidget *>(opt->styleObject))
3331 clipTabBarFrame(opt,
this, ctx);
3333 CGContextTranslateCTM(ctx, 0, rect.origin.y + rect.size.height);
3334 CGContextScaleCTM(ctx, 1, -1);
3335 if (QOperatingSystemVersion::current() < QOperatingSystemVersion::MacOSMojave
3336 || [box isMemberOfClass:QDarkNSBox.
class]) {
3337 [box drawRect:rect];
3339 if (needTranslation)
3340 CGContextTranslateCTM(ctx, -3.0, 5.0);
3341 [box displayRectIgnoringOpacity:box.bounds inContext:NSGraphicsContext.currentContext];
3346 case PE_IndicatorToolBarSeparator: {
3348 if (opt->state & State_Horizontal) {
3349 int xpoint = opt->rect.center().x();
3350 path.moveTo(xpoint + 0.5, opt->rect.top() + 1);
3351 path.lineTo(xpoint + 0.5, opt->rect.bottom());
3353 int ypoint = opt->rect.center().y();
3354 path.moveTo(opt->rect.left() + 2 , ypoint + 0.5);
3355 path.lineTo(opt->rect.right() + 1, ypoint + 0.5);
3357 QPainterPathStroker theStroker;
3358 theStroker.setCapStyle(Qt::FlatCap);
3359 theStroker.setDashPattern(QVector<qreal>() << 1 << 2);
3360 path = theStroker.createStroke(path);
3361 const auto dark =
isDarkMode() ? opt->palette.dark().color().darker()
3362 : QColor(0, 0, 0, 119);
3363 p->fillPath(path, dark);
3366 case PE_FrameWindow:
3367 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
3368 if (qobject_cast<
const QMdiSubWindow*>(w)) {
3370 p->setPen(QPen(frame->palette.dark().color(), frame->lineWidth));
3371 p->setBrush(frame->palette.window());
3372 p->drawRect(frame->rect);
3377 case PE_IndicatorDockWidgetResizeHandle: {
3380 if (opt->state & State_Horizontal) {
3381 p->setPen(QColor(160, 160, 160));
3382 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3384 p->setPen(QColor(145, 145, 145));
3385 p->drawLine(opt->rect.topRight(), opt->rect.bottomRight());
3389 case PE_IndicatorToolBarHandle: {
3392 int x = opt->rect.x() + 6;
3393 int y = opt->rect.y() + 7;
3394 static const int RectHeight = 2;
3395 if (opt->state & State_Horizontal) {
3396 while (y < opt->rect.height() - RectHeight - 5) {
3398 path.addEllipse(x, y, RectHeight, RectHeight);
3402 while (x < opt->rect.width() - RectHeight - 5) {
3404 path.addEllipse(x, y, RectHeight, RectHeight);
3408 p->setPen(Qt::NoPen);
3409 QColor dark = opt->palette.dark().color().darker();
3410 dark.setAlphaF(0.50);
3411 p->fillPath(path, dark);
3416 case PE_IndicatorHeaderArrow:
3417 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
3419 if (header->sortIndicator != QStyleOptionHeader::None)
3420 proxy()->drawPrimitive(
3421 (header->sortIndicator == QStyleOptionHeader::SortDown) ?
3422 PE_IndicatorArrowUp : PE_IndicatorArrowDown, header, p, w);
3425 case PE_IndicatorMenuCheckMark: {
3429 if (opt->state & State_On)
3430 pc = opt->palette.highlightedText().color();
3432 pc = opt->palette.text().color();
3434 QCFType<CGColorRef> checkmarkColor = CGColorCreateGenericRGB(
static_cast<CGFloat>(pc.redF()),
3435 static_cast<CGFloat>(pc.greenF()),
3436 static_cast<CGFloat>(pc.blueF()),
3437 static_cast<CGFloat>(pc.alphaF()));
3443 const CTFontUIFontType fontType = (opt->state & State_Mini) ? kCTFontUIFontMiniSystem :
3444 (opt->state & State_Small) ? kCTFontUIFontSmallSystem :
3445 kCTFontUIFontMenuItemMark;
3449 const CGFloat fontSize = fontType == kCTFontUIFontMenuItemMark ? opt->fontMetrics.height() : 0.0;
3450 QCFType<CTFontRef> checkmarkFont = CTFontCreateUIFontForLanguage(fontType, fontSize, NULL);
3452 CGContextSaveGState(cg);
3453 CGContextSetShouldSmoothFonts(cg, NO);
3456 const CGFloat vOffset = (opt->state & State_Mini) ? 0.0 :
3457 (opt->state & State_Small) ? 1.0 :
3460 CGContextTranslateCTM(cg, 0, opt->rect.bottom());
3461 CGContextScaleCTM(cg, 1, -1);
3463 CGContextTranslateCTM(cg, opt->rect.x(), vOffset);
3467 static const CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName };
3468 static const int numValues =
sizeof(keys) /
sizeof(keys[0]);
3469 const CFTypeRef values[] = { (CFTypeRef)checkmarkFont, (CFTypeRef)checkmarkColor };
3470 static_assert((
sizeof(values) /
sizeof(values[0])) == numValues);
3471 QCFType<CFDictionaryRef> attributes = CFDictionaryCreate(kCFAllocatorDefault, (
const void **)keys, (
const void **)values,
3472 numValues, NULL, NULL);
3474 QCFType<CFAttributedStringRef> checkmarkString = CFAttributedStringCreate(kCFAllocatorDefault, (CFStringRef)@
"\u2713", attributes);
3475 QCFType<CTLineRef> line = CTLineCreateWithAttributedString(checkmarkString);
3477 CTLineDraw((CTLineRef)line, cg);
3480 CGContextRestoreGState(cg);
3482 case PE_IndicatorItemViewItemCheck:
3483 case PE_IndicatorRadioButton:
3484 case PE_IndicatorCheckBox: {
3485 const bool isEnabled = opt->state & State_Enabled;
3486 const bool isPressed = opt->state & State_Sunken;
3487 const bool isRadioButton = (pe == PE_IndicatorRadioButton);
3488 const auto ct = isRadioButton ? QMacStylePrivate::Button_RadioButton : QMacStylePrivate::Button_CheckBox;
3489 const auto cs = d->effectiveAquaSizeConstrain(opt, w);
3490 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
3491 auto *tb =
static_cast<NSButton *>(d->cocoaControl(cw));
3492 tb.enabled = isEnabled;
3493 tb.state = (opt->state & State_NoChange) ? NSControlStateValueMixed :
3494 (opt->state & State_On) ? NSControlStateValueOn : NSControlStateValueOff;
3495 [tb highlight:isPressed];
3496 const auto vOffset = [=] {
3498 if (cs == QStyleHelper::SizeMini)
3499 return ct == QMacStylePrivate::Button_CheckBox ? -0.5 : 0.5;
3501 return cs == QStyleHelper::SizeSmall ? 0.5 : 0.0;
3503 d->drawNSViewInRect(tb, opt->rect, p, ^(CGContextRef ctx,
const CGRect &rect) {
3504 CGContextTranslateCTM(ctx, 0, vOffset);
3505 [tb.cell drawInteriorWithFrame:rect inView:tb];
3508 case PE_FrameFocusRect:
3511 case PE_IndicatorBranch: {
3512 if (!(opt->state & State_Children))
3516 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Button_Disclosure, QStyleHelper::SizeLarge);
3517 NSButtonCell *triangleCell =
static_cast<NSButtonCell *>(d->cocoaCell(cw));
3518 [triangleCell setState:(opt->state & State_Open) ? NSControlStateValueOn : NSControlStateValueOff];
3519 bool viewHasFocus = (w && w->hasFocus()) || (opt->state & State_HasFocus);
3520 [triangleCell setBackgroundStyle:((opt->state & State_Selected) && viewHasFocus) ? NSBackgroundStyleEmphasized : NSBackgroundStyleNormal];
3521 [triangleCell setUserInterfaceLayoutDirection:qt_macLayoutDirectionFromQt(opt->direction)];
3523 d->setupNSGraphicsContext(cg, NO);
3526 CGRect rect = CGRectMake(qtRect.x() + 1, qtRect.y(), qtRect.width(), qtRect.height());
3527 CGContextTranslateCTM(cg, rect.origin.x, rect.origin.y + rect.size.height);
3528 CGContextScaleCTM(cg, 1, -1);
3529 CGContextTranslateCTM(cg, -rect.origin.x, -rect.origin.y);
3531 [triangleCell drawBezelWithFrame:NSRectFromCGRect(rect) inView:[triangleCell controlView]];
3533 d->restoreNSGraphicsContext(cg);
3537 QPen oldPen = p->pen();
3538 p->setPen(opt->palette.base().color().darker(140));
3539 p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
3540 p->setPen(opt->palette.base().color().darker(180));
3541 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3545 case PE_FrameLineEdit:
3546 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
3547 if (frame->state & State_Sunken) {
3548 const bool isEnabled = opt->state & State_Enabled;
3549 const bool isReadOnly = opt->state & State_ReadOnly;
3550 const bool isRounded = frame->features & QStyleOptionFrame::Rounded;
3551 const auto cs = d->effectiveAquaSizeConstrain(opt, w, CT_LineEdit);
3552 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::TextField, cs);
3553 auto *tf =
static_cast<NSTextField *>(d->cocoaControl(cw));
3554 tf.enabled = isEnabled;
3555 tf.editable = !isReadOnly;
3557 static_cast<NSTextFieldCell *>(tf.cell).bezelStyle = isRounded ? NSTextFieldRoundedBezel : NSTextFieldSquareBezel;
3558 tf.frame = opt->rect.toCGRect();
3559 d->drawNSViewInRect(tf, opt->rect, p, ^(CGContextRef,
const CGRect &rect) {
3560 if (!isDarkMode()) {
3565 CGContextRef cgContext = NSGraphicsContext.currentContext.CGContext;
3569 if (cgContext ?
bool(CGBitmapContextGetColorSpace(cgContext)) :
false) {
3570 tf.drawsBackground = YES;
3571 const QColor bgColor = frame->palette.brush(QPalette::Base).color();
3572 tf.backgroundColor = [NSColor colorWithSRGBRed:bgColor.redF()
3573 green:bgColor.greenF()
3574 blue:bgColor.blueF()
3575 alpha:bgColor.alphaF()];
3576 if (bgColor.alpha() != 255) {
3583 CGRect fixedRect = rect;
3584 if (qt_apple_runningWithLiquidGlass()) {
3589 fixedRect = CGRectInset(rect, 1., 1.);
3591 [tf.cell drawWithFrame:fixedRect inView:tf];
3594 QCommonStyle::drawPrimitive(pe, opt, p, w);
3598 case PE_PanelLineEdit:
3600 const QStyleOptionFrame *panel = qstyleoption_cast<
const QStyleOptionFrame *>(opt);
3601 if (
isDarkMode() || (panel && panel->lineWidth <= 0)) {
3607 QCommonStyle::drawPrimitive(pe, opt, p, w);
3612 drawPrimitive(PE_FrameLineEdit, opt, p, w);
3618#if QT_CONFIG(lineedit)
3619 if ((opt->state & State_HasFocus) && !qobject_cast<
const QLineEdit*>(w)) {
3620 int vmargin = pixelMetric(QStyle::PM_FocusFrameVMargin);
3621 int hmargin = pixelMetric(QStyle::PM_FocusFrameHMargin);
3622 QStyleOptionFrame focusFrame = *panel;
3623 focusFrame.rect = panel->rect.adjusted(-hmargin, -vmargin, hmargin, vmargin);
3624 drawControl(CE_FocusFrame, &focusFrame, p, w);
3630 case PE_PanelScrollAreaCorner: {
3631 const QBrush brush(opt->palette.brush(QPalette::Base));
3632 p->fillRect(opt->rect, brush);
3633 p->setPen(QPen(QColor(217, 217, 217)));
3634 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3635 p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
3637 case PE_FrameStatusBarItem:
3639#if QT_CONFIG(tabbar)
3640 case PE_IndicatorTabClose: {
3642 QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget());
3643 const QWidget *closeBtn = w;
3647 tabBar = qobject_cast<QTabBar *>(
const_cast<QWidget*>(w));
3648 closeBtn =
decltype(closeBtn)(property(
"_q_styleSheetRealCloseButton").value<
void *>());
3651 const bool documentMode = tabBar->documentMode();
3652 const QTabBarPrivate *tabBarPrivate =
static_cast<QTabBarPrivate *>(QObjectPrivate::get(tabBar));
3653 const int hoveredTabIndex = tabBarPrivate->hoveredTabIndex();
3654 if (!documentMode ||
3655 (hoveredTabIndex != -1 && ((closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) ||
3656 (closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide))))) {
3657 const bool hover = (opt->state & State_MouseOver);
3658 const bool selected = (opt->state & State_Selected);
3659 const bool pressed = (opt->state & State_Sunken);
3660 drawTabCloseButton(p, hover, selected, pressed, documentMode);
3665 case PE_PanelStatusBar: {
3666 p->fillRect(opt->rect, opt->palette.window());
3669 if (w ? qt_macWindowMainWindow(w->window()) : (opt->state & QStyle::State_Active))
3670 p->setPen(titlebarSeparatorLineActive);
3672 p->setPen(titlebarSeparatorLineInactive);
3673 p->drawLine(opt->rect.left(), opt->rect.top(), opt->rect.right(), opt->rect.top());
3677 case PE_PanelMenu: {
3679 p->fillRect(opt->rect, Qt::transparent);
3680 p->setPen(Qt::transparent);
3681 p->setBrush(opt->palette.window());
3682 p->setRenderHint(QPainter::Antialiasing,
true);
3683 const QPainterPath path = d->windowPanelPath(opt->rect);
3689 QCommonStyle::drawPrimitive(pe, opt, p, w);
3730 const QWidget *w)
const
3732 Q_D(
const QMacStyle);
3733 const QMacAutoReleasePool pool;
3734 QMacCGContext cg(p);
3736 qCWarning(lcMacStyle) <<
"drawControl:" << ce <<
"invalid (nullptr) graphics context";
3738 QWindow *window = w && w->window() ? w->window()->windowHandle() :
nullptr;
3739 d->resolveCurrentNSView(window);
3741 case CE_HeaderSection:
3742 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
3743 State flags = header->state;
3744 QRect ir = header->rect;
3748 bool noVerticalHeader =
true;
3749#if QT_CONFIG(tableview)
3751 if (
const QTableView *table = qobject_cast<
const QTableView *>(w->parentWidget()))
3752 noVerticalHeader = !table->verticalHeader()->isVisible();
3755 const bool drawLeftBorder = header->orientation == Qt::Vertical
3756 || header->position == QStyleOptionHeader::OnlyOneSection
3757 || (header->position == QStyleOptionHeader::Beginning && noVerticalHeader);
3760 const bool pressed = (flags & State_Sunken) && !(flags & State_On);
3761 p->fillRect(ir, pressed ? header->palette.dark() : header->palette.button());
3762 p->setPen(QPen(header->palette.dark(), 1.0));
3763 if (header->orientation == Qt::Horizontal)
3772 case CE_ToolButtonLabel:
3773 if (
const QStyleOptionToolButton *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
3774 QStyleOptionToolButton myTb = *tb;
3775 myTb.state &= ~State_AutoRaise;
3776#if QT_CONFIG(accessibility)
3777 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) {
3778 QRect cr = tb->rect;
3781 bool needText =
false;
3783 bool down = tb->state & (State_Sunken | State_On);
3785 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, w);
3786 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, tb, w);
3792 if (!(tb->features & QStyleOptionToolButton::Arrow)) {
3793 Qt::ToolButtonStyle tbstyle = tb->toolButtonStyle;
3794 if (tb->icon.isNull() && !tb->text.isEmpty())
3795 tbstyle = Qt::ToolButtonTextOnly;
3798 case Qt::ToolButtonTextOnly: {
3800 alignment = Qt::AlignCenter;
3802 case Qt::ToolButtonIconOnly:
3803 case Qt::ToolButtonTextBesideIcon:
3804 case Qt::ToolButtonTextUnderIcon: {
3806 QIcon::Mode iconMode = (tb->state & State_Enabled) ? QIcon::Normal
3808 QIcon::State iconState = (tb->state & State_On) ? QIcon::On
3810 QPixmap pixmap = tb->icon.pixmap(tb->rect.size().boundedTo(tb->iconSize), p->device()->devicePixelRatio(),
3811 iconMode, iconState);
3814 if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) {
3816 QSizeF size = pixmap.deviceIndependentSize();
3817 if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
3818 pr.setHeight(size.height() + 6);
3819 cr.adjust(0, pr.bottom(), 0, -3);
3820 alignment |= Qt::AlignCenter;
3822 pr.setWidth(size.width() + 8);
3823 cr.adjust(pr.right(), 0, 0, 0);
3824 alignment |= Qt::AlignLeft | Qt::AlignVCenter;
3827 if (opt->state & State_Sunken) {
3828 pr.translate(shiftX, shiftY);
3829 pixmap = darkenPixmap(pixmap);
3831 proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pixmap);
3839 QPalette pal = tb->palette;
3840 QPalette::ColorRole role = QPalette::NoRole;
3841 if (!proxy()->styleHint(SH_UnderlineShortcut, tb, w))
3842 alignment |= Qt::TextHideMnemonic;
3844 cr.translate(shiftX, shiftY);
3845 if (tbstyle == Qt::ToolButtonTextOnly
3846 || (tbstyle != Qt::ToolButtonTextOnly && !down)) {
3847 QPen pen = p->pen();
3848 QColor light = down || isDarkMode() ? Qt::black : Qt::white;
3849 light.setAlphaF(0.375f);
3851 p->drawText(cr.adjusted(0, 1, 0, 1), alignment, tb->text);
3853 if (down && tbstyle == Qt::ToolButtonTextOnly) {
3854 pal = QApplication::palette(
"QMenu");
3855 pal.setCurrentColorGroup(tb->palette.currentColorGroup());
3856 role = QPalette::HighlightedText;
3859 proxy()->drawItemText(p, cr, alignment, pal,
3860 tb->state & State_Enabled, tb->text, role);
3863 QCommonStyle::drawControl(ce, &myTb, p, w);
3868 QCommonStyle::drawControl(ce, &myTb, p, w);
3872 case CE_ToolBoxTabShape:
3873 QCommonStyle::drawControl(ce, opt, p, w);
3875 case CE_PushButtonBevel:
3876 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
3877 if (!(btn->state & (State_Raised | State_Sunken | State_On)))
3880 if (btn->features & QStyleOptionButton::CommandLinkButton) {
3881 QCommonStyle::drawControl(ce, opt, p, w);
3885 const bool hasFocus = btn->state & State_HasFocus;
3886 const bool isActive = btn->state & State_Active;
3890 if ((btn->features & QStyleOptionButton::AutoDefaultButton)
3891 && isActive && hasFocus)
3892 d->autoDefaultButton = btn->styleObject;
3893 else if (d->autoDefaultButton == btn->styleObject)
3894 d->autoDefaultButton =
nullptr;
3896 const bool isEnabled = btn->state & State_Enabled;
3897 const bool isPressed = btn->state & State_Sunken;
3898 const bool isHighlighted = isActive &&
3899 ((btn->state & State_On)
3900 || (btn->features & QStyleOptionButton::DefaultButton)
3901 || (btn->features & QStyleOptionButton::AutoDefaultButton
3902 && d->autoDefaultButton == btn->styleObject));
3903 const bool hasMenu = btn->features & QStyleOptionButton::HasMenu;
3904 const auto ct = cocoaControlType(btn, w);
3905 const auto cs = d->effectiveAquaSizeConstrain(btn, w);
3906 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
3907 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
3911 const QRectF frameRect = cw.adjustedControlFrame(btn->rect);
3912 pb.frame = frameRect.toCGRect();
3914 pb.enabled = isEnabled;
3919 [pb highlight:isPressed];
3922 if (cw.type == QMacStylePrivate::Button_SquareButton) {
3923 pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff;
3927 pb.keyEquivalent = isHighlighted ? @
"\r" : @
"";
3930 d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
3931 [pb.cell drawBezelWithFrame:r inView:pb.superview];
3935 if (hasMenu && cw.type == QMacStylePrivate::Button_SquareButton) {
3938 const int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w);
3939 const auto ir = frameRect.toRect();
3940 int arrowYOffset = 0;
3945 arrowYOffset -= ir.top();
3946 if (cw.second == QStyleHelper::SizeSmall)
3950 const auto ar = visualRect(btn->direction, ir, QRect(ir.right() - mbi - 6, ir.height() / 2 - arrowYOffset, mbi, mbi));
3952 QStyleOption arrowOpt = *opt;
3954 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, w);
3958 case CE_PushButtonLabel:
3959 if (
const QStyleOptionButton *b = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
3960 QStyleOptionButton btn(*b);
3965 const bool isEnabled = btn.state & State_Enabled;
3966 const bool hasMenu = btn.features & QStyleOptionButton::HasMenu;
3967 const bool hasIcon = !btn.icon.isNull();
3968 const bool hasText = !btn.text.isEmpty();
3969 const bool isActive = btn.state & State_Active;
3970 const bool isPressed = btn.state & State_Sunken;
3971 const bool isDefault = (btn.features & QStyleOptionButton::DefaultButton && !d->autoDefaultButton)
3972 || d->autoDefaultButton == btn.styleObject;
3976 const QRect oldRect = btn.rect;
3978 btn.rect = w->rect();
3979 const auto ct = cocoaControlType(&btn, w);
3982 if (!hasMenu && ct != QMacStylePrivate::Button_SquareButton) {
3983 if (isPressed || (isActive && isEnabled && ((btn.state & State_On) || isDefault)))
3984 btn.palette.setColor(QPalette::ButtonText, Qt::white);
3987 if (isEnabled && !isDarkMode() && QOperatingSystemVersion::current() > QOperatingSystemVersion::MacOSBigSur) {
3988 if (!isDefault && !(btn.state & State_On)) {
3991 btn.palette.setColor(QPalette::ButtonText, Qt::black);
3995 if ((!hasIcon && !hasMenu) || (hasIcon && !hasText)) {
3996 QCommonStyle::drawControl(ce, &btn, p, w);
3998 QRect freeContentRect = btn.rect;
3999 QRect textRect = itemTextRect(
4000 btn.fontMetrics, freeContentRect, Qt::AlignCenter, isEnabled, btn.text);
4002 if (ct == QMacStylePrivate::Button_SquareButton)
4003 textRect.moveTo(w ? 8 : 11, textRect.top());
4005 textRect.moveTo(w ? (15 - pushButtonBevelRectOffsets[d->effectiveAquaSizeConstrain(b, w)])
4006 : 11, textRect.top());
4010 int contentW = textRect.width();
4012 contentW += proxy()->pixelMetric(PM_MenuButtonIndicator) + 4;
4013 QIcon::Mode mode = isEnabled ? QIcon::Normal : QIcon::Disabled;
4014 if (mode == QIcon::Normal && btn.state & State_HasFocus)
4015 mode = QIcon::Active;
4017 QIcon::State state = QIcon::Off;
4018 if (btn.state & State_On)
4020 QPixmap pixmap = btn.icon.pixmap(btn.iconSize, p->device()->devicePixelRatio(), mode, state);
4021 QSizeF pixmapSize = pixmap.deviceIndependentSize();
4022 contentW += pixmapSize.width() + QMacStylePrivate::PushButtonContentPadding;
4023 int iconLeftOffset = freeContentRect.x() + (freeContentRect.width() - contentW) / 2;
4024 int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmapSize.height()) / 2;
4025 QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmapSize.width(), pixmapSize.height());
4026 QRect visualIconDestRect = visualRect(btn.direction, freeContentRect, iconDestRect);
4027 proxy()->drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap);
4028 int newOffset = iconDestRect.x() + iconDestRect.width()
4029 + QMacStylePrivate::PushButtonContentPadding - textRect.x();
4030 textRect.adjust(newOffset, 0, newOffset, 0);
4034 textRect = visualRect(btn.direction, freeContentRect, textRect);
4035 proxy()->drawItemText(p, textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, btn.palette,
4036 isEnabled, btn.text, QPalette::ButtonText);
4041#if QT_CONFIG(combobox)
4042 case CE_ComboBoxLabel:
4043 if (
const auto *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
4044 auto comboCopy = *cb;
4045 comboCopy.direction = Qt::LeftToRight;
4047 QCommonStyle::drawControl(CE_ComboBoxLabel, &comboCopy, p, w);
4051#if QT_CONFIG(tabbar)
4052 case CE_TabBarTabShape:
4053 if (
const auto *tabOpt = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
4054 if (tabOpt->documentMode) {
4056 bool isUnified =
false;
4058 QRect tabRect = tabOpt->rect;
4059 QPoint windowTabStart = w->mapTo(w->window(), tabRect.topLeft());
4060 isUnified = isInMacUnifiedToolbarArea(w->window()->windowHandle(), windowTabStart.y());
4063 const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, opt, w);
4064 drawTabShape(p, tabOpt, isUnified, tabOverlap);
4093 const bool isActive = tabOpt->state & State_Active;
4094 const bool isEnabled = tabOpt->state & State_Enabled;
4095 const bool isPressed = tabOpt->state & State_Sunken;
4096 const bool isSelected = tabOpt->state & State_Selected;
4097 const auto tabDirection = QMacStylePrivate::tabDirection(tabOpt->shape);
4098 const bool verticalTabs = tabDirection == QMacStylePrivate::East
4099 || tabDirection == QMacStylePrivate::West;
4101 QStyleOptionTab::TabPosition tp = tabOpt->position;
4102 QStyleOptionTab::SelectedPosition sp = tabOpt->selectedPosition;
4103 if (tabOpt->direction == Qt::RightToLeft && !verticalTabs) {
4104 if (tp == QStyleOptionTab::Beginning)
4105 tp = QStyleOptionTab::End;
4106 else if (tp == QStyleOptionTab::End)
4107 tp = QStyleOptionTab::Beginning;
4109 if (sp == QStyleOptionTab::NextIsSelected)
4110 sp = QStyleOptionTab::PreviousIsSelected;
4111 else if (sp == QStyleOptionTab::PreviousIsSelected)
4112 sp = QStyleOptionTab::NextIsSelected;
4121 const auto cs = d->effectiveAquaSizeConstrain(opt, w);
4123 const bool needsInactiveHack = !isActive && isSelected;
4124 const bool isBigSurOrAbove = QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSBigSur;
4125 const auto ct = !needsInactiveHack && (isSelected || tp == QStyleOptionTab::OnlyOneTab) ?
4126 QMacStylePrivate::Button_PushButton :
4127 QMacStylePrivate::Button_PopupButton;
4128 const bool isPopupButton = ct == QMacStylePrivate::Button_PopupButton;
4129 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
4130 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
4131 auto vOffset = isPopupButton ? 1 : 2;
4132 if (isBigSurOrAbove) {
4138 if (tabDirection == QMacStylePrivate::East)
4140 const auto outerAdjust = isPopupButton ? 1 : 4;
4141 const auto innerAdjust = isPopupButton ? 20 : 10;
4142 QRectF frameRect = tabOpt->rect;
4144 frameRect = QRectF(frameRect.y(), frameRect.x(), frameRect.height(), frameRect.width());
4146 frameRect = frameRect.translated(0, vOffset);
4148 case QStyleOptionTab::Beginning:
4150 if (!isSelected && tabDirection == QMacStylePrivate::West)
4151 frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0);
4153 frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0);
4155 if (isSelected && isBigSurOrAbove) {
4158 frameRect = frameRect.adjusted(0, 0, 1, 0);
4161 case QStyleOptionTab::Middle:
4162 frameRect = frameRect.adjusted(-innerAdjust, 0, innerAdjust, 0);
4164 if (isSelected && isBigSurOrAbove) {
4167 frameRect = frameRect.adjusted(-1, 0, 1, 0);
4170 case QStyleOptionTab::Moving:
4171 case QStyleOptionTab::End:
4173 if (isSelected || tabDirection == QMacStylePrivate::West)
4174 frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0);
4176 frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0);
4178 if (isSelected && isBigSurOrAbove) {
4180 frameRect = frameRect.adjusted(-1, 0, 0, 0);
4183 case QStyleOptionTab::OnlyOneTab:
4184 frameRect = frameRect.adjusted(-outerAdjust, 0, outerAdjust, 0);
4187 pb.frame = frameRect.toCGRect();
4189 if (!isPopupButton) {
4193 pb.buttonType = NSButtonTypePushOnPushOff;
4196 pb.enabled = isEnabled;
4197 [pb highlight:isPressed];
4201 if (QOperatingSystemVersion::current() > QOperatingSystemVersion::MacOSBigSur)
4202 pb.state = (isActive && isSelected) ? NSControlStateValueOn : NSControlStateValueOff;
4204 pb.state = (isActive && isSelected && !isPressed) ? NSControlStateValueOn : NSControlStateValueOff;
4206 const auto drawBezelBlock = ^(CGContextRef ctx,
const CGRect &r) {
4207 CGContextClipToRect(ctx, opt->rect.toCGRect());
4208 if (!isSelected || needsInactiveHack) {
4210 if (!verticalTabs && tp == QStyleOptionTab::End) {
4211 CGContextTranslateCTM(ctx, opt->rect.right(), 0);
4212 CGContextScaleCTM(ctx, -1, 1);
4213 CGContextTranslateCTM(ctx, -frameRect.left(), 0);
4214 }
else if (tabDirection == QMacStylePrivate::West && tp == QStyleOptionTab::Beginning) {
4215 CGContextTranslateCTM(ctx, 0, opt->rect.top());
4216 CGContextScaleCTM(ctx, 1, -1);
4217 CGContextTranslateCTM(ctx, 0, -frameRect.right());
4218 }
else if (tabDirection == QMacStylePrivate::East && tp == QStyleOptionTab::End) {
4219 CGContextTranslateCTM(ctx, 0, opt->rect.bottom());
4220 CGContextScaleCTM(ctx, 1, -1);
4221 CGContextTranslateCTM(ctx, 0, -frameRect.left());
4227 if (tabDirection == QMacStylePrivate::West) {
4228 CGContextTranslateCTM(ctx, 0, frameRect.right());
4229 CGContextRotateCTM(ctx, -M_PI_2);
4230 CGContextTranslateCTM(ctx, -frameRect.left(), 0);
4231 }
else if (tabDirection == QMacStylePrivate::East) {
4232 CGContextTranslateCTM(ctx, opt->rect.right(), 0);
4233 CGContextRotateCTM(ctx, M_PI_2);
4238 NSPopUpArrowPosition oldPosition = NSPopUpArrowAtCenter;
4239 NSPopUpButtonCell *pbCell = nil;
4241 if (isPopupButton && (tp == QStyleOptionTab::OnlyOneTab || isBigSurOrAbove)) {
4245 pbCell =
static_cast<NSPopUpButtonCell *>(pb.cell);
4246 oldPosition = pbCell.arrowPosition;
4247 pbCell.arrowPosition = NSPopUpNoArrow;
4248 if (pb.state == NSControlStateValueOff) {
4250 rAdjusted.origin.x -= 3;
4251 rAdjusted.size.width += 6;
4252 if (isBigSurOrAbove) {
4253 if (tp == QStyleOptionTab::End)
4254 rAdjusted.origin.x -= 2;
4258 if (qt_apple_runningWithLiquidGlass()) {
4267 const CGFloat deltaW = 20.0;
4268 rAdjusted = CGContextGetClipBoundingBox(ctx);
4269 if (tp == QStyleOptionTab::Beginning) {
4274 rAdjusted.size.width += deltaW;
4276 if (tabDirection == QMacStylePrivate::West && isSelected && isActive) {
4280 rAdjusted.origin.x -= deltaW;
4282 }
else if (tp == QStyleOptionTab::Middle) {
4284 rAdjusted.origin.x -= deltaW;
4285 rAdjusted.size.width += deltaW * 2;
4286 }
else if (tp == QStyleOptionTab::End) {
4287 if (isSelected && isActive && tabDirection != QMacStylePrivate::West)
4288 rAdjusted.origin.x -= deltaW;
4289 rAdjusted.size.width += deltaW;
4293 [pb.cell drawBezelWithFrame:rAdjusted inView:pb.superview];
4296 pbCell.arrowPosition = oldPosition;
4299 if (needsInactiveHack) {
4301 const qreal pixelRatio = p->device()->devicePixelRatio();
4302 QImage tabPixmap(opt->rect.size() * pixelRatio, QImage::Format_ARGB32_Premultiplied);
4303 tabPixmap.setDevicePixelRatio(pixelRatio);
4304 tabPixmap.fill(Qt::transparent);
4305 QPainter tabPainter(&tabPixmap);
4306 d->drawNSViewInRect(pb, frameRect, &tabPainter, ^(CGContextRef ctx,
const CGRect &r) {
4307 CGContextTranslateCTM(ctx, -opt->rect.left(), -opt->rect.top());
4308 drawBezelBlock(ctx, r);
4313 const qreal inactiveGray = 0.898;
4314 const int inactiveGray8 = qRound(inactiveGray * 255.0);
4315 const QRgb inactiveGrayRGB = qRgb(inactiveGray8, inactiveGray8, inactiveGray8);
4316 for (
int l = 0; l < tabPixmap.height(); ++l) {
4317 auto *line =
reinterpret_cast<QRgb*>(tabPixmap.scanLine(l));
4318 for (
int i = 0; i < tabPixmap.width(); ++i) {
4319 if (qAlpha(line[i]) == 255) {
4320 line[i] = inactiveGrayRGB;
4321 }
else if (qAlpha(line[i]) > 128) {
4322 const int g = qRound(inactiveGray * qRed(line[i]));
4323 line[i] = qRgba(g, g, g, qAlpha(line[i]));
4329 p->drawImage(opt->rect, tabPixmap);
4331 d->drawNSViewInRect(pb, frameRect, p, drawBezelBlock);
4334 if (!isSelected && sp != QStyleOptionTab::NextIsSelected
4335 && tp != QStyleOptionTab::End
4336 && tp != QStyleOptionTab::OnlyOneTab) {
4337 static const QPen separatorPen(Qt::black, 1.0);
4339 p->setOpacity(isEnabled ? 0.105 : 0.06);
4340 p->setPen(separatorPen);
4341 if (tabDirection == QMacStylePrivate::West) {
4342 p->drawLine(QLineF(opt->rect.left() + 1.5, opt->rect.bottom(),
4343 opt->rect.right() - 0.5, opt->rect.bottom()));
4344 }
else if (tabDirection == QMacStylePrivate::East) {
4345 p->drawLine(QLineF(opt->rect.left(), opt->rect.bottom(),
4346 opt->rect.right() - 0.5, opt->rect.bottom()));
4348 p->drawLine(QLineF(opt->rect.right(), opt->rect.top() + 1.0,
4349 opt->rect.right(), opt->rect.bottom() - 0.5));
4355 case CE_TabBarTabLabel:
4356 if (
const auto *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
4357 QStyleOptionTab myTab = *tab;
4358 const auto foregroundRole = w ? w->foregroundRole() : QPalette::WindowText;
4359 const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape);
4360 const bool verticalTabs = tabDirection == QMacStylePrivate::East
4361 || tabDirection == QMacStylePrivate::West;
4367 const bool nonDefaultFont = p->font() != qt_app_fonts_hash()->value(
"QComboMenuItem");
4369 if (!myTab.documentMode && (myTab.state & State_Selected) && (myTab.state & State_Active))
4370 if (
const auto *tabBar = qobject_cast<
const QTabBar *>(w))
4371 if (!tabBar->tabTextColor(tabBar->currentIndex()).isValid())
4372 myTab.palette.setColor(foregroundRole, Qt::white);
4374 if (myTab.documentMode && isDarkMode()) {
4375 if (
const auto *tabBar = qobject_cast<
const QTabBar *>(w)) {
4376 if (!tabBar->tabTextColor(myTab.tabIndex).isValid()) {
4377 bool active = (myTab.state & State_Selected) && (myTab.state & State_Active);
4378 myTab.palette.setColor(foregroundRole, active ? Qt::white : Qt::gray);
4383 int heightOffset = 0;
4386 }
else if (nonDefaultFont) {
4387 if (p->fontMetrics().height() == myTab.rect.height())
4390 myTab.rect.setHeight(myTab.rect.height() + heightOffset);
4392 QCommonStyle::drawControl(ce, &myTab, p, w);
4396#if QT_CONFIG(dockwidget)
4397 case CE_DockWidgetTitle:
4398 if (
const auto *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(opt)) {
4399 const bool isVertical = dwOpt->verticalTitleBar;
4400 const auto effectiveRect = isVertical ? opt->rect.transposed() : opt->rect;
4403 p->translate(effectiveRect.left(), effectiveRect.top() + effectiveRect.width());
4405 p->translate(-effectiveRect.left(), -effectiveRect.top());
4409 p->fillRect(effectiveRect, opt->palette.window());
4412 p->setPen(opt->palette.dark().color());
4413 p->drawLine(effectiveRect.bottomLeft(), effectiveRect.bottomRight());
4415 if (!dwOpt->title.isEmpty()) {
4416 auto titleRect = proxy()->subElementRect(SE_DockWidgetTitleBarText, opt, w);
4418 titleRect = QRect(effectiveRect.left() + opt->rect.bottom() - titleRect.bottom(),
4419 effectiveRect.top() + titleRect.left() - opt->rect.left(),
4423 const auto text = p->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
4424 proxy()->drawItemText(p, titleRect, Qt::AlignCenter | Qt::TextHideMnemonic, dwOpt->palette,
4425 dwOpt->state & State_Enabled, text, QPalette::WindowText);
4431 case CE_FocusFrame: {
4432 const auto *ff = qobject_cast<
const QFocusFrame *>(w);
4433 const auto *ffw = ff ? ff->widget() :
nullptr;
4434 const auto ct = [=] {
4436 if (qobject_cast<
const QCheckBox*>(ffw))
4437 return QMacStylePrivate::Button_CheckBox;
4438 if (qobject_cast<
const QRadioButton*>(ffw))
4439 return QMacStylePrivate::Button_RadioButton;
4440 if (qobject_cast<
const QLineEdit*>(ffw) || qobject_cast<
const QTextEdit*>(ffw))
4441 return QMacStylePrivate::TextField;
4442 if (
const auto *pb = qobject_cast<
const QPushButton *>(ffw)) {
4444 auto sizePolicy = QStyleHelper::widgetSizePolicy(ffw, opt);
4445 if (sizePolicy == QStyleHelper::SizeDefault)
4446 sizePolicy = QStyleHelper::SizeLarge;
4448 || (pb->rect().height() != pushButtonDefaultHeight[sizePolicy])) {
4449 return QMacStylePrivate::Button_SquareButton;
4451 if (pb->menu() !=
nullptr)
4452 return QMacStylePrivate::Button_PullDown;
4453 return QMacStylePrivate::Button_PushButton;
4457 return QMacStylePrivate::Box;
4459 auto cs = QStyleHelper::widgetSizePolicy(ffw, opt);
4460 if (cs == QStyleHelper::SizeDefault)
4461 cs = QStyleHelper::SizeLarge;
4462 const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, w);
4463 const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, opt, w);
4464 d->drawFocusRing(p, opt->rect, hMargin, vMargin, QMacStylePrivate::CocoaControl(ct, cs));
4466 case CE_MenuEmptyArea:
4468 if (qobject_cast<
const QAbstractItemView *>(w))
4469 proxy()->drawPrimitive(PE_PanelMenu, opt, p, w);
4473 case CE_MenuHMargin:
4474 case CE_MenuVMargin:
4475 case CE_MenuTearoff:
4476 case CE_MenuScroller:
4477 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
4478 const bool active = mi->state & State_Selected;
4480 p->fillRect(mi->rect, mi->palette.highlight());
4482 const QStyleHelper::WidgetSizePolicy widgetSize = d->aquaSizeConstrain(opt, w);
4484 if (ce == CE_MenuTearoff) {
4485 p->setPen(QPen(mi->palette.dark().color(), 1, Qt::DashLine));
4486 p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2 - 1,
4487 mi->rect.x() + mi->rect.width() - 4,
4488 mi->rect.y() + mi->rect.height() / 2 - 1);
4489 p->setPen(QPen(mi->palette.light().color(), 1, Qt::DashLine));
4490 p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2,
4491 mi->rect.x() + mi->rect.width() - 4,
4492 mi->rect.y() + mi->rect.height() / 2);
4493 }
else if (ce == CE_MenuScroller) {
4494 const QSize scrollerSize = QSize(10, 8);
4495 const int scrollerVOffset = 5;
4496 const int left = mi->rect.x() + (mi->rect.width() - scrollerSize.width()) / 2;
4497 const int right = left + scrollerSize.width();
4500 if (opt->state & State_DownArrow) {
4501 bottom = mi->rect.y() + scrollerVOffset;
4502 top = bottom + scrollerSize.height();
4504 bottom = mi->rect.bottom() - scrollerVOffset;
4505 top = bottom - scrollerSize.height();
4508 p->setRenderHint(QPainter::Antialiasing);
4510 path.moveTo(left, bottom);
4511 path.lineTo(right, bottom);
4512 path.lineTo((left + right) / 2, top);
4513 p->fillPath(path, opt->palette.buttonText());
4515 }
else if (ce != CE_MenuItem) {
4519 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
4520 CGColorRef separatorColor = [NSColor quaternaryLabelColor].CGColor;
4521 const QRect separatorRect = QRect(mi->rect.left(), mi->rect.center().y(), mi->rect.width(), 2);
4522 p->fillRect(separatorRect, qt_mac_toQColor(separatorColor));
4526 const int maxpmw = mi->maxIconWidth;
4527 const bool enabled = mi->state & State_Enabled;
4529 int xpos = mi->rect.x() + 18;
4530 int checkcol = maxpmw;
4532 p->setPen(mi->palette.text().color());
4534 p->setPen(mi->palette.highlightedText().color());
4536 p->setPen(mi->palette.buttonText().color());
4539 QStyleOption checkmarkOpt;
4540 checkmarkOpt.initFrom(w);
4545 checkmarkOpt.rect = QRect(xp, mi->rect.y() - checkmarkOpt.fontMetrics.descent(), mw, mh);
4547 checkmarkOpt.state.setFlag(State_On, active);
4548 checkmarkOpt.state.setFlag(State_Enabled, enabled);
4549 if (widgetSize == QStyleHelper::SizeMini)
4550 checkmarkOpt.state |= State_Mini;
4551 else if (widgetSize == QStyleHelper::SizeSmall)
4552 checkmarkOpt.state |= State_Small;
4555 checkmarkOpt.palette.setColor(QPalette::HighlightedText, p->pen().color());
4556 checkmarkOpt.palette.setColor(QPalette::Text, p->pen().color());
4558 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &checkmarkOpt, p, w);
4560 if (!mi->icon.isNull()) {
4561 QIcon::Mode mode = (mi->state & State_Enabled) ? QIcon::Normal
4564 int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize);
4565 QSize iconSize(smallIconSize, smallIconSize);
4566#if QT_CONFIG(combobox)
4567 if (
const QComboBox *comboBox = qobject_cast<
const QComboBox *>(w)) {
4568 iconSize = comboBox->iconSize();
4571 QPixmap pixmap = mi->icon.pixmap(iconSize, p->device()->devicePixelRatio(), mode);
4572 QRect cr(xpos, mi->rect.y(), checkcol, mi->rect.height());
4573 QSize size = pixmap.deviceIndependentSize().toSize();
4574 QRect pmr(QPoint(0, 0), size);
4575 pmr.moveCenter(cr.center());
4576 p->drawPixmap(pmr.topLeft(), pixmap);
4577 xpos += size.width() + 6;
4580 QString s = mi->text;
4581 const auto text_flags = Qt::AlignVCenter | Qt::TextHideMnemonic
4582 | Qt::TextSingleLine | Qt::AlignAbsolute;
4583 int yPos = mi->rect.y();
4584 if (widgetSize == QStyleHelper::SizeMini)
4587 const bool isSubMenu = mi->menuItemType == QStyleOptionMenuItem::SubMenu;
4588 const int tabwidth = isSubMenu ? 9 : mi->reservedShortcutWidth;
4590 QString rightMarginText;
4592 rightMarginText = QStringLiteral(
"\u25b6\ufe0e");
4595 const int tabIndex = s.indexOf(QLatin1Char(
'\t'));
4596 if (tabIndex >= 0) {
4598 rightMarginText = s.mid(tabIndex + 1);
4599 s = s.left(tabIndex);
4603 if (!rightMarginText.isEmpty()) {
4604 p->setFont(qt_app_fonts_hash()->value(
"QMenuItem", p->font()));
4607 p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags | Qt::AlignRight, rightMarginText);
4611 const QKeySequence seq = QKeySequence::fromString(rightMarginText, QKeySequence::NativeText);
4612 if (seq.count() == 1) {
4614 const int maxKeyWidth = p->fontMetrics().maxWidth();
4615 const QChar key = rightMarginText.at(rightMarginText.length() - 1);
4616 const QString modifiers = rightMarginText.left(rightMarginText.size() - 1);
4617 p->drawText(xp + tabwidth - maxKeyWidth, yPos, maxKeyWidth, mi->rect.height(), text_flags, key);
4619 p->drawText(xp, yPos, tabwidth - maxKeyWidth, mi->rect.height(),
4620 text_flags | Qt::AlignRight | Qt::TextDontClip, modifiers);
4622 p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags, rightMarginText);
4629 QFont myFont = mi->font;
4635 myFont.setPointSizeF(QFontInfo(mi->font).pointSizeF());
4640 const auto *fontEngine = QFontPrivate::get(myFont)->engineForScript(QChar::Script_Common);
4641 Q_ASSERT(fontEngine);
4642 if (fontEngine->type() == QFontEngine::Multi) {
4643 fontEngine =
static_cast<
const QFontEngineMulti *>(fontEngine)->engine(0);
4644 Q_ASSERT(fontEngine);
4646 if (fontEngine->type() == QFontEngine::Mac) {
4647 NSFont *f = (NSFont *)(CTFontRef)fontEngine->handle();
4650 const auto pc = p->pen().color();
4651 NSColor *c = [NSColor colorWithSRGBRed:pc.redF()
4656 s = qt_mac_removeMnemonics(s);
4658 QMacCGContext cgCtx(p);
4659 d->setupNSGraphicsContext(cgCtx, YES);
4665 [s.toNSString() drawAtPoint:CGPointMake(xpos, yPos)
4666 withAttributes:@{ NSFontAttributeName:f, NSForegroundColorAttributeName:c,
4667 NSObliquenessAttributeName: [NSNumber numberWithDouble: myFont.italic() ? 0.3 : 0.0],
4668 NSUnderlineStyleAttributeName: [NSNumber numberWithInt: myFont.underline() ? NSUnderlineStyleSingle
4669 : NSUnderlineStyleNone],
4670 NSStrikethroughStyleAttributeName: [NSNumber numberWithInt: myFont.strikeOut() ? NSUnderlineStyleSingle
4671 : NSUnderlineStyleNone]}];
4673 d->restoreNSGraphicsContext(cgCtx);
4676 p->drawText(xpos, yPos, mi->rect.width() - xm - tabwidth + 1,
4677 mi->rect.height(), text_flags, s);
4683 case CE_MenuBarItem:
4684 case CE_MenuBarEmptyArea:
4685 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
4686 const bool selected = (opt->state & State_Selected) && (opt->state & State_Enabled) && (opt->state & State_Sunken);
4687 const QBrush bg = selected ? mi->palette.highlight() : mi->palette.window();
4688 p->fillRect(mi->rect, bg);
4690 if (ce != CE_MenuBarItem)
4693 if (!mi->icon.isNull()) {
4694 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
4695 drawItemPixmap(p, mi->rect,
4696 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip
4697 | Qt::TextSingleLine,
4698 mi->icon.pixmap(QSize(iconExtent, iconExtent), p->device()->devicePixelRatio(),
4699 (mi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled));
4701 drawItemText(p, mi->rect,
4702 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip
4703 | Qt::TextSingleLine,
4704 mi->palette, mi->state & State_Enabled,
4705 mi->text, selected ? QPalette::HighlightedText : QPalette::ButtonText);
4709 case CE_ProgressBarLabel:
4710 case CE_ProgressBarGroove:
4713 case CE_ProgressBarContents:
4714 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
4715 const bool isIndeterminate = (pb->minimum == 0 && pb->maximum == 0);
4716 const bool vertical = !(pb->state & QStyle::State_Horizontal);
4717 const bool inverted = pb->invertedAppearance;
4718 bool reverse = (!vertical && (pb->direction == Qt::RightToLeft));
4721 QRect rect = pb->rect;
4723 const auto aquaSize = d->effectiveAquaSizeConstrain(opt, w);
4724 const QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject));
4725 if (isIndeterminate) {
4733 if (!animation && opt->styleObject) {
4734 auto *animation =
new QProgressStyleAnimation(d->animateSpeed(QMacStylePrivate::AquaProgressBar), opt->styleObject);
4736 animation->setFrameRate(QStyleAnimation::FifteenFps);
4737 d->startAnimation(animation);
4740 if (qt_apple_runningWithLiquidGlass()) {
4741 d->drawProgressBar(p, pb);
4744 rect = rect.transposed();
4745 d->setupNSGraphicsContext(cg, NO);
4746 d->setupVerticalInvertedXform(cg, reverse, vertical, rect.toCGRect());
4748 =
static_cast<QIndeterminateProgressIndicator *>(
4749 d->cocoaControl({ QMacStylePrivate::ProgressIndicator_Indeterminate, aquaSize }))) {
4750 [ipi startAnimation];
4751 [ipi drawWithFrame:rect.toCGRect() inView:d->backingStoreNSView];
4753 d->restoreNSGraphicsContext(cg);
4757 d->stopAnimation(opt->styleObject);
4759 =
static_cast<QIndeterminateProgressIndicator *>(
4760 d->cocoaControl({ QMacStylePrivate::ProgressIndicator_Indeterminate, aquaSize })))
4761 [ipi stopAnimation];
4763 if (qt_apple_runningWithLiquidGlass()) {
4764 d->drawProgressBar(p, pb);
4767 rect = rect.transposed();
4768 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::ProgressIndicator_Determinate, aquaSize);
4769 auto *pi =
static_cast<NSProgressIndicator *>(d->cocoaControl(cw));
4770 d->drawNSViewInRect(pi, rect, p, ^(CGContextRef ctx,
const CGRect &cgrect) {
4771 d->setupVerticalInvertedXform(ctx, reverse, vertical, cgrect);
4772 pi.minValue = pb->minimum;
4773 pi.maxValue = pb->maximum;
4774 pi.doubleValue = pb->progress;
4775 [pi drawRect:cgrect]; });
4782#ifndef QT_NO_MDIAREA
4783 if (!w || !qobject_cast<QMdiSubWindow *>(w->parentWidget()))
4787 if (w->testAttribute(Qt::WA_MacOpaqueSizeGrip))
4788 p->fillRect(opt->rect, opt->palette.window());
4790 QPen lineColor = QColor(82, 82, 82, 192);
4791 lineColor.setWidth(1);
4793 p->setRenderHint(QPainter::Antialiasing);
4794 p->setPen(lineColor);
4795 const Qt::LayoutDirection layoutDirection = w ? w->layoutDirection() : qApp->layoutDirection();
4796 const int NumLines = 3;
4797 for (
int l = 0; l < NumLines; ++l) {
4798 const int offset = (l * 4 + 3);
4800 if (layoutDirection == Qt::LeftToRight) {
4801 start = QPoint(opt->rect.width() - offset, opt->rect.height() - 1);
4802 end = QPoint(opt->rect.width() - 1, opt->rect.height() - offset);
4804 start = QPoint(offset, opt->rect.height() - 1);
4805 end = QPoint(1, opt->rect.height() - offset);
4807 p->drawLine(start, end);
4813 if (opt->rect.width() > 1 && opt->rect.height() > 1) {
4814 const bool isVertical = !(opt->state & QStyle::State_Horizontal);
4816 const auto ct = isVertical ? QMacStylePrivate::SplitView_Horizontal : QMacStylePrivate::SplitView_Vertical;
4817 const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
4818 auto *sv =
static_cast<NSSplitView *>(d->cocoaControl(cw));
4819 sv.frame = opt->rect.toCGRect();
4820 d->drawNSViewInRect(sv, opt->rect, p, ^(CGContextRef,
const CGRect &rect) {
4821 [sv drawDividerInRect:rect];
4824 QPen oldPen = p->pen();
4825 p->setPen(opt->palette.dark().color());
4826 if (opt->state & QStyle::State_Horizontal)
4827 p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
4829 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
4834 if (
const QStyleOptionRubberBand *rubber = qstyleoption_cast<
const QStyleOptionRubberBand *>(opt)) {
4835 QColor fillColor(opt->palette.color(QPalette::Disabled, QPalette::Highlight));
4836 if (!rubber->opaque) {
4839 strokeColor.setHsvF(0, 0, 0.86, 1.0);
4840 fillColor.setHsvF(0, 0, 0.53, 0.25);
4841 if (opt->rect.width() * opt->rect.height() <= 3) {
4842 p->fillRect(opt->rect, strokeColor);
4844 QPen oldPen = p->pen();
4845 QBrush oldBrush = p->brush();
4846 QPen pen(strokeColor);
4848 p->setBrush(fillColor);
4849 QRect adjusted = opt->rect.adjusted(1, 1, -1, -1);
4850 if (adjusted.isValid())
4851 p->drawRect(adjusted);
4853 p->setBrush(oldBrush);
4856 p->fillRect(opt->rect, fillColor);
4860#ifndef QT_NO_TOOLBAR
4862 const QStyleOptionToolBar *toolBar = qstyleoption_cast<
const QStyleOptionToolBar *>(opt);
4864 const QColor separatorColor = darkMode ? darkModeSeparatorLine : opt->palette.dark().color();
4871#if QT_CONFIG(mainwindow)
4872 if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) {
4873 if (toolBar && toolBar->toolBarArea == Qt::TopToolBarArea && mainWindow->unifiedTitleAndToolBarOnMac()) {
4876 p->setCompositionMode(QPainter::CompositionMode_Source);
4877 p->fillRect(opt->rect, Qt::transparent);
4884 const QPoint windowToolbarEnd = w->mapTo(w->window(), opt->rect.bottomLeft());
4885 const bool isEndOfUnifiedArea = !isInMacUnifiedToolbarArea(w->window()->windowHandle(), windowToolbarEnd.y() + 1);
4886 if (isEndOfUnifiedArea) {
4887 const int margin = qt_mac_aqua_get_metric(SeparatorSize);
4888 const auto separatorRect = QRect(opt->rect.left(), opt->rect.bottom(), opt->rect.width(), margin);
4889 p->fillRect(separatorRect, separatorColor);
4897 p->fillRect(opt->rect, opt->palette.window());
4900 p->setPen(separatorColor);
4901 QRect toolbarRect = darkMode ? opt->rect.adjusted(0, 0, 0, 1) : opt->rect;
4902 if (opt->state & State_Horizontal) {
4903 p->drawLine(toolbarRect.topLeft(), toolbarRect.topRight());
4904 p->drawLine(toolbarRect.bottomLeft(), toolbarRect.bottomRight());
4906 p->drawLine(toolbarRect.topLeft(), toolbarRect.bottomLeft());
4907 p->drawLine(toolbarRect.topRight(), toolbarRect.bottomRight());
4915 QCommonStyle::drawControl(ce, opt, p, w);
4930 const QWidget *widget)
const
4932 Q_D(
const QMacStyle);
4934 const int controlSize = getControlSize(opt, widget);
4937#if QT_CONFIG(itemviews)
4938 case SE_ItemViewItemText:
4939 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
4940 int fw = proxy()->pixelMetric(PM_FocusFrameHMargin, opt, widget);
4942 rect = QCommonStyle::subElementRect(sr, opt, widget);
4943 if (vopt->features & QStyleOptionViewItem::HasDecoration)
4944 rect.adjust(-fw, 0, 0, 0);
4948 case SE_ToolBoxTabContents:
4949 rect = QCommonStyle::subElementRect(sr, opt, widget);
4951 case SE_PushButtonBevel:
4952 case SE_PushButtonContents:
4953 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
4962 const auto ct = cocoaControlType(btn, widget);
4963 const auto cs = d->effectiveAquaSizeConstrain(btn, widget);
4964 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
4965 auto frameRect = cw.adjustedControlFrame(btn->rect);
4966 if (sr == SE_PushButtonContents) {
4967 frameRect -= cw.titleMargins();
4968 }
else if (cw.type != QMacStylePrivate::Button_SquareButton) {
4969 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
4970 frameRect = QRectF::fromCGRect([pb alignmentRectForFrame:frameRect.toCGRect()]);
4971 if (cw.type == QMacStylePrivate::Button_PushButton)
4972 frameRect -= pushButtonShadowMargins[cw.size];
4973 else if (cw.type == QMacStylePrivate::Button_PullDown)
4974 frameRect -= pullDownButtonShadowMargins[cw.size];
4976 rect = frameRect.toRect();
4979 case SE_HeaderLabel: {
4980 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
4981 rect.setRect(opt->rect.x() + margin, opt->rect.y(),
4982 opt->rect.width() - margin * 2, opt->rect.height() - 2);
4983 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
4985 if (header->sortIndicator != QStyleOptionHeader::None) {
4986 if (opt->state & State_Horizontal)
4992 rect = visualRect(opt->direction, opt->rect, rect);
4995 case SE_HeaderArrow: {
4996 int h = opt->rect.height();
4997 int w = opt->rect.width();
4998 int x = opt->rect.x();
4999 int y = opt->rect.y();
5000 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
5002 if (opt->state & State_Horizontal) {
5009 rect = visualRect(opt->direction, opt->rect, rect);
5012 case SE_ProgressBarGroove:
5016 case SE_ProgressBarLabel:
5018 case SE_ProgressBarContents:
5021 case SE_TreeViewDisclosureItem: {
5027#if QT_CONFIG(tabwidget)
5028 case SE_TabWidgetLeftCorner:
5029 if (
const QStyleOptionTabWidgetFrame *twf
5030 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5031 switch (twf->shape) {
5032 case QTabBar::RoundedNorth:
5033 case QTabBar::TriangularNorth:
5034 rect = QRect(QPoint(0, 0), twf->leftCornerWidgetSize);
5036 case QTabBar::RoundedSouth:
5037 case QTabBar::TriangularSouth:
5038 rect = QRect(QPoint(0, twf->rect.height() - twf->leftCornerWidgetSize.height()),
5039 twf->leftCornerWidgetSize);
5044 rect = visualRect(twf->direction, twf->rect, rect);
5047 case SE_TabWidgetRightCorner:
5048 if (
const QStyleOptionTabWidgetFrame *twf
5049 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5050 switch (twf->shape) {
5051 case QTabBar::RoundedNorth:
5052 case QTabBar::TriangularNorth:
5053 rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(), 0),
5054 twf->rightCornerWidgetSize);
5056 case QTabBar::RoundedSouth:
5057 case QTabBar::TriangularSouth:
5058 rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(),
5059 twf->rect.height() - twf->rightCornerWidgetSize.height()),
5060 twf->rightCornerWidgetSize);
5065 rect = visualRect(twf->direction, twf->rect, rect);
5068 case SE_TabWidgetTabContents:
5069 rect = QCommonStyle::subElementRect(sr, opt, widget);
5070 if (
const auto *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5071 if (twf->lineWidth != 0) {
5072 switch (QMacStylePrivate::tabDirection(twf->shape)) {
5073 case QMacStylePrivate::North:
5074 rect.adjust(+1, +14, -1, -1);
5076 case QMacStylePrivate::South:
5077 rect.adjust(+1, +1, -1, -14);
5079 case QMacStylePrivate::West:
5080 rect.adjust(+14, +1, -1, -1);
5082 case QMacStylePrivate::East:
5083 rect.adjust(+1, +1, -14, -1);
5088 case SE_TabBarTabText:
5089 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
5090 QRect dummyIconRect;
5091 d->tabLayout(tab, widget, &rect, &dummyIconRect);
5094 case SE_TabBarTabLeftButton:
5095 case SE_TabBarTabRightButton:
5096 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
5097 bool selected = tab->state & State_Selected;
5098 int verticalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget);
5099 int horizontalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget);
5102 bool verticalTabs = tab->shape == QTabBar::RoundedEast
5103 || tab->shape == QTabBar::RoundedWest
5104 || tab->shape == QTabBar::TriangularEast
5105 || tab->shape == QTabBar::TriangularWest;
5107 QRect tr = tab->rect;
5108 if (tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::TriangularSouth)
5109 verticalShift = -verticalShift;
5111 qSwap(horizontalShift, verticalShift);
5112 horizontalShift *= -1;
5113 verticalShift *= -1;
5115 if (tab->shape == QTabBar::RoundedWest || tab->shape == QTabBar::TriangularWest)
5116 horizontalShift = -horizontalShift;
5118 tr.adjust(0, 0, horizontalShift, verticalShift);
5121 tr.setBottom(tr.bottom() - verticalShift);
5122 tr.setRight(tr.right() - horizontalShift);
5125 QSize size = (sr == SE_TabBarTabLeftButton) ? tab->leftButtonSize : tab->rightButtonSize;
5126 int w = size.width();
5127 int h = size.height();
5128 int midHeight =
static_cast<
int>(qCeil(
float(tr.height() - h) / 2));
5129 int midWidth = ((tr.width() - w) / 2);
5131 bool atTheTop =
true;
5132 switch (tab->shape) {
5133 case QTabBar::RoundedWest:
5134 case QTabBar::TriangularWest:
5135 atTheTop = (sr == SE_TabBarTabLeftButton);
5137 case QTabBar::RoundedEast:
5138 case QTabBar::TriangularEast:
5139 atTheTop = (sr == SE_TabBarTabRightButton);
5142 if (sr == SE_TabBarTabLeftButton)
5143 rect = QRect(tab->rect.x() + hpadding, midHeight, w, h);
5145 rect = QRect(tab->rect.right() - w - hpadding, midHeight, w, h);
5146 rect = visualRect(tab->direction, tab->rect, rect);
5150 rect = QRect(midWidth, tr.y() + tab->rect.height() - hpadding - h, w, h);
5152 rect = QRect(midWidth, tr.y() + hpadding, w, h);
5157 case SE_LineEditContents:
5158 rect = QCommonStyle::subElementRect(sr, opt, widget);
5159#if QT_CONFIG(combobox)
5160 if (widget && qobject_cast<
const QComboBox*>(widget->parentWidget()))
5161 rect.adjust(-1, -2, 0, 0);
5164 rect.adjust(-1, -1, 0, +1);
5166 case SE_CheckBoxLayoutItem:
5168 if (controlSize == QStyleHelper::SizeLarge) {
5169 setLayoutItemMargins(+2, +3, -9, -4, &rect, opt->direction);
5170 }
else if (controlSize == QStyleHelper::SizeSmall) {
5171 setLayoutItemMargins(+1, +5, 0 , -6, &rect, opt->direction);
5173 setLayoutItemMargins(0, +7, 0 , -6, &rect, opt->direction);
5176 case SE_ComboBoxLayoutItem:
5177#ifndef QT_NO_TOOLBAR
5178 if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
5187 if (controlSize == QStyleHelper::SizeLarge) {
5188 rect.adjust(+3, +2, -3, -4);
5189 }
else if (controlSize == QStyleHelper::SizeSmall) {
5190 setLayoutItemMargins(+2, +1, -3, -4, &rect, opt->direction);
5192 setLayoutItemMargins(+1, 0, -2, 0, &rect, opt->direction);
5196 case SE_LabelLayoutItem:
5198 setLayoutItemMargins(+1, 0 , 0, 0 , &rect, opt->direction);
5200 case SE_ProgressBarLayoutItem: {
5202 int bottom =
SIZE(3, 8, 8);
5203 if (opt->state & State_Horizontal) {
5204 rect.adjust(0, +1, 0, -bottom);
5206 setLayoutItemMargins(+1, 0, -bottom, 0, &rect, opt->direction);
5210 case SE_PushButtonLayoutItem:
5211 if (
const QStyleOptionButton *buttonOpt
5212 = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
5213 if ((buttonOpt->features & QStyleOptionButton::Flat))
5215 if ((buttonOpt->features & QStyleOptionButton::CommandLinkButton)) {
5217 if (controlSize == QStyleHelper::SizeLarge)
5218 rect.adjust(+6, +4, -6, -8);
5219 else if (controlSize == QStyleHelper::SizeSmall)
5220 rect.adjust(+5, +4, -5, -6);
5222 rect.adjust(+1, 0, -1, -2);
5227 if (controlSize == QStyleHelper::SizeLarge) {
5228 rect.adjust(0, +4, 0, -8);
5229 }
else if (controlSize == QStyleHelper::SizeSmall) {
5230 rect.adjust(0, +4, 0, -6);
5232 rect.adjust(0, 0, 0, -2);
5235 case SE_RadioButtonLayoutItem:
5237 if (controlSize == QStyleHelper::SizeLarge) {
5238 setLayoutItemMargins(+2, +2 ,
5239 0, -4 , &rect, opt->direction);
5240 }
else if (controlSize == QStyleHelper::SizeSmall) {
5241 rect.adjust(0, +6, 0 , -5);
5243 rect.adjust(0, +6, 0 , -7);
5246 case SE_SliderLayoutItem:
5247 if (
const QStyleOptionSlider *sliderOpt
5248 = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5250 if (sliderOpt->tickPosition == QSlider::NoTicks) {
5251 int above =
SIZE(3, 0, 2);
5252 int below =
SIZE(4, 3, 0);
5253 if (sliderOpt->orientation == Qt::Horizontal) {
5254 rect.adjust(0, +above, 0, -below);
5256 rect.adjust(+above, 0, -below, 0);
5258 }
else if (sliderOpt->tickPosition == QSlider::TicksAbove) {
5259 int below =
SIZE(3, 2, 0);
5260 if (sliderOpt->orientation == Qt::Horizontal) {
5261 rect.setHeight(rect.height() - below);
5263 rect.setWidth(rect.width() - below);
5265 }
else if (sliderOpt->tickPosition == QSlider::TicksBelow) {
5266 int above =
SIZE(3, 2, 0);
5267 if (sliderOpt->orientation == Qt::Horizontal) {
5268 rect.setTop(rect.top() + above);
5270 rect.setLeft(rect.left() + above);
5275 case SE_FrameLayoutItem:
5277 if (
const QFrame *frame = qobject_cast<
const QFrame *>(widget)) {
5279 switch (frame->frameStyle() & QFrame::Shape_Mask) {
5281 rect.adjust(0, +1, 0, -1);
5284 rect.adjust(+1, 0, -1, 0);
5291 case SE_GroupBoxLayoutItem:
5293 if (
const QStyleOptionGroupBox *groupBoxOpt =
5294 qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
5296
5297
5298
5299
5300 if (groupBoxOpt->subControls & (QStyle::SC_GroupBoxCheckBox
5301 | QStyle::SC_GroupBoxLabel)) {
5303 if (groupBoxOpt->subControls & QStyle::SC_GroupBoxCheckBox) {
5304 delta =
SIZE(8, 4, 4);
5306 delta =
SIZE(15, 12, 12);
5308 rect.setTop(rect.top() + delta);
5311 rect.setBottom(rect.bottom() - 1);
5313#if QT_CONFIG(tabwidget)
5314 case SE_TabWidgetLayoutItem:
5315 if (
const QStyleOptionTabWidgetFrame *tabWidgetOpt =
5316 qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
5318
5319
5320
5321
5322 rect = tabWidgetOpt->rect;
5323 if (tabWidgetOpt->shape == QTabBar::RoundedNorth)
5324 rect.setTop(rect.top() + SIZE(6 , 3 , 2 ));
5328#if QT_CONFIG(dockwidget)
5329 case SE_DockWidgetCloseButton:
5330 case SE_DockWidgetFloatButton:
5331 case SE_DockWidgetTitleBarText:
5332 case SE_DockWidgetIcon: {
5333 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
5334 int buttonMargin = proxy()->pixelMetric(PM_DockWidgetTitleBarButtonMargin, opt, widget);
5335 QRect srect = opt->rect;
5337 const QStyleOptionDockWidget *dwOpt
5338 = qstyleoption_cast<
const QStyleOptionDockWidget*>(opt);
5339 bool canClose = dwOpt == 0 ?
true : dwOpt->closable;
5340 bool canFloat = dwOpt == 0 ?
false : dwOpt->floatable;
5342 const bool verticalTitleBar = dwOpt->verticalTitleBar;
5346 if (verticalTitleBar)
5347 srect = srect.transposed();
5350 int right = srect.right();
5351 int left = srect.left();
5355 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton,
5356 opt, widget).actualSize(QSize(iconSize, iconSize));
5357 sz += QSize(buttonMargin, buttonMargin);
5358 if (verticalTitleBar)
5359 sz = sz.transposed();
5360 closeRect = QRect(left,
5361 srect.center().y() - sz.height()/2,
5362 sz.width(), sz.height());
5363 left = closeRect.right() + 1;
5365 if (sr == SE_DockWidgetCloseButton) {
5372 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarNormalButton,
5373 opt, widget).actualSize(QSize(iconSize, iconSize));
5374 sz += QSize(buttonMargin, buttonMargin);
5375 if (verticalTitleBar)
5376 sz = sz.transposed();
5377 floatRect = QRect(left,
5378 srect.center().y() - sz.height()/2,
5379 sz.width(), sz.height());
5380 left = floatRect.right() + 1;
5382 if (sr == SE_DockWidgetFloatButton) {
5388 if (
const QDockWidget *dw = qobject_cast<
const QDockWidget*>(widget)) {
5390 if (dw->isFloating())
5391 icon = dw->windowIcon();
5393 && icon.cacheKey() != QApplication::windowIcon().cacheKey()) {
5394 QSize sz = icon.actualSize(QSize(rect.height(), rect.height()));
5395 if (verticalTitleBar)
5396 sz = sz.transposed();
5397 iconRect = QRect(right - sz.width(), srect.center().y() - sz.height()/2,
5398 sz.width(), sz.height());
5399 right = iconRect.left() - 1;
5402 if (sr == SE_DockWidgetIcon) {
5407 QRect textRect = QRect(left, srect.top(),
5408 right - left, srect.height());
5409 if (sr == SE_DockWidgetTitleBarText) {
5415 if (verticalTitleBar) {
5416 rect = QRect(srect.left() + rect.top() - srect.top(),
5417 srect.top() + srect.right() - rect.right(),
5418 rect.height(), rect.width());
5420 rect = visualRect(opt->direction, srect, rect);
5426 rect = QCommonStyle::subElementRect(sr, opt, widget);
5459 const QWidget *widget)
const
5461 Q_D(
const QMacStyle);
5462 QMacCGContext cg(p);
5464 qCWarning(lcMacStyle) <<
"drawComplexControl:" << cc <<
"invalid (nullptr) graphics context";
5465 QWindow *window = widget && widget->window() ? widget->window()->windowHandle() :
nullptr;
5466 d->resolveCurrentNSView(window);
5469 if (
const QStyleOptionSlider *sb = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5472 const bool drawTrack = sb->subControls & SC_ScrollBarGroove;
5473 const bool drawKnob = sb->subControls & SC_ScrollBarSlider && sb->minimum != sb->maximum;
5474 if (!drawTrack && !drawKnob)
5477 const bool isHorizontal = sb->orientation == Qt::Horizontal;
5479 if (opt && opt->styleObject && !QMacStylePrivate::scrollBars.contains(opt->styleObject))
5480 QMacStylePrivate::scrollBars.append(QPointer<QObject>(opt->styleObject));
5482 static const CGFloat knobWidths[] = { 7.0, 5.0, 5.0 };
5483 static const CGFloat expandedKnobWidths[] = { 11.0, 9.0, 9.0 };
5484 const auto cocoaSize = d->effectiveAquaSizeConstrain(opt, widget);
5485 const CGFloat maxExpandScale = expandedKnobWidths[cocoaSize] / knobWidths[cocoaSize];
5487 const QStyle *realStyle = widget ? widget->style() : proxy();
5488 const bool isTransient = realStyle->styleHint(SH_ScrollBar_Transient, opt, widget);
5490 d->stopAnimation(opt->styleObject);
5491 bool wasActive =
false;
5492 CGFloat opacity = 0.0;
5493 CGFloat expandScale = 1.0;
5494 CGFloat expandOffset = 0.0;
5495 bool shouldExpand =
false;
5497 if (QObject *styleObject = opt->styleObject) {
5498 const int oldPos = styleObject->property(
"_q_stylepos").toInt();
5499 const int oldMin = styleObject->property(
"_q_stylemin").toInt();
5500 const int oldMax = styleObject->property(
"_q_stylemax").toInt();
5501 const QRect oldRect = styleObject->property(
"_q_stylerect").toRect();
5502 const QStyle::State oldState =
static_cast<QStyle::State>(styleObject->property(
"_q_stylestate").value<QStyle::State::Int>());
5503 const uint oldActiveControls = styleObject->property(
"_q_stylecontrols").toUInt();
5507 const bool transient = isTransient && !opt->activeSubControls && !(sb->state & State_On);
5510 oldPos != sb->sliderPosition ||
5511 oldMin != sb->minimum ||
5512 oldMax != sb->maximum ||
5513 oldRect != sb->rect ||
5514 oldState != sb->state ||
5515 oldActiveControls != sb->activeSubControls) {
5521 styleObject->setProperty(
"_q_stylepos", sb->sliderPosition);
5522 styleObject->setProperty(
"_q_stylemin", sb->minimum);
5523 styleObject->setProperty(
"_q_stylemax", sb->maximum);
5524 styleObject->setProperty(
"_q_stylerect", sb->rect);
5525 styleObject->setProperty(
"_q_stylestate",
static_cast<QStyle::State::Int>(sb->state));
5526 styleObject->setProperty(
"_q_stylecontrols",
static_cast<uint>(sb->activeSubControls));
5528 QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
5531 anim =
new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Deactivating, styleObject);
5532 d->startAnimation(anim);
5533 }
else if (anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5536 anim->setCurrentTime(0);
5538 }
else if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5539 d->stopAnimation(styleObject);
5543 QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
5544 if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
5547 if (oldActiveControls)
5548 anim->setActive(
true);
5550 wasActive = anim->wasActive();
5551 opacity = anim->currentValue();
5554 shouldExpand = isTransient && (opt->activeSubControls || wasActive);
5556 if (!anim && !oldActiveControls) {
5558 anim =
new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Activating, styleObject);
5559 d->startAnimation(anim);
5561 if (anim && anim->mode() == QScrollbarStyleAnimation::Activating) {
5562 expandScale = 1.0 + (maxExpandScale - 1.0) * anim->currentValue();
5563 expandOffset = 5.5 * (1.0 - anim->currentValue());
5566 expandScale = maxExpandScale;
5572 d->setupNSGraphicsContext(cg, NO );
5574 const auto controlType = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical;
5575 const auto cw = QMacStylePrivate::CocoaControl(controlType, cocoaSize);
5576 NSScroller *scroller =
static_cast<NSScroller *>(d->cocoaControl(cw));
5578 const QColor bgColor = QStyleHelper::backgroundColor(opt->palette, widget);
5579 const bool hasDarkBg = bgColor.red() < 128 && bgColor.green() < 128 && bgColor.blue() < 128;
5583 scroller.knobStyle = hasDarkBg? NSScrollerKnobStyleLight : NSScrollerKnobStyleDark;
5585 scroller.knobStyle = NSScrollerKnobStyleDefault;
5588 scroller.scrollerStyle = isTransient ? NSScrollerStyleOverlay : NSScrollerStyleLegacy;
5590 if (!setupScroller(scroller, sb))
5594 CGContextBeginTransparencyLayerWithRect(cg, scroller.frame,
nullptr);
5595 CGContextSetAlpha(cg, opacity);
5600 if (!isTransient || opt->activeSubControls || wasActive) {
5601 CGRect trackRect = scroller.bounds;
5603 trackRect.origin.y += expandOffset;
5605 trackRect.origin.x += expandOffset;
5606 [scroller drawKnobSlotInRect:trackRect highlight:NO];
5616 const CGFloat scrollerWidth = [NSScroller scrollerWidthForControlSize:scroller.controlSize scrollerStyle:scroller.scrollerStyle];
5617 const CGFloat knobWidth = knobWidths[cocoaSize] * expandScale;
5619 const CGRect scrollerKnobRect = CGRectInset([scroller rectForPart:NSScrollerKnob], 1, 1);
5620 const CGFloat knobLength = isHorizontal ? scrollerKnobRect.size.width : scrollerKnobRect.size.height;
5621 const CGFloat knobPos = isHorizontal ? scrollerKnobRect.origin.x : scrollerKnobRect.origin.y;
5622 const CGFloat knobOffset = qRound((scrollerWidth + expandOffset - knobWidth) / 2.0);
5623 const CGFloat knobRadius = knobWidth / 2.0;
5626 knobRect = CGRectMake(knobPos, knobOffset, knobLength, knobWidth);
5628 knobRect = CGRectMake(knobOffset, knobPos, knobWidth, knobLength);
5629 QCFType<CGPathRef> knobPath = CGPathCreateWithRoundedRect(knobRect, knobRadius, knobRadius,
nullptr);
5630 CGContextAddPath(cg, knobPath);
5631 CGContextSetAlpha(cg, 0.5);
5632 CGColorRef knobColor = hasDarkBg ? NSColor.whiteColor.CGColor : NSColor.blackColor.CGColor;
5633 CGContextSetFillColorWithColor(cg, knobColor);
5634 CGContextFillPath(cg);
5636 [scroller drawKnob];
5638 if (!isTransient && opt->activeSubControls) {
5643 CGContextSetBlendMode(cg, kCGBlendModePlusDarker);
5644 [scroller drawKnob];
5650 CGContextEndTransparencyLayer(cg);
5652 d->restoreNSGraphicsContext(cg);
5656 if (
const QStyleOptionSlider *sl = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
5657 const bool isHorizontal = sl->orientation == Qt::Horizontal;
5658 const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical;
5659 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
5660 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5661 auto *slider =
static_cast<NSSlider *>(d->cocoaControl(cw));
5662 if (!setupSlider(slider, sl))
5665 const bool hasTicks = sl->tickPosition != QSlider::NoTicks;
5666 const bool hasDoubleTicks = sl->tickPosition == QSlider::TicksBothSides;
5667 const bool drawKnob = sl->subControls & SC_SliderHandle;
5668 const bool drawBar = sl->subControls & SC_SliderGroove;
5669 const bool drawTicks = sl->subControls & SC_SliderTickmarks;
5670 const bool isPressed = qt_apple_runningWithLiquidGlass() ?
false : sl->state & State_Sunken;
5674 const CGRect knobRect = [slider.cell knobRectFlipped:slider.isFlipped];
5675 pressPoint.x = CGRectGetMidX(knobRect);
5676 pressPoint.y = CGRectGetMidY(knobRect);
5691 [slider.cell startTrackingAt:pressPoint inView:slider];
5692 [slider.cell startTrackingAt:pressPoint inView:slider];
5695 d->drawNSViewInRect(slider, opt->rect, p, ^(CGContextRef ctx,
const CGRect &rect) {
5698 const bool verticalFlip = !isHorizontal && !sl->upsideDown;
5701 if (sl->upsideDown) {
5702 CGContextTranslateCTM(ctx, rect.size.width, rect.origin.y);
5703 CGContextScaleCTM(ctx, -1, 1);
5705 CGContextTranslateCTM(ctx, 0, rect.origin.y);
5707 }
else if (verticalFlip) {
5708 CGContextTranslateCTM(ctx, rect.origin.x, rect.size.height);
5709 CGContextScaleCTM(ctx, 1, -1);
5712 if (hasDoubleTicks) {
5715 CGContextTranslateCTM(ctx, 0, 4);
5717 CGContextTranslateCTM(ctx, 1, 0);
5724 const bool drawAllParts = drawKnob && drawBar && (!hasTicks || drawTicks);
5725 if (drawAllParts && !hasDoubleTicks && (!verticalFlip || drawTicks)) {
5729 if (verticalFlip && drawTicks) {
5732 slider.intValue = slider.maxValue - slider.intValue + slider.minValue;
5734 [slider drawRect:CGRectZero];
5738 NSSliderCell *cell = slider.cell;
5740 const int numberOfTickMarks = slider.numberOfTickMarks;
5743 slider.numberOfTickMarks = 0;
5745 const CGRect barRect = [cell barRectFlipped:slider.isFlipped];
5747 if (!isHorizontal && !sl->upsideDown && (hasDoubleTicks || !hasTicks)) {
5755 [cell drawBarInside:barRect flipped:
true];
5757 [cell drawBarInside:barRect flipped:!verticalFlip];
5761 slider.numberOfTickMarks = numberOfTickMarks;
5764 if (hasTicks && drawTicks) {
5765 if (!drawBar && hasDoubleTicks)
5766 slider.numberOfTickMarks = numberOfTickMarks;
5768 if (qt_apple_runningWithLiquidGlass())
5769 drawTickMarks(ctx, slider, sl);
5771 [cell drawTickMarks];
5773 if (hasDoubleTicks) {
5775 CGAffineTransform tickMarksFlip;
5776 const CGRect tickMarkRect = [cell rectOfTickMarkAtIndex:0];
5778 tickMarksFlip = CGAffineTransformMakeTranslation(0, rect.size.height - tickMarkRect.size.height - 3);
5779 tickMarksFlip = CGAffineTransformScale(tickMarksFlip, 1, -1);
5781 tickMarksFlip = CGAffineTransformMakeTranslation(rect.size.width - tickMarkRect.size.width / 2, 0);
5782 tickMarksFlip = CGAffineTransformScale(tickMarksFlip, -1, 1);
5784 CGContextConcatCTM(ctx, tickMarksFlip);
5785 [cell drawTickMarks];
5786 CGContextConcatCTM(ctx, CGAffineTransformInvert(tickMarksFlip));
5793 slider.numberOfTickMarks = 0;
5794 if (qt_apple_runningWithLiquidGlass())
5795 drawSliderKnob(ctx, slider);
5805 [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO];
5806 [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO];
5810#if QT_CONFIG(spinbox)
5812 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
5813 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
5814 const auto lineEditRect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget);
5815 QStyleOptionFrame frame;
5816 static_cast<QStyleOption &>(frame) = *opt;
5817 frame.rect = lineEditRect;
5818 frame.state |= State_Sunken;
5819 frame.lineWidth = 1;
5820 frame.midLineWidth = 0;
5821 frame.features = QStyleOptionFrame::None;
5822 frame.frameShape = QFrame::Box;
5823 drawPrimitive(PE_FrameLineEdit, &frame, p, widget);
5825 if (sb->subControls & (SC_SpinBoxUp | SC_SpinBoxDown)) {
5826 const QRect updown = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget)
5827 | proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
5830 d->setupNSGraphicsContext(cg, NO);
5832 const auto aquaSize = d->effectiveAquaSizeConstrain(opt, widget);
5833 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize);
5834 NSStepperCell *cell =
static_cast<NSStepperCell *>(d->cocoaCell(cw));
5835 const auto controlSize = cell.controlSize;
5836 if (qt_apple_runningWithLiquidGlass())
5837 cell.controlSize = NSControlSizeMini;
5838 cell.enabled = (sb->state & State_Enabled);
5840 const CGRect newRect = [cell drawingRectForBounds:updown.toCGRect()];
5842 const bool upPressed = sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken);
5843 const bool downPressed = sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken);
5844 const CGFloat x = CGRectGetMidX(newRect);
5845 const CGFloat y = upPressed ? -3 : 3;
5846 const CGPoint pressPoint = CGPointMake(x, y);
5849 if (upPressed || downPressed)
5850 [cell startTrackingAt:pressPoint inView:d->backingStoreNSView];
5852 [cell drawWithFrame:newRect inView:d->backingStoreNSView];
5854 if (upPressed || downPressed)
5855 [cell stopTracking:pressPoint at:pressPoint inView:d->backingStoreNSView mouseIsUp:NO];
5857 d->restoreNSGraphicsContext(cg);
5858 if (qt_apple_runningWithLiquidGlass())
5859 cell.controlSize = controlSize;
5864#if QT_CONFIG(combobox)
5866 if (
const auto *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
5867 const bool isEnabled = combo->state & State_Enabled;
5868 const bool isPressed = combo->state & State_Sunken;
5870 const auto ct = cocoaControlType(combo, widget);
5871 const auto cs = d->effectiveAquaSizeConstrain(combo, widget);
5872 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5873 auto *cc =
static_cast<NSControl *>(d->cocoaControl(cw));
5874 cc.enabled = isEnabled;
5875 QRectF frameRect = cw.adjustedControlFrame(combo->rect);
5876 if (cw.type == QMacStylePrivate::Button_PopupButton) {
5878 auto *pb =
static_cast<NSPopUpButton *>(cc);
5880 if (cw.size == QStyleHelper::SizeSmall) {
5881 frameRect = frameRect.translated(0, 1);
5882 }
else if (cw.size == QStyleHelper::SizeMini) {
5884 frameRect = frameRect.translated(2, -0.5);
5886 pb.frame = frameRect.toCGRect();
5887 [pb highlight:isPressed];
5888 d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
5889 [pb.cell drawBezelWithFrame:r inView:pb.superview];
5891 }
else if (cw.type == QMacStylePrivate::ComboBox) {
5893 auto *cb =
static_cast<NSComboBox *>(cc);
5894 const auto frameRect = cw.adjustedControlFrame(combo->rect);
5895 cb.frame = frameRect.toCGRect();
5898 if (NSButtonCell *cell =
static_cast<NSButtonCell *>([cc.cell qt_valueForPrivateKey:@
"_buttonCell"])) {
5899 cell.highlighted = isPressed;
5904 d->drawNSViewInRect(cb, frameRect, p, ^(CGContextRef,
const CGRect &r) {
5906 [cb.cell drawWithFrame:r inView:cb];
5910 if (combo->state & State_HasFocus) {
5912 const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, combo, widget);
5913 const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, combo, widget);
5915 if (cw.type == QMacStylePrivate::Button_PopupButton) {
5916 if (qt_apple_runningWithLiquidGlass())
5917 focusRect = QRectF::fromCGRect(qt_alignmentRectForFrame(cc.frame, cw.size, cw.type));
5919 focusRect = QRectF::fromCGRect([cc alignmentRectForFrame:cc.frame]);
5920 focusRect -= pullDownButtonShadowMargins[cw.size];
5921 if (cw.size == QStyleHelper::SizeSmall)
5922 focusRect = focusRect.translated(0, 1);
5923 else if (cw.size == QStyleHelper::SizeMini)
5924 focusRect = focusRect.translated(2, -1);
5925 }
else if (cw.type == QMacStylePrivate::ComboBox) {
5926 focusRect = frameRect - comboBoxFocusRingMargins[cw.size];
5928 d->drawFocusRing(p, focusRect, hMargin, vMargin, cw);
5934 if (
const auto *titlebar = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
5935 const bool isActive = (titlebar->state & State_Active)
5936 && (titlebar->titleBarState & State_Active);
5938 p->fillRect(opt->rect, Qt::transparent);
5939 p->setRenderHint(QPainter::Antialiasing);
5940 p->setClipRect(opt->rect, Qt::IntersectClip);
5944 const auto outerFrameRect = QRectF(opt->rect.adjusted(0, 0, 0, opt->rect.height()));
5945 QPainterPath outerFramePath = d->windowPanelPath(outerFrameRect);
5946 p->fillPath(outerFramePath, opt->palette.dark());
5948 const auto frameAdjust = 1.0 / p->device()->devicePixelRatio();
5949 const auto innerFrameRect = outerFrameRect.adjusted(frameAdjust, frameAdjust, -frameAdjust, 0);
5950 QPainterPath innerFramePath = d->windowPanelPath(innerFrameRect);
5951 p->fillPath(innerFramePath, opt->palette.button());
5953 if (titlebar->subControls & (SC_TitleBarCloseButton
5954 | SC_TitleBarMaxButton
5955 | SC_TitleBarMinButton
5956 | SC_TitleBarNormalButton)) {
5957 const bool isHovered = (titlebar->state & State_MouseOver);
5958 static const SubControl buttons[] = {
5959 SC_TitleBarCloseButton, SC_TitleBarMinButton, SC_TitleBarMaxButton
5961 for (
const auto sc : buttons) {
5962 const auto ct = d->windowButtonCocoaControl(sc);
5963 const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
5964 auto *wb =
static_cast<NSButton *>(d->cocoaControl(cw));
5965 wb.enabled = (sc & titlebar->subControls) && isActive;
5966 [wb highlight:(titlebar->state & State_Sunken) && (sc & titlebar->activeSubControls)];
5967 Q_UNUSED(isHovered);
5969 const auto buttonRect = proxy()->subControlRect(CC_TitleBar, titlebar, sc, widget);
5970 d->drawNSViewInRect(wb, buttonRect, p, ^(CGContextRef,
const CGRect &rect) {
5971 auto *wbCell =
static_cast<NSButtonCell *>(wb.cell);
5972 [wbCell drawWithFrame:rect inView:wb];
5977 if (titlebar->subControls & SC_TitleBarLabel) {
5978 const auto tr = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarLabel, widget);
5979 if (!titlebar->icon.isNull()) {
5980 const auto iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
5981 const auto iconSize = QSize(iconExtent, iconExtent);
5982 const auto iconPos = tr.x() - titlebar->icon.actualSize(iconSize).width() - qRound(titleBarIconTitleSpacing);
5984 if (iconPos < tr.right() - titleBarIconTitleSpacing)
5985 p->drawPixmap(iconPos, tr.y(), titlebar->icon.pixmap(iconSize, QIcon::Normal));
5988 if (!titlebar->text.isEmpty())
5989 drawItemText(p, tr, Qt::AlignCenter, opt->palette, isActive, titlebar->text, QPalette::Text);
5994 if (
const QStyleOptionGroupBox *gb
5995 = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
5997 QStyleOptionGroupBox groupBox(*gb);
5998 const bool flat = groupBox.features & QStyleOptionFrame::Flat;
6000 groupBox.state |= QStyle::State_Mini;
6002 groupBox.subControls = groupBox.subControls & ~SC_GroupBoxFrame;
6004 const bool didSetFont = widget && widget->testAttribute(Qt::WA_SetFont);
6005 const bool didModifySubControls = !didSetFont && QApplication::desktopSettingsAware();
6006 if (didModifySubControls)
6007 groupBox.subControls = groupBox.subControls & ~SC_GroupBoxLabel;
6008 QCommonStyle::drawComplexControl(cc, &groupBox, p, widget);
6009 if (didModifySubControls) {
6010 const QRect rect = proxy()->subControlRect(CC_GroupBox, &groupBox, SC_GroupBoxLabel, widget);
6011 const bool rtl = groupBox.direction == Qt::RightToLeft;
6012 const int alignment = Qt::TextHideMnemonic | (rtl ? Qt::AlignRight : Qt::AlignLeft);
6013 const QFont savedFont = p->font();
6014 if (!flat && d->smallSystemFont)
6015 p->setFont(*d->smallSystemFont);
6016 proxy()->drawItemText(p, rect, alignment, groupBox.palette, groupBox.state & State_Enabled, groupBox.text, QPalette::WindowText);
6018 p->setFont(savedFont);
6023 if (
const QStyleOptionToolButton *tb
6024 = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
6025#if QT_CONFIG(accessibility)
6026 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) {
6027 if (tb->subControls & SC_ToolButtonMenu) {
6028 QStyleOption arrowOpt = *tb;
6029 arrowOpt.rect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget);
6030 arrowOpt.rect.setY(arrowOpt.rect.y() + arrowOpt.rect.height() / 2);
6031 arrowOpt.rect.setHeight(arrowOpt.rect.height() / 2);
6032 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
6033 }
else if ((tb->features & QStyleOptionToolButton::HasMenu)
6034 && (tb->toolButtonStyle != Qt::ToolButtonTextOnly && !tb->icon.isNull())) {
6035 d->drawToolbarButtonArrow(tb, p);
6037 if (tb->state & State_On) {
6038 NSView *view = window ? (NSView *)window->winId() : nil;
6041 isKey = [view.window isKeyWindow];
6043 QBrush brush(brushForToolButton(isKey));
6045 path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4);
6046 p->setRenderHint(QPainter::Antialiasing);
6047 p->fillPath(path, brush);
6049 proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget);
6053 auto bflags = tb->state;
6054 if (tb->subControls & SC_ToolButton)
6055 bflags |= State_Sunken;
6056 auto mflags = tb->state;
6057 if (tb->subControls & SC_ToolButtonMenu)
6058 mflags |= State_Sunken;
6060 if (tb->subControls & SC_ToolButton) {
6061 if (bflags & (State_Sunken | State_On | State_Raised)) {
6062 const bool isEnabled = tb->state & State_Enabled;
6063 const bool isPressed = tb->state & State_Sunken;
6064 const bool isHighlighted = (tb->state & State_Active) && (tb->state & State_On);
6065 const auto ct = QMacStylePrivate::Button_PushButton;
6066 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6067 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6068 auto *pb =
static_cast<NSButton *>(d->cocoaControl(cw));
6069 pb.bezelStyle = NSBezelStyleShadowlessSquare;
6070 pb.frame = opt->rect.toCGRect();
6071 pb.buttonType = NSButtonTypePushOnPushOff;
6072 pb.enabled = isEnabled;
6073 [pb highlight:isPressed];
6074 pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff;
6075 const auto buttonRect = proxy()->subControlRect(cc, tb, SC_ToolButton, widget);
6076 d->drawNSViewInRect(pb, buttonRect, p, ^(CGContextRef,
const CGRect &rect) {
6077 [pb.cell drawBezelWithFrame:rect inView:pb];
6082 if (tb->subControls & SC_ToolButtonMenu) {
6083 const auto menuRect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget);
6084 QStyleOption arrowOpt = *tb;
6089 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
6090 }
else if (tb->features & QStyleOptionToolButton::HasMenu) {
6091 d->drawToolbarButtonArrow(tb, p);
6093 QRect buttonRect = proxy()->subControlRect(CC_ToolButton, tb, SC_ToolButton, widget);
6094 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
6095 QStyleOptionToolButton label = *tb;
6096 label.rect = buttonRect.adjusted(fw, fw, -fw, -fw);
6097 proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget);
6103 if (
const QStyleOptionSlider *dial = qstyleoption_cast<
const QStyleOptionSlider *>(opt))
6104 QStyleHelper::drawDial(dial, p);
6108 QCommonStyle::drawComplexControl(cc, opt, p, widget);
6200 const QWidget *widget)
const
6202 Q_D(
const QMacStyle);
6206 if (
const QStyleOptionSlider *sb = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6207 const bool isHorizontal = sb->orientation == Qt::Horizontal;
6208 const bool isReverseHorizontal = isHorizontal && (sb->direction == Qt::RightToLeft);
6210 NSScrollerPart part = NSScrollerNoPart;
6211 if (sc == SC_ScrollBarSlider) {
6212 part = NSScrollerKnob;
6213 }
else if (sc == SC_ScrollBarGroove) {
6214 part = NSScrollerKnobSlot;
6215 }
else if (sc == SC_ScrollBarSubPage || sc == SC_ScrollBarAddPage) {
6216 if ((!isReverseHorizontal && sc == SC_ScrollBarSubPage)
6217 || (isReverseHorizontal && sc == SC_ScrollBarAddPage))
6218 part = NSScrollerDecrementPage;
6220 part = NSScrollerIncrementPage;
6224 if (part != NSScrollerNoPart) {
6225 const auto ct = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical;
6226 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6227 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6228 auto *scroller =
static_cast<NSScroller *>(d->cocoaControl(cw));
6229 if (setupScroller(scroller, sb))
6230 ret = QRectF::fromCGRect([scroller rectForPart:part]).toRect();
6235 if (
const QStyleOptionSlider *sl = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6236 const bool hasTicks = sl->tickPosition != QSlider::NoTicks;
6237 const bool isHorizontal = sl->orientation == Qt::Horizontal;
6238 const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical;
6239 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6240 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6241 auto *slider =
static_cast<NSSlider *>(d->cocoaControl(cw));
6242 if (!setupSlider(slider, sl))
6245 NSSliderCell *cell = slider.cell;
6246 if (sc == SC_SliderHandle) {
6247 ret = QRectF::fromCGRect([cell knobRectFlipped:slider.isFlipped]).toRect();
6249 ret.setTop(sl->rect.top());
6250 ret.setBottom(sl->rect.bottom());
6252 ret.setLeft(sl->rect.left());
6253 ret.setRight(sl->rect.right());
6255 }
else if (sc == SC_SliderGroove) {
6256 ret = QRectF::fromCGRect([cell barRectFlipped:slider.isFlipped]).toRect();
6257 }
else if (hasTicks && sc == SC_SliderTickmarks) {
6258 const auto tickMarkRect = QRectF::fromCGRect([cell rectOfTickMarkAtIndex:0]);
6260 ret = QRect(sl->rect.left(), tickMarkRect.top(), sl->rect.width(), tickMarkRect.height());
6262 ret = QRect(tickMarkRect.left(), sl->rect.top(), tickMarkRect.width(), sl->rect.height());
6267 if (sl->upsideDown) {
6268 ret = QRect(sl->rect.right() - ret.right(), sl->rect.top(), ret.width(), sl->rect.height());
6270 ret.setTop(sl->rect.top());
6271 ret.setBottom(sl->rect.bottom());
6274 if (!sl->upsideDown) {
6275 ret = QRect(sl->rect.left(), sl->rect.bottom() - ret.bottom(), sl->rect.width(), ret.height());
6277 ret.setLeft(sl->rect.left());
6278 ret.setRight(sl->rect.right());
6284 if (
const auto *titlebar = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
6290 if (sc == SC_TitleBarLabel) {
6291 qreal labelWidth = titlebar->fontMetrics.horizontalAdvance(titlebar->text) + 1;
6292 qreal labelHeight = titlebar->fontMetrics.height();
6294 const auto lastButtonRect = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarMaxButton, widget);
6295 qreal controlsSpacing = lastButtonRect.right() + titleBarButtonSpacing;
6296 if (!titlebar->icon.isNull()) {
6297 const auto iconSize = proxy()->pixelMetric(PM_SmallIconSize);
6298 const auto actualIconSize = titlebar->icon.actualSize(QSize(iconSize, iconSize)).width();
6299 controlsSpacing += actualIconSize + titleBarIconTitleSpacing;
6302 const qreal labelPos = qMax(controlsSpacing, (opt->rect.width() - labelWidth) / 2.0);
6303 labelWidth = qMin(labelWidth, opt->rect.width() - (labelPos + titleBarTitleRightMargin));
6304 ret = QRect(labelPos, (opt->rect.height() - labelHeight) / 2,
6305 labelWidth, labelHeight);
6307 const auto currentButton = d->windowButtonCocoaControl(sc);
6308 if (currentButton == QMacStylePrivate::NoControl)
6311 QPointF buttonPos = titlebar->rect.topLeft() + QPointF(titleBarButtonSpacing, 0);
6313 for (
int ct = QMacStylePrivate::Button_WindowClose; ct <= currentButton; ct++) {
6314 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::CocoaControlType(ct),
6315 QStyleHelper::SizeLarge);
6316 auto *wb =
static_cast<NSButton *>(d->cocoaControl(cw));
6317 if (ct == currentButton)
6318 buttonSize = QSizeF::fromCGSize(wb.frame.size);
6320 buttonPos.rx() += wb.frame.size.width + titleBarButtonSpacing;
6323 const auto vOffset = (opt->rect.height() - buttonSize.height()) / 2.0;
6324 ret = QRectF(buttonPos, buttonSize).translated(0, vOffset).toRect();
6329 if (
const QStyleOptionComboBox *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
6330 const auto ct = cocoaControlType(combo, widget);
6331 const auto cs = d->effectiveAquaSizeConstrain(combo, widget);
6332 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
6333 const auto editRect = QMacStylePrivate::comboboxEditBounds(cw.adjustedControlFrame(combo->rect), cw);
6336 case SC_ComboBoxEditField:{
6337 ret = editRect.toAlignedRect();
6339 case SC_ComboBoxArrow:{
6340 ret = editRect.toAlignedRect();
6341 ret.setX(ret.x() + ret.width());
6342 ret.setWidth(combo->rect.right() - ret.right());
6344 case SC_ComboBoxListBoxPopup:{
6345 if (combo->editable) {
6346 const CGRect inner = QMacStylePrivate::comboboxInnerBounds(combo->rect.toCGRect(), cw);
6347 const int comboTop = combo->rect.top();
6348 ret = QRect(qRound(inner.origin.x),
6350 qRound(inner.origin.x - combo->rect.left() + inner.size.width),
6351 editRect.bottom() - comboTop + 2);
6353 ret = QRect(combo->rect.x() + 4 - 11,
6354 combo->rect.y() + 1,
6355 editRect.width() + 10 + 11,
6365 if (
const QStyleOptionGroupBox *groupBox = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
6366 bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
6367 const bool flat = groupBox->features & QStyleOptionFrame::Flat;
6368 bool hasNoText = !checkable && groupBox->text.isEmpty();
6370 case SC_GroupBoxLabel:
6371 case SC_GroupBoxCheckBox: {
6373 const bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
6374 const bool fontIsSet = (widget && widget->testAttribute(Qt::WA_SetFont))
6375 || !QApplication::desktopSettingsAware();
6376 const int margin = flat || hasNoText ? 0 : 9;
6377 ret = groupBox->rect.adjusted(margin, 0, -margin, 0);
6379 const QFontMetricsF fm = flat || fontIsSet || !d->smallSystemFont
6380 ? QFontMetricsF(groupBox->fontMetrics)
6381 : QFontMetricsF(*d->smallSystemFont);
6382 const QSizeF s = fm.size(Qt::AlignHCenter | Qt::AlignVCenter, qt_mac_removeMnemonics(groupBox->text), 0,
nullptr);
6383 const int tw = qCeil(s.width());
6384 const int h = qCeil(fm.height());
6387 QRect labelRect = alignedRect(groupBox->direction, groupBox->textAlignment,
6389 if (flat && checkable)
6390 labelRect.moveLeft(labelRect.left() + 4);
6391 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt, widget);
6392 bool rtl = groupBox->direction == Qt::RightToLeft;
6393 if (sc == SC_GroupBoxLabel) {
6395 int newSum = indicatorWidth + 1;
6396 int newLeft = labelRect.left() + (rtl ? -newSum : newSum);
6397 labelRect.moveLeft(newLeft);
6399 labelRect.moveTop(labelRect.top() + 3);
6401 labelRect.moveTop(labelRect.top() + 4);
6403 int newLeft = labelRect.left() - (rtl ? 3 : -3);
6404 labelRect.moveLeft(newLeft);
6405 labelRect.moveTop(labelRect.top() + 3);
6407 int newLeft = labelRect.left() - (rtl ? 3 : 2);
6408 labelRect.moveLeft(newLeft);
6409 labelRect.moveTop(labelRect.top() + 4);
6414 if (sc == SC_GroupBoxCheckBox) {
6415 int left = rtl ? labelRect.right() - indicatorWidth : labelRect.left() - 1;
6416 int top = flat ? ret.top() + 1 : ret.top() + 5;
6417 ret.setRect(left, top,
6418 indicatorWidth, proxy()->pixelMetric(PM_IndicatorHeight, opt, widget));
6422 case SC_GroupBoxContents:
6423 case SC_GroupBoxFrame: {
6424 QFontMetrics fm = groupBox->fontMetrics;
6427 if (widget && !widget->testAttribute(Qt::WA_SetFont)
6428 && QApplication::desktopSettingsAware())
6429 fm = QFontMetrics(qt_app_fonts_hash()->value(
"QSmallFont", QFont()));
6434 yOffset = -qCeil(QFontMetricsF(fm).height());
6435 ret = opt->rect.adjusted(0, qCeil(QFontMetricsF(fm).height()) + yOffset, 0, 0);
6436 if (sc == SC_GroupBoxContents) {
6438 ret.adjust(3, -5, -3, -4);
6440 ret.adjust(3, 3, -3, -4);
6445 ret = QCommonStyle::subControlRect(cc, groupBox, sc, widget);
6450#if QT_CONFIG(spinbox)
6452 if (
const QStyleOptionSpinBox *spin = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
6453 QStyleHelper::WidgetSizePolicy aquaSize = d->effectiveAquaSizeConstrain(spin, widget);
6454 const auto fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin, widget);
6458 case QStyleHelper::SizeLarge:
6462 case QStyleHelper::SizeSmall:
6466 case QStyleHelper::SizeMini:
6476 case SC_SpinBoxDown: {
6477 if (spin->buttonSymbols == QAbstractSpinBox::NoButtons)
6481 const int x = spin->rect.width() - spinner_w;
6482 ret.setRect(x + spin->rect.x(), y + spin->rect.y(), spinner_w, spin->rect.height() - y * 2);
6485 case QStyleHelper::SizeLarge:
6488 case QStyleHelper::SizeSmall:
6489 hackTranslateX = -2;
6491 case QStyleHelper::SizeMini:
6492 hackTranslateX = -1;
6498 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize);
6499 NSStepperCell *cell =
static_cast<NSStepperCell *>(d->cocoaCell(cw));
6500 const CGRect outRect = [cell drawingRectForBounds:ret.toCGRect()];
6501 ret = QRectF::fromCGRect(outRect).toRect();
6505 ret.setHeight(ret.height() / 2);
6507 case SC_SpinBoxDown:
6508 ret.setY(ret.y() + ret.height() / 2);
6514 ret.translate(hackTranslateX, 0);
6515 ret = visualRect(spin->direction, spin->rect, ret);
6518 case SC_SpinBoxEditField:
6519 ret = spin->rect.adjusted(fw, fw, -fw, -fw);
6520 if (spin->buttonSymbols != QAbstractSpinBox::NoButtons) {
6521 ret.setWidth(spin->rect.width() - spinBoxSep - spinner_w);
6522 ret = visualRect(spin->direction, spin->rect, ret);
6526 ret = QCommonStyle::subControlRect(cc, spin, sc, widget);
6533 ret = QCommonStyle::subControlRect(cc, opt, sc, widget);
6534 if (sc == SC_ToolButtonMenu) {
6535#if QT_CONFIG(accessibility)
6536 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar))
6537 ret.adjust(-toolButtonArrowMargin, 0, 0, 0);
6539 ret.adjust(-1, 0, 0, 0);
6543 ret = QCommonStyle::subControlRect(cc, opt, sc, widget);
6550 const QSize &csz,
const QWidget *widget)
const
6552 Q_D(
const QMacStyle);
6554 bool useAquaGuideline =
true;
6557#if QT_CONFIG(spinbox)
6559 if (
const QStyleOptionSpinBox *vopt = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
6560 const bool hasButtons = (vopt->buttonSymbols != QAbstractSpinBox::NoButtons);
6561 const int buttonWidth = hasButtons ? proxy()->subControlRect(CC_SpinBox, vopt, SC_SpinBoxUp, widget).width() : 0;
6562 sz += QSize(buttonWidth, 0);
6566 case QStyle::CT_TabWidget:
6569 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6601#if QT_CONFIG(tabwidget)
6602 if (
const QStyleOptionTabWidgetFrame *twf
6603 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
6605 const int overlap = pixelMetric(PM_TabBarBaseOverlap, opt, widget);
6606 const int gapBetweenTabbarAndStackWidget = 2 + 14 - overlap;
6608 const auto tabDirection = QMacStylePrivate::tabDirection(twf->shape);
6609 if (tabDirection == QMacStylePrivate::North
6610 || tabDirection == QMacStylePrivate::South) {
6611 extra = QSize(2, gapBetweenTabbarAndStackWidget + 1);
6613 extra = QSize(gapBetweenTabbarAndStackWidget + 1, 2);
6619#if QT_CONFIG(tabbar)
6620 case QStyle::CT_TabBarTab:
6621 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
6622 const bool differentFont = (widget && widget->testAttribute(Qt::WA_SetFont))
6623 || !QApplication::desktopSettingsAware();
6624 const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape);
6625 const bool verticalTabs = tabDirection == QMacStylePrivate::East
6626 || tabDirection == QMacStylePrivate::West;
6628 sz = sz.transposed();
6630 int defaultTabHeight;
6631 const auto cs = d->effectiveAquaSizeConstrain(opt, widget);
6633 case QStyleHelper::SizeLarge:
6634 if (tab->documentMode)
6635 defaultTabHeight = 24;
6637 defaultTabHeight = 21;
6639 if (qt_apple_runningWithLiquidGlass() && !tab->documentMode) {
6647 defaultTabHeight = 23;
6650 case QStyleHelper::SizeSmall:
6651 defaultTabHeight = 18;
6653 case QStyleHelper::SizeMini:
6654 defaultTabHeight = 16;
6660 const bool widthSet = !differentFont && tab->icon.isNull();
6662 const auto textSize = opt->fontMetrics.size(Qt::TextShowMnemonic, tab->text);
6663 sz.rwidth() = textSize.width();
6664 sz.rheight() = qMax(defaultTabHeight, textSize.height());
6666 sz.rheight() = qMax(defaultTabHeight, sz.height());
6668 sz.rwidth() += proxy()->pixelMetric(PM_TabBarTabHSpace, tab, widget);
6671 sz = sz.transposed();
6673 int maxWidgetHeight = qMax(tab->leftButtonSize.height(), tab->rightButtonSize.height());
6674 int maxWidgetWidth = qMax(tab->leftButtonSize.width(), tab->rightButtonSize.width());
6676 int widgetWidth = 0;
6677 int widgetHeight = 0;
6679 if (tab->leftButtonSize.isValid()) {
6681 widgetWidth += tab->leftButtonSize.width();
6682 widgetHeight += tab->leftButtonSize.height();
6684 if (tab->rightButtonSize.isValid()) {
6686 widgetWidth += tab->rightButtonSize.width();
6687 widgetHeight += tab->rightButtonSize.height();
6691 sz.setWidth(qMax(sz.width(), maxWidgetWidth));
6692 sz.setHeight(sz.height() + widgetHeight + padding);
6695 sz.setWidth(sz.width() + widgetWidth + padding);
6696 sz.setHeight(qMax(sz.height(), maxWidgetHeight));
6701 case QStyle::CT_PushButton: {
6702 bool isFlat =
false;
6703 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
6704 if (btn->features & QStyleOptionButton::CommandLinkButton)
6705 return QCommonStyle::sizeFromContents(ct, opt, sz, widget);
6706 isFlat = btn->features & QStyleOptionButton::Flat;
6713 const auto controlSize = d->effectiveAquaSizeConstrain(opt, widget, CT_PushButton, sz, &macsz);
6715 if (macsz.width() != -1)
6716 sz.setWidth(macsz.width());
6718 sz.rwidth() += QMacStylePrivate::PushButtonLeftOffset + QMacStylePrivate::PushButtonRightOffset + 12;
6720 if (controlSize != QStyleHelper::SizeMini)
6723 if (controlSize == QStyleHelper::SizeLarge) {
6726 if (sz.height() > 16)
6727 sz.rheight() += pushButtonDefaultHeight[QStyleHelper::SizeLarge] - 16;
6729 sz.setHeight(pushButtonDefaultHeight[QStyleHelper::SizeLarge]);
6731 if (!isFlat && !qt_apple_runningWithLiquidGlass())
6733 if (controlSize == QStyleHelper::SizeMini)
6736 sz.setHeight(pushButtonDefaultHeight[QStyleHelper::SizeSmall]);
6742 case QStyle::CT_MenuItem:
6743 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
6744 int maxpmw = mi->maxIconWidth;
6745#if QT_CONFIG(combobox)
6746 const QComboBox *comboBox = qobject_cast<
const QComboBox *>(widget);
6750 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
6754 h = mi->fontMetrics.height() + 2;
6755 if (!mi->icon.isNull()) {
6756#if QT_CONFIG(combobox)
6758 const QSize &iconSize = comboBox->iconSize();
6759 h = qMax(h, iconSize.height() + 4);
6760 maxpmw = qMax(maxpmw, iconSize.width());
6764 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
6765 h = qMax(h, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() + 4);
6769 if (mi->text.contains(QLatin1Char(
'\t')))
6771 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
6777#if QT_CONFIG(combobox)
6778 if (comboBox && comboBox->isVisible()) {
6779 QStyleOptionComboBox cmb;
6780 cmb.initFrom(comboBox);
6781 cmb.editable =
false;
6782 cmb.subControls = QStyle::SC_ComboBoxEditField;
6783 cmb.activeSubControls = QStyle::SC_None;
6784 w = qMax(w, subControlRect(QStyle::CC_ComboBox, &cmb,
6785 QStyle::SC_ComboBoxEditField,
6795 case CT_MenuBarItem:
6802 if (
const auto *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt))
6803 if (tb->features & QStyleOptionToolButton::Menu)
6807 if (
const auto *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
6808 const auto controlSize = d->effectiveAquaSizeConstrain(opt, widget);
6809 if (!cb->editable) {
6812 sz.rwidth() += QMacStylePrivate::PushButtonLeftOffset + QMacStylePrivate::PushButtonRightOffset + 24;
6814 if (controlSize != QStyleHelper::SizeMini)
6818 if (controlSize == QStyleHelper::SizeLarge && sz.height() > 16)
6819 sz.rheight() += popupButtonDefaultHeight[QStyleHelper::SizeLarge] - 16;
6827 if (controlSize == QStyleHelper::SizeMini)
6830 sz.setHeight(pushButtonDefaultHeight[controlSize]);
6836 if (proxy() ==
this) {
6839 QStyleHintReturnMask menuMask;
6840 QStyleOption myOption = *opt;
6841 myOption.rect.setSize(sz);
6842 if (proxy()->styleHint(SH_Menu_Mask, &myOption, widget, &menuMask))
6843 sz = menuMask.region.boundingRect().size();
6846 case CT_HeaderSection:{
6847 const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt);
6848 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6849 if (header->text.contains(QLatin1Char(
'\n')))
6850 useAquaGuideline =
false;
6854 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
6855 const int minimumSize = 24;
6856 if (slider->orientation == Qt::Horizontal)
6857 sz = sz.expandedTo(QSize(minimumSize, sz.height()));
6859 sz = sz.expandedTo(QSize(sz.width(), minimumSize));
6862#if QT_CONFIG(itemviews)
6863 case CT_ItemViewItem:
6864 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
6865 sz = QCommonStyle::sizeFromContents(ct, vopt, csz, widget);
6866 sz.setHeight(sz.height() + 2);
6872 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
6875 if (useAquaGuideline && ct != CT_PushButton) {
6878 if (d->aquaSizeConstrain(opt, widget, ct, sz, &macsz) != QStyleHelper::SizeDefault) {
6879 if (macsz.width() != -1)
6880 sz.setWidth(macsz.width());
6881 if (macsz.height() != -1)
6882 sz.setHeight(macsz.height());
6888 if (
const QStyleOptionComboBox *combo = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)){
6889 if (combo->editable) {
6890 const auto widgetSize = d->aquaSizeConstrain(opt, widget);
6891 QMacStylePrivate::CocoaControl cw;
6892 cw.type = combo->editable ? QMacStylePrivate::ComboBox : QMacStylePrivate::Button_PopupButton;
6893 cw.size = widgetSize;
6894 const CGRect diffRect = QMacStylePrivate::comboboxInnerBounds(CGRectZero, cw);
6895 sz.rwidth() -= qRound(diffRect.size.width);
6896 sz.rheight() -= qRound(diffRect.size.height);