| 1 |
/* |
| 2 |
* Copyright (C) 2012-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 QtQuick.Controls.Suru 2.2 |
| 22 |
import Gallery 1.0 |
| 23 |
import ".." |
| 24 |
|
| 25 |
// An item placing the pictures (or cover!) on the front or back of an |
| 26 |
// AlbumPageComponent, including an optional frame around the pictures to mimic |
| 27 |
// seeing the edge of the back of the cover under the page. |
| 28 |
Item { |
| 29 |
id: albumPageContents |
| 30 |
|
| 31 |
/*! |
| 32 |
*/ |
| 33 |
property Album album |
| 34 |
/*! |
| 35 |
*/ |
| 36 |
property int page: -1 |
| 37 |
/*! |
| 38 |
*/ |
| 39 |
property bool isPreview: false |
| 40 |
/*! |
| 41 |
*/ |
| 42 |
property bool load: false |
| 43 |
/*! |
| 44 |
*/ |
| 45 |
property bool contentHasPreviewFrame: false |
| 46 |
|
| 47 |
/*! |
| 48 |
*/ |
| 49 |
property real topMargin |
| 50 |
/*! |
| 51 |
*/ |
| 52 |
property real bottomMargin |
| 53 |
/*! |
| 54 |
*/ |
| 55 |
property real gutterMargin |
| 56 |
/*! |
| 57 |
*/ |
| 58 |
property real outerMargin |
| 59 |
/*! |
| 60 |
*/ |
| 61 |
property real insideMargin |
| 62 |
|
| 63 |
// See AlbumPageComponent for descriptions of these properties |
| 64 |
property bool freeze: false |
| 65 |
/*! |
| 66 |
*/ |
| 67 |
property bool showCover: true |
| 68 |
|
| 69 |
/*! |
| 70 |
*/ |
| 71 |
property real frameHingeInset: frame.startX * scaleFactorX |
| 72 |
|
| 73 |
// readonly |
| 74 |
/*! |
| 75 |
*/ |
| 76 |
property bool isCover: cover.visible |
| 77 |
// These constants (only useful when contentHasPreviewFrame is true) expose |
| 78 |
// the ratio of size between the whole framed page (displayed at the size of |
| 79 |
// this component) and the content of that page (displayed slightly smaller, |
| 80 |
// within the frame), for if you need to match the contents but not the |
| 81 |
// frame. |
| 82 |
property real frameToContentWidth: ((pixelWidth - 10) / frameContentWidth) |
| 83 |
/*! |
| 84 |
*/ |
| 85 |
property real frameToContentHeight: ((pixelHeight - 12) / frameContentHeight) |
| 86 |
|
| 87 |
// internal |
| 88 |
// This might be able to be simplified some, as the components have changed. |
| 89 |
// The original idea was to scale the page up and down, but now the only |
| 90 |
// thing that actually gets scaled is the frame image. |
| 91 |
property bool isRight: (page % 2 == 0) |
| 92 |
|
| 93 |
// Pixel width of preview frame |
| 94 |
property real pixelWidth: 235 |
| 95 |
/*! |
| 96 |
*/ |
| 97 |
property real pixelHeight: 281 |
| 98 |
|
| 99 |
// Difference between desktop gu size and pixel size. |
| 100 |
property real pixelWidthOffset: 11 |
| 101 |
/*! |
| 102 |
*/ |
| 103 |
property real pixelHeightOffset: 17 |
| 104 |
|
| 105 |
// Offset from frame.start* to the "page" inside the frame. |
| 106 |
property real frameInsetMarginX: isRight ? 0 : -9 |
| 107 |
/*! |
| 108 |
*/ |
| 109 |
property real frameInsetMarginY: 10 |
| 110 |
/*! |
| 111 |
*/ |
| 112 |
property real frameContentOffsetX: frame.startX + frameInsetMarginX |
| 113 |
/*! |
| 114 |
*/ |
| 115 |
property real frameContentOffsetY: frameInsetMarginY |
| 116 |
|
| 117 |
// GU/pixel scale factor of preview frame |
| 118 |
property real scaleFactorX: ((isPreview) ? width : (width - gutterMargin)) / (pixelWidth - pixelWidthOffset) |
| 119 |
/*! |
| 120 |
*/ |
| 121 |
property real scaleFactorY: ((isPreview) ? height : (height - topMargin * 2 - bottomMargin)) / (pixelHeight - pixelHeightOffset) |
| 122 |
|
| 123 |
// Frame dimensions |
| 124 |
property real frameContentWidth: frame.contentWidth |
| 125 |
/*! |
| 126 |
*/ |
| 127 |
property real frameContentHeight: frame.contentHeight |
| 128 |
|
| 129 |
/*! |
| 130 |
*/ |
| 131 |
property real contentPageX: (contentHasPreviewFrame |
| 132 |
? frameContentOffsetX * scaleFactorX |
| 133 |
: 0) |
| 134 |
/*! |
| 135 |
*/ |
| 136 |
property real contentPageY: (contentHasPreviewFrame |
| 137 |
? frameContentOffsetY * scaleFactorY |
| 138 |
: 0) |
| 139 |
/*! |
| 140 |
*/ |
| 141 |
property real contentPageWidth: (contentHasPreviewFrame |
| 142 |
? frameContentWidth * scaleFactorX |
| 143 |
: parent.width) |
| 144 |
/*! |
| 145 |
*/ |
| 146 |
property real contentPageHeight: (contentHasPreviewFrame |
| 147 |
? frameContentHeight * scaleFactorY |
| 148 |
: parent.height) |
| 149 |
|
| 150 |
/*! |
| 151 |
*/ |
| 152 |
property variant mediaFrames: (loader.item) ? loader.item.mediaFrames : undefined |
| 153 |
|
| 154 |
onAlbumChanged: loader.reload() |
| 155 |
onPageChanged: loader.reload() |
| 156 |
onFreezeChanged: { |
| 157 |
if (!freeze) |
| 158 |
loader.reload(); |
| 159 |
} |
| 160 |
|
| 161 |
Connections { |
| 162 |
target: album |
| 163 |
ignoreUnknownSignals: true |
| 164 |
onContentPagesChanged: loader.reload() |
| 165 |
} |
| 166 |
|
| 167 |
// Album preview page frame. |
| 168 |
Item { |
| 169 |
id: frame |
| 170 |
|
| 171 |
// Read-only |
| 172 |
// Start of content area |
| 173 |
property int startX: isRight ? frameLeft.width : 18 |
| 174 |
property int startY: 6 |
| 175 |
|
| 176 |
// Dimensions of content area |
| 177 |
property int contentWidth: frameContents.width - 10 |
| 178 |
property int contentHeight: frameContents.height - 27 |
| 179 |
|
| 180 |
width: pixelWidth |
| 181 |
height: pixelHeight |
| 182 |
|
| 183 |
transform: Scale { |
| 184 |
xScale: scaleFactorX |
| 185 |
yScale: scaleFactorY |
| 186 |
} |
| 187 |
|
| 188 |
LayoutMirroring.enabled: !isRight |
| 189 |
LayoutMirroring.childrenInherit: true |
| 190 |
|
| 191 |
visible: (loader.visible && contentHasPreviewFrame) |
| 192 |
|
| 193 |
Image { |
| 194 |
id: frameLeft |
| 195 |
|
| 196 |
source: "img/album-thumbnail-frame-left.png" |
| 197 |
|
| 198 |
width: 6 |
| 199 |
height: pixelHeight |
| 200 |
mirror: !isRight |
| 201 |
anchors.left: parent.left |
| 202 |
anchors.top: parent.top |
| 203 |
} |
| 204 |
|
| 205 |
Image { |
| 206 |
id: frameContents |
| 207 |
|
| 208 |
source: "img/album-thumbnail-frame-right.png" |
| 209 |
|
| 210 |
width: pixelWidth - frameLeft.width |
| 211 |
height: pixelHeight |
| 212 |
mirror: !isRight |
| 213 |
anchors.top: parent.top |
| 214 |
anchors.left: frameLeft.right |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
Item { |
| 219 |
id: paperBackground |
| 220 |
|
| 221 |
anchors.fill: parent |
| 222 |
|
| 223 |
visible: (loader.visible && !contentHasPreviewFrame && !isPreview) |
| 224 |
|
| 225 |
clip: true |
| 226 |
|
| 227 |
Rectangle { |
| 228 |
x: (isRight ? -parent.width : 0) |
| 229 |
y: 0 |
| 230 |
width: (isRight ? parent.width * 2 : parent.width) |
| 231 |
height: parent.height |
| 232 |
color: Suru.backgroundColor |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
Loader { |
| 237 |
id: loader |
| 238 |
|
| 239 |
// read-only |
| 240 |
property variant mediaSourceList |
| 241 |
property alias topMargin: albumPageContents.topMargin |
| 242 |
property alias bottomMargin: albumPageContents.bottomMargin |
| 243 |
property alias gutterMargin: albumPageContents.gutterMargin |
| 244 |
property alias outerMargin: albumPageContents.outerMargin |
| 245 |
property alias insideMargin: albumPageContents.insideMargin |
| 246 |
property alias isPreview: albumPageContents.isPreview |
| 247 |
property alias load: albumPageContents.load |
| 248 |
property bool isLoaded: false |
| 249 |
|
| 250 |
function reload() { |
| 251 |
if (freeze || !isLoaded) |
| 252 |
return; |
| 253 |
|
| 254 |
mediaSourceList = null; |
| 255 |
source = "AlbumPageLayoutLeftPortrait.qml"; |
| 256 |
|
| 257 |
if (!album) |
| 258 |
return; |
| 259 |
var albumPage = album.getPage(page); |
| 260 |
if (!albumPage) |
| 261 |
return; |
| 262 |
|
| 263 |
mediaSourceList = albumPage.mediaSourceList; |
| 264 |
source = albumPage.qmlRc; |
| 265 |
} |
| 266 |
|
| 267 |
x: contentPageX |
| 268 |
y: contentPageY |
| 269 |
width: contentPageWidth |
| 270 |
height: contentPageHeight |
| 271 |
|
| 272 |
visible: (source != null) |
| 273 |
|
| 274 |
Component.onCompleted: { |
| 275 |
isLoaded = true; |
| 276 |
reload(); |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
AlbumCover { |
| 281 |
id: cover |
| 282 |
|
| 283 |
width: pixelWidth |
| 284 |
height: pixelHeight |
| 285 |
y: albumPageContents.isPreview ? 0 : topMargin |
| 286 |
|
| 287 |
xScale: scaleFactorX |
| 288 |
yScale: scaleFactorY |
| 289 |
|
| 290 |
visible: showCover && !freeze && (Boolean(album) && (page == 0 || page == album.totalPageCount - 1)) |
| 291 |
|
| 292 |
album: albumPageContents.album |
| 293 |
isBack: !isRight |
| 294 |
|
| 295 |
// Always consider this as preview, so it matches the preview display when animating out |
| 296 |
// from the cover. |
| 297 |
isPreview: true |
| 298 |
} |
| 299 |
} |