1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include "drmsegmentsview.h"
#include <QPainter>
#include <QDebug>
#include <QPaintEvent>
#include <math.h>
drmSegmentsView::drmSegmentsView(QWidget *parent) :QLabel(parent)
{
maxBlocks=1;
colFail=QColor(Qt::red);
colOK=QColor(Qt::green);
setFrameShape(QFrame::Box);
setFrameShadow(QFrame::Sunken);
setLineWidth(3);
setScaledContents(true);
blockListCount=-1;
}
drmSegmentsView::~drmSegmentsView()
{
}
void drmSegmentsView::paintEvent(QPaintEvent *e)
{
int i;
int blockX;
float blockWidth;
QRectF rct;
QLabel::paintEvent(e);
// if(blockListCount==blockList.count())
// {
// return;
// }
// blockListCount=blockList.count();
QPainter painter(this);
painter.setPen(QPen(colFail, 1, Qt::SolidLine));
painter.setBrush(QBrush(colFail));
painter.setRenderHint(QPainter::Antialiasing);
rct=QRectF(contentsRect().left(),contentsRect().top() ,contentsRect().width()-4 ,contentsRect().height()-4 );
blockWidth=(float)(contentsRect().width()-4)/maxBlocks;
painter.drawRect(rct);
painter.setBrush(QBrush(colOK));
painter.setPen(QPen(colOK, 1, Qt::SolidLine));
for(i=0;i<blockList.count();i++)
{
blockX=floor(blockList.at(i)*blockWidth)+contentsRect().left()+2;
painter.drawRect(blockX,contentsRect().top(),ceil(blockWidth),contentsRect().height()-4);
}
}
void drmSegmentsView::setColorFail(QColor color)
{
colFail = color;
}
void drmSegmentsView::setColorOK(QColor color)
{
colOK = color;
}
void drmSegmentsView::setBlocks(QList<unsigned short> blkList)
{
blockList=blkList;
}
|