Changeset View
Changeset View
Standalone View
Standalone View
src/controls/private/globaltoolbar/ToolBarPageHeader.qml
Show All 14 Lines | |||||
15 | * License along with this program; if not, write to the | 15 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | 16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | import QtQuick 2.5 | 20 | import QtQuick 2.5 | ||
21 | import QtQuick.Controls 2.0 as Controls | 21 | import QtQuick.Controls 2.0 as Controls | ||
22 | import QtQuick.Layouts 1.2 | 22 | import QtQuick.Layouts 1.2 | ||
23 | import org.kde.kirigami 2.4 | 23 | import org.kde.kirigami 2.5 | ||
24 | import "../" as Private | 24 | import "../" as Private | ||
25 | 25 | | |||
26 | 26 | | |||
27 | AbstractPageHeader { | 27 | AbstractPageHeader { | ||
28 | id: root | 28 | id: root | ||
29 | 29 | | |||
30 | implicitWidth: titleLoader.implicitWidth.width/2 + buttonTextMetrics.collapsedButtonsWidth | 30 | implicitWidth: titleLoader.implcitWidth + toolBar.implicitWidth + Units.smallSpacing * 3 | ||
31 | Layout.minimumWidth: ctxActionsButton.width*4 | | |||
32 | 31 | | |||
33 | Layout.preferredHeight: Math.max(titleLoader.implicitHeight, actionsLayout.implicitHeight) + Units.smallSpacing * 2 | 32 | Layout.preferredHeight: Math.max(titleLoader.implicitHeight, toolBar.implicitHeight) + Units.smallSpacing * 2 | ||
34 | 33 | | |||
35 | MouseArea { | 34 | MouseArea { | ||
36 | anchors.fill: parent | 35 | anchors.fill: parent | ||
37 | onClicked: page.forceActiveFocus() | 36 | onClicked: page.forceActiveFocus() | ||
38 | } | 37 | } | ||
39 | 38 | | |||
40 | Loader { | 39 | Loader { | ||
41 | id: titleLoader | 40 | id: titleLoader | ||
42 | 41 | | |||
43 | anchors { | 42 | anchors { | ||
44 | verticalCenter: parent.verticalCenter | 43 | verticalCenter: parent.verticalCenter | ||
45 | left: parent.left | 44 | left: parent.left | ||
46 | right: parent.right | 45 | leftMargin: Units.smallSpacing | ||
47 | leftMargin: Units.largeSpacing | | |||
48 | rightMargin: Units.smallSpacing | 46 | rightMargin: Units.smallSpacing | ||
49 | } | 47 | } | ||
50 | 48 | | |||
51 | visible: pageRow.globalToolBar.toolbarActionAlignment == Qt.AlignRight && width > item.Layout.minimumWidth | 49 | visible: pageRow.globalToolBar.toolbarActionAlignment == Qt.AlignRight && width > item.Layout.minimumWidth | ||
52 | 50 | | |||
53 | sourceComponent: page ? page.titleDelegate : null | 51 | sourceComponent: page ? page.titleDelegate : null | ||
54 | | ||||
55 | Layout.preferredWidth: item | | |||
56 | ? (item.Layout.preferredWidth > 0 ? item.Layout.preferredWidth : item.implicitWidth) | | |||
57 | : 0 | | |||
58 | } | 52 | } | ||
59 | 53 | | |||
54 | ActionToolBar { | ||||
55 | id: toolBar | ||||
60 | 56 | | |||
61 | TextMetrics { | | |||
62 | id: buttonTextMetrics | | |||
63 | text: (page.actions.left ? page.actions.left.text : "") + (page.actions.main ? page.actions.main.text : "") + (page.actions.right ? page.actions.right.text : "") | | |||
64 | readonly property int collapsedButtonsWidth: ctxActionsButton.width + (page.actions.left ? ctxActionsButton.width + Units.gridUnit : 0) + (page.actions.main ? ctxActionsButton.width + Units.gridUnit : 0) + (page.actions.right ? ctxActionsButton.width + Units.gridUnit : 0) | | |||
65 | readonly property int requiredWidth: width + collapsedButtonsWidth | | |||
66 | } | | |||
67 | | ||||
68 | RowLayout { | | |||
69 | id: actionsLayout | | |||
70 | anchors { | 57 | anchors { | ||
58 | left: titleLoader.right | ||||
59 | leftMargin: Units.smallSpacing | ||||
60 | right: parent.right | ||||
61 | rightMargin: Units.smallSpacing | ||||
71 | verticalCenter: parent.verticalCenter | 62 | verticalCenter: parent.verticalCenter | ||
72 | left: parent.left | | |||
73 | right: ctxActionsButton.visible ? ctxActionsButton.left : parent.right | | |||
74 | } | 63 | } | ||
75 | 64 | | |||
76 | readonly property bool toobig: root.width - root.leftPadding - root.rightPadding - titleLoader.implicitWidth - Units.gridUnit < buttonTextMetrics.requiredWidth | 65 | alignment: pageRow.globalToolBar.toolbarActionAlignment | ||
66 | display: buttonTextMetrics.toobig ? Controls.Button.IconOnly : Controls.Button.TextBesideIcon | ||||
67 | | ||||
68 | actions: { | ||||
69 | var result = [] | ||||
77 | 70 | | |||
78 | Item { | 71 | if (page) { | ||
79 | Layout.fillWidth: true | 72 | if (page.actions.main) { | ||
80 | visible: pageRow.globalToolBar.toolbarActionAlignment != Qt.AlignLeft | 73 | result.push(page.actions.main) | ||
81 | } | 74 | } | ||
82 | Private.PrivateActionToolButton { | 75 | if (page.actions.left) { | ||
83 | Layout.alignment: Qt.AlignVCenter | 76 | result.push(page.actions.left) | ||
84 | kirigamiAction: page && page.actions ? page.actions.left : null | 77 | } | ||
85 | showText: !parent.toobig | 78 | if (page.actions.right) { | ||
86 | } | 79 | result.push(page.actions.right) | ||
87 | Private.PrivateActionToolButton { | 80 | } | ||
88 | Layout.alignment: Qt.AlignVCenter | 81 | if (page.actions.contextualActions.length > 0 && !buttonTextMetrics.toobig) { | ||
89 | Layout.rightMargin: Units.smallSpacing | 82 | result = result.concat(Array.prototype.map.call(page.actions.contextualActions, function(item) { return item })) | ||
90 | kirigamiAction: page && page.actions ? page.actions.main : null | | |||
91 | showText: !parent.toobig | | |||
92 | } | | |||
93 | Private.PrivateActionToolButton { | | |||
94 | Layout.alignment: Qt.AlignVCenter | | |||
95 | kirigamiAction: page && page.actions ? page.actions.right : null | | |||
96 | showText: !parent.toobig | | |||
97 | } | | |||
98 | Item { | | |||
99 | Layout.fillWidth: true | | |||
100 | visible: pageRow.globalToolBar.toolbarActionAlignment != Qt.AlignRight | | |||
101 | } | 83 | } | ||
102 | } | 84 | } | ||
103 | 85 | | |||
104 | Private.PrivateActionToolButton { | 86 | return result | ||
105 | id: ctxActionsButton | | |||
106 | showMenuArrow: page.actions.contextualActions.length == 1 | | |||
107 | onMenuAboutToShow: page.contextualActionsAboutToShow(); | | |||
108 | anchors { | | |||
109 | right: parent.right | | |||
110 | verticalCenter: parent.verticalCenter | | |||
111 | rightMargin: Units.smallSpacing | | |||
112 | } | 87 | } | ||
113 | Action { | 88 | | ||
114 | id: overflowAction | 89 | hiddenActions: page && buttonTextMetrics.toobig ? page.actions.contextualActions : [] | ||
115 | icon.name: "overflow-menu" | | |||
116 | tooltip: qsTr("More Actions") | | |||
117 | visible: visibleChildren.length > 0 | | |||
118 | children: page && page.actions.contextualActions ? page.actions.contextualActions : null | | |||
119 | } | 90 | } | ||
120 | 91 | | |||
121 | kirigamiAction: page && page.actions.contextualActions.length === 1 ? page.actions.contextualActions[0] : overflowAction | 92 | | ||
93 | TextMetrics { | ||||
94 | id: buttonTextMetrics | ||||
95 | text: (page.actions.left ? page.actions.left.text : "") + (page.actions.main ? page.actions.main.text : "") + (page.actions.right ? page.actions.right.text : "") | ||||
96 | readonly property int collapsedButtonsWidth: toolBar.Layout.minimumWidth + (page.actions.left ? toolBar.Layout.minimumWidth + Units.gridUnit : 0) + (page.actions.main ? toolBar.Layout.minimumWidth + Units.gridUnit : 0) + (page.actions.right ? toolBar.Layout.minimumWidth + Units.gridUnit : 0) | ||||
97 | readonly property int requiredWidth: width + collapsedButtonsWidth | ||||
98 | readonly property bool toobig: root.width - root.leftPadding - root.rightPadding - titleLoader.implicitWidth - Units.gridUnit < buttonTextMetrics.requiredWidth | ||||
122 | } | 99 | } | ||
123 | } | 100 | } | ||
124 | 101 | |