📄 qgo_interface.cpp
字号:
/* * qgo_interface.cpp - qGoClient's interface to qGo */#include "qgo.h"#include "mainwindow.h"#include "qgo_interface.h"#include "tables.h"#include "defines.h"#include "globals.h"#include "gs_globals.h"#include "misc.h"#include "config.h"#include "interfacehandler.h"#include "normaltools_gui.h"#include "move.h"#include "qnewgamedlg.h"#include <qlabel.h>//#include <qmultilineedit.h>#include <qobject.h>#include <qstring.h>#include <qtimer.h>#include <qpushbutton.h>#include <qmessagebox.h>#include <qtooltip.h>#include <qcombobox.h>#include <qslider.h>#include <qtoolbar.h>#include <qptrlist.h>#ifdef Q_OS_MACX#include <CoreFoundation/CFString.h>#include <CoreFoundation/CFBundle.h>#endif //Q_OS_MACX/* * Playing or Observing */qGoIF::qGoIF(QWidget *p) : QObject(){ qgo = new qGo(); ASSERT(qgo); setting->qgo = qgo; parent = p; qgobrd = 0; gsName = GS_UNKNOWN; boardlist = new QPtrList<qGoBoard>; boardlist->setAutoDelete(false); localBoardCounter = 10000; // init sound (all sounds!) qgo->loadSound();}qGoIF::~qGoIF(){ delete boardlist; delete qgo;}// handle move info and distribute to different boardsbool qGoIF::parse_move(int src, GameInfo* gi, Game* g, QString txt){#ifdef SHOW_MOVES_DLG static Talk *dlg;#endif int game_id = 0; StoneColor sc = stoneNone; QString pt; QString mv_nr; switch (src) { // regular move info (parser) case 0: game_id = gi->nr.toInt(); if (gi->mv_col == QString("B")) sc = stoneBlack; else if (gi->mv_col == QString("W")) sc = stoneWhite; else sc = stoneNone; mv_nr = gi->mv_nr; pt = gi->mv_pt; break; // adjourn/end/resume of a game (parser) case 1: // check if g->nr is a number if (g->nr == QString("@")) { qGoBoard *qb = boardlist->first(); while (qb != NULL && qb->get_bplayer() != myName && qb->get_wplayer() != myName) { qb = boardlist->next(); } if (qb) game_id = qb->get_id(); else { qWarning("*** You are not playing a game to be adjourned!"); return false; } } else game_id = g->nr.toInt(); if (g->Sz == QString("@") || g->Sz == QString("@@")) { // look for adjourned games qGoBoard *qb = boardlist->first(); while (qb != NULL) { if (qb->get_adj() && qb->get_id() == 10000 && qb->get_bplayer() == g->bname && qb->get_wplayer() == g->wname) { qDebug("ok, adjourned game found ..."); if (g->bname != myName && g->wname != myName) // observe if I'm not playing emit signal_sendcommand("observe " + g->nr, false); else // ensure that my game is correct stated emit signal_sendcommand("games " + g->nr, false); qb->set_sentmovescmd(true); qb->set_id(g->nr.toInt()); qb->setGameData(); qb->setMode(); qb->set_adj(false); qb->get_win()->getInterfaceHandler()->toggleMode(); qb->set_runTimer(); qb->set_sentmovescmd(true); emit signal_sendcommand("moves " + g->nr, false); emit signal_sendcommand("all " + g->nr, false); qb->send_kibitz(tr("Game continued as Game number %1").arg(g->nr)); // show new game number; qb->get_win()->getBoard()->updateCaption(); // renew refresh button qb->get_win()->getInterfaceHandler()->refreshButton->setText(QObject::tr("Refresh", "button label")); // increase number of observed games emit signal_addToObservationList(-2); return true; } qb = boardlist->next(); } } // special case: your own game if (g->Sz == QString("@@"))// || g->bname == myName || g->wname == myName) { // set up new game if (g->bname == g->wname) // teaching game src = 14; else // match src = 13; } break; // game to observe case 2: game_id = txt.toInt(); break; // match case 3: game_id = txt.toInt(); break; // teaching game case 4: game_id = txt.toInt(); break; // computer game case 6: game_id = ++localBoardCounter; //txt.toInt(); qDebug(QString("computer game no. %1").arg(game_id)); break; // remove all boards! -> if connection is closed // but: set options for local actions case -1: qgobrd = boardlist->first(); while (qgobrd) { // modeNormal; qgobrd->set_stopTimer(); // enable Menus// qgobrd->get_win()->setOnlineMenu(false); // set board editable... qgobrd->set_Mode(1); // toggle score 2x qgobrd->get_win()->getInterfaceHandler()->toggleMode(); qgobrd->get_win()->getInterfaceHandler()->toggleMode(); boardlist->remove(); qgobrd = boardlist->current(); } // set number of observed games to 0 emit signal_addToObservationList(0); return false; break; default: qWarning("*** qGoIF::parse_move(): unknown case !!! ***"); return false; break; }#ifdef SHOW_MOVES_DLG // dialog recently used? if (!dlg) { dlg = new Talk("SPIEL", parent, true); connect(dlg->get_dialog(), SIGNAL(signal_talkto(QString&, QString&)), parent, SLOT(slot_talkto(QString&, QString&))); CHECK_PTR(dlg); dlg->write("New Dialog created\n"); }#endif // board recently used? if (!qgobrd || qgobrd->get_id() != game_id) { // seek dialog qgobrd = boardlist->first(); while (qgobrd != NULL && qgobrd->get_id() != game_id) qgobrd = boardlist->next(); // not found -> create new dialog if (!qgobrd) { // setup only with mouseclick or automatic in case of matching !!!! // added case 0: 'observe' cmd if (src < 2) //(src == 1) // { return false; } boardlist->append(new qGoBoard(this, qgo)); qgobrd = boardlist->current();// qgobrd->get_win()->setOnlineMenu(true); CHECK_PTR(qgobrd); // connect with board (MainWindow::CloseEvent()) connect(qgobrd->get_win(), SIGNAL(signal_closeevent()), qgobrd, SLOT(slot_closeevent())); // connect with board (qGoBoard)/* connect(qgobrd, SIGNAL(signal_closeevent(int)), this, SLOT(slot_closeevent(int)));*/ // board -> to kibitz or say connect(qgobrd->get_win()->getBoard(), SIGNAL(signal_sendcomment(const QString&)), qgobrd, SLOT(slot_sendcomment(const QString&))); // board -> stones connect(qgobrd->get_win()->getBoard(), SIGNAL(signal_addStone(enum StoneColor, int, int)), qgobrd, SLOT(slot_addStone(enum StoneColor, int, int))); // board-> stones (computer game) connect(qgobrd->get_win()->getBoard(), SIGNAL(signal_Stone_Computer(enum StoneColor, int, int)), qgobrd, SLOT(slot_stoneComputer(enum StoneColor, int, int))); connect(qgobrd, SIGNAL(signal_2passes(const QString&,const QString& )), this, SLOT(slot_removestones(const QString&, const QString&))); connect(qgobrd, SIGNAL(signal_sendcommand(const QString&, bool)), this, SLOT(slot_sendcommand(const QString&, bool))); // board -> commands connect(qgobrd->get_win()->getBoard(), SIGNAL(signal_pass()), qgobrd, SLOT(slot_doPass()));/* connect(qgobrd->get_win()->get_fileClose(), SIGNAL(activated()), qgobrd,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -