|
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 |
|
18 #include "nmuiheaders.h" |
|
19 |
|
20 static const double Un = 6.66; |
|
21 static const double Margin = 2 * Un; |
|
22 static const int MaxRows = 10000; |
|
23 static const double LabelFieldWidth = 10 * Un + Un; |
|
24 static const double ButtonWidth = 9.5 * Un; |
|
25 static const double FieldHeight = 5 * Un; |
|
26 |
|
27 /*! |
|
28 Constructor |
|
29 */ |
|
30 NmRecipientField::NmRecipientField( |
|
31 HbLabel *label, |
|
32 NmRecipientLineEdit *edit, |
|
33 HbPushButton *button, |
|
34 QGraphicsItem *parent): |
|
35 HbWidget(parent), |
|
36 mLabel(label), |
|
37 mRecipientsEditor(edit), |
|
38 mLaunchContactsPickerButton(button), |
|
39 mOwned(false) |
|
40 #ifdef Q_OS_SYMBIAN |
|
41 ,mLaunchContactsPickerRequest(NULL) |
|
42 #endif |
|
43 { |
|
44 mLaunchContactsPickerButton->setIcon(NmIcons::getIcon(NmIcons::NmIconContacts)); |
|
45 createConnections(); |
|
46 } |
|
47 |
|
48 |
|
49 /*! |
|
50 Constructor for 'Cc:' and 'Bcc:' fields. This can be removed when groupBox content |
|
51 widget is created using AD/docml |
|
52 */ |
|
53 NmRecipientField::NmRecipientField(const QString &labelString, QGraphicsItem *parent): |
|
54 HbWidget(parent), |
|
55 mLabel(NULL), |
|
56 mRecipientsEditor(NULL), |
|
57 mLaunchContactsPickerButton(NULL), |
|
58 mOwned(true) |
|
59 #ifdef Q_OS_SYMBIAN |
|
60 ,mLaunchContactsPickerRequest(NULL) |
|
61 #endif |
|
62 { |
|
63 mLayoutHorizontal = new QGraphicsLinearLayout(Qt::Horizontal, this); |
|
64 |
|
65 mLabel = new HbLabel(labelString); |
|
66 if (mLabel) { |
|
67 mLayoutHorizontal->addItem(mLabel); |
|
68 mLabel->setPreferredWidth(LabelFieldWidth); |
|
69 mLabel->setFontSpec(HbFontSpec(HbFontSpec::Secondary)); |
|
70 mLabel->setAlignment(Qt::AlignTop); |
|
71 } |
|
72 |
|
73 mRecipientsEditor = new NmRecipientLineEdit(); |
|
74 if (mRecipientsEditor) { |
|
75 mLayoutHorizontal->addItem(mRecipientsEditor); |
|
76 mRecipientsEditor->setMaxRows(MaxRows); |
|
77 mRecipientsEditor->setPreferredHeight(FieldHeight); |
|
78 mRecipientsEditor->setMinimumHeight(FieldHeight); |
|
79 mRecipientsEditor->setFontSpec(HbFontSpec(HbFontSpec::Secondary)); |
|
80 } |
|
81 |
|
82 mLaunchContactsPickerButton = new HbPushButton(); |
|
83 if (mLaunchContactsPickerButton) { |
|
84 mLayoutHorizontal->addItem(mLaunchContactsPickerButton); |
|
85 mLayoutHorizontal->setAlignment(mLaunchContactsPickerButton, Qt::AlignTop); |
|
86 mLaunchContactsPickerButton->setPreferredHeight(FieldHeight); |
|
87 mLaunchContactsPickerButton->setPreferredWidth(ButtonWidth); |
|
88 mLaunchContactsPickerButton->setMaximumHeight(FieldHeight); |
|
89 |
|
90 mLaunchContactsPickerButton->setIcon(NmIcons::getIcon(NmIcons::NmIconContacts)); |
|
91 } |
|
92 |
|
93 mLayoutHorizontal->setContentsMargins(0, 0, 0, 0); |
|
94 // Set the spacing between the line edit and the Add button to |
|
95 mLayoutHorizontal->setItemSpacing(1, Un); |
|
96 // Set the spacing between the label and the line edit to 0.0 |
|
97 mLayoutHorizontal->setItemSpacing(0, 0.0); |
|
98 |
|
99 createConnections(); |
|
100 } |
|
101 |
|
102 void NmRecipientField::createConnections() |
|
103 { |
|
104 connect(mRecipientsEditor, SIGNAL(textChanged(const QString &)), |
|
105 this, SIGNAL(textChanged(const QString &))); |
|
106 connect(mRecipientsEditor, SIGNAL(cursorPositionChanged(int, int)), |
|
107 this, SIGNAL(cursorPositionChanged(int, int))); |
|
108 connect(mRecipientsEditor, SIGNAL(editingFinished()), |
|
109 this, SIGNAL(editingFinished())); |
|
110 connect(mRecipientsEditor, SIGNAL(selectionChanged()), |
|
111 this, SIGNAL(selectionChanged())); |
|
112 connect(mLaunchContactsPickerButton, SIGNAL(pressed()), |
|
113 this, SIGNAL(launchContactsPickerButtonClicked())); |
|
114 |
|
115 #ifdef Q_OS_SYMBIAN |
|
116 connect(mLaunchContactsPickerButton, SIGNAL(pressed()), this, SLOT(launchContactsPicker())); |
|
117 #endif |
|
118 } |
|
119 |
|
120 |
|
121 /*! |
|
122 Destructor |
|
123 */ |
|
124 NmRecipientField::~NmRecipientField() |
|
125 { |
|
126 if (mOwned) |
|
127 { |
|
128 if (mLaunchContactsPickerButton) { |
|
129 delete mLaunchContactsPickerButton; |
|
130 mLaunchContactsPickerButton = 0; |
|
131 } |
|
132 if (mRecipientsEditor) { |
|
133 delete mRecipientsEditor; |
|
134 mRecipientsEditor = 0; |
|
135 } |
|
136 if (mLabel) { |
|
137 delete mLabel; |
|
138 mLabel = 0; |
|
139 } |
|
140 } |
|
141 |
|
142 #ifdef Q_OS_SYMBIAN |
|
143 if (mLaunchContactsPickerRequest) { |
|
144 delete mLaunchContactsPickerRequest; |
|
145 mLaunchContactsPickerRequest = 0; |
|
146 } |
|
147 #endif |
|
148 } |
|
149 |
|
150 /*! |
|
151 Widget height |
|
152 */ |
|
153 qreal NmRecipientField::height() |
|
154 { |
|
155 return mRecipientsEditor->geometry().height() + Margin; |
|
156 } |
|
157 |
|
158 /*! |
|
159 editor |
|
160 */ |
|
161 NmRecipientLineEdit *NmRecipientField::editor() const |
|
162 { |
|
163 return mRecipientsEditor; |
|
164 } |
|
165 |
|
166 |
|
167 /*! |
|
168 LineEdit contents |
|
169 */ |
|
170 const QString NmRecipientField::text() const |
|
171 { |
|
172 return mRecipientsEditor->text(); |
|
173 } |
|
174 |
|
175 |
|
176 /*! |
|
177 Slot setText |
|
178 */ |
|
179 void NmRecipientField::setText(const QString &newText) |
|
180 { |
|
181 if (newText != mRecipientsEditor->text()) { |
|
182 mRecipientsEditor->setText(newText); |
|
183 emit textChanged(newText); |
|
184 } |
|
185 } |
|
186 |
|
187 |
|
188 #ifdef Q_OS_SYMBIAN |
|
189 /*! |
|
190 This Slot launches the contacts-picker |
|
191 */ |
|
192 void NmRecipientField::launchContactsPicker() |
|
193 { |
|
194 if (mLaunchContactsPickerRequest) { |
|
195 delete mLaunchContactsPickerRequest; |
|
196 mLaunchContactsPickerRequest = 0; |
|
197 } |
|
198 |
|
199 mLaunchContactsPickerRequest = new XQServiceRequest |
|
200 ("com.nokia.services.phonebookservices.Fetch", |
|
201 "fetch(QString,QString,QString)", false); |
|
202 connect(mLaunchContactsPickerRequest, SIGNAL(requestCompleted(QVariant)), |
|
203 mRecipientsEditor, SLOT(insertSelectedContacts(QVariant))); |
|
204 |
|
205 // "Contacts" will be replaced by a hbTrId when it is ready |
|
206 *mLaunchContactsPickerRequest << tr("Contacts"); |
|
207 *mLaunchContactsPickerRequest << KCntActionAll; |
|
208 *mLaunchContactsPickerRequest << KCntActionAll; |
|
209 |
|
210 QVariant returnValue; |
|
211 mLaunchContactsPickerRequest->send(returnValue); |
|
212 } |
|
213 #endif |