Diffstat (limited to 'noncore/multimedia/opieplayer2/audiowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 10 |
1 files changed, 1 insertions, 9 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 1b0de5d..125fd72 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -34,150 +34,142 @@ void Ticker::setText( const QString& text ) { | |||
34 | killTimers(); | 34 | killTimers(); |
35 | if ( pixelLen > width() ) { | 35 | if ( pixelLen > width() ) { |
36 | startTimer( 50 ); | 36 | startTimer( 50 ); |
37 | } | 37 | } |
38 | update(); | 38 | update(); |
39 | } | 39 | } |
40 | 40 | ||
41 | 41 | ||
42 | void Ticker::timerEvent( QTimerEvent * ) { | 42 | void Ticker::timerEvent( QTimerEvent * ) { |
43 | pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; | 43 | pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; |
44 | repaint( FALSE ); | 44 | repaint( FALSE ); |
45 | } | 45 | } |
46 | 46 | ||
47 | void Ticker::drawContents( QPainter *p ) { | 47 | void Ticker::drawContents( QPainter *p ) { |
48 | QPixmap pm( width(), height() ); | 48 | QPixmap pm( width(), height() ); |
49 | pm.fill( colorGroup().base() ); | 49 | pm.fill( colorGroup().base() ); |
50 | QPainter pmp( &pm ); | 50 | QPainter pmp( &pm ); |
51 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { | 51 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) { |
52 | pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); | 52 | pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); |
53 | } | 53 | } |
54 | p->drawPixmap( 0, 0, pm ); | 54 | p->drawPixmap( 0, 0, pm ); |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | |||
59 | |||
60 | struct MediaButton { | 58 | struct MediaButton { |
61 | int xPos, yPos; | 59 | int xPos, yPos; |
62 | int color; | 60 | int color; |
63 | bool isToggle, isBig, isHeld, isDown; | 61 | bool isToggle, isBig, isHeld, isDown; |
64 | }; | 62 | }; |
65 | 63 | ||
66 | 64 | ||
67 | |||
68 | |||
69 | // Layout information for the audioButtons (and if it is a toggle button or not) | 65 | // Layout information for the audioButtons (and if it is a toggle button or not) |
70 | MediaButton audioButtons[] = { | 66 | MediaButton audioButtons[] = { |
71 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play | 67 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play |
72 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop | 68 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop |
73 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause | 69 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause |
74 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next | 70 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next |
75 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous | 71 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous |
76 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up | 72 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up |
77 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down | 73 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down |
78 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop | 74 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop |
79 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist | 75 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist |
80 | }; | 76 | }; |
81 | 77 | ||
82 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 78 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
83 | 79 | ||
84 | 80 | ||
85 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 81 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
86 | QWidget( parent, name, f ) | 82 | QWidget( parent, name, f ) { |
87 | { | ||
88 | setCaption( tr("OpiePlayer - Audio") ); | 83 | setCaption( tr("OpiePlayer - Audio") ); |
89 | Config cfg("OpiePlayer"); | 84 | Config cfg("OpiePlayer"); |
90 | cfg.setGroup("AudioWidget"); | 85 | cfg.setGroup("AudioWidget"); |
91 | 86 | ||
92 | QString backgroundPix, buttonsAllPix, buttonsBigPix, controlsPix, animatedPix; | 87 | QString backgroundPix, buttonsAllPix, buttonsBigPix, controlsPix, animatedPix; |
93 | backgroundPix=cfg.readEntry( " backgroundPix", "opieplayer/metalFinish"); | 88 | backgroundPix=cfg.readEntry( " backgroundPix", "opieplayer/metalFinish"); |
94 | buttonsAllPix=cfg.readEntry( "buttonsAllPix","opieplayer/mediaButtonsAll"); | 89 | buttonsAllPix=cfg.readEntry( "buttonsAllPix","opieplayer/mediaButtonsAll"); |
95 | buttonsBigPix=cfg.readEntry( "buttonsBigPix","opieplayer/mediaButtonsBig"); | 90 | buttonsBigPix=cfg.readEntry( "buttonsBigPix","opieplayer/mediaButtonsBig"); |
96 | controlsPix=cfg.readEntry( "controlsPix","opieplayer/mediaControls"); | 91 | controlsPix=cfg.readEntry( "controlsPix","opieplayer/mediaControls"); |
97 | 92 | ||
98 | setBackgroundPixmap( Resource::loadPixmap( backgroundPix) ); | 93 | setBackgroundPixmap( Resource::loadPixmap( backgroundPix) ); |
99 | pixmaps[0] = new QPixmap( Resource::loadPixmap( buttonsAllPix ) ); | 94 | pixmaps[0] = new QPixmap( Resource::loadPixmap( buttonsAllPix ) ); |
100 | pixmaps[1] = new QPixmap( Resource::loadPixmap( buttonsBigPix ) ); | 95 | pixmaps[1] = new QPixmap( Resource::loadPixmap( buttonsBigPix ) ); |
101 | pixmaps[2] = new QPixmap( Resource::loadPixmap( controlsPix ) ); | 96 | pixmaps[2] = new QPixmap( Resource::loadPixmap( controlsPix ) ); |
102 | 97 | ||
103 | songInfo = new Ticker( this ); | 98 | songInfo = new Ticker( this ); |
104 | songInfo->setFocusPolicy( QWidget::NoFocus ); | 99 | songInfo->setFocusPolicy( QWidget::NoFocus ); |
105 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); | 100 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); |
106 | 101 | ||
107 | slider = new QSlider( Qt::Horizontal, this ); | 102 | slider = new QSlider( Qt::Horizontal, this ); |
108 | slider->setFixedWidth( 220 ); | 103 | slider->setFixedWidth( 220 ); |
109 | slider->setFixedHeight( 20 ); | 104 | slider->setFixedHeight( 20 ); |
110 | slider->setMinValue( 0 ); | 105 | slider->setMinValue( 0 ); |
111 | slider->setMaxValue( 1 ); | 106 | slider->setMaxValue( 1 ); |
112 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | 107 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); |
113 | slider->setFocusPolicy( QWidget::NoFocus ); | 108 | slider->setFocusPolicy( QWidget::NoFocus ); |
114 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); | 109 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); |
115 | 110 | ||
116 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 111 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
117 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 112 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
118 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 113 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
119 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 114 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
120 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 115 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
121 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 116 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
122 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 117 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
123 | 118 | ||
124 | // Intialise state | 119 | // Intialise state |
125 | setLength( mediaPlayerState->length() ); | 120 | setLength( mediaPlayerState->length() ); |
126 | setPosition( mediaPlayerState->position() ); | 121 | setPosition( mediaPlayerState->position() ); |
127 | setLooping( mediaPlayerState->fullscreen() ); | 122 | setLooping( mediaPlayerState->fullscreen() ); |
128 | setPaused( mediaPlayerState->paused() ); | 123 | setPaused( mediaPlayerState->paused() ); |
129 | setPlaying( mediaPlayerState->playing() ); | 124 | setPlaying( mediaPlayerState->playing() ); |
130 | |||
131 | } | 125 | } |
132 | 126 | ||
133 | |||
134 | AudioWidget::~AudioWidget() { | 127 | AudioWidget::~AudioWidget() { |
135 | mediaPlayerState->isStreaming = FALSE; | 128 | mediaPlayerState->isStreaming = FALSE; |
136 | for ( int i = 0; i < 3; i++ ) { | 129 | for ( int i = 0; i < 3; i++ ) { |
137 | delete pixmaps[i]; | 130 | delete pixmaps[i]; |
138 | } | 131 | } |
139 | } | 132 | } |
140 | 133 | ||
141 | 134 | ||
142 | static bool audioSliderBeingMoved = FALSE; | 135 | static bool audioSliderBeingMoved = FALSE; |
143 | 136 | ||
144 | 137 | ||
145 | void AudioWidget::sliderPressed() { | 138 | void AudioWidget::sliderPressed() { |
146 | audioSliderBeingMoved = TRUE; | 139 | audioSliderBeingMoved = TRUE; |
147 | } | 140 | } |
148 | 141 | ||
149 | 142 | ||
150 | void AudioWidget::sliderReleased() { | 143 | void AudioWidget::sliderReleased() { |
151 | audioSliderBeingMoved = FALSE; | 144 | audioSliderBeingMoved = FALSE; |
152 | if ( slider->width() == 0 ) { | 145 | if ( slider->width() == 0 ) { |
153 | return; | 146 | return; |
154 | } | 147 | } |
155 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 148 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
156 | mediaPlayerState->setPosition( val ); | 149 | mediaPlayerState->setPosition( val ); |
157 | } | 150 | } |
158 | 151 | ||
159 | |||
160 | void AudioWidget::setPosition( long i ) { | 152 | void AudioWidget::setPosition( long i ) { |
161 | // qDebug("set position %d",i); | 153 | // qDebug("set position %d",i); |
162 | updateSlider( i, mediaPlayerState->length() ); | 154 | updateSlider( i, mediaPlayerState->length() ); |
163 | } | 155 | } |
164 | 156 | ||
165 | 157 | ||
166 | void AudioWidget::setLength( long max ) { | 158 | void AudioWidget::setLength( long max ) { |
167 | updateSlider( mediaPlayerState->position(), max ); | 159 | updateSlider( mediaPlayerState->position(), max ); |
168 | } | 160 | } |
169 | 161 | ||
170 | 162 | ||
171 | void AudioWidget::setView( char view ) { | 163 | void AudioWidget::setView( char view ) { |
172 | if (mediaPlayerState->isStreaming) { | 164 | if (mediaPlayerState->isStreaming) { |
173 | if( !slider->isHidden()) slider->hide(); | 165 | if( !slider->isHidden()) slider->hide(); |
174 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 166 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
175 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 167 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
176 | } else { | 168 | } else { |
177 | // this stops the slider from being moved, thus | 169 | // this stops the slider from being moved, thus |
178 | // does not stop stream when it reaches the end | 170 | // does not stop stream when it reaches the end |
179 | slider->show(); | 171 | slider->show(); |
180 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 172 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
181 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 173 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
182 | } | 174 | } |
183 | 175 | ||