Debian Codegraph @

src/imports/Components/Themes/Ambiance/1.3/SheetForegroundStyle.qml

raw
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 import Lomiri.Components 1.3
19
20 Item {
21 id: visuals
22 // styling properties
23 property color backgroundColor: "lightgray"
24 property color headerColor: "darkgray"
25 property real headerHeight: units.gu(8)
26 property real buttonContainerWidth: units.gu(14)
27
28 implicitWidth: MathUtils.clamp(styledItem.contentsWidth, styledItem.minWidth, styledItem.maxWidth)
29 implicitHeight: header.height + containerItem.height
30
31 property alias contentItem: containerItem
32
33 Rectangle {
34 id: header
35 color: visuals.headerColor
36 height: visuals.headerHeight
37 anchors {
38 top: parent.top
39 left: parent.left
40 right: parent.right
41 }
42
43 Label {
44 id: headerText
45 anchors {
46 verticalCenter: parent.verticalCenter
47 left: leftButtonContainer.right
48 right: rightButtonContainer.left
49 }
50 width: headerText.implicitWidth + units.gu(4)
51 elide: Text.ElideRight
52 horizontalAlignment: Text.AlignHCenter
53 text: styledItem.title
54 }
55
56 Item {
57 id: leftButtonContainer
58 anchors {
59 left: parent.left
60 top: parent.top
61 bottom: parent.bottom
62 }
63 width: styledItem.leftButton ? visuals.buttonContainerWidth : 0
64 Component.onCompleted: header.updateButton(styledItem.leftButton, leftButtonContainer)
65 }
66
67 Item {
68 id: rightButtonContainer
69 anchors {
70 right: parent.right
71 top: parent.top
72 bottom: parent.bottom
73 }
74 width: styledItem.rightButton ? visuals.buttonContainerWidth : 0
75 Component.onCompleted: header.updateButton(styledItem.rightButton, rightButtonContainer)
76 }
77
78 function updateButton(button, container) {
79 if (!button) return;
80 button.parent = container;
81 button.anchors.left = container.left;
82 button.anchors.right = container.right;
83 button.anchors.verticalCenter = container.verticalCenter;
84 button.anchors.margins = Qt.binding(function() { return units.gu(1) });
85 }
86
87 Connections {
88 target: styledItem
89 function onLeftButtonChanged() { header.updateButton(styledItem.leftButton, leftButtonContainer) }
90 function onRightButtonChanged() { header.updateButton(styledItem.rightButton, rightButtonContainer) }
91 }
92 }
93
94 Rectangle {
95 id: containerItem
96 color: visuals.backgroundColor
97 height: MathUtils.clamp(styledItem.contentsHeight, styledItem.minHeight - header.height, styledItem.maxHeight - header.height)
98 anchors {
99 top: header.bottom
100 left: parent.left
101 right: parent.right
102 }
103 }
104 }