LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
geometry.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "geometry.h"
10#include <QGuiApplication>
11#include <QRect>
12#include <QScreen>
13#include <QSize>
14#include <QtDebug>
15
16namespace LC::Util
17{
19 {
20 return FitRect (pos, size, ScreenGeometry (pos), flags, shiftAdd);
21 }
22
23 QPoint FitRect (QPoint pos, const QSize& size, const QRect& geometry,
24 FitFlags flags, const QPoint& shiftAdd)
25 {
26 int xDiff = std::max (0, pos.x () + size.width () - (geometry.width () + geometry.x ()));
27 if (!xDiff)
28 xDiff = std::min (0, pos.x () - geometry.x ());
29 int yDiff = std::max (0, pos.y () + size.height () - (geometry.height () + geometry.y ()));
30 if (!yDiff)
31 yDiff = std::min (0, pos.y () - geometry.y ());
32
33 if (flags & FitFlag::NoOverlap)
34 {
35 auto overlapFixer = [] (int& diff, int dim)
36 {
37 if (diff > 0)
38 diff = dim > diff ? dim : diff;
39 };
40
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 ());
45 }
46
47 if (xDiff)
48 pos.rx () -= xDiff + shiftAdd.x ();
49 if (yDiff)
50 pos.ry () -= yDiff + shiftAdd.y ();
51
52 return pos;
53 }
54
56 {
57 if (auto screen = QGuiApplication::screenAt (p))
58 return screen;
59
61 << "unknown screen for point"
62 << p;
63 return QGuiApplication::primaryScreen ();
64 }
65
67 {
68 return GetScreenWithFallback (p)->availableGeometry ();
69 }
70
72 {
73 return GetScreenWithFallback (p)->geometry ();
74 }
75}
QPoint FitRect(QPoint pos, const QSize &size, const QRect &geometry, FitFlags flags, const QPoint &shiftAdd)
Tries to fit a rectangle (like a dialog or popup) into geometry.
Definition geometry.cpp:23
QPoint FitRectScreen(QPoint pos, const QSize &size, FitFlags flags, const QPoint &shiftAdd)
Tries to fit a rectangle (like a dialog or popup) into screen.
Definition geometry.cpp:18
@ NoOverlap
Definition geometry.h:37
Container< T > Filter(const Container< T > &c, F f)
Definition prelude.h:118
QRect AvailableGeometry(const QPoint &p)
Definition geometry.cpp:66
QScreen * GetScreenWithFallback(const QPoint &p)
Definition geometry.cpp:55
QRect ScreenGeometry(const QPoint &p)
Definition geometry.cpp:71