| 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 |
* Charles Lindsay <[email protected]> |
| 18 |
* Eric Gregory <[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 "../../js/GalleryUtility.js" as GalleryUtility |
| 26 |
import "../../js/GraphicsRoutines.js" as GraphicsRoutines |
| 27 |
import "../AlbumViewer" |
| 28 |
import "../Components" |
| 29 |
|
| 30 |
/*! |
| 31 |
*/ |
| 32 |
Page { |
| 33 |
id: albumEditor |
| 34 |
objectName: "mainAlbumEditor" |
| 35 |
|
| 36 |
title: i18n.tr("Edit album") |
| 37 |
head.backAction: Action { |
| 38 |
objectName: "cancelButton" |
| 39 |
text: i18n.tr("Cancel") |
| 40 |
iconName: "back" |
| 41 |
onTriggered: { |
| 42 |
if(album.newAlbum) |
| 43 |
albumModel.destroyAlbum(album); |
| 44 |
albumEditor.closeRequested(albumEditor.album, false); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
/*! |
| 49 |
*/ |
| 50 |
signal closeRequested(variant album, bool enterViewer) |
| 51 |
/*! |
| 52 |
*/ |
| 53 |
signal mediaSelectorHidden(int newScrollPos) |
| 54 |
|
| 55 |
/*! |
| 56 |
*/ |
| 57 |
property Album album |
| 58 |
/*! |
| 59 |
*/ |
| 60 |
property real minimumCoverWidth: units.gu(32) |
| 61 |
/*! |
| 62 |
*/ |
| 63 |
property real minimumCoverHeight: units.gu(38) |
| 64 |
/*! |
| 65 |
*/ |
| 66 |
property real preferredCoverWidth: width - units.gu(8) |
| 67 |
/*! |
| 68 |
*/ |
| 69 |
property real preferredCoverHeight: height - units.gu(8) |
| 70 |
/*! |
| 71 |
*/ |
| 72 |
property real minimumTopMargin: units.gu(3) |
| 73 |
|
| 74 |
// readonly |
| 75 |
/*! |
| 76 |
*/ |
| 77 |
property variant editorRect |
| 78 |
/*! |
| 79 |
*/ |
| 80 |
property bool animationRunning: overview.currentPage.animationRunning ? overview.currentPage.animationRunning : false |
| 81 |
|
| 82 |
// internal |
| 83 |
/*! |
| 84 |
*/ |
| 85 |
property real canonicalWidth: units.gu(66) |
| 86 |
/*! |
| 87 |
*/ |
| 88 |
property real canonicalHeight: units.gu(80) |
| 89 |
|
| 90 |
property bool showAlbumCover: true |
| 91 |
|
| 92 |
/*! |
| 93 |
*/ |
| 94 |
function setMediaSelectorScrollPos(newScrollPos) { |
| 95 |
mediaSelectorComponent.setCheckerboardScrollPos(newScrollPos); |
| 96 |
} |
| 97 |
|
| 98 |
// internal |
| 99 |
/*! |
| 100 |
*/ |
| 101 |
function closeAlbum() { |
| 102 |
if (album.populatedContentPageCount > 0) { |
| 103 |
albumModel.addOrphan(album); |
| 104 |
|
| 105 |
// Don't want to stay on the cover. |
| 106 |
if (album.currentPage == album.firstValidCurrentPage) |
| 107 |
album.currentPage = album.firstContentPage; |
| 108 |
} else { |
| 109 |
albumModel.destroyOrphan(album); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
// internal |
| 114 |
/*! |
| 115 |
*/ |
| 116 |
function resetEditorRect() { |
| 117 |
editorRect = GalleryUtility.getRectRelativeTo(cover.internalRect, albumEditor); |
| 118 |
} |
| 119 |
|
| 120 |
onAlbumChanged: resetEditorRect() // HACK: works, but not conceptually correct. |
| 121 |
onWidthChanged: resetEditorRect() |
| 122 |
onHeightChanged: resetEditorRect() |
| 123 |
|
| 124 |
property AlbumCollectionModel model: AlbumCollectionModel { |
| 125 |
id: albumModel |
| 126 |
} |
| 127 |
|
| 128 |
MouseArea { |
| 129 |
id: coverCloser |
| 130 |
|
| 131 |
acceptedButtons: Qt.LeftButton | Qt.RightButton |
| 132 |
anchors.fill: parent |
| 133 |
onPressed: { |
| 134 |
if (coverMenu) { |
| 135 |
coverMenu.hide(); |
| 136 |
} |
| 137 |
cover.editingDone(); |
| 138 |
if(album.newAlbum) |
| 139 |
albumModel.destroyAlbum(album); |
| 140 |
albumEditor.closeRequested(albumEditor.album, false); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
AspectArea { |
| 145 |
id: coverArea |
| 146 |
|
| 147 |
x: (parent.width - width) / 2 |
| 148 |
y: Math.max((parent.height - height) / 2, minimumTopMargin) |
| 149 |
|
| 150 |
width: GraphicsRoutines.clamp( |
| 151 |
preferredCoverWidth, minimumCoverWidth, canonicalWidth) |
| 152 |
height: GraphicsRoutines.clamp( |
| 153 |
preferredCoverHeight, minimumCoverHeight, canonicalHeight) |
| 154 |
|
| 155 |
aspectWidth: canonicalWidth |
| 156 |
aspectHeight: canonicalHeight |
| 157 |
|
| 158 |
content: AlbumCover { |
| 159 |
id: cover |
| 160 |
|
| 161 |
anchors.fill: parent |
| 162 |
|
| 163 |
album: albumEditor.album |
| 164 |
isPreview: false |
| 165 |
visible: showAlbumCover |
| 166 |
|
| 167 |
onPressed: { |
| 168 |
mouse.accepted = true; |
| 169 |
if (!isTextEditing) { |
| 170 |
coverMenu = PopupUtils.open(Qt.resolvedUrl("AlbumCoverMenu.qml"), null); |
| 171 |
coverMenu.newCoverSelected.connect(function(coverName) { |
| 172 |
albumEditor.album.coverNickname = coverName; |
| 173 |
}); |
| 174 |
} else { |
| 175 |
cover.editingDone() |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
onIsTextEditingChanged: { |
| 180 |
// Hide menu when we start editing text. |
| 181 |
if (isTextEditing && coverMenu.visible) { |
| 182 |
PopupUtils.close(coverMenu); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
onAddPhotos: { |
| 187 |
if (isTextEditing) |
| 188 |
cover.editingDone(); |
| 189 |
overview.pushPage(mediaSelectorComponent); |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
property AlbumCoverMenu coverMenu: null |
| 195 |
|
| 196 |
Component { |
| 197 |
id: mediaSelectorComponent |
| 198 |
|
| 199 |
MediaSelector { |
| 200 |
id: mediaSelector |
| 201 |
|
| 202 |
onAddClicked: { |
| 203 |
var album = albumEditor.album; |
| 204 |
var firstPhoto = album.addSelectedMediaSources(selection.model.selectedMedias); |
| 205 |
if(album.newAlbum && selection.model.selectedCount > 0) |
| 206 |
album.newAlbum = false; |
| 207 |
} |
| 208 |
|
| 209 |
onHidden: { |
| 210 |
if(album.newAlbum) |
| 211 |
albumModel.destroyAlbum(album); |
| 212 |
else |
| 213 |
albumCollectionModel.addOrphan(album); |
| 214 |
|
| 215 |
overview.popPage(); |
| 216 |
albumEditor.closeRequested(albumEditor.album, true); |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
} |