Debian Codegraph @

rc/qml/Components/PopupAlbumPicker.qml

raw
1 /*
2 * Copyright (C) 2011-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 * Lucas Beeler <[email protected]>
18 * Charles Lindsay <[email protected]>
19 */
20
21 import QtQuick 2.9
22 import Gallery 1.0
23 import Lomiri.Components 1.3
24 import Lomiri.Components.Popups 1.3
25 import "../AlbumViewer"
26 import "../../js/Gallery.js" as Gallery
27
28 /*!
29 Show a popover with all exisitng albums. With the option to click on one of them.
30 */
31 Popover {
32 id: popupAlbumPicker
33 objectName: "popupAlbumPicker"
34
35 /// Emitted when an album is clicked
36 signal albumPicked(variant album)
37 /// Emitted when a new album was created to add the photo(s) to
38 signal newAlbumPicked(variant album)
39
40 /// height of the content
41 property int contentHeight: -1
42 contentWidth: units.gu(34)
43
44 visible: false
45
46 Component {
47 id: component_Item
48 Item {
49 clip: true
50
51 Flickable {
52 anchors.top: titleBox.bottom
53 anchors.topMargin: units.gu(1)
54 anchors.bottom: parent.bottom
55 anchors.bottomMargin: units.gu(0.25)
56 anchors.horizontalCenter: parent.horizontalCenter
57 width: albumGrid.width
58
59 contentHeight: albumGrid.height
60
61 Grid {
62 id: albumGrid
63
64 property int albumPreviewWidth: units.gu(14);
65 property int albumPreviewHeight: units.gu(16.5);
66 property int gutterWidth: units.gu(2)
67 property int gutterHeight: units.gu(4)
68 property int cellWidth: albumPreviewWidth + gutterWidth
69 property int cellHeight: albumPreviewHeight + gutterHeight
70 property AlbumCollectionModel albumCollectionModel: AlbumCollectionModel{}
71
72 columns: Math.floor((popupAlbumPicker.contentWidth - units.gu(2)) / cellWidth)
73 rows: Math.ceil((albumCollectionModel.count + 1) / columns)
74
75 Item {
76 width: albumGrid.cellWidth
77 height: albumGrid.cellHeight
78 LomiriShape {
79 width: albumGrid.albumPreviewWidth
80 height: albumGrid.albumPreviewHeight
81 anchors.centerIn: parent
82 color: "lightgray"
83
84 Label {
85 anchors.top: parent.top
86 anchors.topMargin: units.gu(3)
87 anchors.left: parent.left
88 anchors.leftMargin: units.gu(3)
89 anchors.right: parent.right
90 anchors.rightMargin: units.gu(3)
91 text: i18n.tr("Add new album")
92 fontSize: "medium"
93 horizontalAlignment: Text.AlignHCenter
94 wrapMode: Text.WordWrap
95 }
96
97 MouseArea {
98 anchors.fill: parent
99 onClicked: {
100 var album = albumGrid.albumCollectionModel.createOrphan();
101 album.title = i18n.tr("New Photo Album");
102 album.subtitle = i18n.tr("Subtitle");
103 album.newAlbum = false;
104 albumGrid.albumCollectionModel.addOrphan(album);
105
106 popupAlbumPicker.hide();
107 popupAlbumPicker.albumPicked(album);
108 popupAlbumPicker.newAlbumPicked(album);
109
110 albumEditor.album = album;
111 albumEditor.origin = null;
112 albumEditor.previewItem = null;
113 albumEditor.open();
114 }
115 }
116 }
117 }
118
119 Repeater {
120 model: albumGrid.albumCollectionModel
121
122 Item {
123 width: albumGrid.cellWidth
124 height: albumGrid.cellHeight
125
126 AlbumPreviewComponent {
127 width: albumGrid.albumPreviewWidth
128 height: albumGrid.albumPreviewHeight
129 anchors.centerIn: parent
130
131 album: model.album
132 showClosed: true
133
134 MouseArea {
135 anchors.fill: parent
136
137 onClicked: {
138 popupAlbumPicker.hide();
139 popupAlbumPicker.albumPicked(album);
140 }
141 }
142 }
143 }
144 }
145 }
146 }
147
148 Rectangle {
149 id: titleBox
150 anchors.left: parent.left
151 anchors.right: parent.right
152 anchors.top: parent.top
153 height: units.gu(3)
154 color: "#dddddd"
155
156 Label {
157 id: title
158 anchors.fill: parent
159 horizontalAlignment: Text.AlignHCenter
160 verticalAlignment: Text.AlignVCenter
161 color: "black"
162 text: i18n.tr("Add Photo to Album")
163 }
164 }
165 }
166 }
167 Loader {
168 id: loader_Item
169
170 width: parent.width
171 height: contentHeight
172 asynchronous: true
173
174 sourceComponent: popupAlbumPicker.visible ? component_Item : undefined
175 }
176 }