|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "cntdateeditorviewitem.h" |
|
18 #include "cntdetailmodelitem.h" |
|
19 #include "cntdetailconst.h" |
|
20 |
|
21 #include <qcontactdetail.h> |
|
22 #include <qcontactbirthday.h> |
|
23 #include <qcontactanniversary.h> |
|
24 |
|
25 #include <hbabstractviewitem.h> |
|
26 #include <hbabstractitemview.h> |
|
27 #include <hbdataformmodel.h> |
|
28 #include <hbwidget.h> |
|
29 #include <hbdatetimepicker.h> |
|
30 #include <hbpushbutton.h> |
|
31 #include <hbdialog.h> |
|
32 #include <hbdatetimepicker.h> |
|
33 #include <hblabel.h> |
|
34 #include <hbaction.h> |
|
35 |
|
36 CntDateEditorViewItem::CntDateEditorViewItem( QGraphicsItem* aParent ) : |
|
37 CntDetailViewItem( aParent ), |
|
38 mButton(NULL) |
|
39 { |
|
40 mLocale = QLocale::system(); |
|
41 } |
|
42 |
|
43 CntDateEditorViewItem::~CntDateEditorViewItem() |
|
44 { |
|
45 } |
|
46 |
|
47 HbAbstractViewItem* CntDateEditorViewItem::createItem() |
|
48 { |
|
49 return new CntDateEditorViewItem( *this ); |
|
50 } |
|
51 |
|
52 void CntDateEditorViewItem::clicked() |
|
53 { |
|
54 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
|
55 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
|
56 QContactDetail detail = item->detail(); |
|
57 |
|
58 if ( detail.definitionName() == QContactBirthday::DefinitionName ) |
|
59 { |
|
60 QContactBirthday bd = detail; |
|
61 if (bd.date().isNull()) |
|
62 { |
|
63 editDate( QDate::currentDate(), hbTrId("txt_phob_formlabel_birthday") ); |
|
64 } |
|
65 else |
|
66 { |
|
67 editDate( bd.date(), hbTrId("txt_phob_formlabel_birthday") ); |
|
68 } |
|
69 } |
|
70 |
|
71 if ( detail.definitionName() == QContactAnniversary::DefinitionName ) |
|
72 { |
|
73 QContactAnniversary anniversary = detail; |
|
74 if (anniversary.originalDate().isNull()) |
|
75 { |
|
76 editDate( QDate::currentDate(), hbTrId("txt_phob_formlabel_anniversary") ); |
|
77 } |
|
78 else |
|
79 { |
|
80 editDate( anniversary.originalDate(), hbTrId("txt_phob_formlabel_anniversary") ); |
|
81 } |
|
82 } |
|
83 } |
|
84 |
|
85 HbWidget* CntDateEditorViewItem::createCustomWidget() |
|
86 { |
|
87 mButton = new HbPushButton(); |
|
88 connect( mButton, SIGNAL(clicked(bool)), this, SLOT(clicked()) ); |
|
89 |
|
90 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
|
91 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
|
92 |
|
93 QContactDetail detail = item->detail(); |
|
94 QString text(hbTrId("txt_phob_formlabel_val_formlabel_val_no_date_set")); |
|
95 QString buttonObjName; |
|
96 |
|
97 if ( detail.definitionName() == QContactBirthday::DefinitionName ) |
|
98 { |
|
99 buttonObjName = detail.definitionName() + " button"; |
|
100 QContactBirthday birthday = detail; |
|
101 if ( !birthday.isEmpty() ) |
|
102 { |
|
103 text = mLocale.toString( birthday.date() ); |
|
104 } |
|
105 } |
|
106 |
|
107 if ( detail.definitionName() == QContactAnniversary::DefinitionName ) |
|
108 { |
|
109 buttonObjName = detail.definitionName() + " button"; |
|
110 QContactAnniversary anniversary = detail; |
|
111 if ( !anniversary.isEmpty() ) |
|
112 { |
|
113 text = mLocale.toString( anniversary.originalDate() ); |
|
114 } |
|
115 } |
|
116 mButton->setText( text ); |
|
117 // Naming UI components for automation testability |
|
118 mButton->setObjectName(buttonObjName); |
|
119 return mButton; |
|
120 } |
|
121 |
|
122 void CntDateEditorViewItem::editDate( QDate aCurrent, QString aTitle ) |
|
123 { |
|
124 HbDialog *popup = new HbDialog(); |
|
125 popup->setDismissPolicy(HbDialog::NoDismiss); |
|
126 popup->setTimeout(HbPopup::NoTimeout); |
|
127 popup->setAttribute(Qt::WA_DeleteOnClose, true); |
|
128 |
|
129 HbDateTimePicker *picker = new HbDateTimePicker( popup ); |
|
130 picker->setDisplayFormat( mLocale.dateFormat() ); |
|
131 picker->setDateRange(CNT_DATEPICKER_FROM, CNT_DATEPICKER_TO ); |
|
132 picker->setDate( aCurrent ); |
|
133 |
|
134 HbLabel *headingText = new HbLabel( popup ); |
|
135 headingText->setPlainText( aTitle ); |
|
136 |
|
137 popup->setHeadingWidget(headingText); |
|
138 popup->setContentWidget(picker); |
|
139 popup->addAction(new HbAction(hbTrId("txt_common_button_ok"), popup)); |
|
140 popup->addAction(new HbAction(hbTrId("txt_common_button_cancel"), popup)); |
|
141 |
|
142 popup->open(this, SLOT(handleEditDate(HbAction*))); |
|
143 } |
|
144 |
|
145 void CntDateEditorViewItem::changeDate( QDate aNewDate ) |
|
146 { |
|
147 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
|
148 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
|
149 QContactDetail detail = item->detail(); |
|
150 |
|
151 QString buttonText("No date set"); // loc missing |
|
152 if ( detail.definitionName() == QContactBirthday::DefinitionName ) |
|
153 { |
|
154 QContactBirthday bd = detail; |
|
155 if ( aNewDate != bd.date() ) |
|
156 { |
|
157 bd.setDate( aNewDate ); |
|
158 item->setDetail( bd ); |
|
159 } |
|
160 buttonText = mLocale.toString( aNewDate ); |
|
161 } |
|
162 |
|
163 if ( detail.definitionName() == QContactAnniversary::DefinitionName ) |
|
164 { |
|
165 QContactAnniversary anniversary = detail; |
|
166 if ( aNewDate != anniversary.originalDate() ) |
|
167 { |
|
168 anniversary.setOriginalDate( aNewDate ); |
|
169 item->setDetail( anniversary ); |
|
170 } |
|
171 buttonText = mLocale.toString( aNewDate ); |
|
172 } |
|
173 |
|
174 mButton->setText( buttonText ); |
|
175 } |
|
176 |
|
177 void CntDateEditorViewItem::handleEditDate( HbAction *aAction ) |
|
178 { |
|
179 HbDialog *popup = static_cast<HbDialog*>(sender()); |
|
180 |
|
181 if (popup && aAction == popup->actions().first()) |
|
182 { |
|
183 QDate date = static_cast<HbDateTimePicker*>(popup->contentWidget())->date(); |
|
184 changeDate(date); |
|
185 } |
|
186 |
|
187 } |
|
188 |
|
189 // End of File |