中国象棋控件 2.0.15
载入中...
搜索中...
未找到
MainWindow.cpp
1#include <QMessageBox>
2#include <QCursor>
3#include <QToolButton>
4#include "RabbitCommonDir.h"
5#include "RabbitCommonTools.h"
6#include "DlgAbout.h"
7#include "FrmUpdater.h"
8
9#include "MainWindow.h"
10#include "./ui_MainWindow.h"
11
12MainWindow::MainWindow(QWidget *parent)
13 : QMainWindow(parent)
14 , m_Chess(this)
15 , ui(new Ui::MainWindow)
16{
17 ui->setupUi(this);
18 RabbitCommon::CTools::AddStyleMenu(ui->menuTools);
19 ui->menuTools->addMenu(RabbitCommon::CTools::GetLogMenu(this));
20
21#if defined(Q_OS_ANDROID) && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
22 auto pTbMenu = new QToolButton(ui->toolBar);
23 pTbMenu->setFocusPolicy(Qt::NoFocus);
24 pTbMenu->setPopupMode(QToolButton::InstantPopup);
25 //m_pTbMenu->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
26 pTbMenu->setText(tr("menu")); //tr("⋮"));
27 pTbMenu->setIcon(QIcon::fromTheme("menu"));
28 pTbMenu->setToolTip(tr("menu"));
29 pTbMenu->setStatusTip(tr("menu"));
30 QMenu *pMenu = new QMenu(pTbMenu);
31 pMenu->addActions(this->menuBar()->actions());
32 pTbMenu->setMenu(pMenu);
33 ui->toolBar->addWidget(pTbMenu);
34#endif
35
36 //m_Chess.SetBoardLayout(CChineseChess::TopRedAndBottomBlack);
37 this->setCentralWidget(&m_Chess);
38 ui->actionPrompt_sound_S->setChecked(m_Chess.getEnablePromptSound());
39 ui->actionPrompt_message_M->setChecked(m_Chess.getEnablePromptMessage());
40
41 CFrmUpdater updater;
42 ui->actionUpdate_U->setIcon(updater.windowIcon());
43#if !defined(Q_OS_ANDROID)
44 RabbitCommon::CTools::Instance()->RestoreWidget(this);
45#endif
46}
47
48MainWindow::~MainWindow()
49{
50 delete ui;
51}
52
53void MainWindow::closeEvent(QCloseEvent *event)
54{
55#if !defined(Q_OS_ANDROID)
56 RabbitCommon::CTools::Instance()->SaveWidget(this);
57#endif
58 QMainWindow::closeEvent(event);
59}
60
61void MainWindow::on_actionOpen_O_triggered()
62{
63 QString szFile = QFileDialog::getOpenFileName(this, tr("Open chess game"));
64 if(szFile.isEmpty()) return;
65 int nRet = m_Chess.LoadChessGame(szFile.toStdString().c_str());
66 if(nRet) return;
67 QMessageBox::information(
68 this, "Load chess game",
69 tr("Load chess game from file %1 successfully!").arg(szFile));
70 m_Chess.update();
71}
72
73void MainWindow::on_actionSave_S_triggered()
74{
75 QString szFile = QFileDialog::getSaveFileName(
76 this, tr("Save chess game"), QString(),
77 tr("Chinese chess control file(*.ccc);; Portable game notation file(*.pgn);; All files(*.*)"));
78 if(szFile.isEmpty()) return;
79 int nRet = m_Chess.SaveChessGame(szFile.toStdString().c_str());
80 if(nRet) return;
81 QMessageBox::information(
82 this, tr("Save chess game"),
83 tr("Save chess game to file %1 successfully!").arg(szFile));
84}
85
86void MainWindow::on_actionPrevious_P_triggered()
87{
88 m_Chess.PreviouStep();
89}
90
91void MainWindow::on_actionNext_N_triggered()
92{
93 m_Chess.NextStep();
94}
95
96void MainWindow::on_actionExit_E_triggered()
97{
98 qApp->exit();
99}
100
101void MainWindow::on_actionAbout_A_triggered()
102{
103 CDlgAbout* pAbout = new CDlgAbout(this);
104 pAbout->m_AppIcon = QImage(":/image/Chess");
105 pAbout->m_szAppName = tr("Chinese chess");
106 pAbout->m_szHomePage = "https://github.com/KangLin/ChineseChessControl";
107 pAbout->m_szCopyrightStartTime = "1994";
108#ifdef ChineseChessApp_VERSION
109 pAbout->m_szVersion = ChineseChessApp_VERSION;
110#endif
111#ifdef ChineseChessApp_REVISION
112 pAbout->m_szVersionRevision = ChineseChessApp_REVISION;
113#endif
114 RC_SHOW_WINDOW(pAbout);
115
116 //m_Chess.AboutBox();
117}
118
119void MainWindow::on_actionPrompt_sound_S_triggered(bool checked)
120{
121 m_Chess.EnablePromptSound(checked);
122}
123
124void MainWindow::on_actionPrompt_message_M_triggered(bool checked)
125{
126 m_Chess.EnablePromptMessage(checked);
127}
128
129void MainWindow::on_actionUpdate_U_triggered()
130{
131 CFrmUpdater* m_pfrmUpdater = new CFrmUpdater();
132 m_pfrmUpdater->SetTitle(QImage(":/image/Chess"));
133 RC_SHOW_WINDOW(m_pfrmUpdater);
134}
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格式