/***************************************************************************
 * radiustuner.cpp: implementation of RadiusTuner class
 *
 * This file is part of KTabEdit, a KDE tabulature editor
 *
 * copyright (C) 2003-2006 the KTabEdit development team <mrgwen@gmail.com>
 * copyright (C) 2002-2003 the KGuitar development team <mrgwen@gmail.com>
 ***************************************************************************/

/***************************************************************************
 * 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 for more information.
 ***************************************************************************/

#include "radiustuner.h"

#include <QPainter>
#include <QPaintEvent>

#include "notespinbox.h"


RadiusTuner::RadiusTuner(QWidget* parent)
: QWidget(parent)
{
	val = new NoteSpinBox(this);
	connect(val, SIGNAL(valueChanged(int)), SLOT(update()));
	connect(val, SIGNAL(valueChanged(int)), SLOT(emitValueChanged()));
}

void RadiusTuner::resizeEvent(QResizeEvent *)
{
	val->setGeometry(0, height() - 20, width(), 20);
}

void RadiusTuner::emitValueChanged()
{
	emit valueChanged(val->value());
}

void RadiusTuner::paintEvent(QPaintEvent *)
{
	QPainter paint(this);

	int maxd = qMin(width(), height()-20);
	int v = val->value()-12;
	if (v < 0)  v = 0;
	if (v > 103)  v = 103;
	int d = (103 - v) * maxd / 103;

	paint.setBrush(Qt::SolidPattern);
	paint.drawEllipse((width() - d) / 2, (height() - 20 - d) / 2, d, d);
}

void RadiusTuner::setValue(uchar x)
{
	val->setValue(x);
}

uchar RadiusTuner::value()
{
	return val->value();
}

#include "radiustuner.moc"
