LibrePCB Developers Documentation
graphicsexport.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_GRAPHICSEXPORT_H
21#define LIBREPCB_CORE_GRAPHICSEXPORT_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../fileio/filepath.h"
27#include "../types/length.h"
29
30#include <optional/tl/optional.hpp>
31
32#include <QtCore>
33#include <QtGui>
34#include <QtPrintSupport>
35
36#include <memory>
37
38/*******************************************************************************
39 * Namespace / Forward Declarations
40 ******************************************************************************/
41namespace librepcb {
42
43/*******************************************************************************
44 * Class GraphicsPagePainter
45 ******************************************************************************/
46
58public:
76 virtual void paint(QPainter& painter,
77 const GraphicsExportSettings& settings) const noexcept = 0;
78};
79
80/*******************************************************************************
81 * Class GraphicsExport
82 ******************************************************************************/
83
90class GraphicsExport final : public QObject {
91 Q_OBJECT
92
93public:
94 // Types
95 typedef std::pair<std::shared_ptr<GraphicsPagePainter>,
96 std::shared_ptr<GraphicsExportSettings>>
98 typedef QList<Page> Pages;
99
100 struct Result {
101 QVector<FilePath> writtenFiles;
102 QString errorMsg;
103 };
104
105 // Constructors / Destructor
106 GraphicsExport(QObject* parent = nullptr) noexcept;
107 GraphicsExport(const GraphicsExport& other) = delete;
108 ~GraphicsExport() noexcept;
109
110 // General Methods
111
117 void setDocumentName(const QString& name) noexcept { mDocumentName = name; }
118
127 void startPreview(const Pages& pages) noexcept;
128
144 void startExport(const Pages& pages, const FilePath& filePath) noexcept;
145
154 void startPrint(const Pages& pages, const QString& printerName,
155 QPrinter::DuplexMode duplex, int copies) noexcept;
156
162 Result waitForFinished() noexcept;
163
167 void cancel() noexcept;
168
169 // Operator Overloadings
170 GraphicsExport& operator=(const GraphicsExport& rhs) = delete;
171
172 // Static Methods.
173
179 static QStringList getSupportedExtensions() noexcept;
180
186 static QStringList getSupportedImageExtensions() noexcept;
187
188signals:
189 void previewReady(int index, const QSize& pageSize, const QRectF margins,
190 std::shared_ptr<QPicture> picture);
191 void savingFile(const librepcb::FilePath& filePath);
192 void progress(int percent, int completed, int total);
193 void succeeded();
194 void failed(const QString& error);
195 void imageCopiedToClipboard(const QImage& image, QClipboard::Mode mode);
196
197private: // Types
198 struct RunArgs {
202 QString printerName;
203 QPrinter::DuplexMode duplex;
205 };
206
207private: // Methods
208 Result run(RunArgs args) noexcept;
209 static QTransform getSourceTransformation(
210 const GraphicsExportSettings& settings) noexcept;
211 static QRectF calcSourceRect(const GraphicsPagePainter& page,
212 const GraphicsExportSettings& settings) noexcept;
213 static QPageLayout::Orientation getOrientation(const QSizeF& size) noexcept;
214
215private: // Data
216 QString mCreator;
218 QFuture<Result> mFuture;
219 bool mAbort;
220};
221
222/*******************************************************************************
223 * End of File
224 ******************************************************************************/
225
226} // namespace librepcb
227
228#endif
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
Asynchronously exports graphics to a QPainter.
Definition: graphicsexport.h:90
static QStringList getSupportedImageExtensions() noexcept
Get all supported image file extensions for startExport()
Definition: graphicsexport.cpp:128
void startExport(const Pages &pages, const FilePath &filePath) noexcept
Start exporting to a file or clipboard asynchronously.
Definition: graphicsexport.cpp:82
void cancel() noexcept
Cancel the current job.
Definition: graphicsexport.cpp:114
static QTransform getSourceTransformation(const GraphicsExportSettings &settings) noexcept
Definition: graphicsexport.cpp:435
void startPrint(const Pages &pages, const QString &printerName, QPrinter::DuplexMode duplex, int copies) noexcept
Start printing to a printer asynchronously.
Definition: graphicsexport.cpp:95
bool mAbort
Definition: graphicsexport.h:219
Result waitForFinished() noexcept
Wait (block) until the preview/export/print is finished.
Definition: graphicsexport.cpp:109
void progress(int percent, int completed, int total)
std::pair< std::shared_ptr< GraphicsPagePainter >, std::shared_ptr< GraphicsExportSettings > > Page
Definition: graphicsexport.h:97
static QRectF calcSourceRect(const GraphicsPagePainter &page, const GraphicsExportSettings &settings) noexcept
Definition: graphicsexport.cpp:450
static QStringList getSupportedExtensions() noexcept
Get all supported file extensions for startExport()
Definition: graphicsexport.cpp:124
void setDocumentName(const QString &name) noexcept
Set the document name used for printing, PDF and SVG export.
Definition: graphicsexport.h:117
GraphicsExport(QObject *parent=nullptr) noexcept
Definition: graphicsexport.cpp:52
static QPageLayout::Orientation getOrientation(const QSizeF &size) noexcept
Definition: graphicsexport.cpp:461
QString mCreator
Definition: graphicsexport.h:216
void savingFile(const librepcb::FilePath &filePath)
QFuture< Result > mFuture
Definition: graphicsexport.h:218
void previewReady(int index, const QSize &pageSize, const QRectF margins, std::shared_ptr< QPicture > picture)
void startPreview(const Pages &pages) noexcept
Start creating previews asynchronously.
Definition: graphicsexport.cpp:70
Result run(RunArgs args) noexcept
Definition: graphicsexport.cpp:140
QString mDocumentName
Definition: graphicsexport.h:217
void imageCopiedToClipboard(const QImage &image, QClipboard::Mode mode)
QList< Page > Pages
Definition: graphicsexport.h:98
void failed(const QString &error)
Settings for librepcb::GraphicsExport.
Definition: graphicsexportsettings.h:51
Base class for printing a page for librepcb::GraphicsExport.
Definition: graphicsexport.h:57
virtual void paint(QPainter &painter, const GraphicsExportSettings &settings) const noexcept=0
Draw page content on a QPainter.
Definition: occmodel.cpp:77
Definition: graphicsexport.h:100
QVector< FilePath > writtenFiles
Definition: graphicsexport.h:101
QString errorMsg
Definition: graphicsexport.h:102
Definition: graphicsexport.h:198
Pages pages
Definition: graphicsexport.h:200
bool preview
Definition: graphicsexport.h:199
QString printerName
Definition: graphicsexport.h:202
FilePath filePath
Definition: graphicsexport.h:201
int copies
Definition: graphicsexport.h:204
QPrinter::DuplexMode duplex
Definition: graphicsexport.h:203