Commit 4ca80b15 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Add panning for the formeditor



You can now pan if you drag the mouse around with the middle mouse button.

Change-Id: I70e1666c542406b126214c2b9b8b56193bcbcf76
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 9fa03fb3
......@@ -31,11 +31,13 @@
#include <QWheelEvent>
#include <QDebug>
#include <QScrollBar>
namespace QmlDesigner {
FormEditorGraphicsView::FormEditorGraphicsView(QWidget *parent) :
QGraphicsView(parent)
QGraphicsView(parent),
m_isPanning(false)
{
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setResizeAnchor(QGraphicsView::AnchorViewCenter);
......@@ -74,6 +76,44 @@ void FormEditorGraphicsView::wheelEvent(QWheelEvent *event)
}
void FormEditorGraphicsView::mousePressEvent(QMouseEvent *event)
{
if (event->buttons().testFlag(Qt::MiddleButton)) {
m_isPanning = true;
m_panStartX = event->x();
m_panStartY = event->y();
setCursor(Qt::ClosedHandCursor);
event->accept();
} else {
QGraphicsView::mousePressEvent(event);
}
}
void FormEditorGraphicsView::mouseMoveEvent(QMouseEvent *event)
{
if (m_isPanning) {
horizontalScrollBar()->setValue(horizontalScrollBar()->value() - (event->x() - m_panStartX));
verticalScrollBar()->setValue(verticalScrollBar()->value() - (event->y() - m_panStartY));
m_panStartX = event->x();
m_panStartY = event->y();
event->accept();
}else {
QGraphicsView::mouseMoveEvent(event);
}
}
void FormEditorGraphicsView::mouseReleaseEvent(QMouseEvent *event)
{
if (m_isPanning) {
m_isPanning = false;
setCursor(Qt::ArrowCursor);
event->accept();
}else {
QGraphicsView::mouseReleaseEvent(event);
}
}
void FormEditorGraphicsView::setRootItemRect(const QRectF &rect)
{
m_rootItemRect = rect;
......
......@@ -46,8 +46,12 @@ public:
protected:
void drawBackground(QPainter *painter, const QRectF &rect);
void wheelEvent(QWheelEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
private:
bool m_isPanning;
int m_panStartX, m_panStartY;
QRectF m_rootItemRect;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment