From 5e3d6c9090171e5c28d4e021a63aa676f5adcff7 Mon Sep 17 00:00:00 2001
From: agsantos <aline.gondimsantos@savoirfairelinux.com>
Date: Thu, 10 Mar 2022 18:13:13 -0500
Subject: [PATCH] windows/popups: set max size

Set a maximum size for Jami secondary windows/popups.

Change-Id: Ie03c48c58e6f08662fe4a51bacbd2c02a500012c
GitLab: #691
---
 src/MainApplicationWindow.qml                 |  4 ---
 src/constant/JamiQmlUtils.qml                 |  2 --
 src/constant/JamiTheme.qml                    |  1 +
 src/mainview/MainView.qml                     | 11 +++---
 src/mainview/components/AboutPopUp.qml        | 14 ++------
 src/mainview/components/CallOverlay.qml       |  4 +--
 src/mainview/components/SelectScreen.qml      | 36 +++++++++----------
 src/mainview/components/UserProfile.qml       | 17 +++------
 src/mainview/js/selectscreenwindowcreation.js | 17 +++++----
 9 files changed, 41 insertions(+), 65 deletions(-)

diff --git a/src/MainApplicationWindow.qml b/src/MainApplicationWindow.qml
index 9dd2360b3..0011976b8 100644
--- a/src/MainApplicationWindow.qml
+++ b/src/MainApplicationWindow.qml
@@ -215,16 +215,12 @@ ApplicationWindow {
 
     onClosing: root.close()
 
-    onScreenChanged: JamiQmlUtils.mainApplicationScreen = root.screen
-
     Component.onCompleted: {
         if (CurrentAccountToMigrate.accountToMigrateListSize <= 0)
             startClient()
         else
             startAccountMigration()
 
-        JamiQmlUtils.mainApplicationScreen = root.screen
-
         if (Qt.platform.os.toString()  !== "windows" && Qt.platform.os.toString()  !== "osx")
             DBusErrorHandler.setActive(true)
     }
diff --git a/src/constant/JamiQmlUtils.qml b/src/constant/JamiQmlUtils.qml
index 4863b8a8d..d3cba9806 100644
--- a/src/constant/JamiQmlUtils.qml
+++ b/src/constant/JamiQmlUtils.qml
@@ -31,8 +31,6 @@ Item {
     readonly property string accountMigrationViewLoadPath: "qrc:/src/AccountMigrationView.qml"
     readonly property string base64StringTitle: "data:image/png;base64,"
 
-    property var mainApplicationScreen: ""
-
     property var accountCreationInputParaObject: ({})
 
     function setUpAccountCreationInputPara(inputPara) {
diff --git a/src/constant/JamiTheme.qml b/src/constant/JamiTheme.qml
index 9c5a62899..701874871 100644
--- a/src/constant/JamiTheme.qml
+++ b/src/constant/JamiTheme.qml
@@ -271,6 +271,7 @@ Item {
     property real minimumPreviewWidth: 120
     property real pluginHandlersPopupViewHeight: 200
     property real pluginHandlersPopupViewDelegateHeight: 50
+    property real secondaryDialogDimension: 500
 
     property real lineEditContextMenuItemsHeight: 15
     property real lineEditContextMenuItemsWidth: 100
diff --git a/src/mainview/MainView.qml b/src/mainview/MainView.qml
index e9342ecd7..0c1191242 100644
--- a/src/mainview/MainView.qml
+++ b/src/mainview/MainView.qml
@@ -449,13 +449,8 @@ Rectangle {
 
     AboutPopUp {
         id: aboutPopUpDialog
-
-        onVisibleChanged: {
-            height = Qt.binding(function () {
-                return Math.min(preferredHeight,
-                                mainView.height - JamiTheme.preferredMarginSize * 2)
-            })
-        }
+        width: Math.min(mainView.width - 2 * JamiTheme.preferredMarginSize, JamiTheme.secondaryDialogDimension)
+        height: Math.min(mainView.height - 2 * JamiTheme.preferredMarginSize, JamiTheme.secondaryDialogDimension)
     }
 
     WelcomePageQrDialog {
@@ -464,6 +459,8 @@ Rectangle {
 
     UserProfile {
         id: userProfile
+        width: Math.min(mainView.width - 2 * JamiTheme.preferredMarginSize, JamiTheme.secondaryDialogDimension)
+        height: Math.min(mainView.height - 2 * JamiTheme.preferredMarginSize, JamiTheme.secondaryDialogDimension)
     }
 
     Shortcut {
diff --git a/src/mainview/components/AboutPopUp.qml b/src/mainview/components/AboutPopUp.qml
index 6b5cd98fd..8bfa16a20 100644
--- a/src/mainview/components/AboutPopUp.qml
+++ b/src/mainview/components/AboutPopUp.qml
@@ -29,26 +29,16 @@ import "../../commoncomponents"
 BaseModalDialog {
     id: root
 
-    property int preferredHeight: 0
-
-    width: 400
-
-    onPopupContentLoadStatusChanged: {
-        if (popupContentLoadStatus === Loader.Ready)
-            preferredHeight = Qt.binding(function() {
-                return popupContentLoader.item.contentHeight
-            })
-    }
-
     popupContent: JamiFlickable {
         id: aboutPopUpScrollView
 
         contentHeight: aboutPopUpContentRectColumnLayout.implicitHeight
+        width: root.width
 
         ColumnLayout {
             id: aboutPopUpContentRectColumnLayout
 
-            width: Math.max(root.width, implicitWidth)
+            width: root.width
             height: Math.max(aboutPopUpScrollView.height, implicitHeight)
 
             ResponsiveImage {
diff --git a/src/mainview/components/CallOverlay.qml b/src/mainview/components/CallOverlay.qml
index a55e1f7ed..3ac6addda 100644
--- a/src/mainview/components/CallOverlay.qml
+++ b/src/mainview/components/CallOverlay.qml
@@ -160,7 +160,7 @@ Item {
         if (Qt.application.screens.length === 1) {
             AvAdapter.shareEntireScreen(0)
         } else {
-            SelectScreenWindowCreation.createSelectScreenWindowObject(JamiQmlUtils.mainApplicationScreen)
+            SelectScreenWindowCreation.createSelectScreenWindowObject(appWindow)
             SelectScreenWindowCreation.showSelectScreenWindow(callPreviewId, false)
         }
     }
@@ -169,7 +169,7 @@ Item {
         AvAdapter.muteCamera = !sharingActive && root.isVideoMuted
         AvAdapter.getListWindows()
         if (AvAdapter.windowsNames.length >= 1) {
-            SelectScreenWindowCreation.createSelectScreenWindowObject(JamiQmlUtils.mainApplicationScreen)
+            SelectScreenWindowCreation.createSelectScreenWindowObject(appWindow)
             SelectScreenWindowCreation.showSelectScreenWindow(callPreviewId, true)
         }
     }
diff --git a/src/mainview/components/SelectScreen.qml b/src/mainview/components/SelectScreen.qml
index a77a2666f..ff86aa82c 100644
--- a/src/mainview/components/SelectScreen.qml
+++ b/src/mainview/components/SelectScreen.qml
@@ -35,15 +35,17 @@ import "../../commoncomponents"
 Window {
     id: root
 
-    property int minWidth: 650
-    property int minHeight: 500
-
     property bool window: false
 
     property int selectedScreenNumber: -1
     property bool selectAllScreens: false
     property string currentPreview: ""
     property var screens: []
+    property real componentMinWidth: 200
+    property real componentWidthDoubleColumn: screenSelectionScrollView.width / 2 -
+                                            screenSelectionScrollViewFlow.spacing / 2 - JamiTheme.preferredMarginSize
+    property real componentWidthSingleColumn: screenSelectionScrollView.width -
+                                              2 * JamiTheme.preferredMarginSize
     
     modality: Qt.ApplicationModal
     title: window ? JamiStrings.selectWindow : JamiStrings.selectScreen
@@ -75,11 +77,6 @@ Window {
         screenInfo2.model = screens.length
         windowsText.visible = root.window
     }
-    minimumWidth: minWidth
-    minimumHeight: minHeight
-
-    width: minWidth
-    height: minHeight
 
     Rectangle {
         id: selectScreenWindowRect
@@ -110,7 +107,7 @@ Window {
                 rightPadding: JamiTheme.preferredMarginSize
                 leftPadding: JamiTheme.preferredMarginSize
 
-                spacing: 10
+                spacing: JamiTheme.preferredMarginSize
 
                 Text {
                     width: screenSelectionScrollView.width
@@ -134,8 +131,7 @@ Window {
 
                         color: JamiTheme.secondaryBackgroundColor
 
-                        width: screenSelectionScrollView.width / 2 -
-                                screenSelectionScrollViewFlow.spacing / 2 - JamiTheme.preferredMarginSize
+                        width: componentWidthDoubleColumn > componentMinWidth ? componentWidthDoubleColumn : componentWidthSingleColumn
                         height: 3 * width / 4
 
                         border.color: selectedScreenNumber === index ? JamiTheme.screenSelectionBorderColor : JamiTheme.tabbarBorderColor
@@ -208,8 +204,7 @@ Window {
 
                     color: JamiTheme.secondaryBackgroundColor
 
-                    width: screenSelectionScrollView.width / 2 -
-                                screenSelectionScrollViewFlow.spacing / 2 - JamiTheme.preferredMarginSize
+                    width: componentWidthDoubleColumn > componentMinWidth ? componentWidthDoubleColumn : componentWidthSingleColumn
                     height: 3 * width / 4
 
                     border.color: selectAllScreens ? JamiTheme.screenSelectionBorderColor : JamiTheme.tabbarBorderColor
@@ -286,8 +281,7 @@ Window {
 
                         color: JamiTheme.secondaryBackgroundColor
 
-                        width: screenSelectionScrollView.width / 2 -
-                                screenSelectionScrollViewFlow.spacing / 2 - JamiTheme.preferredMarginSize
+                        width: componentWidthDoubleColumn > componentMinWidth ? componentWidthDoubleColumn : componentWidthSingleColumn
                         height: 3 * width / 4
 
                         border.color: selectedScreenNumber === index ? JamiTheme.screenSelectionBorderColor : JamiTheme.tabbarBorderColor
@@ -356,14 +350,17 @@ Window {
         anchors.bottomMargin: JamiTheme.preferredMarginSize
         anchors.horizontalCenter: selectScreenWindowRect.horizontalCenter
 
-        width: childrenRect.width
+        width: parent.width
         height: childrenRect.height
         spacing: JamiTheme.preferredMarginSize
 
         MaterialButton {
             id: selectButton
 
-            preferredWidth: 200
+            Layout.maximumWidth: 200
+            Layout.fillWidth: true
+            Layout.alignment: Qt.AlignHCenter
+            Layout.leftMargin: JamiTheme.preferredMarginSize
 
             enabled: selectedScreenNumber != -1 || selectAllScreens
             opacity: enabled ? 1.0 : 0.5
@@ -392,7 +389,10 @@ Window {
         MaterialButton {
             id: cancelButton
 
-            preferredWidth: 200
+            Layout.maximumWidth: 200
+            Layout.fillWidth: true
+            Layout.alignment: Qt.AlignHCenter
+            Layout.rightMargin: JamiTheme.preferredMarginSize
 
             color: JamiTheme.buttonTintedBlack
             hoveredColor: JamiTheme.buttonTintedBlackHovered
diff --git a/src/mainview/components/UserProfile.qml b/src/mainview/components/UserProfile.qml
index 106cb5218..f2b4d492e 100644
--- a/src/mainview/components/UserProfile.qml
+++ b/src/mainview/components/UserProfile.qml
@@ -35,14 +35,12 @@ BaseModalDialog {
 
     property int preferredImgSize: 80
 
-    width: 480
-    height: 480
-
     popupContent: Rectangle {
         id: userProfileContentRect
 
         color: JamiTheme.backgroundColor
         radius: JamiTheme.modalPopupRadius
+        anchors.fill: parent
 
         GridLayout {
             id: userProfileDialogLayout
@@ -160,6 +158,7 @@ BaseModalDialog {
                 id: contactId
 
                 Layout.alignment: Qt.AlignLeft
+                width: userProfileContentRect.width - 200
 
                 font.pointSize: JamiTheme.textFontSize
                 font.kerning: true
@@ -169,19 +168,11 @@ BaseModalDialog {
                 readOnly: true
                 selectByMouse: true
 
-                wrapMode: Text.NoWrap
-                text: textMetricsContactIdText.elidedText
+                wrapMode: Text.WrapAnywhere
+                text: idText
 
                 horizontalAlignment: Text.AlignLeft
                 verticalAlignment: Text.AlignVCenter
-
-                TextMetrics {
-                    id: textMetricsContactIdText
-                    font: contactId.font
-                    text: idText
-                    elideWidth: userProfileContentRect.width - 200
-                    elide: Qt.ElideMiddle
-                }
             }
 
             Text {
diff --git a/src/mainview/js/selectscreenwindowcreation.js b/src/mainview/js/selectscreenwindowcreation.js
index 42766a8cf..dd8a3664e 100644
--- a/src/mainview/js/selectscreenwindowcreation.js
+++ b/src/mainview/js/selectscreenwindowcreation.js
@@ -19,13 +19,14 @@
 // Global select screen window component, object variable for creation.
 var selectScreenWindowComponent
 var selectScreenWindowObject
+var mainWindow
 
-function createSelectScreenWindowObject(providedScreen) {
+function createSelectScreenWindowObject(appWindow) {
     if (selectScreenWindowObject)
         return
     selectScreenWindowComponent = Qt.createComponent(
                 "../components/SelectScreen.qml")
-    selectScreenWindowComponent.screen = providedScreen
+    mainWindow = appWindow
     if (selectScreenWindowComponent.status === Component.Ready)
         finishCreation()
     else if (selectScreenWindowComponent.status === Component.Error)
@@ -49,11 +50,13 @@ function showSelectScreenWindow(previewId, window) {
     selectScreenWindowObject.window = window
     selectScreenWindowObject.show()
 
-    var screen = selectScreenWindowComponent.screen
-    selectScreenWindowObject.x = screen.virtualX +
-            (screen.width - selectScreenWindowObject.width) / 2
-    selectScreenWindowObject.y = screen.virtualY +
-            (screen.height - selectScreenWindowObject.height) / 2
+    var centerX = mainWindow.x + mainWindow.width / 2
+    var centerY = mainWindow.y + mainWindow.height / 2
+
+    selectScreenWindowObject.width = 0.75 * appWindow.width
+    selectScreenWindowObject.height = 0.75 * appWindow.height
+    selectScreenWindowObject.x = centerX - selectScreenWindowObject.width / 2
+    selectScreenWindowObject.y = centerY - selectScreenWindowObject.height / 2
 }
 
 // Destroy and reset selectScreenWindowObject when window is closed.
-- 
GitLab