MauiKit Controls

SwipeItemDelegate.qml
1/*
2 * Copyright 2018 Camilo Higuita <milo.h@aol.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20import QtQuick
21import QtQuick.Layouts
22import QtQuick.Controls
23
24import org.mauikit.controls 1.3 as Maui
25
26/**
27 * @inherit ItemDelegate
28 * A template base for presenting an upper and under layer of content.
29 *
30 * This control inherits from MauiKit ItemDelegate, to checkout its inherited properties refer to the docs.
31
32 * This control is divided into two sections.
33 * First, is the content, which are the elements declared ans the children of this. Those elements are always placed in the surface.
34 * @see content
35 * Second is a set of QQC2 Action that go to the far right side - either in the superior or inferior surface.
36 * That behavior will depend on the `collapse` property value - where `collapse : true` means it will be displayed under the surface.
37
38 @note When the quick actions are displayed above in the surface, they will only be discovered upon hovering, otherwise they will stay hidden.
39
40 You can review the SwipeBrowserDelegate which serves as an example of how to use this control.
41 @see SwipeBrowserDelegate
42 *
43 */
44Maui.ItemDelegate
45{
46 id: control
47
48 padding: Maui.Style.defaultPadding
49 spacing: Maui.Style.space.small
50
51 /**
52 * @brief The implicit height of the underneath area containing the action button.
53 */
54 readonly property int buttonsHeight: Math.max(_background.implicitHeight, _swipeDelegate.implicitHeight)
55
56 isCurrentItem : ListView.isCurrentItem
57
58 /**
59 * @brief The default content children has to be positioned manually, making use of anchors, etc.
60 * @property list<QtObject> SwipeItemDelegate::content
61 */
62 default property alias content : _content.data
63
64 /**
65 * @brief Exposed to quickly append more items to the right side of this control in the far right area.
66 *.
67 * @property list<QtObject> SwipeItemDelegate::actionRow
68 */
69 property alias actionRow : _background.data
70
71 /**
72 * @brief Whether the quick actions declared as `quickActions` should be visible or not.
73 * By default this is set to `true`
74 */
75 property bool showQuickActions : true
76
77 /**
78 * @brief The actions that goes underneath the control and is revealed by swiping to the left when the `collapse` property is set to `true`, otherwise the actions will be shown in the far right side above.
79 */
80 property list<Action> quickActions
81
82 /**
83 * @brief Whether the actions will go underneath the control or above.
84 * By default this depends on the available space, so it can fit the information labels and the `quickAction` buttons.
85 */
86 property bool collapse : width < Maui.Style.units.gridUnit * 26 || Maui.Handy.isMobile
87
88 onCollapseChanged:
89 {
90 if(_swipeDelegate.swipe.position < 0)
91 _swipeDelegate.swipe.close()
92 }
93
94 background: Rectangle
95 {
96 color: Qt.tint(control.Maui.Theme.textColor, Qt.rgba(control.Maui.Theme.backgroundColor.r, control.Maui.Theme.backgroundColor.g, control.Maui.Theme.backgroundColor.b, 0.95))
97 radius: Maui.Style.radiusV
98 }
99
100 SwipeDelegate
101 {
102 id: _swipeDelegate
103 anchors.fill: parent
104 hoverEnabled: true
105 clip: true
106
107 onClicked: control.clicked(null)
108 onPressed: control.pressed(null)
109 onDoubleClicked: control.doubleClicked(null)
110 onPressAndHold: control.pressAndHold(null)
111
112 swipe.enabled: control.collapse && control.showQuickActions
113 padding: 0
114
115 background: null
116 contentItem: RowLayout
117 {
118 spacing: control.spacing
119 id: _background
120
121 Item
122 {
123 id: _content
124 Layout.fillWidth: true
125 Layout.fillHeight: true
126 }
127
128 Loader
129 {
130 active: control.showQuickActions && !control.collapse
131 visible: active && control.hovered
132 asynchronous: true
133
134 sourceComponent: Row
135 {
136 spacing: control.spacing
137 Layout.alignment: Qt.AlignRight
138
139 Repeater
140 {
141 model: control.quickActions
142
143 ToolButton
144 {
145 action: modelData
146 }
147 }
148 }
149 }
150
151 ToolButton
152 {
153 visible: control.collapse && control.quickActions.length > 0 && control.showQuickActions
154 icon.name: _swipeDelegate.swipe.complete ? "go-next" : "go-previous"
155 onClicked: _swipeDelegate.swipe.complete ? _swipeDelegate.swipe.close() : _swipeDelegate.swipe.open(SwipeDelegate.Right)
156 }
157 }
158
159 swipe.right: Row
160 {
161 id: _rowActions
162 anchors.right: parent.right
163 anchors.verticalCenter: parent.verticalCenter
164 spacing: control.spacing
165 padding: Maui.Style.space.medium
166 // width: implicitWidth * Math.abs(_swipeDelegate.swipe.position)
167
168 opacity: Math.abs(_swipeDelegate.swipe.position) > 0.5 ? 1 : 0
169
170 Repeater
171 {
172 model: control.quickActions
173
174 ToolButton
175 {
176 action: modelData
177 onClicked: _swipeDelegate.swipe.close()
178 }
179 }
180 }
181 }
182}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.