18 import Ubuntu.Components 0.1
21 property string contextSnippetText
22 property variant contextSnippetHighlights
23 property string nameText
24 property variant nameHighlights
26 function highlightedText(text, highlights) {
28 var nextIndexToProcess = 0;
29 if (highlights && highlights.length % 2 == 0) {
30 for (var i = 0; i < highlights.length - 1; i += 2) {
31 var highlightStart = highlights[i];
32 var highlightEnd = highlights[i + 1];
33 if (highlightEnd < highlightStart)
35 if (highlightStart < nextIndexToProcess)
37 if (highlightStart != nextIndexToProcess) {
39 hText += text.substr(nextIndexToProcess, highlightStart - nextIndexToProcess);
43 hText +=
"<font color=\"#ffffff\">" + text.substr(highlightStart, highlightEnd - highlightStart + 1) +
"</font>";
44 nextIndexToProcess = highlightEnd + 1;
47 if (nextIndexToProcess != text.length) {
49 hText += text.substr(nextIndexToProcess);
56 objectName:
"actionLabel"
57 anchors.left: parent.left
58 anchors.leftMargin: units.gu(1)
59 anchors.verticalCenter: parent.verticalCenter
60 width: parent.width / 2
62 elide: Text.ElideRight
64 text: highlightedText(nameText, nameHighlights)
69 horizontalAlignment: Text.AlignRight
70 id: contextSnippetLabel
71 objectName:
"contextSnippetLabel"
72 width: parent.width / 2 - units.gu(1)
74 anchors.right: parent.right
75 anchors.rightMargin: units.gu(1)
76 anchors.verticalCenter: parent.verticalCenter
79 elide: Text.ElideRight
81 text: highlightedText(contextSnippetText, contextSnippetHighlights)