/usr/share/qt5/doc/qtsvg/qtsvg-svgviewer-mainwindow-cpp.html is in qtsvg5-doc-html 5.9.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mainwindow.cpp Example File | Qt SVG 5.9</title>
<link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
<script type="text/javascript">
document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
// loading style sheet breaks anchors that were jumped to before
// so force jumping to anchor again
setTimeout(function() {
var anchor = location.hash;
// need to jump to different anchor first (e.g. none)
location.hash = "#";
setTimeout(function() {
location.hash = anchor;
}, 0);
}, 0);
</script>
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<table><tr>
<td >Qt 5.9</td><td ><a href="qtsvg-index.html">Qt SVG</a></td><td ><a href="qtsvg-svgviewer-example.html">SVG Viewer Example</a></td><td >mainwindow.cpp Example File</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.5 Reference Documentation</td>
</tr></table>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">mainwindow.cpp Example File</h1>
<span class="subtitle">svgviewer/mainwindow.cpp</span>
<!-- $$$svgviewer/mainwindow.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">
<span class="comment">/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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$
**
****************************************************************************/</span>
<span class="preprocessor">#include "mainwindow.h"</span>
<span class="preprocessor">#include "exportdialog.h"</span>
<span class="preprocessor">#include <QtWidgets></span>
<span class="preprocessor">#include <QSvgRenderer></span>
<span class="preprocessor">#include "svgview.h"</span>
<span class="keyword">static</span> <span class="keyword">inline</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> picturesLocation()
{
<span class="keyword">return</span> <span class="type"><a href="../qtcore/qstandardpaths.html">QStandardPaths</a></span><span class="operator">::</span>standardLocations(<span class="type"><a href="../qtcore/qstandardpaths.html">QStandardPaths</a></span><span class="operator">::</span>PicturesLocation)<span class="operator">.</span>value(<span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>currentPath());
}
MainWindow<span class="operator">::</span>MainWindow()
: <span class="type"><a href="../qtwidgets/qmainwindow.html">QMainWindow</a></span>()
<span class="operator">,</span> m_view(<span class="keyword">new</span> SvgView)
{
<span class="type"><a href="../qtwidgets/qtoolbar.html">QToolBar</a></span> <span class="operator">*</span>toolBar <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtwidgets/qtoolbar.html">QToolBar</a></span>(<span class="keyword">this</span>);
addToolBar(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>TopToolBarArea<span class="operator">,</span> toolBar);
<span class="type"><a href="../qtwidgets/qmenu.html">QMenu</a></span> <span class="operator">*</span>fileMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">></span>addMenu(tr(<span class="string">"&File"</span>));
<span class="keyword">const</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span> openIcon <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>fromTheme(<span class="string">"document-open"</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span>(<span class="string">":/qt-project.org/styles/commonstyle/images/standardbutton-open-32.png"</span>));
<span class="type"><a href="../qtwidgets/qaction.html">QAction</a></span> <span class="operator">*</span>openAction <span class="operator">=</span> fileMenu<span class="operator">-</span><span class="operator">></span>addAction(openIcon<span class="operator">,</span> tr(<span class="string">"&Open..."</span>)<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>MainWindow<span class="operator">::</span>openFile);
openAction<span class="operator">-</span><span class="operator">></span>setShortcut(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>Open);
toolBar<span class="operator">-</span><span class="operator">></span>addAction(openAction);
<span class="keyword">const</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span> exportIcon <span class="operator">=</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span><span class="operator">::</span>fromTheme(<span class="string">"document-save"</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qicon.html">QIcon</a></span>(<span class="string">":/qt-project.org/styles/commonstyle/images/standardbutton-save-32.png"</span>));
<span class="type"><a href="../qtwidgets/qaction.html">QAction</a></span> <span class="operator">*</span>exportAction <span class="operator">=</span> fileMenu<span class="operator">-</span><span class="operator">></span>addAction(exportIcon<span class="operator">,</span> tr(<span class="string">"&Export..."</span>)<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>MainWindow<span class="operator">::</span>exportImage);
exportAction<span class="operator">-</span><span class="operator">></span>setToolTip(tr(<span class="string">"Export Image"</span>));
exportAction<span class="operator">-</span><span class="operator">></span>setShortcut(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>CTRL <span class="operator">+</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_E);
toolBar<span class="operator">-</span><span class="operator">></span>addAction(exportAction);
<span class="type"><a href="../qtwidgets/qaction.html">QAction</a></span> <span class="operator">*</span>quitAction <span class="operator">=</span> fileMenu<span class="operator">-</span><span class="operator">></span>addAction(tr(<span class="string">"E&xit"</span>)<span class="operator">,</span> qApp<span class="operator">,</span> <span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>quit);
quitAction<span class="operator">-</span><span class="operator">></span>setShortcuts(<span class="type"><a href="../qtgui/qkeysequence.html">QKeySequence</a></span><span class="operator">::</span>Quit);
<span class="type"><a href="../qtwidgets/qmenu.html">QMenu</a></span> <span class="operator">*</span>viewMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">></span>addMenu(tr(<span class="string">"&View"</span>));
m_backgroundAction <span class="operator">=</span> viewMenu<span class="operator">-</span><span class="operator">></span>addAction(tr(<span class="string">"&Background"</span>));
m_backgroundAction<span class="operator">-</span><span class="operator">></span>setEnabled(<span class="keyword">false</span>);
m_backgroundAction<span class="operator">-</span><span class="operator">></span>setCheckable(<span class="keyword">true</span>);
m_backgroundAction<span class="operator">-</span><span class="operator">></span>setChecked(<span class="keyword">false</span>);
connect(m_backgroundAction<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="../qtwidgets/qaction.html">QAction</a></span><span class="operator">::</span>toggled<span class="operator">,</span> m_view<span class="operator">,</span> <span class="operator">&</span>SvgView<span class="operator">::</span>setViewBackground);
m_outlineAction <span class="operator">=</span> viewMenu<span class="operator">-</span><span class="operator">></span>addAction(tr(<span class="string">"&Outline"</span>));
m_outlineAction<span class="operator">-</span><span class="operator">></span>setEnabled(<span class="keyword">false</span>);
m_outlineAction<span class="operator">-</span><span class="operator">></span>setCheckable(<span class="keyword">true</span>);
m_outlineAction<span class="operator">-</span><span class="operator">></span>setChecked(<span class="keyword">true</span>);
connect(m_outlineAction<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="../qtwidgets/qaction.html">QAction</a></span><span class="operator">::</span>toggled<span class="operator">,</span> m_view<span class="operator">,</span> <span class="operator">&</span>SvgView<span class="operator">::</span>setViewOutline);
<span class="type"><a href="../qtwidgets/qmenu.html">QMenu</a></span> <span class="operator">*</span>rendererMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">></span>addMenu(tr(<span class="string">"&Renderer"</span>));
m_nativeAction <span class="operator">=</span> rendererMenu<span class="operator">-</span><span class="operator">></span>addAction(tr(<span class="string">"&Native"</span>));
m_nativeAction<span class="operator">-</span><span class="operator">></span>setCheckable(<span class="keyword">true</span>);
m_nativeAction<span class="operator">-</span><span class="operator">></span>setChecked(<span class="keyword">true</span>);
m_nativeAction<span class="operator">-</span><span class="operator">></span>setData(<span class="type">int</span>(SvgView<span class="operator">::</span>Native));
<span class="preprocessor">#ifndef QT_NO_OPENGL</span>
m_glAction <span class="operator">=</span> rendererMenu<span class="operator">-</span><span class="operator">></span>addAction(tr(<span class="string">"&OpenGL"</span>));
m_glAction<span class="operator">-</span><span class="operator">></span>setCheckable(<span class="keyword">true</span>);
m_glAction<span class="operator">-</span><span class="operator">></span>setData(<span class="type">int</span>(SvgView<span class="operator">::</span>OpenGL));
<span class="preprocessor">#endif</span>
m_imageAction <span class="operator">=</span> rendererMenu<span class="operator">-</span><span class="operator">></span>addAction(tr(<span class="string">"&Image"</span>));
m_imageAction<span class="operator">-</span><span class="operator">></span>setCheckable(<span class="keyword">true</span>);
m_imageAction<span class="operator">-</span><span class="operator">></span>setData(<span class="type">int</span>(SvgView<span class="operator">::</span>Image));
rendererMenu<span class="operator">-</span><span class="operator">></span>addSeparator();
m_highQualityAntialiasingAction <span class="operator">=</span> rendererMenu<span class="operator">-</span><span class="operator">></span>addAction(tr(<span class="string">"&High Quality Antialiasing"</span>));
m_highQualityAntialiasingAction<span class="operator">-</span><span class="operator">></span>setEnabled(<span class="keyword">false</span>);
m_highQualityAntialiasingAction<span class="operator">-</span><span class="operator">></span>setCheckable(<span class="keyword">true</span>);
m_highQualityAntialiasingAction<span class="operator">-</span><span class="operator">></span>setChecked(<span class="keyword">false</span>);
connect(m_highQualityAntialiasingAction<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="../qtwidgets/qaction.html">QAction</a></span><span class="operator">::</span>toggled<span class="operator">,</span> m_view<span class="operator">,</span> <span class="operator">&</span>SvgView<span class="operator">::</span>setHighQualityAntialiasing);
<span class="preprocessor">#ifdef QT_NO_OPENGL</span>
m_highQualityAntialiasingAction<span class="operator">-</span><span class="operator">></span>setVisible(<span class="keyword">false</span>);
<span class="preprocessor">#endif</span>
<span class="type"><a href="../qtwidgets/qactiongroup.html">QActionGroup</a></span> <span class="operator">*</span>rendererGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtwidgets/qactiongroup.html">QActionGroup</a></span>(<span class="keyword">this</span>);
rendererGroup<span class="operator">-</span><span class="operator">></span>addAction(m_nativeAction);
<span class="preprocessor">#ifndef QT_NO_OPENGL</span>
rendererGroup<span class="operator">-</span><span class="operator">></span>addAction(m_glAction);
<span class="preprocessor">#endif</span>
rendererGroup<span class="operator">-</span><span class="operator">></span>addAction(m_imageAction);
menuBar()<span class="operator">-</span><span class="operator">></span>addMenu(rendererMenu);
connect(rendererGroup<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="../qtwidgets/qactiongroup.html">QActionGroup</a></span><span class="operator">::</span>triggered<span class="operator">,</span>
<span class="operator">[</span><span class="keyword">this</span><span class="operator">]</span> (<span class="type"><a href="../qtwidgets/qaction.html">QAction</a></span> <span class="operator">*</span>a) { setRenderer(a<span class="operator">-</span><span class="operator">></span>data()<span class="operator">.</span>toInt()); });
<span class="type"><a href="../qtwidgets/qmenu.html">QMenu</a></span> <span class="operator">*</span>help <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">></span>addMenu(tr(<span class="string">"&Help"</span>));
help<span class="operator">-</span><span class="operator">></span>addAction(tr(<span class="string">"About Qt"</span>)<span class="operator">,</span> qApp<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="../qtwidgets/qapplication.html">QApplication</a></span><span class="operator">::</span>aboutQt);
setCentralWidget(m_view);
}
<span class="type">void</span> MainWindow<span class="operator">::</span>openFile()
{
<span class="type"><a href="../qtwidgets/qfiledialog.html">QFileDialog</a></span> fileDialog(<span class="keyword">this</span>);
fileDialog<span class="operator">.</span>setAcceptMode(<span class="type"><a href="../qtwidgets/qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>AcceptOpen);
fileDialog<span class="operator">.</span>setMimeTypeFilters(<span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span>() <span class="operator"><</span><span class="operator"><</span> <span class="string">"image/svg+xml"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"image/svg+xml-compressed"</span>);
fileDialog<span class="operator">.</span>setWindowTitle(tr(<span class="string">"Open SVG File"</span>));
<span class="keyword">if</span> (m_currentPath<span class="operator">.</span>isEmpty())
fileDialog<span class="operator">.</span>setDirectory(picturesLocation());
<span class="keyword">while</span> (fileDialog<span class="operator">.</span>exec() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="../qtwidgets/qdialog.html">QDialog</a></span><span class="operator">::</span>Accepted <span class="operator">&</span><span class="operator">&</span> <span class="operator">!</span>loadFile(fileDialog<span class="operator">.</span>selectedFiles()<span class="operator">.</span>constFirst()))
;
}
bool MainWindow<span class="operator">::</span>loadFile(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&</span>fileName)
{
<span class="keyword">if</span> (<span class="operator">!</span><span class="type"><a href="../qtcore/qfileinfo.html">QFileInfo</a></span><span class="operator">::</span>exists(fileName) <span class="operator">|</span><span class="operator">|</span> <span class="operator">!</span>m_view<span class="operator">-</span><span class="operator">></span>openFile(fileName)) {
<span class="type"><a href="../qtwidgets/qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>critical(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"Open SVG File"</span>)<span class="operator">,</span>
tr(<span class="string">"Could not open file '%1'."</span>)<span class="operator">.</span>arg(<span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>toNativeSeparators(fileName)));
<span class="keyword">return</span> <span class="keyword">false</span>;
}
<span class="keyword">if</span> (<span class="operator">!</span>fileName<span class="operator">.</span>startsWith(<span class="string">":/"</span>)) {
m_currentPath <span class="operator">=</span> fileName;
setWindowFilePath(fileName);
<span class="keyword">const</span> <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> size <span class="operator">=</span> m_view<span class="operator">-</span><span class="operator">></span>svgSize();
<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> message <span class="operator">=</span>
tr(<span class="string">"Opened %1, %2x%3"</span>)<span class="operator">.</span>arg(<span class="type"><a href="../qtcore/qfileinfo.html">QFileInfo</a></span>(fileName)<span class="operator">.</span>fileName())<span class="operator">.</span>arg(size<span class="operator">.</span>width())<span class="operator">.</span>arg(size<span class="operator">.</span>width());
statusBar()<span class="operator">-</span><span class="operator">></span>showMessage(message);
}
m_outlineAction<span class="operator">-</span><span class="operator">></span>setEnabled(<span class="keyword">true</span>);
m_backgroundAction<span class="operator">-</span><span class="operator">></span>setEnabled(<span class="keyword">true</span>);
<span class="keyword">const</span> <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> availableSize <span class="operator">=</span> <span class="type"><a href="../qtwidgets/qapplication.html">QApplication</a></span><span class="operator">::</span>desktop()<span class="operator">-</span><span class="operator">></span>availableGeometry(<span class="keyword">this</span>)<span class="operator">.</span>size();
resize(m_view<span class="operator">-</span><span class="operator">></span>sizeHint()<span class="operator">.</span>expandedTo(availableSize <span class="operator">/</span> <span class="number">4</span>) <span class="operator">+</span> <span class="type"><a href="../qtcore/qsize.html">QSize</a></span>(<span class="number">80</span><span class="operator">,</span> <span class="number">80</span> <span class="operator">+</span> menuBar()<span class="operator">-</span><span class="operator">></span>height()));
<span class="keyword">return</span> <span class="keyword">true</span>;
}
<span class="type">void</span> MainWindow<span class="operator">::</span>setRenderer(<span class="type">int</span> renderMode)
{
m_highQualityAntialiasingAction<span class="operator">-</span><span class="operator">></span>setEnabled(renderMode <span class="operator">=</span><span class="operator">=</span> SvgView<span class="operator">::</span>OpenGL);
m_view<span class="operator">-</span><span class="operator">></span>setRenderer(<span class="keyword">static_cast</span><span class="operator"><</span>SvgView<span class="operator">::</span>RendererType<span class="operator">></span>(renderMode));
}
<span class="type">void</span> MainWindow<span class="operator">::</span>exportImage()
{
ExportDialog exportDialog(<span class="keyword">this</span>);
exportDialog<span class="operator">.</span>setExportSize(m_view<span class="operator">-</span><span class="operator">></span>svgSize());
<span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileName;
<span class="keyword">if</span> (m_currentPath<span class="operator">.</span>isEmpty()) {
fileName <span class="operator">=</span> picturesLocation() <span class="operator">+</span> QLatin1String(<span class="string">"/export.png"</span>);
} <span class="keyword">else</span> {
<span class="keyword">const</span> <span class="type"><a href="../qtcore/qfileinfo.html">QFileInfo</a></span> fi(m_currentPath);
fileName <span class="operator">=</span> fi<span class="operator">.</span>absolutePath() <span class="operator">+</span> QLatin1Char(<span class="char">'/'</span>) <span class="operator">+</span> fi<span class="operator">.</span>baseName() <span class="operator">+</span> QLatin1String(<span class="string">".png"</span>);
}
exportDialog<span class="operator">.</span>setExportFileName(fileName);
<span class="keyword">while</span> (<span class="keyword">true</span>) {
<span class="keyword">if</span> (exportDialog<span class="operator">.</span>exec() <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="../qtwidgets/qdialog.html">QDialog</a></span><span class="operator">::</span>Accepted)
<span class="keyword">break</span>;
<span class="keyword">const</span> <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> imageSize <span class="operator">=</span> exportDialog<span class="operator">.</span>exportSize();
<span class="type"><a href="../qtgui/qimage.html">QImage</a></span> image(imageSize<span class="operator">,</span> <span class="type"><a href="../qtgui/qimage.html">QImage</a></span><span class="operator">::</span>Format_ARGB32);
image<span class="operator">.</span>fill(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>transparent);
<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> painter;
painter<span class="operator">.</span>begin(<span class="operator">&</span>image);
m_view<span class="operator">-</span><span class="operator">></span>renderer()<span class="operator">-</span><span class="operator">></span>render(<span class="operator">&</span>painter<span class="operator">,</span> <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span>(<span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>()<span class="operator">,</span> <span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span>(imageSize)));
painter<span class="operator">.</span>end();
<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileName <span class="operator">=</span> exportDialog<span class="operator">.</span>exportFileName();
<span class="keyword">if</span> (image<span class="operator">.</span>save(fileName)) {
<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> message <span class="operator">=</span> tr(<span class="string">"Exported %1, %2x%3, %4 bytes"</span>)
<span class="operator">.</span>arg(<span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>toNativeSeparators(fileName))<span class="operator">.</span>arg(imageSize<span class="operator">.</span>width())<span class="operator">.</span>arg(imageSize<span class="operator">.</span>height())
<span class="operator">.</span>arg(<span class="type"><a href="../qtcore/qfileinfo.html">QFileInfo</a></span>(fileName)<span class="operator">.</span>size());
statusBar()<span class="operator">-</span><span class="operator">></span>showMessage(message);
<span class="keyword">break</span>;
} <span class="keyword">else</span> {
<span class="type"><a href="../qtwidgets/qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>critical(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"Export Image"</span>)<span class="operator">,</span>
tr(<span class="string">"Could not write file '%1'."</span>)<span class="operator">.</span>arg(<span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>toNativeSeparators(fileName)));
}
}
}
</pre>
</div>
<!-- @@@svgviewer/mainwindow.cpp -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2017 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|