QtGui/qlineedit.h Source File

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 
66 class Q_GUI_EXPORT QLineEdit : public QWidget
67 {
68  Q_OBJECT
69 
71  Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask)
72  Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true)
73  Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength)
74  Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
75  Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode)
76  Q_PROPERTY(QString displayText READ displayText)
77  Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition)
78  Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
79  Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
80  Q_PROPERTY(bool hasSelectedText READ hasSelectedText)
81  Q_PROPERTY(QString selectedText READ selectedText)
82  Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
83  Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
84  Q_PROPERTY(bool undoAvailable READ isUndoAvailable)
85  Q_PROPERTY(bool redoAvailable READ isRedoAvailable)
86  Q_PROPERTY(bool acceptableInput READ hasAcceptableInput)
87  Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
88  Q_PROPERTY(Qt::CursorMoveStyle cursorMoveStyle READ cursorMoveStyle WRITE setCursorMoveStyle)
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
280  Q_DISABLE_COPY(QLineEdit)
281  Q_DECLARE_PRIVATE(QLineEdit)
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
void update()
bool event(QEvent *)
#define QT_END_NAMESPACE
Definition: qglobal.h:128
#define Q_PROPERTY(text)
Definition: qobjectdefs.h:80
CursorMoveStyle
Definition: qnamespace.h:1790
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
virtual void contextMenuEvent(QContextMenuEvent *)
virtual void dragEnterEvent(QDragEnterEvent *)
virtual void dropEvent(QDropEvent *)
virtual void focusInEvent(QFocusEvent *)
virtual void mouseMoveEvent(QMouseEvent *)
virtual void focusOutEvent(QFocusEvent *)
virtual void keyPressEvent(QKeyEvent *)
Definition: qnamespace.h:54
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
#define Q_SLOTS
Definition: qobjectdefs.h:71
#define Q_SIGNALS
Definition: qobjectdefs.h:72
void setContentsMargins(int left, int top, int right, int bottom)
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
Definition: qpoint.h:53
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
virtual void mouseReleaseEvent(QMouseEvent *)
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
virtual void mouseDoubleClickEvent(QMouseEvent *)
Definition: qmenu.h:72
virtual QSize sizeHint() const
InputMethodQuery
Definition: qnamespace.h:1541
#define Q_OBJECT
Definition: qobjectdefs.h:157
GLubyte GLubyte b
Definition: GLee.h:5404
GLuint GLuint end
Definition: GLee.h:872
Definition: qrect.h:58
Definition: qsize.h:53
GLuint const GLchar * name
Definition: GLee.h:1704
virtual void paintEvent(QPaintEvent *)
virtual void dragMoveEvent(QDragMoveEvent *)
Definition: qchar.h:72
virtual void mousePressEvent(QMouseEvent *)
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
virtual QSize minimumSizeHint() const
virtual void dragLeaveEvent(QDragLeaveEvent *)
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define QT_END_HEADER
Definition: qglobal.h:142
virtual void inputMethodEvent(QInputMethodEvent *)
GLsizei maxLength
Definition: GLee.h:3048
virtual void changeEvent(QEvent *)