summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-08 22:47:39 (UTC)
committer simon <simon>2002-12-08 22:47:39 (UTC)
commit786bc677f61983414df8a4613cc525c4bcd2a054 (patch) (unidiff)
treec39a2a1691ffc8d813a496cb47c00b8ede47ea30
parent8b72df0bb25ca5a0791756b2444fc6a1ce361082 (diff)
downloadopie-786bc677f61983414df8a4613cc525c4bcd2a054.zip
opie-786bc677f61983414df8a4613cc525c4bcd2a054.tar.gz
opie-786bc677f61983414df8a4613cc525c4bcd2a054.tar.bz2
- moved the duplicated code for checking whether the mouse is over a
button into a shared isOverButton method
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp7
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp8
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.h2
-rw-r--r--noncore/multimedia/opieplayer2/videowidget.cpp7
4 files changed, 12 insertions, 12 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index 4301a67..d083273 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -288,198 +288,193 @@ void AudioWidget::setSeekable( bool isSeekable ) {
288 slider.show(); 288 slider.show();
289 qDebug( " CONNECT SET POSTION " ); 289 qDebug( " CONNECT SET POSTION " );
290 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 290 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
291 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 291 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
292 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 292 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
293 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 293 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
294 } 294 }
295} 295}
296 296
297 297
298static QString timeAsString( long length ) { 298static QString timeAsString( long length ) {
299 int minutes = length / 60; 299 int minutes = length / 60;
300 int seconds = length % 60; 300 int seconds = length % 60;
301 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); 301 return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 );
302} 302}
303 303
304void AudioWidget::updateSlider( long i, long max ) { 304void AudioWidget::updateSlider( long i, long max ) {
305 305
306 time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); 306 time.setText( timeAsString( i ) + " / " + timeAsString( max ) );
307// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; 307// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ;
308 308
309 if ( max == 0 ) { 309 if ( max == 0 ) {
310 return; 310 return;
311 } 311 }
312 // Will flicker too much if we don't do this 312 // Will flicker too much if we don't do this
313 // Scale to something reasonable 313 // Scale to something reasonable
314 int width = slider.width(); 314 int width = slider.width();
315 int val = int((double)i * width / max); 315 int val = int((double)i * width / max);
316 if ( !audioSliderBeingMoved ) { 316 if ( !audioSliderBeingMoved ) {
317 if ( slider.value() != val ) { 317 if ( slider.value() != val ) {
318 slider.setValue( val ); 318 slider.setValue( val );
319 } 319 }
320 320
321 if ( slider.maxValue() != width ) { 321 if ( slider.maxValue() != width ) {
322 slider.setMaxValue( width ); 322 slider.setMaxValue( width );
323 } 323 }
324 } 324 }
325} 325}
326 326
327 327
328void AudioWidget::setToggleButton( int i, bool down ) { 328void AudioWidget::setToggleButton( int i, bool down ) {
329 qDebug("setToggleButton %d", i); 329 qDebug("setToggleButton %d", i);
330 if ( down != buttons[i].isDown ) { 330 if ( down != buttons[i].isDown ) {
331 toggleButton( i ); 331 toggleButton( i );
332 } 332 }
333} 333}
334 334
335 335
336void AudioWidget::toggleButton( int i ) { 336void AudioWidget::toggleButton( int i ) {
337 buttons[i].isDown = !buttons[i].isDown; 337 buttons[i].isDown = !buttons[i].isDown;
338 QPainter p(this); 338 QPainter p(this);
339 paintButton ( &p, i ); 339 paintButton ( &p, i );
340} 340}
341 341
342 342
343void AudioWidget::paintButton( QPainter *p, int i ) { 343void AudioWidget::paintButton( QPainter *p, int i ) {
344 if ( buttons[i].isDown ) { 344 if ( buttons[i].isDown ) {
345 p->drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] ); 345 p->drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] );
346 } else { 346 } else {
347 p->drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] ); 347 p->drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] );
348 } 348 }
349} 349}
350 350
351 351
352void AudioWidget::skipFor() { 352void AudioWidget::skipFor() {
353 skipDirection = +1; 353 skipDirection = +1;
354 startTimer( 50 ); 354 startTimer( 50 );
355 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 355 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
356} 356}
357 357
358void AudioWidget::skipBack() { 358void AudioWidget::skipBack() {
359 skipDirection = -1; 359 skipDirection = -1;
360 startTimer( 50 ); 360 startTimer( 50 );
361 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 361 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
362} 362}
363 363
364 364
365 365
366void AudioWidget::stopSkip() { 366void AudioWidget::stopSkip() {
367 killTimers(); 367 killTimers();
368} 368}
369 369
370 370
371void AudioWidget::timerEvent( QTimerEvent * ) { 371void AudioWidget::timerEvent( QTimerEvent * ) {
372 if ( skipDirection == +1 ) { 372 if ( skipDirection == +1 ) {
373 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 373 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
374 } else if ( skipDirection == -1 ) { 374 } else if ( skipDirection == -1 ) {
375 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 375 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
376 } 376 }
377} 377}
378 378
379 379
380void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 380void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
381 for ( unsigned int i = 0; i < buttons.size(); i++ ) { 381 for ( unsigned int i = 0; i < buttons.size(); i++ ) {
382 if ( event->state() == QMouseEvent::LeftButton ) { 382 if ( event->state() == QMouseEvent::LeftButton ) {
383 // The test to see if the mouse click is inside the button or not 383 // The test to see if the mouse click is inside the button or not
384 int x = event->pos().x() - upperLeftOfButtonMask.x(); 384 bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i );
385 int y = event->pos().y() - upperLeftOfButtonMask.y();
386
387 bool isOnButton = ( x > 0 && y > 0 && x < buttonMask.width()
388 && y < buttonMask.height()
389 && buttonMask.pixelIndex( x, y ) == i + 1 );
390 385
391 if ( isOnButton && !buttons[i].isHeld ) { 386 if ( isOnButton && !buttons[i].isHeld ) {
392 buttons[i].isHeld = TRUE; 387 buttons[i].isHeld = TRUE;
393 toggleButton(i); 388 toggleButton(i);
394 switch (i) { 389 switch (i) {
395 case VolumeUp: 390 case VolumeUp:
396 emit moreClicked(); 391 emit moreClicked();
397 return; 392 return;
398 case VolumeDown: 393 case VolumeDown:
399 emit lessClicked(); 394 emit lessClicked();
400 return; 395 return;
401 case Forward: 396 case Forward:
402 emit forwardClicked(); 397 emit forwardClicked();
403 return; 398 return;
404 case Back: 399 case Back:
405 emit backClicked(); 400 emit backClicked();
406 return; 401 return;
407 } 402 }
408 } else if ( !isOnButton && buttons[i].isHeld ) { 403 } else if ( !isOnButton && buttons[i].isHeld ) {
409 buttons[i].isHeld = FALSE; 404 buttons[i].isHeld = FALSE;
410 toggleButton(i); 405 toggleButton(i);
411 } 406 }
412 } else { 407 } else {
413 if ( buttons[i].isHeld ) { 408 if ( buttons[i].isHeld ) {
414 buttons[i].isHeld = FALSE; 409 buttons[i].isHeld = FALSE;
415 if ( !buttons[i].isToggle ) { 410 if ( !buttons[i].isToggle ) {
416 setToggleButton( i, FALSE ); 411 setToggleButton( i, FALSE );
417 } 412 }
418 qDebug("mouseEvent %d", i); 413 qDebug("mouseEvent %d", i);
419 handleCommand( static_cast<Command>( i ), buttons[ i ].isDown ); 414 handleCommand( static_cast<Command>( i ), buttons[ i ].isDown );
420 } 415 }
421 } 416 }
422 } 417 }
423} 418}
424 419
425 420
426void AudioWidget::mousePressEvent( QMouseEvent *event ) { 421void AudioWidget::mousePressEvent( QMouseEvent *event ) {
427 mouseMoveEvent( event ); 422 mouseMoveEvent( event );
428} 423}
429 424
430 425
431void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { 426void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
432 mouseMoveEvent( event ); 427 mouseMoveEvent( event );
433} 428}
434 429
435 430
436void AudioWidget::showEvent( QShowEvent* ) { 431void AudioWidget::showEvent( QShowEvent* ) {
437 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 432 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
438 mouseMoveEvent( &event ); 433 mouseMoveEvent( &event );
439} 434}
440 435
441 436
442void AudioWidget::paintEvent( QPaintEvent * pe ) { 437void AudioWidget::paintEvent( QPaintEvent * pe ) {
443 if ( !pe->erased() ) { 438 if ( !pe->erased() ) {
444 // Combine with background and double buffer 439 // Combine with background and double buffer
445 QPixmap pix( pe->rect().size() ); 440 QPixmap pix( pe->rect().size() );
446 QPainter p( &pix ); 441 QPainter p( &pix );
447 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 442 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
448 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); 443 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() );
449 for ( unsigned int i = 0; i < buttons.size(); i++ ) 444 for ( unsigned int i = 0; i < buttons.size(); i++ )
450 paintButton( &p, i ); 445 paintButton( &p, i );
451 QPainter p2( this ); 446 QPainter p2( this );
452 p2.drawPixmap( pe->rect().topLeft(), pix ); 447 p2.drawPixmap( pe->rect().topLeft(), pix );
453 } else { 448 } else {
454 QPainter p( this ); 449 QPainter p( this );
455 for ( unsigned int i = 0; i < buttons.size(); i++ ) 450 for ( unsigned int i = 0; i < buttons.size(); i++ )
456 paintButton( &p, i ); 451 paintButton( &p, i );
457 } 452 }
458} 453}
459 454
460void AudioWidget::keyReleaseEvent( QKeyEvent *e) { 455void AudioWidget::keyReleaseEvent( QKeyEvent *e) {
461 switch ( e->key() ) { 456 switch ( e->key() ) {
462 ////////////////////////////// Zaurus keys 457 ////////////////////////////// Zaurus keys
463 case Key_Home: 458 case Key_Home:
464 break; 459 break;
465 case Key_F9: //activity 460 case Key_F9: //activity
466 hide(); 461 hide();
467 // qDebug("Audio F9"); 462 // qDebug("Audio F9");
468 break; 463 break;
469 case Key_F10: //contacts 464 case Key_F10: //contacts
470 break; 465 break;
471 case Key_F11: //menu 466 case Key_F11: //menu
472 mediaPlayerState.toggleBlank(); 467 mediaPlayerState.toggleBlank();
473 break; 468 break;
474 case Key_F12: //home 469 case Key_F12: //home
475 break; 470 break;
476 case Key_F13: //mail 471 case Key_F13: //mail
477 mediaPlayerState.toggleBlank(); 472 mediaPlayerState.toggleBlank();
478 break; 473 break;
479 case Key_Space: { 474 case Key_Space: {
480 if(mediaPlayerState.isPlaying()) { 475 if(mediaPlayerState.isPlaying()) {
481 // toggleButton(1); 476 // toggleButton(1);
482 mediaPlayerState.setPlaying(FALSE); 477 mediaPlayerState.setPlaying(FALSE);
483 // toggleButton(1); 478 // toggleButton(1);
484 } else { 479 } else {
485 // toggleButton(0); 480 // toggleButton(0);
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp
index a1b292e..1d18d6f 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.cpp
+++ b/noncore/multimedia/opieplayer2/mediawidget.cpp
@@ -1,64 +1,72 @@
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 26
27MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) 27MediaWidget::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 37
38MediaWidget::~MediaWidget() 38MediaWidget::~MediaWidget()
39{ 39{
40} 40}
41 41
42void MediaWidget::closeEvent( QCloseEvent * ) 42void MediaWidget::closeEvent( QCloseEvent * )
43{ 43{
44 mediaPlayerState.setList(); 44 mediaPlayerState.setList();
45} 45}
46 46
47void MediaWidget::handleCommand( Command command, bool buttonDown ) 47void MediaWidget::handleCommand( Command command, bool buttonDown )
48{ 48{
49 switch ( command ) { 49 switch ( command ) {
50 case Play: mediaPlayerState.togglePaused(); 50 case Play: mediaPlayerState.togglePaused();
51 case Stop: mediaPlayerState.setPlaying(FALSE); return; 51 case Stop: mediaPlayerState.setPlaying(FALSE); return;
52 case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; 52 case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return;
53 case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; 53 case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return;
54 case Loop: mediaPlayerState.setLooping( buttonDown ); return; 54 case Loop: mediaPlayerState.setLooping( buttonDown ); return;
55 case VolumeUp: emit moreReleased(); return; 55 case VolumeUp: emit moreReleased(); return;
56 case VolumeDown: emit lessReleased(); return; 56 case VolumeDown: emit lessReleased(); return;
57 case PlayList: mediaPlayerState.setList(); return; 57 case PlayList: mediaPlayerState.setList(); return;
58 case Forward: emit forwardReleased(); return; 58 case Forward: emit forwardReleased(); return;
59 case Back: emit backReleased(); return; 59 case Back: emit backReleased(); return;
60 } 60 }
61} 61}
62 62
63bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const
64{
65 return ( position.x() > 0 && position.y() > 0 &&
66 position.x() < buttonMask.width() &&
67 position.y() < buttonMask.height() &&
68 buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 );
69}
70
63/* vim: et sw=4 ts=4 71/* vim: et sw=4 ts=4
64 */ 72 */
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h
index 7e6cb3b..6e12a3b 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.h
+++ b/noncore/multimedia/opieplayer2/mediawidget.h
@@ -1,80 +1,82 @@
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 27
28#include "mediaplayerstate.h" 28#include "mediaplayerstate.h"
29#include "playlistwidget.h" 29#include "playlistwidget.h"
30 30
31#include <vector> 31#include <vector>
32 32
33class MediaWidget : public QWidget 33class MediaWidget : public QWidget
34{ 34{
35 Q_OBJECT 35 Q_OBJECT
36public: 36public:
37 enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back }; 37 enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back };
38 38
39 struct Button 39 struct Button
40 { 40 {
41 Button() : isToggle( false ), isHeld( false ), isDown( false ) {} 41 Button() : isToggle( false ), isHeld( false ), isDown( false ) {}
42 42
43 bool isToggle : 1; 43 bool isToggle : 1;
44 bool isHeld : 1; 44 bool isHeld : 1;
45 bool isDown : 1; 45 bool isDown : 1;
46 }; 46 };
47 typedef std::vector<Button> ButtonVector; 47 typedef std::vector<Button> ButtonVector;
48 48
49 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); 49 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 );
50 virtual ~MediaWidget(); 50 virtual ~MediaWidget();
51 51
52public slots: 52public slots:
53 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; 53 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0;
54 virtual void setLength( long length ) = 0; 54 virtual void setLength( long length ) = 0;
55 virtual void setPlaying( bool playing ) = 0; 55 virtual void setPlaying( bool playing ) = 0;
56 56
57signals: 57signals:
58 void moreReleased(); 58 void moreReleased();
59 void lessReleased(); 59 void lessReleased();
60 void forwardReleased(); 60 void forwardReleased();
61 void backReleased(); 61 void backReleased();
62 62
63protected: 63protected:
64 virtual void closeEvent( QCloseEvent * ); 64 virtual void closeEvent( QCloseEvent * );
65 65
66 void handleCommand( Command command, bool buttonDown ); 66 void handleCommand( Command command, bool buttonDown );
67 67
68 bool isOverButton( const QPoint &position, int buttonId ) const;
69
68 MediaPlayerState &mediaPlayerState; 70 MediaPlayerState &mediaPlayerState;
69 PlayListWidget &playList; 71 PlayListWidget &playList;
70 72
71 ButtonVector buttons; 73 ButtonVector buttons;
72 74
73 QImage buttonMask; 75 QImage buttonMask;
74 76
75 QPoint upperLeftOfButtonMask; 77 QPoint upperLeftOfButtonMask;
76}; 78};
77 79
78#endif // MEDIAWIDGET_H 80#endif // MEDIAWIDGET_H
79/* vim: et sw=4 ts=4 81/* vim: et sw=4 ts=4
80 */ 82 */
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp
index 6ab6d7b..6451ac4 100644
--- a/noncore/multimedia/opieplayer2/videowidget.cpp
+++ b/noncore/multimedia/opieplayer2/videowidget.cpp
@@ -189,198 +189,193 @@ void VideoWidget::resizeEvent( QResizeEvent * ) {
189 189
190 QPixmap *pixUp = combineVImageWithBackground( imgUp, pixBg, p ); 190 QPixmap *pixUp = combineVImageWithBackground( imgUp, pixBg, p );
191 QPixmap *pixDn = combineVImageWithBackground( imgDn, pixBg, p ); 191 QPixmap *pixDn = combineVImageWithBackground( imgDn, pixBg, p );
192 192
193 for ( int i = 0; i < 7; i++ ) { 193 for ( int i = 0; i < 7; i++ ) {
194 if ( !masks[i]->isNull() ) { 194 if ( !masks[i]->isNull() ) {
195 delete buttonPixUp[i]; 195 delete buttonPixUp[i];
196 delete buttonPixDown[i]; 196 delete buttonPixDown[i];
197 buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); 197 buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] );
198 buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); 198 buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] );
199 } 199 }
200 } 200 }
201 201
202 delete pixUp; 202 delete pixUp;
203 delete pixDn; 203 delete pixDn;
204} 204}
205 205
206static bool videoSliderBeingMoved = FALSE; 206static bool videoSliderBeingMoved = FALSE;
207 207
208void VideoWidget::sliderPressed() { 208void VideoWidget::sliderPressed() {
209 videoSliderBeingMoved = TRUE; 209 videoSliderBeingMoved = TRUE;
210} 210}
211 211
212void VideoWidget::sliderReleased() { 212void VideoWidget::sliderReleased() {
213 videoSliderBeingMoved = FALSE; 213 videoSliderBeingMoved = FALSE;
214 if ( slider->width() == 0 ) { 214 if ( slider->width() == 0 ) {
215 return; 215 return;
216 } 216 }
217 long val = long((double)slider->value() * mediaPlayerState.length() / slider->width()); 217 long val = long((double)slider->value() * mediaPlayerState.length() / slider->width());
218 mediaPlayerState.setPosition( val ); 218 mediaPlayerState.setPosition( val );
219} 219}
220 220
221void VideoWidget::setPosition( long i ) { 221void VideoWidget::setPosition( long i ) {
222 updateSlider( i, mediaPlayerState.length() ); 222 updateSlider( i, mediaPlayerState.length() );
223} 223}
224 224
225 225
226void VideoWidget::setLength( long max ) { 226void VideoWidget::setLength( long max ) {
227 updateSlider( mediaPlayerState.position(), max ); 227 updateSlider( mediaPlayerState.position(), max );
228} 228}
229 229
230void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType ) 230void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType )
231{ 231{
232 if ( displayType == MediaPlayerState::Video ) { 232 if ( displayType == MediaPlayerState::Video ) {
233 makeVisible(); 233 makeVisible();
234 return; 234 return;
235 } 235 }
236 236
237 // Effectively blank the view next time we show it so it looks nicer 237 // Effectively blank the view next time we show it so it looks nicer
238 scaledWidth = 0; 238 scaledWidth = 0;
239 scaledHeight = 0; 239 scaledHeight = 0;
240 hide(); 240 hide();
241} 241}
242 242
243void VideoWidget::updateSlider( long i, long max ) { 243void VideoWidget::updateSlider( long i, long max ) {
244 // Will flicker too much if we don't do this 244 // Will flicker too much if we don't do this
245 if ( max == 0 ) { 245 if ( max == 0 ) {
246 return; 246 return;
247 } 247 }
248 int width = slider->width(); 248 int width = slider->width();
249 int val = int((double)i * width / max); 249 int val = int((double)i * width / max);
250 if ( !mediaPlayerState.isFullscreen() && !videoSliderBeingMoved ) { 250 if ( !mediaPlayerState.isFullscreen() && !videoSliderBeingMoved ) {
251 if ( slider->value() != val ) { 251 if ( slider->value() != val ) {
252 slider->setValue( val ); 252 slider->setValue( val );
253 } 253 }
254 if ( slider->maxValue() != width ) { 254 if ( slider->maxValue() != width ) {
255 slider->setMaxValue( width ); 255 slider->setMaxValue( width );
256 } 256 }
257 } 257 }
258} 258}
259 259
260void VideoWidget::setToggleButton( int i, bool down ) { 260void VideoWidget::setToggleButton( int i, bool down ) {
261 if ( down != buttons[i].isDown ) { 261 if ( down != buttons[i].isDown ) {
262 toggleButton( i ); 262 toggleButton( i );
263 } 263 }
264} 264}
265 265
266void VideoWidget::toggleButton( int i ) { 266void VideoWidget::toggleButton( int i ) {
267 buttons[i].isDown = !buttons[i].isDown; 267 buttons[i].isDown = !buttons[i].isDown;
268 QPainter p(this); 268 QPainter p(this);
269 paintButton ( &p, i ); 269 paintButton ( &p, i );
270} 270}
271 271
272void VideoWidget::paintButton( QPainter *p, int i ) { 272void VideoWidget::paintButton( QPainter *p, int i ) {
273 273
274 if ( buttons[i].isDown ) { 274 if ( buttons[i].isDown ) {
275 p->drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] ); 275 p->drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] );
276 } else { 276 } else {
277 p->drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] ); 277 p->drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] );
278 } 278 }
279} 279}
280 280
281void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { 281void VideoWidget::mouseMoveEvent( QMouseEvent *event ) {
282 for ( unsigned int i = 0; i < buttons.size(); i++ ) { 282 for ( unsigned int i = 0; i < buttons.size(); i++ ) {
283 if ( event->state() == QMouseEvent::LeftButton ) { 283 if ( event->state() == QMouseEvent::LeftButton ) {
284 // The test to see if the mouse click is inside the button or not 284 // The test to see if the mouse click is inside the button or not
285 int x = event->pos().x() - upperLeftOfButtonMask.x(); 285 bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i );
286 int y = event->pos().y() - upperLeftOfButtonMask.y();
287
288 bool isOnButton = ( x > 0 && y > 0 && x < buttonMask.width()
289 && y < buttonMask.height()
290 && buttonMask.pixelIndex( x, y ) == i + 1 );
291 286
292 if ( isOnButton && !buttons[i].isHeld ) { 287 if ( isOnButton && !buttons[i].isHeld ) {
293 buttons[i].isHeld = TRUE; 288 buttons[i].isHeld = TRUE;
294 toggleButton(i); 289 toggleButton(i);
295 290
296 switch (i) { 291 switch (i) {
297 case VideoVolUp: 292 case VideoVolUp:
298 emit moreClicked(); 293 emit moreClicked();
299 return; 294 return;
300 case VideoVolDown: 295 case VideoVolDown:
301 emit lessClicked(); 296 emit lessClicked();
302 return; 297 return;
303 } 298 }
304 } else if ( !isOnButton && buttons[i].isHeld ) { 299 } else if ( !isOnButton && buttons[i].isHeld ) {
305 buttons[i].isHeld = FALSE; 300 buttons[i].isHeld = FALSE;
306 toggleButton(i); 301 toggleButton(i);
307 } 302 }
308 } else { 303 } else {
309 304
310 if ( buttons[i].isHeld ) { 305 if ( buttons[i].isHeld ) {
311 buttons[i].isHeld = FALSE; 306 buttons[i].isHeld = FALSE;
312 if ( !buttons[i].isToggle ) { 307 if ( !buttons[i].isToggle ) {
313 setToggleButton( i, FALSE ); 308 setToggleButton( i, FALSE );
314 } 309 }
315 310
316 switch(i) { 311 switch(i) {
317 312
318 case VideoPlay: { 313 case VideoPlay: {
319 if( mediaPlayerState.isPaused() ) { 314 if( mediaPlayerState.isPaused() ) {
320 setToggleButton( i, FALSE ); 315 setToggleButton( i, FALSE );
321 mediaPlayerState.setPaused( FALSE ); 316 mediaPlayerState.setPaused( FALSE );
322 return; 317 return;
323 } else if( !mediaPlayerState.isPaused() ) { 318 } else if( !mediaPlayerState.isPaused() ) {
324 setToggleButton( i, TRUE ); 319 setToggleButton( i, TRUE );
325 mediaPlayerState.setPaused( TRUE ); 320 mediaPlayerState.setPaused( TRUE );
326 return; 321 return;
327 } else { 322 } else {
328 return; 323 return;
329 } 324 }
330 } 325 }
331 326
332 case VideoStop: mediaPlayerState.setPlaying( FALSE ); return; 327 case VideoStop: mediaPlayerState.setPlaying( FALSE ); return;
333 case VideoNext: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; 328 case VideoNext: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return;
334 case VideoPrevious: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; 329 case VideoPrevious: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return;
335 case VideoVolUp: emit moreReleased(); return; 330 case VideoVolUp: emit moreReleased(); return;
336 case VideoVolDown: emit lessReleased(); return; 331 case VideoVolDown: emit lessReleased(); return;
337 case VideoFullscreen: mediaPlayerState.setFullscreen( TRUE ); makeVisible(); return; 332 case VideoFullscreen: mediaPlayerState.setFullscreen( TRUE ); makeVisible(); return;
338 } 333 }
339 } 334 }
340 } 335 }
341 } 336 }
342} 337}
343 338
344void VideoWidget::mousePressEvent( QMouseEvent *event ) { 339void VideoWidget::mousePressEvent( QMouseEvent *event ) {
345 mouseMoveEvent( event ); 340 mouseMoveEvent( event );
346} 341}
347 342
348void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { 343void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) {
349 if ( mediaPlayerState.isFullscreen() ) { 344 if ( mediaPlayerState.isFullscreen() ) {
350 mediaPlayerState.setFullscreen( FALSE ); 345 mediaPlayerState.setFullscreen( FALSE );
351 makeVisible(); 346 makeVisible();
352 } 347 }
353 mouseMoveEvent( event ); 348 mouseMoveEvent( event );
354} 349}
355 350
356void VideoWidget::showEvent( QShowEvent* ) { 351void VideoWidget::showEvent( QShowEvent* ) {
357 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 352 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
358 mouseMoveEvent( &event ); 353 mouseMoveEvent( &event );
359} 354}
360 355
361 356
362 void VideoWidget::backToNormal() { 357 void VideoWidget::backToNormal() {
363 mediaPlayerState.setFullscreen( FALSE ); 358 mediaPlayerState.setFullscreen( FALSE );
364 makeVisible(); 359 makeVisible();
365 } 360 }
366 361
367void VideoWidget::makeVisible() { 362void VideoWidget::makeVisible() {
368 if ( mediaPlayerState.isFullscreen() ) { 363 if ( mediaPlayerState.isFullscreen() ) {
369 setBackgroundMode( QWidget::NoBackground ); 364 setBackgroundMode( QWidget::NoBackground );
370 showFullScreen(); 365 showFullScreen();
371 resize( qApp->desktop()->size() ); 366 resize( qApp->desktop()->size() );
372 videoFrame-> setGeometry ( 0, 0, width ( ), height ( )); 367 videoFrame-> setGeometry ( 0, 0, width ( ), height ( ));
373 368
374 slider->hide(); 369 slider->hide();
375 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 370 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
376 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 371 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
377 disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 372 disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
378 disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 373 disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
379 374
380 } else { 375 } else {
381 showNormal(); 376 showNormal();
382 showMaximized(); 377 showMaximized();
383 setBackgroundPixmap( pixBg ); 378 setBackgroundPixmap( pixBg );
384 QWidget *d = QApplication::desktop(); 379 QWidget *d = QApplication::desktop();
385 int w = d->width(); 380 int w = d->width();
386 int h = d->height(); 381 int h = d->height();