author | simon <simon> | 2002-12-11 12:04:54 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-11 12:04:54 (UTC) |
commit | 882ddb046c81bdee5eeca59fde7ec458ae522dc7 (patch) (unidiff) | |
tree | b51292ac603f7ec41501c707a868dd462937224f | |
parent | d7b877a5532e6377f034514c89c0b45b96265471 (diff) | |
download | opie-882ddb046c81bdee5eeca59fde7ec458ae522dc7.zip opie-882ddb046c81bdee5eeca59fde7ec458ae522dc7.tar.gz opie-882ddb046c81bdee5eeca59fde7ec458ae522dc7.tar.bz2 |
- starting to factor out the actual skin image loading into a separate
class
-rw-r--r-- | noncore/multimedia/opieplayer2/mediawidget.cpp | 5 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/opieplayer2.pro | 6 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.cpp | 18 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/skin.h | 22 |
4 files changed, 48 insertions, 3 deletions
diff --git a/noncore/multimedia/opieplayer2/mediawidget.cpp b/noncore/multimedia/opieplayer2/mediawidget.cpp index 70ef8d9..617e0fe 100644 --- a/noncore/multimedia/opieplayer2/mediawidget.cpp +++ b/noncore/multimedia/opieplayer2/mediawidget.cpp | |||
@@ -1,152 +1,155 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> | 2 | Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> |
3 | (C) 2002 Max Reiss <harlekin@handhelds.org> | 3 | (C) 2002 Max Reiss <harlekin@handhelds.org> |
4 | (C) 2002 L. Potter <ljp@llornkcor.com> | 4 | (C) 2002 L. Potter <ljp@llornkcor.com> |
5 | (C) 2002 Holger Freyther <zecke@handhelds.org> | 5 | (C) 2002 Holger Freyther <zecke@handhelds.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
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 | 27 | ||
27 | #include <qpe/config.h> | 28 | #include <qpe/config.h> |
28 | #include <qpe/qpeapplication.h> | 29 | #include <qpe/qpeapplication.h> |
29 | 30 | ||
30 | MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) | 31 | MediaWidget::MediaWidget( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QWidget *parent, const char *name ) |
31 | : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) | 32 | : QWidget( parent, name ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) |
32 | { | 33 | { |
33 | connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), | 34 | connect( &mediaPlayerState, SIGNAL( displayTypeChanged( MediaPlayerState::DisplayType ) ), |
34 | this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); | 35 | this, SLOT( setDisplayType( MediaPlayerState::DisplayType ) ) ); |
35 | connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), | 36 | connect( &mediaPlayerState, SIGNAL( lengthChanged( long ) ), |
36 | this, SLOT( setLength( long ) ) ); | 37 | this, SLOT( setLength( long ) ) ); |
37 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), | 38 | connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), |
38 | this, SLOT( setPlaying( bool ) ) ); | 39 | this, SLOT( setPlaying( bool ) ) ); |
39 | } | 40 | } |
40 | 41 | ||
41 | MediaWidget::~MediaWidget() | 42 | MediaWidget::~MediaWidget() |
42 | { | 43 | { |
43 | } | 44 | } |
44 | 45 | ||
45 | void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, | 46 | void MediaWidget::setupButtons( const SkinButtonInfo *skinInfo, uint buttonCount, |
46 | const QString &imagePrefix, const QSize &buttonAreaSize ) | 47 | const QString &imagePrefix, const QSize &buttonAreaSize ) |
47 | { | 48 | { |
48 | buttonMask = QImage( buttonAreaSize, 8, 255 ); | 49 | buttonMask = QImage( buttonAreaSize, 8, 255 ); |
49 | buttonMask.fill( 0 ); | 50 | buttonMask.fill( 0 ); |
50 | 51 | ||
51 | buttons.clear(); | 52 | buttons.clear(); |
52 | buttons.reserve( buttonCount ); | 53 | buttons.reserve( buttonCount ); |
53 | 54 | ||
54 | for ( uint i = 0; i < buttonCount; ++i ) { | 55 | for ( uint i = 0; i < buttonCount; ++i ) { |
55 | Button button = setupButton( skinInfo[ i ], imagePrefix ); | 56 | Button button = setupButton( skinInfo[ i ], imagePrefix ); |
56 | buttons.push_back( button ); | 57 | buttons.push_back( button ); |
57 | } | 58 | } |
58 | } | 59 | } |
59 | 60 | ||
60 | MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix ) | 61 | MediaWidget::Button MediaWidget::setupButton( const SkinButtonInfo &buttonInfo, const QString &imagePrefix ) |
61 | { | 62 | { |
62 | Button button; | 63 | Button button; |
63 | button.command = buttonInfo.command; | 64 | button.command = buttonInfo.command; |
64 | button.type = buttonInfo.type; | 65 | button.type = buttonInfo.type; |
65 | 66 | ||
66 | QString fileName = imagePrefix + buttonInfo.fileName + ".png"; | 67 | QString fileName = imagePrefix + buttonInfo.fileName + ".png"; |
67 | 68 | ||
68 | button.mask = setupButtonMask( button.command, fileName ); | 69 | button.mask = setupButtonMask( button.command, fileName ); |
69 | 70 | ||
70 | return button; | 71 | return button; |
71 | } | 72 | } |
72 | 73 | ||
73 | QBitmap MediaWidget::setupButtonMask( const Command &command, const QString &fileName ) | 74 | QBitmap MediaWidget::setupButtonMask( const Command &command, const QString &fileName ) |
74 | { | 75 | { |
75 | QImage imgMask( Resource::findPixmap( fileName ) ); | 76 | QImage imgMask( Resource::findPixmap( fileName ) ); |
76 | if ( imgMask.isNull() ) | 77 | if ( imgMask.isNull() ) |
77 | return QBitmap(); | 78 | return QBitmap(); |
78 | 79 | ||
79 | uchar **dest = buttonMask.jumpTable(); | 80 | uchar **dest = buttonMask.jumpTable(); |
80 | for ( int y = 0; y < buttonMask.height(); y++ ) { | 81 | for ( int y = 0; y < buttonMask.height(); y++ ) { |
81 | uchar *line = dest[y]; | 82 | uchar *line = dest[y]; |
82 | for ( int x = 0; x < buttonMask.width(); x++ ) | 83 | for ( int x = 0; x < buttonMask.width(); x++ ) |
83 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 84 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
84 | line[x] = command + 1; | 85 | line[x] = command + 1; |
85 | } | 86 | } |
86 | 87 | ||
87 | // ### grmbl qt2. use constructor when switching to qt3. | 88 | // ### grmbl qt2. use constructor when switching to qt3. |
88 | QBitmap bm; bm = imgMask; | 89 | QBitmap bm; bm = imgMask; |
89 | return bm; | 90 | return bm; |
90 | } | 91 | } |
91 | 92 | ||
92 | void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix ) | 93 | void MediaWidget::loadDefaultSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &fileNameInfix ) |
93 | { | 94 | { |
94 | Config cfg( "OpiePlayer" ); | 95 | Config cfg( "OpiePlayer" ); |
95 | cfg.setGroup( "Options" ); | 96 | cfg.setGroup( "Options" ); |
96 | QString skin = cfg.readEntry( "Skin","default" ); | 97 | QString skin = cfg.readEntry( "Skin","default" ); |
97 | 98 | ||
98 | loadSkin( skinInfo, buttonCount, skin, fileNameInfix ); | 99 | loadSkin( skinInfo, buttonCount, skin, fileNameInfix ); |
99 | } | 100 | } |
100 | 101 | ||
101 | void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix ) | 102 | void MediaWidget::loadSkin( const SkinButtonInfo *skinInfo, uint buttonCount, const QString &name, const QString &fileNameInfix ) |
102 | { | 103 | { |
104 | Skin skin( name, fileNameInfix ); | ||
105 | |||
103 | QString skinPath = "opieplayer2/skins/" + name; | 106 | QString skinPath = "opieplayer2/skins/" + name; |
104 | backgroundPixmap = QPixmap( Resource::loadPixmap( QString( "%1/background" ).arg( skinPath ) ) ); | 107 | backgroundPixmap = skin.backgroundImage(); |
105 | buttonUpImage = QImage( Resource::loadImage( QString( "%1/skin%2_up" ).arg( skinPath ).arg( fileNameInfix ) ) ); | 108 | buttonUpImage = QImage( Resource::loadImage( QString( "%1/skin%2_up" ).arg( skinPath ).arg( fileNameInfix ) ) ); |
106 | buttonDownImage = QImage( Resource::loadImage( QString( "%1/skin%2_down" ).arg( skinPath ).arg( fileNameInfix ) ) ); | 109 | buttonDownImage = QImage( Resource::loadImage( QString( "%1/skin%2_down" ).arg( skinPath ).arg( fileNameInfix ) ) ); |
107 | 110 | ||
108 | setupButtons( skinInfo, buttonCount, | 111 | setupButtons( skinInfo, buttonCount, |
109 | skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( fileNameInfix ), buttonUpImage.size() ); | 112 | skinPath + QString::fromLatin1( "/skin%1_mask_" ).arg( fileNameInfix ), buttonUpImage.size() ); |
110 | } | 113 | } |
111 | 114 | ||
112 | void MediaWidget::closeEvent( QCloseEvent * ) | 115 | void MediaWidget::closeEvent( QCloseEvent * ) |
113 | { | 116 | { |
114 | mediaPlayerState.setList(); | 117 | mediaPlayerState.setList(); |
115 | } | 118 | } |
116 | 119 | ||
117 | void MediaWidget::paintEvent( QPaintEvent *pe ) | 120 | void MediaWidget::paintEvent( QPaintEvent *pe ) |
118 | { | 121 | { |
119 | QPainter p( this ); | 122 | QPainter p( this ); |
120 | 123 | ||
121 | if ( mediaPlayerState.isFullscreen() ) { | 124 | if ( mediaPlayerState.isFullscreen() ) { |
122 | // Clear the background | 125 | // Clear the background |
123 | p.setBrush( QBrush( Qt::black ) ); | 126 | p.setBrush( QBrush( Qt::black ) ); |
124 | return; | 127 | return; |
125 | } | 128 | } |
126 | 129 | ||
127 | if ( !pe->erased() ) { | 130 | if ( !pe->erased() ) { |
128 | // Combine with background and double buffer | 131 | // Combine with background and double buffer |
129 | QPixmap pix( pe->rect().size() ); | 132 | QPixmap pix( pe->rect().size() ); |
130 | QPainter p( &pix ); | 133 | QPainter p( &pix ); |
131 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 134 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
132 | p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); | 135 | p.drawTiledPixmap( pe->rect(), backgroundPixmap, pe->rect().topLeft() ); |
133 | paintAllButtons( p ); | 136 | paintAllButtons( p ); |
134 | QPainter p2( this ); | 137 | QPainter p2( this ); |
135 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 138 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
136 | } else { | 139 | } else { |
137 | QPainter p( this ); | 140 | QPainter p( this ); |
138 | paintAllButtons( p ); | 141 | paintAllButtons( p ); |
139 | } | 142 | } |
140 | } | 143 | } |
141 | 144 | ||
142 | MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) | 145 | MediaWidget::Button *MediaWidget::buttonAt( const QPoint &position ) |
143 | { | 146 | { |
144 | if ( position.x() <= 0 || position.y() <= 0 || | 147 | if ( position.x() <= 0 || position.y() <= 0 || |
145 | position.x() >= buttonMask.width() || | 148 | position.x() >= buttonMask.width() || |
146 | position.y() >= buttonMask.height() ) | 149 | position.y() >= buttonMask.height() ) |
147 | return 0; | 150 | return 0; |
148 | 151 | ||
149 | int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); | 152 | int pixelIdx = buttonMask.pixelIndex( position.x(), position.y() ); |
150 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) | 153 | for ( ButtonVector::iterator it = buttons.begin(); it != buttons.end(); ++it ) |
151 | if ( it->command + 1 == pixelIdx ) | 154 | if ( it->command + 1 == pixelIdx ) |
152 | return &( *it ); | 155 | return &( *it ); |
diff --git a/noncore/multimedia/opieplayer2/opieplayer2.pro b/noncore/multimedia/opieplayer2/opieplayer2.pro index 8d549b6..e1bb879 100644 --- a/noncore/multimedia/opieplayer2/opieplayer2.pro +++ b/noncore/multimedia/opieplayer2/opieplayer2.pro | |||
@@ -1,25 +1,27 @@ | |||
1 | TEMPLATE = app | 1 | TEMPLATE = app |
2 | #CONFIG = qt warn_on release | 2 | #CONFIG = qt warn_on release |
3 | CONFIG = qt warn_on debug | 3 | CONFIG = qt warn_on debug |
4 | DESTDIR = $(OPIEDIR)/bin | 4 | DESTDIR = $(OPIEDIR)/bin |
5 | HEADERS = playlistselection.h mediaplayerstate.h xinecontrol.h \ | 5 | HEADERS = playlistselection.h mediaplayerstate.h xinecontrol.h \ |
6 | videowidget.h audiowidget.h playlistwidget.h om3u.h mediaplayer.h inputDialog.h \ | 6 | videowidget.h audiowidget.h playlistwidget.h om3u.h mediaplayer.h inputDialog.h \ |
7 | frame.h lib.h xinevideowidget.h volumecontrol.h playlistwidgetgui.h\ | 7 | frame.h lib.h xinevideowidget.h volumecontrol.h playlistwidgetgui.h\ |
8 | alphablend.h yuv2rgb.h threadutil.h mediawidget.h playlistview.h playlistfileview.h | 8 | alphablend.h yuv2rgb.h threadutil.h mediawidget.h playlistview.h playlistfileview.h \ |
9 | skin.h | ||
9 | SOURCES = main.cpp \ | 10 | SOURCES = main.cpp \ |
10 | playlistselection.cpp mediaplayerstate.cpp xinecontrol.cpp \ | 11 | playlistselection.cpp mediaplayerstate.cpp xinecontrol.cpp \ |
11 | videowidget.cpp audiowidget.cpp playlistwidget.cpp om3u.cpp mediaplayer.cpp inputDialog.cpp \ | 12 | videowidget.cpp audiowidget.cpp playlistwidget.cpp om3u.cpp mediaplayer.cpp inputDialog.cpp \ |
12 | frame.cpp lib.cpp nullvideo.c xinevideowidget.cpp volumecontrol.cpp \ | 13 | frame.cpp lib.cpp nullvideo.c xinevideowidget.cpp volumecontrol.cpp \ |
13 | playlistwidgetgui.cpp\ | 14 | playlistwidgetgui.cpp\ |
14 | alphablend.c yuv2rgb.c yuv2rgb_arm.c yuv2rgb_arm4l.S \ | 15 | alphablend.c yuv2rgb.c yuv2rgb_arm.c yuv2rgb_arm4l.S \ |
15 | threadutil.cpp mediawidget.cpp playlistview.cpp playlistfileview.cpp | 16 | threadutil.cpp mediawidget.cpp playlistview.cpp playlistfileview.cpp \ |
17 | skin.cpp | ||
16 | TARGET = opieplayer2 | 18 | TARGET = opieplayer2 |
17 | INCLUDEPATH += $(OPIEDIR)/include | 19 | INCLUDEPATH += $(OPIEDIR)/include |
18 | DEPENDPATH += $(OPIEDIR)/include | 20 | DEPENDPATH += $(OPIEDIR)/include |
19 | LIBS += -lqpe -lpthread -lopie -lxine | 21 | LIBS += -lqpe -lpthread -lopie -lxine |
20 | MOC_DIR = qpeobj | 22 | MOC_DIR = qpeobj |
21 | OBJECTS_DIR = qpeobj | 23 | OBJECTS_DIR = qpeobj |
22 | 24 | ||
23 | #INCLUDEPATH += $(OPIEDIR)/include | 25 | #INCLUDEPATH += $(OPIEDIR)/include |
24 | #DEPENDPATH += $(OPIEDIR)/include | 26 | #DEPENDPATH += $(OPIEDIR)/include |
25 | 27 | ||
diff --git a/noncore/multimedia/opieplayer2/skin.cpp b/noncore/multimedia/opieplayer2/skin.cpp new file mode 100644 index 0000000..097b29a --- a/dev/null +++ b/noncore/multimedia/opieplayer2/skin.cpp | |||
@@ -0,0 +1,18 @@ | |||
1 | |||
2 | #include "skin.h" | ||
3 | |||
4 | #include <qpe/resource.h> | ||
5 | |||
6 | Skin::Skin( const QString &name, const QString &fileNameInfix ) | ||
7 | : m_name( name ), m_fileNameInfix( fileNameInfix ) | ||
8 | { | ||
9 | m_skinPath = "opieplayer2/skins/" + name; | ||
10 | } | ||
11 | |||
12 | QImage Skin::backgroundImage() const | ||
13 | { | ||
14 | return QImage( Resource::findPixmap( QString( "%1/background" ).arg( m_skinPath ) ) ); | ||
15 | } | ||
16 | |||
17 | /* vim: et sw=4 ts=4 | ||
18 | */ | ||
diff --git a/noncore/multimedia/opieplayer2/skin.h b/noncore/multimedia/opieplayer2/skin.h new file mode 100644 index 0000000..3c09e43 --- a/dev/null +++ b/noncore/multimedia/opieplayer2/skin.h | |||
@@ -0,0 +1,22 @@ | |||
1 | #ifndef SKIN_H | ||
2 | #define SKIN_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qimage.h> | ||
6 | |||
7 | class Skin | ||
8 | { | ||
9 | public: | ||
10 | Skin( const QString &name, const QString &fileNameInfix ); | ||
11 | |||
12 | QImage backgroundImage() const; | ||
13 | |||
14 | private: | ||
15 | QString m_name; | ||
16 | QString m_fileNameInfix; | ||
17 | QString m_skinPath; | ||
18 | }; | ||
19 | |||
20 | #endif // SKIN_H | ||
21 | /* vim: et sw=4 ts=4 | ||
22 | */ | ||