LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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 <QtCore>
31#include <QtGui>
32#include <QtPrintSupport>
33
34#include <memory>
35#include <optional>
36
37/*******************************************************************************
38 * Namespace / Forward Declarations
39 ******************************************************************************/
40namespace librepcb {
41
42/*******************************************************************************
43 * Class GraphicsPagePainter
44 ******************************************************************************/
45
57public:
75 virtual void paint(QPainter& painter,
76 const GraphicsExportSettings& settings) const noexcept = 0;
77};
78
79/*******************************************************************************
80 * Class GraphicsExport
81 ******************************************************************************/
82
89class GraphicsExport final : public QObject {
90 Q_OBJECT
91
92public:
93 // Types
94 typedef std::pair<std::shared_ptr<GraphicsPagePainter>,
95 std::shared_ptr<GraphicsExportSettings>>
97 typedef QList<Page> Pages;
98
99 struct Result {
100 QVector<FilePath> writtenFiles;
101 QString errorMsg;
102 };
103
104 // Constructors / Destructor
105 GraphicsExport(QObject* parent = nullptr) noexcept;
106 GraphicsExport(const GraphicsExport& other) = delete;
107 ~GraphicsExport() noexcept;
108
109 // General Methods
110
116 void setDocumentName(const QString& name) noexcept { mDocumentName = name; }
117
126 void startPreview(const Pages& pages) noexcept;
127
143 void startExport(const Pages& pages, const FilePath& filePath) noexcept;
144
153 void startPrint(const Pages& pages, const QString& printerName,
154 QPrinter::DuplexMode duplex, int copies) noexcept;
155
161 Result waitForFinished() noexcept;
162
166 void cancel() noexcept;
167
168 // Operator Overloadings
169 GraphicsExport& operator=(const GraphicsExport& rhs) = delete;
170
171 // Static Methods.
172
178 static QStringList getSupportedExtensions() noexcept;
179
185 static QStringList getSupportedImageExtensions() noexcept;
186
187signals:
188 void previewReady(int index, const QSize& pageSize, const QRectF margins,
189 std::shared_ptr<QPicture> picture);
190 void savingFile(const librepcb::FilePath& filePath);
191 void progress(int percent, int completed, int total);
192 void succeeded();
193 void failed(const QString& error);
194 void imageCopiedToClipboard(const QImage& image, QClipboard::Mode mode);
195
196private: // Types
197 struct RunArgs {
201 QString printerName;
202 QPrinter::DuplexMode duplex;
204 };
205
206private: // Methods
207 Result run(RunArgs args) noexcept;
208 static QTransform getSourceTransformation(
209 const GraphicsExportSettings& settings) noexcept;
210 static QRectF calcSourceRect(const GraphicsPagePainter& page,
211 const GraphicsExportSettings& settings) noexcept;
212 static QPageLayout::Orientation getOrientation(const QSizeF& size) noexcept;
213
214private: // Data
215 QString mCreator;
217 QFuture<Result> mFuture;
218 bool mAbort;
219};
220
221/*******************************************************************************
222 * End of File
223 ******************************************************************************/
224
225} // namespace librepcb
226
227#endif
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
Asynchronously exports graphics to a QPainter.
Definition graphicsexport.h:89
static QStringList getSupportedImageExtensions() noexcept
Get all supported image file extensions for startExport()
Definition graphicsexport.cpp:116
void startExport(const Pages &pages, const FilePath &filePath) noexcept
Start exporting to a file or clipboard asynchronously.
Definition graphicsexport.cpp:78
void cancel() noexcept
Cancel the current job.
Definition graphicsexport.cpp:102
static QTransform getSourceTransformation(const GraphicsExportSettings &settings) noexcept
Definition graphicsexport.cpp:423
void startPrint(const Pages &pages, const QString &printerName, QPrinter::DuplexMode duplex, int copies) noexcept
Start printing to a printer asynchronously.
Definition graphicsexport.cpp:87
bool mAbort
Definition graphicsexport.h:218
Result waitForFinished() noexcept
Wait (block) until the preview/export/print is finished.
Definition graphicsexport.cpp:97
void progress(int percent, int completed, int total)
std::pair< std::shared_ptr< GraphicsPagePainter >, std::shared_ptr< GraphicsExportSettings > > Page
Definition graphicsexport.h:96
static QRectF calcSourceRect(const GraphicsPagePainter &page, const GraphicsExportSettings &settings) noexcept
Definition graphicsexport.cpp:438
static QStringList getSupportedExtensions() noexcept
Get all supported file extensions for startExport()
Definition graphicsexport.cpp:112
void setDocumentName(const QString &name) noexcept
Set the document name used for printing, PDF and SVG export.
Definition graphicsexport.h:116
static QPageLayout::Orientation getOrientation(const QSizeF &size) noexcept
Definition graphicsexport.cpp:449
QString mCreator
Definition graphicsexport.h:215
void savingFile(const librepcb::FilePath &filePath)
QFuture< Result > mFuture
Definition graphicsexport.h:217
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:128
QString mDocumentName
Definition graphicsexport.h:216
void imageCopiedToClipboard(const QImage &image, QClipboard::Mode mode)
QList< Page > Pages
Definition graphicsexport.h:97
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:56
virtual void paint(QPainter &painter, const GraphicsExportSettings &settings) const noexcept=0
Draw page content on a QPainter.
Definition occmodel.cpp:76
Definition uuid.h:186
Definition graphicsexport.h:99
QVector< FilePath > writtenFiles
Definition graphicsexport.h:100
QString errorMsg
Definition graphicsexport.h:101
Definition graphicsexport.h:197
Pages pages
Definition graphicsexport.h:199
bool preview
Definition graphicsexport.h:198
QString printerName
Definition graphicsexport.h:201
FilePath filePath
Definition graphicsexport.h:200
int copies
Definition graphicsexport.h:203
QPrinter::DuplexMode duplex
Definition graphicsexport.h:202