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
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
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
17
18QQuickFusionStyle::QQuickFusionStyle(QObject *parent)
19 : QObject(parent)
20{
21 connect(QGuiApplication::styleHints()->accessibility(), &QAccessibilityHints::contrastPreferenceChanged, this, &QQuickFusionStyle::highContrastChanged);
22}
23
24QColor QQuickFusionStyle::lightShade()
25{
26 return QColor(255, 255, 255, 90);
27}
28
29QColor QQuickFusionStyle::darkShade()
30{
31 return QColor(0, 0, 0, 60);
32}
33
34QColor QQuickFusionStyle::topShadow()
35{
36 return QColor(0, 0, 0, 18);
37}
38
39QColor QQuickFusionStyle::innerContrastLine()
40{
41 return QColor(255, 255, 255, 30);
42}
43
44bool QQuickFusionStyle::isHighContrast()
45{
46 return QGuiApplication::styleHints()->accessibility()->contrastPreference() == Qt::ContrastPreference::HighContrast;
47}
48
49QColor QQuickFusionStyle::highlight(QQuickPalette *palette)
50{
51 return palette ? palette->highlight() : QColor();
52}
53
54QColor QQuickFusionStyle::highlightedText(QQuickPalette *palette)
55{
56 return palette ? palette->highlightedText() : QColor();
57}
58
59QColor QQuickFusionStyle::outline(QQuickPalette *palette)
60{
61 if (!palette)
62 return QColor();
63 return isHighContrast() ? palette->windowText() : palette->window().darker(140);
64}
65
66QColor 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
85QColor QQuickFusionStyle::tabFrameColor(QQuickPalette *palette)
86{
87 return palette ? buttonColor(palette).lighter(104) : QColor();
88}
89
90QColor 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
108QColor 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
116QColor QQuickFusionStyle::gradientStart(const QColor &baseColor)
117{
118 return baseColor.lighter(124);
119}
120
121QColor QQuickFusionStyle::gradientStop(const QColor &baseColor)
122{
123 return baseColor.lighter(102);
124}
125
126QColor 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
137QColor 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
148QT_END_NAMESPACE
149
150#include "moc_qquickfusionstyle_p.cpp"
Combined button and popup list for selecting options.