| 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 |
* Jim Nelson <[email protected]> |
| 18 |
* Charles Lindsay <[email protected]> |
| 19 |
* Eric Gregory <[email protected]> |
| 20 |
*/ |
| 21 |
|
| 22 |
import QtQuick 2.9 |
| 23 |
import Gallery 1.0 |
| 24 |
import Lomiri.Components 1.3 |
| 25 |
import "../Components" |
| 26 |
|
| 27 |
/*! |
| 28 |
*/ |
| 29 |
Item { |
| 30 |
id: albumCover |
| 31 |
|
| 32 |
/*! |
| 33 |
*/ |
| 34 |
signal pressed(variant mouse) |
| 35 |
/*! |
| 36 |
*/ |
| 37 |
signal addPhotos() |
| 38 |
|
| 39 |
/*! |
| 40 |
*/ |
| 41 |
property Album album |
| 42 |
/*! |
| 43 |
*/ |
| 44 |
property bool isBack: false |
| 45 |
/*! |
| 46 |
*/ |
| 47 |
property bool isBlank: false |
| 48 |
/*! |
| 49 |
*/ |
| 50 |
property bool isPreview: true |
| 51 |
/*! |
| 52 |
*/ |
| 53 |
property real titleOpacity: 1 |
| 54 |
/*! |
| 55 |
*/ |
| 56 |
property int titleDateSpacing: units.gu(2) // (Preview-sized; will scale up)) |
| 57 |
|
| 58 |
/*! |
| 59 |
*/ |
| 60 |
property alias xScale: scale.xScale |
| 61 |
/*! |
| 62 |
*/ |
| 63 |
property alias yScale: scale.yScale |
| 64 |
|
| 65 |
// Read-only. |
| 66 |
// Represents the fully scaled border of the cover (without shadows.) |
| 67 |
// Numerical values are based on image pixels. |
| 68 |
property var internalRect: isPreview ? internalRectPreview : internalRectFull |
| 69 |
|
| 70 |
Item { |
| 71 |
id: internalRectPreview |
| 72 |
|
| 73 |
visible: false |
| 74 |
x : 9 * xScale |
| 75 |
y : 0 |
| 76 |
width: xScale * (coverImagePreviewLeft.width + coverImagePreviewRight.width - 9 - 12) |
| 77 |
height : yScale * (coverImagePreviewLeft.height - 13) |
| 78 |
} |
| 79 |
|
| 80 |
Item { |
| 81 |
id: internalRectFull |
| 82 |
|
| 83 |
visible: false |
| 84 |
x : 18 * xScale |
| 85 |
y : 0 |
| 86 |
width: xScale * (coverImageFull.width - 18 - 11) |
| 87 |
height : xScale * (coverImageFull.height - 14) |
| 88 |
} |
| 89 |
|
| 90 |
/*! |
| 91 |
*/ |
| 92 |
property real spacerScale: cover.height / units.gu(33) // ratio of image height to canonical height |
| 93 |
// Text margins. Specified as fractions of cover width for scaling (eyeballed) |
| 94 |
property real coverMarginLeft: width / 7 |
| 95 |
/*! |
| 96 |
*/ |
| 97 |
property real coverMarginRight: width / 26 |
| 98 |
/*! |
| 99 |
*/ |
| 100 |
property real coverStartY: height / 50 |
| 101 |
/*! |
| 102 |
*/ |
| 103 |
property variant coverElement: album !== null ? |
| 104 |
coverList.elementForCoverName(album.coverNickname) : coverList.getDefault(); |
| 105 |
|
| 106 |
readonly property alias isTextEditing: cover.isTextEditing |
| 107 |
|
| 108 |
// Stops editing title/subtitle. |
| 109 |
function editingDone() { |
| 110 |
title.focus = false |
| 111 |
subtitle.focus = false |
| 112 |
cover.isTextEditing = false |
| 113 |
} |
| 114 |
|
| 115 |
Item { |
| 116 |
id: cover |
| 117 |
|
| 118 |
property bool isTextEditing: false |
| 119 |
|
| 120 |
// Read-only |
| 121 |
property int previewPixelWidth: coverImagePreviewLeft.width |
| 122 |
+ coverImagePreviewRight.width |
| 123 |
|
| 124 |
anchors.fill: parent |
| 125 |
|
| 126 |
transform: Scale { |
| 127 |
id: scale |
| 128 |
} |
| 129 |
|
| 130 |
AlbumCoverList { |
| 131 |
id: coverList |
| 132 |
} |
| 133 |
|
| 134 |
Image { |
| 135 |
id: coverImagePreviewLeft |
| 136 |
|
| 137 |
source: "img/album-cover-preview-left.png" |
| 138 |
visible: isPreview |
| 139 |
|
| 140 |
width: isPreview ? 6 : undefined |
| 141 |
height: isPreview ? 281 : undefined |
| 142 |
|
| 143 |
anchors.left: parent.left |
| 144 |
anchors.top: parent.top |
| 145 |
cache: true |
| 146 |
} |
| 147 |
|
| 148 |
Image { |
| 149 |
id: coverImagePreviewRight |
| 150 |
|
| 151 |
source: coverElement.imagePreview |
| 152 |
visible: isPreview |
| 153 |
|
| 154 |
width: isPreview ? 229 : undefined |
| 155 |
height: isPreview ? 281 : undefined |
| 156 |
|
| 157 |
anchors.left: coverImagePreviewLeft.right |
| 158 |
anchors.top: parent.top |
| 159 |
cache: true |
| 160 |
} |
| 161 |
|
| 162 |
// Must be positioned before TextEdit elements to capture mouse events |
| 163 |
// underneath the album title. |
| 164 |
MouseArea { |
| 165 |
anchors.fill: parent |
| 166 |
|
| 167 |
acceptedButtons: Qt.LeftButton | Qt.RightButton |
| 168 |
onPressed: { |
| 169 |
mouse.accepted = false; |
| 170 |
albumCover.pressed(mouse); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
Image { |
| 175 |
id: coverImageFull |
| 176 |
objectName: "albumCoverImage" |
| 177 |
|
| 178 |
source: coverElement.imageFull |
| 179 |
visible: !isPreview |
| 180 |
|
| 181 |
anchors.fill: parent |
| 182 |
cache: true |
| 183 |
|
| 184 |
Image { |
| 185 |
id: addPhotosImage |
| 186 |
objectName: "albumCoverAddPhotosImage" |
| 187 |
|
| 188 |
// Size ratio of image to screen space. |
| 189 |
property real sizeRatio: coverImageFull.parent.width / coverImageFull.sourceSize.width |
| 190 |
|
| 191 |
source: coverElement.addFilename |
| 192 |
visible: !isPreview |
| 193 |
|
| 194 |
// Eyeballed in GIMP |
| 195 |
x: 543 * sizeRatio |
| 196 |
y: 0 |
| 197 |
width: sourceSize.width * sizeRatio |
| 198 |
height: sourceSize.height * sizeRatio |
| 199 |
|
| 200 |
MouseArea { |
| 201 |
id: addPhotosButton |
| 202 |
|
| 203 |
acceptedButtons: Qt.LeftButton | Qt.RightButton |
| 204 |
anchors.fill: parent |
| 205 |
onClicked: addPhotos() |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
Column { |
| 211 |
anchors.left: parent.left |
| 212 |
anchors.right: parent.right |
| 213 |
anchors.leftMargin: coverMarginLeft |
| 214 |
anchors.rightMargin: coverMarginRight |
| 215 |
anchors.top: parent.top |
| 216 |
anchors.topMargin: coverStartY |
| 217 |
|
| 218 |
visible: !isBack && !isBlank |
| 219 |
|
| 220 |
// Spacer |
| 221 |
Item { |
| 222 |
id: spacerTop |
| 223 |
|
| 224 |
width: 1 |
| 225 |
height: units.gu(5) * spacerScale |
| 226 |
} |
| 227 |
|
| 228 |
Item { |
| 229 |
id: titleContainer |
| 230 |
height: title.height |
| 231 |
width: parent.width |
| 232 |
|
| 233 |
Rectangle { |
| 234 |
id: titleBackground |
| 235 |
|
| 236 |
color: "black" |
| 237 |
opacity: 0.5 |
| 238 |
visible: !isPreview |
| 239 |
|
| 240 |
anchors.top: titleContainer.top |
| 241 |
height: title.height |
| 242 |
width: parent.width |
| 243 |
} |
| 244 |
|
| 245 |
TextEdit{ |
| 246 |
id: title |
| 247 |
objectName: "albumTitleField" |
| 248 |
anchors{ |
| 249 |
top: titleContainer.top |
| 250 |
left: parent.left |
| 251 |
right: parent.right |
| 252 |
} |
| 253 |
readOnly: isPreview |
| 254 |
enabled: !readOnly // do not block mouse clicks when readOnly |
| 255 |
opacity: titleOpacity |
| 256 |
color: "#ffffff" |
| 257 |
font.family: "Ubuntu" |
| 258 |
font.pixelSize: albumCover.height * 0.09 |
| 259 |
smooth: true |
| 260 |
wrapMode: Text.Wrap |
| 261 |
horizontalAlignment: Text.AlignHCenter |
| 262 |
|
| 263 |
text: album ? album.title : "" |
| 264 |
|
| 265 |
// workaround to limit lineCount |
| 266 |
// Idea taken from: https://bugreports.qt-project.org/browse/QTBUG-12304 |
| 267 |
// this workaround should be replaceable with maximumLength property in Qt 5.15 |
| 268 |
readonly property int maximumLineCount: 2 |
| 269 |
property string previousText: "" |
| 270 |
onTextChanged: { |
| 271 |
if (lineCount > maximumLineCount) { |
| 272 |
var cursor = cursorPosition; |
| 273 |
text = previousText; |
| 274 |
cursorPosition = cursor > text.length ? text.length : cursor - 1; |
| 275 |
} |
| 276 |
|
| 277 |
// Save text so we can revert if necessary. |
| 278 |
previousText = text; |
| 279 |
} |
| 280 |
|
| 281 |
Keys.onPressed: { |
| 282 |
// when pressing enter: give focus to subtitle + don't insert line break character to title |
| 283 |
if (event.key === Qt.Key_Return) { |
| 284 |
subtitle.forceActiveFocus() |
| 285 |
event.accepted = true |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
// commit changes when leaving or destroying the text field |
| 290 |
onActiveFocusChanged: { |
| 291 |
if (!activeFocus && album) |
| 292 |
album.title = text |
| 293 |
} |
| 294 |
Component.onDestruction: { |
| 295 |
if (album) |
| 296 |
album.title = text |
| 297 |
} |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
// Spacer |
| 302 |
Item { |
| 303 |
width: 1 |
| 304 |
height: titleDateSpacing * spacerScale |
| 305 |
} |
| 306 |
|
| 307 |
Item { |
| 308 |
id: subtitleContainer |
| 309 |
height: title.height |
| 310 |
width: parent.width |
| 311 |
|
| 312 |
Rectangle { |
| 313 |
id: subtitleBackground |
| 314 |
|
| 315 |
color: "black" |
| 316 |
opacity: 0.5 |
| 317 |
visible: !isPreview |
| 318 |
|
| 319 |
anchors.top: subtitleContainer.top |
| 320 |
height: subtitle.height |
| 321 |
width: parent.width |
| 322 |
} |
| 323 |
|
| 324 |
TextEdit{ |
| 325 |
id: subtitle |
| 326 |
objectName: "albumSubtitleField" |
| 327 |
anchors{ |
| 328 |
top: subtitleContainer.top |
| 329 |
left: parent.left |
| 330 |
right: parent.right |
| 331 |
} |
| 332 |
readOnly: isPreview |
| 333 |
enabled: !readOnly // do not block mouse clicks when readOnly |
| 334 |
opacity: titleOpacity |
| 335 |
color: "#ffffff" |
| 336 |
font.family: "Ubuntu" |
| 337 |
font.pixelSize: albumCover.height * 0.07 |
| 338 |
smooth: true |
| 339 |
wrapMode: Text.Wrap |
| 340 |
horizontalAlignment: Text.AlignHCenter |
| 341 |
|
| 342 |
text: album ? album.subtitle : "" |
| 343 |
|
| 344 |
// workaround to limit lineCount |
| 345 |
// Idea taken from: https://bugreports.qt-project.org/browse/QTBUG-12304 |
| 346 |
// this workaround should be replaceable with maximumLength property in Qt 5.15 |
| 347 |
readonly property int maximumLineCount: 2 |
| 348 |
property string previousText: "" |
| 349 |
onTextChanged: { |
| 350 |
if (lineCount > maximumLineCount) { |
| 351 |
var cursor = cursorPosition; |
| 352 |
text = previousText; |
| 353 |
cursorPosition = cursor > text.length ? text.length : cursor - 1; |
| 354 |
} |
| 355 |
|
| 356 |
// Save text so we can revert if necessary. |
| 357 |
previousText = text; |
| 358 |
} |
| 359 |
|
| 360 |
Keys.onPressed: { |
| 361 |
// when pressing enter: leave focus + don't insert line break character to title |
| 362 |
if (event.key === Qt.Key_Return) { |
| 363 |
subtitle.focus = false |
| 364 |
event.accepted = true |
| 365 |
} |
| 366 |
} |
| 367 |
|
| 368 |
// commit changes when leaving or destroying the text field |
| 369 |
onActiveFocusChanged: { |
| 370 |
if (!activeFocus && album) |
| 371 |
album.subtitle = text |
| 372 |
} |
| 373 |
Component.onDestruction: { |
| 374 |
if (album) |
| 375 |
album.subtitle = text |
| 376 |
} |
| 377 |
} |
| 378 |
} |
| 379 |
} |
| 380 |
} |
| 381 |
} |