blob: 1d7575fbc3660a53b105068d42a1cdd7ba534f93 (
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
63
64
65
66
67
68
69
70
71
72
73
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;
|