Diffstat (limited to 'noncore/multimedia/opieplayer2/skin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index 84f5f87..5d8929e 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp | |||
@@ -1,120 +1,121 @@ | |||
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 | #include <opie2/odebug.h> | ||
25 | 26 | ||
26 | #include <qcache.h> | 27 | #include <qcache.h> |
27 | #include <qtimer.h> | 28 | #include <qtimer.h> |
28 | 29 | ||
29 | #include <qpe/config.h> | 30 | #include <qpe/config.h> |
30 | 31 | ||
31 | #include <assert.h> | 32 | #include <assert.h> |
32 | 33 | ||
33 | struct SkinData | 34 | struct SkinData |
34 | { | 35 | { |
35 | typedef QMap<QString, QImage> ButtonMaskImageMap; | 36 | typedef QMap<QString, QImage> ButtonMaskImageMap; |
36 | 37 | ||
37 | QPixmap backgroundPixmap; | 38 | QPixmap backgroundPixmap; |
38 | QImage buttonUpImage; | 39 | QImage buttonUpImage; |
39 | QImage buttonDownImage; | 40 | QImage buttonDownImage; |
40 | QImage buttonMask; | 41 | QImage buttonMask; |
41 | ButtonMaskImageMap buttonMasks; | 42 | ButtonMaskImageMap buttonMasks; |
42 | }; | 43 | }; |
43 | 44 | ||
44 | class SkinCache : public Singleton<SkinCache> | 45 | class SkinCache : public Singleton<SkinCache> |
45 | { | 46 | { |
46 | public: | 47 | public: |
47 | SkinCache(); | 48 | SkinCache(); |
48 | 49 | ||
49 | SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix ); | 50 | SkinData *lookupAndTake( const QString &skinPath, const QString &fileNameInfix ); |
50 | 51 | ||
51 | void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ); | 52 | void store( const QString &skinPath, const QString &fileNameInfix, SkinData *data ); |
52 | 53 | ||
53 | private: | 54 | private: |
54 | typedef QCache<SkinData> DataCache; | 55 | typedef QCache<SkinData> DataCache; |
55 | typedef QCache<QPixmap> BackgroundPixmapCache; | 56 | typedef QCache<QPixmap> BackgroundPixmapCache; |
56 | 57 | ||
57 | template <class CacheType> | 58 | template <class CacheType> |
58 | void store( const QCache<CacheType> &cache, const QString &key, CacheType *data ); | 59 | void store( const QCache<CacheType> &cache, const QString &key, CacheType *data ); |
59 | 60 | ||
60 | DataCache m_cache; | 61 | DataCache m_cache; |
61 | BackgroundPixmapCache m_backgroundPixmapCache; | 62 | BackgroundPixmapCache m_backgroundPixmapCache; |
62 | }; | 63 | }; |
63 | 64 | ||
64 | Skin::Skin( const QString &name, const QString &fileNameInfix ) | 65 | Skin::Skin( const QString &name, const QString &fileNameInfix ) |
65 | : m_fileNameInfix( fileNameInfix ) | 66 | : m_fileNameInfix( fileNameInfix ) |
66 | { | 67 | { |
67 | init( name ); | 68 | init( name ); |
68 | } | 69 | } |
69 | 70 | ||
70 | Skin::Skin( const QString &fileNameInfix ) | 71 | Skin::Skin( const QString &fileNameInfix ) |
71 | : m_fileNameInfix( fileNameInfix ) | 72 | : m_fileNameInfix( fileNameInfix ) |
72 | { | 73 | { |
73 | init( defaultSkinName() ); | 74 | init( defaultSkinName() ); |
74 | } | 75 | } |
75 | 76 | ||
76 | Skin::~Skin() | 77 | Skin::~Skin() |
77 | { | 78 | { |
78 | if ( m_isCachable ) | 79 | if ( m_isCachable ) |
79 | SkinCache::self().store( m_skinPath, m_fileNameInfix, d ); | 80 | SkinCache::self().store( m_skinPath, m_fileNameInfix, d ); |
80 | else | 81 | else |
81 | delete d; | 82 | delete d; |
82 | } | 83 | } |
83 | 84 | ||
84 | void Skin::init( const QString &name ) | 85 | void Skin::init( const QString &name ) |
85 | { | 86 | { |
86 | m_isCachable = true; | 87 | m_isCachable = true; |
87 | m_skinPath = "opieplayer2/skins/" + name; | 88 | m_skinPath = "opieplayer2/skins/" + name; |
88 | d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix ); | 89 | d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix ); |
89 | } | 90 | } |
90 | 91 | ||
91 | QPixmap Skin::backgroundPixmap() const | 92 | QPixmap Skin::backgroundPixmap() const |
92 | { | 93 | { |
93 | if ( d->backgroundPixmap.isNull() ) | 94 | if ( d->backgroundPixmap.isNull() ) |
94 | d->backgroundPixmap = loadImage( QString( "%1/background" ).arg( m_skinPath ) ); | 95 | d->backgroundPixmap = loadImage( QString( "%1/background" ).arg( m_skinPath ) ); |
95 | return d->backgroundPixmap; | 96 | return d->backgroundPixmap; |
96 | } | 97 | } |
97 | 98 | ||
98 | QImage Skin::buttonUpImage() const | 99 | QImage Skin::buttonUpImage() const |
99 | { | 100 | { |
100 | if ( d->buttonUpImage.isNull() ) | 101 | if ( d->buttonUpImage.isNull() ) |
101 | d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); | 102 | d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); |
102 | return d->buttonUpImage; | 103 | return d->buttonUpImage; |
103 | } | 104 | } |
104 | 105 | ||
105 | QImage Skin::buttonDownImage() const | 106 | QImage Skin::buttonDownImage() const |
106 | { | 107 | { |
107 | if ( d->buttonDownImage.isNull() ) | 108 | if ( d->buttonDownImage.isNull() ) |
108 | d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); | 109 | d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); |
109 | return d->buttonDownImage; | 110 | return d->buttonDownImage; |
110 | } | 111 | } |
111 | 112 | ||
112 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const | 113 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const |
113 | { | 114 | { |
114 | if ( !d->buttonMask.isNull() ) | 115 | if ( !d->buttonMask.isNull() ) |
115 | return d->buttonMask; | 116 | return d->buttonMask; |
116 | 117 | ||
117 | QSize buttonAreaSize = buttonUpImage().size(); | 118 | QSize buttonAreaSize = buttonUpImage().size(); |
118 | 119 | ||
119 | d->buttonMask = QImage( buttonAreaSize, 8, 255 ); | 120 | d->buttonMask = QImage( buttonAreaSize, 8, 255 ); |
120 | d->buttonMask.fill( 0 ); | 121 | d->buttonMask.fill( 0 ); |