on xenial help sign in
Fix seeAll expansion
6306f75Albert Astals
plugins/Dash/listviewwithpageheader.cpp+10
@@ -409,6 +409,16 @@ void ListViewWithPageHeader::showHeader()
409 }
409 }
410}
410}
411
411
412+Q_INVOKABLE int ListViewWithPageHeader::firstCreatedIndex() const
413+{
414+ return m_firstVisibleIndex;
415+}
416+
417+Q_INVOKABLE int ListViewWithPageHeader::createdItemCount() const
418+{
419+ return m_visibleItems.count();
420+}
421+
412QQuickItem *ListViewWithPageHeader::item(int modelIndex) const
422QQuickItem *ListViewWithPageHeader::item(int modelIndex) const
413{
423{
414 ListItem *item = itemAtIndex(modelIndex);
424 ListItem *item = itemAtIndex(modelIndex);
plugins/Dash/listviewwithpageheader.h+2
@@ -86,6 +86,8 @@ public:
86
86
87 Q_INVOKABLE void positionAtBeginning();
87 Q_INVOKABLE void positionAtBeginning();
88 Q_INVOKABLE void showHeader();
88 Q_INVOKABLE void showHeader();
89+ Q_INVOKABLE int firstCreatedIndex() const;
90+ Q_INVOKABLE int createdItemCount() const;
89 Q_INVOKABLE QQuickItem *item(int modelIndex) const;
91 Q_INVOKABLE QQuickItem *item(int modelIndex) const;
90
92
91 // The index has to be created for this to try to do something
93 // The index has to be created for this to try to do something
qml/Dash/GenericScopeView.qml+46−21
@@ -152,10 +152,50 @@ FocusScope {
152 interactive: !navigationShown
152 interactive: !navigationShown
153
153
154 property string expandedCategoryId: ""
154 property string expandedCategoryId: ""
155+ property bool needMaximizeAfterExpand: false
155
156
156 readonly property bool pageHeaderTotallyVisible: scopeView.showPageHeader &&
157 readonly property bool pageHeaderTotallyVisible: scopeView.showPageHeader &&
157 ((headerItemShownHeight == 0 && categoryView.contentY <= categoryView.originY) || (headerItemShownHeight == pageHeaderLoader.item.height))
158 ((headerItemShownHeight == 0 && categoryView.contentY <= categoryView.originY) || (headerItemShownHeight == pageHeaderLoader.item.height))
158
159
160+ onExpandedCategoryIdChanged: {
161+ var firstCreated = firstCreatedIndex();
162+ var shrinkingAny = false;
163+ var shrinkHeightDifference = 0;
164+ for (var i = 0; i < createdItemCount(); ++i) {
165+ var baseItem = item(firstCreated + i);
166+ if (baseItem.expandable) {
167+ var shouldExpand = baseItem.category === expandedCategoryId;
168+ if (shouldExpand != baseItem.expanded) {
169+
170+ var animate = false;
171+ if (!previewListView.open) {
172+ var animateShrinking = !shouldExpand && baseItem.y + baseItem.item.collapsedHeight + baseItem.seeAll.height < categoryView.height;
173+ var animateGrowing = shouldExpand && baseItem.y + baseItem.height < categoryView.height;
174+ animate = shrinkingAny || animateShrinking || animateGrowing;
175+ }
176+
177+ if (!shouldExpand) {
178+ shrinkingAny = true;
179+ shrinkHeightDifference = baseItem.item.expandedHeight - baseItem.item.collapsedHeight;
180+ }
181+
182+ if (shouldExpand && !previewListView.open) {
183+ if (!shrinkingAny) {
184+ categoryView.maximizeVisibleArea(firstCreated + i, baseItem.item.expandedHeight + baseItem.seeAll.height);
185+ } else {
186+ // If the space that shrkinking is smaller than the one we need to grow we'll call maximizeVisibleArea
187+ // after the shrink/grow animation ends
188+ var growHeightDifference = baseItem.item.expandedHeight - baseItem.item.collapsedHeight;
189+ needMaximizeAfterExpand = growHeightDifference > shrinkHeightDifference;
190+ }
191+ }
192+
193+ baseItem.expand(shouldExpand, animate);
194+ }
195+ }
196+ }
197+ }
198+
159 delegate: ListItems.Base {
199 delegate: ListItems.Base {
160 id: baseItem
200 id: baseItem
161 objectName: "dashCategory" + category
201 objectName: "dashCategory" + category
@@ -172,6 +212,7 @@ FocusScope {
172 readonly property string category: categoryId
212 readonly property string category: categoryId
173 readonly property string headerLink: model.headerLink
213 readonly property string headerLink: model.headerLink
174 readonly property var item: rendererLoader.item
214 readonly property var item: rendererLoader.item
215+ readonly property var seeAll: seeAll
175
216
176 function expand(expand, animate) {
217 function expand(expand, animate) {
177 heightBehaviour.enabled = animate;
218 heightBehaviour.enabled = animate;
@@ -212,9 +253,14 @@ FocusScope {
212 id: heightBehaviour
253 id: heightBehaviour
213 enabled: false
254 enabled: false
214 animation: UbuntuNumberAnimation {
255 animation: UbuntuNumberAnimation {
256+ duration: categoryView.needMaximizeAfterExpand ? UbuntuAnimation.FastDuration / 2 : UbuntuAnimation.FastDuration
215 onRunningChanged: {
257 onRunningChanged: {
216 if (!running) {
258 if (!running) {
217 heightBehaviour.enabled = false
259 heightBehaviour.enabled = false
260+ if (categoryView.needMaximizeAfterExpand && baseItem.category === categoryView.expandedCategoryId) {
261+ categoryView.maximizeVisibleArea(index, item.expandedHeight + seeAll.height);
262+ categoryView.needMaximizeAfterExpand = false;
263+ }
218 }
264 }
219 }
265 }
220 }
266 }
@@ -279,27 +325,6 @@ FocusScope {
279 }
325 }
280 Connections {
326 Connections {
281 target: categoryView
327 target: categoryView
282− onExpandedCategoryIdChanged: {
283− collapseAllButExpandedCategory();
284− }
285− function collapseAllButExpandedCategory() {
286− var item = rendererLoader.item;
287− if (baseItem.expandable) {
288− var shouldExpand = categoryId === categoryView.expandedCategoryId;
289− if (shouldExpand != baseItem.expanded) {
290− // If the filter animation will be seen start it, otherwise, just flip the switch
291− var shrinkingVisible = !shouldExpand && y + item.collapsedHeight + seeAll.height < categoryView.height;
292− var growingVisible = shouldExpand && y + height < categoryView.height;
293− if (!previewListView.open || shouldExpand) {
294− var animate = shrinkingVisible || growingVisible;
295− baseItem.expand(shouldExpand, animate)
296− if (shouldExpand && !previewListView.open) {
297− categoryView.maximizeVisibleArea(index, item.expandedHeight + seeAll.height);
298− }
299− }
300− }
301− }
302− }
303 onOriginYChanged: rendererLoader.updateDelegateCreationRange();
328 onOriginYChanged: rendererLoader.updateDelegateCreationRange();
304 onContentYChanged: rendererLoader.updateDelegateCreationRange();
329 onContentYChanged: rendererLoader.updateDelegateCreationRange();
305 onHeightChanged: rendererLoader.updateDelegateCreationRange();
330 onHeightChanged: rendererLoader.updateDelegateCreationRange();