28 #include <hbwidget.h> |
28 #include <hbwidget.h> |
29 #include <hbdatetimepicker.h> |
29 #include <hbdatetimepicker.h> |
30 #include <hbpushbutton.h> |
30 #include <hbpushbutton.h> |
31 #include <hbdialog.h> |
31 #include <hbdialog.h> |
32 #include <hbdatetimepicker.h> |
32 #include <hbdatetimepicker.h> |
33 #include <hbtextitem.h> |
33 #include <hblabel.h> |
34 #include <hbaction.h> |
34 #include <hbaction.h> |
35 |
35 |
36 #include <QPointer> |
|
37 |
|
38 CntDateEditorViewItem::CntDateEditorViewItem( QGraphicsItem* aParent ) : |
36 CntDateEditorViewItem::CntDateEditorViewItem( QGraphicsItem* aParent ) : |
39 CntDetailViewItem( aParent ), |
37 CntDetailViewItem( aParent ), |
40 mButton(NULL) |
38 mButton(NULL) |
41 { |
39 { |
42 mLocale = QLocale::system(); |
40 mLocale = QLocale::system(); |
43 } |
41 } |
44 |
42 |
45 CntDateEditorViewItem::~CntDateEditorViewItem() |
43 CntDateEditorViewItem::~CntDateEditorViewItem() |
46 { |
44 { |
47 } |
45 } |
48 |
46 |
49 HbAbstractViewItem* CntDateEditorViewItem::createItem() |
47 HbAbstractViewItem* CntDateEditorViewItem::createItem() |
50 { |
48 { |
51 return new CntDateEditorViewItem( *this ); |
49 return new CntDateEditorViewItem( *this ); |
52 } |
50 } |
53 |
51 |
54 void CntDateEditorViewItem::clicked() |
52 void CntDateEditorViewItem::clicked() |
55 { |
53 { |
56 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
54 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
57 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
55 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
58 QContactDetail detail = item->detail(); |
56 QContactDetail detail = item->detail(); |
59 |
57 |
60 QString buttonText = qtTrId( "No date set" ); |
|
61 if ( detail.definitionName() == QContactBirthday::DefinitionName ) |
58 if ( detail.definitionName() == QContactBirthday::DefinitionName ) |
62 { |
59 { |
63 QContactBirthday bd = detail; |
60 QContactBirthday bd = detail; |
64 QDate date = editDate( bd.date(), qtTrId("Birthday") ); |
61 editDate( bd.date(), hbTrId("txt_phob_formlabel_birthday") ); |
65 if ( date != bd.date() ) |
|
66 { |
|
67 bd.setDate( date ); |
|
68 item->setDetail( bd ); |
|
69 } |
|
70 buttonText = mLocale.toString( date ); |
|
71 } |
|
72 |
|
73 if ( detail.definitionName() == QContactAnniversary::DefinitionName ) |
|
74 { |
|
75 QContactAnniversary anniversary = detail; |
|
76 QDate date = editDate( anniversary.originalDate(), qtTrId("Anniversary") ); |
|
77 if ( date != anniversary.originalDate() ) |
|
78 { |
|
79 anniversary.setOriginalDate( date ); |
|
80 item->setDetail( anniversary ); |
|
81 } |
|
82 buttonText = mLocale.toString( date ); |
|
83 } |
|
84 |
|
85 mButton->setText( buttonText ); |
|
86 } |
62 } |
87 |
63 |
|
64 if ( detail.definitionName() == QContactAnniversary::DefinitionName ) |
|
65 { |
|
66 QContactAnniversary anniversary = detail; |
|
67 editDate( anniversary.originalDate(), hbTrId("txt_phob_formlabel_anniversary") ); |
|
68 } |
|
69 } |
|
70 |
88 HbWidget* CntDateEditorViewItem::createCustomWidget() |
71 HbWidget* CntDateEditorViewItem::createCustomWidget() |
89 { |
72 { |
90 mButton = new HbPushButton(); |
73 mButton = new HbPushButton(); |
91 connect( mButton, SIGNAL(clicked(bool)), this, SLOT(clicked()) ); |
74 connect( mButton, SIGNAL(clicked(bool)), this, SLOT(clicked()) ); |
92 |
75 |
93 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
76 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
94 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
77 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
95 |
78 |
96 QContactDetail detail = item->detail(); |
79 QContactDetail detail = item->detail(); |
97 QString text( qtTrId("No date set") ); |
80 QString text("No date set"); // loc missing |
98 |
81 |
99 if ( detail.definitionName() == QContactBirthday::DefinitionName ) |
82 if ( detail.definitionName() == QContactBirthday::DefinitionName ) |
100 { |
83 { |
101 QContactBirthday birthday = detail; |
84 QContactBirthday birthday = detail; |
102 if ( !birthday.isEmpty() ) |
85 if ( !birthday.isEmpty() ) |
103 { |
86 { |
104 text = mLocale.toString( birthday.date() ); |
87 text = mLocale.toString( birthday.date() ); |
105 } |
|
106 } |
88 } |
107 |
89 } |
|
90 |
108 if ( detail.definitionName() == QContactAnniversary::DefinitionName ) |
91 if ( detail.definitionName() == QContactAnniversary::DefinitionName ) |
109 { |
92 { |
110 QContactAnniversary anniversary = detail; |
93 QContactAnniversary anniversary = detail; |
111 if ( !anniversary.isEmpty() ) |
94 if ( !anniversary.isEmpty() ) |
112 { |
95 { |
113 text = mLocale.toString( anniversary.originalDate() ); |
96 text = mLocale.toString( anniversary.originalDate() ); |
114 } |
|
115 } |
97 } |
|
98 } |
116 mButton->setText( text ); |
99 mButton->setText( text ); |
117 return mButton; |
100 return mButton; |
118 } |
101 } |
119 |
102 |
120 QDate CntDateEditorViewItem::editDate( QDate aCurrent, QString aTitle ) |
103 void CntDateEditorViewItem::editDate( QDate aCurrent, QString aTitle ) |
121 { |
104 { |
122 QPointer<HbDialog> popup = new HbDialog(); |
105 HbDialog *popup = new HbDialog(); |
123 popup->setDismissPolicy(HbDialog::NoDismiss); |
106 popup->setDismissPolicy(HbDialog::NoDismiss); |
124 popup->setTimeout(HbPopup::NoTimeout); |
107 popup->setTimeout(HbPopup::NoTimeout); |
|
108 popup->setAttribute(Qt::WA_DeleteOnClose, true); |
125 |
109 |
126 HbDateTimePicker *picker = new HbDateTimePicker( popup ); |
110 HbDateTimePicker *picker = new HbDateTimePicker( popup ); |
127 picker->setDisplayFormat( mLocale.dateFormat() ); |
111 picker->setDisplayFormat( mLocale.dateFormat() ); |
128 picker->setDateRange(CNT_DATEPICKER_FROM, CNT_DATEPICKER_TO ); |
112 picker->setDateRange(CNT_DATEPICKER_FROM, CNT_DATEPICKER_TO ); |
129 picker->setDate( aCurrent ); |
113 picker->setDate( aCurrent ); |
130 |
114 |
131 HbTextItem *headingText = new HbTextItem( popup ); |
115 HbLabel *headingText = new HbLabel( popup ); |
132 headingText->setFontSpec( HbFontSpec(HbFontSpec::Title) ); |
116 headingText->setPlainText( aTitle ); |
133 headingText->setText( aTitle ); |
117 |
134 |
|
135 popup->setHeadingWidget(headingText); |
118 popup->setHeadingWidget(headingText); |
136 popup->setContentWidget(picker); |
119 popup->setContentWidget(picker); |
137 popup->setPrimaryAction(new HbAction(qtTrId("Ok"), popup)); |
120 popup->addAction(new HbAction(hbTrId("txt_common_button_ok"), popup)); |
138 popup->setSecondaryAction(new HbAction(qtTrId("Cancel"), popup)); |
121 popup->addAction(new HbAction(hbTrId("txt_common_button_cancel"), popup)); |
|
122 |
|
123 popup->open(this, SLOT(handleEditDate(HbAction*))); |
|
124 } |
139 |
125 |
140 HbAction *selected = popup->exec(); |
126 void CntDateEditorViewItem::changeDate( QDate aNewDate ) |
141 QDate date = (selected == popup->primaryAction()) ? picker->date() : aCurrent; |
127 { |
142 delete popup; |
128 HbDataFormModel* model = static_cast<HbDataFormModel*>(itemView()->model()); |
143 |
129 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( model->itemFromIndex(modelIndex()) ); |
144 return date; |
130 QContactDetail detail = item->detail(); |
|
131 |
|
132 QString buttonText("No date set"); // loc missing |
|
133 if ( detail.definitionName() == QContactBirthday::DefinitionName ) |
|
134 { |
|
135 QContactBirthday bd = detail; |
|
136 if ( aNewDate != bd.date() ) |
|
137 { |
|
138 bd.setDate( aNewDate ); |
|
139 item->setDetail( bd ); |
|
140 } |
|
141 buttonText = mLocale.toString( aNewDate ); |
145 } |
142 } |
146 |
143 |
|
144 if ( detail.definitionName() == QContactAnniversary::DefinitionName ) |
|
145 { |
|
146 QContactAnniversary anniversary = detail; |
|
147 if ( aNewDate != anniversary.originalDate() ) |
|
148 { |
|
149 anniversary.setOriginalDate( aNewDate ); |
|
150 item->setDetail( anniversary ); |
|
151 } |
|
152 buttonText = mLocale.toString( aNewDate ); |
|
153 } |
|
154 |
|
155 mButton->setText( buttonText ); |
|
156 } |
|
157 |
|
158 void CntDateEditorViewItem::handleEditDate( HbAction *aAction ) |
|
159 { |
|
160 HbDialog *popup = static_cast<HbDialog*>(sender()); |
|
161 |
|
162 if (popup && aAction == popup->actions().first()) |
|
163 { |
|
164 QDate date = static_cast<HbDateTimePicker*>(popup->contentWidget())->date(); |
|
165 changeDate(date); |
|
166 } |
|
167 |
|
168 } |
|
169 |
147 // End of File |
170 // End of File |