author | simon <simon> | 2002-12-09 15:04:10 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-09 15:04:10 (UTC) |
commit | dcc1922ecb8c6816e4ae9ba7973f8653e482b2aa (patch) (unidiff) | |
tree | 5ff73aaf1ac1c59cde2e9ddafe8cebcddb162158 | |
parent | d3451a94e3a4425f9f1b1dcc3999259270780631 (diff) | |
download | opie-dcc1922ecb8c6816e4ae9ba7973f8653e482b2aa.zip opie-dcc1922ecb8c6816e4ae9ba7973f8653e482b2aa.tar.gz opie-dcc1922ecb8c6816e4ae9ba7973f8653e482b2aa.tar.bz2 |
- getting rid of the buttonPixUp/Down arrays, reuse the Button structure
instead
-rw-r--r-- | noncore/multimedia/opieplayer2/videowidget.cpp | 32 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/videowidget.h | 2 |
2 files changed, 12 insertions, 22 deletions
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp index 089ef6a..3baa087 100644 --- a/noncore/multimedia/opieplayer2/videowidget.cpp +++ b/noncore/multimedia/opieplayer2/videowidget.cpp | |||
@@ -105,105 +105,95 @@ VideoWidget::VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlaye | |||
105 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); | 105 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); |
106 | button.mask = QBitmap( filename ); | 106 | button.mask = QBitmap( filename ); |
107 | 107 | ||
108 | if ( !button.mask.isNull() ) { | 108 | if ( !button.mask.isNull() ) { |
109 | QImage imgMask = button.mask.convertToImage(); | 109 | QImage imgMask = button.mask.convertToImage(); |
110 | uchar **dest = buttonMask.jumpTable(); | 110 | uchar **dest = buttonMask.jumpTable(); |
111 | for ( int y = 0; y < imgUp.height(); y++ ) { | 111 | for ( int y = 0; y < imgUp.height(); y++ ) { |
112 | uchar *line = dest[y]; | 112 | uchar *line = dest[y]; |
113 | for ( int x = 0; x < imgUp.width(); x++ ) { | 113 | for ( int x = 0; x < imgUp.width(); x++ ) { |
114 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 114 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
115 | line[x] = i + 1; | 115 | line[x] = i + 1; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | for ( int i = 0; i < 7; i++ ) { | ||
122 | buttonPixUp[i] = NULL; | ||
123 | buttonPixDown[i] = NULL; | ||
124 | } | ||
125 | |||
126 | setBackgroundPixmap( pixBg ); | 121 | setBackgroundPixmap( pixBg ); |
127 | 122 | ||
128 | slider = new QSlider( Qt::Horizontal, this ); | 123 | slider = new QSlider( Qt::Horizontal, this ); |
129 | slider->setMinValue( 0 ); | 124 | slider->setMinValue( 0 ); |
130 | slider->setMaxValue( 1 ); | 125 | slider->setMaxValue( 1 ); |
131 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | 126 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); |
132 | //slider->setFocusPolicy( QWidget::NoFocus ); | 127 | //slider->setFocusPolicy( QWidget::NoFocus ); |
133 | 128 | ||
134 | resizeEvent( NULL ); | 129 | resizeEvent( NULL ); |
135 | 130 | ||
136 | setLength( mediaPlayerState.length() ); | 131 | setLength( mediaPlayerState.length() ); |
137 | setPosition( mediaPlayerState.position() ); | 132 | setPosition( mediaPlayerState.position() ); |
138 | setFullscreen( mediaPlayerState.isFullscreen() ); | 133 | setFullscreen( mediaPlayerState.isFullscreen() ); |
139 | setPlaying( mediaPlayerState.isPlaying() ); | 134 | setPlaying( mediaPlayerState.isPlaying() ); |
140 | } | 135 | } |
141 | 136 | ||
142 | 137 | ||
143 | VideoWidget::~VideoWidget() { | 138 | VideoWidget::~VideoWidget() |
144 | for ( int i = 0; i < 7; i++ ) { | 139 | { |
145 | delete buttonPixUp[i]; | ||
146 | delete buttonPixDown[i]; | ||
147 | } | ||
148 | } | 140 | } |
149 | 141 | ||
150 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 142 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
151 | QPixmap pix( img.width(), img.height() ); | 143 | QPixmap pix( img.width(), img.height() ); |
152 | QPainter p( &pix ); | 144 | QPainter p( &pix ); |
153 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 145 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
154 | p.drawImage( 0, 0, img ); | 146 | p.drawImage( 0, 0, img ); |
155 | return new QPixmap( pix ); | 147 | return new QPixmap( pix ); |
156 | } | 148 | } |
157 | 149 | ||
158 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { | 150 | QPixmap maskVPixToMask( QPixmap pix, QBitmap mask ) { |
159 | QPixmap *pixmap = new QPixmap( pix ); | 151 | QPixmap pixmap( pix ); |
160 | pixmap->setMask( mask ); | 152 | pixmap.setMask( mask ); |
161 | return pixmap; | 153 | return pixmap; |
162 | } | 154 | } |
163 | 155 | ||
164 | void VideoWidget::resizeEvent( QResizeEvent * ) { | 156 | void VideoWidget::resizeEvent( QResizeEvent * ) { |
165 | int h = height(); | 157 | int h = height(); |
166 | int w = width(); | 158 | int w = width(); |
167 | //int Vh = 160; | 159 | //int Vh = 160; |
168 | //int Vw = 220; | 160 | //int Vw = 220; |
169 | 161 | ||
170 | slider->setFixedWidth( w - 20 ); | 162 | slider->setFixedWidth( w - 20 ); |
171 | slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); | 163 | slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
172 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); | 164 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); |
173 | slider->setFocusPolicy( QWidget::NoFocus ); | 165 | slider->setFocusPolicy( QWidget::NoFocus ); |
174 | slider->setBackgroundPixmap( pixBg ); | 166 | slider->setBackgroundPixmap( pixBg ); |
175 | 167 | ||
176 | upperLeftOfButtonMask.rx() = 0;// ( imgUp->width() ) / 2; | 168 | upperLeftOfButtonMask.rx() = 0;// ( imgUp->width() ) / 2; |
177 | if(w>h) | 169 | if(w>h) |
178 | upperLeftOfButtonMask.ry() = 0; | 170 | upperLeftOfButtonMask.ry() = 0; |
179 | else | 171 | else |
180 | upperLeftOfButtonMask.ry() = 185;//(( Vh - imgUp->height() ) / 2) - 10; | 172 | upperLeftOfButtonMask.ry() = 185;//(( Vh - imgUp->height() ) / 2) - 10; |
181 | QPoint p = upperLeftOfButtonMask; | 173 | QPoint p = upperLeftOfButtonMask; |
182 | 174 | ||
183 | QPixmap *pixUp = combineVImageWithBackground( imgUp, pixBg, p ); | 175 | QPixmap *pixUp = combineVImageWithBackground( imgUp, pixBg, p ); |
184 | QPixmap *pixDn = combineVImageWithBackground( imgDn, pixBg, p ); | 176 | QPixmap *pixDn = combineVImageWithBackground( imgDn, pixBg, p ); |
185 | 177 | ||
186 | for ( int i = 0; i < 7; i++ ) { | 178 | for ( int i = 0; i < 7; i++ ) { |
187 | Button &button = buttons[ i ]; | 179 | Button &button = buttons[ i ]; |
188 | 180 | ||
189 | if ( !button.mask.isNull() ) { | 181 | if ( !button.mask.isNull() ) { |
190 | delete buttonPixUp[i]; | 182 | button.pixUp = maskVPixToMask( *pixUp, button.mask ); |
191 | delete buttonPixDown[i]; | 183 | button.pixDown = maskVPixToMask( *pixDn, button.mask ); |
192 | buttonPixUp[i] = maskVPixToMask( *pixUp, button.mask ); | ||
193 | buttonPixDown[i] = maskVPixToMask( *pixDn, button.mask ); | ||
194 | } | 184 | } |
195 | } | 185 | } |
196 | 186 | ||
197 | delete pixUp; | 187 | delete pixUp; |
198 | delete pixDn; | 188 | delete pixDn; |
199 | } | 189 | } |
200 | 190 | ||
201 | static bool videoSliderBeingMoved = FALSE; | 191 | static bool videoSliderBeingMoved = FALSE; |
202 | 192 | ||
203 | void VideoWidget::sliderPressed() { | 193 | void VideoWidget::sliderPressed() { |
204 | videoSliderBeingMoved = TRUE; | 194 | videoSliderBeingMoved = TRUE; |
205 | } | 195 | } |
206 | 196 | ||
207 | void VideoWidget::sliderReleased() { | 197 | void VideoWidget::sliderReleased() { |
208 | videoSliderBeingMoved = FALSE; | 198 | videoSliderBeingMoved = FALSE; |
209 | if ( slider->width() == 0 ) { | 199 | if ( slider->width() == 0 ) { |
@@ -247,36 +237,38 @@ void VideoWidget::updateSlider( long i, long max ) { | |||
247 | slider->setValue( val ); | 237 | slider->setValue( val ); |
248 | } | 238 | } |
249 | if ( slider->maxValue() != width ) { | 239 | if ( slider->maxValue() != width ) { |
250 | slider->setMaxValue( width ); | 240 | slider->setMaxValue( width ); |
251 | } | 241 | } |
252 | } | 242 | } |
253 | } | 243 | } |
254 | 244 | ||
255 | void VideoWidget::setToggleButton( int i, bool down ) { | 245 | void VideoWidget::setToggleButton( int i, bool down ) { |
256 | if ( down != buttons[i].isDown ) { | 246 | if ( down != buttons[i].isDown ) { |
257 | toggleButton( i ); | 247 | toggleButton( i ); |
258 | } | 248 | } |
259 | } | 249 | } |
260 | 250 | ||
261 | void VideoWidget::paintButton( QPainter &p, int i ) { | 251 | void VideoWidget::paintButton( QPainter &p, int i ) { |
262 | 252 | ||
263 | if ( buttons[i].isDown ) { | 253 | Button &button = buttons[ i ]; |
264 | p.drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] ); | 254 | |
255 | if ( button.isDown ) { | ||
256 | p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); | ||
265 | } else { | 257 | } else { |
266 | p.drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] ); | 258 | p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); |
267 | } | 259 | } |
268 | } | 260 | } |
269 | 261 | ||
270 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { | 262 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { |
271 | for ( unsigned int i = 0; i < buttons.count(); i++ ) { | 263 | for ( unsigned int i = 0; i < buttons.count(); i++ ) { |
272 | if ( event->state() == QMouseEvent::LeftButton ) { | 264 | if ( event->state() == QMouseEvent::LeftButton ) { |
273 | // The test to see if the mouse click is inside the button or not | 265 | // The test to see if the mouse click is inside the button or not |
274 | bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); | 266 | bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); |
275 | 267 | ||
276 | if ( isOnButton && !buttons[i].isHeld ) { | 268 | if ( isOnButton && !buttons[i].isHeld ) { |
277 | buttons[i].isHeld = TRUE; | 269 | buttons[i].isHeld = TRUE; |
278 | toggleButton(i); | 270 | toggleButton(i); |
279 | 271 | ||
280 | switch (i) { | 272 | switch (i) { |
281 | case VideoVolUp: | 273 | case VideoVolUp: |
282 | emit moreClicked(); | 274 | emit moreClicked(); |
diff --git a/noncore/multimedia/opieplayer2/videowidget.h b/noncore/multimedia/opieplayer2/videowidget.h index fd301f9..aeb6429 100644 --- a/noncore/multimedia/opieplayer2/videowidget.h +++ b/noncore/multimedia/opieplayer2/videowidget.h | |||
@@ -87,34 +87,32 @@ signals: | |||
87 | 87 | ||
88 | protected: | 88 | protected: |
89 | 89 | ||
90 | void resizeEvent( QResizeEvent * ); | 90 | void resizeEvent( QResizeEvent * ); |
91 | void paintEvent( QPaintEvent *pe ); | 91 | void paintEvent( QPaintEvent *pe ); |
92 | void showEvent( QShowEvent *se ); | 92 | void showEvent( QShowEvent *se ); |
93 | void mouseMoveEvent( QMouseEvent *event ); | 93 | void mouseMoveEvent( QMouseEvent *event ); |
94 | void mousePressEvent( QMouseEvent *event ); | 94 | void mousePressEvent( QMouseEvent *event ); |
95 | void mouseReleaseEvent( QMouseEvent *event ); | 95 | void mouseReleaseEvent( QMouseEvent *event ); |
96 | void keyReleaseEvent( QKeyEvent *e); | 96 | void keyReleaseEvent( QKeyEvent *e); |
97 | 97 | ||
98 | private: | 98 | private: |
99 | // Ticker songInfo; | 99 | // Ticker songInfo; |
100 | QPixmap pixBg; | 100 | QPixmap pixBg; |
101 | QImage imgUp; | 101 | QImage imgUp; |
102 | QImage imgDn; | 102 | QImage imgDn; |
103 | QPixmap *buttonPixUp[7]; | ||
104 | QPixmap *buttonPixDown[7]; | ||
105 | QString skin; | 103 | QString skin; |
106 | 104 | ||
107 | 105 | ||
108 | virtual void paintButton( QPainter &p, int i ); | 106 | virtual void paintButton( QPainter &p, int i ); |
109 | void setToggleButton( int, bool ); | 107 | void setToggleButton( int, bool ); |
110 | 108 | ||
111 | QString backgroundPix; | 109 | QString backgroundPix; |
112 | QSlider *slider; | 110 | QSlider *slider; |
113 | QPixmap *pixmaps[3]; | 111 | QPixmap *pixmaps[3]; |
114 | QImage *currentFrame; | 112 | QImage *currentFrame; |
115 | int scaledWidth; | 113 | int scaledWidth; |
116 | int scaledHeight; | 114 | int scaledHeight; |
117 | XineVideoWidget* videoFrame; | 115 | XineVideoWidget* videoFrame; |
118 | }; | 116 | }; |
119 | 117 | ||
120 | #endif // VIDEO_WIDGET_H | 118 | #endif // VIDEO_WIDGET_H |