2
* BW_LED_Number a very very primitive LED
4
* Copyright: Bernd Johannes Wuebben, wuebben@math.cornell.edu
6
* $Id: bwlednum.cpp,v 1.2 1999/03/01 23:37:59 kulow Exp $
8
* $Log: bwlednum.cpp,v $
9
* Revision 1.2 1999/03/01 23:37:59 kulow
10
* CVS_SILENT ported to Qt 2.0
12
* Revision 1.1.1.1.6.1 1999/02/22 22:28:44 kulow
13
* CVS_SILENT replaced old qt header names with new ones
15
* Revision 1.1.1.1 1997/07/04 21:23:49 kulow
16
* Coolo: added Bernd's kscd
18
* Revision 1.1 1997/06/21 23:10:11 wuebben
21
* Revision 1.2 1997/03/22 22:09:37 wuebben
22
* Added support for visibe non-illuminated Segments
24
* Revision 1.1 1997/03/22 12:45:25 wuebben
34
#include <qbitarray.h>
37
#include "bwlednum.moc"
39
#define NUM_OF_SEGMENTS 8
43
static char segs[14][8] =
44
{ { 0, 1, 2, 4, 5, 6,25, 0}, // 0
45
{ 2, 5,25, 0, 0, 0, 0, 0}, // 1
46
{ 1, 2, 3, 4, 6,25 ,0, 0}, // 2
47
{ 1, 2, 3, 5, 6,25, 0, 0}, // 3
48
{ 0, 3, 2, 5 ,25, 0, 0, 0}, // 4
49
{ 0, 1, 3, 5, 6,25, 0, 0}, // 5
50
{ 0, 1, 3, 4, 5, 6,25, 0}, // 6
51
{ 1,2 , 5,25, 0, 0, 0, 0}, // 7
52
{ 0, 1, 2, 3, 4, 5, 6,25}, // 8
53
{ 0, 1, 2, 3, 5, 6,25, 0}, // 9
54
{ 3,25, 0, 0, 0, 0, 0, 0}, // -
55
{ 7,25, 0, 0, 0, 0, 0, 0}, // .
56
{ 8, 9,25, 0, 0, 0, 0, 0}, // :
57
{25, 0, 0, 0, 0, 0, 0, 0} }; // blank
60
BW_LED_Number::BW_LED_Number( QWidget *parent, const char *name )
61
: QFrame( parent, name ){
64
offcolor = QColor(100,0,0);
69
old_segments = &segs[13][0]; // nothing
70
current_segments = &segs[13][0]; // nothing
71
setLEDColor(yellow,black);
75
void dump_segments(char * segs){
77
printf("dumping segments:");
78
for (int i = 0; i <=7; i++){
79
printf("%d:",segs[i]);
85
BW_LED_Number::~BW_LED_Number(){
89
void BW_LED_Number::resizeEvent( QResizeEvent * ){
93
void BW_LED_Number::showOffColon(bool off){
99
void BW_LED_Number::setLEDColor( const QColor& fgColor, const QColor& bgColor ){
104
QColorGroup old_cg = this->colorGroup();
107
QColorGroup new_cg( fgColor, bgColor,
108
fgColor, fgColor, fgColor,
112
this->setPalette(QPalette(new_cg, new_cg, new_cg));
119
static char *getSegments( char s)
122
if (s >= '0' && s <= '9'){
123
return segs[s - '0'];
149
void BW_LED_Number::drawContents( QPainter *p ){
151
drawSymbol( p, current_symbol,TRUE );
156
void BW_LED_Number::display(int i ){
160
display( (char)('0'+ i));
165
void BW_LED_Number::display(char s ){
171
old_symbol = current_symbol;
172
old_segments = current_segments;
174
current_segments = getSegments(s);
176
drawSymbol(&p,s,FALSE);
182
void BW_LED_Number::setSmallLED(bool a_boolean){
184
smallLED = a_boolean;
189
void BW_LED_Number::drawSymbol( QPainter *p,char s,bool repaint ){
191
// printf("drawSymbol repaint = %d\n",repaint);
195
int xSegment_Length, ySegment_Length, Segment_Length, xAdvance;
196
int Xoffset, Yoffset, space;
200
xSegment_Length = width()*5/((5 + space) + space);
201
ySegment_Length = height()*5/12;
202
Segment_Length = ySegment_Length > xSegment_Length ? xSegment_Length : ySegment_Length;
203
xAdvance = Segment_Length*( 5 + space )/5 +1 ;
204
Xoffset = ( width() - xAdvance + Segment_Length/5 )/2;
205
Yoffset = ( height() - Segment_Length*2 )/2;
207
pos = QPoint( Xoffset , Yoffset );
212
// this draw the non-illumintated segments
214
if(show_off_colon){// we want to show the colon which is actually ugly and
215
// by default not shown.
217
for(int l = 0; l <= NUM_OF_SEGMENTS +1; l++){
218
drawSegment(pos,(char) l,*p,Segment_Length,TRUE); //erase segment
222
for(int l = 0; l <= NUM_OF_SEGMENTS -1; l++){
223
drawSegment(pos,(char) l,*p,Segment_Length,TRUE); //erase segment
227
// now draw the illuminated segments
229
for(int l = 0; l <= NUM_OF_SEGMENTS -1; l++){
230
if(current_segments[l] != STOP_CHAR){
231
drawSegment(pos,current_segments[l],*p,Segment_Length,FALSE); // draw segment
238
else{ // we are not repainting ourselves due to a repaint event but rather
239
// genuinely changing the symbol that is to be displayed
241
for(int l = 0; l <= NUM_OF_SEGMENTS -1; l++){
243
if(current_segments[l] != STOP_CHAR){
244
if(!seg_contained_in(current_segments[l],old_segments))
245
drawSegment(pos,current_segments[l],*p,Segment_Length,FALSE); // draw segment
253
for(int k = 0; k <= NUM_OF_SEGMENTS -1; k++){
255
if(old_segments[k] != STOP_CHAR){
256
if(!seg_contained_in(old_segments[k],current_segments))
257
drawSegment(pos,old_segments[k],*p,Segment_Length,TRUE); //erase segment
268
bool BW_LED_Number::seg_contained_in( char c, char* seg){
272
while ( *seg != STOP_CHAR){
273
// printf("Comparing %d with %d\n",c,*seg);
282
void BW_LED_Number::setLEDoffColor(QColor color){
288
void BW_LED_Number::drawSegment( const QPoint &pos, char seg_number, QPainter &p,
289
int Segment_Length, bool erase){
293
QColorGroup g = colorGroup();
294
QColor lightColor,darkColor;
297
lightColor = offcolor;
298
darkColor = offcolor;
301
lightColor = g.light();
302
darkColor = g.dark();
304
int Width = (int) Segment_Length/5;
307
QBrush brush(g.light());
311
pt.ry() += (QCOORD)Width/2;
316
p.setBrush(offcolor);
317
brush.setColor(offcolor);
321
p.setBrush(g.light());
325
switch ( seg_number ) {
332
pts.setPoints(3,pt.x(), pt.y() ,
333
pt.x(), pt.y()-Width +1,
334
pt.x() + Width-1, pt.y());
336
pts.setPoints(3,pt.x(), pt.y() + Segment_Length -Width - Width/2 -1 ,
337
pt.x() + Width -1 , pt.y() -Width +Segment_Length - Width/2 -1,
338
pt.x() , pt.y() + Segment_Length - 3*Width/4 -1);
344
p.fillRect(pt.x(),pt.y()+ Width/2 -1, Width ,
345
Segment_Length - Width -Width +1 ,brush);
350
p.fillRect(pt.x()+Width,pt.y()- Width , Segment_Length -2* Width, Width ,brush);
355
pts.setPoints(3,pt.x()+1, pt.y()-Width ,
356
pt.x()+Width, pt.y()-Width ,
357
pt.x() + Width, pt.y() -1 );
360
pts.setPoints(3,pt.x()+ Segment_Length - Width , pt.y() - Width,
361
pt.x()+ Segment_Length -1, pt.y() - Width,
362
pt.x() + Segment_Length - Width , pt.y() -1 );
369
pt.rx() += (QCOORD)(Segment_Length);
375
pts.setPoints(3,pt.x() , pt.y() ,
376
pt.x() , pt.y() - Width + 1, // changes from 1 to 2
377
pt.x() - Width +1, pt.y() );
381
pts.setPoints(3,pt.x() , pt.y() + Segment_Length - Width - Width/2 -1,
382
pt.x() , pt.y() + Segment_Length - 3*Width/4 - 1,
383
pt.x() - Width +1, pt.y() + Segment_Length - Width - Width/2 -1);
390
p.fillRect(pt.x() - Width+1 ,pt.y() + Width/2- 1, Width ,
391
Segment_Length - Width - Width + 1 ,brush);
396
pt.ry() += (QCOORD)Segment_Length;
398
p.setPen(g.background());
400
pts.setPoints(3,pt.x()-1 , pt.y() - Width/2 -1,
401
pt.x() + Width+2, pt.y()-Width -1 ,//
402
pt.x() + Width+2, pt.y() );
404
pts.setPoints(3,pt.x() + Segment_Length + 1, pt.y() - Width/2 -1 ,
405
pt.x() + Segment_Length - Width - 2 ,
407
pt.x() + Segment_Length - Width - 2, pt.y() );
411
p.fillRect(pt.x() + Width -1 ,pt.y() - Width, Segment_Length- 2* Width + 3,
416
pt.ry() += (QCOORD)(Segment_Length +1);
417
p.fillRect(pt.x(), pt.y(), Width , Segment_Length - Width - Width/2 ,brush);
421
pts.setPoints(3,pt.x(), pt.y(),
422
pt.x(), pt.y()-Width+1,
423
pt.x() + Width-1, pt.y());
425
pts.setPoints(3,pt.x(), pt.y() + Segment_Length -Width - Width/2 -1 ,
426
pt.x() + Width -1 , pt.y() -Width +Segment_Length - Width/2 -1 ,
427
pt.x() , pt.y() + Segment_Length - 3*Width/4 -1);
435
pt.rx() += (QCOORD)(Segment_Length );
436
pt.ry() += (QCOORD)(Segment_Length +1);
437
p.fillRect(pt.x() - Width +1 ,pt.y(), Width ,
438
Segment_Length - Width - Width/2 ,brush);
443
pts.setPoints(3,pt.x() , pt.y(),
444
pt.x() , pt.y() - Width +1,
445
pt.x() - Width +1, pt.y());
449
pts.setPoints(3,pt.x() , pt.y() + Segment_Length - Width - Width/2 -1,
450
pt.x() , pt.y() + Segment_Length - 3*Width/4 -1,
451
pt.x() - Width +1, pt.y() + Segment_Length - Width - Width/2 -1);
460
pt.ry() += (QCOORD)(Segment_Length*2 );
461
p.fillRect(pt.x() + Width ,pt.y() -Width , Segment_Length -2* Width ,
467
pts.setPoints(3,pt.x()+1, pt.y()-1,
468
pt.x() + Width, pt.y() - Width,
469
pt.x() + Width, pt.y() - 1 );
472
pts.setPoints(3, pt.x() + Segment_Length - 1, pt.y()-1,
473
pt.x() + Segment_Length - Width , pt.y() - Width,
474
pt.x() + Segment_Length - Width , pt.y() - 1 );
485
pt.rx() += (QCOORD)(Segment_Length/2);
486
pt.ry() += (QCOORD)(Segment_Length*2);
487
p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush);
490
pt.ry() += (QCOORD)(Segment_Length/2 + Width/2);
491
pt.rx() += (QCOORD)(Segment_Length/2 - Width/2 + 1);
493
if (!show_off_colon && erase) {
495
brush.setColor(bgcolor);
498
p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush);
501
if (!show_off_colon && erase) {
503
brush.setColor(fgcolor);
508
pt.ry() += (QCOORD)(3*Segment_Length/2 + Width/2);
509
pt.rx() += (QCOORD)(Segment_Length/2 - Width/2 + 1);
511
if (!show_off_colon && erase) {
513
brush.setColor(bgcolor);
515
p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush);
517
if (!show_off_colon && erase) {
519
brush.setColor(fgcolor);
524
} /* if (!smallLED) */
528
pt.ry() += (QCOORD)Width/2;
530
switch ( seg_number ) {
532
p.fillRect(pt.x(),pt.y()+ Width /2, Width , Segment_Length - Width -Width/2 ,brush);
535
p.fillRect(pt.x()+Width,pt.y()- Width , Segment_Length -2* Width, Width ,brush);
538
pt.rx() += (QCOORD)(Segment_Length);
539
p.fillRect(pt.x()-Width,pt.y()+ Width/2, Width ,
540
Segment_Length - Width -Width/2 ,brush);
543
pt.ry() += (QCOORD)Segment_Length;
544
p.fillRect(pt.x() + Width ,pt.y() - Width, Segment_Length- 2* Width, Width ,brush);
547
pt.ry() += (QCOORD)(Segment_Length );
548
p.fillRect(pt.x(), pt.y(), Width , Segment_Length - Width - Width/2 ,brush);
551
pt.rx() += (QCOORD)(Segment_Length );
552
pt.ry() += (QCOORD)(Segment_Length );
553
p.fillRect(pt.x() - Width ,pt.y(), Width ,
554
Segment_Length - Width - Width/2 ,brush);
557
pt.ry() += (QCOORD)(Segment_Length*2);
558
p.fillRect(pt.x() + Width ,pt.y() -Width , Segment_Length -2* Width ,
562
pt.rx() += (QCOORD)(Segment_Length/2);
563
pt.ry() += (QCOORD)(Segment_Length*2);
564
p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush);
567
pt.ry() += (QCOORD)(Segment_Length/2 + Width/2);
568
pt.rx() += (QCOORD)(Segment_Length/2 - Width/2 + 1);
569
if (!show_off_colon && erase) {
571
brush.setColor(bgcolor);
574
p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush);
576
if (!show_off_colon && erase) {
578
brush.setColor(fgcolor);
583
pt.ry() += (QCOORD)(3*Segment_Length/2 + Width/2);
584
pt.rx() += (QCOORD)(Segment_Length/2 - Width/2 + 1);
586
if (!show_off_colon && erase) {
588
brush.setColor(bgcolor);
590
p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush);
591
if (!show_off_colon && erase) {
593
brush.setColor(fgcolor);