Debian Codegraph @

src/imports/Components/Themes/Ambiance/1.3/IconButtonStyle.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
17 import QtQuick 2.4
18 import Lomiri.Components 1.3
19
20 Item {
21 id: iconButtonStyle
22
23 implicitWidth: units.gu(4)
24 implicitHeight: units.gu(4)
25
26 /*!
27 The color of the icons.
28 */
29 property color foregroundColor: styledItem.enabled
30 ? theme.palette.normal.backgroundText
31 : theme.palette.disabled.backgroundText
32
33 /*!
34 The background color of the button.
35 */
36 property color backgroundColor: styledItem.pressed ?
37 theme.palette.highlighted.background :
38 "transparent"
39
40 property real iconWidth: units.gu(2)
41 property real iconHeight: iconWidth
42
43 /*!
44 Show a text label under the icon.
45 */
46 property bool showLabel: false
47
48 Rectangle {
49 id: background
50 color: iconButtonStyle.backgroundColor
51 anchors.fill: parent
52 }
53
54 Icon {
55 id: icon
56 anchors.centerIn: parent
57 width: iconButtonStyle.iconWidth
58 height: iconButtonStyle.iconHeight
59 source: styledItem.iconSource
60 color: iconButtonStyle.foregroundColor
61
62 FocusShape {
63 }
64 }
65
66 Component {
67 id: labelComponent
68 Label {
69 objectName: styledItem.objectName + "_label"
70 color: iconButtonStyle.foregroundColor
71 text: styledItem.text
72 textSize: Label.XxSmall
73 }
74 }
75 Loader {
76 anchors {
77 top: icon.bottom
78 topMargin: units.gu(0.5)
79 horizontalCenter: parent.horizontalCenter
80 }
81 sourceComponent: iconButtonStyle.showLabel ? labelComponent : null
82 }
83 }