2 * Copyright (C) 2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import Ubuntu.Components 1.3
19 import Unity.Launcher 0.1
21 import "../Components"
22 import Qt.labs.settings 1.0
27 property int panelWidth: 0
28 readonly property bool moving: listLoader.item && listLoader.item.moving
30 signal applicationSelected(string appId)
32 property bool draggingHorizontally: false
33 property int dragDistance: 0
37 searchField.selectAll();
41 function focusInput() {
42 searchField.selectAll();
43 searchField.focus = true;
47 property alias selectedTab: sections.selectedIndex
53 acceptedButtons: Qt.AllButtons
54 onWheel: wheel.accepted = true
67 source: appDrawerModel
68 filterString: searchField.displayText
69 sortBy: AppDrawerProxyModel.SortByAToZ
75 anchors.leftMargin: root.panelWidth
79 anchors { left: parent.left; top: parent.top; right: parent.right; margins: units.gu(1) }
80 placeholderText: i18n.tr("Search…")
83 if (searchField.displayText != "" && listLoader.item && listLoader.item.currentItem) {
84 root.applicationSelected(listLoader.item.getFirstAppId());
91 anchors { left: parent.left; top: searchField.bottom; right: parent.right; }
92 height: sections.height
101 text: i18n.ctr("Apps sorted alphabetically", "A-Z")
102 // TODO: Disabling this for now as we don't get the right input from u-a-l yet.
105 // text: i18n.ctr("Most used apps", "Most used")
110 anchors.bottom: parent.bottom
113 width: contentContainer.width
120 anchors { left: parent.left; top: sectionsContainer.bottom; right: parent.right; bottom: parent.bottom; leftMargin: units.gu(1); rightMargin: units.gu(1) }
122 switch (sections.selectedIndex) {
123 case 0: return aToZComponent;
124 case 1: return mostUsedComponent;
128 target: listLoader.item || null
129 property: "objectName"
130 value: "drawerItemList"
135 parent: listLoader.item ? listLoader.item : null
137 propagateComposedEvents: true
143 var diff = oldX - mouseX;
144 root.draggingHorizontally |= diff > units.gu(2);
145 if (!root.draggingHorizontally) {
148 propagateComposedEvents = false;
149 parent.interactive = false;
150 root.dragDistance += diff;
154 if (root.draggingHorizontally) {
155 root.draggingHorizontally = false;
156 parent.interactive = true;
158 reactivateTimer.start();
163 onTriggered: parent.propagateComposedEvents = true;
168 id: mostUsedComponent
171 header: MoreAppsHeader {
176 model: AppDrawerProxyModel {
177 source: sortProxyModel
178 group: AppDrawerProxyModel.GroupByAll
179 sortBy: AppDrawerProxyModel.SortByUsage
182 delegate: UbuntuShape {
185 aspect: UbuntuShape.Flat
186 // NOTE: Cannot use gridView.rows here as it would evaluate to 0 at first and only update later,
187 // which messes up the ListView.
188 height: (Math.ceil(mostUsedGridView.model.count / mostUsedGridView.columns) * mostUsedGridView.delegateHeight) + units.gu(2)
190 readonly property string appId: model.appId
195 topMargin: units.gu(1)
196 bottomMargin: units.gu(1)
199 model: sortProxyModel
201 delegateWidth: units.gu(8)
202 delegateHeight: units.gu(10)
203 delegate: drawerDelegateComponent
213 header: MoreAppsHeader {
218 model: AppDrawerProxyModel {
219 source: sortProxyModel
220 sortBy: AppDrawerProxyModel.SortByAToZ
221 group: AppDrawerProxyModel.GroupByAToZ
224 delegate: UbuntuShape {
227 aspect: UbuntuShape.Flat
229 readonly property string appId: model.appId
231 // NOTE: Cannot use gridView.rows here as it would evaluate to 0 at first and only update later,
232 // which messes up the ListView.
233 height: (Math.ceil(gridView.model.count / gridView.columns) * gridView.delegateHeight) +
234 categoryNameLabel.implicitHeight + units.gu(2)
237 id: categoryNameLabel
238 anchors { left: parent.left; top: parent.top; right: parent.right; margins: units.gu(1) }
244 anchors { left: parent.left; top: categoryNameLabel.bottom; right: parent.right; topMargin: units.gu(1) }
245 height: rows * delegateHeight
249 model: AppDrawerProxyModel {
251 source: sortProxyModel
252 filterLetter: model.letter
254 delegateWidth: units.gu(8)
255 delegateHeight: units.gu(10)
256 delegate: drawerDelegateComponent
264 id: drawerDelegateComponent
266 width: GridView.view.cellWidth
268 objectName: "drawerItem_" + model.appId
270 onClicked: root.applicationSelected(model.appId)
274 anchors.horizontalCenter: parent.horizontalCenter
275 height: childrenRect.height
281 height: 7.5 / 8 * width
282 anchors.horizontalCenter: parent.horizontalCenter
283 backgroundMode: UbuntuShape.SolidColor
284 backgroundColor: UbuntuColors.lightGrey
286 borderSource: 'undefined'
289 sourceSize.width: appIcon.width
292 sourceFillMode: UbuntuShape.PreserveAspectCrop
298 horizontalAlignment: Text.AlignHCenter
300 elide: Text.ElideRight