Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Ottens <kevin.ottens@nextcloud.com>2020-05-20 22:36:08 +0300
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>2020-06-15 15:32:25 +0300
commit5848a1575b40075c6df4474727cf61934fb9d62b (patch)
treece065adc6b2337aab70807ccd90c4925295a6c2c /src/gui/systray.cpp
parent40824dc42740fd9a6e67f20bbd3dcdc82efbca3c (diff)
Make the reference point independent of the window
This leads to simplifying the computation code quite a bit as well. Indeed we're separating concern between what is window size dependent or not and that shows. Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
Diffstat (limited to 'src/gui/systray.cpp')
-rw-r--r--src/gui/systray.cpp73
1 files changed, 40 insertions, 33 deletions
diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp
index 15f18ba66..5bc9e1479 100644
--- a/src/gui/systray.cpp
+++ b/src/gui/systray.cpp
@@ -242,8 +242,9 @@ QRect Systray::currentScreenRect() const
return rect.translated(screen->virtualGeometry().topLeft());
}
-QPoint Systray::computeWindowReferencePoint(int width, int height) const
+QPoint Systray::computeWindowReferencePoint() const
{
+ constexpr auto spacing = 4;
const auto trayIconCenter = calcTrayIconCenter();
const auto taskbarRect = taskbarGeometry();
const auto taskbarScreenEdge = taskbarOrientation();
@@ -252,22 +253,22 @@ QPoint Systray::computeWindowReferencePoint(int width, int height) const
switch(taskbarScreenEdge) {
case TaskBarPosition::Bottom:
return {
- trayIconCenter.x() - width / 2,
- screenRect.bottom() - taskbarRect.height() - height - 4
+ trayIconCenter.x(),
+ screenRect.bottom() - taskbarRect.height() - spacing
};
case TaskBarPosition::Left:
return {
- screenRect.left() + taskbarRect.width() + 4,
+ screenRect.left() + taskbarRect.width() + spacing,
trayIconCenter.y()
};
case TaskBarPosition::Top:
return {
- trayIconCenter.x() - width / 2,
- screenRect.top() + taskbarRect.height() + 4
+ trayIconCenter.x(),
+ screenRect.top() + taskbarRect.height() + spacing
};
case TaskBarPosition::Right:
return {
- screenRect.right() - taskbarRect.width() - width - 4,
+ screenRect.right() - taskbarRect.width() - spacing,
trayIconCenter.y()
};
}
@@ -276,38 +277,44 @@ QPoint Systray::computeWindowReferencePoint(int width, int height) const
QPoint Systray::computeWindowPosition(int width, int height) const
{
- auto referencePoint = computeWindowReferencePoint(width, height);
+ const auto referencePoint = computeWindowReferencePoint();
const auto taskbarScreenEdge = taskbarOrientation();
- const auto taskbarRect = taskbarGeometry();
const auto screenRect = currentScreenRect();
- if (screenRect.right() <= referencePoint.x() + width) {
- referencePoint.rx() = screenRect.right() - width - 4;
-#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
- referencePoint.rx() -= taskbarScreenEdge == TaskBarPosition::Right ? taskbarRect.width() : 0;
-#endif
- }
-
- if (referencePoint.x() <= screenRect.left()) {
- referencePoint.rx() = screenRect.left() + 4;
-#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
- referencePoint.rx() += taskbarScreenEdge == TaskBarPosition::Left ? taskbarRect.width() : 0;
-#endif
- }
-
- if (referencePoint.y() <= screenRect.top()) {
- referencePoint.ry() = screenRect.top() + 4;
+ const auto topLeft = [=]() {
+ switch(taskbarScreenEdge) {
+ case TaskBarPosition::Bottom:
+ return referencePoint - QPoint(width / 2, height);
+ case TaskBarPosition::Left:
+ return referencePoint;
+ case TaskBarPosition::Top:
+ return referencePoint - QPoint(width / 2, 0);
+ case TaskBarPosition::Right:
+ return referencePoint - QPoint(width, 0);
+ }
+ Q_UNREACHABLE();
+ }();
+ const auto bottomRight = topLeft + QPoint(width, height);
+ const auto windowRect = [=]() {
+ const auto rect = QRect(topLeft, bottomRight);
+ auto offset = QPoint();
+
+ if (rect.left() < screenRect.left()) {
+ offset.setX(screenRect.left() - rect.left() + 4);
+ } else if (rect.right() > screenRect.right()) {
+ offset.setX(screenRect.right() - rect.right() - 4);
+ }
-#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
- referencePoint.ry() += taskbarScreenEdge == TaskBarPosition::Top ? taskbarRect.height() : 0;
-#endif
- }
- if (screenRect.bottom() <= referencePoint.y() + height) {
- referencePoint.ry() = screenRect.bottom() - height - 4;
- }
+ if (rect.top() < screenRect.top()) {
+ offset.setY(screenRect.top() - rect.top() + 4);
+ } else if (rect.bottom() > screenRect.bottom()) {
+ offset.setY(screenRect.bottom() - rect.bottom() - 4);
+ }
- return referencePoint;
+ return rect.translated(offset);
+ }();
+ return windowRect.topLeft();
}
QPoint Systray::calcTrayIconCenter() const