-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscene.cpp
More file actions
46 lines (38 loc) · 986 Bytes
/
Copy pathscene.cpp
File metadata and controls
46 lines (38 loc) · 986 Bytes
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
#include "scene.h"
Scene::Scene(QObject *parent):
QGraphicsScene(parent)
{
this->setBackgroundBrush(Qt::black);
}
void Scene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
QGraphicsScene::mousePressEvent(mouseEvent);
auto point = mouseEvent->scenePos();
int x = floor(point.x());
int y = floor(point.y());
emit locationClicked(x,y);
}
void Scene::keyPressEvent(QKeyEvent *event)
{
QGraphicsScene::keyPressEvent(event);
if(event->key() == Qt::Key_Left)
{
emit keyClicked(1);
// qDebug() << "Move Left";
}
if(event->key() == Qt::Key_Right)
{
emit keyClicked(2);
// qDebug() << "Move Right";
}
if(event->key() == Qt::Key_Up)
{
emit keyClicked(3);
// qDebug() << "Move Up";
}
if(event->key() == Qt::Key_Down)
{
emit keyClicked(4);
// qDebug() << "Move Down";
}
}