CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkPathLineEdit.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 /*=========================================================================
21 
22 Program: Maverick
23 Module: $RCSfile: config.h,v $
24 
25 Copyright (c) Kitware Inc. 28 Corporate Drive,
26 Clifton Park, NY, 12065, USA.
27 
28 All rights reserved. No part of this software may be reproduced, distributed,
29 or modified, in any form or by any means, without permission in writing from
30 Kitware Inc.
31 
32 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
33 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
34 OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
35 EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 
37 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
38 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
39 PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
40 "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
41 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
42 
43 =========================================================================*/
44 
45 #ifndef __ctkPathLineEdit_h
46 #define __ctkPathLineEdit_h
47 
48 // Qt includes
49 #include <QDir>
50 #include <QWidget>
51 class QComboBox;
52 
53 // CTK includes
54 #include "ctkWidgetsExport.h"
55 class ctkPathLineEditPrivate;
56 
61 class CTK_WIDGETS_EXPORT ctkPathLineEdit: public QWidget
62 {
63  Q_OBJECT
64  Q_FLAGS(Filters)
65  Q_PROPERTY ( QString label READ label WRITE setLabel )
66 
67  Q_PROPERTY ( QStringList nameFilters READ nameFilters WRITE setNameFilters)
68  Q_PROPERTY ( Filters filters READ filters WRITE setFilters)
69  Q_PROPERTY ( QString currentPath READ currentPath WRITE setCurrentPath USER true )
73 #ifdef USE_QFILEDIALOG_OPTIONS
74  Q_PROPERTY(QFileDialog::Options options READ options WRITE setOptions)
75 #else
76  Q_PROPERTY(Options options READ options WRITE setOptions)
77  Q_FLAGS(Option Options)
78 #endif
79 
88  Q_PROPERTY(QString settingKey READ settingKey WRITE setSettingKey )
89 
90 
91  Q_PROPERTY(bool showBrowseButton READ showBrowseButton WRITE setShowBrowseButton)
95 
96 
97  Q_PROPERTY(bool showHistoryButton READ showHistoryButton WRITE setShowHistoryButton)
101 
102 
103  Q_PROPERTY(SizeAdjustPolicy sizeAdjustPolicy READ sizeAdjustPolicy WRITE setSizeAdjustPolicy)
106 
107 
108  Q_PROPERTY(int minimumContentsLength READ minimumContentsLength WRITE setMinimumContentsLength)
112 
113 
114  Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters)
117 
118 public:
119  enum Filter { Dirs = 0x001,
120  Files = 0x002,
121  Drives = 0x004,
122  NoSymLinks = 0x008,
123  AllEntries = Dirs | Files | Drives,
124  TypeMask = 0x00f,
125  Readable = 0x010,
126  Writable = 0x020,
127  Executable = 0x040,
128  PermissionMask = 0x070,
129  Modified = 0x080,
130  Hidden = 0x100,
131  System = 0x200,
132  AccessMask = 0x3F0,
133  AllDirs = 0x400,
134  CaseSensitive = 0x800,
135  NoDotAndDotDot = 0x1000, // ### Qt5 NoDotAndDotDot = NoDot|NoDotDot
136  NoDot = 0x2000,
137  NoDotDot = 0x4000,
138  NoFilter = -1
139  };
140  Q_DECLARE_FLAGS(Filters, Filter)
141 
142 #ifndef USE_QFILEDIALOG_OPTIONS
143  // Same options than QFileDialog::Options
144  enum Option
145  {
146  ShowDirsOnly = 0x00000001,
147  DontResolveSymlinks = 0x00000002,
148  DontConfirmOverwrite = 0x00000004,
149  DontUseSheet = 0x00000008,
150  DontUseNativeDialog = 0x00000010,
151  ReadOnly = 0x00000020,
152  HideNameFilterDetails = 0x00000040
153  };
154  Q_DECLARE_FLAGS(Options, Option)
155 #endif
156 
158  {
165  AdjustToMinimumContentsLength
166  };
167 
170  ctkPathLineEdit(QWidget *parent = 0);
171 
178  ctkPathLineEdit( const QString& label,
179  const QStringList& nameFilters,
180  Filters filters = ctkPathLineEdit::AllEntries,
181  QWidget *parent=0 );
182  virtual ~ctkPathLineEdit();
183  QString currentPath()const;
184 
185  void setLabel(const QString &label);
186  const QString& label()const;
187 
188  void setNameFilters(const QStringList &nameFilters);
189  const QStringList& nameFilters()const;
190 
191  void setFilters(const Filters& filters);
192  Filters filters()const;
193 
196 #ifdef USE_QFILEDIALOG_OPTIONS
197  void setOptions(const QFileDialog::Options& options);
198  const QFileDialog::Options& options()const;
199 #else
200  void setOptions(const Options& options);
201  const Options& options()const;
202 #endif
203 
206  void setCurrentFileExtension(const QString& extension);
207 
208  QString settingKey()const;
209  void setSettingKey(const QString& key);
210 
211  bool showBrowseButton()const;
212  void setShowBrowseButton(bool visible);
213 
214  bool showHistoryButton()const;
215  void setShowHistoryButton(bool visible);
216 
223  SizeAdjustPolicy sizeAdjustPolicy() const;
224 
225  void setSizeAdjustPolicy(SizeAdjustPolicy policy);
226 
227  int minimumContentsLength()const;
228  void setMinimumContentsLength(int lenght);
229 
231  QComboBox* comboBox() const;
232 
235  virtual QSize minimumSizeHint()const;
236 
239  virtual QSize sizeHint()const;
240 
241 Q_SIGNALS:
244  void validInputChanged(bool);
245 
246  void currentPathChanged(const QString& path);
247 
248 public Q_SLOTS:
249  void setCurrentPath(const QString& path);
250 
256  void browse();
257 
262  void retrieveHistory();
263 
267  void addCurrentPathToHistory();
268 
269 protected Q_SLOTS:
270  void setCurrentDirectory(const QString& directory);
271  void updateHasValidInput();
272 
273 protected:
274  QScopedPointer<ctkPathLineEditPrivate> d_ptr;
275 
276 private:
277  Q_DECLARE_PRIVATE(ctkPathLineEdit);
278  Q_DISABLE_COPY(ctkPathLineEdit);
279 
280  Q_PRIVATE_SLOT(d_ptr, void _q_recomputeCompleterPopupSize())
281 };
282 
283 Q_DECLARE_OPERATORS_FOR_FLAGS(ctkPathLineEdit::Filters)
284 #ifndef USE_QFILEDIALOG_OPTIONS
285 Q_DECLARE_OPERATORS_FOR_FLAGS(ctkPathLineEdit::Options);
286 #endif
287 
288 #endif // __ctkPathLineEdit_h
QScopedPointer< ctkPathLineEditPrivate > d_ptr
The path line edit will adjust to its contents the first time it is shown.
The path line edit will always adjust to the contents.
Q_DECLARE_OPERATORS_FOR_FLAGS(ctkPathLineEdit::Options)
Advanced line edit to select a file or directory.