/* ============================================================
 * File  : tetrahedron.cpp
 * Author: Stephane Gibault
 * Date  : Sun Feb 4 2007
 * Description :
 *
 * 
 *  (C) 2007 by Stephane Gibault
 *
 * 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, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * ============================================================ */
#include <QtGui>
#include "bt_design.h"

bt_design::bt_design ( QWidget * parent )
    : QPushButton(parent)
{
	this->setAttribute(Qt::WA_DeleteOnClose);
	myfont.setFamily("Nimbus Sans L");
	myfont.setPixelSize ( 12 );
	isover = 0;
}

void bt_design::enterEvent ( QEvent * ) 
{
	isover = 1;
	this->repaint();
}

void bt_design::leaveEvent ( QEvent * ) 
{
	isover = 0;
	this->repaint();
}

// ********************************
// *** DESSIN DU FOND DU WIDGET ***
// ********************************

void bt_design::paintEvent(QPaintEvent *)
{
	QPainter p;
	p.begin(this);
	p.setPen(Qt::NoPen);
	p.setRenderHint(QPainter::Antialiasing,true);

	if ( this->isEnabled() == true )
	{
		if ( this->isChecked() == false )
		{
			p.setPen(QColor(150,150,150,200));
			p.setRenderHint(QPainter::Antialiasing,true);
			if ( isover == 0 )
			{
				p.setBrush(QColor(255,255,255,100));

			}
			else
			{
				p.setBrush(QColor(255,255,255,200));
			}
			p.drawRoundedRect(1, 1, this->width()-2, this->height()-2,7,7,Qt::AbsoluteSize);
			QLinearGradient Gradient1(0.0,0.0,0.0,this->height());
			Gradient1.setColorAt(1.0, QColor(151,144,134,200));
			Gradient1.setColorAt(0.0, QColor(183,178,168,200));

			p.setBrush(Gradient1);
			p.drawRoundedRect(4, 4, this->width()-8, this->height()-8,5,5,Qt::AbsoluteSize);
			p.setFont(myfont);
			p.setPen(QColor(0,0,0));
		}
		else
		{
			p.setPen(QColor(150,150,150,200));
			p.setRenderHint(QPainter::Antialiasing,true);
			if ( isover == 0 )
			{
				p.setBrush(QColor(91,171,204,180));

			}
			else
			{
				p.setBrush(QColor(91,171,204,220));
			}
			p.drawRoundedRect(1, 1, this->width()-2, this->height()-2,7,7,Qt::AbsoluteSize);
			QLinearGradient Gradient1(0.0,0.0,0.0,this->height());
			Gradient1.setColorAt(1.0, QColor(151,144,134,200));
			Gradient1.setColorAt(0.0, QColor(183,178,168,200));

			p.setBrush(Gradient1);
			p.drawRoundedRect(4, 4, this->width()-8, this->height()-8,5,5,Qt::AbsoluteSize);
			p.setFont(myfont);
			p.setPen(QColor(0,0,0));
		}
	}
	else
	{
		p.setPen(QColor(150,150,150,200));
		p.setRenderHint(QPainter::Antialiasing,true);
		p.setBrush(QColor(255,255,255,100));
		p.drawRoundedRect(1, 1, this->width()-2, this->height()-2,7,7,Qt::AbsoluteSize);
		QLinearGradient Gradient1(0.0,0.0,0.0,this->height());
		Gradient1.setColorAt(1.0, QColor(151,144,134,200));
		Gradient1.setColorAt(0.0, QColor(183,178,168,200));

		p.setBrush(Gradient1);
		p.drawRoundedRect(4, 4, this->width()-8, this->height()-8,5,5,Qt::AbsoluteSize);
		p.setFont(myfont);
		p.setPen(QColor(0,0,0,100));
	}

	if ( this->iconSize().width() > 0 )
	{
		p.drawText(QRect(40,0,(this->width()-40),this->height()+1), Qt::AlignVCenter | Qt::AlignLeft,this->text());
		p.drawPixmap(6,(this->height()-24)/2,this->icon().pixmap(24,24,QIcon::Normal,QIcon::On));
	}
	else
	{
		p.drawText(QRect(0,0,this->width(),this->height()+1), Qt::AlignCenter,this->text());
	}

	p.end();
}

