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 as PlasmaCore 0015 import org.kde.milou 0.1 as Milou 0016 0017 import "globals.js" as Globals 0018 0019 PlasmoidItem { 0020 id: mainWidget 0021 switchWidth: Globals.SwitchWidth 0022 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 fullRepresentation: Item { 0033 id: wrapper 0034 0035 property alias searchField: searchField 0036 property alias listView: listView 0037 property int minimumHeight: listView.count ? listView.contentHeight + searchField.height + 5 0038 : searchField.height 0039 property int maximumHeight: minimumHeight 0040 anchors.fill: parent 0041 0042 0043 SearchField { 0044 id: searchField 0045 0046 anchors { 0047 left: parent.left 0048 right: parent.right 0049 verticalCenter: parent.height / 2 0050 } 0051 onSearchTextChanged: { 0052 listView.setQueryString(text) 0053 } 0054 onClose: mainWidget.expanded = false 0055 } 0056 0057 Milou.ResultsView { 0058 id: listView 0059 //in case is expanded 0060 clip: true 0061 0062 anchors { 0063 left: parent.left 0064 right: parent.right 0065 } 0066 0067 reversed: isBottomEdge() 0068 onActivated: { 0069 searchField.text = ""; 0070 mainWidget.expanded = false; 0071 } 0072 onUpdateQueryString: function (text, cursorPosition) { 0073 searchField.text = text 0074 searchField.cursorPosition = cursorPosition 0075 } 0076 } 0077 0078 0079 Component.onCompleted: { 0080 //plasmoid.settingsChanged.connect(loadSettings) 0081 0082 if (!isBottomEdge()) { 0083 // Normal view 0084 searchField.anchors.top = wrapper.top 0085 listView.anchors.top = searchField.bottom 0086 listView.anchors.bottom = wrapper.bottom 0087 } 0088 else { 0089 // When on the bottom 0090 listView.anchors.top = wrapper.top 0091 listView.anchors.bottom = searchField.top 0092 searchField.anchors.bottom = wrapper.bottom 0093 } 0094 } 0095 } 0096 0097 Timer { 0098 id: theFocusDoesNotAlwaysWorkTimer 0099 interval: 100 0100 repeat: false 0101 0102 onTriggered: { 0103 setTextFieldFocus(mainWidget.expanded) 0104 } 0105 } 0106 0107 function setTextFieldFocus(shown) { 0108 mainWidget.fullRepresentationItem.searchField.setFocus(); 0109 mainWidget.fullRepresentationItem.searchField.selectAll(); 0110 } 0111 0112 function loadSettings() { 0113 mainWidget.fullRepresentationItem.listView.loadSettings() 0114 } 0115 0116 onExpandedChanged: { 0117 setTextFieldFocus(mainWidget.expanded); 0118 // 0119 // The focus is not always set correctly. The hunch is that this 0120 // function is called before the popup is actually visible and 0121 // therfore the setFocus call does not do anything. So, we are using 0122 // a small timer and calling the setTextFieldFocus function again. 0123 // 0124 theFocusDoesNotAlwaysWorkTimer.start() 0125 } 0126 0127 }