summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/src/images/weatherinfo-demo.pngbin49688 -> 36807 bytes
-rw-r--r--examples/svg/richtext/textobject/textobject.pro8
-rw-r--r--examples/svg/svgviewer/exportdialog.cpp208
-rw-r--r--examples/svg/svgviewer/exportdialog.h80
-rw-r--r--examples/svg/svgviewer/main.cpp21
-rw-r--r--examples/svg/svgviewer/mainwindow.cpp168
-rw-r--r--examples/svg/svgviewer/mainwindow.h7
-rw-r--r--examples/svg/svgviewer/svgview.cpp34
-rw-r--r--examples/svg/svgviewer/svgview.h18
-rw-r--r--examples/svg/svgviewer/svgviewer.pro6
-rw-r--r--src/plugins/iconengines/svgiconengine/svgiconengine.pro10
-rw-r--r--src/plugins/imageformats/svg/svg.pro10
-rw-r--r--src/svg/qgraphicssvgitem.h6
-rw-r--r--src/svg/qsvggenerator.cpp2
-rw-r--r--src/svg/qsvgrenderer.h8
-rw-r--r--src/svg/qsvgwidget.h4
-rw-r--r--src/svg/svg.pro3
-rw-r--r--tests/auto/qsvggenerator/tst_qsvggenerator.cpp4
18 files changed, 483 insertions, 114 deletions
diff --git a/doc/src/images/weatherinfo-demo.png b/doc/src/images/weatherinfo-demo.png
index 3183aa4..7132b94 100644
--- a/doc/src/images/weatherinfo-demo.png
+++ b/doc/src/images/weatherinfo-demo.png
Binary files differ
diff --git a/examples/svg/richtext/textobject/textobject.pro b/examples/svg/richtext/textobject/textobject.pro
index 794ad32..8892ae7 100644
--- a/examples/svg/richtext/textobject/textobject.pro
+++ b/examples/svg/richtext/textobject/textobject.pro
@@ -12,6 +12,8 @@ RESOURCES = resources.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/svg/richtext/textobject
INSTALLS += target
-filesToDeploy.files = files/*.svg
-filesToDeploy.path = files
-DEPLOYMENT += filesToDeploy
+wince*{
+ filesToDeploy.files = files/*.svg
+ filesToDeploy.path = files
+ DEPLOYMENT += filesToDeploy
+}
diff --git a/examples/svg/svgviewer/exportdialog.cpp b/examples/svg/svgviewer/exportdialog.cpp
new file mode 100644
index 0000000..04c9e12
--- /dev/null
+++ b/examples/svg/svgviewer/exportdialog.cpp
@@ -0,0 +1,208 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "exportdialog.h"
+
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QDialogButtonBox>
+#include <QFileDialog>
+#include <QFormLayout>
+#include <QHBoxLayout>
+#include <QMessageBox>
+#include <QLabel>
+#include <QLineEdit>
+#include <QPushButton>
+#include <QSpinBox>
+#include <QToolButton>
+#include <QVBoxLayout>
+
+#include <QImageWriter>
+
+#include <QDebug>
+
+#include <QDir>
+#include <QFileInfo>
+
+enum { exportMinimumSize = 1, exportMaximumSize = 2000 };
+
+ExportDialog::ExportDialog(QWidget *parent)
+ : QDialog(parent)
+ , m_fileNameLineEdit(new QLineEdit(this))
+ , m_widthSpinBox(new QSpinBox(this))
+ , m_heightSpinBox(new QSpinBox(this))
+ , m_aspectRatio(1)
+{
+ typedef void (QSpinBox::*QSpinBoxIntSignal)(int);
+
+ setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
+ setWindowTitle(tr("Export"));
+
+ QFormLayout *formLayout = new QFormLayout(this);
+
+ QHBoxLayout *fileLayout = new QHBoxLayout;
+ fileLayout->addWidget(m_fileNameLineEdit);
+ m_fileNameLineEdit->setMinimumWidth(QApplication::desktop()->availableGeometry(this).width() / 6);
+ QPushButton *browseButton = new QPushButton(tr("Browse..."), this);
+ fileLayout->addWidget(browseButton);
+ connect(browseButton, &QAbstractButton::clicked, this, &ExportDialog::browse);
+ formLayout->addRow(tr("File:"), fileLayout);
+
+ QHBoxLayout *sizeLayout = new QHBoxLayout;
+ sizeLayout->addStretch();
+ m_widthSpinBox->setMinimum(exportMinimumSize);
+ m_widthSpinBox->setMaximum(exportMaximumSize);
+ connect(m_widthSpinBox, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
+ this, &ExportDialog::exportWidthChanged);
+ sizeLayout->addWidget(m_widthSpinBox);
+ //: Multiplication, as in 32x32
+ sizeLayout->addWidget(new QLabel(tr("x")));
+ m_heightSpinBox->setMinimum(exportMinimumSize);
+ m_heightSpinBox->setMaximum(exportMaximumSize);
+ connect(m_heightSpinBox, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
+ this, &ExportDialog::exportHeightChanged);
+ sizeLayout->addWidget(m_heightSpinBox);
+ QToolButton *resetButton = new QToolButton(this);
+ resetButton->setIcon(QIcon(":/qt-project.org/styles/commonstyle/images/refresh-32.png"));
+ sizeLayout->addWidget(resetButton);
+ connect(resetButton, &QAbstractButton::clicked, this, &ExportDialog::resetExportSize);
+ formLayout->addRow(tr("Size:"), sizeLayout);
+
+ QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
+ connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
+ connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
+ formLayout->addRow(buttonBox);
+}
+
+void ExportDialog::accept()
+{
+ const QString fileName = exportFileName();
+ if (fileName.isEmpty()) {
+ QMessageBox::warning(this, windowTitle(), tr("Please enter a file name"));
+ return;
+ }
+ QFileInfo fi(fileName);
+ if (fi.exists()) {
+ const QString question = tr("%1 already exists.\nWould you like to overwrite it?").arg(QDir::toNativeSeparators(fileName));
+ if (QMessageBox::question(this, windowTitle(), question, QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
+ return;
+ }
+ QDialog::accept();
+}
+
+QSize ExportDialog::exportSize() const
+{
+ return QSize(m_widthSpinBox->value(), m_heightSpinBox->value());
+}
+
+void ExportDialog::setExportSize(const QSize &size)
+{
+ m_defaultSize = size;
+ QSizeF defaultSizeF(m_defaultSize);
+ m_aspectRatio = defaultSizeF.width() / defaultSizeF.height();
+ setExportWidthBlocked(size.width());
+ setExportHeightBlocked(size.height());
+}
+
+void ExportDialog::resetExportSize()
+{
+ setExportWidthBlocked(m_defaultSize.width());
+ setExportHeightBlocked(m_defaultSize.height());
+}
+
+void ExportDialog::setExportWidthBlocked(int width)
+{
+ if (m_widthSpinBox->value() != width) {
+ const bool blockSignals = m_widthSpinBox->blockSignals(true);
+ m_widthSpinBox->setValue(width);
+ m_widthSpinBox->blockSignals(blockSignals);
+ }
+}
+
+void ExportDialog::setExportHeightBlocked(int height)
+{
+ if (m_heightSpinBox->value() != height) {
+ const bool blockSignals = m_heightSpinBox->blockSignals(true);
+ m_heightSpinBox->setValue(height);
+ m_heightSpinBox->blockSignals(blockSignals);
+ }
+}
+
+void ExportDialog::exportWidthChanged(int width)
+{
+ const bool square = m_defaultSize.width() == m_defaultSize.height();
+ setExportHeightBlocked(square ? width : qRound(qreal(width) / m_aspectRatio));
+}
+
+void ExportDialog::exportHeightChanged(int height)
+{
+ const bool square = m_defaultSize.width() == m_defaultSize.height();
+ setExportWidthBlocked(square ? height : qRound(qreal(height) * m_aspectRatio));
+}
+
+QString ExportDialog::exportFileName() const
+{
+ return QDir::cleanPath(m_fileNameLineEdit->text().trimmed());
+}
+
+void ExportDialog::setExportFileName(const QString &f)
+{
+ m_fileNameLineEdit->setText(QDir::toNativeSeparators(f));
+}
+
+void ExportDialog::browse()
+{
+ QFileDialog fileDialog(this);
+ fileDialog.setAcceptMode(QFileDialog::AcceptSave);
+ const QString fileName = exportFileName();
+ if (!fileName.isEmpty())
+ fileDialog.setDirectory(QFileInfo(fileName).absolutePath());
+ QStringList mimeTypes;
+ foreach (const QByteArray &mimeType, QImageWriter::supportedMimeTypes())
+ mimeTypes.append(QLatin1String(mimeType));
+ fileDialog.setMimeTypeFilters(mimeTypes);
+ const int pngIndex = mimeTypes.indexOf("image/png");
+ if (pngIndex >= 0) {
+ fileDialog.selectMimeTypeFilter(mimeTypes.at(pngIndex));
+ fileDialog.setDefaultSuffix("png");
+ }
+ if (fileDialog.exec() == QDialog::Accepted)
+ setExportFileName(fileDialog.selectedFiles().constFirst());
+}
diff --git a/examples/svg/svgviewer/exportdialog.h b/examples/svg/svgviewer/exportdialog.h
new file mode 100644
index 0000000..71d8bdd
--- /dev/null
+++ b/examples/svg/svgviewer/exportdialog.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef EXPORTDIALOG_H
+#define EXPORTDIALOG_H
+
+#include <QDialog>
+
+QT_FORWARD_DECLARE_CLASS(QLineEdit)
+QT_FORWARD_DECLARE_CLASS(QSpinBox)
+
+class ExportDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ explicit ExportDialog(QWidget *parent = 0);
+
+ QSize exportSize() const;
+ void setExportSize(const QSize &);
+
+ QString exportFileName() const;
+ void setExportFileName(const QString &);
+
+ void accept() override;
+
+private slots:
+ void browse();
+ void resetExportSize();
+ void exportWidthChanged(int width);
+ void exportHeightChanged(int height);
+
+private:
+ void setExportWidthBlocked(int width);
+ void setExportHeightBlocked(int height);
+
+ QLineEdit *m_fileNameLineEdit;
+ QSpinBox *m_widthSpinBox;
+ QSpinBox *m_heightSpinBox;
+ QSize m_defaultSize;
+ qreal m_aspectRatio;
+};
+
+#endif // EXPORTDIALOG_H
diff --git a/examples/svg/svgviewer/main.cpp b/examples/svg/svgviewer/main.cpp
index 671262c..9155c87 100644
--- a/examples/svg/svgviewer/main.cpp
+++ b/examples/svg/svgviewer/main.cpp
@@ -39,7 +39,9 @@
****************************************************************************/
#include <QApplication>
-#include <QString>
+#include <QCommandLineParser>
+#include <QCommandLineOption>
+#include <QStringList>
#ifndef QT_NO_OPENGL
#include <QGLFormat>
#endif
@@ -51,12 +53,21 @@ int main(int argc, char **argv)
Q_INIT_RESOURCE(svgviewer);
QApplication app(argc, argv);
+ QCoreApplication::setApplicationName("SVG Viewer");
+ QGuiApplication::setApplicationDisplayName(QCoreApplication::applicationName());
+ QCoreApplication::setOrganizationName("QtProject");
+ QCoreApplication::setApplicationVersion(QT_VERSION_STR);
+
+ QCommandLineParser parser;
+ parser.setApplicationDescription("Qt SVG Viewer");
+ parser.addHelpOption();
+ parser.addVersionOption();
+ parser.addPositionalArgument("file", "The file to open.");
+ parser.process(app);
MainWindow window;
- if (argc == 2)
- window.openFile(argv[1]);
- else
- window.openFile(":/files/bubbles.svg");
+ if (!window.loadFile(parser.positionalArguments().value(0, QLatin1String(":/files/bubbles.svg"))))
+ return -1;
window.show();
return app.exec();
}
diff --git a/examples/svg/svgviewer/mainwindow.cpp b/examples/svg/svgviewer/mainwindow.cpp
index d78c5fb..c63f223 100644
--- a/examples/svg/svgviewer/mainwindow.cpp
+++ b/examples/svg/svgviewer/mainwindow.cpp
@@ -39,56 +39,73 @@
****************************************************************************/
#include "mainwindow.h"
+#include "exportdialog.h"
#include <QtWidgets>
+#include <QSvgRenderer>
#include "svgview.h"
+static inline QString picturesLocation()
+{
+ return QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).value(0, QDir::currentPath());
+}
+
MainWindow::MainWindow()
: QMainWindow()
, m_view(new SvgView)
{
- QMenu *fileMenu = new QMenu(tr("&File"), this);
- QAction *openAction = fileMenu->addAction(tr("&Open..."));
- openAction->setShortcut(QKeySequence(tr("Ctrl+O")));
- QAction *quitAction = fileMenu->addAction(tr("E&xit"));
+ QToolBar *toolBar = new QToolBar(this);
+ addToolBar(Qt::TopToolBarArea, toolBar);
+
+ QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+ const QIcon openIcon = QIcon::fromTheme("document-open", QIcon(":/qt-project.org/styles/commonstyle/images/standardbutton-open-32.png"));
+ QAction *openAction = fileMenu->addAction(openIcon, tr("&Open..."), this, &MainWindow::openFile);
+ openAction->setShortcut(QKeySequence::Open);
+ toolBar->addAction(openAction);
+ const QIcon exportIcon = QIcon::fromTheme("document-save", QIcon(":/qt-project.org/styles/commonstyle/images/standardbutton-save-32.png"));
+ QAction *exportAction = fileMenu->addAction(exportIcon, tr("&Export..."), this, &MainWindow::exportImage);
+ exportAction->setToolTip(tr("Export Image"));
+ exportAction->setShortcut(Qt::CTRL + Qt::Key_E);
+ toolBar->addAction(exportAction);
+ QAction *quitAction = fileMenu->addAction(tr("E&xit"), qApp, QCoreApplication::quit);
quitAction->setShortcuts(QKeySequence::Quit);
- menuBar()->addMenu(fileMenu);
-
- QMenu *viewMenu = new QMenu(tr("&View"), this);
+ QMenu *viewMenu = menuBar()->addMenu(tr("&View"));
m_backgroundAction = viewMenu->addAction(tr("&Background"));
m_backgroundAction->setEnabled(false);
m_backgroundAction->setCheckable(true);
m_backgroundAction->setChecked(false);
- connect(m_backgroundAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewBackground(bool)));
+ connect(m_backgroundAction, &QAction::toggled, m_view, &SvgView::setViewBackground);
m_outlineAction = viewMenu->addAction(tr("&Outline"));
m_outlineAction->setEnabled(false);
m_outlineAction->setCheckable(true);
m_outlineAction->setChecked(true);
- connect(m_outlineAction, SIGNAL(toggled(bool)), m_view, SLOT(setViewOutline(bool)));
+ connect(m_outlineAction, &QAction::toggled, m_view, &SvgView::setViewOutline);
- menuBar()->addMenu(viewMenu);
-
- QMenu *rendererMenu = new QMenu(tr("&Renderer"), this);
+ QMenu *rendererMenu = menuBar()->addMenu(tr("&Renderer"));
m_nativeAction = rendererMenu->addAction(tr("&Native"));
m_nativeAction->setCheckable(true);
m_nativeAction->setChecked(true);
+ m_nativeAction->setData(int(SvgView::Native));
#ifndef QT_NO_OPENGL
m_glAction = rendererMenu->addAction(tr("&OpenGL"));
m_glAction->setCheckable(true);
+ m_glAction->setData(int(SvgView::OpenGL));
#endif
m_imageAction = rendererMenu->addAction(tr("&Image"));
m_imageAction->setCheckable(true);
+ m_imageAction->setData(int(SvgView::Image));
-#ifndef QT_NO_OPENGL
rendererMenu->addSeparator();
m_highQualityAntialiasingAction = rendererMenu->addAction(tr("&High Quality Antialiasing"));
m_highQualityAntialiasingAction->setEnabled(false);
m_highQualityAntialiasingAction->setCheckable(true);
m_highQualityAntialiasingAction->setChecked(false);
- connect(m_highQualityAntialiasingAction, SIGNAL(toggled(bool)), m_view, SLOT(setHighQualityAntialiasing(bool)));
+ connect(m_highQualityAntialiasingAction, &QAction::toggled, m_view, &SvgView::setHighQualityAntialiasing);
+#ifdef QT_NO_OPENGL
+ m_highQualityAntialiasingAction->setVisible(false);
#endif
QActionGroup *rendererGroup = new QActionGroup(this);
@@ -100,64 +117,97 @@ MainWindow::MainWindow()
menuBar()->addMenu(rendererMenu);
- connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
- connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
- connect(rendererGroup, SIGNAL(triggered(QAction*)),
- this, SLOT(setRenderer(QAction*)));
+ connect(rendererGroup, &QActionGroup::triggered,
+ [this] (QAction *a) { setRenderer(a->data().toInt()); });
+
+ QMenu *help = menuBar()->addMenu(tr("&Help"));
+ help->addAction(tr("About Qt"), qApp, &QApplication::aboutQt);
setCentralWidget(m_view);
- setWindowTitle(tr("SVG Viewer"));
}
-void MainWindow::openFile(const QString &path)
+void MainWindow::openFile()
{
- QString fileName;
- if (path.isNull())
- fileName = QFileDialog::getOpenFileName(this, tr("Open SVG File"),
- m_currentPath, "SVG files (*.svg *.svgz *.svg.gz)");
- else
- fileName = path;
-
- if (!fileName.isEmpty()) {
- QFile file(fileName);
- if (!file.exists()) {
- QMessageBox::critical(this, tr("Open SVG File"),
- QString("Could not open file '%1'.").arg(fileName));
-
- m_outlineAction->setEnabled(false);
- m_backgroundAction->setEnabled(false);
- return;
- }
+ QFileDialog fileDialog(this);
+ fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
+ fileDialog.setMimeTypeFilters(QStringList() << "image/svg+xml" << "image/svg+xml-compressed");
+ fileDialog.setWindowTitle(tr("Open SVG File"));
+ if (m_currentPath.isEmpty())
+ fileDialog.setDirectory(picturesLocation());
+
+ while (fileDialog.exec() == QDialog::Accepted && !loadFile(fileDialog.selectedFiles().constFirst()))
+ ;
+}
- m_view->openFile(file);
+bool MainWindow::loadFile(const QString &fileName)
+{
+ if (!QFileInfo::exists(fileName) || !m_view->openFile(fileName)) {
+ QMessageBox::critical(this, tr("Open SVG File"),
+ tr("Could not open file '%1'.").arg(QDir::toNativeSeparators(fileName)));
+ return false;
+ }
- if (!fileName.startsWith(":/")) {
- m_currentPath = fileName;
- setWindowTitle(tr("%1 - SVGViewer").arg(m_currentPath));
- }
+ if (!fileName.startsWith(":/")) {
+ m_currentPath = fileName;
+ setWindowFilePath(fileName);
+ const QSize size = m_view->svgSize();
+ const QString message =
+ tr("Opened %1, %2x%3").arg(QFileInfo(fileName).fileName()).arg(size.width()).arg(size.width());
+ statusBar()->showMessage(message);
+ }
- m_outlineAction->setEnabled(true);
- m_backgroundAction->setEnabled(true);
+ m_outlineAction->setEnabled(true);
+ m_backgroundAction->setEnabled(true);
- resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height()));
- }
+ const QSize availableSize = QApplication::desktop()->availableGeometry(this).size();
+ resize(m_view->sizeHint().expandedTo(availableSize / 4) + QSize(80, 80 + menuBar()->height()));
+
+ return true;
}
-void MainWindow::setRenderer(QAction *action)
+void MainWindow::setRenderer(int renderMode)
{
-#ifndef QT_NO_OPENGL
- m_highQualityAntialiasingAction->setEnabled(false);
-#endif
- if (action == m_nativeAction)
- m_view->setRenderer(SvgView::Native);
-#ifndef QT_NO_OPENGL
- else if (action == m_glAction) {
- m_highQualityAntialiasingAction->setEnabled(true);
- m_view->setRenderer(SvgView::OpenGL);
+ m_highQualityAntialiasingAction->setEnabled(renderMode == SvgView::OpenGL);
+ m_view->setRenderer(static_cast<SvgView::RendererType>(renderMode));
+}
+
+void MainWindow::exportImage()
+{
+ ExportDialog exportDialog(this);
+ exportDialog.setExportSize(m_view->svgSize());
+ QString fileName;
+ if (m_currentPath.isEmpty()) {
+ fileName = picturesLocation() + QLatin1String("/export.png");
+ } else {
+ const QFileInfo fi(m_currentPath);
+ fileName = fi.absolutePath() + QLatin1Char('/') + fi.baseName() + QLatin1String(".png");
}
-#endif
- else if (action == m_imageAction) {
- m_view->setRenderer(SvgView::Image);
+ exportDialog.setExportFileName(fileName);
+
+ while (true) {
+ if (exportDialog.exec() != QDialog::Accepted)
+ break;
+
+ const QSize imageSize = exportDialog.exportSize();
+ QImage image(imageSize, QImage::Format_ARGB32);
+ image.fill(Qt::transparent);
+ QPainter painter;
+ painter.begin(&image);
+ m_view->renderer()->render(&painter, QRectF(QPointF(), QSizeF(imageSize)));
+ painter.end();
+
+ const QString fileName = exportDialog.exportFileName();
+ if (image.save(fileName)) {
+
+ const QString message = tr("Exported %1, %2x%3, %4 bytes")
+ .arg(QDir::toNativeSeparators(fileName)).arg(imageSize.width()).arg(imageSize.height())
+ .arg(QFileInfo(fileName).size());
+ statusBar()->showMessage(message);
+ break;
+ } else {
+ QMessageBox::critical(this, tr("Export Image"),
+ tr("Could not write file '%1'.").arg(QDir::toNativeSeparators(fileName)));
+ }
}
}
diff --git a/examples/svg/svgviewer/mainwindow.h b/examples/svg/svgviewer/mainwindow.h
index 1c43da6..c0973f9 100644
--- a/examples/svg/svgviewer/mainwindow.h
+++ b/examples/svg/svgviewer/mainwindow.h
@@ -60,9 +60,12 @@ class MainWindow : public QMainWindow
public:
MainWindow();
+ bool loadFile(const QString &path);
+
public slots:
- void openFile(const QString &path = QString());
- void setRenderer(QAction *action);
+ void openFile();
+ void exportImage();
+ void setRenderer(int renderMode);
private:
QAction *m_nativeAction;
diff --git a/examples/svg/svgviewer/svgview.cpp b/examples/svg/svgviewer/svgview.cpp
index 5283bf1..cbea85d 100644
--- a/examples/svg/svgviewer/svgview.cpp
+++ b/examples/svg/svgviewer/svgview.cpp
@@ -39,7 +39,8 @@
****************************************************************************/
#include "svgview.h"
-#include <QFile>
+#include <QSvgRenderer>
+
#include <QWheelEvent>
#include <QMouseEvent>
#include <QGraphicsRectItem>
@@ -54,9 +55,9 @@
SvgView::SvgView(QWidget *parent)
: QGraphicsView(parent)
, m_renderer(Native)
- , m_svgItem(0)
- , m_backgroundItem(0)
- , m_outlineItem(0)
+ , m_svgItem(nullptr)
+ , m_backgroundItem(nullptr)
+ , m_outlineItem(nullptr)
{
setScene(new QGraphicsScene(this));
setTransformationAnchor(AnchorUnderMouse);
@@ -83,20 +84,26 @@ void SvgView::drawBackground(QPainter *p, const QRectF &)
p->restore();
}
-void SvgView::openFile(const QFile &file)
+QSize SvgView::svgSize() const
{
- if (!file.exists())
- return;
+ return m_svgItem ? m_svgItem->boundingRect().size().toSize() : QSize();
+}
+bool SvgView::openFile(const QString &fileName)
+{
QGraphicsScene *s = scene();
- bool drawBackground = (m_backgroundItem ? m_backgroundItem->isVisible() : false);
- bool drawOutline = (m_outlineItem ? m_outlineItem->isVisible() : true);
+ const bool drawBackground = (m_backgroundItem ? m_backgroundItem->isVisible() : false);
+ const bool drawOutline = (m_outlineItem ? m_outlineItem->isVisible() : true);
+
+ QScopedPointer<QGraphicsSvgItem> svgItem(new QGraphicsSvgItem(fileName));
+ if (!svgItem->renderer()->isValid())
+ return false;
s->clear();
resetTransform();
- m_svgItem = new QGraphicsSvgItem(file.fileName());
+ m_svgItem = svgItem.take();
m_svgItem->setFlags(QGraphicsItem::ItemClipsToShape);
m_svgItem->setCacheMode(QGraphicsItem::NoCache);
m_svgItem->setZValue(0);
@@ -120,6 +127,7 @@ void SvgView::openFile(const QFile &file)
s->addItem(m_outlineItem);
s->setSceneRect(m_outlineItem->boundingRect().adjusted(-10, -10, 10, 10));
+ return true;
}
void SvgView::setRenderer(RendererType type)
@@ -186,3 +194,9 @@ void SvgView::wheelEvent(QWheelEvent *event)
event->accept();
}
+QSvgRenderer *SvgView::renderer() const
+{
+ if (m_svgItem)
+ return m_svgItem->renderer();
+ return nullptr;
+}
diff --git a/examples/svg/svgviewer/svgview.h b/examples/svg/svgviewer/svgview.h
index b6d1b01..645fb49 100644
--- a/examples/svg/svgviewer/svgview.h
+++ b/examples/svg/svgviewer/svgview.h
@@ -44,9 +44,10 @@
#include <QGraphicsView>
QT_BEGIN_NAMESPACE
+class QGraphicsSvgItem;
+class QSvgRenderer;
class QWheelEvent;
class QPaintEvent;
-class QFile;
QT_END_NAMESPACE
class SvgView : public QGraphicsView
@@ -56,11 +57,14 @@ class SvgView : public QGraphicsView
public:
enum RendererType { Native, OpenGL, Image };
- SvgView(QWidget *parent = 0);
+ explicit SvgView(QWidget *parent = nullptr);
- void openFile(const QFile &file);
+ bool openFile(const QString &fileName);
void setRenderer(RendererType type = Native);
- void drawBackground(QPainter *p, const QRectF &rect);
+ void drawBackground(QPainter *p, const QRectF &rect) override;
+
+ QSize svgSize() const;
+ QSvgRenderer *renderer() const;
public slots:
void setHighQualityAntialiasing(bool highQualityAntialiasing);
@@ -68,13 +72,13 @@ public slots:
void setViewOutline(bool enable);
protected:
- void wheelEvent(QWheelEvent *event);
- void paintEvent(QPaintEvent *event);
+ void wheelEvent(QWheelEvent *event) override;
+ void paintEvent(QPaintEvent *event) override;
private:
RendererType m_renderer;
- QGraphicsItem *m_svgItem;
+ QGraphicsSvgItem *m_svgItem;
QGraphicsRectItem *m_backgroundItem;
QGraphicsRectItem *m_outlineItem;
diff --git a/examples/svg/svgviewer/svgviewer.pro b/examples/svg/svgviewer/svgviewer.pro
index 1b4764c..8f3ae05 100644
--- a/examples/svg/svgviewer/svgviewer.pro
+++ b/examples/svg/svgviewer/svgviewer.pro
@@ -1,9 +1,11 @@
HEADERS = mainwindow.h \
- svgview.h
+ svgview.h \
+ exportdialog.h
RESOURCES = svgviewer.qrc
SOURCES = main.cpp \
mainwindow.cpp \
- svgview.cpp
+ svgview.cpp \
+ exportdialog.cpp
QT += widgets svg
qtHaveModule(opengl): QT += opengl
diff --git a/src/plugins/iconengines/svgiconengine/svgiconengine.pro b/src/plugins/iconengines/svgiconengine/svgiconengine.pro
index 516142b..eb6847b 100644
--- a/src/plugins/iconengines/svgiconengine/svgiconengine.pro
+++ b/src/plugins/iconengines/svgiconengine/svgiconengine.pro
@@ -1,12 +1,12 @@
TARGET = qsvgicon
-PLUGIN_TYPE = iconengines
-PLUGIN_EXTENDS = svg
-PLUGIN_CLASS_NAME = QSvgIconPlugin
-load(qt_plugin)
-
HEADERS += qsvgiconengine.h
SOURCES += main.cpp \
qsvgiconengine.cpp
OTHER_FILES += qsvgiconengine.json
QT += svg core-private gui-private
+
+PLUGIN_TYPE = iconengines
+PLUGIN_EXTENDS = svg
+PLUGIN_CLASS_NAME = QSvgIconPlugin
+load(qt_plugin)
diff --git a/src/plugins/imageformats/svg/svg.pro b/src/plugins/imageformats/svg/svg.pro
index ce1881f..9db6a9a 100644
--- a/src/plugins/imageformats/svg/svg.pro
+++ b/src/plugins/imageformats/svg/svg.pro
@@ -1,11 +1,11 @@
TARGET = qsvg
-PLUGIN_TYPE = imageformats
-PLUGIN_EXTENDS = svg
-PLUGIN_CLASS_NAME = QSvgPlugin
-load(qt_plugin)
-
HEADERS += qsvgiohandler.h
SOURCES += main.cpp \
qsvgiohandler.cpp
QT += svg
+
+PLUGIN_TYPE = imageformats
+PLUGIN_EXTENDS = svg
+PLUGIN_CLASS_NAME = QSvgPlugin
+load(qt_plugin)
diff --git a/src/svg/qgraphicssvgitem.h b/src/svg/qgraphicssvgitem.h
index 90ae4c5..88603ec 100644
--- a/src/svg/qgraphicssvgitem.h
+++ b/src/svg/qgraphicssvgitem.h
@@ -61,8 +61,8 @@ class Q_SVG_EXPORT QGraphicsSvgItem : public QGraphicsObject
Q_PROPERTY(QSize maximumCacheSize READ maximumCacheSize WRITE setMaximumCacheSize)
public:
- QGraphicsSvgItem(QGraphicsItem *parentItem=0);
- QGraphicsSvgItem(const QString &fileName, QGraphicsItem *parentItem=0);
+ QGraphicsSvgItem(QGraphicsItem *parentItem = Q_NULLPTR);
+ QGraphicsSvgItem(const QString &fileName, QGraphicsItem *parentItem = Q_NULLPTR);
void setSharedRenderer(QSvgRenderer *renderer);
QSvgRenderer *renderer() const;
@@ -80,7 +80,7 @@ public:
virtual void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
- QWidget *widget=0);
+ QWidget *widget = Q_NULLPTR);
enum { Type = 13 };
virtual int type() const;
diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp
index 46ebca4..468b97f 100644
--- a/src/svg/qsvggenerator.cpp
+++ b/src/svg/qsvggenerator.cpp
@@ -324,8 +324,6 @@ public:
void qpenToSvg(const QPen &spen)
{
- QString width;
-
d_func()->pen = spen;
switch (spen.style()) {
diff --git a/src/svg/qsvgrenderer.h b/src/svg/qsvgrenderer.h
index fe58343..6538df0 100644
--- a/src/svg/qsvgrenderer.h
+++ b/src/svg/qsvgrenderer.h
@@ -65,10 +65,10 @@ class Q_SVG_EXPORT QSvgRenderer : public QObject
Q_PROPERTY(int framesPerSecond READ framesPerSecond WRITE setFramesPerSecond)
Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame)
public:
- QSvgRenderer(QObject *parent=0);
- QSvgRenderer(const QString &filename, QObject *parent=0);
- QSvgRenderer(const QByteArray &contents, QObject *parent=0);
- QSvgRenderer(QXmlStreamReader *contents, QObject *parent=0);
+ QSvgRenderer(QObject *parent = Q_NULLPTR);
+ QSvgRenderer(const QString &filename, QObject *parent = Q_NULLPTR);
+ QSvgRenderer(const QByteArray &contents, QObject *parent = Q_NULLPTR);
+ QSvgRenderer(QXmlStreamReader *contents, QObject *parent = Q_NULLPTR);
~QSvgRenderer();
bool isValid() const;
diff --git a/src/svg/qsvgwidget.h b/src/svg/qsvgwidget.h
index 3f5210e..d936c6b 100644
--- a/src/svg/qsvgwidget.h
+++ b/src/svg/qsvgwidget.h
@@ -59,8 +59,8 @@ class Q_SVG_EXPORT QSvgWidget : public QWidget
{
Q_OBJECT
public:
- QSvgWidget(QWidget *parent=0);
- QSvgWidget(const QString &file, QWidget *parent=0);
+ QSvgWidget(QWidget *parent = Q_NULLPTR);
+ QSvgWidget(const QString &file, QWidget *parent = Q_NULLPTR);
~QSvgWidget();
QSvgRenderer *renderer() const;
diff --git a/src/svg/svg.pro b/src/svg/svg.pro
index 8cee04f..ce5bf1a 100644
--- a/src/svg/svg.pro
+++ b/src/svg/svg.pro
@@ -7,7 +7,6 @@ win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x66000000
solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2
QMAKE_DOCS = $$PWD/doc/qtsvg.qdocconf
-load(qt_module)
HEADERS += \
qsvggraphics_p.h \
@@ -46,3 +45,5 @@ contains(QT_CONFIG, system-zlib) {
} else {
QT_PRIVATE += zlib-private
}
+
+load(qt_module)
diff --git a/tests/auto/qsvggenerator/tst_qsvggenerator.cpp b/tests/auto/qsvggenerator/tst_qsvggenerator.cpp
index 8f0169d..db7e3e5 100644
--- a/tests/auto/qsvggenerator/tst_qsvggenerator.cpp
+++ b/tests/auto/qsvggenerator/tst_qsvggenerator.cpp
@@ -39,10 +39,6 @@
#include <qsvggenerator.h>
#include <qsvgrenderer.h>
-#ifdef Q_OS_SYMBIAN
-#define SRCDIR ""
-#endif
-
class tst_QSvgGenerator : public QObject
{
Q_OBJECT