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