author | simon <simon> | 2002-12-14 18:18:20 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-14 18:18:20 (UTC) |
commit | 7c854ad1b909f37c7314ef4ac2061500d02af16d (patch) (unidiff) | |
tree | 24528d72c0f2d36d6777090d7d93e2536ffb120d | |
parent | ae7a270c56fa0fff6d3f530c80532c54c51be596 (diff) | |
download | opie-7c854ad1b909f37c7314ef4ac2061500d02af16d.zip opie-7c854ad1b909f37c7314ef4ac2061500d02af16d.tar.gz opie-7c854ad1b909f37c7314ef4ac2061500d02af16d.tar.bz2 |
- reduce memory usage a little bit by not storing the images after they
got converted to pixmaps
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 1 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 6 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.h | 4 |
3 files changed, 10 insertions, 1 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index edef2a7..46e7b6e 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp | |||
@@ -39,64 +39,65 @@ MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPla | |||
39 | 39 | ||
40 | MediaWidget::~MediaWidget() | 40 | MediaWidget::~MediaWidget() |
41 | { | 41 | { |
42 | } | 42 | } |
43 | 43 | ||
44 | void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, | 44 | void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, |
45 | const Skin &skin ) | 45 | const Skin &skin ) |
46 | { | 46 | { |
47 | buttonMask = skin.buttonMask( skinInfo, buttonCount ); | 47 | buttonMask = skin.buttonMask( skinInfo, buttonCount ); |
48 | 48 | ||
49 | buttons.clear(); | 49 | buttons.clear(); |
50 | buttons.reserve( buttonCount ); | 50 | buttons.reserve( buttonCount ); |
51 | 51 | ||
52 | for ( uint i = 0; i < buttonCount; ++i ) { | 52 | for ( uint i = 0; i < buttonCount; ++i ) { |
53 | Button button = setupButton( skinInfo[ i ], skin ); | 53 | Button button = setupButton( skinInfo[ i ], skin ); |
54 | buttons.push_back( button ); | 54 | buttons.push_back( button ); |
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ) | 58 | MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ) |
59 | { | 59 | { |
60 | Button button; | 60 | Button button; |
61 | button.command = buttonInfo.command; | 61 | button.command = buttonInfo.command; |
62 | button.type = buttonInfo.type; | 62 | button.type = buttonInfo.type; |
63 | button.mask = skin.buttonMaskImage( buttonInfo.fileName ); | 63 | button.mask = skin.buttonMaskImage( buttonInfo.fileName ); |
64 | 64 | ||
65 | return button; | 65 | return button; |
66 | } | 66 | } |
67 | 67 | ||
68 | void MediaWidget::loadDefaultSkin( const GUIInfo &guiInfo ) | 68 | void MediaWidget::loadDefaultSkin( const GUIInfo &guiInfo ) |
69 | { | 69 | { |
70 | Skin skin( guiInfo.fileNameInfix ); | 70 | Skin skin( guiInfo.fileNameInfix ); |
71 | skin.setCachable( false ); | ||
71 | loadSkin( guiInfo.buttonInfo, guiInfo.buttonCount, skin ); | 72 | loadSkin( guiInfo.buttonInfo, guiInfo.buttonCount, skin ); |
72 | } | 73 | } |
73 | 74 | ||
74 | void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ) | 75 | void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ) |
75 | { | 76 | { |
76 | backgroundPixmap = skin.backgroundPixmap(); | 77 | backgroundPixmap = skin.backgroundPixmap(); |
77 | buttonUpImage = skin.buttonUpImage(); | 78 | buttonUpImage = skin.buttonUpImage(); |
78 | buttonDownImage = skin.buttonDownImage(); | 79 | buttonDownImage = skin.buttonDownImage(); |
79 | 80 | ||
80 | setupButtons( skinInfo, buttonCount, skin ); | 81 | setupButtons( skinInfo, buttonCount, skin ); |
81 | } | 82 | } |
82 | 83 | ||
83 | void MediaWidget::closeEvent( QCloseEvent * ) | 84 | void MediaWidget::closeEvent( QCloseEvent * ) |
84 | { | 85 | { |
85 | mediaPlayerState.setList(); | 86 | mediaPlayerState.setList(); |
86 | } | 87 | } |
87 | 88 | ||
88 | void MediaWidget::paintEvent( QPaintEvent *pe ) | 89 | void MediaWidget::paintEvent( QPaintEvent *pe ) |
89 | { | 90 | { |
90 | QPainter p( this ); | 91 | QPainter p( this ); |
91 | 92 | ||
92 | if ( mediaPlayerState.isFullscreen() ) { | 93 | if ( mediaPlayerState.isFullscreen() ) { |
93 | // Clear the background | 94 | // Clear the background |
94 | p.setBrush( QBrush( Qt::black ) ); | 95 | p.setBrush( QBrush( Qt::black ) ); |
95 | return; | 96 | return; |
96 | } | 97 | } |
97 | 98 | ||
98 | QPixmap buffer( size() ); | 99 | QPixmap buffer( size() ); |
99 | QPainter bufferedPainter( &buffer ); | 100 | QPainter bufferedPainter( &buffer ); |
100 | bufferedPainter.drawTiledPixmap( rect(), backgroundPixmap, QPoint( 0, 0 ) ); | 101 | bufferedPainter.drawTiledPixmap( rect(), backgroundPixmap, QPoint( 0, 0 ) ); |
101 | paintAllButtons( bufferedPainter ); | 102 | paintAllButtons( bufferedPainter ); |
102 | p.drawPixmap( 0, 0, buffer ); | 103 | p.drawPixmap( 0, 0, buffer ); |
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index a8f4ae9..44f5ca2 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp | |||
@@ -48,69 +48,73 @@ class SkinCache : public Singleton<SkinCache> | |||
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<QPixmap> BackgroundPixmapCache; | 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 | BackgroundPixmapCache m_backgroundPixmapCache; | 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() ); |
76 | } | 76 | } |
77 | 77 | ||
78 | Skin::~Skin() | 78 | Skin::~Skin() |
79 | { | 79 | { |
80 | SkinCache::self().store( m_skinPath, m_fileNameInfix, d ); | 80 | if ( m_isCachable ) |
81 | SkinCache::self().store( m_skinPath, m_fileNameInfix, d ); | ||
82 | else | ||
83 | delete d; | ||
81 | } | 84 | } |
82 | 85 | ||
83 | void Skin::init( const QString &name ) | 86 | void Skin::init( const QString &name ) |
84 | { | 87 | { |
88 | m_isCachable = true; | ||
85 | m_skinPath = "opieplayer2/skins/" + name; | 89 | m_skinPath = "opieplayer2/skins/" + name; |
86 | d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix ); | 90 | d = SkinCache::self().lookupAndTake( m_skinPath, m_fileNameInfix ); |
87 | } | 91 | } |
88 | 92 | ||
89 | QPixmap Skin::backgroundPixmap() const | 93 | QPixmap Skin::backgroundPixmap() const |
90 | { | 94 | { |
91 | if ( d->backgroundPixmap.isNull() ) | 95 | if ( d->backgroundPixmap.isNull() ) |
92 | d->backgroundPixmap = loadImage( QString( "%1/background" ).arg( m_skinPath ) ); | 96 | d->backgroundPixmap = loadImage( QString( "%1/background" ).arg( m_skinPath ) ); |
93 | return d->backgroundPixmap; | 97 | return d->backgroundPixmap; |
94 | } | 98 | } |
95 | 99 | ||
96 | QImage Skin::buttonUpImage() const | 100 | QImage Skin::buttonUpImage() const |
97 | { | 101 | { |
98 | if ( d->buttonUpImage.isNull() ) | 102 | if ( d->buttonUpImage.isNull() ) |
99 | d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); | 103 | d->buttonUpImage = loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); |
100 | return d->buttonUpImage; | 104 | return d->buttonUpImage; |
101 | } | 105 | } |
102 | 106 | ||
103 | QImage Skin::buttonDownImage() const | 107 | QImage Skin::buttonDownImage() const |
104 | { | 108 | { |
105 | if ( d->buttonDownImage.isNull() ) | 109 | if ( d->buttonDownImage.isNull() ) |
106 | d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); | 110 | d->buttonDownImage = loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); |
107 | return d->buttonDownImage; | 111 | return d->buttonDownImage; |
108 | } | 112 | } |
109 | 113 | ||
110 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const | 114 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const |
111 | { | 115 | { |
112 | if ( !d->buttonMask.isNull() ) | 116 | if ( !d->buttonMask.isNull() ) |
113 | return d->buttonMask; | 117 | return d->buttonMask; |
114 | 118 | ||
115 | QSize buttonAreaSize = buttonUpImage().size(); | 119 | QSize buttonAreaSize = buttonUpImage().size(); |
116 | 120 | ||
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h index bafebd3..067b6c4 100644 --- a/noncore/multimedia/opieplayer2/skin.h +++ b/noncore/multimedia/opieplayer2/skin.h | |||
@@ -9,83 +9,87 @@ | |||
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 | ||
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 | bool isCachable() const { return m_isCachable; } | ||
42 | void setCachable( bool cachable ) { m_isCachable = cachable; } | ||
43 | |||
41 | QPixmap backgroundPixmap() const; | 44 | QPixmap backgroundPixmap() const; |
42 | QImage buttonUpImage() const; | 45 | QImage buttonUpImage() const; |
43 | QImage buttonDownImage() const; | 46 | QImage buttonDownImage() const; |
44 | 47 | ||
45 | QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; | 48 | QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; |
46 | 49 | ||
47 | QImage buttonMaskImage( const QString &fileName ) const; | 50 | QImage buttonMaskImage( const QString &fileName ) const; |
48 | 51 | ||
49 | static QString defaultSkinName(); | 52 | static QString defaultSkinName(); |
50 | 53 | ||
51 | private: | 54 | private: |
52 | void init( const QString &name ); | 55 | void init( const QString &name ); |
53 | 56 | ||
54 | void addButtonToMask( int tag, const QImage &maskImage ) const; | 57 | void addButtonToMask( int tag, const QImage &maskImage ) const; |
55 | 58 | ||
56 | static QImage loadImage( const QString &fileName ); | 59 | static QImage loadImage( const QString &fileName ); |
57 | 60 | ||
58 | QString m_fileNameInfix; | 61 | QString m_fileNameInfix; |
59 | QString m_skinPath; | 62 | QString m_skinPath; |
63 | bool m_isCachable : 1; | ||
60 | 64 | ||
61 | SkinData *d; | 65 | SkinData *d; |
62 | 66 | ||
63 | Skin( const Skin & ); | 67 | Skin( const Skin & ); |
64 | Skin &operator=( const Skin & ); | 68 | Skin &operator=( const Skin & ); |
65 | }; | 69 | }; |
66 | 70 | ||
67 | class SkinLoader : public QObject | 71 | class SkinLoader : public QObject |
68 | { | 72 | { |
69 | Q_OBJECT | 73 | Q_OBJECT |
70 | public: | 74 | public: |
71 | SkinLoader(); | 75 | SkinLoader(); |
72 | virtual ~SkinLoader(); | 76 | virtual ~SkinLoader(); |
73 | 77 | ||
74 | void schedule( const MediaWidget::GUIInfo &guiInfo ); | 78 | void schedule( const MediaWidget::GUIInfo &guiInfo ); |
75 | void schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo ); | 79 | void schedule( const QString &skinName, const MediaWidget::GUIInfo &guiInfo ); |
76 | 80 | ||
77 | void start(); | 81 | void start(); |
78 | 82 | ||
79 | protected: | 83 | protected: |
80 | virtual void timerEvent( QTimerEvent *ev ); | 84 | virtual void timerEvent( QTimerEvent *ev ); |
81 | 85 | ||
82 | private slots: | 86 | private slots: |
83 | void deleteMe(); | 87 | void deleteMe(); |
84 | 88 | ||
85 | private: | 89 | private: |
86 | struct Info : public MediaWidget::GUIInfo | 90 | struct Info : public MediaWidget::GUIInfo |
87 | { | 91 | { |
88 | Info() {} | 92 | Info() {} |
89 | Info( const QString &_skinName, const MediaWidget::GUIInfo &guiInfo ) | 93 | Info( const QString &_skinName, const MediaWidget::GUIInfo &guiInfo ) |
90 | : MediaWidget::GUIInfo( guiInfo ), skinName( _skinName ) | 94 | : MediaWidget::GUIInfo( guiInfo ), skinName( _skinName ) |
91 | {} | 95 | {} |