-
Notifications
You must be signed in to change notification settings - Fork 11
/
iconloader.h
68 lines (54 loc) · 1.43 KB
/
iconloader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef ICONLOADER_H
#define ICONLOADER_H
#include <QtCore/QMutex>
#include <QtCore/QMap>
#include <QtCore/QList>
#include <QtCore/QStringList>
#include <QtGui/QImage>
// Unfortunately, Qt icon theme support is not flexible enough.
// I need to load icon images in another thread, and this is not possible with Qt implementation.
// Also, I would like to specify what theme to use when calling load function, instead of specifying it globally.
// Reinventing the wheel here...
class IconTheme
{
public:
void init(const QString& themeName);
QImage loadIcon(const QString& iconName, int size);
const QStringList& inheritedThemes()
{
return m_inheritedThemes;
}
private:
struct IconDirectory
{
QString m_path;
int m_size;
bool m_scalable;
};
bool loadIconFromDirectory(QImage& result, const IconDirectory& iconDir, const QString& fileName);
QString m_themeName;
QStringList m_inheritedThemes;
QList<IconDirectory> m_iconDirs;
};
class IconLoader
{
public:
IconLoader();
~IconLoader();
static IconLoader* instance()
{
return m_instance;
}
const QStringList& iconSearchPaths()
{
return m_iconSearchPaths;
}
QImage loadIcon(const QString& themeName, const QString& iconName, int size);
private:
QImage loadIconFromTheme(const QString& themeName, const QString& iconName, int size);
static IconLoader* m_instance;
QStringList m_iconSearchPaths;
QMutex m_iconThemesMutex;
QMap<QString, IconTheme> m_iconThemes;
};
#endif