ctkDirectoryButton.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #if QT_VERSION >= 0x040603
  29. Q_PROPERTY(QFileDialog::Options options READ options WRITE setOptions)
  30. #else
  31. Q_PROPERTY(Options options READ options WRITE setOptions)
  32. // QFileDialog::Options is not a meta-type, we need to create our own.
  33. Q_FLAGS(Option Options);
  34. #endif
  35. public:
  36. #if QT_VERSION < 0x040603
  37. // QFileDialog::Options is not a meta-type, we need to create our own.
  38. enum Option
  39. {
  40. ShowDirsOnly = 0x00000001,
  41. DontResolveSymlinks = 0x00000002,
  42. DontConfirmOverwrite = 0x00000004,
  43. DontUseSheet = 0x00000008,
  44. DontUseNativeDialog = 0x00000010,
  45. ReadOnly = 0x00000020,
  46. HideNameFilterDetails = 0x00000040
  47. };
  48. Q_DECLARE_FLAGS(Options, Option)
  49. #endif
  50. ctkDirectoryButton(QWidget * parent = 0);
  51. ctkDirectoryButton(const QString& directory, QWidget * parent = 0);
  52. ctkDirectoryButton(const QIcon& icon, const QString& directory, QWidget * parent = 0);
  53. void setDirectory(const QString& directory);
  54. QString directory()const;
  55. ///
  56. /// The title of the file dialog used to select a new directory
  57. /// If caption is not set, internally use QWidget::tooltip()
  58. void setCaption(const QString& caption);
  59. const QString& caption()const;
  60. #if QT_VERSION >= 0x040603
  61. void setOptions(const QFileDialog::Options& options);
  62. const QFileDialog::Options& options()const;
  63. #else
  64. void setOptions(const Options& options);
  65. const Options& options()const;
  66. #endif
  67. public slots:
  68. void browse();
  69. signals:
  70. ///
  71. /// directoryChanged is emitted when the current directory changes
  72. ///if you want a directoryChanged signal as a utility. Feel free to add it
  73. void directoryChanged(const QString&);
  74. void directorySelected(const QString&);
  75. private:
  76. CTK_DECLARE_PRIVATE(ctkDirectoryButton);
  77. };
  78. #if QT_VERSION < 0x040603
  79. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkDirectoryButton::Options);
  80. #endif
  81. #endif