Warning, /frameworks/ki18n/tests/demo.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.15
0008 import QtQuick.Layouts 1.1
0009 import QtQuick.Controls 2.15 as QQC2
0010 import org.kde.i18n.localeData 1.0
0011 
0012 QQC2.ApplicationWindow {
0013     visible: true
0014     width: 480
0015     height: 720
0016 
0017     property var currentCountry
0018     property var currentSubdiv
0019 
0020     ColumnLayout {
0021         anchors.fill: parent
0022         anchors.margins: 20
0023         QQC2.ComboBox {
0024             id: countrySelector
0025             Layout.fillWidth: true
0026             model: Country.allCountries
0027             delegate: QQC2.ItemDelegate {
0028                 text: modelData.emojiFlag + " " + modelData.name + " (" + modelData.alpha2 + ")"
0029                 onClicked: {
0030                     countrySelector.currentIndex = index
0031                     currentCountry = modelData
0032                 }
0033             }
0034             displayText: currentValue.emojiFlag + " " + currentValue.name + " (" + currentValue.alpha2 + ")"
0035         }
0036 
0037         QQC2.Label {
0038             text: "Localized name: " + (currentCountry ? currentCountry.name : "N/A")
0039         }
0040         QQC2.Label {
0041             text: "ISO 3166-1 alpha2: " + (currentCountry ? currentCountry.alpha2 : "N/A")
0042         }
0043         QQC2.Label {
0044             text: "ISO 3166-2 aplha3: " + (currentCountry ? currentCountry.alpha3 : "N/A")
0045         }
0046         QQC2.Label {
0047             text: "Flag: " + (currentCountry ? currentCountry.emojiFlag : "N/A")
0048         }
0049         QQC2.Label {
0050             text: "Currency: " + (currentCountry ? currentCountry.currencyCode : "N/A")
0051         }
0052         QQC2.Label {
0053             text: "Timezones: " + (currentCountry ? currentCountry.timeZoneIds.join(', '): "N/A")
0054         }
0055 
0056         QQC2.TextField {
0057             Layout.fillWidth: true
0058             placeholderText: "search country by name or ISO code"
0059             onEditingFinished: currentCountry = Country.fromName(text)
0060         }
0061 
0062         QQC2.ComboBox {
0063             Layout.fillWidth: true
0064             model: currentCountry ? currentCountry.subdivisions : undefined
0065             delegate: QQC2.ItemDelegate {
0066                 text: modelData.name + " (" + modelData.code + ")"
0067                 onClicked: {
0068                     countrySelector.currentIndex = index
0069                     currentSubdiv = modelData
0070                 }
0071             }
0072             displayText: currentValue.name + " (" + currentValue.code + ")"
0073         }
0074 
0075         QQC2.Label {
0076             text: "Localized name: " + (currentSubdiv ? currentSubdiv.name : "N/A")
0077         }
0078         QQC2.Label {
0079             text: "ISO 3166-2: " + (currentSubdiv ? currentSubdiv.code: "N/A")
0080         }
0081         QQC2.Label {
0082             text: "Parent: " + (currentSubdiv ? currentSubdiv.parent.code : "N/A")
0083         }
0084         QQC2.Label {
0085             text: "Country: " + (currentSubdiv ? currentSubdiv.country.alpha2 : "N/A")
0086         }
0087         QQC2.Label {
0088             text: "Timezones: " + (currentSubdiv ? currentSubdiv.timeZoneIds.join(', '): "N/A")
0089         }
0090         QQC2.ComboBox {
0091             Layout.fillWidth: true
0092             visible: currentSubdiv != undefined && currentSubdiv.subdivisions.length > 0
0093             model: currentSubdiv ? currentSubdiv.subdivisions : undefined
0094             delegate: QQC2.ItemDelegate {
0095                 text: modelData.name + " (" + modelData.code + ")"
0096                 onClicked: {
0097                     countrySelector.currentIndex = index
0098                     currentSubdiv = modelData
0099                 }
0100             }
0101             displayText: currentValue.name + " (" + currentValue.code + ")"
0102         }
0103 
0104         QQC2.TextField {
0105             Layout.fillWidth: true
0106             placeholderText: "search country subdivision by ISO code"
0107             onEditingFinished: {
0108                 currentSubdiv = CountrySubdivision.fromCode(text)
0109                 currentCountry = currentSubdiv ? currentSubdiv.country : undefined
0110             }
0111         }
0112 
0113         RowLayout {
0114             function searchByLocation() {
0115                 currentSubdiv = CountrySubdivision.fromLocation(latitude.text, longitude.text);
0116                 if (currentSubdiv) {
0117                     currentCountry = currentSubdiv.country;
0118                 } else {
0119                     currentCountry = Country.fromLocation(latitude.text, longitude.text);
0120                 }
0121                 timezoneAtLocationLabel.text = TimeZone.fromLocation(latitude.text, longitude.text);
0122             }
0123 
0124             QQC2.TextField {
0125                 id: latitude
0126                 placeholderText: "latitude"
0127                 onEditingFinished: parent.searchByLocation()
0128             }
0129             QQC2.TextField {
0130                 id: longitude
0131                 placeholderText: "longitude"
0132                 onEditingFinished: parent.searchByLocation()
0133             }
0134 
0135         }
0136 
0137         QQC2.Label {
0138             id: timezoneAtLocationLabel
0139         }
0140 
0141         Item { Layout.fillHeight: true }
0142     }
0143 }