Debian Codegraph @

rc/qml/AlbumViewer/AlbumViewerAnimated.qml

raw
1 /*
2 * Copyright (C) 2013-2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.9
18 import Lomiri.Components 1.3
19 import Gallery 1.0
20
21 /*! @brief AlbumViewerAnimated shows an album, and performs animations when opening and closing
22 *
23 * Set the album and origin properties befor calling open()
24 * The first call of open() is slow, as the lazy loading is used for the album viewer which is a
25 * big component.
26 */
27 Item {
28 id: root
29
30 /// The album to be shown in that viewer
31 property Album album
32 /// Origin (rectangle) where this view is animated from when calling open()
33 /// And where it is animated to when this view is closed
34 property variant origin
35 /// The preview item that was used to open the view, or null, if it was opend another way
36 /// This item will be hidden when this view is opened. And shown again after closing this view
37 property Item previewItem: null
38 /// Is true if the opne or close animation is running
39 property bool animationRunning: false
40 /// Indicates if this view is open
41 property bool isOpen: false
42
43 /// Opens the album. If the origin is set, an animation is performed
44 function open() {
45 loader_albumViewer.load()
46 if (album.currentPage < 0)
47 album.currentPage = 1
48 loader_albumViewer.item.albumViewer.album = album
49 if (root.origin) {
50 loader_albumViewer.item.albumViewer.visible = true
51 overview.pushPage(loader_albumViewer.item.albumViewer);
52 }
53 else
54 loader_albumViewer.item.albumViewer.visible = true
55 if (previewItem)
56 previewItem.visible = false
57 }
58
59 Component {
60 id: component_ViewerItem
61 Item {
62 id: viewerItem
63 property alias albumViewer: inner_albumViewer
64
65 Rectangle {
66 id: overviewGlass
67 anchors.fill: parent
68 color: "black"
69 opacity: 0.0
70 }
71
72 AlbumViewer {
73 id: inner_albumViewer
74 objectName: "albumViewer"
75
76 anchors.fill: parent
77 visible: false
78
79 onCloseRequested: {
80 if (root.origin) {
81 if (album)
82 album.closed = !stayOpen || (viewingPage == 0);
83 if (previewItem)
84 previewItem.visible = true
85 loader_albumViewer.unload()
86 }
87 inner_albumViewer.visible = false
88 overview.popPage();
89 isOpen = false
90 }
91 onQuickCloseRequested: {
92 inner_albumViewer.visible = false
93 overview.popPage();
94 isOpen = false
95 if (previewItem)
96 previewItem.visible = true;
97 loader_albumViewer.unload();
98 }
99 }
100 }
101 }
102 Loader {
103 id: loader_albumViewer
104 anchors.fill: parent
105
106 onStatusChanged: {
107 if (status == Loader.Ready)
108 isOpen = true;
109 }
110
111 function load() {
112 if (sourceComponent == undefined) {
113 sourceComponent = component_ViewerItem
114 }
115 }
116 function unload() {
117 sourceComponent = undefined
118 }
119 }
120
121 MouseArea {
122 id: transitionClickBlocker
123 anchors.fill: parent
124 enabled: root.animationRunning
125 }
126 }