| 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 |
*/ |
| 19 |
|
| 20 |
import QtQuick 2.9 |
| 21 |
import Lomiri.Components 1.3 |
| 22 |
import "../Utility" |
| 23 |
|
| 24 |
// A PhotoViewer that is opened and closed with the PhotoViewerTransition. |
| 25 |
Page { |
| 26 |
id: popupPhotoViewer |
| 27 |
|
| 28 |
signal selected(int index) |
| 29 |
|
| 30 |
anchors.fill: parent |
| 31 |
property alias model: viewer.model |
| 32 |
|
| 33 |
property alias photo: viewer.media |
| 34 |
property alias index: viewer.index |
| 35 |
|
| 36 |
// Optional: set this when launching from an album view |
| 37 |
property alias album: viewer.album |
| 38 |
|
| 39 |
// Read-only |
| 40 |
property bool animationRunning: transition.animationRunning || |
| 41 |
fadeIn.running || fadeOut.running |
| 42 |
property bool isPoppedUp: popupPhotoViewer.visible && viewer.visible && !animationRunning |
| 43 |
|
| 44 |
property SelectionState selection: null |
| 45 |
|
| 46 |
title: i18n.tr("Gallery") |
| 47 |
|
| 48 |
function setCurrentPhoto(photo) { |
| 49 |
viewer.setCurrentPhoto(photo); |
| 50 |
} |
| 51 |
|
| 52 |
function setCurrentIndex(index) { |
| 53 |
viewer.setCurrentIndex(index); |
| 54 |
} |
| 55 |
|
| 56 |
signal opening() |
| 57 |
signal opened() // The photo viewer's opening animation is finished. |
| 58 |
signal closeRequested() // The user pressed the back button. Call animateClosed() or close(). |
| 59 |
signal closed() // The photo viewer's closing animation is finished. |
| 60 |
signal editRequested(variant photo) // The user wants to edit this photo. |
| 61 |
|
| 62 |
function animateOpen(photo, thumbnailRect) { |
| 63 |
opening(); |
| 64 |
viewer.openCompleted = false; |
| 65 |
transition.transitionToPhotoViewer(photo, thumbnailRect); |
| 66 |
} |
| 67 |
|
| 68 |
function animateClosed(thumbnailRect) { |
| 69 |
transition.transitionFromPhotoViewer(photo, thumbnailRect); |
| 70 |
viewer.visible = false; |
| 71 |
} |
| 72 |
|
| 73 |
function fadeOpen(photo) { |
| 74 |
opening(); |
| 75 |
viewer.setCurrentPhoto(photo); |
| 76 |
fadeIn.restart(); |
| 77 |
} |
| 78 |
|
| 79 |
function fadeClosed() { |
| 80 |
fadeOut.restart(); |
| 81 |
} |
| 82 |
|
| 83 |
function close() { |
| 84 |
viewer.visible = false; |
| 85 |
closed(); |
| 86 |
} |
| 87 |
|
| 88 |
function closePopupPhotoViewer() { |
| 89 |
viewer.closeMediaViewer(); |
| 90 |
} |
| 91 |
|
| 92 |
head.visible: false |
| 93 |
head.locked: true |
| 94 |
|
| 95 |
header: PageHeader { |
| 96 |
objectName: "photoViewerHeader" |
| 97 |
|
| 98 |
title: popupPhotoViewer.title |
| 99 |
trailingActionBar.actions: { |
| 100 |
if (selection && selection.inSelectionMode) |
| 101 |
return selectActions; |
| 102 |
return viewer.actions; |
| 103 |
} |
| 104 |
|
| 105 |
leadingActionBar.actions: viewer.backAction |
| 106 |
} |
| 107 |
|
| 108 |
MediaViewer { |
| 109 |
id: viewer |
| 110 |
|
| 111 |
property bool openCompleted: false |
| 112 |
|
| 113 |
anchors.fill: parent |
| 114 |
visible: false |
| 115 |
|
| 116 |
onCloseRequested: { |
| 117 |
popupPhotoViewer.closeRequested(); |
| 118 |
openCompleted = false; |
| 119 |
} |
| 120 |
|
| 121 |
onEditRequested: popupPhotoViewer.editRequested(media) |
| 122 |
|
| 123 |
onIsReadyChanged: updateVisibility() |
| 124 |
onOpenCompletedChanged: updateVisibility() |
| 125 |
|
| 126 |
onSetHeaderVisibilityRequested: popupPhotoViewer.header.visible = visibility |
| 127 |
onToggleHeaderVisibilityRequested: { |
| 128 |
popupPhotoViewer.header.visible = !popupPhotoViewer.header.visible |
| 129 |
if (!APP.desktopMode) |
| 130 |
setFullScreenAppMode(!popupPhotoViewer.header.visible); |
| 131 |
} |
| 132 |
|
| 133 |
// Internal |
| 134 |
function updateVisibility() { |
| 135 |
if (isReady && openCompleted) { |
| 136 |
visible = true; |
| 137 |
transition.hide(); |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
PhotoViewerTransition { |
| 143 |
id: transition |
| 144 |
|
| 145 |
anchors.fill: parent |
| 146 |
|
| 147 |
onTransitionToPhotoViewerCompleted: { |
| 148 |
setCurrentPhoto(forMediaSource); |
| 149 |
viewer.openCompleted = true; |
| 150 |
if (!APP.desktopMode) |
| 151 |
setFullScreenAppMode(true); |
| 152 |
overview.pushPage(popupPhotoViewer); |
| 153 |
if (selection && selection.inSelectionMode) |
| 154 |
popupPhotoViewer.header.visible = true; |
| 155 |
else |
| 156 |
popupPhotoViewer.header.visible = false; |
| 157 |
opened(); |
| 158 |
} |
| 159 |
|
| 160 |
onTransitionFromPhotoViewerCompleted: { |
| 161 |
closed(); |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
FadeInAnimation { |
| 166 |
id: fadeIn |
| 167 |
|
| 168 |
target: viewer |
| 169 |
onStopped: opened() |
| 170 |
} |
| 171 |
|
| 172 |
FadeOutAnimation { |
| 173 |
id: fadeOut |
| 174 |
|
| 175 |
target: viewer |
| 176 |
onStopped: { |
| 177 |
closed(); |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
property list<Action> selectActions: [ |
| 182 |
Action { |
| 183 |
text: i18n.tr("Toggle Selection") |
| 184 |
objectName: "toggleSelectionButton" |
| 185 |
iconName: selection.isSelected(photo) ? "close" : "ok" |
| 186 |
onTriggered: { |
| 187 |
selection.toggleSelection(photo); |
| 188 |
if (selection.isSelected(photo)) |
| 189 |
popupPhotoViewer.selected(popupPhotoViewer.index); |
| 190 |
} |
| 191 |
} |
| 192 |
] |
| 193 |
} |