[vlc-commits] Qt: extension dialog: update checkboxes if a check state was changed

Daniel Amm git at videolan.org
Tue Jun 23 22:06:17 CEST 2015


vlc/vlc-2.2 | branch: master | Daniel Amm <da2424 at t-online.de> | Mon Jun 15 18:19:46 2015 +0200| [28b18786a49fb73aab0e24967d75ef1311be30ba] | committer: Jean-Baptiste Kempf

Qt: extension dialog: update checkboxes if a check state was changed

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
(cherry picked from commit 1a2f7b20412973d6748bd3188130aba7b6d5e855)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=28b18786a49fb73aab0e24967d75ef1311be30ba
---

 modules/gui/qt4/components/simple_preferences.cpp |   43 +++++++++++++++++++++
 modules/gui/qt4/components/simple_preferences.hpp |    1 +
 2 files changed, 44 insertions(+)

diff --git a/modules/gui/qt4/components/simple_preferences.cpp b/modules/gui/qt4/components/simple_preferences.cpp
index a946b0d..f633668 100644
--- a/modules/gui/qt4/components/simple_preferences.cpp
+++ b/modules/gui/qt4/components/simple_preferences.cpp
@@ -1372,6 +1372,8 @@ void SPrefsPanel::assoDialog()
 #undef aTv
 #undef aTa
 
+    CONNECT( filetypeList, itemChanged(QTreeWidgetItem*, int), this, updateCheckBoxes(QTreeWidgetItem*, int) );
+
     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
@@ -1388,6 +1390,47 @@ void SPrefsPanel::assoDialog()
     listAsso.clear();
 }
 
+void SPrefsPanel::updateCheckBoxes(QTreeWidgetItem* item, int column)
+{
+    if( column != 0 )
+        return;
+
+    /* temporarily block signals to avoid signal loops */
+    bool b_signalsBlocked = item->treeWidget()->blockSignals(true);
+
+    /* A parent checkbox was changed */
+    if( item->parent() == 0 )
+    {
+        Qt::CheckState checkState = item->checkState(0);
+        for( int i = 0; i < item->childCount(); i++ )
+        {
+            item->child(i)->setCheckState(0, checkState);
+        }
+    }
+
+    /* A child checkbox was changed */
+    else
+    {
+        bool b_diff = false;
+        for( int i = 0; i < item->parent()->childCount(); i++ )
+        {
+            if( i != item->parent()->indexOfChild(item) && item->checkState(0) != item->parent()->child(i)->checkState(0) )
+            {
+                b_diff = true;
+                break;
+            }
+        }
+
+        if( b_diff )
+            item->parent()->setCheckState(0, Qt::PartiallyChecked);
+        else
+            item->parent()->setCheckState(0, item->checkState(0));
+    }
+
+    /* Stop signal blocking */
+    item->treeWidget()->blockSignals(b_signalsBlocked);
+}
+
 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
 {
     QString s_path( "VLC" ); s_path += psz_ext;
diff --git a/modules/gui/qt4/components/simple_preferences.hpp b/modules/gui/qt4/components/simple_preferences.hpp
index d6c05f3..8e2bf6e 100644
--- a/modules/gui/qt4/components/simple_preferences.hpp
+++ b/modules/gui/qt4/components/simple_preferences.hpp
@@ -126,6 +126,7 @@ private slots:
     void langChanged( int );
 #ifdef _WIN32
     void assoDialog();
+    void updateCheckBoxes( QTreeWidgetItem*, int );
     void saveAsso();
 #endif
     void configML();



More information about the vlc-commits mailing list