/**************************************************************************** Copyright (C) 2013-2015 by Eike Hein <hein@kde.org> ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the ** Free Software Foundation, Inc., ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . ****************************************************************************/import QtQuick 2.2import QtQuick.Layouts 1.1import org.kde.plasma.core 2.0 as PlasmaCoreimport org.kde.plasma.components 2.0 as PlasmaComponentsFocusScope {id: rootfocus: trueLayout.minimumWidth: sideBar.width + mainRow.spacing + Math.max(units.gridUnit * 14, runnerColumns.width)Layout.maximumWidth: sideBar.width + mainRow.spacing + Math.max(units.gridUnit * 14, runnerColumns.width)Layout.minimumHeight: Math.max(((rootModel.count - rootModel.separatorCount) * rootList.itemHeight)+ (rootModel.separatorCount * rootList.separatorHeight)+ searchField.height + (2 * units.smallSpacing), sideBar.margins.top + sideBar.margins.bottom+ favoriteApps.contentHeight + favoriteSystemActions.contentHeight + sidebarSeparator.height+ (4 * units.smallSpacing))Layout.maximumHeight: Math.max(((rootModel.count - rootModel.separatorCount) * rootList.itemHeight)+ (rootModel.separatorCount * rootList.separatorHeight)+ searchField.height + (2 * units.smallSpacing), sideBar.margins.top + sideBar.margins.bottom+ favoriteApps.contentHeight + favoriteSystemActions.contentHeight + sidebarSeparator.height+ (4 * units.smallSpacing))signal appendSearchText(string text)function reset() {plasmoid.hideOnWindowDeactivate = true;rootList.currentIndex = -1;searchField.text = "";searchField.focus = true;}Row {id: mainRowheight: parent.heightspacing: units.smallSpacingLayoutMirroring.enabled: ((plasmoid.location == PlasmaCore.Types.RightEdge)|| (Qt.application.layoutDirection == Qt.RightToLeft))PlasmaCore.FrameSvgItem {id: sideBarwidth: units.iconSizes.medium + margins.left + margins.rightheight: parent.heightimagePath: "widgets/frame"prefix: "plain"SideBarSection {id: favoriteAppsanchors.top: parent.topanchors.topMargin: sideBar.margins.topheight: (sideBar.height - sideBar.margins.top - sideBar.margins.bottom- favoriteSystemActions.height - sidebarSeparator.height - (4 * units.smallSpacing))model: globalFavoritesstates: [ State {name: "top"when: (plasmoid.location == PlasmaCore.Types.TopEdge)AnchorChanges {target: favoriteAppsanchors.top: undefinedanchors.bottom: parent.bottom}PropertyChanges {target: favoriteAppsanchors.topMargin: undefinedanchors.bottomMargin: sideBar.margins.bottom}}]Binding {target: globalFavoritesproperty: "iconSize"value: units.iconSizes.medium}}PlasmaCore.SvgItem {id: sidebarSeparatoranchors.bottom: favoriteSystemActions.topanchors.bottomMargin: (2 * units.smallSpacing)anchors.horizontalCenter: parent.horizontalCenterwidth: units.iconSizes.mediumheight: lineSvg.horLineHeightvisible: favoriteApps.model.count && favoriteSystemActions.model.countsvg: lineSvgelementId: "horizontal-line"states: [ State {name: "top"when: (plasmoid.location == PlasmaCore.Types.TopEdge)AnchorChanges {target: sidebarSeparatoranchors.top: favoriteSystemActions.bottomanchors.bottom: undefined}PropertyChanges {target: sidebarSeparatoranchors.topMargin: (2 * units.smallSpacing)anchors.bottomMargin: undefined}}]}SideBarSection {id: favoriteSystemActionsanchors.bottom: parent.bottomanchors.bottomMargin: sideBar.margins.bottommodel: systemFavoritesstates: [ State {name: "top"when: (plasmoid.location == PlasmaCore.Types.TopEdge)AnchorChanges {target: favoriteSystemActionsanchors.top: parent.topanchors.bottom: undefined}PropertyChanges {target: favoriteSystemActionsanchors.topMargin: sideBar.margins.topanchors.bottomMargin: undefined}}]}}ItemListView {id: rootListanchors.top: parent.topwidth: root.width - sideBar.width - mainRow.spacingheight: ((rootModel.count - rootModel.separatorCount) * itemHeight) + (rootModel.separatorCount * separatorHeight)visible: (searchField.text == "")iconsEnabled: falsemodel: rootModelonKeyNavigationAtListEnd: {searchField.focus = true;}states: [ State {name: "top"when: (plasmoid.location == PlasmaCore.Types.TopEdge)AnchorChanges {target: rootListanchors.top: undefinedanchors.bottom: parent.bottom}}]Component.onCompleted: {rootList.exited.connect(root.reset);}}Row {id: runnerColumnsheight: parent.heightsignal focusChanged()visible: (searchField.text != "" && runnerModel.count > 0)Repeater {id: runnerColumnsRepeatermodel: runnerModeldelegate: RunnerResultsList {id: runnerMatchesonKeyNavigationAtListEnd: {searchField.focus = true;}onContainsMouseChanged: {if (containsMouse) {runnerMatches.focus = true;}}onFocusChanged: {if (focus) {runnerColumns.focusChanged();}}function focusChanged() {if (!runnerMatches.focus && runnerMatches.currentIndex != -1) {runnerMatches.currentIndex = -1;}}Keys.onPressed: {var target = null;if (event.key == Qt.Key_Right) {var targets = new Array();for (var i = index + 1; i < runnerModel.count; ++i) {targets[targets.length] = i;}for (var i = 0; i < index; ++i) {targets[targets.length] = i;}for (var i = 0; i < targets.length; ++i) {if (runnerModel.modelForRow(targets[i]).count) {target = runnerColumnsRepeater.itemAt(targets[i]);break;}}} else if (event.key == Qt.Key_Left) {var targets = new Array();for (var i = index - 1; i >= 0; --i) {targets[targets.length] = i;}for (var i = runnerModel.count - 1; i > index; --i) {targets[targets.length] = i;}for (var i = 0; i < targets.length; ++i) {if (runnerModel.modelForRow(targets[i]).count) {target = runnerColumnsRepeater.itemAt(targets[i]);break;}}}if (target) {event.accepted = true;currentIndex = -1;target.currentIndex = 0;target.focus = true;}}Component.onCompleted: {runnerColumns.focusChanged.connect(focusChanged);}Component.onDestruction: {runnerColumns.focusChanged.disconnect(focusChanged);}}}}}PlasmaComponents.TextField {id: searchFieldanchors.bottom: mainRow.bottomanchors.left: parent.leftanchors.leftMargin: sideBar.width + mainRow.spacing + units.smallSpacingwidth: (units.gridUnit * 14) - (2 * units.smallSpacing)focus: trueplaceholderText: i18n("Search...")clearButtonShown: trueonTextChanged: {runnerModel.query = text;}onFocusChanged: {if (focus) {// FIXME: Cleanup arbitration between rootList/runnerCols here and in Keys.if (rootList.visible) {rootList.currentIndex = -1;}if (runnerColumns.visible) {runnerColumnsRepeater.itemAt(0).currentIndex = -1;}}}states: [ State {name: "top"when: plasmoid.location == PlasmaCore.Types.TopEdgeAnchorChanges {target: searchFieldanchors.top: mainRow.topanchors.bottom: undefinedanchors.left: parent.leftanchors.right: undefined}PropertyChanges {target: searchFieldanchors.leftMargin: sideBar.width + mainRow.spacing + units.smallSpacinganchors.rightMargin: undefined}},State {name: "right"when: (plasmoid.location == PlasmaCore.Types.RightEdge|| (plasmoid.location != PlasmaCore.Types.RightEdge && mainRow.LayoutMirroring.enabled))AnchorChanges {target: searchFieldanchors.top: undefinedanchors.bottom: mainRow.bottomanchors.left: undefinedanchors.right: parent.right}PropertyChanges {target: searchFieldanchors.leftMargin: undefinedanchors.rightMargin: sideBar.width + mainRow.spacing + units.smallSpacing}}]Keys.onPressed: {if (event.key == Qt.Key_Up) {if (rootList.visible) {rootList.showChildDialogs = false;rootList.currentIndex = rootList.model.count - 1;rootList.showChildDialogs = true;}if (runnerColumns.visible) {for (var i = 0; i < runnerModel.count; ++i) {if (runnerModel.modelForRow(i).count) {runnerColumnsRepeater.itemAt(i).currentIndex = runnerModel.modelForRow(i).count - 1;break;}}}} else if (event.key == Qt.Key_Down) {if (rootList.visible) {rootList.showChildDialogs = false;rootList.currentIndex = 0;rootList.showChildDialogs = true;}if (runnerColumns.visible) {for (var i = 0; i < runnerModel.count; ++i) {if (runnerModel.modelForRow(i).count) {runnerColumnsRepeater.itemAt(i).currentIndex = 0;break;}}}} else if (event.key == Qt.Key_Enter || event.key == Qt.Key_Return) {if (runnerColumns.visible && runnerModel.modelForRow(0).count) {runnerModel.modelForRow(0).trigger(0, "", null);plasmoid.expanded = false;}}}function appendText(newText) {focus = true;text = text + newText;}}Keys.onPressed: {if (event.key == Qt.Key_Escape) {plasmoid.expanded = false;}}Component.onCompleted: {appendSearchText.connect(searchField.appendText);kicker.reset.connect(reset);windowSystem.hidden.connect(reset);}}