-rw-r--r-- | core/applets/volumeapplet/oledbox.cpp | 270 | ||||
-rw-r--r-- | core/applets/volumeapplet/oledbox.h | 51 | ||||
-rw-r--r-- | core/applets/volumeapplet/volume.cpp | 744 | ||||
-rw-r--r-- | core/applets/volumeapplet/volume.h | 124 | ||||
-rw-r--r-- | core/applets/volumeapplet/volumeapplet.pro | 4 | ||||
-rw-r--r-- | core/applets/volumeapplet/volumeappletimpl.cpp | 9 |
6 files changed, 857 insertions, 345 deletions
diff --git a/core/applets/volumeapplet/oledbox.cpp b/core/applets/volumeapplet/oledbox.cpp new file mode 100644 index 0000000..3036929 --- a/dev/null +++ b/core/applets/volumeapplet/oledbox.cpp | |||
@@ -0,0 +1,270 @@ | |||
1 | |||
2 | #include <qpixmap.h> | ||
3 | #include <qbitmap.h> | ||
4 | #include <qpainter.h> | ||
5 | |||
6 | #include "oledbox.h" | ||
7 | |||
8 | |||
9 | #ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC | ||
10 | |||
11 | /* XPM */ | ||
12 | static const char * ledborder_xpm[] = { | ||
13 | "16 16 11 1", | ||
14 | " c None", | ||
15 | ".c #626562", | ||
16 | "+c #7B7D7B", | ||
17 | "@c #949594", | ||
18 | "#c #ACAEAC", | ||
19 | "$c #CDCACD", | ||
20 | "%c #CDCECD", | ||
21 | ";c #E6E6E6", | ||
22 | ">c #FFFFFF", | ||
23 | ",c #E6E2E6", | ||
24 | "'c #FFFAFF", | ||
25 | " .++@@# ", | ||
26 | " ...++@@##$ ", | ||
27 | " .....+@##$$% ", | ||
28 | " ..... #$%%% ", | ||
29 | " ... %%; ", | ||
30 | ".... ;;;;", | ||
31 | "++. ;>>", | ||
32 | "+++ >>>", | ||
33 | "@@@ >>>", | ||
34 | "@@# >>>", | ||
35 | "#### >>>>", | ||
36 | " #$$ >>> ", | ||
37 | " $$,,' >>>>> ", | ||
38 | " ,,,''>>>>>>> ", | ||
39 | " ,''>>>>>>> ", | ||
40 | " '>>>>> "}; | ||
41 | |||
42 | |||
43 | QPixmap *OLedBox::s_border_pix = 0; | ||
44 | |||
45 | #endif | ||
46 | |||
47 | |||
48 | OLedBox::OLedBox ( const QColor &col, QWidget *parent, const char *name ) : QWidget ( parent, name ) | ||
49 | { | ||
50 | m_color = col; | ||
51 | m_on = false; | ||
52 | |||
53 | m_pix [ 0 ] = m_pix [ 1 ] = false; | ||
54 | |||
55 | setBackgroundMode ( PaletteBackground ); | ||
56 | |||
57 | #ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC | ||
58 | if ( !s_border_pix ) | ||
59 | s_border_pix = new QPixmap ( ledborder_xpm ); | ||
60 | #endif | ||
61 | } | ||
62 | |||
63 | OLedBox::~OLedBox ( ) | ||
64 | { | ||
65 | delete m_pix [ 0 ]; | ||
66 | delete m_pix [ 1 ]; | ||
67 | } | ||
68 | |||
69 | QSize OLedBox::sizeHint ( ) const | ||
70 | { | ||
71 | return QSize ( 16, 16 ); | ||
72 | } | ||
73 | |||
74 | bool OLedBox::isOn ( ) const | ||
75 | { | ||
76 | return m_on; | ||
77 | } | ||
78 | |||
79 | QColor OLedBox::color ( ) const | ||
80 | { | ||
81 | return m_color; | ||
82 | } | ||
83 | |||
84 | void OLedBox::setOn ( bool b ) | ||
85 | { | ||
86 | if ( m_on != b ) { | ||
87 | m_on = b; | ||
88 | update ( ); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | void OLedBox::toggle ( ) | ||
93 | { | ||
94 | setOn ( !isOn ( ) ); | ||
95 | } | ||
96 | |||
97 | void OLedBox::setColor ( const QColor &col ) | ||
98 | { | ||
99 | if ( m_color != col ) { | ||
100 | m_color = col; | ||
101 | |||
102 | delete m_pix [ 0 ]; | ||
103 | delete m_pix [ 1 ]; | ||
104 | |||
105 | update ( ); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | void OLedBox::mousePressEvent ( QMouseEvent *e ) | ||
110 | { | ||
111 | if ( e-> button ( ) == LeftButton ) { | ||
112 | m_on = !m_on; | ||
113 | update ( ); | ||
114 | emit toggled ( m_on ); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | |||
119 | void OLedBox::resizeEvent ( QResizeEvent * ) | ||
120 | { | ||
121 | delete m_pix [ 0 ]; | ||
122 | delete m_pix [ 1 ]; | ||
123 | |||
124 | update ( ); | ||
125 | } | ||
126 | |||
127 | void OLedBox::paintEvent ( QPaintEvent *e ) | ||
128 | { | ||
129 | int ind = m_on ? 1 : 0; | ||
130 | |||
131 | if ( !m_pix [ ind ] ) { | ||
132 | m_pix [ ind ] = new QPixmap ( size ( )); | ||
133 | |||
134 | drawLed ( m_pix [ ind ], m_on ? m_color : m_color. dark ( 300 ) ); | ||
135 | } | ||
136 | if ( !e-> erased ( )) | ||
137 | erase ( ); | ||
138 | |||
139 | QPainter p ( this ); | ||
140 | p. drawPixmap ( 0, 0, *m_pix [ ind ] ); | ||
141 | } | ||
142 | |||
143 | // From KDE libkdeui / led.cpp | ||
144 | |||
145 | void OLedBox::drawLed ( QPixmap *pix, const QColor &col ) // paint a ROUND SUNKEN led lamp | ||
146 | { | ||
147 | QPainter paint; | ||
148 | QColor color; | ||
149 | QBrush brush; | ||
150 | QPen pen; | ||
151 | |||
152 | // First of all we want to know what area should be updated | ||
153 | // Initialize coordinates, width, and height of the LED | ||
154 | int width = pix-> width ( ); | ||
155 | |||
156 | // Make sure the LED is round! | ||
157 | if ( width > pix-> height ( )) | ||
158 | width = pix-> height ( ); | ||
159 | width -= 2; // leave one pixel border | ||
160 | if ( width < 0 ) | ||
161 | width = 0; | ||
162 | |||
163 | // maybe we could stop HERE, if width <=0 ? | ||
164 | |||
165 | // start painting widget | ||
166 | // | ||
167 | paint.begin( pix ); | ||
168 | |||
169 | // Set the color of the LED according to given parameters | ||
170 | color = col; | ||
171 | |||
172 | // Set the brush to SolidPattern, this fills the entire area | ||
173 | // of the ellipse which is drawn first | ||
174 | brush.setStyle( QBrush::SolidPattern ); | ||
175 | brush.setColor( color ); | ||
176 | paint.setBrush( brush ); // Assign the brush to the painter | ||
177 | |||
178 | // Draws a "flat" LED with the given color: | ||
179 | paint.drawEllipse( 1, 1, width, width ); | ||
180 | |||
181 | // Draw the bright light spot of the LED now, using modified "old" | ||
182 | // painter routine taken from KDEUIs KLed widget: | ||
183 | |||
184 | // Setting the new width of the pen is essential to avoid "pixelized" | ||
185 | // shadow like it can be observed with the old LED code | ||
186 | pen.setWidth( 2 ); | ||
187 | |||
188 | // shrink the light on the LED to a size about 2/3 of the complete LED | ||
189 | int pos = width / 5 + 1; | ||
190 | int light_width = width; | ||
191 | light_width *= 2; | ||
192 | light_width /= 3; | ||
193 | |||
194 | // Calculate the LEDs "light factor": | ||
195 | int light_quote = ( 130 * 2 / ( light_width ? light_width : 1 ) ) + 100; | ||
196 | |||
197 | // Now draw the bright spot on the LED: | ||
198 | while ( light_width ) | ||
199 | { | ||
200 | color = color.light( light_quote ); // make color lighter | ||
201 | pen.setColor( color ); // set color as pen color | ||
202 | paint.setPen( pen ); // select the pen for drawing | ||
203 | paint.drawEllipse( pos, pos, light_width, light_width ); // draw the ellipse (circle) | ||
204 | light_width--; | ||
205 | if ( !light_width ) | ||
206 | break; | ||
207 | paint.drawEllipse( pos, pos, light_width, light_width ); | ||
208 | light_width--; | ||
209 | if ( !light_width ) | ||
210 | break; | ||
211 | paint.drawEllipse( pos, pos, light_width, light_width ); | ||
212 | pos++; | ||
213 | light_width--; | ||
214 | } | ||
215 | |||
216 | // Drawing of bright spot finished, now draw a thin border | ||
217 | // around the LED which resembles a shadow with light coming | ||
218 | // from the upper left. | ||
219 | |||
220 | #ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC | ||
221 | paint. drawPixmap ( 0, 0, *s_border_pix ); | ||
222 | |||
223 | #else | ||
224 | pen.setWidth( 3 ); | ||
225 | brush.setStyle( QBrush::NoBrush ); // Switch off the brush | ||
226 | paint.setBrush( brush ); // This avoids filling of the ellipse | ||
227 | |||
228 | // Set the initial color value to 200 (bright) and start | ||
229 | // drawing the shadow border at 45 (45*16 = 720). | ||
230 | int shadow_color = 200, angle; | ||
231 | |||
232 | for ( angle = 720; angle < 6480; angle += 240 ) | ||
233 | { | ||
234 | color.setRgb( shadow_color, shadow_color, shadow_color ); | ||
235 | pen.setColor( color ); | ||
236 | paint.setPen( pen ); | ||
237 | paint.drawArc( 0, 0, width+2, width+2, angle, 240 ); | ||
238 | paint.drawArc( 1, 1, width, width, angle, 240 ); | ||
239 | paint.drawArc( 2, 2, width-2, width-2, angle, 240 ); | ||
240 | if ( angle < 2320 ) { | ||
241 | shadow_color -= 25; // set color to a darker value | ||
242 | if ( shadow_color < 100 ) | ||
243 | shadow_color = 100; | ||
244 | } | ||
245 | else if ( ( angle > 2320 ) && ( angle < 5760 ) ) { | ||
246 | shadow_color += 25; // set color to a brighter value | ||
247 | if ( shadow_color > 255 ) | ||
248 | shadow_color = 255; | ||
249 | } | ||
250 | else { | ||
251 | shadow_color -= 25; // set color to a darker value again | ||
252 | if ( shadow_color < 100 ) | ||
253 | shadow_color = 100; | ||
254 | } // end if ( angle < 2320 ) | ||
255 | } // end for ( angle = 720; angle < 6480; angle += 160 ) | ||
256 | #endif | ||
257 | paint.end(); | ||
258 | // | ||
259 | // painting done | ||
260 | |||
261 | QBitmap mask ( pix-> width ( ), pix-> height ( ), true ); | ||
262 | QPainter mp ( &mask ); | ||
263 | mp. setPen ( Qt::NoPen ); | ||
264 | mp. setBrush ( Qt::color1 ); | ||
265 | mp. drawEllipse ( 0, 0, width + 2, width + 2 ); | ||
266 | mp. end ( ); | ||
267 | |||
268 | pix-> setMask ( mask ); | ||
269 | } | ||
270 | |||
diff --git a/core/applets/volumeapplet/oledbox.h b/core/applets/volumeapplet/oledbox.h new file mode 100644 index 0000000..4371a22 --- a/dev/null +++ b/core/applets/volumeapplet/oledbox.h | |||
@@ -0,0 +1,51 @@ | |||
1 | #ifndef __OPIE_OLED_H__ | ||
2 | #define __OPIE_OLED_H__ | ||
3 | |||
4 | #include <qwidget.h> | ||
5 | #include <qcolor.h> | ||
6 | |||
7 | class QPixmap; | ||
8 | |||
9 | #define _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC | ||
10 | |||
11 | class OLedBox : public QWidget { | ||
12 | Q_OBJECT | ||
13 | |||
14 | public: | ||
15 | OLedBox ( const QColor &col = red, QWidget *parent = 0, const char *name = 0 ); | ||
16 | virtual ~OLedBox ( ); | ||
17 | |||
18 | QColor color ( ) const; | ||
19 | bool isOn ( ) const; | ||
20 | |||
21 | virtual QSize sizeHint ( ) const; | ||
22 | |||
23 | public slots: | ||
24 | void toggle ( ); | ||
25 | void setOn ( bool on ); | ||
26 | void setColor ( const QColor &col ); | ||
27 | |||
28 | signals: | ||
29 | void toggled ( bool ); | ||
30 | |||
31 | protected: | ||
32 | virtual void paintEvent ( QPaintEvent *e ); | ||
33 | virtual void resizeEvent ( QResizeEvent *e ); | ||
34 | |||
35 | virtual void mousePressEvent ( QMouseEvent *e ); | ||
36 | |||
37 | private: | ||
38 | void drawLed ( QPixmap *, const QColor &col ); | ||
39 | |||
40 | private: | ||
41 | QPixmap *m_pix [2]; | ||
42 | |||
43 | QColor m_color; | ||
44 | bool m_on; | ||
45 | |||
46 | #ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC | ||
47 | static QPixmap *s_border_pix; | ||
48 | #endif | ||
49 | }; | ||
50 | |||
51 | #endif | ||
diff --git a/core/applets/volumeapplet/volume.cpp b/core/applets/volumeapplet/volume.cpp index d871a35..a000087 100644 --- a/core/applets/volumeapplet/volume.cpp +++ b/core/applets/volumeapplet/volume.cpp | |||
@@ -18,6 +18,7 @@ | |||
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <stdio.h> | ||
21 | 22 | ||
22 | #include "volume.h" | 23 | #include "volume.h" |
23 | 24 | ||
@@ -36,158 +37,351 @@ | |||
36 | #include <qpixmap.h> | 37 | #include <qpixmap.h> |
37 | #include <qlabel.h> | 38 | #include <qlabel.h> |
38 | 39 | ||
40 | #include <qtoolbutton.h> | ||
39 | #include <qpushbutton.h> | 41 | #include <qpushbutton.h> |
40 | #include <qtimer.h> | 42 | #include <qtimer.h> |
41 | 43 | ||
44 | #include <opie/odevice.h> | ||
45 | |||
46 | #include "oledbox.h" | ||
47 | |||
42 | #define RATE_TIMER_INTERVAL 100 | 48 | #define RATE_TIMER_INTERVAL 100 |
43 | // Ten times per second is fine (RATE_TIMER_INTERVAL 100). A shorter time | 49 | // Ten times per second is fine (RATE_TIMER_INTERVAL 100). A shorter time |
44 | // results in "hanging" buttons on the iPAQ due to quite high CPU consumption. | 50 | // results in "hanging" buttons on the iPAQ due to quite high CPU consumption. |
45 | 51 | ||
46 | VolumeControl::VolumeControl( bool showMic, QWidget *parent, const char *name ) | 52 | |
47 | : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) | 53 | /* XPM */ |
54 | static const char * vol_xpm[] = { | ||
55 | "20 20 3 1", | ||
56 | " c None", | ||
57 | ".c #0000FF", | ||
58 | "+c #000000", | ||
59 | " ", | ||
60 | " . ", | ||
61 | " . . . . ", | ||
62 | " . . . . . . ", | ||
63 | " . . . . . . . ", | ||
64 | " . . ..... . . ", | ||
65 | " . ... ..... ... ", | ||
66 | " ........... .... ", | ||
67 | " ................. ", | ||
68 | "++++++++++++++++++++", | ||
69 | " .................. ", | ||
70 | " . ............. . ", | ||
71 | " . ..... ....... ", | ||
72 | " . ... ..... . ", | ||
73 | " . ... ..... . ", | ||
74 | " . ... ..... ", | ||
75 | " . . . . . ", | ||
76 | " . . . ", | ||
77 | " . . . ", | ||
78 | " "}; | ||
79 | /* XPM */ | ||
80 | static const char * mic_xpm[] = { | ||
81 | "20 20 21 1", | ||
82 | " c None", | ||
83 | ".c #000000", | ||
84 | "+c #EEEEEE", | ||
85 | "@c #B4B6B4", | ||
86 | "#c #8B8D8B", | ||
87 | "$c #D5D6D5", | ||
88 | "%c #E6E6E6", | ||
89 | "&c #9C9D9C", | ||
90 | "*c #6A696A", | ||
91 | "=c #E6E2E6", | ||
92 | "-c #F6F2F6", | ||
93 | ";c #CDC6CD", | ||
94 | ">c #737573", | ||
95 | ",c #4A484A", | ||
96 | "'c #DEDEDE", | ||
97 | ")c #F6EEF6", | ||
98 | "!c #414041", | ||
99 | "~c #202020", | ||
100 | "{c #ACAEAC", | ||
101 | "]c #838583", | ||
102 | "^c #6A656A", | ||
103 | " ", | ||
104 | " .... ", | ||
105 | " .+@+#. ", | ||
106 | " ..$%&%*. ", | ||
107 | " .=-.;=>=,. ", | ||
108 | " .'+).&+!+. ", | ||
109 | " .+;+;.~+~. ", | ||
110 | " ..%{%,.... ", | ||
111 | " ..&=>=~.. ", | ||
112 | " .+..]^,.. ", | ||
113 | " .+....... ", | ||
114 | " .%... ", | ||
115 | " .=... ", | ||
116 | " .+... ", | ||
117 | " .+... ", | ||
118 | " .... ", | ||
119 | " .... ", | ||
120 | " .. ", | ||
121 | " . ", | ||
122 | ". "}; | ||
123 | |||
124 | /* XPM */ | ||
125 | static const char * alarm_xpm[] = { | ||
126 | "20 20 33 1", | ||
127 | " c None", | ||
128 | ".c #080602", | ||
129 | "+c #AAA602", | ||
130 | "@c #252002", | ||
131 | "#c #434202", | ||
132 | "$c #795602", | ||
133 | "%c #C3C20D", | ||
134 | "&c #DADAC2", | ||
135 | "*c #826002", | ||
136 | "=c #740502", | ||
137 | "-c #D6D602", | ||
138 | ";c #322E02", | ||
139 | ">c #826A02", | ||
140 | ",c #F1F195", | ||
141 | "'c #959215", | ||
142 | ")c #423602", | ||
143 | "!c #4B0302", | ||
144 | "~c #844315", | ||
145 | "{c #AAAA2A", | ||
146 | "]c #E2DE42", | ||
147 | "^c #BA7E04", | ||
148 | "/c #7F7502", | ||
149 | "(c #828276", | ||
150 | "_c #FEFE4E", | ||
151 | ":c #7D1902", | ||
152 | "<c #989656", | ||
153 | "[c #260B02", | ||
154 | "}c #F7F7D8", | ||
155 | "|c #DCDA5A", | ||
156 | "1c #823102", | ||
157 | "2c #B1AC6B", | ||
158 | "3c #F7F710", | ||
159 | "4c #838204", | ||
160 | " ", | ||
161 | " ", | ||
162 | " 4'4/ ", | ||
163 | " /-^= ", | ||
164 | " 42{4>4 ", | ||
165 | " '2|+*$44 ", | ||
166 | " +2&3+$1*44 ", | ||
167 | " (%_}_+/$:>/4 ", | ||
168 | " 4%_}3+#;>:*4 ", | ||
169 | " 4%_}&+#[1$/4 ", | ||
170 | " 4%_,2')[~~>4 ", | ||
171 | " 4%33'4#@~1>4 ", | ||
172 | " 4%3344#[:>/4 ", | ||
173 | " 42&_3'4#@>:*44 ", | ||
174 | " 42|}}3'4#[;$)$44 ", | ||
175 | "444{]]2^~~:!!#.@##/ ", | ||
176 | "4444-%*:==!!=...../ ", | ||
177 | " /:[.. ", | ||
178 | " /@. ", | ||
179 | " "}; | ||
180 | |||
181 | VolumeControl::VolumeControl ( VolumeApplet *icon, bool /*showMic*/, QWidget *parent, const char *name ) | ||
182 | : QFrame ( parent, name, WStyle_StaysOnTop | WType_Popup ) | ||
48 | { | 183 | { |
49 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 184 | m_icon = icon; |
50 | createView(showMic); | 185 | |
186 | bool has_wav_alarm = false; | ||
187 | |||
188 | switch ( ODevice::inst ( )-> model ( )) { | ||
189 | case OMODEL_iPAQ_H31xx: | ||
190 | case OMODEL_iPAQ_H36xx: | ||
191 | case OMODEL_iPAQ_H37xx: | ||
192 | case OMODEL_iPAQ_H38xx: | ||
193 | has_wav_alarm = true; | ||
194 | break; | ||
195 | default: | ||
196 | break; | ||
51 | } | 197 | } |
52 | 198 | ||
53 | void VolumeControl::createView(bool showMic) | ||
54 | { | ||
55 | Config cfg("qpe"); | ||
56 | cfg.setGroup("Volume"); | ||
57 | //showMic = TRUE; | ||
58 | QHBoxLayout *hboxLayout = new QHBoxLayout(this); | ||
59 | hboxLayout->setMargin( 3 ); | ||
60 | hboxLayout->setSpacing( 0); | ||
61 | 199 | ||
62 | QVBoxLayout *vboxButtons = new QVBoxLayout(this); | 200 | setFrameStyle ( QFrame::PopupPanel | QFrame::Raised ); |
201 | |||
202 | QGridLayout *grid = new QGridLayout ( this, 1, 1, 6, 4 ); | ||
203 | grid-> setSpacing ( 4 ); | ||
204 | grid-> setMargin ( 6 ); | ||
205 | |||
206 | QVBoxLayout *vbox; | ||
207 | QLabel *l; | ||
208 | |||
209 | vbox = new QVBoxLayout ( ); | ||
210 | vbox-> setSpacing ( 4 ); | ||
211 | grid-> addLayout ( vbox, 1, 0 ); | ||
212 | |||
63 | upButton = new QPushButton( this ); | 213 | upButton = new QPushButton( this ); |
64 | upButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); | 214 | upButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); |
65 | upButton->setPixmap( Resource::loadPixmap( "up" ) ); | 215 | upButton->setPixmap( Resource::loadPixmap( "up" ) ); |
216 | upButton-> setFocusPolicy ( QWidget::NoFocus ); | ||
217 | |||
218 | vbox-> addWidget ( upButton ); | ||
219 | |||
66 | downButton = new QPushButton( this ); | 220 | downButton = new QPushButton( this ); |
67 | downButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); | 221 | downButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); |
68 | downButton->setPixmap( Resource::loadPixmap( "down" ) ); | 222 | downButton->setPixmap( Resource::loadPixmap( "down" ) ); |
69 | vboxButtons->setSpacing( 2 ); | 223 | downButton-> setFocusPolicy ( QWidget::NoFocus ); |
70 | 224 | ||
71 | upButton->setFixedHeight(26); | 225 | vbox-> addWidget ( downButton ); |
72 | downButton->setFixedHeight(26); | 226 | |
73 | 227 | volSlider = new QSlider ( this ); | |
74 | vboxButtons->addWidget( upButton ); | 228 | volSlider-> setRange ( 0, 100 ); |
75 | vboxButtons->addWidget( downButton ); | 229 | volSlider-> setTickmarks ( QSlider::Both ); |
76 | 230 | volSlider-> setTickInterval ( 20 ); | |
77 | QVBoxLayout *vbox = new QVBoxLayout( this ); | 231 | volSlider-> setFocusPolicy ( QWidget::NoFocus ); |
78 | QHBoxLayout *hbox = NULL; | 232 | |
79 | 233 | l = new QLabel ( this ); | |
80 | slider = new QSlider( this ); | 234 | l-> setPixmap ( QPixmap ( vol_xpm )); |
81 | slider->setRange( 0, 100 ); | 235 | |
82 | slider->setTickmarks( QSlider::Both ); | 236 | grid-> addWidget ( l, 0, 1, AlignCenter ); |
83 | slider->setTickInterval( 20 ); | 237 | grid-> addWidget ( volSlider, 1, 1, AlignCenter ); |
84 | slider->setFocusPolicy( QWidget::NoFocus ); | 238 | |
85 | slider->setValue(cfg.readNumEntry("VolumePercent")); | 239 | volLed = new OLedBox ( green, this ); |
86 | 240 | volLed-> setFocusPolicy ( QWidget::NoFocus ); | |
87 | QVBoxLayout *sbox = new QVBoxLayout(this); | 241 | volLed-> setFixedSize ( 16, 16 ); |
88 | sbox->setMargin( 3 ); | 242 | |
89 | sbox->setSpacing( 3 ); | 243 | grid-> addWidget ( volLed, 2, 1, AlignCenter ); |
90 | sbox->addWidget( new QLabel("Vol", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter ); | 244 | |
91 | sbox->addWidget( slider, 0, Qt::AlignVCenter | Qt::AlignHCenter ); | 245 | micSlider = new QSlider ( this ); |
92 | 246 | micSlider-> setRange ( 0, 100 ); | |
93 | // if (showMic == TRUE) { | 247 | micSlider-> setTickmarks ( QSlider::Both ); |
94 | mic = new QSlider(this); | 248 | micSlider-> setTickInterval ( 20 ); |
95 | mic->setRange( 0, 100 ); | 249 | micSlider-> setFocusPolicy ( QWidget::NoFocus ); |
96 | mic->setTickmarks( QSlider::Both ); | 250 | |
97 | mic->setTickInterval( 20 ); | 251 | l = new QLabel ( this ); |
98 | mic->setFocusPolicy( QWidget::NoFocus ); | 252 | l-> setPixmap ( QPixmap ( mic_xpm )); |
99 | mic->setValue(cfg.readNumEntry("Mic")); | 253 | |
100 | 254 | grid-> addWidget ( l, 0, 2, AlignCenter ); | |
101 | QVBoxLayout *mbox = new QVBoxLayout(this); | 255 | grid-> addWidget ( micSlider, 1, 2, AlignCenter ); |
102 | mbox->setMargin( 3 ); | 256 | |
103 | mbox->setSpacing( 3 ); | 257 | micLed = new OLedBox ( red, this ); |
104 | mbox->addWidget( new QLabel("Mic", this) , 0, Qt::AlignVCenter | Qt::AlignHCenter ); | 258 | micLed-> setFocusPolicy ( QWidget::NoFocus ); |
105 | mbox->addWidget( mic, 0, Qt::AlignVCenter | Qt::AlignHCenter ); | 259 | micLed-> setFixedSize ( 16, 16 ); |
106 | 260 | ||
107 | hbox = new QHBoxLayout( this ); | 261 | grid-> addWidget ( micLed, 2, 2, AlignCenter ); |
108 | hbox->setMargin( 3 ); | 262 | |
109 | hbox->setSpacing( 3 ); | 263 | alarmSlider = new QSlider ( this ); |
110 | hbox->addLayout( sbox, 1); | 264 | alarmSlider-> setRange ( 0, 100 ); |
111 | hbox->addLayout( mbox, 1); | 265 | alarmSlider-> setTickmarks ( QSlider::Both ); |
112 | // } | 266 | alarmSlider-> setTickInterval ( 20 ); |
113 | 267 | alarmSlider-> setFocusPolicy ( QWidget::NoFocus ); | |
114 | muteBox = new QCheckBox( tr("Mute"), this ); | 268 | |
115 | muteBox->setFocusPolicy( QWidget::NoFocus ); | 269 | QLabel *alarmLabel = new QLabel ( this ); |
116 | 270 | alarmLabel-> setPixmap ( QPixmap ( alarm_xpm )); | |
117 | QVBoxLayout *klbox = new QVBoxLayout(this); | 271 | |
118 | 272 | grid-> addWidget ( alarmLabel, 0, 3, AlignCenter ); | |
119 | QLabel *Label1; | 273 | grid-> addWidget ( alarmSlider, 1, 3, AlignCenter ); |
120 | Label1 = new QLabel( this, "Label1" ); | 274 | |
121 | Label1->setText( tr( "Enable Sounds for:" )); | 275 | alarmLed = new OLedBox ( yellow, this ); |
122 | 276 | alarmLed-> setFocusPolicy ( QWidget::NoFocus ); | |
123 | alarmSound = new QCheckBox( tr("Alarm Sound"), this ); | 277 | alarmLed-> setFixedSize ( 16, 16 ); |
124 | alarmSound->setFocusPolicy( QWidget::NoFocus ); | 278 | |
125 | 279 | grid-> addWidget ( alarmLed, 2, 3, AlignCenter ); | |
126 | keyclicks = new QCheckBox( tr("Key Clicks"), this ); | 280 | |
127 | keyclicks->setFocusPolicy( QWidget::NoFocus ); | 281 | if ( !has_wav_alarm ) { |
128 | 282 | alarmSlider-> hide ( ); | |
129 | screentaps = new QCheckBox( tr("Screen taps"), this ); | 283 | alarmLabel-> hide ( ); |
130 | screentaps->setFocusPolicy( QWidget::NoFocus ); | 284 | alarmLed-> hide ( ); |
131 | 285 | } | |
132 | 286 | ||
133 | keyclicks->setChecked( cfg.readBoolEntry("KeySound",0)); | 287 | grid-> addWidget ( new QLabel ( tr( "Enable Sounds for:" ), this ), 0, 4, AlignVCenter | AlignLeft ); |
134 | screentaps->setChecked( cfg.readBoolEntry("TouchSound",0)); | 288 | |
135 | alarmSound->setChecked( cfg.readBoolEntry("AlarmSound",1)); | 289 | vbox = new QVBoxLayout ( ); |
136 | 290 | vbox-> setSpacing ( 4 ); | |
137 | klbox->setMargin( 3 ); | 291 | grid-> addMultiCellLayout ( vbox, 1, 2, 4, 4 ); |
138 | klbox->setSpacing( 0 ); | 292 | |
139 | klbox->addWidget( Label1, 1); | 293 | tapBox = new QCheckBox ( tr( "Screen Taps" ), this ); |
140 | klbox->addWidget( alarmSound, 1); | 294 | tapBox-> setFocusPolicy ( QWidget::NoFocus ); |
141 | klbox->addWidget( keyclicks, 1); | 295 | |
142 | klbox->addWidget( screentaps, 1); | 296 | vbox-> addWidget ( tapBox, AlignVCenter | AlignLeft ); |
143 | vbox->setMargin( 3 ); | 297 | |
144 | vbox->setSpacing( 0 ); | 298 | keyBox = new QCheckBox ( tr( "Key Clicks" ), this ); |
145 | // if (showMic == TRUE) | 299 | keyBox-> setFocusPolicy ( QWidget::NoFocus ); |
146 | vbox->addLayout( hbox, 1 ); | 300 | |
147 | // else | 301 | vbox-> addWidget ( keyBox, AlignVCenter | AlignLeft ); |
148 | // vbox->addLayout( sbox, 1); | 302 | |
149 | vbox->addWidget( muteBox, 0, Qt::AlignVCenter | Qt::AlignHCenter ); | 303 | alarmBox = new QCheckBox ( tr( "Alarm Sound" ), this ); |
150 | 304 | alarmBox-> setFocusPolicy ( QWidget::NoFocus ); | |
151 | hboxLayout->addLayout( vboxButtons ); | 305 | |
152 | hboxLayout->addLayout( vbox); | 306 | vbox-> addWidget ( alarmBox, AlignVCenter | AlignLeft ); |
153 | hboxLayout->addLayout( klbox); | 307 | |
154 | 308 | if ( has_wav_alarm ) { | |
155 | 309 | alarmBox-> hide ( ); | |
156 | setFixedHeight( 120); | 310 | } |
157 | // setFixedWidth( sizeHint().width() ); | 311 | |
312 | vbox-> addStretch ( 100 ); | ||
313 | |||
314 | setFixedSize ( sizeHint ( )); | ||
158 | setFocusPolicy(QWidget::NoFocus); | 315 | setFocusPolicy(QWidget::NoFocus); |
159 | connect( upButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); | ||
160 | connect( upButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) ); | ||
161 | connect( downButton, SIGNAL( pressed() ), this, SLOT( ButtonChanged() ) ); | ||
162 | connect( downButton, SIGNAL( released() ), this, SLOT( ButtonChanged() ) ); | ||
163 | 316 | ||
164 | rateTimer = new QTimer(this); | 317 | rateTimer = new QTimer(this); |
165 | connect( rateTimer, SIGNAL( timeout() ), this, SLOT( rateTimerDone() ) ); | 318 | connect( rateTimer, SIGNAL( timeout() ), this, SLOT( rateTimerDone() ) ); |
319 | |||
320 | connect ( upButton, SIGNAL( pressed ( )), this, SLOT( buttonChanged ( ))); | ||
321 | connect ( upButton, SIGNAL( released ( )), this, SLOT( buttonChanged ( ))); | ||
322 | connect ( downButton, SIGNAL( pressed ( )), this, SLOT( buttonChanged ( ))); | ||
323 | connect ( downButton, SIGNAL( released ( )), this, SLOT( buttonChanged ( ))); | ||
324 | |||
325 | connect ( micSlider, SIGNAL( valueChanged ( int )), this, SLOT( micMoved( int ))); | ||
326 | connect ( volSlider, SIGNAL( valueChanged ( int )), this, SLOT( volMoved( int ))); | ||
327 | connect ( alarmSlider, SIGNAL( valueChanged ( int )), this, SLOT( alarmMoved( int ))); | ||
328 | |||
329 | connect ( volLed, SIGNAL( toggled ( bool )), this, SLOT( volMuteToggled ( bool ))); | ||
330 | connect ( micLed, SIGNAL( toggled ( bool )), this, SLOT( micMuteToggled ( bool ))); | ||
331 | connect ( alarmLed, SIGNAL( toggled ( bool )), this, SLOT( alarmSoundToggled ( bool ))); | ||
332 | |||
333 | connect ( alarmBox, SIGNAL( toggled ( bool )), this, SLOT( alarmSoundToggled ( bool ))); | ||
334 | connect ( keyBox, SIGNAL( toggled ( bool )), this, SLOT( keyClickToggled ( bool ))); | ||
335 | connect ( tapBox, SIGNAL( toggled ( bool )), this, SLOT( screenTapToggled ( bool ))); | ||
336 | |||
337 | // initialize variables | ||
338 | |||
339 | readConfig ( true ); | ||
340 | |||
341 | // initialize the config file, in case some entries are missing | ||
342 | |||
343 | writeConfigEntry ( "VolumePercent", m_vol_percent, UPD_None ); | ||
344 | writeConfigEntry ( "Mute", m_vol_muted, UPD_None ); | ||
345 | writeConfigEntry ( "AlarmPercent", m_alarm_percent, UPD_None ); | ||
346 | writeConfigEntry ( "TouchSound", m_snd_touch, UPD_None ); | ||
347 | writeConfigEntry ( "KeySound", m_snd_key, UPD_None ); | ||
348 | writeConfigEntry ( "AlarmSound", m_snd_alarm, UPD_Vol ); | ||
349 | |||
350 | writeConfigEntry ( "Mic", m_mic_percent, UPD_None ); | ||
351 | writeConfigEntry ( "MicMute", m_mic_muted, UPD_Mic ); | ||
166 | } | 352 | } |
167 | 353 | ||
168 | void VolumeControl::keyPressEvent( QKeyEvent *e) | 354 | bool VolumeControl::volMuted ( ) const |
355 | { | ||
356 | return m_vol_muted; | ||
357 | } | ||
358 | |||
359 | int VolumeControl::volPercent ( ) const | ||
169 | { | 360 | { |
170 | switch(e->key()) | 361 | return m_vol_percent; |
362 | } | ||
363 | |||
364 | void VolumeControl::keyPressEvent ( QKeyEvent *e ) | ||
171 | { | 365 | { |
366 | switch ( e-> key ( )) { | ||
172 | case Key_Up: | 367 | case Key_Up: |
173 | slider->subtractStep(); | 368 | volSlider-> subtractStep ( ); |
174 | break; | 369 | break; |
175 | case Key_Down: | 370 | case Key_Down: |
176 | slider->addStep(); | 371 | volSlider-> addStep ( ); |
177 | break; | 372 | break; |
178 | case Key_Space: | 373 | case Key_Space: |
179 | muteBox->toggle(); | 374 | volLed-> toggle ( ); |
180 | break; | 375 | break; |
181 | case Key_Escape: | 376 | case Key_Escape: |
182 | close(); | 377 | hide ( ); |
183 | break; | 378 | break; |
184 | } | 379 | } |
185 | } | 380 | } |
186 | 381 | ||
187 | void VolumeControl::ButtonChanged() | 382 | void VolumeControl::buttonChanged ( ) |
188 | { | ||
189 | if ( upButton->isDown() || downButton->isDown() ) | ||
190 | { | 383 | { |
384 | if ( upButton-> isDown ( ) || downButton->isDown ( )) { | ||
191 | rateTimerDone(); // Call it one time manually, otherwise it wont get | 385 | rateTimerDone(); // Call it one time manually, otherwise it wont get |
192 | // called at all when a button is pressed for a time | 386 | // called at all when a button is pressed for a time |
193 | // shorter than RATE_TIMER_INTERVAL. | 387 | // shorter than RATE_TIMER_INTERVAL. |
@@ -200,226 +394,236 @@ void VolumeControl::ButtonChanged() | |||
200 | void VolumeControl::rateTimerDone() | 394 | void VolumeControl::rateTimerDone() |
201 | { | 395 | { |
202 | if ( upButton->isDown() ) | 396 | if ( upButton->isDown() ) |
203 | slider->setValue( slider->value() - 2 ); | 397 | volSlider-> setValue ( volSlider-> value ( ) - 2 ); |
204 | else // downButton->isDown() | 398 | else // if ( downButton-> isDown ( )) |
205 | slider->setValue( slider->value() + 2 ); | 399 | volSlider-> setValue ( volSlider-> value ( ) + 2 ); |
206 | } | 400 | } |
207 | 401 | ||
208 | //=========================================================================== | 402 | void VolumeControl::show ( bool /*showMic*/ ) |
209 | |||
210 | VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) | ||
211 | : QWidget( parent, name ) | ||
212 | { | 403 | { |
213 | Config cfg("qpe"); | 404 | readConfig ( ); |
214 | cfg.setGroup("Volume"); | ||
215 | 405 | ||
216 | setFixedHeight( 18 ); | 406 | QPoint curPos = m_icon-> mapToGlobal ( QPoint ( 0, 0 )); |
217 | setFixedWidth( 14 ); | 407 | printf ( "SHOW AT : %d/%d\n", curPos.x(), curPos.y()); |
218 | 408 | printf ( "SIZEHINT: %d/%d\n", sizeHint().width(),sizeHint().height()); | |
219 | volumePixmap = Resource::loadPixmap( "volume" ); | ||
220 | |||
221 | volumePercent = cfg.readNumEntry("VolumePercent",50); | ||
222 | micPercent = cfg.readNumEntry("Mic", 50); | ||
223 | muted = FALSE; // ### read from pref | ||
224 | micMuted = FALSE; // ### read from pref | ||
225 | |||
226 | advancedTimer = new QTimer(this); | ||
227 | 409 | ||
228 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 410 | int w = sizeHint ( ). width ( ); |
229 | connect( qApp, SIGNAL( micChanged(bool) ), this, SLOT ( micChanged(bool) ) ); | 411 | int x = curPos.x ( ) - ( w / 2 ); |
230 | connect( advancedTimer, SIGNAL( timeout() ),this, SLOT( advVolControl()) ); | ||
231 | 412 | ||
232 | writeSystemVolume(); | 413 | if (( x + w ) > QPEApplication::desktop ( )-> width ( )) |
233 | writeSystemMic(); | 414 | x = QPEApplication::desktop ( )-> width ( ) - w; |
234 | } | ||
235 | |||
236 | VolumeApplet::~VolumeApplet() | ||
237 | { | ||
238 | } | ||
239 | 415 | ||
240 | void VolumeApplet::keyPressEvent ( QKeyEvent * e ) | ||
241 | { | ||
242 | QString s; | ||
243 | s.setNum(e->key()); | ||
244 | qWarning(s); | ||
245 | } | ||
246 | void VolumeApplet::mousePressEvent( QMouseEvent * ) | ||
247 | { | ||
248 | advancedTimer->start( 750, TRUE ); | ||
249 | } | ||
250 | 416 | ||
251 | void VolumeApplet::mouseReleaseEvent( QMouseEvent * ) | 417 | move ( x, curPos. y ( ) - sizeHint ( ). height ( )); |
252 | { | 418 | QFrame::show ( ); |
253 | showVolControl(FALSE); | ||
254 | } | ||
255 | 419 | ||
256 | void VolumeApplet::advVolControl() | ||
257 | { | ||
258 | showVolControl(TRUE); | ||
259 | } | 420 | } |
260 | 421 | ||
261 | void VolumeApplet::showVolControl(bool showMic) | 422 | void VolumeControl::readConfig ( bool force ) |
262 | { | 423 | { |
263 | Config cfg("qpe"); | 424 | Config cfg("qpe"); |
264 | cfg.setGroup("Volume"); | 425 | cfg.setGroup("Volume"); |
265 | volumePercent = cfg.readNumEntry("VolumePercent",50); | ||
266 | micPercent = cfg.readNumEntry("Mic", 50); | ||
267 | |||
268 | // Create a small volume control window to adjust the volume with | ||
269 | VolumeControl *vc = new VolumeControl(showMic); | ||
270 | vc->slider->setValue( 100 - volumePercent ); | ||
271 | // if (showMic) | ||
272 | // { | ||
273 | vc->mic->setValue( 100 - micPercent ); | ||
274 | connect( vc->mic, SIGNAL( valueChanged( int ) ), this, SLOT( micMoved( int ) ) ); | ||
275 | // } | ||
276 | |||
277 | vc->muteBox->setChecked( muted ); | ||
278 | connect( vc->slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) ); | ||
279 | connect( vc->muteBox, SIGNAL( toggled( bool ) ), this, SLOT( mute( bool ) ) ); | ||
280 | |||
281 | Config config("qpe"); | ||
282 | config.setGroup("Volume"); | ||
283 | 426 | ||
284 | vc->keyclicks->setChecked( config.readBoolEntry("KeySound",0)); | 427 | int old_vp = m_vol_percent; |
285 | vc->screentaps->setChecked( config.readBoolEntry("TouchSound",0)); | 428 | int old_mp = m_mic_percent; |
286 | vc->alarmSound->setChecked( config.readBoolEntry("AlarmSound",1)); | 429 | bool old_vm = m_vol_muted; |
287 | 430 | bool old_mm = m_mic_muted; | |
288 | connect( vc->alarmSound, SIGNAL(toggled(bool)), this, SLOT( alarmSoundCheckToggled(bool))); | 431 | bool old_sk = m_snd_key; |
289 | connect( vc->keyclicks, SIGNAL(toggled(bool)), this, SLOT( keyclicksCheckToggled(bool))); | 432 | bool old_st = m_snd_touch; |
290 | connect( vc->screentaps, SIGNAL(toggled(bool)), this, SLOT( screentapsCheckToggled(bool))); | 433 | bool old_sa = m_snd_alarm; |
291 | 434 | int old_ap = m_alarm_percent; | |
292 | QPoint curPos = mapToGlobal( rect().topLeft() ); | 435 | |
293 | vc->move( curPos.x()-(vc->sizeHint().width()/2+50), curPos.y() - 120 ); | 436 | m_vol_percent = cfg. readNumEntry ( "VolumePercent", 50 ); |
294 | vc->show(); | 437 | m_mic_percent = cfg. readNumEntry ( "Mic", 50 ); |
295 | 438 | m_vol_muted = cfg. readBoolEntry ( "Mute", 0 ); | |
296 | advancedTimer->stop(); | 439 | m_mic_muted = cfg. readBoolEntry ( "MicMute", 0 ); |
297 | } | 440 | m_snd_key = cfg. readBoolEntry ( "KeySound", 0 ); |
298 | 441 | m_snd_touch = cfg. readBoolEntry ( "TouchSound", 0 ); | |
299 | void VolumeApplet::volumeChanged( bool nowMuted ) | 442 | m_snd_alarm = cfg. readBoolEntry ( "AlarmSound", 1 ); |
443 | m_alarm_percent = cfg. readNumEntry ( "AlarmPercent", 65 ); | ||
444 | |||
445 | if ( force || ( m_vol_percent != old_vp )) | ||
446 | volSlider-> setValue ( 100 - m_vol_percent ); | ||
447 | if ( force || ( m_mic_percent != old_mp )) | ||
448 | micSlider-> setValue ( 100 - m_mic_percent ); | ||
449 | if ( force || ( m_alarm_percent != old_ap )) | ||
450 | alarmSlider-> setValue ( 100 - m_alarm_percent ); | ||
451 | |||
452 | if ( force || ( m_vol_muted != old_vm )) | ||
453 | volLed-> setOn ( !m_vol_muted ); | ||
454 | if ( force || ( m_mic_muted != old_mm )) | ||
455 | micLed-> setOn ( !m_mic_muted ); | ||
456 | if ( force || ( m_snd_alarm != old_sa )) | ||
457 | alarmLed-> setOn ( m_snd_alarm ); | ||
458 | |||
459 | if ( force || ( m_snd_key != old_sk )) | ||
460 | keyBox-> setChecked ( m_snd_key ); | ||
461 | if ( force || ( m_snd_touch != old_st )) | ||
462 | tapBox-> setChecked ( m_snd_touch ); | ||
463 | if ( force || ( m_snd_alarm != old_sa )) | ||
464 | alarmBox-> setChecked ( m_snd_alarm ); | ||
465 | } | ||
466 | |||
467 | |||
468 | void VolumeControl::volumeChanged ( bool nowMuted ) | ||
300 | { | 469 | { |
301 | int previousVolume = volumePercent; | 470 | int previousVolume = m_vol_percent; |
302 | 471 | ||
303 | if ( !nowMuted ) | 472 | if ( !nowMuted ) |
304 | readSystemVolume(); | 473 | readConfig ( ); |
305 | 474 | ||
306 | // Handle case where muting it toggled | 475 | // Handle case where muting it toggled |
307 | if ( muted != nowMuted ) { | 476 | if ( m_vol_muted != nowMuted ) { |
308 | muted = nowMuted; | 477 | m_vol_muted = nowMuted; |
309 | repaint( TRUE ); | 478 | m_icon-> repaint ( true ); |
310 | return; | ||
311 | } | 479 | } |
312 | 480 | else if ( previousVolume != m_vol_percent ) { | |
313 | // Avoid over repainting | 481 | // Avoid over repainting |
314 | if ( previousVolume != volumePercent ) | 482 | m_icon-> repaint( 2, height ( ) - 3, width ( ) - 4, 2, false ); |
315 | repaint( 2, height() - 3, width() - 4, 2, FALSE ); | 483 | } |
484 | |||
316 | } | 485 | } |
317 | 486 | ||
318 | void VolumeApplet::micChanged( bool nowMuted ) | 487 | void VolumeControl::micChanged ( bool nowMuted ) |
319 | { | 488 | { |
320 | if (!nowMuted) | 489 | if (!nowMuted) |
321 | readSystemMic(); | 490 | readConfig ( ); |
322 | micMuted = nowMuted; | 491 | m_mic_muted = nowMuted; |
323 | } | 492 | } |
324 | 493 | ||
325 | void VolumeApplet::mute( bool toggled ) | 494 | void VolumeControl::screenTapToggled ( bool b ) |
326 | { | 495 | { |
327 | muted = toggled; | 496 | m_snd_touch = b; |
328 | 497 | writeConfigEntry ( "TouchSound", m_snd_touch, UPD_Vol ); | |
329 | // clear if removing mute | ||
330 | repaint( !toggled ); | ||
331 | writeSystemVolume(); | ||
332 | Config cfg("qpe"); | ||
333 | cfg.setGroup("Volume"); | ||
334 | if(muted) | ||
335 | cfg.writeEntry("Mute", "TRUE"); | ||
336 | else | ||
337 | cfg.writeEntry("Mute", "FALSE"); | ||
338 | cfg.write(); | ||
339 | } | 498 | } |
340 | 499 | ||
341 | 500 | void VolumeControl::keyClickToggled ( bool b ) | |
342 | void VolumeApplet::sliderMoved( int percent ) | ||
343 | { | 501 | { |
344 | setVolume( 100 - percent ); | 502 | m_snd_key = b; |
503 | writeConfigEntry ( "KeySound", m_snd_key, UPD_Vol ); | ||
345 | } | 504 | } |
346 | 505 | ||
347 | void VolumeApplet::micMoved( int percent ) | 506 | void VolumeControl::alarmSoundToggled ( bool b ) |
348 | { | 507 | { |
349 | setMic( 100 - percent ); | 508 | m_snd_alarm = b; |
509 | writeConfigEntry ( "AlarmSound", m_snd_alarm, UPD_Vol ); | ||
350 | } | 510 | } |
351 | 511 | ||
352 | void VolumeApplet::readSystemVolume() | 512 | void VolumeControl::volMuteToggled ( bool b ) |
353 | { | 513 | { |
354 | Config cfg("qpe"); | 514 | m_vol_muted = !b; |
355 | cfg.setGroup("Volume"); | 515 | |
356 | volumePercent = cfg.readNumEntry("VolumePercent"); | 516 | m_icon-> repaint ( !m_vol_muted ); // clear if removing mute |
517 | |||
518 | writeConfigEntry ( "Mute", m_vol_muted, UPD_Vol ); | ||
357 | } | 519 | } |
358 | 520 | ||
359 | void VolumeApplet::readSystemMic() | 521 | void VolumeControl::micMuteToggled ( bool b ) |
360 | { | 522 | { |
361 | Config cfg("qpe"); | 523 | m_mic_muted = !b; |
362 | cfg.setGroup("Volume"); | 524 | writeConfigEntry ( "MicMute", m_mic_muted, UPD_Mic ); |
363 | micPercent = cfg.readNumEntry("Mic"); | ||
364 | } | 525 | } |
365 | 526 | ||
366 | void VolumeApplet::setVolume( int percent ) | 527 | |
528 | void VolumeControl::volMoved ( int percent ) | ||
367 | { | 529 | { |
530 | m_vol_percent = 100 - percent; | ||
531 | |||
368 | // clamp volume percent to be between 0 and 100 | 532 | // clamp volume percent to be between 0 and 100 |
369 | volumePercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent); | 533 | m_vol_percent = ( m_vol_percent < 0 ) ? 0 : (( m_vol_percent > 100 ) ? 100 : m_vol_percent ); |
370 | // repaint just the little volume rectangle | 534 | // repaint just the little volume rectangle |
371 | repaint( 2, height() - 3, width() - 4, 2, FALSE ); | 535 | repaint ( 2, height ( ) - 3, width ( ) - 4, 2, false ); |
372 | writeSystemVolume(); | 536 | |
537 | writeConfigEntry ( "VolumePercent", m_vol_percent, UPD_Vol ); | ||
373 | } | 538 | } |
374 | 539 | ||
375 | void VolumeApplet::setMic( int percent ) | 540 | void VolumeControl::micMoved ( int percent ) |
376 | { | 541 | { |
542 | m_mic_percent = 100 - percent; | ||
543 | |||
377 | // clamp volume percent to be between 0 and 100 | 544 | // clamp volume percent to be between 0 and 100 |
378 | micPercent = (percent < 0) ? 0 : ((percent > 100) ? 100 : percent); | 545 | m_mic_percent = ( m_mic_percent < 0 ) ? 0 : (( m_mic_percent > 100 ) ? 100 : m_mic_percent ); |
379 | writeSystemMic(); | 546 | |
547 | writeConfigEntry ( "Mic", m_mic_percent, UPD_Mic ); | ||
380 | } | 548 | } |
381 | 549 | ||
382 | void VolumeApplet::writeSystemVolume() | 550 | void VolumeControl::alarmMoved ( int percent ) |
383 | { | 551 | { |
552 | m_alarm_percent = 100 - percent; | ||
553 | |||
554 | // clamp volume percent to be between 0 and 100 | ||
555 | m_alarm_percent = ( m_alarm_percent < 0 ) ? 0 : (( m_alarm_percent > 100 ) ? 100 : m_alarm_percent ); | ||
556 | |||
557 | writeConfigEntry ( "AlarmPercent", m_alarm_percent, UPD_None ); | ||
558 | } | ||
559 | |||
560 | |||
561 | void VolumeControl::writeConfigEntry ( const char *entry, int val, eUpdate upd ) | ||
384 | { | 562 | { |
385 | Config cfg("qpe"); | 563 | Config cfg("qpe"); |
386 | cfg.setGroup("Volume"); | 564 | cfg.setGroup("Volume"); |
387 | cfg.writeEntry("VolumePercent",volumePercent); | 565 | cfg. writeEntry ( entry, val ); |
388 | } | 566 | //cfg. write ( ); |
567 | |||
389 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 568 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
390 | // Send notification that the volume has changed | 569 | switch ( upd ) { |
391 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; | 570 | case UPD_Vol: { |
571 | QCopEnvelope ( "QPE/System", "volumeChange(bool)" ) << m_vol_muted; | ||
572 | break; | ||
573 | } | ||
574 | case UPD_Mic: { | ||
575 | QCopEnvelope ( "QPE/System", "micChange(bool)" ) << m_mic_muted; | ||
576 | break; | ||
577 | } | ||
578 | case UPD_None: | ||
579 | break; | ||
580 | } | ||
392 | #endif | 581 | #endif |
393 | } | 582 | } |
394 | 583 | ||
395 | void VolumeApplet::writeSystemMic() | 584 | //=========================================================================== |
585 | |||
586 | VolumeApplet::VolumeApplet( QWidget *parent, const char *name ) | ||
587 | : QWidget( parent, name ) | ||
396 | { | 588 | { |
589 | setFixedHeight ( 18 ); | ||
590 | setFixedWidth ( 14 ); | ||
591 | |||
592 | m_pixmap = new QPixmap ( Resource::loadPixmap ( "volume" )); | ||
593 | m_dialog = new VolumeControl ( this ); | ||
594 | |||
595 | connect ( qApp, SIGNAL( volumeChanged ( bool )), m_dialog, SLOT( volumeChanged( bool ))); | ||
596 | connect ( qApp, SIGNAL( micChanged ( bool )), m_dialog, SLOT ( micChanged( bool ))); | ||
597 | } | ||
598 | |||
599 | VolumeApplet::~VolumeApplet() | ||
397 | { | 600 | { |
398 | Config cfg("qpe"); | 601 | delete m_pixmap; |
399 | cfg.setGroup("Volume"); | ||
400 | cfg.writeEntry("Mic",micPercent); | ||
401 | } | 602 | } |
402 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 603 | |
403 | // Send notification that the volume has changed | 604 | |
404 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << micMuted; | 605 | void VolumeApplet::mousePressEvent ( QMouseEvent * ) |
405 | #endif | 606 | { |
607 | if ( m_dialog-> isVisible ( )) | ||
608 | m_dialog-> hide ( ); | ||
609 | else | ||
610 | m_dialog-> show ( true ); | ||
406 | } | 611 | } |
407 | 612 | ||
613 | |||
408 | void VolumeApplet::paintEvent( QPaintEvent* ) | 614 | void VolumeApplet::paintEvent( QPaintEvent* ) |
409 | { | 615 | { |
410 | QPainter p(this); | 616 | QPainter p(this); |
411 | 617 | ||
412 | if (volumePixmap.isNull()) | 618 | p. drawPixmap ( 0, 1, *m_pixmap ); |
413 | volumePixmap = Resource::loadPixmap( "volume" ); | ||
414 | p.drawPixmap( 0, 1, volumePixmap ); | ||
415 | p.setPen( darkGray ); | 619 | p.setPen( darkGray ); |
416 | p.drawRect( 1, height() - 4, width() - 2, 4 ); | 620 | p.drawRect( 1, height() - 4, width() - 2, 4 ); |
417 | 621 | ||
418 | int pixelsWide = volumePercent * (width() - 4) / 100; | 622 | int pixelsWide = m_dialog-> volPercent ( ) * ( width() - 4 ) / 100; |
419 | p.fillRect( 2, height() - 3, pixelsWide, 2, red ); | 623 | p.fillRect( 2, height() - 3, pixelsWide, 2, red ); |
420 | p.fillRect( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); | 624 | p.fillRect( pixelsWide + 2, height() - 3, width() - 4 - pixelsWide, 2, lightGray ); |
421 | 625 | ||
422 | if ( muted ) { | 626 | if ( m_dialog-> volMuted ( )) { |
423 | p.setPen( red ); | 627 | p.setPen( red ); |
424 | p.drawLine( 1, 2, width() - 2, height() - 5 ); | 628 | p.drawLine( 1, 2, width() - 2, height() - 5 ); |
425 | p.drawLine( 1, 3, width() - 2, height() - 4 ); | 629 | p.drawLine( 1, 3, width() - 2, height() - 4 ); |
@@ -428,24 +632,4 @@ void VolumeApplet::paintEvent( QPaintEvent* ) | |||
428 | } | 632 | } |
429 | } | 633 | } |
430 | 634 | ||
431 | void VolumeApplet::screentapsCheckToggled(bool b) { | ||
432 | Config cfg("qpe"); | ||
433 | cfg.setGroup("Volume"); | ||
434 | cfg.writeEntry("TouchSound",b ); | ||
435 | cfg.write(); | ||
436 | } | ||
437 | |||
438 | void VolumeApplet::keyclicksCheckToggled(bool b) { | ||
439 | Config cfg("qpe"); | ||
440 | cfg.setGroup("Volume"); | ||
441 | cfg.writeEntry("KeySound",b); | ||
442 | cfg.write(); | ||
443 | } | ||
444 | |||
445 | void VolumeApplet::alarmSoundCheckToggled(bool b) { | ||
446 | Config cfg("qpe"); | ||
447 | cfg.setGroup("Volume"); | ||
448 | cfg.writeEntry("AlarmSound",b); | ||
449 | cfg.write(); | ||
450 | } | ||
451 | 635 | ||
diff --git a/core/applets/volumeapplet/volume.h b/core/applets/volumeapplet/volume.h index 6e631f2..ff5c64a 100644 --- a/core/applets/volumeapplet/volume.h +++ b/core/applets/volumeapplet/volume.h | |||
@@ -22,85 +22,101 @@ | |||
22 | #define __VOLUME_APPLET_H__ | 22 | #define __VOLUME_APPLET_H__ |
23 | 23 | ||
24 | 24 | ||
25 | #include <qwidget.h> | ||
26 | #include <qframe.h> | 25 | #include <qframe.h> |
27 | #include <qpixmap.h> | ||
28 | #include <qguardedptr.h> | ||
29 | #include <qtimer.h> | ||
30 | 26 | ||
27 | class QPixmap; | ||
28 | class QTimer; | ||
31 | class QSlider; | 29 | class QSlider; |
32 | class QCheckBox; | 30 | class QCheckBox; |
31 | class QButton; | ||
32 | class OLedBox; | ||
33 | 33 | ||
34 | class VolumeControl : public QFrame | 34 | class VolumeApplet; |
35 | { | 35 | |
36 | class VolumeControl : public QFrame { | ||
36 | Q_OBJECT | 37 | Q_OBJECT |
37 | public: | ||
38 | VolumeControl( bool showMic=FALSE, QWidget *parent=0, const char *name=0 ); | ||
39 | 38 | ||
40 | public: | 39 | public: |
41 | QSlider *slider; | 40 | VolumeControl ( VolumeApplet *icon, bool showMic = false, QWidget *parent=0, const char *name=0 ); |
42 | QSlider *mic; | 41 | |
43 | QCheckBox *muteBox; | 42 | bool volMuted ( ) const; |
44 | QCheckBox *alarmSound; | 43 | int volPercent ( ) const; |
45 | QCheckBox *screentaps; | 44 | |
46 | QCheckBox *keyclicks; | 45 | virtual void show ( bool showmic ); |
46 | |||
47 | protected: | ||
48 | virtual void keyPressEvent ( QKeyEvent * e ); | ||
49 | |||
50 | protected slots: | ||
51 | void volumeChanged ( bool muted ); | ||
52 | void micChanged ( bool muted ); | ||
53 | |||
54 | private slots: | ||
55 | void volMoved ( int percent ); | ||
56 | void micMoved ( int percent ); | ||
57 | void alarmMoved ( int percent ); | ||
47 | 58 | ||
59 | void volMuteToggled ( bool ); | ||
60 | void micMuteToggled ( bool ); | ||
61 | void alarmSoundToggled ( bool ); | ||
62 | void keyClickToggled ( bool ); | ||
63 | void screenTapToggled ( bool ); | ||
64 | |||
65 | void buttonChanged ( ); | ||
66 | void rateTimerDone ( ); | ||
48 | 67 | ||
49 | private: | 68 | private: |
69 | void readConfig ( bool force = false ); | ||
70 | |||
71 | enum eUpdate { | ||
72 | UPD_None, | ||
73 | UPD_Vol, | ||
74 | UPD_Mic | ||
75 | }; | ||
76 | void writeConfigEntry ( const char *entry, int val, eUpdate upd ); | ||
77 | |||
78 | |||
79 | private: | ||
80 | QSlider *volSlider; | ||
81 | QSlider *micSlider; | ||
82 | QSlider *alarmSlider; | ||
83 | OLedBox *volLed; | ||
84 | OLedBox *micLed; | ||
85 | OLedBox *alarmLed; | ||
86 | |||
87 | QCheckBox *alarmBox; | ||
88 | QCheckBox *tapBox; | ||
89 | QCheckBox *keyBox; | ||
50 | QPushButton *upButton; | 90 | QPushButton *upButton; |
51 | QPushButton *downButton; | 91 | QPushButton *downButton; |
52 | QTimer *rateTimer; | 92 | QTimer *rateTimer; |
53 | 93 | ||
54 | void keyPressEvent( QKeyEvent * ); | 94 | int m_vol_percent; |
55 | void createView(bool showMic = FALSE); | 95 | int m_mic_percent; |
56 | private slots: | 96 | int m_alarm_percent; |
57 | void ButtonChanged(); | 97 | bool m_vol_muted; |
58 | void rateTimerDone(); | 98 | bool m_mic_muted; |
99 | bool m_snd_alarm; | ||
100 | bool m_snd_touch; | ||
101 | bool m_snd_key; | ||
59 | 102 | ||
103 | VolumeApplet *m_icon; | ||
60 | }; | 104 | }; |
61 | 105 | ||
62 | class VolumeApplet : public QWidget | 106 | class VolumeApplet : public QWidget { |
63 | { | ||
64 | Q_OBJECT | 107 | Q_OBJECT |
108 | |||
65 | public: | 109 | public: |
66 | VolumeApplet( QWidget *parent = 0, const char *name=0 ); | 110 | VolumeApplet( QWidget *parent = 0, const char *name=0 ); |
67 | ~VolumeApplet(); | 111 | ~VolumeApplet(); |
68 | bool isMute( ) { return muted; } | ||
69 | int percent( ) { return volumePercent; } | ||
70 | 112 | ||
71 | public slots: | 113 | protected: |
72 | void volumeChanged( bool muted ); | 114 | virtual void mousePressEvent ( QMouseEvent * ); |
73 | void micChanged( bool muted ); | 115 | virtual void paintEvent ( QPaintEvent* ); |
74 | void sliderMoved( int percent ); | ||
75 | void mute( bool ); | ||
76 | |||
77 | void micMoved( int percent ); | ||
78 | void setVolume( int percent ); | ||
79 | void setMic( int percent ); | ||
80 | |||
81 | void showVolControl(bool showMic = FALSE); | ||
82 | void advVolControl(); | ||
83 | 116 | ||
84 | private: | 117 | private: |
85 | int volumePercent, micPercent; | 118 | QPixmap * m_pixmap; |
86 | bool muted, micMuted; | 119 | VolumeControl *m_dialog; |
87 | QPixmap volumePixmap; | ||
88 | QTimer *advancedTimer; | ||
89 | |||
90 | void readSystemVolume(); | ||
91 | void writeSystemVolume(); | ||
92 | void mousePressEvent( QMouseEvent * ); | ||
93 | void paintEvent( QPaintEvent* ); | ||
94 | |||
95 | void readSystemMic(); | ||
96 | void keyPressEvent ( QKeyEvent * e ); | ||
97 | void mouseReleaseEvent( QMouseEvent *); | ||
98 | void writeSystemMic(); | ||
99 | |||
100 | protected slots: | ||
101 | void alarmSoundCheckToggled(bool); | ||
102 | void keyclicksCheckToggled(bool); | ||
103 | void screentapsCheckToggled(bool); | ||
104 | }; | 120 | }; |
105 | 121 | ||
106 | 122 | ||
diff --git a/core/applets/volumeapplet/volumeapplet.pro b/core/applets/volumeapplet/volumeapplet.pro index f89eea2..937a537 100644 --- a/core/applets/volumeapplet/volumeapplet.pro +++ b/core/applets/volumeapplet/volumeapplet.pro | |||
@@ -1,7 +1,7 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on release | 2 | CONFIG += qt warn_on release |
3 | HEADERS= volume.h volumeappletimpl.h | 3 | HEADERS= volume.h volumeappletimpl.h oledbox.h |
4 | SOURCES= volume.cpp volumeappletimpl.cpp | 4 | SOURCES= volume.cpp volumeappletimpl.cpp oledbox.cpp |
5 | TARGET = volumeapplet | 5 | TARGET = volumeapplet |
6 | DESTDIR = $(OPIEDIR)/plugins/applets | 6 | DESTDIR = $(OPIEDIR)/plugins/applets |
7 | INCLUDEPATH += $(OPIEDIR)/include | 7 | INCLUDEPATH += $(OPIEDIR)/include |
diff --git a/core/applets/volumeapplet/volumeappletimpl.cpp b/core/applets/volumeapplet/volumeappletimpl.cpp index 943e71a..47506cc 100644 --- a/core/applets/volumeapplet/volumeappletimpl.cpp +++ b/core/applets/volumeapplet/volumeappletimpl.cpp | |||
@@ -36,15 +36,6 @@ QWidget *VolumeAppletImpl::applet( QWidget *parent ) | |||
36 | { | 36 | { |
37 | if ( !volume ) | 37 | if ( !volume ) |
38 | volume = new VolumeApplet( parent ); | 38 | volume = new VolumeApplet( parent ); |
39 | |||
40 | Config cfg("qpe"); | ||
41 | cfg.setGroup("Volume"); | ||
42 | QString foo = cfg.readEntry("Mute","TRUE"); | ||
43 | bool muted; | ||
44 | if(foo.find("TRUE",0,TRUE) != -1) | ||
45 | muted = TRUE; | ||
46 | else muted = FALSE; | ||
47 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; //mute | ||
48 | return volume; | 39 | return volume; |
49 | } | 40 | } |
50 | 41 | ||