25 #include <hblistviewitem.h> |
25 #include <hblistviewitem.h> |
26 #include <QStandardItemModel> |
26 #include <QStandardItemModel> |
27 |
27 |
28 QTM_USE_NAMESPACE |
28 QTM_USE_NAMESPACE |
29 |
29 |
30 CntDetailPopup::CntDetailPopup(QGraphicsItem *parent): |
30 CntDetailPopup::CntDetailPopup(QGraphicsItem *parent, CntViewIdList aList ): |
31 HbDialog(parent), |
31 HbDialog(parent), |
32 mListModel(NULL), |
32 mListModel(NULL), |
33 mListView(NULL) |
33 mListView(NULL), |
|
34 mSelectedDetail(0), |
|
35 mViewIdList( aList ) |
34 { |
36 { |
35 mListView = new HbListView(this); |
37 mListView = new HbListView(this); |
36 mListModel = new QStandardItemModel(this); |
38 mListModel = new QStandardItemModel(this); |
37 |
39 |
38 addListItem("qtg_small_mobile", hbTrId("txt_phob_list_number"), phoneNumberEditorView ); |
40 addListItem("qtg_small_mobile", hbTrId("txt_phob_list_number"), phoneNumberEditorView ); |
39 addListItem("qtg_small_email", hbTrId("txt_phob_list_email"), emailEditorView ); |
41 addListItem("qtg_small_email", hbTrId("txt_phob_list_email"), emailEditorView ); |
40 addListItem("qtg_small_url_address", hbTrId("txt_phob_list_url"), urlEditorView); |
42 addListItem("qtg_small_url_address", hbTrId("txt_phob_list_url"), urlEditorView); |
41 addListItem("qtg_small_location", hbTrId("txt_phob_list_address"), addressEditorView ); |
43 addListItem("qtg_small_location", hbTrId("txt_phob_list_address"), addressEditorView ); |
42 addListItem("qtg_small_note", hbTrId("txt_phob_formlabel_note"), noteEditorView); |
44 addListItem("qtg_small_note", hbTrId("txt_phob_list_note"), noteEditorView); |
43 addListItem("qtg_small_sound", hbTrId("txt_phob_formlabel_personal_ringing_tone"), noView ); |
45 addListItem("qtg_small_sound", hbTrId("txt_phob_list_personal_ringing_tone"), noView ); |
44 addListItem("qtg_small_calendar", hbTrId("txt_phob_formlabel_date"), dateEditorView); |
46 addListItem("qtg_small_calendar", hbTrId("txt_phob_list_date"), dateEditorView); |
45 addListItem("qtg_small_company_details", hbTrId("txt_phob_formlabel_company_details"), companyEditorView); |
47 addListItem("qtg_small_company_details", hbTrId("txt_phob_list_company_details"), companyEditorView); |
46 addListItem("qtg_small_family", hbTrId("txt_phob_formlabel_family"), familyDetailEditorView); |
48 addListItem("qtg_small_family", hbTrId("txt_phob_list_family"), familyDetailEditorView); |
47 |
49 |
48 mListView->setModel(mListModel); |
50 mListView->setModel(mListModel); |
49 mListView->setSelectionMode(HbAbstractItemView::NoSelection); |
51 mListView->setSelectionMode(HbAbstractItemView::NoSelection); |
50 // ownership of prototype is not transferred |
52 // ownership of prototype is not transferred |
51 HbListViewItem* prototype = mListView->listItemPrototype(); |
53 HbListViewItem* prototype = mListView->listItemPrototype(); |
52 prototype->setGraphicsSize( HbListViewItem::SmallIcon ); |
54 prototype->setGraphicsSize( HbListViewItem::SmallIcon ); |
53 |
55 |
54 HbGroupBox *headingLabel = new HbGroupBox(); |
56 HbLabel *label = new HbLabel(this); |
55 HbLabel *label = new HbLabel(hbTrId("txt_phob_title_add_field")); |
57 label->setPlainText(hbTrId("txt_phob_title_add_field")); |
56 headingLabel->setContentWidget(label); |
|
57 |
58 |
58 setHeadingWidget(headingLabel); |
59 setHeadingWidget(label); |
59 setContentWidget(mListView); |
60 setContentWidget(mListView); |
60 |
61 |
61 HbAction *mSecondaryAction = new HbAction(hbTrId("txt_common_button_cancel")); |
62 HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"), this); |
62 setSecondaryAction(mSecondaryAction); |
63 addAction(cancelAction); |
63 setTimeout(0); |
64 setTimeout(HbDialog::NoTimeout); |
|
65 setDismissPolicy(HbDialog::NoDismiss); |
|
66 setAttribute(Qt::WA_DeleteOnClose, true); |
64 setModal(true); |
67 setModal(true); |
65 |
68 |
66 connect(mListView, SIGNAL(activated(const QModelIndex&)), this, SLOT(listItemSelected(QModelIndex))); |
69 connect(mListView, SIGNAL(activated(const QModelIndex&)), this, SLOT(listItemSelected(QModelIndex))); |
67 } |
70 } |
68 |
71 |
70 { |
73 { |
71 } |
74 } |
72 |
75 |
73 void CntDetailPopup::listItemSelected(QModelIndex index) |
76 void CntDetailPopup::listItemSelected(QModelIndex index) |
74 { |
77 { |
75 mSelectedDetail = mListModel->item(index.row(), 1)->text(); |
78 mSelectedDetail = mListModel->item(index.row())->data(Qt::UserRole).toInt(); |
76 close(); |
79 close(); |
77 } |
80 } |
78 |
81 |
79 QString CntDetailPopup::selectedDetail() |
82 int CntDetailPopup::selectedDetail() |
80 { |
83 { |
81 return mSelectedDetail; |
84 return mSelectedDetail; |
82 } |
85 } |
83 |
86 |
84 int CntDetailPopup::selectDetail() |
87 void CntDetailPopup::selectDetail( CntViewIdList aList, QObject *receiver, const char *member ) |
85 { |
88 { |
86 CntDetailPopup *popup = new CntDetailPopup(); |
89 CntDetailPopup *popup = new CntDetailPopup( NULL, aList ); |
87 QString result; |
90 |
88 |
91 popup->open(receiver, member); |
89 HbAction *action = popup->exec(); |
|
90 |
|
91 if (action != popup->secondaryAction() && !popup->selectedDetail().isEmpty()) |
|
92 { |
|
93 result = popup->selectedDetail(); |
|
94 } |
|
95 delete popup; |
|
96 |
|
97 return result.toInt(); |
|
98 } |
92 } |
99 |
93 |
100 void CntDetailPopup::addListItem(QString aIcon, QString label, int aId ) |
94 void CntDetailPopup::addListItem(QString aIcon, QString label, int aId ) |
101 { |
95 { |
102 QList<QStandardItem*> items; |
96 if ( !mViewIdList.contains(aId) ) |
103 QStandardItem *labelItem = new QStandardItem(HbIcon(aIcon).qicon(), label); |
97 { |
104 QString id; |
98 QStandardItem *labelItem = new QStandardItem(label); |
105 QStandardItem *idItem = new QStandardItem( id.number(aId) ); |
99 labelItem->setData(HbIcon(aIcon), Qt::DecorationRole); |
|
100 labelItem->setData(aId, Qt::UserRole); |
106 |
101 |
107 items << labelItem << idItem; |
102 mListModel->appendRow(labelItem); |
108 mListModel->appendRow(items); |
103 } |
109 } |
104 } |