summaryrefslogtreecommitdiff
path: root/core/applets/volumeapplet
authorllornkcor <llornkcor>2002-03-24 14:17:54 (UTC)
committer llornkcor <llornkcor>2002-03-24 14:17:54 (UTC)
commit032a2e2e88b60b8ef06f247709c117195fcab09a (patch) (unidiff)
treebd1cd69bb5418059f6830fc633f6cf23343f696d /core/applets/volumeapplet
parent927d5f33cc4c36541d7fb7dde036bdd22f5d7253 (diff)
downloadopie-032a2e2e88b60b8ef06f247709c117195fcab09a.zip
opie-032a2e2e88b60b8ef06f247709c117195fcab09a.tar.gz
opie-032a2e2e88b60b8ef06f247709c117195fcab09a.tar.bz2
added buttons from Markus (list)
Diffstat (limited to 'core/applets/volumeapplet') (more/less context) (show whitespace changes)
-rw-r--r--core/applets/volumeapplet/volume.cpp210
-rw-r--r--core/applets/volumeapplet/volume.h40
2 files changed, 81 insertions, 169 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,7 +1,7 @@
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**
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
@@ -33,78 +33,66 @@
33#include <qlayout.h> 33#include <qlayout.h>
34#include <qframe.h> 34#include <qframe.h>
35#include <qpixmap.h> 35#include <qpixmap.h>
36#include <qlabel.h> 36#include <qpushbutton.h>
37#include <qtimer.h>
37 38
38VolumeControl::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
43VolumeControl::VolumeControl( QWidget *parent, const char *name )
39 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) 44 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
40{ 45{
41 setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 46 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
42 createView(showMic);
43}
44
45void 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 );
54 slider->setRange( 0, 100 ); 61 slider->setRange( 0, 100 );
55 slider->setTickmarks( QSlider::Both ); 62 slider->setTickmarks( QSlider::Both );
56 slider->setTickInterval( 20 ); 63 slider->setTickInterval( 20 );
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}
103 92
104void VolumeControl::keyPressEvent( QKeyEvent *e) 93void VolumeControl::keyPressEvent( QKeyEvent *e)
105{ 94{
106 switch(e->key()) 95 switch(e->key()) {
107 {
108 case Key_Up: 96 case Key_Up:
109 slider->subtractStep(); 97 slider->subtractStep();
110 break; 98 break;
@@ -120,83 +108,56 @@ void VolumeControl::keyPressEvent( QKeyEvent *e)
120 } 108 }
121} 109}
122 110
111void 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
124void 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//===========================================================================
124 133
125VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) 134VolumeApplet::VolumeApplet( QWidget *parent, const char *name )
126 : QWidget( parent, name ) 135 : QWidget( parent, 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}
150 145
151VolumeApplet::~VolumeApplet() 146VolumeApplet::~VolumeApplet()
152{ 147{
153} 148}
154 149
155void VolumeApplet::keyPressEvent ( QKeyEvent * e )
156{
157 QString s;
158 s.setNum(e->key());
159 qWarning(s);
160}
161void VolumeApplet::mousePressEvent( QMouseEvent * ) 150void VolumeApplet::mousePressEvent( QMouseEvent * )
162{ 151{
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
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 );
193 connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) ); 156 connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) );
194 connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) ); 157 connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) );
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}
201 162
202void VolumeApplet::volumeChanged( bool nowMuted ) 163void VolumeApplet::volumeChanged( bool nowMuted )
@@ -218,33 +179,19 @@ void VolumeApplet::volumeChanged( bool nowMuted )
218 repaint( 2, height() - 3, width() - 4, 2, FALSE ); 179 repaint( 2, height() - 3, width() - 4, 2, FALSE );
219} 180}
220 181
221void VolumeApplet::micChanged( bool nowMuted )
222{
223 if (!nowMuted)
224 readSystemMic();
225 micMuted = nowMuted;
226}
227
228void VolumeApplet::mute( bool toggled ) 182void VolumeApplet::mute( bool toggled )
229{ 183{
230 muted = toggled; 184 muted = toggled;
231
232 // clear if removing mute 185 // clear if removing mute
233 repaint( !toggled ); 186 repaint( !toggled );
234 writeSystemVolume(); 187 writeSystemVolume();
235} 188}
236 189
237
238void VolumeApplet::sliderMoved( int percent ) 190void VolumeApplet::sliderMoved( int percent )
239{ 191{
240 setVolume( 100 - percent ); 192 setVolume( 100 - percent );
241} 193}
242 194
243void VolumeApplet::micMoved( int percent )
244{
245 setMic( 100 - percent );
246}
247
248void VolumeApplet::readSystemVolume() 195void VolumeApplet::readSystemVolume()
249{ 196{
250 Config cfg("Sound"); 197 Config cfg("Sound");
@@ -252,13 +199,6 @@ void VolumeApplet::readSystemVolume()
252 volumePercent = cfg.readNumEntry("Volume"); 199 volumePercent = cfg.readNumEntry("Volume");
253} 200}
254 201
255void VolumeApplet::readSystemMic()
256{
257 Config cfg("Sound");
258 cfg.setGroup("System");
259 micPercent = cfg.readNumEntry("Mic");
260}
261
262void VolumeApplet::setVolume( int percent ) 202void VolumeApplet::setVolume( int percent )
263{ 203{
264 // clamp volume percent to be between 0 and 100 204 // clamp volume percent to be between 0 and 100
@@ -268,13 +208,6 @@ void VolumeApplet::setVolume( int percent )
268 writeSystemVolume(); 208 writeSystemVolume();
269} 209}
270 210
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}
277
278void VolumeApplet::writeSystemVolume() 211void VolumeApplet::writeSystemVolume()
279{ 212{
280 { 213 {
@@ -288,19 +221,6 @@ void VolumeApplet::writeSystemVolume()
288#endif 221#endif
289} 222}
290 223
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}
303
304void VolumeApplet::paintEvent( QPaintEvent* ) 224void VolumeApplet::paintEvent( QPaintEvent* )
305{ 225{
306 QPainter p(this); 226 QPainter p(this);
diff --git a/core/applets/volumeapplet/volume.h b/core/applets/volumeapplet/volume.h
index cb0be72..a982f53 100644
--- a/core/applets/volumeapplet/volume.h
+++ b/core/applets/volumeapplet/volume.h
@@ -1,7 +1,7 @@
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**
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
@@ -25,25 +25,33 @@
25#include <qframe.h> 25#include <qframe.h>
26#include <qpixmap.h> 26#include <qpixmap.h>
27#include <qguardedptr.h> 27#include <qguardedptr.h>
28#include <qtimer.h>
29 28
30class QSlider; 29class QSlider;
31class QCheckBox; 30class QCheckBox;
31class QPushButton;
32class QTimer;
32 33
33class VolumeControl : public QFrame 34class VolumeControl : public QFrame
34{ 35{
35 Q_OBJECT 36 Q_OBJECT
36public: 37public:
37 VolumeControl( bool showMic=FALSE, QWidget *parent=0, const char *name=0 ); 38 VolumeControl( QWidget *parent=0, const char *name=0 );
38 39
39public: 40public:
40 QSlider *slider; 41 QSlider *slider;
41 QSlider *mic;
42 QCheckBox *muteBox; 42 QCheckBox *muteBox;
43 43
44private: 44private:
45 void keyPressEvent( QKeyEvent * ); 45 void keyPressEvent( QKeyEvent * );
46 void createView(bool showMic = FALSE); 46
47private slots:
48 void ButtonChanged();
49 void rateTimerDone();
50
51private:
52 QPushButton *upButton;
53 QPushButton *downButton;
54 QTimer *rateTimer;
47}; 55};
48 56
49class VolumeApplet : public QWidget 57class VolumeApplet : public QWidget
@@ -57,37 +65,21 @@ public:
57 65
58public slots: 66public slots:
59 void volumeChanged( bool muted ); 67 void volumeChanged( bool muted );
60 void micChanged( bool muted );
61
62 void setVolume( int percent ); 68 void setVolume( int percent );
63 void setMic( int percent );
64
65 void sliderMoved( int percent ); 69 void sliderMoved( int percent );
66 void micMoved( int percent );
67 void mute( bool ); 70 void mute( bool );
68 71
69 void showVolControl(bool showMic = FALSE);
70 void advVolControl();
71
72private: 72private:
73 void readSystemVolume(); 73 void readSystemVolume();
74 void readSystemMic();
75
76 void writeSystemVolume(); 74 void writeSystemVolume();
77 void writeSystemMic();
78
79 void keyPressEvent ( QKeyEvent * e );
80 void mousePressEvent( QMouseEvent * ); 75 void mousePressEvent( QMouseEvent * );
81 void mouseReleaseEvent( QMouseEvent *);
82 void paintEvent( QPaintEvent* ); 76 void paintEvent( QPaintEvent* );
83 77
84private: 78private:
85 int volumePercent, micPercent; 79 int volumePercent;
86 bool muted, micMuted; 80 bool muted;
87 QPixmap volumePixmap; 81 QPixmap volumePixmap;
88 QTimer *advancedTimer;
89}; 82};
90 83
91 84
92#endif // __VOLUME_APPLET_H__ 85#endif // __VOLUME_APPLET_H__
93