/
Widgets.h
416 lines (323 loc) · 10.7 KB
/
Widgets.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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/***************************************************************************
* 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_WIDGETS_H
#define GUI_WIDGETS_H
#include <Gui/ui_DlgTreeWidget.h>
#include <QListWidget>
#include <QLabel>
#include <QLineEdit>
#include <QPointer>
#include <QPushButton>
#include <QPlainTextEdit>
#include <QBasicTimer>
#include <QTime>
namespace Gui {
class PrefCheckBox;
class CommandViewItemPrivate;
/**
* This class allows to drag one or more items which correspond to a Command object.
* The dragged items can be dropped onto the @ref Gui::PythonConsole.
* @see CommandViewItem, Command
* @author Werner Mayer
*/
class CommandIconView : public QListWidget
{
Q_OBJECT
public:
CommandIconView (QWidget * parent = 0);
virtual ~CommandIconView ();
protected:
void startDrag ( Qt::DropActions supportedActions );
protected Q_SLOTS:
void onSelectionChanged( QListWidgetItem * item, QListWidgetItem * );
Q_SIGNALS:
/** Emits this signal if selection has changed. */
void emitSelectionChanged( const QString& );
};
// ------------------------------------------------------------------------------
class GuiExport ActionSelector : public QWidget
{
Q_OBJECT
public:
ActionSelector(QWidget* parent=0);
~ActionSelector();
QTreeWidget* availableTreeWidget() const
{ return availableWidget; }
QTreeWidget* selectedTreeWidget() const
{ return selectedWidget; }
void setSelectedLabel(const QString&);
QString selectedLabel() const;
void setAvailableLabel(const QString&);
QString availableLabel() const;
private:
void keyPressEvent(QKeyEvent *);
void changeEvent(QEvent*);
void retranslateUi();
void setButtonsEnabled();
private Q_SLOTS:
void on_addButton_clicked();
void on_removeButton_clicked();
void on_upButton_clicked();
void on_downButton_clicked();
void onCurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*);
void onItemDoubleClicked(QTreeWidgetItem * item, int column);
private:
QGridLayout *gridLayout;
QVBoxLayout *vboxLayout;
QVBoxLayout *vboxLayout1;
QPushButton *addButton;
QPushButton *removeButton;
QPushButton *upButton;
QPushButton *downButton;
QLabel *labelAvailable;
QLabel *labelSelected;
QTreeWidget *availableWidget;
QTreeWidget *selectedWidget;
QSpacerItem *spacerItem;
QSpacerItem *spacerItem1;
};
// ------------------------------------------------------------------------------
/**
* The AccelLineEdit class provides a lineedit to specfify shortcuts.
* \author Werner Mayer
*/
class GuiExport AccelLineEdit : public QLineEdit
{
Q_OBJECT
public:
AccelLineEdit ( QWidget * parent=0 );
protected:
void keyPressEvent ( QKeyEvent * e);
private:
int keyPressedCount;
};
// ------------------------------------------------------------------------------
typedef QPair<QString, bool> CheckListItem;
/**
* The CheckListDialog class provides a dialog with a QListView with
* checkable items inside.
* \author Werner Mayer
*/
class GuiExport CheckListDialog : public QDialog
{
Q_OBJECT
public:
CheckListDialog( QWidget* parent = 0, Qt::WFlags fl = 0 );
~CheckListDialog();
void setCheckableItems( const QStringList& items );
void setCheckableItems( const QList<CheckListItem>& items );
QStringList getCheckedItems() const;
void accept ();
private:
QStringList checked;
Ui_DlgTreeWidget ui;
};
// ------------------------------------------------------------------------------
/**
* Implementation of a color button.
* \author Werner Mayer
*/
class GuiExport ColorButton : public QPushButton
{
Q_OBJECT
Q_PROPERTY( QColor color READ color WRITE setColor )
Q_PROPERTY( bool allowChangeColor READ allowChangeColor WRITE setAllowChangeColor )
Q_PROPERTY( bool drawFrame READ drawFrame WRITE setDrawFrame )
public:
ColorButton(QWidget* parent = 0);
~ColorButton();
void setColor(const QColor&);
QColor color() const;
void setAllowChangeColor(bool);
bool allowChangeColor() const;
void setDrawFrame(bool);
bool drawFrame() const;
void setModal(bool);
bool isModal() const;
public Q_SLOTS:
void onChooseColor();
private Q_SLOTS:
void onColorChosen(const QColor&);
void onRejected();
Q_SIGNALS:
/** Emits this signal when color has changed */
void changed();
protected:
void paintEvent (QPaintEvent*);
private:
struct ColorButtonP *d;
};
// ------------------------------------------------------------------------------
/**
* A text label where a url can specified. When the user clicks on the text label the system browser
* gets opened with the specified url.
*
* This can be used for e.g. in the about dialog where the url of the maintainer of an application
* can be specified.
* @author Werner Mayer
*/
class GuiExport UrlLabel : public QLabel
{
Q_OBJECT
Q_PROPERTY( QString url READ url WRITE setUrl)
public:
UrlLabel ( QWidget * parent = 0, Qt::WFlags f = 0 );
virtual ~UrlLabel();
QString url() const;
public Q_SLOTS:
void setUrl( const QString &u );
protected:
void enterEvent ( QEvent * );
void leaveEvent ( QEvent * );
void mouseReleaseEvent ( QMouseEvent * );
private:
QString _url;
};
// ----------------------------------------------------------------------
/**
* The LabelButton class provides a label with a button on the right side.
* @author Werner Mayer
*/
class GuiExport LabelButton : public QWidget
{
Q_OBJECT
Q_PROPERTY(QVariant value READ value WRITE setValue)
public:
LabelButton (QWidget * parent = 0);
virtual ~LabelButton();
QVariant value() const;
QLabel *getLabel() const;
QPushButton *getButton() const;
public Q_SLOTS:
void setValue(const QVariant&);
protected:
virtual void showValue(const QVariant&) = 0;
void resizeEvent(QResizeEvent*);
protected Q_SLOTS:
virtual void browse() = 0;
Q_SIGNALS:
void valueChanged(const QVariant &);
private:
QLabel *label;
QPushButton *button;
QVariant _val;
};
// ----------------------------------------------------------------------
/**
* Qt's tooltip does not work as expected with some classes, e.g. when showing
* it in the 3d view it immediately receives a timer event to destroy itself.
* This class is thought to circumvent this behaviour by filtering the internal
* timer events.
* @author Werner Mayer
*/
class GuiExport ToolTip : public QObject
{
public:
static void showText(const QPoint & pos, const QString & text, QWidget * w = 0);
protected:
static ToolTip* instance();
ToolTip();
virtual ~ToolTip();
void timerEvent(QTimerEvent *e);
bool eventFilter(QObject* o, QEvent*e);
void installEventFilter();
void removeEventFilter();
private:
bool installed, hidden;
static ToolTip* inst;
QString text;
QPoint pos;
QPointer<QWidget> w; // need guard in case widget gets destroyed
QBasicTimer tooltipTimer;
QTime displayTime;
};
// ----------------------------------------------------------------------
class GuiExport StatusWidget : public QWidget
{
Q_OBJECT
public:
StatusWidget(QWidget* parent);
~StatusWidget();
void setStatusText(const QString&);
QSize sizeHint () const;
void showText(int ms);
protected:
void showEvent(QShowEvent*);
void hideEvent(QHideEvent*);
void adjustPosition(QWidget* w);
private:
QLabel* label;
};
// ----------------------------------------------------------------------
class PropertyListEditor : public QPlainTextEdit
{
Q_OBJECT
public:
PropertyListEditor(QWidget *parent = 0);
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
protected:
void resizeEvent(QResizeEvent *event);
private Q_SLOTS:
void updateLineNumberAreaWidth(int newBlockCount);
void highlightCurrentLine();
void updateLineNumberArea(const QRect &, int);
private:
QWidget *lineNumberArea;
};
// ----------------------------------------------------------------------
class GuiExport LabelEditor : public QWidget
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText )
Q_PROPERTY(QString buttonText READ buttonText WRITE setButtonText)
public:
enum InputType {String, Float, Integer};
LabelEditor (QWidget * parent = 0);
virtual ~LabelEditor();
/**
* Returns the text.
*/
QString text() const;
/**
* Returns the button's text.
*/
QString buttonText() const;
/**
* Set the input type.
*/
void setInputType(InputType);
public Q_SLOTS:
virtual void setText(const QString &);
virtual void setButtonText (const QString &);
Q_SIGNALS:
void textChanged(const QString &);
private Q_SLOTS:
void changeText();
private:
InputType type;
QString plainText;
QLineEdit *lineEdit;
QPushButton *button;
};
} // namespace Gui
#endif // GUI_WIDGETS_H