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

0001 /*
0002     SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import QtQuick.Controls as QQC2
0010 import org.kde.i18n.localeData
0011 import org.kde.kirigami as Kirigami
0012 import org.kde.kirigamiaddons.formcard as FormCard
0013 import org.kde.itinerary
0014 
0015 FormCard.FormCard {
0016     id: root
0017     width: ListView.view.width
0018 
0019     required property var tripGroup
0020     required property string tripGroupId
0021     required property int rangeType
0022 
0023     property var weatherForecast: TripGroupInfoProvider.weatherForecast(tripGroup)
0024 
0025     signal removeTrip(tripGroupId: var)
0026 
0027     function clicked() {
0028         if (root.rangeType === TimelineElement.SelfContained) {
0029             TripGroupProxyModel.expand(root.tripGroupId);
0030         } else {
0031             TripGroupProxyModel.collapse(root.tripGroupId);
0032         }
0033     }
0034 
0035     FormCard.AbstractFormDelegate {
0036         onClicked: root.clicked()
0037         background: Rectangle {
0038             id: headerBackground
0039             color: Kirigami.Theme.backgroundColor
0040             Kirigami.Theme.colorSet: Kirigami.Theme.Header
0041             Kirigami.Theme.inherit: false
0042         }
0043         contentItem: RowLayout {
0044             id: headerLayout
0045             anchors.fill: parent
0046             anchors.margins: Kirigami.Units.largeSpacing
0047 
0048             Kirigami.Icon {
0049                 source: switch (rangeType) {
0050                     case TimelineElement.SelfContained: return "go-next-symbolic";
0051                     case TimelineElement.RangeBegin: return "go-down-symbolic";
0052                     case TimelineElement.RangeEnd: return "go-up-symbolic";
0053                 }
0054                 Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium
0055                 Layout.preferredHeight: Layout.preferredWidth
0056                 color: Kirigami.Theme.textColor
0057                 isMask: true
0058             }
0059             QQC2.Label {
0060                 id: headerLabel
0061                 text: root.rangeType === TimelineElement.RangeEnd ? i18n("End: %1", tripGroup.name) : i18n("Trip: %1", tripGroup.name)
0062                 color: Kirigami.Theme.textColor
0063                 elide: Text.ElideRight
0064                 wrapMode: Text.WordWrap
0065                 maximumLineCount: 2
0066                 Layout.fillWidth: true
0067                 Accessible.ignored: true
0068             }
0069         }
0070     }
0071     FormCard.AbstractFormDelegate {
0072         id: content
0073         // hide content entirely in the header-only end elements
0074         visible: root.rangeType !== TimelineElement.RangeEnd
0075         onClicked: root.clicked()
0076 
0077         contentItem: Item {
0078             implicitHeight: contentLayout.implicitHeight
0079 
0080             ColumnLayout {
0081                 id: contentLayout
0082                 spacing: Kirigami.Units.smallSpacing
0083 
0084                 anchors {
0085                     left: parent.left
0086                     right: parent.right
0087                     top: parent.top
0088                 }
0089 
0090                 QQC2.Label {
0091                     Layout.fillWidth: true
0092                     text: i18np("Date: %2 (one day)", "Date: %2 (%1 days)",
0093                             Math.ceil((root.tripGroup.endDateTime.getTime() - root.tripGroup.beginDateTime.getTime()) / (1000 * 3600 * 24)),
0094                             Localizer.formatDateTime(root.tripGroup, "beginDateTime"))
0095                 }
0096 
0097                 RowLayout {
0098                     Layout.fillWidth: true
0099                     visible: weatherForecast.valid
0100 
0101                     Kirigami.Icon {
0102                         source: weatherForecast.symbolIconName
0103                         width: Kirigami.Units.iconSizes.small
0104                         height: width
0105                     }
0106 
0107                     QQC2.Label {
0108                         text: i18nc("temperature range", "%1 / %2",  Localizer.formatTemperature(weatherForecast.minimumTemperature),
0109                                                                     Localizer.formatTemperature(weatherForecast.maximumTemperature))
0110                         Accessible.ignored: !parent.visible
0111                         Layout.fillWidth: true
0112                     }
0113                 }
0114 
0115                 Repeater {
0116                     model: TripGroupInfoProvider.locationInformation(tripGroup, Settings.homeCountryIsoCode)
0117 
0118                     QQC2.Label {
0119                         Layout.fillWidth: true
0120                         text: {
0121                             if (modelData.powerPlugCompatibility == LocationInformation.PartiallyCompatible) {
0122                                 if (modelData.powerPlugTypes.length === 0) {
0123                                     return i18n("%1: some incompatible power sockets (%2)", Country.fromAlpha2(modelData.isoCode).name, modelData.powerSocketTypes);
0124                                 } else {
0125                                     return i18n("%1: some incompatible power plugs (%2)", Country.fromAlpha2(modelData.isoCode).name, modelData.powerPlugTypes);
0126                                 }
0127                             } else {
0128                                 return i18n("%1: no compatible power plugs (%2)", Country.fromAlpha2(modelData.isoCode).name, modelData.powerSocketTypes);
0129                             }
0130                         }
0131                         color: modelData.powerPlugCompatibility == LocationInformation.PartiallyCompatible ? Kirigami.Theme.neutralTextColor : Kirigami.Theme.negativeTextColor
0132                         wrapMode: Text.WordWrap
0133                     }
0134                 }
0135 
0136                 QQC2.Label {
0137                     readonly property var currencies: TripGroupInfoProvider.currencies(tripGroup, Country.fromAlpha2(Settings.homeCountryIsoCode).currencyCode)
0138                     text: currencies.length > 0 ? i18np("Currency: %2", "Currencies: %2", currencies.length, currencies.join(", ")) : ""
0139                     visible: currencies.length > 0
0140                     Accessible.ignored: !visible
0141                     Layout.fillWidth: true
0142                 }
0143 
0144                 Kirigami.Separator {
0145                     visible: root.rangeType === TimelineElement.RangeBegin
0146                     Layout.fillWidth: true
0147                 }
0148 
0149                 RowLayout {
0150                     visible: root.rangeType === TimelineElement.RangeBegin
0151                     Layout.fillWidth: true
0152                     Item {
0153                         Layout.fillWidth: true
0154                     }
0155                     QQC2.ToolButton {
0156                         icon.name: "export-symbolic"
0157                         onClicked: {
0158                             exportTripGroupDialog.tripGroupId = root.tripGroupId
0159                             exportTripGroupDialog.open()
0160                         }
0161                         text: i18n("Export...")
0162                         QQC2.ToolTip.text: text
0163                         QQC2.ToolTip.visible: hovered
0164                         QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0165                     }
0166                     QQC2.ToolButton {
0167                         icon.name: "edit-delete"
0168                         onClicked: removeTrip(root.tripGroupId)
0169                         text: i18n("Delete trip")
0170                         display: QQC2.AbstractButton.IconOnly
0171                         QQC2.ToolTip.text: text
0172                         QQC2.ToolTip.visible: hovered
0173                         QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0174                     }
0175                 }
0176             }
0177         }
0178     }
0179 
0180     Accessible.name: headerLabel.text
0181     Accessible.onPressAction: root.clicked()
0182 }