| 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 |
import QtQuick 2.4 |
| 17 |
import QtQuick.Window 2.2 |
| 18 |
import Lomiri.Components |
| 19 |
import Lomiri.Components.Styles 2.0 as Style |
| 20 |
|
| 21 |
Style.PageHeaderStyle { |
| 22 |
id: pageHeaderStyle |
| 23 |
|
| 24 |
foregroundColor: theme.palette.normal.backgroundText |
| 25 |
disabledForegroundColor: theme.palette.disabled.backgroundText |
| 26 |
subtitleColor: theme.palette.normal.backgroundTertiaryText |
| 27 |
backgroundColor: theme.palette.normal.background |
| 28 |
dividerColor: theme.palette.normal.base |
| 29 |
buttons { |
| 30 |
foregroundColor: pageHeaderStyle.foregroundColor |
| 31 |
disabledForegroundColor: pageHeaderStyle.disabledForegroundColor |
| 32 |
pressedForegroundColor: buttons.foregroundColor |
| 33 |
backgroundColor: "transparent" |
| 34 |
pressedBackgroundColor: theme.palette.highlighted.background |
| 35 |
disabledBackgroundColor: buttons.backgroundColor |
| 36 |
} |
| 37 |
|
| 38 |
// Font weight for the title and subtitle |
| 39 |
property int fontWeight: Font.Light |
| 40 |
|
| 41 |
// Text size for title |
| 42 |
property int textSize: Label.Large |
| 43 |
|
| 44 |
// Text size for subtitle |
| 45 |
property int subTextSize: internal.landscape ? Label.Small : Label.Medium |
| 46 |
|
| 47 |
contentHeight: internal.titleAreaHeight + internal.titleBottomSpacing |
| 48 |
implicitHeight: contentHeight + divider.height + internal.extensionHeight |
| 49 |
|
| 50 |
Component.onCompleted: internal.updateHeights() |
| 51 |
QtObject { |
| 52 |
id: internal |
| 53 |
property real extensionHeight: styledItem.extension |
| 54 |
? styledItem.extension.height |
| 55 |
: styledItem.sections.height |
| 56 |
|
| 57 |
property bool landscape: pageHeaderStyle.Screen.height <= units.gu(50) |
| 58 |
property bool hasSubtitle: styledItem.subtitle && !styledItem.contents |
| 59 |
property bool hasExtension: styledItem.extension |
| 60 |
|
| 61 |
// The height of the area in which the title and icons are vertically centered |
| 62 |
property real titleAreaHeight |
| 63 |
// Add to the content height for additional space under the title |
| 64 |
property real titleBottomSpacing |
| 65 |
|
| 66 |
onLandscapeChanged: updateHeights() |
| 67 |
onHasSubtitleChanged: updateHeights() |
| 68 |
onHasExtensionChanged: updateHeights() |
| 69 |
|
| 70 |
function updateHeights() { |
| 71 |
if (landscape) { |
| 72 |
if (hasSubtitle) { |
| 73 |
// with subtitle, and with or without extension |
| 74 |
titleAreaHeight = Qt.binding(function() { return units.gu(4) }); |
| 75 |
titleBottomSpacing = Qt.binding(function() { return units.gu(2) }); |
| 76 |
} else if (hasExtension) { |
| 77 |
titleAreaHeight = Qt.binding(function() { return units.gu(4) }); |
| 78 |
titleBottomSpacing = Qt.binding(function() { return units.gu(1) }); |
| 79 |
} else { |
| 80 |
titleAreaHeight = Qt.binding(function() { return units.gu(5) }); |
| 81 |
titleBottomSpacing = 0; |
| 82 |
} |
| 83 |
} else { // portrait |
| 84 |
titleAreaHeight = Qt.binding(function() { return units.gu(6) }); |
| 85 |
if (hasSubtitle) { |
| 86 |
titleBottomSpacing = Qt.binding(function() { return units.gu(1) }); |
| 87 |
} else { |
| 88 |
titleBottomSpacing = 0; |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
defaultActionDelegate: AbstractButton { |
| 95 |
id: button |
| 96 |
style: IconButtonStyle { } |
| 97 |
objectName: action.objectName + "_button" |
| 98 |
height: internal.titleAreaHeight |
| 99 |
action: modelData |
| 100 |
StyleHints { |
| 101 |
foregroundColor: button.pressed ? |
| 102 |
pageHeaderStyle.buttons.pressedForegroundColor : |
| 103 |
button.enabled ? |
| 104 |
pageHeaderStyle.buttons.foregroundColor : |
| 105 |
pageHeaderStyle.buttons.disabledForegroundColor |
| 106 |
backgroundColor: button.pressed ? |
| 107 |
pageHeaderStyle.buttons.pressedBackgroundColor : |
| 108 |
button.enabled ? |
| 109 |
pageHeaderStyle.buttons.backgroundColor : |
| 110 |
pageHeaderStyle.buttons.disabledBackgroundColor |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
titleComponent: Component { |
| 115 |
Item { |
| 116 |
// The wrapping inside the extra Item is needed to |
| 117 |
// be able to position the Label vertically. Without it, |
| 118 |
// the Loader resizes the Label to span the full height. |
| 119 |
Label { |
| 120 |
id: titleLabel |
| 121 |
objectName: "header_title_label" |
| 122 |
text: styledItem.title |
| 123 |
horizontalAlignment: Qt.application.layoutDirection == Qt.RightToLeft ? Text.AlignRight: Text.AlignLeft |
| 124 |
|
| 125 |
anchors { |
| 126 |
left: parent.left |
| 127 |
right: parent.right |
| 128 |
verticalCenter: parent.verticalCenter |
| 129 |
verticalCenterOffset: -internal.titleBottomSpacing/2 |
| 130 |
} |
| 131 |
color: pageHeaderStyle.foregroundColor |
| 132 |
font.weight: pageHeaderStyle.fontWeight |
| 133 |
textSize: pageHeaderStyle.textSize |
| 134 |
elide: Qt.application.layoutDirection == Qt.RightToLeft ? Text.ElideLeft: Text.ElideRight |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
subtitleComponent: Component { |
| 140 |
Item { |
| 141 |
// Item fills the contents height |
| 142 |
Label { |
| 143 |
anchors { |
| 144 |
left: parent.left |
| 145 |
right: parent.right |
| 146 |
baseline: parent.bottom |
| 147 |
baselineOffset: -units.gu(1) |
| 148 |
} |
| 149 |
objectName: "header_subtitle_label" |
| 150 |
text: styledItem.subtitle |
| 151 |
color: pageHeaderStyle.subtitleColor |
| 152 |
visible: text != "" |
| 153 |
textSize: pageHeaderStyle.subTextSize |
| 154 |
font.weight: pageHeaderStyle.fontWeight |
| 155 |
elide: Text.ElideRight |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
Rectangle { |
| 161 |
objectName: "header_background" |
| 162 |
anchors.fill: parent |
| 163 |
color: pageHeaderStyle.backgroundColor |
| 164 |
} |
| 165 |
|
| 166 |
Rectangle { |
| 167 |
id: divider |
| 168 |
objectName: "header_divider" |
| 169 |
anchors { |
| 170 |
left: parent.left |
| 171 |
right: parent.right |
| 172 |
bottom: parent.bottom |
| 173 |
} |
| 174 |
height: units.dp(1) |
| 175 |
color: pageHeaderStyle.dividerColor |
| 176 |
} |
| 177 |
} |