Skip to content
Snippets Groups Projects
Commit aec314b2 authored by Marco Bubke's avatar Marco Bubke
Browse files

Mouse event positions are adjusted to the graphics view rect

Task-number: BAUHAUS-120
parent 0969f3b8
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include "formeditorgraphicsview.h" #include "formeditorgraphicsview.h"
#include <QWheelEvent> #include <QWheelEvent>
#include <QApplication>
#include <QtDebug>
namespace QmlDesigner { namespace QmlDesigner {
...@@ -73,6 +75,41 @@ void FormEditorGraphicsView::wheelEvent(QWheelEvent *event) ...@@ -73,6 +75,41 @@ void FormEditorGraphicsView::wheelEvent(QWheelEvent *event)
} }
void FormEditorGraphicsView::mouseMoveEvent(QMouseEvent *event)
{
if (rect().contains(event->pos())) {
QGraphicsView::mouseMoveEvent(event);
} else {
QPoint position = event->pos();
QPoint topLeft = rect().topLeft();
QPoint bottomRight = rect().bottomRight();
position.rx() = qMax(topLeft.x(), qMin(position.x(), bottomRight.x()));
position.ry() = qMax(topLeft.y(), qMin(position.y(), bottomRight.y()));
QMouseEvent *mouseEvent = QMouseEvent::createExtendedMouseEvent(event->type(), position, mapToGlobal(position), event->button(), event->buttons(), event->modifiers());
QGraphicsView::mouseMoveEvent(mouseEvent);
delete mouseEvent;
}
}
void FormEditorGraphicsView::mouseReleaseEvent(QMouseEvent *event)
{
if (rect().contains(event->pos())) {
QGraphicsView::mouseReleaseEvent(event);
} else {
QPoint position = event->pos();
QPoint topLeft = rect().topLeft();
QPoint bottomRight = rect().bottomRight();
position.rx() = qMax(topLeft.x(), qMin(position.x(), bottomRight.x()));
position.ry() = qMax(topLeft.y(), qMin(position.y(), bottomRight.y()));
QMouseEvent *mouseEvent = QMouseEvent::createExtendedMouseEvent(event->type(), position, mapToGlobal(position), event->button(), event->buttons(), event->modifiers());
QGraphicsView::mouseReleaseEvent(mouseEvent);
delete mouseEvent;
}
}
void FormEditorGraphicsView::drawBackground(QPainter *painter, const QRectF &rect) void FormEditorGraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
{ {
painter->save(); painter->save();
......
...@@ -44,6 +44,8 @@ public: ...@@ -44,6 +44,8 @@ public:
protected: protected:
void drawBackground(QPainter *painter, const QRectF &rect); void drawBackground(QPainter *painter, const QRectF &rect);
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
}; };
} // namespace QmlDesigner } // namespace QmlDesigner
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment