Improve window "move within desktop rectangle" code (#1685)
This is used by tooltips to make sure they're always visible Behaviour changed to stick to screen instead and flip up if no space left below cursor
This commit is contained in:
@@ -566,10 +566,14 @@ void BaseWindow::moveIntoDesktopRect(QWidget *parent)
|
||||
|
||||
// move the widget into the screen geometry if it's not already in there
|
||||
QDesktopWidget *desktop = QApplication::desktop();
|
||||
QPoint globalCursorPos = QCursor::pos();
|
||||
|
||||
QRect s = desktop->availableGeometry(parent);
|
||||
QPoint p = this->pos();
|
||||
|
||||
bool stickRight = false;
|
||||
bool stickBottom = false;
|
||||
|
||||
if (p.x() < s.left())
|
||||
{
|
||||
p.setX(s.left());
|
||||
@@ -580,13 +584,20 @@ void BaseWindow::moveIntoDesktopRect(QWidget *parent)
|
||||
}
|
||||
if (p.x() + this->width() > s.right())
|
||||
{
|
||||
stickRight = true;
|
||||
p.setX(s.right() - this->width());
|
||||
}
|
||||
if (p.y() + this->height() > s.bottom())
|
||||
{
|
||||
stickBottom = true;
|
||||
p.setY(s.bottom() - this->height());
|
||||
}
|
||||
|
||||
if (stickRight && stickBottom)
|
||||
{
|
||||
p.setY(globalCursorPos.y() - this->height() - 16);
|
||||
}
|
||||
|
||||
if (p != this->pos())
|
||||
this->move(p);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user