Debian Codegraph @

v1/themes/plastik/package/contents/ui/PlastikButton.qml

raw
1 /*
2 SPDX-FileCopyrightText: 2012 Martin Gräßlin <[email protected]>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 import QtQuick
7 import org.kde.kwin.decoration
8 import org.kde.kwin.decorations.plastik
9
10 DecorationButton {
11 id: button
12 function colorize() {
13 var highlightColor = null;
14 if (button.pressed) {
15 if (button.buttonType == DecorationOptions.DecorationButtonClose) {
16 highlightColor = colorHelper.foreground(decoration.client.active, ColorHelper.NegativeText);
17 } else {
18 highlightColor = options.titleBarColor;
19 }
20 highlightColor = colorHelper.shade(highlightColor, ColorHelper.ShadowShade);
21 highlightColor = colorHelper.multiplyAlpha(highlightColor, 0.3);
22 } else if (button.hovered) {
23 if (button.buttonType == DecorationOptions.DecorationButtonClose) {
24 highlightColor = colorHelper.foreground(decoration.client.active, ColorHelper.NegativeText);
25 } else {
26 highlightColor = options.titleBarColor;
27 }
28 highlightColor = colorHelper.shade(highlightColor, ColorHelper.LightShade, Math.min(1.0, colorHelper.contrast + 0.4));
29 highlightColor = colorHelper.multiplyAlpha(highlightColor, 0.6);
30 }
31 if (highlightColor) {
32 button.surfaceTop = Qt.tint(button.baseSurfaceTop, highlightColor);
33 button.surfaceBottom = Qt.tint(button.baseSurfaceBottom, highlightColor);
34 highlightColor = colorHelper.multiplyAlpha(highlightColor, 0.4);
35 button.conturTop = Qt.tint(button.baseConturTop, highlightColor);
36 button.conturBottom = Qt.tint(button.baseConturBottom, highlightColor);
37 } else {
38 button.conturTop = button.baseConturTop;
39 button.conturBottom = button.baseConturBottom;
40 button.surfaceTop = button.baseSurfaceTop;
41 button.surfaceBottom = button.baseSurfaceBottom;
42 }
43 }
44 property real size
45 property color conturTop
46 property color conturBottom
47 property color surfaceTop
48 property color surfaceBottom
49 property color baseConturTop: colorHelper.shade(options.titleBarColor, ColorHelper.DarkShade, colorHelper.contrast - 0.4)
50 property color baseConturBottom: colorHelper.shade(options.titleBarColor, ColorHelper.MidShade)
51 property color baseSurfaceTop: colorHelper.shade(options.titleBarColor, ColorHelper.MidlightShade, colorHelper.contrast - 0.4)
52 property color baseSurfaceBottom: colorHelper.shade(options.titleBarColor, ColorHelper.LightShade, colorHelper.contrast - 0.4)
53 Behavior on conturTop {
54 ColorAnimation { duration: root.animateButtons ? root.animationDuration : 0 }
55 }
56 Behavior on conturBottom {
57 ColorAnimation { duration: root.animateButtons ? root.animationDuration : 0 }
58 }
59 Behavior on surfaceTop {
60 ColorAnimation { duration: root.animateButtons ? root.animationDuration : 0 }
61 }
62 Behavior on surfaceBottom {
63 ColorAnimation { duration: root.animateButtons ? root.animationDuration : 0 }
64 }
65 width: size
66 height: size
67 Rectangle {
68 // Intentionally not using Kirigami.Units.cornerRadius to mimic a
69 // particular style
70 radius: 2
71 smooth: true
72 anchors.fill: parent
73 gradient: Gradient {
74 GradientStop {
75 position: 0.0
76 color: button.conturTop
77 }
78 GradientStop {
79 position: 1.0
80 color: button.conturBottom
81 }
82 }
83 Rectangle {
84 // Intentionally not using Kirigami.Units.cornerRadius to mimic a
85 // particular style
86 radius: 2
87 smooth: true
88 anchors {
89 fill: parent
90 leftMargin: 1
91 rightMargin: 1
92 topMargin: 1
93 bottomMargin: 1
94 }
95 gradient: Gradient {
96 GradientStop {
97 position: 0.0
98 color: button.surfaceTop
99 }
100 GradientStop {
101 position: 1.0
102 color: button.surfaceBottom
103 }
104 }
105 }
106 }
107 Item {
108 property int imageWidth: button.width > 14 ? button.width - 2 * Math.floor(button.width/3.5) : button.width - 6
109 property int imageHeight: button.height > 14 ? button.height - 2 * Math.floor(button.height/3.5) : button.height - 6
110 property string source: "image://plastik/" + button.buttonType + "/" + decoration.client.active + "/" + ((buttonType == DecorationOptions.DecorationButtonMaximizeRestore) ? decoration.client.maximized : button.toggled)
111 anchors.fill: parent
112 Image {
113 id: shadowImage
114 x: button.x + button.width / 2 - width / 2 + 1
115 y: button.y + button.height / 2 - height / 2 + 1
116 source: parent.source + "/true"
117 width: parent.imageWidth
118 height: parent.imageHeight
119 sourceSize.width: width
120 sourceSize.height: height
121 visible: !button.pressed
122 }
123 Image {
124 id: image
125 x: button.x + button.width / 2 - width / 2
126 y: button.y + button.height / 2 - height / 2 + (button.pressed ? 1 : 0)
127 source: parent.source
128 width: parent.imageWidth
129 height: parent.imageHeight
130 sourceSize.width: width
131 sourceSize.height: height
132 }
133 }
134 Component.onCompleted: {
135 colorize();
136 if (buttonType == DecorationOptions.DecorationButtonQuickHelp) {
137 visible = Qt.binding(function() { return decoration.client.providesContextHelp});
138 }
139 if (buttonType == DecorationOptions.DecorationButtonApplicationMenu) {
140 visible = Qt.binding(function() { return decoration.client.hasApplicationMenu; });
141 }
142 }
143 onHoveredChanged: colorize()
144 onPressedChanged: colorize()
145 Connections {
146 target: decoration.client
147 function onActiveChanged() {
148 button.colorize()
149 }
150 }
151 Connections {
152 target: options
153 function onColorsChanged() {
154 button.colorize();
155 }
156 }
157 }