| 1 |
// SPDX-FileCopyrightText: 2018 James Turner |
| 2 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 3 |
|
| 4 |
import QtQuick 2.4 |
| 5 |
import FlightGear 1.0 |
| 6 |
|
| 7 |
FocusScope { |
| 8 |
id: root |
| 9 |
|
| 10 |
property alias label: label.text |
| 11 |
property bool enabled: true |
| 12 |
property var value: new Date() |
| 13 |
property bool isDuration: true |
| 14 |
|
| 15 |
implicitHeight: editFrame.height |
| 16 |
implicitWidth: label.implicitWidth + Style.margin + editFrame.width |
| 17 |
|
| 18 |
function updateCurrentTime() |
| 19 |
{ |
| 20 |
root.value = new Date(0, 0, 0, hours.value, minutes.value); |
| 21 |
} |
| 22 |
|
| 23 |
function setDurationMinutes(minutes) |
| 24 |
{ |
| 25 |
var d = new Date(0, 0, 0, 0, minutes); |
| 26 |
setTime(d); |
| 27 |
} |
| 28 |
|
| 29 |
function setTime(date) |
| 30 |
{ |
| 31 |
hours.value = date.getHours(); |
| 32 |
minutes.value = date.getMinutes(); |
| 33 |
updateCurrentTime(); |
| 34 |
} |
| 35 |
|
| 36 |
StyledText { |
| 37 |
id: label |
| 38 |
anchors.left: root.left |
| 39 |
anchors.leftMargin: Style.margin |
| 40 |
anchors.verticalCenter: parent.verticalCenter |
| 41 |
horizontalAlignment: Text.AlignRight |
| 42 |
enabled: root.enabled |
| 43 |
} |
| 44 |
|
| 45 |
Keys.onReturnPressed: { |
| 46 |
if (activeFocus) { |
| 47 |
focus = false; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
Rectangle { |
| 52 |
id: editFrame |
| 53 |
clip: true |
| 54 |
|
| 55 |
|
| 56 |
height: hours.height + Style.margin |
| 57 |
|
| 58 |
anchors.left: label.right |
| 59 |
anchors.leftMargin: Style.margin |
| 60 |
anchors.verticalCenter: parent.verticalCenter |
| 61 |
width: editRow.childrenRect.width + Style.roundRadius * 2 + 64 |
| 62 |
|
| 63 |
Row { |
| 64 |
id: editRow |
| 65 |
anchors { |
| 66 |
left: parent.left |
| 67 |
top: parent.top |
| 68 |
bottom: parent.bottom |
| 69 |
right: parent.right |
| 70 |
margins: Style.margin |
| 71 |
} |
| 72 |
|
| 73 |
DateTimeValueEdit { |
| 74 |
id: hours |
| 75 |
minValue: 0 |
| 76 |
maxValue: root.isDuration ? 9999 : 23 |
| 77 |
widthString: "00" |
| 78 |
nextToFocus: minutes |
| 79 |
anchors.verticalCenter: parent.verticalCenter |
| 80 |
onCommit: updateCurrentTime(); |
| 81 |
} |
| 82 |
|
| 83 |
StyledText { |
| 84 |
text: " : " |
| 85 |
anchors.verticalCenter: parent.verticalCenter |
| 86 |
enabled: root.enabled |
| 87 |
} |
| 88 |
|
| 89 |
DateTimeValueEdit { |
| 90 |
id: minutes |
| 91 |
minValue: 0 |
| 92 |
maxValue: 59 |
| 93 |
widthString: "00" |
| 94 |
anchors.verticalCenter: parent.verticalCenter |
| 95 |
previousToFocus: hours |
| 96 |
onCommit: updateCurrentTime(); |
| 97 |
} |
| 98 |
} // of time elements row |
| 99 |
|
| 100 |
// frame rectangle - we need this so we can clip our children |
| 101 |
// but ensure our frame also appears on top |
| 102 |
Rectangle { |
| 103 |
z: 100 |
| 104 |
anchors.fill: parent |
| 105 |
border.color: root.focus ? Style.themeColor : Style.minorFrameColor |
| 106 |
border.width: 1 |
| 107 |
radius: Style.roundRadius |
| 108 |
color: "transparent" |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
} |