ctkFileDialog.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. class CTK_WIDGETS_EXPORT ctkFileDialog : public QFileDialog
  28. {
  29. Q_OBJECT
  30. public:
  31. // Superclass typedef
  32. typedef QFileDialog Superclass;
  33. /// Constructor
  34. /// By default, behaves like a QFileDialog
  35. /// \sa QFileDialog()
  36. explicit ctkFileDialog(QWidget *parent = 0,
  37. const QString &caption = QString(),
  38. const QString &directory = QString(),
  39. const QString &filter = QString());
  40. virtual ~ctkFileDialog();
  41. /// Add an extra widget under the file format combobox. If a label is
  42. /// given, it will appear in the first column.
  43. /// The widget is reparented to ctkFileDialog
  44. Q_INVOKABLE void setBottomWidget(QWidget* widget, const QString& label=QString());
  45. /// Return the extra widget if any
  46. Q_INVOKABLE QWidget* bottomWidget()const;
  47. /// Internally used
  48. bool eventFilter(QObject *obj, QEvent *event);
  49. public Q_SLOTS:
  50. /// Can be used to prevent the accept button to be enabled. It's typically
  51. /// a slot that can be connected to assure that the user doesn't accept the
  52. /// dialog if a value is not set in the extra bottom widget.
  53. void setAcceptButtonEnable(bool enable);
  54. Q_SIGNALS:
  55. /// Signals QFileDialog::file[s]Selected() are fired only when the Ok button
  56. /// is pressed, fileSelectionChanged(QStringList) is emitted when the
  57. /// selection is changed, not just when the dialog is accepted.
  58. void fileSelectionChanged(const QStringList& selected);
  59. protected Q_SLOTS:
  60. void onSelectionChanged();
  61. protected:
  62. QScopedPointer<ctkFileDialogPrivate> d_ptr;
  63. private:
  64. Q_DECLARE_PRIVATE(ctkFileDialog);
  65. Q_DISABLE_COPY(ctkFileDialog);
  66. };
  67. #endif