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

0001 /* Copyright 2019 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.9
0021 import QtQuick.Controls 2.2
0022 import QtQuick.Layouts 1.3
0023 import org.kde.plasma.core 2.0 as PlasmaCore
0024 import org.kde.plasma.components 2.0 as PlasmaComponents
0025 import QtGraphicalEffects 1.0
0026 
0027 Rectangle {
0028     id: container
0029     implicitHeight: autoCompListView.implicitHeight
0030     implicitWidth: parent.width
0031     color: theme.backgroundColor
0032     border.width:  1
0033     border.color: Qt.lighter(theme.backgroundColor, 1.2);
0034     property QtObject model: undefined
0035     property int count: filterItem.model.count
0036     property alias suggestionsModel: filterItem.model
0037     property alias filter: filterItem.filter
0038     property alias property: filterItem.property
0039     property alias navView: autoCompListView
0040     signal itemSelected(variant item)
0041 
0042     function filterMatchesLastSuggestion() {
0043         return suggestionsModel.count == 1 && suggestionsModel.get(0).name === filter
0044     }
0045 
0046     visible: filter.length > 0 && suggestionsModel.count > 0 && !filterMatchesLastSuggestion()
0047 
0048     Logic {
0049         id: filterItem
0050         sourceModel: container.model
0051     }
0052 
0053     ListView{
0054         id: autoCompListView
0055         anchors.fill: parent
0056         model: container.suggestionsModel
0057         implicitHeight: contentItem.childrenRect.height
0058         verticalLayoutDirection: ListView.TopToBottom
0059         keyNavigationEnabled: true
0060         keyNavigationWraps: true
0061         clip: true
0062         delegate: Item {
0063             id: delegateItem
0064             property bool keyboardSelected: autoCompListView.selectedIndex === suggestion.index
0065             property bool selected: itemMouseArea.containsMouse
0066             property variant suggestion: model
0067 
0068             height: textComponent.height + units.gridUnit * 2
0069             width: container.width
0070 
0071             FocusScope{
0072                 anchors.fill:parent
0073                 focus: true
0074 
0075                 Rectangle{
0076                     id: autdelRect
0077                     color: delegateItem.selected ? Qt.darker(theme.textColor, 1.2) : Qt.darker(theme.backgroundColor, 1.2)
0078                     width: parent.width
0079                     height: textComponent.height + units.gridUnit * 2
0080 
0081                     PlasmaCore.IconItem {
0082                         id : smallIconV
0083                         source: "text-speak"
0084                         width: units.gridUnit * 2
0085                         height: units.gridUnit * 2
0086                         anchors.verticalCenter: parent.verticalCenter
0087                         anchors.left: parent.left
0088                         anchors.leftMargin: units.gridUnit * 0.35
0089                     }
0090 
0091                     PlasmaCore.SvgItem {
0092                         id: innerDelegateRectDividerLine
0093                         anchors {
0094                             left: smallIconV.right
0095                             leftMargin: units.gridUnit * 0.35
0096                             top: parent.top
0097                             topMargin: 0
0098                             bottom: parent.bottom
0099                             bottomMargin: 0
0100                         }
0101                         width: lineitemdividerSvg.elementSize("vertical-line").width
0102                         z: 110
0103                         elementId: "vertical-line"
0104 
0105                         svg: PlasmaCore.Svg {
0106                             id: lineitemdividerSvg;
0107                             imagePath: "widgets/line"
0108                         }
0109                     }
0110 
0111                     Text {
0112                         id: textComponent
0113                         anchors.left: innerDelegateRectDividerLine.right
0114                         anchors.leftMargin: units.gridUnit * 0.35
0115                         color: delegateItem.selected ? Qt.darker(theme.backgroundColor, 1.2) : Qt.darker(theme.textColor, 1.2)
0116                         text: model.name;
0117                         width: parent.width - 4
0118                         anchors.horizontalCenter: parent.horizontalCenter
0119                         anchors.verticalCenter: parent.verticalCenter
0120                     }
0121 
0122                     MouseArea {
0123                         id: itemMouseArea
0124                         anchors.fill: parent
0125                         hoverEnabled: true
0126                         onClicked: container.itemSelected(delegateItem.suggestion)
0127                     }
0128                     
0129                     PlasmaCore.SvgItem {
0130                         anchors {
0131                             left: parent.left
0132                             right: parent.right
0133                             bottom: parent.bottom
0134                         }
0135                         width: 1
0136                         height: horlineAutoCSvg.elementSize("horizontal-line").height
0137 
0138                         elementId: "horizontal-line"
0139                         z: 110
0140                         svg: PlasmaCore.Svg {
0141                             id: horlineAutoCSvg;
0142                             imagePath: "widgets/line"
0143                         }
0144                     }
0145                 }
0146             }
0147         }
0148         ScrollBar.vertical: ScrollBar { }
0149     }
0150 }