#!/usr/bin/perl -w
package MyWidget;

use Qt;
use QFont;
use QPushButton;

use CannonField;
use LCDRange;

@ISA = qw(QWidget);

sub new {
    my $self = shift->SUPER::new(@_);

    $self->setMinimumSize(500, 355);

    my $quit = new QPushButton('Quit', $self, 'quit');
    $quit->setGeometry(10, 10, 75, 30);
    $quit->setFont(new QFont('Times', 18, $Weight{Bold}));
    $qApp->connect($quit, 'clicked()', 'quit()');

    my $angle = new LCDRange($self, 'angle');
    $angle->setRange(5, 70);
    $angle->setGeometry(10, $quit->y() + $quit->height() + 10, 75, 130);

    my $force = new LCDRange($self, 'force');
    $force->setRange(10, 50);
    $force->setGeometry(10, $angle->y() + $angle->height() + 10, 75, 130);

    my $cannonField = new CannonField($self, 'cannonField');
    $cannonField->move($angle->x() + $angle->width() + 10, $angle->y());
    $cannonField->setBackgroundColor(new QColor(250, 250, 200));

    $cannonField->connect($angle, 'valueChanged(int)', 'setAngle(int)');
    $angle->connect($cannonField, 'angleChanged(int)', 'setValue(int)');

    $cannonField->connect($force, 'valueChanged(int)', 'setForce(int)');
    $force->connect($cannonField, 'forceChanged(int)', 'setValue(int)');

    $angle->setValue(60);
    $force->setValue(25);

    @$self{'quit', 'angle', 'force', 'cannonField'} =
	($quit, $angle, $force, $cannonField);
    return $self;
}

sub resizeEvent {
    my $self = shift;
    my $cannonField = $$self{'cannonField'};

    $cannonField->resize($self->width()  - $cannonField->x() - 10,
			 $self->height() - $cannonField->y() - 10);
}

package main;

use Qt;

$w = new MyWidget;
$w->setGeometry(100, 100, 500, 355);
$qApp->setMainWidget($w);
$w->show();
exit $qApp->exec();
