• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KStyles

pixmaploader.h

Go to the documentation of this file.
00001 /*
00002    Copyright (c) 2003-2005 Maksim Orlovich <maksim@kde.org>
00003    Copyright (c) 2002 Malte Starostik <malte@kde.org>
00004    
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef __pixmaploader_h__
00023 #define __pixmaploader_h__
00024 
00025 #include <QtCore/QCache>
00026 #include <QtGui/QImage>
00027 #include <QtGui/QStyleOption>
00028 
00029 class QPixmap;
00030 class QImage;
00031 
00032 #include "keramikrc.h"
00033 
00034 namespace Keramik
00035 {
00036     class PixmapLoader
00037     {
00038     public:
00039         PixmapLoader();
00040 
00041         QPixmap pixmap( int name, const QColor& color,  const QColor& bg,
00042                                          bool disabled = false, bool blend = true );
00043 
00044         QPixmap scale( int name, int width, int height, const QColor& color,  const QColor& bg,
00045                                         bool disabled = false, bool blend = true );
00046         QSize size( int id );
00047 
00048         void clear();
00049 
00050         static PixmapLoader& the()
00051         {
00052              if (!s_instance)
00053                 s_instance = new PixmapLoader;
00054             return *s_instance;
00055         }
00056 
00057         static void release()
00058         {
00059             delete s_instance;
00060             s_instance = 0;
00061         }
00062 
00063     private:
00064 
00065         struct KeramikCacheEntry
00066         {
00067             int m_id;
00068             int m_width;
00069             int m_height;
00070             QRgb m_colorCode;
00071             QRgb m_bgCode;
00072             bool    m_disabled;
00073             bool    m_blended;
00074 
00075             QPixmap* m_pixmap;
00076 
00077             KeramikCacheEntry(int id, const QColor& color, const QColor& bg, bool disabled,
00078                                             bool blended, int width, int height, QPixmap* pixmap = 0 ):
00079                 m_id(id), m_width(width), m_height(height), m_colorCode(color.rgb()),m_bgCode(bg.rgb()),
00080                 m_disabled(disabled),  m_blended(blended), m_pixmap(pixmap)
00081             {}
00082 
00083             int key()
00084             {
00085                                return (m_disabled ? 1 : 0) ^ (m_blended << 1) ^ (m_id<<2) ^ (m_width<<14) ^ (m_height<<24) ^ m_colorCode ^ (m_bgCode<<8);
00086             }
00087 
00088             bool operator == (const KeramikCacheEntry& other)
00089             {
00090                 return (m_id        == other.m_id) &&
00091                             (m_width   == other.m_width) &&
00092                             (m_height == other.m_height) &&
00093                             (m_blended == other.m_blended) &&
00094                             (m_bgCode == other.m_bgCode) &&
00095                             (m_colorCode == other.m_colorCode) &&
00096                             (m_disabled == other.m_disabled);
00097             }
00098 
00099             ~KeramikCacheEntry()
00100             {
00101                 delete m_pixmap;
00102             }
00103         };
00104 
00105 
00106 
00107         QImage* getColored(int id, const QColor& color, const QColor& bg, bool blended);
00108         QImage* getDisabled(int id, const QColor& color, const QColor& bg, bool blended);
00109         QCache <int, KeramikCacheEntry>  m_pixmapCache;
00110 
00111 
00112         unsigned char clamp[540];
00113 
00114         static PixmapLoader* s_instance;
00115     };
00116 
00117     class TilePainter
00118     {
00119     public:
00120         TilePainter( int name ) : m_columns(1),m_rows(1),m_name( name ) {}
00121         virtual ~TilePainter() {}
00122 
00123         enum PaintMode
00124         {
00125             PaintNormal,
00126             PaintMask,
00127             PaintFullBlend,
00128             PaintTrivialMask
00129         };
00130 
00131         void draw( QPainter *p, int x, int y, int width, int height, const QColor& color, const QColor& bg,
00132                          bool disabled = false, PaintMode mode = PaintNormal );
00133         void draw( QPainter *p, const QRect& rect, const QColor& color, const QColor& bg, bool disabled = false, PaintMode mode = PaintNormal )
00134         {
00135             draw( p, rect.x(), rect.y(), rect.width(), rect.height(), color, bg, disabled, mode );
00136         }
00137 
00138     protected:
00139         enum TileMode { Fixed, Scaled, Tiled };
00140 
00141         unsigned int columns() const { return m_columns; }
00142         unsigned int rows() const { return m_rows; }
00143 
00166         virtual int tileName( unsigned int, unsigned int ) const { return 0; }
00167 
00168         TileMode columnMode( unsigned int col) const
00169         {
00170             return colMde[col];
00171         }
00172 
00173         TileMode rowMode( unsigned int row) const
00174         {
00175             return rowMde[row];
00176         }
00177 
00178     protected:
00179         TileMode colMde[5], rowMde[5];
00180         unsigned int m_columns;
00181         unsigned int m_rows;
00182     private:
00183 
00184         int absTileName( unsigned int column, unsigned int row ) const
00185         {
00186             int name = tileName( column, row );
00187             return m_name + name;
00188         }
00189 
00190 
00191         QPixmap tile( unsigned int column, unsigned int row, const QColor& color, const QColor& bg, bool disabled, bool blend)
00192             { return PixmapLoader::the().pixmap( absTileName( column, row ), color, bg, disabled, blend ); }
00193         QPixmap scale( unsigned int column, unsigned int row, int width, int height, const QColor& color, const QColor& bg,
00194                             bool disabled, bool blend )
00195             { return PixmapLoader::the().scale( absTileName( column, row ), width, height, color,
00196                             bg, disabled, blend ); }
00197 
00198         int m_name;
00199 
00200     };
00201 
00202     class ScaledPainter : public TilePainter
00203     {
00204     public:
00205         enum Direction { Horizontal = 1, Vertical = 2, Both = Horizontal | Vertical };
00206         explicit ScaledPainter( int name, Direction direction = Both )
00207             : TilePainter( name ), m_direction( direction )
00208         {
00209             colMde[0] =  ( m_direction & Horizontal ) ? Scaled : Tiled;
00210             rowMde[0] =  ( m_direction & Vertical ) ? Scaled : Tiled;
00211         }
00212 
00213         virtual ~ScaledPainter() {}
00214 
00215     private:
00216         Direction m_direction;
00217     };
00218 
00219     class CenteredPainter : public TilePainter
00220     {
00221     public:
00222         CenteredPainter( int name ) : TilePainter( name ) {
00223             colMde[0] = colMde[1] = colMde[2] = colMde[3] =  Fixed;
00224             rowMde[0] = rowMde[1] = rowMde[2] = rowMde[3] = Fixed;
00225         }
00226         virtual ~CenteredPainter() {}
00227 
00228     protected:
00229     };
00230 
00231     class RectTilePainter : public TilePainter
00232     {
00233     public:
00234         explicit RectTilePainter( int name,
00235                          bool scaleH = true, bool scaleV = true,
00236                          unsigned int columns = 3, unsigned int rows = 3 );
00237 
00238         virtual ~RectTilePainter() {}
00239 
00240     protected:
00241         virtual int tileName( unsigned int column, unsigned int row ) const;
00242     private:
00243         bool m_scaleH;
00244         bool m_scaleV;
00245     };
00246 
00247     class RowPainter: public TilePainter
00248     {
00249     public:
00250         RowPainter(int name): TilePainter(name)
00251         {
00252             colMde[0] = colMde[2] = Fixed;
00253             colMde[1] = Tiled;
00254             rowMde[0] = Scaled;
00255             m_columns = 3;
00256         }
00257 
00258         virtual ~RowPainter() {}
00259     protected:
00260         virtual int tileName( unsigned int column, unsigned int /*row*/) const
00261         {
00262             return column + 3; //So can use cl, cc, cr
00263         }
00264     };
00265 
00266     class ProgressBarPainter: public TilePainter
00267     {
00268     public:
00269         ProgressBarPainter(int name, bool reverse): TilePainter(name), m_reverse(reverse)
00270         {
00271             //We use only of the tip bitmaps..
00272             if (reverse)
00273             {
00274                 colMde[0] = Fixed;
00275                 colMde[1] = Tiled;
00276             }
00277             else
00278             {
00279                 colMde[0] = Tiled;
00280                 colMde[1] = Fixed;
00281             }
00282             rowMde[0] = Scaled;
00283 
00284             m_columns = 2;
00285         }
00286 
00287         virtual ~ProgressBarPainter() {}
00288     protected:
00289         virtual int tileName( unsigned int column, unsigned int /*row*/ ) const
00290         {
00291             if (m_reverse)
00292             {
00293                 return column + 3; //So can use cl, cc, cr
00294             }
00295             else
00296                 return column + 4; //So can use cl, cc, cr + we start from cc.
00297 
00298         }
00299 
00300         bool m_reverse;
00301     };
00302 
00303 
00304     class ActiveTabPainter : public RectTilePainter
00305     {
00306     public:
00307         ActiveTabPainter( bool bottom );
00308         virtual ~ActiveTabPainter() {}
00309 
00310     protected:
00311         virtual int tileName( unsigned int column, unsigned int row ) const;
00312 
00313     private:
00314         bool m_bottom;
00315     };
00316 
00317     class InactiveTabPainter : public RectTilePainter
00318     {
00319     public:
00320         InactiveTabPainter( QStyleOptionTab::TabPosition mode, bool bottom );
00321         virtual ~InactiveTabPainter() {}
00322 
00323     protected:
00324         virtual int tileName( unsigned int column, unsigned int row ) const;
00325 
00326     private:
00327         QStyleOptionTab::TabPosition m_mode;
00328         bool m_bottom;
00329     };
00330 
00331     class ScrollBarPainter : public TilePainter
00332     {
00333     public:
00334         ScrollBarPainter( int type, int count, bool horizontal );
00335         virtual ~ScrollBarPainter() {}
00336 
00337         static int name( bool horizontal );
00338 
00339     protected:
00340         virtual int tileName( unsigned int column, unsigned int row ) const;
00341     private:
00342         int m_type;
00343         int m_count;
00344         bool m_horizontal;
00345     };
00346 
00347     class SpinBoxPainter : public TilePainter
00348     {
00349     public:
00350         SpinBoxPainter() : TilePainter( keramik_spinbox ) {
00351             colMde[0] = colMde[2] = Fixed;
00352             colMde[1] = Scaled;
00353             rowMde[0]=rowMde[1]=rowMde[2] = Scaled;
00354             m_columns = 3;
00355         }
00356         virtual ~SpinBoxPainter() {}
00357 
00358     protected:
00359         virtual int tileName( unsigned int column, unsigned int row ) const;
00360     };
00361 }
00362 
00363 #endif
00364 
00365 // vim: ts=4 sw=4 noet
00366 // kate: indent-width 4; replace-tabs off; tab-width 4;

KStyles

Skip menu "KStyles"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KCMShell
  • KNotify
  • KStyles
  • Nepomuk Daemons
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal