2
* BW_LED_Number a very very primitive LED
4
* Copyright: Bernd Johannes Wuebben, wuebben@math.cornell.edu
6
* $Id: bwlednum.cpp,v 1.8 1999/06/27 17:57:37 kulow Exp $
8
* $Log: bwlednum.cpp,v $
9
* Revision 1.8 1999/06/27 17:57:37 kulow
10
* fixes for --enable-final and other problems :)
12
* Revision 1.7 1999/05/17 13:45:35 porten
16
* Revision 1.6 1999/03/01 23:37:46 kulow
17
* CVS_SILENT ported to Qt 2.0
19
* Revision 1.5.6.1 1999/02/22 22:28:30 kulow
20
* CVS_SILENT replaced old qt header names with new ones
22
* Revision 1.5 1998/01/02 00:47:17 wuebben
23
* Bernd: Monster Commit !! Finished CDDB support and Web intergration
26
* Revision 1.4 1997/10/25 15:15:34 wuebben
27
* Bernd: fixed the segfault error if you had no permiision to access the cdrom
30
* Revision 1.2 1997/08/15 22:51:25 wuebben
31
* *** empty log message ***
33
* Revision 1.2 1997/08/15 22:42:54 wuebben
34
* Bernd -- Version 0.4
35
* o Support for cdda on Solaris
37
* o New interactive configuration script
38
* o lot of header, define and configuration changes. -- Keep your
39
* fingers crossed .... ;-)
41
* Revision 1.1 1997/08/14 23:51:07 wuebben
44
* Revision 1.1 1997/06/21 23:09:10 wuebben
47
* Revision 1.2 1997/03/22 22:09:37 wuebben
48
* Added support for visibe non-illuminated Segments
50
* Revision 1.1 1997/03/22 12:45:25 wuebben
60
#include "qbitarray.h"
64
#include "bwlednum.moc"
66
#define NUM_OF_SEGMENTS 8
70
static char segs[14][8] =
71
{ { 0, 1, 2, 4, 5, 6,25, 0}, // 0
72
{ 2, 5,25, 0, 0, 0, 0, 0}, // 1
73
{ 1, 2, 3, 4, 6,25 ,0, 0}, // 2
74
{ 1, 2, 3, 5, 6,25, 0, 0}, // 3
75
{ 0, 3, 2, 5 ,25, 0, 0, 0}, // 4
76
{ 0, 1, 3, 5, 6,25, 0, 0}, // 5
77
{ 0, 1, 3, 4, 5, 6,25, 0}, // 6
78
{ 1,2 , 5,25, 0, 0, 0, 0}, // 7
79
{ 0, 1, 2, 3, 4, 5, 6,25}, // 8
80
{ 0, 1, 2, 3, 5, 6,25, 0}, // 9
81
{ 3,25, 0, 0, 0, 0, 0, 0}, // -
82
{ 7,25, 0, 0, 0, 0, 0, 0}, // .
83
{ 8, 9,25, 0, 0, 0, 0, 0}, // :
84
{25, 0, 0, 0, 0, 0, 0, 0} }; // blank
87
BW_LED_Number::BW_LED_Number( QWidget *parent, const char *name )
88
: QFrame( parent, name ){
91
offcolor = QColor(100,0,0);
95
old_segments = &segs[13][0]; // nothing
96
current_segments = &segs[13][0]; // nothing
97
setLEDColor(yellow,black);
101
void dump_segments(char * segs){
103
printf("dumping segments:");
104
for (int i = 0; i <=7; i++){
105
printf("%d:",segs[i]);
111
BW_LED_Number::~BW_LED_Number(){
115
void BW_LED_Number::resizeEvent( QResizeEvent * ){
119
void BW_LED_Number::showOffColon(bool off){
121
show_off_colon = off;
125
void BW_LED_Number::setLEDColor( const QColor& fgColor, const QColor& bgColor ){
130
QColorGroup old_cg = this->colorGroup();
133
QColorGroup new_cg( fgColor, bgColor,
134
fgColor, fgColor, fgColor,
138
this->setPalette(QPalette(new_cg, new_cg, new_cg));
145
static char *getSegments( char s)
148
if (s >= '0' && s <= '9'){
149
return segs[s - '0'];
175
void BW_LED_Number::drawContents( QPainter *p ){
177
drawSymbol( p, current_symbol,TRUE );
182
void BW_LED_Number::display(int i ){
186
display( (char)('0'+ i));
191
void BW_LED_Number::display(char s){
197
old_segments = current_segments;
199
current_segments = getSegments(s);
201
drawSymbol(&p,s,FALSE);
207
void BW_LED_Number::setSmallLED(bool a_boolean){
209
smallLED = a_boolean;
214
void BW_LED_Number::drawSymbol( QPainter *p,char ,bool repaint ){
216
// printf("drawSymbol repaint = %d\n",repaint);
220
int xSegment_Length, ySegment_Length, Segment_Length, xAdvance;
221
int Xoffset, Yoffset, space;
225
xSegment_Length = width()*5/((5 + space) + space) ;
227
ySegment_Length = height()*5/12;
229
Segment_Length = ySegment_Length > xSegment_Length ? xSegment_Length : ySegment_Length;
231
xAdvance = Segment_Length*( 5 + space )/5 +1 ;
233
// Xoffset = ( width() - xAdvance + Segment_Length/5 )/2; // origininal
234
Xoffset = ( width() - xAdvance + Segment_Length/4 )/2;
235
Yoffset = ( height() - Segment_Length*2 )/2;
237
pos = QPoint( Xoffset , Yoffset );
242
// this draw the non-illumintated segments
244
if(show_off_colon){// we want to show the colon which is actually ugly and
245
// by default not shown.
247
for(int l = 0; l <= NUM_OF_SEGMENTS +1; l++){
248
drawSegment(pos,(char) l,*p,Segment_Length,TRUE); //erase segment
252
for(int l = 0; l <= NUM_OF_SEGMENTS -1; l++){
253
drawSegment(pos,(char) l,*p,Segment_Length,TRUE); //erase segment
257
// now draw the illuminated segments
259
for(int l = 0; l <= NUM_OF_SEGMENTS -1; l++){
260
if(current_segments[l] != STOP_CHAR){
261
drawSegment(pos,current_segments[l],*p,Segment_Length,FALSE); // draw segment
268
else{ // we are not repainting ourselves due to a repaint event but rather
269
// genuinely changing the symbol that is to be displayed
271
for(int l = 0; l <= NUM_OF_SEGMENTS -1; l++){
273
if(current_segments[l] != STOP_CHAR){
274
if(!seg_contained_in(current_segments[l],old_segments))
275
drawSegment(pos,current_segments[l],*p,Segment_Length,FALSE); // draw segment
283
for(int k = 0; k <= NUM_OF_SEGMENTS -1; k++){
285
if(old_segments[k] != STOP_CHAR){
286
if(!seg_contained_in(old_segments[k],current_segments))
287
drawSegment(pos,old_segments[k],*p,Segment_Length,TRUE); //erase segment
298
bool BW_LED_Number::seg_contained_in( char c, char* seg){
302
while ( *seg != STOP_CHAR){
303
// printf("Comparing %d with %d\n",c,*seg);
312
void BW_LED_Number::setLEDoffColor(QColor color){
318
void BW_LED_Number::drawSegment( const QPoint &pos, char seg_number, QPainter &p,
319
int Segment_Length, bool erase){
323
QColorGroup g = colorGroup();
324
QColor lightColor,darkColor;
327
lightColor = offcolor;
328
darkColor = offcolor;
331
lightColor = g.light();
332
darkColor = g.dark();
335
// int Width = (int) Segment_Length/5 ; // original
336
int Width = (int) Segment_Length/4;
339
QBrush brush(g.light());
343
pt.ry() += (QCOORD)Width/2;
348
p.setBrush(offcolor);
349
brush.setColor(offcolor);
353
p.setBrush(g.light());
357
switch ( seg_number ) {
364
pts.setPoints(3,pt.x(), pt.y() ,
365
pt.x(), pt.y()-Width +1,
366
pt.x() + Width-1, pt.y());
368
pts.setPoints(3,pt.x(), pt.y() + Segment_Length -Width - Width/2 -1 ,
369
pt.x() + Width -1 , pt.y() -Width +Segment_Length - Width/2 -1,
370
pt.x() , pt.y() + Segment_Length - 3*Width/4 -1);
376
p.fillRect(pt.x(),pt.y()+ Width/2 -1, Width ,
377
Segment_Length - Width -Width +1 ,brush);
382
p.fillRect(pt.x()+Width,pt.y()- Width , Segment_Length -2* Width, Width ,brush);
387
pts.setPoints(3,pt.x()+1, pt.y()-Width ,
388
pt.x()+Width, pt.y()-Width ,
389
pt.x() + Width, pt.y() -1 );
392
pts.setPoints(3,pt.x()+ Segment_Length - Width , pt.y() - Width,
393
pt.x()+ Segment_Length -1, pt.y() - Width,
394
pt.x() + Segment_Length - Width , pt.y() -1 );
401
pt.rx() += (QCOORD)(Segment_Length);
407
pts.setPoints(3,pt.x() , pt.y() ,
408
pt.x() , pt.y() - Width + 1, // changes from 1 to 2
409
pt.x() - Width +1, pt.y() );
413
pts.setPoints(3,pt.x() , pt.y() + Segment_Length - Width - Width/2 -1,
414
pt.x() , pt.y() + Segment_Length - 3*Width/4 - 1,
415
pt.x() - Width +1, pt.y() + Segment_Length - Width - Width/2 -1);
422
p.fillRect(pt.x() - Width+1 ,pt.y() + Width/2- 1, Width ,
423
Segment_Length - Width - Width + 1 ,brush);
428
pt.ry() += (QCOORD)Segment_Length;
430
p.setPen(g.background());
432
pts.setPoints(3,pt.x()-1 , pt.y() - Width/2 -1,
433
pt.x() + Width+2, pt.y()-Width -1 ,//
434
pt.x() + Width+2, pt.y() );
436
pts.setPoints(3,pt.x() + Segment_Length + 1, pt.y() - Width/2 -1 ,
437
pt.x() + Segment_Length - Width - 2 ,
439
pt.x() + Segment_Length - Width - 2, pt.y() );
443
p.fillRect(pt.x() + Width -1 ,pt.y() - Width, Segment_Length- 2* Width + 3,
448
pt.ry() += (QCOORD)(Segment_Length +1);
449
p.fillRect(pt.x(), pt.y(), Width , Segment_Length - Width - Width/2 ,brush);
453
pts.setPoints(3,pt.x(), pt.y(),
454
pt.x(), pt.y()-Width+1,
455
pt.x() + Width-1, pt.y());
457
pts.setPoints(3,pt.x(), pt.y() + Segment_Length -Width - Width/2 -1 ,
458
pt.x() + Width -1 , pt.y() -Width +Segment_Length - Width/2 -1 ,
459
pt.x() , pt.y() + Segment_Length - 3*Width/4 -1);
467
pt.rx() += (QCOORD)(Segment_Length );
468
pt.ry() += (QCOORD)(Segment_Length +1);
469
p.fillRect(pt.x() - Width +1 ,pt.y(), Width ,
470
Segment_Length - Width - Width/2 ,brush);
475
pts.setPoints(3,pt.x() , pt.y(),
476
pt.x() , pt.y() - Width +1,
477
pt.x() - Width +1, pt.y());
481
pts.setPoints(3,pt.x() , pt.y() + Segment_Length - Width - Width/2 -1,
482
pt.x() , pt.y() + Segment_Length - 3*Width/4 -1,
483
pt.x() - Width +1, pt.y() + Segment_Length - Width - Width/2 -1);
492
pt.ry() += (QCOORD)(Segment_Length*2 );
493
p.fillRect(pt.x() + Width ,pt.y() -Width , Segment_Length -2* Width ,
499
pts.setPoints(3,pt.x()+1, pt.y()-1,
500
pt.x() + Width, pt.y() - Width,
501
pt.x() + Width, pt.y() - 1 );
504
pts.setPoints(3, pt.x() + Segment_Length - 1, pt.y()-1,
505
pt.x() + Segment_Length - Width , pt.y() - Width,
506
pt.x() + Segment_Length - Width , pt.y() - 1 );
517
pt.rx() += (QCOORD)(Segment_Length/2);
518
pt.ry() += (QCOORD)(Segment_Length*2);
519
p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush);
522
pt.ry() += (QCOORD)(Segment_Length/2 + Width/2);
523
pt.rx() += (QCOORD)(Segment_Length/2 - Width/2 + 1);
525
if (!show_off_colon && erase) {
527
brush.setColor(bgcolor);
530
p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush);
533
if (!show_off_colon && erase) {
535
brush.setColor(fgcolor);
540
pt.ry() += (QCOORD)(3*Segment_Length/2 + Width/2);
541
pt.rx() += (QCOORD)(Segment_Length/2 - Width/2 + 1);
543
if (!show_off_colon && erase) {
545
brush.setColor(bgcolor);
547
p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush);
549
if (!show_off_colon && erase) {
551
brush.setColor(fgcolor);
556
} /* if (!smallLED) */
560
pt.ry() += (QCOORD)Width/2;
562
switch ( seg_number ) {
564
p.fillRect(pt.x(),pt.y()+ Width /2, Width , Segment_Length - Width -Width/2 ,brush);
567
p.fillRect(pt.x()+Width,pt.y()- Width , Segment_Length -2* Width, Width ,brush);
570
pt.rx() += (QCOORD)(Segment_Length);
571
p.fillRect(pt.x()-Width,pt.y()+ Width/2, Width ,
572
Segment_Length - Width -Width/2 ,brush);
575
pt.ry() += (QCOORD)Segment_Length;
576
p.fillRect(pt.x() + Width ,pt.y() - Width, Segment_Length- 2* Width, Width ,brush);
579
pt.ry() += (QCOORD)(Segment_Length );
580
p.fillRect(pt.x(), pt.y(), Width , Segment_Length - Width - Width/2 ,brush);
583
pt.rx() += (QCOORD)(Segment_Length );
584
pt.ry() += (QCOORD)(Segment_Length );
585
p.fillRect(pt.x() - Width ,pt.y(), Width ,
586
Segment_Length - Width - Width/2 ,brush);
589
pt.ry() += (QCOORD)(Segment_Length*2);
590
p.fillRect(pt.x() + Width ,pt.y() -Width , Segment_Length -2* Width ,
594
pt.rx() += (QCOORD)(Segment_Length/2);
595
pt.ry() += (QCOORD)(Segment_Length*2);
596
p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush);
599
pt.ry() += (QCOORD)(Segment_Length/2 + Width/2);
600
pt.rx() += (QCOORD)(Segment_Length/2 - Width/2 + 1);
601
if (!show_off_colon && erase) {
603
brush.setColor(bgcolor);
606
p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush);
608
if (!show_off_colon && erase) {
610
brush.setColor(fgcolor);
615
pt.ry() += (QCOORD)(3*Segment_Length/2 + Width/2);
616
pt.rx() += (QCOORD)(Segment_Length/2 - Width/2 + 1);
618
if (!show_off_colon && erase) {
620
brush.setColor(bgcolor);
622
p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush);
623
if (!show_off_colon && erase) {
625
brush.setColor(fgcolor);