Skip to content
Snippets Groups Projects
Commit de526ffc authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Andreas Traczyk
Browse files

generalMenuItem: enable text elide and width extension

Change-Id: I83897c81ed66313e84596bd7ab8cc3c79b56f47e
parent 767f1003
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,14 @@ Menu { ...@@ -50,6 +50,14 @@ Menu {
function loadMenuItems(menuItems) { function loadMenuItems(menuItems) {
root.addItem(menuTopBorder) 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) { for (var i = 0; i < menuItems.length; ++i) {
if (menuItems[i].canTrigger) { if (menuItems[i].canTrigger) {
menuItems[i].parentMenu = root menuItems[i].parentMenu = root
......
...@@ -37,6 +37,7 @@ MenuItem { ...@@ -37,6 +37,7 @@ MenuItem {
property string iconColor: "" property string iconColor: ""
property bool canTrigger: true property bool canTrigger: true
property bool addMenuSeparatorAfter: false property bool addMenuSeparatorAfter: false
property bool autoTextSizeAdjustment: true
property BaseContextMenu parentMenu property BaseContextMenu parentMenu
property int itemPreferredWidth: JamiTheme.menuItemsPreferredWidth property int itemPreferredWidth: JamiTheme.menuItemsPreferredWidth
...@@ -59,35 +60,53 @@ MenuItem { ...@@ -59,35 +60,53 @@ MenuItem {
anchors.fill: parent anchors.fill: parent
ResponsiveImage { RowLayout {
id: contextMenuItemImage spacing: 0
anchors.left: status === Image.Ready ? menuItemContentRect.left : undefined anchors.fill: menuItemContentRect
anchors.leftMargin: (status === Image.Ready ? 24 : 0)
anchors.verticalCenter: menuItemContentRect.verticalCenter
color: iconColor !== "" ? iconColor : JamiTheme.textColor ResponsiveImage {
id: contextMenuItemImage
smooth: true Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
opacity: 0.7 Layout.leftMargin: status === Image.Ready ? 24 : 0
}
Text {
id: contextMenuItemText
anchors.left: contextMenuItemImage.status === Image.Ready ? visible: status === Image.Ready
contextMenuItemImage.right : menuItemContentRect.left
anchors.leftMargin: contextMenuItemImage.status === Image.Ready ? 20 : 10
anchors.verticalCenter: menuItemContentRect.verticalCenter
height: itemPreferredHeight color: iconColor !== "" ? iconColor : JamiTheme.textColor
smooth: true
opacity: 0.7
}
text: itemName Text {
color: JamiTheme.textColor id: contextMenuItemText
wrapMode: Text.WordWrap
font.pointSize: JamiTheme.textFontSize Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
horizontalAlignment: Text.AlignLeft Layout.leftMargin: contextMenuItemImage.status === Image.Ready ? 20 : 10
verticalAlignment: Text.AlignVCenter 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: { onReleased: {
...@@ -97,12 +116,20 @@ MenuItem { ...@@ -97,12 +116,20 @@ MenuItem {
states: [ states: [
State { State {
name: "hovered"; when: hovered name: "hovered"
PropertyChanges { target: background; color: JamiTheme.hoverColor } when: hovered
PropertyChanges {
target: background
color: JamiTheme.hoverColor
}
}, },
State { State {
name: "normal"; when: !hovered name: "normal"
PropertyChanges { target: background; color: JamiTheme.backgroundColor } when: !hovered
PropertyChanges {
target: background
color: JamiTheme.backgroundColor
}
} }
] ]
} }
......
...@@ -197,6 +197,8 @@ Item { ...@@ -197,6 +197,8 @@ Item {
property real smartListAvatarSize: 52 property real smartListAvatarSize: 52
property real avatarSizeInCall: 130 property real avatarSizeInCall: 130
property real callButtonPreferredSize: 50 property real callButtonPreferredSize: 50
property real contextMenuItemTextPreferredWidth: 142
property real contextMenuItemTextMaxWidth: 182
property int participantCallInStatusViewWidth: 175 property int participantCallInStatusViewWidth: 175
property int participantCallInStatusViewHeight: 300 property int participantCallInStatusViewHeight: 300
property int participantCallInStatusDelegateHeight: 85 property int participantCallInStatusDelegateHeight: 85
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment