-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathView.h
194 lines (148 loc) · 5.8 KB
/
View.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#ifndef VIEW_H
#define VIEW_H
#include "CoreLogic.h"
#include "Configuration.h"
#include "Gui/PieMenu.h"
#include "QtAwesome.h"
#include <QFrame>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QPropertyAnimation>
#include <QTabWidget>
#include <QButtonGroup>
#include <QGroupBox>
#include <QGridLayout>
// forward declarations
QT_BEGIN_NAMESPACE
class QLabel;
class QToolButton;
QT_END_NAMESPACE
class View;
class CoreLogic;
///
/// \brief The GraphicsView class extends QGraphicsView, which contains the main scene
///
class GraphicsView : public QGraphicsView
{
Q_OBJECT
public:
/// \brief Constructor for the GraphicsView class
/// \param pView: The frame to contain the GraphicsView
/// \param pCoreLogic: Reference to the core logic
GraphicsView(View &pView, CoreLogic &pCoreLogic);
signals:
/// \brief Emitted when the left mouse button is pressed without the CTRL key being down
/// \param pMappedPos: The mouse position mapped onto the scene
/// \param pEvent: The mouse event object of the event
void LeftMouseButtonPressedWithoutCtrlEvent(QPointF pMappedPos, QMouseEvent &pEvent);
public slots:
/// \brief This slot can be invoked to execute the default behavior for a QGraphicsView::mousePressEvent
/// \param pEvent: The mouse event to handle
void OnMousePressedEventDefault(QMouseEvent &pEvent);
protected:
/// \brief Handles mouse wheel events for zooming
/// \param pEvent: A mouse wheel event pointer
void wheelEvent(QWheelEvent *pEvent) override;
/// \brief Handles mouse press events for panning and editing
/// \param pEvent: A mouse press event pointer
void mousePressEvent(QMouseEvent *pEvent) override;
/// \brief Handles mouse move event for panning and wire drawing
/// \param pEvent: A mouse move event pointer
void mouseMoveEvent(QMouseEvent *pEvent) override;
/// \brief Handles mouse release event for moving components etc.
/// \param pEvent: A mouse release event pointer
void mouseReleaseEvent(QMouseEvent *pEvent) override;
/// \brief Prevents all double click interaction
/// \param pEvent: The associated double click event
void mouseDoubleClickEvent(QMouseEvent *pEvent) override;
protected:
View &mView;
CoreLogic &mCoreLogic;
QPoint mPanStart;
bool mIsLeftMousePressed;
bool mIsAddingWire;
bool mIsDragging;
};
///
/// \brief The View class contains the main canvas
///
class View : public QFrame
{
Q_OBJECT
public:
/// \brief Creator for the View class
/// \param pAwesome: Reference to the QtAwesome object
/// \param pCoreLogic: Reference to the core logic
View(QtAwesome &pAwesome, CoreLogic &pCoreLogic);
/// \brief Initializes the GraphicsView and sets up all signal/slot connections
void Init(void);
/// \brief Sets the displayed scene to the given scene
/// \param pScene: Reference to a QGraphicsScene
void SetScene(QGraphicsScene &pScene);
/// \brief Gets the main scene
/// \return Pointer to a QGraphicsScene
QGraphicsScene* Scene(void) const;
/// \brief Returns a list of pointers to all scene items
/// \return A QList of all items in mScene
QList<QGraphicsItem*> Components(void) const;
/// \brief Fades out the overlay that indicates that the SW is loading
void FadeOutProcessingOverlay(void);
/// \brief Fades in the overlay that indicates that the SW is loading
void FadeInProcessingOverlay(void);
/// \brief Resets zoom and position
void ResetViewport(void);
/// \brief Getter for the current zoom level
int32_t GetZoomLevel(void) const;
void ShowPieMenu(const QPoint &pPos);
void UpdatePieMenuIcons(void);
PieMenu* GetPieMenu(void);
signals:
/// \brief Emitted when the scene is zoomed in or out
/// \param pPercentage: The new zoom percentage
/// \param pValue: The new zoom value
void ZoomLevelChangedSignal(uint8_t pPercentage, uint32_t pValue);
void UndoFromPieMenuSignal(void);
void RedoFromPieMenuSignal(void);
public slots:
/// \brief Sets the zoom level and updates the displayed percentage
/// \param pZoomLevel: The new zoom level
void SetZoom(int32_t pZoomLevel);
/// \brief Increases the zoom level and updates the displayed percentage
/// \param pAmount: The amount to increase the zoom by
void ZoomIn(int32_t pAmount);
/// \brief Decreases the zoom level and updates the displayed percentage
/// \param pAmount: The amount to decrease the zoom by
void ZoomOut(int32_t pAmount);
/// \brief Disables buttons not available in simulation and disables component selection
void OnSimulationStart(void);
/// \brief Enables buttons available for editing and enables component selection
void OnSimulationStop(void);
/// \brief Sets or unsets the grid hide flag
/// \param pValue: The new flag status
void SetHideGrid(bool pValue);
protected slots:
/// \brief Applies the current transform to the GraphicsView and sets the scene background
void SetupMatrix(void);
protected:
/// \brief Creates a grid pattern for the canvas background
/// \param pZoomLevel: The zoom level decides whether to draw the grid or not
/// \return A pixel map containing a background grid tile
QPixmap DrawGridPattern(int32_t pZoomLevel);
void OnPieMenuButtonClicked(int8_t pButtonIndex);
protected:
GraphicsView mGraphicsView;
QGraphicsScene *mScene;
CoreLogic &mCoreLogic;
QtAwesome &mAwesome;
QVariantMap mStandardPieMenuIconVariant;
QVariantMap mDisabledPieMenuIconVariant;
QGridLayout *mMainLayout;
// Over-canvas elements
QWidget *mProcessingOverlay;
QLabel *mProcessingImage;
QGridLayout *mProcessingLayout;
PieMenu *mPieMenu;
int32_t mZoomLevel = canvas::DEFAULT_ZOOM_LEVEL;
bool mHideGrid = false;
};
#endif // VIEW_H