HAL
geometry.cpp
Go to the documentation of this file.
2 
3 #include <QApplication>
4 #include <QDesktopWidget>
5 #include <QWidget>
6 
7 namespace hal
8 {
9  namespace gui_utility
10  {
12  {
13  auto boundingRect = QApplication::desktop()->availableGeometry(w);
14  auto requiredRect = w->geometry();
15  // Try fitting vertically, prioritizing top on screen
16  if (boundingRect.top() > requiredRect.top())
17  requiredRect.moveTop(boundingRect.top());
18  else if (boundingRect.bottom() < requiredRect.bottom())
19  requiredRect.moveBottom(boundingRect.bottom());
20  // Try fitting horizontally, prioritizing left on screen
21  if (boundingRect.left() > requiredRect.left())
22  requiredRect.moveLeft(boundingRect.left());
23  else if (boundingRect.right() < requiredRect.right())
24  requiredRect.moveRight(boundingRect.right());
25  w->move(requiredRect.topLeft());
26  }
27 
28  }
29 }
void ensureOnScreen(QWidget *w)
(Fully) displays the widget by moving it.
Definition: geometry.cpp:11
QDesktopWidget * desktop()
const QRect availableGeometry(const QWidget *widget) const const
void move(int x, int y)