ctkDirectoryButton.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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.commontk.org/LICENSE
  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 __ctkDirectoryButton_h
  15. #define __ctkDirectoryButton_h
  16. // Qt includes
  17. #include <QDir>
  18. #include <QFileDialog>
  19. // CTK includes
  20. #include <ctkPimpl.h>
  21. #include "CTKWidgetsExport.h"
  22. class ctkDirectoryButtonPrivate;
  23. class CTK_WIDGETS_EXPORT ctkDirectoryButton: public QWidget
  24. {
  25. Q_OBJECT
  26. Q_PROPERTY(QString directory READ directory WRITE setDirectory)
  27. Q_PROPERTY(QString caption READ caption WRITE setCaption)
  28. Q_PROPERTY(Options options READ options WRITE setOptions)
  29. // QFileDialog::Options is not a meta-type, we need to create our own.
  30. Q_FLAGS(Option Options);
  31. public:
  32. // QFileDialog::Options is not a meta-type, we need to create our own.
  33. enum Option
  34. {
  35. ShowDirsOnly = 0x00000001,
  36. DontResolveSymlinks = 0x00000002,
  37. DontConfirmOverwrite = 0x00000004,
  38. DontUseSheet = 0x00000008,
  39. DontUseNativeDialog = 0x00000010,
  40. ReadOnly = 0x00000020,
  41. HideNameFilterDetails = 0x00000040
  42. };
  43. Q_DECLARE_FLAGS(Options, Option)
  44. ctkDirectoryButton(QWidget * parent = 0);
  45. ctkDirectoryButton(const QString& directory, QWidget * parent = 0);
  46. ctkDirectoryButton(const QIcon& icon, const QString& directory, QWidget * parent = 0);
  47. void setDirectory(const QString& directory);
  48. QString directory()const;
  49. ///
  50. /// The title of the file dialog used to select a new directory
  51. /// If caption is not set, internally use QWidget::tooltip()
  52. void setCaption(const QString& caption);
  53. const QString& caption()const;
  54. void setOptions(const Options& options);
  55. const Options& options()const;
  56. public slots:
  57. void browse();
  58. signals:
  59. ///
  60. /// directoryChanged is emitted when the current directory changes
  61. ///if you want a directoryChanged signal as a utility. Feel free to add it
  62. void directoryChanged(const QString&);
  63. void directorySelected(const QString&);
  64. private:
  65. CTK_DECLARE_PRIVATE(ctkDirectoryButton);
  66. };
  67. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkDirectoryButton::Options);
  68. #endif