Changeset View
Changeset View
Standalone View
Standalone View
src/controls/templates/SwipeListItem.qml
Show First 20 Lines • Show All 254 Lines • ▼ Show 20 Line(s) | 252 | anchors { | |||
---|---|---|---|---|---|
255 | rightMargin: LayoutMirroring.enabled ? 0 : behindItem.calculateMargin() | 255 | rightMargin: LayoutMirroring.enabled ? 0 : behindItem.calculateMargin() | ||
256 | leftMargin: LayoutMirroring.enabled ? 0 : behindItem.calculateMargin() | 256 | leftMargin: LayoutMirroring.enabled ? 0 : behindItem.calculateMargin() | ||
257 | } | 257 | } | ||
258 | height: Math.min( parent.height / 1.5, Units.iconSizes.smallMedium) | 258 | height: Math.min( parent.height / 1.5, Units.iconSizes.smallMedium) | ||
259 | width: childrenRect.width | 259 | width: childrenRect.width | ||
260 | property bool exclusive: false | 260 | property bool exclusive: false | ||
261 | property Item checkedButton | 261 | property Item checkedButton | ||
262 | spacing: Settings.tabletMode ? Units.largeSpacing : 0 | 262 | spacing: Settings.tabletMode ? Units.largeSpacing : 0 | ||
263 | property int visibleActions: 0 | 263 | property bool hasVisibleActions: false | ||
264 | function updateVisibleActions(definitelyVisible = false) { | ||||
265 | if (definitelyVisible) { | ||||
266 | hasVisibleActions = true; | ||||
267 | } else { | ||||
268 | var actionCount = listItem.actions.length; | ||||
269 | for (var i = 0; i < actionCount; i++) { | ||||
270 | // Assuming that visible is only false if it is explicitly false, and not just falsy | ||||
271 | if (listItem.actions[i].visible === false) { | ||||
272 | continue; | ||||
273 | } | ||||
274 | hasVisibleActions = true; | ||||
275 | break; | ||||
276 | } | ||||
277 | } | ||||
278 | } | ||||
264 | Repeater { | 279 | Repeater { | ||
265 | model: { | 280 | model: { | ||
266 | if (listItem.actions.length === 0) { | 281 | if (listItem.actions.length === 0) { | ||
267 | return null; | 282 | return null; | ||
268 | } else { | 283 | } else { | ||
269 | return listItem.actions[0].text !== undefined && | 284 | return listItem.actions[0].text !== undefined && | ||
270 | listItem.actions[0].trigger !== undefined ? | 285 | listItem.actions[0].trigger !== undefined ? | ||
271 | listItem.actions : | 286 | listItem.actions : | ||
272 | listItem.actions[0]; | 287 | listItem.actions[0]; | ||
273 | } | 288 | } | ||
274 | } | 289 | } | ||
275 | delegate: Controls.ToolButton { | 290 | delegate: Controls.ToolButton { | ||
276 | anchors.verticalCenter: parent.verticalCenter | 291 | anchors.verticalCenter: parent.verticalCenter | ||
277 | icon.name: modelData.iconName !== "" ? modelData.iconName : "" | 292 | icon.name: modelData.iconName !== "" ? modelData.iconName : "" | ||
278 | icon.source: modelData.iconSource !== "" ? modelData.iconSource : "" | 293 | icon.source: modelData.iconSource !== "" ? modelData.iconSource : "" | ||
279 | enabled: (modelData && modelData.enabled !== undefined) ? modelData.enabled : true; | 294 | enabled: (modelData && modelData.enabled !== undefined) ? modelData.enabled : true; | ||
280 | visible: (modelData && modelData.visible !== undefined) ? modelData.visible : true; | 295 | visible: (modelData && modelData.visible !== undefined) ? modelData.visible : true; | ||
281 | onVisibleChanged: { | 296 | onVisibleChanged: actionsLayout.updateVisibleActions(visible); | ||
282 | if (visible) { | 297 | Component.onCompleted: actionsLayout.updateVisibleActions(visible); | ||
283 | actionsLayout.visibleActions++; | 298 | Component.onDestruction: actionsLayout.updateVisibleActions(visible); | ||
284 | } else { | | |||
285 | actionsLayout.visibleActions--; | | |||
286 | } | | |||
287 | } | | |||
288 | Component.onCompleted: { | | |||
289 | if (visible) { | | |||
290 | actionsLayout.visibleActions++; | | |||
291 | } | | |||
292 | } | | |||
293 | Component.onDestruction: { | | |||
294 | if (visible) { | | |||
295 | actionsLayout.visibleActions--; | | |||
296 | } | | |||
297 | } | | |||
298 | Controls.ToolTip.delay: Units.toolTipDelay | 299 | Controls.ToolTip.delay: Units.toolTipDelay | ||
299 | Controls.ToolTip.timeout: 5000 | 300 | Controls.ToolTip.timeout: 5000 | ||
300 | Controls.ToolTip.visible: listItem.visible && (Settings.tabletMode ? pressed : hovered) && Controls.ToolTip.text.length > 0 | 301 | Controls.ToolTip.visible: listItem.visible && (Settings.tabletMode ? pressed : hovered) && Controls.ToolTip.text.length > 0 | ||
301 | Controls.ToolTip.text: modelData.tooltip || modelData.text | 302 | Controls.ToolTip.text: modelData.tooltip || modelData.text | ||
302 | 303 | | |||
303 | onClicked: { | 304 | onClicked: { | ||
304 | if (modelData && modelData.trigger !== undefined) { | 305 | if (modelData && modelData.trigger !== undefined) { | ||
305 | modelData.trigger(); | 306 | modelData.trigger(); | ||
306 | } | 307 | } | ||
307 | positionAnimation.from = background.x; | 308 | positionAnimation.from = background.x; | ||
308 | positionAnimation.to = 0; | 309 | positionAnimation.to = 0; | ||
309 | positionAnimation.running = true; | 310 | positionAnimation.running = true; | ||
310 | } | 311 | } | ||
311 | } | 312 | } | ||
312 | } | 313 | } | ||
313 | } | 314 | } | ||
314 | } | 315 | } | ||
315 | 316 | | |||
316 | MouseArea { | 317 | MouseArea { | ||
317 | id: handleMouse | 318 | id: handleMouse | ||
318 | parent: listItem.background | 319 | parent: listItem.background | ||
319 | visible: Settings.tabletMode && listItem.actionsVisible && actionsLayout.visibleActions > 0 | 320 | visible: Settings.tabletMode && listItem.actionsVisible && actionsLayout.hasVisibleActions | ||
320 | z: 99 | 321 | z: 99 | ||
321 | anchors { | 322 | anchors { | ||
322 | right: parent.right | 323 | right: parent.right | ||
323 | verticalCenter: parent.verticalCenter | 324 | verticalCenter: parent.verticalCenter | ||
324 | rightMargin: LayoutMirroring.enabled ? 0 : behindItem.calculateMargin() | 325 | rightMargin: LayoutMirroring.enabled ? 0 : behindItem.calculateMargin() | ||
325 | leftMargin: LayoutMirroring.enabled ? 0 : behindItem.calculateMargin() | 326 | leftMargin: LayoutMirroring.enabled ? 0 : behindItem.calculateMargin() | ||
326 | } | 327 | } | ||
327 | 328 | | |||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |