Warning, /libraries/kirigami-addons/src/dateandtime/TimeInput.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.15 0008 import QtQuick.Controls 2.15 as QQC2 0009 import org.kde.kirigami 2.20 as Kirigami 0010 import org.kde.kirigamiaddons.dateandtime 0.1 0011 import './private' 0012 0013 /** 0014 * TimeInput is a single line time editor. 0015 */ 0016 QQC2.TextField { 0017 id: timeInput 0018 0019 /** 0020 * This property holds the desired time format. 0021 */ 0022 property string format: Qt.locale().timeFormat(Locale.ShortFormat) 0023 0024 /** 0025 * This property holds the current time value. 0026 */ 0027 property date value: new Date() 0028 0029 // The text field acts as a time input field. 0030 inputMethodHints: Qt.ImhTime 0031 0032 validator: TimeInputValidator { 0033 id: timeValidator 0034 format: timeInput.format 0035 } 0036 0037 onEditingFinished: textToValue() 0038 onValueChanged: valueToText() 0039 0040 function textToValue() { 0041 const locale = Qt.locale(); 0042 timeInput.value = Date.fromLocaleTimeString(locale, timeInput.text, timeInput.format); 0043 } 0044 0045 function valueToText() { 0046 const locale = Qt.locale(); 0047 timeInput.text = timeInput.value.toLocaleTimeString(locale, timeInput.format); 0048 } 0049 0050 Component.onCompleted: valueToText() 0051 0052 MouseArea { 0053 id: mouseArea 0054 anchors.fill: parent 0055 enabled: Kirigami.Settings.isMobile 0056 property bool androidPickerActive: false 0057 onClicked: if (Qt.platform.os === 'android') { 0058 androidPickerActive = true; 0059 AndroidIntegration.showTimePicker(timeInput.value.getTime()); 0060 } else { 0061 popup.open(); 0062 } 0063 Connections { 0064 enabled: Qt.platform.os === 'android' && mouseArea.androidPickerActive 0065 ignoreUnknownSignals: !enabled 0066 target: enabled ? AndroidIntegration : null 0067 function onTimePickerFinished(accepted, newDate) { 0068 mouseArea.androidPickerActive = false; 0069 if (accepted) { 0070 timeInput.value = newDate; 0071 } 0072 } 0073 } 0074 } 0075 0076 QQC2.Popup { 0077 id: popup 0078 x: parent ? Math.round((parent.width - width) / 2) : 0 0079 y: parent ? Math.round((parent.height - height) / 2) : 0 0080 modal: true 0081 0082 contentItem: TumblerTimePicker { 0083 id: popupContent 0084 implicitWidth: applicationWindow().width 0085 minutes: timeInput.value.getMinutes() 0086 hours: timeInput.value.getHours() 0087 onMinutesChanged: { 0088 const date = new Date(timeInput.value); 0089 date.setHours(hours, minutes); 0090 timeInput.value = date; 0091 } 0092 onHoursChanged: { 0093 const date = new Date(timeInput.value); 0094 date.setHours(hours, minutes); 0095 timeInput.value = date; 0096 } 0097 } 0098 } 0099 }