1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets 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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QLINEEDIT_H
41#define QLINEEDIT_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtWidgets/qframe.h>
45#include <QtGui/qtextcursor.h>
46#include <QtCore/qstring.h>
47#include <QtCore/qmargins.h>
48
49QT_REQUIRE_CONFIG(lineedit);
50
51QT_BEGIN_NAMESPACE
52
53class QValidator;
54class QMenu;
55class QLineEditPrivate;
56class QCompleter;
57class QStyleOptionFrame;
58class QAbstractSpinBox;
59class QDateTimeEdit;
60class QIcon;
61class QToolButton;
62
63class Q_WIDGETS_EXPORT QLineEdit : public QWidget
64{
65 Q_OBJECT
66
67 Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask)
68 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true)
69 Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength)
70 Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
71 Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode)
72 Q_PROPERTY(QString displayText READ displayText)
73 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition)
74 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
75 Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
76 Q_PROPERTY(bool hasSelectedText READ hasSelectedText)
77 Q_PROPERTY(QString selectedText READ selectedText)
78 Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
79 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
80 Q_PROPERTY(bool undoAvailable READ isUndoAvailable)
81 Q_PROPERTY(bool redoAvailable READ isRedoAvailable)
82 Q_PROPERTY(bool acceptableInput READ hasAcceptableInput)
83 Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
84 Q_PROPERTY(Qt::CursorMoveStyle cursorMoveStyle READ cursorMoveStyle WRITE setCursorMoveStyle)
85 Q_PROPERTY(bool clearButtonEnabled READ isClearButtonEnabled WRITE setClearButtonEnabled)
86public:
87 enum ActionPosition {
88 LeadingPosition,
89 TrailingPosition
90 };
91 Q_ENUM(ActionPosition)
92
93 explicit QLineEdit(QWidget *parent = nullptr);
94 explicit QLineEdit(const QString &, QWidget *parent = nullptr);
95 ~QLineEdit();
96
97 QString text() const;
98
99 QString displayText() const;
100
101 QString placeholderText() const;
102 void setPlaceholderText(const QString &);
103
104 int maxLength() const;
105 void setMaxLength(int);
106
107 void setFrame(bool);
108 bool hasFrame() const;
109
110 void setClearButtonEnabled(bool enable);
111 bool isClearButtonEnabled() const;
112
113 enum EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit };
114 Q_ENUM(EchoMode)
115 EchoMode echoMode() const;
116 void setEchoMode(EchoMode);
117
118 bool isReadOnly() const;
119 void setReadOnly(bool);
120
121#ifndef QT_NO_VALIDATOR
122 void setValidator(const QValidator *);
123 const QValidator * validator() const;
124#endif
125
126#if QT_CONFIG(completer)
127 void setCompleter(QCompleter *completer);
128 QCompleter *completer() const;
129#endif
130
131 QSize sizeHint() const override;
132 QSize minimumSizeHint() const override;
133
134 int cursorPosition() const;
135 void setCursorPosition(int);
136 int cursorPositionAt(const QPoint &pos);
137
138 void setAlignment(Qt::Alignment flag);
139 Qt::Alignment alignment() const;
140
141 void cursorForward(bool mark, int steps = 1);
142 void cursorBackward(bool mark, int steps = 1);
143 void cursorWordForward(bool mark);
144 void cursorWordBackward(bool mark);
145 void backspace();
146 void del();
147 void home(bool mark);
148 void end(bool mark);
149
150 bool isModified() const;
151 void setModified(bool);
152
153 void setSelection(int, int);
154 bool hasSelectedText() const;
155 QString selectedText() const;
156 int selectionStart() const;
157 int selectionEnd() const;
158 int selectionLength() const;
159
160 bool isUndoAvailable() const;
161 bool isRedoAvailable() const;
162
163 void setDragEnabled(bool b);
164 bool dragEnabled() const;
165
166 void setCursorMoveStyle(Qt::CursorMoveStyle style);
167 Qt::CursorMoveStyle cursorMoveStyle() const;
168
169 QString inputMask() const;
170 void setInputMask(const QString &inputMask);
171 bool hasAcceptableInput() const;
172
173 void setTextMargins(int left, int top, int right, int bottom);
174 void setTextMargins(const QMargins &margins);
175 void getTextMargins(int *left, int *top, int *right, int *bottom) const;
176 QMargins textMargins() const;
177
178#if QT_CONFIG(action)
179 using QWidget::addAction;
180 void addAction(QAction *action, ActionPosition position);
181 QAction *addAction(const QIcon &icon, ActionPosition position);
182#endif
183
184public Q_SLOTS:
185 void setText(const QString &);
186 void clear();
187 void selectAll();
188 void undo();
189 void redo();
190#ifndef QT_NO_CLIPBOARD
191 void cut();
192 void copy() const;
193 void paste();
194#endif
195
196public:
197 void deselect();
198 void insert(const QString &);
199#ifndef QT_NO_CONTEXTMENU
200 QMenu *createStandardContextMenu();
201#endif
202
203Q_SIGNALS:
204 void textChanged(const QString &);
205 void textEdited(const QString &);
206 void cursorPositionChanged(int, int);
207 void returnPressed();
208 void editingFinished();
209 void selectionChanged();
210
211protected:
212 void mousePressEvent(QMouseEvent *) override;
213 void mouseMoveEvent(QMouseEvent *) override;
214 void mouseReleaseEvent(QMouseEvent *) override;
215 void mouseDoubleClickEvent(QMouseEvent *) override;
216 void keyPressEvent(QKeyEvent *) override;
217 void focusInEvent(QFocusEvent *) override;
218 void focusOutEvent(QFocusEvent *) override;
219 void paintEvent(QPaintEvent *) override;
220#if QT_CONFIG(draganddrop)
221 void dragEnterEvent(QDragEnterEvent *) override;
222 void dragMoveEvent(QDragMoveEvent *e) override;
223 void dragLeaveEvent(QDragLeaveEvent *e) override;
224 void dropEvent(QDropEvent *) override;
225#endif
226 void changeEvent(QEvent *) override;
227#ifndef QT_NO_CONTEXTMENU
228 void contextMenuEvent(QContextMenuEvent *) override;
229#endif
230
231 void inputMethodEvent(QInputMethodEvent *) override;
232 void initStyleOption(QStyleOptionFrame *option) const;
233public:
234 QVariant inputMethodQuery(Qt::InputMethodQuery) const override;
235 Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const;
236 bool event(QEvent *) override;
237protected:
238 QRect cursorRect() const;
239
240public:
241
242private:
243 friend class QAbstractSpinBox;
244 friend class QAccessibleLineEdit;
245 friend class QComboBox;
246#ifdef QT_KEYPAD_NAVIGATION
247 friend class QDateTimeEdit;
248#endif
249 Q_DISABLE_COPY(QLineEdit)
250 Q_DECLARE_PRIVATE(QLineEdit)
251 Q_PRIVATE_SLOT(d_func(), void _q_handleWindowActivate())
252 Q_PRIVATE_SLOT(d_func(), void _q_textEdited(const QString &))
253 Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged(int, int))
254#if QT_CONFIG(completer)
255 Q_PRIVATE_SLOT(d_func(), void _q_completionHighlighted(const QString &))
256#endif
257#ifdef QT_KEYPAD_NAVIGATION
258 Q_PRIVATE_SLOT(d_func(), void _q_editFocusChange(bool))
259#endif
260 Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged())
261 Q_PRIVATE_SLOT(d_func(), void _q_updateNeeded(const QRect &))
262 Q_PRIVATE_SLOT(d_func(), void _q_textChanged(const QString &))
263 Q_PRIVATE_SLOT(d_func(), void _q_clearButtonClicked())
264};
265
266QT_END_NAMESPACE
267
268#endif // QLINEEDIT_H
269