summaryrefslogtreecommitdiff
authorsandman <sandman>2002-06-24 20:06:38 (UTC)
committer sandman <sandman>2002-06-24 20:06:38 (UTC)
commit793a63d9cce0502616cad6999643b1a61836a3db (patch) (unidiff)
tree3ea020afd5a06236e5e889f3acae429d87171488
parentfe4cb014e959518e4835d15593f2c392174af55b (diff)
downloadopie-793a63d9cce0502616cad6999643b1a61836a3db.zip
opie-793a63d9cce0502616cad6999643b1a61836a3db.tar.gz
opie-793a63d9cce0502616cad6999643b1a61836a3db.tar.bz2
Started as a bug fix this is a near complete restructuring/rewrite:
- Added a alarm volume slider on iPAQs - Made mic mutable - Correctly inform the launcher about tap/key sounds
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/volumeapplet/oledbox.cpp270
-rw-r--r--core/applets/volumeapplet/oledbox.h51
-rw-r--r--core/applets/volumeapplet/volume.cpp850
-rw-r--r--core/applets/volumeapplet/volume.h140
-rw-r--r--core/applets/volumeapplet/volumeapplet.pro4
-rw-r--r--core/applets/volumeapplet/volumeappletimpl.cpp35
6 files changed, 931 insertions, 419 deletions
diff --git a/core/applets/volumeapplet/oledbox.cpp b/core/applets/volumeapplet/oledbox.cpp
new file mode 100644
index 0000000..3036929
--- a/dev/null
+++ b/core/applets/volumeapplet/oledbox.cpp
@@ -0,0 +1,270 @@
1
2#include <qpixmap.h>
3#include <qbitmap.h>
4#include <qpainter.h>
5
6#include "oledbox.h"
7
8
9#ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC
10
11/* XPM */
12static const char * ledborder_xpm[] = {
13"16 16 11 1",
14 " c None",
15 ".c #626562",
16 "+c #7B7D7B",
17 "@c #949594",
18 "#c #ACAEAC",
19 "$c #CDCACD",
20 "%c #CDCECD",
21 ";c #E6E6E6",
22 ">c #FFFFFF",
23 ",c #E6E2E6",
24 "'c #FFFAFF",
25" .++@@# ",
26" ...++@@##$ ",
27" .....+@##$$% ",
28" ..... #$%%% ",
29" ... %%; ",
30".... ;;;;",
31"++. ;>>",
32"+++ >>>",
33"@@@ >>>",
34"@@# >>>",
35"#### >>>>",
36" #$$ >>> ",
37" $$,,' >>>>> ",
38" ,,,''>>>>>>> ",
39" ,''>>>>>>> ",
40" '>>>>> "};
41
42
43QPixmap *OLedBox::s_border_pix = 0;
44
45#endif
46
47
48OLedBox::OLedBox ( const QColor &col, QWidget *parent, const char *name ) : QWidget ( parent, name )
49{
50 m_color = col;
51 m_on = false;
52
53 m_pix [ 0 ] = m_pix [ 1 ] = false;
54
55 setBackgroundMode ( PaletteBackground );
56
57#ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC
58 if ( !s_border_pix )
59 s_border_pix = new QPixmap ( ledborder_xpm );
60#endif
61}
62
63OLedBox::~OLedBox ( )
64{
65 delete m_pix [ 0 ];
66 delete m_pix [ 1 ];
67}
68
69QSize OLedBox::sizeHint ( ) const
70{
71 return QSize ( 16, 16 );
72}
73
74bool OLedBox::isOn ( ) const
75{
76 return m_on;
77}
78
79QColor OLedBox::color ( ) const
80{
81 return m_color;
82}
83
84void OLedBox::setOn ( bool b )
85{
86 if ( m_on != b ) {
87 m_on = b;
88 update ( );
89 }
90}
91
92void OLedBox::toggle ( )
93{
94 setOn ( !isOn ( ) );
95}
96
97void OLedBox::setColor ( const QColor &col )
98{
99 if ( m_color != col ) {
100 m_color = col;
101
102 delete m_pix [ 0 ];
103 delete m_pix [ 1 ];
104
105 update ( );
106 }
107}
108
109void OLedBox::mousePressEvent ( QMouseEvent *e )
110{
111 if ( e-> button ( ) == LeftButton ) {
112 m_on = !m_on;
113 update ( );
114 emit toggled ( m_on );
115 }
116}
117
118
119void OLedBox::resizeEvent ( QResizeEvent * )
120{
121 delete m_pix [ 0 ];
122 delete m_pix [ 1 ];
123
124 update ( );
125}
126
127void OLedBox::paintEvent ( QPaintEvent *e )
128{
129 int ind = m_on ? 1 : 0;
130
131 if ( !m_pix [ ind ] ) {
132 m_pix [ ind ] = new QPixmap ( size ( ));
133
134 drawLed ( m_pix [ ind ], m_on ? m_color : m_color. dark ( 300 ) );
135 }
136 if ( !e-> erased ( ))
137 erase ( );
138
139 QPainter p ( this );
140 p. drawPixmap ( 0, 0, *m_pix [ ind ] );
141}
142
143// From KDE libkdeui / led.cpp
144
145void OLedBox::drawLed ( QPixmap *pix, const QColor &col ) // paint a ROUND SUNKEN led lamp
146{
147 QPainter paint;
148 QColor color;
149 QBrush brush;
150 QPen pen;
151
152 // First of all we want to know what area should be updated
153 // Initialize coordinates, width, and height of the LED
154 int width = pix-> width ( );
155
156 // Make sure the LED is round!
157 if ( width > pix-> height ( ))
158 width = pix-> height ( );
159 width -= 2; // leave one pixel border
160 if ( width < 0 )
161 width = 0;
162
163 // maybe we could stop HERE, if width <=0 ?
164
165 // start painting widget
166 //
167 paint.begin( pix );
168
169 // Set the color of the LED according to given parameters
170 color = col;
171
172 // Set the brush to SolidPattern, this fills the entire area
173 // of the ellipse which is drawn first
174 brush.setStyle( QBrush::SolidPattern );
175 brush.setColor( color );
176 paint.setBrush( brush ); // Assign the brush to the painter
177
178 // Draws a "flat" LED with the given color:
179 paint.drawEllipse( 1, 1, width, width );
180
181 // Draw the bright light spot of the LED now, using modified "old"
182 // painter routine taken from KDEUIs KLed widget:
183
184 // Setting the new width of the pen is essential to avoid "pixelized"
185 // shadow like it can be observed with the old LED code
186 pen.setWidth( 2 );
187
188 // shrink the light on the LED to a size about 2/3 of the complete LED
189 int pos = width / 5 + 1;
190 int light_width = width;
191 light_width *= 2;
192 light_width /= 3;
193
194 // Calculate the LEDs "light factor":
195 int light_quote = ( 130 * 2 / ( light_width ? light_width : 1 ) ) + 100;
196
197 // Now draw the bright spot on the LED:
198 while ( light_width )
199 {
200 color = color.light( light_quote ); // make color lighter
201 pen.setColor( color ); // set color as pen color
202 paint.setPen( pen ); // select the pen for drawing
203 paint.drawEllipse( pos, pos, light_width, light_width ); // draw the ellipse (circle)
204 light_width--;
205 if ( !light_width )
206 break;
207 paint.drawEllipse( pos, pos, light_width, light_width );
208 light_width--;
209 if ( !light_width )
210 break;
211 paint.drawEllipse( pos, pos, light_width, light_width );
212 pos++;
213 light_width--;
214 }
215
216 // Drawing of bright spot finished, now draw a thin border
217 // around the LED which resembles a shadow with light coming
218 // from the upper left.
219
220#ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC
221 paint. drawPixmap ( 0, 0, *s_border_pix );
222
223#else
224 pen.setWidth( 3 );
225 brush.setStyle( QBrush::NoBrush ); // Switch off the brush
226 paint.setBrush( brush ); // This avoids filling of the ellipse
227
228 // Set the initial color value to 200 (bright) and start
229 // drawing the shadow border at 45 (45*16 = 720).
230 int shadow_color = 200, angle;
231
232 for ( angle = 720; angle < 6480; angle += 240 )
233 {
234 color.setRgb( shadow_color, shadow_color, shadow_color );
235 pen.setColor( color );
236 paint.setPen( pen );
237 paint.drawArc( 0, 0, width+2, width+2, angle, 240 );
238 paint.drawArc( 1, 1, width, width, angle, 240 );
239 paint.drawArc( 2, 2, width-2, width-2, angle, 240 );
240 if ( angle < 2320 ) {
241 shadow_color -= 25; // set color to a darker value
242 if ( shadow_color < 100 )
243 shadow_color = 100;
244 }
245 else if ( ( angle > 2320 ) && ( angle < 5760 ) ) {
246 shadow_color += 25; // set color to a brighter value
247 if ( shadow_color > 255 )
248 shadow_color = 255;
249 }
250 else {
251 shadow_color -= 25; // set color to a darker value again
252 if ( shadow_color < 100 )
253 shadow_color = 100;
254 } // end if ( angle < 2320 )
255 } // end for ( angle = 720; angle < 6480; angle += 160 )
256#endif
257 paint.end();
258 //
259 // painting done
260
261 QBitmap mask ( pix-> width ( ), pix-> height ( ), true );
262 QPainter mp ( &mask );
263 mp. setPen ( Qt::NoPen );
264 mp. setBrush ( Qt::color1 );
265 mp. drawEllipse ( 0, 0, width + 2, width + 2 );
266 mp. end ( );
267
268 pix-> setMask ( mask );
269}
270
diff --git a/core/applets/volumeapplet/oledbox.h b/core/applets/volumeapplet/oledbox.h
new file mode 100644
index 0000000..4371a22
--- a/dev/null
+++ b/core/applets/volumeapplet/oledbox.h
@@ -0,0 +1,51 @@
1#ifndef __OPIE_OLED_H__
2#define __OPIE_OLED_H__
3
4#include <qwidget.h>
5#include <qcolor.h>
6
7class QPixmap;
8
9#define _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC
10
11class OLedBox : public QWidget {
12 Q_OBJECT
13
14public:
15 OLedBox ( const QColor &col = red, QWidget *parent = 0, const char *name = 0 );
16 virtual ~OLedBox ( );
17
18 QColor color ( ) const;
19 bool isOn ( ) const;
20
21 virtual QSize sizeHint ( ) const;
22
23public slots:
24 void toggle ( );
25 void setOn ( bool on );
26 void setColor ( const QColor &col );
27
28signals:
29 void toggled ( bool );
30
31protected:
32 virtual void paintEvent ( QPaintEvent *e );
33 virtual void resizeEvent ( QResizeEvent *e );
34
35 virtual void mousePressEvent ( QMouseEvent *e );
36
37private:
38 void drawLed ( QPixmap *, const QColor &col );
39
40private:
41 QPixmap *m_pix [2];
42
43 QColor m_color;
44 bool m_on;
45
46 #ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC
47 static QPixmap *s_border_pix;
48#endif
49};
50
51#endif
diff --git a/core/applets/volumeapplet/volume.cpp b/core/applets/volumeapplet/volume.cpp
index d871a35..a000087 100644
--- a/core/applets/volumeapplet/volume.cpp
+++ b/core/applets/volumeapplet/volume.cpp
@@ -18,6 +18,7 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <stdio.h>
21 22
22#include "volume.h" 23#include "volume.h"
23 24
@@ -36,416 +37,599 @@
36#include <qpixmap.h> 37#include <qpixmap.h>
37#include <qlabel.h> 38#include <qlabel.h>
38 39
40#include <qtoolbutton.h>
39#include <qpushbutton.h> 41#include <qpushbutton.h>
40#include <qtimer.h> 42#include <qtimer.h>
41 43
42#define RATE_TIMER_INTERVAL 100 44#include <opie/odevice.h>
45
46#include "oledbox.h"
47
48#define RATE_TIMER_INTERVAL 100
43// Ten times per second is fine (RATE_TIMER_INTERVAL 100). A shorter time 49// Ten times per second is fine (RATE_TIMER_INTERVAL 100). A shorter time
44// results in "hanging" buttons on the iPAQ due to quite high CPU consumption. 50// results in "hanging" buttons on the iPAQ due to quite high CPU consumption.
45 51
46VolumeControl::VolumeControl( bool showMic, QWidget *parent, const char *name )
47 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
48{
49 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
50 createView(showMic);
51}
52 52
53void VolumeControl::createView(bool showMic) 53/* XPM */
54static const char * vol_xpm[] = {
55"20 20 3 1",
56 " c None",
57 ".c #0000FF",
58 "+c #000000",
59" ",
60" . ",
61" . . . . ",
62" . . . . . . ",
63" . . . . . . . ",
64" . . ..... . . ",
65" . ... ..... ... ",
66" ........... .... ",
67" ................. ",
68"++++++++++++++++++++",
69" .................. ",
70" . ............. . ",
71" . ..... ....... ",
72" . ... ..... . ",
73" . ... ..... . ",
74" . ... ..... ",
75" . . . . . ",
76" . . . ",
77" . . . ",
78" "};
79/* XPM */
80static const char * mic_xpm[] = {
81"20 20 21 1",
82 " c None",
83 ".c #000000",
84 "+c #EEEEEE",
85 "@c #B4B6B4",
86 "#c #8B8D8B",
87 "$c #D5D6D5",
88 "%c #E6E6E6",
89 "&c #9C9D9C",
90 "*c #6A696A",
91 "=c #E6E2E6",
92 "-c #F6F2F6",
93 ";c #CDC6CD",
94 ">c #737573",
95 ",c #4A484A",
96 "'c #DEDEDE",
97 ")c #F6EEF6",
98 "!c #414041",
99 "~c #202020",
100 "{c #ACAEAC",
101 "]c #838583",
102 "^c #6A656A",
103" ",
104" .... ",
105" .+@+#. ",
106" ..$%&%*. ",
107" .=-.;=>=,. ",
108" .'+).&+!+. ",
109" .+;+;.~+~. ",
110" ..%{%,.... ",
111" ..&=>=~.. ",
112" .+..]^,.. ",
113" .+....... ",
114" .%... ",
115" .=... ",
116" .+... ",
117" .+... ",
118" .... ",
119" .... ",
120" .. ",
121" . ",
122". "};
123
124/* XPM */
125static const char * alarm_xpm[] = {
126"20 20 33 1",
127 " c None",
128 ".c #080602",
129 "+c #AAA602",
130 "@c #252002",
131 "#c #434202",
132 "$c #795602",
133 "%c #C3C20D",
134 "&c #DADAC2",
135 "*c #826002",
136 "=c #740502",
137 "-c #D6D602",
138 ";c #322E02",
139 ">c #826A02",
140 ",c #F1F195",
141 "'c #959215",
142 ")c #423602",
143 "!c #4B0302",
144 "~c #844315",
145 "{c #AAAA2A",
146 "]c #E2DE42",
147 "^c #BA7E04",
148 "/c #7F7502",
149 "(c #828276",
150 "_c #FEFE4E",
151 ":c #7D1902",
152 "<c #989656",
153 "[c #260B02",
154 "}c #F7F7D8",
155 "|c #DCDA5A",
156 "1c #823102",
157 "2c #B1AC6B",
158 "3c #F7F710",
159 "4c #838204",
160" ",
161" ",
162" 4'4/ ",
163" /-^= ",
164" 42{4>4 ",
165" '2|+*$44 ",
166" +2&3+$1*44 ",
167" (%_}_+/$:>/4 ",
168" 4%_}3+#;>:*4 ",
169" 4%_}&+#[1$/4 ",
170" 4%_,2')[~~>4 ",
171" 4%33'4#@~1>4 ",
172" 4%3344#[:>/4 ",
173" 42&_3'4#@>:*44 ",
174" 42|}}3'4#[;$)$44 ",
175"444{]]2^~~:!!#.@##/ ",
176"4444-%*:==!!=...../ ",
177" /:[.. ",
178" /@. ",
179" "};
180
181VolumeControl::VolumeControl ( VolumeApplet *icon, bool /*showMic*/, QWidget *parent, const char *name )
182 : QFrame ( parent, name, WStyle_StaysOnTop | WType_Popup )
54{ 183{
55 Config cfg("qpe"); 184 m_icon = icon;
56 cfg.setGroup("Volume"); 185
57//showMic = TRUE; 186 bool has_wav_alarm = false;
58 QHBoxLayout *hboxLayout = new QHBoxLayout(this); 187
59 hboxLayout->setMargin( 3 ); 188 switch ( ODevice::inst ( )-> model ( )) {
60 hboxLayout->setSpacing( 0); 189 case OMODEL_iPAQ_H31xx:
61 190 case OMODEL_iPAQ_H36xx:
62 QVBoxLayout *vboxButtons = new QVBoxLayout(this); 191 case OMODEL_iPAQ_H37xx:
63 upButton = new QPushButton( this ); 192 case OMODEL_iPAQ_H38xx:
64 upButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); 193 has_wav_alarm = true;
65 upButton->setPixmap( Resource::loadPixmap( "up" ) ); 194 break;
66 downButton = new QPushButton( this ); 195 default:
67 downButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); 196 break;
68 downButton->setPixmap( Resource::loadPixmap( "down" ) ); 197 }
69 vboxButtons->setSpacing( 2 ); 198
70 199
71 upButton->setFixedHeight(26); 200 setFrameStyle ( QFrame::PopupPanel | QFrame::Raised );
72 downButton->setFixedHeight(26); 201
73 202 QGridLayout *grid = new QGridLayout ( this, 1, 1, 6, 4 );
74 vboxButtons->addWidget( upButton ); 203 grid-> setSpacing ( 4 );
75 vboxButtons->addWidget( downButton ); 204 grid-> setMargin ( 6 );
76 205
77 QVBoxLayout *vbox = new QVBoxLayout( this ); 206 QVBoxLayout *vbox;
78 QHBoxLayout *hbox = NULL; 207 QLabel *l;
79 208
80 slider = new QSlider( this ); 209 vbox = new QVBoxLayout ( );
81 slider->setRange( 0, 100 ); 210 vbox-> setSpacing ( 4 );
82 slider->setTickmarks( QSlider::Both ); 211 grid-> addLayout ( vbox, 1, 0 );
83 slider->setTickInterval( 20 ); 212
84 slider->setFocusPolicy( QWidget::NoFocus ); 213 upButton = new QPushButton ( this );
85 slider->setValue(cfg.readNumEntry("VolumePercent")); 214 upButton-> setSizePolicy ( QSizePolicy ( QSizePolicy::Minimum, QSizePolicy::Expanding ));
86 215 upButton-> setPixmap ( Resource::loadPixmap ( "up" ));
87 QVBoxLayout *sbox = new QVBoxLayout(this); 216 upButton-> setFocusPolicy ( QWidget::NoFocus );
88 sbox->setMargin( 3 ); 217
89 sbox->setSpacing( 3 ); 218 vbox-> addWidget ( upButton );
90 sbox->addWidget( new QLabel("Vol", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter ); 219
91 sbox->addWidget( slider, 0, Qt::AlignVCenter | Qt::AlignHCenter ); 220 downButton = new QPushButton ( this );
92 221 downButton-> setSizePolicy ( QSizePolicy ( QSizePolicy::Minimum, QSizePolicy::Expanding ));
93// if (showMic == TRUE) { 222 downButton-> setPixmap ( Resource::loadPixmap ( "down" ));
94 mic = new QSlider(this); 223 downButton-> setFocusPolicy ( QWidget::NoFocus );
95 mic->setRange( 0, 100 ); 224
96 mic->setTickmarks( QSlider::Both ); 225 vbox-> addWidget ( downButton );
97 mic->setTickInterval( 20 ); 226
98 mic->setFocusPolicy( QWidget::NoFocus ); 227 volSlider = new QSlider ( this );
99 mic->setValue(cfg.readNumEntry("Mic")); 228 volSlider-> setRange ( 0, 100 );
100 229 volSlider-> setTickmarks ( QSlider::Both );
101 QVBoxLayout *mbox = new QVBoxLayout(this); 230 volSlider-> setTickInterval ( 20 );
102 mbox->setMargin( 3 ); 231 volSlider-> setFocusPolicy ( QWidget::NoFocus );
103 mbox->setSpacing( 3 ); 232
104 mbox->addWidget( new QLabel("Mic", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter ); 233 l = new QLabel ( this );
105 mbox->addWidget( mic, 0, Qt::AlignVCenter | Qt::AlignHCenter ); 234 l-> setPixmap ( QPixmap ( vol_xpm ));
106 235
107 hbox = new QHBoxLayout( this ); 236 grid-> addWidget ( l, 0, 1, AlignCenter );
108 hbox->setMargin( 3 ); 237 grid-> addWidget ( volSlider, 1, 1, AlignCenter );
109 hbox->setSpacing( 3 ); 238
110 hbox->addLayout( sbox, 1); 239 volLed = new OLedBox ( green, this );
111 hbox->addLayout( mbox, 1); 240 volLed-> setFocusPolicy ( QWidget::NoFocus );
112 // } 241 volLed-> setFixedSize ( 16, 16 );
113 242
114 muteBox = new QCheckBox( tr("Mute"), this ); 243 grid-> addWidget ( volLed, 2, 1, AlignCenter );
115 muteBox->setFocusPolicy( QWidget::NoFocus ); 244
116 245 micSlider = new QSlider ( this );
117 QVBoxLayout *klbox = new QVBoxLayout(this); 246 micSlider-> setRange ( 0, 100 );
118 247 micSlider-> setTickmarks ( QSlider::Both );
119 QLabel *Label1; 248 micSlider-> setTickInterval ( 20 );
120 Label1 = new QLabel( this, "Label1" ); 249 micSlider-> setFocusPolicy ( QWidget::NoFocus );
121 Label1->setText( tr( "Enable Sounds for:" )); 250
122 251 l = new QLabel ( this );
123 alarmSound = new QCheckBox( tr("Alarm Sound"), this ); 252 l-> setPixmap ( QPixmap ( mic_xpm ));
124 alarmSound->setFocusPolicy( QWidget::NoFocus ); 253
125 254 grid-> addWidget ( l, 0, 2, AlignCenter );
126 keyclicks = new QCheckBox( tr("Key Clicks"), this ); 255 grid-> addWidget ( micSlider, 1, 2, AlignCenter );
127 keyclicks->setFocusPolicy( QWidget::NoFocus ); 256
128 257 micLed = new OLedBox ( red, this );
129 screentaps = new QCheckBox( tr("Screen taps"), this ); 258 micLed-> setFocusPolicy ( QWidget::NoFocus );
130 screentaps->setFocusPolicy( QWidget::NoFocus ); 259 micLed-> setFixedSize ( 16, 16 );
131 260
132 261 grid-> addWidget ( micLed, 2, 2, AlignCenter );
133 keyclicks->setChecked( cfg.readBoolEntry("KeySound",0)); 262
134 screentaps->setChecked( cfg.readBoolEntry("TouchSound",0)); 263 alarmSlider = new QSlider ( this );
135 alarmSound->setChecked( cfg.readBoolEntry("AlarmSound",1)); 264 alarmSlider-> setRange ( 0, 100 );
136 265 alarmSlider-> setTickmarks ( QSlider::Both );
137 klbox->setMargin( 3 ); 266 alarmSlider-> setTickInterval ( 20 );
138 klbox->setSpacing( 0 ); 267 alarmSlider-> setFocusPolicy ( QWidget::NoFocus );
139 klbox->addWidget( Label1, 1); 268
140 klbox->addWidget( alarmSound, 1); 269 QLabel *alarmLabel = new QLabel ( this );
141 klbox->addWidget( keyclicks, 1); 270 alarmLabel-> setPixmap ( QPixmap ( alarm_xpm ));
142 klbox->addWidget( screentaps, 1); 271
143 vbox->setMargin( 3 ); 272 grid-> addWidget ( alarmLabel, 0, 3, AlignCenter );
144 vbox->setSpacing( 0 ); 273 grid-> addWidget ( alarmSlider, 1, 3, AlignCenter );
145// if (showMic == TRUE) 274
146 vbox->addLayout( hbox, 1 ); 275 alarmLed = new OLedBox ( yellow, this );
147// else 276 alarmLed-> setFocusPolicy ( QWidget::NoFocus );
148// vbox->addLayout( sbox, 1); 277 alarmLed-> setFixedSize ( 16, 16 );
149 vbox->addWidget( muteBox, 0, Qt::AlignVCenter | Qt::AlignHCenter ); 278
150 279 grid-> addWidget ( alarmLed, 2, 3, AlignCenter );
151 hboxLayout->addLayout( vboxButtons ); 280
152 hboxLayout->addLayout( vbox); 281 if ( !has_wav_alarm ) {
153 hboxLayout->addLayout( klbox); 282 alarmSlider-> hide ( );
154 283 alarmLabel-> hide ( );
155 284 alarmLed-> hide ( );
156 setFixedHeight( 120); 285 }
157// setFixedWidth( sizeHint().width() ); 286
158 setFocusPolicy(QWidget::NoFocus); 287 grid-> addWidget ( new QLabel ( tr( "Enable Sounds for:" ), this ), 0, 4, AlignVCenter | AlignLeft );
159 connect( upButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); 288
160 connect( upButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) ); 289 vbox = new QVBoxLayout ( );
161 connect( downButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); 290 vbox-> setSpacing ( 4 );
162 connect( downButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) ); 291 grid-> addMultiCellLayout ( vbox, 1, 2, 4, 4 );
163 292
164 rateTimer = new QTimer(this); 293 tapBox = new QCheckBox ( tr( "Screen Taps" ), this );
165 connect( rateTimer, SIGNAL( timeout() ), this, SLOT( rateTimerDone() ) ); 294 tapBox-> setFocusPolicy ( QWidget::NoFocus );
295
296 vbox-> addWidget ( tapBox, AlignVCenter | AlignLeft );
297
298 keyBox = new QCheckBox ( tr( "Key Clicks" ), this );
299 keyBox-> setFocusPolicy ( QWidget::NoFocus );
300
301 vbox-> addWidget ( keyBox, AlignVCenter | AlignLeft );
302
303 alarmBox = new QCheckBox ( tr( "Alarm Sound" ), this );
304 alarmBox-> setFocusPolicy ( QWidget::NoFocus );
305
306 vbox-> addWidget ( alarmBox, AlignVCenter | AlignLeft );
307
308 if ( has_wav_alarm ) {
309 alarmBox-> hide ( );
310 }
311
312 vbox-> addStretch ( 100 );
313
314 setFixedSize ( sizeHint ( ));
315 setFocusPolicy ( QWidget::NoFocus );
316
317 rateTimer = new QTimer( this );
318 connect ( rateTimer, SIGNAL( timeout ( )), this, SLOT( rateTimerDone ( )));
319
320 connect ( upButton, SIGNAL( pressed ( )), this, SLOT( buttonChanged ( )));
321 connect ( upButton, SIGNAL( released ( )), this, SLOT( buttonChanged ( )));
322 connect ( downButton, SIGNAL( pressed ( )), this, SLOT( buttonChanged ( )));
323 connect ( downButton, SIGNAL( released ( )), this, SLOT( buttonChanged ( )));
324
325 connect ( micSlider, SIGNAL( valueChanged ( int )), this, SLOT( micMoved( int )));
326 connect ( volSlider, SIGNAL( valueChanged ( int )), this, SLOT( volMoved( int )));
327 connect ( alarmSlider, SIGNAL( valueChanged ( int )), this, SLOT( alarmMoved( int )));
328
329 connect ( volLed, SIGNAL( toggled ( bool )), this, SLOT( volMuteToggled ( bool )));
330 connect ( micLed, SIGNAL( toggled ( bool )), this, SLOT( micMuteToggled ( bool )));
331 connect ( alarmLed, SIGNAL( toggled ( bool )), this, SLOT( alarmSoundToggled ( bool )));
332
333 connect ( alarmBox, SIGNAL( toggled ( bool )), this, SLOT( alarmSoundToggled ( bool )));
334 connect ( keyBox, SIGNAL( toggled ( bool )), this, SLOT( keyClickToggled ( bool )));
335 connect ( tapBox, SIGNAL( toggled ( bool )), this, SLOT( screenTapToggled ( bool )));
336
337 // initialize variables
338
339 readConfig ( true );
340
341 // initialize the config file, in case some entries are missing
342
343 writeConfigEntry ( "VolumePercent", m_vol_percent, UPD_None );
344 writeConfigEntry ( "Mute", m_vol_muted, UPD_None );
345 writeConfigEntry ( "AlarmPercent", m_alarm_percent, UPD_None );
346 writeConfigEntry ( "TouchSound", m_snd_touch, UPD_None );
347 writeConfigEntry ( "KeySound", m_snd_key, UPD_None );
348 writeConfigEntry ( "AlarmSound", m_snd_alarm, UPD_Vol );
349
350 writeConfigEntry ( "Mic", m_mic_percent, UPD_None );
351 writeConfigEntry ( "MicMute", m_mic_muted, UPD_Mic );
166} 352}
167 353
168void VolumeControl::keyPressEvent( QKeyEvent *e) 354bool VolumeControl::volMuted ( ) const
169{ 355{
170 switch(e->key()) 356 return m_vol_muted;
171 {
172 case Key_Up:
173 slider->subtractStep();
174 break;
175 case Key_Down:
176 slider->addStep();
177 break;
178 case Key_Space:
179 muteBox->toggle();
180 break;
181 case Key_Escape:
182 close();
183 break;
184 }
185} 357}
186 358
187void VolumeControl::ButtonChanged() 359int VolumeControl::volPercent ( ) const
188{ 360{
189 if ( upButton->isDown() || downButton->isDown() ) 361 return m_vol_percent;
190 {
191 rateTimerDone(); // Call it one time manually, otherwise it wont get
192 // called at all when a button is pressed for a time
193 // shorter than RATE_TIMER_INTERVAL.
194 rateTimer->start( RATE_TIMER_INTERVAL, false );
195 }
196 else
197 rateTimer->stop();
198} 362}
199 363
200void VolumeControl::rateTimerDone() 364void VolumeControl::keyPressEvent ( QKeyEvent *e )
201{ 365{
202 if ( upButton->isDown() ) 366 switch ( e-> key ( )) {
203 slider->setValue( slider->value() - 2 ); 367 case Key_Up:
204 else // downButton->isDown() 368 volSlider-> subtractStep ( );
205 slider->setValue( slider->value() + 2 ); 369 break;
370 case Key_Down:
371 volSlider-> addStep ( );
372 break;
373 case Key_Space:
374 volLed-> toggle ( );
375 break;
376 case Key_Escape:
377 hide ( );
378 break;
379 }
206} 380}
207 381
208//=========================================================================== 382void VolumeControl::buttonChanged ( )
209
210VolumeApplet::VolumeApplet( QWidget *parent, const char *name )
211 : QWidget( parent, name )
212{ 383{
213 Config cfg("qpe"); 384 if ( upButton-> isDown ( ) || downButton->isDown ( )) {
214 cfg.setGroup("Volume"); 385 rateTimerDone ( ); // Call it one time manually, otherwise it wont get
215 386 // called at all when a button is pressed for a time
216 setFixedHeight( 18 ); 387 // shorter than RATE_TIMER_INTERVAL.
217 setFixedWidth( 14 ); 388 rateTimer-> start ( RATE_TIMER_INTERVAL, false );
218 389 }
219 volumePixmap = Resource::loadPixmap( "volume" ); 390 else
220 391 rateTimer-> stop ( );
221 volumePercent = cfg.readNumEntry("VolumePercent",50);
222 micPercent = cfg.readNumEntry("Mic", 50);
223 muted = FALSE; // ### read from pref
224 micMuted = FALSE; // ### read from pref
225
226 advancedTimer = new QTimer(this);
227
228 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
229 connect( qApp, SIGNAL( micChanged(bool) ), this, SLOT ( micChanged(bool) ) );
230 connect( advancedTimer, SIGNAL( timeout() ),this, SLOT( advVolControl()) );
231
232 writeSystemVolume();
233 writeSystemMic();
234} 392}
235 393
236VolumeApplet::~VolumeApplet() 394void VolumeControl::rateTimerDone ( )
237{ 395{
396 if ( upButton-> isDown ( ))
397 volSlider-> setValue ( volSlider-> value ( ) - 2 );
398 else // if ( downButton-> isDown ( ))
399 volSlider-> setValue ( volSlider-> value ( ) + 2 );
238} 400}
239 401
240void VolumeApplet::keyPressEvent ( QKeyEvent * e ) 402void VolumeControl::show ( bool /*showMic*/ )
241{
242 QString s;
243 s.setNum(e->key());
244 qWarning(s);
245}
246void VolumeApplet::mousePressEvent( QMouseEvent * )
247{ 403{
248 advancedTimer->start( 750, TRUE ); 404 readConfig ( );
249} 405
406 QPoint curPos = m_icon-> mapToGlobal ( QPoint ( 0, 0 ));
407 printf ( "SHOW AT : %d/%d\n", curPos.x(), curPos.y());
408 printf ( "SIZEHINT: %d/%d\n", sizeHint().width(),sizeHint().height());
409
410 int w = sizeHint ( ). width ( );
411 int x = curPos.x ( ) - ( w / 2 );
412
413 if (( x + w ) > QPEApplication::desktop ( )-> width ( ))
414 x = QPEApplication::desktop ( )-> width ( ) - w;
415
416
417 move ( x, curPos. y ( ) - sizeHint ( ). height ( ));
418 QFrame::show ( );
250 419
251void VolumeApplet::mouseReleaseEvent( QMouseEvent * )
252{
253 showVolControl(FALSE);
254} 420}
255 421
256void VolumeApplet::advVolControl() 422void VolumeControl::readConfig ( bool force )
257{ 423{
258 showVolControl(TRUE); 424 Config cfg ( "qpe" );
425 cfg. setGroup ( "Volume" );
426
427 int old_vp = m_vol_percent;
428 int old_mp = m_mic_percent;
429 bool old_vm = m_vol_muted;
430 bool old_mm = m_mic_muted;
431 bool old_sk = m_snd_key;
432 bool old_st = m_snd_touch;
433 bool old_sa = m_snd_alarm;
434 int old_ap = m_alarm_percent;
435
436 m_vol_percent = cfg. readNumEntry ( "VolumePercent", 50 );
437 m_mic_percent = cfg. readNumEntry ( "Mic", 50 );
438 m_vol_muted = cfg. readBoolEntry ( "Mute", 0 );
439 m_mic_muted = cfg. readBoolEntry ( "MicMute", 0 );
440 m_snd_key = cfg. readBoolEntry ( "KeySound", 0 );
441 m_snd_touch = cfg. readBoolEntry ( "TouchSound", 0 );
442 m_snd_alarm = cfg. readBoolEntry ( "AlarmSound", 1 );
443 m_alarm_percent = cfg. readNumEntry ( "AlarmPercent", 65 );
444
445 if ( force || ( m_vol_percent != old_vp ))
446 volSlider-> setValue ( 100 - m_vol_percent );
447 if ( force || ( m_mic_percent != old_mp ))
448 micSlider-> setValue ( 100 - m_mic_percent );
449 if ( force || ( m_alarm_percent != old_ap ))
450 alarmSlider-> setValue ( 100 - m_alarm_percent );
451
452 if ( force || ( m_vol_muted != old_vm ))
453 volLed-> setOn ( !m_vol_muted );
454 if ( force || ( m_mic_muted != old_mm ))
455 micLed-> setOn ( !m_mic_muted );
456 if ( force || ( m_snd_alarm != old_sa ))
457 alarmLed-> setOn ( m_snd_alarm );
458
459 if ( force || ( m_snd_key != old_sk ))
460 keyBox-> setChecked ( m_snd_key );
461 if ( force || ( m_snd_touch != old_st ))
462 tapBox-> setChecked ( m_snd_touch );
463 if ( force || ( m_snd_alarm != old_sa ))
464 alarmBox-> setChecked ( m_snd_alarm );
259} 465}
260 466
261void VolumeApplet::showVolControl(bool showMic)
262{
263 Config cfg("qpe");
264 cfg.setGroup("Volume");
265 volumePercent = cfg.readNumEntry("VolumePercent",50);
266 micPercent = cfg.readNumEntry("Mic", 50);
267
268 // Create a small volume control window to adjust the volume with
269 VolumeControl *vc = new VolumeControl(showMic);
270 vc->slider->setValue( 100 - volumePercent );
271// if (showMic)
272// {
273 vc->mic->setValue( 100 - micPercent );
274 connect( vc->mic, SIGNAL( valueChanged( int ) ), this, SLOT( micMoved( int ) ) );
275// }
276
277 vc->muteBox->setChecked( muted );
278 connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) );
279 connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) );
280
281 Config config("qpe");
282 config.setGroup("Volume");
283
284 vc->keyclicks->setChecked( config.readBoolEntry("KeySound",0));
285 vc->screentaps->setChecked( config.readBoolEntry("TouchSound",0));
286 vc->alarmSound->setChecked( config.readBoolEntry("AlarmSound",1));
287
288 connect( vc->alarmSound, SIGNAL(toggled(bool)), this, SLOT( alarmSoundCheckToggled(bool)));
289 connect( vc->keyclicks, SIGNAL(toggled(bool)), this, SLOT( keyclicksCheckToggled(bool)));
290 connect( vc->screentaps, SIGNAL(toggled(bool)), this, SLOT( screentapsCheckToggled(bool)));
291
292 QPoint curPos = mapToGlobal( rect().topLeft() );
293 vc->move( curPos.x()-(vc->sizeHint().width()/2+50), curPos.y() - 120 );
294 vc->show();
295
296 advancedTimer->stop();
297}
298 467
299void VolumeApplet::volumeChanged( bool nowMuted ) 468void VolumeControl::volumeChanged ( bool nowMuted )
300{ 469{
301 int previousVolume = volumePercent; 470 int previousVolume = m_vol_percent;
302 471
303 if ( !nowMuted ) 472 if ( !nowMuted )
304 readSystemVolume(); 473 readConfig ( );
305 474
306 // Handle case where muting it toggled 475 // Handle case where muting it toggled
307 if ( muted != nowMuted ) { 476 if ( m_vol_muted != nowMuted ) {
308 muted = nowMuted; 477 m_vol_muted = nowMuted;
309 repaint( TRUE ); 478 m_icon-> repaint ( true );
310 return; 479 }
311 } 480 else if ( previousVolume != m_vol_percent ) {
481 // Avoid over repainting
482 m_icon-> repaint( 2, height ( ) - 3, width ( ) - 4, 2, false );
483 }
312 484
313 // Avoid over repainting
314 if ( previousVolume != volumePercent )
315 repaint( 2, height() - 3, width() - 4, 2, FALSE );
316} 485}
317 486
318void VolumeApplet::micChanged( bool nowMuted ) 487void VolumeControl::micChanged ( bool nowMuted )
319{ 488{
320 if (!nowMuted) 489 if ( !nowMuted )
321 readSystemMic(); 490 readConfig ( );
322 micMuted = nowMuted; 491 m_mic_muted = nowMuted;
323} 492}
324 493
325void VolumeApplet::mute( bool toggled ) 494void VolumeControl::screenTapToggled ( bool b )
326{ 495{
327 muted = toggled; 496 m_snd_touch = b;
328 497 writeConfigEntry ( "TouchSound", m_snd_touch, UPD_Vol );
329 // clear if removing mute
330 repaint( !toggled );
331 writeSystemVolume();
332 Config cfg("qpe");
333 cfg.setGroup("Volume");
334 if(muted)
335 cfg.writeEntry("Mute", "TRUE");
336 else
337 cfg.writeEntry("Mute", "FALSE");
338 cfg.write();
339} 498}
340 499
341 500void VolumeControl::keyClickToggled ( bool b )
342void VolumeApplet::sliderMoved( int percent )
343{ 501{
344 setVolume( 100 - percent ); 502 m_snd_key = b;
503 writeConfigEntry ( "KeySound", m_snd_key, UPD_Vol );
345} 504}
346 505
347void VolumeApplet::micMoved( int percent ) 506void VolumeControl::alarmSoundToggled ( bool b )
348{ 507{
349 setMic( 100 - percent ); 508 m_snd_alarm = b;
509 writeConfigEntry ( "AlarmSound", m_snd_alarm, UPD_Vol );
350} 510}
351 511
352void VolumeApplet::readSystemVolume() 512void VolumeControl::volMuteToggled ( bool b )
353{ 513{
354 Config cfg("qpe"); 514 m_vol_muted = !b;
355 cfg.setGroup("Volume"); 515
356 volumePercent = cfg.readNumEntry("VolumePercent"); 516 m_icon-> repaint ( !m_vol_muted ); // clear if removing mute
517
518 writeConfigEntry ( "Mute", m_vol_muted, UPD_Vol );
357} 519}
358 520
359void VolumeApplet::readSystemMic() 521void VolumeControl::micMuteToggled ( bool b )
360{ 522{
361 Config cfg("qpe"); 523 m_mic_muted = !b;
362 cfg.setGroup("Volume"); 524 writeConfigEntry ( "MicMute", m_mic_muted, UPD_Mic );
363 micPercent = cfg.readNumEntry("Mic");
364} 525}
365 526
366void VolumeApplet::setVolume( int percent ) 527
528void VolumeControl::volMoved ( int percent )
367{ 529{
368 // clamp volume percent to be between 0 and 100 530 m_vol_percent = 100 - percent;
369 volumePercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent); 531
370 // repaint just the little volume rectangle 532 // clamp volume percent to be between 0 and 100
371 repaint( 2, height() - 3, width() - 4, 2, FALSE ); 533 m_vol_percent = ( m_vol_percent < 0 ) ? 0 : (( m_vol_percent > 100 ) ? 100 : m_vol_percent );
372 writeSystemVolume(); 534 // repaint just the little volume rectangle
535 repaint ( 2, height ( ) - 3, width ( ) - 4, 2, false );
536
537 writeConfigEntry ( "VolumePercent", m_vol_percent, UPD_Vol );
373} 538}
374 539
375void VolumeApplet::setMic( int percent ) 540void VolumeControl::micMoved ( int percent )
376{ 541{
377 // clamp volume percent to be between 0 and 100 542 m_mic_percent = 100 - percent;
378 micPercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent); 543
379 writeSystemMic(); 544 // clamp volume percent to be between 0 and 100
545 m_mic_percent = ( m_mic_percent < 0 ) ? 0 : (( m_mic_percent > 100 ) ? 100 : m_mic_percent );
546
547 writeConfigEntry ( "Mic", m_mic_percent, UPD_Mic );
380} 548}
381 549
382void VolumeApplet::writeSystemVolume() 550void VolumeControl::alarmMoved ( int percent )
383{ 551{
384 { 552 m_alarm_percent = 100 - percent;
385 Config cfg("qpe"); 553
386 cfg.setGroup("Volume"); 554 // clamp volume percent to be between 0 and 100
387 cfg.writeEntry("VolumePercent",volumePercent); 555 m_alarm_percent = ( m_alarm_percent < 0 ) ? 0 : (( m_alarm_percent > 100 ) ? 100 : m_alarm_percent );
388 } 556
389#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 557 writeConfigEntry ( "AlarmPercent", m_alarm_percent, UPD_None );
390 // Send notification that the volume has changed
391 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
392#endif
393} 558}
394 559
395void VolumeApplet::writeSystemMic() 560
561void VolumeControl::writeConfigEntry ( const char *entry, int val, eUpdate upd )
396{ 562{
397 { 563 Config cfg ( "qpe" );
398 Config cfg("qpe"); 564 cfg. setGroup ( "Volume" );
399 cfg.setGroup("Volume"); 565 cfg. writeEntry ( entry, val );
400 cfg.writeEntry("Mic",micPercent); 566 //cfg. write ( );
401 } 567
402#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 568#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
403 // Send notification that the volume has changed 569 switch ( upd ) {
404 QCopEnvelope( "QPE/System", "micChange(bool)" ) << micMuted; 570 case UPD_Vol: {
571 QCopEnvelope ( "QPE/System", "volumeChange(bool)" ) << m_vol_muted;
572 break;
573 }
574 case UPD_Mic: {
575 QCopEnvelope ( "QPE/System", "micChange(bool)" ) << m_mic_muted;
576 break;
577 }
578 case UPD_None:
579 break;
580 }
405#endif 581#endif
406} 582}
407 583
408void VolumeApplet::paintEvent( QPaintEvent* ) 584//===========================================================================
585
586VolumeApplet::VolumeApplet( QWidget *parent, const char *name )
587 : QWidget( parent, name )
409{ 588{
410 QPainter p(this); 589 setFixedHeight ( 18 );
411 590 setFixedWidth ( 14 );
412 if (volumePixmap.isNull()) 591
413 volumePixmap = Resource::loadPixmap( "volume" ); 592 m_pixmap = new QPixmap ( Resource::loadPixmap ( "volume" ));
414 p.drawPixmap( 0, 1, volumePixmap ); 593 m_dialog = new VolumeControl ( this );
415 p.setPen( darkGray ); 594
416 p.drawRect( 1, height() - 4, width() - 2, 4 ); 595 connect ( qApp, SIGNAL( volumeChanged ( bool )), m_dialog, SLOT( volumeChanged( bool )));
417 596 connect ( qApp, SIGNAL( micChanged ( bool )), m_dialog, SLOT ( micChanged( bool )));
418 int pixelsWide = volumePercent * (width() - 4) / 100;
419 p.fillRect( 2, height() - 3, pixelsWide, 2, red );
420 p.fillRect( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray );
421
422 if ( muted ) {
423 p.setPen( red );
424 p.drawLine( 1, 2, width() - 2, height() - 5 );
425 p.drawLine( 1, 3, width() - 2, height() - 4 );
426 p.drawLine( width() - 2, 2, 1, height() - 5 );
427 p.drawLine( width() - 2, 3, 1, height() - 4 );
428 }
429} 597}
430 598
431void VolumeApplet::screentapsCheckToggled(bool b) { 599VolumeApplet::~VolumeApplet()
432 Config cfg("qpe"); 600{
433 cfg.setGroup("Volume"); 601 delete m_pixmap;
434 cfg.writeEntry("TouchSound",b );
435 cfg.write();
436} 602}
437 603
438void VolumeApplet::keyclicksCheckToggled(bool b) { 604
439 Config cfg("qpe"); 605void VolumeApplet::mousePressEvent ( QMouseEvent * )
440 cfg.setGroup("Volume"); 606{
441 cfg.writeEntry("KeySound",b); 607 if ( m_dialog-> isVisible ( ))
442 cfg.write(); 608 m_dialog-> hide ( );
609 else
610 m_dialog-> show ( true );
443} 611}
444 612
445void VolumeApplet::alarmSoundCheckToggled(bool b) { 613
446 Config cfg("qpe"); 614void VolumeApplet::paintEvent ( QPaintEvent * )
447 cfg.setGroup("Volume"); 615{
448 cfg.writeEntry("AlarmSound",b); 616 QPainter p ( this );
449 cfg.write(); 617
618 p. drawPixmap ( 0, 1, *m_pixmap );
619 p. setPen ( darkGray );
620 p. drawRect ( 1, height() - 4, width() - 2, 4 );
621
622 int pixelsWide = m_dialog-> volPercent ( ) * ( width() - 4 ) / 100;
623 p. fillRect ( 2, height() - 3, pixelsWide, 2, red );
624 p. fillRect ( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray );
625
626 if ( m_dialog-> volMuted ( )) {
627 p. setPen ( red );
628 p. drawLine ( 1, 2, width() - 2, height() - 5 );
629 p. drawLine ( 1, 3, width() - 2, height() - 4 );
630 p. drawLine ( width() - 2, 2, 1, height() - 5 );
631 p. drawLine ( width() - 2, 3, 1, height() - 4 );
632 }
450} 633}
451 634
635
diff --git a/core/applets/volumeapplet/volume.h b/core/applets/volumeapplet/volume.h
index 6e631f2..ff5c64a 100644
--- a/core/applets/volumeapplet/volume.h
+++ b/core/applets/volumeapplet/volume.h
@@ -22,85 +22,101 @@
22#define __VOLUME_APPLET_H__ 22#define __VOLUME_APPLET_H__
23 23
24 24
25#include <qwidget.h>
26#include <qframe.h> 25#include <qframe.h>
27#include <qpixmap.h>
28#include <qguardedptr.h>
29#include <qtimer.h>
30 26
27class QPixmap;
28class QTimer;
31class QSlider; 29class QSlider;
32class QCheckBox; 30class QCheckBox;
31class QButton;
32class OLedBox;
33 33
34class VolumeControl : public QFrame 34class VolumeApplet;
35{
36 Q_OBJECT
37public:
38 VolumeControl( bool showMic=FALSE, QWidget *parent=0, const char *name=0 );
39 35
36class VolumeControl : public QFrame {
37 Q_OBJECT
38
40public: 39public:
41 QSlider *slider; 40 VolumeControl ( VolumeApplet *icon, bool showMic = false, QWidget *parent=0, const char *name=0 );
42 QSlider *mic;
43 QCheckBox *muteBox;
44 QCheckBox *alarmSound;
45 QCheckBox *screentaps;
46 QCheckBox *keyclicks;
47 41
42 bool volMuted ( ) const;
43 int volPercent ( ) const;
48 44
49private: 45 virtual void show ( bool showmic );
50 QPushButton *upButton;
51 QPushButton *downButton;
52 QTimer *rateTimer;
53
54 void keyPressEvent( QKeyEvent * );
55 void createView(bool showMic = FALSE);
56private slots:
57 void ButtonChanged();
58 void rateTimerDone();
59
60};
61 46
62class VolumeApplet : public QWidget 47protected:
63{ 48 virtual void keyPressEvent ( QKeyEvent * e );
64 Q_OBJECT 49
65public: 50protected slots:
66 VolumeApplet( QWidget *parent = 0, const char *name=0 ); 51 void volumeChanged ( bool muted );
67 ~VolumeApplet(); 52 void micChanged ( bool muted );
68 bool isMute( ) { return muted; } 53
69 int percent( ) { return volumePercent; } 54private slots:
70 55 void volMoved ( int percent );
71public slots: 56 void micMoved ( int percent );
72 void volumeChanged( bool muted ); 57 void alarmMoved ( int percent );
73 void micChanged( bool muted ); 58
74 void sliderMoved( int percent ); 59 void volMuteToggled ( bool );
75 void mute( bool ); 60 void micMuteToggled ( bool );
61 void alarmSoundToggled ( bool );
62 void keyClickToggled ( bool );
63 void screenTapToggled ( bool );
64
65 void buttonChanged ( );
66 void rateTimerDone ( );
67
68private:
69 void readConfig ( bool force = false );
76 70
77 void micMoved( int percent ); 71 enum eUpdate {
78 void setVolume( int percent ); 72 UPD_None,
79 void setMic( int percent ); 73 UPD_Vol,
74 UPD_Mic
75 };
76 void writeConfigEntry ( const char *entry, int val, eUpdate upd );
80 77
81 void showVolControl(bool showMic = FALSE);
82 void advVolControl();
83 78
84private: 79private:
85 int volumePercent, micPercent; 80 QSlider *volSlider;
86 bool muted, micMuted; 81 QSlider *micSlider;
87 QPixmap volumePixmap; 82 QSlider *alarmSlider;
88 QTimer *advancedTimer; 83 OLedBox *volLed;
84 OLedBox *micLed;
85 OLedBox *alarmLed;
86
87 QCheckBox *alarmBox;
88 QCheckBox *tapBox;
89 QCheckBox *keyBox;
90 QPushButton *upButton;
91 QPushButton *downButton;
92 QTimer *rateTimer;
93
94 int m_vol_percent;
95 int m_mic_percent;
96 int m_alarm_percent;
97 bool m_vol_muted;
98 bool m_mic_muted;
99 bool m_snd_alarm;
100 bool m_snd_touch;
101 bool m_snd_key;
102
103 VolumeApplet *m_icon;
104};
89 105
90 void readSystemVolume(); 106class VolumeApplet : public QWidget {
91 void writeSystemVolume(); 107 Q_OBJECT
92 void mousePressEvent( QMouseEvent * );
93 void paintEvent( QPaintEvent* );
94 108
95 void readSystemMic(); 109public:
96 void keyPressEvent ( QKeyEvent * e ); 110 VolumeApplet ( QWidget *parent = 0, const char *name=0 );
97 void mouseReleaseEvent( QMouseEvent *); 111 ~VolumeApplet ( );
98 void writeSystemMic();
99 112
100protected slots: 113protected:
101 void alarmSoundCheckToggled(bool); 114 virtual void mousePressEvent ( QMouseEvent * );
102 void keyclicksCheckToggled(bool); 115 virtual void paintEvent ( QPaintEvent* );
103 void screentapsCheckToggled(bool); 116
117private:
118 QPixmap * m_pixmap;
119 VolumeControl *m_dialog;
104}; 120};
105 121
106 122
diff --git a/core/applets/volumeapplet/volumeapplet.pro b/core/applets/volumeapplet/volumeapplet.pro
index f89eea2..937a537 100644
--- a/core/applets/volumeapplet/volumeapplet.pro
+++ b/core/applets/volumeapplet/volumeapplet.pro
@@ -1,7 +1,7 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2 CONFIG += qt warn_on release 2 CONFIG += qt warn_on release
3 HEADERS= volume.h volumeappletimpl.h 3 HEADERS= volume.h volumeappletimpl.h oledbox.h
4 SOURCES= volume.cpp volumeappletimpl.cpp 4 SOURCES= volume.cpp volumeappletimpl.cpp oledbox.cpp
5 TARGET = volumeapplet 5 TARGET = volumeapplet
6 DESTDIR = $(OPIEDIR)/plugins/applets 6 DESTDIR = $(OPIEDIR)/plugins/applets
7INCLUDEPATH += $(OPIEDIR)/include 7INCLUDEPATH += $(OPIEDIR)/include
diff --git a/core/applets/volumeapplet/volumeappletimpl.cpp b/core/applets/volumeapplet/volumeappletimpl.cpp
index 943e71a..47506cc 100644
--- a/core/applets/volumeapplet/volumeappletimpl.cpp
+++ b/core/applets/volumeapplet/volumeappletimpl.cpp
@@ -29,41 +29,32 @@ VolumeAppletImpl::VolumeAppletImpl()
29 29
30VolumeAppletImpl::~VolumeAppletImpl() 30VolumeAppletImpl::~VolumeAppletImpl()
31{ 31{
32 delete volume; 32 delete volume;
33} 33}
34 34
35QWidget *VolumeAppletImpl::applet( QWidget *parent ) 35QWidget *VolumeAppletImpl::applet( QWidget *parent )
36{ 36{
37 if ( !volume ) 37 if ( !volume )
38 volume = new VolumeApplet( parent ); 38 volume = new VolumeApplet( parent );
39 39 return volume;
40 Config cfg("qpe");
41 cfg.setGroup("Volume");
42 QString foo = cfg.readEntry("Mute","TRUE");
43 bool muted;
44 if(foo.find("TRUE",0,TRUE) != -1)
45 muted = TRUE;
46 else muted = FALSE;
47 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; //mute
48 return volume;
49} 40}
50 41
51int VolumeAppletImpl::position() const 42int VolumeAppletImpl::position() const
52{ 43{
53 return 6; 44 return 6;
54} 45}
55 46
56QRESULT VolumeAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) 47QRESULT VolumeAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
57{ 48{
58 *iface = 0; 49 *iface = 0;
59 if ( uuid == IID_QUnknown ) 50 if ( uuid == IID_QUnknown )
60 *iface = this; 51 *iface = this;
61 else if ( uuid == IID_TaskbarApplet ) 52 else if ( uuid == IID_TaskbarApplet )
62 *iface = this; 53 *iface = this;
63 54
64 if ( *iface ) 55 if ( *iface )
65 (*iface)->addRef(); 56 (*iface)->addRef();
66 return QS_OK; 57 return QS_OK;
67} 58}
68 59
69Q_EXPORT_INTERFACE() 60Q_EXPORT_INTERFACE()