mainview: make all context menus generated at run time with the same style

By giving a base context menu, all context menus are generated at run time
and kept the same style. Some issues are fixed along with the patch.

Gitlab: #8
Gitlab: #35
Change-Id: Ieb812420fcb44c33d161a62c8574f6705dc5e1a9
diff --git a/src/mainview/components/ParticipantContextMenu.qml b/src/mainview/components/ParticipantContextMenu.qml
index 9397701..87d883a 100644
--- a/src/mainview/components/ParticipantContextMenu.qml
+++ b/src/mainview/components/ParticipantContextMenu.qml
@@ -1,7 +1,7 @@
-
 /*
  * Copyright (C) 2020 by Savoir-faire Linux
  * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com>
+ * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,6 +16,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
+
 import QtQuick 2.14
 import QtQuick.Controls 2.14
 import QtGraphicalEffects 1.12
@@ -23,105 +24,46 @@
 
 import "../../commoncomponents"
 
-import "../js/videodevicecontextmenuitemcreation.js" as VideoDeviceContextMenuItemCreation
-import "../js/selectscreenwindowcreation.js" as SelectScreenWindowCreation
+import "../../commoncomponents/js/contextmenugenerator.js" as ContextMenuGenerator
 
-Menu {
+Item {
     id: root
 
-    property int generalMenuSeparatorCount: 0
-    property int commonBorderWidth: 1
-    font.pointSize: JamiTheme.textFontSize + 3
     property var uri: ""
     property var maximized: true
     property var active: true
+    property var showHangup: false
+    property var showMaximize: false
+    property var showMinimize: false
 
-    function showHangup(show) {
-        if (show) {
-            hangupItem.visible = true
-            hangupItem.height = hangupItem.preferredHeight
-        } else {
-            hangupItem.visible = false
-            hangupItem.height = 0
-        }
+    function openMenu(){
+        if (showHangup)
+            ContextMenuGenerator.addMenuItem(qsTr("Hang up"),
+                                             "qrc:/images/icons/ic_call_end_white_24px.svg",
+                                             function (){
+                                                 CallAdapter.hangupCall(uri)
+                                             })
+
+        if (showMaximize)
+            ContextMenuGenerator.addMenuItem(qsTr("Maximize participant"),
+                                             "qrc:/images/icons/open_in_full-24px.svg",
+                                             function (){
+                                                  CallAdapter.maximizeParticipant(uri, active)
+                                             })
+        if (showMinimize)
+            ContextMenuGenerator.addMenuItem(qsTr("Minimize participant"),
+                                             "qrc:/images/icons/close_fullscreen-24px.svg",
+                                             function (){
+                                                  CallAdapter.minimizeParticipant()
+                                             })
+
+        root.height = ContextMenuGenerator.getMenu().height
+        root.width = ContextMenuGenerator.getMenu().width
+        ContextMenuGenerator.getMenu().open()
     }
 
-    function showMaximize(show) {
-        if (show) {
-            maximizeItem.visible = true
-            maximizeItem.height = hangupItem.preferredHeight
-        } else {
-            maximizeItem.visible = false
-            maximizeItem.height = 0
-        }
-    }
-
-    function showMinimize(show) {
-        if (show) {
-            minimizeItem.visible = true
-            minimizeItem.height = hangupItem.preferredHeight
-        } else {
-            minimizeItem.visible = false
-            minimizeItem.height = 0
-        }
-    }
-
-    function setHeight(visibleItems) {
-        root.height = hangupItem.preferredHeight * visibleItems;
-    }
-
-    /*
-     * All GeneralMenuItems should remain the same width / height.
-     */
-    GeneralMenuItem {
-        id: hangupItem
-
-        itemName: qsTr("Hangup")
-        iconSource: "qrc:/images/icons/ic_call_end_white_24px.svg"
-        icon.color: "black"
-        leftBorderWidth: commonBorderWidth
-        rightBorderWidth: commonBorderWidth
-
-        onClicked: {
-            CallAdapter.hangupCall(uri)
-            root.close()
-        }
-    }
-    GeneralMenuItem {
-        id: maximizeItem
-
-        itemName: qsTr("Maximize participant")
-        iconSource: "qrc:/images/icons/open_in_full-24px.svg"
-        leftBorderWidth: commonBorderWidth
-        rightBorderWidth: commonBorderWidth
-        visible: !maximized
-
-        onClicked: {
-            CallAdapter.maximizeParticipant(uri, active)
-            root.close()
-        }
-    }
-    GeneralMenuItem {
-        id: minimizeItem
-
-        itemName: qsTr("Minimize participant")
-        iconSource: "qrc:/images/icons/close_fullscreen-24px.svg"
-        leftBorderWidth: commonBorderWidth
-        rightBorderWidth: commonBorderWidth
-        visible: maximized
-
-        onClicked: {
-            CallAdapter.minimizeParticipant()
-            root.close()
-        }
-    }
-
-    background: Rectangle {
-        implicitWidth: hangupItem.preferredWidth
-        implicitHeight: hangupItem.preferredHeight * 3
-
-        border.width: commonBorderWidth
-        border.color: JamiTheme.tabbarBorderColor
+    Component.onCompleted: {
+        ContextMenuGenerator.createBaseContextMenuObjects(root)
     }
 }