view widgets/ConfidenceWidget.cpp @ 282:d9319859a4cf tip

(none)
author benoitrigolleau
date Fri, 31 Oct 2008 11:00:24 +0000
parents c107866fd387
children
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

/*   
	Sound Access
		EASAIER client application.
		Silogic 2007. Benoit Rigolleau.

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License as
	published by the Free Software Foundation; either version 2 of the
	License, or (at your option) any later version.  See the file
	COPYING included with this distribution for more information.
*/

#include "ConfidenceWidget.h"
#include <QPainter>
#include <QString>

ConfidenceWidget::ConfidenceWidget(QWidget *parent, int confidence):QWidget(parent){
	setConfidence(confidence);
}

void ConfidenceWidget::setConfidence(int confidence){
	m_confidence=confidence;
}
int ConfidenceWidget::confidence(){
	return m_confidence;
}

void ConfidenceWidget::paintEvent(QPaintEvent *event){
	QPainter painter(this);
	painter.setRenderHint(QPainter::Antialiasing, false);
	draw(&painter);

}

void ConfidenceWidget::draw(QPainter *painter){
	int marging = 2;
	int confidenceHeight = 12;
	int labelHeight = confidenceHeight/3;

	QColor niceGreen(QRgb(0xffdbf756));
	QLinearGradient rectRadian(0,0,0,confidenceHeight);
	rectRadian.setColorAt(0.0,Qt::black);
	rectRadian.setColorAt(0.2,niceGreen);
	rectRadian.setColorAt(0.5,Qt::lightGray);
	rectRadian.setColorAt(0.8,Qt::white);
	rectRadian.setColorAt(1.0,Qt::black);
	//painter->setBrush(rectRadian);
	
	painter->translate(0,height()/2-confidenceHeight/2-labelHeight/2+4);

	// the green rectangle
	painter->setPen(QPen(palette().foreground(),1,Qt::NoPen,Qt::RoundCap));
	//painter->setBrush(QBrush(palette().highlight().color(),Qt::SolidPattern));
	painter->setBrush(rectRadian);
	painter->drawRect(marging,0,(width()-2*marging)*(m_confidence/100.0),confidenceHeight);

	//the empty rectangle
	QPen(palette().foreground(),1,Qt::SolidLine,Qt::RoundCap);
	painter->setPen(QPen(palette().foreground(),1,Qt::SolidLine,Qt::RoundCap));
	painter->setBrush(QBrush(palette().highlight().color(),Qt::NoBrush));
	painter->drawRect(marging,0,width()-2*marging,confidenceHeight);
	
	//the text
	QString text_integer;
	text_integer = text_integer.setNum(m_confidence); 
	painter->drawText(marging,-1,QString(text_integer+"%"));

	painter->setPen(QPen(palette().foreground(),1,Qt::SolidLine,Qt::RoundCap));
	int step = (width()-2*marging)/4;
	for(int i=1;i<4;i++){
		painter->drawLine(marging+i*step,confidenceHeight,marging+i*step,confidenceHeight+labelHeight);
	}
}