src/hbwidgets/popups/hbselectiondialog_p.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
    35 #include <hbaction.h>
    35 #include <hbaction.h>
    36 #include <hbstyleoption_p.h>
    36 #include <hbstyleoption_p.h>
    37 
    37 
    38 HbSelectionDialogMarkWidget::HbSelectionDialogMarkWidget(QGraphicsItem *parent):HbWidget(parent),mBackgroundItem(0){
    38 HbSelectionDialogMarkWidget::HbSelectionDialogMarkWidget(QGraphicsItem *parent):HbWidget(parent),mBackgroundItem(0){
    39 	chkMark = new HbCheckBox(this);
    39 	chkMark = new HbCheckBox(this);
    40 	chkMark->setText("Mark All");
    40 	chkMark->setText(hbTrId("txt_common_list_mark_all_items"));
    41 	lbCounter = new HbTextItem(this);
    41 	lbCounter = new HbTextItem(this);
    42 	HbStyle::setItemName(chkMark,"checkbox");
    42 	HbStyle::setItemName(chkMark,"checkbox");
    43 	HbStyle::setItemName(lbCounter,"counter");
    43 	HbStyle::setItemName(lbCounter,"counter");
    44 	createPrimitives();
    44 	createPrimitives();
    45 }
    45 }
    46 
    46 
    47 void HbSelectionDialogMarkWidget::createPrimitives()
    47 void HbSelectionDialogMarkWidget::createPrimitives()
    48 {
    48 {
    49     if ( !mBackgroundItem ) {
    49     if ( !mBackgroundItem ) {
    50         mBackgroundItem = style( )->createPrimitive( HbStyle::P_TumbleView_background , this );
    50         mBackgroundItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_TumbleView_background , this );
    51         style()->setItemName( mBackgroundItem , "background" );
    51         HbStyle::setItemName( mBackgroundItem , "background" );
    52     }
    52     }
    53 }
    53 }
    54 
    54 
    55 void HbSelectionDialogMarkWidget::updatePrimitives()
    55 void HbSelectionDialogMarkWidget::updatePrimitives()
    56 {
    56 {
    57     HbStyleOption option;
    57     HbStyleOption option;
    58     initStyleOption( &option );
    58     initStyleOption( &option );
    59    
    59    
    60     if ( mBackgroundItem ) {
    60     if ( mBackgroundItem ) {
    61             style( )->updatePrimitive( mBackgroundItem , HbStyle::P_TumbleView_background , &option );
    61             HbStylePrivate::updatePrimitive( mBackgroundItem , HbStylePrivate::P_TumbleView_background , &option );
    62     }       
    62     }       
    63 }
    63 }
    64 
    64 
    65 /*!
    65 /*!
    66     \reimp
    66     \reimp
    87     Will return NULL if \a primitive passed is invalid
    87     Will return NULL if \a primitive passed is invalid
    88 */
    88 */
    89 QGraphicsItem* HbSelectionDialogMarkWidget::primitive(HbStyle::Primitive primitive) const
    89 QGraphicsItem* HbSelectionDialogMarkWidget::primitive(HbStyle::Primitive primitive) const
    90 {
    90 {
    91     switch (primitive) {
    91     switch (primitive) {
    92         case HbStyle::P_TumbleView_background:
    92         case HbStylePrivate::P_TumbleView_background:
    93             return mBackgroundItem;
    93             return mBackgroundItem;
    94         default:
    94         default:
    95             return 0;
    95             return 0;
    96     }
    96     }
    97 }
    97 }
   195 		if(!markWidget){
   195 		if(!markWidget){
   196 			markWidget = new HbSelectionDialogMarkWidget(this);
   196 			markWidget = new HbSelectionDialogMarkWidget(this);
   197 			HbStyle::setItemName(markWidget,"markwidget");
   197 			HbStyle::setItemName(markWidget,"markwidget");
   198 			setProperty("multiSelection",true);
   198 			setProperty("multiSelection",true);
   199             connect(markWidget->chkMark,SIGNAL(stateChanged ( int )),this,SLOT(_q_checkboxclicked(int)));
   199             connect(markWidget->chkMark,SIGNAL(stateChanged ( int )),this,SLOT(_q_checkboxclicked(int)));
       
   200 			repolish();
   200             updateCounter();
   201             updateCounter();
   201 		}
   202 		}
   202     }
   203     }
   203     else{
   204     else{
   204 		delete markWidget; markWidget = 0;
   205 		delete markWidget; markWidget = 0;
   205 		HbStyle::setItemName(markWidget,"");
   206 		HbStyle::setItemName(markWidget,"");
   206 		setProperty("multiSelection",false);
   207 		setProperty("multiSelection",false);
       
   208 		repolish();
   207     }
   209     }
   208 }
   210 }
   209 
   211 
   210 void HbSelectionDialogContentWidget::connectSlots()
   212 void HbSelectionDialogContentWidget::connectSlots()
   211 {
   213 {
   212     QObject::connect(mListView,SIGNAL(activated(const QModelIndex&)),this,SLOT(_q_listItemSelected(QModelIndex)));
   214     QObject::connect(mListView,SIGNAL(activated(const QModelIndex&)),this,SLOT(_q_listItemSelected(QModelIndex)));
       
   215     QObject::connect(mListView->model(),SIGNAL(rowsRemoved(const QModelIndex& ,int,int)),this,SLOT(modelChanged(const QModelIndex&,int,int)));
       
   216     QObject::connect(mListView->model(),SIGNAL(rowsInserted(const QModelIndex& ,int,int)),this,SLOT(modelChanged(const QModelIndex&,int,int)));
       
   217 }
       
   218 
       
   219 void HbSelectionDialogContentWidget::modelChanged(const QModelIndex &parent, int start,int end)
       
   220 {
       
   221 	Q_UNUSED(parent);
       
   222 	Q_UNUSED(start);
       
   223 	Q_UNUSED(end);
       
   224 	updateCounter();
   213 }
   225 }
   214 
   226 
   215 void HbSelectionDialogContentWidget::createListWidget()
   227 void HbSelectionDialogContentWidget::createListWidget()
   216 {
   228 {
   217 	if(mListView){
   229 	if(mListView){
   276 	showActions(mSelectionMode);
   288 	showActions(mSelectionMode);
   277 }
   289 }
   278 
   290 
   279 void HbSelectionDialogPrivate::showActions(HbAbstractItemView::SelectionMode selectionMode)
   291 void HbSelectionDialogPrivate::showActions(HbAbstractItemView::SelectionMode selectionMode)
   280 {
   292 {
   281 	Q_Q(HbSelectionDialog);
   293     Q_Q(HbSelectionDialog);
   282 	if(selectionMode == HbAbstractItemView::SingleSelection){
   294     if(selectionMode == HbAbstractItemView::SingleSelection){
   283 		delete action1;action1=0;delete action2;action2=0;
   295 
   284 		action1=new HbAction(hbTrId("txt_common_button_cancel"),q);
   296         if(action1) {
   285 		q->addAction(action1);
   297             q->disconnect(action1,SIGNAL(triggered()),q,SLOT(accept()));
   286 		q->connect(action1,SIGNAL(triggered()),q,SLOT(reject()));
   298             q->removeAction(action1);
   287 	}
   299             action1 = 0;
   288 	else{
   300         }
   289 		delete action1;action1=0;delete action2;action2=0;
   301         if(action2 == NULL){
   290 		action1=new HbAction(hbTrId("txt_common_button_ok"),q);
   302         action2 =new HbAction(hbTrId("txt_common_button_cancel"),q);
   291 		q->addAction(action1);
   303         q->connect(action2,SIGNAL(triggered()),q,SLOT(reject()));
   292 		q->connect(action1,SIGNAL(triggered()),q,SLOT(accept()));
   304         q->insertAction(0,action2);
   293 		action2=new HbAction(hbTrId("txt_common_button_cancel"),q);
   305         }
   294 		q->addAction(action2);
   306     }
   295 		q->connect(action2,SIGNAL(triggered()),q,SLOT(reject()));
   307     else{
   296 	}
   308 
       
   309         if(action2 == NULL){
       
   310             action2 =new HbAction(hbTrId("txt_common_button_cancel"),q);
       
   311             q->connect(action2,SIGNAL(triggered()),q,SLOT(reject()));
       
   312             q->insertAction(0,action2);
       
   313         }    
       
   314         if(action1 == NULL){
       
   315             action1 =new HbAction(hbTrId("txt_common_button_ok"),q);
       
   316             q->connect(action1,SIGNAL(triggered()),q,SLOT(accept()));
       
   317             q->insertAction(action2,action1);
       
   318         }    
       
   319     }
   297 }
   320 }
   298 
   321 
   299 void HbSelectionDialogPrivate::setSelectionMode(HbAbstractItemView::SelectionMode mode)
   322 void HbSelectionDialogPrivate::setSelectionMode(HbAbstractItemView::SelectionMode mode)
   300 {
   323 {
   301     Q_Q(HbSelectionDialog);
   324     Q_Q(HbSelectionDialog);
   429     HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget());
   452     HbSelectionDialogContentWidget* cWidget = qobject_cast<HbSelectionDialogContentWidget*>(q->contentWidget());
   430     if(cWidget){
   453     if(cWidget){
   431 		cWidget->createListView();
   454 		cWidget->createListView();
   432 		setSelectionMode(mSelectionMode);
   455 		setSelectionMode(mSelectionMode);
   433         cWidget->mListView->setModel(model); 
   456         cWidget->mListView->setModel(model); 
       
   457 		cWidget->updateCounter();
       
   458 		cWidget->connectSlots();
   434     }
   459     }
   435 }
   460 }
   436 
   461 
   437 void HbSelectionDialogPrivate::setWidgetItems(const QList<HbListWidgetItem*> &items,bool transferOwnership,int currentIndex)
   462 void HbSelectionDialogPrivate::setWidgetItems(const QList<HbListWidgetItem*> &items,bool transferOwnership,int currentIndex)
   438 {
   463 {
   451             }
   476             }
   452             widget->setCurrentRow(currentIndex);
   477             widget->setCurrentRow(currentIndex);
   453             
   478             
   454         }
   479         }
   455         bOwnItems = transferOwnership;
   480         bOwnItems = transferOwnership;
       
   481 		cWidget->updateCounter();
   456     }
   482     }
   457 }
   483 }
   458 
   484 
   459 QAbstractItemModel* HbSelectionDialogPrivate::model() const
   485 QAbstractItemModel* HbSelectionDialogPrivate::model() const
   460 {
   486 {