on 49bb8b9 help sign in
unity8/qml/Dash/GenericScopeView.qml
837 lines 37 kB history raw
1/*
2 * Copyright (C) 2013-2015 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17import QtQuick 2.4
18import Ubuntu.Components 1.3
19import Ubuntu.Components.Popups 1.3
20import "../Components/SearchHistoryModel"
21import Utils 0.1
22import Unity 0.2
23import Dash 0.1
24import "../Components"
25import "../Components/ListItems" as ListItems
27FocusScope {
28 id: scopeView
30 property bool forceNonInteractive: false
31 property var scope: null
32 property UnitySortFilterProxyModel categories: categoryFilter
33 property bool isCurrent: false
34 property alias moving: categoryView.moving
35 property bool hasBackAction: false
36 property bool enableHeightBehaviorOnNextCreation: false
37 property var categoryView: categoryView
38 readonly property alias subPageShown: subPageLoader.subPageShown
39 readonly property alias extraPanelShown: peExtraPanel.visible
40 property int paginationCount: 0
41 property int paginationIndex: 0
42 property bool visibleToParent: false
43 property alias pageHeaderTotallyVisible: categoryView.pageHeaderTotallyVisible
44 property var holdingList: null
45 property bool wasCurrentOnMoveStart: false
47 property var scopeStyle: ScopeStyle {
48 style: scope ? scope.customizations : {}
49 }
51 readonly property bool processing: scope ? scope.searchInProgress || subPageLoader.processing : false
53 signal backClicked()
55 onScopeChanged: {
56 floatingSeeLess.companionBase = null;
57 }
59 function positionAtBeginning() {
60 categoryView.positionAtBeginning()
61 }
63 function showHeader() {
64 categoryView.showHeader()
65 }
67 function closePreview() {
68 subPageLoader.closeSubPage()
69 }
71 function resetSearch() {
72 categoryView.pageHeader.resetSearch()
73 }
75 property var maybePreviewResult;
76 property int maybePreviewIndex;
77 property var maybePreviewResultsModel;
78 property int maybePreviewLimitedCategoryItemCount;
79 property string maybePreviewCategoryId;
81 function clearMaybePreviewData() {
82 scopeView.maybePreviewResult = undefined;
83 scopeView.maybePreviewIndex = -1;
84 scopeView.maybePreviewResultsModel = undefined;
85 scopeView.maybePreviewLimitedCategoryItemCount = -1;
86 scopeView.maybePreviewCategoryId = "";
87 }
89 function itemClicked(index, result, itemModel, resultsModel, limitedCategoryItemCount, categoryId) {
90 scopeView.maybePreviewResult = result;
91 scopeView.maybePreviewIndex = index;
92 scopeView.maybePreviewResultsModel = resultsModel;
93 scopeView.maybePreviewLimitedCategoryItemCount = limitedCategoryItemCount;
94 scopeView.maybePreviewCategoryId = categoryId;
96 scope.activate(result, categoryId);
97 }
99 function itemPressedAndHeld(index, result, resultsModel, limitedCategoryItemCount, categoryId) {
100 clearMaybePreviewData();
102 openPreview(result, index, resultsModel, limitedCategoryItemCount, categoryId);
103 }
105 function openPreview(result, index, resultsModel, limitedCategoryItemCount, categoryId) {
106 var previewStack = scope.preview(result, categoryId);
107 if (previewStack) {
108 if (limitedCategoryItemCount > 0) {
109 previewLimitModel.model = resultsModel;
110 previewLimitModel.limit = limitedCategoryItemCount;
111 subPageLoader.model = previewLimitModel;
112 } else {
113 subPageLoader.model = resultsModel;
114 }
115 subPageLoader.initialIndex = -1;
116 subPageLoader.initialIndex = index;
117 subPageLoader.categoryId = categoryId;
118 subPageLoader.previewStack = previewStack;
119 subPageLoader.openSubPage("preview");
120 }
121 }
123 Binding {
124 target: scope
125 property: "isActive"
126 value: isCurrent && !subPageLoader.open && (Qt.application.state == Qt.ApplicationActive)
127 }
129 UnitySortFilterProxyModel {
130 id: categoryFilter
131 model: scope ? scope.categories : null
132 dynamicSortFilter: true
133 filterRole: Categories.RoleCount
134 filterRegExp: /^0$/
135 invertMatch: true
136 }
138 onIsCurrentChanged: {
139 if (!holdingList || !holdingList.moving) {
140 wasCurrentOnMoveStart = scopeView.isCurrent;
141 }
142 categoryView.pageHeader.resetSearch();
143 subPageLoader.closeSubPage();
144 }
146 Binding {
147 target: scopeView.scope
148 property: "searchQuery"
149 value: categoryView.pageHeader.searchQuery
150 when: isCurrent
151 }
153 Binding {
154 target: categoryView.pageHeader
155 property: "searchQuery"
156 value: scopeView.scope ? scopeView.scope.searchQuery : ""
157 when: isCurrent
158 }
160 Connections {
161 target: scopeView.scope
162 onShowDash: subPageLoader.closeSubPage()
163 onHideDash: subPageLoader.closeSubPage()
164 onPreviewRequested: { // (QVariant const& result)
165 if (result === scopeView.maybePreviewResult) {
166 openPreview(result,
167 scopeView.maybePreviewIndex,
168 scopeView.maybePreviewResultsModel,
169 scopeView.maybePreviewLimitedCategoryItemCount,
170 scopeView.maybePreviewCategoryId);
172 clearMaybePreviewData();
173 }
174 }
175 }
177 Connections {
178 target: holdingList
179 onMovingChanged: {
180 if (!moving) {
181 wasCurrentOnMoveStart = scopeView.isCurrent;
182 }
183 }
184 }
186 Rectangle {
187 anchors.fill: parent
188 color: scopeView.scopeStyle ? scopeView.scopeStyle.background : "transparent"
189 visible: color != "transparent"
190 }
192 ScopeListView {
193 id: categoryView
194 objectName: "categoryListView"
195 interactive: !forceNonInteractive
197 x: subPageLoader.open ? -width : 0
198 visible: x != -width
199 Behavior on x { UbuntuNumberAnimation { } }
200 width: parent.width
201 height: floatingSeeLess.visible ? parent.height - floatingSeeLess.height + floatingSeeLess.yOffset
202 : parent.height
203 clip: height != parent.height
205 model: scopeView.categories
206 forceNoClip: subPageLoader.open
207 pixelAligned: true
209 property string expandedCategoryId: ""
210 property int runMaximizeAfterSizeChanges: 0
212 readonly property bool pageHeaderTotallyVisible:
213 ((headerItemShownHeight == 0 && categoryView.contentY <= categoryView.originY) || (headerItemShownHeight == categoryView.pageHeader.height))
215 onExpandedCategoryIdChanged: {
216 var firstCreated = firstCreatedIndex();
217 var shrinkingAny = false;
218 var shrinkHeightDifference = 0;
219 for (var i = 0; i < createdItemCount(); ++i) {
220 var baseItem = item(firstCreated + i);
221 if (baseItem.expandable) {
222 var shouldExpand = baseItem.category === expandedCategoryId;
223 if (shouldExpand != baseItem.expanded) {
224 var animate = false;
225 if (!subPageLoader.open) {
226 var animateShrinking = !shouldExpand && baseItem.y + baseItem.item.collapsedHeight + baseItem.seeAllButton.height < categoryView.height;
227 var animateGrowing = shouldExpand && baseItem.y + baseItem.height < categoryView.height;
228 animate = shrinkingAny || animateShrinking || animateGrowing;
229 }
231 if (!shouldExpand) {
232 shrinkingAny = true;
233 shrinkHeightDifference = baseItem.item.expandedHeight - baseItem.item.collapsedHeight;
234 }
236 if (shouldExpand && !subPageLoader.open) {
237 if (!shrinkingAny) {
238 categoryView.maximizeVisibleArea(firstCreated + i, baseItem.item.expandedHeight + baseItem.seeAllButton.height);
239 } else {
240 // If the space that shrinking is smaller than the one we need to grow we'll call maximizeVisibleArea
241 // after the shrink/grow animation ends
242 var growHeightDifference = baseItem.item.expandedHeight - baseItem.item.collapsedHeight;
243 if (growHeightDifference > shrinkHeightDifference) {
244 runMaximizeAfterSizeChanges = 2;
245 } else {
246 runMaximizeAfterSizeChanges = 0;
247 }
248 }
249 }
251 baseItem.expand(shouldExpand, animate);
252 }
253 }
254 }
255 }
257 delegate: DashCategoryBase {
258 id: baseItem
259 objectName: "dashCategory" + category
261 property Item seeAllButton: seeAll
263 readonly property bool expandable: {
264 if (categoryView.model.count === 1) return false;
265 if (cardTool.template && cardTool.template["collapsed-rows"] === 0) return false;
266 if (item && item.expandedHeight > item.collapsedHeight) return true;
267 return false;
268 }
269 property bool expanded: false
270 readonly property string category: categoryId
271 readonly property string headerLink: model.headerLink
272 readonly property var item: rendererLoader.item
274 function expand(expand, animate) {
275 heightBehaviour.enabled = animate;
276 expanded = expand;
277 }
279 CardTool {
280 id: cardTool
281 objectName: "cardTool"
282 count: results ? results.count : 0
283 template: model.renderer
284 components: model.components
285 viewWidth: parent.width
286 }
288 onExpandableChanged: {
289 // This can happen with the VJ that doesn't know how height it will be on creation
290 // so doesn't set expandable until a bit too late for onLoaded
291 if (expandable) {
292 var shouldExpand = baseItem.category === categoryView.expandedCategoryId;
293 baseItem.expand(shouldExpand, false /*animate*/);
294 }
295 }
297 onHeightChanged: rendererLoader.updateRanges();
298 onYChanged: rendererLoader.updateRanges();
300 Loader {
301 id: rendererLoader
302 anchors {
303 top: parent.top
304 left: parent.left
305 right: parent.right
306 topMargin: name != "" ? 0 : units.gu(2)
307 }
309 Behavior on height {
310 id: heightBehaviour
311 enabled: false
312 animation: UbuntuNumberAnimation {
313 duration: UbuntuAnimation.FastDuration
314 onRunningChanged: {
315 if (!running) {
316 heightBehaviour.enabled = false
317 if (categoryView.runMaximizeAfterSizeChanges > 0) {
318 categoryView.runMaximizeAfterSizeChanges--;
319 if (categoryView.runMaximizeAfterSizeChanges == 0) {
320 var firstCreated = categoryView.firstCreatedIndex();
321 for (var i = 0; i < categoryView.createdItemCount(); ++i) {
322 var baseItem = categoryView.item(firstCreated + i);
323 if (baseItem.category === categoryView.expandedCategoryId) {
324 categoryView.maximizeVisibleArea(firstCreated + i, baseItem.item.expandedHeight + baseItem.seeAllButton.height);
325 break;
326 }
327 }
328 }
329 }
330 }
331 }
332 }
333 }
335 readonly property bool expanded: baseItem.expanded || !baseItem.expandable
336 height: expanded ? item.expandedHeight : item.collapsedHeight
338 source: {
339 switch (cardTool.categoryLayout) {
340 case "carousel": return "CardCarousel.qml";
341 case "vertical-journal": return "CardVerticalJournal.qml";
342 case "horizontal-list": return "CardHorizontalList.qml";
343 case "grid":
344 default: return "CardGrid.qml";
345 }
346 }
348 onLoaded: {
349 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
350 item.enableHeightBehavior = scopeView.enableHeightBehaviorOnNextCreation;
351 scopeView.enableHeightBehaviorOnNextCreation = false;
352 }
353 item.model = Qt.binding(function() { return results })
354 item.objectName = Qt.binding(function() { return categoryId })
355 item.scopeStyle = scopeView.scopeStyle;
356 if (baseItem.expandable) {
357 var shouldExpand = baseItem.category === categoryView.expandedCategoryId;
358 baseItem.expand(shouldExpand, false /*animate*/);
359 }
360 updateRanges();
361 if (scope && scope.id === "clickscope" && (categoryId === "predefined" || categoryId === "local")) {
362 // Yeah, hackish :/
363 if (scopeView.width > units.gu(45)) {
364 if (scopeView.width >= units.gu(70)) {
365 cardTool.cardWidth = units.gu(9);
366 } else {
367 cardTool.cardWidth = units.gu(10);
368 }
369 }
370 cardTool.artShapeSize = Qt.size(units.gu(8), units.gu(7.5));
371 }
372 item.cardTool = cardTool;
373 }
375 Component.onDestruction: {
376 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
377 scopeView.enableHeightBehaviorOnNextCreation = item.enableHeightBehaviorOnNextCreation;
378 }
379 }
381 Connections {
382 target: rendererLoader.item
383 onClicked: { // (int index, var result, var item, var itemModel)
384 scopeView.itemClicked(index, result, itemModel, target.model, categoryItemCount(), baseItem.category);
385 }
387 onPressAndHold: { // (int index, var result, var itemModel)
388 scopeView.itemPressedAndHeld(index, result, target.model, categoryItemCount(), baseItem.category);
389 }
391 function categoryItemCount() {
392 var categoryItemCount = -1;
393 if (!rendererLoader.expanded && !seeAllLabel.visible && target.collapsedItemCount > 0) {
394 categoryItemCount = target.collapsedItemCount;
395 }
396 return categoryItemCount;
397 }
398 }
399 Connections {
400 target: categoryView
401 onOriginYChanged: rendererLoader.updateRanges();
402 onContentYChanged: rendererLoader.updateRanges();
403 onHeightChanged: rendererLoader.updateRanges();
404 onContentHeightChanged: rendererLoader.updateRanges();
405 }
406 Connections {
407 target: scopeView
408 onIsCurrentChanged: rendererLoader.updateRanges();
409 onVisibleToParentChanged: rendererLoader.updateRanges();
410 }
411 Connections {
412 target: holdingList
413 onMovingChanged: if (!moving) rendererLoader.updateRanges();
414 }
416 function updateRanges() {
417 // Don't want to create stress by requesting more items during scope
418 // changes so unless you're not part of the visible scopes just return.
419 // For the visible scopes we need to do some work, the previously non visible
420 // scope needs to adjust its ranges so that we define the new visible range,
421 // that still means no creation/destruction of delegates, it's just about changing
422 // the culling of the items so they are actually visible
423 if (holdingList && holdingList.moving && !scopeView.visibleToParent) {
424 return;
425 }
427 if (categoryView.moving) {
428 // Do not update the range if we are overshooting up or down, since we'll come back
429 // to the stable position and delete/create items without any reason
430 if (categoryView.contentY < categoryView.originY) {
431 return;
432 } else if (categoryView.contentHeight - categoryView.originY > categoryView.height &&
433 categoryView.contentY + categoryView.height > categoryView.contentHeight) {
434 return;
435 }
436 }
438 if (item && item.hasOwnProperty("displayMarginBeginning")) {
439 var buffer = wasCurrentOnMoveStart ? categoryView.height * 1.5 : 0;
440 var onViewport = baseItem.y + baseItem.height > 0 &&
441 baseItem.y < categoryView.height;
442 var onBufferViewport = baseItem.y + baseItem.height > -buffer &&
443 baseItem.y < categoryView.height + buffer;
445 if (item.growsVertically) {
446 // A item view creates its delegates synchronously from
447 // -displayMarginBeginning
448 // to
449 // height + displayMarginEnd
450 // Around that area it adds the cacheBuffer area where delegates are created async
451 //
452 // We adjust displayMarginBeginning and displayMarginEnd so
453 // * In non visible scopes nothing is considered visible and we set cacheBuffer
454 // so that creates the items that would be in the viewport asynchronously
455 // * For the current scope set the visible range to the viewport and then
456 // use cacheBuffer to create extra items for categoryView.height * 1.5
457 // to make scrolling nicer by mantaining a higher number of
458 // cached items
459 // * For non current but visible scopes (i.e. when the user changes from one scope
460 // to the next, we set the visible range to the viewport so
461 // items are not culled (invisible) but still use no cacheBuffer
462 // (it will be set once the scope is the current one)
463 var displayMarginBeginning = baseItem.y + rendererLoader.anchors.topMargin;
464 displayMarginBeginning = -Math.max(-displayMarginBeginning, 0);
465 displayMarginBeginning = -Math.min(-displayMarginBeginning, baseItem.height);
466 displayMarginBeginning = Math.round(displayMarginBeginning);
467 var displayMarginEnd = -baseItem.height + seeAll.height + categoryView.height - baseItem.y;
468 displayMarginEnd = -Math.max(-displayMarginEnd, 0);
469 displayMarginEnd = -Math.min(-displayMarginEnd, baseItem.height);
470 displayMarginEnd = Math.round(displayMarginEnd);
472 if (onBufferViewport && (scopeView.isCurrent || scopeView.visibleToParent)) {
473 item.displayMarginBeginning = displayMarginBeginning;
474 item.displayMarginEnd = displayMarginEnd;
475 if (holdingList && holdingList.moving) {
476 // If we are moving we need to reset the cache buffer of the
477 // view that was not visible (i.e. !wasCurrentOnMoveStart) to 0 since
478 // otherwise the cache buffer we had set to preload the items of the
479 // visible range will trigger some item creations and we want move to
480 // be as smooth as possible meaning no need creations
481 if (!wasCurrentOnMoveStart) {
482 item.cacheBuffer = 0;
483 }
484 } else {
485 // Protect us against cases where the item hasn't yet been positioned
486 if (!(categoryView.contentY === 0 && baseItem.y === 0 && index !== 0)) {
487 item.cacheBuffer = categoryView.height * 1.5;
488 }
489 }
490 } else {
491 var visibleRange = baseItem.height + displayMarginEnd + displayMarginBeginning;
492 if (visibleRange < 0) {
493 item.displayMarginBeginning = displayMarginBeginning;
494 item.displayMarginEnd = displayMarginEnd;
495 item.cacheBuffer = 0;
496 } else {
497 // This should be visibleRange/2 in each of the properties
498 // but some item views still (like GridView) like creating sync delegates even if
499 // the visible range is 0 so let's make sure the visible range is negative
500 item.displayMarginBeginning = displayMarginBeginning - visibleRange;
501 item.displayMarginEnd = displayMarginEnd - visibleRange;
502 item.cacheBuffer = visibleRange;
503 }
504 }
505 } else {
506 if (!onBufferViewport) {
507 // If not on the buffered viewport, don't load anything
508 item.displayMarginBeginning = 0;
509 item.displayMarginEnd = -item.innerWidth;
510 item.cacheBuffer = 0;
511 } else {
512 if (onViewport && (scopeView.isCurrent || scopeView.visibleToParent)) {
513 // If on the buffered viewport and the viewport and the on a visible scope
514 // Set displayMargin so that cards are rendered
515 // And if not moving the parent list also give it some extra asynchronously
516 // buffering
517 item.displayMarginBeginning = 0;
518 item.displayMarginEnd = 0;
519 if (holdingList && holdingList.moving) {
520 // If we are moving we need to reset the cache buffer of the
521 // view that was not visible (i.e. !wasCurrentOnMoveStart) to 0 since
522 // otherwise the cache buffer we had set to preload the items of the
523 // visible range will trigger some item creations and we want move to
524 // be as smooth as possible meaning no need creations
525 if (!wasCurrentOnMoveStart) {
526 item.cacheBuffer = 0;
527 }
528 } else {
529 item.cacheBuffer = baseItem.width * 1.5;
530 }
531 } else {
532 // If on the buffered viewport but either not in the real viewport
533 // or in the viewport of the non current scope, use displayMargin + cacheBuffer
534 // to render asynchronously the width of cards
535 item.displayMarginBeginning = 0;
536 item.displayMarginEnd = -item.innerWidth;
537 item.cacheBuffer = item.innerWidth;
538 }
539 }
540 }
541 }
542 }
543 }
545 AbstractButton {
546 id: seeAll
547 objectName: "seeAll"
548 anchors {
549 top: rendererLoader.bottom
550 left: parent.left
551 right: parent.right
552 }
553 height: baseItem.expandable && !baseItem.headerLink ? seeAllLabel.font.pixelSize + units.gu(4) : 0
554 visible: height != 0
556 onClicked: {
557 if (categoryView.expandedCategoryId !== baseItem.category) {
558 categoryView.expandedCategoryId = baseItem.category;
559 floatingSeeLess.companionBase = baseItem;
560 } else {
561 categoryView.expandedCategoryId = "";
562 }
563 }
565 Label {
566 id: seeAllLabel
567 text: baseItem.expanded ? i18n.tr("See less") : i18n.tr("See all")
568 anchors {
569 centerIn: parent
570 verticalCenterOffset: units.gu(-0.5)
571 }
572 fontSize: "small"
573 font.weight: Font.Bold
574 color: scopeStyle ? scopeStyle.foreground : theme.palette.normal.baseText
575 }
576 }
578 Image {
579 visible: index != 0
580 anchors {
581 top: parent.top
582 left: parent.left
583 right: parent.right
584 }
585 fillMode: Image.Stretch
586 source: "graphics/dash_divider_top_lightgrad.png"
587 z: -1
588 }
590 Image {
591 // FIXME Should not rely on model.count but view.count, but ListViewWithPageHeader doesn't expose it yet.
592 visible: index != categoryView.model.count - 1
593 anchors {
594 bottom: seeAll.bottom
595 left: parent.left
596 right: parent.right
597 }
598 fillMode: Image.Stretch
599 source: "graphics/dash_divider_top_darkgrad.png"
600 z: -1
601 }
602 }
604 sectionProperty: "name"
605 sectionDelegate: ListItems.Header {
606 objectName: "dashSectionHeader" + (delegate ? delegate.category : "")
607 readonly property var delegate: categoryView.item(delegateIndex)
608 width: categoryView.width
609 height: section != "" ? units.gu(5) : 0
610 text: section
611 color: scopeStyle ? scopeStyle.foreground : theme.palette.normal.baseText
612 iconName: delegate && delegate.headerLink ? "go-next" : ""
613 onClicked: {
614 if (delegate.headerLink) scopeView.scope.performQuery(delegate.headerLink);
615 }
616 }
618 pageHeader: DashPageHeader {
619 objectName: "scopePageHeader"
620 width: parent.width
621 title: scopeView.scope ? scopeView.scope.name : ""
622 extraPanel: peExtraPanel
623 searchHistory: SearchHistoryModel
624 searchHint: scopeView.scope && scopeView.scope.searchHint || i18n.ctr("Label: Hint for dash search line edit", "Search")
625 scopeHasFilters: scopeView.scope.filters != null
626 activeFiltersCount: scopeView.scope.activeFiltersCount
627 showBackButton: scopeView.hasBackAction
628 searchEntryEnabled: true
629 settingsEnabled: scopeView.scope && scopeView.scope.settings && scopeView.scope.settings.count > 0 || false
630 favoriteEnabled: scopeView.scope && scopeView.scope.id !== "clickscope"
631 favorite: scopeView.scope && scopeView.scope.favorite
632 navigationTag: scopeView.scope ? scopeView.scope.primaryNavigationTag : ""
633 scopeStyle: scopeView.scopeStyle
634 paginationCount: scopeView.paginationCount
635 paginationIndex: scopeView.paginationIndex
637 onBackClicked: scopeView.backClicked()
638 onSettingsClicked: subPageLoader.openSubPage("settings")
639 onFavoriteClicked: scopeView.scope.favorite = !scopeView.scope.favorite
640 onSearchTextFieldFocused: scopeView.showHeader()
641 onClearSearch: { // keepPanelOpen
642 var panelOpen = peExtraPanel.visible;
643 resetSearch(keepPanelOpen);
644 scopeView.scope.resetPrimaryNavigationTag();
645 peExtraPanel.resetNavigation();
646 if ((panelOpen || searchHistory.count > 0) && keepPanelOpen) {
647 openPopup();
648 }
649 }
650 onShowFiltersPopup: { // item
651 PopupUtils.open(Qt.resolvedUrl("FiltersPopover.qml"), item, { "contentWidth": scopeView.width - units.gu(2) } );
652 }
653 }
655 PageHeaderExtraPanel {
656 id: peExtraPanel
657 objectName: "peExtraPanel"
658 width: parent.width >= units.gu(60) ? units.gu(40) : parent.width
659 anchors {
660 top: categoryView.pageHeader.bottom
661 topMargin: -categoryView.pageHeader.signatureLineHeight
662 }
663 z: 1
664 visible: false
666 searchHistory: SearchHistoryModel
667 scope: scopeView.scope
668 windowHeight: scopeView.height
670 onHistoryItemClicked: {
671 SearchHistoryModel.addQuery(text);
672 categoryView.pageHeader.searchQuery = text;
673 }
675 onDashNavigationLeafClicked: {
676 categoryView.pageHeader.closePopup();
677 categoryView.pageHeader.unfocus();
678 }
679 }
680 }
682 Item {
683 id: pullToRefreshClippingItem
684 anchors.left: parent.left
685 anchors.right: parent.right
686 anchors.bottom: parent.bottom
687 height: parent.height - pullToRefresh.contentY - categoryView.pageHeader.height
688 clip: true
690 PullToRefresh {
691 id: pullToRefresh
692 objectName: "pullToRefresh"
693 target: categoryView
695 readonly property real contentY: categoryView.contentY - categoryView.originY
696 y: -contentY - units.gu(5)
698 onRefresh: {
699 refreshing = true
700 scopeView.scope.refresh()
701 }
702 anchors.left: parent.left
703 anchors.right: parent.right
705 Connections {
706 target: scopeView
707 onProcessingChanged: if (!scopeView.processing) pullToRefresh.refreshing = false
708 }
710 style: PullToRefreshScopeStyle {
711 anchors.fill: parent
712 activationThreshold: units.gu(14)
713 }
714 }
715 }
717 AbstractButton {
718 id: floatingSeeLess
719 objectName: "floatingSeeLess"
721 property Item companionTo: companionBase ? companionBase.seeAllButton : null
722 property Item companionBase: null
723 property bool showBecausePosition: false
724 property real yOffset: 0
726 anchors {
727 left: categoryView.left
728 right: categoryView.right
729 }
730 y: parent.height - height + yOffset
731 height: seeLessLabel.font.pixelSize + units.gu(4)
732 visible: companionTo && showBecausePosition
734 onClicked: categoryView.expandedCategoryId = "";
736 function updateVisibility() {
737 var companionPos = companionTo.mapToItem(floatingSeeLess, 0, 0);
738 showBecausePosition = companionPos.y > 0;
740 var posToBase = floatingSeeLess.mapToItem(companionBase, 0, -yOffset).y;
741 yOffset = Math.max(0, companionBase.item.collapsedHeight - posToBase);
742 yOffset = Math.min(yOffset, height);
744 if (!showBecausePosition && categoryView.expandedCategoryId === "") {
745 companionBase = null;
746 }
747 }
749 Label {
750 id: seeLessLabel
751 text: i18n.tr("See less")
752 anchors {
753 centerIn: parent
754 verticalCenterOffset: units.gu(-0.5)
755 }
756 fontSize: "small"
757 font.weight: Font.Bold
758 color: scopeStyle ? scopeStyle.foreground : theme.palette.normal.baseText
759 }
761 Connections {
762 target: floatingSeeLess.companionTo ? categoryView : null
763 onContentYChanged: floatingSeeLess.updateVisibility();
764 }
766 Connections {
767 target: floatingSeeLess.companionTo
768 onYChanged: floatingSeeLess.updateVisibility();
769 }
770 }
772 LimitProxyModel {
773 id: previewLimitModel
774 }
776 Loader {
777 id: subPageLoader
778 objectName: "subPageLoader"
779 visible: x != width
780 width: parent.width
781 height: parent.height
782 anchors.left: categoryView.right
784 property bool open: false
785 property var scope: scopeView.scope
786 property var scopeStyle: scopeView.scopeStyle
787 property int initialIndex: -1
788 property var previewStack;
789 property string categoryId
790 property var model: null
792 readonly property bool processing: item && item.processing || false
793 readonly property int count: item && item.count || 0
794 readonly property int currentIndex: item && item.currentIndex || 0
795 readonly property var currentItem: item && item.currentItem || null
797 property string subPage: ""
798 readonly property bool subPageShown: visible && status === Loader.Ready
800 function openSubPage(page) {
801 subPage = page;
802 }
804 function closeSubPage() {
805 open = false;
806 }
808 source: switch(subPage) {
809 case "preview": return "PreviewListView.qml";
810 case "settings": return "ScopeSettingsPage.qml";
811 default: return "";
812 }
814 onLoaded: {
815 item.scope = Qt.binding(function() { return subPageLoader.scope; } )
816 item.scopeStyle = Qt.binding(function() { return subPageLoader.scopeStyle; } )
817 if (subPage == "preview") {
818 item.open = Qt.binding(function() { return subPageLoader.open; } )
819 item.initialIndex = Qt.binding(function() { return subPageLoader.initialIndex; } )
820 item.model = Qt.binding(function() { return subPageLoader.model; } )
821 item.categoryId = Qt.binding(function() { return subPageLoader.categoryId; } )
822 item.initialIndexPreviewStack = subPageLoader.previewStack;
823 subPageLoader.previewStack = null;
824 }
825 open = true;
826 }
828 onOpenChanged: categoryView.pageHeader.unfocus()
830 onVisibleChanged: if (!visible) subPage = ""
832 Connections {
833 target: subPageLoader.item
834 onBackClicked: subPageLoader.closeSubPage()
835 }
836 }