src/hbwidgets/popups/hbselectiondialog_p.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
--- a/src/hbwidgets/popups/hbselectiondialog_p.cpp	Tue Jul 06 14:36:53 2010 +0300
+++ b/src/hbwidgets/popups/hbselectiondialog_p.cpp	Wed Aug 18 10:05:37 2010 +0300
@@ -37,7 +37,7 @@
 
 HbSelectionDialogMarkWidget::HbSelectionDialogMarkWidget(QGraphicsItem *parent):HbWidget(parent),mBackgroundItem(0){
 	chkMark = new HbCheckBox(this);
-	chkMark->setText("Mark All");
+	chkMark->setText(hbTrId("txt_common_list_mark_all_items"));
 	lbCounter = new HbTextItem(this);
 	HbStyle::setItemName(chkMark,"checkbox");
 	HbStyle::setItemName(lbCounter,"counter");
@@ -47,8 +47,8 @@
 void HbSelectionDialogMarkWidget::createPrimitives()
 {
     if ( !mBackgroundItem ) {
-        mBackgroundItem = style( )->createPrimitive( HbStyle::P_TumbleView_background , this );
-        style()->setItemName( mBackgroundItem , "background" );
+        mBackgroundItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_TumbleView_background , this );
+        HbStyle::setItemName( mBackgroundItem , "background" );
     }
 }
 
@@ -58,7 +58,7 @@
     initStyleOption( &option );
    
     if ( mBackgroundItem ) {
-            style( )->updatePrimitive( mBackgroundItem , HbStyle::P_TumbleView_background , &option );
+            HbStylePrivate::updatePrimitive( mBackgroundItem , HbStylePrivate::P_TumbleView_background , &option );
     }       
 }
 
@@ -89,7 +89,7 @@
 QGraphicsItem* HbSelectionDialogMarkWidget::primitive(HbStyle::Primitive primitive) const
 {
     switch (primitive) {
-        case HbStyle::P_TumbleView_background:
+        case HbStylePrivate::P_TumbleView_background:
             return mBackgroundItem;
         default:
             return 0;
@@ -197,6 +197,7 @@
 			HbStyle::setItemName(markWidget,"markwidget");
 			setProperty("multiSelection",true);
             connect(markWidget->chkMark,SIGNAL(stateChanged ( int )),this,SLOT(_q_checkboxclicked(int)));
+			repolish();
             updateCounter();
 		}
     }
@@ -204,12 +205,23 @@
 		delete markWidget; markWidget = 0;
 		HbStyle::setItemName(markWidget,"");
 		setProperty("multiSelection",false);
+		repolish();
     }
 }
 
 void HbSelectionDialogContentWidget::connectSlots()
 {
     QObject::connect(mListView,SIGNAL(activated(const QModelIndex&)),this,SLOT(_q_listItemSelected(QModelIndex)));
+    QObject::connect(mListView->model(),SIGNAL(rowsRemoved(const QModelIndex& ,int,int)),this,SLOT(modelChanged(const QModelIndex&,int,int)));
+    QObject::connect(mListView->model(),SIGNAL(rowsInserted(const QModelIndex& ,int,int)),this,SLOT(modelChanged(const QModelIndex&,int,int)));
+}
+
+void HbSelectionDialogContentWidget::modelChanged(const QModelIndex &parent, int start,int end)
+{
+	Q_UNUSED(parent);
+	Q_UNUSED(start);
+	Q_UNUSED(end);
+	updateCounter();
 }
 
 void HbSelectionDialogContentWidget::createListWidget()
@@ -278,22 +290,33 @@
 
 void HbSelectionDialogPrivate::showActions(HbAbstractItemView::SelectionMode selectionMode)
 {
-	Q_Q(HbSelectionDialog);
-	if(selectionMode == HbAbstractItemView::SingleSelection){
-		delete action1;action1=0;delete action2;action2=0;
-		action1=new HbAction(hbTrId("txt_common_button_cancel"),q);
-		q->addAction(action1);
-		q->connect(action1,SIGNAL(triggered()),q,SLOT(reject()));
-	}
-	else{
-		delete action1;action1=0;delete action2;action2=0;
-		action1=new HbAction(hbTrId("txt_common_button_ok"),q);
-		q->addAction(action1);
-		q->connect(action1,SIGNAL(triggered()),q,SLOT(accept()));
-		action2=new HbAction(hbTrId("txt_common_button_cancel"),q);
-		q->addAction(action2);
-		q->connect(action2,SIGNAL(triggered()),q,SLOT(reject()));
-	}
+    Q_Q(HbSelectionDialog);
+    if(selectionMode == HbAbstractItemView::SingleSelection){
+
+        if(action1) {
+            q->disconnect(action1,SIGNAL(triggered()),q,SLOT(accept()));
+            q->removeAction(action1);
+            action1 = 0;
+        }
+        if(action2 == NULL){
+        action2 =new HbAction(hbTrId("txt_common_button_cancel"),q);
+        q->connect(action2,SIGNAL(triggered()),q,SLOT(reject()));
+        q->insertAction(0,action2);
+        }
+    }
+    else{
+
+        if(action2 == NULL){
+            action2 =new HbAction(hbTrId("txt_common_button_cancel"),q);
+            q->connect(action2,SIGNAL(triggered()),q,SLOT(reject()));
+            q->insertAction(0,action2);
+        }    
+        if(action1 == NULL){
+            action1 =new HbAction(hbTrId("txt_common_button_ok"),q);
+            q->connect(action1,SIGNAL(triggered()),q,SLOT(accept()));
+            q->insertAction(action2,action1);
+        }    
+    }
 }
 
 void HbSelectionDialogPrivate::setSelectionMode(HbAbstractItemView::SelectionMode mode)
@@ -431,6 +454,8 @@
 		cWidget->createListView();
 		setSelectionMode(mSelectionMode);
         cWidget->mListView->setModel(model); 
+		cWidget->updateCounter();
+		cWidget->connectSlots();
     }
 }
 
@@ -453,6 +478,7 @@
             
         }
         bOwnItems = transferOwnership;
+		cWidget->updateCounter();
     }
 }