Debian Codegraph @

src/GUI/qml/DateTimeEdit.qml

raw
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
14 implicitHeight: label.implicitHeight
15 implicitWidth: label.implicitWidth + Style.margin + editFrame.width
16
17 function daysInMonth()
18 {
19 var date = new Date(year.value, month.value, 0 /* last day of preceding month */);
20 return date.getDate();
21 }
22
23 function updateCurrentDate()
24 {
25 root.value = new Date(year.value, month.value - 1, dayOfMonth.value,
26 hours.value, minutes.value);
27 }
28
29 function setDate(date)
30 {
31 year.value = date.getFullYear();
32 month.value = date.getMonth() + 1;
33 dayOfMonth.value = date.getDate();
34 hours.value = date.getHours();
35 minutes.value = date.getMinutes();
36 updateCurrentDate();
37 }
38
39 StyledText {
40 id: label
41 anchors.left: root.left
42 anchors.leftMargin: Style.margin
43 anchors.verticalCenter: parent.verticalCenter
44 horizontalAlignment: Text.AlignRight
45 enabled: root.enabled
46 }
47
48 Rectangle {
49 id: editFrame
50 radius: Style.roundRadius
51 border.color: root.focus ? Style.themeColor : Style.minorFrameColor
52
53 border.width: 1
54 height: 30
55 // height: currentChoiceText.implicitHeight + Style.margin
56
57 anchors.left: label.right
58 anchors.leftMargin: Style.margin
59
60 width: editRow.childrenRect.width + Style.roundRadius * 2 + 64
61
62 // width of current item, or available space after the label
63 // width: Math.min(root.width - (label.width + Style.margin),
64 // currentChoiceText.implicitWidth + (Style.margin * 2) + upDownIcon.width);
65
66 anchors.verticalCenter: parent.verticalCenter
67
68 Row {
69 id: editRow
70 anchors {
71 left: parent.left
72 top: parent.top
73 bottom: parent.bottom
74 right: parent.right
75 margins: Style.margin
76 }
77
78 DateTimeValueEdit {
79 id: year
80 maxValue: 9999
81 widthString: "0000"
82 nextToFocus: month
83 fieldWidth: 4
84 anchors.verticalCenter: parent.verticalCenter
85 onCommit: updateCurrentDate();
86 }
87
88 StyledText {
89 text: " / "
90 anchors.verticalCenter: parent.verticalCenter
91 enabled: root.enabled
92 }
93
94 DateTimeValueEdit {
95 id: month
96 minValue: 1
97 maxValue: 12
98 widthString: "00"
99 nextToFocus: dayOfMonth
100 previousToFocus: year
101 anchors.verticalCenter: parent.verticalCenter
102 onCommit: updateCurrentDate();
103 }
104
105 StyledText {
106 text: " / "
107 anchors.verticalCenter: parent.verticalCenter
108 enabled: root.enabled
109 }
110
111 DateTimeValueEdit {
112 id: dayOfMonth
113 minValue: 1
114 maxValue: root.daysInMonth()
115 widthString: "00"
116 nextToFocus: hours
117 previousToFocus: month
118 anchors.verticalCenter: parent.verticalCenter
119 onCommit: updateCurrentDate();
120 }
121
122 // spacer here
123 StyledText {
124 text: " "
125 anchors.verticalCenter: parent.verticalCenter
126 enabled: root.enabled
127 }
128
129 DateTimeValueEdit {
130 id: hours
131 minValue: 0
132 maxValue: 23
133 widthString: "00"
134 nextToFocus: minutes
135 previousToFocus: dayOfMonth
136 anchors.verticalCenter: parent.verticalCenter
137 onCommit: updateCurrentDate();
138 }
139
140 StyledText {
141 text: " : "
142 anchors.verticalCenter: parent.verticalCenter
143 enabled: root.enabled
144 }
145
146 DateTimeValueEdit {
147 id: minutes
148 minValue: 0
149 maxValue: 59
150 widthString: "00"
151 anchors.verticalCenter: parent.verticalCenter
152 previousToFocus: hours
153 onCommit: updateCurrentDate();
154 }
155 } // of date elements row
156 }
157
158 }