window.cpp Example File
svggenerator/window.cpp
#include <QColorDialog>
#include <QFileDialog>
#include <QPainter>
#include <QSvgGenerator>
#include "window.h"
#include "displaywidget.h"
Window::Window(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
void Window::updateBackground(int background)
{
displayWidget->setBackground(DisplayWidget::Background(background));
}
void Window::updateColor()
{
QColor color = QColorDialog::getColor(displayWidget->color());
if (color.isValid())
displayWidget->setColor(color);
}
void Window::updateShape(int shape)
{
displayWidget->setShape(DisplayWidget::Shape(shape));
}
void Window::saveSvg()
{
QString newPath = QFileDialog::getSaveFileName(this, tr("Save SVG"),
path, tr("SVG files (*.svg)"));
if (newPath.isEmpty())
return;
path = newPath;
QSvgGenerator generator;
generator.setFileName(path);
generator.setSize(QSize(200, 200));
generator.setViewBox(QRect(0, 0, 200, 200));
generator.setTitle(tr("SVG Generator Example Drawing"));
generator.setDescription(tr("An SVG drawing created by the SVG Generator "
"Example provided with Qt."));
QPainter painter;
painter.begin(&generator);
displayWidget->paint(painter);
painter.end();
}