-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGraphicsView.h
68 lines (51 loc) · 1.68 KB
/
GraphicsView.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
#ifndef GRAPHICSVIEWH
#define GRAPHICSVIEWH
#include <QGraphicsView>
#include <QResizeEvent>
#include <QScrollBar>
#include <QDrag>
namespace TilesEditor
{
class GraphicsView : public QGraphicsView
{
Q_OBJECT
signals:
void renderView(QPainter* painter, const QRectF& rect);
void mousePress(QMouseEvent* event);
void mouseRelease(QMouseEvent* event);
void mouseMove(QMouseEvent* event);
void mouseDoubleClick(QMouseEvent* event);
void mouseWheelEvent(QWheelEvent* event);
void keyPress(QKeyEvent* event);
private:
bool m_antialias;
public:
GraphicsView(QWidget* parent = nullptr) :
QGraphicsView(parent)
{
setFocusPolicy(Qt::StrongFocus);
m_antialias = true;
this->setScene(new QGraphicsScene());
this->setMouseTracking(true);
scale(1.0, 1.0f);
setTransformationAnchor(QGraphicsView::NoAnchor);
}
void redraw() {
this->scene()->update();
}
void setAntiAlias(bool value) { m_antialias = value; }
protected:
void mouseMoveEvent(QMouseEvent* event) override;
void mousePressEvent(QMouseEvent* event)override;
void mouseReleaseEvent(QMouseEvent* event) override;
void mouseDoubleClickEvent(QMouseEvent* event) override;
void drawBackground(QPainter* painter, const QRectF& rect) override;
void keyPressEvent(QKeyEvent* event) override;
void wheelEvent(QWheelEvent* event) override;
void dragEnterEvent(QDragEnterEvent* event) override
{
QDrag::cancel();
}
};
}
#endif