-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
95 lines (86 loc) · 2.88 KB
/
Copy pathMainWindow.cpp
File metadata and controls
95 lines (86 loc) · 2.88 KB
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
#include "MainWindow.h"
#include <iostream>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
comboBox_(new QComboBox(this))
{
resize(1200, 800);
controller_.AddPolygon(Polygon({{-10, -10}, {-10, 1010}, {1930, 1010}, {1930, -10}}));
comboBox_.addItem("polygons");
comboBox_.addItem("light");
comboBox_.addItem("static lights");
comboBox_.setFixedSize(100, 30);
setFocus();
setMouseTracking(true);
connect(&comboBox_, &QComboBox::currentTextChanged, [this]() {
setFocus();
});
}
void MainWindow::mousePressEvent(QMouseEvent *event) {
if (comboBox_.currentText() == "polygons") {
if (event->button() == Qt::LeftButton) {
if (controller_.getNewPol()) {
controller_.setNewPol(false);
std::vector<QPointF> vertices;
vertices.emplace_back(event->pos());
controller_.AddPolygon(Polygon(vertices));
} else {
controller_.AddVertexToLastPolygon(event->pos());
}
}
if (event->button() == Qt::RightButton) {
controller_.setNewPol(true);
}
}
if (comboBox_.currentText() == "static lights") {
if (event->button() == Qt::LeftButton) {
controller_.addStaticLights(event->pos());
}
}
update();
}
void MainWindow::paintEvent(QPaintEvent *event) {
QPainter painter(this);
QPen pen;
pen.setWidthF(3);
painter.fillRect(0, 0, 1920, 1000, Qt::black);
pen.setColor(Qt::white);
painter.setPen(pen);
controller_.drawPolygons(painter);
pen.setColor(Qt::yellow);
painter.setPen(pen);
controller_.drawStaticLights(painter);
if (comboBox_.currentText() == "light") {
pen.setColor(Qt::red);
painter.setPen(pen);
painter.drawEllipse(controller_.getLightSource(), 1.5, 1.5);
controller_.drawLightAreas(painter);
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *event) {
if (comboBox_.currentText() == "light") {
controller_.setLightSource(event->pos());
controller_.setLightSources(event->pos());
for (int i = 0; i < controller_.getLightSources().size(); ++i) {
update();
}
}
update();
}
void MainWindow::keyPressEvent(QKeyEvent *event) {
if (comboBox_.currentText() == "polygons") {
if ((event->key() == Qt::Key_Z) && (event->modifiers() & Qt::ControlModifier)) {
controller_.EraseLastVertexInLastPolygon();
update();
}
}
if (comboBox_.currentText() == "static lights") {
if ((event->key() == Qt::Key_Z) && (event->modifiers() & Qt::ControlModifier)) {
controller_.EraseLastStaticLights();
update();
}
}
if (event->key() == Qt::Key_Escape) {
close();
}
}