This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.qml
186 lines (168 loc) · 4.78 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import QtQuick
import QtQuick.Window
import QtQuick.Controls
Window {
id: window
width: 800
height: 200
visible: true
title: qsTr("Writeboard")
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
color: "#444444"
FontLoader {
id: icons
source: Qt.resolvedUrl("fonts/icons.woff2")
}
// Header
MouseArea {
height: 50
width: parent.width
property point pos: Qt.point(0, 0)
onPressed: (mouse) => { pos = Qt.point(mouse.x, mouse.y) }
onPositionChanged: (mouse) => {
window.x += mouse.x - pos.x
window.y += mouse.y - pos.y
}
}
Button {
id: fillButton
anchors.left: parent.left
anchors.leftMargin: 8
height: 50
width: fillText.width+10
flat: true
Text {
id: fillText
renderType: Text.NativeRendering
font.pointSize: 12
color: "white"
text: ""
anchors.centerIn: parent
}
}
Button {
id: closeButton
anchors.left: parent.right
anchors.leftMargin: -50
width: 50
height: 50
flat: true
onClicked: { window.close() }
Text {
renderType: Text.NativeRendering
font.family: icons.font.family
font.pointSize: 24
color: "white"
text: String.fromCodePoint(0xe5cd)
anchors.centerIn: parent
}
}
Button {
id: spaceButton
anchors.top: closeButton.bottom
anchors.left: parent.right
anchors.leftMargin: -50
width: 50
height: 50
flat: true
Text {
renderType: Text.NativeRendering
font.family: icons.font.family
font.pointSize: 24
color: "white"
text: String.fromCodePoint(0xe256)
anchors.centerIn: parent
}
}
Button {
id: backspaceButton
anchors.top: spaceButton.bottom
anchors.left: parent.right
anchors.leftMargin: -50
width: 50
height: 50
flat: true
Text {
renderType: Text.NativeRendering
font.family: icons.font.family
font.pointSize: 24
color: "white"
text: String.fromCodePoint(0xe14a)
anchors.centerIn: parent
}
}
Button {
id: returnButton
anchors.top: backspaceButton.bottom
anchors.left: parent.right
anchors.leftMargin: -50
width: 50
height: 50
flat: true
Text {
renderType: Text.NativeRendering
font.family: icons.font.family
font.pointSize: 24
color: "white"
text: String.fromCodePoint(0xe31b)
anchors.centerIn: parent
}
}
// Canvas
Rectangle {
anchors.left: parent.left
anchors.leftMargin: 8
anchors.top: parent.top
anchors.topMargin: 50
width: parent.width-58
height: parent.height-58
color: "#535353"
Canvas {
id: canvas
anchors.fill: parent
property point lastPos: Qt.point(0, 0)
property point pos: Qt.point(0, 0)
property bool draw: true
MouseArea {
anchors.fill: parent
onPressed: (mouse) => {
canvas.draw = true
canvas.lastPos = Qt.point(mouse.x, mouse.y)
canvas.pos = Qt.point(mouse.x, mouse.y)
canvas.requestPaint()
}
onReleased: {
canvas.draw = false
canvas.save("/tmp/writeboard.png")
}
onPositionChanged: (mouse) => {
canvas.pos = Qt.point(mouse.x, mouse.y)
canvas.requestPaint()
}
}
onPaint: {
if (canvas.draw && canvas.pos != canvas.lastPos) {
var ctx = getContext("2d")
ctx.lineWidth = 5
ctx.strokeStyle = "#b3b3b3"
ctx.lineCap = "round"
ctx.lineJoin = "round"
ctx.beginPath()
ctx.moveTo(canvas.lastPos.x, canvas.lastPos.y)
ctx.lineTo(canvas.pos.x, canvas.pos.y)
canvas.lastPos = canvas.pos
ctx.stroke()
}
}
}
// Guiding line
Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 110
width: parent.width-32
height: 2
color: "grey"
}
}
}