@@ -56,7 +56,6 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
5656 Q_EMIT pushedRightBoundary(newX - (parentItem()->width() - 1), buttons);
5757 newX = parentItem()->width() - 1;
5858 }
59− setX(newX);
6059
6160 qreal newY = y() + appliedMovement.y();
6261 if (newY < 0) {
@@ -64,6 +63,10 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
6463 } else if (newY >= parentItem()->height()) {
6564 newY = parentItem()->height() - 1;
6665 }
66+
67+ applyItemConfinement(newX, newY);
68+
69+ setX(newX);
6770 setY(newY);
6871
6972 QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
@@ -71,6 +74,31 @@ void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::Mouse
7174 buttons, modifiers);
7275}
7376
77+void MousePointer::applyItemConfinement(qreal &newX, qreal &newY)
78+{
79+ Q_ASSERT(parentItem() != nullptr);
80+
81+ if (m_confiningItem.isNull()) {
82+ return;
83+ }
84+
85+ QRectF confiningItemGeometry(0, 0, m_confiningItem->width(), m_confiningItem->height());
86+
87+ QRectF confiningRect = m_confiningItem->mapRectToItem(parentItem(), confiningItemGeometry);
88+
89+ if (newX < confiningRect.x()) {
90+ newX = confiningRect.x();
91+ } else if (newX > confiningRect.right()) {
92+ newX = confiningRect.right();
93+ }
94+
95+ if (newY < confiningRect.y()) {
96+ newY = confiningRect.y();
97+ } else if (newY > confiningRect.bottom()) {
98+ newY = confiningRect.bottom();
99+ }
100+}
101+
74102void MousePointer::handleWheelEvent(ulong timestamp, QPoint angleDelta, Qt::KeyboardModifiers modifiers)
75103{
76104 if (!parentItem()) {
@@ -156,3 +184,16 @@ void MousePointer::setCustomCursor(const QCursor &customCursor)
156184{
157185 CursorImageProvider::instance()->setCustomCursor(customCursor);
158186}
187+
188+QQuickItem* MousePointer::confiningItem() const
189+{
190+ return m_confiningItem.data();
191+}
192+
193+void MousePointer::setConfiningItem(QQuickItem *item)
194+{
195+ if (item != m_confiningItem) {
196+ m_confiningItem = item;
197+ Q_EMIT confiningItemChanged();
198+ }
199+}