Debian Codegraph @

rc/qml/AlbumViewer/AlbumOpener.qml

raw
1 /*
2 * Copyright (C) 2012-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 * Authors:
17 * Charles Lindsay <[email protected]>
18 */
19
20 import QtQuick 2.9
21 import Gallery 1.0
22
23 // A component to show an album thumbnail in closed or open state, and
24 // transition between the two.
25 Item {
26 id: albumOpener
27
28 // public
29 /*!
30 */
31 property Album album
32 /*!
33 */
34 property bool isPreview: false
35 /*!
36 */
37 property bool load: false
38 /*!
39 */
40 property bool contentHasPreviewFrame: false
41 /*!
42 */
43 property int duration: 1000
44 /*!
45 */
46 property real openFraction: 0
47 // Whether to draw the cover (defaults to true)
48 // This is used to prevent the cover from being drawn during certain transitions.
49 property bool showCover: true
50 /// Show the album closed, even if marked open in the DB
51 property bool showClosed: false
52 /*!
53 */
54 property int insideLeftPage: defaultInsideLeftPage
55 /*!
56 */
57 property int insideRightPage: defaultInsideRightPage
58
59 /*!
60 */
61 property real topMargin: previewTopMargin
62 /*!
63 */
64 property real bottomMargin: previewBottomMargin
65 /*!
66 */
67 property real gutterMargin: previewGutterMargin
68 /*!
69 */
70 property real outerMargin: previewOuterMargin
71 /*!
72 */
73 property real insideMargin: previewInsideMargin
74
75 // readonly
76 /*!
77 */
78 property bool isFlipping: (openFraction != 0 && openFraction != 1)
79 /*!
80 */
81 property alias frameToContentWidth: rightPage.frameToContentWidth
82 /*!
83 */
84 property alias frameToContentHeight: rightPage.frameToContentHeight
85
86 /*!
87 */
88 property int defaultInsideLeftPage: leftPage.leftPageForCurrent(currentOrFirstContentPage)
89 /*!
90 */
91 property int defaultInsideRightPage: rightPage.rightPageForCurrent(currentOrFirstContentPage)
92
93 /*!
94 */
95 property alias pageTopMargin: rightPage.pageTopMargin
96 /*!
97 */
98 property alias pageBottomMargin: rightPage.pageBottomMargin
99 /*!
100 */
101 property alias pageGutterMargin: rightPage.pageGutterMargin
102 /*!
103 */
104 property alias pageOuterMargin: rightPage.pageOuterMargin
105 /*!
106 */
107 property alias pageInsideMargin: rightPage.pageInsideMargin
108
109 /*!
110 */
111 property alias previewTopMargin: rightPage.previewTopMargin
112 /*!
113 */
114 property alias previewBottomMargin: rightPage.previewBottomMargin
115 /*!
116 */
117 property alias previewGutterMargin: rightPage.previewGutterMargin
118 /*!
119 */
120 property alias previewOuterMargin: rightPage.previewOuterMargin
121 /*!
122 */
123 property alias previewInsideMargin: rightPage.previewInsideMargin
124
125 // internal
126 /*!
127 */
128 property int currentOrFirstContentPage: (!album
129 ? -1
130 : (album.currentPage == album.firstValidCurrentPage
131 ? album.firstContentPage
132 : album.currentPage))
133
134 /*!
135 */
136 function open() {
137 animator.to = 1;
138 animator.duration = (1 - openFraction) * duration;
139 animator.restart();
140 }
141
142 /*!
143 */
144 function close() {
145 animator.to = 0;
146 animator.duration = openFraction * duration;
147 animator.restart();
148 }
149
150 onAlbumChanged: openFraction = (!album || album.closed || showClosed ? 0 : 1)
151
152 Connections {
153 target: album
154 ignoreUnknownSignals: true
155 onClosedChanged: openFraction = (album.closed || showClosed ? 0 : 1)
156 }
157
158 Item {
159 id: shifter
160
161 // Shift it over as it opens so the visuals stay centered.
162 x: (width * openFraction)
163 y: -5 // Top of page frame
164 width: parent.width
165 height: parent.height
166
167 AlbumPageComponent {
168 id: rightPage
169
170 anchors.fill: parent
171 visible: (openFraction > 0 && openFraction < 1)
172 load: albumOpener.load
173
174 album: albumOpener.album
175 frontPage: insideRightPage
176 backPage: (album ? leftPageForCurrent(album.lastValidCurrentPage) : -1)
177
178 isPreview: albumOpener.isPreview
179 contentHasPreviewFrame: albumOpener.contentHasPreviewFrame
180
181 flipFraction: (openFraction > 0.5 && openFraction <= 1 ? openFraction * -2 + 3 : 0)
182
183 topMargin: albumOpener.topMargin
184 bottomMargin: albumOpener.bottomMargin
185 gutterMargin: albumOpener.gutterMargin
186 outerMargin: albumOpener.outerMargin
187 insideMargin: albumOpener.insideMargin
188 showCover: albumOpener.showCover
189 }
190
191 AlbumPageComponent {
192 id: leftPage
193
194 anchors.fill: parent
195 load: albumOpener.load
196
197 album: albumOpener.album
198 frontPage: (album ? rightPageForCurrent(album.firstValidCurrentPage) : -1)
199 backPage: insideLeftPage
200
201 isPreview: albumOpener.isPreview
202 contentHasPreviewFrame: albumOpener.contentHasPreviewFrame
203
204 flipFraction: (openFraction >= 0 && openFraction < 0.5 ? openFraction * 2 : 1)
205
206 topMargin: albumOpener.topMargin
207 bottomMargin: albumOpener.bottomMargin
208 gutterMargin: albumOpener.gutterMargin
209 outerMargin: albumOpener.outerMargin
210 insideMargin: albumOpener.insideMargin
211 showCover: albumOpener.showCover
212 }
213 }
214
215 NumberAnimation {
216 id: animator
217
218 target: albumOpener
219 property: "openFraction"
220 easing.type: Easing.OutQuad
221
222 onRunningChanged: {
223 if (running)
224 return;
225
226 if (openFraction == 0) {
227 album.closed = true;
228 } else if (openFraction == 1) {
229 album.closed = false;
230 if (album.currentPage == album.firstValidCurrentPage)
231 album.currentPage = album.firstContentPage;
232 }
233 }
234 }
235 }