summaryrefslogtreecommitdiff
path: root/core/applets/volumeapplet
authorjeremy <jeremy>2002-02-10 13:20:54 (UTC)
committer jeremy <jeremy>2002-02-10 13:20:54 (UTC)
commitd0d626304ffb0de247e22760bc342e72406e301a (patch) (unidiff)
treef547ac0cfc33f1d55da1f0743df72f2f7498efa1 /core/applets/volumeapplet
parent16db9b9928f9111f384c202c43a95fac88279b3d (diff)
downloadopie-d0d626304ffb0de247e22760bc342e72406e301a.zip
opie-d0d626304ffb0de247e22760bc342e72406e301a.tar.gz
opie-d0d626304ffb0de247e22760bc342e72406e301a.tar.bz2
Added support for the new setMic and micChange messages in opie-base.
Alos modified the volume control and mic control to read the last set position (as recorded in Sound.conf) instead of always defaulting the sound to 50% as before the change.
Diffstat (limited to 'core/applets/volumeapplet') (more/less context) (show whitespace changes)
-rw-r--r--core/applets/volumeapplet/opie-volumeapplet.control2
-rw-r--r--core/applets/volumeapplet/volume.cpp154
-rw-r--r--core/applets/volumeapplet/volume.h24
3 files changed, 162 insertions, 18 deletions
diff --git a/core/applets/volumeapplet/opie-volumeapplet.control b/core/applets/volumeapplet/opie-volumeapplet.control
index a65cf6d..a2c0363 100644
--- a/core/applets/volumeapplet/opie-volumeapplet.control
+++ b/core/applets/volumeapplet/opie-volumeapplet.control
@@ -5,3 +5,3 @@ Maintainer: Warwick Allison <warwick@trolltech.com>
5Architecture: arm 5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION 6Version: $QPE_VERSION-$SUB_VERSION.1
7Depends: opie-base ($QPE_VERSION) 7Depends: opie-base ($QPE_VERSION)
diff --git a/core/applets/volumeapplet/volume.cpp b/core/applets/volumeapplet/volume.cpp
index 35dbf22..445cc8b 100644
--- a/core/applets/volumeapplet/volume.cpp
+++ b/core/applets/volumeapplet/volume.cpp
@@ -35,5 +35,5 @@
35#include <qpixmap.h> 35#include <qpixmap.h>
36#include <qlabel.h>
36 37
37 38VolumeControl::VolumeControl( bool showMic, QWidget *parent, const char *name )
38VolumeControl::VolumeControl( QWidget *parent, const char *name )
39 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) 39 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
@@ -41,6 +41,14 @@ VolumeControl::VolumeControl( QWidget *parent, const char *name )
41 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 41 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
42 createView(showMic);
43}
44
45void VolumeControl::createView(bool showMic)
46{
47 Config cfg("Sound");
48 cfg.setGroup("System");
42 49
43 QVBoxLayout *vbox = new QVBoxLayout( this ); 50 QVBoxLayout *vbox = new QVBoxLayout( this );
51 QHBoxLayout *hbox = NULL;
52
44 slider = new QSlider( this ); 53 slider = new QSlider( this );
45 muteBox = new QCheckBox( tr("Mute"), this );
46 slider->setRange( 0, 100 ); 54 slider->setRange( 0, 100 );
@@ -49,8 +57,44 @@ VolumeControl::VolumeControl( QWidget *parent, const char *name )
49 slider->setFocusPolicy( QWidget::NoFocus ); 57 slider->setFocusPolicy( QWidget::NoFocus );
58 slider->setValue(cfg.readNumEntry("Volume"));
59
60 QVBoxLayout *sbox = new QVBoxLayout(this);
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
88 muteBox = new QCheckBox( tr("Mute"), this );
50 muteBox->setFocusPolicy( QWidget::NoFocus ); 89 muteBox->setFocusPolicy( QWidget::NoFocus );
51 vbox->setMargin( 6 ); 90
52 vbox->setSpacing( 3 ); 91 vbox->setMargin( 3 );
53 vbox->addWidget( slider, 0, Qt::AlignVCenter | Qt::AlignHCenter ); 92 vbox->setSpacing( 0 );
54 vbox->addWidget( muteBox ); 93 if (showMic == TRUE)
55 setFixedHeight( 100 ); 94 vbox->addLayout( hbox, 1 );
95 else
96 vbox->addLayout( sbox, 1);
97 vbox->addWidget( muteBox, 0, Qt::AlignVCenter | Qt::AlignHCenter );
98
99 setFixedHeight( 120 );
56 setFixedWidth( sizeHint().width() ); 100 setFixedWidth( sizeHint().width() );
@@ -61,3 +105,4 @@ void VolumeControl::keyPressEvent( QKeyEvent *e)
61{ 105{
62 switch(e->key()) { 106 switch(e->key())
107 {
63 case Key_Up: 108 case Key_Up:
@@ -82,9 +127,23 @@ VolumeApplet::VolumeApplet( QWidget *parent, const char *name )
82{ 127{
128 Config cfg("Sound");
129 cfg.setGroup("System");
130
83 setFixedHeight( 18 ); 131 setFixedHeight( 18 );
84 setFixedWidth( 14 ); 132 setFixedWidth( 14 );
133
85 volumePixmap = Resource::loadPixmap( "volume" ); 134 volumePixmap = Resource::loadPixmap( "volume" );
135
136 volumePercent = cfg.readNumEntry("Volume",50);
137 micPercent = cfg.readNumEntry("Mic", 50);
86 muted = FALSE; // ### read from pref 138 muted = FALSE; // ### read from pref
87 volumePercent = 50; // ### read from pref 139 micMuted = FALSE; // ### read from pref
140
141 advancedTimer = new QTimer(this);
142
88 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); 143 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
89 writeSystemVolume(); 147 writeSystemVolume();
148 writeSystemMic();
90} 149}
@@ -95,7 +154,39 @@ VolumeApplet::~VolumeApplet()
95 154
155void VolumeApplet::keyPressEvent ( QKeyEvent * e )
156{
157 QString s;
158 s.setNum(e->key());
159 qWarning(s);
160}
96void VolumeApplet::mousePressEvent( QMouseEvent *) 161void VolumeApplet::mousePressEvent( QMouseEvent *)
97{ 162{
163 advancedTimer->start( 750, TRUE );
164}
165
166void VolumeApplet::mouseReleaseEvent( QMouseEvent * )
167{
168 showVolControl(FALSE);
169}
170
171void VolumeApplet::advVolControl()
172{
173 showVolControl(TRUE);
174}
175
176void 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
98 // Create a small volume control window to adjust the volume with 183 // Create a small volume control window to adjust the volume with
99 VolumeControl *vc = new VolumeControl; 184 VolumeControl *vc = new VolumeControl(showMic);
100 vc->slider->setValue( 100 - volumePercent ); 185 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
101 vc->muteBox->setChecked( muted ); 192 vc->muteBox->setChecked( muted );
@@ -104,4 +195,6 @@ void VolumeApplet::mousePressEvent( QMouseEvent *)
104 QPoint curPos = mapToGlobal( rect().topLeft() ); 195 QPoint curPos = mapToGlobal( rect().topLeft() );
105 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 ); 196 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 120 );
106 vc->show(); 197 vc->show();
198
199 advancedTimer->stop();
107} 200}
@@ -127,2 +220,8 @@ void VolumeApplet::volumeChanged( bool nowMuted )
127 220
221void VolumeApplet::micChanged( bool nowMuted )
222{
223 if (!nowMuted)
224 readSystemMic();
225 micMuted = nowMuted;
226}
128 227
@@ -131,2 +230,3 @@ void VolumeApplet::mute( bool toggled )
131 muted = toggled; 230 muted = toggled;
231
132 // clear if removing mute 232 // clear if removing mute
@@ -142,2 +242,6 @@ void VolumeApplet::sliderMoved( int percent )
142 242
243void VolumeApplet::micMoved( int percent )
244{
245 setMic( 100 - percent );
246}
143 247
@@ -150,2 +254,8 @@ void VolumeApplet::readSystemVolume()
150 254
255void VolumeApplet::readSystemMic()
256{
257 Config cfg("Sound");
258 cfg.setGroup("System");
259 micPercent = cfg.readNumEntry("Mic");
260}
151 261
@@ -160,2 +270,8 @@ void VolumeApplet::setVolume( int percent )
160 270
271void 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}
161 277
@@ -174,2 +290,14 @@ void VolumeApplet::writeSystemVolume()
174 290
291void 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}
175 303
@@ -197,3 +325 @@ void VolumeApplet::paintEvent( QPaintEvent* )
197} }
198
199
diff --git a/core/applets/volumeapplet/volume.h b/core/applets/volumeapplet/volume.h
index 5704cad..cb0be72 100644
--- a/core/applets/volumeapplet/volume.h
+++ b/core/applets/volumeapplet/volume.h
@@ -27,2 +27,3 @@
27#include <qguardedptr.h> 27#include <qguardedptr.h>
28#include <qtimer.h>
28 29
@@ -35,3 +36,3 @@ class VolumeControl : public QFrame
35public: 36public:
36 VolumeControl( QWidget *parent=0, const char *name=0 ); 37 VolumeControl( bool showMic=FALSE, QWidget *parent=0, const char *name=0 );
37 38
@@ -39,2 +40,3 @@ public:
39 QSlider *slider; 40 QSlider *slider;
41 QSlider *mic;
40 QCheckBox *muteBox; 42 QCheckBox *muteBox;
@@ -43,2 +45,3 @@ private:
43 void keyPressEvent( QKeyEvent * ); 45 void keyPressEvent( QKeyEvent * );
46 void createView(bool showMic = FALSE);
44}; 47};
@@ -56,10 +59,24 @@ public slots:
56 void volumeChanged( bool muted ); 59 void volumeChanged( bool muted );
60 void micChanged( bool muted );
61
57 void setVolume( int percent ); 62 void setVolume( int percent );
63 void setMic( int percent );
64
58 void sliderMoved( int percent ); 65 void sliderMoved( int percent );
66 void micMoved( int percent );
59 void mute( bool ); 67 void mute( bool );
60 68
69 void showVolControl(bool showMic = FALSE);
70 void advVolControl();
71
61private: 72private:
62 void readSystemVolume(); 73 void readSystemVolume();
74 void readSystemMic();
75
63 void writeSystemVolume(); 76 void writeSystemVolume();
77 void writeSystemMic();
78
79 void keyPressEvent ( QKeyEvent * e );
64 void mousePressEvent( QMouseEvent * ); 80 void mousePressEvent( QMouseEvent * );
81 void mouseReleaseEvent( QMouseEvent *);
65 void paintEvent( QPaintEvent* ); 82 void paintEvent( QPaintEvent* );
@@ -67,5 +84,6 @@ private:
67private: 84private:
68 int volumePercent; 85 int volumePercent, micPercent;
69 bool muted; 86 bool muted, micMuted;
70 QPixmap volumePixmap; 87 QPixmap volumePixmap;
88 QTimer *advancedTimer;
71}; 89};