summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.cpp105
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.h51
2 files changed, 134 insertions, 22 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp
index 955169c..6b656ee 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.cpp
+++ b/noncore/multimedia/opieplayer2/audiowidget.cpp
@@ -1,48 +1,80 @@
+/*
+                This file is part of the Opie Project
+
+              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
+ Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
+ Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
+ =.
+ .=l.
+           .>+-=
+ _;:,     .>    :=|. This program is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This program is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.=       =       ; Library General Public License for more
+++=   -.     .`     .: details.
+ :     =  ...= . :.=-
+ -.   .:....=;==+<; You should have received a copy of the GNU
+  -_. . .   )=.  = Library General Public License along with
+    --        :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
#include <qpe/qpeapplication.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <qwidget.h>
#include <qpixmap.h>
#include <qbutton.h>
#include <qpainter.h>
#include <qframe.h>
#include <qlayout.h>
#include <stdlib.h>
#include <stdio.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
Ticker::Ticker( QWidget* parent=0 ) : QFrame( parent ) {
setFrameStyle( WinPanel | Sunken );
setText( "No Song" );
}
Ticker::~Ticker() {
}
void Ticker::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();
}
void Ticker::timerEvent( QTimerEvent * ) {
pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1;
scroll( -1, 0, contentsRect() );
repaint( FALSE );
@@ -117,96 +149,103 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png";
masks[i] = new QBitmap( filename );
if ( !masks[i]->isNull() ) {
QImage imgMask = masks[i]->convertToImage();
uchar **dest = imgButtonMask->jumpTable();
for ( int y = 0; y < imgUp->height(); y++ ) {
uchar *line = dest[y];
for ( int x = 0; x < imgUp->width(); x++ )
if ( !qRed( imgMask.pixel( x, y ) ) )
line[x] = i + 1;
}
}
}
for ( int i = 0; i < 11; i++ ) {
buttonPixUp[i] = NULL;
buttonPixDown[i] = NULL;
}
setBackgroundPixmap( *pixBg );
songInfo.setFocusPolicy( QWidget::NoFocus );
changeTextColor( &songInfo );
slider.setFixedHeight( 20 );
slider.setMinValue( 0 );
slider.setMaxValue( 1 );
slider.setFocusPolicy( QWidget::NoFocus );
slider.setBackgroundPixmap( *pixBg );
time.setFocusPolicy( QWidget::NoFocus );
time.setAlignment( Qt::AlignCenter );
time.setFrame(FALSE);
changeTextColor( &time );
resizeEvent( NULL );
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( 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) ) );
+ connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) );
+ connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) );
+ connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) );
+ connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) );
+
+
+
// Intialise state
setLength( mediaPlayerState->length() );
setPosition( mediaPlayerState->position() );
setLooping( mediaPlayerState->fullscreen() );
setPaused( mediaPlayerState->paused() );
setPlaying( mediaPlayerState->playing() );
}
AudioWidget::~AudioWidget() {
for ( int i = 0; i < 11; i++ ) {
delete buttonPixUp[i];
delete buttonPixDown[i];
}
delete pixBg;
delete imgUp;
delete imgDn;
delete imgButtonMask;
for ( int i = 0; i < 11; i++ ) {
delete masks[i];
}
}
QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
QPixmap pix( img.width(), img.height() );
QPainter p( &pix );
p.drawTiledPixmap( pix.rect(), bg, offset );
p.drawImage( 0, 0, img );
return new QPixmap( pix );
}
QPixmap *maskPixToMask( QPixmap pix, QBitmap mask )
{
QPixmap *pixmap = new QPixmap( pix );
pixmap->setMask( mask );
return pixmap;
}
void AudioWidget::resizeEvent( QResizeEvent * ) {
int h = height();
int w = width();
songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) );
slider.setFixedWidth( w - 110 );
@@ -296,147 +335,179 @@ static QString timeAsString( long length ) {
}
void AudioWidget::updateSlider( long i, long max ) {
time.setText( timeAsString( i ) + " / " + timeAsString( max ) );
// qDebug( timeAsString( i ) + " / " + timeAsString( 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 ) {
if ( audioButtons[i].isDown )
p->drawPixmap( xoff, yoff, *buttonPixDown[i] );
else
p->drawPixmap( xoff, yoff, *buttonPixUp[i] );
}
+void AudioWidget::skipFor() {
+ skipDirection = +1;
+ startTimer( 50 );
+ mediaPlayerState->setPosition( mediaPlayerState->position() + 2 );
+}
+
+void AudioWidget::skipBack() {
+ skipDirection = -1;
+ startTimer( 50 );
+ mediaPlayerState->setPosition( mediaPlayerState->position() - 2 );
+}
+
+
+
+void AudioWidget::stopSkip() {
+ killTimers();
+}
+
+
void AudioWidget::timerEvent( QTimerEvent * ) {
+ if ( skipDirection == +1 ) {
+ mediaPlayerState->setPosition( mediaPlayerState->position() + 2 );
+ } else if ( skipDirection == -1 ) {
+ mediaPlayerState->setPosition( mediaPlayerState->position() - 2 );
+ }
}
void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
for ( int i = 0; i < numButtons; i++ ) {
if ( event->state() == QMouseEvent::LeftButton ) {
// The test to see if the mouse click is inside the button or not
int x = event->pos().x() - xoff;
int y = event->pos().y() - yoff;
bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width()
&& y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 );
if ( isOnButton && i == AudioVolumeUp )
qDebug("on up");
if ( isOnButton && !audioButtons[i].isHeld ) {
audioButtons[i].isHeld = TRUE;
toggleButton(i);
switch (i) {
- case AudioVolumeUp:
- qDebug("more clicked");
- emit moreClicked();
- return;
- case AudioVolumeDown:
- emit lessClicked();
- return;
+ case AudioVolumeUp:
+ qDebug("more clicked");
+ emit moreClicked();
+ return;
+ case AudioVolumeDown:
+ emit lessClicked();
+ return;
+ case AudioForward:
+ emit forwardClicked();
+ return;
+ case AudioBack:
+ emit backClicked();
+ 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 );
- qDebug("button toggled3 %d",i);
+ qDebug("button toggled3 %d",i);
}
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;
+ 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;
+ case AudioForward: emit forwardReleased(); return;
+ case AudioBack: emit backReleased(); 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 * pe) {
if ( !pe->erased() ) {
// Combine with background and double buffer
QPixmap pix( pe->rect().size() );
QPainter p( &pix );
p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() );
for ( int i = 0; i < numButtons; i++ )
paintButton( &p, i );
QPainter p2( this );
p2.drawPixmap( pe->rect().topLeft(), pix );
} else {
QPainter p( this );
for ( int i = 0; i < numButtons; i++ )
paintButton( &p, i );
}
}
void AudioWidget::keyReleaseEvent( QKeyEvent *e)
{
diff --git a/noncore/multimedia/opieplayer2/audiowidget.h b/noncore/multimedia/opieplayer2/audiowidget.h
index 2b892be..e05188e 100644
--- a/noncore/multimedia/opieplayer2/audiowidget.h
+++ b/noncore/multimedia/opieplayer2/audiowidget.h
@@ -1,108 +1,149 @@
+/*
+                This file is part of the Opie Project
+
+              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
+ Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
+ Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
+ =.
+ .=l.
+           .>+-=
+ _;:,     .>    :=|. This program is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This program is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.=       =       ; Library General Public License for more
+++=   -.     .`     .: details.
+ :     =  ...= . :.=-
+ -.   .:....=;==+<; You should have received a copy of the GNU
+  -_. . .   )=.  = Library General Public License along with
+    --        :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
#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>
#include <qlineedit.h>
class QPixmap;
enum AudioButtons {
AudioPlay=0,
AudioStop,
AudioPause,
AudioNext,
AudioPrevious,
AudioVolumeUp,
AudioVolumeDown,
AudioLoop,
- AudioPlayList
+ AudioPlayList,
+ AudioForward,
+ AudioBack
};
-//#define USE_DBLBUF
-
-
class Ticker : public QFrame {
Q_OBJECT
public:
Ticker( QWidget* parent=0 );
~Ticker();
void setText( const QString& text ) ;
protected:
void timerEvent( QTimerEvent * );
void drawContents( QPainter *p );
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 ); }
bool isStreaming;
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 forwardClicked();
+ void backClicked();
+ void forwardReleased();
+ void backReleased();
void sliderMoved(long);
protected:
void doBlank();
void doUnblank();
void paintEvent( QPaintEvent *pe );
void showEvent( QShowEvent *se );
void resizeEvent( QResizeEvent *re );
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 slots:
+ void skipFor();
+ void skipBack();
+ void stopSkip();
private:
void toggleButton( int );
void setToggleButton( int, bool );
void paintButton( QPainter *p, int i );
+ int skipDirection;
QString skin;
QPixmap *pixBg;
QImage *imgUp;
QImage *imgDn;
QImage *imgButtonMask;
QBitmap *masks[11];
QPixmap *buttonPixUp[11];
QPixmap *buttonPixDown[11];
-
+
QPixmap *pixmaps[4];
Ticker songInfo;
QSlider slider;
QLineEdit time;
int xoff, yoff;
};
#endif // AUDIO_WIDGET_H