Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquickfusionstyle.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 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
#
include
"qquickfusionstyle_p.h"
6
7
#
include
<
QtGui
/
qcolor
.
h
>
8
#
include
<
QtGui
/
qpalette
.
h
>
9
#
include
<
QtGui
/
qstylehints
.
h
>
10
#
include
<
QtGui
/
qaccessibilityhints
.
h
>
11
#
include
<
QtGui
/
qpa
/
qplatformtheme
.
h
>
12
#
include
<
QtGui
/
private
/
qguiapplication_p
.
h
>
13
14
#
include
<
QtQuick
/
private
/
qquickpalette_p
.
h
>
15
16
QT_BEGIN_NAMESPACE
17
18
QQuickFusionStyle::QQuickFusionStyle(QObject *parent)
19
: QObject(parent)
20
{
21
connect(QGuiApplication::styleHints()->accessibility(), &QAccessibilityHints::contrastPreferenceChanged,
this
, &QQuickFusionStyle::highContrastChanged);
22
}
23
24
QColor QQuickFusionStyle::lightShade()
25
{
26
return
QColor(255, 255, 255, 90);
27
}
28
29
QColor QQuickFusionStyle::darkShade()
30
{
31
return
QColor(0, 0, 0, 60);
32
}
33
34
QColor QQuickFusionStyle::topShadow()
35
{
36
return
QColor(0, 0, 0, 18);
37
}
38
39
QColor QQuickFusionStyle::innerContrastLine()
40
{
41
return
QColor(255, 255, 255, 30);
42
}
43
44
bool
QQuickFusionStyle::isHighContrast()
45
{
46
return
QGuiApplication::styleHints()->accessibility()->contrastPreference() == Qt::ContrastPreference::HighContrast;
47
}
48
49
QColor QQuickFusionStyle::highlight(QQuickPalette *palette)
50
{
51
return
palette ? palette->highlight() : QColor();
52
}
53
54
QColor QQuickFusionStyle::highlightedText(QQuickPalette *palette)
55
{
56
return
palette ? palette->highlightedText() : QColor();
57
}
58
59
QColor QQuickFusionStyle::outline(QQuickPalette *palette)
60
{
61
if
(!palette)
62
return
QColor();
63
return
isHighContrast() ? palette->windowText() : palette->window().darker(140);
64
}
65
66
QColor QQuickFusionStyle::highlightedOutline(QQuickPalette *palette)
67
{
68
if
(!palette)
69
return
QColor();
70
if
(isHighContrast()) {
71
if
(QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Light) {
72
return
highlight(palette).darker(125);
73
}
else
{
74
QColor highlightedOutline = highlight(palette).toHsv();
75
highlightedOutline.setHsv(highlightedOutline.hsvHue(), highlightedOutline.hsvSaturation(), 255);
76
return
highlightedOutline;
77
}
78
}
79
QColor highlightedOutline = highlight(palette).darker(125).toHsv();
80
if
(highlightedOutline.value() > 160)
81
highlightedOutline.setHsl(highlightedOutline.hue(), highlightedOutline.saturation(), 160);
82
return
highlightedOutline;
83
}
84
85
QColor QQuickFusionStyle::tabFrameColor(QQuickPalette *palette)
86
{
87
return
palette ? buttonColor(palette).lighter(104) : QColor();
88
}
89
90
QColor QQuickFusionStyle::buttonColor(QQuickPalette *palette,
bool
highlighted,
bool
down,
bool
hovered)
91
{
92
if
(!palette)
93
return
QColor();
94
QColor buttonColor = palette->button();
95
int
val = qGray(buttonColor.rgb());
96
buttonColor = buttonColor.lighter(100 + qMax(1, (180 - val)/6));
97
buttonColor = buttonColor.toHsv();
98
buttonColor.setHsv(buttonColor.hue(),
int
(buttonColor.saturation() * 0.75), buttonColor.value());
99
if
(highlighted)
100
buttonColor = mergedColors(buttonColor, highlightedOutline(palette).lighter(130), 90);
101
if
(!hovered)
102
buttonColor = buttonColor.darker(104);
103
if
(down)
104
buttonColor = buttonColor.darker(110);
105
return
buttonColor;
106
}
107
108
QColor QQuickFusionStyle::buttonOutline(QQuickPalette *palette,
bool
highlighted,
bool
enabled)
109
{
110
if
(!palette)
111
return
QColor();
112
QColor darkOutline = enabled && highlighted ? highlightedOutline(palette) : outline(palette);
113
return
!enabled ? darkOutline.lighter(115) : darkOutline;
114
}
115
116
QColor QQuickFusionStyle::gradientStart(
const
QColor &baseColor)
117
{
118
return
baseColor.lighter(124);
119
}
120
121
QColor QQuickFusionStyle::gradientStop(
const
QColor &baseColor)
122
{
123
return
baseColor.lighter(102);
124
}
125
126
QColor QQuickFusionStyle::mergedColors(
const
QColor &colorA,
const
QColor &colorB,
int
factor)
127
{
128
const
int
maxFactor = 100;
129
const
auto
rgbColorB = colorB.toRgb();
130
QColor tmp = colorA.toRgb();
131
tmp.setRed((tmp.red() * factor) / maxFactor + (rgbColorB.red() * (maxFactor - factor)) / maxFactor);
132
tmp.setGreen((tmp.green() * factor) / maxFactor + (rgbColorB.green() * (maxFactor - factor)) / maxFactor);
133
tmp.setBlue((tmp.blue() * factor) / maxFactor + (rgbColorB.blue() * (maxFactor - factor)) / maxFactor);
134
return
tmp;
135
}
136
137
QColor QQuickFusionStyle::grooveColor(QQuickPalette *palette)
138
{
139
if
(!palette)
140
return
QColor();
141
QColor color = buttonColor(palette).toHsv();
142
color.setHsv(color.hue(),
143
qMin(255, color.saturation()),
144
qMin<
int
>(255, color.value() * 0.9));
145
return
color;
146
}
147
148
QT_END_NAMESPACE
149
150
#
include
"moc_qquickfusionstyle_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quickcontrols
fusion
qquickfusionstyle.cpp
Generated on
for Qt by
1.18.0