summaryrefslogtreecommitdiffstats
path: root/PerlTQt/examples/drawlines
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2012-01-01 18:29:30 -0600
committerTimothy Pearson <[email protected]>2012-01-01 18:29:30 -0600
commitb2af005db21bd8fd068cb79b2ae700953128af2c (patch)
treeabd0ed633726bf0bbecb57d30e92836c31e02695 /PerlTQt/examples/drawlines
parentc1b9383f2032d82db5eb8918dca885e37a901dde (diff)
downloadlibtqt-perl-b2af005db21bd8fd068cb79b2ae700953128af2c.tar.gz
libtqt-perl-b2af005db21bd8fd068cb79b2ae700953128af2c.zip
Move PerlQt
Diffstat (limited to 'PerlTQt/examples/drawlines')
-rw-r--r--PerlTQt/examples/drawlines/drawlines.pl74
1 files changed, 74 insertions, 0 deletions
diff --git a/PerlTQt/examples/drawlines/drawlines.pl b/PerlTQt/examples/drawlines/drawlines.pl
new file mode 100644
index 0000000..1d7575f
--- /dev/null
+++ b/PerlTQt/examples/drawlines/drawlines.pl
@@ -0,0 +1,74 @@
+#!/usr/bin/perl -w
+use strict;
+package ConnectWidget;
+use TQt;
+use TQt::isa qw(TQt::Widget);
+use TQt::attributes qw(
+ points
+ colors
+ count
+ down
+);
+use constant MAXPOINTS => 2000;
+use constant MAXCOLORS => 40;
+
+#
+# Constructs a ConnectWidget.
+#
+
+sub NEW {
+ shift->SUPER::NEW(@_[0,1], &WStaticContents);
+
+ setBackgroundColor(&white);
+ count = 0;
+ down = 0;
+ points = [];
+ my @colors;
+ for(1 .. MAXCOLORS) {
+ push @colors, TQt::Color(rand(255), rand(255), rand(255));
+ }
+ colors = \@colors;
+}
+
+sub paintEvent {
+ my $paint = TQt::Painter(this);
+ for(my $i = 0; $i < count-1; $i++) {
+ for(my $j = $i+1; $j < count; $j++) {
+ $paint->setPen(colors->[rand(MAXCOLORS)]);
+ $paint->drawLine(points->[$i], points->[$j]);
+ }
+ }
+}
+
+sub mousePressEvent {
+ down = 1;
+ count = 0;
+ points = [];
+ erase();
+}
+
+sub mouseReleaseEvent {
+ down = 0;
+ update();
+}
+
+sub mouseMoveEvent {
+ my $e = shift;
+ if(down && count < MAXPOINTS) {
+ my $paint = TQt::Painter(this);
+ push @{this->points}, TQt::Point($e->pos);
+ count++;
+ $paint->drawPoint($e->pos);
+ }
+}
+
+package main;
+use TQt;
+use ConnectWidget;
+
+my $a = TQt::Application(\@ARGV);
+my $connect = ConnectWidget;
+$connect->setCaption("PerlTQt Example - Draw lines");
+$a->setMainWidget($connect);
+$connect->show;
+exit $a->exec;