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
|
package Window;
use strict;
use warnings;
use QtCore4;
use QtGui4;
use QtSvg4;
use Ui_Window;
use DisplayWidget;
# [Window class definition]
use QtCore4::isa qw( Qt::Widget );
use QtCore4::slots
saveSvg => [],
updateBackground => ['int'],
updateColor => [],
updateShape => ['int'];
sub path() {
return this->{path};
}
sub ui() {
return this->{ui};
}
sub displayWidget {
return this->ui->{displayWidget};
}
# [Window class definition]
sub NEW
{
my ($class, $parent) = @_;
$class->SUPER::NEW($parent);
this->{ui} = Ui_Window->setupUi(this);
}
sub updateBackground
{
my ($background) = @_;
this->displayWidget->setBackground($background);
}
sub updateColor
{
my $color = Qt::ColorDialog::getColor(this->displayWidget->color());
if ($color->isValid()) {
this->displayWidget->setColor($color);
}
}
sub updateShape
{
my ($shape) = @_;
this->displayWidget->setShape($shape);
}
# [save SVG]
sub saveSvg
{
my $newPath = Qt::FileDialog::getSaveFileName(this, this->tr('Save SVG'),
this->path, this->tr('SVG files (*.svg)'));
if (!$newPath) {
return;
}
this->{path} = $newPath;
#[configure SVG generator]
my $generator = Qt::SvgGenerator();
$generator->setFileName(this->path);
$generator->setSize(Qt::Size(200, 200));
$generator->setViewBox(Qt::Rect(0, 0, 200, 200));
$generator->setTitle(this->tr('SVG Generator Example Drawing'));
$generator->setDescription(this->tr('An SVG drawing created by the SVG Generator ' .
'Example provided with Qt4.'));
#[configure SVG generator]
#[begin painting]
my $painter = Qt::Painter();
$painter->begin($generator);
#[begin painting]
this->displayWidget->paint($painter);
#[end painting]
$painter->end();
#[end painting]
}
# [save SVG]
1;
|