LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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_EDITOR_GRAPHICSVIEW_H
21#define LIBREPCB_EDITOR_GRAPHICSVIEW_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
27
28#include <QtCore>
29#include <QtWidgets>
30
31/*******************************************************************************
32 * Namespace / Forward Declarations
33 ******************************************************************************/
34namespace librepcb {
35namespace editor {
36
37class GraphicsScene;
38class IF_GraphicsViewEventHandler;
39class WaitingSpinnerWidget;
40
41/*******************************************************************************
42 * Class GraphicsView
43 ******************************************************************************/
44
48class GraphicsView final : public QGraphicsView {
49 Q_OBJECT
50
51public:
52 // Constructors / Destructor
53 GraphicsView(const GraphicsView& other) = delete;
54 explicit GraphicsView(
55 QWidget* parent = nullptr,
56 IF_GraphicsViewEventHandler* eventHandler = nullptr) noexcept;
57 ~GraphicsView() noexcept;
58
59 // Getters
60 GraphicsScene* getScene() const noexcept { return mScene; }
61 QRectF getVisibleSceneRect() const noexcept;
62 bool getUseOpenGl() const noexcept { return mUseOpenGl; }
63 bool isMouseButtonPressed(Qt::MouseButtons btn) const noexcept {
64 return mPressedMouseButtons & btn;
65 }
66 qint64 getIdleTimeMs() const noexcept { return mIdleTimeMs; }
67
68 // Setters
69 void setSpinnerColor(const QColor& color) noexcept;
70 void setInfoBoxColors(const QColor& fill, const QColor& text) noexcept;
71 void setUseOpenGl(bool useOpenGl) noexcept;
72 void setScene(GraphicsScene* scene) noexcept;
73 void setVisibleSceneRect(const QRectF& rect) noexcept;
74 void setInfoBoxText(const QString& text) noexcept;
76 IF_GraphicsViewEventHandler* eventHandler) noexcept;
77
78 // General Methods
79 Point mapGlobalPosToScenePos(const QPoint& globalPosPx) const noexcept;
80 QPainterPath calcPosWithTolerance(const Point& pos,
81 qreal multiplier = 1) const noexcept;
82 void handleMouseWheelEvent(QGraphicsSceneWheelEvent* event) noexcept;
83
84 // Operator Overloadings
85 GraphicsView& operator=(const GraphicsView& rhs) = delete;
86
87public slots:
88
89 // Public Slots
90 void zoomIn() noexcept;
91 void zoomOut() noexcept;
92 void zoomAll() noexcept;
93 void zoomToRect(const QRectF& rect) noexcept;
94 void showWaitingSpinner() noexcept;
95 void hideWaitingSpinner() noexcept;
96
97signals:
104
105private slots:
106
107 // Private Slots
108 void zoomAnimationValueChanged(const QVariant& value) noexcept;
109
110private:
111 // Inherited Methods
112 void wheelEvent(QWheelEvent* event);
113 bool eventFilter(QObject* obj, QEvent* event);
114
115 // General Attributes
117 QScopedPointer<QLabel> mInfoBoxLabel;
120 QVariantAnimation* mZoomAnimation;
122
123 // State
124 volatile bool mPanningActive;
125 Qt::MouseButton mPanningButton;
126 Qt::MouseButtons mPressedMouseButtons;
129
130 // Static Variables
131 static constexpr qreal sZoomStepFactor = 1.3;
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 GraphicsView class.
Definition graphicsview.h:48
void zoomToRect(const QRectF &rect) noexcept
Definition graphicsview.cpp:241
QCursor mCursorBeforePanning
Definition graphicsview.h:127
bool mUseOpenGl
Definition graphicsview.h:121
void zoomAll() noexcept
Definition graphicsview.cpp:230
QPainterPath calcPosWithTolerance(const Point &pos, qreal multiplier=1) const noexcept
Definition graphicsview.cpp:178
IF_GraphicsViewEventHandler * mEventHandlerObject
Definition graphicsview.h:118
void setUseOpenGl(bool useOpenGl) noexcept
Definition graphicsview.cpp:123
void hideWaitingSpinner() noexcept
Definition graphicsview.cpp:254
void zoomOut() noexcept
Definition graphicsview.cpp:224
void zoomAnimationValueChanged(const QVariant &value) noexcept
Definition graphicsview.cpp:262
Point mapGlobalPosToScenePos(const QPoint &globalPosPx) const noexcept
Definition graphicsview.cpp:170
void handleMouseWheelEvent(QGraphicsSceneWheelEvent *event) noexcept
Definition graphicsview.cpp:190
QScopedPointer< WaitingSpinnerWidget > mWaitingSpinnerWidget
Definition graphicsview.h:116
GraphicsView(const GraphicsView &other)=delete
QRectF getVisibleSceneRect() const noexcept
Definition graphicsview.cpp:98
Qt::MouseButton mPanningButton
Definition graphicsview.h:125
void cursorScenePositionChanged(const Point &pos)
Cursor scene position changed signal.
qint64 mIdleTimeMs
Definition graphicsview.h:128
void zoomIn() noexcept
Definition graphicsview.cpp:218
static constexpr qreal sZoomStepFactor
Definition graphicsview.h:131
QVariantAnimation * mZoomAnimation
Definition graphicsview.h:120
void setSpinnerColor(const QColor &color) noexcept
Definition graphicsview.cpp:106
volatile bool mPanningActive
Definition graphicsview.h:124
void setInfoBoxColors(const QColor &fill, const QColor &text) noexcept
Definition graphicsview.cpp:110
GraphicsScene * getScene() const noexcept
Definition graphicsview.h:60
void wheelEvent(QWheelEvent *event)
Definition graphicsview.cpp:273
bool getUseOpenGl() const noexcept
Definition graphicsview.h:62
void showWaitingSpinner() noexcept
Definition graphicsview.cpp:250
void setInfoBoxText(const QString &text) noexcept
Definition graphicsview.cpp:155
bool eventFilter(QObject *obj, QEvent *event)
Definition graphicsview.cpp:281
QScopedPointer< QLabel > mInfoBoxLabel
Definition graphicsview.h:117
void setVisibleSceneRect(const QRectF &rect) noexcept
Definition graphicsview.cpp:151
qint64 getIdleTimeMs() const noexcept
Definition graphicsview.h:66
void setScene(GraphicsScene *scene) noexcept
Definition graphicsview.cpp:144
GraphicsScene * mScene
Definition graphicsview.h:119
Qt::MouseButtons mPressedMouseButtons
Definition graphicsview.h:126
bool isMouseButtonPressed(Qt::MouseButtons btn) const noexcept
Definition graphicsview.h:63
void setEventHandlerObject(IF_GraphicsViewEventHandler *eventHandler) noexcept
Definition graphicsview.cpp:161
The IF_GraphicsViewEventHandler class.
Definition if_graphicsvieweventhandler.h:45
A widget drawing a rotating spinner to indicate an ongoing operation.
Definition waitingspinnerwidget.h:52
Definition occmodel.cpp:77