Warning, /plasma-mobile/mycroft-plasmoid-mobile/plasmoid/contents/ui/AutocompleteBox.qml is written in an unsupported language. File is not indexed.

0001 /* Copyright 2016 Aditya Mehra <aix.m@outlook.com>                            
0002 
0003     This library is free software; you can redistribute it and/or
0004     modify it under the terms of the GNU Lesser General Public
0005     License as published by the Free Software Foundation; either
0006     version 2.1 of the License, or (at your option) version 3, or any
0007     later version accepted by the membership of KDE e.V. (or its
0008     successor approved by the membership of KDE e.V.), which shall
0009     act as a proxy defined in Section 6 of version 3 of the license.
0010     
0011     This library is distributed in the hope that it will be useful,
0012     but WITHOUT ANY WARRANTY; without even the implied warranty of
0013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014     Lesser General Public License for more details.
0015     
0016     You should have received a copy of the GNU Lesser General Public
0017     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 import QtQuick 2.7
0021 import QtQuick.Controls 2.2
0022 import org.kde.plasma.core 2.0 as PlasmaCore
0023 import org.kde.plasma.components 2.0 as PlasmaComponents
0024 
0025 Rectangle {
0026     id: container
0027     implicitHeight: autoCompListView.implicitHeight
0028     implicitWidth: cbwidth
0029     color: theme.backgroundColor
0030     border.width:  1
0031     border.color: Qt.lighter(theme.backgroundColor, 1.2);
0032     property QtObject model: undefined
0033     property int count: filterItem.model.count
0034     property alias suggestionsModel: filterItem.model
0035     property alias filter: filterItem.filter
0036     property alias property: filterItem.property
0037     property alias navView: autoCompListView
0038     signal itemSelected(variant item)
0039 
0040     function filterMatchesLastSuggestion() {
0041         return suggestionsModel.count == 1 && suggestionsModel.get(0).name === filter
0042     }
0043 
0044     visible: filter.length > 0 && suggestionsModel.count > 0 && !filterMatchesLastSuggestion()
0045 
0046     Logic {
0047         id: filterItem
0048         sourceModel: container.model
0049     }
0050 
0051     ListView{
0052         id: autoCompListView
0053         anchors.fill: parent
0054         model: container.suggestionsModel
0055         implicitHeight: contentItem.childrenRect.height
0056         verticalLayoutDirection: ListView.TopToBottom
0057         keyNavigationEnabled: true
0058         keyNavigationWraps: true
0059         clip: true
0060         delegate: Item {
0061             id: delegateItem
0062             property bool keyboardSelected: autoCompListView.selectedIndex === suggestion.index
0063             property bool selected: itemMouseArea.containsMouse
0064             property variant suggestion: model
0065 
0066             height: textComponent.height + units.gridUnit * 2
0067             width: container.width
0068 
0069             FocusScope{
0070                 anchors.fill:parent
0071                 focus: true
0072 
0073             Rectangle{
0074                 id: autdelRect
0075                 color: delegateItem.selected ? Qt.darker(theme.textColor, 1.2) : Qt.darker(theme.backgroundColor, 1.2)
0076                 width: parent.width
0077                 height: textComponent.height + units.gridUnit * 2
0078                 
0079                 PlasmaCore.IconItem {
0080                     id : smallIconV
0081                     source: "text-speak"
0082                     width: units.gridUnit * 2
0083                     height: units.gridUnit * 2
0084                     anchors.verticalCenter: parent.verticalCenter
0085                     anchors.left: parent.left
0086                     anchors.leftMargin: units.gridUnit * 0.35
0087                 }
0088                 
0089                 PlasmaCore.SvgItem {
0090                         id: innerDelegateRectDividerLine
0091                         anchors {
0092                             left: smallIconV.right
0093                             leftMargin: units.gridUnit * 0.35
0094                             top: parent.top
0095                             topMargin: 0
0096                             bottom: parent.bottom
0097                             bottomMargin: 0
0098                         }
0099                     width: lineitemdividerSvg.elementSize("vertical-line").width
0100                     z: 110
0101                     elementId: "vertical-line"
0102 
0103                     svg: PlasmaCore.Svg {
0104                     id: lineitemdividerSvg;
0105                     imagePath: "widgets/line"
0106                     }
0107                 }  
0108                 
0109                 Text {
0110                     id: textComponent
0111                     anchors.left: innerDelegateRectDividerLine.right
0112                     anchors.leftMargin: units.gridUnit * 0.35
0113                     color: delegateItem.selected ? Qt.darker(theme.backgroundColor, 1.2) : Qt.darker(theme.textColor, 1.2)
0114                     text: model.name;
0115                     width: parent.width - 4
0116                     anchors.horizontalCenter: parent.horizontalCenter
0117                     anchors.verticalCenter: parent.verticalCenter
0118                  }
0119                  
0120             MouseArea {
0121                 id: itemMouseArea
0122                 anchors.fill: parent
0123                 hoverEnabled: true
0124                 onClicked: container.itemSelected(delegateItem.suggestion)
0125                     }
0126                     
0127                 PlasmaCore.SvgItem {
0128                     anchors {
0129                         left: parent.left
0130                         right: parent.right
0131                         bottom: parent.bottom
0132                     }
0133                     width: 1
0134                     height: horlineAutoCSvg.elementSize("horizontal-line").height
0135 
0136                     elementId: "horizontal-line"
0137                     z: 110
0138                     svg: PlasmaCore.Svg {
0139                         id: horlineAutoCSvg;
0140                         imagePath: "widgets/line"
0141                         }
0142                     } 
0143                 }
0144              }
0145            }
0146      ScrollBar.vertical: ScrollBar { }
0147     }
0148 }