/*Copyright (C) 2011 Martin GrΓ€Γlin <mgraesslin@kde.org>Copyright (C) 2012 Gregor Taetzner <gregor@freenet.de>Copyright 2014 Sebastian KΓΌgler <sebas@kde.org>This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe 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 ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public License alongwith this program; if not, write to the Free Software Foundation, Inc.,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.*/import QtQuick 2.0import org.kde.plasma.core 2.0 as PlasmaCoreimport org.kde.plasma.extras 2.0 as PlasmaExtrasimport org.kde.plasma.components 2.0 as PlasmaComponentsimport org.kde.plasma.private.kickoff 0.1 as KickoffItem {id: appViewContaineranchors.fill: parentobjectName: "ApplicationsView"property ListView listView: applicationsViewfunction decrementCurrentIndex() {applicationsView.decrementCurrentIndex();}function incrementCurrentIndex() {applicationsView.incrementCurrentIndex();}function activateCurrentIndex(start) {if (!applicationsView.currentItem.modelChildren) {if (!start) {return;}}appViewScrollArea.state = "OutgoingLeft";}function deactivateCurrentIndex() {if (crumbModel.count > 0) { // this is not the case when switching from the "Applications" to the "Favorites" tab using the "Left" keybreadcrumbsElement.children[crumbModel.count-1].clickCrumb();appViewScrollArea.state = "OutgoingRight";return true;}return false;}function openContextMenu() {listView.currentItem.openContextMenu();}Connections {target: plasmoidonExpandedChanged: {if (!expanded) {applicationsView.model.rootIndex = 0;applicationsView.positionViewAtBeginning();applicationsView.clearBreadcrumbs();}}}ContextMenu {id: contextMenu}Item {id: crumbContaineranchors {top: parent.topleft: parent.leftright: parent.right}height: childrenRect.heightBehavior on opacity { NumberAnimation { duration: units.longDuration } }Flickable {id: breadcrumbFlickableanchors {top: parent.topleft: parent.leftright: parent.right}height: breadcrumbsElement.heightboundsBehavior: Flickable.StopAtBoundscontentWidth: breadcrumbsElement.widthpixelAligned: true//contentX: contentWidth - widthPlasmaComponents.ButtonRow {id: breadcrumbsElementexclusive: falseBreadcrumb {id: rootBreadcrumbroot: truetext: i18n("All Applications")depth: 0}Repeater {model: ListModel {id: crumbModel// Array of the category indexesproperty var indexes: []}Breadcrumb {root: falsetext: model.text}}onWidthChanged: {breadcrumbFlickable.contentX = Math.max(0, breadcrumbsElement.width - breadcrumbFlickable.width)}}} // Flickable} // crumbContainerPlasmaExtras.ScrollArea {id: appViewScrollAreaproperty Item activatedItem: nullanchors {top: crumbContainer.bottombottom: parent.bottomrightMargin: -units.largeSpacingleftMargin: -units.largeSpacing}Behavior on opacity { NumberAnimation { duration: units.longDuration } }width: parent.widthfunction moveRight() {state = "";activatedItem.activate()applicationsView.positionViewAtBeginning()}function moveLeft() {state = "";// newModelIndex set by clicked breadcrumbvar oldIndex = applicationsView.model.rootIndex;applicationsView.model.rootIndex = applicationsView.newModelIndex;applicationsView.positionViewAtIndex(applicationsView.model.model.rowForModelIndex(oldIndex), ListView.Center)}ListView {id: applicationsViewproperty variant newModelIndexfocus: truekeyNavigationWraps: trueboundsBehavior: Flickable.StopAtBoundshighlight: KickoffHighlight {}highlightMoveDuration : 0highlightResizeDuration: 0model: VisualDataModel {id: vmodeldelegate: KickoffItem {id: kickoffItemappView: truePlasmaCore.SvgItem {anchors {right: parent.rightverticalCenter: parent.verticalCenterrightMargin: y}height: units.iconSizes.smallwidth: heightsvg: arrowSvgelementId: "go-next"visible: hasModelChildren}}model: Kickoff.ApplicationModel {sortAppsByName: plasmoid.configuration.showAppsByNameonModelReset: {updatedLabelTimer.running = true;applicationsView.clearBreadcrumbs();}}} // VisualDataModelfunction addBreadcrumb(categoryIndex, title) {crumbModel.append({"text": title, "depth": crumbModel.count+1})crumbModel.indexes.push(categoryIndex);}function clearBreadcrumbs() {crumbModel.clear();crumbModel.indexes = [];}PlasmaCore.Svg {id: arrowSvgimagePath: "toolbar-icons/go"}} // applicationsViewstates: [State {name: "OutgoingLeft"PropertyChanges {target: appViewScrollAreax: -parent.widthopacity: 0.0}},State {name: "OutgoingRight"PropertyChanges {target: appViewScrollAreax: parent.widthopacity: 0.0}}]transitions: [Transition {to: "OutgoingLeft"SequentialAnimation {// We need to cache the currentItem since the selection can move during animation,// and we want the item that has been clicked on, not the one that is under the// mouse once the animation is doneScriptAction { script: appViewScrollArea.activatedItem = applicationsView.currentItem }NumberAnimation { properties: "x,opacity"; easing.type: Easing.InQuad; duration: units.longDuration }ScriptAction { script: appViewScrollArea.moveRight() }}},Transition {to: "OutgoingRight"SequentialAnimation {NumberAnimation { properties: "x,opacity"; easing.type: Easing.InQuad; duration: units.longDuration }ScriptAction { script: appViewScrollArea.moveLeft() }}}]} // appViewScrollAreaTimer {id: updatedLabelTimerinterval: 1500running: falserepeat: trueonRunningChanged: {if (running) {updatedLabel.opacity = 1;crumbContainer.opacity = 0.3;appViewScrollArea.opacity = 0.3;}}onTriggered: {updatedLabel.opacity = 0;crumbContainer.opacity = 1;appViewScrollArea.opacity = 1;running = false;}}PlasmaComponents.Label {id: updatedLabeltext: i18n("Applications updated.")opacity: 0visible: opacity != 0anchors.centerIn: parentBehavior on opacity { NumberAnimation { duration: units.shortDuration } }}} // appViewContainer