1 | // Copyright (C) 2022 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef APPLICATIONSETTINGS_H |
5 | #define APPLICATIONSETTINGS_H |
6 | |
7 | #include <QObject> |
8 | #include <QSettings> |
9 | #include <QList> |
10 | #include <QAbstractListModel> |
11 | |
12 | class EffectManager; |
13 | |
14 | class ImagesModel : public QAbstractListModel |
15 | { |
16 | Q_OBJECT |
17 | Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) |
18 | Q_PROPERTY(QString currentImageFile READ currentImageFile NOTIFY currentImageFileChanged) |
19 | |
20 | public: |
21 | struct ImagesData { |
22 | QString name; |
23 | QString file; |
24 | int width = 0; |
25 | int height = 0; |
26 | bool canRemove = true; |
27 | }; |
28 | |
29 | enum ModelRoles { |
30 | Name = Qt::UserRole + 1, |
31 | File, |
32 | Width, |
33 | Height, |
34 | CanRemove |
35 | }; |
36 | |
37 | explicit ImagesModel(QObject *effectManager); |
38 | |
39 | int rowCount(const QModelIndex & = QModelIndex()) const final; |
40 | QVariant data(const QModelIndex &index, int role) const final; |
41 | QHash<int, QByteArray> roleNames() const final; |
42 | |
43 | QString currentImageFile() const; |
44 | |
45 | public Q_SLOTS: |
46 | void setImageIndex(int index); |
47 | |
48 | Q_SIGNALS: |
49 | void rowCountChanged(); |
50 | void currentImageFileChanged(); |
51 | |
52 | private: |
53 | friend class ApplicationSettings; |
54 | QList<ImagesData> m_modelList; |
55 | EffectManager *m_effectManager = nullptr; |
56 | int m_currentIndex = 0; |
57 | }; |
58 | |
59 | class : public QAbstractListModel |
60 | { |
61 | Q_OBJECT |
62 | Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) |
63 | |
64 | public: |
65 | struct { |
66 | QString ; |
67 | QString ; |
68 | }; |
69 | |
70 | enum { |
71 | = Qt::UserRole + 1, |
72 | |
73 | }; |
74 | |
75 | explicit (QObject *effectManager); |
76 | |
77 | int (const QModelIndex & = QModelIndex()) const final; |
78 | QVariant (const QModelIndex &index, int role) const final; |
79 | QHash<int, QByteArray> () const final; |
80 | |
81 | Q_SIGNALS: |
82 | void (); |
83 | |
84 | private: |
85 | friend class ApplicationSettings; |
86 | QList<MenusData> ; |
87 | EffectManager * = nullptr; |
88 | }; |
89 | |
90 | class CustomNodesModel : public QAbstractListModel |
91 | { |
92 | Q_OBJECT |
93 | Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) |
94 | |
95 | public: |
96 | struct NodesModelData { |
97 | QString path; |
98 | }; |
99 | |
100 | enum ModelRoles { |
101 | Path = Qt::UserRole + 1, |
102 | }; |
103 | |
104 | explicit CustomNodesModel(QObject *effectManager); |
105 | |
106 | int rowCount(const QModelIndex & = QModelIndex()) const final; |
107 | QVariant data(const QModelIndex &index, int role) const final; |
108 | QHash<int, QByteArray> roleNames() const final; |
109 | |
110 | Q_SIGNALS: |
111 | void rowCountChanged(); |
112 | |
113 | private: |
114 | friend class ApplicationSettings; |
115 | QList<NodesModelData> m_modelList; |
116 | EffectManager *m_effectManager = nullptr; |
117 | }; |
118 | |
119 | class ApplicationSettings : public QObject |
120 | { |
121 | Q_OBJECT |
122 | Q_PROPERTY(ImagesModel *sourceImagesModel READ sourceImagesModel NOTIFY sourceImagesModelChanged) |
123 | Q_PROPERTY(ImagesModel *backgroundImagesModel READ backgroundImagesModel NOTIFY backgroundImagesModelChanged) |
124 | Q_PROPERTY(MenusModel *recentProjectsModel READ recentProjectsModel NOTIFY recentProjectsModelChanged) |
125 | Q_PROPERTY(CustomNodesModel *customNodesModel READ customNodesModel NOTIFY customNodesModelChanged) |
126 | Q_PROPERTY(bool useLegacyShaders READ useLegacyShaders WRITE setUseLegacyShaders NOTIFY useLegacyShadersChanged) |
127 | Q_PROPERTY(QString codeFontFile READ codeFontFile WRITE setCodeFontFile NOTIFY codeFontFileChanged) |
128 | Q_PROPERTY(int codeFontSize READ codeFontSize WRITE setCodeFontSize NOTIFY codeFontSizeChanged) |
129 | Q_PROPERTY(QString defaultResourcePath READ defaultResourcePath) |
130 | |
131 | public: |
132 | explicit ApplicationSettings(QObject *parent = nullptr); |
133 | |
134 | ImagesModel *sourceImagesModel() const; |
135 | ImagesModel *backgroundImagesModel() const; |
136 | MenusModel *recentProjectsModel() const; |
137 | CustomNodesModel *customNodesModel() const; |
138 | bool useLegacyShaders() const; |
139 | QString codeFontFile() const; |
140 | int codeFontSize() const; |
141 | |
142 | public Q_SLOTS: |
143 | void refreshSourceImagesModel(); |
144 | bool addSourceImage(const QString &sourceImage, bool canRemove = true, bool updateSettings = true); |
145 | bool removeSourceImageFromSettings(const QString &sourceImage); |
146 | bool removeSourceImage(const QString &sourceImage); |
147 | bool removeSourceImage(int index); |
148 | void updateRecentProjectsModel(const QString &projectName = QString(), const QString &projectFile = QString()); |
149 | void clearRecentProjectsModel(); |
150 | void removeRecentProjectsModel(const QString &projectFile); |
151 | void setUseLegacyShaders(bool legacyShaders); |
152 | void setCodeFontFile(const QString &font); |
153 | void setCodeFontSize(int size); |
154 | void resetCodeFont(); |
155 | QString defaultResourcePath(); |
156 | QStringList customNodesPaths() const; |
157 | void refreshCustomNodesModel(); |
158 | bool addCustomNodesPath(const QString &path, bool updateSettings = true); |
159 | bool removeCustomNodesPath(int index); |
160 | |
161 | Q_SIGNALS: |
162 | void sourceImagesModelChanged(); |
163 | void backgroundImagesModelChanged(); |
164 | void recentProjectsModelChanged(); |
165 | void customNodesModelChanged(); |
166 | void useLegacyShadersChanged(); |
167 | void codeFontFileChanged(); |
168 | void codeFontSizeChanged(); |
169 | |
170 | private: |
171 | QSettings m_settings; |
172 | EffectManager *m_effectManager = nullptr; |
173 | ImagesModel *m_sourceImagesModel = nullptr; |
174 | ImagesModel *m_backgroundImagesModel = nullptr; |
175 | MenusModel *m_recentProjectsModel = nullptr; |
176 | CustomNodesModel *m_customNodesModel = nullptr; |
177 | }; |
178 | |
179 | #endif // APPLICATIONSETTINGS_H |
180 | |