summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-09 14:41:19 (UTC)
committer simon <simon>2002-12-09 14:41:19 (UTC)
commit174c4a427750a3829ffd81a87454be8abf61ee30 (patch) (unidiff)
treee6b8d73afe4426707698396cc3c0086d712983f9
parent3f88070b9be5209cdd88caa0afd7f7294d3b1764 (diff)
downloadopie-174c4a427750a3829ffd81a87454be8abf61ee30.zip
opie-174c4a427750a3829ffd81a87454be8abf61ee30.tar.gz
opie-174c4a427750a3829ffd81a87454be8abf61ee30.tar.bz2
- merged the two button setup loops
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index 87e06ee..c148820 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -1,253 +1,251 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> 4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU General Public 12:`=1 )Y*s>-.--   : the terms of the GNU General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <opie/oticker.h> 37#include <opie/oticker.h>
38 38
39#include <qwidget.h> 39#include <qwidget.h>
40#include <qpixmap.h> 40#include <qpixmap.h>
41#include <qbutton.h> 41#include <qbutton.h>
42#include <qpainter.h> 42#include <qpainter.h>
43#include <qframe.h> 43#include <qframe.h>
44#include <qlayout.h> 44#include <qlayout.h>
45#include <qdir.h> 45#include <qdir.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <stdio.h> 47#include <stdio.h>
48 48
49#include "audiowidget.h" 49#include "audiowidget.h"
50#include "mediaplayerstate.h" 50#include "mediaplayerstate.h"
51#include "playlistwidget.h" 51#include "playlistwidget.h"
52 52
53namespace 53namespace
54{ 54{
55 55
56const int xo = -2; // movable x offset 56const int xo = -2; // movable x offset
57const int yo = 22; // movable y offset 57const int yo = 22; // movable y offset
58 58
59const MediaWidget::SkinButtonInfo skinInfo[] = 59const MediaWidget::SkinButtonInfo skinInfo[] =
60{ 60{
61 { MediaWidget::Play, "play", MediaWidget::ToggleButton }, 61 { MediaWidget::Play, "play", MediaWidget::ToggleButton },
62 { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, 62 { MediaWidget::Stop, "stop", MediaWidget::NormalButton },
63 { MediaWidget::Next, "next", MediaWidget::NormalButton }, 63 { MediaWidget::Next, "next", MediaWidget::NormalButton },
64 { MediaWidget::Previous, "prev", MediaWidget::NormalButton }, 64 { MediaWidget::Previous, "prev", MediaWidget::NormalButton },
65 { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, 65 { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton },
66 { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, 66 { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton },
67 { MediaWidget::Loop, "loop", MediaWidget::ToggleButton }, 67 { MediaWidget::Loop, "loop", MediaWidget::ToggleButton },
68 { MediaWidget::PlayList, "playlist", MediaWidget::NormalButton }, 68 { MediaWidget::PlayList, "playlist", MediaWidget::NormalButton },
69 { MediaWidget::Forward, "forward", MediaWidget::NormalButton }, 69 { MediaWidget::Forward, "forward", MediaWidget::NormalButton },
70 { MediaWidget::Back, "back", MediaWidget::NormalButton } 70 { MediaWidget::Back, "back", MediaWidget::NormalButton }
71}; 71};
72 72
73const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); 73const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] );
74 74
75void changeTextColor( QWidget * w) { 75void changeTextColor( QWidget * w) {
76 QPalette p = w->palette(); 76 QPalette p = w->palette();
77 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); 77 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) );
78 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); 78 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) );
79 w->setPalette( p ); 79 w->setPalette( p );
80} 80}
81 81
82} 82}
83 83
84AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : 84AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) :
85 85
86 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ), 86 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ),
87 audioSliderBeingMoved( false ) 87 audioSliderBeingMoved( false )
88{ 88{
89 for ( uint i = 0; i < buttonCount; ++i ) {
90 Button button;
91 button.type = skinInfo[ i ].type;
92 buttons.push_back( button );
93 }
94
95 setCaption( tr("OpiePlayer") ); 89 setCaption( tr("OpiePlayer") );
96 90
97 Config cfg("OpiePlayer"); 91 Config cfg("OpiePlayer");
98 cfg.setGroup("Options"); 92 cfg.setGroup("Options");
99 skin = cfg.readEntry("Skin","default"); 93 skin = cfg.readEntry("Skin","default");
100 //skin = "scaleTest"; 94 //skin = "scaleTest";
101 // color of background, frame, degree of transparency 95 // color of background, frame, degree of transparency
102 96
103 QString skinPath = "opieplayer2/skins/" + skin; 97 QString skinPath = "opieplayer2/skins/" + skin;
104 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); 98 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) );
105 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); 99 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) );
106 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); 100 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) );
107 101
108 buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); 102 buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 );
109 buttonMask.fill( 0 ); 103 buttonMask.fill( 0 );
110 104
111 for ( uint i = 0; i < buttons.size(); i++ ) { 105 for ( uint i = 0; i < buttonCount; i++ ) {
106 Button button;
107 button.type = skinInfo[ i ].type;
108
112 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skinInfo[i].fileName + ".png" ); 109 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skinInfo[i].fileName + ".png" );
113 buttons[ i ].mask =QBitmap( filename ); 110 button.mask =QBitmap( filename );
114 111
115 if ( !buttons[i].mask.isNull() ) { 112 if ( !button.mask.isNull() ) {
116 QImage imgMask = buttons[i].mask.convertToImage(); 113 QImage imgMask = button.mask.convertToImage();
117 uchar **dest = buttonMask.jumpTable(); 114 uchar **dest = buttonMask.jumpTable();
118 for ( int y = 0; y < imgUp.height(); y++ ) { 115 for ( int y = 0; y < imgUp.height(); y++ ) {
119 uchar *line = dest[y]; 116 uchar *line = dest[y];
120 for ( int x = 0; x < imgUp.width(); x++ ) 117 for ( int x = 0; x < imgUp.width(); x++ )
121 if ( !qRed( imgMask.pixel( x, y ) ) ) 118 if ( !qRed( imgMask.pixel( x, y ) ) )
122 line[x] = i + 1; 119 line[x] = i + 1;
123 } 120 }
124 } 121 }
125 122
123 buttons.push_back( button );
126 } 124 }
127 125
128 setBackgroundPixmap( pixBg ); 126 setBackgroundPixmap( pixBg );
129 127
130 songInfo.setFocusPolicy( QWidget::NoFocus ); 128 songInfo.setFocusPolicy( QWidget::NoFocus );
131// changeTextColor( &songInfo ); 129// changeTextColor( &songInfo );
132// songInfo.setBackgroundColor( QColor( 167, 212, 167 )); 130// songInfo.setBackgroundColor( QColor( 167, 212, 167 ));
133// songInfo.setFrameStyle( QFrame::NoFrame); 131// songInfo.setFrameStyle( QFrame::NoFrame);
134 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 132 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
135// songInfo.setForegroundColor(Qt::white); 133// songInfo.setForegroundColor(Qt::white);
136 134
137 slider.setFixedHeight( 20 ); 135 slider.setFixedHeight( 20 );
138 slider.setMinValue( 0 ); 136 slider.setMinValue( 0 );
139 slider.setMaxValue( 1 ); 137 slider.setMaxValue( 1 );
140 slider.setFocusPolicy( QWidget::NoFocus ); 138 slider.setFocusPolicy( QWidget::NoFocus );
141 slider.setBackgroundPixmap( pixBg ); 139 slider.setBackgroundPixmap( pixBg );
142 140
143// Config cofg("qpe"); 141// Config cofg("qpe");
144// cofg.setGroup("Appearance"); 142// cofg.setGroup("Appearance");
145// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); 143// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) );
146 144
147 time.setFocusPolicy( QWidget::NoFocus ); 145 time.setFocusPolicy( QWidget::NoFocus );
148 time.setAlignment( Qt::AlignCenter ); 146 time.setAlignment( Qt::AlignCenter );
149 147
150// time.setFrame(FALSE); 148// time.setFrame(FALSE);
151// changeTextColor( &time ); 149// changeTextColor( &time );
152 150
153 resizeEvent( NULL ); 151 resizeEvent( NULL );
154 152
155 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 153 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
156 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); 154 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) );
157 155
158 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); 156 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) );
159 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); 157 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) );
160 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); 158 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) );
161 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); 159 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) );
162 160
163 // Intialise state 161 // Intialise state
164 setLength( mediaPlayerState.length() ); 162 setLength( mediaPlayerState.length() );
165 setPosition( mediaPlayerState.position() ); 163 setPosition( mediaPlayerState.position() );
166 setLooping( mediaPlayerState.isFullscreen() ); 164 setLooping( mediaPlayerState.isFullscreen() );
167 // setPaused( mediaPlayerState->paused() ); 165 // setPaused( mediaPlayerState->paused() );
168 setPlaying( mediaPlayerState.isPlaying() ); 166 setPlaying( mediaPlayerState.isPlaying() );
169 167
170} 168}
171 169
172AudioWidget::~AudioWidget() { 170AudioWidget::~AudioWidget() {
173 171
174// mediaPlayerState->setPlaying(false); 172// mediaPlayerState->setPlaying(false);
175} 173}
176 174
177namespace { 175namespace {
178 176
179QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 177QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
180 QPixmap pix( img.width(), img.height() ); 178 QPixmap pix( img.width(), img.height() );
181 QPainter p( &pix ); 179 QPainter p( &pix );
182 p.drawTiledPixmap( pix.rect(), bg, offset ); 180 p.drawTiledPixmap( pix.rect(), bg, offset );
183 p.drawImage( 0, 0, img ); 181 p.drawImage( 0, 0, img );
184 return pix; 182 return pix;
185} 183}
186 184
187 185
188QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) { 186QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) {
189 QPixmap pixmap( pix ); 187 QPixmap pixmap( pix );
190 pixmap.setMask( mask ); 188 pixmap.setMask( mask );
191 return pixmap; 189 return pixmap;
192} 190}
193 191
194}; 192};
195 193
196void AudioWidget::resizeEvent( QResizeEvent * ) { 194void AudioWidget::resizeEvent( QResizeEvent * ) {
197 int h = height(); 195 int h = height();
198 int w = width(); 196 int w = width();
199 197
200 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); 198 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) );
201 slider.setFixedWidth( w - 110 ); 199 slider.setFixedWidth( w - 110 );
202 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); 200 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) );
203 slider.setBackgroundOrigin( QWidget::ParentOrigin ); 201 slider.setBackgroundOrigin( QWidget::ParentOrigin );
204 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); 202 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) );
205 203
206 upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2; 204 upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2;
207 upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10; 205 upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10;
208 QPoint p = upperLeftOfButtonMask; 206 QPoint p = upperLeftOfButtonMask;
209 207
210 QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p ); 208 QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p );
211 QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p ); 209 QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p );
212 210
213 for ( uint i = 0; i < buttons.size(); i++ ) { 211 for ( uint i = 0; i < buttons.size(); i++ ) {
214 if ( !buttons[i].mask.isNull() ) { 212 if ( !buttons[i].mask.isNull() ) {
215 buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask ); 213 buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask );
216 buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask ); 214 buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask );
217 } 215 }
218 } 216 }
219} 217}
220 218
221void AudioWidget::sliderPressed() { 219void AudioWidget::sliderPressed() {
222 audioSliderBeingMoved = TRUE; 220 audioSliderBeingMoved = TRUE;
223} 221}
224 222
225 223
226void AudioWidget::sliderReleased() { 224void AudioWidget::sliderReleased() {
227 audioSliderBeingMoved = FALSE; 225 audioSliderBeingMoved = FALSE;
228 if ( slider.width() == 0 ) 226 if ( slider.width() == 0 )
229 return; 227 return;
230 long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); 228 long val = long((double)slider.value() * mediaPlayerState.length() / slider.width());
231 mediaPlayerState.setPosition( val ); 229 mediaPlayerState.setPosition( val );
232} 230}
233 231
234void AudioWidget::setPosition( long i ) { 232void AudioWidget::setPosition( long i ) {
235 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); 233 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i);
236 updateSlider( i, mediaPlayerState.length() ); 234 updateSlider( i, mediaPlayerState.length() );
237} 235}
238 236
239 237
240void AudioWidget::setLength( long max ) { 238void AudioWidget::setLength( long max ) {
241 updateSlider( mediaPlayerState.position(), max ); 239 updateSlider( mediaPlayerState.position(), max );
242} 240}
243 241
244 242
245void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { 243void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) {
246 if ( mediaType == MediaPlayerState::Audio ) { 244 if ( mediaType == MediaPlayerState::Audio ) {
247 // startTimer( 150 ); 245 // startTimer( 150 );
248 showMaximized(); 246 showMaximized();
249 return; 247 return;
250 } 248 }
251 249
252 killTimers(); 250 killTimers();
253 hide(); 251 hide();