| 1 |
/* |
| 2 |
* Copyright 2014 Canonical Ltd. |
| 3 |
* Copyright (C) 2025 UBports Foundation |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; version 3. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
import QtQuick 2.12 |
| 19 |
import Lomiri.Components 1.3 |
| 20 |
import Lomiri.Components.ListItems 1.3 as ListItems |
| 21 |
import Lomiri.Components.Popups 1.3 |
| 22 |
import Lomiri.Content 1.3 |
| 23 |
import Lomiri.Thumbnailer 0.1 |
| 24 |
import QtGraphicalEffects 1.0 |
| 25 |
|
| 26 |
import CameraApp 0.1 |
| 27 |
import "MimeTypeMapper.js" as MimeTypeMapper |
| 28 |
|
| 29 |
FocusScope { |
| 30 |
id: slideshowView |
| 31 |
|
| 32 |
property var model |
| 33 |
property int currentIndex: listView.currentIndex |
| 34 |
property bool touchAcquired: listView.currentItem ? listView.currentItem.pinchInProgress || |
| 35 |
editor.active || photoBottomEdge.dragProgress != 0 : false |
| 36 |
property bool inView |
| 37 |
property bool editingAvailable: false |
| 38 |
property bool inSelectionMode: false |
| 39 |
signal toggleHeader |
| 40 |
signal toggleSelection |
| 41 |
signal bottomEdgeCommit |
| 42 |
property var actions: inSelectionMode ? slideShowSelectionActions : slideShowActions |
| 43 |
|
| 44 |
property list<Action> slideShowSelectionActions: [ |
| 45 |
Action { |
| 46 |
text: i18n.tr("Select") |
| 47 |
iconName: listView.currentItem && listView.currentItem.isSelected ? "close" : "ok" |
| 48 |
onTriggered: slideshowView.toggleSelection() |
| 49 |
} |
| 50 |
] |
| 51 |
|
| 52 |
property list<Action> slideShowActions: [ |
| 53 |
Action { |
| 54 |
text: i18n.tr("Share") |
| 55 |
iconName: "share" |
| 56 |
onTriggered: { |
| 57 |
var dialog = PopupUtils.open(sharePopoverComponent) |
| 58 |
dialog.parent = slideshowView |
| 59 |
} |
| 60 |
}, |
| 61 |
Action { |
| 62 |
text: i18n.tr("Image Info") |
| 63 |
iconName: "info" |
| 64 |
onTriggered: { |
| 65 |
infoPopover.show() |
| 66 |
} |
| 67 |
}, |
| 68 |
Action { |
| 69 |
text: i18n.tr("Delete") |
| 70 |
iconName: "delete" |
| 71 |
onTriggered: { |
| 72 |
var dialog = PopupUtils.open(deleteDialogComponent) |
| 73 |
dialog.parent = slideshowView |
| 74 |
} |
| 75 |
}, |
| 76 |
Action { |
| 77 |
text: i18n.tr("Settings") |
| 78 |
objectName: "openSettingsPage" |
| 79 |
iconName: "settings" |
| 80 |
onTriggered: { |
| 81 |
galleryPageStack.clear(); |
| 82 |
galleryPageStack.push(advancedOptionsComponent) |
| 83 |
} |
| 84 |
}, |
| 85 |
Action { |
| 86 |
text: i18n.tr("About") |
| 87 |
objectName: "openAboutPage" |
| 88 |
iconName: "info" |
| 89 |
onTriggered: { |
| 90 |
galleryPageStack.clear(); |
| 91 |
galleryPageStack.push(infoPageComponent); |
| 92 |
} |
| 93 |
} |
| 94 |
] |
| 95 |
|
| 96 |
Action { |
| 97 |
id: editAction |
| 98 |
text: i18n.tr("Edit") |
| 99 |
iconName: "edit" |
| 100 |
onTriggered: editor.start(listView.currentItem.url) |
| 101 |
enabled: listView.currentItem && !listView.currentItem.isVideo |
| 102 |
} |
| 103 |
|
| 104 |
Component.onCompleted: { |
| 105 |
// The PhotoEditor is only available in Lomiri.Components.Extras 0.2 |
| 106 |
// If we succeed here we add the edit button to the list of actions. |
| 107 |
try { Qt.createQmlObject('import QtQuick 2.12; import Lomiri.Components.Extras 0.2; Item {}', slideshowView) } |
| 108 |
catch (e) { return; } |
| 109 |
|
| 110 |
editingAvailable = true; |
| 111 |
var newActions = []; |
| 112 |
for (var i = 0; i < slideShowActions.length; i++) newActions.push(slideShowActions[i]); |
| 113 |
newActions.unshift(editAction); |
| 114 |
slideShowActions = newActions; |
| 115 |
} |
| 116 |
|
| 117 |
function showPhotoAtIndex(index) { |
| 118 |
listView.positionViewAtIndex(index, ListView.Contain); |
| 119 |
} |
| 120 |
|
| 121 |
function showLastPhotoTaken() { |
| 122 |
listView.currentIndex = 0; |
| 123 |
} |
| 124 |
|
| 125 |
function exit() { |
| 126 |
if (listView.currentItem) { |
| 127 |
listView.currentItem.zoomOut(); |
| 128 |
} |
| 129 |
showPhotoAtIndex(0); |
| 130 |
} |
| 131 |
|
| 132 |
ListView { |
| 133 |
id: listView |
| 134 |
Component.onCompleted: { |
| 135 |
// FIXME: workaround for qtubuntu not returning values depending on the grid unit definition |
| 136 |
// for Flickable.maximumFlickVelocity and Flickable.flickDeceleration |
| 137 |
var scaleFactor = units.gridUnit / 8; |
| 138 |
maximumFlickVelocity = maximumFlickVelocity * scaleFactor; |
| 139 |
flickDeceleration = flickDeceleration * scaleFactor; |
| 140 |
} |
| 141 |
|
| 142 |
anchors.fill: parent |
| 143 |
model: slideshowView.model |
| 144 |
focus: true |
| 145 |
orientation: ListView.Horizontal |
| 146 |
boundsBehavior: Flickable.StopAtBounds |
| 147 |
cacheBuffer: width |
| 148 |
highlightRangeMode: ListView.StrictlyEnforceRange |
| 149 |
highlightMoveDuration: LomiriAnimation.FastDuration |
| 150 |
snapMode: ListView.SnapOneItem |
| 151 |
onCountChanged: { |
| 152 |
// currentIndex is -1 by default and stays so until manually set to something else |
| 153 |
if (currentIndex == -1 && count != 0) { |
| 154 |
currentIndex = 0; |
| 155 |
} |
| 156 |
} |
| 157 |
spacing: units.gu(1) |
| 158 |
interactive: currentItem ? !currentItem.pinchInProgress : true |
| 159 |
property real maxDimension: Math.max(width, height) |
| 160 |
|
| 161 |
removeDisplaced: Transition { |
| 162 |
LomiriNumberAnimation { property: "x" } |
| 163 |
} |
| 164 |
remove: Transition { |
| 165 |
ParallelAnimation { |
| 166 |
LomiriNumberAnimation { property: "opacity"; to: 0 } |
| 167 |
} |
| 168 |
} |
| 169 |
delegate: Item { |
| 170 |
id: delegate |
| 171 |
objectName: "mediaItem" + index |
| 172 |
property bool pinchInProgress: zoomPinchArea.active |
| 173 |
property string url: fileURL |
| 174 |
property bool isSelected: selected |
| 175 |
property alias isVideo: media.isVideo |
| 176 |
|
| 177 |
function zoomIn(centerX, centerY, factor) { |
| 178 |
flickable.scaleCenterX = centerX / (flickable.sizeScale * flickable.width); |
| 179 |
flickable.scaleCenterY = centerY / (flickable.sizeScale * flickable.height); |
| 180 |
flickable.sizeScale = factor; |
| 181 |
} |
| 182 |
|
| 183 |
function zoomOut() { |
| 184 |
if (flickable.sizeScale != 1.0) { |
| 185 |
flickable.scaleCenterX = flickable.contentX / flickable.width / (flickable.sizeScale - 1); |
| 186 |
flickable.scaleCenterY = flickable.contentY / flickable.height / (flickable.sizeScale - 1); |
| 187 |
flickable.sizeScale = 1.0; |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
function reload() { |
| 192 |
reloadImage(image); |
| 193 |
reloadImage(highResolutionImage); |
| 194 |
} |
| 195 |
|
| 196 |
function getMedia() { |
| 197 |
return isVideo ? null : media; |
| 198 |
} |
| 199 |
|
| 200 |
width: ListView.view.width |
| 201 |
height: ListView.view.height |
| 202 |
|
| 203 |
ActivityIndicator { |
| 204 |
anchors.centerIn: parent |
| 205 |
visible: running |
| 206 |
running: image.status == Image.Loading |
| 207 |
} |
| 208 |
|
| 209 |
PinchArea { |
| 210 |
id: zoomPinchArea |
| 211 |
anchors.fill: parent |
| 212 |
|
| 213 |
property real initialZoom |
| 214 |
property real maximumScale: 3.0 |
| 215 |
property real minimumZoom: 1.0 |
| 216 |
property real maximumZoom: 3.0 |
| 217 |
property bool active: false |
| 218 |
property var center |
| 219 |
enabled: !media.isVideo |
| 220 |
|
| 221 |
onPinchStarted: { |
| 222 |
active = true; |
| 223 |
initialZoom = flickable.sizeScale; |
| 224 |
center = zoomPinchArea.mapToItem(media, pinch.startCenter.x, pinch.startCenter.y); |
| 225 |
zoomIn(center.x, center.y, initialZoom); |
| 226 |
} |
| 227 |
onPinchUpdated: { |
| 228 |
var zoomFactor = MathUtils.clamp(initialZoom * pinch.scale, minimumZoom, maximumZoom); |
| 229 |
flickable.sizeScale = zoomFactor; |
| 230 |
} |
| 231 |
onPinchFinished: { |
| 232 |
active = false; |
| 233 |
} |
| 234 |
|
| 235 |
Flickable { |
| 236 |
id: flickable |
| 237 |
anchors.fill: parent |
| 238 |
contentWidth: media.width |
| 239 |
contentHeight: media.height |
| 240 |
contentX: (sizeScale - 1) * scaleCenterX * width |
| 241 |
contentY: (sizeScale - 1) * scaleCenterY * height |
| 242 |
interactive: !delegate.pinchInProgress |
| 243 |
|
| 244 |
property real sizeScale: 1.0 |
| 245 |
property real scaleCenterX: 0.0 |
| 246 |
property real scaleCenterY: 0.0 |
| 247 |
Behavior on sizeScale { |
| 248 |
enabled: !delegate.pinchInProgress |
| 249 |
LomiriNumberAnimation {duration: LomiriAnimation.FastDuration} |
| 250 |
} |
| 251 |
Behavior on scaleCenterX { |
| 252 |
LomiriNumberAnimation {duration: LomiriAnimation.FastDuration} |
| 253 |
} |
| 254 |
Behavior on scaleCenterY { |
| 255 |
LomiriNumberAnimation {duration: LomiriAnimation.FastDuration} |
| 256 |
} |
| 257 |
|
| 258 |
Item { |
| 259 |
id: media |
| 260 |
scale:1 - (photoBottomEdge.dragProgress*0.05) |
| 261 |
width: flickable.width * flickable.sizeScale |
| 262 |
height: flickable.height * flickable.sizeScale |
| 263 |
|
| 264 |
property bool isVideo: MimeTypeMapper.mimeTypeToContentType(fileType) === ContentType.Videos |
| 265 |
property string photoUrl: editingAvailable ? "image://photo/%1".arg(fileURL.toString()) : fileURL.toString() |
| 266 |
property string url: fileURL.toString().replace("file://", ""); |
| 267 |
Image { |
| 268 |
id: image |
| 269 |
anchors.fill: parent |
| 270 |
asynchronous: true |
| 271 |
cache: false |
| 272 |
source: slideshowView.inView ? (media.isVideo ? "image://thumbnailer/%1".arg(fileURL.toString()) |
| 273 |
: media.photoUrl) : "" |
| 274 |
sourceSize { |
| 275 |
width: listView.maxDimension |
| 276 |
height: listView.maxDimension |
| 277 |
} |
| 278 |
fillMode: Image.PreserveAspectFit |
| 279 |
opacity: status == Image.Ready ? 1.0 : 0.0 |
| 280 |
Behavior on opacity { LomiriNumberAnimation {duration: LomiriAnimation.FastDuration} } |
| 281 |
} |
| 282 |
|
| 283 |
Image { |
| 284 |
id: highResolutionImage |
| 285 |
anchors.fill: parent |
| 286 |
asynchronous: true |
| 287 |
cache: false |
| 288 |
source: slideshowView.inView && (flickable.sizeScale > 1.0 ) ? |
| 289 |
media.photoUrl : |
| 290 |
"" |
| 291 |
sourceSize { |
| 292 |
width: listView.maxDimension * (zoomPinchArea.maximumZoom / 2) |
| 293 |
height: listView.maxDimension * (zoomPinchArea.maximumZoom / 2) |
| 294 |
} |
| 295 |
fillMode: Image.PreserveAspectFit |
| 296 |
} |
| 297 |
|
| 298 |
Icon { |
| 299 |
objectName: "thumbnailLoadingErrorIcon" |
| 300 |
anchors.centerIn: parent |
| 301 |
width: units.gu(30) |
| 302 |
height: width |
| 303 |
name: media.isVideo ? "stock_video" : "stock_image" |
| 304 |
color: "white" |
| 305 |
opacity: image.status == Image.Error ? 1.0 : 0.0 |
| 306 |
asynchronous: true |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
PlayIcon { |
| 311 |
anchors.centerIn: parent |
| 312 |
width: units.gu(7) |
| 313 |
height: width |
| 314 |
visible: media.isVideo |
| 315 |
} |
| 316 |
|
| 317 |
MouseArea { |
| 318 |
// Work around being parented under flickable.contentItem |
| 319 |
parent: flickable |
| 320 |
anchors.fill: parent |
| 321 |
onClicked: { |
| 322 |
// For videos, we check for a tap in the center |
| 323 |
// on the play button icon |
| 324 |
if (media.isVideo |
| 325 |
&& mouse.x > width / 2 - units.gu(5) |
| 326 |
&& mouse.x < width / 2 + units.gu(5) |
| 327 |
&& mouse.y > height / 2 - units.gu(5) |
| 328 |
&& mouse.y < height / 2 + units.gu(5)) { |
| 329 |
var url = fileURL.toString().replace("file://", "video://"); |
| 330 |
Qt.openUrlExternally(url); |
| 331 |
} else { |
| 332 |
slideshowView.toggleHeader(); |
| 333 |
mouse.accepted = false; |
| 334 |
} |
| 335 |
} |
| 336 |
onDoubleClicked: { |
| 337 |
if (listView.moving) { |
| 338 |
// FIXME: workaround for Qt bug specific to touch: |
| 339 |
// doubleClicked is received even though the MouseArea |
| 340 |
// was tapped only once but another MouseArea was also |
| 341 |
// tapped shortly before. |
| 342 |
// Ref.: https://bugreports.qt.io/browse/QTBUG-39332 |
| 343 |
return; |
| 344 |
} |
| 345 |
|
| 346 |
if (media.isVideo) { |
| 347 |
return; |
| 348 |
} |
| 349 |
|
| 350 |
if (flickable.sizeScale < zoomPinchArea.maximumZoom) { |
| 351 |
zoomIn(mouse.x, mouse.y, zoomPinchArea.maximumZoom); |
| 352 |
} else { |
| 353 |
zoomOut(); |
| 354 |
} |
| 355 |
} |
| 356 |
} |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
Component { |
| 363 |
id: sharePopoverComponent |
| 364 |
|
| 365 |
SharePopover { |
| 366 |
id: sharePopover |
| 367 |
|
| 368 |
ContentItem { |
| 369 |
id: contentItem |
| 370 |
} |
| 371 |
|
| 372 |
Component.onCompleted: { |
| 373 |
contentItem.url = slideshowView.model.get(slideshowView.currentIndex, "filePath"); |
| 374 |
transferItems = [contentItem]; |
| 375 |
} |
| 376 |
onVisibleChanged: toggleHeader() |
| 377 |
|
| 378 |
transferContentType: MimeTypeMapper.mimeTypeToContentType(slideshowView.model.get(slideshowView.currentIndex, "fileType")); |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
MediaInfoPopover { |
| 383 |
id: infoPopover |
| 384 |
contentWidth:slideshowView.width > units.gu(45) ? units.gu(40) : slideshowView.width*0.85 |
| 385 |
currentMedia: listView.currentItem ? listView.currentItem.getMedia() : undefined |
| 386 |
model:{ |
| 387 |
"fileName": slideshowView.model.get(slideshowView.currentIndex, "fileName"), |
| 388 |
"fileType": slideshowView.model.get(slideshowView.currentIndex, "fileType"), |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
Component { |
| 393 |
id: deleteDialogComponent |
| 394 |
|
| 395 |
DeleteDialog { |
| 396 |
id: deleteDialog |
| 397 |
|
| 398 |
FileOperations { |
| 399 |
id: fileOperations |
| 400 |
} |
| 401 |
|
| 402 |
onDeleteFiles: { |
| 403 |
// FIXME: workaround bug in ListView with snapMode: ListView.SnapOneItem |
| 404 |
// whereby after deleting the last item in the list the first |
| 405 |
// item would be shown even though the currentIndex was not set to 0 |
| 406 |
var toBeDeleted = listView.currentIndex; |
| 407 |
if (listView.currentIndex == listView.count - 1) { |
| 408 |
listView.currentIndex = listView.currentIndex - 1; |
| 409 |
} |
| 410 |
|
| 411 |
var currentFilePath = slideshowView.model.get(toBeDeleted, "filePath"); |
| 412 |
fileOperations.remove(currentFilePath); |
| 413 |
} |
| 414 |
onVisibleChanged: toggleHeader() |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
Binding { |
| 419 |
target: header |
| 420 |
property: "editMode" |
| 421 |
value: editor.active |
| 422 |
} |
| 423 |
|
| 424 |
Binding { |
| 425 |
target: header |
| 426 |
property: "editModeActions" |
| 427 |
value: editor.item ? editor.item.actions : 0; |
| 428 |
when: editor.active && editor.item |
| 429 |
} |
| 430 |
|
| 431 |
function reloadImage(image) { |
| 432 |
var async = image.asynchronous; |
| 433 |
var source = image.source; |
| 434 |
image.asynchronous = false; |
| 435 |
image.source = ""; |
| 436 |
image.asynchronous = async; |
| 437 |
image.source = source; |
| 438 |
} |
| 439 |
|
| 440 |
Loader { |
| 441 |
id: editor |
| 442 |
source: "PhotoEditorLoader.qml" |
| 443 |
active: false |
| 444 |
anchors.fill: parent |
| 445 |
|
| 446 |
function start(url) { |
| 447 |
editor.active = true; |
| 448 |
editor.item.start(url); |
| 449 |
} |
| 450 |
|
| 451 |
Connections { |
| 452 |
target: editor.item |
| 453 |
onClosed: { |
| 454 |
editor.active = false; |
| 455 |
if (photoWasModified) listView.currentItem.reload(); |
| 456 |
} |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
OverlayPanel { |
| 461 |
id:bottomimageBlur |
| 462 |
|
| 463 |
overlayItem: photoBottomEdge |
| 464 |
anchorTo: photoBottomEdge |
| 465 |
|
| 466 |
visible: photoBottomEdge.status !== BottomEdge.Hidden |
| 467 |
transform: Translate { |
| 468 |
id:beTransalte |
| 469 |
y: photoBottomEdge.height - (photoBottomEdge.height*photoBottomEdge.dragProgress) |
| 470 |
Behavior on y { LomiriNumberAnimation {duration:LomiriAnimation.FastDuration}} |
| 471 |
} |
| 472 |
|
| 473 |
blur.visible: appSettings.blurEffects && !appSettings.blurEffectsPreviewOnly |
| 474 |
blur.backgroundItem: listView |
| 475 |
blur.transparentBorder:false |
| 476 |
blur.offset: Qt.point(photoBottomEdge.x,beTransalte.y) |
| 477 |
} |
| 478 |
|
| 479 |
BottomEdge { |
| 480 |
id: photoBottomEdge |
| 481 |
enabled: !editor.active |
| 482 |
visible: enabled |
| 483 |
height:units.gu(8) |
| 484 |
hint.text: i18n.tr("Back to Photo roll"); |
| 485 |
hint.iconName: "go-up" |
| 486 |
hint.visible:enabled |
| 487 |
hint.opacity: 1.0 - photoBottomEdge.dragProgress |
| 488 |
|
| 489 |
contentComponent: Page { |
| 490 |
id:bottomReturn |
| 491 |
opacity: photoBottomEdge.dragProgress |
| 492 |
header: PageHeader { opacity: 0 } |
| 493 |
|
| 494 |
Icon { |
| 495 |
id:bottomEdgeGoUpIcon |
| 496 |
height:units.gu(3) |
| 497 |
width:units.gu(3) |
| 498 |
name:"go-up" |
| 499 |
color: theme.palette.normal.backgroundText |
| 500 |
anchors.top:parent.top |
| 501 |
anchors.horizontalCenter:parent.horizontalCenter |
| 502 |
} |
| 503 |
Label { |
| 504 |
anchors.horizontalCenter:parent.horizontalCenter |
| 505 |
verticalAlignment: Text.AlignVCenter |
| 506 |
height:photoBottomEdge.height |
| 507 |
text: photoBottomEdge.hint.text |
| 508 |
color: theme.palette.normal.backgroundText |
| 509 |
fontSize: "x-large" |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
onCommitCompleted: { bottomEdgeCommit(); photoBottomEdge.collapse(); } |
| 514 |
} |
| 515 |
} |