itom  3.0.0
pathLineEdit.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom and its software development toolkit (SDK).
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  In addition, as a special exception, the Institut fuer Technische
15  Optik (ITO) gives you certain additional rights.
16  These rights are described in the ITO LGPL Exception version 1.0,
17  which can be found in the file LGPL_EXCEPTION.txt in this package.
18 
19  itom is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22  General Public Licence for more details.
23 
24  You should have received a copy of the GNU Library General Public License
25  along with itom. If not, see <http://www.gnu.org/licenses/>.
26 
27  This file is a port and modified version of the
28  CTK Common Toolkit (http://www.commontk.org)
29 *********************************************************************** */
30 /*=========================================================================
31 
32 Program: Maverick
33 Module: $RCSfile: config.h,v $
34 
35 Copyright (c) Kitware Inc. 28 Corporate Drive,
36 Clifton Park, NY, 12065, USA.
37 
38 All rights reserved. No part of this software may be reproduced, distributed,
39 or modified, in any form or by any means, without permission in writing from
40 Kitware Inc.
41 
42 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
43 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
44 OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
45 EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 
47 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
48 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
49 PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
50 "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
51 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
52 
53 =========================================================================*/
54 
55 #ifndef PATHLINEEDIT_H
56 #define PATHLINEEDIT_H
57 
58 // Qt includes
59 #include <QDir>
60 #include <QWidget>
61 class QComboBox;
62 
63 // CTK includes
64 #include "commonWidgets.h"
66 
71 class ITOMWIDGETS_EXPORT PathLineEdit: public QWidget
72 {
73  Q_OBJECT
74  Q_FLAGS(Filters)
75  Q_PROPERTY ( QString label READ label WRITE setLabel )
76 
77  Q_PROPERTY ( Filters filters READ filters WRITE setFilters)
78  Q_PROPERTY ( QString currentPath READ currentPath WRITE setCurrentPath USER true )
82 #ifdef USE_QFILEDIALOG_OPTIONS
83  Q_PROPERTY(QFileDialog::Options options READ options WRITE setOptions)
84 #else
85  Q_PROPERTY(Options options READ options WRITE setOptions)
86  Q_FLAGS(Option Options)
87 #endif
88 
97  Q_PROPERTY(QString settingKey READ settingKey WRITE setSettingKey )
98 
99 
100  Q_PROPERTY(bool showBrowseButton READ showBrowseButton WRITE setShowBrowseButton)
104 
105 
106  Q_PROPERTY(bool showHistoryButton READ showHistoryButton WRITE setShowHistoryButton)
110 
111 
112  Q_PROPERTY(SizeAdjustPolicy sizeAdjustPolicy READ sizeAdjustPolicy WRITE setSizeAdjustPolicy)
115 
116 
117  Q_PROPERTY(int minimumContentsLength READ minimumContentsLength WRITE setMinimumContentsLength)
121 
122 
123  Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters)
126 
127 public:
128  enum Filter { Dirs = 0x001,
129  Files = 0x002,
130  Drives = 0x004,
131  NoSymLinks = 0x008,
132  AllEntries = Dirs | Files | Drives,
133  TypeMask = 0x00f,
134  Readable = 0x010,
135  Writable = 0x020,
136  Executable = 0x040,
137  PermissionMask = 0x070,
138  Modified = 0x080,
139  Hidden = 0x100,
140  System = 0x200,
141  AccessMask = 0x3F0,
142  AllDirs = 0x400,
143  CaseSensitive = 0x800,
144  NoDotAndDotDot = 0x1000, // ### Qt5 NoDotAndDotDot = NoDot|NoDotDot
145  NoDot = 0x2000,
146  NoDotDot = 0x4000,
147  NoFilter = -1
148  };
149  Q_DECLARE_FLAGS(Filters, Filter)
150 
151 #ifndef USE_QFILEDIALOG_OPTIONS
152  // Same options than QFileDialog::Options
153  enum Option
154  {
155  ShowDirsOnly = 0x00000001,
156  DontResolveSymlinks = 0x00000002,
157  DontConfirmOverwrite = 0x00000004,
158  DontUseSheet = 0x00000008,
159  DontUseNativeDialog = 0x00000010,
160  ReadOnly = 0x00000020,
161  HideNameFilterDetails = 0x00000040
162  };
163  Q_DECLARE_FLAGS(Options, Option)
164 #endif
165 
167  {
174  AdjustToMinimumContentsLength
175  };
176 
179  PathLineEdit(QWidget *parent = 0);
180 
187  PathLineEdit( const QString& label,
188  const QStringList& nameFilters,
189  Filters filters = PathLineEdit::AllEntries,
190  QWidget *parent=0 );
191  virtual ~PathLineEdit();
192  QString currentPath()const;
193 
194  void setLabel(const QString &label);
195  const QString& label()const;
196 
197  void setNameFilters(const QStringList &nameFilters);
198  const QStringList& nameFilters()const;
199 
200  void setFilters(const Filters& filters);
201  Filters filters()const;
202 
205 #ifdef USE_QFILEDIALOG_OPTIONS
206  void setOptions(const QFileDialog::Options& options);
207  const QFileDialog::Options& options()const;
208 #else
209  void setOptions(const Options& options);
210  const Options& options()const;
211 #endif
212 
215  void setCurrentFileExtension(const QString& extension);
216 
217  QString settingKey()const;
218  void setSettingKey(const QString& key);
219 
220  bool showBrowseButton()const;
221  void setShowBrowseButton(bool visible);
222 
223  bool showHistoryButton()const;
224  void setShowHistoryButton(bool visible);
225 
232  SizeAdjustPolicy sizeAdjustPolicy() const;
233 
234  void setSizeAdjustPolicy(SizeAdjustPolicy policy);
235 
236  int minimumContentsLength()const;
237  void setMinimumContentsLength(int lenght);
238 
240  QComboBox* comboBox() const;
241 
244  virtual QSize minimumSizeHint()const;
245 
248  virtual QSize sizeHint()const;
249 
250 signals:
253  void validInputChanged(bool);
254 
255  void currentPathChanged(const QString& path);
256 
257 public slots:
258  void setCurrentPath(const QString& path);
259 
265  void browse();
266 
271  void retrieveHistory();
272 
276  void addCurrentPathToHistory();
277 
278 protected Q_SLOTS:
279  void setCurrentDirectory(const QString& directory);
280  void updateHasValidInput();
281 
282 protected:
283  QScopedPointer<PathLineEditPrivate> d_ptr;
284 
285 private:
286  Q_DECLARE_PRIVATE(PathLineEdit);
287  Q_DISABLE_COPY(PathLineEdit);
288 
289  Q_PRIVATE_SLOT(d_ptr, void _q_recomputeCompleterPopupSize())
290 };
291 
292 Q_DECLARE_OPERATORS_FOR_FLAGS(PathLineEdit::Filters)
293 #ifndef USE_QFILEDIALOG_OPTIONS
294 Q_DECLARE_OPERATORS_FOR_FLAGS(PathLineEdit::Options);
295 #endif
296 
297 #endif // PATHLINEEDIT_H
The path line edit will always adjust to the contents.
Definition: pathLineEdit.h:169
Advanced line edit to select a file or directory.
Definition: pathLineEdit.h:71
Definition: pathLineEdit.cpp:51
SizeAdjustPolicy
Definition: pathLineEdit.h:166
The path line edit will adjust to its contents the first time it is shown.
Definition: pathLineEdit.h:171