• Skip to content
  • Skip to link menu
Brand

API Documentation

  1. KDE API Reference
  2. Kirigami
  • KDE Home
  • Contact Us

Quick Links

Skip menu "Kirigami"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List
  • Related Pages

Class Picker

About

QtQuick plugins to build user interfaces based on the KDE UX guidelines

Maintainer
Marco Martin
Supported platforms
Android, Linux
Community
IRC: #plasma on Freenode
Mailing list: plasma-devel
Use with CMake
find_package(KF5Kirigami)
target_link_libraries(yourapp KF5::Kirigami)
Clone
git clone git://anongit.kde.org/kirigami1.git
Browse source
Kirigami on cgit.kde.org

Kirigami

  • src
  • controls
  • templates
controls/templates/SwipeListItem.qml
1 /*
2  * Copyright 2010 Marco Martin <notmart@gmail.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 Library 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 2.010-1301, USA.
18  */
19 
20 import QtQuick 2.5
21 import QtQuick.Layouts 1.2
22 import QtQuick.Controls 1.0 as Controls
23 import QtQuick.Controls.Private 1.0
24 import org.kde.kirigami 1.0
25 import "../private"
26 
56 Item {
57  id: listItem
58 
59 //BEGIN properties
67  default property Item contentItem
68 
75  property alias supportsMouseEvents: itemMouse.enabled
76 
84  signal clicked
85 
86 
95  signal pressAndHold
96 
102  property bool checked: false
103 
109  property alias pressed: itemMouse.pressed
110 
116  property alias containsMouse: itemMouse.containsMouse
117 
123  property bool sectionDelegate: false
124 
130  property bool separatorVisible: true
131 
138  property list<Action> actions
139 
140 
147  property real position: 0
148 
158  property Item background
159 
167  property color textColor: Theme.viewTextColor
168 
173  property color backgroundColor: Theme.viewBackgroundColor
174 
183  property color activeTextColor: Theme.highlightedTextColor
184 
190  property color activeBackgroundColor: Theme.highlightColor
191 
192  Item {
193  id: behindItem
194  parent: listItem
195  anchors {
196  fill: parent
197  leftMargin: height
198  }
199  Rectangle {
200  id: shadowHolder
201  color: Theme.backgroundColor
202  anchors.fill: parent
203  }
204  EdgeShadow {
205  edge: Qt.TopEdge
206  anchors {
207  right: parent.right
208  left: parent.left
209  top: parent.top
210  }
211  }
212  EdgeShadow {
213  edge: Qt.LeftEdge
214  x: behindItem.width - (behindItem.width * listItem.position)
215  anchors {
216  top: parent.top
217  bottom: parent.bottom
218  }
219  }
220  }
221 
222  implicitWidth: parent ? parent.width : contentItem.width + paddingItem.anchors.margins * 2
223  implicitHeight: contentItem.height + Units.smallSpacing * 5
224 //END properties
225 
226 //BEGIN signal handlers
227  onBackgroundChanged: {
228  if (background) {
229  background.parent = itemMouse;
230  background.anchors.fill = itemMouse;
231  background.z = -1;
232  }
233  }
234 
235  onContentItemChanged: {
236  contentItem.parent = paddingItem
237  contentItem.z = 1;
238  }
239 
240  Component.onCompleted: {
241  backgroundChanged();
242  contentItemChanged();
243  }
244 
245  onPositionChanged: {
246  if (!mainFlickable.loopCheck && !handleMouse.pressed && !mainFlickable.flicking &&
247  !mainFlickable.dragging && !positionAnimation.running) {
248  mainFlickable.contentX = (listItem.width-listItem.height) * mainFlickable.internalPosition;
249  }
250  }
251 //END signal handlers
252 
253 //BEGIN UI implementation
254  Row {
255  id: actionsLayout
256  z: 1
257  anchors {
258  right: parent.right
259  verticalCenter: parent.verticalCenter
260  rightMargin: y
261  }
262  height: Math.min( parent.height / 1.5, Units.iconSizes.medium)
263  width: childrenRect.width
264  property bool exclusive: false
265  property Item checkedButton
266  spacing: Units.largeSpacing
267  Repeater {
268  model: {
269  if (listItem.actions.length == 0) {
270  return null;
271  } else {
272  return listItem.actions[0].text !== undefined &&
273  listItem.actions[0].trigger !== undefined ?
274  listItem.actions :
275  listItem.actions[0];
276  }
277  }
278  delegate: Icon {
279  height: actionsLayout.height
280  width: height
281  source: modelData.iconName
282  enabled: (modelData && modelData.enabled !== undefined) ? modelData.enabled : true;
283  visible: (modelData && modelData.visible !== undefined) ? modelData.visible : true;
284  MouseArea {
285  anchors {
286  fill: parent;
287  margins: -Units.smallSpacing;
288  }
289  enabled: (modelData && modelData.enabled !== undefined) ? modelData.enabled : true;
290  onClicked: {
291  if (modelData && modelData.trigger !== undefined) {
292  modelData.trigger();
293  // assume the model is a list of QAction or Action
294  } else if (toolbar.model.length > index) {
295  toolbar.model[index].trigger();
296  } else {
297  console.log("Don't know how to trigger the action")
298  }
299  positionAnimation.to = 0;
300  positionAnimation.running = true;
301  }
302  }
303  }
304  }
305  }
306 
307  PropertyAnimation {
308  id: positionAnimation
309  target: mainFlickable
310  properties: "contentX"
311  duration: Units.longDuration
312  easing.type: Easing.InOutQuad
313  }
314 
315  Flickable {
316  id: mainFlickable
317  z: 2
318  interactive: false
319  boundsBehavior: Flickable.StopAtBounds
320  anchors.fill: parent
321  contentWidth: mainItem.width
322  contentHeight: height
323  onFlickEnded: {
324  if (contentX > width / 2) {
325  positionAnimation.to = width - height;
326  } else {
327  positionAnimation.to = 0;
328  }
329  positionAnimation.running = true;
330  }
331  readonly property real internalPosition: (mainFlickable.contentX/(listItem.width-listItem.height));
332  property bool loopCheck: false
333  onInternalPositionChanged: {
334  if (!loopCheck) {
335  loopCheck = true;
336  listItem.position = internalPosition;
337  loopCheck = false;
338  }
339  }
340 
341  Item {
342  id: mainItem
343  width: (mainFlickable.width * 2) - handleMouse.width
344  height: mainFlickable.height
345  MouseArea {
346  id: itemMouse
347  anchors {
348  left: parent.left
349  top: parent.top
350  bottom: parent.bottom
351  }
352  hoverEnabled: !Settings.isMobile
353  width: mainFlickable.width
354  onClicked: listItem.clicked()
355  onPressAndHold: listItem.pressAndHold()
356 
357  Item {
358  id: paddingItem
359  anchors {
360  fill: parent
361  margins: Units.smallSpacing
362  rightMargin: handleIcon.width + Units.smallSpacing
363  }
364  }
365  }
366 
367  MouseArea {
368  id: handleMouse
369  anchors {
370  left: itemMouse.right
371  right: itemMouse.right
372  top: parent.top
373  bottom: parent.bottom
374  leftMargin: -height
375  }
376  preventStealing: true
377  property var downTimestamp;
378  property int startX
379  property int startMouseX
380 
381  onClicked: {
382  if (Math.abs(startX - mainFlickable.contentX) > Units.gridUnit ||
383  Math.abs(startMouseX - mouse.x) > Units.gridUnit) {
384  return;
385  }
386  if (mainFlickable.contentX > mainFlickable.width / 2) {
387  positionAnimation.to = 0;
388  } else {
389  positionAnimation.to = mainFlickable.width - mainFlickable.height;
390  }
391  positionAnimation.running = true;
392  }
393  onPressed: {
394  downTimestamp = (new Date()).getTime();
395  startX = mainFlickable.contentX;
396  startMouseX = mouse.x;
397  }
398  onPositionChanged: {
399  mainFlickable.contentX = Math.max(0, Math.min(mainFlickable.width - height, mainFlickable.contentX + (startMouseX - mouse.x)))
400  }
401  onReleased: {
402  var speed = ((startX - mainFlickable.contentX) / ((new Date()).getTime() - downTimestamp) * 1000);
403  mainFlickable.flick(speed, 0);
404  }
405  Icon {
406  id: handleIcon
407  anchors.centerIn: parent
408  selected: listItem.checked || (listItem.pressed && !listItem.checked && !listItem.sectionDelegate)
409  width: Units.iconSizes.smallMedium
410  height: width
411  source: (mainFlickable.contentX > mainFlickable.width / 2) ? "handle-right" : "handle-left"
412  }
413  }
414  }
415  }
416 //END UI implementation
417 
418  Accessible.role: Accessible.ListItem
419 }
org::kde::kirigami::Units::smallSpacing
int smallSpacing
units.smallSpacing is the amount of spacing that should be used around smaller UI elements...
Definition: controls/Units.qml:56
org::kde::kirigami::Units::longDuration
int longDuration
units.longDuration should be used for longer, screen-covering animations, for opening and closing of ...
Definition: controls/Units.qml:75
org::kde::kirigami::Units::largeSpacing
int largeSpacing
units.largeSpacing is the amount of spacing that should be used inside bigger UI elements, for example between an icon and the corresponding text.
Definition: controls/Units.qml:63
org::kde::kirigami::Theme
Definition: controls/Theme.qml:22
org::kde::kirigami::Units::gridUnit
int gridUnit
The fundamental unit of space that should be used for sizes, expressed in pixels. ...
Definition: controls/Units.qml:31
org::kde::kirigami::Units
Definition: controls/Units.qml:24
org::kde::kirigami::Units::iconSizes
QtObject iconSizes
units.iconSizes provides access to platform-dependent icon sizing
Definition: controls/Units.qml:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2017 The KDE developers.
Generated on Fri Feb 17 2017 11:09:23 by doxygen 1.8.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal