1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
|
/*
* Copyright 2014 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.12
import Lomiri.Components 1.3
import Lomiri.Components.Popups 1.3
import Lomiri.Thumbnailer 0.1
import Lomiri.Content 1.3
import Qt.labs.settings 1.0
import CameraApp 0.1
import "MimeTypeMapper.js" as MimeTypeMapper
FocusScope {
id: photogridView
property var model
signal photoClicked(int index)
signal photoPressAndHold(int index)
signal photoSelectionAreaClicked(int index)
signal exitUserSelectionMode
signal toggleHeader()
property real headerHeight
property bool inView
property bool inSelectionMode
property bool userSelectionMode: false
property var actions: userSelectionMode ? userSelectionActions : regularModeActions
property list<Action> userSelectionActions: [
Action {
text: i18n.tr("Share")
iconName: "share"
enabled: model.selectedFiles.length > 0
onTriggered: {
// Display a warning message if we are attempting to share mixed
// content, as the framework does not properly support this
if (selectionContainsMixedMedia()) {
PopupUtils.open(unableShareDialogComponent).parent = photogridView;
} else {
PopupUtils.open(sharePopoverComponent).parent = photogridView;
}
}
},
Action {
text: i18n.tr("Delete")
iconName: "delete"
onTriggered: {
if (model.selectedFiles.length > 0) {
var dialog = PopupUtils.open(deleteDialogComponent)
dialog.parent = photogridView
}
}
}
]
property list<Action> regularModeActions: [
Action {
text: i18n.tr("Settings")
objectName: "openSettingsPage"
iconName: "settings"
onTriggered: {
galleryPageStack.clear();
galleryPageStack.push(advancedOptionsComponent);
}
},
Action {
text: i18n.tr("About")
objectName: "openAboutPage"
iconName: "info"
onTriggered: {
galleryPageStack.clear();
galleryPageStack.push(infoPageComponent);
}
}
]
function selectionContainsMixedMedia() {
var selection = model.selectedFiles;
var lastType = model.get(selection[0], "fileType");
for (var i = 1; i < selection.length; i++) {
var type = model.get(selection[i], "fileType");
if (type !== lastType) {
return true;
}
lastType = type;
}
return false;
}
function showPhotoAtIndex(index) {
gridView.positionViewAtIndex(index, GridView.Center);
}
function exit() {
}
Settings {
id:galleryGridViewSettings
property var delegateWidth: gridView.baseDelegateWidth
property var delegateHeight: gridView.baseDelegateHeight
property real currentScale: 1
}
PinchArea {
id:galleryViewPinch
anchors.fill: parent
property real currentScale: galleryGridViewSettings.currentScale
pinch.dragAxis: Pinch.NoDrag
pinch.minimumScale: 0.5
pinch.maximumScale: 1.5
//FIXME This is a a workaround that remember the scale between pinches
pinch.target: Item {
width: galleryGridViewSettings.delegateWidth
height: galleryGridViewSettings.delegateHeight
scale:galleryGridViewSettings.currentScale
visible:false
}
onPinchUpdated: {
if( pinch.scale ) {
galleryGridViewSettings.currentScale = Math.min(2,Math.max(0.33,galleryViewPinch.pinch.target.scale)) ;
galleryGridViewSettings.delegateHeight = Math.floor(gridView.baseDelegateHeight * currentScale);
galleryGridViewSettings.delegateWidth = Math.floor(gridView.baseDelegateWidth * currentScale);
}
}
ResponsiveGridView {
id: gridView
anchors.fill: parent
// FIXME: prevent the header from overlapping the beginning of the grid
// when Qt 5.3 is landed, use property 'displayMarginBeginning' instead
// cf. http://qt-project.org/doc/qt-5/qml-qtquick-gridview.html#displayMarginBeginning-prop
header: Item {
width: gridView.width
height: headerHeight
}
property var baseDelegateWidth: Math.min(photogridView.width,photogridView.height)/2/2
property var baseDelegateHeight: baseDelegateWidth
Component.onCompleted: {
// FIXME: workaround for qtubuntu not returning values depending on the grid unit definition
// for Flickable.maximumFlickVelocity and Flickable.flickDeceleration
var scaleFactor = units.gridUnit / 8;
maximumFlickVelocity = maximumFlickVelocity * scaleFactor;
flickDeceleration = flickDeceleration * scaleFactor;
}
minimumHorizontalSpacing: units.dp(2)
maximumNumberOfColumns: 100
delegateWidth: galleryGridViewSettings.delegateWidth
delegateHeight: galleryGridViewSettings.delegateHeight
StateSaver.properties:"delegateWidth,delegateHeight"
model: photogridView.model
delegate: Item {
z:10
id: cellDelegate
objectName: "mediaItem" + index
width: gridView.cellWidth
height: gridView.cellHeight
Behavior on height { LomiriNumberAnimation {} }
Behavior on width { LomiriNumberAnimation {} }
property bool isVideo: MimeTypeMapper.mimeTypeToContentType(fileType) === ContentType.Videos
Image {
id: thumbnail
property real margin: units.dp(2)
anchors {
top: parent.top
topMargin: index < photogridView.columns ? 0 : margin/2
bottom: parent.bottom
bottomMargin: margin/2
left: parent.left
leftMargin: index % photogridView.columns == 0 ? 0 : margin/2
right: parent.right
rightMargin: index % photogridView.columns == photogridView.columns - 1 ? 0 : margin/2
}
asynchronous: true
cache: photogridView.inView
// The thumbnailer does not seem to check when an image has been changed on disk,
// so we use this hack to force it to check and refresh if necessary.
source: photogridView.inView ? "image://thumbnailer/" + fileURL.toString() + "?at=" + Date.now() : ""
sourceSize {
width: gridView.baseDelegateWidth
height: gridView.baseDelegateHeight
}
fillMode: Image.PreserveAspectCrop
opacity: status == Image.Ready ? 1.0 : 0.0
Behavior on opacity { LomiriNumberAnimation {duration: LomiriAnimation.FastDuration} }
}
Icon {
width: units.gu(3)
height: units.gu(3)
anchors.centerIn: parent
name: "media-playback-start"
color: "white"
opacity: 0.8
visible: isVideo
asynchronous: true
}
Icon {
objectName: "thumbnailLoadingErrorIcon"
anchors.centerIn: parent
width: units.gu(6)
height: width
name: cellDelegate.isVideo ? "stock_video" : "stock_image"
color: "white"
opacity: thumbnail.status == Image.Error ? 1.0 : 0.0
asynchronous: true
}
MouseArea {
anchors.fill: parent
onClicked: photogridView.photoClicked(index)
onPressAndHold: photogridView.photoPressAndHold(index)
}
Rectangle {
anchors {
top: parent.top
right: parent.right
topMargin: units.gu(0.5)
rightMargin: units.gu(0.5)
}
width: units.gu(4)
height: units.gu(4)
color: selected ? theme.palette.normal.positive : LomiriColors.inkstone
radius: 10
opacity: selected ? 0.8 : 0.6
visible: inSelectionMode
Icon {
objectName: "mediaItemCheckBox"
anchors.centerIn: parent
width: parent.width * 0.8
height: parent.height * 0.8
name: "ok"
color: "white"
visible: selected
asynchronous: true
}
}
MouseArea {
anchors {
top: parent.top
right: parent.right
}
width: parent.width * 0.5
height: parent.height * 0.5
enabled: inSelectionMode
onClicked: {
mouse.accepted = true;
photogridView.photoSelectionAreaClicked(index)
}
}
}
}
}
Component {
id: contentItemComp
ContentItem {}
}
Component {
id: sharePopoverComponent
SharePopover {
id: sharePopover
onContentPeerSelected: photogridView.exitUserSelectionMode();
onVisibleChanged: photogridView.toggleHeader()
transferContentType: MimeTypeMapper.mimeTypeToContentType(model.get(model.selectedFiles[0], "fileType"));
transferItems: model.selectedFiles.map(function(row) {
return contentItemComp.createObject(parent, {"url": model.get(row, "filePath")});
})
}
}
Component {
id: deleteDialogComponent
DeleteDialog {
id: deleteDialog
FileOperations {
id: fileOperations
}
onDeleteFiles: {
model.deleteSelectedFiles();
photogridView.exitUserSelectionMode();
}
onVisibleChanged: photogridView.toggleHeader()
}
}
Component {
id: unableShareDialogComponent
UnableShareDialog {
objectName: "unableShareDialog"
onVisibleChanged: photogridView.toggleHeader()
}
}
}
|