author | simon <simon> | 2002-12-09 15:23:45 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-09 15:23:45 (UTC) |
commit | ab22599627d84a6c6427d2440da4271b48f47c8e (patch) (unidiff) | |
tree | 7afdd78444dc58245a5dd3a110f454354ddd3e2f | |
parent | 47d689545e68f2439cc88630ac78016712f92cc9 (diff) | |
download | opie-ab22599627d84a6c6427d2440da4271b48f47c8e.zip opie-ab22599627d84a6c6427d2440da4271b48f47c8e.tar.gz opie-ab22599627d84a6c6427d2440da4271b48f47c8e.tar.bz2 |
- minor cleanup
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 11 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 2 |
2 files changed, 8 insertions, 5 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index 3a44185..b73a5c0 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp | |||
@@ -35,86 +35,89 @@ MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPla | |||
35 | this, SLOT( setPlaying( bool ) ) ); | 35 | this, SLOT( setPlaying( bool ) ) ); |
36 | } | 36 | } |
37 | 37 | ||
38 | MediaWidget::~MediaWidget() | 38 | MediaWidget::~MediaWidget() |
39 | { | 39 | { |
40 | } | 40 | } |
41 | 41 | ||
42 | void MediaWidget::closeEvent( QCloseEvent * ) | 42 | void MediaWidget::closeEvent( QCloseEvent * ) |
43 | { | 43 | { |
44 | mediaPlayerState.setList(); | 44 | mediaPlayerState.setList(); |
45 | } | 45 | } |
46 | 46 | ||
47 | void MediaWidget::paintEvent( QPaintEvent *pe ) | 47 | void MediaWidget::paintEvent( QPaintEvent *pe ) |
48 | { | 48 | { |
49 | QPainter p( this ); | 49 | QPainter p( this ); |
50 | 50 | ||
51 | if ( mediaPlayerState.isFullscreen() ) { | 51 | if ( mediaPlayerState.isFullscreen() ) { |
52 | // Clear the background | 52 | // Clear the background |
53 | p.setBrush( QBrush( Qt::black ) ); | 53 | p.setBrush( QBrush( Qt::black ) ); |
54 | return; | 54 | return; |
55 | } | 55 | } |
56 | 56 | ||
57 | if ( !pe->erased() ) { | 57 | if ( !pe->erased() ) { |
58 | // Combine with background and double buffer | 58 | // Combine with background and double buffer |
59 | QPixmap pix( pe->rect().size() ); | 59 | QPixmap pix( pe->rect().size() ); |
60 | QPainter p( &pix ); | 60 | QPainter p( &pix ); |
61 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 61 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
62 | p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); | 62 | p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); |
63 | for ( unsigned int i = 0; i < buttons.count(); i++ ) { | 63 | for ( unsigned int i = 0; i < buttons.count(); i++ ) { |
64 | paintButton( p, buttons[ i ] ); | 64 | paintButton( p, buttons[ i ] ); |
65 | } | 65 | } |
66 | QPainter p2( this ); | 66 | QPainter p2( this ); |
67 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 67 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
68 | } else { | 68 | } else { |
69 | QPainter p( this ); | 69 | QPainter p( this ); |
70 | for ( unsigned int i = 0; i < buttons.count(); i++ ) | 70 | for ( unsigned int i = 0; i < buttons.count(); i++ ) |
71 | paintButton( p, buttons[ i ] ); | 71 | paintButton( p, buttons[ i ] ); |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | void MediaWidget::handleCommand( Command command, bool buttonDown ) | 75 | void MediaWidget::handleCommand( Command command, bool buttonDown ) |
76 | { | 76 | { |
77 | switch ( command ) { | 77 | switch ( command ) { |
78 | case Play: mediaPlayerState.togglePaused(); | 78 | case Play: mediaPlayerState.togglePaused(); |
79 | case Stop: mediaPlayerState.setPlaying(FALSE); return; | 79 | case Stop: mediaPlayerState.setPlaying(FALSE); return; |
80 | case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; | 80 | case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; |
81 | case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; | 81 | case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; |
82 | case Loop: mediaPlayerState.setLooping( buttonDown ); return; | 82 | case Loop: mediaPlayerState.setLooping( buttonDown ); return; |
83 | case VolumeUp: emit moreReleased(); return; | 83 | case VolumeUp: emit moreReleased(); return; |
84 | case VolumeDown: emit lessReleased(); return; | 84 | case VolumeDown: emit lessReleased(); return; |
85 | case PlayList: mediaPlayerState.setList(); return; | 85 | case PlayList: mediaPlayerState.setList(); return; |
86 | case Forward: emit forwardReleased(); return; | 86 | case Forward: emit forwardReleased(); return; |
87 | case Back: emit backReleased(); return; | 87 | case Back: emit backReleased(); return; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const | 91 | bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const |
92 | { | 92 | { |
93 | return ( position.x() > 0 && position.y() > 0 && | 93 | return ( position.x() > 0 && position.y() > 0 && |
94 | position.x() < buttonMask.width() && | 94 | position.x() < buttonMask.width() && |
95 | position.y() < buttonMask.height() && | 95 | position.y() < buttonMask.height() && |
96 | buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); | 96 | buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); |
97 | } | 97 | } |
98 | 98 | ||
99 | void MediaWidget::paintButton( int buttonId ) | 99 | void MediaWidget::paintButton( const Button &button ) |
100 | { | 100 | { |
101 | QPainter p( this ); | 101 | QPainter p( this ); |
102 | paintButton( p, buttons[ buttonId ] ); | 102 | paintButton( p, button ); |
103 | } | 103 | } |
104 | 104 | ||
105 | void MediaWidget::paintButton( QPainter &p, const Button &button ) | 105 | void MediaWidget::paintButton( QPainter &p, const Button &button ) |
106 | { | 106 | { |
107 | if ( button.isDown ) | 107 | if ( button.isDown ) |
108 | p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); | 108 | p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); |
109 | else | 109 | else |
110 | p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); | 110 | p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); |
111 | } | 111 | } |
112 | 112 | ||
113 | void MediaWidget::toggleButton( int buttonId ) | 113 | void MediaWidget::toggleButton( int buttonId ) |
114 | { | 114 | { |
115 | buttons[ buttonId ].isDown = !buttons[ buttonId ].isDown; | 115 | Button &button = buttons[ buttonId ]; |
116 | paintButton( buttonId ); | 116 | |
117 | button.isDown = !button.isDown; | ||
118 | |||
119 | paintButton( button ); | ||
117 | } | 120 | } |
118 | 121 | ||
119 | /* vim: et sw=4 ts=4 | 122 | /* vim: et sw=4 ts=4 |
120 | */ | 123 | */ |
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index 8cdaad1..dcf7fb8 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h | |||
@@ -26,84 +26,84 @@ | |||
26 | #include <qwidget.h> | 26 | #include <qwidget.h> |
27 | #include <qmap.h> | 27 | #include <qmap.h> |
28 | 28 | ||
29 | #include "mediaplayerstate.h" | 29 | #include "mediaplayerstate.h" |
30 | #include "playlistwidget.h" | 30 | #include "playlistwidget.h" |
31 | 31 | ||
32 | #include <vector> | 32 | #include <vector> |
33 | 33 | ||
34 | class MediaWidget : public QWidget | 34 | class MediaWidget : public QWidget |
35 | { | 35 | { |
36 | Q_OBJECT | 36 | Q_OBJECT |
37 | public: | 37 | public: |
38 | enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back }; | 38 | enum Command { Play = 0, Stop, Next, Previous, VolumeUp, VolumeDown, Loop, PlayList, Forward, Back }; |
39 | enum ButtonType { NormalButton, ToggleButton }; | 39 | enum ButtonType { NormalButton, ToggleButton }; |
40 | 40 | ||
41 | struct Button | 41 | struct Button |
42 | { | 42 | { |
43 | Button() : type( NormalButton ), isHeld( false ), isDown( false ) {} | 43 | Button() : type( NormalButton ), isHeld( false ), isDown( false ) {} |
44 | 44 | ||
45 | ButtonType type : 1; | 45 | ButtonType type : 1; |
46 | bool isHeld : 1; | 46 | bool isHeld : 1; |
47 | bool isDown : 1; | 47 | bool isDown : 1; |
48 | 48 | ||
49 | QBitmap mask; | 49 | QBitmap mask; |
50 | QPixmap pixUp; | 50 | QPixmap pixUp; |
51 | QPixmap pixDown; | 51 | QPixmap pixDown; |
52 | }; | 52 | }; |
53 | typedef std::vector<Button> ButtonVector; | 53 | typedef std::vector<Button> ButtonVector; |
54 | // when the transition is done this should be Command -> Button | 54 | // when the transition is done this should be Command -> Button |
55 | typedef QMap<int, Button> ButtonMap; | 55 | typedef QMap<int, Button> ButtonMap; |
56 | 56 | ||
57 | struct SkinButtonInfo | 57 | struct SkinButtonInfo |
58 | { | 58 | { |
59 | Command command; | 59 | Command command; |
60 | const char *fileName; | 60 | const char *fileName; |
61 | ButtonType type; | 61 | ButtonType type; |
62 | }; | 62 | }; |
63 | 63 | ||
64 | typedef std::vector<QBitmap> MaskVector; | 64 | typedef std::vector<QBitmap> MaskVector; |
65 | typedef std::vector<QPixmap> PixmapVector; | 65 | typedef std::vector<QPixmap> PixmapVector; |
66 | 66 | ||
67 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); | 67 | MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent = 0, const char *name = 0 ); |
68 | virtual ~MediaWidget(); | 68 | virtual ~MediaWidget(); |
69 | 69 | ||
70 | public slots: | 70 | public slots: |
71 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; | 71 | virtual void setDisplayType( MediaPlayerState::DisplayType displayType ) = 0; |
72 | virtual void setLength( long length ) = 0; | 72 | virtual void setLength( long length ) = 0; |
73 | virtual void setPlaying( bool playing ) = 0; | 73 | virtual void setPlaying( bool playing ) = 0; |
74 | 74 | ||
75 | signals: | 75 | signals: |
76 | void moreReleased(); | 76 | void moreReleased(); |
77 | void lessReleased(); | 77 | void lessReleased(); |
78 | void forwardReleased(); | 78 | void forwardReleased(); |
79 | void backReleased(); | 79 | void backReleased(); |
80 | 80 | ||
81 | protected: | 81 | protected: |
82 | virtual void closeEvent( QCloseEvent * ); | 82 | virtual void closeEvent( QCloseEvent * ); |
83 | 83 | ||
84 | virtual void paintEvent( QPaintEvent *pe ); | 84 | virtual void paintEvent( QPaintEvent *pe ); |
85 | 85 | ||
86 | void handleCommand( Command command, bool buttonDown ); | 86 | void handleCommand( Command command, bool buttonDown ); |
87 | 87 | ||
88 | bool isOverButton( const QPoint &position, int buttonId ) const; | 88 | bool isOverButton( const QPoint &position, int buttonId ) const; |
89 | 89 | ||
90 | void paintButton( int buttonId ); | 90 | void paintButton( const Button &button ); |
91 | void paintButton( QPainter &p, const Button &button ); | 91 | void paintButton( QPainter &p, const Button &button ); |
92 | 92 | ||
93 | void toggleButton( int buttonId ); | 93 | void toggleButton( int buttonId ); |
94 | 94 | ||
95 | MediaPlayerState &mediaPlayerState; | 95 | MediaPlayerState &mediaPlayerState; |
96 | PlayListWidget &playList; | 96 | PlayListWidget &playList; |
97 | 97 | ||
98 | ButtonMap buttons; | 98 | ButtonMap buttons; |
99 | 99 | ||
100 | QImage buttonMask; | 100 | QImage buttonMask; |
101 | 101 | ||
102 | QPoint upperLeftOfButtonMask; | 102 | QPoint upperLeftOfButtonMask; |
103 | 103 | ||
104 | QPixmap backgroundPixmap; | 104 | QPixmap backgroundPixmap; |
105 | }; | 105 | }; |
106 | 106 | ||
107 | #endif // MEDIAWIDGET_H | 107 | #endif // MEDIAWIDGET_H |
108 | /* vim: et sw=4 ts=4 | 108 | /* vim: et sw=4 ts=4 |
109 | */ | 109 | */ |