-rw-r--r-- | noncore/applets/volumeapplet2/volumeapplet.cpp | 52 | ||||
-rw-r--r-- | noncore/applets/volumeapplet2/volumeapplet.h | 15 |
2 files changed, 57 insertions, 10 deletions
diff --git a/noncore/applets/volumeapplet2/volumeapplet.cpp b/noncore/applets/volumeapplet2/volumeapplet.cpp index 2f61f48..2122007 100644 --- a/noncore/applets/volumeapplet2/volumeapplet.cpp +++ b/noncore/applets/volumeapplet2/volumeapplet.cpp | |||
@@ -29,24 +29,25 @@ _;:, .> :=|. This program is free software; you can | |||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "volumeapplet.h" | 31 | #include "volumeapplet.h" |
32 | 32 | ||
33 | /* OPIE */ | 33 | /* OPIE */ |
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | #include <opie2/otaskbarapplet.h> | 35 | #include <opie2/otaskbarapplet.h> |
36 | #include <opie2/osoundsystem.h> | 36 | #include <opie2/osoundsystem.h> |
37 | #include <opie2/oledbox.h> | 37 | #include <opie2/oledbox.h> |
38 | #include <opie2/oresource.h> | 38 | #include <opie2/oresource.h> |
39 | 39 | ||
40 | #include <qpe/applnk.h> | 40 | #include <qpe/applnk.h> |
41 | #include <qpe/qpeapplication.h> | ||
41 | 42 | ||
42 | using namespace Opie::Core; | 43 | using namespace Opie::Core; |
43 | using namespace Opie::MM; | 44 | using namespace Opie::MM; |
44 | using namespace Opie::Ui; | 45 | using namespace Opie::Ui; |
45 | 46 | ||
46 | /* QT */ | 47 | /* QT */ |
47 | #include <qpainter.h> | 48 | #include <qpainter.h> |
48 | #include <qlabel.h> | 49 | #include <qlabel.h> |
49 | #include <qlayout.h> | 50 | #include <qlayout.h> |
50 | #include <qslider.h> | 51 | #include <qslider.h> |
51 | 52 | ||
52 | /* STD */ | 53 | /* STD */ |
@@ -79,93 +80,130 @@ VolumeAppletControl::VolumeAppletControl( OTaskbarApplet* parent, const char* na | |||
79 | { | 80 | { |
80 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 81 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
81 | l = new QGridLayout( this ); | 82 | l = new QGridLayout( this ); |
82 | build(); | 83 | build(); |
83 | } | 84 | } |
84 | 85 | ||
85 | 86 | ||
86 | void VolumeAppletControl::build() | 87 | void VolumeAppletControl::build() |
87 | { | 88 | { |
88 | OSoundSystem* sound = OSoundSystem::instance(); | 89 | OSoundSystem* sound = OSoundSystem::instance(); |
89 | OSoundSystem::CardIterator it = sound->iterator(); | 90 | OSoundSystem::CardIterator it = sound->iterator(); |
90 | 91 | ||
91 | OMixerInterface* mixer = new OMixerInterface( this, "/dev/mixer" ); | 92 | // OMixerInterface* |
93 | mixer = new OMixerInterface( this, "/dev/mixer" ); | ||
92 | 94 | ||
93 | QStringList channels = mixer->allChannels(); | 95 | QStringList channels = mixer->allChannels(); |
94 | 96 | ||
95 | int x = 0; | 97 | int x = 0; |
96 | // int y = 0; | 98 | // int y = 0; |
97 | 99 | ||
98 | for ( QStringList::Iterator it = channels.begin(); it != channels.end(); ++it ) | 100 | for ( QStringList::Iterator it = channels.begin(); it != channels.end(); ++it ) |
99 | { | 101 | { |
100 | odebug << "OSSDEMO: Mixer has channel " << *it << "" << oendl; | 102 | if((*it) == mixer->volume( "Vol")) { |
101 | odebug << "OSSDEMO: +--- volume " << ( mixer->volume( *it ) & 0xff ) | 103 | m_vol_percent=mixer->volume( *it ) >> 8; |
104 | } | ||
105 | owarn << "OSSDEMO: Mixer has channel " << *it << "" << oendl; | ||
106 | owarn << "OSSDEMO: +--- volume " << ( mixer->volume( *it ) & 0xff ) | ||
102 | << " (left) | " << ( mixer->volume( *it ) >> 8 ) << " (right)" << oendl; | 107 | << " (left) | " << ( mixer->volume( *it ) >> 8 ) << " (right)" << oendl; |
103 | 108 | ||
104 | l->addWidget( new Channel( mixer, this, *it ), 0, x++, AlignCenter ); | 109 | l->addWidget( new Channel( mixer, this, *it ), 0, x++, AlignCenter ); |
105 | } | 110 | } |
106 | 111 | ||
107 | } | 112 | } |
108 | 113 | ||
109 | 114 | ||
110 | VolumeAppletControl::~VolumeAppletControl() | 115 | VolumeAppletControl::~VolumeAppletControl() |
111 | { | 116 | { |
112 | } | 117 | } |
113 | 118 | ||
119 | int VolumeAppletControl::volPercent ( ) const | ||
120 | { | ||
121 | return m_vol_percent; | ||
122 | } | ||
123 | |||
124 | bool VolumeAppletControl::volMuted ( ) const | ||
125 | { | ||
126 | return m_vol_muted; | ||
127 | } | ||
128 | |||
114 | 129 | ||
115 | void VolumeAppletControl::showEvent( QShowEvent* e ) | 130 | void VolumeAppletControl::showEvent( QShowEvent* e ) |
116 | { | 131 | { |
117 | odebug << "showEvent" << oendl; | 132 | odebug << "showEvent" << oendl; |
118 | QWidget::showEvent( e ); | 133 | QWidget::showEvent( e ); |
119 | } | 134 | } |
120 | 135 | ||
121 | 136 | ||
122 | void VolumeAppletControl::hideEvent( QHideEvent* e ) | 137 | void VolumeAppletControl::hideEvent( QHideEvent* e ) |
123 | { | 138 | { |
124 | odebug << "hideEvent" << oendl; | 139 | odebug << "hideEvent" << oendl; |
125 | QWidget::hideEvent( e ); | 140 | QWidget::hideEvent( e ); |
126 | } | 141 | } |
127 | 142 | ||
128 | 143 | ||
129 | QSize VolumeAppletControl::sizeHint() const | 144 | QSize VolumeAppletControl::sizeHint() const |
130 | { | 145 | { |
131 | return QSize( 200, 200 ); //QFrame::sizeHint(); | 146 | int wd = QPEApplication::desktop()->width(); |
147 | return QSize( wd, 200 ); //QFrame::sizeHint(); | ||
132 | } | 148 | } |
133 | 149 | ||
134 | 150 | ||
135 | VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) | 151 | VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) |
136 | :OTaskbarApplet( parent, name ) | 152 | :OTaskbarApplet( parent, name ) |
137 | { | 153 | { |
138 | setFixedHeight( AppLnk::smallIconSize() ); | 154 | setFixedHeight( AppLnk::smallIconSize() +4); |
139 | setFixedWidth( AppLnk::smallIconSize() ); | 155 | setFixedWidth( AppLnk::smallIconSize() ); |
140 | _pixmap = Opie::Core::OResource::loadPixmap( "volume", Opie::Core::OResource::SmallIcon ); | 156 | _pixmap = new QPixmap (Opie::Core::OResource::loadPixmap( "volume", Opie::Core::OResource::SmallIcon )); |
141 | _control = new VolumeAppletControl( this, "control" ); | 157 | _control = new VolumeAppletControl( this, "control" ); |
142 | } | 158 | } |
143 | 159 | ||
144 | 160 | ||
145 | VolumeApplet::~VolumeApplet() | 161 | VolumeApplet::~VolumeApplet() |
146 | { | 162 | { |
147 | } | 163 | } |
148 | 164 | ||
149 | 165 | ||
150 | int VolumeApplet::position() | 166 | int VolumeApplet::position() |
151 | { | 167 | { |
152 | return 4; | 168 | return 4; |
153 | } | 169 | } |
154 | 170 | ||
155 | 171 | ||
156 | void VolumeApplet::paintEvent( QPaintEvent* ) | 172 | void VolumeApplet::paintEvent( QPaintEvent* ) |
157 | { | 173 | { |
158 | QPainter p(this); | 174 | QPainter p(this); |
159 | p.drawPixmap(0, 2, _pixmap ); | 175 | |
176 | p. drawPixmap ( (width()- _pixmap->width())/2, QMAX( (height()-4-_pixmap->height() )/2, 1), *_pixmap ); | ||
177 | p. setPen ( darkGray ); | ||
178 | p. drawRect ( 1, height() - 4, width() - 2, 4 ); | ||
179 | |||
180 | OMixerInterface* mixer = new OMixerInterface( this, "/dev/mixer" ); | ||
181 | |||
182 | int volPercent = mixer->volume( "Vol" ) >> 8; | ||
183 | |||
184 | int pixelsWide = volPercent * ( width() - 4 ) / 100; | ||
185 | p. fillRect ( 2, height() - 3, pixelsWide, 2, red ); | ||
186 | p. fillRect ( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); | ||
187 | |||
188 | // if ( _control-> volMuted ( )) { | ||
189 | // p. setPen ( red ); | ||
190 | // p. drawLine ( 1, 2, width() - 2, height() - 5 ); | ||
191 | // p. drawLine ( 1, 3, width() - 2, height() - 4 ); | ||
192 | // p. drawLine ( width() - 2, 2, 1, height() - 5 ); | ||
193 | // p. drawLine ( width() - 2, 3, 1, height() - 4 ); | ||
194 | // } | ||
195 | |||
196 | // QPainter p(this); | ||
197 | // p.drawPixmap(0, 2, _pixmap ); | ||
160 | } | 198 | } |
161 | 199 | ||
162 | 200 | ||
163 | void VolumeApplet::mousePressEvent( QMouseEvent* ) | 201 | void VolumeApplet::mousePressEvent( QMouseEvent* ) |
164 | { | 202 | { |
165 | if ( !_control->isVisible() ) | 203 | if ( !_control->isVisible() ) |
166 | { | 204 | { |
167 | popup( _control ); | 205 | popup( _control ); |
168 | } | 206 | } |
169 | else | 207 | else |
170 | { | 208 | { |
171 | _control->hide(); | 209 | _control->hide(); |
diff --git a/noncore/applets/volumeapplet2/volumeapplet.h b/noncore/applets/volumeapplet2/volumeapplet.h index c1f1a3a..953c305 100644 --- a/noncore/applets/volumeapplet2/volumeapplet.h +++ b/noncore/applets/volumeapplet2/volumeapplet.h | |||
@@ -23,33 +23,35 @@ | |||
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifndef VOLUMEAPPLET_H | 31 | #ifndef VOLUMEAPPLET_H |
32 | #define VOLUMEAPPLET_H | 32 | #define VOLUMEAPPLET_H |
33 | 33 | ||
34 | #include <opie2/otaskbarapplet.h> | 34 | #include <opie2/otaskbarapplet.h> |
35 | #include <opie2/osoundsystem.h> | ||
35 | #include <qframe.h> | 36 | #include <qframe.h> |
36 | #include <qstring.h> | 37 | #include <qstring.h> |
37 | #include <qvbox.h> | 38 | #include <qvbox.h> |
38 | #include <qpixmap.h> | 39 | #include <qpixmap.h> |
40 | //using namespace Opie::MM; | ||
39 | 41 | ||
40 | namespace Opie | 42 | namespace Opie |
41 | { | 43 | { |
42 | namespace Ui { class OLedBox; } | 44 | namespace Ui { class OLedBox; } |
43 | namespace MM { class OMixerInterface; } | 45 | // namespace MM { class OMixerInterface; } |
44 | } | 46 | } |
45 | class QLabel; | 47 | class QLabel; |
46 | class QSlider; | 48 | class QSlider; |
47 | class QShowEvent; | 49 | class QShowEvent; |
48 | class QHideEvent; | 50 | class QHideEvent; |
49 | class QGridLayout; | 51 | class QGridLayout; |
50 | 52 | ||
51 | class Channel : public QVBox | 53 | class Channel : public QVBox |
52 | { | 54 | { |
53 | public: | 55 | public: |
54 | Channel( Opie::MM::OMixerInterface* mixer, QWidget* parent, const char* name ); | 56 | Channel( Opie::MM::OMixerInterface* mixer, QWidget* parent, const char* name ); |
55 | virtual ~Channel(); | 57 | virtual ~Channel(); |
@@ -60,44 +62,51 @@ class Channel : public QVBox | |||
60 | private: | 62 | private: |
61 | QLabel* _name; | 63 | QLabel* _name; |
62 | QSlider* _volume; | 64 | QSlider* _volume; |
63 | Opie::Ui::OLedBox* _mute; | 65 | Opie::Ui::OLedBox* _mute; |
64 | Opie::MM::OMixerInterface* _mixer; | 66 | Opie::MM::OMixerInterface* _mixer; |
65 | }; | 67 | }; |
66 | 68 | ||
67 | class VolumeAppletControl : public QFrame | 69 | class VolumeAppletControl : public QFrame |
68 | { | 70 | { |
69 | public: | 71 | public: |
70 | VolumeAppletControl( Opie::Ui::OTaskbarApplet* parent, const char* name = 0 ); | 72 | VolumeAppletControl( Opie::Ui::OTaskbarApplet* parent, const char* name = 0 ); |
71 | ~VolumeAppletControl(); | 73 | ~VolumeAppletControl(); |
74 | bool volMuted() const; | ||
75 | int volPercent() const; | ||
76 | |||
77 | int m_vol_percent; | ||
78 | bool m_vol_muted; | ||
79 | |||
80 | Opie::MM::OMixerInterface* mixer; | ||
72 | 81 | ||
73 | virtual QSize sizeHint() const; | 82 | virtual QSize sizeHint() const; |
74 | 83 | ||
75 | protected: | 84 | protected: |
76 | virtual void showEvent( QShowEvent* ); | 85 | virtual void showEvent( QShowEvent* ); |
77 | virtual void hideEvent( QHideEvent* ); | 86 | virtual void hideEvent( QHideEvent* ); |
78 | void build(); | 87 | void build(); |
79 | 88 | ||
80 | private: | 89 | private: |
81 | QGridLayout* l; | ||
82 | 90 | ||
91 | QGridLayout* l; | ||
83 | }; | 92 | }; |
84 | 93 | ||
85 | 94 | ||
86 | class VolumeApplet : public Opie::Ui::OTaskbarApplet | 95 | class VolumeApplet : public Opie::Ui::OTaskbarApplet |
87 | { | 96 | { |
88 | public: | 97 | public: |
89 | VolumeApplet( QWidget* parent = 0, const char* name = 0 ); | 98 | VolumeApplet( QWidget* parent = 0, const char* name = 0 ); |
90 | ~VolumeApplet(); | 99 | ~VolumeApplet(); |
91 | 100 | ||
92 | static int position(); | 101 | static int position(); |
93 | protected: | 102 | protected: |
94 | virtual void paintEvent( QPaintEvent* ); | 103 | virtual void paintEvent( QPaintEvent* ); |
95 | virtual void mousePressEvent( QMouseEvent* ); | 104 | virtual void mousePressEvent( QMouseEvent* ); |
96 | 105 | ||
97 | private: | 106 | private: |
98 | VolumeAppletControl* _control; | 107 | VolumeAppletControl* _control; |
99 | QPixmap _pixmap; | 108 | QPixmap* _pixmap; |
100 | }; | 109 | }; |
101 | 110 | ||
102 | #endif | 111 | #endif |
103 | 112 | ||