plasma-framework/src/declarativeimports/plasmacomponents3/Dial.qml
Nate Graham 5447cef2d8 Port to singleton Units
The context property version is slower to access and won't be supported
in Qt6. Let's port away from it and use the singleton version instead.

Here was my full process for making this change:

1. Made the change with `find . -name '*.qml' | xargs perl -pi -e 's/units\./PlasmaCore\.Units\./g'`
2. Verified no more occurrences with `grep -r " units."`
3. Made sure this didn't change any comments in a silly way by inspecting the output of `git diff | grep "+   " | grep "//"`
4. Manually inspected the full git diff to make sure there were no other unintentional or silly changes (there were none)
5. verified that all changed files have the PlasmaCore import with the correct name with `for FILE in `git status | grep modified | cut -d ":" -f 3`; do grep -q "as PlasmaCore" $FILE || echo "$FILE needs the PlasmaCore import"; done` (one needed the import)
2021-03-07 13:34:47 +00:00

90 lines
2.7 KiB
QML

/*
SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.6
import QtQuick.Templates @QQC2_VERSION@ as T
import org.kde.plasma.core 2.0 as PlasmaCore
import "private" as Private
T.Dial {
id: control
implicitWidth: PlasmaCore.Units.gridUnit * 5
implicitHeight: implicitWidth
hoverEnabled: true
onPositionChanged: canvas.requestPaint()
background:Canvas {
id: canvas
width: control.availableWidth
height: control.availableHeight
onPaint: {
var ctx = getContext("2d");
ctx.reset();
var centreX = width / 2;
var centreY = height / 2;
ctx.globalAlpha = 0.3;
ctx.beginPath();
ctx.strokeStyle = control.PlasmaCore.ColorScope.textColor;
ctx.lineWidth=5;
ctx.arc(centreX, centreY, width/2.4, 0, 2*Math.PI, false);
ctx.stroke();
ctx.globalAlpha = 1;
ctx.beginPath();
ctx.strokeStyle = control.PlasmaCore.ColorScope.highlightColor;
ctx.lineWidth=5;
ctx.arc(centreX, centreY, width/2.4, 0.7*Math.PI, 1.6*Math.PI * control.position - 1.25*Math.PI, false);
ctx.stroke();
}
}
PlasmaCore.Svg {
id: grooveSvg
imagePath: "widgets/slider"
colorGroup: PlasmaCore.ColorScope.colorGroup
}
handle: Item {
x: (control.width/2) + Math.cos((-(control.angle-90)*Math.PI)/180) * (control.width/2-width/2) - width/2
y: (control.height/2) + Math.sin(((control.angle-90)*Math.PI)/180) * (control.height/2-height/2) - height/2
implicitHeight: Math.floor(PlasmaCore.Units.gridUnit*1.6)
implicitWidth: implicitHeight
Private.RoundShadow {
id: roundShadow
anchors.fill: parent
state: {
if (control.pressed) {
return "hidden"
} else if (control.hovered) {
return "hover"
} else if (control.activeFocus) {
return "focus"
} else {
return "shadow"
}
}
}
PlasmaCore.SvgItem {
svg: PlasmaCore.Svg {
id: buttonSvg
imagePath: "widgets/actionbutton"
}
elementId: control.pressed? "pressed" : "normal"
width: Math.floor(parent.height/2) * 2
height: width
anchors.centerIn: parent
Behavior on opacity {
NumberAnimation { duration: PlasmaCore.Units.longDuration }
}
}
}
}