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

use Qt;
use QLCDNumber;
use QScrollBar;

@ISA = qw(QWidget);

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

    my $lcd = new QLCDNumber(2, $self, 'lcd');
    $lcd->move(0, 0);
    my $sBar =
	new QScrollBar(0, 99,				# range
		       1, 10,				# line/page steps
		       0,				# initial value
		       $Orientation{Horizontal},	# orientation
		       $self, 'scrollbar');
    $lcd->connect($sBar, 'valueChanged(int)', 'display(int)');

    @$self{'sBar', 'lcd'} = ($sBar, $lcd);
    return $self;
}

sub resizeEvent {
    my $self = shift;
    my($sBar, $lcd) = @$self{'sBar', 'lcd'};

    $sBar->setGeometry(0, $self->height() - 16, $self->width(), 16);
    $lcd->resize($self->width(), $sBar->y() - 5);
}

package MyWidget;

use Qt;
use QFont;
use QPushButton;

@ISA = qw(QWidget);

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

    $self->setMinimumSize(200, 300);

    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()');

    for(0..15) { $$value[$_] = new LCDRange($self) }

    @$self{'quit', 'value'} = ($quit, $value);
    return $self;
}

sub resizeEvent {
    my $self = shift;
    my($quit, $value) = @$self{'quit', 'value'};
    my $startx      = 10;
    my $starty      = $quit->y() + $quit->height() + 10;
    my $valueWidth  = ($self->width()  - $startx - 10 - 3*5)/4;
    my $valueHeight = ($self->height() - $starty - 10 - 3*5)/4;
    for(0..15) {
	$$value[$_]->setGeometry($startx + ($_%4)*(5+$valueWidth),
				 $starty + int($_/4)*(5+$valueHeight),
				 $valueWidth, $valueHeight);
    }
}

package main;

use Qt;

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