on xenial help sign in
added support for count emblems and progress overlays
commita8c472ca512f6cd781c68ca82c7bd60b19437152 authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 19 Aug 2013, 21:34 (13 years ago) parentfc62c98
11 files changed+122−3
Launcher/LauncherDelegate.qml+55 Launcher/LauncherPanel.qml+2 Launcher/graphics/notification@30.png Launcher/graphics/notification@30.sci+5 Launcher/graphics/progressbar-fill@30.png Launcher/graphics/progressbar-fill@30.sci+5 Launcher/graphics/progressbar-trough@30.png Launcher/graphics/progressbar-trough@30.sci+5 tests/mocks/Unity/Launcher/MockLauncherItem.cpp+2−2 tests/mocks/Unity/Launcher/MockLauncherModel.cpp+32−1 tests/qmltests/Launcher/tst_Launcher.qml+16
Launcher/LauncherDelegate.qml+55
@@ -21,6 +21,8 @@ Item {
2121 id: root
2222
2323 property string iconName
24+ property int count: -1
25+ property int progress: -1
2426
2527 property bool highlighted: false
2628 property real maxAngle: 0
@@ -70,6 +72,59 @@ Item {
7072 property bool isSelected: root.highlighted
7173 onIsSelectedChanged: shaderEffectSource.scheduleUpdate();
7274 }
75+
76+ BorderImage {
77+ objectName: "countEmblem"
78+ anchors {
79+ left: parent.left
80+ top: parent.top
81+ }
82+ width: Math.min(units.gu(7.5), Math.max(units.gu(4), countLabel.implicitWidth + units.gu(2)))
83+ height: units.gu(4)
84+ source: "graphics/notification@30.sci"
85+ visible: root.count > 0
86+
87+ Label {
88+ id: countLabel
89+ text: root.count
90+ anchors{
91+ left: parent.left
92+ right: parent.right
93+ margins: units.gu(0.5)
94+ verticalCenter: parent.verticalCenter
95+ }
96+ horizontalAlignment: Text.AlignHCenter
97+ elide: Text.ElideRight
98+ color: "white"
99+ }
100+ }
101+
102+ BorderImage {
103+ objectName: "progressOverlay"
104+ anchors {
105+ left: parent.left
106+ right: parent.right
107+ bottom: parent.bottom
108+ margins: units.dp(3)
109+ }
110+ visible: root.progress > -1
111+ source: "graphics/progressbar-trough@30.sci"
112+
113+ // For fill calculation we need to remove the 3 units of border defined in .sci file
114+ property int adjustedWidth: width - units.gu(3)
115+
116+ BorderImage {
117+ anchors {
118+ fill: parent
119+ rightMargin: parent.adjustedWidth - (Math.min(100, root.progress) * parent.adjustedWidth / 100)
120+ }
121+ source: "graphics/progressbar-fill@30.sci"
122+
123+ // Because of the borders in the borderimage we can't make it smaller than 10%
124+ // Let's just fade in from 0 to 10% instead and then fill the bar.
125+ opacity: root.progress / 10
126+ }
127+ }
73128 }
74129
75130 ShaderEffect {
Launcher/LauncherPanel.qml+2
@@ -131,6 +131,8 @@ Item {
131131 width: itemWidth
132132 height: itemHeight
133133 iconName: model.icon
134+ count: model.count
135+ progress: model.progress
134136 inverted: root.inverted
135137 highlighted: dragging && index === root.highlightIndex
136138 z: -Math.abs(offset)
Launcher/graphics/notification@30.pngnew file

Binary file not shown.

Launcher/graphics/notification@30.scinew file+5
@@ -0,0 +1,5 @@
1+border.left: 36
2+border.top: 36
3+border.bottom: 36
4+border.right: 36
5+source: notification@30.png
Launcher/graphics/progressbar-fill@30.pngnew file

Binary file not shown.

Launcher/graphics/progressbar-fill@30.scinew file+5
@@ -0,0 +1,5 @@
1+border.left: 36
2+border.top: 16
3+border.bottom: 28
4+border.right: 36
5+source: progressbar-fill@30.png
Launcher/graphics/progressbar-trough@30.pngnew file

Binary file not shown.

Launcher/graphics/progressbar-trough@30.scinew file+5
@@ -0,0 +1,5 @@
1+border.left: 36
2+border.top: 16
3+border.bottom: 26
4+border.right: 36
5+source: progressbar-trough@30.png
tests/mocks/Unity/Launcher/MockLauncherItem.cpp+2−2
@@ -31,8 +31,8 @@ MockLauncherItem::MockLauncherItem(const QString &appId, const QString& desktopF
3131 m_pinned(false),
3232 m_running(false),
3333 m_recent(false),
34− m_progress(8),
35− m_count(8),
34+ m_progress(-1),
35+ m_count(0),
3636 m_quickList(new MockQuickListModel(this))
3737{
3838
tests/mocks/Unity/Launcher/MockLauncherModel.cpp+32−1
@@ -25,22 +25,33 @@ MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(pa
2525 MockLauncherItem *item = new MockLauncherItem("phone-app", "/usr/share/applications/phone-app.desktop", "Phone", "phone-app", this);
2626 m_list.append(item);
2727 item = new MockLauncherItem("camera-app", "/usr/share/applications/camera-app.desktop", "Camera", "camera", this);
28+ item->setCount(1234567);
29+ item->setProgress(150);
2830 m_list.append(item);
2931 item = new MockLauncherItem("gallery-app", "/usr/share/applications/gallery-app.desktop", "Gallery", "gallery", this);
32+ item->setProgress(100);
3033 m_list.append(item);
3134 item = new MockLauncherItem("facebook-webapp", "/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook", this);
35+ item->setCount(123456);
3236 m_list.append(item);
3337 item = new MockLauncherItem("webbrowser-app", "/usr/share/applications/webbrowser-app.desktop", "Browser", "browser", this);
38+ item->setProgress(50);
3439 m_list.append(item);
3540 item = new MockLauncherItem("twitter-webapp", "/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter", this);
41+ item->setCount(12345);
3642 m_list.append(item);
3743 item = new MockLauncherItem("gmail-webapp", "/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail", this);
44+ item->setCount(123);
3845 m_list.append(item);
3946 item = new MockLauncherItem("ubuntu-weather-app", "/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather", this);
47+ item->setCount(12);
48+ item->setProgress(10);
4049 m_list.append(item);
4150 item = new MockLauncherItem("notes-app", "/usr/share/applications/notes-app.desktop", "Notepad", "notepad", this);
51+ item->setProgress(0);
4252 m_list.append(item);
4353 item = new MockLauncherItem("calendar-app", "/usr/share/applications/calendar-app.desktop","Calendar", "calendar", this);
54+ item->setCount(1);
4455 m_list.append(item);
4556}
4657
@@ -91,9 +102,29 @@ unity::shell::launcher::LauncherItemInterface *MockLauncherModel::get(int index)
91102
92103void MockLauncherModel::move(int oldIndex, int newIndex)
93104{
94− beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
105+ // Make sure its not moved outside the lists
106+ if (newIndex < 0) {
107+ newIndex = 0;
108+ }
109+ if (newIndex >= m_list.count()) {
110+ newIndex = m_list.count()-1;
111+ }
112+
113+ // Nothing to do?
114+ if (oldIndex == newIndex) {
115+ return;
116+ }
117+
118+ // QList's and QAbstractItemModel's move implementation differ when moving an item up the list :/
119+ // While QList needs the index in the resulting list, beginMoveRows expects it to be in the current list
120+ // adjust the model's index by +1 in case we're moving upwards
121+ int newModelIndex = newIndex > oldIndex ? newIndex+1 : newIndex;
122+
123+ beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newModelIndex);
95124 m_list.move(oldIndex, newIndex);
96125 endMoveRows();
126+
127+ pin(m_list.at(newIndex)->appId());
97128}
98129
99130void MockLauncherModel::pin(const QString &appId, int index)
tests/qmltests/Launcher/tst_Launcher.qml+16
@@ -177,6 +177,22 @@ Item {
177177 revealer.waitUntilLauncherDisappears();
178178 launcher.available = true;
179179 }
180+
181+ function test_countEmblems() {
182+ var launcherListView = findChild(launcher, "launcherListView");
183+ for (var i = 0; i < launcherListView.count; ++i) {
184+ var delegate = findChild(launcherListView, "launcherDelegate" + i)
185+ compare(findChild(delegate, "countEmblem").visible, LauncherModel.get(i).count > 0)
186+ }
187+ }
188+
189+ function test_progressOverlays() {
190+ var launcherListView = findChild(launcher, "launcherListView");
191+ for (var i = 0; i < launcherListView.count; ++i) {
192+ var delegate = findChild(launcherListView, "launcherDelegate" + i)
193+ compare(findChild(delegate, "progressOverlay").visible, LauncherModel.get(i).progress >= 0)
194+ }
195+ }
180196 }
181197
182198 UT.UnityTestCase {