author | simon <simon> | 2002-12-11 13:46:15 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 13:46:15 (UTC) |
commit | 2b3c450378c1da0a2175c91d652ce2eae5614ff8 (patch) (side-by-side diff) | |
tree | 4c11c70dbf487725f6e443f5db4c5a0a0c964e61 | |
parent | cd5e96b40ceae9158e5cb01e71769e895ea7a3c1 (diff) | |
download | opie-2b3c450378c1da0a2175c91d652ce2eae5614ff8.zip opie-2b3c450378c1da0a2175c91d652ce2eae5614ff8.tar.gz opie-2b3c450378c1da0a2175c91d652ce2eae5614ff8.tar.bz2 |
- less code duplication. code from resizeEvent is now shared as well as
the image composing method and the pixmap mask helper
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 13 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 33 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 5 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/videowidget.cpp | 32 |
4 files changed, 42 insertions, 41 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index bb686f1..bb07882 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp @@ -131,5 +131,5 @@ QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) { }; -void AudioWidget::resizeEvent( QResizeEvent * ) { +void AudioWidget::resizeEvent( QResizeEvent *e ) { int h = height(); int w = width(); @@ -143,15 +143,6 @@ void AudioWidget::resizeEvent( QResizeEvent * ) { upperLeftOfButtonMask.rx() = ( w - buttonUpImage.width() ) / 2; upperLeftOfButtonMask.ry() = (( h - buttonUpImage.height() ) / 2) - 10; - QPoint p = upperLeftOfButtonMask; - QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, p ); - QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, p ); - - for ( uint i = 0; i < buttons.size(); i++ ) { - if ( !buttons[i].mask.isNull() ) { - buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask ); - buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask ); - } - } + MediaWidget::resizeEvent( e ); } 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 @@ -110,4 +110,21 @@ void MediaWidget::paintEvent( QPaintEvent *pe ) } +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 ) { @@ -231,4 +248,20 @@ void MediaWidget::toggleButton( Button &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 */ diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 9f13677..4599637 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h @@ -113,4 +113,6 @@ protected: virtual void paintEvent( QPaintEvent *pe ); + virtual void resizeEvent( QResizeEvent *e ); + Button *buttonAt( const QPoint &position ); @@ -144,4 +146,7 @@ protected: QImage buttonUpImage; QImage buttonDownImage; + + static QPixmap combineImageWithBackground( const QImage &background, const QPixmap &pixmap, const QPoint &offset ); + static QPixmap addMaskToPixmap( const QPixmap &pix, const QBitmap &mask ); }; diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp index bc47717..a8ff540 100644 --- a/noncore/multimedia/opieplayer2/videowidget.cpp +++ b/noncore/multimedia/opieplayer2/videowidget.cpp @@ -100,19 +100,5 @@ VideoWidget::~VideoWidget() } -QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { - QPixmap pix( img.width(), img.height() ); - QPainter p( &pix ); - p.drawTiledPixmap( pix.rect(), bg, offset ); - p.drawImage( 0, 0, img ); - return new QPixmap( pix ); -} - -QPixmap maskVPixToMask( QPixmap pix, QBitmap mask ) { - QPixmap pixmap( pix ); - pixmap.setMask( mask ); - return pixmap; -} - -void VideoWidget::resizeEvent( QResizeEvent * ) { +void VideoWidget::resizeEvent( QResizeEvent *e ) { int h = height(); int w = width(); @@ -131,20 +117,6 @@ void VideoWidget::resizeEvent( QResizeEvent * ) { else upperLeftOfButtonMask.ry() = 185;//(( Vh - imgUp->height() ) / 2) - 10; - QPoint p = upperLeftOfButtonMask; - - QPixmap *pixUp = combineVImageWithBackground( buttonUpImage, backgroundPixmap, p ); - QPixmap *pixDn = combineVImageWithBackground( buttonDownImage, backgroundPixmap, p ); - - for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) { - Button &button = *it; - - if ( !button.mask.isNull() ) { - button.pixUp = maskVPixToMask( *pixUp, button.mask ); - button.pixDown = maskVPixToMask( *pixDn, button.mask ); - } - } - delete pixUp; - delete pixDn; + MediaWidget::resizeEvent( e ); } |