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