-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpiece.cpp
More file actions
43 lines (39 loc) · 1.04 KB
/
piece.cpp
File metadata and controls
43 lines (39 loc) · 1.04 KB
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
#include "piece.h"
#include <iostream>
#include <vector>
#include <QtCore>
const char* piecetable[] {
":img/kingw.png",
":img/queenw.png",
":img/rookw.png",
":img/bishopw.png",
":img/knightw.png",
":img/pawnw.png",
":img/kingb.png",
":img/queenb.png",
":img/rookb.png",
":img/bishopb.png",
":img/knightb.png",
":img/pawnb.png"
};
Piece::Piece(QWidget *parentwindow, int piece, bool iswhite) : QLabel(parentwindow)
{
this->setGeometry(QRect(0, 0, 75, 75));
img = new QPixmap(piecetable[piece +((int)!iswhite*6)]);
this->setPixmap(img->scaled(this->width(),this->height(),Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
Piece::~Piece() {
delete img;
}
void Piece::mousePressEvent(QMouseEvent *event) {
if(event->buttons() & Qt::LeftButton)
{
this->move(mapToParent(event->pos()-QPoint(37,37)));
}
}
void Piece::mouseMoveEvent(QMouseEvent *event) {
if(event->buttons() & Qt::LeftButton)
{
this->move(mapToParent(event->pos()-QPoint(37,37)));
}
}