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
10
11#include <private/qcore_mac_p.h>
12#include <private/qpainter_p.h>
13#include <private/qqc2qcommonstyle_p_p.h>
14#include <private/qqc2qstylehelper_p.h>
15
16#include <QtQuick/qquickitem.h>
17
18#include <QtGui/qbitmap.h>
19#include <QtGui/qevent.h>
20#include <QtGui/qpaintdevice.h>
21#include <QtGui/qpainter.h>
22#include <QtGui/qpixmapcache.h>
23
24#include <QtCore/qdebug.h>
25#include <QtCore/qhash.h>
26#include <QtCore/qmap.h>
27#include <QtCore/qmath.h>
28#include <QtCore/qpointer.h>
29#include <QtCore/qtextstream.h>
30#include <QtCore/qvector.h>
31
32#include <AppKit/AppKit.h>
33
34//
35// W A R N I N G
36// -------------
37//
38// This file is not part of the Qt API. It exists purely as an
39// implementation detail. This header file may change from version to
40// version without notice, or even be removed.
41//
42// We mean it.
43//
44
46
49
50QT_BEGIN_NAMESPACE
51
52namespace QQC2 {
53
54/*
55 AHIG:
56 macOS Human Interface Guidelines
57 https://developer.apple.com/macos/human-interface-guidelines/overview/themes/
58
59 Builder:
60 Interface Builder in Xcode 8 or later
61*/
62
63// this works as long as we have at most 16 different control types
64#define CT1(c) CT2(c, c)
65#define CT2(c1, c2) ((uint(c1) << 16) | uint(c2))
66
67#define SIZE(large, small, mini)
68 (controlSize == QStyleHelper::SizeLarge ? (large) : controlSize == QStyleHelper::SizeSmall ? (small) : (mini))
69
70// same as return SIZE(...) but optimized
71#define return_SIZE(large, small, mini)
72 do {
73 static const int sizes[] = { (large), (small), (mini) };
74 return sizes[controlSize];
75 } while (false)
76
78{
79 Q_DECLARE_PUBLIC(QMacStyle)
80
81public:
82 enum Direction {
84 };
85
87 NoControl, // For when there's no such a control in Cocoa
88 Box, // QGroupBox
89 Box_Dark, // FIXME See render code in drawPrimitive(PE_FrameTabWidget)
91 Button_Disclosure, // Disclosure triangle, like in QTreeView
92 Button_PopupButton, // Non-editable QComboBox
93 Button_PullDown, // QPushButton with menu
94 Button_PushButton, // Plain QPushButton and QTabBar buttons
96 Button_SquareButton, // Oversized QPushButton
100 ComboBox, // Editable QComboBox
106 SegmentedControl_First, // QTabBar buttons focus ring
114 Stepper, // QSpinBox buttons
116 };
117
120 CocoaControl(CocoaControlType t, QStyleHelper::WidgetSizePolicy s);
121
124
125 bool operator==(const CocoaControl &other) const;
126
128 QRectF adjustedControlFrame(const QRectF &rect) const;
130
131 bool getCocoaButtonTypeAndBezelStyle(NSButtonType *buttonType, NSBezelStyle *bezelStyle) const;
132 };
133
134 typedef void (^DrawRectBlock)(CGContextRef, const CGRect &);
135
138
139 // Ideally these wouldn't exist, but since they already exist we need some accessors.
140 static const int PushButtonLeftOffset;
141 static const int PushButtonRightOffset;
142 static const int PushButtonContentPadding;
143
145 QStyleHelper::WidgetSizePolicy aquaSizeConstrain(const QStyleOption *option,
146 QStyle::ContentsType ct = QStyle::CT_CustomBase,
147 QSize szHint=QSize(-1, -1), QSize *insz = 0) const;
148 QStyleHelper::WidgetSizePolicy effectiveAquaSizeConstrain(const QStyleOption *option,
149 QStyle::ContentsType ct = QStyle::CT_CustomBase,
150 QSize szHint=QSize(-1, -1), QSize *insz = 0) const;
151 inline int animateSpeed(Animates) const { return 33; }
152
153 // Utility functions
154 static CGRect comboboxInnerBounds(const CGRect &outterBounds, const CocoaControl &cocoaWidget);
155
156 static QRectF comboboxEditBounds(const QRectF &outterBounds, const CocoaControl &cw);
157
158 void setAutoDefaultButton(QObject *button) const;
159
160 NSView *cocoaControl(CocoaControl cocoaControl) const;
161 NSCell *cocoaCell(CocoaControl cocoaControl) const;
162
163 void setupNSGraphicsContext(CGContextRef cg, bool flipped) const;
164 void restoreNSGraphicsContext(CGContextRef cg) const;
165
166 void setupVerticalInvertedXform(CGContextRef cg, bool reverse, bool vertical, const CGRect &rect) const;
167
168 void drawNSViewInRect(NSView *view, const QRectF &rect, QPainter *p, DrawRectBlock drawRectBlock = nil) const;
169 void resolveCurrentNSView(QWindow *window) const;
170
171 void drawToolbarButtonArrow(const QStyleOption *opt, QPainter *p) const;
172
173 QPainterPath windowPanelPath(const QRectF &r) const;
174
175 CocoaControlType windowButtonCocoaControl(QStyle::SubControl sc) const;
176
177 void tabLayout(const QStyleOptionTab *opt, QRect *textRect, QRect *iconRect) const override;
178 static Direction tabDirection(QStyleOptionTab::Shape shape);
179 static bool verticalTabs(QMacStylePrivate::Direction tabDirection);
180
181public:
184
185 mutable QPointer<QQuickItem> focusWidget; // TODO: rename to focusItem
189
192
194};
195
196} // namespace QQC2
197
198QT_END_NAMESPACE
199
200#endif // QMACSTYLE_MAC_P_P_H
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
static QList< QPointer< QObject > > scrollBars
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)
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
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:59
#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: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