Warning, /plasma/milou/plasmoid/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * This file is part of the KDE Milou Project
0003  * SPDX-FileCopyrightText: 2013-2014 Vishesh Handa <me@vhanda.in>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006  *
0007  */
0008 
0009 import QtQuick 2.1
0010 import QtQuick.Layouts 1.1
0011 
0012 import org.kde.plasma.plasmoid 2.0
0013 
0014 import org.kde.plasma.core 2.0 as PlasmaCore
0015 import org.kde.milou 0.1 as Milou
0016 
0017 import "globals.js" as Globals
0018 
0019 Item {
0020     id: mainWidget
0021     Plasmoid.switchWidth: Globals.SwitchWidth
0022     Plasmoid.switchHeight: Globals.SwitchWidth
0023     Layout.minimumWidth: Globals.PlasmoidWidth
0024     Layout.maximumWidth: Globals.PlasmoidWidth
0025     Layout.minimumHeight: wrapper.minimumHeight + wrapper.anchors.topMargin + wrapper.anchors.bottomMargin
0026     Layout.maximumHeight: Layout.minimumHeight
0027 
0028     function isBottomEdge() {
0029         return plasmoid.location == PlasmaCore.Types.BottomEdge;
0030     }
0031 
0032     Item {
0033         id: wrapper
0034 
0035         property int minimumHeight: listView.count ? listView.contentHeight + searchField.height + 5
0036                                                    : searchField.height
0037         property int maximumHeight: minimumHeight
0038         anchors.fill: parent
0039 
0040 
0041         SearchField {
0042             id: searchField
0043 
0044             anchors {
0045                 left: parent.left
0046                 right: parent.right
0047                 verticalCenter: parent.height / 2
0048             }
0049             onSearchTextChanged: {
0050                 listView.setQueryString(text)
0051             }
0052             onClose: plasmoid.expanded = false
0053         }
0054 
0055         Milou.ResultsView {
0056             id: listView
0057             //in case is expanded
0058             clip: true
0059 
0060             anchors {
0061                 left: parent.left
0062                 right: parent.right
0063             }
0064 
0065             reversed: isBottomEdge()
0066             onActivated: {
0067                 searchField.text = "";
0068                 plasmoid.expanded = false;
0069             }
0070             onUpdateQueryString: function (text, cursorPosition) {
0071                 searchField.text = text
0072                 searchField.cursorPosition = cursorPosition
0073             }
0074         }
0075 
0076 
0077         Component.onCompleted: {
0078             //plasmoid.settingsChanged.connect(loadSettings)
0079 
0080             if (!isBottomEdge()) {
0081                 // Normal view
0082                 searchField.anchors.top = wrapper.top
0083                 listView.anchors.top = searchField.bottom
0084                 listView.anchors.bottom = wrapper.bottom
0085             }
0086             else {
0087                 // When on the bottom
0088                 listView.anchors.top = wrapper.top
0089                 listView.anchors.bottom = searchField.top
0090                 searchField.anchors.bottom = wrapper.bottom
0091             }
0092         }
0093     }
0094 
0095     Timer {
0096         id: theFocusDoesNotAlwaysWorkTimer
0097         interval: 100
0098         repeat: false
0099 
0100         onTriggered: {
0101             setTextFieldFocus(plasmoid.expanded)
0102         }
0103     }
0104 
0105     function setTextFieldFocus(shown) {
0106         searchField.setFocus();
0107         searchField.selectAll();
0108     }
0109 
0110     function loadSettings() {
0111         listView.loadSettings()
0112     }
0113 
0114     Plasmoid.onExpandedChanged: {
0115         setTextFieldFocus(plasmoid.expanded);
0116         //
0117         // The focus is not always set correctly. The hunch is that this
0118         // function is called before the popup is actually visible and
0119         // therfore the setFocus call does not do anything. So, we are using
0120         // a small timer and calling the setTextFieldFocus function again.
0121         //
0122         theFocusDoesNotAlwaysWorkTimer.start()
0123     }
0124 
0125 }