summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/mediawidget.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer2/mediawidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp29
1 files changed, 11 insertions, 18 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp
index 563ccf5..880b295 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.cpp
+++ b/noncore/multimedia/opieplayer2/mediawidget.cpp
@@ -39,29 +39,28 @@ MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPla
39} 39}
40 40
41MediaWidget::~MediaWidget() 41MediaWidget::~MediaWidget()
42{ 42{
43} 43}
44 44
45void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, 45void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount,
46 const Skin &skin ) 46 const Skin &skin )
47{ 47{
48 buttonMask = skin.buttonMask( skinInfo, buttonCount ); 48 buttonMask = skin.buttonMask( skinInfo, buttonCount );
49 49
50 buttons.clear(); 50 buttons.clear();
51 buttons.reserve( buttonCount );
52 51
53 for ( uint i = 0; i < buttonCount; ++i ) { 52 for ( uint i = 0; i < buttonCount; ++i ) {
54 Button button = setupButton( skinInfo[ i ], skin ); 53 Button button = setupButton( skinInfo[ i ], skin );
55 buttons.push_back( button ); 54 buttons.append( button );
56 } 55 }
57} 56}
58 57
59MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ) 58MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin )
60{ 59{
61 Button button; 60 Button button;
62 button.command = buttonInfo.command; 61 button.command = buttonInfo.command;
63 button.type = buttonInfo.type; 62 button.type = buttonInfo.type;
64 button.mask = skin.buttonMaskImage( buttonInfo.fileName ); 63 button.mask = skin.buttonMaskImage( buttonInfo.fileName );
65 64
66 return button; 65 return button;
67} 66}
@@ -78,68 +77,62 @@ void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, co
78 backgroundPixmap = skin.backgroundPixmap(); 77 backgroundPixmap = skin.backgroundPixmap();
79 buttonUpImage = skin.buttonUpImage(); 78 buttonUpImage = skin.buttonUpImage();
80 buttonDownImage = skin.buttonDownImage(); 79 buttonDownImage = skin.buttonDownImage();
81 80
82 setupButtons( skinInfo, buttonCount, skin ); 81 setupButtons( skinInfo, buttonCount, skin );
83} 82}
84 83
85void MediaWidget::closeEvent( QCloseEvent * ) 84void MediaWidget::closeEvent( QCloseEvent * )
86{ 85{
87 mediaPlayerState.setList(); 86 mediaPlayerState.setList();
88} 87}
89 88
90void MediaWidget::paintEvent( QPaintEvent *pe ) 89void MediaWidget::paintEvent( QPaintEvent * )
91{ 90{
92 QPainter p( this ); 91 QPainter p( this );
93 92
94 if ( mediaPlayerState.isFullscreen() ) {
95 // Clear the background
96 p.setBrush( QBrush( Qt::black ) );
97 return;
98 }
99
100 QPixmap buffer( size() ); 93 QPixmap buffer( size() );
101 QPainter bufferedPainter( &buffer ); 94 QPainter bufferedPainter( &buffer );
102 bufferedPainter.drawTiledPixmap( rect(), backgroundPixmap, QPoint( 0, 0 ) ); 95 bufferedPainter.drawTiledPixmap( rect(), backgroundPixmap, QPoint( 0, 0 ) );
103 paintAllButtons( bufferedPainter ); 96 paintAllButtons( bufferedPainter );
104 p.drawPixmap( 0, 0, buffer ); 97 p.drawPixmap( 0, 0, buffer );
105} 98}
106 99
107void MediaWidget::resizeEvent( QResizeEvent *e ) 100void MediaWidget::resizeEvent( QResizeEvent *e )
108{ 101{
109 QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, upperLeftOfButtonMask ); 102 QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, upperLeftOfButtonMask );
110 QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, upperLeftOfButtonMask ); 103 QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, upperLeftOfButtonMask );
111 104
112 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) { 105 for ( ButtonVector::Iterator it = buttons.begin(); it != buttons.end(); ++it ) {
113 Button &button = *it; 106 Button &button = *it;
114 107
115 if ( button.mask.isNull() ) 108 if ( button.mask.isNull() )
116 continue; 109 continue;
117 button.pixUp = addMaskToPixmap( pixUp, button.mask ); 110 button.pixUp = addMaskToPixmap( pixUp, button.mask );
118 button.pixDown = addMaskToPixmap( pixDn, button.mask ); 111 button.pixDown = addMaskToPixmap( pixDn, button.mask );
119 } 112 }
120 113
121 QWidget::resizeEvent( e ); 114 QWidget::resizeEvent( e );
122} 115}
123 116
124MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) 117MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position )
125{ 118{
126 if ( position.x() <= 0 || position.y() <= 0 || 119 if ( position.x() <= 0 || position.y() <= 0 ||
127 position.x() >= buttonMask.width() || 120 position.x() >= buttonMask.width() ||
128 position.y() >= buttonMask.height() ) 121 position.y() >= buttonMask.height() )
129 return 0; 122 return 0;
130 123
131 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); 124 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() );
132 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) 125 for ( ButtonVector::Iterator it = buttons.begin(); it != buttons.end(); ++it )
133 if ( it->command + 1 == pixelIdx ) 126 if ( (*it).command + 1 == pixelIdx )
134 return &( *it ); 127 return &( *it );
135 128
136 return 0; 129 return 0;
137} 130}
138 131
139void MediaWidget::mousePressEvent( QMouseEvent *event ) 132void MediaWidget::mousePressEvent( QMouseEvent *event )
140{ 133{
141 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); 134 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
142 135
143 if ( !button ) { 136 if ( !button ) {
144 QWidget::mousePressEvent( event ); 137 QWidget::mousePressEvent( event );
145 return; 138 return;
@@ -184,55 +177,55 @@ void MediaWidget::handleCommand( Command command, bool buttonDown )
184 case VolumeUp: emit moreReleased(); return; 177 case VolumeUp: emit moreReleased(); return;
185 case VolumeDown: emit lessReleased(); return; 178 case VolumeDown: emit lessReleased(); return;
186 case PlayList: mediaPlayerState.setList(); return; 179 case PlayList: mediaPlayerState.setList(); return;
187 case Forward: emit forwardReleased(); return; 180 case Forward: emit forwardReleased(); return;
188 case Back: emit backReleased(); return; 181 case Back: emit backReleased(); return;
189 case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return; 182 case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return;
190 default: assert( false ); 183 default: assert( false );
191 } 184 }
192} 185}
193 186
194bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const 187bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const
195{ 188{
196 return ( position.x() > 0 && position.y() > 0 && 189 return ( position.x() > 0 && position.y() > 0 &&
197 position.x() < buttonMask.width() && 190 position.x() < buttonMask.width() &&
198 position.y() < buttonMask.height() && 191 position.y() < buttonMask.height() &&
199 buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); 192 buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 );
200} 193}
201 194
202void MediaWidget::paintAllButtons( QPainter &p ) 195void MediaWidget::paintAllButtons( QPainter &p )
203{ 196{
204 for ( ButtonVector::const_iterator it = buttons.begin(); 197 for ( ButtonVector::ConstIterator it = buttons.begin();
205 it != buttons.end(); ++it ) 198 it != buttons.end(); ++it )
206 paintButton( p, *it ); 199 paintButton( p, *it );
207} 200}
208 201
209void MediaWidget::paintButton( const Button &button ) 202void MediaWidget::paintButton( const Button &button )
210{ 203{
211 QPainter p( this ); 204 QPainter p( this );
212 paintButton( p, button ); 205 paintButton( p, button );
213} 206}
214 207
215void MediaWidget::paintButton( QPainter &p, const Button &button ) 208void MediaWidget::paintButton( QPainter &p, const Button &button )
216{ 209{
217 if ( button.isDown ) 210 if ( button.isDown )
218 p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); 211 p.drawPixmap( upperLeftOfButtonMask, button.pixDown );
219 else 212 else
220 p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); 213 p.drawPixmap( upperLeftOfButtonMask, button.pixUp );
221} 214}
222 215
223void MediaWidget::setToggleButton( Command command, bool down ) 216void MediaWidget::setToggleButton( Command command, bool down )
224{ 217{
225 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) 218 for ( ButtonVector::Iterator it = buttons.begin(); it != buttons.end(); ++it )
226 if ( it->command == command ) { 219 if ( (*it).command == command ) {
227 setToggleButton( *it, down ); 220 setToggleButton( *it, down );
228 return; 221 return;
229 } 222 }
230} 223}
231 224
232void MediaWidget::setToggleButton( Button &button, bool down ) 225void MediaWidget::setToggleButton( Button &button, bool down )
233{ 226{
234 if ( down != button.isDown ) 227 if ( down != button.isDown )
235 toggleButton( button ); 228 toggleButton( button );
236} 229}
237 230
238void MediaWidget::toggleButton( Button &button ) 231void MediaWidget::toggleButton( Button &button )