author | simon <simon> | 2002-12-11 13:12:29 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 13:12:29 (UTC) |
commit | cd5e96b40ceae9158e5cb01e71769e895ea7a3c1 (patch) (side-by-side diff) | |
tree | 0a5e1961a31096f995e00215d851c3af8e8ae877 | |
parent | 57a776c8345422a0fc32b3fb9d604be1c050d201 (diff) | |
download | opie-cd5e96b40ceae9158e5cb01e71769e895ea7a3c1.zip opie-cd5e96b40ceae9158e5cb01e71769e895ea7a3c1.tar.gz opie-cd5e96b40ceae9158e5cb01e71769e895ea7a3c1.tar.bz2 |
- moved default skin name reading over to skin class
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 9 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 21 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.h | 6 |
3 files changed, 26 insertions, 10 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index 0d1c8b6..ab23aa8 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp @@ -4,97 +4,90 @@ (C) 2002 L. Potter <ljp@llornkcor.com> (C) 2002 Holger Freyther <zecke@handhelds.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 Skin &skin ) { buttonMask = skin.buttonMask( skinInfo, buttonCount ); buttons.clear(); buttons.reserve( buttonCount ); for ( uint i = 0; i < buttonCount; ++i ) { Button button = setupButton( skinInfo[ i ], skin ); buttons.push_back( button ); } } MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const Skin &skin ) { Button button; button.command = buttonInfo.command; button.type = buttonInfo.type; button.mask = skin.buttonMaskImage( buttonInfo.fileName ); return button; } void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix ) { - Config cfg( "OpiePlayer" ); - cfg.setGroup( "Options" ); - QString name = cfg.readEntry( "Skin","default" ); - - Skin skin( name, fileNameInfix ); + Skin skin( fileNameInfix ); loadSkin( skinInfo, buttonCount, skin ); } void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const Skin &skin ) { backgroundPixmap = skin.backgroundImage(); buttonUpImage = skin.buttonUpImage(); buttonDownImage = skin.buttonDownImage(); setupButtons( skinInfo, buttonCount, skin ); } 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 ) ); diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp index d3918d1..8281b20 100644 --- a/noncore/multimedia/opieplayer2/skin.cpp +++ b/noncore/multimedia/opieplayer2/skin.cpp @@ -1,31 +1,43 @@ #include "skin.h" #include <qpe/resource.h> +#include <qpe/config.h> Skin::Skin( const QString &name, const QString &fileNameInfix ) - : m_name( name ), m_fileNameInfix( fileNameInfix ) + : m_fileNameInfix( fileNameInfix ) +{ + init( name ); +} + +Skin::Skin( const QString &fileNameInfix ) + : m_fileNameInfix( fileNameInfix ) +{ + init( defaultSkinName() ); +} + +void Skin::init( const QString &name ) { m_skinPath = "opieplayer2/skins/" + name; } void Skin::preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) { backgroundImage(); buttonUpImage(); buttonDownImage(); ( void )buttonMask( skinButtonInfo, buttonCount ); } QImage Skin::backgroundImage() const { if ( m_backgroundImage.isNull() ) m_backgroundImage = QImage( Resource::findPixmap( QString( "%1/background" ).arg( m_skinPath ) ) ); return m_backgroundImage; } QImage Skin::buttonUpImage() const { if ( m_buttonUpImage.isNull() ) m_buttonUpImage = QImage( Resource::findPixmap( QString( "%1/skin%2_up" ).arg( m_skinPath ).arg( m_fileNameInfix ) ) ); return m_buttonUpImage; @@ -58,26 +70,33 @@ void Skin::addButtonToMask( int tag, const QImage &maskImage ) const { if ( maskImage.isNull() ) return; uchar **dest = m_buttonMask.jumpTable(); for ( int y = 0; y < m_buttonMask.height(); y++ ) { uchar *line = dest[y]; for ( int x = 0; x < m_buttonMask.width(); x++ ) if ( !qRed( maskImage.pixel( x, y ) ) ) line[x] = tag; } } QImage Skin::buttonMaskImage( const QString &fileName ) const { ButtonMaskImageMap::Iterator it = m_buttonMasks.find( fileName ); if ( it == m_buttonMasks.end() ) { QString prefix = m_skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( m_fileNameInfix ); QString path = prefix + fileName + ".png"; it = m_buttonMasks.insert( fileName, QImage( Resource::findPixmap( path ) ) ); } return *it; } +QString Skin::defaultSkinName() +{ + Config cfg( "OpiePlayer" ); + cfg.setGroup( "Options" ); + return cfg.readEntry( "Skin", "default" ); +} + /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h index ee19f4b..58f1849 100644 --- a/noncore/multimedia/opieplayer2/skin.h +++ b/noncore/multimedia/opieplayer2/skin.h @@ -1,46 +1,50 @@ #ifndef SKIN_H #define SKIN_H #include <qstring.h> #include <qimage.h> #include <qmap.h> #include "mediawidget.h" class Skin { public: Skin( const QString &name, const QString &fileNameInfix ); + Skin( const QString &fileNameInfix ); void preload( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ); QImage backgroundImage() const; QImage buttonUpImage() const; QImage buttonDownImage() const; QImage buttonMask( const MediaWidget::SkinButtonInfo *skinButtonInfo, uint buttonCount ) const; QImage buttonMaskImage( const QString &fileName ) const; + static QString defaultSkinName(); + private: + void init( const QString &name ); + void addButtonToMask( int tag, const QImage &maskImage ) const; - QString m_name; QString m_fileNameInfix; QString m_skinPath; typedef QMap<QString, QImage> ButtonMaskImageMap; mutable QImage m_backgroundImage; mutable QImage m_buttonUpImage; mutable QImage m_buttonDownImage; mutable QImage m_buttonMask; mutable ButtonMaskImageMap m_buttonMasks; Skin( const Skin & ); Skin &operator=( const Skin & ); }; #endif // SKIN_H /* vim: et sw=4 ts=4 */ |