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#include "iconsmanager.h"
18
19#include <QPainter>
20#include <QSvgRenderer>
21#include <QDebug>
22#include <QIcon>
23#include <QToolButton>
24#include <QPushButton>
25#include <QFile>
26#include <QDir>
27#include <QDirIterator>
28#include <QJsonDocument>
29#include <QJsonObject>
30#include "utils.h"
31#include "settings.h"
32#include "widgets/customdisablediconengine.h"
33#include <QApplication>
34
35IconsManager* pIconsManager;
36
37IconsManager::IconsManager(QObject *parent) : QObject(parent)
38{
39 mDefaultIconPixmap = std::make_shared<QPixmap>();
40 mIconSetTemplate = "%1/%2/%3/";
41 mMakeDisabledIconDarker = false;
42}
43
44void IconsManager::updateEditorGuttorIcons(const QString& iconSet,int size)
45{
46 QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"editor");
47 updateMakeDisabledIconDarker(iconSet);
48 mIconPixmaps.insert(GUTTER_BREAKPOINT, createSVGIcon(iconFolder+"breakpoint.svg",size,size));
49 mIconPixmaps.insert(GUTTER_SYNTAX_ERROR, createSVGIcon(iconFolder+"syntaxerror.svg",size,size));
50 mIconPixmaps.insert(GUTTER_SYNTAX_WARNING,createSVGIcon(iconFolder+"syntaxwarning.svg",size,size));
51 mIconPixmaps.insert(GUTTER_ACTIVEBREAKPOINT,createSVGIcon(iconFolder+"currentline.svg",size,size));
52 mIconPixmaps.insert(GUTTER_BOOKMARK, createSVGIcon(iconFolder+"bookmark.svg",size,size));
53}
54
55void IconsManager::updateParserIcons(const QString &iconSet, int size)
56{
57 QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"classparser");
58 updateMakeDisabledIconDarker(iconSet);
59 mIconPixmaps.insert(PARSER_TYPE, createSVGIcon(iconFolder+"type.svg",size,size));
60 mIconPixmaps.insert(PARSER_CLASS, createSVGIcon(iconFolder+"class.svg",size,size));
61 mIconPixmaps.insert(PARSER_NAMESPACE, createSVGIcon(iconFolder+"namespace.svg",size,size));
62 mIconPixmaps.insert(PARSER_DEFINE, createSVGIcon(iconFolder+"define.svg",size,size));
63 mIconPixmaps.insert(PARSER_ENUM, createSVGIcon(iconFolder+"enum.svg",size,size));;
64 mIconPixmaps.insert(PARSER_GLOBAL_METHOD, createSVGIcon(iconFolder+"global_method.svg",size,size));
65 mIconPixmaps.insert(PARSER_INHERITED_PROTECTED_METHOD, createSVGIcon(iconFolder+"method_inherited_protected.svg",size,size));
66 mIconPixmaps.insert(PARSER_INHERITED_METHOD, createSVGIcon(iconFolder+"method_inherited.svg",size,size));
67 mIconPixmaps.insert(PARSER_PROTECTED_METHOD, createSVGIcon(iconFolder+"method_protected.svg",size,size));
68 mIconPixmaps.insert(PARSER_PUBLIC_METHOD, createSVGIcon(iconFolder+"method_public.svg",size,size));
69 mIconPixmaps.insert(PARSER_PRIVATE_METHOD, createSVGIcon(iconFolder+"method_private.svg",size,size));
70 mIconPixmaps.insert(PARSER_GLOBAL_VAR, createSVGIcon(iconFolder+"global.svg",size,size));
71 mIconPixmaps.insert(PARSER_INHERITED_PROTECTD_VAR, createSVGIcon(iconFolder+"var_inherited_protected.svg",size,size));
72 mIconPixmaps.insert(PARSER_INHERITED_VAR, createSVGIcon(iconFolder+"var_inherited.svg",size,size));
73 mIconPixmaps.insert(PARSER_PROTECTED_VAR, createSVGIcon(iconFolder+"var_protected.svg",size,size));
74 mIconPixmaps.insert(PARSER_PUBLIC_VAR, createSVGIcon(iconFolder+"var_public.svg",size,size));
75 mIconPixmaps.insert(PARSER_PRIVATE_VAR, createSVGIcon(iconFolder+"var_private.svg",size,size));
76 mIconPixmaps.insert(PARSER_KEYWORD, createSVGIcon(iconFolder+"keyword.svg",size,size));
77 mIconPixmaps.insert(PARSER_CODE_SNIPPET, createSVGIcon(iconFolder+"code_snippet.svg",size,size));
78 mIconPixmaps.insert(PARSER_LOCAL_VAR, createSVGIcon(iconFolder+"var.svg",size,size));
79
80}
81
82void IconsManager::updateActionIcons(const QString& iconSet, int size)
83{
84 QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"actions");
85 updateMakeDisabledIconDarker(iconSet);
86 mActionIconSize = QSize(size,size);
87 mIconPixmaps.insert(ACTION_MISC_BACK, createSVGIcon(iconFolder+"00Misc-01Back.svg",size,size));
88 mIconPixmaps.insert(ACTION_MISC_FORWARD, createSVGIcon(iconFolder+"00Misc-02Forward.svg",size,size));
89 mIconPixmaps.insert(ACTION_MISC_ADD, createSVGIcon(iconFolder+"00Misc-03Add.svg",size,size));
90 mIconPixmaps.insert(ACTION_MISC_REMOVE, createSVGIcon(iconFolder+"00Misc-04Remove.svg",size,size));
91 mIconPixmaps.insert(ACTION_MISC_GEAR, createSVGIcon(iconFolder+"00Misc-05Gear.svg",size,size));
92 mIconPixmaps.insert(ACTION_MISC_CROSS, createSVGIcon(iconFolder+"00Misc-06Cross.svg",size,size));
93 mIconPixmaps.insert(ACTION_MISC_FOLDER, createSVGIcon(iconFolder+"00Misc-07Folder.svg",size,size));
94 mIconPixmaps.insert(ACTION_MISC_TERM, createSVGIcon(iconFolder+"00Misc-08Term.svg",size,size));
95 mIconPixmaps.insert(ACTION_MISC_CLEAN, createSVGIcon(iconFolder+"00Misc-09Clean.svg",size,size));
96 mIconPixmaps.insert(ACTION_MISC_VALIDATE, createSVGIcon(iconFolder+"00Misc-10Check.svg",size,size));
97 mIconPixmaps.insert(ACTION_MISC_RENAME, createSVGIcon(iconFolder+"00Misc-11Rename.svg",size,size));
98 mIconPixmaps.insert(ACTION_MISC_HELP, createSVGIcon(iconFolder+"00Misc-12Help.svg",size,size));
99 mIconPixmaps.insert(ACTION_MISC_FILTER, createSVGIcon(iconFolder+"00Misc-13Filter.svg",size,size));
100
101 mIconPixmaps.insert(ACTION_FILE_NEW, createSVGIcon(iconFolder+"01File-01New.svg",size,size));
102 mIconPixmaps.insert(ACTION_FILE_OPEN, createSVGIcon(iconFolder+"01File-02Open.svg",size,size));
103 mIconPixmaps.insert(ACTION_FILE_OPEN_FOLDER, createSVGIcon(iconFolder+"01File-09Open_Folder.svg",size,size));
104 mIconPixmaps.insert(ACTION_FILE_SAVE, createSVGIcon(iconFolder+"01File-03Save.svg",size,size));
105 mIconPixmaps.insert(ACTION_FILE_SAVE_AS, createSVGIcon(iconFolder+"01File-04SaveAs.svg",size,size));
106 mIconPixmaps.insert(ACTION_FILE_SAVE_ALL, createSVGIcon(iconFolder+"01File-05SaveAll.svg",size,size));
107 mIconPixmaps.insert(ACTION_FILE_CLOSE, createSVGIcon(iconFolder+"01File-06Close.svg",size,size));
108 mIconPixmaps.insert(ACTION_FILE_CLOSE_ALL, createSVGIcon(iconFolder+"01File-07CloseAll.svg",size,size));
109 mIconPixmaps.insert(ACTION_FILE_PRINT, createSVGIcon(iconFolder+"01File-08Print.svg",size,size));
110 mIconPixmaps.insert(ACTION_FILE_PROPERTIES, createSVGIcon(iconFolder+"01File-10FileProperties.svg",size,size));
111 mIconPixmaps.insert(ACTION_FILE_LOCATE, createSVGIcon(iconFolder+"01File-11Locate.svg",size,size));
112
113 mIconPixmaps.insert(ACTION_PROJECT_NEW, createSVGIcon(iconFolder+"02Project-01New.svg",size,size));
114 mIconPixmaps.insert(ACTION_PROJECT_SAVE, createSVGIcon(iconFolder+"02Project-02Save.svg",size,size));
115 mIconPixmaps.insert(ACTION_PROJECT_CLOSE, createSVGIcon(iconFolder+"02Project-03Close.svg",size,size));
116 mIconPixmaps.insert(ACTION_PROJECT_NEW_FILE, createSVGIcon(iconFolder+"02Project-04NewFile.svg",size,size));
117 mIconPixmaps.insert(ACTION_PROJECT_ADD_FILE, createSVGIcon(iconFolder+"02Project-05AddFile.svg",size,size));
118 mIconPixmaps.insert(ACTION_PROJECT_REMOVE_FILE, createSVGIcon(iconFolder+"02Project-06RemoveFile.svg",size,size));
119 mIconPixmaps.insert(ACTION_PROJECT_PROPERTIES, createSVGIcon(iconFolder+"02Project-07Properties.svg",size,size));
120 mIconPixmaps.insert(ACTION_EDIT_UNDO, createSVGIcon(iconFolder+"03Edit-01Undo.svg",size,size));
121 mIconPixmaps.insert(ACTION_EDIT_REDO, createSVGIcon(iconFolder+"03Edit-02Redo.svg",size,size));
122 mIconPixmaps.insert(ACTION_EDIT_CUT, createSVGIcon(iconFolder+"03Edit-03Cut.svg",size,size));
123 mIconPixmaps.insert(ACTION_EDIT_COPY, createSVGIcon(iconFolder+"03Edit-04Copy.svg",size,size));
124 mIconPixmaps.insert(ACTION_EDIT_PASTE, createSVGIcon(iconFolder+"03Edit-05Paste.svg",size,size));
125 mIconPixmaps.insert(ACTION_EDIT_INDENT, createSVGIcon(iconFolder+"03Edit-06Indent.svg",size,size));
126 mIconPixmaps.insert(ACTION_EDIT_UNINDENT, createSVGIcon(iconFolder+"03Edit-07Unindent.svg",size,size));
127 mIconPixmaps.insert(ACTION_EDIT_SEARCH, createSVGIcon(iconFolder+"03Edit-08Search.svg",size,size));
128 mIconPixmaps.insert(ACTION_EDIT_REPLACE, createSVGIcon(iconFolder+"03Edit-09Replace.svg",size,size));
129 mIconPixmaps.insert(ACTION_EDIT_SEARCH_IN_FILES, createSVGIcon(iconFolder+"03Edit-10SearchInFiles.svg",size,size));
130 mIconPixmaps.insert(ACTION_EDIT_SORT_BY_NAME, createSVGIcon(iconFolder+"03Edit-11SortByName.svg",size,size));
131 mIconPixmaps.insert(ACTION_EDIT_SORT_BY_TYPE, createSVGIcon(iconFolder+"03Edit-12SortByType.svg",size,size));
132 mIconPixmaps.insert(ACTION_EDIT_SHOW_INHERITED, createSVGIcon(iconFolder+"03Edit-13ShowInherited.svg",size,size));
133
134 mIconPixmaps.insert(ACTION_CODE_BACK, createSVGIcon(iconFolder+"04Code-01Back.svg",size,size));
135 mIconPixmaps.insert(ACTION_CODE_FORWARD, createSVGIcon(iconFolder+"04Code-02Forward.svg",size,size));
136 mIconPixmaps.insert(ACTION_CODE_ADD_BOOKMARK, createSVGIcon(iconFolder+"04Code-03AddBookmark.svg",size,size));
137 mIconPixmaps.insert(ACTION_CODE_REMOVE_BOOKMARK, createSVGIcon(iconFolder+"04Code-04RemoveBookmark.svg",size,size));
138 mIconPixmaps.insert(ACTION_CODE_REFORMAT, createSVGIcon(iconFolder+"04Code-05Reformat.svg",size,size));
139
140 mIconPixmaps.insert(ACTION_RUN_COMPILE, createSVGIcon(iconFolder+"05Run-01Compile.svg",size,size));
141 mIconPixmaps.insert(ACTION_RUN_COMPILE_RUN, createSVGIcon(iconFolder+"05Run-02CompileRun.svg",size,size));
142 mIconPixmaps.insert(ACTION_RUN_RUN, createSVGIcon(iconFolder+"05Run-03Run.svg",size,size));
143 mIconPixmaps.insert(ACTION_RUN_REBUILD, createSVGIcon(iconFolder+"05Run-04Rebuild.svg",size,size));
144 mIconPixmaps.insert(ACTION_RUN_OPTIONS, createSVGIcon(iconFolder+"05Run-05Options.svg",size,size));
145 mIconPixmaps.insert(ACTION_RUN_DEBUG, createSVGIcon(iconFolder+"05Run-06Debug.svg",size,size));
146 mIconPixmaps.insert(ACTION_RUN_STEP_OVER, createSVGIcon(iconFolder+"05Run-07StepOver.svg",size,size));
147 mIconPixmaps.insert(ACTION_RUN_STEP_INTO, createSVGIcon(iconFolder+"05Run-08StepInto.svg",size,size));
148 mIconPixmaps.insert(ACTION_RUN_STEP_OUT, createSVGIcon(iconFolder+"05Run-08StepOut.svg",size,size));
149 mIconPixmaps.insert(ACTION_RUN_RUN_TO_CURSOR, createSVGIcon(iconFolder+"05Run-09RunToCursor.svg",size,size));
150 mIconPixmaps.insert(ACTION_RUN_CONTINUE, createSVGIcon(iconFolder+"05Run-10Continue.svg",size,size));
151 mIconPixmaps.insert(ACTION_RUN_STOP, createSVGIcon(iconFolder+"05Run-11Stop.svg",size,size));
152 mIconPixmaps.insert(ACTION_RUN_ADD_WATCH, createSVGIcon(iconFolder+"05Run-12AddWatch.svg",size,size));
153 mIconPixmaps.insert(ACTION_RUN_REMOVE_WATCH, createSVGIcon(iconFolder+"05Run-13RemoveWatch.svg",size,size));
154 mIconPixmaps.insert(ACTION_RUN_STEP_OVER_INSTRUCTION, createSVGIcon(iconFolder+"05Run-14StepOverInstruction.svg",size,size));
155 mIconPixmaps.insert(ACTION_RUN_STEP_INTO_INSTRUCTION, createSVGIcon(iconFolder+"05Run-15StepIntoInstruction.svg",size,size));
156 mIconPixmaps.insert(ACTION_RUN_INTERRUPT, createSVGIcon(iconFolder+"05Run-16Interrupt.svg",size,size));
157 mIconPixmaps.insert(ACTION_RUN_COMPILE_OPTIONS, createSVGIcon(iconFolder+"05Run-17CompilerOptions.svg",size,size));
158
159 mIconPixmaps.insert(ACTION_VIEW_MAXIMUM, createSVGIcon(iconFolder+"06View-01Maximum.svg",size,size));
160 mIconPixmaps.insert(ACTION_VIEW_CLASSBROWSER, createSVGIcon(iconFolder+"06View-02ClassBrowser.svg",size,size));
161 mIconPixmaps.insert(ACTION_VIEW_FILES, createSVGIcon(iconFolder+"06View-03Files.svg",size,size));
162 mIconPixmaps.insert(ACTION_VIEW_COMPILELOG, createSVGIcon(iconFolder+"06View-04CompileLog.svg",size,size));
163 mIconPixmaps.insert(ACTION_VIEW_BOOKMARK, createSVGIcon(iconFolder+"06View-05Bookmark.svg",size,size));
164 mIconPixmaps.insert(ACTION_VIEW_TODO, createSVGIcon(iconFolder+"06View-06Todo.svg",size,size));
165
166 mIconPixmaps.insert(ACTION_HELP_ABOUT, createSVGIcon(iconFolder+"07Help-01About.svg",size,size));
167
168 mIconPixmaps.insert(ACTION_PROBLEM_PROBLEM, createSVGIcon(iconFolder+"08Problem-01Problem.svg",size,size));
169 mIconPixmaps.insert(ACTION_PROBLEM_SET, createSVGIcon(iconFolder+"08Problem-02ProblemSet.svg",size,size));
170 mIconPixmaps.insert(ACTION_PROBLEM_PROPERTIES, createSVGIcon(iconFolder+"08Problem-03Properties.svg",size,size));
171 mIconPixmaps.insert(ACTION_PROBLEM_EDIT_SOURCE, createSVGIcon(iconFolder+"08Problem-04EditSource.svg",size,size));
172 mIconPixmaps.insert(ACTION_PROBLEM_RUN_CASES, createSVGIcon(iconFolder+"08Problem-05RunCases.svg",size,size));
173 mIconPixmaps.insert(ACTION_PROBLEM_PASSED, createSVGIcon(iconFolder+"08Problem-06Correct.svg",size,size));
174 mIconPixmaps.insert(ACTION_PROBLEM_FALIED, createSVGIcon(iconFolder+"08Problem-07Wrong.svg",size,size));
175 mIconPixmaps.insert(ACTION_PROBLEM_TESTING, createSVGIcon(iconFolder+"08Problem-08Running.svg",size,size));
176
177 emit actionIconsUpdated();
178
179}
180
181void IconsManager::updateFileSystemIcons(const QString &iconSet, int size)
182{
183 QString iconFolder = mIconSetTemplate.arg( iconSetsFolder(),iconSet,"filesystem");
184 updateMakeDisabledIconDarker(iconSet);
185 mIconPixmaps.insert(FILESYSTEM_GIT, createSVGIcon(iconFolder+"git.svg",size,size));
186 mIconPixmaps.insert(FILESYSTEM_FOLDER, createSVGIcon(iconFolder+"folder.svg",size,size));
187 mIconPixmaps.insert(FILESYSTEM_FOLDER_VCS_CHANGED, createSVGIcon(iconFolder+"folder-vcs-changed.svg",size,size));
188 mIconPixmaps.insert(FILESYSTEM_FOLDER_VCS_CONFLICT, createSVGIcon(iconFolder+"folder-vcs-conflict.svg",size,size));
189 mIconPixmaps.insert(FILESYSTEM_FOLDER_VCS_NOCHANGE, createSVGIcon(iconFolder+"folder-vcs-nochange.svg",size,size));
190 mIconPixmaps.insert(FILESYSTEM_FOLDER_VCS_STAGED, createSVGIcon(iconFolder+"folder-vcs-staged.svg",size,size));
191 mIconPixmaps.insert(FILESYSTEM_FILE, createSVGIcon(iconFolder+"file.svg",size,size));
192 mIconPixmaps.insert(FILESYSTEM_FILE_VCS_CHANGED, createSVGIcon(iconFolder+"file-vcs-changed.svg",size,size));
193 mIconPixmaps.insert(FILESYSTEM_FILE_VCS_CONFLICT, createSVGIcon(iconFolder+"file-vcs-conflict.svg",size,size));
194 mIconPixmaps.insert(FILESYSTEM_FILE_VCS_NOCHANGE, createSVGIcon(iconFolder+"file-vcs-nochange.svg",size,size));
195 mIconPixmaps.insert(FILESYSTEM_FILE_VCS_STAGED, createSVGIcon(iconFolder+"file-vcs-staged.svg",size,size));
196 mIconPixmaps.insert(FILESYSTEM_CFILE, createSVGIcon(iconFolder+"cfile.svg",size,size));
197 mIconPixmaps.insert(FILESYSTEM_CFILE_VCS_CHANGED, createSVGIcon(iconFolder+"cfile-vcs-changed.svg",size,size));
198 mIconPixmaps.insert(FILESYSTEM_CFILE_VCS_CONFLICT, createSVGIcon(iconFolder+"cfile-vcs-conflict.svg",size,size));
199 mIconPixmaps.insert(FILESYSTEM_CFILE_VCS_NOCHANGE, createSVGIcon(iconFolder+"cfile-vcs-nochange.svg",size,size));
200 mIconPixmaps.insert(FILESYSTEM_CFILE_VCS_STAGED, createSVGIcon(iconFolder+"cfile-vcs-staged.svg",size,size));
201 mIconPixmaps.insert(FILESYSTEM_HFILE, createSVGIcon(iconFolder+"hfile.svg",size,size));
202 mIconPixmaps.insert(FILESYSTEM_HFILE_VCS_CHANGED, createSVGIcon(iconFolder+"hfile-vcs-changed.svg",size,size));
203 mIconPixmaps.insert(FILESYSTEM_HFILE_VCS_CONFLICT, createSVGIcon(iconFolder+"hfile-vcs-conflict.svg",size,size));
204 mIconPixmaps.insert(FILESYSTEM_HFILE_VCS_NOCHANGE, createSVGIcon(iconFolder+"hfile-vcs-nochange.svg",size,size));
205 mIconPixmaps.insert(FILESYSTEM_HFILE_VCS_STAGED, createSVGIcon(iconFolder+"hfile-vcs-staged.svg",size,size));
206 mIconPixmaps.insert(FILESYSTEM_CPPFILE, createSVGIcon(iconFolder+"cppfile.svg",size,size));
207 mIconPixmaps.insert(FILESYSTEM_CPPFILE_VCS_CHANGED, createSVGIcon(iconFolder+"cppfile-vcs-changed.svg",size,size));
208 mIconPixmaps.insert(FILESYSTEM_CPPFILE_VCS_CONFLICT, createSVGIcon(iconFolder+"cppfile-vcs-conflict.svg",size,size));
209 mIconPixmaps.insert(FILESYSTEM_CPPFILE_VCS_NOCHANGE, createSVGIcon(iconFolder+"cppfile-vcs-nochange.svg",size,size));
210 mIconPixmaps.insert(FILESYSTEM_CPPFILE_VCS_STAGED, createSVGIcon(iconFolder+"cppfile-vcs-staged.svg",size,size));
211 mIconPixmaps.insert(FILESYSTEM_PROJECTFILE, createSVGIcon(iconFolder+"projectfile.svg",size,size));
212 mIconPixmaps.insert(FILESYSTEM_PROJECTFILE_VCS_CHANGED, createSVGIcon(iconFolder+"projectfile-vcs-changed.svg",size,size));
213 mIconPixmaps.insert(FILESYSTEM_PROJECTFILE_VCS_CONFLICT, createSVGIcon(iconFolder+"projectfile-vcs-conflict.svg",size,size));
214 mIconPixmaps.insert(FILESYSTEM_PROJECTFILE_VCS_NOCHANGE, createSVGIcon(iconFolder+"projectfile-vcs-nochange.svg",size,size));
215 mIconPixmaps.insert(FILESYSTEM_PROJECTFILE_VCS_STAGED, createSVGIcon(iconFolder+"projectfile-vcs-staged.svg",size,size));
216 mIconPixmaps.insert(FILESYSTEM_HEADERS_FOLDER, createSVGIcon(iconFolder+"headerfolder.svg",size,size));
217 mIconPixmaps.insert(FILESYSTEM_SOURCES_FOLDER, createSVGIcon(iconFolder+"sourcefolder.svg",size,size));
218}
219
220IconsManager::PPixmap IconsManager::getPixmap(IconName iconName) const
221{
222 return mIconPixmaps.value(iconName, mDefaultIconPixmap);
223}
224
225QIcon IconsManager:: getIcon(IconName iconName) const
226{
227 PPixmap pixmap = getPixmap(iconName);
228 if (pixmap == mDefaultIconPixmap)
229 return QIcon();
230 if (mMakeDisabledIconDarker) {
231 QIcon icon(new CustomDisabledIconEngine());
232 icon.addPixmap(*pixmap);
233 return icon;
234 } else
235 return QIcon(*pixmap);
236}
237
238void IconsManager::setIcon(QToolButton *btn, IconName iconName) const
239{
240 btn->setIconSize(mActionIconSize);
241 btn->setIcon(getIcon(iconName));
242}
243
244void IconsManager::setIcon(QPushButton *btn, IconName iconName) const
245{
246 btn->setIconSize(mActionIconSize);
247 btn->setIcon(getIcon(iconName));
248}
249
250IconsManager::PPixmap IconsManager::createSVGIcon(const QString &filename, int width, int height)
251{
252 QSvgRenderer renderer(filename);
253 if (!renderer.isValid())
254 return mDefaultIconPixmap;
255 qreal dpr=qApp->devicePixelRatio();
256 PPixmap icon = std::make_shared<QPixmap>(width*dpr,height*dpr);
257 icon->fill(Qt::transparent);
258 QPainter painter(icon.get());
259 renderer.render(&painter,icon->rect());
260 icon->setDevicePixelRatio(dpr);
261 return icon;
262}
263
264const QSize &IconsManager::actionIconSize() const
265{
266 return mActionIconSize;
267}
268
269void IconsManager::prepareCustomIconSet(const QString &customIconSet)
270{
271 if (QFile(customIconSet).exists())
272 return;
273 copyFolder(pSettings->dirs().data(Settings::Dirs::DataType::IconSet),customIconSet);
274}
275
276QPixmap IconsManager::getPixmapForStatement(PStatement statement)
277{
278 if (!statement)
279 return QPixmap();
280 StatementKind kind = getKindOfStatement(statement);
281 switch (kind) {
282 case StatementKind::skTypedef:
283 return *(pIconsManager->getPixmap(IconsManager::PARSER_TYPE));
284 case StatementKind::skClass:
285 return *(pIconsManager->getPixmap(IconsManager::PARSER_CLASS));
286 case StatementKind::skNamespace:
287 case StatementKind::skNamespaceAlias:
288 return *(pIconsManager->getPixmap(IconsManager::PARSER_NAMESPACE));
289 case StatementKind::skPreprocessor:
290 return *(pIconsManager->getPixmap(IconsManager::PARSER_DEFINE));
291 case StatementKind::skEnumClassType:
292 case StatementKind::skEnumType:
293 case StatementKind::skEnum:
294 return *(pIconsManager->getPixmap(IconsManager::PARSER_ENUM));
295 case StatementKind::skFunction:
296 case StatementKind::skConstructor:
297 case StatementKind::skDestructor:
298 if (statement->scope == StatementScope::ssGlobal)
299 return *(pIconsManager->getPixmap(IconsManager::PARSER_GLOBAL_METHOD));
300 if (statement->isInherited) {
301 if (statement->classScope == StatementClassScope::scsProtected) {
302 return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_PROTECTED_METHOD));
303 } else if (statement->classScope == StatementClassScope::scsPublic) {
304 return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_METHOD));
305 }
306 } else {
307 if (statement->classScope == StatementClassScope::scsProtected) {
308 return *(pIconsManager->getPixmap(IconsManager::PARSER_PROTECTED_METHOD));
309 } else if (statement->classScope == StatementClassScope::scsPublic) {
310 return *(pIconsManager->getPixmap(IconsManager::PARSER_PUBLIC_METHOD));
311 } else {
312 return *(pIconsManager->getPixmap(IconsManager::PARSER_PRIVATE_METHOD));
313 }
314 }
315 break;
316 case StatementKind::skGlobalVariable:
317 return *(pIconsManager->getPixmap(IconsManager::PARSER_GLOBAL_VAR));
318 case StatementKind::skLocalVariable:
319 return *(pIconsManager->getPixmap(IconsManager::PARSER_LOCAL_VAR));
320 case StatementKind::skVariable:
321 if (statement->isInherited) {
322 if (statement->classScope == StatementClassScope::scsProtected) {
323 return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_PROTECTD_VAR));
324 } else if (statement->classScope == StatementClassScope::scsPublic) {
325 return *(pIconsManager->getPixmap(IconsManager::PARSER_INHERITED_VAR));
326 }
327 } else {
328 if (statement->classScope == StatementClassScope::scsProtected) {
329 return *(pIconsManager->getPixmap(IconsManager::PARSER_PROTECTED_VAR));
330 } else if (statement->classScope == StatementClassScope::scsPublic) {
331 return *(pIconsManager->getPixmap(IconsManager::PARSER_PUBLIC_VAR));
332 } else {
333 return *(pIconsManager->getPixmap(IconsManager::PARSER_PRIVATE_VAR));
334 }
335 }
336 break;
337 case StatementKind::skKeyword:
338 return *(pIconsManager->getPixmap(IconsManager::PARSER_KEYWORD));
339 case StatementKind::skUserCodeSnippet:
340 return *(pIconsManager->getPixmap(IconsManager::PARSER_CODE_SNIPPET));
341 case StatementKind::skAlias:
342 return *(pIconsManager->getPixmap(IconsManager::PARSER_TYPE));
343 default:
344 break;
345 }
346 return QPixmap();
347}
348
349const QString IconsManager::iconSetsFolder() const
350{
351 if (mIconSetsFolder.isEmpty())
352 return pSettings->dirs().data(Settings::Dirs::DataType::IconSet);
353 return mIconSetsFolder;
354}
355
356void IconsManager::setIconSetsFolder(const QString &newIconSetsFolder)
357{
358 mIconSetsFolder = newIconSetsFolder;
359}
360
361QList<PIconSet> IconsManager::listIconSets()
362{
363 QDirIterator dirIter(iconSetsFolder());
364 QList<PIconSet> result;
365 while(dirIter.hasNext()) {
366 dirIter.next();
367 QFileInfo fileInfo = dirIter.fileInfo();
368 if (!fileInfo.isHidden() && !fileInfo.fileName().startsWith('.') && fileInfo.isDir()) {
369 PIconSet pSet = std::make_shared<IconSet>();
370 pSet->name = fileInfo.baseName();
371 pSet->displayName = pSet->name;
372 QFile infoFile(includeTrailingPathDelimiter(fileInfo.absoluteFilePath())+"info.json");
373 if (infoFile.exists() && infoFile.open(QFile::ReadOnly)) {
374 QByteArray content = infoFile.readAll();
375 QJsonParseError error;
376 QJsonDocument doc(QJsonDocument::fromJson(content,&error));
377 if (error.error == QJsonParseError::NoError) {
378 QJsonObject obj=doc.object();
379 pSet->displayName = obj["name"].toString();
380 QString localeName = obj["name_"+pSettings->environment().language()].toString();
381 if (!localeName.isEmpty())
382 pSet->displayName = localeName;
383 }
384 }
385 result.append(pSet);
386 }
387 }
388 return result;
389}
390
391void IconsManager::updateMakeDisabledIconDarker(const QString& iconset )
392{
393 mMakeDisabledIconDarker = (iconset == "contrast");
394}
395