1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-09 20:42:47 +01:00
ScreenPlay/ScreenPlayWallpaper/Wallpaper.qml

304 lines
8.9 KiB
QML
Raw Normal View History

import QtQml 2.14
import QtQuick 2.14
import QtQuick.Controls 2.14
import ScreenPlayWallpaper 1.0
import ScreenPlay.Enums.InstalledType 1.0
2020-09-13 19:51:20 +02:00
import ScreenPlay.Shader 1.0
import "ShaderWrapper" as ShaderWrapper
2019-03-28 21:25:39 +01:00
Rectangle {
id: root
2019-03-28 21:25:39 +01:00
anchors.fill: parent
color: {
if (Qt.platform.os !== "windows") {
2019-03-28 21:25:39 +01:00
return "black"
} else {
return Wallpaper.windowsDesktopProperties.color
2019-03-28 21:25:39 +01:00
}
}
2019-08-11 19:48:07 +02:00
property bool canFadeByWallpaperFillMode: true
2019-03-28 21:25:39 +01:00
2020-03-09 18:06:50 +01:00
Component.onCompleted: {
init()
2020-03-09 18:06:50 +01:00
}
Connections {
target: Wallpaper
function onQmlExit() {
if (canFadeByWallpaperFillMode && Wallpaper.canFade) {
2021-04-21 18:13:47 +02:00
imgCover.state = "exit"
} else {
Wallpaper.terminate()
}
}
2019-03-30 12:56:34 +01:00
function onQmlSceneValueReceived(key, value) {
var obj2 = 'import QtQuick 2.0; Item {Component.onCompleted: loader.item.'
+ key + ' = ' + value + '; }'
var newObject = Qt.createQmlObject(obj2.toString(), root, "err")
newObject.destroy(10000)
}
// Replace wallpaper with QML Scene
function onReloadQML(oldType) {
2020-03-09 18:06:50 +01:00
loader.sourceComponent = undefined
loader.source = ""
2020-11-07 14:02:27 +01:00
Wallpaper.clearComponentCache()
loader.source = Qt.resolvedUrl(Wallpaper.fullContentPath)
}
// Replace wallpaper with GIF
function onReloadGIF(oldType) {
init()
}
// This function only gets called here (the same function
// is inside the WebView.qml) when the previous Wallpaper type
// was not a video
function onReloadVideo(oldType) {
// We need to check if the old type
// was also Video not get called twice
if (oldType === InstalledType.VideoWallpaper)
2020-08-23 19:06:17 +02:00
return
2021-04-21 18:13:47 +02:00
imgCover.state = "showDefaultBackgroundImage"
loader.source = "qrc:/WebView.qml"
2020-03-09 18:06:50 +01:00
}
}
2019-03-28 21:25:39 +01:00
function init() {
switch (Wallpaper.type) {
case InstalledType.VideoWallpaper:
loader.source = "qrc:/WebView.qml"
2019-03-28 21:25:39 +01:00
break
case InstalledType.HTMLWallpaper:
loader.setSource("qrc:/WebView.qml", {
"url": Qt.resolvedUrl(
Wallpaper.fullContentPath)
})
2019-03-28 21:25:39 +01:00
break
case InstalledType.QMLWallpaper:
loader.source = Qt.resolvedUrl(Wallpaper.fullContentPath)
2021-04-21 18:13:47 +02:00
fadeIn()
2019-03-28 21:25:39 +01:00
break
case InstalledType.WebsiteWallpaper:
2020-12-28 17:26:56 +01:00
loader.setSource("qrc:/WebsiteWallpaper.qml", {
"url": Wallpaper.fullContentPath
2020-12-28 17:26:56 +01:00
})
2021-04-21 18:13:47 +02:00
fadeIn()
2020-12-28 17:26:56 +01:00
break
case InstalledType.GifWallpaper:
2020-12-28 17:26:56 +01:00
loader.setSource("qrc:/GifWallpaper.qml", {
"source": Qt.resolvedUrl(
Wallpaper.fullContentPath)
})
2021-04-21 18:13:47 +02:00
fadeIn()
2020-12-28 17:26:56 +01:00
break
2019-03-28 21:25:39 +01:00
}
}
function fadeIn() {
Wallpaper.setVisible(true)
if (canFadeByWallpaperFillMode && Wallpaper.canFade) {
2021-04-21 18:13:47 +02:00
imgCover.state = "hideDefaultBackgroundImage"
2019-03-28 21:25:39 +01:00
} else {
imgCover.opacity = 0
}
}
Loader {
id: loader
anchors.fill: parent
// QML Engine deadlocks in 5.15.2 when a loader cannot load
// an item. QApplication::quit(); waits for the destruction forever.
asynchronous: true
onStatusChanged: {
if (loader.status === Loader.Error) {
loader.source = ""
Wallpaper.terminate()
}
}
Connections {
ignoreUnknownSignals: true
target: loader.item
function onRequestFadeIn() {
fadeIn()
}
}
}
2019-03-28 21:25:39 +01:00
Image {
id: imgCover
anchors {
top: parent.top
2020-12-11 14:14:00 +01:00
topMargin: -3 // To fix the offset from setupWallpaperForOneScreen
left: parent.left
right: parent.right
}
2021-04-21 18:13:47 +02:00
state: "showDefaultBackgroundImage"
sourceSize.width: Wallpaper.width
sourceSize.height: Wallpaper.height
source: {
if (Qt.platform.os === "windows") {
return Qt.resolvedUrl(
"file:///" + Wallpaper.windowsDesktopProperties.wallpaperPath)
2021-04-22 18:27:55 +02:00
} else {
return ""
}
}
states: [
State {
2021-04-21 18:13:47 +02:00
name: "showDefaultBackgroundImage"
PropertyChanges {
target: imgCover
opacity: 1
}
},
State {
2021-04-21 18:13:47 +02:00
name: "hideDefaultBackgroundImage"
PropertyChanges {
target: imgCover
opacity: 0
}
},
State {
2021-04-21 18:13:47 +02:00
name: "exit"
PropertyChanges {
target: imgCover
opacity: 1
}
}
]
transitions: [
Transition {
2021-04-21 18:13:47 +02:00
from: "showDefaultBackgroundImage"
to: "hideDefaultBackgroundImage"
reversible: true
2021-04-21 18:13:47 +02:00
SequentialAnimation {
PauseAnimation {
duration: 100
}
PropertyAnimation {
target: imgCover
duration: 600
property: "opacity"
}
}
},
Transition {
2021-04-21 18:13:47 +02:00
from: "hideDefaultBackgroundImage"
to: "exit"
reversible: true
SequentialAnimation {
PropertyAnimation {
target: imgCover
duration: 600
property: "opacity"
}
ScriptAction {
script: Wallpaper.terminate()
}
}
}
]
2019-03-28 21:25:39 +01:00
Component.onCompleted: {
2020-08-23 19:06:17 +02:00
if (Qt.platform.os !== "windows") {
root.canFadeByWallpaperFillMode = false
return
2020-08-23 19:06:17 +02:00
}
switch (Wallpaper.windowsDesktopProperties.wallpaperStyle) {
2019-03-28 21:25:39 +01:00
case 10:
imgCover.fillMode = Image.PreserveAspectCrop
break
case 6:
imgCover.fillMode = Image.PreserveAspectFit
break
case 2:
break
case 0:
if (desktopProperties.isTiled) {
// Tiled
imgCover.fillMode = Image.Tile
} else {
// Center
imgCover.fillMode = Image.PreserveAspectFit
imgCover.anchors.centerIn = parent
imgCover.width = sourceSize.width
imgCover.height = sourceSize.height
}
break
case 22:
2020-08-23 19:06:17 +02:00
root.canFadeByWallpaperFillMode = false
2019-03-28 21:25:39 +01:00
break
}
}
}
Pane {
id: debug
visible: Wallpaper.debugMode
enabled: Wallpaper.debugMode
width: parent.width * .3
height: parent.height * .3
anchors.centerIn: parent
background: Rectangle {
opacity: .5
}
Column {
anchors.fill: parent
anchors.margins: 20
spacing: 10
Text {
text: "appID " + Wallpaper.appID
font.pointSize: 14
}
Text {
text: "basePath " + Wallpaper.basePath
font.pointSize: 14
}
Text {
text: "fullContentPath " + Wallpaper.fullContentPath
font.pointSize: 14
}
Text {
text: "fillMode " + Wallpaper.fillMode
font.pointSize: 14
}
Text {
text: "sdk.type " + Wallpaper.sdk.type
font.pointSize: 14
}
Text {
text: "sdk.isConnected " + Wallpaper.sdk.isConnected
font.pointSize: 14
}
Text {
text: "sdk.appID " + Wallpaper.sdk.appID
font.pointSize: 14
}
2021-04-21 18:13:47 +02:00
Text {
text: "canFadeByWallpaperFillMode " + canFadeByWallpaperFillMode
font.pointSize: 14
}
Text {
text: "Wallpaper.canFade " + Wallpaper.canFade
font.pointSize: 14
}
Text {
text: "imgCover.status " + imgCover.status
font.pointSize: 14
}
}
}
2019-03-28 21:25:39 +01:00
}