Libplasma

RadioIndicator.qml
1/*
2 SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8pragma ComponentBehavior: Bound
9
10import QtQuick
11import QtQuick.Templates as T
12import org.kde.ksvg as KSvg
13//NOTE: importing PlasmaCore is necessary in order to make KSvg load the current Plasma Theme
14import org.kde.plasma.core as PlasmaCore
15import org.kde.kirigami as Kirigami
16import "private" as P
17
18Item {
19 id: root
20
21 required property T.AbstractButton control
22
23 property size hintSize: radioButtonSvg.fromCurrentImageSet && radioButtonSvg.hasElement("hint-size")
24 ? radioButtonSvg.elementSize("hint-size")
25 : Qt.size(Kirigami.Units.iconSizes.small, Kirigami.Units.iconSizes.small)
26
27 implicitWidth: hintSize.width
28 implicitHeight: hintSize.height
29 opacity: control.enabled ? 1 : 0.5
30 layer.enabled: opacity < 1
31
32 KSvg.Svg {
33 id: radioButtonSvg
34 imagePath: "widgets/radiobutton"
35 }
36
37 Loader {
38 anchors.fill: parent
39 sourceComponent: radioButtonSvg.fromCurrentImageSet
40 // Hardcode breeze-light and breeze-dark because fromCurrentImageSet is
41 // false for them. This is because they don't contain any SVGs and
42 // inherit all of them from the default theme.
43 || KSvg.ImageSet.imageSetName === "breeze-light"
44 || KSvg.ImageSet.imageSetName === "breeze-dark"
45 ? radiobuttonComponent : compatibilityComponent
46 }
47
48 // Uses newer radiobutton.svg
49 Component {
50 id: radiobuttonComponent
52 svg: radioButtonSvg
53 elementId: "normal"
54 anchors.centerIn: parent
55 implicitWidth: naturalSize.width
56 implicitHeight: naturalSize.height
58 z: -1
59 svg: radioButtonSvg
60 elementId: "shadow"
61 anchors.centerIn: parent
62 implicitWidth: naturalSize.width
63 implicitHeight: naturalSize.height
64 visible: opacity > 0
65 opacity: enabled && !root.control.down
66 Behavior on opacity {
67 enabled: root.control.down && Kirigami.Units.longDuration > 0
68 NumberAnimation {
69 duration: Kirigami.Units.longDuration
70 easing.type: Easing.OutCubic
71 }
72 }
73 }
75 svg: radioButtonSvg
76 elementId: "checked"
77 anchors.centerIn: parent
78 implicitWidth: naturalSize.width
79 implicitHeight: naturalSize.height
80 visible: opacity > 0
81 opacity: (root.control.checked || root.control.down)
82 && !(root.control instanceof T.ItemDelegate && root.control.highlighted)
83 Behavior on opacity {
84 enabled: (root.control.checked || root.control.down) && Kirigami.Units.longDuration > 0
85 NumberAnimation {
86 duration: Kirigami.Units.longDuration
87 easing.type: Easing.OutCubic
88 }
89 }
90 }
92 svg: radioButtonSvg
93 elementId: "focus"
94 anchors.centerIn: parent
95 implicitWidth: naturalSize.width
96 implicitHeight: naturalSize.height
97 visible: opacity > 0
98 opacity: root.control.visualFocus
99 Behavior on opacity {
100 enabled: Kirigami.Units.longDuration > 0
101 NumberAnimation {
102 duration: Kirigami.Units.longDuration
103 easing.type: Easing.OutCubic
104 }
105 }
106 }
107 KSvg.SvgItem {
108 svg: radioButtonSvg
109 elementId: "hover"
110 anchors.centerIn: parent
111 implicitWidth: naturalSize.width
112 implicitHeight: naturalSize.height
113 visible: opacity > 0
114 opacity: root.control.hovered
115 Behavior on opacity {
116 enabled: root.control.hovered && Kirigami.Units.longDuration > 0
117 NumberAnimation {
118 duration: Kirigami.Units.longDuration
119 easing.type: Easing.OutCubic
120 }
121 }
122 }
123 KSvg.SvgItem {
124 svg: radioButtonSvg
125 elementId: "symbol"
126 anchors.centerIn: parent
127 implicitWidth: naturalSize.width
128 implicitHeight: naturalSize.height
129 visible: scale > 0
130 scale: root.control.checked
131 Behavior on scale {
132 enabled: Kirigami.Units.longDuration > 0
133 NumberAnimation {
134 duration: Kirigami.Units.longDuration
135 easing.type: Easing.OutCubic
136 }
137 }
138 }
139 }
140 }
141
142 // Uses older combination of actionbutton.svg and checkmarks.svg.
143 // NOTE: Do not touch this except to fix bugs. This is for compatibility.
144 Component {
145 id: compatibilityComponent
146 KSvg.SvgItem {
147 svg: KSvg.Svg {
148 id: buttonSvg
149 imagePath: "widgets/actionbutton"
150 }
151 elementId: "normal"
152
153 anchors.centerIn: parent
154 implicitWidth: implicitHeight
155 implicitHeight: Kirigami.Units.iconSizes.small
156
157 KSvg.SvgItem {
158 id: checkmark
159 svg: KSvg.Svg {
160 id: checkmarksSvg
161 imagePath: "widgets/checkmarks"
162 }
163 elementId: "radiobutton"
164 opacity: root.control.checked ? 1 : 0
165 anchors {
166 fill: parent
167 }
168 Behavior on opacity {
169 enabled: Kirigami.Units.longDuration > 0
170 NumberAnimation {
171 duration: Kirigami.Units.longDuration
172 easing.type: Easing.InOutQuad
173 }
174 }
175 }
176 P.RoundShadow {
177 anchors.fill: parent
178 z: -1
179 state: root.control.activeFocus ? "focus" : (root.control.hovered ? "hover" : "shadow")
180 }
181 }
182 }
183}
QString imageSetName() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:34:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.