Kirigami2

controls/templates/AbstractApplicationHeader.qml
1 /*
2  * SPDX-FileCopyrightText: 2015 Marco Martin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.7
8 import QtQuick.Layouts 1.2
9 import "private"
10 import org.kde.kirigami 2.4
11 import QtQuick.Controls 2.4 as Controls
12 
25 Item {
26  id: root
27  z: 90
28  property int minimumHeight: 0
29  property int preferredHeight: Units.iconSizes.medium + Units.smallSpacing * 2
30  property int maximumHeight: Units.gridUnit * 3
31 
32  property int position: Controls.ToolBar.Header
33 
34  property PageRow pageRow: __appWindow ? __appWindow.pageStack: null
35  property Page page: pageRow ? pageRow.currentItem : null
36 
37  default property alias contentItem: mainItem.data
38  readonly property int paintedHeight: headerItem.y + headerItem.height - 1
39 
40  property int leftPadding: 0
41  property int topPadding: 0
42  property int rightPadding: 0
43  property int bottomPadding: 0
44  property bool separatorVisible: true
45 
46  LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
47  LayoutMirroring.childrenInherit: true
48 
49  Theme.inherit: true
50 
51  //FIXME: remove
52  property QtObject __appWindow: typeof applicationWindow !== "undefined" ? applicationWindow() : null;
53  implicitHeight: preferredHeight
54 
60  property Item background
61 
62  onBackgroundChanged: {
63  background.z = -1;
64  background.parent = headerItem;
65  background.anchors.fill = headerItem;
66  }
67 
68  onMinimumHeightChanged: implicitHeight = preferredHeight;
69  onPreferredHeightChanged: implicitHeight = preferredHeight;
70 
71  opacity: height > 0 ? 1 : 0
72 
73  NumberAnimation {
74  id: heightAnim
75  target: root
76  property: "implicitHeight"
77  duration: Units.longDuration
78  easing.type: Easing.InOutQuad
79  }
80  Connections {
81  target: __appWindow
82  onControlsVisibleChanged: {
83  heightAnim.from = root.implicitHeight
84  heightAnim.to = __appWindow.controlsVisible ? root.preferredHeight : 0;
85  heightAnim.restart();
86  }
87  }
88 
89  Item {
90  id: headerItem
91  property real computedRootHeight: root.preferredHeight
92  anchors {
93  left: parent.left
94  right: parent.right
95  bottom: root.position === Controls.ToolBar.Header ? parent.bottom : undefined
96  top: root.position === Controls.ToolBar.Footer ? parent.top : undefined
97  }
98 
99  height: __appWindow && __appWindow.reachableMode && __appWindow.reachableModeEnabled ? root.maximumHeight : (root.minimumHeight > 0 ? Math.max(root.height, root.minimumHeight) : root.preferredHeight)
100 
101  //FIXME: see FIXME below
102  Connections {
103  target: root.page ? root.page.globalToolBarItem : null
104  enabled: headerSlideConnection.passive && target
105  onImplicitHeightChanged: root.implicitHeight = root.page.globalToolBarItem.implicitHeight
106  }
107 
108  Connections {
109  id: headerSlideConnection
110  target: root.page ? root.page.flickable : null
111  enabled: !passive
112  property real oldContentY
113  property bool updatingContentY: false
114 
115  //FIXME HACK: if we are in global mode, meaning if we are the toolbar showing the global breadcrumb (but the pages are showing their own toolbar), not to try to mess with page contentY.
116  //A better solution is needed
117  readonly property bool passive: root.pageRow && parent.parent == root.pageRow && root.pageRow.globalToolBar.actualStyle !== ApplicationHeaderStyle.TabBar && root.pageRow.globalToolBar.actualStyle != ApplicationHeaderStyle.Breadcrumb
118 
119  onContentYChanged: {
120  if(root.page && root.page.flickable && root.page.flickable.contentHeight < root.page.height) {
121  return
122  }
123 
124  if ((root.pageRow ? root.pageRow.wideMode : (__appWindow && __appWindow.wideScreen)) || !Settings.isMobile) {
125  root.implicitHeight = root.preferredHeight;
126  } else {
127  var oldHeight = root.implicitHeight;
128 
129  root.implicitHeight = Math.max(root.minimumHeight,
130  Math.min(root.preferredHeight,
131  root.implicitHeight + oldContentY - root.page.flickable.contentY));
132 
133  //if the implicitHeight is changed, use that to simulate scroll
134  if (oldHeight === implicitHeight) {
135  oldContentY = root.page.flickable.contentY;
136  }
137  }
138  }
139 
140  onMovementEnded: {
141  if ((root.pageRow ? root.pageRow.wideMode : (__appWindow && __appWindow.wideScreen)) || !Settings.isMobile) {
142  return;
143  }
144  if (root.height > root.minimumHeight + (root.preferredHeight - root.minimumHeight)/2 ) {
145  heightAnim.to = root.preferredHeight;
146  } else {
147  heightAnim.to = root.minimumHeight;
148  }
149  heightAnim.from = root.implicitHeight
150  heightAnim.restart();
151  }
152  }
153  Connections {
154  target: pageRow
155  onCurrentItemChanged: {
156  if (!root.page) {
157  return;
158  }
159  if (root.page.flickable) {
160  headerSlideConnection.oldContentY = root.page.flickable.contentY;
161  } else {
162  headerSlideConnection.oldContentY = 0;
163  }
164 
165  root.implicitHeight = root.preferredHeight;
166  }
167  }
168 
169  Item {
170  id: mainItem
171  clip: childrenRect.width > width
172  anchors {
173  fill: parent
174  leftMargin: root.leftPadding
175  topMargin: root.topPadding
176  rightMargin: root.rightPadding
177  bottomMargin: root.bottomPadding
178  }
179  }
180  }
181 }
182 
int gridUnit
The fundamental unit of space that should be used for sizes, expressed in pixels. ...
bool isMobile
True if we are running on a small mobile device such as a mobile phone This is used when we want to d...
Definition: settings.h:32
This class contains global kirigami settings about the current device setup It is exposed to QML as t...
Definition: settings.h:16
int smallSpacing
units.smallSpacing is the amount of spacing that should be used around smaller UI elements...
QtObject iconSizes
units.iconSizes provides access to platform-dependent icon sizing
QTextStream & right(QTextStream &stream)
A set of named colors for the application.
int longDuration
units.longDuration should be used for longer, screen-covering animations, for opening and closing of ...
Page is a container for all the app pages: everything pushed to the ApplicationWindow stackView shoul...
Definition: Page.qml:19
A set of values to define semantically sizes and durations.
PageRow implements a row-based navigation model, which can be used with a set of interlinked informat...
Definition: PageRow.qml:22
QTextStream & left(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 22:39:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.