Debian Codegraph @

src/imports/Components/Themes/Ambiance/2.0/PageHeadButton.qml

raw
1 /*
2 * Copyright 2015 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
19
20 // TODO: Remove this component when PageHeadStyle uses ActionBar
21 AbstractButton {
22 id: button
23
24 property real iconWidth: units.gu(2.5)
25 property real iconHeight: iconWidth
26
27 width: visible ? units.gu(5) : 0
28 height: parent ? parent.height : undefined
29
30 property alias color: icon.color
31
32 Rectangle {
33 visible: button.pressed
34 anchors.fill: parent
35 color: theme.palette.selected.background
36 }
37
38 Icon {
39 id: icon
40 anchors {
41 centerIn: parent
42 }
43 // prevent trying to render the icon with an invalid source
44 // when the button is invisible by setting width and height to 0
45 width: visible ? button.iconWidth : 0
46 height: visible ? button.iconHeight : 0
47 source: visible ? button.iconSource : ""
48 color: Qt.rgba(0, 0, 0, 0)
49 opacity: button.enabled ? 1.0 : 0.3
50 }
51
52 Component {
53 id: labelComponent
54 Label {
55 id: label
56 objectName: button.objectName + "_label"
57 color: button.color
58 opacity: button.enabled ? 1.0 : 0.3
59 text: button.text
60 textSize: Label.XxSmall
61 }
62 }
63 Loader {
64 anchors {
65 top: icon.bottom
66 topMargin: units.gu(0.5)
67 horizontalCenter: parent.horizontalCenter
68 }
69 sourceComponent: button.state === "IconAndLabel" ? labelComponent : null
70 }
71 }