| 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 | |
| 4 | #include "qquickfusionstyle_p.h" |
| 5 | |
| 6 | #include <QtGui/qcolor.h> |
| 7 | #include <QtGui/qpalette.h> |
| 8 | #include <QtGui/qpa/qplatformtheme.h> |
| 9 | #include <QtGui/private/qguiapplication_p.h> |
| 10 | |
| 11 | #include <QtQuick/private/qquickpalette_p.h> |
| 12 | |
| 13 | QT_BEGIN_NAMESPACE |
| 14 | |
| 15 | QQuickFusionStyle::QQuickFusionStyle(QObject *parent) |
| 16 | : QObject(parent) |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | QColor QQuickFusionStyle::lightShade() |
| 21 | { |
| 22 | return QColor(255, 255, 255, 90); |
| 23 | } |
| 24 | |
| 25 | QColor QQuickFusionStyle::darkShade() |
| 26 | { |
| 27 | return QColor(0, 0, 0, 60); |
| 28 | } |
| 29 | |
| 30 | QColor QQuickFusionStyle::topShadow() |
| 31 | { |
| 32 | return QColor(0, 0, 0, 18); |
| 33 | } |
| 34 | |
| 35 | QColor QQuickFusionStyle::innerContrastLine() |
| 36 | { |
| 37 | return QColor(255, 255, 255, 30); |
| 38 | } |
| 39 | |
| 40 | QColor QQuickFusionStyle::highlight(QQuickPalette *palette) |
| 41 | { |
| 42 | return palette->highlight(); |
| 43 | } |
| 44 | |
| 45 | QColor QQuickFusionStyle::highlightedText(QQuickPalette *palette) |
| 46 | { |
| 47 | return palette->highlightedText(); |
| 48 | } |
| 49 | |
| 50 | QColor QQuickFusionStyle::outline(QQuickPalette *palette) |
| 51 | { |
| 52 | return palette->window().darker(f: 140); |
| 53 | } |
| 54 | |
| 55 | QColor QQuickFusionStyle::highlightedOutline(QQuickPalette *palette) |
| 56 | { |
| 57 | QColor highlightedOutline = highlight(palette).darker(f: 125).toHsv(); |
| 58 | if (highlightedOutline.value() > 160) |
| 59 | highlightedOutline.setHsl(h: highlightedOutline.hue(), s: highlightedOutline.saturation(), l: 160); |
| 60 | return highlightedOutline; |
| 61 | } |
| 62 | |
| 63 | QColor QQuickFusionStyle::tabFrameColor(QQuickPalette *palette) |
| 64 | { |
| 65 | return buttonColor(palette).lighter(f: 104); |
| 66 | } |
| 67 | |
| 68 | QColor QQuickFusionStyle::buttonColor(QQuickPalette *palette, bool highlighted, bool down, bool hovered) |
| 69 | { |
| 70 | QColor buttonColor = palette->button(); |
| 71 | int val = qGray(rgb: buttonColor.rgb()); |
| 72 | buttonColor = buttonColor.lighter(f: 100 + qMax(a: 1, b: (180 - val)/6)); |
| 73 | buttonColor = buttonColor.toHsv(); |
| 74 | buttonColor.setHsv(h: buttonColor.hue(), s: int(buttonColor.saturation() * 0.75), v: buttonColor.value()); |
| 75 | if (highlighted) |
| 76 | buttonColor = mergedColors(colorA: buttonColor, colorB: highlightedOutline(palette).lighter(f: 130), factor: 90); |
| 77 | if (!hovered) |
| 78 | buttonColor = buttonColor.darker(f: 104); |
| 79 | if (down) |
| 80 | buttonColor = buttonColor.darker(f: 110); |
| 81 | return buttonColor; |
| 82 | } |
| 83 | |
| 84 | QColor QQuickFusionStyle::buttonOutline(QQuickPalette *palette, bool highlighted, bool enabled) |
| 85 | { |
| 86 | QColor darkOutline = enabled && highlighted ? highlightedOutline(palette) : outline(palette); |
| 87 | return !enabled ? darkOutline.lighter(f: 115) : darkOutline; |
| 88 | } |
| 89 | |
| 90 | QColor QQuickFusionStyle::gradientStart(const QColor &baseColor) |
| 91 | { |
| 92 | return baseColor.lighter(f: 124); |
| 93 | } |
| 94 | |
| 95 | QColor QQuickFusionStyle::gradientStop(const QColor &baseColor) |
| 96 | { |
| 97 | return baseColor.lighter(f: 102); |
| 98 | } |
| 99 | |
| 100 | QColor QQuickFusionStyle::mergedColors(const QColor &colorA, const QColor &colorB, int factor) |
| 101 | { |
| 102 | const int maxFactor = 100; |
| 103 | const auto rgbColorB = colorB.toRgb(); |
| 104 | QColor tmp = colorA.toRgb(); |
| 105 | tmp.setRed((tmp.red() * factor) / maxFactor + (rgbColorB.red() * (maxFactor - factor)) / maxFactor); |
| 106 | tmp.setGreen((tmp.green() * factor) / maxFactor + (rgbColorB.green() * (maxFactor - factor)) / maxFactor); |
| 107 | tmp.setBlue((tmp.blue() * factor) / maxFactor + (rgbColorB.blue() * (maxFactor - factor)) / maxFactor); |
| 108 | return tmp; |
| 109 | } |
| 110 | |
| 111 | QColor QQuickFusionStyle::grooveColor(QQuickPalette *palette) |
| 112 | { |
| 113 | QColor color = buttonColor(palette).toHsv(); |
| 114 | color.setHsv(h: color.hue(), |
| 115 | s: qMin(a: 255, b: color.saturation()), |
| 116 | v: qMin<int>(a: 255, b: color.value() * 0.9)); |
| 117 | return color; |
| 118 | } |
| 119 | |
| 120 | QT_END_NAMESPACE |
| 121 | |
| 122 | #include "moc_qquickfusionstyle_p.cpp" |
| 123 | |