Diffstat (limited to 'noncore/multimedia/opieplayer2/mediawidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 78 |
1 files changed, 36 insertions, 42 deletions
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 | |||
@@ -69,58 +69,52 @@ void MediaWidget::paintEvent( QPaintEvent *pe ) | |||
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | void MediaWidget::mouseMoveEvent( QMouseEvent *event ) | 72 | MediaWidget::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 | return 0; | ||
77 | 78 | ||
78 | if ( event->state() == QMouseEvent::LeftButton ) { | 79 | int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); |
79 | // The test to see if the mouse click is inside the button or not | 80 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) |
80 | bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, command ); | 81 | if ( it->command + 1 == pixelIdx ) |
82 | return &( *it ); | ||
81 | 83 | ||
82 | if ( isOnButton && !button.isHeld ) { | 84 | return 0; |
83 | button.isHeld = TRUE; | ||
84 | toggleButton( button ); | ||
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 | ||
116 | void MediaWidget::mousePressEvent( QMouseEvent *event ) | 87 | void 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 | ||
121 | void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) | 105 | void 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 | ||
126 | void MediaWidget::makeVisible() | 120 | void MediaWidget::makeVisible() |
@@ -130,7 +124,7 @@ void MediaWidget::makeVisible() | |||
130 | void MediaWidget::handleCommand( Command command, bool buttonDown ) | 124 | void 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; |