summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-11 13:46:15 (UTC)
committer simon <simon>2002-12-11 13:46:15 (UTC)
commit2b3c450378c1da0a2175c91d652ce2eae5614ff8 (patch) (unidiff)
tree4c11c70dbf487725f6e443f5db4c5a0a0c964e61
parentcd5e96b40ceae9158e5cb01e71769e895ea7a3c1 (diff)
downloadopie-2b3c450378c1da0a2175c91d652ce2eae5614ff8.zip
opie-2b3c450378c1da0a2175c91d652ce2eae5614ff8.tar.gz
opie-2b3c450378c1da0a2175c91d652ce2eae5614ff8.tar.bz2
- less code duplication. code from resizeEvent is now shared as well as
the image composing method and the pixmap mask helper
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp13
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp33
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.h5
-rw-r--r--noncore/multimedia/opieplayer2/videowidget.cpp32
4 files changed, 42 insertions, 41 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index bb686f1..bb07882 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -85,119 +85,110 @@ AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlaye
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 setCaption( tr("OpiePlayer") ); 89 setCaption( tr("OpiePlayer") );
90 90
91 loadSkin(); 91 loadSkin();
92 92
93 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 93 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
94 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); 94 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) );
95 95
96 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); 96 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) );
97 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); 97 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) );
98 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); 98 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) );
99 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); 99 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) );
100 100
101 // Intialise state 101 // Intialise state
102 setLength( mediaPlayerState.length() ); 102 setLength( mediaPlayerState.length() );
103 setPosition( mediaPlayerState.position() ); 103 setPosition( mediaPlayerState.position() );
104 setLooping( mediaPlayerState.isFullscreen() ); 104 setLooping( mediaPlayerState.isFullscreen() );
105 // setPaused( mediaPlayerState->paused() ); 105 // setPaused( mediaPlayerState->paused() );
106 setPlaying( mediaPlayerState.isPlaying() ); 106 setPlaying( mediaPlayerState.isPlaying() );
107} 107}
108 108
109AudioWidget::~AudioWidget() { 109AudioWidget::~AudioWidget() {
110 110
111// mediaPlayerState->setPlaying(false); 111// mediaPlayerState->setPlaying(false);
112} 112}
113 113
114namespace { 114namespace {
115 115
116QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 116QPixmap combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
117 QPixmap pix( img.width(), img.height() ); 117 QPixmap pix( img.width(), img.height() );
118 QPainter p( &pix ); 118 QPainter p( &pix );
119 p.drawTiledPixmap( pix.rect(), bg, offset ); 119 p.drawTiledPixmap( pix.rect(), bg, offset );
120 p.drawImage( 0, 0, img ); 120 p.drawImage( 0, 0, img );
121 return pix; 121 return pix;
122} 122}
123 123
124 124
125QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) { 125QPixmap maskPixToMask( QPixmap pix, QBitmap mask ) {
126 QPixmap pixmap( pix ); 126 QPixmap pixmap( pix );
127 pixmap.setMask( mask ); 127 pixmap.setMask( mask );
128 return pixmap; 128 return pixmap;
129} 129}
130 130
131}; 131};
132 132
133void AudioWidget::resizeEvent( QResizeEvent * ) { 133void AudioWidget::resizeEvent( QResizeEvent *e ) {
134 int h = height(); 134 int h = height();
135 int w = width(); 135 int w = width();
136 136
137 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); 137 songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) );
138 slider.setFixedWidth( w - 110 ); 138 slider.setFixedWidth( w - 110 );
139 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); 139 slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) );
140 slider.setBackgroundOrigin( QWidget::ParentOrigin ); 140 slider.setBackgroundOrigin( QWidget::ParentOrigin );
141 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); 141 time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) );
142 142
143 upperLeftOfButtonMask.rx() = ( w - buttonUpImage.width() ) / 2; 143 upperLeftOfButtonMask.rx() = ( w - buttonUpImage.width() ) / 2;
144 upperLeftOfButtonMask.ry() = (( h - buttonUpImage.height() ) / 2) - 10; 144 upperLeftOfButtonMask.ry() = (( h - buttonUpImage.height() ) / 2) - 10;
145 QPoint p = upperLeftOfButtonMask;
146 145
147 QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, p ); 146 MediaWidget::resizeEvent( e );
148 QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, p );
149
150 for ( uint i = 0; i < buttons.size(); i++ ) {
151 if ( !buttons[i].mask.isNull() ) {
152 buttons[i].pixUp = maskPixToMask( pixUp, buttons[i].mask );
153 buttons[i].pixDown = maskPixToMask( pixDn, buttons[i].mask );
154 }
155 }
156} 147}
157 148
158void AudioWidget::sliderPressed() { 149void AudioWidget::sliderPressed() {
159 audioSliderBeingMoved = TRUE; 150 audioSliderBeingMoved = TRUE;
160} 151}
161 152
162 153
163void AudioWidget::sliderReleased() { 154void AudioWidget::sliderReleased() {
164 audioSliderBeingMoved = FALSE; 155 audioSliderBeingMoved = FALSE;
165 if ( slider.width() == 0 ) 156 if ( slider.width() == 0 )
166 return; 157 return;
167 long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); 158 long val = long((double)slider.value() * mediaPlayerState.length() / slider.width());
168 mediaPlayerState.setPosition( val ); 159 mediaPlayerState.setPosition( val );
169} 160}
170 161
171void AudioWidget::setPosition( long i ) { 162void AudioWidget::setPosition( long i ) {
172 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i); 163 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<set position %d",i);
173 updateSlider( i, mediaPlayerState.length() ); 164 updateSlider( i, mediaPlayerState.length() );
174} 165}
175 166
176 167
177void AudioWidget::setLength( long max ) { 168void AudioWidget::setLength( long max ) {
178 updateSlider( mediaPlayerState.position(), max ); 169 updateSlider( mediaPlayerState.position(), max );
179} 170}
180 171
181 172
182void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { 173void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) {
183 if ( mediaType == MediaPlayerState::Audio ) { 174 if ( mediaType == MediaPlayerState::Audio ) {
184 // startTimer( 150 ); 175 // startTimer( 150 );
185 showMaximized(); 176 showMaximized();
186 return; 177 return;
187 } 178 }
188 179
189 killTimers(); 180 killTimers();
190 hide(); 181 hide();
191} 182}
192 183
193void AudioWidget::loadSkin() 184void AudioWidget::loadSkin()
194{ 185{
195 loadDefaultSkin( skinInfo, buttonCount ); 186 loadDefaultSkin( skinInfo, buttonCount );
196 187
197 setBackgroundPixmap( backgroundPixmap ); 188 setBackgroundPixmap( backgroundPixmap );
198 189
199 songInfo.setFocusPolicy( QWidget::NoFocus ); 190 songInfo.setFocusPolicy( QWidget::NoFocus );
200// changeTextColor( &songInfo ); 191// changeTextColor( &songInfo );
201// songInfo.setBackgroundColor( QColor( 167, 212, 167 )); 192// songInfo.setBackgroundColor( QColor( 167, 212, 167 ));
202// songInfo.setFrameStyle( QFrame::NoFrame); 193// songInfo.setFrameStyle( QFrame::NoFrame);
203 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 194 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp
index ab23aa8..ab2ec50 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.cpp
+++ b/noncore/multimedia/opieplayer2/mediawidget.cpp
@@ -64,96 +64,113 @@ MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo,
64 return button; 64 return button;
65} 65}
66 66
67void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix ) 67void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix )
68{ 68{
69 Skin skin( fileNameInfix ); 69 Skin skin( fileNameInfix );
70 loadSkin( skinInfo, buttonCount, skin ); 70 loadSkin( skinInfo, buttonCount, skin );
71} 71}
72 72
73void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ) 73void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin )
74{ 74{
75 backgroundPixmap = skin.backgroundImage(); 75 backgroundPixmap = skin.backgroundImage();
76 buttonUpImage = skin.buttonUpImage(); 76 buttonUpImage = skin.buttonUpImage();
77 buttonDownImage = skin.buttonDownImage(); 77 buttonDownImage = skin.buttonDownImage();
78 78
79 setupButtons( skinInfo, buttonCount, skin ); 79 setupButtons( skinInfo, buttonCount, skin );
80} 80}
81 81
82void MediaWidget::closeEvent( QCloseEvent * ) 82void MediaWidget::closeEvent( QCloseEvent * )
83{ 83{
84 mediaPlayerState.setList(); 84 mediaPlayerState.setList();
85} 85}
86 86
87void MediaWidget::paintEvent( QPaintEvent *pe ) 87void MediaWidget::paintEvent( QPaintEvent *pe )
88{ 88{
89 QPainter p( this ); 89 QPainter p( this );
90 90
91 if ( mediaPlayerState.isFullscreen() ) { 91 if ( mediaPlayerState.isFullscreen() ) {
92 // Clear the background 92 // Clear the background
93 p.setBrush( QBrush( Qt::black ) ); 93 p.setBrush( QBrush( Qt::black ) );
94 return; 94 return;
95 } 95 }
96 96
97 if ( !pe->erased() ) { 97 if ( !pe->erased() ) {
98 // Combine with background and double buffer 98 // Combine with background and double buffer
99 QPixmap pix( pe->rect().size() ); 99 QPixmap pix( pe->rect().size() );
100 QPainter p( &pix ); 100 QPainter p( &pix );
101 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 101 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
102 p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); 102 p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() );
103 paintAllButtons( p ); 103 paintAllButtons( p );
104 QPainter p2( this ); 104 QPainter p2( this );
105 p2.drawPixmap( pe->rect().topLeft(), pix ); 105 p2.drawPixmap( pe->rect().topLeft(), pix );
106 } else { 106 } else {
107 QPainter p( this ); 107 QPainter p( this );
108 paintAllButtons( p ); 108 paintAllButtons( p );
109 } 109 }
110} 110}
111 111
112void MediaWidget::resizeEvent( QResizeEvent *e )
113{
114 QPixmap pixUp = combineImageWithBackground( buttonUpImage, backgroundPixmap, upperLeftOfButtonMask );
115 QPixmap pixDn = combineImageWithBackground( buttonDownImage, backgroundPixmap, upperLeftOfButtonMask );
116
117 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) {
118 Button &button = *it;
119
120 if ( button.mask.isNull() )
121 continue;
122 button.pixUp = addMaskToPixmap( pixUp, button.mask );
123 button.pixDown = addMaskToPixmap( pixDn, button.mask );
124 }
125
126 QWidget::resizeEvent( e );
127}
128
112MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) 129MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position )
113{ 130{
114 if ( position.x() <= 0 || position.y() <= 0 || 131 if ( position.x() <= 0 || position.y() <= 0 ||
115 position.x() >= buttonMask.width() || 132 position.x() >= buttonMask.width() ||
116 position.y() >= buttonMask.height() ) 133 position.y() >= buttonMask.height() )
117 return 0; 134 return 0;
118 135
119 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); 136 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() );
120 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) 137 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it )
121 if ( it->command + 1 == pixelIdx ) 138 if ( it->command + 1 == pixelIdx )
122 return &( *it ); 139 return &( *it );
123 140
124 return 0; 141 return 0;
125} 142}
126 143
127void MediaWidget::mousePressEvent( QMouseEvent *event ) 144void MediaWidget::mousePressEvent( QMouseEvent *event )
128{ 145{
129 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); 146 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
130 147
131 if ( !button ) { 148 if ( !button ) {
132 QWidget::mousePressEvent( event ); 149 QWidget::mousePressEvent( event );
133 return; 150 return;
134 } 151 }
135 152
136 switch ( button->command ) { 153 switch ( button->command ) {
137 case VolumeUp: emit moreClicked(); return; 154 case VolumeUp: emit moreClicked(); return;
138 case VolumeDown: emit lessClicked(); return; 155 case VolumeDown: emit lessClicked(); return;
139 case Back: emit backClicked(); return; 156 case Back: emit backClicked(); return;
140 case Forward: emit forwardClicked(); return; 157 case Forward: emit forwardClicked(); return;
141 default: break; 158 default: break;
142 } 159 }
143} 160}
144 161
145void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) 162void MediaWidget::mouseReleaseEvent( QMouseEvent *event )
146{ 163{
147 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); 164 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
148 165
149 if ( !button ) { 166 if ( !button ) {
150 QWidget::mouseReleaseEvent( event ); 167 QWidget::mouseReleaseEvent( event );
151 return; 168 return;
152 } 169 }
153 170
154 if ( button->type == ToggleButton ) 171 if ( button->type == ToggleButton )
155 toggleButton( *button ); 172 toggleButton( *button );
156 173
157 handleCommand( button->command, button->isDown ); 174 handleCommand( button->command, button->isDown );
158} 175}
159 176
@@ -185,50 +202,66 @@ bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const
185 position.x() < buttonMask.width() && 202 position.x() < buttonMask.width() &&
186 position.y() < buttonMask.height() && 203 position.y() < buttonMask.height() &&
187 buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); 204 buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 );
188} 205}
189 206
190void MediaWidget::paintAllButtons( QPainter &p ) 207void MediaWidget::paintAllButtons( QPainter &p )
191{ 208{
192 for ( ButtonVector::const_iterator it = buttons.begin(); 209 for ( ButtonVector::const_iterator it = buttons.begin();
193 it != buttons.end(); ++it ) 210 it != buttons.end(); ++it )
194 paintButton( p, *it ); 211 paintButton( p, *it );
195} 212}
196 213
197void MediaWidget::paintButton( const Button &button ) 214void MediaWidget::paintButton( const Button &button )
198{ 215{
199 QPainter p( this ); 216 QPainter p( this );
200 paintButton( p, button ); 217 paintButton( p, button );
201} 218}
202 219
203void MediaWidget::paintButton( QPainter &p, const Button &button ) 220void MediaWidget::paintButton( QPainter &p, const Button &button )
204{ 221{
205 if ( button.isDown ) 222 if ( button.isDown )
206 p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); 223 p.drawPixmap( upperLeftOfButtonMask, button.pixDown );
207 else 224 else
208 p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); 225 p.drawPixmap( upperLeftOfButtonMask, button.pixUp );
209} 226}
210 227
211void MediaWidget::setToggleButton( Command command, bool down ) 228void MediaWidget::setToggleButton( Command command, bool down )
212{ 229{
213 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) 230 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it )
214 if ( it->command == command ) { 231 if ( it->command == command ) {
215 setToggleButton( *it, down ); 232 setToggleButton( *it, down );
216 return; 233 return;
217 } 234 }
218} 235}
219 236
220void MediaWidget::setToggleButton( Button &button, bool down ) 237void MediaWidget::setToggleButton( Button &button, bool down )
221{ 238{
222 if ( down != button.isDown ) 239 if ( down != button.isDown )
223 toggleButton( button ); 240 toggleButton( button );
224} 241}
225 242
226void MediaWidget::toggleButton( Button &button ) 243void MediaWidget::toggleButton( Button &button )
227{ 244{
228 button.isDown = !button.isDown; 245 button.isDown = !button.isDown;
229 246
230 paintButton( button ); 247 paintButton( button );
231} 248}
232 249
250QPixmap MediaWidget::combineImageWithBackground( const QImage &image, const QPixmap &background, const QPoint &offset )
251{
252 QPixmap pix( image.size() );
253 QPainter p( &pix );
254 p.drawTiledPixmap( pix.rect(), background, offset );
255 p.drawImage( 0, 0, image );
256 return pix;
257}
258
259QPixmap MediaWidget::addMaskToPixmap( const QPixmap &pix, const QBitmap &mask )
260{
261 QPixmap result( pix );
262 result.setMask( mask );
263 return result;
264}
265
233/* vim: et sw=4 ts=4 266/* vim: et sw=4 ts=4
234 */ 267 */
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h
index 9f13677..4599637 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.h
+++ b/noncore/multimedia/opieplayer2/mediawidget.h
@@ -67,84 +67,89 @@ public:
67 }; 67 };
68#if defined( _CC_GNU_ ) 68#if defined( _CC_GNU_ )
69 // use that allocator to avoid the default allocator that on gcc2 requires libstdc++ because 69 // use that allocator to avoid the default allocator that on gcc2 requires libstdc++ because
70 // in the BAD_ALLOC macro it uses std::cerr and friends :-( 70 // in the BAD_ALLOC macro it uses std::cerr and friends :-(
71 typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector; 71 typedef std::vector<Button, std::__allocator<Button, simpleAndStupidAllocator> > ButtonVector;
72#else 72#else
73 typedef std::vector<Button> ButtonVector; 73 typedef std::vector<Button> ButtonVector;
74#endif 74#endif
75 75
76 struct SkinButtonInfo 76 struct SkinButtonInfo
77 { 77 {
78 Command command; 78 Command command;
79 const char *fileName; 79 const char *fileName;
80 ButtonType type; 80 ButtonType type;
81 }; 81 };
82 82
83 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); 83 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 );
84 virtual ~MediaWidget(); 84 virtual ~MediaWidget();
85 85
86public slots: 86public slots:
87 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; 87 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0;
88 virtual void setLength( long length ) = 0; 88 virtual void setLength( long length ) = 0;
89 virtual void setPlaying( bool playing ) = 0; 89 virtual void setPlaying( bool playing ) = 0;
90 90
91 virtual void loadSkin() = 0; 91 virtual void loadSkin() = 0;
92 92
93signals: 93signals:
94 void moreReleased(); 94 void moreReleased();
95 void lessReleased(); 95 void lessReleased();
96 void forwardReleased(); 96 void forwardReleased();
97 void backReleased(); 97 void backReleased();
98 void forwardClicked(); 98 void forwardClicked();
99 void backClicked(); 99 void backClicked();
100 void moreClicked(); 100 void moreClicked();
101 void lessClicked(); 101 void lessClicked();
102 102
103protected: 103protected:
104 void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, 104 void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount,
105 const Skin &skin ); 105 const Skin &skin );
106 Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ); 106 Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin );
107 107
108 void loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix = QString::null ); 108 void loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix = QString::null );
109 void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ); 109 void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin );
110 110
111 virtual void closeEvent( QCloseEvent * ); 111 virtual void closeEvent( QCloseEvent * );
112 112
113 virtual void paintEvent( QPaintEvent *pe ); 113 virtual void paintEvent( QPaintEvent *pe );
114 114
115 virtual void resizeEvent( QResizeEvent *e );
116
115 Button *buttonAt( const QPoint &position ); 117 Button *buttonAt( const QPoint &position );
116 118
117 virtual void mousePressEvent( QMouseEvent *event ); 119 virtual void mousePressEvent( QMouseEvent *event );
118 virtual void mouseReleaseEvent( QMouseEvent *event ); 120 virtual void mouseReleaseEvent( QMouseEvent *event );
119 121
120 virtual void makeVisible(); 122 virtual void makeVisible();
121 123
122 void handleCommand( Command command, bool buttonDown ); 124 void handleCommand( Command command, bool buttonDown );
123 125
124 bool isOverButton( const QPoint &position, int buttonId ) const; 126 bool isOverButton( const QPoint &position, int buttonId ) const;
125 127
126 void paintAllButtons( QPainter &p ); 128 void paintAllButtons( QPainter &p );
127 void paintButton( const Button &button ); 129 void paintButton( const Button &button );
128 void paintButton( QPainter &p, const Button &button ); 130 void paintButton( QPainter &p, const Button &button );
129 131
130 void setToggleButton( Button &button, bool down ); 132 void setToggleButton( Button &button, bool down );
131 void setToggleButton( Command command, bool down ); 133 void setToggleButton( Command command, bool down );
132 void toggleButton( Button &button ); 134 void toggleButton( Button &button );
133 135
134 MediaPlayerState &mediaPlayerState; 136 MediaPlayerState &mediaPlayerState;
135 PlayListWidget &playList; 137 PlayListWidget &playList;
136 138
137 ButtonVector buttons; 139 ButtonVector buttons;
138 140
139 QImage buttonMask; 141 QImage buttonMask;
140 142
141 QPoint upperLeftOfButtonMask; 143 QPoint upperLeftOfButtonMask;
142 144
143 QPixmap backgroundPixmap; 145 QPixmap backgroundPixmap;
144 QImage buttonUpImage; 146 QImage buttonUpImage;
145 QImage buttonDownImage; 147 QImage buttonDownImage;
148
149 static QPixmap combineImageWithBackground( const QImage &background, const QPixmap &pixmap, const QPoint &offset );
150 static QPixmap addMaskToPixmap( const QPixmap &pix, const QBitmap &mask );
146}; 151};
147 152
148#endif // MEDIAWIDGET_H 153#endif // MEDIAWIDGET_H
149/* vim: et sw=4 ts=4 154/* vim: et sw=4 ts=4
150 */ 155 */
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp
index bc47717..a8ff540 100644
--- a/noncore/multimedia/opieplayer2/videowidget.cpp
+++ b/noncore/multimedia/opieplayer2/videowidget.cpp
@@ -54,143 +54,115 @@
54 54
55 55
56namespace 56namespace
57{ 57{
58 58
59const int xo = 2; // movable x offset 59const int xo = 2; // movable x offset
60const int yo = 0; // movable y offset 60const int yo = 0; // movable y offset
61 61
62const MediaWidget::SkinButtonInfo skinInfo[] = 62const MediaWidget::SkinButtonInfo skinInfo[] =
63{ 63{
64 { MediaWidget::Play, "play", MediaWidget::ToggleButton }, 64 { MediaWidget::Play, "play", MediaWidget::ToggleButton },
65 { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, 65 { MediaWidget::Stop, "stop", MediaWidget::NormalButton },
66 { MediaWidget::Next, "fwd", MediaWidget::NormalButton }, 66 { MediaWidget::Next, "fwd", MediaWidget::NormalButton },
67 { MediaWidget::Previous, "back", MediaWidget::NormalButton }, 67 { MediaWidget::Previous, "back", MediaWidget::NormalButton },
68 { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, 68 { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton },
69 { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, 69 { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton },
70 { MediaWidget::FullScreen, "full", MediaWidget::ToggleButton } 70 { MediaWidget::FullScreen, "full", MediaWidget::ToggleButton }
71}; 71};
72 72
73const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); 73const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] );
74 74
75} 75}
76 76
77VideoWidget::VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name ) 77VideoWidget::VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name )
78 : MediaWidget( playList, mediaPlayerState, parent, name ), scaledWidth( 0 ), scaledHeight( 0 ), videoSliderBeingMoved( false ) 78 : MediaWidget( playList, mediaPlayerState, parent, name ), scaledWidth( 0 ), scaledHeight( 0 ), videoSliderBeingMoved( false )
79{ 79{
80 setCaption( tr("OpiePlayer - Video") ); 80 setCaption( tr("OpiePlayer - Video") );
81 81
82 videoFrame = new XineVideoWidget ( this, "Video frame" ); 82 videoFrame = new XineVideoWidget ( this, "Video frame" );
83 83
84 connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); 84 connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & )));
85 connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) ); 85 connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) );
86 86
87 slider = 0; 87 slider = 0;
88 88
89 loadSkin(); 89 loadSkin();
90 90
91 setLength( mediaPlayerState.length() ); 91 setLength( mediaPlayerState.length() );
92 setPosition( mediaPlayerState.position() ); 92 setPosition( mediaPlayerState.position() );
93 setFullscreen( mediaPlayerState.isFullscreen() ); 93 setFullscreen( mediaPlayerState.isFullscreen() );
94 setPlaying( mediaPlayerState.isPlaying() ); 94 setPlaying( mediaPlayerState.isPlaying() );
95} 95}
96 96
97 97
98VideoWidget::~VideoWidget() 98VideoWidget::~VideoWidget()
99{ 99{
100} 100}
101 101
102QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 102void VideoWidget::resizeEvent( QResizeEvent *e ) {
103 QPixmap pix( img.width(), img.height() );
104 QPainter p( &pix );
105 p.drawTiledPixmap( pix.rect(), bg, offset );
106 p.drawImage( 0, 0, img );
107 return new QPixmap( pix );
108}
109
110QPixmap maskVPixToMask( QPixmap pix, QBitmap mask ) {
111 QPixmap pixmap( pix );
112 pixmap.setMask( mask );
113 return pixmap;
114}
115
116void VideoWidget::resizeEvent( QResizeEvent * ) {
117 int h = height(); 103 int h = height();
118 int w = width(); 104 int w = width();
119 //int Vh = 160; 105 //int Vh = 160;
120 //int Vw = 220; 106 //int Vw = 220;
121 107
122 slider->setFixedWidth( w - 20 ); 108 slider->setFixedWidth( w - 20 );
123 slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); 109 slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) );
124 slider->setBackgroundOrigin( QWidget::ParentOrigin ); 110 slider->setBackgroundOrigin( QWidget::ParentOrigin );
125 slider->setFocusPolicy( QWidget::NoFocus ); 111 slider->setFocusPolicy( QWidget::NoFocus );
126 slider->setBackgroundPixmap( backgroundPixmap ); 112 slider->setBackgroundPixmap( backgroundPixmap );
127 113
128 upperLeftOfButtonMask.rx() = 0;// ( imgUp->width() ) / 2; 114 upperLeftOfButtonMask.rx() = 0;// ( imgUp->width() ) / 2;
129 if(w>h) 115 if(w>h)
130 upperLeftOfButtonMask.ry() = 0; 116 upperLeftOfButtonMask.ry() = 0;
131 else 117 else
132 upperLeftOfButtonMask.ry() = 185;//(( Vh - imgUp->height() ) / 2) - 10; 118 upperLeftOfButtonMask.ry() = 185;//(( Vh - imgUp->height() ) / 2) - 10;
133 QPoint p = upperLeftOfButtonMask;
134
135 QPixmap *pixUp = combineVImageWithBackground( buttonUpImage, backgroundPixmap, p );
136 QPixmap *pixDn = combineVImageWithBackground( buttonDownImage, backgroundPixmap, p );
137
138 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) {
139 Button &button = *it;
140
141 if ( !button.mask.isNull() ) {
142 button.pixUp = maskVPixToMask( *pixUp, button.mask );
143 button.pixDown = maskVPixToMask( *pixDn, button.mask );
144 }
145 }
146 119
147 delete pixUp; 120 MediaWidget::resizeEvent( e );
148 delete pixDn;
149} 121}
150 122
151void VideoWidget::sliderPressed() { 123void VideoWidget::sliderPressed() {
152 videoSliderBeingMoved = TRUE; 124 videoSliderBeingMoved = TRUE;
153} 125}
154 126
155void VideoWidget::sliderReleased() { 127void VideoWidget::sliderReleased() {
156 videoSliderBeingMoved = FALSE; 128 videoSliderBeingMoved = FALSE;
157 if ( slider->width() == 0 ) { 129 if ( slider->width() == 0 ) {
158 return; 130 return;
159 } 131 }
160 long val = long((double)slider->value() * mediaPlayerState.length() / slider->width()); 132 long val = long((double)slider->value() * mediaPlayerState.length() / slider->width());
161 mediaPlayerState.setPosition( val ); 133 mediaPlayerState.setPosition( val );
162} 134}
163 135
164void VideoWidget::setPosition( long i ) { 136void VideoWidget::setPosition( long i ) {
165 updateSlider( i, mediaPlayerState.length() ); 137 updateSlider( i, mediaPlayerState.length() );
166} 138}
167 139
168 140
169void VideoWidget::setLength( long max ) { 141void VideoWidget::setLength( long max ) {
170 updateSlider( mediaPlayerState.position(), max ); 142 updateSlider( mediaPlayerState.position(), max );
171} 143}
172 144
173void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType ) 145void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType )
174{ 146{
175 if ( displayType == MediaPlayerState::Video ) { 147 if ( displayType == MediaPlayerState::Video ) {
176 makeVisible(); 148 makeVisible();
177 return; 149 return;
178 } 150 }
179 151
180 // Effectively blank the view next time we show it so it looks nicer 152 // Effectively blank the view next time we show it so it looks nicer
181 scaledWidth = 0; 153 scaledWidth = 0;
182 scaledHeight = 0; 154 scaledHeight = 0;
183 hide(); 155 hide();
184} 156}
185 157
186void VideoWidget::loadSkin() 158void VideoWidget::loadSkin()
187{ 159{
188 loadDefaultSkin( skinInfo, buttonCount, "V" ); 160 loadDefaultSkin( skinInfo, buttonCount, "V" );
189 161
190 setBackgroundPixmap( backgroundPixmap ); 162 setBackgroundPixmap( backgroundPixmap );
191 163
192 delete slider; 164 delete slider;
193 slider = new QSlider( Qt::Horizontal, this ); 165 slider = new QSlider( Qt::Horizontal, this );
194 slider->setMinValue( 0 ); 166 slider->setMinValue( 0 );
195 slider->setMaxValue( 1 ); 167 slider->setMaxValue( 1 );
196 slider->setBackgroundPixmap( backgroundPixmap ); 168 slider->setBackgroundPixmap( backgroundPixmap );