on xenial help sign in
Align icons/labels to gu. Preserve icon aspect.
commit994a5f87f68b9dab3ffbe3800298e02ab230a8c4 authorNick Dedekind <nicholas.dedekind@gmail.com> dateWed 16 Oct 2013, 11:50 (13 years ago) parenta2059d1
2 files changed+32−11
Panel/Indicators/DefaultIndicatorWidget.qml+31−10 plugins/Unity/Indicators/qml/IndicatorWidget.qml+1−1
Panel/Indicators/DefaultIndicatorWidget.qml+31−10
@@ -24,7 +24,7 @@ import Unity.Indicators 0.1 as Indicators
2424Indicators.IndicatorWidget {
2525 id: indicatorWidget
2626
27− width: itemRow.width + units.gu(0.5)
27+ width: itemRow.width
2828
2929 property alias leftLabel: itemLeftLabel.text
3030 property alias rightLabel: itemRightLabel.text
@@ -32,16 +32,17 @@ Indicators.IndicatorWidget {
3232
3333 Row {
3434 id: itemRow
35+ width: childrenRect.width
3536 objectName: "itemRow"
3637 anchors {
3738 top: parent.top
3839 bottom: parent.bottom
3940 horizontalCenter: parent.horizontalCenter
4041 }
41− spacing: units.gu(0.5)
4242
4343 Label {
4444 id: itemLeftLabel
45+ width: guRoundUp(implicitWidth)
4546 objectName: "leftLabel"
4647 color: Theme.palette.selected.backgroundText
4748 opacity: 0.8
@@ -57,25 +58,35 @@ Indicators.IndicatorWidget {
5758 top: parent.top
5859 bottom: parent.bottom
5960 }
60− spacing: units.gu(0.5)
6161
6262 Repeater {
6363 model: indicatorWidget.icons
6464
65− Image {
66− id: itemImage
67− objectName: "itemImage"
68− visible: source != ""
69− source: modelData
65+ Item {
66+ width: guRoundUp(itemImage.width)
7067 height: indicatorWidget.iconSize
71− width: indicatorWidget.iconSize
72− anchors.verticalCenter: parent.verticalCenter
68+
69+ Image {
70+ id: itemImage
71+ objectName: "itemImage"
72+ visible: source != ""
73+ source: modelData
74+ height: parent.height
75+ anchors.horizontalCenter: parent.horizontalCenter
76+ fillMode: Image.PreserveAspectFit
77+
78+ sourceSize {
79+ width: indicatorWidget.iconSize
80+ height: indicatorWidget.iconSize
81+ }
82+ }
7383 }
7484 }
7585 }
7686
7787 Label {
7888 id: itemRightLabel
89+ width: guRoundUp(implicitWidth)
7990 objectName: "rightLabel"
8091 color: Theme.palette.selected.backgroundText
8192 opacity: 0.8
@@ -86,6 +97,16 @@ Indicators.IndicatorWidget {
8697 }
8798 }
8899
100+ function guRoundUp(width) {
101+ if (width == 0) {
102+ return 0;
103+ }
104+ var gu1 = units.gu(1.0);
105+ var mod = (width % gu1);
106+
107+ return mod == 0 ? width : width + (gu1 - mod);
108+ }
109+
89110 onRootActionStateChanged: {
90111 if (rootActionState == undefined) {
91112 leftLabel = "";
plugins/Unity/Indicators/qml/IndicatorWidget.qml+1−1
@@ -24,5 +24,5 @@ IndicatorBase {
2424 id: indicatorWidget
2525
2626 enabled: false
27− property int iconSize: height - units.gu(0.5)
27+ property int iconSize: height
2828}