author | simon <simon> | 2002-12-02 18:01:00 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-02 18:01:00 (UTC) |
commit | 41fe383fe8b840de6dc0bcd47cd29b0d68bf760a (patch) (side-by-side diff) | |
tree | 238a6bc98e657ed32d4d71895265d8512013bb14 /noncore | |
parent | c31f9b59dba873739494fcd9916c7cb9120ce1d9 (diff) | |
download | opie-41fe383fe8b840de6dc0bcd47cd29b0d68bf760a.zip opie-41fe383fe8b840de6dc0bcd47cd29b0d68bf760a.tar.gz opie-41fe383fe8b840de6dc0bcd47cd29b0d68bf760a.tar.bz2 |
- added a missing const
- QImage and QPixmap are value based classes, so use them like that for
a couple of objects. simplifies the code and helps to avoid memory leaks
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 53 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.h | 9 |
2 files changed, 28 insertions, 34 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 5cdfbf2..46d374d 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp @@ -69,17 +69,17 @@ MediaButton audioButtons[] = { { FALSE, FALSE, FALSE }, // volume up { FALSE, FALSE, FALSE }, // volume down { TRUE, FALSE, FALSE }, // repeat/loop { FALSE, FALSE, FALSE }, // playlist { FALSE, FALSE, FALSE }, // forward { FALSE, FALSE, FALSE } // back }; -const char *skin_mask_file_names[10] = { +const char * const skin_mask_file_names[10] = { "play", "stop", "next", "prev", "up", "down", "loop", "playlist", "forward", "back" }; static void changeTextColor( QWidget *w ) { QPalette p = w->palette(); p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); @@ -98,59 +98,59 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : Config cfg("OpiePlayer"); cfg.setGroup("Options"); skin = cfg.readEntry("Skin","default"); //skin = "scaleTest"; // color of background, frame, degree of transparency QString skinPath = "opieplayer2/skins/" + skin; - pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); - imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); - imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); + pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); + imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); + imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); - imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); - imgButtonMask->fill( 0 ); + imgButtonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); + imgButtonMask.fill( 0 ); for ( int i = 0; i < 10; i++ ) { QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); masks[i] = new QBitmap( filename ); if ( !masks[i]->isNull() ) { QImage imgMask = masks[i]->convertToImage(); - uchar **dest = imgButtonMask->jumpTable(); - for ( int y = 0; y < imgUp->height(); y++ ) { + uchar **dest = imgButtonMask.jumpTable(); + for ( int y = 0; y < imgUp.height(); y++ ) { uchar *line = dest[y]; - for ( int x = 0; x < imgUp->width(); x++ ) + for ( int x = 0; x < imgUp.width(); x++ ) if ( !qRed( imgMask.pixel( x, y ) ) ) line[x] = i + 1; } } } for ( int i = 0; i < 10; i++ ) { buttonPixUp[i] = 0l; buttonPixDown[i] = 0l; } - setBackgroundPixmap( *pixBg ); + setBackgroundPixmap( pixBg ); songInfo.setFocusPolicy( QWidget::NoFocus ); // changeTextColor( &songInfo ); // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); // songInfo.setFrameStyle( QFrame::NoFrame); songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); // songInfo.setForegroundColor(Qt::white); slider.setFixedHeight( 20 ); slider.setMinValue( 0 ); slider.setMaxValue( 1 ); slider.setFocusPolicy( QWidget::NoFocus ); - slider.setBackgroundPixmap( *pixBg ); + slider.setBackgroundPixmap( pixBg ); // Config cofg("qpe"); // cofg.setGroup("Appearance"); // QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); time.setFocusPolicy( QWidget::NoFocus ); time.setAlignment( Qt::AlignCenter ); @@ -180,34 +180,30 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : } AudioWidget::~AudioWidget() { for ( int i = 0; i < 10; i++ ) { delete buttonPixUp[i]; delete buttonPixDown[i]; } - delete pixBg; - delete imgUp; - delete imgDn; - delete imgButtonMask; for ( int i = 0; i < 10; i++ ) { delete masks[i]; } // mediaPlayerState->setPlaying(false); } namespace { -QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { +QPixmap combineImageWithBackground( 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 ); + return pix; } QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { QPixmap *pixmap = new QPixmap( pix ); pixmap->setMask( mask ); return pixmap; } @@ -219,34 +215,31 @@ void AudioWidget::resizeEvent( QResizeEvent * ) { int w = width(); songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); slider.setFixedWidth( w - 110 ); slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); slider.setBackgroundOrigin( QWidget::ParentOrigin ); time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); - xoff = ( w - imgUp->width() ) / 2; - yoff = (( h - imgUp->height() ) / 2) - 10; + xoff = ( w - imgUp.width() ) / 2; + yoff = (( h - imgUp.height() ) / 2) - 10; QPoint p( xoff, yoff ); - QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); - QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); + QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p ); + QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p ); for ( int i = 0; i < 10; i++ ) { if ( !masks[i]->isNull() ) { delete buttonPixUp[i]; delete buttonPixDown[i]; - buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); - buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); + buttonPixUp[i] = maskPixToMask( pixUp, *masks[i] ); + buttonPixDown[i] = maskPixToMask( pixDn, *masks[i] ); } } - - delete pixUp; - delete pixDn; } static bool audioSliderBeingMoved = FALSE; void AudioWidget::sliderPressed() { audioSliderBeingMoved = TRUE; } @@ -392,19 +385,19 @@ void AudioWidget::timerEvent( QTimerEvent * ) { void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { for ( int i = 0; i < numButtons; i++ ) { if ( event->state() == QMouseEvent::LeftButton ) { // The test to see if the mouse click is inside the button or not int x = event->pos().x() - xoff; int y = event->pos().y() - yoff; - bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() - && y < imgButtonMask->height() - && imgButtonMask->pixelIndex( x, y ) == i + 1 ); + bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask.width() + && y < imgButtonMask.height() + && imgButtonMask.pixelIndex( x, y ) == i + 1 ); if ( isOnButton && !audioButtons[i].isHeld ) { audioButtons[i].isHeld = TRUE; toggleButton(i); switch (i) { case AudioVolumeUp: emit moreClicked(); return; @@ -476,17 +469,17 @@ void AudioWidget::closeEvent( QCloseEvent* ) { void AudioWidget::paintEvent( QPaintEvent * pe ) { 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(), *pixBg, pe->rect().topLeft() ); + p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); for ( int i = 0; i < numButtons; i++ ) paintButton( &p, i ); QPainter p2( this ); p2.drawPixmap( pe->rect().topLeft(), pix ); } else { QPainter p( this ); for ( int i = 0; i < numButtons; i++ ) paintButton( &p, i ); diff --git a/noncore/multimedia/opieplayer2/audiowidget.h b/noncore/multimedia/opieplayer2/audiowidget.h index 7cb1d79..54adb36 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.h +++ b/noncore/multimedia/opieplayer2/audiowidget.h @@ -37,16 +37,17 @@ #include <qwidget.h> #include <qpainter.h> #include <qdrawutil.h> #include <qpixmap.h> #include <qstring.h> #include <qslider.h> #include <qframe.h> #include <qlineedit.h> +#include <qimage.h> #include <opie/oticker.h> class QPixmap; namespace { enum AudioButtons { @@ -108,20 +109,20 @@ private slots: void skipBack(); void stopSkip(); private: void toggleButton( int ); void setToggleButton( int, bool ); void paintButton( QPainter *p, int i ); int skipDirection; QString skin; - QPixmap *pixBg; - QImage *imgUp; - QImage *imgDn; - QImage *imgButtonMask; + QPixmap pixBg; + QImage imgUp; + QImage imgDn; + QImage imgButtonMask; QBitmap *masks[10]; QPixmap *buttonPixUp[10]; QPixmap *buttonPixDown[10]; QPixmap *pixmaps[4]; OTicker songInfo; QSlider slider; QLineEdit time; |