14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 #include "cntdetaileditor.h" |
17 #include "cntdetaileditor.h" |
18 #include "cnteditorfactory.h" |
18 #include "cnteditorfactory.h" |
|
19 #include "cntgroupeditormodel.h" |
19 #include <cntviewparams.h> |
20 #include <cntviewparams.h> |
20 #include <hbmenu.h> |
21 #include <hbmenu.h> |
21 #include <hbaction.h> |
22 #include <hbaction.h> |
22 #include <hbmainwindow.h> |
23 #include <hbmainwindow.h> |
23 #include <hbview.h> |
24 #include <hbview.h> |
24 #include <hbdocumentloader.h> |
25 #include <hbdocumentloader.h> |
25 #include <hbaction.h> |
26 #include <hbaction.h> |
|
27 #include <hblineedit.h> |
|
28 #include <hbinputeditorinterface.h> |
|
29 #include <hbinputstandardfilters.h> |
26 |
30 |
27 const char *CNT_DETAILEDITOR_XML = ":/xml/contacts_detail_editor.docml"; |
31 const char *CNT_DETAILEDITOR_XML = ":/xml/contacts_detail_editor.docml"; |
28 |
32 |
29 CntDetailEditor::CntDetailEditor( int aId ) : |
33 CntDetailEditor::CntDetailEditor( int aId ) : |
30 QObject(), |
34 QObject(), |
|
35 mDataFormModel(NULL), |
31 mId(aId), |
36 mId(aId), |
32 mView(NULL), |
37 mView(NULL), |
33 mLoader(NULL), |
38 mLoader(NULL), |
34 mViewManager(NULL), |
39 mViewManager(NULL), |
35 mEditorFactory(NULL), |
40 mEditorFactory(NULL), |
40 if (!ok) { |
45 if (!ok) { |
41 qFatal("Unable to read %S", CNT_DETAILEDITOR_XML); |
46 qFatal("Unable to read %S", CNT_DETAILEDITOR_XML); |
42 } |
47 } |
43 else { |
48 else { |
44 mView = static_cast<HbView*> (document()->findWidget(QString("view"))); |
49 mView = static_cast<HbView*> (document()->findWidget(QString("view"))); |
45 |
|
46 mDataForm = static_cast<HbDataForm*> (document()->findWidget(QString("dataForm"))); |
50 mDataForm = static_cast<HbDataForm*> (document()->findWidget(QString("dataForm"))); |
47 } |
51 } |
48 |
52 |
49 mEditorFactory = new CntEditorFactory(); |
53 mEditorFactory = new CntEditorFactory(); |
50 |
54 |
74 } |
78 } |
75 |
79 |
76 void CntDetailEditor::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs ) |
80 void CntDetailEditor::activate( CntAbstractViewManager* aMgr, const CntViewParameters aArgs ) |
77 { |
81 { |
78 mViewManager = aMgr; |
82 mViewManager = aMgr; |
|
83 mArgs = aArgs; //don't loose the params while swiching between editview and editorviews. |
79 |
84 |
80 mCancel = static_cast<HbAction*>(document()->findObject("cnt:discardchanges")); |
85 mCancel = static_cast<HbAction*>(document()->findObject("cnt:discardchanges")); |
81 mView->menu()->addAction( mCancel ); |
86 mView->menu()->addAction( mCancel ); |
82 connect( mCancel, SIGNAL(triggered()), this, SLOT(discardChanges()) ); |
87 connect( mCancel, SIGNAL(triggered()), this, SLOT(discardChanges()) ); |
83 |
88 |
92 |
97 |
93 // add new field if required |
98 // add new field if required |
94 if ( aArgs.value(ESelectedAction).toString() == "add" ) { |
99 if ( aArgs.value(ESelectedAction).toString() == "add" ) { |
95 mDataFormModel->insertDetailField(); |
100 mDataFormModel->insertDetailField(); |
96 } |
101 } |
97 |
102 |
98 HbMainWindow* window = mView->mainWindow(); |
103 if ( mId == groupEditorView ) |
99 if ( window ) { |
104 { |
100 connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(handleOrientation(Qt::Orientation))); |
105 connect( mDataForm, SIGNAL(itemShown(const QModelIndex&)), this, SLOT(handleItemShown(const QModelIndex&)) ); |
101 handleOrientation(window->orientation()); |
|
102 } |
106 } |
103 } |
107 } |
104 |
108 |
105 void CntDetailEditor::deactivate() |
109 void CntDetailEditor::deactivate() |
106 { |
110 { |
132 void CntDetailEditor::insertField() |
136 void CntDetailEditor::insertField() |
133 { |
137 { |
134 mDataFormModel->insertDetailField(); |
138 mDataFormModel->insertDetailField(); |
135 } |
139 } |
136 |
140 |
137 void CntDetailEditor::handleOrientation(Qt::Orientation aOrientation) |
141 void CntDetailEditor::handleItemShown(const QModelIndex& aIndex ) |
138 { |
142 { |
139 Q_UNUSED(aOrientation); |
143 if ( mId == groupEditorView ) |
|
144 { |
|
145 CntGroupEditorModel* groupModel = static_cast<CntGroupEditorModel*>( mDataFormModel ); |
|
146 if ( groupModel->isConferenceNumber(aIndex) ) |
|
147 { |
|
148 HbDataFormViewItem* viewItem = static_cast<HbDataFormViewItem*>(mDataForm->itemByIndex( aIndex )); |
|
149 HbLineEdit* edit = static_cast<HbLineEdit*>( viewItem->dataItemContentWidget() ); |
|
150 edit->setInputMethodHints( Qt::ImhDialableCharactersOnly ); |
|
151 } |
|
152 } |
140 } |
153 } |
141 |
154 |
142 void CntDetailEditor::discardChanges() |
155 void CntDetailEditor::discardChanges() |
143 { |
156 { |
144 QContact selected( *mDataFormModel->contact() ); |
157 QContact selected( *mDataFormModel->contact() ); |
145 CntViewParameters args; |
|
146 QVariant var; |
158 QVariant var; |
147 var.setValue(selected); |
159 var.setValue(selected); |
148 args.insert(ESelectedContact, var); |
160 mArgs.insert(ESelectedContact, var); |
149 mViewManager->back( args ); |
161 mViewManager->back( mArgs ); |
150 } |
162 } |
151 |
163 |
152 void CntDetailEditor::saveChanges() |
164 void CntDetailEditor::saveChanges() |
153 { |
165 { |
154 mDataFormModel->saveContactDetails(); |
166 mDataFormModel->saveContactDetails(); |
155 |
167 |
156 QContact selected( *mDataFormModel->contact() ); |
168 QContact selected( *mDataFormModel->contact() ); |
157 CntViewParameters args; |
|
158 QVariant var; |
169 QVariant var; |
159 var.setValue(selected); |
170 var.setValue(selected); |
160 args.insert(ESelectedContact, var); |
171 mArgs.insert(ESelectedContact, var); |
161 mViewManager->back( args ); |
172 mViewManager->back( mArgs ); |
162 } |
173 } |
163 |
174 |
164 void CntDetailEditor::setHeader(QString aHeader) |
175 void CntDetailEditor::setHeader(QString aHeader) |
165 { |
176 { |
166 if (!mHeader) { |
177 if (!mHeader) { |
169 mHeader->setHeading(aHeader); |
180 mHeader->setHeading(aHeader); |
170 } |
181 } |
171 |
182 |
172 void CntDetailEditor::setDetails(CntDetailEditorModel* aModel, HbAbstractViewItem* aPrototype) |
183 void CntDetailEditor::setDetails(CntDetailEditorModel* aModel, HbAbstractViewItem* aPrototype) |
173 { |
184 { |
|
185 //Append custom view item prototype |
|
186 if ( aPrototype ) |
|
187 { |
|
188 QList <HbAbstractViewItem*> protos = mDataForm->itemPrototypes(); |
|
189 protos.append( aPrototype ); |
|
190 mDataForm->setItemPrototypes( protos ); |
|
191 } |
|
192 |
174 mDataFormModel = aModel; |
193 mDataFormModel = aModel; |
175 mDataForm->setModel(mDataFormModel, aPrototype); |
194 mDataForm->setModel( mDataFormModel ); |
|
195 |
176 } |
196 } |
177 |
197 |
178 int CntDetailEditor::viewId() const |
198 int CntDetailEditor::viewId() const |
179 { |
199 { |
180 return mId; |
200 return mId; |