• 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/SplitDrawer.qml
1 /*
2  * Copyright 2012 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.1
21 import org.kde.kirigami 1.0
22 import "private"
23 
30 AbstractDrawer {
31  id: root
32  z:0
33 
34  visible: true
35 
41  default property alias page: mainPage.data
42 
47  property Item contentItem
48 
54  property alias opened: sidebar.open
55 
62  property real position: 0
63 
74  //property bool modal: true
75 
85  property Item background
86 
87  onBackgroundChanged: {
88  background.parent = browserFrame;
89  background.anchors.fill = browserFrame;
90  background.z = -1;
91  }
92 
93  Component.onCompleted: {
94  mainPage.width = browserFrame.width
95  contentItem.parent = drawerPage
96  }
97 
98  onPositionChanged: {
99  if (!browserFrame.loopCheck) {
100  browserFrame.loopCheck = true;
101  browserFrame.x = position * drawerPage.width;
102  browserFrame.loopCheck = false;
103  }
104  }
105  onContentItemChanged: contentItem.parent = drawerPage
106  MouseArea {
107  id: mouseEventListener
108  z: 200
109  drag.filterChildren: true
110  //drag.target: browserFrame
111  property int startMouseX
112  property int oldMouseX
113  property int startBrowserFrameX
114  property bool toggle: false
115  property string startState
116  enabled: root.modal
117 
118  anchors.fill: parent
119 
120  onPressed: {
121  if (drawerPage.children.length == 0 || (browserFrame.state == "Closed" && mouse.x > Units.gridUnit) ||
122  mouse.x < browserFrame.x) {
123  mouse.accepted = false;
124  return;
125  }
126 
127  toggle = true;
128  startBrowserFrameX = browserFrame.x;
129  oldMouseX = startMouseX = mouse.x;
130  startState = browserFrame.state;
131  browserFrame.state = "Dragging";
132  browserFrame.x = startBrowserFrameX;
133  }
134 
135  onPositionChanged: {
136  browserFrame.x = Math.max(0, browserFrame.x + mouse.x - oldMouseX);
137  oldMouseX = mouse.x;
138  if (Math.abs(mouse.x - startMouseX) > Units.gridUnit * 2) {
139  toggle = false;
140  }
141  }
142 
143  onReleased: {
144  if (toggle) {
145  browserFrame.state = startState == "Open" ? "Closed" : "Open"
146  } else if (browserFrame.x < drawerPage.width / 2) {
147  browserFrame.state = "Closed";
148  } else {
149  browserFrame.state = "Open";
150  }
151  }
152  onClicked: root.clicked()
153  }
154 
155  Item {
156  id: browserFrame
157  z: 100
158  state: sidebar.open ? "Open" : "Closed"
159  onStateChanged: sidebar.open = (state != "Closed")
160  readonly property real position: Math.abs(x) / drawerPage.width
161  property bool loopCheck: false
162  onPositionChanged: {
163  if (!loopCheck) {
164  loopCheck = true;
165  root.position = position;
166  loopCheck = false;
167  }
168  }
169 
170  anchors {
171  top: parent.top
172  bottom: parent.bottom
173  }
174  width: root.width;
175 
176  Item {
177  id: mainPage
178  onChildrenChanged: mainPage.children[0].anchors.fill = mainPage
179 
180  anchors.fill: parent
181  }
182 
183  Rectangle {
184  anchors.fill: parent
185  color: "black"
186  opacity: Math.min(0.4, 0.4 * (browserFrame.x / drawerPage.width))
187  visible: root.modal
188  }
189 
190  states: [
191  State {
192  name: "Open"
193  PropertyChanges {
194  target: browserFrame
195  x: drawerPage.width
196  }
197 
198  },
199  State {
200  name: "Dragging"
201  PropertyChanges {
202  target: browserFrame
203  x: mouseEventListener.startBrowserFrameX
204  }
205  },
206  State {
207  name: "Closed"
208  PropertyChanges {
209  target: browserFrame
210  x: 0
211  }
212  }
213  ]
214 
215  transitions: [
216  Transition {
217  //Exclude Dragging
218  to: "Open,Closed,Hidden"
219  NumberAnimation {
220  properties: "x"
221  duration: Units.longDuration
222  easing.type: Easing.InOutQuad
223  }
224  }
225  ]
226  }
227 
228 
229  Item {
230  id: sidebar
231 
232  property bool open: false
233  onOpenChanged: {
234  if (drawerPage.children.length == 0) {
235  return;
236  }
237 
238  if (open) {
239  browserFrame.state = "Open";
240  } else {
241  browserFrame.state = "Closed";
242  }
243  }
244 
245  width: browserFrame.x
246  clip: true
247 
248  anchors {
249  left: parent.left
250  top: parent.top
251  bottom: parent.bottom
252  }
253 
254  Item {
255  id: drawerPage
256  width: Math.min(root.width/4*3, Math.max(root.contentItem ? root.contentItem.implicitWidth : 0, root.width/4))
257  anchors {
258  top: parent.top
259  bottom: parent.bottom
260  left: parent.left
261  topMargin: (applicationWindow !== undefined && applicationWindow().header) && modal ? applicationWindow().header.height : 0
262  }
263  clip: false
264  onChildrenChanged: drawerPage.children[0].anchors.fill = drawerPage
265  }
266  }
267 }
268 
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::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