LibrePCB Developers Documentation
graphicsexportdialog.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_EDITOR_GRAPHICSEXPORTDIALOG_H
21#define LIBREPCB_EDITOR_GRAPHICSEXPORTDIALOG_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
29#include <optional/tl/optional.hpp>
30
31#include <QtCore>
32#include <QtPrintSupport>
33#include <QtWidgets>
34
35#include <memory>
36
37/*******************************************************************************
38 * Namespace / Forward Declarations
39 ******************************************************************************/
40namespace librepcb {
41
42class GraphicsExport;
43class GraphicsExportSettings;
44class GraphicsPagePainter;
45class LengthUnit;
46class Theme;
47
48namespace editor {
49
50namespace Ui {
51class GraphicsExportDialog;
52}
53
54/*******************************************************************************
55 * Class GraphicsExportDialog
56 ******************************************************************************/
57
61class GraphicsExportDialog final : public QDialog {
62 Q_OBJECT
63
64 // Types
66 Load,
67 Store,
68 };
69
70 struct ContentItem {
71 QString name;
72 bool enabled;
73 bool mirror;
74 QSet<QString> colors;
75 };
76
77public:
78 // Types
79 enum class Mode {
80 Schematic,
81 Board,
82 };
83 enum class Output {
84 Image,
85 Pdf,
86 Print,
87 };
88 typedef std::function<QString(QWidget*, const QString&, const QString&,
89 const QString&, QString*, QFileDialog::Options)>
91 typedef std::pair<std::shared_ptr<GraphicsPagePainter>,
92 std::shared_ptr<GraphicsExportSettings>>
94
95 // Constructors / Destructor
98 explicit GraphicsExportDialog(
99 Mode mode, Output output,
100 const QList<std::shared_ptr<GraphicsPagePainter>>& pages, int currentPage,
101 const QString& documentName, int innerLayerCount,
102 const FilePath& defaultFilePath, const LengthUnit& lengthUnit,
103 const Theme& theme, const QString& settingsPrefix,
104 QWidget* parent = nullptr) noexcept;
105 ~GraphicsExportDialog() noexcept;
106
107 // General Methods
108 void setSaveAsCallback(SaveAsCallback callback) noexcept;
109 const QList<Page>& getPages() const noexcept { return mPages; }
110
111 // Operator Overloadings
113
114signals: // Signals
115 void requestOpenFile(const librepcb::FilePath& filePath);
116
117private: // Methods
118 void loadDefaultSettings() noexcept;
119 void syncClientSettings(ClientSettingsAction action) noexcept;
120 void buttonBoxClicked(QDialogButtonBox::StandardButton btn) noexcept;
121 void printersAvailable() noexcept;
122 void printerChanged(int index) noexcept;
123 void setAvailablePageSizes(QList<tl::optional<QPageSize>> sizes) noexcept;
124 void layerListItemDoubleClicked(QListWidgetItem* item) noexcept;
125 void applySettings() noexcept;
126 void startExport(bool toClipboard) noexcept;
127 void openProgressDialog() noexcept;
128 bool eventFilter(QObject* object, QEvent* event) noexcept override;
129
130 // GUI Access Methods
131 void setPageSize(const tl::optional<QPageSize::PageSizeId>& size) noexcept;
132 tl::optional<QPageSize> getPageSize() const noexcept;
133 void setOrientation(GraphicsExportSettings::Orientation orientation) noexcept;
134 GraphicsExportSettings::Orientation getOrientation() const noexcept;
135 void setMarginLeft(const UnsignedLength& margin) noexcept;
136 UnsignedLength getMarginLeft() const noexcept;
137 void setMarginTop(const UnsignedLength& margin) noexcept;
138 UnsignedLength getMarginTop() const noexcept;
139 void setMarginRight(const UnsignedLength& margin) noexcept;
140 UnsignedLength getMarginRight() const noexcept;
141 void setMarginBottom(const UnsignedLength& margin) noexcept;
142 UnsignedLength getMarginBottom() const noexcept;
143 void setShowPinNumbers(bool show) noexcept;
144 bool getShowPinNumbers() const noexcept;
145 void setRotate(bool rotate) noexcept;
146 bool getRotate() const noexcept;
147 void setMirror(bool mirror) noexcept;
148 bool getMirror() const noexcept;
149 void setFitToPage(bool fit) noexcept;
150 bool getFitToPage() const noexcept;
151 void setScaleFactor(const UnsignedRatio& factor) noexcept;
152 UnsignedRatio getScaleFactor() const noexcept;
153 void setDpi(int dpi) noexcept;
154 int getDpi() const noexcept;
155 void setBlackWhite(bool blackWhite) noexcept;
156 bool getBlackWhite() const noexcept;
157 void setBackgroundColor(const QColor& color) noexcept;
158 QColor getBackgroundColor() const noexcept;
159 void setMinLineWidth(const UnsignedLength& width) noexcept;
160 UnsignedLength getMinLineWidth() const noexcept;
161 void setPrinterName(const QString& name) noexcept;
162 QString getPrinterName() const noexcept;
163 void setDuplex(QPrinter::DuplexMode duplex) noexcept;
164 QPrinter::DuplexMode getDuplex() const noexcept;
165 void setPageContent(const QList<ContentItem>& items) noexcept;
166 const QList<ContentItem>& getPageContent() const noexcept;
167 void setOpenExportedFiles(bool open) noexcept;
168 bool getOpenExportedFiles() const noexcept;
169 void updateColorsListWidget() noexcept;
170
171private: // Data
172 const Mode mMode;
174 const QList<std::shared_ptr<GraphicsPagePainter>> mInputPages;
175 const int mCurrentPage; // Note: Might be out of range!
177 const Theme& mTheme;
178 const QString mSettingsPrefix;
179 SaveAsCallback mSaveAsCallback; // Guaranteed to be not null.
180
182 QList<std::pair<QString, QColor>> mColors;
183
185 tl::optional<QPageSize::PageSizeId> mSettingsPageSize;
186 QPrinter::DuplexMode mSettingsDuplexMode;
187
189 QScopedPointer<Ui::GraphicsExportDialog> mUi;
190 QScopedPointer<QProgressDialog> mProgressDialog;
191
192 QScopedPointer<QFutureWatcher<QList<QPrinterInfo>>> mPrinterWatcher;
193 QList<QPrinterInfo> mAvailablePrinters;
194 QList<tl::optional<QPageSize>> mAvailablePageSizes;
196 QList<Page> mPages;
197
198 QScopedPointer<GraphicsExport> mPreview;
199 QScopedPointer<GraphicsExport> mExport;
201};
202
203/*******************************************************************************
204 * End of File
205 ******************************************************************************/
206
207} // namespace editor
208} // namespace librepcb
209
210#endif
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:73
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
Settings for librepcb::GraphicsExport.
Definition: graphicsexportsettings.h:51
Base class for printing a page for librepcb::GraphicsExport.
Definition: graphicsexport.h:57
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition: lengthunit.h:60
The Schematic class represents one schematic page of a project and is always part of a circuit.
Definition: schematic.h:74
Theme class as used by librepcb::WorkspaceSettingsItem_Themes.
Definition: theme.h:44
This class provides a Dialog (GUI) to choose DXF import settings.
Definition: graphicsexportdialog.h:61
QPrinter::DuplexMode mSettingsDuplexMode
Definition: graphicsexportdialog.h:186
int getDpi() const noexcept
Definition: graphicsexportdialog.cpp:1332
FilePath mPathToOpenAfterExport
Definition: graphicsexportdialog.h:200
void setOpenExportedFiles(bool open) noexcept
Definition: graphicsexportdialog.cpp:1439
const QList< ContentItem > & getPageContent() const noexcept
Definition: graphicsexportdialog.cpp:1435
GraphicsExportDialog(const GraphicsExportDialog &other)=delete
const QList< Page > & getPages() const noexcept
Definition: graphicsexportdialog.h:109
void startExport(bool toClipboard) noexcept
Definition: graphicsexportdialog.cpp:1125
void setOrientation(GraphicsExportSettings::Orientation orientation) noexcept
Definition: graphicsexportdialog.cpp:1230
const Output mOutput
Definition: graphicsexportdialog.h:173
void printerChanged(int index) noexcept
Definition: graphicsexportdialog.cpp:921
QScopedPointer< GraphicsExport > mPreview
Definition: graphicsexportdialog.h:198
void setMinLineWidth(const UnsignedLength &width) noexcept
Definition: graphicsexportdialog.cpp:1364
bool getBlackWhite() const noexcept
Definition: graphicsexportdialog.cpp:1340
const Theme & mTheme
Definition: graphicsexportdialog.h:177
bool getRotate() const noexcept
Definition: graphicsexportdialog.cpp:1299
void setMirror(bool mirror) noexcept
Definition: graphicsexportdialog.cpp:1303
void setMarginLeft(const UnsignedLength &margin) noexcept
Definition: graphicsexportdialog.cpp:1252
QScopedPointer< QProgressDialog > mProgressDialog
Definition: graphicsexportdialog.h:190
void setDuplex(QPrinter::DuplexMode duplex) noexcept
Definition: graphicsexportdialog.cpp:1387
void setBackgroundColor(const QColor &color) noexcept
Definition: graphicsexportdialog.cpp:1344
QList< QPrinterInfo > mAvailablePrinters
Definition: graphicsexportdialog.h:193
const int mCurrentPage
Definition: graphicsexportdialog.h:175
QString getPrinterName() const noexcept
Definition: graphicsexportdialog.cpp:1382
tl::optional< QPageSize::PageSizeId > mSettingsPageSize
Definition: graphicsexportdialog.h:185
void setSaveAsCallback(SaveAsCallback callback) noexcept
Definition: graphicsexportdialog.cpp:457
Mode
Definition: graphicsexportdialog.h:79
void setShowPinNumbers(bool show) noexcept
Definition: graphicsexportdialog.cpp:1287
void setPrinterName(const QString &name) noexcept
Definition: graphicsexportdialog.cpp:1373
QScopedPointer< GraphicsExport > mExport
Definition: graphicsexportdialog.h:199
bool getMirror() const noexcept
Definition: graphicsexportdialog.cpp:1307
const FilePath mDefaultFilePath
Definition: graphicsexportdialog.h:176
void setScaleFactor(const UnsignedRatio &factor) noexcept
Definition: graphicsexportdialog.cpp:1319
Output
Definition: graphicsexportdialog.h:83
UnsignedRatio getScaleFactor() const noexcept
Definition: graphicsexportdialog.cpp:1324
void setPageContent(const QList< ContentItem > &items) noexcept
Definition: graphicsexportdialog.cpp:1410
void printersAvailable() noexcept
Definition: graphicsexportdialog.cpp:886
void applySettings() noexcept
Definition: graphicsexportdialog.cpp:995
bool getShowPinNumbers() const noexcept
Definition: graphicsexportdialog.cpp:1291
void layerListItemDoubleClicked(QListWidgetItem *item) noexcept
Definition: graphicsexportdialog.cpp:984
UnsignedLength getMarginBottom() const noexcept
Definition: graphicsexportdialog.cpp:1283
bool getOpenExportedFiles() const noexcept
Definition: graphicsexportdialog.cpp:1443
void syncClientSettings(ClientSettingsAction action) noexcept
Definition: graphicsexportdialog.cpp:584
const QString mSettingsPrefix
Definition: graphicsexportdialog.h:178
std::pair< std::shared_ptr< GraphicsPagePainter >, std::shared_ptr< GraphicsExportSettings > > Page
Definition: graphicsexportdialog.h:93
void loadDefaultSettings() noexcept
Definition: graphicsexportdialog.cpp:466
void setMarginTop(const UnsignedLength &margin) noexcept
Definition: graphicsexportdialog.cpp:1261
void openProgressDialog() noexcept
Definition: graphicsexportdialog.cpp:1190
GraphicsExportDialog & operator=(const GraphicsExportDialog &rhs)=delete
void setRotate(bool rotate) noexcept
Definition: graphicsexportdialog.cpp:1295
const QList< std::shared_ptr< GraphicsPagePainter > > mInputPages
Definition: graphicsexportdialog.h:174
QList< Page > mPages
Definition: graphicsexportdialog.h:196
void setFitToPage(bool fit) noexcept
Definition: graphicsexportdialog.cpp:1311
QList< tl::optional< QPageSize > > mAvailablePageSizes
Definition: graphicsexportdialog.h:194
QList< std::pair< QString, QColor > > mColors
Definition: graphicsexportdialog.h:182
void setAvailablePageSizes(QList< tl::optional< QPageSize > > sizes) noexcept
Definition: graphicsexportdialog.cpp:958
QPrinter::DuplexMode getDuplex() const noexcept
Definition: graphicsexportdialog.cpp:1396
void setPageSize(const tl::optional< QPageSize::PageSizeId > &size) noexcept
Definition: graphicsexportdialog.cpp:1215
UnsignedLength getMarginLeft() const noexcept
Definition: graphicsexportdialog.cpp:1257
bool getFitToPage() const noexcept
Definition: graphicsexportdialog.cpp:1315
tl::optional< QPageSize > getPageSize() const noexcept
Definition: graphicsexportdialog.cpp:1226
QScopedPointer< GraphicsExportSettings > mDefaultSettings
Definition: graphicsexportdialog.h:181
void setMarginBottom(const UnsignedLength &margin) noexcept
Definition: graphicsexportdialog.cpp:1278
GraphicsExportSettings::Orientation getOrientation() const noexcept
Definition: graphicsexportdialog.cpp:1241
std::function< QString(QWidget *, const QString &, const QString &, const QString &, QString *, QFileDialog::Options)> SaveAsCallback
Definition: graphicsexportdialog.h:90
void setBlackWhite(bool blackWhite) noexcept
Definition: graphicsexportdialog.cpp:1336
SaveAsCallback mSaveAsCallback
Definition: graphicsexportdialog.h:179
ClientSettingsAction
Definition: graphicsexportdialog.h:65
UnsignedLength getMarginRight() const noexcept
Definition: graphicsexportdialog.cpp:1274
const Mode mMode
Definition: graphicsexportdialog.h:172
void updateColorsListWidget() noexcept
Definition: graphicsexportdialog.cpp:1447
void setDpi(int dpi) noexcept
Definition: graphicsexportdialog.cpp:1328
void requestOpenFile(const librepcb::FilePath &filePath)
QScopedPointer< QFutureWatcher< QList< QPrinterInfo > > > mPrinterWatcher
Definition: graphicsexportdialog.h:192
QList< ContentItem > mPageContentItems
Definition: graphicsexportdialog.h:195
bool mDisableApplySettings
Definition: graphicsexportdialog.h:188
void setMarginRight(const UnsignedLength &margin) noexcept
Definition: graphicsexportdialog.cpp:1269
UnsignedLength getMinLineWidth() const noexcept
Definition: graphicsexportdialog.cpp:1369
QColor getBackgroundColor() const noexcept
Definition: graphicsexportdialog.cpp:1354
UnsignedLength getMarginTop() const noexcept
Definition: graphicsexportdialog.cpp:1265
QScopedPointer< Ui::GraphicsExportDialog > mUi
Definition: graphicsexportdialog.h:189
QString mSettingsPrinterName
Definition: graphicsexportdialog.h:184
void buttonBoxClicked(QDialogButtonBox::StandardButton btn) noexcept
Definition: graphicsexportdialog.cpp:858
bool eventFilter(QObject *object, QEvent *event) noexcept override
Definition: graphicsexportdialog.cpp:1194
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
type_safe::constrained_type< Ratio, UnsignedRatioConstraint, UnsignedRatioVerifier > UnsignedRatio
Definition: ratio.h:330
Definition: uuid.h:183
Definition: graphicsexportdialog.h:70
bool mirror
Definition: graphicsexportdialog.h:73
QSet< QString > colors
Definition: graphicsexportdialog.h:74
bool enabled
Definition: graphicsexportdialog.h:72
QString name
Definition: graphicsexportdialog.h:71