1/*
2 * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#ifndef ICONSMANAGER_H
18#define ICONSMANAGER_H
19
20#include <QMap>
21#include <QObject>
22#include <QPixmap>
23#include <memory>
24#include "parser/parserutils.h"
25
26struct IconSet {
27 QString name;
28 QString displayName;
29};
30
31using PIconSet = std::shared_ptr<IconSet>;
32
33class QToolButton;
34class QPushButton;
35class IconsManager : public QObject
36{
37 Q_OBJECT
38public:
39 using PPixmap = std::shared_ptr<QPixmap>;
40 enum IconName {
41 GUTTER_SYNTAX_ERROR,
42 GUTTER_SYNTAX_WARNING,
43 GUTTER_BREAKPOINT,
44 GUTTER_ACTIVEBREAKPOINT,
45 GUTTER_BOOKMARK,
46
47 PARSER_TYPE,
48 PARSER_CLASS,
49 PARSER_NAMESPACE,
50 PARSER_DEFINE,
51 PARSER_ENUM,
52 PARSER_GLOBAL_METHOD,
53 PARSER_INHERITED_PROTECTED_METHOD,
54 PARSER_INHERITED_METHOD,
55 PARSER_PROTECTED_METHOD,
56 PARSER_PUBLIC_METHOD,
57 PARSER_PRIVATE_METHOD,
58 PARSER_GLOBAL_VAR,
59 PARSER_INHERITED_PROTECTD_VAR,
60 PARSER_INHERITED_VAR,
61 PARSER_PROTECTED_VAR,
62 PARSER_PUBLIC_VAR,
63 PARSER_PRIVATE_VAR,
64 PARSER_KEYWORD,
65 PARSER_CODE_SNIPPET,
66 PARSER_LOCAL_VAR,
67
68 FILESYSTEM_GIT,
69 FILESYSTEM_FOLDER,
70 FILESYSTEM_FILE,
71 FILESYSTEM_CFILE,
72 FILESYSTEM_HFILE,
73 FILESYSTEM_PROJECTFILE,
74 FILESYSTEM_CPPFILE,
75 FILESYSTEM_FOLDER_VCS_CHANGED,
76 FILESYSTEM_FILE_VCS_CHANGED,
77 FILESYSTEM_CFILE_VCS_CHANGED,
78 FILESYSTEM_HFILE_VCS_CHANGED,
79 FILESYSTEM_PROJECTFILE_VCS_CHANGED,
80 FILESYSTEM_CPPFILE_VCS_CHANGED,
81 FILESYSTEM_FOLDER_VCS_CONFLICT,
82 FILESYSTEM_FILE_VCS_CONFLICT,
83 FILESYSTEM_CFILE_VCS_CONFLICT,
84 FILESYSTEM_HFILE_VCS_CONFLICT,
85 FILESYSTEM_PROJECTFILE_VCS_CONFLICT,
86 FILESYSTEM_CPPFILE_VCS_CONFLICT,
87 FILESYSTEM_FOLDER_VCS_NOCHANGE,
88 FILESYSTEM_FILE_VCS_NOCHANGE,
89 FILESYSTEM_CFILE_VCS_NOCHANGE,
90 FILESYSTEM_HFILE_VCS_NOCHANGE,
91 FILESYSTEM_PROJECTFILE_VCS_NOCHANGE,
92 FILESYSTEM_CPPFILE_VCS_NOCHANGE,
93 FILESYSTEM_FOLDER_VCS_STAGED,
94 FILESYSTEM_FILE_VCS_STAGED,
95 FILESYSTEM_CFILE_VCS_STAGED,
96 FILESYSTEM_HFILE_VCS_STAGED,
97 FILESYSTEM_PROJECTFILE_VCS_STAGED,
98 FILESYSTEM_CPPFILE_VCS_STAGED,
99 FILESYSTEM_HEADERS_FOLDER,
100 FILESYSTEM_SOURCES_FOLDER,
101
102
103 ACTION_MISC_BACK,
104 ACTION_MISC_FORWARD,
105 ACTION_MISC_ADD,
106 ACTION_MISC_REMOVE,
107 ACTION_MISC_GEAR,
108 ACTION_MISC_CROSS,
109 ACTION_MISC_FOLDER,
110 ACTION_MISC_TERM,
111 ACTION_MISC_CLEAN,
112 ACTION_MISC_VALIDATE,
113 ACTION_MISC_RENAME,
114 ACTION_MISC_HELP,
115 ACTION_MISC_FILTER,
116
117 ACTION_FILE_NEW,
118 ACTION_FILE_OPEN,
119 ACTION_FILE_OPEN_FOLDER,
120 ACTION_FILE_SAVE,
121 ACTION_FILE_SAVE_AS,
122 ACTION_FILE_SAVE_ALL,
123 ACTION_FILE_CLOSE,
124 ACTION_FILE_CLOSE_ALL,
125 ACTION_FILE_PRINT,
126 ACTION_FILE_PROPERTIES,
127 ACTION_FILE_LOCATE,
128
129 ACTION_PROJECT_NEW,
130 ACTION_PROJECT_SAVE,
131 ACTION_PROJECT_CLOSE,
132 ACTION_PROJECT_NEW_FILE,
133 ACTION_PROJECT_ADD_FILE,
134 ACTION_PROJECT_REMOVE_FILE,
135 ACTION_PROJECT_PROPERTIES,
136
137 ACTION_EDIT_UNDO,
138 ACTION_EDIT_REDO,
139 ACTION_EDIT_CUT,
140 ACTION_EDIT_COPY,
141 ACTION_EDIT_PASTE,
142 ACTION_EDIT_INDENT,
143 ACTION_EDIT_UNINDENT,
144 ACTION_EDIT_SEARCH,
145 ACTION_EDIT_REPLACE,
146 ACTION_EDIT_SEARCH_IN_FILES,
147 ACTION_EDIT_SORT_BY_NAME,
148 ACTION_EDIT_SORT_BY_TYPE,
149 ACTION_EDIT_SHOW_INHERITED,
150
151 ACTION_CODE_BACK,
152 ACTION_CODE_FORWARD,
153 ACTION_CODE_ADD_BOOKMARK,
154 ACTION_CODE_REMOVE_BOOKMARK,
155 ACTION_CODE_REFORMAT,
156
157 ACTION_RUN_COMPILE,
158 ACTION_RUN_COMPILE_RUN,
159 ACTION_RUN_RUN,
160 ACTION_RUN_REBUILD,
161 ACTION_RUN_OPTIONS,
162 ACTION_RUN_DEBUG,
163 ACTION_RUN_STEP_OVER,
164 ACTION_RUN_STEP_INTO,
165 ACTION_RUN_STEP_OUT,
166 ACTION_RUN_RUN_TO_CURSOR,
167 ACTION_RUN_CONTINUE,
168 ACTION_RUN_STOP,
169 ACTION_RUN_ADD_WATCH,
170 ACTION_RUN_REMOVE_WATCH,
171 ACTION_RUN_STEP_OVER_INSTRUCTION,
172 ACTION_RUN_STEP_INTO_INSTRUCTION,
173 ACTION_RUN_INTERRUPT,
174 ACTION_RUN_COMPILE_OPTIONS,
175
176 ACTION_VIEW_MAXIMUM,
177 ACTION_VIEW_CLASSBROWSER,
178 ACTION_VIEW_FILES,
179 ACTION_VIEW_COMPILELOG,
180 ACTION_VIEW_BOOKMARK,
181 ACTION_VIEW_TODO,
182
183 ACTION_HELP_ABOUT,
184
185 ACTION_PROBLEM_PROBLEM,
186 ACTION_PROBLEM_SET,
187 ACTION_PROBLEM_PROPERTIES,
188 ACTION_PROBLEM_EDIT_SOURCE,
189 ACTION_PROBLEM_RUN_CASES,
190 ACTION_PROBLEM_PASSED,
191 ACTION_PROBLEM_FALIED,
192 ACTION_PROBLEM_TESTING
193 };
194 explicit IconsManager(QObject *parent = nullptr);
195
196 void updateEditorGuttorIcons(const QString& iconSet, int size);
197 void updateParserIcons(const QString& iconSet, int size);
198 void updateActionIcons(const QString& iconSet, int size);
199 void updateFileSystemIcons(const QString& iconSet, int size);
200
201 PPixmap getPixmap(IconName iconName) const;
202
203 QIcon getIcon(IconName iconName) const;
204
205 void setIcon(QToolButton* btn, IconName iconName) const;
206 void setIcon(QPushButton* btn, IconName iconName) const;
207
208 PPixmap createSVGIcon(const QString& filename, int width, int height);
209 const QSize &actionIconSize() const;
210
211 void prepareCustomIconSet(const QString &customIconSet);
212
213 QPixmap getPixmapForStatement(PStatement statement);
214
215 const QString iconSetsFolder() const;
216 void setIconSetsFolder(const QString &newIconSetsFolder);
217
218 QList<PIconSet> listIconSets();
219private:
220 void updateMakeDisabledIconDarker(const QString& iconset);
221signals:
222 void actionIconsUpdated();
223private:
224 QMap<IconName,PPixmap> mIconPixmaps;
225 PPixmap mDefaultIconPixmap;
226 QSize mActionIconSize;
227 QString mIconSetTemplate;
228 QString mIconSetsFolder;
229 bool mMakeDisabledIconDarker;
230};
231
232extern IconsManager* pIconsManager;
233#endif // ICONSMANAGER_H
234