| 1 |
/* |
| 2 |
* Copyright 2012 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 |
|
| 19 |
/*! |
| 20 |
\qmltype ToolbarItems |
| 21 |
\inqmlmodule Lomiri.Components |
| 22 |
\ingroup lomiri |
| 23 |
\deprecated |
| 24 |
\brief Row of Items to be placed in a toolbar. |
| 25 |
|
| 26 |
\b DEPRECATED: DO NOT USE THIS. USE \b head.actions IN \l Page INSTEAD. |
| 27 |
\deprecated |
| 28 |
|
| 29 |
Each \l Page has a tools property that can be set to change the tools of toolbar supplied |
| 30 |
by \l MainView when the \l Page is active. Each ToolbarItems consists of a set of |
| 31 |
Items and several properties that specify the behavior of the toolbar when the \l Page |
| 32 |
is active. |
| 33 |
|
| 34 |
When a \l Page is used inside a \l MainView, \l Tabs or \l PageStack, the toolbar will automatically show |
| 35 |
the tools of the active \l Page. When the active \l Page inside the \l Tabs or \l PageStack |
| 36 |
is updated by changing the selected \l Tab or by pushing/popping a \l Page on the \l PageStack, |
| 37 |
the toolbar will automatically hide, except if the new active \l Page has the \l locked property set. |
| 38 |
|
| 39 |
It is recommended to use \l ToolbarButton inside the ToolbarItems to define the buttons that will |
| 40 |
be visible to the user: |
| 41 |
\qml |
| 42 |
import QtQuick 2.4 |
| 43 |
import Lomiri.Components 1.3 |
| 44 |
|
| 45 |
MainView { |
| 46 |
width: units.gu(50) |
| 47 |
height: units.gu(50) |
| 48 |
|
| 49 |
Page { |
| 50 |
title: "Tools example" |
| 51 |
Label { |
| 52 |
anchors.centerIn: parent |
| 53 |
text: "Custom back button\nToolbar locked" |
| 54 |
} |
| 55 |
tools: ToolbarItems { |
| 56 |
ToolbarButton { |
| 57 |
action: Action { |
| 58 |
text: "button" |
| 59 |
iconName: "compose" |
| 60 |
onTriggered: print("success!") |
| 61 |
} |
| 62 |
} |
| 63 |
locked: true |
| 64 |
opened: true |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
\endqml |
| 69 |
|
| 70 |
However, it is possible to include non-\l ToolbarButton Items inside ToolbarItems, and to mix |
| 71 |
ToolbarButtons and other Items (for example standard Buttons). ToolbarButtons automatically span |
| 72 |
the full height of the toolbar, and other Items you will probably want to center vertically: |
| 73 |
\qml |
| 74 |
import QtQuick 2.4 |
| 75 |
import Lomiri.Components 1.3 |
| 76 |
|
| 77 |
MainView { |
| 78 |
width: units.gu(50) |
| 79 |
height: units.gu(50) |
| 80 |
|
| 81 |
Page { |
| 82 |
title: "Tools example" |
| 83 |
Label { |
| 84 |
anchors.centerIn: parent |
| 85 |
text: "buttons!" |
| 86 |
} |
| 87 |
tools: ToolbarItems { |
| 88 |
ToolbarButton { |
| 89 |
action: Action { |
| 90 |
text: "toolbar" |
| 91 |
iconName: "compose" |
| 92 |
onTriggered: print("success!") |
| 93 |
} |
| 94 |
} |
| 95 |
Button { |
| 96 |
anchors.verticalCenter: parent.verticalCenter |
| 97 |
text: "standard" |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
\endqml |
| 103 |
*/ |
| 104 |
Item { |
| 105 |
id: toolbarItems |
| 106 |
anchors.fill: parent |
| 107 |
|
| 108 |
/*! |
| 109 |
Default property, holds the content which will shown in the toolbar. |
| 110 |
\qmlproperty list<Object> contents |
| 111 |
*/ |
| 112 |
default property alias contents: toolsContainer.data |
| 113 |
|
| 114 |
/*! |
| 115 |
The back button. If it is visible, it will be shown on the left-side of the toolbar. |
| 116 |
If there is a \l PageStack with depth greater than 1, the back button will be |
| 117 |
visible and triggering it will pop the page on top of the stack. If there is no |
| 118 |
\l PageStack with depth greater than 1, the back button is hidden by default |
| 119 |
|
| 120 |
The following example shows how to have a classic cancel button that is always |
| 121 |
visible in the toolbar, instead of the default toolbar-styled back button: |
| 122 |
\qml |
| 123 |
import QtQuick 2.4 |
| 124 |
import Lomiri.Components 1.3 |
| 125 |
|
| 126 |
MainView { |
| 127 |
width: units.gu(50) |
| 128 |
height: units.gu(50) |
| 129 |
|
| 130 |
Page { |
| 131 |
title: "Custom back button" |
| 132 |
tools: ToolbarItems { |
| 133 |
back: Button { |
| 134 |
text: "cancel" |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
} |
| 139 |
\endqml |
| 140 |
*/ |
| 141 |
property Item back: ToolbarButton { |
| 142 |
objectName: "back_toolbar_button" |
| 143 |
iconSource: Qt.resolvedUrl("../artwork/back.png") |
| 144 |
text: i18n.dtr('lomiri-ui-toolkit', "Back") |
| 145 |
visible: toolbarItems.pageStack && toolbarItems.pageStack.depth > 1 |
| 146 |
/*! |
| 147 |
If there is a \l PageStack of sufficient depth, triggering the back button |
| 148 |
will pop the \l Page on top of the \l PageStack. |
| 149 |
*/ |
| 150 |
onTriggered: if (toolbarItems.pageStack && toolbarItems.pageStack.depth > 1) toolbarItems.pageStack.pop() |
| 151 |
} |
| 152 |
|
| 153 |
/*! |
| 154 |
PageStack for the back button. \l Page will automatically set the pageStack property |
| 155 |
of its tools. |
| 156 |
*/ |
| 157 |
property Item pageStack: null |
| 158 |
|
| 159 |
/*! |
| 160 |
The toolbar is opened. |
| 161 |
When the toolbar is not locked, this value is automatically updated |
| 162 |
when the toolbar is opened/closed by user interaction or by other events (such as changing |
| 163 |
the active \l Page). |
| 164 |
*/ |
| 165 |
property bool opened: false |
| 166 |
|
| 167 |
/*! |
| 168 |
The toolbar cannot be opened/closed by bottom-edge swipes. |
| 169 |
If the ToolbarItems contains no visible Items, it is automatically |
| 170 |
locked (in closed state). |
| 171 |
*/ |
| 172 |
property bool locked: !internal.hasVisibleItems() |
| 173 |
|
| 174 |
QtObject { |
| 175 |
id: internal |
| 176 |
/* |
| 177 |
Determine whether this ToolbarItems has any visible Items |
| 178 |
*/ |
| 179 |
function hasVisibleItems() { |
| 180 |
if (back && back.visible) return true; |
| 181 |
for (var i=0; i < toolsContainer.children.length; i++) { |
| 182 |
if (toolsContainer.children[i].visible) return true; |
| 183 |
} |
| 184 |
return false; |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
Item { |
| 189 |
id: backContainer |
| 190 |
anchors { |
| 191 |
left: parent.left |
| 192 |
top: parent.top |
| 193 |
bottom: parent.bottom |
| 194 |
leftMargin: units.gu(2) |
| 195 |
} |
| 196 |
width: childrenRect.width |
| 197 |
|
| 198 |
// internal link to the previous back Item to unset its parent |
| 199 |
// when toolbarItems.back is updated. |
| 200 |
property Item previousBackItem: null |
| 201 |
|
| 202 |
function updateBackItem() { |
| 203 |
if (backContainer.previousBackItem) backContainer.previousBackItem.parent = null; |
| 204 |
backContainer.previousBackItem = toolbarItems.back; |
| 205 |
if (toolbarItems.back) toolbarItems.back.parent = backContainer; |
| 206 |
} |
| 207 |
|
| 208 |
Connections { |
| 209 |
target: toolbarItems |
| 210 |
function onBackChanged() { backContainer.updateBackItem() } |
| 211 |
Component.onCompleted: backContainer.updateBackItem() |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
Row { |
| 216 |
id: toolsContainer |
| 217 |
anchors { |
| 218 |
right: parent.right |
| 219 |
bottom: parent.bottom |
| 220 |
top: parent.top |
| 221 |
rightMargin: units.gu(2) |
| 222 |
} |
| 223 |
spacing: units.gu(1) |
| 224 |
} |
| 225 |
} |