Diffstat (limited to 'core/applets/volumeapplet/volume.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/volumeapplet/volume.cpp | 850 |
1 files changed, 517 insertions, 333 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 | |||
@@ -9,443 +9,627 @@ | |||
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
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> |
27 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 28 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
28 | #include <qpe/qcopenvelope_qws.h> | 29 | #include <qpe/qcopenvelope_qws.h> |
29 | #endif | 30 | #endif |
30 | 31 | ||
31 | #include <qpainter.h> | 32 | #include <qpainter.h> |
32 | #include <qcheckbox.h> | 33 | #include <qcheckbox.h> |
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 | ||
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 | ||
46 | VolumeControl::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 | ||
53 | void VolumeControl::createView(bool showMic) | 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 ) | ||
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 | ||
168 | void VolumeControl::keyPressEvent( QKeyEvent *e) | 354 | bool 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 | ||
187 | void VolumeControl::ButtonChanged() | 359 | int 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 | ||
200 | void VolumeControl::rateTimerDone() | 364 | void 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 | //=========================================================================== | 382 | void VolumeControl::buttonChanged ( ) |
209 | |||
210 | VolumeApplet::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 | ||
236 | VolumeApplet::~VolumeApplet() | 394 | void 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 | ||
240 | void VolumeApplet::keyPressEvent ( QKeyEvent * e ) | 402 | void VolumeControl::show ( bool /*showMic*/ ) |
241 | { | ||
242 | QString s; | ||
243 | s.setNum(e->key()); | ||
244 | qWarning(s); | ||
245 | } | ||
246 | void 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 | ||
251 | void VolumeApplet::mouseReleaseEvent( QMouseEvent * ) | ||
252 | { | ||
253 | showVolControl(FALSE); | ||
254 | } | 420 | } |
255 | 421 | ||
256 | void VolumeApplet::advVolControl() | 422 | void 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 | ||
261 | void 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 | ||
299 | void VolumeApplet::volumeChanged( bool nowMuted ) | 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; | 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 | ||
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 | { |
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 | ||
375 | void VolumeApplet::setMic( int percent ) | 540 | void 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 | ||
382 | void VolumeApplet::writeSystemVolume() | 550 | void 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 | ||
395 | void VolumeApplet::writeSystemMic() | 560 | |
561 | void 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 | ||
408 | void VolumeApplet::paintEvent( QPaintEvent* ) | 584 | //=========================================================================== |
585 | |||
586 | VolumeApplet::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 | ||
431 | void VolumeApplet::screentapsCheckToggled(bool b) { | 599 | VolumeApplet::~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 | ||
438 | void VolumeApplet::keyclicksCheckToggled(bool b) { | 604 | |
439 | Config cfg("qpe"); | 605 | void 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 | ||
445 | void VolumeApplet::alarmSoundCheckToggled(bool b) { | 613 | |
446 | Config cfg("qpe"); | 614 | void 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 | |||