File: ImageItem.pm

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 (124 lines) | stat: -rw-r--r-- 2,413 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package ImageItemObject;

use strict;
use warnings;
use QtCore4;
use QtGui4;
use Scalar::Util qw(weaken);

use QtCore4::isa qw( Qt::Object );
use QtCore4::slots
    setFrame => ['int'],
    updateItemPosition => [];

sub NEW {
    shift->SUPER::NEW(@_);
}

sub setImageItem {
    this->{imageItem} = shift;
    weaken(this->{imageItem});
    return;
}

# [3]
sub setFrame
{
    my ($frame) = @_;
    this->{imageItem}->adjust();
    my $center = this->{imageItem}->boundingRect()->center();

    this->{imageItem}->translate($center->x(), $center->y());
    this->{imageItem}->scale(1 + $frame / 330.0, 1 + $frame / 330.0);
    this->{imageItem}->translate(-($center->x()), -($center->y()));
}
# [3]

# [6]
sub updateItemPosition
{
    this->{imageItem}->setZValue(this->{z});
}
# [6]

package ImageItem;

use strict;
use warnings;
use QtCore4;
use QtGui4;
use QtCore4::isa qw( Qt::GraphicsPixmapItem );
use ImageItemObject;

# [0]
sub NEW {
    my ($class, $id, $pixmap, $parent, $scene) = @_;
    $class->SUPER::NEW($pixmap, $parent, $scene);

    my $object = ImageItemObject($parent);
    $object->setImageItem( this );
    this->{object} = $object;

    this->{z} = 0.0;

    this->{recordId} = $id;
    this->setAcceptsHoverEvents(1);

    this->{timeLine} = Qt::TimeLine();
    this->{timeLine}->setDuration(150);
    this->{timeLine}->setFrameRange(0, 150);

    $object->connect(this->{timeLine}, SIGNAL 'frameChanged(int)', $object, SLOT 'setFrame(int)');
    $object->connect(this->{timeLine}, SIGNAL 'finished()', $object, SLOT 'updateItemPosition()');

    this->adjust();
}
# [0]

# [1]
sub hoverEnterEvent
{
    this->{timeLine}->setDirection(Qt::TimeLine::Forward());

    if (this->{z} != 1.0) {
        this->{z} = 1.0;
        this->{object}->updateItemPosition();
    }

    if (this->{timeLine}->state() == Qt::TimeLine::NotRunning()) {
        this->{timeLine}->start();
    }
}
# [1]

# [2]
sub hoverLeaveEvent
{
    this->{timeLine}->setDirection(Qt::TimeLine::Backward());
    if (this->{z} != 0.0) {
        this->{z} = 0.0;
    }

    if (this->{timeLine}->state() == Qt::TimeLine::NotRunning()) {
        this->{timeLine}->start();
    }
}
# [2]

# [4]
sub adjust
{
    my $matrix = Qt::Matrix();
    $matrix->scale(150/ this->boundingRect()->width(), 120/ this->boundingRect()->height());
    this->setMatrix($matrix);
}
# [4]

# [5]
sub id
{
    return this->{recordId};
}
# [5]

1;