-rw-r--r-- | core/applets/volumeapplet/oledbox.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/core/applets/volumeapplet/oledbox.cpp b/core/applets/volumeapplet/oledbox.cpp index 3036929..7547287 100644 --- a/core/applets/volumeapplet/oledbox.cpp +++ b/core/applets/volumeapplet/oledbox.cpp | |||
@@ -1,270 +1,275 @@ | |||
1 | 1 | ||
2 | #include <qpixmap.h> | 2 | #include <qpixmap.h> |
3 | #include <qbitmap.h> | 3 | #include <qbitmap.h> |
4 | #include <qpainter.h> | 4 | #include <qpainter.h> |
5 | 5 | ||
6 | #include "oledbox.h" | 6 | #include "oledbox.h" |
7 | 7 | ||
8 | 8 | ||
9 | #ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC | 9 | #ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC |
10 | 10 | ||
11 | /* XPM */ | 11 | /* XPM */ |
12 | static const char * ledborder_xpm[] = { | 12 | static const char * ledborder_xpm[] = { |
13 | "16 16 11 1", | 13 | "16 16 11 1", |
14 | " c None", | 14 | " c None", |
15 | ".c #626562", | 15 | ".c #626562", |
16 | "+c #7B7D7B", | 16 | "+c #7B7D7B", |
17 | "@c #949594", | 17 | "@c #949594", |
18 | "#c #ACAEAC", | 18 | "#c #ACAEAC", |
19 | "$c #CDCACD", | 19 | "$c #CDCACD", |
20 | "%c #CDCECD", | 20 | "%c #CDCECD", |
21 | ";c #E6E6E6", | 21 | ";c #E6E6E6", |
22 | ">c #FFFFFF", | 22 | ">c #FFFFFF", |
23 | ",c #E6E2E6", | 23 | ",c #E6E2E6", |
24 | "'c #FFFAFF", | 24 | "'c #FFFAFF", |
25 | " .++@@# ", | 25 | " .++@@# ", |
26 | " ...++@@##$ ", | 26 | " ...++@@##$ ", |
27 | " .....+@##$$% ", | 27 | " .....+@##$$% ", |
28 | " ..... #$%%% ", | 28 | " ..... #$%%% ", |
29 | " ... %%; ", | 29 | " ... %%; ", |
30 | ".... ;;;;", | 30 | ".... ;;;;", |
31 | "++. ;>>", | 31 | "++. ;>>", |
32 | "+++ >>>", | 32 | "+++ >>>", |
33 | "@@@ >>>", | 33 | "@@@ >>>", |
34 | "@@# >>>", | 34 | "@@# >>>", |
35 | "#### >>>>", | 35 | "#### >>>>", |
36 | " #$$ >>> ", | 36 | " #$$ >>> ", |
37 | " $$,,' >>>>> ", | 37 | " $$,,' >>>>> ", |
38 | " ,,,''>>>>>>> ", | 38 | " ,,,''>>>>>>> ", |
39 | " ,''>>>>>>> ", | 39 | " ,''>>>>>>> ", |
40 | " '>>>>> "}; | 40 | " '>>>>> "}; |
41 | 41 | ||
42 | 42 | ||
43 | QPixmap *OLedBox::s_border_pix = 0; | 43 | QPixmap *OLedBox::s_border_pix = 0; |
44 | 44 | ||
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | 47 | ||
48 | OLedBox::OLedBox ( const QColor &col, QWidget *parent, const char *name ) : QWidget ( parent, name ) | 48 | OLedBox::OLedBox ( const QColor &col, QWidget *parent, const char *name ) : QWidget ( parent, name ) |
49 | { | 49 | { |
50 | m_color = col; | 50 | m_color = col; |
51 | m_on = false; | 51 | m_on = false; |
52 | 52 | ||
53 | m_pix [ 0 ] = m_pix [ 1 ] = false; | 53 | m_pix [ 0 ] = m_pix [ 1 ] = false; |
54 | 54 | ||
55 | setBackgroundMode ( PaletteBackground ); | 55 | setBackgroundMode ( PaletteBackground ); |
56 | 56 | ||
57 | #ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC | 57 | #ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC |
58 | if ( !s_border_pix ) | 58 | if ( !s_border_pix ) |
59 | s_border_pix = new QPixmap ( ledborder_xpm ); | 59 | s_border_pix = new QPixmap ( ledborder_xpm ); |
60 | #endif | 60 | #endif |
61 | } | 61 | } |
62 | 62 | ||
63 | OLedBox::~OLedBox ( ) | 63 | OLedBox::~OLedBox ( ) |
64 | { | 64 | { |
65 | delete m_pix [ 0 ]; | 65 | delete m_pix [ 0 ]; |
66 | delete m_pix [ 1 ]; | 66 | delete m_pix [ 1 ]; |
67 | } | 67 | } |
68 | 68 | ||
69 | QSize OLedBox::sizeHint ( ) const | 69 | QSize OLedBox::sizeHint ( ) const |
70 | { | 70 | { |
71 | return QSize ( 16, 16 ); | 71 | return QSize ( 16, 16 ); |
72 | } | 72 | } |
73 | 73 | ||
74 | bool OLedBox::isOn ( ) const | 74 | bool OLedBox::isOn ( ) const |
75 | { | 75 | { |
76 | return m_on; | 76 | return m_on; |
77 | } | 77 | } |
78 | 78 | ||
79 | QColor OLedBox::color ( ) const | 79 | QColor OLedBox::color ( ) const |
80 | { | 80 | { |
81 | return m_color; | 81 | return m_color; |
82 | } | 82 | } |
83 | 83 | ||
84 | void OLedBox::setOn ( bool b ) | 84 | void OLedBox::setOn ( bool b ) |
85 | { | 85 | { |
86 | if ( m_on != b ) { | 86 | if ( m_on != b ) { |
87 | m_on = b; | 87 | m_on = b; |
88 | update ( ); | 88 | update ( ); |
89 | } | 89 | } |
90 | } | 90 | } |
91 | 91 | ||
92 | void OLedBox::toggle ( ) | 92 | void OLedBox::toggle ( ) |
93 | { | 93 | { |
94 | setOn ( !isOn ( ) ); | 94 | setOn ( !isOn ( ) ); |
95 | } | 95 | } |
96 | 96 | ||
97 | void OLedBox::setColor ( const QColor &col ) | 97 | void OLedBox::setColor ( const QColor &col ) |
98 | { | 98 | { |
99 | if ( m_color != col ) { | 99 | if ( m_color != col ) { |
100 | m_color = col; | 100 | m_color = col; |
101 | 101 | ||
102 | delete m_pix [ 0 ]; | 102 | delete m_pix [ 0 ]; |
103 | delete m_pix [ 1 ]; | 103 | delete m_pix [ 1 ]; |
104 | 104 | ||
105 | update ( ); | 105 | update ( ); |
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | void OLedBox::mousePressEvent ( QMouseEvent *e ) | 109 | void OLedBox::mousePressEvent ( QMouseEvent *e ) |
110 | { | 110 | { |
111 | if ( e-> button ( ) == LeftButton ) { | 111 | if ( e-> button ( ) == LeftButton ) { |
112 | m_on = !m_on; | 112 | m_on = !m_on; |
113 | update ( ); | 113 | update ( ); |
114 | emit toggled ( m_on ); | 114 | emit toggled ( m_on ); |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | void OLedBox::resizeEvent ( QResizeEvent * ) | 119 | void OLedBox::resizeEvent ( QResizeEvent * ) |
120 | { | 120 | { |
121 | delete m_pix [ 0 ]; | 121 | delete m_pix [ 0 ]; |
122 | delete m_pix [ 1 ]; | 122 | delete m_pix [ 1 ]; |
123 | 123 | ||
124 | update ( ); | 124 | update ( ); |
125 | } | 125 | } |
126 | 126 | ||
127 | void OLedBox::paintEvent ( QPaintEvent *e ) | 127 | void OLedBox::paintEvent ( QPaintEvent *e ) |
128 | { | 128 | { |
129 | int ind = m_on ? 1 : 0; | 129 | int ind = m_on ? 1 : 0; |
130 | 130 | ||
131 | if ( !m_pix [ ind ] ) { | 131 | if ( !m_pix [ ind ] ) { |
132 | m_pix [ ind ] = new QPixmap ( size ( )); | 132 | m_pix [ ind ] = new QPixmap ( size ( )); |
133 | 133 | ||
134 | drawLed ( m_pix [ ind ], m_on ? m_color : m_color. dark ( 300 ) ); | 134 | drawLed ( m_pix [ ind ], m_on ? m_color : m_color. dark ( 300 ) ); |
135 | } | 135 | } |
136 | if ( !e-> erased ( )) | 136 | if ( !e-> erased ( )) |
137 | erase ( ); | 137 | erase ( ); |
138 | 138 | ||
139 | QPainter p ( this ); | 139 | QPainter p ( this ); |
140 | p. drawPixmap ( 0, 0, *m_pix [ ind ] ); | 140 | p. drawPixmap ( 0, 0, *m_pix [ ind ] ); |
141 | } | 141 | } |
142 | 142 | ||
143 | // From KDE libkdeui / led.cpp | 143 | // From KDE libkdeui / led.cpp |
144 | 144 | ||
145 | void OLedBox::drawLed ( QPixmap *pix, const QColor &col ) // paint a ROUND SUNKEN led lamp | 145 | void OLedBox::drawLed ( QPixmap *pix, const QColor &col ) // paint a ROUND SUNKEN led lamp |
146 | { | 146 | { |
147 | QPainter paint; | 147 | QPainter paint; |
148 | QColor color; | 148 | QColor color; |
149 | QBrush brush; | 149 | QBrush brush; |
150 | QPen pen; | 150 | QPen pen; |
151 | 151 | ||
152 | pix-> fill ( black ); | ||
153 | |||
152 | // First of all we want to know what area should be updated | 154 | // First of all we want to know what area should be updated |
153 | // Initialize coordinates, width, and height of the LED | 155 | // Initialize coordinates, width, and height of the LED |
154 | int width = pix-> width ( ); | 156 | int width = pix-> width ( ); |
155 | 157 | ||
156 | // Make sure the LED is round! | 158 | // Make sure the LED is round! |
157 | if ( width > pix-> height ( )) | 159 | if ( width > pix-> height ( )) |
158 | width = pix-> height ( ); | 160 | width = pix-> height ( ); |
159 | width -= 2; // leave one pixel border | 161 | width -= 2; // leave one pixel border |
160 | if ( width < 0 ) | 162 | if ( width < 0 ) |
161 | width = 0; | 163 | width = 0; |
162 | 164 | ||
163 | // maybe we could stop HERE, if width <=0 ? | 165 | // maybe we could stop HERE, if width <=0 ? |
164 | 166 | ||
165 | // start painting widget | 167 | // start painting widget |
166 | // | 168 | // |
167 | paint.begin( pix ); | 169 | paint.begin( pix ); |
168 | 170 | ||
169 | // Set the color of the LED according to given parameters | 171 | // Set the color of the LED according to given parameters |
170 | color = col; | 172 | color = col; |
171 | 173 | ||
172 | // Set the brush to SolidPattern, this fills the entire area | 174 | // Set the brush to SolidPattern, this fills the entire area |
173 | // of the ellipse which is drawn first | 175 | // of the ellipse which is drawn first |
174 | brush.setStyle( QBrush::SolidPattern ); | 176 | brush.setStyle( QBrush::SolidPattern ); |
175 | brush.setColor( color ); | 177 | brush.setColor( color ); |
176 | paint.setBrush( brush ); // Assign the brush to the painter | 178 | paint.setBrush( brush ); // Assign the brush to the painter |
177 | 179 | ||
178 | // Draws a "flat" LED with the given color: | 180 | // Draws a "flat" LED with the given color: |
179 | paint.drawEllipse( 1, 1, width, width ); | 181 | paint.drawEllipse( 1, 1, width, width ); |
180 | 182 | ||
181 | // Draw the bright light spot of the LED now, using modified "old" | 183 | // Draw the bright light spot of the LED now, using modified "old" |
182 | // painter routine taken from KDEUIs KLed widget: | 184 | // painter routine taken from KDEUIs KLed widget: |
183 | 185 | ||
184 | // Setting the new width of the pen is essential to avoid "pixelized" | 186 | // Setting the new width of the pen is essential to avoid "pixelized" |
185 | // shadow like it can be observed with the old LED code | 187 | // shadow like it can be observed with the old LED code |
186 | pen.setWidth( 2 ); | 188 | pen.setWidth( 2 ); |
187 | 189 | ||
188 | // shrink the light on the LED to a size about 2/3 of the complete LED | 190 | // shrink the light on the LED to a size about 2/3 of the complete LED |
189 | int pos = width / 5 + 1; | 191 | int pos = width / 5 + 1; |
190 | int light_width = width; | 192 | int light_width = width; |
191 | light_width *= 2; | 193 | light_width *= 2; |
192 | light_width /= 3; | 194 | light_width /= 3; |
193 | 195 | ||
194 | // Calculate the LEDs "light factor": | 196 | // Calculate the LEDs "light factor": |
195 | int light_quote = ( 130 * 2 / ( light_width ? light_width : 1 ) ) + 100; | 197 | int light_quote = ( 130 * 2 / ( light_width ? light_width : 1 ) ) + 100; |
196 | 198 | ||
197 | // Now draw the bright spot on the LED: | 199 | // Now draw the bright spot on the LED: |
198 | while ( light_width ) | 200 | while ( light_width ) |
199 | { | 201 | { |
200 | color = color.light( light_quote ); // make color lighter | 202 | color = color.light( light_quote ); // make color lighter |
201 | pen.setColor( color ); // set color as pen color | 203 | pen.setColor( color ); // set color as pen color |
202 | paint.setPen( pen ); // select the pen for drawing | 204 | paint.setPen( pen ); // select the pen for drawing |
203 | paint.drawEllipse( pos, pos, light_width, light_width ); // draw the ellipse (circle) | 205 | paint.drawEllipse( pos, pos, light_width, light_width ); // draw the ellipse (circle) |
204 | light_width--; | 206 | light_width--; |
205 | if ( !light_width ) | 207 | if ( !light_width ) |
206 | break; | 208 | break; |
207 | paint.drawEllipse( pos, pos, light_width, light_width ); | 209 | paint.drawEllipse( pos, pos, light_width, light_width ); |
208 | light_width--; | 210 | light_width--; |
209 | if ( !light_width ) | 211 | if ( !light_width ) |
210 | break; | 212 | break; |
211 | paint.drawEllipse( pos, pos, light_width, light_width ); | 213 | paint.drawEllipse( pos, pos, light_width, light_width ); |
212 | pos++; | 214 | pos++; |
213 | light_width--; | 215 | light_width--; |
214 | } | 216 | } |
215 | 217 | ||
216 | // Drawing of bright spot finished, now draw a thin border | 218 | // Drawing of bright spot finished, now draw a thin border |
217 | // around the LED which resembles a shadow with light coming | 219 | // around the LED which resembles a shadow with light coming |
218 | // from the upper left. | 220 | // from the upper left. |
219 | 221 | ||
220 | #ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC | 222 | #ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC |
221 | paint. drawPixmap ( 0, 0, *s_border_pix ); | 223 | paint. drawPixmap ( 0, 0, *s_border_pix ); |
222 | 224 | paint. end ( ); | |
225 | |||
226 | pix-> setMask ( pix-> createHeuristicMask ( )); | ||
227 | |||
223 | #else | 228 | #else |
224 | pen.setWidth( 3 ); | 229 | pen.setWidth( 3 ); |
225 | brush.setStyle( QBrush::NoBrush ); // Switch off the brush | 230 | brush.setStyle( QBrush::NoBrush ); // Switch off the brush |
226 | paint.setBrush( brush ); // This avoids filling of the ellipse | 231 | paint.setBrush( brush ); // This avoids filling of the ellipse |
227 | 232 | ||
228 | // Set the initial color value to 200 (bright) and start | 233 | // Set the initial color value to 200 (bright) and start |
229 | // drawing the shadow border at 45 (45*16 = 720). | 234 | // drawing the shadow border at 45 (45*16 = 720). |
230 | int shadow_color = 200, angle; | 235 | int shadow_color = 200, angle; |
231 | 236 | ||
232 | for ( angle = 720; angle < 6480; angle += 240 ) | 237 | for ( angle = 720; angle < 6480; angle += 240 ) |
233 | { | 238 | { |
234 | color.setRgb( shadow_color, shadow_color, shadow_color ); | 239 | color.setRgb( shadow_color, shadow_color, shadow_color ); |
235 | pen.setColor( color ); | 240 | pen.setColor( color ); |
236 | paint.setPen( pen ); | 241 | paint.setPen( pen ); |
237 | paint.drawArc( 0, 0, width+2, width+2, angle, 240 ); | 242 | paint.drawArc( 0, 0, width+2, width+2, angle, 240 ); |
238 | paint.drawArc( 1, 1, width, width, angle, 240 ); | 243 | paint.drawArc( 1, 1, width, width, angle, 240 ); |
239 | paint.drawArc( 2, 2, width-2, width-2, angle, 240 ); | 244 | paint.drawArc( 2, 2, width-2, width-2, angle, 240 ); |
240 | if ( angle < 2320 ) { | 245 | if ( angle < 2320 ) { |
241 | shadow_color -= 25; // set color to a darker value | 246 | shadow_color -= 25; // set color to a darker value |
242 | if ( shadow_color < 100 ) | 247 | if ( shadow_color < 100 ) |
243 | shadow_color = 100; | 248 | shadow_color = 100; |
244 | } | 249 | } |
245 | else if ( ( angle > 2320 ) && ( angle < 5760 ) ) { | 250 | else if ( ( angle > 2320 ) && ( angle < 5760 ) ) { |
246 | shadow_color += 25; // set color to a brighter value | 251 | shadow_color += 25; // set color to a brighter value |
247 | if ( shadow_color > 255 ) | 252 | if ( shadow_color > 255 ) |
248 | shadow_color = 255; | 253 | shadow_color = 255; |
249 | } | 254 | } |
250 | else { | 255 | else { |
251 | shadow_color -= 25; // set color to a darker value again | 256 | shadow_color -= 25; // set color to a darker value again |
252 | if ( shadow_color < 100 ) | 257 | if ( shadow_color < 100 ) |
253 | shadow_color = 100; | 258 | shadow_color = 100; |
254 | } // end if ( angle < 2320 ) | 259 | } // end if ( angle < 2320 ) |
255 | } // end for ( angle = 720; angle < 6480; angle += 160 ) | 260 | } // end for ( angle = 720; angle < 6480; angle += 160 ) |
256 | #endif | ||
257 | paint.end(); | 261 | paint.end(); |
258 | // | 262 | // |
259 | // painting done | 263 | // painting done |
260 | 264 | ||
261 | QBitmap mask ( pix-> width ( ), pix-> height ( ), true ); | 265 | QBitmap mask ( pix-> width ( ), pix-> height ( ), true ); |
262 | QPainter mp ( &mask ); | 266 | QPainter mp ( &mask ); |
263 | mp. setPen ( Qt::NoPen ); | 267 | mp. setPen ( Qt::NoPen ); |
264 | mp. setBrush ( Qt::color1 ); | 268 | mp. setBrush ( Qt::color1 ); |
265 | mp. drawEllipse ( 0, 0, width + 2, width + 2 ); | 269 | mp. drawEllipse ( 0, 0, width + 2, width + 2 ); |
266 | mp. end ( ); | 270 | mp. end ( ); |
267 | 271 | ||
268 | pix-> setMask ( mask ); | 272 | pix-> setMask ( mask ); |
273 | #endif | ||
269 | } | 274 | } |
270 | 275 | ||