From 36a22f2c48f7df34c71b2177ff9c8b65daef614c Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 12 Feb 2016 16:46:17 +0100 Subject: consistently put {qt,qml}_{module,plugin} at the end of project files this fixes static builds by ensuring that all dependencies are exported. Task-number: QTBUG-51071 Change-Id: I20b0d2c018e3adce10629aee3fa055df437df71c Reviewed-by: Joerg Bornemann --- src/plugins/iconengines/svgiconengine/svgiconengine.pro | 10 +++++----- src/plugins/imageformats/svg/svg.pro | 10 +++++----- src/svg/svg.pro | 3 ++- 3 files changed, 12 insertions(+), 11 deletions(-) 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/svg.pro b/src/svg/svg.pro index 83e76b7..103bbea 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 \ @@ -53,3 +52,5 @@ contains(QT_CONFIG, system-zlib) { } else { QT_PRIVATE += zlib-private } + +load(qt_module) -- cgit v1.2.1 From a0363376cfbfd9359adbd2501dd087dfb0a4eb98 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 2 Mar 2016 13:59:24 +0100 Subject: Make public headers compile with -Wzero-as-null-pointer-constant ... or equivalent. QtBase 5.6 headers already compile that way, so let the other modules follow suit. Task-number: QTBUG-45291 Change-Id: I725682ffe00dab94f84b00eed3aa76377bb80519 Reviewed-by: Lars Knoll --- src/svg/qgraphicssvgitem.h | 6 +++--- src/svg/qsvgrenderer.h | 8 ++++---- src/svg/qsvgwidget.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/svg/qgraphicssvgitem.h b/src/svg/qgraphicssvgitem.h index 541ddec..f3410d7 100644 --- a/src/svg/qgraphicssvgitem.h +++ b/src/svg/qgraphicssvgitem.h @@ -55,8 +55,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; @@ -74,7 +74,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/qsvgrenderer.h b/src/svg/qsvgrenderer.h index 7d29e6d..612b10d 100644 --- a/src/svg/qsvgrenderer.h +++ b/src/svg/qsvgrenderer.h @@ -59,10 +59,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 86616e1..3b8c26a 100644 --- a/src/svg/qsvgwidget.h +++ b/src/svg/qsvgwidget.h @@ -53,8 +53,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; -- cgit v1.2.1 From 99303e92ae9cf461f99b8eff8b37b42f758118b6 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 11 Mar 2016 10:00:33 +0100 Subject: Polish the SVG viewer example. - Use Qt 5 connection syntax, demonstrating lambdas. - Use QCommandLineParser. - Improve error handling. - Use Mime API of QFileDialog, point to pictures location initially. - Prevent the application from shrinking when loading small images. - Minor polishing, status messages on loading, About Qt dialog. Change-Id: I76f14001c9ab12cbfaaacc2ca4828b404e4b13b2 Reviewed-by: aavit --- examples/svg/svgviewer/main.cpp | 21 ++++-- examples/svg/svgviewer/mainwindow.cpp | 121 ++++++++++++++++------------------ examples/svg/svgviewer/mainwindow.h | 6 +- examples/svg/svgviewer/svgview.cpp | 28 +++++--- examples/svg/svgviewer/svgview.h | 13 ++-- 5 files changed, 102 insertions(+), 87 deletions(-) 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 -#include +#include +#include +#include #ifndef QT_NO_OPENGL #include #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..4e94642 100644 --- a/examples/svg/svgviewer/mainwindow.cpp +++ b/examples/svg/svgviewer/mainwindow.cpp @@ -48,47 +48,47 @@ 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")); + QMenu *fileMenu = menuBar()->addMenu(tr("&File")); + QAction *openAction = fileMenu->addAction(tr("&Open..."), this, &MainWindow::openFile); + openAction->setShortcut(QKeySequence::Open); + 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))); - - menuBar()->addMenu(viewMenu); + connect(m_outlineAction, &QAction::toggled, m_view, &SvgView::setViewOutline); - 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 +100,57 @@ 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; - } - - m_view->openFile(file); - - if (!fileName.startsWith(":/")) { - m_currentPath = fileName; - setWindowTitle(tr("%1 - SVGViewer").arg(m_currentPath)); - } - - m_outlineAction->setEnabled(true); - m_backgroundAction->setEnabled(true); - - resize(m_view->sizeHint() + QSize(80, 80 + menuBar()->height())); - } + 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(QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).value(0, QDir::currentPath())); + + while (fileDialog.exec() == QDialog::Accepted && !loadFile(fileDialog.selectedFiles().constFirst())) + ; } -void MainWindow::setRenderer(QAction *action) +bool MainWindow::loadFile(const QString &fileName) { -#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); + if (!QFileInfo::exists(fileName) || !m_view->openFile(fileName)) { + QMessageBox::critical(this, tr("Open SVG File"), + QString("Could not open file '%1'.").arg(QDir::toNativeSeparators(fileName))); + return false; } -#endif - else if (action == m_imageAction) { - m_view->setRenderer(SvgView::Image); + + 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); + + 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(int renderMode) +{ + + m_highQualityAntialiasingAction->setEnabled(renderMode == SvgView::OpenGL); + m_view->setRenderer(static_cast(renderMode)); } diff --git a/examples/svg/svgviewer/mainwindow.h b/examples/svg/svgviewer/mainwindow.h index 1c43da6..215f4a6 100644 --- a/examples/svg/svgviewer/mainwindow.h +++ b/examples/svg/svgviewer/mainwindow.h @@ -60,9 +60,11 @@ 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 setRenderer(int renderMode); private: QAction *m_nativeAction; diff --git a/examples/svg/svgviewer/svgview.cpp b/examples/svg/svgviewer/svgview.cpp index 5283bf1..dd9de1a 100644 --- a/examples/svg/svgviewer/svgview.cpp +++ b/examples/svg/svgviewer/svgview.cpp @@ -39,7 +39,8 @@ ****************************************************************************/ #include "svgview.h" -#include +#include + #include #include #include @@ -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 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) diff --git a/examples/svg/svgviewer/svgview.h b/examples/svg/svgviewer/svgview.h index b6d1b01..41c0ca5 100644 --- a/examples/svg/svgviewer/svgview.h +++ b/examples/svg/svgviewer/svgview.h @@ -46,7 +46,6 @@ QT_BEGIN_NAMESPACE class QWheelEvent; class QPaintEvent; -class QFile; QT_END_NAMESPACE class SvgView : public QGraphicsView @@ -56,11 +55,13 @@ 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; public slots: void setHighQualityAntialiasing(bool highQualityAntialiasing); @@ -68,8 +69,8 @@ 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; -- cgit v1.2.1 From 95e0d10ddd18b15ba12886d1ec3c5c9c3e06bd55 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 14 Mar 2016 14:25:23 +0100 Subject: SVG viewer: Add export option. Add an option to export an image giving a size. This can be used for creating High DPI icons from SVG files among other things. Task-number: QTBUG-49374 Change-Id: I0437889961bc6e646667c5165584002f7ab4d952 Reviewed-by: aavit --- examples/svg/svgviewer/exportdialog.cpp | 208 ++++++++++++++++++++++++++++++++ examples/svg/svgviewer/exportdialog.h | 80 ++++++++++++ examples/svg/svgviewer/mainwindow.cpp | 63 +++++++++- examples/svg/svgviewer/mainwindow.h | 1 + examples/svg/svgviewer/svgview.cpp | 6 + examples/svg/svgviewer/svgview.h | 5 +- examples/svg/svgviewer/svgviewer.pro | 6 +- 7 files changed, 363 insertions(+), 6 deletions(-) create mode 100644 examples/svg/svgviewer/exportdialog.cpp create mode 100644 examples/svg/svgviewer/exportdialog.h 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include + +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(&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(&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 + +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/mainwindow.cpp b/examples/svg/svgviewer/mainwindow.cpp index 4e94642..c63f223 100644 --- a/examples/svg/svgviewer/mainwindow.cpp +++ b/examples/svg/svgviewer/mainwindow.cpp @@ -39,18 +39,35 @@ ****************************************************************************/ #include "mainwindow.h" +#include "exportdialog.h" #include +#include #include "svgview.h" +static inline QString picturesLocation() +{ + return QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).value(0, QDir::currentPath()); +} + MainWindow::MainWindow() : QMainWindow() , m_view(new SvgView) { + QToolBar *toolBar = new QToolBar(this); + addToolBar(Qt::TopToolBarArea, toolBar); + QMenu *fileMenu = menuBar()->addMenu(tr("&File")); - QAction *openAction = fileMenu->addAction(tr("&Open..."), this, &MainWindow::openFile); + 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); @@ -116,7 +133,7 @@ void MainWindow::openFile() fileDialog.setMimeTypeFilters(QStringList() << "image/svg+xml" << "image/svg+xml-compressed"); fileDialog.setWindowTitle(tr("Open SVG File")); if (m_currentPath.isEmpty()) - fileDialog.setDirectory(QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).value(0, QDir::currentPath())); + fileDialog.setDirectory(picturesLocation()); while (fileDialog.exec() == QDialog::Accepted && !loadFile(fileDialog.selectedFiles().constFirst())) ; @@ -126,7 +143,7 @@ bool MainWindow::loadFile(const QString &fileName) { if (!QFileInfo::exists(fileName) || !m_view->openFile(fileName)) { QMessageBox::critical(this, tr("Open SVG File"), - QString("Could not open file '%1'.").arg(QDir::toNativeSeparators(fileName))); + tr("Could not open file '%1'.").arg(QDir::toNativeSeparators(fileName))); return false; } @@ -154,3 +171,43 @@ void MainWindow::setRenderer(int renderMode) m_highQualityAntialiasingAction->setEnabled(renderMode == SvgView::OpenGL); m_view->setRenderer(static_cast(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"); + } + 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 215f4a6..c0973f9 100644 --- a/examples/svg/svgviewer/mainwindow.h +++ b/examples/svg/svgviewer/mainwindow.h @@ -64,6 +64,7 @@ public: public slots: void openFile(); + void exportImage(); void setRenderer(int renderMode); private: diff --git a/examples/svg/svgviewer/svgview.cpp b/examples/svg/svgviewer/svgview.cpp index dd9de1a..cbea85d 100644 --- a/examples/svg/svgviewer/svgview.cpp +++ b/examples/svg/svgviewer/svgview.cpp @@ -194,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 41c0ca5..645fb49 100644 --- a/examples/svg/svgviewer/svgview.h +++ b/examples/svg/svgviewer/svgview.h @@ -44,6 +44,8 @@ #include QT_BEGIN_NAMESPACE +class QGraphicsSvgItem; +class QSvgRenderer; class QWheelEvent; class QPaintEvent; QT_END_NAMESPACE @@ -62,6 +64,7 @@ public: void drawBackground(QPainter *p, const QRectF &rect) override; QSize svgSize() const; + QSvgRenderer *renderer() const; public slots: void setHighQualityAntialiasing(bool highQualityAntialiasing); @@ -75,7 +78,7 @@ protected: 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 157af4d..6eea56a 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 -- cgit v1.2.1 From 5bc9fa41817ed4707543769d5f77ee6c4a27f27f Mon Sep 17 00:00:00 2001 From: Heiko Becker Date: Sun, 20 Mar 2016 19:38:37 +0100 Subject: examples: Only deploy on wince* Otherwise heart.svg is installed two times - one time in a strange location. Change-Id: Iacd0c7342f323dd600e0539e399efe4d1d9e5665 Reviewed-by: Andreas Holzammer --- examples/svg/richtext/textobject/textobject.pro | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 +} -- cgit v1.2.1 From b722836765dccca04683939d0d4f72a9e2585d88 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 29 Feb 2016 16:24:20 +0100 Subject: Purge sRGB chunks from PNGs in documentation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subjects a *.png file that matched grep -law "sRGB" to: pngcrush -ow -brute -rem allb -reduce -force Change-Id: I457007c527201705b63e0ef758fcf597a5942895 Reviewed-by: Topi Reiniƶ --- doc/src/images/weatherinfo-demo.png | Bin 49688 -> 36807 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/doc/src/images/weatherinfo-demo.png b/doc/src/images/weatherinfo-demo.png index 3183aa4..7132b94 100644 Binary files a/doc/src/images/weatherinfo-demo.png and b/doc/src/images/weatherinfo-demo.png differ -- cgit v1.2.1 From 8c23084b207baed7cf58c17e475baa34b889ead2 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Tue, 29 Mar 2016 11:55:52 +0300 Subject: QSvgGenerator: remove unused var Change-Id: Iccc2699ace61727ae07b362442a0b87f9958e4e0 Reviewed-by: Friedemann Kleint --- src/svg/qsvggenerator.cpp | 2 -- 1 file changed, 2 deletions(-) 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()) { -- cgit v1.2.1 From efc4d3240016f285cad3a523996ad57641046c89 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 5 Apr 2016 18:30:11 +0200 Subject: purge symbian vestige Change-Id: Iad8cc499bd7b7ff973191be762858c12ca7ceef0 Reviewed-by: Lars Knoll --- tests/auto/qsvggenerator/tst_qsvggenerator.cpp | 4 ---- 1 file changed, 4 deletions(-) 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 #include -#ifdef Q_OS_SYMBIAN -#define SRCDIR "" -#endif - class tst_QSvgGenerator : public QObject { Q_OBJECT -- cgit v1.2.1