summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-09 20:02:52 (UTC)
committer simon <simon>2002-12-09 20:02:52 (UTC)
commit2d2d57e3b7988f4246319cdfd0dc7fa90110db8e (patch) (unidiff)
treefb4dfb832e2630e7da1cc57e92ba6c62ead22dee
parent046f040efcb0f313818d1dbb1dc1db9021678175 (diff)
downloadopie-2d2d57e3b7988f4246319cdfd0dc7fa90110db8e.zip
opie-2d2d57e3b7988f4246319cdfd0dc7fa90110db8e.tar.gz
opie-2d2d57e3b7988f4246319cdfd0dc7fa90110db8e.tar.bz2
- reworked the mouse event handling to be much simpler
- fixed missing return in Play case in handleCommand, which accidentially broke pausing - accept the key events we receive in the audioWidget - commented out suspicious connect to pauseCheck in mediaplayer, which broke pausing via space bar
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp8
-rw-r--r--noncore/multimedia/opieplayer2/mediaplayer.cpp3
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp84
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.h3
4 files changed, 51 insertions, 47 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index 5986a72..8e9bbf1 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -325,67 +325,75 @@ void AudioWidget::stopSkip() {
325} 325}
326 326
327 327
328void AudioWidget::timerEvent( QTimerEvent * ) { 328void AudioWidget::timerEvent( QTimerEvent * ) {
329 if ( skipDirection == +1 ) { 329 if ( skipDirection == +1 ) {
330 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 330 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
331 } else if ( skipDirection == -1 ) { 331 } else if ( skipDirection == -1 ) {
332 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 332 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
333 } 333 }
334} 334}
335 335
336void AudioWidget::showEvent( QShowEvent* ) { 336void AudioWidget::showEvent( QShowEvent* ) {
337 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 337 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
338 mouseMoveEvent( &event ); 338 mouseMoveEvent( &event );
339} 339}
340 340
341void AudioWidget::keyReleaseEvent( QKeyEvent *e) { 341void AudioWidget::keyReleaseEvent( QKeyEvent *e) {
342 switch ( e->key() ) { 342 switch ( e->key() ) {
343 ////////////////////////////// Zaurus keys 343 ////////////////////////////// Zaurus keys
344 case Key_Home: 344 case Key_Home:
345 break; 345 break;
346 case Key_F9: //activity 346 case Key_F9: //activity
347 hide(); 347 hide();
348 // qDebug("Audio F9"); 348 // qDebug("Audio F9");
349 e->accept();
349 break; 350 break;
350 case Key_F10: //contacts 351 case Key_F10: //contacts
351 break; 352 break;
352 case Key_F11: //menu 353 case Key_F11: //menu
353 mediaPlayerState.toggleBlank(); 354 mediaPlayerState.toggleBlank();
355 e->accept();
354 break; 356 break;
355 case Key_F12: //home 357 case Key_F12: //home
356 break; 358 break;
357 case Key_F13: //mail 359 case Key_F13: //mail
358 mediaPlayerState.toggleBlank(); 360 mediaPlayerState.toggleBlank();
361 e->accept();
359 break; 362 break;
360 case Key_Space: { 363 case Key_Space: {
364 e->accept();
361 mediaPlayerState.togglePaused(); 365 mediaPlayerState.togglePaused();
362 } 366 }
363 break; 367 break;
364 case Key_Down: 368 case Key_Down:
365 // toggleButton(6); 369 // toggleButton(6);
366 emit lessClicked(); 370 emit lessClicked();
367 emit lessReleased(); 371 emit lessReleased();
368 // toggleButton(6); 372 // toggleButton(6);
373 e->accept();
369 break; 374 break;
370 case Key_Up: 375 case Key_Up:
371 // toggleButton(5); 376 // toggleButton(5);
372 emit moreClicked(); 377 emit moreClicked();
373 emit moreReleased(); 378 emit moreReleased();
374 // toggleButton(5); 379 // toggleButton(5);
380 e->accept();
375 break; 381 break;
376 case Key_Right: 382 case Key_Right:
377 // toggleButton(3); 383 // toggleButton(3);
378 mediaPlayerState.setNext(); 384 mediaPlayerState.setNext();
379 // toggleButton(3); 385 // toggleButton(3);
386 e->accept();
380 break; 387 break;
381 case Key_Left: 388 case Key_Left:
382 // toggleButton(4); 389 // toggleButton(4);
383 mediaPlayerState.setPrev(); 390 mediaPlayerState.setPrev();
384 // toggleButton(4); 391 // toggleButton(4);
392 e->accept();
385 break; 393 break;
386 case Key_Escape: { 394 case Key_Escape: {
387 } 395 }
388 break; 396 break;
389 397
390 }; 398 };
391} 399}
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp
index ed7e37f..e1bfc2d 100644
--- a/noncore/multimedia/opieplayer2/mediaplayer.cpp
+++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp
@@ -24,49 +24,50 @@
24#include <sys/ioctl.h> 24#include <sys/ioctl.h>
25 25
26 26
27 27
28 28
29#define FBIOBLANK 0x4611 29#define FBIOBLANK 0x4611
30 30
31MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name ) 31MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name )
32 : QObject( parent, name ), volumeDirection( 0 ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) { 32 : QObject( parent, name ), volumeDirection( 0 ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) {
33 33
34 audioUI = 0; 34 audioUI = 0;
35 videoUI = 0; 35 videoUI = 0;
36 xineControl = 0; 36 xineControl = 0;
37 recreateAudioAndVideoWidgets(); 37 recreateAudioAndVideoWidgets();
38 38
39 fd=-1;fl=-1; 39 fd=-1;fl=-1;
40 playList.setCaption( tr( "OpiePlayer: Initializating" ) ); 40 playList.setCaption( tr( "OpiePlayer: Initializating" ) );
41 41
42 qApp->processEvents(); 42 qApp->processEvents();
43 // QPEApplication::grabKeyboard(); // EVIL 43 // QPEApplication::grabKeyboard(); // EVIL
44 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); 44 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
45 45
46 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); 46 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) );
47 47
48 connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); 48// What is pauseCheck good for? (Simon)
49// connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) );
49 50
50 connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); 51 connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) );
51 connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); 52 connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) );
52 connect( &mediaPlayerState, SIGNAL( blankToggled( bool ) ), this, SLOT ( blank( bool ) ) ); 53 connect( &mediaPlayerState, SIGNAL( blankToggled( bool ) ), this, SLOT ( blank( bool ) ) );
53 54
54 volControl = new VolumeControl; 55 volControl = new VolumeControl;
55 Config cfg( "OpiePlayer" ); 56 Config cfg( "OpiePlayer" );
56 cfg.setGroup("PlayList"); 57 cfg.setGroup("PlayList");
57 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); 58 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
58 playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() ); 59 playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() );
59} 60}
60 61
61MediaPlayer::~MediaPlayer() { 62MediaPlayer::~MediaPlayer() {
62 delete xineControl; 63 delete xineControl;
63 delete audioUI; 64 delete audioUI;
64 delete videoUI; 65 delete videoUI;
65 delete volControl; 66 delete volControl;
66} 67}
67 68
68void MediaPlayer::pauseCheck( bool b ) { 69void MediaPlayer::pauseCheck( bool b ) {
69 if ( b && !mediaPlayerState.isPlaying() ) { 70 if ( b && !mediaPlayerState.isPlaying() ) {
70 mediaPlayerState.setPaused( FALSE ); 71 mediaPlayerState.setPaused( FALSE );
71 } 72 }
72} 73}
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp
index 439ba2e..4c4cead 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.cpp
+++ b/noncore/multimedia/opieplayer2/mediawidget.cpp
@@ -48,110 +48,104 @@ void MediaWidget::paintEvent( QPaintEvent *pe )
48{ 48{
49 QPainter p( this ); 49 QPainter p( this );
50 50
51 if ( mediaPlayerState.isFullscreen() ) { 51 if ( mediaPlayerState.isFullscreen() ) {
52 // Clear the background 52 // Clear the background
53 p.setBrush( QBrush( Qt::black ) ); 53 p.setBrush( QBrush( Qt::black ) );
54 return; 54 return;
55 } 55 }
56 56
57 if ( !pe->erased() ) { 57 if ( !pe->erased() ) {
58 // Combine with background and double buffer 58 // Combine with background and double buffer
59 QPixmap pix( pe->rect().size() ); 59 QPixmap pix( pe->rect().size() );
60 QPainter p( &pix ); 60 QPainter p( &pix );
61 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 61 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
62 p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); 62 p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() );
63 paintAllButtons( p ); 63 paintAllButtons( p );
64 QPainter p2( this ); 64 QPainter p2( this );
65 p2.drawPixmap( pe->rect().topLeft(), pix ); 65 p2.drawPixmap( pe->rect().topLeft(), pix );
66 } else { 66 } else {
67 QPainter p( this ); 67 QPainter p( this );
68 paintAllButtons( p ); 68 paintAllButtons( p );
69 } 69 }
70} 70}
71 71
72void MediaWidget::mouseMoveEvent( QMouseEvent *event ) 72MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position )
73{ 73{
74 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) { 74 if ( position.x() <= 0 || position.y() <= 0 ||
75 Button &button = *it; 75 position.x() >= buttonMask.width() ||
76 Command command = button.command; 76 position.y() >= buttonMask.height() )
77 77 return 0;
78 if ( event->state() == QMouseEvent::LeftButton ) { 78
79 // The test to see if the mouse click is inside the button or not 79 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() );
80 bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, command ); 80 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it )
81 81 if ( it->command + 1 == pixelIdx )
82 if ( isOnButton && !button.isHeld ) { 82 return &( *it );
83 button.isHeld = TRUE; 83
84 toggleButton( button ); 84 return 0;
85 switch ( command ) {
86 case VolumeUp:
87 emit moreClicked();
88 return;
89 case VolumeDown:
90 emit lessClicked();
91 return;
92 case Forward:
93 emit forwardClicked();
94 return;
95 case Back:
96 emit backClicked();
97 return;
98 default: break;
99 }
100 } else if ( !isOnButton && button.isHeld ) {
101 button.isHeld = FALSE;
102 toggleButton( button );
103 }
104 } else {
105 if ( button.isHeld ) {
106 button.isHeld = FALSE;
107 if ( button.type != ToggleButton ) {
108 setToggleButton( button, FALSE );
109 }
110 handleCommand( command, button.isDown );
111 }
112 }
113 }
114} 85}
115 86
116void MediaWidget::mousePressEvent( QMouseEvent *event ) 87void MediaWidget::mousePressEvent( QMouseEvent *event )
117{ 88{
118 mouseMoveEvent( event ); 89 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
90
91 if ( !button ) {
92 QWidget::mousePressEvent( event );
93 return;
94 }
95
96 switch ( button->command ) {
97 case VolumeUp: emit moreClicked(); return;
98 case VolumeDown: emit lessClicked(); return;
99 case Back: emit backClicked(); return;
100 case Forward: emit forwardClicked(); return;
101 default: break;
102 }
119} 103}
120 104
121void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) 105void MediaWidget::mouseReleaseEvent( QMouseEvent *event )
122{ 106{
123 mouseMoveEvent( event ); 107 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
108
109 if ( !button ) {
110 QWidget::mouseReleaseEvent( event );
111 return;
112 }
113
114 if ( button->type == ToggleButton )
115 toggleButton( *button );
116
117 handleCommand( button->command, button->isDown );
124} 118}
125 119
126void MediaWidget::makeVisible() 120void MediaWidget::makeVisible()
127{ 121{
128} 122}
129 123
130void MediaWidget::handleCommand( Command command, bool buttonDown ) 124void MediaWidget::handleCommand( Command command, bool buttonDown )
131{ 125{
132 switch ( command ) { 126 switch ( command ) {
133 case Play: mediaPlayerState.togglePaused(); 127 case Play: mediaPlayerState.togglePaused(); return;
134 case Stop: mediaPlayerState.setPlaying(FALSE); return; 128 case Stop: mediaPlayerState.setPlaying(FALSE); return;
135 case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; 129 case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return;
136 case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; 130 case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return;
137 case Loop: mediaPlayerState.setLooping( buttonDown ); return; 131 case Loop: mediaPlayerState.setLooping( buttonDown ); return;
138 case VolumeUp: emit moreReleased(); return; 132 case VolumeUp: emit moreReleased(); return;
139 case VolumeDown: emit lessReleased(); return; 133 case VolumeDown: emit lessReleased(); return;
140 case PlayList: mediaPlayerState.setList(); return; 134 case PlayList: mediaPlayerState.setList(); return;
141 case Forward: emit forwardReleased(); return; 135 case Forward: emit forwardReleased(); return;
142 case Back: emit backReleased(); return; 136 case Back: emit backReleased(); return;
143 case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return; 137 case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return;
144 default: assert( false ); 138 default: assert( false );
145 } 139 }
146} 140}
147 141
148bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const 142bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const
149{ 143{
150 return ( position.x() > 0 && position.y() > 0 && 144 return ( position.x() > 0 && position.y() > 0 &&
151 position.x() < buttonMask.width() && 145 position.x() < buttonMask.width() &&
152 position.y() < buttonMask.height() && 146 position.y() < buttonMask.height() &&
153 buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); 147 buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 );
154} 148}
155 149
156void MediaWidget::paintAllButtons( QPainter &p ) 150void MediaWidget::paintAllButtons( QPainter &p )
157{ 151{
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h
index 9042d5b..8031371 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.h
+++ b/noncore/multimedia/opieplayer2/mediawidget.h
@@ -66,49 +66,50 @@ public:
66 66
67 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); 67 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 );
68 virtual ~MediaWidget(); 68 virtual ~MediaWidget();
69 69
70public slots: 70public slots:
71 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; 71 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0;
72 virtual void setLength( long length ) = 0; 72 virtual void setLength( long length ) = 0;
73 virtual void setPlaying( bool playing ) = 0; 73 virtual void setPlaying( bool playing ) = 0;
74 74
75signals: 75signals:
76 void moreReleased(); 76 void moreReleased();
77 void lessReleased(); 77 void lessReleased();
78 void forwardReleased(); 78 void forwardReleased();
79 void backReleased(); 79 void backReleased();
80 void forwardClicked(); 80 void forwardClicked();
81 void backClicked(); 81 void backClicked();
82 void moreClicked(); 82 void moreClicked();
83 void lessClicked(); 83 void lessClicked();
84 84
85protected: 85protected:
86 virtual void closeEvent( QCloseEvent * ); 86 virtual void closeEvent( QCloseEvent * );
87 87
88 virtual void paintEvent( QPaintEvent *pe ); 88 virtual void paintEvent( QPaintEvent *pe );
89 89
90 virtual void mouseMoveEvent( QMouseEvent *event ); 90 Button *buttonAt( const QPoint &position );
91
91 virtual void mousePressEvent( QMouseEvent *event ); 92 virtual void mousePressEvent( QMouseEvent *event );
92 virtual void mouseReleaseEvent( QMouseEvent *event ); 93 virtual void mouseReleaseEvent( QMouseEvent *event );
93 94
94 virtual void makeVisible(); 95 virtual void makeVisible();
95 96
96 void handleCommand( Command command, bool buttonDown ); 97 void handleCommand( Command command, bool buttonDown );
97 98
98 bool isOverButton( const QPoint &position, int buttonId ) const; 99 bool isOverButton( const QPoint &position, int buttonId ) const;
99 100
100 void paintAllButtons( QPainter &p ); 101 void paintAllButtons( QPainter &p );
101 void paintButton( const Button &button ); 102 void paintButton( const Button &button );
102 void paintButton( QPainter &p, const Button &button ); 103 void paintButton( QPainter &p, const Button &button );
103 104
104 void setToggleButton( Button &button, bool down ); 105 void setToggleButton( Button &button, bool down );
105 void setToggleButton( Command command, bool down ); 106 void setToggleButton( Command command, bool down );
106 void toggleButton( Button &button ); 107 void toggleButton( Button &button );
107 108
108 MediaPlayerState &mediaPlayerState; 109 MediaPlayerState &mediaPlayerState;
109 PlayListWidget &playList; 110 PlayListWidget &playList;
110 111
111 ButtonVector buttons; 112 ButtonVector buttons;
112 113
113 QImage buttonMask; 114 QImage buttonMask;
114 115