27 #include <hbpushbutton.h> |
27 #include <hbpushbutton.h> |
28 #include <qgraphicslinearlayout.h> |
28 #include <qgraphicslinearlayout.h> |
29 #include <hbwidget.h> |
29 #include <hbwidget.h> |
30 #include <hbtextitem.h> |
30 #include <hbtextitem.h> |
31 |
31 |
32 //#include "qlocationpickeritem_temp.h" |
32 #include "qlocationpickeritem.h" |
33 #include <xqaiwrequest.h> |
33 #include <xqaiwrequest.h> |
34 #include <xqservicerequest.h> |
34 #include <xqservicerequest.h> |
35 #include <xqappmgr.h> |
35 #include <xqappmgr.h> |
36 CntAddressViewItem::CntAddressViewItem(QGraphicsItem* aParent) : |
36 CntAddressViewItem::CntAddressViewItem(QGraphicsItem* aParent) : |
37 /*CntDetailViewItem(aParent),*/ |
37 /*CntDetailViewItem(aParent),*/ |
38 HbDataFormViewItem(aParent), |
38 HbDataFormViewItem(aParent) |
39 mRequest(NULL), |
|
40 mAppManager(NULL), |
|
41 mSenderButton(NULL) |
|
42 { |
39 { |
43 } |
40 } |
44 |
41 |
45 CntAddressViewItem::~CntAddressViewItem() |
42 CntAddressViewItem::~CntAddressViewItem() |
46 { |
43 { |
47 delete mRequest; |
|
48 delete mAppManager; |
|
49 } |
44 } |
50 |
45 |
51 HbAbstractViewItem* CntAddressViewItem::createItem() |
46 HbAbstractViewItem* CntAddressViewItem::createItem() |
52 { |
47 { |
53 return new CntAddressViewItem(*this); |
48 return new CntAddressViewItem(*this); |
54 } |
49 } |
55 |
50 |
|
51 bool CntAddressViewItem::canSetModelIndex( const QModelIndex &index ) const |
|
52 { |
|
53 HbDataFormModelItem::DataItemType itemType = |
|
54 static_cast<HbDataFormModelItem::DataItemType>( |
|
55 index.data(HbDataFormModelItem::ItemTypeRole).toInt() ); |
|
56 |
|
57 if( itemType == HbDataFormModelItem::CustomItemBase ) |
|
58 { |
|
59 return true; |
|
60 } |
|
61 else |
|
62 { |
|
63 return false; |
|
64 } |
|
65 |
|
66 } |
|
67 |
56 HbWidget* CntAddressViewItem::createCustomWidget() |
68 HbWidget* CntAddressViewItem::createCustomWidget() |
57 { |
69 { |
58 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Horizontal); |
70 HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>( |
59 |
71 modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
72 |
60 HbWidget* widget = new HbWidget(); |
73 HbWidget* widget = new HbWidget(); |
61 widget->setLayout(layout); |
74 if( itemType == HbDataFormModelItem::CustomItemBase ) |
62 |
75 { |
63 HbStyleLoader::registerFilePath(":/style/cntlocationbutton.css"); |
76 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Horizontal); |
64 HbStyleLoader::registerFilePath(":/style/cntlocationbutton.hbpushbutton.widgetml"); |
77 widget->setLayout(layout); |
65 HbDataForm* form = static_cast<HbDataForm*> (itemView()); |
78 |
66 HbDataFormModel* model = static_cast<HbDataFormModel*> (form->model()); |
79 HbStyleLoader::registerFilePath(":/style/cntlocationbutton.css"); |
67 |
80 HbStyleLoader::registerFilePath(":/style/cntlocationbutton.hbpushbutton.widgetml"); |
68 HbPushButton* mLocationButton = new HbPushButton(this); |
81 HbDataForm* form = static_cast<HbDataForm*> (itemView()); |
69 mLocationButton->setObjectName("cntlocationbutton"); |
82 HbDataFormModel* model = static_cast<HbDataFormModel*> (form->model()); |
70 mLocationButton->setIcon(HbIcon(":/icons/pickerIcon.jpg")); |
83 |
71 mLocationButton->setText(qtTrId("Select location from map")); |
84 HbPushButton* mLocationButton = new HbPushButton(this); |
72 mLocationButton->setOrientation(Qt::Horizontal); |
85 mLocationButton->setObjectName("cntlocationbutton"); |
73 |
86 mLocationButton->setIcon(HbIcon("qtg_mono_location")); |
74 connect(mLocationButton, SIGNAL(clicked()), this, SLOT(launchLocationPicker())); |
87 mLocationButton->setText( hbTrId("txt_phob_button_select_location") ); |
75 |
88 |
76 layout->addItem(mLocationButton); |
89 connect(mLocationButton, SIGNAL(clicked()), this, SLOT(launchLocationPicker())); |
|
90 |
|
91 layout->addItem(mLocationButton); |
|
92 |
|
93 } |
77 return widget; |
94 return widget; |
78 } |
95 } |
79 |
96 |
80 void CntAddressViewItem::launchLocationPicker() |
97 void CntAddressViewItem::launchLocationPicker() |
81 { |
98 { |
82 mAppManager = new XQApplicationManager(); |
99 XQApplicationManager *appManager = new XQApplicationManager(); |
83 if (mRequest) { |
100 XQAiwRequest* request = appManager->create("com.nokia.symbian", "ILocationPick", "pick()", true); |
84 delete mRequest; |
101 if( request ) |
85 mRequest = 0; |
102 { |
|
103 QVariant retValue; |
|
104 if( request->send( retValue ) ) |
|
105 { |
|
106 handleLocationChange( retValue ); |
|
107 } |
|
108 |
|
109 delete request; |
86 } |
110 } |
87 |
111 delete appManager; |
88 mSenderButton = sender(); |
|
89 mRequest = mAppManager->create("com.nokia.symbian", "ILocationPick", "pick()", false); |
|
90 if (mRequest) { |
|
91 connect(mRequest, SIGNAL(requestOk(const QVariant&)), this, |
|
92 SLOT(handleLocationChange(const QVariant&))); |
|
93 mRequest->send(); |
|
94 } |
|
95 } |
112 } |
96 |
113 |
97 void CntAddressViewItem::handleLocationChange(const QVariant& aValue) |
114 void CntAddressViewItem::handleLocationChange(const QVariant& aValue) |
98 { |
115 { |
99 Q_UNUSED( aValue ); |
116 QLocationPickerItem selectedLocation = aValue.value<QLocationPickerItem>(); |
|
117 if( selectedLocation.mIsValid ) |
|
118 { |
|
119 HbDataForm* form = static_cast<HbDataForm*>(itemView()); |
|
120 HbDataFormModel* model = static_cast<HbDataFormModel*>(form->model()); |
|
121 HbDataFormModelItem* item = model->itemFromIndex( modelIndex() ); |
|
122 |
|
123 QModelIndex nextIndex = modelIndex().sibling( modelIndex().row() + 1 , modelIndex().column() ); |
|
124 HbDataFormModelItem* street = model->itemFromIndex( nextIndex ); |
|
125 street->setContentWidgetData( "text", selectedLocation.mStreet ); |
|
126 street->setContentWidgetData( "maxLength", CNT_STREET_MAXLENGTH ); |
|
127 |
|
128 nextIndex = modelIndex().sibling( modelIndex().row() + 2 , modelIndex().column() ); |
|
129 |
|
130 HbDataFormModelItem* postal = model->itemFromIndex( nextIndex ); |
|
131 postal->setContentWidgetData( "text", selectedLocation.mPostalCode ); |
|
132 postal->setContentWidgetData( "maxLength", CNT_POSTCODE_MAXLENGTH ); |
|
133 |
|
134 nextIndex = modelIndex().sibling( modelIndex().row() + 3 , modelIndex().column() ); |
|
135 HbDataFormModelItem* locality = model->itemFromIndex( nextIndex ); |
|
136 locality->setContentWidgetData( "text", selectedLocation.mCity ); |
|
137 locality->setContentWidgetData( "maxLength", CNT_LOCALITY_MAXLENGTH ); |
|
138 |
|
139 nextIndex = modelIndex().sibling( modelIndex().row() + 4 , modelIndex().column() ); |
|
140 HbDataFormModelItem* province = model->itemFromIndex( nextIndex ); |
|
141 province->setContentWidgetData( "text", selectedLocation.mState ); |
|
142 province->setContentWidgetData( "maxLength", CNT_REGION_MAXLENGTH ); |
|
143 |
|
144 nextIndex = modelIndex().sibling( modelIndex().row() + 5 , modelIndex().column() ); |
|
145 HbDataFormModelItem* country = model->itemFromIndex( nextIndex ); |
|
146 country->setContentWidgetData( "text", selectedLocation.mCountry ); |
|
147 country->setContentWidgetData( "maxLength", CNT_COUNTRY_MAXLENGTH ); |
|
148 |
|
149 |
|
150 } |
|
151 |
100 } |
152 } |
101 |
153 |
102 //Q_IMPLEMENT_USER_METATYPE(QLocationPickerItem) |
154 Q_IMPLEMENT_USER_METATYPE(QLocationPickerItem) |
103 |
155 |
104 // End of File |
156 // End of File |