File: collidingmice.pl

package info (click to toggle)
qt4-perl 4.8.4-1.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,636 kB
  • ctags: 8,100
  • sloc: perl: 42,963; cpp: 28,039; makefile: 160; xml: 98; sh: 4
file content (55 lines) | stat: -rwxr-xr-x 1,364 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

use strict;
use warnings;
use QtCore4;
use QtGui4;
use Mouse;

my $MouseCount = 7;

# [0]
sub main
{
    my $app = Qt::Application( \@ARGV );
    srand(Qt::Time(0,0,0)->secsTo(Qt::Time::currentTime()));
# [0]

# [1]
    my $scene = Qt::GraphicsScene();
    $scene->setSceneRect(-300, -300, 600, 600);
# [1] //! [2]
    $scene->setItemIndexMethod(Qt::GraphicsScene::NoIndex());
# [2]

# [3]
    for (my $i = 0; $i < $MouseCount; ++$i) {
        my $mouse = Mouse();
        $mouse->setPos(sin(($i * 6.28) / $MouseCount) * 200,
                       cos(($i * 6.28) / $MouseCount) * 200);
        $scene->addItem($mouse);
    }
# [3]

# [4]
    my $view = Qt::GraphicsView($scene);
    $view->setRenderHint(Qt::Painter::Antialiasing());
    $view->setBackgroundBrush(Qt::Brush(Qt::Pixmap('images/cheese.jpg')));
# [4] //! [5]
    $view->setCacheMode(Qt::GraphicsView::CacheBackground());
    $view->setViewportUpdateMode(Qt::GraphicsView::BoundingRectViewportUpdate());
    $view->setDragMode(Qt::GraphicsView::ScrollHandDrag());
# [5] //! [6]
    $view->setWindowTitle(Qt::GraphicsView::tr('Colliding Mice'));
    $view->resize(400, 300);
    $view->show();

    my $timer = Qt::Timer();
    Qt::Object::connect( $timer, SIGNAL 'timeout()', $scene, SLOT 'advance()' );
    $timer->start(1000 / 33);

    return $app->exec();
}
# [6]

exit main();