8import QtQuick.Controls as QQC2
10import QtQuick.Templates as T
11import org.kde.kirigami as Kirigami
57 property alias supportsMouseEvents: listItem.hoverEnabled
68 readonly
property alias containsMouse: listItem.hovered
80 property bool alternatingBackground:
false
91 property bool sectionDelegate:
false
100 property bool separatorVisible:
false
108 property color backgroundColor: Kirigami.Theme.backgroundColor
119 property color alternateBackgroundColor: Kirigami.Theme.alternateBackgroundColor
128 property color activeBackgroundColor: Kirigami.Theme.highlightColor
139 property color textColor: Kirigami.Theme.textColor
150 property color activeTextColor: Kirigami.Theme.highlightedTextColor
161 readonly
property bool actionsVisible: actionsLayout.hasVisibleActions
170 property bool alwaysVisibleActions: !Kirigami.Settings.isMobile
178 property list<T.Action> actions
188 readonly
property alias overlayWidth: overlayLoader.width
192 LayoutMirroring.childrenInherit:
true
195 implicitWidth: contentItem ? implicitContentWidth : Kirigami.Units.gridUnit * 12
196 width: parent ? parent.width : implicitWidth
197 implicitHeight: Math.max(Kirigami.Units.gridUnit * 2, implicitContentHeight) + topPadding + bottomPadding
199 padding: !listItem.alwaysVisibleActions && Kirigami.Settings.tabletMode ? Kirigami.Units.largeSpacing : Kirigami.Units.smallSpacing
201 leftPadding: padding * 2 + (mirrored ? overlayLoader.paddingOffset : 0)
202 rightPadding: padding * 2 + (mirrored ? 0 : overlayLoader.paddingOffset)
205 bottomPadding: padding
211 property Flickable view: listItem.ListView.view || (listItem.parent ? (listItem.parent.ListView.view || (listItem.parent instanceof Flickable ? listItem.parent : null)) : null)
213 function viewHasPropertySwipeFilter(): bool {
214 return view && view.parent && view.parent.parent &&
"_swipeFilter" in view.parent.parent;
217 readonly
property QtObject swipeFilterItem: (viewHasPropertySwipeFilter() && view.parent.parent._swipeFilter) ? view.parent.parent._swipeFilter : null
219 readonly property bool edgeEnabled: swipeFilterItem ? swipeFilterItem.currentItem === listItem || swipeFilterItem.currentItem === listItem.parent : false
223 if (listItem.alwaysVisibleActions || !Kirigami.Settings.tabletMode) {
226 if (viewHasPropertySwipeFilter() && Kirigami.Settings.tabletMode && !internal.view.parent.parent._swipeFilter) {
227 const component =
Qt.createComponent(
Qt.resolvedUrl(
"../private/SwipeItemEventFilter.qml"));
228 internal.view.parent.parent._swipeFilter = component.createObject(internal.view.parent.parent);
235 target: Kirigami.Settings
236 function onTabletModeChanged() {
237 if (!internal.viewHasPropertySwipeFilter()) {
240 if (Kirigami.Settings.tabletMode) {
241 if (!internal.swipeFilterItem) {
242 const component =
Qt.createComponent(
Qt.resolvedUrl(
"../private/SwipeItemEventFilter.qml"));
243 listItem.ListView.view.parent.parent._swipeFilter = component.createObject(listItem.ListView.view.parent.parent);
247 if (listItem.ListView.view.parent.parent._swipeFilter) {
248 listItem.ListView.view.parent.parent._swipeFilter.destroy();
259 readonly
property int paddingOffset: (visible ? width : 0) + Kirigami.Units.smallSpacing
260 readonly property var theAlias: anchors
261 function validate(want, defaultValue) {
262 const expectedLeftPadding = () => listItem.padding * 2 + (listItem.mirrored ? overlayLoader.paddingOffset : 0)
263 const expectedRightPadding = () => listItem.padding * 2 + (listItem.mirrored ? 0 : overlayLoader.paddingOffset)
266 `Don
't override the leftPadding or rightPadding on a SwipeListItem!\n` +
267 `This makes it impossible for me to adjust my layout as I need to for various usecases.\n` +
268 `I'll
try to fix the mistake
for you, but you should
remove your overrides from your app
's code entirely.\n` +
269 `If I can't fix the paddings, I
'll fall back to a default layout, but it'll be slightly incorrect and lacks\n` +
270 `adaptations needed
for touch screens and
right-to-
left languages, among other things.`
272 if (listItem.leftPadding != expectedLeftPadding() || listItem.rightPadding != expectedRightPadding()) {
273 listItem.leftPadding =
Qt.binding(expectedLeftPadding)
274 listItem.rightPadding =
Qt.binding(expectedRightPadding)
275 console.warn(warningText)
282 right: validate(listItem.mirrored ? undefined : (contentItem ? contentItem.right : undefined), contentItem ? contentItem.right : undefined)
283 rightMargin: validate(-paddingOffset, 0)
284 left: validate(!listItem.mirrored ? undefined : (contentItem ? contentItem.left : undefined), undefined)
285 leftMargin: validate(-paddingOffset, 0)
287 bottom: parent.bottom
289 LayoutMirroring.enabled: false
292 z: contentItem ? contentItem.z + 1 : 0
293 width: item ? item.implicitWidth : actionsLayout.implicitWidth
294 active: !listItem.alwaysVisibleActions && Kirigami.Settings.tabletMode
295 visible: listItem.actionsVisible && opacity > 0
297 sourceComponent: handleComponent
298 opacity: listItem.alwaysVisibleActions || Kirigami.Settings.tabletMode || listItem.hovered ? 1 : 0
299 Behavior on opacity {
302 duration: Kirigami.Units.veryShortDuration
303 easing.type: Easing.InOutQuad
316 implicitWidth: Kirigami.Units.iconSizes.smallMedium
318 preventStealing:
true
319 readonly
property real openPosition: (listItem.width - width - listItem.leftPadding * 2)/listItem.width
320 property real startX: 0
321 property real lastPosition: 0
322 property bool openIntention
324 onPressed: mouse => {
325 startX = mapToItem(listItem, 0, 0).x;
327 onClicked: mouse => {
328 if (Math.abs(mapToItem(listItem, 0, 0).x - startX) >
Qt.styleHints.startDragDistance) {
331 if (listItem.mirrored) {
332 if (listItem.swipe.position < 0.5) {
333 slideAnim.to = openPosition
338 if (listItem.swipe.position > -0.5) {
339 slideAnim.to = -openPosition
346 onPositionChanged: mouse => {
347 const pos = mapToItem(listItem, mouse.x, mouse.y);
349 if (listItem.mirrored) {
350 listItem.swipe.position = Math.max(0, Math.min(openPosition, (pos.x / listItem.width)));
351 openIntention = listItem.swipe.position > lastPosition;
353 listItem.swipe.position = Math.min(0, Math.max(-openPosition, (pos.x / (listItem.width -listItem.rightPadding) - 1)));
354 openIntention = listItem.swipe.position < lastPosition;
356 lastPosition = listItem.swipe.position;
358 onReleased: mouse => {
359 if (listItem.mirrored) {
361 slideAnim.to = openPosition
367 slideAnim.to = -openPosition
378 selected: listItem.checked || (listItem.down && !listItem.checked && !listItem.sectionDelegate)
379 source: (listItem.mirrored ? (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"))
383 id: swipeFilterConnection
385 target: internal.edgeEnabled ? internal.swipeFilterItem : null
386 function onPeekChanged() {
387 if (!listItem.actionsVisible) {
391 if (listItem.mirrored) {
392 listItem.swipe.position = Math.max(0, Math.min(dragButton.openPosition, internal.swipeFilterItem.peek));
393 dragButton.openIntention = listItem.swipe.position > dragButton.lastPosition;
396 listItem.swipe.position = Math.min(0, Math.max(-dragButton.openPosition, -internal.swipeFilterItem.peek));
397 dragButton.openIntention = listItem.swipe.position < dragButton.lastPosition;
400 dragButton.lastPosition = listItem.swipe.position;
402 function onPressed(mouse) {
403 if (internal.edgeEnabled) {
404 dragButton.pressed(mouse);
407 function onClicked(mouse) {
408 if (Math.abs(listItem.background.x) < Kirigami.Units.gridUnit && internal.edgeEnabled) {
409 dragButton.clicked(mouse);
412 function onReleased(mouse) {
413 if (internal.edgeEnabled) {
414 dragButton.released(mouse);
417 function onCurrentItemChanged() {
418 if (!internal.edgeEnabled) {
429 id: actionsBackgroundDelegate
435 onClicked: mouse => {
441 color: parent.pressed ?
Qt.darker(Kirigami.Theme.backgroundColor, 1.1) :
Qt.darker(Kirigami.Theme.backgroundColor, 1.05)
444 visible: listItem.swipe.position != 0
449 visible: background.x != 0
457 edge: listItem.mirrored ?
Qt.RightEdge :
Qt.LeftEdge
458 x: listItem.mirrored ? listItem.background.x - width : (listItem.background.x + listItem.background.width)
459 visible: background.x != 0
462 bottom: parent.bottom
472 LayoutMirroring.enabled: listItem.mirrored
476 bottom: parent.bottom
477 rightMargin: Kirigami.
Units.smallSpacing
479 visible: parent !== listItem
480 parent: !listItem.alwaysVisibleActions && Kirigami.Settings.tabletMode
481 ? listItem.swipe.leftItem || listItem.swipe.rightItem || listItem
484 property bool hasVisibleActions: false
486 function updateVisibleActions(definitelyVisible: bool) {
487 hasVisibleActions = definitelyVisible || listItem.actions.some(isActionVisible);
490 function isActionVisible(action: T.Action): bool {
491 return (action instanceof Kirigami.
Action) ? action.visible : true;
495 model: listItem.actions
497 delegate: QQC2.ToolButton {
498 required
property T.Action modelData
501 display: T.AbstractButton.IconOnly
502 visible: actionsLayout.isActionVisible(action)
504 onVisibleChanged: actionsLayout.updateVisibleActions(visible);
505 Component.onCompleted: actionsLayout.updateVisibleActions(visible);
506 Component.onDestruction: actionsLayout.updateVisibleActions(visible);
508 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
509 QQC2.ToolTip.visible: (Kirigami.Settings.tabletMode ? pressed : hovered) && QQC2.ToolTip.text.length > 0
510 QQC2.ToolTip.text: (action as Kirigami.
Action)?.tooltip ?? action?.text ??
""
517 Accessible.name: text
518 Accessible.description: (action as Kirigami.Action)?.tooltip ??
""
525 right: listItem.alwaysVisibleActions || listItem.mirrored || !Kirigami.Settings.tabletMode ? null : actionsBackgroundDelegate
526 left: listItem.alwaysVisibleActions || listItem.mirrored && Kirigami.Settings.tabletMode ? actionsBackgroundDelegate : null
530 duration: Kirigami.Units.longDuration
531 easing.type: Easing.InOutQuad
532 target: listItem.swipe
534 from: listItem.swipe.position
An item that represents an abstract Action.
KEDUVOCDOCUMENT_EXPORT QStringList languages()
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)