-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.cpp
More file actions
42 lines (35 loc) · 1.02 KB
/
Copy pathView.cpp
File metadata and controls
42 lines (35 loc) · 1.02 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
#include "View.h"
View::View(QWidget *widget) : QGraphicsView(widget) {
timer.setInterval(10);
}
void View::keyPressEvent(QKeyEvent *event) {
if (!event->isAutoRepeat()) {
controller->keyPressEvent(event);
}
}
void View::setController(AbstractController *cont) {
controller = cont;
}
void View::setBackground(const QPixmap &background) {
QPixmap scaled = background.scaled(4 * rect().x(), 4 * rect().y());
QBrush back(scaled);
setBackgroundBrush(back);
}
void View::keyReleaseEvent(QKeyEvent *event) {
if (!event->isAutoRepeat()) {
controller->keyReleaseEvent(event);
}
}
void View::setLocation(Location* loc) {
QRect* size = loc->getSize();
qDebug() << int(size->x());
setGeometry(*size);
scene()->setSceneRect(*size);
setStyleSheet("QGraphicsView { border-image: url(:/sources/background.png);}");
for (auto thing: loc->getObstacles()) {
scene()->addItem(thing);
}
for (auto enemy: loc->getEnemies()) {
scene()->addItem(enemy);
}
}