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 }
57 imagePath: "widgets/switch"
58 prefix: "active"
59 }
61 id: button
62
63 x: Math.max(0, Math.min(parent.width - width, root.control.visualPosition * parent.width - (width / 2)))
64
65 anchors.verticalCenter: parent.verticalCenter
66
67 svg: switchSvg
68 elementId: root.control.down ? "handle-pressed" : (root.control.hovered || root.control.focus ? "handle-hover" : "handle")
69
70 implicitWidth: naturalSize.width
71 implicitHeight: naturalSize.height
72
73 Behavior on x {
74 enabled: !root.control.down && Kirigami.Units.shortDuration > 0
75 // Can't use XAnimator, since it doesn't update x during the animation, so the active
76 // background is not animated.
77 NumberAnimation {
78 duration: Kirigami.Units.shortDuration
79 easing.type: Easing.InOutQuad
80 }
81 }
83 svg: switchSvg
84 z: -1
85 anchors.centerIn: parent
86 implicitWidth: naturalSize.width
87 implicitHeight: naturalSize.height
88 elementId: "handle-shadow"
89 visible: enabled && !root.control.down
90 }
92 anchors.centerIn: parent
93 implicitWidth: naturalSize.width
94 implicitHeight: naturalSize.height
95 svg: switchSvg
96 elementId: "handle-focus"
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 }
108}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:10:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.