summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/mediawidget.cpp
Side-by-side diff
Diffstat (limited to 'noncore/multimedia/opieplayer2/mediawidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp33
1 files changed, 33 insertions, 0 deletions
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
@@ -88,48 +88,65 @@ void MediaWidget::paintEvent( QPaintEvent *pe )
{
QPainter p( this );
if ( mediaPlayerState.isFullscreen() ) {
// Clear the background
p.setBrush( QBrush( Qt::black ) );
return;
}
if ( !pe->erased() ) {
// Combine with background and double buffer
QPixmap pix( pe->rect().size() );
QPainter p( &pix );
p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() );
paintAllButtons( p );
QPainter p2( this );
p2.drawPixmap( pe->rect().topLeft(), pix );
} else {
QPainter p( this );
paintAllButtons( p );
}
}
+void MediaWidget::resizeEvent( QResizeEvent *e )
+{
+ QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, upperLeftOfButtonMask );
+ QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, upperLeftOfButtonMask );
+
+ for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) {
+ Button &button = *it;
+
+ if ( button.mask.isNull() )
+ continue;
+ button.pixUp = addMaskToPixmap( pixUp, button.mask );
+ button.pixDown = addMaskToPixmap( pixDn, button.mask );
+ }
+
+ QWidget::resizeEvent( e );
+}
+
MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position )
{
if ( position.x() <= 0 || position.y() <= 0 ||
position.x() >= buttonMask.width() ||
position.y() >= buttonMask.height() )
return 0;
int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() );
for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it )
if ( it->command + 1 == pixelIdx )
return &( *it );
return 0;
}
void MediaWidget::mousePressEvent( QMouseEvent *event )
{
Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
if ( !button ) {
QWidget::mousePressEvent( event );
return;
}
@@ -209,26 +226,42 @@ void MediaWidget::paintButton( QPainter &p, const Button &button )
}
void MediaWidget::setToggleButton( Command command, bool down )
{
for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it )
if ( it->command == command ) {
setToggleButton( *it, down );
return;
}
}
void MediaWidget::setToggleButton( Button &button, bool down )
{
if ( down != button.isDown )
toggleButton( button );
}
void MediaWidget::toggleButton( Button &button )
{
button.isDown = !button.isDown;
paintButton( button );
}
+QPixmap MediaWidget::combineImageWithBackground( const QImage &image, const QPixmap &background, const QPoint &offset )
+{
+ QPixmap pix( image.size() );
+ QPainter p( &pix );
+ p.drawTiledPixmap( pix.rect(), background, offset );
+ p.drawImage( 0, 0, image );
+ return pix;
+}
+
+QPixmap MediaWidget::addMaskToPixmap( const QPixmap &pix, const QBitmap &mask )
+{
+ QPixmap result( pix );
+ result.setMask( mask );
+ return result;
+}
+
/* vim: et sw=4 ts=4
*/