File: RenderArea.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 (141 lines) | stat: -rw-r--r-- 2,486 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package RenderArea;

use strict;
use warnings;
use QtCore4;
use QtGui4;
# [0]
use QtCore4::isa qw( Qt::Widget );
use QtCore4::slots
    setFillRule => ['QFillRule'],
    setFillGradient => ['QColor &', 'QColor &'],
    setPenWidth => ['int'],
    setPenColor => ['QColor &'],
    setRotationAngle => ['int'];
# [0]

# [1]
sub path() {
    return this->{path};
}

sub fillColor1() {
    return this->{fillColor1};
}

sub fillColor2() {
    return this->{fillColor2};
}

sub penWidth() {
    return this->{penWidth};
}

sub penColor() {
    return this->{penColor};
}

sub rotationAngle() {
    return this->{rotationAngle};
}
# [1]

# [0]
sub NEW
{
    my ($class, $path, $parent) = @_;
    $class->SUPER::NEW($parent);
    this->{path} = $path;
    this->{penWidth} = 1;
    this->{rotationAngle} = 0;
    this->setBackgroundRole(Qt::Palette::Base());
}
# [0]

# [1]
sub minimumSizeHint
{
    return Qt::Size(50, 50);
}
# [1]

# [2]
sub sizeHint
{
    return Qt::Size(100, 100);
}
# [2]

# [3]
sub setFillRule
{
    my ($rule) = @_;
    this->path->setFillRule($rule);
    this->update();
}
# [3]

# [4]
sub setFillGradient
{
    my ($color1, $color2) = @_;
    this->{fillColor1} = $color1;
    this->{fillColor2} = $color2;
    this->update();
}
# [4]

# [5]
sub setPenWidth
{
    my ($width) = @_;
    this->{penWidth} = $width;
    this->update();
}
# [5]

# [6]
sub setPenColor
{
    my ($color) = @_;
    this->{penColor} = $color;
    this->update();
}
# [6]

# [7]
sub setRotationAngle
{
    my ($degrees) = @_;
    this->{rotationAngle} = $degrees;
    this->update();
}
# [7]

# [8]
sub paintEvent
{
    my $painter = Qt::Painter(this);
    $painter->setRenderHint(Qt::Painter::Antialiasing());
# [8] //! [9]
    $painter->scale(this->width() / 100.0, this->height() / 100.0);
    $painter->translate(50.0, 50.0);
    $painter->rotate(-(this->rotationAngle));
    $painter->translate(-50.0, -50.0);

# [9] //! [10]
    my $color = Qt::qVariantValue( this->penColor, 'Qt::Color' );
    $painter->setPen(Qt::Pen(Qt::Brush($color), this->penWidth, Qt::SolidLine(), Qt::RoundCap(),
                        Qt::RoundJoin()));
    my $gradient = Qt::LinearGradient(0, 0, 0, 100);
    my $fillColor1 = this->fillColor1->value();
    my $fillColor2 = this->fillColor2->value();
    $gradient->setColorAt(0.0, $fillColor1);
    $gradient->setColorAt(1.0, $fillColor2);
    $painter->setBrush(Qt::Brush($gradient));
    $painter->drawPath(this->path);
    $painter->end();
}
# [10]

1;