-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfigure.cpp
85 lines (70 loc) · 1.94 KB
/
figure.cpp
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
#include "figure.h"
#include <QApplication>
#include <QSizePolicy>
void Figure::resizeEvent(QResizeEvent *size)
{
this->setPixmap(origin.scaled(size->size()));
}
void Figure::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
emit figureSelected(this);
/*_parentWidget = this->parentWidget();
this->hide();
this->setParent(_boardWidget);
move(this->mapToParent(event->pos()));
this->show();
b_move = true;*/
}
}
void Figure::mouseMoveEvent(QMouseEvent *event)
{
/*if((event->buttons() & Qt::LeftButton) && b_move)
{
move(this->mapToParent(event->pos()));
}*/
}
void Figure::mouseReleaseEvent(QMouseEvent *event)
{
/*if (event->button() == Qt::LeftButton && b_move)
{
b_move = false;
qDebug() << pos().x() << " " << pos().y();
emit turnAttempt(this, _parentWidget, QApplication::widgetAt(QCursor::pos()));
this->hide();
this->setParent(_parentWidget);
this->show();
//move(QPoint(0, 0));
}*/
}
void Figure::parentResized(QResizeEvent *size)
{
this->resize(size->size());
}
bool Figure::makeKing()
{
this->isKing = true;
origin = QPixmap(isWhite ? ":/new/prefix1/checker_white_king" : ":/new/prefix1/checker_black_king");
this->setPixmap(origin.scaled(this->pixmap().size()));
return true;
}
Figure::Figure(QWidget* parent, bool isWhite, QWidget *board) : QLabel()
{
setParent(parent);
_parentWidget = parent;
isKing = false;
//b_move = false;
this->isWhite = isWhite;
this->setBaseSize(25, 25);
this->setMinimumSize(1,1);
this->setAlignment(Qt::AlignCenter);
_boardWidget = board;
origin = QPixmap(isWhite ? ":/new/prefix1/checker_white" : ":/new/prefix1/checker_black");
this->setPixmap(origin);
}
Figure::~Figure()
{
if(availableTurns != nullptr) delete availableTurns;
qDebug() << "шашка удалена";
}