1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-02 08:39:49 +02:00

Add a way easier way to debug wallpaper and widgets

This commit is contained in:
Elias 2019-03-27 18:38:36 +01:00
parent 9b606a79bc
commit 6b370d57ba
18 changed files with 225 additions and 291 deletions

View File

@ -1,6 +1,7 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>assets/image/noisy-texture-3.png</file>
<file>test.qml</file>
<file>mainWidget.qml</file>
</qresource>
</RCC>

View File

@ -1,21 +1,15 @@
QT += quick qml quickcontrols2 core widgets gui
CONFIG += c++17
CONFIG += qtquickcompiler
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
src/widgetwindow.cpp
HEADERS += \
src/widgetwindow.h
RESOURCES += \
SPWidgetResources.qrc
@ -26,8 +20,8 @@ INCLUDEPATH += \
include(../ScreenPlaySDK/Screenplaysdk.pri)
macx: {
QMAKE_LIBDIR += $$OUT_PWD/
install_it.path = $${OUT_PWD}/../ScreenPlaySDK
QMAKE_LIBDIR += $$OUT_PWD/
install_it.path = $${OUT_PWD}/../ScreenPlaySDK
}
!macx: {
@ -42,19 +36,3 @@ install_it.path = $${OUT_PWD}/../ScreenPlaySDK
}
QMAKE_LIBDIR += $$OUT_PWD/../ScreenPlaySDK
}
# Additional import path used to resolve QML modules just for Qt Quick Designer
# QML_DESIGNER_IMPORT_PATH =
QT_QUICK_CONTROLS_STYLE = "Material"
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
HEADERS += \
src/widgetwindow.h

View File

@ -14,12 +14,10 @@ int main(int argc, char* argv[])
QStringList argumentList = app.arguments();
// If we start with only one argument (app path)
// It means we want to test a single widget
// If we start with only one argument (app path),
// it means we want to test a single widget
if (argumentList.length() == 1) {
// Todo generic widget
WidgetWindow spwmw("D:/672870/xkcd","appid" );
WidgetWindow spwmw("test","appid" );
return app.exec();
}

View File

@ -1,7 +1,8 @@
import QtQuick 2.12
import net.aimber.screenplaysdk 1.0
import QtQuick.Controls 2.3
import net.aimber.screenplaysdk 1.0
Item {
id: mainWindow
visible: true
@ -22,27 +23,54 @@ Item {
opacity: .05
fillMode: Image.Tile
}
Loader {
id: loader
anchors.fill: parent
asynchronous: true
source: {
Qt.resolvedUrl(window.sourcePath)
}
onStatusChanged: {
if (loader.status === Loader.Ready) {
}
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
onPressed: {
backend.setClickPos(Qt.point(mouse.x, mouse.y))
window.setClickPos(Qt.point(mouse.x, mouse.y))
}
onPositionChanged: {
backend.setPos(mouse.x, mouse.y)
window.setPos(mouse.x, mouse.y)
}
onClicked: {
if (mouse.button === Qt.RightButton) {
contextMenu.popup()
}
}
}
Menu {
id: contextMenu
MenuItem {
text: qsTr("Close Widget")
onClicked: {
Qt.quit()
}
}
}
Connections {
target: backend
target: window
onSetWidgetSource: {
loader.source = Qt.resolvedUrl("file:///" + source)
print(loader.source)
}
onQmlSceneValueReceived: {
var obj2 = 'import QtQuick 2.12; Item {Component.onCompleted: loader.item.'
@ -52,14 +80,5 @@ Item {
}
}
Loader {
id: loader
anchors.fill: parent
asynchronous: true
onStatusChanged: {
if (loader.status === Loader.Ready) {
}
}
}
}

View File

@ -13,32 +13,39 @@ WidgetWindow::WidgetWindow(QString projectPath, QString appid, QObject* parent)
m_window.setWidth(300);
m_window.setHeight(300);
m_window.setFlags(flags | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::BypassWindowManagerHint | Qt::SplashScreen);
QFile configTmp;
QJsonDocument configJsonDocument;
QJsonParseError parseError;
configTmp.setFileName(projectPath + "/project.json");
configTmp.open(QIODevice::ReadOnly | QIODevice::Text);
m_projectConfig = configTmp.readAll();
configJsonDocument = QJsonDocument::fromJson(m_projectConfig.toUtf8(), &parseError);
if (!(parseError.error == QJsonParseError::NoError)) {
qWarning("Settings Json Parse Error ");
}
m_project = configJsonDocument.object();
QString fullPath = projectPath + "/" + m_project.value("file").toString();
m_window.rootContext()->setContextProperty("backend", this);
m_window.rootContext()->setContextProperty("window", this);
m_window.setColor(Qt::transparent);
m_window.setSource(QUrl("qrc:/main.qml"));
#ifdef Q_OS_WIN
SetWindowBlur(m_hwnd);
#endif
if (projectPath != "test") {
QFile configTmp;
QJsonDocument configJsonDocument;
QJsonParseError parseError;
configTmp.setFileName(projectPath + "/project.json");
configTmp.open(QIODevice::ReadOnly | QIODevice::Text);
m_projectConfig = configTmp.readAll();
configJsonDocument = QJsonDocument::fromJson(m_projectConfig.toUtf8(), &parseError);
if (!(parseError.error == QJsonParseError::NoError)) {
qWarning("Settings Json Parse Error ");
}
m_project = configJsonDocument.object();
QString fullPath = "file:///" + projectPath + "/" + m_project.value("file").toString();
setSourcePath(fullPath);
} else {
setSourcePath("qrc:/test.qml");
}
// Instead of setting "renderType: Text.NativeRendering" every time
// we can set it here once :)
m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering);
m_window.setSource(QUrl("qrc:/mainWidget.qml"));
m_window.show();
emit setWidgetSource(fullPath);
}
void WidgetWindow::setSize(QSize size)

View File

@ -8,6 +8,7 @@
#include <QPoint>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickWindow>
#include <QSharedPointer>
#include <QString>
@ -28,6 +29,7 @@ public:
Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged)
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
Q_PROPERTY(QString projectConfig READ projectConfig WRITE setProjectConfig NOTIFY projectConfigChanged)
Q_PROPERTY(QString sourcePath READ sourcePath WRITE setSourcePath NOTIFY sourcePathChanged)
QString appID() const
{
@ -44,17 +46,24 @@ public:
return m_projectConfig;
}
QString sourcePath() const
{
return m_sourcePath;
}
signals:
void appIDChanged(QString appID);
void typeChanged(QString type);
void projectConfigChanged(QString projectConfig);
void setWidgetSource(QString source);
void sourcePathChanged(QString sourcePath);
void qmlSceneValueReceived(QString key, QString value);
public slots:
void setSize(QSize size);
void destroyThis();
void messageReceived(QString key, QString value);
void setAppID(QString appID)
{
if (m_appID == appID)
@ -85,15 +94,25 @@ public slots:
#ifdef Q_OS_WIN
void SetWindowBlur(HWND hWnd);
#endif
void setSourcePath(QString sourcePath)
{
if (m_sourcePath == sourcePath)
return;
m_sourcePath = sourcePath;
emit sourcePathChanged(m_sourcePath);
}
private:
QString m_appID;
QString m_type = "qmlWidget";
QString m_projectConfig;
QJsonObject m_project;
#ifdef Q_OS_WIN
#ifdef Q_OS_WIN
HWND m_hwnd;
#endif
#endif
QPoint m_clickPos = { 0, 0 };
QQuickView m_window;
QString m_sourcePath;
};

25
ScreenPlayWidget/test.qml Normal file
View File

@ -0,0 +1,25 @@
import QtQuick 2.12
Rectangle {
anchors.fill: parent
color: "#80000000"
Text {
id: name
text: qsTr("This is a empty test widget. You can change the source in test.qml")
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
anchors.fill: parent
anchors.margins: 10
color: "white"
}
}
/*##^## Designer {
D{i:0;autoSize:true;height:480;width:640}
}
##^##*/

View File

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>qml/main.qml</file>
<file>mainWindow.qml</file>
<file>test.qml</file>
</qresource>
</RCC>

View File

@ -2,22 +2,28 @@ TEMPLATE = app
QT += qml quick quickcontrols2 widgets core webengine
CONFIG += c++17
msvc: LIBS += -luser32
DEFINES += QT_DEPRECATED_WARNINGS
TARGETPATH = ScreenPlayWindow
SOURCES += \
#src/SPWmainwindow.cpp \
main.cpp \
src/basewindow.cpp \
src/windowsdesktopproperties.cpp \
src/winwindow.cpp
HEADERS += \
#src/SPWmainwindow.h \
src/basewindow.h \
src/windowsdesktopproperties.h \
src/winwindow.h
win32 {
LIBS += -luser32
SOURCES += \
src/windowsdesktopproperties.cpp \
src/winwindow.cpp
HEADERS += \
src/windowsdesktopproperties.h \
src/winwindow.h
}
RESOURCES += \
SPWResources.qrc
@ -62,19 +68,3 @@ macx: {
index.html
}
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
QT_QUICK_CONTROLS_STYLE = "Material"
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

View File

@ -1,13 +1,20 @@
#include "../ScreenPlaySDK/screenplaysdk.h"
#include <QApplication>
#include <QObject>
#include <QStringList>
#include <QtGlobal>
#include <QtWebEngine>
#if defined(Q_OS_WIN)
#include "src/winwindow.h"
#endif
#include <QApplication>
#include <QObject>
#include <QStringList>
#include <QtWebEngine>
#if defined(Q_OS_OSX)
// TODO MAC OSX PORT HERE
#endif
#include "../ScreenPlaySDK/screenplaysdk.h"
int main(int argc, char* argv[])
{
@ -15,15 +22,22 @@ int main(int argc, char* argv[])
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QStringList argumentList = app.arguments();
// This gives us nice clickable output in QtCreator
qSetMessagePattern("%{if-category}%{category}: %{endif}%{message}\n Loc: [%{file}:%{line}]");
// Qt < 6.0 needs this init QtWebEngine
QtWebEngine::initialize();
// If we start with only one argument (app path)
// It means we want to test a single wallpaper
QStringList argumentList = app.arguments();
if (argumentList.length() == 1) {
QVector<int> list;
list.append(0);
WinWindow window(list, "D:/672870/_tmp_135011", "appid", "1");
#if defined(Q_OS_WIN)
WinWindow window(list, "test", "appid", "1");
#endif
return app.exec();
}
@ -66,5 +80,13 @@ int main(int argc, char* argv[])
QObject::connect(&sdk, &ScreenPlaySDK::incommingMessage, &window, &WinWindow::messageReceived);
#endif
#if defined(Q_OS_OSX)
// TODO MAC OSX PORT HERE
// QObject::connect(&sdk, &ScreenPlaySDK::sdkDisconnected, &TODO, &TODO::destroyThis);
// QObject::connect(&sdk, &ScreenPlaySDK::incommingMessage, &TODO, &TODO::messageReceived);
#endif
return app.exec();
}

View File

@ -1,167 +0,0 @@
import QtQuick 2.12
import QtWebEngine 1.7
import net.aimber.wallpaper 1.0
Rectangle {
anchors.fill: parent
color: desktopProperties.color
property bool canFadeIn: true
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.enabled = true
webView.url = Qt.resolvedUrl("file:///" + window.getApplicationPath(
) + "/index.html")
break
case Wallpaper.WallpaperType.Html:
webView.enabled = true
webView.url = Qt.resolvedUrl("file:///" + window.fullContentPath)
break
case Wallpaper.WallpaperType.ThreeJSScene:
webView.enabled = true
break
case Wallpaper.WallpaperType.Qml:
loader.source = Qt.resolvedUrl("file:///" + window.fullContentPath)
break
}
fadeIn()
}
function fadeIn() {
window.setVisible(true)
if (canFadeIn) {
animFadeIn.start()
} else {
imgCover.opacity = 0
}
}
WebEngineView {
id: webView
enabled: false
anchors.fill: parent
onLoadProgressChanged: {
if (loadProgress === 100) {
var src = ""
src += "var videoPlayer = document.getElementById('videoPlayer');"
src += "var videoSource = document.getElementById('videoSource');"
src += "videoSource.src = 'file:///" + window.fullContentPath + "';"
src += "videoPlayer.load();"
src += "videoPlayer.volume = " + window.volume + ";"
src += "videoPlayer.play();"
webView.runJavaScript(src, function () {
fadeIn()
})
}
}
}
Loader {
id: loader
anchors.fill: parent
}
OpacityAnimator {
id: animFadeIn
target: imgCover
from: 1
to: 0
duration: 300
easing.type: Easing.InCubic
running: true
}
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();")
}
}
}
}
}

View File

@ -11,6 +11,12 @@ BaseWindow::BaseWindow(QString projectFilePath, QObject* parent)
qRegisterMetaType<BaseWindow::WallpaperType>();
qmlRegisterType<BaseWindow>("net.aimber.wallpaper", 1, 0, "Wallpaper");
if (projectFilePath == "test") {
setType(BaseWindow::WallpaperType::Qml);
setFullContentPath("qrc:/test.qml");
return;
}
QFile projectFile;
QJsonDocument configJsonDocument;
QJsonParseError parseError;
@ -48,7 +54,7 @@ BaseWindow::BaseWindow(QString projectFilePath, QObject* parent)
qFatal("No type was specified inside the json object!");
}
setFullContentPath(projectFilePath + "/" + projectObject.value("file").toString());
setFullContentPath("file:///" + projectFilePath + "/" + projectObject.value("file").toString());
if (projectObject.value("type") == "video") {
setType(BaseWindow::WallpaperType::Video);

View File

@ -1,13 +1,13 @@
#pragma once
#include <QApplication>
#include <QDebug>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonParseError>
#include <QObject>
#include <QDebug>
#include <QString>
#include <QApplication>
#include <qqml.h>
class BaseWindow : public QObject {
@ -81,8 +81,12 @@ signals:
public slots:
virtual void destroyThis() {}
virtual void setVisible(bool show) {Q_UNUSED(show)}
virtual void messageReceived(QString key, QString value){Q_UNUSED(key);Q_UNUSED(value)}
virtual void setVisible(bool show) { Q_UNUSED(show) }
virtual void messageReceived(QString key, QString value)
{
Q_UNUSED(key);
Q_UNUSED(value)
}
QString getApplicationPath()
{

View File

@ -1,7 +1,7 @@
#include "macintegration.h"
#include "macbridge.h"
MacIntegration::MacIntegration(QObject *parent)
MacIntegration::MacIntegration(QObject* parent)
: QObject(parent)
{
MacBridge::instance();

View File

@ -1,15 +1,10 @@
#ifndef MACINTEGRATION_H
#define MACINTEGRATION_H
#pragma oncer
#include <QApplication>
class MacIntegration : public QObject
{
class MacIntegration : public QObject {
Q_OBJECT
public:
explicit MacIntegration(QObject *parent);
explicit MacIntegration(QObject* parent);
void SetBackgroundLevel(QWindow* window);
};
#endif // MACINTEGRATION_H

View File

@ -17,6 +17,10 @@ WinWindow::WinWindow(QVector<int>& activeScreensList, QString projectPath, QStri
: BaseWindow(projectPath)
{
m_windowHandle = reinterpret_cast<HWND>(m_window.winId());
if(!IsWindow(m_windowHandle)){
qFatal("Could not get a valid window handle!");
}
setAppID(id);
bool ok = false;
@ -50,16 +54,25 @@ WinWindow::WinWindow(QVector<int>& activeScreensList, QString projectPath, QStri
m_window.setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
m_window.rootContext()->setContextProperty("window", this);
m_window.rootContext()->setContextProperty("desktopProperties", &m_windowsDesktopProperties);
m_window.setSource(QUrl("qrc:/qml/main.qml"));
// Instead of setting "renderType: Text.NativeRendering" every time
// we can set it here once :)
m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering);
m_window.setSource(QUrl("qrc:/mainWindow.qml"));
// Let QML decide when were are read to show the window
ShowWindow(m_windowHandle, SW_HIDE);
//ShowWindow(m_windowHandle, SW_HIDE);
}
void WinWindow::setVisible(bool show)
{
if (show) {
ShowWindow(m_windowHandle, SW_SHOW);
if(!IsWindowVisible(m_windowHandle)){
qFatal("Could net set window visible!");
}
} else {
ShowWindow(m_windowHandle, SW_HIDE);
}
@ -79,7 +92,6 @@ void WinWindow::destroyThis()
void WinWindow::messageReceived(QString key, QString value)
{
}
void WinWindow::calcOffsets()

View File

@ -7,16 +7,15 @@
#include <QQmlEngine>
#include <QQuickView>
#include <QScreen>
#include <QVector>
#include <memory>
#include "windowsdesktopproperties.h"
#include <QSettings>
#include <QString>
#include <QVector>
#include <memory>
#include <qt_windows.h>
#include "basewindow.h"
#include "windowsdesktopproperties.h"
class WinWindow : public BaseWindow {
Q_OBJECT

25
ScreenPlayWindow/test.qml Normal file
View File

@ -0,0 +1,25 @@
import QtQuick 2.12
import QtQuick.Controls.Material 2.12
Rectangle {
anchors.fill: parent
color: Material.color(Material.Grey, Material.Shade800)
Text {
id: name
text: qsTr("This is a empty test window. You can change the source in test.qml")
font.pointSize: 32
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
anchors.fill: parent
anchors.margins: 10
color: "white"
}
}
/*##^## Designer {
D{i:0;autoSize:true;height:480;width:640}
}
##^##*/