-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 19 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.h | 4 |
2 files changed, 12 insertions, 11 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index adef247..fe7ddc1 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp | |||
@@ -81,70 +81,72 @@ AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlaye | |||
81 | Button toggleButton; | 81 | Button toggleButton; |
82 | toggleButton.isToggle = true; | 82 | toggleButton.isToggle = true; |
83 | toggleButton.isHeld = toggleButton.isDown = false; | 83 | toggleButton.isHeld = toggleButton.isDown = false; |
84 | 84 | ||
85 | buttons.reserve( 10 ); | 85 | buttons.reserve( 10 ); |
86 | buttons.push_back( toggleButton ); // play | 86 | buttons.push_back( toggleButton ); // play |
87 | buttons.push_back( defaultButton ); // stop | 87 | buttons.push_back( defaultButton ); // stop |
88 | buttons.push_back( defaultButton ); // next | 88 | buttons.push_back( defaultButton ); // next |
89 | buttons.push_back( defaultButton ); // previous | 89 | buttons.push_back( defaultButton ); // previous |
90 | buttons.push_back( defaultButton ); // volume up | 90 | buttons.push_back( defaultButton ); // volume up |
91 | buttons.push_back( defaultButton ); // volume down | 91 | buttons.push_back( defaultButton ); // volume down |
92 | buttons.push_back( toggleButton ); // repeat/loop | 92 | buttons.push_back( toggleButton ); // repeat/loop |
93 | buttons.push_back( defaultButton ); // playlist | 93 | buttons.push_back( defaultButton ); // playlist |
94 | buttons.push_back( defaultButton ); // forward | 94 | buttons.push_back( defaultButton ); // forward |
95 | buttons.push_back( defaultButton ); // back | 95 | buttons.push_back( defaultButton ); // back |
96 | 96 | ||
97 | setCaption( tr("OpiePlayer") ); | 97 | setCaption( tr("OpiePlayer") ); |
98 | 98 | ||
99 | Config cfg("OpiePlayer"); | 99 | Config cfg("OpiePlayer"); |
100 | cfg.setGroup("Options"); | 100 | cfg.setGroup("Options"); |
101 | skin = cfg.readEntry("Skin","default"); | 101 | skin = cfg.readEntry("Skin","default"); |
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 = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 106 | pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
107 | imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 107 | imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
108 | imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 108 | imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
109 | 109 | ||
110 | buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); | 110 | buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); |
111 | buttonMask.fill( 0 ); | 111 | buttonMask.fill( 0 ); |
112 | 112 | ||
113 | for ( int i = 0; i < 10; i++ ) { | 113 | masks.reserve( 10 ); |
114 | |||
115 | for ( uint i = 0; i < masks.capacity(); i++ ) { | ||
114 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); | 116 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); |
115 | masks[i] = new QBitmap( filename ); | 117 | masks.push_back( QBitmap( filename ) ); |
116 | 118 | ||
117 | if ( !masks[i]->isNull() ) { | 119 | if ( !masks[i].isNull() ) { |
118 | QImage imgMask = masks[i]->convertToImage(); | 120 | QImage imgMask = masks[i].convertToImage(); |
119 | uchar **dest = buttonMask.jumpTable(); | 121 | uchar **dest = buttonMask.jumpTable(); |
120 | for ( int y = 0; y < imgUp.height(); y++ ) { | 122 | for ( int y = 0; y < imgUp.height(); y++ ) { |
121 | uchar *line = dest[y]; | 123 | uchar *line = dest[y]; |
122 | for ( int x = 0; x < imgUp.width(); x++ ) | 124 | for ( int x = 0; x < imgUp.width(); x++ ) |
123 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 125 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
124 | line[x] = i + 1; | 126 | line[x] = i + 1; |
125 | } | 127 | } |
126 | } | 128 | } |
127 | 129 | ||
128 | } | 130 | } |
129 | 131 | ||
130 | for ( int i = 0; i < 10; i++ ) { | 132 | for ( int i = 0; i < 10; i++ ) { |
131 | buttonPixUp[i] = 0l; | 133 | buttonPixUp[i] = 0l; |
132 | buttonPixDown[i] = 0l; | 134 | buttonPixDown[i] = 0l; |
133 | } | 135 | } |
134 | 136 | ||
135 | setBackgroundPixmap( pixBg ); | 137 | setBackgroundPixmap( pixBg ); |
136 | 138 | ||
137 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 139 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
138 | // changeTextColor( &songInfo ); | 140 | // changeTextColor( &songInfo ); |
139 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); | 141 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); |
140 | // songInfo.setFrameStyle( QFrame::NoFrame); | 142 | // songInfo.setFrameStyle( QFrame::NoFrame); |
141 | songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); | 143 | songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); |
142 | // songInfo.setForegroundColor(Qt::white); | 144 | // songInfo.setForegroundColor(Qt::white); |
143 | 145 | ||
144 | slider.setFixedHeight( 20 ); | 146 | slider.setFixedHeight( 20 ); |
145 | slider.setMinValue( 0 ); | 147 | slider.setMinValue( 0 ); |
146 | slider.setMaxValue( 1 ); | 148 | slider.setMaxValue( 1 ); |
147 | slider.setFocusPolicy( QWidget::NoFocus ); | 149 | slider.setFocusPolicy( QWidget::NoFocus ); |
148 | slider.setBackgroundPixmap( pixBg ); | 150 | slider.setBackgroundPixmap( pixBg ); |
149 | 151 | ||
150 | // Config cofg("qpe"); | 152 | // Config cofg("qpe"); |
@@ -153,112 +155,109 @@ AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlaye | |||
153 | 155 | ||
154 | time.setFocusPolicy( QWidget::NoFocus ); | 156 | time.setFocusPolicy( QWidget::NoFocus ); |
155 | time.setAlignment( Qt::AlignCenter ); | 157 | time.setAlignment( Qt::AlignCenter ); |
156 | 158 | ||
157 | // time.setFrame(FALSE); | 159 | // time.setFrame(FALSE); |
158 | // changeTextColor( &time ); | 160 | // changeTextColor( &time ); |
159 | 161 | ||
160 | resizeEvent( NULL ); | 162 | resizeEvent( NULL ); |
161 | 163 | ||
162 | connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 164 | connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
163 | connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); | 165 | connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); |
164 | 166 | ||
165 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); | 167 | connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); |
166 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); | 168 | connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); |
167 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); | 169 | connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); |
168 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); | 170 | connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); |
169 | 171 | ||
170 | // Intialise state | 172 | // Intialise state |
171 | setLength( mediaPlayerState.length() ); | 173 | setLength( mediaPlayerState.length() ); |
172 | setPosition( mediaPlayerState.position() ); | 174 | setPosition( mediaPlayerState.position() ); |
173 | setLooping( mediaPlayerState.isFullscreen() ); | 175 | setLooping( mediaPlayerState.isFullscreen() ); |
174 | // setPaused( mediaPlayerState->paused() ); | 176 | // setPaused( mediaPlayerState->paused() ); |
175 | setPlaying( mediaPlayerState.isPlaying() ); | 177 | setPlaying( mediaPlayerState.isPlaying() ); |
176 | 178 | ||
177 | } | 179 | } |
178 | 180 | ||
179 | AudioWidget::~AudioWidget() { | 181 | AudioWidget::~AudioWidget() { |
180 | 182 | ||
181 | for ( int i = 0; i < 10; i++ ) { | 183 | for ( int i = 0; i < 10; i++ ) { |
182 | delete buttonPixUp[i]; | 184 | delete buttonPixUp[i]; |
183 | delete buttonPixDown[i]; | 185 | delete buttonPixDown[i]; |
184 | } | 186 | } |
185 | for ( int i = 0; i < 10; i++ ) { | ||
186 | delete masks[i]; | ||
187 | } | ||
188 | // mediaPlayerState->setPlaying(false); | 187 | // mediaPlayerState->setPlaying(false); |
189 | } | 188 | } |
190 | 189 | ||
191 | namespace { | 190 | namespace { |
192 | 191 | ||
193 | QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 192 | QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
194 | QPixmap pix( img.width(), img.height() ); | 193 | QPixmap pix( img.width(), img.height() ); |
195 | QPainter p( &pix ); | 194 | QPainter p( &pix ); |
196 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 195 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
197 | p.drawImage( 0, 0, img ); | 196 | p.drawImage( 0, 0, img ); |
198 | return pix; | 197 | return pix; |
199 | } | 198 | } |
200 | 199 | ||
201 | 200 | ||
202 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { | 201 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) { |
203 | QPixmap *pixmap = new QPixmap( pix ); | 202 | QPixmap *pixmap = new QPixmap( pix ); |
204 | pixmap->setMask( mask ); | 203 | pixmap->setMask( mask ); |
205 | return pixmap; | 204 | return pixmap; |
206 | } | 205 | } |
207 | 206 | ||
208 | }; | 207 | }; |
209 | 208 | ||
210 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 209 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
211 | int h = height(); | 210 | int h = height(); |
212 | int w = width(); | 211 | int w = width(); |
213 | 212 | ||
214 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); | 213 | songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); |
215 | slider.setFixedWidth( w - 110 ); | 214 | slider.setFixedWidth( w - 110 ); |
216 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); | 215 | slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
217 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 216 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
218 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 217 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
219 | 218 | ||
220 | upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2; | 219 | upperLeftOfButtonMask.rx() = ( w - imgUp.width() ) / 2; |
221 | upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10; | 220 | upperLeftOfButtonMask.ry() = (( h - imgUp.height() ) / 2) - 10; |
222 | QPoint p = upperLeftOfButtonMask; | 221 | QPoint p = upperLeftOfButtonMask; |
223 | 222 | ||
224 | QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p ); | 223 | QPixmap pixUp = combineImageWithBackground( imgUp, pixBg, p ); |
225 | QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p ); | 224 | QPixmap pixDn = combineImageWithBackground( imgDn, pixBg, p ); |
226 | 225 | ||
227 | for ( int i = 0; i < 10; i++ ) { | 226 | for ( int i = 0; i < 10; i++ ) { |
228 | if ( !masks[i]->isNull() ) { | 227 | if ( !masks[i].isNull() ) { |
229 | delete buttonPixUp[i]; | 228 | delete buttonPixUp[i]; |
230 | delete buttonPixDown[i]; | 229 | delete buttonPixDown[i]; |
231 | buttonPixUp[i] = maskPixToMask( pixUp, *masks[i] ); | 230 | buttonPixUp[i] = maskPixToMask( pixUp, masks[i] ); |
232 | buttonPixDown[i] = maskPixToMask( pixDn, *masks[i] ); | 231 | buttonPixDown[i] = maskPixToMask( pixDn, masks[i] ); |
233 | } | 232 | } |
234 | } | 233 | } |
235 | } | 234 | } |
236 | 235 | ||
237 | void AudioWidget::sliderPressed() { | 236 | void AudioWidget::sliderPressed() { |
238 | audioSliderBeingMoved = TRUE; | 237 | audioSliderBeingMoved = TRUE; |
239 | } | 238 | } |
240 | 239 | ||
241 | 240 | ||
242 | void AudioWidget::sliderReleased() { | 241 | void AudioWidget::sliderReleased() { |
243 | audioSliderBeingMoved = FALSE; | 242 | audioSliderBeingMoved = FALSE; |
244 | if ( slider.width() == 0 ) | 243 | if ( slider.width() == 0 ) |
245 | return; | 244 | return; |
246 | long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); | 245 | long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); |
247 | mediaPlayerState.setPosition( val ); | 246 | mediaPlayerState.setPosition( val ); |
248 | } | 247 | } |
249 | 248 | ||
250 | void AudioWidget::setPosition( long i ) { | 249 | void AudioWidget::setPosition( long i ) { |
251 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); | 250 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); |
252 | updateSlider( i, mediaPlayerState.length() ); | 251 | updateSlider( i, mediaPlayerState.length() ); |
253 | } | 252 | } |
254 | 253 | ||
255 | 254 | ||
256 | void AudioWidget::setLength( long max ) { | 255 | void AudioWidget::setLength( long max ) { |
257 | updateSlider( mediaPlayerState.position(), max ); | 256 | updateSlider( mediaPlayerState.position(), max ); |
258 | } | 257 | } |
259 | 258 | ||
260 | 259 | ||
261 | void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { | 260 | void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { |
262 | if ( mediaType == MediaPlayerState::Audio ) { | 261 | if ( mediaType == MediaPlayerState::Audio ) { |
263 | // startTimer( 150 ); | 262 | // startTimer( 150 ); |
264 | showMaximized(); | 263 | showMaximized(); |
diff --git a/noncore/multimedia/opieplayer2/audiowidget.h b/noncore/multimedia/opieplayer2/audiowidget.h index 8426490..bc7262c 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.h +++ b/noncore/multimedia/opieplayer2/audiowidget.h | |||
@@ -62,54 +62,56 @@ public slots: | |||
62 | void setLooping( bool b) { setToggleButton( Loop, b ); } | 62 | void setLooping( bool b) { setToggleButton( Loop, b ); } |
63 | void setPosition( long ); | 63 | void setPosition( long ); |
64 | void setSeekable( bool ); | 64 | void setSeekable( bool ); |
65 | 65 | ||
66 | public: | 66 | public: |
67 | virtual void setLength( long ); | 67 | virtual void setLength( long ); |
68 | virtual void setPlaying( bool b) { setToggleButton( Play, b ); } | 68 | virtual void setPlaying( bool b) { setToggleButton( Play, b ); } |
69 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ); | 69 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ); |
70 | 70 | ||
71 | signals: | 71 | signals: |
72 | void moreClicked(); | 72 | void moreClicked(); |
73 | void lessClicked(); | 73 | void lessClicked(); |
74 | void forwardClicked(); | 74 | void forwardClicked(); |
75 | void backClicked(); | 75 | void backClicked(); |
76 | void sliderMoved(long); | 76 | void sliderMoved(long); |
77 | 77 | ||
78 | protected: | 78 | protected: |
79 | void doBlank(); | 79 | void doBlank(); |
80 | void doUnblank(); | 80 | void doUnblank(); |
81 | void paintEvent( QPaintEvent *pe ); | 81 | void paintEvent( QPaintEvent *pe ); |
82 | void showEvent( QShowEvent *se ); | 82 | void showEvent( QShowEvent *se ); |
83 | void resizeEvent( QResizeEvent *re ); | 83 | void resizeEvent( QResizeEvent *re ); |
84 | void mouseMoveEvent( QMouseEvent *event ); | 84 | void mouseMoveEvent( QMouseEvent *event ); |
85 | void mousePressEvent( QMouseEvent *event ); | 85 | void mousePressEvent( QMouseEvent *event ); |
86 | void mouseReleaseEvent( QMouseEvent *event ); | 86 | void mouseReleaseEvent( QMouseEvent *event ); |
87 | void timerEvent( QTimerEvent *event ); | 87 | void timerEvent( QTimerEvent *event ); |
88 | void keyReleaseEvent( QKeyEvent *e); | 88 | void keyReleaseEvent( QKeyEvent *e); |
89 | private slots: | 89 | private slots: |
90 | void skipFor(); | 90 | void skipFor(); |
91 | void skipBack(); | 91 | void skipBack(); |
92 | void stopSkip(); | 92 | void stopSkip(); |
93 | private: | 93 | private: |
94 | typedef std::vector<QBitmap> MaskVector; | ||
95 | |||
94 | void setToggleButton( int, bool ); | 96 | void setToggleButton( int, bool ); |
95 | virtual void paintButton( QPainter &p, int i ); | 97 | virtual void paintButton( QPainter &p, int i ); |
96 | int skipDirection; | 98 | int skipDirection; |
97 | QString skin; | 99 | QString skin; |
98 | QPixmap pixBg; | 100 | QPixmap pixBg; |
99 | QImage imgUp; | 101 | QImage imgUp; |
100 | QImage imgDn; | 102 | QImage imgDn; |
101 | QBitmap *masks[10]; | 103 | MaskVector masks; |
102 | QPixmap *buttonPixUp[10]; | 104 | QPixmap *buttonPixUp[10]; |
103 | QPixmap *buttonPixDown[10]; | 105 | QPixmap *buttonPixDown[10]; |
104 | 106 | ||
105 | QPixmap *pixmaps[4]; | 107 | QPixmap *pixmaps[4]; |
106 | OTicker songInfo; | 108 | OTicker songInfo; |
107 | QSlider slider; | 109 | QSlider slider; |
108 | QLineEdit time; | 110 | QLineEdit time; |
109 | bool isStreaming : 1; | 111 | bool isStreaming : 1; |
110 | bool audioSliderBeingMoved : 1; | 112 | bool audioSliderBeingMoved : 1; |
111 | }; | 113 | }; |
112 | 114 | ||
113 | 115 | ||
114 | #endif // AUDIO_WIDGET_H | 116 | #endif // AUDIO_WIDGET_H |
115 | 117 | ||