-
Notifications
You must be signed in to change notification settings - Fork 0
/
clickboxsize1.cpp
99 lines (82 loc) · 2.57 KB
/
clickboxsize1.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "ClickBoxSize1.h"
#include <QtGui>
#include <QVector>
#include <QDebug>
#include <QHash>
//#include <QtWidgets>
//#include <QRectF>
#include <QGraphicsSceneMouseEvent>
#include "mainwindow.h"
#include "ui_mainwindow.h"
ClickBoxSize1::ClickBoxSize1( int where_x, int where_y, int xs, int ys, int place_s, MainWindow* mainW,QGraphicsItem* parent): QGraphicsItem(parent){
setFlag(QGraphicsItem::ItemIsFocusable);
setFlag(QGraphicsItem::ItemIsSelectable);
this->setOpacity(0.01);
main = mainW;
size_x = xs;
size_y = ys;
loc_x = where_x;
loc_y = where_y;
place = place_s;
}
QRectF ClickBoxSize1::boundingRect() const {
return QRectF(loc_x,loc_y,size_x,size_y);
}
void ClickBoxSize1::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
qDebug() << "ITEM IS CLICKED";
main->getPlayers()->at(main->round)->setGlobal(place);
main->getBoard()->spaces.at( place )->landOn(*( main->getPlayers()->at(main->round) ), main);
main->getUi()->console->append( QString::fromStdString( main->getBoard()->spaces.at( place )->print() ) );
if (main->getPlayers()->at(main->round)->getMessage() != "" ) {
main->getUi()->console->append( QString::fromStdString( main->getPlayers()->at(main->round)->getMessage() ) ) ;
main->getPlayers()->at(main->round)->setMessage("");
}
main->redrawMoney();
main->getScene()->update();
QPointF tmp = event->scenePos();
qDebug() << tmp.x();
qDebug() << tmp.y();
// update();
}
//void ClickBoxSize1::mousePressEvent(QGraphicsSceneMouseEvent *event)
//{
//// qDebug() << "ITEM IS CLICKED";
//// update();
//}
void ClickBoxSize1::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
// painter->setBrush(Qt::OpaqueMode);
QPen framepen(Qt::red);
painter->setPen(framepen);
painter->drawRect(loc_x,loc_y,size_x,size_y);
}
void ClickBoxSize1::keyPressEvent(QKeyEvent *event) {
switch ( event->key() ) {
case Qt::Key_Right: {
moveBy(2,0);
break;
}
case Qt::Key_Left: {
moveBy(-2,0);
break;
}
case Qt::Key_Up: {
moveBy(0,-2);
break;
}
case Qt::Key_Down: {
moveBy(0,2);
break;
}
}
update();
}
//void ClickBoxSize1::mousePressEvent(QGraphicsSceneMouseEvent* event) {
// QPointF tmp = event->scenePos();
// qDebug() << tmp.x();
// qDebug() << tmp.y();
//}
//void ClickBoxSize1::MousePressEvent(QMouseEvent *event) {
// QWidget::mousePressEvent(event);
// event->accept();
//}