-
Notifications
You must be signed in to change notification settings - Fork 0
/
squarewidget.h
89 lines (70 loc) · 1.96 KB
/
squarewidget.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
#ifndef SQUAREWIDGET_H
#define SQUAREWIDGET_H
#include <QtSvgWidgets/QSvgWidget>
#include <QMouseEvent>
#include <QDrag>
#include <QSvgWidget>
#include <QMimeData>
#include <QDebug>
enum Piece{
ROOK,
KNIGHT,
BISHOP,
QUEEN,
KING,
PAWN
};
enum Move {
NOT_MOVED,
FIRST_MOVE_PAWN_CAN_BE_KILLED,
FIRST_MOVE,
MOVED
};
class SquareWidget : public QSvgWidget
{
Q_OBJECT
public:
int x,y;
bool isWhitePiece;
Move move;
Piece type;
explicit SquareWidget(QWidget *parent = nullptr) : QSvgWidget(parent){}
explicit SquareWidget(QWidget *parent = nullptr, int _x = 0, int _y = 0, bool _isWhitePiece = false, Piece _type = PAWN) : QSvgWidget(parent), x(_x), y(_y), isWhitePiece(_isWhitePiece), move(NOT_MOVED), type(_type) {}
// Override to return the height based on the given width
int heightForWidth(int width) const override {
return width; // Maintain a 1:1 aspect ratio
}
// Enable the height-for-width behavior
bool hasHeightForWidth() const override {
return true;
}
signals:
void pieceClicked(SquareWidget* piece);
protected:
// Mouse press event to initiate the drag
void mousePressEvent(QMouseEvent *event) override {
// qInfo()<< "HEre";
if (event->button() == Qt::LeftButton) {
emit pieceClicked(this);
}
}
};
class BoardWidget : public QSvgWidget
{
Q_OBJECT
public:
int x,y;
explicit BoardWidget(QWidget *parent = nullptr) : QSvgWidget(parent){}
explicit BoardWidget(QWidget *parent = nullptr, int _x = 0, int _y = 0) : QSvgWidget(parent), x(_x), y(_y) {}
// signals:
// void pieceClicked(SquareWidget* piece);
// protected:
// // Mouse press event to initiate the drag
// void mousePressEvent(QMouseEvent *event) override {
// // qInfo()<< "HEre";
// if (event->button() == Qt::LeftButton) {
// emit pieceClicked(this);
// }
// }
};
#endif // SQUAREWIDGET_H