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 Projection operator-(const Projection& rhs) const noexcept {
70 return Projection{
71 offset - rhs.offset,
72 scale - rhs.scale,
73 };
74 }
75 };
76
77public:
78 // Constructors / Destructor
79 explicit SlintGraphicsView(QObject* parent = nullptr) noexcept;
80 SlintGraphicsView(const SlintGraphicsView& other) = delete;
81 virtual ~SlintGraphicsView() noexcept;
82
83 // Getters
84 bool isPanning() const noexcept { return mPanning; }
85 QPainterPath calcPosWithTolerance(const Point& pos,
86 qreal multiplier) const noexcept;
87 Point mapToScenePos(const QPointF& pos) const noexcept;
88
89 // General Methods
90 void setUseOpenGl(bool use) noexcept;
92 slint::Image render(GraphicsScene& scene, float width, float height) noexcept;
93 bool pointerEvent(const QPointF& pos,
94 slint::private_api::PointerEvent e) noexcept;
95 bool scrollEvent(const QPointF& pos,
96 slint::private_api::PointerScrollEvent e) noexcept;
97 bool keyEvent(const slint::private_api::KeyEvent& e) noexcept;
98 void scrollLeft() noexcept;
99 void scrollRight() noexcept;
100 void scrollUp() noexcept;
101 void scrollDown() noexcept;
102 void zoomIn() noexcept;
103 void zoomOut() noexcept;
104 void zoomToSceneRect(const QRectF& r) noexcept;
105
106 // Operator Overloadings
107 SlintGraphicsView& operator=(const SlintGraphicsView& rhs) = delete;
108
109signals:
112
113private: // Methods
114 void scroll(const QPointF& delta) noexcept;
115 void zoom(const QPointF& center, qreal factor) noexcept;
116 void smoothTo(const Projection& projection) noexcept;
117 bool applyProjection(const Projection& projection) noexcept;
118
119private: // Data
121 std::unique_ptr<QOffscreenSurface> mGlSurface;
122 std::unique_ptr<QOpenGLContext> mGlContext;
123 std::unique_ptr<QOpenGLFramebufferObject> mGlFbo;
124 QString mGlError;
126 QSizeF mViewSize;
127
130
131 bool mPanning = false;
134
137 std::unique_ptr<QVariantAnimation> mAnimation;
138};
139
140/*******************************************************************************
141 * End of File
142 ******************************************************************************/
143
144} // namespace editor
145} // namespace librepcb
146
147#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
bool keyEvent(const slint::private_api::KeyEvent &e) noexcept
Definition slintgraphicsview.cpp:303
void setEventHandler(IF_GraphicsViewEventHandler *obj) noexcept
Definition slintgraphicsview.cpp:119
QPointF mPanningStartScreenPos
Definition slintgraphicsview.h:132
slint::Image render(GraphicsScene &scene, float width, float height) noexcept
Definition slintgraphicsview.cpp:124
void scroll(const QPointF &delta) noexcept
Definition slintgraphicsview.cpp:364
void scrollRight() noexcept
Definition slintgraphicsview.cpp:324
Point mapToScenePos(const QPointF &pos) const noexcept
Definition slintgraphicsview.cpp:82
std::unique_ptr< QOpenGLFramebufferObject > mGlFbo
Definition slintgraphicsview.h:123
QSizeF mViewSize
Definition slintgraphicsview.h:126
std::unique_ptr< QOffscreenSurface > mGlSurface
Definition slintgraphicsview.h:121
void zoomOut() noexcept
Definition slintgraphicsview.cpp:340
GraphicsSceneMouseEvent mMouseEvent
Definition slintgraphicsview.h:128
QPainterPath calcPosWithTolerance(const Point &pos, qreal multiplier) const noexcept
Definition slintgraphicsview.cpp:72
bool applyProjection(const Projection &projection) noexcept
Definition slintgraphicsview.cpp:398
void setUseOpenGl(bool use) noexcept
Definition slintgraphicsview.cpp:93
void scrollLeft() noexcept
Definition slintgraphicsview.cpp:320
QDeadlineTimer mLeftMouseButtonDoubleClickTimer
Definition slintgraphicsview.h:129
std::unique_ptr< QOpenGLContext > mGlContext
Definition slintgraphicsview.h:122
QString mGlError
Definition slintgraphicsview.h:124
QPointF mPanningStartScenePos
Definition slintgraphicsview.h:133
void zoomIn() noexcept
Definition slintgraphicsview.cpp:336
Projection mAnimationDataStart
Definition slintgraphicsview.h:135
Projection mAnimationDataDelta
Definition slintgraphicsview.h:136
bool isPanning() const noexcept
Definition slintgraphicsview.h:84
void scrollDown() noexcept
Definition slintgraphicsview.cpp:332
void zoomToSceneRect(const QRectF &r) noexcept
Definition slintgraphicsview.cpp:344
void smoothTo(const Projection &projection) noexcept
Definition slintgraphicsview.cpp:388
void scrollUp() noexcept
Definition slintgraphicsview.cpp:328
std::unique_ptr< QVariantAnimation > mAnimation
Definition slintgraphicsview.h:137
IF_GraphicsViewEventHandler * mEventHandler
Definition slintgraphicsview.h:120
Projection mProjection
Definition slintgraphicsview.h:125
bool scrollEvent(const QPointF &pos, slint::private_api::PointerScrollEvent e) noexcept
Definition slintgraphicsview.cpp:286
bool mPanning
Definition slintgraphicsview.h:131
bool pointerEvent(const QPointF &pos, slint::private_api::PointerEvent e) noexcept
Definition slintgraphicsview.cpp:192
void zoom(const QPointF &center, qreal factor) noexcept
Definition slintgraphicsview.cpp:370
Definition occmodel.cpp:77
Definition uuid.h:186
Definition graphicsscene.h:45
Definition slintgraphicsview.h:55
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:69
qreal scale
Definition slintgraphicsview.h:57
bool operator!=(const Projection &rhs) const noexcept
Definition slintgraphicsview.h:66