on xenial help sign in
Make "See Less" get stuck at the bottom of the view

Approved by: Daniel d'Andrada, PS Jenkins bot

commitdb4d213728cda2dfd68b868bebbeaee31ca92be0 authorMichał Sawicz <michal.sawicz@canonical.com> dateWed 27 Aug 2014, 15:34 (12 years ago) parent577223c313e109
2 files changed+72−13
qml/Dash/GenericScopeView.qml+65−10 tests/qmltests/Dash/tst_GenericScopeView.qml+7−3
qml/Dash/GenericScopeView.qml+65−10
@@ -144,14 +144,16 @@ FocusScope {
144144 x: previewListView.open ? -width : 0
145145 Behavior on x { UbuntuNumberAnimation { } }
146146 width: parent.width
147− height: parent.height
147+ height: floatingSeeLess.visible ? parent.height - floatingSeeLess.height + floatingSeeLess.yOffset
148+ : parent.height
149+ clip: height != parent.height
148150
149151 model: scopeView.categories
150152 forceNoClip: previewListView.open
151153 pixelAligned: true
152154 interactive: !navigationShown
153155
154− property string expandedCategoryId: ""
156+ property Item expandedCategoryItem: null
155157
156158 readonly property bool pageHeaderTotallyVisible: scopeView.showPageHeader &&
157159 ((headerItemShownHeight == 0 && categoryView.contentY <= categoryView.originY) || (headerItemShownHeight == pageHeaderLoader.item.height))
@@ -162,6 +164,8 @@ FocusScope {
162164 highlightWhenPressed: false
163165 showDivider: false
164166
167+ property Item seeAllButton: seeAll
168+
165169 readonly property bool expandable: {
166170 if (categoryView.model.count === 1) return false;
167171 if (cardTool.template && cardTool.template["collapsed-rows"] === 0) return false;
@@ -191,7 +195,7 @@ FocusScope {
191195 // This can happen with the VJ that doesn't know how height it will be on creation
192196 // so doesn't set expandable until a bit too late for onLoaded
193197 if (expandable) {
194− var shouldExpand = baseItem.category === categoryView.expandedCategoryId;
198+ var shouldExpand = baseItem === categoryView.expandedCategoryItem;
195199 baseItem.expand(shouldExpand, false /*animate*/);
196200 }
197201 }
@@ -242,7 +246,7 @@ FocusScope {
242246 item.objectName = Qt.binding(function() { return categoryId })
243247 item.scopeStyle = scopeView.scopeStyle;
244248 if (baseItem.expandable) {
245− var shouldExpand = categoryId === categoryView.expandedCategoryId;
249+ var shouldExpand = baseItem === categoryView.expandedCategoryItem;
246250 baseItem.expand(shouldExpand, false /*animate*/);
247251 }
248252 updateDelegateCreationRange();
@@ -279,13 +283,13 @@ FocusScope {
279283 }
280284 Connections {
281285 target: categoryView
282− onExpandedCategoryIdChanged: {
286+ onExpandedCategoryItemChanged: {
283287 collapseAllButExpandedCategory();
284288 }
285289 function collapseAllButExpandedCategory() {
286290 var item = rendererLoader.item;
287291 if (baseItem.expandable) {
288− var shouldExpand = categoryId === categoryView.expandedCategoryId;
292+ var shouldExpand = baseItem === categoryView.expandedCategoryItem;
289293 if (shouldExpand != baseItem.expanded) {
290294 // If the filter animation will be seen start it, otherwise, just flip the switch
291295 var shrinkingVisible = !shouldExpand && y + item.collapsedHeight + seeAll.height < categoryView.height;
@@ -346,13 +350,13 @@ FocusScope {
346350 left: parent.left
347351 right: parent.right
348352 }
349− height: seeAllLabel.visible ? seeAllLabel.font.pixelSize + units.gu(6) : 0
353+ height: seeAllLabel.visible ? seeAllLabel.font.pixelSize + units.gu(4) : 0
350354
351355 onClicked: {
352− if (categoryView.expandedCategoryId != baseItem.category) {
353− categoryView.expandedCategoryId = baseItem.category;
356+ if (categoryView.expandedCategoryItem !== baseItem) {
357+ categoryView.expandedCategoryItem = baseItem;
354358 } else {
355− categoryView.expandedCategoryId = "";
359+ categoryView.expandedCategoryItem = null;
356360 }
357361 }
358362
@@ -443,6 +447,57 @@ FocusScope {
443447 }
444448 }
445449
450+ AbstractButton {
451+ id: floatingSeeLess
452+ objectName: "floatingSeeLess"
453+
454+ property Item companionTo: companionBase ? companionBase.seeAllButton : null
455+ property Item companionBase: categoryView.expandedCategoryItem
456+ property bool showBecausePosition: false
457+ property real yOffset: 0
458+
459+ anchors {
460+ left: categoryView.left
461+ right: categoryView.right
462+ }
463+ y: parent.height - height + yOffset
464+ height: seeLessLabel.font.pixelSize + units.gu(4)
465+ visible: companionTo && showBecausePosition
466+
467+ onClicked: categoryView.expandedCategoryItem = null;
468+
469+ function updateVisibility() {
470+ var companionPos = companionTo.mapToItem(floatingSeeLess, 0, 0);
471+ showBecausePosition = companionPos.y > 0;
472+
473+ var posToBase = floatingSeeLess.mapToItem(companionBase, 0, -yOffset).y;
474+ yOffset = Math.max(0, companionBase.item.collapsedHeight - posToBase);
475+ yOffset = Math.min(yOffset, height);
476+ }
477+
478+ Label {
479+ id: seeLessLabel
480+ text: i18n.tr("See less")
481+ anchors {
482+ centerIn: parent
483+ verticalCenterOffset: units.gu(-0.5)
484+ }
485+ fontSize: "small"
486+ font.weight: Font.Bold
487+ color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
488+ }
489+
490+ Connections {
491+ target: floatingSeeLess.companionTo ? categoryView : null
492+ onContentYChanged: floatingSeeLess.updateVisibility();
493+ }
494+
495+ Connections {
496+ target: floatingSeeLess.companionTo
497+ onYChanged: floatingSeeLess.updateVisibility();
498+ }
499+ }
500+
446501 LimitProxyModel {
447502 id: previewLimitModel
448503 }
tests/qmltests/Dash/tst_GenericScopeView.qml+7−3
@@ -227,11 +227,15 @@ Item {
227227 shell.width = units.gu(20)
228228 var categoryListView = findChild(genericScopeView, "categoryListView");
229229 categoryListView.contentY = units.gu(20);
230− var seeAll = findChild(category, "seeAll")
230+ var seeAll = findChild(category, "seeAll");
231+ var floatingSeeLess = findChild(genericScopeView, "floatingSeeLess");
231232 mouseClick(seeAll, seeAll.width / 2, seeAll.height / 2);
232233 tryCompare(category, "expanded", true);
233− tryCompareFunction(function() { return category.item.height == genericScopeView.height - category.item.displayMarginBeginning - category.item.displayMarginEnd; }, true);
234− mouseClick(seeAll, seeAll.width / 2, seeAll.height / 2);
234+ tryCompareFunction(function() {
235+ return category.item.height + floatingSeeLess.height ==
236+ genericScopeView.height - category.item.displayMarginBeginning - category.item.displayMarginEnd;
237+ }, true);
238+ mouseClick(floatingSeeLess, floatingSeeLess.width / 2, floatingSeeLess.height / 2);
235239 tryCompare(category, "expanded", false);
236240 }
237241