@@ -0,0 +1,252 @@
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+ * Authors:
17+ * Nick Dedekind <nick.dedekind@canonical.com>
18+ */
19+
20+import QtQuick 2.1
21+import Ubuntu.Components 0.1
22+import Ubuntu.Settings.Components 0.1
23+import "../Indicators"
24+
25+IndicatorBase {
26+ id: root
27+
28+ property alias title: indicatorName.text
29+ property alias leftLabel: itemLeftLabel.text
30+ property alias rightLabel: itemRightLabel.text
31+ property var icons: undefined
32+ property bool expanded: false
33+ property bool selected: false
34+
35+ signal clicked()
36+
37+ width: mainItems.width
38+ enabled: false
39+
40+ MouseArea {
41+ anchors.fill: parent
42+ onClicked: parent.clicked()
43+ }
44+
45+ // FIXME: For now we will enable led indicator support only for messaging indicator
46+ // in the future we should export a led API insted of doing that,
47+ Loader {
48+ id: indicatorLed
49+ // only load source Component if the icons contains the new message icon
50+ source: (root.icons && (String(root.icons).indexOf("indicator-messages-new") != -1)) ? Qt.resolvedUrl("IndicatorsLight.qml") : ""
51+ }
52+
53+ Item {
54+ id: mainItems
55+ anchors.centerIn: parent
56+
57+ width: itemLeftLabel.width + iconsItem.width + itemRightLabel.width
58+ implicitHeight: units.gu(2)
59+
60+ Label {
61+ id: itemLeftLabel
62+ anchors {
63+ left: mainItems.left
64+ verticalCenter: parent.verticalCenter
65+ }
66+ width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
67+ horizontalAlignment: Text.AlignHCenter
68+
69+ objectName: "leftLabel"
70+ opacity: 0.8
71+ font.family: "Ubuntu"
72+ fontSize: "medium"
73+ color: {
74+ if (!expanded) return Theme.palette.normal.foregroundText;
75+ if (!selected) return Theme.palette.selected.backgroundText;
76+ return Theme.palette.normal.foregroundText;
77+ }
78+ Behavior on color { ColorAnimation{ duration: UbuntuAnimation.SnapDuration } }
79+ }
80+
81+ Item {
82+ id: iconsItem
83+ width: iconRow.width > 0 ? iconRow.width + units.gu(1) : 0
84+ anchors {
85+ left: itemLeftLabel.right
86+ verticalCenter: parent.verticalCenter
87+ }
88+
89+ Row {
90+ id: iconRow
91+ anchors.centerIn: iconsItem
92+ spacing: units.gu(1)
93+
94+ Repeater {
95+ id: iconRepeater
96+ model: d.useFallbackIcon ? [ "image://theme/settings" ] : root.icons
97+
98+ StatusIcon {
99+ id: itemImage
100+ height: units.gu(2)
101+ source: modelData
102+ sets: ["status", "actions"]
103+ color: {
104+ if (!expanded) return Theme.palette.normal.foregroundText;
105+ if (!selected) return Theme.palette.selected.backgroundText;
106+ return Theme.palette.normal.foregroundText;
107+ }
108+ Behavior on color { ColorAnimation{ duration: 1 } }
109+ }
110+ }
111+ }
112+ }
113+
114+ Label {
115+ id: itemRightLabel
116+ anchors {
117+ left: iconsItem.right
118+ verticalCenter: parent.verticalCenter
119+ }
120+ width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
121+ horizontalAlignment: Text.AlignHCenter
122+
123+ objectName: "rightLabel"
124+ opacity: 0.8
125+ font.family: "Ubuntu"
126+ fontSize: "medium"
127+ color: {
128+ if (!expanded) return Theme.palette.normal.foregroundText;
129+ if (!selected) return Theme.palette.selected.backgroundText;
130+ return Theme.palette.normal.foregroundText;
131+ }
132+ Behavior on color { ColorAnimation{ duration: UbuntuAnimation.SnapDuration } }
133+ }
134+ }
135+
136+ Label {
137+ id: indicatorName
138+
139+ anchors.top: mainItems.bottom
140+ anchors.topMargin: units.gu(0.5)
141+ anchors.horizontalCenter: parent.horizontalCenter
142+ width: contentWidth > 0 ? contentWidth + units.gu(1) : 0
143+
144+ text: rootActionState.title
145+ fontSize: "x-small"
146+ horizontalAlignment: Text.AlignHCenter
147+ opacity: 0
148+ color: {
149+ if (!expanded) return Theme.palette.normal.foregroundText;
150+ if (!selected) return Theme.palette.selected.backgroundText;
151+ return Theme.palette.normal.foregroundText;
152+ }
153+ Behavior on color { ColorAnimation{ duration: UbuntuAnimation.SnapDuration } }
154+ }
155+
156+ StateGroup {
157+ id: d
158+ property bool useFallbackIcon: false
159+
160+
161+ states: [
162+ State {
163+ name: "minimised"
164+ when: !expanded && ((icons && icons.length > 0) || leftLabel !== "" || rightLabel !== "")
165+ PropertyChanges { target: indicatorName; opacity: 0}
166+ },
167+
168+ State {
169+ name: "minimised_fallback"
170+ when: !expanded && (!icons || icons.length === 0) && leftLabel == "" && rightLabel == ""
171+ PropertyChanges { target: indicatorName; opacity: 0}
172+ PropertyChanges { target: d; useFallbackIcon: true }
173+ },
174+
175+ State {
176+ name: "expanded_icon"
177+ when: expanded && (icons && icons.length > 0)
178+ PropertyChanges { target: indicatorName; visible: true; opacity: 1}
179+ AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
180+ AnchorChanges { target: itemLeftLabel; anchors.left: undefined; anchors.right: iconsItem.left }
181+ PropertyChanges { target: itemLeftLabel; opacity: 0 }
182+ PropertyChanges { target: mainItems; width: Math.max(iconsItem.width, indicatorName.width); anchors.verticalCenterOffset: -units.gu(1) }
183+ PropertyChanges { target: itemLeftLabel; opacity: 0 }
184+ PropertyChanges { target: itemRightLabel; opacity: 0 }
185+ },
186+
187+ State {
188+ name: "expanded_fallback"
189+ when: expanded && (!icons || icons.length === 0) && leftLabel == "" && rightLabel == ""
190+ PropertyChanges { target: d; useFallbackIcon: true }
191+ PropertyChanges { target: indicatorName; visible: true; opacity: 1}
192+ AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
193+ AnchorChanges { target: itemLeftLabel; anchors.left: undefined; anchors.right: iconsItem.left }
194+ PropertyChanges { target: itemLeftLabel; opacity: 0 }
195+ PropertyChanges { target: mainItems; width: Math.max(iconsItem.width, indicatorName.width); anchors.verticalCenterOffset: -units.gu(1) }
196+ PropertyChanges { target: itemLeftLabel; opacity: 0 }
197+ PropertyChanges { target: itemRightLabel; opacity: 0 }
198+ },
199+
200+ State {
201+ name: "expanded_rightLabel"
202+ when: expanded && (!icons || icons.length === 0) && rightLabel !== ""
203+ PropertyChanges { target: indicatorName; visible: true; opacity: 1}
204+ AnchorChanges { target: itemRightLabel; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
205+ PropertyChanges { target: mainItems; width: Math.max(itemRightLabel.width, indicatorName.width); anchors.verticalCenterOffset: -units.gu(1) }
206+ PropertyChanges { target: iconsItem; opacity: 0 }
207+ PropertyChanges { target: itemLeftLabel; opacity: 0 }
208+ },
209+
210+ State {
211+ name: "expanded_leftLabel"
212+ when: expanded && (!icons || icons.length === 0) && leftLabel !== ""
213+ PropertyChanges { target: indicatorName; visible: true; opacity: 1}
214+ AnchorChanges { target: itemLeftLabel; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
215+ PropertyChanges { target: mainItems; width: Math.max(itemLeftLabel.width, indicatorName.width); anchors.verticalCenterOffset: -units.gu(1) }
216+ PropertyChanges { target: iconsItem; opacity: 0 }
217+ PropertyChanges { target: itemRightLabel; opacity: 0 }
218+ }
219+ ]
220+
221+ transitions: [
222+ Transition {
223+ PropertyAction { target: d; property: "useFallbackIcon"}
224+ AnchorAnimation {
225+ targets: [ mainItems, iconsItem, itemLeftLabel, itemRightLabel ]
226+ duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing
227+ }
228+ PropertyAnimation {
229+ targets: [ mainItems, iconsItem, itemLeftLabel, itemRightLabel, indicatorName ]
230+ properties: "width, opacity, anchors.verticalCenterOffset";
231+ duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing
232+ }
233+ }
234+ ]
235+ }
236+
237+ onRootActionStateChanged: {
238+ if (rootActionState == undefined) {
239+ leftLabel = "";
240+ rightLabel = "";
241+ icons = undefined;
242+ enabled = false;
243+ return;
244+ }
245+
246+ title = rootActionState.title ? rootActionState.title : "";
247+ leftLabel = rootActionState.leftLabel ? rootActionState.leftLabel : "";
248+ rightLabel = rootActionState.rightLabel ? rootActionState.rightLabel : "";
249+ icons = rootActionState.icons;
250+ enabled = rootActionState.visible;
251+ }
252+}