• 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
templates/OverlaySheet.qml
1 /*
2 * Copyright (C) 2016 by 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 2.010-1301, USA.
18 */
19 
20 import QtQuick 2.5
21 import QtQuick.Controls 1.3 as Controls
22 import org.kde.kirigami 1.0
23 import QtGraphicalEffects 1.0
24 import "private"
25 
34 Item {
35  id: root
36 
37  z: 999
38 
39  anchors.fill: parent
40  visible: false
41 
49  default property Item contentItem
50 
56  property bool opened
57 
62  property int leftPadding: Units.gridUnit
63 
68  property int topPadding: Units.gridUnit
69 
74  property int rightPadding: Units.gridUnit
75 
80  property int bottomPadding: Units.gridUnit
81 
91  property Item background
92 
93 
94  function open() {
95  root.visible = true;
96  openAnimation.from = -root.height;
97  openAnimation.to = openAnimation.topOpenPosition;
98  openAnimation.running = true;
99  root.opened = true;
100  }
101 
102  function close() {
103  if (scrollView.flickableItem.contentY < 0) {
104  closeAnimation.to = -height;
105  } else {
106  closeAnimation.to = scrollView.flickableItem.contentHeight;
107  }
108  closeAnimation.running = true;
109  }
110 
111  Rectangle {
112  anchors.fill: parent
113  color: Theme.textColor
114  opacity: 0.6 * Math.min(
115  (Math.min(scrollView.flickableItem.contentY + scrollView.flickableItem.height, scrollView.flickableItem.height) / scrollView.flickableItem.height),
116  (2 + (scrollView.flickableItem.contentHeight - scrollView.flickableItem.contentY - scrollView.flickableItem.topMargin - scrollView.flickableItem.bottomMargin)/scrollView.flickableItem.height))
117  }
118 
119 
120  Component.onCompleted: {
121  scrollView.flickableItem.interactive = true;
122  }
123  onBackgroundChanged: {
124  background.parent = flickableContents;
125  background.z = -1;
126  }
127  onContentItemChanged: {
128  if (contentItem.hasOwnProperty("contentY") && // Check if flickable
129  contentItem.hasOwnProperty("contentHeight")) {
130  contentItem.parent = scrollView;
131  scrollView.contentItem = contentItem;
132  } else {
133  contentItem.parent = contentItemParent;
134  scrollView.contentItem = flickableContents;
135  contentItem.anchors.left = contentItemParent.left;
136  contentItem.anchors.right = contentItemParent.right;
137  }
138  scrollView.flickableItem.flickableDirection = Flickable.VerticalFlick;
139  }
140  onOpenedChanged: {
141  if (opened) {
142  open();
143  } else {
144  close();
145  Qt.inputMethod.hide();
146  }
147  }
148  onWidthChanged: {
149  if (!contentItem.contentItem)
150  return
151 
152  var width = Math.max(root.width/2, Math.min(root.width, root.contentItem.implicitWidth));
153  contentItem.contentItem.x = (root.width - width)/2
154  contentItem.contentItem.width = width;
155  }
156  onHeightChanged: {
157  var focusItem;
158 
159  if (typeof applicationWindow !== "undefined") {
160  focusItem = applicationWindow().activeFocusItem;
161  //fallback: hope activeFocusItem is in context
162  } else {
163  focusItem = activeFocusItem;
164  }
165 
166  if (!activeFocusItem) {
167  return;
168  }
169 
170  //NOTE: there is no function to know if an item is descended from another,
171  //so we have to walk the parent hyerarchy by hand
172  var isDescendent = false;
173  var candidate = focusItem.parent;
174  while (candidate) {
175  if (candidate == root) {
176  isDescendent = true;
177  break;
178  }
179  candidate = candidate.parent;
180  }
181  if (!isDescendent) {
182  return;
183  }
184 
185  var cursorY = 0;
186  if (focusItem.cursorPosition !== undefined) {
187  cursorY = focusItem.positionToRectangle(focusItem.cursorPosition).y;
188  }
189 
190 
191  var pos = focusItem.mapToItem(flickableContents, 0, cursorY - Units.gridUnit*3);
192  //focused item alreqady visible? add some margin for the space of the action buttons
193  if (pos.y >= scrollView.flickableItem.contentY && pos.y <= scrollView.flickableItem.contentY + scrollView.flickableItem.height - Units.gridUnit * 8) {
194  return;
195  }
196  scrollView.flickableItem.contentY = pos.y;
197  }
198 
199 
200  NumberAnimation {
201  id: openAnimation
202  property int topOpenPosition: Math.min(-root.height*0.15, scrollView.flickableItem.contentHeight - root.height + Units.gridUnit * 5)
203  property int bottomOpenPosition: (scrollView.flickableItem.contentHeight - root.height) + (Units.gridUnit * 5)
204  target: scrollView.flickableItem
205  properties: "contentY"
206  from: -root.height
207  to: topOpenPosition
208  duration: Units.longDuration
209  easing.type: Easing.OutQuad
210  onRunningChanged: {
211  if (!running && contentItem.contentItem) {
212  var width = Math.max(root.width/2, Math.min(root.width, root.contentItem.implicitWidth));
213  contentItem.contentItem.x = (root.width - width)/2
214  contentItem.contentItem.width = width;
215  }
216  }
217  }
218 
219  SequentialAnimation {
220  id: closeAnimation
221  property int to: -root.height
222  NumberAnimation {
223  target: scrollView.flickableItem
224  properties: "contentY"
225  to: closeAnimation.to
226  duration: Units.longDuration
227  easing.type: Easing.InQuad
228  }
229  ScriptAction {
230  script: {
231  scrollView.flickableItem.contentY = -root.height;
232  root.visible = root.opened = false;
233  }
234  }
235  }
236 
237  MouseArea {
238  anchors.fill: parent
239  z: 2
240  drag.filterChildren: true
241  hoverEnabled: true
242 
243  onClicked: {
244  var pos = mapToItem(flickableContents, mouse.x, mouse.y);
245  if (!flickableContents.contains(pos)) {
246  root.close();
247  }
248  }
249 
250  Item {
251  id: flickableContents
252  //anchors.horizontalCenter: parent.horizontalCenter
253  x: (root.width - width) / 2
254  y: scrollView.flickableItem && root.contentItem.hasOwnProperty("contentY") ? -scrollView.flickableItem.contentY : 0
255  width: root.contentItem.implicitWidth <= 0 ? root.width : Math.max(root.width/2, Math.min(root.width, root.contentItem.implicitWidth))
256  height: scrollView.flickableItem && root.contentItem.hasOwnProperty("contentY") ? scrollView.flickableItem.contentHeight : (root.contentItem.height + topPadding + bottomPadding + Units.iconSizes.medium + Units.gridUnit)
257  Item {
258  id: contentItemParent
259  anchors {
260  fill: parent
261  leftMargin: leftPadding
262  topMargin: topPadding
263  rightMargin: rightPadding
264  bottomMargin: bottomPadding
265  }
266  }
267  }
268  Binding {
269  when: scrollView.flickableItem != null
270  target: scrollView.flickableItem
271  property: "topMargin"
272  value: scrollView.height
273  }
274  Binding {
275  when: scrollView.flickableItem != null
276  target: scrollView.flickableItem
277  property: "bottomMargin"
278  value: scrollView.height
279  }
280 
281  Connections {
282  target: scrollView.flickableItem
283  function movementEnded() {
284  //close
285  if ((root.height + scrollView.flickableItem.contentY) < root.height/2) {
286  closeAnimation.to = -root.height;
287  closeAnimation.running = true;
288  } else if ((root.height*0.6 + scrollView.flickableItem.contentY) > scrollView.flickableItem.contentHeight) {
289  closeAnimation.to = scrollView.flickableItem.contentHeight
290  closeAnimation.running = true;
291 
292  //reset to the default opened position
293  } else if (scrollView.flickableItem.contentY < openAnimation.topOpenPosition) {
294  openAnimation.from = scrollView.flickableItem.contentY;
295  openAnimation.to = openAnimation.topOpenPosition;
296  openAnimation.running = true;
297  //reset to the default "bottom" opened position
298  } else if (scrollView.flickableItem.contentY > openAnimation.bottomOpenPosition) {
299  openAnimation.from = scrollView.flickableItem.contentY;
300  openAnimation.to = openAnimation.bottomOpenPosition;
301  openAnimation.running = true;
302  }
303  }
304  onMovementEnded: movementEnded();
305  onFlickEnded: movementEnded();
306  onContentHeightChanged: {
307  if (openAnimation.running) {
308  openAnimation.running = false;
309  open();
310  }
311  }
312  }
313  Controls.ScrollView {
314  id: scrollView
315  anchors.fill: parent
316  horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
317  }
318  }
319 }
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::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