summaryrefslogtreecommitdiffstats
path: root/PerlQt/tutorials/t11/LCDRange.pm
blob: be0f8ec366ea09b95b4531f94254fa89c13ec138 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package LCDRange;
use strict;
use Qt;
use Qt::isa qw(Qt::VBox);
use Qt::slots 
	setValue => ['int'],
	setRange => ['int', 'int'];
use Qt::signals
	valueChanged => ['int'];
use Qt::attributes qw(
	slider
);

sub NEW {
    shift->SUPER::NEW(@_);

    my $lcd = Qt::LCDNumber(2, this, "lcd");

    slider = Qt::Slider(&Horizontal, this, "slider");
    slider->setRange(0, 99);
    slider->setValue(0);
    $lcd->connect(slider, SIGNAL('valueChanged(int)'), SLOT('display(int)'));
    this->connect(slider, SIGNAL('valueChanged(int)'), SIGNAL('valueChanged(int)'));

    setFocusProxy(slider);
}

sub value { slider->value }

sub setValue { slider->setValue(shift) }

sub setRange {
    my($minVal, $maxVal) = @_;
    if($minVal < 0 || $maxVal > 99 || $minVal > $maxVal) {
	warn "LCDRange::setRange($minVal,$maxVal)\n" .
	     "\tRange must be 0..99\n" .
	     "\tand minVal must not be greater than maxVal\n";
	return;
    }
    slider->setRange($minVal, $maxVal);
}

1;