on xenial help sign in
Make the PreviewButtons be of the width of the button and not half the total width

half the total width is still the max width and the combos are still all the same width Approved by: Andrea Cimitan, Unity8 CI Bot

commit75d3855f39e063c22f9233f455cc50c947ef57ba authorAlbert Astals Cid <albert.astals@canonical.com> dateWed 9 Nov 2016, 15:03 (10 years ago) parent76ddd6242716a4
3 files changed+47−5
qml/Dash/Previews/PreviewActionCombo.qml+13−2 qml/Dash/Previews/PreviewActions.qml+3−2 tests/qmltests/Dash/Previews/tst_PreviewActions.qml+31−1
qml/Dash/Previews/PreviewActionCombo.qml+13−2
@@ -21,6 +21,7 @@ Item {
2121 id: root
2222
2323 implicitHeight: childrenRect.height
24+ implicitWidth: Math.max(moreButton.implicitWidth, column.maxButtonImplicitWidth)
2425
2526 signal triggeredAction(var actionData)
2627
@@ -39,14 +40,23 @@ Item {
3940 }
4041
4142 Column {
43+ id: column
4244 anchors {
4345 top: moreButton.bottom
4446 topMargin: height > 0 ? spacing : 0
4547 }
4648 objectName: "buttonColumn"
4749 spacing: units.gu(1)
48− width: parent.width
4950 height: moreButton.expanded ? implicitHeight : 0
51+
52+ property real maxButtonImplicitWidth: 0
53+ function calculateImplicitWidth() {
54+ maxButtonImplicitWidth = 0;
55+ for (var i in children) {
56+ maxButtonImplicitWidth = Math.max(maxButtonImplicitWidth, children[i].implicitWidth);
57+ }
58+ }
59+
5060 clip: true
5161 Behavior on height {
5262 UbuntuNumberAnimation {
@@ -59,7 +69,8 @@ Item {
5969
6070 delegate: PreviewActionButton {
6171 data: modelData
62− width: implicitWidth < root.width ? root.width : implicitWidth
72+ width: root.width
73+ onImplicitWidthChanged: column.calculateImplicitWidth();
6374 onClicked: root.triggeredAction(modelData)
6475 strokeColor: moreButton.strokeColor
6576 }
qml/Dash/Previews/PreviewActions.qml+3−2
@@ -27,6 +27,7 @@ PreviewWidget {
2727
2828 implicitHeight: row.height + units.gu(1)
2929 readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
30+ readonly property real maxButtonWidth: (width - units.gu(1)) / 2
3031
3132 Row {
3233 id: row
@@ -40,7 +41,7 @@ PreviewWidget {
4041 readonly property bool button: root.actions && root.actions.length == 2
4142 readonly property bool combo: root.actions && root.actions.length > 2
4243 source: button ? "PreviewActionButton.qml" : (combo ? "PreviewActionCombo.qml" : "")
43− width: (root.width - units.gu(1)) / 2
44+ width: Math.min(root.maxButtonWidth, implicitWidth + units.gu(2))
4445 onLoaded: {
4546 if (button) {
4647 item.data = Qt.binding(function() { return root.actions[1]; });
@@ -65,7 +66,7 @@ PreviewWidget {
6566 data: visible ? root.actions[0] : null
6667 visible: root.actions && root.actions.length > 0
6768 onTriggeredAction: root.triggered(root.widgetId, actionData.id, actionData)
68− width: (root.width - units.gu(1)) / 2
69+ width: Math.min(root.maxButtonWidth, implicitWidth + units.gu(2))
6970 color: root.scopeStyle ? root.scopeStyle.previewButtonColor : theme.palette.normal.positive
7071 }
7172 }
tests/qmltests/Dash/Previews/tst_PreviewActions.qml+31−1
@@ -39,12 +39,30 @@ Rectangle {
3939 readonly property var actionDataFiveActions: {
4040 "actions": [{"label": "Some Label C", "id": "someid3"},
4141 {"label": "Some Label D", "id": "someid4"},
42− {"label": "Some Label E", "id": "someid5"},
42+ {"label": "Some Longer Longer Longer Longer Label E", "id": "someid5"},
4343 {"label": "Some Label F", "id": "someid6"},
4444 {"label": "Some Label G", "id": "someid7"}
4545 ]
4646 }
4747
48+ readonly property var actionDataFiveActions2: {
49+ "actions": [{"label": "Some Label C", "id": "someid3"},
50+ {"label": "Some Label D", "id": "someid4"},
51+ {"label": "Some E", "id": "someid5"},
52+ {"label": "Some Label F", "id": "someid6"},
53+ {"label": "Some Label G", "id": "someid7"}
54+ ]
55+ }
56+
57+ readonly property var actionDataFiveActions3: {
58+ "actions": [{"label": "C", "id": "someid3"},
59+ {"label": "D", "id": "someid4"},
60+ {"label": "E", "id": "someid5"},
61+ {"label": "F", "id": "someid6"},
62+ {"label": "G", "id": "someid7"}
63+ ]
64+ }
65+
4866 property var actionModelActions: {
4967 "actions": [{"label": "Some Label H", "id": "someid8"},
5068 {"label": "Some Label I", "id": "someid9"},
@@ -90,6 +108,18 @@ Rectangle {
90108 }
91109 }
92110
111+ PreviewActions {
112+ id: buttonAndCombo2
113+ widgetData: actionDataFiveActions2
114+ width: units.gu(40)
115+ }
116+
117+ PreviewActions {
118+ id: buttonAndCombo3
119+ widgetData: actionDataFiveActions3
120+ width: units.gu(40)
121+ }
122+
93123 PreviewActions {
94124 id: twoActions
95125 widgetId: "2buttons"