-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
360 lines (313 loc) · 10.1 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*******************************************************************/
/* Original File Name: main.qml */
/* Date: 21-06-2018 */
/* Developer: Dionysus Benstein */
/* Copyright © 2018 Dionysus Benstein. All rights reserved. */
/* Description: Основное окно программы. */
/*******************************************************************/
import QtQuick 2.11
import QtQuick.Window 2.3
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.4
import Qt.labs.settings 1.0
import QtQuick.Controls.Material 2.3
import com.enclave.counter 1.4
ApplicationWindow {
id: mainWindow
width: 640
height: 480
visible: true
minimumWidth: 550
minimumHeight: 350
flags: Qt.FramelessWindowHint | Qt.Window
Material.theme: appBar.popupMenu.currentIndex === 0 ? Material.Light : Material.Dark
Material.accent: primaryColor
readonly property color closeButtonColor: "#e81123"
readonly property color lightFontColor: "#9a9a9a"
readonly property color darkFontColor: "#404040"
readonly property string appVersion: "2.9.4"
property color primaryColor: "#e91e63"
property color lightColor: "#ff6090"
property color darkColor: "#b0003a"
property int borderSize: 3
property int cornerSize: 5
property int previousX
property int previousY
function isMaximize() {
return mainWindow.visibility === ApplicationWindow.Maximized
}
FontLoader { id: robotoThinFont; source: "fonts/Roboto-Thin_0.ttf" }
FontLoader { id: robotoLightFont; source: "fonts/Roboto-Light.ttf" }
FontLoader { id: robotoMediumFont; source: "fonts/Roboto-Medium.ttf" }
FontLoader { id: robotoRegularFont; source: "fonts/Roboto-Regular_0.ttf" }
MouseArea {
id: bottomArea
height: borderSize
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
leftMargin: cornerSize
rightMargin: cornerSize
}
cursorShape: Qt.SizeVerCursor
onPressed: previousY = mouseY
onMouseYChanged: {
var dy = mouseY - previousY
if ((mainWindow.height + dy) >= mainWindow.minimumHeight) {
mainWindow.setHeight(mainWindow.height + dy)
}
}
}
MouseArea {
id: leftArea
width: borderSize
anchors {
left: parent.left
top: appBar.bottom
bottom: bottomArea.top
}
cursorShape: Qt.SizeHorCursor
onPressed: previousX = mouseX
onMouseXChanged: {
var dx = mouseX - previousX
if ((mainWindow.width - dx) >= mainWindow.minimumWidth) {
mainWindow.setX(mainWindow.x + dx)
mainWindow.setWidth(mainWindow.width - dx)
}
}
}
MouseArea {
id: rightArea
width: borderSize
anchors {
right: parent.right
top: appBar.bottom
bottom: bottomArea.top
}
cursorShape: Qt.SizeHorCursor
onPressed: previousX = mouseX
onMouseXChanged: {
var dx = mouseX - previousX
if ((mainWindow.width + dx) >= mainWindow.minimumWidth) {
mainWindow.setWidth(mainWindow.width + dx)
}
}
}
MouseArea {
id: bottomLeftArea
height: cornerSize
width: cornerSize
anchors {
left: parent.left
bottom: parent.bottom
}
cursorShape: Qt.SizeBDiagCursor
onPressed: {
previousX = mouseX
previousY = mouseY
}
onMouseXChanged: {
var dx = mouseX - previousX
if ((mainWindow.width - dx) >= mainWindow.minimumWidth) {
mainWindow.setX(mainWindow.x + dx)
mainWindow.setWidth(mainWindow.width - dx)
}
}
onMouseYChanged: {
var dy = mouseY - previousY
if ((mainWindow.height + dy) >= mainWindow.minimumHeight) {
mainWindow.setHeight(mainWindow.height + dy)
}
}
}
MouseArea {
id: bottomRightArea
height: cornerSize
width: cornerSize
anchors {
right: parent.right
bottom: parent.bottom
}
cursorShape: Qt.SizeFDiagCursor
onPressed: {
previousX = mouseX
previousY = mouseY
}
onMouseXChanged: {
var dx = mouseX - previousX
if ((mainWindow.width + dx) >= mainWindow.minimumWidth) {
mainWindow.setWidth(mainWindow.width + dx)
}
}
onMouseYChanged: {
var dy = mouseY - previousY
if ((mainWindow.height + dy) >= mainWindow.minimumHeight) {
mainWindow.setHeight(mainWindow.height + dy)
}
}
}
MouseArea {
id: posChangedMouseArea
anchors {
left: leftArea.right
right: rightArea.left
top: appBar.bottom
bottom: bottomArea.top
}
onPositionChanged: if (isMaximize()) mainWindow.showNormal()
onDoubleClicked: {
previousX = mouseX
previousY = mouseY
isMaximize() ? mainWindow.showNormal() : mainWindow.showMaximized()
}
onPressed: {
previousX = mouseX
previousY = mouseY
}
onMouseXChanged: {
var dx = mouseX - previousX
mainWindow.setX(mainWindow.x + dx)
}
onMouseYChanged: {
var dy = mouseY - previousY
mainWindow.setY(mainWindow.y + dy)
}
}
TitleBar { id: titleBar }
AppBar { id: appBar }
Counter { id: backEnd }
ScrollView {
id: scrollView
anchors {
left: parent.left
right: parent.right
top: appBar.bottom
bottom: cbGrid.top
margins: 19
}
TextArea {
id: input
anchors.fill: input
focus: true
selectByMouse: true
persistentSelection: true
wrapMode: Text.Wrap
placeholderText: qsTr("Введите текст...")
ContextMenu { id: contextMenu; anchors.fill: parent }
}
}
GridLayout {
id: cbGrid
anchors {
bottom: parent.bottom
left: parent.left
margins: 19
}
rows: 2
columns: 2
CheckBox {
id: spacesCounter
text: qsTr(" Не учитывать пробелы")
onClicked: {
if (linesCounter.checked || wordsCounter.checked) {
wordsCounter.checked = false
linesCounter.checked = false
spacesCounter.checked = true
}
}
}
CheckBox {
id: signsCounter
text: qsTr(" Не учитывать знаки")
onClicked: {
if (linesCounter.checked || wordsCounter.checked) {
wordsCounter.checked = false
linesCounter.checked = false
signsCounter.checked = true
}
}
}
CheckBox {
id: linesCounter
text: qsTr(" Посчитать количество строк")
onClicked: {
if (wordsCounter.checked || signsCounter.checked || spacesCounter.checked) {
wordsCounter.checked = false
signsCounter.checked = false
spacesCounter.checked = false
linesCounter.checked = true
}
}
}
CheckBox {
id: wordsCounter;
text: qsTr(" Посчитать количество слов")
onClicked: {
if (linesCounter.checked || signsCounter.checked || spacesCounter.checked) {
linesCounter.checked = false
signsCounter.checked = false
spacesCounter.checked = false
wordsCounter.checked = true
}
}
}
}
Item {
width: 100
height: 100
anchors {
left: cbGrid.right
right: rightArea.left
top: scrollView.bottom
bottom: bottomArea.top
margins: 19
}
Text {
id: counter
anchors.centerIn: parent
color: Material.theme === Material.Dark ? "white" : darkFontColor
text: {
if (spacesCounter.checked) {
backEnd.lengthWithoutSpaces(input.text)
} else if (signsCounter.checked) {
backEnd.lengthWithoutSigns(input.text)
} else if (wordsCounter.checked) {
backEnd.wordsCounter(input.text)
} else if (linesCounter.checked) {
input.lineCount.toString()
} else {
input.text.length.toString()
}
}
font.pixelSize: 40
onTextChanged: {
textOpacityAnim.running = true
textScaleAnim.running = true
}
}
}
Settings {
id: settings
property alias currentLanguage: appBar.currentLanguage
property alias primaryColor: mainWindow.primaryColor
property alias lightColor: mainWindow.lightColor
property alias darkColor: mainWindow.darkColor
}
ScaleAnimator {
id: textScaleAnim
easing.type: Easing.OutCubic
target: counter
from: 0; to: 1
running: false
duration: 100
}
OpacityAnimator {
id: textOpacityAnim
easing.type: Easing.OutCubic
target: counter
from: 0; to: 1
running: false
duration: 100
}
}