on xenial help sign in
Multiple icon/label support for indicators.

Approved by PS Jenkins bot, Daniel d'Andrada.

commitaee304ff64464e21ef09540c0489f2e8cf856e76 authorNick Dedekind <nicholas.dedekind@gmail.com> dateWed 4 Sep 2013, 01:34 (13 years ago) parent24765087e80e75
5 files changed+98−38
Panel/Indicators/DefaultIndicatorWidget.qml+1−1 Panel/Indicators/DefaultIndicatorWidget2.qml+43−16 Panel/Indicators/NetworkIndicatorWidget.qml+1−1 plugins/Unity/Indicators/rootactionstate.cpp+44−14 plugins/Unity/Indicators/rootactionstate.h+9−6
Panel/Indicators/DefaultIndicatorWidget.qml+1−1
@@ -24,7 +24,7 @@ import Unity.IndicatorsLegacy 0.1 as Indicators
2424Indicators.IndicatorWidget {
2525 id: indicatorWidget
2626
27− width: itemRow.width + units.gu(1)
27+ width: itemRow.width + units.gu(0.5)
2828
2929 property alias label: itemLabel.text
3030 property alias iconSource: itemImage.source
Panel/Indicators/DefaultIndicatorWidget2.qml+43−16
@@ -24,10 +24,11 @@ import Unity.Indicators 0.1 as Indicators
2424Indicators.IndicatorWidget {
2525 id: indicatorWidget
2626
27− width: itemRow.width + units.gu(1)
27+ width: itemRow.width + units.gu(0.5)
2828
29− property alias label: itemLabel.text
30− property alias iconSource: itemImage.source
29+ property alias leftLabel: itemLeftLabel.text
30+ property alias rightLabel: itemRightLabel.text
31+ property var icons: undefined
3132
3233 Row {
3334 id: itemRow
@@ -39,19 +40,43 @@ Indicators.IndicatorWidget {
3940 }
4041 spacing: units.gu(0.5)
4142
42− // FIXME : Should us Ubuntu.Icon . results in low res images
43− Image {
44− id: itemImage
45− objectName: "itemImage"
46− visible: source != ""
47− height: indicatorWidget.iconSize
48− width: indicatorWidget.iconSize
43+ Label {
44+ id: itemLeftLabel
45+ objectName: "leftLabel"
46+ color: Theme.palette.selected.backgroundText
47+ opacity: 0.8
48+ font.family: "Ubuntu"
49+ fontSize: "medium"
4950 anchors.verticalCenter: parent.verticalCenter
51+ visible: text != ""
52+ }
53+
54+ Row {
55+ width: childrenRect.width
56+ anchors {
57+ top: parent.top
58+ bottom: parent.bottom
59+ }
60+ spacing: units.gu(0.5)
61+
62+ Repeater {
63+ model: indicatorWidget.icons
64+
65+ Image {
66+ id: itemImage
67+ objectName: "itemImage"
68+ visible: source != ""
69+ source: modelData
70+ height: indicatorWidget.iconSize
71+ width: indicatorWidget.iconSize
72+ anchors.verticalCenter: parent.verticalCenter
73+ }
74+ }
5075 }
5176
5277 Label {
53− id: itemLabel
54− objectName: "itemLabel"
78+ id: itemRightLabel
79+ objectName: "rightLabel"
5580 color: Theme.palette.selected.backgroundText
5681 opacity: 0.8
5782 font.family: "Ubuntu"
@@ -63,14 +88,16 @@ Indicators.IndicatorWidget {
6388
6489 onActionStateChanged: {
6590 if (actionState == undefined) {
66− label = "";
67− iconSource = "";
91+ leftLabel = "";
92+ rightLabel = "";
93+ icons = undefined;
6894 enabled = false;
6995 return;
7096 }
7197
72− label = actionState.label;
73− iconSource = actionState.icon;
98+ leftLabel = actionState.leftLabel ? actionState.leftLabel : "";
99+ rightLabel = actionState.rightLabel ? actionState.rightLabel : "";
100+ icons = actionState.icons;
74101 enabled = actionState.visible;
75102 }
76103}
Panel/Indicators/NetworkIndicatorWidget.qml+1−1
@@ -24,7 +24,7 @@ import Unity.IndicatorsLegacy 0.1 as Indicators
2424Indicators.IndicatorWidget {
2525 id: indicatorWidget
2626
27− width: networkIcon.width + units.gu(1)
27+ width: networkIcon.width + units.gu(0.5)
2828
2929 property int signalStrength: 0
3030 property int connectionState: Indicators.NetworkConnection.Initial
plugins/Unity/Indicators/rootactionstate.cpp+44−14
@@ -108,25 +108,32 @@ bool RootActionState::isValid() const
108108 return m_menu && m_menu->rowCount() > 0;
109109}
110110
111−QString RootActionState::label() const
111+QString RootActionState::leftLabel() const
112112{
113113 if (!isValid()) return QString();
114114
115− return m_cachedState.value("label", QVariant::fromValue(QString())).toString();
115+ return m_cachedState.value("pre-label", QVariant::fromValue(QString())).toString();
116116}
117117
118−QString RootActionState::icon() const
118+QString RootActionState::rightLabel() const
119119{
120120 if (!isValid()) return QString();
121121
122− return m_cachedState.value("icon", QVariant::fromValue(QString())).toString();
122+ return m_cachedState.value("label", QVariant::fromValue(QString())).toString();
123+}
124+
125+QStringList RootActionState::icons() const
126+{
127+ if (!isValid()) return QStringList();
128+
129+ return m_cachedState.value("icons", QVariant::fromValue(QStringList())).toStringList();
123130}
124131
125132QString RootActionState::accessibleName() const
126133{
127134 if (!isValid()) return QString();
128135
129− return m_cachedState.value("accessible-name", QVariant::fromValue(QString())).toString();
136+ return m_cachedState.value("accessible-desc", QVariant::fromValue(QString())).toString();
130137}
131138
132139bool RootActionState::isVisible() const
@@ -198,16 +205,39 @@ QVariant RootActionState::toQVariant(GVariant* state) const
198205 while (g_variant_iter_loop (&iter, "{sv}", &key, &vvalue))
199206 {
200207 QString str = QString::fromUtf8(key);
201− if (str == "icon") {
208+ if (str == "icon" && !qmap.contains("icons")) {
209+ QStringList icons;
210+
202211 // FIXME - should be sending a url.
203− GIcon *icon = g_icon_deserialize (vvalue);
204− if (icon) {
205− qmap.insert(str, iconUri(icon));
206− g_object_unref (icon);
212+ GIcon *gicon = g_icon_deserialize (vvalue);
213+ if (gicon) {
214+ icons << iconUri(gicon);
215+ g_object_unref (gicon);
207216 }
208− else {
209− qmap.insert(str, QVariant(""));
217+ qmap.insert("icons", icons);
218+
219+ } else if (str == "icons") {
220+
221+ QStringList icons;
222+
223+ if (g_variant_type_is_array(g_variant_get_type(vvalue))) {
224+
225+
226+ for (int i = 0, iMax = g_variant_n_children(vvalue); i < iMax; i++) {
227+ GVariant *child = g_variant_get_child_value(vvalue, i);
228+
229+ // FIXME - should be sending a url.
230+ GIcon *gicon = g_icon_deserialize (child);
231+ if (gicon) {
232+ icons << iconUri(gicon);
233+ g_object_unref (gicon);
234+ }
235+ g_variant_unref(child);
236+ }
210237 }
238+ // will overwrite icon.
239+ qmap.insert("icons", icons);
240+
211241 } else {
212242 qmap.insert(str, ActionStateParser::toQVariant(vvalue));
213243 }
@@ -230,12 +260,12 @@ QVariant RootActionState::toQVariant(GVariant* state) const
230260 &visible);
231261
232262 qmap["label"] = label ? QString::fromUtf8(label) : "";
233− qmap["accessible-name"] = accessible_name ? QString::fromUtf8(accessible_name) : "";
263+ qmap["accessible-desc"] = accessible_name ? QString::fromUtf8(accessible_name) : "";
234264 qmap["visible"] = visible;
235265
236266 gicon = g_icon_new_for_string (icon, NULL);
237267 if (gicon) {
238− qmap["icon"] = iconUri(gicon);
268+ qmap["icons"] = QStringList() << iconUri(gicon);
239269 g_object_unref (gicon);
240270 }
241271
plugins/Unity/Indicators/rootactionstate.h+9−6
@@ -32,8 +32,9 @@ class UNITYINDICATORS_EXPORT RootActionState : public ActionStateParser
3232 Q_PROPERTY(UnityMenuModel* menu READ menu WRITE setMenu NOTIFY menuChanged)
3333
3434 Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
35− Q_PROPERTY(QString label READ label NOTIFY labelChanged)
36− Q_PROPERTY(QString icon READ icon NOTIFY iconChanged)
35+ Q_PROPERTY(QString leftLabel READ leftLabel NOTIFY leftLabelChanged)
36+ Q_PROPERTY(QString rightLabel READ rightLabel NOTIFY rightLabelChanged)
37+ Q_PROPERTY(QStringList icons READ icons NOTIFY iconsChanged)
3738 Q_PROPERTY(QString accessibleName READ accessibleName NOTIFY accessibleNameChanged)
3839 Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
3940public:
@@ -47,8 +48,9 @@ public:
4748 void setIndex(int index);
4849
4950 bool isValid() const;
50− QString label() const;
51− QString icon() const;
51+ QString leftLabel() const;
52+ QString rightLabel() const;
53+ QStringList icons() const;
5254 QString accessibleName() const;
5355 bool isVisible() const;
5456
@@ -62,8 +64,9 @@ Q_SIGNALS:
6264 void indexChanged();
6365
6466 void validChanged();
65− void labelChanged();
66− void iconChanged();
67+ void leftLabelChanged();
68+ void rightLabelChanged();
69+ void iconsChanged();
6770 void accessibleNameChanged();
6871 void visibleChanged();
6972