on xenial help sign in
Set width of title label when inside the title row Fixes: #1461979
85ad905Albert Astals Cid
plugins/Dash/CardCreator.js+7−3
@@ -155,7 +155,7 @@ var kOverlayLoaderCode = 'Loader { \n\
155
155
156// multiple row version of HeaderRowCode
156// multiple row version of HeaderRowCode
157function kHeaderRowCodeGenerator() {
157function kHeaderRowCodeGenerator() {
158−var kHeaderRowCodeTemplate = 'Row { \n\
158+ var kHeaderRowCodeTemplate = 'Row { \n\
159 id: row; \n\
159 id: row; \n\
160 objectName: "outerRow"; \n\
160 objectName: "outerRow"; \n\
161 property real margins: units.gu(1); \n\
161 property real margins: units.gu(1); \n\
@@ -220,6 +220,7 @@ var kMascotImageCode = 'CroppedImageMinimumSourceSize { \n\
220// %1 is used as anchors of titleLabel
220// %1 is used as anchors of titleLabel
221// %2 is used as color of titleLabel
221// %2 is used as color of titleLabel
222// %3 is used as extra condition for visible of titleLabel
222// %3 is used as extra condition for visible of titleLabel
223+// %4 is used as title width
223var kTitleLabelCode = 'Label { \n\
224var kTitleLabelCode = 'Label { \n\
224 id: titleLabel; \n\
225 id: titleLabel; \n\
225 objectName: "titleLabel"; \n\
226 objectName: "titleLabel"; \n\
@@ -231,6 +232,7 @@ var kTitleLabelCode = 'Label { \n\
231 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
232 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale); \n\
232 color: %2; \n\
233 color: %2; \n\
233 visible: showHeader %3; \n\
234 visible: showHeader %3; \n\
235+ width: %4; \n\
234 text: root.title; \n\
236 text: root.title; \n\
235 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal; \n\
237 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal; \n\
236 horizontalAlignment: root.titleAlignment; \n\
238 horizontalAlignment: root.titleAlignment; \n\
@@ -499,6 +501,7 @@ function cardString(template, components) {
499 var attributesAnchors;
501 var attributesAnchors;
500 var titleContainerAnchors;
502 var titleContainerAnchors;
501 var titleRightAnchor;
503 var titleRightAnchor;
504+ var titleWidth = "undefined";
502
505
503 var extraRightAnchor = '';
506 var extraRightAnchor = '';
504 var extraLeftAnchor = '';
507 var extraLeftAnchor = '';
@@ -542,8 +545,9 @@ function cardString(template, components) {
542 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
545 attributesAnchors = subtitleAnchors + 'top: titleLabel.bottom;\n';
543 }
546 }
544 } else if (hasMascot) {
547 } else if (hasMascot) {
545− // Using row + titleContainer
548+ // Using row without titleContainer
546 titleAnchors = 'verticalCenter: parent.verticalCenter;\n';
549 titleAnchors = 'verticalCenter: parent.verticalCenter;\n';
550+ titleWidth = "parent.width - x";
547 } else {
551 } else {
548 if (headerAsOverlay) {
552 if (headerAsOverlay) {
549 // Using anchors to the overlay
553 // Using anchors to the overlay
@@ -581,7 +585,7 @@ function cardString(template, components) {
581
585
582 // code for different elements
586 // code for different elements
583 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
587 var titleLabelVisibleExtra = (headerAsOverlay ? '&& overlayLoader.active': '');
584− var titleCode = kTitleLabelCode.arg(titleAnchors).arg(titleColor).arg(titleLabelVisibleExtra);
588+ var titleCode = kTitleLabelCode.arg(titleAnchors).arg(titleColor).arg(titleLabelVisibleExtra).arg(titleWidth);
585 var subtitleCode;
589 var subtitleCode;
586 var attributesCode;
590 var attributesCode;
587
591
tests/plugins/Dash/cardcreator/1.res+1
@@ -89,6 +89,7 @@ Label {
89 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
89 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
90 color: root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText;
90 color: root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText;
91 visible: showHeader ;
91 visible: showHeader ;
92+ width: undefined;
92 text: root.title;
93 text: root.title;
93 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
94 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
94 horizontalAlignment: root.titleAlignment;
95 horizontalAlignment: root.titleAlignment;
tests/plugins/Dash/cardcreator/2.res+1
@@ -90,6 +90,7 @@ CroppedImageMinimumSourceSize {
90 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
90 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
91 color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white");
91 color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white");
92 visible: showHeader ;
92 visible: showHeader ;
93+ width: undefined;
93 text: root.title;
94 text: root.title;
94 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
95 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
95 horizontalAlignment: root.titleAlignment;
96 horizontalAlignment: root.titleAlignment;
tests/plugins/Dash/cardcreator/3.res+1
@@ -89,6 +89,7 @@ Label {
89 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
89 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
90 color: root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText;
90 color: root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText;
91 visible: showHeader ;
91 visible: showHeader ;
92+ width: undefined;
92 text: root.title;
93 text: root.title;
93 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
94 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
94 horizontalAlignment: root.titleAlignment;
95 horizontalAlignment: root.titleAlignment;
tests/plugins/Dash/cardcreator/4.res+1
@@ -74,6 +74,7 @@ Label {
74 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
74 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
75 color: root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText;
75 color: root.scopeStyle ? root.scopeStyle.foreground : Theme.palette.normal.baseText;
76 visible: showHeader ;
76 visible: showHeader ;
77+ width: undefined;
77 text: root.title;
78 text: root.title;
78 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
79 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
79 horizontalAlignment: root.titleAlignment;
80 horizontalAlignment: root.titleAlignment;
tests/plugins/Dash/cardcreator/5.res+1
@@ -133,6 +133,7 @@ Label {
133 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
133 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
134 color: root.scopeStyle && overlayLoader.item ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item && overlayLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white");
134 color: root.scopeStyle && overlayLoader.item ? root.scopeStyle.getTextColor(overlayLoader.item.luminance) : (overlayLoader.item && overlayLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white");
135 visible: showHeader && overlayLoader.active;
135 visible: showHeader && overlayLoader.active;
136+ width: undefined;
136 text: root.title;
137 text: root.title;
137 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
138 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
138 horizontalAlignment: root.titleAlignment;
139 horizontalAlignment: root.titleAlignment;
tests/plugins/Dash/cardcreator/6.res+1
@@ -69,6 +69,7 @@ Item {
69 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
69 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
70 color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white");
70 color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white");
71 visible: showHeader ;
71 visible: showHeader ;
72+ width: undefined;
72 text: root.title;
73 text: root.title;
73 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
74 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
74 horizontalAlignment: root.titleAlignment;
75 horizontalAlignment: root.titleAlignment;
tests/plugins/Dash/cardcreator/7.res+1
@@ -91,6 +91,7 @@ CroppedImageMinimumSourceSize {
91 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
91 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
92 color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white");
92 color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white");
93 visible: showHeader ;
93 visible: showHeader ;
94+ width: undefined;
94 text: root.title;
95 text: root.title;
95 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
96 font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
96 horizontalAlignment: root.titleAlignment;
97 horizontalAlignment: root.titleAlignment;
tests/plugins/Dash/cardcreator/8.resnew file+102
@@ -0,0 +1,102 @@
1+AbstractButton {
2+ id: root;
3+ property var components;
4+ property var cardData;
5+ property var artShapeBorderSource: undefined;
6+ property real fontScale: 1.0;
7+ property var scopeStyle: null;
8+ property int titleAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+ enabled: true;
16+
17+Loader {
18+ id: backgroundLoader;
19+ objectName: "backgroundLoader";
20+ anchors.fill: parent;
21+ asynchronous: root.asynchronous;
22+ visible: status == Loader.Ready;
23+ sourceComponent: UbuntuShape {
24+ objectName: "background";
25+ radius: "medium";
26+ color: getColor(0) || "white";
27+ gradientColor: getColor(1) || color;
28+ anchors.fill: parent;
29+ image: backgroundImage.source ? backgroundImage : null;
30+ property real luminance: Style.luminance(color);
31+ property Image backgroundImage: Image {
32+ objectName: "backgroundImage";
33+ source: {
34+ if (cardData && typeof cardData["background"] === "string") return cardData["background"];
35+ else return "";
36+ }
37+ }
38+ function getColor(index) {
39+ if (cardData && typeof cardData["background"] === "object"
40+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
41+ return cardData["background"]["elements"][index];
42+ } else return index === 0 ? "#E9E9E9" : "#E9AAE9";
43+ }
44+ }
45+ }
46+readonly property size artShapeSize: Qt.size(-1, -1);
47+readonly property int headerHeight: row.height;
48+Row {
49+ id: row;
50+ objectName: "outerRow";
51+ property real margins: units.gu(1);
52+ spacing: margins;
53+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight;
54+ anchors { top: parent.top;
55+ topMargin: units.gu(1);
56+left: parent.left;
57+ }
58+ anchors.right: parent.right;
59+ anchors.margins: margins;
60+ anchors.rightMargin: 0;
61+ data: [
62+ CroppedImageMinimumSourceSize {
63+ id: mascotImage;
64+ objectName: "mascotImage";
65+ anchors { verticalCenter: parent.verticalCenter; }
66+ source: cardData && cardData["mascot"] || "";
67+ width: units.gu(6);
68+ height: units.gu(5.625);
69+ horizontalAlignment: Image.AlignHCenter;
70+ verticalAlignment: Image.AlignVCenter;
71+ visible: showHeader;
72+ }
73+,Label {
74+ id: titleLabel;
75+ objectName: "titleLabel";
76+ anchors { verticalCenter: parent.verticalCenter;
77+ }
78+ elide: Text.ElideRight;
79+ fontSize: "small";
80+ wrapMode: Text.Wrap;
81+ maximumLineCount: 2;
82+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale);
83+ color: backgroundLoader.active && backgroundLoader.item && root.scopeStyle ? root.scopeStyle.getTextColor(backgroundLoader.item.luminance) : (backgroundLoader.item && backgroundLoader.item.luminance > 0.7 ? Theme.palette.normal.baseText : "white");
84+ visible: showHeader ;
85+ width: parent.width - x;
86+ text: root.title;
87+ font.weight: cardData && cardData["subtitle"] ? Font.DemiBold : Font.Normal;
88+ horizontalAlignment: root.titleAlignment;
89+ }
90+
91+ ]
92+ }
93+UbuntuShape {
94+ id: touchdown;
95+ objectName: "touchdown";
96+ anchors { fill: backgroundLoader }
97+ visible: root.pressed;
98+ radius: "medium";
99+ borderSource: "radius_pressed.sci"
100+ }
101+implicitHeight: row.y + row.height + units.gu(1);
102+}
tests/plugins/Dash/cardcreator/8.tstnew file+3
@@ -0,0 +1,3 @@
1+template: {"card-background":{"elements":["#E9E9E9","#E9AAE9"],"type":"color"},"card-layout":"vertical","card-size":"medium","category-layout":"grid","collapsed-rows":2}
2+components: {"background":{"field":"background"},"mascot":{"field":"icon"},"title":{"field":"title"},"attributes":{}}
3+result: 8.res