on xenial help sign in
clip the corner of pinned icons in the launcher as per new design

Approved by: PS Jenkins bot, Vesa Rautiainen, PS Jenkins bot, Michał Sawicz

commit41d1e09a0aadad6ef3fc9b2901b8ad0879f4a9d7 authorMichael Zanetti <michael.zanetti@canonical.com> dateWed 9 Jul 2014, 19:45 (12 years ago) parent503b8a81459f99
5 files changed+54−3
plugins/Unity/Launcher/launchermodel.cpp+3−1 qml/Launcher/LauncherDelegate.qml+31 qml/Launcher/LauncherPanel.qml+5−1 tests/mocks/Unity/Launcher/MockLauncherModel.cpp+6−1 tests/plugins/Unity/Launcher/launchermodeltest.cpp+9
plugins/Unity/Launcher/launchermodel.cpp+3−1
@@ -128,7 +128,7 @@ void LauncherModel::pin(const QString &appId, int index)
128128 if (index == -1 || index == currentIndex) {
129129 m_list.at(currentIndex)->setPinned(true);
130130 QModelIndex modelIndex = this->index(currentIndex);
131− Q_EMIT dataChanged(modelIndex, modelIndex);
131+ Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RolePinned);
132132 } else {
133133 move(currentIndex, index);
134134 // move() will store the list to the backend itself, so just exit at this point.
@@ -159,6 +159,8 @@ void LauncherModel::requestRemove(const QString &appId)
159159
160160 if (m_appManager->findApplication(appId)) {
161161 m_list.at(index)->setPinned(false);
162+ QModelIndex modelIndex = this->index(index);
163+ Q_EMIT dataChanged(modelIndex, modelIndex, QVector<int>() << RolePinned);
162164 return;
163165 }
164166
qml/Launcher/LauncherDelegate.qml+31
@@ -26,6 +26,7 @@ Item {
2626 property bool itemFocused: false
2727 property real maxAngle: 0
2828 property bool inverted: false
29+ property bool clipCorner: false
2930
3031 readonly property int effectiveHeight: Math.cos(angle * Math.PI / 180) * itemHeight
3132 readonly property real foldedHeight: Math.cos(maxAngle * Math.PI / 180) * itemHeight
@@ -143,6 +144,24 @@ Item {
143144 }
144145 }
145146
147+ Item {
148+ id: clipper
149+ anchors.centerIn: parent
150+ width: iconItem.width
151+ height: iconItem.height
152+ Rectangle {
153+ anchors {
154+ fill: parent
155+ topMargin: -units.gu(2)
156+ leftMargin: -units.gu(2)
157+ rightMargin: -units.gu(2)
158+ bottomMargin: units.gu(1.2)
159+ }
160+ color: "red"
161+ rotation: root.rotation + 45
162+ }
163+ }
164+
146165 ShaderEffect {
147166 id: transformEffect
148167 anchors.centerIn: parent
@@ -152,6 +171,7 @@ Item {
152171 property real itemOpacity: root.itemOpacity
153172 property real brightness: Math.max(-1, root.brightness)
154173 property real angle: root.angle
174+ property bool clipCorner: root.clipCorner
155175 rotation: root.inverted ? 180 : 0
156176
157177 property variant source: ShaderEffectSource {
@@ -160,6 +180,11 @@ Item {
160180 hideSource: true
161181 }
162182
183+ property var mask: ShaderEffectSource {
184+ sourceItem: clipper
185+ hideSource: true
186+ }
187+
163188 transform: [
164189 // Rotating 3 times at top/bottom because that increases the perspective.
165190 // This is a hack, but as QML does not support real 3D coordinates
@@ -194,13 +219,19 @@ Item {
194219 fragmentShader: "
195220 varying highp vec2 qt_TexCoord0;
196221 uniform sampler2D source;
222+ uniform sampler2D mask;
197223 uniform lowp float brightness;
198224 uniform lowp float itemOpacity;
225+ uniform bool clipCorner;
199226 void main(void)
200227 {
201228 highp vec4 sourceColor = texture2D(source, qt_TexCoord0);
229+ highp vec4 maskColor = texture2D(mask, qt_TexCoord0);
202230 sourceColor.rgb = mix(sourceColor.rgb, vec3(step(0.0, brightness)), abs(brightness));
203231 sourceColor *= itemOpacity;
232+ if (clipCorner) {
233+ sourceColor *= maskColor.a;
234+ }
204235 gl_FragColor = sourceColor;
205236 }"
206237 }
qml/Launcher/LauncherPanel.qml+5−1
@@ -155,6 +155,7 @@ Item {
155155 iconName: model.icon
156156 count: model.count
157157 progress: model.progress
158+ clipCorner: model.pinned
158159 itemFocused: model.focused
159160 inverted: root.inverted
160161 z: -Math.abs(offset)
@@ -465,6 +466,10 @@ Item {
465466 width: itemWidth
466467 rotation: root.rotation
467468 itemOpacity: 0.9
469+ clipCorner: dndArea.draggedIndex > -1 &&
470+ LauncherModel.get(dndArea.draggedIndex).pinned &&
471+ !dndArea.preDragging &&
472+ !dndArea.dragging
468473
469474 function flatten() {
470475 fakeDragItemAnimation.start();
@@ -528,7 +533,6 @@ Item {
528533 left: root.inverted ? undefined : parent.right
529534 right: root.inverted ? parent.left : undefined
530535 margins: units.gu(1)
531−
532536 }
533537 y: itemCenter - (height / 2) + offset
534538 rotation: root.rotation
tests/mocks/Unity/Launcher/MockLauncherModel.cpp+6−1
@@ -24,10 +24,12 @@ MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(pa
2424{
2525 MockLauncherItem *item = new MockLauncherItem("dialer-app", "/usr/share/applications/dialer-app.desktop", "Dialer", "dialer-app", this);
2626 item->setProgress(0);
27− m_list.append(item);
27+ item->setPinned(true);
2828 item->setFocused(true);
29+ m_list.append(item);
2930 item = new MockLauncherItem("camera-app", "/usr/share/applications/camera-app.desktop", "Camera", "camera", this);
3031 item->setProgress(10);
32+ item->setPinned(true);
3133 m_list.append(item);
3234 item = new MockLauncherItem("gallery-app", "/usr/share/applications/gallery-app.desktop", "Gallery", "gallery", this);
3335 item->setProgress(50);
@@ -40,6 +42,7 @@ MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(pa
4042 m_list.append(item);
4143 item = new MockLauncherItem("twitter-webapp", "/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter", this);
4244 item->setCount(12);
45+ item->setPinned(true);
4346 m_list.append(item);
4447 item = new MockLauncherItem("gmail-webapp", "/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail", this);
4548 item->setCount(123);
@@ -51,8 +54,10 @@ MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(pa
5154 item->setProgress(50);
5255 item->setCount(5);
5356 item->setFocused(true);
57+ item->setPinned(true);
5458 m_list.append(item);
5559 item = new MockLauncherItem("calendar-app", "/usr/share/applications/calendar-app.desktop","Calendar", "calendar", this);
60+ item->setPinned(true);
5661 m_list.append(item);
5762}
5863
tests/plugins/Unity/Launcher/launchermodeltest.cpp+9
@@ -156,11 +156,20 @@ private Q_SLOTS:
156156 }
157157
158158 void testPinning() {
159+ QSignalSpy spy(launcherModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
159160 QCOMPARE(launcherModel->get(0)->pinned(), false);
160161 QCOMPARE(launcherModel->get(1)->pinned(), false);
161162 launcherModel->pin(launcherModel->get(0)->appId());
162163 QCOMPARE(launcherModel->get(0)->pinned(), true);
163164 QCOMPARE(launcherModel->get(1)->pinned(), false);
165+ QCOMPARE(spy.count(), 1);
166+ QCOMPARE(spy.at(0).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
167+
168+ launcherModel->requestRemove(launcherModel->get(0)->appId());
169+ QCOMPARE(launcherModel->get(0)->pinned(), false);
170+ QCOMPARE(launcherModel->get(1)->pinned(), false);
171+ QCOMPARE(spy.count(), 2);
172+ QCOMPARE(spy.at(1).at(2).value<QVector<int>>().first(), (int)LauncherModelInterface::RolePinned);
164173 }
165174
166175 void testRemove_data() {