15 * |
15 * |
16 */ |
16 */ |
17 #include "cntemaileditorviewitem.h" |
17 #include "cntemaileditorviewitem.h" |
18 #include "cntdetailmodelitem.h" |
18 #include "cntdetailmodelitem.h" |
19 #include "cntdetailconst.h" |
19 #include "cntdetailconst.h" |
|
20 #include "cntcommondetailviewitem.h" |
20 |
21 |
21 #include <qcontactdetail.h> |
22 #include <qcontactdetail.h> |
22 #include <qgraphicslinearlayout.h> |
|
23 #include <qcontactemailaddress.h> |
23 #include <qcontactemailaddress.h> |
24 #include <qgraphicslinearlayout.h> |
24 #include <qgraphicslinearlayout.h> |
25 #include <hbwidget.h> |
25 #include <hbwidget.h> |
26 #include <hbabstractitemview.h> |
26 #include <hbabstractitemview.h> |
27 #include <hbdataformmodelitem.h> |
27 #include <hbdataformmodelitem.h> |
51 return new CntEmailEditorViewItem(*this); |
49 return new CntEmailEditorViewItem(*this); |
52 } |
50 } |
53 |
51 |
54 HbWidget* CntEmailEditorViewItem::createCustomWidget() |
52 HbWidget* CntEmailEditorViewItem::createCustomWidget() |
55 { |
53 { |
56 connect(itemView()->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(changeOrientation(Qt::Orientation))); |
54 mItem = new CntCommonDetailViewItem(this); |
57 mLayout = new QGraphicsLinearLayout( itemView()->mainWindow()->orientation() ); |
55 mItem->editor()->setMaxLength( CNT_EMAIL_EDITOR_MAXLENGTH ); |
58 HbWidget* widget = new HbWidget(); |
56 mItem->editor()->setInputMethodHints(Qt::ImhPreferLowercase); |
59 mBox = new HbComboBox(); |
|
60 mEdit = new HbLineEdit(); |
|
61 mEdit->setMaxLength( CNT_EMAIL_EDITOR_MAXLENGTH ); |
|
62 mEdit->setInputMethodHints(Qt::ImhPreferLowercase); |
|
63 |
57 |
64 widget->setLayout( mLayout ); |
|
65 mLayout->addItem( mBox ); |
|
66 mLayout->addItem( mEdit ); |
|
67 |
|
68 mLayout->setStretchFactor(mBox, 2); |
|
69 mLayout->setStretchFactor(mEdit, 2); |
|
70 |
|
71 connect( mBox, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)) ); |
|
72 connect( mEdit, SIGNAL(textChanged(QString)),this, SLOT(textChanged(QString)) ); |
|
73 |
|
74 |
|
75 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
58 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
76 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
59 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
77 QContactDetail detail = item->detail(); |
60 QContactDetail detail = item->detail(); |
78 |
61 |
79 mEdit->setInputMethodHints( Qt::ImhEmailCharactersOnly ); |
62 mItem->editor()->setInputMethodHints( Qt::ImhEmailCharactersOnly ); |
80 |
63 |
81 constructSubTypeModel( detail.contexts() ); |
64 constructSubTypeModel( detail.contexts() ); |
82 |
65 |
83 QContactEmailAddress address = detail; |
66 QContactEmailAddress address = detail; |
84 QString d = address.emailAddress(); |
67 QString d = address.emailAddress(); |
85 mEdit->setText( address.emailAddress() ); |
68 mItem->editor()->setText( address.emailAddress() ); |
86 |
69 |
87 return widget; |
70 connect( mItem->comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)) ); |
|
71 connect( mItem->editor(), SIGNAL(textChanged(QString)),this, SLOT(textChanged(QString)) ); |
|
72 |
|
73 return mItem; |
88 } |
74 } |
89 |
75 |
90 void CntEmailEditorViewItem::indexChanged( int aIndex ) |
76 void CntEmailEditorViewItem::indexChanged( int aIndex ) |
91 { |
77 { |
92 QString context = mBox->itemData( aIndex, DetailContext ).toString(); |
78 QString context = mItem->comboBox()->itemData( aIndex, DetailContext ).toString(); |
93 |
79 |
94 // check that if current QContactDetail contains the changed subtype |
80 // check that if current QContactDetail contains the changed subtype |
95 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
81 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
96 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
82 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
97 |
83 |
110 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
96 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
111 |
97 |
112 QContactEmailAddress address = item->detail(); |
98 QContactEmailAddress address = item->detail(); |
113 address.setEmailAddress( aText ); |
99 address.setEmailAddress( aText ); |
114 item->setDetail( address ); |
100 item->setDetail( address ); |
115 } |
|
116 |
|
117 void CntEmailEditorViewItem::changeOrientation(Qt::Orientation aOrient) |
|
118 { |
|
119 if (mLayout) { |
|
120 mLayout->setOrientation(aOrient); |
|
121 } |
|
122 } |
101 } |
123 |
102 |
124 void CntEmailEditorViewItem::constructSubTypeModel( QStringList aContext ) |
103 void CntEmailEditorViewItem::constructSubTypeModel( QStringList aContext ) |
125 { |
104 { |
126 QStandardItemModel* model = new QStandardItemModel(); |
105 QStandardItemModel* model = new QStandardItemModel(); |
147 work->setData(fieldAddress, DetailSubType); |
126 work->setData(fieldAddress, DetailSubType); |
148 work->setData(contextWork, DetailContext); |
127 work->setData(contextWork, DetailContext); |
149 work->setData(CNT_EMAIL_EDITOR_MAXLENGTH, DetailMaxLength); |
128 work->setData(CNT_EMAIL_EDITOR_MAXLENGTH, DetailMaxLength); |
150 model->appendRow(work); |
129 model->appendRow(work); |
151 |
130 |
152 mBox->setModel( model ); |
131 mItem->comboBox()->setModel( model ); |
153 |
132 |
154 QString context = aContext.isEmpty() ? "" : aContext.first(); |
133 QString context = aContext.isEmpty() ? "" : aContext.first(); |
155 // search the selected index to be set |
134 // search the selected index to be set |
156 for ( int i(0); i < model->rowCount(); i++ ) |
135 for ( int i(0); i < model->rowCount(); i++ ) |
157 { |
136 { |
158 if ( model->item(i)->data( DetailContext ).toString() == context ) |
137 if ( model->item(i)->data( DetailContext ).toString() == context ) |
159 { |
138 { |
160 mBox->setCurrentIndex( i ); |
139 mItem->comboBox()->setCurrentIndex( i ); |
161 break; |
140 break; |
162 } |
141 } |
163 } |
142 } |
164 } |
143 } |
165 |
144 |