| 1 |
/* |
| 2 |
* Copyright (C) 2013 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 |
\internal |
| 22 |
\qmltype Toolbar |
| 23 |
\inqmlmodule Lomiri.Components |
| 24 |
\ingroup lomiri |
| 25 |
\brief Application toolbar. This class is not exposed because it will |
| 26 |
be automatically added when a Page defines tools. |
| 27 |
*/ |
| 28 |
Panel { |
| 29 |
id: toolbar |
| 30 |
anchors { |
| 31 |
left: parent ? parent.left : undefined |
| 32 |
right: parent ? parent.right : undefined |
| 33 |
bottom: parent ? parent.bottom : undefined |
| 34 |
} |
| 35 |
height: background.height |
| 36 |
|
| 37 |
LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft |
| 38 |
LayoutMirroring.childrenInherit: true |
| 39 |
|
| 40 |
// Closing of the toolbar on app contents interaction is handled by the Page. |
| 41 |
__closeOnContentsClicks: false |
| 42 |
|
| 43 |
// Open toolbar on hover (for desktop only) |
| 44 |
__openOnHover: true |
| 45 |
|
| 46 |
/*! |
| 47 |
The list of \l Actions to be shown on the toolbar |
| 48 |
*/ |
| 49 |
property Item tools: null |
| 50 |
|
| 51 |
hideTimeout: 5000 |
| 52 |
|
| 53 |
/*! \internal */ |
| 54 |
onToolsChanged: { |
| 55 |
internal.updateVisibleTools(); |
| 56 |
if (tools) { |
| 57 |
if (tools && tools.hasOwnProperty("locked")) locked = tools.locked; |
| 58 |
// open the toolbar, except when it is locked in closed position |
| 59 |
if (tools && tools.hasOwnProperty("locked") && tools.hasOwnProperty("opened") |
| 60 |
&& !tools.opened && tools.locked) { |
| 61 |
// toolbar is locked in closed state |
| 62 |
toolbar.close(); |
| 63 |
} else { |
| 64 |
toolbar.open(); |
| 65 |
} |
| 66 |
|
| 67 |
if (tools && tools.hasOwnProperty("opened")) { |
| 68 |
tools.opened = toolbar.opened; |
| 69 |
} |
| 70 |
} else { // no tools |
| 71 |
locked = true; |
| 72 |
toolbar.close(); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
// if tools is not specified, lock the toolbar in closed position |
| 77 |
locked: tools && tools.hasOwnProperty("locked") ? tools.locked : false |
| 78 |
|
| 79 |
onOpenedChanged: { |
| 80 |
if (tools && tools.hasOwnProperty("opened")) { |
| 81 |
tools.opened = toolbar.opened; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
Connections { |
| 86 |
target: tools |
| 87 |
ignoreUnknownSignals: true |
| 88 |
function onOpenedChanged() { |
| 89 |
if (!tools) // Can happen due to signal emision order |
| 90 |
return; |
| 91 |
|
| 92 |
if (tools.opened) { |
| 93 |
toolbar.open(); |
| 94 |
} else { |
| 95 |
toolbar.close(); |
| 96 |
} |
| 97 |
} |
| 98 |
function onLockedChanged() { |
| 99 |
if (!tools) // Can happen due to signal emision order |
| 100 |
return; |
| 101 |
|
| 102 |
toolbar.locked = tools.locked; |
| 103 |
// open the toolbar when it becomes unlocked |
| 104 |
// (may be because a new page was pushed to the page stack) |
| 105 |
if (!toolbar.locked) toolbar.open(); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
QtObject { |
| 110 |
id: internal |
| 111 |
property Item visibleTools: tools |
| 112 |
function updateVisibleTools() { |
| 113 |
if (internal.visibleTools !== toolbar.tools) { |
| 114 |
if (internal.visibleTools) internal.visibleTools.parent = null; |
| 115 |
internal.visibleTools = toolbar.tools; |
| 116 |
} |
| 117 |
if (internal.visibleTools) internal.visibleTools.parent = visibleToolsContainer; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
onAnimatingChanged: { |
| 122 |
if (!animating && !opened) { |
| 123 |
internal.updateVisibleTools(); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
StyledItem { |
| 128 |
// FIXME: |
| 129 |
// All theming items go into the background because only the children |
| 130 |
// of the Panel are being shown/hidden while the toolbar |
| 131 |
// itself may stay in place. |
| 132 |
id: background |
| 133 |
anchors { |
| 134 |
left: parent.left |
| 135 |
right: parent.right |
| 136 |
bottom: parent.bottom |
| 137 |
} |
| 138 |
height: units.gu(8) |
| 139 |
|
| 140 |
// The values of opened and animated properties are used in the style |
| 141 |
property bool opened: toolbar.opened |
| 142 |
property bool animating: toolbar.animating |
| 143 |
|
| 144 |
style: Theme.createStyleComponent("DeprecatedToolbarStyle.qml", background) |
| 145 |
} |
| 146 |
|
| 147 |
Item { |
| 148 |
id: visibleToolsContainer |
| 149 |
anchors { |
| 150 |
fill: background |
| 151 |
} |
| 152 |
} |
| 153 |
} |