LibrePCB Developers Documentation
Loading...
Searching...
No Matches
graphicsscene.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_GRAPHICSSCENE_H
21#define LIBREPCB_EDITOR_GRAPHICSSCENE_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
41/*******************************************************************************
42 * Event Data Structs
43 ******************************************************************************/
44
48 Qt::MouseButtons buttons = Qt::MouseButtons();
49 Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers();
50};
51
53 int key = 0;
54 Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers();
55};
56
57/*******************************************************************************
58 * Class GraphicsScene
59 ******************************************************************************/
60
64class GraphicsScene : public QGraphicsScene {
65 Q_OBJECT
66
67public:
68 // Constructors / Destructor
69 explicit GraphicsScene(QObject* parent = nullptr) noexcept;
70 virtual ~GraphicsScene() noexcept;
71
72 // Getters
73 const PositiveLength& getGridInterval() const noexcept {
74 return mGridInterval;
75 }
76 Theme::GridStyle getGridStyle() const noexcept { return mGridStyle; }
77
78 // Setters
79 void setBackgroundColors(const QColor& fill, const QColor& grid) noexcept;
80 void setOverlayColors(const QColor& fill, const QColor& content) noexcept;
81 void setSelectionRectColors(const QColor& line, const QColor& fill) noexcept;
82 void setGridStyle(Theme::GridStyle style) noexcept;
83 void setGridInterval(const PositiveLength& interval) noexcept;
84 void setOriginCrossVisible(bool visible) noexcept;
85 void setGrayOut(bool grayOut) noexcept;
86
87 // General Methods
88 void setSelectionRect(const Point& p1, const Point& p2) noexcept;
89 void clearSelectionRect() noexcept;
99 void setSceneRectMarker(const QRectF& rect) noexcept;
100 void setSceneCursor(const Point& pos, bool cross, bool circle) noexcept;
102 const std::optional<std::pair<Point, Point>>& pos) noexcept;
103
104 void addItem(QGraphicsItem& item) noexcept;
105 void removeItem(QGraphicsItem& item) noexcept;
106
107 QPixmap toPixmap(int dpi,
108 const QColor& background = Qt::transparent) noexcept;
109 QPixmap toPixmap(const QSize& size,
110 const QColor& background = Qt::transparent) noexcept;
111
112protected:
113 void drawBackground(QPainter* painter, const QRectF& rect) noexcept override;
114 void drawForeground(QPainter* painter, const QRectF& rect) noexcept override;
115
116private:
117 Theme::GridStyle mGridStyle;
126
127 std::unique_ptr<QGraphicsRectItem> mSelectionRectItem;
128
129 // Overlay scene cursor
133
134 // Configuration for the ruler overlay
142 QVector<RulerGauge> mRulerGauges;
143 std::optional<std::pair<Point, Point>> mRulerPositions;
144};
145
146/*******************************************************************************
147 * End of File
148 ******************************************************************************/
149
150} // namespace editor
151} // namespace librepcb
152
153#endif
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:62
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:64
Theme::GridStyle getGridStyle() const noexcept
Definition graphicsscene.h:76
QColor mOverlayFillColor
Definition graphicsscene.h:121
void setRulerPositions(const std::optional< std::pair< Point, Point > > &pos) noexcept
Definition graphicsscene.cpp:163
QColor mGridColor
Definition graphicsscene.h:120
QVector< RulerGauge > mRulerGauges
Definition graphicsscene.h:142
PositiveLength mGridInterval
Definition graphicsscene.h:118
const PositiveLength & getGridInterval() const noexcept
Definition graphicsscene.h:73
std::unique_ptr< QGraphicsRectItem > mSelectionRectItem
Definition graphicsscene.h:127
void setGridStyle(Theme::GridStyle style) noexcept
Definition graphicsscene.cpp:92
void clearSelectionRect() noexcept
Definition graphicsscene.cpp:159
bool mSceneCursorCross
Definition graphicsscene.h:131
void setOriginCrossVisible(bool visible) noexcept
Definition graphicsscene.cpp:106
void addItem(QGraphicsItem &item) noexcept
Definition graphicsscene.cpp:132
void setSelectionRectColors(const QColor &line, const QColor &fill) noexcept
Definition graphicsscene.cpp:147
Theme::GridStyle mGridStyle
Definition graphicsscene.h:117
void setSceneRectMarker(const QRectF &rect) noexcept
Setup the marker for a specific scene rect.
Definition graphicsscene.cpp:113
QPixmap toPixmap(int dpi, const QColor &background=Qt::transparent) noexcept
Definition graphicsscene.cpp:169
virtual ~GraphicsScene() noexcept
Definition graphicsscene.cpp:70
QColor mOverlayContentColor
Definition graphicsscene.h:122
void setOverlayColors(const QColor &fill, const QColor &content) noexcept
Definition graphicsscene.cpp:85
void setGrayOut(bool grayOut) noexcept
Definition graphicsscene.cpp:142
bool mGrayOut
Definition graphicsscene.h:125
bool mOriginCrossVisible
Definition graphicsscene.h:124
void setBackgroundColors(const QColor &fill, const QColor &grid) noexcept
Definition graphicsscene.cpp:78
QRectF mSceneRectMarker
Definition graphicsscene.h:123
void removeItem(QGraphicsItem &item) noexcept
Definition graphicsscene.cpp:137
Point mSceneCursorPos
Definition graphicsscene.h:130
std::optional< std::pair< Point, Point > > mRulerPositions
Definition graphicsscene.h:143
void drawBackground(QPainter *painter, const QRectF &rect) noexcept override
Definition graphicsscene.cpp:192
bool mSceneCursorCircle
Definition graphicsscene.h:132
void setSceneCursor(const Point &pos, bool cross, bool circle) noexcept
Definition graphicsscene.cpp:120
void setSelectionRect(const Point &p1, const Point &p2) noexcept
Definition graphicsscene.cpp:153
void drawForeground(QPainter *painter, const QRectF &rect) noexcept override
Definition graphicsscene.cpp:243
void setGridInterval(const PositiveLength &interval) noexcept
Definition graphicsscene.cpp:99
QColor mBackgroundColor
Definition graphicsscene.h:119
Definition occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
Definition uuid.h:186
Definition graphicsscene.h:135
QString unitSeparator
Definition graphicsscene.h:138
LengthUnit unit
Definition graphicsscene.h:137
Length currentTickInterval
Definition graphicsscene.h:140
int xScale
Definition graphicsscene.h:136
Length minTickInterval
Definition graphicsscene.h:139
Definition graphicsscene.h:52
int key
Definition graphicsscene.h:53
Qt::KeyboardModifiers modifiers
Definition graphicsscene.h:54
Definition graphicsscene.h:45
Qt::KeyboardModifiers modifiers
Definition graphicsscene.h:49
Qt::MouseButtons buttons
Definition graphicsscene.h:48
Point scenePos
Definition graphicsscene.h:46
Point downPos
Definition graphicsscene.h:47