-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoardWidget.h
152 lines (118 loc) · 3.9 KB
/
BoardWidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* This file is part of Qenolaba.
Copyright (C) 1997-2015 Josef Weidendorfer <[email protected]>
Qenolaba 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, version 2.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/*
* Handle rendering of a Board onto a Qt widget,
* shows moves and manages input of moves
*/
#ifndef _BOARDWIDGET_H_
#define _BOARDWIDGET_H_
#include "Move.h"
#include "Board.h"
#include "Piece.h"
#include <QWidget>
#include <QPixmap>
class BoardWidget : public PieceWidget
{
Q_OBJECT
public:
BoardWidget(Board&, QWidget *parent = 0);
~BoardWidget();
void createPos(int , int , int , Piece*);
void initPieces();
void updatePieces();
virtual void resizeEvent(QResizeEvent *);
virtual void paintEvent(QPaintEvent *);
virtual void mousePressEvent( QMouseEvent* pEvent );
virtual void mouseReleaseEvent( QMouseEvent* pEvent );
virtual void mouseMoveEvent( QMouseEvent* pEvent );
void renderPieces(bool r);
void choseMove(MoveList*);
/* Show a move with highlighting
* step 0: state before move
* 1: state after move
* 2: remove all marks (for blinking)
* 3: highlight marks (before move)
* 4: highlight marks (after move)
* Always call with step 0 before actual playing the move !!
*/
void showMove(const Move& m, int step, bool updateGUI = true);
/* Only highlight start
* Step 0: original state
* 1: highlight start
* Always call with step 0 before actual playing the move !!
*/
void showStart(const Move& m, int step, bool updateGUI = true);
/* enable/disable Edit Mode:
* On disabling & valid position it's actually copied to Board
*/
bool setEditMode(bool);
// int validState() { return board->validState(); }
// bool isValid() { return validState()==Board::valid; }
/* copy actual board position */
void updatePosition(bool updateGUI = false);
void clearPosition();
int getColor1Count() { return color1Count; }
int getColor2Count() { return color2Count; }
public slots:
void configure();
signals:
void moveChoosen(Move&);
void rightButtonPressed(int,const QPoint&);
void updateSpy(QString);
void edited(int);
protected:
virtual QSize sizeHint() const;
private:
int positionOf(int x, int y);
bool isValidStart(int pos, bool);
bool isValidEnd(int pos);
void drawBoard();
QPixmap boardPM;
Board& board;
int actValue;
bool editMode, renderMode;
int editColor;
/* copied position */
int field[Board::AllFields];
int color1Count, color2Count, color;
bool boardOK;
/* for getting user Move */
MoveList *pList;
Move actMove;
bool gettingMove, mbDown, startValid, startShown;
int startPos, actPos, oldPos, shownDirection;
int startField, startField2, actField, oldField, startType;
QColor *boardColor, *redColor, *yellowColor, *redHColor, *yellowHColor;
QCursor *arrowAll, *arrow[7];
Piece *n1, *n2, *h1, *h2, *d1, *d2; //, *e;
};
/* Test BoardWidget */
class Network;
class TestGame: public QObject
{
Q_OBJECT
public:
TestGame(Network*);
void initInput();
Board b;
MoveList l;
BoardWidget w;
Network* _n;
public slots:
void startOnEmpty();
void draw(Move& m);
void newPosition(const char*);
};
#endif /* _BOARDWIDGET_H_ */