278 lines
8.9 KiB
QML
278 lines
8.9 KiB
QML
import QtQuick 2.12
|
|
import QtQuick.Controls 2.12
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import Controls 1.0 as Controls
|
|
import Cubo 1.0
|
|
|
|
ColumnLayout {
|
|
id: root
|
|
spacing: 20
|
|
|
|
GridLayout {
|
|
columns: 2
|
|
rowSpacing: 20
|
|
columnSpacing: 20
|
|
|
|
Controls.TitleLabel {
|
|
text: qsTr("Date")
|
|
}
|
|
|
|
Controls.TitleLabel {
|
|
text: qsTr("Time")
|
|
}
|
|
|
|
Controls.Frame {
|
|
GridLayout {
|
|
anchors.fill: parent
|
|
columns: 3
|
|
columnSpacing: 10
|
|
|
|
Controls.SubtitleLabel {
|
|
text: qsTr("Day")
|
|
Layout.alignment: Qt.AlignCenter
|
|
}
|
|
|
|
Controls.SubtitleLabel {
|
|
text: qsTr("Month")
|
|
Layout.alignment: Qt.AlignCenter
|
|
}
|
|
|
|
Controls.SubtitleLabel {
|
|
text: qsTr("Year")
|
|
Layout.alignment: Qt.AlignCenter
|
|
}
|
|
|
|
Controls.LineSeparator {
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Controls.LineSeparator {
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Controls.LineSeparator {
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Tumbler {
|
|
id: dayTumbler
|
|
model: {
|
|
switch (monthTumbler.currentIndex) {
|
|
case 0: return range(1, 31)
|
|
case 1: return range(1, yearTumbler.model[yearTumbler.currentIndex] % 4 || monthTumbler.currentIndex !== 1 ? 28 : 29)
|
|
case 2: return range(1, 31)
|
|
case 3: return range(1, 30)
|
|
case 4: return range(1, 31)
|
|
case 5: return range(1, 30)
|
|
case 6: return range(1, 31)
|
|
case 7: return range(1, 31)
|
|
case 8: return range(1, 30)
|
|
case 9: return range(1, 31)
|
|
case 10: return range(1, 30)
|
|
case 11: return range(1, 31)
|
|
default: return range(1, 0)
|
|
}
|
|
}
|
|
delegate: tumblerComponent
|
|
Layout.alignment: Qt.AlignCenter
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Tumbler {
|
|
id: monthTumbler
|
|
model: [
|
|
qsTr("January"),
|
|
qsTr("February"),
|
|
qsTr("March"),
|
|
qsTr("April"),
|
|
qsTr("May"),
|
|
qsTr("June"),
|
|
qsTr("July"),
|
|
qsTr("August"),
|
|
qsTr("September"),
|
|
qsTr("October"),
|
|
qsTr("November"),
|
|
qsTr("December")
|
|
]
|
|
delegate: tumblerComponent
|
|
Layout.alignment: Qt.AlignCenter
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Tumbler {
|
|
id: yearTumbler
|
|
model: range(2000, 200)
|
|
delegate: tumblerComponent
|
|
Layout.alignment: Qt.AlignCenter
|
|
Layout.fillWidth: true
|
|
}
|
|
}
|
|
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Controls.Frame {
|
|
GridLayout {
|
|
anchors.fill: parent
|
|
columns: 3
|
|
columnSpacing: 10
|
|
|
|
Controls.SubtitleLabel {
|
|
text: qsTr("Hour")
|
|
Layout.alignment: Qt.AlignCenter
|
|
}
|
|
|
|
Controls.SubtitleLabel {
|
|
text: qsTr("Minute")
|
|
Layout.alignment: Qt.AlignCenter
|
|
}
|
|
|
|
Controls.SubtitleLabel {
|
|
text: qsTr("Second")
|
|
Layout.alignment: Qt.AlignCenter
|
|
}
|
|
|
|
Controls.LineSeparator {
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Controls.LineSeparator {
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Controls.LineSeparator {
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Tumbler {
|
|
id: hoursTumbler
|
|
model: 24
|
|
delegate: tumblerComponent
|
|
Layout.alignment: Qt.AlignCenter
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Tumbler {
|
|
id: minutesTumbler
|
|
model: 60
|
|
delegate: tumblerComponent
|
|
Layout.alignment: Qt.AlignCenter
|
|
Layout.fillWidth: true
|
|
}
|
|
|
|
Tumbler {
|
|
id: secondsTumbler
|
|
model: 60
|
|
delegate: tumblerComponent
|
|
Layout.alignment: Qt.AlignCenter
|
|
Layout.fillWidth: true
|
|
}
|
|
}
|
|
|
|
Layout.fillWidth: true
|
|
}
|
|
}
|
|
|
|
RowLayout {
|
|
spacing: 20
|
|
|
|
Controls.OutlineButton {
|
|
text: qsTr("Read from board")
|
|
onClicked: BmsInterface.commands().sendTerminalCmd("checkUnixTime")
|
|
}
|
|
|
|
Controls.OutlineButton {
|
|
text: qsTr("Read from computer")
|
|
onClicked: {
|
|
const date = new Date()
|
|
|
|
yearTumbler.currentIndex = date.getFullYear() - 2000
|
|
monthTumbler.currentIndex = date.getMonth()
|
|
dayTumbler.currentIndex = date.getDate() - 1
|
|
|
|
hoursTumbler.currentIndex = date.getHours()
|
|
minutesTumbler.currentIndex = date.getMinutes()
|
|
secondsTumbler.currentIndex = date.getSeconds()
|
|
}
|
|
}
|
|
|
|
Controls.Button {
|
|
text: qsTr("Write to board")
|
|
onClicked: {
|
|
const date = new Date()
|
|
|
|
date.setFullYear(yearTumbler.model[yearTumbler.currentIndex])
|
|
date.setMonth(monthTumbler.currentIndex)
|
|
date.setDate(dayTumbler.currentIndex + 1)
|
|
|
|
date.setHours(hoursTumbler.currentIndex)
|
|
date.setMinutes(minutesTumbler.currentIndex)
|
|
date.setSeconds(secondsTumbler.currentIndex)
|
|
|
|
const localTimestamp = (Math.round(date / 1000) - date.getTimezoneOffset() * 60).toString(16)
|
|
BmsInterface.commands().sendTerminalCmd("setUnixTime " + localTimestamp)
|
|
}
|
|
}
|
|
}
|
|
|
|
Component {
|
|
id: tumblerComponent
|
|
|
|
Controls.SubtitleLabel {
|
|
text: modelData
|
|
opacity: 1.0 - Math.abs(Tumbler.displacement) / (Tumbler.tumbler.visibleItemCount / 2)
|
|
horizontalAlignment: Text.AlignHCenter
|
|
verticalAlignment: Text.AlignVCenter
|
|
}
|
|
}
|
|
|
|
Connections {
|
|
target: BmsInterface.commands()
|
|
enabled: root.visible
|
|
onPrintReceived: {
|
|
const lines = str.split(/\r?\n/)
|
|
for (const line of lines) {
|
|
if (line.includes("Year")) {
|
|
const value = extractValue(line)
|
|
if (value.length === 0) contine
|
|
yearTumbler.currentIndex = parseInt(value)
|
|
} else if (line.includes("Month")) {
|
|
const value = extractValue(line)
|
|
if (value.length === 0) contine
|
|
monthTumbler.currentIndex = parseInt(value) - 1
|
|
} else if (line.includes("Day")) {
|
|
const value = extractValue(line)
|
|
if (value.length === 0) contine
|
|
dayTumbler.currentIndex = parseInt(value) - 1
|
|
} else if (line.includes("Hours")) {
|
|
const value = extractValue(line)
|
|
if (value.length === 0) contine
|
|
hoursTumbler.currentIndex = parseInt(value)
|
|
} else if (line.includes("Minutes")) {
|
|
const value = extractValue(line)
|
|
if (value.length === 0) contine
|
|
minutesTumbler.currentIndex = parseInt(value)
|
|
} else if (line.includes("Seconds")) {
|
|
const value = extractValue(line)
|
|
if (value.length === 0) contine
|
|
secondsTumbler.currentIndex = parseInt(value)
|
|
}
|
|
}
|
|
}
|
|
|
|
function extractValue(valueHolder) {
|
|
const values = valueHolder.split(":")
|
|
return values.length < 2 ? "" : values[1].trim()
|
|
}
|
|
}
|
|
|
|
function range(startAt, size) {
|
|
return [...Array(size).keys()].map(i => i + startAt);
|
|
}
|
|
|
|
onVisibleChanged: if (visible) {
|
|
BmsInterface.commands().sendTerminalCmd("checkUnixTime")
|
|
}
|
|
}
|