]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/preferences_widgets.hpp
Qt: hotkeys: add check for app's menu shortcuts (fix #7930)
[vlc] / modules / gui / qt4 / components / preferences_widgets.hpp
index 473548cbc498b08f955420b4c38fe5f8c91ee428..d6bff2884ed05c502c58b98602ec09331529fdbe 100644 (file)
@@ -52,6 +52,8 @@ class QGroupBox;
 class QGridLayout;
 class QDialogButtonBox;
 class QVBoxLayout;
+class QBoxLayout;
+class SearchLineEdit;
 
 /*******************************************************
  * Simple widgets
@@ -79,35 +81,31 @@ class ConfigControl : public QObject
 {
     Q_OBJECT
 public:
-    ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf,
-                   QWidget *p ) : p_this( _p_this ), p_item( _p_conf )
-    {
-        widget = NULL;
-    }
-    ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
-                            p_this (_p_this ), p_item( _p_conf )
-    {
-        widget = NULL;
-    }
     virtual int getType() const = 0;
     const char * getName() const { return  p_item->psz_name; }
-    QWidget *getWidget() const { return widget; }
     bool isAdvanced() const { return p_item->b_advanced; }
-    virtual void hide() { if ( widget ) widget->hide(); };
-    virtual void show() { if ( widget ) widget->show(); };
-
+    void hide() { changeVisibility( false ); }
+    void show() { changeVisibility( true ); }
+    /* ConfigControl factory */
     static ConfigControl * createControl( vlc_object_t*,
                                           module_config_t*,QWidget*,
                                           QGridLayout *, int line = 0 );
+    /* Inserts control into another layout block, using a sublayout */
+    void insertInto( QBoxLayout * );
+    /* Inserts control into an existing grid layout */
+    void insertIntoExistingGrid( QGridLayout*, int );
     virtual void doApply() = 0;
 protected:
+    ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
+                            p_this (_p_this ), p_item( _p_conf ) {}
+    virtual void changeVisibility( bool b ) { Q_UNUSED(b); };
     vlc_object_t *p_this;
     module_config_t *p_item;
-    QString _name;
-    QWidget *widget;
+    virtual void fillGrid( QGridLayout*, int ) {};
+signals:
+    void changed();
 #if 0
 /* You shouldn't use that now..*/
-signals:
     void Updated();
 #endif
 };
@@ -119,31 +117,30 @@ class VIntConfigControl : public ConfigControl
 {
 Q_OBJECT
 public:
-    VIntConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
-            ConfigControl(a,b,c) {};
-    VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
-                ConfigControl(a,b) {};
     virtual int getValue() const = 0;
     virtual int getType() const;
     virtual void doApply();
+protected:
+    VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
+                ConfigControl(a,b) {};
 };
 
 class IntegerConfigControl : public VIntConfigControl
 {
 Q_OBJECT
 public:
-    IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                          QGridLayout *, int );
+    IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget * );
     IntegerConfigControl( vlc_object_t *, module_config_t *,
                           QLabel*, QSpinBox* );
-    IntegerConfigControl( vlc_object_t *, module_config_t *,
-                          QLabel*, QSlider* );
     virtual int getValue() const;
-    virtual void show() { spin->show(); if( label ) label->show(); }
-    virtual void hide() { spin->hide(); if( label ) label->hide(); }
-
 protected:
     QSpinBox *spin;
+    virtual void changeVisibility( bool b )
+    {
+        spin->setVisible( b );
+        if ( label ) label->setVisible( b );
+    }
+    virtual void fillGrid( QGridLayout*, int );
 private:
     QLabel *label;
     void finish();
@@ -152,10 +149,11 @@ private:
 class IntegerRangeConfigControl : public IntegerConfigControl
 {
 public:
-    IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                               QGridLayout *, int );
+    IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget * );
     IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
                                QLabel*, QSpinBox* );
+    IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
+                               QLabel*, QSlider* );
 private:
     void finish();
 };
@@ -168,6 +166,11 @@ public:
     virtual int getValue() const;
 protected:
     QSlider *slider;
+    virtual void changeVisibility( bool b )
+    {
+        slider->setVisible( b );
+        if ( label ) label->setVisible( b );
+    }
 private:
     QLabel *label;
     void finish();
@@ -177,33 +180,38 @@ class IntegerListConfigControl : public VIntConfigControl
 {
 Q_OBJECT
 public:
-    IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                              bool, QGridLayout*, int );
+    IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool );
     IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
                               QComboBox*, bool );
     virtual int getValue() const;
-    virtual void hide() { combo->hide(); if( label ) label->hide(); }
-    virtual void show() { combo->show(); if( label ) label->show(); }
+protected:
+    virtual void changeVisibility( bool b )
+    {
+        combo->setVisible( b );
+        if ( label ) label->setVisible( b );
+    }
+    virtual void fillGrid( QGridLayout*, int );
 private:
     void finish(module_config_t * );
     QLabel *label;
     QComboBox *combo;
-private slots:
-    void actionRequested( int );
-
+    QList<QPushButton *> buttons;
 };
 
 class BoolConfigControl : public VIntConfigControl
 {
 public:
-    BoolConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                       QGridLayout *, int );
+    BoolConfigControl( vlc_object_t *, module_config_t *, QWidget * );
     BoolConfigControl( vlc_object_t *, module_config_t *,
                        QLabel *, QAbstractButton* );
     virtual int getValue() const;
-    virtual void show() { checkbox->show(); }
-    virtual void hide() { checkbox->hide(); }
     virtual int getType() const;
+protected:
+    virtual void changeVisibility( bool b )
+    {
+        checkbox->setVisible( b );
+    }
+    virtual void fillGrid( QGridLayout*, int );
 private:
     QAbstractButton *checkbox;
     void finish();
@@ -213,12 +221,18 @@ class ColorConfigControl : public VIntConfigControl
 {
 Q_OBJECT
 public:
-    ColorConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                        QGridLayout *, int );
+    ColorConfigControl( vlc_object_t *, module_config_t *, QWidget * );
     ColorConfigControl( vlc_object_t *, module_config_t *,
                         QLabel *, QAbstractButton* );
     virtual ~ColorConfigControl() { delete color_px; }
     virtual int getValue() const;
+protected:
+    virtual void changeVisibility( bool b )
+    {
+        color_but->setVisible( b );
+        if ( label ) label->setVisible( b );
+    }
+    virtual void fillGrid( QGridLayout*, int );
 private:
     QLabel *label;
     QAbstractButton *color_but;
@@ -236,28 +250,30 @@ class VFloatConfigControl : public ConfigControl
 {
     Q_OBJECT
 public:
-    VFloatConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
-                ConfigControl(a,b,c) {};
-    VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
-                ConfigControl(a,b) {};
     virtual float getValue() const = 0;
     virtual int getType() const;
     virtual void doApply();
+protected:
+    VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
+                ConfigControl(a,b) {};
 };
 
 class FloatConfigControl : public VFloatConfigControl
 {
     Q_OBJECT
 public:
-    FloatConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                        QGridLayout *, int );
+    FloatConfigControl( vlc_object_t *, module_config_t *, QWidget * );
     FloatConfigControl( vlc_object_t *, module_config_t *,
                         QLabel*, QDoubleSpinBox* );
     virtual float getValue() const;
-    virtual void show() { spin->show(); if( label ) label->show(); }
-    virtual void hide() { spin->hide(); if( label ) label->hide(); }
 
 protected:
+    virtual void changeVisibility( bool b )
+    {
+        spin->setVisible( b );
+        if ( label ) label->setVisible( b );
+    }
+    virtual void fillGrid( QGridLayout*, int );
     QDoubleSpinBox *spin;
 
 private:
@@ -269,8 +285,7 @@ class FloatRangeConfigControl : public FloatConfigControl
 {
     Q_OBJECT
 public:
-    FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                             QGridLayout *, int );
+    FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget * );
     FloatRangeConfigControl( vlc_object_t *, module_config_t *,
                              QLabel*, QDoubleSpinBox* );
 private:
@@ -284,26 +299,30 @@ class VStringConfigControl : public ConfigControl
 {
     Q_OBJECT
 public:
-    VStringConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
-                ConfigControl(a,b,c) {};
-    VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
-                ConfigControl(a,b) {};
     virtual QString getValue() const = 0;
     virtual int getType() const;
     virtual void doApply();
+protected:
+    VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
+                ConfigControl(a,b) {};
 };
 
 class StringConfigControl : public VStringConfigControl
 {
     Q_OBJECT
 public:
-    StringConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                         QGridLayout *, int,  bool pwd );
+    StringConfigControl( vlc_object_t *, module_config_t *,
+                         QWidget *, bool pwd );
     StringConfigControl( vlc_object_t *, module_config_t *, QLabel *,
                          QLineEdit*,  bool pwd );
     virtual QString getValue() const { return text->text(); };
-    virtual void show() { text->show(); if( label ) label->show(); }
-    virtual void hide() { text->hide(); if( label ) label->hide(); }
+protected:
+    virtual void changeVisibility( bool b )
+    {
+        text->setVisible( b );
+        if ( label ) label->setVisible( b );
+    }
+    virtual void fillGrid( QGridLayout*, int );
 private:
     void finish();
     QLineEdit *text;
@@ -314,16 +333,20 @@ class FileConfigControl : public VStringConfigControl
 {
     Q_OBJECT
 public:
-    FileConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                       QGridLayout *, int );
+    FileConfigControl( vlc_object_t *, module_config_t *, QWidget * );
     FileConfigControl( vlc_object_t *, module_config_t *, QLabel *,
                        QLineEdit *, QPushButton * );
     virtual QString getValue() const { return text->text(); };
-    virtual void show() { text->show(); if( label ) label->show(); browse->show(); }
-    virtual void hide() { text->hide(); if( label ) label->hide(); browse->hide(); }
 public slots:
     virtual void updateField();
 protected:
+    virtual void changeVisibility( bool b )
+    {
+        text->setVisible( b );
+        browse->setVisible( b );
+        if ( label ) label->setVisible( b );
+    }
+    virtual void fillGrid( QGridLayout*, int );
     void finish();
     QLineEdit *text;
     QLabel *label;
@@ -334,8 +357,7 @@ class DirectoryConfigControl : public FileConfigControl
 {
     Q_OBJECT
 public:
-    DirectoryConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                            QGridLayout *, int );
+    DirectoryConfigControl( vlc_object_t *, module_config_t *, QWidget * );
     DirectoryConfigControl( vlc_object_t *, module_config_t *, QLabel *,
                             QLineEdit *, QPushButton * );
 public slots:
@@ -346,12 +368,17 @@ class FontConfigControl : public VStringConfigControl
 {
     Q_OBJECT
 public:
-    FontConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                       QGridLayout *, int);
+    FontConfigControl( vlc_object_t *, module_config_t *, QWidget * );
     FontConfigControl( vlc_object_t *, module_config_t *, QLabel *,
                        QFontComboBox *);
     virtual QString getValue() const { return font->currentFont().family(); }
 protected:
+    virtual void changeVisibility( bool b )
+    {
+        font->setVisible( b );
+        if ( label ) label->setVisible( b );
+    }
+    virtual void fillGrid( QGridLayout*, int );
     QLabel *label;
     QFontComboBox *font;
 };
@@ -359,15 +386,19 @@ protected:
 class ModuleConfigControl : public VStringConfigControl
 {
 public:
-    ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
-                         QGridLayout*, int );
+    ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget * );
     ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
-                         QComboBox*, bool );
+                         QComboBox* );
     virtual QString getValue() const;
-    virtual void hide() { combo->hide(); if( label ) label->hide(); }
-    virtual void show() { combo->show(); if( label ) label->show(); }
+protected:
+    virtual void changeVisibility( bool b )
+    {
+        combo->setVisible( b );
+        if ( label ) label->setVisible( b );
+    }
+    virtual void fillGrid( QGridLayout*, int );
 private:
-    void finish( bool );
+    void finish( );
     QLabel *label;
     QComboBox *combo;
 };
@@ -382,16 +413,16 @@ class ModuleListConfigControl : public VStringConfigControl
     Q_OBJECT
     friend class ConfigControl;
 public:
-    ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                             bool, QGridLayout*, int );
+    ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool );
 //    ModuleListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
 //                         QComboBox*, bool );
     virtual ~ModuleListConfigControl();
     virtual QString getValue() const;
-    virtual void hide();
-    virtual void show();
 public slots:
     void onUpdate();
+protected:
+    virtual void changeVisibility( bool );
+    virtual void fillGrid( QGridLayout*, int );
 private:
     void finish( bool );
     void checkbox_lists(module_t*);
@@ -405,20 +436,24 @@ class StringListConfigControl : public VStringConfigControl
 {
     Q_OBJECT
 public:
-    StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
-                             QGridLayout*, int );
+    StringListConfigControl( vlc_object_t *, module_config_t *, QWidget * );
     StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
                              QComboBox*, bool );
     virtual QString getValue() const;
-    virtual void hide() { combo->hide(); if( label ) label->hide(); }
-    virtual void show() { combo->show(); if( label ) label->show(); }
+protected:
+    virtual void changeVisibility( bool b )
+    {
+        combo->setVisible( b );
+        if ( label ) label->setVisible( b );
+    }
+    virtual void fillGrid( QGridLayout*, int );
     QComboBox *combo;
 private:
     void finish(module_config_t * );
     QLabel *label;
+    QList<QPushButton *> buttons;
 private slots:
-    void actionRequested( int );
-
+    void comboIndexChanged( int );
 };
 
 void setfillVLCConfigCombo(const char *configname, intf_thread_t *p_intf,
@@ -451,20 +486,31 @@ private slot:
 class KeySelectorControl : public ConfigControl
 {
     Q_OBJECT
+
 public:
-    KeySelectorControl( vlc_object_t *, module_config_t *, QWidget *,
-                        QGridLayout*, int );
+    explicit KeySelectorControl( vlc_object_t *, module_config_t *, QWidget * );
     virtual int getType() const;
-    virtual void hide() { table->hide(); if( label ) label->hide(); }
-    virtual void show() { table->show(); if( label ) label->show(); }
     virtual void doApply();
+
 protected:
     virtual bool eventFilter( QObject *, QEvent * );
+    virtual void changeVisibility( bool b )
+    {
+        table->setVisible( b );
+        if ( label ) label->setVisible( b );
+    }
+    virtual void fillGrid( QGridLayout*, int );
+
 private:
+    void buildAppHotkeysList( QWidget *rootWidget );
     void finish();
     QLabel *label;
+    QLabel *searchLabel;
+    SearchLineEdit *actionSearch;
     QTreeWidget *table;
     QList<module_config_t *> values;
+    QSet<QString> existingkeys;
+
 private slots:
     void selectKey( QTreeWidgetItem * = NULL, int column = 1 );
     void filter( const QString & );
@@ -472,19 +518,26 @@ private slots:
 
 class KeyInputDialog : public QDialog
 {
+    Q_OBJECT
+
 public:
-    KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false);
+    explicit KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false );
     int keyValue;
     bool conflicts;
+    void setExistingkeysSet( const QSet<QString> *keyset = NULL );
 
 private:
     QTreeWidget *table;
     QLabel *selected, *warning;
-    QDialogButtonBox *buttonBox;
+    QPushButton *ok, *unset;
 
-    void checkForConflicts( int i_vlckey );
+    void checkForConflicts( int i_vlckey, const QString &sequence );
     void keyPressEvent( QKeyEvent *);
     void wheelEvent( QWheelEvent *);
     bool b_global;
+    const QSet<QString> *existingkeys;
+
+private slots:
+    void unsetAction();
 };
 #endif