mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-23 11:13:00 +01:00
WIP: Refactor saving/loading of profiles
We now partially support saving and loading custom properties. This is acomplished via a flat ProjectSettingsListModel that is only used for the properties. We still display the DefaultVideoControls.qml if the content is a video. For this I added the m_installedType to the MonitorListModel.
This commit is contained in:
parent
9852b09abe
commit
c4423a1497
@ -51,7 +51,6 @@ set(headers app.h
|
||||
src/profile.h
|
||||
src/projectfile.h
|
||||
src/installedlistfilter.h
|
||||
src/projectsettingslistitem.h
|
||||
src/projectsettingslistmodel.h
|
||||
src/screenplaymanager.h
|
||||
src/sdkconnection.h
|
||||
|
@ -7,7 +7,6 @@ import QtQuick.Layouts 1.3
|
||||
import ScreenPlay 1.0
|
||||
import ScreenPlay.Enums.FillMode 1.0
|
||||
|
||||
|
||||
import "../Common/" as SP
|
||||
|
||||
ColumnLayout {
|
||||
@ -30,26 +29,29 @@ ColumnLayout {
|
||||
|
||||
SP.Slider {
|
||||
headline: qsTr("Volume")
|
||||
slider.onMoved: {
|
||||
print("MODEV")
|
||||
ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
|
||||
activeMonitorIndex, "volume", slider.value)
|
||||
}
|
||||
slider.stepSize: 0.1
|
||||
slider.onMoved: {
|
||||
ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
|
||||
activeMonitorIndex, "volume", slider.value)
|
||||
}
|
||||
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
SP.Slider {
|
||||
headline: qsTr("Playback rate")
|
||||
slider.onMoved: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
|
||||
slider.onMoved: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
|
||||
activeMonitorIndex, "playbackRate", slider.value)
|
||||
Layout.fillWidth: true
|
||||
slider.stepSize: 0.1
|
||||
}
|
||||
SP.Slider {
|
||||
headline: qsTr("Current Video Time")
|
||||
slider.onMoved: ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
|
||||
activeMonitorIndex, "currentTime", slider.value)
|
||||
Layout.fillWidth: true
|
||||
slider.stepSize: 0.1
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
height: 50
|
||||
Layout.fillWidth: true
|
||||
@ -78,10 +80,8 @@ ColumnLayout {
|
||||
|
||||
textRole: "text"
|
||||
valueRole: "value"
|
||||
currentIndex: root.indexOfValue(
|
||||
settingsComboBox.model,
|
||||
ScreenPlay.settings.videoFillMode)
|
||||
|
||||
currentIndex: root.indexOfValue(settingsComboBox.model,
|
||||
ScreenPlay.settings.videoFillMode)
|
||||
|
||||
model: [{
|
||||
"value": FillMode.Stretch,
|
||||
|
@ -6,7 +6,7 @@ import QtQuick.Controls.Material 2.12
|
||||
import ScreenPlay 1.0
|
||||
|
||||
Rectangle {
|
||||
id: rect
|
||||
id: root
|
||||
color: Material.theme === Material.Light ? Material.background : Qt.darker(
|
||||
Material.background)
|
||||
|
||||
@ -18,15 +18,15 @@ Rectangle {
|
||||
property real availableWidth: 0
|
||||
property real availableHeight: 0
|
||||
property int fontSize: 12
|
||||
property bool multipleMonitorsSelectable: true
|
||||
property bool multipleMonitorsSelectable: false
|
||||
|
||||
// We preselect the main monitor
|
||||
property var activeMonitors: [0]
|
||||
|
||||
property alias background: rect.color
|
||||
property alias radius: rect.radius
|
||||
property alias background: root.color
|
||||
property alias radius: root.radius
|
||||
|
||||
signal requestProjectSettings(var at)
|
||||
signal requestProjectSettings(int index, var installedType, string appID)
|
||||
|
||||
Component.onCompleted: {
|
||||
resize()
|
||||
@ -59,16 +59,16 @@ Rectangle {
|
||||
}
|
||||
|
||||
function getActiveMonitors() {
|
||||
rect.activeMonitors = []
|
||||
root.activeMonitors = []
|
||||
for (var i = 0; i < rp.count; i++) {
|
||||
if (rp.itemAt(i).isSelected) {
|
||||
rect.activeMonitors.push(rp.itemAt(i).index)
|
||||
root.activeMonitors.push(rp.itemAt(i).index)
|
||||
}
|
||||
}
|
||||
// Must be called manually. When QML properties are getting altered in js the
|
||||
// property binding breaks
|
||||
rect.activeMonitorsChanged()
|
||||
return rect.activeMonitors
|
||||
root.activeMonitorsChanged()
|
||||
return root.activeMonitors
|
||||
}
|
||||
|
||||
function resize() {
|
||||
@ -134,7 +134,6 @@ Rectangle {
|
||||
snapMode: ScrollBar.SnapOnRelease
|
||||
}
|
||||
|
||||
|
||||
Repeater {
|
||||
id: rp
|
||||
model: ScreenPlay.monitorListModel
|
||||
@ -147,6 +146,7 @@ Rectangle {
|
||||
id: delegate
|
||||
monitorID: m_monitorID
|
||||
monitorName: m_name
|
||||
appID: m_appID
|
||||
height: m_availableGeometry.height
|
||||
width: m_availableGeometry.width
|
||||
x: m_availableGeometry.x
|
||||
@ -154,9 +154,10 @@ Rectangle {
|
||||
monitorManufacturer: m_manufacturer
|
||||
monitorModel: m_model
|
||||
monitorSize: m_availableGeometry
|
||||
fontSize: rect.fontSize
|
||||
fontSize: root.fontSize
|
||||
index: m_number
|
||||
previewImage: m_previewImage
|
||||
installedType: m_installedType
|
||||
|
||||
onMonitorSelected: {
|
||||
|
||||
@ -169,7 +170,7 @@ Rectangle {
|
||||
|
||||
getActiveMonitors()
|
||||
|
||||
requestProjectSettings(index)
|
||||
root.requestProjectSettings(delegate.index, delegate.installedType, delegate.appID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,10 @@ Item {
|
||||
property string monitorName
|
||||
property string monitorID
|
||||
property string previewImage: ""
|
||||
property string appID
|
||||
property var installedType
|
||||
|
||||
|
||||
onPreviewImageChanged: {
|
||||
if (previewImage === "") {
|
||||
imgPreview.opacity = 0
|
||||
|
@ -5,6 +5,7 @@ import QtQuick.Controls.Material 2.2
|
||||
import QtQuick.Layouts 1.3
|
||||
|
||||
import ScreenPlay 1.0
|
||||
|
||||
import ScreenPlay.Enums.InstalledType 1.0
|
||||
import "../Common/" as SP
|
||||
|
||||
@ -89,15 +90,28 @@ Item {
|
||||
}
|
||||
availableWidth: width - 20
|
||||
availableHeight: 150
|
||||
|
||||
onRequestProjectSettings: {
|
||||
ScreenPlay.screenPlayManager.requestProjectSettingsAtMonitorIndex(
|
||||
at)
|
||||
activeMonitorIndex = at
|
||||
if (installedType === InstalledType.VideoWallpaper) {
|
||||
videoControlWrapper.state = "visible"
|
||||
customPropertiesGridView.visible = false
|
||||
print(appID)
|
||||
const wallpaper = ScreenPlay.screenPlayManager.getWallpaperByAppID(appID)
|
||||
print("volume", wallpaper.volume)
|
||||
} else {
|
||||
videoControlWrapper.state = "hidden"
|
||||
customPropertiesGridView.visible = true
|
||||
ScreenPlay.screenPlayManager.requestProjectSettingsAtMonitorIndex(
|
||||
index)
|
||||
}
|
||||
|
||||
activeMonitorIndex = index
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: ScreenPlay.screenPlayManager
|
||||
function onProjectSettingsListModelResult(listModel) {
|
||||
customPropertiesGridView.model = listModel
|
||||
customPropertiesGridView.projectSettingsListmodelRef = listModel
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -165,6 +179,14 @@ Item {
|
||||
left: itmLeftWrapper.right
|
||||
}
|
||||
|
||||
DefaultVideoControls {
|
||||
id: videoControlWrapper
|
||||
activeMonitorIndex: monitors.activeMonitorIndex
|
||||
state: "hidden"
|
||||
anchors.fill: parent
|
||||
anchors.margins: 10
|
||||
}
|
||||
|
||||
GridView {
|
||||
id: customPropertiesGridView
|
||||
boundsBehavior: Flickable.DragOverBounds
|
||||
@ -176,6 +198,9 @@ Item {
|
||||
clip: true
|
||||
anchors.fill: parent
|
||||
anchors.margins: 10
|
||||
visible: false
|
||||
model: customPropertiesGridView.projectSettingsListmodelRef
|
||||
property var projectSettingsListmodelRef
|
||||
|
||||
delegate: MonitorsProjectSettingItem {
|
||||
id: delegate
|
||||
@ -184,6 +209,8 @@ Item {
|
||||
name: m_name
|
||||
isHeadline: m_isHeadline
|
||||
value: m_value
|
||||
itemIndex: index
|
||||
projectSettingsListmodelRef: customPropertiesGridView.projectSettingsListmodelRef
|
||||
}
|
||||
|
||||
ScrollBar.vertical: ScrollBar {
|
||||
|
@ -15,6 +15,8 @@ Item {
|
||||
property string name
|
||||
property var value
|
||||
property bool isHeadline
|
||||
property int itemIndex
|
||||
property var projectSettingsListmodelRef
|
||||
|
||||
Text {
|
||||
id: txtDescription
|
||||
@ -42,38 +44,44 @@ Item {
|
||||
right: parent.right
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
if (root.value.toString() === "") {
|
||||
return
|
||||
}
|
||||
Loader {
|
||||
id: loader
|
||||
anchors.fill: parent
|
||||
anchors.rightMargin: 10
|
||||
|
||||
Connections {
|
||||
target: loader.item
|
||||
function onSave(value) {
|
||||
projectSettingsListmodelRef.setValueAtIndex(root.itemIndex,
|
||||
name, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
if (root.isHeadline)
|
||||
return
|
||||
|
||||
switch (root.value["type"]) {
|
||||
case "slider":
|
||||
loader.sourceComponent = compSlider
|
||||
loader.item.from = root.value["from"]
|
||||
loader.item.to = root.value["to"]
|
||||
loader.item.value = root.value["value"]
|
||||
loader.item.stepSize = root.value["stepSize"]
|
||||
break
|
||||
case "bool":
|
||||
loader.sourceComponent = compCheckbox
|
||||
loader.item.value = root.value["value"]
|
||||
break
|
||||
case "color":
|
||||
loader.sourceComponent = compColorpicker
|
||||
loader.item.value = root.value["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"]
|
||||
}
|
||||
if (root.value["text"]) {
|
||||
txtDescription.text = root.value["text"]
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,6 +102,13 @@ Item {
|
||||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
onCheckedChanged: {
|
||||
let obj = {
|
||||
"value": checkbox.checked,
|
||||
"type": "checkBox",
|
||||
}
|
||||
|
||||
root.save(obj)
|
||||
|
||||
ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
|
||||
selectedMonitor, name, checkbox.checked)
|
||||
}
|
||||
@ -109,6 +124,8 @@ Item {
|
||||
anchors.fill: parent
|
||||
property color value
|
||||
|
||||
signal save(var value)
|
||||
|
||||
Button {
|
||||
id: btnSetColor
|
||||
text: qsTr("Set color")
|
||||
@ -138,6 +155,15 @@ Item {
|
||||
onAccepted: {
|
||||
rctPreviewColor.color = colorDialog.color
|
||||
let tmpColor = "'" + colorDialog.color.toString() + "'"
|
||||
|
||||
|
||||
let obj = {
|
||||
"value": colorDialog.color,
|
||||
"type": "color",
|
||||
}
|
||||
|
||||
root.save(obj)
|
||||
|
||||
ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
|
||||
selectedMonitor, name, tmpColor)
|
||||
}
|
||||
@ -156,6 +182,8 @@ Item {
|
||||
property int value
|
||||
property int stepSize
|
||||
|
||||
signal save(var value)
|
||||
|
||||
Slider {
|
||||
id: slider
|
||||
from: root.from
|
||||
@ -175,6 +203,17 @@ Item {
|
||||
onValueChanged: {
|
||||
var value = Math.round(slider.value * 100) / 100
|
||||
txtSliderValue.text = value
|
||||
|
||||
let obj = {
|
||||
"from": root.from,
|
||||
"to": root.to,
|
||||
"value": value,
|
||||
"type": "slider",
|
||||
"stepSize": root.stepSize
|
||||
}
|
||||
|
||||
root.save(obj)
|
||||
|
||||
ScreenPlay.screenPlayManager.setWallpaperValueAtMonitorIndex(
|
||||
selectedMonitor, name, value)
|
||||
}
|
||||
@ -191,12 +230,6 @@ Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: loader
|
||||
anchors.fill: parent
|
||||
anchors.rightMargin: 10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,11 +47,11 @@ QHash<int, QByteArray> MonitorListModel::roleNames() const
|
||||
{ static_cast<int>(MonitorRole::Model), "m_model" },
|
||||
{ static_cast<int>(MonitorRole::Manufacturer), "m_manufacturer" },
|
||||
{ static_cast<int>(MonitorRole::PreviewImage), "m_previewImage" },
|
||||
{ static_cast<int>(MonitorRole::InstalledType), "m_installedType" },
|
||||
};
|
||||
return roles;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\brief Returns the amount of active monitors.
|
||||
*/
|
||||
@ -78,7 +78,6 @@ QVariant MonitorListModel::data(const QModelIndex& index, int role) const
|
||||
|
||||
auto roleEnum = static_cast<MonitorRole>(role);
|
||||
|
||||
|
||||
if (row < rowCount())
|
||||
switch (roleEnum) {
|
||||
case MonitorRole::AppID:
|
||||
@ -113,10 +112,16 @@ QVariant MonitorListModel::data(const QModelIndex& index, int role) const
|
||||
return m_monitorList.at(row).m_screen->model();
|
||||
case MonitorRole::Manufacturer:
|
||||
return m_monitorList.at(row).m_screen->manufacturer();
|
||||
case MonitorRole::InstalledType:
|
||||
if (m_monitorList.at(row).m_activeWallpaper) {
|
||||
return static_cast<int>(m_monitorList.at(row).m_activeWallpaper->type());
|
||||
} else {
|
||||
return { "" };
|
||||
}
|
||||
case MonitorRole::PreviewImage:
|
||||
if (m_monitorList.at(row).m_activeWallpaper) {
|
||||
QString absolutePath = m_monitorList.at(row).m_activeWallpaper->absolutePath();
|
||||
return absolutePath + "/" + m_monitorList.at(row).m_activeWallpaper->previewImage();
|
||||
QString absolutePath = m_monitorList.at(row).m_activeWallpaper->absolutePath();
|
||||
return absolutePath + "/" + m_monitorList.at(row).m_activeWallpaper->previewImage();
|
||||
} else {
|
||||
return QVariant("");
|
||||
}
|
||||
@ -176,6 +181,7 @@ void MonitorListModel::clearActiveWallpaper()
|
||||
index(i, 0),
|
||||
QVector<int> {
|
||||
static_cast<int>(MonitorRole::PreviewImage),
|
||||
static_cast<int>(MonitorRole::InstalledType),
|
||||
static_cast<int>(MonitorRole::AppID) });
|
||||
++i;
|
||||
}
|
||||
@ -196,6 +202,7 @@ void MonitorListModel::closeWallpaper(const QString& appID)
|
||||
index(i, 0),
|
||||
QVector<int> {
|
||||
static_cast<int>(MonitorRole::PreviewImage),
|
||||
static_cast<int>(MonitorRole::InstalledType),
|
||||
static_cast<int>(MonitorRole::AppID) });
|
||||
}
|
||||
}
|
||||
@ -203,6 +210,16 @@ void MonitorListModel::closeWallpaper(const QString& appID)
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief MonitorListModel::getAbsoluteDesktopSize
|
||||
* \return
|
||||
*/
|
||||
QRect MonitorListModel::getAbsoluteDesktopSize() const
|
||||
{
|
||||
auto* app = static_cast<QApplication*>(QApplication::instance());
|
||||
return app->screens().at(0)->availableVirtualGeometry();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Sets the previewImage and appID for a list item.
|
||||
*/
|
||||
@ -217,6 +234,7 @@ void MonitorListModel::setWallpaperActiveMonitor(const std::shared_ptr<ScreenPla
|
||||
index(monitor, 0),
|
||||
QVector<int> {
|
||||
static_cast<int>(MonitorRole::PreviewImage),
|
||||
static_cast<int>(MonitorRole::InstalledType),
|
||||
static_cast<int>(MonitorRole::AppID) });
|
||||
}
|
||||
}
|
||||
|
@ -79,11 +79,6 @@ class MonitorListModel : public QAbstractListModel {
|
||||
public:
|
||||
explicit MonitorListModel(QObject* parent = nullptr);
|
||||
|
||||
~MonitorListModel() override
|
||||
{
|
||||
m_monitorList.clear();
|
||||
}
|
||||
|
||||
enum class MonitorRole {
|
||||
AppID = Qt::UserRole,
|
||||
MonitorID,
|
||||
@ -96,6 +91,7 @@ public:
|
||||
Model,
|
||||
Manufacturer,
|
||||
PreviewImage,
|
||||
InstalledType,
|
||||
};
|
||||
Q_ENUM(MonitorRole)
|
||||
|
||||
@ -103,18 +99,11 @@ public:
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
void setWallpaperActiveMonitor(
|
||||
const std::shared_ptr<ScreenPlayWallpaper>& wallpaper,
|
||||
void setWallpaperActiveMonitor(const std::shared_ptr<ScreenPlayWallpaper>& wallpaper,
|
||||
const QVector<int> monitors);
|
||||
|
||||
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);
|
||||
@ -124,6 +113,7 @@ public slots:
|
||||
void reset();
|
||||
void clearActiveWallpaper();
|
||||
void closeWallpaper(const QString& appID);
|
||||
QRect getAbsoluteDesktopSize() const;
|
||||
|
||||
void screenAdded(QScreen* screen)
|
||||
{
|
||||
|
@ -42,6 +42,8 @@
|
||||
#include <QUrl>
|
||||
#include <QVariant>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
/*!
|
||||
@ -53,106 +55,76 @@ namespace ScreenPlay {
|
||||
*/
|
||||
|
||||
struct IListItem {
|
||||
//MOC complains otherwise WTF
|
||||
bool operator!=(const IListItem& val)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
Q_GADGET
|
||||
public:
|
||||
QVariant m_value;
|
||||
virtual QJsonObject getItemSettings() = 0;
|
||||
public slots:
|
||||
virtual void setData(const QJsonObject& obj){}
|
||||
};
|
||||
|
||||
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_value = { 0.0 };
|
||||
double m_to = { 0.1 };
|
||||
double m_stepSize = { 0.1 };
|
||||
double m_value = { 0.0 };
|
||||
QJsonObject getItemSettings() override;
|
||||
public slots:
|
||||
void setData(const QJsonObject& obj) override;
|
||||
};
|
||||
|
||||
struct ColorItem : public IListItem {
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QColor color MEMBER m_color)
|
||||
public:
|
||||
QJsonObject getItemSettings() override;
|
||||
QColor m_color = { QColor::fromRgb(0, 0, 0) };
|
||||
public slots:
|
||||
void setData(const QJsonObject& obj) override;
|
||||
};
|
||||
|
||||
struct CheckBoxItem : public IListItem {
|
||||
Q_GADGET
|
||||
Q_PROPERTY(bool value MEMBER m_value)
|
||||
Q_PROPERTY(bool checked MEMBER m_checked)
|
||||
public:
|
||||
bool m_value = { false };
|
||||
QJsonObject getItemSettings() override;
|
||||
bool m_checked = { false };
|
||||
public slots:
|
||||
void setData(const QJsonObject& obj) override;
|
||||
};
|
||||
|
||||
struct FileItem : public IListItem {
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUrl file MEMBER m_file)
|
||||
Q_PROPERTY(QString formats MEMBER m_formats)
|
||||
public:
|
||||
QJsonObject getItemSettings() override;
|
||||
QUrl m_file = {};
|
||||
QString m_formats = {};
|
||||
public slots:
|
||||
void setData(const QJsonObject& obj) override;
|
||||
};
|
||||
|
||||
struct ProjectSettingsListItem {
|
||||
Q_GADGET
|
||||
Q_PROPERTY(IListItem item MEMBER m_item)
|
||||
public:
|
||||
ProjectSettingsListItem(
|
||||
const QString& headline)
|
||||
{
|
||||
m_isHeadline = true;
|
||||
m_key = headline;
|
||||
}
|
||||
const QString& headline);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
const QJsonObject& obj);
|
||||
|
||||
QString m_key;
|
||||
bool m_isHeadline { false };
|
||||
QVariant m_value;
|
||||
IListItem m_item;
|
||||
QVariant value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
std::shared_ptr<IListItem> m_item;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
@ -36,41 +36,115 @@ namespace ScreenPlay {
|
||||
|
||||
/*!
|
||||
Constructor when loading properties from settings.json
|
||||
We need to _flatten_ the json to make it work with a flat list model!
|
||||
See \sa getActiveSettingsJson to make the flat list to a hierarchical json object
|
||||
*/
|
||||
|
||||
void ProjectSettingsListModel::init(const InstalledType::InstalledType& type, const QJsonObject& properties)
|
||||
{
|
||||
if (type == InstalledType::InstalledType::VideoWallpaper) {
|
||||
// beginInsertRows(QModelIndex(), m_projectSettings.size(), m_projectSettings.size());
|
||||
|
||||
// m_projectSettings.append("General");
|
||||
for (QJsonObject::const_iterator itParent = properties.begin(); itParent != properties.end(); itParent++) {
|
||||
|
||||
// if (properties.contains("volume"))
|
||||
// append({"slider", properties.value("volume")}=;
|
||||
// The first object is always a category
|
||||
const QJsonObject category = properties.value(itParent.key()).toObject();
|
||||
|
||||
// if (properties.contains("playbackRate"))
|
||||
// append("slider", properties.value("playbackRate").toObject());
|
||||
// endInsertRows();
|
||||
append(SettingsItem { itParent.key() });
|
||||
|
||||
} 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();
|
||||
}
|
||||
// Children of this category
|
||||
for (QJsonObject::const_iterator itChild = category.begin(); itChild != category.end(); itChild++) {
|
||||
const QJsonObject child = category.value(itChild.key()).toObject();
|
||||
append(SettingsItem { itChild.key(), child });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief ProjectSettingsListModel::getActiveSettingsJson
|
||||
* \return
|
||||
*/
|
||||
QJsonObject ProjectSettingsListModel::getActiveSettingsJson()
|
||||
{
|
||||
if (m_projectSettings.isEmpty()) {
|
||||
qWarning() << "Trying to read empty projectSettings. Abort!";
|
||||
return {};
|
||||
}
|
||||
|
||||
// This creates a hierarchical json from the flat list model:
|
||||
// Category 1 // <- this is a headline item
|
||||
// emitRate:
|
||||
// "from": 0,
|
||||
// "stepSize": 1,
|
||||
// "to": 2500,
|
||||
// "type": "slider",
|
||||
// "value": 25
|
||||
// Category 2
|
||||
// property 1
|
||||
// ...
|
||||
QString currentCategory;
|
||||
QJsonObject ret;
|
||||
std::unique_ptr<QJsonObject> properties = std::make_unique<QJsonObject>();
|
||||
|
||||
for (auto& item : m_projectSettings) {
|
||||
|
||||
if (item.m_isHeadline) {
|
||||
|
||||
// It is empty the first time
|
||||
if (!properties->isEmpty()) {
|
||||
|
||||
// We only write the current category right _before_
|
||||
// we start with the next one. This way we need to save
|
||||
// the last category below!
|
||||
|
||||
ret.insert(currentCategory, *properties);
|
||||
}
|
||||
|
||||
currentCategory = item.m_name;
|
||||
properties = std::make_unique<QJsonObject>();
|
||||
|
||||
} else {
|
||||
properties->insert(item.m_name, item.m_value);
|
||||
}
|
||||
|
||||
// Because the last item is never a headline,
|
||||
// we need to add the last category here because
|
||||
if (&item == &m_projectSettings.last()) {
|
||||
ret.insert(currentCategory, *properties);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ProjectSettingsListModel::append(const SettingsItem&& item)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), m_projectSettings.size(), m_projectSettings.size());
|
||||
m_projectSettings.append(item);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void ProjectSettingsListModel::setValueAtIndex(const int row, const QString& key, const QJsonObject& value)
|
||||
{
|
||||
if (row >= m_projectSettings.size() || row < 0) {
|
||||
qWarning() << "Cannot setValueAtIndex when index is out of bounce! Row: " << row << ", m_projectSettings size: " << m_projectSettings.size();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_projectSettings.at(row).m_isHeadline) {
|
||||
qWarning() << "Cannot set settings item from type headline!";
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_projectSettings.at(row).m_name != key) {
|
||||
qWarning() << "Name of the element does not match current settings";
|
||||
return;
|
||||
}
|
||||
|
||||
m_projectSettings.replace(row, SettingsItem { key, value });
|
||||
|
||||
QVector<int> roles = { ValueRole };
|
||||
|
||||
emit dataChanged(index(row, 0), index(row, 0), roles);
|
||||
}
|
||||
|
||||
int ProjectSettingsListModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
// For list models only the root node (an invalid parent) should return the list's size. For all
|
||||
@ -91,7 +165,7 @@ QVariant ProjectSettingsListModel::data(const QModelIndex& index, int role) cons
|
||||
if (index.row() < rowCount())
|
||||
switch (role) {
|
||||
case NameRole:
|
||||
return m_projectSettings.at(rowIndex).m_key;
|
||||
return m_projectSettings.at(rowIndex).m_name;
|
||||
case IsHeadlineRole:
|
||||
return m_projectSettings.at(rowIndex).m_isHeadline;
|
||||
case ValueRole:
|
||||
@ -114,26 +188,4 @@ QHash<int, QByteArray> ProjectSettingsListModel::roleNames() const
|
||||
return roles;
|
||||
}
|
||||
|
||||
QJsonObject ProjectSettingsListModel::getActiveSettingsJson()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,11 +43,38 @@
|
||||
#include <QJsonObject>
|
||||
#include <QVector>
|
||||
|
||||
#include "projectsettingslistitem.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace ScreenPlay {
|
||||
|
||||
struct SettingsItem {
|
||||
SettingsItem(
|
||||
const QString& name,
|
||||
const QJsonObject& value)
|
||||
{
|
||||
m_name = name;
|
||||
m_isHeadline = false;
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
SettingsItem(
|
||||
const QString& name)
|
||||
{
|
||||
m_name = name;
|
||||
m_isHeadline = true;
|
||||
}
|
||||
QString m_name;
|
||||
bool m_isHeadline;
|
||||
QJsonObject m_value;
|
||||
QString m_type;
|
||||
|
||||
public:
|
||||
void SettingsItem::setValue(const QJsonObject& value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
};
|
||||
|
||||
class ProjectSettingsListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
|
||||
@ -65,8 +92,12 @@ public:
|
||||
|
||||
QJsonObject getActiveSettingsJson();
|
||||
void init(const InstalledType::InstalledType& type, const QJsonObject& properties);
|
||||
void append(const SettingsItem&& item);
|
||||
|
||||
public slots:
|
||||
void setValueAtIndex(const int row, const QString& key, const QJsonObject& value);
|
||||
|
||||
private:
|
||||
QVector<ProjectSettingsListItem> m_projectSettings;
|
||||
QVector<SettingsItem> m_projectSettings;
|
||||
};
|
||||
}
|
||||
|
@ -85,14 +85,16 @@ 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,
|
||||
const QVector<int>& monitorIndex,
|
||||
const float volume,
|
||||
const float playbackRate, const QJsonObject& properties,
|
||||
const float playbackRate,
|
||||
const QJsonObject& properties,
|
||||
const bool saveToProfilesConfigFile)
|
||||
{
|
||||
auto saveToProfile = qScopeGuard([=, this] {
|
||||
@ -160,7 +162,8 @@ void ScreenPlayManager::createWallpaper(const InstalledType::InstalledType type,
|
||||
/*!
|
||||
\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,
|
||||
@ -178,7 +181,7 @@ void ScreenPlayManager::createWidget(const InstalledType::InstalledType type,
|
||||
const QString path = QUrl::fromUserInput(absoluteStoragePath).toLocalFile();
|
||||
|
||||
if (path.isEmpty()) {
|
||||
qInfo() << "Path is empty, Abort! String: " << absoluteStoragePath;
|
||||
qWarning() << "Path is empty, Abort! String: " << absoluteStoragePath;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -198,14 +201,14 @@ void ScreenPlayManager::createWidget(const InstalledType::InstalledType type,
|
||||
|
||||
void ScreenPlayManager::appConnected(const std::shared_ptr<SDKConnection>& connection)
|
||||
{
|
||||
for (const auto& item : m_screenPlayWidgets) {
|
||||
for (const auto& item : qAsConst(m_screenPlayWidgets)) {
|
||||
if (item->appID() == connection->appID()) {
|
||||
item->setSDKConnection(connection);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& item : m_screenPlayWallpapers) {
|
||||
for (const auto& item : qAsConst(m_screenPlayWallpapers)) {
|
||||
if (item->appID() == connection->appID()) {
|
||||
item->setSDKConnection(connection);
|
||||
return;
|
||||
@ -313,11 +316,9 @@ void ScreenPlayManager::requestProjectSettingsAtMonitorIndex(const int index)
|
||||
void ScreenPlayManager::setWallpaperValueAtMonitorIndex(const int index, const QString& key, const QString& value)
|
||||
{
|
||||
if (auto appID = m_monitorListModel->getAppIDByMonitorIndex(index)) {
|
||||
|
||||
setWallpaperValue(*appID, key, value);
|
||||
|
||||
if (auto wallpaper = getWallpaperByAppID(*appID)) {
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Could net get appID from m_monitorListModel!";
|
||||
}
|
||||
}
|
||||
|
||||
@ -334,14 +335,14 @@ void ScreenPlayManager::setAllWallpaperValue(const QString& key, const QString&
|
||||
/*!
|
||||
\brief Returns \c a ScreenPlayWallpaper if successful, otherwhise \c std::nullopt.
|
||||
*/
|
||||
std::optional<std::shared_ptr<ScreenPlayWallpaper>> ScreenPlayManager::getWallpaperByAppID(const QString& appID)
|
||||
ScreenPlayWallpaper* ScreenPlayManager::getWallpaperByAppID(const QString& appID) const
|
||||
{
|
||||
for (auto& wallpaper : m_screenPlayWallpapers) {
|
||||
if (wallpaper->appID() == appID) {
|
||||
return wallpaper;
|
||||
return wallpaper.get();
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -426,7 +427,7 @@ bool ScreenPlayManager::closeWallpaper(const QString& appID)
|
||||
*/
|
||||
void ScreenPlayManager::setWallpaperValue(const QString& appID, const QString& key, const QVariant& value)
|
||||
{
|
||||
for (const auto& wallpaper : m_screenPlayWallpapers) {
|
||||
for (const auto& wallpaper : qAsConst(m_screenPlayWallpapers)) {
|
||||
if (wallpaper->appID() == appID) {
|
||||
wallpaper->setWallpaperValue(key, value, true);
|
||||
}
|
||||
@ -442,12 +443,12 @@ void ScreenPlayManager::saveProfiles()
|
||||
m_saveLimiter.stop();
|
||||
qInfo() << "Save profiles!";
|
||||
QJsonArray wallpaper {};
|
||||
for (const auto& activeWallpaper : m_screenPlayWallpapers) {
|
||||
for (const auto& activeWallpaper : qAsConst(m_screenPlayWallpapers)) {
|
||||
wallpaper.append(activeWallpaper->getActiveSettingsJson());
|
||||
}
|
||||
|
||||
QJsonArray widgets {};
|
||||
for (const auto& activeWidget : m_screenPlayWidgets) {
|
||||
for (const auto& activeWidget : qAsConst(m_screenPlayWidgets)) {
|
||||
widgets.append(activeWidget->getActiveSettingsJson());
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ public slots:
|
||||
void requestProjectSettingsAtMonitorIndex(const int index);
|
||||
void setWallpaperValueAtMonitorIndex(const int index, const QString& key, const QString& value);
|
||||
void setAllWallpaperValue(const QString& key, const QString& value);
|
||||
std::optional<std::shared_ptr<ScreenPlayWallpaper>> getWallpaperByAppID(const QString& appID);
|
||||
ScreenPlayWallpaper* getWallpaperByAppID(const QString& appID) const;
|
||||
|
||||
void newConnection();
|
||||
void closeAllWallpapers();
|
||||
|
@ -13,6 +13,8 @@ namespace ScreenPlay {
|
||||
/*!
|
||||
\brief Constructor for video Wallpaper.
|
||||
*/
|
||||
|
||||
|
||||
ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
|
||||
const std::shared_ptr<GlobalVariables>& globalVariables,
|
||||
const QString& appID,
|
||||
@ -88,7 +90,6 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
|
||||
// Fixes issue 84 media key overlay
|
||||
" --disable-features=HardwareMediaKeyHandling"
|
||||
};
|
||||
qInfo() << proArgs;
|
||||
|
||||
m_process.setArguments(proArgs);
|
||||
m_process.setProgram(m_globalVariables->wallpaperExecutablePath().toString());
|
||||
@ -110,7 +111,7 @@ QJsonObject ScreenPlayWallpaper::getActiveSettingsJson()
|
||||
obj.insert("volume", m_volume);
|
||||
obj.insert("playbackRate", m_playbackRate);
|
||||
} else {
|
||||
auto properties = m_projectSettingsListModel.getActiveSettingsJson();
|
||||
QJsonObject properties = m_projectSettingsListModel.getActiveSettingsJson();
|
||||
if (!properties.isEmpty())
|
||||
obj.insert("properties", properties);
|
||||
}
|
||||
@ -156,7 +157,7 @@ void ScreenPlayWallpaper::setWallpaperValue(const QString& key, const QVariant&
|
||||
}
|
||||
|
||||
m_connection->sendMessage(QJsonDocument(obj).toJson(QJsonDocument::Compact));
|
||||
qInfo() << "save" << save;
|
||||
|
||||
if (save)
|
||||
emit requestSave();
|
||||
}
|
||||
@ -164,8 +165,6 @@ void ScreenPlayWallpaper::setWallpaperValue(const QString& key, const QVariant&
|
||||
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);
|
||||
|
@ -67,6 +67,7 @@ class ScreenPlayWallpaper : public QObject {
|
||||
Q_PROPERTY(InstalledType::InstalledType type READ type WRITE setType NOTIFY typeChanged)
|
||||
|
||||
public:
|
||||
ScreenPlayWallpaper(){}
|
||||
explicit ScreenPlayWallpaper(const QVector<int>& screenNumber,
|
||||
const std::shared_ptr<GlobalVariables>& globalVariables,
|
||||
const QString& appID,
|
||||
@ -259,7 +260,7 @@ public slots:
|
||||
}
|
||||
|
||||
private:
|
||||
const std::shared_ptr<GlobalVariables>& m_globalVariables;
|
||||
const std::shared_ptr<GlobalVariables> m_globalVariables;
|
||||
std::shared_ptr<SDKConnection> m_connection;
|
||||
|
||||
ProjectSettingsListModel m_projectSettingsListModel;
|
||||
|
@ -96,14 +96,14 @@ public:
|
||||
|
||||
void setSDKConnection(const std::shared_ptr<SDKConnection>& connection);
|
||||
|
||||
public slots:
|
||||
QJsonObject getActiveSettingsJson();
|
||||
|
||||
ProjectSettingsListModel* getProjectSettingsListModel()
|
||||
{
|
||||
return &m_projectSettingsListModel;
|
||||
}
|
||||
|
||||
public slots:
|
||||
QJsonObject getActiveSettingsJson();
|
||||
|
||||
void setPreviewImage(QString previewImage)
|
||||
{
|
||||
if (m_previewImage == previewImage)
|
||||
|
Loading…
Reference in New Issue
Block a user