-
Notifications
You must be signed in to change notification settings - Fork 1
/
MapView.h
90 lines (67 loc) · 2.24 KB
/
MapView.h
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
// MapMaker (c) 2016 Andrey Fidrya. MIT license. See LICENSE for more information.
#ifndef MAPVIEW_H
#define MAPVIEW_H
#include <functional>
#include <QGraphicsView>
#include <QPixmap>
class QGraphicsItem;
class Settings;
class LevelObject;
class MapScene;
class MapItem;
class MapView : public QGraphicsView
{
Q_OBJECT
public:
explicit MapView(QWidget *parent = 0);
MapScene *mapScene() const;
void drawBackground(QPainter *painter, const QRectF &rect) override;
void drawForeground(QPainter *painter, const QRectF &rect) override;
void paintEvent(QPaintEvent *event) override;
void dragEnterEvent(QDragEnterEvent *event) override;
void dragMoveEvent(QDragMoveEvent *event) override;
void dragLeaveEvent(QDragLeaveEvent *event) override;
void dropEvent(QDropEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void resetScene();
void selectActiveItems();
void moveOrCloneSelectedItemsBy(int dx, int dy);
signals:
void sceneCreated(QGraphicsScene *scene);
public slots:
void copy();
void paste();
void selectAll();
protected slots:
void updateGridPixmap();
void onZoomChanged(double zoom);
protected:
using MapItems = QList<MapItem *>;
enum DragState {
NotDragging,
AboutToDrag,
Dragging
};
friend class LevelLoader;
QRect selectionRect() const;
void snapToGrid(qreal firstLine, qreal secondLine, qreal gridSize, qreal *newFirstLine, qreal *newSecondLine) const;
QRectF snapToGrid(const QRectF &rect, const QSizeF &gridSize, bool bothSides = false) const;
QPointF snapToDockPoints(const QPointF &movedByDelta) const;
Settings *settings_ = nullptr;
DragState dragState_ = NotDragging;
bool scrolling_ = false;
bool selecting_ = false;
QPoint startPos_;
QPoint prevPos_;
QPixmap gridPixmap_;
double zoom_ = 1.0;
bool macroStarted_ = false;
MapItems draggedItems_;
QRectF dragInitialBounds_;
QRectF dragPrevBounds_;
};
#endif // MAPVIEW_H