-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavigatorview.cpp
76 lines (63 loc) · 1.79 KB
/
navigatorview.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "navigatorview.h"
#include "graphicsview.h"
#include "opacityhelper.h"
#include <QDebug>
#include <QMouseEvent>
NavigatorView::NavigatorView(QWidget *parent)
: QGraphicsView (parent)
, m_viewportRegion(this->rect())
, m_opacityHelper(new OpacityHelper(this))
{
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setStyleSheet("background-color: rgba(0, 0, 0, 120);"
"border-radius: 3px");
}
void NavigatorView::setMainView(GraphicsView *mainView)
{
m_mainView = mainView;
}
void NavigatorView::setOpacity(qreal opacity, bool animated)
{
m_opacityHelper->setOpacity(opacity, animated);
}
void NavigatorView::updateMainViewportRegion()
{
if (m_mainView != nullptr) {
m_viewportRegion = mapFromScene(m_mainView->mapToScene(m_mainView->rect()));
}
}
void NavigatorView::mousePressEvent(QMouseEvent *event)
{
m_mouseDown = true;
if (m_mainView) {
m_mainView->centerOn(mapToScene(event->pos()));
update();
}
return QGraphicsView::mousePressEvent(event);
}
void NavigatorView::mouseMoveEvent(QMouseEvent *event)
{
if (m_mouseDown && m_mainView) {
m_mainView->centerOn(mapToScene(event->pos()));
update();
}
return QGraphicsView::mouseMoveEvent(event);
}
void NavigatorView::mouseReleaseEvent(QMouseEvent *event)
{
m_mouseDown = false;
return QGraphicsView::mouseReleaseEvent(event);
}
void NavigatorView::wheelEvent(QWheelEvent *event)
{
event->ignore();
return QGraphicsView::wheelEvent(event);
}
void NavigatorView::paintEvent(QPaintEvent *event)
{
QGraphicsView::paintEvent(event);
QPainter painter(viewport());
painter.setPen(QPen(Qt::gray, 2));
painter.drawRect(m_viewportRegion.boundingRect());
}