-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource.cpp
111 lines (86 loc) · 2.25 KB
/
resource.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "resoure.h"
#define RES_PLAY ":/res/play.bmp"
#define RES_STOP ":/res/stop.bmp"
#define RES_TIME_IN ":/res/timein.bmp"
#define RES_TIME_OUT ":/res/timeout.bmp"
namespace Resource {
class IndexPixmap::Impl
{
public:
qint32 m_width;
QHash<qint32, QPixmap> m_pixs;
};
IndexPixmap::IndexPixmap()
: m_pimpl(new Impl())
{
m_pimpl->m_width = 0;
}
IndexPixmap::IndexPixmap(const char *fileName, quint32 cnt)
: QPixmap(fileName)
, m_pimpl(new Impl())
{
m_pimpl->m_width = width() / cnt;
}
void IndexPixmap::setWidth(quint32 w)
{
m_pimpl->m_width = w;
}
QPixmap IndexPixmap::getSubPixmap(qint32 index) const
{
if (index == -1)
return *this;
if (!m_pimpl->m_pixs.contains(index))
m_pimpl->m_pixs.insert(index, copy(index * m_pimpl->m_width, 0, m_pimpl->m_width, height()));
return m_pimpl->m_pixs.value(index);
}
////////////////////////////////////////////////////////////////////////////////
class PixmapManager::Impl
{
public:
QPixmap getPixmap(IndexPixmapType t, qint32 idx);
private:
void loadPixmap(IndexPixmapType t);
private:
typedef QHash<IndexPixmapType, IndexPixmap> IndexPixmapSet;
IndexPixmapSet m_indexPixmaps;
};
QPixmap PixmapManager::Impl::getPixmap(IndexPixmapType t, qint32 idx)
{
if (!m_indexPixmaps.contains(t))
loadPixmap(t);
return m_indexPixmaps.value(t).getSubPixmap(idx);
}
void PixmapManager::Impl::loadPixmap(IndexPixmapType t)
{
IndexPixmap tmp;
switch (t) {
case Play:
tmp = IndexPixmap(RES_PLAY, 4);
break;
case Stop:
tmp = IndexPixmap(RES_STOP, 4);
break;
case TimeIn:
tmp = IndexPixmap(RES_TIME_IN, 4);
break;
case TimeOut:
tmp = IndexPixmap(RES_TIME_OUT, 4);
break;
}
m_indexPixmaps.insert(t, tmp);
}
////////////////////////////////////////////////////////////////////////////////
PixmapManager::PixmapManager()
: m_pImpl(new PixmapManager::Impl())
{
}
PixmapManager &PixmapManager::inst()
{
static PixmapManager mgr;
return mgr;
}
QPixmap PixmapManager::getPixmap(IndexPixmapType t, qint32 idx)
{
return m_pImpl->getPixmap(t, idx);
}
} // namespace Resource