Libplasma

SwitchIndicator.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
8import QtQuick
9import QtQuick.Templates as T
10import org.kde.ksvg as KSvg
11import org.kde.kirigami as Kirigami
12import "private" as Private
14Item {
15 id: root
16
17 required property T.AbstractButton control
18
19 implicitWidth: inactive.implicitWidth
20 implicitHeight: Math.max(inactive.implicitHeight, button.implicitHeight)
21
22 layer.enabled: opacity < 1
23 opacity: control.enabled ? 1 : 0.6
24
25 KSvg.Svg {
26 id: switchSvg
27 imagePath: "widgets/switch"
28 // FIXME
29 colorSet: root.control.Kirigami.Theme.colorSet
30 }
31
33 id: inactive
34 anchors {
35 left: parent.left
36 right: parent.right
37 leftMargin: 1
38 rightMargin: 1
39 verticalCenter: parent.verticalCenter
40 }
41 implicitHeight: switchSvg.hasElement("hint-bar-size")
42 ? switchSvg.elementSize("hint-bar-size").height
43 : button.implicitHeight
44 implicitWidth: switchSvg.hasElement("hint-bar-size")
45 ? switchSvg.elementSize("hint-bar-size").width
46 : root.implicitHeight * 2
47 imagePath: "widgets/switch"
48 prefix: "inactive"
49 }
51 anchors {
52 left: inactive.left
53 top: inactive.top
54 bottom: inactive.bottom
55 right: button.right
56 // This is to avoid the switch underneath
57 // to be seen on the edge of the switch
58 // button due to e.g. antialiasing
59 rightMargin: 1
60 leftMargin: 1
61 }
62 imagePath: "widgets/switch"
63 prefix: "active"
64 }
66 id: button
67
68 x: Math.max(0, Math.min(parent.width - width, root.control.visualPosition * parent.width - (width / 2)))
69
70 anchors.verticalCenter: parent.verticalCenter
71
72 svg: switchSvg
73 elementId: root.control.down ? "handle-pressed" : ( (root.control.enabled && root.control.hovered) || root.control.focus ? "handle-hover" : "handle")
74
75 implicitWidth: naturalSize.width
76 implicitHeight: naturalSize.height
77
78 Behavior on x {
79 enabled: !root.control.down && Kirigami.Units.shortDuration > 0
80 // Can't use XAnimator, since it doesn't update x during the animation, so the active
81 // background is not animated.
82 NumberAnimation {
83 duration: Kirigami.Units.shortDuration
84 easing.type: Easing.InOutQuad
85 }
86 }
88 svg: switchSvg
89 z: -1
90 anchors.centerIn: parent
91 implicitWidth: naturalSize.width
92 implicitHeight: naturalSize.height
93 elementId: "handle-shadow"
94 visible: enabled && !root.control.down
95 }
97 anchors.centerIn: parent
98 implicitWidth: naturalSize.width
99 implicitHeight: naturalSize.height
100 svg: switchSvg
101 elementId: "handle-focus"
102 visible: opacity > 0
103 opacity: root.control.visualFocus
104 Behavior on opacity {
105 enabled: Kirigami.Units.longDuration > 0
106 NumberAnimation {
107 duration: Kirigami.Units.longDuration
108 easing.type: Easing.OutCubic
109 }
110 }
111 }
112 }
113}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 11:50:52 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.