summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediawidget.cpp4
-rw-r--r--noncore/multimedia/opieplayer2/skin.cpp10
-rw-r--r--noncore/multimedia/opieplayer2/skin.h5
3 files changed, 17 insertions, 2 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp
index 617e0fe..2031b4d 100644
--- a/noncore/multimedia/opieplayer2/mediawidget.cpp
+++ b/noncore/multimedia/opieplayer2/mediawidget.cpp
@@ -12,194 +12,194 @@
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23 23
24#include "mediawidget.h" 24#include "mediawidget.h"
25#include "playlistwidget.h" 25#include "playlistwidget.h"
26#include "skin.h" 26#include "skin.h"
27 27
28#include <qpe/config.h> 28#include <qpe/config.h>
29#include <qpe/qpeapplication.h> 29#include <qpe/qpeapplication.h>
30 30
31MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) 31MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name )
32 : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) 32 : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList )
33{ 33{
34 connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), 34 connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ),
35 this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); 35 this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) );
36 connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), 36 connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ),
37 this, SLOT( setLength( long ) ) ); 37 this, SLOT( setLength( long ) ) );
38 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), 38 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ),
39 this, SLOT( setPlaying( bool ) ) ); 39 this, SLOT( setPlaying( bool ) ) );
40} 40}
41 41
42MediaWidget::~MediaWidget() 42MediaWidget::~MediaWidget()
43{ 43{
44} 44}
45 45
46void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, 46void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount,
47 const QString &imagePrefix, const QSize &buttonAreaSize ) 47 const QString &imagePrefix, const QSize &buttonAreaSize )
48{ 48{
49 buttonMask = QImage( buttonAreaSize, 8, 255 ); 49 buttonMask = QImage( buttonAreaSize, 8, 255 );
50 buttonMask.fill( 0 ); 50 buttonMask.fill( 0 );
51 51
52 buttons.clear(); 52 buttons.clear();
53 buttons.reserve( buttonCount ); 53 buttons.reserve( buttonCount );
54 54
55 for ( uint i = 0; i < buttonCount; ++i ) { 55 for ( uint i = 0; i < buttonCount; ++i ) {
56 Button button = setupButton( skinInfo[ i ], imagePrefix ); 56 Button button = setupButton( skinInfo[ i ], imagePrefix );
57 buttons.push_back( button ); 57 buttons.push_back( button );
58 } 58 }
59} 59}
60 60
61MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix ) 61MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix )
62{ 62{
63 Button button; 63 Button button;
64 button.command = buttonInfo.command; 64 button.command = buttonInfo.command;
65 button.type = buttonInfo.type; 65 button.type = buttonInfo.type;
66 66
67 QString fileName = imagePrefix + buttonInfo.fileName + ".png"; 67 QString fileName = imagePrefix + buttonInfo.fileName + ".png";
68 68
69 button.mask = setupButtonMask( button.command, fileName ); 69 button.mask = setupButtonMask( button.command, fileName );
70 70
71 return button; 71 return button;
72} 72}
73 73
74QBitmap MediaWidget::setupButtonMask( const Command &command, const QString &fileName ) 74QBitmap MediaWidget::setupButtonMask( const Command &command, const QString &fileName )
75{ 75{
76 QImage imgMask( Resource::findPixmap( fileName ) ); 76 QImage imgMask( Resource::findPixmap( fileName ) );
77 if ( imgMask.isNull() ) 77 if ( imgMask.isNull() )
78 return QBitmap(); 78 return QBitmap();
79 79
80 uchar **dest = buttonMask.jumpTable(); 80 uchar **dest = buttonMask.jumpTable();
81 for ( int y = 0; y < buttonMask.height(); y++ ) { 81 for ( int y = 0; y < buttonMask.height(); y++ ) {
82 uchar *line = dest[y]; 82 uchar *line = dest[y];
83 for ( int x = 0; x < buttonMask.width(); x++ ) 83 for ( int x = 0; x < buttonMask.width(); x++ )
84 if ( !qRed( imgMask.pixel( x, y ) ) ) 84 if ( !qRed( imgMask.pixel( x, y ) ) )
85 line[x] = command + 1; 85 line[x] = command + 1;
86 } 86 }
87 87
88 // ### grmbl qt2. use constructor when switching to qt3. 88 // ### grmbl qt2. use constructor when switching to qt3.
89 QBitmap bm; bm = imgMask; 89 QBitmap bm; bm = imgMask;
90 return bm; 90 return bm;
91} 91}
92 92
93void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix ) 93void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix )
94{ 94{
95 Config cfg( "OpiePlayer" ); 95 Config cfg( "OpiePlayer" );
96 cfg.setGroup( "Options" ); 96 cfg.setGroup( "Options" );
97 QString skin = cfg.readEntry( "Skin","default" ); 97 QString skin = cfg.readEntry( "Skin","default" );
98 98
99 loadSkin( skinInfo, buttonCount, skin, fileNameInfix ); 99 loadSkin( skinInfo, buttonCount, skin, fileNameInfix );
100} 100}
101 101
102void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix ) 102void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix )
103{ 103{
104 Skin skin( name, fileNameInfix ); 104 Skin skin( name, fileNameInfix );
105 105
106 QString skinPath = "opieplayer2/skins/" + name; 106 QString skinPath = "opieplayer2/skins/" + name;
107 backgroundPixmap = skin.backgroundImage(); 107 backgroundPixmap = skin.backgroundImage();
108 buttonUpImage = QImage( Resource::loadImage( QString( "%1/skin%2_up" ).arg( skinPath ).arg( fileNameInfix ) ) ); 108 buttonUpImage = skin.buttonUpImage();
109 buttonDownImage = QImage( Resource::loadImage( QString( "%1/skin%2_down" ).arg( skinPath ).arg( fileNameInfix ) ) ); 109 buttonDownImage = skin.buttonDownImage();
110 110
111 setupButtons( skinInfo, buttonCount, 111 setupButtons( skinInfo, buttonCount,
112 skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( fileNameInfix ), buttonUpImage.size() ); 112 skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( fileNameInfix ), buttonUpImage.size() );
113} 113}
114 114
115void MediaWidget::closeEvent( QCloseEvent * ) 115void MediaWidget::closeEvent( QCloseEvent * )
116{ 116{
117 mediaPlayerState.setList(); 117 mediaPlayerState.setList();
118} 118}
119 119
120void MediaWidget::paintEvent( QPaintEvent *pe ) 120void MediaWidget::paintEvent( QPaintEvent *pe )
121{ 121{
122 QPainter p( this ); 122 QPainter p( this );
123 123
124 if ( mediaPlayerState.isFullscreen() ) { 124 if ( mediaPlayerState.isFullscreen() ) {
125 // Clear the background 125 // Clear the background
126 p.setBrush( QBrush( Qt::black ) ); 126 p.setBrush( QBrush( Qt::black ) );
127 return; 127 return;
128 } 128 }
129 129
130 if ( !pe->erased() ) { 130 if ( !pe->erased() ) {
131 // Combine with background and double buffer 131 // Combine with background and double buffer
132 QPixmap pix( pe->rect().size() ); 132 QPixmap pix( pe->rect().size() );
133 QPainter p( &pix ); 133 QPainter p( &pix );
134 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 134 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
135 p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); 135 p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() );
136 paintAllButtons( p ); 136 paintAllButtons( p );
137 QPainter p2( this ); 137 QPainter p2( this );
138 p2.drawPixmap( pe->rect().topLeft(), pix ); 138 p2.drawPixmap( pe->rect().topLeft(), pix );
139 } else { 139 } else {
140 QPainter p( this ); 140 QPainter p( this );
141 paintAllButtons( p ); 141 paintAllButtons( p );
142 } 142 }
143} 143}
144 144
145MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) 145MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position )
146{ 146{
147 if ( position.x() <= 0 || position.y() <= 0 || 147 if ( position.x() <= 0 || position.y() <= 0 ||
148 position.x() >= buttonMask.width() || 148 position.x() >= buttonMask.width() ||
149 position.y() >= buttonMask.height() ) 149 position.y() >= buttonMask.height() )
150 return 0; 150 return 0;
151 151
152 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); 152 int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() );
153 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) 153 for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it )
154 if ( it->command + 1 == pixelIdx ) 154 if ( it->command + 1 == pixelIdx )
155 return &( *it ); 155 return &( *it );
156 156
157 return 0; 157 return 0;
158} 158}
159 159
160void MediaWidget::mousePressEvent( QMouseEvent *event ) 160void MediaWidget::mousePressEvent( QMouseEvent *event )
161{ 161{
162 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); 162 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
163 163
164 if ( !button ) { 164 if ( !button ) {
165 QWidget::mousePressEvent( event ); 165 QWidget::mousePressEvent( event );
166 return; 166 return;
167 } 167 }
168 168
169 switch ( button->command ) { 169 switch ( button->command ) {
170 case VolumeUp: emit moreClicked(); return; 170 case VolumeUp: emit moreClicked(); return;
171 case VolumeDown: emit lessClicked(); return; 171 case VolumeDown: emit lessClicked(); return;
172 case Back: emit backClicked(); return; 172 case Back: emit backClicked(); return;
173 case Forward: emit forwardClicked(); return; 173 case Forward: emit forwardClicked(); return;
174 default: break; 174 default: break;
175 } 175 }
176} 176}
177 177
178void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) 178void MediaWidget::mouseReleaseEvent( QMouseEvent *event )
179{ 179{
180 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); 180 Button *button = buttonAt( event->pos() - upperLeftOfButtonMask );
181 181
182 if ( !button ) { 182 if ( !button ) {
183 QWidget::mouseReleaseEvent( event ); 183 QWidget::mouseReleaseEvent( event );
184 return; 184 return;
185 } 185 }
186 186
187 if ( button->type == ToggleButton ) 187 if ( button->type == ToggleButton )
188 toggleButton( *button ); 188 toggleButton( *button );
189 189
190 handleCommand( button->command, button->isDown ); 190 handleCommand( button->command, button->isDown );
191} 191}
192 192
193void MediaWidget::makeVisible() 193void MediaWidget::makeVisible()
194{ 194{
195} 195}
196 196
197void MediaWidget::handleCommand( Command command, bool buttonDown ) 197void MediaWidget::handleCommand( Command command, bool buttonDown )
198{ 198{
199 switch ( command ) { 199 switch ( command ) {
200 case Play: mediaPlayerState.togglePaused(); return; 200 case Play: mediaPlayerState.togglePaused(); return;
201 case Stop: mediaPlayerState.setPlaying(FALSE); return; 201 case Stop: mediaPlayerState.setPlaying(FALSE); return;
202 case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; 202 case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return;
203 case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; 203 case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return;
204 case Loop: mediaPlayerState.setLooping( buttonDown ); return; 204 case Loop: mediaPlayerState.setLooping( buttonDown ); return;
205 case VolumeUp: emit moreReleased(); return; 205 case VolumeUp: emit moreReleased(); return;
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp
index 097b29a..352368f 100644
--- a/noncore/multimedia/opieplayer2/skin.cpp
+++ b/noncore/multimedia/opieplayer2/skin.cpp
@@ -1,18 +1,28 @@
1 1
2#include "skin.h" 2#include "skin.h"
3 3
4#include <qpe/resource.h> 4#include <qpe/resource.h>
5 5
6Skin::Skin( const QString &name, const QString &fileNameInfix ) 6Skin::Skin( const QString &name, const QString &fileNameInfix )
7 : m_name( name ), m_fileNameInfix( fileNameInfix ) 7 : m_name( name ), m_fileNameInfix( fileNameInfix )
8{ 8{
9 m_skinPath = "opieplayer2/skins/" + name; 9 m_skinPath = "opieplayer2/skins/" + name;
10} 10}
11 11
12QImage Skin::backgroundImage() const 12QImage Skin::backgroundImage() const
13{ 13{
14 return QImage( Resource::findPixmap( QString( "%1/background" ).arg( m_skinPath ) ) ); 14 return QImage( Resource::findPixmap( QString( "%1/background" ).arg( m_skinPath ) ) );
15} 15}
16 16
17QImage Skin::buttonUpImage() const
18{
19 return QImage( Resource::findPixmap( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) );
20}
21
22QImage Skin::buttonDownImage() const
23{
24 return QImage( Resource::findPixmap( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) );
25}
26
17/* vim: et sw=4 ts=4 27/* vim: et sw=4 ts=4
18 */ 28 */
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h
index 3c09e43..85f9e57 100644
--- a/noncore/multimedia/opieplayer2/skin.h
+++ b/noncore/multimedia/opieplayer2/skin.h
@@ -1,22 +1,27 @@
1#ifndef SKIN_H 1#ifndef SKIN_H
2#define SKIN_H 2#define SKIN_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qimage.h> 5#include <qimage.h>
6 6
7class Skin 7class Skin
8{ 8{
9public: 9public:
10 Skin( const QString &name, const QString &fileNameInfix ); 10 Skin( const QString &name, const QString &fileNameInfix );
11 11
12 QImage backgroundImage() const; 12 QImage backgroundImage() const;
13 QImage buttonUpImage() const;
14 QImage buttonDownImage() const;
13 15
14private: 16private:
15 QString m_name; 17 QString m_name;
16 QString m_fileNameInfix; 18 QString m_fileNameInfix;
17 QString m_skinPath; 19 QString m_skinPath;
20
21 Skin( const Skin & );
22 Skin &operator=( const Skin & );
18}; 23};
19 24
20#endif // SKIN_H 25#endif // SKIN_H
21/* vim: et sw=4 ts=4 26/* vim: et sw=4 ts=4
22 */ 27 */