/* ============================================================
 * File  : mydialy.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 "mydialy.h"
#include "math.h"

mydialy::mydialy ( QWidget * parent )
    : QDial(parent)
{
	//myparent = parent;
	//this->setAcceptDrops(true);
}

void mydialy::paintEvent(QPaintEvent *)
{
	QPainter p;
	p.begin(this);
	p.setRenderHint(QPainter::Antialiasing,true);

	if ( this->statusTip() == "A" )
	{
		p.setPen(Qt::NoPen);

		p.setBrush(QColor(255,255,255,200));
		p.drawEllipse(0, 0, 60, 60);

		QLinearGradient Gradient2(60.0, 60.0,0.0,0.0);
		Gradient2.setColorAt(0.0, QColor(69,63,55,180));
		Gradient2.setColorAt(1.0, QColor(29,23,15,200));

		p.setBrush(Gradient2);
		p.drawEllipse(3, 3, 54, 54);

		QRadialGradient Gradient3(0, 0, 60);
		Gradient3.setColorAt(0.0, QColor(169,163,155));
		Gradient3.setColorAt(1.0, QColor(199,193,185));

		p.setPen (QColor(255,255,255,255));
		p.drawText(0, 20, 60, 20, Qt::AlignHCenter | Qt::AlignVCenter,  QString::number(this->value()));
		p.setBrush(Gradient3);
		p.translate(30.0,30.0);
		if ( this->minimum() <= 0 )
		{
			longueur = this->maximum() + (this->minimum()*-1);
		}
		else
		{
			longueur = this->maximum() + this->minimum();
		}
		p.rotate(((this->value()) * 280)/longueur);
		p.setPen (QColor(0,0,0,255));
		if ( this->minimum() >= 0 )
		{
	    		p.drawEllipse(-18,10, 10, 10);
		}
		else
		{
	    		p.drawEllipse(-5,-24, 10, 10);
		}
	}
	else
	{
		p.setPen(Qt::NoPen);
		QLinearGradient Gradient1(60.0, 60.0,0.0,0.0);
		Gradient1.setColorAt(0.0, QColor(10,10,10,255));
		Gradient1.setColorAt(1.0, QColor(80,80,80,255));

		p.setBrush(Gradient1);
		p.drawEllipse(0, 0, 60, 60);

		QLinearGradient Gradient2(60.0, 60.0,0.0,0.0);
		Gradient2.setColorAt(0.0, QColor(80,80,80,255));
		Gradient2.setColorAt(1.0, QColor(10,10,10,255));

		p.setBrush(Gradient2);
		p.drawEllipse(3, 3, 54, 54);

		QRadialGradient Gradient3(0, 0, 60);
		Gradient3.setColorAt(0.0, QColor(205,224,228));
		Gradient3.setColorAt(1.0, QColor(191,211,211));

		p.setPen (QColor(255,255,255,255));
		p.drawText(0, 20, 60, 20, Qt::AlignHCenter | Qt::AlignVCenter,  QString::number(this->value()));
		p.setBrush(Gradient3);
		p.translate(30.0,30.0);
		if ( this->minimum() <= 0 )
		{
			longueur = this->maximum() + (this->minimum()*-1);
		}
		else
		{
			longueur = this->maximum() + this->minimum();
		}
		p.rotate(((this->value()) * 280)/longueur);
		p.setPen (QColor(0,0,0,255));
		if ( this->minimum() >= 0 )
		{
	    		p.drawEllipse(-18,10, 10, 10);
		}
		else
		{
	    		p.drawEllipse(-5,-24, 10, 10);
		}
	}

 	p.end();
}

