Debian Codegraph @

rc/qml/AlbumsOverview.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
18 import QtQuick 2.9
19 import Lomiri.Components 1.3
20 import Gallery 1.0
21 import "AlbumEditor"
22 import "AlbumViewer"
23 import "Components"
24 import "Utility"
25
26 /*!
27 Shows all the albums in one grid view
28 */
29 Checkerboard {
30 id: root
31
32 property bool isAlbumOpened: false
33
34 property int albumCurrentlyInView: -1
35 StateSaver.properties: "albumCurrentlyInView"
36
37 Component.onCompleted: {
38 /* FIXME: Does not working after PageStack
39 if (albumCurrentlyInView != -1) {
40 for (var i = 0; i < albumCollectionModel.count; i++) {
41 if (albumCollectionModel.getAt(i).id == albumCurrentlyInView) {
42 if (albumCollectionModel.getAt(i).currentPage < 0)
43 albumCollectionModel.getAt(i).currentPage = 1
44
45 albumViewer.album = albumCollectionModel.getAt(i);
46 root.visible = false;
47
48 if (albumViewer.origin) {
49 albumViewer.visible = true
50 overview.pushPage(albumViewer);
51 }
52 else
53 albumViewer.visible = true
54
55 if (albumViewer.previewItem)
56 albumViewer.previewItem.visible = false
57
58 return;
59 }
60 }
61 }
62 */
63 }
64
65 onActiveChanged: {
66 if (active) {
67 root.visible = true;
68 }
69 }
70
71 /*!
72 */
73 function getRectOfAlbumPreview(album, relativeTo) {
74 return getRectOfItemAt(model.indexOf(album), relativeTo);
75 }
76
77 function closeAlbum() {
78 if (isAlbumOpened)
79 albumViewer.closeAlbum();
80 }
81
82 topExtraGutter: getDeviceSpecific("albumGridTopMargin")
83 bottomExtraGutter: getDeviceSpecific("albumGridGutterHeight") / 2
84 leftExtraGutter: getDeviceSpecific("albumGridLeftMargin")
85 rightExtraGutter: getDeviceSpecific("albumGridRightMargin")
86
87 itemWidth: getDeviceSpecific("albumThumbnailWidth")
88 itemHeight: getDeviceSpecific("albumThumbnailHeight")
89 minGutterWidth: getDeviceSpecific("albumGridGutterWidth")
90 minGutterHeight: getDeviceSpecific("albumGridGutterHeight")
91
92 selection: SelectionState {
93 allowSelectionModeChange: false
94 model: root.model
95 }
96
97 model: AlbumCollectionModel {
98 id: albumCollectionModel
99 }
100
101 delegate: CheckerboardDelegate {
102 id: thisDelegate
103 property real commitFraction: 0.05
104
105 // internal
106 property bool validSwipe: false
107
108 z: (albumThumbnail.isFlipping ? 10 : 0)
109
110 checkerboard: root
111
112 contentIsSwipable: album.containedCount > 0
113
114 onSwipeStarted: {
115 validSwipe = ((leftToRight && !album.closed) || (!leftToRight && album.closed));
116 }
117
118 onSwiping: {
119 if (!validSwipe)
120 return;
121
122 var availableDistance = (leftToRight) ? (width - start) : start;
123 var fraction = Math.max(0, Math.min(1, distance / availableDistance));
124
125 albumThumbnail.openFraction = (leftToRight ? 1 - fraction : fraction);
126 }
127
128 onLongPressed: {
129 albumMenu.album = album
130 albumMenu.caller = content
131 albumMenu.show()
132 }
133
134 onSwiped: {
135 if (!validSwipe)
136 return;
137
138 var fraction = (leftToRight
139 ? 1 - albumThumbnail.openFraction
140 : albumThumbnail.openFraction);
141 if ((leftToRight && fraction >= commitFraction)
142 || (!leftToRight && fraction < commitFraction))
143 albumThumbnail.close();
144 else
145 albumThumbnail.open();
146 }
147
148 content: AlbumPreviewComponent {
149 id: albumThumbnail
150
151 property real maxAddScale: 0.5
152
153 width: root.itemWidth
154 height: root.itemHeight
155
156 album: modelData.album
157 load: true
158
159 // Scale from 1 to 1 + maxAddScale and back to 1 as openFraction goes
160 // from 0 to 0.5 to 1.
161 scale: 1 + maxAddScale - Math.abs((openFraction - 0.5) * maxAddScale * 2)
162 }
163 }
164
165 onActivated: {
166 if (object.currentPage < 0)
167 object.currentPage = 1
168
169 isAlbumOpened = true
170 albumCurrentlyInView = object.id
171 albumViewer.album = object
172 albumViewer.origin = root.getRectOfAlbumPreview(object, albumViewer)
173 albumViewer.previewItem = activatingItem
174 root.visible = false;
175
176 if (albumViewer.origin) {
177 albumViewer.visible = true;
178 if (!APP.desktopMode)
179 setFullScreenAppMode(true);
180 overview.pushPage(albumViewer);
181 if (object.containedCount > 0)
182 albumViewer.header.visible = false;
183 else
184 albumViewer.header.visible = true;
185 }
186 else
187 albumViewer.visible = true
188
189 if (albumViewer.previewItem)
190 albumViewer.previewItem.visible = false
191 }
192
193 Rectangle {
194 id: overviewGlass
195
196 anchors.fill: parent
197
198 color: "black"
199 opacity: 0.0
200 }
201
202 AlbumEditMenu {
203 id: albumMenu
204
205 property Album album
206
207 visible: false
208
209 onEditClicked: albumEditorLoader.load(album)
210
211 onDeleteClicked: {
212 albumTrashDialog.album = album
213 albumTrashDialog.caller = caller
214 albumTrashDialog.show()
215 }
216 }
217
218 // Dialog for deleting albums.
219 DeleteOrDeleteWithContentsDialog {
220 id: albumTrashDialog
221
222 visible: false
223 }
224
225 /// Contains the actions for the toolbar in the albums tab
226 head.actions: [
227 Action {
228 objectName: "addButton"
229 text: i18n.tr("Add new album") // Text in HUD
230 iconName: "add"
231 onTriggered: {
232 var album = albumCollectionModel.createOrphan();
233 album.title = i18n.tr("New Photo Album");
234 album.subtitle = i18n.tr("Subtitle");
235
236 albumEditorLoader.load(album)
237 }
238 },
239 Action {
240 objectName: "cameraButton"
241 text: i18n.tr("Camera")
242 visible: !APP.desktopMode
243 iconName: "camera-app-symbolic"
244 onTriggered: Qt.openUrlExternally("appid://camera.ubports/camera/current-user-version")
245 }
246 ]
247
248 AlbumViewer {
249 id: albumViewer
250 objectName: "albumViewer"
251 anchors.fill: parent
252 visible: false
253 onIsOpenChanged: if (!isOpen) albumCurrentlyInView = -1
254
255 onCloseRequested: isAlbumOpened = false;
256 onQuickCloseRequested: isAlbumOpened = false;
257 }
258
259 Loader {
260 id: albumEditorLoader
261 anchors.fill: parent
262
263 property var album
264
265 onStatusChanged: {
266 if (status === Loader.Ready) {
267 albumEditorLoader.item.album = albumEditorLoader.album
268 overview.pushPage(albumEditorLoader.item)
269 }
270 }
271
272 function load(album) {
273 albumEditorLoader.album = album
274 sourceComponent = albumEditorComponent
275 }
276
277 Component {
278 id: albumEditorComponent
279 AlbumEditor {
280 id: albumEditor
281 objectName: "albumEditor"
282 anchors.fill: parent
283 visible: false
284
285 onMediaSelectorHidden: albumEditorCheckerboardHidden(newScrollPos);
286 onCloseRequested: {
287 overview.popPage()
288 albumEditorLoader.album = null
289 albumEditorLoader.sourceComponent = null
290 }
291 }
292 }
293 }
294 }