on xenial help sign in
Disable expansion for categories with header links.
commit7abda69e85171ef89b89e8b7485d438500c73c18 authorMichał Sawicz <michal.sawicz@canonical.com> dateFri 18 Jul 2014, 13:35 (12 years ago) parente27ae0a
5 files changed+53−16
qml/Dash/CardGrid.qml+1 qml/Dash/DashRenderer.qml+2 qml/Dash/GenericScopeView.qml+21−11 tests/mocks/Unity/fake_categories.cpp+1−1 tests/qmltests/Dash/tst_GenericScopeView.qml+28−4
qml/Dash/CardGrid.qml+1
@@ -27,6 +27,7 @@ DashRenderer {
2727
2828 expandedHeight: grid.totalContentHeight
2929 collapsedHeight: Math.min(grid.contentHeightForRows(collapsedRows), expandedHeight)
30+ collapsedItemCount: collapsedRows * grid.columns
3031 originY: grid.originY
3132
3233 ResponsiveGridView {
qml/Dash/DashRenderer.qml+2
@@ -21,6 +21,8 @@ Item {
2121
2222 property int expandedHeight
2323
24+ property int collapsedItemCount: 0
25+
2426 property int displayMarginBeginning: 0
2527
2628 property int displayMarginEnd: 0
qml/Dash/GenericScopeView.qml+21−11
@@ -186,7 +186,8 @@ FocusScope {
186186 }
187187 }
188188
189− height: baseItem.expandable && !baseItem.expanded ? item.collapsedHeight : item.expandedHeight
189+ readonly property bool expanded: baseItem.expanded || !baseItem.expandable
190+ height: expanded ? item.expandedHeight : item.collapsedHeight
190191
191192 source: {
192193 switch (cardTool.categoryLayout) {
@@ -236,17 +237,22 @@ FocusScope {
236237 // so it's not implemented
237238 scopeView.scope.activate(result)
238239 } else {
239− previewListView.model = target.model;
240− previewListView.currentIndex = -1
241− previewListView.currentIndex = index;
242− previewListView.open = true
240+ openPreview(index);
243241 }
244242 }
245− onPressAndHold: {
246− previewListView.model = target.model;
247− previewListView.currentIndex = -1
243+ onPressAndHold: openPreview(index)
244+
245+ function openPreview(index) {
246+ if (!rendererLoader.expanded && !seeAllLabel.visible && target.collapsedItemCount > 0) {
247+ previewLimitModel.model = target.model;
248+ previewLimitModel.limit = target.collapsedItemCount;
249+ previewListView.model = previewLimitModel;
250+ } else {
251+ previewListView.model = target.model;
252+ }
253+ previewListView.currentIndex = -1;
248254 previewListView.currentIndex = index;
249− previewListView.open = true
255+ previewListView.open = true;
250256 }
251257 }
252258 Connections {
@@ -318,7 +324,7 @@ FocusScope {
318324 left: parent.left
319325 right: parent.right
320326 }
321− height: baseItem.expandable ? seeAllLabel.font.pixelSize + units.gu(6) : 0
327+ height: seeAllLabel.visible ? seeAllLabel.font.pixelSize + units.gu(6) : 0
322328
323329 onClicked: {
324330 if (categoryView.expandedCategoryId != baseItem.category) {
@@ -338,7 +344,7 @@ FocusScope {
338344 fontSize: "small"
339345 font.weight: Font.Bold
340346 color: scopeStyle ? scopeStyle.foreground : "grey"
341− visible: baseItem.expandable
347+ visible: baseItem.expandable && !baseItem.headerLink
342348 }
343349
344350 Image {
@@ -404,6 +410,10 @@ FocusScope {
404410 }
405411 }
406412
413+ LimitProxyModel {
414+ id: previewLimitModel
415+ }
416+
407417 PreviewListView {
408418 id: previewListView
409419 objectName: "previewListView"
tests/mocks/Unity/fake_categories.cpp+1−1
@@ -169,7 +169,7 @@ Categories::data(const QModelIndex& index, int role) const
169169 return map;
170170 }
171171 case RoleHeaderLink:
172− if (index.row() == 1) {
172+ if (index.row() == 1 || index.row() == 4) {
173173 return QString("scope://query/1");
174174 }
175175 return QString();
tests/qmltests/Dash/tst_GenericScopeView.qml+28−4
@@ -176,6 +176,28 @@ Item {
176176 compare(spy.signalArguments[0][0], genericScopeView.scope.categories.data(1, Categories.RoleHeaderLink));
177177 }
178178
179+ function test_headerLink_disable_expansion() {
180+ var categoryListView = findChild(genericScopeView, "categoryListView");
181+ waitForRendering(categoryListView);
182+
183+ categoryListView.contentY = categoryListView.height * 2;
184+
185+ // wait for the item to be there
186+ tryCompareFunction(function() { return findChild(genericScopeView, "dashSectionHeader4") != null; }, true);
187+
188+ var categoryView = findChild(genericScopeView, "dashCategory4");
189+ verify(categoryView, "Can't find the category view.");
190+
191+ var seeAll = findChild(categoryView, "seeAll");
192+ verify(seeAll, "Can't find the seeAll element");
193+
194+ compare(seeAll.height, 0, "SeeAll should be 0-height.");
195+
196+ openPreview(4, 0);
197+
198+ compare(testCase.previewListView.count, 12, "There should only be 12 items in preview.");
199+ }
200+
179201 function test_narrow_delegate_ranges_expand() {
180202 tryCompareFunction(function() { return findChild(genericScopeView, "dashCategory0") !== null; }, true);
181203 var category = findChild(genericScopeView, "dashCategory0")
@@ -220,17 +242,19 @@ Item {
220242 compare(grid.height, grid.expandedHeight, "Only category should always be expanded");
221243 }
222244
223− function openPreview() {
245+ function openPreview(category, delegate) {
246+ if (category === undefined) category = 0;
247+ if (delegate === undefined) delegate = 0;
224248 tryCompareFunction(function() {
225− var cardGrid = findChild(genericScopeView, "0");
249+ var cardGrid = findChild(genericScopeView, category);
226250 if (cardGrid != null) {
227− var tile = findChild(cardGrid, "delegate0");
251+ var tile = findChild(cardGrid, "delegate"+delegate);
228252 return tile != null;
229253 }
230254 return false;
231255 },
232256 true);
233− var tile = findChild(findChild(genericScopeView, "0"), "delegate0");
257+ var tile = findChild(findChild(genericScopeView, category), "delegate"+delegate);
234258 mouseClick(tile, tile.width / 2, tile.height / 2);
235259 tryCompare(testCase.previewListView, "open", true);
236260 tryCompare(testCase.previewListView, "x", 0);