diff --git a/src/commoncomponents/contextmenu/BaseContextMenu.qml b/src/commoncomponents/contextmenu/BaseContextMenu.qml index 79c4e5508b6bf76e933655160009e8bfc4ae9763..9b100a6935848e541cd55dd5025df4b9b6165902 100644 --- a/src/commoncomponents/contextmenu/BaseContextMenu.qml +++ b/src/commoncomponents/contextmenu/BaseContextMenu.qml @@ -50,6 +50,14 @@ Menu { function loadMenuItems(menuItems) { root.addItem(menuTopBorder) + // use the maximum text width as the preferred width for menu + for (var j = 0; j < menuItems.length; ++j) { + var currentItemWidth = menuItems[j].itemPreferredWidth + if (currentItemWidth !== JamiTheme.menuItemsPreferredWidth + && currentItemWidth > menuPreferredWidth) + menuPreferredWidth = currentItemWidth + } + for (var i = 0; i < menuItems.length; ++i) { if (menuItems[i].canTrigger) { menuItems[i].parentMenu = root diff --git a/src/commoncomponents/contextmenu/GeneralMenuItem.qml b/src/commoncomponents/contextmenu/GeneralMenuItem.qml index 173835590f49b4c0977ab6284ecb25c341531c19..6aa3edc7e83232aa75ed187d6411fa2537497d16 100644 --- a/src/commoncomponents/contextmenu/GeneralMenuItem.qml +++ b/src/commoncomponents/contextmenu/GeneralMenuItem.qml @@ -37,6 +37,7 @@ MenuItem { property string iconColor: "" property bool canTrigger: true property bool addMenuSeparatorAfter: false + property bool autoTextSizeAdjustment: true property BaseContextMenu parentMenu property int itemPreferredWidth: JamiTheme.menuItemsPreferredWidth @@ -59,35 +60,53 @@ MenuItem { anchors.fill: parent - ResponsiveImage { - id: contextMenuItemImage + RowLayout { + spacing: 0 - anchors.left: status === Image.Ready ? menuItemContentRect.left : undefined - anchors.leftMargin: (status === Image.Ready ? 24 : 0) - anchors.verticalCenter: menuItemContentRect.verticalCenter + anchors.fill: menuItemContentRect - color: iconColor !== "" ? iconColor : JamiTheme.textColor + ResponsiveImage { + id: contextMenuItemImage - smooth: true - opacity: 0.7 - } - - Text { - id: contextMenuItemText + Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft + Layout.leftMargin: status === Image.Ready ? 24 : 0 - anchors.left: contextMenuItemImage.status === Image.Ready ? - contextMenuItemImage.right : menuItemContentRect.left - anchors.leftMargin: contextMenuItemImage.status === Image.Ready ? 20 : 10 - anchors.verticalCenter: menuItemContentRect.verticalCenter + visible: status === Image.Ready - height: itemPreferredHeight + color: iconColor !== "" ? iconColor : JamiTheme.textColor + smooth: true + opacity: 0.7 + } - text: itemName - color: JamiTheme.textColor - wrapMode: Text.WordWrap - font.pointSize: JamiTheme.textFontSize - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter + Text { + id: contextMenuItemText + + Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft + Layout.leftMargin: contextMenuItemImage.status === Image.Ready ? 20 : 10 + Layout.rightMargin: contextMenuItemImage.status === Image.Ready ? 20 : 10 + Layout.preferredHeight: itemPreferredHeight + Layout.preferredWidth: JamiTheme.contextMenuItemTextPreferredWidth + + text: itemName + color: JamiTheme.textColor + font.pointSize: JamiTheme.textFontSize + horizontalAlignment: Text.AlignLeft + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + + onWidthChanged: { + if (autoTextSizeAdjustment + && width > contextMenuItemText.Layout.preferredWidth) { + if (width > JamiTheme.contextMenuItemTextMaxWidth) + contextMenuItemText.Layout.preferredWidth + = JamiTheme.contextMenuItemTextMaxWidth + else + contextMenuItemText.Layout.preferredWidth = width + itemPreferredWidth += contextMenuItemText.Layout.preferredWidth + - JamiTheme.contextMenuItemTextPreferredWidth + } + } + } } onReleased: { @@ -97,12 +116,20 @@ MenuItem { states: [ State { - name: "hovered"; when: hovered - PropertyChanges { target: background; color: JamiTheme.hoverColor } + name: "hovered" + when: hovered + PropertyChanges { + target: background + color: JamiTheme.hoverColor + } }, State { - name: "normal"; when: !hovered - PropertyChanges { target: background; color: JamiTheme.backgroundColor } + name: "normal" + when: !hovered + PropertyChanges { + target: background + color: JamiTheme.backgroundColor + } } ] } diff --git a/src/constant/JamiTheme.qml b/src/constant/JamiTheme.qml index d223ff360cd6e2d5d91afbd2f2b178be64506ff7..e3cc33c617b72a19873702354c6d1496dd9f34a2 100644 --- a/src/constant/JamiTheme.qml +++ b/src/constant/JamiTheme.qml @@ -197,6 +197,8 @@ Item { property real smartListAvatarSize: 52 property real avatarSizeInCall: 130 property real callButtonPreferredSize: 50 + property real contextMenuItemTextPreferredWidth: 142 + property real contextMenuItemTextMaxWidth: 182 property int participantCallInStatusViewWidth: 175 property int participantCallInStatusViewHeight: 300 property int participantCallInStatusDelegateHeight: 85