Warning, /plasma/kdeplasma-addons/wallpapers/potd/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   SPDX-FileCopyrightText: 2016 Weng Xuetian <wengxt@gmail.com>
0003  *
0004  *   SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 import QtQuick 2.15
0008 import QtQuick.Controls 2.15 as QQC2
0009 import QtQuick.Window 2.15
0010 
0011 import org.kde.plasma.core as PlasmaCore
0012 import org.kde.kirigami 2.20 as Kirigami
0013 
0014 import org.kde.plasma.wallpapers.potd 1.0
0015 import org.kde.plasma.plasmoid 2.0
0016 
0017 WallpaperItem {
0018     id: root
0019 
0020     contextualActions: [
0021         PlasmaCore.Action {
0022             text: i18nd("plasma_wallpaper_org.kde.potd", "Open Wallpaper Image")
0023             icon.name: "document-open"
0024             onTriggered: Qt.openUrlExternally(backend.localUrl);
0025         }
0026     ]
0027 
0028     QQC2.StackView {
0029         id: imageView
0030         anchors.fill: parent
0031 
0032         readonly property int fillMode: root.configuration.FillMode
0033         readonly property size sourceSize: Qt.size(imageView.width * Screen.devicePixelRatio, imageView.height * Screen.devicePixelRatio)
0034         property Item pendingImage
0035         property bool doesSkipAnimation: true
0036 
0037         onFillModeChanged: Qt.callLater(imageView.loadImage)
0038         onSourceSizeChanged: Qt.callLater(imageView.loadImage)
0039 
0040         function loadImage() {
0041             if (backend.localUrl.length === 0) {
0042                 return;
0043             }
0044             if (imageView.pendingImage) {
0045                 imageView.pendingImage.statusChanged.disconnect(replaceWhenLoaded);
0046                 imageView.pendingImage.destroy();
0047                 imageView.pendingImage = null;
0048             }
0049 
0050             imageView.doesSkipAnimation = imageView.empty || sourceSize !== imageView.currentItem.sourceSize;
0051             imageView.pendingImage = imageComponent.createObject(imageView, {
0052                 "source": backend.localUrl,
0053                 "fillMode": imageView.fillMode,
0054                 "opacity": imageView.doesSkipAnimation ? 1 : 0,
0055                 "sourceSize": imageView.sourceSize,
0056                 "width": imageView.width,
0057                 "height": imageView.height,
0058             });
0059             imageView.pendingImage.statusChanged.connect(imageView.replaceWhenLoaded);
0060             imageView.replaceWhenLoaded();
0061         }
0062 
0063         function replaceWhenLoaded() {
0064             if (imageView.pendingImage.status === Image.Loading) {
0065                 return;
0066             }
0067             imageView.pendingImage.statusChanged.disconnect(imageView.replaceWhenLoaded);
0068             imageView.replace(imageView.pendingImage, {}, imageView.doesSkipAnimation ? QQC2.StackView.Immediate : QQC2.StackView.Transition);
0069             imageView.pendingImage = null;
0070         }
0071 
0072         PotdBackend {
0073             id: backend
0074             identifier: root.configuration.Provider
0075             arguments: {
0076                 if (identifier === "bing") {
0077                     // Bing supports 1366/1920/UHD resolutions
0078                     const w = imageView.sourceSize.width > 1920 ? 3840 : 1920;
0079                     const h = imageView.sourceSize.height > 1080 ? 2160 : 1080;
0080                     return [w, h];
0081                 }
0082                 return [];
0083             }
0084             updateOverMeteredConnection: root.configuration.UpdateOverMeteredConnection
0085 
0086             onImageChanged: Qt.callLater(imageView.loadImage)
0087             onLocalUrlChanged: Qt.callLater(imageView.loadImage)
0088         }
0089 
0090         Component {
0091             id: imageComponent
0092 
0093             Image {
0094                 asynchronous: true
0095                 cache: false
0096                 autoTransform: true
0097                 smooth: true
0098 
0099                 QQC2.StackView.onActivated: root.accentColorChanged()
0100                 QQC2.StackView.onRemoved: destroy()
0101             }
0102         }
0103 
0104         Rectangle {
0105             id: backgroundColor
0106             anchors.fill: parent
0107             color: root.configuration.Color
0108             Behavior on color {
0109                 ColorAnimation { duration: Kirigami.Units.longDuration }
0110             }
0111         }
0112 
0113         replaceEnter: Transition {
0114             OpacityAnimator {
0115                 id: replaceEnterOpacityAnimator
0116                 to: 1
0117                 // As the wallpaper is updated once a day, the transition should be longer.
0118                 duration: Math.round(Kirigami.Units.veryLongDuration * 5)
0119             }
0120         }
0121         // Keep the old image around till the new one is fully faded in
0122         // If we fade both at the same time you can see the background behind glimpse through
0123         replaceExit: Transition {
0124             PauseAnimation {
0125                 duration: replaceEnterOpacityAnimator.duration
0126             }
0127         }
0128     }
0129 }