• 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/ApplicationHeader.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.Layouts 1.2
22 import QtQuick.Controls.Private 1.0
23 import "private"
24 import org.kde.kirigami 1.0
25 
26 
38 AbstractApplicationHeader {
39  id: header
40 
51  property int headerStyle: ApplicationHeaderStyle.Auto
52 
53  property alias pageDelegate: titleList.delegate
54 
55  Rectangle {
56  anchors {
57  right: titleList.left
58  verticalCenter: parent.verticalCenter
59  }
60  visible: titleList.x > 0 && !titleList.atXBeginning
61  height: parent.height * 0.7
62  color: Theme.highlightedTextColor
63  width: Math.ceil(Units.smallSpacing / 6)
64  opacity: 0.4
65  }
66 
67  ListView {
68  id: titleList
69  property int internalHeaderStyle: header.headerStyle == ApplicationHeaderStyle.Auto ? (__appWindow.wideScreen ? ApplicationHeaderStyle.Titles : ApplicationHeaderStyle.Breadcrumb) : header.headerStyle
70  //uses this to have less strings comparisons
71  property bool isTabBar: header.headerStyle == ApplicationHeaderStyle.TabBar
72  Component.onCompleted: {
73  //only iOS and desktop systems put the back button on top left corner
74  if (!titleList.isTabBar && (!Settings.isMobile || Qt.platform.os == "ios")) {
75  var component = Qt.createComponent(Qt.resolvedUrl("private/BackButton.qml"));
76  titleList.backButton = component.createObject(titleList.parent);
77  }
78  }
79  property Item backButton
80  clip: true
81  anchors {
82  fill: parent
83  leftMargin: Math.max ((backButton ? backButton.width : (titleList.isTabBar ? 0 : Units.smallSpacing*2)), __appWindow.contentItem.x)
84  }
85  cacheBuffer: width ? Math.max(0, width * count) : 0
86  displayMarginBeginning: __appWindow.pageStack.width * count
87  orientation: ListView.Horizontal
88  boundsBehavior: Flickable.StopAtBounds
89  model: __appWindow.pageStack.depth
90  spacing: 0
91  currentIndex: __appWindow.pageStack && __appWindow.pageStack.currentIndex !== undefined ? __appWindow.pageStack.currentIndex : 0
92 
93  function gotoIndex(idx) {
94  //don't actually scroll in widescreen mode
95  if (__appWindow.wideScreen) {
96  return;
97  }
98  listScrollAnim.running = false
99  var pos = titleList.contentX;
100  var destPos;
101  titleList.positionViewAtIndex(idx, ListView.Center);
102  destPos = titleList.contentX;
103  listScrollAnim.from = pos;
104  listScrollAnim.to = destPos;
105  listScrollAnim.running = true;
106  }
107 
108  NumberAnimation {
109  id: listScrollAnim
110  target: titleList
111  property: "contentX"
112  duration: Units.longDuration
113  easing.type: Easing.InOutQuad
114  }
115 
116  onCurrentIndexChanged: gotoIndex(currentIndex);
117  onModelChanged: gotoIndex(currentIndex);
118  onContentWidthChanged: gotoIndex(currentIndex);
119 
120  onContentXChanged: {
121  if (__appWindow.wideScreen && !__appWindow.pageStack.contentItem.moving) {
122  //__appWindow.pageStack.contentItem.contentX = titleList.contentX
123  }
124  }
125  onHeightChanged: {
126  titleList.returnToBounds()
127  }
128  onMovementEnded: {
129  if (__appWindow.wideScreen) {
130  __appWindow.pageStack.contentItem.movementEnded();
131  }
132  }
133 
134  NumberAnimation {
135  id: scrollTopAnimation
136  target: __appWindow.pageStack.currentItem && __appWindow.pageStack.currentItem.flickable ? __appWindow.pageStack.currentItem.flickable : null
137  property: "contentY"
138  to: 0
139  duration: Units.longDuration
140  easing.type: Easing.InOutQuad
141  }
142 
143  delegate: MouseArea {
144  id: delegate
145  readonly property Page page: __appWindow.pageStack.get(modelData)
146  //NOTE: why not use ListViewCurrentIndex? because listview itself resets
147  //currentIndex in some situations (since here we are using an int as a model,
148  //even more often) so the property binding gets broken
149  readonly property bool current: __appWindow.pageStack.currentIndex == index
150 
151  width: {
152  //more columns shown?
153  if (__appWindow.wideScreen && page) {
154  if (modelData == 0 && titleList.backButton) {
155  return page.width - Math.max(0, titleList.backButton.width - __appWindow.contentItem.x);
156  } else {
157  return page.width;
158  }
159  } else {
160  return Math.min(titleList.width, delegateRoot.implicitWidth + Units.smallSpacing);
161  }
162  }
163  height: titleList.height
164  onClicked: {
165  if (__appWindow.pageStack.currentIndex == modelData) {
166  //scroll up if current otherwise make current
167  if (!__appWindow.pageStack.currentItem.flickable) {
168  return;
169  }
170  if (__appWindow.pageStack.currentItem.flickable.contentY > -__appWindow.header.height) {
171  scrollTopAnimation.to = -__appWindow.pageStack.currentItem.flickable.topMargin;
172  scrollTopAnimation.running = true;
173  }
174 
175  } else {
176  __appWindow.pageStack.currentIndex = modelData;
177  }
178  }
179 
180  Row {
181  id: delegateRoot
182  x: Units.smallSpacing + __appWindow.wideScreen ? (Math.min(delegate.width - width, Math.max(0, titleList.contentX - delegate.x))) : 0
183  height: parent.height
184 
185  spacing: Units.smallSpacing
186 
187  Icon {
188  //in tabbar mode this is just a spacer
189  visible: !__appWindow.wideScreen && (modelData > 0 || titleList.internalHeaderStyle == ApplicationHeaderStyle.TabBar)
190  height: title.height
191  width: height
192  selected: header.background && header.background.color && header.background.color == Theme.highlightColor
193  source: titleList.isTabBar ? "" : "go-next"
194  }
195 
196  Heading {
197  id: title
198  width:Math.min(titleList.width, implicitWidth)
199  anchors.verticalCenter: parent.verticalCenter
200  opacity: delegate.current ? 1 : 0.4
201  //Scaling animate NativeRendering is too slow
202  renderType: Text.QtRendering
203  color: header.background && header.background.color && header.background.color == Theme.highlightColor ? Theme.highlightedTextColor : Theme.textColor
204  elide: Text.ElideRight
205  text: page ? page.title : ""
206  font.pixelSize: titleList.height / 1.6
207  height: parent.height
208  Rectangle {
209  anchors {
210  bottom: parent.bottom
211  left: parent.left
212  right: parent.right
213  }
214  height: Units.smallSpacing
215  color: title.color
216  opacity: 0.6
217  visible: titleList.isTabBar && delegate.current
218  }
219  }
220  }
221  }
222  Connections {
223  target: __appWindow.wideScreen ? __appWindow.pageStack.contentItem : null
224  onContentXChanged: {
225  if (!titleList.contentItem.moving) {
226  titleList.contentX = __appWindow.pageStack.contentItem.contentX - __appWindow.pageStack.contentItem.originX + titleList.originX;
227  }
228  }
229  }
230  }
231 }
org::kde::kirigami::Heading
A heading label used for subsections of texts.
Definition: Heading.qml:47
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::Page::flickable
Flickable flickable
flickable: Flickable if the central element of the page is a Flickable (ListView and Gridview as well...
Definition: Page.qml:71
org::kde::kirigami::Theme
Definition: controls/Theme.qml:22
org::kde::kirigami::Page
Page is a container for all the app pages: everything pushed to the ApplicationWindow stackView shoul...
Definition: Page.qml:29
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