Better comments and docs for resource manager classes.
[tagua/yd.git] / src / loader / theme.h
blobc9ccc77de479a785a204476d2e2e28fa3dd1d9ff
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 #ifndef LOADER__THEME_H
12 #define LOADER__THEME_H
14 #include <map>
15 #include <QPixmap>
16 #include <QObject>
17 #include "loader/context.h"
18 #include "luaapi/loader.h"
20 namespace Loader {
22 typedef std::map<QRect, QPixmap, ::LuaApi::RectLess> PixmapMap;
23 typedef boost::variant<QPixmap, PixmapMap> PixmapOrMap;
25 /**
26 * @class Theme <loader/theme.h>
27 * @brief A class that represents and caches all images loaded by a theme.
29 * This class will be created once for each lua-scripted theme, and will cache
30 * images loaded from that theme.
32 class Theme : public QObject {
33 Q_OBJECT
35 private:
36 QString m_file;
38 /** there will be one such class for each size, and i will store pixmaps and glyphs */
39 class SizeCache {
40 public:
41 typedef std::map<QString, PixmapOrMap> PixmapsCache;
42 typedef std::map<QString, Glyph> GlyphsCache;
43 int m_ref_count;
44 PixmapsCache m_pixmaps_cache;
45 GlyphsCache m_glyphs_cache;
47 SizeCache()
48 : m_ref_count(0) {}
51 typedef std::map<int, SizeCache> Cache;
53 Context m_context;
54 LuaApi::Loader m_lua_loader;
55 Cache m_cache;
57 static PixmapOrMap to_pixmap_map(const ::LuaApi::ImageOrMap& m);
59 private slots:
60 void onSettingsChanged();
62 public:
63 /** Constructor, created the class from a lua theme file */
64 Theme(const QString& lua_file);
65 ~Theme();
67 /** References the size \a size, enabling you to get pixmaps of size \a size */
68 void refSize(int size);
70 /** Unreferences the size */
71 void unrefSize(int size);
73 /** Loads a pixmap */
74 QPixmap getPixmap(const QString& key, int size);
76 /** Loads a pixmap -or- map of rects->pixmaps */
77 PixmapOrMap getPixmapMap(const QString& key, int size);
79 /** Loads a glyph */
80 Glyph getGlyph(const QString& key, int size);
83 } //end namespace loader
85 #endif //LOADER__THEME_H