on xenial help sign in
Some overlay height fixes
commitc4bfea47c4658da7f8c792fc2fa73072c6c3a499 authorAlbert Astals <albert.astals@canonical.com> dateFri 2 May 2014, 15:56 (12 years ago) parentecb7a65
6 files changed+32−24
plugins/Dash/CardCreator.js+26−21 qml/Dash/CardCarousel.qml+1−1 qml/Dash/CardTool.qml+1 tests/mocks/Unity/fake_categories.cpp+1 tests/mocks/Unity/fake_resultsmodel.cpp+2−1 tests/qmltests/Dash/tst_Card.qml+1−1
plugins/Dash/CardCreator.js+26−21
@@ -30,6 +30,7 @@ function createCardComponent(parent, template, components) {
3030 property var cardData; \
3131 property real fontScale: 1.0; \
3232 property int headerAlignment: Text.AlignLeft; \
33+ property int fixedHeaderHeight: -1; \
3334 property size fixedArtShapeSize: Qt.size(-1, -1); \
3435 readonly property string title: cardData && cardData["title"] || ""; \
3536 property bool asynchronous: true; \
@@ -41,12 +42,11 @@ function createCardComponent(parent, template, components) {
4142 var artAndSummary = hasArt && hasSummary;
4243 var isHorizontal = template["card-layout"] === "horizontal";
4344 var hasBackground = !isHorizontal && (template["card-background"] || components["background"] || artAndSummary);
44− var inOverlay = hasArt && template && template["overlay"] === true;
4545 var hasTitle = components["title"] || false;
4646 var hasMascot = components["mascot"] || false;
47+ var inOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
4748 var hasSubtitle = components["subtitle"] || false;
4849 var hasHeaderRow = hasMascot && hasTitle;
49− var mascotImageHeight = 'units.gu(5.625)';
5050
5151 if (hasBackground) {
5252 code += 'Loader {\
@@ -88,12 +88,12 @@ function createCardComponent(parent, template, components) {
8888 code += 'readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);'
8989 var imageWidthHeight;
9090 if (isHorizontal) {
91− if (hasMascot) {
91+ if (hasMascot || hasTitle) {
9292 imageWidthHeight = 'width: height * artShape.aspect; \
93− height: mascotImage.height + 2 * units.gu(1);'
93+ height: headerHeight;'
9494 } else {
9595 imageWidthHeight = 'width: height * artShape.aspect; \
96− height: ' + mascotImageHeight + ' + 2 * units.gu(1);'
96+ height: units.gu(8.625)';
9797 }
9898 } else {
9999 imageWidthHeight = 'width: root.width; \
@@ -144,12 +144,7 @@ function createCardComponent(parent, template, components) {
144144 }
145145
146146 if (inOverlay) {
147− var height;
148− if (hasMascot) {
149− var height = 'mascotImage.height + 2 * units.gu(1);';
150− } else {
151− var height = mascotImageHeight + ' + 2 * units.gu(1);';
152− }
147+ var height = 'fixedHeaderHeight != -1 ? fixedHeaderHeight : headerHeight;';
153148 code += 'Loader { \
154149 id: overlayLoader; \
155150 anchors { \
@@ -219,6 +214,7 @@ function createCardComponent(parent, template, components) {
219214 }
220215
221216 if (hasHeaderRow) {
217+ code += 'readonly property int headerHeight: row.height + row.margins * 2;'
222218 code += 'Row { \
223219 id: row; \
224220 objectName: "outerRow"; \
@@ -237,6 +233,7 @@ function createCardComponent(parent, template, components) {
237233 anchors += headerLeftAnchor;
238234 anchors += 'anchors.leftMargin: units.gu(1);'
239235 anchors += headerVerticalAnchors;
236+ code += 'readonly property int headerHeight: mascotImage.height + units.gu(1) * 2;'
240237 } else {
241238 anchors = "anchors.verticalCenter: parent.verticalCenter;"
242239 }
@@ -262,7 +259,7 @@ function createCardComponent(parent, template, components) {
262259 readonly property int maxSize: Math.max(width, height) * 4; \
263260 source: cardData && cardData["mascot"]; \
264261 width: units.gu(6); \
265− height: ' + mascotImageHeight + '; \
262+ height: units.gu(5.625); \
266263 sourceSize { width: maxSize; height: maxSize } \
267264 fillMode: Image.PreserveAspectCrop; \
268265 horizontalAlignment: Image.AlignHCenter; \
@@ -296,16 +293,17 @@ function createCardComponent(parent, template, components) {
296293 width: parent.width - x;';
297294 } else if (hasMascot) {
298295 titleAnchors = 'anchors.verticalCenter: parent.verticalCenter;'
299− } else if (inOverlay && hasSubtitle) {
300− titleAnchors = 'anchors.leftMargin: units.gu(1); \
296+ } else if (inOverlay) {
297+ titleAnchors = 'anchors.left: parent.left; \
298+ anchors.leftMargin: units.gu(1); \
301299 anchors.right: parent.right; \
302− anchors.bottom: subtitleLabel.top; \
303− anchors.bottomMargin: units.dp(2);';
304− titleAnchors += headerLeftAnchor;
300+ anchors.top: overlayLoader.top; \
301+ anchors.topMargin: units.gu(1);';
305302 subtitleAnchors = 'anchors.left: titleLabel.left; \
306303 anchors.leftMargin: titleLabel.leftMargin; \
307− anchors.right: titleLabel.right;';
308− subtitleAnchors += headerVerticalAnchors;
304+ anchors.right: titleLabel.right; \
305+ anchors.top: titleLabel.bottom; \
306+ anchors.topMargin: units.dp(2);';
309307 } else {
310308 titleAnchors = "anchors.right: parent.right;";
311309 if (hasMascot) {
@@ -321,6 +319,13 @@ function createCardComponent(parent, template, components) {
321319 anchors.top: titleLabel.bottom; \
322320 anchors.topMargin: units.dp(2);';
323321 }
322+ if (!hasHeaderRow) {
323+ if (hasSubtitle) {
324+ code += 'readonly property int headerHeight: subtitleLabel.y + subtitleLabel.height - titleLabel.y + titleLabel.anchors.topMargin * 2 + subtitleLabel.anchors.topMargin;'
325+ } else {
326+ code += 'readonly property int headerHeight: titleLabel.height + titleLabel.anchors.topMargin * 2;'
327+ }
328+ }
324329
325330 code += 'Label { \
326331 id: titleLabel; \
@@ -332,7 +337,7 @@ function createCardComponent(parent, template, components) {
332337 maximumLineCount: 2; \
333338 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \
334339 color: ' + color + '; \
335− visible: showHeader; \
340+ visible: showHeader ' + (inOverlay ? '&& overlayLoader.active': '') + '; \
336341 text: root.title; \
337342 font.weight: components && components["subtitle"] ? Font.DemiBold : Font.Normal; \
338343 horizontalAlignment: root.headerAlignment; \
@@ -347,7 +352,7 @@ function createCardComponent(parent, template, components) {
347352 fontSize: "small"; \
348353 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \
349354 color: ' + color + '; \
350− visible: showHeader && titleLabel.text; \
355+ visible: titleLabel.visible && titleLabel.text; \
351356 text: cardData && cardData["subtitle"] || ""; \
352357 font.weight: Font.Light; \
353358 horizontalAlignment: root.headerAlignment; \
qml/Dash/CardCarousel.qml+1−1
@@ -60,7 +60,7 @@ DashRenderer {
6060 anchors.horizontalCenter: parent.horizontalCenter
6161 onLoaded: {
6262 item.objectName = "carouselDelegate" + index;
63−// item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
63+ item.fixedHeaderHeight = Qt.binding(function() { return carousel.headerHeight; });
6464 item.height = Qt.binding(function() { return cardTool.cardHeight; });
6565 item.cardData = Qt.binding(function() { return model; });
6666 item.template = Qt.binding(function() { return cardTool.template; });
qml/Dash/CardTool.qml+1
@@ -125,6 +125,7 @@ Item {
125125 /*!
126126 type:real \brief Height of the card's header.
127127 */
128+ readonly property int headerHeight: cardLoader.item ? cardLoader.item.headerHeight : 0
128129 readonly property size artShapeSize: cardLoader.item ? cardLoader.item.artShapeSize : 0
129130
130131 /*!
tests/mocks/Unity/fake_categories.cpp+1
@@ -169,6 +169,7 @@ Categories::data(const QModelIndex& index, int role) const
169169 artMap["field"] = "art";
170170 map["art"] = artMap;
171171 map["title"] = "HOLA";
172+ map["subtitle"] = "HOLA";
172173 return map;
173174 }
174175 case RoleProgressSource:
tests/mocks/Unity/fake_resultsmodel.cpp+2−1
@@ -99,10 +99,11 @@ ResultsModel::data(const QModelIndex& index, int role) const
9999 case RoleResult:
100100 return QString();
101101 case RoleTitle:
102− return QString("Title.%1.%2").arg(m_categoryId).arg(index.row());
102+ return QString("Title.%1.%2 a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a").arg(m_categoryId).arg(index.row());
103103 case RoleArt:
104104 return qmlDirectory() + "graphics/applicationIcons/dash.png";
105105 case RoleSubtitle:
106+ return QString("Subtitle.%1.%2 a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a").arg(m_categoryId).arg(index.row());
106107 case RoleMascot:
107108 case RoleEmblem:
108109 case RoleOldPrice:
tests/qmltests/Dash/tst_Card.qml+1−1
@@ -116,8 +116,8 @@ Rectangle {
116116 item.cardData = Qt.binding(function() { return Helpers.mapData(dataArea.text, cardTool.components, dataError); });
117117 item.width = Qt.binding(function() { return cardTool.cardWidth || item.implicitWidth; });
118118 item.height = Qt.binding(function() { return cardTool.cardHeight || item.implicitHeight; });
119+ item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
119120 }
120−
121121 }
122122
123123 Rectangle {