2008-01-20 19:40:12 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Eliot
|
|
|
|
* Copyright (C) 2008 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
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2008-11-22 14:09:28 +01:00
|
|
|
#include <boost/foreach.hpp>
|
2008-01-20 19:40:12 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <QtGui/QTreeView>
|
|
|
|
#include <QtGui/QStandardItemModel>
|
|
|
|
|
|
|
|
#include "bag_widget.h"
|
|
|
|
#include "qtcommon.h"
|
2008-11-30 21:53:44 +01:00
|
|
|
#include "public_game.h"
|
2008-01-20 19:40:12 +01:00
|
|
|
#include "dic.h"
|
|
|
|
#include "tile.h"
|
|
|
|
#include "bag.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2008-01-22 16:30:20 +01:00
|
|
|
BagWidget::BagWidget(QWidget *parent)
|
|
|
|
: QTreeView(parent), m_game(NULL)
|
2008-01-20 19:40:12 +01:00
|
|
|
{
|
|
|
|
// Create the tree view
|
|
|
|
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
setRootIsDecorated(false);
|
|
|
|
setSortingEnabled(true);
|
|
|
|
QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
|
|
|
setSizePolicy(policy);
|
|
|
|
|
|
|
|
// Associate the model to the view
|
|
|
|
m_model = new QStandardItemModel(this);
|
|
|
|
setModel(m_model);
|
2008-01-24 21:18:00 +01:00
|
|
|
m_model->setColumnCount(2);
|
|
|
|
m_model->setHeaderData(0, Qt::Horizontal, _q("Letter"), Qt::DisplayRole);
|
|
|
|
m_model->setHeaderData(1, Qt::Horizontal, _q("Points"), Qt::DisplayRole);
|
2008-01-20 19:40:12 +01:00
|
|
|
updateModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-30 21:53:44 +01:00
|
|
|
void BagWidget::setGame(const PublicGame *iGame)
|
2008-01-22 16:30:20 +01:00
|
|
|
{
|
|
|
|
m_game = iGame;
|
|
|
|
updateModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BagWidget::refresh()
|
2008-01-20 19:40:12 +01:00
|
|
|
{
|
|
|
|
updateModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BagWidget::updateModel()
|
|
|
|
{
|
2008-01-24 21:18:00 +01:00
|
|
|
m_model->removeRows(0, m_model->rowCount());
|
2008-01-20 19:40:12 +01:00
|
|
|
|
2008-01-22 16:30:20 +01:00
|
|
|
if (m_game == NULL)
|
2008-01-20 19:40:12 +01:00
|
|
|
return;
|
|
|
|
|
2008-11-22 14:09:28 +01:00
|
|
|
const Bag &bag = m_game->getBag();
|
|
|
|
BOOST_FOREACH(const Tile &tile, m_game->getDic().getAllTiles())
|
2008-01-20 19:40:12 +01:00
|
|
|
{
|
2008-11-22 14:09:28 +01:00
|
|
|
unsigned int nb = bag.in(tile);
|
2008-01-20 19:40:12 +01:00
|
|
|
if (nb != 0)
|
|
|
|
{
|
|
|
|
int rowNum = m_model->rowCount();
|
|
|
|
m_model->insertRow(rowNum);
|
|
|
|
m_model->setData(m_model->index(rowNum, 0),
|
2008-11-22 14:09:28 +01:00
|
|
|
qfw(wstring(nb, tile.toChar())));
|
|
|
|
m_model->setData(m_model->index(rowNum, 1), tile.getPoints());
|
2008-01-20 19:40:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//resizeColumnToContents(0);
|
|
|
|
resizeColumnToContents(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QSize BagWidget::sizeHint() const
|
|
|
|
{
|
|
|
|
return QSize(160, 300);
|
|
|
|
}
|
|
|
|
|