2 * Copyright (C) 2013 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/>.
18import Ubuntu.Components 0.1
22import "../Components/ListItems" as ListItems
28 property SortFilterProxyModel categories: categoryFilter
29 property bool isCurrent
30 property ListModel searchHistory
31 property alias moving: categoryView.moving
34 signal movementStarted
35 signal positionedAtBeginning
37 readonly property alias previewShown: previewListView.onScreen
38 property bool enableHeightBehaviorOnNextCreation: false
40 // FIXME delay the search so that daemons have time to settle, note that
41 // removing this will break ScopeView::test_changeScope
45 scope.activateApplication.connect(activateApp);
49 function activateApp(appId) {
50 shell.activateApplication(appId);
62 onTriggered: scope.searchQuery = ""
65 SortFilterProxyModel {
67 model: scope ? scope.categories : null
68 dynamicSortFilter: true
69 filterRole: Categories.RoleCount
75 pageHeader.resetSearch();
76 previewListView.open = false;
79 onMovementStarted: categoryView.showHeader()
81 onPositionedAtBeginning: categoryView.positionAtBeginning()
84 target: scopeView.scope
85 property: "searchQuery"
86 value: pageHeader.searchQuery
91 property: "searchQuery"
92 value: scopeView.scope.searchQuery
97 onSearchClicked: if (isCurrent) {
98 pageHeader.triggerSearch()
99 categoryView.showHeader()
104 target: scopeView.scope
105 onShowDash: previewListView.open = false;
106 onHideDash: previewListView.open = false;
111 objectName: "categoryListView"
113 model: scopeView.categories
114 forceNoClip: previewListView.onScreen
116 onAtYEndChanged: if (atYEnd) endReached()
117 onMovingChanged: if (moving && atYEnd) endReached()
119 property string expandedCategoryId: ""
120 signal correctExpandedCategory();
122 Behavior on contentY {
123 enabled: previewListView.open
124 UbuntuNumberAnimation {}
127 delegate: ListItems.Base {
129 highlightWhenPressed: false
131 readonly property bool expandable: rendererLoader.item ? rendererLoader.item.expandable : false
132 readonly property bool filtered: rendererLoader.item ? rendererLoader.item.filter : true
133 readonly property string category: categoryId
143 source: getRenderer(model.renderer, model.contentType, model.rendererHint, results)
146 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
147 item.enableHeightBehavior = scopeView.enableHeightBehaviorOnNextCreation;
148 scopeView.enableHeightBehaviorOnNextCreation = false;
150 if (source.toString().indexOf("Apps/RunningApplicationsGrid.qml") != -1) {
151 // TODO: the running apps grid doesn't support standard scope results model yet
152 item.firstModel = Qt.binding(function() { return results.firstModel })
153 item.secondModel = Qt.binding(function() { return results.secondModel })
154 item.canEnableTerminationMode = Qt.binding(function() { return scopeView.isCurrent })
156 item.model = Qt.binding(function() { return results })
158 item.objectName = Qt.binding(function() { return categoryId })
159 if (item.expandable) {
160 var shouldFilter = categoryId != categoryView.expandedCategoryId;
161 if (shouldFilter != item.filter) {
162 item.filter = shouldFilter;
165 updateDelegateCreationRange();
168 Component.onDestruction: {
169 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
170 scopeView.enableHeightBehaviorOnNextCreation = item.enableHeightBehaviorOnNextCreation;
175 target: rendererLoader.item
177 // Prepare the preview in case activate() triggers a preview only
178 effect.positionPx = Math.max(mapToItem(categoryView, 0, itemY).y, pageHeader.height + categoryView.stickyHeaderHeight);
179 previewListView.categoryId = categoryId
180 previewListView.categoryDelegate = rendererLoader.item
181 previewListView.model = target.model;
182 previewListView.init = true;
183 previewListView.currentIndex = index;
185 var item = target.model.get(index);
187 if ((scopeView.scope.id == "applications.scope" && categoryId == "installed")
188 || (scopeView.scope.id == "home.scope" && categoryId == "applications.scope")) {
189 scopeView.scope.activate(item.uri, item.icon, item.category, 0, item.mimetype, item.title,
190 item.comment, item.dndUri, item.metadata)
192 previewListView.open = true
194 scopeView.scope.preview(item.uri, item.icon, item.category, 0, item.mimetype, item.title,
195 item.comment, item.dndUri, item.metadata)
199 effect.positionPx = Math.max(mapToItem(categoryView, 0, itemY).y, pageHeader.height + categoryView.stickyHeaderHeight);
200 previewListView.categoryId = categoryId
201 previewListView.categoryDelegate = rendererLoader.item
202 previewListView.model = target.model;
203 previewListView.init = true;
204 previewListView.currentIndex = index;
205 previewListView.open = true
207 var item = target.model.get(index)
208 scopeView.scope.preview(item.uri, item.icon, item.category, 0, item.mimetype, item.title,
209 item.comment, item.dndUri, item.metadata)
214 onExpandedCategoryIdChanged: {
215 collapseAllButExpandedCategory();
217 onCorrectExpandedCategory: {
218 collapseAllButExpandedCategory();
220 function collapseAllButExpandedCategory() {
221 var item = rendererLoader.item;
222 if (item.expandable) {
223 var shouldFilter = categoryId != categoryView.expandedCategoryId;
224 if (shouldFilter != item.filter) {
225 // If the filter animation will be seen start it, otherwise, just flip the switch
226 var shrinkingVisible = shouldFilter && y + item.collapsedHeight < categoryView.height;
227 var growingVisible = !shouldFilter && y + height < categoryView.height;
228 if (!previewListView.open || !shouldFilter) {
229 if (shrinkingVisible || growingVisible) {
230 item.startFilterAnimation(shouldFilter)
232 item.filter = shouldFilter;
234 if (!shouldFilter && !previewListView.open) {
235 categoryView.maximizeVisibleArea(index, item.uncollapsedHeight);
241 onContentYChanged: rendererLoader.updateDelegateCreationRange();
242 onHeightChanged: rendererLoader.updateDelegateCreationRange();
245 function updateDelegateCreationRange() {
246 // Do not update the range if we are overshooting up or down, since we'll come back
247 // to the stable position and delete/create items without any reason
248 if (categoryView.contentY < categoryView.originY) {
250 } else if (categoryView.contentY + categoryView.height > categoryView.contentHeight) {
254 if (item.hasOwnProperty("delegateCreationBegin")) {
255 if (baseItem.y + baseItem.height <= 0) {
256 // Not visible (item at top of the list)
257 item.delegateCreationBegin = baseItem.height
258 item.delegateCreationEnd = baseItem.height
259 } else if (baseItem.y >= categoryView.height) {
260 // Not visible (item at bottom of the list)
261 item.delegateCreationBegin = 0
262 item.delegateCreationEnd = 0
264 item.delegateCreationBegin = Math.max(-baseItem.y, 0)
265 item.delegateCreationEnd = Math.min(categoryView.height + item.delegateCreationBegin, baseItem.height)
272 sectionProperty: "name"
273 sectionDelegate: ListItems.Header {
274 property var delegate: categoryView.item(delegateIndex)
275 width: categoryView.width
278 if (delegate && delegate.expandable)
279 return delegate.filtered ? "graphics/header_handlearrow.png" : "graphics/header_handlearrow2.png"
283 if (categoryView.expandedCategoryId != delegate.category)
284 categoryView.expandedCategoryId = delegate.category;
286 categoryView.expandedCategoryId = "";
289 pageHeader: PageHeader {
291 objectName: "pageHeader"
292 width: categoryView.width
293 text: scopeView.scope.name
294 searchEntryEnabled: true
295 scope: scopeView.scope
296 searchHistory: scopeView.searchHistory
300 function getDefaultRendererId(contentType) {
301 switch (contentType) {
302 default: return "grid";
306 function getRenderer(rendererId, contentType, rendererHint, results) {
307 if (rendererId == "default") {
308 rendererId = getDefaultRendererId(contentType);
310 if (rendererId == "carousel") {
311 // Selectively disable carousel, 6 is fixed for now, should change on the form factor
312 if (results.count <= 6)
315 switch (rendererId) {
317 switch (contentType) {
318 case "music": return "Music/MusicCarousel.qml";
319 case "video": return "Video/VideoCarousel.qml";
320 default: return "Generic/GenericCarousel.qml";
324 switch (contentType) {
326 if (rendererHint == "toggled")
327 return "Apps/DashPluginFilterGrid.qml";
329 return "Generic/GenericFilterGrid.qml";
331 case "music": return "Music/MusicFilterGrid.qml";
332 case "video": return "Video/VideoFilterGrid.qml";
333 case "weather": return "Generic/WeatherFilterGrid.qml";
334 default: return "Generic/GenericFilterGrid.qml";
338 switch (contentType) {
339 case "apps": return "Apps/RunningApplicationsGrid.qml";
340 default: return "Generic/GenericFilterGrid.qml";
343 default: return "Generic/GenericFilterGrid.qml";
349 objectName: "openEffect"
352 bottomMargin: -bottomOverflow
354 sourceItem: categoryView
358 topGapPx: (1 - gap) * positionPx
359 topOpacity: (1 - gap * 1.2)
360 bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
361 bottomOverflow: units.gu(20)
362 live: !expansionAnimation.running
364 property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
365 property real gap: previewListView.open ? 1.0 : 0.0
369 id: expansionAnimation
371 easing.type: Easing.InOutQuad
373 if (!previewListView.open && !running) {
374 previewListView.onScreen = false
379 Behavior on positionPx {
380 enabled: previewListView.open
381 UbuntuNumberAnimation {}
386 target: scopeView.scope
388 if (previewListView.init) {
389 // Preview was triggered because of a click on the item. Need to expand now.
390 if (!previewListView.open) {
391 previewListView.open = true
394 var index = previewListView.currentIndex
395 previewListView.currentIndex = -1
396 previewListView.currentIndex = index
397 previewListView.init = false
399 previewListView.currentItem.previewData = preview
403 PreviewDelegateMapper {
404 id: previewDelegateMapper
409 objectName: "previewListView"
410 height: effect.bottomGapPx - effect.topGapPx
413 topMargin: effect.topGapPx
417 orientation: ListView.Horizontal
418 highlightRangeMode: ListView.StrictlyEnforceRange
419 snapMode: ListView.SnapOneItem
420 boundsBehavior: Flickable.DragAndOvershootBounds
421 highlightMoveDuration: 250
422 flickDeceleration: units.gu(625)
423 maximumFlickVelocity: width * 5
426 // To be set before opening the preview
427 property string categoryId: ""
428 property var categoryDelegate
430 // because the ListView is built asynchronous, setting the
431 // currentIndex directly won't work. We need to refresh it
432 // when the first preview is ready to be displayed.
433 property bool init: true
435 onCurrentIndexChanged: {
436 var row = Math.floor(currentIndex / categoryDelegate.columns);
437 if (categoryDelegate.collapsedRowCount <= row) {
438 categoryView.expandedCategoryId = categoryId
442 categoryDelegate.highlightIndex = currentIndex
445 if (!init && model !== undefined) {
446 var item = model.get(currentIndex)
447 scopeView.scope.preview(item.uri, item.icon, item.category, 0, item.mimetype, item.title, item.comment, item.dndUri, item.metadata)
450 // Adjust contentY in case we need to change to it to show the next row
451 if (categoryDelegate.rows > 1) {
452 var itemY = categoryView.contentItem.mapFromItem(categoryDelegate.currentItem).y;
454 // Find new contentY and effect.postionPx
455 var newContentY = itemY - effect.positionPx - categoryDelegate.verticalSpacing;
457 // Make sure the item is not covered by a header. Move the effect split down if necessary
458 var headerHeight = pageHeader.height + categoryView.stickyHeaderHeight;
459 var effectAdjust = Math.max(effect.positionPx, headerHeight);
461 // Make sure we don't overscroll the listview. If yes, adjust effect position
462 if (newContentY < 0) {
463 effectAdjust += newContentY;
466 if (newContentY > Math.max(0, categoryView.contentHeight - categoryView.height)) {
467 effectAdjust += -(categoryView.contentHeight - categoryView.height) + newContentY
468 newContentY = categoryView.contentHeight - categoryView.height;
471 effect.positionPx = effectAdjust;
472 categoryView.contentY = newContentY;
476 property bool open: false
477 property bool onScreen: false
482 categoryDelegate.highlightIndex = currentIndex;
483 pageHeader.unfocus();
485 // Cancel any pending preview requests or actions
486 if (previewListView.currentItem.previewData !== undefined) {
487 previewListView.currentItem.previewData.cancelAction();
489 scopeView.scope.cancelActivation();
491 categoryView.correctExpandedCategory();
492 categoryDelegate.highlightIndex = -1;
498 color: Qt.rgba(0, 0, 0, .3)
504 objectName: "previewLoader" + index
505 height: previewListView.height
506 width: previewListView.width
508 source: previewListView.onScreen ?
509 (previewData !== undefined ? previewDelegateMapper.map(previewData.rendererName) : "DashPreviewPlaceholder.qml") : ""
511 onPreviewDataChanged: {
512 if (previewData !== undefined && source.toString().indexOf("DashPreviewPlaceholder.qml") != -1) {
513 previewLoader.opacity = 0;
518 if (previewData !== undefined) {
525 target: previewLoader
529 duration: UbuntuAnimation.BriskDuration
532 property var previewData
533 property bool valid: item !== null
536 if (previewListView.onScreen && previewData !== undefined) {
537 item.previewData = Qt.binding(function() { return previewData })
538 item.isCurrent = Qt.binding(function() { return ListView.isCurrentItem })
543 ignoreUnknownSignals: true
546 previewListView.open = false
550 function closePreviewSpinner() {
552 item.showProcessingAction = false;
559 objectName: "pointerArrow"
561 top: previewListView.bottom
563 leftMargin: previewListView.categoryDelegate !== undefined && previewListView.categoryDelegate.currentItem ?
564 previewListView.categoryDelegate.currentItem.center + (-width + margins) / 2 : 0
566 Behavior on leftMargin {
568 duration: UbuntuAnimation.FastDuration
574 property int margins: previewListView.categoryDelegate ? previewListView.categoryDelegate.margins : 0
575 opacity: previewListView.open ? .5 : 0
577 source: "graphics/tooltip_arrow.png"
580 // TODO: Move as InverseMouseArea to DashPreview
582 objectName: "closePreviewMouseArea"
583 enabled: previewListView.onScreen
586 topMargin: effect.bottomGapPx
589 previewListView.open = false;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list