on xenial help sign in
add support for highlighting the currently focused app
commit4a9640b24c9759c898738d8cf34afb5bdc2a36c1 authorMichael Zanetti <michael.zanetti@canonical.com> dateWed 4 Sep 2013, 22:40 (13 years ago) parent98fb59f
8 files changed+85−29
Launcher/LauncherDelegate.qml+19−9 Launcher/LauncherPanel.qml+3−2 Launcher/graphics/focused_app_arrow@30.png Shell.qml+5−1 plugins/Unity/Launcher/backend/launcherbackend.cpp+6−11 plugins/Unity/Launcher/launcheritem.cpp+14 plugins/Unity/Launcher/launcheritem.h+4 plugins/Unity/Launcher/launchermodel.cpp+34−6
Launcher/LauncherDelegate.qml+19−9
@@ -24,6 +24,7 @@ Item {
2424 property int count: -1
2525 property int progress: -1
2626 property bool highlighted: false
27+ property bool itemFocused: false
2728 property real maxAngle: 0
2829 property bool inverted: false
2930
@@ -43,17 +44,18 @@ Item {
4344 onCountChanged: shaderEffectSource.scheduleUpdate();
4445 onProgressChanged: shaderEffectSource.scheduleUpdate();
4546 onHighlightedChanged: shaderEffectSource.scheduleUpdate();
47+ onItemFocusedChanged: shaderEffectSource.scheduleUpdate();
4648
4749 Item {
4850 id: iconItem
49− width: parent.itemWidth
50− height: parent.itemHeight
51+ width: parent.itemWidth + units.gu(1)
52+ height: parent.itemHeight + units.gu(1)
5153 anchors.centerIn: parent
5254
5355 UbuntuShape {
5456 id: iconShape
5557 anchors.fill: parent
56− anchors.margins: units.gu(0.5)
58+ anchors.margins: units.gu(1)
5759 radius: "medium"
5860
5961 image: Image {
@@ -78,7 +80,7 @@ Item {
7880 anchors {
7981 right: parent.right
8082 top: parent.top
81− margins: -units.dp(1)
83+ margins: units.dp(3)
8284 }
8385 width: Math.min(root.itemWidth, Math.max(units.gu(3), countLabel.implicitWidth + units.gu(2.5)))
8486 height: units.gu(3)
@@ -105,9 +107,9 @@ Item {
105107 left: iconItem.left
106108 right: iconItem.right
107109 bottom: iconItem.bottom
108− leftMargin: units.gu(0.5)
109− rightMargin: units.gu(0.5)
110− bottomMargin: units.gu(0.5)
110+ leftMargin: units.gu(1)
111+ rightMargin: units.gu(1)
112+ bottomMargin: units.gu(1)
111113 }
112114 height: units.gu(1.5)
113115 visible: root.progress > -1
@@ -136,14 +138,22 @@ Item {
136138 }
137139 }
138140 }
141+ Image {
142+ anchors {
143+ right: parent.right
144+ verticalCenter: parent.verticalCenter
145+ }
146+ visible: root.itemFocused
147+ source: "graphics/focused_app_arrow.png"
148+ }
139149 }
140150
141151 ShaderEffect {
142152 id: transformEffect
143153 anchors.centerIn: parent
144154 anchors.verticalCenterOffset: root.offset
145− width: parent.itemWidth
146− height: parent.itemHeight
155+ width: iconItem.width
156+ height: iconItem.height
147157 property real itemOpacity: root.itemOpacity
148158 property real brightness: Math.max(-1, root.brightness)
149159 property real angle: root.angle
Launcher/LauncherPanel.qml+3−2
@@ -50,8 +50,6 @@ Item {
5050 id: mainColumn
5151 anchors {
5252 fill: parent
53− leftMargin: units.gu(0.5)
54− rightMargin: units.gu(0.5)
5553 }
5654
5755 MouseArea {
@@ -94,6 +92,8 @@ Item {
9492 fill: parent
9593 topMargin: -extensionSize + units.gu(0.5)
9694 bottomMargin: -extensionSize + units.gu(1)
95+ leftMargin: units.gu(0.5)
96+ rightMargin: units.gu(0.5)
9797 }
9898 topMargin: extensionSize
9999 bottomMargin: extensionSize
@@ -156,6 +156,7 @@ Item {
156156 iconName: model.icon
157157 count: model.count
158158 progress: model.progress
159+ itemFocused: model.focused
159160 inverted: root.inverted
160161 z: -Math.abs(offset)
161162 maxAngle: 55
Launcher/graphics/focused_app_arrow@30.pngnew file

Binary file not shown.

Shell.qml+5−1
@@ -98,7 +98,11 @@ FocusScope {
9898
9999 onMainStageFocusedApplicationChanged: {
100100 var app = applicationManager.mainStageFocusedApplication
101− LauncherModel.applicationFocused(app.desktopFile);
101+ if (app != null) {
102+ LauncherModel.applicationFocused(app.desktopFile);
103+ } else {
104+ LauncherModel.applicationFocused("");
105+ }
102106 }
103107 }
104108
plugins/Unity/Launcher/backend/launcherbackend.cpp+6−11
@@ -225,6 +225,9 @@ void LauncherBackend::syncFromAccounts()
225225 if (entry.startsWith("application://")) {
226226 QString appId = entry;
227227 appId.remove("application://");
228+ if (appId.endsWith(".desktop")) {
229+ appId.chop(8);
230+ }
228231 QString df = findDesktopFile(appId);
229232
230233 if (!df.isEmpty()) {
@@ -265,18 +268,9 @@ QString LauncherBackend::findDesktopFile(const QString &appId) const
265268 QStringList searchDirs;
266269 searchDirs << "/usr/share/applications";
267270
268−// FIXME: Right now the appId can be (or rather is) a full path
269−// to a .desktop file. This will change in the future.
270−// Once the ApplicationManager has been switched over to use appIds,
271−// remove this chop() and enable the ifdef to only search the current
272−// working dir for testing. Also, this is the place to add the search
273−// paths for click apps in the next step.
274− if (helper.endsWith(".desktop")) {
275− helper.chop(8);
276− }
277−//#ifdef LAUNCHER_TESTING
271+#ifdef LAUNCHER_TESTING
278272 searchDirs << "";
279−//#endif
273+#endif
280274
281275 do {
282276 if (dashPos != -1) {
@@ -284,6 +278,7 @@ QString LauncherBackend::findDesktopFile(const QString &appId) const
284278 }
285279
286280 Q_FOREACH(const QString &searchDir, searchDirs) {
281+ qDebug() << "searching for desktop file:" << searchDir << helper + ".desktop";
287282 QFileInfo fileInfo(QDir(searchDir), helper + ".desktop");
288283 if (fileInfo.exists()) {
289284 return fileInfo.absoluteFilePath();
plugins/Unity/Launcher/launcheritem.cpp+14
@@ -31,6 +31,7 @@ LauncherItem::LauncherItem(const QString &appId, const QString &desktopFile, con
3131 m_recent(false),
3232 m_progress(-1),
3333 m_count(0),
34+ m_focused(false),
3435 m_quickList(new QuickListModel(this))
3536{
3637 QuickListEntry nameAction;
@@ -131,6 +132,19 @@ void LauncherItem::setCount(int count)
131132 }
132133}
133134
135+bool LauncherItem::focused() const
136+{
137+ return m_focused;
138+}
139+
140+void LauncherItem::setFocused(bool focused)
141+{
142+ if (m_focused != focused) {
143+ m_focused = focused;
144+ Q_EMIT focusedChanged(focused);
145+ }
146+}
147+
134148unity::shell::launcher::QuickListModelInterface *LauncherItem::quickList() const
135149{
136150 return m_quickList;
plugins/Unity/Launcher/launcheritem.h+4
@@ -54,6 +54,9 @@ public:
5454 int count() const;
5555 void setCount(int count);
5656
57+ bool focused() const;
58+ void setFocused(bool focused);
59+
5760 unity::shell::launcher::QuickListModelInterface *quickList() const;
5861
5962Q_SIGNALS:
@@ -70,6 +73,7 @@ private:
7073 bool m_recent;
7174 int m_progress;
7275 int m_count;
76+ bool m_focused;
7377 QuickListModel *m_quickList;
7478};
7579
plugins/Unity/Launcher/launchermodel.cpp+34−6
@@ -21,6 +21,8 @@
2121#include "launcheritem.h"
2222#include "backend/launcherbackend.h"
2323
24+#include <QDebug>
25+
2426LauncherModel::LauncherModel(QObject *parent):
2527 LauncherModelInterface(parent),
2628 m_backend(new LauncherBackend(true, this))
@@ -74,6 +76,8 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
7476 return item->count();
7577 case RoleProgress:
7678 return item->progress();
79+ case RoleFocused:
80+ return item->focused();
7781 }
7882
7983 return QVariant();
@@ -193,18 +197,41 @@ void LauncherModel::setUser(const QString &username)
193197
194198void LauncherModel::applicationFocused(const QString &appId)
195199{
196− int index = findApplication(appId);
200+ // Unfocus all apps
201+ for(int i = 0; i < m_list.count(); ++i) {
202+ LauncherItem *item = m_list.at(i);
203+ if (item->focused()) {
204+ item->setFocused(false);
205+ Q_EMIT dataChanged(this->index(i), this->index(i), QVector<int>() << RoleFocused);
206+ }
207+ }
208+
209+ if (appId.isEmpty()) {
210+ return;
211+ }
212+
213+ // FIXME: drop this once we get real appIds from the AppManager
214+ QString helper = appId.split('/').last();
215+ if (helper.endsWith(".desktop")) {
216+ helper.chop(8);
217+ }
218+
219+ int index = findApplication(helper);
220+ qDebug() << "################## found focused app index" << index << helper;
197221
198222 if (index >= 0) {
199− // TODO: Mark application as focued
223+ m_list.at(index)->setFocused(true);
224+ qDebug() << "set focused to true on" << m_list.at(index)->name();
225+ Q_EMIT dataChanged(this->index(index), this->index(index), QVector<int>() << RoleFocused);
200226 } else {
201227 // Add app to recent apps
202− QString desktopFile = m_backend->desktopFile(appId);
203− QString appName = m_backend->displayName(appId);
204− QString icon = m_backend->icon(appId);
228+ QString desktopFile = m_backend->desktopFile(helper);
229+ QString appName = m_backend->displayName(helper);
230+ QString icon = m_backend->icon(helper);
205231
206− LauncherItem *item = new LauncherItem(appId, desktopFile, appName, icon);
232+ LauncherItem *item = new LauncherItem(helper, desktopFile, appName, icon);
207233 item->setRecent(true);
234+ item->setFocused(true);
208235 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
209236 m_list.append(item);
210237 endInsertRows();
@@ -243,6 +270,7 @@ int LauncherModel::findApplication(const QString &appId)
243270{
244271 for (int i = 0; i < m_list.count(); ++i) {
245272 LauncherItem *item = m_list.at(i);
273+ qDebug() << "checking app" << item->appId();
246274 if (item->appId() == appId) {
247275 return i;
248276 }