中国象棋控件 v2.0.13
载入中...
搜索中...
未找到
MainWindow.cpp
1#include "MainWindow.h"
2#include "./ui_MainWindow.h"
3
4#include "RabbitCommonDir.h"
5#include "RabbitCommonTools.h"
6#include "DlgAbout.h"
7#include "FrmUpdater.h"
8
9#include <QCursor>
10
11MainWindow::MainWindow(QWidget *parent)
12 : QMainWindow(parent)
13 , ui(new Ui::MainWindow)
14{
15 ui->setupUi(this);
16 RabbitCommon::CTools::AddStyleMenu(ui->menuTools);
17 ui->menuTools->addMenu(RabbitCommon::CTools::GetLogMenu(this));
18 m_pChess = new CFrmChineseChess(this);
19 //m_pChess->SetBoardLayout(CChineseChess::TopRedAndBottomBlack);
20 this->setCentralWidget(m_pChess);
21 ui->actionPrompt_sound_S->setChecked(m_pChess->getEnablePromptSound());
22 ui->actionPrompt_message_M->setChecked(m_pChess->getEnablePromptMessage());
23
24 CFrmUpdater updater;
25 ui->actionUpdate_U->setIcon(updater.windowIcon());
26}
27
28MainWindow::~MainWindow()
29{
30 delete ui;
31}
32
33void MainWindow::on_actionOpen_O_triggered()
34{
35 if(!m_pChess) return;
36 QString szFile = QFileDialog::getOpenFileName(this, tr("Open chess game"));
37 m_pChess->LoadChessGame(szFile.toStdString().c_str());
38 m_pChess->update();
39}
40
41void MainWindow::on_actionSave_S_triggered()
42{
43 if(!m_pChess) return;
44 QString szFile = QFileDialog::getSaveFileName(this,
45 tr("Open chess game"),
46 QString(),
47 tr("Chinese chess control file(*.ccc);;Portable game notation file(*.pgn);;All files(*.*)"));
48 m_pChess->SaveChessGame(szFile.toStdString().c_str());
49}
50
51void MainWindow::on_actionPreviou_P_triggered()
52{
53 if(m_pChess)
54 m_pChess->PreviouStep();
55}
56
57void MainWindow::on_actionNext_N_triggered()
58{
59 if(m_pChess)
60 m_pChess->NextStep();
61}
62
63void MainWindow::on_actionExit_E_triggered()
64{
65 qApp->exit();
66}
67
68void MainWindow::on_actionAbout_A_triggered()
69{
70 QCursor cursor = this->cursor();
71 setCursor(Qt::WaitCursor);
72 CDlgAbout about(this);
73 about.m_AppIcon = QImage(":/image/Chess");
74 about.m_szAppName = tr("Chinese chess");
75 about.m_szHomePage = "https://github.com/KangLin/ChineseChessControl";
76 about.m_szCopyrightStartTime = "1994";
77 about.m_szVersion = ChineseChessApp_VERSION;
78 about.m_szVersionRevision = ChineseChessApp_REVISION;
79 if(about.isHidden())
80#if defined (Q_OS_ANDROID)
81 about.showMaximized();
82#endif
83 about.exec();
84 setCursor(cursor);
85}
86
87void MainWindow::on_actionPrompt_sound_S_triggered(bool checked)
88{
89 if(m_pChess)
90 m_pChess->EnablePromptSound(checked);
91}
92
93void MainWindow::on_actionPrompt_message_M_triggered(bool checked)
94{
95 if(m_pChess)
96 m_pChess->EnablePromptMessage(checked);
97}
98
99void MainWindow::on_actionUpdate_U_triggered()
100{
101 CFrmUpdater* m_pfrmUpdater = new CFrmUpdater();
102 m_pfrmUpdater->SetTitle(QImage(":/image/Chess"));
103 #if defined (Q_OS_ANDROID)
104 m_pfrmUpdater->showMaximized();
105 #else
106 m_pfrmUpdater->show();
107 #endif
108}
int PreviouStep()
函数名:PreviouStep 功 能:上步棋 参 数:无 返回值:走棋步数 作 者:康 林 版 本:1.0.0.1 日 期:2004-10-5 时 间:10:19:51
virtual int LoadChessGame(const char *pszFile)
加载棋局。 根据文件扩展名来解析文件的格式。 当前支持自定义格式、PGN格式
int NextStep()
函数名:NextStep 功 能:下步棋 参 数:无 返回值:走棋步数 作 者:康 林 版 本:1.0.0.1 日 期:2004-10-5 时 间:10:19:33
virtual int SaveChessGame(const char *pszFile)
保存棋局。 根据文件扩展名来保存为相应的格式。 当前支持自定义格式、PGN格式
中国象棋窗体,完成中国象棋的界面