-rw-r--r-- | core/applets/volumeapplet/volume.cpp | 49 | ||||
-rw-r--r-- | core/applets/volumeapplet/volume.h | 2 |
2 files changed, 22 insertions, 29 deletions
diff --git a/core/applets/volumeapplet/volume.cpp b/core/applets/volumeapplet/volume.cpp index b047877..eedc749 100644 --- a/core/applets/volumeapplet/volume.cpp +++ b/core/applets/volumeapplet/volume.cpp | |||
@@ -170,46 +170,37 @@ static const char * alarm_xpm[] = { | |||
170 | " 4%_,2')[~~>4 ", | 170 | " 4%_,2')[~~>4 ", |
171 | " 4%33'4#@~1>4 ", | 171 | " 4%33'4#@~1>4 ", |
172 | " 4%3344#[:>/4 ", | 172 | " 4%3344#[:>/4 ", |
173 | " 42&_3'4#@>:*44 ", | 173 | " 42&_3'4#@>:*44 ", |
174 | " 42|}}3'4#[;$)$44 ", | 174 | " 42|}}3'4#[;$)$44 ", |
175 | "444{]]2^~~:!!#.@##/ ", | 175 | "444{]]2^~~:!!#.@##/ ", |
176 | "4444-%*:==!!=...../ ", | 176 | "4444-%*:==!!=...../ ", |
177 | " /:[.. ", | 177 | " /:[.. ", |
178 | " /@. ", | 178 | " /@. ", |
179 | " "}; | 179 | " "}; |
180 | 180 | ||
181 | VolumeControl::VolumeControl ( VolumeApplet *icon, bool /*showMic*/, QWidget *parent, const char *name ) | 181 | VolumeControl::VolumeControl ( VolumeApplet *icon, bool /*showMic*/, QWidget *parent, const char *name ) |
182 | : QFrame ( parent, name, WStyle_StaysOnTop | WType_Popup ) | 182 | : QFrame ( parent, name, WStyle_StaysOnTop | WType_Popup ) |
183 | { | 183 | { |
184 | m_icon = icon; | 184 | m_icon = icon; |
185 | 185 | ||
186 | bool has_wav_alarm = false; | 186 | bool has_wav_alarm = true; |
187 | 187 | ||
188 | switch ( ODevice::inst ( )-> model ( )) { // we need to add other devices eventually | 188 | switch ( ODevice::inst ( )-> model ( )) { // we need to add other devices eventually |
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 | case OMODEL_Zaurus_SL5000: | 189 | case OMODEL_Zaurus_SL5000: |
196 | has_wav_alarm = false; //poor guys probably feeling left out... | 190 | has_wav_alarm = false; //poor guys probably feeling left out... |
197 | break; | ||
198 | default: | ||
199 | has_wav_alarm = true; //lets just presume | ||
200 | break; | 191 | break; |
201 | } | 192 | } |
202 | 193 | ||
203 | 194 | ||
204 | setFrameStyle ( QFrame::PopupPanel | QFrame::Raised ); | 195 | setFrameStyle ( QFrame::PopupPanel | QFrame::Raised ); |
205 | 196 | ||
206 | QGridLayout *grid = new QGridLayout ( this, 1, 1, 6, 4 ); | 197 | QGridLayout *grid = new QGridLayout ( this, 1, 1, 6, 4 ); |
207 | grid-> setSpacing ( 4 ); | 198 | grid-> setSpacing ( 4 ); |
208 | grid-> setMargin ( 6 ); | 199 | grid-> setMargin ( 6 ); |
209 | 200 | ||
210 | QVBoxLayout *vbox; | 201 | QVBoxLayout *vbox; |
211 | QLabel *l; | 202 | QLabel *l; |
212 | 203 | ||
213 | vbox = new QVBoxLayout ( ); | 204 | vbox = new QVBoxLayout ( ); |
214 | vbox-> setSpacing ( 4 ); | 205 | vbox-> setSpacing ( 4 ); |
215 | grid-> addLayout ( vbox, 1, 0 ); | 206 | grid-> addLayout ( vbox, 1, 0 ); |
@@ -395,42 +386,39 @@ void VolumeControl::buttonChanged ( ) | |||
395 | rateTimer-> stop ( ); | 386 | rateTimer-> stop ( ); |
396 | } | 387 | } |
397 | 388 | ||
398 | void VolumeControl::rateTimerDone ( ) | 389 | void VolumeControl::rateTimerDone ( ) |
399 | { | 390 | { |
400 | if ( upButton-> isDown ( )) | 391 | if ( upButton-> isDown ( )) |
401 | volSlider-> setValue ( volSlider-> value ( ) - 2 ); | 392 | volSlider-> setValue ( volSlider-> value ( ) - 2 ); |
402 | else // if ( downButton-> isDown ( )) | 393 | else // if ( downButton-> isDown ( )) |
403 | volSlider-> setValue ( volSlider-> value ( ) + 2 ); | 394 | volSlider-> setValue ( volSlider-> value ( ) + 2 ); |
404 | } | 395 | } |
405 | 396 | ||
406 | void VolumeControl::show ( bool /*showMic*/ ) | 397 | void VolumeControl::show ( bool /*showMic*/ ) |
407 | { | 398 | { |
408 | readConfig ( ); | 399 | readConfig ( ); |
409 | 400 | ||
410 | QPoint curPos = m_icon-> mapToGlobal ( QPoint ( 0, 0 )); | 401 | QPoint curPos = m_icon-> mapToGlobal ( QPoint ( 0, 0 )); |
411 | printf ( "SHOW AT : %d/%d\n", curPos.x(), curPos.y()); | ||
412 | printf ( "SIZEHINT: %d/%d\n", sizeHint().width(),sizeHint().height()); | ||
413 | 402 | ||
414 | int w = sizeHint ( ). width ( ); | 403 | int w = sizeHint ( ). width ( ); |
415 | int x = curPos.x ( ) - ( w / 2 ); | 404 | int x = curPos.x ( ) - ( w / 2 ); |
416 | 405 | ||
417 | if (( x + w ) > QPEApplication::desktop ( )-> width ( )) | 406 | if (( x + w ) > QPEApplication::desktop ( )-> width ( )) |
418 | x = QPEApplication::desktop ( )-> width ( ) - w; | 407 | x = QPEApplication::desktop ( )-> width ( ) - w; |
419 | 408 | ||
420 | |||
421 | move ( x, curPos. y ( ) - sizeHint ( ). height ( )); | 409 | move ( x, curPos. y ( ) - sizeHint ( ). height ( )); |
422 | QFrame::show ( ); | 410 | QFrame::show ( ); |
423 | 411 | ||
424 | } | 412 | } |
425 | 413 | ||
426 | void VolumeControl::readConfig ( bool force ) | 414 | void VolumeControl::readConfig ( bool force ) |
427 | { | 415 | { |
428 | Config cfg ( "qpe" ); | 416 | Config cfg ( "qpe" ); |
429 | cfg. setGroup ( "Volume" ); | 417 | cfg. setGroup ( "Volume" ); |
430 | 418 | ||
431 | int old_vp = m_vol_percent; | 419 | int old_vp = m_vol_percent; |
432 | int old_mp = m_mic_percent; | 420 | int old_mp = m_mic_percent; |
433 | bool old_vm = m_vol_muted; | 421 | bool old_vm = m_vol_muted; |
434 | bool old_mm = m_mic_muted; | 422 | bool old_mm = m_mic_muted; |
435 | bool old_sk = m_snd_key; | 423 | bool old_sk = m_snd_key; |
436 | bool old_st = m_snd_touch; | 424 | bool old_st = m_snd_touch; |
@@ -458,99 +446,94 @@ void VolumeControl::readConfig ( bool force ) | |||
458 | if ( force || ( m_mic_muted != old_mm )) | 446 | if ( force || ( m_mic_muted != old_mm )) |
459 | micLed-> setOn ( !m_mic_muted ); | 447 | micLed-> setOn ( !m_mic_muted ); |
460 | if ( force || ( m_snd_alarm != old_sa )) | 448 | if ( force || ( m_snd_alarm != old_sa )) |
461 | alarmLed-> setOn ( m_snd_alarm ); | 449 | alarmLed-> setOn ( m_snd_alarm ); |
462 | 450 | ||
463 | if ( force || ( m_snd_key != old_sk )) | 451 | if ( force || ( m_snd_key != old_sk )) |
464 | keyBox-> setChecked ( m_snd_key ); | 452 | keyBox-> setChecked ( m_snd_key ); |
465 | if ( force || ( m_snd_touch != old_st )) | 453 | if ( force || ( m_snd_touch != old_st )) |
466 | tapBox-> setChecked ( m_snd_touch ); | 454 | tapBox-> setChecked ( m_snd_touch ); |
467 | if ( force || ( m_snd_alarm != old_sa )) | 455 | if ( force || ( m_snd_alarm != old_sa )) |
468 | alarmBox-> setChecked ( m_snd_alarm ); | 456 | alarmBox-> setChecked ( m_snd_alarm ); |
469 | } | 457 | } |
470 | 458 | ||
471 | 459 | ||
472 | void VolumeControl::volumeChanged ( bool nowMuted ) | 460 | void VolumeControl::volumeChanged ( bool nowMuted ) |
473 | { | 461 | { |
474 | int previousVolume = m_vol_percent; | 462 | int prevVol = m_vol_percent; |
463 | bool prevMute = m_vol_muted; | ||
475 | 464 | ||
476 | if ( !nowMuted ) | 465 | readConfig ( ); |
477 | readConfig ( ); | ||
478 | 466 | ||
479 | // Handle case where muting it toggled | 467 | // Handle case where muting it toggled |
480 | if ( m_vol_muted != nowMuted ) { | 468 | if ( m_vol_muted != prevMute ) |
481 | m_vol_muted = nowMuted; | 469 | m_icon-> redraw ( true ); |
482 | m_icon-> repaint ( true ); | 470 | else if ( prevVol != m_vol_percent ) // Avoid over repainting |
483 | } | 471 | m_icon-> redraw ( false ); |
484 | else if ( previousVolume != m_vol_percent ) { | ||
485 | // Avoid over repainting | ||
486 | m_icon-> repaint( 2, height ( ) - 3, width ( ) - 4, 2, false ); | ||
487 | } | ||
488 | |||
489 | } | 472 | } |
490 | 473 | ||
491 | void VolumeControl::micChanged ( bool nowMuted ) | 474 | void VolumeControl::micChanged ( bool nowMuted ) |
492 | { | 475 | { |
493 | if ( !nowMuted ) | 476 | if ( !nowMuted ) |
494 | readConfig ( ); | 477 | readConfig ( ); |
495 | m_mic_muted = nowMuted; | 478 | m_mic_muted = nowMuted; |
496 | } | 479 | } |
497 | 480 | ||
498 | void VolumeControl::screenTapToggled ( bool b ) | 481 | void VolumeControl::screenTapToggled ( bool b ) |
499 | { | 482 | { |
500 | m_snd_touch = b; | 483 | m_snd_touch = b; |
501 | writeConfigEntry ( "TouchSound", m_snd_touch, UPD_Vol ); | 484 | writeConfigEntry ( "TouchSound", m_snd_touch, UPD_Vol ); |
502 | } | 485 | } |
503 | 486 | ||
504 | void VolumeControl::keyClickToggled ( bool b ) | 487 | void VolumeControl::keyClickToggled ( bool b ) |
505 | { | 488 | { |
506 | m_snd_key = b; | 489 | m_snd_key = b; |
507 | writeConfigEntry ( "KeySound", m_snd_key, UPD_Vol ); | 490 | writeConfigEntry ( "KeySound", m_snd_key, UPD_Vol ); |
508 | } | 491 | } |
509 | 492 | ||
510 | void VolumeControl::alarmSoundToggled ( bool b ) | 493 | void VolumeControl::alarmSoundToggled ( bool b ) |
511 | { | 494 | { |
512 | m_snd_alarm = b; | 495 | m_snd_alarm = b; |
513 | writeConfigEntry ( "AlarmSound", m_snd_alarm, UPD_Vol ); | 496 | writeConfigEntry ( "AlarmSound", m_snd_alarm, UPD_Vol ); |
514 | } | 497 | } |
515 | 498 | ||
516 | void VolumeControl::volMuteToggled ( bool b ) | 499 | void VolumeControl::volMuteToggled ( bool b ) |
517 | { | 500 | { |
518 | m_vol_muted = !b; | 501 | m_vol_muted = !b; |
519 | 502 | ||
520 | m_icon-> repaint ( !m_vol_muted ); // clear if removing mute | 503 | m_icon-> redraw ( true ); |
521 | 504 | ||
522 | writeConfigEntry ( "Mute", m_vol_muted, UPD_Vol ); | 505 | writeConfigEntry ( "Mute", m_vol_muted, UPD_Vol ); |
523 | } | 506 | } |
524 | 507 | ||
525 | void VolumeControl::micMuteToggled ( bool b ) | 508 | void VolumeControl::micMuteToggled ( bool b ) |
526 | { | 509 | { |
527 | m_mic_muted = !b; | 510 | m_mic_muted = !b; |
528 | writeConfigEntry ( "MicMute", m_mic_muted, UPD_Mic ); | 511 | writeConfigEntry ( "MicMute", m_mic_muted, UPD_Mic ); |
529 | } | 512 | } |
530 | 513 | ||
531 | 514 | ||
532 | void VolumeControl::volMoved ( int percent ) | 515 | void VolumeControl::volMoved ( int percent ) |
533 | { | 516 | { |
534 | m_vol_percent = 100 - percent; | 517 | m_vol_percent = 100 - percent; |
535 | 518 | ||
536 | // clamp volume percent to be between 0 and 100 | 519 | // clamp volume percent to be between 0 and 100 |
537 | m_vol_percent = ( m_vol_percent < 0 ) ? 0 : (( m_vol_percent > 100 ) ? 100 : m_vol_percent ); | 520 | m_vol_percent = ( m_vol_percent < 0 ) ? 0 : (( m_vol_percent > 100 ) ? 100 : m_vol_percent ); |
538 | // repaint just the little volume rectangle | 521 | // repaint just the little volume rectangle |
539 | repaint ( 2, height ( ) - 3, width ( ) - 4, 2, false ); | 522 | m_icon-> redraw ( false ); |
540 | 523 | ||
541 | writeConfigEntry ( "VolumePercent", m_vol_percent, UPD_Vol ); | 524 | writeConfigEntry ( "VolumePercent", m_vol_percent, UPD_Vol ); |
542 | } | 525 | } |
543 | 526 | ||
544 | void VolumeControl::micMoved ( int percent ) | 527 | void VolumeControl::micMoved ( int percent ) |
545 | { | 528 | { |
546 | m_mic_percent = 100 - percent; | 529 | m_mic_percent = 100 - percent; |
547 | 530 | ||
548 | // clamp volume percent to be between 0 and 100 | 531 | // clamp volume percent to be between 0 and 100 |
549 | m_mic_percent = ( m_mic_percent < 0 ) ? 0 : (( m_mic_percent > 100 ) ? 100 : m_mic_percent ); | 532 | m_mic_percent = ( m_mic_percent < 0 ) ? 0 : (( m_mic_percent > 100 ) ? 100 : m_mic_percent ); |
550 | 533 | ||
551 | writeConfigEntry ( "Mic", m_mic_percent, UPD_Mic ); | 534 | writeConfigEntry ( "Mic", m_mic_percent, UPD_Mic ); |
552 | } | 535 | } |
553 | 536 | ||
554 | void VolumeControl::alarmMoved ( int percent ) | 537 | void VolumeControl::alarmMoved ( int percent ) |
555 | { | 538 | { |
556 | m_alarm_percent = 100 - percent; | 539 | m_alarm_percent = 100 - percent; |
@@ -601,32 +584,40 @@ VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) | |||
601 | } | 584 | } |
602 | 585 | ||
603 | VolumeApplet::~VolumeApplet() | 586 | VolumeApplet::~VolumeApplet() |
604 | { | 587 | { |
605 | delete m_pixmap; | 588 | delete m_pixmap; |
606 | } | 589 | } |
607 | 590 | ||
608 | 591 | ||
609 | void VolumeApplet::mousePressEvent ( QMouseEvent * ) | 592 | void VolumeApplet::mousePressEvent ( QMouseEvent * ) |
610 | { | 593 | { |
611 | if ( m_dialog-> isVisible ( )) | 594 | if ( m_dialog-> isVisible ( )) |
612 | m_dialog-> hide ( ); | 595 | m_dialog-> hide ( ); |
613 | else | 596 | else |
614 | m_dialog-> show ( true ); | 597 | m_dialog-> show ( true ); |
615 | } | 598 | } |
616 | 599 | ||
600 | void VolumeApplet::redraw ( bool all ) | ||
601 | { | ||
602 | if ( all ) | ||
603 | repaint ( true ); | ||
604 | else | ||
605 | repaint ( 2, height ( ) - 3, width ( ) - 4, 2, false ); | ||
606 | } | ||
607 | |||
617 | 608 | ||
618 | void VolumeApplet::paintEvent ( QPaintEvent * ) | 609 | void VolumeApplet::paintEvent ( QPaintEvent * ) |
619 | { | 610 | { |
620 | QPainter p ( this ); | 611 | QPainter p ( this ); |
621 | 612 | ||
622 | p. drawPixmap ( 0, 1, *m_pixmap ); | 613 | p. drawPixmap ( 0, 1, *m_pixmap ); |
623 | p. setPen ( darkGray ); | 614 | p. setPen ( darkGray ); |
624 | p. drawRect ( 1, height() - 4, width() - 2, 4 ); | 615 | p. drawRect ( 1, height() - 4, width() - 2, 4 ); |
625 | 616 | ||
626 | int pixelsWide = m_dialog-> volPercent ( ) * ( width() - 4 ) / 100; | 617 | int pixelsWide = m_dialog-> volPercent ( ) * ( width() - 4 ) / 100; |
627 | p. fillRect ( 2, height() - 3, pixelsWide, 2, red ); | 618 | p. fillRect ( 2, height() - 3, pixelsWide, 2, red ); |
628 | p. fillRect ( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); | 619 | p. fillRect ( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); |
629 | 620 | ||
630 | if ( m_dialog-> volMuted ( )) { | 621 | if ( m_dialog-> volMuted ( )) { |
631 | p. setPen ( red ); | 622 | p. setPen ( red ); |
632 | p. drawLine ( 1, 2, width() - 2, height() - 5 ); | 623 | p. drawLine ( 1, 2, width() - 2, height() - 5 ); |
diff --git a/core/applets/volumeapplet/volume.h b/core/applets/volumeapplet/volume.h index ff5c64a..4d988ac 100644 --- a/core/applets/volumeapplet/volume.h +++ b/core/applets/volumeapplet/volume.h | |||
@@ -97,28 +97,30 @@ private: | |||
97 | bool m_vol_muted; | 97 | bool m_vol_muted; |
98 | bool m_mic_muted; | 98 | bool m_mic_muted; |
99 | bool m_snd_alarm; | 99 | bool m_snd_alarm; |
100 | bool m_snd_touch; | 100 | bool m_snd_touch; |
101 | bool m_snd_key; | 101 | bool m_snd_key; |
102 | 102 | ||
103 | VolumeApplet *m_icon; | 103 | VolumeApplet *m_icon; |
104 | }; | 104 | }; |
105 | 105 | ||
106 | class VolumeApplet : public QWidget { | 106 | class VolumeApplet : public QWidget { |
107 | Q_OBJECT | 107 | Q_OBJECT |
108 | 108 | ||
109 | public: | 109 | public: |
110 | VolumeApplet ( QWidget *parent = 0, const char *name=0 ); | 110 | VolumeApplet ( QWidget *parent = 0, const char *name=0 ); |
111 | ~VolumeApplet ( ); | 111 | ~VolumeApplet ( ); |
112 | 112 | ||
113 | void redraw ( bool all = true ); | ||
114 | |||
113 | protected: | 115 | protected: |
114 | virtual void mousePressEvent ( QMouseEvent * ); | 116 | virtual void mousePressEvent ( QMouseEvent * ); |
115 | virtual void paintEvent ( QPaintEvent* ); | 117 | virtual void paintEvent ( QPaintEvent* ); |
116 | 118 | ||
117 | private: | 119 | private: |
118 | QPixmap * m_pixmap; | 120 | QPixmap * m_pixmap; |
119 | VolumeControl *m_dialog; | 121 | VolumeControl *m_dialog; |
120 | }; | 122 | }; |
121 | 123 | ||
122 | 124 | ||
123 | #endif // __VOLUME_APPLET_H__ | 125 | #endif // __VOLUME_APPLET_H__ |
124 | 126 | ||