/***************************************************************************
 *   Copyright (C) 2006 by Matej Svejda   *
 *   mata@aw-modell.at   *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   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.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <QWidget>
#include <QPainter>
#include <QKeyEvent>
#include <QPaintEvent>

#include "bubbleplayground.h"

BubblePlayground::BubblePlayground(QWidget *parent)
	: QWidget(parent)
{
	speed = 0;
	maxSpeed = 100;
	accelerationSpeed = 1;
	slowDownSpeed = 10;
	
	setBackgroundRole(QPalette::Base);
	setAutoFillBackground(true);
	setFixedSize(500, 500);
}

void BubblePlayground::keyPressEvent(QKeyEvent *keyEvent)
{
	if(keyEvent->key() == Qt::Key_Up) {
		accelerate();
	} else if(keyEvent->key() == Qt::Key_Down) {
		slowDown();
	} else if(keyEvent->key() == Qt::Key_Left) {
		turnLeft();
	} else if(keyEvent->key() == Qt::Key_Right) {
		turnRight();
	}
}


void BubblePlayground::accelerate()
{
	if(speed <= maxSpeed - accelerationSpeed) {
		speed += accelerationSpeed;
	}
}

void BubblePlayground::slowDown()
{
	if(0 <= speed - accelerationSpeed) {
		speed -= slowDownSpeed;
	}
}

void BubblePlayground::turnLeft()
{
	/* turn left */
}

void BubblePlayground::turnRight()
{
	/* turn right */
}

void BubblePlayground::paintEvent(QPaintEvent *event)
{
	QPainter painter(this);
	painter.setRenderHint(QPainter::Antialiasing);
	painter.setPen(Qt::NoPen);
	painter.setBrush(Qt::blue);
	painter.drawEllipse(QRect(10, 10, 200, 200));
}

