Libplasma

Dial.qml
1/*
2 SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7import QtQuick
8import QtQuick.Templates as T
9import org.kde.ksvg as KSvg
10//NOTE: importing PlasmaCore is necessary in order to make KSvg load the current Plasma Theme
11import org.kde.plasma.core as PlasmaCore
12import org.kde.kirigami as Kirigami
13import "private" as Private
14
15T.Dial {
16 id: control
17
18 implicitWidth: Kirigami.Units.gridUnit * 5
19 implicitHeight: implicitWidth
20 hoverEnabled: true
21 onPositionChanged: canvas.requestPaint()
22
23 background:Canvas {
24 id: canvas
25 width: control.availableWidth
26 height: control.availableHeight
27 onPaint: {
28 var ctx = getContext("2d");
29 ctx.reset();
30
31 var centreX = width / 2;
32 var centreY = height / 2;
33
34 ctx.globalAlpha = 0.3;
35 ctx.beginPath();
36 ctx.strokeStyle = control.Kirigami.Theme.textColor;
37 ctx.lineWidth=5;
38 ctx.arc(centreX, centreY, width/2.4, 0, 2*Math.PI, false);
39 ctx.stroke();
40 ctx.globalAlpha = 1;
41
42 ctx.beginPath();
43 ctx.strokeStyle = control.Kirigami.Theme.highlightColor;
44 ctx.lineWidth=5;
45 ctx.arc(centreX, centreY, width/2.4, 0.7*Math.PI, 1.6*Math.PI * control.position - 1.25*Math.PI, false);
46 ctx.stroke();
47 }
48 }
49
50 KSvg.Svg {
51 id: grooveSvg
52 imagePath: "widgets/slider"
53 //FIXME: can this be made not necessary/less hacky?
54 colorSet: control.Kirigami.Theme.colorSet
55 }
56 handle: Item {
57 x: (control.width/2) + Math.cos((-(control.angle-90)*Math.PI)/180) * (control.width/2-width/2) - width/2
58 y: (control.height/2) + Math.sin(((control.angle-90)*Math.PI)/180) * (control.height/2-height/2) - height/2
59
60 implicitHeight: Math.floor(Kirigami.Units.gridUnit * 1.6)
61 implicitWidth: implicitHeight
62
63 Private.RoundShadow {
64 id: roundShadow
65 anchors.fill: parent
66 state: {
67 if (control.pressed) {
68 return "hidden"
69 } else if (control.hovered) {
70 return "hover"
71 } else if (control.activeFocus) {
72 return "focus"
73 } else {
74 return "shadow"
75 }
76 }
77 }
78
80 svg: KSvg.Svg {
81 id: buttonSvg
82 imagePath: "widgets/actionbutton"
83 }
84 elementId: control.pressed ? "pressed" : "normal"
85 width: Math.floor(parent.height/2) * 2
86 height: width
87 anchors.centerIn: parent
88 Behavior on opacity {
89 enabled: Kirigami.Units.longDuration > 0
90 NumberAnimation { duration: Kirigami.Units.longDuration }
91 }
92 }
93 }
94}
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.