diff --git a/ScreenPlay/qml.qrc b/ScreenPlay/qml.qrc index 2e91cf57..3ea744cd 100644 --- a/ScreenPlay/qml.qrc +++ b/ScreenPlay/qml.qrc @@ -87,5 +87,6 @@ qml/Create/WizardsFiles/HTMLWallpaperMain.html qml/Create/WizardsFiles/HTMLWidgetMain.html qml/Common/LicenseSelector.qml + qml/Common/Util.js diff --git a/ScreenPlay/qml/Common/Util.js b/ScreenPlay/qml/Common/Util.js new file mode 100644 index 00000000..2b5c9484 --- /dev/null +++ b/ScreenPlay/qml/Common/Util.js @@ -0,0 +1,14 @@ + +function isWallpaper(type) { + return type === InstalledType.VideoWallpaper + || type === InstalledType.HTMLWallpaper + || type === InstalledType.QMLWallpaper + || type === InstalledType.GifWallpaper + || type === InstalledType.WebsiteWallpaper + || type === InstalledType.GodotWallpaper +} + +function isWidget(type) { + return type === InstalledType.HTMLWidget + || type === InstalledType.QMLWidget +} diff --git a/ScreenPlay/qml/Installed/ScreenPlayItem.qml b/ScreenPlay/qml/Installed/ScreenPlayItem.qml index 9f789e84..d596c5ea 100644 --- a/ScreenPlay/qml/Installed/ScreenPlayItem.qml +++ b/ScreenPlay/qml/Installed/ScreenPlayItem.qml @@ -5,36 +5,27 @@ import QtQuick.Controls.Styles 1.4 import ScreenPlay 1.0 import ScreenPlay.Enums.InstalledType 1.0 +import "../Common/Util.js" as JSUtil + Item { id: root width: 320 height: 180 - property string customTitle: "name here" + property string customTitle + property string screenId property url absoluteStoragePath - property var type + property var type: InstalledType.Unknown property int workshopID: 0 property int itemIndex - property string screenId: "" signal openContextMenu(point position) onTypeChanged: { - switch (type) { - case InstalledType.Unknown: - return - case InstalledType.VideoWallpaper: - case InstalledType.QMLWallpaper: - case InstalledType.HTMLWallpaper: - case InstalledType.GodotWallpaper: - case InstalledType.GifWallpaper: - case InstalledType.WebsiteWallpaper: + if (JSUtil.isWallpaper()) { icnType.source = "qrc:/assets/icons/icon_widgets.svg" - return - case InstalledType.QMLWidget: - case InstalledType.HTMLWidget: + } else { icnType.source = "qrc:/assets/icons/icon_movie.svg" - return } } @@ -92,7 +83,6 @@ Item { spread: 0.2 color: "black" opacity: 0.4 - cornerRadius: 15 } @@ -121,6 +111,7 @@ Item { anchors.fill: parent sourceImage: m_preview sourceImageGIF: m_previewGIF + type: root.type absoluteStoragePath: m_absoluteStoragePath } diff --git a/ScreenPlay/qml/Installed/ScreenPlayItemImage.qml b/ScreenPlay/qml/Installed/ScreenPlayItemImage.qml index f39bb513..417ab52a 100644 --- a/ScreenPlay/qml/Installed/ScreenPlayItemImage.qml +++ b/ScreenPlay/qml/Installed/ScreenPlayItemImage.qml @@ -9,6 +9,7 @@ Item { property string absoluteStoragePath property string sourceImage property string sourceImageGIF + property var type: InstalledType.Unknown function enter() { if (root.sourceImageGIF != "") { diff --git a/ScreenPlay/qml/Installed/Sidebar.qml b/ScreenPlay/qml/Installed/Sidebar.qml index 922a7f10..4bd6e54f 100644 --- a/ScreenPlay/qml/Installed/Sidebar.qml +++ b/ScreenPlay/qml/Installed/Sidebar.qml @@ -12,6 +12,7 @@ import ScreenPlay.Enums.InstalledType 1.0 import "../Monitors" import "../Common" as Common +import "../Common/Util.js" as JSUtil Item { id: root @@ -43,7 +44,8 @@ Item { image.playing = true } - if (isWidget() || (monitorSelection.activeMonitors.length > 0)) { + if (JSUtil.isWidget(root.type) + || (monitorSelection.activeMonitors.length > 0)) { btnSetWallpaper.enabled = true return } @@ -51,17 +53,6 @@ Item { btnSetWallpaper.enabled = false } - function isWallpaper() { - return type === InstalledType.VideoWallpaper - || type === InstalledType.HTMLWallpaper - || type === InstalledType.QMLWallpaper - } - - function isWidget() { - return type === InstalledType.HTMLWidget - || type === InstalledType.QMLWidget - } - function indexOfValue(model, value) { for (var i = 0; i < model.length; i++) { @@ -87,7 +78,7 @@ Item { root.contentFolderName = folderName root.type = type - if (root.isWallpaper()) { + if (JSUtil.isWallpaper(root.type)) { if (type === InstalledType.VideoWallpaper) { root.state = "activeWallpaper" } else { @@ -117,7 +108,6 @@ Item { id: sidebarWrapper anchors.fill: parent - Item { id: navBackground height: navHeight @@ -271,7 +261,7 @@ Item { availableHeight: height fontSize: 11 onActiveMonitorsChanged: { - if (isWidget()) { + if (JSUtil.isWidget(root.type)) { btnSetWallpaper.enabled = true return } @@ -363,7 +353,7 @@ Item { + "/" + root.contentFolderName const previewImage = ScreenPlay.installedListModel.get( root.contentFolderName).m_preview - if (root.isWallpaper()) { + if (JSUtil.isWallpaper(root.type)) { let activeMonitors = monitorSelection.getActiveMonitors( ) @@ -374,7 +364,8 @@ Item { // We only have sliderVolume if it is a VideoWallpaper let volume = 0.0 if (type === InstalledType.VideoWallpaper) { - volume = Math.round(sliderVolume.slider.value * 100) / 100 + volume = Math.round( + sliderVolume.slider.value * 100) / 100 } const screenFile = ScreenPlay.installedListModel.get( @@ -387,7 +378,7 @@ Item { 1.0, {}, true) } - if (root.isWidget()) { + if (JSUtil.isWidget(root.type)) { ScreenPlay.screenPlayManager.createWidget( type, Qt.point(0, 0), absoluteStoragePath, previewImage, {}, true) @@ -404,7 +395,6 @@ Item { State { name: "inactive" - PropertyChanges { target: root anchors.rightMargin: -root.width @@ -442,7 +432,6 @@ Item { State { name: "activeWallpaper" - PropertyChanges { target: image opacity: 1 diff --git a/ScreenPlay/src/globalvariables.h b/ScreenPlay/src/globalvariables.h index 7fe6b6fa..e26c3db7 100644 --- a/ScreenPlay/src/globalvariables.h +++ b/ScreenPlay/src/globalvariables.h @@ -52,40 +52,6 @@ namespace ScreenPlay { */ -namespace InstalledType { - Q_NAMESPACE - - enum class InstalledType { - Unknown, - - VideoWallpaper, - QMLWallpaper, - HTMLWallpaper, - GodotWallpaper, - GifWallpaper, - WebsiteWallpaper, - - QMLWidget, - HTMLWidget, - }; - Q_ENUM_NS(InstalledType) - - static bool isWallpaper(const InstalledType type) - { - return (type == InstalledType::VideoWallpaper - || type == InstalledType::QMLWallpaper - || type == InstalledType::HTMLWallpaper - || type == InstalledType::GifWallpaper - || type == InstalledType::WebsiteWallpaper - || type == InstalledType::GodotWallpaper); - } - - static bool isWidget(const InstalledType type) - { - return (type == InstalledType::QMLWidget || type == InstalledType::HTMLWidget); - } -} - namespace SearchType { Q_NAMESPACE @@ -114,6 +80,45 @@ namespace FillMode { } +namespace InstalledType { + Q_NAMESPACE + + // When changing the enum, one also needs to change: + // GlobalVariables::getAvailableWallpaper + // GlobalVariables::getAvailableWidgets + // Common/Util.js isWallpaper() and isWidget() + // ScreenPlayWallpaper: BaseWindow::parseWallpaperType() + enum class InstalledType { + Unknown, + //Wallpaper + VideoWallpaper, + QMLWallpaper, + HTMLWallpaper, + GodotWallpaper, + GifWallpaper, + WebsiteWallpaper, + //Widgets + QMLWidget, + HTMLWidget, + }; + Q_ENUM_NS(InstalledType) + + static bool isWallpaper(const InstalledType type) + { + return (type == InstalledType::VideoWallpaper + || type == InstalledType::QMLWallpaper + || type == InstalledType::HTMLWallpaper + || type == InstalledType::GifWallpaper + || type == InstalledType::WebsiteWallpaper + || type == InstalledType::GodotWallpaper); + } + + static bool isWidget(const InstalledType type) + { + return (type == InstalledType::QMLWidget || type == InstalledType::HTMLWidget); + } +} + class GlobalVariables : public QObject { Q_OBJECT @@ -126,6 +131,30 @@ class GlobalVariables : public QObject { public: explicit GlobalVariables(QObject* parent = nullptr); + static QStringList getAvailableWallpaper() + { + return { + "qmlWallpaper", + "htmlWallpaper", + "videoWallpaper", + "godotWallpaper", + "gifWallpaper", + "websiteWallpaper" + }; + } + static QStringList getAvailableWidgets() + { + return { + "qmlWidget", + "htmlWidget", + }; + } + + static QStringList getAvailableTypes() + { + return { getAvailableWallpaper() + getAvailableWidgets() }; + } + /*! \property GlobalVariables::localStoragePath \brief Returns the localStoragePath. @@ -167,28 +196,6 @@ 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);