summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp46
-rw-r--r--noncore/multimedia/opieplayer2/skin.h4
2 files changed, 25 insertions, 25 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp
index e9fb5a6..d6f4080 100644
--- a/noncore/multimedia/opieplayer2/skin.cpp
+++ b/noncore/multimedia/opieplayer2/skin.cpp
@@ -1,324 +1,324 @@
1/* 1/*
2 Copyright (C) 2002 Simon Hausmann <simon@lst.de> 2 Copyright (C) 2002 Simon Hausmann <simon@lst.de>
3 (C) 2002 Max Reiss <harlekin@handhelds.org> 3 (C) 2002 Max Reiss <harlekin@handhelds.org>
4 (C) 2002 L. Potter <ljp@llornkcor.com> 4 (C) 2002 L. Potter <ljp@llornkcor.com>
5 (C) 2002 Holger Freyther <zecke@handhelds.org> 5 (C) 2002 Holger Freyther <zecke@handhelds.org>
6 6
7 This program is free software; you can redistribute it and/or 7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public 8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details. 15 General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to 18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include "skin.h" 23#include "skin.h"
24#include "singleton.h" 24#include "singleton.h"
25 25
26#include <qcache.h> 26#include <qcache.h>
27#include <qmap.h> 27#include <qmap.h>
28#include <qtimer.h> 28#include <qtimer.h>
29 29
30#include <qpe/resource.h> 30#include <qpe/resource.h>
31#include <qpe/config.h> 31#include <qpe/config.h>
32 32
33#include <assert.h> 33#include <assert.h>
34 34
35struct SkinData 35struct SkinData
36{ 36{
37 typedef QMap<QString, QImage> ButtonMaskImageMap; 37 typedef QMap<QString, QImage> ButtonMaskImageMap;
38 38
39 QImage backgroundImage; 39 QPixmap backgroundPixmap;
40 QImage buttonUpImage; 40 QImage buttonUpImage;
41 QImage buttonDownImage; 41 QImage buttonDownImage;
42 QImage buttonMask; 42 QImage buttonMask;
43 ButtonMaskImageMap buttonMasks; 43 ButtonMaskImageMap buttonMasks;
44}; 44};
45 45
46class SkinCache : public Singleton<SkinCache> 46class SkinCache : public Singleton<SkinCache>
47{ 47{
48public: 48public:
49 SkinCache(); 49 SkinCache();
50 50
51 SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix ); 51 SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix );
52 52
53 void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ); 53 void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data );
54 54
55private: 55private:
56 typedef QCache<SkinData> DataCache; 56 typedef QCache<SkinData> DataCache;
57 typedef QCache<QImage> BackgroundImageCache; 57 typedef QCache<QPixmap> BackgroundPixmapCache;
58 58
59 template <class CacheType> 59 template <class CacheType>
60 void store( const QCache<CacheType> &cache, const QString &key, CacheType *data ); 60 void store( const QCache<CacheType> &cache, const QString &key, CacheType *data );
61 61
62 DataCache m_cache; 62 DataCache m_cache;
63 BackgroundImageCache m_backgroundImageCache; 63 BackgroundPixmapCache m_backgroundPixmapCache;
64}; 64};
65 65
66Skin::Skin( const QString &name, const QString &fileNameInfix ) 66Skin::Skin( const QString &name, const QString &fileNameInfix )
67 : m_fileNameInfix( fileNameInfix ) 67 : m_fileNameInfix( fileNameInfix )
68{ 68{
69 init( name ); 69 init( name );
70} 70}
71 71
72Skin::Skin( const QString &fileNameInfix ) 72Skin::Skin( const QString &fileNameInfix )
73 : m_fileNameInfix( fileNameInfix ) 73 : m_fileNameInfix( fileNameInfix )
74{ 74{
75 init( defaultSkinName() ); 75 init( defaultSkinName() );
76} 76}
77 77
78Skin::~Skin() 78Skin::~Skin()
79{ 79{
80 SkinCache::self().store( m_skinPath, m_fileNameInfix, d ); 80 SkinCache::self().store( m_skinPath, m_fileNameInfix, d );
81} 81}
82 82
83void Skin::init( const QString &name ) 83void Skin::init( const QString &name )
84{ 84{
85 m_skinPath = "opieplayer2/skins/" + name; 85 m_skinPath = "opieplayer2/skins/" + name;
86 d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix ); 86 d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix );
87} 87}
88 88
89void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) 89void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount )
90{ 90{
91 backgroundImage(); 91 backgroundPixmap();
92 buttonUpImage(); 92 buttonUpImage();
93 buttonDownImage(); 93 buttonDownImage();
94 ( void )buttonMask( skinButtonInfo, buttonCount ); 94 ( void )buttonMask( skinButtonInfo, buttonCount );
95} 95}
96 96
97QImage Skin::backgroundImage() const 97QPixmap Skin::backgroundPixmap() const
98{ 98{
99 if ( d->backgroundImage.isNull() ) 99 if ( d->backgroundPixmap.isNull() )
100 d->backgroundImage = loadImage( QString( "%1/background" ).arg( m_skinPath ) ); 100 d->backgroundPixmap = loadImage( QString( "%1/background" ).arg( m_skinPath ) );
101 return d->backgroundImage; 101 return d->backgroundPixmap;
102} 102}
103 103
104QImage Skin::buttonUpImage() const 104QImage Skin::buttonUpImage() const
105{ 105{
106 if ( d->buttonUpImage.isNull() ) 106 if ( d->buttonUpImage.isNull() )
107 d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); 107 d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
108 return d->buttonUpImage; 108 return d->buttonUpImage;
109} 109}
110 110
111QImage Skin::buttonDownImage() const 111QImage Skin::buttonDownImage() const
112{ 112{
113 if ( d->buttonDownImage.isNull() ) 113 if ( d->buttonDownImage.isNull() )
114 d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); 114 d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) );
115 return d->buttonDownImage; 115 return d->buttonDownImage;
116} 116}
117 117
118QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const 118QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const
119{ 119{
120 if ( !d->buttonMask.isNull() ) 120 if ( !d->buttonMask.isNull() )
121 return d->buttonMask; 121 return d->buttonMask;
122 122
123 QSize buttonAreaSize = buttonUpImage().size(); 123 QSize buttonAreaSize = buttonUpImage().size();
124 124
125 d->buttonMask = QImage( buttonAreaSize, 8, 255 ); 125 d->buttonMask = QImage( buttonAreaSize, 8, 255 );
126 d->buttonMask.fill( 0 ); 126 d->buttonMask.fill( 0 );
127 127
128 for ( uint i = 0; i < buttonCount; ++i ) 128 for ( uint i = 0; i < buttonCount; ++i )
129 addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) ); 129 addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) );
130 130
131 return d->buttonMask; 131 return d->buttonMask;
132} 132}
133 133
134void Skin::addButtonToMask( int tag, const QImage &maskImage ) const 134void Skin::addButtonToMask( int tag, const QImage &maskImage ) const
135{ 135{
136 if ( maskImage.isNull() ) 136 if ( maskImage.isNull() )
137 return; 137 return;
138 138
139 uchar **dest = d->buttonMask.jumpTable(); 139 uchar **dest = d->buttonMask.jumpTable();
140 for ( int y = 0; y < d->buttonMask.height(); y++ ) { 140 for ( int y = 0; y < d->buttonMask.height(); y++ ) {
141 uchar *line = dest[y]; 141 uchar *line = dest[y];
142 for ( int x = 0; x < d->buttonMask.width(); x++ ) 142 for ( int x = 0; x < d->buttonMask.width(); x++ )
143 if ( !qRed( maskImage.pixel( x, y ) ) ) 143 if ( !qRed( maskImage.pixel( x, y ) ) )
144 line[x] = tag; 144 line[x] = tag;
145 } 145 }
146} 146}
147 147
148QImage Skin::buttonMaskImage( const QString &fileName ) const 148QImage Skin::buttonMaskImage( const QString &fileName ) const
149{ 149{
150 SkinData::ButtonMaskImageMap::Iterator it = d->buttonMasks.find( fileName ); 150 SkinData::ButtonMaskImageMap::Iterator it = d->buttonMasks.find( fileName );
151 if ( it == d->buttonMasks.end() ) { 151 if ( it == d->buttonMasks.end() ) {
152 QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); 152 QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix );
153 QString path = prefix + fileName + ".png"; 153 QString path = prefix + fileName + ".png";
154 it = d->buttonMasks.insert( fileName, loadImage( path ) ); 154 it = d->buttonMasks.insert( fileName, loadImage( path ) );
155 } 155 }
156 return *it; 156 return *it;
157} 157}
158 158
159QString Skin::defaultSkinName() 159QString Skin::defaultSkinName()
160{ 160{
161 Config cfg( "OpiePlayer" ); 161 Config cfg( "OpiePlayer" );
162 cfg.setGroup( "Options" ); 162 cfg.setGroup( "Options" );
163 return cfg.readEntry( "Skin", "default" ); 163 return cfg.readEntry( "Skin", "default" );
164} 164}
165 165
166QImage Skin::loadImage( const QString &fileName ) 166QImage Skin::loadImage( const QString &fileName )
167{ 167{
168 return QImage( Resource::findPixmap( fileName ) ); 168 return QImage( Resource::findPixmap( fileName ) );
169} 169}
170 170
171SkinCache::SkinCache() 171SkinCache::SkinCache()
172{ 172{
173 // let's say we cache two skins (audio+video) at maximum 173 // let's say we cache two skins (audio+video) at maximum
174 m_cache.setMaxCost( 2 ); 174 m_cache.setMaxCost( 2 );
175 // ... and one background pixmap 175 // ... and one background pixmap
176 m_backgroundImageCache.setMaxCost( 1 ); 176 m_backgroundPixmapCache.setMaxCost( 1 );
177} 177}
178 178
179SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix ) 179SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix )
180{ 180{
181 QString key = skinPath + fileNameInfix; 181 QString key = skinPath + fileNameInfix;
182 182
183 SkinData *data = m_cache.take( key ); 183 SkinData *data = m_cache.take( key );
184 if ( !data ) 184 if ( !data )
185 data = new SkinData; 185 data = new SkinData;
186 else 186 else
187 qDebug( "SkinCache: hit" ); 187 qDebug( "SkinCache: hit" );
188 188
189 QImage *bgImage = m_backgroundImageCache.find( skinPath ); 189 QPixmap *bgPixmap = m_backgroundPixmapCache.find( skinPath );
190 if ( bgImage ) { 190 if ( bgPixmap ) {
191 qDebug( "SkinCache: hit on bgimage" ); 191 qDebug( "SkinCache: hit on bgpixmap" );
192 data->backgroundImage = *bgImage; 192 data->backgroundPixmap = *bgPixmap;
193 } 193 }
194 else 194 else
195 data->backgroundImage = QImage(); 195 data->backgroundPixmap = QPixmap();
196 196
197 return data; 197 return data;
198} 198}
199 199
200void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ) 200void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data )
201{ 201{
202 QImage *backgroundImage = new QImage( data->backgroundImage ); 202 QPixmap *backgroundPixmap = new QPixmap( data->backgroundPixmap );
203 203
204 data->backgroundImage = QImage(); 204 data->backgroundPixmap = QPixmap();
205 205
206 QString key = skinPath + fileNameInfix; 206 QString key = skinPath + fileNameInfix;
207 207
208 if ( m_cache.find( key, false /*ref*/ ) != 0 || 208 if ( m_cache.find( key, false /*ref*/ ) != 0 ||
209 !m_cache.insert( key, data ) ) 209 !m_cache.insert( key, data ) )
210 delete data; 210 delete data;
211 211
212 if ( m_backgroundImageCache.find( skinPath, false /*ref*/ ) != 0 || 212 if ( m_backgroundPixmapCache.find( skinPath, false /*ref*/ ) != 0 ||
213 !m_backgroundImageCache.insert( skinPath, backgroundImage ) ) 213 !m_backgroundPixmapCache.insert( skinPath, backgroundPixmap ) )
214 delete backgroundImage; 214 delete backgroundPixmap;
215} 215}
216 216
217SkinLoader::IncrementalLoader::IncrementalLoader( const Info &info ) 217SkinLoader::IncrementalLoader::IncrementalLoader( const Info &info )
218 : m_skin( info.skinName, info.fileNameInfix ), m_info( info ) 218 : m_skin( info.skinName, info.fileNameInfix ), m_info( info )
219{ 219{
220 m_currentState = LoadBackgroundImage; 220 m_currentState = LoadBackgroundPixmap;
221} 221}
222 222
223SkinLoader::IncrementalLoader::LoaderResult SkinLoader::IncrementalLoader::loadStep() 223SkinLoader::IncrementalLoader::LoaderResult SkinLoader::IncrementalLoader::loadStep()
224{ 224{
225 switch ( m_currentState ) { 225 switch ( m_currentState ) {
226 case LoadBackgroundImage: 226 case LoadBackgroundPixmap:
227 qDebug( "load bgimage" ); 227 qDebug( "load bgpixmap" );
228 m_skin.backgroundImage(); 228 m_skin.backgroundPixmap();
229 m_currentState = LoadButtonUpImage; 229 m_currentState = LoadButtonUpImage;
230 break; 230 break;
231 case LoadButtonUpImage: 231 case LoadButtonUpImage:
232 qDebug( "load upimage" ); 232 qDebug( "load upimage" );
233 m_skin.buttonUpImage(); 233 m_skin.buttonUpImage();
234 m_currentState = LoadButtonDownImage; 234 m_currentState = LoadButtonDownImage;
235 break; 235 break;
236 case LoadButtonDownImage: 236 case LoadButtonDownImage:
237 qDebug( "load downimage" ); 237 qDebug( "load downimage" );
238 m_skin.buttonDownImage(); 238 m_skin.buttonDownImage();
239 m_currentState = LoadButtonMasks; 239 m_currentState = LoadButtonMasks;
240 m_currentButton = 0; 240 m_currentButton = 0;
241 break; 241 break;
242 case LoadButtonMasks: 242 case LoadButtonMasks:
243 qDebug( "load button masks %i", m_currentButton ); 243 qDebug( "load button masks %i", m_currentButton );
244 m_skin.buttonMaskImage( m_info.buttonInfo[ m_currentButton ].fileName ); 244 m_skin.buttonMaskImage( m_info.buttonInfo[ m_currentButton ].fileName );
245 245
246 m_currentButton++; 246 m_currentButton++;
247 if ( m_currentButton >= m_info.buttonCount ) 247 if ( m_currentButton >= m_info.buttonCount )
248 m_currentState = LoadButtonMask; 248 m_currentState = LoadButtonMask;
249 249
250 break; 250 break;
251 case LoadButtonMask: 251 case LoadButtonMask:
252 qDebug( "load whole mask" ); 252 qDebug( "load whole mask" );
253 m_skin.buttonMask( m_info.buttonInfo, m_info.buttonCount ); 253 m_skin.buttonMask( m_info.buttonInfo, m_info.buttonCount );
254 return LoadingCompleted; 254 return LoadingCompleted;
255 } 255 }
256 256
257 return MoreToCome; 257 return MoreToCome;
258} 258}
259 259
260SkinLoader::SkinLoader() 260SkinLoader::SkinLoader()
261 : m_currentLoader( 0 ), m_timerId( -1 ) 261 : m_currentLoader( 0 ), m_timerId( -1 )
262{ 262{
263} 263}
264 264
265SkinLoader::~SkinLoader() 265SkinLoader::~SkinLoader()
266{ 266{
267 qDebug( "SkinLoader::~SkinLoader()" ); 267 qDebug( "SkinLoader::~SkinLoader()" );
268 killTimers(); 268 killTimers();
269 delete m_currentLoader; 269 delete m_currentLoader;
270} 270}
271 271
272void SkinLoader::schedule( const MediaWidget::GUIInfo &guiInfo ) 272void SkinLoader::schedule( const MediaWidget::GUIInfo &guiInfo )
273{ 273{
274 schedule( Skin::defaultSkinName(), guiInfo ); 274 schedule( Skin::defaultSkinName(), guiInfo );
275} 275}
276 276
277void SkinLoader::schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo ) 277void SkinLoader::schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo )
278{ 278{
279 pendingSkins << Info( skinName, guiInfo ); 279 pendingSkins << Info( skinName, guiInfo );
280} 280}
281 281
282void SkinLoader::start() 282void SkinLoader::start()
283{ 283{
284 assert( m_timerId == -1 ); 284 assert( m_timerId == -1 );
285 m_timerId = startTimer( 100 /* ms */ ); 285 m_timerId = startTimer( 100 /* ms */ );
286 qDebug( "SkinLoader::start() %d jobs", pendingSkins.count() ); 286 qDebug( "SkinLoader::start() %d jobs", pendingSkins.count() );
287} 287}
288 288
289void SkinLoader::timerEvent( QTimerEvent *ev ) 289void SkinLoader::timerEvent( QTimerEvent *ev )
290{ 290{
291 if ( ev->timerId() != m_timerId ) { 291 if ( ev->timerId() != m_timerId ) {
292 QObject::timerEvent( ev ); 292 QObject::timerEvent( ev );
293 return; 293 return;
294 } 294 }
295 295
296 if ( !m_currentLoader ) { 296 if ( !m_currentLoader ) {
297 297
298 if ( pendingSkins.isEmpty() ) { 298 if ( pendingSkins.isEmpty() ) {
299 qDebug( "all jobs done" ); 299 qDebug( "all jobs done" );
300 killTimer( m_timerId ); 300 killTimer( m_timerId );
301 m_timerId = -1; 301 m_timerId = -1;
302 // ### qt3: use deleteLater(); 302 // ### qt3: use deleteLater();
303 QTimer::singleShot( 0, this, SLOT( deleteMe() ) ); 303 QTimer::singleShot( 0, this, SLOT( deleteMe() ) );
304 return; 304 return;
305 } 305 }
306 306
307 Info nfo = *pendingSkins.begin(); 307 Info nfo = *pendingSkins.begin();
308 pendingSkins.remove( pendingSkins.begin() ); 308 pendingSkins.remove( pendingSkins.begin() );
309 309
310 m_currentLoader = new IncrementalLoader( nfo ); 310 m_currentLoader = new IncrementalLoader( nfo );
311 qDebug( "new loader %i jobs left", pendingSkins.count() ); 311 qDebug( "new loader %i jobs left", pendingSkins.count() );
312 } 312 }
313 313
314 if ( m_currentLoader->loadStep() == IncrementalLoader::LoadingCompleted ) { 314 if ( m_currentLoader->loadStep() == IncrementalLoader::LoadingCompleted ) {
315 delete m_currentLoader; 315 delete m_currentLoader;
316 m_currentLoader = 0; 316 m_currentLoader = 0;
317 } 317 }
318 318
319 qDebug( "finished step" ); 319 qDebug( "finished step" );
320} 320}
321 321
322void SkinLoader::deleteMe() 322void SkinLoader::deleteMe()
323{ 323{
324 delete this; 324 delete this;
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h
index a43a1d0..90062c2 100644
--- a/noncore/multimedia/opieplayer2/skin.h
+++ b/noncore/multimedia/opieplayer2/skin.h
@@ -1,124 +1,124 @@
1/* 1/*
2 Copyright (C) 2002 Simon Hausmann <simon@lst.de> 2 Copyright (C) 2002 Simon Hausmann <simon@lst.de>
3 (C) 2002 Max Reiss <harlekin@handhelds.org> 3 (C) 2002 Max Reiss <harlekin@handhelds.org>
4 (C) 2002 L. Potter <ljp@llornkcor.com> 4 (C) 2002 L. Potter <ljp@llornkcor.com>
5 (C) 2002 Holger Freyther <zecke@handhelds.org> 5 (C) 2002 Holger Freyther <zecke@handhelds.org>
6 6
7 This program is free software; you can redistribute it and/or 7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public 8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details. 15 General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to 18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#ifndef SKIN_H 23#ifndef SKIN_H
24#define SKIN_H 24#define SKIN_H
25 25
26#include <qstring.h> 26#include <qstring.h>
27#include <qimage.h> 27#include <qimage.h>
28#include <qobject.h> 28#include <qobject.h>
29 29
30#include "mediawidget.h" 30#include "mediawidget.h"
31 31
32struct SkinData; 32struct SkinData;
33 33
34class Skin 34class Skin
35{ 35{
36public: 36public:
37 Skin( const QString &name, const QString &fileNameInfix ); 37 Skin( const QString &name, const QString &fileNameInfix );
38 Skin( const QString &fileNameInfix ); 38 Skin( const QString &fileNameInfix );
39 ~Skin(); 39 ~Skin();
40 40
41 void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); 41 void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount );
42 42
43 QImage backgroundImage() const; 43 QPixmap backgroundPixmap() const;
44 QImage buttonUpImage() const; 44 QImage buttonUpImage() const;
45 QImage buttonDownImage() const; 45 QImage buttonDownImage() const;
46 46
47 QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; 47 QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const;
48 48
49 QImage buttonMaskImage( const QString &fileName ) const; 49 QImage buttonMaskImage( const QString &fileName ) const;
50 50
51 static QString defaultSkinName(); 51 static QString defaultSkinName();
52 52
53private: 53private:
54 void init( const QString &name ); 54 void init( const QString &name );
55 55
56 void addButtonToMask( int tag, const QImage &maskImage ) const; 56 void addButtonToMask( int tag, const QImage &maskImage ) const;
57 57
58 static QImage loadImage( const QString &fileName ); 58 static QImage loadImage( const QString &fileName );
59 59
60 QString m_fileNameInfix; 60 QString m_fileNameInfix;
61 QString m_skinPath; 61 QString m_skinPath;
62 62
63 SkinData *d; 63 SkinData *d;
64 64
65 Skin( const Skin & ); 65 Skin( const Skin & );
66 Skin &operator=( const Skin & ); 66 Skin &operator=( const Skin & );
67}; 67};
68 68
69class SkinLoader : public QObject 69class SkinLoader : public QObject
70{ 70{
71 Q_OBJECT 71 Q_OBJECT
72public: 72public:
73 SkinLoader(); 73 SkinLoader();
74 virtual ~SkinLoader(); 74 virtual ~SkinLoader();
75 75
76 void schedule( const MediaWidget::GUIInfo &guiInfo ); 76 void schedule( const MediaWidget::GUIInfo &guiInfo );
77 void schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo ); 77 void schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo );
78 78
79 void start(); 79 void start();
80 80
81protected: 81protected:
82 virtual void timerEvent( QTimerEvent *ev ); 82 virtual void timerEvent( QTimerEvent *ev );
83 83
84private slots: 84private slots:
85 void deleteMe(); 85 void deleteMe();
86 86
87private: 87private:
88 struct Info : public MediaWidget::GUIInfo 88 struct Info : public MediaWidget::GUIInfo
89 { 89 {
90 Info() {} 90 Info() {}
91 Info( const QString &_skinName, const MediaWidget::GUIInfo &guiInfo ) 91 Info( const QString &_skinName, const MediaWidget::GUIInfo &guiInfo )
92 : MediaWidget::GUIInfo( guiInfo ), skinName( _skinName ) 92 : MediaWidget::GUIInfo( guiInfo ), skinName( _skinName )
93 {} 93 {}
94 94
95 QString skinName; 95 QString skinName;
96 }; 96 };
97 typedef QValueList<Info> InfoList; 97 typedef QValueList<Info> InfoList;
98 98
99 class IncrementalLoader 99 class IncrementalLoader
100 { 100 {
101 public: 101 public:
102 enum LoaderResult { LoadingCompleted, MoreToCome }; 102 enum LoaderResult { LoadingCompleted, MoreToCome };
103 103
104 IncrementalLoader( const Info &info ); 104 IncrementalLoader( const Info &info );
105 105
106 LoaderResult loadStep(); 106 LoaderResult loadStep();
107 107
108 private: 108 private:
109 enum State { LoadBackgroundImage, LoadButtonUpImage, LoadButtonDownImage, LoadButtonMasks, LoadButtonMask }; 109 enum State { LoadBackgroundPixmap, LoadButtonUpImage, LoadButtonDownImage, LoadButtonMasks, LoadButtonMask };
110 110
111 Skin m_skin; 111 Skin m_skin;
112 Info m_info; 112 Info m_info;
113 State m_currentState; 113 State m_currentState;
114 uint m_currentButton; 114 uint m_currentButton;
115 }; 115 };
116 116
117 InfoList pendingSkins; 117 InfoList pendingSkins;
118 IncrementalLoader *m_currentLoader; 118 IncrementalLoader *m_currentLoader;
119 int m_timerId; 119 int m_timerId;
120}; 120};
121 121
122#endif // SKIN_H 122#endif // SKIN_H
123/* vim: et sw=4 ts=4 123/* vim: et sw=4 ts=4
124 */ 124 */