aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicknativestyle/util/qquickstyleconstants.mm
blob: fb2b00e8c6c689b04ec703d0df55de7891fa6a30 (plain)
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
// 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

#include "qquickstyleconstants.h"

#include <QtCore/private/qcore_mac_p.h>
#include <QtGui/private/qcoregraphics_p.h>
#include <QtGui/qguiapplication.h>
#include <QtGui/qstylehints.h>

#include <AppKit/AppKit.h>

QT_BEGIN_NAMESPACE

using namespace Qt::StringLiterals;

QQuickStyleConstants::QQuickStyleConstants()
{
    connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, [=]{
        emit secondarySystemFillColorChanged();
        emit tertiarySystemFillColorChanged();
    });
}

bool QQuickStyleConstants::runningWithLiquidGlass() const
{
    return qt_apple_runningWithLiquidGlass();
}

static QColor systemColor(std::function<NSColor *()> block)
{
    __block QColor color;
    [NSApp.effectiveAppearance performAsCurrentDrawingAppearance:^{
        color = qt_mac_toQBrush(block()).color();
    }];
    return color;
}

QColor QQuickStyleConstants::secondarySystemFillColor() const
{
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(140000)
    if (@available(macOS 14.0, *))
        return systemColor([]{ return NSColor.secondarySystemFillColor; });
#endif
    return Qt::black;
}

QColor QQuickStyleConstants::tertiarySystemFillColor() const
{
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(140000)
    if (@available(macOS 14.0, *))
        return systemColor([]{ return NSColor.tertiarySystemFillColor; });
#endif
    return Qt::black;
}

QT_END_NAMESPACE

#include "moc_qquickstyleconstants.cpp"