-rw-r--r-- | noncore/applets/volumeapplet2/volumeapplet.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/noncore/applets/volumeapplet2/volumeapplet.cpp b/noncore/applets/volumeapplet2/volumeapplet.cpp index 2122007..946616f 100644 --- a/noncore/applets/volumeapplet2/volumeapplet.cpp +++ b/noncore/applets/volumeapplet2/volumeapplet.cpp | |||
@@ -1,213 +1,216 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 4 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
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 | #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 | #include <qpe/qpeapplication.h> |
42 | 42 | ||
43 | using namespace Opie::Core; | 43 | using namespace Opie::Core; |
44 | using namespace Opie::MM; | 44 | using namespace Opie::MM; |
45 | using namespace Opie::Ui; | 45 | using namespace Opie::Ui; |
46 | 46 | ||
47 | /* QT */ | 47 | /* QT */ |
48 | #include <qpainter.h> | 48 | #include <qpainter.h> |
49 | #include <qlabel.h> | 49 | #include <qlabel.h> |
50 | #include <qlayout.h> | 50 | #include <qlayout.h> |
51 | #include <qslider.h> | 51 | #include <qslider.h> |
52 | 52 | ||
53 | /* STD */ | 53 | /* STD */ |
54 | #include <assert.h> | 54 | #include <assert.h> |
55 | 55 | ||
56 | Channel::Channel( OMixerInterface* mixer, QWidget* parent, const char* name ) | 56 | Channel::Channel( OMixerInterface* mixer, QWidget* parent, const char* name ) |
57 | :QVBox( parent, name ) | 57 | :QVBox( parent, name ) |
58 | { | 58 | { |
59 | _name = new QLabel( name, this ); | 59 | _name = new QLabel( name, this ); |
60 | _name->setFont( QFont( "Vera", 8 ) ); | 60 | _name->setFont( QFont( "Vera", 8 ) ); |
61 | _volume = new QSlider( 0, 100, 10, mixer->volume( name ) & 0xff, QSlider::Vertical, this ); | 61 | _volume = new QSlider( 0, 100, 10, mixer->volume( name ) & 0xff, QSlider::Vertical, this ); |
62 | _volume->setTickmarks( QSlider::Both ); | 62 | _volume->setTickmarks( QSlider::Both ); |
63 | _volume->setTickInterval( 20 ); | 63 | _volume->setTickInterval( 20 ); |
64 | _mute = new OLedBox( green, this ); | 64 | _mute = new OLedBox( green, this ); |
65 | _mute->setFocusPolicy( QWidget::NoFocus ); | 65 | _mute->setFocusPolicy( QWidget::NoFocus ); |
66 | _mute->setFixedSize( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); | 66 | _mute->setFixedSize( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); |
67 | _name->show(); | 67 | _name->show(); |
68 | _volume->show(); | 68 | _volume->show(); |
69 | _mute->show(); | 69 | _mute->show(); |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | Channel::~Channel() | 73 | Channel::~Channel() |
74 | { | 74 | { |
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
78 | VolumeAppletControl::VolumeAppletControl( OTaskbarApplet* parent, const char* name ) | 78 | VolumeAppletControl::VolumeAppletControl( OTaskbarApplet* parent, const char* name ) |
79 | :QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), l(0) | 79 | :QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), l(0) |
80 | { | 80 | { |
81 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 81 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
82 | l = new QGridLayout( this ); | 82 | l = new QGridLayout( this ); |
83 | build(); | 83 | build(); |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
87 | void VolumeAppletControl::build() | 87 | void VolumeAppletControl::build() |
88 | { | 88 | { |
89 | OSoundSystem* sound = OSoundSystem::instance(); | 89 | OSoundSystem* sound = OSoundSystem::instance(); |
90 | OSoundSystem::CardIterator it = sound->iterator(); | 90 | OSoundSystem::CardIterator it = sound->iterator(); |
91 | 91 | ||
92 | // OMixerInterface* | 92 | // OMixerInterface* |
93 | mixer = new OMixerInterface( this, "/dev/mixer" ); | 93 | mixer = new OMixerInterface( this, "/dev/mixer" ); |
94 | 94 | ||
95 | QStringList channels = mixer->allChannels(); | 95 | QStringList channels = mixer->allChannels(); |
96 | 96 | ||
97 | int x = 0; | 97 | int x = 0; |
98 | // int y = 0; | 98 | // int y = 0; |
99 | 99 | ||
100 | for ( QStringList::Iterator it = channels.begin(); it != channels.end(); ++it ) | 100 | for ( QStringList::Iterator it = channels.begin(); it != channels.end(); ++it ) |
101 | { | 101 | { |
102 | if((*it) == mixer->volume( "Vol")) { | 102 | if((*it) == mixer->volume( "Vol")) { |
103 | m_vol_percent=mixer->volume( *it ) >> 8; | 103 | m_vol_percent=mixer->volume( *it ) >> 8; |
104 | } | 104 | } |
105 | owarn << "OSSDEMO: Mixer has channel " << *it << "" << oendl; | 105 | owarn << "OSSDEMO: Mixer has channel " << *it << "" << oendl; |
106 | owarn << "OSSDEMO: +--- volume " << ( mixer->volume( *it ) & 0xff ) | 106 | owarn << "OSSDEMO: +--- volume " << ( mixer->volume( *it ) & 0xff ) |
107 | << " (left) | " << ( mixer->volume( *it ) >> 8 ) << " (right)" << oendl; | 107 | << " (left) | " << ( mixer->volume( *it ) >> 8 ) << " (right)" << oendl; |
108 | 108 | ||
109 | l->addWidget( new Channel( mixer, this, *it ), 0, x++, AlignCenter ); | 109 | l->addWidget( new Channel( mixer, this, *it ), 0, x++, AlignCenter ); |
110 | } | 110 | } |
111 | 111 | ||
112 | } | 112 | } |
113 | 113 | ||
114 | 114 | ||
115 | VolumeAppletControl::~VolumeAppletControl() | 115 | VolumeAppletControl::~VolumeAppletControl() |
116 | { | 116 | { |
117 | } | 117 | } |
118 | 118 | ||
119 | int VolumeAppletControl::volPercent ( ) const | 119 | int VolumeAppletControl::volPercent ( ) const |
120 | { | 120 | { |
121 | return m_vol_percent; | 121 | return m_vol_percent; |
122 | } | 122 | } |
123 | 123 | ||
124 | bool VolumeAppletControl::volMuted ( ) const | 124 | bool VolumeAppletControl::volMuted ( ) const |
125 | { | 125 | { |
126 | return m_vol_muted; | 126 | return m_vol_muted; |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | void VolumeAppletControl::showEvent( QShowEvent* e ) | 130 | void VolumeAppletControl::showEvent( QShowEvent* e ) |
131 | { | 131 | { |
132 | odebug << "showEvent" << oendl; | 132 | odebug << "showEvent" << oendl; |
133 | QWidget::showEvent( e ); | 133 | QWidget::showEvent( e ); |
134 | } | 134 | } |
135 | 135 | ||
136 | 136 | ||
137 | void VolumeAppletControl::hideEvent( QHideEvent* e ) | 137 | void VolumeAppletControl::hideEvent( QHideEvent* e ) |
138 | { | 138 | { |
139 | odebug << "hideEvent" << oendl; | 139 | odebug << "hideEvent" << oendl; |
140 | QWidget::hideEvent( e ); | 140 | QWidget::hideEvent( e ); |
141 | } | 141 | } |
142 | 142 | ||
143 | 143 | ||
144 | QSize VolumeAppletControl::sizeHint() const | 144 | QSize VolumeAppletControl::sizeHint() const |
145 | { | 145 | { |
146 | int wd = QPEApplication::desktop()->width(); | 146 | int wd = QPEApplication::desktop()->width(); |
147 | return QSize( wd, 200 ); //QFrame::sizeHint(); | 147 | return QSize( wd, 200 ); //QFrame::sizeHint(); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) | 151 | VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) |
152 | :OTaskbarApplet( parent, name ) | 152 | :OTaskbarApplet( parent, name ) |
153 | { | 153 | { |
154 | setFixedHeight( AppLnk::smallIconSize() +4); | 154 | setFixedHeight( AppLnk::smallIconSize() +4); |
155 | setFixedWidth( AppLnk::smallIconSize() ); | 155 | setFixedWidth( AppLnk::smallIconSize() ); |
156 | _pixmap = new QPixmap (Opie::Core::OResource::loadPixmap( "volume", Opie::Core::OResource::SmallIcon )); | 156 | _pixmap = new QPixmap (Opie::Core::OResource::loadPixmap( "volume", Opie::Core::OResource::SmallIcon )); |
157 | _control = new VolumeAppletControl( this, "control" ); | 157 | _control = new VolumeAppletControl( this, "control" ); |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | VolumeApplet::~VolumeApplet() | 161 | VolumeApplet::~VolumeApplet() |
162 | { | 162 | { |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | int VolumeApplet::position() | 166 | int VolumeApplet::position() |
167 | { | 167 | { |
168 | return 4; | 168 | return 4; |
169 | } | 169 | } |
170 | 170 | ||
171 | 171 | ||
172 | void VolumeApplet::paintEvent( QPaintEvent* ) | 172 | void VolumeApplet::paintEvent( QPaintEvent* ) |
173 | { | 173 | { |
174 | QPainter p ( this ); | 174 | QPainter p(this); |
175 | p.drawPixmap(0, 2, _pixmap ); | ||
175 | 176 | ||
177 | /* | ||
176 | p. drawPixmap ( (width()- _pixmap->width())/2, QMAX( (height()-4-_pixmap->height() )/2, 1), *_pixmap ); | 178 | p. drawPixmap ( (width()- _pixmap->width())/2, QMAX( (height()-4-_pixmap->height() )/2, 1), *_pixmap ); |
177 | p. setPen ( darkGray ); | 179 | p. setPen ( darkGray ); |
178 | p. drawRect ( 1, height() - 4, width() - 2, 4 ); | 180 | p. drawRect ( 1, height() - 4, width() - 2, 4 ); |
179 | 181 | ||
180 | OMixerInterface* mixer = new OMixerInterface( this, "/dev/mixer" ); | 182 | OMixerInterface* mixer = new OMixerInterface( this, "/dev/mixer" ); |
181 | 183 | ||
182 | int volPercent = mixer->volume( "Vol" ) >> 8; | 184 | int volPercent = mixer->volume( "Vol" ) >> 8; |
183 | 185 | ||
184 | int pixelsWide = volPercent * ( width() - 4 ) / 100; | 186 | int pixelsWide = volPercent * ( width() - 4 ) / 100; |
185 | p. fillRect ( 2, height() - 3, pixelsWide, 2, red ); | 187 | p. fillRect ( 2, height() - 3, pixelsWide, 2, red ); |
186 | p. fillRect ( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); | 188 | p. fillRect ( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); |
189 | */ | ||
187 | 190 | ||
188 | // if ( _control-> volMuted ( )) { | 191 | // if ( _control-> volMuted ( )) { |
189 | // p. setPen ( red ); | 192 | // p. setPen ( red ); |
190 | // p. drawLine ( 1, 2, width() - 2, height() - 5 ); | 193 | // p. drawLine ( 1, 2, width() - 2, height() - 5 ); |
191 | // p. drawLine ( 1, 3, width() - 2, height() - 4 ); | 194 | // p. drawLine ( 1, 3, width() - 2, height() - 4 ); |
192 | // p. drawLine ( width() - 2, 2, 1, height() - 5 ); | 195 | // p. drawLine ( width() - 2, 2, 1, height() - 5 ); |
193 | // p. drawLine ( width() - 2, 3, 1, height() - 4 ); | 196 | // p. drawLine ( width() - 2, 3, 1, height() - 4 ); |
194 | // } | 197 | // } |
195 | 198 | ||
196 | // QPainter p(this); | 199 | // QPainter p(this); |
197 | // p.drawPixmap(0, 2, _pixmap ); | 200 | // p.drawPixmap(0, 2, _pixmap ); |
198 | } | 201 | } |
199 | 202 | ||
200 | 203 | ||
201 | void VolumeApplet::mousePressEvent( QMouseEvent* ) | 204 | void VolumeApplet::mousePressEvent( QMouseEvent* ) |
202 | { | 205 | { |
203 | if ( !_control->isVisible() ) | 206 | if ( !_control->isVisible() ) |
204 | { | 207 | { |
205 | popup( _control ); | 208 | popup( _control ); |
206 | } | 209 | } |
207 | else | 210 | else |
208 | { | 211 | { |
209 | _control->hide(); | 212 | _control->hide(); |
210 | } | 213 | } |
211 | } | 214 | } |
212 | 215 | ||
213 | EXPORT_OPIE_APPLET_v1( VolumeApplet ) | 216 | EXPORT_OPIE_APPLET_v1( VolumeApplet ) |