summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/libopieui2.control2
-rw-r--r--libopie2/opieui/oledbox.cpp277
-rw-r--r--libopie2/opieui/oledbox.h56
-rw-r--r--libopie2/opieui/opieui.pro2
4 files changed, 336 insertions, 1 deletions
diff --git a/libopie2/opieui/libopieui2.control b/libopie2/opieui/libopieui2.control
index 07dafb9..51cabf7 100644
--- a/libopie2/opieui/libopieui2.control
+++ b/libopie2/opieui/libopieui2.control
@@ -1,10 +1,10 @@
1Package: libopieui2 1Package: libopieui2
2Files: lib/libopieui2.so.* 2Files: lib/libopieui2.so.*
3Priority: optional 3Priority: optional
4Section: opie/system 4Section: opie/system
5Maintainer: Opie Team <opie@handhelds.org> 5Maintainer: Opie Team <opie@handhelds.org>
6Architecture: arm 6Architecture: arm
7Version: 1.8.5-$SUB_VERSION.1 7Version: $QPE_VERSION$EXTRAVERSION
8Depends: libqpe1, libopiecore2 (1.8.5) 8Depends: libqpe1, libopiecore2 (1.8.5)
9Provides: libopieui2 9Provides: libopieui2
10Description: Opie library 2.0 UI 10Description: Opie library 2.0 UI
diff --git a/libopie2/opieui/oledbox.cpp b/libopie2/opieui/oledbox.cpp
new file mode 100644
index 0000000..52826f1
--- a/dev/null
+++ b/libopie2/opieui/oledbox.cpp
@@ -0,0 +1,277 @@
1
2#include <qbitmap.h>
3#include <qpainter.h>
4
5#include "oledbox.h"
6
7
8#ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC
9
10/* XPM */
11static const char * ledborder_xpm[] = {
12"16 16 11 1",
13 " c None",
14 ".c #626562",
15 "+c #7B7D7B",
16 "@c #949594",
17 "#c #ACAEAC",
18 "$c #CDCACD",
19 "%c #CDCECD",
20 ";c #E6E6E6",
21 ">c #FFFFFF",
22 ",c #E6E2E6",
23 "'c #FFFAFF",
24" .++@@# ",
25" ...++@@##$ ",
26" .....+@##$$% ",
27" ..... #$%%% ",
28" ... %%; ",
29".... ;;;;",
30"++. ;>>",
31"+++ >>>",
32"@@@ >>>",
33"@@# >>>",
34"#### >>>>",
35" #$$ >>> ",
36" $$,,' >>>>> ",
37" ,,,''>>>>>>> ",
38" ,''>>>>>>> ",
39" '>>>>> "};
40
41
42QPixmap *OLedBox::s_border_pix = 0;
43
44#endif
45
46
47OLedBox::OLedBox ( const QColor &col, QWidget *parent, const char *name ) : QWidget ( parent, name )
48{
49 m_color = col;
50 m_on = false;
51 m_readonly = true;
52
53 m_pix [ 0 ] = m_pix [ 1 ] = 0;
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
63OLedBox::~OLedBox ( )
64{
65 delete m_pix [ 0 ];
66 delete m_pix [ 1 ];
67}
68
69QSize OLedBox::sizeHint ( ) const
70{
71 return QSize ( 16, 16 );
72}
73
74bool OLedBox::isOn ( ) const
75{
76 return m_on;
77}
78
79QColor OLedBox::color ( ) const
80{
81 return m_color;
82}
83
84void OLedBox::setOn ( bool b )
85{
86 if ( m_on != b ) {
87 m_on = b;
88 update ( );
89 }
90}
91
92void OLedBox::toggle ( )
93{
94 setOn ( !isOn ( ) );
95}
96
97void 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 m_pix[0] = m_pix[1] = 0;
105 update ( );
106 }
107}
108
109void OLedBox::mousePressEvent ( QMouseEvent *e )
110{
111 if ( ! m_readonly &&
112 e-> button ( ) == LeftButton ) {
113 m_on = !m_on;
114 update ( );
115 emit toggled ( m_on );
116 }
117}
118
119
120void OLedBox::resizeEvent ( QResizeEvent * )
121{
122 delete m_pix [ 0 ];
123 delete m_pix [ 1 ];
124 m_pix[0] = m_pix[1] = 0;
125
126 update ( );
127}
128
129void OLedBox::paintEvent ( QPaintEvent *e )
130{
131 int ind = m_on ? 1 : 0;
132
133 if ( !m_pix [ ind ] ) {
134 m_pix [ ind ] = new QPixmap ( size ( ));
135
136 drawLed ( m_pix [ ind ], m_on ? m_color : m_color. dark ( 300 ) );
137 }
138 if ( !e-> erased ( ))
139 erase ( );
140
141 QPainter p ( this );
142 p. drawPixmap ( 0, 0, *m_pix [ ind ] );
143}
144
145// From KDE libkdeui / led.cpp
146
147void OLedBox::drawLed ( QPixmap *pix, const QColor &col ) // paint a ROUND SUNKEN led lamp
148{
149 QPainter paint;
150 QColor color;
151 QBrush brush;
152 QPen pen;
153
154 pix-> fill ( black );
155
156 // First of all we want to know what area should be updated
157 // Initialize coordinates, width, and height of the LED
158 int width = pix-> width ( );
159
160 // Make sure the LED is round!
161 if ( width > pix-> height ( ))
162 width = pix-> height ( );
163 width -= 2; // leave one pixel border
164 if ( width < 0 )
165 width = 0;
166
167 // maybe we could stop HERE, if width <=0 ?
168
169 // start painting widget
170 //
171 paint.begin( pix );
172
173 // Set the color of the LED according to given parameters
174 color = col;
175
176 // Set the brush to SolidPattern, this fills the entire area
177 // of the ellipse which is drawn first
178 brush.setStyle( QBrush::SolidPattern );
179 brush.setColor( color );
180 paint.setBrush( brush ); // Assign the brush to the painter
181
182 // Draws a "flat" LED with the given color:
183 paint.drawEllipse( 1, 1, width, width );
184
185 // Draw the bright light spot of the LED now, using modified "old"
186 // painter routine taken from KDEUIs KLed widget:
187
188 // Setting the new width of the pen is essential to avoid "pixelized"
189 // shadow like it can be observed with the old LED code
190 pen.setWidth( 2 );
191
192 // shrink the light on the LED to a size about 2/3 of the complete LED
193 int pos = width / 5 + 1;
194 int light_width = width;
195 light_width *= 2;
196 light_width /= 3;
197
198 // Calculate the LEDs "light factor":
199 int light_quote = ( 130 * 2 / ( light_width ? light_width : 1 ) ) + 100;
200
201 // Now draw the bright spot on the LED:
202 while ( light_width )
203 {
204 color = color.light( light_quote ); // make color lighter
205 pen.setColor( color ); // set color as pen color
206 paint.setPen( pen ); // select the pen for drawing
207 paint.drawEllipse( pos, pos, light_width, light_width ); // draw the ellipse (circle)
208 light_width--;
209 if ( !light_width )
210 break;
211 paint.drawEllipse( pos, pos, light_width, light_width );
212 light_width--;
213 if ( !light_width )
214 break;
215 paint.drawEllipse( pos, pos, light_width, light_width );
216 pos++;
217 light_width--;
218 }
219
220 // Drawing of bright spot finished, now draw a thin border
221 // around the LED which resembles a shadow with light coming
222 // from the upper left.
223
224#ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC
225 paint. drawPixmap ( 0, 0, *s_border_pix );
226 paint. end ( );
227
228 pix-> setMask ( pix-> createHeuristicMask ( ));
229
230#else
231 pen.setWidth( 3 );
232 brush.setStyle( QBrush::NoBrush ); // Switch off the brush
233 paint.setBrush( brush ); // This avoids filling of the ellipse
234
235 // Set the initial color value to 200 (bright) and start
236 // drawing the shadow border at 45 (45*16 = 720).
237 int shadow_color = 200, angle;
238
239 for ( angle = 720; angle < 6480; angle += 240 )
240 {
241 color.setRgb( shadow_color, shadow_color, shadow_color );
242 pen.setColor( color );
243 paint.setPen( pen );
244 paint.drawArc( 0, 0, width+2, width+2, angle, 240 );
245 paint.drawArc( 1, 1, width, width, angle, 240 );
246 paint.drawArc( 2, 2, width-2, width-2, angle, 240 );
247 if ( angle < 2320 ) {
248 shadow_color -= 25; // set color to a darker value
249 if ( shadow_color < 100 )
250 shadow_color = 100;
251 }
252 else if ( ( angle > 2320 ) && ( angle < 5760 ) ) {
253 shadow_color += 25; // set color to a brighter value
254 if ( shadow_color > 255 )
255 shadow_color = 255;
256 }
257 else {
258 shadow_color -= 25; // set color to a darker value again
259 if ( shadow_color < 100 )
260 shadow_color = 100;
261 } // end if ( angle < 2320 )
262 } // end for ( angle = 720; angle < 6480; angle += 160 )
263 paint.end();
264 //
265 // painting done
266
267 QBitmap mask ( pix-> width ( ), pix-> height ( ), true );
268 QPainter mp ( &mask );
269 mp. setPen ( Qt::NoPen );
270 mp. setBrush ( Qt::color1 );
271 mp. drawEllipse ( 0, 0, width + 2, width + 2 );
272 mp. end ( );
273
274 pix-> setMask ( mask );
275#endif
276}
277
diff --git a/libopie2/opieui/oledbox.h b/libopie2/opieui/oledbox.h
new file mode 100644
index 0000000..dd930bd
--- a/dev/null
+++ b/libopie2/opieui/oledbox.h
@@ -0,0 +1,56 @@
1#ifndef __OPIE_OLED_H__
2#define __OPIE_OLED_H__
3
4#include <qwidget.h>
5#include <qcolor.h>
6
7class QPixmap;
8
9#define _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC
10
11class OLedBox : public QWidget {
12 Q_OBJECT
13
14public:
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 void setReadOnly( bool R )
21 { m_readonly = R; }
22 inline bool readOnly( void ) const
23 { return m_readonly; }
24
25 virtual QSize sizeHint ( ) const;
26
27public slots:
28 void toggle ( );
29 void setOn ( bool on );
30 void setColor ( const QColor &col );
31
32signals:
33 void toggled ( bool );
34
35protected:
36 virtual void paintEvent ( QPaintEvent *e );
37 virtual void resizeEvent ( QResizeEvent *e );
38
39 virtual void mousePressEvent ( QMouseEvent *e );
40
41private:
42 void drawLed ( QPixmap *, const QColor &col );
43
44private:
45 QPixmap *m_pix [2];
46
47 QColor m_color;
48 bool m_on;
49 bool m_readonly;
50
51 #ifdef _QTE_IS_TOO_DUMB_TO_DRAW_AN_ARC
52 static QPixmap *s_border_pix;
53#endif
54};
55
56#endif
diff --git a/libopie2/opieui/opieui.pro b/libopie2/opieui/opieui.pro
index 8cae43f..24157a1 100644
--- a/libopie2/opieui/opieui.pro
+++ b/libopie2/opieui/opieui.pro
@@ -1,63 +1,65 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3DESTDIR = $(OPIEDIR)/lib 3DESTDIR = $(OPIEDIR)/lib
4HEADERS = oclickablelabel.h \ 4HEADERS = oclickablelabel.h \
5 odialog.h \ 5 odialog.h \
6 ofontselector.h \ 6 ofontselector.h \
7 oimageeffect.h \ 7 oimageeffect.h \
8 okeyconfigwidget.h \ 8 okeyconfigwidget.h \
9 olistview.h \ 9 olistview.h \
10 opixmapeffect.h \ 10 opixmapeffect.h \
11 opopupmenu.h \ 11 opopupmenu.h \
12 opixmapprovider.h \ 12 opixmapprovider.h \
13 oselector.h \ 13 oselector.h \
14 oseparator.h \ 14 oseparator.h \
15 otabinfo.h \ 15 otabinfo.h \
16 otabbar.h \ 16 otabbar.h \
17 otabwidget.h \ 17 otabwidget.h \
18 oledbox.h \
18 otaskbarapplet.h \ 19 otaskbarapplet.h \
19 otimepicker.h \ 20 otimepicker.h \
20 oversatileview.h \ 21 oversatileview.h \
21 oversatileviewitem.h \ 22 oversatileviewitem.h \
22 owait.h 23 owait.h
23 24
24SOURCES = oclickablelabel.cpp \ 25SOURCES = oclickablelabel.cpp \
25 odialog.cpp \ 26 odialog.cpp \
26 ofontselector.cpp \ 27 ofontselector.cpp \
27 oimageeffect.cpp \ 28 oimageeffect.cpp \
28 okeyconfigwidget.cpp \ 29 okeyconfigwidget.cpp \
29 olistview.cpp \ 30 olistview.cpp \
30 opixmapeffect.cpp \ 31 opixmapeffect.cpp \
31 opopupmenu.cpp \ 32 opopupmenu.cpp \
32 opixmapprovider.cpp \ 33 opixmapprovider.cpp \
33 oselector.cpp \ 34 oselector.cpp \
34 oseparator.cpp \ 35 oseparator.cpp \
35 otabbar.cpp \ 36 otabbar.cpp \
36 otabwidget.cpp \ 37 otabwidget.cpp \
38 oledbox.cpp \
37 otaskbarapplet.cpp \ 39 otaskbarapplet.cpp \
38 otimepicker.cpp \ 40 otimepicker.cpp \
39 oversatileview.cpp \ 41 oversatileview.cpp \
40 oversatileviewitem.cpp \ 42 oversatileviewitem.cpp \
41 owait.cpp 43 owait.cpp
42 44
43include( big-screen/big-screen.pro ) 45include( big-screen/big-screen.pro )
44include( fileselector/fileselector.pro ) 46include( fileselector/fileselector.pro )
45 47
46INTERFACES = otimepickerbase.ui 48INTERFACES = otimepickerbase.ui
47 49
48TARGET = opieui2 50TARGET = opieui2
49VERSION = 1.8.5 51VERSION = 1.8.5
50 52
51INCLUDEPATH += $(OPIEDIR)/include 53INCLUDEPATH += $(OPIEDIR)/include
52DEPENDPATH += $(OPIEDIR)/include 54DEPENDPATH += $(OPIEDIR)/include
53 55
54LIBS += -lopiecore2 56LIBS += -lopiecore2
55 57
56!contains( platform, x11 ) { 58!contains( platform, x11 ) {
57 include( $(OPIEDIR)/include.pro ) 59 include( $(OPIEDIR)/include.pro )
58} 60}
59 61
60contains( platform, x11 ) { 62contains( platform, x11 ) {
61 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib 63 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib
62} 64}
63 65