| 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 |
import "../Utility" |
| 23 |
import "../../js/GalleryUtility.js" as GalleryUtility |
| 24 |
|
| 25 |
// An "organic" vertically-scrollable view of media in a particular album. |
| 26 |
// This view doesn't have "trays" that scroll horizontally. |
| 27 |
OrganicView { |
| 28 |
id: organicAlbumView |
| 29 |
|
| 30 |
/*! |
| 31 |
*/ |
| 32 |
property var album |
| 33 |
/*! |
| 34 |
*/ |
| 35 |
property var albumModel: MediaCollectionModel { |
| 36 |
forCollection: album |
| 37 |
} |
| 38 |
|
| 39 |
// internal |
| 40 |
/*! |
| 41 |
*/ |
| 42 |
property int patternsPerRow: Math.max(1, Math.floor( |
| 43 |
(width - organicMediaListMargin) / organicMediaListPatternWidth)) |
| 44 |
/*! |
| 45 |
*/ |
| 46 |
property int photosPerRow: organicMediaListMediaPerPattern * patternsPerRow |
| 47 |
/*! |
| 48 |
*/ |
| 49 |
property real photosWidth: organicMediaListPatternWidth * patternsPerRow + |
| 50 |
organicMediaListMargin |
| 51 |
|
| 52 |
selection: SelectionState { |
| 53 |
model: albumModel |
| 54 |
} |
| 55 |
|
| 56 |
Component.onCompleted: chunkingModel.reset() |
| 57 |
onAlbumChanged: chunkingModel.reset() |
| 58 |
onPhotosPerRowChanged: chunkingModel.reset() |
| 59 |
Connections { |
| 60 |
target: album |
| 61 |
ignoreUnknownSignals: true |
| 62 |
onContentPagesChanged: chunkingModel.reset() |
| 63 |
} |
| 64 |
|
| 65 |
model: ListModel { |
| 66 |
id: chunkingModel |
| 67 |
|
| 68 |
function reset() { |
| 69 |
clear(); |
| 70 |
|
| 71 |
if (!album) |
| 72 |
return; |
| 73 |
|
| 74 |
var rows = Math.ceil(album.containedCount / photosPerRow); |
| 75 |
for (var i = 0; i < rows; ++i) |
| 76 |
append({"head": i * photosPerRow, "limit": photosPerRow}); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
delegate: OrganicMediaList { |
| 81 |
id: photosList |
| 82 |
|
| 83 |
anchors.left: parent.left |
| 84 |
anchors.leftMargin: (parent.width - photosWidth) / 2 |
| 85 |
|
| 86 |
selection: organicAlbumView.selection |
| 87 |
|
| 88 |
mediaModel: MediaCollectionModel { |
| 89 |
forCollection: album |
| 90 |
head: model.head |
| 91 |
limit: model.limit |
| 92 |
} |
| 93 |
|
| 94 |
onPressed: { |
| 95 |
var rect = GalleryUtility.translateRect(thumbnailRect, photosList, |
| 96 |
organicAlbumView); |
| 97 |
organicAlbumView.mediaSourcePressed(mediaSource, rect); |
| 98 |
} |
| 99 |
} |
| 100 |
} |