This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VueCase.cpp
77 lines (58 loc) · 1.54 KB
/
VueCase.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
//Corps de la classe VueCase
#include "VueCase.h"
#include <QDebug>
Ui::VueCase::VueCase(qreal x, qreal y, qreal width, qreal height, Modele::ModeleCase* caseAssocie, QGraphicsItem* parent) : QGraphicsRectItem(x, y, width, height, parent)
{
caseAssocie_ = caseAssocie;
brush.setStyle(Qt::SolidPattern);
setBrush(brush);
setAcceptHoverEvents(true);
}
void Ui::VueCase::mettreCoordonnees(int i, int j)
{
ligne_ = i;
colonne_ = j;
}
void Ui::VueCase::mettreCouleurbase(QColor couleur) {
couleurDeBase_ = couleur;
mettreCouleur(couleur);
}
void Ui::VueCase::mettreCouleur(QColor couleur)
{
couleurActuelle = couleur;
brush.setColor(couleur);
setBrush(brush);
}
void Ui::VueCase::mettreCouleurBase()
{
couleurActuelle = couleurDeBase_;
brush.setColor(couleurDeBase_);
setBrush(brush);
}
void Ui::VueCase::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
event->accept();
brush.setColor(QColor(148, 148, 148));
setBrush(brush);
if (couleurActuelle != QColor(148, 148, 148)) {
setCursor(Qt::ForbiddenCursor);
}
else {
setCursor(Qt::ArrowCursor);
}
QString piece;
caseAssocie_->getPiece() != nullptr ? piece = QString::fromStdString(caseAssocie_->getPiece()->lireEquipe()) : piece = " Null";
qDebug() <<" case pos : "<< piece << " " << ligne_ << " " << colonne_;
}
void Ui::VueCase::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
event->accept();
mettreCouleur(couleurActuelle);
}
void Ui::VueCase::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
if (event->buttons() == Qt::LeftButton)
{
emit caseClique(caseAssocie_);
}
}