@@ -56,7 +56,6 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
56 Q_EMIT pushedRightBoundary(newX - (parentItem()->width() - 1), buttons);
56 Q_EMIT pushedRightBoundary(newX - (parentItem()->width() - 1), buttons);
57 newX = parentItem()->width() - 1;
57 newX = parentItem()->width() - 1;
61 qreal newY = y() + appliedMovement.y();
60 qreal newY = y() + appliedMovement.y();
62 if (newY < 0) {
61 if (newY < 0) {
@@ -64,6 +63,10 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
64 } else if (newY >= parentItem()->height()) {
63 } else if (newY >= parentItem()->height()) {
65 newY = parentItem()->height() - 1;
64 newY = parentItem()->height() - 1;
67+ applyItemConfinement(newX, newY);
67 setY(newY);
70 setY(newY);
69 QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
72 QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
@@ -71,6 +74,31 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
71 buttons, modifiers);
74 buttons, modifiers);
77+void MousePointer::applyItemConfinement(qreal &newX, qreal &newY)
79+ Q_ASSERT(parentItem() != nullptr);
81+ if (m_confiningItem.isNull()) {
85+ QRectF confiningItemGeometry(0, 0, m_confiningItem->width(), m_confiningItem->height());
87+ QRectF confiningRect = m_confiningItem->mapRectToItem(parentItem(), confiningItemGeometry);
89+ if (newX < confiningRect.x()) {
90+ newX = confiningRect.x();
91+ } else if (newX > confiningRect.right()) {
92+ newX = confiningRect.right();
95+ if (newY < confiningRect.y()) {
96+ newY = confiningRect.y();
97+ } else if (newY > confiningRect.bottom()) {
98+ newY = confiningRect.bottom();
74void MousePointer::handleWheelEvent(ulong timestamp, QPoint angleDelta, Qt::KeyboardModifiers modifiers)
102void MousePointer::handleWheelEvent(ulong timestamp, QPoint angleDelta, Qt::KeyboardModifiers modifiers)
76 if (!parentItem()) {
104 if (!parentItem()) {
@@ -156,3 +184,16 @@ void MousePointer::setCustomCursor(const QCursor &customCursor)
157 CursorImageProvider::instance()->setCustomCursor(customCursor);
185 CursorImageProvider::instance()->setCustomCursor(customCursor);
188+QQuickItem* MousePointer::confiningItem() const
190+ return m_confiningItem.data();
193+void MousePointer::setConfiningItem(QQuickItem *item)
195+ if (item != m_confiningItem) {
196+ m_confiningItem = item;
197+ Q_EMIT confiningItemChanged();