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
210 property Flickable view: listItem.ListView.view || (listItem.parent ? (listItem.parent.ListView.view || (listItem.parent instanceof Flickable ? listItem.parent : null)) : null)
212 function viewHasPropertySwipeFilter(): bool {
213 return view && view.parent && view.parent.parent &&
"_swipeFilter" in view.parent.parent;
216 readonly
property QtObject swipeFilterItem: (viewHasPropertySwipeFilter() && view.parent.parent._swipeFilter) ? view.parent.parent._swipeFilter : null
218 readonly property bool edgeEnabled: swipeFilterItem ? swipeFilterItem.currentItem === listItem || swipeFilterItem.currentItem === listItem.parent : false
222 if (listItem.alwaysVisibleActions || !Kirigami.Settings.tabletMode) {
225 if (viewHasPropertySwipeFilter() && Kirigami.Settings.tabletMode && !internal.view.parent.parent._swipeFilter) {
226 const component =
Qt.createComponent(
Qt.resolvedUrl(
"../private/SwipeItemEventFilter.qml"));
227 internal.view.parent.parent._swipeFilter = component.createObject(internal.view.parent.parent);
234 target: Kirigami.Settings
235 function onTabletModeChanged() {
236 if (!internal.viewHasPropertySwipeFilter()) {
239 if (Kirigami.Settings.tabletMode) {
240 if (!internal.swipeFilterItem) {
241 const component =
Qt.createComponent(
Qt.resolvedUrl(
"../private/SwipeItemEventFilter.qml"));
242 listItem.ListView.view.parent.parent._swipeFilter = component.createObject(listItem.ListView.view.parent.parent);
246 if (listItem.ListView.view.parent.parent._swipeFilter) {
247 listItem.ListView.view.parent.parent._swipeFilter.destroy();
258 readonly
property int paddingOffset: (visible ? width : 0) + Kirigami.Units.smallSpacing
259 readonly property var theAlias: anchors
260 function validate(want, defaultValue) {
261 const expectedLeftPadding = () => listItem.padding * 2 + (listItem.mirrored ? overlayLoader.paddingOffset : 0)
262 const expectedRightPadding = () => listItem.padding * 2 + (listItem.mirrored ? 0 : overlayLoader.paddingOffset)
265 `Don
't override the leftPadding or rightPadding on a SwipeListItem!\n` +
266 `This makes it impossible for me to adjust my layout as I need to for various usecases.\n` +
267 `I'll
try to fix the mistake
for you, but you should
remove your overrides from your app
's code entirely.\n` +
268 `If I can't fix the paddings, I
'll fall back to a default layout, but it'll be slightly incorrect and lacks\n` +
269 `adaptations needed
for touch screens and
right-to-
left languages, among other things.`
271 if (listItem.leftPadding != expectedLeftPadding() || listItem.rightPadding != expectedRightPadding()) {
272 listItem.leftPadding =
Qt.binding(expectedLeftPadding)
273 listItem.rightPadding =
Qt.binding(expectedRightPadding)
274 console.warn(warningText)
281 right: validate(listItem.mirrored ? undefined : (contentItem ? contentItem.right : undefined), contentItem ? contentItem.right : undefined)
282 rightMargin: validate(-paddingOffset, 0)
283 left: validate(!listItem.mirrored ? undefined : (contentItem ? contentItem.left : undefined), undefined)
284 leftMargin: validate(-paddingOffset, 0)
286 bottom: parent.bottom
288 LayoutMirroring.enabled: false
291 z: contentItem ? contentItem.z + 1 : 0
292 width: item ? item.implicitWidth : actionsLayout.implicitWidth
293 active: !listItem.alwaysVisibleActions && Kirigami.Settings.tabletMode
294 visible: listItem.actionsVisible && opacity > 0
296 sourceComponent: handleComponent
297 opacity: listItem.alwaysVisibleActions || Kirigami.Settings.tabletMode || listItem.hovered ? 1 : 0
298 Behavior on opacity {
301 duration: Kirigami.Units.veryShortDuration
302 easing.type: Easing.InOutQuad
315 implicitWidth: Kirigami.Units.iconSizes.smallMedium
317 preventStealing:
true
318 readonly
property real openPosition: (listItem.width - width - listItem.leftPadding * 2)/listItem.width
319 property real startX: 0
320 property real lastPosition: 0
321 property bool openIntention
323 onPressed: mouse => {
324 startX = mapToItem(listItem, 0, 0).x;
326 onClicked: mouse => {
327 if (Math.abs(mapToItem(listItem, 0, 0).x - startX) >
Qt.styleHints.startDragDistance) {
330 if (listItem.mirrored) {
331 if (listItem.swipe.position < 0.5) {
332 slideAnim.to = openPosition
337 if (listItem.swipe.position > -0.5) {
338 slideAnim.to = -openPosition
345 onPositionChanged: mouse => {
346 const pos = mapToItem(listItem, mouse.x, mouse.y);
348 if (listItem.mirrored) {
349 listItem.swipe.position = Math.max(0, Math.min(openPosition, (pos.x / listItem.width)));
350 openIntention = listItem.swipe.position > lastPosition;
352 listItem.swipe.position = Math.min(0, Math.max(-openPosition, (pos.x / (listItem.width -listItem.rightPadding) - 1)));
353 openIntention = listItem.swipe.position < lastPosition;
355 lastPosition = listItem.swipe.position;
357 onReleased: mouse => {
358 if (listItem.mirrored) {
360 slideAnim.to = openPosition
366 slideAnim.to = -openPosition
377 selected: listItem.checked || (listItem.down && !listItem.checked && !listItem.sectionDelegate)
378 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"))
382 id: swipeFilterConnection
384 target: internal.edgeEnabled ? internal.swipeFilterItem : null
385 function onPeekChanged() {
386 if (!listItem.actionsVisible) {
390 if (listItem.mirrored) {
391 listItem.swipe.position = Math.max(0, Math.min(dragButton.openPosition, internal.swipeFilterItem.peek));
392 dragButton.openIntention = listItem.swipe.position > dragButton.lastPosition;
395 listItem.swipe.position = Math.min(0, Math.max(-dragButton.openPosition, -internal.swipeFilterItem.peek));
396 dragButton.openIntention = listItem.swipe.position < dragButton.lastPosition;
399 dragButton.lastPosition = listItem.swipe.position;
401 function onPressed(mouse) {
402 if (internal.edgeEnabled) {
403 dragButton.pressed(mouse);
406 function onClicked(mouse) {
407 if (Math.abs(listItem.background.x) < Kirigami.Units.gridUnit && internal.edgeEnabled) {
408 dragButton.clicked(mouse);
411 function onReleased(mouse) {
412 if (internal.edgeEnabled) {
413 dragButton.released(mouse);
416 function onCurrentItemChanged() {
417 if (!internal.edgeEnabled) {
428 id: actionsBackgroundDelegate
433 readonly
property Item contentItem: swipeBackground
438 bottom: parent.bottom
441 color: parent.pressed ?
Qt.darker(Kirigami.Theme.backgroundColor, 1.1) :
Qt.darker(Kirigami.Theme.backgroundColor, 1.05)
442 x: listItem.mirrored ? listItem.background.x - width : (listItem.background.x + listItem.background.width)
443 width: listItem.mirrored ? parent.width - (parent.width - x) : parent.width - x
446 onTapped: listItem.swipe.
close()
450 visible: background.x != 0
460 visible: background.x != 0
463 bottom: parent.bottom
468 visible: listItem.swipe.position != 0
476 LayoutMirroring.enabled: listItem.mirrored
480 bottom: parent.bottom
481 rightMargin: Kirigami.
Units.smallSpacing
483 visible: parent !== listItem
484 parent: !listItem.alwaysVisibleActions && Kirigami.Settings.tabletMode
485 ? listItem.swipe.leftItem?.contentItem || listItem.swipe.rightItem?.contentItem || listItem
488 property bool hasVisibleActions: false
490 function updateVisibleActions(definitelyVisible: bool) {
491 hasVisibleActions = definitelyVisible || listItem.actions.some(isActionVisible);
494 function isActionVisible(action: T.Action): bool {
495 return (action instanceof Kirigami.
Action) ? action.visible : true;
499 model: listItem.actions
501 delegate: QQC2.ToolButton {
502 required
property T.Action modelData
505 display: T.AbstractButton.IconOnly
506 visible: actionsLayout.isActionVisible(action)
508 onVisibleChanged: actionsLayout.updateVisibleActions(visible);
509 Component.onCompleted: actionsLayout.updateVisibleActions(visible);
510 Component.onDestruction: actionsLayout.updateVisibleActions(visible);
512 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
513 QQC2.ToolTip.visible: (Kirigami.Settings.tabletMode ? pressed : hovered) && QQC2.ToolTip.text.length > 0
514 QQC2.ToolTip.text: (action as Kirigami.
Action)?.tooltip ?? action?.text ??
""
521 Accessible.name: text
522 Accessible.description: (action as Kirigami.Action)?.tooltip ??
""
529 right: listItem.alwaysVisibleActions || listItem.mirrored || !Kirigami.Settings.tabletMode ? null : actionsBackgroundDelegate
530 left: listItem.alwaysVisibleActions || listItem.mirrored && Kirigami.Settings.tabletMode ? actionsBackgroundDelegate : null
534 duration: Kirigami.Units.longDuration
535 easing.type: Easing.InOutQuad
536 target: listItem.swipe
538 from: listItem.swipe.position
KEDUVOCDOCUMENT_EXPORT QStringList languages()
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)