2
Written 1998-1999 by Uwe Langenkamp
4
This software may be used and distributed according to the terms
5
of the GNU Public License, incorporated herein by reference.
7
The author may be reached as ul@it-guru.de
11
* 99/10/28 Last Change
12
* 99/10/28 Shaded Background color added
13
* 99/10/26 Changes will only be made to free qtai!!!
37
#include "qtai_meter.h"
41
AIMeter::AIMeter(QWidget *parent,const char *name,int n)
42
: AIBar(parent,name,n)
47
color[i].setRgb( 0, 164, 0 );
50
setType(AI_METER_LEVEL);
53
void AIMeter::drawGrid( QPainter *p )
55
int w=width()*FACTOR,h=height()*FACTOR;
59
QFont font("Helvetica",10);
60
QFontMetrics fm(font);
66
p->setWindow(0,0,w,h); // defines coordinate system
68
azero=(0-min)*(amax-amin)/(max-min)+amin;
69
zmatrix.translate( zx, zy ); // move to center
70
zmatrix.rotate(270+azero);
71
p->setWorldMatrix( zmatrix ); // use this world matrix
73
str.sprintf("%.2f",0.0);
74
p->drawText(-fm.width(str)/2,-rs-10,str);
76
matrix.translate( zx, zy ); // move to center
77
matrix.rotate(270+amin);
79
for (i=0;i<=scale_tile;i++) {
81
p->setWorldMatrix( matrix ); // use this world matrix
82
p->drawLine(0,-r,0,-rs);
84
if (i==0 || i==scale_tile) {
85
str.sprintf("%.2f",i*(max-min)/scale_tile+min);
86
p->drawText(-fm.width(str)/2,-rs-10,str);
89
matrix.rotate((amax-amin)/scale_tile);
93
void AIMeter::drawIt( QPainter *p )
96
QWMatrix matrix,pmatrix;
98
int h=height()*FACTOR;
99
QFont font("Helvetica",10);
100
QFontMetrics fm(font);
110
QPainter tmp; // for double buffering
111
QPixmap pix(width(),height());
115
tmp.setWindow(0,0,w,h); // defines coordinate system
118
static int bw=-1,bh=-1; // BG Buffer
119
static QPixmap *bg_buf=NULL;
125
if (bh!=h || bw!=w || bg_buf==NULL) {
127
bg_buf=new QPixmap(w,h);
129
bg_p.begin( bg_buf ); // begin painting
131
float step=100.0/(double)h;
134
// Must be buffered !!!
136
c.setRgb(64,64,(int)colval);
139
bg_p.drawLine(0,n,w,n);
142
bg_p.end(); // painting done
146
tmp.drawPixmap(qp,*bg_buf);
148
// 1999-05-23 UL, disabled, enabled
149
tmp.fillRect(0,0,w,h,c_bg);
151
//tmp.fillRect(0,0,w,h,c_bg);
157
pmatrix.translate(0,0); // move to center
158
tmp.setWorldMatrix( pmatrix ); // use this world matrix
163
tmp.drawText(w-(fm.width(range_s)+10),fm.height(),range_s);
165
for (i=0;i<nbars;i++) {
166
tmp.setWorldMatrix( pmatrix ); // use this world matrix
168
tmp.setPen(color[i]);
169
str.sprintf("%.2f",actual[i]);
170
tmp.drawText(10,(i+1)*fm.height(),str);
172
aact=(actual[i]-min)*(amax-amin)/(max-min)+amin;
173
matrix.translate( zx, zy ); // move to center
174
matrix.rotate(270+aact);
175
tmp.setWorldMatrix( matrix ); // use this world matrix
178
tmp.drawLine(-2,0,0,-r);
179
//tmp.drawLine(0,0,0,-r);
180
tmp.drawLine(2,0,0,-r);
183
p->drawPixmap(qp,pix);
188
void AIMeter::setType(int type)
195
fzx=0.5f,fzy=1.3f,fr=0.8f;
201
fzx=0.5f,fzy=0.5f,fr=0.3f;
205
#include "qtai_meter.moc"