forked from bupticybee/TexasSolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boardselector.cpp
77 lines (67 loc) · 2.37 KB
/
boardselector.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
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
#include "boardselector.h"
#include "ui_boardselector.h"
boardselector::boardselector(QTextEdit* boardEdit,PokerMode mode,QWidget *parent) :
QDialog(parent),
ui(new Ui::boardselector)
{
ui->setupUi(this);
this->setWindowTitle(tr("BoardSelector"));
this->boardEdit = boardEdit;
this->mode = mode;
QString ranks;
if(mode == PokerMode::HOLDEM){
ranks = "A,K,Q,J,T,9,8,7,6,5,4,3,2";
}else if(mode == PokerMode::SHORTDECK){
ranks = "A,K,Q,J,T,9,8,7,6";
}else{
throw runtime_error("mode not found in range selector");
}
this->rank_list = ranks.split(",");
this->boardSelectorTableModel = new BoardSelectorTableModel(this->rank_list,boardEdit->toPlainText(),this);
this->ui->boardSelectorTable->setModel(boardSelectorTableModel);
this->boardSelectorTableDelegate = new BoardSelectorTableDelegate(this->rank_list,this->boardSelectorTableModel,this);
this->ui->boardSelectorTable->setItemDelegate(this->boardSelectorTableDelegate);
this->ui->boardEdit->setText(boardEdit->toPlainText());
}
boardselector::~boardselector()
{
delete ui;
}
void boardselector::on_boardSelectorTable_clicked(const QModelIndex &index)
{
int row = index.row();
int col = index.column();
this->boardSelectorTableModel->setBoardAt(row,col,1 - this->boardSelectorTableModel->getBoardAt(row,col));
if(this->ui->boardEdit->text() != this->boardSelectorTableModel->getBoardText()){
this->ui->boardEdit->setText(this->boardSelectorTableModel->getBoardText());
}
this->ui->boardEdit->setFocus();
this->ui->boardSelectorTable->setFocus();
}
void boardselector::on_boardEdit_textEdited(const QString &arg1)
{
}
void boardselector::on_boardEdit_textChanged(const QString &arg1)
{
this->boardSelectorTableModel->setBoardText(arg1);
this->ui->boardSelectorTable->update();
this->ui->boardSelectorTable->setFocus();
this->ui->boardEdit->setFocus();
}
void boardselector::on_confirmButton_clicked()
{
this->boardEdit->setText(this->ui->boardEdit->text());
this->close();
}
void boardselector::on_cancelButton_clicked()
{
this->close();
}
void boardselector::on_clearBoardButton_clicked()
{
this->boardSelectorTableModel->clear_board();
this->ui->boardEdit->clear();
this->ui->boardSelectorTable->update();
this->ui->boardSelectorTable->setFocus();
this->ui->boardEdit->setFocus();
}