00001 #ifndef THEME_MANAGER_H
00002 #define THEME_MANAGER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <QObject>
00025 #include <QHash>
00026
00027
00028 #include <kconfig.h>
00029 #include <KSvgRenderer>
00030
00031
00032 class ThemeManager;
00033
00039 class Themable
00040 {
00041 public:
00044 Themable();
00045
00052 Themable(QString id, ThemeManager* thememanager);
00053
00056 virtual ~Themable();
00057
00061 QString id() {return mId;}
00062
00066 ThemeManager* thememanager() {return mThemeManager;}
00067
00071 double getScale() {return mScale;}
00072
00076 void setScale(double scale) {mScale = scale;}
00077
00082 virtual void changeTheme() = 0;
00083
00084 private:
00085
00086 QString mId;
00087
00088
00089 ThemeManager* mThemeManager;
00090
00091
00092 double mScale;
00093 };
00094
00095
00096
00105 class ThemeManager : public QObject
00106 {
00107
00108 public:
00116 ThemeManager(QString cards, QString deck, QString themefile, QObject* parent, int initialSize = 1);
00117
00124 const QPixmap getCard(int suite, int cardtype, double width);
00125
00130 const QPixmap getCardback(double width);
00131
00139 const QPixmap getPixmap(QString svgid, QSize size);
00140
00149 const QPixmap getPixmap(QString svgid, double width);
00150
00160 const QPixmap getPixmap(QString svgid, QString svgref, double refwidth);
00161
00165 double getScale();
00166
00170 KConfigGroup config(QString id);
00171
00175 void registerTheme(Themable* ob);
00176
00180 void unregisterTheme(Themable* ob);
00181
00186 void updateTheme(Themable* ob);
00187
00192 void updateCardTheme(QString cards, QString deck);
00193
00200 void updateTheme(QString themefile);
00201
00207 void rescale(int scale);
00208
00213 double aspectRatio() {return mAspectRatio;}
00214
00215 protected:
00224 const QPixmap getPixmap(KSvgRenderer* renderer, QString svgid, QSize size);
00225
00231 void updateCardTheme(QString themefile, QString cards, QString deck);
00232
00238 QString calcCardSVGId(int no);
00239
00240 private:
00241
00242 KSvgRenderer* mRenderer;
00243
00244
00245 KSvgRenderer* mCardRenderer;
00246
00247
00248 KSvgRenderer* mDeckRenderer;
00249
00250
00251 QHash<Themable*,int> mObjects;
00252
00253
00254 QHash<QString,QPixmap> mPixmapCache;
00255
00256
00257 KConfig* mConfig;
00258
00259
00260 QString mCardFile;
00261
00262
00263 QString mDeckFile;
00264
00265
00266 int mScale;
00267
00268
00269 double mAspectRatio;
00270
00271
00272 double mCardAspectRatio;
00273
00274
00275 QString mThemeFile;
00276
00277 };
00278
00279
00280 #endif