-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWnd.cpp
More file actions
106 lines (91 loc) · 3.39 KB
/
Copy pathMainWnd.cpp
File metadata and controls
106 lines (91 loc) · 3.39 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
#include "MainWnd.h"
#include <QHBoxLayout>
#include "ChooseDlg.h"
#include "SingleGame.h"
#include "MultiGame.h"
#include "NetGame.h"
#include "ChooseDlg.h"
#include <QCoreApplication>
#include <QString>
#include <QIcon>
#include <QProcess>
MainWnd::MainWnd(int gameType, QWidget *parent) : QWidget(parent)
{
//dlg.exec();
//_gameType = dlg._selected;
_gameType=gameType;
this->setWindowIcon(QIcon(":/img/images/logo.png"));
// this->setStyleSheet("MainWnd{border-image:url(:/img/images/ChooseBgd.png);}");
this->setAutoFillBackground(true); // 这句要加上, 否则可能显示不出背景图.
QPalette palette = this->palette();
palette.setBrush(QPalette::Window,
QBrush(QPixmap(":/img/images/ChooseBgd.png").scaled(// 缩放背景图.
this->size(),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation))); // 使用平滑的缩放方式
this->setPalette(palette); // 给widget加上背景图
CtrlPanel* panel = new CtrlPanel;
if(_gameType == 0)
{
this->setWindowTitle(QString("人机对战"));
SingleGame* game = new SingleGame;
panel->_cb->setVisible(true);
game->setCtrlPanel(panel);
QHBoxLayout* hLay = new QHBoxLayout(this);
hLay->addWidget(game, 1);
hLay->addWidget(panel);
connect(panel, SIGNAL(sigBack()), game, SLOT(slotBack()));
connect(panel, SIGNAL(sendsignal()), this, SLOT(slotreturn()));
connect(panel, SIGNAL(sigChangeIndex(int)), game, SLOT(slotChangeIndex(int)));
//connect(panel, SIGNAL(sigMusic()), this, SLOT(slotMusic()));
}
else if(_gameType == 1)
{
this->setWindowTitle(QString("双人对战"));
MultiGame* game = new MultiGame;
panel->_cb->setVisible(false);
// CtrlPanel* panel = new CtrlPanel;
game->setCtrlPanel(panel);
QHBoxLayout* hLay = new QHBoxLayout(this);
hLay->addWidget(game, 1);
hLay->addWidget(panel);
connect(panel, SIGNAL(sendsignal()), this, SLOT(slotreturn()));
connect(panel, SIGNAL(sigBack()), game, SLOT(slotBack()));
}
else if(_gameType == 2)
{ this->setWindowTitle(QString("网络对战(服务端)"));
NetGame* game = new NetGame(true);
panel->_cb->setVisible(false);
//CtrlPanel* panel = new CtrlPanel;
game->setCtrlPanel(panel);
QHBoxLayout* hLay = new QHBoxLayout(this);
hLay->addWidget(game, 1);
hLay->addWidget(panel);
connect(panel, SIGNAL(sendsignal()), this, SLOT(slotreturn()));
connect(panel, SIGNAL(sigBack()), game, SLOT(slotBack()));
}
else if(_gameType == 3)
{
this->setWindowTitle(QString("网络对战(客户端)"));
NetGame* game = new NetGame(false);
panel->_cb->setVisible(false);
// CtrlPanel* panel = new CtrlPanel;
game->setCtrlPanel(panel);
QHBoxLayout* hLay = new QHBoxLayout(this);
hLay->addWidget(game, 1);
hLay->addWidget(panel);
connect(panel, SIGNAL(sendsignal()), this, SLOT(slotreturn()));
connect(panel, SIGNAL(sigBack()), game, SLOT(slotBack()));
}
}
MainWnd::~MainWnd()
{
}
void MainWnd::slotExit(){
qApp->exit(0);
}
void MainWnd::slotreturn(){
//this->re
QProcess::startDetached(qApp->applicationFilePath(), QStringList());
qApp->exit(0);
}