• 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
  • private
RefreshableScrollView.qml
1 /*
2  * Copyright 2015 Marco Martin <mart@kde.org>
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 02110-1301, USA.
18  */
19 
20 import QtQuick 2.5
21 import QtQuick.Controls 1.3 as Controls
22 import QtGraphicalEffects 1.0
23 import QtQuick.Layouts 1.2
24 import org.kde.kirigami 1.0
25 
26 
64 Controls.ScrollView {
65  id: root
66 
74  property bool refreshing: false
75 
80  property bool supportsRefreshing: false
81 
86  property int leftPadding: Units.gridUnit
87 
92  property int topPadding: Units.gridUnit
93 
98  property int rightPadding: Units.gridUnit
99 
104  property int bottomPadding: Units.gridUnit
105 
106 
107  frameVisible: false
108 
109  children: [
110  Item {
111  id: busyIndicatorFrame
112  z: 99
113  y: -root.flickableItem.contentY-height
114  width: root.flickableItem.width
115  height: busyIndicator.height + Units.gridUnit * 2
116  Controls.BusyIndicator {
117  id: busyIndicator
118  anchors.centerIn: parent
119  running: root.refreshing
120  visible: root.refreshing
121  //Android busywidget QQC seems to be broken at custom sizes
122  }
123  Rectangle {
124  id: spinnerProgress
125  anchors {
126  fill: busyIndicator
127  margins: Math.ceil(Units.smallSpacing/2)
128  }
129  radius: width
130  visible: supportsRefreshing && !refreshing && progress > 0
131  color: "transparent"
132  opacity: 0.8
133  border.color: Theme.viewBackgroundColor
134  border.width: Math.ceil(Units.smallSpacing/4)
135  property real progress: supportsRefreshing && !refreshing ? (parent.y/busyIndicatorFrame.height) : 0
136 
137  }
138  ConicalGradient {
139  source: spinnerProgress
140  visible: spinnerProgress.visible
141  anchors.fill: spinnerProgress
142  gradient: Gradient {
143  GradientStop { position: 0.00; color: Theme.highlightColor }
144  GradientStop { position: spinnerProgress.progress; color: Theme.highlightColor }
145  GradientStop { position: spinnerProgress.progress + 0.01; color: "transparent" }
146  GradientStop { position: 1.00; color: "transparent" }
147  }
148  }
149 
150  onYChanged: {
151  if (y > busyIndicatorFrame.height*1.5 + topPadding && applicationWindow() && root.flickableItem.atYBeginning && applicationWindow().pageStack.anchors.bottomMargin == 0 && root.width < root.height) {
152  applicationWindow().reachableMode = true;
153  overshootResetTimer.restart();
154  }
155 
156  if (!supportsRefreshing) {
157  return;
158  }
159  if (!root.refreshing && y > busyIndicatorFrame.height/2 + topPadding) {
160  root.refreshing = true;
161  }
162  }
163  Timer {
164  id: overshootResetTimer
165  interval: 8000
166  onTriggered: {
167  applicationWindow().reachableMode = false;
168  }
169  }
170  Binding {
171  target: root.flickableItem
172  property: "topMargin"
173  value: applicationWindow().wideScreen ? 0 : Math.max(root.topPadding + (root.refreshing ? busyIndicatorFrame.height : 0), applicationWindow().header.height)
174  }
175 
176  Binding {
177  target: root.flickableItem
178  property: "flickableDirection"
179  value: Flickable.VerticalFlick
180  }
181 
182  Binding {
183  target: root.flickableItem
184  property: "bottomMargin"
185  value: Units.gridUnit * 5
186  }
187 
188  Binding {
189  target: root.contentItem
190  property: "width"
191  value: root.flickableItem.width
192  }
193 
194  //FIXME: this shouldn't exist
195  Timer {
196  id: resetTimer
197  interval: 100
198  onTriggered: {
199  if (applicationWindow() && applicationWindow().header && !applicationWindow().wideScreen) {
200  flickableItem.contentY = -applicationWindow().header.preferredHeight;
201  }
202 
203  if (root.contentItem == root.flickableItem) {
204  flickableItem.anchors.leftMargin = 0;
205  flickableItem.anchors.topMargin = 0;
206  flickableItem.anchors.rightMargin = 0;
207  flickableItem.anchors.bottomMargin = 0;
208  } else {
209  flickableItem.anchors.leftMargin = leftPadding;
210  flickableItem.anchors.topMargin = topPadding;
211  flickableItem.anchors.rightMargin = rightPadding;
212  flickableItem.anchors.bottomMargin = bottomPadding;
213  }
214  }
215  }
216  }
217  ]
218 
219  onHeightChanged: {
220  if (!applicationWindow() || !applicationWindow().activeFocusItem) {
221  return;
222  }
223 
224  //NOTE: there is no function to know if an item is descended from another,
225  //so we have to walk the parent hyerarchy by hand
226  var isDescendent = false;
227  var candidate = applicationWindow().activeFocusItem.parent;
228  while (candidate) {
229  if (candidate == root) {
230  isDescendent = true;
231  break;
232  }
233  candidate = candidate.parent;
234  }
235  if (!isDescendent) {
236  return;
237  }
238 
239  var cursorY = 0;
240  if (applicationWindow().activeFocusItem.cursorPosition !== undefined) {
241  cursorY = applicationWindow().activeFocusItem.positionToRectangle(applicationWindow().activeFocusItem.cursorPosition).y;
242  }
243 
244  var pos = applicationWindow().activeFocusItem.mapToItem(root.contentItem, 0, cursorY);
245 
246  //focused item alreqady visible? add some margin for the space of the action buttons
247  if (pos.y >= root.flickableItem.contentY && pos.y <= root.flickableItem.contentY + root.flickableItem.height - Units.gridUnit * 8) {
248  return;
249  }
250  root.flickableItem.contentY = pos.y;
251  }
252 
253  onLeftPaddingChanged: {
254  if (root.contentItem == root.flickableItem) {
255  flickableItem.anchors.leftMargin = 0;
256  flickableItem.anchors.topMargin = 0;
257  flickableItem.anchors.rightMargin = 0;
258  flickableItem.anchors.bottomMargin = 0;
259  } else {
260  flickableItem.anchors.leftMargin = leftPadding;
261  flickableItem.anchors.topMargin = topPadding;
262  flickableItem.anchors.rightMargin = rightPadding;
263  flickableItem.anchors.bottomMargin = bottomPadding;
264  }
265  }
266 
267  onFlickableItemChanged: resetTimer.restart()
268 }
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::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
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