mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-09-15 06:52:34 +02:00
Add basic wallpaper logic to qml file
We now use websocket for communcation. For this to work we must add the logic to the screenplaymanager class.
This commit is contained in:
parent
076def3c03
commit
da59b2f4c6
37
ScreenPlayWallpaper/kde/ScreenPlay/contents/ui/index.html
Normal file
37
ScreenPlayWallpaper/kde/ScreenPlay/contents/ui/index.html
Normal file
@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
video {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: fill;
|
||||
overflow: hidden;
|
||||
}
|
||||
body, html{
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
overflow: hidden;
|
||||
background:black;
|
||||
}
|
||||
#errorMsg{
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
text-align: center;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
z-index: 0;
|
||||
color:white;
|
||||
font-family: "Segoe UI, Roboto, Arial";
|
||||
font-weight: lighter;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<video id="videoPlayer" oncontextmenu="return false;" width="100%" height="100%" loop autoplay>
|
||||
<source id="videoSource" type="video/webm" oncontextmenu="return false;" width="100%" height="100%">
|
||||
</video>
|
||||
</body>
|
||||
</html>
|
@ -1,12 +1,91 @@
|
||||
import QtQuick 2.11
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import QtGraphicalEffects 1.0
|
||||
import QtQuick.Window 2.0
|
||||
import Qt.WebSockets 1.15
|
||||
import QtWebEngine 1.8
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
color: "orange"
|
||||
width: Screen.width
|
||||
height: Screen.height
|
||||
color: "#333333"
|
||||
property string fullContentPath
|
||||
property real volume: 1.0
|
||||
property string fillMode: "Cover"
|
||||
property string type
|
||||
|
||||
WebSocket {
|
||||
id: socket
|
||||
url: "ws://127.0.0.1:16395"
|
||||
active: true
|
||||
onTextMessageReceived: {
|
||||
var obj = JSON.parse(message)
|
||||
if (obj.command === "replace") {
|
||||
root.type = obj.type
|
||||
root.fillMode = obj.fillMode
|
||||
root.volume = obj.volume
|
||||
root.fullContentPath = obj.absolutePath + "/" + obj.file
|
||||
webView.setVideo()
|
||||
}
|
||||
}
|
||||
onStatusChanged: if (socket.status === WebSocket.Error) {
|
||||
messageBox.text = "Error: " + socket.errorString
|
||||
} else if (socket.status === WebSocket.Open) {
|
||||
socket.sendTextMessage("Hello World")
|
||||
} else if (socket.status === WebSocket.Closed) {
|
||||
messageBox.text += "Socket closed"
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
function getSetVideoCommand() {
|
||||
// TODO 30:
|
||||
// Currently wont work. Commit anyways til QtCreator and Qt work with js template literals
|
||||
var src = ""
|
||||
src += "var videoPlayer = document.getElementById('videoPlayer');"
|
||||
src += "var videoSource = document.getElementById('videoSource');"
|
||||
src += "videoSource.src = '" + root.fullContentPath + "';"
|
||||
src += "videoPlayer.load();"
|
||||
src += "videoPlayer.volume = " + root.volume + ";"
|
||||
src += "videoPlayer.setAttribute('style', 'object-fit :" + root.fillMode + ";');"
|
||||
src += "videoPlayer.play();"
|
||||
print(src)
|
||||
|
||||
return src
|
||||
}
|
||||
|
||||
WebEngineView {
|
||||
id: webView
|
||||
anchors.fill: parent
|
||||
opacity: loadProgress === 100 ? 1 : 0
|
||||
onLoadProgressChanged: {
|
||||
if (loadProgress === 100)
|
||||
setVideo()
|
||||
}
|
||||
|
||||
function setVideo() {
|
||||
webView.runJavaScript(root.getSetVideoCommand())
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: infoWrapper
|
||||
width: 300
|
||||
height: 200
|
||||
opacity: 0
|
||||
anchors.centerIn: parent
|
||||
|
||||
Text {
|
||||
id: messageBox
|
||||
text: qsTr("text")
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user