Debian Codegraph @

src/imports/Components/1.2/PageHeadConfiguration.qml

raw
1 /*
2 * Copyright 2014-2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import Lomiri.Components 1.2
19
20 /*!
21 \qmltype PageHeadConfiguration
22 \inqmlmodule Lomiri.Components
23 \ingroup lomiri
24 \since Lomiri.Components 1.1
25 \brief Page.head is used to configure the header for a \l Page.
26
27 For examples how to use Page.head, see \l Page.
28 */
29 Item {
30 // To be used inside a Page only.
31 id: headerConfig
32
33 /*!
34 List of actions to show in the header.
35
36 Example:
37 \qml
38 Page {
39 title: "Custom header actions"
40 head.actions: [
41 Action {
42 iconName: "save"
43 text: i18n.tr("Save")
44 },
45 Action {
46 iconName: "add"
47 text: i18n.tr("Add")
48 }
49 ]
50 }
51 \endqml
52 */
53 property list<Action> actions
54
55 /*!
56 Overrides the default \l PageStack back button and the
57 \l Tabs drawer button in the header.
58
59 Example:
60 \qml
61 Page {
62 title: "Back Action Page"
63 head.backAction: Action {
64 iconName: "close"
65 onTriggered: {
66 console.log("Run custom back action")
67 }
68 }
69 }
70 \endqml
71 */
72 property Action backAction: null
73
74 /*!
75 Set this property to show this Item in the header instead of
76 the title. Use a \l TextField here for implementing search in header.
77
78 The parent of this Item will be binded while the \l Page is active.
79 The header contents will automatically be anchored to the left and
80 vertically centered inside the header.
81
82 Example:
83 \qml
84 Page {
85 title: "Invisible title"
86 head.contents: Rectangle {
87 color: LomiriColors.orange
88 height: units.gu(5)
89 width: parent ? parent.width - units.gu(2) : undefined
90 }
91 }
92 \endqml
93
94 See \l PageHeadState for an example that shows how search mode can
95 be implemented.
96 */
97 property Item contents: null
98
99 QtObject {
100 id: internal
101 property Item oldContents: null
102 }
103
104 onContentsChanged: {
105 if (internal.oldContents) {
106 // FIX: bug #1341814 and #1400297
107 // We have to force the removal of the previous head.contents
108 // in order to show the new contents
109 internal.oldContents.parent = null;
110 }
111 internal.oldContents = contents;
112 }
113
114 // FIXME: The example below can be much simplified using PageHeadState
115 // when bug #1345775 has been fixed.
116 /*!
117 Choose a preset for the header visuals and behavior.
118 The default is an empty string "".
119 By setting this to "select", title will be hidden and
120 actions will be represented by icons with a label.
121
122 Example:
123 \qml
124 import QtQuick 2.4
125 import Lomiri.Components 1.2
126
127 MainView {
128 id: mainView
129 width: units.gu(40)
130 height: units.gu(50)
131
132 Page {
133 id: page
134 title: "Demo"
135
136 state: "default"
137 states: [
138 PageHeadState {
139 name: "default"
140 head: page.head
141 actions: [
142 Action {
143 iconName: "contact"
144 text: "Contact"
145 }
146 ]
147 },
148 State {
149 id: selectState
150 name: "select"
151
152 property Action leaveSelect: Action {
153 iconName: "back"
154 text: "Back"
155 onTriggered: page.state = "default"
156 }
157 property list<Action> actions: [
158 Action {
159 iconName: "select"
160 text: "Select All"
161 },
162 Action {
163 iconName: "delete"
164 text: "Delete"
165 }
166 ]
167 PropertyChanges {
168 target: page.head
169 backAction: selectState.leaveSelect
170 actions: selectState.actions
171 preset: "select"
172 }
173 }
174 ]
175
176 Label {
177 anchors.centerIn: parent
178 text: "Use back button to leave selection mode."
179 visible: page.state == "select"
180 }
181
182 Button {
183 anchors.centerIn: parent
184 onClicked: page.state = "select"
185 visible: page.state != "select"
186 text: "selection mode"
187 }
188 }
189 }
190 \endqml
191 */
192 property string preset: ""
193
194 /*!
195 \qmlproperty PageHeadSections sections
196 Defines the sections in the page header divider.
197 */
198 readonly property alias sections: headSections
199 PageHeadSections {
200 id: headSections
201 }
202
203 /*!
204 The color of the text and icons.
205 */
206 property color foregroundColor: Theme.palette.selected.backgroundText
207 }