| 1 |
/* |
| 2 |
* Copyright (C) 2011-2015 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 version 3 as |
| 7 |
* published by the Free Software Foundation. |
| 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 |
* Authors: |
| 18 |
* Jim Nelson <[email protected]> |
| 19 |
*/ |
| 20 |
|
| 21 |
import QtQuick 2.9 |
| 22 |
import Lomiri.Components 1.3 |
| 23 |
import Gallery 1.0 |
| 24 |
import "../../Components" |
| 25 |
import "../../../js/Gallery.js" as Gallery |
| 26 |
|
| 27 |
/*! |
| 28 |
Item to show a photo. It first loads very fast a preview of the photo. Afterwards a bigger version |
| 29 |
is loaded (max. size of the screen). This way a blank screen is avoided. |
| 30 |
If the isPreview property is true, only the preview is loaded. |
| 31 |
All image loading is done asynchronous. |
| 32 |
*/ |
| 33 |
Item { |
| 34 |
id: root |
| 35 |
|
| 36 |
/// Link to the media to be shown |
| 37 |
property variant mediaSource |
| 38 |
/// Limit the view to show the preview version only, if set to true |
| 39 |
property bool isPreview: false |
| 40 |
/// As long as this load property is false, the loading of the images is not triggered |
| 41 |
property bool load: false |
| 42 |
/// True if the photo is visible, either as preview, or as full version |
| 43 |
property bool isLoaded: preview.status === Image.Ready || fullImage.status === Image.Ready |
| 44 |
|
| 45 |
Image { |
| 46 |
id: preview |
| 47 |
anchors.fill: parent |
| 48 |
asynchronous: true |
| 49 |
visible: fullImage.opacity < 1 |
| 50 |
source: load && mediaSource ? "image://thumbnailer/" + mediaSource.path + "?at=" + mediaSource.lastModified : "" |
| 51 |
fillMode: fullImage.fillMode |
| 52 |
sourceSize.width: 256 |
| 53 |
} |
| 54 |
Image { |
| 55 |
id: fullImage |
| 56 |
anchors.fill: parent |
| 57 |
asynchronous: true |
| 58 |
cache: false |
| 59 |
fillMode: Image.PreserveAspectCrop |
| 60 |
source: (preview.status === Image.Ready && !isPreview) ? |
| 61 |
"image://thumbnailer/" + mediaSource.path + "?at=" + mediaSource.lastModified : "" |
| 62 |
|
| 63 |
property int maxSize: Math.max(width, height) |
| 64 |
sourceSize.width: maxSize |
| 65 |
sourceSize.height: maxSize |
| 66 |
|
| 67 |
opacity: status === Image.Ready ? 1 : 0 |
| 68 |
Behavior on opacity { |
| 69 |
NumberAnimation { duration: Gallery.SNAP_DURATION } |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
Rectangle { |
| 74 |
anchors.fill: parent |
| 75 |
color: "black" |
| 76 |
visible: preview.status == Image.Error |
| 77 |
|
| 78 |
Icon { |
| 79 |
anchors.centerIn: parent |
| 80 |
width: isPreview ? units.gu(4) : units.gu(6) |
| 81 |
height: width |
| 82 |
name: "stock_image" |
| 83 |
color: "white" |
| 84 |
opacity: 0.8 |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
// Display a play icon if the thumbnail is from a video |
| 89 |
PlayIcon { |
| 90 |
anchors.centerIn: parent |
| 91 |
width: units.gu(5.5) |
| 92 |
height: width |
| 93 |
visible: isLoaded && mediaSource.type === MediaSource.Video |
| 94 |
} |
| 95 |
} |