on xenial help sign in
A bit of refactoring
c336164Daniel d'Andrada
qml/Dash/GenericScopeView.qml+16−25
@@ -47,11 +47,6 @@ FocusScope {
47
47
48 signal backClicked()
48 signal backClicked()
49
49
50− onScopeChanged: {
51− floatingSeeLess.companionTo = null;
52− floatingSeeLess.companionBase = null;
53− }
54−
55 function positionAtBeginning() {
50 function positionAtBeginning() {
56 categoryView.positionAtBeginning()
51 categoryView.positionAtBeginning()
57 }
52 }
@@ -149,7 +144,8 @@ FocusScope {
149 x: previewListView.open ? -width : 0
144 x: previewListView.open ? -width : 0
150 Behavior on x { UbuntuNumberAnimation { } }
145 Behavior on x { UbuntuNumberAnimation { } }
151 width: parent.width
146 width: parent.width
152− height: floatingSeeLess.visible ? parent.height - floatingSeeLess.height + floatingSeeLess.yOffset : parent.height
147+ height: floatingSeeLess.visible ? parent.height - floatingSeeLess.height + floatingSeeLess.yOffset
148+ : parent.height
153 clip: height != parent.height
149 clip: height != parent.height
154
150
155 model: scopeView.categories
151 model: scopeView.categories
@@ -157,7 +153,7 @@ FocusScope {
157 pixelAligned: true
153 pixelAligned: true
158 interactive: !navigationShown
154 interactive: !navigationShown
159
155
160− property string expandedCategoryId: ""
156+ property Item expandedCategoryItem: null
161
157
162 readonly property bool pageHeaderTotallyVisible: scopeView.showPageHeader &&
158 readonly property bool pageHeaderTotallyVisible: scopeView.showPageHeader &&
163 ((headerItemShownHeight == 0 && categoryView.contentY <= categoryView.originY) || (headerItemShownHeight == pageHeaderLoader.item.height))
159 ((headerItemShownHeight == 0 && categoryView.contentY <= categoryView.originY) || (headerItemShownHeight == pageHeaderLoader.item.height))
@@ -168,6 +164,8 @@ FocusScope {
168 highlightWhenPressed: false
164 highlightWhenPressed: false
169 showDivider: false
165 showDivider: false
170
166
167+ property Item seeAllButton: seeAll
168+
171 readonly property bool expandable: {
169 readonly property bool expandable: {
172 if (categoryView.model.count === 1) return false;
170 if (categoryView.model.count === 1) return false;
173 if (cardTool.template && cardTool.template["collapsed-rows"] === 0) return false;
171 if (cardTool.template && cardTool.template["collapsed-rows"] === 0) return false;
@@ -197,7 +195,7 @@ FocusScope {
197 // This can happen with the VJ that doesn't know how height it will be on creation
195 // This can happen with the VJ that doesn't know how height it will be on creation
198 // so doesn't set expandable until a bit too late for onLoaded
196 // so doesn't set expandable until a bit too late for onLoaded
199 if (expandable) {
197 if (expandable) {
200− var shouldExpand = baseItem.category === categoryView.expandedCategoryId;
198+ var shouldExpand = baseItem === categoryView.expandedCategoryItem;
201 baseItem.expand(shouldExpand, false /*animate*/);
199 baseItem.expand(shouldExpand, false /*animate*/);
202 }
200 }
203 }
201 }
@@ -248,7 +246,7 @@ FocusScope {
248 item.objectName = Qt.binding(function() { return categoryId })
246 item.objectName = Qt.binding(function() { return categoryId })
249 item.scopeStyle = scopeView.scopeStyle;
247 item.scopeStyle = scopeView.scopeStyle;
250 if (baseItem.expandable) {
248 if (baseItem.expandable) {
251− var shouldExpand = categoryId === categoryView.expandedCategoryId;
249+ var shouldExpand = baseItem === categoryView.expandedCategoryItem;
252 baseItem.expand(shouldExpand, false /*animate*/);
250 baseItem.expand(shouldExpand, false /*animate*/);
253 }
251 }
254 updateDelegateCreationRange();
252 updateDelegateCreationRange();
@@ -285,13 +283,13 @@ FocusScope {
285 }
283 }
286 Connections {
284 Connections {
287 target: categoryView
285 target: categoryView
288− onExpandedCategoryIdChanged: {
286+ onExpandedCategoryItemChanged: {
289 collapseAllButExpandedCategory();
287 collapseAllButExpandedCategory();
290 }
288 }
291 function collapseAllButExpandedCategory() {
289 function collapseAllButExpandedCategory() {
292 var item = rendererLoader.item;
290 var item = rendererLoader.item;
293 if (baseItem.expandable) {
291 if (baseItem.expandable) {
294− var shouldExpand = categoryId === categoryView.expandedCategoryId;
292+ var shouldExpand = baseItem === categoryView.expandedCategoryItem;
295 if (shouldExpand != baseItem.expanded) {
293 if (shouldExpand != baseItem.expanded) {
296 // If the filter animation will be seen start it, otherwise, just flip the switch
294 // If the filter animation will be seen start it, otherwise, just flip the switch
297 var shrinkingVisible = !shouldExpand && y + item.collapsedHeight + seeAll.height < categoryView.height;
295 var shrinkingVisible = !shouldExpand && y + item.collapsedHeight + seeAll.height < categoryView.height;
@@ -355,12 +353,10 @@ FocusScope {
355 height: seeAllLabel.visible ? seeAllLabel.font.pixelSize + units.gu(4) : 0
353 height: seeAllLabel.visible ? seeAllLabel.font.pixelSize + units.gu(4) : 0
356
354
357 onClicked: {
355 onClicked: {
358− if (categoryView.expandedCategoryId != baseItem.category) {
356+ if (categoryView.expandedCategoryItem !== baseItem) {
359− categoryView.expandedCategoryId = baseItem.category;
357+ categoryView.expandedCategoryItem = baseItem;
360− floatingSeeLess.companionTo = seeAll;
361− floatingSeeLess.companionBase = baseItem;
362 } else {
358 } else {
363− categoryView.expandedCategoryId = "";
359+ categoryView.expandedCategoryItem = null;
364 }
360 }
365 }
361 }
366
362
@@ -455,8 +451,8 @@ FocusScope {
455 id: floatingSeeLess
451 id: floatingSeeLess
456 objectName: "floatingSeeLess"
452 objectName: "floatingSeeLess"
457
453
458− property var companionTo: null
454+ property Item companionTo: companionBase ? companionBase.seeAllButton : null
459− property var companionBase: null
455+ property Item companionBase: categoryView.expandedCategoryItem
460 property bool showBecausePosition: false
456 property bool showBecausePosition: false
461 property real yOffset: 0
457 property real yOffset: 0
462
458
@@ -468,7 +464,7 @@ FocusScope {
468 height: seeLessLabel.font.pixelSize + units.gu(4)
464 height: seeLessLabel.font.pixelSize + units.gu(4)
469 visible: companionTo && showBecausePosition
465 visible: companionTo && showBecausePosition
470
466
471− onClicked: categoryView.expandedCategoryId = "";
467+ onClicked: categoryView.expandedCategoryItem = null;
472
468
473 function updateVisibility() {
469 function updateVisibility() {
474 var companionPos = companionTo.mapToItem(floatingSeeLess, 0, 0);
470 var companionPos = companionTo.mapToItem(floatingSeeLess, 0, 0);
@@ -477,11 +473,6 @@ FocusScope {
477 var posToBase = floatingSeeLess.mapToItem(companionBase, 0, -yOffset).y;
473 var posToBase = floatingSeeLess.mapToItem(companionBase, 0, -yOffset).y;
478 yOffset = Math.max(0, companionBase.item.collapsedHeight - posToBase);
474 yOffset = Math.max(0, companionBase.item.collapsedHeight - posToBase);
479 yOffset = Math.min(yOffset, height);
475 yOffset = Math.min(yOffset, height);
480−
481− if (!showBecausePosition && categoryView.expandedCategoryId === "") {
482− companionTo = null;
483− companionBase = null;
484− }
485 }
476 }
486
477
487 Label {
478 Label {
@@ -502,7 +493,7 @@ FocusScope {
502 }
493 }
503
494
504 Connections {
495 Connections {
505− target: floatingSeeLess.companionTo ? floatingSeeLess.companionTo : null
496+ target: floatingSeeLess.companionTo
506 onYChanged: floatingSeeLess.updateVisibility();
497 onYChanged: floatingSeeLess.updateVisibility();
507 }
498 }
508 }
499 }
tests/qmltests/Dash/tst_GenericScopeView.qml+4−1
@@ -217,7 +217,10 @@ Item {
217 var floatingSeeLess = findChild(genericScopeView, "floatingSeeLess");
217 var floatingSeeLess = findChild(genericScopeView, "floatingSeeLess");
218 mouseClick(seeAll, seeAll.width / 2, seeAll.height / 2);
218 mouseClick(seeAll, seeAll.width / 2, seeAll.height / 2);
219 tryCompare(category, "expanded", true);
219 tryCompare(category, "expanded", true);
220+ tryCompareFunction(function() {
221+ return category.item.height + floatingSeeLess.height ==
220− tryCompareFunction(function() { return category.item.height + floatingSeeLess.height == genericScopeView.height - category.item.displayMarginBeginning - category.item.displayMarginEnd; }, true);
222+ genericScopeView.height - category.item.displayMarginBeginning - category.item.displayMarginEnd;
223+ }, true);
221 mouseClick(floatingSeeLess, floatingSeeLess.width / 2, floatingSeeLess.height / 2);
224 mouseClick(floatingSeeLess, floatingSeeLess.width / 2, floatingSeeLess.height / 2);
222 tryCompare(category, "expanded", false);
225 tryCompare(category, "expanded", false);
223 }
226 }