author | simon <simon> | 2002-12-14 18:00:50 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-14 18:00:50 (UTC) |
commit | d73e34645e839c1aea21bd62e622788361cf866d (patch) (unidiff) | |
tree | 8f290403aa5ddae5b07ce53e5e551112848998bf | |
parent | 309c34a61e7cf6a199275c32c00ec1eaaa511d9b (diff) | |
download | opie-d73e34645e839c1aea21bd62e622788361cf866d.zip opie-d73e34645e839c1aea21bd62e622788361cf866d.tar.gz opie-d73e34645e839c1aea21bd62e622788361cf866d.tar.bz2 |
- oops, forgot this one
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index f7a22a3..edef2a7 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp | |||
@@ -1,260 +1,260 @@ | |||
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 "mediawidget.h" | 23 | #include "mediawidget.h" |
24 | #include "playlistwidget.h" | 24 | #include "playlistwidget.h" |
25 | #include "skin.h" | 25 | #include "skin.h" |
26 | 26 | ||
27 | MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) | 27 | MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) |
28 | : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) | 28 | : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) |
29 | { | 29 | { |
30 | connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), | 30 | connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), |
31 | this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); | 31 | this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); |
32 | connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), | 32 | connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), |
33 | this, SLOT( setLength( long ) ) ); | 33 | this, SLOT( setLength( long ) ) ); |
34 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), | 34 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), |
35 | this, SLOT( setPlaying( bool ) ) ); | 35 | this, SLOT( setPlaying( bool ) ) ); |
36 | 36 | ||
37 | setBackgroundMode( NoBackground ); | 37 | setBackgroundMode( NoBackground ); |
38 | } | 38 | } |
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 | loadSkin( guiInfo.buttonInfo, guiInfo.buttonCount, skin ); | 71 | loadSkin( guiInfo.buttonInfo, guiInfo.buttonCount, skin ); |
72 | } | 72 | } |
73 | 73 | ||
74 | void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ) | 74 | void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ) |
75 | { | 75 | { |
76 | backgroundPixmap = skin.backgroundImage(); | 76 | backgroundPixmap = skin.backgroundPixmap(); |
77 | buttonUpImage = skin.buttonUpImage(); | 77 | buttonUpImage = skin.buttonUpImage(); |
78 | buttonDownImage = skin.buttonDownImage(); | 78 | buttonDownImage = skin.buttonDownImage(); |
79 | 79 | ||
80 | setupButtons( skinInfo, buttonCount, skin ); | 80 | setupButtons( skinInfo, buttonCount, skin ); |
81 | } | 81 | } |
82 | 82 | ||
83 | void MediaWidget::closeEvent( QCloseEvent * ) | 83 | void MediaWidget::closeEvent( QCloseEvent * ) |
84 | { | 84 | { |
85 | mediaPlayerState.setList(); | 85 | mediaPlayerState.setList(); |
86 | } | 86 | } |
87 | 87 | ||
88 | void MediaWidget::paintEvent( QPaintEvent *pe ) | 88 | void MediaWidget::paintEvent( QPaintEvent *pe ) |
89 | { | 89 | { |
90 | QPainter p( this ); | 90 | QPainter p( this ); |
91 | 91 | ||
92 | if ( mediaPlayerState.isFullscreen() ) { | 92 | if ( mediaPlayerState.isFullscreen() ) { |
93 | // Clear the background | 93 | // Clear the background |
94 | p.setBrush( QBrush( Qt::black ) ); | 94 | p.setBrush( QBrush( Qt::black ) ); |
95 | return; | 95 | return; |
96 | } | 96 | } |
97 | 97 | ||
98 | QPixmap buffer( size() ); | 98 | QPixmap buffer( size() ); |
99 | QPainter bufferedPainter( &buffer ); | 99 | QPainter bufferedPainter( &buffer ); |
100 | bufferedPainter.drawTiledPixmap( rect(), backgroundPixmap, QPoint( 0, 0 ) ); | 100 | bufferedPainter.drawTiledPixmap( rect(), backgroundPixmap, QPoint( 0, 0 ) ); |
101 | paintAllButtons( bufferedPainter ); | 101 | paintAllButtons( bufferedPainter ); |
102 | p.drawPixmap( 0, 0, buffer ); | 102 | p.drawPixmap( 0, 0, buffer ); |
103 | } | 103 | } |
104 | 104 | ||
105 | void MediaWidget::resizeEvent( QResizeEvent *e ) | 105 | void MediaWidget::resizeEvent( QResizeEvent *e ) |
106 | { | 106 | { |
107 | QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, upperLeftOfButtonMask ); | 107 | QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, upperLeftOfButtonMask ); |
108 | QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, upperLeftOfButtonMask ); | 108 | QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, upperLeftOfButtonMask ); |
109 | 109 | ||
110 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) { | 110 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) { |
111 | Button &button = *it; | 111 | Button &button = *it; |
112 | 112 | ||
113 | if ( button.mask.isNull() ) | 113 | if ( button.mask.isNull() ) |
114 | continue; | 114 | continue; |
115 | button.pixUp = addMaskToPixmap( pixUp, button.mask ); | 115 | button.pixUp = addMaskToPixmap( pixUp, button.mask ); |
116 | button.pixDown = addMaskToPixmap( pixDn, button.mask ); | 116 | button.pixDown = addMaskToPixmap( pixDn, button.mask ); |
117 | } | 117 | } |
118 | 118 | ||
119 | QWidget::resizeEvent( e ); | 119 | QWidget::resizeEvent( e ); |
120 | } | 120 | } |
121 | 121 | ||
122 | MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) | 122 | MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) |
123 | { | 123 | { |
124 | if ( position.x() <= 0 || position.y() <= 0 || | 124 | if ( position.x() <= 0 || position.y() <= 0 || |
125 | position.x() >= buttonMask.width() || | 125 | position.x() >= buttonMask.width() || |
126 | position.y() >= buttonMask.height() ) | 126 | position.y() >= buttonMask.height() ) |
127 | return 0; | 127 | return 0; |
128 | 128 | ||
129 | int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); | 129 | int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); |
130 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) | 130 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) |
131 | if ( it->command + 1 == pixelIdx ) | 131 | if ( it->command + 1 == pixelIdx ) |
132 | return &( *it ); | 132 | return &( *it ); |
133 | 133 | ||
134 | return 0; | 134 | return 0; |
135 | } | 135 | } |
136 | 136 | ||
137 | void MediaWidget::mousePressEvent( QMouseEvent *event ) | 137 | void MediaWidget::mousePressEvent( QMouseEvent *event ) |
138 | { | 138 | { |
139 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); | 139 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); |
140 | 140 | ||
141 | if ( !button ) { | 141 | if ( !button ) { |
142 | QWidget::mousePressEvent( event ); | 142 | QWidget::mousePressEvent( event ); |
143 | return; | 143 | return; |
144 | } | 144 | } |
145 | 145 | ||
146 | switch ( button->command ) { | 146 | switch ( button->command ) { |
147 | case VolumeUp: emit moreClicked(); return; | 147 | case VolumeUp: emit moreClicked(); return; |
148 | case VolumeDown: emit lessClicked(); return; | 148 | case VolumeDown: emit lessClicked(); return; |
149 | case Back: emit backClicked(); return; | 149 | case Back: emit backClicked(); return; |
150 | case Forward: emit forwardClicked(); return; | 150 | case Forward: emit forwardClicked(); return; |
151 | default: break; | 151 | default: break; |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) | 155 | void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) |
156 | { | 156 | { |
157 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); | 157 | Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); |
158 | 158 | ||
159 | if ( !button ) { | 159 | if ( !button ) { |
160 | QWidget::mouseReleaseEvent( event ); | 160 | QWidget::mouseReleaseEvent( event ); |
161 | return; | 161 | return; |
162 | } | 162 | } |
163 | 163 | ||
164 | if ( button->type == ToggleButton ) | 164 | if ( button->type == ToggleButton ) |
165 | toggleButton( *button ); | 165 | toggleButton( *button ); |
166 | 166 | ||
167 | handleCommand( button->command, button->isDown ); | 167 | handleCommand( button->command, button->isDown ); |
168 | } | 168 | } |
169 | 169 | ||
170 | void MediaWidget::makeVisible() | 170 | void MediaWidget::makeVisible() |
171 | { | 171 | { |
172 | } | 172 | } |
173 | 173 | ||
174 | void MediaWidget::handleCommand( Command command, bool buttonDown ) | 174 | void MediaWidget::handleCommand( Command command, bool buttonDown ) |
175 | { | 175 | { |
176 | switch ( command ) { | 176 | switch ( command ) { |
177 | case Play: mediaPlayerState.togglePaused(); return; | 177 | case Play: mediaPlayerState.togglePaused(); return; |
178 | case Stop: mediaPlayerState.setPlaying(FALSE); return; | 178 | case Stop: mediaPlayerState.setPlaying(FALSE); return; |
179 | case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; | 179 | case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; |
180 | case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; | 180 | case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; |
181 | case Loop: mediaPlayerState.setLooping( buttonDown ); return; | 181 | case Loop: mediaPlayerState.setLooping( buttonDown ); return; |
182 | case VolumeUp: emit moreReleased(); return; | 182 | case VolumeUp: emit moreReleased(); return; |
183 | case VolumeDown: emit lessReleased(); return; | 183 | case VolumeDown: emit lessReleased(); return; |
184 | case PlayList: mediaPlayerState.setList(); return; | 184 | case PlayList: mediaPlayerState.setList(); return; |
185 | case Forward: emit forwardReleased(); return; | 185 | case Forward: emit forwardReleased(); return; |
186 | case Back: emit backReleased(); return; | 186 | case Back: emit backReleased(); return; |
187 | case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return; | 187 | case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return; |
188 | default: assert( false ); | 188 | default: assert( false ); |
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const | 192 | bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const |
193 | { | 193 | { |
194 | return ( position.x() > 0 && position.y() > 0 && | 194 | return ( position.x() > 0 && position.y() > 0 && |
195 | position.x() < buttonMask.width() && | 195 | position.x() < buttonMask.width() && |
196 | position.y() < buttonMask.height() && | 196 | position.y() < buttonMask.height() && |
197 | buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); | 197 | buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); |
198 | } | 198 | } |
199 | 199 | ||
200 | void MediaWidget::paintAllButtons( QPainter &p ) | 200 | void MediaWidget::paintAllButtons( QPainter &p ) |
201 | { | 201 | { |
202 | for ( ButtonVector::const_iterator it = buttons.begin(); | 202 | for ( ButtonVector::const_iterator it = buttons.begin(); |
203 | it != buttons.end(); ++it ) | 203 | it != buttons.end(); ++it ) |
204 | paintButton( p, *it ); | 204 | paintButton( p, *it ); |
205 | } | 205 | } |
206 | 206 | ||
207 | void MediaWidget::paintButton( const Button &button ) | 207 | void MediaWidget::paintButton( const Button &button ) |
208 | { | 208 | { |
209 | QPainter p( this ); | 209 | QPainter p( this ); |
210 | paintButton( p, button ); | 210 | paintButton( p, button ); |
211 | } | 211 | } |
212 | 212 | ||
213 | void MediaWidget::paintButton( QPainter &p, const Button &button ) | 213 | void MediaWidget::paintButton( QPainter &p, const Button &button ) |
214 | { | 214 | { |
215 | if ( button.isDown ) | 215 | if ( button.isDown ) |
216 | p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); | 216 | p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); |
217 | else | 217 | else |
218 | p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); | 218 | p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); |
219 | } | 219 | } |
220 | 220 | ||
221 | void MediaWidget::setToggleButton( Command command, bool down ) | 221 | void MediaWidget::setToggleButton( Command command, bool down ) |
222 | { | 222 | { |
223 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) | 223 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) |
224 | if ( it->command == command ) { | 224 | if ( it->command == command ) { |
225 | setToggleButton( *it, down ); | 225 | setToggleButton( *it, down ); |
226 | return; | 226 | return; |
227 | } | 227 | } |
228 | } | 228 | } |
229 | 229 | ||
230 | void MediaWidget::setToggleButton( Button &button, bool down ) | 230 | void MediaWidget::setToggleButton( Button &button, bool down ) |
231 | { | 231 | { |
232 | if ( down != button.isDown ) | 232 | if ( down != button.isDown ) |
233 | toggleButton( button ); | 233 | toggleButton( button ); |
234 | } | 234 | } |
235 | 235 | ||
236 | void MediaWidget::toggleButton( Button &button ) | 236 | void MediaWidget::toggleButton( Button &button ) |
237 | { | 237 | { |
238 | button.isDown = !button.isDown; | 238 | button.isDown = !button.isDown; |
239 | 239 | ||
240 | paintButton( button ); | 240 | paintButton( button ); |
241 | } | 241 | } |
242 | 242 | ||
243 | QPixmap MediaWidget::combineImageWithBackground( const QImage &image, const QPixmap &background, const QPoint &offset ) | 243 | QPixmap MediaWidget::combineImageWithBackground( const QImage &image, const QPixmap &background, const QPoint &offset ) |
244 | { | 244 | { |
245 | QPixmap pix( image.size() ); | 245 | QPixmap pix( image.size() ); |
246 | QPainter p( &pix ); | 246 | QPainter p( &pix ); |
247 | p.drawTiledPixmap( pix.rect(), background, offset ); | 247 | p.drawTiledPixmap( pix.rect(), background, offset ); |
248 | p.drawImage( 0, 0, image ); | 248 | p.drawImage( 0, 0, image ); |
249 | return pix; | 249 | return pix; |
250 | } | 250 | } |
251 | 251 | ||
252 | QPixmap MediaWidget::addMaskToPixmap( const QPixmap &pix, const QBitmap &mask ) | 252 | QPixmap MediaWidget::addMaskToPixmap( const QPixmap &pix, const QBitmap &mask ) |
253 | { | 253 | { |
254 | QPixmap result( pix ); | 254 | QPixmap result( pix ); |
255 | result.setMask( mask ); | 255 | result.setMask( mask ); |
256 | return result; | 256 | return result; |
257 | } | 257 | } |
258 | 258 | ||
259 | /* vim: et sw=4 ts=4 | 259 | /* vim: et sw=4 ts=4 |
260 | */ | 260 | */ |