Debian Codegraph @

src/imports/Components/1.2/PageHeadState.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 // for Action
19
20 /*!
21 \qmltype PageHeadState
22 \inqmlmodule Lomiri.Components
23 \ingroup lomiri
24 \since Lomiri.Components 1.1
25 \brief PageHeadState is a helper component to make it easier to
26 configure the page header when changing states.
27
28 This example shows how to add an action to the header that
29 enables the user to enter search/input mode:
30 \qml
31 import QtQuick 2.4
32 import Lomiri.Components 1.2
33
34 MainView {
35 id: mainView
36 width: units.gu(40)
37 height: units.gu(50)
38
39 Page {
40 id: searchPage
41 title: "Click the icon"
42
43 Label {
44 anchors.centerIn: parent
45 text: searchPage.state == "search" ? "search mode" : "normal mode"
46 }
47
48 state: "default"
49 states: [
50 PageHeadState {
51 name: "default"
52 head: searchPage.head
53 actions: Action {
54 iconName: "toolkit_input-search"
55 onTriggered: searchPage.state = "search"
56 }
57 },
58 PageHeadState {
59 id: headerState
60 name: "search"
61 head: searchPage.head
62 actions: [
63 Action {
64 iconName: "contact"
65 }
66 ]
67 backAction: Action {
68 id: leaveSearchAction
69 text: "back"
70 iconName: "back"
71 onTriggered: searchPage.state = "default"
72 }
73 contents: TextField {
74 placeholderText: "search..."
75 }
76 }
77 ]
78 }
79 }
80 \endqml
81 */
82 State {
83 id: state
84
85 /*!
86 The head property of the \l Page which will be the target of
87 the property changes of this State. This property must always
88 be set before the State can be used.
89 */
90 property PageHeadConfiguration head
91
92 /*!
93 The actions to be shown in the header with this state.
94 */
95 property list<Action> actions
96
97 /*!
98 The back action for this state.
99 */
100 property Action backAction
101
102 /*!
103 The contents of the header when this state is active.
104 */
105 property Item contents
106
107 PropertyChanges {
108 target: state.head
109 backAction: state.backAction
110 actions: state.actions
111 contents: state.contents
112 }
113 }