on xenial help sign in
Dynamically change click scope card size according to size Fixes: #1536745
43a1490Andrea Cimitan
qml/Dash/CardGrid.qml+2−1
@@ -20,6 +20,7 @@ import "../Components"
20DashRenderer {
20DashRenderer {
21 id: root
21 id: root
22
22
23+ readonly property real defaultMinimumHorizontalSpacing: units.gu(1)
23 readonly property int collapsedRows: {
24 readonly property int collapsedRows: {
24 if (!cardTool || !cardTool.template || typeof cardTool.template["collapsed-rows"] != "number") return 2;
25 if (!cardTool || !cardTool.template || typeof cardTool.template["collapsed-rows"] != "number") return 2;
25 return cardTool.template["collapsed-rows"];
26 return cardTool.template["collapsed-rows"];
@@ -46,7 +47,7 @@ DashRenderer {
46 ResponsiveGridView {
47 ResponsiveGridView {
47 id: grid
48 id: grid
48 anchors.fill: parent
49 anchors.fill: parent
49− minimumHorizontalSpacing: units.gu(1)
50+ minimumHorizontalSpacing: root.defaultMinimumHorizontalSpacing
50 delegateWidth: cardTool.cardWidth
51 delegateWidth: cardTool.cardWidth
51 delegateHeight: cardTool.cardHeight
52 delegateHeight: cardTool.cardHeight
52 verticalSpacing: units.gu(1)
53 verticalSpacing: units.gu(1)
qml/Dash/GenericScopeView.qml+19−9
@@ -360,17 +360,9 @@ FocusScope {
360 baseItem.expand(shouldExpand, false /*animate*/);
360 baseItem.expand(shouldExpand, false /*animate*/);
361 }
361 }
362 updateRanges();
362 updateRanges();
363+ clickScopeSizingHacks();
363 if (scope && scope.id === "clickscope") {
364 if (scope && scope.id === "clickscope") {
364 if (categoryId === "predefined" || categoryId === "local") {
365 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− }
374 cardTool.artShapeSize = Qt.size(units.gu(8), units.gu(7.5));
366 cardTool.artShapeSize = Qt.size(units.gu(8), units.gu(7.5));
375 item.artShapeStyle = "icon";
367 item.artShapeStyle = "icon";
376 } else {
368 } else {
@@ -388,6 +380,23 @@ FocusScope {
388 }
380 }
389 }
381 }
390
382
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+
391 Connections {
400 Connections {
392 target: rendererLoader.item
401 target: rendererLoader.item
393 onClicked: { // (int index, var result, var item, var itemModel)
402 onClicked: { // (int index, var result, var item, var itemModel)
@@ -417,6 +426,7 @@ FocusScope {
417 target: scopeView
426 target: scopeView
418 onIsCurrentChanged: rendererLoader.updateRanges();
427 onIsCurrentChanged: rendererLoader.updateRanges();
419 onVisibleToParentChanged: rendererLoader.updateRanges();
428 onVisibleToParentChanged: rendererLoader.updateRanges();
429+ onWidthChanged: rendererLoader.clickScopeSizingHacks();
420 }
430 }
421 Connections {
431 Connections {
422 target: holdingList
432 target: holdingList
tests/qmltests/Dash/tst_GenericScopeView.qml+20
@@ -667,6 +667,26 @@ Item {
667 var shape = findChildsByType(artShapeLoader, "UCUbuntuShape");
667 var shape = findChildsByType(artShapeLoader, "UCUbuntuShape");
668 compare(shape.borderSource, undefined);
668 compare(shape.borderSource, undefined);
669 }
669 }
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+ }
670 }
690 }
671 }
691 }
672}
692}