summaryrefslogtreecommitdiff
path: root/core/applets/volumeapplet/volume.cpp
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/volume.cpp
parent927d5f33cc4c36541d7fb7dde036bdd22f5d7253 (diff)
downloadopie-032a2e2e88b60b8ef06f247709c117195fcab09a.zip
opie-032a2e2e88b60b8ef06f247709c117195fcab09a.tar.gz
opie-032a2e2e88b60b8ef06f247709c117195fcab09a.tar.bz2
added buttons from Markus (list)
Diffstat (limited to 'core/applets/volumeapplet/volume.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/volumeapplet/volume.cpp324
1 files changed, 122 insertions, 202 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,170 +33,131 @@
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
39 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) 40// Ten times per second is fine (RATE_TIMER_INTERVAL 100). A shorter time
40{ 41// results in "hanging" buttons on the iPAQ due to quite high CPU consumption.
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");
49
50 QVBoxLayout *vbox = new QVBoxLayout( this );
51 QHBoxLayout *hbox = NULL;
52
53 slider = new QSlider( this );
54 slider->setRange( 0, 100 );
55 slider->setTickmarks( QSlider::Both );
56 slider->setTickInterval( 20 );
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 42
81 hbox = new QHBoxLayout( this ); 43VolumeControl::VolumeControl( QWidget *parent, const char *name )
82 hbox->setMargin( 3 ); 44 : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup )
83 hbox->setSpacing( 3 );
84 hbox->addLayout( sbox, 1);
85 hbox->addLayout( mbox, 1);
86 }
87
88 muteBox = new QCheckBox( tr("Mute"), this );
89 muteBox->setFocusPolicy( QWidget::NoFocus );
90
91 vbox->setMargin( 3 );
92 vbox->setSpacing( 0 );
93 if (showMic == TRUE)
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 );
100 setFixedWidth( sizeHint().width() );
101 setFocusPolicy(QWidget::NoFocus);
102}
103
104void VolumeControl::keyPressEvent( QKeyEvent *e)
105{ 45{
106 switch(e->key()) 46 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
107 { 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;
60 slider = new QSlider( this );
61 slider->setRange( 0, 100 );
62 slider->setTickmarks( QSlider::Both );
63 slider->setTickInterval( 20 );
64 slider->setFocusPolicy( QWidget::NoFocus );
65 hbox->setSpacing( 4 );
66 hbox->addWidget( slider );
67 hbox->addLayout( vboxButtons );
68
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 );
73 muteBox->setFocusPolicy( QWidget::NoFocus );
74 vbox->setSpacing( 4 );
75 vbox->setMargin( 6 );
76 vbox->addLayout( hbox );
77 vbox->addWidget( separator );
78 vbox->addWidget( muteBox, 0, Qt::AlignVCenter | Qt::AlignHCenter );
79
80 setFixedHeight( 100 );
81 setFixedWidth( sizeHint().width() );
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() ) );
91}
92
93void VolumeControl::keyPressEvent( QKeyEvent *e)
94{
95 switch(e->key()) {
108 case Key_Up: 96 case Key_Up:
109 slider->subtractStep(); 97 slider->subtractStep();
110 break; 98 break;
111 case Key_Down: 99 case Key_Down:
112 slider->addStep(); 100 slider->addStep();
113 break; 101 break;
114 case Key_Space: 102 case Key_Space:
115 muteBox->toggle(); 103 muteBox->toggle();
116 break; 104 break;
117 case Key_Escape: 105 case Key_Escape:
118 close(); 106 close();
119 break; 107 break;
120 } 108 }
121} 109}
122 110
123//=========================================================================== 111void VolumeControl::ButtonChanged()
124
125VolumeApplet::VolumeApplet( QWidget *parent, const char *name )
126 : QWidget( parent, name )
127{ 112{
128 Config cfg("Sound"); 113 if ( upButton->isDown() || downButton->isDown() )
129 cfg.setGroup("System"); 114 {
130 115 rateTimerDone(); // Call it one time manually, otherwise it wont get
131 setFixedHeight( 18 ); 116 // called at all when a button is pressed for a time
132 setFixedWidth( 14 ); 117 // shorter than RATE_TIMER_INTERVAL.
133 118 rateTimer->start( RATE_TIMER_INTERVAL, false );
134 volumePixmap = Resource::loadPixmap( "volume" ); 119 }
135 120 else
136 volumePercent = cfg.readNumEntry("Volume",50); 121 rateTimer->stop();
137 micPercent = cfg.readNumEntry("Mic", 50);
138 muted = FALSE; // ### read from pref
139 micMuted = FALSE; // ### read from pref
140
141 advancedTimer = new QTimer(this);
142
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
147 writeSystemVolume();
148 writeSystemMic();
149} 122}
150 123
151VolumeApplet::~VolumeApplet() 124void VolumeControl::rateTimerDone()
152{ 125{
126 if ( upButton->isDown() )
127 slider->setValue( slider->value() - 2 );
128 else // downButton->isDown()
129 slider->setValue( slider->value() + 2 );
153} 130}
154 131
155void VolumeApplet::keyPressEvent ( QKeyEvent * e ) 132//===========================================================================
156{
157 QString s;
158 s.setNum(e->key());
159 qWarning(s);
160}
161void VolumeApplet::mousePressEvent( QMouseEvent * )
162{
163 advancedTimer->start( 750, TRUE );
164}
165 133
166void VolumeApplet::mouseReleaseEvent( QMouseEvent * ) 134VolumeApplet::VolumeApplet( QWidget *parent, const char *name )
135 : QWidget( parent, name )
167{ 136{
168 showVolControl(FALSE); 137 setFixedHeight( 18 );
138 setFixedWidth( 14 );
139 volumePixmap = Resource::loadPixmap( "volume" );
140 muted = FALSE; // ### read from pref
141 volumePercent = 50; // ### read from pref
142 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
143 writeSystemVolume();
169} 144}
170 145
171void VolumeApplet::advVolControl() 146VolumeApplet::~VolumeApplet()
172{ 147{
173 showVolControl(TRUE);
174} 148}
175 149
176void VolumeApplet::showVolControl(bool showMic) 150void VolumeApplet::mousePressEvent( QMouseEvent *)
177{ 151{
178 Config cfg("Sound"); 152 // Create a small volume control window to adjust the volume with
179 cfg.setGroup("System"); 153 VolumeControl *vc = new VolumeControl;
180 volumePercent = cfg.readNumEntry("Volume",50); 154 vc->slider->setValue( 100 - volumePercent );
181 micPercent = cfg.readNumEntry("Mic", 50); 155 vc->muteBox->setChecked( muted );
182 156 connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) );
183 // Create a small volume control window to adjust the volume with 157 connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) );
184 VolumeControl *vc = new VolumeControl(showMic); 158 QPoint curPos = mapToGlobal( rect().topLeft() );
185 vc->slider->setValue( 100 - volumePercent ); 159 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 100 );
186 if (showMic) 160 vc->show();
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 );
193 connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) );
194 connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) );
195 QPoint curPos = mapToGlobal( rect().topLeft() );
196 vc->move( curPos.x()-(vc->sizeHint().width()-width())/2, curPos.y() - 120 );
197 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,58 +208,38 @@ 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 {
281 Config cfg("Sound"); 214 Config cfg("Sound");
282 cfg.setGroup("System"); 215 cfg.setGroup("System");
283 cfg.writeEntry("Volume",volumePercent); 216 cfg.writeEntry("Volume",volumePercent);
284 } 217 }
285#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
286 // Send notification that the volume has changed
287 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
288#endif
289}
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) 218#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
299 // Send notification that the volume has changed 219 // Send notification that the volume has changed
300 QCopEnvelope( "QPE/System", "micChange(bool)" ) << micMuted; 220 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
301#endif 221#endif
302} 222}
303 223
304void VolumeApplet::paintEvent( QPaintEvent* ) 224void VolumeApplet::paintEvent( QPaintEvent* )
305{ 225{
306 QPainter p(this); 226 QPainter p(this);
307 227
308 if (volumePixmap.isNull()) 228 if (volumePixmap.isNull())
309 volumePixmap = Resource::loadPixmap( "volume" ); 229 volumePixmap = Resource::loadPixmap( "volume" );
310 p.drawPixmap( 0, 1, volumePixmap ); 230 p.drawPixmap( 0, 1, volumePixmap );
311 p.setPen( darkGray ); 231 p.setPen( darkGray );
312 p.drawRect( 1, height() - 4, width() - 2, 4 ); 232 p.drawRect( 1, height() - 4, width() - 2, 4 );
313 233
314 int pixelsWide = volumePercent * (width() - 4) / 100; 234 int pixelsWide = volumePercent * (width() - 4) / 100;
315 p.fillRect( 2, height() - 3, pixelsWide, 2, red ); 235 p.fillRect( 2, height() - 3, pixelsWide, 2, red );
316 p.fillRect( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); 236 p.fillRect( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray );
317 237
318 if ( muted ) { 238 if ( muted ) {
319 p.setPen( red ); 239 p.setPen( red );
320 p.drawLine( 1, 2, width() - 2, height() - 5 ); 240 p.drawLine( 1, 2, width() - 2, height() - 5 );
321 p.drawLine( 1, 3, width() - 2, height() - 4 ); 241 p.drawLine( 1, 3, width() - 2, height() - 4 );
322 p.drawLine( width() - 2, 2, 1, height() - 5 ); 242 p.drawLine( width() - 2, 2, 1, height() - 5 );
323 p.drawLine( width() - 2, 3, 1, height() - 4 ); 243 p.drawLine( width() - 2, 3, 1, height() - 4 );
324 } 244 }
325} 245}