1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMACSTYLE_P_H
#define QMACSTYLE_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtGui/qtguiglobal.h>
#if defined(QT_WIDGETS_LIB) && defined(QT_QUICK_LIB)
# error "Cannot use QtGui Mac style with both Widgets and Quick"
#endif
#if defined(QT_WIDGETS_LIB)
# define OPTIONAL_WIDGET_ARGUMENT , const QWidget *w = nullptr
# define FORWARD_OPTIONAL_WIDGET_ARGUMENT , w
# else
# define OPTIONAL_WIDGET_ARGUMENT
# define FORWARD_OPTIONAL_WIDGET_ARGUMENT
#endif
#include <AppKit/NSApplication.h>
QT_BEGIN_NAMESPACE
/*
Helper class to ensure that the Mac style in Widgets and Quick
draw their NSViews and NSCells with the correct appearance,
as the native controls use NSAppearance.currentDrawingAppearance
instead of NSApp.effectiveAppearance when drawing.
Due to the duplicated class hierarchies between Widgets and Quick
for the styles, with the Quick styles missing the QWidget pointer
in the function parameters, we have to opt for an awkward macro
to solve this.
*/
template <typename Style>
class QMacApperanceStyle : public Style
{
public:
void drawPrimitive(typename Style::PrimitiveElement pe, const QStyleOption *opt, QPainter *p
OPTIONAL_WIDGET_ARGUMENT) const override
{
[NSApp.effectiveAppearance performAsCurrentDrawingAppearance:^{
Style::drawPrimitive(pe, opt, p
FORWARD_OPTIONAL_WIDGET_ARGUMENT);
}];
}
void drawControl(typename Style::ControlElement element, const QStyleOption *opt, QPainter *p
OPTIONAL_WIDGET_ARGUMENT) const override
{
[NSApp.effectiveAppearance performAsCurrentDrawingAppearance:^{
Style::drawControl(element, opt, p
FORWARD_OPTIONAL_WIDGET_ARGUMENT);
}];
}
void drawComplexControl(typename Style::ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p
OPTIONAL_WIDGET_ARGUMENT) const override
{
[NSApp.effectiveAppearance performAsCurrentDrawingAppearance:^{
Style::drawComplexControl(cc, opt, p
FORWARD_OPTIONAL_WIDGET_ARGUMENT);
}];
}
};
QT_END_NAMESPACE
#endif // QMACSTYLE_P_H
|