You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.2 KiB
60 lines
1.2 KiB
13 years ago
|
#!/usr/bin/perl -w
|
||
|
use strict;
|
||
|
package Forever;
|
||
13 years ago
|
use TQt;
|
||
|
use TQt::isa qw(TQt::Widget);
|
||
|
use TQt::slots
|
||
13 years ago
|
updateCaption => [];
|
||
13 years ago
|
use TQt::attributes qw(
|
||
13 years ago
|
rectangles
|
||
|
colors
|
||
|
);
|
||
|
use constant numColors => 120;
|
||
|
|
||
|
sub NEW {
|
||
|
shift->SUPER::NEW(@_);
|
||
|
colors = \my @colors;
|
||
|
for(my $a = 0; $a < numColors; $a++) {
|
||
13 years ago
|
push @colors, TQt::Color(rand(255), rand(255), rand(255));
|
||
13 years ago
|
}
|
||
|
rectangles = 0;
|
||
|
startTimer(0);
|
||
13 years ago
|
my $counter = TQt::Timer(this);
|
||
|
this->connect($counter, TQT_SIGNAL('timeout()'), TQT_SLOT('updateCaption()'));
|
||
13 years ago
|
$counter->start(1000);
|
||
|
}
|
||
|
|
||
|
sub updateCaption {
|
||
13 years ago
|
my $s = sprintf "PerlTQt Example - Forever - %d rectangles/second", rectangles;
|
||
13 years ago
|
rectangles = 0;
|
||
|
setCaption($s);
|
||
|
}
|
||
|
|
||
|
sub paintEvent {
|
||
13 years ago
|
my $paint = TQt::Painter(this);
|
||
13 years ago
|
my $w = width();
|
||
|
my $h = height();
|
||
|
return if $w <= 0 || $h <= 0;
|
||
|
$paint->setPen(&NoPen);
|
||
|
$paint->setBrush(colors->[rand(numColors)]);
|
||
|
$paint->drawRect(rand($w), rand($h), rand($w), rand($h));
|
||
|
}
|
||
|
|
||
|
sub timerEvent {
|
||
|
for(my $i = 0; $i < 100; $i++) {
|
||
|
repaint(0);
|
||
|
rectangles++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
package main;
|
||
13 years ago
|
use TQt;
|
||
13 years ago
|
use Forever;
|
||
|
|
||
13 years ago
|
my $a = TQt::Application(\@ARGV);
|
||
13 years ago
|
my $always = Forever;
|
||
|
$a->setMainWidget($always);
|
||
13 years ago
|
$always->setCaption("PerlTQt Example - Forever");
|
||
13 years ago
|
$always->show;
|
||
|
exit $a->exec;
|