Debian Codegraph @

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

raw
1 /*
2 * Copyright 2013 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 * Author: Florian Boucault <[email protected]>
17 */
18
19 import QtQuick 2.4
20 import Lomiri.Components
21
22 Item {
23 id: buttonForeground
24
25 property alias text: label.text
26 property alias textColor: label.color
27 property alias iconSource: icon.source
28 property string iconPosition
29 property real iconSize
30 property real spacing
31 property bool hasIcon: iconSource.toString() !== ""
32 property bool hasText: text !== ""
33 property alias font: label.font
34
35 implicitHeight: Math.max(icon.height, label.height)
36 state: hasIcon && hasText ? iconPosition : "center"
37
38 Icon {
39 id: icon
40 visible: hasIcon
41 anchors.verticalCenter: parent.verticalCenter
42 width: iconSize
43 height: iconSize
44 color: label.color
45 }
46
47 Label {
48 id: label
49 anchors {
50 verticalCenter: parent.verticalCenter
51 verticalCenterOffset: units.dp(-1)
52 }
53 elide: Text.ElideRight
54 opacity: 1.0
55 }
56
57 states: [
58 State {
59 name: "left"
60 AnchorChanges {
61 target: icon
62 anchors.left: buttonForeground.left
63 }
64 AnchorChanges {
65 target: label
66 anchors.left: icon.right
67 }
68 PropertyChanges {
69 target: label
70 anchors.leftMargin: spacing
71 width: buttonForeground.width - icon.width - spacing
72 }
73 PropertyChanges {
74 target: buttonForeground
75 implicitWidth: icon.implicitWidth + spacing + label.implicitWidth
76 }
77 },
78 State {
79 name: "right"
80 AnchorChanges {
81 target: icon
82 anchors.right: buttonForeground.right
83 }
84 AnchorChanges {
85 target: label
86 anchors.left: buttonForeground.left
87 }
88 PropertyChanges {
89 target: label
90 width: buttonForeground.width - icon.width - spacing
91 }
92 PropertyChanges {
93 target: buttonForeground
94 implicitWidth: label.implicitWidth + spacing + icon.implicitWidth
95 }
96 },
97 State {
98 name: "center"
99 AnchorChanges {
100 target: icon
101 anchors.horizontalCenter: buttonForeground.horizontalCenter
102 }
103 AnchorChanges {
104 target: label
105 anchors.horizontalCenter: buttonForeground.horizontalCenter
106 }
107 PropertyChanges {
108 target: label
109 width: buttonForeground.width
110 horizontalAlignment: Text.AlignHCenter
111 }
112 PropertyChanges {
113 target: buttonForeground
114 implicitWidth: hasText ? label.implicitWidth : icon.implicitWidth
115 }
116 }
117 ]
118 }