1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 03:22:33 +01:00
ScreenPlay/ScreenPlayWallpaper/WebView.qml

150 lines
5.4 KiB
QML
Raw Normal View History

import QtQuick 2.0
import QtWebEngine 1.8
import ScreenPlay.Enums.InstalledType 1.0
import ScreenPlayWallpaper 1.0
2019-11-23 18:20:32 +01:00
Item {
2020-02-06 18:39:48 +01:00
id: root
2021-05-16 19:37:55 +02:00
2019-11-23 18:20:32 +01:00
property alias url: webView.url
2021-05-16 19:37:55 +02:00
signal requestFadeIn()
function getSetVideoCommand() {
// TODO 30:
// Currently wont work. Commit anyways til QtCreator and Qt work with js template literals
2021-05-16 19:37:55 +02:00
var src = "";
src += "var videoPlayer = document.getElementById('videoPlayer');";
src += "var videoSource = document.getElementById('videoSource');";
src += "videoSource.src = '" + Wallpaper.projectSourceFileAbsolute + "';";
src += "videoPlayer.load();";
src += "videoPlayer.volume = " + Wallpaper.volume + ";";
src += "videoPlayer.setAttribute('style', 'object-fit :" + Wallpaper.fillMode + ";');";
src += "videoPlayer.play();";
return src;
}
Component.onCompleted: {
WebEngine.settings.localContentCanAccessFileUrls = true;
WebEngine.settings.localContentCanAccessRemoteUrls = true;
WebEngine.settings.allowRunningInsecureContent = true;
WebEngine.settings.accelerated2dCanvasEnabled = true;
WebEngine.settings.javascriptCanOpenWindows = false;
WebEngine.settings.showScrollBars = false;
WebEngine.settings.playbackRequiresUserGesture = false;
WebEngine.settings.focusOnNavigationEnabled = true;
}
WebEngineView {
id: webView
2021-05-16 19:37:55 +02:00
anchors.fill: parent
url: "qrc:/index.html"
backgroundColor: "transparent"
2019-11-23 18:20:32 +01:00
onJavaScriptConsoleMessage: print(lineNumber, message)
onLoadProgressChanged: {
2019-11-23 18:20:32 +01:00
if ((loadProgress === 100)) {
2021-05-16 19:37:55 +02:00
if (Wallpaper.type === InstalledType.VideoWallpaper)
webView.runJavaScript(root.getSetVideoCommand(), function(result) {
requestFadeIn();
});
else
requestFadeIn();
}
}
}
Text {
id: txtVisualsPaused
2021-05-16 19:37:55 +02:00
text: qsTr("If you can read this, then the VisualsPaused optimization does not work on your system. You can fix this by disable this in: \n Settings -> Perfromance -> Pause wallpaper video rendering while another app is in the foreground ")
font.pointSize: 32
visible: false
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
anchors.centerIn: parent
2021-05-16 19:37:55 +02:00
width: parent.width * 0.8
color: "white"
}
Timer {
id: timerCover
2021-05-16 19:37:55 +02:00
interval: 300
onTriggered: {
2021-05-16 19:37:55 +02:00
webView.visible = !Wallpaper.visualsPaused;
txtVisualsPaused.visible = Wallpaper.visualsPaused;
}
}
Connections {
function onReloadVideo(oldType) {
2021-05-16 19:37:55 +02:00
webView.runJavaScript(root.getSetVideoCommand());
}
function onQmlExit() {
2021-05-16 19:37:55 +02:00
webView.runJavaScript("var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;");
}
function onMutedChanged(muted) {
2021-05-16 19:37:55 +02:00
if (muted)
webView.runJavaScript("var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;");
else
webView.runJavaScript("var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = " + Wallpaper.volume + ";");
}
function onFillModeChanged(fillMode) {
2021-05-16 19:37:55 +02:00
if (webView.loadProgress === 100)
webView.runJavaScript("var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.setAttribute('style', 'object-fit :" + fillMode + ";');");
}
function onLoopsChanged(loops) {
2021-05-16 19:37:55 +02:00
if (webView.loadProgress === 100)
webView.runJavaScript("var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.loop = " + loops + ";");
}
function onVolumeChanged(volume) {
2021-05-16 19:37:55 +02:00
if (webView.loadProgress === 100)
webView.runJavaScript("var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = " + volume + ";");
}
function onCurrentTimeChanged(currentTime) {
2021-05-16 19:37:55 +02:00
if (webView.loadProgress === 100)
webView.runJavaScript("var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.currentTime = " + currentTime + " * videoPlayer.duration;");
}
function onPlaybackRateChanged(playbackRate) {
2021-05-16 19:37:55 +02:00
if (webView.loadProgress === 100)
webView.runJavaScript("var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.playbackRate = " + playbackRate + ";");
}
function onVisualsPausedChanged(visualsPaused) {
if (visualsPaused) {
// Wait until Wallpaper animation is finsihed
2021-05-16 19:37:55 +02:00
timerCover.restart();
} else {
2021-05-16 19:37:55 +02:00
webView.visible = true;
txtVisualsPaused.visible = false;
}
}
function onIsPlayingChanged(isPlaying) {
if (webView.loadProgress === 100) {
2021-05-16 19:37:55 +02:00
if (isPlaying)
webView.runJavaScript("var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.play();");
else
webView.runJavaScript("var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.pause();");
}
}
2021-05-16 19:37:55 +02:00
target: Wallpaper
}
2021-05-16 19:37:55 +02:00
}