-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 4 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 10 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.h | 5 |
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 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "mediawidget.h" #include "playlistwidget.h" #include "skin.h" #include <qpe/config.h> #include <qpe/qpeapplication.h> MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) { connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), this, SLOT( setLength( long ) ) ); connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); } MediaWidget::~MediaWidget() { } void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &imagePrefix, const QSize &buttonAreaSize ) { buttonMask = QImage( buttonAreaSize, 8, 255 ); buttonMask.fill( 0 ); buttons.clear(); buttons.reserve( buttonCount ); for ( uint i = 0; i < buttonCount; ++i ) { Button button = setupButton( skinInfo[ i ], imagePrefix ); buttons.push_back( button ); } } MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix ) { Button button; button.command = buttonInfo.command; button.type = buttonInfo.type; QString fileName = imagePrefix + buttonInfo.fileName + ".png"; button.mask = setupButtonMask( button.command, fileName ); return button; } QBitmap MediaWidget::setupButtonMask( const Command &command, const QString &fileName ) { QImage imgMask( Resource::findPixmap( fileName ) ); if ( imgMask.isNull() ) return QBitmap(); uchar **dest = buttonMask.jumpTable(); for ( int y = 0; y < buttonMask.height(); y++ ) { uchar *line = dest[y]; for ( int x = 0; x < buttonMask.width(); x++ ) if ( !qRed( imgMask.pixel( x, y ) ) ) line[x] = command + 1; } // ### grmbl qt2. use constructor when switching to qt3. QBitmap bm; bm = imgMask; return bm; } void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix ) { Config cfg( "OpiePlayer" ); cfg.setGroup( "Options" ); QString skin = cfg.readEntry( "Skin","default" ); loadSkin( skinInfo, buttonCount, skin, fileNameInfix ); } void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix ) { Skin skin( name, fileNameInfix ); QString skinPath = "opieplayer2/skins/" + name; backgroundPixmap = skin.backgroundImage(); - buttonUpImage = QImage( Resource::loadImage( QString( "%1/skin%2_up" ).arg( skinPath ).arg( fileNameInfix ) ) ); - buttonDownImage = QImage( Resource::loadImage( QString( "%1/skin%2_down" ).arg( skinPath ).arg( fileNameInfix ) ) ); + buttonUpImage = skin.buttonUpImage(); + buttonDownImage = skin.buttonDownImage(); setupButtons( skinInfo, buttonCount, skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( fileNameInfix ), buttonUpImage.size() ); } void MediaWidget::closeEvent( QCloseEvent * ) { mediaPlayerState.setList(); } void MediaWidget::paintEvent( QPaintEvent *pe ) { QPainter p( this ); if ( mediaPlayerState.isFullscreen() ) { // Clear the background p.setBrush( QBrush( Qt::black ) ); return; } if ( !pe->erased() ) { // Combine with background and double buffer QPixmap pix( pe->rect().size() ); QPainter p( &pix ); p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); paintAllButtons( p ); QPainter p2( this ); p2.drawPixmap( pe->rect().topLeft(), pix ); } else { QPainter p( this ); paintAllButtons( p ); } } MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) { if ( position.x() <= 0 || position.y() <= 0 || position.x() >= buttonMask.width() || position.y() >= buttonMask.height() ) return 0; int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) if ( it->command + 1 == pixelIdx ) return &( *it ); return 0; } void MediaWidget::mousePressEvent( QMouseEvent *event ) { Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); if ( !button ) { QWidget::mousePressEvent( event ); return; } switch ( button->command ) { case VolumeUp: emit moreClicked(); return; case VolumeDown: emit lessClicked(); return; case Back: emit backClicked(); return; case Forward: emit forwardClicked(); return; default: break; } } void MediaWidget::mouseReleaseEvent( QMouseEvent *event ) { Button *button = buttonAt( event->pos() - upperLeftOfButtonMask ); if ( !button ) { QWidget::mouseReleaseEvent( event ); return; } if ( button->type == ToggleButton ) toggleButton( *button ); handleCommand( button->command, button->isDown ); } void MediaWidget::makeVisible() { } void MediaWidget::handleCommand( Command command, bool buttonDown ) { switch ( command ) { case Play: mediaPlayerState.togglePaused(); return; case Stop: mediaPlayerState.setPlaying(FALSE); return; case Next: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setNext(); return; case Previous: if( playList.currentTab() == PlayListWidget::CurrentPlayList ) mediaPlayerState.setPrev(); return; case Loop: mediaPlayerState.setLooping( buttonDown ); return; 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 @@ #include "skin.h" #include <qpe/resource.h> Skin::Skin( const QString &name, const QString &fileNameInfix ) : m_name( name ), m_fileNameInfix( fileNameInfix ) { m_skinPath = "opieplayer2/skins/" + name; } QImage Skin::backgroundImage() const { return QImage( Resource::findPixmap( QString( "%1/background" ).arg( m_skinPath ) ) ); } +QImage Skin::buttonUpImage() const +{ + return QImage( Resource::findPixmap( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); +} + +QImage Skin::buttonDownImage() const +{ + return QImage( Resource::findPixmap( QString( "%1/skin%2_down" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); +} + /* vim: et sw=4 ts=4 */ 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 @@ #ifndef SKIN_H #define SKIN_H #include <qstring.h> #include <qimage.h> class Skin { public: Skin( const QString &name, const QString &fileNameInfix ); QImage backgroundImage() const; + QImage buttonUpImage() const; + QImage buttonDownImage() const; private: QString m_name; QString m_fileNameInfix; QString m_skinPath; + + Skin( const Skin & ); + Skin &operator=( const Skin & ); }; #endif // SKIN_H /* vim: et sw=4 ts=4 */ |