-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
480 lines (407 loc) · 17.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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
import QtQuick
import QtQuick.Controls 2.15
import QtQuick 2.15
import QtQuick.Window 2.15
Window {
width: Screen.desktopAvailableWidth
height: Screen.desktopAvailableHeight
visible: true
title: qsTr("ChemicalCalculator")
Connections {
target: adapter
onMolecularWeightChanged: {
molecularWeightOutput.textInput = adapter.getMolecularWeight()
}
onErrorHappend: {
errorText.text = adapter.getError()
}
onEquivalentCalculated: {
equivalentInputItem.textInput = adapter.getEquivalent()
}
onResultCalculated: {
if(swip.currentIndex === swip.thirdPageNumber || swip.currentIndex === swip.secondPageNumber ) {
if (radioButtonInputItemTop.checkedState){
radioButtonInputItemTop.textInput = adapter.getResult()
}
if (radioButtonInputItemMiddle.checkedState){
radioButtonInputItemMiddle.textInput = adapter.getResult()
}
if (radioButtonInputItemBottom.checkedState) {
radioButtonInputItemBottom.textInput = adapter.getResult()
}
}
else {
insertDnaMassOutput.textInput = adapter.getResult()
}
}
}
QtObject {
id: _CONSTANTA
readonly property int topPanelHeight: Screen.desktopAvailableHeight / 20
readonly property color colorBackGround: "#5ccccc"
readonly property color colorPanel: "#009999"
readonly property color pageCaptionColor: "black"
readonly property color textButtonColor: "#4aff26"
readonly property color topPanelColor: "white"
readonly property int pageCaptionTextHeight: 24
readonly property int captionTextHeight: 18
readonly property int buttonBottomMargin: 20
readonly property int leftMargin: 20
readonly property int buttonHeight: Screen.desktopAvailableHeight / 10
readonly property int buttonRadius: 10
readonly property int textFieldHeight: 35
readonly property int textFieldWidth: 160
readonly property int textFieldBorderWidth: 2
readonly property int textWidth: 150
}
QtObject {
id: buffer
property string bufferStr: ""
property string formulaBuffer: ""
property string resultBuffer: ""
property string topRadioButtonBuffer: ""
property string middleRadioButtonBuffer: ""
property string bottomRadioButtonBuffer: ""
}
// 1. Переключение свайпом вместо меню
// 2. TODO: Реализовать клавиатуру без лишних символов с крупными кнопками
function saveInput() {
buffer.bufferStr = buffer.formulaBuffer
buffer.formulaBuffer = inputFormula.textInput
inputFormula.textInput = buffer.bufferStr
buffer.bufferStr = buffer.resultBuffer
buffer.resultBuffer = molecularWeightOutput.textInput
molecularWeightOutput.textInput = buffer.bufferStr
buffer.bufferStr = buffer.topRadioButtonBuffer
buffer.topRadioButtonBuffer = radioButtonInputItemTop.textInput
radioButtonInputItemTop.textInput = buffer.bufferStr
buffer.bufferStr = buffer.middleRadioButtonBuffer
buffer.middleRadioButtonBuffer = radioButtonInputItemMiddle.textInput
radioButtonInputItemMiddle.textInput = buffer.bufferStr
buffer.bufferStr = buffer.bottomRadioButtonBuffer
buffer.bottomRadioButtonBuffer = radioButtonInputItemBottom.textInput
radioButtonInputItemBottom.textInput = buffer.bufferStr
}
function saveCurrentPageInput() {
if(swip.currentIndex === swip.thirdPageNumber) {
saveInput()
}
if(swip.currentIndex === swip.secondPageNumber) {
if(swip.prevPageIndex === swip.thirdPageNumber) {
saveInput()
}
}
}
MySwip {
id: swip
anchors.fill: parent
onIndexChanged: {
saveCurrentPageInput()
}
}
MyTopPanel {
id: topPanel
anchors { horizontalCenter: parent.horizontalCenter; top: parent.top; }
height: parent.height / 20
width: parent.width
}
MyPageCaption {
id: pageCaption
anchors { top: topPanel.bottom; horizontalCenter: topPanel.horizontalCenter; }
width: topPanel.width
height: topPanel.height
text: swip.currentIndex === swip.firstPageNumber ? "Calculation of ligation" :
swip.currentIndex === swip.secondPageNumber ? "Molar concentration" : "Normal concentration"
}
function maxTextLenthChemicalFormula(){
return Math.max(inputFormula.textWidth, molecularWeightOutput.textWidth)
}
MyInputItem {
id: inputFormula
textCaption: "Chemical formula"
leftMarginInput: maxTextLenthChemicalFormula() + leftMarginText * 2
textFieldWidth: Math.min(parent.width - leftMarginInput - leftMarginText, 160)
anchors { horizontalCenter: pageCaption.horizontalCenter; top: pageCaption.bottom; topMargin: 30 }
visibleState: swip.currentIndex !== swip.firstPageNumber
inputValidator: RegularExpressionValidator {
regularExpression:
/[A-Za-z0-9\[\]()+-.,*]+/
}
}
MyInputItem {
id: molecularWeightOutput
textCaption: "Molecular weight"
leftMarginInput: maxTextLenthChemicalFormula() + leftMarginText * 2
textFieldWidth: Math.min(parent.width - leftMarginInput - leftMarginText, 160)
anchors { horizontalCenter: inputFormula.horizontalCenter; top: inputFormula.bottom; topMargin: 10}
visibleState: swip.currentIndex !== swip.firstPageNumber
readOnlyState: true
}
MyRadioButtonInputItem {
id: radioButtonInputItemTop
anchors { left: parent.left; top: molecularWeightOutput.bottom; topMargin: 10}
width: Math.min(parent.width / 2, 180)
height: radioButtonInputItemTop.textFieldHeight * 2
visibleState: swip.currentIndex !== swip.firstPageNumber
textButton: qsTr("Volume, L")
checkedState: true
onClicked: {
radioButtonInputItemMiddle.checkedState = false
radioButtonInputItemBottom.checkedState = false
}
methodHints: Qt.ImhDigitsOnly
}
MyRadioButtonInputItem {
id: radioButtonInputItemMiddle
anchors { left: parent.left; top: radioButtonInputItemTop.bottom; topMargin: 10}
width: Math.min(parent.width / 2, 180)
height: radioButtonInputItemMiddle.textFieldHeight * 2
visibleState: swip.currentIndex !== swip.firstPageNumber
textButton: swip.currentIndex === swip.secondPageNumber ?
qsTr("Molar concentration, mol/L")
: qsTr("Equivalent concentration, eq/L")
onClicked: {
radioButtonInputItemTop.checkedState = false
radioButtonInputItemBottom.checkedState = false
}
methodHints: Qt.ImhDigitsOnly
}
MyRadioButtonInputItem {
id: radioButtonInputItemBottom
anchors { left: parent.left; top: radioButtonInputItemMiddle.bottom; topMargin: 10}
width: Math.min(parent.width / 2, 180)
height: radioButtonInputItemBottom.textFieldHeight * 2
visibleState: swip.currentIndex !== swip.firstPageNumber
textButton: qsTr("Weight, g")
onClicked: {
radioButtonInputItemMiddle.checkedState = false
radioButtonInputItemTop.checkedState = false
}
methodHints: Qt.ImhDigitsOnly
}
MyInputItemVertical {
id: equivalentInputItem
width: parent.width / 2
height: equivalentInputItem.textFieldHeight * 2
anchors { left: radioButtonInputItemTop.right; top: radioButtonInputItemTop.top;}
visibleState: swip.currentIndex === swip.thirdPageNumber
}
function maxTextLenthThirdPage(){
return Math.max(Math.max(Math.max(Math.max(vectorDnaMassInput.textWidth, vectorDnaLengthInput.textWidth),
insertDnaLengthInput.textWidth), molarVectorInsertRatioLeftInput.textWidth), insertDnaMassOutput.textWidth)
}
MyInputItem {
id: vectorDnaMassInput
textCaption: "Vector DNA mass, ng"
leftMarginInput: maxTextLenthThirdPage() + leftMarginText * 2
textFieldWidth: Math.min(parent.width - leftMarginInput - leftMarginText, 160)
anchors { horizontalCenter: pageCaption.horizontalCenter; top: pageCaption.bottom; topMargin: 60 }
visibleState: swip.currentIndex === swip.firstPageNumber
methodHints: Qt.ImhDigitsOnly
}
MyInputItem {
id: vectorDnaLengthInput
textCaption: "Vector DNA length, bp"
leftMarginInput: maxTextLenthThirdPage() + leftMarginText * 2
textFieldWidth: Math.min(parent.width - leftMarginInput - leftMarginText, 160)
anchors { horizontalCenter: vectorDnaMassInput.horizontalCenter; top: vectorDnaMassInput.bottom; topMargin: 10 }
visibleState: swip.currentIndex === swip.firstPageNumber
methodHints: Qt.ImhDigitsOnly
}
MyInputItem {
id: insertDnaLengthInput
textCaption: "Insert DNA length, bp"
leftMarginInput: maxTextLenthThirdPage() + leftMarginText * 2
textFieldWidth: Math.min(parent.width - leftMarginInput - leftMarginText, 160)
anchors { horizontalCenter: vectorDnaLengthInput.horizontalCenter; top: vectorDnaLengthInput.bottom; topMargin: 10 }
visibleState: swip.currentIndex === swip.firstPageNumber
methodHints: Qt.ImhDigitsOnly
}
////////////////////////////////////
MyInputItem {
id: molarVectorInsertRatioLeftInput
textCaption: "Molar vector:insert ratio"
leftMarginInput: maxTextLenthThirdPage() + leftMarginText * 2
textFieldWidth: Math.min(parent.width - leftMarginInput - defaultMarginText, 50)
anchors { horizontalCenter: insertDnaLengthInput.horizontalCenter;
top: insertDnaLengthInput.bottom; topMargin: 10 }
visibleState: swip.currentIndex === swip.firstPageNumber
methodHints: Qt.ImhDigitsOnly
}
MyInputItem {
id: molarVectorInsertRatioRigthInput
textCaption: ":"
leftMarginText: molarVectorInsertRatioLeftInput.textWidth +
molarVectorInsertRatioLeftInput.textFieldWidth + defaultMarginText * 3
leftMarginInput: leftMarginText + defaultMarginText * 2
textFieldWidth: Math.min(parent.width - leftMarginInput - defaultMarginText, 50)
anchors { verticalCenter: molarVectorInsertRatioLeftInput.verticalCenter;
left: molarVectorInsertRatioLeftInput.rigth;}
visibleState: swip.currentIndex === swip.firstPageNumber
methodHints: Qt.ImhDigitsOnly
}
////////////////////////
MyInputItem {
id: insertDnaMassOutput
textCaption: "Insert DNA mass, ng"
leftMarginInput: maxTextLenthThirdPage() + leftMarginText * 2
textFieldWidth: Math.min(parent.width - leftMarginInput - leftMarginText, 160)
anchors { horizontalCenter: molarVectorInsertRatioLeftInput.horizontalCenter; top: molarVectorInsertRatioLeftInput.bottom; topMargin: 10 }
visibleState: swip.currentIndex === swip.firstPageNumber
readOnlyState: true
}
///////////////////////////////////////////////////////////////////
// Buttons
Button {
id: calculateButton
anchors.bottom: bottomErrorPanel.top
anchors.left: parent.left
anchors.leftMargin: (parent.width / 2 / 10) / 2
anchors.bottomMargin: _CONSTANTA.buttonBottomMargin
width: parent.width / 2 - (parent.width / 2 / 10)
height: _CONSTANTA.buttonHeight
text: qsTr("Calculate")
contentItem: Text {
text: parent.text
font.pointSize: 25
opacity: enabled ? 1.0 : 0.3
color: parent.down ? "#21be2b" : "#4aff26"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: parent.width
implicitHeight: parent.height
anchors.fill: parent
opacity: enabled ? 1 : 0.3
color: "#0c6460"
//border.color: control.down ? "#21be2b" : "#4aff26"
border.width: 1
radius: _CONSTANTA.buttonRadius
}
onClicked: {
calculate()
}
}
Button {
id: cleareButton
anchors.bottom: bottomErrorPanel.top
anchors.right: parent.right
anchors.rightMargin: (parent.width / 2 / 10) / 2
anchors.bottomMargin: _CONSTANTA.buttonBottomMargin
width: parent.width / 2 - (parent.width / 2 / 10)
height: _CONSTANTA.buttonHeight
text: qsTr("Clear")
contentItem: Text {
text: parent.text
font.pointSize: 25
opacity: enabled ? 1.0 : 0.3
color: parent.down ? "#21be2b" : "#4aff26"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: parent.width
implicitHeight: parent.height
anchors.fill: parent
opacity: enabled ? 1 : 0.3
color: "#0c6460"
//border.color: control.down ? "#21be2b" : "#4aff26"
border.width: 1
radius: _CONSTANTA.buttonRadius
}
onClicked: {
if (swip.currentIndex === swip.firstPageNumber)
cleareFirstPage()
else if (swip.currentIndex === swip.secondPageNumber)
cleareSecondPage()
else
cleareThirdPage()
}
}
///////////////////////////////////////////////////////////////////
Rectangle {
id: bottomErrorPanel
anchors.bottom: whiteBottomPanel.top
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width
height: _CONSTANTA.topPanelHeight
color: _CONSTANTA.colorPanel
Text {
id: errorText
width: parent.width
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
font.pointSize: _CONSTANTA.captionTextHeight
elide: Text.ElideNone
Timer {
interval: 5000; running: errorText !== ""; repeat: true
onTriggered: errorText.text = ""
}
}
}
Rectangle {
id: whiteBottomPanel
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width
height: _CONSTANTA.topPanelHeight
color: "white"
}
PageIndicator {
id: indicator
count: swip.count
currentIndex: swip.currentIndex
anchors.bottom: swip.bottom
anchors.horizontalCenter: swip.horizontalCenter
}
function calculate() {
if(swip.currentIndex === swip.thirdPageNumber || swip.currentIndex === swip.secondPageNumber) {
if (radioButtonInputItemTop.checkedState){
adapter.calculateVolume(
inputFormula.textInput, radioButtonInputItemMiddle.textInput,
radioButtonInputItemBottom.textInput, swip.currentIndex === swip.thirdPageNumber);
}
if (radioButtonInputItemMiddle.checkedState){
adapter.calculateConcentration(
inputFormula.textInput, radioButtonInputItemTop.textInput,
radioButtonInputItemBottom.textInput, swip.currentIndex === swip.thirdPageNumber);
}
if (radioButtonInputItemBottom.checkedState) {
adapter.calculateMass(
inputFormula.textInput, radioButtonInputItemTop.textInput,
radioButtonInputItemMiddle.textInput, swip.currentIndex === swip.thirdPageNumber);
}
}
if(swip.currentIndex === swip.firstPageNumber){
adapter.calculateLigation(
vectorDnaMassInput.textInput, vectorDnaLengthInput.textInput,
insertDnaLengthInput.textInput, molarVectorInsertRatioRigthInput.textInput,
molarVectorInsertRatioLeftInput.textInput)
}
}
function clearTextById(id) {
id.textInput = ""
}
function cleareFirstPage() {
clearTextById(vectorDnaMassInput)
clearTextById(vectorDnaLengthInput)
clearTextById(insertDnaLengthInput)
clearTextById(molarVectorInsertRatioLeftInput)
clearTextById(molarVectorInsertRatioRigthInput)
clearTextById(insertDnaMassOutput)
}
function cleareSecondPage() {
clearTextById(inputFormula)
clearTextById(molecularWeightOutput)
clearTextById(radioButtonInputItemTop)
clearTextById(radioButtonInputItemMiddle)
clearTextById(radioButtonInputItemBottom)
}
function cleareThirdPage() {
cleareSecondPage()
clearTextById(equivalentInputItem)
}
}