Debian Codegraph @

src/imports/Components/Themes/Ambiance/1.3/PageHeaderStyle.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 import QtQuick 2.4
17 import QtQuick.Window 2.2
18 import Lomiri.Components 1.3
19 import Lomiri.Components.Styles 1.3 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 activeFocusOnTab: true
101 StyleHints {
102 foregroundColor: button.pressed ?
103 pageHeaderStyle.buttons.pressedForegroundColor :
104 button.enabled ?
105 pageHeaderStyle.buttons.foregroundColor :
106 pageHeaderStyle.buttons.disabledForegroundColor
107 backgroundColor: button.pressed ?
108 pageHeaderStyle.buttons.pressedBackgroundColor :
109 button.enabled ?
110 pageHeaderStyle.buttons.backgroundColor :
111 pageHeaderStyle.buttons.disabledBackgroundColor
112 }
113 }
114
115 titleComponent: Component {
116 Item {
117 // The wrapping inside the extra Item is needed to
118 // be able to position the Label vertically. Without it,
119 // the Loader resizes the Label to span the full height.
120 Label {
121 id: titleLabel
122 objectName: "header_title_label"
123 text: styledItem.title
124 horizontalAlignment: Qt.application.layoutDirection == Qt.RightToLeft ? Text.AlignRight: Text.AlignLeft
125
126 anchors {
127 left: parent.left
128 right: parent.right
129 verticalCenter: parent.verticalCenter
130 verticalCenterOffset: -internal.titleBottomSpacing/2
131 }
132 color: pageHeaderStyle.foregroundColor
133 font.weight: pageHeaderStyle.fontWeight
134 textSize: pageHeaderStyle.textSize
135 elide: Qt.application.layoutDirection == Qt.RightToLeft ? Text.ElideLeft: Text.ElideRight
136 }
137 }
138 }
139
140 subtitleComponent: Component {
141 Item {
142 // Item fills the contents height
143 Label {
144 anchors {
145 left: parent.left
146 right: parent.right
147 baseline: parent.bottom
148 baselineOffset: -units.gu(1)
149 }
150 objectName: "header_subtitle_label"
151 text: styledItem.subtitle
152 color: pageHeaderStyle.subtitleColor
153 visible: text != ""
154 textSize: pageHeaderStyle.subTextSize
155 font.weight: pageHeaderStyle.fontWeight
156 elide: Text.ElideRight
157 }
158 }
159 }
160
161 Rectangle {
162 objectName: "header_background"
163 anchors.fill: parent
164 color: pageHeaderStyle.backgroundColor
165 }
166
167 Rectangle {
168 id: divider
169 objectName: "header_divider"
170 anchors {
171 left: parent.left
172 right: parent.right
173 bottom: parent.bottom
174 }
175 height: units.dp(1)
176 color: pageHeaderStyle.dividerColor
177 }
178 }