]> git.sesse.net Git - vlc/commitdiff
Qt4 - Open: - remove a few kludges, clean and do it a better way.
authorJean-Baptiste Kempf <jb@videolan.org>
Tue, 16 Oct 2007 17:19:27 +0000 (17:19 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Tue, 16 Oct 2007 17:19:27 +0000 (17:19 +0000)
            - Use a QDirModel to provide completion, this is cool for geeks, but may increase the size of the object, since we didn't use that class before... Any thoughts on that? Remove it for Windows ?
            - Clean the layouts, and simplify and fix some signals.
            - layout fixes for capture.

modules/gui/qt4/components/open.cpp
modules/gui/qt4/components/open.hpp
modules/gui/qt4/ui/open_capture.ui
modules/gui/qt4/ui/open_file.ui

index 0a20d3b3c64c5794a3b4bbed78f8a1c17512a0d9..b05453c394015f4798a90f62cd2abc90c5b907ce 100644 (file)
@@ -38,6 +38,7 @@
 #include <QStackedLayout>
 #include <QListView>
 #include <QCompleter>
+#include <QDirModel>
 
 /**************************************************************************
  * Open Files and subtitles                                               *
@@ -48,6 +49,7 @@ FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     /* Classic UI Setup */
     ui.setupUi( this );
 
+    /** BEGIN QFileDialog tweaking **/
     /* Use a QFileDialog and customize it because we don't want to
        rewrite it all. Be careful to your eyes cause there are a few hacks.
        Be very careful and test correctly when you modify this. */
@@ -61,60 +63,60 @@ FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     ADD_FILTER_ALL( fileTypes );
     fileTypes.replace( QString(";*"), QString(" *"));
 
+    /* retrieve last known path used in file browsing */
+    char *psz_filepath = config_GetPsz( p_intf, "qt-filedialog-path" );
+    if( EMPTY_STR( psz_filepath ) )
+    {
+        psz_filepath = p_intf->p_libvlc->psz_homedir;
+    }
     // Make this QFileDialog a child of tempWidget from the ui.
     dialogBox = new FileOpenBox( ui.tempWidget, NULL,
-            qfu( p_intf->p_libvlc->psz_homedir ), fileTypes );
+            qfu( psz_filepath ), fileTypes );
+    delete psz_filepath;
 
     dialogBox->setFileMode( QFileDialog::ExistingFiles );
     dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
 
-    /* retrieve last known path used in file browsing */
-    char *psz_filepath = config_GetPsz( p_intf, "qt-filedialog-path" );
-    if( psz_filepath )
-    {
-        dialogBox->setDirectory( qfu( psz_filepath ) );
-        delete psz_filepath;
-    }
-
     /* We don't want to see a grip in the middle of the window, do we? */
     dialogBox->setSizeGripEnabled( false );
 
     /* Add a tooltip */
     dialogBox->setToolTip( qtr( "Select one or multiple files, or a folder" ) );
 
-    // Add it to the layout
-    ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
-
     // But hide the two OK/Cancel buttons. Enable them for debug.
     QDialogButtonBox *fileDialogAcceptBox =
-                                        findChildren<QDialogButtonBox*>()[0];
+                      dialogBox->findChildren<QDialogButtonBox*>()[0];
     fileDialogAcceptBox->hide();
 
     /* Ugly hacks to get the good Widget */
     //This lineEdit is the normal line in the fileDialog.
 #if HAS_QT43
-    lineFileEdit = findChildren<QLineEdit*>()[2];
+    lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
 #else
-    lineFileEdit = findChildren<QLineEdit*>()[3];
+    // FIXME
+    lineFileEdit = dialogBox->findChildren<QLineEdit*>()[1];
 #endif
 
-    QStringList fileCompleteList ;
-    QCompleter *fileCompleter = new QCompleter( fileCompleteList, this );
-
-    lineFileEdit->setCompleter( fileCompleter );
-
-//    lineFileEdit->hide();
-
     /* Make a list of QLabel inside the QFileDialog to access the good ones */
-    QList<QLabel *> listLabel = findChildren<QLabel*>();
+    QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
 
     /* Hide the FileNames one. Enable it for debug */
-    listLabel[4]->hide();
+    listLabel[1]->setText( qtr( "File names:" ) );
     /* Change the text that was uncool in the usual box */
-    listLabel[5]->setText( qtr( "Filter:" ) );
+    listLabel[2]->setText( qtr( "Filter:" ) );
 
+    dialogBox->layout()->setMargin( 0 );
+    dialogBox->layout()->setSizeConstraint( QLayout::SetMinimumSize );
 
-    QListView *fileListView = findChildren<QListView*>().first();
+    /** END of QFileDialog tweaking **/
+
+    // Add the DialogBox to the layout
+    ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
+
+    //TODO later: fill the fileCompleteList with previous items played.
+    QCompleter *fileCompleter = new QCompleter( fileCompleteList, this );
+    fileCompleter->setModel( new QDirModel( fileCompleter ) );
+    lineFileEdit->setCompleter( fileCompleter );
 
     // Hide the subtitles control by default.
     ui.subFrame->hide();
@@ -130,18 +132,13 @@ FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     BUTTONACT( ui.subBrowseButton, browseFileSub() );
     BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
 
-#if QT43
-    CONNECT( fileListView, clicked( QModelIndex ), this, updateMRL() );
-#else
-    CONNECT( ui.fileInput, editTextChanged( QString ), this, updateMRL() );
-#endif
-    CONNECT( ui.subInput, editTextChanged( QString ), this, updateMRL() );
+    CONNECT( lineFileEdit, textChanged( QString ), this, updateMRL() );
+
+    CONNECT( ui.subInput, textChanged( QString ), this, updateMRL() );
     CONNECT( ui.alignSubComboBox, currentIndexChanged( int ), this,
                                                             updateMRL() );
     CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this,
                                                             updateMRL() );
-
-    CONNECT( lineFileEdit, textChanged( QString ), this, browseFile() );
 }
 
 FileOpenPanel::~FileOpenPanel()
@@ -152,15 +149,6 @@ QStringList FileOpenPanel::browse( QString help )
     return THEDP->showSimpleOpen( help );
 }
 
-void FileOpenPanel::browseFile()
-{
-    QString fileString = "";
-    foreach( QString file, dialogBox->selectedFiles() ) {
-         fileString += "\"" + file + "\" ";
-    }
-    ui.fileInput->setEditText( fileString );
-    updateMRL();
-}
 
 void FileOpenPanel::browseFileSub()
 {
@@ -169,17 +157,19 @@ void FileOpenPanel::browseFileSub()
                             EXT_FILTER_SUBTITLE,
                             dialogBox->directory().absolutePath() );
     if( files.isEmpty() ) return;
-    ui.subInput->setEditText( files.join(" ") );
+    ui.subInput->setText( files.join(" ") );
     updateMRL();
 }
 
 void FileOpenPanel::updateMRL()
 {
-    msg_Dbg( p_intf, "I was here" );
-    QString mrl = ui.fileInput->currentText();
+    QString mrl = "";
+    foreach( QString file, dialogBox->selectedFiles() ) {
+         mrl += "\"" + file + "\" ";
+    }
 
     if( ui.subCheckBox->isChecked() ) {
-        mrl.append( " :sub-file=" + ui.subInput->currentText() );
+        mrl.append( " :sub-file=" + ui.subInput->text() );
         int align = ui.alignSubComboBox->itemData(
                     ui.alignSubComboBox->currentIndex() ).toInt();
         mrl.append( " :subsdec-align=" + QString().setNum( align ) );
@@ -206,8 +196,7 @@ void FileOpenPanel::updateMRL()
 /* Function called by Open Dialog when clicke on Play/Enqueue */
 void FileOpenPanel::accept()
 {
-    ui.fileInput->addItem( ui.fileInput->currentText());
-    if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem( 0 );
+    //FIXME set the completer
 }
 
 void FileOpenBox::accept()
@@ -218,22 +207,13 @@ void FileOpenBox::accept()
 /* Function called by Open Dialog when clicked on cancel */
 void FileOpenPanel::clear()
 {
-    ui.fileInput->setEditText( "" );
-    ui.subInput->setEditText( "" );
+    lineFileEdit->clear();
+    ui.subInput->clear();
 }
 
 void FileOpenPanel::toggleSubtitleFrame()
 {
-    if ( ui.subFrame->isVisible() )
-    {
-        ui.subFrame->hide();
-        updateGeometry();
-    /* FiXME Size */
-    }
-    else
-    {
-        ui.subFrame->show();
-    }
+    TOGGLEV( ui.subFrame );
 
     /* Update the MRL */
     updateMRL();
@@ -536,6 +516,8 @@ CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     v4lFreq->setSuffix(" kHz");
     setSpinBoxFreq( v4lFreq );
     v4lPropLayout->addWidget( v4lFreq, 1 , 1 );
+    v4lPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
+            2, 0, 2, 1 );
 
     /* v4l CONNECTs */
     CuMRL( v4lVideoDevice, textChanged( QString ) );
@@ -568,6 +550,8 @@ CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     v4l2StdBox = new QComboBox;
     setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
     v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
+    v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
+            1, 0, 3, 1 );
 
     /* v4l2 CONNECTs */
     CuMRL( v4l2VideoDevice, textChanged( QString ) );
@@ -669,6 +653,8 @@ CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     pvrBitr->setSuffix(" kHz");
     setSpinBoxFreq( pvrBitr );
     pvrPropLayout->addWidget( pvrBitr, 2, 1 );
+    pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
+            3, 0, 1, 1 );
 
     /* PVR CONNECTs */
     CuMRL( pvrDevice, textChanged( QString ) );
@@ -716,6 +702,8 @@ CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
 
     QLineEdit *dshowVSizeLine = new QLineEdit;
     dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
+    dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
+            1, 0, 3, 1 );
 
     /* dshow CONNECTs */
     CuMRL( dshowVDevice, currentIndexChanged ( int ) );
@@ -770,6 +758,8 @@ CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
 
     bdaBandLabel->hide();
     bdaBandBox->hide();
+    bdaPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
+            2, 0, 2, 1 );
 
     /* bda CONNECTs */
     CuMRL( bdaFreq, valueChanged ( int ) );
@@ -827,6 +817,8 @@ CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     dvbSrate->setSuffix(" kHz");
     setSpinBoxFreq( dvbSrate );
     dvbPropLayout->addWidget( dvbSrate, 1, 1 );
+    dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
+            2, 0, 2, 1 );
 
     /* DVB CONNECTs */
     CuMRL( dvbCard, valueChanged ( int ) );
index 2618cf49c3f98587886d7e365e8a9fb3ead34b5e..791e3a31ea49c7e1309def07004c2c51d6fa6d37 100644 (file)
@@ -103,10 +103,10 @@ private:
     QStringList browse( QString );
     FileOpenBox *dialogBox;
     QLineEdit *lineFileEdit;
+    QStringList fileCompleteList ;
 public slots:
     virtual void updateMRL();
 private slots:
-    void browseFile();
     void browseFileSub();
     void toggleSubtitleFrame();
 };
index 156624812eb45674adfb0bf2865fe1c98adaa043..6ea39901bb536471ce99b6010173e009baa667cc 100644 (file)
    <string>Capture</string>
   </property>
   <layout class="QGridLayout" >
-   <property name="margin" >
+   <property name="leftMargin" >
     <number>9</number>
    </property>
-   <property name="spacing" >
+   <property name="topMargin" >
+    <number>9</number>
+   </property>
+   <property name="rightMargin" >
+    <number>9</number>
+   </property>
+   <property name="bottomMargin" >
+    <number>9</number>
+   </property>
+   <property name="horizontalSpacing" >
+    <number>6</number>
+   </property>
+   <property name="verticalSpacing" >
     <number>6</number>
    </property>
-   <item row="4" column="0" colspan="2" >
+   <item row="5" column="0" colspan="2" >
     <spacer>
      <property name="orientation" >
       <enum>Qt::Vertical</enum>
@@ -39,9 +51,7 @@
    <item row="0" column="1" >
     <widget class="QComboBox" name="deviceCombo" >
      <property name="sizePolicy" >
-      <sizepolicy>
-       <hsizetype>1</hsizetype>
-       <vsizetype>0</vsizetype>
+      <sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
     </widget>
    </item>
-   <item row="2" column="0" colspan="2" >
+   <item row="3" column="0" colspan="2" >
     <widget class="QGroupBox" name="optionsBox" >
      <property name="sizePolicy" >
-      <sizepolicy>
-       <hsizetype>5</hsizetype>
-       <vsizetype>0</vsizetype>
+      <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
     </widget>
    </item>
-   <item row="1" column="0" colspan="2" >
+   <item row="2" column="0" colspan="2" >
     <widget class="QGroupBox" name="cardBox" >
      <property name="sizePolicy" >
-      <sizepolicy>
-       <hsizetype>3</hsizetype>
-       <vsizetype>5</vsizetype>
+      <sizepolicy vsizetype="Preferred" hsizetype="MinimumExpanding" >
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
@@ -88,7 +94,7 @@
      </property>
     </widget>
    </item>
-   <item row="3" column="0" >
+   <item row="4" column="0" >
     <widget class="QPushButton" name="advancedButton" >
      <property name="toolTip" >
       <string>_("Access advanced options to tweak the device")</string>
      </property>
     </widget>
    </item>
+   <item row="1" column="0" colspan="2" >
+    <widget class="Line" name="line" >
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>
index 146db957a1171a24e5fcb5dab7a112c90069e6d7..ae39502fca408eed34b9fe5dc8655da28ab7df69 100644 (file)
    <string>_("Open File")</string>
   </property>
   <layout class="QGridLayout" >
-   <item row="1" column="1" colspan="2" >
-    <widget class="QComboBox" name="fileInput" >
-     <property name="editable" >
-      <bool>true</bool>
-     </property>
-     <property name="maxVisibleItems" >
-      <number>7</number>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="0" >
-    <widget class="QLabel" name="fileLabel" >
-     <property name="maximumSize" >
-      <size>
-       <width>85</width>
-       <height>16777215</height>
-      </size>
-     </property>
-     <property name="text" >
-      <string>_("File Names:")</string>
-     </property>
-    </widget>
-   </item>
    <item row="0" column="0" colspan="3" >
     <widget class="QWidget" native="1" name="tempWidget" >
      <property name="toolTip" >
@@ -88,7 +65,7 @@
       <enum>QFrame::StyledPanel</enum>
      </property>
      <layout class="QGridLayout" >
-      <item row="1" column="7" >
+      <item row="1" column="0" >
        <spacer>
         <property name="orientation" >
          <enum>Qt::Horizontal</enum>
         </property>
        </spacer>
       </item>
-      <item row="1" column="0" >
-       <spacer>
-        <property name="orientation" >
-         <enum>Qt::Horizontal</enum>
+      <item row="1" column="1" >
+       <widget class="QLabel" name="sizeSubLabel" >
+        <property name="sizePolicy" >
+         <sizepolicy vsizetype="Preferred" hsizetype="Minimum" >
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
         </property>
-        <property name="sizeHint" >
-         <size>
-          <width>16</width>
-          <height>20</height>
-         </size>
+        <property name="text" >
+         <string>_("Size:")</string>
         </property>
-       </spacer>
+       </widget>
       </item>
-      <item row="1" column="5" colspan="2" >
-       <widget class="QComboBox" name="alignSubComboBox" >
+      <item row="1" column="2" >
+       <widget class="QComboBox" name="sizeSubComboBox" >
         <property name="minimumSize" >
          <size>
           <width>100</width>
           <height>0</height>
          </size>
         </property>
-        <property name="currentIndex" >
-         <number>-1</number>
-        </property>
-        <property name="insertPolicy" >
-         <enum>QComboBox::NoInsert</enum>
-        </property>
-        <property name="minimumContentsLength" >
-         <number>0</number>
-        </property>
-       </widget>
-      </item>
-      <item row="1" column="4" >
-       <widget class="QLabel" name="alignSubLabel" >
-        <property name="text" >
-         <string>_("Alignment:")</string>
-        </property>
-        <property name="buddy" >
-         <cstring>alignSubLabel</cstring>
-        </property>
        </widget>
       </item>
       <item row="1" column="3" >
         </property>
         <property name="sizeHint" >
          <size>
-          <width>71</width>
+          <width>30</width>
           <height>26</height>
          </size>
         </property>
        </spacer>
       </item>
-      <item row="1" column="2" >
-       <widget class="QComboBox" name="sizeSubComboBox" >
+      <item row="1" column="4" >
+       <widget class="QLabel" name="alignSubLabel" >
+        <property name="sizePolicy" >
+         <sizepolicy vsizetype="Preferred" hsizetype="Minimum" >
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="text" >
+         <string>_("Alignment:")</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="5" >
+       <widget class="QComboBox" name="alignSubComboBox" >
         <property name="minimumSize" >
          <size>
           <width>100</width>
         </property>
        </widget>
       </item>
-      <item row="1" column="1" >
-       <widget class="QLabel" name="sizeSubLabel" >
-        <property name="text" >
-         <string>_("Size:")</string>
+      <item row="1" column="6" colspan="2" >
+       <spacer>
+        <property name="orientation" >
+         <enum>Qt::Horizontal</enum>
         </property>
-       </widget>
+        <property name="sizeHint" >
+         <size>
+          <width>16</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
       </item>
       <item row="0" column="0" colspan="6" >
-       <widget class="QComboBox" name="subInput" >
-        <property name="editable" >
-         <bool>true</bool>
+       <widget class="QLineEdit" name="subInput" >
+        <property name="sizePolicy" >
+         <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
         </property>
        </widget>
       </item>
       <item row="0" column="6" colspan="2" >
        <widget class="QPushButton" name="subBrowseButton" >
+        <property name="sizePolicy" >
+         <sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="minimumSize" >
+         <size>
+          <width>100</width>
+          <height>0</height>
+         </size>
+        </property>
         <property name="toolTip" >
          <string>_("Select the subtitle file")</string>
         </property>
    </item>
   </layout>
  </widget>
- <layoutdefault spacing="0" margin="0" />
  <tabstops>
-  <tabstop>fileInput</tabstop>
   <tabstop>subCheckBox</tabstop>
   <tabstop>subInput</tabstop>
   <tabstop>subBrowseButton</tabstop>