messagingapp/msgui/unifiedviewer/src/univieweraddresswidget.cpp
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     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 "univieweraddresswidget.h"
       
    19 #include "univiewerfeeder_p.h"
       
    20 // SYSTEM INCLUDES
       
    21 #include <HbApplication>
       
    22 #include <QString>
       
    23 #include <QTextCursor>
       
    24 #include <HbMenu>
       
    25 
       
    26 // USER INCLUDES
       
    27 #include "unitexteditor.h"
       
    28 #include "debugtraces.h"
       
    29 
       
    30 // LOCAL CONSTANTS
       
    31 const QString ADDRESS_SEPARATOR("; ");
       
    32 
       
    33 //----------------------------------------------------------------------------
       
    34 // UniViewerAddressWidget::UniViewerAddressWidget
       
    35 // @see header file
       
    36 //----------------------------------------------------------------------------
       
    37 UniViewerAddressWidget::UniViewerAddressWidget(QGraphicsItem *parent) :
       
    38     HbWidget(parent), mAddress(NULL)
       
    39 {
       
    40     mAddress = new UniTextEditor(this);
       
    41     HbStyle::setItemName(mAddress, "addressField");
       
    42 
       
    43     connect(mAddress, SIGNAL(aboutToShowContextMenu(HbMenu *,QPointF)), this,
       
    44         SLOT(handleAboutToShowContextMenu(HbMenu *,QPointF)));
       
    45 
       
    46 }
       
    47 
       
    48 //----------------------------------------------------------------------------
       
    49 // UniViewerAddressWidget::~UniViewerAddressWidget
       
    50 // @see header file
       
    51 //----------------------------------------------------------------------------
       
    52 UniViewerAddressWidget::~UniViewerAddressWidget()
       
    53 {
       
    54 }
       
    55 
       
    56 //----------------------------------------------------------------------------
       
    57 // UniViewerAddressWidget::populate
       
    58 // @see header file
       
    59 //----------------------------------------------------------------------------
       
    60 void UniViewerAddressWidget::populate(const QString &label,
       
    61                                       const QString &address,
       
    62                                       const QString &alias)
       
    63 {
       
    64 
       
    65     QTextCursor cursor(mAddress->document());
       
    66 
       
    67     QTextCharFormat addressFormat = cursor.charFormat();
       
    68     addressFormat.setFontWeight(QFont::Bold);
       
    69     addressFormat.setForeground(QApplication::palette().link());
       
    70     addressFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
       
    71 
       
    72     // Insert the label then the addresses
       
    73     cursor.insertText(label);
       
    74     QString address1 = QString();
       
    75     if (!(alias.isEmpty()))
       
    76     {
       
    77         address1.append(alias);
       
    78         QString alias1 = QString();
       
    79         if (UniViewerFeederPrivate::GetNameFromContacts(address, alias1) > 1)
       
    80         {
       
    81             address1.append(" (");
       
    82             address1.append(address);
       
    83             address1.append(")");
       
    84         }
       
    85     }
       
    86     else
       
    87     {
       
    88         address1.append(address);
       
    89     }
       
    90     addressFormat.setAnchorHref(address);
       
    91     cursor.insertText(address1, addressFormat);
       
    92     repolish();
       
    93 }
       
    94 
       
    95 //----------------------------------------------------------------------------
       
    96 // UniViewerAddressWidget::populate
       
    97 // @see header file
       
    98 //----------------------------------------------------------------------------
       
    99 void UniViewerAddressWidget::populate(const QString &label,
       
   100                                       ConvergedMessageAddressList addressList)
       
   101 {
       
   102     QTextCursor cursor(mAddress->document());
       
   103 
       
   104     QTextCharFormat defaultFormat = cursor.charFormat();
       
   105     defaultFormat.setFontWeight(QFont::Bold);
       
   106     defaultFormat.setForeground(QApplication::palette().link());
       
   107 
       
   108     QTextCharFormat addressFormat = cursor.charFormat();
       
   109     addressFormat.setFontWeight(QFont::Bold);
       
   110     addressFormat.setForeground(QApplication::palette().link());
       
   111     addressFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
       
   112 
       
   113     // Insert the label then the addresses
       
   114     cursor.insertText(label);
       
   115 
       
   116     int addressCount = addressList.count();
       
   117 
       
   118     for (int i = 0; i < addressCount; ++i)
       
   119     {
       
   120 
       
   121         QString address = QString();
       
   122         if (! (addressList[i]->alias().isEmpty()))
       
   123         {
       
   124             address.append(addressList[i]->alias());
       
   125             QString alias = QString();
       
   126             if (UniViewerFeederPrivate::GetNameFromContacts(addressList[i]->address(),
       
   127                                                             alias) > 1)
       
   128             {
       
   129                 address.append(" (");
       
   130                 address.append(addressList[i]->address());
       
   131                 address.append(")");
       
   132             }
       
   133         }
       
   134         else
       
   135         {
       
   136             address.append(addressList[i]->address());
       
   137         }
       
   138 
       
   139         addressFormat.setAnchorHref(addressList[i]->address());
       
   140         cursor.insertText(address, addressFormat);
       
   141 
       
   142         if (addressCount - 1 != i)
       
   143         {
       
   144             cursor.insertText(ADDRESS_SEPARATOR, defaultFormat);
       
   145         }
       
   146         
       
   147     }
       
   148     repolish();
       
   149 }
       
   150 
       
   151 //----------------------------------------------------------------------------
       
   152 // UniViewerAddressWidget::clearContent
       
   153 // @see header file
       
   154 //----------------------------------------------------------------------------
       
   155 void UniViewerAddressWidget::clearContent()
       
   156 {
       
   157     mAddress->document()->clear();
       
   158 }
       
   159 
       
   160 //----------------------------------------------------------------------------
       
   161 // UniViewerAddressWidget::handleAboutToShowContextMenu
       
   162 // @see header file
       
   163 //----------------------------------------------------------------------------
       
   164 void UniViewerAddressWidget::handleAboutToShowContextMenu(HbMenu *contextMenu, const QPointF &pos)
       
   165 {
       
   166     Q_UNUSED(pos)
       
   167     contextMenu->clearActions();
       
   168 }
       
   169 
       
   170 // EOF