瀏覽代碼

Add ctkFileDialog::fileSelectionChanged()

Julien Finet 13 年之前
父節點
當前提交
5668da52d0
共有 2 個文件被更改,包括 33 次插入0 次删除
  1. 24 0
      Libs/Widgets/ctkFileDialog.cpp
  2. 9 0
      Libs/Widgets/ctkFileDialog.h

+ 24 - 0
Libs/Widgets/ctkFileDialog.cpp

@@ -24,6 +24,7 @@
 #include <QEvent>
 #include <QGridLayout>
 #include <QLabel>
+#include <QListView>
 #include <QPushButton>
 
 // CTK includes
@@ -38,7 +39,10 @@ protected:
 public:
   ctkFileDialogPrivate(ctkFileDialog& object);
   void init();
+
   QPushButton* acceptButton()const;
+  QListView* listView()const;
+
   bool AcceptButtonEnable;
   bool AcceptButtonState;
   bool IgnoreEvent;
@@ -65,6 +69,10 @@ void ctkFileDialogPrivate::init()
   // double click on the file, the dialog will be accepted, that event should
   // be intercepted as well
   button->installEventFilter(q);
+
+  QObject::connect(this->listView()->selectionModel(),
+                   SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+                   q, SLOT(onSelectionChanged()));
 }
 
 //------------------------------------------------------------------------------
@@ -79,6 +87,15 @@ QPushButton* ctkFileDialogPrivate::acceptButton()const
 }
 
 //------------------------------------------------------------------------------
+QListView* ctkFileDialogPrivate::listView()const
+{
+  Q_Q(const ctkFileDialog);
+  QListView* listView= q->findChild<QListView*>("listView");
+  Q_ASSERT(listView);
+  return listView;
+}
+
+//------------------------------------------------------------------------------
 ctkFileDialog::ctkFileDialog(QWidget *parentWidget,
               const QString &caption,
               const QString &directory,
@@ -164,3 +181,10 @@ bool ctkFileDialog::eventFilter(QObject *obj, QEvent *event)
     }
   return QFileDialog::eventFilter(obj, event);
 }
+
+//------------------------------------------------------------------------------
+void ctkFileDialog::onSelectionChanged()
+{
+  Q_D(ctkFileDialog);
+  emit this->fileSelectionChanged(this->selectedFiles());
+}

+ 9 - 0
Libs/Widgets/ctkFileDialog.h

@@ -66,6 +66,15 @@ public slots:
   /// dialog if a value is not set in the extra bottom widget.
   void setAcceptButtonEnable(bool enable);
 
+signals:
+  /// Signals QFileDialog::file[s]Selected() are fired only when the Ok button
+  /// is pressed, fileSelectionChanged(QStringList) is emitted when the
+  /// selection is changed, not just when the dialog is accepted.
+  void fileSelectionChanged(const QStringList& selected);
+
+protected slots:
+  void onSelectionChanged();
+
 protected:
   QScopedPointer<ctkFileDialogPrivate> d_ptr;