on xenial help sign in
some more fixes
commitcc1fa6a277380e02cf03df4c5ca2c28be28bc202 authorMichael Zanetti <michael.zanetti@canonical.com> dateFri 4 Nov 2016, 11:10 (10 years ago) parent09ad1ca
6 files changed+96−32
plugins/Utils/appdrawerproxymodel.cpp+16−1 plugins/Utils/appdrawerproxymodel.h+11 qml/Launcher/Drawer.qml+41−3 qml/Launcher/Launcher.qml+17−27 qml/Launcher/MoreAppsHeader.qml+6−1 tests/mocks/Unity/Launcher/MockAppDrawerModel.cpp+5
plugins/Utils/appdrawerproxymodel.cpp+16−1
@@ -23,7 +23,7 @@ void AppDrawerProxyModel::setSource(QAbstractItemModel *source)
2323 if (m_source != source) {
2424 m_source = source;
2525 setSourceModel(m_source);
26− sort(0);
26+ setSortRole(m_sortBy == SortByAToZ ? AppDrawerModelInterface::RoleName : AppDrawerModelInterface::RoleUsage);
2727 connect(m_source, &QAbstractItemModel::rowsRemoved, this, &AppDrawerProxyModel::invalidateFilter);
2828 connect(m_source, &QAbstractItemModel::rowsInserted, this, &AppDrawerProxyModel::invalidateFilter);
2929 Q_EMIT sourceChanged();
@@ -72,6 +72,21 @@ void AppDrawerProxyModel::setFilterString(const QString &filterString)
7272 }
7373}
7474
75+AppDrawerProxyModel::SortBy AppDrawerProxyModel::sortBy() const
76+{
77+ return m_sortBy;
78+}
79+
80+void AppDrawerProxyModel::setSortBy(AppDrawerProxyModel::SortBy sortBy)
81+{
82+ if (m_sortBy != sortBy) {
83+ m_sortBy = sortBy;
84+ Q_EMIT sortByChanged();
85+ setSortRole(m_sortBy == SortByAToZ ? AppDrawerModelInterface::RoleName : AppDrawerModelInterface::RoleUsage);
86+ sort(0);
87+ }
88+}
89+
7590int AppDrawerProxyModel::count() const
7691{
7792 return rowCount();
plugins/Utils/appdrawerproxymodel.h+11
@@ -8,10 +8,12 @@ class AppDrawerProxyModel: public QSortFilterProxyModel
88{
99 Q_OBJECT
1010 Q_ENUMS(GroupBy)
11+ Q_ENUMS(SortBy)
1112 Q_PROPERTY(QAbstractItemModel* source READ source WRITE setSource NOTIFY sourceChanged)
1213 Q_PROPERTY(GroupBy group READ group WRITE setGroup NOTIFY groupChanged)
1314 Q_PROPERTY(QString filterLetter READ filterLetter WRITE setFilterLetter NOTIFY filterLetterChanged)
1415 Q_PROPERTY(QString filterString READ filterString WRITE setFilterString NOTIFY filterStringChanged)
16+ Q_PROPERTY(SortBy sortBy READ sortBy WRITE setSortBy NOTIFY sortByChanged)
1517 Q_PROPERTY(int count READ count NOTIFY countChanged)
1618
1719public:
@@ -20,6 +22,10 @@ public:
2022 GroupByAll,
2123 GroupByAToZ
2224 };
25+ enum SortBy {
26+ SortByAToZ,
27+ SortByUsage
28+ };
2329
2430 AppDrawerProxyModel(QObject* parent = nullptr);
2531
@@ -35,6 +41,9 @@ public:
3541 QString filterString() const;
3642 void setFilterString(const QString &filterString);
3743
44+ SortBy sortBy() const;
45+ void setSortBy(SortBy sortBy);
46+
3847 int count() const;
3948
4049 QVariant data(const QModelIndex &index, int role) const override;
@@ -48,6 +57,7 @@ Q_SIGNALS:
4857 void groupChanged();
4958 void filterLetterChanged();
5059 void filterStringChanged();
60+ void sortByChanged();
5161 void countChanged();
5262
5363private:
@@ -55,4 +65,5 @@ private:
5565 GroupBy m_group = GroupByNone;
5666 QString m_filterLetter;
5767 QString m_filterString;
68+ SortBy m_sortBy = SortByAToZ;
5869};
qml/Launcher/Drawer.qml+41−3
@@ -12,6 +12,9 @@ FocusScope {
1212
1313 signal applicationSelected(string appId)
1414
15+ property bool draggingHorizontally: false
16+ property int dragDistance: 0
17+
1518 Rectangle {
1619 anchors.fill: parent
1720 color: "#BF000000"
@@ -50,10 +53,10 @@ FocusScope {
5053 width: parent.width
5154 actions: [
5255 Action {
53− text: i18n.tr("A-Z")
56+ text: i18n.ctr("Apps sorted alphabetically", "A-Z")
5457 },
5558 Action {
56− text: i18n.tr("Most used")
59+ text: i18n.ctr("Most used apps", "Most used")
5760 }
5861 ]
5962
@@ -72,6 +75,39 @@ FocusScope {
7275 sourceComponent: sections.selectedIndex == 0 ? aToZComponent : mostUsedComponent
7376 }
7477
78+ MouseArea {
79+ parent: listLoader.item ? listLoader.item : null
80+ anchors.fill: parent
81+ propagateComposedEvents: true
82+ property int oldX: 0
83+ onPressed: {
84+ oldX = mouseX;
85+ }
86+ onMouseXChanged: {
87+ var diff = oldX - mouseX;
88+ root.draggingHorizontally |= diff > units.gu(2);
89+ if (!root.draggingHorizontally) {
90+ return;
91+ }
92+ propagateComposedEvents = false;
93+ parent.interactive = false;
94+ root.dragDistance += diff;
95+ oldX = mouseX
96+ }
97+ onReleased: {
98+ if (root.draggingHorizontally) {
99+ root.draggingHorizontally = false;
100+ parent.interactive = true;
101+ }
102+ reactivateTimer.start();
103+ }
104+ Timer {
105+ id: reactivateTimer
106+ interval: 0
107+ onTriggered: parent.propagateComposedEvents = true;
108+ }
109+ }
110+
75111 Component {
76112 id: mostUsedComponent
77113 ListView {
@@ -89,6 +125,7 @@ FocusScope {
89125 model: AppDrawerProxyModel {
90126 source: sortProxyModel
91127 group: AppDrawerProxyModel.GroupByAll
128+ sortBy: AppDrawerProxyModel.SortByUsage
92129 }
93130
94131 delegate: UbuntuShape {
@@ -98,6 +135,7 @@ FocusScope {
98135 // NOTE: Cannot use gridView.rows here as it would evaluate to 0 at first and only update later,
99136 // which messes up the ListView.
100137 height: (Math.ceil(mostUsedGridView.model.count / mostUsedGridView.columns) * mostUsedGridView.delegateHeight) + units.gu(2)
138+ enabled: parent.interactive
101139
102140 DrawerGridView {
103141 id: mostUsedGridView
@@ -108,7 +146,6 @@ FocusScope {
108146
109147 model: sortProxyModel
110148
111−
112149 delegateWidth: units.gu(8)
113150 delegateHeight: units.gu(10)
114151 delegate: drawerDelegateComponent
@@ -140,6 +177,7 @@ FocusScope {
140177 width: parent.width
141178 color: "#20ffffff"
142179 aspect: UbuntuShape.Flat
180+ enabled: parent.interactive
143181
144182 // NOTE: Cannot use gridView.rows here as it would evaluate to 0 at first and only update later,
145183 // which messes up the ListView.
qml/Launcher/Launcher.qml+17−27
@@ -295,16 +295,8 @@ FocusScope {
295295 visible: enabled
296296 onPressed: {
297297 mouse.accepted = false;
298− if (root.lockedVisible) {
299− if (root.state == "drawer") {
300− switchToNextState("visible")
301− }
302− } else {
303− if (root.state == "visible" || root.state == "drawer") {
304− panel.highlightIndex = -2;
305− root.hide();
306− }
307− }
298+ panel.highlightIndex = -2;
299+ root.hide();
308300 }
309301 }
310302
@@ -360,22 +352,6 @@ FocusScope {
360352 cached: drawer.moving
361353 }
362354
363− MouseArea {
364− anchors.fill: drawer
365− property int startX: 0
366− preventStealing: true
367−
368− onPressed: {
369− print("**** mouse pressed")
370− startX = mouseX
371− }
372−
373− onMouseXChanged: {
374− drawer.x += mouseX - startX
375− startX = mouseX
376− }
377− }
378−
379355 Drawer {
380356 id: drawer
381357 anchors {
@@ -394,8 +370,22 @@ FocusScope {
394370 root.focus = false;
395371 }
396372
373+ onDragDistanceChanged: {
374+ x -= dragDistance;
375+ }
376+ onDraggingHorizontallyChanged: {
377+ if (!draggingHorizontally) {
378+ if (drawer.x < -units.gu(10)) {
379+ root.hide();
380+ } else {
381+ root.openDrawer();
382+ }
383+ }
384+ }
385+
386+
397387 Behavior on x {
398− enabled: !dragArea.dragging && !launcherDragArea.drag.active// && panel.animate;
388+ enabled: !dragArea.dragging && !launcherDragArea.drag.active && !drawer.draggingHorizontally// && panel.animate;
399389 NumberAnimation {
400390 duration: 300
401391 easing.type: Easing.OutCubic
qml/Launcher/MoreAppsHeader.qml+6−1
@@ -1,9 +1,14 @@
11import QtQuick 2.4
22import Ubuntu.Components 1.3
33
4−Item {
4+AbstractButton {
55 id: root
66
7+ onClicked: {
8+ // TODO: Make this point to the snappy store as soon as we stop landing to vivid
9+ Qt.openUrlExternally("scope://com.canonical.scopes.clickstore")
10+ }
11+
712 UbuntuShape {
813 width: parent.width
914 height: parent.height - units.gu(1)
tests/mocks/Unity/Launcher/MockAppDrawerModel.cpp+5
@@ -1,6 +1,7 @@
11#include "MockAppDrawerModel.h"
22
33#include <QDebug>
4+#include <QDateTime>
45
56MockAppDrawerModel::MockAppDrawerModel(QObject *parent):
67 AppDrawerModelInterface(parent)
@@ -32,6 +33,8 @@ MockAppDrawerModel::MockAppDrawerModel(QObject *parent):
3233 item = new MockLauncherItem("libreoffice", "/usr/share/applications/libreoffice.desktop","Libre Office", "libreoffice", this);
3334 m_list.append(item);
3435 qDebug() << "mock model created";
36+
37+ qsrand(QDateTime::currentMSecsSinceEpoch() / 1000);
3538}
3639
3740int MockAppDrawerModel::rowCount(const QModelIndex &parent) const
@@ -48,6 +51,8 @@ QVariant MockAppDrawerModel::data(const QModelIndex &index, int role) const
4851 return m_list.at(index.row())->name();
4952 case RoleIcon:
5053 return m_list.at(index.row())->icon();
54+ case RoleUsage:
55+ return qrand();
5156 }
5257
5358 return QVariant();