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,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,3 +45,3 @@
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 )
@@ -46,4 +49,15 @@ VolumeControl::VolumeControl( QWidget *parent, const char *name )
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 );
@@ -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 ); 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() ) );
@@ -94,3 +138,4 @@ void VolumeControl::keyPressEvent( QKeyEvent *e)
94{ 138{
95 switch(e->key()) { 139 switch(e->key())
140 {
96 case Key_Up: 141 case Key_Up:
@@ -136,9 +181,23 @@ VolumeApplet::VolumeApplet( QWidget *parent, const char *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}
@@ -149,7 +208,39 @@ VolumeApplet::~VolumeApplet()
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 );
@@ -158,4 +249,6 @@ void VolumeApplet::mousePressEvent( QMouseEvent *)
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}
@@ -181,2 +274,9 @@ void VolumeApplet::volumeChanged( bool nowMuted )
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 )
@@ -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
190void VolumeApplet::sliderMoved( int percent ) 292void VolumeApplet::sliderMoved( int percent )
@@ -194,2 +296,7 @@ void VolumeApplet::sliderMoved( int percent )
194 296
297void VolumeApplet::micMoved( int percent )
298{
299 setMic( 100 - percent );
300}
301
195void VolumeApplet::readSystemVolume() 302void VolumeApplet::readSystemVolume()
@@ -201,2 +308,9 @@ void VolumeApplet::readSystemVolume()
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 )
@@ -210,2 +324,9 @@ void VolumeApplet::setVolume( int percent )
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()
@@ -223,2 +344,15 @@ void VolumeApplet::writeSystemVolume()
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* )
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;
30class QCheckBox; 32class QCheckBox;
31class QPushButton;
32class QTimer;
33 33
@@ -37,3 +37,3 @@ class VolumeControl : public QFrame
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
@@ -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:
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:
@@ -50,6 +55,2 @@ private slots:
50 55
51private:
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
72private: 80private:
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
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};
@@ -85 +99,2 @@ private:
85#endif // __VOLUME_APPLET_H__ 99#endif // __VOLUME_APPLET_H__
100