Qt: possibility of having a small Qt dialog for preferences on small screens like...
authorJean-Baptiste Kempf <jb@videolan.org>
Wed, 21 Jan 2009 21:11:39 +0000 (22:11 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Wed, 21 Jan 2009 21:11:39 +0000 (22:11 +0100)
modules/gui/qt4/components/simple_preferences.cpp
modules/gui/qt4/components/simple_preferences.hpp
modules/gui/qt4/dialogs/preferences.cpp
modules/gui/qt4/dialogs/preferences.hpp

index 2cfaf75..86b2740 100644 (file)
 #include <QToolButton>
 #include <QButtonGroup>
 #include <QVBoxLayout>
+#include <QScrollArea>
 
 #include <QtAlgorithms>
 
 #include <string>
 
 #define ICON_HEIGHT 64
-#define BUTTON_HEIGHT 74
 
 /*********************************************************************
  * The List of categories
  *********************************************************************/
-SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
+SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent, bool small ) :
                                   QWidget( _parent ), p_intf( _p_intf )
 {
     QVBoxLayout *layout = new QVBoxLayout();
@@ -59,13 +59,15 @@ SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
     CONNECT( buttonGroup, buttonClicked ( int ),
             this, switchPanel( int ) );
 
+    short icon_height = small ? ICON_HEIGHT /2 : ICON_HEIGHT;
+
 #define ADD_CATEGORY( button, label, icon, numb )                           \
     QToolButton * button = new QToolButton( this );                         \
     button->setIcon( QIcon( ":/pixmaps/prefs/" #icon ) );                   \
-    button->setIconSize( QSize( ICON_HEIGHT , ICON_HEIGHT ) );              \
     button->setText( label );                                               \
     button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              \
-    button->resize( BUTTON_HEIGHT , BUTTON_HEIGHT);                         \
+    button->setIconSize( QSize( icon_height, icon_height ) );               \
+    button->resize( icon_height + 6 , icon_height + 6 );                    \
     button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ;  \
     button->setAutoRaise( true );                                           \
     button->setCheckable( true );                                           \
@@ -100,7 +102,7 @@ void SPrefsCatList::switchPanel( int i )
  * The Panels
  *********************************************************************/
 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
-                          int _number ) : QWidget( _parent ), p_intf( _p_intf )
+                          int _number, bool small ) : QWidget( _parent ), p_intf( _p_intf )
 {
     module_config_t *p_config;
     ConfigControl *control;
@@ -556,8 +558,20 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
 
     panel_layout->addWidget( panel_label );
     panel_layout->addWidget( title_line );
-    panel_layout->addWidget( panel );
-    if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
+
+    if( small )
+    {
+        QScrollArea *scroller= new QScrollArea;
+        scroller->setWidget( panel );
+        scroller->setWidgetResizable( true );
+        scroller->setFrameStyle( QFrame::NoFrame );
+        panel_layout->addWidget( scroller );
+    }
+    else
+    {
+        panel_layout->addWidget( panel );
+        if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
+    }
 
     setLayout( panel_layout );
 }
index 1959e9c..754d8ad 100644 (file)
@@ -94,7 +94,7 @@ class SPrefsCatList : public QWidget
 {
     Q_OBJECT;
 public:
-    SPrefsCatList( intf_thread_t *, QWidget *);
+    SPrefsCatList( intf_thread_t *, QWidget *, bool );
     virtual ~SPrefsCatList() {};
 private:
     intf_thread_t *p_intf;
@@ -108,7 +108,7 @@ class SPrefsPanel : public QWidget
 {
     Q_OBJECT
 public:
-    SPrefsPanel( intf_thread_t *, QWidget *, int );
+    SPrefsPanel( intf_thread_t *, QWidget *, int, bool );
     virtual ~SPrefsPanel();
     void apply();
     void clean();
index 3853337..88268ed 100644 (file)
@@ -98,7 +98,7 @@ PrefsDialog::PrefsDialog( QWidget *parent, intf_thread_t *_p_intf )
     main_layout->setColumnMinimumWidth( 1, 10 );
     main_layout->setColumnStretch( 0, 1 );
     main_layout->setColumnStretch( 1, 0 );
-    main_layout->setColumnStretch( 2, 3 );
+    main_layout->setColumnStretch( 2, 10 );
 
     main_layout->setRowStretch( 2, 4 );
 
@@ -109,6 +109,9 @@ PrefsDialog::PrefsDialog( QWidget *parent, intf_thread_t *_p_intf )
     tree_panel_l->setMargin( 1 );
     main_panel_l->setLayoutMargins( 6, 0, 0, 3, 3 );
 
+    b_small = (p_intf->p_sys->i_screenHeight < 750);
+    if( b_small ) msg_Dbg( p_intf, "Small");
+    setMaximumHeight( p_intf->p_sys->i_screenHeight );
     for( int i = 0; i < SPrefsMax ; i++ ) simple_panels[i] = NULL;
 
     if( config_GetInt( p_intf, "qt-advanced-pref" ) == 1 )
@@ -123,7 +126,7 @@ PrefsDialog::PrefsDialog( QWidget *parent, intf_thread_t *_p_intf )
     BUTTONACT( small, setSmall() );
     BUTTONACT( all, setAdvanced() );
 
-    resize( 750, sizeHint().height() );
+    resize( 780, sizeHint().height() );
 }
 
 void PrefsDialog::setAdvanced()
@@ -176,7 +179,7 @@ void PrefsDialog::setSmall()
     /* If no simple_tree, create one, connect it */
     if( !simple_tree )
     {
-         simple_tree = new SPrefsCatList( p_intf, tree_panel );
+         simple_tree = new SPrefsCatList( p_intf, tree_panel, b_small );
          CONNECT( simple_tree,
                   currentItemChanged( int ),
                   this,  changeSimplePanel( int ) );
@@ -193,7 +196,7 @@ void PrefsDialog::setSmall()
     if( !current_simple_panel )
     {
         current_simple_panel =
-            new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
+            new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat, b_small );
         simple_panels[SPrefsDefaultCat] =  current_simple_panel;
         main_panel_l->addWidget( current_simple_panel );
     }
@@ -211,7 +214,7 @@ void PrefsDialog::changeSimplePanel( int number )
     current_simple_panel = simple_panels[number];
     if( !current_simple_panel )
     {
-        current_simple_panel  = new SPrefsPanel( p_intf, main_panel, number );
+        current_simple_panel  = new SPrefsPanel( p_intf, main_panel, number, b_small );
         simple_panels[number] = current_simple_panel;
         main_panel_l->addWidget( current_simple_panel );
     }
index b451851..bbddfaa 100644 (file)
@@ -81,6 +81,8 @@ private:
 
     static PrefsDialog *instance;
 
+    bool b_small;
+
 private slots:
     void setAdvanced();
     void setSmall();