author | simon <simon> | 2002-12-09 15:31:35 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-09 15:31:35 (UTC) |
commit | 159a3334ecd168f422afe81853998373457fefa0 (patch) (unidiff) | |
tree | 2672138cdabca5b73f3828d3b88b31bb1b280c67 | |
parent | ab22599627d84a6c6427d2440da4271b48f47c8e (diff) | |
download | opie-159a3334ecd168f422afe81853998373457fefa0.zip opie-159a3334ecd168f422afe81853998373457fefa0.tar.gz opie-159a3334ecd168f422afe81853998373457fefa0.tar.bz2 |
- minor cleanup in paintEvent
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 14 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.h | 1 |
2 files changed, 10 insertions, 5 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index b73a5c0..271f788 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp | |||
@@ -39,84 +39,88 @@ 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 | paintAllButtons( p ); |
64 | paintButton( p, buttons[ i ] ); | ||
65 | } | ||
66 | QPainter p2( this ); | 64 | QPainter p2( this ); |
67 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 65 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
68 | } else { | 66 | } else { |
69 | QPainter p( this ); | 67 | QPainter p( this ); |
70 | for ( unsigned int i = 0; i < buttons.count(); i++ ) | 68 | paintAllButtons( p ); |
71 | paintButton( p, buttons[ i ] ); | ||
72 | } | 69 | } |
73 | } | 70 | } |
74 | 71 | ||
75 | void MediaWidget::handleCommand( Command command, bool buttonDown ) | 72 | void MediaWidget::handleCommand( Command command, bool buttonDown ) |
76 | { | 73 | { |
77 | switch ( command ) { | 74 | switch ( command ) { |
78 | case Play: mediaPlayerState.togglePaused(); | 75 | case Play: mediaPlayerState.togglePaused(); |
79 | case Stop: mediaPlayerState.setPlaying(FALSE); return; | 76 | case Stop: mediaPlayerState.setPlaying(FALSE); return; |
80 | case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; | 77 | case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; |
81 | case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; | 78 | case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; |
82 | case Loop: mediaPlayerState.setLooping( buttonDown ); return; | 79 | case Loop: mediaPlayerState.setLooping( buttonDown ); return; |
83 | case VolumeUp: emit moreReleased(); return; | 80 | case VolumeUp: emit moreReleased(); return; |
84 | case VolumeDown: emit lessReleased(); return; | 81 | case VolumeDown: emit lessReleased(); return; |
85 | case PlayList: mediaPlayerState.setList(); return; | 82 | case PlayList: mediaPlayerState.setList(); return; |
86 | case Forward: emit forwardReleased(); return; | 83 | case Forward: emit forwardReleased(); return; |
87 | case Back: emit backReleased(); return; | 84 | case Back: emit backReleased(); return; |
88 | } | 85 | } |
89 | } | 86 | } |
90 | 87 | ||
91 | bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const | 88 | bool MediaWidget::isOverButton( const QPoint &position, int buttonId ) const |
92 | { | 89 | { |
93 | return ( position.x() > 0 && position.y() > 0 && | 90 | return ( position.x() > 0 && position.y() > 0 && |
94 | position.x() < buttonMask.width() && | 91 | position.x() < buttonMask.width() && |
95 | position.y() < buttonMask.height() && | 92 | position.y() < buttonMask.height() && |
96 | buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); | 93 | buttonMask.pixelIndex( position.x(), position.y() ) == buttonId + 1 ); |
97 | } | 94 | } |
98 | 95 | ||
96 | void MediaWidget::paintAllButtons( QPainter &p ) | ||
97 | { | ||
98 | for ( ButtonMap::ConstIterator it = buttons.begin(); | ||
99 | it != buttons.end(); ++it ) | ||
100 | paintButton( *it ); | ||
101 | } | ||
102 | |||
99 | void MediaWidget::paintButton( const Button &button ) | 103 | void MediaWidget::paintButton( const Button &button ) |
100 | { | 104 | { |
101 | QPainter p( this ); | 105 | QPainter p( this ); |
102 | paintButton( p, button ); | 106 | paintButton( p, button ); |
103 | } | 107 | } |
104 | 108 | ||
105 | void MediaWidget::paintButton( QPainter &p, const Button &button ) | 109 | void MediaWidget::paintButton( QPainter &p, const Button &button ) |
106 | { | 110 | { |
107 | if ( button.isDown ) | 111 | if ( button.isDown ) |
108 | p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); | 112 | p.drawPixmap( upperLeftOfButtonMask, button.pixDown ); |
109 | else | 113 | else |
110 | p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); | 114 | p.drawPixmap( upperLeftOfButtonMask, button.pixUp ); |
111 | } | 115 | } |
112 | 116 | ||
113 | void MediaWidget::toggleButton( int buttonId ) | 117 | void MediaWidget::toggleButton( int buttonId ) |
114 | { | 118 | { |
115 | Button &button = buttons[ buttonId ]; | 119 | Button &button = buttons[ buttonId ]; |
116 | 120 | ||
117 | button.isDown = !button.isDown; | 121 | button.isDown = !button.isDown; |
118 | 122 | ||
119 | paintButton( button ); | 123 | paintButton( button ); |
120 | } | 124 | } |
121 | 125 | ||
122 | /* vim: et sw=4 ts=4 | 126 | /* vim: et sw=4 ts=4 |
diff --git a/noncore/multimedia/opieplayer2/mediawidget.h b/noncore/multimedia/opieplayer2/mediawidget.h index dcf7fb8..34910fb 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.h +++ b/noncore/multimedia/opieplayer2/mediawidget.h | |||
@@ -66,44 +66,45 @@ public: | |||
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 paintAllButtons( QPainter &p ); | ||
90 | void paintButton( const Button &button ); | 91 | void paintButton( const Button &button ); |
91 | void paintButton( QPainter &p, const Button &button ); | 92 | void paintButton( QPainter &p, const Button &button ); |
92 | 93 | ||
93 | void toggleButton( int buttonId ); | 94 | void toggleButton( int buttonId ); |
94 | 95 | ||
95 | MediaPlayerState &mediaPlayerState; | 96 | MediaPlayerState &mediaPlayerState; |
96 | PlayListWidget &playList; | 97 | PlayListWidget &playList; |
97 | 98 | ||
98 | ButtonMap buttons; | 99 | ButtonMap buttons; |
99 | 100 | ||
100 | QImage buttonMask; | 101 | QImage buttonMask; |
101 | 102 | ||
102 | QPoint upperLeftOfButtonMask; | 103 | QPoint upperLeftOfButtonMask; |
103 | 104 | ||
104 | QPixmap backgroundPixmap; | 105 | QPixmap backgroundPixmap; |
105 | }; | 106 | }; |
106 | 107 | ||
107 | #endif // MEDIAWIDGET_H | 108 | #endif // MEDIAWIDGET_H |
108 | /* vim: et sw=4 ts=4 | 109 | /* vim: et sw=4 ts=4 |
109 | */ | 110 | */ |