-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemonstrationwindow.cpp
More file actions
133 lines (112 loc) · 3.87 KB
/
demonstrationwindow.cpp
File metadata and controls
133 lines (112 loc) · 3.87 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
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
#include "demonstrationwindow.h"
#include "ui_demonstrationwindow.h"
DemonstrationWindow::DemonstrationWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::DemonstrationWindow)
{
ui->setupUi(this);
ui->DescriptionTextBox->setText(Messages[0]);
}
DemonstrationWindow::~DemonstrationWindow()
{
delete ui;
}
void DemonstrationWindow::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter(this);
DrawGraph(&painter);
}
void DemonstrationWindow::DrawGraph(QPainter *painter)
{
// - Массив линий союдиняющих вершины
QVector<QLine> Lines = {QLine(200, 75, 350, 75),
QLine(100, 275, 250, 275),
QLine(300, 275, 450, 275),
QLine(75, 250, 175, 100),
QLine(275, 250, 375, 100),
QLine(475, 250, 375, 100),
QLine(275, 250, 175, 100)};
// - Массив вершин графа
QVector<QPoint> Vertexes = {QPoint(150+25, 50+25),
QPoint(350+25, 50+25),
QPoint(50+25, 250+25),
QPoint(250+25, 250+25),
QPoint(450+25, 250+25)};
// - Массив названий вершин
QVector<QString> VertexNames = {"a",
"e",
"b",
"c",
"d"};
// - Веса рёбер
QVector<QString> LineWeight = {"1",
"3",
"4",
"6",
"7",
"5",
"2"};
// - Кисть для рисования основная
QPen pen(Qt::black, 2, Qt::SolidLine);
// - Кисть для выделения
QPen pen_red(Qt::red, 4, Qt::SolidLine);
// - Рисуем вершины
painter -> setPen(pen);
for(int i = 0; i < Vertexes.size(); i++)
{
painter -> drawEllipse(Vertexes[i], 25, 25);
painter -> drawText(Vertexes[i], VertexNames[i]);
}
painter -> drawLines(Lines);
// - Рисуем веса рёбер
painter -> drawText(QPoint(275, 70), "1");
painter -> drawText(QPoint(100, 175), "3");
painter -> drawText(QPoint(230, 175), "4");
painter -> drawText(QPoint(300, 175), "6");
painter -> drawText(QPoint(450, 175), "7");
painter -> drawText(QPoint(175, 270), "5");
painter -> drawText(QPoint(375, 270), "2");
painter -> setPen(pen_red);
if(PageNumber >= 0)
{
painter -> drawEllipse(Vertexes[0], 25, 25);
}
if(PageNumber >= 1)
{
painter -> drawLine(Lines[0]);
painter -> drawLine(Lines[3]);
painter -> drawLine(Lines[6]);
}
if(PageNumber >= 2)
{
painter -> drawEllipse(Vertexes[1], 25, 25);
painter -> drawLine(Lines[5]);
}
if(PageNumber >= 3)
{
painter -> setPen(QPen(Qt::gray, 4, Qt::SolidLine));
painter -> drawLine(Lines[5]);
painter -> drawLine(Lines[1]);
painter -> drawLine(Lines[4]);
painter -> drawText(QPoint(300, 175), "6");
painter -> drawText(QPoint(450, 175), "7");
painter -> drawText(QPoint(175, 270), "5");
painter -> setPen(pen_red);
painter -> drawEllipse(Vertexes[2], 25, 25);
painter -> drawEllipse(Vertexes[3], 25, 25);
painter -> drawEllipse(Vertexes[4], 25, 25);
painter -> drawLine(Lines[2]);
}
}
void DemonstrationWindow::call_paint()
{
repaint();
}
void DemonstrationWindow::on_nextQuestion_clicked()
{
PageNumber++;
if(PageNumber < 4)
ui -> DescriptionTextBox -> setText(Messages[PageNumber]);
call_paint();
}