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()));
|
|
|
|
qDebug() << m_mainView->rect() << m_mainView->mapToScene(m_mainView->rect()) << m_viewportRegion;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|