|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbWidgets module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 #include "hbselectiondialog.h" |
|
26 #include "hbwidget_p.h" |
|
27 #include "hbselectiondialog_p.h" |
|
28 #include "hblabel.h" |
|
29 #include "hbaction.h" |
|
30 #include "hbabstractviewitem.h" |
|
31 #include <hbinstance.h> |
|
32 |
|
33 #include <QtDebug> |
|
34 #include <QGraphicsScene> |
|
35 #include <hblistwidgetitem.h> |
|
36 #include <hblistwidget.h> |
|
37 #include <hbradiobuttonlist.h> |
|
38 |
|
39 |
|
40 /*! |
|
41 @beta |
|
42 @hbwidgets |
|
43 \class HbSelectionDialog |
|
44 \brief HbSelectionDialog class allows user create a list of options out of which one or more can be selected. |
|
45 |
|
46 HbSelectionDialog is a modal dialog which means once it is displayed, user can not perform any action |
|
47 untill dialog is closed. |
|
48 |
|
49 There can be 2 modes of selection. SingleSelection or MultiSelection. If it is SingleSelection, dialog is closed |
|
50 as soon as user clicks one of the options.In case of MultiSelection, user has to explicitly press "OK" button to |
|
51 close it after selecting the item(s). User can anytime press "Cancel" button to close the dialog without selecting |
|
52 anything. |
|
53 |
|
54 User can provide the data for options in different forms. It can be simple list of strings, list of custom |
|
55 items or a model itself. |
|
56 */ |
|
57 |
|
58 |
|
59 /*! |
|
60 @beta |
|
61 Constructor of HbSelectionDialog |
|
62 |
|
63 \param parent. Parent widget |
|
64 */ |
|
65 HbSelectionDialog::HbSelectionDialog(QGraphicsItem* parent): |
|
66 HbDialog(*new HbSelectionDialogPrivate, parent) |
|
67 { |
|
68 Q_D(HbSelectionDialog); |
|
69 d->init(); |
|
70 setDismissPolicy(NoDismiss); |
|
71 } |
|
72 |
|
73 /*! |
|
74 @beta |
|
75 Destructor |
|
76 */ |
|
77 HbSelectionDialog::~HbSelectionDialog() |
|
78 { |
|
79 } |
|
80 |
|
81 /*! |
|
82 @beta |
|
83 |
|
84 \reimp |
|
85 */ |
|
86 void HbSelectionDialog::showEvent(QShowEvent *event) |
|
87 { |
|
88 HbDialog::showEvent(event); |
|
89 } |
|
90 |
|
91 /*! |
|
92 @beta |
|
93 Sets the \a SelectionMode of the list. |
|
94 |
|
95 \param mode. It can be SingleSelection or MultiSelection .Default value is \a NoSelection. |
|
96 |
|
97 \sa selectionMode() |
|
98 */ |
|
99 void HbSelectionDialog::setSelectionMode(HbAbstractItemView::SelectionMode mode) |
|
100 { |
|
101 Q_D(HbSelectionDialog); |
|
102 |
|
103 d->setSelectionMode(mode); |
|
104 } |
|
105 |
|
106 /*! |
|
107 @beta |
|
108 Returns current SelectionMode of the list.Default value is \a NoSelection. |
|
109 |
|
110 \sa setSelectionMode() |
|
111 */ |
|
112 HbAbstractItemView::SelectionMode HbSelectionDialog::selectionMode() const |
|
113 { |
|
114 Q_D(const HbSelectionDialog); |
|
115 return d->mSelectionMode; |
|
116 } |
|
117 |
|
118 /*! |
|
119 @beta |
|
120 Sets the string list items to be displayed. |
|
121 |
|
122 \param items. A items is the list of strings |
|
123 \param currentIndex. A currentIndex is the index of default selection |
|
124 |
|
125 \sa stringItems() |
|
126 */ |
|
127 void HbSelectionDialog::setStringItems(const QStringList &items,int currentIndex) |
|
128 { |
|
129 Q_D(HbSelectionDialog); |
|
130 d->setStringItems(items,currentIndex); |
|
131 } |
|
132 |
|
133 /*! |
|
134 @beta |
|
135 Returns list of string list items earlier set by setStringItems(). |
|
136 |
|
137 \sa setStringItems() |
|
138 */ |
|
139 QStringList HbSelectionDialog::stringItems() const |
|
140 { |
|
141 Q_D(const HbSelectionDialog); |
|
142 return d->stringItems(); |
|
143 } |
|
144 |
|
145 /*! |
|
146 @beta |
|
147 Returns list of selected indexes. List contains only one item if |
|
148 \a SelectionMode is \a NoSelection or \a SingleSelection. It may |
|
149 contain more items if \a SelectionMode is \a MultiSelection. |
|
150 |
|
151 \sa setSelectionMode(), |
|
152 \sa selectionMode() |
|
153 */ |
|
154 QList<QVariant> HbSelectionDialog::selectedItems() const |
|
155 { |
|
156 Q_D(const HbSelectionDialog); |
|
157 return d->selectedItems(); |
|
158 } |
|
159 |
|
160 /*! |
|
161 @beta |
|
162 set the item selected. |
|
163 It can select one item if \a Selection mode is \a SingleSelection |
|
164 it can select more item if \a SelectionMode is \a MultiSelection. |
|
165 |
|
166 \param items. |
|
167 |
|
168 \sa selectedItems |
|
169 */ |
|
170 void HbSelectionDialog::setSelectedItems(const QList<QVariant> items) |
|
171 { |
|
172 Q_D(HbSelectionDialog); |
|
173 d->setSelectedItems(items); |
|
174 } |
|
175 |
|
176 /*! |
|
177 @beta |
|
178 Returns list of selected model indexes. List contains only one item if |
|
179 \a SelectionMode is \a NoSelection or \a SingleSelection. It may |
|
180 contain more items if \a SelectionMode is \a MultiSelection. |
|
181 |
|
182 \sa setSelectionMode(), |
|
183 \sa selectionMode() |
|
184 */ |
|
185 QModelIndexList HbSelectionDialog::selectedModelIndexes() const |
|
186 { |
|
187 Q_D(const HbSelectionDialog); |
|
188 return d->selectedModelIndexes(); |
|
189 } |
|
190 |
|
191 /*! |
|
192 @beta |
|
193 Sets the list of custom list items to be displayed.\a items is the |
|
194 list of custom items.\a bTransferOwnership is a flag defining the owner |
|
195 of the items. If \a true, items will be deleted when dialog is deleted else |
|
196 user is responsible for deleting the items.Default value is \a false. |
|
197 \a current is the index of default selection. |
|
198 |
|
199 \param items. items is the list of custom items |
|
200 \param transferOwnership. true or false |
|
201 \param currentIndex |
|
202 |
|
203 \sa widgetItems(); |
|
204 */ |
|
205 void HbSelectionDialog::setWidgetItems(const QList<HbListWidgetItem*> &items,bool transferOwnership,int currentIndex) |
|
206 { |
|
207 Q_D(HbSelectionDialog); |
|
208 d->setWidgetItems(items,transferOwnership,currentIndex); |
|
209 } |
|
210 |
|
211 /*! |
|
212 @beta |
|
213 Returns list of custom list items earlier set by setWidgetItems(). |
|
214 |
|
215 \sa setWidgetItems(). |
|
216 */ |
|
217 QList<HbListWidgetItem*> HbSelectionDialog::widgetItems() const |
|
218 { |
|
219 Q_D(const HbSelectionDialog); |
|
220 return d->widgetItems(); |
|
221 } |
|
222 |
|
223 /*! |
|
224 @beta |
|
225 Sets the Model containing data for the list items. |
|
226 |
|
227 \param model. |
|
228 |
|
229 \sa model() |
|
230 */ |
|
231 void HbSelectionDialog::setModel(QAbstractItemModel* model) |
|
232 { |
|
233 Q_D(HbSelectionDialog); |
|
234 d->setModel(model); |
|
235 } |
|
236 |
|
237 /*! |
|
238 @beta |
|
239 Returns model eariler set by setModel(). |
|
240 |
|
241 \sa setModel() |
|
242 */ |
|
243 QAbstractItemModel* HbSelectionDialog::model() const |
|
244 { |
|
245 Q_D(const HbSelectionDialog); |
|
246 return d->model(); |
|
247 } |
|
248 |
|
249 |
|
250 #include "moc_hbselectiondialog.cpp" |