[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Eliot-dev] eliot/qt Makefile.am board_widget.cpp tile_layo...
From: |
Olivier Teulière |
Subject: |
[Eliot-dev] eliot/qt Makefile.am board_widget.cpp tile_layo... |
Date: |
Fri, 22 Oct 2010 17:01:31 +0000 |
CVSROOT: /cvsroot/eliot
Module name: eliot
Changes by: Olivier Teulière <ipkiss> 10/10/22 17:01:31
Modified files:
qt : Makefile.am board_widget.cpp
Added files:
qt : tile_layout.cpp tile_layout.h
Log message:
Moved the tiles layout to a dedicated file
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/Makefile.am?cvsroot=eliot&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/board_widget.cpp?cvsroot=eliot&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/tile_layout.cpp?cvsroot=eliot&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/tile_layout.h?cvsroot=eliot&rev=1.1
Patches:
Index: Makefile.am
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/Makefile.am,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- Makefile.am 17 Oct 2010 21:28:01 -0000 1.21
+++ Makefile.am 22 Oct 2010 17:01:31 -0000 1.22
@@ -57,6 +57,7 @@
eliot_SOURCES = \
qtcommon.h qtcommon.cpp \
coord_model.h coord_model.cpp \
+ tile_layout.cpp tile_layout.h \
bag_widget.cpp bag_widget.h \
dic_tools_widget.cpp dic_tools_widget.h \
new_game.cpp new_game.h \
@@ -85,6 +86,7 @@
ui/dic_wizard_letters_def_page.ui.h \
ui/dic_wizard_conclusion_page.ui.h \
coord_model.moc.cpp \
+ tile_layout.moc.cpp \
new_game.moc.cpp \
dic_tools_widget.moc.cpp \
bag_widget.moc.cpp \
Index: board_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/board_widget.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- board_widget.cpp 22 Oct 2010 16:59:43 -0000 1.22
+++ board_widget.cpp 22 Oct 2010 17:01:31 -0000 1.23
@@ -18,15 +18,12 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
-#include <algorithm> // For std::transform
#include <cmath>
-#include <QtGui/QGridLayout>
#include <QtGui/QMouseEvent>
#include <QtGui/QPainter>
-// XXX
-#include <iostream>
#include "board_widget.h"
+#include "tile_layout.h"
#include "tile_widget.h"
#include "qtcommon.h"
#include "public_game.h"
@@ -37,99 +34,6 @@
using namespace std;
-class BoardLayout : public QLayout
-{
- //Q_OBJECT
-
-public:
- BoardLayout(int nbCols, int spacing): m_nbCols(nbCols), m_space(spacing)
- {
- setContentsMargins(0, 0, 0, 0);
- }
- ~BoardLayout()
- {
- QLayoutItem *item;
- while ((item = takeAt(0)))
- delete item;
- }
-
- 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());
- }
-
- int getSquareSize() const
- {
- if (m_items.empty())
- return 0;
- return m_items.at(0)->geometry().width();
- }
-
- int getSpacing() const
- {
- return m_space;
- }
-
- virtual void addItem(QLayoutItem *item)
- {
- m_items.append(item);
- }
- virtual bool hasHeightForWidth() const { return true; }
- virtual int heightForWidth(int width) const { return width; }
- virtual int count() const { return m_items.size(); }
- virtual QLayoutItem *itemAt(int index) const { return
m_items.value(index); }
- virtual QLayoutItem *takeAt(int index)
- {
- if (index >= 0 && index < m_items.size())
- return m_items.takeAt(index);
- else
- return 0;
- }
- virtual QSize minimumSize() const
- {
- QSize size(m_space, m_space);
- if (!m_items.empty())
- size += m_items.at(0)->minimumSize();
- return size * m_nbCols + QSize(5, 5);
- }
- virtual void setGeometry(const QRect &rect)
- {
- QLayout::setGeometry(rect);
- doLayout(rect);
- }
- virtual QSize sizeHint() const { return minimumSize(); }
-
-private:
- QList<QLayoutItem *> m_items;
- int m_nbCols;
- int m_space;
-
- void doLayout(const QRect &rect)
- {
- int size = std::min(rect.width(), rect.height());
- int squareSize = size / m_nbCols - m_space;
- QLayoutItem *item;
- int x = 0;
- int y = 0;
- int nbInRow = 1;
- foreach (item, m_items)
- {
- QRect itemRect(QPoint(x, y), QSize(squareSize, squareSize));
- item->setGeometry(itemRect);
- x += squareSize + m_space;
- ++nbInRow;
- if (nbInRow > m_nbCols)
- {
- x = 0;
- y += squareSize + m_space;
- nbInRow = 1;
- }
- }
- }
-};
-
BoardWidget::BoardWidget(CoordModel &iCoordModel, QWidget *parent)
: QFrame(parent), m_game(NULL), m_coordModel(iCoordModel),
m_widgetsMatrix(BOARD_MAX + 1, BOARD_MAX + 1, 0)
@@ -142,7 +46,7 @@
setForegroundRole(QPalette::Window);
setBackgroundRole(QPalette::Window);
- BoardLayout *layout = new BoardLayout(BOARD_MAX + 1, 1);
+ TileLayout *layout = new TileLayout(BOARD_MAX + 1, 1);
// Line full of coordinates
layout->addWidget(new BasicTileWidget(this, ""));
for (unsigned int col = BOARD_MIN; col <= BOARD_MAX; ++col)
@@ -246,7 +150,7 @@
void BoardWidget::paintEvent(QPaintEvent *)
{
- const BoardLayout *boardLayout = (BoardLayout*)layout();
+ const TileLayout *boardLayout = (TileLayout*)layout();
QPainter painter(this);
QRect rect = boardLayout->getBoardRect();
const int size = boardLayout->getSquareSize();
Index: tile_layout.cpp
===================================================================
RCS file: tile_layout.cpp
diff -N tile_layout.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tile_layout.cpp 22 Oct 2010 17:01:31 -0000 1.1
@@ -0,0 +1,105 @@
+/*****************************************************************************
+ * Eliot
+ * Copyright (C) 2010 Olivier Teulière
+ * Authors: Olivier Teulière <ipkiss @@ gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *****************************************************************************/
+
+#include "tile_layout.h"
+#include "tile_widget.h"
+
+using namespace std;
+
+
+TileLayout::TileLayout(int nbCols, int spacing)
+ : m_nbCols(nbCols), m_space(spacing)
+{
+ setContentsMargins(0, 0, 0, 0);
+}
+
+
+TileLayout::~TileLayout()
+{
+ QLayoutItem *item;
+ while ((item = takeAt(0)))
+ delete item;
+}
+
+
+QRect TileLayout::getBoardRect() const
+{
+ if (m_items.size() < m_nbCols + 2)
+ return QRect();
+ return m_items.at(m_nbCols +
1)->geometry().united(m_items.back()->geometry());
+}
+
+
+int TileLayout::getSquareSize() const
+{
+ if (m_items.empty())
+ return 0;
+ return m_items.at(0)->geometry().width();
+}
+
+
+QLayoutItem *TileLayout::takeAt(int index)
+{
+ if (index >= 0 && index < m_items.size())
+ return m_items.takeAt(index);
+ else
+ return 0;
+}
+
+
+QSize TileLayout::minimumSize() const
+{
+ QSize size(m_space, m_space);
+ if (!m_items.empty())
+ size += m_items.at(0)->minimumSize();
+ return size * m_nbCols + QSize(5, 5);
+}
+
+
+void TileLayout::setGeometry(const QRect &rect)
+{
+ QLayout::setGeometry(rect);
+ doLayout(rect);
+}
+
+
+void TileLayout::doLayout(const QRect &rect)
+{
+ int size = std::min(rect.width(), rect.height());
+ int squareSize = size / m_nbCols - m_space;
+ QLayoutItem *item;
+ int x = 0;
+ int y = 0;
+ int nbInRow = 1;
+ foreach (item, m_items)
+ {
+ QRect itemRect(QPoint(x, y), QSize(squareSize, squareSize));
+ item->setGeometry(itemRect);
+ x += squareSize + m_space;
+ ++nbInRow;
+ if (nbInRow > m_nbCols)
+ {
+ x = 0;
+ y += squareSize + m_space;
+ nbInRow = 1;
+ }
+ }
+}
+
Index: tile_layout.h
===================================================================
RCS file: tile_layout.h
diff -N tile_layout.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tile_layout.h 22 Oct 2010 17:01:31 -0000 1.1
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * Eliot
+ * Copyright (C) 2010 Olivier Teulière
+ * Authors: Olivier Teulière <ipkiss @@ gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *****************************************************************************/
+
+#ifndef TILE_LAYOUT_H_
+#define TILE_LAYOUT_H_
+
+#include <QtGui/QLayout>
+//#include <QtGui/QList>
+
+
+class TileLayout : public QLayout
+{
+ Q_OBJECT
+
+public:
+ TileLayout(int nbCols, int spacing);
+ virtual ~TileLayout();
+
+ QRect getBoardRect() const;
+
+ int getSquareSize() const;
+
+ int getSpacing() const { return m_space; }
+
+ virtual void addItem(QLayoutItem *item) { m_items.append(item); }
+ virtual bool hasHeightForWidth() const { return true; }
+ virtual int heightForWidth(int width) const { return width; }
+ virtual int count() const { return m_items.size(); }
+ virtual QLayoutItem *itemAt(int index) const { return
m_items.value(index); }
+ virtual QLayoutItem *takeAt(int index);
+ virtual QSize minimumSize() const;
+ virtual void setGeometry(const QRect &rect);
+ virtual QSize sizeHint() const { return minimumSize(); }
+
+private:
+ QList<QLayoutItem *> m_items;
+ int m_nbCols;
+ int m_space;
+
+ void doLayout(const QRect &rect);
+};
+
+#endif
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Eliot-dev] eliot/qt Makefile.am board_widget.cpp tile_layo...,
Olivier Teulière <=