Unity 8
 All Classes Functions Properties
DefaultIndicatorWidget.qml
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.0
21 import Ubuntu.Components 0.1
22 import Ubuntu.Settings.Components 0.1
23 
24 IndicatorBase {
25  id: indicatorWidget
26 
27  property int iconSize: units.gu(2)
28  property alias leftLabel: itemLeftLabel.text
29  property alias rightLabel: itemRightLabel.text
30  property var icons: undefined
31 
32  width: itemRow.width
33  enabled: false
34 
35  // FIXME: For now we will enable led indicator support only for messaging indicator
36  // in the future we should export a led API insted of doing that,
37  Loader {
38  id: indicatorLed
39  // only load source Component if the icons contains the new message icon
40  source: (indicatorWidget.icons && (String(indicatorWidget.icons).indexOf("indicator-messages-new") != -1)) ? Qt.resolvedUrl("IndicatorsLight.qml") : ""
41  }
42 
43  Row {
44  id: itemRow
45  objectName: "itemRow"
46  anchors {
47  top: parent.top
48  bottom: parent.bottom
49  horizontalCenter: parent.horizontalCenter
50  }
51 
52  Label {
53  id: itemLeftLabel
54  width: contentWidth + units.gu(1)
55  objectName: "leftLabel"
56  color: Theme.palette.selected.backgroundText
57  opacity: 0.8
58  font.family: "Ubuntu"
59  fontSize: "medium"
60  anchors.verticalCenter: parent.verticalCenter
61  visible: text != ""
62  horizontalAlignment: Text.AlignHCenter
63  }
64 
65  Row {
66  anchors {
67  top: parent.top
68  bottom: parent.bottom
69  }
70 
71  Repeater {
72  model: indicatorWidget.icons
73 
74  Item {
75  width: itemImage.width + units.gu(1)
76  anchors { top: parent.top; bottom: parent.bottom }
77 
78  StatusIcon {
79  id: itemImage
80  height: indicatorWidget.iconSize
81  anchors.centerIn: parent
82  source: modelData
83  sets: ["status", "actions"]
84  color: "#CCCCCC"
85  }
86  }
87  }
88  }
89 
90  Label {
91  id: itemRightLabel
92  width: contentWidth + units.gu(1)
93  objectName: "rightLabel"
94  color: Theme.palette.selected.backgroundText
95  opacity: 0.8
96  font.family: "Ubuntu"
97  fontSize: "medium"
98  anchors.verticalCenter: parent.verticalCenter
99  visible: text != ""
100  horizontalAlignment: Text.AlignHCenter
101  }
102  }
103 
104  onRootActionStateChanged: {
105  if (rootActionState == undefined) {
106  leftLabel = "";
107  rightLabel = "";
108  icons = undefined;
109  enabled = false;
110  return;
111  }
112 
113  leftLabel = rootActionState.leftLabel ? rootActionState.leftLabel : "";
114  rightLabel = rootActionState.rightLabel ? rootActionState.rightLabel : "";
115  icons = rootActionState.icons;
116  enabled = rootActionState.visible;
117  }
118 }