ctkFileDialog.h 2.7 KB

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