Warning, /pim/itinerary/src/app/CountryComboBoxDelegate.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2021-2022 Volker Krause <vkrause@kde.org>
0003     SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtQuick
0008 import QtQuick.Controls as QQC2
0009 import org.kde.kirigamiaddons.formcard as FormCard
0010 import org.kde.i18n.localeData
0011 import org.kde.kirigami as Kirigami
0012 
0013 /**
0014  * Combo box for showing a list of countries.
0015  * The model is expected to be an array of ISO 3166-1 alpha 2 codes.
0016  */
0017 FormCard.FormComboBoxDelegate {
0018     id: controlRoot
0019 
0020     /** The currently selected country, as a KCountry object. */
0021     readonly property var currentCountry: Country.fromAlpha2(currentValue)
0022 
0023     /** Initially selected country. */
0024     property string initialCountry
0025 
0026     displayMode: Kirigami.Settings.isMobile ? FormCard.FormComboBoxDelegate.Page : FormCard.FormComboBoxDelegate.ComboBox
0027 
0028     displayText: currentCountry ? (currentCountry.emojiFlag + ' ' + currentCountry.name) : ""
0029 
0030     comboBoxDelegate: QQC2.ItemDelegate {
0031         id: delegate
0032         implicitWidth: ListView.view ? ListView.view.width : Kirigami.Units.gridUnit * 16
0033         highlighted: controlRoot.highlightedIndex === index
0034         property bool separatorVisible: false
0035         Kirigami.Theme.colorSet: controlRoot.Kirigami.Theme.inherit ? controlRoot.Kirigami.Theme.colorSet : Kirigami.Theme.View
0036         Kirigami.Theme.inherit: controlRoot.Kirigami.Theme.inherit
0037         text: {
0038             const c = Country.fromAlpha2(modelData);
0039             return c.emojiFlag + ' ' + c.name;
0040         }
0041         Accessible.name: Country.fromAlpha2(modelData).name
0042         Accessible.onPressAction: delegate.clicked()
0043     }
0044 
0045     dialogDelegate: QQC2.RadioDelegate {
0046         id: delegate
0047         implicitWidth: ListView.view ? ListView.view.width : Kirigami.Units.gridUnit * 16
0048         text: {
0049             const c = Country.fromAlpha2(modelData);
0050             return c.emojiFlag + ' ' + c.name;
0051         }
0052         checked: controlRoot.currentIndex === index
0053         property bool separatorVisible: false
0054         Kirigami.Theme.colorSet: controlRoot.Kirigami.Theme.inherit ? controlRoot.Kirigami.Theme.colorSet : Kirigami.Theme.View
0055         Kirigami.Theme.inherit: controlRoot.Kirigami.Theme.inherit
0056         onClicked: {
0057             controlRoot.currentIndex = index;
0058             controlRoot.activated(index);
0059             controlRoot.closeDialog();
0060         }
0061         Accessible.name: Country.fromAlpha2(modelData).name
0062         Accessible.onPressAction: delegate.clicked()
0063     }
0064 
0065     Component.onCompleted: if (initialCountry) {
0066         currentIndex = indexOfValue(initialCountry);
0067     }
0068 }