summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-09 13:52:00 (UTC)
committer simon <simon>2002-12-09 13:52:00 (UTC)
commit46bca195f0dacc3b596eb1537ae47bc2117ce8e4 (patch) (unidiff)
tree135414127395da9466d77ef71fa85bd41b130bf0
parent374d7ba11f669449900c7e93f7929d724eb85f26 (diff)
downloadopie-46bca195f0dacc3b596eb1537ae47bc2117ce8e4.zip
opie-46bca195f0dacc3b596eb1537ae47bc2117ce8e4.tar.gz
opie-46bca195f0dacc3b596eb1537ae47bc2117ce8e4.tar.bz2
- isToggle is now an enum ButtonType { NormalButton, ToggleButton };
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp10
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.h5
-rw-r--r--noncore/multimedia/opieplayer2/videowidget.cpp8
3 files changed, 10 insertions, 13 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index 8659971..56b75f2 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -1,179 +1,177 @@
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 char * const skin_mask_file_names[10] = { 59const char * const skin_mask_file_names[10] = {
60 "play", "stop", "next", "prev", "up", 60 "play", "stop", "next", "prev", "up",
61 "down", "loop", "playlist", "forward", "back" 61 "down", "loop", "playlist", "forward", "back"
62}; 62};
63 63
64void changeTextColor( QWidget * w) { 64void changeTextColor( QWidget * w) {
65 QPalette p = w->palette(); 65 QPalette p = w->palette();
66 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); 66 p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) );
67 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); 67 p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) );
68 w->setPalette( p ); 68 w->setPalette( p );
69} 69}
70 70
71} 71}
72 72
73AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : 73AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) :
74 74
75 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ), 75 MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ),
76 audioSliderBeingMoved( false ) 76 audioSliderBeingMoved( false )
77{ 77{
78 Button defaultButton;
78 79
79 Button defaultButton; 80 Button toggleButton = defaultButton;
80 defaultButton.isToggle = defaultButton.isHeld = defaultButton.isDown = false; 81 toggleButton.buttonType = ToggleButton;
81 Button toggleButton;
82 toggleButton.isToggle = true;
83 toggleButton.isHeld = toggleButton.isDown = false;
84 82
85 buttons.reserve( 10 ); 83 buttons.reserve( 10 );
86 buttons.push_back( toggleButton ); // play 84 buttons.push_back( toggleButton ); // play
87 buttons.push_back( defaultButton ); // stop 85 buttons.push_back( defaultButton ); // stop
88 buttons.push_back( defaultButton ); // next 86 buttons.push_back( defaultButton ); // next
89 buttons.push_back( defaultButton ); // previous 87 buttons.push_back( defaultButton ); // previous
90 buttons.push_back( defaultButton ); // volume up 88 buttons.push_back( defaultButton ); // volume up
91 buttons.push_back( defaultButton ); // volume down 89 buttons.push_back( defaultButton ); // volume down
92 buttons.push_back( toggleButton ); // repeat/loop 90 buttons.push_back( toggleButton ); // repeat/loop
93 buttons.push_back( defaultButton ); // playlist 91 buttons.push_back( defaultButton ); // playlist
94 buttons.push_back( defaultButton ); // forward 92 buttons.push_back( defaultButton ); // forward
95 buttons.push_back( defaultButton ); // back 93 buttons.push_back( defaultButton ); // back
96 94
97 setCaption( tr("OpiePlayer") ); 95 setCaption( tr("OpiePlayer") );
98 96
99 Config cfg("OpiePlayer"); 97 Config cfg("OpiePlayer");
100 cfg.setGroup("Options"); 98 cfg.setGroup("Options");
101 skin = cfg.readEntry("Skin","default"); 99 skin = cfg.readEntry("Skin","default");
102 //skin = "scaleTest"; 100 //skin = "scaleTest";
103 // color of background, frame, degree of transparency 101 // color of background, frame, degree of transparency
104 102
105 QString skinPath = "opieplayer2/skins/" + skin; 103 QString skinPath = "opieplayer2/skins/" + skin;
106 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); 104 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) );
107 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); 105 imgUp = QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) );
108 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); 106 imgDn = QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) );
109 107
110 buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); 108 buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 );
111 buttonMask.fill( 0 ); 109 buttonMask.fill( 0 );
112 110
113 masks.reserve( 10 ); 111 masks.reserve( 10 );
114 112
115 for ( uint i = 0; i < masks.capacity(); i++ ) { 113 for ( uint i = 0; i < masks.capacity(); i++ ) {
116 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" ); 114 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png" );
117 masks.push_back( QBitmap( filename ) ); 115 masks.push_back( QBitmap( filename ) );
118 116
119 if ( !masks[i].isNull() ) { 117 if ( !masks[i].isNull() ) {
120 QImage imgMask = masks[i].convertToImage(); 118 QImage imgMask = masks[i].convertToImage();
121 uchar **dest = buttonMask.jumpTable(); 119 uchar **dest = buttonMask.jumpTable();
122 for ( int y = 0; y < imgUp.height(); y++ ) { 120 for ( int y = 0; y < imgUp.height(); y++ ) {
123 uchar *line = dest[y]; 121 uchar *line = dest[y];
124 for ( int x = 0; x < imgUp.width(); x++ ) 122 for ( int x = 0; x < imgUp.width(); x++ )
125 if ( !qRed( imgMask.pixel( x, y ) ) ) 123 if ( !qRed( imgMask.pixel( x, y ) ) )
126 line[x] = i + 1; 124 line[x] = i + 1;
127 } 125 }
128 } 126 }
129 127
130 } 128 }
131 129
132 buttonPixUp.resize( masks.size(), QPixmap() ); 130 buttonPixUp.resize( masks.size(), QPixmap() );
133 buttonPixDown.resize( masks.size(), QPixmap() ); 131 buttonPixDown.resize( masks.size(), QPixmap() );
134 132
135 setBackgroundPixmap( pixBg ); 133 setBackgroundPixmap( pixBg );
136 134
137 songInfo.setFocusPolicy( QWidget::NoFocus ); 135 songInfo.setFocusPolicy( QWidget::NoFocus );
138// changeTextColor( &songInfo ); 136// changeTextColor( &songInfo );
139// songInfo.setBackgroundColor( QColor( 167, 212, 167 )); 137// songInfo.setBackgroundColor( QColor( 167, 212, 167 ));
140// songInfo.setFrameStyle( QFrame::NoFrame); 138// songInfo.setFrameStyle( QFrame::NoFrame);
141 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 139 songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
142// songInfo.setForegroundColor(Qt::white); 140// songInfo.setForegroundColor(Qt::white);
143 141
144 slider.setFixedHeight( 20 ); 142 slider.setFixedHeight( 20 );
145 slider.setMinValue( 0 ); 143 slider.setMinValue( 0 );
146 slider.setMaxValue( 1 ); 144 slider.setMaxValue( 1 );
147 slider.setFocusPolicy( QWidget::NoFocus ); 145 slider.setFocusPolicy( QWidget::NoFocus );
148 slider.setBackgroundPixmap( pixBg ); 146 slider.setBackgroundPixmap( pixBg );
149 147
150// Config cofg("qpe"); 148// Config cofg("qpe");
151// cofg.setGroup("Appearance"); 149// cofg.setGroup("Appearance");
152// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); 150// QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) );
153 151
154 time.setFocusPolicy( QWidget::NoFocus ); 152 time.setFocusPolicy( QWidget::NoFocus );
155 time.setAlignment( Qt::AlignCenter ); 153 time.setAlignment( Qt::AlignCenter );
156 154
157// time.setFrame(FALSE); 155// time.setFrame(FALSE);
158// changeTextColor( &time ); 156// changeTextColor( &time );
159 157
160 resizeEvent( NULL ); 158 resizeEvent( NULL );
161 159
162 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 160 connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
163 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) ); 161 connect( &mediaPlayerState, SIGNAL( isSeekableToggled( bool ) ), this, SLOT( setSeekable( bool ) ) );
164 162
165 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); 163 connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) );
166 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); 164 connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) );
167 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); 165 connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) );
168 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); 166 connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) );
169 167
170 // Intialise state 168 // Intialise state
171 setLength( mediaPlayerState.length() ); 169 setLength( mediaPlayerState.length() );
172 setPosition( mediaPlayerState.position() ); 170 setPosition( mediaPlayerState.position() );
173 setLooping( mediaPlayerState.isFullscreen() ); 171 setLooping( mediaPlayerState.isFullscreen() );
174 // setPaused( mediaPlayerState->paused() ); 172 // setPaused( mediaPlayerState->paused() );
175 setPlaying( mediaPlayerState.isPlaying() ); 173 setPlaying( mediaPlayerState.isPlaying() );
176 174
177} 175}
178 176
179AudioWidget::~AudioWidget() { 177AudioWidget::~AudioWidget() {
@@ -296,192 +294,192 @@ void AudioWidget::updateSlider( long i, long max ) {
296 time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); 294 time.setText( timeAsString( i ) + " / " + timeAsString( max ) );
297// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; 295// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ;
298 296
299 if ( max == 0 ) { 297 if ( max == 0 ) {
300 return; 298 return;
301 } 299 }
302 // Will flicker too much if we don't do this 300 // Will flicker too much if we don't do this
303 // Scale to something reasonable 301 // Scale to something reasonable
304 int width = slider.width(); 302 int width = slider.width();
305 int val = int((double)i * width / max); 303 int val = int((double)i * width / max);
306 if ( !audioSliderBeingMoved ) { 304 if ( !audioSliderBeingMoved ) {
307 if ( slider.value() != val ) { 305 if ( slider.value() != val ) {
308 slider.setValue( val ); 306 slider.setValue( val );
309 } 307 }
310 308
311 if ( slider.maxValue() != width ) { 309 if ( slider.maxValue() != width ) {
312 slider.setMaxValue( width ); 310 slider.setMaxValue( width );
313 } 311 }
314 } 312 }
315} 313}
316 314
317 315
318void AudioWidget::setToggleButton( int i, bool down ) { 316void AudioWidget::setToggleButton( int i, bool down ) {
319 qDebug("setToggleButton %d", i); 317 qDebug("setToggleButton %d", i);
320 if ( down != buttons[i].isDown ) { 318 if ( down != buttons[i].isDown ) {
321 toggleButton( i ); 319 toggleButton( i );
322 } 320 }
323} 321}
324 322
325void AudioWidget::paintButton( QPainter &p, int i ) { 323void AudioWidget::paintButton( QPainter &p, int i ) {
326 if ( buttons[i].isDown ) { 324 if ( buttons[i].isDown ) {
327 p.drawPixmap( upperLeftOfButtonMask, buttonPixDown[i] ); 325 p.drawPixmap( upperLeftOfButtonMask, buttonPixDown[i] );
328 } else { 326 } else {
329 p.drawPixmap( upperLeftOfButtonMask, buttonPixUp[i] ); 327 p.drawPixmap( upperLeftOfButtonMask, buttonPixUp[i] );
330 } 328 }
331} 329}
332 330
333 331
334void AudioWidget::skipFor() { 332void AudioWidget::skipFor() {
335 skipDirection = +1; 333 skipDirection = +1;
336 startTimer( 50 ); 334 startTimer( 50 );
337 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 335 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
338} 336}
339 337
340void AudioWidget::skipBack() { 338void AudioWidget::skipBack() {
341 skipDirection = -1; 339 skipDirection = -1;
342 startTimer( 50 ); 340 startTimer( 50 );
343 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 341 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
344} 342}
345 343
346 344
347 345
348void AudioWidget::stopSkip() { 346void AudioWidget::stopSkip() {
349 killTimers(); 347 killTimers();
350} 348}
351 349
352 350
353void AudioWidget::timerEvent( QTimerEvent * ) { 351void AudioWidget::timerEvent( QTimerEvent * ) {
354 if ( skipDirection == +1 ) { 352 if ( skipDirection == +1 ) {
355 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); 353 mediaPlayerState.setPosition( mediaPlayerState.position() + 2 );
356 } else if ( skipDirection == -1 ) { 354 } else if ( skipDirection == -1 ) {
357 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); 355 mediaPlayerState.setPosition( mediaPlayerState.position() - 2 );
358 } 356 }
359} 357}
360 358
361 359
362void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 360void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
363 for ( unsigned int i = 0; i < buttons.size(); i++ ) { 361 for ( unsigned int i = 0; i < buttons.size(); i++ ) {
364 if ( event->state() == QMouseEvent::LeftButton ) { 362 if ( event->state() == QMouseEvent::LeftButton ) {
365 // The test to see if the mouse click is inside the button or not 363 // The test to see if the mouse click is inside the button or not
366 bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); 364 bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i );
367 365
368 if ( isOnButton && !buttons[i].isHeld ) { 366 if ( isOnButton && !buttons[i].isHeld ) {
369 buttons[i].isHeld = TRUE; 367 buttons[i].isHeld = TRUE;
370 toggleButton(i); 368 toggleButton(i);
371 switch (i) { 369 switch (i) {
372 case VolumeUp: 370 case VolumeUp:
373 emit moreClicked(); 371 emit moreClicked();
374 return; 372 return;
375 case VolumeDown: 373 case VolumeDown:
376 emit lessClicked(); 374 emit lessClicked();
377 return; 375 return;
378 case Forward: 376 case Forward:
379 emit forwardClicked(); 377 emit forwardClicked();
380 return; 378 return;
381 case Back: 379 case Back:
382 emit backClicked(); 380 emit backClicked();
383 return; 381 return;
384 } 382 }
385 } else if ( !isOnButton && buttons[i].isHeld ) { 383 } else if ( !isOnButton && buttons[i].isHeld ) {
386 buttons[i].isHeld = FALSE; 384 buttons[i].isHeld = FALSE;
387 toggleButton(i); 385 toggleButton(i);
388 } 386 }
389 } else { 387 } else {
390 if ( buttons[i].isHeld ) { 388 if ( buttons[i].isHeld ) {
391 buttons[i].isHeld = FALSE; 389 buttons[i].isHeld = FALSE;
392 if ( !buttons[i].isToggle ) { 390 if ( buttons[i].buttonType != ToggleButton ) {
393 setToggleButton( i, FALSE ); 391 setToggleButton( i, FALSE );
394 } 392 }
395 qDebug("mouseEvent %d", i); 393 qDebug("mouseEvent %d", i);
396 handleCommand( static_cast<Command>( i ), buttons[ i ].isDown ); 394 handleCommand( static_cast<Command>( i ), buttons[ i ].isDown );
397 } 395 }
398 } 396 }
399 } 397 }
400} 398}
401 399
402 400
403void AudioWidget::mousePressEvent( QMouseEvent *event ) { 401void AudioWidget::mousePressEvent( QMouseEvent *event ) {
404 mouseMoveEvent( event ); 402 mouseMoveEvent( event );
405} 403}
406 404
407 405
408void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { 406void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
409 mouseMoveEvent( event ); 407 mouseMoveEvent( event );
410} 408}
411 409
412 410
413void AudioWidget::showEvent( QShowEvent* ) { 411void AudioWidget::showEvent( QShowEvent* ) {
414 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 412 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
415 mouseMoveEvent( &event ); 413 mouseMoveEvent( &event );
416} 414}
417 415
418 416
419void AudioWidget::paintEvent( QPaintEvent * pe ) { 417void AudioWidget::paintEvent( QPaintEvent * pe ) {
420 if ( !pe->erased() ) { 418 if ( !pe->erased() ) {
421 // Combine with background and double buffer 419 // Combine with background and double buffer
422 QPixmap pix( pe->rect().size() ); 420 QPixmap pix( pe->rect().size() );
423 QPainter p( &pix ); 421 QPainter p( &pix );
424 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 422 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
425 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() ); 423 p.drawTiledPixmap( pe->rect(), pixBg, pe->rect().topLeft() );
426 for ( unsigned int i = 0; i < buttons.size(); i++ ) 424 for ( unsigned int i = 0; i < buttons.size(); i++ )
427 paintButton( p, i ); 425 paintButton( p, i );
428 QPainter p2( this ); 426 QPainter p2( this );
429 p2.drawPixmap( pe->rect().topLeft(), pix ); 427 p2.drawPixmap( pe->rect().topLeft(), pix );
430 } else { 428 } else {
431 QPainter p( this ); 429 QPainter p( this );
432 for ( unsigned int i = 0; i < buttons.size(); i++ ) 430 for ( unsigned int i = 0; i < buttons.size(); i++ )
433 paintButton( p, i ); 431 paintButton( p, i );
434 } 432 }
435} 433}
436 434
437void AudioWidget::keyReleaseEvent( QKeyEvent *e) { 435void AudioWidget::keyReleaseEvent( QKeyEvent *e) {
438 switch ( e->key() ) { 436 switch ( e->key() ) {
439 ////////////////////////////// Zaurus keys 437 ////////////////////////////// Zaurus keys
440 case Key_Home: 438 case Key_Home:
441 break; 439 break;
442 case Key_F9: //activity 440 case Key_F9: //activity
443 hide(); 441 hide();
444 // qDebug("Audio F9"); 442 // qDebug("Audio F9");
445 break; 443 break;
446 case Key_F10: //contacts 444 case Key_F10: //contacts
447 break; 445 break;
448 case Key_F11: //menu 446 case Key_F11: //menu
449 mediaPlayerState.toggleBlank(); 447 mediaPlayerState.toggleBlank();
450 break; 448 break;
451 case Key_F12: //home 449 case Key_F12: //home
452 break; 450 break;
453 case Key_F13: //mail 451 case Key_F13: //mail
454 mediaPlayerState.toggleBlank(); 452 mediaPlayerState.toggleBlank();
455 break; 453 break;
456 case Key_Space: { 454 case Key_Space: {
457 mediaPlayerState.togglePaused(); 455 mediaPlayerState.togglePaused();
458 } 456 }
459 break; 457 break;
460 case Key_Down: 458 case Key_Down:
461 // toggleButton(6); 459 // toggleButton(6);
462 emit lessClicked(); 460 emit lessClicked();
463 emit lessReleased(); 461 emit lessReleased();
464 // toggleButton(6); 462 // toggleButton(6);
465 break; 463 break;
466 case Key_Up: 464 case Key_Up:
467 // toggleButton(5); 465 // toggleButton(5);
468 emit moreClicked(); 466 emit moreClicked();
469 emit moreReleased(); 467 emit moreReleased();
470 // toggleButton(5); 468 // toggleButton(5);
471 break; 469 break;
472 case Key_Right: 470 case Key_Right:
473 // toggleButton(3); 471 // toggleButton(3);
474 mediaPlayerState.setNext(); 472 mediaPlayerState.setNext();
475 // toggleButton(3); 473 // toggleButton(3);
476 break; 474 break;
477 case Key_Left: 475 case Key_Left:
478 // toggleButton(4); 476 // toggleButton(4);
479 mediaPlayerState.setPrev(); 477 mediaPlayerState.setPrev();
480 // toggleButton(4); 478 // toggleButton(4);
481 break; 479 break;
482 case Key_Escape: { 480 case Key_Escape: {
483 } 481 }
484 break; 482 break;
485 483
486 }; 484 };
487} 485}
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h
index 46c304d..aa8891f 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.h
+++ b/noncore/multimedia/opieplayer2/mediawidget.h
@@ -1,87 +1,88 @@
1/* 1/*
2 Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> 2 Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
3 (C) 2002 Max Reiss <harlekin@handhelds.org> 3 (C) 2002 Max Reiss <harlekin@handhelds.org>
4 (C) 2002 L. Potter <ljp@llornkcor.com> 4 (C) 2002 L. Potter <ljp@llornkcor.com>
5 (C) 2002 Holger Freyther <zecke@handhelds.org> 5 (C) 2002 Holger Freyther <zecke@handhelds.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#ifndef MEDIAWIDGET_H 23#ifndef MEDIAWIDGET_H
24#define MEDIAWIDGET_H 24#define MEDIAWIDGET_H
25 25
26#include <qwidget.h> 26#include <qwidget.h>
27 27
28#include "mediaplayerstate.h" 28#include "mediaplayerstate.h"
29#include "playlistwidget.h" 29#include "playlistwidget.h"
30 30
31#include <vector> 31#include <vector>
32 32
33class MediaWidget : public QWidget 33class MediaWidget : public QWidget
34{ 34{
35 Q_OBJECT 35 Q_OBJECT
36public: 36public:
37 enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back }; 37 enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back };
38 enum ButtonType { NormalButton, ToggleButton };
38 39
39 struct Button 40 struct Button
40 { 41 {
41 Button() : isToggle( false ), isHeld( false ), isDown( false ) {} 42 Button() : buttonType( NormalButton ), isHeld( false ), isDown( false ) {}
42 43
43 bool isToggle : 1; 44 ButtonType buttonType : 1;
44 bool isHeld : 1; 45 bool isHeld : 1;
45 bool isDown : 1; 46 bool isDown : 1;
46 }; 47 };
47 typedef std::vector<Button> ButtonVector; 48 typedef std::vector<Button> ButtonVector;
48 49
49 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); 50 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 );
50 virtual ~MediaWidget(); 51 virtual ~MediaWidget();
51 52
52public slots: 53public slots:
53 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; 54 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0;
54 virtual void setLength( long length ) = 0; 55 virtual void setLength( long length ) = 0;
55 virtual void setPlaying( bool playing ) = 0; 56 virtual void setPlaying( bool playing ) = 0;
56 57
57signals: 58signals:
58 void moreReleased(); 59 void moreReleased();
59 void lessReleased(); 60 void lessReleased();
60 void forwardReleased(); 61 void forwardReleased();
61 void backReleased(); 62 void backReleased();
62 63
63protected: 64protected:
64 virtual void closeEvent( QCloseEvent * ); 65 virtual void closeEvent( QCloseEvent * );
65 66
66 void handleCommand( Command command, bool buttonDown ); 67 void handleCommand( Command command, bool buttonDown );
67 68
68 bool isOverButton( const QPoint &position, int buttonId ) const; 69 bool isOverButton( const QPoint &position, int buttonId ) const;
69 70
70 void paintButton( int buttonId ); 71 void paintButton( int buttonId );
71 virtual void paintButton( QPainter &p, int i ) = 0; 72 virtual void paintButton( QPainter &p, int i ) = 0;
72 73
73 void toggleButton( int buttonId ); 74 void toggleButton( int buttonId );
74 75
75 MediaPlayerState &mediaPlayerState; 76 MediaPlayerState &mediaPlayerState;
76 PlayListWidget &playList; 77 PlayListWidget &playList;
77 78
78 ButtonVector buttons; 79 ButtonVector buttons;
79 80
80 QImage buttonMask; 81 QImage buttonMask;
81 82
82 QPoint upperLeftOfButtonMask; 83 QPoint upperLeftOfButtonMask;
83}; 84};
84 85
85#endif // MEDIAWIDGET_H 86#endif // MEDIAWIDGET_H
86/* vim: et sw=4 ts=4 87/* vim: et sw=4 ts=4
87 */ 88 */
diff --git a/noncore/multimedia/opieplayer2/videowidget.cpp b/noncore/multimedia/opieplayer2/videowidget.cpp
index 2f51c82..23acfa3 100644
--- a/noncore/multimedia/opieplayer2/videowidget.cpp
+++ b/noncore/multimedia/opieplayer2/videowidget.cpp
@@ -1,173 +1,171 @@
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 37
38 38
39#include <qwidget.h> 39#include <qwidget.h>
40#include <qpainter.h> 40#include <qpainter.h>
41#include <qpixmap.h> 41#include <qpixmap.h>
42#include <qslider.h> 42#include <qslider.h>
43#include <qdrawutil.h> 43#include <qdrawutil.h>
44#include "videowidget.h" 44#include "videowidget.h"
45#include "mediaplayerstate.h" 45#include "mediaplayerstate.h"
46#include "playlistwidget.h" 46#include "playlistwidget.h"
47 47
48 48
49#ifdef Q_WS_QWS 49#ifdef Q_WS_QWS
50# define USE_DIRECT_PAINTER 50# define USE_DIRECT_PAINTER
51# include <qdirectpainter_qws.h> 51# include <qdirectpainter_qws.h>
52# include <qgfxraster_qws.h> 52# include <qgfxraster_qws.h>
53#endif 53#endif
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 char * const skinV_mask_file_names[7] = { 62const char * const skinV_mask_file_names[7] = {
63"play","stop","fwd","back","up","down","full" 63"play","stop","fwd","back","up","down","full"
64}; 64};
65 65
66} 66}
67 67
68VideoWidget::VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name ) 68VideoWidget::VideoWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name )
69 : MediaWidget( playList, mediaPlayerState, parent, name ), scaledWidth( 0 ), scaledHeight( 0 ) 69 : MediaWidget( playList, mediaPlayerState, parent, name ), scaledWidth( 0 ), scaledHeight( 0 )
70{ 70{
71 setCaption( tr("OpiePlayer - Video") ); 71 setCaption( tr("OpiePlayer - Video") );
72 72
73 Button defaultButton; 73 Button defaultButton;
74 defaultButton.isToggle = defaultButton.isHeld = defaultButton.isDown = false; 74 Button toggleButton = defaultButton;
75 Button toggleButton; 75 toggleButton.buttonType = ToggleButton;
76 toggleButton.isToggle = true;
77 toggleButton.isHeld = toggleButton.isDown = false;
78 76
79 buttons.reserve( 7 ); 77 buttons.reserve( 7 );
80 buttons.push_back( toggleButton ); // play 78 buttons.push_back( toggleButton ); // play
81 buttons.push_back( defaultButton ); // stop 79 buttons.push_back( defaultButton ); // stop
82 buttons.push_back( defaultButton ); // next 80 buttons.push_back( defaultButton ); // next
83 buttons.push_back( defaultButton ); // previous 81 buttons.push_back( defaultButton ); // previous
84 buttons.push_back( defaultButton ); // volUp 82 buttons.push_back( defaultButton ); // volUp
85 buttons.push_back( defaultButton ); // volDown 83 buttons.push_back( defaultButton ); // volDown
86 buttons.push_back( toggleButton ); //fullscreen 84 buttons.push_back( toggleButton ); //fullscreen
87 85
88 videoFrame = new XineVideoWidget ( this, "Video frame" ); 86 videoFrame = new XineVideoWidget ( this, "Video frame" );
89 87
90 connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & ))); 88 connect ( videoFrame, SIGNAL( videoResized ( const QSize & )), this, SIGNAL( videoResized ( const QSize & )));
91 connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) ); 89 connect ( videoFrame, SIGNAL( clicked () ), this, SLOT ( backToNormal() ) );
92 90
93 Config cfg("OpiePlayer"); 91 Config cfg("OpiePlayer");
94 cfg.setGroup("Options"); 92 cfg.setGroup("Options");
95 skin = cfg.readEntry("Skin","default"); 93 skin = cfg.readEntry("Skin","default");
96 94
97 QString skinPath = "opieplayer2/skins/" + skin; 95 QString skinPath = "opieplayer2/skins/" + skin;
98 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); 96 pixBg = QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) );
99 imgUp = QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); 97 imgUp = QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) );
100 imgDn = QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); 98 imgDn = QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) );
101 99
102 buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 ); 100 buttonMask = QImage( imgUp.width(), imgUp.height(), 8, 255 );
103 buttonMask.fill( 0 ); 101 buttonMask.fill( 0 );
104 102
105 for ( int i = 0; i < 7; i++ ) { 103 for ( int i = 0; i < 7; i++ ) {
106 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); 104 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + "/skinV_mask_" + skinV_mask_file_names[i] + ".png" );
107 masks[i] = new QBitmap( filename ); 105 masks[i] = new QBitmap( filename );
108 106
109 if ( !masks[i]->isNull() ) { 107 if ( !masks[i]->isNull() ) {
110 QImage imgMask = masks[i]->convertToImage(); 108 QImage imgMask = masks[i]->convertToImage();
111 uchar **dest = buttonMask.jumpTable(); 109 uchar **dest = buttonMask.jumpTable();
112 for ( int y = 0; y < imgUp.height(); y++ ) { 110 for ( int y = 0; y < imgUp.height(); y++ ) {
113 uchar *line = dest[y]; 111 uchar *line = dest[y];
114 for ( int x = 0; x < imgUp.width(); x++ ) { 112 for ( int x = 0; x < imgUp.width(); x++ ) {
115 if ( !qRed( imgMask.pixel( x, y ) ) ) 113 if ( !qRed( imgMask.pixel( x, y ) ) )
116 line[x] = i + 1; 114 line[x] = i + 1;
117 } 115 }
118 } 116 }
119 } 117 }
120 } 118 }
121 119
122 for ( int i = 0; i < 7; i++ ) { 120 for ( int i = 0; i < 7; i++ ) {
123 buttonPixUp[i] = NULL; 121 buttonPixUp[i] = NULL;
124 buttonPixDown[i] = NULL; 122 buttonPixDown[i] = NULL;
125 } 123 }
126 124
127 setBackgroundPixmap( pixBg ); 125 setBackgroundPixmap( pixBg );
128 126
129 slider = new QSlider( Qt::Horizontal, this ); 127 slider = new QSlider( Qt::Horizontal, this );
130 slider->setMinValue( 0 ); 128 slider->setMinValue( 0 );
131 slider->setMaxValue( 1 ); 129 slider->setMaxValue( 1 );
132 slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); 130 slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) );
133 //slider->setFocusPolicy( QWidget::NoFocus ); 131 //slider->setFocusPolicy( QWidget::NoFocus );
134 132
135 resizeEvent( NULL ); 133 resizeEvent( NULL );
136 134
137 setLength( mediaPlayerState.length() ); 135 setLength( mediaPlayerState.length() );
138 setPosition( mediaPlayerState.position() ); 136 setPosition( mediaPlayerState.position() );
139 setFullscreen( mediaPlayerState.isFullscreen() ); 137 setFullscreen( mediaPlayerState.isFullscreen() );
140 setPlaying( mediaPlayerState.isPlaying() ); 138 setPlaying( mediaPlayerState.isPlaying() );
141} 139}
142 140
143 141
144VideoWidget::~VideoWidget() { 142VideoWidget::~VideoWidget() {
145 143
146 for ( int i = 0; i < 7; i++ ) { 144 for ( int i = 0; i < 7; i++ ) {
147 delete buttonPixUp[i]; 145 delete buttonPixUp[i];
148 delete buttonPixDown[i]; 146 delete buttonPixDown[i];
149 } 147 }
150 148
151 for ( int i = 0; i < 7; i++ ) { 149 for ( int i = 0; i < 7; i++ ) {
152 delete masks[i]; 150 delete masks[i];
153 } 151 }
154 152
155} 153}
156 154
157QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 155QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
158 QPixmap pix( img.width(), img.height() ); 156 QPixmap pix( img.width(), img.height() );
159 QPainter p( &pix ); 157 QPainter p( &pix );
160 p.drawTiledPixmap( pix.rect(), bg, offset ); 158 p.drawTiledPixmap( pix.rect(), bg, offset );
161 p.drawImage( 0, 0, img ); 159 p.drawImage( 0, 0, img );
162 return new QPixmap( pix ); 160 return new QPixmap( pix );
163} 161}
164 162
165QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { 163QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) {
166 QPixmap *pixmap = new QPixmap( pix ); 164 QPixmap *pixmap = new QPixmap( pix );
167 pixmap->setMask( mask ); 165 pixmap->setMask( mask );
168 return pixmap; 166 return pixmap;
169} 167}
170 168
171void VideoWidget::resizeEvent( QResizeEvent * ) { 169void VideoWidget::resizeEvent( QResizeEvent * ) {
172 int h = height(); 170 int h = height();
173 int w = width(); 171 int w = width();
@@ -205,193 +203,193 @@ void VideoWidget::resizeEvent( QResizeEvent * ) {
205 203
206static bool videoSliderBeingMoved = FALSE; 204static bool videoSliderBeingMoved = FALSE;
207 205
208void VideoWidget::sliderPressed() { 206void VideoWidget::sliderPressed() {
209 videoSliderBeingMoved = TRUE; 207 videoSliderBeingMoved = TRUE;
210} 208}
211 209
212void VideoWidget::sliderReleased() { 210void VideoWidget::sliderReleased() {
213 videoSliderBeingMoved = FALSE; 211 videoSliderBeingMoved = FALSE;
214 if ( slider->width() == 0 ) { 212 if ( slider->width() == 0 ) {
215 return; 213 return;
216 } 214 }
217 long val = long((double)slider->value() * mediaPlayerState.length() / slider->width()); 215 long val = long((double)slider->value() * mediaPlayerState.length() / slider->width());
218 mediaPlayerState.setPosition( val ); 216 mediaPlayerState.setPosition( val );
219} 217}
220 218
221void VideoWidget::setPosition( long i ) { 219void VideoWidget::setPosition( long i ) {
222 updateSlider( i, mediaPlayerState.length() ); 220 updateSlider( i, mediaPlayerState.length() );
223} 221}
224 222
225 223
226void VideoWidget::setLength( long max ) { 224void VideoWidget::setLength( long max ) {
227 updateSlider( mediaPlayerState.position(), max ); 225 updateSlider( mediaPlayerState.position(), max );
228} 226}
229 227
230void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType ) 228void VideoWidget::setDisplayType( MediaPlayerState::DisplayType displayType )
231{ 229{
232 if ( displayType == MediaPlayerState::Video ) { 230 if ( displayType == MediaPlayerState::Video ) {
233 makeVisible(); 231 makeVisible();
234 return; 232 return;
235 } 233 }
236 234
237 // Effectively blank the view next time we show it so it looks nicer 235 // Effectively blank the view next time we show it so it looks nicer
238 scaledWidth = 0; 236 scaledWidth = 0;
239 scaledHeight = 0; 237 scaledHeight = 0;
240 hide(); 238 hide();
241} 239}
242 240
243void VideoWidget::updateSlider( long i, long max ) { 241void VideoWidget::updateSlider( long i, long max ) {
244 // Will flicker too much if we don't do this 242 // Will flicker too much if we don't do this
245 if ( max == 0 ) { 243 if ( max == 0 ) {
246 return; 244 return;
247 } 245 }
248 int width = slider->width(); 246 int width = slider->width();
249 int val = int((double)i * width / max); 247 int val = int((double)i * width / max);
250 if ( !mediaPlayerState.isFullscreen() && !videoSliderBeingMoved ) { 248 if ( !mediaPlayerState.isFullscreen() && !videoSliderBeingMoved ) {
251 if ( slider->value() != val ) { 249 if ( slider->value() != val ) {
252 slider->setValue( val ); 250 slider->setValue( val );
253 } 251 }
254 if ( slider->maxValue() != width ) { 252 if ( slider->maxValue() != width ) {
255 slider->setMaxValue( width ); 253 slider->setMaxValue( width );
256 } 254 }
257 } 255 }
258} 256}
259 257
260void VideoWidget::setToggleButton( int i, bool down ) { 258void VideoWidget::setToggleButton( int i, bool down ) {
261 if ( down != buttons[i].isDown ) { 259 if ( down != buttons[i].isDown ) {
262 toggleButton( i ); 260 toggleButton( i );
263 } 261 }
264} 262}
265 263
266void VideoWidget::paintButton( QPainter &p, int i ) { 264void VideoWidget::paintButton( QPainter &p, int i ) {
267 265
268 if ( buttons[i].isDown ) { 266 if ( buttons[i].isDown ) {
269 p.drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] ); 267 p.drawPixmap( upperLeftOfButtonMask, *buttonPixDown[i] );
270 } else { 268 } else {
271 p.drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] ); 269 p.drawPixmap( upperLeftOfButtonMask, *buttonPixUp[i] );
272 } 270 }
273} 271}
274 272
275void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { 273void VideoWidget::mouseMoveEvent( QMouseEvent *event ) {
276 for ( unsigned int i = 0; i < buttons.size(); i++ ) { 274 for ( unsigned int i = 0; i < buttons.size(); i++ ) {
277 if ( event->state() == QMouseEvent::LeftButton ) { 275 if ( event->state() == QMouseEvent::LeftButton ) {
278 // The test to see if the mouse click is inside the button or not 276 // The test to see if the mouse click is inside the button or not
279 bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i ); 277 bool isOnButton = isOverButton( event->pos() - upperLeftOfButtonMask, i );
280 278
281 if ( isOnButton && !buttons[i].isHeld ) { 279 if ( isOnButton && !buttons[i].isHeld ) {
282 buttons[i].isHeld = TRUE; 280 buttons[i].isHeld = TRUE;
283 toggleButton(i); 281 toggleButton(i);
284 282
285 switch (i) { 283 switch (i) {
286 case VideoVolUp: 284 case VideoVolUp:
287 emit moreClicked(); 285 emit moreClicked();
288 return; 286 return;
289 case VideoVolDown: 287 case VideoVolDown:
290 emit lessClicked(); 288 emit lessClicked();
291 return; 289 return;
292 } 290 }
293 } else if ( !isOnButton && buttons[i].isHeld ) { 291 } else if ( !isOnButton && buttons[i].isHeld ) {
294 buttons[i].isHeld = FALSE; 292 buttons[i].isHeld = FALSE;
295 toggleButton(i); 293 toggleButton(i);
296 } 294 }
297 } else { 295 } else {
298 296
299 if ( buttons[i].isHeld ) { 297 if ( buttons[i].isHeld ) {
300 buttons[i].isHeld = FALSE; 298 buttons[i].isHeld = FALSE;
301 if ( !buttons[i].isToggle ) { 299 if ( buttons[i].buttonType != ToggleButton ) {
302 setToggleButton( i, FALSE ); 300 setToggleButton( i, FALSE );
303 } 301 }
304 302
305 switch(i) { 303 switch(i) {
306 304
307 case VideoPlay: { 305 case VideoPlay: {
308 if( mediaPlayerState.isPaused() ) { 306 if( mediaPlayerState.isPaused() ) {
309 setToggleButton( i, FALSE ); 307 setToggleButton( i, FALSE );
310 mediaPlayerState.setPaused( FALSE ); 308 mediaPlayerState.setPaused( FALSE );
311 return; 309 return;
312 } else if( !mediaPlayerState.isPaused() ) { 310 } else if( !mediaPlayerState.isPaused() ) {
313 setToggleButton( i, TRUE ); 311 setToggleButton( i, TRUE );
314 mediaPlayerState.setPaused( TRUE ); 312 mediaPlayerState.setPaused( TRUE );
315 return; 313 return;
316 } else { 314 } else {
317 return; 315 return;
318 } 316 }
319 } 317 }
320 318
321 case VideoStop: mediaPlayerState.setPlaying( FALSE ); return; 319 case VideoStop: mediaPlayerState.setPlaying( FALSE ); return;
322 case VideoNext: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; 320 case VideoNext: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return;
323 case VideoPrevious: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; 321 case VideoPrevious: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return;
324 case VideoVolUp: emit moreReleased(); return; 322 case VideoVolUp: emit moreReleased(); return;
325 case VideoVolDown: emit lessReleased(); return; 323 case VideoVolDown: emit lessReleased(); return;
326 case VideoFullscreen: mediaPlayerState.setFullscreen( TRUE ); makeVisible(); return; 324 case VideoFullscreen: mediaPlayerState.setFullscreen( TRUE ); makeVisible(); return;
327 } 325 }
328 } 326 }
329 } 327 }
330 } 328 }
331} 329}
332 330
333void VideoWidget::mousePressEvent( QMouseEvent *event ) { 331void VideoWidget::mousePressEvent( QMouseEvent *event ) {
334 mouseMoveEvent( event ); 332 mouseMoveEvent( event );
335} 333}
336 334
337void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { 335void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) {
338 if ( mediaPlayerState.isFullscreen() ) { 336 if ( mediaPlayerState.isFullscreen() ) {
339 mediaPlayerState.setFullscreen( FALSE ); 337 mediaPlayerState.setFullscreen( FALSE );
340 makeVisible(); 338 makeVisible();
341 } 339 }
342 mouseMoveEvent( event ); 340 mouseMoveEvent( event );
343} 341}
344 342
345void VideoWidget::showEvent( QShowEvent* ) { 343void VideoWidget::showEvent( QShowEvent* ) {
346 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 344 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
347 mouseMoveEvent( &event ); 345 mouseMoveEvent( &event );
348} 346}
349 347
350 348
351 void VideoWidget::backToNormal() { 349 void VideoWidget::backToNormal() {
352 mediaPlayerState.setFullscreen( FALSE ); 350 mediaPlayerState.setFullscreen( FALSE );
353 makeVisible(); 351 makeVisible();
354 } 352 }
355 353
356void VideoWidget::makeVisible() { 354void VideoWidget::makeVisible() {
357 if ( mediaPlayerState.isFullscreen() ) { 355 if ( mediaPlayerState.isFullscreen() ) {
358 setBackgroundMode( QWidget::NoBackground ); 356 setBackgroundMode( QWidget::NoBackground );
359 showFullScreen(); 357 showFullScreen();
360 resize( qApp->desktop()->size() ); 358 resize( qApp->desktop()->size() );
361 videoFrame-> setGeometry ( 0, 0, width ( ), height ( )); 359 videoFrame-> setGeometry ( 0, 0, width ( ), height ( ));
362 360
363 slider->hide(); 361 slider->hide();
364 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 362 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
365 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 363 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
366 disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 364 disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
367 disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 365 disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
368 366
369 } else { 367 } else {
370 showNormal(); 368 showNormal();
371 showMaximized(); 369 showMaximized();
372 setBackgroundPixmap( pixBg ); 370 setBackgroundPixmap( pixBg );
373 QWidget *d = QApplication::desktop(); 371 QWidget *d = QApplication::desktop();
374 int w = d->width(); 372 int w = d->width();
375 int h = d->height(); 373 int h = d->height();
376 374
377 if(w>h) { 375 if(w>h) {
378 int newW=(w/2)-(246/2); //this will only work with 320x240 376 int newW=(w/2)-(246/2); //this will only work with 320x240
379 videoFrame->setGeometry( QRect( newW, 4, 240, 170 ) ); 377 videoFrame->setGeometry( QRect( newW, 4, 240, 170 ) );
380 } else { 378 } else {
381 videoFrame->setGeometry( QRect( 0, 30, 240, 170 ) ); 379 videoFrame->setGeometry( QRect( 0, 30, 240, 170 ) );
382 } 380 }
383 381
384 if ( !mediaPlayerState.isSeekable() ) { 382 if ( !mediaPlayerState.isSeekable() ) {
385 if( !slider->isHidden()) { 383 if( !slider->isHidden()) {
386 slider->hide(); 384 slider->hide();
387 } 385 }
388 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 386 disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
389 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 387 disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
390 disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 388 disconnect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
391 disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 389 disconnect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
392 } else { 390 } else {
393 slider->show(); 391 slider->show();
394 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 392 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
395 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 393 connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
396 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 394 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
397 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 395 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );