mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-11-17 07:48:27 +01:00
Display the coordinates of the board, and draw a square around it.
It now looks exactly like the old board (with 1 pixel difference for the coordinates, making it better).
This commit is contained in:
parent
858b3997ae
commit
90027c3210
3 changed files with 87 additions and 44 deletions
|
@ -55,9 +55,11 @@ public:
|
|||
delete item;
|
||||
}
|
||||
|
||||
QRect getBoardRect()
|
||||
QRect getBoardRect() const
|
||||
{
|
||||
|
||||
if (m_items.size() < m_nbCols + 2)
|
||||
return QRect();
|
||||
return m_items.at(m_nbCols + 1)->geometry().united(m_items.back()->geometry());
|
||||
}
|
||||
|
||||
virtual void addItem(QLayoutItem *item)
|
||||
|
@ -129,9 +131,23 @@ BoardWidget::BoardWidget(CoordModel &iCoordModel, QWidget *parent)
|
|||
setForegroundRole(QPalette::Window);
|
||||
setBackgroundRole(QPalette::Window);
|
||||
|
||||
BoardLayout *layout = new BoardLayout(15);
|
||||
BoardLayout *layout = new BoardLayout(16);
|
||||
// Line full of coordinates
|
||||
layout->addWidget(new BasicTileWidget(this, ""));
|
||||
for (unsigned int col = BOARD_MIN; col <= BOARD_MAX; ++col)
|
||||
{
|
||||
BasicTileWidget *coordTile =
|
||||
new BasicTileWidget(this, QString("%1").arg(col));
|
||||
layout->addWidget(coordTile);
|
||||
}
|
||||
// Rest of the board
|
||||
for (unsigned int row = BOARD_MIN; row <= BOARD_MAX; ++row)
|
||||
{
|
||||
// Add the coordinate
|
||||
BasicTileWidget *coordTile =
|
||||
new BasicTileWidget(this, QString(QChar('A' + row - BOARD_MIN)));
|
||||
layout->addWidget(coordTile);
|
||||
// Add the squares
|
||||
for (unsigned int col = BOARD_MIN; col <= BOARD_MAX; ++col)
|
||||
{
|
||||
TileWidget::Multiplier mult = TileWidget::NONE;
|
||||
|
@ -191,32 +207,13 @@ QSize BoardWidget::sizeHint() const
|
|||
void BoardWidget::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
QRect rect = ((BoardLayout*)layout())->getBoardRect();
|
||||
painter.drawRect(rect);
|
||||
|
||||
#if 0
|
||||
const int size = std::min(width(), height());
|
||||
const int squareSize = lrint(floor((size - 1) / (BOARD_MAX - BOARD_MIN + 2)));
|
||||
|
||||
// The font must grow with the square size
|
||||
QFont letterFont = font();
|
||||
letterFont.setPixelSize(squareSize * 2 / 3);
|
||||
|
||||
QFont pointsFont = font();
|
||||
const double pointsCoeff = 8. / 25.;
|
||||
pointsFont.setPixelSize(squareSize * pointsCoeff);
|
||||
|
||||
// Draw the coordinates
|
||||
painter.setFont(letterFont);
|
||||
for (unsigned x = 1; x <= BOARD_MAX - BOARD_MIN + 1; ++x)
|
||||
{
|
||||
painter.drawText(x * squareSize, 1,
|
||||
squareSize, squareSize,
|
||||
Qt::AlignCenter,
|
||||
QString::number(x));
|
||||
painter.drawText(0, x * squareSize,
|
||||
squareSize, squareSize,
|
||||
Qt::AlignCenter,
|
||||
QString(1, 'A' + x - 1));
|
||||
}
|
||||
// Draw the arrow
|
||||
const Coord &markCoord = m_coordModel.getCoord();
|
||||
if (m_game != NULL && markCoord.isValid())
|
||||
|
|
|
@ -43,8 +43,44 @@ const QColor TileWidget::JokerColour(255, 0, 0);
|
|||
const QColor TileWidget::ArrowColour(10, 10, 10);
|
||||
|
||||
|
||||
BasicTileWidget::BasicTileWidget(QWidget *parent, QString text)
|
||||
: QWidget(parent), m_text(text)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int BasicTileWidget::heightForWidth(int width) const
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
QSize BasicTileWidget::sizeHint() const
|
||||
{
|
||||
return QSize(30, 30);
|
||||
}
|
||||
|
||||
|
||||
int BasicTileWidget::getSquareSize() const
|
||||
{
|
||||
return std::min(width(), height());
|
||||
}
|
||||
|
||||
|
||||
void BasicTileWidget::paintEvent(QPaintEvent *)
|
||||
{
|
||||
const int squareSize = getSquareSize();
|
||||
QFont letterFont = font();
|
||||
letterFont.setPixelSize(squareSize * 2 / 3);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setFont(letterFont);
|
||||
painter.drawText(0, 1, squareSize, squareSize, Qt::AlignCenter, m_text);
|
||||
}
|
||||
|
||||
|
||||
TileWidget::TileWidget(QWidget *parent, Multiplier multiplier)
|
||||
: QWidget(parent), m_multiplier(multiplier), m_isJoker(false),
|
||||
: BasicTileWidget(parent), m_multiplier(multiplier), m_isJoker(false),
|
||||
m_isPreview(false), m_showArrow(false), m_horizontalArrow(true)
|
||||
{
|
||||
setMinimumSize(15, 15);
|
||||
|
@ -62,18 +98,6 @@ TileWidget::TileWidget(QWidget *parent, Multiplier multiplier)
|
|||
}
|
||||
|
||||
|
||||
int TileWidget::heightForWidth(int width) const
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
QSize TileWidget::sizeHint() const
|
||||
{
|
||||
return QSize(30, 30);
|
||||
}
|
||||
|
||||
|
||||
void TileWidget::tileChanged(const Tile &iTile, bool isJoker, bool isPreview,
|
||||
bool showArrow, bool horizontalArrow)
|
||||
{
|
||||
|
@ -88,7 +112,7 @@ void TileWidget::tileChanged(const Tile &iTile, bool isJoker, bool isPreview,
|
|||
|
||||
void TileWidget::paintEvent(QPaintEvent *)
|
||||
{
|
||||
const int squareSize = std::min(width(), height());
|
||||
const int squareSize = getSquareSize();
|
||||
|
||||
// The font must grow with the square size
|
||||
QFont letterFont = font();
|
||||
|
|
|
@ -25,7 +25,33 @@
|
|||
#include "tile.h"
|
||||
|
||||
|
||||
class TileWidget: public QWidget
|
||||
/**
|
||||
* Simplified tile, only used to draw the coordinates of the board
|
||||
*/
|
||||
class BasicTileWidget: public QWidget
|
||||
{
|
||||
public:
|
||||
BasicTileWidget(QWidget *parent = 0, QString text = "");
|
||||
|
||||
int getSquareSize() const;
|
||||
|
||||
virtual int heightForWidth(int w) const;
|
||||
|
||||
protected:
|
||||
/// Define a default size
|
||||
virtual QSize sizeHint() const;
|
||||
/// Paint the square
|
||||
virtual void paintEvent(QPaintEvent *iEvent);
|
||||
|
||||
private:
|
||||
QString m_text;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Widget used to display a square on the board, with or without letter.
|
||||
*/
|
||||
class TileWidget: public BasicTileWidget
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
|
@ -41,16 +67,12 @@ public:
|
|||
|
||||
explicit TileWidget(QWidget *parent = 0, Multiplier multiplier = NONE);
|
||||
|
||||
virtual int heightForWidth(int w) const;
|
||||
|
||||
public slots:
|
||||
void tileChanged(const Tile &iTile, bool isJoker, bool isPreview,
|
||||
bool showArrow, bool horizontalArrow);
|
||||
|
||||
protected:
|
||||
/// Define a default size
|
||||
virtual QSize sizeHint() const;
|
||||
/// Paint the board
|
||||
/// Paint the square
|
||||
virtual void paintEvent(QPaintEvent *iEvent);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue