-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmapview.cpp
55 lines (44 loc) · 1.22 KB
/
mapview.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
/* mapview.cpp
* the map view implementation file */
#include <stdio.h>
#include <QMouseEvent>
#include <QScrollBar>
#include <QMessageBox>
#include <QFileDialog>
#include "editorwindow.h"
#include "newdialog.h"
#include "qnamespace.h"
#include "ui_mainwindow.h"
#include "ui_newmap.h"
MapView::MapView(QWidget* parent) : QGraphicsView(parent), dragging(false) {
}
/* tell the component about the window its in */
void MapView::set_window(EditorWindow* window) {
this->window = window;
}
/* mouse handlers */
void MapView::mouseMoveEvent(QMouseEvent* e) {
if(!dragging) {
return;
}
updateMapAt(e);
}
void MapView::updateMapAt(QMouseEvent* e) {
/* find the position of our scroll bar */
int scroll_x = horizontalScrollBar()->value();
int scroll_y = verticalScrollBar()->value();
/* apply the click onto the window - adjusted for scroll */
window->map_click(e->x() + scroll_x, e->y() + scroll_y);
}
void MapView::mouseReleaseEvent(QMouseEvent* e) {
if (e->button() == Qt::LeftButton) {
dragging = false;
}
}
void MapView::mousePressEvent(QMouseEvent* e) {
if (e->button() == Qt::LeftButton) {
dragging = true;
window->start_drag();
updateMapAt(e);
}
}