-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
118 lines (105 loc) · 2.2 KB
/
main.qml
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import QtQuick 2.5
Item {
id: root
width: 240
height: 240
signal clicked
property alias source: image.source
property int centerX: 100
property int centerY: 0
property int radius: 80
property bool positionLocked: false
property bool nudging: false
MouseArea {
cursorShape: Qt.CrossCursor
anchors.fill: parent
hoverEnabled: true
onClicked: {
positionLocked = true
nudging = true
okButton.visible = true
}
onPositionChanged: {
if (!positionLocked) {
centerX = mouse.x
centerY = mouse.y
canvas.requestPaint()
}
}
onPressed: {
positionLocked = false
}
onReleased: {
positionLocked = true
}
}
Image {
id: image
source: "./reference-images/Reflectance-Template-2.3.png"
}
Button {
id: okButton
visible: false
width: 100
height: 50
x: parent.width/2 - width/2
y: parent.height - 100
bgColor: "blue"
text: "OK"
opacity: 0.5
onClicked: {
root.clicked()
}
}
Canvas {
id: canvas
anchors.fill: parent
focus: true
onPaint: {
var ctx = getContext("2d")
ctx.reset()
ctx.beginPath()
ctx.fillStyle = "rgba(255,0,0,0.5)"
ctx.moveTo(centerX, centerY)
ctx.arc(centerX, centerY, radius, 0, 2*Math.PI, false)
ctx.lineTo(centerX, centerY)
ctx.fill()
}
Keys.onPressed: {
if (event.key == Qt.Key_Left) {
centerX--
event.accepted = true;
}
else if (event.key == Qt.Key_Right) {
centerX++
event.accepted = true;
}
else if (event.key == Qt.Key_Up) {
if (event.modifiers & Qt.ControlModifier) {
if (radius >= 1) {
radius++
}
}
else {
centerY--
}
event.accepted = true;
}
else if (event.key == Qt.Key_Down) {
if (event.modifiers & Qt.ControlModifier) {
if (radius >= 1) {
radius--
}
}
else {
centerY++
}
event.accepted = true;
}
else if (event.key == Qt.Key_Return) {
root.clicked()
}
canvas.requestPaint()
}
}
}