-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainWindow.cpp
162 lines (125 loc) · 3.56 KB
/
MainWindow.cpp
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
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QEvent>
#include <QMouseEvent>
#include <QGraphicsRectItem>
#include <QGraphicsLineItem>
#include <QGraphicsEllipseItem>
#include <QtCore>
#include <QtGui>
#include <iostream>
#include "Shape.h"
using std::cout;
using std::endl;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow), currentlySelectedTool(SELECT), m_scene(new Scene()), m_editManager(m_scene)
{
ui->setupUi(this);
ui->graphicsView->setScene(m_scene);
ui->actionSelect->setChecked(true);
ui->graphicsView->installEventFilter(this);
cout << sizeof(QGraphicsItem) << endl;
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
// Filtered MousePress from QGraphicsView
if (event->type() == QEvent::MouseButtonPress) {
if (currentlySelectedTool == LINE || currentlySelectedTool == CIRCLE || currentlySelectedTool == RECTANGLE) {
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
auto pos = ui->graphicsView->mapToScene(mouseEvent->pos());
QPointF size = QPointF(100, 100);
Shape::Type shapeType = Shape::LINE;
switch(currentlySelectedTool) {
case CIRCLE:
shapeType = Shape::CIRCLE;
size = QPointF(100, 100);
break;
case RECTANGLE:
shapeType = Shape::RECTANGLE;
size = QPointF(150, 100);
break;
}
m_editManager.createShape(shapeType, pos, size, QColor("black"));
return true;
}
}
return false;
}
void MainWindow::on_actionLine_triggered(bool checked)
{
changeCurrentlySelectedTool(currentlySelectedTool, LINE, ui->actionLine);
}
void MainWindow::on_actionRectangle_triggered(bool checked)
{
changeCurrentlySelectedTool(currentlySelectedTool, RECTANGLE, ui->actionRectangle);
}
void MainWindow::on_actionCircle_triggered(bool checked)
{
changeCurrentlySelectedTool(currentlySelectedTool, CIRCLE, ui->actionCircle);
}
void MainWindow::on_actionSelect_triggered(bool checked)
{
changeCurrentlySelectedTool(currentlySelectedTool, SELECT, ui->actionSelect);
}
void MainWindow::on_actionPan_triggered(bool checked)
{
changeCurrentlySelectedTool(currentlySelectedTool, PAN, ui->actionPan);
}
void MainWindow::changeCurrentlySelectedTool(CheckableTool oldTool, CheckableTool newTool, QAction* newToolAction)
{
if (oldTool == newTool) {
newToolAction->setChecked(true);
return;
}
QAction* action = nullptr;
switch(oldTool) {
case SELECT:
action = ui->actionSelect;
break;
case PAN:
action = ui->actionPan;
break;
case LINE:
action = ui->actionLine;
break;
case RECTANGLE:
action = ui->actionRectangle;
break;
case CIRCLE:
action = ui->actionCircle;
break;
}
if (action != nullptr) {
action->setChecked(false);
}
newToolAction->setChecked(true);
currentlySelectedTool = newTool;
}
void MainWindow::on_actionZoom_In_triggered()
{
}
void MainWindow::on_actionZoom_Out_triggered()
{
}
void MainWindow::on_actionZoom_All_triggered()
{
}
void MainWindow::on_actionDelete_triggered()
{
auto items = m_scene->selectedItems();
for (auto item : items) {
m_editManager.deleteShape(item);
}
}
void MainWindow::on_actionUndo_triggered()
{
m_editManager.undo();
}
void MainWindow::on_actionRedo_triggered()
{
m_editManager.redo();
}