thememanager.h

Go to the documentation of this file.
00001 #ifndef THEME_MANAGER_H
00002 #define THEME_MANAGER_H
00003 /*
00004    This file is part of the KDE games lskat program
00005    Copyright (c) 2006 Martin Heni <kde@heni-online.de>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 // Qt includes
00024 #include <QObject>
00025 #include <QHash>
00026 
00027 // KDE includes
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      // The theme ID
00086      QString mId;
00087      
00088      // The theme manager
00089      ThemeManager* mThemeManager;
00090      
00091      // The current scale for the object (maximum extension)
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      // The used SVG rendered
00242      KSvgRenderer* mRenderer;
00243 
00244      // The card SVG rendered
00245      KSvgRenderer* mCardRenderer;
00246 
00247      // The deck SVG rendered
00248      KSvgRenderer* mDeckRenderer;
00249      
00250      // Storage of all theme objects [object,1] [TODO: Alist might suffice]
00251      QHash<Themable*,int> mObjects;
00252 
00253      // The cache of all pixmap objects [id,pixmap]
00254      QHash<QString,QPixmap> mPixmapCache;
00255      
00256      // The theme configration file
00257      KConfig* mConfig;
00258 
00259      // The card configration file
00260      QString mCardFile;
00261 
00262      // The deck configration file
00263      QString mDeckFile;
00264 
00265      // The current theme scale
00266      int mScale;
00267 
00268      // The aspect ration
00269      double mAspectRatio;
00270 
00271      // The card aspect ration
00272      double mCardAspectRatio;
00273 
00274      // The theme file
00275      QString mThemeFile;
00276      
00277 };
00278 
00279 
00280 #endif

Generated on Tue May 1 09:34:40 2007 for LSkat by  doxygen 1.4.6