/* ============================================================
 * File  : toolbar_bt2.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 "toolbar_bt2.h"

toolbar_bt2::toolbar_bt2 ( QWidget * parent )
    : QPushButton(parent)
{
	this->setAttribute(Qt::WA_DeleteOnClose);
	isover = 0;
	myfont.setFamily("DejaVu Sans Condensed");
	myfont.setPixelSize ( 10 );
}

void toolbar_bt2::enterEvent ( QEvent * ) 
{
	isover = 1;
}

void toolbar_bt2::leaveEvent ( QEvent * ) 
{
	isover = 0;
}

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

void toolbar_bt2::paintEvent(QPaintEvent *)
{
	QPainter p;
	p.begin(this);
	if ( this->isChecked() == true )
	{
		p.drawPixmap(0,0,QPixmap(":/Interface/Interface/" + this->text().mid(2,this->text().length()-2) + "2.png"));
	}
	else
	{
		if ( isover == 1 )
		{
			p.drawPixmap(0,0,QPixmap(":/Interface/Interface/" + this->text().mid(2,this->text().length()-2) + "1.png"));
		}
		else
		{
			p.drawPixmap(0,0,QPixmap(":/Interface/Interface/" + this->text().mid(2,this->text().length()-2) + ".png"));
		}
	}
	if ( this->statusTip() != "" )
	{
		if ( this->isEnabled() == true )
		{
			if ( isover == 1 )
			{
				p.setPen(QColor(50,50,50));
			}
			else
			{
				p.setPen(QColor(10,10,10));
			}
		}
		else
		{
			p.setPen(QColor(100,100,100));
		}

		p.setFont(myfont);
		p.drawText(QRect(32,0,this->width()-34,this->height()), Qt::AlignVCenter, this->statusTip());
	}
	p.end();
}

