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
33#include <slint.h>
34
35/*******************************************************************************
36 * Namespace / Forward Declarations
37 ******************************************************************************/
38namespace librepcb {
39namespace editor {
40
41class GraphicsScene;
42class IF_GraphicsViewEventHandler;
43
44/*******************************************************************************
45 * Class SlintGraphicsView
46 ******************************************************************************/
47
51class SlintGraphicsView final : public QObject {
52 Q_OBJECT
53
54 struct Projection {
55 QPointF offset;
56 qreal scale = 1;
57
59 qreal factor) const noexcept {
60 return Projection{
61 offset + delta.offset * factor,
62 scale + delta.scale * factor,
63 };
64 }
65 bool operator!=(const Projection& rhs) const noexcept {
66 return (offset != rhs.offset) || (scale != rhs.scale);
67 }
68 Projection operator-(const Projection& rhs) const noexcept {
69 return Projection{
70 offset - rhs.offset,
71 scale - rhs.scale,
72 };
73 }
74 };
75
76public:
77 // Constructors / Destructor
78 explicit SlintGraphicsView(QObject* parent = nullptr) noexcept;
79 SlintGraphicsView(const SlintGraphicsView& other) = delete;
80 virtual ~SlintGraphicsView() noexcept;
81
82 // Getters
83 bool isPanning() const noexcept { return mPanning; }
84 QPainterPath calcPosWithTolerance(const Point& pos,
85 qreal multiplier) const noexcept;
86 Point mapToScenePos(const QPointF& pos) const noexcept;
87
88 // General Methods
90 slint::Image render(GraphicsScene& scene, float width, float height) noexcept;
91 bool pointerEvent(const QPointF& pos,
92 slint::private_api::PointerEvent e) noexcept;
93 bool scrollEvent(const QPointF& pos,
94 slint::private_api::PointerScrollEvent e) noexcept;
95 bool keyEvent(const slint::private_api::KeyEvent& e) noexcept;
96 void scrollLeft() noexcept;
97 void scrollRight() noexcept;
98 void scrollUp() noexcept;
99 void scrollDown() noexcept;
100 void zoomIn() noexcept;
101 void zoomOut() noexcept;
102 void zoomToSceneRect(const QRectF& r) noexcept;
103
104 // Operator Overloadings
105 SlintGraphicsView& operator=(const SlintGraphicsView& rhs) = delete;
106
107signals:
110
111private: // Methods
112 void scroll(const QPointF& delta) noexcept;
113 void zoom(const QPointF& center, qreal factor) noexcept;
114 void smoothTo(const Projection& projection) noexcept;
115 bool applyProjection(const Projection& projection) noexcept;
116
117private: // Data
120 QSizeF mViewSize;
121
124
125 bool mPanning = false;
128
131 std::unique_ptr<QVariantAnimation> mAnimation;
132};
133
134/*******************************************************************************
135 * End of File
136 ******************************************************************************/
137
138} // namespace editor
139} // namespace librepcb
140
141#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:51
bool keyEvent(const slint::private_api::KeyEvent &e) noexcept
Definition slintgraphicsview.cpp:237
void setEventHandler(IF_GraphicsViewEventHandler *obj) noexcept
Definition slintgraphicsview.cpp:93
QPointF mPanningStartScreenPos
Definition slintgraphicsview.h:126
slint::Image render(GraphicsScene &scene, float width, float height) noexcept
Definition slintgraphicsview.cpp:98
void scroll(const QPointF &delta) noexcept
Definition slintgraphicsview.cpp:298
void scrollRight() noexcept
Definition slintgraphicsview.cpp:258
Point mapToScenePos(const QPointF &pos) const noexcept
Definition slintgraphicsview.cpp:82
QSizeF mViewSize
Definition slintgraphicsview.h:120
void zoomOut() noexcept
Definition slintgraphicsview.cpp:274
GraphicsSceneMouseEvent mMouseEvent
Definition slintgraphicsview.h:122
QPainterPath calcPosWithTolerance(const Point &pos, qreal multiplier) const noexcept
Definition slintgraphicsview.cpp:72
bool applyProjection(const Projection &projection) noexcept
Definition slintgraphicsview.cpp:332
void scrollLeft() noexcept
Definition slintgraphicsview.cpp:254
QDeadlineTimer mLeftMouseButtonDoubleClickTimer
Definition slintgraphicsview.h:123
QPointF mPanningStartScenePos
Definition slintgraphicsview.h:127
void zoomIn() noexcept
Definition slintgraphicsview.cpp:270
Projection mAnimationDataStart
Definition slintgraphicsview.h:129
Projection mAnimationDataDelta
Definition slintgraphicsview.h:130
bool isPanning() const noexcept
Definition slintgraphicsview.h:83
void scrollDown() noexcept
Definition slintgraphicsview.cpp:266
void zoomToSceneRect(const QRectF &r) noexcept
Definition slintgraphicsview.cpp:278
void smoothTo(const Projection &projection) noexcept
Definition slintgraphicsview.cpp:322
void scrollUp() noexcept
Definition slintgraphicsview.cpp:262
std::unique_ptr< QVariantAnimation > mAnimation
Definition slintgraphicsview.h:131
IF_GraphicsViewEventHandler * mEventHandler
Definition slintgraphicsview.h:118
Projection mProjection
Definition slintgraphicsview.h:119
bool scrollEvent(const QPointF &pos, slint::private_api::PointerScrollEvent e) noexcept
Definition slintgraphicsview.cpp:220
bool mPanning
Definition slintgraphicsview.h:125
bool pointerEvent(const QPointF &pos, slint::private_api::PointerEvent e) noexcept
Definition slintgraphicsview.cpp:126
void zoom(const QPointF &center, qreal factor) noexcept
Definition slintgraphicsview.cpp:304
Definition occmodel.cpp:77
Definition uuid.h:186
Definition graphicsscene.h:45
Definition slintgraphicsview.h:54
Projection interpolated(const Projection &delta, qreal factor) const noexcept
Definition slintgraphicsview.h:58
QPointF offset
Definition slintgraphicsview.h:55
Projection operator-(const Projection &rhs) const noexcept
Definition slintgraphicsview.h:68
qreal scale
Definition slintgraphicsview.h:56
bool operator!=(const Projection &rhs) const noexcept
Definition slintgraphicsview.h:65