summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/applets/volumeapplet/volume.cpp176
-rw-r--r--core/applets/volumeapplet/volume.h45
2 files changed, 185 insertions, 36 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,7 +1,7 @@
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**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
@@ -18,6 +18,7 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21
21#include "volume.h" 22#include "volume.h"
22 23
23#include <qpe/resource.h> 24#include <qpe/resource.h>
@@ -33,6 +34,8 @@
33#include <qlayout.h> 34#include <qlayout.h>
34#include <qframe.h> 35#include <qframe.h>
35#include <qpixmap.h> 36#include <qpixmap.h>
37#include <qlabel.h>
38
36#include <qpushbutton.h> 39#include <qpushbutton.h>
37#include <qtimer.h> 40#include <qtimer.h>
38 41
@@ -40,12 +43,23 @@
40// Ten times per second is fine (RATE_TIMER_INTERVAL 100). A shorter time 43// 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. 44// results in "hanging" buttons on the iPAQ due to quite high CPU consumption.
42 45
43VolumeControl::VolumeControl( QWidget *parent, const char *name ) 46VolumeControl::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
53void 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 );
50 upButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); 64 upButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
51 upButton->setPixmap( Resource::loadPixmap( "up" ) ); 65 upButton->setPixmap( Resource::loadPixmap( "up" ) );
@@ -53,34 +67,64 @@ VolumeControl::VolumeControl( QWidget *parent, const char *name )
53 downButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); 67 downButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
54 downButton->setPixmap( Resource::loadPixmap( "down" ) ); 68 downButton->setPixmap( Resource::loadPixmap( "down" ) );
55 vboxButtons->setSpacing( 2 ); 69 vboxButtons->setSpacing( 2 );
70
56 vboxButtons->addWidget( upButton ); 71 vboxButtons->addWidget( upButton );
57 vboxButtons->addWidget( downButton ); 72 vboxButtons->addWidget( downButton );
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 );
61 slider->setRange( 0, 100 ); 78 slider->setRange( 0, 100 );
62 slider->setTickmarks( QSlider::Both ); 79 slider->setTickmarks( QSlider::Both );
63 slider->setTickInterval( 20 ); 80 slider->setTickInterval( 20 );
64 slider->setFocusPolicy( QWidget::NoFocus ); 81 slider->setFocusPolicy( QWidget::NoFocus );
65 hbox->setSpacing( 4 ); 82 slider->setValue(cfg.readNumEntry("Volume"));
66 hbox->addWidget( slider ); 83
67 hbox->addLayout( vboxButtons ); 84 QVBoxLayout *sbox = new QVBoxLayout(this);
85 sbox->setMargin( 3 );
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 }
68 110
69 QVBoxLayout *vbox = new QVBoxLayout( this );
70 QFrame *separator = new QFrame( this );
71 separator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
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() ) );
85 connect( upButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) ); 129 connect( upButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) );
86 connect( downButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); 130 connect( downButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) );
@@ -92,7 +136,8 @@ VolumeControl::VolumeControl( QWidget *parent, const char *name )
92 136
93void VolumeControl::keyPressEvent( QKeyEvent *e) 137void VolumeControl::keyPressEvent( QKeyEvent *e)
94{ 138{
95 switch(e->key()) { 139 switch(e->key())
140 {
96 case Key_Up: 141 case Key_Up:
97 slider->subtractStep(); 142 slider->subtractStep();
98 break; 143 break;
@@ -134,30 +179,78 @@ void VolumeControl::rateTimerDone()
134VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) 179VolumeApplet::VolumeApplet( QWidget *parent, const char *name )
135 : QWidget( parent, name ) 180 : QWidget( parent, name )
136{ 181{
182 Config cfg("Sound");
183 cfg.setGroup("System");
184
137 setFixedHeight( 18 ); 185 setFixedHeight( 18 );
138 setFixedWidth( 14 ); 186 setFixedWidth( 14 );
187
139 volumePixmap = Resource::loadPixmap( "volume" ); 188 volumePixmap = Resource::loadPixmap( "volume" );
189
190 volumePercent = cfg.readNumEntry("Volume",50);
191 micPercent = cfg.readNumEntry("Mic", 50);
140 muted = FALSE; // ### read from pref 192 muted = FALSE; // ### read from pref
141 volumePercent = 50; // ### read from pref 193 micMuted = FALSE; // ### read from pref
194
195 advancedTimer = new QTimer(this);
196
142 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); 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
143 writeSystemVolume(); 201 writeSystemVolume();
202 writeSystemMic();
144} 203}
145 204
146VolumeApplet::~VolumeApplet() 205VolumeApplet::~VolumeApplet()
147{ 206{
148} 207}
149 208
209void VolumeApplet::keyPressEvent ( QKeyEvent * e )
210{
211 QString s;
212 s.setNum(e->key());
213 qWarning(s);
214}
150void VolumeApplet::mousePressEvent( QMouseEvent *) 215void VolumeApplet::mousePressEvent( QMouseEvent *)
151{ 216{
217 advancedTimer->start( 750, TRUE );
218}
219
220void VolumeApplet::mouseReleaseEvent( QMouseEvent * )
221{
222 showVolControl(FALSE);
223}
224
225void VolumeApplet::advVolControl()
226{
227 showVolControl(TRUE);
228}
229
230void 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
152 // Create a small volume control window to adjust the volume with 237 // Create a small volume control window to adjust the volume with
153 VolumeControl *vc = new VolumeControl; 238 VolumeControl *vc = new VolumeControl(showMic);
154 vc->slider->setValue( 100 - volumePercent ); 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
155 vc->muteBox->setChecked( muted ); 246 vc->muteBox->setChecked( muted );
156 connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) ); 247 connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) );
157 connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) ); 248 connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) );
158 QPoint curPos = mapToGlobal( rect().topLeft() ); 249 QPoint curPos = mapToGlobal( rect().topLeft() );
159 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 ); 250 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 120 );
160 vc->show(); 251 vc->show();
252
253 advancedTimer->stop();
161} 254}
162 255
163void VolumeApplet::volumeChanged( bool nowMuted ) 256void VolumeApplet::volumeChanged( bool nowMuted )
@@ -179,19 +272,33 @@ void VolumeApplet::volumeChanged( bool nowMuted )
179 repaint( 2, height() - 3, width() - 4, 2, FALSE ); 272 repaint( 2, height() - 3, width() - 4, 2, FALSE );
180} 273}
181 274
275void VolumeApplet::micChanged( bool nowMuted )
276{
277 if (!nowMuted)
278 readSystemMic();
279 micMuted = nowMuted;
280}
281
182void VolumeApplet::mute( bool toggled ) 282void VolumeApplet::mute( bool toggled )
183{ 283{
184 muted = toggled; 284 muted = toggled;
285
185 // clear if removing mute 286 // clear if removing mute
186 repaint( !toggled ); 287 repaint( !toggled );
187 writeSystemVolume(); 288 writeSystemVolume();
188} 289}
189 290
291
190void VolumeApplet::sliderMoved( int percent ) 292void VolumeApplet::sliderMoved( int percent )
191{ 293{
192 setVolume( 100 - percent ); 294 setVolume( 100 - percent );
193} 295}
194 296
297void VolumeApplet::micMoved( int percent )
298{
299 setMic( 100 - percent );
300}
301
195void VolumeApplet::readSystemVolume() 302void VolumeApplet::readSystemVolume()
196{ 303{
197 Config cfg("Sound"); 304 Config cfg("Sound");
@@ -199,6 +306,13 @@ void VolumeApplet::readSystemVolume()
199 volumePercent = cfg.readNumEntry("Volume"); 306 volumePercent = cfg.readNumEntry("Volume");
200} 307}
201 308
309void VolumeApplet::readSystemMic()
310{
311 Config cfg("Sound");
312 cfg.setGroup("System");
313 micPercent = cfg.readNumEntry("Mic");
314}
315
202void VolumeApplet::setVolume( int percent ) 316void VolumeApplet::setVolume( int percent )
203{ 317{
204 // clamp volume percent to be between 0 and 100 318 // clamp volume percent to be between 0 and 100
@@ -208,6 +322,13 @@ void VolumeApplet::setVolume( int percent )
208 writeSystemVolume(); 322 writeSystemVolume();
209} 323}
210 324
325void 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
211void VolumeApplet::writeSystemVolume() 332void VolumeApplet::writeSystemVolume()
212{ 333{
213 { 334 {
@@ -221,6 +342,19 @@ void VolumeApplet::writeSystemVolume()
221#endif 342#endif
222} 343}
223 344
345void VolumeApplet::writeSystemMic()
346{
347 {
348 Config cfg("Sound");
349 cfg.setGroup("System");
350 cfg.writeEntry("Mic",micPercent);
351 }
352#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
353 // Send notification that the volume has changed
354 QCopEnvelope( "QPE/System", "micChange(bool)" ) << micMuted;
355#endif
356}
357
224void VolumeApplet::paintEvent( QPaintEvent* ) 358void VolumeApplet::paintEvent( QPaintEvent* )
225{ 359{
226 QPainter p(this); 360 QPainter p(this);
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,7 +1,7 @@
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**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
@@ -17,6 +17,7 @@
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20
20#ifndef __VOLUME_APPLET_H__ 21#ifndef __VOLUME_APPLET_H__
21#define __VOLUME_APPLET_H__ 22#define __VOLUME_APPLET_H__
22 23
@@ -25,33 +26,33 @@
25#include <qframe.h> 26#include <qframe.h>
26#include <qpixmap.h> 27#include <qpixmap.h>
27#include <qguardedptr.h> 28#include <qguardedptr.h>
29#include <qtimer.h>
28 30
29class QSlider; 31class QSlider;
30class QCheckBox; 32class QCheckBox;
31class QPushButton;
32class QTimer;
33 33
34class VolumeControl : public QFrame 34class VolumeControl : public QFrame
35{ 35{
36 Q_OBJECT 36 Q_OBJECT
37public: 37public:
38 VolumeControl( QWidget *parent=0, const char *name=0 ); 38 VolumeControl( bool showMic=FALSE, QWidget *parent=0, const char *name=0 );
39 39
40public: 40public:
41 QSlider *slider; 41 QSlider *slider;
42 QSlider *mic;
42 QCheckBox *muteBox; 43 QCheckBox *muteBox;
43 44
44private: 45private:
45 void keyPressEvent( QKeyEvent * ); 46 QPushButton *upButton;
47 QPushButton *downButton;
48 QTimer *rateTimer;
46 49
50 void keyPressEvent( QKeyEvent * );
51 void createView(bool showMic = FALSE);
47private slots: 52private slots:
48 void ButtonChanged(); 53 void ButtonChanged();
49 void rateTimerDone(); 54 void rateTimerDone();
50 55
51private:
52 QPushButton *upButton;
53 QPushButton *downButton;
54 QTimer *rateTimer;
55}; 56};
56 57
57class VolumeApplet : public QWidget 58class VolumeApplet : public QWidget
@@ -65,21 +66,35 @@ public:
65 66
66public slots: 67public 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 );
70 void mute( bool ); 71 void mute( bool );
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
72private: 80private:
81 int volumePercent, micPercent;
82 bool muted, micMuted;
83 QPixmap volumePixmap;
84 QTimer *advancedTimer;
85
73 void readSystemVolume(); 86 void readSystemVolume();
74 void writeSystemVolume(); 87 void writeSystemVolume();
75 void mousePressEvent( QMouseEvent * ); 88 void mousePressEvent( QMouseEvent * );
76 void paintEvent( QPaintEvent* ); 89 void paintEvent( QPaintEvent* );
77 90
78private: 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};
83 97
84 98
85#endif // __VOLUME_APPLET_H__ 99#endif // __VOLUME_APPLET_H__
100