ctkFileDialog.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkFileDialog_h
  15. #define __ctkFileDialog_h
  16. // Qt includes
  17. #include <QFileDialog>
  18. // CTK includes
  19. #include <ctkPimpl.h>
  20. #include "ctkWidgetsExport.h"
  21. class ctkFileDialogPrivate;
  22. /// \ingroup Widgets
  23. /// Customizable QFileDialog.
  24. /// An extra widget can be added at the bottom of the dialog
  25. /// under the file format combobox. The Accept button is also controllable
  26. /// using setAcceptButtonEnable().
  27. /// The behavior of the "return" key is the following:
  28. /// - it selects the directory written in the line edit or it
  29. /// - it accepts the dialog if the directory is already selected.
  30. class CTK_WIDGETS_EXPORT ctkFileDialog : public QFileDialog
  31. {
  32. Q_OBJECT
  33. public:
  34. // Superclass typedef
  35. typedef QFileDialog Superclass;
  36. /// Constructor
  37. /// By default, behaves like a QFileDialog
  38. /// \sa QFileDialog()
  39. explicit ctkFileDialog(QWidget *parent = 0,
  40. const QString &caption = QString(),
  41. const QString &directory = QString(),
  42. const QString &filter = QString());
  43. virtual ~ctkFileDialog();
  44. /// Add an extra widget under the file format combobox. If a label is
  45. /// given, it will appear in the first column.
  46. /// The widget is reparented to ctkFileDialog
  47. Q_INVOKABLE void setBottomWidget(QWidget* widget, const QString& label=QString());
  48. /// Return the extra widget if any
  49. Q_INVOKABLE QWidget* bottomWidget()const;
  50. /// Internally used
  51. bool eventFilter(QObject *obj, QEvent *event);
  52. public Q_SLOTS:
  53. /// Can be used to prevent the accept button to be enabled. It's typically
  54. /// a slot that can be connected to assure that the user doesn't accept the
  55. /// dialog if a value is not set in the extra bottom widget.
  56. void setAcceptButtonEnable(bool enable);
  57. Q_SIGNALS:
  58. /// Signals QFileDialog::file[s]Selected() are fired only when the Ok button
  59. /// is pressed, fileSelectionChanged(QStringList) is emitted when the
  60. /// selection is changed, not just when the dialog is accepted.
  61. void fileSelectionChanged(const QStringList& selected);
  62. protected Q_SLOTS:
  63. void onSelectionChanged();
  64. protected:
  65. QScopedPointer<ctkFileDialogPrivate> d_ptr;
  66. /// Reimplemented to override the return key behavior
  67. virtual void accept();
  68. private:
  69. Q_DECLARE_PRIVATE(ctkFileDialog);
  70. Q_DISABLE_COPY(ctkFileDialog);
  71. };
  72. #endif