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 #include <hbstyletextprimitivedata.h> |
|
40 #include <hbstringutil.h> |
|
41 |
|
42 HbSelectionDialogMarkWidget::HbSelectionDialogMarkWidget(QGraphicsItem *parent):HbWidget(parent),mBackgroundItem(0),mLbCounter(0){ |
39 chkMark = new HbCheckBox(this); |
43 chkMark = new HbCheckBox(this); |
40 chkMark->setText(hbTrId("txt_common_list_mark_all_items")); |
|
41 lbCounter = new HbTextItem(this); |
|
42 HbStyle::setItemName(chkMark,"checkbox"); |
44 HbStyle::setItemName(chkMark,"checkbox"); |
43 HbStyle::setItemName(lbCounter,"counter"); |
|
44 createPrimitives(); |
45 createPrimitives(); |
45 } |
46 } |
46 |
47 |
47 void HbSelectionDialogMarkWidget::createPrimitives() |
48 void HbSelectionDialogMarkWidget::createPrimitives() |
48 { |
49 { |
49 if ( !mBackgroundItem ) { |
50 if (!mBackgroundItem ) { |
50 mBackgroundItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_TumbleView_background , this ); |
51 mBackgroundItem = style()->createPrimitive( HbStyle::PT_FrameItem ,"background",this ); |
51 HbStyle::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 HbStylePrivate::updatePrimitive( mBackgroundItem , HbStylePrivate::P_TumbleView_background , &option ); |
99 } |
62 } |
|
63 } |
100 } |
64 |
101 |
65 /*! |
102 /*! |
66 \reimp |
103 \reimp |
67 */ |
104 */ |
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){ |
151 if(model) |
180 if(model) |
152 QObject::connect(mListView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),this,SLOT(_q_selectionChanged(const QItemSelection&, const QItemSelection&))); |
181 QObject::connect(mListView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),this,SLOT(_q_selectionChanged(const QItemSelection&, const QItemSelection&))); |
153 } |
182 } |
154 } |
183 } |
155 } |
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 } |
|
198 } |
|
199 |
156 void HbSelectionDialogContentWidget::updateCounter() |
200 void HbSelectionDialogContentWidget::updateCounter() |
157 { |
201 { |
158 if(!mListView) return; |
202 if(!mListView) return; |
159 if(mListView->selectionMode()!= HbAbstractItemView::MultiSelection) return; |
203 if(mListView->selectionMode()!= HbAbstractItemView::MultiSelection) return; |
160 if(markWidget){ |
204 if(markWidget){ |
161 int totalItems = totalItemCount(); |
205 int totalItems = totalItemCount(); |
162 int selectedItems = selectedItemCount(); |
206 int selectedItems = selectedItemCount(); |
163 markWidget->updatePrimitives(); |
207 markWidget->updatePrimitives(); |
164 markWidget->lbCounter->setText(QString(QString::number(selectedItems) + "/" + QString::number(totalItems))); |
208 markWidget->updateCounter(QString(HbStringUtil::convertDigits(QString::number(selectedItems)) + "/" + HbStringUtil::convertDigits(QString::number(totalItems)))); |
165 //update checked state of "MarkAll" checkbox |
209 //update checked state of "MarkAll" checkbox |
166 if (totalItems > 0 && (selectedItems == totalItems)){ |
210 if (totalItems > 0 && (selectedItems == totalItems)){ |
167 markWidget->chkMark->blockSignals(true); //should not call _q_checkboxclicked() |
211 markWidget->chkMark->blockSignals(true); //should not call _q_checkboxclicked() |
168 markWidget->chkMark->setChecked(true); |
212 markWidget->chkMark->setChecked(true); |
169 markWidget->chkMark->blockSignals(false); |
213 markWidget->chkMark->blockSignals(false); |
234 void HbSelectionDialogContentWidget::_q_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) |
279 void HbSelectionDialogContentWidget::_q_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) |
235 { |
280 { |
236 Q_UNUSED(selected); |
281 Q_UNUSED(selected); |
237 Q_UNUSED(deselected); |
282 Q_UNUSED(deselected); |
238 updateCounter(); |
283 updateCounter(); |
239 } |
284 if(mListView->selectionMode()== HbAbstractItemView::MultiSelection) |
|
285 d->_p_SelectionChanged(); |
|
286 } |
|
287 |
|
288 void HbSelectionDialogContentWidget::_q_listItemSelected(QModelIndex index) |
|
289 { |
|
290 Q_UNUSED(index) |
|
291 if(mListView->selectionMode()== HbAbstractItemView::SingleSelection || mListView->selectionMode()== HbAbstractItemView::NoSelection){ |
|
292 d->close(); |
|
293 } |
|
294 updateCounter(); |
|
295 //d->_p_SelectionChanged(); |
|
296 } |
|
297 |
240 |
298 |
241 void HbSelectionDialogContentWidget::modelChanged(const QModelIndex &parent, int start,int end) |
299 void HbSelectionDialogContentWidget::modelChanged(const QModelIndex &parent, int start,int end) |
242 { |
300 { |
243 Q_UNUSED(parent); |
301 Q_UNUSED(parent); |
244 Q_UNUSED(start); |
302 Q_UNUSED(start); |
314 q->setTimeout(HbPopup::NoTimeout); |
374 q->setTimeout(HbPopup::NoTimeout); |
315 q->setModal(true); |
375 q->setModal(true); |
316 showActions(mSelectionMode); |
376 showActions(mSelectionMode); |
317 } |
377 } |
318 |
378 |
|
379 void HbSelectionDialogPrivate::_p_SelectionChanged() |
|
380 { |
|
381 Q_Q(HbSelectionDialog); |
|
382 if(mSelectionMode == HbAbstractItemView::MultiSelection) |
|
383 { |
|
384 emit q->selectionChanged(); |
|
385 } |
|
386 } |
|
387 |
319 void HbSelectionDialogPrivate::showActions(HbAbstractItemView::SelectionMode selectionMode) |
388 void HbSelectionDialogPrivate::showActions(HbAbstractItemView::SelectionMode selectionMode) |
320 { |
389 { |
321 Q_Q(HbSelectionDialog); |
390 Q_Q(HbSelectionDialog); |
322 if(selectionMode == HbAbstractItemView::SingleSelection){ |
391 if(selectionMode == HbAbstractItemView::SingleSelection || selectionMode == HbAbstractItemView::NoSelection){ |
323 |
392 |
324 if(action1) { |
393 if(action1) { |
325 q->disconnect(action1,SIGNAL(triggered()),q,SLOT(accept())); |
394 q->disconnect(action1,SIGNAL(triggered()),q,SLOT(accept())); |
326 q->removeAction(action1); |
395 q->removeAction(action1); |
327 action1 = 0; |
|
328 } |
396 } |
329 if(action2 == NULL){ |
397 if(action2 == NULL){ |
330 action2 =new HbAction(hbTrId("txt_common_button_cancel"),q); |
398 action2 =new HbAction(hbTrId("txt_common_button_cancel"),q); |
331 q->connect(action2,SIGNAL(triggered()),q,SLOT(reject())); |
399 q->connect(action2,SIGNAL(triggered()),q,SLOT(reject())); |
332 q->insertAction(0,action2); |
400 } |
|
401 if(q->actions().contains(action2) == false){ |
|
402 q->insertAction(0,action2); |
333 } |
403 } |
334 } |
404 } |
335 else{ |
405 else{ |
336 |
406 |
337 if(action2 == NULL){ |
407 if(action2 == NULL){ |
338 action2 =new HbAction(hbTrId("txt_common_button_cancel"),q); |
408 action2 =new HbAction(hbTrId("txt_common_button_cancel"),q); |
339 q->connect(action2,SIGNAL(triggered()),q,SLOT(reject())); |
409 q->connect(action2,SIGNAL(triggered()),q,SLOT(reject())); |
340 q->insertAction(0,action2); |
410 q->insertAction(0,action2); |
341 } |
411 } |
|
412 if(q->actions().contains(action2) == false) |
|
413 q->insertAction(0,action2); |
|
414 |
342 if(action1 == NULL){ |
415 if(action1 == NULL){ |
343 action1 =new HbAction(hbTrId("txt_common_button_ok"),q); |
416 action1 =new HbAction(hbTrId("txt_common_button_ok"),q); |
344 q->connect(action1,SIGNAL(triggered()),q,SLOT(accept())); |
417 q->connect(action1,SIGNAL(triggered()),q,SLOT(accept())); |
345 q->insertAction(action2,action1); |
|
346 } |
418 } |
347 } |
419 if(q->actions().contains(action1) == false) |
|
420 { |
|
421 q->insertAction(q->actions().first(),action1); |
|
422 } |
|
423 } |
|
424 |
348 } |
425 } |
349 |
426 |
350 void HbSelectionDialogPrivate::setSelectionMode(HbAbstractItemView::SelectionMode mode) |
427 void HbSelectionDialogPrivate::setSelectionMode(HbAbstractItemView::SelectionMode mode) |
351 { |
428 { |
352 Q_Q(HbSelectionDialog); |
429 Q_Q(HbSelectionDialog); |
353 |
430 |
354 mSelectionMode = mode; |
431 mSelectionMode = mode; |
355 switch(mSelectionMode) |
432 switch(mSelectionMode) |
356 { |
433 { |
|
434 case HbAbstractItemView::NoSelection: |
357 case HbAbstractItemView::SingleSelection: |
435 case HbAbstractItemView::SingleSelection: |
358 case HbAbstractItemView::MultiSelection: |
436 case HbAbstractItemView::MultiSelection: |
359 { |
437 { |
360 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
438 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
361 if(cWidget && cWidget->mListView){ |
439 if(cWidget && cWidget->mListView){ |
553 { |
631 { |
554 QItemSelectionModel *model = 0; |
632 QItemSelectionModel *model = 0; |
555 QList<QVariant> selIndexes; |
633 QList<QVariant> selIndexes; |
556 model = selectionModel(); |
634 model = selectionModel(); |
557 if(model){ |
635 if(model){ |
558 QModelIndexList indexes = model->selectedIndexes(); |
636 if(mSelectionMode == HbAbstractItemView::NoSelection){ |
559 int count = indexes.count(); |
637 QModelIndex index = model->currentIndex(); |
560 QModelIndex index; |
|
561 for(int i = 0 ; i < count ; i++){ |
|
562 index = indexes[i]; |
|
563 selIndexes.append(QVariant(index.row())); |
638 selIndexes.append(QVariant(index.row())); |
564 } |
639 } |
|
640 else{ |
|
641 QModelIndexList indexes = model->selectedIndexes(); |
|
642 int count = indexes.count(); |
|
643 QModelIndex index; |
|
644 for(int i = 0 ; i < count ; i++){ |
|
645 index = indexes[i]; |
|
646 selIndexes.append(QVariant(index.row())); |
|
647 } |
|
648 } |
565 } |
649 } |
566 return selIndexes; |
650 return selIndexes; |
567 |
|
568 } |
651 } |
569 |
652 |
570 QModelIndexList HbSelectionDialogPrivate::selectedModelIndexes() const |
653 QModelIndexList HbSelectionDialogPrivate::selectedModelIndexes() const |
571 { |
654 { |
572 QItemSelectionModel *model = 0; |
655 QItemSelectionModel *model = 0; |
573 QModelIndexList selIndexes; |
656 QModelIndexList selIndexes; |
574 model = selectionModel(); |
657 model = selectionModel(); |
575 if(model){ |
658 if(model){ |
576 selIndexes = model->selectedIndexes(); |
659 if(mSelectionMode == HbAbstractItemView::NoSelection){ |
|
660 QModelIndex index = model->currentIndex(); |
|
661 selIndexes.append(index); |
|
662 } |
|
663 else{ |
|
664 selIndexes = model->selectedIndexes(); |
|
665 } |
577 } |
666 } |
578 return selIndexes; |
667 return selIndexes; |
579 } |
668 } |
580 |
669 |
581 void HbSelectionDialogPrivate::close() |
670 void HbSelectionDialogPrivate::close() |
582 { |
671 { |
583 Q_Q(HbSelectionDialog); |
672 Q_Q(HbSelectionDialog); |
584 q->accept(); //emit the signal |
673 q->accept(); //emit the signal |
585 } |
674 } |
586 |
675 |
|
676 QString HbSelectionDialogPrivate::selectionTitle() const |
|
677 { |
|
678 Q_Q(const HbSelectionDialog); |
|
679 QString str; |
|
680 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
|
681 if(cWidget){ |
|
682 str = cWidget->selectionTitle(); |
|
683 } |
|
684 return str; |
|
685 } |
|
686 |
|
687 void HbSelectionDialogPrivate::setSelectionTitle(const QString& title) |
|
688 { |
|
689 Q_Q(HbSelectionDialog); |
|
690 HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget()); |
|
691 if(cWidget){ |
|
692 cWidget->setSelectionTitle(title); |
|
693 } |
|
694 } |