phonebookui/pbkcommonui/src/cnturleditorviewitem.cpp
branchRCL_3
changeset 62 5b6f26637ad3
equal deleted inserted replaced
58:d4f567ce2e7c 62:5b6f26637ad3
       
     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 #include "cnturleditorviewitem.h"
       
    18 #include "cntdetailmodelitem.h"
       
    19 #include "cntdetailconst.h"
       
    20 #include "cntcommondetailviewitem.h"
       
    21 #include <qstandarditemmodel.h>
       
    22 #include <qcontacturl.h>
       
    23 #include <hbdataformmodel.h>
       
    24 #include <hbmainwindow.h>
       
    25 #include <hbabstractitemview.h>
       
    26 #include <hbinputeditorinterface.h>
       
    27 #include <hbinputstandardfilters.h>
       
    28 
       
    29 CntUrlEditorViewItem::CntUrlEditorViewItem( QGraphicsItem* aParent ) :
       
    30 CntDetailViewItem( aParent ),
       
    31 mItem(NULL)
       
    32 {
       
    33 }
       
    34 
       
    35 CntUrlEditorViewItem::~CntUrlEditorViewItem()
       
    36 {
       
    37 }
       
    38     
       
    39 HbAbstractViewItem* CntUrlEditorViewItem::createItem()
       
    40 {
       
    41     return new CntUrlEditorViewItem(*this);
       
    42 }
       
    43 
       
    44 HbWidget* CntUrlEditorViewItem::createCustomWidget()
       
    45 {
       
    46     mItem = new CntCommonDetailViewItem(this);
       
    47     mItem->editor()->setMaxLength( CNT_URL_EDITOR_MAXLENGTH );
       
    48     
       
    49     HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model());
       
    50     CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) );
       
    51     QContactUrl detail = item->detail();
       
    52     
       
    53     mItem->editor()->setInputMethodHints( Qt::ImhUrlCharactersOnly );
       
    54     
       
    55     constructSubTypeModel( detail.contexts() );
       
    56     
       
    57     mItem->editor()->setText( detail.url() );
       
    58     connect( mItem->comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)) );
       
    59     connect( mItem->editor(), SIGNAL(textChanged(QString)),this, SLOT(textChanged(QString)) );
       
    60     
       
    61     // Naming UI components for automation testability
       
    62     QString editorObjName = detail.definitionName() + " line edit %1";
       
    63     mItem->editor()->setObjectName(editorObjName.arg(modelIndex().row()));
       
    64     
       
    65     QString comboBoxObjName = detail.definitionName() + " combo box %1";
       
    66     mItem->comboBox()->setObjectName(comboBoxObjName.arg(modelIndex().row()));
       
    67     return mItem;
       
    68 }
       
    69     
       
    70 void CntUrlEditorViewItem::indexChanged( int aIndex )
       
    71 {
       
    72     QString context = mItem->comboBox()->itemData( aIndex, DetailContext ).toString();
       
    73     HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model());
       
    74     CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) );
       
    75     
       
    76     QContactUrl url = item->detail();
       
    77     
       
    78     QStringList contextList;
       
    79     if ( !context.isEmpty() )
       
    80         contextList << context;
       
    81     
       
    82     url.setContexts( contextList );
       
    83     
       
    84     item->setDetail( url );
       
    85 }
       
    86 
       
    87 void CntUrlEditorViewItem::textChanged( QString aText )
       
    88 {
       
    89     HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model());
       
    90     CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) );
       
    91         
       
    92     QContactUrl url = item->detail();
       
    93     url.setUrl( aText );
       
    94     item->setDetail( url );
       
    95 }
       
    96 
       
    97 void CntUrlEditorViewItem::constructSubTypeModel( QStringList aContext )
       
    98 {
       
    99     QStandardItemModel* model = new QStandardItemModel();
       
   100             
       
   101     QString contextHome = QContactDetail::ContextHome;
       
   102     QString contextWork = QContactDetail::ContextWork;
       
   103     QString fieldAddress = QContactUrl::FieldUrl;
       
   104         
       
   105     QStandardItem *noContext = new QStandardItem;
       
   106     noContext->setText(hbTrId("txt_phob_formlabel_val_url"));
       
   107     noContext->setData(fieldAddress, DetailSubType);
       
   108     noContext->setData(CNT_URL_EDITOR_MAXLENGTH, DetailMaxLength);
       
   109     model->appendRow(noContext);
       
   110            
       
   111     QStandardItem *home = new QStandardItem;
       
   112     home->setText(hbTrId("txt_phob_formlabel_val_url_home"));
       
   113     home->setData(fieldAddress, DetailSubType);
       
   114     home->setData(contextHome, DetailContext);
       
   115     home->setData(CNT_URL_EDITOR_MAXLENGTH, DetailMaxLength);
       
   116     model->appendRow(home);
       
   117            
       
   118     QStandardItem *work = new QStandardItem;
       
   119     work->setText(hbTrId("txt_phob_formlabel_val_url_work"));
       
   120     work->setData(fieldAddress, DetailSubType);
       
   121     work->setData(contextWork, DetailContext);
       
   122     work->setData(CNT_URL_EDITOR_MAXLENGTH, DetailMaxLength);
       
   123     model->appendRow(work);
       
   124     
       
   125     mItem->comboBox()->setModel( model );
       
   126     
       
   127     // search the selected index to be set
       
   128     QString context = aContext.isEmpty() ? "" : aContext.first();
       
   129     for ( int i(0); i < model->rowCount(); i++ )
       
   130         {
       
   131         if ( model->item(i)->data( DetailContext ).toString() == context )
       
   132             {
       
   133             mItem->comboBox()->setCurrentIndex( i );
       
   134             break;
       
   135             }
       
   136         }
       
   137 }
       
   138 
       
   139 // End of File