emit viewportRectChanged() in a better way

This commit is contained in:
Gary Wang 2019-10-06 13:02:08 +08:00
parent 5d35de4e84
commit 0ae1def918
2 changed files with 3 additions and 13 deletions

View File

@ -19,6 +19,9 @@ GraphicsView::GraphicsView(QWidget *parent)
"border-radius: 3px;"); "border-radius: 3px;");
setAcceptDrops(true); setAcceptDrops(true);
setCheckerboardEnabled(false); setCheckerboardEnabled(false);
connect(horizontalScrollBar(), &QScrollBar::valueChanged, this, &GraphicsView::viewportRectChanged);
connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &GraphicsView::viewportRectChanged);
} }
void GraphicsView::showFromUrlList(const QList<QUrl> &urlList) void GraphicsView::showFromUrlList(const QList<QUrl> &urlList)
@ -243,17 +246,6 @@ void GraphicsView::dropEvent(QDropEvent *event)
} }
} }
void GraphicsView::paintEvent(QPaintEvent *event)
{
// A little dirty hack way to get the viewport "pan" event
// but still doesn't works well with gif which scaled up bigger than the window.
if (event->rect() == this->rect() && !isThingSmallerThanWindowWith(transform())) {
emit viewportRectChanged();
// qDebug() << "paintEvent" << event << QObject::sender();
}
return QGraphicsView::paintEvent(event);
}
bool GraphicsView::isThingSmallerThanWindowWith(const QTransform &transform) const bool GraphicsView::isThingSmallerThanWindowWith(const QTransform &transform) const
{ {
return rect().size().expandedTo(transform.mapRect(sceneRect()).size().toSize()) return rect().size().expandedTo(transform.mapRect(sceneRect()).size().toSize())

View File

@ -49,8 +49,6 @@ private:
void dragMoveEvent(QDragMoveEvent *event) override; void dragMoveEvent(QDragMoveEvent *event) override;
void dropEvent(QDropEvent *event) override; void dropEvent(QDropEvent *event) override;
void paintEvent(QPaintEvent *event) override;
bool isThingSmallerThanWindowWith(const QTransform &transform) const; bool isThingSmallerThanWindowWith(const QTransform &transform) const;
bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const; bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const;
void setCheckerboardEnabled(bool enabled); void setCheckerboardEnabled(bool enabled);