phonebookui/pbkcommonui/src/cntphonenumberviewitem.cpp
changeset 46 efe85016a067
parent 37 fd64c38c277d
child 47 7cbcb2896f0e
equal deleted inserted replaced
40:b46a585f6909 46:efe85016a067
    15 *
    15 *
    16 */
    16 */
    17 #include "cntdetailconst.h"
    17 #include "cntdetailconst.h"
    18 #include "cntphonenumberviewitem.h"
    18 #include "cntphonenumberviewitem.h"
    19 #include "cntdetailmodelitem.h"
    19 #include "cntdetailmodelitem.h"
       
    20 #include "cntcommondetailviewitem.h"
    20 #include "cntdetaileditormodel.h"
    21 #include "cntdetaileditormodel.h"
    21 
    22 
    22 #include <qdebug.h>
    23 #include <qdebug.h>
    23 #include <qgraphicslinearlayout.h>
       
    24 #include <qcontactphonenumber.h>
    24 #include <qcontactphonenumber.h>
    25 #include <qcontactonlineaccount.h>
    25 #include <qcontactonlineaccount.h>
    26 #include <qcontactdetail.h>
    26 #include <qcontactdetail.h>
    27 #include <qstandarditemmodel.h>
    27 #include <qstandarditemmodel.h>
    28 
    28 
    29 #include <hbwidget.h>
       
    30 #include <hbmainwindow.h>
    29 #include <hbmainwindow.h>
       
    30 #include <hbcombobox.h>
       
    31 #include <hblineedit.h>
    31 #include <hbabstractviewitem.h>
    32 #include <hbabstractviewitem.h>
    32 #include <hbabstractitemview.h>
    33 #include <hbabstractitemview.h>
    33 #include <hbdataformmodelitem.h>
    34 #include <hbdataformmodelitem.h>
    34 #include <hbdataformmodel.h>
    35 #include <hbdataformmodel.h>
    35 #include <hbcombobox.h>
       
    36 #include <hblineedit.h>
       
    37 #include <hbinputstandardfilters.h>
    36 #include <hbinputstandardfilters.h>
    38 
    37 
    39 CntPhoneNumberViewItem::CntPhoneNumberViewItem( QGraphicsItem* aParent ) : 
    38 CntPhoneNumberViewItem::CntPhoneNumberViewItem( QGraphicsItem* aParent ) : 
    40 CntDetailViewItem( aParent ),
    39 CntDetailViewItem( aParent ),
    41 mBox(NULL),
    40     mItem(NULL)
    42 mEdit(NULL),
       
    43 mLayout(NULL)
       
    44     {
    41     {
    45     }
    42     }
    46 
    43 
    47 CntPhoneNumberViewItem::~CntPhoneNumberViewItem()
    44 CntPhoneNumberViewItem::~CntPhoneNumberViewItem()
    48     {
    45     {
    53     return new CntPhoneNumberViewItem( *this );
    50     return new CntPhoneNumberViewItem( *this );
    54     }
    51     }
    55 
    52 
    56 void CntPhoneNumberViewItem::indexChanged( int aIndex )
    53 void CntPhoneNumberViewItem::indexChanged( int aIndex )
    57     {
    54     {
    58     QString subType = mBox->itemData( aIndex, DetailSubType ).toString();
    55     QString subType = mItem->comboBox()->itemData( aIndex, DetailSubType ).toString();
    59     QString context = mBox->itemData( aIndex, DetailContext ).toString();
    56     QString context = mItem->comboBox()->itemData( aIndex, DetailContext ).toString();
    60     
    57     
    61     // check that if current QContactDetail contains the changed subtype
    58     // check that if current QContactDetail contains the changed subtype
    62     HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model());
    59     HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model());
    63     CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) );
    60     CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) );
    64     
    61     
   100         account.setAccountUri( aText );
    97         account.setAccountUri( aText );
   101         item->setDetail( account );
    98         item->setDetail( account );
   102         }
    99         }
   103     }
   100     }
   104 
   101 
   105 void CntPhoneNumberViewItem::changeOrientation(Qt::Orientation aOrient)
       
   106 {
       
   107     if (mLayout) {
       
   108         mLayout->setOrientation(aOrient);
       
   109     }
       
   110 }
       
   111 
       
   112 HbWidget* CntPhoneNumberViewItem::createCustomWidget()
   102 HbWidget* CntPhoneNumberViewItem::createCustomWidget()
   113     {
   103     {
   114     connect(itemView()->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(changeOrientation(Qt::Orientation)));
   104     mItem = new CntCommonDetailViewItem(this);
   115     mLayout = new QGraphicsLinearLayout( itemView()->mainWindow()->orientation() );
       
   116     HbWidget* widget = new HbWidget();
       
   117     mBox = new HbComboBox();
       
   118     mEdit = new HbLineEdit();
       
   119     
       
   120     widget->setLayout( mLayout );
       
   121 
       
   122     mLayout->addItem( mBox );
       
   123     mLayout->addItem( mEdit );
       
   124     
       
   125     mLayout->setStretchFactor(mBox, 2);
       
   126     mLayout->setStretchFactor(mEdit, 2);
       
   127     
       
   128     connect( mBox, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)) );
       
   129     connect( mEdit, SIGNAL(textChanged(QString)),this, SLOT(textChanged(QString)) );
       
   130     
   105     
   131     HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model());
   106     HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model());
   132     CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) );
   107     CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) );
   133     
   108     
   134     // select correct index
   109     // select correct index
   136     QStringList context;
   111     QStringList context;
   137     QString subType;
   112     QString subType;
   138     QString value;
   113     QString value;
   139     if ( detail.definitionName() == QContactPhoneNumber::DefinitionName )
   114     if ( detail.definitionName() == QContactPhoneNumber::DefinitionName )
   140         {
   115         {
   141         mEdit->setMaxLength( CNT_PHONENUMBER_EDITOR_MAXLENGTH );
   116         mItem->editor()->setMaxLength( CNT_PHONENUMBER_EDITOR_MAXLENGTH );
   142         QContactPhoneNumber phone = detail;
   117         QContactPhoneNumber phone = detail;
   143         subType = phone.subTypes().isEmpty() ? "" : phone.subTypes().first();
   118         subType = phone.subTypes().isEmpty() ? "" : phone.subTypes().first();
   144         if ( !phone.contexts().isEmpty() )
   119         if ( !phone.contexts().isEmpty() )
   145             context << phone.contexts().first();
   120             context << phone.contexts().first();
   146         value = phone.number();
   121         value = phone.number();
   147         }
   122         }
   148     
   123     
   149     if ( detail.definitionName() == QContactOnlineAccount::DefinitionName )
   124     if ( detail.definitionName() == QContactOnlineAccount::DefinitionName )
   150         {
   125         {
   151         mEdit->setMaxLength( CNT_ONLINEACCOUNT_EDITOR_MAXLENGTH );
   126         mItem->editor()->setMaxLength( CNT_ONLINEACCOUNT_EDITOR_MAXLENGTH );
   152         QContactOnlineAccount account = detail;
   127         QContactOnlineAccount account = detail;
   153         subType = account.subTypes().isEmpty() ? "" : account.subTypes().first();
   128         subType = account.subTypes().isEmpty() ? "" : account.subTypes().first();
   154         if (!account.contexts().isEmpty())
   129         if (!account.contexts().isEmpty())
   155             context << account.contexts().first();
   130             context << account.contexts().first();
   156         value = account.accountUri();
   131         value = account.accountUri();
   157         }
   132         }
   158     
   133     
   159     mEdit->setText( value );
   134     mItem->editor()->setText( value );
       
   135     
       
   136     connect( mItem->comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)) );
       
   137     connect( mItem->editor(), SIGNAL(textChanged(QString)),this, SLOT(textChanged(QString)) );
       
   138     
   160     constructSubtypeModel( subType, context );
   139     constructSubtypeModel( subType, context );
   161     
   140     
   162     return widget;        
   141     return mItem;
   163     }
   142     }
   164 
   143 
   165 void CntPhoneNumberViewItem::constructPhoneNumber( CntDetailModelItem* aItem, QString aSubType, QStringList aContext )
   144 void CntPhoneNumberViewItem::constructPhoneNumber( CntDetailModelItem* aItem, QString aSubType, QStringList aContext )
   166     {
   145     {
   167     mEdit->setInputMethodHints( Qt::ImhDialableCharactersOnly );
   146     mItem->editor()->setInputMethodHints( Qt::ImhDialableCharactersOnly );
   168     mEdit->setMaxLength( CNT_PHONENUMBER_EDITOR_MAXLENGTH );
   147     mItem->editor()->setMaxLength( CNT_PHONENUMBER_EDITOR_MAXLENGTH );
   169             
   148             
   170     QContactDetail detail = aItem->detail();
   149     QContactDetail detail = aItem->detail();
   171     
   150     
   172     // check if the detail type needs to changed
   151     // check if the detail type needs to changed
   173     if ( detail.definitionName() == QContactOnlineAccount::DefinitionName )
   152     if ( detail.definitionName() == QContactOnlineAccount::DefinitionName )
   188         QContactPhoneNumber number = detail;
   167         QContactPhoneNumber number = detail;
   189         number.setSubTypes( aSubType );
   168         number.setSubTypes( aSubType );
   190         number.setContexts( aContext );
   169         number.setContexts( aContext );
   191         aItem->setDetail( number );
   170         aItem->setDetail( number );
   192         }
   171         }
   193     qDebug() << mEdit->text();
   172     qDebug() << mItem->editor()->text();
   194     }
   173     }
   195 
   174 
   196 void CntPhoneNumberViewItem::constructOnlineAccount( CntDetailModelItem* aItem, QString aSubType, QStringList aContext )
   175 void CntPhoneNumberViewItem::constructOnlineAccount( CntDetailModelItem* aItem, QString aSubType, QStringList aContext )
   197     {
   176     {
   198     mEdit->setMaxLength( CNT_ONLINEACCOUNT_EDITOR_MAXLENGTH );
   177     mItem->editor()->setMaxLength( CNT_ONLINEACCOUNT_EDITOR_MAXLENGTH );
   199     mEdit->setInputMethodHints( Qt::ImhUrlCharactersOnly );
   178     mItem->editor()->setInputMethodHints( Qt::ImhUrlCharactersOnly );
   200     
   179     
   201     QContactDetail detail = aItem->detail();
   180     QContactDetail detail = aItem->detail();
   202     // check if the detail type needs to changed
   181     // check if the detail type needs to changed
   203     if ( detail.definitionName() == QContactPhoneNumber::DefinitionName )
   182     if ( detail.definitionName() == QContactPhoneNumber::DefinitionName )
   204         {
   183         {
   209         contact->removeDetail( &detail );
   188         contact->removeDetail( &detail );
   210         
   189         
   211         QContactOnlineAccount account;
   190         QContactOnlineAccount account;
   212         account.setSubTypes( aSubType );
   191         account.setSubTypes( aSubType );
   213         account.setContexts( aContext );
   192         account.setContexts( aContext );
   214         account.setAccountUri( mEdit->text() );
   193         account.setAccountUri( mItem->editor()->text() );
   215         aItem->setDetail( account );
   194         aItem->setDetail( account );
   216         }
   195         }
   217     else
   196     else
   218         {
   197         {
   219         QContactOnlineAccount account = detail;
   198         QContactOnlineAccount account = detail;
   220         account.setSubTypes( aSubType );
   199         account.setSubTypes( aSubType );
   221         account.setContexts( aContext );
   200         account.setContexts( aContext );
   222         account.setAccountUri( mEdit->text() );
   201         account.setAccountUri( mItem->editor()->text() );
   223         aItem->setDetail( account );
   202         aItem->setDetail( account );
   224         }
   203         }
   225     qDebug() << mEdit->text();
   204     qDebug() << mItem->editor()->text();
   226     }
   205     }
   227 
   206 
   228 void CntPhoneNumberViewItem::constructSubtypeModel( QString aSubType, QStringList aContext )
   207 void CntPhoneNumberViewItem::constructSubtypeModel( QString aSubType, QStringList aContext )
   229     {
   208     {
   230     QStandardItemModel* model = new QStandardItemModel();
   209     QStandardItemModel* model = new QStandardItemModel();
   232     QString contextHome = QContactDetail::ContextHome;
   211     QString contextHome = QContactDetail::ContextHome;
   233     QString contextWork = QContactDetail::ContextWork;
   212     QString contextWork = QContactDetail::ContextWork;
   234         
   213         
   235     QString subTypeMobile = QContactPhoneNumber::SubTypeMobile;
   214     QString subTypeMobile = QContactPhoneNumber::SubTypeMobile;
   236     QString subTypeLandline = QContactPhoneNumber::SubTypeLandline;
   215     QString subTypeLandline = QContactPhoneNumber::SubTypeLandline;
   237     QString subTypeFax = QContactPhoneNumber::SubTypeFacsimile;
   216     QString subTypeFax = QContactPhoneNumber::SubTypeFax;
   238     QString subTypePager = QContactPhoneNumber::SubTypePager;
   217     QString subTypePager = QContactPhoneNumber::SubTypePager;
   239     QString subTypeCarPhone = QContactPhoneNumber::SubTypeCar;
   218     QString subTypeCarPhone = QContactPhoneNumber::SubTypeCar;
   240     QString subTypeDtmf = QContactPhoneNumber::SubTypeDtmfMenu;
   219     QString subTypeDtmf = QContactPhoneNumber::SubTypeDtmfMenu;
   241     QString subTypeAssistant = QContactPhoneNumber::SubTypeAssistant;
   220     QString subTypeAssistant = QContactPhoneNumber::SubTypeAssistant;
   242         
   221         
   346     sip->setText(hbTrId("txt_phob_formlabel_val_sip"));
   325     sip->setText(hbTrId("txt_phob_formlabel_val_sip"));
   347     sip->setData(subTypeSIP, DetailSubType);
   326     sip->setData(subTypeSIP, DetailSubType);
   348     sip->setData(CNT_ONLINEACCOUNT_EDITOR_MAXLENGTH, DetailMaxLength);
   327     sip->setData(CNT_ONLINEACCOUNT_EDITOR_MAXLENGTH, DetailMaxLength);
   349     model->appendRow(sip);
   328     model->appendRow(sip);
   350          
   329          
   351     mBox->setModel( model );
   330     mItem->comboBox()->setModel( model );
   352     
   331     
   353     // search the selected index to be set
   332     // search the selected index to be set
   354     QString context = aContext.isEmpty() ? "" : aContext.first();
   333     QString context = aContext.isEmpty() ? "" : aContext.first();
   355     for ( int i(0); i < model->rowCount(); i++ )
   334     for ( int i(0); i < model->rowCount(); i++ )
   356         {
   335         {
   357         if ( model->item(i)->data( DetailSubType ).toString() == aSubType &&
   336         if ( model->item(i)->data( DetailSubType ).toString() == aSubType &&
   358              model->item(i)->data( DetailContext ).toString() == context )
   337              model->item(i)->data( DetailContext ).toString() == context )
   359             {
   338             {
   360             mBox->setCurrentIndex( i );
   339             mItem->comboBox()->setCurrentIndex( i );
   361             break;
   340             break;
   362             }
   341             }
   363         }
   342         }
   364     }
   343     }
   365 // End of File
   344 // End of File