15 * |
15 * |
16 */ |
16 */ |
17 #include "cnturleditorviewitem.h" |
17 #include "cnturleditorviewitem.h" |
18 #include "cntdetailmodelitem.h" |
18 #include "cntdetailmodelitem.h" |
19 #include "cntdetailconst.h" |
19 #include "cntdetailconst.h" |
20 #include <qgraphicslinearlayout.h> |
20 #include "cntcommondetailviewitem.h" |
21 #include <qstandarditemmodel.h> |
21 #include <qstandarditemmodel.h> |
22 #include <qcontacturl.h> |
22 #include <qcontacturl.h> |
23 #include <hbdataformmodel.h> |
23 #include <hbdataformmodel.h> |
24 #include <hbmainwindow.h> |
24 #include <hbmainwindow.h> |
25 #include <hbabstractitemview.h> |
25 #include <hbabstractitemview.h> |
26 #include <hbinputeditorinterface.h> |
26 #include <hbinputeditorinterface.h> |
27 #include <hbinputstandardfilters.h> |
27 #include <hbinputstandardfilters.h> |
28 |
28 |
29 CntUrlEditorViewItem::CntUrlEditorViewItem( QGraphicsItem* aParent ) : |
29 CntUrlEditorViewItem::CntUrlEditorViewItem( QGraphicsItem* aParent ) : |
30 CntDetailViewItem( aParent ), |
30 CntDetailViewItem( aParent ), |
31 mBox(NULL), |
31 mItem(NULL) |
32 mEdit(NULL), |
|
33 mLayout(NULL) |
|
34 { |
32 { |
35 |
|
36 } |
33 } |
37 |
34 |
38 CntUrlEditorViewItem::~CntUrlEditorViewItem() |
35 CntUrlEditorViewItem::~CntUrlEditorViewItem() |
39 { |
36 { |
40 } |
37 } |
44 return new CntUrlEditorViewItem(*this); |
41 return new CntUrlEditorViewItem(*this); |
45 } |
42 } |
46 |
43 |
47 HbWidget* CntUrlEditorViewItem::createCustomWidget() |
44 HbWidget* CntUrlEditorViewItem::createCustomWidget() |
48 { |
45 { |
49 connect(itemView()->mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), |
46 mItem = new CntCommonDetailViewItem(this); |
50 this, SLOT(changeOrientation(Qt::Orientation))); |
47 mItem->editor()->setMaxLength( CNT_URL_EDITOR_MAXLENGTH ); |
51 |
48 |
52 mLayout = new QGraphicsLinearLayout(itemView()->mainWindow()->orientation()); |
|
53 HbWidget* widget = new HbWidget(); |
|
54 mBox = new HbComboBox(); |
|
55 mEdit = new HbLineEdit(); |
|
56 mEdit->setMaxLength( CNT_URL_EDITOR_MAXLENGTH ); |
|
57 |
|
58 widget->setLayout( mLayout ); |
|
59 mLayout->addItem( mBox ); |
|
60 mLayout->addItem( mEdit ); |
|
61 |
|
62 mLayout->setStretchFactor(mBox, 2); |
|
63 mLayout->setStretchFactor(mEdit, 2); |
|
64 |
|
65 connect( mBox, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)) ); |
|
66 connect( mEdit, SIGNAL(textChanged(QString)),this, SLOT(textChanged(QString)) ); |
|
67 |
|
68 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
49 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
69 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
50 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
70 QContactUrl detail = item->detail(); |
51 QContactUrl detail = item->detail(); |
71 |
52 |
72 mEdit->setInputMethodHints( Qt::ImhUrlCharactersOnly ); |
53 mItem->editor()->setInputMethodHints( Qt::ImhUrlCharactersOnly ); |
73 |
54 |
74 constructSubTypeModel( detail.contexts() ); |
55 constructSubTypeModel( detail.contexts() ); |
75 |
56 |
76 mEdit->setText( detail.url() ); |
57 mItem->editor()->setText( detail.url() ); |
77 |
58 connect( mItem->comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)) ); |
78 return widget; |
59 connect( mItem->editor(), SIGNAL(textChanged(QString)),this, SLOT(textChanged(QString)) ); |
|
60 |
|
61 return mItem; |
79 } |
62 } |
80 |
63 |
81 void CntUrlEditorViewItem::indexChanged( int aIndex ) |
64 void CntUrlEditorViewItem::indexChanged( int aIndex ) |
82 { |
65 { |
83 QString context = mBox->itemData( aIndex, DetailContext ).toString(); |
66 QString context = mItem->comboBox()->itemData( aIndex, DetailContext ).toString(); |
84 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
67 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
85 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
68 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
86 |
69 |
87 QContactUrl url = item->detail(); |
70 QContactUrl url = item->detail(); |
88 |
71 |
101 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
84 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
102 |
85 |
103 QContactUrl url = item->detail(); |
86 QContactUrl url = item->detail(); |
104 url.setUrl( aText ); |
87 url.setUrl( aText ); |
105 item->setDetail( url ); |
88 item->setDetail( url ); |
106 } |
|
107 |
|
108 void CntUrlEditorViewItem::changeOrientation(Qt::Orientation aOrient) |
|
109 { |
|
110 mLayout->setOrientation(aOrient); |
|
111 } |
89 } |
112 |
90 |
113 void CntUrlEditorViewItem::constructSubTypeModel( QStringList aContext ) |
91 void CntUrlEditorViewItem::constructSubTypeModel( QStringList aContext ) |
114 { |
92 { |
115 QStandardItemModel* model = new QStandardItemModel(); |
93 QStandardItemModel* model = new QStandardItemModel(); |
136 work->setData(fieldAddress, DetailSubType); |
114 work->setData(fieldAddress, DetailSubType); |
137 work->setData(contextWork, DetailContext); |
115 work->setData(contextWork, DetailContext); |
138 work->setData(CNT_URL_EDITOR_MAXLENGTH, DetailMaxLength); |
116 work->setData(CNT_URL_EDITOR_MAXLENGTH, DetailMaxLength); |
139 model->appendRow(work); |
117 model->appendRow(work); |
140 |
118 |
141 mBox->setModel( model ); |
119 mItem->comboBox()->setModel( model ); |
142 |
120 |
143 // search the selected index to be set |
121 // search the selected index to be set |
144 QString context = aContext.isEmpty() ? "" : aContext.first(); |
122 QString context = aContext.isEmpty() ? "" : aContext.first(); |
145 for ( int i(0); i < model->rowCount(); i++ ) |
123 for ( int i(0); i < model->rowCount(); i++ ) |
146 { |
124 { |
147 if ( model->item(i)->data( DetailContext ).toString() == context ) |
125 if ( model->item(i)->data( DetailContext ).toString() == context ) |
148 { |
126 { |
149 mBox->setCurrentIndex( i ); |
127 mItem->comboBox()->setCurrentIndex( i ); |
150 break; |
128 break; |
151 } |
129 } |
152 } |
130 } |
153 } |
131 } |
154 |
132 |