1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "qquickfusionstyle_p.h"
38
39#include <QtGui/qcolor.h>
40#include <QtGui/qpalette.h>
41#include <QtGui/qpa/qplatformtheme.h>
42#include <QtGui/private/qguiapplication_p.h>
43
44QT_BEGIN_NAMESPACE
45
46QQuickFusionStyle::QQuickFusionStyle(QObject *parent)
47 : QObject(parent)
48{
49}
50
51QColor QQuickFusionStyle::lightShade()
52{
53 return QColor(255, 255, 255, 90);
54}
55
56QColor QQuickFusionStyle::darkShade()
57{
58 return QColor(0, 0, 0, 60);
59}
60
61QColor QQuickFusionStyle::topShadow()
62{
63 return QColor(0, 0, 0, 18);
64}
65
66QColor QQuickFusionStyle::innerContrastLine()
67{
68 return QColor(255, 255, 255, 30);
69}
70
71QColor QQuickFusionStyle::highlight(const QPalette &palette)
72{
73 return palette.color(cr: QPalette::Highlight);
74}
75
76QColor QQuickFusionStyle::highlightedText(const QPalette &palette)
77{
78 return palette.color(cr: QPalette::HighlightedText);
79}
80
81QColor QQuickFusionStyle::outline(const QPalette &palette)
82{
83 return palette.window().color().darker(f: 140);
84}
85
86QColor QQuickFusionStyle::highlightedOutline(const QPalette &palette)
87{
88 QColor highlightedOutline = highlight(palette).darker(f: 125);
89 if (highlightedOutline.value() > 160)
90 highlightedOutline.setHsl(h: highlightedOutline.hue(), s: highlightedOutline.saturation(), l: 160);
91 return highlightedOutline;
92}
93
94QColor QQuickFusionStyle::tabFrameColor(const QPalette &palette)
95{
96 return buttonColor(palette).lighter(f: 104);
97}
98
99QColor QQuickFusionStyle::buttonColor(const QPalette &palette, bool highlighted, bool down, bool hovered)
100{
101 QColor buttonColor = palette.button().color();
102 int val = qGray(rgb: buttonColor.rgb());
103 buttonColor = buttonColor.lighter(f: 100 + qMax(a: 1, b: (180 - val)/6));
104 buttonColor.setHsv(h: buttonColor.hue(), s: buttonColor.saturation() * 0.75, v: buttonColor.value());
105 if (highlighted)
106 buttonColor = mergedColors(colorA: buttonColor, colorB: highlightedOutline(palette).lighter(f: 130), factor: 90);
107 if (!hovered)
108 buttonColor = buttonColor.darker(f: 104);
109 if (down)
110 buttonColor = buttonColor.darker(f: 110);
111 return buttonColor;
112}
113
114QColor QQuickFusionStyle::buttonOutline(const QPalette &palette, bool highlighted, bool enabled)
115{
116 QColor darkOutline = enabled && highlighted ? highlightedOutline(palette) : outline(palette);
117 return !enabled ? darkOutline.lighter(f: 115) : darkOutline;
118}
119
120QColor QQuickFusionStyle::gradientStart(const QColor &baseColor)
121{
122 return baseColor.lighter(f: 124);
123}
124
125QColor QQuickFusionStyle::gradientStop(const QColor &baseColor)
126{
127 return baseColor.lighter(f: 102);
128}
129
130QColor QQuickFusionStyle::mergedColors(const QColor &colorA, const QColor &colorB, int factor)
131{
132 const int maxFactor = 100;
133 QColor tmp = colorA;
134 tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor);
135 tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor);
136 tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor);
137 return tmp;
138}
139
140QColor QQuickFusionStyle::grooveColor(const QPalette &palette)
141{
142 QColor color = buttonColor(palette);
143 color.setHsv(h: color.hue(),
144 s: qMin(a: 255, b: color.saturation()),
145 v: qMin<int>(a: 255, b: color.value() * 0.9));
146 return color;
147}
148
149QT_END_NAMESPACE
150

source code of qtquickcontrols2/src/imports/controls/fusion/qquickfusionstyle.cpp