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_p_p.h
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#ifndef QMACSTYLE_MAC_P_P_H
7#define QMACSTYLE_MAC_P_P_H
8
12
13#include <QtCore/qdebug.h>
14#include <QtCore/qhash.h>
15#include <QtCore/qmap.h>
16#include <QtCore/qmath.h>
17#include <QtCore/qpointer.h>
18#include <QtCore/qtextstream.h>
19#include <QtCore/qvector.h>
20
21#include <QtGui/qbitmap.h>
22#include <QtGui/qevent.h>
23#include <QtGui/qpaintdevice.h>
24#include <QtGui/qpainter.h>
25#include <QtGui/qpixmapcache.h>
26
27#include <QtQuick/qquickitem.h>
28
29#include <QtCore/private/qcore_mac_p.h>
30#include <QtGui/private/qpainter_p.h>
31
32//
33// W A R N I N G
34// -------------
35//
36// This file is not part of the Qt API. It exists purely as an
37// implementation detail. This header file may change from version to
38// version without notice, or even be removed.
39//
40// We mean it.
41//
42
44
47
48QT_BEGIN_NAMESPACE
49
50namespace QQC2 {
51
52/*
53 AHIG:
54 macOS Human Interface Guidelines
55 https://developer.apple.com/macos/human-interface-guidelines/overview/themes/
56
57 Builder:
58 Interface Builder in Xcode 8 or later
59*/
60
61// this works as long as we have at most 16 different control types
62#define CT1(c) CT2(c, c)
63#define CT2(c1, c2) ((uint(c1) << 16) | uint(c2))
64
65#define SIZE(large, small, mini)
66 (controlSize == QStyleHelper::SizeLarge ? (large) : controlSize == QStyleHelper::SizeSmall ? (small) : (mini))
67
68// same as return SIZE(...) but optimized
69#define return_SIZE(large, small, mini)
70 do {
71 static const int sizes[] = { (large), (small), (mini) };
72 return sizes[controlSize];
73 } while (false)
74
76{
77 Q_DECLARE_PUBLIC(QMacStyle)
78
79public:
80 enum Direction {
82 };
83
85 NoControl, // For when there's no such a control in Cocoa
86 Box, // QGroupBox
87 Box_Dark, // FIXME See render code in drawPrimitive(PE_FrameTabWidget)
89 Button_Disclosure, // Disclosure triangle, like in QTreeView
90 Button_PopupButton, // Non-editable QComboBox
91 Button_PullDown, // QPushButton with menu
92 Button_PushButton, // Plain QPushButton and QTabBar buttons
94 Button_SquareButton, // Oversized QPushButton
98 ComboBox, // Editable QComboBox
104 SegmentedControl_First, // QTabBar buttons focus ring
112 Stepper, // QSpinBox buttons
114 };
115
119
122
123 bool operator==(const CocoaControl &other) const;
124
126 QRectF adjustedControlFrame(const QRectF &rect) const;
128
129 bool getCocoaButtonTypeAndBezelStyle(NSButtonType *buttonType, NSBezelStyle *bezelStyle) const;
130 };
131
132 typedef void (^DrawRectBlock)(CGContextRef, const CGRect &);
133
136
137 // Ideally these wouldn't exist, but since they already exist we need some accessors.
138 static const int PushButtonLeftOffset;
139 static const int PushButtonRightOffset;
140 static const int PushButtonContentPadding;
141
144 QStyle::ContentsType ct = QStyle::CT_CustomBase,
145 QSize szHint=QSize(-1, -1), QSize *insz = 0) const;
147 QStyle::ContentsType ct = QStyle::CT_CustomBase,
148 QSize szHint=QSize(-1, -1), QSize *insz = 0) const;
149 inline int animateSpeed(Animates) const { return 33; }
150
151 // Utility functions
152 static CGRect comboboxInnerBounds(const CGRect &outterBounds, const CocoaControl &cocoaWidget);
153
154 static QRectF comboboxEditBounds(const QRectF &outterBounds, const CocoaControl &cw);
155
156 void setAutoDefaultButton(QObject *button) const;
157
158 NSView *cocoaControl(CocoaControl cocoaControl) const;
159 NSCell *cocoaCell(CocoaControl cocoaControl) const;
160
161 void setupNSGraphicsContext(CGContextRef cg, bool flipped) const;
162 void restoreNSGraphicsContext(CGContextRef cg) const;
163
164 void setupVerticalInvertedXform(CGContextRef cg, bool reverse, bool vertical, const CGRect &rect) const;
165
166 void drawNSViewInRect(NSView *view, const QRectF &rect, QPainter *p, DrawRectBlock drawRectBlock = nil) const;
167 void resolveCurrentNSView(QWindow *window) const;
168
169 void drawToolbarButtonArrow(const QStyleOption *opt, QPainter *p) const;
170
171 QPainterPath windowPanelPath(const QRectF &r) const;
172
173 CocoaControlType windowButtonCocoaControl(QStyle::SubControl sc) const;
174
175 void tabLayout(const QStyleOptionTab *opt, QRect *textRect, QRect *iconRect) const override;
176 static Direction tabDirection(QStyleOptionTab::Shape shape);
177 static bool verticalTabs(QMacStylePrivate::Direction tabDirection);
178
179public:
182
183 mutable QPointer<QQuickItem> focusWidget; // TODO: rename to focusItem
187
190
192};
193
194} // namespace QQC2
195
196QT_END_NAMESPACE
197
198#endif // QMACSTYLE_MAC_P_P_H
friend class QPainter
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p) const override
QMargins ninePatchMargins(ControlElement ce, const QStyleOption *opt, const QSize &imageSize) const override
QCommonStyle(QCommonStylePrivate &dd)
QRect subElementRect(SubElement r, const QStyleOption *opt) const override
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p) const override
SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt) const override
\reimp
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc) const override
\reimp
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *opt=nullptr) const override
int styleHint(StyleHint sh, const QStyleOption *opt=nullptr, QStyleHintReturn *shret=nullptr) const override
QPixmap standardPixmap(StandardPixmap sp, const QStyleOption *opt=nullptr) const override
int pixelMetric(PixelMetric m, const QStyleOption *opt=nullptr) const override
QFont font(ControlElement element, const QStyle::State state) const override
QMargins ninePatchMargins(ComplexControl cc, const QStyleOptionComplex *opt, const QSize &imageSize) const override
QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize) const override
QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const override
\reimp
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p) const override
\reimp
static Direction tabDirection(QStyleOptionTab::Shape shape)
static bool verticalTabs(QMacStylePrivate::Direction tabDirection)
QMacKeyValueObserver appearanceObserver
QStyleHelper::WidgetSizePolicy aquaSizeConstrain(const QStyleOption *option, QStyle::ContentsType ct=QStyle::CT_CustomBase, QSize szHint=QSize(-1, -1), QSize *insz=0) const
QPointer< QQuickItem > focusWidget
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
QHash< CocoaControl, NSCell * > cocoaCells
void resolveCurrentNSView(QWindow *window) const
NSView * cocoaControl(CocoaControl cocoaControl) const
void setAutoDefaultButton(QObject *button) const
void drawToolbarButtonArrow(const QStyleOption *opt, QPainter *p) const
QPointer< QObject > autoDefaultButton
static CGRect comboboxInnerBounds(const CGRect &outterBounds, const CocoaControl &cocoaWidget)
static QVector< QPointer< QObject > > scrollBars
QHash< CocoaControl, NSView * > cocoaControls
void setupNSGraphicsContext(CGContextRef cg, bool flipped) const
QPainterPath windowPanelPath(const QRectF &r) const
void(^ DrawRectBlock)(CGContextRef, const CGRect &)
static const int PushButtonLeftOffset
NSCell * cocoaCell(CocoaControl cocoaControl) const
static const int PushButtonContentPadding
void drawNSViewInRect(NSView *view, const QRectF &rect, QPainter *p, DrawRectBlock drawRectBlock=nil) const
static QRectF comboboxEditBounds(const QRectF &outterBounds, const CocoaControl &cw)
void tabLayout(const QStyleOptionTab *opt, QRect *textRect, QRect *iconRect) const override
void restoreNSGraphicsContext(CGContextRef cg) const
int animateSpeed(Animates) 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
WidgetSizePolicy widgetSizePolicy(const QStyleOption *opt)
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)
uint qHash(const QMacStylePrivate::CocoaControl &cw, uint seed=0)
Q_FORWARD_DECLARE_OBJC_CLASS(NSView)
#define QT_NAMESPACE_ALIAS_OBJC_CLASS(__KLASS__)
Definition qcore_mac_p.h:58
#define return_SIZE(large, small, mini)
#define CT2(c1, c2)
Q_FORWARD_DECLARE_OBJC_CLASS(NSCell)
#define SIZE(large, small, mini)
Q_FORWARD_DECLARE_MUTABLE_CG_TYPE(CGContext)
#define M_PI_2
Definition qmath.h:204
#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