mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-21 18:22:29 +01:00
Some refactoring of the wallpaper. Split video/webview into seperate qml file.
Add sanity check for current time. Change animation from OpacityAnimation to states. This is a behavior change in Qt 5.14 resulting in not starting the animation when no mouse enter was detected at all.
This commit is contained in:
parent
4d1a68b4b9
commit
0a27b61885
@ -3,5 +3,7 @@
|
||||
<file>mainWindow.qml</file>
|
||||
<file>test.qml</file>
|
||||
<file>dot.png</file>
|
||||
<file>qtquickcontrols2.conf</file>
|
||||
<file>WebView.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
120
ScreenPlayWallpaper/WebView.qml
Normal file
120
ScreenPlayWallpaper/WebView.qml
Normal file
@ -0,0 +1,120 @@
|
||||
import QtQuick 2.0
|
||||
import ScreenPlay.Wallpaper 1.0
|
||||
import QtWebEngine 1.8
|
||||
|
||||
Item {
|
||||
property string url: webView.url
|
||||
|
||||
signal requestFadeIn()
|
||||
|
||||
Component.onCompleted: {
|
||||
|
||||
WebEngine.settings.allowRunningInsecureContent = true
|
||||
WebEngine.settings.accelerated2dCanvasEnabled = true
|
||||
WebEngine.settings.javascriptCanOpenWindows = false
|
||||
WebEngine.settings.printElementBackgrounds = false
|
||||
WebEngine.settings.showScrollBars = false
|
||||
WebEngine.settings.playbackRequiresUserGesture = false
|
||||
}
|
||||
|
||||
WebEngineView {
|
||||
id: webView
|
||||
anchors.fill: parent
|
||||
url: Qt.resolvedUrl(window.getApplicationPath() + "/index.html")
|
||||
onLoadProgressChanged: {
|
||||
if (loadProgress === 100) {
|
||||
|
||||
// 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 = '" + window.fullContentPath + "';"
|
||||
src += "videoPlayer.load();"
|
||||
src += "videoPlayer.volume = " + window.volume + ";"
|
||||
src += "videoPlayer.setAttribute('style', 'object-fit :" + window.fillMode + ";');"
|
||||
src += "videoPlayer.play();"
|
||||
|
||||
webView.runJavaScript(src, function (result) {
|
||||
fadeInTimer.start()
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
onJavaScriptConsoleMessage: print(lineNumber, message)
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: fadeInTimer
|
||||
interval: 500
|
||||
onTriggered: requestFadeIn()
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: window
|
||||
|
||||
onQmlExit: {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;")
|
||||
}
|
||||
|
||||
onMutedChanged: {
|
||||
if (muted) {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;")
|
||||
} else {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = " + window.volume + ";")
|
||||
}
|
||||
}
|
||||
|
||||
onFillModeChanged: {
|
||||
if (webView.loadProgress === 100) {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.setAttribute('style', 'object-fit :" + window.fillMode + ";');")
|
||||
}
|
||||
}
|
||||
|
||||
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 + ";")
|
||||
}
|
||||
}
|
||||
|
||||
onCurrentTimeChanged: {
|
||||
if (webView.loadProgress === 100) {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.currentTime = "
|
||||
+ currentTime + " * videoPlayer.duration;")
|
||||
}
|
||||
}
|
||||
|
||||
onPlaybackRateChanged: {
|
||||
if (webView.loadProgress === 100) {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.playbackRate = " + playbackRate + ";")
|
||||
}
|
||||
}
|
||||
|
||||
onIsPlayingChanged: {
|
||||
if (webView.loadProgress === 100) {
|
||||
if (isPlaying) {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.play();")
|
||||
} else {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.pause();")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
import QtQuick 2.12
|
||||
import QtWebEngine 1.8
|
||||
import ScreenPlay.Wallpaper 1.0
|
||||
|
||||
Rectangle {
|
||||
@ -15,102 +14,78 @@ Rectangle {
|
||||
|
||||
property bool canFadeByWallpaperFillMode: true
|
||||
|
||||
Connections {
|
||||
target: window
|
||||
|
||||
onQmlExit: {
|
||||
if (canFadeByWallpaperFillMode && window.canFade) {
|
||||
imgCover.state = "outExit"
|
||||
} else {
|
||||
window.terminate()
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
|
||||
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")
|
||||
webView.enabled = true
|
||||
loader.source = "qrc:/WebView.qml"
|
||||
|
||||
break
|
||||
case Wallpaper.WallpaperType.Html:
|
||||
webView.enabled = true
|
||||
webView.url = Qt.resolvedUrl(window.fullContentPath)
|
||||
loader.source = "qrc:/WebView.qml"
|
||||
loader.webViewUrl = Qt.resolvedUrl(window.fullContentPath)
|
||||
break
|
||||
case Wallpaper.WallpaperType.ThreeJSScene:
|
||||
webView.enabled = true
|
||||
webView.url = Qt.resolvedUrl(window.fullContentPath)
|
||||
loader.source = "qrc:/WebView.qml"
|
||||
loader.webViewUrl = Qt.resolvedUrl(window.fullContentPath)
|
||||
break
|
||||
case Wallpaper.WallpaperType.Qml:
|
||||
loader.enabled = true
|
||||
loader.source = Qt.resolvedUrl(window.fullContentPath)
|
||||
fadeIn()
|
||||
imgCover.state = "out"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function fadeIn() {
|
||||
print("fadeIn()")
|
||||
window.setVisible(true)
|
||||
print("setVisible()")
|
||||
if (canFadeByWallpaperFillMode && window.canFade) {
|
||||
animFadeIn.start()
|
||||
print("fadein")
|
||||
imgCover.state = "out"
|
||||
} else {
|
||||
print("imgCover.opacity = 0")
|
||||
imgCover.opacity = 0
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: fadeInTimer
|
||||
interval: 50
|
||||
onTriggered: fadeIn()
|
||||
}
|
||||
|
||||
OpacityAnimator {
|
||||
id: animFadeIn
|
||||
target: imgCover
|
||||
from: 1
|
||||
to: 0
|
||||
duration: 800
|
||||
easing.type: Easing.InOutQuad
|
||||
}
|
||||
|
||||
OpacityAnimator {
|
||||
id: animFadeOut
|
||||
target: imgCover
|
||||
from: 0
|
||||
to: 1
|
||||
duration: 800
|
||||
easing.type: Easing.InOutQuad
|
||||
onFinished: window.terminate()
|
||||
}
|
||||
|
||||
WebEngineView {
|
||||
id: webView
|
||||
enabled: false
|
||||
anchors.fill: parent
|
||||
onLoadProgressChanged: {
|
||||
if (loadProgress === 100) {
|
||||
|
||||
// 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 = '" + window.fullContentPath + "';"
|
||||
src += "videoPlayer.load();"
|
||||
src += "videoPlayer.volume = " + window.volume + ";"
|
||||
src += "videoPlayer.setAttribute('style', 'object-fit :" + window.fillMode + ";');"
|
||||
src += "videoPlayer.play();"
|
||||
|
||||
webView.runJavaScript(src, function (result) {
|
||||
fadeInTimer.start()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
onJavaScriptConsoleMessage: print(lineNumber, message)
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: loader
|
||||
anchors.fill: parent
|
||||
enabled: false
|
||||
property string webViewUrl
|
||||
onStatusChanged: {
|
||||
if (loader.status === Loader.Ready) {
|
||||
if (window.type === Wallpaper.WallpaperType.Video) {
|
||||
loader.item.url = loader.webViewUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
ignoreUnknownSignals: true
|
||||
target: loader.item
|
||||
onRequestFadeIn:fadeIn()
|
||||
}
|
||||
}
|
||||
|
||||
Image {
|
||||
@ -120,11 +95,63 @@ Rectangle {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
state: "in"
|
||||
|
||||
sourceSize.width: window.width
|
||||
sourceSize.height: window.height
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Component.onCompleted: {
|
||||
|
||||
switch (desktopProperties.wallpaperStyle) {
|
||||
@ -154,85 +181,4 @@ Rectangle {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: window
|
||||
|
||||
onMutedChanged:{
|
||||
if(muted){
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;")
|
||||
} else {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = " + window.volume + ";")
|
||||
}
|
||||
}
|
||||
|
||||
onQmlExit: {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.volume = 0;")
|
||||
|
||||
if (canFadeByWallpaperFillMode && window.canFade) {
|
||||
animFadeOut.start()
|
||||
} else {
|
||||
window.terminate()
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
onFillModeChanged:{
|
||||
if (webView.loadProgress === 100) {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.setAttribute('style', 'object-fit :" + window.fillMode + ";');")
|
||||
}
|
||||
}
|
||||
|
||||
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 + ";")
|
||||
}
|
||||
}
|
||||
|
||||
onCurrentTimeChanged: {
|
||||
if (webView.loadProgress === 100) {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.currentTime = " + currentTime + " * videoPlayer.duration;")
|
||||
}
|
||||
}
|
||||
|
||||
onPlaybackRateChanged: {
|
||||
if (webView.loadProgress === 100) {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.playbackRate = " + playbackRate + ";")
|
||||
}
|
||||
}
|
||||
|
||||
onIsPlayingChanged: {
|
||||
if (webView.loadProgress === 100) {
|
||||
if (isPlaying) {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.play();")
|
||||
} else {
|
||||
webView.runJavaScript(
|
||||
"var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.pause();")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
ScreenPlayWallpaper/qtquickcontrols2.conf
Normal file
11
ScreenPlayWallpaper/qtquickcontrols2.conf
Normal file
@ -0,0 +1,11 @@
|
||||
[Controls]
|
||||
Style=Material
|
||||
|
||||
[Material]
|
||||
Theme=Light
|
||||
Accent=Orange
|
||||
Primary=White
|
||||
Foreground=Grey
|
||||
Font\Family=Roboto
|
||||
Font\PixelSize=12
|
||||
Variant=Dense
|
@ -232,7 +232,9 @@ public slots:
|
||||
|
||||
void setCurrentTime(float currentTime)
|
||||
{
|
||||
qWarning("Floating point comparison needs context sanity check");
|
||||
if (currentTime < 0.0f || currentTime > 100000000000.0f)
|
||||
return;
|
||||
|
||||
if (qFuzzyCompare(m_currentTime, currentTime))
|
||||
return;
|
||||
|
||||
|
@ -68,6 +68,7 @@ WinWindow::WinWindow(
|
||||
const QString fillmode)
|
||||
: BaseWindow(projectPath)
|
||||
{
|
||||
m_window.hide();
|
||||
m_windowHandle = reinterpret_cast<HWND>(m_window.winId());
|
||||
|
||||
if (!IsWindow(m_windowHandle)) {
|
||||
@ -90,8 +91,8 @@ WinWindow::WinWindow(
|
||||
|
||||
// WARNING: Setting Window flags must be called *here*!
|
||||
Qt::WindowFlags flags = m_window.flags();
|
||||
m_window.setFlags(flags | Qt::FramelessWindowHint);
|
||||
SetWindowLongPtr(m_windowHandle, GWL_STYLE, WS_CHILDWINDOW);
|
||||
m_window.setFlags(flags | Qt::FramelessWindowHint | Qt::SplashScreen | Qt::ForeignWindow | Qt::SubWindow);
|
||||
//SetWindowLongPtr(m_windowHandle, GWL_STYLE, WS_CHILDWINDOW);
|
||||
SetWindowLongPtr(m_windowHandle, GWL_EXSTYLE, WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_NOACTIVATE);
|
||||
|
||||
// Windows coordante system begins at 0x0 at the
|
||||
@ -118,35 +119,18 @@ WinWindow::WinWindow(
|
||||
// we can set it here once :)
|
||||
m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering);
|
||||
m_window.setSource(QUrl("qrc:/mainWindow.qml"));
|
||||
|
||||
// MUST be called before setting hook for events!
|
||||
// if(type() == BaseWindow::WallpaperType::Qml){
|
||||
// winGlobalHook = &m_window;
|
||||
// if (!(mouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookCallback, nullptr, 0))) {
|
||||
// qDebug() << "Faild to install mouse hook!";
|
||||
// }
|
||||
// }
|
||||
|
||||
// FIXME WORKAROUND:
|
||||
// There is a strange bug when we open the ScreenPlayWallpaper project on its one
|
||||
// that if we set ShowWindow(m_windowHandle, SW_HIDE); we can no longer set
|
||||
// the window visible via set Visible.
|
||||
if (projectPath != "test") {
|
||||
// Let QML decide when were are read to show the window
|
||||
// ShowWindow(m_windowHandle, SW_HIDE);
|
||||
}
|
||||
m_window.hide();
|
||||
}
|
||||
|
||||
void WinWindow::setVisible(bool show)
|
||||
{
|
||||
if (show) {
|
||||
if (!ShowWindow(m_windowHandle, SW_SHOW)) {
|
||||
qDebug() << "Cannot set window handle visible";
|
||||
qDebug() << "Cannot set window handle SW_SHOW";
|
||||
}
|
||||
m_window.show();
|
||||
} else {
|
||||
if (!ShowWindow(m_windowHandle, SW_HIDE)) {
|
||||
qDebug() << "Cannot set window handle hidden";
|
||||
qDebug() << "Cannot set window handle SW_HIDE";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -220,7 +204,7 @@ void WinWindow::setupWallpaperForMultipleScreens(const QVector<int>& activeScree
|
||||
rect.setX(upperLeftScreen->geometry().x());
|
||||
rect.setY(upperLeftScreen->geometry().y());
|
||||
|
||||
if (!SetWindowPos(m_windowHandle, nullptr, rect.x()+ m_windowOffsetX, rect.y()+ m_windowOffsetY, rect.width(), rect.height(), SWP_SHOWWINDOW)) {
|
||||
if (!SetWindowPos(m_windowHandle, nullptr, rect.x() + m_windowOffsetX, rect.y() + m_windowOffsetY, rect.width(), rect.height(), SWP_SHOWWINDOW)) {
|
||||
qFatal("Could not set window pos: ");
|
||||
}
|
||||
if (SetParent(m_windowHandle, m_windowHandleWorker) == nullptr) {
|
||||
@ -228,6 +212,17 @@ void WinWindow::setupWallpaperForMultipleScreens(const QVector<int>& activeScree
|
||||
}
|
||||
}
|
||||
|
||||
void WinWindow::setupWindowMouseHook()
|
||||
{
|
||||
// MUST be called before setting hook for events!
|
||||
if (type() == BaseWindow::WallpaperType::Qml) {
|
||||
winGlobalHook = &m_window;
|
||||
if (!(mouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookCallback, nullptr, 0))) {
|
||||
qDebug() << "Faild to install mouse hook!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool WinWindow::searchWorkerWindowToParentTo()
|
||||
{
|
||||
HWND progman_hwnd = FindWindowW(L"Progman", L"Program Manager");
|
||||
@ -240,6 +235,7 @@ bool WinWindow::searchWorkerWindowToParentTo()
|
||||
|
||||
void WinWindow::terminate()
|
||||
{
|
||||
|
||||
ShowWindow(m_windowHandle, SW_HIDE);
|
||||
|
||||
// Force refresh so that we display the regular
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QApplication>
|
||||
#include <memory>
|
||||
|
||||
#include <qt_windows.h>
|
||||
@ -34,6 +35,7 @@ private:
|
||||
void setupWallpaperForOneScreen(int activeScreen);
|
||||
void setupWallpaperForAllScreens();
|
||||
void setupWallpaperForMultipleScreens(const QVector<int>& activeScreensList);
|
||||
void setupWindowMouseHook();
|
||||
bool searchWorkerWindowToParentTo();
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user