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

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtCore
0008 import QtQuick
0009 import QtQuick.Layouts
0010 import QtQuick.Controls as QQC2
0011 import QtQuick.Dialogs
0012 import QtLocation as QtLocation
0013 import QtPositioning
0014 import org.kde.kirigami as Kirigami
0015 import org.kde.kirigamiaddons.components
0016 import org.kde.itinerary
0017 
0018 Kirigami.Page {
0019     id: root
0020     title: i18n("Favorite Locations")
0021 
0022     topPadding: 0
0023     bottomPadding: 0
0024     leftPadding: 0
0025     rightPadding: 0
0026 
0027     Component.onCompleted: {
0028         if (combo.count == 0)
0029             FavoriteLocationModel.appendNewLocation();
0030 
0031     }
0032 
0033     FileDialog {
0034         id: favoriteGpxExportDialog
0035         fileMode: FileDialog.SaveFile
0036         title: i18n("Export Favorite Locations")
0037         currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
0038         nameFilters: [i18n("GPX Files (*.gpx)")]
0039         onAccepted: FavoriteLocationModel.exportToGpx(selectedFile)
0040     }
0041     FileDialog {
0042         id: favoriteGpxImportDialog
0043         fileMode: FileDialog.OpenFile
0044         title: i18n("Import Favorite Locations")
0045         currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
0046         nameFilters: [i18n("GPX Files (*.gpx)")]
0047         onAccepted: FavoriteLocationModel.importFromGpx(selectedFile)
0048     }
0049 
0050     actions: [
0051         Kirigami.Action {
0052             text: i18n("Add Favorite Location")
0053             icon.name: "list-add"
0054             onTriggered: {
0055                 FavoriteLocationModel.appendNewLocation();
0056                 combo.currentIndex = combo.count - 1;
0057             }
0058         },
0059         Kirigami.Action {
0060             text: i18n("Rename Favorite Location")
0061             icon.name: "edit-rename"
0062             onTriggered: renameSheet.open()
0063         },
0064         Kirigami.Action {
0065             text: i18n("Remove Favorite Location")
0066             icon.name: "edit-delete"
0067             enabled: combo.count > 1
0068             onTriggered: {
0069                 var prevIndex = combo.currentIndex;
0070                 FavoriteLocationModel.removeLocation(combo.currentIndex);
0071                 combo.currentIndex = Math.min(prevIndex, combo.count - 1);
0072             }
0073         },
0074         Kirigami.Action {
0075             text: i18n("Export to GPX")
0076             icon.name: "export-symbolic"
0077             onTriggered: favoriteGpxExportDialog.open()
0078         },
0079         Kirigami.Action {
0080             text: i18n("Import from GPX")
0081             icon.name: "document-import"
0082             onTriggered: favoriteGpxImportDialog.open()
0083         }
0084     ]
0085 
0086     Kirigami.OverlaySheet {
0087         id: renameSheet
0088 
0089         QQC2.Label {
0090             text: i18n("Rename favorite location")
0091         }
0092 
0093         footer: ColumnLayout {
0094             QQC2.TextField {
0095                 id: nameEdit
0096                 Layout.fillWidth: true
0097                 text: combo.currentText
0098             }
0099             QQC2.Button {
0100                 Layout.alignment: Qt.AlignHCenter
0101                 text: i18n("Rename")
0102                 icon.name: "edit-rename"
0103                 onClicked: {
0104                     var idx = FavoriteLocationModel.index(combo.currentIndex, 0);
0105                     FavoriteLocationModel.setData(idx, nameEdit.text, Qt.DisplayRole);
0106                     renameSheet.close();
0107                 }
0108             }
0109         }
0110     }
0111 
0112 
0113     QQC2.ComboBox {
0114         id: combo
0115         anchors { top: parent.top; left: parent.left; right: parent.right; margins: Kirigami.Units.largeSpacing }
0116         model: FavoriteLocationModel
0117         textRole: "display"
0118         onCurrentIndexChanged: {
0119             var favLoc = delegateModel.items.get(currentIndex)
0120             map.center = QtPositioning.coordinate(favLoc.model.latitude, favLoc.model.longitude)
0121             map.zoomLevel = 16;
0122         }
0123     }
0124 
0125     MapView {
0126         id: map
0127         anchors { top: combo.bottom; left: parent.left; right: parent.right; bottom: parent.bottom; topMargin: Kirigami.Units.largeSpacing }
0128 
0129         QtLocation.MapQuickItem {
0130             coordinate: map.center
0131             anchorPoint { x: icon.width / 2; y: icon.height / 2 }
0132             sourceItem: Kirigami.Icon {
0133                 id: icon
0134                 source: "crosshairs"
0135                 width: height
0136                 height: Kirigami.Units.iconSizes.large
0137                 color: Kirigami.Theme.negativeTextColor
0138             }
0139         }
0140     }
0141 
0142     FloatingButton {
0143         anchors {
0144             right: parent.right
0145             rightMargin: Kirigami.Units.largeSpacing + (root.contentItem.QQC2.ScrollBar && root.contentItem.QQC2.ScrollBar.vertical ? root.contentItem.QQC2.ScrollBar.vertical.width : 0)
0146             bottom: parent.bottom
0147             bottomMargin: Kirigami.Units.largeSpacing
0148         }
0149         action: Kirigami.Action {
0150             icon.name: "crosshairs"
0151             text: i18n("Pick Location")
0152             onTriggered: {
0153                 var idx = FavoriteLocationModel.index(combo.currentIndex, 0);
0154                 FavoriteLocationModel.setData(idx, map.center.latitude, FavoriteLocationModel.LatitudeRole);
0155                 FavoriteLocationModel.setData(idx, map.center.longitude, FavoriteLocationModel.LongitudeRole);
0156                 applicationWindow().pageStack.goBack();
0157             }
0158         }
0159     }
0160 
0161     footer: null
0162 }