32 #include <hblistwidgetitem.h> |
32 #include <hblistwidgetitem.h> |
33 #include <QtDebug> |
33 #include <QtDebug> |
34 #include <hbcheckbox.h> |
34 #include <hbcheckbox.h> |
35 #include <hbaction.h> |
35 #include <hbaction.h> |
36 #include <hbstyleoption_p.h> |
36 #include <hbstyleoption_p.h> |
37 |
37 #include <hbstyleprimitivedata.h> |
38 HbSelectionDialogMarkWidget::HbSelectionDialogMarkWidget(QGraphicsItem *parent):HbWidget(parent),mBackgroundItem(0){ |
38 #include <hbstyleframeprimitivedata.h> |
39 chkMark = new HbCheckBox(this); |
39 #include <hbstyletextprimitivedata.h> |
40 chkMark->setText("Mark All"); |
40 #include <hbstringutil.h> |
41 lbCounter = new HbTextItem(this); |
41 |
42 HbStyle::setItemName(chkMark,"checkbox"); |
42 HbSelectionDialogMarkWidget::HbSelectionDialogMarkWidget(QGraphicsItem *parent):HbWidget(parent),mBackgroundItem(0),mLbCounter(0){ |
43 HbStyle::setItemName(lbCounter,"counter"); |
43 chkMark = new HbCheckBox(this); |
44 createPrimitives(); |
44 HbStyle::setItemName(chkMark,"checkbox"); |
|
45 createPrimitives(); |
45 } |
46 } |
46 |
47 |
47 void HbSelectionDialogMarkWidget::createPrimitives() |
48 void HbSelectionDialogMarkWidget::createPrimitives() |
48 { |
49 { |
49 if ( !mBackgroundItem ) { |
50 if (!mBackgroundItem ) { |
50 mBackgroundItem = style( )->createPrimitive( HbStyle::P_TumbleView_background , this ); |
51 mBackgroundItem = style()->createPrimitive( HbStyle::PT_FrameItem ,"background",this ); |
51 style()->setItemName( mBackgroundItem , "background" ); |
52 mBackgroundItem->setZValue(-5); |
52 } |
53 } |
|
54 if(!mLbCounter){ |
|
55 mLbCounter = style()->createPrimitive( HbStyle::PT_TextItem ,"counter",this ); |
|
56 } |
|
57 } |
|
58 |
|
59 void HbSelectionDialogMarkWidget::recreatePrimitives() |
|
60 { |
|
61 delete mBackgroundItem; |
|
62 mBackgroundItem = style()->createPrimitive( HbStyle::PT_FrameItem ,"background",this ); |
|
63 mBackgroundItem->setZValue(-5); |
|
64 |
|
65 delete mLbCounter; |
|
66 mLbCounter = style()->createPrimitive( HbStyle::PT_TextItem ,"counter",this ); |
|
67 |
|
68 } |
|
69 void HbSelectionDialogMarkWidget::initPrimitiveData(HbStylePrimitiveData *primitiveData, const QGraphicsObject *primitive) |
|
70 { |
|
71 HbWidgetBase::initPrimitiveData(primitiveData, primitive); |
|
72 QString itemName = HbStyle::itemName(primitive); |
|
73 if (itemName == QLatin1String("background")) { |
|
74 HbStyleFramePrimitiveData* data = hbstyleprimitivedata_cast<HbStyleFramePrimitiveData*>(primitiveData); |
|
75 data->frameGraphicsName = QLatin1String("qtg_fr_groupbox"); |
|
76 data->frameType = HbFrameDrawer::NinePieces; |
|
77 } |
|
78 else if (itemName == QLatin1String("counter")) { |
|
79 HbStyleTextPrimitiveData *data = hbstyleprimitivedata_cast<HbStyleTextPrimitiveData*>(primitiveData); |
|
80 data->text = mCounterText; |
|
81 } |
|
82 |
|
83 } |
|
84 |
|
85 void HbSelectionDialogMarkWidget::updateCounter(const QString& text) |
|
86 { |
|
87 mCounterText = text; |
|
88 HbStyleTextPrimitiveData data; |
|
89 initPrimitiveData(&data, mLbCounter); |
|
90 style()->updatePrimitive(mLbCounter, &data, this); |
53 } |
91 } |
54 |
92 |
55 void HbSelectionDialogMarkWidget::updatePrimitives() |
93 void HbSelectionDialogMarkWidget::updatePrimitives() |
56 { |
94 { |
57 HbStyleOption option; |
95 if (mBackgroundItem) { |
58 initStyleOption( &option ); |
96 HbStyleFramePrimitiveData frameData; |
59 |
97 initPrimitiveData(&frameData, mBackgroundItem); |
60 if ( mBackgroundItem ) { |
98 style()->updatePrimitive(mBackgroundItem, &frameData, this); |
61 style( )->updatePrimitive( mBackgroundItem , HbStyle::P_TumbleView_background , &option ); |
99 } |
62 } |
|
63 } |
100 } |
64 |
101 |
65 /*! |
102 /*! |
66 \reimp |
103 \reimp |
67 */ |
104 */ |
68 QVariant HbSelectionDialogMarkWidget::itemChange( GraphicsItemChange change, const QVariant &value ) |
105 QVariant HbSelectionDialogMarkWidget::itemChange( GraphicsItemChange change, const QVariant &value ) |
69 { |
106 { |
70 switch ( change ) { |
107 switch ( change ) { |
71 case ItemVisibleHasChanged: { |
108 case ItemVisibleHasChanged: { |
72 updatePrimitives( ); |
109 updatePrimitives( ); |
73 } |
110 } |
74 break; |
111 break; |
75 |
112 |
76 case ItemSceneHasChanged: { |
113 case ItemSceneHasChanged: { |
77 updatePrimitives(); |
114 updatePrimitives(); |
80 default: |
117 default: |
81 break; |
118 break; |
82 } |
119 } |
83 return HbWidget::itemChange( change, value ); |
120 return HbWidget::itemChange( change, value ); |
84 } |
121 } |
|
122 |
85 /*! |
123 /*! |
86 Returns the pointer for \a primitive passed. |
124 \reimp |
87 Will return NULL if \a primitive passed is invalid |
|
88 */ |
125 */ |
89 QGraphicsItem* HbSelectionDialogMarkWidget::primitive(HbStyle::Primitive primitive) const |
126 QGraphicsItem *HbSelectionDialogMarkWidget::primitive(const QString &itemName) const |
90 { |
127 { |
91 switch (primitive) { |
128 if(!itemName.compare(QString("background"))){ |
92 case HbStyle::P_TumbleView_background: |
129 return mBackgroundItem; |
93 return mBackgroundItem; |
130 } |
94 default: |
131 |
95 return 0; |
132 return HbWidget::primitive(itemName); |
96 } |
133 } |
97 } |
134 |
98 |
135 |
99 HbSelectionDialogMarkWidget::~HbSelectionDialogMarkWidget() |
136 HbSelectionDialogMarkWidget::~HbSelectionDialogMarkWidget() |
100 { |
137 { |
101 } |
138 } |
102 |
139 |
103 HbSelectionDialogContentWidget::HbSelectionDialogContentWidget(HbSelectionDialogPrivate *priv):HbWidget(), |
140 HbSelectionDialogContentWidget::HbSelectionDialogContentWidget(HbSelectionDialogPrivate *priv):HbWidget(), |
104 mListView(0),d(priv),markWidget(0) |
141 mListView(0),d(priv),markWidget(0) |
105 { |
142 { |
106 |
143 mSelectionTitle = hbTrId("txt_common_list_mark_all_items"); |
107 } |
144 } |
108 |
145 |
109 void HbSelectionDialogContentWidget::_q_listWidgetItemSelected(HbListWidgetItem *item) |
146 void HbSelectionDialogContentWidget::_q_listWidgetItemSelected(HbListWidgetItem *item) |
110 { |
147 { |
111 Q_UNUSED(item) |
148 Q_UNUSED(item) |
112 } |
149 } |
113 |
150 |
114 void HbSelectionDialogContentWidget::_q_listItemSelected(QModelIndex index) |
|
115 { |
|
116 Q_UNUSED(index) |
|
117 if(mListView->selectionMode()== HbAbstractItemView::SingleSelection){ |
|
118 d->close(); |
|
119 } |
|
120 updateCounter(); |
|
121 } |
|
122 |
151 |
123 int HbSelectionDialogContentWidget::selectedItemCount() const |
152 int HbSelectionDialogContentWidget::selectedItemCount() const |
124 { |
153 { |
125 int selectedItems = 0; |
154 int selectedItems = 0; |
126 if(mListView){ |
155 if(mListView){ |
127 QItemSelectionModel* selectionModel = mListView->selectionModel(); |
156 QItemSelectionModel* selectionModel = mListView->selectionModel(); |
128 if(selectionModel){ |
157 if(selectionModel){ |
129 selectedItems = selectionModel->selectedRows().count(); |
158 selectedItems = selectionModel->selectedRows().count(); |
130 } |
159 } |
131 } |
160 } |
132 return selectedItems; |
161 return selectedItems; |
133 } |
162 } |
134 |
163 |
135 int HbSelectionDialogContentWidget::totalItemCount() const |
164 int HbSelectionDialogContentWidget::totalItemCount() const |
136 { |
165 { |
137 int nCount = 0; |
166 int nCount = 0; |
138 if(mListView && mListView->model()){ |
167 if(mListView && mListView->model()){ |
139 nCount = mListView->model()->rowCount(); |
168 nCount = mListView->model()->rowCount(); |
140 } |
169 } |
141 return nCount; |
170 return nCount; |
|
171 } |
|
172 |
|
173 void HbSelectionDialogContentWidget::setModel(QAbstractItemModel* model) |
|
174 { |
|
175 if(mListView){ |
|
176 HbListWidget* mView = qobject_cast<HbListWidget*>(mListView); |
|
177 if(!mView){ //can not set model on HbListWidget |
|
178 QObject::disconnect(mListView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),this,SLOT(_q_selectionChanged(const QItemSelection&, const QItemSelection&))); |
|
179 mListView->setModel(model); |
|
180 if(model) |
|
181 QObject::connect(mListView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),this,SLOT(_q_selectionChanged(const QItemSelection&, const QItemSelection&))); |
|
182 } |
|
183 } |
|
184 } |
|
185 |
|
186 QString HbSelectionDialogContentWidget::selectionTitle() const |
|
187 { |
|
188 return mSelectionTitle; |
|
189 } |
|
190 |
|
191 void HbSelectionDialogContentWidget::setSelectionTitle(const QString& title) |
|
192 { |
|
193 if(mSelectionTitle != title){ |
|
194 mSelectionTitle = title; |
|
195 if(markWidget) |
|
196 markWidget->chkMark->setText(mSelectionTitle); |
|
197 } |
142 } |
198 } |
143 |
199 |
144 void HbSelectionDialogContentWidget::updateCounter() |
200 void HbSelectionDialogContentWidget::updateCounter() |
145 { |
201 { |
146 if(!mListView) return; |
202 if(!mListView) return; |
147 if(mListView->selectionMode()!= HbAbstractItemView::MultiSelection) return; |
203 if(mListView->selectionMode()!= HbAbstractItemView::MultiSelection) return; |
148 if(markWidget){ |
204 if(markWidget){ |
149 int totalItems = totalItemCount(); |
205 int totalItems = totalItemCount(); |
150 int selectedItems = selectedItemCount(); |
206 int selectedItems = selectedItemCount(); |
151 markWidget->updatePrimitives(); |
207 markWidget->updatePrimitives(); |
152 markWidget->lbCounter->setText(QString(QString::number(selectedItems) + "/" + QString::number(totalItems))); |
208 markWidget->updateCounter(QString(HbStringUtil::convertDigits(QString::number(selectedItems)) + "/" + HbStringUtil::convertDigits(QString::number(totalItems)))); |
153 //update checked state of "MarkAll" checkbox |
209 //update checked state of "MarkAll" checkbox |
154 if (totalItems > 0 && (selectedItems == totalItems)){ |
210 if (totalItems > 0 && (selectedItems == totalItems)){ |
155 markWidget->chkMark->blockSignals(true); //should not call _q_checkboxclicked() |
211 markWidget->chkMark->blockSignals(true); //should not call _q_checkboxclicked() |
156 markWidget->chkMark->setChecked(true); |
212 markWidget->chkMark->setChecked(true); |
157 markWidget->chkMark->blockSignals(false); |
213 markWidget->chkMark->blockSignals(false); |
189 updateCounter(); |
241 updateCounter(); |
190 } |
242 } |
191 |
243 |
192 void HbSelectionDialogContentWidget::showMarkWidget(bool bShow) |
244 void HbSelectionDialogContentWidget::showMarkWidget(bool bShow) |
193 { |
245 { |
194 if(bShow){ |
246 if(bShow){ |
195 if(!markWidget){ |
247 if(!markWidget){ |
196 markWidget = new HbSelectionDialogMarkWidget(this); |
248 markWidget = new HbSelectionDialogMarkWidget(this); |
197 HbStyle::setItemName(markWidget,"markwidget"); |
249 markWidget->chkMark->setText(mSelectionTitle); |
198 setProperty("multiSelection",true); |
250 } |
199 connect(markWidget->chkMark,SIGNAL(stateChanged ( int )),this,SLOT(_q_checkboxclicked(int))); |
251 else{ |
200 updateCounter(); |
252 markWidget->show(); |
201 } |
253 } |
|
254 HbStyle::setItemName(markWidget,"markwidget"); |
|
255 connect(markWidget->chkMark,SIGNAL(stateChanged ( int )),this,SLOT(_q_checkboxclicked(int))); |
|
256 repolish(); |
|
257 updateCounter(); |
202 } |
258 } |
203 else{ |
259 else{ |
204 delete markWidget; markWidget = 0; |
260 if(markWidget){ |
205 HbStyle::setItemName(markWidget,""); |
261 HbStyle::setItemName(markWidget,""); |
206 setProperty("multiSelection",false); |
262 markWidget->hide(); |
|
263 repolish(); |
|
264 } |
207 } |
265 } |
208 } |
266 } |
209 |
267 |
210 void HbSelectionDialogContentWidget::connectSlots() |
268 void HbSelectionDialogContentWidget::connectSlots() |
211 { |
269 { |
212 QObject::connect(mListView,SIGNAL(activated(const QModelIndex&)),this,SLOT(_q_listItemSelected(QModelIndex))); |
270 QObject::connect(mListView,SIGNAL(activated(const QModelIndex&)),this,SLOT(_q_listItemSelected(QModelIndex))); |
|
271 QObject::connect(mListView->model(),SIGNAL(rowsRemoved(const QModelIndex& ,int,int)),this,SLOT(modelChanged(const QModelIndex&,int,int))); |
|
272 QObject::connect(mListView->model(),SIGNAL(rowsInserted(const QModelIndex& ,int,int)),this,SLOT(modelChanged(const QModelIndex&,int,int))); |
|
273 } |
|
274 |
|
275 void HbSelectionDialogContentWidget::_q_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) |
|
276 { |
|
277 Q_UNUSED(selected); |
|
278 Q_UNUSED(deselected); |
|
279 updateCounter(); |
|
280 if(mListView->selectionMode()== HbAbstractItemView::MultiSelection) |
|
281 d->_p_SelectionChanged(); |
|
282 } |
|
283 |
|
284 void HbSelectionDialogContentWidget::_q_listItemSelected(QModelIndex index) |
|
285 { |
|
286 Q_UNUSED(index) |
|
287 if(mListView->selectionMode()== HbAbstractItemView::SingleSelection || mListView->selectionMode()== HbAbstractItemView::NoSelection){ |
|
288 d->close(); |
|
289 } |
|
290 updateCounter(); |
|
291 } |
|
292 |
|
293 |
|
294 void HbSelectionDialogContentWidget::modelChanged(const QModelIndex &parent, int start,int end) |
|
295 { |
|
296 Q_UNUSED(parent); |
|
297 Q_UNUSED(start); |
|
298 Q_UNUSED(end); |
|
299 updateCounter(); |
213 } |
300 } |
214 |
301 |
215 void HbSelectionDialogContentWidget::createListWidget() |
302 void HbSelectionDialogContentWidget::createListWidget() |
216 { |
303 { |
217 if(mListView){ |
304 if(mListView){ |
218 HbListWidget* mView = qobject_cast<HbListWidget*>(mListView); |
305 QObject::disconnect(mListView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),this,SLOT(_q_selectionChanged(const QItemSelection&, const QItemSelection&))); |
219 if(!mView){ |
306 HbListWidget* mView = qobject_cast<HbListWidget*>(mListView); |
220 delete mListView; |
307 if(!mView){ |
221 mListView = new HbListWidget(this); |
308 delete mListView; |
222 HbStyle::setItemName(mListView, "list"); |
309 mListView = new HbListWidget(this); |
223 connectSlots(); |
310 HbStyle::setItemName(mListView, "list"); |
224 } |
311 connectSlots(); |
225 } |
312 repolish(); |
226 else{ |
313 } |
227 mListView = new HbListWidget(this); |
314 } |
228 HbStyle::setItemName(mListView, "list"); |
315 else{ |
229 connectSlots(); |
316 mListView = new HbListWidget(this); |
230 } |
317 HbStyle::setItemName(mListView, "list"); |
|
318 connectSlots(); |
|
319 repolish(); |
|
320 } |
|
321 QObject::connect(mListView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),this,SLOT(_q_selectionChanged(const QItemSelection&, const QItemSelection&))); |
231 } |
322 } |
232 |
323 |
233 void HbSelectionDialogContentWidget::createListView() |
324 void HbSelectionDialogContentWidget::createListView() |
234 { |
325 { |
235 if(mListView){ |
326 if(mListView){ |
236 HbListView* mView = qobject_cast<HbListView*>(mListView); |
327 QObject::disconnect(mListView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),this,SLOT(_q_selectionChanged(const QItemSelection&, const QItemSelection&))); |
237 if(!mView){ |
328 HbListWidget* mView = qobject_cast<HbListWidget*>(mListView); |
238 delete mListView; |
329 if(mView){ |
239 mListView = new HbListView(this); |
330 delete mListView; |
240 HbStyle::setItemName(mListView, "list"); |
331 mListView = new HbListView(this); |
241 connectSlots(); |
332 HbStyle::setItemName(mListView, "list"); |
242 } |
333 connectSlots(); |
243 } |
334 repolish(); |
244 else{ |
335 } |
245 mListView = new HbListView(this); |
336 } |
246 HbStyle::setItemName(mListView, "list"); |
337 else{ |
247 connectSlots(); |
338 mListView = new HbListView(this); |
248 } |
339 HbStyle::setItemName(mListView, "list"); |
|
340 connectSlots(); |
|
341 repolish(); |
|
342 } |
|
343 QObject::connect(mListView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),this,SLOT(_q_selectionChanged(const QItemSelection&, const QItemSelection&))); |
249 } |
344 } |
250 |
345 |
251 HbSelectionDialogPrivate::HbSelectionDialogPrivate() |
346 HbSelectionDialogPrivate::HbSelectionDialogPrivate() |
252 :HbDialogPrivate() |
347 :HbDialogPrivate() |
253 { |
348 { |
254 bOwnItems = false; |
349 bOwnItems = false; |
255 action1 = action2 = 0; |
350 // action1 = action2 = 0; |
256 } |
351 } |
257 |
352 |
258 HbSelectionDialogPrivate::~HbSelectionDialogPrivate() |
353 HbSelectionDialogPrivate::~HbSelectionDialogPrivate() |
259 { |
354 { |
260 clearItems(bOwnItems); |
355 clearItems(bOwnItems); |
261 } |
356 } |
262 |
357 |
263 void HbSelectionDialogPrivate::init() |
358 void HbSelectionDialogPrivate::init() |
264 { |
359 { |
265 qDebug()<<" Entering init()"; |
360 qDebug()<<" Entering init()"; |
266 Q_Q(HbSelectionDialog); |
361 Q_Q(HbSelectionDialog); |
267 |
362 |
268 bOwnItems = false; |
363 bOwnItems = false; |
269 mSelectionMode = HbAbstractItemView::SingleSelection; |
364 mSelectionMode = HbAbstractItemView::SingleSelection; |
270 HbSelectionDialogContentWidget* contentWidget = new HbSelectionDialogContentWidget(this); |
365 HbSelectionDialogContentWidget* contentWidget = new HbSelectionDialogContentWidget(this); |
271 q->setContentWidget(contentWidget); |
366 q->setContentWidget(contentWidget); |
272 |
367 |
273 q->setDismissPolicy(HbPopup::NoDismiss); |
368 q->setDismissPolicy(HbPopup::NoDismiss); |
274 q->setTimeout(HbPopup::NoTimeout); |
369 q->setTimeout(HbPopup::NoTimeout); |
275 q->setModal(true); |
370 q->setModal(true); |
276 showActions(mSelectionMode); |
371 showActions(mSelectionMode); |
|
372 } |
|
373 |
|
374 void HbSelectionDialogPrivate::_p_SelectionChanged() |
|
375 { |
|
376 Q_Q(HbSelectionDialog); |
|
377 if(mSelectionMode == HbAbstractItemView::MultiSelection) |
|
378 { |
|
379 if(action1){ |
|
380 QItemSelectionModel *model = 0; |
|
381 model = selectionModel(); |
|
382 if(model->selectedRows().count()==0) |
|
383 action1->setEnabled(false); |
|
384 else |
|
385 action1->setEnabled(true); |
|
386 } |
|
387 emit q->selectionChanged(); |
|
388 } |
277 } |
389 } |
278 |
390 |
279 void HbSelectionDialogPrivate::showActions(HbAbstractItemView::SelectionMode selectionMode) |
391 void HbSelectionDialogPrivate::showActions(HbAbstractItemView::SelectionMode selectionMode) |
280 { |
392 { |
281 Q_Q(HbSelectionDialog); |
393 Q_Q(HbSelectionDialog); |
282 if(selectionMode == HbAbstractItemView::SingleSelection){ |
394 if(selectionMode == HbAbstractItemView::SingleSelection || selectionMode == HbAbstractItemView::NoSelection){ |
283 delete action1;action1=0;delete action2;action2=0; |
395 if(action1) { |
284 action1=new HbAction(hbTrId("txt_common_button_cancel"),q); |
396 q->disconnect(action1,SIGNAL(triggered()),q,SLOT(accept())); |
285 q->addAction(action1); |
397 q->removeAction(action1); |
286 q->connect(action1,SIGNAL(triggered()),q,SLOT(reject())); |
398 } |
287 } |
399 if(action2 == NULL){ |
288 else{ |
400 action2 =new HbAction(hbTrId("txt_common_button_cancel"),q); |
289 delete action1;action1=0;delete action2;action2=0; |
401 } |
290 action1=new HbAction(hbTrId("txt_common_button_ok"),q); |
402 if(q->actions().contains(action2) == false){ |
291 q->addAction(action1); |
403 q->connect(action2,SIGNAL(triggered()),q,SLOT(reject())); |
292 q->connect(action1,SIGNAL(triggered()),q,SLOT(accept())); |
404 q->insertAction(0,action2); |
293 action2=new HbAction(hbTrId("txt_common_button_cancel"),q); |
405 } |
294 q->addAction(action2); |
406 } |
295 q->connect(action2,SIGNAL(triggered()),q,SLOT(reject())); |
407 else{ |
296 } |
408 |
|
409 if(action2 == NULL){ |
|
410 action2 =new HbAction(hbTrId("txt_common_button_cancel"),q); |
|
411 } |
|
412 if(q->actions().contains(action2) == false){ |
|
413 q->connect(action2,SIGNAL(triggered()),q,SLOT(reject())); |
|
414 q->insertAction(0,action2); |
|
415 } |
|
416 if(action1 == NULL){ |
|
417 action1 =new HbAction(hbTrId("txt_common_button_ok"),q); |
|
418 } |
|
419 if(q->actions().contains(action1) == false) |
|
420 { |
|
421 q->connect(action1,SIGNAL(triggered()),q,SLOT(accept())); |
|
422 q->insertAction(q->actions().first(),action1); |
|
423 } |
|
424 } |
|
425 |
297 } |
426 } |
298 |
427 |
299 void HbSelectionDialogPrivate::setSelectionMode(HbAbstractItemView::SelectionMode mode) |
428 void HbSelectionDialogPrivate::setSelectionMode(HbAbstractItemView::SelectionMode mode) |
300 { |
429 { |
301 Q_Q(HbSelectionDialog); |
430 Q_Q(HbSelectionDialog); |
302 |
431 |
303 mSelectionMode = mode; |
432 mSelectionMode = mode; |
304 switch(mSelectionMode) |
433 switch(mSelectionMode) |
305 { |
434 { |
|
435 case HbAbstractItemView::NoSelection: |
306 case HbAbstractItemView::SingleSelection: |
436 case HbAbstractItemView::SingleSelection: |
307 case HbAbstractItemView::MultiSelection: |
437 case HbAbstractItemView::MultiSelection: |
308 { |
438 { |
309 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
439 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
310 if(cWidget && cWidget->mListView){ |
440 if(cWidget && cWidget->mListView){ |
311 cWidget->mListView->setSelectionMode(mSelectionMode); |
441 cWidget->mListView->setSelectionMode(mSelectionMode); |
312 if(mode == HbAbstractItemView::MultiSelection) |
442 if(mode == HbAbstractItemView::MultiSelection){ |
313 cWidget->showMarkWidget(true); |
443 cWidget->showMarkWidget(true); |
314 else |
444 q->setFullScreen(true); |
315 cWidget->showMarkWidget(false); |
445 } |
316 } |
446 else{ |
317 showActions(mSelectionMode); |
447 cWidget->showMarkWidget(false); |
|
448 q->setFullScreen(false); |
|
449 } |
|
450 } |
|
451 showActions(mSelectionMode); |
318 } |
452 } |
319 break; |
453 break; |
320 case HbAbstractItemView::NoSelection: |
454 default: |
321 break; |
455 break; |
322 } |
456 } |
323 } |
457 } |
324 |
458 |
325 |
459 |
326 void HbSelectionDialogPrivate::clearItems(bool keepItems) |
460 void HbSelectionDialogPrivate::clearItems(bool keepItems) |
327 { |
461 { |
328 Q_Q(HbSelectionDialog); |
462 Q_Q(HbSelectionDialog); |
329 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
463 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
330 if(cWidget){ |
464 if(cWidget){ |
331 HbListWidget* mWidget = qobject_cast<HbListWidget*>(cWidget->mListView); |
465 HbListWidget* mWidget = qobject_cast<HbListWidget*>(cWidget->mListView); |
332 if(mWidget){ |
466 if(mWidget){ |
333 if(keepItems){ |
467 if(keepItems){ |
334 int nRows = 0; |
468 int nRows = 0; |
335 QAbstractItemModel* itemModel = mWidget->model(); |
469 QAbstractItemModel* itemModel = mWidget->model(); |
336 if(itemModel){ |
470 if(itemModel){ |
337 nRows = itemModel->rowCount(); |
471 nRows = itemModel->rowCount(); |
338 while(nRows){ |
472 while(nRows){ |
339 mWidget->takeItem(0); |
473 mWidget->takeItem(0); |
340 nRows = itemModel->rowCount(); |
474 nRows = itemModel->rowCount(); |
341 } |
475 } |
342 } |
476 } |
343 } |
477 } |
344 else{ |
478 else{ |
345 mWidget->clear(); |
479 mWidget->clear(); |
346 } |
480 } |
347 bOwnItems = false; |
481 bOwnItems = false; |
348 return; |
482 return; |
349 } |
483 } |
350 HbListView* mView = qobject_cast<HbListView*>(cWidget->mListView); |
484 HbListView* mView = qobject_cast<HbListView*>(cWidget->mListView); |
351 if(mView){ |
485 if(mView){ |
352 cWidget->mListView->setModel(0); |
486 cWidget->setModel(0); |
353 } |
487 } |
354 } |
488 } |
355 } |
489 } |
356 |
490 |
357 QList<HbListWidgetItem*> HbSelectionDialogPrivate::widgetItems() const |
491 QList<HbListWidgetItem*> HbSelectionDialogPrivate::widgetItems() const |
358 { |
492 { |
359 Q_Q(const HbSelectionDialog); |
493 Q_Q(const HbSelectionDialog); |
426 { |
560 { |
427 Q_Q(HbSelectionDialog); |
561 Q_Q(HbSelectionDialog); |
428 |
562 |
429 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
563 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
430 if(cWidget){ |
564 if(cWidget){ |
431 cWidget->createListView(); |
565 cWidget->createListView(); |
432 setSelectionMode(mSelectionMode); |
566 setSelectionMode(mSelectionMode); |
433 cWidget->mListView->setModel(model); |
567 cWidget->setModel(model); |
|
568 cWidget->updateCounter(); |
434 } |
569 } |
435 } |
570 } |
436 |
571 |
437 void HbSelectionDialogPrivate::setWidgetItems(const QList<HbListWidgetItem*> &items,bool transferOwnership,int currentIndex) |
572 void HbSelectionDialogPrivate::setWidgetItems(const QList<HbListWidgetItem*> &items,bool transferOwnership,int currentIndex) |
438 { |
573 { |
439 Q_Q(HbSelectionDialog); |
574 Q_Q(HbSelectionDialog); |
440 |
575 |
441 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
576 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
442 if(cWidget){ |
577 if(cWidget){ |
443 cWidget->createListWidget(); |
578 cWidget->createListWidget(); |
444 setSelectionMode(mSelectionMode); |
579 setSelectionMode(mSelectionMode); |
445 if(cWidget->mListView){ |
580 if(cWidget->mListView){ |
446 HbListWidget* widget = (HbListWidget*)cWidget->mListView; |
581 HbListWidget* widget = (HbListWidget*)cWidget->mListView; |
447 int count = items.count(); |
582 int count = items.count(); |
448 if(count > 0) clearItems(bOwnItems); //Clear the existing items first |
583 if(count > 0) clearItems(bOwnItems); //Clear the existing items first |
449 for(int i = 0; i < count; i++){ |
584 for(int i = 0; i < count; i++){ |
450 widget->addItem(items[i]); |
585 widget->addItem(items[i]); |
451 } |
586 } |
452 widget->setCurrentRow(currentIndex); |
587 widget->setCurrentRow(currentIndex); |
453 |
588 |
454 } |
589 } |
455 bOwnItems = transferOwnership; |
590 bOwnItems = transferOwnership; |
|
591 cWidget->updateCounter(); |
456 } |
592 } |
457 } |
593 } |
458 |
594 |
459 QAbstractItemModel* HbSelectionDialogPrivate::model() const |
595 QAbstractItemModel* HbSelectionDialogPrivate::model() const |
460 { |
596 { |
461 Q_Q(const HbSelectionDialog); |
597 Q_Q(const HbSelectionDialog); |
462 |
598 |
463 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
599 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
464 if(cWidget && cWidget->mListView){ |
600 if(cWidget && cWidget->mListView){ |
465 return cWidget->mListView->model(); |
601 return cWidget->mListView->model(); |
466 } |
602 } |
467 return 0; |
603 return 0; |
468 } |
604 } |
469 |
605 |
470 QItemSelectionModel* HbSelectionDialogPrivate::selectionModel() const |
606 QItemSelectionModel* HbSelectionDialogPrivate::selectionModel() const |
482 { |
618 { |
483 Q_Q(const HbSelectionDialog); |
619 Q_Q(const HbSelectionDialog); |
484 QItemSelectionModel *model = 0; |
620 QItemSelectionModel *model = 0; |
485 model = selectionModel(); |
621 model = selectionModel(); |
486 if(model){ |
622 if(model){ |
487 model->clearSelection(); |
623 model->clearSelection(); |
|
624 _p_SelectionChanged(); |
488 Q_FOREACH(QVariant i,items) { |
625 Q_FOREACH(QVariant i,items) { |
489 model->select(model->model()->index(i.toInt(),0), |
626 model->select(model->model()->index(i.toInt(),0), |
490 QItemSelectionModel::Select); |
627 QItemSelectionModel::Select); |
491 } |
628 } |
492 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
629 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
493 if(cWidget){ |
630 if(cWidget){ |
494 cWidget->updateCounter(); |
631 cWidget->updateCounter(); |
495 } |
632 } |
496 } |
633 } |
497 } |
634 } |
498 |
635 |
499 QList<QVariant> HbSelectionDialogPrivate::selectedItems() const |
636 QList<QVariant> HbSelectionDialogPrivate::selectedItems() const |
500 { |
637 { |
501 QItemSelectionModel *model = 0; |
638 QItemSelectionModel *model = 0; |
502 QList<QVariant> selIndexes; |
639 QList<QVariant> selIndexes; |
503 model = selectionModel(); |
640 model = selectionModel(); |
504 if(model){ |
641 if(model){ |
505 QModelIndexList indexes = model->selectedIndexes(); |
642 if(mSelectionMode == HbAbstractItemView::NoSelection){ |
506 int count = indexes.count(); |
643 QModelIndex index = model->currentIndex(); |
507 QModelIndex index; |
|
508 for(int i = 0 ; i < count ; i++){ |
|
509 index = indexes[i]; |
|
510 selIndexes.append(QVariant(index.row())); |
644 selIndexes.append(QVariant(index.row())); |
511 } |
645 } |
|
646 else{ |
|
647 QModelIndexList indexes = model->selectedIndexes(); |
|
648 int count = indexes.count(); |
|
649 QModelIndex index; |
|
650 for(int i = 0 ; i < count ; i++){ |
|
651 index = indexes[i]; |
|
652 selIndexes.append(QVariant(index.row())); |
|
653 } |
|
654 } |
512 } |
655 } |
513 return selIndexes; |
656 return selIndexes; |
514 |
|
515 } |
657 } |
516 |
658 |
517 QModelIndexList HbSelectionDialogPrivate::selectedModelIndexes() const |
659 QModelIndexList HbSelectionDialogPrivate::selectedModelIndexes() const |
518 { |
660 { |
519 QItemSelectionModel *model = 0; |
661 QItemSelectionModel *model = 0; |
520 QModelIndexList selIndexes; |
662 QModelIndexList selIndexes; |
521 model = selectionModel(); |
663 model = selectionModel(); |
522 if(model){ |
664 if(model){ |
523 selIndexes = model->selectedIndexes(); |
665 if(mSelectionMode == HbAbstractItemView::NoSelection){ |
|
666 QModelIndex index = model->currentIndex(); |
|
667 selIndexes.append(index); |
|
668 } |
|
669 else{ |
|
670 selIndexes = model->selectedIndexes(); |
|
671 } |
524 } |
672 } |
525 return selIndexes; |
673 return selIndexes; |
526 } |
674 } |
527 |
675 |
528 void HbSelectionDialogPrivate::close() |
676 void HbSelectionDialogPrivate::close() |
529 { |
677 { |
530 Q_Q(HbSelectionDialog); |
678 Q_Q(HbSelectionDialog); |
531 q->accept(); //emit the signal |
679 q->accept(); //emit the signal |
532 } |
680 } |
533 |
681 |
|
682 QString HbSelectionDialogPrivate::selectionTitle() const |
|
683 { |
|
684 Q_Q(const HbSelectionDialog); |
|
685 QString str; |
|
686 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
|
687 if(cWidget){ |
|
688 str = cWidget->selectionTitle(); |
|
689 } |
|
690 return str; |
|
691 } |
|
692 |
|
693 void HbSelectionDialogPrivate::setSelectionTitle(const QString& title) |
|
694 { |
|
695 Q_Q(HbSelectionDialog); |
|
696 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
|
697 if(cWidget){ |
|
698 cWidget->setSelectionTitle(title); |
|
699 } |
|
700 } |