on xenial help sign in
Dynamically change click scope card size according to size Fixes: #1536745

Approved by: Unity8 CI Bot, Albert Astals Cid

commit43a14903ad2550898608c2f2a90dfc0f7825a71c authorAndrea Cimitan <andrea.cimitan@gmail.com> dateFri 29 Jan 2016, 11:52 (11 years ago) parent59205c1e97c3ac
3 files changed+41−10
qml/Dash/CardGrid.qml+2−1 qml/Dash/GenericScopeView.qml+19−9 tests/qmltests/Dash/tst_GenericScopeView.qml+20
qml/Dash/CardGrid.qml+2−1
@@ -20,6 +20,7 @@ import "../Components"
2020DashRenderer {
2121 id: root
2222
23+ readonly property real defaultMinimumHorizontalSpacing: units.gu(1)
2324 readonly property int collapsedRows: {
2425 if (!cardTool || !cardTool.template || typeof cardTool.template["collapsed-rows"] != "number") return 2;
2526 return cardTool.template["collapsed-rows"];
@@ -46,7 +47,7 @@ DashRenderer {
4647 ResponsiveGridView {
4748 id: grid
4849 anchors.fill: parent
49− minimumHorizontalSpacing: units.gu(1)
50+ minimumHorizontalSpacing: root.defaultMinimumHorizontalSpacing
5051 delegateWidth: cardTool.cardWidth
5152 delegateHeight: cardTool.cardHeight
5253 verticalSpacing: units.gu(1)
qml/Dash/GenericScopeView.qml+19−9
@@ -360,17 +360,9 @@ FocusScope {
360360 baseItem.expand(shouldExpand, false /*animate*/);
361361 }
362362 updateRanges();
363+ clickScopeSizingHacks();
363364 if (scope && scope.id === "clickscope") {
364365 if (categoryId === "predefined" || categoryId === "local") {
365− // Yeah, hackish :/
366− if (scopeView.width > units.gu(45)) {
367− if (scopeView.width >= units.gu(70)) {
368− cardTool.cardWidth = units.gu(11);
369− item.minimumHorizontalSpacing = units.gu(5)
370− } else {
371− cardTool.cardWidth = units.gu(10);
372− }
373− }
374366 cardTool.artShapeSize = Qt.size(units.gu(8), units.gu(7.5));
375367 item.artShapeStyle = "icon";
376368 } else {
@@ -388,6 +380,23 @@ FocusScope {
388380 }
389381 }
390382
383+ function clickScopeSizingHacks() {
384+ if (scope && scope.id === "clickscope" &&
385+ (categoryId === "predefined" || categoryId === "local")) {
386+ // Yeah, hackish :/
387+ if (scopeView.width > units.gu(45)) {
388+ if (scopeView.width >= units.gu(70)) {
389+ cardTool.cardWidth = units.gu(11);
390+ item.minimumHorizontalSpacing = units.gu(5);
391+ return;
392+ } else {
393+ cardTool.cardWidth = units.gu(10);
394+ }
395+ }
396+ item.minimumHorizontalSpacing = item.defaultMinimumHorizontalSpacing;
397+ }
398+ }
399+
391400 Connections {
392401 target: rendererLoader.item
393402 onClicked: { // (int index, var result, var item, var itemModel)
@@ -417,6 +426,7 @@ FocusScope {
417426 target: scopeView
418427 onIsCurrentChanged: rendererLoader.updateRanges();
419428 onVisibleToParentChanged: rendererLoader.updateRanges();
429+ onWidthChanged: rendererLoader.clickScopeSizingHacks();
420430 }
421431 Connections {
422432 target: holdingList
tests/qmltests/Dash/tst_GenericScopeView.qml+20
@@ -667,6 +667,26 @@ Item {
667667 var shape = findChildsByType(artShapeLoader, "UCUbuntuShape");
668668 compare(shape.borderSource, undefined);
669669 }
670+
671+ function test_clickScopeSizing() {
672+ genericScopeView.scope = scopes.getScopeFromAll("clickscope");
673+ waitForRendering(genericScopeView);
674+
675+ var categoryListView = findChild(genericScopeView, "categoryListView");
676+ waitForRendering(categoryListView);
677+
678+ var categorypredefined = findChild(categoryListView, "dashCategorypredefined");
679+ waitForRendering(categorypredefined);
680+
681+ var cardTool = findChild(categorypredefined, "cardTool");
682+
683+ compare(cardTool.cardWidth, units.gu(11));
684+ shell.width = units.gu(46);
685+ waitForRendering(genericScopeView);
686+ compare(cardTool.cardWidth, units.gu(10));
687+
688+ shell.width = units.gu(120)
689+ }
670690 }
671691 }
672692}