-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 2 | ||||
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 142 | ||||
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.h | 45 | ||||
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol.cpp | 29 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistselection.cpp | 9 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 212 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.h | 17 | ||||
-rw-r--r-- | core/multimedia/opieplayer/videowidget.cpp | 110 | ||||
-rw-r--r-- | core/multimedia/opieplayer/videowidget.h | 3 |
9 files changed, 356 insertions, 213 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index 5fef792..2087c7f 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp @@ -8,364 +8,362 @@ ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ // L.J.Potter added better error code Fri 02-15-2002 14:37:47 #include <stdlib.h> #include <stdio.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include "audiodevice.h" #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) #include "qpe/qcopenvelope_qws.h" #endif #ifdef Q_WS_WIN #include <windows.h> #include <mmsystem.h> #include <mmreg.h> #endif #if defined(Q_WS_X11) || defined(Q_WS_QWS) #include <fcntl.h> #include <sys/ioctl.h> #include <sys/soundcard.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> #include <unistd.h> #endif #if defined(Q_OS_WIN32) static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; static const int timerResolutionMilliSeconds = 30; static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; #else # if defined(QT_QWS_IPAQ) static const int sound_fragment_shift = 14; # else static const int sound_fragment_shift = 16; # endif static const int sound_fragment_bytes = (1<<sound_fragment_shift); #endif class AudioDevicePrivate { public: int handle; unsigned int frequency; unsigned int channels; unsigned int bytesPerSample; unsigned int bufferSize; #ifndef Q_OS_WIN32 bool can_GETOSPACE; char* unwrittenBuffer; unsigned int unwritten; #endif static int dspFd; static bool muted; static unsigned int leftVolume; static unsigned int rightVolume; }; #ifdef Q_WS_QWS // This is for keeping the device open in-between playing files when // the device makes clicks and it starts to drive you insane! :) // Best to have the device not open when not using it though //#define KEEP_DEVICE_OPEN #endif int AudioDevicePrivate::dspFd = 0; bool AudioDevicePrivate::muted = FALSE; unsigned int AudioDevicePrivate::leftVolume = 0; unsigned int AudioDevicePrivate::rightVolume = 0; void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { muted = AudioDevicePrivate::muted; unsigned int volume; #ifdef Q_OS_WIN32 HWAVEOUT handle; WAVEFORMATEX formatData; formatData.cbSize = sizeof(WAVEFORMATEX); formatData.wFormatTag = WAVE_FORMAT_PCM; formatData.nAvgBytesPerSec = 4 * 44000; formatData.nBlockAlign = 4; formatData.nChannels = 2; formatData.nSamplesPerSec = 44000; formatData.wBitsPerSample = 16; waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) // qDebug( "get volume of audio device failed" ); waveOutClose( handle ); leftVolume = volume & 0xFFFF; rightVolume = volume >> 16; #else int mixerHandle = open( "/dev/mixer", O_RDWR ); if ( mixerHandle >= 0 ) { if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) perror("ioctl(\"MIXER_READ\")"); close( mixerHandle ); } else perror("open(\"/dev/mixer\")"); leftVolume = ((volume & 0x00FF) << 16) / 101; rightVolume = ((volume & 0xFF00) << 8) / 101; #endif } void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { AudioDevicePrivate::muted = muted; if ( muted ) { AudioDevicePrivate::leftVolume = leftVolume; AudioDevicePrivate::rightVolume = rightVolume; leftVolume = 0; rightVolume = 0; } else { leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); } #ifdef Q_OS_WIN32 HWAVEOUT handle; WAVEFORMATEX formatData; formatData.cbSize = sizeof(WAVEFORMATEX); formatData.wFormatTag = WAVE_FORMAT_PCM; formatData.nAvgBytesPerSec = 4 * 44000; formatData.nBlockAlign = 4; formatData.nChannels = 2; formatData.nSamplesPerSec = 44000; formatData.wBitsPerSample = 16; waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); unsigned int volume = (rightVolume << 16) | leftVolume; if ( waveOutSetVolume( handle, volume ) ) // qDebug( "set volume of audio device failed" ); waveOutClose( handle ); #else // Volume can be from 0 to 100 which is 101 distinct values unsigned int rV = (rightVolume * 101) >> 16; # if 0 unsigned int lV = (leftVolume * 101) >> 16; unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); int mixerHandle = 0; if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) perror("ioctl(\"MIXER_WRITE\")"); close( mixerHandle ); } else perror("open(\"/dev/mixer\")"); # else // This is the way this has to be done now I guess, doesn't allow for // independant right and left channel setting, or setting for different outputs Config cfg("Sound"); cfg.setGroup("System"); cfg.writeEntry("Volume",(int)rV); # endif #endif // qDebug( "setting volume to: 0x%x", volume ); #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) // Send notification that the volume has changed QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; #endif } AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { qDebug("creating new audio device"); d = new AudioDevicePrivate; d->frequency = f; d->channels = chs; d->bytesPerSample = bps; qDebug("%d",bps); int format=0; if( bps == 8) format = AFMT_U8; else if( bps <= 0) format = AFMT_S16_LE; else format = AFMT_S16_LE; - qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); - int fragments = 0x10000 * 8 + sound_fragment_shift; int capabilities = 0; #ifdef KEEP_DEVICE_OPEN if ( AudioDevicePrivate::dspFd == 0 ) { #endif if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { perror("open(\"/dev/dsp\") sending to /dev/null instead"); d->handle = ::open( "/dev/null", O_WRONLY ); } #ifdef KEEP_DEVICE_OPEN AudioDevicePrivate::dspFd = d->handle; } else { d->handle = AudioDevicePrivate::dspFd; } #endif if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); qDebug("freq %d", d->frequency); if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) perror("ioctl(\"SNDCTL_DSP_SPEED\")"); qDebug("channels %d",d->channels); if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { d->channels = ( d->channels == 1 ) ? 2 : d->channels; if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); } d->bufferSize = sound_fragment_bytes; d->unwrittenBuffer = new char[d->bufferSize]; d->unwritten = 0; d->can_GETOSPACE = TRUE; // until we find otherwise //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); } AudioDevice::~AudioDevice() { #ifdef Q_OS_WIN32 waveOutClose( (HWAVEOUT)d->handle ); #else # ifndef KEEP_DEVICE_OPEN close( d->handle ); // Now it should be safe to shut the handle # endif delete d->unwrittenBuffer; delete d; #endif } void AudioDevice::volumeChanged( bool muted ) { AudioDevicePrivate::muted = muted; } void AudioDevice::write( char *buffer, unsigned int length ) { #ifdef Q_OS_WIN32 // returns immediately and (to be implemented) emits completedIO() when finished writing WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) ); // maybe the buffer should be copied so that this fool proof, but its a performance hit lpWaveHdr->lpData = buffer; lpWaveHdr->dwBufferLength = length; lpWaveHdr->dwFlags = 0L; lpWaveHdr->dwLoops = 0L; waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ); // waveOutWrite returns immediately. the data is sent in the background. if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) ) qDebug( "failed to write block to audio device" ); // emit completedIO(); #else int t = ::write( d->handle, buffer, length ); if ( t<0 ) t = 0; if ( t != (int)length) { qDebug("Ahhh!! memcpys 1"); memcpy(d->unwrittenBuffer,buffer+t,length-t); d->unwritten = length-t; } #endif } unsigned int AudioDevice::channels() const { return d->channels; } unsigned int AudioDevice::frequency() const { return d->frequency; } unsigned int AudioDevice::bytesPerSample() const { return d->bytesPerSample; } unsigned int AudioDevice::bufferSize() const { return d->bufferSize; } unsigned int AudioDevice::canWrite() const { #ifdef Q_OS_WIN32 return bufferSize(); // Any better? #else audio_buf_info info; if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { d->can_GETOSPACE = FALSE; fcntl( d->handle, F_SETFL, O_NONBLOCK ); } if ( d->can_GETOSPACE ) { int t = info.fragments * sound_fragment_bytes; return QMIN(t,(int)bufferSize()); } else { if ( d->unwritten ) { int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); if ( t<0 ) t = 0; if ( (unsigned)t!=d->unwritten ) { memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); d->unwritten -= t; } else { d->unwritten = 0; } } if ( d->unwritten ) return 0; else return d->bufferSize; } #endif } int AudioDevice::bytesWritten() { #ifdef Q_OS_WIN32 MMTIME pmmt = { TIME_BYTES, 0 }; if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) { qDebug( "failed to get audio device position" ); return -1; } return pmmt.u.cb; #else int buffered = 0; if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { qDebug( "failed to get audio device position" ); return -1; } return buffered; #endif } diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index 582660c..3901446 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp @@ -1,276 +1,336 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ +#include <qpe/qpeapplication.h> +#include <qpe/resource.h> + #include <qwidget.h> #include <qpixmap.h> #include <qbutton.h> #include <qpainter.h> #include <qframe.h> -#include <qpe/resource.h> + #include "audiowidget.h" #include "mediaplayerstate.h" extern MediaPlayerState *mediaPlayerState; static const int xo = -2; // movable x offset static const int yo = 22; // movable y offset struct MediaButton { int xPos, yPos; int color; bool isToggle, isBig, isHeld, isDown; }; // Layout information for the audioButtons (and if it is a toggle button or not) MediaButton audioButtons[] = { { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist }; static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : QWidget( parent, name, f ) { +// QPEApplication::grabKeyboard(); setCaption( tr("OpiePlayer") ); setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) ); pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) ); pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) ); pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) ); songInfo = new Ticker( this ); songInfo->setFocusPolicy( QWidget::NoFocus ); songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); slider = new QSlider( Qt::Horizontal, this ); slider->setFixedWidth( 220 ); slider->setFixedHeight( 20 ); slider->setMinValue( 0 ); slider->setMaxValue( 1 ); slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); slider->setFocusPolicy( QWidget::NoFocus ); slider->setGeometry( QRect( 7, 262, 220, 20 ) ); connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); // Intialise state setLength( mediaPlayerState->length() ); setPosition( mediaPlayerState->position() ); setLooping( mediaPlayerState->fullscreen() ); setPaused( mediaPlayerState->paused() ); setPlaying( mediaPlayerState->playing() ); } AudioWidget::~AudioWidget() { for ( int i = 0; i < 4; i++ ) delete pixmaps[i]; } static bool audioSliderBeingMoved = FALSE; void AudioWidget::sliderPressed() { audioSliderBeingMoved = TRUE; } void AudioWidget::sliderReleased() { audioSliderBeingMoved = FALSE; if ( slider->width() == 0 ) return; long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); mediaPlayerState->setPosition( val ); } void AudioWidget::setPosition( long i ) { updateSlider( i, mediaPlayerState->length() ); } void AudioWidget::setLength( long max ) { updateSlider( mediaPlayerState->position(), max ); } void AudioWidget::setView( char view ) { if ( view == 'a' ) { startTimer( 150 ); showMaximized(); } else { killTimers(); hide(); } } void AudioWidget::updateSlider( long i, long max ) { if ( max == 0 ) return; // Will flicker too much if we don't do this // Scale to something reasonable int width = slider->width(); int val = int((double)i * width / max); if ( !audioSliderBeingMoved ) { if ( slider->value() != val ) slider->setValue( val ); if ( slider->maxValue() != width ) slider->setMaxValue( width ); } } void AudioWidget::setToggleButton( int i, bool down ) { if ( down != audioButtons[i].isDown ) toggleButton( i ); } void AudioWidget::toggleButton( int i ) { audioButtons[i].isDown = !audioButtons[i].isDown; QPainter p(this); paintButton ( &p, i ); } void AudioWidget::paintButton( QPainter *p, int i ) { int x = audioButtons[i].xPos; int y = audioButtons[i].yPos; int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); } void AudioWidget::timerEvent( QTimerEvent * ) { static int frame = 0; if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { frame = frame >= 7 ? 0 : frame + 1; int x = audioButtons[AudioPlay].xPos; int y = audioButtons[AudioPlay].yPos; QPainter p( this ); // Optimize to only draw the little bit of the changing images which is different p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); } } void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { for ( int i = 0; i < numButtons; i++ ) { - int size = audioButtons[i].isBig; - int x = audioButtons[i].xPos; - int y = audioButtons[i].yPos; - if ( event->state() == QMouseEvent::LeftButton ) { - // The test to see if the mouse click is inside the circular button or not - // (compared with the radius squared to avoid a square-root of our distance) - int radius = 32 + 13 * size; - QPoint center = QPoint( x + radius, y + radius ); - QPoint dXY = center - event->pos(); - int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); - bool isOnButton = dist <= (radius * radius); + int size = audioButtons[i].isBig; + int x = audioButtons[i].xPos; + int y = audioButtons[i].yPos; + if ( event->state() == QMouseEvent::LeftButton ) { + // The test to see if the mouse click is inside the circular button or not + // (compared with the radius squared to avoid a square-root of our distance) + int radius = 32 + 13 * size; + QPoint center = QPoint( x + radius, y + radius ); + QPoint dXY = center - event->pos(); + int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); + bool isOnButton = dist <= (radius * radius); // QRect r( x, y, 64 + 22*size, 64 + 22*size ); // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code - if ( isOnButton && !audioButtons[i].isHeld ) { - audioButtons[i].isHeld = TRUE; - toggleButton(i); - switch (i) { - case AudioVolumeUp: emit moreClicked(); return; - case AudioVolumeDown: emit lessClicked(); return; - } - } else if ( !isOnButton && audioButtons[i].isHeld ) { - audioButtons[i].isHeld = FALSE; - toggleButton(i); - } - } else { - if ( audioButtons[i].isHeld ) { - audioButtons[i].isHeld = FALSE; - if ( !audioButtons[i].isToggle ) - setToggleButton( i, FALSE ); - switch (i) { - case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; - case AudioStop: mediaPlayerState->setPlaying(FALSE); return; - case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; - case AudioNext: mediaPlayerState->setNext(); return; - case AudioPrevious: mediaPlayerState->setPrev(); return; - case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; - case AudioVolumeUp: emit moreReleased(); return; - case AudioVolumeDown: emit lessReleased(); return; - case AudioPlayList: mediaPlayerState->setList(); return; - } - } - } + if ( isOnButton && !audioButtons[i].isHeld ) { + audioButtons[i].isHeld = TRUE; + toggleButton(i); + qDebug("button toggled %d",i); + switch (i) { + case AudioVolumeUp: emit moreClicked(); return; + case AudioVolumeDown: emit lessClicked(); return; + } + } else if ( !isOnButton && audioButtons[i].isHeld ) { + audioButtons[i].isHeld = FALSE; + toggleButton(i); + } + } else { + if ( audioButtons[i].isHeld ) { + audioButtons[i].isHeld = FALSE; + if ( !audioButtons[i].isToggle ) + setToggleButton( i, FALSE ); + switch (i) { + case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; + case AudioStop: mediaPlayerState->setPlaying(FALSE); return; + case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; + case AudioNext: mediaPlayerState->setNext(); return; + case AudioPrevious: mediaPlayerState->setPrev(); return; + case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; + case AudioVolumeUp: emit moreReleased(); return; + case AudioVolumeDown: emit lessReleased(); return; + case AudioPlayList: mediaPlayerState->setList(); return; + } + } + } } } void AudioWidget::mousePressEvent( QMouseEvent *event ) { mouseMoveEvent( event ); } void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { mouseMoveEvent( event ); } void AudioWidget::showEvent( QShowEvent* ) { QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); mouseMoveEvent( &event ); } void AudioWidget::closeEvent( QCloseEvent* ) { mediaPlayerState->setList(); } void AudioWidget::paintEvent( QPaintEvent * ) { QPainter p( this ); for ( int i = 0; i < numButtons; i++ ) paintButton( &p, i ); } +void AudioWidget::keyReleaseEvent( QKeyEvent *e) +{ + switch ( e->key() ) { +////////////////////////////// Zaurus keys + case Key_Home: + break; + case Key_F9: //activity + break; + case Key_F10: //contacts + break; + case Key_F11: //menu + break; + case Key_F12: //home + break; + case Key_F13: //mail + break; + case Key_Space: { + if(mediaPlayerState->playing()) { +// toggleButton(1); + mediaPlayerState->setPlaying(FALSE); +// toggleButton(1); + } else { +// toggleButton(0); + mediaPlayerState->setPlaying(TRUE); +// toggleButton(0); + } + } + break; + case Key_Down: + toggleButton(6); + emit lessClicked(); + emit lessReleased(); + toggleButton(6); + break; + case Key_Up: + toggleButton(5); + emit moreClicked(); + emit moreReleased(); + toggleButton(5); + break; + case Key_Right: +// toggleButton(3); + mediaPlayerState->setNext(); +// toggleButton(3); + break; + case Key_Left: +// toggleButton(4); + mediaPlayerState->setPrev(); +// toggleButton(4); + break; + case Key_Escape: + break; + + }; +} diff --git a/core/multimedia/opieplayer/audiowidget.h b/core/multimedia/opieplayer/audiowidget.h index 53e84b3..a2850aa 100644 --- a/core/multimedia/opieplayer/audiowidget.h +++ b/core/multimedia/opieplayer/audiowidget.h @@ -1,143 +1,144 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef AUDIO_WIDGET_H #define AUDIO_WIDGET_H #include <qwidget.h> #include <qpainter.h> #include <qdrawutil.h> #include <qpixmap.h> #include <qstring.h> #include <qslider.h> #include <qframe.h> class QPixmap; enum AudioButtons { AudioPlay, AudioStop, AudioPause, AudioNext, AudioPrevious, AudioVolumeUp, AudioVolumeDown, AudioLoop, AudioPlayList }; #define USE_DBLBUF class Ticker : public QFrame { Q_OBJECT public: Ticker( QWidget* parent=0 ) : QFrame( parent ) { - setFrameStyle( WinPanel | Sunken ); - setText( "No Song" ); + setFrameStyle( WinPanel | Sunken ); + setText( "No Song" ); } ~Ticker() { } void setText( const QString& text ) { - pos = 0; // reset it everytime the text is changed - scrollText = text; - pixelLen = fontMetrics().width( scrollText ); - killTimers(); - if ( pixelLen > width() ) - startTimer( 50 ); - update(); + pos = 0; // reset it everytime the text is changed + scrollText = text; + pixelLen = fontMetrics().width( scrollText ); + killTimers(); + if ( pixelLen > width() ) + startTimer( 50 ); + update(); } protected: void timerEvent( QTimerEvent * ) { - pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; + pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; #ifndef USE_DBLBUF - scroll( -1, 0, contentsRect() ); + scroll( -1, 0, contentsRect() ); #else - repaint( FALSE ); + repaint( FALSE ); #endif } void drawContents( QPainter *p ) { #ifndef USE_DBLBUF - for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) - p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); + for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) + p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); #else - // Double buffering code. - // Looks like qvfb makes it look like it flickers but I don't think it really is - QPixmap pm( width(), height() ); - pm.fill( colorGroup().base() ); - QPainter pmp( &pm ); - for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) - pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); - p->drawPixmap( 0, 0, pm ); + // Double buffering code. + // Looks like qvfb makes it look like it flickers but I don't think it really is + QPixmap pm( width(), height() ); + pm.fill( colorGroup().base() ); + QPainter pmp( &pm ); + for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) + pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); + p->drawPixmap( 0, 0, pm ); #endif } private: QString scrollText; int pos, pixelLen; }; class AudioWidget : public QWidget { Q_OBJECT public: AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); ~AudioWidget(); void setTickerText( const QString &text ) { songInfo->setText( text ); } public slots: void updateSlider( long, long ); void sliderPressed( ); void sliderReleased( ); void setPaused( bool b) { setToggleButton( AudioPause, b ); } void setLooping( bool b) { setToggleButton( AudioLoop, b ); } void setPlaying( bool b) { setToggleButton( AudioPlay, b ); } void setPosition( long ); void setLength( long ); void setView( char ); signals: void moreClicked(); void lessClicked(); void moreReleased(); void lessReleased(); void sliderMoved(long); protected: void paintEvent( QPaintEvent *pe ); void showEvent( QShowEvent *se ); void mouseMoveEvent( QMouseEvent *event ); void mousePressEvent( QMouseEvent *event ); void mouseReleaseEvent( QMouseEvent *event ); void timerEvent( QTimerEvent *event ); void closeEvent( QCloseEvent *event ); + void keyReleaseEvent( QKeyEvent *e); private: void toggleButton( int ); void setToggleButton( int, bool ); void paintButton( QPainter *p, int i ); QPixmap *pixmaps[4]; Ticker *songInfo; QSlider *slider; }; #endif // AUDIO_WIDGET_H diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp index cb8de8a..4b2827e 100644 --- a/core/multimedia/opieplayer/loopcontrol.cpp +++ b/core/multimedia/opieplayer/loopcontrol.cpp @@ -32,444 +32,445 @@ #include <errno.h> #include <unistd.h> #include "loopcontrol.h" #include "videowidget.h" #include "audiodevice.h" #include <qpe/mediaplayerplugininterface.h> #include "mediaplayerstate.h" extern VideoWidget *videoUI; // now only needed to tell it to play a frame extern MediaPlayerState *mediaPlayerState; //#define DecodeLoopDebug(x) qDebug x #define DecodeLoopDebug(x) static char *audioBuffer = NULL; static AudioDevice *audioDevice = NULL; static bool disabledSuspendScreenSaver = FALSE; static bool previousSuspendMode = FALSE; pthread_t audio_tid; pthread_attr_t audio_attr; bool threadOkToGo = FALSE; class Mutex { public: Mutex() { pthread_mutexattr_t attr; pthread_mutexattr_init( &attr ); pthread_mutex_init( &mutex, &attr ); pthread_mutexattr_destroy( &attr ); } ~Mutex() { pthread_mutex_destroy( &mutex ); } void lock() { pthread_mutex_lock( &mutex ); } void unlock() { pthread_mutex_unlock( &mutex ); } private: pthread_mutex_t mutex; }; void *startAudioThread( void *ptr ) { LoopControl *mpegView = (LoopControl *)ptr; while ( TRUE ) { if ( threadOkToGo && mpegView->moreAudio ) mpegView->startAudio(); else usleep( 10000 ); // Semi-buzy-wait till we are playing again } return 0; } Mutex *audioMutex; LoopControl::LoopControl( QObject *parent, const char *name ) : QObject( parent, name ) { isMuted = FALSE; connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); //qDebug("starting loopcontrol"); audioMutex = new Mutex; pthread_attr_init(&audio_attr); #define USE_REALTIME_AUDIO_THREAD #ifdef USE_REALTIME_AUDIO_THREAD // Attempt to set it to real-time round robin if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { sched_param params; params.sched_priority = 50; pthread_attr_setschedparam(&audio_attr,¶ms); } else { qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); pthread_attr_destroy(&audio_attr); pthread_attr_init(&audio_attr); } #endif //qDebug("create audio thread"); pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); } LoopControl::~LoopControl() { stop(); } static long prev_frame = 0; static int currentSample = 0; void LoopControl::timerEvent( QTimerEvent *te ) { if ( te->timerId() == videoId ) startVideo(); if ( te->timerId() == sliderId ) { if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { mediaPlayerState->updatePosition( audioSampleCounter ); } else if ( hasVideoChannel && moreVideo ) { mediaPlayerState->updatePosition( current_frame ); } } if ( !moreVideo && !moreAudio ) { mediaPlayerState->setPlaying( FALSE ); mediaPlayerState->setNext(); } } void LoopControl::setPosition( long pos ) { audioMutex->lock(); if ( hasVideoChannel && hasAudioChannel ) { playtime.restart(); playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); current_frame = pos + 1; mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); prev_frame = current_frame - 1; currentSample = (int)( (double)current_frame * freq / framerate ); mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); audioSampleCounter = currentSample - 1; } else if ( hasVideoChannel ) { playtime.restart(); playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); current_frame = pos + 1; mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); prev_frame = current_frame - 1; } else if ( hasAudioChannel ) { playtime.restart(); playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); currentSample = pos + 1; mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); audioSampleCounter = currentSample - 1; } audioMutex->unlock(); } void LoopControl::startVideo() { if ( moreVideo ) { if ( mediaPlayerState->curDecoder() ) { if ( hasAudioChannel && !isMuted ) { current_frame = long( playtime.elapsed() * framerate / 1000 ); if ( prev_frame != -1 && current_frame <= prev_frame ) return; } else { // Don't skip current_frame++; } if ( prev_frame == -1 || current_frame > prev_frame ) { if ( current_frame > prev_frame + 1 ) { mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); } moreVideo = videoUI->playVideo(); prev_frame = current_frame; } } else { moreVideo = FALSE; killTimer( videoId ); } } } void LoopControl::startAudio() { -//qDebug("start audio"); audioMutex->lock(); if ( moreAudio ) { if ( !isMuted && mediaPlayerState->curDecoder() ) { currentSample = audioSampleCounter + 1; if ( currentSample != audioSampleCounter + 1 ) qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); long samplesRead = 0; bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; long sampleWaitTime = currentSample - sampleWeShouldBeAt; -// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { -// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); -// } -// else if ( sampleWaitTime <= -5000 ) { -// qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); -// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); -// currentSample = sampleWeShouldBeAt; -// } +// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { +// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); +// } +// else if ( sampleWaitTime <= -5000 ) { +// // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); +// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); +// currentSample = sampleWeShouldBeAt; +// } audioDevice->write( audioBuffer, samplesRead * 2 * channels ); audioSampleCounter = currentSample + samplesRead - 1; moreAudio = readOk && (audioSampleCounter <= total_audio_samples); } else { moreAudio = FALSE; } } audioMutex->unlock(); } void LoopControl::killTimers() { audioMutex->lock(); if ( hasVideoChannel ) killTimer( videoId ); killTimer( sliderId ); threadOkToGo = FALSE; audioMutex->unlock(); } void LoopControl::startTimers() { audioMutex->lock(); moreVideo = FALSE; moreAudio = FALSE; if ( hasVideoChannel ) { moreVideo = TRUE; int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value videoId = startTimer( mSecsBetweenFrames ); } if ( hasAudioChannel ) { moreAudio = TRUE; threadOkToGo = TRUE; } sliderId = startTimer( 300 ); // update slider every 1/3 second audioMutex->unlock(); } void LoopControl::setPaused( bool pause ) { if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) return; if ( pause ) { killTimers(); } else { // Force an update of the position mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); // Just like we never stopped startTimers(); } } void LoopControl::stop( bool willPlayAgainShortly ) { #if defined(Q_WS_QWS) && !defined(QT_NO_COP) if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { disabledSuspendScreenSaver = FALSE; // Re-enable the suspend mode QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; } #endif if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { killTimers(); audioMutex->lock(); mediaPlayerState->curDecoder()->close(); if ( audioDevice ) { delete audioDevice; delete audioBuffer; audioDevice = 0; audioBuffer = 0; } audioMutex->unlock(); } } bool LoopControl::init( const QString& filename ) { stop(); audioMutex->lock(); fileName = filename; stream = 0; // only play stream 0 for now current_frame = total_video_frames = total_audio_samples = 0; qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); mediaPlayerState->libMpeg3Decoder()->close(); } } if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { audioMutex->unlock(); return FALSE; } hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; if ( hasAudioChannel ) { int astream = 0; channels = mediaPlayerState->curDecoder()->audioChannels( astream ); - qDebug( "LC- channels = %d", channels ); +// qDebug( "LC- channels = %d", channels ); if ( !total_audio_samples ) total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); // total_audio_samples += 1000; mediaPlayerState->setLength( total_audio_samples ); freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); - qDebug( "LC- frequency = %d", freq ); +// qDebug( "LC- frequency = %d", freq ); audioSampleCounter = 0; int bits_per_sample; - if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { + if ( mediaPlayerState->curDecoder()->pluginName() == QString("WavPlugin") ) { bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); - qDebug("using stupid hack"); +// qDebug("using stupid hack"); } else { - bits_per_sample=0; + bits_per_sample=0; +// freq=44100; + channels=2; } audioDevice = new AudioDevice( freq, channels, bits_per_sample); audioBuffer = new char[ audioDevice->bufferSize() ]; channels = audioDevice->channels(); //### must check which frequency is actually used. static const int size = 1; short int buf[size]; long samplesRead = 0; mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); } if ( hasVideoChannel ) { total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); mediaPlayerState->setLength( total_video_frames ); framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); if ( framerate <= 1.0 ) { DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); framerate = 25; } if ( total_video_frames == 1 ) { DecodeLoopDebug(( "Cannot seek to frame" )); } } current_frame = 0; prev_frame = -1; connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); audioMutex->unlock(); return TRUE; } void LoopControl::play() { qDebug("LC- play"); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { disabledSuspendScreenSaver = TRUE; previousSuspendMode = hasVideoChannel; // Stop the screen from blanking and power saving state QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); } #endif playtime.start(); startTimers(); } void LoopControl::setMute( bool on ) { if ( on != isMuted ) { isMuted = on; if ( !on ) { // Force an update of the position mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); // Resume playing audio moreAudio = TRUE; } } } diff --git a/core/multimedia/opieplayer/playlistselection.cpp b/core/multimedia/opieplayer/playlistselection.cpp index 4019d12..47fc731 100644 --- a/core/multimedia/opieplayer/playlistselection.cpp +++ b/core/multimedia/opieplayer/playlistselection.cpp @@ -1,184 +1,183 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include <qpe/applnk.h> #include <qpe/resource.h> #include <qpainter.h> #include <qimage.h> #include <qheader.h> #include <qlistview.h> #include <qlist.h> #include <qpixmap.h> #include "playlistselection.h" #include <stdlib.h> class PlayListSelectionItem : public QListViewItem { public: PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) { setText( 0, f->name() ); setPixmap( 0, f->pixmap() ); } ~PlayListSelectionItem() { }; const DocLnk *file() const { return fl; } private: const DocLnk *fl; }; PlayListSelection::PlayListSelection( QWidget *parent, const char *name ) : QListView( parent, name ) { qDebug("starting playlistselector"); // #ifdef USE_PLAYLIST_BACKGROUND // setStaticBackground( TRUE ); // setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/background" ) ); -// setBackgroundPixmap( Resource::loadPixmap( "opielogo" ) ); + setBackgroundPixmap( Resource::loadPixmap( "opielogo" ) ); // #endif // addColumn("Title",236); // setAllColumnsShowFocus( TRUE ); addColumn( tr( "Playlist Selection" ) ); header()->hide(); setSorting( -1, FALSE ); } PlayListSelection::~PlayListSelection() { } // #ifdef USE_PLAYLIST_BACKGROUND void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) { // qDebug("drawBackground"); p->fillRect( r, QBrush( white ) ); -// QImage logo = Resource::loadImage( "mpegplayer/background" ); -// // QImage logo = Resource::loadImage( "opielogo" ); -// if ( !logo.isNull() ) -// p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo ); + QImage logo = Resource::loadImage( "opielogo" ); + if ( !logo.isNull() ) + p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo ); } // #endif void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) { if ( event->state() == QMouseEvent::LeftButton ) { QListViewItem *currentItem = selectedItem(); QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) ); if ( currentItem && currentItem->itemAbove() == itemUnder ) moveSelectedUp(); else if ( currentItem && currentItem->itemBelow() == itemUnder ) moveSelectedDown(); } } const DocLnk *PlayListSelection::current() { PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem(); if ( item ) return item->file(); return NULL; } void PlayListSelection::addToSelection( const DocLnk &lnk ) { PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) ); QListViewItem *current = selectedItem(); if ( current ) item->moveItem( current ); setSelected( item, TRUE ); ensureItemVisible( selectedItem() ); } void PlayListSelection::removeSelected() { QListViewItem *item = selectedItem(); if ( item ) delete item; setSelected( currentItem(), TRUE ); ensureItemVisible( selectedItem() ); } void PlayListSelection::moveSelectedUp() { QListViewItem *item = selectedItem(); if ( item && item->itemAbove() ) item->itemAbove()->moveItem( item ); ensureItemVisible( selectedItem() ); } void PlayListSelection::moveSelectedDown() { QListViewItem *item = selectedItem(); if ( item && item->itemBelow() ) item->moveItem( item->itemBelow() ); ensureItemVisible( selectedItem() ); } bool PlayListSelection::prev() { QListViewItem *item = selectedItem(); if ( item && item->itemAbove() ) setSelected( item->itemAbove(), TRUE ); else return FALSE; ensureItemVisible( selectedItem() ); return TRUE; } bool PlayListSelection::next() { QListViewItem *item = selectedItem(); if ( item && item->itemBelow() ) setSelected( item->itemBelow(), TRUE ); else return FALSE; ensureItemVisible( selectedItem() ); return TRUE; } bool PlayListSelection::first() { QListViewItem *item = firstChild(); if ( item ) setSelected( item, TRUE ); else return FALSE; ensureItemVisible( selectedItem() ); return TRUE; } bool PlayListSelection::last() { QListViewItem *prevItem = NULL; QListViewItem *item = firstChild(); while ( ( item = item->nextSibling() ) ) prevItem = item; if ( prevItem ) setSelected( prevItem, TRUE ); else return FALSE; ensureItemVisible( selectedItem() ); return TRUE; } diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index 9969526..524747e 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp @@ -1,784 +1,814 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ // code added by L. J. Potter Sat 03-02-2002 06:17:54 #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> #include <qpe/fileselector.h> #include <qpe/qpeapplication.h> #include <qpe/applnk.h> #include <qpe/config.h> #include <qpe/global.h> #include <qpe/resource.h> #include <qaction.h> #include <qimage.h> #include <qfile.h> #include <qdir.h> #include <qlayout.h> #include <qlabel.h> #include <qlist.h> #include <qlistbox.h> #include <qmainwindow.h> #include <qmessagebox.h> #include <qtoolbutton.h> #include <qtabwidget.h> #include <qlistview.h> #include <qpoint.h> #include <qlineedit.h> #include <qpushbutton.h> //#include <qtimer.h> #include "playlistselection.h" #include "playlistwidget.h" #include "mediaplayerstate.h" #include "inputDialog.h" #include <stdlib.h> #define BUTTONS_ON_TOOLBAR #define SIDE_BUTTONS #define CAN_SAVE_LOAD_PLAYLISTS extern MediaPlayerState *mediaPlayerState; // class myFileSelector { // }; class PlayListWidgetPrivate { public: QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; QFrame *playListFrame; FileSelector *files; PlayListSelection *selectedFiles; bool setDocumentUsed; DocLnk *current; }; class ToolButton : public QToolButton { public: ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) : QToolButton( parent, name ) { setTextLabel( name ); setPixmap( Resource::loadPixmap( icon ) ); setAutoRaise( TRUE ); setFocusPolicy( QWidget::NoFocus ); setToggleButton( t ); connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); QPEMenuToolFocusManager::manager()->addWidget( this ); } }; class MenuItem : public QAction { public: MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) : QAction( text, QString::null, 0, 0 ) { connect( this, SIGNAL( activated() ), handler, slot ); addTo( parent ); } }; PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) : QMainWindow( parent, name, fl ) { d = new PlayListWidgetPrivate; d->setDocumentUsed = FALSE; d->current = NULL; + fromSetDocument = FALSE; // menuTimer = new QTimer( this ,"menu timer"), // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); setBackgroundMode( PaletteButton ); setCaption( tr("OpiePlayer") ); setIcon( Resource::loadPixmap( "MPEGPlayer" ) ); setToolBarsMovable( FALSE ); // Create Toolbar QPEToolBar *toolbar = new QPEToolBar( this ); toolbar->setHorizontalStretchable( TRUE ); // Create Menubar QPEMenuBar *menu = new QPEMenuBar( toolbar ); menu->setMargin( 0 ); QPEToolBar *bar = new QPEToolBar( this ); bar->setLabel( tr( "Play Operations" ) ); // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "mpegplayer/play_current_list", // this , SLOT( addSelected()) ); tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); tbDeletePlaylist->setFlat(TRUE); tbDeletePlaylist->setFixedSize(20,20); connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "mpegplayer/add_to_playlist", this , SLOT(addSelected()) ); d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "mpegplayer/remove_from_playlist", this , SLOT(removeSelected()) ); // d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", this , SLOT( btnPlay(bool) ), TRUE ); d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"mpegplayer/shuffle", mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); d->tbLoop = new ToolButton( bar, tr( "Loop" ),"mpegplayer/loop", mediaPlayerState, SLOT(setLooping(bool)), TRUE ); tbDeletePlaylist->hide(); QPopupMenu *pmPlayList = new QPopupMenu( this ); menu->insertItem( tr( "File" ), pmPlayList ); new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); // new MenuItem( pmPlayList, tr( "Load PlayList" ), this, SLOT( loadList() ) ); QPopupMenu *pmView = new QPopupMenu( this ); menu->insertItem( tr( "View" ), pmView ); fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); fullScreenButton->addTo(pmView); scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("mpegplayer/scale"), QString::null, 0, this, 0); connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); scaleButton->addTo(pmView); QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); tabWidget = new QTabWidget( hbox6, "tabWidget" ); tabWidget->setTabShape(QTabWidget::Triangular); QWidget *pTab; pTab = new QWidget( tabWidget, "pTab" ); - playlistView = new QListView( pTab, "Videoview" ); - playlistView->setMinimumSize(236,260); +// playlistView = new QListView( pTab, "playlistview" ); +// playlistView->setMinimumSize(236,260); tabWidget->insertTab( pTab,"Playlist"); + // Add the playlist area QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); d->playListFrame = vbox3; d->playListFrame ->setMinimumSize(235,260); QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); d->selectedFiles = new PlayListSelection( hbox2); QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); + QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); + connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), + this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); + + QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch new ToolButton( vbox1, tr( "Move Up" ), "mpegplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); new ToolButton( vbox1, tr( "Remove" ), "mpegplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); new ToolButton( vbox1, tr( "Move Down" ), "mpegplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch QWidget *aTab; aTab = new QWidget( tabWidget, "aTab" ); audioView = new QListView( aTab, "Audioview" ); audioView->setMinimumSize(233,260); audioView->addColumn( "Title",150); audioView->addColumn("Size", 45); audioView->addColumn("Media",35); audioView->setColumnAlignment(1, Qt::AlignRight); audioView->setColumnAlignment(2, Qt::AlignRight); + audioView->setAllColumnsShowFocus(TRUE); tabWidget->insertTab(aTab,"Audio"); + + QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); + connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), + this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); + + // audioView Global::findDocuments(&files, "audio/*"); QListIterator<DocLnk> dit( files.children() ); QString storage; for ( ; dit.current(); ++dit ) { QListViewItem * newItem; if(dit.current()->file().find("/mnt/cf") != -1 ) storage="CF"; else if(dit.current()->file().find("/mnt/hda") != -1 ) storage="CF"; else if(dit.current()->file().find("/mnt/card") != -1 ) storage="SD"; else storage="RAM"; if ( QFile( dit.current()->file()).exists() ) { newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage); newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" )); } } // videowidget QWidget *vTab; vTab = new QWidget( tabWidget, "vTab" ); videoView = new QListView( vTab, "Videoview" ); videoView->setMinimumSize(233,260); videoView->addColumn("Title",150); videoView->addColumn("Size",45); videoView->addColumn("Media",35); videoView->setColumnAlignment(1, Qt::AlignRight); videoView->setColumnAlignment(2, Qt::AlignRight); + videoView->setAllColumnsShowFocus(TRUE); + QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); + connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), + this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); tabWidget->insertTab( vTab,"Video"); Global::findDocuments(&vFiles, "video/*"); QListIterator<DocLnk> Vdit( vFiles.children() ); for ( ; Vdit.current(); ++Vdit ) { if( Vdit.current()->file().find("/mnt/cf") != -1 ) storage="CF"; else if( Vdit.current()->file().find("/mnt/hda") != -1 ) storage="CF"; else if( Vdit.current()->file().find("/mnt/card") != -1 ) storage="SD"; else storage="RAM"; QListViewItem * newItem; if ( QFile( Vdit.current()->file()).exists() ) { newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage); newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/videofile" )); } } //playlists list QWidget *LTab; LTab = new QWidget( tabWidget, "LTab" ); playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy playLists->setMinimumSize(233,260);; tabWidget->insertTab(LTab,"Lists"); connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); // connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); // add the library area - QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); - // connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), // this, SLOT( fauxPlay( QListViewItem *) ) ); // connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), // this, SLOT( fauxPlay( QListViewItem *)) ); // connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); // connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); // connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); setCentralWidget( vbox5 ); Config cfg( "MediaPlayer" ); readConfig( cfg ); QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); // qDebug("currentList is "+currentPlaylist); loadList(DocLnk( currentPlaylist)); setCaption("OpiePlayer: "+ currentPlaylist ); initializeStates(); } PlayListWidget::~PlayListWidget() { Config cfg( "MediaPlayer" ); writeConfig( cfg ); if ( d->current ) delete d->current; delete d; } void PlayListWidget::initializeStates() { d->tbPlay->setOn( mediaPlayerState->playing() ); d->tbLoop->setOn( mediaPlayerState->looping() ); d->tbShuffle->setOn( mediaPlayerState->shuffled() ); // d->tbFull->setOn( mediaPlayerState->fullscreen() ); // d->tbScale->setOn( mediaPlayerState->scaled() ); // d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); // setPlaylist( mediaPlayerState->playlist() ); setPlaylist( true); d->selectedFiles->first(); } void PlayListWidget::readConfig( Config& cfg ) { cfg.setGroup("PlayList"); int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); for ( int i = 0; i < noOfFiles; i++ ) { QString entryName; entryName.sprintf( "File%i", i + 1 ); QString linkFile = cfg.readEntry( entryName ); DocLnk lnk( linkFile ); if ( lnk.isValid() ) d->selectedFiles->addToSelection( lnk ); } } void PlayListWidget::writeConfig( Config& cfg ) const { cfg.setGroup("PlayList"); int noOfFiles = 0; d->selectedFiles->first(); do { const DocLnk *lnk = d->selectedFiles->current(); if ( lnk ) { QString entryName; entryName.sprintf( "File%i", noOfFiles + 1 ); cfg.writeEntry( entryName, lnk->linkFile() ); // if this link does exist, add it so we have the file // next time... if ( !QFile::exists( lnk->linkFile() ) ) { // the way writing lnks doesn't really check for out // of disk space, but check it anyway. if ( !lnk->writeLink() ) { QMessageBox::critical( 0, tr("Out of space"), tr( "There was a problem saving " "the playlist.\n" "Your playlist " "may be missing some entries\n" "the next time you start it." ) ); } } noOfFiles++; } } while ( d->selectedFiles->next() ); cfg.writeEntry("NumberOfFiles", noOfFiles ); } void PlayListWidget::addToSelection( const DocLnk& lnk ) { // qDebug("add"); d->setDocumentUsed = FALSE; if ( mediaPlayerState->playlist() ) d->selectedFiles->addToSelection( lnk ); else mediaPlayerState->setPlaying( TRUE ); } void PlayListWidget::clearList() { while ( first() ) d->selectedFiles->removeSelected(); } void PlayListWidget::addAllToList() { DocLnkSet files; Global::findDocuments(&files, "video/*;audio/*"); QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) d->selectedFiles->addToSelection( **dit ); } void PlayListWidget::addAllMusicToList() { DocLnkSet files; Global::findDocuments(&files, "audio/*"); QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) d->selectedFiles->addToSelection( **dit ); } void PlayListWidget::addAllVideoToList() { DocLnkSet files; Global::findDocuments(&files, "video/*"); QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) d->selectedFiles->addToSelection( **dit ); } void PlayListWidget::setDocument(const QString& fileref) { + fromSetDocument = TRUE; if ( fileref.isNull() ) { QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); return; } -// qDebug("setDocument"); +// qDebug("setDocument "+fileref); if(fileref.find("playlist",0,TRUE) == -1) { - addToSelection( DocLnk( fileref ) ); - d->setDocumentUsed = TRUE; - qApp->processEvents(); - mediaPlayerState->setPlaying( FALSE ); - qApp->processEvents(); - mediaPlayerState->setPlaying( TRUE ); - d->selectedFiles->removeSelected( ); - } else { + clearList(); + addToSelection( DocLnk( fileref ) ); + d->setDocumentUsed = TRUE; + mediaPlayerState->setPlaying( FALSE ); + qApp->processEvents(); + mediaPlayerState->setPlaying( TRUE ); + qApp->processEvents(); + setCaption("OpiePlayer"); + + } else { //is playlist + clearList(); loadList(DocLnk(fileref)); d->selectedFiles->first(); -// mediaPlayerState->setPlaying( TRUE ); -// mediaPlayerState->setPlaying( FALSE ); - } } void PlayListWidget::setActiveWindow() { // When we get raised we need to ensure that it switches views char origView = mediaPlayerState->view(); mediaPlayerState->setView( 'l' ); // invalidate mediaPlayerState->setView( origView ); // now switch back } void PlayListWidget::useSelectedDocument() { d->setDocumentUsed = FALSE; } -const DocLnk *PlayListWidget::current() { - -// qDebug("in Playlist widget ::current"); - if ( mediaPlayerState->playlist() ) { - return d->selectedFiles->current(); - } - else if ( d->setDocumentUsed && d->current ) { - return d->current; - } else { - return d->files->selected(); - } +const DocLnk *PlayListWidget::current() { // this is fugly + +// if( fromSetDocument) { +// qDebug("from setDoc"); +// DocLnkSet files; +// Global::findDocuments(&files, "video/*;audio/*"); +// QListIterator<DocLnk> dit( files.children() ); +// for ( ; dit.current(); ++dit ) { +// if(dit.current()->linkFile() == setDocFileRef) { +// qDebug(setDocFileRef); +// return dit; +// } +// } +// } else + switch (tabWidget->currentPageIndex()) { + case 0: //playlist + { + if ( mediaPlayerState->playlist() ) { + return d->selectedFiles->current(); + } + else if ( d->setDocumentUsed && d->current ) { + return d->current; + } else { + return d->files->selected(); + } + } + break; + case 1: { //audio + Global::findDocuments(&files, "audio/*"); + QListIterator<DocLnk> dit( files.children() ); + for ( ; dit.current(); ++dit ) { + if( dit.current()->name() == audioView->currentItem()->text(0)) + return dit; + } + } + break; + case 2: { // video + Global::findDocuments(&vFiles, "video/*"); + QListIterator<DocLnk> Vdit( vFiles.children() ); + for ( ; Vdit.current(); ++Vdit ) { + if( Vdit.current()->name() == videoView->currentItem()->text(0)) + return Vdit; + } + } + break; + }; } - bool PlayListWidget::prev() { if ( mediaPlayerState->playlist() ) { if ( mediaPlayerState->shuffled() ) { const DocLnk *cur = current(); int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); for ( int i = 0; i < j; i++ ) { if ( !d->selectedFiles->next() ) d->selectedFiles->first(); } if ( cur == current() ) if ( !d->selectedFiles->next() ) d->selectedFiles->first(); return TRUE; } else { if ( !d->selectedFiles->prev() ) { if ( mediaPlayerState->looping() ) { return d->selectedFiles->last(); } else { return FALSE; } } return TRUE; } } else { return mediaPlayerState->looping(); } } bool PlayListWidget::next() { if ( mediaPlayerState->playlist() ) { if ( mediaPlayerState->shuffled() ) { return prev(); } else { if ( !d->selectedFiles->next() ) { if ( mediaPlayerState->looping() ) { return d->selectedFiles->first(); } else { return FALSE; } } return TRUE; } } else { return mediaPlayerState->looping(); } } bool PlayListWidget::first() { if ( mediaPlayerState->playlist() ) return d->selectedFiles->first(); else return mediaPlayerState->looping(); } bool PlayListWidget::last() { if ( mediaPlayerState->playlist() ) return d->selectedFiles->last(); else return mediaPlayerState->looping(); } void PlayListWidget::saveList() { QString filename; InputDialog *fileDlg; fileDlg = new InputDialog(this,"Save Playlist",TRUE, 0); fileDlg->exec(); if( fileDlg->result() == 1 ) { if ( d->current ) delete d->current; filename = fileDlg->LineEdit1->text();//+".playlist"; // qDebug("saving playlist "+filename+".playlist"); Config cfg( filename +".playlist"); writeConfig( cfg ); if( playLists->selected()->name() == filename) { // qDebug("same name so delete lnk"); QFile().remove(playLists->selected()->file()); QFile().remove(playLists->selected()->linkFile()); playLists->reread(); } DocLnk lnk; // lnk.setComment( ""); lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D lnk.setIcon("mpegplayer/playlist2"); lnk.setName( filename); //sets file name if(!lnk.writeLink()) qDebug("Writing doclink did not work"); } Config config( "MediaPlayer" ); config.writeEntry("CurrentPlaylist",filename); setCaption("OpiePlayer: "+filename); d->selectedFiles->first(); if(fileDlg) delete fileDlg; - } - void PlayListWidget::loadList( const DocLnk & lnk) { QString name= lnk.name(); // qDebug("currentList is "+name); if( name.length()>1) { setCaption("OpiePlayer: "+name); // qDebug("load list "+ name+".playlist"); clearList(); Config cfg( name+".playlist"); readConfig(cfg); tabWidget->setCurrentPage(0); Config config( "MediaPlayer" ); config.writeEntry("CurrentPlaylist", name); d->selectedFiles->first(); } } - void PlayListWidget::setPlaylist( bool shown ) { if ( shown ) d->playListFrame->show(); else d->playListFrame->hide(); } - void PlayListWidget::setView( char view ) { if ( view == 'l' ) showMaximized(); else hide(); } void PlayListWidget::addSelected() { switch (tabWidget->currentPageIndex()) { case 0: //playlist break; case 1: { //audio addToSelection( audioView->selectedItem() ); } break; case 2: { // video addToSelection( videoView->selectedItem() ); } break; }; } void PlayListWidget::removeSelected() { d->selectedFiles->removeSelected( ); } void PlayListWidget::playIt( QListViewItem *it) { // d->setDocumentUsed = FALSE; mediaPlayerState->setPlaying(TRUE); } void PlayListWidget::addToSelection( QListViewItem *it) { d->setDocumentUsed = FALSE; if(it) { // qDebug("add to selection"); switch (tabWidget->currentPageIndex()) { case 1: { // qDebug("case 1"); QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) { // qDebug(dit.current()->name()); if( dit.current()->name() == it->text(0)) { d->selectedFiles->addToSelection( **dit ); } } } break; case 2: { // qDebug("case 2"); QListIterator<DocLnk> dit( vFiles.children() ); for ( ; dit.current(); ++dit ) { // qDebug(dit.current()->name()); if( dit.current()->name() == it->text(0)) { d->selectedFiles->addToSelection( **dit ); } } } break; case 0: break; }; tabWidget->setCurrentPage(0); // mediaPlayerState->setPlaying( TRUE ); } } void PlayListWidget::tabChanged(QWidget *widg) { switch ( tabWidget->currentPageIndex()) { case 0: { if( !tbDeletePlaylist->isHidden()) tbDeletePlaylist->hide(); d->tbRemoveFromList->setEnabled(TRUE); d->tbAddToList->setEnabled(FALSE); } break; case 1: { if( !tbDeletePlaylist->isHidden()) tbDeletePlaylist->hide(); d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); } break; case 2: { if( !tbDeletePlaylist->isHidden()) tbDeletePlaylist->hide(); d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); } break; case 3: { if( tbDeletePlaylist->isHidden()) tbDeletePlaylist->show(); playLists->reread(); } break; }; } -/* - list is right clicked*/ -void PlayListWidget::fauxPlay(QListViewItem *it) { - - switch (tabWidget->currentPageIndex()) { - case 0: //playlist - break; - case 1: { //audio - QListIterator<DocLnk> dit( files.children() ); - for ( ; dit.current(); ++dit ) { -// qDebug(dit.current()->name()); - if( dit.current()->name() == it->text(0)) { - d->selectedFiles->addToSelection( **dit ); - } - } - } - break; - case 2: { // video - QListIterator<DocLnk> dit( vFiles.children() ); - for ( ; dit.current(); ++dit ) { -// qDebug(dit.current()->name()); - if( dit.current()->name() == it->text(0)) { - d->selectedFiles->addToSelection( **dit ); - } - } - } - break; - }; - mediaPlayerState->setPlaying( TRUE ); -// tabWidget->setCurrentPage(0); - d->selectedFiles->removeSelected(); -} /* play button is pressed*/ -void PlayListWidget::btnPlay(bool b) { // this is fugly - switch ( tabWidget->currentPageIndex()) { - case 0: - { - mediaPlayerState->setPlaying(b); - } - break; - case 1: - { - addToSelection( audioView->selectedItem() ); - mediaPlayerState->setPlaying(b); - qApp->processEvents(); - d->selectedFiles->removeSelected( ); - tabWidget->setCurrentPage(1); - } - break; - case 2: - { - addToSelection( videoView->selectedItem() ); - mediaPlayerState->setPlaying(b); - qApp->processEvents(); - d->selectedFiles->removeSelected( ); - tabWidget->setCurrentPage(2); - } - break; - }; - +void PlayListWidget::btnPlay(bool b) { + mediaPlayerState->setPlaying(b); } void PlayListWidget::deletePlaylist() { switch( QMessageBox::information( this, (tr("Remove Playlist?")), (tr("You really want to delete\nthis playlist?")), (tr("Yes")), (tr("No")), 0 )){ case 0: // Yes clicked, QFile().remove(playLists->selected()->file()); QFile().remove(playLists->selected()->linkFile()); playLists->reread(); break; case 1: // Cancel break; }; } + +void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) +{ + switch (mouse) { + case 1: + break; + case 2:{ + QPopupMenu m; + m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); + m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); +// m.insertSeparator(); +// m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); + m.exec( QCursor::pos() ); + } + break; + }; + +} + +void PlayListWidget::playSelected() +{ + btnPlay( TRUE); +} + +void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) +{ + switch (mouse) { + case 1: + break; + case 2:{ + QPopupMenu m; + m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); + m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); +// m.insertSeparator(); + m.exec( QCursor::pos() ); + } + break; + }; + +} diff --git a/core/multimedia/opieplayer/playlistwidget.h b/core/multimedia/opieplayer/playlistwidget.h index e72551b..effc600 100644 --- a/core/multimedia/opieplayer/playlistwidget.h +++ b/core/multimedia/opieplayer/playlistwidget.h @@ -1,102 +1,107 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef PLAY_LIST_WIDGET_H #define PLAY_LIST_WIDGET_H #include <qmainwindow.h> #include <qpe/applnk.h> #include <qtabwidget.h> #include <qpe/fileselector.h> #include <qpushbutton.h> /* #include <qtimer.h> */ class PlayListWidgetPrivate; class Config; class QListViewItem; class QListView; class QPoint; class QAction; class QLabel; class PlayListWidget : public QMainWindow { Q_OBJECT public: PlayListWidget( QWidget* parent=0, const char* name=0, WFlags fl=0 ); ~PlayListWidget(); QTabWidget * tabWidget; - QAction *fullScreenButton, *scaleButton; - DocLnkSet files; - DocLnkSet vFiles; - QListView *audioView, *videoView, *playlistView; - QLabel *libString; + QAction *fullScreenButton, *scaleButton; + DocLnkSet files; + DocLnkSet vFiles; + QListView *audioView, *videoView, *playlistView; + QLabel *libString; + bool fromSetDocument; + QString setDocFileRef; // retrieve the current playlist entry (media file link) const DocLnk *current(); void useSelectedDocument(); /* QTimer * menuTimer; */ FileSelector* playLists; QPushButton *tbDeletePlaylist; public slots: void setDocument( const QString& fileref ); void addToSelection( const DocLnk& ); // Add a media file to the playlist void addToSelection( QListViewItem* ); // Add a media file to the playlist void setActiveWindow(); // need to handle this to show the right view void setPlaylist( bool ); // Show/Hide the playlist void setView( char ); void clearList(); void addAllToList(); void addAllMusicToList(); void addAllVideoToList(); void saveList(); // Save the playlist void loadList( const DocLnk &); // Load a playlist void playIt( QListViewItem *); - void fauxPlay(QListViewItem *); + void btnPlay(bool); void deletePlaylist(); bool first(); bool last(); bool next(); bool prev(); void addSelected(); void removeSelected(); void tabChanged(QWidget*); + void viewPressed( int, QListViewItem *, const QPoint&, int); + void playlistViewPressed( int, QListViewItem *, const QPoint&, int); + void playSelected(); /* void setFullScreen(); */ /* void setScaled(); */ protected: /* void contentsMousePressEvent( QMouseEvent * e ); */ /* void contentsMouseReleaseEvent( QMouseEvent * e ); */ private: void initializeStates(); void readConfig( Config& cfg ); void writeConfig( Config& cfg ) const; PlayListWidgetPrivate *d; // Private implementation data protected slots: /* void cancelMenuTimer(); */ /* void showFileMenu(); */ }; #endif // PLAY_LIST_WIDGET_H diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp index be838c4..bb5f9e8 100644 --- a/core/multimedia/opieplayer/videowidget.cpp +++ b/core/multimedia/opieplayer/videowidget.cpp @@ -1,423 +1,471 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include <qpe/resource.h> #include <qpe/mediaplayerplugininterface.h> #include <qwidget.h> #include <qpainter.h> #include <qpixmap.h> #include <qslider.h> #include <qdrawutil.h> #include "videowidget.h" #include "mediaplayerstate.h" #ifdef Q_WS_QWS # define USE_DIRECT_PAINTER # include <qdirectpainter_qws.h> # include <qgfxraster_qws.h> #endif extern MediaPlayerState *mediaPlayerState; static const int xo = 2; // movable x offset static const int yo = 0; // movable y offset struct MediaButton { int xPos, yPos; bool isToggle, isHeld, isDown; int controlType; }; // Layout information for the videoButtons (and if it is a toggle button or not) MediaButton videoButtons[] = { { 5+0*32+xo, 200+yo, FALSE, FALSE, FALSE, 4 }, // previous { 5+1*32+xo, 200+yo, FALSE, FALSE, FALSE, 1 }, // stop { 5+2*32+xo, 200+yo, TRUE, FALSE, FALSE, 0 }, // play { 5+3*32+xo, 200+yo, TRUE, FALSE, FALSE, 2 }, // pause { 5+4*32+xo, 200+yo, FALSE, FALSE, FALSE, 3 }, // next { 5+5*32+xo, 200+yo, FALSE, FALSE, FALSE, 8 }, // playlist { 5+6*32+xo, 200+yo, TRUE, FALSE, FALSE, 9 } // fullscreen }; static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { setCaption( tr("OpiePlayer") ); setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0a" ) ); pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0b" ) ); pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls0" ) ); currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); slider = new QSlider( Qt::Horizontal, this ); slider->setMinValue( 0 ); slider->setMaxValue( 1 ); slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); slider->setFocusPolicy( QWidget::NoFocus ); slider->setGeometry( QRect( 7, 250, 220, 20 ) ); connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); // Intialise state setLength( mediaPlayerState->length() ); setPosition( mediaPlayerState->position() ); setFullscreen( mediaPlayerState->fullscreen() ); setPaused( mediaPlayerState->paused() ); setPlaying( mediaPlayerState->playing() ); } VideoWidget::~VideoWidget() { for ( int i = 0; i < 3; i++ ) delete pixmaps[i]; delete currentFrame; } static bool videoSliderBeingMoved = FALSE; void VideoWidget::sliderPressed() { videoSliderBeingMoved = TRUE; } void VideoWidget::sliderReleased() { videoSliderBeingMoved = FALSE; if ( slider->width() == 0 ) return; long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); mediaPlayerState->setPosition( val ); } void VideoWidget::setPosition( long i ) { updateSlider( i, mediaPlayerState->length() ); } void VideoWidget::setLength( long max ) { updateSlider( mediaPlayerState->position(), max ); } void VideoWidget::setView( char view ) { if ( view == 'v' ) { makeVisible(); } else { // Effectively blank the view next time we show it so it looks nicer scaledWidth = 0; scaledHeight = 0; hide(); } } void VideoWidget::updateSlider( long i, long max ) { // Will flicker too much if we don't do this if ( max == 0 ) return; int width = slider->width(); int val = int((double)i * width / max); if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { if ( slider->value() != val ) slider->setValue( val ); if ( slider->maxValue() != width ) slider->setMaxValue( width ); } } void VideoWidget::setToggleButton( int i, bool down ) { if ( down != videoButtons[i].isDown ) toggleButton( i ); } void VideoWidget::toggleButton( int i ) { videoButtons[i].isDown = !videoButtons[i].isDown; QPainter p(this); paintButton ( &p, i ); } void VideoWidget::paintButton( QPainter *p, int i ) { int x = videoButtons[i].xPos; int y = videoButtons[i].yPos; int offset = 10 + videoButtons[i].isDown; p->drawPixmap( x, y, *pixmaps[videoButtons[i].isDown] ); p->drawPixmap( x + 1 + offset, y + offset, *pixmaps[2], 9 * videoButtons[i].controlType, 0, 9, 9 ); } void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { for ( int i = 0; i < numButtons; i++ ) { - int x = videoButtons[i].xPos; - int y = videoButtons[i].yPos; - if ( event->state() == QMouseEvent::LeftButton ) { - // The test to see if the mouse click is inside the circular button or not - // (compared with the radius squared to avoid a square-root of our distance) - int radius = 16; - QPoint center = QPoint( x + radius, y + radius ); - QPoint dXY = center - event->pos(); - int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); - bool isOnButton = dist <= (radius * radius); - if ( isOnButton != videoButtons[i].isHeld ) { - videoButtons[i].isHeld = isOnButton; - toggleButton(i); - } - } else { - if ( videoButtons[i].isHeld ) { - videoButtons[i].isHeld = FALSE; - if ( !videoButtons[i].isToggle ) - setToggleButton( i, FALSE ); - switch (i) { - case VideoPlay: mediaPlayerState->setPlaying(videoButtons[i].isDown); return; - case VideoStop: mediaPlayerState->setPlaying(FALSE); return; - case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return; - case VideoNext: mediaPlayerState->setNext(); return; - case VideoPrevious: mediaPlayerState->setPrev(); return; - case VideoPlayList: mediaPlayerState->setList(); return; - case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; - } - } - } + int x = videoButtons[i].xPos; + int y = videoButtons[i].yPos; + if ( event->state() == QMouseEvent::LeftButton ) { + // The test to see if the mouse click is inside the circular button or not + // (compared with the radius squared to avoid a square-root of our distance) + int radius = 16; + QPoint center = QPoint( x + radius, y + radius ); + QPoint dXY = center - event->pos(); + int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); + bool isOnButton = dist <= (radius * radius); + if ( isOnButton != videoButtons[i].isHeld ) { + videoButtons[i].isHeld = isOnButton; + toggleButton(i); + } + } else { + if ( videoButtons[i].isHeld ) { + videoButtons[i].isHeld = FALSE; + if ( !videoButtons[i].isToggle ) + setToggleButton( i, FALSE ); + switch (i) { + case VideoPlay: mediaPlayerState->setPlaying(videoButtons[i].isDown); return; + case VideoStop: mediaPlayerState->setPlaying(FALSE); return; + case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return; + case VideoNext: mediaPlayerState->setNext(); return; + case VideoPrevious: mediaPlayerState->setPrev(); return; + case VideoPlayList: mediaPlayerState->setList(); return; + case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; + } + } + } } } void VideoWidget::mousePressEvent( QMouseEvent *event ) { mouseMoveEvent( event ); } void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { if ( mediaPlayerState->fullscreen() ) { mediaPlayerState->setFullscreen( FALSE ); makeVisible(); - } else { + mouseMoveEvent( event ); } } void VideoWidget::makeVisible() { if ( mediaPlayerState->fullscreen() ) { setBackgroundMode( QWidget::NoBackground ); showFullScreen(); resize( qApp->desktop()->size() ); slider->hide(); } else { setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); showNormal(); showMaximized(); slider->show(); } } void VideoWidget::paintEvent( QPaintEvent * ) { QPainter p( this ); if ( mediaPlayerState->fullscreen() ) { // Clear the background p.setBrush( QBrush( Qt::black ) ); p.drawRect( rect() ); // Draw the current frame //p.drawImage( ); // If using directpainter we won't have a copy except whats on the screen } else { // draw border qDrawShadePanel( &p, 4, 15, 230, 170, colorGroup(), TRUE, 5, NULL ); // Clear the movie screen first p.setBrush( QBrush( Qt::black ) ); p.drawRect( 9, 20, 220, 160 ); // draw current frame (centrally positioned from scaling to maintain aspect ratio) p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); // draw the buttons for ( int i = 0; i < numButtons; i++ ) paintButton( &p, i ); // draw the slider slider->repaint( TRUE ); } } void VideoWidget::closeEvent( QCloseEvent* ) { mediaPlayerState->setList(); } bool VideoWidget::playVideo() { bool result = FALSE; int stream = 0; int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); int dd = QPixmap::defaultDepth(); int w = height(); int h = width(); ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; if ( mediaPlayerState->fullscreen() ) { #ifdef USE_DIRECT_PAINTER QDirectPainter p(this); if ( ( qt_screen->transformOrientation() == 3 ) && ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) { w = 320; h = 240; if ( mediaPlayerState->scaled() ) { // maintain aspect ratio if ( w * sh > sw * h ) w = sw * h / sh; else h = sh * w / sw; } else { w = sw; h = sh; } w--; // we can't allow libmpeg to overwrite. QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); int ox = roff.x() - height() + 2 + (height() - w) / 2; int oy = roff.y() + (width() - h) / 2; int sx = 0, sy = 0; uchar* fp = p.frameBuffer() + p.lineStep() * oy; fp += dd * ox / 8; uchar **jt = new uchar*[h]; for ( int i = h; i; i-- ) { jt[h - i] = fp; fp += p.lineStep(); } result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; delete [] jt; } else { #endif QPainter p(this); w = 320; h = 240; if ( mediaPlayerState->scaled() ) { // maintain aspect ratio if ( w * sh > sw * h ) w = sw * h / sh; else h = sh * w / sw; } else { w = sw; h = sh; } int bytes = ( dd == 16 ) ? 2 : 4; QImage tempFrame( w, h, bytes << 3 ); result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; if ( result && mediaPlayerState->fullscreen() ) { int rw = h, rh = w; QImage rotatedFrame( rw, rh, bytes << 3 ); ushort* in = (ushort*)tempFrame.bits(); ushort* out = (ushort*)rotatedFrame.bits(); int spl = rotatedFrame.bytesPerLine() / bytes; for (int x=0; x<h; x++) { if ( bytes == 2 ) { ushort* lout = out++ + (w - 1)*spl; for (int y=0; y<w; y++) { *lout=*in++; lout-=spl; } } else { ulong* lout = ((ulong *)out)++ + (w - 1)*spl; for (int y=0; y<w; y++) { *lout=*((ulong*)in)++; lout-=spl; } } } p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); } #ifdef USE_DIRECT_PAINTER } #endif } else { w = 220; h = 160; // maintain aspect ratio if ( w * sh > sw * h ) w = sw * h / sh; else h = sh * w / sw; result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; QPainter p( this ); // Image changed size, therefore need to blank the possibly unpainted regions first if ( scaledWidth != w || scaledHeight != h ) { p.setBrush( QBrush( Qt::black ) ); p.drawRect( 9, 20, 220, 160 ); } scaledWidth = w; scaledHeight = h; if ( result ) { p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); } } return result; } + +void VideoWidget::keyReleaseEvent( QKeyEvent *e) +{ + switch ( e->key() ) { +////////////////////////////// Zaurus keys + case Key_Home: + break; + case Key_F9: //activity + break; + case Key_F10: //contacts + break; + case Key_F11: //menu + break; + case Key_F12: //home + break; + case Key_F13: //mail + break; + case Key_Space: { + if(mediaPlayerState->playing()) { + mediaPlayerState->setPlaying(FALSE); + } else { + mediaPlayerState->setPlaying(TRUE); + } + } + break; + case Key_Down: +// toggleButton(6); +// emit lessClicked(); +// emit lessReleased(); +// toggleButton(6); + break; + case Key_Up: +// toggleButton(5); +// emit moreClicked(); +// emit moreReleased(); +// toggleButton(5); + break; + case Key_Right: + mediaPlayerState->setNext(); + break; + case Key_Left: + mediaPlayerState->setPrev(); + break; + case Key_Escape: + break; + + }; +} diff --git a/core/multimedia/opieplayer/videowidget.h b/core/multimedia/opieplayer/videowidget.h index cf13743..fe56ca1 100644 --- a/core/multimedia/opieplayer/videowidget.h +++ b/core/multimedia/opieplayer/videowidget.h @@ -1,87 +1,88 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef VIDEO_WIDGET_H #define VIDEO_WIDGET_H #include <qwidget.h> class QPixmap; class QSlider; enum VideoButtons { VideoPrevious, VideoStop, VideoPlay, VideoPause, VideoNext, VideoPlayList, VideoFullscreen }; class VideoWidget : public QWidget { Q_OBJECT public: VideoWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); ~VideoWidget(); bool playVideo(); public slots: void updateSlider( long, long ); void sliderPressed( ); void sliderReleased( ); void setPaused( bool b) { setToggleButton( VideoPause, b ); } void setPlaying( bool b) { setToggleButton( VideoPlay, b ); } void setFullscreen( bool b ) { setToggleButton( VideoFullscreen, b ); } void makeVisible(); void setPosition( long ); void setLength( long ); void setView( char ); signals: void sliderMoved( long ); protected: void paintEvent( QPaintEvent *pe ); void mouseMoveEvent( QMouseEvent *event ); void mousePressEvent( QMouseEvent *event ); void mouseReleaseEvent( QMouseEvent *event ); void closeEvent( QCloseEvent *event ); + void keyReleaseEvent( QKeyEvent *e); private: void paintButton( QPainter *p, int i ); void toggleButton( int ); void setToggleButton( int, bool ); QSlider *slider; QPixmap *pixmaps[3]; QImage *currentFrame; - int scaledWidth; + int scaledWidth; int scaledHeight; }; #endif // VIDEO_WIDGET_H |