Kirigami2

ToolBarPageHeader.qml
1 /*
2  * SPDX-FileCopyrightText: 2018 Marco Martin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.15
8 import QtQml 2.15
9 import QtQuick.Layouts 1.15
10 import org.kde.kirigami 2.19 as Kirigami
11 
12 AbstractPageHeader {
13  id: root
14 
15  implicitWidth: layout.implicitWidth + Kirigami.Units.smallSpacing * 2
16  implicitHeight: Math.max(titleLoader.implicitHeight, toolBar.implicitHeight) + Kirigami.Units.smallSpacing * 2
17 
18  MouseArea {
19  anchors.fill: parent
20  onPressed: mouse => {
21  page.forceActiveFocus()
22  mouse.accepted = false
23  }
24  }
25 
26  RowLayout {
27  id: layout
28  anchors.fill: parent
29  anchors.rightMargin: Kirigami.Units.smallSpacing
30  spacing: Kirigami.Units.smallSpacing
31 
32  Loader {
33  id: titleLoader
34 
35  Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
36  Layout.fillWidth: item ? item.Layout.fillWidth : false
37  Layout.minimumWidth: item ? item.Layout.minimumWidth : -1
38  Layout.preferredWidth: item ? item.Layout.preferredWidth : -1
39  Layout.maximumWidth: item ? item.Layout.maximumWidth : -1
40 
41  // Don't load async to prevent jumpy behaviour on slower devices as it loads in.
42  // If the title delegate really needs to load async, it should be its responsibility to do it itself.
43  asynchronous: false
44  sourceComponent: page ? page.titleDelegate : null
45  }
46 
47  Kirigami.ActionToolBar {
48  id: toolBar
49 
50  Layout.alignment: Qt.AlignVCenter
51  Layout.fillWidth: true
52  Layout.fillHeight: true
53 
54  visible: actions.length > 0
55  alignment: pageRow ? pageRow.globalToolBar.toolbarActionAlignment : Qt.AlignRight
56  heightMode: pageRow ? pageRow.globalToolBar.toolbarActionHeightMode : Kirigami.ToolBarLayout.ConstrainIfLarger
57 
58  actions: {
59  if (!page) {
60  return []
61  }
62 
63  const result = []
64 
65  if (page.actions.main) {
66  result.push(page.actions.main)
67  }
68  if (page.actions.left) {
69  result.push(page.actions.left)
70  }
71  if (page.actions.right) {
72  result.push(page.actions.right)
73  }
74  if (page.actions.contextualActions.length > 0) {
75  return result.concat(Array.prototype.map.call(page.actions.contextualActions, function(item) { return item }))
76  }
77  return result
78  }
79 
80  Binding {
81  target: page.actions.main
82  property: "displayHint"
83  value: page.actions.main ? (page.actions.main.displayHint | Kirigami.DisplayHint.KeepVisible) : null
84  restoreMode: Binding.RestoreBinding
85  }
86  Binding {
87  target: page.actions.left
88  property: "displayHint"
89  value: page.actions.left ? (page.actions.left.displayHint | Kirigami.DisplayHint.KeepVisible) : null
90  restoreMode: Binding.RestoreBinding
91  }
92  Binding {
93  target: page.actions.right
94  property: "displayHint"
95  value: page.actions.right ? (page.actions.right.displayHint | Kirigami.DisplayHint.KeepVisible) : null
96  restoreMode: Binding.RestoreBinding
97  }
98  }
99  }
100 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 04:11:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.