1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 19:42:45 +01:00

Change installed content type from string to enum

We now use the InstalledType enum in QML for differentiating between wallpaper types

Fix widgets start
Add tag parsing from project file
Cleanup sidebar unused code
This commit is contained in:
Elias Steurer 2020-06-19 18:05:32 +02:00
parent b13d643d44
commit 5fb1ea3a96
10 changed files with 269 additions and 275 deletions

View File

@ -99,6 +99,14 @@ App::App()
"ScreenPlayEnums",
"Error: only enums");
qRegisterMetaType<InstalledType::InstalledType>();
qmlRegisterUncreatableMetaObject(ScreenPlay::InstalledType::staticMetaObject,
"ScreenPlay.Enums.InstalledType",
1, 0,
"InstalledType",
"Error: only enums");
qmlRegisterAnonymousType<GlobalVariables>("ScreenPlay", 1);
qmlRegisterAnonymousType<ScreenPlayManager>("ScreenPlay", 1);
qmlRegisterAnonymousType<Util>("ScreenPlay", 1);

View File

@ -298,7 +298,7 @@ ApplicationWindow {
Sidebar {
id: sidebar
width: 400
navHeight: nav.height
anchors {
top: parent.top

View File

@ -3,6 +3,8 @@ import QtGraphicalEffects 1.0
import QtQuick.Controls 2.3
import QtQuick.Controls.Styles 1.4
import ScreenPlay 1.0
import ScreenPlay.Enums.InstalledType 1.0
Item {
id: screenPlayItem
width: 320
@ -12,18 +14,27 @@ Item {
property string customTitle: "name here"
property url absoluteStoragePath
property string type
property var type
property bool hasMenuOpen: false
property int workshopID: 0
property int itemIndex
property string screenId: ""
onTypeChanged: {
if(type.endsWith("Widget"))
switch (type) {
case InstalledType.Unknown:
return
case InstalledType.VideoWallpaper:
case InstalledType.QMLWallpaper:
case InstalledType.HTMLWallpaper:
case InstalledType.GodotWallpaper:
icnType.source = "qrc:/assets/icons/icon_widgets.svg"
if(type.endsWith("Wallpaper"))
return
case InstalledType.QMLWidget:
case InstalledType.HTMLWidget:
icnType.source = "qrc:/assets/icons/icon_movie.svg"
return
}
}
Component.onCompleted: {
@ -34,10 +45,10 @@ Item {
id: timerAnim
interval: {
var itemIndexMax = itemIndex
if(itemIndex > 30)
if (itemIndex > 30)
itemIndexMax = 3
10 * itemIndexMax *Math.random()
10 * itemIndexMax * Math.random()
}
running: true
@ -133,7 +144,6 @@ Item {
visible: false
smooth: true
fillMode: Image.PreserveAspectFit
}
Item {
@ -202,15 +212,16 @@ Item {
onExited: {
if (!hasMenuOpen) {
screenPlayItem.state = "visible"
screenPlayItemImage.state = "loaded"
screenPlayItemImage.state = "loaded"
screenPlayItemImage.exit()
}
}
onClicked: {
if (mouse.button === Qt.LeftButton) {
ScreenPlay.util.setSidebarItem(screenPlayItem.screenId, screenPlayItem.type.toString())
ScreenPlay.util.setSidebarItem(
screenPlayItem.screenId,
screenPlayItem.type)
} else if (mouse.button === Qt.RightButton) {
if (workshopID != 0) {
miWorkshop.enabled = true

View File

@ -7,6 +7,7 @@ import QtQuick.Controls.Material 2.12
import ScreenPlay 1.0
import ScreenPlayEnums 1.0
import ScreenPlay.Enums.InstalledType 1.0
import "../Monitors"
import "../Common" as SP
@ -18,28 +19,46 @@ Item {
focus: true
property real navHeight
property string type
property var typeEnum: ScreenPlayEnums.QMLWallpaper
property string activeScreen
property var type: InstalledType.QMLWallpaper
property string contentFolderName
onContentFolderNameChanged: {
txtHeadline.text = ScreenPlay.installedListModel.get(
root.contentFolderName).screenTitle
if (ScreenPlay.installedListModel.get(
root.contentFolderName).screenPreviewGIF === undefined) {
image.source = Qt.resolvedUrl(
ScreenPlay.globalVariables.localStoragePath + "/"
+ root.contentFolderName + "/" + ScreenPlay.installedListModel.get(
root.contentFolderName).screenPreview)
image.playing = false
} else {
image.source = Qt.resolvedUrl(
ScreenPlay.globalVariables.localStoragePath + "/"
+ root.contentFolderName + "/" + ScreenPlay.installedListModel.get(
root.contentFolderName).screenPreviewGIF)
image.playing = true
}
if (isWidget() || monitorSelection.activeMonitors.length > 0) {
btnSetWallpaper.enabled = true
return
}
btnSetWallpaper.enabled = false
}
function isWallpaper() {
if (typeEnum === ScreenPlayEnums.VideoWallpaper
|| typeEnum === ScreenPlayEnums.HTMLWallpaper
|| typeEnum === ScreenPlayEnums.QMLWallpaper) {
return true
} else {
return false
}
return type === InstalledType.VideoWallpaper
|| type === InstalledType.HTMLWallpaper
|| type === InstalledType.QMLWallpaper
}
function isWidget() {
if (typeEnum === ScreenPlayEnums.HTMLWidget
|| typeEnum === ScreenPlayEnums.QMLWidget) {
return true
} else {
return false
}
return type === InstalledType.HTMLWidget
|| type === InstalledType.QMLWidget
}
function indexOfValue(model, value) {
@ -55,79 +74,40 @@ Item {
Connections {
target: ScreenPlay.util
function onSetSidebarItem(screenId, type) {
function onSetSidebarItem(folderName, type) {
// Toggle sidebar if clicked on the same content twice
if (activeScreen === screenId && root.state !== "inactive") {
if (root.contentFolderName === folderName
&& root.state !== "inactive") {
root.state = "inactive"
return
}
activeScreen = screenId
root.contentFolderName = folderName
root.type = type
switch (type) {
case "videoWallpaper":
root.typeEnum = ScreenPlayEnums.VideoWallpaper
state = "videoWallpaper"
return
case "htmlWallpaper":
state = "activeScene"
root.typeEnum = ScreenPlayEnums.HTMLWallpaper
return
case "qmlWallpaper":
state = "activeScene"
root.typeEnum = ScreenPlayEnums.QMLWallpaper
return
case "godotWallpaper":
state = "activeScene"
return
case "qmlWidget":
state = "activeWidget"
root.typeEnum = ScreenPlayEnums.QMLWidget
return
case "htmlWidget":
state = "activeWidget"
root.typeEnum = ScreenPlayEnums.HTMLWidget
return
case "standaloneWidget":
state = "activeWidget"
return
if (root.isWallpaper()) {
if (type === InstalledType.VideoWallpaper) {
root.state = "activeWallpaper"
} else {
root.state = "activeScene"
}
btnSetWallpaper.text = qsTr("Set Wallpaper")
} else {
root.state = "activeWidget"
btnSetWallpaper.text = qsTr("Set Widget")
}
}
}
MouseArea {
id: mouseAreaHelper
anchors.fill: parent
enabled: true
}
onActiveScreenChanged: {
txtHeadline.text = ScreenPlay.installedListModel.get(
activeScreen).screenTitle
if (ScreenPlay.installedListModel.get(
activeScreen).screenPreviewGIF === undefined) {
image.source = Qt.resolvedUrl(
ScreenPlay.globalVariables.localStoragePath + "/"
+ activeScreen + "/" + ScreenPlay.installedListModel.get(
activeScreen).screenPreview)
image.playing = false
} else {
image.source = Qt.resolvedUrl(
ScreenPlay.globalVariables.localStoragePath + "/"
+ activeScreen + "/" + ScreenPlay.installedListModel.get(
activeScreen).screenPreviewGIF)
image.playing = true
}
}
Item {
id: sidebarWrapper
anchors.fill: parent
MouseArea {
id: mouseAreaHelper
anchors.fill: parent
enabled: true
}
Item {
id: navBackground
height: navHeight
@ -311,16 +291,15 @@ Item {
Layout.fillWidth: true
}
ComboBox {
id:cbVideoFillMode
id: cbVideoFillMode
visible: false
Layout.fillWidth: true
textRole: "text"
valueRole: "value"
font.family: ScreenPlay.settings.font
currentIndex: root.indexOfValue(
cbVideoFillMode.model,
ScreenPlay.settings.videoFillMode)
currentIndex: root.indexOfValue(
cbVideoFillMode.model,
ScreenPlay.settings.videoFillMode)
model: [{
"value": ScreenPlayEnums.Stretch,
@ -344,7 +323,6 @@ Item {
Button {
id: btnSetWallpaper
text: qsTr("Set wallpaper")
Material.background: Material.accent
Material.foreground: "white"
font.family: ScreenPlay.settings.font
@ -352,17 +330,6 @@ Item {
icon.color: "white"
icon.width: 16
icon.height: 16
enabled: {
if (root.isWallpaper()) {
if (monitorSelection.activeMonitors.length > 0) {
return true
}
}
if (root.isWidget()) {
return true
}
return false
}
anchors {
bottom: parent.bottom
@ -371,6 +338,7 @@ Item {
}
onClicked: {
print(root.type, root.isWidget(),root.isWallpaper())
if (root.isWallpaper()) {
let activeMonitors = monitorSelection.getActiveMonitors(
)
@ -380,24 +348,21 @@ Item {
return
ScreenPlay.screenPlayManager.createWallpaper(
root.typeEnum,
cbVideoFillMode.currentValue,
ScreenPlay.globalVariables.localStoragePath + "/" + activeScreen,
ScreenPlay.installedListModel.get(activeScreen).screenPreview,
ScreenPlay.installedListModel.get(activeScreen).screenFile,
activeMonitors,
(Math.round( sliderVolume.value * 100) / 100),
root.type, cbVideoFillMode.currentValue,
ScreenPlay.globalVariables.localStoragePath + "/"
+ root.contentFolderName, ScreenPlay.installedListModel.get(
root.contentFolderName).screenPreview, ScreenPlay.installedListModel.get(
root.contentFolderName).screenFile, activeMonitors,
(Math.round(sliderVolume.value * 100) / 100),
true)
}
else if(root.isWidget())
{
} else if (root.isWidget()) {
print("widget")
ScreenPlay.screenPlayManager.createWidget(
ScreenPlay.globalVariables.localStoragePath
+ "/" + activeScreen,
+ "/" + root.contentFolderName,
ScreenPlay.installedListModel.get(
activeScreen).screenPreview,
typeEnum)
root.contentFolderName).screenPreview,
type)
}
root.state = "inactive"
monitorSelection.deselectAll()
@ -435,32 +400,6 @@ Item {
}
states: [
State {
name: "active"
PropertyChanges {
target: mouseAreaHelper
enabled: true
}
PropertyChanges {
target: root
anchors.rightMargin: 0
}
PropertyChanges {
target: image
opacity: 1
anchors.topMargin: 0
}
PropertyChanges {
target: btnSetWallpaper
text: qsTr("Set Wallpaper")
}
PropertyChanges {
target: txtHeadlineMonitor
opacity: 1
}
},
State {
name: "inactive"
@ -502,18 +441,13 @@ Item {
opacity: 1
anchors.topMargin: 0
}
PropertyChanges {
target: btnSetWallpaper
text: qsTr("Create Widget")
}
PropertyChanges {
target: txtHeadlineMonitor
opacity: 0
}
},
State {
name: "activeScene"
name: "activeWallpaper"
PropertyChanges {
target: mouseAreaHelper
enabled: true
@ -524,37 +458,6 @@ Item {
opacity: 1
anchors.topMargin: 0
}
PropertyChanges {
target: btnSetWallpaper
text: qsTr("Create Wallpaper")
}
PropertyChanges {
target: txtHeadlineMonitor
opacity: 1
}
PropertyChanges {
target: sliderVolume
opacity: 0
visible: false
}
},
State {
name: "videoWallpaper"
PropertyChanges {
target: mouseAreaHelper
enabled: true
}
PropertyChanges {
target: image
opacity: 1
anchors.topMargin: 0
}
PropertyChanges {
target: btnSetWallpaper
text: qsTr("Create Wallpaper")
}
PropertyChanges {
target: txtHeadlineMonitor
opacity: 1
@ -571,12 +474,57 @@ Item {
opacity: 1
visible: true
}
},
State {
name: "activeScene"
PropertyChanges {
target: mouseAreaHelper
enabled: true
}
PropertyChanges {
target: image
opacity: 1
anchors.topMargin: 0
}
PropertyChanges {
target: txtHeadlineMonitor
opacity: 1
}
PropertyChanges {
target: sliderVolume
opacity: 0
visible: false
}
}
]
transitions: [
Transition {
to: "active"
to: "inactive"
from: "*"
reversible: true
NumberAnimation {
target: image
property: "opacity"
duration: 200
}
NumberAnimation {
target: image
property: "anchors.topMargin"
duration: 400
}
NumberAnimation {
target: root
properties: "anchors.rightMargin"
duration: 250
easing.type: Easing.OutQuart
}
},
Transition {
to: "activeWidget"
from: "*"
SequentialAnimation {
NumberAnimation {
@ -601,29 +549,8 @@ Item {
}
},
Transition {
to: "inactive"
NumberAnimation {
target: image
property: "opacity"
duration: 200
}
NumberAnimation {
target: image
property: "anchors.topMargin"
duration: 400
}
NumberAnimation {
target: root
properties: "anchors.rightMargin"
duration: 250
easing.type: Easing.OutQuart
}
},
Transition {
to: "activeWidget"
to: "activeWallpaper"
from: "*"
SequentialAnimation {
NumberAnimation {
target: root
@ -648,32 +575,6 @@ Item {
},
Transition {
to: "activeScene"
SequentialAnimation {
NumberAnimation {
target: root
properties: "anchors.rightMargin"
duration: 250
easing.type: Easing.OutQuart
}
ParallelAnimation {
NumberAnimation {
target: image
property: "opacity"
duration: 200
}
NumberAnimation {
target: image
property: "anchors.topMargin"
duration: 100
}
}
}
},
Transition {
to: "videoWallpaper"
SequentialAnimation {
NumberAnimation {
target: root

View File

@ -3,6 +3,6 @@ namespace ScreenPlay {
ScreenPlay::GlobalVariables::GlobalVariables(QObject* parent)
: QObject(parent)
{
setLocalSettingsPath(QUrl { QStandardPaths::writableLocation(QStandardPaths::DataLocation) });
setLocalSettingsPath(QUrl { QStandardPaths::writableLocation(QStandardPaths::DataLocation) });
}
}

View File

@ -34,6 +34,7 @@
#pragma once
#include <QMetaType>
#include <QObject>
#include <QQmlEngine>
#include <QStandardPaths>
@ -51,6 +52,22 @@ namespace ScreenPlay {
*/
namespace InstalledType {
Q_NAMESPACE
enum class InstalledType {
Unknown,
VideoWallpaper,
QMLWallpaper,
HTMLWallpaper,
GodotWallpaper,
QMLWidget,
HTMLWidget,
};
Q_ENUM_NS(InstalledType)
}
namespace Enums {
Q_NAMESPACE
@ -63,7 +80,6 @@ namespace Enums {
};
Q_ENUM_NS(FillMode)
enum class WallpaperType {
VideoWallpaper,
QMLWallpaper,
@ -91,9 +107,6 @@ class GlobalVariables : public QObject {
public:
explicit GlobalVariables(QObject* parent = nullptr);
/*!
\property GlobalVariables::localStoragePath
\brief Returns the localStoragePath.
@ -135,6 +148,28 @@ public:
return m_version;
}
static QStringList getAvailableWallpaper()
{
return {
"qmlWallpaper",
"htmlWallpaper",
"videoWallpaper",
"godotWallpaper",
};
}
static QStringList getAvailableWidgets()
{
return {
"qmlWidget",
"htmlWidget",
};
}
static QStringList getAvailableTypes()
{
return { getAvailableWallpaper() + getAvailableWidgets() };
}
signals:
void localStoragePathChanged(QUrl localStoragePath);
void localSettingsPathChanged(QUrl localSettingsPath);

View File

@ -37,6 +37,7 @@ void InstalledListModel::init()
loadInstalledContent();
QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &InstalledListModel::reset);
QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, &InstalledListModel::reset);
}
/*!
@ -63,24 +64,26 @@ QVariant InstalledListModel::data(const QModelIndex& index, int role) const
return QVariant();
}
if (index.row() < rowCount())
if (row < rowCount())
switch (role) {
case TitleRole:
return m_screenPlayFiles.at(index.row()).m_title;
return m_screenPlayFiles.at(row).m_title;
case PreviewRole:
return m_screenPlayFiles.at(index.row()).m_preview;
return m_screenPlayFiles.at(row).m_preview;
case PreviewGIFRole:
return m_screenPlayFiles.at(index.row()).m_previewGIF;
return m_screenPlayFiles.at(row).m_previewGIF;
case TypeRole:
return m_screenPlayFiles.at(index.row()).m_type;
return QVariant::fromValue(m_screenPlayFiles.at(row).m_type);
case FolderIdRole:
return m_screenPlayFiles.at(index.row()).m_folderId;
return m_screenPlayFiles.at(row).m_folderId;
case FileIdRole:
return m_screenPlayFiles.at(index.row()).m_file;
return m_screenPlayFiles.at(row).m_file;
case AbsoluteStoragePathRole:
return m_screenPlayFiles.at(index.row()).m_absoluteStoragePath;
return m_screenPlayFiles.at(row).m_absoluteStoragePath;
case WorkshopIDRole:
return m_screenPlayFiles.at(index.row()).m_workshopID;
return m_screenPlayFiles.at(row).m_workshopID;
case TagsRole:
return m_screenPlayFiles.at(row).m_tags;
default:
return QVariant();
}
@ -101,6 +104,7 @@ QHash<int, QByteArray> InstalledListModel::roleNames() const
{ FileIdRole, "screenFile" },
{ AbsoluteStoragePathRole, "screenAbsoluteStoragePath" },
{ WorkshopIDRole, "screenWorkshopID" },
{ TagsRole, "screenTags" },
};
return roles;
}
@ -136,18 +140,7 @@ void InstalledListModel::loadInstalledContent()
if (!obj->contains("file") || !obj->contains("type"))
continue;
QStringList availableTypes {
"qmlWallpaper",
"htmlWallpaper",
"videoWallpaper",
"godotWallpaper",
"qmlWidget",
"htmlWidget",
"standaloneWidget"
};
if (availableTypes.contains(obj->value("type").toString())) {
if (GlobalVariables::getAvailableTypes().contains(obj->value("type").toString())) {
emit addInstalledItem(*obj, item.baseName());
}
@ -174,7 +167,7 @@ QVariantMap InstalledListModel::get(QString folderId)
map.insert("screenPreview", m_screenPlayFiles[i].m_preview);
map.insert("screenPreviewGIF", m_screenPlayFiles[i].m_previewGIF);
map.insert("screenFile", m_screenPlayFiles[i].m_file);
map.insert("screenType", m_screenPlayFiles[i].m_type);
map.insert("screenType", QVariant::fromValue(m_screenPlayFiles[i].m_type));
map.insert("screenAbsoluteStoragePath", m_screenPlayFiles[i].m_absoluteStoragePath);
map.insert("screenWorkshopID", m_screenPlayFiles[i].m_workshopID);
}

View File

@ -84,6 +84,7 @@ public:
FileIdRole,
AbsoluteStoragePathRole,
WorkshopIDRole,
TagsRole,
};
Q_ENUM(InstalledRole)
@ -92,6 +93,7 @@ public:
return m_count;
}
public slots:
void loadInstalledContent();
void append(const QJsonObject&, const QString&);

View File

@ -34,8 +34,12 @@
#pragma once
#include "globalvariables.h"
#include <QDebug>
#include <QJsonArray>
#include <QJsonObject>
#include <QMetaEnum>
#include <QString>
#include <QUrl>
#include <QVariant>
#include <QVariantList>
@ -60,7 +64,7 @@ struct ProjectFile {
if (obj.contains("file"))
m_file = obj.value("file");
if (obj.contains("previewThumbnail")){
if (obj.contains("previewThumbnail")) {
m_preview = obj.value("previewThumbnail");
} else {
if (obj.contains("preview"))
@ -73,21 +77,65 @@ struct ProjectFile {
if (obj.contains("title"))
m_title = obj.value("title");
if (obj.contains("type"))
m_type = obj.value("type").toString();
if (obj.contains("workshopid")) {
m_workshopID = obj.value("workshopid").toInt();
} else {
m_workshopID = 0;
m_workshopID = obj.value("workshopid").toInt(0);
}
if (obj.contains("tags")) {
if (obj.value("tags").isArray()) {
auto tagArray = obj.value("tags").toArray();
if (tagArray.size() > 0) {
for (const auto& tag : tagArray) {
m_tags.append(tag.toString());
}
qInfo() << m_tags;
}
}
}
m_absoluteStoragePath = QUrl(absolutePath.toString() + "/" + folderName);
m_folderId = folderName;
if (!obj.contains("type"))
return;
QString type = obj.value("type").toString();
if (type.endsWith("Wallpaper")) {
if (type.startsWith("video")) {
m_type = InstalledType::InstalledType::VideoWallpaper;
return;
}
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;
}
}
if (type.endsWith("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;
}
ProjectFile() {}
ProjectFile() { }
QVariant m_description;
QVariant m_file;
@ -96,10 +144,8 @@ struct ProjectFile {
QVariant m_title;
QString m_folderId;
QUrl m_absoluteStoragePath;
QString m_type;
QJsonObject m_settings;
int m_workshopID {0};
QVariantList m_tags; //TODO: Implement me!
InstalledType::InstalledType m_type = InstalledType::InstalledType::Unknown;
int m_workshopID { 0 };
QVariantList m_tags;
};
}

View File

@ -34,12 +34,12 @@
#pragma once
#include <QApplication>
#include <QClipboard>
#include <QCoreApplication>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QApplication>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkAccessManager>
@ -57,8 +57,8 @@
#include <iostream>
#include <optional>
#include "globalvariables.h"
#include "libzippp/libzippp.h"
#include "nlohmann/json.hpp"
namespace ScreenPlay {
@ -77,7 +77,6 @@ T QStringToEnum(const QString& key, const T defaultValue)
return defaultValue;
}
class Util : public QObject {
Q_OBJECT
@ -123,7 +122,7 @@ signals:
void requestNavigation(QString nav);
void requestNavigationActive(bool isActive);
void requestToggleWallpaperConfiguration();
void setSidebarItem(QString screenId, QString type);
void setSidebarItem(QString folderName, ScreenPlay::InstalledType::InstalledType type);
void allLicenseLoaded(QString licensesText);
void allDataProtectionLoaded(QString dataProtectionText);
void ffmpegAvailableChanged(bool ffmpegAvailable);
@ -134,7 +133,6 @@ public slots:
void copyToClipboard(const QString& text) const;
void openFolderInExplorer(const QString& url) const;
void requestAllLicenses();
void requestDataProtection();