source: calamares/trunk/fuentes/src/qml/calamares/slideshow/Presentation.qml @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 17 months ago

sync with github

File size: 7.9 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
4 *     - added looping, keys-instead-of-shortcut
5 *   Copyright 2018, Adriaan de Groot <groot@kde.org>
6 *     - make looping a property, drop the 'c' fade-key
7 *     - drop navigation through entering a slide number
8 *       (this and the 'c' key make sense in a *presentation*
9 *       slideshow, not in a passive slideshow like Calamares)
10 *     - remove quit key
11 *
12 *   SPDX-License-Identifier: LGPL-2.1
13 *   License-Filename: LICENSES/LGPLv2.1-Presentation
14 */
15
16/****************************************************************************
17**
18** Copyright (C) 2016 The Qt Company Ltd.
19** Contact: https://www.qt.io/licensing/
20**
21** This file is part of the QML Presentation System.
22**
23** $QT_BEGIN_LICENSE:LGPL$
24** Commercial License Usage
25** Licensees holding valid commercial Qt licenses may use this file in
26** accordance with the commercial license agreement provided with the
27** Software or, alternatively, in accordance with the terms contained in
28** a written agreement between you and Digia.  For licensing terms and
29** conditions see http://qt.digia.com/licensing.  For further information
30** use the contact form at http://qt.digia.com/contact-us.
31**
32** GNU Lesser General Public License Usage
33** Alternatively, this file may be used under the terms of the GNU Lesser
34** General Public License version 2.1 as published by the Free Software
35** Foundation and appearing in the file LICENSE.LGPL included in the
36** packaging of this file.  Please review the following information to
37** ensure the GNU Lesser General Public License version 2.1 requirements
38** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
39**
40** In addition, as a special exception, Digia gives you certain additional
41** rights.  These rights are described in the Digia Qt LGPL Exception
42** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
43**
44** GNU General Public License Usage
45** Alternatively, this file may be used under the terms of the GNU
46** General Public License version 3.0 as published by the Free Software
47** Foundation and appearing in the file LICENSE.GPL included in the
48** packaging of this file.  Please review the following information to
49** ensure the GNU General Public License version 3.0 requirements will be
50** met: http://www.gnu.org/copyleft/gpl.html.
51**
52**
53** $QT_END_LICENSE$
54**
55****************************************************************************/
56
57
58import QtQuick 2.5
59import QtQuick.Window 2.0
60
61Item {
62    id: root
63
64    property variant slides: []
65    property int currentSlide: 0
66
67    property bool loopSlides: true
68
69    property bool showNotes: false;
70    property bool allowDelay: true;
71    property alias mouseNavigation: mouseArea.enabled
72    property bool arrowNavigation: true
73    property bool keyShortcutsEnabled: true
74
75    property color titleColor: textColor;
76    property color textColor: "black"
77    property string fontFamily: "Helvetica"
78    property string codeFontFamily: "Courier New"
79
80    // Private API
81    property int _lastShownSlide: 0
82
83    Component.onCompleted: {
84        var slideCount = 0;
85        var slides = [];
86        for (var i=0; i<root.children.length; ++i) {
87            var r = root.children[i];
88            if (r.isSlide) {
89                slides.push(r);
90            }
91        }
92
93        root.slides = slides;
94
95        // Make first slide visible...
96        if (root.slides.length > 0)
97            root.slides[root.currentSlide].visible = true;
98    }
99
100    function switchSlides(from, to, forward) {
101        from.visible = false
102        to.visible = true
103        return true
104    }
105
106    onCurrentSlideChanged: {
107        switchSlides(root.slides[_lastShownSlide], root.slides[currentSlide], currentSlide > _lastShownSlide)
108        _lastShownSlide = currentSlide
109        // Always keep focus on the slideshow
110        root.focus = true
111    }
112
113    function goToNextSlide() {
114        if (root.slides[currentSlide].delayPoints) {
115            if (root.slides[currentSlide]._advance())
116                return;
117        }
118        if (currentSlide + 1 < root.slides.length)
119            ++currentSlide;
120        else if (loopSlides)
121            currentSlide = 0;  // Loop at the end
122    }
123
124    function goToPreviousSlide() {
125        if (currentSlide - 1 >= 0)
126            --currentSlide;
127        else if (loopSlides)
128            currentSlide = root.slides.length - 1
129    }
130
131    focus: true  // Keep focus
132
133    // Navigation through key events, too
134    Keys.onSpacePressed: goToNextSlide()
135    Keys.onRightPressed: goToNextSlide()
136    Keys.onLeftPressed: goToPreviousSlide()
137
138    // navigate with arrow keys
139    Shortcut { sequence: StandardKey.MoveToNextLine; enabled: root.arrowNavigation; onActivated: goToNextSlide() }
140    Shortcut { sequence: StandardKey.MoveToPreviousLine; enabled: root.arrowNavigation; onActivated: goToPreviousSlide() }
141    Shortcut { sequence: StandardKey.MoveToNextChar; enabled: root.arrowNavigation; onActivated: goToNextSlide() }
142    Shortcut { sequence: StandardKey.MoveToPreviousChar; enabled: root.arrowNavigation; onActivated: goToPreviousSlide() }
143
144    // presentation-specific single-key shortcuts (which interfere with normal typing)
145    Shortcut { sequence: " "; enabled: root.keyShortcutsEnabled; onActivated: goToNextSlide() }
146
147    // standard shortcuts
148    Shortcut { sequence: StandardKey.MoveToNextPage; onActivated: goToNextSlide() }
149    Shortcut { sequence: StandardKey.MoveToPreviousPage; onActivated: goToPreviousSlide() }
150
151    MouseArea {
152        id: mouseArea
153        anchors.fill: parent
154        acceptedButtons: Qt.LeftButton | Qt.RightButton
155        onClicked: {
156            if (mouse.button == Qt.RightButton)
157                goToPreviousSlide()
158            else
159                goToNextSlide()
160        }
161        onPressAndHold: goToPreviousSlide(); //A back mechanism for touch only devices
162    }
163
164    Window {
165        id: notesWindow;
166        width: 400
167        height: 300
168
169        title: "QML Presentation: Notes"
170        visible: root.showNotes
171
172        Flickable {
173            anchors.fill: parent
174            contentWidth: parent.width
175            contentHeight: textContainer.height
176
177            Item {
178                id: textContainer
179                width: parent.width
180                height: notesText.height + 2 * notesText.padding
181
182                Text {
183                    id: notesText
184
185                    property real padding: 16;
186
187                    x: padding
188                    y: padding
189                    width: parent.width - 2 * padding
190
191
192                    font.pixelSize: 16
193                    wrapMode: Text.WordWrap
194
195                    property string notes: root.slides[root.currentSlide].notes;
196
197                    onNotesChanged: {
198                        var result = "";
199
200                        var lines = notes.split("\n");
201                        var beginNewLine = false
202                        for (var i=0; i<lines.length; ++i) {
203                            var line = lines[i].trim();
204                            if (line.length == 0) {
205                                beginNewLine = true;
206                            } else {
207                                if (beginNewLine && result.length) {
208                                    result += "\n\n"
209                                    beginNewLine = false
210                                }
211                                if (result.length > 0)
212                                    result += " ";
213                                result += line;
214                            }
215                        }
216
217                        if (result.length == 0) {
218                            font.italic = true;
219                            text = "no notes.."
220                        } else {
221                            font.italic = false;
222                            text = result;
223                        }
224                    }
225                }
226            }
227        }
228    }
229}
Note: See TracBrowser for help on using the repository browser.