LibrePCB Developers Documentation
Loading...
Searching...
No Matches
slintgraphicsview.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_SLINTGRAPHICSVIEW_H
21#define LIBREPCB_EDITOR_SLINTGRAPHICSVIEW_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "graphicsscene.h"
27
29
30#include <QtCore>
31#include <QtGui>
32#include <QtOpenGL>
33
34#include <slint.h>
35
36/*******************************************************************************
37 * Namespace / Forward Declarations
38 ******************************************************************************/
39namespace librepcb {
40namespace editor {
41
42class GraphicsScene;
43class IF_GraphicsViewEventHandler;
44
45/*******************************************************************************
46 * Class SlintGraphicsView
47 ******************************************************************************/
48
52class SlintGraphicsView final : public QObject {
53 Q_OBJECT
54
55 struct Projection {
56 QPointF offset;
57 qreal scale = 1;
58
60 qreal factor) const noexcept {
61 return Projection{
62 offset + delta.offset * factor,
63 scale + delta.scale * factor,
64 };
65 }
66 bool operator==(const Projection& rhs) const noexcept {
67 return (offset == rhs.offset) && (scale == rhs.scale);
68 }
69 bool operator!=(const Projection& rhs) const noexcept {
70 return !(*this == rhs);
71 }
72 Projection operator-(const Projection& rhs) const noexcept {
73 return Projection{
74 offset - rhs.offset,
75 scale - rhs.scale,
76 };
77 }
78 };
79
80public:
81 // Constructors / Destructor
82 explicit SlintGraphicsView(const QRectF& defaultSceneRect,
83 const QMarginsF& defaultMargins,
84 QObject* parent = nullptr) noexcept;
85 SlintGraphicsView(const SlintGraphicsView& other) = delete;
86 virtual ~SlintGraphicsView() noexcept;
87
88 // Getters
89 bool isPanning() const noexcept { return mPanning; }
90 QPainterPath calcPosWithTolerance(const Point& pos,
91 qreal multiplier) const noexcept;
92 Point mapToScenePos(const QPointF& pos,
93 qreal devicePixelRatio) const noexcept;
94
95 // General Methods
96 void setUseOpenGl(bool use) noexcept;
98 slint::Image render(GraphicsScene& scene, float width, float height) noexcept;
99 bool pointerEvent(const QPointF& pos,
100 slint::private_api::PointerEvent e) noexcept;
101 bool scrollEvent(const QPointF& pos,
102 slint::private_api::PointerScrollEvent e) noexcept;
103 bool keyEvent(const slint::private_api::KeyEvent& e) noexcept;
104 void scrollLeft() noexcept;
105 void scrollRight() noexcept;
106 void scrollUp() noexcept;
107 void scrollDown() noexcept;
108 void zoomIn() noexcept;
109 void zoomOut() noexcept;
110 void zoomToSceneRect(const QRectF& r) noexcept;
111
112 // Static Methods
113 static QRectF defaultSymbolSceneRect() noexcept;
114 static QRectF defaultFootprintSceneRect() noexcept;
115 static QRectF defaultSchematicSceneRect() noexcept;
116 static QRectF defaultBoardSceneRect() noexcept;
117 static QMarginsF defaultMargins() noexcept;
118 static QMarginsF defaultEditorMargins() noexcept;
119
120 // Operator Overloadings
121 SlintGraphicsView& operator=(const SlintGraphicsView& rhs) = delete;
122
123signals:
126
127private: // Methods
128 void scroll(const QPointF& delta) noexcept;
129 void zoom(const QPointF& center, qreal factor) noexcept;
130 void smoothTo(const Projection& projection) noexcept;
131 bool applyProjection(const Projection& projection) noexcept;
132 QRectF validateSceneRect(const QRectF& r) const noexcept;
133
134private: // Data
135 const QRectF mDefaultSceneRect;
136 const QMarginsF mDefaultMargins;
138 std::unique_ptr<QOffscreenSurface> mGlSurface;
139 std::unique_ptr<QOpenGLContext> mGlContext;
140 std::unique_ptr<QOpenGLFramebufferObject> mGlFbo;
141 QString mGlError;
143 QSizeF mViewSize;
144
147
148 bool mPanning = false;
151
154 std::unique_ptr<QVariantAnimation> mAnimation;
155};
156
157/*******************************************************************************
158 * End of File
159 ******************************************************************************/
160
161} // namespace editor
162} // namespace librepcb
163
164#endif
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
The GraphicsScene class.
Definition graphicsscene.h:64
The IF_GraphicsViewEventHandler class.
Definition if_graphicsvieweventhandler.h:45
The SlintGraphicsView class.
Definition slintgraphicsview.h:52
static QMarginsF defaultEditorMargins() noexcept
Definition slintgraphicsview.cpp:385
QRectF validateSceneRect(const QRectF &r) const noexcept
Definition slintgraphicsview.cpp:445
bool keyEvent(const slint::private_api::KeyEvent &e) noexcept
Definition slintgraphicsview.cpp:299
void setEventHandler(IF_GraphicsViewEventHandler *obj) noexcept
Definition slintgraphicsview.cpp:114
QPointF mPanningStartScreenPos
Definition slintgraphicsview.h:149
slint::Image render(GraphicsScene &scene, float width, float height) noexcept
Definition slintgraphicsview.cpp:119
void scroll(const QPointF &delta) noexcept
Definition slintgraphicsview.cpp:393
const QRectF mDefaultSceneRect
Definition slintgraphicsview.h:135
void scrollRight() noexcept
Definition slintgraphicsview.cpp:319
static QRectF defaultSchematicSceneRect() noexcept
Definition slintgraphicsview.cpp:373
std::unique_ptr< QOpenGLFramebufferObject > mGlFbo
Definition slintgraphicsview.h:140
QSizeF mViewSize
Definition slintgraphicsview.h:143
std::unique_ptr< QOffscreenSurface > mGlSurface
Definition slintgraphicsview.h:138
void zoomOut() noexcept
Definition slintgraphicsview.cpp:335
static QRectF defaultSymbolSceneRect() noexcept
Definition slintgraphicsview.cpp:365
GraphicsSceneMouseEvent mMouseEvent
Definition slintgraphicsview.h:145
QPainterPath calcPosWithTolerance(const Point &pos, qreal multiplier) const noexcept
Definition slintgraphicsview.cpp:66
const QMarginsF mDefaultMargins
Definition slintgraphicsview.h:136
bool applyProjection(const Projection &projection) noexcept
Definition slintgraphicsview.cpp:435
void setUseOpenGl(bool use) noexcept
Definition slintgraphicsview.cpp:88
void scrollLeft() noexcept
Definition slintgraphicsview.cpp:315
QDeadlineTimer mLeftMouseButtonDoubleClickTimer
Definition slintgraphicsview.h:146
std::unique_ptr< QOpenGLContext > mGlContext
Definition slintgraphicsview.h:139
QString mGlError
Definition slintgraphicsview.h:141
QPointF mPanningStartScenePos
Definition slintgraphicsview.h:150
void zoomIn() noexcept
Definition slintgraphicsview.cpp:331
Projection mAnimationDataStart
Definition slintgraphicsview.h:152
Projection mAnimationDataDelta
Definition slintgraphicsview.h:153
bool isPanning() const noexcept
Definition slintgraphicsview.h:89
void scrollDown() noexcept
Definition slintgraphicsview.cpp:327
void zoomToSceneRect(const QRectF &r) noexcept
Definition slintgraphicsview.cpp:339
static QMarginsF defaultMargins() noexcept
Definition slintgraphicsview.cpp:381
void smoothTo(const Projection &projection) noexcept
Definition slintgraphicsview.cpp:417
void scrollUp() noexcept
Definition slintgraphicsview.cpp:323
std::unique_ptr< QVariantAnimation > mAnimation
Definition slintgraphicsview.h:154
static QRectF defaultBoardSceneRect() noexcept
Definition slintgraphicsview.cpp:377
IF_GraphicsViewEventHandler * mEventHandler
Definition slintgraphicsview.h:137
Projection mProjection
Definition slintgraphicsview.h:142
bool scrollEvent(const QPointF &pos, slint::private_api::PointerScrollEvent e) noexcept
Definition slintgraphicsview.cpp:282
bool mPanning
Definition slintgraphicsview.h:148
bool pointerEvent(const QPointF &pos, slint::private_api::PointerEvent e) noexcept
Definition slintgraphicsview.cpp:188
Point mapToScenePos(const QPointF &pos, qreal devicePixelRatio) const noexcept
Definition slintgraphicsview.cpp:76
void zoom(const QPointF &center, qreal factor) noexcept
Definition slintgraphicsview.cpp:399
static QRectF defaultFootprintSceneRect() noexcept
Definition slintgraphicsview.cpp:369
Definition occmodel.cpp:77
Definition uuid.h:186
Definition graphicsscene.h:45
Definition slintgraphicsview.h:55
bool operator==(const Projection &rhs) const noexcept
Definition slintgraphicsview.h:66
Projection interpolated(const Projection &delta, qreal factor) const noexcept
Definition slintgraphicsview.h:59
QPointF offset
Definition slintgraphicsview.h:56
Projection operator-(const Projection &rhs) const noexcept
Definition slintgraphicsview.h:72
qreal scale
Definition slintgraphicsview.h:57
bool operator!=(const Projection &rhs) const noexcept
Definition slintgraphicsview.h:69