summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-11 11:52:24 (UTC)
committer simon <simon>2002-12-11 11:52:24 (UTC)
commit9ae7f1a1b5fbadf4ea40f8d7bf07a637299a091a (patch) (unidiff)
tree08bfee61215df1af5c0a9a7e2068ea3f4fb8045c
parent03ac4af4d6014bbd46b12d5fe89ee2cc73941080 (diff)
downloadopie-9ae7f1a1b5fbadf4ea40f8d7bf07a637299a091a.zip
opie-9ae7f1a1b5fbadf4ea40f8d7bf07a637299a091a.tar.gz
opie-9ae7f1a1b5fbadf4ea40f8d7bf07a637299a091a.tar.bz2
- less qimage<>qpixmap conversions
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp
index 865ff91..70ef8d9 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.cpp
+++ b/noncore/multimedia/opieplayer2/mediawidget.cpp
@@ -1,263 +1,264 @@
1/* 1/*
2 Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> 2 Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
3 (C) 2002 Max Reiss <harlekin@handhelds.org> 3 (C) 2002 Max Reiss <harlekin@handhelds.org>
4 (C) 2002 L. Potter <ljp@llornkcor.com> 4 (C) 2002 L. Potter <ljp@llornkcor.com>
5 (C) 2002 Holger Freyther <zecke@handhelds.org> 5 (C) 2002 Holger Freyther <zecke@handhelds.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
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( Resource::findPixmap( fileName ) ); 75 QImage imgMask( Resource::findPixmap( fileName ) );
76 if ( mask.isNull() ) 76 if ( imgMask.isNull() )
77 return mask; 77 return QBitmap();
78 78
79 QImage imgMask = mask.convertToImage();
80 uchar **dest = buttonMask.jumpTable(); 79 uchar **dest = buttonMask.jumpTable();
81 for ( int y = 0; y < buttonMask.height(); y++ ) { 80 for ( int y = 0; y < buttonMask.height(); y++ ) {
82 uchar *line = dest[y]; 81 uchar *line = dest[y];
83 for ( int x = 0; x < buttonMask.width(); x++ ) 82 for ( int x = 0; x < buttonMask.width(); x++ )
84 if ( !qRed( imgMask.pixel( x, y ) ) ) 83 if ( !qRed( imgMask.pixel( x, y ) ) )
85 line[x] = command + 1; 84 line[x] = command + 1;
86 } 85 }
87 86
88 return mask; 87 // ### grmbl qt2. use constructor when switching to qt3.
88 QBitmap bm; bm = imgMask;
89 return bm;
89} 90}
90 91
91void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix ) 92void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix )
92{ 93{
93 Config cfg( "OpiePlayer" ); 94 Config cfg( "OpiePlayer" );
94 cfg.setGroup( "Options" ); 95 cfg.setGroup( "Options" );
95 QString skin = cfg.readEntry( "Skin","default" ); 96 QString skin = cfg.readEntry( "Skin","default" );
96 97
97 loadSkin( skinInfo, buttonCount, skin, fileNameInfix ); 98 loadSkin( skinInfo, buttonCount, skin, fileNameInfix );
98} 99}
99 100
100void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix ) 101void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix )
101{ 102{
102 QString skinPath = "opieplayer2/skins/" + name; 103 QString skinPath = "opieplayer2/skins/" + name;
103 backgroundPixmap = QPixmap( Resource::loadPixmap( QString( "%1/background" ).arg( skinPath ) ) ); 104 backgroundPixmap = QPixmap( Resource::loadPixmap( QString( "%1/background" ).arg( skinPath ) ) );
104 buttonUpImage = QImage( Resource::loadImage( QString( "%1/skin%2_up" ).arg( skinPath ).arg( fileNameInfix ) ) ); 105 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 ) ) ); 106 buttonDownImage = QImage( Resource::loadImage( QString( "%1/skin%2_down" ).arg( skinPath ).arg( fileNameInfix ) ) );
106 107
107 setupButtons( skinInfo, buttonCount, 108 setupButtons( skinInfo, buttonCount,
108 skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( fileNameInfix ), buttonUpImage.size() ); 109 skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( fileNameInfix ), buttonUpImage.size() );
109} 110}
110 111
111void MediaWidget::closeEvent( QCloseEvent * ) 112void MediaWidget::closeEvent( QCloseEvent * )
112{ 113{
113 mediaPlayerState.setList(); 114 mediaPlayerState.setList();
114} 115}
115 116
116void MediaWidget::paintEvent( QPaintEvent *pe ) 117void MediaWidget::paintEvent( QPaintEvent *pe )
117{ 118{
118 QPainter p( this ); 119 QPainter p( this );
119 120
120 if ( mediaPlayerState.isFullscreen() ) { 121 if ( mediaPlayerState.isFullscreen() ) {
121 // Clear the background 122 // Clear the background
122 p.setBrush( QBrush( Qt::black ) ); 123 p.setBrush( QBrush( Qt::black ) );
123 return; 124 return;
124 } 125 }
125 126
126 if ( !pe->erased() ) { 127 if ( !pe->erased() ) {
127 // Combine with background and double buffer 128 // Combine with background and double buffer
128 QPixmap pix( pe->rect().size() ); 129 QPixmap pix( pe->rect().size() );
129 QPainter p( &pix ); 130 QPainter p( &pix );
130 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 131 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
131 p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); 132 p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() );
132 paintAllButtons( p ); 133 paintAllButtons( p );
133 QPainter p2( this ); 134 QPainter p2( this );
134 p2.drawPixmap( pe->rect().topLeft(), pix ); 135 p2.drawPixmap( pe->rect().topLeft(), pix );
135 } else { 136 } else {
136 QPainter p( this ); 137 QPainter p( this );
137 paintAllButtons( p ); 138 paintAllButtons( p );
138 } 139 }
139} 140}
140 141
141MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) 142MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position )
142{ 143{
143 if ( position.x() <= 0 || position.y() <= 0 || 144 if ( position.x() <= 0 || position.y() <= 0 ||
144 position.x() >= buttonMask.width() || 145 position.x() >= buttonMask.width() ||
145 position.y() >= buttonMask.height() ) 146 position.y() >= buttonMask.height() )
146 return 0; 147 return 0;
147 148
148 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); 149 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() );
149 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) 150 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it )
150 if ( it->command + 1 == pixelIdx ) 151 if ( it->command + 1 == pixelIdx )
151 return &( *it ); 152 return &( *it );
152 153
153 return 0; 154 return 0;
154} 155}
155 156
156void MediaWidget::mousePressEvent( QMouseEvent *event ) 157void MediaWidget::mousePressEvent( QMouseEvent *event )
157{ 158{
158 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); 159 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
159 160
160 if ( !button ) { 161 if ( !button ) {
161 QWidget::mousePressEvent( event ); 162 QWidget::mousePressEvent( event );
162 return; 163 return;
163 } 164 }
164 165
165 switch ( button->command ) { 166 switch ( button->command ) {
166 case VolumeUp: emit moreClicked(); return; 167 case VolumeUp: emit moreClicked(); return;
167 case VolumeDown: emit lessClicked(); return; 168 case VolumeDown: emit lessClicked(); return;
168 case Back: emit backClicked(); return; 169 case Back: emit backClicked(); return;
169 case Forward: emit forwardClicked(); return; 170 case Forward: emit forwardClicked(); return;
170 default: break; 171 default: break;
171 } 172 }
172} 173}
173 174
174void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) 175void MediaWidget::mouseReleaseEvent( QMouseEvent *event )
175{ 176{
176 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); 177 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
177 178
178 if ( !button ) { 179 if ( !button ) {
179 QWidget::mouseReleaseEvent( event ); 180 QWidget::mouseReleaseEvent( event );
180 return; 181 return;
181 } 182 }
182 183
183 if ( button->type == ToggleButton ) 184 if ( button->type == ToggleButton )
184 toggleButton( *button ); 185 toggleButton( *button );
185 186
186 handleCommand( button->command, button->isDown ); 187 handleCommand( button->command, button->isDown );
187} 188}
188 189
189void MediaWidget::makeVisible() 190void MediaWidget::makeVisible()
190{ 191{
191} 192}
192 193
193void MediaWidget::handleCommand( Command command, bool buttonDown ) 194void MediaWidget::handleCommand( Command command, bool buttonDown )
194{ 195{
195 switch ( command ) { 196 switch ( command ) {
196 case Play: mediaPlayerState.togglePaused(); return; 197 case Play: mediaPlayerState.togglePaused(); return;
197 case Stop: mediaPlayerState.setPlaying(FALSE); return; 198 case Stop: mediaPlayerState.setPlaying(FALSE); return;
198 case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; 199 case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return;
199 case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; 200 case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return;
200 case Loop: mediaPlayerState.setLooping( buttonDown ); return; 201 case Loop: mediaPlayerState.setLooping( buttonDown ); return;
201 case VolumeUp: emit moreReleased(); return; 202 case VolumeUp: emit moreReleased(); return;
202 case VolumeDown: emit lessReleased(); return; 203 case VolumeDown: emit lessReleased(); return;
203 case PlayList: mediaPlayerState.setList(); return; 204 case PlayList: mediaPlayerState.setList(); return;
204 case Forward: emit forwardReleased(); return; 205 case Forward: emit forwardReleased(); return;
205 case Back: emit backReleased(); return; 206 case Back: emit backReleased(); return;
206 case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return; 207 case FullScreen: mediaPlayerState.setFullscreen( true ); makeVisible(); return;
207 default: assert( false ); 208 default: assert( false );
208 } 209 }
209} 210}
210 211
211bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const 212bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const
212{ 213{
213 return ( position.x() > 0 && position.y() > 0 && 214 return ( position.x() > 0 && position.y() > 0 &&
214 position.x() < buttonMask.width() && 215 position.x() < buttonMask.width() &&
215 position.y() < buttonMask.height() && 216 position.y() < buttonMask.height() &&
216 buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); 217 buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 );
217} 218}
218 219
219void MediaWidget::paintAllButtons( QPainter &p ) 220void MediaWidget::paintAllButtons( QPainter &p )
220{ 221{
221 for ( ButtonVector::const_iterator it = buttons.begin(); 222 for ( ButtonVector::const_iterator it = buttons.begin();
222 it != buttons.end(); ++it ) 223 it != buttons.end(); ++it )
223 paintButton( p, *it ); 224 paintButton( p, *it );
224} 225}
225 226
226void MediaWidget::paintButton( const Button &button ) 227void MediaWidget::paintButton( const Button &button )
227{ 228{
228 QPainter p( this ); 229 QPainter p( this );
229 paintButton( p, button ); 230 paintButton( p, button );
230} 231}
231 232
232void MediaWidget::paintButton( QPainter &p, const Button &button ) 233void MediaWidget::paintButton( QPainter &p, const Button &button )
233{ 234{
234 if ( button.isDown ) 235 if ( button.isDown )
235 p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); 236 p.drawPixmap( upperLeftOfButtonMask, button.pixDown );
236 else 237 else
237 p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); 238 p.drawPixmap( upperLeftOfButtonMask, button.pixUp );
238} 239}
239 240
240void MediaWidget::setToggleButton( Command command, bool down ) 241void MediaWidget::setToggleButton( Command command, bool down )
241{ 242{
242 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) 243 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it )
243 if ( it->command == command ) { 244 if ( it->command == command ) {
244 setToggleButton( *it, down ); 245 setToggleButton( *it, down );
245 return; 246 return;
246 } 247 }
247} 248}
248 249
249void MediaWidget::setToggleButton( Button &button, bool down ) 250void MediaWidget::setToggleButton( Button &button, bool down )
250{ 251{
251 if ( down != button.isDown ) 252 if ( down != button.isDown )
252 toggleButton( button ); 253 toggleButton( button );
253} 254}
254 255
255void MediaWidget::toggleButton( Button &button ) 256void MediaWidget::toggleButton( Button &button )
256{ 257{
257 button.isDown = !button.isDown; 258 button.isDown = !button.isDown;
258 259
259 paintButton( button ); 260 paintButton( button );
260} 261}
261 262
262/* vim: et sw=4 ts=4 263/* vim: et sw=4 ts=4
263 */ 264 */