summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-02 18:01:00 (UTC)
committer simon <simon>2002-12-02 18:01:00 (UTC)
commit41fe383fe8b840de6dc0bcd47cd29b0d68bf760a (patch) (unidiff)
tree238a6bc98e657ed32d4d71895265d8512013bb14
parentc31f9b59dba873739494fcd9916c7cb9120ce1d9 (diff)
downloadopie-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
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp53
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.h9
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
@@ -75,5 +75,5 @@ MediaButton audioButtons[] = {
75}; 75};
76 76
77const char *skin_mask_file_names[10] = { 77const char * const skin_mask_file_names[10] = {
78 "play", "stop", "next", "prev", "up", 78 "play", "stop", "next", "prev", "up",
79 "down", "loop", "playlist", "forward", "back" 79 "down", "loop", "playlist", "forward", "back"
@@ -104,10 +104,10 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
104 104
105 QString skinPath = "opieplayer2/skins/" + skin; 105 QString skinPath = "opieplayer2/skins/" + skin;
106 pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); 106 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) );
107 imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); 107 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) );
108 imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); 108 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) );
109 109
110 imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); 110 imgButtonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 );
111 imgButtonMask->fill( 0 ); 111 imgButtonMask.fill( 0 );
112 112
113 for ( int i = 0; i < 10; i++ ) { 113 for ( int i = 0; i < 10; i++ ) {
@@ -117,8 +117,8 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
117 if ( !masks[i]->isNull() ) { 117 if ( !masks[i]->isNull() ) {
118 QImage imgMask = masks[i]->convertToImage(); 118 QImage imgMask = masks[i]->convertToImage();
119 uchar **dest = imgButtonMask->jumpTable(); 119 uchar **dest = imgButtonMask.jumpTable();
120 for ( int y = 0; y < imgUp->height(); y++ ) { 120 for ( int y = 0; y < imgUp.height(); y++ ) {
121 uchar *line = dest[y]; 121 uchar *line = dest[y];
122 for ( int x = 0; x < imgUp->width(); x++ ) 122 for ( int x = 0; x < imgUp.width(); x++ )
123 if ( !qRed( imgMask.pixel( x, y ) ) ) 123 if ( !qRed( imgMask.pixel( x, y ) ) )
124 line[x] = i + 1; 124 line[x] = i + 1;
@@ -133,5 +133,5 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
133 } 133 }
134 134
135 setBackgroundPixmap( *pixBg ); 135 setBackgroundPixmap( pixBg );
136 136
137 songInfo.setFocusPolicy( QWidget::NoFocus ); 137 songInfo.setFocusPolicy( QWidget::NoFocus );
@@ -146,5 +146,5 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
146 slider.setMaxValue( 1 ); 146 slider.setMaxValue( 1 );
147 slider.setFocusPolicy( QWidget::NoFocus ); 147 slider.setFocusPolicy( QWidget::NoFocus );
148 slider.setBackgroundPixmap( *pixBg ); 148 slider.setBackgroundPixmap( pixBg );
149 149
150// Config cofg("qpe"); 150// Config cofg("qpe");
@@ -186,8 +186,4 @@ AudioWidget::~AudioWidget() {
186 delete buttonPixDown[i]; 186 delete buttonPixDown[i];
187 } 187 }
188 delete pixBg;
189 delete imgUp;
190 delete imgDn;
191 delete imgButtonMask;
192 for ( int i = 0; i < 10; i++ ) { 188 for ( int i = 0; i < 10; i++ ) {
193 delete masks[i]; 189 delete masks[i];
@@ -198,10 +194,10 @@ AudioWidget::~AudioWidget() {
198namespace { 194namespace {
199 195
200QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 196QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
201 QPixmap pix( img.width(), img.height() ); 197 QPixmap pix( img.width(), img.height() );
202 QPainter p( &pix ); 198 QPainter p( &pix );
203 p.drawTiledPixmap( pix.rect(), bg, offset ); 199 p.drawTiledPixmap( pix.rect(), bg, offset );
204 p.drawImage( 0, 0, img ); 200 p.drawImage( 0, 0, img );
205 return new QPixmap( pix ); 201 return pix;
206} 202}
207 203
@@ -225,10 +221,10 @@ void AudioWidget::resizeEvent( QResizeEvent * ) {
225 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); 221 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) );
226 222
227 xoff = ( w - imgUp->width() ) / 2; 223 xoff = ( w - imgUp.width() ) / 2;
228 yoff = (( h - imgUp->height() ) / 2) - 10; 224 yoff = (( h - imgUp.height() ) / 2) - 10;
229 QPoint p( xoff, yoff ); 225 QPoint p( xoff, yoff );
230 226
231 QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); 227 QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p );
232 QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); 228 QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p );
233 229
234 for ( int i = 0; i < 10; i++ ) { 230 for ( int i = 0; i < 10; i++ ) {
@@ -236,11 +232,8 @@ void AudioWidget::resizeEvent( QResizeEvent * ) {
236 delete buttonPixUp[i]; 232 delete buttonPixUp[i];
237 delete buttonPixDown[i]; 233 delete buttonPixDown[i];
238 buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); 234 buttonPixUp[i] = maskPixToMask( pixUp, *masks[i] );
239 buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); 235 buttonPixDown[i] = maskPixToMask( pixDn, *masks[i] );
240 } 236 }
241 } 237 }
242
243 delete pixUp;
244 delete pixDn;
245} 238}
246 239
@@ -398,7 +391,7 @@ void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
398 int y = event->pos().y() - yoff; 391 int y = event->pos().y() - yoff;
399 392
400 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() 393 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask.width()
401 && y < imgButtonMask->height() 394 && y < imgButtonMask.height()
402 && imgButtonMask->pixelIndex( x, y ) == i + 1 ); 395 && imgButtonMask.pixelIndex( x, y ) == i + 1 );
403 396
404 if ( isOnButton && !audioButtons[i].isHeld ) { 397 if ( isOnButton && !audioButtons[i].isHeld ) {
@@ -482,5 +475,5 @@ void AudioWidget::paintEvent( QPaintEvent * pe ) {
482 QPainter p( &pix ); 475 QPainter p( &pix );
483 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 476 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
484 p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); 477 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() );
485 for ( int i = 0; i < numButtons; i++ ) 478 for ( int i = 0; i < numButtons; i++ )
486 paintButton( &p, i ); 479 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
@@ -43,4 +43,5 @@
43#include <qframe.h> 43#include <qframe.h>
44#include <qlineedit.h> 44#include <qlineedit.h>
45#include <qimage.h>
45 46
46#include <opie/oticker.h> 47#include <opie/oticker.h>
@@ -114,8 +115,8 @@ private:
114 int skipDirection; 115 int skipDirection;
115 QString skin; 116 QString skin;
116 QPixmap *pixBg; 117 QPixmap pixBg;
117 QImage *imgUp; 118 QImage imgUp;
118 QImage *imgDn; 119 QImage imgDn;
119 QImage *imgButtonMask; 120 QImage imgButtonMask;
120 QBitmap *masks[10]; 121 QBitmap *masks[10];
121 QPixmap *buttonPixUp[10]; 122 QPixmap *buttonPixUp[10];