Warning, /system/mycroft-gui/import/qml/SlideShow.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * Copyright 2019 by Aditya Mehra <aix.m@outlook.com>
0003  * Copyright 2019 by Marco Martin <mart@kde.org>
0004  *
0005  * Licensed under the Apache License, Version 2.0 (the "License");
0006  * you may not use this file except in compliance with the License.
0007  * You may obtain a copy of the License at
0008  *
0009  *    http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  *
0017  */
0018 
0019 
0020 import QtQuick 2.15
0021 import QtQuick.Layouts 1.15
0022 import QtQuick.Controls 2.15 as Controls
0023 import org.kde.kirigami 2.19 as Kirigami
0024 import Mycroft 1.0 as Mycroft
0025 
0026 /**
0027  * Contains an slideshow object that can autoplay each slide and loop
0028  * This can be used inside any mycroft delegate like in the following example.
0029  *
0030  * @code
0031  *  Mycroft.Delegate {
0032  *      ...
0033  *      Mycroft.SlideShow {
0034  *              id: root model: sessionData.exampleModel // model with slideshow data
0035  *              anchors.fill: parent
0036  *              interval: 5000 // time to switch between slides 
0037  *              running: true // can be set to false if one wants to swipe manually 
0038  *              delegate: Item {...}
0039  *              loop: true // can be set to play through continously or just once
0040  *      }
0041  *  }
0042  * @endcode
0043  */
0044 
0045 Item {
0046     id: root
0047     focus: true
0048     
0049     //Listview Model
0050     property alias model: slideShowView.model
0051     
0052     //Listview Delegate
0053     property alias delegate: slideShowView.delegate
0054     
0055     //Slideshow Timer Control
0056     property alias interval: slideShowTimer.interval
0057     
0058     //Slideshow Timer Running
0059     property alias running: slideShowTimer.running
0060     
0061     //Slideshow Timer Loop
0062     property alias loop: slideShowTimer.repeat
0063     
0064     Timer {
0065         id: slideShowTimer
0066         interval: 5000
0067         running: false
0068         repeat: true
0069         onTriggered: {
0070             var getCount = slideShowView.count
0071             if(slideShowView.currentIndex !== getCount){
0072                 slideShowView.currentIndex = slideShowView.currentIndex+1;
0073             } else{
0074                 slideShowView.currentIndex = 0
0075             }
0076         }
0077     }
0078     
0079     ColumnLayout { 
0080         anchors.fill: parent
0081         spacing: Kirigami.Units.largeSpacing
0082         
0083         ListView {
0084             id: slideShowView
0085             layoutDirection: Qt.LeftToRight
0086             Layout.fillWidth: true
0087             Layout.alignment: Qt.AlignTop
0088             Layout.preferredHeight: root.height - slideshowIndicator.height
0089             orientation: ListView.Horizontal
0090             snapMode: ListView.SnapOneItem;
0091             flickableDirection: Flickable.AutoFlickDirection
0092             highlightRangeMode: ListView.StrictlyEnforceRange
0093             highlightFollowsCurrentItem: true
0094             spacing: Kirigami.Units.largeSpacing
0095             clip: true
0096             
0097             onFlickEnded: {
0098                 slideShowTimer.restart()
0099             }
0100         }
0101         
0102         Controls.PageIndicator {
0103             id: slideshowIndicator
0104             Layout.preferredHeight: Kirigami.Units.gridUnit * 2
0105             Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
0106             currentIndex: slideShowView.currentIndex
0107             count: slideShowView.count        
0108         }
0109     }
0110     
0111     Keys.onLeftPressed: {
0112             if (slideShowView.currentIndex > 0 ) {
0113                 slideShowView.currentIndex = slideShowView.currentIndex-1
0114             }
0115             
0116             if (slideShowView.currentIndex == 0 ) {
0117                 slideShowView.currentIndex = slideShowView.count
0118             }
0119             slideShowTimer.restart()
0120     }
0121 
0122     Keys.onRightPressed: {
0123         if (slideShowView.currentIndex < slideShowView.count) {
0124             slideShowView.currentIndex = Math.min(slideShowView.currentIndex+1, slideShowView.count)
0125         } 
0126         
0127         if(slideShowView.currentIndex == slideShowView.count) {
0128             slideShowView.currentIndex = 0
0129         }
0130         slideShowTimer.restart()
0131     }
0132 }