[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Eliot-dev] eliot/qt board_widget.cpp tile_widget.cpp tile_...
From: |
Olivier Teulière |
Subject: |
[Eliot-dev] eliot/qt board_widget.cpp tile_widget.cpp tile_... |
Date: |
Sun, 17 Oct 2010 21:45:10 +0000 |
CVSROOT: /cvsroot/eliot
Module name: eliot
Changes by: Olivier Teulière <ipkiss> 10/10/17 21:45:10
Modified files:
qt : board_widget.cpp tile_widget.cpp tile_widget.h
Log message:
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).
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/board_widget.cpp?cvsroot=eliot&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/tile_widget.cpp?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/tile_widget.h?cvsroot=eliot&r1=1.1&r2=1.2
Patches:
Index: board_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/board_widget.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- board_widget.cpp 17 Oct 2010 21:28:01 -0000 1.17
+++ board_widget.cpp 17 Oct 2010 21:45:10 -0000 1.18
@@ -55,9 +55,11 @@
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 @@
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 @@
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())
Index: tile_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/tile_widget.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- tile_widget.cpp 17 Oct 2010 21:28:01 -0000 1.1
+++ tile_widget.cpp 17 Oct 2010 21:45:10 -0000 1.2
@@ -43,8 +43,44 @@
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 @@
}
-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::paintEvent(QPaintEvent *)
{
- const int squareSize = std::min(width(), height());
+ const int squareSize = getSquareSize();
// The font must grow with the square size
QFont letterFont = font();
Index: tile_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/tile_widget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- tile_widget.h 17 Oct 2010 21:28:01 -0000 1.1
+++ tile_widget.h 17 Oct 2010 21:45:10 -0000 1.2
@@ -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 @@
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:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Eliot-dev] eliot/qt board_widget.cpp tile_widget.cpp tile_...,
Olivier Teulière <=