1// Copyright (C) 2016 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
4#ifndef QFUSIONSTYLE_P_P_H
5#define QFUSIONSTYLE_P_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
13// file may change from version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19#include "qcommonstyle.h"
20#include "qcommonstyle_p.h"
21#include <qpa/qplatformtheme.h>
22#include "private/qguiapplication_p.h"
23
24#if QT_CONFIG(style_fusion)
25
26QT_BEGIN_NAMESPACE
27
28class QFusionStylePrivate : public QCommonStylePrivate
29{
30 Q_DECLARE_PUBLIC(QFusionStyle)
31
32public:
33 QFusionStylePrivate();
34
35 // Used for grip handles
36 static constexpr QColor lightShade = QColor(255, 255, 255, 90);
37 static constexpr QColor darkShade = QColor(0, 0, 0, 60);
38 static constexpr QColor topShadow = QColor(0, 0, 0, 18);
39 static constexpr QColor innerContrastLine = QColor(255, 255, 255, 30);
40
41 // On mac we want a standard blue color used when the system palette is used
42 bool isMacSystemPalette(const QPalette &pal) const {
43 Q_UNUSED(pal);
44#if defined(Q_OS_MACOS)
45 const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette();
46 if (themePalette && themePalette->color(QPalette::Normal, QPalette::Highlight) ==
47 pal.color(QPalette::Normal, QPalette::Highlight) &&
48 themePalette->color(QPalette::Normal, QPalette::HighlightedText) ==
49 pal.color(QPalette::Normal, QPalette::HighlightedText))
50 return true;
51#endif
52 return false;
53 }
54
55 QColor highlight(const QPalette &pal) const {
56 if (isMacSystemPalette(pal))
57 return QColor(60, 140, 230);
58 return pal.color(cr: QPalette::Highlight);
59 }
60
61 QColor highlightedText(const QPalette &pal) const {
62 if (isMacSystemPalette(pal))
63 return Qt::white;
64 return pal.color(cr: QPalette::HighlightedText);
65 }
66
67 QColor outline(const QPalette &pal) const {
68 if (isHighContrast()) {
69 return pal.text().color();
70 }
71 if (pal.window().style() == Qt::TexturePattern)
72 return QColor(0, 0, 0, 160);
73 return pal.window().color().darker(f: 140);
74 }
75
76 QColor highlightedOutline(const QPalette &pal) const {
77 QColor highlightedOutline = highlight(pal).darker(f: 125);
78 if (highlightedOutline.value() > 160)
79 highlightedOutline.setHsl(h: highlightedOutline.hue(), s: highlightedOutline.saturation(), l: 160);
80 return highlightedOutline;
81 }
82
83 QColor tabFrameColor(const QPalette &pal) const {
84 if (pal.window().style() == Qt::TexturePattern)
85 return QColor(255, 255, 255, 8);
86 return buttonColor(pal).lighter(f: 104);
87 }
88
89 QColor buttonColor(const QPalette &pal) const {
90 QColor buttonColor = pal.button().color();
91 int val = qGray(rgb: buttonColor.rgb());
92 buttonColor = buttonColor.lighter(f: 100 + qMax(a: 1, b: (180 - val)/6));
93 buttonColor.setHsv(h: buttonColor.hue(), s: buttonColor.saturation() * 0.75, v: buttonColor.value());
94 return buttonColor;
95 }
96
97 enum {
98 menuItemHMargin = 3, // menu item hor text margin
99 menuArrowHMargin = 6, // menu arrow horizontal margin
100 menuRightBorder = 15, // right border on menus
101 menuCheckMarkWidth = 12 // checkmarks width on menus
102 };
103
104private:
105 Qt::ColorScheme colorScheme() const
106 {
107 return QGuiApplicationPrivate::platformTheme()->colorScheme();
108 }
109
110 bool isHighContrast() const
111 {
112 return QGuiApplicationPrivate::platformTheme()->contrastPreference()
113 == Qt::ContrastPreference::HighContrast;
114 }
115};
116
117QT_END_NAMESPACE
118
119#endif // style_fusion
120
121#endif //QFUSIONSTYLE_P_P_H
122

source code of qtbase/src/widgets/styles/qfusionstyle_p_p.h