2 * Copyright (C) 2013-2016 Canonical Ltd.
3 * Copyright (C) 2021 UBports Foundation
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.
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.
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/>.
19import QtQuick.Window 2.2
20import Lomiri.Components 1.3
24 objectName: "Wallpaper"
25 property url source: ""
27 // sourceSize should be set to the largest width or height that this
28 // Wallpaper will likely be set to.
29 // In most cases inside Lomiri, this should be set to the width or height
30 // of the shell, whichever is larger.
31 // However, care should be taken to avoid changing sourceSize once
33 property real sourceSize: -1.0
37 objectName: "wallpaperImage"
39 fillMode: Image.PreserveAspectCrop
43 property real oldSourceSize: 0.0
44 property real intermediarySourceSize: {
45 // If minSourceSize is defined by root's parent, it will be 0 until
46 // the binding resolves. Otherwise, it'll be -1.0. Abuse this
47 // behavior to avoid changing sourceSize more than once during
49 if (root.sourceSize === 0.0) {
50 developerSanityTimer.start();
51 // -1.0 signals that the wallpaper shouldn't render yet.
54 developerSanityTimer.stop();
55 if (root.sourceSize === -1.0 && root.source !== "") {
56 console.warn(`${root.objectName}'s sourceSize is unset. It will use a lot of memory.`);
60 return root.sourceSize
63 onIntermediarySourceSizeChanged: {
64 if (oldSourceSize !== 0.0 && oldSourceSize !== -1.0 && root.source !== "") {
65 console.warn(`${root.objectName} source size is changing from ${oldSourceSize} to ${intermediarySourceSize}. This will cause an expensive image reload.`);
67 oldSourceSize = intermediarySourceSize;
70 sourceSize: Qt.size(intermediarySourceSize, intermediarySourceSize)
71 source: intermediarySourceSize !== -1.0 ? root.source : ""
75 id: wallpaperFadeRectangle
76 objectName: "wallpaperFadeRectangle"
77 color: theme.palette.normal.background
79 opacity: image.status === Image.Ready ? 0: 1
80 visible: opacity !== 0
82 LomiriNumberAnimation { duration: LomiriAnimation.FastDuration }
87 id: developerSanityTimer
91 if (root.sourceSize === 0.0 && root.source !== "") {
92 console.warn(`${root.objectName} has not received its sourceSize yet. It will not render.`);