on xenial help sign in
Make the card carousel use the card creator

Still need some tweaks to get same behaviour as we had before

commitecb7a6542b4b849abc264b11cab66eddfccae770 authorAlbert Astals <albert.astals@canonical.com> dateFri 2 May 2014, 12:32 (12 years ago) parentb3b7847
3 files changed+35−17
plugins/Dash/CardCreator.js+7−5 qml/Dash/CardCarousel.qml+14−10 tests/mocks/Unity/fake_categories.cpp+14−2
plugins/Dash/CardCreator.js+7−5
@@ -159,7 +159,7 @@ function createCardComponent(parent, template, components) {
159159 } \
160160 active: artShapeLoader.active && artShapeLoader.item && artShapeLoader.item.image.status === Image.Ready || false; \
161161 asynchronous: root.asynchronous; \
162− visible: status == Loader.Ready; \
162+ visible: showHeader && status == Loader.Ready; \
163163 sourceComponent: ShaderEffect { \
164164 id: overlay; \
165165 height: ' + height + ' \
@@ -247,7 +247,7 @@ function createCardComponent(parent, template, components) {
247247 objectName: "mascotShapeLoader"; \
248248 asynchronous: root.asynchronous; \
249249 active: mascotImage.status === Image.Ready; \
250− visible: active && status == Loader.Ready; \
250+ visible: showHeader && active && status == Loader.Ready; \
251251 width: units.gu(6); \
252252 height: units.gu(5.625); \
253253 sourceComponent: UbuntuShape { image: mascotImage } \
@@ -267,7 +267,7 @@ function createCardComponent(parent, template, components) {
267267 fillMode: Image.PreserveAspectCrop; \
268268 horizontalAlignment: Image.AlignHCenter; \
269269 verticalAlignment: Image.AlignVCenter; \
270− visible:' + (useMascotShape ? 'false' : 'true') + '; \
270+ visible: showHeader && ' + (useMascotShape ? 'false' : 'true') + '; \
271271 }';
272272 }
273273
@@ -297,7 +297,8 @@ function createCardComponent(parent, template, components) {
297297 } else if (hasMascot) {
298298 titleAnchors = 'anchors.verticalCenter: parent.verticalCenter;'
299299 } else if (inOverlay && hasSubtitle) {
300− titleAnchors = 'anchors.right: parent.right; \
300+ titleAnchors = 'anchors.leftMargin: units.gu(1); \
301+ anchors.right: parent.right; \
301302 anchors.bottom: subtitleLabel.top; \
302303 anchors.bottomMargin: units.dp(2);';
303304 titleAnchors += headerLeftAnchor;
@@ -331,6 +332,7 @@ function createCardComponent(parent, template, components) {
331332 maximumLineCount: 2; \
332333 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \
333334 color: ' + color + '; \
335+ visible: showHeader; \
334336 text: root.title; \
335337 font.weight: components && components["subtitle"] ? Font.DemiBold : Font.Normal; \
336338 horizontalAlignment: root.headerAlignment; \
@@ -345,7 +347,7 @@ function createCardComponent(parent, template, components) {
345347 fontSize: "small"; \
346348 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \
347349 color: ' + color + '; \
348− visible: titleLabel.text; \
350+ visible: showHeader && titleLabel.text; \
349351 text: cardData && cardData["subtitle"] || ""; \
350352 font.weight: Font.Light; \
351353 horizontalAlignment: root.headerAlignment; \
qml/Dash/CardCarousel.qml+14−10
@@ -49,21 +49,25 @@ DashRenderer {
4949 property real fontScale: 1 / selectedItemScaleFactor
5050 property real headerHeight: cardTool.headerHeight / selectedItemScaleFactor
5151
52− itemComponent: Card {
53− id: card
54− objectName: "carouselDelegate" + index
55− fixedHeaderHeight: carousel.headerHeight
56− cardData: model
57− template: cardTool.template
58− components: cardTool.components
52+ itemComponent: Loader {
53+ id: loader
5954
6055 property bool explicitlyScaled
6156 property var model
62−
6357 enabled: false
64− showHeader: explicitlyScaled
6558
66− fontScale: carousel.fontScale
59+ sourceComponent: cardTool.cardComponent
60+ anchors.horizontalCenter: parent.horizontalCenter
61+ onLoaded: {
62+ item.objectName = "carouselDelegate" + index;
63+// item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
64+ item.height = Qt.binding(function() { return cardTool.cardHeight; });
65+ item.cardData = Qt.binding(function() { return model; });
66+ item.template = Qt.binding(function() { return cardTool.template; });
67+ item.components = Qt.binding(function() { return cardTool.components; });
68+ item.fontScale = Qt.binding(function() { return carousel.fontScale; });
69+ item.showHeader = Qt.binding(function() { return loader.explicitlyScaled; });
70+ }
6771 }
6872 }
6973}
tests/mocks/Unity/fake_categories.cpp+14−2
@@ -108,7 +108,12 @@ Categories::data(const QModelIndex& index, int role) const
108108 case RoleRenderer:
109109 {
110110 QVariantMap map;
111− map["category-layout"] = index.row() % 2 == 0 ? "grid" : "carousel";
111+ if (index.row() % 2 == 0) {
112+ map["category-layout"] = "grid";
113+ } else {
114+ map["category-layout"] = "carousel";
115+ map["overlay"] = true;
116+ }
112117 map["card-size"] = "small";
113118 return map;
114119 }
@@ -146,7 +151,14 @@ Categories::data(const QModelIndex& index, int role) const
146151 case RoleRenderer:
147152 {
148153 QVariantMap map;
149− map["category-layout"] = index.row() % 2 == 0 ? "grid" : "carousel";
154+ if (index.row() % 2 == 0) {
155+ map["category-layout"] = "grid";
156+ } else {
157+ map["category-layout"] = "carousel";
158+ map["card-size"] = "medium";
159+ map["collapsed-rows"] = 2;
160+ map["overlay"] = true;
161+ }
150162 map["card-size"] = "small";
151163 return map;
152164 }