mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-11 13:16:53 +00:00
GODT-22: Facelift
- GODT-1199: Add menu to status window - GODT-22: use ColorImage instead of IconLabel - GODT-22: remove banners from MainWindow - GODT-1199: Fix separator width - GODT-1199: Fix StatusWindow button position - GODT-1198: Open main window on startup if no users - GODT-1199: Fix avatar text color - GODT-1198: refactor main window layout - GODT-22: add missing components to qmldir - GODT-22: refactor components having Layout as root item - GODT-22: add more user controls - GODT-1199: Add status window resize and maximum height - GODT-22: WIP: notification arch - GODT-22: Notifications WIP - GODT-22: Fix notification filter, topmost notification - GODT-1199: Add notifications to status window - GODT-22: Add strict typization to colorScheme variable - GODT-1198: WIP Notifications, dialogs and banners - GODT-22: Add backend notifications (Banners & Dialogs) D
This commit is contained in:
@ -18,25 +18,34 @@
|
||||
import QtQml 2.12
|
||||
import QtQuick 2.13
|
||||
import QtQuick.Window 2.13
|
||||
import Qt.labs.platform 1.0
|
||||
import Qt.labs.platform 1.1
|
||||
|
||||
import Notifications 1.0
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
property var backend
|
||||
property var users
|
||||
|
||||
signal login(string username, string password)
|
||||
signal login2FA(string username, string code)
|
||||
signal login2Password(string username, string password)
|
||||
signal loginAbort(string username)
|
||||
|
||||
property var mainWindow: MainWindow {
|
||||
property Notifications _notifications: Notifications {
|
||||
id: notifications
|
||||
backend: root.backend
|
||||
frontendMain: mainWindow
|
||||
frontendStatus: statusWindow
|
||||
frontendTray: trayIcon
|
||||
}
|
||||
|
||||
property MainWindow _mainWindow: MainWindow {
|
||||
id: mainWindow
|
||||
visible: true
|
||||
visible: false
|
||||
|
||||
backend: root.backend
|
||||
users: root.users
|
||||
notifications: notifications
|
||||
|
||||
onLogin: {
|
||||
root.login(username, password)
|
||||
@ -52,38 +61,142 @@ QtObject {
|
||||
}
|
||||
}
|
||||
|
||||
property var _trayMenu: Window {
|
||||
id: trayMenu
|
||||
title: "window 2"
|
||||
property StatusWindow _statusWindow: StatusWindow {
|
||||
id: statusWindow
|
||||
visible: false
|
||||
flags: Qt.Dialog
|
||||
|
||||
backend: root.backend
|
||||
notifications: notifications
|
||||
|
||||
onShowMainWindow: {
|
||||
mainWindow.visible = true
|
||||
}
|
||||
onShowHelp: {
|
||||
|
||||
}
|
||||
onShowSettings: {
|
||||
|
||||
}
|
||||
onQuit: {
|
||||
backend.quit()
|
||||
}
|
||||
}
|
||||
|
||||
property var _trayIcon: SystemTrayIcon {
|
||||
property SystemTrayIcon _trayIcon: SystemTrayIcon {
|
||||
id: trayIcon
|
||||
visible: true
|
||||
iconSource: "./icons/ic-systray.svg"
|
||||
onActivated: {
|
||||
function calcStatusWindowPosition(statusWidth, statusHeight) {
|
||||
function bound(num, lower_limit, upper_limit) {
|
||||
return Math.max(lower_limit, Math.min(upper_limit, num))
|
||||
}
|
||||
// checks if rect1 fits within rect2
|
||||
function isRectFit(rect1, rect2) {
|
||||
//if (rect2.)
|
||||
if ((rect2.left > rect1.left) ||
|
||||
(rect2.right < rect1.right) ||
|
||||
(rect2.top > rect1.top) ||
|
||||
(rect2.bottom < rect1.bottom)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// First we get icon center position.
|
||||
// On some platforms (X11 / Wayland) Qt does not provide icon geometry info.
|
||||
// In this case we rely on cursor position
|
||||
var iconCenter = Qt.point(geometry.x + (geometry.width / 2), geometry.y + (geometry.height / 2))
|
||||
|
||||
if (geometry.width == 0 && geometry.height == 0) {
|
||||
iconCenter = backend.getCursorPos()
|
||||
}
|
||||
|
||||
// Now bound this position to virtual screen available rect
|
||||
// TODO: here we should detect which screen mouse is on and use that screen available geometry to bound
|
||||
iconCenter.x = bound(iconCenter.x, 0, Qt.application.screens[0].desktopAvailableWidth)
|
||||
iconCenter.y = bound(iconCenter.y, 0, Qt.application.screens[0].desktopAvailableHeight)
|
||||
|
||||
var x = 0
|
||||
var y = 0
|
||||
|
||||
// Check if window may fit above
|
||||
x = iconCenter.x - statusWidth / 2
|
||||
y = iconCenter.y - statusHeight
|
||||
if (isRectFit(
|
||||
Qt.rect(x, y, statusWidth, statusHeight),
|
||||
// TODO: we should detect which screen mouse is on and use that screen available geometry to bound
|
||||
Qt.rect(0, 0, Qt.application.screens[0].desktopAvailableWidth, Qt.application.screens[0].desktopAvailableHeight)
|
||||
)) {
|
||||
return Qt.point(x, y)
|
||||
}
|
||||
|
||||
// Check if window may fit below
|
||||
x = iconCenter.x - statusWidth / 2
|
||||
y = iconCenter.y
|
||||
if (isRectFit(
|
||||
Qt.rect(x, y, statusWidth, statusHeight),
|
||||
// TODO: we should detect which screen mouse is on and use that screen available geometry to bound
|
||||
Qt.rect(0, 0, Qt.application.screens[0].desktopAvailableWidth, Qt.application.screens[0].desktopAvailableHeight)
|
||||
)) {
|
||||
return Qt.point(x, y)
|
||||
}
|
||||
|
||||
// Check if window may fit to the left
|
||||
x = iconCenter.x - statusWidth
|
||||
y = iconCenter.y - statusHeight / 2
|
||||
if (isRectFit(
|
||||
Qt.rect(x, y, statusWidth, statusHeight),
|
||||
// TODO: we should detect which screen mouse is on and use that screen available geometry to bound
|
||||
Qt.rect(0, 0, Qt.application.screens[0].desktopAvailableWidth, Qt.application.screens[0].desktopAvailableHeight)
|
||||
)) {
|
||||
return Qt.point(x, y)
|
||||
}
|
||||
|
||||
// Check if window may fit to the right
|
||||
x = iconCenter.x
|
||||
y = iconCenter.y - statusHeight / 2
|
||||
if (isRectFit(
|
||||
Qt.rect(x, y, statusWidth, statusHeight),
|
||||
// TODO: we should detect which screen mouse is on and use that screen available geometry to bound
|
||||
Qt.rect(0, 0, Qt.application.screens[0].desktopAvailableWidth, Qt.application.screens[0].desktopAvailableHeight)
|
||||
)) {
|
||||
return Qt.point(x, y)
|
||||
}
|
||||
|
||||
// TODO: add fallback
|
||||
}
|
||||
|
||||
switch (reason) {
|
||||
case SystemTrayIcon.Unknown:
|
||||
case SystemTrayIcon.Unknown:
|
||||
break;
|
||||
case SystemTrayIcon.Context:
|
||||
trayMenu.x = (Screen.desktopAvailableWidth - trayMenu.width) / 2
|
||||
trayMenu.visible = !trayMenu.visible
|
||||
case SystemTrayIcon.Context:
|
||||
case SystemTrayIcon.Trigger:!statusWindow.visible
|
||||
if (!statusWindow.visible) {
|
||||
var point = calcStatusWindowPosition(statusWindow.width, statusWindow.height)
|
||||
statusWindow.x = point.x
|
||||
statusWindow.y = point.y
|
||||
}
|
||||
statusWindow.visible = !statusWindow.visible
|
||||
break
|
||||
case SystemTrayIcon.DoubleClick:
|
||||
case SystemTrayIcon.DoubleClick:
|
||||
case SystemTrayIcon.MiddleClick:
|
||||
mainWindow.visible = !mainWindow.visible
|
||||
break;
|
||||
case SystemTrayIcon.Trigger:
|
||||
trayMenu.x = (Screen.desktopAvailableWidth - trayMenu.width) / 2
|
||||
trayMenu.visible = !trayMenu.visible
|
||||
break;
|
||||
case SystemTrayIcon.MiddleClick:
|
||||
mainWindow.visible = !mainWindow.visible
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
if (root.backend.users.count === 0) {
|
||||
mainWindow.show()
|
||||
}
|
||||
|
||||
if (root.backend.users.count === 1 && root.backend.users.get(0).loggedIn === false) {
|
||||
mainWindow.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user