LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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
30#include <QtCore>
31#include <QtPrintSupport>
32#include <QtWidgets>
33
34#include <memory>
35#include <optional>
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<std::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 std::optional<QPageSize::PageSizeId>& size) noexcept;
132 std::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 std::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<std::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
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
Settings for librepcb::GraphicsExport.
Definition graphicsexportsettings.h:51
Base class for printing a page for librepcb::GraphicsExport.
Definition graphicsexport.h:56
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition lengthunit.h:60
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:1329
FilePath mPathToOpenAfterExport
Definition graphicsexportdialog.h:200
void setOpenExportedFiles(bool open) noexcept
Definition graphicsexportdialog.cpp:1436
const QList< ContentItem > & getPageContent() const noexcept
Definition graphicsexportdialog.cpp:1432
void setPageSize(const std::optional< QPageSize::PageSizeId > &size) noexcept
Definition graphicsexportdialog.cpp:1212
GraphicsExportDialog(const GraphicsExportDialog &other)=delete
const QList< Page > & getPages() const noexcept
Definition graphicsexportdialog.h:109
void startExport(bool toClipboard) noexcept
Definition graphicsexportdialog.cpp:1122
void setOrientation(GraphicsExportSettings::Orientation orientation) noexcept
Definition graphicsexportdialog.cpp:1227
const Output mOutput
Definition graphicsexportdialog.h:173
void printerChanged(int index) noexcept
Definition graphicsexportdialog.cpp:918
QScopedPointer< GraphicsExport > mPreview
Definition graphicsexportdialog.h:198
void setMinLineWidth(const UnsignedLength &width) noexcept
Definition graphicsexportdialog.cpp:1361
bool getBlackWhite() const noexcept
Definition graphicsexportdialog.cpp:1337
std::optional< QPageSize > getPageSize() const noexcept
Definition graphicsexportdialog.cpp:1223
const Theme & mTheme
Definition graphicsexportdialog.h:177
bool getRotate() const noexcept
Definition graphicsexportdialog.cpp:1296
void setMirror(bool mirror) noexcept
Definition graphicsexportdialog.cpp:1300
void setMarginLeft(const UnsignedLength &margin) noexcept
Definition graphicsexportdialog.cpp:1249
QScopedPointer< QProgressDialog > mProgressDialog
Definition graphicsexportdialog.h:190
void setDuplex(QPrinter::DuplexMode duplex) noexcept
Definition graphicsexportdialog.cpp:1384
void setBackgroundColor(const QColor &color) noexcept
Definition graphicsexportdialog.cpp:1341
QList< QPrinterInfo > mAvailablePrinters
Definition graphicsexportdialog.h:193
const int mCurrentPage
Definition graphicsexportdialog.h:175
QString getPrinterName() const noexcept
Definition graphicsexportdialog.cpp:1379
void setSaveAsCallback(SaveAsCallback callback) noexcept
Definition graphicsexportdialog.cpp:454
Mode
Definition graphicsexportdialog.h:79
@ Board
Initialize settings suitable for footprints/boards.
@ Schematic
Initialize settings suitable for symbols/schematics.
void setShowPinNumbers(bool show) noexcept
Definition graphicsexportdialog.cpp:1284
std::optional< QPageSize::PageSizeId > mSettingsPageSize
Definition graphicsexportdialog.h:185
void setPrinterName(const QString &name) noexcept
Definition graphicsexportdialog.cpp:1370
QScopedPointer< GraphicsExport > mExport
Definition graphicsexportdialog.h:199
bool getMirror() const noexcept
Definition graphicsexportdialog.cpp:1304
const FilePath mDefaultFilePath
Definition graphicsexportdialog.h:176
void setScaleFactor(const UnsignedRatio &factor) noexcept
Definition graphicsexportdialog.cpp:1316
Output
Definition graphicsexportdialog.h:83
UnsignedRatio getScaleFactor() const noexcept
Definition graphicsexportdialog.cpp:1321
void setPageContent(const QList< ContentItem > &items) noexcept
Definition graphicsexportdialog.cpp:1407
void printersAvailable() noexcept
Definition graphicsexportdialog.cpp:883
void applySettings() noexcept
Definition graphicsexportdialog.cpp:992
bool getShowPinNumbers() const noexcept
Definition graphicsexportdialog.cpp:1288
void layerListItemDoubleClicked(QListWidgetItem *item) noexcept
Definition graphicsexportdialog.cpp:981
UnsignedLength getMarginBottom() const noexcept
Definition graphicsexportdialog.cpp:1280
bool getOpenExportedFiles() const noexcept
Definition graphicsexportdialog.cpp:1440
void syncClientSettings(ClientSettingsAction action) noexcept
Definition graphicsexportdialog.cpp:581
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:463
void setMarginTop(const UnsignedLength &margin) noexcept
Definition graphicsexportdialog.cpp:1258
void openProgressDialog() noexcept
Definition graphicsexportdialog.cpp:1187
GraphicsExportDialog & operator=(const GraphicsExportDialog &rhs)=delete
void setRotate(bool rotate) noexcept
Definition graphicsexportdialog.cpp:1292
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:1308
QList< std::pair< QString, QColor > > mColors
Definition graphicsexportdialog.h:182
QPrinter::DuplexMode getDuplex() const noexcept
Definition graphicsexportdialog.cpp:1393
UnsignedLength getMarginLeft() const noexcept
Definition graphicsexportdialog.cpp:1254
bool getFitToPage() const noexcept
Definition graphicsexportdialog.cpp:1312
QScopedPointer< GraphicsExportSettings > mDefaultSettings
Definition graphicsexportdialog.h:181
void setMarginBottom(const UnsignedLength &margin) noexcept
Definition graphicsexportdialog.cpp:1275
GraphicsExportSettings::Orientation getOrientation() const noexcept
Definition graphicsexportdialog.cpp:1238
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:1333
SaveAsCallback mSaveAsCallback
Definition graphicsexportdialog.h:179
ClientSettingsAction
Definition graphicsexportdialog.h:65
UnsignedLength getMarginRight() const noexcept
Definition graphicsexportdialog.cpp:1271
QList< std::optional< QPageSize > > mAvailablePageSizes
Definition graphicsexportdialog.h:194
const Mode mMode
Definition graphicsexportdialog.h:172
void updateColorsListWidget() noexcept
Definition graphicsexportdialog.cpp:1444
void setDpi(int dpi) noexcept
Definition graphicsexportdialog.cpp:1325
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:1266
UnsignedLength getMinLineWidth() const noexcept
Definition graphicsexportdialog.cpp:1366
void setAvailablePageSizes(QList< std::optional< QPageSize > > sizes) noexcept
Definition graphicsexportdialog.cpp:955
QColor getBackgroundColor() const noexcept
Definition graphicsexportdialog.cpp:1351
UnsignedLength getMarginTop() const noexcept
Definition graphicsexportdialog.cpp:1262
QScopedPointer< Ui::GraphicsExportDialog > mUi
Definition graphicsexportdialog.h:189
QString mSettingsPrinterName
Definition graphicsexportdialog.h:184
void buttonBoxClicked(QDialogButtonBox::StandardButton btn) noexcept
Definition graphicsexportdialog.cpp:855
bool eventFilter(QObject *object, QEvent *event) noexcept override
Definition graphicsexportdialog.cpp:1191
Definition occmodel.cpp:76
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition length.h:694
type_safe::constrained_type< Ratio, UnsignedRatioConstraint, UnsignedRatioVerifier > UnsignedRatio
Definition ratio.h:328
Definition uuid.h:186
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