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

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