on xenial help sign in
Move title alignment to card creator time
40eeb37Albert Astals Cid
plugins/Dash/CardCreator.js+18−3
@@ -275,6 +275,7 @@ var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
275// %2 is used as color of titleLabel
275// %2 is used as color of titleLabel
276// %3 is used as extra condition for visible of titleLabel
276// %3 is used as extra condition for visible of titleLabel
277// %4 is used as title width
277// %4 is used as title width
278+// %5 is used as horizontal alignment
278var kTitleLabelCode = 'Label { \n\
279var kTitleLabelCode = 'Label { \n\
279 id: titleLabel; \n\
280 id: titleLabel; \n\
280 objectName: "titleLabel"; \n\
281 objectName: "titleLabel"; \n\
@@ -289,7 +290,7 @@ var kTitleLabelCode = 'Label { \n\
289 width: %4; \n\
290 width: %4; \n\
290 text: root.title; \n\
291 text: root.title; \n\
291 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal; \n\
292 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal; \n\
292− horizontalAlignment: root.titleAlignment; \n\
293+ horizontalAlignment: %5; \n\
293 }\n';
294 }\n';
294
295
295// %1 is used as extra anchors of emblemIcon
296// %1 is used as extra anchors of emblemIcon
@@ -410,7 +411,6 @@ function cardString(template, components) {
410 property string backgroundShapeStyle: "inset"; \n\
411 property string backgroundShapeStyle: "inset"; \n\
411 property real fontScale: 1.0; \n\
412 property real fontScale: 1.0; \n\
412 property var scopeStyle: null; \n\
413 property var scopeStyle: null; \n\
413− property int titleAlignment: Text.AlignLeft; \n\
414 property int fixedHeaderHeight: -1; \n\
414 property int fixedHeaderHeight: -1; \n\
415 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
415 property size fixedArtShapeSize: Qt.size(-1, -1); \n\
416 readonly property string title: cardData && cardData["title"] || ""; \n\
416 readonly property string title: cardData && cardData["title"] || ""; \n\
@@ -715,9 +715,24 @@ function cardString(template, components) {
715 }
715 }
716 }
716 }
717
717
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+
718 // code for different elements
733 // code for different elements
719 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
734 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);
721 var subtitleCode;
736 var subtitleCode;
722 var attributesCode;
737 var attributesCode;
723
738
qml/Dash/CardCarousel.qml−1
@@ -66,7 +66,6 @@ DashRenderer {
66 item.cardData = Qt.binding(function() { return model; });
66 item.cardData = Qt.binding(function() { return model; });
67 item.fontScale = Qt.binding(function() { return carousel.fontScale; });
67 item.fontScale = Qt.binding(function() { return carousel.fontScale; });
68 item.showHeader = Qt.binding(function() { return loader.explicitlyScaled; });
68 item.showHeader = Qt.binding(function() { return loader.explicitlyScaled; });
69− item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
70 item.artShapeStyle = "shadow";
69 item.artShapeStyle = "shadow";
71 item.scopeStyle = cardCarousel.scopeStyle;
70 item.scopeStyle = cardCarousel.scopeStyle;
72 }
71 }
qml/Dash/CardGrid.qml−1
@@ -70,7 +70,6 @@ DashRenderer {
70 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
70 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
71 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
71 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
72 item.cardData = Qt.binding(function() { return model; });
72 item.cardData = Qt.binding(function() { return model; });
73− item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
74 item.scopeStyle = root.scopeStyle;
73 item.scopeStyle = root.scopeStyle;
75 item.artShapeStyle = root.artShapeStyle;
74 item.artShapeStyle = root.artShapeStyle;
76 item.backgroundShapeStyle = root.backgroundShapeStyle;
75 item.backgroundShapeStyle = root.backgroundShapeStyle;
qml/Dash/CardHorizontalList.qml−1
@@ -53,7 +53,6 @@ DashRenderer {
53 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
53 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
54 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
54 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
55 item.cardData = Qt.binding(function() { return model; });
55 item.cardData = Qt.binding(function() { return model; });
56− item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
57 item.scopeStyle = root.scopeStyle;
56 item.scopeStyle = root.scopeStyle;
58 }
57 }
59 Connections {
58 Connections {
qml/Dash/CardTool.qml−23
@@ -139,29 +139,6 @@ Item {
139 readonly property int headerHeight: cardLoader.item ? cardLoader.item.headerHeight : 0
139 readonly property int headerHeight: cardLoader.item ? cardLoader.item.headerHeight : 0
140 property size artShapeSize: cardLoader.item ? cardLoader.item.artShapeSize : 0
140 property size artShapeSize: cardLoader.item ? cardLoader.item.artShapeSize : 0
141
141
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−
165 QtObject {
142 QtObject {
166 id: carouselTool
143 id: carouselTool
167
144
qml/Dash/CardVerticalJournal.qml−1
@@ -72,7 +72,6 @@ DashRenderer {
72 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
72 item.fixedArtShapeSize = Qt.binding(function() { return cardTool.artShapeSize; });
73 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
73 item.fixedHeaderHeight = Qt.binding(function() { return cardTool.headerHeight; });
74 item.cardData = Qt.binding(function() { return model; });
74 item.cardData = Qt.binding(function() { return model; });
75− item.titleAlignment = Qt.binding(function() { return cardTool.titleAlignment; });
76 item.scopeStyle = root.scopeStyle;
75 item.scopeStyle = root.scopeStyle;
77 }
76 }
78 Connections {
77 Connections {