Commit 55e074c8 authored by Nikola Nikolic's avatar Nikola Nikolic Committed by Albert Astals Cid
Browse files

Prevent popup note from being dragged outside the viewport

BUG: 423363
parent 915e8230
Pipeline #213702 passed with stage
in 8 minutes and 12 seconds
......@@ -139,10 +139,36 @@ public:
case QEvent::MouseButtonRelease:
mousePressPos = QPoint();
break;
case QEvent::MouseMove:
case QEvent::MouseMove: {
me = (QMouseEvent *)e;
parentWidget()->move(me->pos() - mousePressPos + parentWidget()->pos());
// viewport info
const QPoint topLeftPoint = parentWidget()->parentWidget()->pos();
const int viewportHeight = parentWidget()->parentWidget()->height();
const int viewportWidth = parentWidget()->parentWidget()->width();
// annotation's popup window info
QPoint newPositionPoint = me->pos() - mousePressPos + parentWidget()->pos();
const int annotHeight = parentWidget()->height();
const int annotWidth = parentWidget()->width();
// make sure x is in range
if (newPositionPoint.x() < topLeftPoint.x()) {
newPositionPoint.setX(topLeftPoint.x());
} else if (newPositionPoint.x() + annotWidth > topLeftPoint.x() + viewportWidth) {
newPositionPoint.setX(topLeftPoint.x() + viewportWidth - annotWidth);
}
// make sure y is in range
if (newPositionPoint.y() < topLeftPoint.y()) {
newPositionPoint.setY(topLeftPoint.y());
} else if (newPositionPoint.y() + annotHeight > topLeftPoint.y() + viewportHeight) {
newPositionPoint.setY(topLeftPoint.y() + viewportHeight - annotHeight);
}
parentWidget()->move(newPositionPoint);
break;
}
default:
return false;
}
......
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