2021-09-10 12:45:15 +02:00
|
|
|
import QtQml
|
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
2022-05-05 13:02:54 +02:00
|
|
|
import ScreenPlayWallpaper
|
|
|
|
import ScreenPlay.Enums.InstalledType
|
|
|
|
import ScreenPlay.Enums.VideoCodec
|
2020-09-13 19:51:20 +02:00
|
|
|
|
2019-03-28 21:25:39 +01:00
|
|
|
Rectangle {
|
2019-06-09 12:21:03 +02:00
|
|
|
id: root
|
2021-05-16 19:37:55 +02:00
|
|
|
|
|
|
|
property bool canFadeByWallpaperFillMode: true
|
|
|
|
|
|
|
|
function init() {
|
2023-02-02 15:25:26 +01:00
|
|
|
fadeInImageSetup();
|
2021-05-16 19:37:55 +02:00
|
|
|
switch (Wallpaper.type) {
|
|
|
|
case InstalledType.VideoWallpaper:
|
2021-11-01 18:25:46 +01:00
|
|
|
if (Wallpaper.videoCodec === VideoCodec.Unknown) {
|
2023-02-02 15:25:26 +01:00
|
|
|
Wallpaper.terminate();
|
2021-10-23 10:35:15 +02:00
|
|
|
}
|
2022-10-10 11:35:41 +02:00
|
|
|
|
2021-11-01 18:25:46 +01:00
|
|
|
// macOS only supports h264 via the native Qt MM
|
2021-11-13 14:26:48 +01:00
|
|
|
if (Qt.platform.os === "osx") {
|
2023-02-02 15:25:26 +01:00
|
|
|
if ((Wallpaper.videoCodec === VideoCodec.VP8 || Wallpaper.videoCodec === VideoCodec.VP9)) {
|
|
|
|
loader.source = "qrc:/qml/ScreenPlayWallpaper/qml/MultimediaWebView.qml";
|
2021-11-13 14:26:48 +01:00
|
|
|
} else {
|
2023-02-02 15:25:26 +01:00
|
|
|
loader.source = "qrc:/qml/ScreenPlayWallpaper/qml/MultimediaView.qml";
|
2021-11-13 14:26:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Qt.platform.os === "windows") {
|
2023-02-02 15:25:26 +01:00
|
|
|
loader.source = "qrc:/qml/ScreenPlayWallpaper/qml/MultimediaView.qml";
|
2021-10-23 10:35:15 +02:00
|
|
|
}
|
2023-02-02 15:25:26 +01:00
|
|
|
break;
|
2021-05-16 19:37:55 +02:00
|
|
|
case InstalledType.HTMLWallpaper:
|
2023-02-02 15:25:26 +01:00
|
|
|
loader.setSource("qrc:/qml/ScreenPlayWallpaper/qml/WebsiteWallpaper.qml", {
|
|
|
|
"url": Qt.resolvedUrl(Wallpaper.projectSourceFileAbsolute)
|
|
|
|
});
|
|
|
|
break;
|
2021-05-16 19:37:55 +02:00
|
|
|
case InstalledType.QMLWallpaper:
|
2023-02-02 15:25:26 +01:00
|
|
|
loader.source = Qt.resolvedUrl(Wallpaper.projectSourceFileAbsolute);
|
|
|
|
break;
|
2021-05-16 19:37:55 +02:00
|
|
|
case InstalledType.WebsiteWallpaper:
|
2023-02-02 15:25:26 +01:00
|
|
|
loader.setSource("qrc:/qml/ScreenPlayWallpaper/qml/WebsiteWallpaper.qml", {
|
|
|
|
"url": Wallpaper.projectSourceFileAbsolute
|
|
|
|
});
|
|
|
|
break;
|
2021-05-16 19:37:55 +02:00
|
|
|
case InstalledType.GifWallpaper:
|
2023-02-02 15:25:26 +01:00
|
|
|
loader.setSource("qrc:/qml/ScreenPlayWallpaper/qml/GifWallpaper.qml", {
|
|
|
|
"source": Qt.resolvedUrl(Wallpaper.projectSourceFileAbsolute)
|
|
|
|
});
|
|
|
|
break;
|
2019-03-28 21:25:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-02 15:25:26 +01:00
|
|
|
function fadeInImageSetup() {
|
|
|
|
if (Qt.platform.os !== "windows") {
|
|
|
|
root.canFadeByWallpaperFillMode = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
imgCover.source = Qt.resolvedUrl("file:///" + Wallpaper.windowsDesktopProperties.wallpaperPath);
|
|
|
|
switch (Wallpaper.windowsDesktopProperties.wallpaperStyle) {
|
|
|
|
case 10:
|
|
|
|
imgCover.fillMode = Image.PreserveAspectCrop;
|
|
|
|
// We only support fade in for one screen
|
|
|
|
if (Wallpaper.activeScreensList.length !== 1)
|
|
|
|
return;
|
|
|
|
if (Wallpaper.width === 0)
|
|
|
|
return;
|
|
|
|
if (Wallpaper.width > Wallpaper.windowsDesktopProperties.defaultWallpaperSize.width)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Windows does some weird top margin if the Wallpaper
|
|
|
|
// is bigger than the monitor. So instead of centering
|
|
|
|
// it vertically it moves the wallpaper down by 1/3 of
|
|
|
|
// the remaining height.
|
|
|
|
// 1. Scale down the wallpaper based on the height.
|
|
|
|
// The default Windows 11 wallpaper C:\Windows\Web\Wallpaper\Windows\img19.jpg
|
|
|
|
// has a resoltion of 3841x2400 scaled down to 3440x2150,3 with a given monitor
|
|
|
|
// resolution of 3440x1440 resulting in a 2150,3 - 1440 = 710,3
|
|
|
|
// 710,3 / (1/3) = 236,767
|
|
|
|
const monitorWidth = Wallpaper.width;
|
|
|
|
const monitorHeight = Wallpaper.height;
|
|
|
|
const windowsWallpaperWidth = Wallpaper.windowsDesktopProperties.defaultWallpaperSize.width;
|
|
|
|
const windowsWallpapeHeight = Wallpaper.windowsDesktopProperties.defaultWallpaperSize.height;
|
|
|
|
|
|
|
|
// 1. Get scale factor:
|
|
|
|
// -> 3440 / 3840 = 0.8956
|
|
|
|
const scaleFactor = monitorWidth / windowsWallpaperWidth;
|
|
|
|
// 2. Scale down the default Windows wallpaper height (width stays the same for correct aspect ratio):
|
|
|
|
// -> 2400 * 0.8956 = 2149.4
|
|
|
|
const scaledDownDefaultWallpaperHeight = windowsWallpapeHeight * scaleFactor;
|
|
|
|
// 3. Calc offste
|
|
|
|
// -> 2150,3 - 1440 = 710,3
|
|
|
|
const offset = scaledDownDefaultWallpaperHeight - monitorHeight;
|
|
|
|
// 4. Calc the one third offset (topMargin)
|
|
|
|
// -> 710,3 * (1/3) = 236,767
|
|
|
|
const topMargin = Math.floor(offset * 0.3333333);
|
|
|
|
imgCover.anchors.topMargin = -topMargin;
|
|
|
|
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;
|
2023-01-22 16:27:18 +01:00
|
|
|
}
|
2023-02-02 15:25:26 +01:00
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
root.canFadeByWallpaperFillMode = false;
|
|
|
|
break;
|
|
|
|
}
|
2023-01-22 16:27:18 +01:00
|
|
|
}
|
|
|
|
|
2021-05-16 19:37:55 +02:00
|
|
|
function fadeIn() {
|
2023-02-02 15:25:26 +01:00
|
|
|
Wallpaper.setVisible(true);
|
2021-05-16 19:37:55 +02:00
|
|
|
if (canFadeByWallpaperFillMode && Wallpaper.canFade)
|
2023-02-02 15:25:26 +01:00
|
|
|
imgCover.state = "hideDefaultBackgroundImage";
|
2021-05-16 19:37:55 +02:00
|
|
|
else
|
2023-02-02 15:25:26 +01:00
|
|
|
imgCover.opacity = 0;
|
2021-05-16 19:37:55 +02:00
|
|
|
}
|
2019-03-28 21:25:39 +01:00
|
|
|
|
2021-05-16 19:37:55 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
color: {
|
|
|
|
if (Qt.platform.os !== "windows")
|
2023-02-02 15:25:26 +01:00
|
|
|
return "black";
|
2021-05-16 19:37:55 +02:00
|
|
|
else
|
2023-02-02 15:25:26 +01:00
|
|
|
return Wallpaper.windowsDesktopProperties.color;
|
2021-05-16 19:37:55 +02:00
|
|
|
}
|
2023-02-02 15:25:26 +01:00
|
|
|
|
2020-03-09 18:06:50 +01:00
|
|
|
Component.onCompleted: {
|
2023-02-02 15:25:26 +01:00
|
|
|
init();
|
2020-03-09 18:06:50 +01:00
|
|
|
}
|
|
|
|
|
2019-11-23 17:22:24 +01:00
|
|
|
Connections {
|
2020-03-25 21:29:01 +01:00
|
|
|
function onQmlExit() {
|
2021-05-16 19:37:55 +02:00
|
|
|
if (canFadeByWallpaperFillMode && Wallpaper.canFade)
|
2023-02-02 15:25:26 +01:00
|
|
|
imgCover.state = "exit";
|
2021-05-16 19:37:55 +02:00
|
|
|
else
|
2023-02-02 15:25:26 +01:00
|
|
|
Wallpaper.terminate();
|
2019-11-23 17:22:24 +01:00
|
|
|
}
|
2019-03-30 12:56:34 +01:00
|
|
|
|
2020-07-18 20:21:47 +02:00
|
|
|
function onQmlSceneValueReceived(key, value) {
|
2023-02-02 15:25:26 +01:00
|
|
|
var obj2 = 'import QtQuick; Item {Component.onCompleted: loader.item.' + key + ' = ' + value + '; }';
|
|
|
|
var newObject = Qt.createQmlObject(obj2.toString(), root, "err");
|
|
|
|
newObject.destroy(10000);
|
2019-11-23 17:22:24 +01:00
|
|
|
}
|
2020-07-18 20:21:47 +02:00
|
|
|
|
2020-08-11 20:18:34 +02:00
|
|
|
// Replace wallpaper with QML Scene
|
|
|
|
function onReloadQML(oldType) {
|
2023-02-02 15:25:26 +01:00
|
|
|
loader.sourceComponent = undefined;
|
|
|
|
loader.source = "";
|
|
|
|
Wallpaper.clearComponentCache();
|
|
|
|
loader.source = Qt.resolvedUrl(Wallpaper.projectSourceFileAbsolute);
|
2020-08-11 20:18:34 +02:00
|
|
|
}
|
|
|
|
|
2021-02-19 17:21:17 +01:00
|
|
|
// Replace wallpaper with GIF
|
|
|
|
function onReloadGIF(oldType) {
|
2023-02-02 15:25:26 +01:00
|
|
|
init();
|
2021-02-19 17:21:17 +01:00
|
|
|
}
|
|
|
|
|
2020-08-11 20:18:34 +02:00
|
|
|
// This function only gets called here (the same function
|
2021-11-12 14:56:22 +01:00
|
|
|
// is inside the MultimediaWebView.qml) when the previous Wallpaper type
|
2020-08-11 20:18:34 +02:00
|
|
|
// was not a video
|
|
|
|
function onReloadVideo(oldType) {
|
|
|
|
// We need to check if the old type
|
|
|
|
// was also Video not get called twice
|
2021-01-31 16:21:32 +01:00
|
|
|
if (oldType === InstalledType.VideoWallpaper)
|
2023-02-02 15:25:26 +01:00
|
|
|
return;
|
|
|
|
loader.source = "qrc:/qml/ScreenPlayWallpaper/qml/MultimediaView.qml";
|
2020-03-09 18:06:50 +01:00
|
|
|
}
|
2019-03-28 21:25:39 +01:00
|
|
|
|
2021-05-16 19:37:55 +02:00
|
|
|
target: Wallpaper
|
2019-03-28 21:25:39 +01:00
|
|
|
}
|
|
|
|
|
2019-06-12 16:54:05 +02:00
|
|
|
Loader {
|
|
|
|
id: loader
|
|
|
|
anchors.fill: parent
|
2021-02-28 12:46:56 +01:00
|
|
|
// QML Engine deadlocks in 5.15.2 when a loader cannot load
|
|
|
|
// an item. QApplication::quit(); waits for the destruction forever.
|
2021-10-23 10:35:15 +02:00
|
|
|
//asynchronous: true
|
2021-02-28 12:46:56 +01:00
|
|
|
onStatusChanged: {
|
2023-02-02 15:25:26 +01:00
|
|
|
if (loader.status === Loader.Ready) {
|
|
|
|
if (loader.item.ready)
|
|
|
|
root.fadeIn();
|
2023-01-22 16:27:18 +01:00
|
|
|
}
|
2021-02-28 12:46:56 +01:00
|
|
|
if (loader.status === Loader.Error) {
|
2023-02-02 15:25:26 +01:00
|
|
|
loader.source = "";
|
|
|
|
imgCover.state = "exit";
|
2021-02-28 12:46:56 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-12 16:54:05 +02:00
|
|
|
}
|
2019-03-28 21:25:39 +01:00
|
|
|
|
|
|
|
Image {
|
|
|
|
id: imgCover
|
2021-04-21 18:13:47 +02:00
|
|
|
state: "showDefaultBackgroundImage"
|
2020-07-18 20:21:47 +02:00
|
|
|
sourceSize.width: Wallpaper.width
|
|
|
|
sourceSize.height: Wallpaper.height
|
2023-02-02 15:25:26 +01:00
|
|
|
|
2021-05-16 19:37:55 +02:00
|
|
|
anchors {
|
|
|
|
top: parent.top
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
}
|
|
|
|
|
2019-11-23 17:22:24 +01:00
|
|
|
states: [
|
|
|
|
State {
|
2021-04-21 18:13:47 +02:00
|
|
|
name: "showDefaultBackgroundImage"
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2019-11-23 17:22:24 +01:00
|
|
|
PropertyChanges {
|
|
|
|
target: imgCover
|
|
|
|
opacity: 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
2021-04-21 18:13:47 +02:00
|
|
|
name: "hideDefaultBackgroundImage"
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2019-11-23 17:22:24 +01:00
|
|
|
PropertyChanges {
|
|
|
|
target: imgCover
|
|
|
|
opacity: 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
2021-04-21 18:13:47 +02:00
|
|
|
name: "exit"
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2019-11-23 17:22:24 +01:00
|
|
|
PropertyChanges {
|
|
|
|
target: imgCover
|
|
|
|
opacity: 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
transitions: [
|
|
|
|
Transition {
|
2021-04-21 18:13:47 +02:00
|
|
|
from: "showDefaultBackgroundImage"
|
|
|
|
to: "hideDefaultBackgroundImage"
|
2019-11-23 17:22:24 +01:00
|
|
|
reversible: true
|
2021-04-21 18:13:47 +02:00
|
|
|
|
|
|
|
SequentialAnimation {
|
|
|
|
PauseAnimation {
|
|
|
|
duration: 100
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-21 18:13:47 +02:00
|
|
|
PropertyAnimation {
|
|
|
|
target: imgCover
|
|
|
|
duration: 600
|
|
|
|
property: "opacity"
|
|
|
|
}
|
2019-11-23 17:22:24 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
Transition {
|
2021-04-21 18:13:47 +02:00
|
|
|
from: "hideDefaultBackgroundImage"
|
|
|
|
to: "exit"
|
2019-11-23 17:22:24 +01:00
|
|
|
reversible: true
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2019-11-23 17:22:24 +01:00
|
|
|
SequentialAnimation {
|
|
|
|
PropertyAnimation {
|
|
|
|
target: imgCover
|
|
|
|
duration: 600
|
|
|
|
property: "opacity"
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2019-11-23 17:22:24 +01:00
|
|
|
ScriptAction {
|
2020-07-18 20:21:47 +02:00
|
|
|
script: Wallpaper.terminate()
|
2019-11-23 17:22:24 +01:00
|
|
|
}
|
2019-03-28 21:25:39 +01:00
|
|
|
}
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
]
|
2019-03-28 21:25:39 +01:00
|
|
|
}
|
2021-04-18 17:23:21 +02:00
|
|
|
|
|
|
|
Pane {
|
|
|
|
id: debug
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-18 17:23:21 +02:00
|
|
|
visible: Wallpaper.debugMode
|
|
|
|
enabled: Wallpaper.debugMode
|
2021-05-16 19:37:55 +02:00
|
|
|
width: parent.width * 0.3
|
|
|
|
height: parent.height * 0.3
|
2021-04-18 17:23:21 +02:00
|
|
|
anchors.centerIn: parent
|
|
|
|
|
|
|
|
Column {
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: 20
|
|
|
|
spacing: 10
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-18 17:23:21 +02:00
|
|
|
Text {
|
|
|
|
text: "appID " + Wallpaper.appID
|
|
|
|
font.pointSize: 14
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-18 17:23:21 +02:00
|
|
|
Text {
|
2021-05-14 12:50:22 +02:00
|
|
|
text: "projectPath " + Wallpaper.projectPath
|
2021-04-18 17:23:21 +02:00
|
|
|
font.pointSize: 14
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-18 17:23:21 +02:00
|
|
|
Text {
|
2021-12-11 17:05:41 +01:00
|
|
|
text: "getApplicationPath " + Wallpaper.getApplicationPath()
|
|
|
|
font.pointSize: 14
|
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
2023-02-02 15:25:26 +01:00
|
|
|
text: "projectSourceFileAbsolute " + Qt.resolvedUrl(Wallpaper.projectSourceFileAbsolute)
|
2021-04-18 17:23:21 +02:00
|
|
|
font.pointSize: 14
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-18 17:23:21 +02:00
|
|
|
Text {
|
|
|
|
text: "fillMode " + Wallpaper.fillMode
|
|
|
|
font.pointSize: 14
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-18 17:23:21 +02:00
|
|
|
Text {
|
|
|
|
text: "sdk.type " + Wallpaper.sdk.type
|
|
|
|
font.pointSize: 14
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-18 17:23:21 +02:00
|
|
|
Text {
|
|
|
|
text: "sdk.isConnected " + Wallpaper.sdk.isConnected
|
|
|
|
font.pointSize: 14
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-18 17:23:21 +02:00
|
|
|
Text {
|
|
|
|
text: "sdk.appID " + Wallpaper.sdk.appID
|
|
|
|
font.pointSize: 14
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-21 18:13:47 +02:00
|
|
|
Text {
|
|
|
|
text: "canFadeByWallpaperFillMode " + canFadeByWallpaperFillMode
|
|
|
|
font.pointSize: 14
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-21 18:13:47 +02:00
|
|
|
Text {
|
|
|
|
text: "Wallpaper.canFade " + Wallpaper.canFade
|
|
|
|
font.pointSize: 14
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-21 18:13:47 +02:00
|
|
|
Text {
|
2021-05-18 17:26:02 +02:00
|
|
|
text: {
|
|
|
|
if (Qt.platform.os === "windows")
|
2023-02-02 15:25:26 +01:00
|
|
|
return "imgCover.source " + Qt.resolvedUrl("file:///" + Wallpaper.windowsDesktopProperties.wallpaperPath);
|
2021-12-11 17:05:41 +01:00
|
|
|
else
|
2023-02-02 15:25:26 +01:00
|
|
|
return "";
|
2021-05-18 17:26:02 +02:00
|
|
|
}
|
2021-04-21 18:13:47 +02:00
|
|
|
font.pointSize: 14
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
|
2021-04-21 18:13:47 +02:00
|
|
|
Text {
|
|
|
|
text: "imgCover.status " + imgCover.status
|
|
|
|
font.pointSize: 14
|
|
|
|
}
|
2021-05-16 19:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
opacity: 0.5
|
2021-04-18 17:23:21 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-28 21:25:39 +01:00
|
|
|
}
|