-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChooseDlg.cpp
40 lines (34 loc) · 1.04 KB
/
ChooseDlg.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
#include "ChooseDlg.h"
#include <QVBoxLayout>
ChooseDlg::ChooseDlg(QWidget *parent) : QDialog(parent)
{
/* 创建 4 个按钮 */
QVBoxLayout* lay = new QVBoxLayout(this);
lay->addWidget(_buttons[0] = new QPushButton("人机对战"));
lay->addWidget(_buttons[1] = new QPushButton("人人对战"));
lay->addWidget(_buttons[2] = new QPushButton("网络对战(server)"));
lay->addWidget(_buttons[3] = new QPushButton("网络对战(client)"));
/* 把按钮关联到窗口上 */
for(int i=0; i<4; ++i)
{
connect(_buttons[i], SIGNAL(clicked()), this, SLOT(slotClicked()));
}
}
/* 将获取到的用户点击的按钮的编号传输给main.cpp,并调用对应函数创建窗口 */
void ChooseDlg::slotClicked()
{
/* 将被选中的棋子传递给 main ,由 main 创建对应的游戏窗口 */
QObject* s = sender();
for(int i=0; i<4; ++i)
{
if(_buttons[i] == s)
{
this->_selected = i;
break;
}
}
accept();
}
ChooseDlg::~ChooseDlg()
{
}