2019-10-03 17:57:14 +08:00
|
|
|
#include "navigatorview.h"
|
|
|
|
|
2019-10-04 09:54:13 +08:00
|
|
|
#include "graphicsview.h"
|
|
|
|
|
2019-10-03 17:57:14 +08:00
|
|
|
#include <QMouseEvent>
|
2019-10-04 09:54:13 +08:00
|
|
|
#include <QDebug>
|
2019-10-03 17:57:14 +08:00
|
|
|
|
|
|
|
NavigatorView::NavigatorView(QWidget *parent)
|
|
|
|
: QGraphicsView (parent)
|
2019-10-04 09:54:13 +08:00
|
|
|
, m_viewportRegion(this->rect())
|
2019-10-03 17:57:14 +08:00
|
|
|
{
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setStyleSheet("background-color: rgba(0, 0, 0, 220);"
|
|
|
|
"border-radius: 3px;");
|
|
|
|
}
|
|
|
|
|
2019-10-04 09:54:13 +08:00
|
|
|
// doesn't take or manage its ownership
|
|
|
|
void NavigatorView::setMainView(GraphicsView *mainView)
|
|
|
|
{
|
|
|
|
m_mainView = mainView;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigatorView::updateMainViewportRegion()
|
|
|
|
{
|
|
|
|
if (m_mainView != nullptr) {
|
|
|
|
m_viewportRegion = mapFromScene(m_mainView->mapToScene(m_mainView->rect()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 20:41:27 +08:00
|
|
|
void NavigatorView::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
m_mouseDown = true;
|
|
|
|
|
|
|
|
if (m_mainView) {
|
|
|
|
m_mainView->centerOn(mapToScene(event->pos()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsView::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigatorView::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (m_mouseDown && m_mainView) {
|
|
|
|
m_mainView->centerOn(mapToScene(event->pos()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsView::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NavigatorView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
m_mouseDown = false;
|
|
|
|
|
|
|
|
return QGraphicsView::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2019-10-03 17:57:14 +08:00
|
|
|
void NavigatorView::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
return QGraphicsView::wheelEvent(event);
|
|
|
|
}
|
2019-10-04 09:54:13 +08:00
|
|
|
|
|
|
|
void NavigatorView::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsView::paintEvent(event);
|
|
|
|
|
|
|
|
QPainter painter(viewport());
|
|
|
|
painter.setPen(QPen(Qt::gray, 2));
|
|
|
|
painter.drawRect(m_viewportRegion.boundingRect());
|
|
|
|
}
|