2019-03-28 21:25:39 +01:00
|
|
|
import QtQuick 2.12
|
2019-03-30 12:56:34 +01:00
|
|
|
import QtWebEngine 1.8
|
2019-04-04 17:20:13 +02:00
|
|
|
import net.aimber.wallpaper 1.0
|
2019-03-28 21:25:39 +01:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
property bool canFadeIn: true
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
2019-03-30 12:56:34 +01:00
|
|
|
|
2019-03-28 21:25:39 +01:00
|
|
|
WebEngine.settings.allowRunningInsecureContent = true
|
|
|
|
WebEngine.settings.accelerated2dCanvasEnabled = true
|
|
|
|
WebEngine.settings.javascriptCanOpenWindows = false
|
|
|
|
WebEngine.settings.printElementBackgrounds = false
|
|
|
|
WebEngine.settings.showScrollBars = false
|
|
|
|
WebEngine.settings.playbackRequiresUserGesture = false
|
|
|
|
|
|
|
|
switch (window.type) {
|
|
|
|
case Wallpaper.WallpaperType.Video:
|
|
|
|
webView.url = Qt.resolvedUrl(window.getApplicationPath(
|
|
|
|
) + "/index.html")
|
2019-03-30 12:56:34 +01:00
|
|
|
webView.enabled = true
|
2019-03-28 21:25:39 +01:00
|
|
|
|
|
|
|
break
|
|
|
|
case Wallpaper.WallpaperType.Html:
|
|
|
|
webView.enabled = true
|
|
|
|
webView.url = Qt.resolvedUrl(window.fullContentPath)
|
|
|
|
break
|
|
|
|
case Wallpaper.WallpaperType.ThreeJSScene:
|
|
|
|
webView.enabled = true
|
|
|
|
break
|
|
|
|
case Wallpaper.WallpaperType.Qml:
|
|
|
|
loader.source = Qt.resolvedUrl(window.fullContentPath)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
fadeIn()
|
|
|
|
}
|
|
|
|
|
|
|
|
function fadeIn() {
|
|
|
|
window.setVisible(true)
|
|
|
|
if (canFadeIn) {
|
|
|
|
animFadeIn.start()
|
|
|
|
} else {
|
|
|
|
imgCover.opacity = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-30 12:56:34 +01:00
|
|
|
Loader {
|
|
|
|
id: loader
|
|
|
|
anchors.fill: parent
|
|
|
|
}
|
|
|
|
|
2019-03-28 21:25:39 +01:00
|
|
|
WebEngineView {
|
|
|
|
id: webView
|
2019-03-30 12:56:34 +01:00
|
|
|
enabled: false
|
2019-03-28 21:25:39 +01:00
|
|
|
anchors.fill: parent
|
|
|
|
onLoadProgressChanged: {
|
2019-03-30 12:56:34 +01:00
|
|
|
|
2019-03-28 21:25:39 +01:00
|
|
|
if (loadProgress === 100) {
|
|
|
|
|
|
|
|
var src = ""
|
|
|
|
src += "var videoPlayer = document.getElementById('videoPlayer');"
|
|
|
|
src += "var videoSource = document.getElementById('videoSource');"
|
2019-03-30 12:56:34 +01:00
|
|
|
src += "videoSource.src = '" + window.fullContentPath + "';"
|
2019-03-28 21:25:39 +01:00
|
|
|
src += "videoPlayer.load();"
|
|
|
|
src += "videoPlayer.volume = " + window.volume + ";"
|
|
|
|
src += "videoPlayer.play();"
|
|
|
|
|
2019-03-30 12:56:34 +01:00
|
|
|
webView.runJavaScript(src, function (result) {
|
2019-03-28 21:25:39 +01:00
|
|
|
fadeIn()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-03-30 12:56:34 +01:00
|
|
|
|
|
|
|
onJavaScriptConsoleMessage: print(lineNumber, message)
|
2019-03-28 21:25:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
OpacityAnimator {
|
|
|
|
id: animFadeIn
|
|
|
|
target: imgCover
|
|
|
|
from: 1
|
|
|
|
to: 0
|
|
|
|
duration: 300
|
|
|
|
easing.type: Easing.InCubic
|
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: imgCover
|
|
|
|
anchors.fill: parent
|
|
|
|
source: Qt.resolvedUrl("file:///" + desktopProperties.wallpaperPath)
|
|
|
|
Component.onCompleted: {
|
|
|
|
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:
|
|
|
|
canFadeIn = false
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: window
|
|
|
|
|
|
|
|
onQmlExit: {
|
|
|
|
webView.runJavaScript(
|
|
|
|
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;")
|
|
|
|
window.destroyThis()
|
|
|
|
}
|
|
|
|
|
|
|
|
onQmlSceneValueReceived: {
|
|
|
|
var obj2 = 'import QtQuick 2.12; Item {Component.onCompleted: loader.item.'
|
|
|
|
+ key + ' = ' + value + '; }'
|
|
|
|
var newObject = Qt.createQmlObject(obj2.toString(), root, "err")
|
|
|
|
newObject.destroy(10000)
|
|
|
|
}
|
|
|
|
|
|
|
|
onLoopsChanged: {
|
|
|
|
if (webView.loadProgress === 100) {
|
|
|
|
webView.runJavaScript(
|
|
|
|
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.loop = " + loops + ";")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onVolumeChanged: {
|
|
|
|
if (webView.loadProgress === 100) {
|
|
|
|
webView.runJavaScript(
|
|
|
|
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = " + volume + ";")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onPlaybackRateChanged: {
|
|
|
|
if (webView.loadProgress === 100) {
|
|
|
|
webView.runJavaScript(
|
|
|
|
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.playbackRate = " + playbackRate + ";")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onIsPlayingChanged: {
|
|
|
|
if (webView.loadProgress === 100) {
|
|
|
|
if (isPlaying === "false") {
|
|
|
|
webView.runJavaScript(
|
|
|
|
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.play();")
|
|
|
|
} else {
|
|
|
|
webView.runJavaScript(
|
|
|
|
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.pause();")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|