forked from commontk/CTK
/
ctkPathLineEdit.h
288 lines (234 loc) · 10.3 KB
/
ctkPathLineEdit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*=========================================================================
Library: CTK
Copyright (c) Kitware Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
/*=========================================================================
Program: Maverick
Module: $RCSfile: config.h,v $
Copyright (c) Kitware Inc. 28 Corporate Drive,
Clifton Park, NY, 12065, USA.
All rights reserved. No part of this software may be reproduced, distributed,
or modified, in any form or by any means, without permission in writing from
Kitware Inc.
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
#ifndef __ctkPathLineEdit_h
#define __ctkPathLineEdit_h
// Qt includes
#include <QDir>
#include <QWidget>
class QComboBox;
// CTK includes
#include "ctkWidgetsExport.h"
class ctkPathLineEditPrivate;
/// \ingroup Widgets
/// \brief Advanced line edit to select a file or directory.
/// \sa ctkDirectoryButton, ctkPathListWidget
///
class CTK_WIDGETS_EXPORT ctkPathLineEdit: public QWidget
{
Q_OBJECT
Q_FLAGS(Filters)
Q_PROPERTY ( QString label READ label WRITE setLabel )
Q_PROPERTY ( QStringList nameFilters READ nameFilters WRITE setNameFilters)
Q_PROPERTY ( Filters filters READ filters WRITE setFilters)
Q_PROPERTY ( QString currentPath READ currentPath WRITE setCurrentPath USER true )
/// Qt versions prior to 4.7.0 didn't expose QFileDialog::Options in the
/// public API. We need to create a custom property that will be used when
/// instanciating a QFileDialog in ctkPathLineEdit::browse()
#ifdef USE_QFILEDIALOG_OPTIONS
Q_PROPERTY(QFileDialog::Options options READ options WRITE setOptions)
#else
Q_PROPERTY(Options options READ options WRITE setOptions)
Q_FLAGS(Option Options)
#endif
/// This property controls the key used to search the settings for recorded
/// paths.
/// If multiple path line edits share the same key, their history is then
/// shared.
/// If an empty key string is given, the object name is used as key.
/// Setting the key automatically retrieve the history from settings
/// Empty by default.
/// \sa retrieveHistory(), addCurrentPathToHistory(), showHistoryButton
Q_PROPERTY(QString settingKey READ settingKey WRITE setSettingKey )
/// This property controls whether the browse ("...") button is visible or
/// not. Clicking on the button calls opens a dialog to select the current path.
/// True by default
/// \sa browse()
Q_PROPERTY(bool showBrowseButton READ showBrowseButton WRITE setShowBrowseButton)
/// This property controls whether the history button (arrow button that opens
/// the history menu) is visible or not.
/// True by default.
/// \sa retrieveHistory(), addCurrentPathToHistory(), settingKey
Q_PROPERTY(bool showHistoryButton READ showHistoryButton WRITE setShowHistoryButton)
/// This property holds the policy describing how the size of the path line edit widget
/// changes when the content changes.
/// The default value is AdjustToContentsOnFirstShow.
Q_PROPERTY(SizeAdjustPolicy sizeAdjustPolicy READ sizeAdjustPolicy WRITE setSizeAdjustPolicy)
/// This property holds the minimum number of characters that should fit into
/// the path line edit.
/// The default value is 0.
/// If this property is set to a positive value, the minimumSizeHint() and sizeHint() take it into account.
Q_PROPERTY(int minimumContentsLength READ minimumContentsLength WRITE setMinimumContentsLength)
/// This property holds the list of regular expressions (in wildcard mode) used to help the user
/// complete a line.
/// For example: "Images (*.jpg *.gif *.png)"
Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters)
public:
enum Filter { Dirs = 0x001,
Files = 0x002,
Drives = 0x004,
NoSymLinks = 0x008,
AllEntries = Dirs | Files | Drives,
TypeMask = 0x00f,
Readable = 0x010,
Writable = 0x020,
Executable = 0x040,
PermissionMask = 0x070,
Modified = 0x080,
Hidden = 0x100,
System = 0x200,
AccessMask = 0x3F0,
AllDirs = 0x400,
CaseSensitive = 0x800,
NoDotAndDotDot = 0x1000, // ### Qt5 NoDotAndDotDot = NoDot|NoDotDot
NoDot = 0x2000,
NoDotDot = 0x4000,
NoFilter = -1
};
Q_DECLARE_FLAGS(Filters, Filter)
#ifndef USE_QFILEDIALOG_OPTIONS
// Same options than QFileDialog::Options
enum Option
{
ShowDirsOnly = 0x00000001,
DontResolveSymlinks = 0x00000002,
DontConfirmOverwrite = 0x00000004,
DontUseSheet = 0x00000008,
DontUseNativeDialog = 0x00000010,
ReadOnly = 0x00000020,
HideNameFilterDetails = 0x00000040
};
Q_DECLARE_FLAGS(Options, Option)
#endif
enum SizeAdjustPolicy
{
/// The path line edit will always adjust to the contents.
AdjustToContents,
/// The path line edit will adjust to its contents the first time it is shown.
AdjustToContentsOnFirstShow,
/// The combobox will adjust to minimumContentsLength. For performance reasons
/// use this policy on large models.
AdjustToMinimumContentsLength
};
/** Default constructor
*/
ctkPathLineEdit(QWidget *parent = 0);
/** Constructor
* /param label Used in file dialogs
* /param nameFilters Regular expression (in wildcard mode) used to help the user to complete the line,
* example: "Images (*.jpg *.gif *.png)"
* /param parent Parent widget
*/
ctkPathLineEdit( const QString& label,
const QStringList& nameFilters,
Filters filters = ctkPathLineEdit::AllEntries,
QWidget *parent=0 );
virtual ~ctkPathLineEdit();
QString currentPath()const;
void setLabel(const QString &label);
const QString& label()const;
void setNameFilters(const QStringList &nameFilters);
const QStringList& nameFilters()const;
void setFilters(const Filters& filters);
Filters filters()const;
/// Options of the file dialog pop up.
/// \sa QFileDialog::getExistingDirectory
#ifdef USE_QFILEDIALOG_OPTIONS
void setOptions(const QFileDialog::Options& options);
const QFileDialog::Options& options()const;
#else
void setOptions(const Options& options);
const Options& options()const;
#endif
/// Change the current extension of the edit line.
/// If there is no extension yet, set it
void setCurrentFileExtension(const QString& extension);
QString settingKey()const;
void setSettingKey(const QString& key);
bool showBrowseButton()const;
void setShowBrowseButton(bool visible);
bool showHistoryButton()const;
void setShowHistoryButton(bool visible);
/// the policy describing how the size of the combobox changes
/// when the content changes
///
/// The default value is \c AdjustToContentsOnFirstShow.
///
/// \sa SizeAdjustPolicy
SizeAdjustPolicy sizeAdjustPolicy() const;
void setSizeAdjustPolicy(SizeAdjustPolicy policy);
int minimumContentsLength()const;
void setMinimumContentsLength(int lenght);
/// Return the combo box internally used by the path line edit
QComboBox* comboBox() const;
/// The width returned, in pixels, is the length of the file name (with no
/// path) if any. Otherwise, it's enough for 15 to 20 characters.
virtual QSize minimumSizeHint()const;
/// The width returned, in pixels, is the entire length of the current path
/// if any. Otherwise, it's enough for 15 to 20 characters.
virtual QSize sizeHint()const;
Q_SIGNALS:
/** the signal is emit when the state of hasValidInput changed
*/
void validInputChanged(bool);
void currentPathChanged(const QString& path);
public Q_SLOTS:
void setCurrentPath(const QString& path);
/// Open a QFileDialog to select a file or directory and set current text to it
/// You would probably connect a browse push button like this:
/// connect(myPushButton,SIGNAL(clicked()),myPathLineEdit,SLOT(browse()))
/// As a conveniency, such button is provided by default via the browseButton
/// \sa showBrowseButton
void browse();
/// Load the history of the paths that have been saved in the application
/// settings with addCurrentPathToHistory().
/// The history is identified using \a settingKey
/// \sa addCurrentPathToHistory(), showHistoryButton, settingKey
void retrieveHistory();
/// Save the current value (this->currentPath()) into the history. That value
/// will be retrieved next time retrieveHistory() is called.
/// \sa retrieveHistory(), showHistoryButton, settingKey
void addCurrentPathToHistory();
protected Q_SLOTS:
void setCurrentDirectory(const QString& directory);
void updateHasValidInput();
protected:
QScopedPointer<ctkPathLineEditPrivate> d_ptr;
private:
Q_DECLARE_PRIVATE(ctkPathLineEdit);
Q_DISABLE_COPY(ctkPathLineEdit);
Q_PRIVATE_SLOT(d_ptr, void _q_recomputeCompleterPopupSize())
};
Q_DECLARE_OPERATORS_FOR_FLAGS(ctkPathLineEdit::Filters)
#ifndef USE_QFILEDIALOG_OPTIONS
Q_DECLARE_OPERATORS_FOR_FLAGS(ctkPathLineEdit::Options);
#endif
#endif // __ctkPathLineEdit_h