Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickmacstyle_mac.mm
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5/*
6 Note: The qdoc comments for QMacStyle are contained in
7 .../doc/src/qstyles.qdoc.
8*/
9
12
13#include <private/qcore_mac_p.h>
14#include <private/qcoregraphics_p.h>
15#include <private/qfontengine_p.h>
16#include <private/qguiapplication_p.h>
17#include <private/qmacstyle_p.h>
18#include <private/qqc2qstylehelper_p.h>
19#include <private/qquickcontrol_p.h>
20
21#include <qpa/qplatformfontdatabase.h>
22#include <qpa/qplatformnativeinterface.h>
23#include <qpa/qplatformtheme.h>
24
25#include <QtGui/qpainterpath.h>
26#include <QtGui/qstylehints.h>
27
28#include <QtCore/qoperatingsystemversion.h>
29#include <QtCore/qvariant.h>
30#include <QtCore/qvarlengtharray.h>
31
32#include <cmath>
33
34#define QMAC_QAQUASTYLE_SIZE_CONSTRAIN
35
36using namespace QQC2;
37
38QT_USE_NAMESPACE
39
40// OBS! Changing QT_MANGLE_NAMESPACE and QT_NAMESPACE_ALIAS_OBJC_CLASS to take
41// both QT_NAMESPACE and QQC2_NAMESPACE into account (and not only QT_NAMESPACE, which
42// would otherwise be the case). This will make it possible to link in both widgets and
43// controls in the same application when building statically.
44#undef QT_MANGLE_NAMESPACE
45#undef QT_NAMESPACE_ALIAS_OBJC_CLASS
46
47#define QQC2_MANGLE1(a, b) a##_##b
48#define QQC2_MANGLE2(a, b) QQC2_MANGLE1(a, b)
49
50#if defined(QT_NAMESPACE)
51 #define QT_MANGLE_NAMESPACE(name) QQC2_MANGLE2(QQC2_MANGLE1(name, QQC2_NAMESPACE), QT_NAMESPACE)
52 #define QT_NAMESPACE_ALIAS_OBJC_CLASS(name) @compatibility_alias name QT_MANGLE_NAMESPACE(name)
53#else
54 #define QT_MANGLE_NAMESPACE(name) QQC2_MANGLE2(name, QQC2_NAMESPACE)
55 #define QT_NAMESPACE_ALIAS_OBJC_CLASS(name) @compatibility_alias name QT_MANGLE_NAMESPACE(name)
56#endif
57
58@interface QT_MANGLE_NAMESPACE(QIndeterminateProgressIndicator) : NSProgressIndicator
59
60@property (readonly, nonatomic) NSInteger animators;
61
62- (instancetype)init;
63
64- (void)startAnimation;
65- (void)stopAnimation;
66
67- (void)drawWithFrame:(CGRect)rect inView:(NSView *)view;
68
69@end
70
71QT_NAMESPACE_ALIAS_OBJC_CLASS(QIndeterminateProgressIndicator);
72
73@implementation QIndeterminateProgressIndicator
74
75- (instancetype)init
76{
77 if ((self = [super init])) {
78 _animators = 0;
79 self.indeterminate = YES;
80 self.usesThreadedAnimation = NO;
81 self.alphaValue = 0.0;
82 }
83
84 return self;
85}
86
87- (void)startAnimation
88{
89 if (_animators == 0) {
90 self.hidden = NO;
91 [super startAnimation:self];
92 }
93 ++_animators;
94}
95
96- (void)stopAnimation
97{
98 --_animators;
99 if (_animators == 0) {
100 [super stopAnimation:self];
101 self.hidden = YES;
102 [self removeFromSuperviewWithoutNeedingDisplay];
103 }
104}
105
106- (void)drawWithFrame:(CGRect)rect inView:(NSView *)view
107{
108 // The alphaValue change is not strictly necessary, but feels safer.
109 self.alphaValue = 1.0;
110 if (self.superview != view)
111 [view addSubview:self];
112 if (!CGRectEqualToRect(self.frame, rect))
113 self.frame = rect;
114 [self drawRect:rect];
115 self.alphaValue = 0.0;
116}
117
118@end
119
120@interface QT_MANGLE_NAMESPACE(QVerticalSplitView) : NSSplitView
121- (BOOL)isVertical;
122@end
123
125
126@implementation QVerticalSplitView
127- (BOOL)isVertical
128{
129 return YES;
130}
131@end
132
133// See render code in drawPrimitive(PE_FrameTabWidget)
134@interface QT_MANGLE_NAMESPACE(QDarkNSBox) : NSBox
135@end
136
138
139@implementation QDarkNSBox
140- (instancetype)init
141{
142 if ((self = [super init])) {
143 self.title = @"";
144 self.titlePosition = NSNoTitle;
145 self.boxType = NSBoxCustom;
146 self.cornerRadius = 3;
147 self.borderColor = [NSColor.controlColor colorWithAlphaComponent:0.1];
148 self.fillColor = [NSColor.darkGrayColor colorWithAlphaComponent:0.2];
149 }
150
151 return self;
152}
153
154- (void)drawRect:(NSRect)rect
155{
156 [super drawRect:rect];
157}
158@end
159
160QT_BEGIN_NAMESPACE
161
162namespace QQC2_NAMESPACE {
163
164// The following constants are used for adjusting the size
165// of push buttons so that they are drawn inside their bounds.
169
171
172static const QColor titlebarSeparatorLineActive(111, 111, 111);
173static const QColor titlebarSeparatorLineInactive(131, 131, 131);
174static const QColor darkModeSeparatorLine(88, 88, 88);
175
176// Gradient colors used for the dock widget title bar and
177// non-unifed tool bar background.
178static const QColor lightMainWindowGradientBegin(240, 240, 240);
179static const QColor lightMainWindowGradientEnd(200, 200, 200);
180static const QColor darkMainWindowGradientBegin(47, 47, 47);
181static const QColor darkMainWindowGradientEnd(47, 47, 47);
182
183static const int DisclosureOffset = 4;
184
188
189// Tab bar colors
190// active: window is active
191// selected: tab is selected
192// hovered: tab is hovered
193static bool isDarkMode() { return qGuiApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark; }
194
195static const QColor lightTabBarTabBackgroundActive(190, 190, 190);
196static const QColor darkTabBarTabBackgroundActive(38, 38, 38);
197static const QColor tabBarTabBackgroundActive() { return isDarkMode() ? darkTabBarTabBackgroundActive : lightTabBarTabBackgroundActive; }
198
201static const QColor tabBarTabBackgroundActiveHovered() { return isDarkMode() ? darkTabBarTabBackgroundActiveHovered : lightTabBarTabBackgroundActiveHovered; }
202
205static const QColor tabBarTabBackgroundActiveSelected() { return isDarkMode() ? darkTabBarTabBackgroundActiveSelected : lightTabBarTabBackgroundActiveSelected; }
206
207static const QColor lightTabBarTabBackground(227, 227, 227);
208static const QColor darkTabBarTabBackground(38, 38, 38);
209static const QColor tabBarTabBackground() { return isDarkMode() ? darkTabBarTabBackground : lightTabBarTabBackground; }
210
211static const QColor lightTabBarTabBackgroundSelected(246, 246, 246);
213static const QColor tabBarTabBackgroundSelected() { return isDarkMode() ? darkTabBarTabBackgroundSelected : lightTabBarTabBackgroundSelected; }
214
215static const QColor lightTabBarTabLineActive(160, 160, 160);
216static const QColor darkTabBarTabLineActive(90, 90, 90);
217static const QColor tabBarTabLineActive() { return isDarkMode() ? darkTabBarTabLineActive : lightTabBarTabLineActive; }
218
219static const QColor lightTabBarTabLineActiveHovered(150, 150, 150);
220static const QColor darkTabBarTabLineActiveHovered(90, 90, 90);
221static const QColor tabBarTabLineActiveHovered() { return isDarkMode() ? darkTabBarTabLineActiveHovered : lightTabBarTabLineActiveHovered; }
222
223static const QColor lightTabBarTabLine(210, 210, 210);
224static const QColor darkTabBarTabLine(90, 90, 90);
225static const QColor tabBarTabLine() { return isDarkMode() ? darkTabBarTabLine : lightTabBarTabLine; }
226
227static const QColor lightTabBarTabLineSelected(189, 189, 189);
228static const QColor darkTabBarTabLineSelected(90, 90, 90);
229static const QColor tabBarTabLineSelected() { return isDarkMode() ? darkTabBarTabLineSelected : lightTabBarTabLineSelected; }
230
231static const int closeButtonSize = 14;
232
233#ifndef QT_NO_ACCESSIBILITY // This ifdef to avoid "unused function" warning.
234QBrush brushForToolButton(bool isOnKeyWindow)
235{
236 // When a toolbutton in a toolbar is in the 'ON' state, we draw a
237 // partially transparent background. The colors must be different
238 // for 'Aqua' and 'DarkAqua' appearances though.
239 if (isDarkMode())
240 return isOnKeyWindow ? QColor(73, 73, 73, 100) : QColor(56, 56, 56, 100);
241
242 return isOnKeyWindow ? QColor(0, 0, 0, 28) : QColor(0, 0, 0, 21);
243}
244#endif // QT_NO_ACCESSIBILITY
245
246static const int headerSectionArrowHeight = 6;
247static const int headerSectionSeparatorInset = 2;
248
249// These are frame heights as reported by Xcode 9's Interface Builder.
250// Alignemnet rectangle's heights match for push and popup buttons
251// with respective values 21, 18 and 15.
252
253static const qreal comboBoxDefaultHeight[3] = {
254 26, 22, 19
255};
256
258 32, 28, 16
259};
260
262 26, 22, 15
263};
264
265static const int toolButtonArrowSize = 7;
266static const int toolButtonArrowMargin = 2;
267
268static const qreal focusRingWidth = 3.5;
269
270static bool setupScroller(NSScroller *scroller, const QStyleOptionSlider *sb)
271{
272 const qreal length = sb->maximum - sb->minimum + sb->pageStep;
273 if (qFuzzyIsNull(length))
274 return false;
275 const qreal proportion = sb->pageStep / length;
276 const qreal range = qreal(sb->maximum - sb->minimum);
277 qreal value = range ? qreal(sb->sliderValue - sb->minimum) / range : 0;
278 if (sb->orientation == Qt::Horizontal && sb->direction == Qt::RightToLeft)
279 value = 1.0 - value;
280
281 scroller.frame = sb->rect.toCGRect();
282 scroller.floatValue = value;
283 scroller.knobProportion = proportion;
284 return true;
285}
286
287static bool setupSlider(NSSlider *slider, const QStyleOptionSlider *sl)
288{
289 if (sl->minimum >= sl->maximum)
290 return false;
291
292 // NSSlider seems to cache values based on tracking and the last layout of the
293 // NSView, resulting in incorrect knob rects that break the interaction with
294 // multiple sliders. So completely reinitialize the slider.
295 [slider initWithFrame:sl->rect.toCGRect()];
296
297 slider.minValue = sl->minimum;
298 slider.maxValue = sl->maximum;
299 slider.intValue = sl->sliderPosition;
300 slider.enabled = sl->state & QStyle::State_Enabled;
301 if (sl->tickPosition != QStyleOptionSlider::NoTicks) {
302 // Set numberOfTickMarks, but TicksBothSides will be treated differently
303 int interval = sl->tickInterval;
304 if (interval == 0) {
305 interval = sl->pageStep;
306 if (interval == 0)
307 interval = sl->singleStep;
308 if (interval == 0)
309 interval = 1; // return false?
310 }
311 slider.numberOfTickMarks = 1 + ((sl->maximum - sl->minimum) / interval);
312
313 const bool ticksAbove = sl->tickPosition == QStyleOptionSlider::TicksAbove;
314 if (sl->orientation == Qt::Horizontal)
315 slider.tickMarkPosition = ticksAbove ? NSTickMarkPositionAbove : NSTickMarkPositionBelow;
316 else
317 slider.tickMarkPosition = ticksAbove ? NSTickMarkPositionLeading : NSTickMarkPositionTrailing;
318 } else {
319 slider.numberOfTickMarks = 0;
320 }
321
322 // Ensure the values set above are reflected when asking
323 // the cell for its metrics and to draw itself.
324 [slider layoutSubtreeIfNeeded];
325
326 if (sl->state & QStyle::State_Sunken) {
327 const CGRect knobRect = [slider.cell knobRectFlipped:slider.isFlipped];
328 CGPoint pressPoint;
329 pressPoint.x = CGRectGetMidX(knobRect);
330 pressPoint.y = CGRectGetMidY(knobRect);
331 [slider.cell startTrackingAt:pressPoint inView:slider];
332 }
333
334 return true;
335}
336
337QRect rotateTabPainter(QPainter *p, QStyleOptionTab::Shape shape, QRect tabRect)
338{
339 const auto tabDirection = QMacStylePrivate::tabDirection(shape);
340 if (QMacStylePrivate::verticalTabs(tabDirection)) {
341 int newX, newY, newRot;
342 if (tabDirection == QMacStylePrivate::East) {
343 newX = tabRect.width();
344 newY = tabRect.y();
345 newRot = 90;
346 } else {
347 newX = 0;
348 newY = tabRect.y() + tabRect.height();
349 newRot = -90;
350 }
351 tabRect.setRect(0, 0, tabRect.height(), tabRect.width());
352 QTransform transform;
353 transform.translate(newX, newY);
354 transform.rotate(newRot);
355 p->setTransform(transform, true);
356 }
357 return tabRect;
358}
359
360void drawTabShape(QPainter *p, const QStyleOptionTab *tabOpt, bool isUnified, int tabOverlap)
361{
362 QRect rect = tabOpt->rect;
363 if (QMacStylePrivate::verticalTabs(QMacStylePrivate::tabDirection(tabOpt->shape)))
364 rect = rect.adjusted(-tabOverlap, 0, 0, 0);
365 else
366 rect = rect.adjusted(0, -tabOverlap, 0, 0);
367
368 p->translate(rect.x(), rect.y());
369 rect.moveLeft(0);
370 rect.moveTop(0);
371 const QRect tabRect = rotateTabPainter(p, tabOpt->shape, rect);
372
373 const int width = tabRect.width();
374 const int height = tabRect.height();
375 const bool active = (tabOpt->state & QStyle::State_Active);
376 const bool selected = (tabOpt->state & QStyle::State_Selected);
377
378 const QRect bodyRect(1, 2, width - 2, height - 3);
379 const QRect topLineRect(1, 0, width - 2, 1);
380 const QRect bottomLineRect(1, height - 1, width - 2, 1);
381 if (selected) {
382 // fill body
383 if (tabOpt->documentMode && isUnified) {
384 p->save();
385 p->setCompositionMode(QPainter::CompositionMode_Source);
386 p->fillRect(tabRect, QColor(Qt::transparent));
387 p->restore();
388 } else if (active) {
389 p->fillRect(bodyRect, tabBarTabBackgroundActiveSelected());
390 // top line
391 p->fillRect(topLineRect, tabBarTabLineSelected());
392 } else {
393 p->fillRect(bodyRect, tabBarTabBackgroundSelected());
394 }
395 } else {
396 // when the mouse is over non selected tabs they get a new color
397 const bool hover = (tabOpt->state & QStyle::State_MouseOver);
398 if (hover) {
399 // fill body
400 p->fillRect(bodyRect, tabBarTabBackgroundActiveHovered());
401 // bottom line
402 p->fillRect(bottomLineRect, isDarkMode() ? QColor(Qt::black) : tabBarTabLineActiveHovered());
403 }
404 }
405
406 // separator lines between tabs
407 const QRect leftLineRect(0, 1, 1, height - 2);
408 const QRect rightLineRect(width - 1, 1, 1, height - 2);
409 const QColor separatorLineColor = active ? tabBarTabLineActive() : tabBarTabLine();
410 p->fillRect(leftLineRect, separatorLineColor);
411 p->fillRect(rightLineRect, separatorLineColor);
412}
413
414void drawTabBase(QPainter *p, const QStyleOptionTabBarBase *tbb)
415{
416 QRect r = tbb->rect;
417// if (QMacStylePrivate::verticalTabs(QMacStylePrivate::tabDirection(tbb->shape)))
418// r.setWidth(w->width());
419// else
420// r.setHeight(w->height());
421
422 const QRect tabRect = rotateTabPainter(p, tbb->shape, r);
423 const int width = tabRect.width();
424 const int height = tabRect.height();
425 const bool active = (tbb->state & QStyle::State_Active);
426
427 // fill body
428 const QRect bodyRect(0, 1, width, height - 1);
429 const QColor bodyColor = active ? tabBarTabBackgroundActive() : tabBarTabBackground();
430 p->fillRect(bodyRect, bodyColor);
431
432 // top line
433 const QRect topLineRect(0, 0, width, 1);
434 const QColor topLineColor = active ? tabBarTabLineActive() : tabBarTabLine();
435 p->fillRect(topLineRect, topLineColor);
436
437 // bottom line
438 const QRect bottomLineRect(0, height - 1, width, 1);
439 bool isDocument = false;
440// if (const QTabBar *tabBar = qobject_cast<const QTabBar*>(w))
441// isDocument = tabBar->documentMode();
442 const QColor bottomLineColor = isDocument && isDarkMode() ? QColor(Qt::black) : active ? tabBarTabLineActive() : tabBarTabLine();
443 p->fillRect(bottomLineRect, bottomLineColor);
444}
445
446static QStyleHelper::WidgetSizePolicy getControlSize(const QStyleOption *option)
447{
448 const auto wsp = QStyleHelper::widgetSizePolicy(option);
449 if (wsp == QStyleHelper::SizeDefault)
450 return QStyleHelper::SizeLarge;
451
452 return wsp;
453}
454
455static QString qt_mac_removeMnemonics(const QString &original)
456{
457 QString returnText(original.size(), QChar());
458 int finalDest = 0;
459 int currPos = 0;
460 int l = original.length();
461 while (l) {
462 if (original.at(currPos) == QLatin1Char('&')) {
463 ++currPos;
464 --l;
465 if (l == 0)
466 break;
467 } else if (original.at(currPos) == QLatin1Char('(') && l >= 4 &&
468 original.at(currPos + 1) == QLatin1Char('&') &&
469 original.at(currPos + 2) != QLatin1Char('&') &&
470 original.at(currPos + 3) == QLatin1Char(')')) {
471 /* remove mnemonics its format is "\s*(&X)" */
472 int n = 0;
473 while (finalDest > n && returnText.at(finalDest - n - 1).isSpace())
474 ++n;
475 finalDest -= n;
476 currPos += 4;
477 l -= 4;
478 continue;
479 }
480 returnText[finalDest] = original.at(currPos);
481 ++currPos;
482 ++finalDest;
483 --l;
484 }
485 returnText.truncate(finalDest);
486 return returnText;
487}
488
489static bool qt_macWindowMainWindow(const QWindow *window)
490{
491 if (window->handle()) {
492 if (NSWindow *nswindow = static_cast<NSWindow*>(
493 QGuiApplication::platformNativeInterface()->
494 nativeResourceForWindow(QByteArrayLiteral("nswindow"),
495 const_cast<QWindow *>(window)))) {
496 return [nswindow isMainWindow];
497 }
498 }
499 return false;
500}
501
502#define LargeSmallMini(option, large, small, mini)
503 (option->state & QStyle::State_Small) ? small : ((option->state & QStyle::State_Mini) ? mini : large)
504
505/*****************************************************************************
506 QMacCGStyle globals
507 *****************************************************************************/
508const int macItemFrame = 2; // menu item frame width
509const int macItemHMargin = 3; // menu item hor text margin
510const int macRightBorder = 12; // right border on mac
511
512/*****************************************************************************
513 QMacCGStyle utility functions
514 *****************************************************************************/
515
559
560static const int qt_mac_aqua_metrics[] = {
561 // Values as of macOS 10.12.4 and Xcode 8.3.1
562 18 /* CheckBoxHeight */,
563 18 /* CheckBoxWidth */,
564 1 /* EditTextFrameOutset */,
565 4 /* FocusRectOutset */,
566 22 /* HSliderHeight */,
567 5 /* HSliderTickHeight */,
568 16 /* LargeProgressBarThickness */,
569 17 /* ListHeaderHeight */,
570 12 /* MenuSeparatorHeight, aka GetThemeMenuSeparatorHeight */,
571 11 /* MiniCheckBoxHeight */,
572 11 /* MiniCheckBoxWidth */,
573 12 /* MiniHSliderHeight */,
574 4 /* MiniHSliderTickHeight */,
575 15 /* MiniPopupButtonHeight */,
576 16 /* MiniPushButtonHeight */,
577 11 /* MiniRadioButtonHeight */,
578 11 /* MiniRadioButtonWidth */,
579 4 /* MiniVSliderTickWidth */,
580 12 /* MiniVSliderWidth */,
581 12 /* NormalProgressBarThickness */,
582 20 /* PopupButtonHeight */,
583 4 /* ProgressBarShadowOutset */,
584 20 /* PushButtonHeight */,
585 18 /* RadioButtonHeight */,
586 18 /* RadioButtonWidth */,
587 1 /* SeparatorSize */,
588 16 /* SmallCheckBoxHeight */,
589 14 /* SmallCheckBoxWidth */,
590 15 /* SmallHSliderHeight */,
591 4 /* SmallHSliderTickHeight */,
592 17 /* SmallPopupButtonHeight */,
593 2 /* SmallProgressBarShadowOutset */,
594 17 /* SmallPushButtonHeight */,
595 15 /* SmallRadioButtonHeight */,
596 15 /* SmallRadioButtonWidth */,
597 4 /* SmallVSliderTickWidth */,
598 15 /* SmallVSliderWidth */,
599 5 /* VSliderTickWidth */,
600 22 /* VSliderWidth */
601};
602
604{
605 return qt_mac_aqua_metrics[m];
606}
607
608static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QStyleOption *opt,
609 QSize szHint, QStyleHelper::WidgetSizePolicy sz)
610{
611 QSize ret(-1, -1);
612 if (sz != QStyleHelper::SizeSmall && sz != QStyleHelper::SizeLarge && sz != QStyleHelper::SizeMini) {
613 qDebug("Not sure how to return this...");
614 return ret;
615 }
616// if ((widget && widget->testAttribute(Qt::WA_SetFont)) || !QApplication::desktopSettingsAware()) {
617// // If you're using a custom font and it's bigger than the default font,
618// // then no constraints for you. If you are smaller, we can try to help you out
619// QFont font = qt_app_fonts_hash()->value(widget->metaObject()->className(), QFont());
620// if (widget->font().pointSize() > font.pointSize())
621// return ret;
622// }
623
624 // TODO: investigate how this function is used. 'ct' can/should be
625 // filled out correctly in the styleoption already from the styleitem?
626 Q_ASSERT(ct != QStyle::CT_CustomBase);
627// if (ct == QStyle::CT_CustomBase && widget) {
628//#if QT_CONFIG(pushbutton)
629// if (qobject_cast<const QPushButton *>(widg))
630// ct = QStyle::CT_PushButton;
631//#endif
632// else if (qobject_cast<const QRadioButton *>(widget))
633// ct = QStyle::CT_RadioButton;
634//#if QT_CONFIG(checkbox)
635// else if (qobject_cast<const QCheckBox *>(widg))
636// ct = QStyle::CT_CheckBox;
637//#endif
638//#if QT_CONFIG(combobox)
639// else if (qobject_cast<const QComboBox *>(widg))
640// ct = QStyle::CT_ComboBox;
641//#endif
642//#if QT_CONFIG(toolbutton)
643// else if (qobject_cast<const QToolButton *>(widg))
644// ct = QStyle::CT_ToolButton;
645//#endif
646// else if (qobject_cast<const QSlider *>(widget))
647// ct = QStyle::CT_Slider;
648//#if QT_CONFIG(progressbar)
649// else if (qobject_cast<const QProgressBar *>(widg))
650// ct = QStyle::CT_ProgressBar;
651//#endif
652//#if QT_CONFIG(lineedit)
653// else if (qobject_cast<const QLineEdit *>(widg))
654// ct = QStyle::CT_LineEdit;
655//#endif
656//#if QT_CONFIG(itemviews)
657// else if (qobject_cast<const QHeaderView *>(widg))
658// ct = QStyle::CT_HeaderSection;
659//#endif
660//#if QT_CONFIG(menubar)
661// else if (qobject_cast<const QMenuBar *>(widg))
662// ct = QStyle::CT_MenuBar;
663//#endif
664//#if QT_CONFIG(sizegrip)
665// else if (qobject_cast<const QSizeGrip *>(widg))
666// ct = QStyle::CT_SizeGrip;
667//#endif
668// else
669// return ret;
670// }
671
672 switch (ct) {
673 case QStyle::CT_PushButton: {
674 const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt);
675 if (btn) {
676 QString buttonText = qt_mac_removeMnemonics(btn->text);
677 if (buttonText.contains(QLatin1Char('\n')))
678 ret = QSize(-1, -1);
679 else if (sz == QStyleHelper::SizeLarge)
681 else if (sz == QStyleHelper::SizeSmall)
683 else if (sz == QStyleHelper::SizeMini)
685
686 if (!btn->icon.isNull()){
687 // If the button got an icon, and the icon is larger than the
688 // button, we can't decide on a default size
689 ret.setWidth(-1);
690 if (ret.height() < btn->iconSize.height())
691 ret.setHeight(-1);
692 }
693 else if (buttonText == QLatin1String("OK") || buttonText == QLatin1String("Cancel")){
694 // Aqua Style guidelines restrict the size of OK and Cancel buttons to 68 pixels.
695 // However, this doesn't work for German, therefore only do it for English,
696 // I suppose it would be better to do some sort of lookups for languages
697 // that like to have really long words.
698 // FIXME This is not exactly true. Out of context, OK buttons have their
699 // implicit size calculated the same way as any other button. Inside a
700 // QDialogButtonBox, their size should be calculated such that the action
701 // or accept button (i.e., rightmost) and cancel button have the same width.
702 ret.setWidth(69);
703 }
704 } else {
705 // The only sensible thing to do is to return whatever the style suggests...
706 if (sz == QStyleHelper::SizeLarge)
708 else if (sz == QStyleHelper::SizeSmall)
710 else if (sz == QStyleHelper::SizeMini)
712 else
713 // Since there's no default size we return the large size...
715 }
716 break; }
717 case QStyle::CT_SizeGrip:
718 // Not HIG kosher: mimic what we were doing earlier until we support 4-edge resizing in MDI subwindows
719 if (sz == QStyleHelper::SizeLarge || sz == QStyleHelper::SizeSmall) {
720 int s = sz == QStyleHelper::SizeSmall ? 16 : 22; // large: pixel measured from HITheme, small: from my hat
721 int width = 0;
722//#if QT_CONFIG(mdiarea)
723// if (widg && qobject_cast<QMdiSubWindow *>(widg->parentWidget()))
724// width = s;
725//#endif
726 ret = QSize(width, s);
727 }
728 break;
729 case QStyle::CT_ComboBox:
730 switch (sz) {
731 case QStyleHelper::SizeLarge:
733 break;
734 case QStyleHelper::SizeSmall:
736 break;
737 case QStyleHelper::SizeMini:
739 break;
740 default:
741 break;
742 }
743 break;
744 case QStyle::CT_ToolButton:
745 if (sz == QStyleHelper::SizeSmall) {
746 int width = 0, height = 0;
747 if (szHint == QSize(-1, -1)) { //just 'guess'..
748//#if QT_CONFIG(toolbutton)
749// const QStyleOptionToolButton *bt = qstyleoption_cast<const QStyleOptionToolButton *>(opt);
750// // If this conversion fails then the widget was not what it claimed to be.
751// if(bt) {
752// if (!bt->icon.isNull()) {
753// QSize iconSize = bt->iconSize;
754// QSize pmSize = bt->icon.actualSize(QSize(32, 32), QIcon::Normal);
755// width = qMax(width, qMax(iconSize.width(), pmSize.width()));
756// height = qMax(height, qMax(iconSize.height(), pmSize.height()));
757// }
758// if (!bt->text.isNull() && bt->toolButtonStyle != Qt::ToolButtonIconOnly) {
759// int text_width = bt->fontMetrics.horizontalAdvance(bt->text),
760// text_height = bt->fontMetrics.height();
761// if (bt->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
762// width = qMax(width, text_width);
763// height += text_height;
764// } else {
765// width += text_width;
766// width = qMax(height, text_height);
767// }
768// }
769// } else
770//#endif
771 {
772 // Let's return the size hint...
773 width = szHint.width();
774 height = szHint.height();
775 }
776 } else {
777 width = szHint.width();
778 height = szHint.height();
779 }
780 width = qMax(20, width + 5); //border
781 height = qMax(20, height + 5); //border
782 ret = QSize(width, height);
783 }
784 break;
785 case QStyle::CT_Slider: {
786 int w = -1;
787 const QStyleOptionSlider *sld = qstyleoption_cast<const QStyleOptionSlider *>(opt);
788 // If this conversion fails then the widget was not what it claimed to be.
789 if(sld) {
790 if (sz == QStyleHelper::SizeLarge) {
791 if (sld->orientation == Qt::Horizontal) {
793 if (sld->tickPosition != QStyleOptionSlider::NoTicks)
795 } else {
797 if (sld->tickPosition != QStyleOptionSlider::NoTicks)
799 }
800 } else if (sz == QStyleHelper::SizeSmall) {
801 if (sld->orientation == Qt::Horizontal) {
803 if (sld->tickPosition != QStyleOptionSlider::NoTicks)
805 } else {
807 if (sld->tickPosition != QStyleOptionSlider::NoTicks)
809 }
810 } else if (sz == QStyleHelper::SizeMini) {
811 if (sld->orientation == Qt::Horizontal) {
813 if (sld->tickPosition != QStyleOptionSlider::NoTicks)
815 } else {
817 if (sld->tickPosition != QStyleOptionSlider::NoTicks)
819 }
820 }
821 } else {
822 // This is tricky, we were requested to find a size for a slider which is not
823 // a slider. We don't know if this is vertical or horizontal or if we need to
824 // have tick marks or not.
825 // For this case we will return an horizontal slider without tick marks.
828 }
829 if (sld->orientation == Qt::Horizontal)
830 ret.setHeight(w);
831 else
832 ret.setWidth(w);
833 break;
834 }
835//#if QT_CONFIG(progressbar)
836// case QStyle::CT_ProgressBar: {
837// int finalValue = -1;
838// Qt::Orientation orient = Qt::Horizontal;
839// if (const QProgressBar *pb = qobject_cast<const QProgressBar *>(widg))
840// orient = pb->orientation();
841
842// if (sz == QStyleHelper::SizeLarge)
843// finalValue = qt_mac_aqua_get_metric(LargeProgressBarThickness)
844// + qt_mac_aqua_get_metric(ProgressBarShadowOutset);
845// else
846// finalValue = qt_mac_aqua_get_metric(NormalProgressBarThickness)
847// + qt_mac_aqua_get_metric(SmallProgressBarShadowOutset);
848// if (orient == Qt::Horizontal)
849// ret.setHeight(finalValue);
850// else
851// ret.setWidth(finalValue);
852// break;
853// }
854//#endif
855//#if QT_CONFIG(combobox)
856// case QStyle::CT_LineEdit:
857// if (!widg || !qobject_cast<QComboBox *>(widg->parentWidget())) {
858// //should I take into account the font dimentions of the lineedit? -Sam
859// if (sz == QStyleHelper::SizeLarge)
860// ret = QSize(-1, 21);
861// else
862// ret = QSize(-1, 19);
863// }
864// break;
865//#endif
866 case QStyle::CT_HeaderSection:
867//#if QT_CONFIG(treeview)
868// if (isTreeView(widg))
869// ret = QSize(-1, qt_mac_aqua_get_metric(ListHeaderHeight));
870//#endif
871 break;
872 case QStyle::CT_MenuBar:
873 if (sz == QStyleHelper::SizeLarge) {
874 ret = QSize(-1, [[NSApp mainMenu] menuBarHeight]);
875 // In the qt_mac_set_native_menubar(false) case,
876 // we come it here with a zero-height main menu,
877 // preventing the in-window menu from displaying.
878 // Use 22 pixels for the height, by observation.
879 if (ret.height() <= 0)
880 ret.setHeight(22);
881 }
882 break;
883 default:
884 break;
885 }
886 return ret;
887}
888
889
891{
892 static const qreal CornerPointOffset = 5.5;
893 static const qreal CornerControlOffset = 2.1;
894
895 QPainterPath path;
896 // Top-left corner
897 path.moveTo(r.left(), r.top() + CornerPointOffset);
898 path.cubicTo(r.left(), r.top() + CornerControlOffset,
899 r.left() + CornerControlOffset, r.top(),
900 r.left() + CornerPointOffset, r.top());
901 // Top-right corner
902 path.lineTo(r.right() - CornerPointOffset, r.top());
903 path.cubicTo(r.right() - CornerControlOffset, r.top(),
904 r.right(), r.top() + CornerControlOffset,
905 r.right(), r.top() + CornerPointOffset);
906 // Bottom-right corner
907 path.lineTo(r.right(), r.bottom() - CornerPointOffset);
908 path.cubicTo(r.right(), r.bottom() - CornerControlOffset,
909 r.right() - CornerControlOffset, r.bottom(),
910 r.right() - CornerPointOffset, r.bottom());
911 // Bottom-right corner
912 path.lineTo(r.left() + CornerPointOffset, r.bottom());
913 path.cubicTo(r.left() + CornerControlOffset, r.bottom(),
914 r.left(), r.bottom() - CornerControlOffset,
915 r.left(), r.bottom() - CornerPointOffset);
916 path.lineTo(r.left(), r.top() + CornerPointOffset);
917
918 return path;
919}
920
922{
923 struct WindowButtons {
924 QStyle::SubControl sc;
926 };
927
928 static const WindowButtons buttons[] = {
929 { QStyle::SC_TitleBarCloseButton, QMacStylePrivate::Button_WindowClose },
930 { QStyle::SC_TitleBarMinButton, QMacStylePrivate::Button_WindowMiniaturize },
931 { QStyle::SC_TitleBarMaxButton, QMacStylePrivate::Button_WindowZoom }
932 };
933
934 for (const auto &wb : buttons)
935 if (wb.sc == sc)
936 return wb.ct;
937
938 return NoControl;
939}
940
941
942void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, QRect *textRect, QRect *iconRect) const
943{
944 Q_ASSERT(textRect);
945 Q_ASSERT(iconRect);
946 QRect tr = opt->rect;
947 const bool verticalTabs = opt->shape == QStyleOptionTab::RoundedEast
948 || opt->shape == QStyleOptionTab::RoundedWest
949 || opt->shape == QStyleOptionTab::TriangularEast
950 || opt->shape == QStyleOptionTab::TriangularWest;
951 if (verticalTabs)
952 tr.setRect(0, 0, tr.height(), tr.width()); // 0, 0 as we will have a translate transform
953
954 int verticalShift = proxyStyle->pixelMetric(QStyle::PM_TabBarTabShiftVertical, opt);
955 int horizontalShift = proxyStyle->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, opt);
956 const int hpadding = 4;
957 const int vpadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabVSpace, opt) / 2;
958 if (opt->shape == QStyleOptionTab::RoundedSouth || opt->shape == QStyleOptionTab::TriangularSouth)
959 verticalShift = -verticalShift;
960 tr.adjust(hpadding, verticalShift - vpadding, horizontalShift - hpadding, vpadding);
961
962 // left widget
963 if (!opt->leftButtonSize.isEmpty()) {
964 const int buttonSize = verticalTabs ? opt->leftButtonSize.height() : opt->leftButtonSize.width();
965 tr.setLeft(tr.left() + 4 + buttonSize);
966 // make text aligned to center
967 if (opt->rightButtonSize.isEmpty())
968 tr.setRight(tr.right() - 4 - buttonSize);
969 }
970 // right widget
971 if (!opt->rightButtonSize.isEmpty()) {
972 const int buttonSize = verticalTabs ? opt->rightButtonSize.height() : opt->rightButtonSize.width();
973 tr.setRight(tr.right() - 4 - buttonSize);
974 // make text aligned to center
975 if (opt->leftButtonSize.isEmpty())
976 tr.setLeft(tr.left() + 4 + buttonSize);
977 }
978
979 // icon
980 if (!opt->icon.isNull()) {
981 QSize iconSize = opt->iconSize;
982 if (!iconSize.isValid()) {
983 int iconExtent = proxyStyle->pixelMetric(QStyle::PM_SmallIconSize);
984 iconSize = QSize(iconExtent, iconExtent);
985 }
986 QSize tabIconSize = opt->icon.actualSize(iconSize,
987 (opt->state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled,
988 (opt->state & QStyle::State_Selected) ? QIcon::On : QIcon::Off);
989 // High-dpi icons do not need adjustment; make sure tabIconSize is not larger than iconSize
990 tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height()));
991
992 const int stylePadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabHSpace, opt) / 2 - hpadding;
993
994 if (opt->documentMode) {
995 // documents show the icon as part of the the text
996 const int textWidth =
997 opt->fontMetrics.boundingRect(tr, Qt::AlignCenter | Qt::TextShowMnemonic, opt->text).width();
998 *iconRect = QRect(tr.center().x() - textWidth / 2 - stylePadding - tabIconSize.width(),
999 tr.center().y() - tabIconSize.height() / 2,
1000 tabIconSize.width(), tabIconSize.height());
1001 } else {
1002 *iconRect = QRect(tr.left() + stylePadding, tr.center().y() - tabIconSize.height() / 2,
1003 tabIconSize.width(), tabIconSize.height());
1004 }
1005 if (!verticalTabs)
1006 *iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect);
1007
1008 tr.setLeft(tr.left() + stylePadding + tabIconSize.width() + 4);
1009 tr.setRight(tr.right() - stylePadding - tabIconSize.width() - 4);
1010 }
1011
1012 if (!verticalTabs)
1013 tr = proxyStyle->visualRect(opt->direction, opt->rect, tr);
1014
1015 *textRect = tr;
1016}
1017
1018QMacStylePrivate::Direction QMacStylePrivate::tabDirection(QStyleOptionTab::Shape shape)
1019{
1020 switch (shape) {
1021 case QStyleOptionTab::RoundedSouth:
1022 case QStyleOptionTab::TriangularSouth:
1023 return South;
1024 case QStyleOptionTab::RoundedNorth:
1025 case QStyleOptionTab::TriangularNorth:
1026 return North;
1027 case QStyleOptionTab::RoundedWest:
1028 case QStyleOptionTab::TriangularWest:
1029 return West;
1030 case QStyleOptionTab::RoundedEast:
1031 case QStyleOptionTab::TriangularEast:
1032 return East;
1033 }
1034}
1035
1036bool QMacStylePrivate::verticalTabs(QMacStylePrivate::Direction direction)
1037{
1038 return (direction == QMacStylePrivate::East
1039 || direction == QMacStylePrivate::West);
1040}
1041
1043 QStyle::ContentsType ct,
1044 QSize szHint, QSize *insz) const
1045{
1046 QStyleHelper::WidgetSizePolicy sz = aquaSizeConstrain(option, ct, szHint, insz);
1047 if (sz == QStyleHelper::SizeDefault)
1048 return QStyleHelper::SizeLarge;
1049 return sz;
1050}
1051
1053 QStyle::ContentsType /*ct*/, QSize /*szHint*/, QSize * /*insz*/) const
1054{
1055 if (!option)
1056 return QStyleHelper::SizeLarge;
1057
1058 if (option->state & QStyle::State_Small)
1059 return QStyleHelper::SizeSmall;
1060 if (option->state & QStyle::State_Mini)
1061 return QStyleHelper::SizeMini;
1062
1063 return QStyleHelper::SizeLarge;
1064
1065}
1066
1069{
1070}
1071
1072QMacStylePrivate::CocoaControl::CocoaControl(CocoaControlType t, QStyleHelper::WidgetSizePolicy s)
1073 : type(t), size(s)
1074{
1075}
1076
1077bool QMacStylePrivate::CocoaControl::operator==(const CocoaControl &other) const
1078{
1079 return other.type == type && other.size == size;
1080}
1081
1083{
1084 // We need this because things like NSView.alignmentRectInsets
1085 // or -[NSCell titleRectForBounds:] won't work unless the control
1086 // has a reasonable frame set. IOW, it's a chicken and egg problem.
1087 // These values are as observed in Xcode 9's Interface Builder.
1088
1089 if (type == Button_PushButton)
1090 return QSizeF(-1, pushButtonDefaultHeight[size]);
1091
1093 || type == Button_PullDown)
1094 return QSizeF(-1, popupButtonDefaultHeight[size]);
1095
1096 if (type == ComboBox)
1097 return QSizeF(-1, comboBoxDefaultHeight[size]);
1098
1099 return QSizeF();
1100}
1101
1102QRectF QMacStylePrivate::CocoaControl::adjustedControlFrame(const QRectF &rect) const
1103{
1104 QRectF frameRect;
1105 const auto frameSize = defaultFrameSize();
1107 frameRect = rect.adjusted(3, 1, -3, -1)
1108 .adjusted(focusRingWidth, focusRingWidth, -focusRingWidth, -focusRingWidth);
1110 // Start from the style option's top-left corner.
1111 frameRect = QRectF(rect.topLeft(),
1112 QSizeF(rect.width(), frameSize.height()));
1113 if (size == QStyleHelper::SizeSmall)
1114 frameRect = frameRect.translated(0, 1.5);
1115 else if (size == QStyleHelper::SizeMini)
1116 frameRect = frameRect.adjusted(0, 0, -8, 0).translated(4, 4);
1117 } else {
1118 // Center in the style option's rect.
1119 frameRect = QRectF(QPointF(0, (rect.height() - frameSize.height()) / 2.0),
1120 QSizeF(rect.width(), frameSize.height()));
1121 frameRect = frameRect.translated(rect.topLeft());
1123 if (size == QStyleHelper::SizeLarge)
1124 frameRect = frameRect.adjusted(0, 0, -6, 0).translated(3, 0);
1125 else if (size == QStyleHelper::SizeSmall)
1126 frameRect = frameRect.adjusted(0, 0, -4, 0).translated(2, 1);
1127 else if (size == QStyleHelper::SizeMini)
1128 frameRect = frameRect.adjusted(0, 0, -9, 0).translated(5, 0);
1129 } else if (type == QMacStylePrivate::ComboBox) {
1130 frameRect = frameRect.adjusted(0, 0, -6, 0).translated(4, 0);
1131 }
1132 }
1133
1134 return frameRect;
1135}
1136
1138{
1140 if (size == QStyleHelper::SizeLarge) {
1141 if (qt_apple_runningWithLiquidGlass())
1142 return QMarginsF(10, 5, 10, 5);
1143 else
1144 return QMarginsF(12, 5, 12, 7);
1145 }
1146 if (size == QStyleHelper::SizeSmall)
1147 return QMarginsF(12, 4, 12, 9);
1148 if (size == QStyleHelper::SizeMini)
1149 return QMarginsF(10, 1, 10, 2);
1150 }
1151
1153 if (size == QStyleHelper::SizeLarge)
1154 return QMarginsF(7.5, 2.5, 22.5, 5.5);
1155 if (size == QStyleHelper::SizeSmall)
1156 return QMarginsF(7.5, 2, 20.5, 4);
1157 if (size == QStyleHelper::SizeMini)
1158 return QMarginsF(4.5, 0, 16.5, 2);
1159 }
1160
1162 return QMarginsF(6, 1, 6, 2);
1163
1164 return QMarginsF();
1165}
1166
1167bool QMacStylePrivate::CocoaControl::getCocoaButtonTypeAndBezelStyle(NSButtonType *buttonType, NSBezelStyle *bezelStyle) const
1168{
1169 switch (type) {
1170 case Button_CheckBox:
1171 *buttonType = NSButtonTypeSwitch;
1172 *bezelStyle = NSBezelStyleRegularSquare;
1173 break;
1174 case Button_Disclosure:
1175 *buttonType = NSButtonTypeOnOff;
1176 *bezelStyle = NSBezelStyleDisclosure;
1177 break;
1178 case Button_RadioButton:
1179 *buttonType = NSButtonTypeRadio;
1180 *bezelStyle = NSBezelStyleRegularSquare;
1181 break;
1183 *buttonType = NSButtonTypePushOnPushOff;
1184 *bezelStyle = NSBezelStyleShadowlessSquare;
1185 break;
1186 case Button_PushButton:
1187 *buttonType = NSButtonTypePushOnPushOff;
1188 *bezelStyle = NSBezelStyleRounded;
1189 break;
1190 default:
1191 return false;
1192 }
1193
1194 return true;
1195}
1196
1198{
1199 if (const auto *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
1200 const bool hasMenu = btn->features & QStyleOptionButton::HasMenu;
1201 // When the contents won't fit in a large sized button,
1202 // and WA_MacNormalSize is not set, make the button square.
1203 // Threshold used to be at 34, not 32.
1204 const auto maxNonSquareHeight = pushButtonDefaultHeight[QStyleHelper::SizeLarge];
1205 const bool isSquare = (btn->features & QStyleOptionButton::Flat)
1206 || (btn->rect.height() > maxNonSquareHeight);
1207// && !(w && w->testAttribute(Qt::WA_MacNormalSize)));
1208 return (isSquare? QMacStylePrivate::Button_SquareButton :
1211 }
1212
1213 if (const auto *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
1214 if (combo->editable)
1216 // TODO Me may support square, non-editable combo boxes, but not more than that
1218 }
1219
1221}
1222
1223/**
1224 Carbon draws comboboxes (and other views) outside the rect given as argument. Use this function to obtain
1225 the corresponding inner rect for drawing the same combobox so that it stays inside the given outerBounds.
1226*/
1227CGRect QMacStylePrivate::comboboxInnerBounds(const CGRect &outerBounds, const CocoaControl &cocoaWidget)
1228{
1229 CGRect innerBounds = outerBounds;
1230 // Carbon draw parts of the view outside the rect.
1231 // So make the rect a bit smaller to compensate
1232 // (I wish HIThemeGetButtonBackgroundBounds worked)
1233 if (cocoaWidget.type == Button_PopupButton) {
1234 switch (cocoaWidget.size) {
1235 case QStyleHelper::SizeSmall:
1236 innerBounds.origin.x += 3;
1237 innerBounds.origin.y += 3;
1238 innerBounds.size.width -= 6;
1239 innerBounds.size.height -= 7;
1240 break;
1241 case QStyleHelper::SizeMini:
1242 innerBounds.origin.x += 2;
1243 innerBounds.origin.y += 2;
1244 innerBounds.size.width -= 5;
1245 innerBounds.size.height -= 6;
1246 break;
1247 case QStyleHelper::SizeLarge:
1248 case QStyleHelper::SizeDefault:
1249 innerBounds.origin.x += 2;
1250 innerBounds.origin.y += 2;
1251 innerBounds.size.width -= 5;
1252 innerBounds.size.height -= 6;
1253 }
1254 } else if (cocoaWidget.type == ComboBox) {
1255 switch (cocoaWidget.size) {
1256 case QStyleHelper::SizeSmall:
1257 innerBounds.origin.x += 3;
1258 innerBounds.origin.y += 3;
1259 innerBounds.size.width -= 7;
1260 innerBounds.size.height -= 8;
1261 break;
1262 case QStyleHelper::SizeMini:
1263 innerBounds.origin.x += 3;
1264 innerBounds.origin.y += 3;
1265 innerBounds.size.width -= 4;
1266 innerBounds.size.height -= 8;
1267 break;
1268 case QStyleHelper::SizeLarge:
1269 case QStyleHelper::SizeDefault:
1270 innerBounds.origin.x += 3;
1271 innerBounds.origin.y += 2;
1272 innerBounds.size.width -= 6;
1273 innerBounds.size.height -= 8;
1274 }
1275 }
1276
1277 return innerBounds;
1278}
1279
1280/**
1281 Inside a combobox Qt places a line edit widget. The size of this widget should depend on the kind
1282 of combobox we choose to draw. This function calculates and returns this size.
1283*/
1284QRectF QMacStylePrivate::comboboxEditBounds(const QRectF &outerBounds, const CocoaControl &cw)
1285{
1286 QRectF ret = outerBounds;
1287 if (cw.type == ComboBox) {
1288 switch (cw.size) {
1289 case QStyleHelper::SizeLarge:
1290 ret = ret.adjusted(0, 0, -25, 0).translated(2, 4.5);
1291 ret.setHeight(16);
1292 break;
1293 case QStyleHelper::SizeSmall:
1294 ret = ret.adjusted(0, 0, -22, 0).translated(2, 3);
1295 ret.setHeight(14);
1296 break;
1297 case QStyleHelper::SizeMini:
1298 ret = ret.adjusted(0, 0, -19, 0).translated(2, 2.5);
1299 ret.setHeight(10.5);
1300 break;
1301 default:
1302 break;
1303 }
1304 } else if (cw.type == Button_PopupButton) {
1305 switch (cw.size) {
1306 case QStyleHelper::SizeLarge:
1307 ret.adjust(10, 1, -23, -4);
1308 break;
1309 case QStyleHelper::SizeSmall:
1310 ret.adjust(10, 4, -20, -3);
1311 break;
1312 case QStyleHelper::SizeMini:
1313 ret.adjust(9, 0, -19, 0);
1314 ret.setHeight(13);
1315 break;
1316 default:
1317 break;
1318 }
1319 }
1320 return ret;
1321}
1322
1325{
1326 if (auto *ssf = QGuiApplicationPrivate::platformTheme()->font(QPlatformTheme::SmallFont))
1327 smallSystemFont = *ssf;
1328 if (auto *msf = QGuiApplicationPrivate::platformTheme()->font(QPlatformTheme::MiniFont))
1329 miniSystemFont = *msf;
1330}
1331
1333{
1334 QMacAutoReleasePool pool;
1335 for (NSView *b : cocoaControls)
1336 [b release];
1337 for (NSCell *cell : cocoaCells)
1338 [cell release];
1339}
1340
1342{
1343 if (cocoaControl.type == QMacStylePrivate::NoControl
1344 || cocoaControl.size == QStyleHelper::SizeDefault)
1345 return nil;
1346
1347 if (cocoaControl.type == Box) {
1348 if (isDarkMode()) {
1349 // See render code in drawPrimitive(PE_FrameTabWidget)
1350 cocoaControl.type = Box_Dark;
1351 }
1352 }
1353
1354 NSView *bv = cocoaControls.value(cocoaControl, nil);
1355 if (!bv) {
1356 switch (cocoaControl.type) {
1357 case Box: {
1358 NSBox *box = [[NSBox alloc] init];
1359 bv = box;
1360 box.title = @"";
1361 box.titlePosition = NSNoTitle;
1362 break;
1363 }
1364 case Box_Dark:
1365 bv = [[QDarkNSBox alloc] init];
1366 break;
1367 case Button_CheckBox:
1368 case Button_Disclosure:
1369 case Button_PushButton:
1370 case Button_RadioButton:
1371 case Button_SquareButton: {
1372 NSButton *bc = [[NSButton alloc] init];
1373 bc.title = @"";
1374 // See below for style and bezel setting.
1375 bv = bc;
1376 break;
1377 }
1378 case Button_PopupButton:
1379 case Button_PullDown: {
1380 NSPopUpButton *bc = [[NSPopUpButton alloc] init];
1381 bc.title = @"";
1382 if (cocoaControl.type == Button_PullDown)
1383 bc.pullsDown = YES;
1384 bv = bc;
1385 break;
1386 }
1387 case Button_WindowClose:
1389 case Button_WindowZoom: {
1390 const NSWindowButton button = [=] {
1391 switch (cocoaControl.type) {
1392 case Button_WindowClose:
1393 return NSWindowCloseButton;
1394 case Button_WindowMiniaturize:
1395 return NSWindowMiniaturizeButton;
1396 case Button_WindowZoom:
1397 return NSWindowZoomButton;
1398 default:
1399 break;
1400 }
1401 Q_UNREACHABLE();
1402 } ();
1403 const auto styleMask = NSWindowStyleMaskTitled
1404 | NSWindowStyleMaskClosable
1405 | NSWindowStyleMaskMiniaturizable
1406 | NSWindowStyleMaskResizable;
1407 bv = [NSWindow standardWindowButton:button forStyleMask:styleMask];
1408 [bv retain];
1409 break;
1410 }
1411 case SearchField:
1412 bv = [[NSSearchField alloc] init];
1413 break;
1414 case ComboBox:
1415 bv = [[NSComboBox alloc] init];
1416 break;
1417 case ProgressIndicator_Determinate:
1418 bv = [[NSProgressIndicator alloc] init];
1419 break;
1420 case ProgressIndicator_Indeterminate:
1421 bv = [[QIndeterminateProgressIndicator alloc] init];
1422 break;
1423 case Scroller_Horizontal:
1424 bv = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)];
1425 break;
1426 case Scroller_Vertical:
1427 // Cocoa sets the orientation from the view's frame
1428 // at construction time, and it cannot be changed later.
1429 bv = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 20, 200)];
1430 break;
1431 case Slider_Horizontal:
1432 bv = [[NSSlider alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)];
1433 break;
1434 case Slider_Vertical:
1435 // Cocoa sets the orientation from the view's frame
1436 // at construction time, and it cannot be changed later.
1437 bv = [[NSSlider alloc] initWithFrame:NSMakeRect(0, 0, 20, 200)];
1438 break;
1439 case SplitView_Horizontal:
1440 bv = [[NSSplitView alloc] init];
1441 break;
1442 case SplitView_Vertical:
1443 bv = [[QVerticalSplitView alloc] init];
1444 break;
1445 case TextField:
1446 bv = [[NSTextField alloc] init];
1447 break;
1448 default:
1449 break;
1450 }
1451
1452 if ([bv isKindOfClass:[NSControl class]]) {
1453 auto *ctrl = static_cast<NSControl *>(bv);
1454 switch (cocoaControl.size) {
1455 case QStyleHelper::SizeSmall:
1456 ctrl.controlSize = NSControlSizeSmall;
1457 break;
1458 case QStyleHelper::SizeMini:
1459 ctrl.controlSize = NSControlSizeMini;
1460 break;
1461 default:
1462 break;
1463 }
1464 } else if (cocoaControl.type == ProgressIndicator_Determinate ||
1465 cocoaControl.type == ProgressIndicator_Indeterminate) {
1466 auto *pi = static_cast<NSProgressIndicator *>(bv);
1467 pi.indeterminate = (cocoaControl.type == ProgressIndicator_Indeterminate);
1468 switch (cocoaControl.size) {
1469 case QStyleHelper::SizeSmall:
1470 pi.controlSize = NSControlSizeSmall;
1471 break;
1472 case QStyleHelper::SizeMini:
1473 pi.controlSize = NSControlSizeMini;
1474 break;
1475 default:
1476 break;
1477 }
1478 }
1479
1480 cocoaControls.insert(cocoaControl, bv);
1481 }
1482
1483 NSButtonType buttonType;
1484 NSBezelStyle bezelStyle;
1486 // FIXME We need to reset the button's type and
1487 // bezel style properties, even when cached.
1488 auto *button = static_cast<NSButton *>(bv);
1493 }
1494
1495 return bv;
1496}
1497
1499{
1500 NSCell *cell = cocoaCells[cocoaControl];
1501 if (!cell) {
1502 switch (cocoaControl.type) {
1503 case Stepper:
1504 cell = [[NSStepperCell alloc] init];
1505 break;
1506 case Button_Disclosure: {
1507 NSButtonCell *bc = [[NSButtonCell alloc] init];
1508 bc.buttonType = NSButtonTypeOnOff;
1509 bc.bezelStyle = NSBezelStyleDisclosure;
1510 cell = bc;
1511 break;
1512 }
1513 default:
1514 break;
1515 }
1516
1517 switch (cocoaControl.size) {
1518 case QStyleHelper::SizeSmall:
1519 cell.controlSize = NSControlSizeSmall;
1520 break;
1521 case QStyleHelper::SizeMini:
1522 cell.controlSize = NSControlSizeMini;
1523 break;
1524 default:
1525 break;
1526 }
1527
1528 cocoaCells.insert(cocoaControl, cell);
1529 }
1530
1531 return cell;
1532}
1533
1534void QMacStylePrivate::drawNSViewInRect(NSView *view, const QRectF &rect, QPainter *p, DrawRectBlock drawRectBlock) const
1535{
1536 QMacAutoReleasePool pool;
1537 QMacCGContext ctx(p);
1538 setupNSGraphicsContext(ctx, YES);
1539
1540 // FIXME: The rect that we get in is relative to the widget that we're drawing
1541 // style on behalf of, and doesn't take into account the offset of that widget
1542 // to the widget that owns the backingstore, which we are placing the native
1543 // view into below. This means most of the views are placed in the upper left
1544 // corner of backingStoreNSView, which does not map to where the actual widget
1545 // is, and which may cause problems such as triggering a setNeedsDisplay of the
1546 // backingStoreNSView for the wrong rect. We work around this by making the view
1547 // layer-backed, which prevents triggering display of the backingStoreNSView, but
1548 // but there may be other issues lurking here due to the wrong position. QTBUG-68023
1549 view.wantsLayer = YES;
1550
1551 // FIXME: We are also setting the frame of the incoming view a lot at the call
1552 // sites of this function, making it unclear who's actually responsible for
1553 // maintaining the size and position of the view. In theory the call sites
1554 // should ensure the _size_ of the view is correct, and then let this code
1555 // take care of _positioning_ the view at the right place inside backingStoreNSView.
1556 // For now we pass on the rect as is, to prevent any regressions until this
1557 // can be investigated properly.
1558 view.frame = rect.toCGRect();
1559
1560 [backingStoreNSView addSubview:view];
1561
1562 // FIXME: Based on the code below, this method isn't drawing an NSView into
1563 // a rect, it's drawing _part of the NSView_, defined by the incoming clip
1564 // or dirty rect, into the current graphics context. We're doing some manual
1565 // translations at the call sites that would indicate that this relationship
1566 // is a bit fuzzy.
1567 const CGRect dirtyRect = rect.toCGRect();
1568
1569 if (drawRectBlock)
1570 drawRectBlock(ctx, dirtyRect);
1571 else
1572 [view drawRect:dirtyRect];
1573
1574 [view removeFromSuperviewWithoutNeedingDisplay];
1575
1576 restoreNSGraphicsContext(ctx);
1577}
1578
1579void QMacStylePrivate::resolveCurrentNSView(QWindow *window) const
1580{
1581 backingStoreNSView = window ? (NSView *)window->winId() : nil;
1582}
1583
1585{
1586 return new QMacApperanceStyle<QMacStyle, QStyleOption, QStyleOptionComplex>;
1587}
1588
1589QMacStyle::QMacStyle()
1590 : QCommonStyle(*new QMacStylePrivate)
1591{
1592 QMacAutoReleasePool pool;
1593
1594 static QMacNotificationObserver scrollbarStyleObserver(nil,
1595 NSPreferredScrollerStyleDidChangeNotification, []() {
1596 // Purge destroyed scroll bars
1597 QMacStylePrivate::scrollBars.removeAll(QPointer<QObject>());
1598
1599 QEvent event(QEvent::StyleChange);
1600 for (const auto &o : QMacStylePrivate::scrollBars)
1601 QCoreApplication::sendEvent(o, &event);
1602 });
1603}
1604
1606{
1607}
1608
1610{
1611 Q_D(QMacStyle);
1612 for (NSView *b : d->cocoaControls)
1613 [b release];
1614 d->cocoaControls.clear();
1615}
1616
1617int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt) const
1618{
1619 Q_D(const QMacStyle);
1620 const int controlSize = getControlSize(opt);
1621 int ret = 0;
1622
1623 switch (metric) {
1624 case PM_TabCloseIndicatorWidth:
1625 case PM_TabCloseIndicatorHeight:
1626 ret = closeButtonSize;
1627 break;
1628 case PM_ToolBarIconSize:
1629 ret = proxy()->pixelMetric(PM_LargeIconSize);
1630 break;
1631 case PM_FocusFrameVMargin:
1632 case PM_FocusFrameHMargin:
1634 break;
1635 case PM_DialogButtonsSeparator:
1636 ret = -5;
1637 break;
1638 case PM_DialogButtonsButtonHeight: {
1639 QSize sz;
1640 ret = d->aquaSizeConstrain(opt, QStyle::CT_PushButton, QSize(-1, -1), &sz);
1641 if (sz == QSize(-1, -1))
1642 ret = 32;
1643 else
1644 ret = sz.height();
1645 break; }
1646 case PM_DialogButtonsButtonWidth: {
1647 QSize sz;
1648 ret = d->aquaSizeConstrain(opt, QStyle::CT_PushButton, QSize(-1, -1), &sz);
1649 if (sz == QSize(-1, -1))
1650 ret = 70;
1651 else
1652 ret = sz.width();
1653 break; }
1654
1655 case PM_MenuBarHMargin:
1656 ret = 8;
1657 break;
1658
1659 case PM_MenuBarVMargin:
1660 ret = 0;
1661 break;
1662
1663 case PM_MenuBarPanelWidth:
1664 ret = 0;
1665 break;
1666
1667 case PM_MenuButtonIndicator:
1668 ret = toolButtonArrowSize;
1669 break;
1670
1671 case QStyle::PM_MenuDesktopFrameWidth:
1672 ret = 5;
1673 break;
1674
1675 case PM_CheckBoxLabelSpacing:
1676 case PM_RadioButtonLabelSpacing:
1677 ret = [=] {
1678 if (opt) {
1679 if (opt->state & State_Mini)
1680 return 4;
1681 if (opt->state & State_Small)
1682 return 3;
1683 }
1684 return 2;
1685 } ();
1686 break;
1687 case PM_MenuScrollerHeight:
1688 ret = 15; // I hate having magic numbers in here...
1689 break;
1690 case PM_DefaultFrameWidth:
1691//#if QT_CONFIG(mainwindow)
1692// if (widget && (widget->isWindow() || !widget->parentWidget()
1693// || (qobject_cast<const QMainWindow*>(widget->parentWidget())
1694// && static_cast<QMainWindow *>(widget->parentWidget())->centralWidget() == widget))
1695// && qobject_cast<const QAbstractScrollArea *>(widget))
1696// ret = 0;
1697// else
1698//#endif
1699 // The combo box popup has no frame.
1700 if (qstyleoption_cast<const QStyleOptionComboBox *>(opt) != 0)
1701 ret = 0;
1702 else
1703 ret = 1;
1704 break;
1705 case PM_MaximumDragDistance:
1706 ret = -1;
1707 break;
1708 case PM_ScrollBarSliderMin:
1709 ret = 24;
1710 break;
1711 case PM_SpinBoxFrameWidth:
1713 break;
1714 case PM_ButtonShiftHorizontal:
1715 case PM_ButtonShiftVertical:
1716 ret = 0;
1717 break;
1718 case PM_SliderLength:
1719 ret = 17;
1720 break;
1721 // Returns the number of pixels to use for the business part of the
1722 // slider (i.e., the non-tickmark portion). The remaining space is shared
1723 // equally between the tickmark regions.
1724 case PM_SliderControlThickness:
1725 if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
1726 int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
1727 int ticks = sl->tickPosition;
1728 int n = 0;
1729 if (ticks & QStyleOptionSlider::TicksAbove)
1730 ++n;
1731 if (ticks & QStyleOptionSlider::TicksBelow)
1732 ++n;
1733 if (!n) {
1734 ret = space;
1735 break;
1736 }
1737
1738 int thick = 6; // Magic constant to get 5 + 16 + 5
1739 if (ticks != QStyleOptionSlider::TicksBothSides && ticks != QStyleOptionSlider::NoTicks)
1740 thick += proxy()->pixelMetric(PM_SliderLength, sl) / 4;
1741
1742 space -= thick;
1743 if (space > 0)
1744 thick += (space * 2) / (n + 2);
1745 ret = thick;
1746 } else {
1747 ret = 0;
1748 }
1749 break;
1750 case PM_SmallIconSize:
1751 ret = int(QStyleHelper::dpiScaled(16., opt));
1752 break;
1753
1754 case PM_LargeIconSize:
1755 ret = int(QStyleHelper::dpiScaled(32., opt));
1756 break;
1757
1758 case PM_IconViewIconSize:
1759 ret = proxy()->pixelMetric(PM_LargeIconSize, opt);
1760 break;
1761
1762 case PM_ButtonDefaultIndicator:
1763 ret = 0;
1764 break;
1765 case PM_TitleBarHeight: {
1766 NSUInteger style = NSWindowStyleMaskTitled;
1767// if (widget && ((widget->windowFlags() & Qt::Tool) == Qt::Tool))
1768// style |= NSWindowStyleMaskUtilityWindow;
1769 ret = int([NSWindow frameRectForContentRect:NSZeroRect
1770 styleMask:style].size.height);
1771 break; }
1772 case QStyle::PM_TabBarTabHSpace:
1773 switch (d->aquaSizeConstrain(opt)) {
1774 case QStyleHelper::SizeLarge:
1775 ret = QCommonStyle::pixelMetric(metric, opt);
1776 break;
1777 case QStyleHelper::SizeSmall:
1778 ret = 20;
1779 break;
1780 case QStyleHelper::SizeMini:
1781 ret = 16;
1782 break;
1783 case QStyleHelper::SizeDefault:
1784 const QStyleOptionTab *tb = qstyleoption_cast<const QStyleOptionTab *>(opt);
1785 if (tb && tb->documentMode)
1786 ret = 30;
1787 else
1788 ret = QCommonStyle::pixelMetric(metric, opt);
1789 break;
1790 }
1791 break;
1792 case PM_TabBarTabVSpace:
1793 ret = 4;
1794 break;
1795 case PM_TabBarTabShiftHorizontal:
1796 case PM_TabBarTabShiftVertical:
1797 ret = 0;
1798 break;
1799 case PM_TabBarBaseHeight:
1800 ret = 0;
1801 break;
1802 case PM_TabBarTabOverlap:
1803 ret = 1;
1804 break;
1805 case PM_TabBarBaseOverlap:
1806 switch (d->aquaSizeConstrain(opt)) {
1807 case QStyleHelper::SizeDefault:
1808 case QStyleHelper::SizeLarge:
1809 ret = 11;
1810 break;
1811 case QStyleHelper::SizeSmall:
1812 ret = 8;
1813 break;
1814 case QStyleHelper::SizeMini:
1815 ret = 7;
1816 break;
1817 }
1818 break;
1819 case PM_ScrollBarExtent: {
1820 const QStyleHelper::WidgetSizePolicy size = d->effectiveAquaSizeConstrain(opt);
1821 ret = static_cast<int>([NSScroller
1822 scrollerWidthForControlSize:static_cast<NSControlSize>(size)
1823 scrollerStyle:[NSScroller preferredScrollerStyle]]);
1824 break; }
1825 case PM_IndicatorHeight: {
1826 switch (d->aquaSizeConstrain(opt)) {
1827 case QStyleHelper::SizeDefault:
1828 case QStyleHelper::SizeLarge:
1830 break;
1831 case QStyleHelper::SizeMini:
1833 break;
1834 case QStyleHelper::SizeSmall:
1836 break;
1837 }
1838 break; }
1839 case PM_IndicatorWidth: {
1840 switch (d->aquaSizeConstrain(opt)) {
1841 case QStyleHelper::SizeDefault:
1842 case QStyleHelper::SizeLarge:
1844 break;
1845 case QStyleHelper::SizeMini:
1847 break;
1848 case QStyleHelper::SizeSmall:
1850 break;
1851 }
1852 ++ret;
1853 break; }
1854 case PM_ExclusiveIndicatorHeight: {
1855 switch (d->aquaSizeConstrain(opt)) {
1856 case QStyleHelper::SizeDefault:
1857 case QStyleHelper::SizeLarge:
1859 break;
1860 case QStyleHelper::SizeMini:
1862 break;
1863 case QStyleHelper::SizeSmall:
1865 break;
1866 }
1867 break; }
1868 case PM_ExclusiveIndicatorWidth: {
1869 switch (d->aquaSizeConstrain(opt)) {
1870 case QStyleHelper::SizeDefault:
1871 case QStyleHelper::SizeLarge:
1873 break;
1874 case QStyleHelper::SizeMini:
1876 break;
1877 case QStyleHelper::SizeSmall:
1879 break;
1880 }
1881 ++ret;
1882 break; }
1883 case PM_MenuVMargin:
1884 ret = 4;
1885 break;
1886 case PM_MenuPanelWidth:
1887 ret = 0;
1888 break;
1889 case PM_ToolTipLabelFrameWidth:
1890 ret = 0;
1891 break;
1892 case PM_SizeGripSize: {
1893 QStyleHelper::WidgetSizePolicy aSize;
1894// if (widget && widget->window()->windowType() == Qt::Tool)
1895// aSize = QStyleHelper::SizeSmall;
1896// else
1897 aSize = QStyleHelper::SizeLarge;
1898 const QSize size = qt_aqua_get_known_size(CT_SizeGrip, opt, QSize(), aSize);
1899 ret = size.width();
1900 break; }
1901 case PM_MdiSubWindowFrameWidth:
1902 ret = 1;
1903 break;
1904 case PM_DockWidgetFrameWidth:
1905 ret = 0;
1906 break;
1907 case PM_DockWidgetTitleMargin:
1908 ret = 0;
1909 break;
1910 case PM_DockWidgetSeparatorExtent:
1911 ret = 1;
1912 break;
1913 case PM_ToolBarHandleExtent:
1914 ret = 11;
1915 break;
1916 case PM_ToolBarItemMargin:
1917 ret = 0;
1918 break;
1919 case PM_ToolBarItemSpacing:
1920 ret = 4;
1921 break;
1922 case PM_SplitterWidth:
1923 ret = 7;
1924 break;
1925 case PM_LayoutLeftMargin:
1926 case PM_LayoutTopMargin:
1927 case PM_LayoutRightMargin:
1928 case PM_LayoutBottomMargin:
1929 {
1930 if (opt->state & State_Window) {
1931 /*
1932 AHIG would have (20, 8, 10) here but that makes
1933 no sense. It would also have 14 for the top margin
1934 but this contradicts both Builder and most
1935 applications.
1936 */
1937 return_SIZE(20, 10, 10); // AHIG
1938 } else {
1939 // hack to detect QTabWidget
1940// if (widget && widget->parentWidget()
1941// && widget->parentWidget()->sizePolicy().controlType() == QSizePolicy::TabWidget) {
1942// if (metric == PM_LayoutTopMargin) {
1943// /*
1944// Builder would have 14 (= 20 - 6) instead of 12,
1945// but that makes the tab look disproportionate.
1946// */
1947// return_SIZE(12, 6, 6); // guess
1948// } else {
1949// return_SIZE(20 /* Builder */, 8 /* guess */, 8 /* guess */);
1950// }
1951// } else {
1952 /*
1953 Child margins are highly inconsistent in AHIG and Builder.
1954 */
1955 return_SIZE(12, 8, 6); // guess
1956// }
1957 }
1958 }
1959 case PM_LayoutHorizontalSpacing:
1960 case PM_LayoutVerticalSpacing:
1961 return -1;
1962 case PM_MenuHMargin:
1963 ret = 0;
1964 break;
1965 case PM_ToolBarExtensionExtent:
1966 ret = 21;
1967 break;
1968 case PM_ToolBarFrameWidth:
1969 ret = 1;
1970 break;
1971 case PM_ScrollView_ScrollBarOverlap:
1972 ret = styleHint(SH_ScrollBar_Transient, opt, nullptr)
1973 ? pixelMetric(PM_ScrollBarExtent, opt)
1974 : 0;
1975 break;
1976 case PM_PushButtonFocusFrameRadius:
1977 ret = LargeSmallMini(opt, 5, 4, 2);
1978 break;
1979 case PM_CheckBoxFocusFrameRadius:
1980 ret = LargeSmallMini(opt, 3, 2, 1);
1981 break;
1982 case PM_SearchFieldFocusFrameRadius:
1983 case PM_ComboBoxFocusFrameRadius:
1984 if (qt_apple_runningWithLiquidGlass())
1985 ret = LargeSmallMini(opt, 8, 4, 1);
1986 else
1987 ret = LargeSmallMini(opt, 5, 4, 1);
1988 break;
1989 case PM_RadioButtonFocusFrameRadius:
1990 ret = 7;
1991 break;
1992 case PM_SliderFocusFrameRadius:
1993 // QTBUG-93423: We currently need to skip drawing a focus ring around the handle, since
1994 // the handle drawn by the UIKit is not centered inside the rect we get from calling
1995 // [cell knobRectFlipped:slider.isFlipped]. So we choose to draw the focus as
1996 // a rect instead until we have a better solution available.
1997 ret = 0;
1998 break;
1999 case PM_DialFocusFrameRadius:
2000 case PM_SpinBoxFocusFrameRadius:
2001 case PM_TextAreaFocusFrameRadius:
2002 case PM_TextFieldFocusFrameRadius:
2003 ret = qt_apple_runningWithLiquidGlass() ? 6 : 0;
2004 break;
2005 default:
2006 ret = QCommonStyle::pixelMetric(metric, opt);
2007 break;
2008 }
2009 return ret;
2010}
2011
2012//QPalette QMacStyle::standardPalette() const
2013//{
2014// auto platformTheme = QGuiApplicationPrivate::platformTheme();
2015// auto styleNames = platformTheme->themeHint(QPlatformTheme::StyleNames);
2016// if (styleNames.toStringList().contains("macintosh"))
2017// return QPalette(); // Inherit everything from theme
2018// else
2019// return QStyle::standardPalette();
2020//}
2021
2022int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, QStyleHintReturn *hret) const
2023{
2024 QMacAutoReleasePool pool;
2025
2026 int ret = 0;
2027 switch (sh) {
2028 case SH_Slider_SnapToValue:
2029 case SH_PrintDialog_RightAlignButtons:
2030 case SH_FontDialog_SelectAssociatedText:
2031 case SH_MenuBar_MouseTracking:
2032 case SH_Menu_MouseTracking:
2033 case SH_ComboBox_ListMouseTracking:
2034 case SH_MainWindow_SpaceBelowMenuBar:
2035 case SH_ItemView_ChangeHighlightOnFocus:
2036 ret = 1;
2037 break;
2038 case SH_ToolBox_SelectedPageTitleBold:
2039 ret = 0;
2040 break;
2041 case SH_DialogButtonBox_ButtonsHaveIcons:
2042 ret = 0;
2043 break;
2044 case SH_Menu_SelectionWrap:
2045 ret = false;
2046 break;
2047 case SH_Menu_KeyboardSearch:
2048 ret = true;
2049 break;
2050 case SH_Menu_SpaceActivatesItem:
2051 ret = true;
2052 break;
2053 case SH_Slider_AbsoluteSetButtons:
2054 ret = Qt::LeftButton|Qt::MiddleButton;
2055 break;
2056 case SH_Slider_PageSetButtons:
2057 ret = 0;
2058 break;
2059 case SH_ScrollBar_ContextMenu:
2060 ret = false;
2061 break;
2062 case SH_TitleBar_AutoRaise:
2063 ret = true;
2064 break;
2065 case SH_Menu_AllowActiveAndDisabled:
2066 ret = false;
2067 break;
2068 case SH_Menu_SubMenuPopupDelay:
2069 ret = 100;
2070 break;
2071 case SH_Menu_SubMenuUniDirection:
2072 ret = true;
2073 break;
2074 case SH_Menu_SubMenuSloppySelectOtherActions:
2075 ret = false;
2076 break;
2077 case SH_Menu_SubMenuResetWhenReenteringParent:
2078 ret = true;
2079 break;
2080 case SH_Menu_SubMenuDontStartSloppyOnLeave:
2081 ret = true;
2082 break;
2083
2084 case SH_ScrollBar_LeftClickAbsolutePosition: {
2085 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
2086 bool result = [defaults boolForKey:@"AppleScrollerPagingBehavior"];
2087// if(QApplication::keyboardModifiers() & Qt::AltModifier)
2088// ret = !result;
2089// else
2090 ret = result;
2091 break; }
2092 case SH_TabBar_PreferNoArrows:
2093 ret = true;
2094 break;
2095 /*
2096 case SH_DialogButtons_DefaultButton:
2097 ret = QDialogButtons::Reject;
2098 break;
2099 */
2100 case SH_GroupBox_TextLabelVerticalAlignment:
2101 ret = Qt::AlignTop;
2102 break;
2103 case SH_ScrollView_FrameOnlyAroundContents:
2104 ret = QCommonStyle::styleHint(sh, opt, hret);
2105 break;
2106 case SH_Menu_FillScreenWithScroll:
2107 ret = false;
2108 break;
2109 case SH_Menu_Scrollable:
2110 ret = true;
2111 break;
2112 case SH_RichText_FullWidthSelection:
2113 ret = true;
2114 break;
2115 case SH_BlinkCursorWhenTextSelected:
2116 ret = false;
2117 break;
2118 case SH_Slider_StopMouseOverSlider:
2119 ret = true;
2120 break;
2121 case SH_ListViewExpand_SelectMouseType:
2122 ret = QEvent::MouseButtonRelease;
2123 break;
2124 case SH_TabBar_SelectMouseType:
2125 if (const QStyleOptionTabBarBase *opt2 = qstyleoption_cast<const QStyleOptionTabBarBase *>(opt)) {
2126 ret = opt2->documentMode ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease;
2127 } else {
2128 ret = QEvent::MouseButtonRelease;
2129 }
2130 break;
2131 case SH_ComboBox_Popup:
2132 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt))
2133 ret = !cmb->editable;
2134 else
2135 ret = 0;
2136 break;
2137 case SH_Workspace_FillSpaceOnMaximize:
2138 ret = true;
2139 break;
2140 case SH_Widget_ShareActivation:
2141 ret = true;
2142 break;
2143 case SH_Header_ArrowAlignment:
2144 ret = Qt::AlignRight;
2145 break;
2146 case SH_TabBar_Alignment: {
2147//#if QT_CONFIG(tabwidget)
2148// if (const QTabWidget *tab = qobject_cast<const QTabWidget*>(w)) {
2149// if (tab->documentMode()) {
2150// ret = Qt::AlignLeft;
2151// break;
2152// }
2153// }
2154//#endif
2155//#if QT_CONFIG(tabbar)
2156// if (const QTabBar *tab = qobject_cast<const QTabBar*>(w)) {
2157// if (tab->documentMode()) {
2158// ret = Qt::AlignLeft;
2159// break;
2160// }
2161// }
2162//#endif
2163 ret = Qt::AlignCenter;
2164 } break;
2165 case SH_UnderlineShortcut:
2166 ret = false;
2167 break;
2168 case SH_ToolTipLabel_Opacity:
2169 ret = 242; // About 95%
2170 break;
2171 case SH_Button_FocusPolicy:
2172 ret = Qt::TabFocus;
2173 break;
2174 case SH_EtchDisabledText:
2175 ret = false;
2176 break;
2177 case SH_FocusFrame_Mask: {
2178 ret = true;
2179 if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(hret)) {
2180 const uchar fillR = 192, fillG = 191, fillB = 190;
2181 QImage img;
2182
2183 QSize pixmapSize = opt->rect.size();
2184 if (!pixmapSize.isEmpty()) {
2185 QPixmap pix(pixmapSize);
2186 pix.fill(QColor(fillR, fillG, fillB));
2187 QPainter pix_paint(&pix);
2188 proxy()->drawControl(CE_FocusFrame, opt, &pix_paint);
2189 pix_paint.end();
2190 img = pix.toImage();
2191 }
2192
2193 const QRgb *sptr = (QRgb*)img.bits(), *srow;
2194 const qsizetype sbpl = img.bytesPerLine();
2195 const int w = sbpl/4, h = img.height();
2196
2197 QImage img_mask(img.width(), img.height(), QImage::Format_ARGB32);
2198 QRgb *dptr = (QRgb*)img_mask.bits(), *drow;
2199 const qsizetype dbpl = img_mask.bytesPerLine();
2200
2201 for (int y = 0; y < h; ++y) {
2202 srow = sptr+((y*sbpl)/4);
2203 drow = dptr+((y*dbpl)/4);
2204 for (int x = 0; x < w; ++x) {
2205 const int redDiff = qRed(*srow) - fillR;
2206 const int greenDiff = qGreen(*srow) - fillG;
2207 const int blueDiff = qBlue(*srow) - fillB;
2208 const int diff = (redDiff * redDiff) + (greenDiff * greenDiff) + (blueDiff * blueDiff);
2209 (*drow++) = (diff < 10) ? 0xffffffff : 0xff000000;
2210 ++srow;
2211 }
2212 }
2213 QBitmap qmask = QBitmap::fromImage(std::move(img_mask));
2214 mask->region = QRegion(qmask);
2215 }
2216 break; }
2217 case SH_TitleBar_NoBorder:
2218 ret = 1;
2219 break;
2220 case SH_RubberBand_Mask:
2221 ret = 0;
2222 break;
2223 case SH_ComboBox_LayoutDirection:
2224 ret = Qt::LeftToRight;
2225 break;
2226 case SH_ItemView_EllipsisLocation:
2227 ret = Qt::AlignHCenter;
2228 break;
2229 case SH_ItemView_ShowDecorationSelected:
2230 ret = true;
2231 break;
2232 case SH_TitleBar_ModifyNotification:
2233 ret = false;
2234 break;
2235 case SH_ScrollBar_RollBetweenButtons:
2236 ret = true;
2237 break;
2238 case SH_WindowFrame_Mask:
2239 ret = false;
2240 break;
2241 case SH_TabBar_ElideMode:
2242 ret = Qt::ElideRight;
2243 break;
2244// case SH_DialogButtonLayout:
2245// ret = QDialogButtonBox::MacLayout;
2246// break;
2247// case SH_FormLayoutWrapPolicy:
2248// ret = QFormLayout::DontWrapRows;
2249// break;
2250// case SH_FormLayoutFieldGrowthPolicy:
2251// ret = QFormLayout::FieldsStayAtSizeHint;
2252// break;
2253 case SH_FormLayoutFormAlignment:
2254 ret = Qt::AlignHCenter | Qt::AlignTop;
2255 break;
2256 case SH_FormLayoutLabelAlignment:
2257 ret = Qt::AlignRight;
2258 break;
2259// case SH_ComboBox_PopupFrameStyle:
2260// ret = QFrame::NoFrame;
2261// break;
2262 case SH_MessageBox_TextInteractionFlags:
2263 ret = Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse | Qt::TextSelectableByKeyboard;
2264 break;
2265 case SH_SpellCheckUnderlineStyle:
2266 ret = QTextCharFormat::DashUnderline;
2267 break;
2268 case SH_MessageBox_CenterButtons:
2269 ret = false;
2270 break;
2271 case SH_MenuBar_AltKeyNavigation:
2272 ret = false;
2273 break;
2274 case SH_ItemView_MovementWithoutUpdatingSelection:
2275 ret = false;
2276 break;
2277 case SH_FocusFrame_AboveWidget:
2278 ret = true;
2279 break;
2280// case SH_WizardStyle:
2281// ret = QWizard::MacStyle;
2282// break;
2283 case SH_ItemView_ArrowKeysNavigateIntoChildren:
2284 ret = false;
2285 break;
2286 case SH_Menu_FlashTriggeredItem:
2287 ret = true;
2288 break;
2289 case SH_Menu_FadeOutOnHide:
2290 ret = true;
2291 break;
2292 case SH_ItemView_PaintAlternatingRowColorsForEmptyArea:
2293 ret = true;
2294 break;
2295 case SH_TabBar_CloseButtonPosition:
2296 ret = QStyleOptionTabBarBase::LeftSide;
2297 break;
2298 case SH_DockWidget_ButtonsHaveFrame:
2299 ret = false;
2300 break;
2301 case SH_ScrollBar_Transient:
2302 // For the initial version in QQC2, we don't support transient scrollbars. When the
2303 // time comes, consider doing all such animations from QML.
2304 // ret = [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay;
2305 ret = false;
2306 break;
2307 case SH_TitleBar_ShowToolTipsOnButtons:
2308 // min/max/close buttons on windows don't show tool tips
2309 ret = false;
2310 break;
2311 case SH_ComboBox_AllowWheelScrolling:
2312 ret = false;
2313 break;
2314 case SH_SpinBox_ButtonsInsideFrame:
2315 ret = false;
2316 break;
2317 case SH_Table_GridLineColor:
2318 ret = int(qt_mac_toQColor(NSColor.gridColor).rgba());
2319 break;
2320 default:
2321 ret = QCommonStyle::styleHint(sh, opt, hret);
2322 break;
2323 }
2324 return ret;
2325}
2326
2327QPixmap QMacStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
2328 const QStyleOption *opt) const
2329{
2330 switch (iconMode) {
2331 case QIcon::Disabled: {
2332 QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
2333 int imgh = img.height();
2334 int imgw = img.width();
2335 QRgb pixel;
2336 for (int y = 0; y < imgh; ++y) {
2337 for (int x = 0; x < imgw; ++x) {
2338 pixel = img.pixel(x, y);
2339 img.setPixel(x, y, qRgba(qRed(pixel), qGreen(pixel), qBlue(pixel),
2340 qAlpha(pixel) / 2));
2341 }
2342 }
2343 return QPixmap::fromImage(img);
2344 }
2345 default:
2346 ;
2347 }
2348 return QCommonStyle::generatedIconPixmap(iconMode, pixmap, opt);
2349}
2350
2351
2352QPixmap QMacStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt) const
2353{
2354 // The default implementation of QStyle::standardIconImplementation() is to call standardPixmap()
2355 // I don't want infinite recursion so if we do get in that situation, just return the Window's
2356 // standard pixmap instead (since there is no mac-specific icon then). This should be fine until
2357 // someone changes how Windows standard
2358 // pixmap works.
2359 static bool recursionGuard = false;
2360
2361 if (recursionGuard)
2362 return QCommonStyle::standardPixmap(standardPixmap, opt);
2363
2364 recursionGuard = true;
2365 QIcon icon = proxy()->standardIcon(standardPixmap, opt);
2366 recursionGuard = false;
2367 int size;
2368 switch (standardPixmap) {
2369 default:
2370 size = 32;
2371 break;
2372 case SP_MessageBoxCritical:
2373 case SP_MessageBoxQuestion:
2374 case SP_MessageBoxInformation:
2375 case SP_MessageBoxWarning:
2376 size = 64;
2377 break;
2378 }
2379 return icon.pixmap(QSize(size, size), opt->window->devicePixelRatio());
2380}
2381
2382void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p) const
2383{
2384 Q_D(const QMacStyle);
2385
2386 QMacCGContext cg(p);
2387 d->resolveCurrentNSView(opt->window);
2388
2389 switch (pe) {
2390 case PE_IndicatorArrowUp:
2391 case PE_IndicatorArrowDown:
2392 case PE_IndicatorArrowRight:
2393 case PE_IndicatorArrowLeft: {
2394 p->save();
2395 p->setRenderHint(QPainter::Antialiasing);
2396 const int xOffset = 1; // FIXME: opt->direction == Qt::LeftToRight ? 2 : -1;
2397 qreal halfSize = 0.5 * qMin(opt->rect.width(), opt->rect.height());
2398 const qreal penWidth = qMax(halfSize / 3.0, 1.25);
2399//#if QT_CONFIG(toolbutton)
2400// if (const QToolButton *tb = qobject_cast<const QToolButton *>(w)) {
2401// // When stroking the arrow, make sure it fits in the tool button
2402// if (tb->arrowType() != Qt::NoArrow
2403// || tb->popupMode() == QToolButton::MenuButtonPopup)
2404// halfSize -= penWidth;
2405// }
2406//#endif
2407
2408 QTransform transform;
2409 transform.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2);
2410 QPainterPath path;
2411 switch(pe) {
2412 default:
2413 case PE_IndicatorArrowDown:
2414 break;
2415 case PE_IndicatorArrowUp:
2416 transform.rotate(180);
2417 break;
2418 case PE_IndicatorArrowLeft:
2419 transform.rotate(90);
2420 break;
2421 case PE_IndicatorArrowRight:
2422 transform.rotate(-90);
2423 break;
2424 }
2425 p->setTransform(transform);
2426
2427 path.moveTo(-halfSize, -halfSize * 0.5);
2428 path.lineTo(0.0, halfSize * 0.5);
2429 path.lineTo(halfSize, -halfSize * 0.5);
2430
2431 const QPen arrowPen(opt->palette.text(), penWidth,
2432 Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
2433 p->strokePath(path, arrowPen);
2434 p->restore();
2435 break; }
2436 case PE_FrameTabBarBase:
2437 if (const QStyleOptionTabBarBase *tbb
2438 = qstyleoption_cast<const QStyleOptionTabBarBase *>(opt)) {
2439 if (tbb->documentMode) {
2440 p->save();
2441 drawTabBase(p, tbb);
2442 p->restore();
2443 return;
2444 }
2445 QRegion region(tbb->rect);
2446 region -= tbb->tabBarRect;
2447 p->save();
2448 p->setClipRegion(region);
2449 QStyleOptionTabWidgetFrame twf;
2450 twf.QStyleOption::operator=(*tbb);
2451 twf.shape = tbb->shape;
2452 switch (QMacStylePrivate::tabDirection(twf.shape)) {
2453 case QMacStylePrivate::North:
2454 twf.rect = twf.rect.adjusted(0, 0, 0, 10);
2455 break;
2456 case QMacStylePrivate::South:
2457 twf.rect = twf.rect.adjusted(0, -10, 0, 0);
2458 break;
2459 case QMacStylePrivate::West:
2460 twf.rect = twf.rect.adjusted(0, 0, 10, 0);
2461 break;
2462 case QMacStylePrivate::East:
2463 twf.rect = twf.rect.adjusted(0, -10, 0, 0);
2464 break;
2465 }
2466 proxy()->drawPrimitive(PE_FrameTabWidget, &twf, p);
2467 p->restore();
2468 }
2469 break;
2470 case PE_PanelTipLabel:
2471 p->fillRect(opt->rect, opt->palette.brush(QPalette::ToolTipBase));
2472 break;
2473 case PE_FrameGroupBox:
2474 if (const auto *groupBox = qstyleoption_cast<const QStyleOptionFrame *>(opt))
2475 if (groupBox->features & QStyleOptionFrame::Flat) {
2476 QCommonStyle::drawPrimitive(pe, groupBox, p);
2477 break;
2478 }
2479 Q_FALLTHROUGH();
2480 case PE_FrameTabWidget:
2481 {
2482 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Box, QStyleHelper::SizeLarge);
2483 auto *box = static_cast<NSBox *>(d->cocoaControl(cw));
2484 // FIXME Since macOS 10.14, simply calling drawRect: won't display anything anymore.
2485 // The AppKit team is aware of this and has proposed a couple of solutions.
2486 // The first solution was to call displayRectIgnoringOpacity:inContext: instead.
2487 // However, it doesn't seem to work on 10.13. More importantly, dark mode on 10.14
2488 // is extremely slow. Light mode works fine.
2489 // The second solution is to subclass NSBox and reimplement a trivial drawRect: which
2490 // would only call super. This works without any issue on 10.13, but a double border
2491 // shows on 10.14 in both light and dark modes.
2492 // The code below picks what works on each version and mode. On 10.13 and earlier, we
2493 // simply call drawRect: on a regular NSBox. On 10.14, we call displayRectIgnoringOpacity:
2494 // inContext:, but only in light mode. In dark mode, we use a custom NSBox subclass,
2495 // QDarkNSBox, of type NSBoxCustom. Its appearance is close enough to the real thing so
2496 // we can use this for now.
2497 auto adjustedRect = opt->rect;
2498 bool needTranslation = false;
2499 if (!isDarkMode()) {
2500 // In Aqua theme we have to use the 'default' NSBox (as opposite
2501 // to the 'custom' QDarkNSBox we use in dark theme). Since -drawRect:
2502 // does nothing in default NSBox, we call -displayRectIgnoringOpaticty:.
2503 // Unfortunately, the resulting box is smaller then the actual rect we
2504 // wanted. This can be seen, e.g. because tabs (buttons) are misaligned
2505 // vertically and even worse, if QTabWidget has autoFillBackground
2506 // set, this background overpaints NSBox making it to disappear.
2507 // We trick our NSBox to render in a larger rectangle, so that
2508 // the actuall result (which is again smaller than requested),
2509 // more or less is what we really want. We'll have to adjust CTM
2510 // and translate accordingly.
2511 adjustedRect.adjust(0, 0, 6, 6);
2512 needTranslation = true;
2513 }
2514 d->drawNSViewInRect(box, adjustedRect, p, ^(CGContextRef ctx, const CGRect &rect) {
2515//#if QT_CONFIG(tabwidget)
2516// if (QTabWidget *tabWidget = qobject_cast<QTabWidget *>(opt->styleObject))
2517// clipTabBarFrame(opt, this, ctx);
2518//#endif
2519 QMacAutoReleasePool pool;
2520 CGContextTranslateCTM(ctx, 0, rect.origin.y + rect.size.height);
2521 CGContextScaleCTM(ctx, 1, -1);
2522 if ([box isMemberOfClass:QDarkNSBox.class]) {
2523 [box drawRect:rect];
2524 } else {
2525 if (needTranslation)
2526 CGContextTranslateCTM(ctx, -3.0, 5.0);
2527 [box displayRectIgnoringOpacity:box.bounds inContext:NSGraphicsContext.currentContext];
2528 }
2529 });
2530 break;
2531 }
2532 case PE_IndicatorToolBarSeparator: {
2533 QPainterPath path;
2534 if (opt->state & State_Horizontal) {
2535 int xpoint = opt->rect.center().x();
2536 path.moveTo(xpoint + 0.5, opt->rect.top() + 1);
2537 path.lineTo(xpoint + 0.5, opt->rect.bottom());
2538 } else {
2539 int ypoint = opt->rect.center().y();
2540 path.moveTo(opt->rect.left() + 2 , ypoint + 0.5);
2541 path.lineTo(opt->rect.right() + 1, ypoint + 0.5);
2542 }
2543 QPainterPathStroker theStroker;
2544 theStroker.setCapStyle(Qt::FlatCap);
2545 theStroker.setDashPattern(QList<qreal>() << 1 << 2);
2546 path = theStroker.createStroke(path);
2547 const auto dark = isDarkMode() ? opt->palette.dark().color().darker()
2548 : QColor(0, 0, 0, 119);
2549 p->fillPath(path, dark);
2550 }
2551 break;
2552 case PE_FrameWindow:
2553// if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
2554// if (w && w->inherits("QMdiSubWindow")) {
2555// p->save();
2556// p->setPen(QPen(frame->palette.dark().color(), frame->lineWidth));
2557// p->setBrush(frame->palette.window());
2558// p->drawRect(frame->rect);
2559// p->restore();
2560// }
2561// }
2562 break;
2563 case PE_IndicatorDockWidgetResizeHandle: {
2564 // The docwidget resize handle is drawn as a one-pixel wide line.
2565 p->save();
2566 if (opt->state & State_Horizontal) {
2567 p->setPen(QColor(160, 160, 160));
2568 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
2569 } else {
2570 p->setPen(QColor(145, 145, 145));
2571 p->drawLine(opt->rect.topRight(), opt->rect.bottomRight());
2572 }
2573 p->restore();
2574 } break;
2575 case PE_IndicatorToolBarHandle: {
2576 p->save();
2577 QPainterPath path;
2578 int x = opt->rect.x() + 6;
2579 int y = opt->rect.y() + 7;
2580 static const int RectHeight = 2;
2581 if (opt->state & State_Horizontal) {
2582 while (y < opt->rect.height() - RectHeight - 5) {
2583 path.moveTo(x, y);
2584 path.addEllipse(x, y, RectHeight, RectHeight);
2585 y += 6;
2586 }
2587 } else {
2588 while (x < opt->rect.width() - RectHeight - 5) {
2589 path.moveTo(x, y);
2590 path.addEllipse(x, y, RectHeight, RectHeight);
2591 x += 6;
2592 }
2593 }
2594 p->setPen(Qt::NoPen);
2595 QColor dark = opt->palette.dark().color().darker();
2596 dark.setAlphaF(0.50);
2597 p->fillPath(path, dark);
2598 p->restore();
2599
2600 break;
2601 }
2602 case PE_IndicatorHeaderArrow:
2603 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
2604 // In HITheme, up is down, down is up and hamburgers eat people.
2605 if (header->sortIndicator != QStyleOptionHeader::None)
2606 proxy()->drawPrimitive(
2607 (header->sortIndicator == QStyleOptionHeader::SortDown) ?
2608 PE_IndicatorArrowUp : PE_IndicatorArrowDown, header, p);
2609 }
2610 break;
2611 case PE_IndicatorMenuCheckMark: {
2612 QColor pc;
2613 if (opt->state & State_On)
2614 pc = opt->palette.highlightedText().color();
2615 else
2616 pc = opt->palette.text().color();
2617
2618 QCFType<CGColorRef> checkmarkColor = CGColorCreateGenericRGB(static_cast<CGFloat>(pc.redF()),
2619 static_cast<CGFloat>(pc.greenF()),
2620 static_cast<CGFloat>(pc.blueF()),
2621 static_cast<CGFloat>(pc.alphaF()));
2622 // kCTFontUIFontSystem and others give the same result
2623 // as kCTFontUIFontMenuItemMark. However, the latter is
2624 // more reminiscent to HITheme's kThemeMenuItemMarkFont.
2625 // See also the font for small- and mini-sized widgets,
2626 // where we end up using the generic system font type.
2627 const CTFontUIFontType fontType = (opt->state & State_Mini) ? kCTFontUIFontMiniSystem :
2628 (opt->state & State_Small) ? kCTFontUIFontSmallSystem :
2629 kCTFontUIFontMenuItemMark;
2630 // Similarly for the font size, where there is a small difference
2631 // between regular combobox and item view items, and and menu items.
2632 // However, we ignore any difference for small- and mini-sized widgets.
2633 const CGFloat fontSize = fontType == kCTFontUIFontMenuItemMark ? opt->fontMetrics.height() : 0.0;
2634 QCFType<CTFontRef> checkmarkFont = CTFontCreateUIFontForLanguage(fontType, fontSize, NULL);
2635
2636 CGContextSaveGState(cg);
2637 CGContextSetShouldSmoothFonts(cg, NO); // Same as HITheme and Cocoa menu checkmarks
2638
2639 // Baseline alignment tweaks for QComboBox and QMenu
2640 const CGFloat vOffset = (opt->state & State_Mini) ? 0.0 :
2641 (opt->state & State_Small) ? 1.0 :
2642 0.75;
2643
2644 CGContextTranslateCTM(cg, 0, opt->rect.bottom());
2645 CGContextScaleCTM(cg, 1, -1);
2646 // Translate back to the original position and add rect origin and offset
2647 CGContextTranslateCTM(cg, opt->rect.x(), vOffset);
2648
2649 // CTFont has severe difficulties finding the checkmark character among its
2650 // glyphs. Fortunately, CTLine knows its ways inside the Cocoa labyrinth.
2651 static const CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName };
2652 static const int numValues = sizeof(keys) / sizeof(keys[0]);
2653 const CFTypeRef values[] = { (CFTypeRef)checkmarkFont, (CFTypeRef)checkmarkColor };
2654 Q_STATIC_ASSERT((sizeof(values) / sizeof(values[0])) == numValues);
2655 QCFType<CFDictionaryRef> attributes = CFDictionaryCreate(kCFAllocatorDefault, (const void **)keys, (const void **)values,
2656 numValues, NULL, NULL);
2657 // U+2713: CHECK MARK
2658 QCFType<CFAttributedStringRef> checkmarkString = CFAttributedStringCreate(kCFAllocatorDefault, (CFStringRef)@"\u2713", attributes);
2659 QCFType<CTLineRef> line = CTLineCreateWithAttributedString(checkmarkString);
2660
2661 CTLineDraw((CTLineRef)line, cg);
2662 CGContextFlush(cg); // CTLineDraw's documentation says it doesn't flush
2663
2664 CGContextRestoreGState(cg);
2665 break; }
2666 case PE_IndicatorItemViewItemCheck:
2667 case PE_IndicatorRadioButton:
2668 case PE_IndicatorCheckBox: {
2669 const bool isEnabled = opt->state & State_Enabled;
2670 const bool isPressed = opt->state & State_Sunken;
2671 const bool isRadioButton = (pe == PE_IndicatorRadioButton);
2673 const auto cs = d->effectiveAquaSizeConstrain(opt);
2674 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
2675 auto *tb = static_cast<NSButton *>(d->cocoaControl(cw));
2676 tb.enabled = isEnabled;
2677 tb.state = (opt->state & State_NoChange) ? NSControlStateValueMixed :
2678 (opt->state & State_On) ? NSControlStateValueOn : NSControlStateValueOff;
2679 [tb highlight:isPressed];
2680 const auto vOffset = [=] {
2681 // As measured
2682 if (cs == QStyleHelper::SizeMini)
2683 return ct == QMacStylePrivate::Button_CheckBox ? -0.5 : 0.5;
2684
2685 return cs == QStyleHelper::SizeSmall ? 0.5 : 0.0;
2686 } ();
2687 d->drawNSViewInRect(tb, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) {
2688 QMacAutoReleasePool pool;
2689 CGContextTranslateCTM(ctx, 0, vOffset);
2690 [tb.cell drawInteriorWithFrame:rect inView:tb];
2691 });
2692 break; }
2693 case PE_FrameFocusRect:
2694 // Use the our own focus widget stuff.
2695 break;
2696 case PE_IndicatorBranch: {
2697 if (!(opt->state & State_Children))
2698 break;
2699 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Button_Disclosure, QStyleHelper::SizeLarge);
2700 NSButtonCell *triangleCell = static_cast<NSButtonCell *>(d->cocoaCell(cw));
2701 [triangleCell setState:(opt->state & State_Open) ? NSControlStateValueOn : NSControlStateValueOff];
2702// bool viewHasFocus = (w && w->hasFocus()) || (opt->state & State_HasFocus);
2703 bool viewHasFocus = false;
2704 [triangleCell setBackgroundStyle:((opt->state & State_Selected) && viewHasFocus) ? NSBackgroundStyleEmphasized : NSBackgroundStyleNormal];
2705
2706 d->setupNSGraphicsContext(cg, NO);
2707
2708 QRect qtRect = opt->rect.adjusted(DisclosureOffset, 0, -DisclosureOffset, 0);
2709 CGRect rect = CGRectMake(qtRect.x() + 1, qtRect.y(), qtRect.width(), qtRect.height());
2710 CGContextTranslateCTM(cg, rect.origin.x, rect.origin.y + rect.size.height);
2711 CGContextScaleCTM(cg, 1, -1);
2712 CGContextTranslateCTM(cg, -rect.origin.x, -rect.origin.y);
2713
2714 [triangleCell drawBezelWithFrame:NSRectFromCGRect(rect) inView:[triangleCell controlView]];
2715
2716 d->restoreNSGraphicsContext(cg);
2717 break; }
2718
2719 case PE_Frame: {
2720 const QPen oldPen = p->pen();
2721 QPen penCpy = p->pen();
2722 penCpy.setWidth(2);
2723 penCpy.setColor(opt->palette.dark().color());
2724 p->setPen(penCpy);
2725 p->drawRect(opt->rect);
2726 p->setPen(oldPen);
2727 break; }
2728 case PE_PanelLineEdit:
2729 case PE_FrameLineEdit:
2730 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
2731 if (frame->state & State_Sunken) {
2732 const bool isEnabled = opt->state & State_Enabled;
2733 const bool isReadOnly = opt->state & State_ReadOnly;
2734 const bool isRounded = frame->features & QStyleOptionFrame::Rounded;
2735 const auto cs = d->effectiveAquaSizeConstrain(opt, CT_LineEdit);
2737 auto *tf = static_cast<NSTextField *>(d->cocoaControl(cw));
2738 tf.enabled = isEnabled;
2739 tf.editable = !isReadOnly;
2740 tf.bezeled = YES;
2741 static_cast<NSTextFieldCell *>(tf.cell).bezelStyle = isRounded ? NSTextFieldRoundedBezel : NSTextFieldSquareBezel;
2742 tf.frame = opt->rect.toCGRect();
2743 d->drawNSViewInRect(tf, opt->rect, p, ^(CGContextRef, const CGRect &rect) {
2744 QMacAutoReleasePool pool;
2745 if (!isDarkMode()) {
2746 // In 'Dark' mode controls are transparent, so we do not
2747 // over-paint the (potentially custom) color in the background.
2748 // In 'Light' mode we have to care about the correct
2749 // background color. See the comments below for PE_PanelLineEdit.
2750 CGContextRef cgContext = NSGraphicsContext.currentContext.CGContext;
2751 // See QMacCGContext, here we expect bitmap context created with
2752 // color space 'kCGColorSpaceSRGB', if it's something else - we
2753 // give up.
2754 if (cgContext ? bool(CGBitmapContextGetColorSpace(cgContext)) : false) {
2755 tf.drawsBackground = YES;
2756 const QColor bgColor = frame->palette.brush(QPalette::Base).color();
2757 tf.backgroundColor = [NSColor colorWithSRGBRed:bgColor.redF()
2758 green:bgColor.greenF()
2759 blue:bgColor.blueF()
2760 alpha:bgColor.alphaF()];
2761 if (bgColor.alpha() != 255) {
2762 // No way we can have it bezeled and transparent ...
2763 tf.bordered = YES;
2764 }
2765 }
2766 }
2767
2768 CGRect fixedRect = rect;
2769 if (qt_apple_runningWithLiquidGlass()) {
2770 // The text edit cell is drawn with a little offset to the left and
2771 // the size increase compared to the 'rect' we want it to be drawn in. As a
2772 // result, the cell's 'outline' is clipped away. Adjusting the rectangle
2773 // for this, so that it's inside the clip rect, as it was before Tahoe.
2774 fixedRect = CGRectInset(rect, 1., 1.);
2775 }
2776 [tf.cell drawWithFrame:fixedRect inView:tf];
2777 });
2778 } else {
2779 QCommonStyle::drawPrimitive(pe, opt, p);
2780 }
2781 }
2782 break;
2783 case PE_PanelScrollAreaCorner: {
2784 const QBrush brush(opt->palette.brush(QPalette::Base));
2785 p->fillRect(opt->rect, brush);
2786 p->setPen(QPen(QColor(217, 217, 217)));
2787 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
2788 p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
2789 } break;
2790 case PE_FrameStatusBarItem:
2791 break;
2792//#if QT_CONFIG(tabbar)
2793// case PE_IndicatorTabClose: {
2794// // Make close button visible only on the hovered tab.
2795// QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget());
2796// const QWidget *closeBtn = w;
2797// if (!tabBar) {
2798// // QStyleSheetStyle instead of CloseButton (which has
2799// // a QTabBar as a parent widget) uses the QTabBar itself:
2800// tabBar = qobject_cast<QTabBar *>(const_cast<QWidget*>(w));
2801// closeBtn = decltype(closeBtn)(property("_q_styleSheetRealCloseButton").value<void *>());
2802// }
2803// if (tabBar) {
2804// const bool documentMode = tabBar->documentMode();
2805// const QTabBarPrivate *tabBarPrivate = static_cast<QTabBarPrivate *>(QObjectPrivate::get(tabBar));
2806// const int hoveredTabIndex = tabBarPrivate->hoveredTabIndex();
2807// if (!documentMode ||
2808// (hoveredTabIndex != -1 && ((closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) ||
2809// (closeBtn == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide))))) {
2810// const bool hover = (opt->state & State_MouseOver);
2811// const bool selected = (opt->state & State_Selected);
2812// const bool pressed = (opt->state & State_Sunken);
2813// drawTabCloseButton(p, hover, selected, pressed, documentMode);
2814// }
2815// }
2816// } break;
2817//#endif // QT_CONFIG(tabbar)
2818 case PE_PanelStatusBar: {
2819 p->fillRect(opt->rect, opt->palette.window());
2820
2821 // Draw the black separator line at the top of the status bar.
2822 if (qt_macWindowMainWindow(opt->window))
2823 p->setPen(titlebarSeparatorLineActive);
2824 else
2825 p->setPen(titlebarSeparatorLineInactive);
2826 p->drawLine(opt->rect.left(), opt->rect.top(), opt->rect.right(), opt->rect.top());
2827
2828 break;
2829 }
2830 case PE_PanelMenu: {
2831 p->save();
2832 p->fillRect(opt->rect, Qt::transparent);
2833 p->setPen(Qt::transparent);
2834 p->setBrush(opt->palette.window());
2835 p->setRenderHint(QPainter::Antialiasing, true);
2836 const QPainterPath path = d->windowPanelPath(opt->rect);
2837 p->drawPath(path);
2838 p->restore();
2839 } break;
2840
2841 default:
2842 QCommonStyle::drawPrimitive(pe, opt, p);
2843 break;
2844 }
2845}
2846
2847static QPixmap darkenPixmap(const QPixmap &pixmap)
2848{
2849 QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
2850 int imgh = img.height();
2851 int imgw = img.width();
2852 int h, s, v, a;
2853 QRgb pixel;
2854 for (int y = 0; y < imgh; ++y) {
2855 for (int x = 0; x < imgw; ++x) {
2856 pixel = img.pixel(x, y);
2857 a = qAlpha(pixel);
2858 QColor hsvColor(pixel);
2859 hsvColor.getHsv(&h, &s, &v);
2860 s = qMin(100, s * 2);
2861 v = v / 2;
2862 hsvColor.setHsv(h, s, v);
2863 pixel = hsvColor.rgb();
2864 img.setPixel(x, y, qRgba(qRed(pixel), qGreen(pixel), qBlue(pixel), a));
2865 }
2866 }
2867 return QPixmap::fromImage(img);
2868}
2869
2870void QMacStylePrivate::setupVerticalInvertedXform(CGContextRef cg, bool reverse, bool vertical, const CGRect &rect) const
2871{
2872 if (vertical) {
2873 CGContextTranslateCTM(cg, rect.size.height, 0);
2874 CGContextRotateCTM(cg, M_PI_2);
2875 }
2876 if (vertical != reverse) {
2877 CGContextTranslateCTM(cg, rect.size.width, 0);
2878 CGContextScaleCTM(cg, -1, 1);
2879 }
2880}
2881
2882void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p) const
2883{
2884 Q_D(const QMacStyle);
2885
2886 const QMacAutoReleasePool pool;
2887
2888 QMacCGContext cg(p);
2889 d->resolveCurrentNSView(opt->window);
2890
2891 switch (ce) {
2892 case CE_HeaderSection:
2893 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
2894 State flags = header->state;
2895 QRect ir = header->rect;
2896 const bool pressed = (flags & State_Sunken) && !(flags & State_On);
2897 p->fillRect(ir, pressed ? header->palette.dark() : header->palette.button());
2898 p->setPen(QPen(header->palette.dark(), 1.0));
2899 if (header->orientation == Qt::Horizontal)
2900 p->drawLine(QLineF(ir.right() + 0.5, ir.top() + headerSectionSeparatorInset,
2901 ir.right() + 0.5, ir.bottom() - headerSectionSeparatorInset));
2902 else
2903 p->drawLine(QLineF(ir.left() + headerSectionSeparatorInset, ir.bottom(),
2904 ir.right() - headerSectionSeparatorInset, ir.bottom()));
2905 }
2906
2907 break;
2908 case CE_HeaderLabel:
2909 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
2910 p->save();
2911 QRect textr = header->rect;
2912 if (!header->icon.isNull()) {
2913 QIcon::Mode mode = QIcon::Disabled;
2914 if (opt->state & State_Enabled)
2915 mode = QIcon::Normal;
2916 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
2917 QPixmap pixmap = header->icon.pixmap(QSize(iconExtent, iconExtent),
2918 opt->window->devicePixelRatio(), mode);
2919
2920 QRect pixr = header->rect;
2921 pixr.setY(header->rect.center().y() - (pixmap.height() / pixmap.devicePixelRatio() - 1) / 2);
2922 proxy()->drawItemPixmap(p, pixr, Qt::AlignVCenter, pixmap);
2923 textr.translate(pixmap.width() / pixmap.devicePixelRatio() + 2, 0);
2924 }
2925
2926 proxy()->drawItemText(p, textr, header->textAlignment | Qt::AlignVCenter, header->palette,
2927 header->state & State_Enabled, header->text, QPalette::ButtonText);
2928 p->restore();
2929 }
2930 break;
2931 case CE_ToolButtonLabel:
2932 if (const QStyleOptionToolButton *tb = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
2933 QStyleOptionToolButton myTb = *tb;
2934 myTb.state &= ~State_AutoRaise;
2935#ifndef QT_NO_ACCESSIBILITY
2936 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) {
2937 QRect cr = tb->rect;
2938 int shiftX = 0;
2939 int shiftY = 0;
2940 bool needText = false;
2941 int alignment = 0;
2942 bool down = tb->state & (State_Sunken | State_On);
2943 if (down) {
2944 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb);
2945 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, tb);
2946 }
2947 // The down state is special for QToolButtons in a toolbar on the Mac
2948 // The text is a bit bolder and gets a drop shadow and the icons are also darkened.
2949 // This doesn't really fit into any particular case in QIcon, so we
2950 // do the majority of the work ourselves.
2951 if (!(tb->features & QStyleOptionToolButton::Arrow)) {
2952 Qt::ToolButtonStyle tbstyle = tb->toolButtonStyle;
2953 if (tb->icon.isNull() && !tb->text.isEmpty())
2954 tbstyle = Qt::ToolButtonTextOnly;
2955
2956 switch (tbstyle) {
2957 case Qt::ToolButtonTextOnly: {
2958 needText = true;
2959 alignment = Qt::AlignCenter;
2960 break; }
2961 case Qt::ToolButtonIconOnly:
2962 case Qt::ToolButtonTextBesideIcon:
2963 case Qt::ToolButtonTextUnderIcon: {
2964 QRect pr = cr;
2965 QIcon::Mode iconMode = (tb->state & State_Enabled) ? QIcon::Normal
2966 : QIcon::Disabled;
2967 QIcon::State iconState = (tb->state & State_On) ? QIcon::On
2968 : QIcon::Off;
2969 QPixmap pixmap = tb->icon.pixmap(tb->rect.size().boundedTo(tb->iconSize),
2970 opt->window->devicePixelRatio(), iconMode,
2971 iconState);
2972
2973 // Draw the text if it's needed.
2974 if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) {
2975 needText = true;
2976 if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
2977 pr.setHeight(pixmap.size().height() / pixmap.devicePixelRatio() + 6);
2978 cr.adjust(0, pr.bottom(), 0, -3);
2979 alignment |= Qt::AlignCenter;
2980 } else {
2981 pr.setWidth(pixmap.width() / pixmap.devicePixelRatio() + 8);
2982 cr.adjust(pr.right(), 0, 0, 0);
2983 alignment |= Qt::AlignLeft | Qt::AlignVCenter;
2984 }
2985 }
2986 if (opt->state & State_Sunken) {
2987 pr.translate(shiftX, shiftY);
2988 pixmap = darkenPixmap(pixmap);
2989 }
2990 proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pixmap);
2991 break; }
2992 default:
2993 Q_ASSERT(false);
2994 break;
2995 }
2996
2997 if (needText) {
2998 QPalette pal = tb->palette;
2999 QPalette::ColorRole role = QPalette::NoRole;
3000 if (!proxy()->styleHint(SH_UnderlineShortcut, tb))
3001 alignment |= Qt::TextHideMnemonic;
3002 if (down)
3003 cr.translate(shiftX, shiftY);
3004 if (tbstyle == Qt::ToolButtonTextOnly
3005 || (tbstyle != Qt::ToolButtonTextOnly && !down)) {
3006 QPen pen = p->pen();
3007 QColor light = down || isDarkMode() ? Qt::black : Qt::white;
3008 light.setAlphaF(0.375f);
3009 p->setPen(light);
3010 p->drawText(cr.adjusted(0, 1, 0, 1), alignment, tb->text);
3011 p->setPen(pen);
3012 if (down && tbstyle == Qt::ToolButtonTextOnly) {
3013// pal = QApplication::palette("QMenu");
3014 pal.setCurrentColorGroup(tb->palette.currentColorGroup());
3015 role = QPalette::HighlightedText;
3016 }
3017 }
3018 proxy()->drawItemText(p, cr, alignment, pal,
3019 tb->state & State_Enabled, tb->text, role);
3020 }
3021 } else {
3022 QCommonStyle::drawControl(ce, &myTb, p);
3023 }
3024 } else
3025#endif // QT_NO_ACCESSIBILITY
3026 {
3027 QCommonStyle::drawControl(ce, &myTb, p);
3028 }
3029 }
3030 break;
3031 case CE_ToolBoxTabShape:
3032 QCommonStyle::drawControl(ce, opt, p);
3033 break;
3034 case CE_PushButtonBevel:
3035 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
3036 if (!(btn->state & (State_Raised | State_Sunken | State_On)))
3037 break;
3038
3039 if (btn->features & QStyleOptionButton::CommandLinkButton) {
3040 QCommonStyle::drawControl(ce, opt, p);
3041 break;
3042 }
3043
3044 const bool hasFocus = btn->state & State_HasFocus;
3045 const bool isActive = btn->state & State_Active;
3046
3047 // a focused auto-default button within an active window
3048 // takes precedence over a normal default button
3049 if ((btn->features & QStyleOptionButton::AutoDefaultButton)
3050 && isActive && hasFocus)
3051 d->autoDefaultButton = btn->styleObject;
3052 else if (d->autoDefaultButton == btn->styleObject)
3053 d->autoDefaultButton = nullptr;
3054
3055 const bool isEnabled = btn->state & State_Enabled;
3056 const bool isPressed = btn->state & State_Sunken;
3057 const bool isHighlighted = isActive &&
3058 ((btn->state & State_On)
3059 || (btn->features & QStyleOptionButton::DefaultButton)
3060 || (btn->features & QStyleOptionButton::AutoDefaultButton
3061 && d->autoDefaultButton == btn->styleObject));
3062 const bool hasMenu = btn->features & QStyleOptionButton::HasMenu;
3063 const auto ct = cocoaControlType(btn);
3064 const auto cs = d->effectiveAquaSizeConstrain(btn);
3065 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
3066 auto *pb = static_cast<NSButton *>(d->cocoaControl(cw));
3067 // Ensure same size and location as we used to have with HITheme.
3068 // This is more convoluted than we initialy thought. See for example
3069 // differences between plain and menu button frames.
3070 const QRectF frameRect = cw.adjustedControlFrame(btn->rect);
3071 pb.frame = frameRect.toCGRect();
3072
3073 pb.enabled = isEnabled;
3074 [pb highlight:isPressed];
3075 pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff;
3076 d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef, const CGRect &r) {
3077 QMacAutoReleasePool pool;
3078 [pb.cell drawBezelWithFrame:r inView:pb.superview];
3079 });
3080 [pb highlight:NO];
3081
3082 if (hasMenu && cw.type == QMacStylePrivate::Button_SquareButton) {
3083 // Using -[NSPopuButtonCell drawWithFrame:inView:] above won't do
3084 // it right because we don't set the text in the native button.
3085 const int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn);
3086 const auto ir = frameRect.toRect();
3087 int arrowYOffset = 0;
3088 const auto ar = visualRect(btn->direction, ir, QRect(ir.right() - mbi - 6, ir.height() / 2 - arrowYOffset, mbi, mbi));
3089
3090 QStyleOption arrowOpt = *opt;
3091 arrowOpt.rect = ar;
3092 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p);
3093 }
3094 }
3095 break;
3096 case CE_PushButtonLabel:
3097 if (const QStyleOptionButton *b = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
3098 QStyleOptionButton btn(*b);
3099 // We really don't want the label to be drawn the same as on
3100 // windows style if it has an icon and text, then it should be more like a
3101 // tab. So, cheat a little here. However, if it *is* only an icon
3102 // the windows style works great, so just use that implementation.
3103 const bool isEnabled = btn.state & State_Enabled;
3104 const bool hasMenu = btn.features & QStyleOptionButton::HasMenu;
3105 const bool hasIcon = !btn.icon.isNull();
3106 const bool hasText = !btn.text.isEmpty();
3107 const bool isActive = btn.state & State_Active;
3108 const bool isPressed = btn.state & State_Sunken;
3109
3110 const auto ct = cocoaControlType(&btn);
3111
3112 if (!hasMenu && ct != QMacStylePrivate::Button_SquareButton) {
3113 if (isPressed
3114 || (isActive && isEnabled
3115 && ((btn.state & State_On)
3116 || ((btn.features & QStyleOptionButton::DefaultButton) && !d->autoDefaultButton)
3117 || d->autoDefaultButton == btn.styleObject)))
3118 btn.palette.setColor(QPalette::ButtonText, Qt::white);
3119 }
3120
3121 if ((!hasIcon && !hasMenu) || (hasIcon && !hasText)) {
3122 QCommonStyle::drawControl(ce, &btn, p);
3123 } else {
3124 QRect freeContentRect = btn.rect;
3125 QRect textRect = itemTextRect(
3126 btn.fontMetrics, freeContentRect, Qt::AlignCenter, isEnabled, btn.text);
3127 if (hasMenu) {
3128 textRect.moveTo(11, textRect.top());
3129 }
3130 // Draw the icon:
3131 if (hasIcon) {
3132 int contentW = textRect.width();
3133 if (hasMenu)
3134 contentW += proxy()->pixelMetric(PM_MenuButtonIndicator) + 4;
3135 QIcon::Mode mode = isEnabled ? QIcon::Normal : QIcon::Disabled;
3136 if (mode == QIcon::Normal && btn.state & State_HasFocus)
3137 mode = QIcon::Active;
3138 // Decide if the icon is should be on or off:
3139 QIcon::State state = QIcon::Off;
3140 if (btn.state & State_On)
3141 state = QIcon::On;
3142 QPixmap pixmap = btn.icon.pixmap(btn.iconSize, opt->window->devicePixelRatio(),
3143 mode, state);
3144 int pixmapWidth = pixmap.width() / pixmap.devicePixelRatio();
3145 int pixmapHeight = pixmap.height() / pixmap.devicePixelRatio();
3146 contentW += pixmapWidth + QMacStylePrivate::PushButtonContentPadding;
3147 int iconLeftOffset = freeContentRect.x() + (freeContentRect.width() - contentW) / 2;
3148 int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmapHeight) / 2;
3149 QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmapWidth, pixmapHeight);
3150 QRect visualIconDestRect = visualRect(btn.direction, freeContentRect, iconDestRect);
3151 proxy()->drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap);
3152 int newOffset = iconDestRect.x() + iconDestRect.width()
3154 textRect.adjust(newOffset, 0, newOffset, 0);
3155 }
3156 // Draw the text:
3157 if (hasText) {
3158 textRect = visualRect(btn.direction, freeContentRect, textRect);
3159 proxy()->drawItemText(p, textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, btn.palette,
3160 isEnabled, btn.text, QPalette::ButtonText);
3161 }
3162 }
3163 }
3164 break;
3165 case CE_ComboBoxLabel:
3166 if (const auto *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
3167 auto comboCopy = *cb;
3168 comboCopy.direction = Qt::LeftToRight;
3169 // The rectangle will be adjusted to SC_ComboBoxEditField with comboboxEditBounds()
3170 QCommonStyle::drawControl(CE_ComboBoxLabel, &comboCopy, p);
3171 }
3172 break;
3173 case CE_TabBarTabShape:
3174 if (const auto *tabOpt = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
3175 if (tabOpt->documentMode) {
3176 p->save();
3177 bool isUnified = false;
3178// if (w) {
3179// QRect tabRect = tabOpt->rect;
3180// QPoint windowTabStart = w->mapTo(w->window(), tabRect.topLeft());
3181// isUnified = isInMacUnifiedToolbarArea(w->window()->windowHandle(), windowTabStart.y());
3182// }
3183
3184 const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, opt);
3185 drawTabShape(p, tabOpt, isUnified, tabOverlap);
3186
3187 p->restore();
3188 return;
3189 }
3190
3191 const bool isActive = tabOpt->state & State_Active;
3192 const bool isEnabled = tabOpt->state & State_Enabled;
3193 const bool isPressed = tabOpt->state & State_Sunken;
3194 const bool isSelected = tabOpt->state & State_Selected;
3195 const auto tabDirection = QMacStylePrivate::tabDirection(tabOpt->shape);
3196 const bool verticalTabs = tabDirection == QMacStylePrivate::East
3197 || tabDirection == QMacStylePrivate::West;
3198
3199 QStyleOptionTab::TabPosition tp = tabOpt->position;
3200 QStyleOptionTab::SelectedPosition sp = tabOpt->selectedPosition;
3201 if (tabOpt->direction == Qt::RightToLeft && !verticalTabs) {
3202 if (tp == QStyleOptionTab::Beginning)
3203 tp = QStyleOptionTab::End;
3204 else if (tp == QStyleOptionTab::End)
3205 tp = QStyleOptionTab::Beginning;
3206
3207 if (sp == QStyleOptionTab::NextIsSelected)
3208 sp = QStyleOptionTab::PreviousIsSelected;
3209 else if (sp == QStyleOptionTab::PreviousIsSelected)
3210 sp = QStyleOptionTab::NextIsSelected;
3211 }
3212
3213 // Alas, NSSegmentedControl and NSSegmentedCell are letting us down.
3214 // We're not able to draw it at will, either calling -[drawSegment:
3215 // inFrame:withView:], -[drawRect:] or anything in between. Besides,
3216 // there's no public API do draw the pressed state, AFAICS. We'll use
3217 // a push NSButton instead and clip the CGContext.
3218 // NOTE/TODO: this is not true. On 10.13 NSSegmentedControl works with
3219 // some (black?) magic/magic dances, on 10.14 it simply works (was
3220 // it fixed in AppKit?). But, indeed, we cannot make a tab 'pressed'
3221 // with NSSegmentedControl (only selected), so we stay with buttons
3222 // (mixing buttons and NSSegmentedControl for such a simple thing
3223 // is too much work).
3224
3225 const auto cs = d->effectiveAquaSizeConstrain(opt);
3226 // Extra hacks to get the proper pressed appreance when not selected or selected and inactive
3227 const bool needsInactiveHack = (!isActive && isSelected);
3228 const auto ct = !needsInactiveHack && (isSelected || tp == QStyleOptionTab::OnlyOneTab) ?
3229 QMacStylePrivate::Button_PushButton :
3230 QMacStylePrivate::Button_PopupButton;
3231 const bool isPopupButton = ct == QMacStylePrivate::Button_PopupButton;
3232 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
3233 auto *pb = static_cast<NSButton *>(d->cocoaControl(cw));
3234
3235 auto vOffset = isPopupButton ? 1 : 2;
3236 if (tabDirection == QMacStylePrivate::East)
3237 vOffset -= 1;
3238 const auto outerAdjust = isPopupButton ? 1 : 4;
3239 const auto innerAdjust = isPopupButton ? 20 : 10;
3240 QRectF frameRect = tabOpt->rect;
3241 if (verticalTabs)
3242 frameRect = QRectF(frameRect.y(), frameRect.x(), frameRect.height(), frameRect.width());
3243 // Adjust before clipping
3244 frameRect = frameRect.translated(0, vOffset);
3245 switch (tp) {
3246 case QStyleOptionTab::Beginning:
3247 // Pressed state hack: tweak adjustments in preparation for flip below
3248 if (!isSelected && tabDirection == QMacStylePrivate::West)
3249 frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0);
3250 else
3251 frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0);
3252 break;
3253 case QStyleOptionTab::Middle:
3254 frameRect = frameRect.adjusted(-innerAdjust, 0, innerAdjust, 0);
3255 break;
3256 case QStyleOptionTab::End:
3257 // Pressed state hack: tweak adjustments in preparation for flip below
3258 if (isSelected || tabDirection == QMacStylePrivate::West)
3259 frameRect = frameRect.adjusted(-innerAdjust, 0, outerAdjust, 0);
3260 else
3261 frameRect = frameRect.adjusted(-outerAdjust, 0, innerAdjust, 0);
3262 break;
3263 case QStyleOptionTab::OnlyOneTab:
3264 frameRect = frameRect.adjusted(-outerAdjust, 0, outerAdjust, 0);
3265 break;
3266 }
3267 pb.frame = frameRect.toCGRect();
3268
3269 pb.enabled = isEnabled;
3270 [pb highlight:isPressed];
3271 // Set off state when inactive. See needsInactiveHack for when it's selected
3272 pb.state = (isActive && isSelected && !isPressed) ? NSControlStateValueOn : NSControlStateValueOff;
3273
3274 const auto drawBezelBlock = ^(CGContextRef ctx, const CGRect &r) {
3275 QMacAutoReleasePool pool;
3276 CGContextClipToRect(ctx, opt->rect.toCGRect());
3277 if (!isSelected || needsInactiveHack) {
3278 // Final stage of the pressed state hack: flip NSPopupButton rendering
3279 if (!verticalTabs && tp == QStyleOptionTab::End) {
3280 CGContextTranslateCTM(ctx, opt->rect.right(), 0);
3281 CGContextScaleCTM(ctx, -1, 1);
3282 CGContextTranslateCTM(ctx, -frameRect.left(), 0);
3283 } else if (tabDirection == QMacStylePrivate::West && tp == QStyleOptionTab::Beginning) {
3284 CGContextTranslateCTM(ctx, 0, opt->rect.top());
3285 CGContextScaleCTM(ctx, 1, -1);
3286 CGContextTranslateCTM(ctx, 0, -frameRect.right());
3287 } else if (tabDirection == QMacStylePrivate::East && tp == QStyleOptionTab::End) {
3288 CGContextTranslateCTM(ctx, 0, opt->rect.bottom());
3289 CGContextScaleCTM(ctx, 1, -1);
3290 CGContextTranslateCTM(ctx, 0, -frameRect.left());
3291 }
3292 }
3293
3294 // Rotate and translate CTM when vertical
3295 // On macOS: positive angle is CW, negative is CCW
3296 if (tabDirection == QMacStylePrivate::West) {
3297 CGContextTranslateCTM(ctx, 0, frameRect.right());
3298 CGContextRotateCTM(ctx, -M_PI_2);
3299 CGContextTranslateCTM(ctx, -frameRect.left(), 0);
3300 } else if (tabDirection == QMacStylePrivate::East) {
3301 CGContextTranslateCTM(ctx, opt->rect.right(), 0);
3302 CGContextRotateCTM(ctx, M_PI_2);
3303 }
3304
3305 // Now, if it's a trick with a popup button, it has an arrow
3306 // which makes no sense on tabs.
3307 NSPopUpArrowPosition oldPosition = NSPopUpArrowAtCenter;
3308 NSPopUpButtonCell *pbCell = nil;
3309 if (isPopupButton) {
3310 pbCell = static_cast<NSPopUpButtonCell *>(pb.cell);
3311 oldPosition = pbCell.arrowPosition;
3312 pbCell.arrowPosition = NSPopUpNoArrow;
3313 }
3314
3315 [pb.cell drawBezelWithFrame:r inView:pb.superview];
3316
3317 if (pbCell) // Restore, we may reuse it for a ComboBox.
3318 pbCell.arrowPosition = oldPosition;
3319 };
3320
3321 if (needsInactiveHack) {
3322 // First, render tab as non-selected tab on a pixamp
3323 const qreal pixelRatio = p->device()->devicePixelRatioF();
3324 QImage tabPixmap(opt->rect.size() * pixelRatio, QImage::Format_ARGB32_Premultiplied);
3325 tabPixmap.setDevicePixelRatio(pixelRatio);
3326 tabPixmap.fill(Qt::transparent);
3327 QPainter tabPainter(&tabPixmap);
3328 d->drawNSViewInRect(pb, frameRect, &tabPainter, ^(CGContextRef ctx, const CGRect &r) {
3329 QMacAutoReleasePool pool;
3330 CGContextTranslateCTM(ctx, -opt->rect.left(), -opt->rect.top());
3331 drawBezelBlock(ctx, r);
3332 });
3333 tabPainter.end();
3334
3335 // Then, darken it with the proper shade of gray
3336 const qreal inactiveGray = 0.898; // As measured
3337 const int inactiveGray8 = qRound(inactiveGray * 255.0);
3338 const QRgb inactiveGrayRGB = qRgb(inactiveGray8, inactiveGray8, inactiveGray8);
3339 for (int l = 0; l < tabPixmap.height(); ++l) {
3340 auto *line = reinterpret_cast<QRgb*>(tabPixmap.scanLine(l));
3341 for (int i = 0; i < tabPixmap.width(); ++i) {
3342 if (qAlpha(line[i]) == 255) {
3343 line[i] = inactiveGrayRGB;
3344 } else if (qAlpha(line[i]) > 128) {
3345 const int g = qRound(inactiveGray * qRed(line[i]));
3346 line[i] = qRgba(g, g, g, qAlpha(line[i]));
3347 }
3348 }
3349 }
3350
3351 // Finally, draw the tab pixmap on the current painter
3352 p->drawImage(opt->rect, tabPixmap);
3353 } else {
3354 d->drawNSViewInRect(pb, frameRect, p, drawBezelBlock);
3355 }
3356
3357 if (!isSelected && sp != QStyleOptionTab::NextIsSelected
3358 && tp != QStyleOptionTab::End
3359 && tp != QStyleOptionTab::OnlyOneTab) {
3360 static const QPen separatorPen(Qt::black, 1.0);
3361 p->save();
3362 p->setOpacity(isEnabled ? 0.105 : 0.06); // As measured
3363 p->setPen(separatorPen);
3364 if (tabDirection == QMacStylePrivate::West) {
3365 p->drawLine(QLineF(opt->rect.left() + 1.5, opt->rect.bottom(),
3366 opt->rect.right() - 0.5, opt->rect.bottom()));
3367 } else if (tabDirection == QMacStylePrivate::East) {
3368 p->drawLine(QLineF(opt->rect.left(), opt->rect.bottom(),
3369 opt->rect.right() - 0.5, opt->rect.bottom()));
3370 } else {
3371 p->drawLine(QLineF(opt->rect.right(), opt->rect.top() + 1.0,
3372 opt->rect.right(), opt->rect.bottom() - 0.5));
3373 }
3374 p->restore();
3375 }
3376 }
3377 break;
3378 case CE_TabBarTabLabel:
3379 if (const auto *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
3380 QStyleOptionTab myTab = *tab;
3381 const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape);
3382 const bool verticalTabs = tabDirection == QMacStylePrivate::East
3383 || tabDirection == QMacStylePrivate::West;
3384
3385 // Check to see if we use have the same as the system font
3386 // (QComboMenuItem is internal and should never be seen by the
3387 // outside world, unless they read the source, in which case, it's
3388 // their own fault).
3389// const bool nonDefaultFont = p->font() != qt_app_fonts_hash()->value("QComboMenuItem");
3390 const bool nonDefaultFont = false;
3391
3392// if (!myTab.documentMode && (myTab.state & State_Selected) && (myTab.state & State_Active))
3393// if (const auto *tabBar = qobject_cast<const QTabBar *>(w))
3394// if (!tabBar->tabTextColor(tabBar->currentIndex()).isValid())
3395// myTab.palette.setColor(QPalette::WindowText, Qt::white);
3396
3397 if (myTab.documentMode && isDarkMode()) {
3398 bool active = (myTab.state & State_Selected) && (myTab.state & State_Active);
3399 myTab.palette.setColor(QPalette::WindowText, active ? Qt::white : Qt::gray);
3400 }
3401
3402 int heightOffset = 0;
3403 if (verticalTabs) {
3404 heightOffset = -1;
3405 } else if (nonDefaultFont) {
3406 if (p->fontMetrics().height() == myTab.rect.height())
3407 heightOffset = 2;
3408 }
3409 myTab.rect.setHeight(myTab.rect.height() + heightOffset);
3410
3411 QCommonStyle::drawControl(ce, &myTab, p);
3412 }
3413 break;
3414 case CE_DockWidgetTitle:
3415 if (const auto *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
3416 const bool isVertical = dwOpt->verticalTitleBar;
3417 const auto effectiveRect = isVertical ? opt->rect.transposed() : opt->rect;
3418 p->save();
3419 if (isVertical) {
3420 p->translate(effectiveRect.left(), effectiveRect.top() + effectiveRect.width());
3421 p->rotate(-90);
3422 p->translate(-effectiveRect.left(), -effectiveRect.top());
3423 }
3424
3425 // fill title bar background
3426 p->fillRect(effectiveRect, opt->palette.window());
3427
3428 // draw horizontal line at bottom
3429 p->setPen(opt->palette.dark().color());
3430 p->drawLine(effectiveRect.bottomLeft(), effectiveRect.bottomRight());
3431
3432 if (!dwOpt->title.isEmpty()) {
3433 auto titleRect = proxy()->subElementRect(SE_DockWidgetTitleBarText, opt);
3434 if (isVertical)
3435 titleRect = QRect(effectiveRect.left() + opt->rect.bottom() - titleRect.bottom(),
3436 effectiveRect.top() + titleRect.left() - opt->rect.left(),
3437 titleRect.height(),
3438 titleRect.width());
3439
3440 const auto text = p->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, titleRect.width());
3441 proxy()->drawItemText(p, titleRect, Qt::AlignCenter, dwOpt->palette,
3442 dwOpt->state & State_Enabled, text, QPalette::WindowText);
3443 }
3444 p->restore();
3445 }
3446 break;
3447 case CE_FocusFrame: {
3448// const auto *ff = qobject_cast<const QFocusFrame *>(w);
3449// const auto *ffw = ff ? ff->widget() : nullptr;
3450// const auto ct = [=] {
3451// if (ffw) {
3452// if (ffw->inherits("QCheckBox"))
3453// return QMacStylePrivate::Button_CheckBox;
3454// if (ffw->inherits("QRadioButton"))
3455// return QMacStylePrivate::Button_RadioButton;
3456// if (ffw->inherits("QLineEdit") || ffw->inherits("QTextEdit"))
3457// return QMacStylePrivate::TextField;
3458// }
3459//
3460// return QMacStylePrivate::Box; // Not really, just make it the default
3461// } ();
3462// const auto cs = ffw ? (ffw->testAttribute(Qt::WA_MacMiniSize) ? QStyleHelper::SizeMini :
3463// ffw->testAttribute(Qt::WA_MacSmallSize) ? QStyleHelper::SizeSmall :
3464// QStyleHelper::SizeLarge) :
3465// QStyleHelper::SizeLarge;
3466// const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, opt);
3467// const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, opt);
3468// d->drawFocusRing(p, opt->rect, hMargin, vMargin, QMacStylePrivate::CocoaControl(ct, cs));
3469 break; }
3470 case CE_MenuEmptyArea:
3471 // Skip: PE_PanelMenu fills in everything
3472 break;
3473 case CE_MenuItem:
3474 case CE_MenuHMargin:
3475 case CE_MenuVMargin:
3476 case CE_MenuTearoff:
3477 case CE_MenuScroller:
3478 if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
3479 const bool active = mi->state & State_Selected;
3480 if (active)
3481 p->fillRect(mi->rect, mi->palette.highlight());
3482
3483 const QStyleHelper::WidgetSizePolicy widgetSize = d->aquaSizeConstrain(opt);
3484
3485 if (ce == CE_MenuTearoff) {
3486 p->setPen(QPen(mi->palette.dark().color(), 1, Qt::DashLine));
3487 p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2 - 1,
3488 mi->rect.x() + mi->rect.width() - 4,
3489 mi->rect.y() + mi->rect.height() / 2 - 1);
3490 p->setPen(QPen(mi->palette.light().color(), 1, Qt::DashLine));
3491 p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2,
3492 mi->rect.x() + mi->rect.width() - 4,
3493 mi->rect.y() + mi->rect.height() / 2);
3494 } else if (ce == CE_MenuScroller) {
3495 const QSize scrollerSize = QSize(10, 8);
3496 const int scrollerVOffset = 5;
3497 const int left = mi->rect.x() + (mi->rect.width() - scrollerSize.width()) / 2;
3498 const int right = left + scrollerSize.width();
3499 int top;
3500 int bottom;
3501 if (opt->state & State_DownArrow) {
3502 bottom = mi->rect.y() + scrollerVOffset;
3503 top = bottom + scrollerSize.height();
3504 } else {
3505 bottom = mi->rect.bottom() - scrollerVOffset;
3506 top = bottom - scrollerSize.height();
3507 }
3508 p->save();
3509 p->setRenderHint(QPainter::Antialiasing);
3510 QPainterPath path;
3511 path.moveTo(left, bottom);
3512 path.lineTo(right, bottom);
3513 path.lineTo((left + right) / 2, top);
3514 p->fillPath(path, opt->palette.buttonText());
3515 p->restore();
3516 } else if (ce != CE_MenuItem) {
3517 break;
3518 }
3519
3520 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
3521 CGColorRef separatorColor = [NSColor quaternaryLabelColor].CGColor;
3522 const QRect separatorRect = QRect(mi->rect.left(), mi->rect.center().y(), mi->rect.width(), 2);
3523 p->fillRect(separatorRect, qt_mac_toQColor(separatorColor));
3524 break;
3525 }
3526
3527 const int maxpmw = mi->maxIconWidth;
3528 const bool enabled = mi->state & State_Enabled;
3529
3530 int xpos = mi->rect.x() + 18;
3531 int checkcol = maxpmw;
3532 if (!enabled)
3533 p->setPen(mi->palette.text().color());
3534 else if (active)
3535 p->setPen(mi->palette.highlightedText().color());
3536 else
3537 p->setPen(mi->palette.buttonText().color());
3538
3539 if (mi->checked) {
3540 QStyleOption checkmarkOpt;
3541// checkmarkOpt.initFrom(w);
3542
3543 const int mw = checkcol + macItemFrame;
3544 const int mh = mi->rect.height() + macItemFrame;
3545 const int xp = mi->rect.x() + macItemFrame;
3546 checkmarkOpt.rect = QRect(xp, mi->rect.y() - checkmarkOpt.fontMetrics.descent(), mw, mh);
3547
3548 checkmarkOpt.state.setFlag(State_On, active);
3549 checkmarkOpt.state.setFlag(State_Enabled, enabled);
3550 if (widgetSize == QStyleHelper::SizeMini)
3551 checkmarkOpt.state |= State_Mini;
3552 else if (widgetSize == QStyleHelper::SizeSmall)
3553 checkmarkOpt.state |= State_Small;
3554
3555 // We let drawPrimitive(PE_IndicatorMenuCheckMark) pick the right color
3556 checkmarkOpt.palette.setColor(QPalette::HighlightedText, p->pen().color());
3557 checkmarkOpt.palette.setColor(QPalette::Text, p->pen().color());
3558
3559 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &checkmarkOpt, p);
3560 }
3561 if (!mi->icon.isNull()) {
3562 QIcon::Mode mode = (mi->state & State_Enabled) ? QIcon::Normal
3563 : QIcon::Disabled;
3564 // Always be normal or disabled to follow the Mac style.
3565 int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize);
3566 QSize iconSize(smallIconSize, smallIconSize);
3567//#if QT_CONFIG(combobox)
3568// if (const QComboBox *comboBox = qobject_cast<const QComboBox *>(w)) {
3569// iconSize = comboBox->iconSize();
3570// }
3571//#endif
3572 QPixmap pixmap = mi->icon.pixmap(iconSize, opt->window->devicePixelRatio(), mode);
3573 int pixw = pixmap.width() / pixmap.devicePixelRatio();
3574 int pixh = pixmap.height() / pixmap.devicePixelRatio();
3575 QRect cr(xpos, mi->rect.y(), checkcol, mi->rect.height());
3576 QRect pmr(0, 0, pixw, pixh);
3577 pmr.moveCenter(cr.center());
3578 p->drawPixmap(pmr.topLeft(), pixmap);
3579 xpos += pixw + 6;
3580 }
3581
3582 QString s = mi->text;
3583 const auto text_flags = Qt::AlignVCenter | Qt::TextHideMnemonic
3584 | Qt::TextSingleLine | Qt::AlignAbsolute;
3585 int yPos = mi->rect.y();
3586 if (widgetSize == QStyleHelper::SizeMini)
3587 yPos += 1;
3588
3589 const bool isSubMenu = mi->menuItemType == QStyleOptionMenuItem::SubMenu;
3590 const int tabwidth = isSubMenu ? 9 : mi->tabWidth;
3591
3592 QString rightMarginText;
3593 if (isSubMenu)
3594 rightMarginText = QStringLiteral("\u25b6\ufe0e"); // U+25B6 U+FE0E: BLACK RIGHT-POINTING TRIANGLE
3595
3596 // If present, save and remove embedded shorcut from text
3597 const int tabIndex = s.indexOf(QLatin1Char('\t'));
3598 if (tabIndex >= 0) {
3599 if (!isSubMenu) // ... but ignore it if it's a submenu.
3600 rightMarginText = s.mid(tabIndex + 1);
3601 s = s.left(tabIndex);
3602 }
3603
3604 p->save();
3605 if (!rightMarginText.isEmpty()) {
3606// p->setFont(qt_app_fonts_hash()->value("QMenuItem", p->font()));
3607 int xp = mi->rect.right() - tabwidth - macRightBorder + 2;
3608 if (!isSubMenu)
3609 xp -= macItemHMargin + macItemFrame + 3; // Adjust for shortcut
3610 p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags | Qt::AlignRight, rightMarginText);
3611 }
3612
3613 if (!s.isEmpty()) {
3614 const int xm = macItemFrame + maxpmw + macItemHMargin;
3615 QFont myFont = mi->font;
3616 // myFont may not have any "hard" flags set. We override
3617 // the point size so that when it is resolved against the device, this font will win.
3618 // This is mainly to handle cases where someone sets the font on the window
3619 // and then the combo inherits it and passes it onward. At that point the resolve mask
3620 // is very, very weak. This makes it stonger.
3621 myFont.setPointSizeF(QFontInfo(mi->font).pointSizeF());
3622
3623 // QTBUG-65653: Our own text rendering doesn't look good enough, especially on non-retina
3624 // displays. Worked around here while waiting for a proper fix in QCoreTextFontEngine.
3625 // Only if we're not using QCoreTextFontEngine we do fallback to our own text rendering.
3626 const auto *fontEngine = QFontPrivate::get(myFont)->engineForScript(QChar::Script_Common);
3627 Q_ASSERT(fontEngine);
3628 if (fontEngine->type() == QFontEngine::Multi) {
3629 fontEngine = static_cast<const QFontEngineMulti *>(fontEngine)->engine(0);
3630 Q_ASSERT(fontEngine);
3631 }
3632 if (fontEngine->type() == QFontEngine::Mac) {
3633 NSFont *f = (NSFont *)(CTFontRef)fontEngine->handle();
3634
3635 // Respect the menu item palette as set in the style option.
3636 const auto pc = p->pen().color();
3637 NSColor *c = [NSColor colorWithSRGBRed:pc.redF()
3638 green:pc.greenF()
3639 blue:pc.blueF()
3640 alpha:pc.alphaF()];
3641
3642 s = qt_mac_removeMnemonics(s);
3643
3644 QMacCGContext cgCtx(p);
3645 d->setupNSGraphicsContext(cgCtx, YES);
3646
3647 // Draw at point instead of in rect, as the rect we've computed for the menu item
3648 // is based on the font metrics we got from HarfBuzz, so we may risk having CoreText
3649 // line-break the string if it doesn't fit the given rect. It's better to draw outside
3650 // the rect and possibly overlap something than to have part of the text disappear.
3651 [s.toNSString() drawAtPoint:CGPointMake(xpos, yPos)
3652 withAttributes:@{ NSFontAttributeName:f, NSForegroundColorAttributeName:c,
3653 NSObliquenessAttributeName: [NSNumber numberWithDouble: myFont.italic() ? 0.3 : 0.0]}];
3654
3655 d->restoreNSGraphicsContext(cgCtx);
3656 } else {
3657 p->setFont(myFont);
3658 p->drawText(xpos, yPos, mi->rect.width() - xm - tabwidth + 1,
3659 mi->rect.height(), text_flags, s);
3660 }
3661 }
3662 p->restore();
3663 }
3664 break;
3665 case CE_MenuBarItem:
3666 case CE_MenuBarEmptyArea:
3667 if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
3668 const bool selected = (opt->state & State_Selected) && (opt->state & State_Enabled) && (opt->state & State_Sunken);
3669 const QBrush bg = selected ? mi->palette.highlight() : mi->palette.window();
3670 p->fillRect(mi->rect, bg);
3671
3672 if (ce != CE_MenuBarItem)
3673 break;
3674
3675 if (!mi->icon.isNull()) {
3676 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
3677 drawItemPixmap(p, mi->rect,
3678 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip
3679 | Qt::TextSingleLine,
3680 mi->icon.pixmap(QSize(iconExtent, iconExtent),
3681 opt->window->devicePixelRatio(),
3682 (mi->state & State_Enabled) ? QIcon::Normal
3683 : QIcon::Disabled));
3684 } else {
3685 drawItemText(p, mi->rect,
3686 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip
3687 | Qt::TextSingleLine,
3688 mi->palette, mi->state & State_Enabled,
3689 mi->text, selected ? QPalette::HighlightedText : QPalette::ButtonText);
3690 }
3691 }
3692 break;
3693 case CE_ProgressBarLabel:
3694 case CE_ProgressBarContents:
3695 break;
3696 case CE_ProgressBarGroove:
3697 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
3698 const bool isIndeterminate = (pb->minimum == 0 && pb->maximum == 0);
3699 const bool inverted = pb->invertedAppearance;
3700 bool reverse = pb->direction == Qt::RightToLeft;
3701 if (inverted)
3702 reverse = !reverse;
3703
3704 QRect rect = pb->rect;
3705 const CGRect cgRect = rect.toCGRect();
3706
3707 const auto aquaSize = d->aquaSizeConstrain(opt);
3708
3709// const QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject));
3710 QIndeterminateProgressIndicator *ipi = nil;
3711// if (isIndeterminate || animation)
3712 ipi = static_cast<QIndeterminateProgressIndicator *>(d->cocoaControl({ QMacStylePrivate::ProgressIndicator_Indeterminate, aquaSize }));
3713 if (isIndeterminate) {
3714 // QIndeterminateProgressIndicator derives from NSProgressIndicator. We use a single
3715 // instance that we start animating as soon as one of the progress bars is indeterminate.
3716 // Since they will be in sync (as it's the case in Cocoa), we just need to draw it with
3717 // the right geometry when the animation triggers an update. However, we can't hide it
3718 // entirely between frames since that would stop the animation, so we just set its alpha
3719 // value to 0. Same if we remove it from its superview. See QIndeterminateProgressIndicator
3720 // implementation for details.
3721 //
3722 // Quick: consider implementing this animation by using Quick/QML instead.
3723 //
3724// if (!animation && opt->styleObject) {
3725// auto *animation = new QProgressStyleAnimation(d->animateSpeed(QMacStylePrivate::AquaProgressBar), opt->styleObject);
3726// // NSProgressIndicator is heavier to draw than the HITheme API, so we reduce the frame rate a couple notches.
3727// animation->setFrameRate(QStyleAnimation::FifteenFps);
3728// d->startAnimation(animation);
3729// [ipi startAnimation];
3730// }
3731
3732 d->setupNSGraphicsContext(cg, NO);
3733 d->setupVerticalInvertedXform(cg, reverse, false, cgRect);
3734 [ipi drawWithFrame:cgRect inView:d->backingStoreNSView];
3735 d->restoreNSGraphicsContext(cg);
3736 } else {
3737// if (animation) {
3738// d->stopAnimation(opt->styleObject);
3739// [ipi stopAnimation];
3740// }
3741
3743 auto *pi = static_cast<NSProgressIndicator *>(d->cocoaControl(cw));
3744 d->drawNSViewInRect(pi, rect, p, ^(CGContextRef ctx, const CGRect &rect) {
3745 QMacAutoReleasePool pool;
3746 d->setupVerticalInvertedXform(ctx, reverse, false, rect);
3747 pi.minValue = pb->minimum;
3748 pi.maxValue = pb->maximum;
3749 pi.doubleValue = pb->progress;
3750 [pi drawRect:rect];
3751 });
3752 }
3753 }
3754 break;
3755 case CE_SizeGrip: {
3756 // This is not HIG kosher: Fall back to the old stuff until we decide what to do.
3757//#ifndef QT_NO_MDIAREA
3758// if (!w || !qobject_cast<QMdiSubWindow *>(w->parentWidget()))
3759//#endif
3760// break;
3761
3762// if (w->testAttribute(Qt::WA_MacOpaqueSizeGrip))
3763// p->fillRect(opt->rect, opt->palette.window());
3764
3765// QPen lineColor = QColor(82, 82, 82, 192);
3766// lineColor.setWidth(1);
3767// p->save();
3768// p->setRenderHint(QPainter::Antialiasing);
3769// p->setPen(lineColor);
3770// const Qt::LayoutDirection layoutDirection = w ? w->layoutDirection() : qApp->layoutDirection();
3771// const int NumLines = 3;
3772// for (int l = 0; l < NumLines; ++l) {
3773// const int offset = (l * 4 + 3);
3774// QPoint start, end;
3775// if (layoutDirection == Qt::LeftToRight) {
3776// start = QPoint(opt->rect.width() - offset, opt->rect.height() - 1);
3777// end = QPoint(opt->rect.width() - 1, opt->rect.height() - offset);
3778// } else {
3779// start = QPoint(offset, opt->rect.height() - 1);
3780// end = QPoint(1, opt->rect.height() - offset);
3781// }
3782// p->drawLine(start, end);
3783// }
3784// p->restore();
3785 break;
3786 }
3787 case CE_Splitter:
3788 if (opt->rect.width() > 1 && opt->rect.height() > 1) {
3789 const bool isVertical = !(opt->state & QStyle::State_Horizontal);
3790 // Qt refers to the layout orientation, while Cocoa refers to the divider's.
3792 const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
3793 auto *sv = static_cast<NSSplitView *>(d->cocoaControl(cw));
3794 sv.frame = opt->rect.toCGRect();
3795 d->drawNSViewInRect(sv, opt->rect, p, ^(CGContextRef, const CGRect &rect) {
3796 QMacAutoReleasePool pool;
3797 [sv drawDividerInRect:rect];
3798 });
3799 } else {
3800 QPen oldPen = p->pen();
3801 p->setPen(opt->palette.dark().color());
3802 if (opt->state & QStyle::State_Horizontal)
3803 p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
3804 else
3805 p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
3806 p->setPen(oldPen);
3807 }
3808 break;
3809 case CE_RubberBand:
3810 if (const QStyleOptionRubberBand *rubber = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
3811 QColor fillColor(opt->palette.color(QPalette::Disabled, QPalette::Highlight));
3812 if (!rubber->opaque) {
3813 QColor strokeColor;
3814 // I retrieved these colors from the Carbon-Dev mailing list
3815 strokeColor.setHsvF(0, 0, 0.86, 1.0);
3816 fillColor.setHsvF(0, 0, 0.53, 0.25);
3817 if (opt->rect.width() * opt->rect.height() <= 3) {
3818 p->fillRect(opt->rect, strokeColor);
3819 } else {
3820 QPen oldPen = p->pen();
3821 QBrush oldBrush = p->brush();
3822 QPen pen(strokeColor);
3823 p->setPen(pen);
3824 p->setBrush(fillColor);
3825 QRect adjusted = opt->rect.adjusted(1, 1, -1, -1);
3826 if (adjusted.isValid())
3827 p->drawRect(adjusted);
3828 p->setPen(oldPen);
3829 p->setBrush(oldBrush);
3830 }
3831 } else {
3832 p->fillRect(opt->rect, fillColor);
3833 }
3834 }
3835 break;
3836 case CE_ToolBar: {
3837 const bool isDarkMode = QT_PREPEND_NAMESPACE(QQC2_NAMESPACE::isDarkMode());
3838
3839 // Unified title and toolbar drawing. In this mode the cocoa platform plugin will
3840 // fill the top toolbar area part with a background gradient that "unifies" with
3841 // the title bar. The following code fills the toolBar area with transparent pixels
3842 // to make that gradient visible.
3843// if (w) {
3844//#if QT_CONFIG(mainwindow)
3845// if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) {
3846// if (toolBar && toolBar->toolBarArea == Qt::TopToolBarArea && mainWindow->unifiedTitleAndToolBarOnMac()) {
3847// // fill with transparent pixels.
3848// p->save();
3849// p->setCompositionMode(QPainter::CompositionMode_Source);
3850// p->fillRect(opt->rect, Qt::transparent);
3851// p->restore();
3852
3853// // Draw a horizontal separator line at the toolBar bottom if the "unified" area ends here.
3854// // There might be additional toolbars or other widgets such as tab bars in document
3855// // mode below. Determine this by making a unified toolbar area test for the row below
3856// // this toolbar.
3857// const QPoint windowToolbarEnd = w->mapTo(w->window(), opt->rect.bottomLeft());
3858// const bool isEndOfUnifiedArea = !isInMacUnifiedToolbarArea(w->window()->windowHandle(), windowToolbarEnd.y() + 1);
3859// if (isEndOfUnifiedArea) {
3860// const int margin = qt_mac_aqua_get_metric(SeparatorSize);
3861// const auto separatorRect = QRect(opt->rect.left(), opt->rect.bottom(), opt->rect.width(), margin);
3862// p->fillRect(separatorRect, isDarkMode ? darkModeSeparatorLine : opt->palette.dark().color());
3863// }
3864// break;
3865// }
3866// }
3867//#endif
3868// }
3869
3870 // draw background gradient
3871 QLinearGradient linearGrad;
3872 if (opt->state & State_Horizontal)
3873 linearGrad = QLinearGradient(0, opt->rect.top(), 0, opt->rect.bottom());
3874 else
3875 linearGrad = QLinearGradient(opt->rect.left(), 0, opt->rect.right(), 0);
3876
3877 QColor mainWindowGradientBegin = isDarkMode ? darkMainWindowGradientBegin : lightMainWindowGradientBegin;
3878 QColor mainWindowGradientEnd = isDarkMode ? darkMainWindowGradientEnd : lightMainWindowGradientEnd;
3879
3880 linearGrad.setColorAt(0, mainWindowGradientBegin);
3881 linearGrad.setColorAt(1, mainWindowGradientEnd);
3882 p->fillRect(opt->rect, linearGrad);
3883
3884 p->save();
3885 QRect toolbarRect = isDarkMode ? opt->rect.adjusted(0, 0, 0, 1) : opt->rect;
3886 if (opt->state & State_Horizontal) {
3887 p->setPen(isDarkMode ? darkModeSeparatorLine : mainWindowGradientBegin.lighter(114));
3888 p->drawLine(toolbarRect.topLeft(), toolbarRect.topRight());
3889 p->setPen(isDarkMode ? darkModeSeparatorLine :mainWindowGradientEnd.darker(114));
3890 p->drawLine(toolbarRect.bottomLeft(), toolbarRect.bottomRight());
3891 } else {
3892 p->setPen(isDarkMode ? darkModeSeparatorLine : mainWindowGradientBegin.lighter(114));
3893 p->drawLine(toolbarRect.topLeft(), toolbarRect.bottomLeft());
3894 p->setPen(isDarkMode ? darkModeSeparatorLine : mainWindowGradientEnd.darker(114));
3895 p->drawLine(toolbarRect.topRight(), toolbarRect.bottomRight());
3896 }
3897 p->restore();
3898
3899 break; }
3900 default:
3901 QCommonStyle::drawControl(ce, opt, p);
3902 break;
3903 }
3904}
3905
3906static void setLayoutItemMargins(int left, int top, int right, int bottom, QRect *rect, Qt::LayoutDirection dir)
3907{
3908 if (dir == Qt::RightToLeft) {
3909 rect->adjust(-right, top, -left, bottom);
3910 } else {
3911 rect->adjust(left, top, right, bottom);
3912 }
3913}
3914
3915QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt) const
3916{
3917 Q_D(const QMacStyle);
3918 QRect rect;
3919 const int controlSize = getControlSize(opt);
3920
3921 switch (sr) {
3922 case SE_ItemViewItemText:
3923 if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
3924 int fw = proxy()->pixelMetric(PM_FocusFrameHMargin, opt);
3925 // We add the focusframeargin between icon and text in commonstyle
3926 rect = QCommonStyle::subElementRect(sr, opt);
3927 if (vopt->features & QStyleOptionViewItem::HasDecoration)
3928 rect.adjust(-fw, 0, 0, 0);
3929 }
3930 break;
3931 case SE_ToolBoxTabContents:
3932 rect = QCommonStyle::subElementRect(sr, opt);
3933 break;
3934 case SE_PushButtonContents:
3935 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
3936 // Comment from the old HITheme days:
3937 // "Unlike Carbon, we want the button to always be drawn inside its bounds.
3938 // Therefore, the button is a bit smaller, so that even if it got focus,
3939 // the focus 'shadow' will be inside. Adjust the content rect likewise."
3940 // In the future, we should consider using -[NSCell titleRectForBounds:].
3941 // Since it requires configuring the NSButton fully, i.e. frame, image,
3942 // title and font, we keep things more manual until we are more familiar
3943 // with side effects when changing NSButton state.
3944 const auto ct = cocoaControlType(btn);
3945 const auto cs = d->effectiveAquaSizeConstrain(btn);
3946 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
3947 auto frameRect = cw.adjustedControlFrame(btn->rect);
3948 frameRect -= cw.titleMargins();
3949 rect = frameRect.toRect();
3950 }
3951 break;
3952 case SE_HeaderLabel: {
3953 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt);
3954 rect.setRect(opt->rect.x() + margin, opt->rect.y(),
3955 opt->rect.width() - margin * 2, opt->rect.height() - 2);
3956 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
3957 // Subtract width needed for arrow, if there is one
3958 if (header->sortIndicator != QStyleOptionHeader::None) {
3959 if (opt->state & State_Horizontal)
3960 rect.setWidth(rect.width() - (headerSectionArrowHeight) - (margin * 2));
3961 else
3962 rect.setHeight(rect.height() - (headerSectionArrowHeight) - (margin * 2));
3963 }
3964 }
3965 rect = visualRect(opt->direction, opt->rect, rect);
3966 break;
3967 }
3968 case SE_HeaderArrow: {
3969 int h = opt->rect.height();
3970 int w = opt->rect.width();
3971 int x = opt->rect.x();
3972 int y = opt->rect.y();
3973 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt);
3974
3975 if (opt->state & State_Horizontal) {
3976 rect.setRect(x + w - margin * 2 - headerSectionArrowHeight, y + 5,
3977 headerSectionArrowHeight, h - margin * 2 - 5);
3978 } else {
3979 rect.setRect(x + 5, y + h - margin * 2 - headerSectionArrowHeight,
3980 w - margin * 2 - 5, headerSectionArrowHeight);
3981 }
3982 rect = visualRect(opt->direction, opt->rect, rect);
3983 break;
3984 }
3985 case SE_ProgressBarGroove:
3986 // Wrong in the secondary dimension, but accurate enough in the main dimension.
3987 rect = opt->rect;
3988 break;
3989 case SE_ProgressBarLabel:
3990 break;
3991 case SE_ProgressBarContents:
3992 rect = opt->rect;
3993 break;
3994 case SE_TreeViewDisclosureItem: {
3995 rect = opt->rect;
3996 // As previously returned by HIThemeGetButtonContentBounds
3997 rect.setLeft(rect.left() + 2 + DisclosureOffset);
3998 break;
3999 }
4000 case SE_TabWidgetLeftCorner:
4001 if (const QStyleOptionTabWidgetFrame *twf
4002 = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
4003 switch (twf->shape) {
4004 case QStyleOptionTab::RoundedNorth:
4005 case QStyleOptionTab::TriangularNorth:
4006 rect = QRect(QPoint(0, 0), twf->leftCornerWidgetSize);
4007 break;
4008 case QStyleOptionTab::RoundedSouth:
4009 case QStyleOptionTab::TriangularSouth:
4010 rect = QRect(QPoint(0, twf->rect.height() - twf->leftCornerWidgetSize.height()),
4011 twf->leftCornerWidgetSize);
4012 break;
4013 default:
4014 break;
4015 }
4016 rect = visualRect(twf->direction, twf->rect, rect);
4017 }
4018 break;
4019 case SE_TabWidgetRightCorner:
4020 if (const QStyleOptionTabWidgetFrame *twf
4021 = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
4022 switch (twf->shape) {
4023 case QStyleOptionTab::RoundedNorth:
4024 case QStyleOptionTab::TriangularNorth:
4025 rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(), 0),
4026 twf->rightCornerWidgetSize);
4027 break;
4028 case QStyleOptionTab::RoundedSouth:
4029 case QStyleOptionTab::TriangularSouth:
4030 rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(),
4031 twf->rect.height() - twf->rightCornerWidgetSize.height()),
4032 twf->rightCornerWidgetSize);
4033 break;
4034 default:
4035 break;
4036 }
4037 rect = visualRect(twf->direction, twf->rect, rect);
4038 }
4039 break;
4040 case SE_TabWidgetTabContents:
4041 rect = QCommonStyle::subElementRect(sr, opt);
4042 if (const auto *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
4043 if (twf->lineWidth != 0) {
4044 switch (QMacStylePrivate::tabDirection(twf->shape)) {
4045 case QMacStylePrivate::North:
4046 rect.adjust(+1, +14, -1, -1);
4047 break;
4048 case QMacStylePrivate::South:
4049 rect.adjust(+1, +1, -1, -14);
4050 break;
4051 case QMacStylePrivate::West:
4052 rect.adjust(+14, +1, -1, -1);
4053 break;
4054 case QMacStylePrivate::East:
4055 rect.adjust(+1, +1, -14, -1);
4056 }
4057 }
4058 }
4059 break;
4060 case SE_TabBarTabText:
4061 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
4062 QRect dummyIconRect;
4063 d->tabLayout(tab, &rect, &dummyIconRect);
4064 }
4065 break;
4066 case SE_TabBarTabLeftButton:
4067 case SE_TabBarTabRightButton:
4068 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
4069 bool selected = tab->state & State_Selected;
4070 int verticalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab);
4071 int horizontalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab);
4072 int hpadding = 5;
4073
4074 bool verticalTabs = tab->shape == QStyleOptionTab::RoundedEast
4075 || tab->shape == QStyleOptionTab::RoundedWest
4076 || tab->shape == QStyleOptionTab::TriangularEast
4077 || tab->shape == QStyleOptionTab::TriangularWest;
4078
4079 QRect tr = tab->rect;
4080 if (tab->shape == QStyleOptionTab::RoundedSouth || tab->shape == QStyleOptionTab::TriangularSouth)
4081 verticalShift = -verticalShift;
4082 if (verticalTabs) {
4083 qSwap(horizontalShift, verticalShift);
4084 horizontalShift *= -1;
4085 verticalShift *= -1;
4086 }
4087 if (tab->shape == QStyleOptionTab::RoundedWest || tab->shape == QStyleOptionTab::TriangularWest)
4088 horizontalShift = -horizontalShift;
4089
4090 tr.adjust(0, 0, horizontalShift, verticalShift);
4091 if (selected)
4092 {
4093 tr.setBottom(tr.bottom() - verticalShift);
4094 tr.setRight(tr.right() - horizontalShift);
4095 }
4096
4097 QSize size = (sr == SE_TabBarTabLeftButton) ? tab->leftButtonSize : tab->rightButtonSize;
4098 int w = size.width();
4099 int h = size.height();
4100 int midHeight = static_cast<int>(qCeil(float(tr.height() - h) / 2));
4101 int midWidth = ((tr.width() - w) / 2);
4102
4103 bool atTheTop = true;
4104 switch (tab->shape) {
4105 case QStyleOptionTab::RoundedWest:
4106 case QStyleOptionTab::TriangularWest:
4107 atTheTop = (sr == SE_TabBarTabLeftButton);
4108 break;
4109 case QStyleOptionTab::RoundedEast:
4110 case QStyleOptionTab::TriangularEast:
4111 atTheTop = (sr == SE_TabBarTabRightButton);
4112 break;
4113 default:
4114 if (sr == SE_TabBarTabLeftButton)
4115 rect = QRect(tab->rect.x() + hpadding, midHeight, w, h);
4116 else
4117 rect = QRect(tab->rect.right() - w - hpadding, midHeight, w, h);
4118 rect = visualRect(tab->direction, tab->rect, rect);
4119 }
4120 if (verticalTabs) {
4121 if (atTheTop)
4122 rect = QRect(midWidth, tr.y() + tab->rect.height() - hpadding - h, w, h);
4123 else
4124 rect = QRect(midWidth, tr.y() + hpadding, w, h);
4125 }
4126 }
4127 break;
4128 case SE_LineEditContents: {
4129 // From using pixelTool with XCode/NSTextTextField
4130 int leftPadding = 4;
4131 int rightPadding = 4;
4132 int topPadding = 4;
4133 int bottomPadding = 0;
4134
4135 if (opt->state & QStyle::State_Small) {
4136 topPadding = 3;
4137 } else if (opt->state & QStyle::State_Mini) {
4138 topPadding = 2;
4139 }
4140
4141 rect = QRect(leftPadding, topPadding, opt->rect.width() - leftPadding - rightPadding,
4142 opt->rect.height() - topPadding - bottomPadding);
4143 break; }
4144 case SE_CheckBoxLayoutItem:
4145 rect = opt->rect;
4146 if (controlSize == QStyleHelper::SizeLarge) {
4147 setLayoutItemMargins(+2, +2, -3, -2, &rect, opt->direction);
4148 } else if (controlSize == QStyleHelper::SizeSmall) {
4149 setLayoutItemMargins(+1, +2, -2, -1, &rect, opt->direction);
4150 } else {
4151 setLayoutItemMargins(-0, +0, -1, -0, &rect, opt->direction);
4152 }
4153 break;
4154 case SE_SearchFieldLayoutItem:
4155 if (qstyleoption_cast<const QStyleOptionSearchField *>(opt)) {
4156 if (qt_apple_runningWithLiquidGlass()) {
4157 rect = LargeSmallMini(opt,
4158 opt->rect.adjusted(2, 4, -2, -4),
4159 opt->rect.adjusted(2, 3, -2, -2),
4160 opt->rect.adjusted(2, 3, -2, -2));
4161 } else {
4162 rect = LargeSmallMini(opt,
4163 opt->rect.adjusted(2, 6, -2, -6),
4164 opt->rect.adjusted(2, 3, -2, -2),
4165 opt->rect.adjusted(2, 3, -2, -2));
4166 }
4167 }
4168 break;
4169 case SE_ComboBoxLayoutItem:
4170 if (const auto *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
4171 //#ifndef QT_NO_TOOLBAR
4172 // if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) {
4173 // // Do nothing, because QToolbar needs the entire widget rect.
4174 // // Otherwise it will be clipped. Equivalent to
4175 // // widget->setAttribute(Qt::WA_LayoutUsesWidgetRect), but without
4176 // // all the hassle.
4177 // } else
4178 //#endif
4179 if (combo->editable) {
4180 if (qt_apple_runningWithLiquidGlass()) {
4181 rect = LargeSmallMini(opt,
4182 opt->rect.adjusted(4, 4, -4, -4),
4183 opt->rect.adjusted(4, 4, -5, -7),
4184 opt->rect.adjusted(5, 4, -4, -6));
4185 } else {
4186 rect = LargeSmallMini(opt,
4187 opt->rect.adjusted(5, 6, -6, -7),
4188 opt->rect.adjusted(4, 4, -5, -7),
4189 opt->rect.adjusted(5, 4, -4, -6));
4190 }
4191 } else {
4192 if (qt_apple_runningWithLiquidGlass()) {
4193 rect = LargeSmallMini(opt,
4194 opt->rect.adjusted(4, 4, -4, -4),
4195 opt->rect.adjusted(6, 7, -6, -5),
4196 opt->rect.adjusted(9, 5, -5, -7));
4197 } else {
4198 rect = LargeSmallMini(opt,
4199 opt->rect.adjusted(6, 4, -7, -7),
4200 opt->rect.adjusted(6, 7, -6, -5),
4201 opt->rect.adjusted(9, 5, -5, -7));
4202 }
4203 }
4204 }
4205 break;
4206 case SE_LabelLayoutItem:
4207 rect = opt->rect;
4208 setLayoutItemMargins(+1, 0 /* SHOULD be -1, done for alignment */, 0, 0 /* SHOULD be -1, done for alignment */, &rect, opt->direction);
4209 break;
4210 case SE_ProgressBarLayoutItem:
4211 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
4212 const bool isIndeterminate = (pb->minimum == 0 && pb->maximum == 0);
4213 rect = opt->rect;
4214
4215 if (isIndeterminate) {
4216 rect.adjust(1, 2, -1, -2);
4217 } else {
4218 rect.adjust(1, 1, -1, -2);
4219 }
4220 }
4221 break;
4222 case SE_PushButtonLayoutItem:
4223 rect = opt->rect;
4224 if (const QStyleOptionButton *buttonOpt = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
4225 if ((buttonOpt->features & QStyleOptionButton::Flat))
4226 break;
4227 }
4228 if (qt_apple_runningWithLiquidGlass()) {
4229 rect = LargeSmallMini(opt,
4230 opt->rect.adjusted(2, 5, -2, -7),
4231 opt->rect.adjusted(6, 6, -6, -6),
4232 opt->rect.adjusted(6, 5, -6, -6));
4233 } else {
4234 rect = LargeSmallMini(opt,
4235 opt->rect.adjusted(7, 5, -7, -7),
4236 opt->rect.adjusted(6, 6, -6, -6),
4237 opt->rect.adjusted(6, 5, -6, -6));
4238 }
4239 break;
4240 case SE_SpinBoxLayoutItem:
4241 rect = LargeSmallMini(opt,
4242 opt->rect.adjusted(2, 3, -2, -2),
4243 opt->rect.adjusted(2, 3, -2, -2),
4244 opt->rect.adjusted(2, 3, -2, -2));
4245 break;
4246 case SE_RadioButtonLayoutItem:
4247 rect = LargeSmallMini(opt,
4248 opt->rect.adjusted(2, 2, -3, -2),
4249 opt->rect.adjusted(2, 2, -3, -2),
4250 opt->rect.adjusted(1, 2, -3, -2));
4251 break;
4252 case SE_SliderLayoutItem:
4253 if (const QStyleOptionSlider *sliderOpt
4254 = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
4255 rect = opt->rect;
4256 if (sliderOpt->subControls & QStyle::SC_SliderHandle) {
4257 if (sliderOpt->tickPosition == QStyleOptionSlider::NoTicks)
4258 rect.adjust(3, 3, -3, -3);
4259 } else {
4260 rect.adjust(3, 0, -3, 0);
4261 }
4262 }
4263 break;
4264 case SE_ScrollBarLayoutItem:
4265 if (qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
4266 rect = opt->rect;
4267 }
4268 case SE_FrameLayoutItem:
4269 // hack because QStyleOptionFrame doesn't have a frameStyle member
4270// if (const QFrame *frame = qobject_cast<const QFrame *>(widget)) {
4271// rect = opt->rect;
4272// switch (frame->frameStyle() & QFrame::Shape_Mask) {
4273// case QFrame::HLine:
4274// rect.adjust(0, +1, 0, -1);
4275// break;
4276// case QFrame::VLine:
4277// rect.adjust(+1, 0, -1, 0);
4278// break;
4279// default:
4280// ;
4281// }
4282// }
4283 break;
4284 case SE_GroupBoxLayoutItem:
4285 rect = opt->rect;
4286 if (const QStyleOptionGroupBox *groupBoxOpt =
4287 qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) {
4288 /*
4289 AHIG is very inconsistent when it comes to group boxes.
4290 Basically, we make sure that (non-checkable) group boxes
4291 and tab widgets look good when laid out side by side.
4292 */
4293 if (groupBoxOpt->subControls & (QStyle::SC_GroupBoxCheckBox
4294 | QStyle::SC_GroupBoxLabel)) {
4295 int delta;
4296 if (groupBoxOpt->subControls & QStyle::SC_GroupBoxCheckBox) {
4297 delta = SIZE(8, 4, 4); // guess
4298 } else {
4299 delta = SIZE(15, 12, 12); // guess
4300 }
4301 rect.setTop(rect.top() + delta);
4302 }
4303 }
4304 rect.setBottom(rect.bottom() - 1);
4305 break;
4306 case SE_TabWidgetLayoutItem:
4307 if (const QStyleOptionTabWidgetFrame *tabWidgetOpt =
4308 qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
4309 /*
4310 AHIG specifies "12 or 14" as the distance from the window
4311 edge. We choose 14 and since the default top margin is 20,
4312 the overlap is 6.
4313 */
4314 rect = tabWidgetOpt->rect;
4315 if (tabWidgetOpt->shape == QStyleOptionTab::RoundedNorth)
4316 rect.setTop(rect.top() + SIZE(6 /* AHIG */, 3 /* guess */, 2 /* AHIG */));
4317 }
4318 break;
4319 case SE_DockWidgetCloseButton:
4320 case SE_DockWidgetFloatButton:
4321 case SE_DockWidgetTitleBarText:
4322 case SE_DockWidgetIcon: {
4323 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, opt);
4324 int buttonMargin = proxy()->pixelMetric(PM_DockWidgetTitleBarButtonMargin, opt);
4325 QRect srect = opt->rect;
4326
4327 const QStyleOptionDockWidget *dwOpt
4328 = qstyleoption_cast<const QStyleOptionDockWidget*>(opt);
4329 bool canClose = dwOpt == 0 ? true : dwOpt->closable;
4330 bool canFloat = dwOpt == 0 ? false : dwOpt->floatable;
4331
4332 const bool verticalTitleBar = dwOpt->verticalTitleBar;
4333
4334 // If this is a vertical titlebar, we transpose and work as if it was
4335 // horizontal, then transpose again.
4336 if (verticalTitleBar)
4337 srect = srect.transposed();
4338
4339 do {
4340 int right = srect.right();
4341 int left = srect.left();
4342
4343 QRect closeRect;
4344 if (canClose) {
4345 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton,
4346 opt).actualSize(QSize(iconSize, iconSize));
4347 sz += QSize(buttonMargin, buttonMargin);
4348 if (verticalTitleBar)
4349 sz = sz.transposed();
4350 closeRect = QRect(left,
4351 srect.center().y() - sz.height()/2,
4352 sz.width(), sz.height());
4353 left = closeRect.right() + 1;
4354 }
4355 if (sr == SE_DockWidgetCloseButton) {
4356 rect = closeRect;
4357 break;
4358 }
4359
4360 QRect floatRect;
4361 if (canFloat) {
4362 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarNormalButton,
4363 opt).actualSize(QSize(iconSize, iconSize));
4364 sz += QSize(buttonMargin, buttonMargin);
4365 if (verticalTitleBar)
4366 sz = sz.transposed();
4367 floatRect = QRect(left,
4368 srect.center().y() - sz.height()/2,
4369 sz.width(), sz.height());
4370 left = floatRect.right() + 1;
4371 }
4372 if (sr == SE_DockWidgetFloatButton) {
4373 rect = floatRect;
4374 break;
4375 }
4376
4377 QRect iconRect;
4378// if (const QDockWidget *dw = qobject_cast<const QDockWidget*>(widget)) {
4379// QIcon icon;
4380// if (dw->isFloating())
4381// icon = dw->windowIcon();
4382// if (!icon.isNull()
4383// && icon.cacheKey() != QApplication::windowIcon().cacheKey()) {
4384// QSize sz = icon.actualSize(QSize(rect.height(), rect.height()));
4385// if (verticalTitleBar)
4386// sz = sz.transposed();
4387// iconRect = QRect(right - sz.width(), srect.center().y() - sz.height()/2,
4388// sz.width(), sz.height());
4389// right = iconRect.left() - 1;
4390// }
4391// }
4392 if (sr == SE_DockWidgetIcon) {
4393 rect = iconRect;
4394 break;
4395 }
4396
4397 QRect textRect = QRect(left, srect.top(),
4398 right - left, srect.height());
4399 if (sr == SE_DockWidgetTitleBarText) {
4400 rect = textRect;
4401 break;
4402 }
4403 } while (false);
4404
4405 if (verticalTitleBar) {
4406 rect = QRect(srect.left() + rect.top() - srect.top(),
4407 srect.top() + srect.right() - rect.right(),
4408 rect.height(), rect.width());
4409 } else {
4410 rect = visualRect(opt->direction, srect, rect);
4411 }
4412 break;
4413 }
4414 default:
4415 rect = QCommonStyle::subElementRect(sr, opt);
4416 break;
4417 }
4418 return rect;
4419}
4420
4421void QMacStylePrivate::drawToolbarButtonArrow(const QStyleOption *opt, QPainter *p) const
4422{
4423 Q_Q(const QMacStyle);
4424 QStyleOption arrowOpt = *opt;
4425 arrowOpt.rect = QRect(opt->rect.right() - (toolButtonArrowSize + toolButtonArrowMargin),
4426 opt->rect.bottom() - (toolButtonArrowSize + toolButtonArrowMargin),
4429 q->proxy()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &arrowOpt, p);
4430}
4431
4432void QMacStylePrivate::setupNSGraphicsContext(CGContextRef cg, bool flipped) const
4433{
4434 CGContextSaveGState(cg);
4435 [NSGraphicsContext saveGraphicsState];
4436
4437 [NSGraphicsContext setCurrentContext:
4438 [NSGraphicsContext graphicsContextWithCGContext:cg flipped:flipped]];
4439}
4440
4441void QMacStylePrivate::restoreNSGraphicsContext(CGContextRef cg) const
4442{
4443 [NSGraphicsContext restoreGraphicsState];
4444 CGContextRestoreGState(cg);
4445}
4446
4447void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p) const
4448{
4449 Q_D(const QMacStyle);
4450
4451 QMacCGContext cg(p);
4452 d->resolveCurrentNSView(opt->window);
4453
4454 switch (cc) {
4455 case CC_ScrollBar:
4456 if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
4457
4458 const bool drawTrack = sb->subControls & SC_ScrollBarGroove;
4459 const bool drawKnob = sb->subControls & SC_ScrollBarSlider;
4460 if (!drawTrack && !drawKnob)
4461 break;
4462
4463 const bool isHorizontal = sb->orientation == Qt::Horizontal;
4464
4465 if (opt && opt->styleObject && !QMacStylePrivate::scrollBars.contains(opt->styleObject))
4466 QMacStylePrivate::scrollBars.append(QPointer<QObject>(opt->styleObject));
4467
4468 static const CGFloat knobWidths[] = { 7.0, 5.0, 5.0 };
4469 const auto cocoaSize = d->effectiveAquaSizeConstrain(opt);
4470
4471 const bool isTransient = proxy()->styleHint(SH_ScrollBar_Transient, opt);
4472// if (!isTransient)
4473// d->stopAnimation(opt->styleObject);
4474 bool wasActive = false;
4475 CGFloat opacity = 0.0;
4476 CGFloat expandScale = 1.0;
4477 CGFloat expandOffset = 0.0;
4478 bool shouldExpand = false;
4479
4480 if (QObject *styleObject = opt->styleObject) {
4481 const int oldPos = styleObject->property("_q_stylepos").toInt();
4482 const int oldMin = styleObject->property("_q_stylemin").toInt();
4483 const int oldMax = styleObject->property("_q_stylemax").toInt();
4484 const QRect oldRect = styleObject->property("_q_stylerect").toRect();
4485 const QStyle::State oldState = static_cast<QStyle::State>(styleObject->property("_q_stylestate").value<QStyle::State::Int>());
4486 const uint oldActiveControls = styleObject->property("_q_stylecontrols").toUInt();
4487
4488 // a scrollbar is transient when the scrollbar itself and
4489 // its sibling are both inactive (ie. not pressed/hovered/moved)
4490 const bool transient = isTransient && !opt->activeSubControls && !(sb->state & State_On);
4491
4492 if (!transient ||
4493 oldPos != sb->sliderPosition ||
4494 oldMin != sb->minimum ||
4495 oldMax != sb->maximum ||
4496 oldRect != sb->rect ||
4497 oldState != sb->state ||
4498 oldActiveControls != sb->activeSubControls) {
4499
4500 // if the scrollbar is transient or its attributes, geometry or
4501 // state has changed, the opacity is reset back to 100% opaque
4502 opacity = 1.0;
4503
4504 styleObject->setProperty("_q_stylepos", sb->sliderPosition);
4505 styleObject->setProperty("_q_stylemin", sb->minimum);
4506 styleObject->setProperty("_q_stylemax", sb->maximum);
4507 styleObject->setProperty("_q_stylerect", sb->rect);
4508 styleObject->setProperty("_q_stylestate", static_cast<QStyle::State::Int>(sb->state));
4509 styleObject->setProperty("_q_stylecontrols", static_cast<uint>(sb->activeSubControls));
4510
4511// QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
4512// if (transient) {
4513// if (!anim) {
4514// anim = new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Deactivating, styleObject);
4515// d->startAnimation(anim);
4516// } else if (anim->mode() == QScrollbarStyleAnimation::Deactivating) {
4517// // the scrollbar was already fading out while the
4518// // state changed -> restart the fade out animation
4519// anim->setCurrentTime(0);
4520// }
4521// } else if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
4522// d->stopAnimation(styleObject);
4523// }
4524 }
4525
4526// QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject));
4527// if (anim && anim->mode() == QScrollbarStyleAnimation::Deactivating) {
4528// // once a scrollbar was active (hovered/pressed), it retains
4529// // the active look even if it's no longer active while fading out
4530// if (oldActiveControls)
4531// anim->setActive(true);
4532
4533// wasActive = anim->wasActive();
4534// opacity = anim->currentValue();
4535// }
4536
4537 shouldExpand = isTransient && (opt->activeSubControls || wasActive);
4538 if (shouldExpand) {
4539// if (!anim && !oldActiveControls) {
4540// // Start expand animation only once and when entering
4541// anim = new QScrollbarStyleAnimation(QScrollbarStyleAnimation::Activating, styleObject);
4542// d->startAnimation(anim);
4543// }
4544// if (anim && anim->mode() == QScrollbarStyleAnimation::Activating) {
4545// expandScale = 1.0 + (maxExpandScale - 1.0) * anim->currentValue();
4546// expandOffset = 5.5 * (1.0 - anim->currentValue());
4547// } else {
4548// // Keep expanded state after the animation ends, and when fading out
4549// expandScale = maxExpandScale;
4550// expandOffset = 0.0;
4551// }
4552 }
4553 }
4554
4555 d->setupNSGraphicsContext(cg, NO /* flipped */);
4556
4557 const auto controlType = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical;
4558 const auto cw = QMacStylePrivate::CocoaControl(controlType, cocoaSize);
4559 NSScroller *scroller = static_cast<NSScroller *>(d->cocoaControl(cw));
4560
4561 const QColor bgColor = QStyleHelper::backgroundColor(opt->palette);
4562 const bool hasDarkBg = bgColor.red() < 128 && bgColor.green() < 128 && bgColor.blue() < 128;
4563 if (isTransient) {
4564 // macOS behavior: as soon as one color channel is >= 128,
4565 // the background is considered bright, scroller is dark.
4566 scroller.knobStyle = hasDarkBg? NSScrollerKnobStyleLight : NSScrollerKnobStyleDark;
4567 } else {
4568 scroller.knobStyle = NSScrollerKnobStyleDefault;
4569 }
4570
4571 scroller.scrollerStyle = isTransient ? NSScrollerStyleOverlay : NSScrollerStyleLegacy;
4572
4573 if (!setupScroller(scroller, sb))
4574 break;
4575
4576 if (isTransient) {
4577 CGContextBeginTransparencyLayerWithRect(cg, scroller.frame, nullptr);
4578 CGContextSetAlpha(cg, opacity);
4579 }
4580
4581 if (drawTrack) {
4582 // Draw the track when hovering. Expand by shifting the track rect.
4583 if (!isTransient || opt->activeSubControls || wasActive) {
4584 CGRect trackRect = scroller.bounds;
4585 if (isHorizontal)
4586 trackRect.origin.y += expandOffset;
4587 else
4588 trackRect.origin.x += expandOffset;
4589 [scroller drawKnobSlotInRect:trackRect highlight:NO];
4590 }
4591 }
4592
4593 if (drawKnob) {
4594 if (shouldExpand) {
4595 // -[NSScroller drawKnob] is not useful here because any scaling applied
4596 // will only be used to draw the hi-DPI artwork. And even if did scale,
4597 // the stretched knob would look wrong, actually. So we need to draw the
4598 // scroller manually when it's being hovered.
4599 const CGFloat scrollerWidth = [NSScroller scrollerWidthForControlSize:scroller.controlSize scrollerStyle:scroller.scrollerStyle];
4600 const CGFloat knobWidth = knobWidths[cocoaSize] * expandScale;
4601 // Cocoa can help get the exact knob length in the current orientation
4602 const CGRect scrollerKnobRect = CGRectInset([scroller rectForPart:NSScrollerKnob], 1, 1);
4603 const CGFloat knobLength = isHorizontal ? scrollerKnobRect.size.width : scrollerKnobRect.size.height;
4604 const CGFloat knobPos = isHorizontal ? scrollerKnobRect.origin.x : scrollerKnobRect.origin.y;
4605 const CGFloat knobOffset = qRound((scrollerWidth + expandOffset - knobWidth) / 2.0);
4606 const CGFloat knobRadius = knobWidth / 2.0;
4607 CGRect knobRect;
4608 if (isHorizontal)
4609 knobRect = CGRectMake(knobPos, knobOffset, knobLength, knobWidth);
4610 else
4611 knobRect = CGRectMake(knobOffset, knobPos, knobWidth, knobLength);
4612 QCFType<CGPathRef> knobPath = CGPathCreateWithRoundedRect(knobRect, knobRadius, knobRadius, nullptr);
4613 CGContextAddPath(cg, knobPath);
4614 CGContextSetAlpha(cg, 0.5);
4615 CGColorRef knobColor = hasDarkBg ? NSColor.whiteColor.CGColor : NSColor.blackColor.CGColor;
4616 CGContextSetFillColorWithColor(cg, knobColor);
4617 CGContextFillPath(cg);
4618 } else {
4619 [scroller drawKnob];
4620
4621 if (!isTransient && opt->state & State_Sunken) {
4622 // The knob should appear darker (going from 0.76 down to 0.49).
4623 // But no blending mode can help darken enough in a single pass,
4624 // so we resort to drawing the knob twice with a small help from
4625 // blending. This brings the gray level to a close enough 0.53.
4626 CGContextSetBlendMode(cg, kCGBlendModePlusDarker);
4627 [scroller drawKnob];
4628 }
4629 }
4630 }
4631
4632 if (isTransient)
4633 CGContextEndTransparencyLayer(cg);
4634
4635 d->restoreNSGraphicsContext(cg);
4636 }
4637 break;
4638 case CC_Slider:
4639 if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
4640 const bool isHorizontal = sl->orientation == Qt::Horizontal;
4642 const auto cs = d->effectiveAquaSizeConstrain(opt);
4643 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
4644 auto *slider = static_cast<NSSlider *>(d->cocoaControl(cw));
4645 if (!setupSlider(slider, sl))
4646 break;
4647
4648 const bool hasTicks = sl->tickPosition != QStyleOptionSlider::NoTicks;
4649 const bool hasDoubleTicks = sl->tickPosition == QStyleOptionSlider::TicksBothSides;
4650 const bool drawKnob = sl->subControls & SC_SliderHandle;
4651 const bool drawBar = sl->subControls & SC_SliderGroove;
4652 const bool drawTicks = sl->subControls & SC_SliderTickmarks;
4653 const bool isPressed = sl->state & State_Sunken;
4654
4655 CGPoint pressPoint;
4656 if (isPressed && drawKnob) {
4657 const CGRect knobRect = [slider.cell knobRectFlipped:slider.isFlipped];
4658 pressPoint.x = CGRectGetMidX(knobRect);
4659 pressPoint.y = CGRectGetMidY(knobRect);
4660 [slider.cell startTrackingAt:pressPoint inView:slider];
4661 }
4662
4663 d->drawNSViewInRect(slider, opt->rect, p, ^(CGContextRef, const CGRect &) {
4664 // Note that we don't support drawing the slider upside down. When this
4665 // is needed, simply set scale = -1 on the QML control / style item instead.
4666 NSSliderCell *cell = slider.cell;
4667
4668 if (drawBar) {
4669 const CGRect barRect = [cell barRectFlipped:slider.isFlipped];
4670 // "flipped" will only make a difference when NSSliderCell is vertical. And then
4671 // flipped means fill the groove from bottom-to-top instead of top-to-bottom.
4672 // Bottom-to-top is QSlider's normal mode, which means that we always need to flip
4673 // in vertical mode. (In case NSSlider can also be flipped horizontally in the future,
4674 // we stay on the safe side, and only flip when in vertical mode).
4675 [cell drawBarInside:barRect flipped:!isHorizontal];
4676 }
4677
4678 if (drawBar && hasTicks && drawTicks) {
4679 if (!hasDoubleTicks) {
4680 [cell drawTickMarks];
4681 } else {
4682 if (sl->orientation == Qt::Horizontal) {
4683 slider.tickMarkPosition = NSTickMarkPositionAbove;
4684 [slider layoutSubtreeIfNeeded];
4685 [cell drawTickMarks];
4686 slider.tickMarkPosition = NSTickMarkPositionBelow;
4687 [slider layoutSubtreeIfNeeded];
4688 [cell drawTickMarks];
4689 } else {
4690 slider.tickMarkPosition = NSTickMarkPositionLeading;
4691 [slider layoutSubtreeIfNeeded];
4692 [cell drawTickMarks];
4693 slider.tickMarkPosition = NSTickMarkPositionTrailing;
4694 [slider layoutSubtreeIfNeeded];
4695 [cell drawTickMarks];
4696 }
4697 }
4698 }
4699
4700 if (drawKnob)
4701 [cell drawKnob];
4702 });
4703
4704 if (isPressed && drawKnob)
4705 [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO];
4706 }
4707 break;
4708 case CC_SpinBox:
4709 if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
4710 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
4711 const auto lineEditRect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField);
4712 QStyleOptionFrame frame;
4713 static_cast<QStyleOption &>(frame) = *opt;
4714 frame.rect = lineEditRect;
4715 frame.state |= State_Sunken;
4716 frame.lineWidth = 1;
4717 frame.midLineWidth = 0;
4718 frame.features = QStyleOptionFrame::None;
4719 frame.frameShape = QStyleOptionFrame::Box;
4720 drawPrimitive(PE_FrameLineEdit, &frame, p);
4721 }
4722 if (sb->subControls & (SC_SpinBoxUp | SC_SpinBoxDown)) {
4723 const QRect updown = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp)
4724 | proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown);
4725
4726 d->setupNSGraphicsContext(cg, NO);
4727
4728 const auto aquaSize = d->effectiveAquaSizeConstrain(opt);
4729 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize);
4730 NSStepperCell *cell = static_cast<NSStepperCell *>(d->cocoaCell(cw));
4731 cell.enabled = (sb->state & State_Enabled);
4732 const auto controlSize = cell.controlSize;
4733 if (qt_apple_runningWithLiquidGlass())
4734 cell.controlSize = NSControlSizeMini;
4735
4736 const CGRect newRect = [cell drawingRectForBounds:updown.toCGRect()];
4737
4738 const bool upPressed = sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken);
4739 const bool downPressed = sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken);
4740 const CGFloat x = CGRectGetMidX(newRect);
4741 const CGFloat y = upPressed ? -3 : 3; // Weird coordinate shift going on. Verified with Hopper
4742 const CGPoint pressPoint = CGPointMake(x, y);
4743 // Pretend we're pressing the mouse on the right button. Unfortunately, NSStepperCell has no
4744 // API to highlight a specific button. The highlighted property works only on the down button.
4745 if (upPressed || downPressed)
4746 [cell startTrackingAt:pressPoint inView:d->backingStoreNSView];
4747
4748 [cell drawWithFrame:newRect inView:d->backingStoreNSView];
4749
4750 if (upPressed || downPressed)
4751 [cell stopTracking:pressPoint at:pressPoint inView:d->backingStoreNSView mouseIsUp:NO];
4752
4753 d->restoreNSGraphicsContext(cg);
4754 if (qt_apple_runningWithLiquidGlass())
4755 cell.controlSize = controlSize;
4756 }
4757 }
4758 break;
4759 case CC_ComboBox:
4760 if (const auto *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
4761 const bool isEnabled = combo->state & State_Enabled;
4762 const bool isPressed = combo->state & State_Sunken;
4763
4764 const auto ct = cocoaControlType(combo);
4765 const auto cs = d->effectiveAquaSizeConstrain(combo);
4766 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
4767 auto *cc = static_cast<NSControl *>(d->cocoaControl(cw));
4768 cc.enabled = isEnabled;
4769 QRectF frameRect = cw.adjustedControlFrame(combo->rect);;
4770 if (cw.type == QMacStylePrivate::Button_PopupButton) {
4771 // Non-editable QComboBox
4772 auto *pb = static_cast<NSPopUpButton *>(cc);
4773 // FIXME Old offsets. Try to move to adjustedControlFrame()
4774 if (cw.size == QStyleHelper::SizeSmall) {
4775 frameRect = frameRect.translated(0, 1);
4776 } else if (cw.size == QStyleHelper::SizeMini) {
4777 // Same 0.5 pt misalignment as AppKit and fit the focus ring
4778 frameRect = frameRect.translated(2, -0.5);
4779 }
4780 pb.frame = frameRect.toCGRect();
4781 [pb highlight:isPressed];
4782 d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef, const CGRect &r) {
4783 QMacAutoReleasePool pool;
4784 [pb.cell drawBezelWithFrame:r inView:pb.superview];
4785 });
4786 } else if (cw.type == QMacStylePrivate::ComboBox) {
4787 // Editable QComboBox
4788 auto *cb = static_cast<NSComboBox *>(cc);
4789 const auto frameRect = cw.adjustedControlFrame(combo->rect);
4790 cb.frame = frameRect.toCGRect();
4791
4792 // This API was requested to Apple in rdar #36197888. We know it's safe to use up to macOS 10.13.3
4793 if (NSButtonCell *cell = static_cast<NSButtonCell *>([cc.cell qt_valueForPrivateKey:@"_buttonCell"])) {
4794 cell.highlighted = isPressed;
4795 } else {
4796 // TODO Render to pixmap and darken the button manually
4797 }
4798
4799 d->drawNSViewInRect(cb, frameRect, p, ^(CGContextRef, const CGRect &r) {
4800 // FIXME This is usually drawn in the control's superview, but we wouldn't get inactive look in this case
4801 QMacAutoReleasePool pool;
4802 [cb.cell drawWithFrame:r inView:cb];
4803 });
4804 }
4805 }
4806 break;
4807 case CC_SearchField:
4808 if (const auto *sf = qstyleoption_cast<const QStyleOptionSearchField *>(opt)) {
4809 const bool isEnabled = sf->state & State_Enabled;
4810
4811 const auto cs = d->effectiveAquaSizeConstrain(sf);
4813 auto *searchField = static_cast<NSSearchField *>(d->cocoaControl(cw));
4814 auto *cell = static_cast<NSSearchFieldCell *>(searchField.cell);
4815
4816 searchField.enabled = isEnabled;
4817
4818 // QTBUG-141776
4819 // macOS 26 (Tahoe) changed NSSearchFieldCell: the magnifying glass icon is taller.
4820 // Drawing it at the button’s full rect causes the top to be clipped by the bezel,
4821 // though the clear icon remains fine. To avoid this, on 26.0+ we render the search
4822 // icon at a fixed, smaller size to prevent upscaling and eliminate clipping.
4823 #if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(26))
4824 if (__builtin_available(macOS 26, *)) {
4825 NSButtonCell *btn = cell.searchButtonCell;
4826 NSImageSymbolConfiguration *imgCfg =
4827 [NSImageSymbolConfiguration configurationWithPointSize:11
4828 weight:NSFontWeightMedium
4829 scale:NSImageSymbolScaleMedium];
4830 btn.image = [btn.image imageWithSymbolConfiguration:imgCfg];
4831 [btn.image setTemplate:YES];
4832 btn.imageScaling = NSImageScaleNone;
4833 }
4834 #endif
4835
4836 QRectF frameRect = cw.adjustedControlFrame(sf->rect);
4837
4838 #if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(26))
4839 if (__builtin_available(macOS 26, *)) {
4840 const auto oneDevicePx = 1.0 / p->device()->devicePixelRatioF();
4841 frameRect = frameRect.adjusted(+oneDevicePx, -oneDevicePx, -oneDevicePx, +oneDevicePx);
4842 }
4843 #endif
4844
4845 searchField.frame = frameRect.toCGRect();
4846
4847 if (sf->subControls == QStyle::SC_SearchFieldSearch) {
4848 // Draw only the search icon
4849 CGRect rect = [cell searchButtonRectForBounds:searchField.bounds];
4850 [cell drawWithFrame:rect inView:searchField];
4851 } else if (sf->subControls == QStyle::SC_SearchFieldClear) {
4852 // Draw only the clear icon
4853 CGRect rect = [cell cancelButtonRectForBounds:searchField.bounds];
4854 [cell drawWithFrame:rect inView:searchField];
4855 } else {
4856 // Draw the frame
4857 [cell setStringValue:sf->text.toNSString()];
4858 d->drawNSViewInRect(searchField, frameRect, p, ^(CGContextRef, const CGRect &r) {
4859 [cell drawWithFrame:r inView:searchField];
4860 });
4861 }
4862 }
4863 break;
4864 case CC_TitleBar:
4865 if (const auto *titlebar = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
4866 const bool isActive = (titlebar->state & State_Active)
4867 && (titlebar->titleBarState & State_Active);
4868
4869 p->fillRect(opt->rect, Qt::transparent);
4870 p->setRenderHint(QPainter::Antialiasing);
4871 p->setClipRect(opt->rect, Qt::IntersectClip);
4872
4873 // FIXME A single drawPath() with 0-sized pen
4874 // doesn't look as good as this double fillPath().
4875 const auto outerFrameRect = QRectF(opt->rect.adjusted(0, 0, 0, opt->rect.height()));
4876 QPainterPath outerFramePath = d->windowPanelPath(outerFrameRect);
4877 p->fillPath(outerFramePath, opt->palette.dark());
4878
4879 const auto frameAdjust = 1.0 / p->device()->devicePixelRatioF();
4880 const auto innerFrameRect = outerFrameRect.adjusted(frameAdjust, frameAdjust, -frameAdjust, 0);
4881 QPainterPath innerFramePath = d->windowPanelPath(innerFrameRect);
4882 p->fillPath(innerFramePath, opt->palette.button());
4883
4884 if (titlebar->subControls & (SC_TitleBarCloseButton
4885 | SC_TitleBarMaxButton
4886 | SC_TitleBarMinButton
4887 | SC_TitleBarNormalButton)) {
4888 const bool isHovered = (titlebar->state & State_MouseOver);
4889 static const SubControl buttons[] = {
4890 SC_TitleBarCloseButton, SC_TitleBarMinButton, SC_TitleBarMaxButton
4891 };
4892 for (const auto sc : buttons) {
4893 const auto ct = d->windowButtonCocoaControl(sc);
4894 const auto cw = QMacStylePrivate::CocoaControl(ct, QStyleHelper::SizeLarge);
4895 auto *wb = static_cast<NSButton *>(d->cocoaControl(cw));
4896 wb.enabled = (sc & titlebar->subControls) && isActive;
4897 [wb highlight:(titlebar->state & State_Sunken) && (sc & titlebar->activeSubControls)];
4898 Q_UNUSED(isHovered); // FIXME No public API for this
4899
4900 const auto buttonRect = proxy()->subControlRect(CC_TitleBar, titlebar, sc);
4901 d->drawNSViewInRect(wb, buttonRect, p, ^(CGContextRef, const CGRect &rect) {
4902 QMacAutoReleasePool pool;
4903 auto *wbCell = static_cast<NSButtonCell *>(wb.cell);
4904 [wbCell drawWithFrame:rect inView:wb];
4905 });
4906 }
4907 }
4908
4909 if (titlebar->subControls & SC_TitleBarLabel) {
4910 const auto tr = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarLabel);
4911 if (!titlebar->icon.isNull()) {
4912 const auto iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
4913 const auto iconSize = QSize(iconExtent, iconExtent);
4914 const auto iconPos = tr.x() - titlebar->icon.actualSize(iconSize).width() - qRound(titleBarIconTitleSpacing);
4915 // Only render the icon if it'll be fully visible
4916 if (iconPos < tr.right() - titleBarIconTitleSpacing)
4917 p->drawPixmap(iconPos, tr.y(),
4918 titlebar->icon.pixmap(iconSize,
4919 opt->window->devicePixelRatio(),
4920 QIcon::Normal));
4921 }
4922
4923 if (!titlebar->text.isEmpty())
4924 drawItemText(p, tr, Qt::AlignCenter, opt->palette, isActive, titlebar->text, QPalette::Text);
4925 }
4926 }
4927 break;
4928 case CC_GroupBox:
4929 if (const QStyleOptionGroupBox *gb
4930 = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) {
4931
4932 QStyleOptionGroupBox groupBox(*gb);
4933 const bool flat = groupBox.features & QStyleOptionFrame::Flat;
4934 if (!flat)
4935 groupBox.state |= QStyle::State_Mini; // Force mini-sized checkbox to go with small-sized label
4936 else
4937 groupBox.subControls = groupBox.subControls & ~SC_GroupBoxFrame; // We don't like frames and ugly lines
4938
4939// const bool didSetFont = widget && widget->testAttribute(Qt::WA_SetFont);
4940// const bool didModifySubControls = !didSetFont && QApplication::desktopSettingsAware();
4941// if (didModifySubControls)
4942// groupBox.subControls = groupBox.subControls & ~SC_GroupBoxLabel;
4943 QCommonStyle::drawComplexControl(cc, &groupBox, p);
4944// if (didModifySubControls) {
4945// const QRect rect = proxy()->subControlRect(CC_GroupBox, &groupBox, SC_GroupBoxLabel);
4946// const bool rtl = groupBox.direction == Qt::RightToLeft;
4947// const int alignment = Qt::TextHideMnemonic | (rtl ? Qt::AlignRight : Qt::AlignLeft);
4948// const QFont savedFont = p->font();
4949// if (!flat)
4950// p->setFont(d->smallSystemFont);
4951// proxy()->drawItemText(p, rect, alignment, groupBox.palette, groupBox.state & State_Enabled, groupBox.text, QPalette::WindowText);
4952// if (!flat)
4953// p->setFont(savedFont);
4954// }
4955 }
4956 break;
4957 case CC_ToolButton:
4958 if (const QStyleOptionToolButton *tb
4959 = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
4960#ifndef QT_NO_ACCESSIBILITY
4961 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar)) {
4962 if (tb->subControls & SC_ToolButtonMenu) {
4963 QStyleOption arrowOpt = *tb;
4964 arrowOpt.rect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu);
4965 arrowOpt.rect.setY(arrowOpt.rect.y() + arrowOpt.rect.height() / 2);
4966 arrowOpt.rect.setHeight(arrowOpt.rect.height() / 2);
4967 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p);
4968 } else if ((tb->features & QStyleOptionToolButton::HasMenu)
4969 && (tb->toolButtonStyle != Qt::ToolButtonTextOnly && !tb->icon.isNull())) {
4970 d->drawToolbarButtonArrow(tb, p);
4971 }
4972 if (tb->state & State_On) {
4973 NSView *view = reinterpret_cast<NSView *>(opt->window->winId());
4974 bool isKey = false;
4975 if (view)
4976 isKey = [view.window isKeyWindow];
4977
4978 QBrush brush(brushForToolButton(isKey));
4979 QPainterPath path;
4980 path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4);
4981 p->setRenderHint(QPainter::Antialiasing);
4982 p->fillPath(path, brush);
4983 }
4984 proxy()->drawControl(CE_ToolButtonLabel, opt, p);
4985 } else
4986#endif // QT_NO_ACCESSIBILITY
4987 {
4988 auto bflags = tb->state;
4989 if (tb->subControls & SC_ToolButton)
4990 bflags |= State_Sunken;
4991 auto mflags = tb->state;
4992 if (tb->subControls & SC_ToolButtonMenu)
4993 mflags |= State_Sunken;
4994
4995 if (tb->subControls & SC_ToolButton) {
4996 if (bflags & (State_Sunken | State_On | State_Raised)) {
4997 const bool isEnabled = tb->state & State_Enabled;
4998 const bool isPressed = tb->state & State_Sunken;
4999 const bool isHighlighted = (tb->state & State_Active) && (tb->state & State_On);
5001 const auto cs = d->effectiveAquaSizeConstrain(opt);
5002 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5003 auto *pb = static_cast<NSButton *>(d->cocoaControl(cw));
5004 pb.bezelStyle = NSBezelStyleShadowlessSquare; // TODO Use NSTexturedRoundedBezelStyle in the future.
5005 pb.frame = opt->rect.toCGRect();
5006 pb.buttonType = NSButtonTypePushOnPushOff;
5007 pb.enabled = isEnabled;
5008 [pb highlight:isPressed];
5009 pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff;
5010 const auto buttonRect = proxy()->subControlRect(cc, tb, SC_ToolButton);
5011 d->drawNSViewInRect(pb, buttonRect, p, ^(CGContextRef, const CGRect &rect) {
5012 QMacAutoReleasePool pool;
5013 [pb.cell drawBezelWithFrame:rect inView:pb];
5014 });
5015 }
5016 }
5017
5018 if (tb->subControls & SC_ToolButtonMenu) {
5019 const auto menuRect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu);
5020 QStyleOption arrowOpt = *tb;
5021 arrowOpt.rect = QRect(menuRect.x() + ((menuRect.width() - toolButtonArrowSize) / 2),
5022 menuRect.height() - (toolButtonArrowSize + toolButtonArrowMargin),
5025 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p);
5026 } else if (tb->features & QStyleOptionToolButton::HasMenu) {
5027 d->drawToolbarButtonArrow(tb, p);
5028 }
5029 QRect buttonRect = proxy()->subControlRect(CC_ToolButton, tb, SC_ToolButton);
5030 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt);
5031 QStyleOptionToolButton label = *tb;
5032 label.rect = buttonRect.adjusted(fw, fw, -fw, -fw);
5033 proxy()->drawControl(CE_ToolButtonLabel, &label, p);
5034 }
5035 }
5036 break;
5037 case CC_Dial:
5038 if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt))
5039 QStyleHelper::drawDial(dial, p);
5040 break;
5041 default:
5042 QCommonStyle::drawComplexControl(cc, opt, p);
5043 break;
5044 }
5045}
5046
5047QStyle::SubControl QMacStyle::hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt) const
5048{
5049 Q_D(const QMacStyle);
5050
5051 SubControl sc = QStyle::SC_None;
5052
5053 switch (cc) {
5054 case CC_ComboBox:
5055 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
5056 sc = QCommonStyle::hitTestComplexControl(cc, cmb, pt);
5057 if (!cmb->editable && sc != QStyle::SC_None)
5058 sc = SC_ComboBoxArrow; // A bit of a lie, but what we want
5059 }
5060 break;
5061 case CC_Slider:
5062 if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
5063 if (!sl->rect.contains(pt))
5064 break;
5065
5066 const bool hasTicks = sl->tickPosition != QStyleOptionSlider::NoTicks;
5067 const bool isHorizontal = sl->orientation == Qt::Horizontal;
5069 const auto cs = d->effectiveAquaSizeConstrain(opt);
5070 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5071 auto *slider = static_cast<NSSlider *>(d->cocoaControl(cw));
5072 if (!setupSlider(slider, sl))
5073 break;
5074
5075 NSSliderCell *cell = slider.cell;
5076 const auto barRect = QRectF::fromCGRect([cell barRectFlipped:slider.isFlipped]);
5077 const auto knobRect = QRectF::fromCGRect([cell knobRectFlipped:slider.isFlipped]);
5078 if (knobRect.contains(pt)) {
5079 sc = SC_SliderHandle;
5080 } else if (barRect.contains(pt)) {
5081 sc = SC_SliderGroove;
5082 } else if (hasTicks) {
5083 sc = SC_SliderTickmarks;
5084 }
5085 }
5086 break;
5087 case CC_ScrollBar:
5088 if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
5089 if (!sb->rect.contains(pt)) {
5090 sc = SC_None;
5091 break;
5092 }
5093
5094 const bool isHorizontal = sb->orientation == Qt::Horizontal;
5096 const auto cs = d->effectiveAquaSizeConstrain(opt);
5097 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5098 auto *scroller = static_cast<NSScroller *>(d->cocoaControl(cw));
5099 if (!setupScroller(scroller, sb)) {
5100 sc = SC_None;
5101 break;
5102 }
5103
5104 // Since -[NSScroller testPart:] doesn't want to cooperate, we do it the
5105 // straightforward way. In any case, macOS doesn't return line-sized changes
5106 // with NSScroller since 10.7, according to the aforementioned method's doc.
5107 const auto knobRect = QRectF::fromCGRect([scroller rectForPart:NSScrollerKnob]);
5108 if (isHorizontal) {
5109 const bool isReverse = sb->direction == Qt::RightToLeft;
5110 if (pt.x() < knobRect.left())
5111 sc = isReverse ? SC_ScrollBarAddPage : SC_ScrollBarSubPage;
5112 else if (pt.x() > knobRect.right())
5113 sc = isReverse ? SC_ScrollBarSubPage : SC_ScrollBarAddPage;
5114 else
5115 sc = SC_ScrollBarSlider;
5116 } else {
5117 if (pt.y() < knobRect.top())
5118 sc = SC_ScrollBarSubPage;
5119 else if (pt.y() > knobRect.bottom())
5120 sc = SC_ScrollBarAddPage;
5121 else
5122 sc = SC_ScrollBarSlider;
5123 }
5124 }
5125 break;
5126 case CC_SearchField:
5127 if (const auto *sf = qstyleoption_cast<const QStyleOptionSearchField *>(opt)) {
5128 if (!sf->rect.contains(pt))
5129 break;
5130
5131 const auto cs = d->effectiveAquaSizeConstrain(sf);
5133 auto *searchField = static_cast<NSSearchField *>(d->cocoaControl(cw));
5134 searchField.frame = cw.adjustedControlFrame(sf->rect).toCGRect();
5135
5136 auto *cell = static_cast<NSSearchFieldCell *>(searchField.cell);
5137 const CGRect bounds = searchField.bounds;
5138
5139 const QRectF cancelRect = QRectF::fromCGRect([cell cancelButtonRectForBounds:bounds]);
5140 const QRectF searchIconRect = QRectF::fromCGRect([cell searchButtonRectForBounds:bounds]);
5141 const QRectF textFieldRect = QRectF::fromCGRect([cell searchTextRectForBounds:bounds]);
5142
5143 const QPointF localPt = pt - sf->rect.topLeft();
5144
5145 if (cancelRect.contains(localPt))
5146 sc = SC_SearchFieldClear;
5147 else if (searchIconRect.contains(localPt))
5148 sc = SC_SearchFieldSearch;
5149 else if (textFieldRect.contains(localPt))
5150 sc = SC_SearchFieldEditField;
5151 else
5152 sc = SC_SearchFieldPopup;
5153
5154 break;
5155 }
5156 break;
5157 default:
5158 sc = QCommonStyle::hitTestComplexControl(cc, opt, pt);
5159 break;
5160 }
5161 return sc;
5162}
5163
5164QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc) const
5165{
5166 Q_D(const QMacStyle);
5167
5168 QRect ret;
5169
5170 switch (cc) {
5171 case CC_ScrollBar:
5172 if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
5173 const bool isHorizontal = sb->orientation == Qt::Horizontal;
5174 const bool isReverseHorizontal = isHorizontal && (sb->direction == Qt::RightToLeft);
5175
5176 NSScrollerPart part = NSScrollerNoPart;
5177 if (sc == SC_ScrollBarSlider) {
5178 part = NSScrollerKnob;
5179 } else if (sc == SC_ScrollBarGroove) {
5180 part = NSScrollerKnobSlot;
5181 } else if (sc == SC_ScrollBarSubPage || sc == SC_ScrollBarAddPage) {
5182 if ((!isReverseHorizontal && sc == SC_ScrollBarSubPage)
5183 || (isReverseHorizontal && sc == SC_ScrollBarAddPage))
5184 part = NSScrollerDecrementPage;
5185 else
5186 part = NSScrollerIncrementPage;
5187 }
5188 // And nothing else since 10.7
5189
5190 if (part != NSScrollerNoPart) {
5192 const auto cs = d->effectiveAquaSizeConstrain(opt);
5193 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5194 auto *scroller = static_cast<NSScroller *>(d->cocoaControl(cw));
5195 if (setupScroller(scroller, sb))
5196 ret = QRectF::fromCGRect([scroller rectForPart:part]).toRect();
5197 }
5198 }
5199 break;
5200 case CC_Slider:
5201 if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
5202 const bool hasTicks = sl->tickPosition != QStyleOptionSlider::NoTicks;
5203 const bool isHorizontal = sl->orientation == Qt::Horizontal;
5205 const auto cs = d->effectiveAquaSizeConstrain(opt);
5206 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5207 auto *slider = static_cast<NSSlider *>(d->cocoaControl(cw));
5208 if (!setupSlider(slider, sl))
5209 break;
5210
5211 NSSliderCell *cell = slider.cell;
5212 if (sc == SC_SliderHandle) {
5213 ret = QRectF::fromCGRect([cell knobRectFlipped:slider.isFlipped]).toRect();
5214 } else if (sc == SC_SliderGroove) {
5215 ret = QRectF::fromCGRect([cell barRectFlipped:slider.isFlipped]).toRect();
5216 } else if (hasTicks && sc == SC_SliderTickmarks) {
5217 const auto tickMarkRect = QRectF::fromCGRect([cell rectOfTickMarkAtIndex:0]);
5218 if (isHorizontal)
5219 ret = QRect(sl->rect.left(), tickMarkRect.top(), sl->rect.width(), tickMarkRect.height());
5220 else
5221 ret = QRect(tickMarkRect.left(), sl->rect.top(), tickMarkRect.width(), sl->rect.height());
5222 }
5223
5224// if (sl->upsideDown) {
5225// if isHorizontal) {
5226// } else {
5227// }
5228// }
5229 }
5230 break;
5231 case CC_TitleBar:
5232 if (const auto *titlebar = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
5233 // The title bar layout is as follows: close, min, zoom, icon, title
5234 // [ x _ + @ Window Title ]
5235 // Center the icon and title until it starts to overlap with the buttons.
5236 // The icon doesn't count towards SC_TitleBarLabel, but it's still rendered
5237 // next to the title text. See drawComplexControl().
5238 if (sc == SC_TitleBarLabel) {
5239 qreal labelWidth = titlebar->fontMetrics.horizontalAdvance(titlebar->text) + 1; // FIXME Rounding error?
5240 qreal labelHeight = titlebar->fontMetrics.height();
5241
5242 const auto lastButtonRect = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarMaxButton);
5243 qreal controlsSpacing = lastButtonRect.right() + titleBarButtonSpacing;
5244 if (!titlebar->icon.isNull()) {
5245 const auto iconSize = proxy()->pixelMetric(PM_SmallIconSize);
5246 const auto actualIconSize = titlebar->icon.actualSize(QSize(iconSize, iconSize)).width();;
5247 controlsSpacing += actualIconSize + titleBarIconTitleSpacing;
5248 }
5249
5250 const qreal labelPos = qMax(controlsSpacing, (opt->rect.width() - labelWidth) / 2.0);
5251 labelWidth = qMin(labelWidth, opt->rect.width() - (labelPos + titleBarTitleRightMargin));
5252 ret = QRect(labelPos, (opt->rect.height() - labelHeight) / 2,
5253 labelWidth, labelHeight);
5254 } else {
5255 const auto currentButton = d->windowButtonCocoaControl(sc);
5256 if (currentButton == QMacStylePrivate::NoControl)
5257 break;
5258
5259 QPointF buttonPos = titlebar->rect.topLeft() + QPointF(titleBarButtonSpacing, 0);
5260 QSizeF buttonSize;
5261 for (int ct = QMacStylePrivate::Button_WindowClose; ct <= currentButton; ct++) {
5262 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::CocoaControlType(ct),
5263 QStyleHelper::SizeLarge);
5264 auto *wb = static_cast<NSButton *>(d->cocoaControl(cw));
5265 if (ct == currentButton)
5266 buttonSize = QSizeF::fromCGSize(wb.frame.size);
5267 else
5268 buttonPos.rx() += wb.frame.size.width + titleBarButtonSpacing;
5269 }
5270
5271 const auto vOffset = (opt->rect.height() - buttonSize.height()) / 2.0;
5272 ret = QRectF(buttonPos, buttonSize).translated(0, vOffset).toRect();
5273 }
5274 }
5275 break;
5276 case CC_ComboBox:
5277 if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
5278 const auto ct = cocoaControlType(combo);
5279 const auto cs = d->effectiveAquaSizeConstrain(combo);
5280 const auto cw = QMacStylePrivate::CocoaControl(ct, cs);
5281
5282 // Old widget path. Current not understood why it's needed:
5283 //const auto editRect = QMacStylePrivate::comboboxEditBounds(cw.adjustedControlFrame(combo->rect), cw);
5284
5285 // New path:
5286 QRectF editRect;
5287 switch (cs) {
5288 case QStyleHelper::SizeLarge:
5289 if (qt_apple_runningWithLiquidGlass())
5290 editRect = combo->rect.adjusted(15, 7, -25, -7);
5291 else
5292 editRect = combo->rect.adjusted(15, 7, -25, -9);
5293 break;
5294 case QStyleHelper::SizeSmall:
5295 if (combo->editable)
5296 editRect = combo->rect.adjusted(15, 6, -22, -9);
5297 else
5298 editRect = combo->rect.adjusted(15, 8, -22, -6);
5299 break;
5300 default:
5301 if (combo->editable)
5302 editRect = combo->rect.adjusted(15, 6, -20, -7);
5303 else
5304 editRect = combo->rect.adjusted(15, 5, -22, -6);
5305 break;
5306 }
5307
5308 switch (sc) {
5309 case SC_ComboBoxEditField:{
5310 ret = editRect.toAlignedRect();
5311 break; }
5312 case SC_ComboBoxArrow:{
5313 ret = editRect.toAlignedRect();
5314 ret.setX(ret.x() + ret.width());
5315 ret.setWidth(combo->rect.right() - ret.right());
5316 break; }
5317 case SC_ComboBoxListBoxPopup:{
5318 if (combo->editable) {
5319 const CGRect inner = QMacStylePrivate::comboboxInnerBounds(combo->rect.toCGRect(), cw);
5320 const int comboTop = combo->rect.top();
5321 ret = QRect(qRound(inner.origin.x),
5322 comboTop,
5323 qRound(inner.origin.x - combo->rect.left() + inner.size.width),
5324 editRect.bottom() - comboTop + 2);
5325 } else {
5326 ret = QRect(combo->rect.x() + 4 - 11,
5327 combo->rect.y() + 1,
5328 editRect.width() + 10 + 11,
5329 1);
5330 }
5331 break; }
5332 default:
5333 break;
5334 }
5335 }
5336 break;
5337 case CC_GroupBox:
5338 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) {
5339 bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
5340 const bool flat = groupBox->features & QStyleOptionFrame::Flat;
5341 bool hasNoText = !checkable && groupBox->text.isEmpty();
5342 switch (sc) {
5343 case SC_GroupBoxLabel:
5344 case SC_GroupBoxCheckBox: {
5345 // Cheat and use the smaller font if we need to
5346 const bool checkable = groupBox->subControls & SC_GroupBoxCheckBox;
5347 const bool fontIsSet = false;
5348// const bool fontIsSet = (widget && widget->testAttribute(Qt::WA_SetFont))
5349// || !QApplication::desktopSettingsAware();
5350 const int margin = flat || hasNoText ? 0 : 9;
5351 ret = groupBox->rect.adjusted(margin, 0, -margin, 0);
5352
5353 const QFontMetricsF fm = flat || fontIsSet ? QFontMetricsF(groupBox->fontMetrics) : QFontMetricsF(d->smallSystemFont);
5354 const QSizeF s = fm.size(Qt::AlignHCenter | Qt::AlignVCenter, qt_mac_removeMnemonics(groupBox->text), 0, nullptr);
5355 const int tw = qCeil(s.width());
5356 const int h = qCeil(fm.height());
5357 ret.setHeight(h);
5358
5359 QRect labelRect = alignedRect(groupBox->direction, groupBox->textAlignment,
5360 QSize(tw, h), ret);
5361 if (flat && checkable)
5362 labelRect.moveLeft(labelRect.left() + 4);
5363 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt);
5364 bool rtl = groupBox->direction == Qt::RightToLeft;
5365 if (sc == SC_GroupBoxLabel) {
5366 if (checkable) {
5367 int newSum = indicatorWidth + 1;
5368 int newLeft = labelRect.left() + (rtl ? -newSum : newSum);
5369 labelRect.moveLeft(newLeft);
5370 if (flat)
5371 labelRect.moveTop(labelRect.top() + 3);
5372 else
5373 labelRect.moveTop(labelRect.top() + 4);
5374 } else if (flat) {
5375 int newLeft = labelRect.left() - (rtl ? 3 : -3);
5376 labelRect.moveLeft(newLeft);
5377 labelRect.moveTop(labelRect.top() + 3);
5378 } else {
5379 int newLeft = labelRect.left() - (rtl ? 3 : 2);
5380 labelRect.moveLeft(newLeft);
5381 labelRect.moveTop(labelRect.top() + 4);
5382 }
5383 ret = labelRect;
5384 }
5385
5386 if (sc == SC_GroupBoxCheckBox) {
5387 int left = rtl ? labelRect.right() - indicatorWidth : labelRect.left() - 1;
5388 int top = flat ? ret.top() + 1 : ret.top() + 5;
5389 ret.setRect(left, top,
5390 indicatorWidth, proxy()->pixelMetric(PM_IndicatorHeight, opt));
5391 }
5392 break;
5393 }
5394 case SC_GroupBoxContents:
5395 case SC_GroupBoxFrame: {
5396 QFontMetrics fm = groupBox->fontMetrics;
5397 int yOffset = 3;
5398 if (!flat)
5399 yOffset = 5;
5400
5401 if (hasNoText)
5402 yOffset = -qCeil(QFontMetricsF(fm).height());
5403 ret = opt->rect.adjusted(0, qCeil(QFontMetricsF(fm).height()) + yOffset, 0, 0);
5404 if (sc == SC_GroupBoxContents) {
5405 if (flat)
5406 ret.adjust(3, -5, -3, -4); // guess too
5407 else
5408 ret.adjust(3, 3, -3, -4); // guess
5409 }
5410 }
5411 break;
5412 default:
5413 ret = QCommonStyle::subControlRect(cc, groupBox, sc);
5414 break;
5415 }
5416 }
5417 break;
5418 case CC_SpinBox:
5419 if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
5420 QStyleHelper::WidgetSizePolicy aquaSize = d->effectiveAquaSizeConstrain(spin);
5421 const auto fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin);
5422 int spinner_w;
5423 int spinner_h;
5424 int adjust_y;
5425 int spinBoxSep;
5426 switch (aquaSize) {
5427 case QStyleHelper::SizeLarge:
5428 spinner_w = 14;
5429 spinner_h = 24;
5430 adjust_y = -1;
5431 spinBoxSep = 2;
5432 break;
5433 case QStyleHelper::SizeSmall:
5434 spinner_w = 12;
5435 spinner_h = 20;
5436 adjust_y = -1;
5437 spinBoxSep = 2;
5438 break;
5439 case QStyleHelper::SizeMini:
5440 spinner_w = 10;
5441 spinner_h = 16;
5442 adjust_y = -1;
5443 spinBoxSep = 1;
5444 break;
5445 default:
5446 Q_UNREACHABLE();
5447 }
5448
5449 switch (sc) {
5450 case SC_SpinBoxUp:
5451 case SC_SpinBoxDown: {
5452 if (spin->buttonSymbols == QStyleOptionSpinBox::NoButtons)
5453 break;
5454
5455 const int y = fw;
5456 const int x = spin->rect.width() - spinner_w;
5457 ret.setRect(x + spin->rect.x(), y + spin->rect.y(), spinner_w, spinner_h);
5458
5459 const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize);
5460 NSStepperCell *cell = static_cast<NSStepperCell *>(d->cocoaCell(cw));
5461 const CGRect outRect = [cell drawingRectForBounds:ret.toCGRect()];
5462 ret = QRectF::fromCGRect(outRect).toRect();
5463
5464 switch (sc) {
5465 case SC_SpinBoxUp:
5466 ret.setHeight(ret.height() / 2);
5467 break;
5468 case SC_SpinBoxDown:
5469 ret.setY(ret.y() + ret.height() / 2);
5470 break;
5471 default:
5472 Q_ASSERT(0);
5473 break;
5474 }
5475 // The buttons are drawn with a top-margin (for some reason) into
5476 // the rect. So undo that margin here:
5477 ret.translate(0, adjust_y);
5478 ret = visualRect(spin->direction, spin->rect, ret);
5479 break;
5480 }
5481 case SC_SpinBoxEditField:
5482 ret = spin->rect.adjusted(fw, fw, -fw, -fw);
5483 if (spin->subControls & SC_SpinBoxUp || spin->subControls & SC_SpinBoxDown) {
5484 ret.setWidth(spin->rect.width() - spinBoxSep - spinner_w);
5485 ret = visualRect(spin->direction, spin->rect, ret);
5486 }
5487 break;
5488 default:
5489 ret = QCommonStyle::subControlRect(cc, spin, sc);
5490 break;
5491 }
5492 }
5493 break;
5494 case CC_ToolButton:
5495 ret = QCommonStyle::subControlRect(cc, opt, sc);
5496 if (sc == SC_ToolButtonMenu) {
5497#ifndef QT_NO_ACCESSIBILITY
5498 if (QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ToolBar))
5499 ret.adjust(-toolButtonArrowMargin, 0, 0, 0);
5500#endif
5501 ret.adjust(-1, 0, 0, 0);
5502 }
5503 break;
5504 case CC_SearchField:
5505 if (const QStyleOptionSearchField *sf = qstyleoption_cast<const QStyleOptionSearchField *>(opt)) {
5506 const auto cs = d->effectiveAquaSizeConstrain(sf);
5508
5509 QRectF editRect;
5510 switch (cs) {
5511 case QStyleHelper::SizeLarge:
5512 editRect = sf->rect.adjusted(16, 0, -22, 0);
5513 break;
5514 case QStyleHelper::SizeSmall:
5515 editRect = sf->rect.adjusted(16, 5, -22, -7);
5516 break;
5517 default:
5518 editRect = sf->rect.adjusted(16, 5, -18, -7);
5519 break;
5520 }
5521
5522 auto *searchField = static_cast<NSSearchField *>(d->cocoaControl(cw));
5523 auto *cell = static_cast<NSSearchFieldCell *>(searchField.cell);
5524 const CGRect bounds = searchField.bounds;
5525
5526 switch (sc) {
5527 case SC_SearchFieldEditField:{
5528 ret = editRect.toAlignedRect();
5530 break;
5531 }
5532 case SC_SearchFieldClear: {
5533 const CGRect r = [cell cancelButtonRectForBounds:bounds];
5534 ret = QRectF::fromCGRect(r).toRect();
5535 ret.translate(0, -1);
5536 ret = visualRect(sf->direction, sf->rect, ret);
5537 ret.adjust(-3, -3, 3, 3);
5538 break;
5539 }
5540 case SC_SearchFieldSearch: {
5541 const CGRect r = [cell searchButtonRectForBounds:bounds];
5542 ret = QRectF::fromCGRect(r).toRect();
5543 ret.translate(0, -1);
5544 ret = visualRect(sf->direction, sf->rect, ret);
5545 ret.adjust(-3, -3, 3, 3);
5546 break;
5547 }
5548 case SC_SearchFieldPopup: {
5549 const CGRect inner = QMacStylePrivate::comboboxInnerBounds(sf->rect.toCGRect(), cw);
5550 const int searchTop = sf->rect.top();
5551 ret = QRect(qRound(inner.origin.x),
5552 searchTop,
5553 qRound(inner.origin.x - sf->rect.left() + inner.size.width),
5554 editRect.bottom() - searchTop + 2);
5555 break;
5556 }
5557 default:
5558 break;
5559 }
5560 }
5561 break;
5562 default:
5563 ret = QCommonStyle::subControlRect(cc, opt, sc);
5564 break;
5565 }
5566 return ret;
5567}
5568
5569QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &csz) const
5570{
5571 Q_D(const QMacStyle);
5572
5573 QSize sz(csz);
5574 bool useAquaGuideline = true;
5575
5576 switch (ct) {
5577 case CT_SpinBox:
5578 if (const QStyleOptionSpinBox *vopt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
5579 if (vopt->subControls == SC_SpinBoxFrame) {
5580 const QSize minimumSize(20, 24);
5581 if (sz.width() < minimumSize.width())
5582 sz.setWidth(minimumSize.width());
5583 if (sz.height() < minimumSize.height())
5584 sz.setHeight(minimumSize.height());
5585 } else {
5586 const QSize buttonSize = proxy()->subControlRect(CC_SpinBox, vopt, SC_SpinBoxUp).size();
5587 const int upAndDownTogetherHeight = buttonSize.height() * 2;
5588 sz += QSize(buttonSize.width(), upAndDownTogetherHeight);
5589 }
5590 }
5591 break;
5592 case QStyle::CT_TabWidget:
5593 // the size between the pane and the "contentsRect" (+4,+4)
5594 // (the "contentsRect" is on the inside of the pane)
5595 sz = QCommonStyle::sizeFromContents(ct, opt, csz);
5596 /**
5597 This is supposed to show the relationship between the tabBar and
5598 the stack widget of a QTabWidget.
5599 Unfortunately ascii is not a good way of representing graphics.....
5600 PS: The '=' line is the painted frame.
5601
5602 top ---+
5603 |
5604 |
5605 |
5606 | vvv just outside the painted frame is the "pane"
5607 - -|- - - - - - - - - - <-+
5608 TAB BAR +=====^============ | +2 pixels
5609 - - -|- - -|- - - - - - - <-+
5610 | | ^ ^^^ just inside the painted frame is the "contentsRect"
5611 | | |
5612 | overlap |
5613 | | |
5614 bottom ------+ <-+ +14 pixels
5615 |
5616 v
5617 ------------------------------ <- top of stack widget
5618
5619
5620 To summarize:
5621 * 2 is the distance between the pane and the contentsRect
5622 * The 14 and the 1's are the distance from the contentsRect to the stack widget.
5623 (same value as used in SE_TabWidgetTabContents)
5624 * overlap is how much the pane should overlap the tab bar
5625 */
5626 // then add the size between the stackwidget and the "contentsRect"
5627 if (const QStyleOptionTabWidgetFrame *twf
5628 = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
5629 QSize extra(0,0);
5630 const int overlap = pixelMetric(PM_TabBarBaseOverlap, opt);
5631 const int gapBetweenTabbarAndStackWidget = 2 + 14 - overlap;
5632
5633 const auto tabDirection = QMacStylePrivate::tabDirection(twf->shape);
5634 if (tabDirection == QMacStylePrivate::North
5635 || tabDirection == QMacStylePrivate::South) {
5636 extra = QSize(2, gapBetweenTabbarAndStackWidget + 1);
5637 } else {
5638 extra = QSize(gapBetweenTabbarAndStackWidget + 1, 2);
5639 }
5640 sz+= extra;
5641 }
5642 break;
5643 case QStyle::CT_TabBarTab:
5644 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
5645// const bool differentFont = (widget && widget->testAttribute(Qt::WA_SetFont))
5646// || !QApplication::desktopSettingsAware();
5647 const bool differentFont = false;
5648 const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape);
5649 const bool verticalTabs = tabDirection == QMacStylePrivate::East
5650 || tabDirection == QMacStylePrivate::West;
5651 if (verticalTabs)
5652 sz = sz.transposed();
5653
5654 int defaultTabHeight;
5655 const auto cs = d->effectiveAquaSizeConstrain(opt);
5656 switch (cs) {
5657 case QStyleHelper::SizeLarge:
5658 if (tab->documentMode)
5659 defaultTabHeight = 24;
5660 else
5661 defaultTabHeight = 21;
5662 break;
5663 case QStyleHelper::SizeSmall:
5664 defaultTabHeight = 18;
5665 break;
5666 case QStyleHelper::SizeMini:
5667 defaultTabHeight = 16;
5668 break;
5669 default:
5670 break;
5671 }
5672
5673 const bool widthSet = !differentFont && tab->icon.isNull();
5674 if (widthSet) {
5675 const auto textSize = opt->fontMetrics.size(Qt::TextShowMnemonic, tab->text);
5676 sz.rwidth() = textSize.width();
5677 sz.rheight() = qMax(defaultTabHeight, textSize.height());
5678 } else {
5679 sz.rheight() = qMax(defaultTabHeight, sz.height());
5680 }
5681 sz.rwidth() += proxy()->pixelMetric(PM_TabBarTabHSpace, tab);
5682
5683 if (verticalTabs)
5684 sz = sz.transposed();
5685
5686 int maxWidgetHeight = qMax(tab->leftButtonSize.height(), tab->rightButtonSize.height());
5687 int maxWidgetWidth = qMax(tab->leftButtonSize.width(), tab->rightButtonSize.width());
5688
5689 int widgetWidth = 0;
5690 int widgetHeight = 0;
5691 int padding = 0;
5692 if (tab->leftButtonSize.isValid()) {
5693 padding += 8;
5694 widgetWidth += tab->leftButtonSize.width();
5695 widgetHeight += tab->leftButtonSize.height();
5696 }
5697 if (tab->rightButtonSize.isValid()) {
5698 padding += 8;
5699 widgetWidth += tab->rightButtonSize.width();
5700 widgetHeight += tab->rightButtonSize.height();
5701 }
5702
5703 if (verticalTabs) {
5704 sz.setWidth(qMax(sz.width(), maxWidgetWidth));
5705 sz.setHeight(sz.height() + widgetHeight + padding);
5706 } else {
5707 if (widthSet)
5708 sz.setWidth(sz.width() + widgetWidth + padding);
5709 sz.setHeight(qMax(sz.height(), maxWidgetHeight));
5710 }
5711 }
5712 break;
5713 case CT_LineEdit:
5714 if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
5715 // Minimum size (with padding: 18x24)
5716 if (sz.width() < 10)
5717 sz.setWidth(10);
5718 if (sz.height() < 20)
5719 sz.setHeight(20);
5720
5721 // From using pixelTool with XCode/NSTextTextField
5722 int leftPadding = 4;
5723 int rightPadding = 4;
5724 int topPadding = 4;
5725 int bottomPadding = 0;
5726
5727 if (opt->state & QStyle::State_Small) {
5728 topPadding = 3;
5729 } else if (opt->state & QStyle::State_Mini) {
5730 topPadding = 2;
5731 }
5732
5733 sz.rwidth() += leftPadding + rightPadding;
5734 sz.rheight() += topPadding + bottomPadding;
5735 }
5736 break;
5737 case QStyle::CT_PushButton: {
5738 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt))
5739 if (btn->features & QStyleOptionButton::CommandLinkButton)
5740 return QCommonStyle::sizeFromContents(ct, opt, sz);
5741
5742 // By default, we fit the contents inside a normal rounded push button.
5743 // Do this by add enough space around the contents so that rounded
5744 // borders (including highlighting when active) will show.
5745 // TODO Use QFocusFrame and get rid of these horrors.
5746 QSize macsz;
5747 const auto controlSize = d->effectiveAquaSizeConstrain(opt, CT_PushButton, sz, &macsz);
5748 // FIXME See comment in CT_PushButton case in qt_aqua_get_known_size().
5749 if (macsz.width() != -1)
5750 sz.setWidth(macsz.width());
5751 else
5753 // All values as measured from HIThemeGetButtonBackgroundBounds()
5754 if (controlSize != QStyleHelper::SizeMini)
5755 sz.rwidth() += 12; // We like 12 over here.
5756 if (controlSize == QStyleHelper::SizeLarge && sz.height() > 16)
5757 sz.rheight() += pushButtonDefaultHeight[QStyleHelper::SizeLarge] - 16;
5758 else if (controlSize == QStyleHelper::SizeMini)
5759 sz.setHeight(24); // FIXME Our previous HITheme-based logic returned this.
5760 else
5761 sz.setHeight(pushButtonDefaultHeight[controlSize]);
5762 break;
5763 }
5764 case QStyle::CT_MenuItem:
5765 if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
5766 int maxpmw = mi->maxIconWidth;
5767 int w = sz.width();
5768 int h = sz.height();
5769
5770//#if QT_CONFIG(combobox)
5771// const QComboBox *comboBox = qobject_cast<const QComboBox *>(widget);
5772//#endif
5773
5774 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
5775 w = 10;
5777 } else {
5778 h = mi->fontMetrics.height() + 2;
5779 if (!mi->icon.isNull()) {
5780//#if QT_CONFIG(combobox)
5781// if (comboBox) {
5782// const QSize &iconSize = comboBox->iconSize();
5783// h = qMax(h, iconSize.height() + 4);
5784// maxpmw = qMax(maxpmw, iconSize.width());
5785// } else
5786//#endif
5787 {
5788 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
5789 h = qMax(h, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() + 4);
5790 }
5791 }
5792 }
5793 if (mi->text.contains(QLatin1Char('\t')))
5794 w += 12;
5795 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
5796 w += 35; // Not quite exactly as it seems to depend on other factors
5797 if (maxpmw)
5798 w += maxpmw + 6;
5799 // add space for a check. All items have place for a check too.
5800 w += 20;
5801// if (comboBox && comboBox->isVisible()) {
5802// QStyleOptionComboBox cmb;
5803// cmb.initFrom(comboBox);
5804// cmb.editable = false;
5805// cmb.subControls = QStyle::SC_ComboBoxEditField;
5806// cmb.activeSubControls = QStyle::SC_None;
5807// w = qMax(w, subControlRect(QStyle::CC_ComboBox, &cmb,
5808// QStyle::SC_ComboBoxEditField,
5809// comboBox).width());
5810// } else {
5811// w += 12;
5812 sz = QSize(w, h);
5813 } break;
5814 case CT_MenuBarItem:
5815 if (!sz.isEmpty())
5816 sz += QSize(12, 4); // Constants from QWindowsStyle
5817 break;
5818 case CT_ToolButton:
5819 sz.rwidth() += 10;
5820 sz.rheight() += 10;
5821 if (const auto *tb = qstyleoption_cast<const QStyleOptionToolButton *>(opt))
5822 if (tb->features & QStyleOptionToolButton::Menu)
5823 sz.rwidth() += toolButtonArrowMargin;
5824 return sz;
5825 case CT_ComboBox:
5826 if (const auto *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
5827 const int controlSize = getControlSize(opt);
5828
5829 // Set a sensible minimum width
5830 if (sz.width() < 10)
5831 sz.setWidth(10);
5832
5833 if (!cb->editable) {
5834 // Same as CT_PushButton, because we have to fit the focus
5835 // ring and a non-editable combo box is a NSPopUpButton.
5837
5838 if (controlSize == QStyleHelper::SizeLarge) {
5839 sz.rwidth() += 30;
5840 } else if (controlSize == QStyleHelper::SizeSmall) {
5841 sz.rwidth() += 26;
5842 } else {
5843 sz.rwidth() += 21;
5844 }
5845 } else {
5846 sz.rwidth() += 50; // FIXME Double check this
5847 }
5848
5849 // This should be enough to fit the focus ring
5850 if (controlSize == QStyleHelper::SizeMini)
5851 sz.setHeight(24); // FIXME Our previous HITheme-based logic returned this for CT_PushButton.
5852 else
5853 sz.setHeight(pushButtonDefaultHeight[controlSize]);
5854
5855 return sz;
5856 }
5857 break;
5858 case CT_SearchField:
5859 if (const QStyleOptionSearchField *sf = qstyleoption_cast<const QStyleOptionSearchField *>(opt)) {
5860 const QSize clearButton = proxy()->subControlRect(CC_SearchField, sf, SC_SearchFieldClear).size();
5861 const QSize searchButton = proxy()->subControlRect(CC_SearchField, sf, SC_SearchFieldSearch).size();
5862 if (sf->subControls == SC_SearchFieldFrame) {
5863 const int controlSize = getControlSize(opt);
5864 int padding;
5865 int iconSpacing;
5866
5867 if (controlSize == QStyleHelper::SizeLarge) {
5868 padding = 6;
5869 iconSpacing = 6;
5870 sz.setHeight(32);
5871 } else if (controlSize == QStyleHelper::SizeSmall) {
5872 padding = 5;
5873 iconSpacing = 5;
5874 sz.setHeight(28);
5875 } else {
5876 padding = 4;
5877 iconSpacing = 4;
5878 sz.setHeight(22);
5879 }
5880
5881 // minimum width
5882 if (sz.width() < 60)
5883 sz.setWidth(60);
5884
5885 const int totalIconsSize = clearButton.width() + searchButton.width() + (padding + iconSpacing) * 2;
5886 sz.rwidth() += totalIconsSize;
5887
5888 return sz;
5889 } else if (sf->subControls == SC_SearchFieldClear) {
5890 return clearButton;
5891 } else if (sf->subControls == SC_SearchFieldSearch) {
5892 return searchButton;
5893 }
5894 }
5895 break;
5896 case CT_Menu: {
5897 if (proxy() == this) {
5898 sz = csz;
5899 } else {
5900 QStyleHintReturnMask menuMask;
5901 QStyleOption myOption = *opt;
5902 myOption.rect.setSize(sz);
5903 if (proxy()->styleHint(SH_Menu_Mask, &myOption, &menuMask))
5904 sz = menuMask.region.boundingRect().size();
5905 }
5906 break; }
5907 case CT_HeaderSection:{
5908 const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt);
5909 sz = QCommonStyle::sizeFromContents(ct, opt, csz);
5910 if (header->text.contains(QLatin1Char('\n')))
5911 useAquaGuideline = false;
5912 break; }
5913 case CT_ScrollBar :
5914 // Make sure that the scroll bar is large enough to display the thumb indicator.
5915 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
5916 const int minimumWidth = 24;
5917 const int absoluteHeight = 14;
5918 if (slider->orientation == Qt::Horizontal) {
5919 sz = sz.expandedTo(QSize(minimumWidth, sz.height()));
5920 sz.setHeight(absoluteHeight);
5921 } else {
5922 sz = sz.expandedTo(QSize(sz.width(), minimumWidth));
5923 sz.setWidth(absoluteHeight);
5924 }
5925 }
5926 break;
5927 case CT_ItemViewItem:
5928 if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
5929 sz = QCommonStyle::sizeFromContents(ct, vopt, csz);
5930 sz.setHeight(sz.height() + 2);
5931 }
5932 break;
5933 default:
5934 sz = QCommonStyle::sizeFromContents(ct, opt, csz);
5935 }
5936
5937 if (useAquaGuideline && ct != CT_PushButton) {
5938 // TODO Probably going away at some point
5939 QSize macsz;
5940 if (d->aquaSizeConstrain(opt, ct, sz, &macsz) != QStyleHelper::SizeDefault) {
5941 if (macsz.width() != -1)
5942 sz.setWidth(macsz.width());
5943 if (macsz.height() != -1)
5944 sz.setHeight(macsz.height());
5945 }
5946 }
5947
5948 // The sizes that Carbon and the guidelines gives us excludes the focus frame.
5949 // We compensate for this by adding some extra space here to make room for the frame when drawing:
5950 if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt)){
5951 if (combo->editable) {
5952 const auto widgetSize = d->aquaSizeConstrain(opt);
5955 cw.size = widgetSize;
5956 const CGRect diffRect = QMacStylePrivate::comboboxInnerBounds(CGRectZero, cw);
5957 sz.rwidth() -= qRound(diffRect.size.width);
5958 sz.rheight() -= qRound(diffRect.size.height);
5959 }
5960 }
5961 return sz;
5962}
5963
5964QFont QMacStyle::font(QStyle::ControlElement element, const QStyle::State state) const
5965{
5966 QFont font = QCommonStyle::font(element, state);
5967
5968 if (state & QStyle::State_Small) {
5969 font.setPixelSize(11);
5970 } else if (state & QStyle::State_Mini) {
5971 font.setPixelSize(9);
5972 }
5973
5974 return font;
5975}
5976
5977QMargins QMacStyle::ninePatchMargins(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, const QSize &imageSize) const
5978{
5979 QMargins margins;
5980
5981 switch (cc) {
5982 case CC_ComboBox: {
5983 const QRect arrow = subControlRect(CC_ComboBox, opt, SC_ComboBoxArrow);
5984 margins = QMargins(10, 0, arrow.width() + 1, -1);
5985 break; }
5986 default:
5987 margins = QCommonStyle::ninePatchMargins(cc, opt, imageSize);
5988 break;
5989 }
5990
5991 return margins;
5992}
5993
5994void QMacStyle::drawItemText(QPainter *p, const QRect &r, int flags, const QPalette &pal,
5995 bool enabled, const QString &text, QPalette::ColorRole textRole) const
5996{
5997 if(flags & Qt::TextShowMnemonic)
5998 flags |= Qt::TextHideMnemonic;
5999 QCommonStyle::drawItemText(p, r, flags, pal, enabled, text, textRole);
6000}
6001
6002QIcon QMacStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *opt) const
6003{
6004 switch (standardIcon) {
6005 default:
6006 return QCommonStyle::standardIcon(standardIcon, opt);
6007 case SP_ToolBarHorizontalExtensionButton:
6008 case SP_ToolBarVerticalExtensionButton: {
6009 QPixmap pixmap(QLatin1String(":/qt-project.org/styles/macstyle/images/toolbar-ext.png"));
6010 if (standardIcon == SP_ToolBarVerticalExtensionButton) {
6011 QPixmap pix2(pixmap.height(), pixmap.width());
6012 pix2.setDevicePixelRatio(pixmap.devicePixelRatio());
6013 pix2.fill(Qt::transparent);
6014 QPainter p(&pix2);
6015 p.translate(pix2.width(), 0);
6016 p.rotate(90);
6017 p.drawPixmap(0, 0, pixmap);
6018 return pix2;
6019 }
6020 return pixmap;
6021 }
6022 }
6023}
6024
6025} // QQC2_NAMESPACE
6026
6027QT_END_NAMESPACE
QStyleHelper::WidgetSizePolicy aquaSizeConstrain(const QStyleOption *option, QStyle::ContentsType ct=QStyle::CT_CustomBase, QSize szHint=QSize(-1, -1), QSize *insz=0) const
static const int PushButtonRightOffset
CocoaControlType windowButtonCocoaControl(QStyle::SubControl sc) const
QStyleHelper::WidgetSizePolicy effectiveAquaSizeConstrain(const QStyleOption *option, QStyle::ContentsType ct=QStyle::CT_CustomBase, QSize szHint=QSize(-1, -1), QSize *insz=0) const
void resolveCurrentNSView(QWindow *window) const
NSView * cocoaControl(CocoaControl cocoaControl) const
static QList< QPointer< QObject > > scrollBars
void drawToolbarButtonArrow(const QStyleOption *opt, QPainter *p) const
void setupNSGraphicsContext(CGContextRef cg, bool flipped) const
QPainterPath windowPanelPath(const QRectF &r) const
static const int PushButtonLeftOffset
NSCell * cocoaCell(CocoaControl cocoaControl) const
static const int PushButtonContentPadding
void tabLayout(const QStyleOptionTab *opt, QRect *textRect, QRect *iconRect) const override
void restoreNSGraphicsContext(CGContextRef cg) const
void setupVerticalInvertedXform(CGContextRef cg, bool reverse, bool vertical, const CGRect &rect) const
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *opt=0) const override
QRect subElementRect(SubElement r, const QStyleOption *opt) const override
QPixmap standardPixmap(StandardPixmap sp, const QStyleOption *opt) const override
int styleHint(StyleHint sh, const QStyleOption *opt=0, QStyleHintReturn *shret=0) const override
QMargins ninePatchMargins(ComplexControl cc, const QStyleOptionComplex *opt, const QSize &imageSize) const override
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p) const override
QFont font(ControlElement element, const QStyle::State state) const override
QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const override
\reimp
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p) const override
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p) const override
int pixelMetric(PixelMetric pm, const QStyleOption *opt=0) const override
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc) const override
SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt) const override
void drawItemText(QPainter *p, const QRect &r, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const override
Draws the given text in the specified rectangle using the provided painter and palette.
QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize) const override
static const int closeButtonSize
static const int qt_mac_aqua_metrics[]
static const QColor lightTabBarTabLineActive(160, 160, 160)
static const QColor darkTabBarTabLineActiveHovered(90, 90, 90)
static const QColor tabBarTabLineActiveHovered()
static const QColor titlebarSeparatorLineActive(111, 111, 111)
static const qreal focusRingWidth
static const QColor tabBarTabBackgroundActiveHovered()
static const qreal comboBoxDefaultHeight[3]
static const qreal titleBarTitleRightMargin
static const QColor lightTabBarTabLine(210, 210, 210)
QMacStylePrivate::CocoaControlType cocoaControlType(const QStyleOption *opt)
static const QColor lightTabBarTabBackgroundActiveSelected(211, 211, 211)
static void setLayoutItemMargins(int left, int top, int right, int bottom, QRect *rect, Qt::LayoutDirection dir)
static const QColor tabBarTabBackgroundSelected()
static const QColor lightMainWindowGradientEnd(200, 200, 200)
static bool qt_macWindowMainWindow(const QWindow *window)
QBrush brushForToolButton(bool isOnKeyWindow)
static const int toolButtonArrowSize
static const QColor lightMainWindowGradientBegin(240, 240, 240)
static int qt_mac_aqua_get_metric(QAquaMetric m)
static const int headerSectionArrowHeight
static const qreal pushButtonDefaultHeight[3]
static const QColor darkTabBarTabBackground(38, 38, 38)
static const QColor lightTabBarTabBackgroundSelected(246, 246, 246)
static QString qt_mac_removeMnemonics(const QString &original)
static const qreal titleBarIconTitleSpacing
static QPixmap darkenPixmap(const QPixmap &pixmap)
static const QColor titlebarSeparatorLineInactive(131, 131, 131)
static const int DisclosureOffset
static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QStyleOption *opt, QSize szHint, QStyleHelper::WidgetSizePolicy sz)
static bool setupScroller(NSScroller *scroller, const QStyleOptionSlider *sb)
static const QColor darkTabBarTabLine(90, 90, 90)
static const QColor lightTabBarTabBackgroundActive(190, 190, 190)
static const QColor darkTabBarTabLineActive(90, 90, 90)
static bool isDarkMode()
static const QColor tabBarTabLineActive()
static const QColor darkTabBarTabBackgroundActive(38, 38, 38)
static const int headerSectionSeparatorInset
static const QColor tabBarTabBackgroundActiveSelected()
static const QColor lightTabBarTabLineSelected(189, 189, 189)
static const qreal popupButtonDefaultHeight[3]
static const QColor darkMainWindowGradientBegin(47, 47, 47)
QRect rotateTabPainter(QPainter *p, QStyleOptionTab::Shape shape, QRect tabRect)
static const QColor darkTabBarTabBackgroundActiveSelected(52, 52, 52)
static const QColor tabBarTabBackgroundActive()
static const QColor lightTabBarTabLineActiveHovered(150, 150, 150)
static const QColor darkTabBarTabLineSelected(90, 90, 90)
static const QColor darkTabBarTabBackgroundSelected(52, 52, 52)
static QStyleHelper::WidgetSizePolicy getControlSize(const QStyleOption *option)
static const QColor darkTabBarTabBackgroundActiveHovered(32, 32, 32)
static const QColor tabBarTabLine()
static const QColor tabBarTabBackground()
static const QColor darkModeSeparatorLine(88, 88, 88)
static const QColor tabBarTabLineSelected()
static const qreal titleBarButtonSpacing
void drawTabShape(QPainter *p, const QStyleOptionTab *tabOpt, bool isUnified, int tabOverlap)
void drawTabBase(QPainter *p, const QStyleOptionTabBarBase *tbb)
static const QColor lightTabBarTabBackground(227, 227, 227)
static const QColor darkMainWindowGradientEnd(47, 47, 47)
static const int toolButtonArrowMargin
static bool setupSlider(NSSlider *slider, const QStyleOptionSlider *sl)
static const QColor lightTabBarTabBackgroundActiveHovered(178, 178, 178)
#define QT_NAMESPACE_ALIAS_OBJC_CLASS(__KLASS__)
Definition qcore_mac_p.h:59
#define return_SIZE(large, small, mini)
#define SIZE(large, small, mini)
#define M_PI_2
Definition qmath.h:205
#define QQC2_MANGLE1(a, b)
#define LargeSmallMini(option, large, small, mini)
#define QQC2_MANGLE2(a, b)
#define QQC2_NAMESPACE
#define QT_MANGLE_NAMESPACE(name)
bool operator==(const CocoaControl &other) const
QRectF adjustedControlFrame(const QRectF &rect) const
CocoaControl(CocoaControlType t, QStyleHelper::WidgetSizePolicy s)
bool getCocoaButtonTypeAndBezelStyle(NSButtonType *buttonType, NSBezelStyle *bezelStyle) const