summaryrefslogtreecommitdiffstats
path: root/PerlQt/tutorials/t12/LCDRange.pm
blob: d3a5166a07c8260c903f8fab95d8c0c47e760269 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package LCDRange;
use strict;
use TQt;
use TQt::isa qw(TQt::VBox);
use TQt::slots 
	setValue => ['int'],
	setRange => ['int', 'int'],
	setText => ['const char*'];
use TQt::signals
	valueChanged => ['int'];
use TQt::attributes qw(
	slider
	label
);

sub NEW {
    my $class = shift;
    my $s;
    $s = shift if $_[0] and not ref $_[0];
    $class->SUPER::NEW(@_);

    init();
    setText($s) if $s;
}


sub init {
    my $lcd = TQt::LCDNumber(2, this, "lcd");

    slider = TQt::Slider(&Horizontal, this, "slider");
    slider->setRange(0, 99);
    slider->setValue(0);

    label = TQt::Label(" ", this, "label");
    label->setAlignment(&AlignCenter);

    $lcd->connect(slider, TQT_SIGNAL('valueChanged(int)'), TQT_SLOT('display(int)'));
    this->connect(slider, TQT_SIGNAL('valueChanged(int)'), TQT_SIGNAL('valueChanged(int)'));

    setFocusProxy(slider);
}

sub value { slider->value }

sub text { label->text }

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);
}

sub setText { label->setText(shift) }

1;