ctkPathLineEdit.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.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. /*=========================================================================
  15. Program: Maverick
  16. Module: $RCSfile: config.h,v $
  17. Copyright (c) Kitware Inc. 28 Corporate Drive,
  18. Clifton Park, NY, 12065, USA.
  19. All rights reserved. No part of this software may be reproduced, distributed,
  20. or modified, in any form or by any means, without permission in writing from
  21. Kitware Inc.
  22. IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
  23. DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  24. OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
  25. EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
  27. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  28. PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
  29. "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
  30. MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  31. =========================================================================*/
  32. #ifndef __ctkPathLineEdit_h
  33. #define __ctkPathLineEdit_h
  34. // Qt includes
  35. #include <QWidget>
  36. #include <QDir>
  37. // CTK includes
  38. #include "ctkWidgetsExport.h"
  39. class ctkPathLineEditPrivate;
  40. /** /class Advanced line edit to select file or directory
  41. * /brief Widget that remember previous selection (using QSettings and objectName)
  42. * the user to select a file on the disk.
  43. */
  44. class CTK_WIDGETS_EXPORT ctkPathLineEdit: public QWidget
  45. {
  46. Q_OBJECT
  47. Q_FLAGS(Filters)
  48. Q_PROPERTY ( QString label READ label WRITE setLabel )
  49. Q_PROPERTY ( QStringList nameFilters READ nameFilters WRITE setNameFilters)
  50. Q_PROPERTY ( Filters filters READ filters WRITE setFilters)
  51. Q_PROPERTY ( QString currentPath READ currentPath WRITE setCurrentPath USER true )
  52. public:
  53. enum Filter { Dirs = 0x001,
  54. Files = 0x002,
  55. Drives = 0x004,
  56. NoSymLinks = 0x008,
  57. AllEntries = Dirs | Files | Drives,
  58. TypeMask = 0x00f,
  59. Readable = 0x010,
  60. Writable = 0x020,
  61. Executable = 0x040,
  62. PermissionMask = 0x070,
  63. Modified = 0x080,
  64. Hidden = 0x100,
  65. System = 0x200,
  66. AccessMask = 0x3F0,
  67. AllDirs = 0x400,
  68. CaseSensitive = 0x800,
  69. NoDotAndDotDot = 0x1000, // ### Qt5 NoDotAndDotDot = NoDot|NoDotDot
  70. NoDot = 0x2000,
  71. NoDotDot = 0x4000,
  72. NoFilter = -1
  73. };
  74. Q_DECLARE_FLAGS(Filters, Filter)
  75. /** Default constructor
  76. */
  77. ctkPathLineEdit(QWidget *parent = 0);
  78. /** Constructor
  79. * /param label Used in file dialogs
  80. * /param nameFilters Regular expression (in wildcard mode) used to help the user to complete the line,
  81. * example: "Images (*.jpg *.gif *.png)"
  82. * /param parent Parent widget
  83. */
  84. ctkPathLineEdit( const QString& label,
  85. const QStringList& nameFilters,
  86. Filters filters = ctkPathLineEdit::AllEntries,
  87. QWidget *parent=0 );
  88. virtual ~ctkPathLineEdit();
  89. QString currentPath()const;
  90. void setLabel(const QString &label);
  91. const QString& label()const;
  92. void setNameFilters(const QStringList &nameFilters);
  93. const QStringList& nameFilters()const;
  94. void setFilters(const Filters& filters);
  95. Filters filters()const;
  96. /** Change the current extension of the edit line.
  97. * If there is no extension yet, set it
  98. */
  99. void setCurrentFileExtension(const QString& extension);
  100. signals:
  101. /** the signal is emit when the state of hasValidInput changed
  102. */
  103. void validInputChanged(bool);
  104. void currentPathChanged(const QString& path);
  105. public slots:
  106. void setCurrentPath(const QString& path);
  107. /** Open a QFileDialog to select a file or directory and set current text to it
  108. * You would probably connect a browse push button like this:
  109. * connect(myPushButton,SIGNAL(clicked()),myPathLineEdit,SLOT(browse()))
  110. */
  111. void browse();
  112. /** Load the history of the paths. To be restored the inputs must have been saved by
  113. * saveCurrentPathInHistory().
  114. */
  115. void retrieveHistory();
  116. /** Save the current value (this->currentPath()) into the history. That value will be retrieved
  117. * next time the retrieveHistory()
  118. */
  119. void addCurrentPathToHistory();
  120. protected slots:
  121. void setCurrentDirectory(const QString& directory);
  122. void updateHasValidInput();
  123. protected:
  124. QScopedPointer<ctkPathLineEditPrivate> d_ptr;
  125. private:
  126. Q_DECLARE_PRIVATE(ctkPathLineEdit);
  127. Q_DISABLE_COPY(ctkPathLineEdit);
  128. };
  129. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkPathLineEdit::Filters)
  130. #endif // __ctkPathLineEdit_h