Debian Codegraph @

src/imports/Components/Themes/Ambiance/2.0/SectionsForPageHeadStyle.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 Lomiri.Components
18
19 Item {
20 id: sectionsStyle
21
22 implicitWidth: sectionsRow.width
23 implicitHeight: units.gu(4)
24
25 enabled: styledItem.enabled
26
27 /*!
28 The foreground color of unselected sections.
29 */
30 property color sectionColor: enabled
31 ? theme.palette.normal.backgroundTertiaryText
32 : theme.palette.disabled.backgroundTertiaryText
33
34 /*!
35 The foreground color of the selected section.
36 */
37 property color selectedSectionColor: enabled
38 ? theme.palette.selected.positionText
39 : theme.palette.selectedDisabled.positionText
40
41 /*!
42 The background color for the pressed section button.
43 */
44 property color pressedBackgroundColor: theme.palette.highlighted.background
45
46 /*!
47 The font size for the text in the buttons.
48 */
49 property int textSize: Label.Small
50
51 /*!
52 The spacing on the left and right sides of the label
53 inside a section button.
54 */
55 property real horizontalLabelSpacing: units.gu(2)
56
57 /*!
58 The height of the bar underlining the sections.
59 */
60 property real underlineHeight: units.dp(2)
61
62 Row {
63 id: sectionsRow
64 anchors {
65 top: parent.top
66 bottom: parent.bottom
67 horizontalCenter: parent.horizontalCenter
68 }
69 width: childrenRect.width
70
71 Repeater {
72 id: sectionsRepeater
73 model: styledItem.model
74 objectName: "sections_repeater"
75 AbstractButton {
76 id: sectionButton
77 anchors {
78 top: parent ? parent.top : undefined
79 bottom: parent ? parent.bottom : undefined
80 }
81 objectName: "section_button_" + index
82 width: label.width + 2 * sectionsStyle.horizontalLabelSpacing
83 height: sectionsRow.height
84 property bool selected: index === styledItem.selectedIndex
85 onClicked: styledItem.selectedIndex = index
86
87 // Background pressed highlight
88 Rectangle {
89 visible: parent.pressed
90 anchors.fill: parent
91 color: sectionsStyle.pressedBackgroundColor
92 }
93
94 // Section title
95 Label {
96 id: label
97 objectName: "section_button_label_" + index
98 // modelData may be either a string, or an Action
99 text: modelData.hasOwnProperty("text") ? modelData.text : modelData
100 textSize: sectionsStyle.textSize
101 anchors.centerIn: parent
102 color: sectionButton.selected ?
103 sectionsStyle.selectedSectionColor :
104 sectionsStyle.sectionColor
105 }
106
107 // Section title underline
108 Rectangle {
109 anchors {
110 bottom: parent.bottom
111 left: parent.left
112 right: parent.right
113 }
114 height: sectionsStyle.underlineHeight
115 color: sectionButton.selected ?
116 sectionsStyle.selectedSectionColor :
117 sectionsStyle.sectionColor
118 }
119 }
120 }
121 }
122 }