on xenial help sign in
Move title alignment to card creator time
commit40eeb3763d867a9fa6198977ca8ac800fe00e7b2 authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 16 Feb 2016, 16:09 (11 years ago) parent96a9bce
6 files changed+18−30
plugins/Dash/CardCreator.js+18−3 qml/Dash/CardCarousel.qml−1 qml/Dash/CardGrid.qml−1 qml/Dash/CardHorizontalList.qml−1 qml/Dash/CardTool.qml−23 qml/Dash/CardVerticalJournal.qml−1
plugins/Dash/CardCreator.js+18−3
@@ -275,6 +275,7 @@ var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
275275// %2 is used as color of titleLabel
276276// %3 is used as extra condition for visible of titleLabel
277277// %4 is used as title width
278+// %5 is used as horizontal alignment
278279var kTitleLabelCode = 'Label { \n\
279280 id: titleLabel; \n\
280281 objectName: "titleLabel"; \n\
@@ -289,7 +290,7 @@ var kTitleLabelCode = 'Label { \n\
289290 width: %4; \n\
290291 text: root.title; \n\
291292 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal; \n\
292− horizontalAlignment: root.titleAlignment; \n\
293+ horizontalAlignment: %5; \n\
293294 }\n';
294295
295296// %1 is used as extra anchors of emblemIcon
@@ -410,7 +411,6 @@ function cardString(template, components) {
410411 property string backgroundShapeStyle: "inset"; \n\
411412 property real fontScale: 1.0; \n\
412413 property var scopeStyle: null; \n\
413− property int titleAlignment: Text.AlignLeft; \n\
414414 property int fixedHeaderHeight: -1; \n\
415415 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
416416 readonly property string title: cardData && cardData["title"] || ""; \n\
@@ -715,9 +715,24 @@ function cardString(template, components) {
715715 }
716716 }
717717
718+ var titleAlignment = "Text.AlignHCenter";
719+ if (template["card-layout"] === "horizontal"
720+ || typeof components["title"] !== "object"
721+ || components["title"]["align"] === "left") titleAlignment = "Text.AlignLeft";
722+ var keys = ["mascot", "emblem", "subtitle", "attributes", "summary"];
723+ for (var key in keys) {
724+ key = keys[key];
725+ try {
726+ if (typeof components[key] === "string"
727+ || typeof components[key]["field"] === "string") titleAlignment = "Text.AlignLeft";
728+ } catch (e) {
729+ continue;
730+ }
731+ }
732+
718733 // code for different elements
719734 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
720− var titleCode = kTitleLabelCode.arg(titleAnchors).arg(titleColor).arg(titleLabelVisibleExtra).arg(titleWidth);
735+ var titleCode = kTitleLabelCode.arg(titleAnchors).arg(titleColor).arg(titleLabelVisibleExtra).arg(titleWidth).arg(titleAlignment);
721736 var subtitleCode;
722737 var attributesCode;
723738
qml/Dash/CardCarousel.qml−1
@@ -66,7 +66,6 @@ DashRenderer {
6666 item.cardData = Qt.binding(function() { return model; });
6767 item.fontScale = Qt.binding(function() { return carousel.fontScale; });
6868 item.showHeader = Qt.binding(function() { return loader.explicitlyScaled; });
69− item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
7069 item.artShapeStyle = "shadow";
7170 item.scopeStyle = cardCarousel.scopeStyle;
7271 }
qml/Dash/CardGrid.qml−1
@@ -70,7 +70,6 @@ DashRenderer {
7070 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
7171 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
7272 item.cardData = Qt.binding(function() { return model; });
73− item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
7473 item.scopeStyle = root.scopeStyle;
7574 item.artShapeStyle = root.artShapeStyle;
7675 item.backgroundShapeStyle = root.backgroundShapeStyle;
qml/Dash/CardHorizontalList.qml−1
@@ -53,7 +53,6 @@ DashRenderer {
5353 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
5454 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
5555 item.cardData = Qt.binding(function() { return model; });
56− item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
5756 item.scopeStyle = root.scopeStyle;
5857 }
5958 Connections {
qml/Dash/CardTool.qml−23
@@ -139,29 +139,6 @@ Item {
139139 readonly property int headerHeight: cardLoader.item ? cardLoader.item.headerHeight : 0
140140 property size artShapeSize: cardLoader.item ? cardLoader.item.artShapeSize : 0
141141
142− /*!
143− \brief Desired alignment of title
144− */
145− readonly property int titleAlignment: {
146− if (template["card-layout"] === "horizontal"
147− || typeof components["title"] !== "object"
148− || components["title"]["align"] === "left") return Text.AlignLeft;
149−
150− var keys = ["mascot", "emblem", "subtitle", "attributes", "summary"];
151−
152− for (var key in keys) {
153− key = keys[key];
154− try {
155− if (typeof components[key] === "string"
156− || typeof components[key]["field"] === "string") return Text.AlignLeft;
157− } catch (e) {
158− continue;
159− }
160− }
161−
162− return Text.AlignHCenter;
163− }
164−
165142 QtObject {
166143 id: carouselTool
167144
qml/Dash/CardVerticalJournal.qml−1
@@ -72,7 +72,6 @@ DashRenderer {
7272 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
7373 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
7474 item.cardData = Qt.binding(function() { return model; });
75− item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
7675 item.scopeStyle = root.scopeStyle;
7776 }
7877 Connections {