#include "progressbarpreview.h"

ApollonProgressBarPreview::ApollonProgressBarPreview(QWidget* parent)
  : QWidget(parent)
{
}

void ApollonProgressBarPreview::paintEvent(QPaintEvent*)
{
	QPainter p(this);
	QColorGroup cg = colorGroup();
	int fillwidth;
	int m_progress = 75;
	p.setPen(cg.foreground());
	p.drawRect(1, 1, width() - 2, height() - 2);
	p.setPen(QColor(255, 255, 255));
	p.drawRect(0, 0, width(), height());
	p.drawRect(2, 2, width() - 4, height() - 4);
	if(m_lastWidth != width())
	{
		m_lastWidth = width();
		m_gradient.resize(width(), height());
		QColor color = cg.highlight();
		KPixmapEffect::gradient((KPixmap &) m_gradient, color, color.light(), KPixmapEffect::EllipticGradient);
	}
	/*if(parent() == 0)
	{
		if(m_progress == -1)
			fillwidth = width - 6;
		else
			fillwidth = (int) (m_progress / 100.0 * (width - 6));
		bitBlt(p->device(), (int) p->worldMatrix().dx() + 3, (int) p->worldMatrix().dy() + 3, &m_gradient, 0, 0, fillwidth, height() - 6, Qt::CopyROP, false);
		p->fillRect(3 + fillwidth, 3, width - fillwidth - 6, height() - 6, QColor(255, 255, 255));
		p->setPen(cg.foreground());
		if(m_progress != -1)
			p->drawText(0, 0, width, height(), Qt::AlignCenter, QString::number((int) m_progress) + "%");
		else
			p->drawText(0, 0, width, height(), Qt::AlignCenter, m_status);
	}
	else
	{*/
		fillwidth = (int) (m_progress / 100.0 * (width() - 6));
		bitBlt(p.device(), (int) p.worldMatrix().dx() + 3, (int) p.worldMatrix().dy() + 3, &m_gradient, 0, 0, fillwidth, height() - 6, Qt::CopyROP, false);
		p.fillRect(3 + fillwidth, 3, width() - fillwidth - 6, height() - 6, QColor(255, 255, 255));
		p.setPen(cg.foreground());
		p.drawText(0, 0, width(), height(), Qt::AlignCenter, QString::number((int) m_progress) + "%");
	/*}
	listView()->repaint();*/
} 
