8 import QtQuick.Layouts 1.4
9 import QtQuick.Controls 2.4 as QQC2
10 import QtQuick.Templates 2.4 as T
11 import org.kde.kirigami 2.11 as Kirigami
58 property alias supportsMouseEvents: listItem.hoverEnabled
69 property alias containsMouse: listItem.hovered
81 property bool alternatingBackground:
false
92 property bool sectionDelegate:
false
101 property bool separatorVisible:
false
109 property color backgroundColor: Kirigami.Theme.backgroundColor
120 property color alternateBackgroundColor: Kirigami.Theme.alternateBackgroundColor
129 property color activeBackgroundColor: Kirigami.Theme.highlightColor
140 property color textColor: Kirigami.Theme.textColor
151 property color activeTextColor: Kirigami.Theme.highlightedTextColor
162 readonly
property bool actionsVisible: actionsLayout.hasVisibleActions
171 property bool alwaysVisibleActions: !Kirigami.Settings.isMobile
179 property list<QQC2.Action> actions
189 readonly
property alias overlayWidth: overlayLoader.width
194 default property alias _default: listItem.contentItem
197 LayoutMirroring.childrenInherit:
true
200 implicitWidth: contentItem ? contentItem.implicitWidth : Kirigami.Units.gridUnit * 12
201 width: parent ? parent.width : implicitWidth
202 implicitHeight: Math.max(Kirigami.Units.gridUnit * 2, contentItem.implicitHeight) + topPadding + bottomPadding
204 padding: !listItem.alwaysVisibleActions && Kirigami.Settings.tabletMode ? Kirigami.Units.largeSpacing : Kirigami.Units.smallSpacing
206 leftPadding: padding * 2 + (mirrored ? overlayLoader.paddingOffset : 0)
207 rightPadding: padding * 2 + (mirrored ? 0 : overlayLoader.paddingOffset)
210 bottomPadding: padding
216 property Flickable view: listItem.ListView.view || (listItem.parent ? (listItem.parent.ListView.view || (listItem.parent instanceof Flickable ? listItem.parent :
null)) :
null)
218 readonly property QtObject swipeFilterItem: (view && view.parent && view.parent.parent && view.parent.parent._swipeFilter) ? view.parent.parent._swipeFilter :
null
220 readonly
property bool edgeEnabled: swipeFilterItem ? swipeFilterItem.currentItem === listItem || swipeFilterItem.currentItem === listItem.parent :
false
224 if (listItem.alwaysVisibleActions || !Kirigami.Settings.tabletMode) {
227 if (
internal.view && Kirigami.Settings.tabletMode && !
internal.view.parent.parent._swipeFilter) {
228 const component =
Qt.createComponent(
Qt.resolvedUrl(
"../private/SwipeItemEventFilter.qml"));
229 internal.view.parent.parent._swipeFilter = component.createObject(
internal.view.parent.parent);
236 target: Kirigami.Settings
237 function onTabletModeChanged() {
238 if (Kirigami.Settings.tabletMode) {
239 if (!
internal.swipeFilterItem) {
240 const component =
Qt.createComponent(
Qt.resolvedUrl(
"../private/SwipeItemEventFilter.qml"));
241 listItem.ListView.view.parent.parent._swipeFilter = component.createObject(listItem.ListView.view.parent.parent);
245 if (listItem.ListView.view.parent.parent._swipeFilter) {
246 listItem.ListView.view.parent.parent._swipeFilter.destroy();
257 readonly
property int paddingOffset: (visible ? width : 0) + Kirigami.Units.smallSpacing
258 readonly property var theAlias: anchors
259 function validate(want, defaultValue) {
260 const expectedLeftPadding = () => listItem.padding * 2 + (listItem.mirrored ? overlayLoader.paddingOffset : 0)
261 const expectedRightPadding = () => listItem.padding * 2 + (listItem.mirrored ? 0 : overlayLoader.paddingOffset)
264 `Don
't override the leftPadding or rightPadding on a SwipeListItem!\n` +
265 `This makes it impossible for me to adjust my layout as I need to for various usecases.\n` +
266 `I'll
try to fix the mistake
for you, but you should
remove your overrides from your app
's code entirely.\n` +
267 `If I can't fix the paddings, I
'll fall back to a default layout, but it'll be slightly incorrect and lacks\n` +
268 `adaptations needed
for touch screens and
right-to-
left languages, among other things.`
270 if (listItem.leftPadding != expectedLeftPadding() || listItem.rightPadding != expectedRightPadding()) {
271 listItem.leftPadding =
Qt.binding(expectedLeftPadding)
272 listItem.rightPadding =
Qt.binding(expectedRightPadding)
273 console.warn(warningText)
280 right: validate((
Qt.application.layoutDirection ===
Qt.RightToLeft) ? undefined : (contentItem ? contentItem.right : undefined), contentItem ? contentItem.right : undefined)
281 rightMargin: validate(-paddingOffset, 0)
282 left: validate((
Qt.application.layoutDirection ===
Qt.LeftToRight) ? undefined : (contentItem ? contentItem.left : undefined), undefined)
283 leftMargin: validate(-paddingOffset, 0)
285 bottom: parent.bottom
287 LayoutMirroring.enabled: false
290 z: contentItem ? contentItem.z + 1 : 0
291 width: item ? item.implicitWidth : actionsLayout.implicitWidth
292 active: !listItem.alwaysVisibleActions && Kirigami.
Settings.tabletMode
293 visible: listItem.actionsVisible && opacity > 0
295 sourceComponent: handleComponent
296 opacity: listItem.alwaysVisibleActions || Kirigami.
Settings.tabletMode || listItem.hovered ? 1 : 0
297 Behavior on opacity {
300 duration: Kirigami.Units.veryShortDuration
301 easing.type: Easing.InOutQuad
314 implicitWidth: Kirigami.Units.iconSizes.smallMedium
316 preventStealing:
true
317 readonly
property real openPosition: (listItem.width - width - listItem.leftPadding * 2)/listItem.width
318 property real startX: 0
319 property real lastPosition: 0
320 property
bool openIntention
322 onPressed: mouse => {
323 startX = mapToItem(listItem, 0, 0).x;
325 onClicked: mouse => {
326 if (Math.abs(mapToItem(listItem, 0, 0).x - startX) >
Qt.styleHints.startDragDistance) {
329 if (listItem.LayoutMirroring.enabled) {
330 if (listItem.swipe.position < 0.5) {
331 slideAnim.to = openPosition
336 if (listItem.swipe.position > -0.5) {
337 slideAnim.to = -openPosition
344 onPositionChanged: mouse => {
345 const pos = mapToItem(listItem, mouse.x, mouse.y);
347 if (listItem.LayoutMirroring.enabled) {
348 listItem.swipe.position = Math.max(0, Math.min(openPosition, (pos.x / listItem.width)));
349 openIntention = listItem.swipe.position > lastPosition;
351 listItem.swipe.position = Math.min(0, Math.max(-openPosition, (pos.x / (listItem.width -listItem.rightPadding) - 1)));
352 openIntention = listItem.swipe.position < lastPosition;
354 lastPosition = listItem.swipe.position;
356 onReleased: mouse => {
357 if (listItem.LayoutMirroring.enabled) {
359 slideAnim.to = openPosition
365 slideAnim.to = -openPosition
376 selected: listItem.checked || (listItem.pressed && !listItem.checked && !listItem.sectionDelegate)
377 source: (LayoutMirroring.enabled ? (listItem.background.x < listItem.background.width/2 ?
"overflow-menu-right" :
"overflow-menu-left") : (listItem.background.x < -listItem.background.width/2 ?
"overflow-menu-right" :
"overflow-menu-left"))
381 id: swipeFilterConnection
383 target:
internal.edgeEnabled ?
internal.swipeFilterItem :
null
384 function onPeekChanged() {
385 if (!listItem.actionsVisible) {
389 if (listItem.LayoutMirroring.enabled) {
390 listItem.swipe.position = Math.max(0, Math.min(dragButton.openPosition,
internal.swipeFilterItem.peek));
391 dragButton.openIntention = listItem.swipe.position > dragButton.lastPosition;
394 listItem.swipe.position = Math.min(0, Math.max(-dragButton.openPosition, -
internal.swipeFilterItem.peek));
395 dragButton.openIntention = listItem.swipe.position < dragButton.lastPosition;
398 dragButton.lastPosition = listItem.swipe.position;
400 function onPressed(mouse) {
401 if (
internal.edgeEnabled) {
402 dragButton.onPressed(mouse);
405 function onClicked(mouse) {
406 if (Math.abs(listItem.background.x) < Kirigami.Units.gridUnit &&
internal.edgeEnabled) {
407 dragButton.clicked(mouse);
410 function onReleased(mouse) {
411 if (
internal.edgeEnabled) {
412 dragButton.released(mouse);
415 function onCurrentItemChanged() {
416 if (!
internal.edgeEnabled) {
427 id: actionsBackgroundDelegate
433 onClicked: mouse => {
439 color: parent.pressed ?
Qt.darker(Kirigami.Theme.backgroundColor, 1.1) :
Qt.darker(Kirigami.Theme.backgroundColor, 1.05)
442 visible: listItem.swipe.position != 0
447 visible: background.x != 0
455 edge: LayoutMirroring.enabled ?
Qt.RightEdge :
Qt.LeftEdge
456 x: LayoutMirroring.enabled ? listItem.background.x - width : (listItem.background.x + listItem.background.width)
457 visible: background.x != 0
460 bottom: parent.bottom
472 bottom: parent.bottom
473 rightMargin: Kirigami.Units.smallSpacing
475 visible: parent !== listItem
476 parent: !listItem.alwaysVisibleActions && Kirigami.Settings.tabletMode
477 ? listItem.swipe.leftItem || listItem.swipe.rightItem || listItem
480 property bool hasVisibleActions:
false
481 function updateVisibleActions(definitelyVisible) {
482 if (definitelyVisible === undefined) {
483 definitelyVisible =
false
486 if (definitelyVisible) {
487 hasVisibleActions =
true;
489 const actionCount = listItem.actions.length;
490 for (let i = 0; i < actionCount; i++) {
492 if (listItem.actions[i].visible ===
false) {
495 hasVisibleActions =
true;
503 if (listItem.actions.length === 0) {
506 return listItem.actions[0].text !== undefined &&
507 listItem.actions[0].trigger !== undefined ?
512 delegate: QQC2.ToolButton {
513 icon.name: modelData.iconName !==
"" ? modelData.iconName :
""
514 icon.source: modelData.iconSource !==
"" ? modelData.iconSource :
""
515 enabled: (modelData && modelData.enabled !== undefined) ? modelData.enabled :
true;
516 visible: (modelData && modelData.visible !== undefined) ? modelData.visible :
true;
517 onVisibleChanged: actionsLayout.updateVisibleActions(visible);
518 Component.onCompleted: actionsLayout.updateVisibleActions(visible);
519 Component.onDestruction: actionsLayout.updateVisibleActions(visible);
520 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
521 QQC2.ToolTip.timeout: 5000
522 QQC2.ToolTip.visible: listItem.visible && (Kirigami.Settings.tabletMode ? pressed : hovered) && QQC2.ToolTip.text.length > 0
523 QQC2.ToolTip.text: modelData.tooltip || modelData.text
526 if (modelData && modelData.trigger !== undefined) {
533 Accessible.name: modelData.text
534 Accessible.description: modelData.tooltip
540 background: DefaultListItemBackground {}
544 right: listItem.alwaysVisibleActions || listItem.LayoutMirroring.enabled || !Kirigami.Settings.tabletMode ? null : actionsBackgroundDelegate
545 left: listItem.alwaysVisibleActions || listItem.LayoutMirroring.enabled && Kirigami.Settings.tabletMode ? actionsBackgroundDelegate :
null
549 duration: Kirigami.Units.longDuration
550 easing.type: Easing.InOutQuad
551 target: listItem.swipe
553 from: listItem.swipe.position