Skip to content
This repository was archived by the owner on Sep 26, 2022. It is now read-only.

Commit 7bf2561

Browse files
committed
fix(StatusMenuItemDelegate): Use Control padding, spacing and mirrored
1 parent 436453c commit 7bf2561

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

sandbox/pages/StatusPopupMenuPage.qml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,8 @@ GridLayout {
6565
assetSettings.name: "info"
6666
}
6767

68-
StatusMenuItem {
69-
text: "Three [disabled]"
70-
assetSettings.name: "info"
71-
enabled: false
72-
}
73-
7468
StatusPopupMenu {
75-
title: "Four"
69+
title: "Two"
7670
assetSettings.name: "info"
7771

7872
StatusMenuItem {
@@ -86,14 +80,19 @@ GridLayout {
8680
}
8781

8882
StatusMenuItem {
89-
text: "Five [Danger]"
83+
text: "Disabled"
84+
assetSettings.name: "info"
85+
enabled: false
86+
}
87+
88+
StatusMenuItem {
89+
text: "Danger"
9090
type: StatusMenuItem.Type.Danger
9191
}
9292
}
9393

9494
StatusPopupMenu {
9595
id: customMenu
96-
width: customPopupButton.width
9796

9897
// subMenuItemIcons: [
9998
// {
@@ -108,10 +107,6 @@ GridLayout {
108107
// }
109108
// ]
110109

111-
MenuItem {
112-
text: "Default MenuItem, action: " + action
113-
}
114-
115110
StatusMenuItem {
116111
text: "Anywhere"
117112
}
@@ -139,7 +134,8 @@ CExPynn1gWf9bx498P7/nzPcxEzGExhBdJGYihtAYQlO+tUZvqrPbqeudo5iJGEJjCE15a3VtodH3q2I
139134

140135
StatusPopupMenu {
141136
title: "Cryptokitties"
142-
assetSettings.source: "qrc:/demoapp/data/profile-image-1.jpeg"
137+
assetSettings.isImage: true
138+
assetSettings.name: "qrc:/demoapp/data/profile-image-1.jpeg"
143139

144140
StatusMenuItem {
145141
text: "welcome"
@@ -164,7 +160,7 @@ CExPynn1gWf9bx498P7/nzPcxEzGExhBdJGYihtAYQlO+tUZvqrPbqeudo5iJGEJjCE15a3VtodH3q2I
164160
StatusPopupMenu {
165161
title: "Another community"
166162
assetSettings.isLetterIdenticon: true
167-
assetSettings.color: "red"
163+
assetSettings.bgColor: "red"
168164

169165
StatusMenuItem {
170166
text: "welcome"

src/StatusQ/Popups/StatusMenuItemDelegate.qml

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ MenuItem {
1212
implicitHeight: menu.hideDisabledItems && !enabled ? 0 : 38
1313
objectName: action ? action.objectName : "StatusMenuItemDelegate"
1414

15+
spacing: 4
16+
horizontalPadding: 8
17+
1518
// property int subMenuIndex
1619
// property var statusPopupMenu: null
1720

@@ -33,6 +36,7 @@ MenuItem {
3336

3437
readonly property bool isSubMenu: !!root.subMenu
3538
readonly property bool isStatusSubMenu: isSubMenu && (root.subMenu instanceof StatusPopupMenu)
39+
readonly property bool subMenuOpened: isSubMenu && root.subMenu.opened
3640
readonly property bool hasAction: !!root.action
3741
readonly property bool isStatusAction: d.hasAction && (root.action instanceof StatusMenuItem)
3842
readonly property bool isDangerIcon: d.isStatusAction && root.action.type === StatusMenuItem.Type.Danger
@@ -72,6 +76,8 @@ MenuItem {
7276
const c = d.assetSettings.color;
7377
if (!Qt.colorEqual(c, "transparent"))
7478
return c;
79+
if (!root.enabled)
80+
return Theme.palette.baseColor1;
7581
if (d.isDangerIcon)
7682
return Theme.palette.dangerColor1;
7783
return Theme.palette.primaryColor1;
@@ -104,14 +110,21 @@ MenuItem {
104110
}
105111

106112
indicator: Item {
107-
anchors.verticalCenter: parent.verticalCenter
108-
anchors.left: parent.left
109-
anchors.leftMargin: 8
113+
x: root.mirrored ? root.width - width - root.rightPadding : root.leftPadding
114+
y: root.topPadding + (root.availableHeight - height) / 2
115+
116+
// anchors.verticalCenter: parent.verticalCenter
117+
// anchors.left: parent.left
118+
// anchors.leftMargin: root.leftPadding
110119
implicitWidth: 24
111120
implicitHeight: 24
121+
visible: d.assetSettings.isLetterIdenticon
122+
|| d.assetSettings.isImage
123+
|| !!d.assetSettings.name
112124

113125
Loader {
114126
anchors.centerIn: parent
127+
active: parent.visible
115128
sourceComponent: {
116129
if (d.assetSettings.isImage)
117130
return indicatorImage;
@@ -120,24 +133,25 @@ MenuItem {
120133
return indicatorIcon;
121134
}
122135

123-
active: enabled
124-
&& (d.assetSettings.isLetterIdenticon
125-
|| d.assetSettings.isImage
126-
|| !!d.assetSettings.name)
127136
}
128137
}
129138

130139
contentItem: StatusBaseText {
131-
anchors.left: root.indicator.right
132-
anchors.right: arrowIcon.visible ? arrowIcon.left : arrowIcon.right
133-
anchors.rightMargin: 8
134-
anchors.leftMargin: 4
140+
readonly property real arrowPadding: root.subMenu && root.arrow ? root.arrow.width + root.spacing : 0
141+
readonly property real indicatorPadding: root.indicator.visible ? root.indicator.width + root.spacing : 0
142+
leftPadding: !root.mirrored ? indicatorPadding : arrowPadding
143+
rightPadding: root.mirrored ? indicatorPadding : arrowPadding
144+
145+
// anchors.left: root.indicator.visible ? parent.indicator.right : parent.left
146+
// anchors.right: arrowIcon.visible ? arrowIcon.left : arrowIcon.right
147+
// anchors.rightMargin: root.rightPadding
148+
// anchors.leftMargin: root.spacing
135149

136150
horizontalAlignment: Text.AlignLeft
137151
verticalAlignment: Text.AlignVCenter
138152

139153
text: root.text
140-
color: !root.enabled ? Theme.palette.directColor5
154+
color: !root.enabled ? Theme.palette.baseColor1
141155
: d.isDangerIcon ? Theme.palette.dangerColor1 : Theme.palette.directColor1
142156

143157
font.pixelSize: d.fontSettings.pixelSize // !!root.action.fontSettings ? root.action.fontSettings.pixelSize : 13
@@ -149,9 +163,12 @@ MenuItem {
149163

150164
arrow: StatusIcon {
151165
id: arrowIcon
152-
anchors.verticalCenter: parent.verticalCenter
153-
anchors.right: parent.right
154-
anchors.rightMargin: 8
166+
x: root.mirrored ? root.leftPadding : root.width - width - root.rightPadding
167+
y: root.topPadding + (root.availableHeight - height) / 2
168+
169+
// anchors.verticalCenter: parent.verticalCenter
170+
// anchors.right: parent.right
171+
// anchors.rightMargin: root.rightPadding
155172
height: 16
156173
visible: d.isSubMenu
157174
icon: "next"
@@ -160,7 +177,7 @@ MenuItem {
160177

161178
background: Rectangle {
162179
color: {
163-
if (!root.hovered)
180+
if (!root.hovered && !d.subMenuOpened)
164181
return "transparent"
165182
if (root.action.type === StatusMenuItem.Type.Danger)
166183
return Theme.palette.dangerColor3;

0 commit comments

Comments
 (0)