2 * Copyright (C) 2012, 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
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) {
38 // Prev non marked text
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) {
48 // End non marked text
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)