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
@@ -73,9 +73,9 @@ MediaButton audioButtons[] = {
73 { FALSE, FALSE, FALSE }, // forward 73 { FALSE, FALSE, FALSE }, // forward
74 { FALSE, FALSE, FALSE } // back 74 { FALSE, FALSE, FALSE } // back
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"
80}; 80};
81 81
@@ -102,25 +102,25 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
102 //skin = "scaleTest"; 102 //skin = "scaleTest";
103 // color of background, frame, degree of transparency 103 // color of background, frame, degree of transparency
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++ ) {
114 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); 114 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" );
115 masks[i] = new QBitmap( filename ); 115 masks[i] = new QBitmap( filename );
116 116
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;
125 } 125 }
126 } 126 }
@@ -131,9 +131,9 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
131 buttonPixUp[i] = 0l; 131 buttonPixUp[i] = 0l;
132 buttonPixDown[i] = 0l; 132 buttonPixDown[i] = 0l;
133 } 133 }
134 134
135 setBackgroundPixmap( *pixBg ); 135 setBackgroundPixmap( pixBg );
136 136
137 songInfo.setFocusPolicy( QWidget::NoFocus ); 137 songInfo.setFocusPolicy( QWidget::NoFocus );
138// changeTextColor( &songInfo ); 138// changeTextColor( &songInfo );
139// songInfo.setBackgroundColor( QColor( 167, 212, 167 )); 139// songInfo.setBackgroundColor( QColor( 167, 212, 167 ));
@@ -144,9 +144,9 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
144 slider.setFixedHeight( 20 ); 144 slider.setFixedHeight( 20 );
145 slider.setMinValue( 0 ); 145 slider.setMinValue( 0 );
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");
151// cofg.setGroup("Appearance"); 151// cofg.setGroup("Appearance");
152// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); 152// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) );
@@ -184,26 +184,22 @@ AudioWidget::~AudioWidget() {
184 for ( int i = 0; i < 10; i++ ) { 184 for ( int i = 0; i < 10; i++ ) {
185 delete buttonPixUp[i]; 185 delete buttonPixUp[i];
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];
194 } 190 }
195// mediaPlayerState->setPlaying(false); 191// mediaPlayerState->setPlaying(false);
196} 192}
197 193
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
208 204
209QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { 205QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) {
@@ -223,26 +219,23 @@ void AudioWidget::resizeEvent( QResizeEvent * ) {
223 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); 219 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) );
224 slider.setBackgroundOrigin( QWidget::ParentOrigin ); 220 slider.setBackgroundOrigin( QWidget::ParentOrigin );
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++ ) {
235 if ( !masks[i]->isNull() ) { 231 if ( !masks[i]->isNull() ) {
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
247static bool audioSliderBeingMoved = FALSE; 240static bool audioSliderBeingMoved = FALSE;
248 241
@@ -396,11 +389,11 @@ void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
396 // The test to see if the mouse click is inside the button or not 389 // The test to see if the mouse click is inside the button or not
397 int x = event->pos().x() - xoff; 390 int x = event->pos().x() - xoff;
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 ) {
405 audioButtons[i].isHeld = TRUE; 398 audioButtons[i].isHeld = TRUE;
406 toggleButton(i); 399 toggleButton(i);
@@ -480,9 +473,9 @@ void AudioWidget::paintEvent( QPaintEvent * pe ) {
480 // Combine with background and double buffer 473 // Combine with background and double buffer
481 QPixmap pix( pe->rect().size() ); 474 QPixmap pix( pe->rect().size() );
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 );
487 QPainter p2( this ); 480 QPainter p2( this );
488 p2.drawPixmap( pe->rect().topLeft(), pix ); 481 p2.drawPixmap( pe->rect().topLeft(), pix );
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
@@ -41,8 +41,9 @@
41#include <qstring.h> 41#include <qstring.h>
42#include <qslider.h> 42#include <qslider.h>
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>
47 48
48class QPixmap; 49class QPixmap;
@@ -112,12 +113,12 @@ private:
112 void setToggleButton( int, bool ); 113 void setToggleButton( int, bool );
113 void paintButton( QPainter *p, int i ); 114 void paintButton( QPainter *p, int i );
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];
122 QPixmap *buttonPixDown[10]; 123 QPixmap *buttonPixDown[10];
123 124