Qt 4.8
qlineedit.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QLINEEDIT_H
43 #define QLINEEDIT_H
44 
45 #include <QtGui/qframe.h>
46 #include <QtGui/qtextcursor.h>
47 #include <QtCore/qstring.h>
48 #include <QtCore/qmargins.h>
49 
51 
53 
54 QT_MODULE(Gui)
55 
56 #ifndef QT_NO_LINEEDIT
57 
58 class QValidator;
59 class QMenu;
60 class QLineEditPrivate;
61 class QCompleter;
62 class QStyleOptionFrame;
63 class QAbstractSpinBox;
64 class QDateTimeEdit;
65 
67 {
68  Q_OBJECT
69 
71  QString inputMask;
73  int maxLength;
74  bool frame;
75  EchoMode echoMode;
76  QString displayText;
77  int cursorPosition;
78  Qt::Alignment alignment;
79  bool modified;
80  bool hasSelectedText;
81  QString selectedText;
82  bool dragEnabled;
83  bool readOnly;
84  bool undoAvailable;
85  bool redoAvailable;
86  bool acceptableInput;
87  QString placeholderText;
88  Qt::CursorMoveStyle cursorMoveStyle;
89 
90 public:
91  explicit QLineEdit(QWidget* parent=0);
92  explicit QLineEdit(const QString &, QWidget* parent=0);
93 #ifdef QT3_SUPPORT
94  QT3_SUPPORT_CONSTRUCTOR QLineEdit(QWidget* parent, const char* name);
95  QT3_SUPPORT_CONSTRUCTOR QLineEdit(const QString &, QWidget* parent, const char* name);
96  QT3_SUPPORT_CONSTRUCTOR QLineEdit(const QString &, const QString &, QWidget* parent=0, const char* name=0);
97 #endif
98  ~QLineEdit();
99 
100  QString text() const;
101 
102  QString displayText() const;
103 
104  QString placeholderText() const;
105  void setPlaceholderText(const QString &);
106 
107  int maxLength() const;
108  void setMaxLength(int);
109 
110  void setFrame(bool);
111  bool hasFrame() const;
112 
113  enum EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit };
114  EchoMode echoMode() const;
115  void setEchoMode(EchoMode);
116 
117  bool isReadOnly() const;
118  void setReadOnly(bool);
119 
120 #ifndef QT_NO_VALIDATOR
121  void setValidator(const QValidator *);
122  const QValidator * validator() const;
123 #endif
124 
125 #ifndef QT_NO_COMPLETER
126  void setCompleter(QCompleter *completer);
127  QCompleter *completer() const;
128 #endif
129 
130  QSize sizeHint() const;
131  QSize minimumSizeHint() const;
132 
133  int cursorPosition() const;
134  void setCursorPosition(int);
135  int cursorPositionAt(const QPoint &pos);
136 
137  void setAlignment(Qt::Alignment flag);
138  Qt::Alignment alignment() const;
139 
140  void cursorForward(bool mark, int steps = 1);
141  void cursorBackward(bool mark, int steps = 1);
142  void cursorWordForward(bool mark);
143  void cursorWordBackward(bool mark);
144  void backspace();
145  void del();
146  void home(bool mark);
147  void end(bool mark);
148 
149  bool isModified() const;
150  void setModified(bool);
151 
152  void setSelection(int, int);
153  bool hasSelectedText() const;
154  QString selectedText() const;
155  int selectionStart() const;
156 
157  bool isUndoAvailable() const;
158  bool isRedoAvailable() const;
159 
160  void setDragEnabled(bool b);
161  bool dragEnabled() const;
162 
163  void setCursorMoveStyle(Qt::CursorMoveStyle style);
164  Qt::CursorMoveStyle cursorMoveStyle() const;
165 
166  QString inputMask() const;
167  void setInputMask(const QString &inputMask);
168  bool hasAcceptableInput() const;
169 
170  void setTextMargins(int left, int top, int right, int bottom);
171  void setTextMargins(const QMargins &margins);
172  void getTextMargins(int *left, int *top, int *right, int *bottom) const;
173  QMargins textMargins() const;
174 
175 public Q_SLOTS:
176  void setText(const QString &);
177  void clear();
178  void selectAll();
179  void undo();
180  void redo();
181 #ifndef QT_NO_CLIPBOARD
182  void cut();
183  void copy() const;
184  void paste();
185 #endif
186 
187 public:
188  void deselect();
189  void insert(const QString &);
190 #ifndef QT_NO_CONTEXTMENU
191  QMenu *createStandardContextMenu();
192 #endif
193 
194 Q_SIGNALS:
195  void textChanged(const QString &);
196  void textEdited(const QString &);
197  void cursorPositionChanged(int, int);
198  void returnPressed();
199  void editingFinished();
200  void selectionChanged();
201 
202 protected:
204  void mouseMoveEvent(QMouseEvent *);
207  void keyPressEvent(QKeyEvent *);
208  void focusInEvent(QFocusEvent *);
209  void focusOutEvent(QFocusEvent *);
210  void paintEvent(QPaintEvent *);
211 #ifndef QT_NO_DRAGANDDROP
213  void dragMoveEvent(QDragMoveEvent *e);
215  void dropEvent(QDropEvent *);
216 #endif
217  void changeEvent(QEvent *);
218 #ifndef QT_NO_CONTEXTMENU
220 #endif
221 #ifdef QT3_SUPPORT
222  inline QT3_SUPPORT void repaintArea(int, int) { update(); }
223 #endif
224 
226  void initStyleOption(QStyleOptionFrame *option) const;
227 public:
229  bool event(QEvent *);
230 protected:
231  QRect cursorRect() const;
232 
233 public:
234 #ifdef QT3_SUPPORT
235  inline QT3_SUPPORT void clearModified() { setModified(false); }
236  inline QT3_SUPPORT void cursorLeft(bool mark, int steps = 1) { cursorForward(mark, -steps); }
237  inline QT3_SUPPORT void cursorRight(bool mark, int steps = 1) { cursorForward(mark, steps); }
238  QT3_SUPPORT bool validateAndSet(const QString &, int, int, int);
239  inline QT3_SUPPORT bool frame() const { return hasFrame(); }
240 #ifndef QT_NO_VALIDATOR
241  inline QT3_SUPPORT void clearValidator() { setValidator(0); }
242 #endif
243  inline QT3_SUPPORT bool hasMarkedText() const { return hasSelectedText(); }
244  inline QT3_SUPPORT QString markedText() const { return selectedText(); }
245  QT3_SUPPORT bool edited() const;
246  QT3_SUPPORT void setEdited(bool);
247  QT3_SUPPORT int characterAt(int, QChar*) const;
248  QT3_SUPPORT bool getSelection(int *, int *);
249 
250  QT3_SUPPORT void setFrameRect(QRect) {}
251  QT3_SUPPORT QRect frameRect() const { return QRect(); }
252  enum DummyFrame { Box, Sunken, Plain, Raised, MShadow, NoFrame, Panel, StyledPanel,
253  HLine, VLine, GroupBoxPanel, WinPanel, ToolBarPanel, MenuBarPanel,
254  PopupPanel, LineEditPanel, TabWidgetPanel, MShape };
255  QT3_SUPPORT void setFrameShadow(DummyFrame) {}
256  QT3_SUPPORT DummyFrame frameShadow() const { return Plain; }
257  QT3_SUPPORT void setFrameShape(DummyFrame) {}
258  QT3_SUPPORT DummyFrame frameShape() const { return NoFrame; }
259  QT3_SUPPORT void setFrameStyle(int) {}
260  QT3_SUPPORT int frameStyle() const { return 0; }
261  QT3_SUPPORT int frameWidth() const { return 0; }
262  QT3_SUPPORT void setLineWidth(int) {}
263  QT3_SUPPORT int lineWidth() const { return 0; }
264  QT3_SUPPORT void setMargin(int margin) { setContentsMargins(margin, margin, margin, margin); }
265  QT3_SUPPORT int margin() const
266  { int margin; int dummy; getContentsMargins(&margin, &dummy, &dummy, &dummy); return margin; }
267  QT3_SUPPORT void setMidLineWidth(int) {}
268  QT3_SUPPORT int midLineWidth() const { return 0; }
269 
270 Q_SIGNALS:
271  QT_MOC_COMPAT void lostFocus();
272 #endif
273 
274 private:
275  friend class QAbstractSpinBox;
276  friend class QAccessibleLineEdit;
277 #ifdef QT_KEYPAD_NAVIGATION
278  friend class QDateTimeEdit;
279 #endif
282  Q_PRIVATE_SLOT(d_func(), void _q_handleWindowActivate())
283  Q_PRIVATE_SLOT(d_func(), void _q_textEdited(const QString &))
284  Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged(int, int))
285 #ifndef QT_NO_COMPLETER
286  Q_PRIVATE_SLOT(d_func(), void _q_completionHighlighted(QString))
287 #endif
288 #ifdef QT_KEYPAD_NAVIGATION
289  Q_PRIVATE_SLOT(d_func(), void _q_editFocusChange(bool))
290 #endif
291  Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged())
292  Q_PRIVATE_SLOT(d_func(), void _q_updateNeeded(const QRect &))
293 };
294 
295 #endif // QT_NO_LINEEDIT
296 
298 
300 
301 #endif // QLINEEDIT_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
#define QT_MOC_COMPAT
Definition: qglobal.h:1128
The QKeyEvent class describes a key event.
Definition: qevent.h:224
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual void inputMethodEvent(QInputMethodEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive Input Method compo...
Definition: qwidget.cpp:9668
#define QT_MODULE(x)
Definition: qglobal.h:2783
virtual QSize minimumSizeHint() const
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
virtual void mouseReleaseEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
Definition: qwidget.cpp:9286
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
virtual void dragEnterEvent(QDragEnterEvent *)
This event handler is called when a drag is in progress and the mouse enters this widget...
Definition: qwidget.cpp:9768
virtual void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition: qwidget.cpp:9261
The QAccessibleLineEdit class implements the QAccessibleInterface for widgets with editable text...
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
The QCompleter class provides completions based on an item model.
Definition: qcompleter.h:64
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
#define Q_SLOTS
Definition: qobjectdefs.h:71
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition: qwidget.cpp:9683
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
#define Q_SIGNALS
Definition: qobjectdefs.h:72
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
virtual void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition: qwidget.cpp:9457
virtual QSize sizeHint() const
The QDateTimeEdit class provides a widget for editing dates and times.
Definition: qdatetimeedit.h:61
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
virtual void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
Definition: qwidget.cpp:9548
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QValidator class provides validation of input text.
Definition: qvalidator.h:60
EchoMode
This enum type describes how a line edit should display its contents.
Definition: qlineedit.h:113
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Returns the widget&#39;s contents margins for left, top, right, and bottom.
Definition: qwidget.cpp:7509
void setContentsMargins(int left, int top, int right, int bottom)
Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom.
Definition: qwidget.cpp:7449
const char * name
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
virtual void mouseDoubleClickEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse double click...
Definition: qwidget.cpp:9306
The QStyleOptionFrame class is used to describe the parameters for drawing a frame.
Definition: qstyleoption.h:118
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
Definition: qevent.h:577
The QAbstractSpinBox class provides a spinbox and a line edit to display values.
virtual void keyPressEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
Definition: qwidget.cpp:9375
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
virtual void contextMenuEvent(QContextMenuEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive widget context men...
Definition: qwidget.cpp:9645
InputMethodQuery
Definition: qnamespace.h:1541
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
virtual void dragMoveEvent(QDragMoveEvent *)
This event handler is called if a drag is in progress, and when any of the following conditions occur...
Definition: qwidget.cpp:9786
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
Definition: qevent.h:476
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
CursorMoveStyle
This enum describes the movement style available to text cursors.
Definition: qnamespace.h:1790
virtual void dropEvent(QDropEvent *)
This event handler is called when the drag is dropped on this widget.
Definition: qwidget.cpp:9817
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
Definition: qevent.h:555
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
virtual void mouseMoveEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition: qwidget.cpp:9239
The QMargins class defines the four margins of a rectangle.
Definition: qmargins.h:53
virtual void dragLeaveEvent(QDragLeaveEvent *)
This event handler is called when a drag is in progress and the mouse leaves this widget...
Definition: qwidget.cpp:9802
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
static const KeyPair *const end
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define QT_END_HEADER
Definition: qglobal.h:137
virtual void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition: qwidget.cpp:9431
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
#define text
Definition: qobjectdefs.h:80