1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cntdisplaytextformatter.h" |
|
19 #include <qcontactdetailfilter.h> |
|
20 #include <qcontactdisplaylabel.h> |
|
21 #include <hbcolorscheme.h> |
|
22 #include <cntdebug.h> |
|
23 #include <QStringList> |
|
24 |
|
25 CntHTMLDisplayTextFormatter::CntHTMLDisplayTextFormatter() |
|
26 { |
|
27 } |
|
28 |
|
29 CntHTMLDisplayTextFormatter::~CntHTMLDisplayTextFormatter() |
|
30 { |
|
31 } |
|
32 |
|
33 QString CntHTMLDisplayTextFormatter::formattedText( const QString aText, const QContactFilter& aCriteria ) |
|
34 { |
|
35 CNT_LOG_ARGS( "filter:" << aText ) |
|
36 if ( aCriteria.type() == QContactFilter::ContactDetailFilter ) |
|
37 { |
|
38 const QContactDetailFilter& filter = static_cast<const QContactDetailFilter&>( aCriteria ); |
|
39 if ( filter.detailDefinitionName() == QContactDisplayLabel::DefinitionName && |
|
40 filter.matchFlags() & QContactFilter::MatchStartsWith ) |
|
41 { |
|
42 QString formattedText; |
|
43 // go through the words (e.g. Lastname, Firstname) and apply list of pattern to them. |
|
44 foreach ( QString text, aText.split(QRegExp("\\s+"), QString::SkipEmptyParts) ) |
|
45 { |
|
46 bool match( false ); |
|
47 // go through every search criteria word |
|
48 foreach (QString pattern, filter.value().toStringList() ) |
|
49 { |
|
50 if ( text.startsWith(pattern, Qt::CaseInsensitive) ) |
|
51 { |
|
52 insertTag( text, pattern.length() ); |
|
53 formattedText.append( text ); |
|
54 match = true; |
|
55 break; // break this inner foreach |
|
56 } |
|
57 } |
|
58 |
|
59 // if no match found, original text is returned |
|
60 if ( !match ) |
|
61 formattedText.append( text ); |
|
62 |
|
63 // put spaces back between words (split() looses them) |
|
64 formattedText.append( " " ); |
|
65 } |
|
66 return formattedText.trimmed(); |
|
67 } |
|
68 } |
|
69 return aText; |
|
70 } |
|
71 |
|
72 void CntHTMLDisplayTextFormatter::insertTag( QString& aText, int aChars ) |
|
73 { |
|
74 QColor highlight = HbColorScheme::color("qtc_lineedit_marker_normal"); |
|
75 QColor color = HbColorScheme::color("qtc_lineedit_selected"); |
|
76 |
|
77 QString start = QString(TAG_START).arg( highlight.name().toUpper() ).arg(color.name().toUpper()); |
|
78 aText.prepend( start ); |
|
79 aText.insert( start.length() + aChars, TAG_END ); |
|
80 } |
|
81 // End of File |
|