diff options
author | Timothy Pearson <[email protected]> | 2011-12-18 03:08:08 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-12-18 03:08:08 -0600 |
commit | bcc95cd92ca12c1783464b8ada6816d430dc0e98 (patch) | |
tree | 4701c447365db5392df0174b4bb00b5b5c369da4 /PerlQt/examples/forever | |
download | libtqt-perl-bcc95cd92ca12c1783464b8ada6816d430dc0e98.tar.gz libtqt-perl-bcc95cd92ca12c1783464b8ada6816d430dc0e98.zip |
Initial import of libqt-perl (not yet TQt compatible)
Diffstat (limited to 'PerlQt/examples/forever')
-rw-r--r-- | PerlQt/examples/forever/forever.pl | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/PerlQt/examples/forever/forever.pl b/PerlQt/examples/forever/forever.pl new file mode 100644 index 0000000..bf6d56a --- /dev/null +++ b/PerlQt/examples/forever/forever.pl @@ -0,0 +1,59 @@ +#!/usr/bin/perl -w +use strict; +package Forever; +use Qt; +use Qt::isa qw(Qt::Widget); +use Qt::slots + updateCaption => []; +use Qt::attributes qw( + rectangles + colors +); +use constant numColors => 120; + +sub NEW { + shift->SUPER::NEW(@_); + colors = \my @colors; + for(my $a = 0; $a < numColors; $a++) { + push @colors, Qt::Color(rand(255), rand(255), rand(255)); + } + rectangles = 0; + startTimer(0); + my $counter = Qt::Timer(this); + this->connect($counter, SIGNAL('timeout()'), SLOT('updateCaption()')); + $counter->start(1000); +} + +sub updateCaption { + my $s = sprintf "PerlQt Example - Forever - %d rectangles/second", rectangles; + rectangles = 0; + setCaption($s); +} + +sub paintEvent { + my $paint = Qt::Painter(this); + 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; +use Qt; +use Forever; + +my $a = Qt::Application(\@ARGV); +my $always = Forever; +$a->setMainWidget($always); +$always->setCaption("PerlQt Example - Forever"); +$always->show; +exit $a->exec; |