10 #include <QGuiApplication>
18 QPoint
FitRectScreen (QPoint pos,
const QSize& size, FitFlags flags,
const QPoint& shiftAdd)
23 QPoint
FitRect (QPoint pos,
const QSize& size,
const QRect& geometry,
24 FitFlags flags,
const QPoint& shiftAdd)
26 int xDiff =
std::max (0, pos.x () + size.width () - (geometry.width () + geometry.x ()));
28 xDiff =
std::min (0, pos.x () - geometry.x ());
29 int yDiff =
std::max (0, pos.y () + size.height () - (geometry.height () + geometry.y ()));
31 yDiff =
std::min (0, pos.y () - geometry.y ());
35 auto overlapFixer = [] (
int& diff,
int dim)
38 diff = dim > diff ? dim : diff;
41 if (QRect (pos - QPoint (xDiff, yDiff), size).contains (pos) && yDiff < size.height ())
42 overlapFixer (yDiff, size.height ());
43 if (QRect (pos - QPoint (xDiff, yDiff), size).contains (pos) && xDiff < size.width ())
44 overlapFixer (xDiff, size.width ());
48 pos.rx () -= xDiff + shiftAdd.x ();
50 pos.ry () -= yDiff + shiftAdd.y ();
57 if (
auto screen = QGuiApplication::screenAt (p))
60 qWarning () << Q_FUNC_INFO
61 <<
"unknown screen for point"
63 return QGuiApplication::primaryScreen ();