00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MEDIAWIDGET_H
00024 #define MEDIAWIDGET_H
00025
00026 #include <qbitmap.h>
00027 #include <qwidget.h>
00028 #include <qmap.h>
00029
00030 #include "mediaplayerstate.h"
00031 #include "playlistwidget.h"
00032
00033 class Skin;
00034
00035 class MediaWidget : public QWidget
00036 {
00037 Q_OBJECT
00038 public:
00039 enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back, FullScreen, Undefined };
00040 enum ButtonType { NormalButton, ToggleButton };
00041
00042 struct Button
00043 {
00044 Button() : command( Undefined ), type( NormalButton ), isDown( false ) {}
00045
00046 Command command;
00047
00048 ButtonType type;
00049 bool isDown : 1;
00050
00051 QBitmap mask;
00052 QPixmap pixUp;
00053 QPixmap pixDown;
00054 };
00055 typedef QValueList<Button> ButtonVector;
00056
00057 struct SkinButtonInfo
00058 {
00059 Command command;
00060 const char *fileName;
00061 ButtonType type;
00062 };
00063
00064 struct GUIInfo
00065 {
00066 GUIInfo() : buttonInfo( 0 ), buttonCount( 0 ) {}
00067 GUIInfo( const QString &_fileNameInfix, const SkinButtonInfo *_buttonInfo, const uint _buttonCount )
00068 : fileNameInfix( _fileNameInfix ), buttonInfo( _buttonInfo ), buttonCount( _buttonCount )
00069 {}
00070
00071 QString fileNameInfix;
00072 const SkinButtonInfo *buttonInfo;
00073 const uint buttonCount;
00074 };
00075 typedef QValueList<GUIInfo> GUIInfoList;
00076
00077 MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 );
00078 virtual ~MediaWidget();
00079
00080 public slots:
00081 virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0;
00082 virtual void setLength( long length ) = 0;
00083 virtual void setPlaying( bool playing ) = 0;
00084
00085 virtual void loadSkin() = 0;
00086
00087 signals:
00088 void moreReleased();
00089 void lessReleased();
00090 void forwardReleased();
00091 void backReleased();
00092 void forwardClicked();
00093 void backClicked();
00094 void moreClicked();
00095 void lessClicked();
00096
00097 protected:
00098 void setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount,
00099 const Skin &skin );
00100 Button setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin );
00101
00102 void loadDefaultSkin( const GUIInfo &guiInfo );
00103 void loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin );
00104
00105 virtual void closeEvent( QCloseEvent * );
00106
00107 virtual void paintEvent( QPaintEvent *pe );
00108
00109 virtual void resizeEvent( QResizeEvent *e );
00110
00111 Button *buttonAt( const QPoint &position );
00112
00113 virtual void mousePressEvent( QMouseEvent *event );
00114 virtual void mouseReleaseEvent( QMouseEvent *event );
00115
00116 virtual void makeVisible();
00117
00118 void handleCommand( Command command, bool buttonDown );
00119
00120 bool isOverButton( const QPoint &position, int buttonId ) const;
00121
00122 void paintAllButtons( QPainter &p );
00123 void paintButton( const Button &button );
00124 void paintButton( QPainter &p, const Button &button );
00125
00126 void setToggleButton( Button &button, bool down );
00127 void setToggleButton( Command command, bool down );
00128 void toggleButton( Button &button );
00129
00130 MediaPlayerState &mediaPlayerState;
00131 PlayListWidget &playList;
00132
00133 ButtonVector buttons;
00134
00135 QImage buttonMask;
00136
00137 QPoint upperLeftOfButtonMask;
00138
00139 QPixmap backgroundPixmap;
00140 QImage buttonUpImage;
00141 QImage buttonDownImage;
00142
00143 static QPixmap combineImageWithBackground( const QImage &background, const QPixmap &pixmap, const QPoint &offset );
00144 static QPixmap addMaskToPixmap( const QPixmap &pix, const QBitmap &mask );
00145 };
00146
00147 #endif // MEDIAWIDGET_H
00148
00149