Diffstat (limited to 'core/applets/volumeapplet/volume.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/applets/volumeapplet/volume.cpp | 210 |
1 files changed, 65 insertions, 145 deletions
diff --git a/core/applets/volumeapplet/volume.cpp b/core/applets/volumeapplet/volume.cpp index 445cc8b..ee9eab3 100644 --- a/core/applets/volumeapplet/volume.cpp +++ b/core/applets/volumeapplet/volume.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
@@ -35,5 +35,10 @@ | |||
35 | #include <qpixmap.h> | 35 | #include <qpixmap.h> |
36 | #include <qlabel.h> | 36 | #include <qpushbutton.h> |
37 | #include <qtimer.h> | ||
37 | 38 | ||
38 | VolumeControl::VolumeControl( bool showMic, QWidget *parent, const char *name ) | 39 | #define RATE_TIMER_INTERVAL 100 |
40 | // Ten times per second is fine (RATE_TIMER_INTERVAL 100). A shorter time | ||
41 | // results in "hanging" buttons on the iPAQ due to quite high CPU consumption. | ||
42 | |||
43 | VolumeControl::VolumeControl( QWidget *parent, const char *name ) | ||
39 | : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) | 44 | : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) |
@@ -41,13 +46,15 @@ VolumeControl::VolumeControl( bool showMic, QWidget *parent, const char *name ) | |||
41 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 46 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
42 | createView(showMic); | ||
43 | } | ||
44 | |||
45 | void VolumeControl::createView(bool showMic) | ||
46 | { | ||
47 | Config cfg("Sound"); | ||
48 | cfg.setGroup("System"); | ||
49 | |||
50 | QVBoxLayout *vbox = new QVBoxLayout( this ); | ||
51 | QHBoxLayout *hbox = NULL; | ||
52 | 47 | ||
48 | QVBoxLayout *vboxButtons = new QVBoxLayout; | ||
49 | upButton = new QPushButton( this ); | ||
50 | upButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); | ||
51 | upButton->setPixmap( Resource::loadPixmap( "up" ) ); | ||
52 | downButton = new QPushButton( this ); | ||
53 | downButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); | ||
54 | downButton->setPixmap( Resource::loadPixmap( "down" ) ); | ||
55 | vboxButtons->setSpacing( 2 ); | ||
56 | vboxButtons->addWidget( upButton ); | ||
57 | vboxButtons->addWidget( downButton ); | ||
58 | |||
59 | QHBoxLayout *hbox = new QHBoxLayout; | ||
53 | slider = new QSlider( this ); | 60 | slider = new QSlider( this ); |
@@ -57,46 +64,28 @@ void VolumeControl::createView(bool showMic) | |||
57 | slider->setFocusPolicy( QWidget::NoFocus ); | 64 | slider->setFocusPolicy( QWidget::NoFocus ); |
58 | slider->setValue(cfg.readNumEntry("Volume")); | 65 | hbox->setSpacing( 4 ); |
59 | 66 | hbox->addWidget( slider ); | |
60 | QVBoxLayout *sbox = new QVBoxLayout(this); | 67 | hbox->addLayout( vboxButtons ); |
61 | sbox->setMargin( 3 ); | ||
62 | sbox->setSpacing( 3 ); | ||
63 | sbox->addWidget( new QLabel("Vol", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter ); | ||
64 | sbox->addWidget( slider, 0, Qt::AlignVCenter | Qt::AlignHCenter ); | ||
65 | |||
66 | if (showMic == TRUE) | ||
67 | { | ||
68 | mic = new QSlider(this); | ||
69 | mic->setRange( 0, 100 ); | ||
70 | mic->setTickmarks( QSlider::Both ); | ||
71 | mic->setTickInterval( 20 ); | ||
72 | mic->setFocusPolicy( QWidget::NoFocus ); | ||
73 | mic->setValue(cfg.readNumEntry("Mic")); | ||
74 | |||
75 | QVBoxLayout *mbox = new QVBoxLayout(this); | ||
76 | mbox->setMargin( 3 ); | ||
77 | mbox->setSpacing( 3 ); | ||
78 | mbox->addWidget( new QLabel("Mic", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter ); | ||
79 | mbox->addWidget( mic, 0, Qt::AlignVCenter | Qt::AlignHCenter ); | ||
80 | |||
81 | hbox = new QHBoxLayout( this ); | ||
82 | hbox->setMargin( 3 ); | ||
83 | hbox->setSpacing( 3 ); | ||
84 | hbox->addLayout( sbox, 1); | ||
85 | hbox->addLayout( mbox, 1); | ||
86 | } | ||
87 | 68 | ||
69 | QVBoxLayout *vbox = new QVBoxLayout( this ); | ||
70 | QFrame *separator = new QFrame( this ); | ||
71 | separator->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | ||
88 | muteBox = new QCheckBox( tr("Mute"), this ); | 72 | muteBox = new QCheckBox( tr("Mute"), this ); |
89 | muteBox->setFocusPolicy( QWidget::NoFocus ); | 73 | muteBox->setFocusPolicy( QWidget::NoFocus ); |
90 | 74 | vbox->setSpacing( 4 ); | |
91 | vbox->setMargin( 3 ); | 75 | vbox->setMargin( 6 ); |
92 | vbox->setSpacing( 0 ); | 76 | vbox->addLayout( hbox ); |
93 | if (showMic == TRUE) | 77 | vbox->addWidget( separator ); |
94 | vbox->addLayout( hbox, 1 ); | ||
95 | else | ||
96 | vbox->addLayout( sbox, 1); | ||
97 | vbox->addWidget( muteBox, 0, Qt::AlignVCenter | Qt::AlignHCenter ); | 78 | vbox->addWidget( muteBox, 0, Qt::AlignVCenter | Qt::AlignHCenter ); |
98 | 79 | ||
99 | setFixedHeight( 120 ); | 80 | setFixedHeight( 100 ); |
100 | setFixedWidth( sizeHint().width() ); | 81 | setFixedWidth( sizeHint().width() ); |
101 | setFocusPolicy(QWidget::NoFocus); | 82 | setFocusPolicy(QWidget::NoFocus); |
83 | |||
84 | connect( upButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); | ||
85 | connect( upButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) ); | ||
86 | connect( downButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); | ||
87 | connect( downButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) ); | ||
88 | |||
89 | rateTimer = new QTimer(this); | ||
90 | connect( rateTimer, SIGNAL( timeout() ), this, SLOT( rateTimerDone() ) ); | ||
102 | } | 91 | } |
@@ -105,4 +94,3 @@ void VolumeControl::keyPressEvent( QKeyEvent *e) | |||
105 | { | 94 | { |
106 | switch(e->key()) | 95 | switch(e->key()) { |
107 | { | ||
108 | case Key_Up: | 96 | case Key_Up: |
@@ -122,2 +110,23 @@ void VolumeControl::keyPressEvent( QKeyEvent *e) | |||
122 | 110 | ||
111 | void VolumeControl::ButtonChanged() | ||
112 | { | ||
113 | if ( upButton->isDown() || downButton->isDown() ) | ||
114 | { | ||
115 | rateTimerDone(); // Call it one time manually, otherwise it wont get | ||
116 | // called at all when a button is pressed for a time | ||
117 | // shorter than RATE_TIMER_INTERVAL. | ||
118 | rateTimer->start( RATE_TIMER_INTERVAL, false ); | ||
119 | } | ||
120 | else | ||
121 | rateTimer->stop(); | ||
122 | } | ||
123 | |||
124 | void VolumeControl::rateTimerDone() | ||
125 | { | ||
126 | if ( upButton->isDown() ) | ||
127 | slider->setValue( slider->value() - 2 ); | ||
128 | else // downButton->isDown() | ||
129 | slider->setValue( slider->value() + 2 ); | ||
130 | } | ||
131 | |||
123 | //=========================================================================== | 132 | //=========================================================================== |
@@ -127,23 +136,9 @@ VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) | |||
127 | { | 136 | { |
128 | Config cfg("Sound"); | ||
129 | cfg.setGroup("System"); | ||
130 | |||
131 | setFixedHeight( 18 ); | 137 | setFixedHeight( 18 ); |
132 | setFixedWidth( 14 ); | 138 | setFixedWidth( 14 ); |
133 | |||
134 | volumePixmap = Resource::loadPixmap( "volume" ); | 139 | volumePixmap = Resource::loadPixmap( "volume" ); |
135 | |||
136 | volumePercent = cfg.readNumEntry("Volume",50); | ||
137 | micPercent = cfg.readNumEntry("Mic", 50); | ||
138 | muted = FALSE; // ### read from pref | 140 | muted = FALSE; // ### read from pref |
139 | micMuted = FALSE; // ### read from pref | 141 | volumePercent = 50; // ### read from pref |
140 | |||
141 | advancedTimer = new QTimer(this); | ||
142 | |||
143 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 142 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); |
144 | connect( qApp, SIGNAL( micChanged(bool) ), this, SLOT ( micChanged(bool) ) ); | ||
145 | connect( advancedTimer, SIGNAL( timeout() ),this, SLOT( advVolControl()) ); | ||
146 | |||
147 | writeSystemVolume(); | 143 | writeSystemVolume(); |
148 | writeSystemMic(); | ||
149 | } | 144 | } |
@@ -154,39 +149,7 @@ VolumeApplet::~VolumeApplet() | |||
154 | 149 | ||
155 | void VolumeApplet::keyPressEvent ( QKeyEvent * e ) | ||
156 | { | ||
157 | QString s; | ||
158 | s.setNum(e->key()); | ||
159 | qWarning(s); | ||
160 | } | ||
161 | void VolumeApplet::mousePressEvent( QMouseEvent * ) | 150 | void VolumeApplet::mousePressEvent( QMouseEvent * ) |
162 | { | 151 | { |
163 | advancedTimer->start( 750, TRUE ); | ||
164 | } | ||
165 | |||
166 | void VolumeApplet::mouseReleaseEvent( QMouseEvent * ) | ||
167 | { | ||
168 | showVolControl(FALSE); | ||
169 | } | ||
170 | |||
171 | void VolumeApplet::advVolControl() | ||
172 | { | ||
173 | showVolControl(TRUE); | ||
174 | } | ||
175 | |||
176 | void VolumeApplet::showVolControl(bool showMic) | ||
177 | { | ||
178 | Config cfg("Sound"); | ||
179 | cfg.setGroup("System"); | ||
180 | volumePercent = cfg.readNumEntry("Volume",50); | ||
181 | micPercent = cfg.readNumEntry("Mic", 50); | ||
182 | |||
183 | // Create a small volume control window to adjust the volume with | 152 | // Create a small volume control window to adjust the volume with |
184 | VolumeControl *vc = new VolumeControl(showMic); | 153 | VolumeControl *vc = new VolumeControl; |
185 | vc->slider->setValue( 100 - volumePercent ); | 154 | vc->slider->setValue( 100 - volumePercent ); |
186 | if (showMic) | ||
187 | { | ||
188 | vc->mic->setValue( 100 - micPercent ); | ||
189 | connect( vc->mic, SIGNAL( valueChanged( int ) ), this, SLOT( micMoved( int ) ) ); | ||
190 | } | ||
191 | |||
192 | vc->muteBox->setChecked( muted ); | 155 | vc->muteBox->setChecked( muted ); |
@@ -195,6 +158,4 @@ void VolumeApplet::showVolControl(bool showMic) | |||
195 | QPoint curPos = mapToGlobal( rect().topLeft() ); | 158 | QPoint curPos = mapToGlobal( rect().topLeft() ); |
196 | vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 120 ); | 159 | vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 ); |
197 | vc->show(); | 160 | vc->show(); |
198 | |||
199 | advancedTimer->stop(); | ||
200 | } | 161 | } |
@@ -220,9 +181,2 @@ void VolumeApplet::volumeChanged( bool nowMuted ) | |||
220 | 181 | ||
221 | void VolumeApplet::micChanged( bool nowMuted ) | ||
222 | { | ||
223 | if (!nowMuted) | ||
224 | readSystemMic(); | ||
225 | micMuted = nowMuted; | ||
226 | } | ||
227 | |||
228 | void VolumeApplet::mute( bool toggled ) | 182 | void VolumeApplet::mute( bool toggled ) |
@@ -230,3 +184,2 @@ void VolumeApplet::mute( bool toggled ) | |||
230 | muted = toggled; | 184 | muted = toggled; |
231 | |||
232 | // clear if removing mute | 185 | // clear if removing mute |
@@ -236,3 +189,2 @@ void VolumeApplet::mute( bool toggled ) | |||
236 | 189 | ||
237 | |||
238 | void VolumeApplet::sliderMoved( int percent ) | 190 | void VolumeApplet::sliderMoved( int percent ) |
@@ -242,7 +194,2 @@ void VolumeApplet::sliderMoved( int percent ) | |||
242 | 194 | ||
243 | void VolumeApplet::micMoved( int percent ) | ||
244 | { | ||
245 | setMic( 100 - percent ); | ||
246 | } | ||
247 | |||
248 | void VolumeApplet::readSystemVolume() | 195 | void VolumeApplet::readSystemVolume() |
@@ -254,9 +201,2 @@ void VolumeApplet::readSystemVolume() | |||
254 | 201 | ||
255 | void VolumeApplet::readSystemMic() | ||
256 | { | ||
257 | Config cfg("Sound"); | ||
258 | cfg.setGroup("System"); | ||
259 | micPercent = cfg.readNumEntry("Mic"); | ||
260 | } | ||
261 | |||
262 | void VolumeApplet::setVolume( int percent ) | 202 | void VolumeApplet::setVolume( int percent ) |
@@ -270,9 +210,2 @@ void VolumeApplet::setVolume( int percent ) | |||
270 | 210 | ||
271 | void VolumeApplet::setMic( int percent ) | ||
272 | { | ||
273 | // clamp volume percent to be between 0 and 100 | ||
274 | micPercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent); | ||
275 | writeSystemMic(); | ||
276 | } | ||
277 | |||
278 | void VolumeApplet::writeSystemVolume() | 211 | void VolumeApplet::writeSystemVolume() |
@@ -290,15 +223,2 @@ void VolumeApplet::writeSystemVolume() | |||
290 | 223 | ||
291 | void VolumeApplet::writeSystemMic() | ||
292 | { | ||
293 | { | ||
294 | Config cfg("Sound"); | ||
295 | cfg.setGroup("System"); | ||
296 | cfg.writeEntry("Mic",micPercent); | ||
297 | } | ||
298 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | ||
299 | // Send notification that the volume has changed | ||
300 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << micMuted; | ||
301 | #endif | ||
302 | } | ||
303 | |||
304 | void VolumeApplet::paintEvent( QPaintEvent* ) | 224 | void VolumeApplet::paintEvent( QPaintEvent* ) |