Diffstat (limited to 'core/applets/volumeapplet/volume.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/applets/volumeapplet/volume.cpp | 744 |
1 files changed, 464 insertions, 280 deletions
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 | |||
@@ -15,12 +15,13 @@ | |||
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <stdio.h> | ||
21 | 22 | ||
22 | #include "volume.h" | 23 | #include "volume.h" |
23 | 24 | ||
24 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
25 | #include <qpe/qpeapplication.h> | 26 | #include <qpe/qpeapplication.h> |
26 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
@@ -33,419 +34,602 @@ | |||
33 | #include <qslider.h> | 34 | #include <qslider.h> |
34 | #include <qlayout.h> | 35 | #include <qlayout.h> |
35 | #include <qframe.h> | 36 | #include <qframe.h> |
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 | ||
44 | #include <opie/odevice.h> | ||
45 | |||
46 | #include "oledbox.h" | ||
47 | |||
42 | #define RATE_TIMER_INTERVAL 100 | 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 | ||
46 | VolumeControl::VolumeControl( bool showMic, QWidget *parent, const char *name ) | 52 | |
47 | : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) | 53 | /* XPM */ |
54 | static 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 */ | ||
80 | static 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 */ | ||
125 | static 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 | |||
181 | VolumeControl::VolumeControl ( VolumeApplet *icon, bool /*showMic*/, QWidget *parent, const char *name ) | ||
182 | : QFrame ( parent, name, WStyle_StaysOnTop | WType_Popup ) | ||
48 | { | 183 | { |
49 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 184 | m_icon = icon; |
50 | createView(showMic); | 185 | |
186 | bool has_wav_alarm = false; | ||
187 | |||
188 | switch ( ODevice::inst ( )-> model ( )) { | ||
189 | case OMODEL_iPAQ_H31xx: | ||
190 | case OMODEL_iPAQ_H36xx: | ||
191 | case OMODEL_iPAQ_H37xx: | ||
192 | case OMODEL_iPAQ_H38xx: | ||
193 | has_wav_alarm = true; | ||
194 | break; | ||
195 | default: | ||
196 | break; | ||
51 | } | 197 | } |
52 | 198 | ||
53 | void VolumeControl::createView(bool showMic) | ||
54 | { | ||
55 | Config cfg("qpe"); | ||
56 | cfg.setGroup("Volume"); | ||
57 | //showMic = TRUE; | ||
58 | QHBoxLayout *hboxLayout = new QHBoxLayout(this); | ||
59 | hboxLayout->setMargin( 3 ); | ||
60 | hboxLayout->setSpacing( 0); | ||
61 | 199 | ||
62 | QVBoxLayout *vboxButtons = new QVBoxLayout(this); | 200 | setFrameStyle ( QFrame::PopupPanel | QFrame::Raised ); |
201 | |||
202 | QGridLayout *grid = new QGridLayout ( this, 1, 1, 6, 4 ); | ||
203 | grid-> setSpacing ( 4 ); | ||
204 | grid-> setMargin ( 6 ); | ||
205 | |||
206 | QVBoxLayout *vbox; | ||
207 | QLabel *l; | ||
208 | |||
209 | vbox = new QVBoxLayout ( ); | ||
210 | vbox-> setSpacing ( 4 ); | ||
211 | grid-> addLayout ( vbox, 1, 0 ); | ||
212 | |||
63 | upButton = new QPushButton( this ); | 213 | upButton = new QPushButton( this ); |
64 | upButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); | 214 | upButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); |
65 | upButton->setPixmap( Resource::loadPixmap( "up" ) ); | 215 | upButton->setPixmap( Resource::loadPixmap( "up" ) ); |
216 | upButton-> setFocusPolicy ( QWidget::NoFocus ); | ||
217 | |||
218 | vbox-> addWidget ( upButton ); | ||
219 | |||
66 | downButton = new QPushButton( this ); | 220 | downButton = new QPushButton( this ); |
67 | downButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); | 221 | downButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); |
68 | downButton->setPixmap( Resource::loadPixmap( "down" ) ); | 222 | downButton->setPixmap( Resource::loadPixmap( "down" ) ); |
69 | vboxButtons->setSpacing( 2 ); | 223 | downButton-> setFocusPolicy ( QWidget::NoFocus ); |
70 | 224 | ||
71 | upButton->setFixedHeight(26); | 225 | vbox-> addWidget ( downButton ); |
72 | downButton->setFixedHeight(26); | 226 | |
73 | 227 | volSlider = new QSlider ( this ); | |
74 | vboxButtons->addWidget( upButton ); | 228 | volSlider-> setRange ( 0, 100 ); |
75 | vboxButtons->addWidget( downButton ); | 229 | volSlider-> setTickmarks ( QSlider::Both ); |
76 | 230 | volSlider-> setTickInterval ( 20 ); | |
77 | QVBoxLayout *vbox = new QVBoxLayout( this ); | 231 | volSlider-> setFocusPolicy ( QWidget::NoFocus ); |
78 | QHBoxLayout *hbox = NULL; | 232 | |
79 | 233 | l = new QLabel ( this ); | |
80 | slider = new QSlider( this ); | 234 | l-> setPixmap ( QPixmap ( vol_xpm )); |
81 | slider->setRange( 0, 100 ); | 235 | |
82 | slider->setTickmarks( QSlider::Both ); | 236 | grid-> addWidget ( l, 0, 1, AlignCenter ); |
83 | slider->setTickInterval( 20 ); | 237 | grid-> addWidget ( volSlider, 1, 1, AlignCenter ); |
84 | slider->setFocusPolicy( QWidget::NoFocus ); | 238 | |
85 | slider->setValue(cfg.readNumEntry("VolumePercent")); | 239 | volLed = new OLedBox ( green, this ); |
86 | 240 | volLed-> setFocusPolicy ( QWidget::NoFocus ); | |
87 | QVBoxLayout *sbox = new QVBoxLayout(this); | 241 | volLed-> setFixedSize ( 16, 16 ); |
88 | sbox->setMargin( 3 ); | 242 | |
89 | sbox->setSpacing( 3 ); | 243 | grid-> addWidget ( volLed, 2, 1, AlignCenter ); |
90 | sbox->addWidget( new QLabel("Vol", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter ); | 244 | |
91 | sbox->addWidget( slider, 0, Qt::AlignVCenter | Qt::AlignHCenter ); | 245 | micSlider = new QSlider ( this ); |
92 | 246 | micSlider-> setRange ( 0, 100 ); | |
93 | // if (showMic == TRUE) { | 247 | micSlider-> setTickmarks ( QSlider::Both ); |
94 | mic = new QSlider(this); | 248 | micSlider-> setTickInterval ( 20 ); |
95 | mic->setRange( 0, 100 ); | 249 | micSlider-> setFocusPolicy ( QWidget::NoFocus ); |
96 | mic->setTickmarks( QSlider::Both ); | 250 | |
97 | mic->setTickInterval( 20 ); | 251 | l = new QLabel ( this ); |
98 | mic->setFocusPolicy( QWidget::NoFocus ); | 252 | l-> setPixmap ( QPixmap ( mic_xpm )); |
99 | mic->setValue(cfg.readNumEntry("Mic")); | 253 | |
100 | 254 | grid-> addWidget ( l, 0, 2, AlignCenter ); | |
101 | QVBoxLayout *mbox = new QVBoxLayout(this); | 255 | grid-> addWidget ( micSlider, 1, 2, AlignCenter ); |
102 | mbox->setMargin( 3 ); | 256 | |
103 | mbox->setSpacing( 3 ); | 257 | micLed = new OLedBox ( red, this ); |
104 | mbox->addWidget( new QLabel("Mic", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter ); | 258 | micLed-> setFocusPolicy ( QWidget::NoFocus ); |
105 | mbox->addWidget( mic, 0, Qt::AlignVCenter | Qt::AlignHCenter ); | 259 | micLed-> setFixedSize ( 16, 16 ); |
106 | 260 | ||
107 | hbox = new QHBoxLayout( this ); | 261 | grid-> addWidget ( micLed, 2, 2, AlignCenter ); |
108 | hbox->setMargin( 3 ); | 262 | |
109 | hbox->setSpacing( 3 ); | 263 | alarmSlider = new QSlider ( this ); |
110 | hbox->addLayout( sbox, 1); | 264 | alarmSlider-> setRange ( 0, 100 ); |
111 | hbox->addLayout( mbox, 1); | 265 | alarmSlider-> setTickmarks ( QSlider::Both ); |
112 | // } | 266 | alarmSlider-> setTickInterval ( 20 ); |
113 | 267 | alarmSlider-> setFocusPolicy ( QWidget::NoFocus ); | |
114 | muteBox = new QCheckBox( tr("Mute"), this ); | 268 | |
115 | muteBox->setFocusPolicy( QWidget::NoFocus ); | 269 | QLabel *alarmLabel = new QLabel ( this ); |
116 | 270 | alarmLabel-> setPixmap ( QPixmap ( alarm_xpm )); | |
117 | QVBoxLayout *klbox = new QVBoxLayout(this); | 271 | |
118 | 272 | grid-> addWidget ( alarmLabel, 0, 3, AlignCenter ); | |
119 | QLabel *Label1; | 273 | grid-> addWidget ( alarmSlider, 1, 3, AlignCenter ); |
120 | Label1 = new QLabel( this, "Label1" ); | 274 | |
121 | Label1->setText( tr( "Enable Sounds for:" )); | 275 | alarmLed = new OLedBox ( yellow, this ); |
122 | 276 | alarmLed-> setFocusPolicy ( QWidget::NoFocus ); | |
123 | alarmSound = new QCheckBox( tr("Alarm Sound"), this ); | 277 | alarmLed-> setFixedSize ( 16, 16 ); |
124 | alarmSound->setFocusPolicy( QWidget::NoFocus ); | 278 | |
125 | 279 | grid-> addWidget ( alarmLed, 2, 3, AlignCenter ); | |
126 | keyclicks = new QCheckBox( tr("Key Clicks"), this ); | 280 | |
127 | keyclicks->setFocusPolicy( QWidget::NoFocus ); | 281 | if ( !has_wav_alarm ) { |
128 | 282 | alarmSlider-> hide ( ); | |
129 | screentaps = new QCheckBox( tr("Screen taps"), this ); | 283 | alarmLabel-> hide ( ); |
130 | screentaps->setFocusPolicy( QWidget::NoFocus ); | 284 | alarmLed-> hide ( ); |
131 | 285 | } | |
132 | 286 | ||
133 | keyclicks->setChecked( cfg.readBoolEntry("KeySound",0)); | 287 | grid-> addWidget ( new QLabel ( tr( "Enable Sounds for:" ), this ), 0, 4, AlignVCenter | AlignLeft ); |
134 | screentaps->setChecked( cfg.readBoolEntry("TouchSound",0)); | 288 | |
135 | alarmSound->setChecked( cfg.readBoolEntry("AlarmSound",1)); | 289 | vbox = new QVBoxLayout ( ); |
136 | 290 | vbox-> setSpacing ( 4 ); | |
137 | klbox->setMargin( 3 ); | 291 | grid-> addMultiCellLayout ( vbox, 1, 2, 4, 4 ); |
138 | klbox->setSpacing( 0 ); | 292 | |
139 | klbox->addWidget( Label1, 1); | 293 | tapBox = new QCheckBox ( tr( "Screen Taps" ), this ); |
140 | klbox->addWidget( alarmSound, 1); | 294 | tapBox-> setFocusPolicy ( QWidget::NoFocus ); |
141 | klbox->addWidget( keyclicks, 1); | 295 | |
142 | klbox->addWidget( screentaps, 1); | 296 | vbox-> addWidget ( tapBox, AlignVCenter | AlignLeft ); |
143 | vbox->setMargin( 3 ); | 297 | |
144 | vbox->setSpacing( 0 ); | 298 | keyBox = new QCheckBox ( tr( "Key Clicks" ), this ); |
145 | // if (showMic == TRUE) | 299 | keyBox-> setFocusPolicy ( QWidget::NoFocus ); |
146 | vbox->addLayout( hbox, 1 ); | 300 | |
147 | // else | 301 | vbox-> addWidget ( keyBox, AlignVCenter | AlignLeft ); |
148 | // vbox->addLayout( sbox, 1); | 302 | |
149 | vbox->addWidget( muteBox, 0, Qt::AlignVCenter | Qt::AlignHCenter ); | 303 | alarmBox = new QCheckBox ( tr( "Alarm Sound" ), this ); |
150 | 304 | alarmBox-> setFocusPolicy ( QWidget::NoFocus ); | |
151 | hboxLayout->addLayout( vboxButtons ); | 305 | |
152 | hboxLayout->addLayout( vbox); | 306 | vbox-> addWidget ( alarmBox, AlignVCenter | AlignLeft ); |
153 | hboxLayout->addLayout( klbox); | 307 | |
154 | 308 | if ( has_wav_alarm ) { | |
155 | 309 | alarmBox-> hide ( ); | |
156 | setFixedHeight( 120); | 310 | } |
157 | // setFixedWidth( sizeHint().width() ); | 311 | |
312 | vbox-> addStretch ( 100 ); | ||
313 | |||
314 | setFixedSize ( sizeHint ( )); | ||
158 | setFocusPolicy(QWidget::NoFocus); | 315 | setFocusPolicy(QWidget::NoFocus); |
159 | connect( upButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); | ||
160 | connect( upButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) ); | ||
161 | connect( downButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); | ||
162 | connect( downButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) ); | ||
163 | 316 | ||
164 | rateTimer = new QTimer(this); | 317 | rateTimer = new QTimer(this); |
165 | connect( rateTimer, SIGNAL( timeout() ), this, SLOT( rateTimerDone() ) ); | 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 | ||
168 | void VolumeControl::keyPressEvent( QKeyEvent *e) | 354 | bool VolumeControl::volMuted ( ) const |
355 | { | ||
356 | return m_vol_muted; | ||
357 | } | ||
358 | |||
359 | int VolumeControl::volPercent ( ) const | ||
169 | { | 360 | { |
170 | switch(e->key()) | 361 | return m_vol_percent; |
362 | } | ||
363 | |||
364 | void VolumeControl::keyPressEvent ( QKeyEvent *e ) | ||
171 | { | 365 | { |
366 | switch ( e-> key ( )) { | ||
172 | case Key_Up: | 367 | case Key_Up: |
173 | slider->subtractStep(); | 368 | volSlider-> subtractStep ( ); |
174 | break; | 369 | break; |
175 | case Key_Down: | 370 | case Key_Down: |
176 | slider->addStep(); | 371 | volSlider-> addStep ( ); |
177 | break; | 372 | break; |
178 | case Key_Space: | 373 | case Key_Space: |
179 | muteBox->toggle(); | 374 | volLed-> toggle ( ); |
180 | break; | 375 | break; |
181 | case Key_Escape: | 376 | case Key_Escape: |
182 | close(); | 377 | hide ( ); |
183 | break; | 378 | break; |
184 | } | 379 | } |
185 | } | 380 | } |
186 | 381 | ||
187 | void VolumeControl::ButtonChanged() | 382 | void VolumeControl::buttonChanged ( ) |
188 | { | ||
189 | if ( upButton->isDown() || downButton->isDown() ) | ||
190 | { | 383 | { |
384 | if ( upButton-> isDown ( ) || downButton->isDown ( )) { | ||
191 | rateTimerDone(); // Call it one time manually, otherwise it wont get | 385 | rateTimerDone(); // Call it one time manually, otherwise it wont get |
192 | // called at all when a button is pressed for a time | 386 | // called at all when a button is pressed for a time |
193 | // shorter than RATE_TIMER_INTERVAL. | 387 | // shorter than RATE_TIMER_INTERVAL. |
194 | rateTimer->start( RATE_TIMER_INTERVAL, false ); | 388 | rateTimer->start( RATE_TIMER_INTERVAL, false ); |
195 | } | 389 | } |
196 | else | 390 | else |
197 | rateTimer->stop(); | 391 | rateTimer->stop(); |
198 | } | 392 | } |
199 | 393 | ||
200 | void VolumeControl::rateTimerDone() | 394 | void VolumeControl::rateTimerDone() |
201 | { | 395 | { |
202 | if ( upButton->isDown() ) | 396 | if ( upButton->isDown() ) |
203 | slider->setValue( slider->value() - 2 ); | 397 | volSlider-> setValue ( volSlider-> value ( ) - 2 ); |
204 | else // downButton->isDown() | 398 | else // if ( downButton-> isDown ( )) |
205 | slider->setValue( slider->value() + 2 ); | 399 | volSlider-> setValue ( volSlider-> value ( ) + 2 ); |
206 | } | 400 | } |
207 | 401 | ||
208 | //=========================================================================== | 402 | void VolumeControl::show ( bool /*showMic*/ ) |
209 | |||
210 | VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) | ||
211 | : QWidget( parent, name ) | ||
212 | { | 403 | { |
213 | Config cfg("qpe"); | 404 | readConfig ( ); |
214 | cfg.setGroup("Volume"); | ||
215 | 405 | ||
216 | setFixedHeight( 18 ); | 406 | QPoint curPos = m_icon-> mapToGlobal ( QPoint ( 0, 0 )); |
217 | setFixedWidth( 14 ); | 407 | printf ( "SHOW AT : %d/%d\n", curPos.x(), curPos.y()); |
218 | 408 | printf ( "SIZEHINT: %d/%d\n", sizeHint().width(),sizeHint().height()); | |
219 | volumePixmap = Resource::loadPixmap( "volume" ); | ||
220 | |||
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 | 409 | ||
228 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 410 | int w = sizeHint ( ). width ( ); |
229 | connect( qApp, SIGNAL( micChanged(bool) ), this, SLOT ( micChanged(bool) ) ); | 411 | int x = curPos.x ( ) - ( w / 2 ); |
230 | connect( advancedTimer, SIGNAL( timeout() ),this, SLOT( advVolControl()) ); | ||
231 | 412 | ||
232 | writeSystemVolume(); | 413 | if (( x + w ) > QPEApplication::desktop ( )-> width ( )) |
233 | writeSystemMic(); | 414 | x = QPEApplication::desktop ( )-> width ( ) - w; |
234 | } | ||
235 | |||
236 | VolumeApplet::~VolumeApplet() | ||
237 | { | ||
238 | } | ||
239 | 415 | ||
240 | void VolumeApplet::keyPressEvent ( QKeyEvent * e ) | ||
241 | { | ||
242 | QString s; | ||
243 | s.setNum(e->key()); | ||
244 | qWarning(s); | ||
245 | } | ||
246 | void VolumeApplet::mousePressEvent( QMouseEvent * ) | ||
247 | { | ||
248 | advancedTimer->start( 750, TRUE ); | ||
249 | } | ||
250 | 416 | ||
251 | void VolumeApplet::mouseReleaseEvent( QMouseEvent * ) | 417 | move ( x, curPos. y ( ) - sizeHint ( ). height ( )); |
252 | { | 418 | QFrame::show ( ); |
253 | showVolControl(FALSE); | ||
254 | } | ||
255 | 419 | ||
256 | void VolumeApplet::advVolControl() | ||
257 | { | ||
258 | showVolControl(TRUE); | ||
259 | } | 420 | } |
260 | 421 | ||
261 | void VolumeApplet::showVolControl(bool showMic) | 422 | void VolumeControl::readConfig ( bool force ) |
262 | { | 423 | { |
263 | Config cfg("qpe"); | 424 | Config cfg("qpe"); |
264 | cfg.setGroup("Volume"); | 425 | 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 | 426 | ||
284 | vc->keyclicks->setChecked( config.readBoolEntry("KeySound",0)); | 427 | int old_vp = m_vol_percent; |
285 | vc->screentaps->setChecked( config.readBoolEntry("TouchSound",0)); | 428 | int old_mp = m_mic_percent; |
286 | vc->alarmSound->setChecked( config.readBoolEntry("AlarmSound",1)); | 429 | bool old_vm = m_vol_muted; |
287 | 430 | bool old_mm = m_mic_muted; | |
288 | connect( vc->alarmSound, SIGNAL(toggled(bool)), this, SLOT( alarmSoundCheckToggled(bool))); | 431 | bool old_sk = m_snd_key; |
289 | connect( vc->keyclicks, SIGNAL(toggled(bool)), this, SLOT( keyclicksCheckToggled(bool))); | 432 | bool old_st = m_snd_touch; |
290 | connect( vc->screentaps, SIGNAL(toggled(bool)), this, SLOT( screentapsCheckToggled(bool))); | 433 | bool old_sa = m_snd_alarm; |
291 | 434 | int old_ap = m_alarm_percent; | |
292 | QPoint curPos = mapToGlobal( rect().topLeft() ); | 435 | |
293 | vc->move( curPos.x()-(vc->sizeHint().width()/2+50), curPos.y() - 120 ); | 436 | m_vol_percent = cfg. readNumEntry ( "VolumePercent", 50 ); |
294 | vc->show(); | 437 | m_mic_percent = cfg. readNumEntry ( "Mic", 50 ); |
295 | 438 | m_vol_muted = cfg. readBoolEntry ( "Mute", 0 ); | |
296 | advancedTimer->stop(); | 439 | m_mic_muted = cfg. readBoolEntry ( "MicMute", 0 ); |
297 | } | 440 | m_snd_key = cfg. readBoolEntry ( "KeySound", 0 ); |
298 | 441 | m_snd_touch = cfg. readBoolEntry ( "TouchSound", 0 ); | |
299 | void VolumeApplet::volumeChanged( bool nowMuted ) | 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 ); | ||
465 | } | ||
466 | |||
467 | |||
468 | void 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; | ||
311 | } | 479 | } |
312 | 480 | else if ( previousVolume != m_vol_percent ) { | |
313 | // Avoid over repainting | 481 | // Avoid over repainting |
314 | if ( previousVolume != volumePercent ) | 482 | m_icon-> repaint( 2, height ( ) - 3, width ( ) - 4, 2, false ); |
315 | repaint( 2, height() - 3, width() - 4, 2, FALSE ); | 483 | } |
484 | |||
316 | } | 485 | } |
317 | 486 | ||
318 | void VolumeApplet::micChanged( bool nowMuted ) | 487 | void 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 | ||
325 | void VolumeApplet::mute( bool toggled ) | 494 | void 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 | 500 | void VolumeControl::keyClickToggled ( bool b ) | |
342 | void 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 | ||
347 | void VolumeApplet::micMoved( int percent ) | 506 | void 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 | ||
352 | void VolumeApplet::readSystemVolume() | 512 | void 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 | ||
359 | void VolumeApplet::readSystemMic() | 521 | void 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 | ||
366 | void VolumeApplet::setVolume( int percent ) | 527 | |
528 | void VolumeControl::volMoved ( int percent ) | ||
367 | { | 529 | { |
530 | m_vol_percent = 100 - percent; | ||
531 | |||
368 | // clamp volume percent to be between 0 and 100 | 532 | // clamp volume percent to be between 0 and 100 |
369 | volumePercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent); | 533 | m_vol_percent = ( m_vol_percent < 0 ) ? 0 : (( m_vol_percent > 100 ) ? 100 : m_vol_percent ); |
370 | // repaint just the little volume rectangle | 534 | // repaint just the little volume rectangle |
371 | repaint( 2, height() - 3, width() - 4, 2, FALSE ); | 535 | repaint ( 2, height ( ) - 3, width ( ) - 4, 2, false ); |
372 | writeSystemVolume(); | 536 | |
537 | writeConfigEntry ( "VolumePercent", m_vol_percent, UPD_Vol ); | ||
373 | } | 538 | } |
374 | 539 | ||
375 | void VolumeApplet::setMic( int percent ) | 540 | void VolumeControl::micMoved ( int percent ) |
376 | { | 541 | { |
542 | m_mic_percent = 100 - percent; | ||
543 | |||
377 | // clamp volume percent to be between 0 and 100 | 544 | // clamp volume percent to be between 0 and 100 |
378 | micPercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent); | 545 | m_mic_percent = ( m_mic_percent < 0 ) ? 0 : (( m_mic_percent > 100 ) ? 100 : m_mic_percent ); |
379 | writeSystemMic(); | 546 | |
547 | writeConfigEntry ( "Mic", m_mic_percent, UPD_Mic ); | ||
380 | } | 548 | } |
381 | 549 | ||
382 | void VolumeApplet::writeSystemVolume() | 550 | void VolumeControl::alarmMoved ( int percent ) |
383 | { | 551 | { |
552 | m_alarm_percent = 100 - percent; | ||
553 | |||
554 | // clamp volume percent to be between 0 and 100 | ||
555 | m_alarm_percent = ( m_alarm_percent < 0 ) ? 0 : (( m_alarm_percent > 100 ) ? 100 : m_alarm_percent ); | ||
556 | |||
557 | writeConfigEntry ( "AlarmPercent", m_alarm_percent, UPD_None ); | ||
558 | } | ||
559 | |||
560 | |||
561 | void VolumeControl::writeConfigEntry ( const char *entry, int val, eUpdate upd ) | ||
384 | { | 562 | { |
385 | Config cfg("qpe"); | 563 | Config cfg("qpe"); |
386 | cfg.setGroup("Volume"); | 564 | cfg.setGroup("Volume"); |
387 | cfg.writeEntry("VolumePercent",volumePercent); | 565 | cfg. writeEntry ( entry, val ); |
388 | } | 566 | //cfg. write ( ); |
567 | |||
389 | #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) |
390 | // Send notification that the volume has changed | 569 | switch ( upd ) { |
391 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; | 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 | } | ||
392 | #endif | 581 | #endif |
393 | } | 582 | } |
394 | 583 | ||
395 | void VolumeApplet::writeSystemMic() | 584 | //=========================================================================== |
585 | |||
586 | VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) | ||
587 | : QWidget( parent, name ) | ||
396 | { | 588 | { |
589 | setFixedHeight ( 18 ); | ||
590 | setFixedWidth ( 14 ); | ||
591 | |||
592 | m_pixmap = new QPixmap ( Resource::loadPixmap ( "volume" )); | ||
593 | m_dialog = new VolumeControl ( this ); | ||
594 | |||
595 | connect ( qApp, SIGNAL( volumeChanged ( bool )), m_dialog, SLOT( volumeChanged( bool ))); | ||
596 | connect ( qApp, SIGNAL( micChanged ( bool )), m_dialog, SLOT ( micChanged( bool ))); | ||
597 | } | ||
598 | |||
599 | VolumeApplet::~VolumeApplet() | ||
397 | { | 600 | { |
398 | Config cfg("qpe"); | 601 | delete m_pixmap; |
399 | cfg.setGroup("Volume"); | ||
400 | cfg.writeEntry("Mic",micPercent); | ||
401 | } | 602 | } |
402 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 603 | |
403 | // Send notification that the volume has changed | 604 | |
404 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << micMuted; | 605 | void VolumeApplet::mousePressEvent ( QMouseEvent * ) |
405 | #endif | 606 | { |
607 | if ( m_dialog-> isVisible ( )) | ||
608 | m_dialog-> hide ( ); | ||
609 | else | ||
610 | m_dialog-> show ( true ); | ||
406 | } | 611 | } |
407 | 612 | ||
613 | |||
408 | void VolumeApplet::paintEvent( QPaintEvent* ) | 614 | void VolumeApplet::paintEvent( QPaintEvent* ) |
409 | { | 615 | { |
410 | QPainter p(this); | 616 | QPainter p(this); |
411 | 617 | ||
412 | if (volumePixmap.isNull()) | 618 | p. drawPixmap ( 0, 1, *m_pixmap ); |
413 | volumePixmap = Resource::loadPixmap( "volume" ); | ||
414 | p.drawPixmap( 0, 1, volumePixmap ); | ||
415 | p.setPen( darkGray ); | 619 | p.setPen( darkGray ); |
416 | p.drawRect( 1, height() - 4, width() - 2, 4 ); | 620 | p.drawRect( 1, height() - 4, width() - 2, 4 ); |
417 | 621 | ||
418 | int pixelsWide = volumePercent * (width() - 4) / 100; | 622 | int pixelsWide = m_dialog-> volPercent ( ) * ( width() - 4 ) / 100; |
419 | p.fillRect( 2, height() - 3, pixelsWide, 2, red ); | 623 | p.fillRect( 2, height() - 3, pixelsWide, 2, red ); |
420 | p.fillRect( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); | 624 | p.fillRect( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); |
421 | 625 | ||
422 | if ( muted ) { | 626 | if ( m_dialog-> volMuted ( )) { |
423 | p.setPen( red ); | 627 | p.setPen( red ); |
424 | p.drawLine( 1, 2, width() - 2, height() - 5 ); | 628 | p.drawLine( 1, 2, width() - 2, height() - 5 ); |
425 | p.drawLine( 1, 3, width() - 2, height() - 4 ); | 629 | p.drawLine( 1, 3, width() - 2, height() - 4 ); |
426 | p.drawLine( width() - 2, 2, 1, height() - 5 ); | 630 | p.drawLine( width() - 2, 2, 1, height() - 5 ); |
427 | p.drawLine( width() - 2, 3, 1, height() - 4 ); | 631 | p.drawLine( width() - 2, 3, 1, height() - 4 ); |
428 | } | 632 | } |
429 | } | 633 | } |
430 | 634 | ||
431 | void VolumeApplet::screentapsCheckToggled(bool b) { | ||
432 | Config cfg("qpe"); | ||
433 | cfg.setGroup("Volume"); | ||
434 | cfg.writeEntry("TouchSound",b ); | ||
435 | cfg.write(); | ||
436 | } | ||
437 | |||
438 | void VolumeApplet::keyclicksCheckToggled(bool b) { | ||
439 | Config cfg("qpe"); | ||
440 | cfg.setGroup("Volume"); | ||
441 | cfg.writeEntry("KeySound",b); | ||
442 | cfg.write(); | ||
443 | } | ||
444 | |||
445 | void VolumeApplet::alarmSoundCheckToggled(bool b) { | ||
446 | Config cfg("qpe"); | ||
447 | cfg.setGroup("Volume"); | ||
448 | cfg.writeEntry("AlarmSound",b); | ||
449 | cfg.write(); | ||
450 | } | ||
451 | 635 | ||