-rw-r--r-- | core/applets/volumeapplet/volume.cpp | 296 | ||||
-rw-r--r-- | core/applets/volumeapplet/volume.h | 47 |
2 files changed, 246 insertions, 97 deletions
diff --git a/core/applets/volumeapplet/volume.cpp b/core/applets/volumeapplet/volume.cpp index ee9eab3..344f86f 100644 --- a/core/applets/volumeapplet/volume.cpp +++ b/core/applets/volumeapplet/volume.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
@@ -20,2 +20,3 @@ | |||
20 | 20 | ||
21 | |||
21 | #include "volume.h" | 22 | #include "volume.h" |
@@ -35,2 +36,4 @@ | |||
35 | #include <qpixmap.h> | 36 | #include <qpixmap.h> |
37 | #include <qlabel.h> | ||
38 | |||
36 | #include <qpushbutton.h> | 39 | #include <qpushbutton.h> |
@@ -42,8 +45,19 @@ | |||
42 | 45 | ||
43 | VolumeControl::VolumeControl( QWidget *parent, const char *name ) | 46 | VolumeControl::VolumeControl( bool showMic, QWidget *parent, const char *name ) |
44 | : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) | 47 | : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) |
45 | { | 48 | { |
46 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 49 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
50 | createView(showMic); | ||
51 | } | ||
52 | |||
53 | void VolumeControl::createView(bool showMic) | ||
54 | { | ||
55 | Config cfg("Sound"); | ||
56 | cfg.setGroup("System"); | ||
57 | //showMic = TRUE; | ||
58 | QHBoxLayout *hboxLayout = new QHBoxLayout(this); | ||
59 | hboxLayout->setMargin( 3 ); | ||
60 | hboxLayout->setSpacing( 0); | ||
47 | 61 | ||
48 | QVBoxLayout *vboxButtons = new QVBoxLayout; | 62 | QVBoxLayout *vboxButtons = new QVBoxLayout(this); |
49 | upButton = new QPushButton( this ); | 63 | upButton = new QPushButton( this ); |
@@ -55,2 +69,3 @@ VolumeControl::VolumeControl( QWidget *parent, const char *name ) | |||
55 | vboxButtons->setSpacing( 2 ); | 69 | vboxButtons->setSpacing( 2 ); |
70 | |||
56 | vboxButtons->addWidget( upButton ); | 71 | vboxButtons->addWidget( upButton ); |
@@ -58,3 +73,5 @@ VolumeControl::VolumeControl( QWidget *parent, const char *name ) | |||
58 | 73 | ||
59 | QHBoxLayout *hbox = new QHBoxLayout; | 74 | QVBoxLayout *vbox = new QVBoxLayout( this ); |
75 | QHBoxLayout *hbox = NULL; | ||
76 | |||
60 | slider = new QSlider( this ); | 77 | slider = new QSlider( this ); |
@@ -64,21 +81,48 @@ VolumeControl::VolumeControl( QWidget *parent, const char *name ) | |||
64 | slider->setFocusPolicy( QWidget::NoFocus ); | 81 | slider->setFocusPolicy( QWidget::NoFocus ); |
65 | hbox->setSpacing( 4 ); | 82 | slider->setValue(cfg.readNumEntry("Volume")); |
66 | hbox->addWidget( slider ); | ||
67 | hbox->addLayout( vboxButtons ); | ||
68 | 83 | ||
69 | QVBoxLayout *vbox = new QVBoxLayout( this ); | 84 | QVBoxLayout *sbox = new QVBoxLayout(this); |
70 | QFrame *separator = new QFrame( this ); | 85 | sbox->setMargin( 3 ); |
71 | separator->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | 86 | sbox->setSpacing( 3 ); |
87 | sbox->addWidget( new QLabel("Vol", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter ); | ||
88 | sbox->addWidget( slider, 0, Qt::AlignVCenter | Qt::AlignHCenter ); | ||
89 | |||
90 | if (showMic == TRUE) { | ||
91 | mic = new QSlider(this); | ||
92 | mic->setRange( 0, 100 ); | ||
93 | mic->setTickmarks( QSlider::Both ); | ||
94 | mic->setTickInterval( 20 ); | ||
95 | mic->setFocusPolicy( QWidget::NoFocus ); | ||
96 | mic->setValue(cfg.readNumEntry("Mic")); | ||
97 | |||
98 | QVBoxLayout *mbox = new QVBoxLayout(this); | ||
99 | mbox->setMargin( 3 ); | ||
100 | mbox->setSpacing( 3 ); | ||
101 | mbox->addWidget( new QLabel("Mic", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter ); | ||
102 | mbox->addWidget( mic, 0, Qt::AlignVCenter | Qt::AlignHCenter ); | ||
103 | |||
104 | hbox = new QHBoxLayout( this ); | ||
105 | hbox->setMargin( 3 ); | ||
106 | hbox->setSpacing( 3 ); | ||
107 | hbox->addLayout( sbox, 1); | ||
108 | hbox->addLayout( mbox, 1); | ||
109 | } | ||
110 | |||
72 | muteBox = new QCheckBox( tr("Mute"), this ); | 111 | muteBox = new QCheckBox( tr("Mute"), this ); |
73 | muteBox->setFocusPolicy( QWidget::NoFocus ); | 112 | muteBox->setFocusPolicy( QWidget::NoFocus ); |
74 | vbox->setSpacing( 4 ); | 113 | |
75 | vbox->setMargin( 6 ); | 114 | vbox->setMargin( 3 ); |
76 | vbox->addLayout( hbox ); | 115 | vbox->setSpacing( 0 ); |
77 | vbox->addWidget( separator ); | 116 | if (showMic == TRUE) |
117 | vbox->addLayout( hbox, 1 ); | ||
118 | else | ||
119 | vbox->addLayout( sbox, 1); | ||
78 | vbox->addWidget( muteBox, 0, Qt::AlignVCenter | Qt::AlignHCenter ); | 120 | vbox->addWidget( muteBox, 0, Qt::AlignVCenter | Qt::AlignHCenter ); |
79 | 121 | ||
80 | setFixedHeight( 100 ); | 122 | hboxLayout->addLayout( vboxButtons ); |
123 | hboxLayout->addLayout(vbox); | ||
124 | |||
125 | setFixedHeight( 120 ); | ||
81 | setFixedWidth( sizeHint().width() ); | 126 | setFixedWidth( sizeHint().width() ); |
82 | setFocusPolicy(QWidget::NoFocus); | 127 | setFocusPolicy(QWidget::NoFocus); |
83 | |||
84 | connect( upButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); | 128 | connect( upButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); |
@@ -92,18 +136,19 @@ VolumeControl::VolumeControl( QWidget *parent, const char *name ) | |||
92 | 136 | ||
93 | void VolumeControl::keyPressEvent( QKeyEvent *e) | 137 | void VolumeControl::keyPressEvent( QKeyEvent *e) |
94 | { | 138 | { |
95 | switch(e->key()) { | 139 | switch(e->key()) |
96 | case Key_Up: | 140 | { |
97 | slider->subtractStep(); | 141 | case Key_Up: |
98 | break; | 142 | slider->subtractStep(); |
99 | case Key_Down: | 143 | break; |
100 | slider->addStep(); | 144 | case Key_Down: |
101 | break; | 145 | slider->addStep(); |
102 | case Key_Space: | 146 | break; |
103 | muteBox->toggle(); | 147 | case Key_Space: |
104 | break; | 148 | muteBox->toggle(); |
105 | case Key_Escape: | 149 | break; |
106 | close(); | 150 | case Key_Escape: |
107 | break; | 151 | close(); |
108 | } | 152 | break; |
153 | } | ||
109 | } | 154 | } |
@@ -136,9 +181,23 @@ VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) | |||
136 | { | 181 | { |
137 | setFixedHeight( 18 ); | 182 | Config cfg("Sound"); |
138 | setFixedWidth( 14 ); | 183 | cfg.setGroup("System"); |
139 | volumePixmap = Resource::loadPixmap( "volume" ); | 184 | |
140 | muted = FALSE; // ### read from pref | 185 | setFixedHeight( 18 ); |
141 | volumePercent = 50; // ### read from pref | 186 | setFixedWidth( 14 ); |
142 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 187 | |
143 | writeSystemVolume(); | 188 | volumePixmap = Resource::loadPixmap( "volume" ); |
189 | |||
190 | volumePercent = cfg.readNumEntry("Volume",50); | ||
191 | micPercent = cfg.readNumEntry("Mic", 50); | ||
192 | muted = FALSE; // ### read from pref | ||
193 | micMuted = FALSE; // ### read from pref | ||
194 | |||
195 | advancedTimer = new QTimer(this); | ||
196 | |||
197 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | ||
198 | connect( qApp, SIGNAL( micChanged(bool) ), this, SLOT ( micChanged(bool) ) ); | ||
199 | connect( advancedTimer, SIGNAL( timeout() ),this, SLOT( advVolControl()) ); | ||
200 | |||
201 | writeSystemVolume(); | ||
202 | writeSystemMic(); | ||
144 | } | 203 | } |
@@ -149,13 +208,47 @@ VolumeApplet::~VolumeApplet() | |||
149 | 208 | ||
150 | void VolumeApplet::mousePressEvent( QMouseEvent *) | 209 | void VolumeApplet::keyPressEvent ( QKeyEvent * e ) |
151 | { | 210 | { |
152 | // Create a small volume control window to adjust the volume with | 211 | QString s; |
153 | VolumeControl *vc = new VolumeControl; | 212 | s.setNum(e->key()); |
154 | vc->slider->setValue( 100 - volumePercent ); | 213 | qWarning(s); |
155 | vc->muteBox->setChecked( muted ); | 214 | } |
156 | connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) ); | 215 | void VolumeApplet::mousePressEvent( QMouseEvent * ) |
157 | connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) ); | 216 | { |
158 | QPoint curPos = mapToGlobal( rect().topLeft() ); | 217 | advancedTimer->start( 750, TRUE ); |
159 | vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 ); | 218 | } |
160 | vc->show(); | 219 | |
220 | void VolumeApplet::mouseReleaseEvent( QMouseEvent * ) | ||
221 | { | ||
222 | showVolControl(FALSE); | ||
223 | } | ||
224 | |||
225 | void VolumeApplet::advVolControl() | ||
226 | { | ||
227 | showVolControl(TRUE); | ||
228 | } | ||
229 | |||
230 | void VolumeApplet::showVolControl(bool showMic) | ||
231 | { | ||
232 | Config cfg("Sound"); | ||
233 | cfg.setGroup("System"); | ||
234 | volumePercent = cfg.readNumEntry("Volume",50); | ||
235 | micPercent = cfg.readNumEntry("Mic", 50); | ||
236 | |||
237 | // Create a small volume control window to adjust the volume with | ||
238 | VolumeControl *vc = new VolumeControl(showMic); | ||
239 | vc->slider->setValue( 100 - volumePercent ); | ||
240 | if (showMic) | ||
241 | { | ||
242 | vc->mic->setValue( 100 - micPercent ); | ||
243 | connect( vc->mic, SIGNAL( valueChanged( int ) ), this, SLOT( micMoved( int ) ) ); | ||
244 | } | ||
245 | |||
246 | vc->muteBox->setChecked( muted ); | ||
247 | connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) ); | ||
248 | connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) ); | ||
249 | QPoint curPos = mapToGlobal( rect().topLeft() ); | ||
250 | vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 120 ); | ||
251 | vc->show(); | ||
252 | |||
253 | advancedTimer->stop(); | ||
161 | } | 254 | } |
@@ -171,5 +264,5 @@ void VolumeApplet::volumeChanged( bool nowMuted ) | |||
171 | if ( muted != nowMuted ) { | 264 | if ( muted != nowMuted ) { |
172 | muted = nowMuted; | 265 | muted = nowMuted; |
173 | repaint( TRUE ); | 266 | repaint( TRUE ); |
174 | return; | 267 | return; |
175 | } | 268 | } |
@@ -178,3 +271,10 @@ void VolumeApplet::volumeChanged( bool nowMuted ) | |||
178 | if ( previousVolume != volumePercent ) | 271 | if ( previousVolume != volumePercent ) |
179 | repaint( 2, height() - 3, width() - 4, 2, FALSE ); | 272 | repaint( 2, height() - 3, width() - 4, 2, FALSE ); |
273 | } | ||
274 | |||
275 | void VolumeApplet::micChanged( bool nowMuted ) | ||
276 | { | ||
277 | if (!nowMuted) | ||
278 | readSystemMic(); | ||
279 | micMuted = nowMuted; | ||
180 | } | 280 | } |
@@ -184,2 +284,3 @@ void VolumeApplet::mute( bool toggled ) | |||
184 | muted = toggled; | 284 | muted = toggled; |
285 | |||
185 | // clear if removing mute | 286 | // clear if removing mute |
@@ -189,2 +290,3 @@ void VolumeApplet::mute( bool toggled ) | |||
189 | 290 | ||
291 | |||
190 | void VolumeApplet::sliderMoved( int percent ) | 292 | void VolumeApplet::sliderMoved( int percent ) |
@@ -194,2 +296,7 @@ void VolumeApplet::sliderMoved( int percent ) | |||
194 | 296 | ||
297 | void VolumeApplet::micMoved( int percent ) | ||
298 | { | ||
299 | setMic( 100 - percent ); | ||
300 | } | ||
301 | |||
195 | void VolumeApplet::readSystemVolume() | 302 | void VolumeApplet::readSystemVolume() |
@@ -201,2 +308,9 @@ void VolumeApplet::readSystemVolume() | |||
201 | 308 | ||
309 | void VolumeApplet::readSystemMic() | ||
310 | { | ||
311 | Config cfg("Sound"); | ||
312 | cfg.setGroup("System"); | ||
313 | micPercent = cfg.readNumEntry("Mic"); | ||
314 | } | ||
315 | |||
202 | void VolumeApplet::setVolume( int percent ) | 316 | void VolumeApplet::setVolume( int percent ) |
@@ -210,12 +324,19 @@ void VolumeApplet::setVolume( int percent ) | |||
210 | 324 | ||
325 | void VolumeApplet::setMic( int percent ) | ||
326 | { | ||
327 | // clamp volume percent to be between 0 and 100 | ||
328 | micPercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent); | ||
329 | writeSystemMic(); | ||
330 | } | ||
331 | |||
211 | void VolumeApplet::writeSystemVolume() | 332 | void VolumeApplet::writeSystemVolume() |
212 | { | 333 | { |
213 | { | 334 | { |
214 | Config cfg("Sound"); | 335 | Config cfg("Sound"); |
215 | cfg.setGroup("System"); | 336 | cfg.setGroup("System"); |
216 | cfg.writeEntry("Volume",volumePercent); | 337 | cfg.writeEntry("Volume",volumePercent); |
217 | } | 338 | } |
218 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 339 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
219 | // Send notification that the volume has changed | 340 | // Send notification that the volume has changed |
220 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; | 341 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; |
221 | #endif | 342 | #endif |
@@ -223,23 +344,36 @@ void VolumeApplet::writeSystemVolume() | |||
223 | 344 | ||
224 | void VolumeApplet::paintEvent( QPaintEvent* ) | 345 | void VolumeApplet::writeSystemMic() |
225 | { | 346 | { |
226 | QPainter p(this); | 347 | { |
227 | 348 | Config cfg("Sound"); | |
228 | if (volumePixmap.isNull()) | 349 | cfg.setGroup("System"); |
229 | volumePixmap = Resource::loadPixmap( "volume" ); | 350 | cfg.writeEntry("Mic",micPercent); |
230 | p.drawPixmap( 0, 1, volumePixmap ); | 351 | } |
231 | p.setPen( darkGray ); | 352 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
232 | p.drawRect( 1, height() - 4, width() - 2, 4 ); | 353 | // Send notification that the volume has changed |
233 | 354 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << micMuted; | |
234 | int pixelsWide = volumePercent * (width() - 4) / 100; | 355 | #endif |
235 | p.fillRect( 2, height() - 3, pixelsWide, 2, red ); | 356 | } |
236 | p.fillRect( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); | ||
237 | 357 | ||
238 | if ( muted ) { | 358 | void VolumeApplet::paintEvent( QPaintEvent* ) |
239 | p.setPen( red ); | 359 | { |
240 | p.drawLine( 1, 2, width() - 2, height() - 5 ); | 360 | QPainter p(this); |
241 | p.drawLine( 1, 3, width() - 2, height() - 4 ); | 361 | |
242 | p.drawLine( width() - 2, 2, 1, height() - 5 ); | 362 | if (volumePixmap.isNull()) |
243 | p.drawLine( width() - 2, 3, 1, height() - 4 ); | 363 | volumePixmap = Resource::loadPixmap( "volume" ); |
244 | } | 364 | p.drawPixmap( 0, 1, volumePixmap ); |
365 | p.setPen( darkGray ); | ||
366 | p.drawRect( 1, height() - 4, width() - 2, 4 ); | ||
367 | |||
368 | int pixelsWide = volumePercent * (width() - 4) / 100; | ||
369 | p.fillRect( 2, height() - 3, pixelsWide, 2, red ); | ||
370 | p.fillRect( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); | ||
371 | |||
372 | if ( muted ) { | ||
373 | p.setPen( red ); | ||
374 | p.drawLine( 1, 2, width() - 2, height() - 5 ); | ||
375 | p.drawLine( 1, 3, width() - 2, height() - 4 ); | ||
376 | p.drawLine( width() - 2, 2, 1, height() - 5 ); | ||
377 | p.drawLine( width() - 2, 3, 1, height() - 4 ); | ||
378 | } | ||
245 | } | 379 | } |
diff --git a/core/applets/volumeapplet/volume.h b/core/applets/volumeapplet/volume.h index a982f53..9fc12d8 100644 --- a/core/applets/volumeapplet/volume.h +++ b/core/applets/volumeapplet/volume.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
@@ -19,2 +19,3 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | |||
20 | #ifndef __VOLUME_APPLET_H__ | 21 | #ifndef __VOLUME_APPLET_H__ |
@@ -27,2 +28,3 @@ | |||
27 | #include <qguardedptr.h> | 28 | #include <qguardedptr.h> |
29 | #include <qtimer.h> | ||
28 | 30 | ||
@@ -30,4 +32,2 @@ class QSlider; | |||
30 | class QCheckBox; | 32 | class QCheckBox; |
31 | class QPushButton; | ||
32 | class QTimer; | ||
33 | 33 | ||
@@ -37,3 +37,3 @@ class VolumeControl : public QFrame | |||
37 | public: | 37 | public: |
38 | VolumeControl( QWidget *parent=0, const char *name=0 ); | 38 | VolumeControl( bool showMic=FALSE, QWidget *parent=0, const char *name=0 ); |
39 | 39 | ||
@@ -41,2 +41,3 @@ public: | |||
41 | QSlider *slider; | 41 | QSlider *slider; |
42 | QSlider *mic; | ||
42 | QCheckBox *muteBox; | 43 | QCheckBox *muteBox; |
@@ -44,4 +45,8 @@ public: | |||
44 | private: | 45 | private: |
46 | QPushButton *upButton; | ||
47 | QPushButton *downButton; | ||
48 | QTimer *rateTimer; | ||
49 | |||
45 | void keyPressEvent( QKeyEvent * ); | 50 | void keyPressEvent( QKeyEvent * ); |
46 | 51 | void createView(bool showMic = FALSE); | |
47 | private slots: | 52 | private slots: |
@@ -49,7 +54,3 @@ private slots: | |||
49 | void rateTimerDone(); | 54 | void rateTimerDone(); |
50 | 55 | ||
51 | private: | ||
52 | QPushButton *upButton; | ||
53 | QPushButton *downButton; | ||
54 | QTimer *rateTimer; | ||
55 | }; | 56 | }; |
@@ -67,3 +68,3 @@ public slots: | |||
67 | void volumeChanged( bool muted ); | 68 | void volumeChanged( bool muted ); |
68 | void setVolume( int percent ); | 69 | void micChanged( bool muted ); |
69 | void sliderMoved( int percent ); | 70 | void sliderMoved( int percent ); |
@@ -71,3 +72,15 @@ public slots: | |||
71 | 72 | ||
73 | void micMoved( int percent ); | ||
74 | void setVolume( int percent ); | ||
75 | void setMic( int percent ); | ||
76 | |||
77 | void showVolControl(bool showMic = FALSE); | ||
78 | void advVolControl(); | ||
79 | |||
72 | private: | 80 | private: |
81 | int volumePercent, micPercent; | ||
82 | bool muted, micMuted; | ||
83 | QPixmap volumePixmap; | ||
84 | QTimer *advancedTimer; | ||
85 | |||
73 | void readSystemVolume(); | 86 | void readSystemVolume(); |
@@ -77,6 +90,7 @@ private: | |||
77 | 90 | ||
78 | private: | 91 | void readSystemMic(); |
79 | int volumePercent; | 92 | void keyPressEvent ( QKeyEvent * e ); |
80 | bool muted; | 93 | void mouseReleaseEvent( QMouseEvent *); |
81 | QPixmap volumePixmap; | 94 | void writeSystemMic(); |
95 | |||
82 | }; | 96 | }; |
@@ -85 +99,2 @@ private: | |||
85 | #endif // __VOLUME_APPLET_H__ | 99 | #endif // __VOLUME_APPLET_H__ |
100 | |||