LibrePCB Developers Documentation
backgroundimagesetupdialog.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_BACKGROUNDIMAGESETUPDIALOG_H
21#define LIBREPCB_EDITOR_BACKGROUNDIMAGESETUPDIALOG_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../widgets/if_graphicsvieweventhandler.h"
27
30
31#include <QtCore>
32#include <QtWidgets>
33
34/*******************************************************************************
35 * Namespace / Forward Declarations
36 ******************************************************************************/
37namespace librepcb {
38namespace editor {
39
40namespace Ui {
41class BackgroundImageSetupDialog;
42}
43
44/*******************************************************************************
45 * Class BackgroundImageSetupDialog
46 ******************************************************************************/
47
51class BackgroundImageSetupDialog final : public QDialog,
53 Q_OBJECT
54
55public:
56 // Types
57 enum class State {
58 Idle,
59 Crop,
60 Rotate,
61 SelectRef1,
62 SelectRef2,
63 };
64
65 // Constructors / Destructor
68 explicit BackgroundImageSetupDialog(const QString& settingsPrefix,
69 QWidget* parent = nullptr) noexcept;
71
72 // General Methods
73 const QImage& getImage() const noexcept { return mImage; }
74 const Angle& getRotation() const noexcept { return mRotation; }
75 const QList<std::pair<QPointF, Point>>& getReferences() const noexcept {
76 return mReferences;
77 }
78 void setData(const QImage& image, const Angle& rotation,
79 const QList<std::pair<QPointF, Point>>& references) noexcept;
80
81 // Operator Overloadings
83 delete;
84
85private:
86 void keyPressEvent(QKeyEvent* event) noexcept override;
87 bool graphicsViewEventHandler(QEvent* event) noexcept override;
88 void startScreenshot() noexcept;
89 void screenshotCountdownTick() noexcept;
90 void takeScreenshot() noexcept;
91 void pasteFromClipboard() noexcept;
92 void loadFromFile() noexcept;
93 void updateUi(QString msg = QString()) noexcept;
94 void fitImageInView() noexcept;
95 void updateAnchors() noexcept;
96 void updateStatusMsg() noexcept;
97 static QImage cropImage(const QImage& img, const QPainterPath& p) noexcept;
98
99 QScopedPointer<Ui::BackgroundImageSetupDialog> mUi;
100 const QString mSettingsPrefix;
101
102 // State
104 QImage mImage;
106 QList<std::pair<QPointF, Point>> mLoadedReferences;
107 QList<std::pair<QPointF, Point>> mReferences;
108 QPointer<QScreen> mScreen;
110
111 // Widgets & graphics items
112 QScopedPointer<QWidget> mRotateWidget;
113 QScopedPointer<QGraphicsPixmapItem> mImageGraphicsItem;
114 std::shared_ptr<QGraphicsPathItem> mCursorGraphicsItem;
115 QScopedPointer<QGraphicsPathItem> mCropGraphicsItem;
116
117 // Always in sync with #mReferences
118 QList<std::shared_ptr<QGraphicsPathItem>> mReferenceGraphicsItems;
119 QList<std::shared_ptr<QGraphicsLineItem>> mReferenceLineGraphicsItems;
120 QList<std::shared_ptr<QWidget>> mReferenceWidgets;
121};
122
123/*******************************************************************************
124 * End of File
125 ******************************************************************************/
126
127} // namespace editor
128} // namespace librepcb
129
130#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition: point.h:79
Dialog (GUI) to configure the background image of a 2D view.
Definition: backgroundimagesetupdialog.h:52
bool graphicsViewEventHandler(QEvent *event) noexcept override
The event handler method.
Definition: backgroundimagesetupdialog.cpp:260
void screenshotCountdownTick() noexcept
Definition: backgroundimagesetupdialog.cpp:340
int mCountdownSecs
Definition: backgroundimagesetupdialog.h:109
const Angle & getRotation() const noexcept
Definition: backgroundimagesetupdialog.h:74
QScopedPointer< QGraphicsPixmapItem > mImageGraphicsItem
Definition: backgroundimagesetupdialog.h:113
const QImage & getImage() const noexcept
Definition: backgroundimagesetupdialog.h:73
std::shared_ptr< QGraphicsPathItem > mCursorGraphicsItem
Definition: backgroundimagesetupdialog.h:114
QList< std::shared_ptr< QGraphicsPathItem > > mReferenceGraphicsItems
Definition: backgroundimagesetupdialog.h:118
void updateStatusMsg() noexcept
Definition: backgroundimagesetupdialog.cpp:527
State mState
Definition: backgroundimagesetupdialog.h:103
QList< std::pair< QPointF, Point > > mLoadedReferences
Definition: backgroundimagesetupdialog.h:106
void fitImageInView() noexcept
Definition: backgroundimagesetupdialog.cpp:507
QScopedPointer< QGraphicsPathItem > mCropGraphicsItem
Definition: backgroundimagesetupdialog.h:115
void setData(const QImage &image, const Angle &rotation, const QList< std::pair< QPointF, Point > > &references) noexcept
Definition: backgroundimagesetupdialog.cpp:229
QList< std::pair< QPointF, Point > > mReferences
Definition: backgroundimagesetupdialog.h:107
State
Definition: backgroundimagesetupdialog.h:57
void updateUi(QString msg=QString()) noexcept
Definition: backgroundimagesetupdialog.cpp:410
const QString mSettingsPrefix
Definition: backgroundimagesetupdialog.h:100
static QImage cropImage(const QImage &img, const QPainterPath &p) noexcept
Definition: backgroundimagesetupdialog.cpp:593
Angle mRotation
Definition: backgroundimagesetupdialog.h:105
void takeScreenshot() noexcept
Definition: backgroundimagesetupdialog.cpp:354
QList< std::shared_ptr< QGraphicsLineItem > > mReferenceLineGraphicsItems
Definition: backgroundimagesetupdialog.h:119
QPointer< QScreen > mScreen
Definition: backgroundimagesetupdialog.h:108
void startScreenshot() noexcept
Definition: backgroundimagesetupdialog.cpp:317
BackgroundImageSetupDialog(const BackgroundImageSetupDialog &other)=delete
void loadFromFile() noexcept
Definition: backgroundimagesetupdialog.cpp:386
void keyPressEvent(QKeyEvent *event) noexcept override
Definition: backgroundimagesetupdialog.cpp:244
const QList< std::pair< QPointF, Point > > & getReferences() const noexcept
Definition: backgroundimagesetupdialog.h:75
void pasteFromClipboard() noexcept
Definition: backgroundimagesetupdialog.cpp:373
QImage mImage
Definition: backgroundimagesetupdialog.h:104
QList< std::shared_ptr< QWidget > > mReferenceWidgets
Definition: backgroundimagesetupdialog.h:120
void updateAnchors() noexcept
Definition: backgroundimagesetupdialog.cpp:516
BackgroundImageSetupDialog & operator=(const BackgroundImageSetupDialog &rhs)=delete
QScopedPointer< Ui::BackgroundImageSetupDialog > mUi
Definition: backgroundimagesetupdialog.h:99
QScopedPointer< QWidget > mRotateWidget
Definition: backgroundimagesetupdialog.h:112
The IF_GraphicsViewEventHandler class.
Definition: if_graphicsvieweventhandler.h:41
Definition: occmodel.cpp:77