-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathColorWheel.qml
More file actions
74 lines (66 loc) · 1.88 KB
/
Copy pathColorWheel.qml
File metadata and controls
74 lines (66 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import QtQuick
import Quickshell
import qs.Commons
import qs.Ui
Item {
id: root
visible: lightOn && hasColor && pickerOpen && !themeSynced
width: Style.space(180)
height: Style.space(180)
anchors.horizontalCenter: parent.horizontalCenter
property bool lightOn: true
property bool hasColor: false
property bool pickerOpen: false
property bool themeSynced: false
property real initialHue: 0
property real initialSat: 0
signal colorSelected(real hue, real sat)
property real dragHue: initialHue
property real dragSat: initialSat
property bool picking: false
Image {
anchors.fill: parent
source: Qt.resolvedUrl("hsv_wheel.png")
fillMode: Image.Stretch
smooth: true
}
Rectangle {
width: 12
height: 12
radius: 6
border.color: "#ffffff"
border.width: 2
color: "transparent"
x: root.width / 2
+ Math.cos(-Math.PI / 2 + (root.dragHue / 65535) * 2 * Math.PI)
* (root.dragSat / 254) * (root.width / 2) - width / 2
y: root.height / 2
+ Math.sin(-Math.PI / 2 + (root.dragHue / 65535) * 2 * Math.PI)
* (root.dragSat / 254) * (root.height / 2) - height / 2
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
function apply(x, y) {
var c = root.width / 2
var dx = x - c
var dy = y - c
var dist = Math.sqrt(dx * dx + dy * dy)
if (dist > c) return
var hue01 = (((Math.atan2(dy, dx) + Math.PI / 2) / (2 * Math.PI)) % 1 + 1) % 1
root.dragHue = Math.round(hue01 * 65535)
root.dragSat = Math.round((dist / c) * 254)
}
onPressed: function(mouse) {
root.picking = true
apply(mouse.x, mouse.y)
}
onPositionChanged: function(mouse) {
if (root.picking) apply(mouse.x, mouse.y)
}
onReleased: function(mouse) {
root.picking = false
root.colorSelected(root.dragHue, root.dragSat)
}
}
}