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  void setOriginCrossVisible(bool visible) noexcept;
72  IF_GraphicsViewEventHandler* eventHandler) noexcept;
73 
74  // General Methods
75  Point mapGlobalPosToScenePos(const QPoint& globalPosPx, bool boundToView,
76  bool mapToGrid) const noexcept;
77  void handleMouseWheelEvent(QGraphicsSceneWheelEvent* event) noexcept;
78 
79 public slots:
80 
81  // Public Slots
82  void zoomIn() noexcept;
83  void zoomOut() noexcept;
84  void zoomAll() noexcept;
85 
86 signals:
92  void cursorScenePositionChanged(const Point& pos);
93 
94 private slots:
95 
96  // Private Slots
97  void zoomAnimationValueChanged(const QVariant& value) noexcept;
98 
99 private:
100  // make some methods inaccessible...
101  GraphicsView(const GraphicsView& other) = delete;
102  GraphicsView& operator=(const GraphicsView& rhs) = delete;
103 
104  // Inherited Methods
105  void wheelEvent(QWheelEvent* event);
106  bool eventFilter(QObject* obj, QEvent* event);
107  void drawBackground(QPainter* painter, const QRectF& rect);
108  void drawForeground(QPainter* painter, const QRectF& rect);
109 
110  // General Attributes
113  QVariantAnimation* mZoomAnimation;
117  volatile bool mPanningActive;
119 
120  // Static Variables
121  static constexpr qreal sZoomStepFactor = 1.3;
122 };
123 
124 /*******************************************************************************
125  * End of File
126  ******************************************************************************/
127 
128 } // namespace librepcb
129 
130 #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:182
void setOriginCrossVisible(bool visible) noexcept
Definition: graphicsview.cpp:115
static constexpr qreal sZoomStepFactor
Definition: graphicsview.h:121
GridProperties * mGridProperties
Definition: graphicsview.h:114
GraphicsScene * mScene
Definition: graphicsview.h:112
QCursor mCursorBeforePanning
Definition: graphicsview.h:118
void setVisibleSceneRect(const QRectF &rect) noexcept
Definition: graphicsview.cpp:111
void drawBackground(QPainter *painter, const QRectF &rect)
Definition: graphicsview.cpp:300
QVariantAnimation * mZoomAnimation
Definition: graphicsview.h:113
The GraphicsView class.
Definition: graphicsview.h:47
void setEventHandlerObject(IF_GraphicsViewEventHandler *eventHandler) noexcept
Definition: graphicsview.cpp:120
The GridProperties class.
Definition: gridproperties.h:43
void setGridProperties(const GridProperties &properties) noexcept
Definition: graphicsview.cpp:98
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:349
~GraphicsView() noexcept
Definition: graphicsview.cpp:67
void setScene(GraphicsScene *scene) noexcept
Definition: graphicsview.cpp:104
bool getUseOpenGl() const noexcept
Definition: graphicsview.h:60
void handleMouseWheelEvent(QGraphicsSceneWheelEvent *event) noexcept
Definition: graphicsview.cpp:144
void zoomOut() noexcept
Definition: graphicsview.cpp:177
GraphicsScene * getScene() const noexcept
Definition: graphicsview.h:58
void zoomAnimationValueChanged(const QVariant &value) noexcept
Definition: graphicsview.cpp:200
void setUseOpenGl(bool useOpenGl) noexcept
Definition: graphicsview.cpp:86
IF_GraphicsViewEventHandler * mEventHandlerObject
Definition: graphicsview.h:111
bool mUseOpenGl
Definition: graphicsview.h:116
The IF_GraphicsViewEventHandler class.
Definition: if_graphicsvieweventhandler.h:40
Point mapGlobalPosToScenePos(const QPoint &globalPosPx, bool boundToView, bool mapToGrid) const noexcept
Definition: graphicsview.cpp:129
The GraphicsScene class.
Definition: graphicsscene.h:43
QRectF getVisibleSceneRect() const noexcept
Definition: graphicsview.cpp:78
void wheelEvent(QWheelEvent *event)
Definition: graphicsview.cpp:213
void zoomIn() noexcept
Definition: graphicsview.cpp:172
bool mOriginCrossVisible
Definition: graphicsview.h:115
volatile bool mPanningActive
Definition: graphicsview.h:117
bool eventFilter(QObject *obj, QEvent *event)
Definition: graphicsview.cpp:226