author | simon <simon> | 2002-12-11 17:38:55 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 17:38:55 (UTC) |
commit | 719acab56c57f283168b955582ab5b30b9809b02 (patch) (unidiff) | |
tree | 370c9f8bae6741b0ee2303b6c04f9329757a8a3e | |
parent | aaac5c934e7053fa4323b03f7ea31c32c6388883 (diff) | |
download | opie-719acab56c57f283168b955582ab5b30b9809b02.zip opie-719acab56c57f283168b955582ab5b30b9809b02.tar.gz opie-719acab56c57f283168b955582ab5b30b9809b02.tar.bz2 |
- copyright notice fixlet
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 15 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 14 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/singleton.h | 19 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 21 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.h | 22 |
5 files changed, 76 insertions, 15 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index c0106d4..702e6d7 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp | |||
@@ -1,267 +1,266 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> | 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 library 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 Library 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 library 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 | Library 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 Library General Public License | 17 | You should have received a copy of the GNU General Public License |
18 | along with this library; see the file COPYING.LIB. 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 | |||
24 | #include "mediawidget.h" | 23 | #include "mediawidget.h" |
25 | #include "playlistwidget.h" | 24 | #include "playlistwidget.h" |
26 | #include "skin.h" | 25 | #include "skin.h" |
27 | 26 | ||
28 | MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) | 27 | MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) |
29 | : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) | 28 | : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) |
30 | { | 29 | { |
31 | connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), | 30 | connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), |
32 | this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); | 31 | this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); |
33 | connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), | 32 | connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), |
34 | this, SLOT( setLength( long ) ) ); | 33 | this, SLOT( setLength( long ) ) ); |
35 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), | 34 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), |
36 | this, SLOT( setPlaying( bool ) ) ); | 35 | this, SLOT( setPlaying( bool ) ) ); |
37 | } | 36 | } |
38 | 37 | ||
39 | MediaWidget::~MediaWidget() | 38 | MediaWidget::~MediaWidget() |
40 | { | 39 | { |
41 | } | 40 | } |
42 | 41 | ||
43 | void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, | 42 | void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, |
44 | const Skin &skin ) | 43 | const Skin &skin ) |
45 | { | 44 | { |
46 | buttonMask = skin.buttonMask( skinInfo, buttonCount ); | 45 | buttonMask = skin.buttonMask( skinInfo, buttonCount ); |
47 | 46 | ||
48 | buttons.clear(); | 47 | buttons.clear(); |
49 | buttons.reserve( buttonCount ); | 48 | buttons.reserve( buttonCount ); |
50 | 49 | ||
51 | for ( uint i = 0; i < buttonCount; ++i ) { | 50 | for ( uint i = 0; i < buttonCount; ++i ) { |
52 | Button button = setupButton( skinInfo[ i ], skin ); | 51 | Button button = setupButton( skinInfo[ i ], skin ); |
53 | buttons.push_back( button ); | 52 | buttons.push_back( button ); |
54 | } | 53 | } |
55 | } | 54 | } |
56 | 55 | ||
57 | MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ) | 56 | MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ) |
58 | { | 57 | { |
59 | Button button; | 58 | Button button; |
60 | button.command = buttonInfo.command; | 59 | button.command = buttonInfo.command; |
61 | button.type = buttonInfo.type; | 60 | button.type = buttonInfo.type; |
62 | button.mask = skin.buttonMaskImage( buttonInfo.fileName ); | 61 | button.mask = skin.buttonMaskImage( buttonInfo.fileName ); |
63 | 62 | ||
64 | return button; | 63 | return button; |
65 | } | 64 | } |
66 | 65 | ||
67 | void MediaWidget::loadDefaultSkin( const GUIInfo &guiInfo ) | 66 | void MediaWidget::loadDefaultSkin( const GUIInfo &guiInfo ) |
68 | { | 67 | { |
69 | Skin skin( guiInfo.fileNameInfix ); | 68 | Skin skin( guiInfo.fileNameInfix ); |
70 | loadSkin( guiInfo.buttonInfo, guiInfo.buttonCount, skin ); | 69 | loadSkin( guiInfo.buttonInfo, guiInfo.buttonCount, skin ); |
71 | } | 70 | } |
72 | 71 | ||
73 | void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ) | 72 | void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ) |
74 | { | 73 | { |
75 | backgroundPixmap = skin.backgroundImage(); | 74 | backgroundPixmap = skin.backgroundImage(); |
76 | buttonUpImage = skin.buttonUpImage(); | 75 | buttonUpImage = skin.buttonUpImage(); |
77 | buttonDownImage = skin.buttonDownImage(); | 76 | buttonDownImage = skin.buttonDownImage(); |
78 | 77 | ||
79 | setupButtons( skinInfo, buttonCount, skin ); | 78 | setupButtons( skinInfo, buttonCount, skin ); |
80 | } | 79 | } |
81 | 80 | ||
82 | void MediaWidget::closeEvent( QCloseEvent * ) | 81 | void MediaWidget::closeEvent( QCloseEvent * ) |
83 | { | 82 | { |
84 | mediaPlayerState.setList(); | 83 | mediaPlayerState.setList(); |
85 | } | 84 | } |
86 | 85 | ||
87 | void MediaWidget::paintEvent( QPaintEvent *pe ) | 86 | void MediaWidget::paintEvent( QPaintEvent *pe ) |
88 | { | 87 | { |
89 | QPainter p( this ); | 88 | QPainter p( this ); |
90 | 89 | ||
91 | if ( mediaPlayerState.isFullscreen() ) { | 90 | if ( mediaPlayerState.isFullscreen() ) { |
92 | // Clear the background | 91 | // Clear the background |
93 | p.setBrush( QBrush( Qt::black ) ); | 92 | p.setBrush( QBrush( Qt::black ) ); |
94 | return; | 93 | return; |
95 | } | 94 | } |
96 | 95 | ||
97 | if ( !pe->erased() ) { | 96 | if ( !pe->erased() ) { |
98 | // Combine with background and double buffer | 97 | // Combine with background and double buffer |
99 | QPixmap pix( pe->rect().size() ); | 98 | QPixmap pix( pe->rect().size() ); |
100 | QPainter p( &pix ); | 99 | QPainter p( &pix ); |
101 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 100 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
102 | p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); | 101 | p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); |
103 | paintAllButtons( p ); | 102 | paintAllButtons( p ); |
104 | QPainter p2( this ); | 103 | QPainter p2( this ); |
105 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 104 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
106 | } else { | 105 | } else { |
107 | QPainter p( this ); | 106 | QPainter p( this ); |
108 | paintAllButtons( p ); | 107 | paintAllButtons( p ); |
109 | } | 108 | } |
110 | } | 109 | } |
111 | 110 | ||
112 | void MediaWidget::resizeEvent( QResizeEvent *e ) | 111 | void MediaWidget::resizeEvent( QResizeEvent *e ) |
113 | { | 112 | { |
114 | QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, upperLeftOfButtonMask ); | 113 | QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, upperLeftOfButtonMask ); |
115 | QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, upperLeftOfButtonMask ); | 114 | QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, upperLeftOfButtonMask ); |
116 | 115 | ||
117 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) { | 116 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) { |
118 | Button &button = *it; | 117 | Button &button = *it; |
119 | 118 | ||
120 | if ( button.mask.isNull() ) | 119 | if ( button.mask.isNull() ) |
121 | continue; | 120 | continue; |
122 | button.pixUp = addMaskToPixmap( pixUp, button.mask ); | 121 | button.pixUp = addMaskToPixmap( pixUp, button.mask ); |
123 | button.pixDown = addMaskToPixmap( pixDn, button.mask ); | 122 | button.pixDown = addMaskToPixmap( pixDn, button.mask ); |
124 | } | 123 | } |
125 | 124 | ||
126 | QWidget::resizeEvent( e ); | 125 | QWidget::resizeEvent( e ); |
127 | } | 126 | } |
128 | 127 | ||
129 | MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) | 128 | MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) |
130 | { | 129 | { |
131 | if ( position.x() <= 0 || position.y() <= 0 || | 130 | if ( position.x() <= 0 || position.y() <= 0 || |
132 | position.x() >= buttonMask.width() || | 131 | position.x() >= buttonMask.width() || |
133 | position.y() >= buttonMask.height() ) | 132 | position.y() >= buttonMask.height() ) |
134 | return 0; | 133 | return 0; |
135 | 134 | ||
136 | int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); | 135 | int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); |
137 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) | 136 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) |
138 | if ( it->command + 1 == pixelIdx ) | 137 | if ( it->command + 1 == pixelIdx ) |
139 | return &( *it ); | 138 | return &( *it ); |
140 | 139 | ||
141 | return 0; | 140 | return 0; |
142 | } | 141 | } |
143 | 142 | ||
144 | void MediaWidget::mousePressEvent( QMouseEvent *event ) | 143 | void MediaWidget::mousePressEvent( QMouseEvent *event ) |
145 | { | 144 | { |
146 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); | 145 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); |
147 | 146 | ||
148 | if ( !button ) { | 147 | if ( !button ) { |
149 | QWidget::mousePressEvent( event ); | 148 | QWidget::mousePressEvent( event ); |
150 | return; | 149 | return; |
151 | } | 150 | } |
152 | 151 | ||
153 | switch ( button->command ) { | 152 | switch ( button->command ) { |
154 | case VolumeUp: emit moreClicked(); return; | 153 | case VolumeUp: emit moreClicked(); return; |
155 | case VolumeDown: emit lessClicked(); return; | 154 | case VolumeDown: emit lessClicked(); return; |
156 | case Back: emit backClicked(); return; | 155 | case Back: emit backClicked(); return; |
157 | case Forward: emit forwardClicked(); return; | 156 | case Forward: emit forwardClicked(); return; |
158 | default: break; | 157 | default: break; |
159 | } | 158 | } |
160 | } | 159 | } |
161 | 160 | ||
162 | void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) | 161 | void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) |
163 | { | 162 | { |
164 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); | 163 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); |
165 | 164 | ||
166 | if ( !button ) { | 165 | if ( !button ) { |
167 | QWidget::mouseReleaseEvent( event ); | 166 | QWidget::mouseReleaseEvent( event ); |
168 | return; | 167 | return; |
169 | } | 168 | } |
170 | 169 | ||
171 | if ( button->type == ToggleButton ) | 170 | if ( button->type == ToggleButton ) |
172 | toggleButton( *button ); | 171 | toggleButton( *button ); |
173 | 172 | ||
174 | handleCommand( button->command, button->isDown ); | 173 | handleCommand( button->command, button->isDown ); |
175 | } | 174 | } |
176 | 175 | ||
177 | void MediaWidget::makeVisible() | 176 | void MediaWidget::makeVisible() |
178 | { | 177 | { |
179 | } | 178 | } |
180 | 179 | ||
181 | void MediaWidget::handleCommand( Command command, bool buttonDown ) | 180 | void MediaWidget::handleCommand( Command command, bool buttonDown ) |
182 | { | 181 | { |
183 | switch ( command ) { | 182 | switch ( command ) { |
184 | case Play: mediaPlayerState.togglePaused(); return; | 183 | case Play: mediaPlayerState.togglePaused(); return; |
185 | case Stop: mediaPlayerState.setPlaying(FALSE); return; | 184 | case Stop: mediaPlayerState.setPlaying(FALSE); return; |
186 | case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; | 185 | case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; |
187 | case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; | 186 | case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; |
188 | case Loop: mediaPlayerState.setLooping( buttonDown ); return; | 187 | case Loop: mediaPlayerState.setLooping( buttonDown ); return; |
189 | case VolumeUp: emit moreReleased(); return; | 188 | case VolumeUp: emit moreReleased(); return; |
190 | case VolumeDown: emit lessReleased(); return; | 189 | case VolumeDown: emit lessReleased(); return; |
191 | case PlayList: mediaPlayerState.setList(); return; | 190 | case PlayList: mediaPlayerState.setList(); return; |
192 | case Forward: emit forwardReleased(); return; | 191 | case Forward: emit forwardReleased(); return; |
193 | case Back: emit backReleased(); return; | 192 | case Back: emit backReleased(); return; |
194 | case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return; | 193 | case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return; |
195 | default: assert( false ); | 194 | default: assert( false ); |
196 | } | 195 | } |
197 | } | 196 | } |
198 | 197 | ||
199 | bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const | 198 | bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const |
200 | { | 199 | { |
201 | return ( position.x() > 0 && position.y() > 0 && | 200 | return ( position.x() > 0 && position.y() > 0 && |
202 | position.x() < buttonMask.width() && | 201 | position.x() < buttonMask.width() && |
203 | position.y() < buttonMask.height() && | 202 | position.y() < buttonMask.height() && |
204 | buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); | 203 | buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); |
205 | } | 204 | } |
206 | 205 | ||
207 | void MediaWidget::paintAllButtons( QPainter &p ) | 206 | void MediaWidget::paintAllButtons( QPainter &p ) |
208 | { | 207 | { |
209 | for ( ButtonVector::const_iterator it = buttons.begin(); | 208 | for ( ButtonVector::const_iterator it = buttons.begin(); |
210 | it != buttons.end(); ++it ) | 209 | it != buttons.end(); ++it ) |
211 | paintButton( p, *it ); | 210 | paintButton( p, *it ); |
212 | } | 211 | } |
213 | 212 | ||
214 | void MediaWidget::paintButton( const Button &button ) | 213 | void MediaWidget::paintButton( const Button &button ) |
215 | { | 214 | { |
216 | QPainter p( this ); | 215 | QPainter p( this ); |
217 | paintButton( p, button ); | 216 | paintButton( p, button ); |
218 | } | 217 | } |
219 | 218 | ||
220 | void MediaWidget::paintButton( QPainter &p, const Button &button ) | 219 | void MediaWidget::paintButton( QPainter &p, const Button &button ) |
221 | { | 220 | { |
222 | if ( button.isDown ) | 221 | if ( button.isDown ) |
223 | p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); | 222 | p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); |
224 | else | 223 | else |
225 | p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); | 224 | p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); |
226 | } | 225 | } |
227 | 226 | ||
228 | void MediaWidget::setToggleButton( Command command, bool down ) | 227 | void MediaWidget::setToggleButton( Command command, bool down ) |
229 | { | 228 | { |
230 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) | 229 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) |
231 | if ( it->command == command ) { | 230 | if ( it->command == command ) { |
232 | setToggleButton( *it, down ); | 231 | setToggleButton( *it, down ); |
233 | return; | 232 | return; |
234 | } | 233 | } |
235 | } | 234 | } |
236 | 235 | ||
237 | void MediaWidget::setToggleButton( Button &button, bool down ) | 236 | void MediaWidget::setToggleButton( Button &button, bool down ) |
238 | { | 237 | { |
239 | if ( down != button.isDown ) | 238 | if ( down != button.isDown ) |
240 | toggleButton( button ); | 239 | toggleButton( button ); |
241 | } | 240 | } |
242 | 241 | ||
243 | void MediaWidget::toggleButton( Button &button ) | 242 | void MediaWidget::toggleButton( Button &button ) |
244 | { | 243 | { |
245 | button.isDown = !button.isDown; | 244 | button.isDown = !button.isDown; |
246 | 245 | ||
247 | paintButton( button ); | 246 | paintButton( button ); |
248 | } | 247 | } |
249 | 248 | ||
250 | QPixmap MediaWidget::combineImageWithBackground( const QImage &image, const QPixmap &background, const QPoint &offset ) | 249 | QPixmap MediaWidget::combineImageWithBackground( const QImage &image, const QPixmap &background, const QPoint &offset ) |
251 | { | 250 | { |
252 | QPixmap pix( image.size() ); | 251 | QPixmap pix( image.size() ); |
253 | QPainter p( &pix ); | 252 | QPainter p( &pix ); |
254 | p.drawTiledPixmap( pix.rect(), background, offset ); | 253 | p.drawTiledPixmap( pix.rect(), background, offset ); |
255 | p.drawImage( 0, 0, image ); | 254 | p.drawImage( 0, 0, image ); |
256 | return pix; | 255 | return pix; |
257 | } | 256 | } |
258 | 257 | ||
259 | QPixmap MediaWidget::addMaskToPixmap( const QPixmap &pix, const QBitmap &mask ) | 258 | QPixmap MediaWidget::addMaskToPixmap( const QPixmap &pix, const QBitmap &mask ) |
260 | { | 259 | { |
261 | QPixmap result( pix ); | 260 | QPixmap result( pix ); |
262 | result.setMask( mask ); | 261 | result.setMask( mask ); |
263 | return result; | 262 | return result; |
264 | } | 263 | } |
265 | 264 | ||
266 | /* vim: et sw=4 ts=4 | 265 | /* vim: et sw=4 ts=4 |
267 | */ | 266 | */ |
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 64483d8..40eb0af 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h | |||
@@ -1,167 +1,167 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> | 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 library 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 Library 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 library 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 | Library 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 Library General Public License | 17 | You should have received a copy of the GNU General Public License |
18 | along with this library; see the file COPYING.LIB. 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 MEDIAWIDGET_H | 23 | #ifndef MEDIAWIDGET_H |
24 | #define MEDIAWIDGET_H | 24 | #define MEDIAWIDGET_H |
25 | 25 | ||
26 | #include <qwidget.h> | 26 | #include <qwidget.h> |
27 | #include <qmap.h> | 27 | #include <qmap.h> |
28 | 28 | ||
29 | #include "mediaplayerstate.h" | 29 | #include "mediaplayerstate.h" |
30 | #include "playlistwidget.h" | 30 | #include "playlistwidget.h" |
31 | 31 | ||
32 | #include <vector> | 32 | #include <vector> |
33 | #include <memory> | 33 | #include <memory> |
34 | 34 | ||
35 | namespace | 35 | namespace |
36 | { | 36 | { |
37 | struct simpleAndStupidAllocator | 37 | struct simpleAndStupidAllocator |
38 | { | 38 | { |
39 | static void *allocate( size_t amount ) | 39 | static void *allocate( size_t amount ) |
40 | { return ::operator new( amount ); } | 40 | { return ::operator new( amount ); } |
41 | static void deallocate( void *p, size_t ) | 41 | static void deallocate( void *p, size_t ) |
42 | { ::operator delete( p ); } | 42 | { ::operator delete( p ); } |
43 | }; | 43 | }; |
44 | } | 44 | } |
45 | 45 | ||
46 | class Skin; | 46 | class Skin; |
47 | 47 | ||
48 | class MediaWidget : public QWidget | 48 | class MediaWidget : public QWidget |
49 | { | 49 | { |
50 | Q_OBJECT | 50 | Q_OBJECT |
51 | public: | 51 | public: |
52 | enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back, FullScreen, Undefined }; | 52 | enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back, FullScreen, Undefined }; |
53 | enum ButtonType { NormalButton, ToggleButton }; | 53 | enum ButtonType { NormalButton, ToggleButton }; |
54 | 54 | ||
55 | struct Button | 55 | struct Button |
56 | { | 56 | { |
57 | Button() : command( Undefined ), type( NormalButton ), isDown( false ) {} | 57 | Button() : command( Undefined ), type( NormalButton ), isDown( false ) {} |
58 | 58 | ||
59 | Command command; | 59 | Command command; |
60 | 60 | ||
61 | ButtonType type; // this should be part of the bitfield but gcc2 is too buggy to support this :-( | 61 | ButtonType type; // this should be part of the bitfield but gcc2 is too buggy to support this :-( |
62 | bool isDown : 1; | 62 | bool isDown : 1; |
63 | 63 | ||
64 | QBitmap mask; | 64 | QBitmap mask; |
65 | QPixmap pixUp; | 65 | QPixmap pixUp; |
66 | QPixmap pixDown; | 66 | QPixmap pixDown; |
67 | }; | 67 | }; |
68 | #if defined( _CC_GNU_ ) | 68 | #if defined( _CC_GNU_ ) |
69 | // use that allocator to avoid the default allocator that on gcc2 requires libstdc++ because | 69 | // use that allocator to avoid the default allocator that on gcc2 requires libstdc++ because |
70 | // in the BAD_ALLOC macro it uses std::cerr and friends :-( | 70 | // in the BAD_ALLOC macro it uses std::cerr and friends :-( |
71 | typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector; | 71 | typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector; |
72 | #else | 72 | #else |
73 | typedef std::vector<Button> ButtonVector; | 73 | typedef std::vector<Button> ButtonVector; |
74 | #endif | 74 | #endif |
75 | 75 | ||
76 | struct SkinButtonInfo | 76 | struct SkinButtonInfo |
77 | { | 77 | { |
78 | Command command; | 78 | Command command; |
79 | const char *fileName; | 79 | const char *fileName; |
80 | ButtonType type; | 80 | ButtonType type; |
81 | }; | 81 | }; |
82 | 82 | ||
83 | struct GUIInfo | 83 | struct GUIInfo |
84 | { | 84 | { |
85 | GUIInfo() : buttonInfo( 0 ), buttonCount( 0 ) {} | 85 | GUIInfo() : buttonInfo( 0 ), buttonCount( 0 ) {} |
86 | GUIInfo( const QString &_fileNameInfix, const SkinButtonInfo *_buttonInfo, const uint _buttonCount ) | 86 | GUIInfo( const QString &_fileNameInfix, const SkinButtonInfo *_buttonInfo, const uint _buttonCount ) |
87 | : fileNameInfix( _fileNameInfix ), buttonInfo( _buttonInfo ), buttonCount( _buttonCount ) | 87 | : fileNameInfix( _fileNameInfix ), buttonInfo( _buttonInfo ), buttonCount( _buttonCount ) |
88 | {} | 88 | {} |
89 | 89 | ||
90 | QString fileNameInfix; | 90 | QString fileNameInfix; |
91 | const SkinButtonInfo *buttonInfo; | 91 | const SkinButtonInfo *buttonInfo; |
92 | const uint buttonCount; | 92 | const uint buttonCount; |
93 | }; | 93 | }; |
94 | 94 | ||
95 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); | 95 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); |
96 | virtual ~MediaWidget(); | 96 | virtual ~MediaWidget(); |
97 | 97 | ||
98 | public slots: | 98 | public slots: |
99 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; | 99 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; |
100 | virtual void setLength( long length ) = 0; | 100 | virtual void setLength( long length ) = 0; |
101 | virtual void setPlaying( bool playing ) = 0; | 101 | virtual void setPlaying( bool playing ) = 0; |
102 | 102 | ||
103 | virtual void loadSkin() = 0; | 103 | virtual void loadSkin() = 0; |
104 | 104 | ||
105 | signals: | 105 | signals: |
106 | void moreReleased(); | 106 | void moreReleased(); |
107 | void lessReleased(); | 107 | void lessReleased(); |
108 | void forwardReleased(); | 108 | void forwardReleased(); |
109 | void backReleased(); | 109 | void backReleased(); |
110 | void forwardClicked(); | 110 | void forwardClicked(); |
111 | void backClicked(); | 111 | void backClicked(); |
112 | void moreClicked(); | 112 | void moreClicked(); |
113 | void lessClicked(); | 113 | void lessClicked(); |
114 | 114 | ||
115 | protected: | 115 | protected: |
116 | void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, | 116 | void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, |
117 | const Skin &skin ); | 117 | const Skin &skin ); |
118 | Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ); | 118 | Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ); |
119 | 119 | ||
120 | void loadDefaultSkin( const GUIInfo &guiInfo ); | 120 | void loadDefaultSkin( const GUIInfo &guiInfo ); |
121 | void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ); | 121 | void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ); |
122 | 122 | ||
123 | virtual void closeEvent( QCloseEvent * ); | 123 | virtual void closeEvent( QCloseEvent * ); |
124 | 124 | ||
125 | virtual void paintEvent( QPaintEvent *pe ); | 125 | virtual void paintEvent( QPaintEvent *pe ); |
126 | 126 | ||
127 | virtual void resizeEvent( QResizeEvent *e ); | 127 | virtual void resizeEvent( QResizeEvent *e ); |
128 | 128 | ||
129 | Button *buttonAt( const QPoint &position ); | 129 | Button *buttonAt( const QPoint &position ); |
130 | 130 | ||
131 | virtual void mousePressEvent( QMouseEvent *event ); | 131 | virtual void mousePressEvent( QMouseEvent *event ); |
132 | virtual void mouseReleaseEvent( QMouseEvent *event ); | 132 | virtual void mouseReleaseEvent( QMouseEvent *event ); |
133 | 133 | ||
134 | virtual void makeVisible(); | 134 | virtual void makeVisible(); |
135 | 135 | ||
136 | void handleCommand( Command command, bool buttonDown ); | 136 | void handleCommand( Command command, bool buttonDown ); |
137 | 137 | ||
138 | bool isOverButton( const QPoint &position, int buttonId ) const; | 138 | bool isOverButton( const QPoint &position, int buttonId ) const; |
139 | 139 | ||
140 | void paintAllButtons( QPainter &p ); | 140 | void paintAllButtons( QPainter &p ); |
141 | void paintButton( const Button &button ); | 141 | void paintButton( const Button &button ); |
142 | void paintButton( QPainter &p, const Button &button ); | 142 | void paintButton( QPainter &p, const Button &button ); |
143 | 143 | ||
144 | void setToggleButton( Button &button, bool down ); | 144 | void setToggleButton( Button &button, bool down ); |
145 | void setToggleButton( Command command, bool down ); | 145 | void setToggleButton( Command command, bool down ); |
146 | void toggleButton( Button &button ); | 146 | void toggleButton( Button &button ); |
147 | 147 | ||
148 | MediaPlayerState &mediaPlayerState; | 148 | MediaPlayerState &mediaPlayerState; |
149 | PlayListWidget &playList; | 149 | PlayListWidget &playList; |
150 | 150 | ||
151 | ButtonVector buttons; | 151 | ButtonVector buttons; |
152 | 152 | ||
153 | QImage buttonMask; | 153 | QImage buttonMask; |
154 | 154 | ||
155 | QPoint upperLeftOfButtonMask; | 155 | QPoint upperLeftOfButtonMask; |
156 | 156 | ||
157 | QPixmap backgroundPixmap; | 157 | QPixmap backgroundPixmap; |
158 | QImage buttonUpImage; | 158 | QImage buttonUpImage; |
159 | QImage buttonDownImage; | 159 | QImage buttonDownImage; |
160 | 160 | ||
161 | static QPixmap combineImageWithBackground( const QImage &background, const QPixmap &pixmap, const QPoint &offset ); | 161 | static QPixmap combineImageWithBackground( const QImage &background, const QPixmap &pixmap, const QPoint &offset ); |
162 | static QPixmap addMaskToPixmap( const QPixmap &pix, const QBitmap &mask ); | 162 | static QPixmap addMaskToPixmap( const QPixmap &pix, const QBitmap &mask ); |
163 | }; | 163 | }; |
164 | 164 | ||
165 | #endif // MEDIAWIDGET_H | 165 | #endif // MEDIAWIDGET_H |
166 | /* vim: et sw=4 ts=4 | 166 | /* vim: et sw=4 ts=4 |
167 | */ | 167 | */ |
diff --git a/noncore/multimedia/opieplayer2/singleton.h b/noncore/multimedia/opieplayer2/singleton.h index 35b3dff..83e228f 100644 --- a/noncore/multimedia/opieplayer2/singleton.h +++ b/noncore/multimedia/opieplayer2/singleton.h | |||
@@ -1,49 +1,68 @@ | |||
1 | /* | ||
2 | Copyright (C) 2002 Simon Hausmann <simon@lst.de> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
1 | #ifndef SINGLETON_H | 20 | #ifndef SINGLETON_H |
2 | #define SINGLETON_H | 21 | #define SINGLETON_H |
3 | 22 | ||
4 | template <class Product> | 23 | template <class Product> |
5 | struct DefaultSingletonCreator | 24 | struct DefaultSingletonCreator |
6 | { | 25 | { |
7 | static Product *create() { return new Product; } | 26 | static Product *create() { return new Product; } |
8 | }; | 27 | }; |
9 | 28 | ||
10 | template <class Product> | 29 | template <class Product> |
11 | struct NullSingletonCreator | 30 | struct NullSingletonCreator |
12 | { | 31 | { |
13 | static Product *create() { return 0; } | 32 | static Product *create() { return 0; } |
14 | }; | 33 | }; |
15 | 34 | ||
16 | template | 35 | template |
17 | < | 36 | < |
18 | class T, | 37 | class T, |
19 | template <class> class Creator = DefaultSingletonCreator | 38 | template <class> class Creator = DefaultSingletonCreator |
20 | > | 39 | > |
21 | class Singleton | 40 | class Singleton |
22 | { | 41 | { |
23 | public: | 42 | public: |
24 | static T &self() | 43 | static T &self() |
25 | { | 44 | { |
26 | if ( !s_self ) | 45 | if ( !s_self ) |
27 | s_self = Creator<T>::create(); | 46 | s_self = Creator<T>::create(); |
28 | return *s_self; | 47 | return *s_self; |
29 | } | 48 | } |
30 | 49 | ||
31 | protected: | 50 | protected: |
32 | Singleton() | 51 | Singleton() |
33 | { s_self = static_cast<T *>( this ); } | 52 | { s_self = static_cast<T *>( this ); } |
34 | ~Singleton() | 53 | ~Singleton() |
35 | { s_self = 0; } | 54 | { s_self = 0; } |
36 | 55 | ||
37 | private: | 56 | private: |
38 | Singleton( const Singleton<T, Creator> &rhs ); | 57 | Singleton( const Singleton<T, Creator> &rhs ); |
39 | Singleton<T, Creator> &operator=( const Singleton<T, Creator> &rhs ); | 58 | Singleton<T, Creator> &operator=( const Singleton<T, Creator> &rhs ); |
40 | 59 | ||
41 | static T *s_self; | 60 | static T *s_self; |
42 | }; | 61 | }; |
43 | 62 | ||
44 | template <class T, template <class> class Creator> | 63 | template <class T, template <class> class Creator> |
45 | T *Singleton<T, Creator>::s_self = 0; | 64 | T *Singleton<T, Creator>::s_self = 0; |
46 | 65 | ||
47 | #endif // SINGLETON_H | 66 | #endif // SINGLETON_H |
48 | /* vim: et sw=4 ts=4 | 67 | /* vim: et sw=4 ts=4 |
49 | */ | 68 | */ |
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index 0de3023..cef3259 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp | |||
@@ -1,152 +1,173 @@ | |||
1 | /* | ||
2 | Copyright (C) 2002 Simon Hausmann <simon@lst.de> | ||
3 | (C) 2002 Max Reiss <harlekin@handhelds.org> | ||
4 | (C) 2002 L. Potter <ljp@llornkcor.com> | ||
5 | (C) 2002 Holger Freyther <zecke@handhelds.org> | ||
6 | |||
7 | This program is free software; you can redistribute it and/or | ||
8 | modify it under the terms of the GNU General Public | ||
9 | License as published by the Free Software Foundation; either | ||
10 | version 2 of the License, or (at your option) any later version. | ||
11 | |||
12 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | General Public License for more details. | ||
16 | |||
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 | ||
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
20 | Boston, MA 02111-1307, USA. | ||
21 | */ | ||
1 | 22 | ||
2 | #include "skin.h" | 23 | #include "skin.h" |
3 | 24 | ||
4 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
5 | #include <qpe/config.h> | 26 | #include <qpe/config.h> |
6 | 27 | ||
7 | #include <assert.h> | 28 | #include <assert.h> |
8 | 29 | ||
9 | Skin::Skin( const QString &name, const QString &fileNameInfix ) | 30 | Skin::Skin( const QString &name, const QString &fileNameInfix ) |
10 | : m_fileNameInfix( fileNameInfix ) | 31 | : m_fileNameInfix( fileNameInfix ) |
11 | { | 32 | { |
12 | init( name ); | 33 | init( name ); |
13 | } | 34 | } |
14 | 35 | ||
15 | Skin::Skin( const QString &fileNameInfix ) | 36 | Skin::Skin( const QString &fileNameInfix ) |
16 | : m_fileNameInfix( fileNameInfix ) | 37 | : m_fileNameInfix( fileNameInfix ) |
17 | { | 38 | { |
18 | init( defaultSkinName() ); | 39 | init( defaultSkinName() ); |
19 | } | 40 | } |
20 | 41 | ||
21 | void Skin::init( const QString &name ) | 42 | void Skin::init( const QString &name ) |
22 | { | 43 | { |
23 | m_skinPath = "opieplayer2/skins/" + name; | 44 | m_skinPath = "opieplayer2/skins/" + name; |
24 | } | 45 | } |
25 | 46 | ||
26 | void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) | 47 | void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) |
27 | { | 48 | { |
28 | backgroundImage(); | 49 | backgroundImage(); |
29 | buttonUpImage(); | 50 | buttonUpImage(); |
30 | buttonDownImage(); | 51 | buttonDownImage(); |
31 | ( void )buttonMask( skinButtonInfo, buttonCount ); | 52 | ( void )buttonMask( skinButtonInfo, buttonCount ); |
32 | } | 53 | } |
33 | 54 | ||
34 | QImage Skin::backgroundImage() const | 55 | QImage Skin::backgroundImage() const |
35 | { | 56 | { |
36 | if ( m_backgroundImage.isNull() ) | 57 | if ( m_backgroundImage.isNull() ) |
37 | m_backgroundImage = SkinCache::self().loadImage( QString( "%1/background" ).arg( m_skinPath ) ); | 58 | m_backgroundImage = SkinCache::self().loadImage( QString( "%1/background" ).arg( m_skinPath ) ); |
38 | return m_backgroundImage; | 59 | return m_backgroundImage; |
39 | } | 60 | } |
40 | 61 | ||
41 | QImage Skin::buttonUpImage() const | 62 | QImage Skin::buttonUpImage() const |
42 | { | 63 | { |
43 | if ( m_buttonUpImage.isNull() ) | 64 | if ( m_buttonUpImage.isNull() ) |
44 | m_buttonUpImage = SkinCache::self().loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); | 65 | m_buttonUpImage = SkinCache::self().loadImage( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); |
45 | return m_buttonUpImage; | 66 | return m_buttonUpImage; |
46 | } | 67 | } |
47 | 68 | ||
48 | QImage Skin::buttonDownImage() const | 69 | QImage Skin::buttonDownImage() const |
49 | { | 70 | { |
50 | if ( m_buttonDownImage.isNull() ) | 71 | if ( m_buttonDownImage.isNull() ) |
51 | m_buttonDownImage = SkinCache::self().loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); | 72 | m_buttonDownImage = SkinCache::self().loadImage( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ); |
52 | return m_buttonDownImage; | 73 | return m_buttonDownImage; |
53 | } | 74 | } |
54 | 75 | ||
55 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const | 76 | QImage Skin::buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const |
56 | { | 77 | { |
57 | if ( !m_buttonMask.isNull() ) | 78 | if ( !m_buttonMask.isNull() ) |
58 | return m_buttonMask; | 79 | return m_buttonMask; |
59 | 80 | ||
60 | QSize buttonAreaSize = buttonUpImage().size(); | 81 | QSize buttonAreaSize = buttonUpImage().size(); |
61 | 82 | ||
62 | m_buttonMask = QImage( buttonAreaSize, 8, 255 ); | 83 | m_buttonMask = QImage( buttonAreaSize, 8, 255 ); |
63 | m_buttonMask.fill( 0 ); | 84 | m_buttonMask.fill( 0 ); |
64 | 85 | ||
65 | for ( uint i = 0; i < buttonCount; ++i ) | 86 | for ( uint i = 0; i < buttonCount; ++i ) |
66 | addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) ); | 87 | addButtonToMask( skinButtonInfo[ i ].command + 1, buttonMaskImage( skinButtonInfo[ i ].fileName ) ); |
67 | 88 | ||
68 | return m_buttonMask; | 89 | return m_buttonMask; |
69 | } | 90 | } |
70 | 91 | ||
71 | void Skin::addButtonToMask( int tag, const QImage &maskImage ) const | 92 | void Skin::addButtonToMask( int tag, const QImage &maskImage ) const |
72 | { | 93 | { |
73 | if ( maskImage.isNull() ) | 94 | if ( maskImage.isNull() ) |
74 | return; | 95 | return; |
75 | 96 | ||
76 | uchar **dest = m_buttonMask.jumpTable(); | 97 | uchar **dest = m_buttonMask.jumpTable(); |
77 | for ( int y = 0; y < m_buttonMask.height(); y++ ) { | 98 | for ( int y = 0; y < m_buttonMask.height(); y++ ) { |
78 | uchar *line = dest[y]; | 99 | uchar *line = dest[y]; |
79 | for ( int x = 0; x < m_buttonMask.width(); x++ ) | 100 | for ( int x = 0; x < m_buttonMask.width(); x++ ) |
80 | if ( !qRed( maskImage.pixel( x, y ) ) ) | 101 | if ( !qRed( maskImage.pixel( x, y ) ) ) |
81 | line[x] = tag; | 102 | line[x] = tag; |
82 | } | 103 | } |
83 | } | 104 | } |
84 | 105 | ||
85 | QImage Skin::buttonMaskImage( const QString &fileName ) const | 106 | QImage Skin::buttonMaskImage( const QString &fileName ) const |
86 | { | 107 | { |
87 | ButtonMaskImageMap::Iterator it = m_buttonMasks.find( fileName ); | 108 | ButtonMaskImageMap::Iterator it = m_buttonMasks.find( fileName ); |
88 | if ( it == m_buttonMasks.end() ) { | 109 | if ( it == m_buttonMasks.end() ) { |
89 | QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); | 110 | QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); |
90 | QString path = prefix + fileName + ".png"; | 111 | QString path = prefix + fileName + ".png"; |
91 | it = m_buttonMasks.insert( fileName, SkinCache::self().loadImage( path ) ); | 112 | it = m_buttonMasks.insert( fileName, SkinCache::self().loadImage( path ) ); |
92 | } | 113 | } |
93 | return *it; | 114 | return *it; |
94 | } | 115 | } |
95 | 116 | ||
96 | QString Skin::defaultSkinName() | 117 | QString Skin::defaultSkinName() |
97 | { | 118 | { |
98 | Config cfg( "OpiePlayer" ); | 119 | Config cfg( "OpiePlayer" ); |
99 | cfg.setGroup( "Options" ); | 120 | cfg.setGroup( "Options" ); |
100 | return cfg.readEntry( "Skin", "default" ); | 121 | return cfg.readEntry( "Skin", "default" ); |
101 | } | 122 | } |
102 | 123 | ||
103 | SkinCache::SkinCache() | 124 | SkinCache::SkinCache() |
104 | { | 125 | { |
105 | m_cache.setAutoDelete( true ); | 126 | m_cache.setAutoDelete( true ); |
106 | } | 127 | } |
107 | 128 | ||
108 | QImage SkinCache::loadImage( const QString &name ) | 129 | QImage SkinCache::loadImage( const QString &name ) |
109 | { | 130 | { |
110 | ThreadUtil::AutoLock lock( m_cacheGuard ); | 131 | ThreadUtil::AutoLock lock( m_cacheGuard ); |
111 | 132 | ||
112 | QImage *image = m_cache.find( name ); | 133 | QImage *image = m_cache.find( name ); |
113 | if ( image ) { | 134 | if ( image ) { |
114 | qDebug( "cache hit for %s", name.ascii() ); | 135 | qDebug( "cache hit for %s", name.ascii() ); |
115 | return *image; | 136 | return *image; |
116 | } | 137 | } |
117 | 138 | ||
118 | image = new QImage( Resource::findPixmap( name ) ); | 139 | image = new QImage( Resource::findPixmap( name ) ); |
119 | m_cache.insert( name, image ); | 140 | m_cache.insert( name, image ); |
120 | return *image; | 141 | return *image; |
121 | } | 142 | } |
122 | 143 | ||
123 | SkinLoader::SkinLoader() | 144 | SkinLoader::SkinLoader() |
124 | { | 145 | { |
125 | } | 146 | } |
126 | 147 | ||
127 | void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, | 148 | void SkinLoader::schedule( const QString &skinName, const QString &fileNameInfix, |
128 | const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ) | 149 | const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ) |
129 | { | 150 | { |
130 | assert( isRunning() == false ); | 151 | assert( isRunning() == false ); |
131 | 152 | ||
132 | pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount ); | 153 | pendingSkins << Info( skinName, fileNameInfix, skinButtonInfo, buttonCount ); |
133 | } | 154 | } |
134 | 155 | ||
135 | void SkinLoader::run() | 156 | void SkinLoader::run() |
136 | { | 157 | { |
137 | qDebug( "SkinLoader::run()" ); | 158 | qDebug( "SkinLoader::run()" ); |
138 | for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it ) | 159 | for ( InfoList::ConstIterator it = pendingSkins.begin(); it != pendingSkins.end(); ++it ) |
139 | load( *it ); | 160 | load( *it ); |
140 | qDebug( "SkinLoader is done." ); | 161 | qDebug( "SkinLoader is done." ); |
141 | } | 162 | } |
142 | 163 | ||
143 | void SkinLoader::load( const Info &nfo ) | 164 | void SkinLoader::load( const Info &nfo ) |
144 | { | 165 | { |
145 | qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() ); | 166 | qDebug( "preloading %s with infix %s", nfo.skinName.ascii(), nfo.fileNameInfix.ascii() ); |
146 | 167 | ||
147 | Skin skin( nfo.skinName, nfo.fileNameInfix ); | 168 | Skin skin( nfo.skinName, nfo.fileNameInfix ); |
148 | skin.preload( nfo.skinButtonInfo, nfo.buttonCount ); | 169 | skin.preload( nfo.skinButtonInfo, nfo.buttonCount ); |
149 | } | 170 | } |
150 | 171 | ||
151 | /* vim: et sw=4 ts=4 | 172 | /* vim: et sw=4 ts=4 |
152 | */ | 173 | */ |
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h index c15d9dc..9f7326e 100644 --- a/noncore/multimedia/opieplayer2/skin.h +++ b/noncore/multimedia/opieplayer2/skin.h | |||
@@ -1,102 +1,124 @@ | |||
1 | /* | ||
2 | Copyright (C) 2002 Simon Hausmann <simon@lst.de> | ||
3 | (C) 2002 Max Reiss <harlekin@handhelds.org> | ||
4 | (C) 2002 L. Potter <ljp@llornkcor.com> | ||
5 | (C) 2002 Holger Freyther <zecke@handhelds.org> | ||
6 | |||
7 | This program is free software; you can redistribute it and/or | ||
8 | modify it under the terms of the GNU General Public | ||
9 | License as published by the Free Software Foundation; either | ||
10 | version 2 of the License, or (at your option) any later version. | ||
11 | |||
12 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | General Public License for more details. | ||
16 | |||
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 | ||
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
20 | Boston, MA 02111-1307, USA. | ||
21 | */ | ||
22 | |||
1 | #ifndef SKIN_H | 23 | #ifndef SKIN_H |
2 | #define SKIN_H | 24 | #define SKIN_H |
3 | 25 | ||
4 | #include <qstring.h> | 26 | #include <qstring.h> |
5 | #include <qimage.h> | 27 | #include <qimage.h> |
6 | #include <qmap.h> | 28 | #include <qmap.h> |
7 | #include <qdict.h> | 29 | #include <qdict.h> |
8 | 30 | ||
9 | #include "mediawidget.h" | 31 | #include "mediawidget.h" |
10 | #include "threadutil.h" | 32 | #include "threadutil.h" |
11 | #include "singleton.h" | 33 | #include "singleton.h" |
12 | 34 | ||
13 | class Skin | 35 | class Skin |
14 | { | 36 | { |
15 | public: | 37 | public: |
16 | Skin( const QString &name, const QString &fileNameInfix ); | 38 | Skin( const QString &name, const QString &fileNameInfix ); |
17 | Skin( const QString &fileNameInfix ); | 39 | Skin( const QString &fileNameInfix ); |
18 | 40 | ||
19 | void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); | 41 | void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); |
20 | 42 | ||
21 | QImage backgroundImage() const; | 43 | QImage backgroundImage() const; |
22 | QImage buttonUpImage() const; | 44 | QImage buttonUpImage() const; |
23 | QImage buttonDownImage() const; | 45 | QImage buttonDownImage() const; |
24 | 46 | ||
25 | QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; | 47 | QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; |
26 | 48 | ||
27 | QImage buttonMaskImage( const QString &fileName ) const; | 49 | QImage buttonMaskImage( const QString &fileName ) const; |
28 | 50 | ||
29 | static QString defaultSkinName(); | 51 | static QString defaultSkinName(); |
30 | 52 | ||
31 | private: | 53 | private: |
32 | void init( const QString &name ); | 54 | void init( const QString &name ); |
33 | 55 | ||
34 | void addButtonToMask( int tag, const QImage &maskImage ) const; | 56 | void addButtonToMask( int tag, const QImage &maskImage ) const; |
35 | 57 | ||
36 | QString m_fileNameInfix; | 58 | QString m_fileNameInfix; |
37 | QString m_skinPath; | 59 | QString m_skinPath; |
38 | 60 | ||
39 | typedef QMap<QString, QImage> ButtonMaskImageMap; | 61 | typedef QMap<QString, QImage> ButtonMaskImageMap; |
40 | 62 | ||
41 | mutable QImage m_backgroundImage; | 63 | mutable QImage m_backgroundImage; |
42 | mutable QImage m_buttonUpImage; | 64 | mutable QImage m_buttonUpImage; |
43 | mutable QImage m_buttonDownImage; | 65 | mutable QImage m_buttonDownImage; |
44 | mutable QImage m_buttonMask; | 66 | mutable QImage m_buttonMask; |
45 | mutable ButtonMaskImageMap m_buttonMasks; | 67 | mutable ButtonMaskImageMap m_buttonMasks; |
46 | 68 | ||
47 | Skin( const Skin & ); | 69 | Skin( const Skin & ); |
48 | Skin &operator=( const Skin & ); | 70 | Skin &operator=( const Skin & ); |
49 | }; | 71 | }; |
50 | 72 | ||
51 | class SkinCache : public Singleton<SkinCache> | 73 | class SkinCache : public Singleton<SkinCache> |
52 | { | 74 | { |
53 | public: | 75 | public: |
54 | SkinCache(); | 76 | SkinCache(); |
55 | 77 | ||
56 | QImage loadImage( const QString &name ); | 78 | QImage loadImage( const QString &name ); |
57 | 79 | ||
58 | private: | 80 | private: |
59 | typedef QDict<QImage> ImageCache; | 81 | typedef QDict<QImage> ImageCache; |
60 | 82 | ||
61 | ImageCache m_cache; | 83 | ImageCache m_cache; |
62 | 84 | ||
63 | ThreadUtil::Mutex m_cacheGuard; | 85 | ThreadUtil::Mutex m_cacheGuard; |
64 | }; | 86 | }; |
65 | 87 | ||
66 | class SkinLoader : public ThreadUtil::Thread | 88 | class SkinLoader : public ThreadUtil::Thread |
67 | { | 89 | { |
68 | public: | 90 | public: |
69 | SkinLoader(); | 91 | SkinLoader(); |
70 | 92 | ||
71 | void schedule( const QString &skinName, const QString &fileNameInfix, | 93 | void schedule( const QString &skinName, const QString &fileNameInfix, |
72 | const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ); | 94 | const MediaWidget::SkinButtonInfo *skinButtonInfo, const uint buttonCount ); |
73 | 95 | ||
74 | protected: | 96 | protected: |
75 | virtual void run(); | 97 | virtual void run(); |
76 | 98 | ||
77 | private: | 99 | private: |
78 | struct Info | 100 | struct Info |
79 | { | 101 | { |
80 | Info() : skinButtonInfo( 0 ), buttonCount( 0 ) {} | 102 | Info() : skinButtonInfo( 0 ), buttonCount( 0 ) {} |
81 | Info( const QString &_skinName, const QString &_fileNameInfix, | 103 | Info( const QString &_skinName, const QString &_fileNameInfix, |
82 | const MediaWidget::SkinButtonInfo *_skinButtonInfo, const uint _buttonCount ) | 104 | const MediaWidget::SkinButtonInfo *_skinButtonInfo, const uint _buttonCount ) |
83 | : skinName( _skinName ), fileNameInfix( _fileNameInfix ), | 105 | : skinName( _skinName ), fileNameInfix( _fileNameInfix ), |
84 | skinButtonInfo( _skinButtonInfo ), buttonCount( _buttonCount ) | 106 | skinButtonInfo( _skinButtonInfo ), buttonCount( _buttonCount ) |
85 | {} | 107 | {} |
86 | 108 | ||
87 | const QString skinName; | 109 | const QString skinName; |
88 | const QString fileNameInfix; | 110 | const QString fileNameInfix; |
89 | const MediaWidget::SkinButtonInfo *skinButtonInfo; | 111 | const MediaWidget::SkinButtonInfo *skinButtonInfo; |
90 | const uint buttonCount; | 112 | const uint buttonCount; |
91 | }; | 113 | }; |
92 | typedef QValueList<Info> InfoList; | 114 | typedef QValueList<Info> InfoList; |
93 | 115 | ||
94 | void load( const Info &nfo ); | 116 | void load( const Info &nfo ); |
95 | 117 | ||
96 | InfoList pendingSkins; | 118 | InfoList pendingSkins; |
97 | ThreadUtil::Mutex guard; | 119 | ThreadUtil::Mutex guard; |
98 | }; | 120 | }; |
99 | 121 | ||
100 | #endif // SKIN_H | 122 | #endif // SKIN_H |
101 | /* vim: et sw=4 ts=4 | 123 | /* vim: et sw=4 ts=4 |
102 | */ | 124 | */ |