1/* 2 * SPDX-FileCopyrightText: 2018 Marco Martin <mart@kde.org> 3 * 4 * SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 7import QtQuick 2.5 8import QtQuick.Window 2.5 9import QtQuick.Controls 2.0 as Controls 10import QtQuick.Layouts 1.2 11import org.kde.kirigami 2.14 12import "../" as Private 13 14 15AbstractPageHeader { 16 id: root 17 18 implicitWidth: layout.implicitWidth + Units.smallSpacing * 2 19 implicitHeight: Math.max(titleLoader.implicitHeight, toolBar.implicitHeight) + Units.smallSpacing * 2 20 21 MouseArea { 22 anchors.fill: parent 23 onPressed: { 24 page.forceActiveFocus() 25 mouse.accepted = false 26 } 27 } 28 29 RowLayout { 30 id: layout 31 anchors.fill: parent 32 anchors.rightMargin: Units.smallSpacing 33 spacing: Units.smallSpacing 34 35 Loader { 36 id: titleLoader 37 38 Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter 39 Layout.fillWidth: item ? item.Layout.fillWidth : undefined 40 Layout.minimumWidth: item ? item.Layout.minimumWidth : undefined 41 Layout.preferredWidth: item ? item.Layout.preferredWidth : undefined 42 Layout.maximumWidth: item ? item.Layout.maximumWidth : undefined 43 44 asynchronous: true 45 46 sourceComponent: page ? page.titleDelegate : null 47 } 48 49 ActionToolBar { 50 id: toolBar 51 52 Layout.alignment: Qt.AlignVCenter 53 Layout.fillWidth: true 54 Layout.fillHeight: true 55 56 visible: actions.length > 0 57 alignment: pageRow ? pageRow.globalToolBar.toolbarActionAlignment : Qt.AlignRight 58 heightMode: ToolBarLayout.ConstrainIfLarger 59 60 actions: { 61 if (!page) { 62 return [] 63 } 64 65 var result = [] 66 67 if (page.actions.main) { 68 result.push(page.actions.main) 69 } 70 if (page.actions.left) { 71 result.push(page.actions.left) 72 } 73 if (page.actions.right) { 74 result.push(page.actions.right) 75 } 76 if (page.actions.contextualActions.length > 0) { 77 result = result.concat(Array.prototype.map.call(page.actions.contextualActions, function(item) { return item })) 78 } 79 80 return result 81 } 82 83 Binding { 84 target: page.actions.main 85 property: "displayHint" 86 value: page.actions.main ? (page.actions.main.displayHint | DisplayHint.KeepVisible) : null 87 } 88 Binding { 89 target: page.actions.left 90 property: "displayHint" 91 value: page.actions.left ? (page.actions.left.displayHint | DisplayHint.KeepVisible) : null 92 } 93 Binding { 94 target: page.actions.right 95 property: "displayHint" 96 value: page.actions.right ? (page.actions.right.displayHint | DisplayHint.KeepVisible) : null 97 } 98 } 99 } 100} 101 102