-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
155 lines (126 loc) · 4.03 KB
/
Copy pathmainwindow.cpp
File metadata and controls
155 lines (126 loc) · 4.03 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTextBrowser>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowTitle("OpenDota_API v1.0");
this->setStyleSheet("background-color: #ffecf3;");
req = new Requester();
createContacts();
createFinderLine();
createTable();
line_finder->setStyleSheet("color : red;padding: 3px; background-color: white; border: 1px solid #CCCCCC; border-radius: 3px;");
team_table->setStyleSheet("color : green;background-color: black; border: 1px solid #CCCCCC;");
count_label->setStyleSheet("font-weight: bold; font-size: 12px; color: #333333;");
this->setFixedSize(360,600);
QPixmap pix_dota(":/dota2.png");
QLabel *logo = new QLabel(this);
logo->setPixmap(pix_dota);
logo->setFixedSize(pix_dota.size());
logo->move(320,5);
connect(req, SIGNAL(teamsReady()), this, SLOT(takeTeamsData()));
connect(req, SIGNAL(heroesReady()), this, SLOT(takeTeamsHeros()));
connect(contacts_button, SIGNAL(clicked()), this, SLOT(show_contacts()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::createFinderLine()
{
line_finder = new QLineEdit(this);
line_finder->setGeometry(50,20,200,20);
connect(line_finder, &QLineEdit::returnPressed, this, &MainWindow::find);
QLabel *search = new QLabel(this);
search->setText("Search:");
search->setGeometry(5,20,55,20);
search->setStyleSheet("color : black");
count_label = new QLabel(this);
count_label->setGeometry(250,20,70,20);
}
void MainWindow::createTable()
{
team_table = new QTableWidget(this);
team_table->setGeometry(5,50,340,500);
team_table->setColumnCount(1);
team_table->setColumnWidth(0,290);
QStringList horHeaders;
horHeaders << "team name";
team_table->setHorizontalHeaderLabels(horHeaders);
}
void MainWindow::fillTable(QTableWidget *table, QMap<QString, int> &list)
{
int row = 0;
table_rows = list.size();
table->setRowCount(table_rows);
for(auto it = list.begin(); it != list.end(); it++)
{
if(it.key().isEmpty())
continue;
QTableWidgetItem *name = new QTableWidgetItem(it.key());
name->setFlags(name->flags() | Qt::ItemIsSelectable);
table->setItem(row,0,name);
++row;
}
}
void MainWindow::createContacts()
{
contacts_button = new QPushButton(this);
contacts_button->setText("Contacts");
contacts_button->setStyleSheet("color : green; background-color : #ff8bb4");
contacts_button->setGeometry(20,570,60,20);
}
void MainWindow::takeTeamsData()
{
container = req->container;
fillTable(team_table, container->team_list);
connect(team_table, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(teamVote(QTableWidgetItem*)));
}
void MainWindow::takeTeamsHeros()
{
QList<Hero*> h = container->heroByTeam.value(current_team_id);
icon = new TeamIcon(curr_team_name, h);
icon->exec();
}
void MainWindow::find()
{
QString search = line_finder->text();
int count_of_finders = 0;
for(int row = 0; row < table_rows; row++)
{
QTableWidgetItem *name = team_table->item(row,0);
if(name && name->text().contains(search, Qt::CaseInsensitive))
{
team_table->setRowHidden(row, false);
count_of_finders++;
}
else
{
team_table->setRowHidden(row,true);
}
}
count_label->setText(QString(" : %1 items").arg(count_of_finders));
}
void MainWindow::teamVote(QTableWidgetItem *item)
{
QString name = item->text();
curr_team_name = name;
auto it = container->team_list.find(name);
if(it != container->team_list.end())
{
int id = it.value();
current_team_id = id;
req->get_heroes(id);
}
else
{
qDebug() << "Something is wrong with key searcher";
}
}
void MainWindow::show_contacts()
{
QMessageBox::information(this, "Contacts", "Github: https://github.com/AlexeyProg", QMessageBox::Ok);
}