Warning, /education/marble/src/apps/marble-maps/Search.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2015 Gábor Péterffy <peterffy95@gmail.com>
0004 //
0005 
0006 import QtQuick 2.7
0007 import QtQuick.Controls 2.0
0008 import QtQuick.Window 2.2
0009 
0010 import org.kde.marble 0.20
0011 
0012 Item {
0013     id: root
0014 
0015     property var marbleQuickItem: null
0016 
0017     signal itemSelected(var suggestedPlacemark)
0018     signal menuButtonClicked()
0019     readonly property alias searchResultPlacemark: backend.selectedPlacemark
0020     readonly property alias searchResultsVisible: searchResults.visible
0021 
0022     onVisibleChanged: {
0023         if( !visible ) {
0024             searchResults.visible = false;
0025             searchField.query = "";
0026         }
0027     }
0028 
0029     SystemPalette {
0030         id: palette
0031         colorGroup: SystemPalette.Active
0032     }
0033 
0034     SystemPalette {
0035         id: paletteDisabled
0036         colorGroup: SystemPalette.Disabled
0037     }
0038 
0039     SearchResults {
0040         id: searchResults
0041         anchors {
0042             top: searchField.bottom
0043             left: searchField.left
0044         }
0045         width: searchField.width
0046         height: delegateHeight * Math.min(10,count)
0047 
0048         visible: false
0049         onItemSelected: {
0050             backend.setSelectedPlacemark(index);
0051             root.itemSelected(backend.selectedPlacemark);
0052             searchResults.visible = false;
0053         }
0054     }
0055 
0056     Rectangle {
0057         id: background
0058         visible: searchField.hasFocus && searchField.query === ""
0059         anchors.top: searchField.bottom
0060         anchors.left: searchField.left
0061         width: searchField.width
0062         height: childrenRect.height
0063         color: palette.base
0064 
0065         property int delegateHeight: 0
0066 
0067         property double itemSpacing: Screen.pixelDensity * 1
0068 
0069         Column {
0070             anchors.top: parent.top
0071             anchors.left: parent.left
0072             anchors.right: parent.right
0073             spacing: background.itemSpacing
0074 
0075             ListView {
0076                 id: bookmarksView
0077                 anchors.left: parent.left
0078                 anchors.right: parent.right
0079                 height: background.delegateHeight * Math.min(6, model.count) + 2 * background.itemSpacing
0080                 clip: true
0081                 ScrollIndicator.vertical: ScrollIndicator { }
0082 
0083                 model: bookmarks.model
0084 
0085                 MouseArea {
0086                     anchors.bottom: parent.bottom
0087                     height: 2 * background.itemSpacing
0088                     width: parent.width
0089                     visible: bookmarks.model.count <= 6
0090                     onClicked: {
0091                         app.selectedPlacemark = bookmarks.placemark(bookmarks.model.count - 1)
0092                         itemSelected(bookmarks.placemark(bookmarks.model.count - 1))
0093                         marbleMaps.centerOn(selectedPlacemark.longitude, selectedPlacemark.latitude)
0094                         dialogLoader.focus = true
0095                     }
0096                 }
0097 
0098                 delegate: Row {
0099                     width: bookmarksView.width
0100                     height: background.itemSpacing + Math.max(bookmarkIcon.height, bookmarkText.height)
0101                     spacing: background.itemSpacing
0102 
0103                     leftPadding: 10
0104                     rightPadding: 10
0105 
0106                     Image {
0107                         id: bookmarkIcon
0108                         anchors.verticalCenter: parent.verticalCenter
0109                         source: iconPath.substr(0,1) === '/' ? "file://" + iconPath : iconPath
0110                         width: Screen.pixelDensity * 4
0111                         height: width
0112                         sourceSize.width: width
0113                         sourceSize.height: height
0114                     }
0115 
0116                     Text {
0117                         id: bookmarkText
0118                         anchors.verticalCenter: parent.verticalCenter
0119                         anchors.leftMargin: Screen.pixelDensity * 2
0120                         width: bookmarksView.width - bookmarksView.spacing - bookmarkIcon.width
0121                         text: display
0122                         font.pointSize: 14
0123                         color: palette.text
0124                         elide: Text.ElideMiddle
0125 
0126                         MouseArea {
0127                             anchors.fill: parent
0128                             onClicked: {
0129                                 bookmarksView.currentIndex = index
0130                                 app.selectedPlacemark = bookmarks.placemark(index);
0131                                 itemSelected(bookmarks.placemark(index))
0132                                 marbleMaps.centerOn(selectedPlacemark.longitude, selectedPlacemark.latitude)
0133                                 dialogLoader.focus = true
0134                             }
0135                         }
0136                     }
0137 
0138                     onHeightChanged: {
0139                         if( background.delegateHeight !== height ) {
0140                             background.delegateHeight = height;
0141                         }
0142                     }
0143                 }
0144             }
0145 
0146             Row {
0147                 visible: bookmarksView.model.count === 0
0148                 width: parent.width
0149                 anchors.left: parent.left
0150                 anchors.right: parent.right
0151                 spacing: Screen.pixelDensity * 2
0152                 anchors.margins: Screen.pixelDensity * 2
0153 
0154                 Text {
0155                     anchors.bottom: parent.bottom
0156                     leftPadding: 10
0157                     bottomPadding: 3
0158                     width: parent.width - Screen.pixelDensity * 2 - emptyImage.width
0159                     font.pointSize: 14
0160                     color: paletteDisabled.text
0161                     text: qsTr("Your bookmarks will appear here.")
0162 
0163                     wrapMode: Text.WrapAtWordBoundaryOrAnywhere
0164                     elide: Text.ElideRight
0165                 }
0166 
0167                 Image {
0168                     id: emptyImage
0169                     anchors.bottom: parent.bottom
0170                     width: Screen.pixelDensity* 10
0171 
0172                     fillMode: Image.PreserveAspectFit
0173                     source: "qrc:/konqi/books.png"
0174                 }
0175             }
0176         }
0177     }
0178 
0179     SearchBackend {
0180         id: backend
0181         marbleQuickItem: root.marbleQuickItem
0182         onSearchResultChanged: {
0183             searchResults.model = model;
0184             searchResults.visible = true;
0185         }
0186         onSearchFinished: searchField.busy = false
0187     }
0188 
0189     SearchField {
0190         id: searchField
0191         width: parent.width
0192         anchors {
0193             top: parent.top
0194             left: parent.left
0195             right: parent.right
0196         }
0197         completionModel: backend.completionModel
0198         onSearchRequested: backend.search(query)
0199         onCompletionRequested: backend.setCompletionPrefix(query)
0200         onCleared: searchResults.visible = false
0201         onMenuButtonClicked: root.menuButtonClicked()
0202     }
0203 
0204     Bookmarks {
0205         id: bookmarks
0206         map: root.marbleQuickItem
0207     }
0208 }