Browse Source

set window title

master
Stefan Bühler 13 years ago
parent
commit
910626b3c7
  1. 63
      src/testgame.cpp

63
src/testgame.cpp

@ -65,11 +65,34 @@ namespace toruschess {
pt.drawImage(0, 0, *m_buffers[piece-1]);
}
TestGame::TestGame(QWidget *parent) : QMainWindow(parent), m_game(new Game()) {
PieceLibrary *lib = new PieceLibrary(this);
setCentralWidget(new TestField(this, lib, m_game));
TestPlace::TestPlace(QWidget *parent, const PieceLibrary *lib, const Field *field, const Pos &p)
: QWidget(parent), m_field(field), m_lib(lib), m_pos(p), m_mark(false) {
setMinimumSize(m_lib->minPieceSize());
}
QSize TestPlace::sizeHint() const {
return m_lib->pieceSize();
}
void TestPlace::paintEvent(QPaintEvent *) {
QPainter pt(this);
int pl = m_field->place(m_pos);
if ((m_pos.x() + m_pos.y()) % 2) {
// #D18B47
pt.fillRect(rect(), QBrush(QColor(0xD1, 0x8B, 0x47)));
} else {
// #FFCE9E
pt.fillRect(rect(), QBrush(QColor(0xFF, 0xCE, 0x9E)));
}
m_lib->paint(pt, pl);
if (m_mark) {
int r = qMax(1, (rect().width() + rect().height()) / 36);
pt.setBrush(pl != 0 ? Qt::green : Qt::white);
pt.setPen(Qt::red);
pt.drawEllipse(QPoint(rect().width() / 2, rect().height() / 2), r, r);
}
}
TestField::TestField(QWidget *parent, PieceLibrary *lib, Game *game) : QWidget(parent), m_lib(lib), m_game(game) {
QGridLayout *layout = new QGridLayout();
for (int y = 0; y < 8; y++) {
@ -124,32 +147,10 @@ namespace toruschess {
}
}
TestPlace::TestPlace(QWidget *parent, const PieceLibrary *lib, const Field *field, const Pos &p)
: QWidget(parent), m_field(field), m_lib(lib), m_pos(p), m_mark(false) {
setMinimumSize(m_lib->minPieceSize());
}
QSize TestPlace::sizeHint() const {
return m_lib->pieceSize();
}
void TestPlace::paintEvent(QPaintEvent *) {
QPainter pt(this);
int pl = m_field->place(m_pos);
if ((m_pos.x() + m_pos.y()) % 2) {
// #D18B47
pt.fillRect(rect(), QBrush(QColor(0xD1, 0x8B, 0x47)));
} else {
// #FFCE9E
pt.fillRect(rect(), QBrush(QColor(0xFF, 0xCE, 0x9E)));
}
m_lib->paint(pt, pl);
if (m_mark) {
int r = qMax(1, (rect().width() + rect().height()) / 36);
pt.setBrush(pl != 0 ? Qt::green : Qt::white);
pt.setPen(Qt::red);
pt.drawEllipse(QPoint(rect().width() / 2, rect().height() / 2), r, r);
}
TestGame::TestGame(QWidget *parent) : QMainWindow(parent), m_game(new Game()) {
setWindowTitle("Torus Chess");
PieceLibrary *lib = new PieceLibrary(this);
setCentralWidget(new TestField(this, lib, m_game));
}
}

Loading…
Cancel
Save