| 1 | #include <QColor>
|
|---|
| 2 |
|
|---|
| 3 | #include <QVBoxLayout>
|
|---|
| 4 | #include <QPainter>
|
|---|
| 5 | #include "tpixel.h"
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | Tpixel::Tpixel( QWidget *parent ) : QWidget( parent)
|
|---|
| 9 | {
|
|---|
| 10 | //setPalette( QPalette( QColor( 250, 250, 200) ) );
|
|---|
| 11 | //this->setPalette( QPalette( QColor( 250, 250, 200) ) );
|
|---|
| 12 | bgColor= new QColor(200,200,200);
|
|---|
| 13 | this->setAutoFillBackground (1);
|
|---|
| 14 | MaxVal=255;
|
|---|
| 15 | }
|
|---|
| 16 | int Tpixel::value()
|
|---|
| 17 | {
|
|---|
| 18 | return val;
|
|---|
| 19 |
|
|---|
| 20 | }
|
|---|
| 21 | void Tpixel::paintEvent( QPaintEvent * )
|
|---|
| 22 | {
|
|---|
| 23 | QString s = QString( "%1" ).arg((double)(val));
|
|---|
| 24 | if(val==0)
|
|---|
| 25 | s= QString("n/c");
|
|---|
| 26 | QFont sansFont( "Helvetica [Cronyx]", 12 );
|
|---|
| 27 |
|
|---|
| 28 | QPainter p( this );
|
|---|
| 29 | p.setFont(sansFont);
|
|---|
| 30 | p.setPen(Qt::white);
|
|---|
| 31 | int width=this->width();
|
|---|
| 32 | int height=this->height();
|
|---|
| 33 | p.drawText(width/3 , height/2, s );
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | void Tpixel::setValue( int vall )
|
|---|
| 37 | {
|
|---|
| 38 | val=vall;
|
|---|
| 39 |
|
|---|
| 40 | bgColor->setRgb((int)(((float)(val)/(float)(MaxVal))*255.),0,0);
|
|---|
| 41 | if(val>=MaxVal)
|
|---|
| 42 | bgColor->setRgb(0,255,255);
|
|---|
| 43 | //printf("%f\n",(((float)(val)/(float)(MaxVal))));
|
|---|
| 44 | //QPalette::ColorRole
|
|---|
| 45 | QPalette *mypalette=new QPalette();
|
|---|
| 46 | // mypalette->setColor ( mypalette->Base, *bgColor );
|
|---|
| 47 | mypalette->setColor ( mypalette->Base, Qt::red);
|
|---|
| 48 | //this->setBackgroundRole (mypalette->Shadow);
|
|---|
| 49 | //this->setBackgroundColor(*bgColor);
|
|---|
| 50 | repaint();
|
|---|
| 51 | this->setPalette( QPalette( *bgColor ) );
|
|---|
| 52 | emit valueChanged(val);
|
|---|
| 53 |
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|