LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
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
16
namespace
LC::Util
17
{
18
QPoint
FitRectScreen
(QPoint pos,
const
QSize& size, FitFlags flags,
const
QPoint& shiftAdd)
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
55
QScreen*
GetScreenWithFallback
(
const
QPoint& p)
56
{
57
if
(
auto
screen = QGuiApplication::screenAt (p))
58
return
screen;
59
60
qWarning () << Q_FUNC_INFO
61
<<
"unknown screen for point"
62
<< p;
63
return
QGuiApplication::primaryScreen ();
64
}
65
66
QRect
AvailableGeometry
(
const
QPoint& p)
67
{
68
return
GetScreenWithFallback
(p)->availableGeometry ();
69
}
70
71
QRect
ScreenGeometry
(
const
QPoint& p)
72
{
73
return
GetScreenWithFallback
(p)->geometry ();
74
}
75
}
geometry.h
LC::Util::FitRect
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
LC::Util::FitRectScreen
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
LC::Util::NoOverlap
@ NoOverlap
Definition
geometry.h:37
LC::Util
Definition
icoreproxy.h:34
LC::Util::AvailableGeometry
QRect AvailableGeometry(const QPoint &p)
Definition
geometry.cpp:66
LC::Util::GetScreenWithFallback
QScreen * GetScreenWithFallback(const QPoint &p)
Definition
geometry.cpp:55
LC::Util::ScreenGeometry
QRect ScreenGeometry(const QPoint &p)
Definition
geometry.cpp:71
src
util
gui
geometry.cpp
Generated by
1.17.0