on 551c708 help sign in
117 lines 3.3 kB history 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 * Authors:
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 */
20import QtQuick 2.0
21import Ubuntu.Components 0.1
22import Ubuntu.Components.ListItems 0.1 as ListItem
23import Unity.Indicators 0.1 as Indicators
25Indicators.BaseMenuItem {
26 id: menuItem
27 implicitHeight: units.gu(5.5)
29 property bool checked: false
30 property bool secure: false
31 property bool adHoc: false
32 property int signalStrength: 0
33 property alias label: _label.text
35 signal activate()
37 onCheckedChanged: {
38 // Can't rely on binding. Checked is assigned on click.
39 checkBoxActive.checked = checked;
40 }
42 onClicked: {
43 checkBoxActive.clicked();
44 }
46 CheckBox {
47 id: checkBoxActive
48 height: units.gu(3)
49 width: units.gu(3)
51 anchors {
52 left: parent.left
53 leftMargin: menuItem.__contentsMargins
54 verticalCenter: parent.verticalCenter
55 }
57 onClicked: {
58 menuItem.activate();
59 }
60 }
62 Image {
63 id: iconSignal
65 width: height
66 height: Math.min(units.gu(5), parent.height - units.gu(1))
67 anchors {
68 left: checkBoxActive.right
69 leftMargin: units.gu(1)
70 verticalCenter: parent.verticalCenter
71 }
73 source: {
74 var imageName = "nm-signal-100"
76 if (adHoc) {
77 imageName = "nm-adhoc";
78 } else if (signalStrength == 0) {
79 imageName = "nm-signal-00";
80 } else if (signalStrength <= 25) {
81 imageName = "nm-signal-25";
82 } else if (signalStrength <= 50) {
83 imageName = "nm-signal-50";
84 } else if (signalStrength <= 75) {
85 imageName = "nm-signal-75";
86 }
87 return "image://theme/" + imageName;
88 }
89 }
91 Label {
92 id: _label
93 anchors {
94 left: iconSignal.right
95 leftMargin: units.gu(1)
96 verticalCenter: parent.verticalCenter
97 right: iconSecure.visible ? iconSecure.left : parent.right
98 rightMargin: menuItem.__contentsMargins
99 }
100 elide: Text.ElideRight
101 opacity: label.enabled ? 1.0 : 0.5
102 }
104 Image {
105 id: iconSecure
106 visible: secure
107 source: "qrc:/indicators/artwork/network/secure.svg"
109 width: height
110 height: Math.min(units.gu(4), parent.height - units.gu(1))
111 anchors {
112 right: parent.right
113 rightMargin: units.gu(1)
114 verticalCenter: parent.verticalCenter
115 }
116 }