Warning, /plasma-bigscreen/youtube-voice-application/ui/+mediacenter/views/ListTileView.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *  Copyright 2019 Aditya Mehra <aix.m@outlook.com>
0003  *  Copyright 2019 Marco Martin <mart@kde.org>
0004  *
0005  *  This program is free software; you can redistribute it and/or modify
0006  *  it under the terms of the GNU General Public License as published by
0007  *  the Free Software Foundation; either version 2 of the License, or
0008  *  (at your option) any later version.
0009  *
0010  *  This program is distributed in the hope that it will be useful,
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  *  GNU General Public License for more details.
0014  *
0015  *  You should have received a copy of the GNU General Public License
0016  *  along with this program; if not, write to the Free Software
0017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  2.010-1301, USA.
0018  */
0019 
0020 import QtQuick 2.12
0021 import QtQuick.Layouts 1.4
0022 import QtQuick.Window 2.2
0023 import QtQuick.Controls 2.4 as Controls
0024 import QtGraphicalEffects 1.12
0025 
0026 import org.kde.plasma.core 2.0 as PlasmaCore
0027 import org.kde.plasma.components 3.0 as PlasmaComponents
0028 import org.kde.kirigami 2.5 as Kirigami
0029 
0030 FocusScope {
0031     id: root
0032     signal activated
0033     property string title
0034     property alias view: view
0035     property alias delegate: view.delegate
0036     property alias model: view.model
0037     property alias currentIndex: view.currentIndex
0038     property alias currentItem: view.currentItem
0039     Layout.fillWidth: true
0040     
0041     implicitHeight: view.implicitHeight + header.implicitHeight
0042     property int columns: parent.width >= 1500 ? Math.max(3, Math.floor(width / (Kirigami.Units.gridUnit * 14))) : 5
0043     property alias cellWidth: view.cellWidth
0044     
0045     property Item navigationUp
0046     property Item navigationDown
0047     
0048      Kirigami.Heading {
0049         id: header
0050         anchors {
0051             left: parent.left
0052             right: parent.right
0053             top: parent.top
0054         }
0055         text: title
0056         layer.enabled: true
0057         color: "white"
0058     }
0059     
0060     ListView {
0061         id: view
0062         anchors {
0063             left: parent.left
0064             right: parent.right
0065             top: header.baseline
0066             bottom: parent.bottom
0067             topMargin: Kirigami.Units.largeSpacing*2
0068             leftMargin: -Kirigami.Units.largeSpacing
0069         }
0070         focus: true
0071 
0072         z: activeFocus ? 10: 1
0073         keyNavigationEnabled: true
0074         //Centering disabled as experiment
0075         highlightRangeMode: ListView.ApplyRange
0076 
0077         highlightFollowsCurrentItem: true
0078         snapMode: ListView.SnapToItem
0079         cacheBuffer: width
0080         implicitHeight: cellWidth + Kirigami.Units.gridUnit * 3
0081         rightMargin: width-cellWidth*3
0082         readonly property int cellWidth: parent.width / 6
0083         preferredHighlightBegin: cellWidth
0084         preferredHighlightEnd: cellWidth
0085         displayMarginBeginning: cellWidth
0086         displayMarginEnd: cellWidth
0087 
0088         highlightMoveVelocity: -1
0089         highlightMoveDuration: Kirigami.Units.longDuration
0090 
0091         onContentWidthChanged: if (view.currentIndex === 0) view.contentX = view.originX
0092 
0093         onMovementEnded: flickEnded()
0094         onFlickEnded: currentIndex = indexAt(mapToItem(contentItem, cellWidth, 0).x, 0)
0095         
0096         spacing: 0
0097         orientation: ListView.Horizontal
0098 
0099         move: Transition {
0100             SmoothedAnimation {
0101                 property: "x"
0102                 duration: Kirigami.Units.longDuration
0103             }
0104         }
0105 
0106         KeyNavigation.left: root
0107         KeyNavigation.right: root
0108 
0109         Keys.onDownPressed:  {
0110             if (!navigationDown) {
0111                 return;
0112             }
0113 
0114             if (navigationDown instanceof TileView) {
0115                 navigationDown.currentIndex = Math.min(Math.floor(navigationDown.view.indexAt(navigationDown.view.contentX + cellWidth/2, height/2)) + (view.currentIndex - view.indexAt(view.contentX + cellWidth/2, height/2)), navigationDown.view.count - 1);
0116 
0117                 if (navigationDown.currentIndex < 0) {
0118                     navigationDown.currentIndex = view.currentIndex > 0 ? navigationDown.view.count - 1 : 0
0119                 }
0120             }
0121 
0122             navigationDown.forceActiveFocus();
0123         }
0124 
0125         Keys.onUpPressed:  {
0126             if (!navigationUp) {
0127                 return;
0128             }
0129 
0130             if (navigationUp instanceof TileView) {
0131                 navigationUp.currentIndex = Math.min(Math.floor(navigationUp.view.indexAt(navigationUp.view.contentX + cellWidth/2, height/2)) + (view.currentIndex - view.indexAt(view.contentX + cellWidth/2, height/2)), navigationUp.view.count - 1);
0132 
0133                 if (navigationUp.currentIndex < 0) {
0134                     navigationUp.currentIndex = view.currentIndex > 0 ? navigationUp.view.count - 1 : 0
0135                 }
0136             }
0137 
0138             navigationUp.forceActiveFocus();
0139         }
0140     }
0141 }