Removed old commented out code.
[tagua/yd.git] / src / pixmaploader.cpp
blobfade02a6d68584983adb96c8e083fa875fd607c6
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #include <map>
12 #include <iostream>
13 #include "common.h"
14 #include "loader/theme.h"
15 #include "pixmaploader.h"
17 class PixmapLoader::ThemeLoader : public Loader::Theme {
18 public:
19 int m_ref_count;
21 ThemeLoader(const QString& s)
22 : Loader::Theme(s)
23 , m_ref_count(0) {
28 PixmapLoader::ThemeLoadersCache PixmapLoader::s_loaders;
31 PixmapLoader::PixmapLoader()
32 : m_loader(NULL)
33 , m_size(0)
37 PixmapLoader::~PixmapLoader() {
38 flush();
41 void PixmapLoader::flush() {
42 if(m_loader) {
43 /* unref the size */
44 if(m_size)
45 m_loader->unrefSize(m_size);
46 m_loader->unrefSize(0);
48 /* unref the loader, and possibly destroy it */
49 if(!--m_loader->m_ref_count) {
50 delete m_loader;
51 s_loaders.erase(m_base);
53 m_loader = NULL;
57 void PixmapLoader::setBasePath(const QString& base) {
58 if(base == m_base)
59 return;
61 flush();
62 m_base = base;
65 void PixmapLoader::setSize(int s) {
66 if(s == m_size)
67 return;
69 if(m_loader) {
70 if(s)
71 m_loader->refSize(s);
72 if(m_size)
73 m_loader->unrefSize(m_size);
75 m_size = s;
78 void PixmapLoader::initialize() {
79 if(m_loader)
80 return;
82 /* try to get a loader */
83 ThemeLoadersCache::iterator it = s_loaders.find(m_base);
84 if(it != s_loaders.end())
85 m_loader = it->second;
86 else {
87 m_loader = new ThemeLoader(m_base);
88 s_loaders[m_base] = m_loader;
91 m_loader->m_ref_count++;
92 if(m_size)
93 m_loader->refSize(m_size);
94 m_loader->refSize(0);
97 template<typename T>
98 T PixmapLoader::getValue(const QString& id, const ::LuaApi::LuaValueMap* args) {
99 if(!m_size || m_base.isEmpty())
100 return T();
102 if(!m_loader)
103 initialize();
105 return m_loader->getValue<T>(id, m_size, args);
108 template QPixmap PixmapLoader::getValue<QPixmap>(const QString&, const ::LuaApi::LuaValueMap*);
109 template Loader::PixmapOrMap PixmapLoader::getValue<Loader::PixmapOrMap>(const QString&, const ::LuaApi::LuaValueMap*);
110 template Loader::Glyph PixmapLoader::getValue<Loader::Glyph>(const QString&, const ::LuaApi::LuaValueMap*);
111 template double PixmapLoader::getValue<double>(const QString&, const ::LuaApi::LuaValueMap*);
112 template QPointF PixmapLoader::getValue<QPointF>(const QString&, const ::LuaApi::LuaValueMap*);
113 template QRectF PixmapLoader::getValue<QRectF>(const QString&, const ::LuaApi::LuaValueMap*);
114 template QBrush PixmapLoader::getValue<QBrush>(const QString&, const ::LuaApi::LuaValueMap*);
115 template QColor PixmapLoader::getValue<QColor>(const QString&, const ::LuaApi::LuaValueMap*);
116 template QFont PixmapLoader::getValue<QFont>(const QString&, const ::LuaApi::LuaValueMap*);
117 template ::LuaApi::LuaValueMap PixmapLoader::getValue< ::LuaApi::LuaValueMap>(const QString&, const ::LuaApi::LuaValueMap*);
120 template<typename T>
121 T PixmapLoader::getStaticValue(const QString& id, const ::LuaApi::LuaValueMap* args) {
122 if(m_base.isEmpty())
123 return T();
125 if(!m_loader)
126 initialize();
128 return m_loader->getValue<T>(id, 0, args);
131 template QPixmap PixmapLoader::getStaticValue<QPixmap>(const QString&, const ::LuaApi::LuaValueMap*);
132 template Loader::PixmapOrMap PixmapLoader::getStaticValue<Loader::PixmapOrMap>(const QString&, const ::LuaApi::LuaValueMap*);
133 template Loader::Glyph PixmapLoader::getStaticValue<Loader::Glyph>(const QString&, const ::LuaApi::LuaValueMap*);
134 template double PixmapLoader::getStaticValue<double>(const QString&, const ::LuaApi::LuaValueMap*);
135 template QPointF PixmapLoader::getStaticValue<QPointF>(const QString&, const ::LuaApi::LuaValueMap*);
136 template QRectF PixmapLoader::getStaticValue<QRectF>(const QString&, const ::LuaApi::LuaValueMap*);
137 template QBrush PixmapLoader::getStaticValue<QBrush>(const QString&, const ::LuaApi::LuaValueMap*);
138 template QColor PixmapLoader::getStaticValue<QColor>(const QString&, const ::LuaApi::LuaValueMap*);
139 template QFont PixmapLoader::getStaticValue<QFont>(const QString&, const ::LuaApi::LuaValueMap*);
140 template ::LuaApi::LuaValueMap PixmapLoader::getStaticValue< ::LuaApi::LuaValueMap>(const QString&, const ::LuaApi::LuaValueMap*);