summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-11 01:24:05 (UTC)
committer simon <simon>2002-12-11 01:24:05 (UTC)
commit3ec7f32d0924c737664a6ad4dfb43dc3c20605d0 (patch) (unidiff)
treebb9a9dcef582754293be5e1f7367c64e178c8243
parentd67ad1a6ef93d358beab268153cf2b0694e5f633 (diff)
downloadopie-3ec7f32d0924c737664a6ad4dfb43dc3c20605d0.zip
opie-3ec7f32d0924c737664a6ad4dfb43dc3c20605d0.tar.gz
opie-3ec7f32d0924c737664a6ad4dfb43dc3c20605d0.tar.bz2
- make more use of the Resource::* api for loading the data
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp
index c9d7db8..865ff91 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.cpp
+++ b/noncore/multimedia/opieplayer2/mediawidget.cpp
@@ -11,162 +11,162 @@
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23 23
24#include "mediawidget.h" 24#include "mediawidget.h"
25#include "playlistwidget.h" 25#include "playlistwidget.h"
26 26
27#include <qpe/config.h> 27#include <qpe/config.h>
28#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
29 29
30MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) 30MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name )
31 : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) 31 : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList )
32{ 32{
33 connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), 33 connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ),
34 this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); 34 this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) );
35 connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), 35 connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ),
36 this, SLOT( setLength( long ) ) ); 36 this, SLOT( setLength( long ) ) );
37 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), 37 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ),
38 this, SLOT( setPlaying( bool ) ) ); 38 this, SLOT( setPlaying( bool ) ) );
39} 39}
40 40
41MediaWidget::~MediaWidget() 41MediaWidget::~MediaWidget()
42{ 42{
43} 43}
44 44
45void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, 45void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount,
46 const QString &imagePrefix, const QSize &buttonAreaSize ) 46 const QString &imagePrefix, const QSize &buttonAreaSize )
47{ 47{
48 buttonMask = QImage( buttonAreaSize, 8, 255 ); 48 buttonMask = QImage( buttonAreaSize, 8, 255 );
49 buttonMask.fill( 0 ); 49 buttonMask.fill( 0 );
50 50
51 buttons.clear(); 51 buttons.clear();
52 buttons.reserve( buttonCount ); 52 buttons.reserve( buttonCount );
53 53
54 for ( uint i = 0; i < buttonCount; ++i ) { 54 for ( uint i = 0; i < buttonCount; ++i ) {
55 Button button = setupButton( skinInfo[ i ], imagePrefix ); 55 Button button = setupButton( skinInfo[ i ], imagePrefix );
56 buttons.push_back( button ); 56 buttons.push_back( button );
57 } 57 }
58} 58}
59 59
60MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix ) 60MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix )
61{ 61{
62 Button button; 62 Button button;
63 button.command = buttonInfo.command; 63 button.command = buttonInfo.command;
64 button.type = buttonInfo.type; 64 button.type = buttonInfo.type;
65 65
66 QString fileName = imagePrefix + buttonInfo.fileName + ".png"; 66 QString fileName = imagePrefix + buttonInfo.fileName + ".png";
67 67
68 button.mask = setupButtonMask( button.command, fileName ); 68 button.mask = setupButtonMask( button.command, fileName );
69 69
70 return button; 70 return button;
71} 71}
72 72
73QBitmap MediaWidget::setupButtonMask( const Command &command, const QString &fileName ) 73QBitmap MediaWidget::setupButtonMask( const Command &command, const QString &fileName )
74{ 74{
75 QBitmap mask( fileName ); 75 QBitmap mask( Resource::findPixmap( fileName ) );
76 if ( mask.isNull() ) 76 if ( mask.isNull() )
77 return mask; 77 return mask;
78 78
79 QImage imgMask = mask.convertToImage(); 79 QImage imgMask = mask.convertToImage();
80 uchar **dest = buttonMask.jumpTable(); 80 uchar **dest = buttonMask.jumpTable();
81 for ( int y = 0; y < buttonMask.height(); y++ ) { 81 for ( int y = 0; y < buttonMask.height(); y++ ) {
82 uchar *line = dest[y]; 82 uchar *line = dest[y];
83 for ( int x = 0; x < buttonMask.width(); x++ ) 83 for ( int x = 0; x < buttonMask.width(); x++ )
84 if ( !qRed( imgMask.pixel( x, y ) ) ) 84 if ( !qRed( imgMask.pixel( x, y ) ) )
85 line[x] = command + 1; 85 line[x] = command + 1;
86 } 86 }
87 87
88 return mask; 88 return mask;
89} 89}
90 90
91void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix ) 91void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix )
92{ 92{
93 Config cfg( "OpiePlayer" ); 93 Config cfg( "OpiePlayer" );
94 cfg.setGroup( "Options" ); 94 cfg.setGroup( "Options" );
95 QString skin = cfg.readEntry( "Skin","default" ); 95 QString skin = cfg.readEntry( "Skin","default" );
96 96
97 loadSkin( skinInfo, buttonCount, skin, fileNameInfix ); 97 loadSkin( skinInfo, buttonCount, skin, fileNameInfix );
98} 98}
99 99
100void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix ) 100void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix )
101{ 101{
102 QString skinPath = "opieplayer2/skins/" + name; 102 QString skinPath = "opieplayer2/skins/" + name;
103 backgroundPixmap = QPixmap( Resource::loadPixmap( QString( "%1/background" ).arg( skinPath ) ) ); 103 backgroundPixmap = QPixmap( Resource::loadPixmap( QString( "%1/background" ).arg( skinPath ) ) );
104 buttonUpImage = QImage( Resource::loadImage( QString( "%1/skin%2_up" ).arg( skinPath ).arg( fileNameInfix ) ) ); 104 buttonUpImage = QImage( Resource::loadImage( QString( "%1/skin%2_up" ).arg( skinPath ).arg( fileNameInfix ) ) );
105 buttonDownImage = QImage( Resource::loadImage( QString( "%1/skin%2_down" ).arg( skinPath ).arg( fileNameInfix ) ) ); 105 buttonDownImage = QImage( Resource::loadImage( QString( "%1/skin%2_down" ).arg( skinPath ).arg( fileNameInfix ) ) );
106 106
107 setupButtons( skinInfo, buttonCount, 107 setupButtons( skinInfo, buttonCount,
108 QPEApplication::qpeDir() + "/pics/" + skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( fileNameInfix ), buttonUpImage.size() ); 108 skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( fileNameInfix ), buttonUpImage.size() );
109} 109}
110 110
111void MediaWidget::closeEvent( QCloseEvent * ) 111void MediaWidget::closeEvent( QCloseEvent * )
112{ 112{
113 mediaPlayerState.setList(); 113 mediaPlayerState.setList();
114} 114}
115 115
116void MediaWidget::paintEvent( QPaintEvent *pe ) 116void MediaWidget::paintEvent( QPaintEvent *pe )
117{ 117{
118 QPainter p( this ); 118 QPainter p( this );
119 119
120 if ( mediaPlayerState.isFullscreen() ) { 120 if ( mediaPlayerState.isFullscreen() ) {
121 // Clear the background 121 // Clear the background
122 p.setBrush( QBrush( Qt::black ) ); 122 p.setBrush( QBrush( Qt::black ) );
123 return; 123 return;
124 } 124 }
125 125
126 if ( !pe->erased() ) { 126 if ( !pe->erased() ) {
127 // Combine with background and double buffer 127 // Combine with background and double buffer
128 QPixmap pix( pe->rect().size() ); 128 QPixmap pix( pe->rect().size() );
129 QPainter p( &pix ); 129 QPainter p( &pix );
130 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 130 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
131 p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); 131 p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() );
132 paintAllButtons( p ); 132 paintAllButtons( p );
133 QPainter p2( this ); 133 QPainter p2( this );
134 p2.drawPixmap( pe->rect().topLeft(), pix ); 134 p2.drawPixmap( pe->rect().topLeft(), pix );
135 } else { 135 } else {
136 QPainter p( this ); 136 QPainter p( this );
137 paintAllButtons( p ); 137 paintAllButtons( p );
138 } 138 }
139} 139}
140 140
141MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) 141MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position )
142{ 142{
143 if ( position.x() <= 0 || position.y() <= 0 || 143 if ( position.x() <= 0 || position.y() <= 0 ||
144 position.x() >= buttonMask.width() || 144 position.x() >= buttonMask.width() ||
145 position.y() >= buttonMask.height() ) 145 position.y() >= buttonMask.height() )
146 return 0; 146 return 0;
147 147
148 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); 148 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() );
149 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) 149 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it )
150 if ( it->command + 1 == pixelIdx ) 150 if ( it->command + 1 == pixelIdx )
151 return &( *it ); 151 return &( *it );
152 152
153 return 0; 153 return 0;
154} 154}
155 155
156void MediaWidget::mousePressEvent( QMouseEvent *event ) 156void MediaWidget::mousePressEvent( QMouseEvent *event )
157{ 157{
158 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); 158 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
159 159
160 if ( !button ) { 160 if ( !button ) {
161 QWidget::mousePressEvent( event ); 161 QWidget::mousePressEvent( event );
162 return; 162 return;
163 } 163 }
164 164
165 switch ( button->command ) { 165 switch ( button->command ) {
166 case VolumeUp: emit moreClicked(); return; 166 case VolumeUp: emit moreClicked(); return;
167 case VolumeDown: emit lessClicked(); return; 167 case VolumeDown: emit lessClicked(); return;
168 case Back: emit backClicked(); return; 168 case Back: emit backClicked(); return;
169 case Forward: emit forwardClicked(); return; 169 case Forward: emit forwardClicked(); return;
170 default: break; 170 default: break;
171 } 171 }
172} 172}