/
PrefWidgets.h
395 lines (326 loc) · 11.2 KB
/
PrefWidgets.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/***************************************************************************
* Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_PREFWIDGETS_H
#define GUI_PREFWIDGETS_H
#include <QCheckBox>
#include <QComboBox>
#include <QRadioButton>
#include <QFontComboBox>
#include <QFont>
#include <QTextEdit>
#include <Base/Parameter.h>
#include "Widgets.h"
#include "Window.h"
#include "SpinBox.h"
#include "FileDialog.h"
#include "QuantitySpinBox.h"
namespace Gui {
class CommandManager;
class WidgetFactoryInst;
/** The preference widget class.
* If you want to extend a QWidget class to save/restore its data
* you just have to derive from this class and implement the methods
* restorePreferences() and savePreferences().
*
* To restore and save the settings of any widgets in own dialogs you have
* call onRestore() e.g. in the dialog's constructor and call onSave() e.g.
* in accept() for each widget you want to enable this mechanism.
*
* For more information of how to use these widgets in normal container widgets
* which are again in a dialog refer to the description of Gui::Dialog::DlgPreferencesImp.
*
* \author Werner Mayer
*/
class GuiExport PrefWidget : public WindowParameter
{
public:
void setEntryName( const QByteArray& name );
QByteArray entryName() const;
void setParamGrpPath( const QByteArray& path );
QByteArray paramGrpPath() const;
virtual void OnChange(Base::Subject<const char*> &rCaller, const char * sReason);
void onSave();
void onRestore();
protected:
/** Restores the preferences
* Must be reimplemented in any subclasses.
*/
virtual void restorePreferences() = 0;
/** Save the preferences
* Must be reimplemented in any subclasses.
*/
virtual void savePreferences() = 0;
/** Print warning that saving failed.
*/
void failedToSave(const QString&) const;
/** Print warning that restoring failed.
*/
void failedToRestore(const QString&) const;
PrefWidget();
virtual ~PrefWidget();
private:
QByteArray m_sPrefName;
QByteArray m_sPrefGrp;
// friends
friend class Gui::WidgetFactoryInst;
};
/** The PrefSpinBox class.
* \author Werner Mayer
*/
class GuiExport PrefSpinBox : public QSpinBox, public PrefWidget
{
Q_OBJECT
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
public:
PrefSpinBox ( QWidget * parent = 0 );
virtual ~PrefSpinBox();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
/** The PrefDoubleSpinBox class.
* \author Werner Mayer
*/
class GuiExport PrefDoubleSpinBox : public QDoubleSpinBox, public PrefWidget
{
Q_OBJECT
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
public:
PrefDoubleSpinBox ( QWidget * parent = 0 );
virtual ~PrefDoubleSpinBox();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
/**
* The PrefLineEdit class.
* \author Werner Mayer
*/
class GuiExport PrefLineEdit : public QLineEdit, public PrefWidget
{
Q_OBJECT
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
public:
PrefLineEdit ( QWidget * parent = 0 );
virtual ~PrefLineEdit();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
/**
* The PrefLineEdit class.
* \author Chris Hennes
*/
class GuiExport PrefTextEdit : public QTextEdit, public PrefWidget
{
Q_OBJECT
Q_PROPERTY(QByteArray prefEntry READ entryName WRITE setEntryName)
Q_PROPERTY(QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath)
public:
PrefTextEdit(QWidget* parent = 0);
virtual ~PrefTextEdit();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
/**
* The PrefFileChooser class.
* \author Werner Mayer
*/
class GuiExport PrefFileChooser : public FileChooser, public PrefWidget
{
Q_OBJECT
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
public:
PrefFileChooser ( QWidget * parent = 0 );
virtual ~PrefFileChooser();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
/**
* The PrefComboBox class.
* \author Werner Mayer
*/
class GuiExport PrefComboBox : public QComboBox, public PrefWidget
{
Q_OBJECT
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
public:
PrefComboBox ( QWidget * parent = 0 );
virtual ~PrefComboBox();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
/**
* The PrefCheckBox class.
* \author Werner Mayer
*/
class GuiExport PrefCheckBox : public QCheckBox, public PrefWidget
{
Q_OBJECT
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
public:
PrefCheckBox ( QWidget * parent = 0 );
virtual ~PrefCheckBox();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
/**
* The PrefRadioButton class.
* \author Werner Mayer
*/
class GuiExport PrefRadioButton : public QRadioButton, public PrefWidget
{
Q_OBJECT
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
public:
PrefRadioButton ( QWidget * parent = 0 );
virtual ~PrefRadioButton();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
/**
* The PrefSlider class.
* \author Werner Mayer
*/
class GuiExport PrefSlider : public QSlider, public PrefWidget
{
Q_OBJECT
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
public:
PrefSlider ( QWidget * parent = 0 );
virtual ~PrefSlider();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
/**
* The PrefColorButton class.
* \author Werner Mayer
*/
class GuiExport PrefColorButton : public ColorButton, public PrefWidget
{
Q_OBJECT
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
public:
PrefColorButton ( QWidget * parent = 0 );
virtual ~PrefColorButton();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
/** The PrefUnitSpinBox class.
* \author wandererfan
* a simple Unit aware spin box.
* See also \ref PrefQuantitySpinBox
*/
class GuiExport PrefUnitSpinBox : public QuantitySpinBox, public PrefWidget
{
Q_OBJECT
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
public:
PrefUnitSpinBox ( QWidget * parent = 0 );
virtual ~PrefUnitSpinBox();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
class PrefQuantitySpinBoxPrivate;
/**
* The PrefQuantitySpinBox class.
* \author Werner Mayer
*/
class GuiExport PrefQuantitySpinBox : public QuantitySpinBox, public PrefWidget
{
Q_OBJECT
Q_PROPERTY(QByteArray prefEntry READ entryName WRITE setEntryName)
Q_PROPERTY(QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath)
Q_PROPERTY(int historySize READ historySize WRITE setHistorySize)
public:
PrefQuantitySpinBox (QWidget * parent = nullptr);
virtual ~PrefQuantitySpinBox();
/// set the input field to the last used value (works only if the setParamGrpPath() was called)
void setToLastUsedValue();
/// get the value of the history size property
int historySize() const;
/// set the value of the history size property
void setHistorySize(int);
/** @name history and default management */
//@{
/// push a new value to the history, if no string given the actual text of the input field is used.
void pushToHistory(const QString& value = QString());
/// get the history of the field, newest first
QStringList getHistory() const;
//@}
protected:
virtual void contextMenuEvent(QContextMenuEvent * event);
// restore from/save to parameters
void restorePreferences();
void savePreferences();
private:
QScopedPointer<PrefQuantitySpinBoxPrivate> d_ptr;
Q_DISABLE_COPY(PrefQuantitySpinBox)
Q_DECLARE_PRIVATE(PrefQuantitySpinBox)
};
/** The PrefFontBox class.
* \author wandererfan
*/
class GuiExport PrefFontBox : public QFontComboBox, public PrefWidget
{
Q_OBJECT
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
public:
PrefFontBox ( QWidget * parent = 0 );
virtual ~PrefFontBox();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
} // namespace Gui
#endif // GUI_PREFWIDGETS_H