summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/audiowidget.h
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer2/audiowidget.h') (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/audiowidget.h125
1 files changed, 125 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/audiowidget.h b/noncore/multimedia/opieplayer2/audiowidget.h
new file mode 100644
index 0000000..eab5df4
--- a/dev/null
+++ b/noncore/multimedia/opieplayer2/audiowidget.h
@@ -0,0 +1,125 @@
1#ifndef AUDIO_WIDGET_H
2#define AUDIO_WIDGET_H
3
4#include <qwidget.h>
5#include <qpainter.h>
6#include <qdrawutil.h>
7#include <qpixmap.h>
8#include <qstring.h>
9#include <qslider.h>
10#include <qframe.h>
11
12
13class QPixmap;
14
15enum AudioButtons {
16 AudioPlay,
17 AudioStop,
18 AudioPause,
19 AudioNext,
20 AudioPrevious,
21 AudioVolumeUp,
22 AudioVolumeDown,
23 AudioLoop,
24 AudioPlayList
25};
26
27
28#define USE_DBLBUF
29
30
31class Ticker : public QFrame {
32 Q_OBJECT
33public:
34 Ticker( QWidget* parent=0 ) : QFrame( parent ) {
35 setFrameStyle( WinPanel | Sunken );
36 setText( "No Song" );
37 }
38 ~Ticker() { }
39 void setText( const QString& text ) {
40 pos = 0; // reset it everytime the text is changed
41 scrollText = text;
42 pixelLen = fontMetrics().width( scrollText );
43 killTimers();
44 if ( pixelLen > width() )
45 startTimer( 50 );
46 update();
47 }
48protected:
49 void timerEvent( QTimerEvent * ) {
50 pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1;
51#ifndef USE_DBLBUF
52 scroll( -1, 0, contentsRect() );
53#else
54 repaint( FALSE );
55#endif
56 }
57 void drawContents( QPainter *p ) {
58#ifndef USE_DBLBUF
59 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen )
60 p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText );
61#else
62 // Double buffering code.
63 // Looks like qvfb makes it look like it flickers but I don't think it really is
64 QPixmap pm( width(), height() );
65 pm.fill( colorGroup().base() );
66 QPainter pmp( &pm );
67 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen )
68 pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText );
69 p->drawPixmap( 0, 0, pm );
70#endif
71 }
72private:
73 QString scrollText;
74 int pos, pixelLen;
75};
76
77
78class AudioWidget : public QWidget {
79 Q_OBJECT
80public:
81 AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 );
82 ~AudioWidget();
83 void setTickerText( const QString &text ) { songInfo->setText( text ); }
84 bool isStreaming;
85public slots:
86 void updateSlider( long, long );
87 void sliderPressed( );
88 void sliderReleased( );
89 void setPaused( bool b) { setToggleButton( AudioPause, b ); }
90 void setLooping( bool b) { setToggleButton( AudioLoop, b ); }
91 void setPlaying( bool b) { setToggleButton( AudioPlay, b ); }
92 void setPosition( long );
93 void setLength( long );
94 void setView( char );
95
96signals:
97 void moreClicked();
98 void lessClicked();
99 void moreReleased();
100 void lessReleased();
101 void sliderMoved(long);
102
103protected:
104 void doBlank();
105 void doUnblank();
106 void paintEvent( QPaintEvent *pe );
107 void showEvent( QShowEvent *se );
108 void mouseMoveEvent( QMouseEvent *event );
109 void mousePressEvent( QMouseEvent *event );
110 void mouseReleaseEvent( QMouseEvent *event );
111 void timerEvent( QTimerEvent *event );
112 void closeEvent( QCloseEvent *event );
113 void keyReleaseEvent( QKeyEvent *e);
114private:
115 void toggleButton( int );
116 void setToggleButton( int, bool );
117 void paintButton( QPainter *p, int i );
118 QPixmap *pixmaps[4];
119 Ticker *songInfo;
120 QSlider *slider;
121};
122
123
124#endif // AUDIO_WIDGET_H
125