From 3e78da27951713bae25f83ddccd6b589ca193de8 Mon Sep 17 00:00:00 2001 From: zyz Date: Thu, 17 Mar 2016 10:51:38 +0800 Subject: [PATCH] renamed resoure.* to resource.* --- SkinButton/resource.cpp | 111 ++++++++++++++++++++++++++++++++++++++++ SkinButton/resource.h | 51 ++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 SkinButton/resource.cpp create mode 100644 SkinButton/resource.h diff --git a/SkinButton/resource.cpp b/SkinButton/resource.cpp new file mode 100644 index 0000000..7a5b5d8 --- /dev/null +++ b/SkinButton/resource.cpp @@ -0,0 +1,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 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 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 diff --git a/SkinButton/resource.h b/SkinButton/resource.h new file mode 100644 index 0000000..f40df21 --- /dev/null +++ b/SkinButton/resource.h @@ -0,0 +1,51 @@ +#ifndef RESOURE_H +#define RESOURE_H + +#include +#include + +namespace Resource { + +typedef enum{ + Play, + Stop, + TimeIn, + TimeOut +}IndexPixmapType; + +class IndexPixmap : public QPixmap +{ +public: + IndexPixmap(); + IndexPixmap(const char *fileName, quint32 cnt = 1); + ~IndexPixmap() {} + +public: + void setWidth(quint32 w); + QPixmap getSubPixmap(qint32 index = -1) const; + +private: + class Impl; + QSharedPointer m_pimpl; +}; + + +class PixmapManager +{ +public: + PixmapManager(); + +public: + static PixmapManager &inst(); + +public: + QPixmap getPixmap(IndexPixmapType t, qint32 idx = -1); + +private: + class Impl; + QScopedPointer m_pImpl; +}; + +} // namespace Resource + +#endif // RESOURE_H