Use TaskBarPosition enum on the QML side
authorKevin Ottens <kevin.ottens@nextcloud.com>
Wed, 20 May 2020 13:17:54 +0000 (15:17 +0200)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Mon, 15 Jun 2020 12:32:25 +0000 (12:32 +0000)
Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/gui/systray.cpp
src/gui/tray/Window.qml

index 88d6812a49cd9dc674d197c3d41f275f0da16d82..3370a85f77b01d88fb93798a738f817238df21d9 100644 (file)
@@ -62,6 +62,7 @@ Systray::Systray()
     connect(AccountManager::instance(), &AccountManager::accountAdded,
         this, &Systray::showWindow);
 
+    qmlRegisterUncreatableType<Systray>("com.nextcloud.gui", 1, 0, "Systray", "This type is uncreatable, it is exported for its enums");
 }
 
 void Systray::create()
index 77c097ba679d02d745bcf0012490161273a578db..3684162d7e506c5b3cf1301a1d0637f718683c40 100644 (file)
@@ -8,6 +8,7 @@ import QtGraphicalEffects 1.0
 \r
 // Custom qml modules are in /theme (and included by resources.qrc)\r
 import Style 1.0\r
+import com.nextcloud.gui 1.0\r
 \r
 Window {\r
 \r
@@ -29,24 +30,24 @@ Window {
         switch(tbOrientation) {\r
             // Platform separation here: Windows and macOS draw coordinates have to be given in screen-coordinates\r
             // KDE and most xorg based DEs expect them as virtual coordinates\r
-            case 0:\r
+            case Systray.Bottom:\r
                 console.debug("Taskbar is on the bottom.");\r
                 trayWindowX = trayIconCenter.x - trayWindow.width / 2;\r
                 trayWindowY = (Qt.platform.os !== "linux") ? (Screen.height - taskbarRect.height - trayWindow.height - 4)\r
                                                            : (Screen.height + Screen.virtualY - taskbarRect.height - trayWindow.height - 4);\r
                 break;\r
-            case 1:\r
+            case Systray.Left:\r
                 console.debug("Taskbar is on the left.");\r
                 trayWindowX = (Qt.platform.os !== "linux") ? (taskbarRect.width + 4)\r
                                                            : (Screen.virtualX + taskbarRect.width + 4);\r
                 trayWindowY = trayIconCenter.y;\r
                 break;\r
-            case 2:\r
+            case Systray.Top:\r
                 console.debug("Taskbar is on the top.");\r
                 trayWindowX = trayIconCenter.x - trayWindow.width / 2;\r
                 trayWindowY = Screen.virtualY + taskbarRect.height + 4;\r
                 break;\r
-            case 3:\r
+            case Systray.Right:\r
                 console.debug("Taskbar is on the right.");\r
                 trayWindowX = (Qt.platform.os !== "linux") ? (Screen.width - taskbarRect.width - trayWindow.width - 4)\r
                                                            : (Screen.width + Screen.virtualX - taskbarRect.width - trayWindow.width - 4);\r
@@ -68,7 +69,7 @@ Window {
             if (Qt.platform.os !== "linux") {\r
                 trayWindowX = Screen.width - trayWindow.width - 4;\r
             } else {\r
-                trayWindowX = Screen.width + Screen.virtualX - trayWindow.width - 4 - (tbOrientation === 3 ? taskbarRect.width : 0);\r
+                trayWindowX = Screen.width + Screen.virtualX - trayWindow.width - 4 - (tbOrientation === Systray.Right ? taskbarRect.width : 0);\r
             }\r
         }\r
         if (trayWindowX <= Screen.x && Qt.platform.os !== "linux") {\r
@@ -77,7 +78,7 @@ Window {
         }\r
         if (trayWindowX <= Screen.virtualX && Qt.platform.os === "linux") {\r
            console.debug("Out-of-screen condition on the left detected. Adjusting window position.");\r
-           trayWindowX = Screen.virtualX + 4 + (tbOrientation === 1 ? taskbarRect.width : 0)\r
+           trayWindowX = Screen.virtualX + 4 + (tbOrientation === Systray.Left ? taskbarRect.width : 0)\r
         }\r
         if (trayWindowY <= Screen.y && Qt.platform.os !== "linux") {\r
             console.debug("Out-of-screen condition on the top detected. Adjusting window position.");\r
@@ -85,7 +86,7 @@ Window {
         }\r
         if (trayWindowY <= Screen.virtualY && Qt.platform.os === "linux") {\r
             console.debug("Out-of-screen condition on the top detected. Adjusting window position.");\r
-            trayWindowY = Screen.virtualY + 4 + (tbOrientation === 2 ? taskbarRect.height : 0);\r
+            trayWindowY = Screen.virtualY + 4 + (tbOrientation === Systray.Top ? taskbarRect.height : 0);\r
         }\r
         if (Screen.height <= trayWindowY - Screen.virtualY + trayWindow.height) {\r
             console.debug("Out-of-screen condition on the bottom detected. Adjusting window position.");\r