#include "PlotTurns.h"
#include <QPainter>

PlotTurns::PlotTurns(QWidget *parent) : QWidget(parent) {

	setMinimumWidth(96);
	setMinimumHeight(96);

	//setSizeIncrement(QSize(1,1));
	//setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding));
// resize(96, 96);

//	setMaximumWidth(64);
//	setMaximumHeight(64);

}

void PlotTurns::add(const Timestamp ts, const TurnData& data) {
	(void) ts;
	this->data = data;
	static int i = 0;
	if (++i % 4 == 0) {
		QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection);
	}
}

void PlotTurns::paintEvent(QPaintEvent* evt) {

	(void) evt;
	QPainter p(this);

	const float s = std::min(width(), height());
	const float s1 = s / 1.9;

	const float cx = width() / 2;
	const float cy = height() / 2;

	const float x1 = cx + std::cos(data.radSinceStart-M_PI_2) * s1;
	const float y1 = cy + std::sin(data.radSinceStart-M_PI_2) * s1;

	p.fillRect(0,0,width(),height(),QColor(255,255,255,192));
	p.setPen(Qt::black);
	p.drawRect(0,0,width()-1,height()-1);

	const QPen pen(Qt::black, 2);
	p.setPen(pen);
	p.drawLine(cx, cy, x1, y1);

	p.end();

}
