Changeset View
Changeset View
Standalone View
Standalone View
src/controls/ActionToolBar.qml
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 88 | RowLayout { | |||
---|---|---|---|---|---|
91 | spacing: 0 | 91 | spacing: 0 | ||
92 | 92 | | |||
93 | Item { | 93 | Item { | ||
94 | Layout.fillWidth: root.alignment == Qt.AlignRight || root.alignment == Qt.AlignHCenter || root.alignment == Qt.AlignCenter; | 94 | Layout.fillWidth: root.alignment == Qt.AlignRight || root.alignment == Qt.AlignHCenter || root.alignment == Qt.AlignCenter; | ||
95 | Layout.fillHeight: true | 95 | Layout.fillHeight: true | ||
96 | } | 96 | } | ||
97 | 97 | | |||
98 | Repeater { | 98 | Repeater { | ||
99 | model: placeholderLayout.visibleActions | 99 | model: root.actions | ||
100 | 100 | | |||
101 | delegate: PrivateActionToolButton { | 101 | delegate: PrivateActionToolButton { | ||
102 | id: actionDelegate | 102 | id: actionDelegate | ||
103 | 103 | | |||
104 | Layout.alignment: Qt.AlignVCenter | 104 | Layout.alignment: Qt.AlignVCenter | ||
105 | Layout.minimumWidth: implicitWidth | 105 | Layout.minimumWidth: implicitWidth | ||
106 | // Use rightMargin instead of spacing on the layout to prevent spacer items | 106 | // Use rightMargin instead of spacing on the layout to prevent spacer items | ||
107 | // from creating useless spacing | 107 | // from creating useless spacing | ||
108 | Layout.rightMargin: Kirigami.Units.smallSpacing | 108 | Layout.rightMargin: Kirigami.Units.smallSpacing | ||
109 | 109 | | |||
110 | visible: details.visibleActions.indexOf(modelData) != -1 | ||||
111 | && (modelData.visible === undefined || modelData.visible) | ||||
broulik: Shouldn't this be
```
modelData.visible === undefined || modelData.visible
```
i.e. have the… | |||||
ahiemstra: You are right, fixed. | |||||
112 | | ||||
110 | flat: root.flat && !modelData.icon.color.a | 113 | flat: root.flat && !modelData.icon.color.a | ||
111 | display: root.display | 114 | display: details.iconOnlyActions.indexOf(modelData) != -1 ? Controls.Button.IconOnly : root.display | ||
112 | kirigamiAction: modelData | 115 | kirigamiAction: modelData | ||
113 | } | 116 | } | ||
114 | } | 117 | } | ||
115 | 118 | | |||
116 | Item { | 119 | Item { | ||
117 | Layout.fillWidth: root.alignment == Qt.AlignLeft || root.alignment == Qt.AlignHCenter || root.alignment == Qt.AlignCenter; | 120 | Layout.fillWidth: root.alignment == Qt.AlignLeft || root.alignment == Qt.AlignHCenter || root.alignment == Qt.AlignCenter; | ||
118 | Layout.fillHeight: true | 121 | Layout.fillHeight: true | ||
119 | } | 122 | } | ||
120 | 123 | | |||
121 | PrivateActionToolButton { | 124 | PrivateActionToolButton { | ||
122 | id: moreButton | 125 | id: moreButton | ||
123 | 126 | | |||
124 | Layout.alignment: Qt.AlignRight | 127 | Layout.alignment: Qt.AlignRight | ||
125 | 128 | visible: root.hiddenActions.length > 0 || details.hiddenActions.length > 0 | |||
126 | visible: hiddenActions.length > 0 || placeholderLayout.hiddenActions.length > 0 | | |||
127 | showMenuArrow: false | | |||
128 | 129 | | |||
129 | kirigamiAction: Kirigami.Action { | 130 | kirigamiAction: Kirigami.Action { | ||
130 | icon.name: "overflow-menu" | 131 | icon.name: "overflow-menu" | ||
132 | displayHint: Kirigami.Action.DisplayHint.IconOnly | Kirigami.Action.DisplayHint.HideChildIndicator | ||||
131 | children: Array.prototype.map.call(root.actions, function (i) { return i }).concat(Array.prototype.map.call(hiddenActions, function (i) { return i })) | 133 | children: Array.prototype.map.call(root.actions, function (i) { return i }).concat(Array.prototype.map.call(hiddenActions, function (i) { return i })) | ||
132 | } | 134 | } | ||
133 | 135 | | |||
134 | menu.submenuComponent: ActionsMenu { | 136 | menu.submenuComponent: ActionsMenu { | ||
135 | Binding { | 137 | Binding { | ||
136 | target: parentItem | 138 | target: parentItem | ||
137 | property: "visible" | 139 | property: "visible" | ||
138 | value: placeholderLayout.visibleActions.indexOf(parentAction) == -1 && | 140 | value: details.visibleActions.indexOf(parentAction) == -1 && | ||
139 | (parentAction.visible === undefined || parentAction.visible) | 141 | (parentAction.visible === undefined || parentAction.visible) | ||
140 | } | 142 | } | ||
141 | } | 143 | } | ||
142 | 144 | | |||
143 | menu.itemDelegate: ActionMenuItem { | 145 | menu.itemDelegate: ActionMenuItem { | ||
144 | visible: placeholderLayout.visibleActions.indexOf(action) == -1 && | 146 | visible: details.visibleActions.indexOf(action) == -1 && | ||
145 | (action.visible === undefined || action.visible) | 147 | (action.visible === undefined || action.visible) | ||
146 | } | 148 | } | ||
147 | } | 149 | } | ||
148 | } | 150 | } | ||
149 | 151 | | |||
150 | RowLayout { | 152 | ActionToolBarLayoutDetails { | ||
151 | id: placeholderLayout | 153 | id: details | ||
152 | enabled: false | 154 | anchors.fill: parent | ||
153 | opacity: 0 // Cannot use visible: false because then relayout doesn't happen correctly | 155 | actions: root.actions | ||
154 | spacing: Kirigami.Units.smallSpacing | 156 | rightPadding: moreButton.width + Kirigami.Units.smallSpacing | ||
155 | 157 | flat: root.flat | |||
156 | property var visibleActions: [] | | |||
157 | property var hiddenActions: [] | | |||
158 | property real layoutWidth: root.width - moreButton.width - Kirigami.Units.smallSpacing | | |||
159 | | ||||
160 | Repeater { | | |||
161 | id: placeholderRepeater | | |||
162 | model: root.actions | | |||
163 | | ||||
164 | PrivateActionToolButton { | | |||
165 | flat: root.flat && !modelData.icon.color.a | | |||
166 | display: root.display | 158 | display: root.display | ||
167 | visible: modelData.visible === undefined || modelData.visible | | |||
168 | kirigamiAction: modelData | | |||
169 | | ||||
170 | property bool actionVisible: x + width < placeholderLayout.layoutWidth | | |||
171 | } | 159 | } | ||
172 | } | 160 | } | ||
173 | | ||||
174 | Component.onCompleted: Qt.callLater(updateVisibleActions) | | |||
175 | onWidthChanged: Qt.callLater(updateVisibleActions) | | |||
176 | | ||||
177 | function updateVisibleActions() { | | |||
178 | var visible = [] | | |||
179 | var hidden = [] | | |||
180 | | ||||
181 | if (root.width >= placeholderLayout.width + moreButton.width + Kirigami.Units.smallSpacing) { | | |||
182 | visibleActions = Array.prototype.map.call(root.actions, function(item) { return item }) | | |||
183 | hiddenActions = [] | | |||
184 | return | | |||
185 | } | | |||
186 | | ||||
187 | for (var i = 0; i < root.actions.length; ++i) { | | |||
188 | var item = placeholderRepeater.itemAt(i) | | |||
189 | if (item.actionVisible) { | | |||
190 | visible.push(item.kirigamiAction) | | |||
191 | } else { | | |||
192 | hidden.push(item.kirigamiAction) | | |||
193 | | ||||
194 | } | | |||
195 | } | | |||
196 | | ||||
197 | visibleActions = visible | | |||
198 | hiddenActions = hidden | | |||
199 | } | | |||
200 | } | | |||
201 | | ||||
202 | onWidthChanged: Qt.callLater(placeholderLayout.updateVisibleActions) | | |||
203 | } | |
Shouldn't this be
i.e. have the action show if visible is not defined