-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 46 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.h | 4 |
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 | |||
@@ -27,49 +27,49 @@ | |||
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 | ||
35 | struct SkinData | 35 | struct 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 | ||
46 | class SkinCache : public Singleton<SkinCache> | 46 | class SkinCache : public Singleton<SkinCache> |
47 | { | 47 | { |
48 | public: | 48 | public: |
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 | ||
55 | private: | 55 | private: |
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 | ||
66 | Skin::Skin( const QString &name, const QString &fileNameInfix ) | 66 | Skin::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 | ||
72 | Skin::Skin( const QString &fileNameInfix ) | 72 | Skin::Skin( const QString &fileNameInfix ) |
73 | : m_fileNameInfix( fileNameInfix ) | 73 | : m_fileNameInfix( fileNameInfix ) |
74 | { | 74 | { |
75 | init( defaultSkinName() ); | 75 | init( defaultSkinName() ); |
@@ -79,35 +79,35 @@ Skin::~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 | ||
83 | void Skin::init( const QString &name ) | 83 | void 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 | ||
89 | void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) | 89 | void 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 | ||
97 | QImage Skin::backgroundImage() const | 97 | QPixmap 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 | ||
104 | QImage Skin::buttonUpImage() const | 104 | QImage 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 | ||
111 | QImage Skin::buttonDownImage() const | 111 | QImage Skin::buttonDownImage() const |
112 | { | 112 | { |
113 | if ( d->buttonDownImage.isNull() ) | 113 | if ( d->buttonDownImage.isNull() ) |
@@ -164,77 +164,77 @@ QString Skin::defaultSkinName() | |||
164 | } | 164 | } |
165 | 165 | ||
166 | QImage Skin::loadImage( const QString &fileName ) | 166 | QImage Skin::loadImage( const QString &fileName ) |
167 | { | 167 | { |
168 | return QImage( Resource::findPixmap( fileName ) ); | 168 | return QImage( Resource::findPixmap( fileName ) ); |
169 | } | 169 | } |
170 | 170 | ||
171 | SkinCache::SkinCache() | 171 | SkinCache::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 | ||
179 | SkinData *SkinCache::lookupAndTake( const QString &skinPath, const QString &fileNameInfix ) | 179 | SkinData *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 | ||
200 | void SkinCache::store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ) | 200 | void 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 | ||
217 | SkinLoader::IncrementalLoader::IncrementalLoader( const Info &info ) | 217 | SkinLoader::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 | ||
223 | SkinLoader::IncrementalLoader::LoaderResult SkinLoader::IncrementalLoader::loadStep() | 223 | SkinLoader::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; |
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 | |||
@@ -31,25 +31,25 @@ | |||
31 | 31 | ||
32 | struct SkinData; | 32 | struct SkinData; |
33 | 33 | ||
34 | class Skin | 34 | class Skin |
35 | { | 35 | { |
36 | public: | 36 | public: |
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 | ||
53 | private: | 53 | private: |
54 | void init( const QString &name ); | 54 | void init( const QString &name ); |
55 | 55 | ||
@@ -97,25 +97,25 @@ private: | |||
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 | ||