1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-09 12:32:40 +01:00
ScreenPlay/ScreenPlayWallpaper/mainWindow.qml

193 lines
5.2 KiB
QML
Raw Normal View History

2019-03-28 21:25:39 +01:00
import QtQuick 2.12
2019-06-10 16:27:17 +02:00
import ScreenPlay.Wallpaper 1.0
2019-03-28 21:25:39 +01:00
Rectangle {
id: root
2019-03-28 21:25:39 +01:00
anchors.fill: parent
color: {
2019-03-30 12:56:34 +01:00
if (desktopProperties.color === null) {
2019-03-28 21:25:39 +01:00
return "black"
} else {
return desktopProperties.color
}
}
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();
}
Connections {
target: window
onQmlExit: {
if (canFadeByWallpaperFillMode && window.canFade) {
imgCover.state = "outExit"
} else {
window.terminate()
}
}
2019-03-30 12:56:34 +01:00
onQmlSceneValueReceived: {
var obj2 = 'import QtQuick 2.0; Item {Component.onCompleted: loader.item.'
+ key + ' = ' + value + '; }'
print(key, value)
var newObject = Qt.createQmlObject(obj2.toString(), root, "err")
newObject.destroy(10000)
}
2020-03-09 18:06:50 +01:00
onReloadQML:{
loader.sourceComponent = undefined
loader.source = ""
window.clearComponentCache()
root.init()
}
}
2019-03-28 21:25:39 +01:00
2020-03-09 18:06:50 +01:00
function init(){
2019-03-28 21:25:39 +01:00
switch (window.type) {
case Wallpaper.WallpaperType.Video:
loader.source = "qrc:/WebView.qml"
2019-03-28 21:25:39 +01:00
break
case Wallpaper.WallpaperType.Html:
loader.webViewUrl = Qt.resolvedUrl(window.fullContentPath)
2019-11-23 18:20:32 +01:00
loader.source = "qrc:/WebView.qml"
2019-03-28 21:25:39 +01:00
break
case Wallpaper.WallpaperType.ThreeJSScene:
loader.webViewUrl = Qt.resolvedUrl(window.fullContentPath)
2019-11-23 18:20:32 +01:00
loader.source = "qrc:/WebView.qml"
2019-03-28 21:25:39 +01:00
break
case Wallpaper.WallpaperType.Qml:
loader.source = Qt.resolvedUrl(window.fullContentPath)
imgCover.state = "out"
2019-03-28 21:25:39 +01:00
break
}
}
function fadeIn() {
window.setVisible(true)
2019-08-11 19:48:07 +02:00
if (canFadeByWallpaperFillMode && window.canFade) {
imgCover.state = "out"
2019-03-28 21:25:39 +01:00
} else {
imgCover.opacity = 0
}
}
Loader {
id: loader
anchors.fill: parent
property string webViewUrl
onStatusChanged: {
if (loader.status === Loader.Ready) {
2019-11-23 18:20:32 +01:00
if (window.type === Wallpaper.WallpaperType.Html
|| window.type === Wallpaper.WallpaperType.ThreeJSScene) {
loader.item.url = loader.webViewUrl
2019-11-23 18:20:32 +01:00
print(loader.item.url," --- ",loader.webViewUrl)
}
}
}
Connections {
ignoreUnknownSignals: true
target: loader.item
2019-11-23 18:20:32 +01:00
onRequestFadeIn: fadeIn()
}
}
2019-03-28 21:25:39 +01:00
Image {
id: imgCover
anchors {
top: parent.top
left: parent.left
right: parent.right
}
state: "in"
sourceSize.width: window.width
sourceSize.height: window.height
2019-03-28 21:25:39 +01:00
source: Qt.resolvedUrl("file:///" + desktopProperties.wallpaperPath)
states: [
State {
name: "in"
PropertyChanges {
target: imgCover
opacity: 1
}
},
State {
name: "out"
PropertyChanges {
target: imgCover
opacity: 0
}
},
State {
name: "outExit"
PropertyChanges {
target: imgCover
opacity: 1
}
}
]
transitions: [
Transition {
from: "out"
to: "in"
reversible: true
PropertyAnimation {
target: imgCover
duration: 600
property: "opacity"
}
},
Transition {
from: "out"
to: "outExit"
reversible: true
SequentialAnimation {
PropertyAnimation {
target: imgCover
duration: 600
property: "opacity"
}
ScriptAction {
script: window.terminate()
}
}
}
]
2019-03-28 21:25:39 +01:00
Component.onCompleted: {
2019-03-28 21:25:39 +01:00
switch (desktopProperties.wallpaperStyle) {
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:
2019-08-11 19:48:07 +02:00
canFadeByWallpaperFillMode = false
2019-03-28 21:25:39 +01:00
break
}
}
}
}