1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-08 03:52:42 +01:00

Add search type enum

Change FillMode namespace
This commit is contained in:
Elias Steurer 2020-06-19 21:27:26 +02:00
parent 7b4a5cb747
commit 4f2854ba5a
18 changed files with 101 additions and 83 deletions

View File

@ -90,11 +90,11 @@ App::App()
// Registers the enums from globalvariables.
// Apparently this is the only way for qml to work
// https://www.kdab.com/new-qt-5-8-meta-object-support-namespaces/
qRegisterMetaType<Enums::FillMode>();
qmlRegisterUncreatableMetaObject(ScreenPlay::Enums::staticMetaObject,
"ScreenPlayEnums",
qRegisterMetaType<FillMode::FillMode>();
qmlRegisterUncreatableMetaObject(ScreenPlay::FillMode::staticMetaObject,
"ScreenPlay.Enums.FillMode",
1, 0,
"ScreenPlayEnums",
"FillMode",
"Error: only enums");
qRegisterMetaType<InstalledType::InstalledType>();
@ -104,6 +104,13 @@ App::App()
"InstalledType",
"Error: only enums");
qRegisterMetaType<SearchType::SearchType>();
qmlRegisterUncreatableMetaObject(ScreenPlay::SearchType::staticMetaObject,
"ScreenPlay.Enums.SearchType",
1, 0,
"SearchType",
"Error: only enums");
qmlRegisterAnonymousType<GlobalVariables>("ScreenPlay", 1);
qmlRegisterAnonymousType<ScreenPlayManager>("ScreenPlay", 1);

View File

@ -5,6 +5,8 @@ import QtQuick.Controls.Styles 1.4
import QtGraphicalEffects 1.0
import ScreenPlay 1.0
import ScreenPlay.Enums.InstalledType 1.0
import ScreenPlay.Enums.SearchType 1.0
Item {
id: pageInstalled
@ -18,7 +20,7 @@ Item {
Component.onCompleted: {
pageInstalled.state = "in"
ScreenPlay.installedListFilter.sortByRoleType("All")
ScreenPlay.installedListFilter.sortBySearchType(SearchType.All)
checkIsContentInstalled()
}
@ -248,7 +250,7 @@ Item {
icon.source: "qrc:/assets/icons/icon_installed.svg"
onClicked: {
setSidebarActive(false)
ScreenPlay.installedListFilter.sortByRoleType("All")
ScreenPlay.installedListFilter.sortBySearchType(SearchType.All)
}
}
TabButton {
@ -263,7 +265,7 @@ Item {
icon.source: "qrc:/assets/icons/icon_code.svg"
onClicked: {
setSidebarActive(false)
ScreenPlay.installedListFilter.sortByRoleType("Scenes")
ScreenPlay.installedListFilter.sortBySearchType(SearchType.Scenes)
}
}
TabButton {
@ -278,7 +280,7 @@ Item {
icon.source: "qrc:/assets/icons/icon_movie.svg"
onClicked: {
setSidebarActive(false)
ScreenPlay.installedListFilter.sortByRoleType("Videos")
ScreenPlay.installedListFilter.sortBySearchType(SearchType.Wallpaper)
}
}
TabButton {
@ -293,7 +295,7 @@ Item {
icon.source: "qrc:/assets/icons/icon_widgets.svg"
onClicked: {
setSidebarActive(false)
ScreenPlay.installedListFilter.sortByRoleType("Widgets")
ScreenPlay.installedListFilter.sortBySearchType(SearchType.Widgets)
}
}
}

View File

@ -6,7 +6,7 @@ import QtQuick.Layouts 1.12
import QtQuick.Controls.Material 2.12
import ScreenPlay 1.0
import ScreenPlayEnums 1.0
import ScreenPlay.Enums.FillMode 1.0
import ScreenPlay.Enums.InstalledType 1.0
import "../Monitors"
@ -311,19 +311,19 @@ Item {
ScreenPlay.settings.videoFillMode)
model: [{
"value": ScreenPlayEnums.Stretch,
"value": InstalledType.Stretch,
"text": qsTr("Stretch")
}, {
"value": ScreenPlayEnums.Fill,
"value": InstalledType.Fill,
"text": qsTr("Fill")
}, {
"value": ScreenPlayEnums.Contain,
"value": InstalledType.Contain,
"text": qsTr("Contain")
}, {
"value": ScreenPlayEnums.Cover,
"value": InstalledType.Cover,
"text": qsTr("Cover")
}, {
"value": ScreenPlayEnums.Scale_Down,
"value": InstalledType.Scale_Down,
"text": qsTr("Scale-Down")
}]
}

View File

@ -5,7 +5,7 @@ import QtQuick.Controls.Material 2.2
import QtQuick.Layouts 1.3
import ScreenPlay 1.0
import ScreenPlayEnums 1.0
import ScreenPlay.Enums.FillMode 1.0
import "../Common/" as SP
@ -86,19 +86,19 @@ ColumnLayout {
model: [{
"value": ScreenPlayEnums.Stretch,
"value": FillMode.Stretch,
"text": qsTr("Stretch")
}, {
"value": ScreenPlayEnums.Fill,
"value": FillMode.Fill,
"text": qsTr("Fill")
}, {
"value": ScreenPlayEnums.Contain,
"value": FillMode.Contain,
"text": qsTr("Contain")
}, {
"value": ScreenPlayEnums.Cover,
"value": FillMode.Cover,
"text": qsTr("Cover")
}, {
"value": ScreenPlayEnums.Scale_Down,
"value": FillMode.Scale_Down,
"text": qsTr("Scale-Down")
}]
}

View File

@ -5,7 +5,7 @@ import QtQuick.Controls.Material 2.2
import QtQuick.Layouts 1.3
import ScreenPlay 1.0
import ScreenPlayEnums 1.0
import ScreenPlay.Enums.InstalledType 1.0
import "../Common/" as SP
Item {
@ -107,7 +107,7 @@ Item {
videoControlWrapper.state = "visible"
customPropertiesGridView.model = listModel
if (type === ScreenPlayEnums.VideoWallpaper) {
if (type === InstalledType.VideoWallpaper) {
customPropertiesGridView.state = "hidden"
videoControlWrapper.state = "visible"
} else {

View File

@ -7,7 +7,7 @@ import QtGraphicalEffects 1.0
import Qt.labs.platform 1.0
import ScreenPlay 1.0
import ScreenPlayEnums 1.0
import ScreenPlay.Enums.FillMode 1.0
import Settings 1.0
import "../Common"
@ -322,19 +322,19 @@ Item {
cbVideoFillMode.comboBox.currentValue)
model: [{
"value": ScreenPlayEnums.Stretch,
"value": FillMode.Stretch,
"text": qsTr("Stretch")
}, {
"value": ScreenPlayEnums.Fill,
"value": FillMode.Fill,
"text": qsTr("Fill")
}, {
"value": ScreenPlayEnums.Contain,
"value": FillMode.Contain,
"text": qsTr("Contain")
}, {
"value": ScreenPlayEnums.Cover,
"value": FillMode.Cover,
"text": qsTr("Cover")
}, {
"value": ScreenPlayEnums.Scale_Down,
"value": FillMode.Scale_Down,
"text": qsTr("Scale-Down")
}]
}

View File

@ -57,10 +57,12 @@ namespace InstalledType {
enum class InstalledType {
Unknown,
VideoWallpaper,
QMLWallpaper,
HTMLWallpaper,
GodotWallpaper,
QMLWidget,
HTMLWidget,
};
@ -68,7 +70,21 @@ namespace InstalledType {
}
namespace Enums {
namespace SearchType {
Q_NAMESPACE
enum class SearchType {
All,
Text,
Scenes, //QML, HTML, Godot wallpaper
Wallpaper,
Widget,
};
Q_ENUM_NS(SearchType)
}
namespace FillMode {
Q_NAMESPACE
enum class FillMode {

View File

@ -20,42 +20,13 @@ InstalledListFilter::InstalledListFilter(const std::shared_ptr<InstalledListMode
{
setSourceModel(m_ilm.get());
setFilterRole(InstalledListModel::InstalledRole::TitleRole);
sortByRoleType("All");
}
/*!
\brief Set the filter proxy to sort by the given \a type. This can be:
\list
\li All
\li Videos
\li Widgets
\li Scenes
\endlist
*/
void InstalledListFilter::sortByRoleType(QString type)
{
if (type == "All") {
setFilterRole(InstalledListModel::InstalledRole::TitleRole);
setFilterWildcard("*");
} else if (type == "Videos") {
setFilterRole(InstalledListModel::InstalledRole::TypeRole);
setFilterFixedString("videoWallpaper");
} else if (type == "Widgets") {
setFilterRole(InstalledListModel::InstalledRole::TypeRole);
setFilterWildcard("*Widget");
} else if (type == "Scenes") {
setFilterRole(InstalledListModel::InstalledRole::TypeRole);
setFilterFixedString("qmlWallpaper");
}
sort(0);
}
/*!
\brief Invoked when the user uses the quicksearch at the top right of the installed page.
Uses the \a name to sort by name. This name is saved in the project.json title.
*/
void InstalledListFilter::sortByName(QString name)
void InstalledListFilter::sortByName(const QString& name)
{
setFilterRole(InstalledListModel::InstalledRole::TitleRole);
setFilterCaseSensitivity(Qt::CaseInsensitive);
@ -63,6 +34,17 @@ void InstalledListFilter::sortByName(QString name)
sort(0);
}
void InstalledListFilter::sortBySearchType(const ScreenPlay::SearchType::SearchType searchType)
{
if (searchType == SearchType::SearchType::All) {
resetFilter();
return;
}
setFilterRole(InstalledListModel::InstalledRole::SearchTypeRole);
setFilterFixedString(QVariant::fromValue(searchType).toString());
sort(0);
}
/*!
\brief Resets the filter and sorts by title.
*/
@ -72,4 +54,5 @@ void InstalledListFilter::resetFilter()
setFilterWildcard("*");
sort(0);
}
}

View File

@ -34,11 +34,13 @@
#pragma once
#include "installedlistmodel.h"
#include <QRegExp>
#include <QSortFilterProxyModel>
#include <memory>
#include "globalvariables.h"
#include "installedlistmodel.h"
namespace ScreenPlay {
class InstalledListFilter : public QSortFilterProxyModel {
@ -48,11 +50,12 @@ public:
InstalledListFilter(const std::shared_ptr<InstalledListModel>& ilm);
public slots:
void sortByRoleType(QString type);
void sortByName(QString name);
void sortBySearchType(const ScreenPlay::SearchType::SearchType searchType);
void sortByName(const QString& name);
void resetFilter();
private:
const std::shared_ptr<InstalledListModel> m_ilm;
ScreenPlay::SearchType::SearchType m_searchType = ScreenPlay::SearchType::SearchType::All;
};
}

View File

@ -84,6 +84,8 @@ QVariant InstalledListModel::data(const QModelIndex& index, int role) const
return m_screenPlayFiles.at(row).m_workshopID;
case TagsRole:
return m_screenPlayFiles.at(row).m_tags;
case SearchTypeRole:
return QVariant::fromValue(m_screenPlayFiles.at(row).m_searchType);
default:
return QVariant();
}
@ -105,6 +107,7 @@ QHash<int, QByteArray> InstalledListModel::roleNames() const
{ AbsoluteStoragePathRole, "screenAbsoluteStoragePath" },
{ WorkshopIDRole, "screenWorkshopID" },
{ TagsRole, "screenTags" },
{ SearchTypeRole, "screenSearchType" },
};
return roles;
}
@ -153,7 +156,7 @@ void InstalledListModel::loadInstalledContent()
});
}
QVariantMap InstalledListModel::get(QString folderId)
QVariantMap InstalledListModel::get(QString folderId) const
{
QVariantMap map;

View File

@ -85,6 +85,7 @@ public:
AbsoluteStoragePathRole,
WorkshopIDRole,
TagsRole,
SearchTypeRole,
};
Q_ENUM(InstalledRole)
@ -93,13 +94,12 @@ public:
return m_count;
}
public slots:
void loadInstalledContent();
void append(const QJsonObject&, const QString&);
void reset();
void init();
QVariantMap get(QString folderId);
QVariantMap get(QString folderId) const;
void setCount(int count)
{

View File

@ -102,9 +102,11 @@ struct ProjectFile {
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;
@ -120,6 +122,7 @@ struct ProjectFile {
}
if (type.endsWith("Widget")) {
m_searchType = SearchType::SearchType::Widget;
if (type.startsWith("qml")) {
m_type = InstalledType::InstalledType::QMLWidget;
return;
@ -144,6 +147,7 @@ struct ProjectFile {
QString m_folderId;
QUrl m_absoluteStoragePath;
InstalledType::InstalledType m_type = InstalledType::InstalledType::Unknown;
SearchType::SearchType m_searchType = SearchType::SearchType::All;
int m_workshopID { 0 };
QVariantList m_tags;
};

View File

@ -39,7 +39,7 @@ ScreenPlayManager::ScreenPlayManager(
*/
void ScreenPlayManager::createWallpaper(
const InstalledType::InstalledType type,
const Enums::FillMode fillMode,
const FillMode::FillMode fillMode,
const QString& absoluteStoragePath,
const QString& previewImage,
const QString& file,
@ -366,7 +366,7 @@ void ScreenPlayManager::loadProfiles()
QString typeString = wallpaperObj.value("type").toString();
auto type = QStringToEnum<InstalledType::InstalledType>(typeString, InstalledType::InstalledType::VideoWallpaper);
auto fillMode = QStringToEnum<Enums::FillMode>(fillModeString, Enums::FillMode::Cover);
auto fillMode = QStringToEnum<FillMode::FillMode>(fillModeString, FillMode::FillMode::Cover);
createWallpaper(type, fillMode, absolutePath, previewImage, file, monitors, volume, false);
monitors.clear();

View File

@ -94,7 +94,7 @@ public slots:
// moc needs full enum namespace info see QTBUG-58454
void createWallpaper(
const ScreenPlay::InstalledType::InstalledType type,
const ScreenPlay::Enums::FillMode fillMode,
const ScreenPlay::FillMode::FillMode fillMode,
const QString& absoluteStoragePath,
const QString& previewImage,
const QString& file,

View File

@ -21,7 +21,7 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(
const QString& previewImage,
const QString& file,
const float volume,
const Enums::FillMode fillMode,
const FillMode::FillMode fillMode,
const InstalledType::InstalledType type,
const bool checkWallpaperVisible,
QObject* parent)

View File

@ -60,7 +60,7 @@ class ScreenPlayWallpaper : public QObject {
Q_PROPERTY(QString previewImage READ previewImage WRITE setPreviewImage NOTIFY previewImageChanged)
Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged)
Q_PROPERTY(Enums::FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
Q_PROPERTY(FillMode::FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
Q_PROPERTY(InstalledType::InstalledType type READ type WRITE setType NOTIFY typeChanged)
public:
@ -72,7 +72,7 @@ public:
const QString& previewImage,
const QString& file,
const float volume,
const Enums::FillMode fillMode,
const FillMode::FillMode fillMode,
const InstalledType::InstalledType type,
const bool checkWallpaperVisible,
QObject* parent = nullptr);
@ -104,7 +104,7 @@ public:
return m_file;
}
Enums::FillMode fillMode() const
FillMode::FillMode fillMode() const
{
return m_fillMode;
}
@ -132,7 +132,7 @@ signals:
void appIDChanged(QString appID);
void typeChanged(InstalledType::InstalledType type);
void fileChanged(QString file);
void fillModeChanged(Enums::FillMode fillMode);
void fillModeChanged(FillMode::FillMode fillMode);
void absolutePathChanged(QString absolutePath);
void profileJsonObjectChanged(QJsonObject profileJsonObject);
void volumeChanged(float volume);
@ -187,7 +187,7 @@ public slots:
emit fileChanged(m_file);
}
void setFillMode(Enums::FillMode fillMode)
void setFillMode(FillMode::FillMode fillMode)
{
if (m_fillMode == fillMode)
return;
@ -236,7 +236,7 @@ private:
QString m_previewImage;
InstalledType::InstalledType m_type;
Enums::FillMode m_fillMode;
FillMode::FillMode m_fillMode;
QString m_appID;
QString m_absolutePath;
QString m_file;

View File

@ -64,9 +64,9 @@ Settings::Settings(const std::shared_ptr<GlobalVariables>& globalVariables,
setHighPriorityStart(m_qSettings.value("ScreenPlayExecutable", false).toBool());
if (m_qSettings.contains("VideoFillMode")) {
auto value = m_qSettings.value("VideoFillMode").toString();
setVideoFillMode(QStringToEnum<Enums::FillMode>(value, Enums::FillMode::Cover));
setVideoFillMode(QStringToEnum<FillMode::FillMode>(value, FillMode::FillMode::Cover));
} else {
setVideoFillMode(Enums::FillMode::Cover);
setVideoFillMode(FillMode::FillMode::Cover);
}
if (m_qSettings.contains("Theme")) {

View File

@ -83,7 +83,7 @@ class Settings : public QObject {
Q_PROPERTY(bool checkWallpaperVisible READ checkWallpaperVisible WRITE setCheckWallpaperVisible NOTIFY checkWallpaperVisibleChanged)
Q_PROPERTY(bool offlineMode READ offlineMode WRITE setOfflineMode NOTIFY offlineModeChanged)
Q_PROPERTY(ScreenPlay::Enums::FillMode videoFillMode READ videoFillMode WRITE setVideoFillMode NOTIFY videoFillModeChanged)
Q_PROPERTY(ScreenPlay::FillMode::FillMode videoFillMode READ videoFillMode WRITE setVideoFillMode NOTIFY videoFillModeChanged)
Q_PROPERTY(Language language READ language WRITE setLanguage NOTIFY languageChanged)
Q_PROPERTY(Theme theme READ theme WRITE setTheme NOTIFY themeChanged)
@ -159,7 +159,7 @@ public:
return m_checkWallpaperVisible;
}
ScreenPlay::Enums::FillMode videoFillMode() const
ScreenPlay::FillMode::FillMode videoFillMode() const
{
return m_videoFillMode;
}
@ -196,7 +196,7 @@ signals:
void silentStartChanged(bool silentStart);
void anonymousTelemetryChanged(bool anonymousTelemetry);
void checkWallpaperVisibleChanged(bool checkWallpaperVisible);
void videoFillModeChanged(ScreenPlay::Enums::FillMode videoFillMode);
void videoFillModeChanged(ScreenPlay::FillMode::FillMode videoFillMode);
void languageChanged(Language language);
void fontChanged(QString font);
void themeChanged(Theme theme);
@ -314,7 +314,7 @@ public slots:
emit checkWallpaperVisibleChanged(m_checkWallpaperVisible);
}
void setVideoFillMode(ScreenPlay::Enums::FillMode videoFillMode)
void setVideoFillMode(ScreenPlay::FillMode::FillMode videoFillMode)
{
if (m_videoFillMode == videoFillMode)
return;
@ -374,7 +374,7 @@ private:
QString m_gitBuildHash;
QString m_decoder;
ScreenPlay::Enums::FillMode m_videoFillMode { ScreenPlay::Enums::FillMode::Cover };
ScreenPlay::FillMode::FillMode m_videoFillMode { ScreenPlay::FillMode::FillMode::Cover };
Language m_language { Language::En };
Theme m_theme { Theme::System };
QString m_font { "Roboto" };