Repository navigation
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
executable file
·93 lines (87 loc) · 2.52 KB
/
Copy pathmainwindow.cpp
File metadata and controls
executable file
·93 lines (87 loc) · 2.52 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
#include "mainwindow.h"
#include "dialog.h"
#include "ui_mainwindow.h"
#include "enterrefractiveindex.h"
#include "polygon.h"
#include "raydrawer.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
plane(new GeogebraPlane())
{
ui->setupUi(this);
// QDesktopWidget *widget = QApplication::desktop();
int width = this->width(); // returns desktop width
int height = this->height(); // returns desktop height
setFixedSize(width, height);
graphics_view_ = ui->graphicsView;
auto size = graphics_view_->size();
scene_ = new QGraphicsScene(0, 0, size.width() - 2, size.height() - 2);
graphics_view_->setScene(scene_);
graphics_view_->setRenderHint(QPainter::Antialiasing);
plane->SetParams(graphics_view_, scene_, this);
QObject::connect(plane, SIGNAL(ErrorDuringAddingPoint(QString)), this, SLOT(OpenDialogWindow(QString)));
QObject::connect(plane, SIGNAL(FinishEnteringPolygon(Polygon*)), this, SLOT(ActionEnteringPolygonEnded(Polygon*)));
QObject::connect(graphics_view_, SIGNAL(PressLeftMouseButton(QPoint)), this, SLOT(ActionLeftMouseButtonPressed(QPoint)));
}
MainWindow::~MainWindow()
{
delete ui;
delete scene_;
delete graphics_view_;
delete plane;
}
void MainWindow::OpenDialogWindow(QString text)
{
Dialog dialog;
dialog.SetText(text);
dialog.show();
dialog.exec();
}
void MainWindow::OpenRefractiveIndexEnteringWindow(Polygon *polygon)
{
EnterRefractiveIndex dialog;
dialog.SetPolygon(polygon);
dialog.show();
dialog.exec();
}
void MainWindow::ActionLeftMouseButtonPressed(QPoint point)
{
if (status_ == EnteringStatus::WAITING)
{
if (ui->pushButton->GetStatus())
{
status_ = EnteringStatus::ENTERINGRAY;
}
else
{
status_ = EnteringStatus::ENTERINGPOLYGON;
}
}
if (status_ == EnteringStatus::ENTERINGPOLYGON)
{
plane->AddPoint(point);
}
else
{
ray_points_.push_back(point);
if (ray_points_.size() == 2)
{
rays_.push_back({ray_points_[0], ray_points_[1]});
status_ = EnteringStatus::WAITING;
ray_points_.clear();
}
}
scene_->clear();
plane->UpdateScene();
for (const auto& ray: rays_)
{
RayDrawer drawer(ray, plane);
drawer.TrassRay();
}
}
void MainWindow::ActionEnteringPolygonEnded(Polygon* polygon)
{
status_ = EnteringStatus::WAITING;
OpenRefractiveIndexEnteringWindow(polygon);
}