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 ******************************************************************************/
29
30#include <QtCore>
31#include <QtWidgets>
32
33#include <optional>
34
35/*******************************************************************************
36 * Namespace / Forward Declarations
37 ******************************************************************************/
38namespace librepcb {
39namespace editor {
40
41class GraphicsScene;
42class IF_GraphicsViewEventHandler;
43class WaitingSpinnerWidget;
44
45/*******************************************************************************
46 * Class GraphicsView
47 ******************************************************************************/
48
52class GraphicsView final : public QGraphicsView {
53 Q_OBJECT
54
55public:
56 // Types
57 enum class CursorOption {
58 Cross = (1 << 0),
59 Circle = (1 << 1),
60 };
61 Q_DECLARE_FLAGS(CursorOptions, CursorOption)
62
63 // Constructors / Destructor
64 GraphicsView(const GraphicsView& other) = delete;
65 explicit GraphicsView(
66 QWidget* parent = nullptr,
67 IF_GraphicsViewEventHandler* eventHandler = nullptr) noexcept;
68 ~GraphicsView() noexcept;
69
70 // Getters
71 GraphicsScene* getScene() const noexcept { return mScene; }
72 QRectF getVisibleSceneRect() const noexcept;
73 bool getUseOpenGl() const noexcept { return mUseOpenGl; }
74 const PositiveLength& getGridInterval() const noexcept {
75 return mGridInterval;
76 }
77 Theme::GridStyle getGridStyle() const noexcept { return mGridStyle; }
78 bool isMouseButtonPressed(Qt::MouseButtons btn) const noexcept {
79 return mPressedMouseButtons & btn;
80 }
81 qint64 getIdleTimeMs() const noexcept { return mIdleTimeMs; }
82
83 // Setters
84 void setBackgroundColors(const QColor& fill, const QColor& grid) noexcept;
85 void setOverlayColors(const QColor& fill, const QColor& content) noexcept;
86 void setInfoBoxColors(const QColor& fill, const QColor& text) noexcept;
87 void setUseOpenGl(bool useOpenGl) noexcept;
88 void setGrayOut(bool grayOut) noexcept;
89 void setGridStyle(Theme::GridStyle style) noexcept;
90 void setGridInterval(const PositiveLength& interval) noexcept;
91 void setScene(GraphicsScene* scene) noexcept;
92 void setVisibleSceneRect(const QRectF& rect) noexcept;
93
103 void setSceneRectMarker(const QRectF& rect) noexcept;
104 void setSceneCursor(
105 const std::optional<std::pair<Point, CursorOptions>>& cursor) noexcept;
107 const std::optional<std::pair<Point, Point>>& pos) noexcept;
108 void setInfoBoxText(const QString& text) noexcept;
109 void setOriginCrossVisible(bool visible) noexcept;
111 IF_GraphicsViewEventHandler* eventHandler) noexcept;
112
113 // General Methods
114 Point mapGlobalPosToScenePos(const QPoint& globalPosPx, bool boundToView,
115 bool mapToGrid) const noexcept;
116 QPainterPath calcPosWithTolerance(const Point& pos,
117 qreal multiplier = 1) const noexcept;
118 void handleMouseWheelEvent(QGraphicsSceneWheelEvent* event) noexcept;
119
120 // Operator Overloadings
121 GraphicsView& operator=(const GraphicsView& rhs) = delete;
122
123public slots:
124
125 // Public Slots
126 void zoomIn() noexcept;
127 void zoomOut() noexcept;
128 void zoomAll() noexcept;
129 void zoomToRect(const QRectF& rect) noexcept;
130 void showWaitingSpinner() noexcept;
131 void hideWaitingSpinner() noexcept;
132
133signals:
140
141private slots:
142
143 // Private Slots
144 void zoomAnimationValueChanged(const QVariant& value) noexcept;
145
146private:
147 // Inherited Methods
148 void wheelEvent(QWheelEvent* event);
149 bool eventFilter(QObject* obj, QEvent* event);
150 void drawBackground(QPainter* painter, const QRectF& rect);
151 void drawForeground(QPainter* painter, const QRectF& rect);
152
153 // General Attributes
155 QScopedPointer<QLabel> mInfoBoxLabel;
158 QVariantAnimation* mZoomAnimation;
159 Theme::GridStyle mGridStyle;
169
171 std::optional<std::pair<Point, CursorOptions>> mSceneCursor;
172
173 // Configuration for the ruler overlay
181 QVector<RulerGauge> mRulerGauges;
182 std::optional<std::pair<Point, Point>> mRulerPositions;
183
184 // State
185 volatile bool mPanningActive;
186 Qt::MouseButton mPanningButton;
187 Qt::MouseButtons mPressedMouseButtons;
190
191 // Static Variables
192 static constexpr qreal sZoomStepFactor = 1.3;
193};
194
195/*******************************************************************************
196 * End of File
197 ******************************************************************************/
198
199} // namespace editor
200} // namespace librepcb
201
202#endif
The Circle class.
Definition circle.h:46
The Length class is used to represent a length (for example 12.75 millimeters)
Definition length.h:82
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition lengthunit.h:60
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
Theme class as used by librepcb::WorkspaceSettingsItem_Themes.
Definition theme.h:44
GridStyle
Definition theme.h:49
The GraphicsScene class.
Definition graphicsscene.h:45
The GraphicsView class.
Definition graphicsview.h:52
void zoomToRect(const QRectF &rect) noexcept
Definition graphicsview.cpp:316
QCursor mCursorBeforePanning
Definition graphicsview.h:188
std::optional< std::pair< Point, CursorOptions > > mSceneCursor
If not nullopt, a cursor will be shown at the given position.
Definition graphicsview.h:171
Theme::GridStyle getGridStyle() const noexcept
Definition graphicsview.h:77
bool mUseOpenGl
Definition graphicsview.h:167
void zoomAll() noexcept
Definition graphicsview.cpp:305
QColor mOverlayFillColor
Definition graphicsview.h:163
void setRulerPositions(const std::optional< std::pair< Point, Point > > &pos) noexcept
Definition graphicsview.cpp:212
QColor mGridColor
Definition graphicsview.h:162
QVector< RulerGauge > mRulerGauges
Definition graphicsview.h:181
PositiveLength mGridInterval
Definition graphicsview.h:160
const PositiveLength & getGridInterval() const noexcept
Definition graphicsview.h:74
void setGridStyle(Theme::GridStyle style) noexcept
Definition graphicsview.cpp:179
QPainterPath calcPosWithTolerance(const Point &pos, qreal multiplier=1) const noexcept
Definition graphicsview.cpp:253
IF_GraphicsViewEventHandler * mEventHandlerObject
Definition graphicsview.h:156
void setUseOpenGl(bool useOpenGl) noexcept
Definition graphicsview.cpp:153
void setOriginCrossVisible(bool visible) noexcept
Definition graphicsview.cpp:224
void hideWaitingSpinner() noexcept
Definition graphicsview.cpp:329
void zoomOut() noexcept
Definition graphicsview.cpp:299
void zoomAnimationValueChanged(const QVariant &value) noexcept
Definition graphicsview.cpp:337
Theme::GridStyle mGridStyle
Definition graphicsview.h:159
void setSceneCursor(const std::optional< std::pair< Point, CursorOptions > > &cursor) noexcept
Definition graphicsview.cpp:206
void setSceneRectMarker(const QRectF &rect) noexcept
Setup the marker for a specific scene rect.
Definition graphicsview.cpp:201
void handleMouseWheelEvent(QGraphicsSceneWheelEvent *event) noexcept
Definition graphicsview.cpp:265
QScopedPointer< WaitingSpinnerWidget > mWaitingSpinnerWidget
Definition graphicsview.h:154
QColor mOverlayContentColor
Definition graphicsview.h:164
void setOverlayColors(const QColor &fill, const QColor &content) noexcept
Definition graphicsview.cpp:133
QRectF getVisibleSceneRect() const noexcept
Definition graphicsview.cpp:117
Qt::MouseButton mPanningButton
Definition graphicsview.h:186
void setGrayOut(bool grayOut) noexcept
Definition graphicsview.cpp:174
void cursorScenePositionChanged(const Point &pos)
Cursor scene position changed signal.
bool mGrayOut
Definition graphicsview.h:168
void drawBackground(QPainter *painter, const QRectF &rect)
Definition graphicsview.cpp:449
bool mOriginCrossVisible
Definition graphicsview.h:166
qint64 mIdleTimeMs
Definition graphicsview.h:189
void zoomIn() noexcept
Definition graphicsview.cpp:293
static constexpr qreal sZoomStepFactor
Definition graphicsview.h:192
QVariantAnimation * mZoomAnimation
Definition graphicsview.h:158
volatile bool mPanningActive
Definition graphicsview.h:185
void setBackgroundColors(const QColor &fill, const QColor &grid) noexcept
Definition graphicsview.cpp:125
void drawForeground(QPainter *painter, const QRectF &rect)
Definition graphicsview.cpp:498
void setInfoBoxColors(const QColor &fill, const QColor &text) noexcept
Definition graphicsview.cpp:140
GraphicsScene * getScene() const noexcept
Definition graphicsview.h:71
QRectF mSceneRectMarker
Definition graphicsview.h:165
std::optional< std::pair< Point, Point > > mRulerPositions
Definition graphicsview.h:182
void wheelEvent(QWheelEvent *event)
Definition graphicsview.cpp:348
bool getUseOpenGl() const noexcept
Definition graphicsview.h:73
CursorOption
Definition graphicsview.h:57
void showWaitingSpinner() noexcept
Definition graphicsview.cpp:325
void setInfoBoxText(const QString &text) noexcept
Definition graphicsview.cpp:218
bool eventFilter(QObject *obj, QEvent *event)
Definition graphicsview.cpp:356
QScopedPointer< QLabel > mInfoBoxLabel
Definition graphicsview.h:155
void setVisibleSceneRect(const QRectF &rect) noexcept
Definition graphicsview.cpp:197
qint64 getIdleTimeMs() const noexcept
Definition graphicsview.h:81
Point mapGlobalPosToScenePos(const QPoint &globalPosPx, bool boundToView, bool mapToGrid) const noexcept
Definition graphicsview.cpp:238
void setGridInterval(const PositiveLength &interval) noexcept
Definition graphicsview.cpp:184
QColor mBackgroundColor
Definition graphicsview.h:161
void setScene(GraphicsScene *scene) noexcept
Definition graphicsview.cpp:189
GraphicsScene * mScene
Definition graphicsview.h:157
Qt::MouseButtons mPressedMouseButtons
Definition graphicsview.h:187
bool isMouseButtonPressed(Qt::MouseButtons btn) const noexcept
Definition graphicsview.h:78
void setEventHandlerObject(IF_GraphicsViewEventHandler *eventHandler) noexcept
Definition graphicsview.cpp:229
The IF_GraphicsViewEventHandler class.
Definition if_graphicsvieweventhandler.h:41
A widget drawing a rotating spinner to indicate an ongoing operation.
Definition waitingspinnerwidget.h:52
Definition occmodel.cpp:76
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
Definition uuid.h:186
Definition graphicsview.h:174
QString unitSeparator
Definition graphicsview.h:177
LengthUnit unit
Definition graphicsview.h:176
Length currentTickInterval
Definition graphicsview.h:179
int xScale
Definition graphicsview.h:175
Length minTickInterval
Definition graphicsview.h:178