Qt4 - Open: New way and interface for File Open using an integration of QFileDialog...
authorJean-Baptiste Kempf <jb@videolan.org>
Mon, 19 Mar 2007 00:19:47 +0000 (00:19 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Mon, 19 Mar 2007 00:19:47 +0000 (00:19 +0000)
Be careful for your eyes when reading the code, it can burn them :)
Anyway, there are still a few bugs (the main one is the disapearing of QFileDialog on acceptance) and some alignment issues.

I got NO idea how this behaves under Windows... A special code may be needed.

modules/gui/qt4/components/open.cpp
modules/gui/qt4/components/open.hpp
modules/gui/qt4/dialogs/open.cpp
modules/gui/qt4/ui/open.ui
modules/gui/qt4/ui/open_disk.ui
modules/gui/qt4/ui/open_file.ui
modules/gui/qt4/ui/sprefs_subtitles.ui

index 3fbab46..bc90e3a 100644 (file)
 #include "qt4.hpp"
 #include "components/open.hpp"
 #include "dialogs_provider.hpp"
+#include "util/customwidgets.hpp"
+
+#include <QFileDialog>
+#include <QDialogButtonBox>
+#include <QLineEdit>
 
 /**************************************************************************
  * File open
 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
                                 OpenPanel( _parent, _p_intf )
 {
+    /* Classic UI Setup */
     ui.setupUi( this );
 
+    /* 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. */
+
+    // Make this QFileDialog a child of tempWidget from the ui.
+    dialogBox = new QFileDialog( ui.tempWidget );
+    dialogBox->setFileMode( QFileDialog::ExistingFiles );
+    dialogBox->setDirectory( qfu( p_intf->p_libvlc->psz_homedir ) );
+    /* We don't want to see a grip in the middle of the window, do we? */
+    dialogBox->setSizeGripEnabled( false );
+
+    // Add it to the layout
+    ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
+
+    // But hide the two OK/Cancel buttons. Enable them for debug.
+    findChild<QDialogButtonBox*>()->hide();
+
+    /* Ugly hacks to get the good Widget */
+    //This lineEdit is the normal line in the fileDialog.
+    lineFileEdit = findChildren<QLineEdit*>()[3];
+    lineFileEdit->hide();
+
+    /* Make a list of QLabel inside the QFileDialog to access the good ones */
+    QList<QLabel *> listLabel = findChildren<QLabel*>();
+
+    /* Hide the FileNames one. Enable it for debug */
+    listLabel[4]->hide();
+    /* Change the text that was uncool in the usual box */
+    listLabel[5]->setText( qtr( "Filter:" ) );
 
-    BUTTONACT( ui.fileBrowseButton, browseFile() );
     BUTTONACT( ui.subBrowseButton, browseFileSub() );
 
     BUTTONACT( ui.subGroupBox, updateMRL());
@@ -44,6 +78,7 @@ FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     CONNECT( ui.subInput, editTextChanged(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()
@@ -57,14 +92,10 @@ QStringList FileOpenPanel::browse(QString help)
 void FileOpenPanel::browseFile()
 {
     QString fileString = "";
-    QStringList files = browse( qtr("Open File") );
-    foreach( QString file, files) {
-        fileString += "\"" + file + "\" ";
+    foreach( QString file, dialogBox->selectedFiles() ) { 
+         fileString += "\"" + file + "\" ";
     }
     ui.fileInput->setEditText( fileString );
-    ui.fileInput->addItem( fileString );
-    if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
-
     updateMRL();
 }
 
@@ -83,14 +114,24 @@ void FileOpenPanel::updateMRL()
         mrl.append( " :subsdec-align=" + ui.alignSubComboBox->currentText() );
         mrl.append( " :sub-rel-fontsize=" + ui.sizeSubComboBox->currentText() );
     }
-    emit mrlUpdated(mrl);
+    emit mrlUpdated( mrl );
     emit methodChanged( "file-caching" );
 }
 
+
+/* 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);
+}
+
+
+/* Function called by Open Dialog when clicked on cancel */
 void FileOpenPanel::clear()
 {
-    ui.fileInput->setEditText( "");
-    ui.subInput->setEditText( "");
+    ui.fileInput->setEditText( "" );
+    ui.subInput->setEditText( "" );
 }
 
 
index d3b6a12..81ec2b4 100644 (file)
@@ -33,6 +33,9 @@
 #include "ui/open_net.h"
 #include "ui/open_capture.h"
 
+class QFileDialog;
+class QLineEdit;
+
 class OpenPanel: public QWidget
 {
     Q_OBJECT;
@@ -59,9 +62,12 @@ public:
     FileOpenPanel( QWidget *, intf_thread_t * );
     virtual ~FileOpenPanel();
     virtual void clear() ;
+    virtual void accept() ;
 private:
     Ui::OpenFile ui;
     QStringList browse( QString );
+    QFileDialog *dialogBox;
+    QLineEdit *lineFileEdit;
 public slots:
     virtual void updateMRL();
 private slots:
index 71030d9..f23fe4e 100644 (file)
@@ -42,6 +42,7 @@ OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal ) :
     setModal( modal );
     ui.setupUi( this );
     setWindowTitle( qtr("Open" ) );
+    resize( 500, 300);
 
     fileOpenPanel = new FileOpenPanel( this , p_intf );
     diskOpenPanel = new DiskOpenPanel( this , p_intf );
index 0981a68..88b7363 100644 (file)
         <property name="spacing" >
          <number>6</number>
         </property>
-        <item row="0" column="2" >
-         <widget class="QLabel" name="label" >
-          <property name="text" >
-           <string>ms</string>
-          </property>
-         </widget>
-        </item>
-        <item row="2" column="0" >
-         <widget class="QLabel" name="label_2" >
+        <item row="2" column="1" colspan="2" >
+         <widget class="QLineEdit" name="slaveText" >
           <property name="enabled" >
            <bool>false</bool>
           </property>
-          <property name="text" >
-           <string>Extra media</string>
-          </property>
          </widget>
         </item>
         <item row="0" column="0" >
           </property>
          </widget>
         </item>
+        <item row="0" column="2" >
+         <widget class="QLabel" name="label" >
+          <property name="text" >
+           <string>ms</string>
+          </property>
+         </widget>
+        </item>
+        <item row="3" column="0" >
+         <widget class="QLabel" name="advancedLabel" >
+          <property name="text" >
+           <string>Customize</string>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="0" >
+         <widget class="QLabel" name="label_2" >
+          <property name="enabled" >
+           <bool>false</bool>
+          </property>
+          <property name="text" >
+           <string>Extra media</string>
+          </property>
+         </widget>
+        </item>
         <item row="0" column="1" >
          <widget class="QSpinBox" name="cacheSpinBox" >
           <property name="sizePolicy" >
             <verstretch>0</verstretch>
            </sizepolicy>
           </property>
+          <property name="alignment" >
+           <set>Qt::AlignRight</set>
+          </property>
           <property name="maximum" >
            <number>999999</number>
           </property>
          </widget>
         </item>
-        <item row="3" column="0" >
-         <widget class="QLabel" name="advancedLabel" >
+        <item row="2" column="3" >
+         <widget class="QToolButton" name="slaveBrowseButton" >
+          <property name="enabled" >
+           <bool>false</bool>
+          </property>
           <property name="text" >
-           <string>Customize</string>
+           <string>Browse</string>
           </property>
          </widget>
         </item>
-        <item row="3" column="1" colspan="2" >
+        <item row="3" column="1" colspan="3" >
          <widget class="QLineEdit" name="advancedLineInput" />
         </item>
-        <item row="2" column="1" colspan="2" >
-         <widget class="QLineEdit" name="slaveText" >
-          <property name="enabled" >
-           <bool>false</bool>
-          </property>
-         </widget>
-        </item>
-        <item row="1" column="0" colspan="3" >
+        <item row="1" column="0" colspan="4" >
          <widget class="QCheckBox" name="slaveCheckbox" >
           <property name="text" >
            <string>Play another media synchronously (extra audio file, ...)</string>
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>slaveCheckbox</sender>
+   <signal>clicked(bool)</signal>
+   <receiver>slaveBrowseButton</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>219</x>
+     <y>102</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>386</x>
+     <y>131</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
 </ui>
index 2166c0d..76aa262 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>487</width>
-    <height>254</height>
+    <width>539</width>
+    <height>246</height>
    </rect>
   </property>
   <property name="windowTitle" >
       <property name="spacing" >
        <number>6</number>
       </property>
-      <item row="1" column="0" >
+      <item row="0" column="4" >
+       <widget class="QRadioButton" name="vcdRadioButton" >
+        <property name="text" >
+         <string>SVCD/VCD</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="5" >
+       <spacer>
+        <property name="orientation" >
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" >
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="2" column="0" colspan="2" >
        <widget class="QLabel" name="label" >
         <property name="text" >
          <string>Disk device</string>
         </property>
        </widget>
       </item>
-      <item row="0" column="1" >
-       <widget class="QRadioButton" name="vcdRadioButton" >
+      <item row="0" column="3" >
+       <spacer>
+        <property name="orientation" >
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" >
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="0" column="1" colspan="2" >
+       <widget class="QRadioButton" name="dvdRadioButton" >
+        <property name="layoutDirection" >
+         <enum>Qt::LeftToRight</enum>
+        </property>
         <property name="text" >
-         <string>SVCD/VCD</string>
+         <string>DVD</string>
+        </property>
+        <property name="checked" >
+         <bool>true</bool>
         </property>
        </widget>
       </item>
-      <item row="1" column="1" colspan="2" >
+      <item row="2" column="2" colspan="5" >
        <widget class="QComboBox" name="deviceCombo" >
         <property name="editable" >
          <bool>true</bool>
         </property>
        </widget>
       </item>
-      <item row="0" column="2" >
+      <item row="2" column="7" >
+       <widget class="QToolButton" name="toolButton" >
+        <property name="text" >
+         <string>Browse</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="6" >
        <widget class="QRadioButton" name="audioCDRadioButton" >
         <property name="text" >
          <string>Audio CD</string>
        </widget>
       </item>
       <item row="0" column="0" >
-       <widget class="QRadioButton" name="dvdRadioButton" >
-        <property name="text" >
-         <string>DVD</string>
+       <spacer>
+        <property name="orientation" >
+         <enum>Qt::Horizontal</enum>
         </property>
-        <property name="checked" >
-         <bool>true</bool>
+        <property name="sizeHint" >
+         <size>
+          <width>21</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="0" column="7" >
+       <spacer>
+        <property name="orientation" >
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" >
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="1" column="1" colspan="6" >
+       <widget class="Line" name="line" >
+        <property name="orientation" >
+         <enum>Qt::Horizontal</enum>
         </property>
        </widget>
       </item>
       </item>
       <item row="1" column="1" >
        <widget class="QSpinBox" name="chapterSpin" >
+        <property name="alignment" >
+         <set>Qt::AlignRight</set>
+        </property>
         <property name="suffix" >
          <string/>
         </property>
         <property name="autoFillBackground" >
          <bool>false</bool>
         </property>
+        <property name="alignment" >
+         <set>Qt::AlignRight</set>
+        </property>
         <property name="suffix" >
          <string/>
         </property>
      </property>
      <property name="sizeHint" >
       <size>
-       <width>20</width>
-       <height>40</height>
+       <width>469</width>
+       <height>16</height>
       </size>
      </property>
     </spacer>
index b7ae837..0ac290b 100644 (file)
@@ -6,20 +6,20 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>487</width>
-    <height>181</height>
+    <width>400</width>
+    <height>210</height>
    </rect>
   </property>
   <property name="sizePolicy" >
    <sizepolicy>
-    <hsizetype>3</hsizetype>
+    <hsizetype>7</hsizetype>
     <vsizetype>3</vsizetype>
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
   </property>
   <property name="windowTitle" >
-   <string>Form</string>
+   <string>Open File</string>
   </property>
   <layout class="QGridLayout" >
    <property name="margin" >
    <property name="spacing" >
     <number>6</number>
    </property>
-   <item row="2" column="1" >
+   <item row="1" column="0" >
     <spacer>
      <property name="orientation" >
-      <enum>Qt::Vertical</enum>
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="sizeType" >
+      <enum>QSizePolicy::Fixed</enum>
      </property>
      <property name="sizeHint" >
       <size>
-       <width>20</width>
-       <height>40</height>
+       <width>3</width>
+       <height>20</height>
       </size>
      </property>
     </spacer>
    </item>
-   <item row="1" column="0" colspan="3" >
+   <item row="3" column="0" colspan="3" >
     <widget class="QGroupBox" name="subGroupBox" >
      <property name="sizePolicy" >
       <sizepolicy>
      </property>
      <layout class="QGridLayout" >
       <property name="margin" >
-       <number>9</number>
+       <number>6</number>
       </property>
       <property name="spacing" >
-       <number>6</number>
+       <number>5</number>
       </property>
       <item row="0" column="4" >
        <widget class="QPushButton" name="subBrowseButton" >
      </layout>
     </widget>
    </item>
-   <item row="0" column="0" >
-    <widget class="QLabel" name="label" >
-     <property name="text" >
-      <string>File</string>
-     </property>
-    </widget>
-   </item>
-   <item row="0" column="2" >
-    <widget class="QPushButton" name="fileBrowseButton" >
-     <property name="text" >
-      <string>Browse</string>
-     </property>
-    </widget>
+   <item row="0" column="1" colspan="2" >
+    <widget class="QWidget" native="1" name="tempWidget" />
    </item>
-   <item row="0" column="1" >
+   <item row="1" column="2" >
     <widget class="QComboBox" name="fileInput" >
      <property name="sizePolicy" >
       <sizepolicy>
      </property>
     </widget>
    </item>
+   <item row="1" column="1" >
+    <widget class="QLabel" name="fileLabel" >
+     <property name="text" >
+      <string>File / Directory Names;</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="2" >
+    <spacer>
+     <property name="orientation" >
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeType" >
+      <enum>QSizePolicy::Fixed</enum>
+     </property>
+     <property name="sizeHint" >
+      <size>
+       <width>273</width>
+       <height>16</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="4" column="1" colspan="2" >
+    <spacer>
+     <property name="orientation" >
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" >
+      <size>
+       <width>525</width>
+       <height>31</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
   </layout>
  </widget>
+ <layoutdefault spacing="0" margin="0" />
  <resources/>
  <connections/>
 </ui>
index 44be37b..91f7096 100644 (file)
        </widget>
       </item>
       <item row="1" column="1" >
-       <widget class="QComboBox" name="encoding" />
+       <widget class="QComboBox" name="encoding" >
+        <property name="maxVisibleItems" >
+         <number>12</number>
+        </property>
+        <property name="frame" >
+         <bool>false</bool>
+        </property>
+       </widget>
       </item>
       <item row="0" column="1" >
        <widget class="QLineEdit" name="preferredLanguage" />