LibrePCB Developers Documentation
graphicsexportpreviewwidget.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_GRAPHICSEXPORTPREVIEWWIDGET_H
21 #define LIBREPCB_EDITOR_GRAPHICSEXPORTPREVIEWWIDGET_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include <QtCore>
27 #include <QtWidgets>
28 
29 #include <memory>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 namespace editor {
36 
37 /*******************************************************************************
38  * Class GraphicsExportWidget
39  ******************************************************************************/
40 
53 class GraphicsExportWidget final : public QWidget {
54  Q_OBJECT
55 
56  class PageItem final : public QGraphicsItem {
57  public:
58  // Constructors / Destructor
59  PageItem() = delete;
60  PageItem(bool showPageNumber, bool showResolution, int number) noexcept;
61  PageItem(const PageItem& other) = delete;
62  ~PageItem() noexcept;
63 
64  // General Methods
65  void setContent(const QSize& pageSize, const QRectF margins,
66  std::shared_ptr<QPicture> picture) noexcept;
67  QRectF boundingRect() const noexcept override;
68  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
69  QWidget* widget) noexcept override;
70 
71  // Operator Overloadings
72  PageItem& operator=(const PageItem& rhs) = delete;
73 
74  private: // Methods
75  QSize getSize() const noexcept;
76  QString getResolution() const noexcept;
77 
78  private: // Data
81  int mNumber;
82  QSize mSize;
83  QRectF mMargins;
84  std::shared_ptr<QPicture> mPicture;
85  };
86 
87 public:
88  // Constructors / Destructor
89  GraphicsExportWidget(const GraphicsExportWidget& other) = delete;
90  explicit GraphicsExportWidget(QWidget* parent = nullptr) noexcept;
91  ~GraphicsExportWidget() noexcept;
92 
93  // General Methods
94  void setShowPageNumbers(bool show) noexcept;
95  void setShowResolution(bool show) noexcept;
96  void setNumberOfPages(int number) noexcept;
97  void setPageContent(int index, const QSize& pageSize, const QRectF margins,
98  std::shared_ptr<QPicture> picture) noexcept;
99 
100  // Operator Overloadings
101  GraphicsExportWidget& operator=(const GraphicsExportWidget& rhs) = delete;
102 
103 protected:
104  void resizeEvent(QResizeEvent* e) noexcept override;
105  void showEvent(QShowEvent* e) noexcept override;
106 
107 private: // Methods
108  void updateScale() noexcept;
109  void updateItemPositions() noexcept;
110 
111 private: // Data
112  QScopedPointer<QGraphicsView> mView;
113  QScopedPointer<QGraphicsScene> mScene;
114  QVector<std::shared_ptr<PageItem> > mItems;
117 };
118 
119 /*******************************************************************************
120  * End of File
121  ******************************************************************************/
122 
123 } // namespace editor
124 } // namespace librepcb
125 
126 #endif
void updateScale() noexcept
Definition: graphicsexportpreviewwidget.cpp:223
GraphicsExportWidget(const GraphicsExportWidget &other)=delete
bool mShowPageNumbers
Definition: graphicsexportpreviewwidget.h:79
QScopedPointer< QGraphicsView > mView
Definition: graphicsexportpreviewwidget.h:112
Definition: occmodel.cpp:76
void setShowPageNumbers(bool show) noexcept
Definition: graphicsexportpreviewwidget.cpp:171
PageItem & operator=(const PageItem &rhs)=delete
void setNumberOfPages(int number) noexcept
Definition: graphicsexportpreviewwidget.cpp:179
QSize getSize() const noexcept
Definition: graphicsexportpreviewwidget.cpp:127
Definition: graphicsexportpreviewwidget.h:56
QVector< std::shared_ptr< PageItem > > mItems
Definition: graphicsexportpreviewwidget.h:114
void showEvent(QShowEvent *e) noexcept override
Definition: graphicsexportpreviewwidget.cpp:214
bool mShowResolution
Definition: graphicsexportpreviewwidget.h:80
int mNumber
Definition: graphicsexportpreviewwidget.h:81
void setContent(const QSize &pageSize, const QRectF margins, std::shared_ptr< QPicture > picture) noexcept
Definition: graphicsexportpreviewwidget.cpp:53
QSize mSize
Definition: graphicsexportpreviewwidget.h:82
std::shared_ptr< QPicture > mPicture
Definition: graphicsexportpreviewwidget.h:84
QRectF mMargins
Definition: graphicsexportpreviewwidget.h:83
Like QGraphicsExportWidget, just better.
Definition: graphicsexportpreviewwidget.h:53
QRectF boundingRect() const noexcept override
Definition: graphicsexportpreviewwidget.cpp:66
~PageItem() noexcept
Definition: graphicsexportpreviewwidget.cpp:50
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) noexcept override
Definition: graphicsexportpreviewwidget.cpp:74
void setShowResolution(bool show) noexcept
Definition: graphicsexportpreviewwidget.cpp:175
void setPageContent(int index, const QSize &pageSize, const QRectF margins, std::shared_ptr< QPicture > picture) noexcept
Definition: graphicsexportpreviewwidget.cpp:193
void updateItemPositions() noexcept
Definition: graphicsexportpreviewwidget.cpp:229
void resizeEvent(QResizeEvent *e) noexcept override
Definition: graphicsexportpreviewwidget.cpp:209
QScopedPointer< QGraphicsScene > mScene
Definition: graphicsexportpreviewwidget.h:113
QString getResolution() const noexcept
Definition: graphicsexportpreviewwidget.cpp:131