Warning, /maui/mauikit-calendar/src/controls.5/TimePicker.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.4 0002 import QtQuick.Layouts 1.1 0003 import QtQuick.Controls 2.15 0004 0005 import org.mauikit.controls 1.3 as Maui 0006 import org.mauikit.calendar 1.0 as Kalendar 0007 0008 0009 Page 0010 { 0011 id: control 0012 0013 readonly property date startTime : new Date() 0014 0015 property int selectedMinute: selectedTime.getMinutes() 0016 property int selectedHour: selectedTime.getHours() 0017 property int timeZoneOffset : 0 0018 property date selectedTime : startTime 0019 0020 property string format: control.selectedHour < 12 ? "AM" : "PM" 0021 0022 signal accepted(var time) 0023 0024 background: null 0025 0026 header: ToolBar 0027 { 0028 width: parent.width 0029 background: null 0030 0031 contentItem: RowLayout 0032 { 0033 spacing: 0 0034 0035 Maui.ToolActions 0036 { 0037 id: _dateGroup 0038 autoExclusive: true 0039 0040 Action 0041 { 0042 text: i18n("AM") 0043 checked: control.format === text 0044 onTriggered: control.format = text 0045 } 0046 0047 Action 0048 { 0049 text: i18n("PM") 0050 checked: control.format === text 0051 0052 onTriggered: control.format = text 0053 } 0054 } 0055 0056 Item {Layout.fillWidth: true} 0057 0058 Button 0059 { 0060 text: i18n("Done") 0061 onClicked: 0062 { 0063 control.updateSelectedTime(minutesTumbler.currentIndex, hoursTumbler.currentIndex, control.format) 0064 control.accepted(control.selectedTime) 0065 } 0066 } 0067 } 0068 } 0069 0070 contentItem: Item 0071 { 0072 0073 Row 0074 { 0075 id: row 0076 height: parent.height 0077 anchors.horizontalCenter: parent.horizontalCenter 0078 0079 spacing: Maui.Style.space.medium 0080 0081 Tumbler 0082 { 0083 id: hoursTumbler 0084 spacing: Maui.Style.space.medium 0085 0086 model: 12 0087 currentIndex: formatUTCHour(control.selectedHour) 0088 0089 delegate: Button 0090 { 0091 font.bold: checked 0092 0093 checked : index === Tumbler.tumbler.currentIndex 0094 text: formatText(Tumbler.tumbler.count, modelData) 0095 opacity: 1.0 - Math.abs(Tumbler.displacement) / (Tumbler.tumbler.visibleItemCount / 2) 0096 0097 onClicked: 0098 { 0099 Tumbler.tumbler.currentIndex = modelData 0100 control.updateSelectedTime(minutesTumbler.currentIndex, hoursTumbler.currentIndex) 0101 } 0102 0103 background: Rectangle 0104 { 0105 visible: checked 0106 color: checked ? Maui.Theme.highlightColor : hovered ? Maui.Theme.focusColor : "transparent" 0107 radius: Maui.Style.radiusV 0108 } 0109 } 0110 0111 } 0112 0113 Tumbler 0114 { 0115 id: minutesTumbler 0116 model: 60 0117 spacing: Maui.Style.space.medium 0118 0119 currentIndex: control.selectedMinute 0120 0121 Label 0122 { 0123 text: minutesTumbler.currentIndex 0124 color: "yellow" 0125 } 0126 0127 delegate: Button 0128 { 0129 font.bold: checked 0130 checked : index === Tumbler.tumbler.currentIndex 0131 text: formatText(Tumbler.tumbler.count, modelData) 0132 opacity: 1.0 - Math.abs(Tumbler.displacement) / (Tumbler.tumbler.visibleItemCount / 2) 0133 0134 onClicked: 0135 { 0136 Tumbler.tumbler.currentIndex = modelData 0137 control.updateSelectedTime(minutesTumbler.currentIndex, hoursTumbler.currentIndex) 0138 } 0139 0140 background: Rectangle 0141 { 0142 visible: checked 0143 color: checked ? Maui.Theme.highlightColor : hovered ? Maui.Theme.focusColor : "transparent" 0144 radius: Maui.Style.radiusV 0145 } 0146 } 0147 } 0148 } 0149 0150 // Label 0151 // { 0152 // text: hoursTumbler.currentIndex + " / " + control.selectedTime.getUTCHours() 0153 // color: "yellow" 0154 // } 0155 } 0156 0157 0158 function formatUTCHour(hour : int) 0159 { 0160 if(hour > 12) 0161 { 0162 return hour - 12; 0163 } 0164 0165 return hour 0166 } 0167 0168 function formatHourToUTC(hour, format) 0169 { 0170 if(format == "AM") 0171 { 0172 if(hour >= 11) 0173 { 0174 return 0; 0175 } 0176 0177 return hour + 1 0178 } 0179 0180 0181 if(hour >= 11) 0182 { 0183 return 23 0184 } 0185 0186 return 12 + hour +1; 0187 } 0188 0189 function formatText(count : int, modelData : int) 0190 { 0191 var data = count === 12 ? modelData + 1 : modelData; 0192 return data.toString().length < 2 ? "0" + data : data; 0193 } 0194 0195 function updateSelectedTime(minute, hour, format = control.format) 0196 { 0197 control.selectedMinute = minute 0198 control.selectedHour = formatHourToUTC(hour, format) 0199 0200 var newdate = new Date() 0201 0202 newdate.setHours(control.selectedHour) 0203 newdate.setMinutes(control.selectedMinute) 0204 0205 control.selectedTime = newdate 0206 0207 console.log("UPDATING TIMEW", control.selectedTime.getHours(), control.selectedTime.getMinutes(), hour, minute, format, control.selectedTime.toLocaleTimeString()) 0208 } 0209 0210 }