2012-01-29 02:25:37 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Eliot
|
|
|
|
* Copyright (C) 2012 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 RACK_WIDGET_H_
|
|
|
|
#define RACK_WIDGET_H_
|
|
|
|
|
2012-12-18 09:56:07 +01:00
|
|
|
#include <vector>
|
2012-08-07 22:18:55 +02:00
|
|
|
#include <QtGui/QFrame>
|
2012-01-29 02:25:37 +01:00
|
|
|
|
|
|
|
#include "tile.h"
|
|
|
|
#include "logging.h"
|
|
|
|
|
2012-12-18 09:56:07 +01:00
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
|
2012-01-29 02:25:37 +01:00
|
|
|
class PublicGame;
|
|
|
|
class TileWidget;
|
2012-12-18 09:56:07 +01:00
|
|
|
class PlayedRack;
|
2012-12-25 16:30:37 +01:00
|
|
|
class PlayModel;
|
2012-01-29 02:25:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Widget used to display a rack with big letters
|
|
|
|
*/
|
2012-08-07 22:18:55 +02:00
|
|
|
class RackWidget: public QFrame
|
2012-01-29 02:25:37 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT;
|
|
|
|
DEFINE_LOGGER();
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit RackWidget(QWidget *parent = 0);
|
2012-04-10 20:29:52 +02:00
|
|
|
void setShowOnlyLastTurn(bool iShow) { m_showOnlyLastTurn = iShow; }
|
2012-01-29 02:25:37 +01:00
|
|
|
|
2012-12-25 16:30:37 +01:00
|
|
|
void setPlayModel(PlayModel *iPlayModel);
|
|
|
|
|
2012-01-29 02:25:37 +01:00
|
|
|
public slots:
|
|
|
|
void setGame(const PublicGame *iGame);
|
2013-01-09 16:27:00 +01:00
|
|
|
void setRack(const PlayedRack &iRack);
|
2012-01-29 02:25:37 +01:00
|
|
|
|
2013-01-09 18:42:49 +01:00
|
|
|
signals:
|
|
|
|
void gameUpdated();
|
|
|
|
|
2012-12-23 18:40:40 +01:00
|
|
|
protected:
|
|
|
|
virtual void dragEnterEvent(QDragEnterEvent *event);
|
|
|
|
virtual void dragLeaveEvent(QDragLeaveEvent *event);
|
|
|
|
virtual void dragMoveEvent(QDragMoveEvent *event);
|
|
|
|
virtual void dropEvent(QDropEvent *event);
|
|
|
|
|
2013-01-09 16:27:00 +01:00
|
|
|
private slots:
|
|
|
|
/**
|
|
|
|
* Refresh the widget, using m_tiles as a reference.
|
|
|
|
*/
|
|
|
|
void refresh();
|
|
|
|
/// Set the tiles and refresh the widget
|
|
|
|
void setTiles(const vector<Tile> &iTiles);
|
|
|
|
|
2012-01-29 02:25:37 +01:00
|
|
|
private:
|
2012-12-29 19:18:12 +01:00
|
|
|
/// Tiles from which widgets are created
|
|
|
|
vector<Tile> m_tiles;
|
|
|
|
|
2013-01-09 16:27:00 +01:00
|
|
|
/// Tiles after filtering (removing from m_tiles the ones in the word being played)
|
|
|
|
vector<Tile> m_filteredTiles;
|
|
|
|
|
2012-12-29 19:18:12 +01:00
|
|
|
/**
|
|
|
|
* Encapsulated tiles.
|
|
|
|
* Always in sync with m_tiles, except maybe during a drag & drop operation.
|
|
|
|
*/
|
2012-01-29 02:25:37 +01:00
|
|
|
vector<TileWidget *> m_tilesVect;
|
|
|
|
|
|
|
|
/// Encapsulated game, can be NULL
|
|
|
|
const PublicGame *m_game;
|
2012-04-10 20:29:52 +02:00
|
|
|
|
2012-12-25 16:30:37 +01:00
|
|
|
/// Word being played
|
|
|
|
PlayModel *m_playModel;
|
|
|
|
|
2012-04-10 20:29:52 +02:00
|
|
|
/**
|
|
|
|
* Indicate whether to show only the last rack
|
2013-01-09 16:27:00 +01:00
|
|
|
* (useful on the external board, in particular in arbitration mode)
|
2012-04-10 20:29:52 +02:00
|
|
|
*/
|
|
|
|
bool m_showOnlyLastTurn;
|
2012-12-23 18:40:40 +01:00
|
|
|
|
2012-12-29 19:18:12 +01:00
|
|
|
int m_dragOrigin;
|
|
|
|
|
2012-12-25 16:30:37 +01:00
|
|
|
/**
|
|
|
|
* If the play model is not NULL and contains a valid move, this method
|
|
|
|
* returns a vector of tiles filtered from the tiles in the move.
|
|
|
|
* Otherwise, the given tiles are returned without any change.
|
|
|
|
*/
|
|
|
|
vector<Tile> filterRack(const vector<Tile> &iTiles) const;
|
|
|
|
|
2013-01-09 18:08:56 +01:00
|
|
|
bool canStartDragDrop() const;
|
|
|
|
|
2012-12-23 18:40:40 +01:00
|
|
|
/**
|
|
|
|
* Return the 0-based index of the tile found at the given (relative)
|
|
|
|
* position. If there is no such tile, return -1.
|
|
|
|
*/
|
|
|
|
int findTile(const QPoint &iPos) const;
|
|
|
|
|
|
|
|
int findClosestTile(const QPoint &iPos) const;
|
|
|
|
|
2012-12-29 19:18:12 +01:00
|
|
|
void moveTile(int fromPos, int toPos, bool shaded = false);
|
|
|
|
|
2012-12-23 18:40:40 +01:00
|
|
|
private slots:
|
|
|
|
void tilePressed(int row, int col, QMouseEvent *event);
|
2012-01-29 02:25:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|