toruschess/src/field2d.h

82 lines
2.8 KiB
C++

/***************************************************************************
* Copyright (C) 2009 by Stefan Bühler *
* stbuehler@web.de *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef TORUSCHESSFIELD2D_H
#define TORUSCHESSFIELD2D_H
#include "toruschess.h"
#include "piecelibrary.h"
#include <QWidget>
#include <QList>
/**
@author Stefan Bühler <stbuehler@web.de>
*/
namespace toruschess {
/** Widget for the 2d field view (Game* is shared with other widgets) */
class Field2D : public QWidget {
Q_OBJECT
public:
Field2D(Game *game, QWidget *parent = 0);
virtual ~Field2D();
/** Mark the destination fields */
void markMoves(const QList<Move> &moves);
virtual QSize sizeHint() const;
protected:
virtual void paintEvent(QPaintEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void wheelEvent(QWheelEvent *event);
/* update field buffer size */
void checkSizes();
/* update field buffer */
void updateFieldBuffer();
/* find position on board from window coords */
Pos findPos(int x, int y);
protected slots:
/* slot for game updated event */
void fieldUpdated();
private:
PieceLibrary *m_lib;
Game *m_game;
bool m_marked[8][8];
QList<Move> m_markedMoves;
int m_fieldWidth, m_fieldHeight;
int m_originX, m_originY; /* offset for moving board in window */
int m_mouseLastX, m_mouseLastY;
QImage *m_fieldBuffer;
};
}
#endif