summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-11 13:46:15 (UTC)
committer simon <simon>2002-12-11 13:46:15 (UTC)
commit2b3c450378c1da0a2175c91d652ce2eae5614ff8 (patch) (unidiff)
tree4c11c70dbf487725f6e443f5db4c5a0a0c964e61
parentcd5e96b40ceae9158e5cb01e71769e895ea7a3c1 (diff)
downloadopie-2b3c450378c1da0a2175c91d652ce2eae5614ff8.zip
opie-2b3c450378c1da0a2175c91d652ce2eae5614ff8.tar.gz
opie-2b3c450378c1da0a2175c91d652ce2eae5614ff8.tar.bz2
- less code duplication. code from resizeEvent is now shared as well as
the image composing method and the pixmap mask helper
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp13
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp33
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.h5
-rw-r--r--noncore/multimedia/opieplayer2/videowidget.cpp32
4 files changed, 42 insertions, 41 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index bb686f1..bb07882 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -1,363 +1,354 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> 4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU General Public 12:`=1 )Y*s>-.--   : the terms of the GNU General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <opie/oticker.h> 37#include <opie/oticker.h>
38 38
39#include <qwidget.h> 39#include <qwidget.h>
40#include <qpixmap.h> 40#include <qpixmap.h>
41#include <qbutton.h> 41#include <qbutton.h>
42#include <qpainter.h> 42#include <qpainter.h>
43#include <qframe.h> 43#include <qframe.h>
44#include <qlayout.h> 44#include <qlayout.h>
45#include <qdir.h> 45#include <qdir.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <stdio.h> 47#include <stdio.h>
48 48
49#include "audiowidget.h" 49#include "audiowidget.h"
50#include "mediaplayerstate.h" 50#include "mediaplayerstate.h"
51#include "playlistwidget.h" 51#include "playlistwidget.h"
52 52
53namespace 53namespace
54{ 54{
55 55
56const int xo = -2; // movable x offset 56const int xo = -2; // movable x offset
57const int yo = 22; // movable y offset 57const int yo = 22; // movable y offset
58 58
59const MediaWidget::SkinButtonInfo skinInfo[] = 59const MediaWidget::SkinButtonInfo skinInfo[] =
60{ 60{
61 { MediaWidget::Play, "play", MediaWidget::ToggleButton }, 61 { MediaWidget::Play, "play", MediaWidget::ToggleButton },
62 { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, 62 { MediaWidget::Stop, "stop", MediaWidget::NormalButton },
63 { MediaWidget::Next, "next", MediaWidget::NormalButton }, 63 { MediaWidget::Next, "next", MediaWidget::NormalButton },
64 { MediaWidget::Previous, "prev", MediaWidget::NormalButton }, 64 { MediaWidget::Previous, "prev", MediaWidget::NormalButton },
65 { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, 65 { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton },
66 { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, 66 { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton },
67 { MediaWidget::Loop, "loop", MediaWidget::ToggleButton }, 67 { MediaWidget::Loop, "loop", MediaWidget::ToggleButton },
68 { MediaWidget::PlayList, "playlist", MediaWidget::NormalButton }, 68 { MediaWidget::PlayList, "playlist", MediaWidget::NormalButton },
69 { MediaWidget::Forward, "forward", MediaWidget::NormalButton }, 69 { MediaWidget::Forward, "forward", MediaWidget::NormalButton },
70 { MediaWidget::Back, "back", MediaWidget::NormalButton } 70 { MediaWidget::Back, "back", MediaWidget::NormalButton }
71}; 71};
72 72
73const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); 73const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] );
74 74
75void changeTextColor( QWidget * w) { 75void changeTextColor( QWidget * w) {
76 QPalette p = w->palette(); 76 QPalette p = w->palette();
77 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); 77 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) );
78 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); 78 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) );
79 w->setPalette( p ); 79 w->setPalette( p );
80} 80}
81 81
82} 82}
83 83
84AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : 84AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) :
85 85
86 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ), 86 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ),
87 audioSliderBeingMoved( false ) 87 audioSliderBeingMoved( false )
88{ 88{
89 setCaption( tr("OpiePlayer") ); 89 setCaption( tr("OpiePlayer") );
90 90
91 loadSkin(); 91 loadSkin();
92 92
93 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 93 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
94 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); 94 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) );
95 95
96 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); 96 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) );
97 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); 97 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) );
98 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); 98 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) );
99 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); 99 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) );
100 100
101 // Intialise state 101 // Intialise state
102 setLength( mediaPlayerState.length() ); 102 setLength( mediaPlayerState.length() );
103 setPosition( mediaPlayerState.position() ); 103 setPosition( mediaPlayerState.position() );
104 setLooping( mediaPlayerState.isFullscreen() ); 104 setLooping( mediaPlayerState.isFullscreen() );
105 // setPaused( mediaPlayerState->paused() ); 105 // setPaused( mediaPlayerState->paused() );
106 setPlaying( mediaPlayerState.isPlaying() ); 106 setPlaying( mediaPlayerState.isPlaying() );
107} 107}
108 108
109AudioWidget::~AudioWidget() { 109AudioWidget::~AudioWidget() {
110 110
111// mediaPlayerState->setPlaying(false); 111// mediaPlayerState->setPlaying(false);
112} 112}
113 113
114namespace { 114namespace {
115 115
116QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 116QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
117 QPixmap pix( img.width(), img.height() ); 117 QPixmap pix( img.width(), img.height() );
118 QPainter p( &pix ); 118 QPainter p( &pix );
119 p.drawTiledPixmap( pix.rect(), bg, offset ); 119 p.drawTiledPixmap( pix.rect(), bg, offset );
120 p.drawImage( 0, 0, img ); 120 p.drawImage( 0, 0, img );
121 return pix; 121 return pix;
122} 122}
123 123
124 124
125QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) { 125QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) {
126 QPixmap pixmap( pix ); 126 QPixmap pixmap( pix );
127 pixmap.setMask( mask ); 127 pixmap.setMask( mask );
128 return pixmap; 128 return pixmap;
129} 129}
130 130
131}; 131};
132 132
133void AudioWidget::resizeEvent( QResizeEvent * ) { 133void AudioWidget::resizeEvent( QResizeEvent *e ) {
134 int h = height(); 134 int h = height();
135 int w = width(); 135 int w = width();
136 136
137 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); 137 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) );
138 slider.setFixedWidth( w - 110 ); 138 slider.setFixedWidth( w - 110 );
139 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); 139 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) );
140 slider.setBackgroundOrigin( QWidget::ParentOrigin ); 140 slider.setBackgroundOrigin( QWidget::ParentOrigin );
141 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); 141 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) );
142 142
143 upperLeftOfButtonMask.rx() = ( w - buttonUpImage.width() ) / 2; 143 upperLeftOfButtonMask.rx() = ( w - buttonUpImage.width() ) / 2;
144 upperLeftOfButtonMask.ry() = (( h - buttonUpImage.height() ) / 2) - 10; 144 upperLeftOfButtonMask.ry() = (( h - buttonUpImage.height() ) / 2) - 10;
145 QPoint p = upperLeftOfButtonMask;
146 145
147 QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, p ); 146 MediaWidget::resizeEvent( e );
148 QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, p );
149
150 for ( uint i = 0; i < buttons.size(); i++ ) {
151 if ( !buttons[i].mask.isNull() ) {
152 buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask );
153 buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask );
154 }
155 }
156} 147}
157 148
158void AudioWidget::sliderPressed() { 149void AudioWidget::sliderPressed() {
159 audioSliderBeingMoved = TRUE; 150 audioSliderBeingMoved = TRUE;
160} 151}
161 152
162 153
163void AudioWidget::sliderReleased() { 154void AudioWidget::sliderReleased() {
164 audioSliderBeingMoved = FALSE; 155 audioSliderBeingMoved = FALSE;
165 if ( slider.width() == 0 ) 156 if ( slider.width() == 0 )
166 return; 157 return;
167 long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); 158 long val = long((double)slider.value() * mediaPlayerState.length() / slider.width());
168 mediaPlayerState.setPosition( val ); 159 mediaPlayerState.setPosition( val );
169} 160}
170 161
171void AudioWidget::setPosition( long i ) { 162void AudioWidget::setPosition( long i ) {
172 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); 163 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i);
173 updateSlider( i, mediaPlayerState.length() ); 164 updateSlider( i, mediaPlayerState.length() );
174} 165}
175 166
176 167
177void AudioWidget::setLength( long max ) { 168void AudioWidget::setLength( long max ) {
178 updateSlider( mediaPlayerState.position(), max ); 169 updateSlider( mediaPlayerState.position(), max );
179} 170}
180 171
181 172
182void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { 173void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) {
183 if ( mediaType == MediaPlayerState::Audio ) { 174 if ( mediaType == MediaPlayerState::Audio ) {
184 // startTimer( 150 ); 175 // startTimer( 150 );
185 showMaximized(); 176 showMaximized();
186 return; 177 return;
187 } 178 }
188 179
189 killTimers(); 180 killTimers();
190 hide(); 181 hide();
191} 182}
192 183
193void AudioWidget::loadSkin() 184void AudioWidget::loadSkin()
194{ 185{
195 loadDefaultSkin( skinInfo, buttonCount ); 186 loadDefaultSkin( skinInfo, buttonCount );
196 187
197 setBackgroundPixmap( backgroundPixmap ); 188 setBackgroundPixmap( backgroundPixmap );
198 189
199 songInfo.setFocusPolicy( QWidget::NoFocus ); 190 songInfo.setFocusPolicy( QWidget::NoFocus );
200// changeTextColor( &songInfo ); 191// changeTextColor( &songInfo );
201// songInfo.setBackgroundColor( QColor( 167, 212, 167 )); 192// songInfo.setBackgroundColor( QColor( 167, 212, 167 ));
202// songInfo.setFrameStyle( QFrame::NoFrame); 193// songInfo.setFrameStyle( QFrame::NoFrame);
203 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 194 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
204// songInfo.setForegroundColor(Qt::white); 195// songInfo.setForegroundColor(Qt::white);
205 196
206 slider.setFixedHeight( 20 ); 197 slider.setFixedHeight( 20 );
207 slider.setMinValue( 0 ); 198 slider.setMinValue( 0 );
208 slider.setMaxValue( 1 ); 199 slider.setMaxValue( 1 );
209 slider.setFocusPolicy( QWidget::NoFocus ); 200 slider.setFocusPolicy( QWidget::NoFocus );
210 slider.setBackgroundPixmap( backgroundPixmap ); 201 slider.setBackgroundPixmap( backgroundPixmap );
211 202
212// Config cofg("qpe"); 203// Config cofg("qpe");
213// cofg.setGroup("Appearance"); 204// cofg.setGroup("Appearance");
214// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); 205// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) );
215 206
216 time.setFocusPolicy( QWidget::NoFocus ); 207 time.setFocusPolicy( QWidget::NoFocus );
217 time.setAlignment( Qt::AlignCenter ); 208 time.setAlignment( Qt::AlignCenter );
218 209
219// time.setFrame(FALSE); 210// time.setFrame(FALSE);
220// changeTextColor( &time ); 211// changeTextColor( &time );
221 212
222 resizeEvent( 0 ); 213 resizeEvent( 0 );
223} 214}
224 215
225void AudioWidget::setSeekable( bool isSeekable ) { 216void AudioWidget::setSeekable( bool isSeekable ) {
226 217
227 if ( !isSeekable ) { 218 if ( !isSeekable ) {
228 qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>"); 219 qDebug("<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>");
229 if( !slider.isHidden()) { 220 if( !slider.isHidden()) {
230 slider.hide(); 221 slider.hide();
231 } 222 }
232 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 223 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
233 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 224 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
234 disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 225 disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
235 disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 226 disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
236 } else { 227 } else {
237 // this stops the slider from being moved, thus 228 // this stops the slider from being moved, thus
238 // does not stop stream when it reaches the end 229 // does not stop stream when it reaches the end
239 slider.show(); 230 slider.show();
240 qDebug( " CONNECT SET POSTION " ); 231 qDebug( " CONNECT SET POSTION " );
241 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 232 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
242 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 233 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
243 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 234 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
244 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 235 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
245 } 236 }
246} 237}
247 238
248 239
249static QString timeAsString( long length ) { 240static QString timeAsString( long length ) {
250 int minutes = length / 60; 241 int minutes = length / 60;
251 int seconds = length % 60; 242 int seconds = length % 60;
252 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); 243 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 );
253} 244}
254 245
255void AudioWidget::updateSlider( long i, long max ) { 246void AudioWidget::updateSlider( long i, long max ) {
256 247
257 time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); 248 time.setText( timeAsString( i ) + " / " + timeAsString( max ) );
258// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; 249// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ;
259 250
260 if ( max == 0 ) { 251 if ( max == 0 ) {
261 return; 252 return;
262 } 253 }
263 // Will flicker too much if we don't do this 254 // Will flicker too much if we don't do this
264 // Scale to something reasonable 255 // Scale to something reasonable
265 int width = slider.width(); 256 int width = slider.width();
266 int val = int((double)i * width / max); 257 int val = int((double)i * width / max);
267 if ( !audioSliderBeingMoved ) { 258 if ( !audioSliderBeingMoved ) {
268 if ( slider.value() != val ) { 259 if ( slider.value() != val ) {
269 slider.setValue( val ); 260 slider.setValue( val );
270 } 261 }
271 262
272 if ( slider.maxValue() != width ) { 263 if ( slider.maxValue() != width ) {
273 slider.setMaxValue( width ); 264 slider.setMaxValue( width );
274 } 265 }
275 } 266 }
276} 267}
277 268
278void AudioWidget::skipFor() { 269void AudioWidget::skipFor() {
279 skipDirection = +1; 270 skipDirection = +1;
280 startTimer( 50 ); 271 startTimer( 50 );
281 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 272 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
282} 273}
283 274
284void AudioWidget::skipBack() { 275void AudioWidget::skipBack() {
285 skipDirection = -1; 276 skipDirection = -1;
286 startTimer( 50 ); 277 startTimer( 50 );
287 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 278 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
288} 279}
289 280
290 281
291 282
292void AudioWidget::stopSkip() { 283void AudioWidget::stopSkip() {
293 killTimers(); 284 killTimers();
294} 285}
295 286
296 287
297void AudioWidget::timerEvent( QTimerEvent * ) { 288void AudioWidget::timerEvent( QTimerEvent * ) {
298 if ( skipDirection == +1 ) { 289 if ( skipDirection == +1 ) {
299 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 290 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
300 } else if ( skipDirection == -1 ) { 291 } else if ( skipDirection == -1 ) {
301 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 292 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
302 } 293 }
303} 294}
304 295
305void AudioWidget::keyReleaseEvent( QKeyEvent *e) { 296void AudioWidget::keyReleaseEvent( QKeyEvent *e) {
306 switch ( e->key() ) { 297 switch ( e->key() ) {
307 ////////////////////////////// Zaurus keys 298 ////////////////////////////// Zaurus keys
308 case Key_Home: 299 case Key_Home:
309 break; 300 break;
310 case Key_F9: //activity 301 case Key_F9: //activity
311 hide(); 302 hide();
312 // qDebug("Audio F9"); 303 // qDebug("Audio F9");
313 e->accept(); 304 e->accept();
314 break; 305 break;
315 case Key_F10: //contacts 306 case Key_F10: //contacts
316 break; 307 break;
317 case Key_F11: //menu 308 case Key_F11: //menu
318 mediaPlayerState.toggleBlank(); 309 mediaPlayerState.toggleBlank();
319 e->accept(); 310 e->accept();
320 break; 311 break;
321 case Key_F12: //home 312 case Key_F12: //home
322 break; 313 break;
323 case Key_F13: //mail 314 case Key_F13: //mail
324 mediaPlayerState.toggleBlank(); 315 mediaPlayerState.toggleBlank();
325 e->accept(); 316 e->accept();
326 break; 317 break;
327 case Key_Space: { 318 case Key_Space: {
328 e->accept(); 319 e->accept();
329 mediaPlayerState.togglePaused(); 320 mediaPlayerState.togglePaused();
330 } 321 }
331 break; 322 break;
332 case Key_Down: 323 case Key_Down:
333 // toggleButton(6); 324 // toggleButton(6);
334 emit lessClicked(); 325 emit lessClicked();
335 emit lessReleased(); 326 emit lessReleased();
336 // toggleButton(6); 327 // toggleButton(6);
337 e->accept(); 328 e->accept();
338 break; 329 break;
339 case Key_Up: 330 case Key_Up:
340 // toggleButton(5); 331 // toggleButton(5);
341 emit moreClicked(); 332 emit moreClicked();
342 emit moreReleased(); 333 emit moreReleased();
343 // toggleButton(5); 334 // toggleButton(5);
344 e->accept(); 335 e->accept();
345 break; 336 break;
346 case Key_Right: 337 case Key_Right:
347 // toggleButton(3); 338 // toggleButton(3);
348 mediaPlayerState.setNext(); 339 mediaPlayerState.setNext();
349 // toggleButton(3); 340 // toggleButton(3);
350 e->accept(); 341 e->accept();
351 break; 342 break;
352 case Key_Left: 343 case Key_Left:
353 // toggleButton(4); 344 // toggleButton(4);
354 mediaPlayerState.setPrev(); 345 mediaPlayerState.setPrev();
355 // toggleButton(4); 346 // toggleButton(4);
356 e->accept(); 347 e->accept();
357 break; 348 break;
358 case Key_Escape: { 349 case Key_Escape: {
359 } 350 }
360 break; 351 break;
361 352
362 }; 353 };
363} 354}
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp
index ab23aa8..ab2ec50 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.cpp
+++ b/noncore/multimedia/opieplayer2/mediawidget.cpp
@@ -1,234 +1,267 @@
1/* 1/*
2 Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> 2 Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
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 library 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 Library 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 library 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 Library 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 Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. 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 23
24#include "mediawidget.h" 24#include "mediawidget.h"
25#include "playlistwidget.h" 25#include "playlistwidget.h"
26#include "skin.h" 26#include "skin.h"
27 27
28MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) 28MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name )
29 : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) 29 : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList )
30{ 30{
31 connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), 31 connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ),
32 this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); 32 this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) );
33 connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), 33 connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ),
34 this, SLOT( setLength( long ) ) ); 34 this, SLOT( setLength( long ) ) );
35 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), 35 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ),
36 this, SLOT( setPlaying( bool ) ) ); 36 this, SLOT( setPlaying( bool ) ) );
37} 37}
38 38
39MediaWidget::~MediaWidget() 39MediaWidget::~MediaWidget()
40{ 40{
41} 41}
42 42
43void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, 43void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount,
44 const Skin &skin ) 44 const Skin &skin )
45{ 45{
46 buttonMask = skin.buttonMask( skinInfo, buttonCount ); 46 buttonMask = skin.buttonMask( skinInfo, buttonCount );
47 47
48 buttons.clear(); 48 buttons.clear();
49 buttons.reserve( buttonCount ); 49 buttons.reserve( buttonCount );
50 50
51 for ( uint i = 0; i < buttonCount; ++i ) { 51 for ( uint i = 0; i < buttonCount; ++i ) {
52 Button button = setupButton( skinInfo[ i ], skin ); 52 Button button = setupButton( skinInfo[ i ], skin );
53 buttons.push_back( button ); 53 buttons.push_back( button );
54 } 54 }
55} 55}
56 56
57MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ) 57MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin )
58{ 58{
59 Button button; 59 Button button;
60 button.command = buttonInfo.command; 60 button.command = buttonInfo.command;
61 button.type = buttonInfo.type; 61 button.type = buttonInfo.type;
62 button.mask = skin.buttonMaskImage( buttonInfo.fileName ); 62 button.mask = skin.buttonMaskImage( buttonInfo.fileName );
63 63
64 return button; 64 return button;
65} 65}
66 66
67void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix ) 67void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix )
68{ 68{
69 Skin skin( fileNameInfix ); 69 Skin skin( fileNameInfix );
70 loadSkin( skinInfo, buttonCount, skin ); 70 loadSkin( skinInfo, buttonCount, skin );
71} 71}
72 72
73void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ) 73void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin )
74{ 74{
75 backgroundPixmap = skin.backgroundImage(); 75 backgroundPixmap = skin.backgroundImage();
76 buttonUpImage = skin.buttonUpImage(); 76 buttonUpImage = skin.buttonUpImage();
77 buttonDownImage = skin.buttonDownImage(); 77 buttonDownImage = skin.buttonDownImage();
78 78
79 setupButtons( skinInfo, buttonCount, skin ); 79 setupButtons( skinInfo, buttonCount, skin );
80} 80}
81 81
82void MediaWidget::closeEvent( QCloseEvent * ) 82void MediaWidget::closeEvent( QCloseEvent * )
83{ 83{
84 mediaPlayerState.setList(); 84 mediaPlayerState.setList();
85} 85}
86 86
87void MediaWidget::paintEvent( QPaintEvent *pe ) 87void MediaWidget::paintEvent( QPaintEvent *pe )
88{ 88{
89 QPainter p( this ); 89 QPainter p( this );
90 90
91 if ( mediaPlayerState.isFullscreen() ) { 91 if ( mediaPlayerState.isFullscreen() ) {
92 // Clear the background 92 // Clear the background
93 p.setBrush( QBrush( Qt::black ) ); 93 p.setBrush( QBrush( Qt::black ) );
94 return; 94 return;
95 } 95 }
96 96
97 if ( !pe->erased() ) { 97 if ( !pe->erased() ) {
98 // Combine with background and double buffer 98 // Combine with background and double buffer
99 QPixmap pix( pe->rect().size() ); 99 QPixmap pix( pe->rect().size() );
100 QPainter p( &pix ); 100 QPainter p( &pix );
101 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 101 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
102 p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); 102 p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() );
103 paintAllButtons( p ); 103 paintAllButtons( p );
104 QPainter p2( this ); 104 QPainter p2( this );
105 p2.drawPixmap( pe->rect().topLeft(), pix ); 105 p2.drawPixmap( pe->rect().topLeft(), pix );
106 } else { 106 } else {
107 QPainter p( this ); 107 QPainter p( this );
108 paintAllButtons( p ); 108 paintAllButtons( p );
109 } 109 }
110} 110}
111 111
112void MediaWidget::resizeEvent( QResizeEvent *e )
113{
114 QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, upperLeftOfButtonMask );
115 QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, upperLeftOfButtonMask );
116
117 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) {
118 Button &button = *it;
119
120 if ( button.mask.isNull() )
121 continue;
122 button.pixUp = addMaskToPixmap( pixUp, button.mask );
123 button.pixDown = addMaskToPixmap( pixDn, button.mask );
124 }
125
126 QWidget::resizeEvent( e );
127}
128
112MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) 129MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position )
113{ 130{
114 if ( position.x() <= 0 || position.y() <= 0 || 131 if ( position.x() <= 0 || position.y() <= 0 ||
115 position.x() >= buttonMask.width() || 132 position.x() >= buttonMask.width() ||
116 position.y() >= buttonMask.height() ) 133 position.y() >= buttonMask.height() )
117 return 0; 134 return 0;
118 135
119 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); 136 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() );
120 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) 137 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it )
121 if ( it->command + 1 == pixelIdx ) 138 if ( it->command + 1 == pixelIdx )
122 return &( *it ); 139 return &( *it );
123 140
124 return 0; 141 return 0;
125} 142}
126 143
127void MediaWidget::mousePressEvent( QMouseEvent *event ) 144void MediaWidget::mousePressEvent( QMouseEvent *event )
128{ 145{
129 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); 146 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
130 147
131 if ( !button ) { 148 if ( !button ) {
132 QWidget::mousePressEvent( event ); 149 QWidget::mousePressEvent( event );
133 return; 150 return;
134 } 151 }
135 152
136 switch ( button->command ) { 153 switch ( button->command ) {
137 case VolumeUp: emit moreClicked(); return; 154 case VolumeUp: emit moreClicked(); return;
138 case VolumeDown: emit lessClicked(); return; 155 case VolumeDown: emit lessClicked(); return;
139 case Back: emit backClicked(); return; 156 case Back: emit backClicked(); return;
140 case Forward: emit forwardClicked(); return; 157 case Forward: emit forwardClicked(); return;
141 default: break; 158 default: break;
142 } 159 }
143} 160}
144 161
145void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) 162void MediaWidget::mouseReleaseEvent( QMouseEvent *event )
146{ 163{
147 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); 164 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
148 165
149 if ( !button ) { 166 if ( !button ) {
150 QWidget::mouseReleaseEvent( event ); 167 QWidget::mouseReleaseEvent( event );
151 return; 168 return;
152 } 169 }
153 170
154 if ( button->type == ToggleButton ) 171 if ( button->type == ToggleButton )
155 toggleButton( *button ); 172 toggleButton( *button );
156 173
157 handleCommand( button->command, button->isDown ); 174 handleCommand( button->command, button->isDown );
158} 175}
159 176
160void MediaWidget::makeVisible() 177void MediaWidget::makeVisible()
161{ 178{
162} 179}
163 180
164void MediaWidget::handleCommand( Command command, bool buttonDown ) 181void MediaWidget::handleCommand( Command command, bool buttonDown )
165{ 182{
166 switch ( command ) { 183 switch ( command ) {
167 case Play: mediaPlayerState.togglePaused(); return; 184 case Play: mediaPlayerState.togglePaused(); return;
168 case Stop: mediaPlayerState.setPlaying(FALSE); return; 185 case Stop: mediaPlayerState.setPlaying(FALSE); return;
169 case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; 186 case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return;
170 case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; 187 case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return;
171 case Loop: mediaPlayerState.setLooping( buttonDown ); return; 188 case Loop: mediaPlayerState.setLooping( buttonDown ); return;
172 case VolumeUp: emit moreReleased(); return; 189 case VolumeUp: emit moreReleased(); return;
173 case VolumeDown: emit lessReleased(); return; 190 case VolumeDown: emit lessReleased(); return;
174 case PlayList: mediaPlayerState.setList(); return; 191 case PlayList: mediaPlayerState.setList(); return;
175 case Forward: emit forwardReleased(); return; 192 case Forward: emit forwardReleased(); return;
176 case Back: emit backReleased(); return; 193 case Back: emit backReleased(); return;
177 case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return; 194 case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return;
178 default: assert( false ); 195 default: assert( false );
179 } 196 }
180} 197}
181 198
182bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const 199bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const
183{ 200{
184 return ( position.x() > 0 && position.y() > 0 && 201 return ( position.x() > 0 && position.y() > 0 &&
185 position.x() < buttonMask.width() && 202 position.x() < buttonMask.width() &&
186 position.y() < buttonMask.height() && 203 position.y() < buttonMask.height() &&
187 buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); 204 buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 );
188} 205}
189 206
190void MediaWidget::paintAllButtons( QPainter &p ) 207void MediaWidget::paintAllButtons( QPainter &p )
191{ 208{
192 for ( ButtonVector::const_iterator it = buttons.begin(); 209 for ( ButtonVector::const_iterator it = buttons.begin();
193 it != buttons.end(); ++it ) 210 it != buttons.end(); ++it )
194 paintButton( p, *it ); 211 paintButton( p, *it );
195} 212}
196 213
197void MediaWidget::paintButton( const Button &button ) 214void MediaWidget::paintButton( const Button &button )
198{ 215{
199 QPainter p( this ); 216 QPainter p( this );
200 paintButton( p, button ); 217 paintButton( p, button );
201} 218}
202 219
203void MediaWidget::paintButton( QPainter &p, const Button &button ) 220void MediaWidget::paintButton( QPainter &p, const Button &button )
204{ 221{
205 if ( button.isDown ) 222 if ( button.isDown )
206 p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); 223 p.drawPixmap( upperLeftOfButtonMask, button.pixDown );
207 else 224 else
208 p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); 225 p.drawPixmap( upperLeftOfButtonMask, button.pixUp );
209} 226}
210 227
211void MediaWidget::setToggleButton( Command command, bool down ) 228void MediaWidget::setToggleButton( Command command, bool down )
212{ 229{
213 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) 230 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it )
214 if ( it->command == command ) { 231 if ( it->command == command ) {
215 setToggleButton( *it, down ); 232 setToggleButton( *it, down );
216 return; 233 return;
217 } 234 }
218} 235}
219 236
220void MediaWidget::setToggleButton( Button &button, bool down ) 237void MediaWidget::setToggleButton( Button &button, bool down )
221{ 238{
222 if ( down != button.isDown ) 239 if ( down != button.isDown )
223 toggleButton( button ); 240 toggleButton( button );
224} 241}
225 242
226void MediaWidget::toggleButton( Button &button ) 243void MediaWidget::toggleButton( Button &button )
227{ 244{
228 button.isDown = !button.isDown; 245 button.isDown = !button.isDown;
229 246
230 paintButton( button ); 247 paintButton( button );
231} 248}
232 249
250QPixmap MediaWidget::combineImageWithBackground( const QImage &image, const QPixmap &background, const QPoint &offset )
251{
252 QPixmap pix( image.size() );
253 QPainter p( &pix );
254 p.drawTiledPixmap( pix.rect(), background, offset );
255 p.drawImage( 0, 0, image );
256 return pix;
257}
258
259QPixmap MediaWidget::addMaskToPixmap( const QPixmap &pix, const QBitmap &mask )
260{
261 QPixmap result( pix );
262 result.setMask( mask );
263 return result;
264}
265
233/* vim: et sw=4 ts=4 266/* vim: et sw=4 ts=4
234 */ 267 */
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h
index 9f13677..4599637 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.h
+++ b/noncore/multimedia/opieplayer2/mediawidget.h
@@ -1,150 +1,155 @@
1/* 1/*
2 Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> 2 Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
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 library 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 Library 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 library 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 Library 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 Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. 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
35namespace 35namespace
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
46class Skin; 46class Skin;
47 47
48class MediaWidget : public QWidget 48class MediaWidget : public QWidget
49{ 49{
50 Q_OBJECT 50 Q_OBJECT
51public: 51public:
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 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); 83 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 );
84 virtual ~MediaWidget(); 84 virtual ~MediaWidget();
85 85
86public slots: 86public slots:
87 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; 87 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0;
88 virtual void setLength( long length ) = 0; 88 virtual void setLength( long length ) = 0;
89 virtual void setPlaying( bool playing ) = 0; 89 virtual void setPlaying( bool playing ) = 0;
90 90
91 virtual void loadSkin() = 0; 91 virtual void loadSkin() = 0;
92 92
93signals: 93signals:
94 void moreReleased(); 94 void moreReleased();
95 void lessReleased(); 95 void lessReleased();
96 void forwardReleased(); 96 void forwardReleased();
97 void backReleased(); 97 void backReleased();
98 void forwardClicked(); 98 void forwardClicked();
99 void backClicked(); 99 void backClicked();
100 void moreClicked(); 100 void moreClicked();
101 void lessClicked(); 101 void lessClicked();
102 102
103protected: 103protected:
104 void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, 104 void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount,
105 const Skin &skin ); 105 const Skin &skin );
106 Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ); 106 Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin );
107 107
108 void loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix = QString::null ); 108 void loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix = QString::null );
109 void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ); 109 void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin );
110 110
111 virtual void closeEvent( QCloseEvent * ); 111 virtual void closeEvent( QCloseEvent * );
112 112
113 virtual void paintEvent( QPaintEvent *pe ); 113 virtual void paintEvent( QPaintEvent *pe );
114 114
115 virtual void resizeEvent( QResizeEvent *e );
116
115 Button *buttonAt( const QPoint &position ); 117 Button *buttonAt( const QPoint &position );
116 118
117 virtual void mousePressEvent( QMouseEvent *event ); 119 virtual void mousePressEvent( QMouseEvent *event );
118 virtual void mouseReleaseEvent( QMouseEvent *event ); 120 virtual void mouseReleaseEvent( QMouseEvent *event );
119 121
120 virtual void makeVisible(); 122 virtual void makeVisible();
121 123
122 void handleCommand( Command command, bool buttonDown ); 124 void handleCommand( Command command, bool buttonDown );
123 125
124 bool isOverButton( const QPoint &position, int buttonId ) const; 126 bool isOverButton( const QPoint &position, int buttonId ) const;
125 127
126 void paintAllButtons( QPainter &p ); 128 void paintAllButtons( QPainter &p );
127 void paintButton( const Button &button ); 129 void paintButton( const Button &button );
128 void paintButton( QPainter &p, const Button &button ); 130 void paintButton( QPainter &p, const Button &button );
129 131
130 void setToggleButton( Button &button, bool down ); 132 void setToggleButton( Button &button, bool down );
131 void setToggleButton( Command command, bool down ); 133 void setToggleButton( Command command, bool down );
132 void toggleButton( Button &button ); 134 void toggleButton( Button &button );
133 135
134 MediaPlayerState &mediaPlayerState; 136 MediaPlayerState &mediaPlayerState;
135 PlayListWidget &playList; 137 PlayListWidget &playList;
136 138
137 ButtonVector buttons; 139 ButtonVector buttons;
138 140
139 QImage buttonMask; 141 QImage buttonMask;
140 142
141 QPoint upperLeftOfButtonMask; 143 QPoint upperLeftOfButtonMask;
142 144
143 QPixmap backgroundPixmap; 145 QPixmap backgroundPixmap;
144 QImage buttonUpImage; 146 QImage buttonUpImage;
145 QImage buttonDownImage; 147 QImage buttonDownImage;
148
149 static QPixmap combineImageWithBackground( const QImage &background, const QPixmap &pixmap, const QPoint &offset );
150 static QPixmap addMaskToPixmap( const QPixmap &pix, const QBitmap &mask );
146}; 151};
147 152
148#endif // MEDIAWIDGET_H 153#endif // MEDIAWIDGET_H
149/* vim: et sw=4 ts=4 154/* vim: et sw=4 ts=4
150 */ 155 */
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp
index bc47717..a8ff540 100644
--- a/noncore/multimedia/opieplayer2/videowidget.cpp
+++ b/noncore/multimedia/opieplayer2/videowidget.cpp
@@ -1,339 +1,311 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> 4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU General Public 12:`=1 )Y*s>-.--   : the terms of the GNU General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37 37
38 38
39#include <qwidget.h> 39#include <qwidget.h>
40#include <qpainter.h> 40#include <qpainter.h>
41#include <qpixmap.h> 41#include <qpixmap.h>
42#include <qslider.h> 42#include <qslider.h>
43#include <qdrawutil.h> 43#include <qdrawutil.h>
44#include "videowidget.h" 44#include "videowidget.h"
45#include "mediaplayerstate.h" 45#include "mediaplayerstate.h"
46#include "playlistwidget.h" 46#include "playlistwidget.h"
47 47
48 48
49#ifdef Q_WS_QWS 49#ifdef Q_WS_QWS
50# define USE_DIRECT_PAINTER 50# define USE_DIRECT_PAINTER
51# include <qdirectpainter_qws.h> 51# include <qdirectpainter_qws.h>
52# include <qgfxraster_qws.h> 52# include <qgfxraster_qws.h>
53#endif 53#endif
54 54
55 55
56namespace 56namespace
57{ 57{
58 58
59const int xo = 2; // movable x offset 59const int xo = 2; // movable x offset
60const int yo = 0; // movable y offset 60const int yo = 0; // movable y offset
61 61
62const MediaWidget::SkinButtonInfo skinInfo[] = 62const MediaWidget::SkinButtonInfo skinInfo[] =
63{ 63{
64 { MediaWidget::Play, "play", MediaWidget::ToggleButton }, 64 { MediaWidget::Play, "play", MediaWidget::ToggleButton },
65 { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, 65 { MediaWidget::Stop, "stop", MediaWidget::NormalButton },
66 { MediaWidget::Next, "fwd", MediaWidget::NormalButton }, 66 { MediaWidget::Next, "fwd", MediaWidget::NormalButton },
67 { MediaWidget::Previous, "back", MediaWidget::NormalButton }, 67 { MediaWidget::Previous, "back", MediaWidget::NormalButton },
68 { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, 68 { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton },
69 { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, 69 { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton },
70 { MediaWidget::FullScreen, "full", MediaWidget::ToggleButton } 70 { MediaWidget::FullScreen, "full", MediaWidget::ToggleButton }
71}; 71};
72 72
73const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); 73const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] );
74 74
75} 75}
76 76
77VideoWidget::VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name ) 77VideoWidget::VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name )
78 : MediaWidget( playList, mediaPlayerState, parent, name ), scaledWidth( 0 ), scaledHeight( 0 ), videoSliderBeingMoved( false ) 78 : MediaWidget( playList, mediaPlayerState, parent, name ), scaledWidth( 0 ), scaledHeight( 0 ), videoSliderBeingMoved( false )
79{ 79{
80 setCaption( tr("OpiePlayer - Video") ); 80 setCaption( tr("OpiePlayer - Video") );
81 81
82 videoFrame = new XineVideoWidget ( this, "Video frame" ); 82 videoFrame = new XineVideoWidget ( this, "Video frame" );
83 83
84 connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); 84 connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & )));
85 connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) ); 85 connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) );
86 86
87 slider = 0; 87 slider = 0;
88 88
89 loadSkin(); 89 loadSkin();
90 90
91 setLength( mediaPlayerState.length() ); 91 setLength( mediaPlayerState.length() );
92 setPosition( mediaPlayerState.position() ); 92 setPosition( mediaPlayerState.position() );
93 setFullscreen( mediaPlayerState.isFullscreen() ); 93 setFullscreen( mediaPlayerState.isFullscreen() );
94 setPlaying( mediaPlayerState.isPlaying() ); 94 setPlaying( mediaPlayerState.isPlaying() );
95} 95}
96 96
97 97
98VideoWidget::~VideoWidget() 98VideoWidget::~VideoWidget()
99{ 99{
100} 100}
101 101
102QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 102void VideoWidget::resizeEvent( QResizeEvent *e ) {
103 QPixmap pix( img.width(), img.height() );
104 QPainter p( &pix );
105 p.drawTiledPixmap( pix.rect(), bg, offset );
106 p.drawImage( 0, 0, img );
107 return new QPixmap( pix );
108}
109
110QPixmap maskVPixToMask( QPixmap pix, QBitmap mask ) {
111 QPixmap pixmap( pix );
112 pixmap.setMask( mask );
113 return pixmap;
114}
115
116void VideoWidget::resizeEvent( QResizeEvent * ) {
117 int h = height(); 103 int h = height();
118 int w = width(); 104 int w = width();
119 //int Vh = 160; 105 //int Vh = 160;
120 //int Vw = 220; 106 //int Vw = 220;
121 107
122 slider->setFixedWidth( w - 20 ); 108 slider->setFixedWidth( w - 20 );
123 slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); 109 slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) );
124 slider->setBackgroundOrigin( QWidget::ParentOrigin ); 110 slider->setBackgroundOrigin( QWidget::ParentOrigin );
125 slider->setFocusPolicy( QWidget::NoFocus ); 111 slider->setFocusPolicy( QWidget::NoFocus );
126 slider->setBackgroundPixmap( backgroundPixmap ); 112 slider->setBackgroundPixmap( backgroundPixmap );
127 113
128 upperLeftOfButtonMask.rx() = 0;// ( imgUp->width() ) / 2; 114 upperLeftOfButtonMask.rx() = 0;// ( imgUp->width() ) / 2;
129 if(w>h) 115 if(w>h)
130 upperLeftOfButtonMask.ry() = 0; 116 upperLeftOfButtonMask.ry() = 0;
131 else 117 else
132 upperLeftOfButtonMask.ry() = 185;//(( Vh - imgUp->height() ) / 2) - 10; 118 upperLeftOfButtonMask.ry() = 185;//(( Vh - imgUp->height() ) / 2) - 10;
133 QPoint p = upperLeftOfButtonMask;
134
135 QPixmap *pixUp = combineVImageWithBackground( buttonUpImage, backgroundPixmap, p );
136 QPixmap *pixDn = combineVImageWithBackground( buttonDownImage, backgroundPixmap, p );
137
138 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) {
139 Button &button = *it;
140
141 if ( !button.mask.isNull() ) {
142 button.pixUp = maskVPixToMask( *pixUp, button.mask );
143 button.pixDown = maskVPixToMask( *pixDn, button.mask );
144 }
145 }
146 119
147 delete pixUp; 120 MediaWidget::resizeEvent( e );
148 delete pixDn;
149} 121}
150 122
151void VideoWidget::sliderPressed() { 123void VideoWidget::sliderPressed() {
152 videoSliderBeingMoved = TRUE; 124 videoSliderBeingMoved = TRUE;
153} 125}
154 126
155void VideoWidget::sliderReleased() { 127void VideoWidget::sliderReleased() {
156 videoSliderBeingMoved = FALSE; 128 videoSliderBeingMoved = FALSE;
157 if ( slider->width() == 0 ) { 129 if ( slider->width() == 0 ) {
158 return; 130 return;
159 } 131 }
160 long val = long((double)slider->value() * mediaPlayerState.length() / slider->width()); 132 long val = long((double)slider->value() * mediaPlayerState.length() / slider->width());
161 mediaPlayerState.setPosition( val ); 133 mediaPlayerState.setPosition( val );
162} 134}
163 135
164void VideoWidget::setPosition( long i ) { 136void VideoWidget::setPosition( long i ) {
165 updateSlider( i, mediaPlayerState.length() ); 137 updateSlider( i, mediaPlayerState.length() );
166} 138}
167 139
168 140
169void VideoWidget::setLength( long max ) { 141void VideoWidget::setLength( long max ) {
170 updateSlider( mediaPlayerState.position(), max ); 142 updateSlider( mediaPlayerState.position(), max );
171} 143}
172 144
173void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType ) 145void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType )
174{ 146{
175 if ( displayType == MediaPlayerState::Video ) { 147 if ( displayType == MediaPlayerState::Video ) {
176 makeVisible(); 148 makeVisible();
177 return; 149 return;
178 } 150 }
179 151
180 // Effectively blank the view next time we show it so it looks nicer 152 // Effectively blank the view next time we show it so it looks nicer
181 scaledWidth = 0; 153 scaledWidth = 0;
182 scaledHeight = 0; 154 scaledHeight = 0;
183 hide(); 155 hide();
184} 156}
185 157
186void VideoWidget::loadSkin() 158void VideoWidget::loadSkin()
187{ 159{
188 loadDefaultSkin( skinInfo, buttonCount, "V" ); 160 loadDefaultSkin( skinInfo, buttonCount, "V" );
189 161
190 setBackgroundPixmap( backgroundPixmap ); 162 setBackgroundPixmap( backgroundPixmap );
191 163
192 delete slider; 164 delete slider;
193 slider = new QSlider( Qt::Horizontal, this ); 165 slider = new QSlider( Qt::Horizontal, this );
194 slider->setMinValue( 0 ); 166 slider->setMinValue( 0 );
195 slider->setMaxValue( 1 ); 167 slider->setMaxValue( 1 );
196 slider->setBackgroundPixmap( backgroundPixmap ); 168 slider->setBackgroundPixmap( backgroundPixmap );
197 //slider->setFocusPolicy( QWidget::NoFocus ); 169 //slider->setFocusPolicy( QWidget::NoFocus );
198 170
199 resizeEvent( 0 ); 171 resizeEvent( 0 );
200} 172}
201 173
202void VideoWidget::updateSlider( long i, long max ) { 174void VideoWidget::updateSlider( long i, long max ) {
203 // Will flicker too much if we don't do this 175 // Will flicker too much if we don't do this
204 if ( max == 0 ) { 176 if ( max == 0 ) {
205 return; 177 return;
206 } 178 }
207 int width = slider->width(); 179 int width = slider->width();
208 int val = int((double)i * width / max); 180 int val = int((double)i * width / max);
209 if ( !mediaPlayerState.isFullscreen() && !videoSliderBeingMoved ) { 181 if ( !mediaPlayerState.isFullscreen() && !videoSliderBeingMoved ) {
210 if ( slider->value() != val ) { 182 if ( slider->value() != val ) {
211 slider->setValue( val ); 183 slider->setValue( val );
212 } 184 }
213 if ( slider->maxValue() != width ) { 185 if ( slider->maxValue() != width ) {
214 slider->setMaxValue( width ); 186 slider->setMaxValue( width );
215 } 187 }
216 } 188 }
217} 189}
218 190
219void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { 191void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) {
220 if ( mediaPlayerState.isFullscreen() ) { 192 if ( mediaPlayerState.isFullscreen() ) {
221 mediaPlayerState.setFullscreen( FALSE ); 193 mediaPlayerState.setFullscreen( FALSE );
222 makeVisible(); 194 makeVisible();
223 } 195 }
224 MediaWidget::mouseReleaseEvent( event ); 196 MediaWidget::mouseReleaseEvent( event );
225} 197}
226 198
227void VideoWidget::backToNormal() { 199void VideoWidget::backToNormal() {
228 mediaPlayerState.setFullscreen( FALSE ); 200 mediaPlayerState.setFullscreen( FALSE );
229 makeVisible(); 201 makeVisible();
230} 202}
231 203
232void VideoWidget::makeVisible() { 204void VideoWidget::makeVisible() {
233 if ( mediaPlayerState.isFullscreen() ) { 205 if ( mediaPlayerState.isFullscreen() ) {
234 setBackgroundMode( QWidget::NoBackground ); 206 setBackgroundMode( QWidget::NoBackground );
235 showFullScreen(); 207 showFullScreen();
236 resize( qApp->desktop()->size() ); 208 resize( qApp->desktop()->size() );
237 videoFrame-> setGeometry ( 0, 0, width ( ), height ( )); 209 videoFrame-> setGeometry ( 0, 0, width ( ), height ( ));
238 210
239 slider->hide(); 211 slider->hide();
240 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 212 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
241 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 213 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
242 disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 214 disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
243 disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 215 disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
244 216
245 } else { 217 } else {
246 showNormal(); 218 showNormal();
247 showMaximized(); 219 showMaximized();
248 setBackgroundPixmap( backgroundPixmap ); 220 setBackgroundPixmap( backgroundPixmap );
249 QWidget *d = QApplication::desktop(); 221 QWidget *d = QApplication::desktop();
250 int w = d->width(); 222 int w = d->width();
251 int h = d->height(); 223 int h = d->height();
252 224
253 if(w>h) { 225 if(w>h) {
254 int newW=(w/2)-(246/2); //this will only work with 320x240 226 int newW=(w/2)-(246/2); //this will only work with 320x240
255 videoFrame->setGeometry( QRect( newW, 4, 240, 170 ) ); 227 videoFrame->setGeometry( QRect( newW, 4, 240, 170 ) );
256 } else { 228 } else {
257 videoFrame->setGeometry( QRect( 0, 30, 240, 170 ) ); 229 videoFrame->setGeometry( QRect( 0, 30, 240, 170 ) );
258 } 230 }
259 231
260 if ( !mediaPlayerState.isSeekable() ) { 232 if ( !mediaPlayerState.isSeekable() ) {
261 if( !slider->isHidden()) { 233 if( !slider->isHidden()) {
262 slider->hide(); 234 slider->hide();
263 } 235 }
264 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 236 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
265 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 237 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
266 disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 238 disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
267 disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 239 disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
268 } else { 240 } else {
269 slider->show(); 241 slider->show();
270 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 242 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
271 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 243 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
272 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 244 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
273 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 245 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
274 } 246 }
275 } 247 }
276} 248}
277 249
278void VideoWidget::keyReleaseEvent( QKeyEvent *e) { 250void VideoWidget::keyReleaseEvent( QKeyEvent *e) {
279 switch ( e->key() ) { 251 switch ( e->key() ) {
280////////////////////////////// Zaurus keys 252////////////////////////////// Zaurus keys
281 case Key_Home: 253 case Key_Home:
282 break; 254 break;
283 case Key_F9: //activity 255 case Key_F9: //activity
284 break; 256 break;
285 case Key_F10: //contacts 257 case Key_F10: //contacts
286// hide(); 258// hide();
287 break; 259 break;
288 case Key_F11: //menu 260 case Key_F11: //menu
289 break; 261 break;
290 case Key_F12: //home 262 case Key_F12: //home
291 break; 263 break;
292 case Key_F13: //mail 264 case Key_F13: //mail
293 break; 265 break;
294 case Key_Space: { 266 case Key_Space: {
295 if(mediaPlayerState.isPlaying()) { 267 if(mediaPlayerState.isPlaying()) {
296 mediaPlayerState.setPlaying(FALSE); 268 mediaPlayerState.setPlaying(FALSE);
297 } else { 269 } else {
298 mediaPlayerState.setPlaying(TRUE); 270 mediaPlayerState.setPlaying(TRUE);
299 } 271 }
300 } 272 }
301 break; 273 break;
302 case Key_Down: 274 case Key_Down:
303// toggleButton(6); 275// toggleButton(6);
304 emit lessClicked(); 276 emit lessClicked();
305 emit lessReleased(); 277 emit lessReleased();
306// toggleButton(6); 278// toggleButton(6);
307 break; 279 break;
308 case Key_Up: 280 case Key_Up:
309// toggleButton(5); 281// toggleButton(5);
310 emit moreClicked(); 282 emit moreClicked();
311 emit moreReleased(); 283 emit moreReleased();
312// toggleButton(5); 284// toggleButton(5);
313 break; 285 break;
314 case Key_Right: 286 case Key_Right:
315 mediaPlayerState.setNext(); 287 mediaPlayerState.setNext();
316 break; 288 break;
317 case Key_Left: 289 case Key_Left:
318 mediaPlayerState.setPrev(); 290 mediaPlayerState.setPrev();
319 break; 291 break;
320 case Key_Escape: 292 case Key_Escape:
321 break; 293 break;
322 294
323 }; 295 };
324} 296}
325 297
326XineVideoWidget* VideoWidget::vidWidget() { 298XineVideoWidget* VideoWidget::vidWidget() {
327 return videoFrame; 299 return videoFrame;
328} 300}
329 301
330 302
331void VideoWidget::setFullscreen ( bool b ) { 303void VideoWidget::setFullscreen ( bool b ) {
332 setToggleButton( FullScreen, b ); 304 setToggleButton( FullScreen, b );
333} 305}
334 306
335 307
336void VideoWidget::setPlaying( bool b) { 308void VideoWidget::setPlaying( bool b) {
337 setToggleButton( Play, b ); 309 setToggleButton( Play, b );
338} 310}
339 311