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

More settings save reworking

This commit is contained in:
Elias Steurer 2020-07-30 21:36:40 +02:00
parent 281c3cf639
commit e1b40a7d4c
28 changed files with 519 additions and 326 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16.0)
cmake_minimum_required(VERSION 3.17 )
project(ScreenPlay)
project(ScreenPlay LANGUAGES CXX)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)

View File

@ -1,6 +1,6 @@
import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.2
import QtQuick.Controls 2.2 as QQC
import ScreenPlay 1.0
Item {
@ -9,11 +9,7 @@ Item {
property string headline: "dummyHeandline"
property string iconSource: "qrc:/assets/icons/icon_volume.svg"
property alias value: slider.value
property alias from: slider.from
property alias to: slider.to
property alias stepSize: slider.stepSize
property alias slider: slider
Text {
id: txtHeadline
@ -48,14 +44,14 @@ Item {
Layout.alignment: Qt.AlignVCenter
}
Slider {
QQC.Slider {
id: slider
stepSize: 0.01
from: 0
value: 1
to: 1
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
to: 1
}
Text {

View File

@ -269,7 +269,7 @@ Item {
availableHeight: height
fontSize: 11
onActiveMonitorsChanged: {
if(isWidget()){
if (isWidget()) {
btnSetWallpaper.enabled = true
return
}
@ -281,10 +281,13 @@ Item {
SP.Slider {
id: sliderVolume
stepSize: 0.01
from: 0
value: 1
to: 1
slider {
stepSize: 0.01
from: 0
value: 1
to: 1
}
Layout.fillWidth: true
headline: qsTr("Set Volume")
}
@ -374,12 +377,14 @@ Item {
ScreenPlay.screenPlayManager.createWallpaper(
root.type, cbVideoFillMode.currentValue,
absoluteStoragePath, previewImage,
screenFile, activeMonitors, volume, true)
screenFile, activeMonitors, volume,
1.0, {}, true)
}
if (root.isWidget()) {
ScreenPlay.screenPlayManager.createWidget(
type, Qt.point(0,0), absoluteStoragePath, previewImage, true)
type, Qt.point(0, 0), absoluteStoragePath,
previewImage, {}, true)
}
root.state = "inactive"

View File

@ -30,20 +30,24 @@ ColumnLayout {
SP.Slider {
headline: qsTr("Volume")
onValueChanged: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
activeMonitorIndex, "volume", value)
slider.onMoved: {
print("MODEV")
ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
activeMonitorIndex, "volume", slider.value)
}
Layout.fillWidth: true
}
SP.Slider {
headline: qsTr("Playback rate")
onValueChanged: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
activeMonitorIndex, "playbackRate", value)
slider.onMoved: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
activeMonitorIndex, "playbackRate", slider.value)
Layout.fillWidth: true
}
SP.Slider {
headline: qsTr("Current Video Time")
onValueChanged: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
activeMonitorIndex, "currentTime", value)
slider.onMoved: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
activeMonitorIndex, "currentTime", slider.value)
Layout.fillWidth: true
}
ColumnLayout {
@ -93,7 +97,7 @@ ColumnLayout {
"text": qsTr("Cover")
}, {
"value": FillMode.Scale_Down,
"text": qsTr("Scale-Down")
"text": qsTr("Scale_Down")
}]
}
}

View File

@ -96,24 +96,8 @@ Item {
}
Connections {
target: ScreenPlay.screenPlayManager
function onProjectSettingsListModelResult(found, listModel, type) {
customPropertiesGridView.model = null
if (!found) {
videoControlWrapper.state = "hidden"
customPropertiesGridView.state = "hidden"
return
}
videoControlWrapper.state = "visible"
function onProjectSettingsListModelResult(listModel) {
customPropertiesGridView.model = listModel
if (type === InstalledType.VideoWallpaper) {
customPropertiesGridView.state = "hidden"
videoControlWrapper.state = "visible"
} else {
customPropertiesGridView.state = "visible"
videoControlWrapper.state = "hidden"
}
}
}
}
@ -181,19 +165,6 @@ Item {
left: itmLeftWrapper.right
}
DefaultVideoControls {
id: videoControlWrapper
activeMonitorIndex: monitors.activeMonitorIndex
anchors {
top: parent.top
topMargin: 10
right: parent.right
rightMargin: 20
left: parent.left
leftMargin: 20
}
}
GridView {
id: customPropertiesGridView
boundsBehavior: Flickable.DragOverBounds
@ -219,41 +190,6 @@ Item {
snapMode: ScrollBar.SnapOnRelease
policy: ScrollBar.AlwaysOn
}
states: [
State {
name: "visible"
PropertyChanges {
target: customPropertiesGridView
opacity: 1
z: 1
anchors.topMargin: 60
}
},
State {
name: "hidden"
PropertyChanges {
target: customPropertiesGridView
opacity: 0
z: -1
anchors.topMargin: -100
}
}
]
transitions: [
Transition {
from: "visible"
to: "hidden"
reversible: true
PropertyAnimation {
target: customPropertiesGridView
duration: 300
easing.type: Easing.InOutQuart
properties: "anchors.topMargin, opacity"
}
}
]
}
}
MouseArea {

View File

@ -5,7 +5,6 @@ import QtQuick.Dialogs 1.2
import QtQuick.Controls.Material 2.2
import QtQuick.Layouts 1.3
import ScreenPlay 1.0
Item {
@ -25,7 +24,8 @@ Item {
anchors.verticalCenter: parent.verticalCenter
font.family: ScreenPlay.settings.font
font.weight: Font.Normal
color: root.isHeadline ? Qt.darker(Material.foreground) : Material.foreground
color: root.isHeadline ? Qt.darker(
Material.foreground) : Material.foreground
anchors {
left: parent.left
@ -47,28 +47,33 @@ Item {
return
}
var obj = JSON.parse(root.value.toString())
if (root.isHeadline)
return
if (obj["text"]) {
txtDescription.text = obj["text"]
}
switch (obj["type"]) {
case "slider":
loader.sourceComponent = compSlider
loader.item.from = obj["from"]
loader.item.to = obj["to"]
loader.item.value = obj["value"]
loader.item.stepSize = obj["stepSize"]
break
case "bool":
loader.sourceComponent = compCheckbox
loader.item.value = obj["value"]
break
case "color":
loader.sourceComponent = compColorpicker
loader.item.value = obj["value"]
break
for (let item in root.value) {
// print(item.toString())
switch (item["type"]) {
case "slider":
loader.sourceComponent = compSlider
loader.item.from = obj["from"]
loader.item.to = obj["to"]
loader.item.value = obj["value"]
loader.item.stepSize = obj["stepSize"]
break
case "bool":
loader.sourceComponent = compCheckbox
loader.item.value = obj["value"]
break
case "color":
loader.sourceComponent = compColorpicker
loader.item.value = obj["value"]
break
}
if (item["text"]) {
txtDescription.text = obj["text"]
}
}
}
@ -88,7 +93,7 @@ Item {
right: parent.right
verticalCenter: parent.verticalCenter
}
onCheckedChanged: {
onCheckedChanged: {
ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
selectedMonitor, name, checkbox.checked)
}
@ -161,9 +166,9 @@ Item {
anchors {
verticalCenter: parent.verticalCenter
right:txtSliderValue.left
right: txtSliderValue.left
rightMargin: 20
left:parent.left
left: parent.left
leftMargin: 20
}
@ -176,7 +181,7 @@ Item {
}
Text {
id: txtSliderValue
color: Material.foreground
color: Material.foreground
horizontalAlignment: Text.AlignRight
font.family: ScreenPlay.settings.font
anchors {

View File

@ -12,4 +12,5 @@ Item {
anchors.fill: parent
}
}

View File

@ -101,7 +101,7 @@ namespace FillMode {
class GlobalVariables : public QObject {
Q_OBJECT
Q_PROPERTY(QVersionNumber version READ version)
Q_PROPERTY(QVersionNumber version READ version CONSTANT)
Q_PROPERTY(QUrl localStoragePath READ localStoragePath WRITE setLocalStoragePath NOTIFY localStoragePathChanged)
Q_PROPERTY(QUrl localSettingsPath READ localSettingsPath WRITE setLocalSettingsPath NOTIFY localSettingsPathChanged)
Q_PROPERTY(QUrl wallpaperExecutablePath READ wallpaperExecutablePath WRITE setWallpaperExecutablePath NOTIFY wallpaperExecutablePathChanged)

View File

@ -37,7 +37,6 @@
#include <QAbstractListModel>
#include <QApplication>
#include <QDebug>
#include <QApplication>
#include <QRect>
#include <QScreen>
#include <QSize>
@ -110,6 +109,12 @@ public:
std::optional<QString> getAppIDByMonitorIndex(const int index) const;
QRect getAbsoluteDesktopSize() const
{
auto* app = static_cast<QApplication*>(QApplication::instance());
return app->screens().at(0)->availableVirtualGeometry();
}
signals:
void monitorReloadCompleted();
void setNewActiveMonitor(int index, QString path);
@ -133,12 +138,6 @@ public slots:
reset();
}
QRect getAbsoluteDesktopSize() const
{
auto* app = static_cast<QApplication*>(QApplication::instance());
return app->screens().at(0)->availableVirtualGeometry();
}
private:
void loadMonitors();

View File

@ -34,7 +34,6 @@
#pragma once
#include "globalvariables.h"
#include <QDebug>
#include <QJsonArray>
#include <QJsonObject>
@ -44,6 +43,9 @@
#include <QVariant>
#include <QVariantList>
#include "globalvariables.h"
#include "util.h"
/*!
\class ProjectFile
\brief In ScreenPlay every Wallpaper, Scene or Widget has an project.json to store its configuration
@ -99,42 +101,14 @@ struct ProjectFile {
if (!obj.contains("type"))
return;
QString type = obj.value("type").toString();
if (type.endsWith("Wallpaper")) {
if (type.startsWith("video")) {
m_searchType = SearchType::SearchType::Wallpaper;
m_type = InstalledType::InstalledType::VideoWallpaper;
return;
}
m_searchType = SearchType::SearchType::Scenes;
if (type.startsWith("qml")) {
m_type = InstalledType::InstalledType::QMLWallpaper;
return;
}
if (type.startsWith("html")) {
m_type = InstalledType::InstalledType::HTMLWallpaper;
return;
}
if (type.startsWith("godot")) {
m_type = InstalledType::InstalledType::GodotWallpaper;
return;
}
auto type = Util::getInstalledTypeFromString(obj.value("type").toString());
if (!type) {
qWarning() << "Type could not parsed from: " << *type << folderName;
return;
}
if (type.endsWith("Widget")) {
m_searchType = SearchType::SearchType::Widget;
if (type.startsWith("qml")) {
m_type = InstalledType::InstalledType::QMLWidget;
return;
}
if (type.startsWith("html")) {
m_type = InstalledType::InstalledType::HTMLWidget;
return;
}
}
qWarning() << "Type could not parsed from: " << type << folderName;
m_type = *type;
m_searchType = Util::getSearchTypeFromInstalledType(m_type);
}
ProjectFile() { }

View File

@ -34,7 +34,12 @@
#pragma once
#include <QColor>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
#include <QUrl>
#include <QVariant>
namespace ScreenPlay {
@ -47,20 +52,107 @@ namespace ScreenPlay {
*/
struct ProjectSettingsListItem {
ProjectSettingsListItem(
const QString& name,
const bool isHeadline,
const QVariant& value)
struct IListItem {
//MOC complains otherwise WTF
bool operator!=(const IListItem& val)
{
m_name = name;
m_isHeadline = isHeadline;
m_value = value;
return true;
}
};
struct SliderItem : public IListItem {
Q_GADGET
Q_PROPERTY(double from MEMBER m_from)
Q_PROPERTY(double to MEMBER m_to)
Q_PROPERTY(double stepSize MEMBER m_stepSize)
Q_PROPERTY(double value MEMBER m_value)
public:
double m_from = { 0.0 };
double m_to = { 0.1 };
double m_stepSize = { 0.1 };
double m_value = { 0.0 };
};
struct ColorItem : public IListItem {
Q_GADGET
Q_PROPERTY(QColor color MEMBER m_color)
public:
QColor m_color = { QColor::fromRgb(0, 0, 0) };
};
struct CheckBoxItem : public IListItem {
Q_GADGET
Q_PROPERTY(bool value MEMBER m_value)
public:
bool m_value = { false };
};
struct FileItem : public IListItem {
Q_GADGET
Q_PROPERTY(QUrl file MEMBER m_file)
public:
QUrl m_file = {};
};
struct ProjectSettingsListItem {
Q_GADGET
Q_PROPERTY(IListItem item MEMBER m_item)
public:
ProjectSettingsListItem(
const QString& headline)
{
m_isHeadline = true;
m_key = headline;
}
QString m_name;
ProjectSettingsListItem(
const QString& key,
const QJsonObject& obj)
{
m_isHeadline = false;
m_key = key;
QString type = obj.value("type").toString();
qInfo() << type;
if (type == "slider") {
SliderItem item;
item.m_from = obj.value("from").toDouble(0);
item.m_to = obj.value("to").toDouble(1);
item.m_stepSize = obj.value("stepSize").toDouble(0.1);
item.m_value = obj.value("value").toDouble(1);
m_item = item;
return;
}
if (type == "file") {
FileItem item;
item.m_file = obj.value("file").toString();
m_item = item;
return;
}
if (type == "color") {
ColorItem item;
item.m_color = { obj.value("file").toString() };
m_item = item;
return;
}
if (type == "bool") {
CheckBoxItem item;
m_item = item;
return;
}
}
QString m_key;
bool m_isHeadline { false };
QVariant m_value;
IListItem m_item;
QVariant value() const
{
return m_value;
}
};
}

View File

@ -35,12 +35,40 @@ namespace ScreenPlay {
*/
/*!
Constructor
Constructor when loading properties from settings.json
*/
ProjectSettingsListModel::ProjectSettingsListModel(QString file, QObject* parent)
: QAbstractListModel(parent)
void ProjectSettingsListModel::init(const InstalledType::InstalledType& type, const QJsonObject& properties)
{
init(file);
if (type == InstalledType::InstalledType::VideoWallpaper) {
// beginInsertRows(QModelIndex(), m_projectSettings.size(), m_projectSettings.size());
// m_projectSettings.append("General");
// if (properties.contains("volume"))
// append({"slider", properties.value("volume")}=;
// if (properties.contains("playbackRate"))
// append("slider", properties.value("playbackRate").toObject());
// endInsertRows();
} else {
for (QJsonObject::const_iterator itParent = properties.begin(); itParent != properties.end(); itParent++) {
// The first object is always a category
const QJsonObject category = properties.value(itParent.key()).toObject();
beginInsertRows(QModelIndex(), m_projectSettings.size(), m_projectSettings.size());
m_projectSettings.append(ProjectSettingsListItem { itParent.key() });
endInsertRows();
// Children of this category
for (QJsonObject::const_iterator itChild = category.begin(); itChild != category.end(); itChild++) {
qInfo() << itChild.key() << itChild.value();
beginInsertRows(QModelIndex(), m_projectSettings.size(), m_projectSettings.size());
m_projectSettings.append(ProjectSettingsListItem {itChild.key(), itChild.value().toObject() });
endInsertRows();
}
}
}
}
int ProjectSettingsListModel::rowCount(const QModelIndex& parent) const
@ -63,7 +91,7 @@ QVariant ProjectSettingsListModel::data(const QModelIndex& index, int role) cons
if (index.row() < rowCount())
switch (role) {
case NameRole:
return m_projectSettings.at(rowIndex).m_name;
return m_projectSettings.at(rowIndex).m_key;
case IsHeadlineRole:
return m_projectSettings.at(rowIndex).m_isHeadline;
case ValueRole:
@ -86,45 +114,26 @@ QHash<int, QByteArray> ProjectSettingsListModel::roleNames() const
return roles;
}
/*!
Recursively loads the content of a project.json.
See also \l {https://kelteseth.gitlab.io/ScreenPlayDocs/project/project/} .
*/
void ProjectSettingsListModel::init(const QString& file)
QJsonObject ProjectSettingsListModel::getActiveSettingsJson()
{
if (auto config = Util::openJsonFileToObject(file)) {
QJsonObject obj = *config;
QJsonObject tmpParent;
if (obj.contains("properties")) {
tmpParent = obj.value("properties").toObject();
} else {
return;
}
QJsonObject::iterator itParent, itChild;
for (itParent = tmpParent.begin(); itParent != tmpParent.end(); itParent++) {
// The first object is always a category
QJsonObject tmpChildObj = tmpParent.value(itParent.key()).toObject();
append(itParent.key(), true, "");
// Children of this category
for (itChild = tmpChildObj.begin(); itChild != tmpChildObj.end(); itChild++) {
append(itChild.key(), false, QJsonDocument(tmpChildObj.value(itChild.key()).toObject()).toJson());
}
}
} else {
qWarning() << "Could not load: " << file << " for wallpaper settings!";
if (m_projectSettings.isEmpty()) {
qWarning() << "Trying to read emppty projectSettings. Abort!";
return {};
}
QJsonObject obj;
for (const auto& itemCategory : m_projectSettings) {
QJsonObject category;
if (itemCategory.m_isHeadline) {
for (const auto& itemProperties : m_projectSettings) {
if (itemProperties.m_isHeadline)
continue;
category.insert(itemProperties.m_key, QJsonValue::fromVariant(itemProperties.m_value));
}
obj.insert(itemCategory.m_key, category);
}
}
return obj;
}
void ProjectSettingsListModel::append(QString name, bool isHeadline, QVariant value)
{
beginInsertRows(QModelIndex(), m_projectSettings.size(), m_projectSettings.size());
ProjectSettingsListItem tmpFile(name, isHeadline, value.toString());
m_projectSettings.append(tmpFile);
endInsertRows();
}
}

View File

@ -52,8 +52,6 @@ class ProjectSettingsListModel : public QAbstractListModel {
Q_OBJECT
public:
explicit ProjectSettingsListModel(QString file, QObject* parent = nullptr);
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
@ -65,10 +63,8 @@ public:
};
Q_ENUM(ProjectSettingsRole)
void init(const QString& file);
public slots:
void append(QString name, bool isHeadline, QVariant value);
QJsonObject getActiveSettingsJson();
void init(const InstalledType::InstalledType& type, const QJsonObject& properties);
private:
QVector<ProjectSettingsListItem> m_projectSettings;

View File

@ -32,6 +32,15 @@ ScreenPlayManager::ScreenPlayManager(
if (!m_server->listen("ScreenPlay")) {
qCritical("Could not open Local Socket with the name ScreenPlay!");
}
// We limit the time we save via a Qtimer. This is because we can live update values like
// volume to the wallpaper very fast. This would be very imperformant for HDD user, so
// we limit ourself to m_saveLimiters interval below:
m_saveLimiter.setInterval(1000);
QObject::connect(&m_saveLimiter, &QTimer::timeout, this, &ScreenPlayManager::saveProfiles);
QObject::connect(this, &ScreenPlayManager::requestSaveProfiles, this, [this]() {
m_saveLimiter.start();
});
}
/*!
@ -76,20 +85,20 @@ void ScreenPlayManager::init(
a \a fillMode, a \a type (htmlWallpaper, qmlWallpaper etc.), a \a saveToProfilesConfigFile bool only set to flase
if we call the method when using via the settings on startup to skip a unnecessary save.
*/
void ScreenPlayManager::createWallpaper(
const InstalledType::InstalledType type,
void ScreenPlayManager::createWallpaper(const InstalledType::InstalledType type,
const FillMode::FillMode fillMode,
const QString& absoluteStoragePath,
const QString& previewImage,
const QString& file,
QVector<int> monitorIndex,
const QVector<int>& monitorIndex,
const float volume,
const float playbackRate, const QJsonObject& properties,
const bool saveToProfilesConfigFile)
{
auto saveToProfile = qScopeGuard([=, this] {
// Do not save on app start
if (saveToProfilesConfigFile) {
saveProfiles();
emit requestSaveProfiles();
}
});
@ -128,8 +137,7 @@ void ScreenPlayManager::createWallpaper(
}
}
std::shared_ptr<ScreenPlayWallpaper> wallpaper;
wallpaper = std::make_shared<ScreenPlayWallpaper>(
auto wallpaper = std::make_shared<ScreenPlayWallpaper>(
monitorIndex,
m_globalVariables,
appID,
@ -137,11 +145,13 @@ void ScreenPlayManager::createWallpaper(
previewImage,
file,
volume,
playbackRate,
fillMode,
type,
properties,
m_settings->checkWallpaperVisible());
QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestSave, this, &ScreenPlayManager::saveProfiles);
QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestSave, this, &ScreenPlayManager::requestSaveProfiles);
m_screenPlayWallpapers.append(wallpaper);
m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex);
increaseActiveWallpaperCounter();
@ -150,17 +160,17 @@ void ScreenPlayManager::createWallpaper(
/*!
\brief Creates a ScreenPlayWidget object via a \a absoluteStoragePath and a \a preview image (relative path).
*/
void ScreenPlayManager::createWidget(
const InstalledType::InstalledType type,
void ScreenPlayManager::createWidget(const InstalledType::InstalledType type,
const QPoint& position,
const QString& absoluteStoragePath,
const QString& previewImage,
const QJsonObject& properties,
const bool saveToProfilesConfigFile)
{
auto saveToProfile = qScopeGuard([=, this] {
// Do not save on app start
if (saveToProfilesConfigFile) {
saveProfiles();
emit requestSaveProfiles();
}
});
@ -171,8 +181,17 @@ void ScreenPlayManager::createWidget(
qInfo() << "Path is empty, Abort! String: " << absoluteStoragePath;
return;
}
auto widget = std::make_shared<ScreenPlayWidget>(appID, m_globalVariables, position, path, previewImage, type);
QObject::connect(widget.get(), &ScreenPlayWidget::requestSave, this, &ScreenPlayManager::saveProfiles);
auto widget = std::make_shared<ScreenPlayWidget>(
appID,
m_globalVariables,
position,
path,
previewImage,
properties,
type);
QObject::connect(widget.get(), &ScreenPlayWidget::requestSave, this, &ScreenPlayManager::requestSaveProfiles);
increaseActiveWidgetsCounter();
m_screenPlayWidgets.append(widget);
}
@ -207,7 +226,7 @@ void ScreenPlayManager::removeAllWallpapers()
m_monitorListModel->clearActiveWallpaper();
saveProfiles();
emit requestSaveProfiles();
setActiveWallpaperCounter(0);
if (activeWallpaperCounter() != m_screenPlayWallpapers.length()) {
if (m_telemetry) {
@ -233,7 +252,7 @@ void ScreenPlayManager::removeAllWidgets()
if (!m_screenPlayWidgets.empty()) {
closeAllWidgets();
m_screenPlayWidgets.clear();
saveProfiles();
emit requestSaveProfiles();
setActiveWidgetsCounter(0);
}
}
@ -247,7 +266,7 @@ bool ScreenPlayManager::removeWallpaperAt(int index)
{
if (auto appID = m_monitorListModel->getAppIDByMonitorIndex(index)) {
saveProfiles();
emit requestSaveProfiles();
if (!closeWallpaper(*appID)) {
qWarning() << "Could not close socket. Abort!";
@ -263,7 +282,7 @@ bool ScreenPlayManager::removeWallpaperAt(int index)
qWarning() << "Could not remove Wallpaper " << appIDCopy << " from wallpaper list!";
return false;
}
saveProfiles();
emit requestSaveProfiles();
return true;
}
if (m_telemetry) {
@ -282,13 +301,10 @@ void ScreenPlayManager::requestProjectSettingsAtMonitorIndex(const int index)
if (uPtrWallpaper->screenNumber()[0] == index) {
emit projectSettingsListModelResult(
true,
uPtrWallpaper->getProjectSettingsListModel(),
uPtrWallpaper->type());
uPtrWallpaper->getProjectSettingsListModel());
return;
}
}
emit projectSettingsListModelResult(false);
}
/*!
@ -340,7 +356,7 @@ void ScreenPlayManager::newConnection()
// Only after we receive the first message with appID and type we can set the shared reference to the
// ScreenPlayWallpaper or ScreenPlayWidgets class
QObject::connect(connection.get(), &SDKConnection::appConnected, this, [this](const SDKConnection* connection) {
for (const auto& client : m_clients) {
for (const auto& client : qAsConst(m_clients)) {
if (client.get() == connection) {
appConnected(client);
return;
@ -350,7 +366,6 @@ void ScreenPlayManager::newConnection()
m_clients.append(connection);
}
/*!
\brief Closes all wallpaper connection with the following type:
\list
@ -409,23 +424,23 @@ bool ScreenPlayManager::closeWallpaper(const QString& appID)
/*!
\brief Sets a given \a value to a given \a key. The \a appID is used to identify the receiver socket.
*/
void ScreenPlayManager::setWallpaperValue(QString appID, QString key, QString value)
void ScreenPlayManager::setWallpaperValue(const QString& appID, const QString& key, const QVariant& value)
{
for (const auto& wallpaper : m_screenPlayWallpapers) {
if (wallpaper->appID() == appID) {
wallpaper->setWallpaperValue(key, value);
wallpaper->setWallpaperValue(key, value, true);
}
}
}
/*!
\brief Saves a given wallpaper \a newProfileObject to a \a profileName. We ignore the profileName argument
because we currently only support one profile. Returns \c true if successfuly saved to profiles.json, otherwise \c false.
*/
void ScreenPlayManager::saveProfiles()
{
m_saveLimiter.stop();
qInfo() << "Save profiles!";
QJsonArray wallpaper {};
for (const auto& activeWallpaper : m_screenPlayWallpapers) {
wallpaper.append(activeWallpaper->getActiveSettingsJson());
@ -534,13 +549,15 @@ void ScreenPlayManager::loadProfiles()
const QString absolutePath = wallpaperObj.value("absolutePath").toString();
const QString fillModeString = wallpaperObj.value("fillMode").toString();
const QString previewImage = wallpaperObj.value("previewImage").toString();
const float playbackRate = wallpaperObj.value("playbackRate").toDouble(1.0);
const QString file = wallpaperObj.value("file").toString();
const QString typeString = wallpaperObj.value("type").toString();
const QJsonObject properties = wallpaperObj.value("properties").toObject();
const auto type = QStringToEnum<InstalledType::InstalledType>(typeString, InstalledType::InstalledType::VideoWallpaper);
const auto fillMode = QStringToEnum<FillMode::FillMode>(fillModeString, FillMode::FillMode::Cover);
createWallpaper(type, fillMode, absolutePath, previewImage, file, monitors, volume, false);
createWallpaper(type, fillMode, absolutePath, previewImage, file, monitors, volume, playbackRate, properties, false);
monitors.clear();
}
@ -557,8 +574,9 @@ void ScreenPlayManager::loadProfiles()
const int positionY = widgetObj.value("positionY").toInt(0);
const QPoint position { positionX, positionY };
const auto type = QStringToEnum<InstalledType::InstalledType>(typeString, InstalledType::InstalledType::QMLWidget);
const QJsonObject properties = widgetObj.value("properties").toObject();
createWidget(type, position, absolutePath, previewImage, false);
createWidget(type, position, absolutePath, previewImage, properties, false);
}
}
}

View File

@ -88,29 +88,34 @@ public:
const std::shared_ptr<Settings>& settings);
signals:
void projectSettingsListModelResult(
const bool found,
ProjectSettingsListModel* li = nullptr,
const ScreenPlay::InstalledType::InstalledType type = ScreenPlay::InstalledType::InstalledType::VideoWallpaper);
void projectSettingsListModelResult(ScreenPlay::ProjectSettingsListModel* li = nullptr);
void activeWallpaperCounterChanged(int activeWallpaperCounter);
void activeWidgetsCounterChanged(int activeWidgetsCounter);
void requestSaveProfiles();
void requestRaise();
private slots:
void saveProfiles();
public slots:
// moc needs full enum namespace info see QTBUG-58454
void createWallpaper(
const ScreenPlay::InstalledType::InstalledType type,
void createWallpaper(const ScreenPlay::InstalledType::InstalledType type,
const ScreenPlay::FillMode::FillMode fillMode,
const QString& absoluteStoragePath,
const QString& previewImage,
const QString& file,
QVector<int> monitorIndex,
const QVector<int>& monitorIndex,
const float volume,
const float playbackRate,
const QJsonObject& properties,
const bool saveToProfilesConfigFile);
void createWidget(const ScreenPlay::InstalledType::InstalledType type, const QPoint& position,
void createWidget(
const ScreenPlay::InstalledType::InstalledType type,
const QPoint& position,
const QString& absoluteStoragePath,
const QString& previewImage,
const QJsonObject& properties,
const bool saveToProfilesConfigFile);
void removeAllWallpapers();
@ -122,13 +127,12 @@ public slots:
void setAllWallpaperValue(const QString& key, const QString& value);
std::optional<std::shared_ptr<ScreenPlayWallpaper>> getWallpaperByAppID(const QString& appID);
void saveProfiles();
void newConnection();
void closeAllWallpapers();
void closeAllWidgets();
void closeConntectionByType(const QStringList& list);
bool closeWallpaper(const QString& appID);
void setWallpaperValue(QString appID, QString key, QString value);
void setWallpaperValue(const QString& appID, const QString& key, const QVariant& value);
void setActiveWallpaperCounter(int activeWallpaperCounter)
{
@ -198,6 +202,7 @@ private:
int m_activeWidgetsCounter { 0 };
bool m_isAnotherScreenPlayInstanceRunning = false;
QTimer m_saveLimiter;
};
}

View File

@ -13,20 +13,20 @@ namespace ScreenPlay {
/*!
\brief Constructor for video Wallpaper.
*/
ScreenPlayWallpaper::ScreenPlayWallpaper(
const QVector<int>& screenNumber,
ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
const std::shared_ptr<GlobalVariables>& globalVariables,
const QString& appID,
const QString& absolutePath,
const QString& previewImage,
const QString& file,
const float volume,
const float playbackRate,
const FillMode::FillMode fillMode,
const InstalledType::InstalledType type,
const QJsonObject& properties,
const bool checkWallpaperVisible,
QObject* parent)
: QObject(parent)
, m_projectSettingsListModel { absolutePath + "/project.json" }
, m_globalVariables { globalVariables }
, m_screenNumber { screenNumber }
, m_previewImage { previewImage }
@ -35,8 +35,30 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(
, m_appID { appID }
, m_absolutePath { absolutePath }
, m_file { file }
, m_playbackRate { playbackRate }
{
{
// If
QJsonObject projectSettingsListModelProperties;
if (type == InstalledType::InstalledType::VideoWallpaper) {
projectSettingsListModelProperties.insert("volume", m_volume);
projectSettingsListModelProperties.insert("playbackRate", m_playbackRate);
} else {
if (properties.isEmpty()) {
auto obj = Util::openJsonFileToObject(absolutePath + "/project.json");
if (!obj)
return;
if (!obj->contains("properties"))
return;
projectSettingsListModelProperties = obj->value("properties").toObject();
} else {
projectSettingsListModelProperties = properties;
}
}
m_projectSettingsListModel.init(type, projectSettingsListModelProperties);
}
QObject::connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &ScreenPlayWallpaper::processExit);
QObject::connect(&m_process, &QProcess::errorOccurred, this, &ScreenPlayWallpaper::processError);
@ -66,6 +88,7 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(
// Fixes issue 84 media key overlay
" --disable-features=HardwareMediaKeyHandling"
};
qInfo() << proArgs;
m_process.setArguments(proArgs);
m_process.setProgram(m_globalVariables->wallpaperExecutablePath().toString());
@ -80,14 +103,22 @@ QJsonObject ScreenPlayWallpaper::getActiveSettingsJson()
}
QJsonObject obj;
QJsonObject properties;
if (m_type == InstalledType::InstalledType::VideoWallpaper) {
obj.insert("fillMode", QVariant::fromValue(m_fillMode).toString());
obj.insert("isLooping", m_isLooping);
obj.insert("volume", m_volume);
obj.insert("playbackRate", m_playbackRate);
} else {
auto properties = m_projectSettingsListModel.getActiveSettingsJson();
if (!properties.isEmpty())
obj.insert("properties", properties);
}
obj.insert("file", m_file);
obj.insert("absolutePath", m_absolutePath);
obj.insert("fillMode", QVariant::fromValue(m_fillMode).toString());
obj.insert("isLooping", m_isLooping);
obj.insert("monitors", screenNumber);
obj.insert("previewImage", m_previewImage);
obj.insert("type", QVariant::fromValue(m_type).toString());
obj.insert("volume", m_volume);
return obj;
}
@ -109,23 +140,37 @@ void ScreenPlayWallpaper::processError(QProcess::ProcessError error)
qDebug() << "EX: " << error;
}
void ScreenPlayWallpaper::setWallpaperValue(const QString& key, const QString& value)
void ScreenPlayWallpaper::setWallpaperValue(const QString& key, const QVariant& value, const bool save)
{
QJsonObject obj;
obj.insert(key, value);
obj.insert(key, value.toString());
if (key == "volume") {
setVolume(value.toFloat());
}
if (key == "playbackRate") {
setPlaybackRate(value.toFloat());
}
if (key == "fillmode") {
setFillMode(QStringToEnum<FillMode::FillMode>(value.toString(), FillMode::FillMode::Cover));
}
m_connection->sendMessage(QJsonDocument(obj).toJson(QJsonDocument::Compact));
}
ProjectSettingsListModel* ScreenPlayWallpaper::getProjectSettingsListModel()
{
return &m_projectSettingsListModel;
qInfo() << "save" << save;
if (save)
emit requestSave();
}
void ScreenPlayWallpaper::setSDKConnection(const std::shared_ptr<SDKConnection>& connection)
{
m_connection = connection;
qInfo() << "App Wallpaper connected!";
qInfo() << playbackRate() << (playbackRate() != 1.0);
QTimer::singleShot(500, [this]() {
if (playbackRate() != 1.0) {
setWallpaperValue("playbackRate", playbackRate(), false);
}
});
}
void ScreenPlayWallpaper::replace(
@ -155,9 +200,8 @@ void ScreenPlayWallpaper::replace(
obj.insert("file", file);
obj.insert("checkWallpaperVisible", checkWallpaperVisible);
m_connection->sendMessage(QJsonDocument(obj).toJson(QJsonDocument::Compact));
emit requestSave();
}
}

View File

@ -44,6 +44,7 @@
#include "globalvariables.h"
#include "projectsettingslistmodel.h"
#include "sdkconnection.h"
#include "util.h"
namespace ScreenPlay {
@ -53,6 +54,7 @@ class ScreenPlayWallpaper : public QObject {
Q_PROPERTY(QVector<int> screenNumber READ screenNumber WRITE setScreenNumber NOTIFY screenNumberChanged)
Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged)
Q_PROPERTY(float playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged)
Q_PROPERTY(bool isLooping READ isLooping WRITE setIsLooping NOTIFY isLoopingChanged)
@ -65,22 +67,29 @@ class ScreenPlayWallpaper : public QObject {
Q_PROPERTY(InstalledType::InstalledType type READ type WRITE setType NOTIFY typeChanged)
public:
explicit ScreenPlayWallpaper(
const QVector<int>& screenNumber,
explicit ScreenPlayWallpaper(const QVector<int>& screenNumber,
const std::shared_ptr<GlobalVariables>& globalVariables,
const QString& appID,
const QString& absolutePath,
const QString& previewImage,
const QString& file,
const float volume,
const float volume, const float playbackRate,
const FillMode::FillMode fillMode,
const InstalledType::InstalledType type,
const InstalledType::InstalledType type, const QJsonObject& properties,
const bool checkWallpaperVisible,
QObject* parent = nullptr);
QJsonObject getActiveSettingsJson();
void replace(const QString& absolutePath,
const QString& previewImage,
const QString& file,
const float volume,
const FillMode::FillMode fillMode,
const InstalledType::InstalledType type,
const bool checkWallpaperVisible);
bool m_isAnotherScreenPlayInstanceRunning { false };
void setSDKConnection(const std::shared_ptr<SDKConnection>& connection);
QJsonObject getActiveSettingsJson();
QVector<int> screenNumber() const
{
@ -127,17 +136,15 @@ public:
return m_isLooping;
}
ProjectSettingsListModel* getProjectSettingsListModel();
ProjectSettingsListModel* getProjectSettingsListModel()
{
return &m_projectSettingsListModel;
}
void setSDKConnection(const std::shared_ptr<SDKConnection>& connection);
void replace(const QString& absolutePath,
const QString& previewImage,
const QString& file,
const float volume,
const FillMode::FillMode fillMode,
const InstalledType::InstalledType type,
const bool checkWallpaperVisible);
float playbackRate() const
{
return m_playbackRate;
}
signals:
void screenNumberChanged(QVector<int> screenNumber);
@ -151,11 +158,12 @@ signals:
void volumeChanged(float volume);
void isLoopingChanged(bool isLooping);
void requestSave();
void playbackRateChanged(float playbackRate);
public slots:
void processExit(int exitCode, QProcess::ExitStatus exitStatus);
void processError(QProcess::ProcessError error);
void setWallpaperValue(const QString &key, const QString &value);
void setWallpaperValue(const QString& key, const QVariant& value, const bool save = false);
void setScreenNumber(QVector<int> screenNumber)
{
@ -241,6 +249,15 @@ public slots:
emit isLoopingChanged(m_isLooping);
}
void setPlaybackRate(float playbackRate)
{
if (playbackRate < 0.0f || playbackRate > 1.0f)
return;
m_playbackRate = playbackRate;
emit playbackRateChanged(m_playbackRate);
}
private:
const std::shared_ptr<GlobalVariables>& m_globalVariables;
std::shared_ptr<SDKConnection> m_connection;
@ -256,5 +273,6 @@ private:
QString m_file;
float m_volume { 1.0f };
bool m_isLooping { true };
float m_playbackRate { 1.0f };
};
}

View File

@ -19,6 +19,7 @@ ScreenPlayWidget::ScreenPlayWidget(
const QPoint& position,
const QString& absolutePath,
const QString& previewImage,
const QJsonObject& properties,
const InstalledType::InstalledType type)
: QObject { nullptr }
, m_globalVariables { globalVariables }
@ -28,6 +29,25 @@ ScreenPlayWidget::ScreenPlayWidget(
, m_type { type }
, m_absolutePath { absolutePath }
{
{
// If
QJsonObject projectSettingsListModelProperties;
if (properties.isEmpty()) {
auto obj = Util::openJsonFileToObject(absolutePath + "/project.json");
if (!obj)
return;
if (!obj->contains("properties"))
return;
projectSettingsListModelProperties = obj->value("properties").toObject();
} else {
projectSettingsListModelProperties = properties;
}
m_projectSettingsListModel.init(type, projectSettingsListModelProperties);
}
const QStringList proArgs {
m_absolutePath,
QString { "appID=" + m_appID },
@ -39,8 +59,6 @@ ScreenPlayWidget::ScreenPlayWidget(
m_process.setArguments(proArgs);
m_process.setProgram(m_globalVariables->widgetExecutablePath().path());
qDebug() << proArgs;
QObject::connect(&m_process, &QProcess::errorOccurred, this, [](QProcess::ProcessError error) {
qDebug() << "error: " << error;
});
@ -62,6 +80,11 @@ void ScreenPlayWidget::setSDKConnection(const std::shared_ptr<SDKConnection>& co
QJsonObject ScreenPlayWidget::getActiveSettingsJson()
{
QJsonObject obj;
auto properties = m_projectSettingsListModel.getActiveSettingsJson();
if (!properties.isEmpty())
obj.insert("properties", properties);
obj.insert("previewImage", m_previewImage);
obj.insert("absolutePath", m_absolutePath);
obj.insert("positionX", m_position.x());

View File

@ -45,6 +45,7 @@
#include <memory>
#include "globalvariables.h"
#include "projectsettingslistmodel.h"
#include "sdkconnection.h"
namespace ScreenPlay {
@ -63,7 +64,7 @@ public:
const std::shared_ptr<GlobalVariables>& globalVariables,
const QPoint& position,
const QString& absolutePath,
const QString& previewImage,
const QString& previewImage, const QJsonObject& properties,
const InstalledType::InstalledType type);
~ScreenPlayWidget() { }
@ -98,6 +99,11 @@ public:
public slots:
QJsonObject getActiveSettingsJson();
ProjectSettingsListModel* getProjectSettingsListModel()
{
return &m_projectSettingsListModel;
}
void setPreviewImage(QString previewImage)
{
if (m_previewImage == previewImage)
@ -154,6 +160,7 @@ signals:
private:
const std::shared_ptr<GlobalVariables>& m_globalVariables;
std::shared_ptr<SDKConnection> m_connection;
ProjectSettingsListModel m_projectSettingsListModel;
QProcess m_process;
QString m_previewImage;

View File

@ -98,7 +98,7 @@ signals:
void typeChanged(QString type);
void requestDecreaseWidgetCount();
void requestRaise();
void appConnected(const SDKConnection* connection);
void appConnected(const ScreenPlay::SDKConnection* connection);
void jsonMessageReceived(const QJsonObject obj);
public slots:

View File

@ -197,9 +197,9 @@ signals:
void anonymousTelemetryChanged(bool anonymousTelemetry);
void checkWallpaperVisibleChanged(bool checkWallpaperVisible);
void videoFillModeChanged(ScreenPlay::FillMode::FillMode videoFillMode);
void languageChanged(Language language);
void languageChanged(ScreenPlay::Settings::Language language);
void fontChanged(QString font);
void themeChanged(Theme theme);
void themeChanged(ScreenPlay::Settings::Theme theme);
public slots:
void writeJsonFileFromResource(const QString& filename);
@ -325,7 +325,7 @@ public slots:
emit videoFillModeChanged(m_videoFillMode);
}
void setLanguage(Language language)
void setLanguage(ScreenPlay::Settings::Language language)
{
if (m_language == language)
return;
@ -345,7 +345,7 @@ public slots:
emit fontChanged(m_font);
}
void setTheme(Theme theme)
void setTheme(ScreenPlay::Settings::Theme theme)
{
if (m_theme == theme)
return;

View File

@ -175,7 +175,7 @@ bool Util::writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObj
QString Util::toString(const QStringList& list)
{
QString out;
for (const auto &string : list) {
for (const auto& string : list) {
out += " " + string;
}
return out;
@ -326,8 +326,8 @@ void Util::downloadFFMPEG()
ZipEntry entryFFMPEG;
std::string entryFFMPEGPath;
#ifdef Q_OS_WIN
entryFFMPEG = archive->getEntry(ffmpegVersion.toStdString() + "-win64-static/bin/ffmpeg.exe");
entryFFMPEGPath = path + "ffmpeg.exe";
entryFFMPEG = archive->getEntry(ffmpegVersion.toStdString() + "-win64-static/bin/ffmpeg.exe");
entryFFMPEGPath = path + "ffmpeg.exe";
#elif defined(Q_OS_OSX)
entryFFMPEG = archive->getEntry(ffmpegVersion.toStdString() +"-macos64-static/bin/ffmpeg");
entryFFMPEGPath = path + "ffmpeg";
@ -347,8 +347,8 @@ void Util::downloadFFMPEG()
return;
}
ZipEntry entryFFPROBE;
std::string entryFFPROBEPath;
ZipEntry entryFFPROBE;
std::string entryFFPROBEPath;
#ifdef Q_OS_WIN
entryFFPROBE = archive->getEntry(ffmpegVersion.toStdString() + "-win64-static/bin/ffprobe.exe");
entryFFPROBEPath = path + "ffprobe.exe";
@ -377,6 +377,56 @@ void Util::downloadFFMPEG()
});
}
SearchType::SearchType Util::getSearchTypeFromInstalledType(const InstalledType::InstalledType type)
{
using InstalledType::InstalledType;
using SearchType::SearchType;
switch (type) {
case InstalledType::GodotWallpaper:
case InstalledType::HTMLWallpaper:
case InstalledType::QMLWallpaper:
return SearchType::Scenes;
case InstalledType::VideoWallpaper:
return SearchType::Wallpaper;
case InstalledType::HTMLWidget:
case InstalledType::QMLWidget:
return SearchType::Widget;
case InstalledType::Unknown:
default:
return SearchType::All;
}
}
std::optional<InstalledType::InstalledType> Util::getInstalledTypeFromString(const QString& type)
{
if (type.endsWith("Wallpaper")) {
if (type.startsWith("video", Qt::CaseInsensitive)) {
return InstalledType::InstalledType::VideoWallpaper;
}
if (type.startsWith("qml", Qt::CaseInsensitive)) {
return InstalledType::InstalledType::QMLWallpaper;
}
if (type.startsWith("html", Qt::CaseInsensitive)) {
return InstalledType::InstalledType::HTMLWallpaper;
}
if (type.startsWith("godot", Qt::CaseInsensitive)) {
return InstalledType::InstalledType::GodotWallpaper;
}
}
if (type.endsWith("Widget")) {
if (type.startsWith("qml", Qt::CaseInsensitive)) {
return InstalledType::InstalledType::QMLWidget;
}
if (type.startsWith("html", Qt::CaseInsensitive)) {
return InstalledType::InstalledType::HTMLWidget;
}
}
return std::nullopt;
}
/*!
\brief Basic logging to the GUI. No logging is done to a log file for now. This string can be copied
in the settings tab in the UI.

View File

@ -126,7 +126,7 @@ signals:
void allLicenseLoaded(QString licensesText);
void allDataProtectionLoaded(QString dataProtectionText);
void ffmpegAvailableChanged(bool ffmpegAvailable);
void aquireFFMPEGStatusChanged(AquireFFMPEGStatus aquireFFMPEGStatus);
void aquireFFMPEGStatusChanged(ScreenPlay::Util::AquireFFMPEGStatus aquireFFMPEGStatus);
void debugMessagesChanged(QString debugMessages);
public slots:
@ -138,6 +138,8 @@ public slots:
void downloadFFMPEG();
static SearchType::SearchType getSearchTypeFromInstalledType(const InstalledType::InstalledType type);
static std::optional<InstalledType::InstalledType> getInstalledTypeFromString(const QString& type);
static std::optional<QJsonObject> parseQByteArrayToQJsonObject(const QByteArray& byteArray);
static std::optional<QJsonObject> openJsonFileToObject(const QString& path);
static std::optional<QString> openJsonFileToString(const QString& path);
@ -173,7 +175,7 @@ public slots:
emit ffmpegAvailableChanged(m_ffmpegAvailable);
}
void setAquireFFMPEGStatus(AquireFFMPEGStatus aquireFFMPEGStatus)
void setAquireFFMPEGStatus(ScreenPlay::Util::AquireFFMPEGStatus aquireFFMPEGStatus)
{
if (m_aquireFFMPEGStatus == aquireFFMPEGStatus)
return;

View File

@ -1,4 +1,6 @@
project(ScreenPlaySDK)
cmake_minimum_required(VERSION 3.17 )
project(ScreenPlaySDK LANGUAGES CXX)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)

View File

@ -1,4 +1,6 @@
project(ScreenPlaySysInfo)
cmake_minimum_required(VERSION 3.17 )
project(ScreenPlaySysInfo LANGUAGES CXX)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)

View File

@ -1,4 +1,6 @@
project(ScreenPlayWallpaper)
cmake_minimum_required(VERSION 3.17 )
project(ScreenPlayWallpaper LANGUAGES CXX)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)

View File

@ -1,4 +1,6 @@
project(ScreenPlayWidget)
cmake_minimum_required(VERSION 3.17 )
project(ScreenPlayWidget LANGUAGES CXX)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)

View File

@ -29,26 +29,6 @@ WidgetWindow::WidgetWindow(
setType(type);
{
// We limit ourself to only update the position every 500ms!
auto sendPositionUpdate = [this]() {
m_positionMessageLimiter.stop();
if (!m_sdk->isConnected())
return;
QJsonObject obj;
obj.insert("messageType", "positionUpdate");
obj.insert("positionX", m_window.x());
obj.insert("positionY", m_window.y());
m_sdk->sendMessage(obj);
};
m_positionMessageLimiter.setInterval(500);
QObject::connect(&m_positionMessageLimiter, &QTimer::timeout, this, sendPositionUpdate);
QObject::connect(&m_window, &QWindow::xChanged, this, [this]() { m_positionMessageLimiter.start(); });
QObject::connect(&m_window, &QWindow::yChanged, this, [this]() { m_positionMessageLimiter.start(); });
}
Qt::WindowFlags flags = m_window.flags();
m_window.setFlags(flags | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::BypassWindowManagerHint | Qt::SplashScreen);
@ -87,6 +67,27 @@ WidgetWindow::WidgetWindow(
m_window.setSource(QUrl("qrc:/Widget.qml"));
m_window.setPosition(m_position);
m_window.show();
// Do not trigger position changed save reuqest on startup
QTimer::singleShot(1000, [=, this]() {
// We limit ourself to only update the position every 500ms!
auto sendPositionUpdate = [this]() {
m_positionMessageLimiter.stop();
if (!m_sdk->isConnected())
return;
QJsonObject obj;
obj.insert("messageType", "positionUpdate");
obj.insert("positionX", m_window.x());
obj.insert("positionY", m_window.y());
m_sdk->sendMessage(obj);
};
m_positionMessageLimiter.setInterval(500);
QObject::connect(&m_positionMessageLimiter, &QTimer::timeout, this, sendPositionUpdate);
QObject::connect(&m_window, &QWindow::xChanged, this, [this]() { m_positionMessageLimiter.start(); });
QObject::connect(&m_window, &QWindow::yChanged, this, [this]() { m_positionMessageLimiter.start(); });
});
}
void WidgetWindow::setSize(QSize size)