Debian Codegraph @

src/imports/Components/2.0/Toolbar.qml

raw
1 /*
2 * Copyright 2016 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
19
20 // FIXME: In the example code below, replace the delegate
21 // by the new text button when it becomes available.
22 /*!
23 \qmltype Toolbar
24 \inqmlmodule Lomiri.Components
25 \ingroup lomiri
26 \brief Toolbar that can be used as an extension for the edit mode header.
27 Example:
28 \qml
29 PageHeader {
30 id: editHeader
31 property Component delegate: Component {
32 AbstractButton {
33 id: button
34 action: modelData
35 width: label.width + units.gu(4)
36 height: parent.height
37 Rectangle {
38 color: LomiriColors.slate
39 opacity: 0.1
40 anchors.fill: parent
41 visible: button.pressed
42 }
43 Label {
44 anchors.centerIn: parent
45 id: label
46 text: action.text
47 font.weight: text === "Confirm" ? Font.Normal : Font.Light
48 }
49 }
50 }
51
52 leadingActionBar {
53 anchors.leftMargin: 0
54 actions: Action {
55 text: "Cancel"
56 iconName: "close"
57 }
58 delegate: editHeader.delegate
59 }
60 trailingActionBar {
61 anchors.rightMargin: 0
62 actions: Action {
63 text: "Confirm"
64 iconName: "tick"
65 }
66 delegate: editHeader.delegate
67 }
68
69 extension: Toolbar {
70 anchors {
71 left: parent.left
72 right: parent.right
73 bottom: parent.bottom
74 }
75 trailingActionBar.actions: [
76 Action { iconName: "bookmark-new" },
77 Action { iconName: "add" },
78 Action { iconName: "edit-select-all" },
79 Action { iconName: "edit-copy" },
80 Action { iconName: "select" }
81 ]
82 leadingActionBar.actions: Action {
83 iconName: "delete"
84 text: "delete"
85 onTriggered: print("Delete action triggered")
86 }
87 }
88 }
89 \endqml
90 See \l PageHeader.
91 */
92 StyledItem {
93 id: toolbar
94 styleName: "ToolbarStyle"
95
96 /*!
97 \qmlproperty ActionBar leadingActionBar
98 The leading ActionBar that should hold at most one action.
99 Recommneded for the delete action.
100 Example:
101 \qml
102 Toolbar {
103 leadingActionBar.actions: [
104 Action {
105 iconName: "delete"
106 text: "Delete"
107 onTriggered: print("delete!")
108 }
109 ]
110 }
111 \endqml
112 See \l ActionBar.
113 */
114 readonly property alias leadingActionBar: leading
115 ActionBar {
116 id: leading
117 anchors {
118 left: parent.left
119 top: parent.top
120 bottom: parent.bottom
121 leftMargin: units.gu(1)
122 }
123 numberOfSlots: 1
124 delegate: toolbar.__styleInstance.defaultDelegate
125 Component.onCompleted: {
126 if (actions && actions.length > 1) {
127 print("WARNING: Toolbar with more than one leading actions is not supported.");
128 }
129 }
130 StyleHints {
131 backgroundColor: "transparent" // background is drawn by the toolbarStyle
132 buttons {
133 foregroundColor: toolbar.__styleInstance.buttons.foregroundColor
134 pressedForegroundColor: toolbar.__styleInstance.buttons.pressedForegroundColor
135 disabledForegroundColor: toolbar.__styleInstance.buttons.disabledForegroundColor
136 backgroundColor: toolbar.__styleInstance.buttons.backgroundColor
137 pressedBackgroundColor: toolbar.__styleInstance.buttons.pressedBackgroundColor
138 disabledBackgroundColor: toolbar.__styleInstance.buttons.disabledBackgroundColor
139 }
140 }
141 }
142
143 /*!
144 \qmlproperty ActionBar trailingActionBar
145 The \l ActionBar with trailing actions.
146 Example:
147 \qml
148 Toolbar {
149 trailingActionBar.actions: [
150 Action { iconName: "bookmark-new" },
151 Action { iconName: "add" },
152 Action { iconName: "edit-select-all" },
153 Action { iconName: "edit-copy" }
154 ]
155 }
156 \endqml
157 The trailing ActionBar may contain up to 8 actions.
158 Scrolling and support for more than 8 actions will be added in the near future.
159 See \l ActionBar.
160 */
161 readonly property alias trailingActionBar: trailing
162 ActionBar {
163 id: trailing
164 styleName: "ScrollingActionBarStyle"
165 anchors {
166 left: leading.right
167 right: parent.right
168 top: parent.top
169 bottom: parent.bottom
170 leftMargin: units.gu(1)
171 rightMargin: units.gu(1)
172 }
173 delegate: toolbar.__styleInstance.defaultDelegate
174 StyleHints {
175 backgroundColor: "transparent" // background is drawn by the toolbarStyle
176 buttons {
177 foregroundColor: toolbar.__styleInstance.buttons.foregroundColor
178 pressedForegroundColor: toolbar.__styleInstance.buttons.pressedForegroundColor
179 disabledForegroundColor: toolbar.__styleInstance.buttons.disabledForegroundColor
180 backgroundColor: toolbar.__styleInstance.buttons.backgroundColor
181 pressedBackgroundColor: toolbar.__styleInstance.buttons.pressedBackgroundColor
182 disabledBackgroundColor: toolbar.__styleInstance.buttons.disabledBackgroundColor
183 }
184 scrollButtons {
185 backgroundColor: toolbar.__styleInstance.backgroundColor // must be opaque to hide the icon buttons
186 }
187 }
188 }
189 }