From 04555d2dc8d5fb23240e99b14bbc804d049b4f29 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 29 Aug 2016 10:05:28 +0200 Subject: Presentation.qml: allow directly changing currentSlide instead of needing to go through the switchSlides function. Change-Id: Ia28df40025070fbdd699720f7017ec0619ec85a6 Reviewed-by: Frederik Gladhorn --- src/Presentation.qml | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/Presentation.qml b/src/Presentation.qml index d922f2d..a99e272 100644 --- a/src/Presentation.qml +++ b/src/Presentation.qml @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QML Presentation System. ** @@ -47,7 +47,7 @@ Item { id: root property variant slides: [] - property int currentSlide; + property int currentSlide: 0 property bool showNotes: false; property bool allowDelay: true; @@ -61,6 +61,7 @@ Item { // Private API property bool _faded: false property int _userNum; + property int _lastShownSlide: 0 Component.onCompleted: { var slideCount = 0; @@ -76,10 +77,8 @@ Item { root._userNum = 0; // Make first slide visible... - if (root.slides.length > 0) { - root.currentSlide = 0; + if (root.slides.length > 0) root.slides[root.currentSlide].visible = true; - } } function switchSlides(from, to, forward) { @@ -88,6 +87,11 @@ Item { return true } + onCurrentSlideChanged: { + switchSlides(root.slides[_lastShownSlide], root.slides[currentSlide], currentSlide > _lastShownSlide) + _lastShownSlide = currentSlide + } + function goToNextSlide() { root._userNum = 0 if (_faded) @@ -96,13 +100,9 @@ Item { if (root.slides[currentSlide]._advance()) return; } - if (root.currentSlide + 1 < root.slides.length) { - var from = slides[currentSlide] - var to = slides[currentSlide + 1] - if (switchSlides(from, to, true)) { - currentSlide = currentSlide + 1; - root.focus = true; - } + if (currentSlide + 1 < root.slides.length) { + ++currentSlide; + root.focus = true; } } @@ -110,13 +110,9 @@ Item { root._userNum = 0 if (root._faded) return - if (root.currentSlide - 1 >= 0) { - var from = slides[currentSlide] - var to = slides[currentSlide - 1] - if (switchSlides(from, to, false)) { - currentSlide = currentSlide - 1; - root.focus = true; - } + if (currentSlide - 1 >= 0) { + --currentSlide; + root.focus = true; } } @@ -126,13 +122,9 @@ Item { return if (_userNum < 0) goToNextSlide() - else if (root.currentSlide != _userNum) { - var from = slides[currentSlide] - var to = slides[_userNum] - if (switchSlides(from, to, _userNum > currentSlide)) { - currentSlide = _userNum; - root.focus = true; - } + else { + currentSlide = _userNum; + root.focus = true; } } -- cgit v1.2.3