Debian Codegraph @

tests/manual/examples/svggenerator/window.cpp

raw
1 // Copyright (C) 2017 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4 #include <QColorDialog>
5 #include <QFileDialog>
6 #include <QPainter>
7 #include <QSvgGenerator>
8 #include "window.h"
9 #include "displaywidget.h"
10
11 Window::Window(QWidget *parent)
12 : QWidget(parent)
13 {
14 setupUi(this);
15 connect(shapeComboBox, &QComboBox::currentIndexChanged, this, &Window::updateShape);
16 connect(colorButton, &QToolButton::clicked, this, &Window::updateColor);
17 connect(shapeComboBox_2, &QComboBox::currentIndexChanged, this, &Window::updateBackground);
18 connect(toolButton_2, &QToolButton::clicked, this, &Window::saveSvg);
19 }
20
21 void Window::updateBackground(int background)
22 {
23 displayWidget->setBackground(DisplayWidget::Background(background));
24 }
25
26 void Window::updateColor()
27 {
28 QColor color = QColorDialog::getColor(displayWidget->color());
29 if (color.isValid())
30 displayWidget->setColor(color);
31 }
32
33 void Window::updateShape(int shape)
34 {
35 displayWidget->setShape(DisplayWidget::Shape(shape));
36 }
37
38 //! [save SVG]
39 void Window::saveSvg()
40 {
41 QString newPath = QFileDialog::getSaveFileName(this, tr("Save SVG"),
42 path, tr("SVG files (*.svg)"));
43
44 if (newPath.isEmpty())
45 return;
46
47 path = newPath;
48
49 //![configure SVG generator]
50 QSvgGenerator generator;
51 generator.setFileName(path);
52 generator.setSize(QSize(200, 200));
53 generator.setViewBox(QRect(0, 0, 200, 200));
54 generator.setTitle(tr("SVG Generator Example Drawing"));
55 generator.setDescription(tr("An SVG drawing created by the SVG Generator "
56 "Example provided with Qt."));
57 //![configure SVG generator]
58 //![begin painting]
59 QPainter painter;
60 painter.begin(&generator);
61 //![begin painting]
62 displayWidget->paint(painter);
63 //![end painting]
64 painter.end();
65 //![end painting]
66 }
67 //! [save SVG]