LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
graphicsview.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_GRAPHICSVIEW_H
21 #define LIBREPCB_GRAPHICSVIEW_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../units/all_length_units.h"
27 
28 #include <QtCore>
29 #include <QtWidgets>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 
36 class IF_GraphicsViewEventHandler;
37 class GraphicsScene;
38 class GridProperties;
39 
40 /*******************************************************************************
41  * Class GraphicsView
42  ******************************************************************************/
43 
47 class GraphicsView final : public QGraphicsView {
48  Q_OBJECT
49 
50 public:
51  // Constructors / Destructor
52  explicit GraphicsView(
53  QWidget* parent = nullptr,
54  IF_GraphicsViewEventHandler* eventHandler = nullptr) noexcept;
55  ~GraphicsView() noexcept;
56 
57  // Getters
58  GraphicsScene* getScene() const noexcept { return mScene; }
59  QRectF getVisibleSceneRect() const noexcept;
60  bool getUseOpenGl() const noexcept { return mUseOpenGl; }
61  const GridProperties& getGridProperties() const noexcept {
62  return *mGridProperties;
63  }
64 
65  // Setters
66  void setUseOpenGl(bool useOpenGl) noexcept;
67  void setGridProperties(const GridProperties& properties) noexcept;
68  void setScene(GraphicsScene* scene) noexcept;
69  void setVisibleSceneRect(const QRectF& rect) noexcept;
70 
80  void setSceneRectMarker(const QRectF& rect) noexcept;
81  void setOriginCrossVisible(bool visible) noexcept;
83  IF_GraphicsViewEventHandler* eventHandler) noexcept;
84 
85  // General Methods
86  Point mapGlobalPosToScenePos(const QPoint& globalPosPx, bool boundToView,
87  bool mapToGrid) const noexcept;
88  void handleMouseWheelEvent(QGraphicsSceneWheelEvent* event) noexcept;
89 
90 public slots:
91 
92  // Public Slots
93  void zoomIn() noexcept;
94  void zoomOut() noexcept;
95  void zoomAll() noexcept;
96  void zoomToRect(const QRectF& rect) noexcept;
97 
98 signals:
104  void cursorScenePositionChanged(const Point& pos);
105 
106 private slots:
107 
108  // Private Slots
109  void zoomAnimationValueChanged(const QVariant& value) noexcept;
110 
111 private:
112  // make some methods inaccessible...
113  GraphicsView(const GraphicsView& other) = delete;
114  GraphicsView& operator=(const GraphicsView& rhs) = delete;
115 
116  // Inherited Methods
117  void wheelEvent(QWheelEvent* event);
118  bool eventFilter(QObject* obj, QEvent* event);
119  void drawBackground(QPainter* painter, const QRectF& rect);
120  void drawForeground(QPainter* painter, const QRectF& rect);
121 
122  // General Attributes
125  QVariantAnimation* mZoomAnimation;
130  volatile bool mPanningActive;
132 
133  // Static Variables
134  static constexpr qreal sZoomStepFactor = 1.3;
135 };
136 
137 /*******************************************************************************
138  * End of File
139  ******************************************************************************/
140 
141 } // namespace librepcb
142 
143 #endif // LIBREPCB_GRAPHICSVIEW_H
GraphicsView(QWidget *parent=nullptr, IF_GraphicsViewEventHandler *eventHandler=nullptr) noexcept
Definition: graphicsview.cpp:42
void cursorScenePositionChanged(const Point &pos)
Cursor scene position changed signal.
const GridProperties & getGridProperties() const noexcept
Definition: graphicsview.h:61
void zoomAll() noexcept
Definition: graphicsview.cpp:203
void setOriginCrossVisible(bool visible) noexcept
Definition: graphicsview.cpp:136
static constexpr qreal sZoomStepFactor
Definition: graphicsview.h:134
GridProperties * mGridProperties
Definition: graphicsview.h:126
GraphicsScene * mScene
Definition: graphicsview.h:124
QCursor mCursorBeforePanning
Definition: graphicsview.h:131
void setVisibleSceneRect(const QRectF &rect) noexcept
Definition: graphicsview.cpp:127
void drawBackground(QPainter *painter, const QRectF &rect)
Definition: graphicsview.cpp:326
void zoomToRect(const QRectF &rect) noexcept
Definition: graphicsview.cpp:213
QVariantAnimation * mZoomAnimation
Definition: graphicsview.h:125
The GraphicsView class.
Definition: graphicsview.h:47
void setEventHandlerObject(IF_GraphicsViewEventHandler *eventHandler) noexcept
Definition: graphicsview.cpp:141
The GridProperties class.
Definition: gridproperties.h:43
void setGridProperties(const GridProperties &properties) noexcept
Definition: graphicsview.cpp:113
QRectF mSceneRectMarker
Definition: graphicsview.h:127
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
void drawForeground(QPainter *painter, const QRectF &rect)
Definition: graphicsview.cpp:375
~GraphicsView() noexcept
Definition: graphicsview.cpp:68
void setScene(GraphicsScene *scene) noexcept
Definition: graphicsview.cpp:119
void setSceneRectMarker(const QRectF &rect) noexcept
Setup the marker for a specific scene rect.
Definition: graphicsview.cpp:131
bool getUseOpenGl() const noexcept
Definition: graphicsview.h:60
void handleMouseWheelEvent(QGraphicsSceneWheelEvent *event) noexcept
Definition: graphicsview.cpp:165
void zoomOut() noexcept
Definition: graphicsview.cpp:198
GraphicsScene * getScene() const noexcept
Definition: graphicsview.h:58
void zoomAnimationValueChanged(const QVariant &value) noexcept
Definition: graphicsview.cpp:225
void setUseOpenGl(bool useOpenGl) noexcept
Definition: graphicsview.cpp:87
IF_GraphicsViewEventHandler * mEventHandlerObject
Definition: graphicsview.h:123
bool mUseOpenGl
Definition: graphicsview.h:129
The IF_GraphicsViewEventHandler class.
Definition: if_graphicsvieweventhandler.h:40
Point mapGlobalPosToScenePos(const QPoint &globalPosPx, bool boundToView, bool mapToGrid) const noexcept
Definition: graphicsview.cpp:150
The GraphicsScene class.
Definition: graphicsscene.h:43
QRectF getVisibleSceneRect() const noexcept
Definition: graphicsview.cpp:79
void wheelEvent(QWheelEvent *event)
Definition: graphicsview.cpp:238
void zoomIn() noexcept
Definition: graphicsview.cpp:193
bool mOriginCrossVisible
Definition: graphicsview.h:128
volatile bool mPanningActive
Definition: graphicsview.h:130
bool eventFilter(QObject *obj, QEvent *event)
Definition: graphicsview.cpp:251